]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- reordered fixed hunks
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-3.0-rc5/Documentation/vserver/debug.txt linux-3.0-rc5-vs2.3.1-pre3/Documentation/vserver/debug.txt
2 --- linux-3.0-rc5/Documentation/vserver/debug.txt       1970-01-01 01:00:00.000000000 +0100
3 +++ linux-3.0-rc5-vs2.3.1-pre3/Documentation/vserver/debug.txt  2011-06-10 22:11:24.000000000 +0200
4 @@ -0,0 +1,154 @@
5 +
6 +debug_cvirt:
7 +
8 + 2   4 "vx_map_tgid: %p/%llx: %d -> %d"
9 +       "vx_rmap_tgid: %p/%llx: %d -> %d"
10 +
11 +debug_dlim:
12 +
13 + 0   1 "ALLOC (%p,#%d)%c inode (%d)"
14 +       "FREE  (%p,#%d)%c inode"
15 + 1   2 "ALLOC (%p,#%d)%c %lld bytes (%d)"
16 +       "FREE  (%p,#%d)%c %lld bytes"
17 + 2   4 "ADJUST: %lld,%lld on %ld,%ld [mult=%d]"
18 + 3   8 "ext3_has_free_blocks(%p): %lu<%lu+1, %c, %u!=%u r=%d"
19 +       "ext3_has_free_blocks(%p): free=%lu, root=%lu"
20 +       "rcu_free_dl_info(%p)"
21 + 4  10 "alloc_dl_info(%p,%d) = %p"
22 +       "dealloc_dl_info(%p)"
23 +       "get_dl_info(%p[#%d.%d])"
24 +       "put_dl_info(%p[#%d.%d])"
25 + 5  20 "alloc_dl_info(%p,%d)*"
26 + 6  40 "__hash_dl_info: %p[#%d]"
27 +       "__unhash_dl_info: %p[#%d]"
28 + 7  80 "locate_dl_info(%p,#%d) = %p"
29 +
30 +debug_misc:
31 +
32 + 0   1 "destroy_dqhash: %p [#0x%08x] c=%d"
33 +       "new_dqhash: %p [#0x%08x]"
34 +       "vroot[%d]_clr_dev: dev=%p[%lu,%d:%d]"
35 +       "vroot[%d]_get_real_bdev: dev=%p[%lu,%d:%d]"
36 +       "vroot[%d]_set_dev: dev=%p[%lu,%d:%d]"
37 +       "vroot_get_real_bdev not set"
38 + 1   2 "cow_break_link(»%s«)"
39 +       "temp copy »%s«"
40 + 2   4 "dentry_open(new): %p"
41 +       "dentry_open(old): %p"
42 +       "lookup_create(new): %p"
43 +       "old path »%s«"
44 +       "path_lookup(old): %d"
45 +       "vfs_create(new): %d"
46 +       "vfs_rename: %d"
47 +       "vfs_sendfile: %d"
48 + 3   8 "fput(new_file=%p[#%d])"
49 +       "fput(old_file=%p[#%d])"
50 + 4  10 "vx_info_kill(%p[#%d],%d,%d) = %d"
51 +       "vx_info_kill(%p[#%d],%d,%d)*"
52 + 5  20 "vs_reboot(%p[#%d],%d)"
53 + 6  40 "dropping task %p[#%u,%u] for %p[#%u,%u]"
54 +
55 +debug_net:
56 +
57 + 2   4 "nx_addr_conflict(%p,%p) %d.%d,%d.%d"
58 + 3   8 "inet_bind(%p) %d.%d.%d.%d, %d.%d.%d.%d, %d.%d.%d.%d"
59 +       "inet_bind(%p)* %p,%p;%lx %d.%d.%d.%d"
60 + 4  10 "ip_route_connect(%p) %p,%p;%lx"
61 + 5  20 "__addr_in_socket(%p,%d.%d.%d.%d) %p:%d.%d.%d.%d %p;%lx"
62 + 6  40 "sk,egf: %p [#%d] (from %d)"
63 +       "sk,egn: %p [#%d] (from %d)"
64 +       "sk,req: %p [#%d] (from %d)"
65 +       "sk: %p [#%d] (from %d)"
66 +       "tw: %p [#%d] (from %d)"
67 + 7  80 "__sock_recvmsg: %p[%p,%p,%p;%d]:%d/%d"
68 +       "__sock_sendmsg: %p[%p,%p,%p;%d]:%d/%d"
69 +
70 +debug_nid:
71 +
72 + 0   1 "__lookup_nx_info(#%u): %p[#%u]"
73 +       "alloc_nx_info(%d) = %p"
74 +       "create_nx_info(%d) (dynamic rejected)"
75 +       "create_nx_info(%d) = %p (already there)"
76 +       "create_nx_info(%d) = %p (new)"
77 +       "dealloc_nx_info(%p)"
78 + 1   2 "alloc_nx_info(%d)*"
79 +       "create_nx_info(%d)*"
80 + 2   4 "get_nx_info(%p[#%d.%d])"
81 +       "put_nx_info(%p[#%d.%d])"
82 + 3   8 "claim_nx_info(%p[#%d.%d.%d]) %p"
83 +       "clr_nx_info(%p[#%d.%d])"
84 +       "init_nx_info(%p[#%d.%d])"
85 +       "release_nx_info(%p[#%d.%d.%d]) %p"
86 +       "set_nx_info(%p[#%d.%d])"
87 + 4  10 "__hash_nx_info: %p[#%d]"
88 +       "__nx_dynamic_id: [#%d]"
89 +       "__unhash_nx_info: %p[#%d.%d.%d]"
90 + 5  20 "moved task %p into nxi:%p[#%d]"
91 +       "nx_migrate_task(%p,%p[#%d.%d.%d])"
92 +       "task_get_nx_info(%p)"
93 + 6  40 "nx_clear_persistent(%p[#%d])"
94 +
95 +debug_quota:
96 +
97 + 0   1 "quota_sync_dqh(%p,%d) discard inode %p"
98 + 1   2 "quota_sync_dqh(%p,%d)"
99 +       "sync_dquots(%p,%d)"
100 +       "sync_dquots_dqh(%p,%d)"
101 + 3   8 "do_quotactl(%p,%d,cmd=%d,id=%d,%p)"
102 +
103 +debug_switch:
104 +
105 + 0   1 "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]"
106 + 1   2 "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]"
107 + 4  10 "%s: (%s %s) returned %s with %d"
108 +
109 +debug_tag:
110 +
111 + 7  80 "dx_parse_tag(»%s«): %d:#%d"
112 +       "dx_propagate_tag(%p[#%lu.%d]): %d,%d"
113 +
114 +debug_xid:
115 +
116 + 0   1 "__lookup_vx_info(#%u): %p[#%u]"
117 +       "alloc_vx_info(%d) = %p"
118 +       "alloc_vx_info(%d)*"
119 +       "create_vx_info(%d) (dynamic rejected)"
120 +       "create_vx_info(%d) = %p (already there)"
121 +       "create_vx_info(%d) = %p (new)"
122 +       "dealloc_vx_info(%p)"
123 +       "loc_vx_info(%d) = %p (found)"
124 +       "loc_vx_info(%d) = %p (new)"
125 +       "loc_vx_info(%d) = %p (not available)"
126 + 1   2 "create_vx_info(%d)*"
127 +       "loc_vx_info(%d)*"
128 + 2   4 "get_vx_info(%p[#%d.%d])"
129 +       "put_vx_info(%p[#%d.%d])"
130 + 3   8 "claim_vx_info(%p[#%d.%d.%d]) %p"
131 +       "clr_vx_info(%p[#%d.%d])"
132 +       "init_vx_info(%p[#%d.%d])"
133 +       "release_vx_info(%p[#%d.%d.%d]) %p"
134 +       "set_vx_info(%p[#%d.%d])"
135 + 4  10 "__hash_vx_info: %p[#%d]"
136 +       "__unhash_vx_info: %p[#%d.%d.%d]"
137 +       "__vx_dynamic_id: [#%d]"
138 + 5  20 "enter_vx_info(%p[#%d],%p) %p[#%d,%p]"
139 +       "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]"
140 +       "moved task %p into vxi:%p[#%d]"
141 +       "task_get_vx_info(%p)"
142 +       "vx_migrate_task(%p,%p[#%d.%d])"
143 + 6  40 "vx_clear_persistent(%p[#%d])"
144 +       "vx_exit_init(%p[#%d],%p[#%d,%d,%d])"
145 +       "vx_set_init(%p[#%d],%p[#%d,%d,%d])"
146 +       "vx_set_persistent(%p[#%d])"
147 +       "vx_set_reaper(%p[#%d],%p[#%d,%d])"
148 + 7  80 "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]"
149 +
150 +
151 +debug_limit:
152 +
153 + n 2^n "vx_acc_cres[%5d,%s,%2d]: %5d%s"
154 +       "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
155 +
156 + m 2^m "vx_acc_page[%5d,%s,%2d]: %5d%s"
157 +       "vx_acc_pages[%5d,%s,%2d]: %5d += %5d"
158 +       "vx_pages_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
159 diff -NurpP --minimal linux-3.0-rc5/arch/alpha/Kconfig linux-3.0-rc5-vs2.3.1-pre3/arch/alpha/Kconfig
160 --- linux-3.0-rc5/arch/alpha/Kconfig    2011-07-01 11:13:32.000000000 +0200
161 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/alpha/Kconfig       2011-06-10 22:11:24.000000000 +0200
162 @@ -668,6 +668,8 @@ config DUMMY_CONSOLE
163         depends on VGA_HOSE
164         default y
165  
166 +source "kernel/vserver/Kconfig"
167 +
168  source "security/Kconfig"
169  
170  source "crypto/Kconfig"
171 diff -NurpP --minimal linux-3.0-rc5/arch/alpha/kernel/entry.S linux-3.0-rc5-vs2.3.1-pre3/arch/alpha/kernel/entry.S
172 --- linux-3.0-rc5/arch/alpha/kernel/entry.S     2010-10-21 13:06:45.000000000 +0200
173 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/alpha/kernel/entry.S        2011-06-10 22:11:24.000000000 +0200
174 @@ -860,24 +860,15 @@ sys_getxgid:
175         .globl  sys_getxpid
176         .ent    sys_getxpid
177  sys_getxpid:
178 +       lda     $sp, -16($sp)
179 +       stq     $26, 0($sp)
180         .prologue 0
181 -       ldq     $2, TI_TASK($8)
182  
183 -       /* See linux/kernel/timer.c sys_getppid for discussion
184 -          about this loop.  */
185 -       ldq     $3, TASK_GROUP_LEADER($2)
186 -       ldq     $4, TASK_REAL_PARENT($3)
187 -       ldl     $0, TASK_TGID($2)
188 -1:     ldl     $1, TASK_TGID($4)
189 -#ifdef CONFIG_SMP
190 -       mov     $4, $5
191 -       mb
192 -       ldq     $3, TASK_GROUP_LEADER($2)
193 -       ldq     $4, TASK_REAL_PARENT($3)
194 -       cmpeq   $4, $5, $5
195 -       beq     $5, 1b
196 -#endif
197 -       stq     $1, 80($sp)
198 +       lda     $16, 96($sp)
199 +       jsr     $26, do_getxpid
200 +       ldq     $26, 0($sp)
201 +
202 +       lda     $sp, 16($sp)
203         ret
204  .end sys_getxpid
205  
206 diff -NurpP --minimal linux-3.0-rc5/arch/alpha/kernel/ptrace.c linux-3.0-rc5-vs2.3.1-pre3/arch/alpha/kernel/ptrace.c
207 --- linux-3.0-rc5/arch/alpha/kernel/ptrace.c    2011-01-05 21:48:40.000000000 +0100
208 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/alpha/kernel/ptrace.c       2011-06-10 22:11:24.000000000 +0200
209 @@ -13,6 +13,7 @@
210  #include <linux/user.h>
211  #include <linux/security.h>
212  #include <linux/signal.h>
213 +#include <linux/vs_base.h>
214  
215  #include <asm/uaccess.h>
216  #include <asm/pgtable.h>
217 diff -NurpP --minimal linux-3.0-rc5/arch/alpha/kernel/systbls.S linux-3.0-rc5-vs2.3.1-pre3/arch/alpha/kernel/systbls.S
218 --- linux-3.0-rc5/arch/alpha/kernel/systbls.S   2011-07-01 11:13:32.000000000 +0200
219 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/alpha/kernel/systbls.S      2011-06-10 22:11:24.000000000 +0200
220 @@ -446,7 +446,7 @@ sys_call_table:
221         .quad sys_stat64                        /* 425 */
222         .quad sys_lstat64
223         .quad sys_fstat64
224 -       .quad sys_ni_syscall                    /* sys_vserver */
225 +       .quad sys_vserver                       /* sys_vserver */
226         .quad sys_ni_syscall                    /* sys_mbind */
227         .quad sys_ni_syscall                    /* sys_get_mempolicy */
228         .quad sys_ni_syscall                    /* sys_set_mempolicy */
229 diff -NurpP --minimal linux-3.0-rc5/arch/alpha/kernel/traps.c linux-3.0-rc5-vs2.3.1-pre3/arch/alpha/kernel/traps.c
230 --- linux-3.0-rc5/arch/alpha/kernel/traps.c     2010-10-21 13:06:46.000000000 +0200
231 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/alpha/kernel/traps.c        2011-06-10 22:11:24.000000000 +0200
232 @@ -183,7 +183,8 @@ die_if_kernel(char * str, struct pt_regs
233  #ifdef CONFIG_SMP
234         printk("CPU %d ", hard_smp_processor_id());
235  #endif
236 -       printk("%s(%d): %s %ld\n", current->comm, task_pid_nr(current), str, err);
237 +       printk("%s(%d[#%u]): %s %ld\n", current->comm,
238 +               task_pid_nr(current), current->xid, str, err);
239         dik_show_regs(regs, r9_15);
240         add_taint(TAINT_DIE);
241         dik_show_trace((unsigned long *)(regs+1));
242 diff -NurpP --minimal linux-3.0-rc5/arch/arm/Kconfig linux-3.0-rc5-vs2.3.1-pre3/arch/arm/Kconfig
243 --- linux-3.0-rc5/arch/arm/Kconfig      2011-07-01 11:13:32.000000000 +0200
244 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/arm/Kconfig 2011-06-10 22:11:24.000000000 +0200
245 @@ -2035,6 +2035,8 @@ source "fs/Kconfig"
246  
247  source "arch/arm/Kconfig.debug"
248  
249 +source "kernel/vserver/Kconfig"
250 +
251  source "security/Kconfig"
252  
253  source "crypto/Kconfig"
254 diff -NurpP --minimal linux-3.0-rc5/arch/arm/kernel/calls.S linux-3.0-rc5-vs2.3.1-pre3/arch/arm/kernel/calls.S
255 --- linux-3.0-rc5/arch/arm/kernel/calls.S       2011-07-01 11:13:32.000000000 +0200
256 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/arm/kernel/calls.S  2011-06-10 22:11:24.000000000 +0200
257 @@ -322,7 +322,7 @@
258  /* 310 */      CALL(sys_request_key)
259                 CALL(sys_keyctl)
260                 CALL(ABI(sys_semtimedop, sys_oabi_semtimedop))
261 -/* vserver */  CALL(sys_ni_syscall)
262 +               CALL(sys_vserver)
263                 CALL(sys_ioprio_set)
264  /* 315 */      CALL(sys_ioprio_get)
265                 CALL(sys_inotify_init)
266 diff -NurpP --minimal linux-3.0-rc5/arch/arm/kernel/process.c linux-3.0-rc5-vs2.3.1-pre3/arch/arm/kernel/process.c
267 --- linux-3.0-rc5/arch/arm/kernel/process.c     2011-05-22 16:16:47.000000000 +0200
268 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/arm/kernel/process.c        2011-06-10 22:11:24.000000000 +0200
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-3.0-rc5/arch/arm/kernel/traps.c linux-3.0-rc5-vs2.3.1-pre3/arch/arm/kernel/traps.c
280 --- linux-3.0-rc5/arch/arm/kernel/traps.c       2011-07-01 11:13:32.000000000 +0200
281 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/arm/kernel/traps.c  2011-06-22 12:39:12.000000000 +0200
282 @@ -242,8 +242,8 @@ static int __die(const char *str, int er
283  
284         print_modules();
285         __show_regs(regs);
286 -       printk(KERN_EMERG "Process %.*s (pid: %d, stack limit = 0x%p)\n",
287 -               TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), thread + 1);
288 +       printk(KERN_EMERG "Process %.*s (pid: %d:#%u, stack limit = 0x%p)\n",
289 +               TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), tsk->xid, thread + 1);
290  
291         if (!user_mode(regs) || in_interrupt()) {
292                 dump_mem(KERN_EMERG, "Stack: ", regs->ARM_sp,
293 diff -NurpP --minimal linux-3.0-rc5/arch/cris/Kconfig linux-3.0-rc5-vs2.3.1-pre3/arch/cris/Kconfig
294 --- linux-3.0-rc5/arch/cris/Kconfig     2011-07-01 11:13:37.000000000 +0200
295 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/cris/Kconfig        2011-06-10 22:11:24.000000000 +0200
296 @@ -678,6 +678,8 @@ source "drivers/staging/Kconfig"
297  
298  source "arch/cris/Kconfig.debug"
299  
300 +source "kernel/vserver/Kconfig"
301 +
302  source "security/Kconfig"
303  
304  source "crypto/Kconfig"
305 diff -NurpP --minimal linux-3.0-rc5/arch/frv/kernel/kernel_thread.S linux-3.0-rc5-vs2.3.1-pre3/arch/frv/kernel/kernel_thread.S
306 --- linux-3.0-rc5/arch/frv/kernel/kernel_thread.S       2008-12-25 00:26:37.000000000 +0100
307 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/frv/kernel/kernel_thread.S  2011-06-10 22:11:24.000000000 +0200
308 @@ -37,7 +37,7 @@ kernel_thread:
309  
310         # start by forking the current process, but with shared VM
311         setlos.p        #__NR_clone,gr7         ; syscall number
312 -       ori             gr10,#CLONE_VM,gr8      ; first syscall arg     [clone_flags]
313 +       ori             gr10,#CLONE_KT,gr8      ; first syscall arg     [clone_flags]
314         sethi.p         #0xe4e4,gr9             ; second syscall arg    [newsp]
315         setlo           #0xe4e4,gr9
316         setlos.p        #0,gr10                 ; third syscall arg     [parent_tidptr]
317 diff -NurpP --minimal linux-3.0-rc5/arch/h8300/Kconfig linux-3.0-rc5-vs2.3.1-pre3/arch/h8300/Kconfig
318 --- linux-3.0-rc5/arch/h8300/Kconfig    2011-07-01 11:13:37.000000000 +0200
319 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/h8300/Kconfig       2011-06-10 22:11:24.000000000 +0200
320 @@ -213,6 +213,8 @@ source "fs/Kconfig"
321  
322  source "arch/h8300/Kconfig.debug"
323  
324 +source "kernel/vserver/Kconfig"
325 +
326  source "security/Kconfig"
327  
328  source "crypto/Kconfig"
329 diff -NurpP --minimal linux-3.0-rc5/arch/ia64/Kconfig linux-3.0-rc5-vs2.3.1-pre3/arch/ia64/Kconfig
330 --- linux-3.0-rc5/arch/ia64/Kconfig     2011-07-01 11:13:37.000000000 +0200
331 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/ia64/Kconfig        2011-06-10 22:11:24.000000000 +0200
332 @@ -671,6 +671,8 @@ source "fs/Kconfig"
333  
334  source "arch/ia64/Kconfig.debug"
335  
336 +source "kernel/vserver/Kconfig"
337 +
338  source "security/Kconfig"
339  
340  source "crypto/Kconfig"
341 diff -NurpP --minimal linux-3.0-rc5/arch/ia64/include/asm/tlb.h linux-3.0-rc5-vs2.3.1-pre3/arch/ia64/include/asm/tlb.h
342 --- linux-3.0-rc5/arch/ia64/include/asm/tlb.h   2011-07-01 11:13:37.000000000 +0200
343 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/ia64/include/asm/tlb.h      2011-06-10 22:11:24.000000000 +0200
344 @@ -40,6 +40,7 @@
345  #include <linux/mm.h>
346  #include <linux/pagemap.h>
347  #include <linux/swap.h>
348 +#include <linux/vs_memory.h>
349  
350  #include <asm/pgalloc.h>
351  #include <asm/processor.h>
352 diff -NurpP --minimal linux-3.0-rc5/arch/ia64/kernel/entry.S linux-3.0-rc5-vs2.3.1-pre3/arch/ia64/kernel/entry.S
353 --- linux-3.0-rc5/arch/ia64/kernel/entry.S      2011-07-01 11:13:38.000000000 +0200
354 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/ia64/kernel/entry.S 2011-06-10 22:11:24.000000000 +0200
355 @@ -1714,7 +1714,7 @@ sys_call_table:
356         data8 sys_mq_notify
357         data8 sys_mq_getsetattr
358         data8 sys_kexec_load
359 -       data8 sys_ni_syscall                    // reserved for vserver
360 +       data8 sys_vserver
361         data8 sys_waitid                        // 1270
362         data8 sys_add_key
363         data8 sys_request_key
364 diff -NurpP --minimal linux-3.0-rc5/arch/ia64/kernel/perfmon.c linux-3.0-rc5-vs2.3.1-pre3/arch/ia64/kernel/perfmon.c
365 --- linux-3.0-rc5/arch/ia64/kernel/perfmon.c    2011-03-15 18:06:39.000000000 +0100
366 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/ia64/kernel/perfmon.c       2011-06-10 22:11:24.000000000 +0200
367 @@ -42,6 +42,7 @@
368  #include <linux/completion.h>
369  #include <linux/tracehook.h>
370  #include <linux/slab.h>
371 +#include <linux/vs_memory.h>
372  
373  #include <asm/errno.h>
374  #include <asm/intrinsics.h>
375 diff -NurpP --minimal linux-3.0-rc5/arch/ia64/kernel/process.c linux-3.0-rc5-vs2.3.1-pre3/arch/ia64/kernel/process.c
376 --- linux-3.0-rc5/arch/ia64/kernel/process.c    2011-03-15 18:06:39.000000000 +0100
377 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/ia64/kernel/process.c       2011-06-10 22:11:24.000000000 +0200
378 @@ -109,8 +109,8 @@ show_regs (struct pt_regs *regs)
379         unsigned long ip = regs->cr_iip + ia64_psr(regs)->ri;
380  
381         print_modules();
382 -       printk("\nPid: %d, CPU %d, comm: %20s\n", task_pid_nr(current),
383 -                       smp_processor_id(), current->comm);
384 +       printk("\nPid: %d[#%u], CPU %d, comm: %20s\n", task_pid_nr(current),
385 +                       current->xid, smp_processor_id(), current->comm);
386         printk("psr : %016lx ifs : %016lx ip  : [<%016lx>]    %s (%s)\n",
387                regs->cr_ipsr, regs->cr_ifs, ip, print_tainted(),
388                init_utsname()->release);
389 diff -NurpP --minimal linux-3.0-rc5/arch/ia64/kernel/ptrace.c linux-3.0-rc5-vs2.3.1-pre3/arch/ia64/kernel/ptrace.c
390 --- linux-3.0-rc5/arch/ia64/kernel/ptrace.c     2011-01-05 21:48:59.000000000 +0100
391 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/ia64/kernel/ptrace.c        2011-06-10 22:11:24.000000000 +0200
392 @@ -21,6 +21,7 @@
393  #include <linux/regset.h>
394  #include <linux/elf.h>
395  #include <linux/tracehook.h>
396 +#include <linux/vs_base.h>
397  
398  #include <asm/pgtable.h>
399  #include <asm/processor.h>
400 diff -NurpP --minimal linux-3.0-rc5/arch/ia64/kernel/traps.c linux-3.0-rc5-vs2.3.1-pre3/arch/ia64/kernel/traps.c
401 --- linux-3.0-rc5/arch/ia64/kernel/traps.c      2010-07-07 18:31:01.000000000 +0200
402 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/ia64/kernel/traps.c 2011-06-10 22:11:24.000000000 +0200
403 @@ -59,8 +59,9 @@ die (const char *str, struct pt_regs *re
404         put_cpu();
405  
406         if (++die.lock_owner_depth < 3) {
407 -               printk("%s[%d]: %s %ld [%d]\n",
408 -               current->comm, task_pid_nr(current), str, err, ++die_counter);
409 +               printk("%s[%d[#%u]]: %s %ld [%d]\n",
410 +                       current->comm, task_pid_nr(current), current->xid,
411 +                       str, err, ++die_counter);
412                 if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV)
413                     != NOTIFY_STOP)
414                         show_regs(regs);
415 @@ -323,8 +324,9 @@ handle_fpu_swa (int fp_fault, struct pt_
416                         if ((last.count & 15) < 5 && (ia64_fetchadd(1, &last.count, acq) & 15) < 5) {
417                                 last.time = current_jiffies + 5 * HZ;
418                                 printk(KERN_WARNING
419 -                                       "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
420 -                                       current->comm, task_pid_nr(current), regs->cr_iip + ia64_psr(regs)->ri, isr);
421 +                                       "%s(%d[#%u]): floating-point assist fault at ip %016lx, isr %016lx\n",
422 +                                       current->comm, task_pid_nr(current), current->xid,
423 +                                       regs->cr_iip + ia64_psr(regs)->ri, isr);
424                         }
425                 }
426         }
427 diff -NurpP --minimal linux-3.0-rc5/arch/ia64/mm/fault.c linux-3.0-rc5-vs2.3.1-pre3/arch/ia64/mm/fault.c
428 --- linux-3.0-rc5/arch/ia64/mm/fault.c  2011-07-01 11:13:38.000000000 +0200
429 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/ia64/mm/fault.c     2011-06-10 22:28:23.000000000 +0200
430 @@ -11,6 +11,7 @@
431  #include <linux/kprobes.h>
432  #include <linux/kdebug.h>
433  #include <linux/prefetch.h>
434 +#include <linux/vs_memory.h>
435  
436  #include <asm/pgtable.h>
437  #include <asm/processor.h>
438 diff -NurpP --minimal linux-3.0-rc5/arch/m32r/kernel/traps.c linux-3.0-rc5-vs2.3.1-pre3/arch/m32r/kernel/traps.c
439 --- linux-3.0-rc5/arch/m32r/kernel/traps.c      2009-12-03 20:01:57.000000000 +0100
440 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/m32r/kernel/traps.c 2011-06-10 22:11:24.000000000 +0200
441 @@ -196,8 +196,9 @@ static void show_registers(struct pt_reg
442         } else {
443                 printk("SPI: %08lx\n", sp);
444         }
445 -       printk("Process %s (pid: %d, process nr: %d, stackpage=%08lx)",
446 -               current->comm, task_pid_nr(current), 0xffff & i, 4096+(unsigned long)current);
447 +       printk("Process %s (pid: %d[#%u], process nr: %d, stackpage=%08lx)",
448 +               current->comm, task_pid_nr(current), current->xid,
449 +               0xffff & i, 4096+(unsigned long)current);
450  
451         /*
452          * When in-kernel, we also print out the stack and code at the
453 diff -NurpP --minimal linux-3.0-rc5/arch/m68k/Kconfig linux-3.0-rc5-vs2.3.1-pre3/arch/m68k/Kconfig
454 --- linux-3.0-rc5/arch/m68k/Kconfig     2011-07-01 11:13:38.000000000 +0200
455 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/m68k/Kconfig        2011-06-10 22:11:24.000000000 +0200
456 @@ -241,6 +241,8 @@ source "fs/Kconfig"
457  
458  source "arch/m68k/Kconfig.debug"
459  
460 +source "kernel/vserver/Kconfig"
461 +
462  source "security/Kconfig"
463  
464  source "crypto/Kconfig"
465 diff -NurpP --minimal linux-3.0-rc5/arch/mips/Kconfig linux-3.0-rc5-vs2.3.1-pre3/arch/mips/Kconfig
466 --- linux-3.0-rc5/arch/mips/Kconfig     2011-07-01 11:13:38.000000000 +0200
467 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/mips/Kconfig        2011-06-10 22:11:24.000000000 +0200
468 @@ -2485,6 +2485,8 @@ source "fs/Kconfig"
469  
470  source "arch/mips/Kconfig.debug"
471  
472 +source "kernel/vserver/Kconfig"
473 +
474  source "security/Kconfig"
475  
476  source "crypto/Kconfig"
477 diff -NurpP --minimal linux-3.0-rc5/arch/mips/kernel/ptrace.c linux-3.0-rc5-vs2.3.1-pre3/arch/mips/kernel/ptrace.c
478 --- linux-3.0-rc5/arch/mips/kernel/ptrace.c     2011-07-01 11:13:39.000000000 +0200
479 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/mips/kernel/ptrace.c        2011-06-10 22:11:24.000000000 +0200
480 @@ -25,6 +25,7 @@
481  #include <linux/security.h>
482  #include <linux/audit.h>
483  #include <linux/seccomp.h>
484 +#include <linux/vs_base.h>
485  
486  #include <asm/byteorder.h>
487  #include <asm/cpu.h>
488 @@ -263,6 +264,9 @@ long arch_ptrace(struct task_struct *chi
489         void __user *datavp = (void __user *) data;
490         unsigned long __user *datalp = (void __user *) data;
491  
492 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
493 +               goto out;
494 +
495         switch (request) {
496         /* when I and D space are separate, these will need to be fixed. */
497         case PTRACE_PEEKTEXT: /* read word at location addr. */
498 diff -NurpP --minimal linux-3.0-rc5/arch/mips/kernel/scall32-o32.S linux-3.0-rc5-vs2.3.1-pre3/arch/mips/kernel/scall32-o32.S
499 --- linux-3.0-rc5/arch/mips/kernel/scall32-o32.S        2011-07-01 11:13:39.000000000 +0200
500 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/mips/kernel/scall32-o32.S   2011-06-10 22:11:24.000000000 +0200
501 @@ -523,7 +523,7 @@ einval:     li      v0, -ENOSYS
502         sys     sys_mq_timedreceive     5
503         sys     sys_mq_notify           2       /* 4275 */
504         sys     sys_mq_getsetattr       3
505 -       sys     sys_ni_syscall          0       /* sys_vserver */
506 +       sys     sys_vserver             3
507         sys     sys_waitid              5
508         sys     sys_ni_syscall          0       /* available, was setaltroot */
509         sys     sys_add_key             5       /* 4280 */
510 diff -NurpP --minimal linux-3.0-rc5/arch/mips/kernel/scall64-64.S linux-3.0-rc5-vs2.3.1-pre3/arch/mips/kernel/scall64-64.S
511 --- linux-3.0-rc5/arch/mips/kernel/scall64-64.S 2011-07-01 11:13:39.000000000 +0200
512 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/mips/kernel/scall64-64.S    2011-06-10 22:11:24.000000000 +0200
513 @@ -362,7 +362,7 @@ sys_call_table:
514         PTR     sys_mq_timedreceive
515         PTR     sys_mq_notify
516         PTR     sys_mq_getsetattr               /* 5235 */
517 -       PTR     sys_ni_syscall                  /* sys_vserver */
518 +       PTR     sys_vserver
519         PTR     sys_waitid
520         PTR     sys_ni_syscall                  /* available, was setaltroot */
521         PTR     sys_add_key
522 diff -NurpP --minimal linux-3.0-rc5/arch/mips/kernel/scall64-n32.S linux-3.0-rc5-vs2.3.1-pre3/arch/mips/kernel/scall64-n32.S
523 --- linux-3.0-rc5/arch/mips/kernel/scall64-n32.S        2011-07-01 11:13:39.000000000 +0200
524 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/mips/kernel/scall64-n32.S   2011-06-10 22:11:24.000000000 +0200
525 @@ -361,7 +361,7 @@ EXPORT(sysn32_call_table)
526         PTR     compat_sys_mq_timedreceive
527         PTR     compat_sys_mq_notify
528         PTR     compat_sys_mq_getsetattr
529 -       PTR     sys_ni_syscall                  /* 6240, sys_vserver */
530 +       PTR     sys32_vserver                   /* 6240 */
531         PTR     compat_sys_waitid
532         PTR     sys_ni_syscall                  /* available, was setaltroot */
533         PTR     sys_add_key
534 diff -NurpP --minimal linux-3.0-rc5/arch/mips/kernel/scall64-o32.S linux-3.0-rc5-vs2.3.1-pre3/arch/mips/kernel/scall64-o32.S
535 --- linux-3.0-rc5/arch/mips/kernel/scall64-o32.S        2011-07-01 11:13:39.000000000 +0200
536 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/mips/kernel/scall64-o32.S   2011-06-10 22:11:24.000000000 +0200
537 @@ -480,7 +480,7 @@ sys_call_table:
538         PTR     compat_sys_mq_timedreceive
539         PTR     compat_sys_mq_notify            /* 4275 */
540         PTR     compat_sys_mq_getsetattr
541 -       PTR     sys_ni_syscall                  /* sys_vserver */
542 +       PTR     sys32_vserver
543         PTR     sys_32_waitid
544         PTR     sys_ni_syscall                  /* available, was setaltroot */
545         PTR     sys_add_key                     /* 4280 */
546 diff -NurpP --minimal linux-3.0-rc5/arch/mips/kernel/traps.c linux-3.0-rc5-vs2.3.1-pre3/arch/mips/kernel/traps.c
547 --- linux-3.0-rc5/arch/mips/kernel/traps.c      2011-05-22 16:17:00.000000000 +0200
548 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/mips/kernel/traps.c 2011-06-10 22:11:24.000000000 +0200
549 @@ -343,9 +343,10 @@ void show_registers(struct pt_regs *regs
550  
551         __show_regs(regs);
552         print_modules();
553 -       printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
554 -              current->comm, current->pid, current_thread_info(), current,
555 -             field, current_thread_info()->tp_value);
556 +       printk("Process %s (pid: %d:#%u, threadinfo=%p, task=%p, tls=%0*lx)\n",
557 +               current->comm, task_pid_nr(current), current->xid,
558 +               current_thread_info(), current,
559 +               field, current_thread_info()->tp_value);
560         if (cpu_has_userlocal) {
561                 unsigned long tls;
562  
563 diff -NurpP --minimal linux-3.0-rc5/arch/parisc/Kconfig linux-3.0-rc5-vs2.3.1-pre3/arch/parisc/Kconfig
564 --- linux-3.0-rc5/arch/parisc/Kconfig   2011-07-01 11:13:42.000000000 +0200
565 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/parisc/Kconfig      2011-06-10 22:11:24.000000000 +0200
566 @@ -279,6 +279,8 @@ source "fs/Kconfig"
567  
568  source "arch/parisc/Kconfig.debug"
569  
570 +source "kernel/vserver/Kconfig"
571 +
572  source "security/Kconfig"
573  
574  source "crypto/Kconfig"
575 diff -NurpP --minimal linux-3.0-rc5/arch/parisc/kernel/syscall_table.S linux-3.0-rc5-vs2.3.1-pre3/arch/parisc/kernel/syscall_table.S
576 --- linux-3.0-rc5/arch/parisc/kernel/syscall_table.S    2011-07-01 11:13:43.000000000 +0200
577 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/parisc/kernel/syscall_table.S       2011-06-10 22:11:24.000000000 +0200
578 @@ -361,7 +361,7 @@
579         ENTRY_COMP(mbind)               /* 260 */
580         ENTRY_COMP(get_mempolicy)
581         ENTRY_COMP(set_mempolicy)
582 -       ENTRY_SAME(ni_syscall)  /* 263: reserved for vserver */
583 +       ENTRY_DIFF(vserver)
584         ENTRY_SAME(add_key)
585         ENTRY_SAME(request_key)         /* 265 */
586         ENTRY_SAME(keyctl)
587 diff -NurpP --minimal linux-3.0-rc5/arch/parisc/kernel/traps.c linux-3.0-rc5-vs2.3.1-pre3/arch/parisc/kernel/traps.c
588 --- linux-3.0-rc5/arch/parisc/kernel/traps.c    2009-09-10 15:25:40.000000000 +0200
589 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/parisc/kernel/traps.c       2011-06-10 22:11:24.000000000 +0200
590 @@ -236,8 +236,9 @@ void die_if_kernel(char *str, struct pt_
591                 if (err == 0)
592                         return; /* STFU */
593  
594 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
595 -                       current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
596 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld) at " RFMT "\n",
597 +                       current->comm, task_pid_nr(current), current->xid,
598 +                       str, err, regs->iaoq[0]);
599  #ifdef PRINT_USER_FAULTS
600                 /* XXX for debugging only */
601                 show_regs(regs);
602 @@ -270,8 +271,8 @@ void die_if_kernel(char *str, struct pt_
603                 pdc_console_restart();
604         
605         if (err)
606 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
607 -                       current->comm, task_pid_nr(current), str, err);
608 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld)\n",
609 +                       current->comm, task_pid_nr(current), current->xid, str, err);
610  
611         /* Wot's wrong wif bein' racy? */
612         if (current->thread.flags & PARISC_KERNEL_DEATH) {
613 diff -NurpP --minimal linux-3.0-rc5/arch/parisc/mm/fault.c linux-3.0-rc5-vs2.3.1-pre3/arch/parisc/mm/fault.c
614 --- linux-3.0-rc5/arch/parisc/mm/fault.c        2010-08-02 16:52:06.000000000 +0200
615 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/parisc/mm/fault.c   2011-06-10 22:11:24.000000000 +0200
616 @@ -237,8 +237,9 @@ bad_area:
617  
618  #ifdef PRINT_USER_FAULTS
619                 printk(KERN_DEBUG "\n");
620 -               printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n",
621 -                   task_pid_nr(tsk), tsk->comm, code, address);
622 +               printk(KERN_DEBUG "do_page_fault() pid=%d:#%u "
623 +                   "command='%s' type=%lu address=0x%08lx\n",
624 +                   task_pid_nr(tsk), tsk->xid, tsk->comm, code, address);
625                 if (vma) {
626                         printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n",
627                                         vma->vm_start, vma->vm_end);
628 diff -NurpP --minimal linux-3.0-rc5/arch/powerpc/Kconfig linux-3.0-rc5-vs2.3.1-pre3/arch/powerpc/Kconfig
629 --- linux-3.0-rc5/arch/powerpc/Kconfig  2011-07-01 11:13:43.000000000 +0200
630 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/powerpc/Kconfig     2011-06-10 22:11:24.000000000 +0200
631 @@ -978,6 +978,8 @@ source "lib/Kconfig"
632  
633  source "arch/powerpc/Kconfig.debug"
634  
635 +source "kernel/vserver/Kconfig"
636 +
637  source "security/Kconfig"
638  
639  config KEYS_COMPAT
640 diff -NurpP --minimal linux-3.0-rc5/arch/powerpc/include/asm/unistd.h linux-3.0-rc5-vs2.3.1-pre3/arch/powerpc/include/asm/unistd.h
641 --- linux-3.0-rc5/arch/powerpc/include/asm/unistd.h     2011-07-01 11:13:44.000000000 +0200
642 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/powerpc/include/asm/unistd.h        2011-06-10 22:11:24.000000000 +0200
643 @@ -275,7 +275,7 @@
644  #endif
645  #define __NR_rtas              255
646  #define __NR_sys_debug_setcontext 256
647 -/* Number 257 is reserved for vserver */
648 +#define __NR_vserver           257
649  #define __NR_migrate_pages     258
650  #define __NR_mbind             259
651  #define __NR_get_mempolicy     260
652 diff -NurpP --minimal linux-3.0-rc5/arch/powerpc/kernel/process.c linux-3.0-rc5-vs2.3.1-pre3/arch/powerpc/kernel/process.c
653 --- linux-3.0-rc5/arch/powerpc/kernel/process.c 2011-07-01 11:13:44.000000000 +0200
654 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/powerpc/kernel/process.c    2011-06-10 22:11:24.000000000 +0200
655 @@ -656,8 +656,9 @@ void show_regs(struct pt_regs * regs)
656  #else
657                 printk("DAR: "REG", DSISR: %08lx\n", regs->dar, regs->dsisr);
658  #endif
659 -       printk("TASK = %p[%d] '%s' THREAD: %p",
660 -              current, task_pid_nr(current), current->comm, task_thread_info(current));
661 +       printk("TASK = %p[%d,#%u] '%s' THREAD: %p",
662 +              current, task_pid_nr(current), current->xid,
663 +              current->comm, task_thread_info(current));
664  
665  #ifdef CONFIG_SMP
666         printk(" CPU: %d", raw_smp_processor_id());
667 diff -NurpP --minimal linux-3.0-rc5/arch/powerpc/kernel/traps.c linux-3.0-rc5-vs2.3.1-pre3/arch/powerpc/kernel/traps.c
668 --- linux-3.0-rc5/arch/powerpc/kernel/traps.c   2011-07-01 11:13:44.000000000 +0200
669 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/powerpc/kernel/traps.c      2011-06-10 22:11:24.000000000 +0200
670 @@ -1075,8 +1075,9 @@ void nonrecoverable_exception(struct pt_
671  
672  void trace_syscall(struct pt_regs *regs)
673  {
674 -       printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
675 -              current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
676 +       printk("Task: %p(%d[#%u]), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
677 +              current, task_pid_nr(current), current->xid,
678 +              regs->nip, regs->link, regs->gpr[0],
679                regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
680  }
681  
682 diff -NurpP --minimal linux-3.0-rc5/arch/powerpc/kernel/vdso.c linux-3.0-rc5-vs2.3.1-pre3/arch/powerpc/kernel/vdso.c
683 --- linux-3.0-rc5/arch/powerpc/kernel/vdso.c    2011-05-22 16:17:02.000000000 +0200
684 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/powerpc/kernel/vdso.c       2011-06-10 22:11:24.000000000 +0200
685 @@ -23,6 +23,7 @@
686  #include <linux/security.h>
687  #include <linux/bootmem.h>
688  #include <linux/memblock.h>
689 +#include <linux/vs_memory.h>
690  
691  #include <asm/pgtable.h>
692  #include <asm/system.h>
693 diff -NurpP --minimal linux-3.0-rc5/arch/s390/Kconfig linux-3.0-rc5-vs2.3.1-pre3/arch/s390/Kconfig
694 --- linux-3.0-rc5/arch/s390/Kconfig     2011-07-01 11:13:45.000000000 +0200
695 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/s390/Kconfig        2011-07-01 11:35:34.000000000 +0200
696 @@ -628,6 +628,8 @@ source "fs/Kconfig"
697  
698  source "arch/s390/Kconfig.debug"
699  
700 +source "kernel/vserver/Kconfig"
701 +
702  source "security/Kconfig"
703  
704  source "crypto/Kconfig"
705 diff -NurpP --minimal linux-3.0-rc5/arch/s390/include/asm/tlb.h linux-3.0-rc5-vs2.3.1-pre3/arch/s390/include/asm/tlb.h
706 --- linux-3.0-rc5/arch/s390/include/asm/tlb.h   2011-07-01 11:13:45.000000000 +0200
707 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/s390/include/asm/tlb.h      2011-06-15 02:40:14.000000000 +0200
708 @@ -24,6 +24,8 @@
709  #include <linux/mm.h>
710  #include <linux/pagemap.h>
711  #include <linux/swap.h>
712 +#include <linux/vs_memory.h>
713 +
714  #include <asm/processor.h>
715  #include <asm/pgalloc.h>
716  #include <asm/tlbflush.h>
717 diff -NurpP --minimal linux-3.0-rc5/arch/s390/include/asm/unistd.h linux-3.0-rc5-vs2.3.1-pre3/arch/s390/include/asm/unistd.h
718 --- linux-3.0-rc5/arch/s390/include/asm/unistd.h        2011-07-01 11:13:45.000000000 +0200
719 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/s390/include/asm/unistd.h   2011-06-10 22:11:24.000000000 +0200
720 @@ -202,7 +202,7 @@
721  #define __NR_clock_gettime     (__NR_timer_create+6)
722  #define __NR_clock_getres      (__NR_timer_create+7)
723  #define __NR_clock_nanosleep   (__NR_timer_create+8)
724 -/* Number 263 is reserved for vserver */
725 +#define __NR_vserver           263
726  #define __NR_statfs64          265
727  #define __NR_fstatfs64         266
728  #define __NR_remap_file_pages  267
729 diff -NurpP --minimal linux-3.0-rc5/arch/s390/kernel/ptrace.c linux-3.0-rc5-vs2.3.1-pre3/arch/s390/kernel/ptrace.c
730 --- linux-3.0-rc5/arch/s390/kernel/ptrace.c     2011-03-15 18:06:45.000000000 +0100
731 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/s390/kernel/ptrace.c        2011-06-10 22:11:24.000000000 +0200
732 @@ -20,6 +20,7 @@
733  #include <linux/regset.h>
734  #include <linux/tracehook.h>
735  #include <linux/seccomp.h>
736 +#include <linux/vs_base.h>
737  #include <trace/syscall.h>
738  #include <asm/compat.h>
739  #include <asm/segment.h>
740 diff -NurpP --minimal linux-3.0-rc5/arch/s390/kernel/syscalls.S linux-3.0-rc5-vs2.3.1-pre3/arch/s390/kernel/syscalls.S
741 --- linux-3.0-rc5/arch/s390/kernel/syscalls.S   2011-07-01 11:13:45.000000000 +0200
742 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/s390/kernel/syscalls.S      2011-06-10 22:11:24.000000000 +0200
743 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
744  SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper)       /* 260 */
745  SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
746  SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
747 -NI_SYSCALL                                                     /* reserved for vserver */
748 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
749  SYSCALL(sys_s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
750  SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
751  SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
752 diff -NurpP --minimal linux-3.0-rc5/arch/sh/Kconfig linux-3.0-rc5-vs2.3.1-pre3/arch/sh/Kconfig
753 --- linux-3.0-rc5/arch/sh/Kconfig       2011-07-01 11:13:45.000000000 +0200
754 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/sh/Kconfig  2011-06-10 22:11:24.000000000 +0200
755 @@ -888,6 +888,8 @@ source "fs/Kconfig"
756  
757  source "arch/sh/Kconfig.debug"
758  
759 +source "kernel/vserver/Kconfig"
760 +
761  source "security/Kconfig"
762  
763  source "crypto/Kconfig"
764 diff -NurpP --minimal linux-3.0-rc5/arch/sh/kernel/irq.c linux-3.0-rc5-vs2.3.1-pre3/arch/sh/kernel/irq.c
765 --- linux-3.0-rc5/arch/sh/kernel/irq.c  2011-05-22 16:17:07.000000000 +0200
766 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/sh/kernel/irq.c     2011-06-10 22:11:24.000000000 +0200
767 @@ -13,6 +13,7 @@
768  #include <linux/seq_file.h>
769  #include <linux/ftrace.h>
770  #include <linux/delay.h>
771 +// #include <linux/vs_context.h>
772  #include <linux/ratelimit.h>
773  #include <asm/processor.h>
774  #include <asm/machvec.h>
775 diff -NurpP --minimal linux-3.0-rc5/arch/sh/kernel/vsyscall/vsyscall.c linux-3.0-rc5-vs2.3.1-pre3/arch/sh/kernel/vsyscall/vsyscall.c
776 --- linux-3.0-rc5/arch/sh/kernel/vsyscall/vsyscall.c    2011-05-22 16:17:07.000000000 +0200
777 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/sh/kernel/vsyscall/vsyscall.c       2011-06-10 22:11:24.000000000 +0200
778 @@ -18,6 +18,7 @@
779  #include <linux/elf.h>
780  #include <linux/sched.h>
781  #include <linux/err.h>
782 +#include <linux/vs_memory.h>
783  
784  /*
785   * Should the kernel map a VDSO page into processes and pass its
786 diff -NurpP --minimal linux-3.0-rc5/arch/sparc/Kconfig linux-3.0-rc5-vs2.3.1-pre3/arch/sparc/Kconfig
787 --- linux-3.0-rc5/arch/sparc/Kconfig    2011-07-01 11:13:46.000000000 +0200
788 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/sparc/Kconfig       2011-06-15 02:40:14.000000000 +0200
789 @@ -601,6 +601,8 @@ source "fs/Kconfig"
790  
791  source "arch/sparc/Kconfig.debug"
792  
793 +source "kernel/vserver/Kconfig"
794 +
795  source "security/Kconfig"
796  
797  source "crypto/Kconfig"
798 diff -NurpP --minimal linux-3.0-rc5/arch/sparc/include/asm/tlb_64.h linux-3.0-rc5-vs2.3.1-pre3/arch/sparc/include/asm/tlb_64.h
799 --- linux-3.0-rc5/arch/sparc/include/asm/tlb_64.h       2011-07-01 11:13:46.000000000 +0200
800 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/sparc/include/asm/tlb_64.h  2011-06-10 22:11:24.000000000 +0200
801 @@ -3,6 +3,7 @@
802  
803  #include <linux/swap.h>
804  #include <linux/pagemap.h>
805 +#include <linux/vs_memory.h>
806  #include <asm/pgalloc.h>
807  #include <asm/tlbflush.h>
808  #include <asm/mmu_context.h>
809 diff -NurpP --minimal linux-3.0-rc5/arch/sparc/include/asm/unistd.h linux-3.0-rc5-vs2.3.1-pre3/arch/sparc/include/asm/unistd.h
810 --- linux-3.0-rc5/arch/sparc/include/asm/unistd.h       2011-07-01 11:13:46.000000000 +0200
811 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/sparc/include/asm/unistd.h  2011-06-10 22:11:24.000000000 +0200
812 @@ -335,7 +335,7 @@
813  #define __NR_timer_getoverrun  264
814  #define __NR_timer_delete      265
815  #define __NR_timer_create      266
816 -/* #define __NR_vserver                267 Reserved for VSERVER */
817 +#define __NR_vserver           267
818  #define __NR_io_setup          268
819  #define __NR_io_destroy                269
820  #define __NR_io_submit         270
821 diff -NurpP --minimal linux-3.0-rc5/arch/sparc/kernel/systbls_32.S linux-3.0-rc5-vs2.3.1-pre3/arch/sparc/kernel/systbls_32.S
822 --- linux-3.0-rc5/arch/sparc/kernel/systbls_32.S        2011-07-01 11:13:46.000000000 +0200
823 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/sparc/kernel/systbls_32.S   2011-06-10 22:11:24.000000000 +0200
824 @@ -70,7 +70,7 @@ sys_call_table:
825  /*250*/        .long sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
826  /*255*/        .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
827  /*260*/        .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
828 -/*265*/        .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
829 +/*265*/        .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
830  /*270*/        .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
831  /*275*/        .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
832  /*280*/        .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
833 diff -NurpP --minimal linux-3.0-rc5/arch/sparc/kernel/systbls_64.S linux-3.0-rc5-vs2.3.1-pre3/arch/sparc/kernel/systbls_64.S
834 --- linux-3.0-rc5/arch/sparc/kernel/systbls_64.S        2011-07-01 11:13:46.000000000 +0200
835 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/sparc/kernel/systbls_64.S   2011-06-10 22:11:24.000000000 +0200
836 @@ -71,7 +71,7 @@ sys_call_table32:
837  /*250*/        .word sys_mremap, compat_sys_sysctl, sys32_getsid, sys_fdatasync, sys32_nfsservctl
838         .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
839  /*260*/        .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
840 -       .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
841 +       .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
842  /*270*/        .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
843         .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
844  /*280*/        .word sys32_tee, sys_add_key, sys_request_key, sys_keyctl, compat_sys_openat
845 @@ -148,7 +148,7 @@ sys_call_table:
846  /*250*/        .word sys_64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
847         .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
848  /*260*/        .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
849 -       .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
850 +       .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
851  /*270*/        .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
852         .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
853  /*280*/        .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
854 diff -NurpP --minimal linux-3.0-rc5/arch/um/Kconfig.rest linux-3.0-rc5-vs2.3.1-pre3/arch/um/Kconfig.rest
855 --- linux-3.0-rc5/arch/um/Kconfig.rest  2009-06-11 17:12:19.000000000 +0200
856 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/um/Kconfig.rest     2011-06-10 22:11:24.000000000 +0200
857 @@ -18,6 +18,8 @@ source "drivers/connector/Kconfig"
858  
859  source "fs/Kconfig"
860  
861 +source "kernel/vserver/Kconfig"
862 +
863  source "security/Kconfig"
864  
865  source "crypto/Kconfig"
866 diff -NurpP --minimal linux-3.0-rc5/arch/um/include/asm/tlb.h linux-3.0-rc5-vs2.3.1-pre3/arch/um/include/asm/tlb.h
867 --- linux-3.0-rc5/arch/um/include/asm/tlb.h     2011-07-01 11:13:46.000000000 +0200
868 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/um/include/asm/tlb.h        2011-06-10 22:11:24.000000000 +0200
869 @@ -3,6 +3,7 @@
870  
871  #include <linux/pagemap.h>
872  #include <linux/swap.h>
873 +#include <linux/vs_memory.h>
874  #include <asm/percpu.h>
875  #include <asm/pgalloc.h>
876  #include <asm/tlbflush.h>
877 diff -NurpP --minimal linux-3.0-rc5/arch/um/include/shared/kern_constants.h linux-3.0-rc5-vs2.3.1-pre3/arch/um/include/shared/kern_constants.h
878 --- linux-3.0-rc5/arch/um/include/shared/kern_constants.h       1970-01-01 01:00:00.000000000 +0100
879 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/um/include/shared/kern_constants.h  2011-06-10 22:11:24.000000000 +0200
880 @@ -0,0 +1 @@
881 +#include "../../../../include/generated/asm-offsets.h"
882 diff -NurpP --minimal linux-3.0-rc5/arch/um/include/shared/user_constants.h linux-3.0-rc5-vs2.3.1-pre3/arch/um/include/shared/user_constants.h
883 --- linux-3.0-rc5/arch/um/include/shared/user_constants.h       1970-01-01 01:00:00.000000000 +0100
884 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/um/include/shared/user_constants.h  2011-06-10 22:11:24.000000000 +0200
885 @@ -0,0 +1,40 @@
886 +/*
887 + * DO NOT MODIFY.
888 + *
889 + * This file was generated by arch/um/Makefile
890 + *
891 + */
892 +
893 +#define HOST_SC_CR2 176 /* offsetof(struct sigcontext, cr2)    # */
894 +#define HOST_SC_ERR 152 /* offsetof(struct sigcontext, err)    # */
895 +#define HOST_SC_TRAPNO 160 /* offsetof(struct sigcontext, trapno)      # */
896 +#define HOST_FP_SIZE 64 /* sizeof(struct _fpstate) / sizeof(unsigned long)     # */
897 +#define HOST_RBX 5 /* RBX      # */
898 +#define HOST_RCX 11 /* RCX     # */
899 +#define HOST_RDI 14 /* RDI     # */
900 +#define HOST_RSI 13 /* RSI     # */
901 +#define HOST_RDX 12 /* RDX     # */
902 +#define HOST_RBP 4 /* RBP      # */
903 +#define HOST_RAX 10 /* RAX     # */
904 +#define HOST_R8 9 /* R8        # */
905 +#define HOST_R9 8 /* R9        # */
906 +#define HOST_R10 7 /* R10      # */
907 +#define HOST_R11 6 /* R11      # */
908 +#define HOST_R12 3 /* R12      # */
909 +#define HOST_R13 2 /* R13      # */
910 +#define HOST_R14 1 /* R14      # */
911 +#define HOST_R15 0 /* R15      # */
912 +#define HOST_ORIG_RAX 15 /* ORIG_RAX   # */
913 +#define HOST_CS 17 /* CS       # */
914 +#define HOST_SS 20 /* SS       # */
915 +#define HOST_EFLAGS 18 /* EFLAGS       # */
916 +#define HOST_IP 16 /* RIP      # */
917 +#define HOST_SP 19 /* RSP      # */
918 +#define UM_FRAME_SIZE 216 /* sizeof(struct user_regs_struct)   # */
919 +#define UM_POLLIN 1 /* POLLIN  # */
920 +#define UM_POLLPRI 2 /* POLLPRI        # */
921 +#define UM_POLLOUT 4 /* POLLOUT        # */
922 +#define UM_PROT_READ 1 /* PROT_READ    # */
923 +#define UM_PROT_WRITE 2 /* PROT_WRITE  # */
924 +#define UM_PROT_EXEC 4 /* PROT_EXEC    # */
925 +
926 diff -NurpP --minimal linux-3.0-rc5/arch/x86/Kconfig linux-3.0-rc5-vs2.3.1-pre3/arch/x86/Kconfig
927 --- linux-3.0-rc5/arch/x86/Kconfig      2011-07-01 11:13:47.000000000 +0200
928 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/x86/Kconfig 2011-06-10 22:11:24.000000000 +0200
929 @@ -2159,6 +2159,8 @@ source "fs/Kconfig"
930  
931  source "arch/x86/Kconfig.debug"
932  
933 +source "kernel/vserver/Kconfig"
934 +
935  source "security/Kconfig"
936  
937  source "crypto/Kconfig"
938 diff -NurpP --minimal linux-3.0-rc5/arch/x86/ia32/ia32entry.S linux-3.0-rc5-vs2.3.1-pre3/arch/x86/ia32/ia32entry.S
939 --- linux-3.0-rc5/arch/x86/ia32/ia32entry.S     2011-07-01 11:13:47.000000000 +0200
940 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/x86/ia32/ia32entry.S        2011-06-10 22:11:24.000000000 +0200
941 @@ -776,7 +776,7 @@ ia32_sys_call_table:
942         .quad sys_tgkill                /* 270 */
943         .quad compat_sys_utimes
944         .quad sys32_fadvise64_64
945 -       .quad quiet_ni_syscall  /* sys_vserver */
946 +       .quad sys32_vserver
947         .quad sys_mbind
948         .quad compat_sys_get_mempolicy  /* 275 */
949         .quad sys_set_mempolicy
950 diff -NurpP --minimal linux-3.0-rc5/arch/x86/include/asm/unistd_64.h linux-3.0-rc5-vs2.3.1-pre3/arch/x86/include/asm/unistd_64.h
951 --- linux-3.0-rc5/arch/x86/include/asm/unistd_64.h      2011-07-01 11:13:47.000000000 +0200
952 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/x86/include/asm/unistd_64.h 2011-06-10 22:11:24.000000000 +0200
953 @@ -535,7 +535,7 @@ __SYSCALL(__NR_tgkill, sys_tgkill)
954  #define __NR_utimes                            235
955  __SYSCALL(__NR_utimes, sys_utimes)
956  #define __NR_vserver                           236
957 -__SYSCALL(__NR_vserver, sys_ni_syscall)
958 +__SYSCALL(__NR_vserver, sys_vserver)
959  #define __NR_mbind                             237
960  __SYSCALL(__NR_mbind, sys_mbind)
961  #define __NR_set_mempolicy                     238
962 diff -NurpP --minimal linux-3.0-rc5/arch/x86/kernel/syscall_table_32.S linux-3.0-rc5-vs2.3.1-pre3/arch/x86/kernel/syscall_table_32.S
963 --- linux-3.0-rc5/arch/x86/kernel/syscall_table_32.S    2011-07-01 11:13:48.000000000 +0200
964 +++ linux-3.0-rc5-vs2.3.1-pre3/arch/x86/kernel/syscall_table_32.S       2011-06-10 22:11:24.000000000 +0200
965 @@ -272,7 +272,7 @@ ENTRY(sys_call_table)
966         .long sys_tgkill        /* 270 */
967         .long sys_utimes
968         .long sys_fadvise64_64
969 -       .long sys_ni_syscall    /* sys_vserver */
970 +       .long sys_vserver
971         .long sys_mbind
972         .long sys_get_mempolicy
973         .long sys_set_mempolicy
974 diff -NurpP --minimal linux-3.0-rc5/block/genhd.c linux-3.0-rc5-vs2.3.1-pre3/block/genhd.c
975 --- linux-3.0-rc5/block/genhd.c 2011-07-01 11:13:48.000000000 +0200
976 +++ linux-3.0-rc5-vs2.3.1-pre3/block/genhd.c    2011-07-01 11:35:34.000000000 +0200
977 @@ -1154,17 +1154,17 @@ static int diskstats_show(struct seq_fil
978                 cpu = part_stat_lock();
979                 part_round_stats(cpu, hd);
980                 part_stat_unlock();
981 -               seq_printf(seqf, "%4d %7d %s %lu %lu %llu "
982 -                          "%u %lu %lu %llu %u %u %u %u\n",
983 +               seq_printf(seqf, "%4d %7d %s %lu %lu %lu "
984 +                          "%u %lu %lu %lu %u %u %u %u\n",
985                            MAJOR(part_devt(hd)), MINOR(part_devt(hd)),
986                            disk_name(gp, hd->partno, buf),
987                            part_stat_read(hd, ios[READ]),
988                            part_stat_read(hd, merges[READ]),
989 -                          (unsigned long long)part_stat_read(hd, sectors[READ]),
990 +                          part_stat_read(hd, sectors[READ]),
991                            jiffies_to_msecs(part_stat_read(hd, ticks[READ])),
992                            part_stat_read(hd, ios[WRITE]),
993                            part_stat_read(hd, merges[WRITE]),
994 -                          (unsigned long long)part_stat_read(hd, sectors[WRITE]),
995 +                          part_stat_read(hd, sectors[WRITE]),
996                            jiffies_to_msecs(part_stat_read(hd, ticks[WRITE])),
997                            part_in_flight(hd),
998                            jiffies_to_msecs(part_stat_read(hd, io_ticks)),
999 diff -NurpP --minimal linux-3.0-rc5/drivers/block/Kconfig linux-3.0-rc5-vs2.3.1-pre3/drivers/block/Kconfig
1000 --- linux-3.0-rc5/drivers/block/Kconfig 2011-07-01 11:13:50.000000000 +0200
1001 +++ linux-3.0-rc5-vs2.3.1-pre3/drivers/block/Kconfig    2011-06-10 22:11:24.000000000 +0200
1002 @@ -273,6 +273,13 @@ config BLK_DEV_CRYPTOLOOP
1003  
1004  source "drivers/block/drbd/Kconfig"
1005  
1006 +config BLK_DEV_VROOT
1007 +       tristate "Virtual Root device support"
1008 +       depends on QUOTACTL
1009 +       ---help---
1010 +         Saying Y here will allow you to use quota/fs ioctls on a shared
1011 +         partition within a virtual server without compromising security.
1012 +
1013  config BLK_DEV_NBD
1014         tristate "Network block device support"
1015         depends on NET
1016 diff -NurpP --minimal linux-3.0-rc5/drivers/block/Makefile linux-3.0-rc5-vs2.3.1-pre3/drivers/block/Makefile
1017 --- linux-3.0-rc5/drivers/block/Makefile        2011-07-01 11:13:50.000000000 +0200
1018 +++ linux-3.0-rc5-vs2.3.1-pre3/drivers/block/Makefile   2011-06-10 22:11:24.000000000 +0200
1019 @@ -34,6 +34,7 @@ obj-$(CONFIG_VIODASD)         += viodasd.o
1020  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
1021  obj-$(CONFIG_BLK_DEV_UB)       += ub.o
1022  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
1023 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
1024  
1025  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
1026  obj-$(CONFIG_XEN_BLKDEV_BACKEND)       += xen-blkback/
1027 diff -NurpP --minimal linux-3.0-rc5/drivers/block/loop.c linux-3.0-rc5-vs2.3.1-pre3/drivers/block/loop.c
1028 --- linux-3.0-rc5/drivers/block/loop.c  2011-07-01 11:13:50.000000000 +0200
1029 +++ linux-3.0-rc5-vs2.3.1-pre3/drivers/block/loop.c     2011-06-10 22:11:24.000000000 +0200
1030 @@ -75,6 +75,7 @@
1031  #include <linux/kthread.h>
1032  #include <linux/splice.h>
1033  #include <linux/sysfs.h>
1034 +#include <linux/vs_context.h>
1035  
1036  #include <asm/uaccess.h>
1037  
1038 @@ -891,6 +892,7 @@ static int loop_set_fd(struct loop_devic
1039         lo->lo_blocksize = lo_blocksize;
1040         lo->lo_device = bdev;
1041         lo->lo_flags = lo_flags;
1042 +       lo->lo_xid = vx_current_xid();
1043         lo->lo_backing_file = file;
1044         lo->transfer = transfer_none;
1045         lo->ioctl = NULL;
1046 @@ -1019,6 +1021,7 @@ static int loop_clr_fd(struct loop_devic
1047         lo->lo_encrypt_key_size = 0;
1048         lo->lo_flags = 0;
1049         lo->lo_thread = NULL;
1050 +       lo->lo_xid = 0;
1051         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
1052         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
1053         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
1054 @@ -1057,7 +1060,7 @@ loop_set_status(struct loop_device *lo, 
1055  
1056         if (lo->lo_encrypt_key_size &&
1057             lo->lo_key_owner != uid &&
1058 -           !capable(CAP_SYS_ADMIN))
1059 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
1060                 return -EPERM;
1061         if (lo->lo_state != Lo_bound)
1062                 return -ENXIO;
1063 @@ -1141,7 +1144,8 @@ loop_get_status(struct loop_device *lo, 
1064         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
1065         info->lo_encrypt_type =
1066                 lo->lo_encryption ? lo->lo_encryption->number : 0;
1067 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
1068 +       if (lo->lo_encrypt_key_size &&
1069 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
1070                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
1071                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
1072                        lo->lo_encrypt_key_size);
1073 @@ -1487,6 +1491,9 @@ static int lo_open(struct block_device *
1074  {
1075         struct loop_device *lo = bdev->bd_disk->private_data;
1076  
1077 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P))
1078 +               return -EACCES;
1079 +
1080         mutex_lock(&lo->lo_ctl_mutex);
1081         lo->lo_refcnt++;
1082         mutex_unlock(&lo->lo_ctl_mutex);
1083 diff -NurpP --minimal linux-3.0-rc5/drivers/block/vroot.c linux-3.0-rc5-vs2.3.1-pre3/drivers/block/vroot.c
1084 --- linux-3.0-rc5/drivers/block/vroot.c 1970-01-01 01:00:00.000000000 +0100
1085 +++ linux-3.0-rc5-vs2.3.1-pre3/drivers/block/vroot.c    2011-06-10 22:11:24.000000000 +0200
1086 @@ -0,0 +1,292 @@
1087 +/*
1088 + *  linux/drivers/block/vroot.c
1089 + *
1090 + *  written by Herbert Pötzl, 9/11/2002
1091 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
1092 + *
1093 + *  based on the loop.c code by Theodore Ts'o.
1094 + *
1095 + * Copyright (C) 2002-2007 by Herbert Pötzl.
1096 + * Redistribution of this file is permitted under the
1097 + * GNU General Public License.
1098 + *
1099 + */
1100 +
1101 +#include <linux/module.h>
1102 +#include <linux/moduleparam.h>
1103 +#include <linux/file.h>
1104 +#include <linux/major.h>
1105 +#include <linux/blkdev.h>
1106 +#include <linux/slab.h>
1107 +
1108 +#include <linux/vroot.h>
1109 +#include <linux/vs_context.h>
1110 +
1111 +
1112 +static int max_vroot = 8;
1113 +
1114 +static struct vroot_device *vroot_dev;
1115 +static struct gendisk **disks;
1116 +
1117 +
1118 +static int vroot_set_dev(
1119 +       struct vroot_device *vr,
1120 +       struct block_device *bdev,
1121 +       unsigned int arg)
1122 +{
1123 +       struct block_device *real_bdev;
1124 +       struct file *file;
1125 +       struct inode *inode;
1126 +       int error;
1127 +
1128 +       error = -EBUSY;
1129 +       if (vr->vr_state != Vr_unbound)
1130 +               goto out;
1131 +
1132 +       error = -EBADF;
1133 +       file = fget(arg);
1134 +       if (!file)
1135 +               goto out;
1136 +
1137 +       error = -EINVAL;
1138 +       inode = file->f_dentry->d_inode;
1139 +
1140 +
1141 +       if (S_ISBLK(inode->i_mode)) {
1142 +               real_bdev = inode->i_bdev;
1143 +               vr->vr_device = real_bdev;
1144 +               __iget(real_bdev->bd_inode);
1145 +       } else
1146 +               goto out_fput;
1147 +
1148 +       vxdprintk(VXD_CBIT(misc, 0),
1149 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
1150 +               vr->vr_number, VXD_DEV(real_bdev));
1151 +
1152 +       vr->vr_state = Vr_bound;
1153 +       error = 0;
1154 +
1155 + out_fput:
1156 +       fput(file);
1157 + out:
1158 +       return error;
1159 +}
1160 +
1161 +static int vroot_clr_dev(
1162 +       struct vroot_device *vr,
1163 +       struct block_device *bdev)
1164 +{
1165 +       struct block_device *real_bdev;
1166 +
1167 +       if (vr->vr_state != Vr_bound)
1168 +               return -ENXIO;
1169 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
1170 +               return -EBUSY;
1171 +
1172 +       real_bdev = vr->vr_device;
1173 +
1174 +       vxdprintk(VXD_CBIT(misc, 0),
1175 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
1176 +               vr->vr_number, VXD_DEV(real_bdev));
1177 +
1178 +       bdput(real_bdev);
1179 +       vr->vr_state = Vr_unbound;
1180 +       vr->vr_device = NULL;
1181 +       return 0;
1182 +}
1183 +
1184 +
1185 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
1186 +       unsigned int cmd, unsigned long arg)
1187 +{
1188 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1189 +       int err;
1190 +
1191 +       down(&vr->vr_ctl_mutex);
1192 +       switch (cmd) {
1193 +       case VROOT_SET_DEV:
1194 +               err = vroot_set_dev(vr, bdev, arg);
1195 +               break;
1196 +       case VROOT_CLR_DEV:
1197 +               err = vroot_clr_dev(vr, bdev);
1198 +               break;
1199 +       default:
1200 +               err = -EINVAL;
1201 +               break;
1202 +       }
1203 +       up(&vr->vr_ctl_mutex);
1204 +       return err;
1205 +}
1206 +
1207 +static int vr_open(struct block_device *bdev, fmode_t mode)
1208 +{
1209 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1210 +
1211 +       down(&vr->vr_ctl_mutex);
1212 +       vr->vr_refcnt++;
1213 +       up(&vr->vr_ctl_mutex);
1214 +       return 0;
1215 +}
1216 +
1217 +static int vr_release(struct gendisk *disk, fmode_t mode)
1218 +{
1219 +       struct vroot_device *vr = disk->private_data;
1220 +
1221 +       down(&vr->vr_ctl_mutex);
1222 +       --vr->vr_refcnt;
1223 +       up(&vr->vr_ctl_mutex);
1224 +       return 0;
1225 +}
1226 +
1227 +static struct block_device_operations vr_fops = {
1228 +       .owner =        THIS_MODULE,
1229 +       .open =         vr_open,
1230 +       .release =      vr_release,
1231 +       .ioctl =        vr_ioctl,
1232 +};
1233 +
1234 +static int vroot_make_request(struct request_queue *q, struct bio *bio)
1235 +{
1236 +       printk("vroot_make_request %p, %p\n", q, bio);
1237 +       bio_io_error(bio);
1238 +       return 0;
1239 +}
1240 +
1241 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
1242 +{
1243 +       struct inode *inode = bdev->bd_inode;
1244 +       struct vroot_device *vr;
1245 +       struct block_device *real_bdev;
1246 +       int minor = iminor(inode);
1247 +
1248 +       vr = &vroot_dev[minor];
1249 +       real_bdev = vr->vr_device;
1250 +
1251 +       vxdprintk(VXD_CBIT(misc, 0),
1252 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1253 +               vr->vr_number, VXD_DEV(real_bdev));
1254 +
1255 +       if (vr->vr_state != Vr_bound)
1256 +               return ERR_PTR(-ENXIO);
1257 +
1258 +       __iget(real_bdev->bd_inode);
1259 +       return real_bdev;
1260 +}
1261 +
1262 +
1263 +
1264 +/*
1265 + * And now the modules code and kernel interface.
1266 + */
1267 +
1268 +module_param(max_vroot, int, 0);
1269 +
1270 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1271 +MODULE_LICENSE("GPL");
1272 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1273 +
1274 +MODULE_AUTHOR ("Herbert Pötzl");
1275 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1276 +
1277 +
1278 +int __init vroot_init(void)
1279 +{
1280 +       int err, i;
1281 +
1282 +       if (max_vroot < 1 || max_vroot > 256) {
1283 +               max_vroot = MAX_VROOT_DEFAULT;
1284 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1285 +                       "(must be between 1 and 256), "
1286 +                       "using default (%d)\n", max_vroot);
1287 +       }
1288 +
1289 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1290 +               return -EIO;
1291 +
1292 +       err = -ENOMEM;
1293 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1294 +       if (!vroot_dev)
1295 +               goto out_mem1;
1296 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1297 +
1298 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1299 +       if (!disks)
1300 +               goto out_mem2;
1301 +
1302 +       for (i = 0; i < max_vroot; i++) {
1303 +               disks[i] = alloc_disk(1);
1304 +               if (!disks[i])
1305 +                       goto out_mem3;
1306 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1307 +               if (!disks[i]->queue)
1308 +                       goto out_mem3;
1309 +               blk_queue_make_request(disks[i]->queue, vroot_make_request);
1310 +       }
1311 +
1312 +       for (i = 0; i < max_vroot; i++) {
1313 +               struct vroot_device *vr = &vroot_dev[i];
1314 +               struct gendisk *disk = disks[i];
1315 +
1316 +               memset(vr, 0, sizeof(*vr));
1317 +               sema_init(&vr->vr_ctl_mutex, 1);
1318 +               vr->vr_number = i;
1319 +               disk->major = VROOT_MAJOR;
1320 +               disk->first_minor = i;
1321 +               disk->fops = &vr_fops;
1322 +               sprintf(disk->disk_name, "vroot%d", i);
1323 +               disk->private_data = vr;
1324 +       }
1325 +
1326 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1327 +       if (err)
1328 +               goto out_mem3;
1329 +
1330 +       for (i = 0; i < max_vroot; i++)
1331 +               add_disk(disks[i]);
1332 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1333 +       return 0;
1334 +
1335 +out_mem3:
1336 +       while (i--)
1337 +               put_disk(disks[i]);
1338 +       kfree(disks);
1339 +out_mem2:
1340 +       kfree(vroot_dev);
1341 +out_mem1:
1342 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1343 +       printk(KERN_ERR "vroot: ran out of memory\n");
1344 +       return err;
1345 +}
1346 +
1347 +void vroot_exit(void)
1348 +{
1349 +       int i;
1350 +
1351 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1352 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1353 +
1354 +       for (i = 0; i < max_vroot; i++) {
1355 +               del_gendisk(disks[i]);
1356 +               put_disk(disks[i]);
1357 +       }
1358 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1359 +
1360 +       kfree(disks);
1361 +       kfree(vroot_dev);
1362 +}
1363 +
1364 +module_init(vroot_init);
1365 +module_exit(vroot_exit);
1366 +
1367 +#ifndef MODULE
1368 +
1369 +static int __init max_vroot_setup(char *str)
1370 +{
1371 +       max_vroot = simple_strtol(str, NULL, 0);
1372 +       return 1;
1373 +}
1374 +
1375 +__setup("max_vroot=", max_vroot_setup);
1376 +
1377 +#endif
1378 +
1379 diff -NurpP --minimal linux-3.0-rc5/drivers/gpu/drm/radeon/r100_reg_safe.h linux-3.0-rc5-vs2.3.1-pre3/drivers/gpu/drm/radeon/r100_reg_safe.h
1380 --- linux-3.0-rc5/drivers/gpu/drm/radeon/r100_reg_safe.h        1970-01-01 01:00:00.000000000 +0100
1381 +++ linux-3.0-rc5-vs2.3.1-pre3/drivers/gpu/drm/radeon/r100_reg_safe.h   2011-06-10 22:11:24.000000000 +0200
1382 @@ -0,0 +1,28 @@
1383 +static const unsigned r100_reg_safe_bm[102] = {
1384 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1385 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1386 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1387 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1388 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1389 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1390 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1391 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1392 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1393 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1394 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1395 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1396 +       0xFFFFFFCF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1397 +       0xFFFFFF9F, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1398 +       0x38E7FE1F, 0xFFC3FF8E, 0x7FF8FFFF, 0xFFFF803C,
1399 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1400 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFEFFFF, 0xFFFFFFFF,
1401 +       0x00000000, 0xFFFFFFFD, 0xFFFFFFFF, 0xFFFFFFFF,
1402 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1403 +       0xFFFFFFFF, 0xFFFCFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1404 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1405 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1406 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1407 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1408 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1409 +       0xFFFFFFFF, 0xFFFFFFEF,
1410 +};
1411 diff -NurpP --minimal linux-3.0-rc5/drivers/gpu/drm/radeon/r200_reg_safe.h linux-3.0-rc5-vs2.3.1-pre3/drivers/gpu/drm/radeon/r200_reg_safe.h
1412 --- linux-3.0-rc5/drivers/gpu/drm/radeon/r200_reg_safe.h        1970-01-01 01:00:00.000000000 +0100
1413 +++ linux-3.0-rc5-vs2.3.1-pre3/drivers/gpu/drm/radeon/r200_reg_safe.h   2011-06-10 22:11:24.000000000 +0200
1414 @@ -0,0 +1,28 @@
1415 +static const unsigned r200_reg_safe_bm[102] = {
1416 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1417 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1418 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1419 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1420 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1421 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1422 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1423 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1424 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1425 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1426 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1427 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1428 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1429 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1430 +       0xFFE7FE1F, 0xF003FFFF, 0x7EFFFFFF, 0xFFFF803C,
1431 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1432 +       0xFFFFFFFF, 0xFFFFEFCE, 0xFFFEFFFF, 0xFFFFFFFE,
1433 +       0x020E0FF0, 0xFFCC83FD, 0xFFFFFFFF, 0xFFFFFFFF,
1434 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1435 +       0xFFFBFFFF, 0xEFFCFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1436 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1437 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1438 +       0xDFDFDFDF, 0x3FFDDFDF, 0xFFFFFFFF, 0xFFFFFF7F,
1439 +       0xFFFFFFFF, 0x00FFFFFF, 0x00000000, 0x00000000,
1440 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1441 +       0xFFFFFE3F, 0xFFFFFFEF,
1442 +};
1443 diff -NurpP --minimal linux-3.0-rc5/drivers/gpu/drm/radeon/r300_reg_safe.h linux-3.0-rc5-vs2.3.1-pre3/drivers/gpu/drm/radeon/r300_reg_safe.h
1444 --- linux-3.0-rc5/drivers/gpu/drm/radeon/r300_reg_safe.h        1970-01-01 01:00:00.000000000 +0100
1445 +++ linux-3.0-rc5-vs2.3.1-pre3/drivers/gpu/drm/radeon/r300_reg_safe.h   2011-06-10 22:11:24.000000000 +0200
1446 @@ -0,0 +1,42 @@
1447 +static const unsigned r300_reg_safe_bm[159] = {
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 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1456 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1457 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1458 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1459 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1460 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1461 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1462 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF03F,
1463 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1464 +       0xFFFFFFFF, 0xFFFFEFCE, 0xF00EBFFF, 0x007C0000,
1465 +       0xF0000078, 0xFF000009, 0xFFFFFFFF, 0xFFFFFFFF,
1466 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1467 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1468 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1469 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1470 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1471 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1472 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1473 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1474 +       0xFFFFF7FF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1475 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1476 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1477 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1478 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1479 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1480 +       0xFFFFFC78, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF,
1481 +       0x38FF8F50, 0xFFF88082, 0xF000000C, 0xFAE009FF,
1482 +       0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
1483 +       0x00000000, 0x0000C100, 0x00000000, 0x00000000,
1484 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1485 +       0x00000000, 0xFFFF0000, 0xFFFFFFFF, 0xFF80FFFF,
1486 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1487 +       0x0003FC01, 0xFFFFFCF8, 0xFF800B19,
1488 +};
1489 diff -NurpP --minimal linux-3.0-rc5/drivers/gpu/drm/radeon/r420_reg_safe.h linux-3.0-rc5-vs2.3.1-pre3/drivers/gpu/drm/radeon/r420_reg_safe.h
1490 --- linux-3.0-rc5/drivers/gpu/drm/radeon/r420_reg_safe.h        1970-01-01 01:00:00.000000000 +0100
1491 +++ linux-3.0-rc5-vs2.3.1-pre3/drivers/gpu/drm/radeon/r420_reg_safe.h   2011-06-10 22:11:24.000000000 +0200
1492 @@ -0,0 +1,42 @@
1493 +static const unsigned r420_reg_safe_bm[159] = {
1494 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1495 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1496 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1497 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1498 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1499 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1500 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1501 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1502 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1503 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1504 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1505 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1506 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1507 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1508 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF03F,
1509 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1510 +       0xFFFFFFFF, 0xFFFFEFCE, 0xF00EBFFF, 0x007C0000,
1511 +       0xF0000078, 0xFF000009, 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 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1520 +       0xFFFFF7FF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1521 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1522 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1523 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1524 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1525 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1526 +       0xFFFFFC78, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF,
1527 +       0x38FF8F50, 0xFFF88082, 0xF000000C, 0xFAE009FF,
1528 +       0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
1529 +       0x00000000, 0x00000100, 0x00000000, 0x00000000,
1530 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1531 +       0x00000000, 0x00000000, 0x00000000, 0xFF800000,
1532 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1533 +       0x0003FC01, 0xFFFFFCF8, 0xFF800B19,
1534 +};
1535 diff -NurpP --minimal linux-3.0-rc5/drivers/gpu/drm/radeon/rn50_reg_safe.h linux-3.0-rc5-vs2.3.1-pre3/drivers/gpu/drm/radeon/rn50_reg_safe.h
1536 --- linux-3.0-rc5/drivers/gpu/drm/radeon/rn50_reg_safe.h        1970-01-01 01:00:00.000000000 +0100
1537 +++ linux-3.0-rc5-vs2.3.1-pre3/drivers/gpu/drm/radeon/rn50_reg_safe.h   2011-06-10 22:11:24.000000000 +0200
1538 @@ -0,0 +1,28 @@
1539 +static const unsigned rn50_reg_safe_bm[102] = {
1540 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1541 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1542 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1543 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1544 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1545 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1546 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1547 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1548 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1549 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1550 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1551 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1552 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1553 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1554 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
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 +       0xFFFFFFFF, 0xFFFFFFFF,
1566 +};
1567 diff -NurpP --minimal linux-3.0-rc5/drivers/gpu/drm/radeon/rs600_reg_safe.h linux-3.0-rc5-vs2.3.1-pre3/drivers/gpu/drm/radeon/rs600_reg_safe.h
1568 --- linux-3.0-rc5/drivers/gpu/drm/radeon/rs600_reg_safe.h       1970-01-01 01:00:00.000000000 +0100
1569 +++ linux-3.0-rc5-vs2.3.1-pre3/drivers/gpu/drm/radeon/rs600_reg_safe.h  2011-06-10 22:11:24.000000000 +0200
1570 @@ -0,0 +1,57 @@
1571 +static const unsigned rs600_reg_safe_bm[219] = {
1572 +       0xFFFFFFFF, 0xFFFFFFFF, 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 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1582 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1583 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1584 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1585 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1586 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF03F,
1587 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1588 +       0xFFFFFFFF, 0xFFFFEFCE, 0xF00EBFFF, 0x007C0000,
1589 +       0xF0000078, 0xFF000009, 0xFFFFFFFF, 0xFFFFFFFF,
1590 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1591 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1592 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1593 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1594 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1595 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1596 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1597 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1598 +       0xFFFFF7FF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1599 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1600 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1601 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1602 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1603 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1604 +       0xFFFFFC78, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF,
1605 +       0x38FF8F50, 0xFFF88082, 0xF000000C, 0xFAE009FF,
1606 +       0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
1607 +       0x00000000, 0x00000100, 0x00000000, 0x00000000,
1608 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1609 +       0x00000000, 0x00000000, 0x00000000, 0xFF800000,
1610 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1611 +       0x0003FC01, 0xFFFFFCF8, 0xFF800B19, 0xFFFFFFFF,
1612 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1613 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1614 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1615 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1616 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1617 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1618 +       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, 0xFFFFFFFF,
1627 +};
1628 diff -NurpP --minimal linux-3.0-rc5/drivers/gpu/drm/radeon/rv515_reg_safe.h linux-3.0-rc5-vs2.3.1-pre3/drivers/gpu/drm/radeon/rv515_reg_safe.h
1629 --- linux-3.0-rc5/drivers/gpu/drm/radeon/rv515_reg_safe.h       1970-01-01 01:00:00.000000000 +0100
1630 +++ linux-3.0-rc5-vs2.3.1-pre3/drivers/gpu/drm/radeon/rv515_reg_safe.h  2011-06-10 22:11:24.000000000 +0200
1631 @@ -0,0 +1,57 @@
1632 +static const unsigned rv515_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 +       0xF0000038, 0xFF000009, 0xFFFFFFFF, 0xFFFFFFFF,
1651 +       0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 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 +       0x1FFFF878, 0xFFFFE000, 0xFFFFFE1E, 0xFFFFFFFF,
1666 +       0x388F8F50, 0xFFF88082, 0xFF0000FC, 0xFAE009FF,
1667 +       0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
1668 +       0xFFFF8CFC, 0xFFFFC1FF, 0xFFFFFFFF, 0xFFFFFFFF,
1669 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1670 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFF80FFFF,
1671 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1672 +       0x0003FC01, 0x3FFFFCF8, 0xFF800B19, 0xFFDFFFFF,
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-3.0-rc5/drivers/infiniband/core/addr.c linux-3.0-rc5-vs2.3.1-pre3/drivers/infiniband/core/addr.c
1690 --- linux-3.0-rc5/drivers/infiniband/core/addr.c        2011-07-01 11:13:52.000000000 +0200
1691 +++ linux-3.0-rc5-vs2.3.1-pre3/drivers/infiniband/core/addr.c   2011-06-16 14:16:51.000000000 +0200
1692 @@ -252,7 +252,7 @@ static int addr6_resolve(struct sockaddr
1693  
1694         if (ipv6_addr_any(&fl6.saddr)) {
1695                 ret = ipv6_dev_get_saddr(&init_net, ip6_dst_idev(dst)->dev,
1696 -                                        &fl6.daddr, 0, &fl6.saddr);
1697 +                                        &fl6.daddr, 0, &fl6.saddr, NULL);
1698                 if (ret)
1699                         goto put;
1700  
1701 diff -NurpP --minimal linux-3.0-rc5/drivers/infiniband/hw/ipath/ipath_user_pages.c linux-3.0-rc5-vs2.3.1-pre3/drivers/infiniband/hw/ipath/ipath_user_pages.c
1702 --- linux-3.0-rc5/drivers/infiniband/hw/ipath/ipath_user_pages.c        2011-05-22 16:17:16.000000000 +0200
1703 +++ linux-3.0-rc5-vs2.3.1-pre3/drivers/infiniband/hw/ipath/ipath_user_pages.c   2011-06-10 22:11:24.000000000 +0200
1704 @@ -35,6 +35,7 @@
1705  #include <linux/device.h>
1706  #include <linux/slab.h>
1707  #include <linux/sched.h>
1708 +#include <linux/vs_memory.h>
1709  
1710  #include "ipath_kernel.h"
1711  
1712 diff -NurpP --minimal linux-3.0-rc5/drivers/md/dm-ioctl.c linux-3.0-rc5-vs2.3.1-pre3/drivers/md/dm-ioctl.c
1713 --- linux-3.0-rc5/drivers/md/dm-ioctl.c 2011-05-22 16:17:18.000000000 +0200
1714 +++ linux-3.0-rc5-vs2.3.1-pre3/drivers/md/dm-ioctl.c    2011-06-10 22:11:24.000000000 +0200
1715 @@ -16,6 +16,7 @@
1716  #include <linux/dm-ioctl.h>
1717  #include <linux/hdreg.h>
1718  #include <linux/compat.h>
1719 +#include <linux/vs_context.h>
1720  
1721  #include <asm/uaccess.h>
1722  
1723 @@ -106,7 +107,8 @@ static struct hash_cell *__get_name_cell
1724         unsigned int h = hash_str(str);
1725  
1726         list_for_each_entry (hc, _name_buckets + h, name_list)
1727 -               if (!strcmp(hc->name, str)) {
1728 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1729 +                       !strcmp(hc->name, str)) {
1730                         dm_get(hc->md);
1731                         return hc;
1732                 }
1733 @@ -120,7 +122,8 @@ static struct hash_cell *__get_uuid_cell
1734         unsigned int h = hash_str(str);
1735  
1736         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1737 -               if (!strcmp(hc->uuid, str)) {
1738 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1739 +                       !strcmp(hc->uuid, str)) {
1740                         dm_get(hc->md);
1741                         return hc;
1742                 }
1743 @@ -427,6 +430,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl 
1744  
1745  static int remove_all(struct dm_ioctl *param, size_t param_size)
1746  {
1747 +       if (!vx_check(0, VS_ADMIN))
1748 +               return -EPERM;
1749 +
1750         dm_hash_remove_all(1);
1751         param->data_size = 0;
1752         return 0;
1753 @@ -474,6 +480,8 @@ static int list_devices(struct dm_ioctl 
1754          */
1755         for (i = 0; i < NUM_BUCKETS; i++) {
1756                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1757 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1758 +                               continue;
1759                         needed += sizeof(struct dm_name_list);
1760                         needed += strlen(hc->name) + 1;
1761                         needed += ALIGN_MASK;
1762 @@ -497,6 +505,8 @@ static int list_devices(struct dm_ioctl 
1763          */
1764         for (i = 0; i < NUM_BUCKETS; i++) {
1765                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1766 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1767 +                               continue;
1768                         if (old_nl)
1769                                 old_nl->next = (uint32_t) ((void *) nl -
1770                                                            (void *) old_nl);
1771 @@ -731,10 +741,11 @@ static struct hash_cell *__find_device_h
1772         if (!md)
1773                 goto out;
1774  
1775 -       mdptr = dm_get_mdptr(md);
1776 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1777 +               mdptr = dm_get_mdptr(md);
1778 +
1779         if (!mdptr)
1780                 dm_put(md);
1781 -
1782  out:
1783         return mdptr;
1784  }
1785 @@ -1577,8 +1588,8 @@ static int ctl_ioctl(uint command, struc
1786         ioctl_fn fn = NULL;
1787         size_t input_param_size;
1788  
1789 -       /* only root can play with this */
1790 -       if (!capable(CAP_SYS_ADMIN))
1791 +       /* only root and certain contexts can play with this */
1792 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1793                 return -EACCES;
1794  
1795         if (_IOC_TYPE(command) != DM_IOCTL)
1796 diff -NurpP --minimal linux-3.0-rc5/drivers/md/dm.c linux-3.0-rc5-vs2.3.1-pre3/drivers/md/dm.c
1797 --- linux-3.0-rc5/drivers/md/dm.c       2011-05-22 16:17:18.000000000 +0200
1798 +++ linux-3.0-rc5-vs2.3.1-pre3/drivers/md/dm.c  2011-06-10 22:11:24.000000000 +0200
1799 @@ -20,6 +20,7 @@
1800  #include <linux/idr.h>
1801  #include <linux/hdreg.h>
1802  #include <linux/delay.h>
1803 +#include <linux/vs_base.h>
1804  
1805  #include <trace/events/block.h>
1806  
1807 @@ -119,6 +120,7 @@ struct mapped_device {
1808         rwlock_t map_lock;
1809         atomic_t holders;
1810         atomic_t open_count;
1811 +       xid_t xid;
1812  
1813         unsigned long flags;
1814  
1815 @@ -326,6 +328,7 @@ int dm_deleting_md(struct mapped_device 
1816  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1817  {
1818         struct mapped_device *md;
1819 +       int ret = -ENXIO;
1820  
1821         spin_lock(&_minor_lock);
1822  
1823 @@ -334,18 +337,19 @@ static int dm_blk_open(struct block_devi
1824                 goto out;
1825  
1826         if (test_bit(DMF_FREEING, &md->flags) ||
1827 -           dm_deleting_md(md)) {
1828 -               md = NULL;
1829 +           dm_deleting_md(md))
1830 +               goto out;
1831 +
1832 +       ret = -EACCES;
1833 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1834                 goto out;
1835 -       }
1836  
1837         dm_get(md);
1838         atomic_inc(&md->open_count);
1839 -
1840 +       ret = 0;
1841  out:
1842         spin_unlock(&_minor_lock);
1843 -
1844 -       return md ? 0 : -ENXIO;
1845 +       return ret;
1846  }
1847  
1848  static int dm_blk_close(struct gendisk *disk, fmode_t mode)
1849 @@ -566,6 +570,14 @@ int dm_set_geometry(struct mapped_device
1850         return 0;
1851  }
1852  
1853 +/*
1854 + * Get the xid associated with a dm device
1855 + */
1856 +xid_t dm_get_xid(struct mapped_device *md)
1857 +{
1858 +       return md->xid;
1859 +}
1860 +
1861  /*-----------------------------------------------------------------
1862   * CRUD START:
1863   *   A more elegant soln is in the works that uses the queue
1864 @@ -1841,6 +1853,7 @@ static struct mapped_device *alloc_dev(i
1865         INIT_LIST_HEAD(&md->uevent_list);
1866         spin_lock_init(&md->uevent_lock);
1867  
1868 +       md->xid = vx_current_xid();
1869         md->queue = blk_alloc_queue(GFP_KERNEL);
1870         if (!md->queue)
1871                 goto bad_queue;
1872 diff -NurpP --minimal linux-3.0-rc5/drivers/md/dm.h linux-3.0-rc5-vs2.3.1-pre3/drivers/md/dm.h
1873 --- linux-3.0-rc5/drivers/md/dm.h       2011-05-22 16:17:18.000000000 +0200
1874 +++ linux-3.0-rc5-vs2.3.1-pre3/drivers/md/dm.h  2011-06-10 22:11:24.000000000 +0200
1875 @@ -41,6 +41,8 @@ struct dm_dev_internal {
1876  struct dm_table;
1877  struct dm_md_mempools;
1878  
1879 +xid_t dm_get_xid(struct mapped_device *md);
1880 +
1881  /*-----------------------------------------------------------------
1882   * Internal table functions.
1883   *---------------------------------------------------------------*/
1884 diff -NurpP --minimal linux-3.0-rc5/drivers/net/tun.c linux-3.0-rc5-vs2.3.1-pre3/drivers/net/tun.c
1885 --- linux-3.0-rc5/drivers/net/tun.c     2011-07-01 11:14:01.000000000 +0200
1886 +++ linux-3.0-rc5-vs2.3.1-pre3/drivers/net/tun.c        2011-06-22 12:39:14.000000000 +0200
1887 @@ -64,6 +64,7 @@
1888  #include <linux/nsproxy.h>
1889  #include <linux/virtio_net.h>
1890  #include <linux/rcupdate.h>
1891 +#include <linux/vs_network.h>
1892  #include <net/net_namespace.h>
1893  #include <net/netns/generic.h>
1894  #include <net/rtnetlink.h>
1895 @@ -121,6 +122,7 @@ struct tun_struct {
1896         unsigned int            flags;
1897         uid_t                   owner;
1898         gid_t                   group;
1899 +       nid_t                   nid;
1900  
1901         struct net_device       *dev;
1902         u32                     set_features;
1903 @@ -904,6 +906,7 @@ static void tun_setup(struct net_device 
1904  
1905         tun->owner = -1;
1906         tun->group = -1;
1907 +       tun->nid = current->nid;
1908  
1909         dev->ethtool_ops = &tun_ethtool_ops;
1910         dev->destructor = tun_free_netdev;
1911 @@ -1054,7 +1057,7 @@ static int tun_set_iff(struct net *net, 
1912  
1913                 if (((tun->owner != -1 && cred->euid != tun->owner) ||
1914                      (tun->group != -1 && !in_egroup_p(tun->group))) &&
1915 -                   !capable(CAP_NET_ADMIN))
1916 +               !cap_raised(current_cap(), CAP_NET_ADMIN))
1917                         return -EPERM;
1918                 err = security_tun_dev_attach(tun->socket.sk);
1919                 if (err < 0)
1920 @@ -1068,7 +1071,7 @@ static int tun_set_iff(struct net *net, 
1921                 char *name;
1922                 unsigned long flags = 0;
1923  
1924 -               if (!capable(CAP_NET_ADMIN))
1925 +               if (!nx_capable(CAP_NET_ADMIN, NXC_TUN_CREATE))
1926                         return -EPERM;
1927                 err = security_tun_dev_create();
1928                 if (err < 0)
1929 @@ -1136,6 +1139,9 @@ static int tun_set_iff(struct net *net, 
1930  
1931                 sk->sk_destruct = tun_sock_destruct;
1932  
1933 +               if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
1934 +                       return -EPERM;
1935 +
1936                 err = tun_attach(tun, file);
1937                 if (err < 0)
1938                         goto failed;
1939 @@ -1317,6 +1323,16 @@ static long __tun_chr_ioctl(struct file 
1940                 tun_debug(KERN_INFO, tun, "group set to %d\n", tun->group);
1941                 break;
1942  
1943 +       case TUNSETNID:
1944 +               if (!capable(CAP_CONTEXT))
1945 +                       return -EPERM;
1946 +
1947 +               /* Set nid owner of the device */
1948 +               tun->nid = (nid_t) arg;
1949 +
1950 +               tun_debug(KERN_INFO, tun, "nid owner set to %u\n", tun->nid);
1951 +               break;
1952 +
1953         case TUNSETLINK:
1954                 /* Only allow setting the type when the interface is down */
1955                 if (tun->dev->flags & IFF_UP) {
1956 diff -NurpP --minimal linux-3.0-rc5/drivers/tty/sysrq.c linux-3.0-rc5-vs2.3.1-pre3/drivers/tty/sysrq.c
1957 --- linux-3.0-rc5/drivers/tty/sysrq.c   2011-05-22 16:17:44.000000000 +0200
1958 +++ linux-3.0-rc5-vs2.3.1-pre3/drivers/tty/sysrq.c      2011-06-10 22:11:24.000000000 +0200
1959 @@ -41,6 +41,7 @@
1960  #include <linux/oom.h>
1961  #include <linux/slab.h>
1962  #include <linux/input.h>
1963 +#include <linux/vserver/debug.h>
1964  
1965  #include <asm/ptrace.h>
1966  #include <asm/irq_regs.h>
1967 @@ -395,6 +396,21 @@ static struct sysrq_key_op sysrq_unrt_op
1968         .enable_mask    = SYSRQ_ENABLE_RTNICE,
1969  };
1970  
1971 +
1972 +#ifdef CONFIG_VSERVER_DEBUG
1973 +static void sysrq_handle_vxinfo(int key)
1974 +{
1975 +       dump_vx_info_inactive((key == 'x') ? 0 : 1);
1976 +}
1977 +
1978 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1979 +       .handler        = sysrq_handle_vxinfo,
1980 +       .help_msg       = "conteXt",
1981 +       .action_msg     = "Show Context Info",
1982 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
1983 +};
1984 +#endif
1985 +
1986  /* Key Operations table and lock */
1987  static DEFINE_SPINLOCK(sysrq_key_table_lock);
1988  
1989 @@ -449,7 +465,11 @@ static struct sysrq_key_op *sysrq_key_ta
1990         NULL,                           /* v */
1991         &sysrq_showstate_blocked_op,    /* w */
1992         /* x: May be registered on ppc/powerpc for xmon */
1993 +#ifdef CONFIG_VSERVER_DEBUG
1994 +       &sysrq_showvxinfo_op,           /* x */
1995 +#else
1996         NULL,                           /* x */
1997 +#endif
1998         /* y: May be registered on sparc64 for global register dump */
1999         NULL,                           /* y */
2000         &sysrq_ftrace_dump_op,          /* z */
2001 @@ -464,6 +484,8 @@ static int sysrq_key_table_key2index(int
2002                 retval = key - '0';
2003         else if ((key >= 'a') && (key <= 'z'))
2004                 retval = key + 10 - 'a';
2005 +       else if ((key >= 'A') && (key <= 'Z'))
2006 +               retval = key + 10 - 'A';
2007         else
2008                 retval = -1;
2009         return retval;
2010 diff -NurpP --minimal linux-3.0-rc5/drivers/tty/tty_io.c linux-3.0-rc5-vs2.3.1-pre3/drivers/tty/tty_io.c
2011 --- linux-3.0-rc5/drivers/tty/tty_io.c  2011-07-01 11:14:14.000000000 +0200
2012 +++ linux-3.0-rc5-vs2.3.1-pre3/drivers/tty/tty_io.c     2011-06-10 22:11:24.000000000 +0200
2013 @@ -104,6 +104,7 @@
2014  
2015  #include <linux/kmod.h>
2016  #include <linux/nsproxy.h>
2017 +#include <linux/vs_pid.h>
2018  
2019  #undef TTY_DEBUG_HANGUP
2020  
2021 @@ -2057,7 +2058,8 @@ static int tiocsti(struct tty_struct *tt
2022         char ch, mbz = 0;
2023         struct tty_ldisc *ld;
2024  
2025 -       if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
2026 +       if (((current->signal->tty != tty) &&
2027 +               !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
2028                 return -EPERM;
2029         if (get_user(ch, p))
2030                 return -EFAULT;
2031 @@ -2345,6 +2347,7 @@ static int tiocspgrp(struct tty_struct *
2032                 return -ENOTTY;
2033         if (get_user(pgrp_nr, p))
2034                 return -EFAULT;
2035 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
2036         if (pgrp_nr < 0)
2037                 return -EINVAL;
2038         rcu_read_lock();
2039 diff -NurpP --minimal linux-3.0-rc5/fs/attr.c linux-3.0-rc5-vs2.3.1-pre3/fs/attr.c
2040 --- linux-3.0-rc5/fs/attr.c     2011-07-01 11:14:16.000000000 +0200
2041 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/attr.c        2011-06-10 22:11:24.000000000 +0200
2042 @@ -13,6 +13,9 @@
2043  #include <linux/fsnotify.h>
2044  #include <linux/fcntl.h>
2045  #include <linux/security.h>
2046 +#include <linux/proc_fs.h>
2047 +#include <linux/devpts_fs.h>
2048 +#include <linux/vs_tag.h>
2049  
2050  /**
2051   * inode_change_ok - check if attribute changes to an inode are allowed
2052 @@ -73,6 +76,10 @@ int inode_change_ok(const struct inode *
2053                         return -EPERM;
2054         }
2055  
2056 +       /* check for inode tag permission */
2057 +       if (dx_permission(inode, MAY_WRITE))
2058 +               return -EACCES;
2059 +
2060         return 0;
2061  }
2062  EXPORT_SYMBOL(inode_change_ok);
2063 @@ -143,6 +150,8 @@ void setattr_copy(struct inode *inode, c
2064                 inode->i_uid = attr->ia_uid;
2065         if (ia_valid & ATTR_GID)
2066                 inode->i_gid = attr->ia_gid;
2067 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2068 +               inode->i_tag = attr->ia_tag;
2069         if (ia_valid & ATTR_ATIME)
2070                 inode->i_atime = timespec_trunc(attr->ia_atime,
2071                                                 inode->i_sb->s_time_gran);
2072 @@ -170,7 +179,8 @@ int notify_change(struct dentry * dentry
2073         struct timespec now;
2074         unsigned int ia_valid = attr->ia_valid;
2075  
2076 -       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
2077 +       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
2078 +               ATTR_TAG | ATTR_TIMES_SET)) {
2079                 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
2080                         return -EPERM;
2081         }
2082 diff -NurpP --minimal linux-3.0-rc5/fs/binfmt_aout.c linux-3.0-rc5-vs2.3.1-pre3/fs/binfmt_aout.c
2083 --- linux-3.0-rc5/fs/binfmt_aout.c      2010-10-21 13:07:47.000000000 +0200
2084 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/binfmt_aout.c 2011-06-10 22:11:24.000000000 +0200
2085 @@ -25,6 +25,7 @@
2086  #include <linux/init.h>
2087  #include <linux/coredump.h>
2088  #include <linux/slab.h>
2089 +#include <linux/vs_memory.h>
2090  
2091  #include <asm/system.h>
2092  #include <asm/uaccess.h>
2093 diff -NurpP --minimal linux-3.0-rc5/fs/binfmt_elf.c linux-3.0-rc5-vs2.3.1-pre3/fs/binfmt_elf.c
2094 --- linux-3.0-rc5/fs/binfmt_elf.c       2011-05-22 16:17:48.000000000 +0200
2095 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/binfmt_elf.c  2011-06-10 22:11:24.000000000 +0200
2096 @@ -32,6 +32,7 @@
2097  #include <linux/elf.h>
2098  #include <linux/utsname.h>
2099  #include <linux/coredump.h>
2100 +#include <linux/vs_memory.h>
2101  #include <asm/uaccess.h>
2102  #include <asm/param.h>
2103  #include <asm/page.h>
2104 diff -NurpP --minimal linux-3.0-rc5/fs/binfmt_flat.c linux-3.0-rc5-vs2.3.1-pre3/fs/binfmt_flat.c
2105 --- linux-3.0-rc5/fs/binfmt_flat.c      2011-07-01 11:14:16.000000000 +0200
2106 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/binfmt_flat.c 2011-06-10 22:11:24.000000000 +0200
2107 @@ -35,6 +35,7 @@
2108  #include <linux/init.h>
2109  #include <linux/flat.h>
2110  #include <linux/syscalls.h>
2111 +#include <linux/vs_memory.h>
2112  
2113  #include <asm/byteorder.h>
2114  #include <asm/system.h>
2115 diff -NurpP --minimal linux-3.0-rc5/fs/binfmt_som.c linux-3.0-rc5-vs2.3.1-pre3/fs/binfmt_som.c
2116 --- linux-3.0-rc5/fs/binfmt_som.c       2010-02-25 11:52:04.000000000 +0100
2117 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/binfmt_som.c  2011-06-10 22:11:24.000000000 +0200
2118 @@ -28,6 +28,7 @@
2119  #include <linux/shm.h>
2120  #include <linux/personality.h>
2121  #include <linux/init.h>
2122 +#include <linux/vs_memory.h>
2123  
2124  #include <asm/uaccess.h>
2125  #include <asm/pgtable.h>
2126 diff -NurpP --minimal linux-3.0-rc5/fs/block_dev.c linux-3.0-rc5-vs2.3.1-pre3/fs/block_dev.c
2127 --- linux-3.0-rc5/fs/block_dev.c        2011-07-01 11:14:16.000000000 +0200
2128 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/block_dev.c   2011-07-01 11:35:34.000000000 +0200
2129 @@ -25,6 +25,7 @@
2130  #include <linux/namei.h>
2131  #include <linux/log2.h>
2132  #include <linux/kmemleak.h>
2133 +#include <linux/vs_device.h>
2134  #include <asm/uaccess.h>
2135  #include "internal.h"
2136  
2137 @@ -553,6 +554,7 @@ struct block_device *bdget(dev_t dev)
2138                 bdev->bd_invalidated = 0;
2139                 inode->i_mode = S_IFBLK;
2140                 inode->i_rdev = dev;
2141 +               inode->i_mdev = dev;
2142                 inode->i_bdev = bdev;
2143                 inode->i_data.a_ops = &def_blk_aops;
2144                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
2145 @@ -599,6 +601,11 @@ EXPORT_SYMBOL(bdput);
2146  static struct block_device *bd_acquire(struct inode *inode)
2147  {
2148         struct block_device *bdev;
2149 +       dev_t mdev;
2150 +
2151 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
2152 +               return NULL;
2153 +       inode->i_mdev = mdev;
2154  
2155         spin_lock(&bdev_lock);
2156         bdev = inode->i_bdev;
2157 @@ -609,7 +616,7 @@ static struct block_device *bd_acquire(s
2158         }
2159         spin_unlock(&bdev_lock);
2160  
2161 -       bdev = bdget(inode->i_rdev);
2162 +       bdev = bdget(mdev);
2163         if (bdev) {
2164                 spin_lock(&bdev_lock);
2165                 if (!inode->i_bdev) {
2166 diff -NurpP --minimal linux-3.0-rc5/fs/btrfs/ctree.h linux-3.0-rc5-vs2.3.1-pre3/fs/btrfs/ctree.h
2167 --- linux-3.0-rc5/fs/btrfs/ctree.h      2011-07-01 11:14:16.000000000 +0200
2168 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/btrfs/ctree.h 2011-07-01 11:35:34.000000000 +0200
2169 @@ -600,11 +600,14 @@ struct btrfs_inode_item {
2170         /* modification sequence number for NFS */
2171         __le64 sequence;
2172  
2173 +       __le16 tag;
2174         /*
2175          * a little future expansion, for more than this we can
2176          * just grow the inode item and version it
2177          */
2178 -       __le64 reserved[4];
2179 +       __le16 reserved16;
2180 +       __le32 reserved32;
2181 +       __le64 reserved[3];
2182         struct btrfs_timespec atime;
2183         struct btrfs_timespec ctime;
2184         struct btrfs_timespec mtime;
2185 @@ -1354,6 +1357,8 @@ struct btrfs_ioctl_defrag_range_args {
2186  #define BTRFS_MOUNT_AUTO_DEFRAG                (1 << 16)
2187  #define BTRFS_MOUNT_INODE_MAP_CACHE    (1 << 17)
2188  
2189 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
2190 +
2191  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
2192  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
2193  #define btrfs_test_opt(root, opt)      ((root)->fs_info->mount_opt & \
2194 @@ -1563,6 +1568,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
2195  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
2196  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
2197  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
2198 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
2199  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
2200  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
2201  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
2202 @@ -1616,6 +1622,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct 
2203  
2204  BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
2205  
2206 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
2207 +#define BTRFS_INODE_BARRIER            (1 << 25)
2208 +#define BTRFS_INODE_COW                        (1 << 26)
2209 +
2210  
2211  BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
2212  
2213 @@ -2590,6 +2600,7 @@ extern const struct dentry_operations bt
2214  long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
2215  void btrfs_update_iflags(struct inode *inode);
2216  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
2217 +int btrfs_sync_flags(struct inode *inode, int, int);
2218  int btrfs_defrag_file(struct inode *inode, struct file *file,
2219                       struct btrfs_ioctl_defrag_range_args *range,
2220                       u64 newer_than, unsigned long max_pages);
2221 diff -NurpP --minimal linux-3.0-rc5/fs/btrfs/disk-io.c linux-3.0-rc5-vs2.3.1-pre3/fs/btrfs/disk-io.c
2222 --- linux-3.0-rc5/fs/btrfs/disk-io.c    2011-07-01 11:14:16.000000000 +0200
2223 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/btrfs/disk-io.c       2011-06-22 12:39:15.000000000 +0200
2224 @@ -1765,6 +1765,9 @@ struct btrfs_root *open_ctree(struct sup
2225                 goto fail_alloc;
2226         }
2227  
2228 +       if (btrfs_test_opt(tree_root, TAGGED))
2229 +               sb->s_flags |= MS_TAGGED;
2230 +
2231         features = btrfs_super_incompat_flags(disk_super) &
2232                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
2233         if (features) {
2234 diff -NurpP --minimal linux-3.0-rc5/fs/btrfs/inode.c linux-3.0-rc5-vs2.3.1-pre3/fs/btrfs/inode.c
2235 --- linux-3.0-rc5/fs/btrfs/inode.c      2011-07-01 11:14:17.000000000 +0200
2236 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/btrfs/inode.c 2011-07-01 11:35:34.000000000 +0200
2237 @@ -38,6 +38,7 @@
2238  #include <linux/falloc.h>
2239  #include <linux/slab.h>
2240  #include <linux/ratelimit.h>
2241 +#include <linux/vs_tag.h>
2242  #include "compat.h"
2243  #include "ctree.h"
2244  #include "disk-io.h"
2245 @@ -2508,6 +2509,8 @@ static void btrfs_read_locked_inode(stru
2246         struct btrfs_key location;
2247         int maybe_acls;
2248         u32 rdev;
2249 +       uid_t uid;
2250 +       gid_t gid;
2251         int ret;
2252         bool filled = false;
2253  
2254 @@ -2540,8 +2543,13 @@ static void btrfs_read_locked_inode(stru
2255  
2256         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
2257         inode->i_nlink = btrfs_inode_nlink(leaf, inode_item);
2258 -       inode->i_uid = btrfs_inode_uid(leaf, inode_item);
2259 -       inode->i_gid = btrfs_inode_gid(leaf, inode_item);
2260 +
2261 +       uid = btrfs_inode_uid(leaf, inode_item);
2262 +       gid = btrfs_inode_gid(leaf, inode_item);
2263 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2264 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2265 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2266 +               btrfs_inode_tag(leaf, inode_item));
2267         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
2268  
2269         tspec = btrfs_inode_atime(inode_item);
2270 @@ -2624,6 +2632,9 @@ static void fill_inode_item(struct btrfs
2271                             struct btrfs_inode_item *item,
2272                             struct inode *inode)
2273  {
2274 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2275 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2276 +
2277         if (!leaf->map_token)
2278                 map_private_extent_buffer(leaf, (unsigned long)item,
2279                                           sizeof(struct btrfs_inode_item),
2280 @@ -2631,8 +2642,11 @@ static void fill_inode_item(struct btrfs
2281                                           &leaf->map_start, &leaf->map_len,
2282                                           KM_USER1);
2283  
2284 -       btrfs_set_inode_uid(leaf, item, inode->i_uid);
2285 -       btrfs_set_inode_gid(leaf, item, inode->i_gid);
2286 +       btrfs_set_inode_uid(leaf, item, uid);
2287 +       btrfs_set_inode_gid(leaf, item, gid);
2288 +#ifdef CONFIG_TAGGING_INTERN
2289 +       btrfs_set_inode_tag(leaf, item, inode->i_tag);
2290 +#endif
2291         btrfs_set_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size);
2292         btrfs_set_inode_mode(leaf, item, inode->i_mode);
2293         btrfs_set_inode_nlink(leaf, item, inode->i_nlink);
2294 @@ -7357,6 +7371,7 @@ static const struct inode_operations btr
2295         .listxattr      = btrfs_listxattr,
2296         .removexattr    = btrfs_removexattr,
2297         .permission     = btrfs_permission,
2298 +       .sync_flags     = btrfs_sync_flags,
2299  };
2300  static const struct inode_operations btrfs_dir_ro_inode_operations = {
2301         .lookup         = btrfs_lookup,
2302 @@ -7429,6 +7444,7 @@ static const struct inode_operations btr
2303         .removexattr    = btrfs_removexattr,
2304         .permission     = btrfs_permission,
2305         .fiemap         = btrfs_fiemap,
2306 +       .sync_flags     = btrfs_sync_flags,
2307  };
2308  static const struct inode_operations btrfs_special_inode_operations = {
2309         .getattr        = btrfs_getattr,
2310 diff -NurpP --minimal linux-3.0-rc5/fs/btrfs/ioctl.c linux-3.0-rc5-vs2.3.1-pre3/fs/btrfs/ioctl.c
2311 --- linux-3.0-rc5/fs/btrfs/ioctl.c      2011-07-01 11:14:17.000000000 +0200
2312 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/btrfs/ioctl.c 2011-06-22 12:39:15.000000000 +0200
2313 @@ -70,10 +70,13 @@ static unsigned int btrfs_flags_to_ioctl
2314  {
2315         unsigned int iflags = 0;
2316  
2317 -       if (flags & BTRFS_INODE_SYNC)
2318 -               iflags |= FS_SYNC_FL;
2319         if (flags & BTRFS_INODE_IMMUTABLE)
2320                 iflags |= FS_IMMUTABLE_FL;
2321 +       if (flags & BTRFS_INODE_IXUNLINK)
2322 +               iflags |= FS_IXUNLINK_FL;
2323 +
2324 +       if (flags & BTRFS_INODE_SYNC)
2325 +               iflags |= FS_SYNC_FL;
2326         if (flags & BTRFS_INODE_APPEND)
2327                 iflags |= FS_APPEND_FL;
2328         if (flags & BTRFS_INODE_NODUMP)
2329 @@ -90,28 +93,78 @@ static unsigned int btrfs_flags_to_ioctl
2330         else if (flags & BTRFS_INODE_NOCOMPRESS)
2331                 iflags |= FS_NOCOMP_FL;
2332  
2333 +       if (flags & BTRFS_INODE_BARRIER)
2334 +               iflags |= FS_BARRIER_FL;
2335 +       if (flags & BTRFS_INODE_COW)
2336 +               iflags |= FS_COW_FL;
2337         return iflags;
2338  }
2339  
2340  /*
2341 - * Update inode->i_flags based on the btrfs internal flags.
2342 + * Update inode->i_(v)flags based on the btrfs internal flags.
2343   */
2344  void btrfs_update_iflags(struct inode *inode)
2345  {
2346         struct btrfs_inode *ip = BTRFS_I(inode);
2347  
2348 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2349 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2350 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2351  
2352 -       if (ip->flags & BTRFS_INODE_SYNC)
2353 -               inode->i_flags |= S_SYNC;
2354         if (ip->flags & BTRFS_INODE_IMMUTABLE)
2355                 inode->i_flags |= S_IMMUTABLE;
2356 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
2357 +               inode->i_flags |= S_IXUNLINK;
2358 +
2359 +       if (ip->flags & BTRFS_INODE_SYNC)
2360 +               inode->i_flags |= S_SYNC;
2361         if (ip->flags & BTRFS_INODE_APPEND)
2362                 inode->i_flags |= S_APPEND;
2363         if (ip->flags & BTRFS_INODE_NOATIME)
2364                 inode->i_flags |= S_NOATIME;
2365         if (ip->flags & BTRFS_INODE_DIRSYNC)
2366                 inode->i_flags |= S_DIRSYNC;
2367 +
2368 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2369 +
2370 +       if (ip->flags & BTRFS_INODE_BARRIER)
2371 +               inode->i_vflags |= V_BARRIER;
2372 +       if (ip->flags & BTRFS_INODE_COW)
2373 +               inode->i_vflags |= V_COW;
2374 +}
2375 +
2376 +/*
2377 + * Update btrfs internal flags from inode->i_(v)flags.
2378 + */
2379 +void btrfs_update_flags(struct inode *inode)
2380 +{
2381 +       struct btrfs_inode *ip = BTRFS_I(inode);
2382 +
2383 +       unsigned int flags = inode->i_flags;
2384 +       unsigned int vflags = inode->i_vflags;
2385 +
2386 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
2387 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
2388 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
2389 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
2390 +
2391 +       if (flags & S_IMMUTABLE)
2392 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
2393 +       if (flags & S_IXUNLINK)
2394 +               ip->flags |= BTRFS_INODE_IXUNLINK;
2395 +
2396 +       if (flags & S_SYNC)
2397 +               ip->flags |= BTRFS_INODE_SYNC;
2398 +       if (flags & S_APPEND)
2399 +               ip->flags |= BTRFS_INODE_APPEND;
2400 +       if (flags & S_NOATIME)
2401 +               ip->flags |= BTRFS_INODE_NOATIME;
2402 +       if (flags & S_DIRSYNC)
2403 +               ip->flags |= BTRFS_INODE_DIRSYNC;
2404 +
2405 +       if (vflags & V_BARRIER)
2406 +               ip->flags |= BTRFS_INODE_BARRIER;
2407 +       if (vflags & V_COW)
2408 +               ip->flags |= BTRFS_INODE_COW;
2409  }
2410  
2411  /*
2412 @@ -129,7 +182,7 @@ void btrfs_inherit_iflags(struct inode *
2413         flags = BTRFS_I(dir)->flags;
2414  
2415         if (S_ISREG(inode->i_mode))
2416 -               flags &= ~BTRFS_INODE_DIRSYNC;
2417 +               flags &= ~(BTRFS_INODE_DIRSYNC | BTRFS_INODE_BARRIER);
2418         else if (!S_ISDIR(inode->i_mode))
2419                 flags &= (BTRFS_INODE_NODUMP | BTRFS_INODE_NOATIME);
2420  
2421 @@ -137,6 +190,30 @@ void btrfs_inherit_iflags(struct inode *
2422         btrfs_update_iflags(inode);
2423  }
2424  
2425 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
2426 +{
2427 +       struct btrfs_inode *ip = BTRFS_I(inode);
2428 +       struct btrfs_root *root = ip->root;
2429 +       struct btrfs_trans_handle *trans;
2430 +       int ret;
2431 +
2432 +       trans = btrfs_join_transaction(root);
2433 +       BUG_ON(!trans);
2434 +
2435 +       inode->i_flags = flags;
2436 +       inode->i_vflags = vflags;
2437 +       btrfs_update_flags(inode);
2438 +
2439 +       ret = btrfs_update_inode(trans, root, inode);
2440 +       BUG_ON(ret);
2441 +
2442 +       btrfs_update_iflags(inode);
2443 +       inode->i_ctime = CURRENT_TIME;
2444 +       btrfs_end_transaction(trans, root);
2445 +
2446 +       return 0;
2447 +}
2448 +
2449  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
2450  {
2451         struct btrfs_inode *ip = BTRFS_I(file->f_path.dentry->d_inode);
2452 @@ -188,7 +265,8 @@ static int btrfs_ioctl_setflags(struct f
2453  
2454         flags = btrfs_mask_flags(inode->i_mode, flags);
2455         oldflags = btrfs_flags_to_ioctl(ip->flags);
2456 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
2457 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
2458 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
2459                 if (!capable(CAP_LINUX_IMMUTABLE)) {
2460                         ret = -EPERM;
2461                         goto out_unlock;
2462 @@ -199,14 +277,19 @@ static int btrfs_ioctl_setflags(struct f
2463         if (ret)
2464                 goto out_unlock;
2465  
2466 -       if (flags & FS_SYNC_FL)
2467 -               ip->flags |= BTRFS_INODE_SYNC;
2468 -       else
2469 -               ip->flags &= ~BTRFS_INODE_SYNC;
2470         if (flags & FS_IMMUTABLE_FL)
2471                 ip->flags |= BTRFS_INODE_IMMUTABLE;
2472         else
2473                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
2474 +       if (flags & FS_IXUNLINK_FL)
2475 +               ip->flags |= BTRFS_INODE_IXUNLINK;
2476 +       else
2477 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
2478 +
2479 +       if (flags & FS_SYNC_FL)
2480 +               ip->flags |= BTRFS_INODE_SYNC;
2481 +       else
2482 +               ip->flags &= ~BTRFS_INODE_SYNC;
2483         if (flags & FS_APPEND_FL)
2484                 ip->flags |= BTRFS_INODE_APPEND;
2485         else
2486 diff -NurpP --minimal linux-3.0-rc5/fs/btrfs/super.c linux-3.0-rc5-vs2.3.1-pre3/fs/btrfs/super.c
2487 --- linux-3.0-rc5/fs/btrfs/super.c      2011-07-01 11:14:17.000000000 +0200
2488 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/btrfs/super.c 2011-06-15 02:40:14.000000000 +0200
2489 @@ -162,7 +162,7 @@ enum {
2490         Opt_notreelog, Opt_ratio, Opt_flushoncommit, Opt_discard,
2491         Opt_space_cache, Opt_clear_cache, Opt_user_subvol_rm_allowed,
2492         Opt_enospc_debug, Opt_subvolrootid, Opt_defrag,
2493 -       Opt_inode_cache, Opt_err,
2494 +       Opt_inode_cache, Opt_tag, Opt_notag, Opt_tagid, Opt_err,
2495  };
2496  
2497  static match_table_t tokens = {
2498 @@ -195,6 +195,9 @@ static match_table_t tokens = {
2499         {Opt_subvolrootid, "subvolrootid=%d"},
2500         {Opt_defrag, "autodefrag"},
2501         {Opt_inode_cache, "inode_cache"},
2502 +       {Opt_tag, "tag"},
2503 +       {Opt_notag, "notag"},
2504 +       {Opt_tagid, "tagid=%u"},
2505         {Opt_err, NULL},
2506  };
2507  
2508 @@ -381,6 +384,22 @@ int btrfs_parse_options(struct btrfs_roo
2509                         printk(KERN_INFO "btrfs: enabling auto defrag");
2510                         btrfs_set_opt(info->mount_opt, AUTO_DEFRAG);
2511                         break;
2512 +#ifndef CONFIG_TAGGING_NONE
2513 +               case Opt_tag:
2514 +                       printk(KERN_INFO "btrfs: use tagging\n");
2515 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2516 +                       break;
2517 +               case Opt_notag:
2518 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
2519 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
2520 +                       break;
2521 +#endif
2522 +#ifdef CONFIG_PROPAGATE
2523 +               case Opt_tagid:
2524 +                       /* use args[0] */
2525 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2526 +                       break;
2527 +#endif
2528                 case Opt_err:
2529                         printk(KERN_INFO "btrfs: unrecognized mount option "
2530                                "'%s'\n", p);
2531 @@ -901,6 +920,12 @@ static int btrfs_remount(struct super_bl
2532         if (ret)
2533                 return -EINVAL;
2534  
2535 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
2536 +               printk("btrfs: %s: tagging not permitted on remount.\n",
2537 +                       sb->s_id);
2538 +               return -EINVAL;
2539 +       }
2540 +
2541         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
2542                 return 0;
2543  
2544 diff -NurpP --minimal linux-3.0-rc5/fs/char_dev.c linux-3.0-rc5-vs2.3.1-pre3/fs/char_dev.c
2545 --- linux-3.0-rc5/fs/char_dev.c 2011-03-15 18:07:31.000000000 +0100
2546 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/char_dev.c    2011-06-10 22:11:24.000000000 +0200
2547 @@ -21,6 +21,8 @@
2548  #include <linux/mutex.h>
2549  #include <linux/backing-dev.h>
2550  #include <linux/tty.h>
2551 +#include <linux/vs_context.h>
2552 +#include <linux/vs_device.h>
2553  
2554  #include "internal.h"
2555  
2556 @@ -371,14 +373,21 @@ static int chrdev_open(struct inode *ino
2557         struct cdev *p;
2558         struct cdev *new = NULL;
2559         int ret = 0;
2560 +       dev_t mdev;
2561 +
2562 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2563 +               return -EPERM;
2564 +       inode->i_mdev = mdev;
2565  
2566         spin_lock(&cdev_lock);
2567         p = inode->i_cdev;
2568         if (!p) {
2569                 struct kobject *kobj;
2570                 int idx;
2571 +
2572                 spin_unlock(&cdev_lock);
2573 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2574 +
2575 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
2576                 if (!kobj)
2577                         return -ENXIO;
2578                 new = container_of(kobj, struct cdev, kobj);
2579 diff -NurpP --minimal linux-3.0-rc5/fs/dcache.c linux-3.0-rc5-vs2.3.1-pre3/fs/dcache.c
2580 --- linux-3.0-rc5/fs/dcache.c   2011-07-01 11:14:17.000000000 +0200
2581 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/dcache.c      2011-06-10 22:35:26.000000000 +0200
2582 @@ -36,6 +36,7 @@
2583  #include <linux/bit_spinlock.h>
2584  #include <linux/rculist_bl.h>
2585  #include <linux/prefetch.h>
2586 +#include <linux/vs_limit.h>
2587  #include "internal.h"
2588  
2589  /*
2590 @@ -479,6 +480,8 @@ int d_invalidate(struct dentry * dentry)
2591                 spin_lock(&dentry->d_lock);
2592         }
2593  
2594 +       vx_dentry_dec(dentry);
2595 +
2596         /*
2597          * Somebody else still using it?
2598          *
2599 @@ -506,6 +509,7 @@ EXPORT_SYMBOL(d_invalidate);
2600  static inline void __dget_dlock(struct dentry *dentry)
2601  {
2602         dentry->d_count++;
2603 +       vx_dentry_inc(dentry);
2604  }
2605  
2606  static inline void __dget(struct dentry *dentry)
2607 @@ -1266,6 +1270,9 @@ struct dentry *d_alloc(struct dentry * p
2608         struct dentry *dentry;
2609         char *dname;
2610  
2611 +       if (!vx_dentry_avail(1))
2612 +               return NULL;
2613 +
2614         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2615         if (!dentry)
2616                 return NULL;
2617 @@ -1288,6 +1295,7 @@ struct dentry *d_alloc(struct dentry * p
2618  
2619         dentry->d_count = 1;
2620         dentry->d_flags = 0;
2621 +       vx_dentry_inc(dentry);
2622         spin_lock_init(&dentry->d_lock);
2623         seqcount_init(&dentry->d_seq);
2624         dentry->d_inode = NULL;
2625 @@ -1947,6 +1955,7 @@ struct dentry *__d_lookup(struct dentry 
2626                 }
2627  
2628                 dentry->d_count++;
2629 +               vx_dentry_inc(dentry);
2630                 found = dentry;
2631                 spin_unlock(&dentry->d_lock);
2632                 break;
2633 diff -NurpP --minimal linux-3.0-rc5/fs/devpts/inode.c linux-3.0-rc5-vs2.3.1-pre3/fs/devpts/inode.c
2634 --- linux-3.0-rc5/fs/devpts/inode.c     2011-05-22 16:17:50.000000000 +0200
2635 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/devpts/inode.c        2011-06-10 22:11:24.000000000 +0200
2636 @@ -25,6 +25,7 @@
2637  #include <linux/parser.h>
2638  #include <linux/fsnotify.h>
2639  #include <linux/seq_file.h>
2640 +#include <linux/vs_base.h>
2641  
2642  #define DEVPTS_DEFAULT_MODE 0600
2643  /*
2644 @@ -36,6 +37,20 @@
2645  #define DEVPTS_DEFAULT_PTMX_MODE 0000
2646  #define PTMX_MINOR     2
2647  
2648 +static int devpts_permission(struct inode *inode, int mask, unsigned int flags)
2649 +{
2650 +       int ret = -EACCES;
2651 +
2652 +       /* devpts is xid tagged */
2653 +       if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
2654 +               ret = generic_permission(inode, mask, flags, NULL);
2655 +       return ret;
2656 +}
2657 +
2658 +static struct inode_operations devpts_file_inode_operations = {
2659 +       .permission     = devpts_permission,
2660 +};
2661 +
2662  extern int pty_limit;                  /* Config limit on Unix98 ptys */
2663  static DEFINE_MUTEX(allocated_ptys_lock);
2664  
2665 @@ -263,6 +278,34 @@ static int devpts_show_options(struct se
2666         return 0;
2667  }
2668  
2669 +static int devpts_filter(struct dentry *de)
2670 +{
2671 +       xid_t xid = 0;
2672 +
2673 +       /* devpts is xid tagged */
2674 +       if (de && de->d_inode)
2675 +               xid = (xid_t)de->d_inode->i_tag;
2676 +#ifdef CONFIG_VSERVER_WARN_DEVPTS
2677 +       else
2678 +               vxwprintk_task(1, "devpts " VS_Q("%.*s") " without inode.",
2679 +                       de->d_name.len, de->d_name.name);
2680 +#endif
2681 +       return vx_check(xid, VS_WATCH_P | VS_IDENT);
2682 +}
2683 +
2684 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2685 +{
2686 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2687 +}
2688 +
2689 +static struct file_operations devpts_dir_operations = {
2690 +       .open           = dcache_dir_open,
2691 +       .release        = dcache_dir_close,
2692 +       .llseek         = dcache_dir_lseek,
2693 +       .read           = generic_read_dir,
2694 +       .readdir        = devpts_readdir,
2695 +};
2696 +
2697  static const struct super_operations devpts_sops = {
2698         .statfs         = simple_statfs,
2699         .remount_fs     = devpts_remount,
2700 @@ -302,12 +345,15 @@ devpts_fill_super(struct super_block *s,
2701         inode = new_inode(s);
2702         if (!inode)
2703                 goto free_fsi;
2704 +
2705         inode->i_ino = 1;
2706         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2707         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2708         inode->i_op = &simple_dir_inode_operations;
2709 -       inode->i_fop = &simple_dir_operations;
2710 +       inode->i_fop = &devpts_dir_operations;
2711         inode->i_nlink = 2;
2712 +       /* devpts is xid tagged */
2713 +       inode->i_tag = (tag_t)vx_current_xid();
2714  
2715         s->s_root = d_alloc_root(inode);
2716         if (s->s_root)
2717 @@ -494,6 +540,9 @@ int devpts_pty_new(struct inode *ptmx_in
2718         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2719         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2720         init_special_inode(inode, S_IFCHR|opts->mode, device);
2721 +       /* devpts is xid tagged */
2722 +       inode->i_tag = (tag_t)vx_current_xid();
2723 +       inode->i_op = &devpts_file_inode_operations;
2724         inode->i_private = tty;
2725         tty->driver_data = inode;
2726  
2727 diff -NurpP --minimal linux-3.0-rc5/fs/ext2/balloc.c linux-3.0-rc5-vs2.3.1-pre3/fs/ext2/balloc.c
2728 --- linux-3.0-rc5/fs/ext2/balloc.c      2011-05-22 16:17:51.000000000 +0200
2729 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/ext2/balloc.c 2011-06-10 22:11:24.000000000 +0200
2730 @@ -701,7 +701,6 @@ ext2_try_to_allocate(struct super_block 
2731                         start = 0;
2732                 end = EXT2_BLOCKS_PER_GROUP(sb);
2733         }
2734 -
2735         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2736  
2737  repeat:
2738 diff -NurpP --minimal linux-3.0-rc5/fs/ext2/ext2.h linux-3.0-rc5-vs2.3.1-pre3/fs/ext2/ext2.h
2739 --- linux-3.0-rc5/fs/ext2/ext2.h        2011-05-22 16:17:51.000000000 +0200
2740 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/ext2/ext2.h   2011-06-10 22:11:24.000000000 +0200
2741 @@ -126,6 +126,7 @@ extern void ext2_set_inode_flags(struct 
2742  extern void ext2_get_inode_flags(struct ext2_inode_info *);
2743  extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2744                        u64 start, u64 len);
2745 +extern int ext2_sync_flags(struct inode *, int, int);
2746  
2747  /* ioctl.c */
2748  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2749 diff -NurpP --minimal linux-3.0-rc5/fs/ext2/file.c linux-3.0-rc5-vs2.3.1-pre3/fs/ext2/file.c
2750 --- linux-3.0-rc5/fs/ext2/file.c        2010-08-02 16:52:48.000000000 +0200
2751 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/ext2/file.c   2011-06-10 22:11:24.000000000 +0200
2752 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
2753         .setattr        = ext2_setattr,
2754         .check_acl      = ext2_check_acl,
2755         .fiemap         = ext2_fiemap,
2756 +       .sync_flags     = ext2_sync_flags,
2757  };
2758 diff -NurpP --minimal linux-3.0-rc5/fs/ext2/ialloc.c linux-3.0-rc5-vs2.3.1-pre3/fs/ext2/ialloc.c
2759 --- linux-3.0-rc5/fs/ext2/ialloc.c      2011-05-22 16:17:51.000000000 +0200
2760 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/ext2/ialloc.c 2011-06-10 22:11:24.000000000 +0200
2761 @@ -17,6 +17,7 @@
2762  #include <linux/backing-dev.h>
2763  #include <linux/buffer_head.h>
2764  #include <linux/random.h>
2765 +#include <linux/vs_tag.h>
2766  #include "ext2.h"
2767  #include "xattr.h"
2768  #include "acl.h"
2769 @@ -549,6 +550,7 @@ got:
2770                 inode->i_mode = mode;
2771                 inode->i_uid = current_fsuid();
2772                 inode->i_gid = dir->i_gid;
2773 +               inode->i_tag = dx_current_fstag(sb);
2774         } else
2775                 inode_init_owner(inode, dir, mode);
2776  
2777 diff -NurpP --minimal linux-3.0-rc5/fs/ext2/inode.c linux-3.0-rc5-vs2.3.1-pre3/fs/ext2/inode.c
2778 --- linux-3.0-rc5/fs/ext2/inode.c       2011-05-22 16:17:51.000000000 +0200
2779 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/ext2/inode.c  2011-06-10 22:11:24.000000000 +0200
2780 @@ -32,6 +32,7 @@
2781  #include <linux/mpage.h>
2782  #include <linux/fiemap.h>
2783  #include <linux/namei.h>
2784 +#include <linux/vs_tag.h>
2785  #include "ext2.h"
2786  #include "acl.h"
2787  #include "xip.h"
2788 @@ -1167,7 +1168,7 @@ static void ext2_truncate_blocks(struct 
2789                 return;
2790         if (ext2_inode_is_fast_symlink(inode))
2791                 return;
2792 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2793 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2794                 return;
2795         __ext2_truncate_blocks(inode, offset);
2796  }
2797 @@ -1256,36 +1257,61 @@ void ext2_set_inode_flags(struct inode *
2798  {
2799         unsigned int flags = EXT2_I(inode)->i_flags;
2800  
2801 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2802 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2803 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2804 +
2805 +
2806 +       if (flags & EXT2_IMMUTABLE_FL)
2807 +               inode->i_flags |= S_IMMUTABLE;
2808 +       if (flags & EXT2_IXUNLINK_FL)
2809 +               inode->i_flags |= S_IXUNLINK;
2810 +
2811         if (flags & EXT2_SYNC_FL)
2812                 inode->i_flags |= S_SYNC;
2813         if (flags & EXT2_APPEND_FL)
2814                 inode->i_flags |= S_APPEND;
2815 -       if (flags & EXT2_IMMUTABLE_FL)
2816 -               inode->i_flags |= S_IMMUTABLE;
2817         if (flags & EXT2_NOATIME_FL)
2818                 inode->i_flags |= S_NOATIME;
2819         if (flags & EXT2_DIRSYNC_FL)
2820                 inode->i_flags |= S_DIRSYNC;
2821 +
2822 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2823 +
2824 +       if (flags & EXT2_BARRIER_FL)
2825 +               inode->i_vflags |= V_BARRIER;
2826 +       if (flags & EXT2_COW_FL)
2827 +               inode->i_vflags |= V_COW;
2828  }
2829  
2830  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2831  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2832  {
2833         unsigned int flags = ei->vfs_inode.i_flags;
2834 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2835 +
2836 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2837 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2838 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2839 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2840 +
2841 +       if (flags & S_IMMUTABLE)
2842 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2843 +       if (flags & S_IXUNLINK)
2844 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2845  
2846 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2847 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2848         if (flags & S_SYNC)
2849                 ei->i_flags |= EXT2_SYNC_FL;
2850         if (flags & S_APPEND)
2851                 ei->i_flags |= EXT2_APPEND_FL;
2852 -       if (flags & S_IMMUTABLE)
2853 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2854         if (flags & S_NOATIME)
2855                 ei->i_flags |= EXT2_NOATIME_FL;
2856         if (flags & S_DIRSYNC)
2857                 ei->i_flags |= EXT2_DIRSYNC_FL;
2858 +
2859 +       if (vflags & V_BARRIER)
2860 +               ei->i_flags |= EXT2_BARRIER_FL;
2861 +       if (vflags & V_COW)
2862 +               ei->i_flags |= EXT2_COW_FL;
2863  }
2864  
2865  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2866 @@ -1295,6 +1321,8 @@ struct inode *ext2_iget (struct super_bl
2867         struct ext2_inode *raw_inode;
2868         struct inode *inode;
2869         long ret = -EIO;
2870 +       uid_t uid;
2871 +       gid_t gid;
2872         int n;
2873  
2874         inode = iget_locked(sb, ino);
2875 @@ -1313,12 +1341,17 @@ struct inode *ext2_iget (struct super_bl
2876         }
2877  
2878         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2879 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2880 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2881 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2882 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2883         if (!(test_opt (inode->i_sb, NO_UID32))) {
2884 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2885 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2886 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2887 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2888         }
2889 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2890 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2891 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2892 +               le16_to_cpu(raw_inode->i_raw_tag));
2893 +
2894         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
2895         inode->i_size = le32_to_cpu(raw_inode->i_size);
2896         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2897 @@ -1416,8 +1449,8 @@ static int __ext2_write_inode(struct ino
2898         struct ext2_inode_info *ei = EXT2_I(inode);
2899         struct super_block *sb = inode->i_sb;
2900         ino_t ino = inode->i_ino;
2901 -       uid_t uid = inode->i_uid;
2902 -       gid_t gid = inode->i_gid;
2903 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2904 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2905         struct buffer_head * bh;
2906         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2907         int n;
2908 @@ -1453,6 +1486,9 @@ static int __ext2_write_inode(struct ino
2909                 raw_inode->i_uid_high = 0;
2910                 raw_inode->i_gid_high = 0;
2911         }
2912 +#ifdef CONFIG_TAGGING_INTERN
2913 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2914 +#endif
2915         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2916         raw_inode->i_size = cpu_to_le32(inode->i_size);
2917         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2918 @@ -1533,7 +1569,8 @@ int ext2_setattr(struct dentry *dentry, 
2919         if (is_quota_modification(inode, iattr))
2920                 dquot_initialize(inode);
2921         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
2922 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
2923 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
2924 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
2925                 error = dquot_transfer(inode, iattr);
2926                 if (error)
2927                         return error;
2928 diff -NurpP --minimal linux-3.0-rc5/fs/ext2/ioctl.c linux-3.0-rc5-vs2.3.1-pre3/fs/ext2/ioctl.c
2929 --- linux-3.0-rc5/fs/ext2/ioctl.c       2011-05-22 16:17:51.000000000 +0200
2930 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/ext2/ioctl.c  2011-06-10 22:11:24.000000000 +0200
2931 @@ -17,6 +17,16 @@
2932  #include <asm/uaccess.h>
2933  
2934  
2935 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2936 +{
2937 +       inode->i_flags = flags;
2938 +       inode->i_vflags = vflags;
2939 +       ext2_get_inode_flags(EXT2_I(inode));
2940 +       inode->i_ctime = CURRENT_TIME_SEC;
2941 +       mark_inode_dirty(inode);
2942 +       return 0;
2943 +}
2944 +
2945  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2946  {
2947         struct inode *inode = filp->f_dentry->d_inode;
2948 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2949  
2950                 flags = ext2_mask_flags(inode->i_mode, flags);
2951  
2952 +               if (IS_BARRIER(inode)) {
2953 +                       vxwprintk_task(1, "messing with the barrier.");
2954 +                       return -EACCES;
2955 +               }
2956 +
2957                 mutex_lock(&inode->i_mutex);
2958                 /* Is it quota file? Do not allow user to mess with it */
2959                 if (IS_NOQUOTA(inode)) {
2960 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2961                  *
2962                  * This test looks nicer. Thanks to Pauline Middelink
2963                  */
2964 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2965 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2966 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2967 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2968                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2969                                 mutex_unlock(&inode->i_mutex);
2970                                 ret = -EPERM;
2971 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2972                         }
2973                 }
2974  
2975 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
2976 +               flags &= EXT2_FL_USER_MODIFIABLE;
2977                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2978                 ei->i_flags = flags;
2979                 mutex_unlock(&inode->i_mutex);
2980 diff -NurpP --minimal linux-3.0-rc5/fs/ext2/namei.c linux-3.0-rc5-vs2.3.1-pre3/fs/ext2/namei.c
2981 --- linux-3.0-rc5/fs/ext2/namei.c       2011-05-22 16:17:51.000000000 +0200
2982 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/ext2/namei.c  2011-06-10 22:11:24.000000000 +0200
2983 @@ -32,6 +32,7 @@
2984  
2985  #include <linux/pagemap.h>
2986  #include <linux/quotaops.h>
2987 +#include <linux/vs_tag.h>
2988  #include "ext2.h"
2989  #include "xattr.h"
2990  #include "acl.h"
2991 @@ -75,6 +76,7 @@ static struct dentry *ext2_lookup(struct
2992                                 return ERR_PTR(-EIO);
2993                         } else {
2994                                 return ERR_CAST(inode);
2995 +               dx_propagate_tag(nd, inode);
2996                         }
2997                 }
2998         }
2999 @@ -413,6 +415,7 @@ const struct inode_operations ext2_dir_i
3000  #endif
3001         .setattr        = ext2_setattr,
3002         .check_acl      = ext2_check_acl,
3003 +       .sync_flags     = ext2_sync_flags,
3004  };
3005  
3006  const struct inode_operations ext2_special_inode_operations = {
3007 diff -NurpP --minimal linux-3.0-rc5/fs/ext2/super.c linux-3.0-rc5-vs2.3.1-pre3/fs/ext2/super.c
3008 --- linux-3.0-rc5/fs/ext2/super.c       2011-07-01 11:14:18.000000000 +0200
3009 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/ext2/super.c  2011-06-10 22:11:24.000000000 +0200
3010 @@ -394,7 +394,8 @@ enum {
3011         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
3012         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
3013         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
3014 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
3015 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
3016 +       Opt_tag, Opt_notag, Opt_tagid
3017  };
3018  
3019  static const match_table_t tokens = {
3020 @@ -422,6 +423,9 @@ static const match_table_t tokens = {
3021         {Opt_acl, "acl"},
3022         {Opt_noacl, "noacl"},
3023         {Opt_xip, "xip"},
3024 +       {Opt_tag, "tag"},
3025 +       {Opt_notag, "notag"},
3026 +       {Opt_tagid, "tagid=%u"},
3027         {Opt_grpquota, "grpquota"},
3028         {Opt_ignore, "noquota"},
3029         {Opt_quota, "quota"},
3030 @@ -492,6 +496,20 @@ static int parse_options(char *options, 
3031                 case Opt_nouid32:
3032                         set_opt (sbi->s_mount_opt, NO_UID32);
3033                         break;
3034 +#ifndef CONFIG_TAGGING_NONE
3035 +               case Opt_tag:
3036 +                       set_opt (sbi->s_mount_opt, TAGGED);
3037 +                       break;
3038 +               case Opt_notag:
3039 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3040 +                       break;
3041 +#endif
3042 +#ifdef CONFIG_PROPAGATE
3043 +               case Opt_tagid:
3044 +                       /* use args[0] */
3045 +                       set_opt (sbi->s_mount_opt, TAGGED);
3046 +                       break;
3047 +#endif
3048                 case Opt_nocheck:
3049                         clear_opt (sbi->s_mount_opt, CHECK);
3050                         break;
3051 @@ -850,6 +868,8 @@ static int ext2_fill_super(struct super_
3052         if (!parse_options((char *) data, sb))
3053                 goto failed_mount;
3054  
3055 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
3056 +               sb->s_flags |= MS_TAGGED;
3057         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3058                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
3059                  MS_POSIXACL : 0);
3060 @@ -1224,6 +1244,14 @@ static int ext2_remount (struct super_bl
3061                 goto restore_opts;
3062         }
3063  
3064 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
3065 +               !(sb->s_flags & MS_TAGGED)) {
3066 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
3067 +                      sb->s_id);
3068 +               err = -EINVAL;
3069 +               goto restore_opts;
3070 +       }
3071 +
3072         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3073                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3074  
3075 diff -NurpP --minimal linux-3.0-rc5/fs/ext3/file.c linux-3.0-rc5-vs2.3.1-pre3/fs/ext3/file.c
3076 --- linux-3.0-rc5/fs/ext3/file.c        2010-07-07 18:31:51.000000000 +0200
3077 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/ext3/file.c   2011-06-10 22:11:24.000000000 +0200
3078 @@ -81,5 +81,6 @@ const struct inode_operations ext3_file_
3079  #endif
3080         .check_acl      = ext3_check_acl,
3081         .fiemap         = ext3_fiemap,
3082 +       .sync_flags     = ext3_sync_flags,
3083  };
3084  
3085 diff -NurpP --minimal linux-3.0-rc5/fs/ext3/ialloc.c linux-3.0-rc5-vs2.3.1-pre3/fs/ext3/ialloc.c
3086 --- linux-3.0-rc5/fs/ext3/ialloc.c      2011-05-22 16:17:52.000000000 +0200
3087 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/ext3/ialloc.c 2011-06-10 22:11:24.000000000 +0200
3088 @@ -23,6 +23,7 @@
3089  #include <linux/buffer_head.h>
3090  #include <linux/random.h>
3091  #include <linux/bitops.h>
3092 +#include <linux/vs_tag.h>
3093  
3094  #include <asm/byteorder.h>
3095  
3096 @@ -532,6 +533,7 @@ got:
3097                 inode->i_mode = mode;
3098                 inode->i_uid = current_fsuid();
3099                 inode->i_gid = dir->i_gid;
3100 +               inode->i_tag = dx_current_fstag(sb);
3101         } else
3102                 inode_init_owner(inode, dir, mode);
3103  
3104 diff -NurpP --minimal linux-3.0-rc5/fs/ext3/inode.c linux-3.0-rc5-vs2.3.1-pre3/fs/ext3/inode.c
3105 --- linux-3.0-rc5/fs/ext3/inode.c       2011-07-01 11:14:18.000000000 +0200
3106 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/ext3/inode.c  2011-06-10 22:11:24.000000000 +0200
3107 @@ -38,6 +38,7 @@
3108  #include <linux/bio.h>
3109  #include <linux/fiemap.h>
3110  #include <linux/namei.h>
3111 +#include <linux/vs_tag.h>
3112  #include "xattr.h"
3113  #include "acl.h"
3114  
3115 @@ -2391,7 +2392,7 @@ static void ext3_free_branches(handle_t 
3116  
3117  int ext3_can_truncate(struct inode *inode)
3118  {
3119 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3120 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3121                 return 0;
3122         if (S_ISREG(inode->i_mode))
3123                 return 1;
3124 @@ -2775,36 +2776,60 @@ void ext3_set_inode_flags(struct inode *
3125  {
3126         unsigned int flags = EXT3_I(inode)->i_flags;
3127  
3128 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3129 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3130 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3131 +
3132 +       if (flags & EXT3_IMMUTABLE_FL)
3133 +               inode->i_flags |= S_IMMUTABLE;
3134 +       if (flags & EXT3_IXUNLINK_FL)
3135 +               inode->i_flags |= S_IXUNLINK;
3136 +
3137         if (flags & EXT3_SYNC_FL)
3138                 inode->i_flags |= S_SYNC;
3139         if (flags & EXT3_APPEND_FL)
3140                 inode->i_flags |= S_APPEND;
3141 -       if (flags & EXT3_IMMUTABLE_FL)
3142 -               inode->i_flags |= S_IMMUTABLE;
3143         if (flags & EXT3_NOATIME_FL)
3144                 inode->i_flags |= S_NOATIME;
3145         if (flags & EXT3_DIRSYNC_FL)
3146                 inode->i_flags |= S_DIRSYNC;
3147 +
3148 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3149 +
3150 +       if (flags & EXT3_BARRIER_FL)
3151 +               inode->i_vflags |= V_BARRIER;
3152 +       if (flags & EXT3_COW_FL)
3153 +               inode->i_vflags |= V_COW;
3154  }
3155  
3156  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
3157  void ext3_get_inode_flags(struct ext3_inode_info *ei)
3158  {
3159         unsigned int flags = ei->vfs_inode.i_flags;
3160 +       unsigned int vflags = ei->vfs_inode.i_vflags;
3161 +
3162 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
3163 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
3164 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
3165 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
3166 +
3167 +       if (flags & S_IMMUTABLE)
3168 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
3169 +       if (flags & S_IXUNLINK)
3170 +               ei->i_flags |= EXT3_IXUNLINK_FL;
3171  
3172 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
3173 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
3174         if (flags & S_SYNC)
3175                 ei->i_flags |= EXT3_SYNC_FL;
3176         if (flags & S_APPEND)
3177                 ei->i_flags |= EXT3_APPEND_FL;
3178 -       if (flags & S_IMMUTABLE)
3179 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
3180         if (flags & S_NOATIME)
3181                 ei->i_flags |= EXT3_NOATIME_FL;
3182         if (flags & S_DIRSYNC)
3183                 ei->i_flags |= EXT3_DIRSYNC_FL;
3184 +
3185 +       if (vflags & V_BARRIER)
3186 +               ei->i_flags |= EXT3_BARRIER_FL;
3187 +       if (vflags & V_COW)
3188 +               ei->i_flags |= EXT3_COW_FL;
3189  }
3190  
3191  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
3192 @@ -2818,6 +2843,8 @@ struct inode *ext3_iget(struct super_blo
3193         transaction_t *transaction;
3194         long ret;
3195         int block;
3196 +       uid_t uid;
3197 +       gid_t gid;
3198  
3199         inode = iget_locked(sb, ino);
3200         if (!inode)
3201 @@ -2834,12 +2861,17 @@ struct inode *ext3_iget(struct super_blo
3202         bh = iloc.bh;
3203         raw_inode = ext3_raw_inode(&iloc);
3204         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3205 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3206 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3207 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3208 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3209         if(!(test_opt (inode->i_sb, NO_UID32))) {
3210 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3211 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3212 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3213 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3214         }
3215 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3216 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3217 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3218 +               le16_to_cpu(raw_inode->i_raw_tag));
3219 +
3220         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3221         inode->i_size = le32_to_cpu(raw_inode->i_size);
3222         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
3223 @@ -2994,6 +3026,8 @@ static int ext3_do_update_inode(handle_t
3224         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
3225         struct ext3_inode_info *ei = EXT3_I(inode);
3226         struct buffer_head *bh = iloc->bh;
3227 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3228 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3229         int err = 0, rc, block;
3230  
3231  again:
3232 @@ -3008,29 +3042,32 @@ again:
3233         ext3_get_inode_flags(ei);
3234         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3235         if(!(test_opt(inode->i_sb, NO_UID32))) {
3236 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3237 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3238 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3239 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3240  /*
3241   * Fix up interoperability with old kernels. Otherwise, old inodes get
3242   * re-used with the upper 16 bits of the uid/gid intact
3243   */
3244                 if(!ei->i_dtime) {
3245                         raw_inode->i_uid_high =
3246 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3247 +                               cpu_to_le16(high_16_bits(uid));
3248                         raw_inode->i_gid_high =
3249 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3250 +                               cpu_to_le16(high_16_bits(gid));
3251                 } else {
3252                         raw_inode->i_uid_high = 0;
3253                         raw_inode->i_gid_high = 0;
3254                 }
3255         } else {
3256                 raw_inode->i_uid_low =
3257 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3258 +                       cpu_to_le16(fs_high2lowuid(uid));
3259                 raw_inode->i_gid_low =
3260 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3261 +                       cpu_to_le16(fs_high2lowgid(gid));
3262                 raw_inode->i_uid_high = 0;
3263                 raw_inode->i_gid_high = 0;
3264         }
3265 +#ifdef CONFIG_TAGGING_INTERN
3266 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3267 +#endif
3268         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3269         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
3270         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
3271 @@ -3190,7 +3227,8 @@ int ext3_setattr(struct dentry *dentry, 
3272         if (is_quota_modification(inode, attr))
3273                 dquot_initialize(inode);
3274         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3275 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3276 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3277 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3278                 handle_t *handle;
3279  
3280                 /* (user+group)*(old+new) structure, inode write (sb,
3281 @@ -3212,6 +3250,8 @@ int ext3_setattr(struct dentry *dentry, 
3282                         inode->i_uid = attr->ia_uid;
3283                 if (attr->ia_valid & ATTR_GID)
3284                         inode->i_gid = attr->ia_gid;
3285 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3286 +                       inode->i_tag = attr->ia_tag;
3287                 error = ext3_mark_inode_dirty(handle, inode);
3288                 ext3_journal_stop(handle);
3289         }
3290 diff -NurpP --minimal linux-3.0-rc5/fs/ext3/ioctl.c linux-3.0-rc5-vs2.3.1-pre3/fs/ext3/ioctl.c
3291 --- linux-3.0-rc5/fs/ext3/ioctl.c       2011-05-22 16:17:52.000000000 +0200
3292 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/ext3/ioctl.c  2011-06-10 22:11:24.000000000 +0200
3293 @@ -8,6 +8,7 @@
3294   */
3295  
3296  #include <linux/fs.h>
3297 +#include <linux/mount.h>
3298  #include <linux/jbd.h>
3299  #include <linux/capability.h>
3300  #include <linux/ext3_fs.h>
3301 @@ -17,6 +18,34 @@
3302  #include <linux/compat.h>
3303  #include <asm/uaccess.h>
3304  
3305 +
3306 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
3307 +{
3308 +       handle_t *handle = NULL;
3309 +       struct ext3_iloc iloc;
3310 +       int err;
3311 +
3312 +       handle = ext3_journal_start(inode, 1);
3313 +       if (IS_ERR(handle))
3314 +               return PTR_ERR(handle);
3315 +
3316 +       if (IS_SYNC(inode))
3317 +               handle->h_sync = 1;
3318 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
3319 +       if (err)
3320 +               goto flags_err;
3321 +
3322 +       inode->i_flags = flags;
3323 +       inode->i_vflags = vflags;
3324 +       ext3_get_inode_flags(EXT3_I(inode));
3325 +       inode->i_ctime = CURRENT_TIME_SEC;
3326 +
3327 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
3328 +flags_err:
3329 +       ext3_journal_stop(handle);
3330 +       return err;
3331 +}
3332 +
3333  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3334  {
3335         struct inode *inode = filp->f_dentry->d_inode;
3336 @@ -50,6 +79,11 @@ long ext3_ioctl(struct file *filp, unsig
3337  
3338                 flags = ext3_mask_flags(inode->i_mode, flags);
3339  
3340 +               if (IS_BARRIER(inode)) {
3341 +                       vxwprintk_task(1, "messing with the barrier.");
3342 +                       return -EACCES;
3343 +               }
3344 +
3345                 mutex_lock(&inode->i_mutex);
3346  
3347                 /* Is it quota file? Do not allow user to mess with it */
3348 @@ -68,7 +102,9 @@ long ext3_ioctl(struct file *filp, unsig
3349                  *
3350                  * This test looks nicer. Thanks to Pauline Middelink
3351                  */
3352 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
3353 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
3354 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
3355 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
3356                         if (!capable(CAP_LINUX_IMMUTABLE))
3357                                 goto flags_out;
3358                 }
3359 @@ -93,7 +129,7 @@ long ext3_ioctl(struct file *filp, unsig
3360                 if (err)
3361                         goto flags_err;
3362  
3363 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
3364 +               flags &= EXT3_FL_USER_MODIFIABLE;
3365                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
3366                 ei->i_flags = flags;
3367  
3368 diff -NurpP --minimal linux-3.0-rc5/fs/ext3/namei.c linux-3.0-rc5-vs2.3.1-pre3/fs/ext3/namei.c
3369 --- linux-3.0-rc5/fs/ext3/namei.c       2011-07-01 11:14:18.000000000 +0200
3370 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/ext3/namei.c  2011-06-10 22:11:24.000000000 +0200
3371 @@ -36,6 +36,7 @@
3372  #include <linux/quotaops.h>
3373  #include <linux/buffer_head.h>
3374  #include <linux/bio.h>
3375 +#include <linux/vs_tag.h>
3376  
3377  #include "namei.h"
3378  #include "xattr.h"
3379 @@ -923,6 +924,7 @@ restart:
3380                                 if (bh)
3381                                         ll_rw_block(READ_META, 1, &bh);
3382                         }
3383 +               dx_propagate_tag(nd, inode);
3384                 }
3385                 if ((bh = bh_use[ra_ptr++]) == NULL)
3386                         goto next;
3387 @@ -2534,6 +2536,7 @@ const struct inode_operations ext3_dir_i
3388         .removexattr    = generic_removexattr,
3389  #endif
3390         .check_acl      = ext3_check_acl,
3391 +       .sync_flags     = ext3_sync_flags,
3392  };
3393  
3394  const struct inode_operations ext3_special_inode_operations = {
3395 diff -NurpP --minimal linux-3.0-rc5/fs/ext3/super.c linux-3.0-rc5-vs2.3.1-pre3/fs/ext3/super.c
3396 --- linux-3.0-rc5/fs/ext3/super.c       2011-07-01 11:14:18.000000000 +0200
3397 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/ext3/super.c  2011-06-10 22:11:24.000000000 +0200
3398 @@ -821,7 +821,8 @@ enum {
3399         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
3400         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
3401         Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
3402 -       Opt_resize, Opt_usrquota, Opt_grpquota
3403 +       Opt_resize, Opt_usrquota, Opt_grpquota,
3404 +       Opt_tag, Opt_notag, Opt_tagid
3405  };
3406  
3407  static const match_table_t tokens = {
3408 @@ -878,6 +879,9 @@ static const match_table_t tokens = {
3409         {Opt_barrier, "barrier"},
3410         {Opt_nobarrier, "nobarrier"},
3411         {Opt_resize, "resize"},
3412 +       {Opt_tag, "tag"},
3413 +       {Opt_notag, "notag"},
3414 +       {Opt_tagid, "tagid=%u"},
3415         {Opt_err, NULL},
3416  };
3417  
3418 @@ -1030,6 +1034,20 @@ static int parse_options (char *options,
3419                 case Opt_nouid32:
3420                         set_opt (sbi->s_mount_opt, NO_UID32);
3421                         break;
3422 +#ifndef CONFIG_TAGGING_NONE
3423 +               case Opt_tag:
3424 +                       set_opt (sbi->s_mount_opt, TAGGED);
3425 +                       break;
3426 +               case Opt_notag:
3427 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3428 +                       break;
3429 +#endif
3430 +#ifdef CONFIG_PROPAGATE
3431 +               case Opt_tagid:
3432 +                       /* use args[0] */
3433 +                       set_opt (sbi->s_mount_opt, TAGGED);
3434 +                       break;
3435 +#endif
3436                 case Opt_nocheck:
3437                         clear_opt (sbi->s_mount_opt, CHECK);
3438                         break;
3439 @@ -1724,6 +1742,9 @@ static int ext3_fill_super (struct super
3440                             NULL, 0))
3441                 goto failed_mount;
3442  
3443 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
3444 +               sb->s_flags |= MS_TAGGED;
3445 +
3446         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3447                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3448  
3449 @@ -2604,6 +2625,14 @@ static int ext3_remount (struct super_bl
3450         if (test_opt(sb, ABORT))
3451                 ext3_abort(sb, __func__, "Abort forced by user");
3452  
3453 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
3454 +               !(sb->s_flags & MS_TAGGED)) {
3455 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
3456 +                       sb->s_id);
3457 +               err = -EINVAL;
3458 +               goto restore_opts;
3459 +       }
3460 +
3461         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3462                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3463  
3464 diff -NurpP --minimal linux-3.0-rc5/fs/ext4/ext4.h linux-3.0-rc5-vs2.3.1-pre3/fs/ext4/ext4.h
3465 --- linux-3.0-rc5/fs/ext4/ext4.h        2011-07-01 11:14:18.000000000 +0200
3466 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/ext4/ext4.h   2011-06-10 22:11:24.000000000 +0200
3467 @@ -350,8 +350,12 @@ struct flex_groups {
3468  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
3469  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
3470  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
3471 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
3472  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
3473  
3474 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
3475 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
3476 +
3477  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
3478  #define EXT4_FL_USER_MODIFIABLE                0x004B80FF /* User modifiable flags */
3479  
3480 @@ -608,7 +612,8 @@ struct ext4_inode {
3481                         __le16  l_i_file_acl_high;
3482                         __le16  l_i_uid_high;   /* these 2 fields */
3483                         __le16  l_i_gid_high;   /* were reserved2[0] */
3484 -                       __u32   l_i_reserved2;
3485 +                       __le16  l_i_tag;        /* Context Tag */
3486 +                       __u16   l_i_reserved2;
3487                 } linux2;
3488                 struct {
3489                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
3490 @@ -726,6 +731,7 @@ do {                                                                               \
3491  #define i_gid_low      i_gid
3492  #define i_uid_high     osd2.linux2.l_i_uid_high
3493  #define i_gid_high     osd2.linux2.l_i_gid_high
3494 +#define i_raw_tag      osd2.linux2.l_i_tag
3495  #define i_reserved2    osd2.linux2.l_i_reserved2
3496  
3497  #elif defined(__GNU__)
3498 @@ -902,6 +908,7 @@ struct ext4_inode_info {
3499  #define EXT4_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
3500  #define EXT4_MOUNT_NO_AUTO_DA_ALLOC    0x10000 /* No auto delalloc mapping */
3501  #define EXT4_MOUNT_BARRIER             0x20000 /* Use block barriers */
3502 +#define EXT4_MOUNT_TAGGED              0x40000 /* Enable Context Tags */
3503  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
3504  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
3505  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
3506 @@ -2172,6 +2179,7 @@ extern int ext4_map_blocks(handle_t *han
3507                            struct ext4_map_blocks *map, int flags);
3508  extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
3509                         __u64 start, __u64 len);
3510 +extern int ext4_sync_flags(struct inode *, int, int);
3511  /* move_extent.c */
3512  extern int ext4_move_extents(struct file *o_filp, struct file *d_filp,
3513                              __u64 start_orig, __u64 start_donor,
3514 diff -NurpP --minimal linux-3.0-rc5/fs/ext4/file.c linux-3.0-rc5-vs2.3.1-pre3/fs/ext4/file.c
3515 --- linux-3.0-rc5/fs/ext4/file.c        2011-07-01 11:14:18.000000000 +0200
3516 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/ext4/file.c   2011-06-10 22:11:24.000000000 +0200
3517 @@ -282,5 +282,6 @@ const struct inode_operations ext4_file_
3518  #endif
3519         .check_acl      = ext4_check_acl,
3520         .fiemap         = ext4_fiemap,
3521 +       .sync_flags     = ext4_sync_flags,
3522  };
3523  
3524 diff -NurpP --minimal linux-3.0-rc5/fs/ext4/ialloc.c linux-3.0-rc5-vs2.3.1-pre3/fs/ext4/ialloc.c
3525 --- linux-3.0-rc5/fs/ext4/ialloc.c      2011-05-22 16:17:52.000000000 +0200
3526 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/ext4/ialloc.c 2011-06-10 22:11:24.000000000 +0200
3527 @@ -22,6 +22,7 @@
3528  #include <linux/random.h>
3529  #include <linux/bitops.h>
3530  #include <linux/blkdev.h>
3531 +#include <linux/vs_tag.h>
3532  #include <asm/byteorder.h>
3533  
3534  #include "ext4.h"
3535 @@ -992,6 +993,7 @@ got:
3536                 inode->i_mode = mode;
3537                 inode->i_uid = current_fsuid();
3538                 inode->i_gid = dir->i_gid;
3539 +               inode->i_tag = dx_current_fstag(sb);
3540         } else
3541                 inode_init_owner(inode, dir, mode);
3542  
3543 diff -NurpP --minimal linux-3.0-rc5/fs/ext4/inode.c linux-3.0-rc5-vs2.3.1-pre3/fs/ext4/inode.c
3544 --- linux-3.0-rc5/fs/ext4/inode.c       2011-07-01 11:14:18.000000000 +0200
3545 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/ext4/inode.c  2011-07-01 11:35:34.000000000 +0200
3546 @@ -42,6 +42,7 @@
3547  #include <linux/printk.h>
3548  #include <linux/slab.h>
3549  #include <linux/ratelimit.h>
3550 +#include <linux/vs_tag.h>
3551  
3552  #include "ext4_jbd2.h"
3553  #include "xattr.h"
3554 @@ -4797,41 +4798,64 @@ void ext4_set_inode_flags(struct inode *
3555  {
3556         unsigned int flags = EXT4_I(inode)->i_flags;
3557  
3558 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3559 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3560 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3561 +
3562 +       if (flags & EXT4_IMMUTABLE_FL)
3563 +               inode->i_flags |= S_IMMUTABLE;
3564 +       if (flags & EXT4_IXUNLINK_FL)
3565 +               inode->i_flags |= S_IXUNLINK;
3566 +
3567         if (flags & EXT4_SYNC_FL)
3568                 inode->i_flags |= S_SYNC;
3569         if (flags & EXT4_APPEND_FL)
3570                 inode->i_flags |= S_APPEND;
3571 -       if (flags & EXT4_IMMUTABLE_FL)
3572 -               inode->i_flags |= S_IMMUTABLE;
3573         if (flags & EXT4_NOATIME_FL)
3574                 inode->i_flags |= S_NOATIME;
3575         if (flags & EXT4_DIRSYNC_FL)
3576                 inode->i_flags |= S_DIRSYNC;
3577 +
3578 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3579 +
3580 +       if (flags & EXT4_BARRIER_FL)
3581 +               inode->i_vflags |= V_BARRIER;
3582 +       if (flags & EXT4_COW_FL)
3583 +               inode->i_vflags |= V_COW;
3584  }
3585  
3586  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3587  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3588  {
3589 -       unsigned int vfs_fl;
3590 +       unsigned int vfs_fl, vfs_vf;
3591         unsigned long old_fl, new_fl;
3592  
3593         do {
3594                 vfs_fl = ei->vfs_inode.i_flags;
3595 +               vfs_vf = ei->vfs_inode.i_vflags;
3596                 old_fl = ei->i_flags;
3597                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3598                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
3599 -                               EXT4_DIRSYNC_FL);
3600 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
3601 +                               EXT4_COW_FL);
3602 +
3603 +               if (vfs_fl & S_IMMUTABLE)
3604 +                       new_fl |= EXT4_IMMUTABLE_FL;
3605 +               if (vfs_fl & S_IXUNLINK)
3606 +                       new_fl |= EXT4_IXUNLINK_FL;
3607 +
3608                 if (vfs_fl & S_SYNC)
3609                         new_fl |= EXT4_SYNC_FL;
3610                 if (vfs_fl & S_APPEND)
3611                         new_fl |= EXT4_APPEND_FL;
3612 -               if (vfs_fl & S_IMMUTABLE)
3613 -                       new_fl |= EXT4_IMMUTABLE_FL;
3614                 if (vfs_fl & S_NOATIME)
3615                         new_fl |= EXT4_NOATIME_FL;
3616                 if (vfs_fl & S_DIRSYNC)
3617                         new_fl |= EXT4_DIRSYNC_FL;
3618 +
3619 +               if (vfs_vf & V_BARRIER)
3620 +                       new_fl |= EXT4_BARRIER_FL;
3621 +               if (vfs_vf & V_COW)
3622 +                       new_fl |= EXT4_COW_FL;
3623         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3624  }
3625  
3626 @@ -4867,6 +4891,8 @@ struct inode *ext4_iget(struct super_blo
3627         journal_t *journal = EXT4_SB(sb)->s_journal;
3628         long ret;
3629         int block;
3630 +       uid_t uid;
3631 +       gid_t gid;
3632  
3633         inode = iget_locked(sb, ino);
3634         if (!inode)
3635 @@ -4882,12 +4908,16 @@ struct inode *ext4_iget(struct super_blo
3636                 goto bad_inode;
3637         raw_inode = ext4_raw_inode(&iloc);
3638         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3639 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3640 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3641 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3642 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3643         if (!(test_opt(inode->i_sb, NO_UID32))) {
3644 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3645 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3646 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3647 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3648         }
3649 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3650 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3651 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3652 +               le16_to_cpu(raw_inode->i_raw_tag));
3653         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3654  
3655         ext4_clear_state_flags(ei);     /* Only relevant on 32-bit archs */
3656 @@ -5106,6 +5136,8 @@ static int ext4_do_update_inode(handle_t
3657         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
3658         struct ext4_inode_info *ei = EXT4_I(inode);
3659         struct buffer_head *bh = iloc->bh;
3660 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3661 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3662         int err = 0, rc, block;
3663  
3664         /* For fields not not tracking in the in-memory inode,
3665 @@ -5116,29 +5148,32 @@ static int ext4_do_update_inode(handle_t
3666         ext4_get_inode_flags(ei);
3667         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3668         if (!(test_opt(inode->i_sb, NO_UID32))) {
3669 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3670 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3671 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3672 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3673  /*
3674   * Fix up interoperability with old kernels. Otherwise, old inodes get
3675   * re-used with the upper 16 bits of the uid/gid intact
3676   */
3677                 if (!ei->i_dtime) {
3678                         raw_inode->i_uid_high =
3679 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3680 +                               cpu_to_le16(high_16_bits(uid));
3681                         raw_inode->i_gid_high =
3682 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3683 +                               cpu_to_le16(high_16_bits(gid));
3684                 } else {
3685                         raw_inode->i_uid_high = 0;
3686                         raw_inode->i_gid_high = 0;
3687                 }
3688         } else {
3689                 raw_inode->i_uid_low =
3690 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3691 +                       cpu_to_le16(fs_high2lowuid(uid));
3692                 raw_inode->i_gid_low =
3693 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3694 +                       cpu_to_le16(fs_high2lowgid(gid));
3695                 raw_inode->i_uid_high = 0;
3696                 raw_inode->i_gid_high = 0;
3697         }
3698 +#ifdef CONFIG_TAGGING_INTERN
3699 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3700 +#endif
3701         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3702  
3703         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3704 @@ -5324,7 +5359,8 @@ int ext4_setattr(struct dentry *dentry, 
3705         if (is_quota_modification(inode, attr))
3706                 dquot_initialize(inode);
3707         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3708 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3709 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3710 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3711                 handle_t *handle;
3712  
3713                 /* (user+group)*(old+new) structure, inode write (sb,
3714 @@ -5346,6 +5382,8 @@ int ext4_setattr(struct dentry *dentry, 
3715                         inode->i_uid = attr->ia_uid;
3716                 if (attr->ia_valid & ATTR_GID)
3717                         inode->i_gid = attr->ia_gid;
3718 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3719 +                       inode->i_tag = attr->ia_tag;
3720                 error = ext4_mark_inode_dirty(handle, inode);
3721                 ext4_journal_stop(handle);
3722         }
3723 diff -NurpP --minimal linux-3.0-rc5/fs/ext4/ioctl.c linux-3.0-rc5-vs2.3.1-pre3/fs/ext4/ioctl.c
3724 --- linux-3.0-rc5/fs/ext4/ioctl.c       2011-05-22 16:17:52.000000000 +0200
3725 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/ext4/ioctl.c  2011-06-10 22:11:24.000000000 +0200
3726 @@ -14,10 +14,39 @@
3727  #include <linux/compat.h>
3728  #include <linux/mount.h>
3729  #include <linux/file.h>
3730 +#include <linux/vs_tag.h>
3731  #include <asm/uaccess.h>
3732  #include "ext4_jbd2.h"
3733  #include "ext4.h"
3734  
3735 +
3736 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3737 +{
3738 +       handle_t *handle = NULL;
3739 +       struct ext4_iloc iloc;
3740 +       int err;
3741 +
3742 +       handle = ext4_journal_start(inode, 1);
3743 +       if (IS_ERR(handle))
3744 +               return PTR_ERR(handle);
3745 +
3746 +       if (IS_SYNC(inode))
3747 +               ext4_handle_sync(handle);
3748 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3749 +       if (err)
3750 +               goto flags_err;
3751 +
3752 +       inode->i_flags = flags;
3753 +       inode->i_vflags = vflags;
3754 +       ext4_get_inode_flags(EXT4_I(inode));
3755 +       inode->i_ctime = ext4_current_time(inode);
3756 +
3757 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3758 +flags_err:
3759 +       ext4_journal_stop(handle);
3760 +       return err;
3761 +}
3762 +
3763  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3764  {
3765         struct inode *inode = filp->f_dentry->d_inode;
3766 @@ -50,6 +79,11 @@ long ext4_ioctl(struct file *filp, unsig
3767  
3768                 flags = ext4_mask_flags(inode->i_mode, flags);
3769  
3770 +               if (IS_BARRIER(inode)) {
3771 +                       vxwprintk_task(1, "messing with the barrier.");
3772 +                       return -EACCES;
3773 +               }
3774 +
3775                 err = -EPERM;
3776                 mutex_lock(&inode->i_mutex);
3777                 /* Is it quota file? Do not allow user to mess with it */
3778 @@ -67,7 +101,9 @@ long ext4_ioctl(struct file *filp, unsig
3779                  *
3780                  * This test looks nicer. Thanks to Pauline Middelink
3781                  */
3782 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3783 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3784 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3785 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3786                         if (!capable(CAP_LINUX_IMMUTABLE))
3787                                 goto flags_out;
3788                 }
3789 diff -NurpP --minimal linux-3.0-rc5/fs/ext4/namei.c linux-3.0-rc5-vs2.3.1-pre3/fs/ext4/namei.c
3790 --- linux-3.0-rc5/fs/ext4/namei.c       2011-07-01 11:14:18.000000000 +0200
3791 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/ext4/namei.c  2011-06-10 22:11:24.000000000 +0200
3792 @@ -34,6 +34,7 @@
3793  #include <linux/quotaops.h>
3794  #include <linux/buffer_head.h>
3795  #include <linux/bio.h>
3796 +#include <linux/vs_tag.h>
3797  #include "ext4.h"
3798  #include "ext4_jbd2.h"
3799  
3800 @@ -924,6 +925,7 @@ restart:
3801                                 if (bh)
3802                                         ll_rw_block(READ_META, 1, &bh);
3803                         }
3804 +               dx_propagate_tag(nd, inode);
3805                 }
3806                 if ((bh = bh_use[ra_ptr++]) == NULL)
3807                         goto next;
3808 @@ -2596,6 +2598,7 @@ const struct inode_operations ext4_dir_i
3809  #endif
3810         .check_acl      = ext4_check_acl,
3811         .fiemap         = ext4_fiemap,
3812 +       .sync_flags     = ext4_sync_flags,
3813  };
3814  
3815  const struct inode_operations ext4_special_inode_operations = {
3816 diff -NurpP --minimal linux-3.0-rc5/fs/ext4/super.c linux-3.0-rc5-vs2.3.1-pre3/fs/ext4/super.c
3817 --- linux-3.0-rc5/fs/ext4/super.c       2011-07-01 11:14:18.000000000 +0200
3818 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/ext4/super.c  2011-07-01 11:35:34.000000000 +0200
3819 @@ -1294,6 +1294,7 @@ enum {
3820         Opt_dioread_nolock, Opt_dioread_lock,
3821         Opt_discard, Opt_nodiscard,
3822         Opt_init_inode_table, Opt_noinit_inode_table,
3823 +       Opt_tag, Opt_notag, Opt_tagid
3824  };
3825  
3826  static const match_table_t tokens = {
3827 @@ -1369,6 +1370,9 @@ static const match_table_t tokens = {
3828         {Opt_init_inode_table, "init_itable=%u"},
3829         {Opt_init_inode_table, "init_itable"},
3830         {Opt_noinit_inode_table, "noinit_itable"},
3831 +       {Opt_tag, "tag"},
3832 +       {Opt_notag, "notag"},
3833 +       {Opt_tagid, "tagid=%u"},
3834         {Opt_err, NULL},
3835  };
3836  
3837 @@ -1537,6 +1541,20 @@ static int parse_options(char *options, 
3838                 case Opt_nouid32:
3839                         set_opt(sb, NO_UID32);
3840                         break;
3841 +#ifndef CONFIG_TAGGING_NONE
3842 +               case Opt_tag:
3843 +                       set_opt(sb, TAGGED);
3844 +                       break;
3845 +               case Opt_notag:
3846 +                       clear_opt(sb, TAGGED);
3847 +                       break;
3848 +#endif
3849 +#ifdef CONFIG_PROPAGATE
3850 +               case Opt_tagid:
3851 +                       /* use args[0] */
3852 +                       set_opt(sb, TAGGED);
3853 +                       break;
3854 +#endif
3855                 case Opt_debug:
3856                         set_opt(sb, DEBUG);
3857                         break;
3858 @@ -3194,6 +3212,9 @@ static int ext4_fill_super(struct super_
3859                            &journal_ioprio, NULL, 0))
3860                 goto failed_mount;
3861  
3862 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3863 +               sb->s_flags |= MS_TAGGED;
3864 +
3865         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3866                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3867  
3868 @@ -4324,6 +4345,14 @@ static int ext4_remount(struct super_blo
3869         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3870                 ext4_abort(sb, "Abort forced by user");
3871  
3872 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3873 +               !(sb->s_flags & MS_TAGGED)) {
3874 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3875 +                       sb->s_id);
3876 +               err = -EINVAL;
3877 +               goto restore_opts;
3878 +       }
3879 +
3880         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3881                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3882  
3883 diff -NurpP --minimal linux-3.0-rc5/fs/fcntl.c linux-3.0-rc5-vs2.3.1-pre3/fs/fcntl.c
3884 --- linux-3.0-rc5/fs/fcntl.c    2011-05-22 16:17:52.000000000 +0200
3885 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/fcntl.c       2011-06-10 22:11:24.000000000 +0200
3886 @@ -20,6 +20,7 @@
3887  #include <linux/signal.h>
3888  #include <linux/rcupdate.h>
3889  #include <linux/pid_namespace.h>
3890 +#include <linux/vs_limit.h>
3891  
3892  #include <asm/poll.h>
3893  #include <asm/siginfo.h>
3894 @@ -103,6 +104,8 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldf
3895  
3896         if (tofree)
3897                 filp_close(tofree, files);
3898 +       else
3899 +               vx_openfd_inc(newfd);   /* fd was unused */
3900  
3901         return newfd;
3902  
3903 @@ -447,6 +450,8 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd,
3904         filp = fget_raw(fd);
3905         if (!filp)
3906                 goto out;
3907 +       if (!vx_files_avail(1))
3908 +               goto out;
3909  
3910         if (unlikely(filp->f_mode & FMODE_PATH)) {
3911                 if (!check_fcntl_cmd(cmd)) {
3912 diff -NurpP --minimal linux-3.0-rc5/fs/file.c linux-3.0-rc5-vs2.3.1-pre3/fs/file.c
3913 --- linux-3.0-rc5/fs/file.c     2011-05-22 16:17:52.000000000 +0200
3914 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/file.c        2011-06-10 22:11:24.000000000 +0200
3915 @@ -21,6 +21,7 @@
3916  #include <linux/spinlock.h>
3917  #include <linux/rcupdate.h>
3918  #include <linux/workqueue.h>
3919 +#include <linux/vs_limit.h>
3920  
3921  struct fdtable_defer {
3922         spinlock_t lock;
3923 @@ -359,6 +360,8 @@ struct files_struct *dup_fd(struct files
3924                 struct file *f = *old_fds++;
3925                 if (f) {
3926                         get_file(f);
3927 +                       /* TODO: sum it first for check and performance */
3928 +                       vx_openfd_inc(open_files - i);
3929                 } else {
3930                         /*
3931                          * The fd may be claimed in the fd bitmap but not yet
3932 @@ -466,6 +469,7 @@ repeat:
3933         else
3934                 FD_CLR(fd, fdt->close_on_exec);
3935         error = fd;
3936 +       vx_openfd_inc(fd);
3937  #if 1
3938         /* Sanity check */
3939         if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
3940 diff -NurpP --minimal linux-3.0-rc5/fs/file_table.c linux-3.0-rc5-vs2.3.1-pre3/fs/file_table.c
3941 --- linux-3.0-rc5/fs/file_table.c       2011-05-22 16:17:52.000000000 +0200
3942 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/file_table.c  2011-06-10 22:11:24.000000000 +0200
3943 @@ -24,6 +24,8 @@
3944  #include <linux/percpu_counter.h>
3945  #include <linux/percpu.h>
3946  #include <linux/ima.h>
3947 +#include <linux/vs_limit.h>
3948 +#include <linux/vs_context.h>
3949  
3950  #include <asm/atomic.h>
3951  
3952 @@ -135,6 +137,8 @@ struct file *get_empty_filp(void)
3953         spin_lock_init(&f->f_lock);
3954         eventpoll_init_file(f);
3955         /* f->f_version: 0 */
3956 +       f->f_xid = vx_current_xid();
3957 +       vx_files_inc(f);
3958         return f;
3959  
3960  over:
3961 @@ -253,6 +257,8 @@ static void __fput(struct file *file)
3962         }
3963         fops_put(file->f_op);
3964         put_pid(file->f_owner.pid);
3965 +       vx_files_dec(file);
3966 +       file->f_xid = 0;
3967         file_sb_list_del(file);
3968         if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
3969                 i_readcount_dec(inode);
3970 @@ -383,6 +389,8 @@ void put_filp(struct file *file)
3971  {
3972         if (atomic_long_dec_and_test(&file->f_count)) {
3973                 security_file_free(file);
3974 +               vx_files_dec(file);
3975 +               file->f_xid = 0;
3976                 file_sb_list_del(file);
3977                 file_free(file);
3978         }
3979 diff -NurpP --minimal linux-3.0-rc5/fs/fs_struct.c linux-3.0-rc5-vs2.3.1-pre3/fs/fs_struct.c
3980 --- linux-3.0-rc5/fs/fs_struct.c        2011-03-15 18:07:31.000000000 +0100
3981 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/fs_struct.c   2011-06-10 22:11:24.000000000 +0200
3982 @@ -4,6 +4,7 @@
3983  #include <linux/path.h>
3984  #include <linux/slab.h>
3985  #include <linux/fs_struct.h>
3986 +#include <linux/vserver/global.h>
3987  #include "internal.h"
3988  
3989  static inline void path_get_longterm(struct path *path)
3990 @@ -96,6 +97,7 @@ void free_fs_struct(struct fs_struct *fs
3991  {
3992         path_put_longterm(&fs->root);
3993         path_put_longterm(&fs->pwd);
3994 +       atomic_dec(&vs_global_fs);
3995         kmem_cache_free(fs_cachep, fs);
3996  }
3997  
3998 @@ -135,6 +137,7 @@ struct fs_struct *copy_fs_struct(struct 
3999                 fs->pwd = old->pwd;
4000                 path_get_longterm(&fs->pwd);
4001                 spin_unlock(&old->lock);
4002 +               atomic_inc(&vs_global_fs);
4003         }
4004         return fs;
4005  }
4006 diff -NurpP --minimal linux-3.0-rc5/fs/gfs2/file.c linux-3.0-rc5-vs2.3.1-pre3/fs/gfs2/file.c
4007 --- linux-3.0-rc5/fs/gfs2/file.c        2011-07-01 11:14:18.000000000 +0200
4008 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/gfs2/file.c   2011-06-10 22:11:24.000000000 +0200
4009 @@ -134,6 +134,9 @@ static const u32 fsflags_to_gfs2[32] = {
4010         [7] = GFS2_DIF_NOATIME,
4011         [12] = GFS2_DIF_EXHASH,
4012         [14] = GFS2_DIF_INHERIT_JDATA,
4013 +       [27] = GFS2_DIF_IXUNLINK,
4014 +       [26] = GFS2_DIF_BARRIER,
4015 +       [29] = GFS2_DIF_COW,
4016  };
4017  
4018  static const u32 gfs2_to_fsflags[32] = {
4019 @@ -143,6 +146,9 @@ static const u32 gfs2_to_fsflags[32] = {
4020         [gfs2fl_NoAtime] = FS_NOATIME_FL,
4021         [gfs2fl_ExHash] = FS_INDEX_FL,
4022         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
4023 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
4024 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
4025 +       [gfs2fl_Cow] = FS_COW_FL,
4026  };
4027  
4028  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
4029 @@ -173,10 +179,16 @@ void gfs2_set_inode_flags(struct inode *
4030  {
4031         struct gfs2_inode *ip = GFS2_I(inode);
4032         unsigned int flags = inode->i_flags;
4033 +       unsigned int vflags = inode->i_vflags;
4034 +
4035 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4036 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4037  
4038 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
4039         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
4040                 flags |= S_IMMUTABLE;
4041 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
4042 +               flags |= S_IXUNLINK;
4043 +
4044         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
4045                 flags |= S_APPEND;
4046         if (ip->i_diskflags & GFS2_DIF_NOATIME)
4047 @@ -184,6 +196,43 @@ void gfs2_set_inode_flags(struct inode *
4048         if (ip->i_diskflags & GFS2_DIF_SYNC)
4049                 flags |= S_SYNC;
4050         inode->i_flags = flags;
4051 +
4052 +       vflags &= ~(V_BARRIER | V_COW);
4053 +
4054 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
4055 +               vflags |= V_BARRIER;
4056 +       if (ip->i_diskflags & GFS2_DIF_COW)
4057 +               vflags |= V_COW;
4058 +       inode->i_vflags = vflags;
4059 +}
4060 +
4061 +void gfs2_get_inode_flags(struct inode *inode)
4062 +{
4063 +       struct gfs2_inode *ip = GFS2_I(inode);
4064 +       unsigned int flags = inode->i_flags;
4065 +       unsigned int vflags = inode->i_vflags;
4066 +
4067 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
4068 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
4069 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
4070 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
4071 +
4072 +       if (flags & S_IMMUTABLE)
4073 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
4074 +       if (flags & S_IXUNLINK)
4075 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
4076 +
4077 +       if (flags & S_APPEND)
4078 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
4079 +       if (flags & S_NOATIME)
4080 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
4081 +       if (flags & S_SYNC)
4082 +               ip->i_diskflags |= GFS2_DIF_SYNC;
4083 +
4084 +       if (vflags & V_BARRIER)
4085 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
4086 +       if (vflags & V_COW)
4087 +               ip->i_diskflags |= GFS2_DIF_COW;
4088  }
4089  
4090  /* Flags that can be set by user space */
4091 @@ -295,6 +344,37 @@ static int gfs2_set_flags(struct file *f
4092         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
4093  }
4094  
4095 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
4096 +{
4097 +       struct gfs2_inode *ip = GFS2_I(inode);
4098 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
4099 +       struct buffer_head *bh;
4100 +       struct gfs2_holder gh;
4101 +       int error;
4102 +
4103 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
4104 +       if (error)
4105 +               return error;
4106 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
4107 +       if (error)
4108 +               goto out;
4109 +       error = gfs2_meta_inode_buffer(ip, &bh);
4110 +       if (error)
4111 +               goto out_trans_end;
4112 +       gfs2_trans_add_bh(ip->i_gl, bh, 1);
4113 +       inode->i_flags = flags;
4114 +       inode->i_vflags = vflags;
4115 +       gfs2_get_inode_flags(inode);
4116 +       gfs2_dinode_out(ip, bh->b_data);
4117 +       brelse(bh);
4118 +       gfs2_set_aops(inode);
4119 +out_trans_end:
4120 +       gfs2_trans_end(sdp);
4121 +out:
4122 +       gfs2_glock_dq_uninit(&gh);
4123 +       return error;
4124 +}
4125 +
4126  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4127  {
4128         switch(cmd) {
4129 diff -NurpP --minimal linux-3.0-rc5/fs/gfs2/inode.h linux-3.0-rc5-vs2.3.1-pre3/fs/gfs2/inode.h
4130 --- linux-3.0-rc5/fs/gfs2/inode.h       2011-07-01 11:14:18.000000000 +0200
4131 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/gfs2/inode.h  2011-06-10 22:11:24.000000000 +0200
4132 @@ -120,6 +120,7 @@ extern const struct file_operations gfs2
4133  extern const struct file_operations gfs2_dir_fops_nolock;
4134  
4135  extern void gfs2_set_inode_flags(struct inode *inode);
4136 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
4137   
4138  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
4139  extern const struct file_operations gfs2_file_fops;
4140 diff -NurpP --minimal linux-3.0-rc5/fs/inode.c linux-3.0-rc5-vs2.3.1-pre3/fs/inode.c
4141 --- linux-3.0-rc5/fs/inode.c    2011-07-01 11:14:18.000000000 +0200
4142 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/inode.c       2011-07-01 11:35:34.000000000 +0200
4143 @@ -26,6 +26,7 @@
4144  #include <linux/ima.h>
4145  #include <linux/cred.h>
4146  #include <linux/buffer_head.h> /* for inode_has_buffers */
4147 +#include <linux/vs_tag.h>
4148  #include "internal.h"
4149  
4150  /*
4151 @@ -146,6 +147,9 @@ int inode_init_always(struct super_block
4152         struct address_space *const mapping = &inode->i_data;
4153  
4154         inode->i_sb = sb;
4155 +
4156 +       /* essential because of inode slab reuse */
4157 +       inode->i_tag = 0;
4158         inode->i_blkbits = sb->s_blocksize_bits;
4159         inode->i_flags = 0;
4160         atomic_set(&inode->i_count, 1);
4161 @@ -166,6 +170,7 @@ int inode_init_always(struct super_block
4162         inode->i_bdev = NULL;
4163         inode->i_cdev = NULL;
4164         inode->i_rdev = 0;
4165 +       inode->i_mdev = 0;
4166         inode->dirtied_when = 0;
4167  
4168         if (security_inode_alloc(inode))
4169 @@ -404,6 +409,8 @@ void __insert_inode_hash(struct inode *i
4170  }
4171  EXPORT_SYMBOL(__insert_inode_hash);
4172  
4173 +EXPORT_SYMBOL_GPL(__iget);
4174 +
4175  /**
4176   *     remove_inode_hash - remove an inode from the hash
4177   *     @inode: inode to unhash
4178 @@ -1643,9 +1650,11 @@ void init_special_inode(struct inode *in
4179         if (S_ISCHR(mode)) {
4180                 inode->i_fop = &def_chr_fops;
4181                 inode->i_rdev = rdev;
4182 +               inode->i_mdev = rdev;
4183         } else if (S_ISBLK(mode)) {
4184                 inode->i_fop = &def_blk_fops;
4185                 inode->i_rdev = rdev;
4186 +               inode->i_mdev = rdev;
4187         } else if (S_ISFIFO(mode))
4188                 inode->i_fop = &def_fifo_fops;
4189         else if (S_ISSOCK(mode))
4190 @@ -1674,6 +1683,7 @@ void inode_init_owner(struct inode *inod
4191         } else
4192                 inode->i_gid = current_fsgid();
4193         inode->i_mode = mode;
4194 +       inode->i_tag = dx_current_fstag(inode->i_sb);
4195  }
4196  EXPORT_SYMBOL(inode_init_owner);
4197  
4198 diff -NurpP --minimal linux-3.0-rc5/fs/ioctl.c linux-3.0-rc5-vs2.3.1-pre3/fs/ioctl.c
4199 --- linux-3.0-rc5/fs/ioctl.c    2011-05-22 16:17:52.000000000 +0200
4200 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/ioctl.c       2011-06-10 22:11:24.000000000 +0200
4201 @@ -15,6 +15,9 @@
4202  #include <linux/writeback.h>
4203  #include <linux/buffer_head.h>
4204  #include <linux/falloc.h>
4205 +#include <linux/proc_fs.h>
4206 +#include <linux/vserver/inode.h>
4207 +#include <linux/vs_tag.h>
4208  
4209  #include <asm/ioctls.h>
4210  
4211 diff -NurpP --minimal linux-3.0-rc5/fs/ioprio.c linux-3.0-rc5-vs2.3.1-pre3/fs/ioprio.c
4212 --- linux-3.0-rc5/fs/ioprio.c   2011-01-05 21:50:24.000000000 +0100
4213 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/ioprio.c      2011-06-10 22:11:24.000000000 +0200
4214 @@ -27,6 +27,7 @@
4215  #include <linux/syscalls.h>
4216  #include <linux/security.h>
4217  #include <linux/pid_namespace.h>
4218 +#include <linux/vs_base.h>
4219  
4220  int set_task_ioprio(struct task_struct *task, int ioprio)
4221  {
4222 @@ -119,6 +120,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which, 
4223                         else
4224                                 pgrp = find_vpid(who);
4225                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
4226 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4227 +                                       continue;
4228                                 ret = set_task_ioprio(p, ioprio);
4229                                 if (ret)
4230                                         break;
4231 @@ -208,6 +211,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which, 
4232                         else
4233                                 pgrp = find_vpid(who);
4234                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
4235 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4236 +                                       continue;
4237                                 tmpio = get_task_ioprio(p);
4238                                 if (tmpio < 0)
4239                                         continue;
4240 diff -NurpP --minimal linux-3.0-rc5/fs/jfs/file.c linux-3.0-rc5-vs2.3.1-pre3/fs/jfs/file.c
4241 --- linux-3.0-rc5/fs/jfs/file.c 2011-07-01 11:14:18.000000000 +0200
4242 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/jfs/file.c    2011-07-01 11:35:34.000000000 +0200
4243 @@ -102,7 +102,8 @@ int jfs_setattr(struct dentry *dentry, s
4244         if (is_quota_modification(inode, iattr))
4245                 dquot_initialize(inode);
4246         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
4247 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
4248 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
4249 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
4250                 rc = dquot_transfer(inode, iattr);
4251                 if (rc)
4252                         return rc;
4253 @@ -133,6 +134,7 @@ const struct inode_operations jfs_file_i
4254  #ifdef CONFIG_JFS_POSIX_ACL
4255         .check_acl      = jfs_check_acl,
4256  #endif
4257 +       .sync_flags     = jfs_sync_flags,
4258  };
4259  
4260  const struct file_operations jfs_file_operations = {
4261 diff -NurpP --minimal linux-3.0-rc5/fs/jfs/ioctl.c linux-3.0-rc5-vs2.3.1-pre3/fs/jfs/ioctl.c
4262 --- linux-3.0-rc5/fs/jfs/ioctl.c        2011-05-22 16:17:52.000000000 +0200
4263 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/jfs/ioctl.c   2011-06-10 22:11:24.000000000 +0200
4264 @@ -11,6 +11,7 @@
4265  #include <linux/mount.h>
4266  #include <linux/time.h>
4267  #include <linux/sched.h>
4268 +#include <linux/mount.h>
4269  #include <asm/current.h>
4270  #include <asm/uaccess.h>
4271  
4272 @@ -52,6 +53,16 @@ static long jfs_map_ext2(unsigned long f
4273  }
4274  
4275  
4276 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
4277 +{
4278 +       inode->i_flags = flags;
4279 +       inode->i_vflags = vflags;
4280 +       jfs_get_inode_flags(JFS_IP(inode));
4281 +       inode->i_ctime = CURRENT_TIME_SEC;
4282 +       mark_inode_dirty(inode);
4283 +       return 0;
4284 +}
4285 +
4286  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4287  {
4288         struct inode *inode = filp->f_dentry->d_inode;
4289 @@ -85,6 +96,11 @@ long jfs_ioctl(struct file *filp, unsign
4290                 if (!S_ISDIR(inode->i_mode))
4291                         flags &= ~JFS_DIRSYNC_FL;
4292  
4293 +               if (IS_BARRIER(inode)) {
4294 +                       vxwprintk_task(1, "messing with the barrier.");
4295 +                       return -EACCES;
4296 +               }
4297 +
4298                 /* Is it quota file? Do not allow user to mess with it */
4299                 if (IS_NOQUOTA(inode)) {
4300                         err = -EPERM;
4301 @@ -102,8 +118,8 @@ long jfs_ioctl(struct file *filp, unsign
4302                  * the relevant capability.
4303                  */
4304                 if ((oldflags & JFS_IMMUTABLE_FL) ||
4305 -                       ((flags ^ oldflags) &
4306 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
4307 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
4308 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
4309                         if (!capable(CAP_LINUX_IMMUTABLE)) {
4310                                 mutex_unlock(&inode->i_mutex);
4311                                 err = -EPERM;
4312 @@ -111,7 +127,7 @@ long jfs_ioctl(struct file *filp, unsign
4313                         }
4314                 }
4315  
4316 -               flags = flags & JFS_FL_USER_MODIFIABLE;
4317 +               flags &= JFS_FL_USER_MODIFIABLE;
4318                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
4319                 jfs_inode->mode2 = flags;
4320  
4321 diff -NurpP --minimal linux-3.0-rc5/fs/jfs/jfs_dinode.h linux-3.0-rc5-vs2.3.1-pre3/fs/jfs/jfs_dinode.h
4322 --- linux-3.0-rc5/fs/jfs/jfs_dinode.h   2008-12-25 00:26:37.000000000 +0100
4323 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/jfs/jfs_dinode.h      2011-06-10 22:11:24.000000000 +0200
4324 @@ -161,9 +161,13 @@ struct dinode {
4325  
4326  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
4327  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
4328 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
4329  
4330 -#define JFS_FL_USER_VISIBLE    0x03F80000
4331 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
4332 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
4333 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
4334 +
4335 +#define JFS_FL_USER_VISIBLE    0x07F80000
4336 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
4337  #define JFS_FL_INHERIT         0x03C80000
4338  
4339  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
4340 diff -NurpP --minimal linux-3.0-rc5/fs/jfs/jfs_filsys.h linux-3.0-rc5-vs2.3.1-pre3/fs/jfs/jfs_filsys.h
4341 --- linux-3.0-rc5/fs/jfs/jfs_filsys.h   2008-12-25 00:26:37.000000000 +0100
4342 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/jfs/jfs_filsys.h      2011-06-10 22:11:24.000000000 +0200
4343 @@ -263,6 +263,7 @@
4344  #define JFS_NAME_MAX   255
4345  #define JFS_PATH_MAX   BPSIZE
4346  
4347 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
4348  
4349  /*
4350   *     file system state (superblock state)
4351 diff -NurpP --minimal linux-3.0-rc5/fs/jfs/jfs_imap.c linux-3.0-rc5-vs2.3.1-pre3/fs/jfs/jfs_imap.c
4352 --- linux-3.0-rc5/fs/jfs/jfs_imap.c     2011-07-01 11:14:18.000000000 +0200
4353 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/jfs/jfs_imap.c        2011-07-01 11:35:34.000000000 +0200
4354 @@ -46,6 +46,7 @@
4355  #include <linux/pagemap.h>
4356  #include <linux/quotaops.h>
4357  #include <linux/slab.h>
4358 +#include <linux/vs_tag.h>
4359  
4360  #include "jfs_incore.h"
4361  #include "jfs_inode.h"
4362 @@ -3058,6 +3059,8 @@ static int copy_from_dinode(struct dinod
4363  {
4364         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
4365         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
4366 +       uid_t uid;
4367 +       gid_t gid;
4368  
4369         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
4370         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
4371 @@ -3078,14 +3081,18 @@ static int copy_from_dinode(struct dinod
4372         }
4373         ip->i_nlink = le32_to_cpu(dip->di_nlink);
4374  
4375 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
4376 +       uid = le32_to_cpu(dip->di_uid);
4377 +       gid = le32_to_cpu(dip->di_gid);
4378 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
4379 +
4380 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
4381         if (sbi->uid == -1)
4382                 ip->i_uid = jfs_ip->saved_uid;
4383         else {
4384                 ip->i_uid = sbi->uid;
4385         }
4386  
4387 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
4388 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
4389         if (sbi->gid == -1)
4390                 ip->i_gid = jfs_ip->saved_gid;
4391         else {
4392 @@ -3150,14 +3157,12 @@ static void copy_to_dinode(struct dinode
4393         dip->di_size = cpu_to_le64(ip->i_size);
4394         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
4395         dip->di_nlink = cpu_to_le32(ip->i_nlink);
4396 -       if (sbi->uid == -1)
4397 -               dip->di_uid = cpu_to_le32(ip->i_uid);
4398 -       else
4399 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
4400 -       if (sbi->gid == -1)
4401 -               dip->di_gid = cpu_to_le32(ip->i_gid);
4402 -       else
4403 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
4404 +
4405 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
4406 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
4407 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
4408 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
4409 +
4410         jfs_get_inode_flags(jfs_ip);
4411         /*
4412          * mode2 is only needed for storing the higher order bits.
4413 diff -NurpP --minimal linux-3.0-rc5/fs/jfs/jfs_inode.c linux-3.0-rc5-vs2.3.1-pre3/fs/jfs/jfs_inode.c
4414 --- linux-3.0-rc5/fs/jfs/jfs_inode.c    2010-08-02 16:52:49.000000000 +0200
4415 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/jfs/jfs_inode.c       2011-06-10 22:11:24.000000000 +0200
4416 @@ -18,6 +18,7 @@
4417  
4418  #include <linux/fs.h>
4419  #include <linux/quotaops.h>
4420 +#include <linux/vs_tag.h>
4421  #include "jfs_incore.h"
4422  #include "jfs_inode.h"
4423  #include "jfs_filsys.h"
4424 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
4425  {
4426         unsigned int flags = JFS_IP(inode)->mode2;
4427  
4428 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
4429 -               S_NOATIME | S_DIRSYNC | S_SYNC);
4430 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4431 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4432  
4433         if (flags & JFS_IMMUTABLE_FL)
4434                 inode->i_flags |= S_IMMUTABLE;
4435 +       if (flags & JFS_IXUNLINK_FL)
4436 +               inode->i_flags |= S_IXUNLINK;
4437 +
4438 +       if (flags & JFS_SYNC_FL)
4439 +               inode->i_flags |= S_SYNC;
4440         if (flags & JFS_APPEND_FL)
4441                 inode->i_flags |= S_APPEND;
4442         if (flags & JFS_NOATIME_FL)
4443                 inode->i_flags |= S_NOATIME;
4444         if (flags & JFS_DIRSYNC_FL)
4445                 inode->i_flags |= S_DIRSYNC;
4446 -       if (flags & JFS_SYNC_FL)
4447 -               inode->i_flags |= S_SYNC;
4448 +
4449 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
4450 +
4451 +       if (flags & JFS_BARRIER_FL)
4452 +               inode->i_vflags |= V_BARRIER;
4453 +       if (flags & JFS_COW_FL)
4454 +               inode->i_vflags |= V_COW;
4455  }
4456  
4457  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
4458  {
4459         unsigned int flags = jfs_ip->vfs_inode.i_flags;
4460 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
4461 +
4462 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
4463 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
4464 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
4465 +                          JFS_BARRIER_FL | JFS_COW_FL);
4466  
4467 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
4468 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
4469         if (flags & S_IMMUTABLE)
4470                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
4471 +       if (flags & S_IXUNLINK)
4472 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
4473 +
4474         if (flags & S_APPEND)
4475                 jfs_ip->mode2 |= JFS_APPEND_FL;
4476         if (flags & S_NOATIME)
4477 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
4478                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
4479         if (flags & S_SYNC)
4480                 jfs_ip->mode2 |= JFS_SYNC_FL;
4481 +
4482 +       if (vflags & V_BARRIER)
4483 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
4484 +       if (vflags & V_COW)
4485 +               jfs_ip->mode2 |= JFS_COW_FL;
4486  }
4487  
4488  /*
4489 diff -NurpP --minimal linux-3.0-rc5/fs/jfs/jfs_inode.h linux-3.0-rc5-vs2.3.1-pre3/fs/jfs/jfs_inode.h
4490 --- linux-3.0-rc5/fs/jfs/jfs_inode.h    2011-07-01 11:14:18.000000000 +0200
4491 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/jfs/jfs_inode.h       2011-06-10 22:11:24.000000000 +0200
4492 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
4493  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
4494         int fh_len, int fh_type);
4495  extern void jfs_set_inode_flags(struct inode *);
4496 +extern int jfs_sync_flags(struct inode *, int, int);
4497  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
4498  extern int jfs_setattr(struct dentry *, struct iattr *);
4499  
4500 diff -NurpP --minimal linux-3.0-rc5/fs/jfs/namei.c linux-3.0-rc5-vs2.3.1-pre3/fs/jfs/namei.c
4501 --- linux-3.0-rc5/fs/jfs/namei.c        2011-05-22 16:17:53.000000000 +0200
4502 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/jfs/namei.c   2011-06-10 22:11:24.000000000 +0200
4503 @@ -22,6 +22,7 @@
4504  #include <linux/ctype.h>
4505  #include <linux/quotaops.h>
4506  #include <linux/exportfs.h>
4507 +#include <linux/vs_tag.h>
4508  #include "jfs_incore.h"
4509  #include "jfs_superblock.h"
4510  #include "jfs_inode.h"
4511 @@ -1486,6 +1487,7 @@ static struct dentry *jfs_lookup(struct 
4512                 return ERR_CAST(ip);
4513         }
4514  
4515 +       dx_propagate_tag(nd, ip);
4516         return d_splice_alias(ip, dentry);
4517  }
4518  
4519 @@ -1550,6 +1552,7 @@ const struct inode_operations jfs_dir_in
4520  #ifdef CONFIG_JFS_POSIX_ACL
4521         .check_acl      = jfs_check_acl,
4522  #endif
4523 +       .sync_flags     = jfs_sync_flags,
4524  };
4525  
4526  const struct file_operations jfs_dir_operations = {
4527 diff -NurpP --minimal linux-3.0-rc5/fs/jfs/super.c linux-3.0-rc5-vs2.3.1-pre3/fs/jfs/super.c
4528 --- linux-3.0-rc5/fs/jfs/super.c        2011-05-22 16:17:53.000000000 +0200
4529 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/jfs/super.c   2011-06-10 22:11:24.000000000 +0200
4530 @@ -198,7 +198,8 @@ static void jfs_put_super(struct super_b
4531  enum {
4532         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4533         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4534 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
4535 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4536 +       Opt_tag, Opt_notag, Opt_tagid
4537  };
4538  
4539  static const match_table_t tokens = {
4540 @@ -208,6 +209,10 @@ static const match_table_t tokens = {
4541         {Opt_resize, "resize=%u"},
4542         {Opt_resize_nosize, "resize"},
4543         {Opt_errors, "errors=%s"},
4544 +       {Opt_tag, "tag"},
4545 +       {Opt_notag, "notag"},
4546 +       {Opt_tagid, "tagid=%u"},
4547 +       {Opt_tag, "tagxid"},
4548         {Opt_ignore, "noquota"},
4549         {Opt_ignore, "quota"},
4550         {Opt_usrquota, "usrquota"},
4551 @@ -342,6 +347,20 @@ static int parse_options(char *options, 
4552                         }
4553                         break;
4554                 }
4555 +#ifndef CONFIG_TAGGING_NONE
4556 +               case Opt_tag:
4557 +                       *flag |= JFS_TAGGED;
4558 +                       break;
4559 +               case Opt_notag:
4560 +                       *flag &= JFS_TAGGED;
4561 +                       break;
4562 +#endif
4563 +#ifdef CONFIG_PROPAGATE
4564 +               case Opt_tagid:
4565 +                       /* use args[0] */
4566 +                       *flag |= JFS_TAGGED;
4567 +                       break;
4568 +#endif
4569                 default:
4570                         printk("jfs: Unrecognized mount option \"%s\" "
4571                                         " or missing value\n", p);
4572 @@ -373,6 +392,12 @@ static int jfs_remount(struct super_bloc
4573                 return -EINVAL;
4574         }
4575  
4576 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4577 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4578 +                       sb->s_id);
4579 +               return -EINVAL;
4580 +       }
4581 +
4582         if (newLVSize) {
4583                 if (sb->s_flags & MS_RDONLY) {
4584                         printk(KERN_ERR
4585 @@ -455,6 +480,9 @@ static int jfs_fill_super(struct super_b
4586  #ifdef CONFIG_JFS_POSIX_ACL
4587         sb->s_flags |= MS_POSIXACL;
4588  #endif
4589 +       /* map mount option tagxid */
4590 +       if (sbi->flag & JFS_TAGGED)
4591 +               sb->s_flags |= MS_TAGGED;
4592  
4593         if (newLVSize) {
4594                 printk(KERN_ERR "resize option for remount only\n");
4595 diff -NurpP --minimal linux-3.0-rc5/fs/libfs.c linux-3.0-rc5-vs2.3.1-pre3/fs/libfs.c
4596 --- linux-3.0-rc5/fs/libfs.c    2011-03-15 18:07:32.000000000 +0100
4597 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/libfs.c       2011-06-10 22:11:24.000000000 +0200
4598 @@ -133,7 +133,8 @@ static inline unsigned char dt_type(stru
4599   * both impossible due to the lock on directory.
4600   */
4601  
4602 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4603 +static inline int do_dcache_readdir_filter(struct file *filp,
4604 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4605  {
4606         struct dentry *dentry = filp->f_path.dentry;
4607         struct dentry *cursor = filp->private_data;
4608 @@ -164,6 +165,8 @@ int dcache_readdir(struct file * filp, v
4609                         for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
4610                                 struct dentry *next;
4611                                 next = list_entry(p, struct dentry, d_u.d_child);
4612 +                               if (filter && !filter(next))
4613 +                                       continue;
4614                                 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
4615                                 if (!simple_positive(next)) {
4616                                         spin_unlock(&next->d_lock);
4617 @@ -190,6 +193,17 @@ int dcache_readdir(struct file * filp, v
4618         return 0;
4619  }
4620  
4621 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4622 +{
4623 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4624 +}
4625 +
4626 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4627 +       int (*filter)(struct dentry *))
4628 +{
4629 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4630 +}
4631 +
4632  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4633  {
4634         return -EISDIR;
4635 @@ -965,6 +979,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4636  EXPORT_SYMBOL(dcache_dir_lseek);
4637  EXPORT_SYMBOL(dcache_dir_open);
4638  EXPORT_SYMBOL(dcache_readdir);
4639 +EXPORT_SYMBOL(dcache_readdir_filter);
4640  EXPORT_SYMBOL(generic_read_dir);
4641  EXPORT_SYMBOL(mount_pseudo);
4642  EXPORT_SYMBOL(simple_write_begin);
4643 diff -NurpP --minimal linux-3.0-rc5/fs/locks.c linux-3.0-rc5-vs2.3.1-pre3/fs/locks.c
4644 --- linux-3.0-rc5/fs/locks.c    2011-05-22 16:17:53.000000000 +0200
4645 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/locks.c       2011-06-10 22:11:24.000000000 +0200
4646 @@ -126,6 +126,8 @@
4647  #include <linux/time.h>
4648  #include <linux/rcupdate.h>
4649  #include <linux/pid_namespace.h>
4650 +#include <linux/vs_base.h>
4651 +#include <linux/vs_limit.h>
4652  
4653  #include <asm/uaccess.h>
4654  
4655 @@ -163,6 +168,7 @@ static void locks_init_lock_always(struc
4656         fl->fl_flags = 0;
4657         fl->fl_type = 0;
4658         fl->fl_start = fl->fl_end = 0;
4659 +       fl->fl_xid = -1;
4660  }
4661  
4662  /* Allocate an empty lock structure. */
4663 @@ -173,7 +175,12 @@ static struct kmem_cache *filelock_cache
4664  /* Allocate an empty lock structure. */
4665  struct file_lock *locks_alloc_lock(void)
4666  {
4667 -       struct file_lock *fl = kmem_cache_alloc(filelock_cache, GFP_KERNEL);
4668 +       struct file_lock *fl;
4669 +
4670 +       if (!vx_locks_avail(1))
4671 +               return NULL;
4672 +
4673 +       fl = kmem_cache_alloc(filelock_cache, GFP_KERNEL);
4674  
4675         if (fl)
4676                 locks_init_lock_always(fl);
4677 @@ -190,6 +194,7 @@ void locks_free_lock(struct file_lock *f
4678         BUG_ON(!list_empty(&fl->fl_block));
4679         BUG_ON(!list_empty(&fl->fl_link));
4680  
4681 +       vx_locks_dec(fl);
4682         locks_release_private(fl);
4683         kmem_cache_free(filelock_cache, fl);
4684  }
4685 @@ -262,6 +268,7 @@ void locks_copy_lock(struct file_lock *n
4686         new->fl_file = fl->fl_file;
4687         new->fl_ops = fl->fl_ops;
4688         new->fl_lmops = fl->fl_lmops;
4689 +       new->fl_xid = fl->fl_xid;
4690  
4691         locks_copy_private(new, fl);
4692  }
4693 @@ -300,6 +307,11 @@ static int flock_make_lock(struct file *
4694         fl->fl_flags = FL_FLOCK;
4695         fl->fl_type = type;
4696         fl->fl_end = OFFSET_MAX;
4697 +
4698 +       vxd_assert(filp->f_xid == vx_current_xid(),
4699 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4700 +       fl->fl_xid = filp->f_xid;
4701 +       vx_locks_inc(fl);
4702         
4703         *lock = fl;
4704         return 0;
4705 @@ -449,6 +461,7 @@ static int lease_init(struct file *filp,
4706  
4707         fl->fl_owner = current->files;
4708         fl->fl_pid = current->tgid;
4709 +       fl->fl_xid = vx_current_xid();
4710  
4711         fl->fl_file = filp;
4712         fl->fl_flags = FL_LEASE;
4713 @@ -468,6 +481,11 @@ static struct file_lock *lease_alloc(str
4714         if (fl == NULL)
4715                 return ERR_PTR(error);
4716  
4717 +       fl->fl_xid = vx_current_xid();
4718 +       if (filp)
4719 +               vxd_assert(filp->f_xid == fl->fl_xid,
4720 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4721 +       vx_locks_inc(fl);
4722         error = lease_init(filp, type, fl);
4723         if (error) {
4724                 locks_free_lock(fl);
4725 @@ -769,6 +787,7 @@ static int flock_lock_file(struct file *
4726                 lock_flocks();
4727         }
4728  
4729 +       new_fl->fl_xid = -1;
4730  find_conflict:
4731         for_each_lock(inode, before) {
4732                 struct file_lock *fl = *before;
4733 @@ -789,6 +808,7 @@ find_conflict:
4734                 goto out;
4735         locks_copy_lock(new_fl, request);
4736         locks_insert_lock(before, new_fl);
4737 +       vx_locks_inc(new_fl);
4738         new_fl = NULL;
4739         error = 0;
4740  
4741 @@ -799,7 +819,8 @@ out:
4742         return error;
4743  }
4744  
4745 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4746 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4747 +       struct file_lock *conflock, xid_t xid)
4748  {
4749         struct file_lock *fl;
4750         struct file_lock *new_fl = NULL;
4751 @@ -809,6 +830,8 @@ static int __posix_lock_file(struct inod
4752         struct file_lock **before;
4753         int error, added = 0;
4754  
4755 +       vxd_assert(xid == vx_current_xid(),
4756 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4757         /*
4758          * We may need two file_lock structures for this operation,
4759          * so we get them in advance to avoid races.
4760 @@ -819,7 +842,11 @@ static int __posix_lock_file(struct inod
4761             (request->fl_type != F_UNLCK ||
4762              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4763                 new_fl = locks_alloc_lock();
4764 +               new_fl->fl_xid = xid;
4765 +               vx_locks_inc(new_fl);
4766                 new_fl2 = locks_alloc_lock();
4767 +               new_fl2->fl_xid = xid;
4768 +               vx_locks_inc(new_fl2);
4769         }
4770  
4771         lock_flocks();
4772 @@ -1018,7 +1045,8 @@ static int __posix_lock_file(struct inod
4773  int posix_lock_file(struct file *filp, struct file_lock *fl,
4774                         struct file_lock *conflock)
4775  {
4776 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
4777 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
4778 +               fl, conflock, filp->f_xid);
4779  }
4780  EXPORT_SYMBOL(posix_lock_file);
4781  
4782 @@ -1108,7 +1136,7 @@ int locks_mandatory_area(int read_write,
4783         fl.fl_end = offset + count - 1;
4784  
4785         for (;;) {
4786 -               error = __posix_lock_file(inode, &fl, NULL);
4787 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4788                 if (error != FILE_LOCK_DEFERRED)
4789                         break;
4790                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4791 @@ -1421,6 +1449,7 @@ int generic_setlease(struct file *filp, 
4792                 goto out;
4793  
4794         locks_insert_lock(before, lease);
4795 +       vx_locks_inc(lease);
4796         return 0;
4797  
4798  out:
4799 @@ -1805,6 +1834,11 @@ int fcntl_setlk(unsigned int fd, struct 
4800         if (file_lock == NULL)
4801                 return -ENOLCK;
4802  
4803 +       vxd_assert(filp->f_xid == vx_current_xid(),
4804 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4805 +       file_lock->fl_xid = filp->f_xid;
4806 +       vx_locks_inc(file_lock);
4807 +
4808         /*
4809          * This might block, so we do it before checking the inode.
4810          */
4811 @@ -1923,6 +1957,11 @@ int fcntl_setlk64(unsigned int fd, struc
4812         if (file_lock == NULL)
4813                 return -ENOLCK;
4814  
4815 +       vxd_assert(filp->f_xid == vx_current_xid(),
4816 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4817 +       file_lock->fl_xid = filp->f_xid;
4818 +       vx_locks_inc(file_lock);
4819 +
4820         /*
4821          * This might block, so we do it before checking the inode.
4822          */
4823 @@ -2188,8 +2227,11 @@ static int locks_show(struct seq_file *f
4824  
4825         lock_get_status(f, fl, *((loff_t *)f->private), "");
4826  
4827 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4828 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4829 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4830 +                       continue;
4831                 lock_get_status(f, bfl, *((loff_t *)f->private), " ->");
4832 +       }
4833  
4834         return 0;
4835  }
4836 diff -NurpP --minimal linux-3.0-rc5/fs/namei.c linux-3.0-rc5-vs2.3.1-pre3/fs/namei.c
4837 --- linux-3.0-rc5/fs/namei.c    2011-07-01 11:14:19.000000000 +0200
4838 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/namei.c       2011-06-22 12:39:15.000000000 +0200
4839 @@ -32,6 +32,14 @@
4840  #include <linux/fcntl.h>
4841  #include <linux/device_cgroup.h>
4842  #include <linux/fs_struct.h>
4843 +#include <linux/proc_fs.h>
4844 +#include <linux/vserver/inode.h>
4845 +#include <linux/vs_base.h>
4846 +#include <linux/vs_tag.h>
4847 +#include <linux/vs_cowbl.h>
4848 +#include <linux/vs_device.h>
4849 +#include <linux/vs_context.h>
4850 +#include <linux/pid_namespace.h>
4851  #include <asm/uaccess.h>
4852  
4853  #include "internal.h"
4854 @@ -173,6 +181,84 @@ void putname(const char *name)
4855  EXPORT_SYMBOL(putname);
4856  #endif
4857  
4858 +static inline int dx_barrier(const struct inode *inode)
4859 +{
4860 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4861 +               vxwprintk_task(1, "did hit the barrier.");
4862 +               return 1;
4863 +       }
4864 +       return 0;
4865 +}
4866 +
4867 +static int __dx_permission(const struct inode *inode, int mask)
4868 +{
4869 +       if (dx_barrier(inode))
4870 +               return -EACCES;
4871 +
4872 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4873 +               /* devpts is xid tagged */
4874 +               if (S_ISDIR(inode->i_mode) ||
4875 +                   vx_check((xid_t)inode->i_tag, VS_IDENT | VS_WATCH_P))
4876 +                       return 0;
4877 +
4878 +               /* just pretend we didn't find anything */
4879 +               return -ENOENT;
4880 +       }
4881 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4882 +               struct proc_dir_entry *de = PDE(inode);
4883 +
4884 +               if (de && !vx_hide_check(0, de->vx_flags))
4885 +                       goto out;
4886 +
4887 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4888 +                       struct pid *pid;
4889 +                       struct task_struct *tsk;
4890 +
4891 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4892 +                           vx_flags(VXF_STATE_SETUP, 0))
4893 +                               return 0;
4894 +
4895 +                       pid = PROC_I(inode)->pid;
4896 +                       if (!pid)
4897 +                               goto out;
4898 +
4899 +                       tsk = pid_task(pid, PIDTYPE_PID);
4900 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4901 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4902 +                       if (tsk && vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P))
4903 +                               return 0;
4904 +               }
4905 +               else {
4906 +                       /* FIXME: Should we block some entries here? */
4907 +                       return 0;
4908 +               }
4909 +       }
4910 +       else {
4911 +               if (dx_notagcheck(inode->i_sb) ||
4912 +                   dx_check(inode->i_tag, DX_HOSTID | DX_ADMIN | DX_WATCH |
4913 +                            DX_IDENT))
4914 +                       return 0;
4915 +       }
4916 +
4917 +out:
4918 +       return -EACCES;
4919 +}
4920 +
4921 +int dx_permission(const struct inode *inode, int mask)
4922 +{
4923 +       int ret = __dx_permission(inode, mask);
4924 +       if (unlikely(ret)) {
4925 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
4926 +               if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4927 +#endif
4928 +                   vxwprintk_task(1,
4929 +                       "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4930 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
4931 +                       inode->i_ino);
4932 +       }
4933 +       return ret;
4934 +}
4935 +
4936  /*
4937   * This does basic POSIX ACL permission checking
4938   */
4939 @@ -283,10 +369,14 @@ int inode_permission(struct inode *inode
4940                 /*
4941                  * Nobody gets write access to an immutable file.
4942                  */
4943 -               if (IS_IMMUTABLE(inode))
4944 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4945                         return -EACCES;
4946         }
4947  
4948 +       retval = dx_permission(inode, mask);
4949 +       if (retval)
4950 +               return retval;
4951 +
4952         if (inode->i_op->permission)
4953                 retval = inode->i_op->permission(inode, mask, 0);
4954         else
4955 @@ -580,6 +670,9 @@ static inline int exec_permission(struct
4956         int ret;
4957         struct user_namespace *ns = inode_userns(inode);
4958  
4959 +       if (dx_barrier(inode))
4960 +               return -EACCES;
4961 +
4962         if (inode->i_op->permission) {
4963                 ret = inode->i_op->permission(inode, MAY_EXEC, flags);
4964         } else {
4965 @@ -1082,7 +1175,8 @@ static void follow_dotdot(struct nameida
4966  
4967                 if (nd->path.dentry == nd->root.dentry &&
4968                     nd->path.mnt == nd->root.mnt) {
4969 -                       break;
4970 +                       /* for sane '/' avoid follow_mount() */
4971 +                       return;
4972                 }
4973                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4974                         /* rare case of legitimate dget_parent()... */
4975 @@ -1832,7 +1926,7 @@ static int may_delete(struct inode *dir,
4976         if (IS_APPEND(dir))
4977                 return -EPERM;
4978         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
4979 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4980 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4981                 return -EPERM;
4982         if (isdir) {
4983                 if (!S_ISDIR(victim->d_inode->i_mode))
4984 @@ -1959,6 +2053,15 @@ static int may_open(struct path *path, i
4985                 break;
4986         }
4987  
4988 +#ifdef CONFIG_VSERVER_COWBL
4989 +       if (IS_COW(inode) &&
4990 +               ((flag & O_ACCMODE) != O_RDONLY)) {
4991 +               if (IS_COW_LINK(inode))
4992 +                       return -EMLINK;
4993 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4994 +               mark_inode_dirty(inode);
4995 +       }
4996 +#endif
4997         error = inode_permission(inode, acc_mode);
4998         if (error)
4999                 return error;
5000 @@ -2852,7 +2955,7 @@ int vfs_link(struct dentry *old_dentry, 
5001         /*
5002          * A link to an append-only or immutable file cannot be created.
5003          */
5004 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
5005 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
5006                 return -EPERM;
5007         if (!dir->i_op->link)
5008                 return -EPERM;
5009 @@ -3238,6 +3341,222 @@ int vfs_follow_link(struct nameidata *nd
5010         return __vfs_follow_link(nd, link);
5011  }
5012  
5013 +
5014 +#ifdef CONFIG_VSERVER_COWBL
5015 +
5016 +#include <linux/file.h>
5017 +
5018 +static inline
5019 +long do_cow_splice(struct file *in, struct file *out, size_t len)
5020 +{
5021 +       loff_t ppos = 0;
5022 +
5023 +       return do_splice_direct(in, &ppos, out, len, 0);
5024 +}
5025 +
5026 +struct dentry *cow_break_link(const char *pathname)
5027 +{
5028 +       int ret, mode, pathlen, redo = 0;
5029 +       struct nameidata old_nd, dir_nd;
5030 +       struct path old_path, new_path;
5031 +       struct dentry *dir, *res = NULL;
5032 +       struct file *old_file;
5033 +       struct file *new_file;
5034 +       char *to, *path, pad='\251';
5035 +       loff_t size;
5036 +
5037 +       vxdprintk(VXD_CBIT(misc, 1),
5038 +               "cow_break_link(" VS_Q("%s") ")", pathname);
5039 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
5040 +       ret = -ENOMEM;
5041 +       if (!path)
5042 +               goto out;
5043 +
5044 +       /* old_nd will have refs to dentry and mnt */
5045 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
5046 +       vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(old): %d", ret);
5047 +       if (ret < 0)
5048 +               goto out_free_path;
5049 +
5050 +       old_path = old_nd.path;
5051 +       mode = old_path.dentry->d_inode->i_mode;
5052 +
5053 +       to = d_path(&old_path, path, PATH_MAX-2);
5054 +       pathlen = strlen(to);
5055 +       vxdprintk(VXD_CBIT(misc, 2),
5056 +               "old path " VS_Q("%s") " [" VS_Q("%.*s") ":%d]", to,
5057 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5058 +               old_path.dentry->d_name.len);
5059 +
5060 +       to[pathlen + 1] = 0;
5061 +retry:
5062 +       to[pathlen] = pad--;
5063 +       ret = -EMLINK;
5064 +       if (pad <= '\240')
5065 +               goto out_rel_old;
5066 +
5067 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
5068 +       /* dir_nd will have refs to dentry and mnt */
5069 +       ret = do_path_lookup(AT_FDCWD, to,
5070 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
5071 +       vxdprintk(VXD_CBIT(misc, 2),
5072 +               "do_path_lookup(new): %d", ret);
5073 +       if (ret < 0)
5074 +               goto retry;
5075 +
5076 +       /* this puppy downs the inode mutex */
5077 +       new_path.dentry = lookup_create(&dir_nd, 0);
5078 +       if (!new_path.dentry || IS_ERR(new_path.dentry)) {
5079 +               vxdprintk(VXD_CBIT(misc, 2),
5080 +                       "lookup_create(new): %p", new_path.dentry);
5081 +               mutex_unlock(&dir_nd.path.dentry->d_inode->i_mutex);
5082 +               path_put(&dir_nd.path);
5083 +               goto retry;
5084 +       }
5085 +       vxdprintk(VXD_CBIT(misc, 2),
5086 +               "lookup_create(new): %p [" VS_Q("%.*s") ":%d]",
5087 +               new_path.dentry,
5088 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5089 +               new_path.dentry->d_name.len);
5090 +       dir = dir_nd.path.dentry;
5091 +
5092 +       ret = vfs_create(dir_nd.path.dentry->d_inode, new_path.dentry, mode, &dir_nd);
5093 +       vxdprintk(VXD_CBIT(misc, 2),
5094 +               "vfs_create(new): %d", ret);
5095 +       if (ret == -EEXIST) {
5096 +               mutex_unlock(&dir->d_inode->i_mutex);
5097 +               dput(new_path.dentry);
5098 +               path_put(&dir_nd.path);
5099 +               goto retry;
5100 +       }
5101 +       else if (ret < 0)
5102 +               goto out_unlock_new;
5103 +
5104 +       /* drop out early, ret passes ENOENT */
5105 +       ret = -ENOENT;
5106 +       if ((redo = d_unhashed(old_path.dentry)))
5107 +               goto out_unlock_new;
5108 +
5109 +       new_path.mnt = dir_nd.path.mnt;
5110 +       dget(old_path.dentry);
5111 +       mntget(old_path.mnt);
5112 +       /* this one cleans up the dentry/mnt in case of failure */
5113 +       old_file = dentry_open(old_path.dentry, old_path.mnt,
5114 +               O_RDONLY, current_cred());
5115 +       vxdprintk(VXD_CBIT(misc, 2),
5116 +               "dentry_open(old): %p", old_file);
5117 +       if (!old_file || IS_ERR(old_file)) {
5118 +               res = IS_ERR(old_file) ? (void *) old_file : res;
5119 +               goto out_unlock_new;
5120 +       }
5121 +
5122 +       dget(new_path.dentry);
5123 +       mntget(new_path.mnt);
5124 +       /* this one cleans up the dentry/mnt in case of failure */
5125 +       new_file = dentry_open(new_path.dentry, new_path.mnt,
5126 +               O_WRONLY, current_cred());
5127 +       vxdprintk(VXD_CBIT(misc, 2),
5128 +               "dentry_open(new): %p", new_file);
5129 +
5130 +       ret = IS_ERR(new_file) ? PTR_ERR(new_file) : -ENOENT;
5131 +       if (!new_file || IS_ERR(new_file))
5132 +               goto out_fput_old;
5133 +
5134 +       size = i_size_read(old_file->f_dentry->d_inode);
5135 +       ret = do_cow_splice(old_file, new_file, size);
5136 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
5137 +       if (ret < 0) {
5138 +               goto out_fput_both;
5139 +       } else if (ret < size) {
5140 +               ret = -ENOSPC;
5141 +               goto out_fput_both;
5142 +       } else {
5143 +               struct inode *old_inode = old_path.dentry->d_inode;
5144 +               struct inode *new_inode = new_path.dentry->d_inode;
5145 +               struct iattr attr = {
5146 +                       .ia_uid = old_inode->i_uid,
5147 +                       .ia_gid = old_inode->i_gid,
5148 +                       .ia_valid = ATTR_UID | ATTR_GID
5149 +                       };
5150 +
5151 +               setattr_copy(new_inode, &attr);
5152 +               mark_inode_dirty(new_inode);
5153 +       }
5154 +
5155 +       mutex_lock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5156 +
5157 +       /* drop out late */
5158 +       ret = -ENOENT;
5159 +       if ((redo = d_unhashed(old_path.dentry)))
5160 +               goto out_unlock;
5161 +
5162 +       vxdprintk(VXD_CBIT(misc, 2),
5163 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
5164 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5165 +               new_path.dentry->d_name.len,
5166 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5167 +               old_path.dentry->d_name.len);
5168 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_path.dentry,
5169 +               old_nd.path.dentry->d_parent->d_inode, old_path.dentry);
5170 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
5171 +       res = new_path.dentry;
5172 +
5173 +out_unlock:
5174 +       mutex_unlock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5175 +
5176 +out_fput_both:
5177 +       vxdprintk(VXD_CBIT(misc, 3),
5178 +               "fput(new_file=%p[#%ld])", new_file,
5179 +               atomic_long_read(&new_file->f_count));
5180 +       fput(new_file);
5181 +
5182 +out_fput_old:
5183 +       vxdprintk(VXD_CBIT(misc, 3),
5184 +               "fput(old_file=%p[#%ld])", old_file,
5185 +               atomic_long_read(&old_file->f_count));
5186 +       fput(old_file);
5187 +
5188 +out_unlock_new:
5189 +       mutex_unlock(&dir->d_inode->i_mutex);
5190 +       if (!ret)
5191 +               goto out_redo;
5192 +
5193 +       /* error path cleanup */
5194 +       vfs_unlink(dir->d_inode, new_path.dentry);
5195 +       dput(new_path.dentry);
5196 +
5197 +out_redo:
5198 +       if (!redo)
5199 +               goto out_rel_both;
5200 +       /* lookup dentry once again */
5201 +       path_put(&old_nd.path);
5202 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
5203 +       if (ret)
5204 +               goto out_rel_both;
5205 +
5206 +       new_path.dentry = old_nd.path.dentry;
5207 +       vxdprintk(VXD_CBIT(misc, 2),
5208 +               "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
5209 +               new_path.dentry,
5210 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5211 +               new_path.dentry->d_name.len);
5212 +       dget(new_path.dentry);
5213 +       res = new_path.dentry;
5214 +
5215 +out_rel_both:
5216 +       path_put(&dir_nd.path);
5217 +out_rel_old:
5218 +       path_put(&old_nd.path);
5219 +out_free_path:
5220 +       kfree(path);
5221 +out:
5222 +       if (ret)
5223 +               res = ERR_PTR(ret);
5224 +       return res;
5225 +}
5226 +
5227 +#endif
5228 +
5229  /* get the link contents into pagecache */
5230  static char *page_getlink(struct dentry * dentry, struct page **ppage)
5231  {
5232 diff -NurpP --minimal linux-3.0-rc5/fs/namespace.c linux-3.0-rc5-vs2.3.1-pre3/fs/namespace.c
5233 --- linux-3.0-rc5/fs/namespace.c        2011-07-01 11:14:19.000000000 +0200
5234 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/namespace.c   2011-06-13 18:26:48.000000000 +0200
5235 @@ -31,6 +31,11 @@
5236  #include <linux/idr.h>
5237  #include <linux/fs_struct.h>
5238  #include <linux/fsnotify.h>
5239 +#include <linux/vs_base.h>
5240 +#include <linux/vs_context.h>
5241 +#include <linux/vs_tag.h>
5242 +#include <linux/vserver/space.h>
5243 +#include <linux/vserver/global.h>
5244  #include <asm/uaccess.h>
5245  #include <asm/unistd.h>
5246  #include "pnode.h"
5247 @@ -724,6 +729,7 @@ static struct vfsmount *clone_mnt(struct
5248                 mnt->mnt_root = dget(root);
5249                 mnt->mnt_mountpoint = mnt->mnt_root;
5250                 mnt->mnt_parent = mnt;
5251 +               mnt->mnt_tag = old->mnt_tag;
5252  
5253                 if (flag & CL_SLAVE) {
5254                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
5255 @@ -852,6 +858,31 @@ static inline void mangle(struct seq_fil
5256         seq_escape(m, s, " \t\n\\");
5257  }
5258  
5259 +static int mnt_is_reachable(struct vfsmount *mnt)
5260 +{
5261 +       struct path root;
5262 +       struct dentry *point;
5263 +       int ret;
5264 +
5265 +       if (mnt == mnt->mnt_ns->root)
5266 +               return 1;
5267 +
5268 +       br_read_lock(vfsmount_lock);
5269 +       root = current->fs->root;
5270 +       point = root.dentry;
5271 +
5272 +       while ((mnt != mnt->mnt_parent) && (mnt != root.mnt)) {
5273 +               point = mnt->mnt_mountpoint;
5274 +               mnt = mnt->mnt_parent;
5275 +       }
5276 +
5277 +       ret = (mnt == root.mnt) && is_subdir(point, root.dentry);
5278 +
5279 +       br_read_unlock(vfsmount_lock);
5280 +
5281 +       return ret;
5282 +}
5283 +
5284  /*
5285   * Simple .show_options callback for filesystems which don't want to
5286   * implement more complex mount option showing.
5287 @@ -954,6 +985,8 @@ static int show_sb_opts(struct seq_file 
5288                 { MS_SYNCHRONOUS, ",sync" },
5289                 { MS_DIRSYNC, ",dirsync" },
5290                 { MS_MANDLOCK, ",mand" },
5291 +               { MS_TAGGED, ",tag" },
5292 +               { MS_NOTAGCHECK, ",notagcheck" },
5293                 { 0, NULL }
5294         };
5295         const struct proc_fs_info *fs_infop;
5296 @@ -1000,16 +1033,26 @@ static int show_vfsmnt(struct seq_file *
5297         int err = 0;
5298         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5299  
5300 -       if (mnt->mnt_sb->s_op->show_devname) {
5301 -               err = mnt->mnt_sb->s_op->show_devname(m, mnt);
5302 -               if (err)
5303 -                       goto out;
5304 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5305 +               return SEQ_SKIP;
5306 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5307 +               return SEQ_SKIP;
5308 +
5309 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5310 +               mnt == current->fs->root.mnt) {
5311 +               seq_puts(m, "/dev/root / ");
5312         } else {
5313 -               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5314 +               if (mnt->mnt_sb->s_op->show_devname) {
5315 +                       err = mnt->mnt_sb->s_op->show_devname(m, mnt);
5316 +                       if (err)
5317 +                               goto out;
5318 +               } else {
5319 +                       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5320 +               }
5321 +               seq_putc(m, ' ');
5322 +               seq_path(m, &mnt_path, " \t\n\\");
5323 +               seq_putc(m, ' ');
5324         }
5325 -       seq_putc(m, ' ');
5326 -       seq_path(m, &mnt_path, " \t\n\\");
5327 -       seq_putc(m, ' ');
5328         show_type(m, mnt->mnt_sb);
5329         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
5330         err = show_sb_opts(m, mnt->mnt_sb);
5331 @@ -1039,6 +1082,11 @@ static int show_mountinfo(struct seq_fil
5332         struct path root = p->root;
5333         int err = 0;
5334  
5335 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5336 +               return SEQ_SKIP;
5337 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5338 +               return SEQ_SKIP;
5339 +
5340         seq_printf(m, "%i %i %u:%u ", mnt->mnt_id, mnt->mnt_parent->mnt_id,
5341                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
5342         if (sb->s_op->show_path)
5343 @@ -1107,21 +1155,31 @@ static int show_vfsstat(struct seq_file 
5344         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5345         int err = 0;
5346  
5347 -       /* device */
5348 -       if (mnt->mnt_sb->s_op->show_devname) {
5349 -               err = mnt->mnt_sb->s_op->show_devname(m, mnt);
5350 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5351 +               return SEQ_SKIP;
5352 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5353 +               return SEQ_SKIP;
5354 +
5355 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5356 +               mnt == current->fs->root.mnt) {
5357 +               seq_puts(m, "device /dev/root mounted on / ");
5358         } else {
5359 -               if (mnt->mnt_devname) {
5360 -                       seq_puts(m, "device ");
5361 -                       mangle(m, mnt->mnt_devname);
5362 -               } else
5363 -                       seq_puts(m, "no device");
5364 -       }
5365 +               /* device */
5366 +               if (mnt->mnt_sb->s_op->show_devname) {
5367 +                       err = mnt->mnt_sb->s_op->show_devname(m, mnt);
5368 +               } else {
5369 +                       if (mnt->mnt_devname) {
5370 +                               seq_puts(m, "device ");
5371 +                               mangle(m, mnt->mnt_devname);
5372 +                       } else
5373 +                               seq_puts(m, "no device");
5374 +               }
5375  
5376 -       /* mount point */
5377 -       seq_puts(m, " mounted on ");
5378 -       seq_path(m, &mnt_path, " \t\n\\");
5379 -       seq_putc(m, ' ');
5380 +               /* mount point */
5381 +               seq_puts(m, " mounted on ");
5382 +               seq_path(m, &mnt_path, " \t\n\\");
5383 +               seq_putc(m, ' ');
5384 +       }
5385  
5386         /* file system type */
5387         seq_puts(m, "with fstype ");
5388 @@ -1380,7 +1438,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
5389                 goto dput_and_out;
5390  
5391         retval = -EPERM;
5392 -       if (!capable(CAP_SYS_ADMIN))
5393 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5394                 goto dput_and_out;
5395  
5396         retval = do_umount(path.mnt, flags);
5397 @@ -1406,7 +1464,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
5398  
5399  static int mount_is_safe(struct path *path)
5400  {
5401 -       if (capable(CAP_SYS_ADMIN))
5402 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5403                 return 0;
5404         return -EPERM;
5405  #ifdef notyet
5406 @@ -1716,7 +1774,7 @@ static int do_change_type(struct path *p
5407         int type;
5408         int err = 0;
5409  
5410 -       if (!capable(CAP_SYS_ADMIN))
5411 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_NAMESPACE))
5412                 return -EPERM;
5413  
5414         if (path->dentry != path->mnt->mnt_root)
5415 @@ -1732,6 +1790,7 @@ static int do_change_type(struct path *p
5416                 if (err)
5417                         goto out_unlock;
5418         }
5419 +       // mnt->mnt_flags = mnt_flags;
5420  
5421         br_write_lock(vfsmount_lock);
5422         for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
5423 @@ -1747,12 +1806,14 @@ static int do_change_type(struct path *p
5424   * do loopback mount.
5425   */
5426  static int do_loopback(struct path *path, char *old_name,
5427 -                               int recurse)
5428 +       tag_t tag, unsigned long flags, int mnt_flags)
5429  {
5430         LIST_HEAD(umount_list);
5431         struct path old_path;
5432         struct vfsmount *mnt = NULL;
5433         int err = mount_is_safe(path);
5434 +       int recurse = flags & MS_REC;
5435 +
5436         if (err)
5437                 return err;
5438         if (!old_name || !*old_name)
5439 @@ -1818,12 +1879,12 @@ static int change_mount_flags(struct vfs
5440   * on it - tough luck.
5441   */
5442  static int do_remount(struct path *path, int flags, int mnt_flags,
5443 -                     void *data)
5444 +       void *data, xid_t xid)
5445  {
5446         int err;
5447         struct super_block *sb = path->mnt->mnt_sb;
5448  
5449 -       if (!capable(CAP_SYS_ADMIN))
5450 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
5451                 return -EPERM;
5452  
5453         if (!check_mnt(path->mnt))
5454 @@ -1871,7 +1932,7 @@ static int do_move_mount(struct path *pa
5455         struct path old_path, parent_path;
5456         struct vfsmount *p;
5457         int err = 0;
5458 -       if (!capable(CAP_SYS_ADMIN))
5459 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5460                 return -EPERM;
5461         if (!old_name || !*old_name)
5462                 return -EINVAL;
5463 @@ -2022,7 +2083,7 @@ static int do_new_mount(struct path *pat
5464                 return -EINVAL;
5465  
5466         /* we need capabilities... */
5467 -       if (!capable(CAP_SYS_ADMIN))
5468 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5469                 return -EPERM;
5470  
5471         mnt = do_kern_mount(type, flags, name, data);
5472 @@ -2291,6 +2352,7 @@ long do_mount(char *dev_name, char *dir_
5473         struct path path;
5474         int retval = 0;
5475         int mnt_flags = 0;
5476 +       tag_t tag = 0;
5477  
5478         /* Discard magic */
5479         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5480 @@ -2318,6 +2380,12 @@ long do_mount(char *dev_name, char *dir_
5481         if (!(flags & MS_NOATIME))
5482                 mnt_flags |= MNT_RELATIME;
5483  
5484 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5485 +               /* FIXME: bind and re-mounts get the tag flag? */
5486 +               if (flags & (MS_BIND|MS_REMOUNT))
5487 +                       flags |= MS_TAGID;
5488 +       }
5489 +
5490         /* Separate the per-mountpoint flags */
5491         if (flags & MS_NOSUID)
5492                 mnt_flags |= MNT_NOSUID;
5493 @@ -2334,15 +2402,17 @@ long do_mount(char *dev_name, char *dir_
5494         if (flags & MS_RDONLY)
5495                 mnt_flags |= MNT_READONLY;
5496  
5497 +       if (!capable(CAP_SYS_ADMIN))
5498 +               mnt_flags |= MNT_NODEV;
5499         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
5500                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
5501                    MS_STRICTATIME);
5502  
5503         if (flags & MS_REMOUNT)
5504                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5505 -                                   data_page);
5506 +                                   data_page, tag);
5507         else if (flags & MS_BIND)
5508 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5509 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5510         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5511                 retval = do_change_type(&path, flags);
5512         else if (flags & MS_MOVE)
5513 @@ -2442,6 +2512,7 @@ static struct mnt_namespace *dup_mnt_ns(
5514                 q = next_mnt(q, new_ns->root);
5515         }
5516         up_write(&namespace_sem);
5517 +       atomic_inc(&vs_global_mnt_ns);
5518  
5519         if (rootmnt)
5520                 mntput(rootmnt);
5521 @@ -2581,9 +2652,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5522                 goto out3;
5523  
5524         error = -EINVAL;
5525 -       if (IS_MNT_SHARED(old.mnt) ||
5526 -               IS_MNT_SHARED(new.mnt->mnt_parent) ||
5527 -               IS_MNT_SHARED(root.mnt->mnt_parent))
5528 +       if ((IS_MNT_SHARED(old.mnt) ||
5529 +               IS_MNT_SHARED(new.mnt->mnt_parent) ||
5530 +               IS_MNT_SHARED(root.mnt->mnt_parent)) &&
5531 +               !vx_flags(VXF_STATE_SETUP, 0))
5532                 goto out4;
5533         if (!check_mnt(root.mnt) || !check_mnt(new.mnt))
5534                 goto out4;
5535 @@ -2715,6 +2787,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5536         br_write_unlock(vfsmount_lock);
5537         up_write(&namespace_sem);
5538         release_mounts(&umount_list);
5539 +       atomic_dec(&vs_global_mnt_ns);
5540         kfree(ns);
5541  }
5542  EXPORT_SYMBOL(put_mnt_ns);
5543 diff -NurpP --minimal linux-3.0-rc5/fs/nfs/client.c linux-3.0-rc5-vs2.3.1-pre3/fs/nfs/client.c
5544 --- linux-3.0-rc5/fs/nfs/client.c       2011-07-01 11:14:19.000000000 +0200
5545 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/nfs/client.c  2011-06-10 22:11:24.000000000 +0200
5546 @@ -780,6 +780,9 @@ static int nfs_init_server_rpcclient(str
5547         if (server->flags & NFS_MOUNT_SOFT)
5548                 server->client->cl_softrtry = 1;
5549  
5550 +       server->client->cl_tag = 0;
5551 +       if (server->flags & NFS_MOUNT_TAGGED)
5552 +               server->client->cl_tag = 1;
5553         return 0;
5554  }
5555  
5556 @@ -951,6 +954,10 @@ static void nfs_server_set_fsinfo(struct
5557                 server->acdirmin = server->acdirmax = 0;
5558         }
5559  
5560 +       /* FIXME: needs fsinfo
5561 +       if (server->flags & NFS_MOUNT_TAGGED)
5562 +               sb->s_flags |= MS_TAGGED;       */
5563 +
5564         server->maxfilesize = fsinfo->maxfilesize;
5565  
5566         server->time_delta = fsinfo->time_delta;
5567 diff -NurpP --minimal linux-3.0-rc5/fs/nfs/dir.c linux-3.0-rc5-vs2.3.1-pre3/fs/nfs/dir.c
5568 --- linux-3.0-rc5/fs/nfs/dir.c  2011-07-01 11:14:19.000000000 +0200
5569 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/nfs/dir.c     2011-06-10 22:11:24.000000000 +0200
5570 @@ -35,6 +35,7 @@
5571  #include <linux/sched.h>
5572  #include <linux/kmemleak.h>
5573  #include <linux/xattr.h>
5574 +#include <linux/vs_tag.h>
5575  
5576  #include "delegation.h"
5577  #include "iostat.h"
5578 @@ -1298,6 +1299,7 @@ static struct dentry *nfs_lookup(struct 
5579         if (IS_ERR(res))
5580                 goto out_unblock_sillyrename;
5581  
5582 +       dx_propagate_tag(nd, inode);
5583  no_entry:
5584         res = d_materialise_unique(dentry, inode);
5585         if (res != NULL) {
5586 diff -NurpP --minimal linux-3.0-rc5/fs/nfs/inode.c linux-3.0-rc5-vs2.3.1-pre3/fs/nfs/inode.c
5587 --- linux-3.0-rc5/fs/nfs/inode.c        2011-07-01 11:14:19.000000000 +0200
5588 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/nfs/inode.c   2011-07-01 11:35:34.000000000 +0200
5589 @@ -38,6 +38,7 @@
5590  #include <linux/nfs_xdr.h>
5591  #include <linux/slab.h>
5592  #include <linux/compat.h>
5593 +#include <linux/vs_tag.h>
5594  
5595  #include <asm/system.h>
5596  #include <asm/uaccess.h>
5597 @@ -273,6 +274,8 @@ nfs_fhget(struct super_block *sb, struct
5598         if (inode->i_state & I_NEW) {
5599                 struct nfs_inode *nfsi = NFS_I(inode);
5600                 unsigned long now = jiffies;
5601 +               uid_t uid;
5602 +               gid_t gid;
5603  
5604                 /* We set i_ino for the few things that still rely on it,
5605                  * such as stat(2) */
5606 @@ -321,8 +324,8 @@ nfs_fhget(struct super_block *sb, struct
5607                 nfsi->change_attr = 0;
5608                 inode->i_size = 0;
5609                 inode->i_nlink = 0;
5610 -               inode->i_uid = -2;
5611 -               inode->i_gid = -2;
5612 +               uid = -2;
5613 +               gid = -2;
5614                 inode->i_blocks = 0;
5615                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5616  
5617 @@ -359,13 +362,13 @@ nfs_fhget(struct super_block *sb, struct
5618                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5619                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5620                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5621 -                       inode->i_uid = fattr->uid;
5622 +                       uid = fattr->uid;
5623                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5624                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5625                                 | NFS_INO_INVALID_ACCESS
5626                                 | NFS_INO_INVALID_ACL;
5627                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5628 -                       inode->i_gid = fattr->gid;
5629 +                       gid = fattr->gid;
5630                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5631                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5632                                 | NFS_INO_INVALID_ACCESS
5633 @@ -378,6 +381,11 @@ nfs_fhget(struct super_block *sb, struct
5634                          */
5635                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5636                 }
5637 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5638 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5639 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
5640 +                               /* maybe fattr->xid someday */
5641 +
5642                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5643                 nfsi->attrtimeo_timestamp = now;
5644                 nfsi->access_cache = RB_ROOT;
5645 @@ -494,6 +502,8 @@ void nfs_setattr_update_inode(struct ino
5646                         inode->i_uid = attr->ia_uid;
5647                 if ((attr->ia_valid & ATTR_GID) != 0)
5648                         inode->i_gid = attr->ia_gid;
5649 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5650 +                       inode->i_tag = attr->ia_tag;
5651                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5652                 spin_unlock(&inode->i_lock);
5653         }
5654 @@ -941,6 +951,9 @@ static int nfs_check_inode_attributes(st
5655         struct nfs_inode *nfsi = NFS_I(inode);
5656         loff_t cur_size, new_isize;
5657         unsigned long invalid = 0;
5658 +       uid_t uid;
5659 +       gid_t gid;
5660 +       tag_t tag;
5661  
5662  
5663         /* Has the inode gone and changed behind our back? */
5664 @@ -964,13 +977,18 @@ static int nfs_check_inode_attributes(st
5665                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5666         }
5667  
5668 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5669 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5670 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5671 +
5672         /* Have any file permissions changed? */
5673         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5674                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5675 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && inode->i_uid != fattr->uid)
5676 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && uid != fattr->uid)
5677                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5678 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && inode->i_gid != fattr->gid)
5679 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && gid != fattr->gid)
5680                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5681 +               /* maybe check for tag too? */
5682  
5683         /* Has the link count changed? */
5684         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5685 @@ -1205,6 +1223,9 @@ static int nfs_update_inode(struct inode
5686         unsigned long invalid = 0;
5687         unsigned long now = jiffies;
5688         unsigned long save_cache_validity;
5689 +       uid_t uid;
5690 +       gid_t gid;
5691 +       tag_t tag;
5692  
5693         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
5694                         __func__, inode->i_sb->s_id, inode->i_ino,
5695 @@ -1312,6 +1333,9 @@ static int nfs_update_inode(struct inode
5696                                 | NFS_INO_REVAL_PAGECACHE
5697                                 | NFS_INO_REVAL_FORCED);
5698  
5699 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5700 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5701 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5702  
5703         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5704                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5705 @@ -1333,9 +1357,9 @@ static int nfs_update_inode(struct inode
5706                                 | NFS_INO_REVAL_FORCED);
5707  
5708         if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
5709 -               if (inode->i_uid != fattr->uid) {
5710 +               if (uid != fattr->uid) {
5711                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5712 -                       inode->i_uid = fattr->uid;
5713 +                       uid = fattr->uid;
5714                 }
5715         } else if (server->caps & NFS_CAP_OWNER)
5716                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5717 @@ -1344,9 +1368,9 @@ static int nfs_update_inode(struct inode
5718                                 | NFS_INO_REVAL_FORCED);
5719  
5720         if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
5721 -               if (inode->i_gid != fattr->gid) {
5722 +               if (gid != fattr->gid) {
5723                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5724 -                       inode->i_gid = fattr->gid;
5725 +                       gid = fattr->gid;
5726                 }
5727         } else if (server->caps & NFS_CAP_OWNER_GROUP)
5728                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5729 @@ -1354,6 +1378,10 @@ static int nfs_update_inode(struct inode
5730                                 | NFS_INO_INVALID_ACL
5731                                 | NFS_INO_REVAL_FORCED);
5732  
5733 +       inode->i_uid = uid;
5734 +       inode->i_gid = gid;
5735 +       inode->i_tag = tag;
5736 +
5737         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5738                 if (inode->i_nlink != fattr->nlink) {
5739                         invalid |= NFS_INO_INVALID_ATTR;
5740 diff -NurpP --minimal linux-3.0-rc5/fs/nfs/nfs3xdr.c linux-3.0-rc5-vs2.3.1-pre3/fs/nfs/nfs3xdr.c
5741 --- linux-3.0-rc5/fs/nfs/nfs3xdr.c      2011-03-15 18:07:32.000000000 +0100
5742 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/nfs/nfs3xdr.c 2011-06-10 22:11:24.000000000 +0200
5743 @@ -20,6 +20,7 @@
5744  #include <linux/nfs3.h>
5745  #include <linux/nfs_fs.h>
5746  #include <linux/nfsacl.h>
5747 +#include <linux/vs_tag.h>
5748  #include "internal.h"
5749  
5750  #define NFSDBG_FACILITY                NFSDBG_XDR
5751 @@ -562,7 +563,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5752   *             set_mtime       mtime;
5753   *     };
5754   */
5755 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5756 +static void encode_sattr3(struct xdr_stream *xdr,
5757 +       const struct iattr *attr, int tag)
5758  {
5759         u32 nbytes;
5760         __be32 *p;
5761 @@ -594,15 +596,19 @@ static void encode_sattr3(struct xdr_str
5762         } else
5763                 *p++ = xdr_zero;
5764  
5765 -       if (attr->ia_valid & ATTR_UID) {
5766 +       if (attr->ia_valid & ATTR_UID ||
5767 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5768                 *p++ = xdr_one;
5769 -               *p++ = cpu_to_be32(attr->ia_uid);
5770 +               *p++ = cpu_to_be32(TAGINO_UID(tag,
5771 +                       attr->ia_uid, attr->ia_tag));
5772         } else
5773                 *p++ = xdr_zero;
5774  
5775 -       if (attr->ia_valid & ATTR_GID) {
5776 +       if (attr->ia_valid & ATTR_GID ||
5777 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5778                 *p++ = xdr_one;
5779 -               *p++ = cpu_to_be32(attr->ia_gid);
5780 +               *p++ = cpu_to_be32(TAGINO_GID(tag,
5781 +                       attr->ia_gid, attr->ia_tag));
5782         } else
5783                 *p++ = xdr_zero;
5784  
5785 @@ -878,7 +884,7 @@ static void nfs3_xdr_enc_setattr3args(st
5786                                       const struct nfs3_sattrargs *args)
5787  {
5788         encode_nfs_fh3(xdr, args->fh);
5789 -       encode_sattr3(xdr, args->sattr);
5790 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5791         encode_sattrguard3(xdr, args);
5792  }
5793  
5794 @@ -1028,13 +1034,13 @@ static void nfs3_xdr_enc_write3args(stru
5795   *     };
5796   */
5797  static void encode_createhow3(struct xdr_stream *xdr,
5798 -                             const struct nfs3_createargs *args)
5799 +       const struct nfs3_createargs *args, int tag)
5800  {
5801         encode_uint32(xdr, args->createmode);
5802         switch (args->createmode) {
5803         case NFS3_CREATE_UNCHECKED:
5804         case NFS3_CREATE_GUARDED:
5805 -               encode_sattr3(xdr, args->sattr);
5806 +               encode_sattr3(xdr, args->sattr, tag);
5807                 break;
5808         case NFS3_CREATE_EXCLUSIVE:
5809                 encode_createverf3(xdr, args->verifier);
5810 @@ -1049,7 +1055,7 @@ static void nfs3_xdr_enc_create3args(str
5811                                      const struct nfs3_createargs *args)
5812  {
5813         encode_diropargs3(xdr, args->fh, args->name, args->len);
5814 -       encode_createhow3(xdr, args);
5815 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5816  }
5817  
5818  /*
5819 @@ -1065,7 +1071,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5820                                     const struct nfs3_mkdirargs *args)
5821  {
5822         encode_diropargs3(xdr, args->fh, args->name, args->len);
5823 -       encode_sattr3(xdr, args->sattr);
5824 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5825  }
5826  
5827  /*
5828 @@ -1082,9 +1088,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
5829   *     };
5830   */
5831  static void encode_symlinkdata3(struct xdr_stream *xdr,
5832 -                               const struct nfs3_symlinkargs *args)
5833 +       const struct nfs3_symlinkargs *args, int tag)
5834  {
5835 -       encode_sattr3(xdr, args->sattr);
5836 +       encode_sattr3(xdr, args->sattr, tag);
5837         encode_nfspath3(xdr, args->pages, args->pathlen);
5838  }
5839  
5840 @@ -1093,7 +1099,7 @@ static void nfs3_xdr_enc_symlink3args(st
5841                                       const struct nfs3_symlinkargs *args)
5842  {
5843         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
5844 -       encode_symlinkdata3(xdr, args);
5845 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
5846  }
5847  
5848  /*
5849 @@ -1121,24 +1127,24 @@ static void nfs3_xdr_enc_symlink3args(st
5850   *     };
5851   */
5852  static void encode_devicedata3(struct xdr_stream *xdr,
5853 -                              const struct nfs3_mknodargs *args)
5854 +       const struct nfs3_mknodargs *args, int tag)
5855  {
5856 -       encode_sattr3(xdr, args->sattr);
5857 +       encode_sattr3(xdr, args->sattr, tag);
5858         encode_specdata3(xdr, args->rdev);
5859  }
5860  
5861  static void encode_mknoddata3(struct xdr_stream *xdr,
5862 -                             const struct nfs3_mknodargs *args)
5863 +       const struct nfs3_mknodargs *args, int tag)
5864  {
5865         encode_ftype3(xdr, args->type);
5866         switch (args->type) {
5867         case NF3CHR:
5868         case NF3BLK:
5869 -               encode_devicedata3(xdr, args);
5870 +               encode_devicedata3(xdr, args, tag);
5871                 break;
5872         case NF3SOCK:
5873         case NF3FIFO:
5874 -               encode_sattr3(xdr, args->sattr);
5875 +               encode_sattr3(xdr, args->sattr, tag);
5876                 break;
5877         case NF3REG:
5878         case NF3DIR:
5879 @@ -1153,7 +1159,7 @@ static void nfs3_xdr_enc_mknod3args(stru
5880                                     const struct nfs3_mknodargs *args)
5881  {
5882         encode_diropargs3(xdr, args->fh, args->name, args->len);
5883 -       encode_mknoddata3(xdr, args);
5884 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
5885  }
5886  
5887  /*
5888 diff -NurpP --minimal linux-3.0-rc5/fs/nfs/super.c linux-3.0-rc5-vs2.3.1-pre3/fs/nfs/super.c
5889 --- linux-3.0-rc5/fs/nfs/super.c        2011-07-01 11:14:19.000000000 +0200
5890 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/nfs/super.c   2011-06-10 22:11:24.000000000 +0200
5891 @@ -53,6 +53,7 @@
5892  #include <linux/nfs_xdr.h>
5893  #include <linux/magic.h>
5894  #include <linux/parser.h>
5895 +#include <linux/vs_tag.h>
5896  
5897  #include <asm/system.h>
5898  #include <asm/uaccess.h>
5899 @@ -87,6 +88,7 @@ enum {
5900         Opt_sharecache, Opt_nosharecache,
5901         Opt_resvport, Opt_noresvport,
5902         Opt_fscache, Opt_nofscache,
5903 +       Opt_tag, Opt_notag,
5904  
5905         /* Mount options that take integer arguments */
5906         Opt_port,
5907 @@ -100,6 +102,7 @@ enum {
5908         Opt_mountvers,
5909         Opt_nfsvers,
5910         Opt_minorversion,
5911 +       Opt_tagid,
5912  
5913         /* Mount options that take string arguments */
5914         Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
5915 @@ -180,6 +183,10 @@ static const match_table_t nfs_mount_opt
5916         { Opt_fscache_uniq, "fsc=%s" },
5917         { Opt_local_lock, "local_lock=%s" },
5918  
5919 +       { Opt_tag, "tag" },
5920 +       { Opt_notag, "notag" },
5921 +       { Opt_tagid, "tagid=%u" },
5922 +
5923         { Opt_err, NULL }
5924  };
5925  
5926 @@ -650,6 +657,7 @@ static void nfs_show_mount_options(struc
5927                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5928                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5929                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5930 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5931                 { 0, NULL, NULL }
5932         };
5933         const struct proc_nfs_info *nfs_infop;
5934 @@ -1198,6 +1206,14 @@ static int nfs_parse_mount_options(char 
5935                         kfree(mnt->fscache_uniq);
5936                         mnt->fscache_uniq = NULL;
5937                         break;
5938 +#ifndef CONFIG_TAGGING_NONE
5939 +               case Opt_tag:
5940 +                       mnt->flags |= NFS_MOUNT_TAGGED;
5941 +                       break;
5942 +               case Opt_notag:
5943 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
5944 +                       break;
5945 +#endif
5946  
5947                 /*
5948                  * options that take numeric values
5949 @@ -1304,6 +1320,12 @@ static int nfs_parse_mount_options(char 
5950                                 goto out_invalid_value;
5951                         mnt->minorversion = option;
5952                         break;
5953 +#ifdef CONFIG_PROPAGATE
5954 +               case Opt_tagid:
5955 +                       /* use args[0] */
5956 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
5957 +                       break;
5958 +#endif
5959  
5960                 /*
5961                  * options that take text values
5962 diff -NurpP --minimal linux-3.0-rc5/fs/nfsd/auth.c linux-3.0-rc5-vs2.3.1-pre3/fs/nfsd/auth.c
5963 --- linux-3.0-rc5/fs/nfsd/auth.c        2010-02-25 11:52:05.000000000 +0100
5964 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/nfsd/auth.c   2011-06-10 22:11:24.000000000 +0200
5965 @@ -1,6 +1,7 @@
5966  /* Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> */
5967  
5968  #include <linux/sched.h>
5969 +#include <linux/vs_tag.h>
5970  #include "nfsd.h"
5971  #include "auth.h"
5972  
5973 @@ -36,6 +37,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5974  
5975         new->fsuid = rqstp->rq_cred.cr_uid;
5976         new->fsgid = rqstp->rq_cred.cr_gid;
5977 +       /* FIXME: this desperately needs a tag :)
5978 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5979 +                       */
5980  
5981         rqgi = rqstp->rq_cred.cr_group_info;
5982  
5983 diff -NurpP --minimal linux-3.0-rc5/fs/nfsd/nfs3xdr.c linux-3.0-rc5-vs2.3.1-pre3/fs/nfsd/nfs3xdr.c
5984 --- linux-3.0-rc5/fs/nfsd/nfs3xdr.c     2011-07-01 11:14:19.000000000 +0200
5985 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/nfsd/nfs3xdr.c        2011-06-10 22:11:24.000000000 +0200
5986 @@ -7,6 +7,7 @@
5987   */
5988  
5989  #include <linux/namei.h>
5990 +#include <linux/vs_tag.h>
5991  #include "xdr3.h"
5992  #include "auth.h"
5993  
5994 @@ -95,6 +96,8 @@ static __be32 *
5995  decode_sattr3(__be32 *p, struct iattr *iap)
5996  {
5997         u32     tmp;
5998 +       uid_t   uid = 0;
5999 +       gid_t   gid = 0;
6000  
6001         iap->ia_valid = 0;
6002  
6003 @@ -104,12 +107,15 @@ decode_sattr3(__be32 *p, struct iattr *i
6004         }
6005         if (*p++) {
6006                 iap->ia_valid |= ATTR_UID;
6007 -               iap->ia_uid = ntohl(*p++);
6008 +               uid = ntohl(*p++);
6009         }
6010         if (*p++) {
6011                 iap->ia_valid |= ATTR_GID;
6012 -               iap->ia_gid = ntohl(*p++);
6013 +               gid = ntohl(*p++);
6014         }
6015 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6016 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6017 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6018         if (*p++) {
6019                 u64     newsize;
6020  
6021 @@ -165,8 +171,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
6022         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
6023         *p++ = htonl((u32) stat->mode);
6024         *p++ = htonl((u32) stat->nlink);
6025 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6026 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6027 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6028 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6029 +               stat->uid, stat->tag)));
6030 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6031 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6032 +               stat->gid, stat->tag)));
6033         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
6034                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
6035         } else {
6036 diff -NurpP --minimal linux-3.0-rc5/fs/nfsd/nfs4xdr.c linux-3.0-rc5-vs2.3.1-pre3/fs/nfsd/nfs4xdr.c
6037 --- linux-3.0-rc5/fs/nfsd/nfs4xdr.c     2011-07-01 11:14:19.000000000 +0200
6038 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/nfsd/nfs4xdr.c        2011-06-10 22:11:24.000000000 +0200
6039 @@ -45,6 +45,7 @@
6040  #include <linux/statfs.h>
6041  #include <linux/utsname.h>
6042  #include <linux/sunrpc/svcauth_gss.h>
6043 +#include <linux/vs_tag.h>
6044  
6045  #include "idmap.h"
6046  #include "acl.h"
6047 @@ -2090,14 +2091,18 @@ out_acl:
6048                 WRITE32(stat.nlink);
6049         }
6050         if (bmval1 & FATTR4_WORD1_OWNER) {
6051 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
6052 +               status = nfsd4_encode_user(rqstp,
6053 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
6054 +                       stat.uid, stat.tag), &p, &buflen);
6055                 if (status == nfserr_resource)
6056                         goto out_resource;
6057                 if (status)
6058                         goto out;
6059         }
6060         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
6061 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
6062 +               status = nfsd4_encode_group(rqstp,
6063 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
6064 +                       stat.gid, stat.tag), &p, &buflen);
6065                 if (status == nfserr_resource)
6066                         goto out_resource;
6067                 if (status)
6068 diff -NurpP --minimal linux-3.0-rc5/fs/nfsd/nfsxdr.c linux-3.0-rc5-vs2.3.1-pre3/fs/nfsd/nfsxdr.c
6069 --- linux-3.0-rc5/fs/nfsd/nfsxdr.c      2011-05-22 16:17:53.000000000 +0200
6070 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/nfsd/nfsxdr.c 2011-06-10 22:11:24.000000000 +0200
6071 @@ -6,6 +6,7 @@
6072  
6073  #include "xdr.h"
6074  #include "auth.h"
6075 +#include <linux/vs_tag.h>
6076  
6077  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6078  
6079 @@ -88,6 +89,8 @@ static __be32 *
6080  decode_sattr(__be32 *p, struct iattr *iap)
6081  {
6082         u32     tmp, tmp1;
6083 +       uid_t   uid = 0;
6084 +       gid_t   gid = 0;
6085  
6086         iap->ia_valid = 0;
6087  
6088 @@ -101,12 +104,15 @@ decode_sattr(__be32 *p, struct iattr *ia
6089         }
6090         if ((tmp = ntohl(*p++)) != (u32)-1) {
6091                 iap->ia_valid |= ATTR_UID;
6092 -               iap->ia_uid = tmp;
6093 +               uid = tmp;
6094         }
6095         if ((tmp = ntohl(*p++)) != (u32)-1) {
6096                 iap->ia_valid |= ATTR_GID;
6097 -               iap->ia_gid = tmp;
6098 +               gid = tmp;
6099         }
6100 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6101 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6102 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6103         if ((tmp = ntohl(*p++)) != (u32)-1) {
6104                 iap->ia_valid |= ATTR_SIZE;
6105                 iap->ia_size = tmp;
6106 @@ -151,8 +157,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
6107         *p++ = htonl(nfs_ftypes[type >> 12]);
6108         *p++ = htonl((u32) stat->mode);
6109         *p++ = htonl((u32) stat->nlink);
6110 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6111 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6112 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6113 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
6114 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6115 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
6116  
6117         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
6118                 *p++ = htonl(NFS_MAXPATHLEN);
6119 diff -NurpP --minimal linux-3.0-rc5/fs/ocfs2/dlmglue.c linux-3.0-rc5-vs2.3.1-pre3/fs/ocfs2/dlmglue.c
6120 --- linux-3.0-rc5/fs/ocfs2/dlmglue.c    2011-05-22 16:17:53.000000000 +0200
6121 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/ocfs2/dlmglue.c       2011-06-10 22:11:24.000000000 +0200
6122 @@ -2041,6 +2041,7 @@ static void __ocfs2_stuff_meta_lvb(struc
6123         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
6124         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
6125         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
6126 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
6127         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
6128         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
6129         lvb->lvb_iatime_packed  =
6130 @@ -2091,6 +2092,7 @@ static void ocfs2_refresh_inode_from_lvb
6131  
6132         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
6133         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
6134 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
6135         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
6136         inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
6137         ocfs2_unpack_timespec(&inode->i_atime,
6138 diff -NurpP --minimal linux-3.0-rc5/fs/ocfs2/dlmglue.h linux-3.0-rc5-vs2.3.1-pre3/fs/ocfs2/dlmglue.h
6139 --- linux-3.0-rc5/fs/ocfs2/dlmglue.h    2010-10-21 13:07:50.000000000 +0200
6140 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/ocfs2/dlmglue.h       2011-06-10 22:11:24.000000000 +0200
6141 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
6142         __be16       lvb_inlink;
6143         __be32       lvb_iattr;
6144         __be32       lvb_igeneration;
6145 -       __be32       lvb_reserved2;
6146 +       __be16       lvb_itag;
6147 +       __be16       lvb_reserved2;
6148  };
6149  
6150  #define OCFS2_QINFO_LVB_VERSION 1
6151 diff -NurpP --minimal linux-3.0-rc5/fs/ocfs2/file.c linux-3.0-rc5-vs2.3.1-pre3/fs/ocfs2/file.c
6152 --- linux-3.0-rc5/fs/ocfs2/file.c       2011-07-01 11:14:20.000000000 +0200
6153 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/ocfs2/file.c  2011-06-10 22:43:33.000000000 +0200
6154 @@ -1111,7 +1111,7 @@ int ocfs2_setattr(struct dentry *dentry,
6155                 attr->ia_valid &= ~ATTR_SIZE;
6156  
6157  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
6158 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
6159 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
6160         if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
6161                 return 0;
6162  
6163 diff -NurpP --minimal linux-3.0-rc5/fs/ocfs2/inode.c linux-3.0-rc5-vs2.3.1-pre3/fs/ocfs2/inode.c
6164 --- linux-3.0-rc5/fs/ocfs2/inode.c      2011-05-22 16:17:53.000000000 +0200
6165 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/ocfs2/inode.c 2011-06-10 22:11:24.000000000 +0200
6166 @@ -28,6 +28,7 @@
6167  #include <linux/highmem.h>
6168  #include <linux/pagemap.h>
6169  #include <linux/quotaops.h>
6170 +#include <linux/vs_tag.h>
6171  
6172  #include <asm/byteorder.h>
6173  
6174 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode 
6175  {
6176         unsigned int flags = OCFS2_I(inode)->ip_attr;
6177  
6178 -       inode->i_flags &= ~(S_IMMUTABLE |
6179 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
6180                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
6181  
6182         if (flags & OCFS2_IMMUTABLE_FL)
6183                 inode->i_flags |= S_IMMUTABLE;
6184 +       if (flags & OCFS2_IXUNLINK_FL)
6185 +               inode->i_flags |= S_IXUNLINK;
6186  
6187         if (flags & OCFS2_SYNC_FL)
6188                 inode->i_flags |= S_SYNC;
6189 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode 
6190                 inode->i_flags |= S_NOATIME;
6191         if (flags & OCFS2_DIRSYNC_FL)
6192                 inode->i_flags |= S_DIRSYNC;
6193 +
6194 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
6195 +
6196 +       if (flags & OCFS2_BARRIER_FL)
6197 +               inode->i_vflags |= V_BARRIER;
6198 +       if (flags & OCFS2_COW_FL)
6199 +               inode->i_vflags |= V_COW;
6200  }
6201  
6202  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
6203  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
6204  {
6205         unsigned int flags = oi->vfs_inode.i_flags;
6206 +       unsigned int vflags = oi->vfs_inode.i_vflags;
6207 +
6208 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
6209 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
6210 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
6211 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
6212 +
6213 +       if (flags & S_IMMUTABLE)
6214 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6215 +       if (flags & S_IXUNLINK)
6216 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
6217  
6218 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
6219 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
6220         if (flags & S_SYNC)
6221                 oi->ip_attr |= OCFS2_SYNC_FL;
6222         if (flags & S_APPEND)
6223                 oi->ip_attr |= OCFS2_APPEND_FL;
6224 -       if (flags & S_IMMUTABLE)
6225 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6226         if (flags & S_NOATIME)
6227                 oi->ip_attr |= OCFS2_NOATIME_FL;
6228         if (flags & S_DIRSYNC)
6229                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
6230 +
6231 +       if (vflags & V_BARRIER)
6232 +               oi->ip_attr |= OCFS2_BARRIER_FL;
6233 +       if (vflags & V_COW)
6234 +               oi->ip_attr |= OCFS2_COW_FL;
6235  }
6236  
6237  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
6238 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
6239         struct super_block *sb;
6240         struct ocfs2_super *osb;
6241         int use_plocks = 1;
6242 +       uid_t uid;
6243 +       gid_t gid;
6244  
6245         sb = inode->i_sb;
6246         osb = OCFS2_SB(sb);
6247 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
6248         inode->i_generation = le32_to_cpu(fe->i_generation);
6249         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
6250         inode->i_mode = le16_to_cpu(fe->i_mode);
6251 -       inode->i_uid = le32_to_cpu(fe->i_uid);
6252 -       inode->i_gid = le32_to_cpu(fe->i_gid);
6253 +       uid = le32_to_cpu(fe->i_uid);
6254 +       gid = le32_to_cpu(fe->i_gid);
6255 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6256 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6257 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
6258 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
6259  
6260         /* Fast symlinks will have i_size but no allocated clusters. */
6261         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
6262 diff -NurpP --minimal linux-3.0-rc5/fs/ocfs2/inode.h linux-3.0-rc5-vs2.3.1-pre3/fs/ocfs2/inode.h
6263 --- linux-3.0-rc5/fs/ocfs2/inode.h      2011-01-05 21:50:26.000000000 +0100
6264 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/ocfs2/inode.h 2011-06-10 22:11:24.000000000 +0200
6265 @@ -151,6 +151,7 @@ struct buffer_head *ocfs2_bread(struct i
6266  
6267  void ocfs2_set_inode_flags(struct inode *inode);
6268  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
6269 +int ocfs2_sync_flags(struct inode *inode, int, int);
6270  
6271  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
6272  {
6273 diff -NurpP --minimal linux-3.0-rc5/fs/ocfs2/ioctl.c linux-3.0-rc5-vs2.3.1-pre3/fs/ocfs2/ioctl.c
6274 --- linux-3.0-rc5/fs/ocfs2/ioctl.c      2011-07-01 11:14:20.000000000 +0200
6275 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/ocfs2/ioctl.c 2011-06-10 22:11:24.000000000 +0200
6276 @@ -78,7 +78,41 @@ static int ocfs2_get_inode_attr(struct i
6277         return status;
6278  }
6279  
6280 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6281 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
6282 +{
6283 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
6284 +       struct buffer_head *bh = NULL;
6285 +       handle_t *handle = NULL;
6286 +       int status;
6287 +
6288 +       status = ocfs2_inode_lock(inode, &bh, 1);
6289 +       if (status < 0) {
6290 +               mlog_errno(status);
6291 +               return status;
6292 +       }
6293 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6294 +       if (IS_ERR(handle)) {
6295 +               status = PTR_ERR(handle);
6296 +               mlog_errno(status);
6297 +               goto bail_unlock;
6298 +       }
6299 +
6300 +       inode->i_flags = flags;
6301 +       inode->i_vflags = vflags;
6302 +       ocfs2_get_inode_flags(OCFS2_I(inode));
6303 +
6304 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
6305 +       if (status < 0)
6306 +               mlog_errno(status);
6307 +
6308 +       ocfs2_commit_trans(osb, handle);
6309 +bail_unlock:
6310 +       ocfs2_inode_unlock(inode, 1);
6311 +       brelse(bh);
6312 +       return status;
6313 +}
6314 +
6315 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6316                                 unsigned mask)
6317  {
6318         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
6319 @@ -103,6 +137,11 @@ static int ocfs2_set_inode_attr(struct i
6320         if (!S_ISDIR(inode->i_mode))
6321                 flags &= ~OCFS2_DIRSYNC_FL;
6322  
6323 +       if (IS_BARRIER(inode)) {
6324 +               vxwprintk_task(1, "messing with the barrier.");
6325 +               goto bail_unlock;
6326 +       }
6327 +
6328         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6329         if (IS_ERR(handle)) {
6330                 status = PTR_ERR(handle);
6331 @@ -880,6 +919,7 @@ bail:
6332         return status;
6333  }
6334  
6335 +
6336  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
6337  {
6338         struct inode *inode = filp->f_path.dentry->d_inode;
6339 diff -NurpP --minimal linux-3.0-rc5/fs/ocfs2/namei.c linux-3.0-rc5-vs2.3.1-pre3/fs/ocfs2/namei.c
6340 --- linux-3.0-rc5/fs/ocfs2/namei.c      2011-05-22 16:17:53.000000000 +0200
6341 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/ocfs2/namei.c 2011-06-10 22:11:24.000000000 +0200
6342 @@ -41,6 +41,7 @@
6343  #include <linux/slab.h>
6344  #include <linux/highmem.h>
6345  #include <linux/quotaops.h>
6346 +#include <linux/vs_tag.h>
6347  
6348  #include <cluster/masklog.h>
6349  
6350 @@ -477,6 +478,7 @@ static int __ocfs2_mknod_locked(struct i
6351         struct ocfs2_dinode *fe = NULL;
6352         struct ocfs2_extent_list *fel;
6353         u16 feat;
6354 +       tag_t tag;
6355  
6356         *new_fe_bh = NULL;
6357  
6358 @@ -514,8 +516,11 @@ static int __ocfs2_mknod_locked(struct i
6359         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
6360         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
6361         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
6362 -       fe->i_uid = cpu_to_le32(inode->i_uid);
6363 -       fe->i_gid = cpu_to_le32(inode->i_gid);
6364 +
6365 +       tag = dx_current_fstag(osb->sb);
6366 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
6367 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
6368 +       inode->i_tag = tag;
6369         fe->i_mode = cpu_to_le16(inode->i_mode);
6370         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
6371                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
6372 diff -NurpP --minimal linux-3.0-rc5/fs/ocfs2/ocfs2.h linux-3.0-rc5-vs2.3.1-pre3/fs/ocfs2/ocfs2.h
6373 --- linux-3.0-rc5/fs/ocfs2/ocfs2.h      2011-05-22 16:17:53.000000000 +0200
6374 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/ocfs2/ocfs2.h 2011-06-10 22:11:24.000000000 +0200
6375 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
6376                                                      writes */
6377         OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
6378         OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
6379 +       OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
6380  };
6381  
6382  #define OCFS2_OSB_SOFT_RO                      0x0001
6383 diff -NurpP --minimal linux-3.0-rc5/fs/ocfs2/ocfs2_fs.h linux-3.0-rc5-vs2.3.1-pre3/fs/ocfs2/ocfs2_fs.h
6384 --- linux-3.0-rc5/fs/ocfs2/ocfs2_fs.h   2011-05-22 16:17:53.000000000 +0200
6385 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/ocfs2/ocfs2_fs.h      2011-06-10 22:11:24.000000000 +0200
6386 @@ -266,6 +266,11 @@
6387  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
6388  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
6389  
6390 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
6391 +
6392 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
6393 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
6394 +
6395  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
6396  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
6397  
6398 diff -NurpP --minimal linux-3.0-rc5/fs/ocfs2/super.c linux-3.0-rc5-vs2.3.1-pre3/fs/ocfs2/super.c
6399 --- linux-3.0-rc5/fs/ocfs2/super.c      2011-07-01 11:14:20.000000000 +0200
6400 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/ocfs2/super.c 2011-06-15 02:40:14.000000000 +0200
6401 @@ -184,6 +184,7 @@ enum {
6402         Opt_coherency_full,
6403         Opt_resv_level,
6404         Opt_dir_resv_level,
6405 +       Opt_tag, Opt_notag, Opt_tagid,
6406         Opt_err,
6407  };
6408  
6409 @@ -215,6 +216,9 @@ static const match_table_t tokens = {
6410         {Opt_coherency_full, "coherency=full"},
6411         {Opt_resv_level, "resv_level=%u"},
6412         {Opt_dir_resv_level, "dir_resv_level=%u"},
6413 +       {Opt_tag, "tag"},
6414 +       {Opt_notag, "notag"},
6415 +       {Opt_tagid, "tagid=%u"},
6416         {Opt_err, NULL}
6417  };
6418  
6419 @@ -662,6 +666,13 @@ static int ocfs2_remount(struct super_bl
6420                 goto out;
6421         }
6422  
6423 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
6424 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
6425 +               ret = -EINVAL;
6426 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
6427 +               goto out;
6428 +       }
6429 +
6430         /* We're going to/from readonly mode. */
6431         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
6432                 /* Disable quota accounting before remounting RO */
6433 @@ -1177,6 +1188,9 @@ static int ocfs2_fill_super(struct super
6434  
6435         ocfs2_complete_mount_recovery(osb);
6436  
6437 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
6438 +               sb->s_flags |= MS_TAGGED;
6439 +
6440         if (ocfs2_mount_local(osb))
6441                 snprintf(nodestr, sizeof(nodestr), "local");
6442         else
6443 @@ -1506,6 +1520,20 @@ static int ocfs2_parse_options(struct su
6444                             option < OCFS2_MAX_RESV_LEVEL)
6445                                 mopt->dir_resv_level = option;
6446                         break;
6447 +#ifndef CONFIG_TAGGING_NONE
6448 +               case Opt_tag:
6449 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6450 +                       break;
6451 +               case Opt_notag:
6452 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
6453 +                       break;
6454 +#endif
6455 +#ifdef CONFIG_PROPAGATE
6456 +               case Opt_tagid:
6457 +                       /* use args[0] */
6458 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6459 +                       break;
6460 +#endif
6461                 default:
6462                         mlog(ML_ERROR,
6463                              "Unrecognized mount option \"%s\" "
6464 diff -NurpP --minimal linux-3.0-rc5/fs/open.c linux-3.0-rc5-vs2.3.1-pre3/fs/open.c
6465 --- linux-3.0-rc5/fs/open.c     2011-05-22 16:17:53.000000000 +0200
6466 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/open.c        2011-06-10 22:11:24.000000000 +0200
6467 @@ -30,6 +30,11 @@
6468  #include <linux/fs_struct.h>
6469  #include <linux/ima.h>
6470  #include <linux/dnotify.h>
6471 +#include <linux/vs_base.h>
6472 +#include <linux/vs_limit.h>
6473 +#include <linux/vs_tag.h>
6474 +#include <linux/vs_cowbl.h>
6475 +#include <linux/vserver/dlimit.h>
6476  
6477  #include "internal.h"
6478  
6479 @@ -494,6 +499,12 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6480         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
6481         if (error)
6482                 goto out;
6483 +
6484 +#ifdef CONFIG_VSERVER_COWBL
6485 +       error = cow_check_and_break(&path);
6486 +       if (error)
6487 +               goto dput_and_out;
6488 +#endif
6489         inode = path.dentry->d_inode;
6490  
6491         error = mnt_want_write(path.mnt);
6492 @@ -531,11 +542,11 @@ static int chown_common(struct path *pat
6493         newattrs.ia_valid =  ATTR_CTIME;
6494         if (user != (uid_t) -1) {
6495                 newattrs.ia_valid |= ATTR_UID;
6496 -               newattrs.ia_uid = user;
6497 +               newattrs.ia_uid = dx_map_uid(user);
6498         }
6499         if (group != (gid_t) -1) {
6500                 newattrs.ia_valid |= ATTR_GID;
6501 -               newattrs.ia_gid = group;
6502 +               newattrs.ia_gid = dx_map_gid(group);
6503         }
6504         if (!S_ISDIR(inode->i_mode))
6505                 newattrs.ia_valid |=
6506 @@ -560,6 +571,10 @@ SYSCALL_DEFINE3(chown, const char __user
6507         error = mnt_want_write(path.mnt);
6508         if (error)
6509                 goto out_release;
6510 +#ifdef CONFIG_VSERVER_COWBL
6511 +       error = cow_check_and_break(&path);
6512 +       if (!error)
6513 +#endif
6514         error = chown_common(&path, user, group);
6515         mnt_drop_write(path.mnt);
6516  out_release:
6517 @@ -587,6 +602,10 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
6518         error = mnt_want_write(path.mnt);
6519         if (error)
6520                 goto out_release;
6521 +#ifdef CONFIG_VSERVER_COWBL
6522 +       error = cow_check_and_break(&path);
6523 +       if (!error)
6524 +#endif
6525         error = chown_common(&path, user, group);
6526         mnt_drop_write(path.mnt);
6527  out_release:
6528 @@ -606,6 +625,10 @@ SYSCALL_DEFINE3(lchown, const char __use
6529         error = mnt_want_write(path.mnt);
6530         if (error)
6531                 goto out_release;
6532 +#ifdef CONFIG_VSERVER_COWBL
6533 +       error = cow_check_and_break(&path);
6534 +       if (!error)
6535 +#endif
6536         error = chown_common(&path, user, group);
6537         mnt_drop_write(path.mnt);
6538  out_release:
6539 @@ -857,6 +880,7 @@ static void __put_unused_fd(struct files
6540         __FD_CLR(fd, fdt->open_fds);
6541         if (fd < files->next_fd)
6542                 files->next_fd = fd;
6543 +       vx_openfd_dec(fd);
6544  }
6545  
6546  void put_unused_fd(unsigned int fd)
6547 diff -NurpP --minimal linux-3.0-rc5/fs/proc/array.c linux-3.0-rc5-vs2.3.1-pre3/fs/proc/array.c
6548 --- linux-3.0-rc5/fs/proc/array.c       2011-07-01 11:14:20.000000000 +0200
6549 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/proc/array.c  2011-06-10 22:11:24.000000000 +0200
6550 @@ -81,6 +81,8 @@
6551  #include <linux/pid_namespace.h>
6552  #include <linux/ptrace.h>
6553  #include <linux/tracehook.h>
6554 +#include <linux/vs_context.h>
6555 +#include <linux/vs_network.h>
6556  
6557  #include <asm/pgtable.h>
6558  #include <asm/processor.h>
6559 @@ -170,6 +172,9 @@ static inline void task_state(struct seq
6560         rcu_read_lock();
6561         ppid = pid_alive(p) ?
6562                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6563 +       if (unlikely(vx_current_initpid(p->pid)))
6564 +               ppid = 0;
6565 +
6566         tpid = 0;
6567         if (pid_alive(p)) {
6568                 struct task_struct *tracer = tracehook_tracer_task(p);
6569 @@ -287,7 +292,7 @@ static inline void task_sig(struct seq_f
6570  }
6571  
6572  static void render_cap_t(struct seq_file *m, const char *header,
6573 -                       kernel_cap_t *a)
6574 +                       struct vx_info *vxi, kernel_cap_t *a)
6575  {
6576         unsigned __capi;
6577  
6578 @@ -312,10 +317,11 @@ static inline void task_cap(struct seq_f
6579         cap_bset        = cred->cap_bset;
6580         rcu_read_unlock();
6581  
6582 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6583 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6584 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6585 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6586 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6587 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6588 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6589 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6590 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6591  }
6592  
6593  static inline void task_context_switch_counts(struct seq_file *m,
6594 @@ -337,6 +343,42 @@ static void task_cpus_allowed(struct seq
6595         seq_putc(m, '\n');
6596  }
6597  
6598 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6599 +                       struct pid *pid, struct task_struct *task)
6600 +{
6601 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6602 +                       "Count:\t%u\n"
6603 +                       "uts:\t%p(%c)\n"
6604 +                       "ipc:\t%p(%c)\n"
6605 +                       "mnt:\t%p(%c)\n"
6606 +                       "pid:\t%p(%c)\n"
6607 +                       "net:\t%p(%c)\n",
6608 +                       task->nsproxy,
6609 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6610 +                       atomic_read(&task->nsproxy->count),
6611 +                       task->nsproxy->uts_ns,
6612 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6613 +                       task->nsproxy->ipc_ns,
6614 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6615 +                       task->nsproxy->mnt_ns,
6616 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6617 +                       task->nsproxy->pid_ns,
6618 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6619 +                       task->nsproxy->net_ns,
6620 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6621 +       return 0;
6622 +}
6623 +
6624 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6625 +{
6626 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6627 +               return;
6628 +
6629 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6630 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6631 +}
6632 +
6633 +
6634  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6635                         struct pid *pid, struct task_struct *task)
6636  {
6637 @@ -353,6 +395,7 @@ int proc_pid_status(struct seq_file *m, 
6638         task_cap(m, task);
6639         task_cpus_allowed(m, task);
6640         cpuset_task_status_allowed(m, task);
6641 +       task_vs_id(m, task);
6642         task_context_switch_counts(m, task);
6643         return 0;
6644  }
6645 @@ -462,6 +505,17 @@ static int do_task_stat(struct seq_file 
6646         /* convert nsec -> ticks */
6647         start_time = nsec_to_clock_t(start_time);
6648  
6649 +       /* fixup start time for virt uptime */
6650 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6651 +               unsigned long long bias =
6652 +                       current->vx_info->cvirt.bias_clock;
6653 +
6654 +               if (start_time > bias)
6655 +                       start_time -= bias;
6656 +               else
6657 +                       start_time = 0;
6658 +       }
6659 +
6660         seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \
6661  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
6662  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
6663 diff -NurpP --minimal linux-3.0-rc5/fs/proc/base.c linux-3.0-rc5-vs2.3.1-pre3/fs/proc/base.c
6664 --- linux-3.0-rc5/fs/proc/base.c        2011-07-01 11:14:20.000000000 +0200
6665 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/proc/base.c   2011-06-22 12:39:15.000000000 +0200
6666 @@ -83,6 +83,8 @@
6667  #include <linux/pid_namespace.h>
6668  #include <linux/fs_struct.h>
6669  #include <linux/slab.h>
6670 +#include <linux/vs_context.h>
6671 +#include <linux/vs_network.h>
6672  #ifdef CONFIG_HARDWALL
6673  #include <asm/hardwall.h>
6674  #endif
6675 @@ -1102,11 +1104,16 @@ static ssize_t oom_adjust_write(struct f
6676                 goto err_task_lock;
6677         }
6678  
6679 -       if (oom_adjust < task->signal->oom_adj && !capable(CAP_SYS_RESOURCE)) {
6680 +       if (oom_adjust < task->signal->oom_adj &&
6681 +               !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6682                 err = -EACCES;
6683                 goto err_sighand;
6684         }
6685  
6686 +       /* prevent guest processes from circumventing the oom killer */
6687 +       if (vx_current_xid() && (oom_adjust == OOM_DISABLE))
6688 +               oom_adjust = OOM_ADJUST_MIN;
6689 +
6690         if (oom_adjust != task->signal->oom_adj) {
6691                 if (oom_adjust == OOM_DISABLE)
6692                         atomic_inc(&task->mm->oom_disable_count);
6693 @@ -1275,7 +1282,7 @@ static ssize_t proc_loginuid_write(struc
6694         ssize_t length;
6695         uid_t loginuid;
6696  
6697 -       if (!capable(CAP_AUDIT_CONTROL))
6698 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
6699                 return -EPERM;
6700  
6701         rcu_read_lock();
6702 @@ -1722,6 +1729,8 @@ struct inode *proc_pid_make_inode(struct
6703                 inode->i_gid = cred->egid;
6704                 rcu_read_unlock();
6705         }
6706 +       /* procfs is xid tagged */
6707 +       inode->i_tag = (tag_t)vx_task_xid(task);
6708         security_task_to_inode(task, inode);
6709  
6710  out:
6711 @@ -1758,6 +1767,8 @@ int pid_getattr(struct vfsmount *mnt, st
6712  
6713  /* dentry stuff */
6714  
6715 +static unsigned name_to_int(struct dentry *dentry);
6716 +
6717  /*
6718   *     Exceptional case: normally we are not allowed to unhash a busy
6719   * directory. In this case, however, we can do it - no aliasing problems
6720 @@ -1786,6 +1797,12 @@ int pid_revalidate(struct dentry *dentry
6721         task = get_proc_task(inode);
6722  
6723         if (task) {
6724 +               unsigned pid = name_to_int(dentry);
6725 +
6726 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6727 +                       put_task_struct(task);
6728 +                       goto drop;
6729 +               }
6730                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6731                     task_dumpable(task)) {
6732                         rcu_read_lock();
6733 @@ -1802,6 +1819,7 @@ int pid_revalidate(struct dentry *dentry
6734                 put_task_struct(task);
6735                 return 1;
6736         }
6737 +drop:
6738         d_drop(dentry);
6739         return 0;
6740  }
6741 @@ -2283,6 +2301,13 @@ static struct dentry *proc_pident_lookup
6742         if (!task)
6743                 goto out_no_task;
6744  
6745 +       /* TODO: maybe we can come up with a generic approach? */
6746 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6747 +               (dentry->d_name.len == 5) &&
6748 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6749 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6750 +               goto out;
6751 +
6752         /*
6753          * Yes, it does not scale. And it should not. Don't add
6754          * new entries into /proc/<tgid>/ without very good reasons.
6755 @@ -2668,7 +2693,7 @@ out_iput:
6756  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
6757  {
6758         struct dentry *error;
6759 -       struct task_struct *task = get_proc_task(dir);
6760 +       struct task_struct *task = get_proc_task_real(dir);
6761         const struct pid_entry *p, *last;
6762  
6763         error = ERR_PTR(-ENOENT);
6764 @@ -2762,6 +2787,9 @@ static int proc_pid_personality(struct s
6765  static const struct file_operations proc_task_operations;
6766  static const struct inode_operations proc_task_inode_operations;
6767  
6768 +extern int proc_pid_vx_info(struct task_struct *, char *);
6769 +extern int proc_pid_nx_info(struct task_struct *, char *);
6770 +
6771  static const struct pid_entry tgid_base_stuff[] = {
6772         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6773         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6774 @@ -2825,6 +2853,8 @@ static const struct pid_entry tgid_base_
6775  #ifdef CONFIG_CGROUPS
6776         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6777  #endif
6778 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6779 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6780         INF("oom_score",  S_IRUGO, proc_oom_score),
6781         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
6782         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6783 @@ -2844,6 +2874,7 @@ static const struct pid_entry tgid_base_
6784  #ifdef CONFIG_HARDWALL
6785         INF("hardwall",   S_IRUGO, proc_pid_hardwall),
6786  #endif
6787 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6788  };
6789  
6790  static int proc_tgid_base_readdir(struct file * filp,
6791 @@ -3036,7 +3067,7 @@ retry:
6792         iter.task = NULL;
6793         pid = find_ge_pid(iter.tgid, ns);
6794         if (pid) {
6795 -               iter.tgid = pid_nr_ns(pid, ns);
6796 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6797                 iter.task = pid_task(pid, PIDTYPE_PID);
6798                 /* What we to know is if the pid we have find is the
6799                  * pid of a thread_group_leader.  Testing for task
6800 @@ -3066,7 +3097,7 @@ static int proc_pid_fill_cache(struct fi
6801         struct tgid_iter iter)
6802  {
6803         char name[PROC_NUMBUF];
6804 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6805 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6806         return proc_fill_cache(filp, dirent, filldir, name, len,
6807                                 proc_pid_instantiate, iter.task, NULL);
6808  }
6809 @@ -3083,7 +3114,7 @@ int proc_pid_readdir(struct file * filp,
6810                 goto out_no_task;
6811         nr = filp->f_pos - FIRST_PROCESS_ENTRY;
6812  
6813 -       reaper = get_proc_task(filp->f_path.dentry->d_inode);
6814 +       reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
6815         if (!reaper)
6816                 goto out_no_task;
6817  
6818 @@ -3100,6 +3131,8 @@ int proc_pid_readdir(struct file * filp,
6819              iter.task;
6820              iter.tgid += 1, iter = next_tgid(ns, iter)) {
6821                 filp->f_pos = iter.tgid + TGID_OFFSET;
6822 +               if (!vx_proc_task_visible(iter.task))
6823 +                       continue;
6824                 if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
6825                         put_task_struct(iter.task);
6826                         goto out;
6827 @@ -3253,6 +3286,8 @@ static struct dentry *proc_task_lookup(s
6828         tid = name_to_int(dentry);
6829         if (tid == ~0U)
6830                 goto out;
6831 +       if (vx_current_initpid(tid))
6832 +               goto out;
6833  
6834         ns = dentry->d_sb->s_fs_info;
6835         rcu_read_lock();
6836 diff -NurpP --minimal linux-3.0-rc5/fs/proc/generic.c linux-3.0-rc5-vs2.3.1-pre3/fs/proc/generic.c
6837 --- linux-3.0-rc5/fs/proc/generic.c     2011-07-01 11:14:20.000000000 +0200
6838 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/proc/generic.c        2011-06-10 22:11:24.000000000 +0200
6839 @@ -22,6 +22,7 @@
6840  #include <linux/bitops.h>
6841  #include <linux/spinlock.h>
6842  #include <linux/completion.h>
6843 +#include <linux/vserver/inode.h>
6844  #include <asm/uaccess.h>
6845  
6846  #include "internal.h"
6847 @@ -424,11 +425,15 @@ struct dentry *proc_lookup_de(struct pro
6848         for (de = de->subdir; de ; de = de->next) {
6849                 if (de->namelen != dentry->d_name.len)
6850                         continue;
6851 +               if (!vx_hide_check(0, de->vx_flags))
6852 +                       continue;
6853                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6854                         pde_get(de);
6855                         spin_unlock(&proc_subdir_lock);
6856                         error = -EINVAL;
6857                         inode = proc_get_inode(dir->i_sb, de);
6858 +                       /* generic proc entries belong to the host */
6859 +                       inode->i_tag = 0;
6860                         goto out_unlock;
6861                 }
6862         }
6863 @@ -506,6 +511,8 @@ int proc_readdir_de(struct proc_dir_entr
6864  
6865                                 /* filldir passes info to user space */
6866                                 pde_get(de);
6867 +                               if (!vx_hide_check(0, de->vx_flags))
6868 +                                       goto skip;
6869                                 spin_unlock(&proc_subdir_lock);
6870                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6871                                             de->low_ino, de->mode >> 12) < 0) {
6872 @@ -513,6 +520,7 @@ int proc_readdir_de(struct proc_dir_entr
6873                                         goto out;
6874                                 }
6875                                 spin_lock(&proc_subdir_lock);
6876 +                       skip:
6877                                 filp->f_pos++;
6878                                 next = de->next;
6879                                 pde_put(de);
6880 @@ -627,6 +635,7 @@ static struct proc_dir_entry *__proc_cre
6881         ent->nlink = nlink;
6882         atomic_set(&ent->count, 1);
6883         ent->pde_users = 0;
6884 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6885         spin_lock_init(&ent->pde_unload_lock);
6886         ent->pde_unload_completion = NULL;
6887         INIT_LIST_HEAD(&ent->pde_openers);
6888 @@ -650,7 +659,8 @@ struct proc_dir_entry *proc_symlink(cons
6889                                 kfree(ent->data);
6890                                 kfree(ent);
6891                                 ent = NULL;
6892 -                       }
6893 +                       } else
6894 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6895                 } else {
6896                         kfree(ent);
6897                         ent = NULL;
6898 diff -NurpP --minimal linux-3.0-rc5/fs/proc/inode.c linux-3.0-rc5-vs2.3.1-pre3/fs/proc/inode.c
6899 --- linux-3.0-rc5/fs/proc/inode.c       2011-07-01 11:14:20.000000000 +0200
6900 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/proc/inode.c  2011-06-10 22:11:24.000000000 +0200
6901 @@ -442,6 +442,8 @@ struct inode *proc_get_inode(struct supe
6902                         inode->i_uid = de->uid;
6903                         inode->i_gid = de->gid;
6904                 }
6905 +               if (de->vx_flags)
6906 +                       PROC_I(inode)->vx_flags = de->vx_flags;
6907                 if (de->size)
6908                         inode->i_size = de->size;
6909                 if (de->nlink)
6910 diff -NurpP --minimal linux-3.0-rc5/fs/proc/internal.h linux-3.0-rc5-vs2.3.1-pre3/fs/proc/internal.h
6911 --- linux-3.0-rc5/fs/proc/internal.h    2011-07-01 11:14:20.000000000 +0200
6912 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/proc/internal.h       2011-06-10 22:11:24.000000000 +0200
6913 @@ -10,6 +10,7 @@
6914   */
6915  
6916  #include <linux/proc_fs.h>
6917 +#include <linux/vs_pid.h>
6918  
6919  extern struct proc_dir_entry proc_root;
6920  #ifdef CONFIG_PROC_SYSCTL
6921 @@ -51,6 +52,9 @@ extern int proc_pid_status(struct seq_fi
6922                                 struct pid *pid, struct task_struct *task);
6923  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
6924                                 struct pid *pid, struct task_struct *task);
6925 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6926 +                               struct pid *pid, struct task_struct *task);
6927 +
6928  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
6929  
6930  extern const struct file_operations proc_maps_operations;
6931 @@ -76,11 +80,16 @@ static inline struct pid *proc_pid(struc
6932         return PROC_I(inode)->pid;
6933  }
6934  
6935 -static inline struct task_struct *get_proc_task(struct inode *inode)
6936 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6937  {
6938         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6939  }
6940  
6941 +static inline struct task_struct *get_proc_task(struct inode *inode)
6942 +{
6943 +       return vx_get_proc_task(inode, proc_pid(inode));
6944 +}
6945 +
6946  static inline int proc_fd(struct inode *inode)
6947  {
6948         return PROC_I(inode)->fd;
6949 diff -NurpP --minimal linux-3.0-rc5/fs/proc/loadavg.c linux-3.0-rc5-vs2.3.1-pre3/fs/proc/loadavg.c
6950 --- linux-3.0-rc5/fs/proc/loadavg.c     2009-09-10 15:26:23.000000000 +0200
6951 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/proc/loadavg.c        2011-06-10 22:11:24.000000000 +0200
6952 @@ -12,15 +12,27 @@
6953  
6954  static int loadavg_proc_show(struct seq_file *m, void *v)
6955  {
6956 +       unsigned long running;
6957 +       unsigned int threads;
6958         unsigned long avnrun[3];
6959  
6960         get_avenrun(avnrun, FIXED_1/200, 0);
6961  
6962 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
6963 +               struct vx_info *vxi = current_vx_info();
6964 +
6965 +               running = atomic_read(&vxi->cvirt.nr_running);
6966 +               threads = atomic_read(&vxi->cvirt.nr_threads);
6967 +       } else {
6968 +               running = nr_running();
6969 +               threads = nr_threads;
6970 +       }
6971 +
6972         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6973                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6974                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6975                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6976 -               nr_running(), nr_threads,
6977 +               running, threads,
6978                 task_active_pid_ns(current)->last_pid);
6979         return 0;
6980  }
6981 diff -NurpP --minimal linux-3.0-rc5/fs/proc/meminfo.c linux-3.0-rc5-vs2.3.1-pre3/fs/proc/meminfo.c
6982 --- linux-3.0-rc5/fs/proc/meminfo.c     2011-03-15 18:07:33.000000000 +0100
6983 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/proc/meminfo.c        2011-06-10 22:11:24.000000000 +0200
6984 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
6985         allowed = ((totalram_pages - hugetlb_total_pages())
6986                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
6987  
6988 -       cached = global_page_state(NR_FILE_PAGES) -
6989 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
6990 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6991                         total_swapcache_pages - i.bufferram;
6992         if (cached < 0)
6993                 cached = 0;
6994 diff -NurpP --minimal linux-3.0-rc5/fs/proc/root.c linux-3.0-rc5-vs2.3.1-pre3/fs/proc/root.c
6995 --- linux-3.0-rc5/fs/proc/root.c        2011-07-01 11:14:20.000000000 +0200
6996 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/proc/root.c   2011-06-22 12:39:15.000000000 +0200
6997 @@ -18,9 +18,14 @@
6998  #include <linux/bitops.h>
6999  #include <linux/mount.h>
7000  #include <linux/pid_namespace.h>
7001 +#include <linux/vserver/inode.h>
7002  
7003  #include "internal.h"
7004  
7005 +struct proc_dir_entry *proc_virtual;
7006 +
7007 +extern void proc_vx_init(void);
7008 +
7009  static int proc_test_super(struct super_block *sb, void *data)
7010  {
7011         return sb->s_fs_info == data;
7012 @@ -125,6 +130,7 @@ void __init proc_root_init(void)
7013  #endif
7014         proc_mkdir("bus", NULL);
7015         proc_sys_init();
7016 +       proc_vx_init();
7017  }
7018  
7019  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
7020 @@ -193,6 +199,7 @@ struct proc_dir_entry proc_root = {
7021         .proc_iops      = &proc_root_inode_operations, 
7022         .proc_fops      = &proc_root_operations,
7023         .parent         = &proc_root,
7024 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
7025  };
7026  
7027  int pid_ns_prepare_proc(struct pid_namespace *ns)
7028 diff -NurpP --minimal linux-3.0-rc5/fs/proc/uptime.c linux-3.0-rc5-vs2.3.1-pre3/fs/proc/uptime.c
7029 --- linux-3.0-rc5/fs/proc/uptime.c      2009-12-03 20:02:53.000000000 +0100
7030 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/proc/uptime.c 2011-06-10 22:11:24.000000000 +0200
7031 @@ -4,22 +4,22 @@
7032  #include <linux/sched.h>
7033  #include <linux/seq_file.h>
7034  #include <linux/time.h>
7035 -#include <linux/kernel_stat.h>
7036 +#include <linux/vserver/cvirt.h>
7037  #include <asm/cputime.h>
7038  
7039  static int uptime_proc_show(struct seq_file *m, void *v)
7040  {
7041         struct timespec uptime;
7042         struct timespec idle;
7043 -       int i;
7044 -       cputime_t idletime = cputime_zero;
7045 -
7046 -       for_each_possible_cpu(i)
7047 -               idletime = cputime64_add(idletime, kstat_cpu(i).cpustat.idle);
7048 +       cputime_t idletime = cputime_add(init_task.utime, init_task.stime);
7049  
7050         do_posix_clock_monotonic_gettime(&uptime);
7051         monotonic_to_bootbased(&uptime);
7052         cputime_to_timespec(idletime, &idle);
7053 +
7054 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
7055 +               vx_vsi_uptime(&uptime, &idle);
7056 +
7057         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
7058                         (unsigned long) uptime.tv_sec,
7059                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
7060 diff -NurpP --minimal linux-3.0-rc5/fs/quota/dquot.c linux-3.0-rc5-vs2.3.1-pre3/fs/quota/dquot.c
7061 --- linux-3.0-rc5/fs/quota/dquot.c      2011-07-01 11:14:20.000000000 +0200
7062 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/quota/dquot.c 2011-06-10 22:11:24.000000000 +0200
7063 @@ -1548,6 +1548,9 @@ int __dquot_alloc_space(struct inode *in
7064         int reserve = flags & DQUOT_SPACE_RESERVE;
7065         int nofail = flags & DQUOT_SPACE_NOFAIL;
7066  
7067 +       if ((ret = dl_alloc_space(inode, number)))
7068 +               return ret;
7069 +
7070         /*
7071          * First test before acquiring mutex - solves deadlocks when we
7072          * re-enter the quota code and are already holding the mutex
7073 @@ -1602,6 +1605,9 @@ int dquot_alloc_inode(const struct inode
7074         int cnt, ret = 0;
7075         char warntype[MAXQUOTAS];
7076  
7077 +       if ((ret = dl_alloc_inode(inode)))
7078 +               return ret;
7079 +
7080         /* First test before acquiring mutex - solves deadlocks when we
7081           * re-enter the quota code and are already holding the mutex */
7082         if (!dquot_active(inode))
7083 @@ -1672,6 +1678,8 @@ void __dquot_free_space(struct inode *in
7084         char warntype[MAXQUOTAS];
7085         int reserve = flags & DQUOT_SPACE_RESERVE;
7086  
7087 +       dl_free_space(inode, number);
7088 +
7089         /* First test before acquiring mutex - solves deadlocks when we
7090           * re-enter the quota code and are already holding the mutex */
7091         if (!dquot_active(inode)) {
7092 @@ -1710,6 +1718,8 @@ void dquot_free_inode(const struct inode
7093         unsigned int cnt;
7094         char warntype[MAXQUOTAS];
7095  
7096 +       dl_free_inode(inode);
7097 +
7098         /* First test before acquiring mutex - solves deadlocks when we
7099           * re-enter the quota code and are already holding the mutex */
7100         if (!dquot_active(inode))
7101 diff -NurpP --minimal linux-3.0-rc5/fs/quota/quota.c linux-3.0-rc5-vs2.3.1-pre3/fs/quota/quota.c
7102 --- linux-3.0-rc5/fs/quota/quota.c      2011-03-15 18:07:34.000000000 +0100
7103 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/quota/quota.c 2011-06-13 18:19:47.000000000 +0200
7104 @@ -8,6 +8,7 @@
7105  #include <linux/fs.h>
7106  #include <linux/namei.h>
7107  #include <linux/slab.h>
7108 +#include <linux/vs_context.h>
7109  #include <asm/current.h>
7110  #include <asm/uaccess.h>
7111  #include <linux/kernel.h>
7112 @@ -38,7 +39,7 @@ static int check_quotactl_permission(str
7113                         break;
7114                 /*FALLTHROUGH*/
7115         default:
7116 -               if (!capable(CAP_SYS_ADMIN))
7117 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7118                         return -EPERM;
7119         }
7120  
7121 @@ -293,6 +294,46 @@ static int do_quotactl(struct super_bloc
7122         }
7123  }
7124  
7125 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7126 +
7127 +#include <linux/vroot.h>
7128 +#include <linux/major.h>
7129 +#include <linux/module.h>
7130 +#include <linux/kallsyms.h>
7131 +#include <linux/vserver/debug.h>
7132 +
7133 +static vroot_grb_func *vroot_get_real_bdev = NULL;
7134 +
7135 +static DEFINE_SPINLOCK(vroot_grb_lock);
7136 +
7137 +int register_vroot_grb(vroot_grb_func *func) {
7138 +       int ret = -EBUSY;
7139 +
7140 +       spin_lock(&vroot_grb_lock);
7141 +       if (!vroot_get_real_bdev) {
7142 +               vroot_get_real_bdev = func;
7143 +               ret = 0;
7144 +       }
7145 +       spin_unlock(&vroot_grb_lock);
7146 +       return ret;
7147 +}
7148 +EXPORT_SYMBOL(register_vroot_grb);
7149 +
7150 +int unregister_vroot_grb(vroot_grb_func *func) {
7151 +       int ret = -EINVAL;
7152 +
7153 +       spin_lock(&vroot_grb_lock);
7154 +       if (vroot_get_real_bdev) {
7155 +               vroot_get_real_bdev = NULL;
7156 +               ret = 0;
7157 +       }
7158 +       spin_unlock(&vroot_grb_lock);
7159 +       return ret;
7160 +}
7161 +EXPORT_SYMBOL(unregister_vroot_grb);
7162 +
7163 +#endif
7164 +
7165  /*
7166   * look up a superblock on which quota ops will be performed
7167   * - use the name of a block device to find the superblock thereon
7168 @@ -310,6 +351,22 @@ static struct super_block *quotactl_bloc
7169         putname(tmp);
7170         if (IS_ERR(bdev))
7171                 return ERR_CAST(bdev);
7172 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7173 +       if (bdev && bdev->bd_inode &&
7174 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
7175 +               struct block_device *bdnew = (void *)-EINVAL;
7176 +
7177 +               if (vroot_get_real_bdev)
7178 +                       bdnew = vroot_get_real_bdev(bdev);
7179 +               else
7180 +                       vxdprintk(VXD_CBIT(misc, 0),
7181 +                                       "vroot_get_real_bdev not set");
7182 +               bdput(bdev);
7183 +               if (IS_ERR(bdnew))
7184 +                       return ERR_PTR(PTR_ERR(bdnew));
7185 +               bdev = bdnew;
7186 +       }
7187 +#endif
7188         sb = get_super(bdev);
7189         bdput(bdev);
7190         if (!sb)
7191 diff -NurpP --minimal linux-3.0-rc5/fs/reiserfs/file.c linux-3.0-rc5-vs2.3.1-pre3/fs/reiserfs/file.c
7192 --- linux-3.0-rc5/fs/reiserfs/file.c    2011-01-05 21:50:26.000000000 +0100
7193 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/reiserfs/file.c       2011-06-10 22:11:24.000000000 +0200
7194 @@ -312,4 +312,5 @@ const struct inode_operations reiserfs_f
7195         .listxattr = reiserfs_listxattr,
7196         .removexattr = reiserfs_removexattr,
7197         .permission = reiserfs_permission,
7198 +       .sync_flags = reiserfs_sync_flags,
7199  };
7200 diff -NurpP --minimal linux-3.0-rc5/fs/reiserfs/inode.c linux-3.0-rc5-vs2.3.1-pre3/fs/reiserfs/inode.c
7201 --- linux-3.0-rc5/fs/reiserfs/inode.c   2011-05-22 16:17:53.000000000 +0200
7202 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/reiserfs/inode.c      2011-06-10 22:11:24.000000000 +0200
7203 @@ -18,6 +18,7 @@
7204  #include <linux/writeback.h>
7205  #include <linux/quotaops.h>
7206  #include <linux/swap.h>
7207 +#include <linux/vs_tag.h>
7208  
7209  int reiserfs_commit_write(struct file *f, struct page *page,
7210                           unsigned from, unsigned to);
7211 @@ -1131,6 +1132,8 @@ static void init_inode(struct inode *ino
7212         struct buffer_head *bh;
7213         struct item_head *ih;
7214         __u32 rdev;
7215 +       uid_t uid;
7216 +       gid_t gid;
7217         //int version = ITEM_VERSION_1;
7218  
7219         bh = PATH_PLAST_BUFFER(path);
7220 @@ -1151,12 +1154,13 @@ static void init_inode(struct inode *ino
7221                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
7222                 unsigned long blocks;
7223  
7224 +               uid = sd_v1_uid(sd);
7225 +               gid = sd_v1_gid(sd);
7226 +
7227                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
7228                 set_inode_sd_version(inode, STAT_DATA_V1);
7229                 inode->i_mode = sd_v1_mode(sd);
7230                 inode->i_nlink = sd_v1_nlink(sd);
7231 -               inode->i_uid = sd_v1_uid(sd);
7232 -               inode->i_gid = sd_v1_gid(sd);
7233                 inode->i_size = sd_v1_size(sd);
7234                 inode->i_atime.tv_sec = sd_v1_atime(sd);
7235                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
7236 @@ -1198,11 +1202,12 @@ static void init_inode(struct inode *ino
7237                 // (directories and symlinks)
7238                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
7239  
7240 +               uid    = sd_v2_uid(sd);
7241 +               gid    = sd_v2_gid(sd);
7242 +
7243                 inode->i_mode = sd_v2_mode(sd);
7244                 inode->i_nlink = sd_v2_nlink(sd);
7245 -               inode->i_uid = sd_v2_uid(sd);
7246                 inode->i_size = sd_v2_size(sd);
7247 -               inode->i_gid = sd_v2_gid(sd);
7248                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
7249                 inode->i_atime.tv_sec = sd_v2_atime(sd);
7250                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
7251 @@ -1232,6 +1237,10 @@ static void init_inode(struct inode *ino
7252                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
7253         }
7254  
7255 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7256 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7257 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
7258 +
7259         pathrelse(path);
7260         if (S_ISREG(inode->i_mode)) {
7261                 inode->i_op = &reiserfs_file_inode_operations;
7262 @@ -1254,13 +1263,15 @@ static void init_inode(struct inode *ino
7263  static void inode2sd(void *sd, struct inode *inode, loff_t size)
7264  {
7265         struct stat_data *sd_v2 = (struct stat_data *)sd;
7266 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
7267 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
7268         __u16 flags;
7269  
7270 +       set_sd_v2_uid(sd_v2, uid);
7271 +       set_sd_v2_gid(sd_v2, gid);
7272         set_sd_v2_mode(sd_v2, inode->i_mode);
7273         set_sd_v2_nlink(sd_v2, inode->i_nlink);
7274 -       set_sd_v2_uid(sd_v2, inode->i_uid);
7275         set_sd_v2_size(sd_v2, size);
7276 -       set_sd_v2_gid(sd_v2, inode->i_gid);
7277         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
7278         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
7279         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
7280 @@ -2863,14 +2874,19 @@ int reiserfs_commit_write(struct file *f
7281  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
7282  {
7283         if (reiserfs_attrs(inode->i_sb)) {
7284 -               if (sd_attrs & REISERFS_SYNC_FL)
7285 -                       inode->i_flags |= S_SYNC;
7286 -               else
7287 -                       inode->i_flags &= ~S_SYNC;
7288                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
7289                         inode->i_flags |= S_IMMUTABLE;
7290                 else
7291                         inode->i_flags &= ~S_IMMUTABLE;
7292 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
7293 +                       inode->i_flags |= S_IXUNLINK;
7294 +               else
7295 +                       inode->i_flags &= ~S_IXUNLINK;
7296 +
7297 +               if (sd_attrs & REISERFS_SYNC_FL)
7298 +                       inode->i_flags |= S_SYNC;
7299 +               else
7300 +                       inode->i_flags &= ~S_SYNC;
7301                 if (sd_attrs & REISERFS_APPEND_FL)
7302                         inode->i_flags |= S_APPEND;
7303                 else
7304 @@ -2883,6 +2899,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
7305                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
7306                 else
7307                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
7308 +
7309 +               if (sd_attrs & REISERFS_BARRIER_FL)
7310 +                       inode->i_vflags |= V_BARRIER;
7311 +               else
7312 +                       inode->i_vflags &= ~V_BARRIER;
7313 +               if (sd_attrs & REISERFS_COW_FL)
7314 +                       inode->i_vflags |= V_COW;
7315 +               else
7316 +                       inode->i_vflags &= ~V_COW;
7317         }
7318  }
7319  
7320 @@ -2893,6 +2918,11 @@ void i_attrs_to_sd_attrs(struct inode *i
7321                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
7322                 else
7323                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
7324 +               if (inode->i_flags & S_IXUNLINK)
7325 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
7326 +               else
7327 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
7328 +
7329                 if (inode->i_flags & S_SYNC)
7330                         *sd_attrs |= REISERFS_SYNC_FL;
7331                 else
7332 @@ -2905,6 +2935,15 @@ void i_attrs_to_sd_attrs(struct inode *i
7333                         *sd_attrs |= REISERFS_NOTAIL_FL;
7334                 else
7335                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
7336 +
7337 +               if (inode->i_vflags & V_BARRIER)
7338 +                       *sd_attrs |= REISERFS_BARRIER_FL;
7339 +               else
7340 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
7341 +               if (inode->i_vflags & V_COW)
7342 +                       *sd_attrs |= REISERFS_COW_FL;
7343 +               else
7344 +                       *sd_attrs &= ~REISERFS_COW_FL;
7345         }
7346  }
7347  
7348 @@ -3148,7 +3187,8 @@ int reiserfs_setattr(struct dentry *dent
7349         }
7350  
7351         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
7352 -           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
7353 +           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
7354 +           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
7355                 struct reiserfs_transaction_handle th;
7356                 int jbegin_count =
7357                     2 *
7358 @@ -3177,6 +3217,9 @@ int reiserfs_setattr(struct dentry *dent
7359                         inode->i_uid = attr->ia_uid;
7360                 if (attr->ia_valid & ATTR_GID)
7361                         inode->i_gid = attr->ia_gid;
7362 +                               if ((attr->ia_valid & ATTR_TAG) &&
7363 +                                       IS_TAGGED(inode))
7364 +                                       inode->i_tag = attr->ia_tag;
7365                 mark_inode_dirty(inode);
7366                 error = journal_end(&th, inode->i_sb, jbegin_count);
7367                 if (error)
7368 diff -NurpP --minimal linux-3.0-rc5/fs/reiserfs/ioctl.c linux-3.0-rc5-vs2.3.1-pre3/fs/reiserfs/ioctl.c
7369 --- linux-3.0-rc5/fs/reiserfs/ioctl.c   2011-05-22 16:17:53.000000000 +0200
7370 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/reiserfs/ioctl.c      2011-06-10 22:11:24.000000000 +0200
7371 @@ -11,6 +11,21 @@
7372  #include <linux/pagemap.h>
7373  #include <linux/compat.h>
7374  
7375 +
7376 +int reiserfs_sync_flags(struct inode *inode, int flags, int vflags)
7377 +{
7378 +       __u16 sd_attrs = 0;
7379 +
7380 +       inode->i_flags = flags;
7381 +       inode->i_vflags = vflags;
7382 +
7383 +       i_attrs_to_sd_attrs(inode, &sd_attrs);
7384 +       REISERFS_I(inode)->i_attrs = sd_attrs;
7385 +       inode->i_ctime = CURRENT_TIME_SEC;
7386 +       mark_inode_dirty(inode);
7387 +       return 0;
7388 +}
7389 +
7390  /*
7391   * reiserfs_ioctl - handler for ioctl for inode
7392   * supported commands:
7393 @@ -22,7 +37,7 @@
7394  long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
7395  {
7396         struct inode *inode = filp->f_path.dentry->d_inode;
7397 -       unsigned int flags;
7398 +       unsigned int flags, oldflags;
7399         int err = 0;
7400  
7401         reiserfs_write_lock(inode->i_sb);
7402 @@ -47,6 +62,7 @@ long reiserfs_ioctl(struct file *filp, u
7403  
7404                 flags = REISERFS_I(inode)->i_attrs;
7405                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
7406 +               flags &= REISERFS_FL_USER_VISIBLE;
7407                 err = put_user(flags, (int __user *)arg);
7408                 break;
7409         case REISERFS_IOC_SETFLAGS:{
7410 @@ -67,6 +83,10 @@ long reiserfs_ioctl(struct file *filp, u
7411                                 err = -EFAULT;
7412                                 goto setflags_out;
7413                         }
7414 +                       if (IS_BARRIER(inode)) {
7415 +                               vxwprintk_task(1, "messing with the barrier.");
7416 +                               return -EACCES;
7417 +                       }
7418                         /*
7419                          * Is it quota file? Do not allow user to mess with it
7420                          */
7421 @@ -91,6 +111,10 @@ long reiserfs_ioctl(struct file *filp, u
7422                                         goto setflags_out;
7423                                 }
7424                         }
7425 +
7426 +                       oldflags = REISERFS_I(inode)->i_attrs;
7427 +                       flags &= REISERFS_FL_USER_MODIFIABLE;
7428 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
7429                         sd_attrs_to_i_attrs(flags, inode);
7430                         REISERFS_I(inode)->i_attrs = flags;
7431                         inode->i_ctime = CURRENT_TIME_SEC;
7432 diff -NurpP --minimal linux-3.0-rc5/fs/reiserfs/namei.c linux-3.0-rc5-vs2.3.1-pre3/fs/reiserfs/namei.c
7433 --- linux-3.0-rc5/fs/reiserfs/namei.c   2011-05-22 16:17:53.000000000 +0200
7434 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/reiserfs/namei.c      2011-06-10 22:11:24.000000000 +0200
7435 @@ -18,6 +18,7 @@
7436  #include <linux/reiserfs_acl.h>
7437  #include <linux/reiserfs_xattr.h>
7438  #include <linux/quotaops.h>
7439 +#include <linux/vs_tag.h>
7440  
7441  #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; }
7442  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
7443 @@ -362,6 +363,7 @@ static struct dentry *reiserfs_lookup(st
7444         if (retval == IO_ERROR) {
7445                 return ERR_PTR(-EIO);
7446         }
7447 +               dx_propagate_tag(nd, inode);
7448  
7449         return d_splice_alias(inode, dentry);
7450  }
7451 @@ -1529,6 +1531,7 @@ const struct inode_operations reiserfs_d
7452         .listxattr = reiserfs_listxattr,
7453         .removexattr = reiserfs_removexattr,
7454         .permission = reiserfs_permission,
7455 +       .sync_flags = reiserfs_sync_flags,
7456  };
7457  
7458  /*
7459 diff -NurpP --minimal linux-3.0-rc5/fs/reiserfs/super.c linux-3.0-rc5-vs2.3.1-pre3/fs/reiserfs/super.c
7460 --- linux-3.0-rc5/fs/reiserfs/super.c   2011-07-01 11:14:20.000000000 +0200
7461 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/reiserfs/super.c      2011-06-10 22:11:24.000000000 +0200
7462 @@ -899,6 +899,14 @@ static int reiserfs_parse_options(struct
7463                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
7464                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
7465  #endif
7466 +#ifndef CONFIG_TAGGING_NONE
7467 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
7468 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
7469 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
7470 +#endif
7471 +#ifdef CONFIG_PROPAGATE
7472 +               {"tag",.arg_required = 'T',.values = NULL},
7473 +#endif
7474  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
7475                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
7476                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
7477 @@ -1208,6 +1216,14 @@ static int reiserfs_remount(struct super
7478         handle_quota_files(s, qf_names, &qfmt);
7479  #endif
7480  
7481 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
7482 +               !(s->s_flags & MS_TAGGED)) {
7483 +               reiserfs_warning(s, "super-vs01",
7484 +                       "reiserfs: tagging not permitted on remount.");
7485 +               err = -EINVAL;
7486 +               goto out_err;
7487 +       }
7488 +
7489         handle_attrs(s);
7490  
7491         /* Add options that are safe here */
7492 @@ -1690,6 +1706,10 @@ static int reiserfs_fill_super(struct su
7493                 goto error;
7494         }
7495  
7496 +       /* map mount option tagxid */
7497 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
7498 +               s->s_flags |= MS_TAGGED;
7499 +
7500         rs = SB_DISK_SUPER_BLOCK(s);
7501         /* Let's do basic sanity check to verify that underlying device is not
7502            smaller than the filesystem. If the check fails then abort and scream,
7503 diff -NurpP --minimal linux-3.0-rc5/fs/reiserfs/xattr.c linux-3.0-rc5-vs2.3.1-pre3/fs/reiserfs/xattr.c
7504 --- linux-3.0-rc5/fs/reiserfs/xattr.c   2011-07-01 11:14:20.000000000 +0200
7505 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/reiserfs/xattr.c      2011-06-22 12:39:15.000000000 +0200
7506 @@ -40,6 +40,7 @@
7507  #include <linux/errno.h>
7508  #include <linux/gfp.h>
7509  #include <linux/fs.h>
7510 +#include <linux/mount.h>
7511  #include <linux/file.h>
7512  #include <linux/pagemap.h>
7513  #include <linux/xattr.h>
7514 diff -NurpP --minimal linux-3.0-rc5/fs/stat.c linux-3.0-rc5-vs2.3.1-pre3/fs/stat.c
7515 --- linux-3.0-rc5/fs/stat.c     2011-05-22 16:17:54.000000000 +0200
7516 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/stat.c        2011-06-10 22:11:24.000000000 +0200
7517 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
7518         stat->nlink = inode->i_nlink;
7519         stat->uid = inode->i_uid;
7520         stat->gid = inode->i_gid;
7521 +       stat->tag = inode->i_tag;
7522         stat->rdev = inode->i_rdev;
7523         stat->atime = inode->i_atime;
7524         stat->mtime = inode->i_mtime;
7525 diff -NurpP --minimal linux-3.0-rc5/fs/statfs.c linux-3.0-rc5-vs2.3.1-pre3/fs/statfs.c
7526 --- linux-3.0-rc5/fs/statfs.c   2011-05-22 16:17:54.000000000 +0200
7527 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/statfs.c      2011-06-10 22:11:24.000000000 +0200
7528 @@ -7,6 +7,8 @@
7529  #include <linux/statfs.h>
7530  #include <linux/security.h>
7531  #include <linux/uaccess.h>
7532 +#include <linux/vs_base.h>
7533 +#include <linux/vs_dlimit.h>
7534  
7535  static int flags_by_mnt(int mnt_flags)
7536  {
7537 @@ -59,6 +61,8 @@ int statfs_by_dentry(struct dentry *dent
7538         retval = dentry->d_sb->s_op->statfs(dentry, buf);
7539         if (retval == 0 && buf->f_frsize == 0)
7540                 buf->f_frsize = buf->f_bsize;
7541 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
7542 +               vx_vsi_statfs(dentry->d_sb, buf);
7543         return retval;
7544  }
7545  
7546 diff -NurpP --minimal linux-3.0-rc5/fs/sysfs/mount.c linux-3.0-rc5-vs2.3.1-pre3/fs/sysfs/mount.c
7547 --- linux-3.0-rc5/fs/sysfs/mount.c      2011-07-01 11:14:20.000000000 +0200
7548 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/sysfs/mount.c 2011-06-22 12:39:15.000000000 +0200
7549 @@ -47,7 +47,7 @@ static int sysfs_fill_super(struct super
7550  
7551         sb->s_blocksize = PAGE_CACHE_SIZE;
7552         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
7553 -       sb->s_magic = SYSFS_MAGIC;
7554 +       sb->s_magic = SYSFS_SUPER_MAGIC;
7555         sb->s_op = &sysfs_ops;
7556         sb->s_time_gran = 1;
7557  
7558 diff -NurpP --minimal linux-3.0-rc5/fs/utimes.c linux-3.0-rc5-vs2.3.1-pre3/fs/utimes.c
7559 --- linux-3.0-rc5/fs/utimes.c   2011-05-22 16:17:54.000000000 +0200
7560 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/utimes.c      2011-06-10 22:11:24.000000000 +0200
7561 @@ -8,6 +8,8 @@
7562  #include <linux/stat.h>
7563  #include <linux/utime.h>
7564  #include <linux/syscalls.h>
7565 +#include <linux/mount.h>
7566 +#include <linux/vs_cowbl.h>
7567  #include <asm/uaccess.h>
7568  #include <asm/unistd.h>
7569  
7570 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
7571  {
7572         int error;
7573         struct iattr newattrs;
7574 -       struct inode *inode = path->dentry->d_inode;
7575 +       struct inode *inode;
7576  
7577         error = mnt_want_write(path->mnt);
7578         if (error)
7579                 goto out;
7580  
7581 +       error = cow_check_and_break(path);
7582 +       if (error)
7583 +               goto mnt_drop_write_and_out;
7584 +
7585 +       inode = path->dentry->d_inode;
7586 +
7587         if (times && times[0].tv_nsec == UTIME_NOW &&
7588                      times[1].tv_nsec == UTIME_NOW)
7589                 times = NULL;
7590 diff -NurpP --minimal linux-3.0-rc5/fs/xattr.c linux-3.0-rc5-vs2.3.1-pre3/fs/xattr.c
7591 --- linux-3.0-rc5/fs/xattr.c    2011-07-01 11:14:20.000000000 +0200
7592 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/xattr.c       2011-06-10 23:10:19.000000000 +0200
7593 @@ -18,6 +18,7 @@
7594  #include <linux/module.h>
7595  #include <linux/fsnotify.h>
7596  #include <linux/audit.h>
7597 +#include <linux/mount.h>
7598  #include <asm/uaccess.h>
7599  
7600  
7601 @@ -49,7 +50,7 @@ xattr_permission(struct inode *inode, co
7602          * The trusted.* namespace can only be accessed by privileged users.
7603          */
7604         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
7605 -               if (!capable(CAP_SYS_ADMIN))
7606 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
7607                         return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
7608                 return 0;
7609         }
7610 diff -NurpP --minimal linux-3.0-rc5/fs/xfs/linux-2.6/xfs_ioctl.c linux-3.0-rc5-vs2.3.1-pre3/fs/xfs/linux-2.6/xfs_ioctl.c
7611 --- linux-3.0-rc5/fs/xfs/linux-2.6/xfs_ioctl.c  2011-05-22 16:17:54.000000000 +0200
7612 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/xfs/linux-2.6/xfs_ioctl.c     2011-06-10 22:11:24.000000000 +0200
7613 @@ -28,7 +28,7 @@
7614  #include "xfs_bmap_btree.h"
7615  #include "xfs_dinode.h"
7616  #include "xfs_inode.h"
7617 -#include "xfs_ioctl.h"
7618 +// #include "xfs_ioctl.h"
7619  #include "xfs_rtalloc.h"
7620  #include "xfs_itable.h"
7621  #include "xfs_error.h"
7622 @@ -748,6 +748,10 @@ xfs_merge_ioc_xflags(
7623                 xflags |= XFS_XFLAG_IMMUTABLE;
7624         else
7625                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7626 +       if (flags & FS_IXUNLINK_FL)
7627 +               xflags |= XFS_XFLAG_IXUNLINK;
7628 +       else
7629 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7630         if (flags & FS_APPEND_FL)
7631                 xflags |= XFS_XFLAG_APPEND;
7632         else
7633 @@ -776,6 +780,8 @@ xfs_di2lxflags(
7634  
7635         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7636                 flags |= FS_IMMUTABLE_FL;
7637 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7638 +               flags |= FS_IXUNLINK_FL;
7639         if (di_flags & XFS_DIFLAG_APPEND)
7640                 flags |= FS_APPEND_FL;
7641         if (di_flags & XFS_DIFLAG_SYNC)
7642 @@ -836,6 +842,8 @@ xfs_set_diflags(
7643         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7644         if (xflags & XFS_XFLAG_IMMUTABLE)
7645                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7646 +       if (xflags & XFS_XFLAG_IXUNLINK)
7647 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7648         if (xflags & XFS_XFLAG_APPEND)
7649                 di_flags |= XFS_DIFLAG_APPEND;
7650         if (xflags & XFS_XFLAG_SYNC)
7651 @@ -878,6 +886,10 @@ xfs_diflags_to_linux(
7652                 inode->i_flags |= S_IMMUTABLE;
7653         else
7654                 inode->i_flags &= ~S_IMMUTABLE;
7655 +       if (xflags & XFS_XFLAG_IXUNLINK)
7656 +               inode->i_flags |= S_IXUNLINK;
7657 +       else
7658 +               inode->i_flags &= ~S_IXUNLINK;
7659         if (xflags & XFS_XFLAG_APPEND)
7660                 inode->i_flags |= S_APPEND;
7661         else
7662 @@ -1370,10 +1382,18 @@ xfs_file_ioctl(
7663         case XFS_IOC_FSGETXATTRA:
7664                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7665         case XFS_IOC_FSSETXATTR:
7666 +               if (IS_BARRIER(inode)) {
7667 +                       vxwprintk_task(1, "messing with the barrier.");
7668 +                       return -XFS_ERROR(EACCES);
7669 +               }
7670                 return xfs_ioc_fssetxattr(ip, filp, arg);
7671         case XFS_IOC_GETXFLAGS:
7672                 return xfs_ioc_getxflags(ip, arg);
7673         case XFS_IOC_SETXFLAGS:
7674 +               if (IS_BARRIER(inode)) {
7675 +                       vxwprintk_task(1, "messing with the barrier.");
7676 +                       return -XFS_ERROR(EACCES);
7677 +               }
7678                 return xfs_ioc_setxflags(ip, filp, arg);
7679  
7680         case XFS_IOC_FSSETDM: {
7681 diff -NurpP --minimal linux-3.0-rc5/fs/xfs/linux-2.6/xfs_ioctl.h linux-3.0-rc5-vs2.3.1-pre3/fs/xfs/linux-2.6/xfs_ioctl.h
7682 --- linux-3.0-rc5/fs/xfs/linux-2.6/xfs_ioctl.h  2010-07-07 18:31:54.000000000 +0200
7683 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/xfs/linux-2.6/xfs_ioctl.h     2011-06-10 22:11:24.000000000 +0200
7684 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7685         void __user             *uhandle,
7686         u32                     hlen);
7687  
7688 +extern int
7689 +xfs_sync_flags(
7690 +       struct inode            *inode,
7691 +       int                     flags,
7692 +       int                     vflags);
7693 +
7694  extern long
7695  xfs_file_ioctl(
7696         struct file             *filp,
7697 diff -NurpP --minimal linux-3.0-rc5/fs/xfs/linux-2.6/xfs_iops.c linux-3.0-rc5-vs2.3.1-pre3/fs/xfs/linux-2.6/xfs_iops.c
7698 --- linux-3.0-rc5/fs/xfs/linux-2.6/xfs_iops.c   2011-07-01 11:14:20.000000000 +0200
7699 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/xfs/linux-2.6/xfs_iops.c      2011-06-22 12:39:15.000000000 +0200
7700 @@ -30,6 +30,7 @@
7701  #include "xfs_bmap_btree.h"
7702  #include "xfs_dinode.h"
7703  #include "xfs_inode.h"
7704 +#include "xfs_ioctl.h"
7705  #include "xfs_bmap.h"
7706  #include "xfs_rtalloc.h"
7707  #include "xfs_error.h"
7708 @@ -48,6 +49,7 @@
7709  #include <linux/security.h>
7710  #include <linux/fiemap.h>
7711  #include <linux/slab.h>
7712 +#include <linux/vs_tag.h>
7713  
7714  /*
7715   * Bring the timestamps in the XFS inode uptodate.
7716 @@ -464,6 +466,7 @@ xfs_vn_getattr(
7717         stat->nlink = ip->i_d.di_nlink;
7718         stat->uid = ip->i_d.di_uid;
7719         stat->gid = ip->i_d.di_gid;
7720 +       stat->tag = ip->i_d.di_tag;
7721         stat->ino = ip->i_ino;
7722         stat->atime = inode->i_atime;
7723         stat->mtime = inode->i_mtime;
7724 @@ -599,6 +602,7 @@ static const struct inode_operations xfs
7725         .removexattr            = generic_removexattr,
7726         .listxattr              = xfs_vn_listxattr,
7727         .fiemap                 = xfs_vn_fiemap,
7728 +       .sync_flags             = xfs_sync_flags,
7729  };
7730  
7731  static const struct inode_operations xfs_dir_inode_operations = {
7732 @@ -624,6 +628,7 @@ static const struct inode_operations xfs
7733         .getxattr               = generic_getxattr,
7734         .removexattr            = generic_removexattr,
7735         .listxattr              = xfs_vn_listxattr,
7736 +       .sync_flags             = xfs_sync_flags,
7737  };
7738  
7739  static const struct inode_operations xfs_dir_ci_inode_operations = {
7740 @@ -673,6 +678,10 @@ xfs_diflags_to_iflags(
7741                 inode->i_flags |= S_IMMUTABLE;
7742         else
7743                 inode->i_flags &= ~S_IMMUTABLE;
7744 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7745 +               inode->i_flags |= S_IXUNLINK;
7746 +       else
7747 +               inode->i_flags &= ~S_IXUNLINK;
7748         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7749                 inode->i_flags |= S_APPEND;
7750         else
7751 @@ -685,6 +694,15 @@ xfs_diflags_to_iflags(
7752                 inode->i_flags |= S_NOATIME;
7753         else
7754                 inode->i_flags &= ~S_NOATIME;
7755 +
7756 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7757 +               inode->i_vflags |= V_BARRIER;
7758 +       else
7759 +               inode->i_vflags &= ~V_BARRIER;
7760 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7761 +               inode->i_vflags |= V_COW;
7762 +       else
7763 +               inode->i_vflags &= ~V_COW;
7764  }
7765  
7766  /*
7767 @@ -716,6 +734,7 @@ xfs_setup_inode(
7768         inode->i_nlink  = ip->i_d.di_nlink;
7769         inode->i_uid    = ip->i_d.di_uid;
7770         inode->i_gid    = ip->i_d.di_gid;
7771 +       inode->i_tag    = ip->i_d.di_tag;
7772  
7773         switch (inode->i_mode & S_IFMT) {
7774         case S_IFBLK:
7775 diff -NurpP --minimal linux-3.0-rc5/fs/xfs/linux-2.6/xfs_linux.h linux-3.0-rc5-vs2.3.1-pre3/fs/xfs/linux-2.6/xfs_linux.h
7776 --- linux-3.0-rc5/fs/xfs/linux-2.6/xfs_linux.h  2011-07-01 11:14:20.000000000 +0200
7777 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/xfs/linux-2.6/xfs_linux.h     2011-06-10 22:11:24.000000000 +0200
7778 @@ -115,6 +115,7 @@
7779  
7780  #define current_cpu()          (raw_smp_processor_id())
7781  #define current_pid()          (current->pid)
7782 +#define current_fstag(vp)      (dx_current_fstag((vp)->i_sb))
7783  #define current_test_flags(f)  (current->flags & (f))
7784  #define current_set_flags_nested(sp, f)                \
7785                 (*(sp) = current->flags, current->flags |= (f))
7786 diff -NurpP --minimal linux-3.0-rc5/fs/xfs/linux-2.6/xfs_super.c linux-3.0-rc5-vs2.3.1-pre3/fs/xfs/linux-2.6/xfs_super.c
7787 --- linux-3.0-rc5/fs/xfs/linux-2.6/xfs_super.c  2011-07-01 11:14:20.000000000 +0200
7788 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/xfs/linux-2.6/xfs_super.c     2011-06-22 12:39:15.000000000 +0200
7789 @@ -114,6 +114,9 @@ mempool_t *xfs_ioend_pool;
7790  #define MNTOPT_NODELAYLOG  "nodelaylog"        /* Delayed logging disabled */
7791  #define MNTOPT_DISCARD    "discard"    /* Discard unused blocks */
7792  #define MNTOPT_NODISCARD   "nodiscard" /* Do not discard unused blocks */
7793 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
7794 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
7795 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
7796  
7797  /*
7798   * Table driven mount option parser.
7799 @@ -122,10 +125,14 @@ mempool_t *xfs_ioend_pool;
7800   * in the future, too.
7801   */
7802  enum {
7803 +       Opt_tag, Opt_notag,
7804         Opt_barrier, Opt_nobarrier, Opt_err
7805  };
7806  
7807  static const match_table_t tokens = {
7808 +       {Opt_tag, "tagxid"},
7809 +       {Opt_tag, "tag"},
7810 +       {Opt_notag, "notag"},
7811         {Opt_barrier, "barrier"},
7812         {Opt_nobarrier, "nobarrier"},
7813         {Opt_err, NULL}
7814 @@ -373,6 +380,19 @@ xfs_parseargs(
7815                 } else if (!strcmp(this_char, "irixsgid")) {
7816                         xfs_warn(mp,
7817         "irixsgid is now a sysctl(2) variable, option is deprecated.");
7818 +#ifndef CONFIG_TAGGING_NONE
7819 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7820 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7821 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7822 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
7823 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7824 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7825 +#endif
7826 +#ifdef CONFIG_PROPAGATE
7827 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7828 +                       /* use value */
7829 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7830 +#endif
7831                 } else {
7832                         xfs_warn(mp, "unknown mount option [%s].", this_char);
7833                         return EINVAL;
7834 @@ -1182,6 +1202,16 @@ xfs_fs_remount(
7835                 case Opt_nobarrier:
7836                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
7837                         break;
7838 +               case Opt_tag:
7839 +                       if (!(sb->s_flags & MS_TAGGED)) {
7840 +                               printk(KERN_INFO
7841 +                                       "XFS: %s: tagging not permitted on remount.\n",
7842 +                                       sb->s_id);
7843 +                               return -EINVAL;
7844 +                       }
7845 +                       break;
7846 +               case Opt_notag:
7847 +                       break;
7848                 default:
7849                         /*
7850                          * Logically we would return an error here to prevent
7851 @@ -1397,6 +1427,9 @@ xfs_fs_fill_super(
7852         if (error)
7853                 goto out_free_sb;
7854  
7855 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
7856 +               sb->s_flags |= MS_TAGGED;
7857 +
7858         /*
7859          * we must configure the block size in the superblock before we run the
7860          * full mount process as the mount process can lookup and cache inodes.
7861 diff -NurpP --minimal linux-3.0-rc5/fs/xfs/xfs_dinode.h linux-3.0-rc5-vs2.3.1-pre3/fs/xfs/xfs_dinode.h
7862 --- linux-3.0-rc5/fs/xfs/xfs_dinode.h   2011-01-05 21:50:28.000000000 +0100
7863 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/xfs/xfs_dinode.h      2011-06-10 22:11:24.000000000 +0200
7864 @@ -51,7 +51,9 @@ typedef struct xfs_dinode {
7865         __be32          di_nlink;       /* number of links to file */
7866         __be16          di_projid_lo;   /* lower part of owner's project id */
7867         __be16          di_projid_hi;   /* higher part owner's project id */
7868 -       __u8            di_pad[6];      /* unused, zeroed space */
7869 +       __u8            di_pad[2];      /* unused, zeroed space */
7870 +       __be16          di_tag;         /* context tagging */
7871 +       __be16          di_vflags;      /* vserver specific flags */
7872         __be16          di_flushiter;   /* incremented on flush */
7873         xfs_timestamp_t di_atime;       /* time last accessed */
7874         xfs_timestamp_t di_mtime;       /* time last modified */
7875 @@ -184,6 +186,8 @@ static inline void xfs_dinode_put_rdev(s
7876  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
7877  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
7878  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
7879 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
7880 +
7881  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
7882  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
7883  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
7884 @@ -199,6 +203,7 @@ static inline void xfs_dinode_put_rdev(s
7885  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
7886  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
7887  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
7888 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
7889  
7890  #ifdef CONFIG_XFS_RT
7891  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
7892 @@ -211,6 +216,10 @@ static inline void xfs_dinode_put_rdev(s
7893          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
7894          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
7895          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
7896 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
7897 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
7898 +        XFS_DIFLAG_IXUNLINK)
7899 +
7900 +#define XFS_DIVFLAG_BARRIER    0x01
7901 +#define XFS_DIVFLAG_COW                0x02
7902  
7903  #endif /* __XFS_DINODE_H__ */
7904 diff -NurpP --minimal linux-3.0-rc5/fs/xfs/xfs_fs.h linux-3.0-rc5-vs2.3.1-pre3/fs/xfs/xfs_fs.h
7905 --- linux-3.0-rc5/fs/xfs/xfs_fs.h       2011-01-05 21:50:28.000000000 +0100
7906 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/xfs/xfs_fs.h  2011-06-10 22:11:24.000000000 +0200
7907 @@ -67,6 +67,9 @@ struct fsxattr {
7908  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
7909  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
7910  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
7911 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
7912 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
7913 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
7914  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
7915  
7916  /*
7917 @@ -297,7 +300,8 @@ typedef struct xfs_bstat {
7918  #define        bs_projid       bs_projid_lo    /* (previously just bs_projid)  */
7919         __u16           bs_forkoff;     /* inode fork offset in bytes   */
7920         __u16           bs_projid_hi;   /* higher part of project id    */
7921 -       unsigned char   bs_pad[10];     /* pad space, unused            */
7922 +       unsigned char   bs_pad[8];      /* pad space, unused            */
7923 +       __u16           bs_tag;         /* context tagging              */
7924         __u32           bs_dmevmask;    /* DMIG event mask              */
7925         __u16           bs_dmstate;     /* DMIG state info              */
7926         __u16           bs_aextents;    /* attribute number of extents  */
7927 diff -NurpP --minimal linux-3.0-rc5/fs/xfs/xfs_ialloc.c linux-3.0-rc5-vs2.3.1-pre3/fs/xfs/xfs_ialloc.c
7928 --- linux-3.0-rc5/fs/xfs/xfs_ialloc.c   2011-05-22 16:17:54.000000000 +0200
7929 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/xfs/xfs_ialloc.c      2011-06-10 22:11:24.000000000 +0200
7930 @@ -37,7 +37,6 @@
7931  #include "xfs_error.h"
7932  #include "xfs_bmap.h"
7933  
7934 -
7935  /*
7936   * Allocation group level functions.
7937   */
7938 diff -NurpP --minimal linux-3.0-rc5/fs/xfs/xfs_inode.c linux-3.0-rc5-vs2.3.1-pre3/fs/xfs/xfs_inode.c
7939 --- linux-3.0-rc5/fs/xfs/xfs_inode.c    2011-07-01 11:14:20.000000000 +0200
7940 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/xfs/xfs_inode.c       2011-06-10 22:11:24.000000000 +0200
7941 @@ -243,6 +243,7 @@ xfs_inotobp(
7942         return 0;
7943  }
7944  
7945 +#include <linux/vs_tag.h>
7946  
7947  /*
7948   * This routine is called to map an inode to the buffer containing
7949 @@ -641,15 +642,25 @@ xfs_iformat_btree(
7950  STATIC void
7951  xfs_dinode_from_disk(
7952         xfs_icdinode_t          *to,
7953 -       xfs_dinode_t            *from)
7954 +       xfs_dinode_t            *from,
7955 +       int tagged)
7956  {
7957 +       uint32_t uid, gid, tag;
7958 +
7959         to->di_magic = be16_to_cpu(from->di_magic);
7960         to->di_mode = be16_to_cpu(from->di_mode);
7961         to->di_version = from ->di_version;
7962         to->di_format = from->di_format;
7963         to->di_onlink = be16_to_cpu(from->di_onlink);
7964 -       to->di_uid = be32_to_cpu(from->di_uid);
7965 -       to->di_gid = be32_to_cpu(from->di_gid);
7966 +
7967 +       uid = be32_to_cpu(from->di_uid);
7968 +       gid = be32_to_cpu(from->di_gid);
7969 +       tag = be16_to_cpu(from->di_tag);
7970 +
7971 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
7972 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
7973 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
7974 +
7975         to->di_nlink = be32_to_cpu(from->di_nlink);
7976         to->di_projid_lo = be16_to_cpu(from->di_projid_lo);
7977         to->di_projid_hi = be16_to_cpu(from->di_projid_hi);
7978 @@ -671,21 +682,26 @@ xfs_dinode_from_disk(
7979         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
7980         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
7981         to->di_flags    = be16_to_cpu(from->di_flags);
7982 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
7983         to->di_gen      = be32_to_cpu(from->di_gen);
7984  }
7985  
7986  void
7987  xfs_dinode_to_disk(
7988         xfs_dinode_t            *to,
7989 -       xfs_icdinode_t          *from)
7990 +       xfs_icdinode_t          *from,
7991 +       int tagged)
7992  {
7993         to->di_magic = cpu_to_be16(from->di_magic);
7994         to->di_mode = cpu_to_be16(from->di_mode);
7995         to->di_version = from ->di_version;
7996         to->di_format = from->di_format;
7997         to->di_onlink = cpu_to_be16(from->di_onlink);
7998 -       to->di_uid = cpu_to_be32(from->di_uid);
7999 -       to->di_gid = cpu_to_be32(from->di_gid);
8000 +
8001 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
8002 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
8003 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
8004 +
8005         to->di_nlink = cpu_to_be32(from->di_nlink);
8006         to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
8007         to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
8008 @@ -707,12 +723,14 @@ xfs_dinode_to_disk(
8009         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
8010         to->di_dmstate = cpu_to_be16(from->di_dmstate);
8011         to->di_flags = cpu_to_be16(from->di_flags);
8012 +       to->di_vflags = cpu_to_be16(from->di_vflags);
8013         to->di_gen = cpu_to_be32(from->di_gen);
8014  }
8015  
8016  STATIC uint
8017  _xfs_dic2xflags(
8018 -       __uint16_t              di_flags)
8019 +       __uint16_t              di_flags,
8020 +       __uint16_t              di_vflags)
8021  {
8022         uint                    flags = 0;
8023  
8024 @@ -723,6 +741,8 @@ _xfs_dic2xflags(
8025                         flags |= XFS_XFLAG_PREALLOC;
8026                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
8027                         flags |= XFS_XFLAG_IMMUTABLE;
8028 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
8029 +                       flags |= XFS_XFLAG_IXUNLINK;
8030                 if (di_flags & XFS_DIFLAG_APPEND)
8031                         flags |= XFS_XFLAG_APPEND;
8032                 if (di_flags & XFS_DIFLAG_SYNC)
8033 @@ -747,6 +767,10 @@ _xfs_dic2xflags(
8034                         flags |= XFS_XFLAG_FILESTREAM;
8035         }
8036  
8037 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
8038 +               flags |= FS_BARRIER_FL;
8039 +       if (di_vflags & XFS_DIVFLAG_COW)
8040 +               flags |= FS_COW_FL;
8041         return flags;
8042  }
8043  
8044 @@ -756,7 +780,7 @@ xfs_ip2xflags(
8045  {
8046         xfs_icdinode_t          *dic = &ip->i_d;
8047  
8048 -       return _xfs_dic2xflags(dic->di_flags) |
8049 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
8050                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
8051  }
8052  
8053 @@ -764,7 +788,8 @@ uint
8054  xfs_dic2xflags(
8055         xfs_dinode_t            *dip)
8056  {
8057 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
8058 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
8059 +                               be16_to_cpu(dip->di_vflags)) |
8060                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
8061  }
8062  
8063 @@ -797,7 +822,6 @@ xfs_iread(
8064         if (error)
8065                 return error;
8066         dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);
8067 -
8068         /*
8069          * If we got something that isn't an inode it means someone
8070          * (nfs or dmi) has a stale handle.
8071 @@ -820,7 +844,8 @@ xfs_iread(
8072          * Otherwise, just get the truly permanent information.
8073          */
8074         if (dip->di_mode) {
8075 -               xfs_dinode_from_disk(&ip->i_d, dip);
8076 +               xfs_dinode_from_disk(&ip->i_d, dip,
8077 +                       mp->m_flags & XFS_MOUNT_TAGGED);
8078                 error = xfs_iformat(ip, dip);
8079                 if (error)  {
8080  #ifdef DEBUG
8081 @@ -1015,6 +1040,7 @@ xfs_ialloc(
8082         ASSERT(ip->i_d.di_nlink == nlink);
8083         ip->i_d.di_uid = current_fsuid();
8084         ip->i_d.di_gid = current_fsgid();
8085 +       ip->i_d.di_tag = current_fstag(&ip->i_vnode);
8086         xfs_set_projid(ip, prid);
8087         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
8088  
8089 @@ -1075,6 +1101,7 @@ xfs_ialloc(
8090         ip->i_d.di_dmevmask = 0;
8091         ip->i_d.di_dmstate = 0;
8092         ip->i_d.di_flags = 0;
8093 +       ip->i_d.di_vflags = 0;
8094         flags = XFS_ILOG_CORE;
8095         switch (mode & S_IFMT) {
8096         case S_IFIFO:
8097 @@ -2108,6 +2135,7 @@ xfs_ifree(
8098         }
8099         ip->i_d.di_mode = 0;            /* mark incore inode as free */
8100         ip->i_d.di_flags = 0;
8101 +       ip->i_d.di_vflags = 0;
8102         ip->i_d.di_dmevmask = 0;
8103         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
8104         ip->i_df.if_ext_max =
8105 @@ -2987,7 +3015,8 @@ xfs_iflush_int(
8106          * because if the inode is dirty at all the core must
8107          * be.
8108          */
8109 -       xfs_dinode_to_disk(dip, &ip->i_d);
8110 +       xfs_dinode_to_disk(dip, &ip->i_d,
8111 +               mp->m_flags & XFS_MOUNT_TAGGED);
8112  
8113         /* Wrap, we never let the log put out DI_MAX_FLUSH */
8114         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
8115 diff -NurpP --minimal linux-3.0-rc5/fs/xfs/xfs_inode.h linux-3.0-rc5-vs2.3.1-pre3/fs/xfs/xfs_inode.h
8116 --- linux-3.0-rc5/fs/xfs/xfs_inode.h    2011-07-01 11:14:20.000000000 +0200
8117 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/xfs/xfs_inode.h       2011-07-01 11:35:35.000000000 +0200
8118 @@ -135,7 +135,9 @@ typedef struct xfs_icdinode {
8119         __uint32_t      di_nlink;       /* number of links to file */
8120         __uint16_t      di_projid_lo;   /* lower part of owner's project id */
8121         __uint16_t      di_projid_hi;   /* higher part of owner's project id */
8122 -       __uint8_t       di_pad[6];      /* unused, zeroed space */
8123 +       __uint8_t       di_pad[2];      /* unused, zeroed space */
8124 +       __uint16_t      di_tag;         /* context tagging */
8125 +       __uint16_t      di_vflags;      /* vserver specific flags */
8126         __uint16_t      di_flushiter;   /* incremented on flush */
8127         xfs_ictimestamp_t di_atime;     /* time last accessed */
8128         xfs_ictimestamp_t di_mtime;     /* time last modified */
8129 @@ -546,7 +548,7 @@ int         xfs_itobp(struct xfs_mount *, struc
8130  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
8131                           struct xfs_inode *, uint);
8132  void           xfs_dinode_to_disk(struct xfs_dinode *,
8133 -                                  struct xfs_icdinode *);
8134 +                                  struct xfs_icdinode *, int);
8135  void           xfs_idestroy_fork(struct xfs_inode *, int);
8136  void           xfs_idata_realloc(struct xfs_inode *, int, int);
8137  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
8138 diff -NurpP --minimal linux-3.0-rc5/fs/xfs/xfs_itable.c linux-3.0-rc5-vs2.3.1-pre3/fs/xfs/xfs_itable.c
8139 --- linux-3.0-rc5/fs/xfs/xfs_itable.c   2011-05-22 16:17:54.000000000 +0200
8140 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/xfs/xfs_itable.c      2011-06-10 22:11:24.000000000 +0200
8141 @@ -98,6 +98,7 @@ xfs_bulkstat_one_int(
8142         buf->bs_mode = dic->di_mode;
8143         buf->bs_uid = dic->di_uid;
8144         buf->bs_gid = dic->di_gid;
8145 +       buf->bs_tag = dic->di_tag;
8146         buf->bs_size = dic->di_size;
8147  
8148         /*
8149 diff -NurpP --minimal linux-3.0-rc5/fs/xfs/xfs_log_recover.c linux-3.0-rc5-vs2.3.1-pre3/fs/xfs/xfs_log_recover.c
8150 --- linux-3.0-rc5/fs/xfs/xfs_log_recover.c      2011-07-01 11:14:20.000000000 +0200
8151 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/xfs/xfs_log_recover.c 2011-06-10 22:11:24.000000000 +0200
8152 @@ -2343,7 +2343,8 @@ xlog_recover_inode_pass2(
8153         }
8154  
8155         /* The core is in in-core format */
8156 -       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr);
8157 +       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr,
8158 +               mp->m_flags & XFS_MOUNT_TAGGED);
8159  
8160         /* the rest is in on-disk format */
8161         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
8162 diff -NurpP --minimal linux-3.0-rc5/fs/xfs/xfs_mount.h linux-3.0-rc5-vs2.3.1-pre3/fs/xfs/xfs_mount.h
8163 --- linux-3.0-rc5/fs/xfs/xfs_mount.h    2011-07-01 11:14:20.000000000 +0200
8164 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/xfs/xfs_mount.h       2011-06-10 22:11:24.000000000 +0200
8165 @@ -249,6 +249,7 @@ typedef struct xfs_mount {
8166                                                    allocator */
8167  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
8168  
8169 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
8170  
8171  /*
8172   * Default minimum read and write sizes.
8173 diff -NurpP --minimal linux-3.0-rc5/fs/xfs/xfs_vnodeops.c linux-3.0-rc5-vs2.3.1-pre3/fs/xfs/xfs_vnodeops.c
8174 --- linux-3.0-rc5/fs/xfs/xfs_vnodeops.c 2011-07-01 11:14:20.000000000 +0200
8175 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/xfs/xfs_vnodeops.c    2011-07-01 11:35:35.000000000 +0200
8176 @@ -50,6 +50,78 @@
8177  #include "xfs_vnodeops.h"
8178  #include "xfs_trace.h"
8179  
8180 +
8181 +STATIC void
8182 +xfs_get_inode_flags(
8183 +       xfs_inode_t     *ip)
8184 +{
8185 +       struct inode    *inode = VFS_I(ip);
8186 +       unsigned int    flags = inode->i_flags;
8187 +       unsigned int    vflags = inode->i_vflags;
8188 +
8189 +       if (flags & S_IMMUTABLE)
8190 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
8191 +       else
8192 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
8193 +       if (flags & S_IXUNLINK)
8194 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
8195 +       else
8196 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
8197 +
8198 +       if (vflags & V_BARRIER)
8199 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
8200 +       else
8201 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
8202 +       if (vflags & V_COW)
8203 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
8204 +       else
8205 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
8206 +}
8207 +
8208 +int
8209 +xfs_sync_flags(
8210 +       struct inode            *inode,
8211 +       int                     flags,
8212 +       int                     vflags)
8213 +{
8214 +       struct xfs_inode        *ip = XFS_I(inode);
8215 +       struct xfs_mount        *mp = ip->i_mount;
8216 +       struct xfs_trans        *tp;
8217 +       unsigned int            lock_flags = 0;
8218 +       int                     code;
8219 +
8220 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
8221 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
8222 +       if (code)
8223 +               goto error_out;
8224 +
8225 +       xfs_ilock(ip, XFS_ILOCK_EXCL);
8226 +
8227 +       xfs_trans_ijoin(tp, ip);
8228 +
8229 +       inode->i_flags = flags;
8230 +       inode->i_vflags = vflags;
8231 +       xfs_get_inode_flags(ip);
8232 +
8233 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
8234 +       xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
8235 +
8236 +       XFS_STATS_INC(xs_ig_attrchg);
8237 +
8238 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
8239 +               xfs_trans_set_sync(tp);
8240 +       code = xfs_trans_commit(tp, 0);
8241 +       xfs_iunlock(ip, XFS_ILOCK_EXCL);
8242 +       return code;
8243 +
8244 +error_out:
8245 +       xfs_trans_cancel(tp, 0);
8246 +       if (lock_flags)
8247 +               xfs_iunlock(ip, XFS_ILOCK_EXCL);
8248 +       return code;
8249 +}
8250 +
8251 +
8252  int
8253  xfs_setattr(
8254         struct xfs_inode        *ip,
8255 @@ -65,6 +137,7 @@ xfs_setattr(
8256         uint                    commit_flags=0;
8257         uid_t                   uid=0, iuid=0;
8258         gid_t                   gid=0, igid=0;
8259 +       tag_t                   tag=0, itag=0;
8260         struct xfs_dquot        *udqp, *gdqp, *olddquot1, *olddquot2;
8261         int                     need_iolock = 1;
8262  
8263 @@ -147,7 +220,7 @@ xfs_setattr(
8264         /*
8265          * Change file ownership.  Must be the owner or privileged.
8266          */
8267 -       if (mask & (ATTR_UID|ATTR_GID)) {
8268 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8269                 /*
8270                  * These IDs could have changed since we last looked at them.
8271                  * But, we're assured that if the ownership did change
8272 @@ -156,8 +229,10 @@ xfs_setattr(
8273                  */
8274                 iuid = ip->i_d.di_uid;
8275                 igid = ip->i_d.di_gid;
8276 +               itag = ip->i_d.di_tag;
8277                 gid = (mask & ATTR_GID) ? iattr->ia_gid : igid;
8278                 uid = (mask & ATTR_UID) ? iattr->ia_uid : iuid;
8279 +               tag = (mask & ATTR_TAG) ? iattr->ia_tag : itag;
8280  
8281                 /*
8282                  * Do a quota reservation only if uid/gid is actually
8283 @@ -165,7 +240,8 @@ xfs_setattr(
8284                  */
8285                 if (XFS_IS_QUOTA_RUNNING(mp) &&
8286                     ((XFS_IS_UQUOTA_ON(mp) && iuid != uid) ||
8287 -                    (XFS_IS_GQUOTA_ON(mp) && igid != gid))) {
8288 +                    (XFS_IS_GQUOTA_ON(mp) && igid != gid) ||
8289 +                    (XFS_IS_GQUOTA_ON(mp) && itag != tag))) {
8290                         ASSERT(tp);
8291                         code = xfs_qm_vop_chown_reserve(tp, ip, udqp, gdqp,
8292                                                 capable(CAP_FOWNER) ?
8293 @@ -329,7 +405,7 @@ xfs_setattr(
8294         /*
8295          * Change file ownership.  Must be the owner or privileged.
8296          */
8297 -       if (mask & (ATTR_UID|ATTR_GID)) {
8298 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8299                 /*
8300                  * CAP_FSETID overrides the following restrictions:
8301                  *
8302 @@ -345,6 +421,10 @@ xfs_setattr(
8303                  * Change the ownerships and register quota modifications
8304                  * in the transaction.
8305                  */
8306 +               if (itag != tag) {
8307 +                       ip->i_d.di_tag = tag;
8308 +                       inode->i_tag = tag;
8309 +               }
8310                 if (iuid != uid) {
8311                         if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_UQUOTA_ON(mp)) {
8312                                 ASSERT(mask & ATTR_UID);
8313 diff -NurpP --minimal linux-3.0-rc5/fs/xfs/xfs_vnodeops.h linux-3.0-rc5-vs2.3.1-pre3/fs/xfs/xfs_vnodeops.h
8314 --- linux-3.0-rc5/fs/xfs/xfs_vnodeops.h 2011-05-22 16:17:54.000000000 +0200
8315 +++ linux-3.0-rc5-vs2.3.1-pre3/fs/xfs/xfs_vnodeops.h    2011-06-10 22:11:24.000000000 +0200
8316 @@ -13,6 +13,7 @@ struct xfs_inode;
8317  struct xfs_iomap;
8318  
8319  
8320 +int xfs_sync_xflags(struct xfs_inode *ip);
8321  int xfs_setattr(struct xfs_inode *ip, struct iattr *vap, int flags);
8322  #define        XFS_ATTR_DMI            0x01    /* invocation from a DMI function */
8323  #define        XFS_ATTR_NONBLOCK       0x02    /* return EAGAIN if operation would block */
8324 diff -NurpP --minimal linux-3.0-rc5/include/asm-generic/tlb.h linux-3.0-rc5-vs2.3.1-pre3/include/asm-generic/tlb.h
8325 --- linux-3.0-rc5/include/asm-generic/tlb.h     2011-07-01 11:14:20.000000000 +0200
8326 +++ linux-3.0-rc5-vs2.3.1-pre3/include/asm-generic/tlb.h        2011-06-10 22:11:24.000000000 +0200
8327 @@ -16,6 +16,7 @@
8328  #define _ASM_GENERIC__TLB_H
8329  
8330  #include <linux/swap.h>
8331 +#include <linux/vs_memory.h>
8332  #include <asm/pgalloc.h>
8333  #include <asm/tlbflush.h>
8334  
8335 diff -NurpP --minimal linux-3.0-rc5/include/linux/Kbuild linux-3.0-rc5-vs2.3.1-pre3/include/linux/Kbuild
8336 --- linux-3.0-rc5/include/linux/Kbuild  2011-07-01 11:14:20.000000000 +0200
8337 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/Kbuild     2011-06-10 22:11:24.000000000 +0200
8338 @@ -17,6 +17,7 @@ header-y += netfilter_bridge/
8339  header-y += netfilter_ipv4/
8340  header-y += netfilter_ipv6/
8341  header-y += usb/
8342 +header-y += vserver/
8343  header-y += wimax/
8344  
8345  objhdr-y += version.h
8346 diff -NurpP --minimal linux-3.0-rc5/include/linux/capability.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/capability.h
8347 --- linux-3.0-rc5/include/linux/capability.h    2011-07-01 11:14:21.000000000 +0200
8348 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/capability.h       2011-06-10 22:11:24.000000000 +0200
8349 @@ -279,6 +279,7 @@ struct cpu_vfs_cap_data {
8350     arbitrary SCSI commands */
8351  /* Allow setting encryption key on loopback filesystem */
8352  /* Allow setting zone reclaim policy */
8353 +/* Allow the selection of a security context */
8354  
8355  #define CAP_SYS_ADMIN        21
8356  
8357 @@ -362,7 +363,12 @@ struct cpu_vfs_cap_data {
8358  
8359  #define CAP_LAST_CAP         CAP_WAKE_ALARM
8360  
8361 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
8362 +/* Allow context manipulations */
8363 +/* Allow changing context info on files */
8364 +
8365 +#define CAP_CONTEXT         63
8366 +
8367 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
8368  
8369  /*
8370   * Bit location of each capability (used by user-space library and kernel)
8371 diff -NurpP --minimal linux-3.0-rc5/include/linux/cred.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/cred.h
8372 --- linux-3.0-rc5/include/linux/cred.h  2011-07-01 11:14:21.000000000 +0200
8373 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/cred.h     2011-06-10 22:11:24.000000000 +0200
8374 @@ -156,6 +156,7 @@ extern void exit_creds(struct task_struc
8375  extern int copy_creds(struct task_struct *, unsigned long);
8376  extern const struct cred *get_task_cred(struct task_struct *);
8377  extern struct cred *cred_alloc_blank(void);
8378 +extern struct cred *__prepare_creds(const struct cred *);
8379  extern struct cred *prepare_creds(void);
8380  extern struct cred *prepare_exec_creds(void);
8381  extern int commit_creds(struct cred *);
8382 @@ -209,6 +210,31 @@ static inline void validate_process_cred
8383  }
8384  #endif
8385  
8386 +static inline void set_cred_subscribers(struct cred *cred, int n)
8387 +{
8388 +#ifdef CONFIG_DEBUG_CREDENTIALS
8389 +       atomic_set(&cred->subscribers, n);
8390 +#endif
8391 +}
8392 +
8393 +static inline int read_cred_subscribers(const struct cred *cred)
8394 +{
8395 +#ifdef CONFIG_DEBUG_CREDENTIALS
8396 +       return atomic_read(&cred->subscribers);
8397 +#else
8398 +       return 0;
8399 +#endif
8400 +}
8401 +
8402 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
8403 +{
8404 +#ifdef CONFIG_DEBUG_CREDENTIALS
8405 +       struct cred *cred = (struct cred *) _cred;
8406 +
8407 +       atomic_add(n, &cred->subscribers);
8408 +#endif
8409 +}
8410 +
8411  /**
8412   * get_new_cred - Get a reference on a new set of credentials
8413   * @cred: The new credentials to reference
8414 diff -NurpP --minimal linux-3.0-rc5/include/linux/devpts_fs.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/devpts_fs.h
8415 --- linux-3.0-rc5/include/linux/devpts_fs.h     2008-12-25 00:26:37.000000000 +0100
8416 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/devpts_fs.h        2011-06-10 22:11:24.000000000 +0200
8417 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
8418  
8419  #endif
8420  
8421 -
8422  #endif /* _LINUX_DEVPTS_FS_H */
8423 diff -NurpP --minimal linux-3.0-rc5/include/linux/ext2_fs.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/ext2_fs.h
8424 --- linux-3.0-rc5/include/linux/ext2_fs.h       2010-02-25 11:52:07.000000000 +0100
8425 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/ext2_fs.h  2011-06-10 22:11:24.000000000 +0200
8426 @@ -189,8 +189,12 @@ struct ext2_group_desc
8427  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
8428  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
8429  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
8430 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
8431  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
8432  
8433 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
8434 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
8435 +
8436  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
8437  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
8438  
8439 @@ -274,7 +278,8 @@ struct ext2_inode {
8440                         __u16   i_pad1;
8441                         __le16  l_i_uid_high;   /* these 2 fields    */
8442                         __le16  l_i_gid_high;   /* were reserved2[0] */
8443 -                       __u32   l_i_reserved2;
8444 +                       __le16  l_i_tag;        /* Context Tag */
8445 +                       __u16   l_i_reserved2;
8446                 } linux2;
8447                 struct {
8448                         __u8    h_i_frag;       /* Fragment number */
8449 @@ -303,6 +308,7 @@ struct ext2_inode {
8450  #define i_gid_low      i_gid
8451  #define i_uid_high     osd2.linux2.l_i_uid_high
8452  #define i_gid_high     osd2.linux2.l_i_gid_high
8453 +#define i_raw_tag      osd2.linux2.l_i_tag
8454  #define i_reserved2    osd2.linux2.l_i_reserved2
8455  #endif
8456  
8457 @@ -347,6 +353,7 @@ struct ext2_inode {
8458  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
8459  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
8460  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
8461 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
8462  
8463  
8464  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
8465 diff -NurpP --minimal linux-3.0-rc5/include/linux/ext3_fs.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/ext3_fs.h
8466 --- linux-3.0-rc5/include/linux/ext3_fs.h       2011-07-01 11:14:21.000000000 +0200
8467 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/ext3_fs.h  2011-06-10 22:11:24.000000000 +0200
8468 @@ -173,10 +173,14 @@ struct ext3_group_desc
8469  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
8470  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
8471  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
8472 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
8473  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
8474  
8475 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
8476 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
8477 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
8478 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
8479 +
8480 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
8481 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
8482  
8483  /* Flags that should be inherited by new inodes from their parent. */
8484  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
8485 @@ -312,7 +316,8 @@ struct ext3_inode {
8486                         __u16   i_pad1;
8487                         __le16  l_i_uid_high;   /* these 2 fields    */
8488                         __le16  l_i_gid_high;   /* were reserved2[0] */
8489 -                       __u32   l_i_reserved2;
8490 +                       __le16  l_i_tag;        /* Context Tag */
8491 +                       __u16   l_i_reserved2;
8492                 } linux2;
8493                 struct {
8494                         __u8    h_i_frag;       /* Fragment number */
8495 @@ -343,6 +348,7 @@ struct ext3_inode {
8496  #define i_gid_low      i_gid
8497  #define i_uid_high     osd2.linux2.l_i_uid_high
8498  #define i_gid_high     osd2.linux2.l_i_gid_high
8499 +#define i_raw_tag      osd2.linux2.l_i_tag
8500  #define i_reserved2    osd2.linux2.l_i_reserved2
8501  
8502  #elif defined(__GNU__)
8503 @@ -405,6 +411,7 @@ struct ext3_inode {
8504  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
8505  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
8506                                                   * error in ordered mode */
8507 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
8508  
8509  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
8510  #ifndef _LINUX_EXT2_FS_H
8511 @@ -919,6 +926,7 @@ extern void ext3_get_inode_flags(struct 
8512  extern void ext3_set_aops(struct inode *inode);
8513  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
8514                        u64 start, u64 len);
8515 +extern int ext3_sync_flags(struct inode *, int, int);
8516  
8517  /* ioctl.c */
8518  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
8519 diff -NurpP --minimal linux-3.0-rc5/include/linux/fs.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/fs.h
8520 --- linux-3.0-rc5/include/linux/fs.h    2011-07-01 11:14:21.000000000 +0200
8521 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/fs.h       2011-07-01 11:35:35.000000000 +0200
8522 @@ -208,6 +208,9 @@ struct inodes_stat_t {
8523  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
8524  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
8525  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
8526 +#define MS_TAGGED      (1<<25) /* use generic inode tagging */
8527 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
8528 +#define MS_NOTAGCHECK  (1<<27) /* don't check tags */
8529  #define MS_NOSEC       (1<<28)
8530  #define MS_BORN                (1<<29)
8531  #define MS_ACTIVE      (1<<30)
8532 @@ -239,6 +242,14 @@ struct inodes_stat_t {
8533  #define S_IMA          1024    /* Inode has an associated IMA struct */
8534  #define S_AUTOMOUNT    2048    /* Automount/referral quasi-directory */
8535  #define S_NOSEC                4096    /* no suid or xattr security attributes */
8536 +#define S_IXUNLINK     16384   /* Immutable Invert on unlink */
8537 +
8538 +/* Linux-VServer related Inode flags */
8539 +
8540 +#define V_VALID                1
8541 +#define V_XATTR                2
8542 +#define V_BARRIER      4       /* Barrier for chroot() */
8543 +#define V_COW          8       /* Copy on Write */
8544  
8545  /*
8546   * Note that nosuid etc flags are inode-specific: setting some file-system
8547 @@ -261,12 +272,15 @@ struct inodes_stat_t {
8548  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
8549                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
8550  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
8551 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8552 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
8553 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8554 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
8555 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
8556  
8557  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
8558  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
8559  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
8560 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
8561 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
8562  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
8563  
8564  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
8565 @@ -277,6 +291,16 @@ struct inodes_stat_t {
8566  #define IS_AUTOMOUNT(inode)    ((inode)->i_flags & S_AUTOMOUNT)
8567  #define IS_NOSEC(inode)                ((inode)->i_flags & S_NOSEC)
8568  
8569 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
8570 +
8571 +#ifdef CONFIG_VSERVER_COWBL
8572 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
8573 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
8574 +#else
8575 +#  define IS_COW(inode)                (0)
8576 +#  define IS_COW_LINK(inode)   (0)
8577 +#endif
8578 +
8579  /* the read-only stuff doesn't really belong here, but any other place is
8580     probably as bad and I don't want to create yet another include file. */
8581  
8582 @@ -362,11 +386,14 @@ struct inodes_stat_t {
8583  #define FS_EXTENT_FL                   0x00080000 /* Extents */
8584  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
8585  #define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
8586 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
8587  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
8588  
8589 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
8590 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
8591 -
8592 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
8593 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
8594 +
8595 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
8596 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
8597  
8598  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
8599  #define SYNC_FILE_RANGE_WRITE          2
8600 @@ -447,6 +474,7 @@ typedef void (dio_iodone_t)(struct kiocb
8601  #define ATTR_KILL_PRIV (1 << 14)
8602  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
8603  #define ATTR_TIMES_SET (1 << 16)
8604 +#define ATTR_TAG       (1 << 17)
8605  
8606  /*
8607   * This is the Inode Attributes structure, used for notify_change().  It
8608 @@ -462,6 +490,7 @@ struct iattr {
8609         umode_t         ia_mode;
8610         uid_t           ia_uid;
8611         gid_t           ia_gid;
8612 +       tag_t           ia_tag;
8613         loff_t          ia_size;
8614         struct timespec ia_atime;
8615         struct timespec ia_mtime;
8616 @@ -475,6 +504,9 @@ struct iattr {
8617         struct file     *ia_file;
8618  };
8619  
8620 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
8621 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
8622 +
8623  /*
8624   * Includes for diskquotas.
8625   */
8626 @@ -740,11 +772,13 @@ struct inode {
8627         umode_t                 i_mode;
8628         uid_t                   i_uid;
8629         gid_t                   i_gid;
8630 +       tag_t                   i_tag;
8631         const struct inode_operations   *i_op;
8632         struct super_block      *i_sb;
8633  
8634         spinlock_t              i_lock; /* i_blocks, i_bytes, maybe i_size */
8635 -       unsigned int            i_flags;
8636 +       unsigned short          i_flags;
8637 +       unsigned short          i_vflags;
8638         unsigned long           i_state;
8639  #ifdef CONFIG_SECURITY
8640         void                    *i_security;
8641 @@ -766,6 +800,7 @@ struct inode {
8642         atomic_t                i_count;
8643         unsigned int            i_nlink;
8644         dev_t                   i_rdev;
8645 +       dev_t                   i_mdev;
8646         unsigned int            i_blkbits;
8647         u64                     i_version;
8648         loff_t                  i_size;
8649 @@ -890,12 +925,12 @@ static inline void i_size_write(struct i
8650  
8651  static inline unsigned iminor(const struct inode *inode)
8652  {
8653 -       return MINOR(inode->i_rdev);
8654 +       return MINOR(inode->i_mdev);
8655  }
8656  
8657  static inline unsigned imajor(const struct inode *inode)
8658  {
8659 -       return MAJOR(inode->i_rdev);
8660 +       return MAJOR(inode->i_mdev);
8661  }
8662  
8663  extern struct block_device *I_BDEV(struct inode *inode);
8664 @@ -957,6 +992,7 @@ struct file {
8665         loff_t                  f_pos;
8666         struct fown_struct      f_owner;
8667         const struct cred       *f_cred;
8668 +       xid_t                   f_xid;
8669         struct file_ra_state    f_ra;
8670  
8671         u64                     f_version;
8672 @@ -1101,6 +1137,7 @@ struct file_lock {
8673         struct file *fl_file;
8674         loff_t fl_start;
8675         loff_t fl_end;
8676 +       xid_t fl_xid;
8677  
8678         struct fasync_struct *  fl_fasync; /* for lease break notifications */
8679         unsigned long fl_break_time;    /* for nonblocking lease breaks */
8680 @@ -1600,6 +1637,7 @@ struct inode_operations {
8681         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
8682         ssize_t (*listxattr) (struct dentry *, char *, size_t);
8683         int (*removexattr) (struct dentry *, const char *);
8684 +       int (*sync_flags) (struct inode *, int, int);
8685         void (*truncate_range)(struct inode *, loff_t, loff_t);
8686         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
8687                       u64 len);
8688 @@ -1618,6 +1656,7 @@ extern ssize_t vfs_readv(struct file *, 
8689                 unsigned long, loff_t *);
8690  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
8691                 unsigned long, loff_t *);
8692 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
8693  
8694  struct super_operations {
8695         struct inode *(*alloc_inode)(struct super_block *sb);
8696 @@ -2437,6 +2476,7 @@ extern int dcache_dir_open(struct inode 
8697  extern int dcache_dir_close(struct inode *, struct file *);
8698  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
8699  extern int dcache_readdir(struct file *, void *, filldir_t);
8700 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
8701  extern int simple_setattr(struct dentry *, struct iattr *);
8702  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
8703  extern int simple_statfs(struct dentry *, struct kstatfs *);
8704 diff -NurpP --minimal linux-3.0-rc5/include/linux/gfs2_ondisk.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/gfs2_ondisk.h
8705 --- linux-3.0-rc5/include/linux/gfs2_ondisk.h   2010-07-07 18:31:55.000000000 +0200
8706 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/gfs2_ondisk.h      2011-06-10 22:11:24.000000000 +0200
8707 @@ -211,6 +211,9 @@ enum {
8708         gfs2fl_NoAtime          = 7,
8709         gfs2fl_Sync             = 8,
8710         gfs2fl_System           = 9,
8711 +       gfs2fl_IXUnlink         = 16,
8712 +       gfs2fl_Barrier          = 17,
8713 +       gfs2fl_Cow              = 18,
8714         gfs2fl_TruncInProg      = 29,
8715         gfs2fl_InheritDirectio  = 30,
8716         gfs2fl_InheritJdata     = 31,
8717 @@ -227,6 +230,9 @@ enum {
8718  #define GFS2_DIF_NOATIME               0x00000080
8719  #define GFS2_DIF_SYNC                  0x00000100
8720  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
8721 +#define GFS2_DIF_IXUNLINK              0x00010000
8722 +#define GFS2_DIF_BARRIER               0x00020000
8723 +#define GFS2_DIF_COW                   0x00040000
8724  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
8725  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000
8726  #define GFS2_DIF_INHERIT_JDATA         0x80000000
8727 diff -NurpP --minimal linux-3.0-rc5/include/linux/if_tun.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/if_tun.h
8728 --- linux-3.0-rc5/include/linux/if_tun.h        2010-08-02 16:52:54.000000000 +0200
8729 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/if_tun.h   2011-06-10 22:11:24.000000000 +0200
8730 @@ -53,6 +53,7 @@
8731  #define TUNDETACHFILTER _IOW('T', 214, struct sock_fprog)
8732  #define TUNGETVNETHDRSZ _IOR('T', 215, int)
8733  #define TUNSETVNETHDRSZ _IOW('T', 216, int)
8734 +#define TUNSETNID     _IOW('T', 217, int)
8735  
8736  /* TUNSETIFF ifr flags */
8737  #define IFF_TUN                0x0001
8738 diff -NurpP --minimal linux-3.0-rc5/include/linux/init_task.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/init_task.h
8739 --- linux-3.0-rc5/include/linux/init_task.h     2011-07-01 11:14:21.000000000 +0200
8740 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/init_task.h        2011-06-10 22:11:24.000000000 +0200
8741 @@ -193,6 +193,10 @@ extern struct cred init_cred;
8742         INIT_FTRACE_GRAPH                                               \
8743         INIT_TRACE_RECURSION                                            \
8744         INIT_TASK_RCU_PREEMPT(tsk)                                      \
8745 +       .xid            = 0,                                            \
8746 +       .vx_info        = NULL,                                         \
8747 +       .nid            = 0,                                            \
8748 +       .nx_info        = NULL,                                         \
8749  }
8750  
8751  
8752 diff -NurpP --minimal linux-3.0-rc5/include/linux/ipc.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/ipc.h
8753 --- linux-3.0-rc5/include/linux/ipc.h   2009-12-03 20:02:55.000000000 +0100
8754 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/ipc.h      2011-06-10 22:11:24.000000000 +0200
8755 @@ -91,6 +91,7 @@ struct kern_ipc_perm
8756         key_t           key;
8757         uid_t           uid;
8758         gid_t           gid;
8759 +       xid_t           xid;
8760         uid_t           cuid;
8761         gid_t           cgid;
8762         mode_t          mode; 
8763 diff -NurpP --minimal linux-3.0-rc5/include/linux/ipc_namespace.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/ipc_namespace.h
8764 --- linux-3.0-rc5/include/linux/ipc_namespace.h 2011-05-22 16:17:55.000000000 +0200
8765 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/ipc_namespace.h    2011-06-13 14:09:44.000000000 +0200
8766 @@ -94,7 +94,8 @@ static inline int mq_init_ns(struct ipc_
8767  
8768  #if defined(CONFIG_IPC_NS)
8769  extern struct ipc_namespace *copy_ipcs(unsigned long flags,
8770 -                                      struct task_struct *tsk);
8771 +                                      struct ipc_namespace *old_ns,
8772 +                                      struct user_namespace *user_ns);
8773  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
8774  {
8775         if (ns)
8776 @@ -105,12 +106,13 @@ static inline struct ipc_namespace *get_
8777  extern void put_ipc_ns(struct ipc_namespace *ns);
8778  #else
8779  static inline struct ipc_namespace *copy_ipcs(unsigned long flags,
8780 -                                             struct task_struct *tsk)
8781 +                                             struct ipc_namespace *old_ns,
8782 +                                             struct user_namespace *user_ns)
8783  {
8784         if (flags & CLONE_NEWIPC)
8785                 return ERR_PTR(-EINVAL);
8786  
8787 -       return tsk->nsproxy->ipc_ns;
8788 +       return old_ns;
8789  }
8790  
8791  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
8792 diff -NurpP --minimal linux-3.0-rc5/include/linux/loop.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/loop.h
8793 --- linux-3.0-rc5/include/linux/loop.h  2009-09-10 15:26:25.000000000 +0200
8794 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/loop.h     2011-06-10 22:11:24.000000000 +0200
8795 @@ -45,6 +45,7 @@ struct loop_device {
8796         struct loop_func_table *lo_encryption;
8797         __u32           lo_init[2];
8798         uid_t           lo_key_owner;   /* Who set the key */
8799 +       xid_t           lo_xid;
8800         int             (*ioctl)(struct loop_device *, int cmd, 
8801                                  unsigned long arg); 
8802  
8803 diff -NurpP --minimal linux-3.0-rc5/include/linux/magic.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/magic.h
8804 --- linux-3.0-rc5/include/linux/magic.h 2011-05-22 16:17:55.000000000 +0200
8805 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/magic.h    2011-06-10 22:11:24.000000000 +0200
8806 @@ -3,7 +3,7 @@
8807  
8808  #define ADFS_SUPER_MAGIC       0xadf5
8809  #define AFFS_SUPER_MAGIC       0xadff
8810 -#define AFS_SUPER_MAGIC                0x5346414F
8811 +#define AFS_SUPER_MAGIC                0x5346414F
8812  #define AUTOFS_SUPER_MAGIC     0x0187
8813  #define CODA_SUPER_MAGIC       0x73757245
8814  #define CRAMFS_MAGIC           0x28cd3d45      /* some random number */
8815 @@ -41,6 +41,7 @@
8816  #define NFS_SUPER_MAGIC                0x6969
8817  #define OPENPROM_SUPER_MAGIC   0x9fa1
8818  #define PROC_SUPER_MAGIC       0x9fa0
8819 +#define DEVPTS_SUPER_MAGIC     0x1cd1
8820  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
8821  
8822  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
8823 diff -NurpP --minimal linux-3.0-rc5/include/linux/major.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/major.h
8824 --- linux-3.0-rc5/include/linux/major.h 2009-09-10 15:26:25.000000000 +0200
8825 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/major.h    2011-06-10 22:11:24.000000000 +0200
8826 @@ -15,6 +15,7 @@
8827  #define HD_MAJOR               IDE0_MAJOR
8828  #define PTY_SLAVE_MAJOR                3
8829  #define TTY_MAJOR              4
8830 +#define VROOT_MAJOR            4
8831  #define TTYAUX_MAJOR           5
8832  #define LP_MAJOR               6
8833  #define VCS_MAJOR              7
8834 diff -NurpP --minimal linux-3.0-rc5/include/linux/memcontrol.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/memcontrol.h
8835 --- linux-3.0-rc5/include/linux/memcontrol.h    2011-07-01 11:14:21.000000000 +0200
8836 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/memcontrol.h       2011-06-22 12:39:15.000000000 +0200
8837 @@ -86,6 +86,13 @@ extern struct mem_cgroup *try_get_mem_cg
8838  extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
8839  extern struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm);
8840  
8841 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
8842 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
8843 +
8844 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
8845 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
8846 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
8847 +
8848  static inline
8849  int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
8850  {
8851 diff -NurpP --minimal linux-3.0-rc5/include/linux/mm_types.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/mm_types.h
8852 --- linux-3.0-rc5/include/linux/mm_types.h      2011-07-01 11:14:21.000000000 +0200
8853 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/mm_types.h 2011-06-10 22:11:24.000000000 +0200
8854 @@ -268,6 +268,7 @@ struct mm_struct {
8855  
8856         /* Architecture-specific MM context */
8857         mm_context_t context;
8858 +       struct vx_info *mm_vx_info;
8859  
8860         /* Swap token stuff */
8861         /*
8862 diff -NurpP --minimal linux-3.0-rc5/include/linux/mmzone.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/mmzone.h
8863 --- linux-3.0-rc5/include/linux/mmzone.h        2011-07-01 11:14:21.000000000 +0200
8864 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/mmzone.h   2011-07-01 11:35:35.000000000 +0200
8865 @@ -654,6 +654,13 @@ typedef struct pglist_data {
8866         __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
8867  })
8868  
8869 +#define node_start_pfn(nid)    (NODE_DATA(nid)->node_start_pfn)
8870 +
8871 +#define node_end_pfn(nid) ({\
8872 +       pg_data_t *__pgdat = NODE_DATA(nid);\
8873 +       __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
8874 +})
8875 +
8876  #include <linux/memory_hotplug.h>
8877  
8878  extern struct mutex zonelists_mutex;
8879 diff -NurpP --minimal linux-3.0-rc5/include/linux/mount.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/mount.h
8880 --- linux-3.0-rc5/include/linux/mount.h 2011-03-15 18:07:39.000000000 +0100
8881 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/mount.h    2011-06-10 22:11:24.000000000 +0200
8882 @@ -52,6 +52,9 @@ struct mnt_pcp {
8883         int mnt_writers;
8884  };
8885  
8886 +#define MNT_TAGID      0x10000
8887 +#define MNT_NOTAG      0x20000
8888 +
8889  struct vfsmount {
8890         struct list_head mnt_hash;
8891         struct vfsmount *mnt_parent;    /* fs we are mounted on */
8892 @@ -86,6 +89,7 @@ struct vfsmount {
8893         int mnt_expiry_mark;            /* true if marked for expiry */
8894         int mnt_pinned;
8895         int mnt_ghosts;
8896 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
8897  };
8898  
8899  struct file; /* forward dec */
8900 diff -NurpP --minimal linux-3.0-rc5/include/linux/net.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/net.h
8901 --- linux-3.0-rc5/include/linux/net.h   2011-07-01 11:14:21.000000000 +0200
8902 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/net.h      2011-06-10 22:11:24.000000000 +0200
8903 @@ -72,6 +72,7 @@ struct net;
8904  #define SOCK_NOSPACE           2
8905  #define SOCK_PASSCRED          3
8906  #define SOCK_PASSSEC           4
8907 +#define SOCK_USER_SOCKET       5
8908  
8909  #ifndef ARCH_HAS_SOCKET_TYPES
8910  /**
8911 diff -NurpP --minimal linux-3.0-rc5/include/linux/nfs_mount.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/nfs_mount.h
8912 --- linux-3.0-rc5/include/linux/nfs_mount.h     2011-01-05 21:50:31.000000000 +0100
8913 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/nfs_mount.h        2011-06-10 22:11:24.000000000 +0200
8914 @@ -63,7 +63,8 @@ struct nfs_mount_data {
8915  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
8916  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
8917  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
8918 -#define NFS_MOUNT_FLAGMASK     0xFFFF
8919 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
8920 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
8921  
8922  /* The following are for internal use only */
8923  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
8924 diff -NurpP --minimal linux-3.0-rc5/include/linux/nsproxy.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/nsproxy.h
8925 --- linux-3.0-rc5/include/linux/nsproxy.h       2011-07-01 11:14:21.000000000 +0200
8926 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/nsproxy.h  2011-06-10 22:11:24.000000000 +0200
8927 @@ -3,6 +3,7 @@
8928  
8929  #include <linux/spinlock.h>
8930  #include <linux/sched.h>
8931 +#include <linux/vserver/debug.h>
8932  
8933  struct mnt_namespace;
8934  struct uts_namespace;
8935 @@ -63,22 +64,33 @@ static inline struct nsproxy *task_nspro
8936  }
8937  
8938  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
8939 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
8940  void exit_task_namespaces(struct task_struct *tsk);
8941  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
8942  void free_nsproxy(struct nsproxy *ns);
8943  int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
8944         struct fs_struct *);
8945  
8946 -static inline void put_nsproxy(struct nsproxy *ns)
8947 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
8948 +
8949 +static inline void __get_nsproxy(struct nsproxy *ns,
8950 +       const char *_file, int _line)
8951  {
8952 -       if (atomic_dec_and_test(&ns->count)) {
8953 -               free_nsproxy(ns);
8954 -       }
8955 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
8956 +               ns, atomic_read(&ns->count), _file, _line);
8957 +       atomic_inc(&ns->count);
8958  }
8959  
8960 -static inline void get_nsproxy(struct nsproxy *ns)
8961 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
8962 +
8963 +static inline void __put_nsproxy(struct nsproxy *ns,
8964 +       const char *_file, int _line)
8965  {
8966 -       atomic_inc(&ns->count);
8967 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
8968 +               ns, atomic_read(&ns->count), _file, _line);
8969 +       if (atomic_dec_and_test(&ns->count)) {
8970 +               free_nsproxy(ns);
8971 +       }
8972  }
8973  
8974  #endif
8975 diff -NurpP --minimal linux-3.0-rc5/include/linux/pid.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/pid.h
8976 --- linux-3.0-rc5/include/linux/pid.h   2011-07-01 11:14:21.000000000 +0200
8977 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/pid.h      2011-06-10 22:11:24.000000000 +0200
8978 @@ -8,7 +8,8 @@ enum pid_type
8979         PIDTYPE_PID,
8980         PIDTYPE_PGID,
8981         PIDTYPE_SID,
8982 -       PIDTYPE_MAX
8983 +       PIDTYPE_MAX,
8984 +       PIDTYPE_REALPID
8985  };
8986  
8987  /*
8988 @@ -171,6 +172,7 @@ static inline pid_t pid_nr(struct pid *p
8989  }
8990  
8991  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
8992 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
8993  pid_t pid_vnr(struct pid *pid);
8994  
8995  #define do_each_pid_task(pid, type, task)                              \
8996 diff -NurpP --minimal linux-3.0-rc5/include/linux/proc_fs.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/proc_fs.h
8997 --- linux-3.0-rc5/include/linux/proc_fs.h       2011-07-01 11:14:21.000000000 +0200
8998 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/proc_fs.h  2011-06-10 22:11:24.000000000 +0200
8999 @@ -56,6 +56,7 @@ struct proc_dir_entry {
9000         nlink_t nlink;
9001         uid_t uid;
9002         gid_t gid;
9003 +       int vx_flags;
9004         loff_t size;
9005         const struct inode_operations *proc_iops;
9006         /*
9007 @@ -252,12 +253,18 @@ extern const struct proc_ns_operations n
9008  extern const struct proc_ns_operations utsns_operations;
9009  extern const struct proc_ns_operations ipcns_operations;
9010  
9011 +struct vx_info;
9012 +struct nx_info;
9013 +
9014  union proc_op {
9015         int (*proc_get_link)(struct inode *, struct path *);
9016         int (*proc_read)(struct task_struct *task, char *page);
9017         int (*proc_show)(struct seq_file *m,
9018                 struct pid_namespace *ns, struct pid *pid,
9019                 struct task_struct *task);
9020 +       int (*proc_vs_read)(char *page);
9021 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
9022 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
9023  };
9024  
9025  struct ctl_table_header;
9026 @@ -265,6 +272,7 @@ struct ctl_table;
9027  
9028  struct proc_inode {
9029         struct pid *pid;
9030 +       int vx_flags;
9031         int fd;
9032         union proc_op op;
9033         struct proc_dir_entry *pde;
9034 diff -NurpP --minimal linux-3.0-rc5/include/linux/quotaops.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/quotaops.h
9035 --- linux-3.0-rc5/include/linux/quotaops.h      2011-05-22 16:17:57.000000000 +0200
9036 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/quotaops.h 2011-06-10 22:11:24.000000000 +0200
9037 @@ -8,6 +8,7 @@
9038  #define _LINUX_QUOTAOPS_
9039  
9040  #include <linux/fs.h>
9041 +#include <linux/vs_dlimit.h>
9042  
9043  #define DQUOT_SPACE_WARN       0x1
9044  #define DQUOT_SPACE_RESERVE    0x2
9045 @@ -204,11 +205,12 @@ static inline void dquot_drop(struct ino
9046  
9047  static inline int dquot_alloc_inode(const struct inode *inode)
9048  {
9049 -       return 0;
9050 +       return dl_alloc_inode(inode);
9051  }
9052  
9053  static inline void dquot_free_inode(const struct inode *inode)
9054  {
9055 +       dl_free_inode(inode);
9056  }
9057  
9058  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
9059 @@ -219,6 +221,10 @@ static inline int dquot_transfer(struct 
9060  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
9061                 int flags)
9062  {
9063 +       int ret = 0;
9064 +
9065 +       if ((ret = dl_alloc_space(inode, number)))
9066 +               return ret;
9067         if (!(flags & DQUOT_SPACE_RESERVE))
9068                 inode_add_bytes(inode, number);
9069         return 0;
9070 @@ -229,6 +235,7 @@ static inline void __dquot_free_space(st
9071  {
9072         if (!(flags & DQUOT_SPACE_RESERVE))
9073                 inode_sub_bytes(inode, number);
9074 +       dl_free_space(inode, number);
9075  }
9076  
9077  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
9078 diff -NurpP --minimal linux-3.0-rc5/include/linux/reboot.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/reboot.h
9079 --- linux-3.0-rc5/include/linux/reboot.h        2010-07-07 18:31:56.000000000 +0200
9080 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/reboot.h   2011-06-10 22:11:24.000000000 +0200
9081 @@ -33,6 +33,7 @@
9082  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
9083  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
9084  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
9085 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
9086  
9087  
9088  #ifdef __KERNEL__
9089 diff -NurpP --minimal linux-3.0-rc5/include/linux/reiserfs_fs.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/reiserfs_fs.h
9090 --- linux-3.0-rc5/include/linux/reiserfs_fs.h   2011-05-22 16:17:58.000000000 +0200
9091 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/reiserfs_fs.h      2011-06-10 22:11:24.000000000 +0200
9092 @@ -976,6 +976,11 @@ struct stat_data_v1 {
9093  #define REISERFS_COMPR_FL     FS_COMPR_FL
9094  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
9095  
9096 +/* unfortunately reiserfs sdattr is only 16 bit */
9097 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
9098 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
9099 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
9100 +
9101  /* persistent flags that file inherits from the parent directory */
9102  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
9103                                 REISERFS_SYNC_FL |      \
9104 @@ -985,6 +990,9 @@ struct stat_data_v1 {
9105                                 REISERFS_COMPR_FL |     \
9106                                 REISERFS_NOTAIL_FL )
9107  
9108 +#define REISERFS_FL_USER_VISIBLE       0x80FF
9109 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
9110 +
9111  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
9112     address blocks) */
9113  struct stat_data {
9114 @@ -2073,6 +2081,7 @@ static inline void reiserfs_update_sd(st
9115  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
9116  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
9117  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
9118 +int reiserfs_sync_flags(struct inode *inode, int, int);
9119  
9120  int __reiserfs_write_begin(struct page *page, unsigned from, unsigned len);
9121  
9122 diff -NurpP --minimal linux-3.0-rc5/include/linux/reiserfs_fs_sb.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/reiserfs_fs_sb.h
9123 --- linux-3.0-rc5/include/linux/reiserfs_fs_sb.h        2010-02-25 11:52:07.000000000 +0100
9124 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/reiserfs_fs_sb.h   2011-06-10 22:11:24.000000000 +0200
9125 @@ -476,6 +476,7 @@ enum reiserfs_mount_options {
9126         REISERFS_EXPOSE_PRIVROOT,
9127         REISERFS_BARRIER_NONE,
9128         REISERFS_BARRIER_FLUSH,
9129 +       REISERFS_TAGGED,
9130  
9131         /* Actions on error */
9132         REISERFS_ERROR_PANIC,
9133 diff -NurpP --minimal linux-3.0-rc5/include/linux/sched.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/sched.h
9134 --- linux-3.0-rc5/include/linux/sched.h 2011-07-01 11:14:21.000000000 +0200
9135 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/sched.h    2011-06-15 02:40:14.000000000 +0200
9136 @@ -1397,6 +1397,14 @@ struct task_struct {
9137  #endif
9138         seccomp_t seccomp;
9139  
9140 +/* vserver context data */
9141 +       struct vx_info *vx_info;
9142 +       struct nx_info *nx_info;
9143 +
9144 +       xid_t xid;
9145 +       nid_t nid;
9146 +       tag_t tag;
9147 +
9148  /* Thread group tracking */
9149         u32 parent_exec_id;
9150         u32 self_exec_id;
9151 @@ -1640,6 +1648,11 @@ struct pid_namespace;
9152  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
9153                         struct pid_namespace *ns);
9154  
9155 +#include <linux/vserver/base.h>
9156 +#include <linux/vserver/context.h>
9157 +#include <linux/vserver/debug.h>
9158 +#include <linux/vserver/pid.h>
9159 +
9160  static inline pid_t task_pid_nr(struct task_struct *tsk)
9161  {
9162         return tsk->pid;
9163 @@ -1653,7 +1666,8 @@ static inline pid_t task_pid_nr_ns(struc
9164  
9165  static inline pid_t task_pid_vnr(struct task_struct *tsk)
9166  {
9167 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
9168 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
9169 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
9170  }
9171  
9172  
9173 @@ -1666,7 +1680,7 @@ pid_t task_tgid_nr_ns(struct task_struct
9174  
9175  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
9176  {
9177 -       return pid_vnr(task_tgid(tsk));
9178 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
9179  }
9180  
9181  
9182 diff -NurpP --minimal linux-3.0-rc5/include/linux/shmem_fs.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/shmem_fs.h
9183 --- linux-3.0-rc5/include/linux/shmem_fs.h      2011-07-01 11:14:21.000000000 +0200
9184 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/shmem_fs.h 2011-07-01 11:35:35.000000000 +0200
9185 @@ -12,6 +12,9 @@
9186  
9187  #define SHMEM_SYMLINK_INLINE_LEN (SHMEM_NR_DIRECT * sizeof(swp_entry_t))
9188  
9189 +#define TMPFS_SUPER_MAGIC      0x01021994
9190 +
9191 +
9192  struct shmem_inode_info {
9193         spinlock_t              lock;
9194         unsigned long           flags;
9195 diff -NurpP --minimal linux-3.0-rc5/include/linux/stat.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/stat.h
9196 --- linux-3.0-rc5/include/linux/stat.h  2008-12-25 00:26:37.000000000 +0100
9197 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/stat.h     2011-06-10 22:11:24.000000000 +0200
9198 @@ -66,6 +66,7 @@ struct kstat {
9199         unsigned int    nlink;
9200         uid_t           uid;
9201         gid_t           gid;
9202 +       tag_t           tag;
9203         dev_t           rdev;
9204         loff_t          size;
9205         struct timespec  atime;
9206 diff -NurpP --minimal linux-3.0-rc5/include/linux/sunrpc/auth.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/sunrpc/auth.h
9207 --- linux-3.0-rc5/include/linux/sunrpc/auth.h   2011-03-15 18:07:39.000000000 +0100
9208 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/sunrpc/auth.h      2011-06-10 22:11:24.000000000 +0200
9209 @@ -25,6 +25,7 @@
9210  struct auth_cred {
9211         uid_t   uid;
9212         gid_t   gid;
9213 +       tag_t   tag;
9214         struct group_info *group_info;
9215         unsigned char machine_cred : 1;
9216  };
9217 diff -NurpP --minimal linux-3.0-rc5/include/linux/sunrpc/clnt.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/sunrpc/clnt.h
9218 --- linux-3.0-rc5/include/linux/sunrpc/clnt.h   2011-05-22 16:17:58.000000000 +0200
9219 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/sunrpc/clnt.h      2011-06-10 22:11:24.000000000 +0200
9220 @@ -49,7 +49,8 @@ struct rpc_clnt {
9221         unsigned int            cl_softrtry : 1,/* soft timeouts */
9222                                 cl_discrtry : 1,/* disconnect before retry */
9223                                 cl_autobind : 1,/* use getport() */
9224 -                               cl_chatty   : 1;/* be verbose */
9225 +                               cl_chatty   : 1,/* be verbose */
9226 +                               cl_tag      : 1;/* context tagging */
9227  
9228         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
9229         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
9230 diff -NurpP --minimal linux-3.0-rc5/include/linux/syscalls.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/syscalls.h
9231 --- linux-3.0-rc5/include/linux/syscalls.h      2011-07-01 11:14:22.000000000 +0200
9232 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/syscalls.h 2011-06-10 22:11:24.000000000 +0200
9233 @@ -483,6 +483,8 @@ asmlinkage long sys_symlink(const char _
9234  asmlinkage long sys_unlink(const char __user *pathname);
9235  asmlinkage long sys_rename(const char __user *oldname,
9236                                 const char __user *newname);
9237 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
9238 +                               umode_t mode);
9239  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
9240  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
9241  
9242 diff -NurpP --minimal linux-3.0-rc5/include/linux/sysctl.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/sysctl.h
9243 --- linux-3.0-rc5/include/linux/sysctl.h        2011-03-15 18:07:40.000000000 +0100
9244 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/sysctl.h   2011-06-10 22:11:24.000000000 +0200
9245 @@ -60,6 +60,7 @@ enum
9246         CTL_ABI=9,              /* Binary emulation */
9247         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
9248         CTL_ARLAN=254,          /* arlan wireless driver */
9249 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
9250         CTL_S390DBF=5677,       /* s390 debug */
9251         CTL_SUNRPC=7249,        /* sunrpc debug */
9252         CTL_PM=9899,            /* frv power management */
9253 @@ -94,6 +95,7 @@ enum
9254  
9255         KERN_PANIC=15,          /* int: panic timeout */
9256         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
9257 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
9258  
9259         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
9260         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
9261 diff -NurpP --minimal linux-3.0-rc5/include/linux/sysfs.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/sysfs.h
9262 --- linux-3.0-rc5/include/linux/sysfs.h 2011-07-01 11:14:22.000000000 +0200
9263 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/sysfs.h    2011-06-22 12:39:15.000000000 +0200
9264 @@ -19,6 +19,8 @@
9265  #include <linux/kobject_ns.h>
9266  #include <asm/atomic.h>
9267  
9268 +#define SYSFS_SUPER_MAGIC      0x62656572
9269 +
9270  struct kobject;
9271  struct module;
9272  enum kobj_ns_type;
9273 diff -NurpP --minimal linux-3.0-rc5/include/linux/time.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/time.h
9274 --- linux-3.0-rc5/include/linux/time.h  2011-07-01 11:14:22.000000000 +0200
9275 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/time.h     2011-06-10 22:11:24.000000000 +0200
9276 @@ -256,6 +256,9 @@ static __always_inline void timespec_add
9277         a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
9278         a->tv_nsec = ns;
9279  }
9280 +
9281 +#include <linux/vs_time.h>
9282 +
9283  #endif /* __KERNEL__ */
9284  
9285  #define NFDBITS                        __NFDBITS
9286 diff -NurpP --minimal linux-3.0-rc5/include/linux/types.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/types.h
9287 --- linux-3.0-rc5/include/linux/types.h 2011-05-22 16:17:58.000000000 +0200
9288 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/types.h    2011-06-10 22:11:24.000000000 +0200
9289 @@ -40,6 +40,9 @@ typedef __kernel_uid32_t      uid_t;
9290  typedef __kernel_gid32_t       gid_t;
9291  typedef __kernel_uid16_t        uid16_t;
9292  typedef __kernel_gid16_t        gid16_t;
9293 +typedef unsigned int           xid_t;
9294 +typedef unsigned int           nid_t;
9295 +typedef unsigned int           tag_t;
9296  
9297  typedef unsigned long          uintptr_t;
9298  
9299 diff -NurpP --minimal linux-3.0-rc5/include/linux/utsname.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/utsname.h
9300 --- linux-3.0-rc5/include/linux/utsname.h       2011-05-22 16:17:58.000000000 +0200
9301 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/utsname.h  2011-06-13 14:36:48.000000000 +0200
9302 @@ -54,7 +54,8 @@ static inline void get_uts_ns(struct uts
9303  }
9304  
9305  extern struct uts_namespace *copy_utsname(unsigned long flags,
9306 -                                         struct task_struct *tsk);
9307 +                                         struct uts_namespace *old_ns,
9308 +                                         struct user_namespace *user_ns);
9309  extern void free_uts_ns(struct kref *kref);
9310  
9311  static inline void put_uts_ns(struct uts_namespace *ns)
9312 @@ -71,12 +72,13 @@ static inline void put_uts_ns(struct uts
9313  }
9314  
9315  static inline struct uts_namespace *copy_utsname(unsigned long flags,
9316 -                                                struct task_struct *tsk)
9317 +                                                struct uts_namespace *old_ns,
9318 +                                                struct user_namespace *user_ns)
9319  {
9320         if (flags & CLONE_NEWUTS)
9321                 return ERR_PTR(-EINVAL);
9322  
9323 -       return tsk->nsproxy->uts_ns;
9324 +       return old_ns;
9325  }
9326  #endif
9327  
9328 diff -NurpP --minimal linux-3.0-rc5/include/linux/vroot.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vroot.h
9329 --- linux-3.0-rc5/include/linux/vroot.h 1970-01-01 01:00:00.000000000 +0100
9330 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vroot.h    2011-06-10 22:11:24.000000000 +0200
9331 @@ -0,0 +1,51 @@
9332 +
9333 +/*
9334 + * include/linux/vroot.h
9335 + *
9336 + * written by Herbert Pötzl, 9/11/2002
9337 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
9338 + *
9339 + * Copyright (C) 2002-2007 by Herbert Pötzl.
9340 + * Redistribution of this file is permitted under the
9341 + * GNU General Public License.
9342 + */
9343 +
9344 +#ifndef _LINUX_VROOT_H
9345 +#define _LINUX_VROOT_H
9346 +
9347 +
9348 +#ifdef __KERNEL__
9349 +
9350 +/* Possible states of device */
9351 +enum {
9352 +       Vr_unbound,
9353 +       Vr_bound,
9354 +};
9355 +
9356 +struct vroot_device {
9357 +       int             vr_number;
9358 +       int             vr_refcnt;
9359 +
9360 +       struct semaphore        vr_ctl_mutex;
9361 +       struct block_device    *vr_device;
9362 +       int                     vr_state;
9363 +};
9364 +
9365 +
9366 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
9367 +
9368 +extern int register_vroot_grb(vroot_grb_func *);
9369 +extern int unregister_vroot_grb(vroot_grb_func *);
9370 +
9371 +#endif /* __KERNEL__ */
9372 +
9373 +#define MAX_VROOT_DEFAULT      8
9374 +
9375 +/*
9376 + * IOCTL commands --- we will commandeer 0x56 ('V')
9377 + */
9378 +
9379 +#define VROOT_SET_DEV          0x5600
9380 +#define VROOT_CLR_DEV          0x5601
9381 +
9382 +#endif /* _LINUX_VROOT_H */
9383 diff -NurpP --minimal linux-3.0-rc5/include/linux/vs_base.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vs_base.h
9384 --- linux-3.0-rc5/include/linux/vs_base.h       1970-01-01 01:00:00.000000000 +0100
9385 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vs_base.h  2011-06-10 22:11:24.000000000 +0200
9386 @@ -0,0 +1,10 @@
9387 +#ifndef _VS_BASE_H
9388 +#define _VS_BASE_H
9389 +
9390 +#include "vserver/base.h"
9391 +#include "vserver/check.h"
9392 +#include "vserver/debug.h"
9393 +
9394 +#else
9395 +#warning duplicate inclusion
9396 +#endif
9397 diff -NurpP --minimal linux-3.0-rc5/include/linux/vs_context.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vs_context.h
9398 --- linux-3.0-rc5/include/linux/vs_context.h    1970-01-01 01:00:00.000000000 +0100
9399 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vs_context.h       2011-06-10 22:11:24.000000000 +0200
9400 @@ -0,0 +1,242 @@
9401 +#ifndef _VS_CONTEXT_H
9402 +#define _VS_CONTEXT_H
9403 +
9404 +#include "vserver/base.h"
9405 +#include "vserver/check.h"
9406 +#include "vserver/context.h"
9407 +#include "vserver/history.h"
9408 +#include "vserver/debug.h"
9409 +
9410 +#include <linux/sched.h>
9411 +
9412 +
9413 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
9414 +
9415 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
9416 +       const char *_file, int _line, void *_here)
9417 +{
9418 +       if (!vxi)
9419 +               return NULL;
9420 +
9421 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
9422 +               vxi, vxi ? vxi->vx_id : 0,
9423 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9424 +               _file, _line);
9425 +       __vxh_get_vx_info(vxi, _here);
9426 +
9427 +       atomic_inc(&vxi->vx_usecnt);
9428 +       return vxi;
9429 +}
9430 +
9431 +
9432 +extern void free_vx_info(struct vx_info *);
9433 +
9434 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
9435 +
9436 +static inline void __put_vx_info(struct vx_info *vxi,
9437 +       const char *_file, int _line, void *_here)
9438 +{
9439 +       if (!vxi)
9440 +               return;
9441 +
9442 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
9443 +               vxi, vxi ? vxi->vx_id : 0,
9444 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9445 +               _file, _line);
9446 +       __vxh_put_vx_info(vxi, _here);
9447 +
9448 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
9449 +               free_vx_info(vxi);
9450 +}
9451 +
9452 +
9453 +#define init_vx_info(p, i) \
9454 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9455 +
9456 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9457 +       const char *_file, int _line, void *_here)
9458 +{
9459 +       if (vxi) {
9460 +               vxlprintk(VXD_CBIT(xid, 3),
9461 +                       "init_vx_info(%p[#%d.%d])",
9462 +                       vxi, vxi ? vxi->vx_id : 0,
9463 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9464 +                       _file, _line);
9465 +               __vxh_init_vx_info(vxi, vxp, _here);
9466 +
9467 +               atomic_inc(&vxi->vx_usecnt);
9468 +       }
9469 +       *vxp = vxi;
9470 +}
9471 +
9472 +
9473 +#define set_vx_info(p, i) \
9474 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9475 +
9476 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9477 +       const char *_file, int _line, void *_here)
9478 +{
9479 +       struct vx_info *vxo;
9480 +
9481 +       if (!vxi)
9482 +               return;
9483 +
9484 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
9485 +               vxi, vxi ? vxi->vx_id : 0,
9486 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9487 +               _file, _line);
9488 +       __vxh_set_vx_info(vxi, vxp, _here);
9489 +
9490 +       atomic_inc(&vxi->vx_usecnt);
9491 +       vxo = xchg(vxp, vxi);
9492 +       BUG_ON(vxo);
9493 +}
9494 +
9495 +
9496 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
9497 +
9498 +static inline void __clr_vx_info(struct vx_info **vxp,
9499 +       const char *_file, int _line, void *_here)
9500 +{
9501 +       struct vx_info *vxo;
9502 +
9503 +       vxo = xchg(vxp, NULL);
9504 +       if (!vxo)
9505 +               return;
9506 +
9507 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
9508 +               vxo, vxo ? vxo->vx_id : 0,
9509 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
9510 +               _file, _line);
9511 +       __vxh_clr_vx_info(vxo, vxp, _here);
9512 +
9513 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
9514 +               free_vx_info(vxo);
9515 +}
9516 +
9517 +
9518 +#define claim_vx_info(v, p) \
9519 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9520 +
9521 +static inline void __claim_vx_info(struct vx_info *vxi,
9522 +       struct task_struct *task,
9523 +       const char *_file, int _line, void *_here)
9524 +{
9525 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
9526 +               vxi, vxi ? vxi->vx_id : 0,
9527 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9528 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9529 +               task, _file, _line);
9530 +       __vxh_claim_vx_info(vxi, task, _here);
9531 +
9532 +       atomic_inc(&vxi->vx_tasks);
9533 +}
9534 +
9535 +
9536 +extern void unhash_vx_info(struct vx_info *);
9537 +
9538 +#define release_vx_info(v, p) \
9539 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9540 +
9541 +static inline void __release_vx_info(struct vx_info *vxi,
9542 +       struct task_struct *task,
9543 +       const char *_file, int _line, void *_here)
9544 +{
9545 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
9546 +               vxi, vxi ? vxi->vx_id : 0,
9547 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9548 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9549 +               task, _file, _line);
9550 +       __vxh_release_vx_info(vxi, task, _here);
9551 +
9552 +       might_sleep();
9553 +
9554 +       if (atomic_dec_and_test(&vxi->vx_tasks))
9555 +               unhash_vx_info(vxi);
9556 +}
9557 +
9558 +
9559 +#define task_get_vx_info(p) \
9560 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
9561 +
9562 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
9563 +       const char *_file, int _line, void *_here)
9564 +{
9565 +       struct vx_info *vxi;
9566 +
9567 +       task_lock(p);
9568 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
9569 +               p, _file, _line);
9570 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
9571 +       task_unlock(p);
9572 +       return vxi;
9573 +}
9574 +
9575 +
9576 +static inline void __wakeup_vx_info(struct vx_info *vxi)
9577 +{
9578 +       if (waitqueue_active(&vxi->vx_wait))
9579 +               wake_up_interruptible(&vxi->vx_wait);
9580 +}
9581 +
9582 +
9583 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
9584 +
9585 +static inline void __enter_vx_info(struct vx_info *vxi,
9586 +       struct vx_info_save *vxis, const char *_file, int _line)
9587 +{
9588 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
9589 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
9590 +               current->xid, current->vx_info, _file, _line);
9591 +       vxis->vxi = xchg(&current->vx_info, vxi);
9592 +       vxis->xid = current->xid;
9593 +       current->xid = vxi ? vxi->vx_id : 0;
9594 +}
9595 +
9596 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
9597 +
9598 +static inline void __leave_vx_info(struct vx_info_save *vxis,
9599 +       const char *_file, int _line)
9600 +{
9601 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
9602 +               vxis, vxis->xid, vxis->vxi, current,
9603 +               current->xid, current->vx_info, _file, _line);
9604 +       (void)xchg(&current->vx_info, vxis->vxi);
9605 +       current->xid = vxis->xid;
9606 +}
9607 +
9608 +
9609 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
9610 +{
9611 +       vxis->vxi = xchg(&current->vx_info, NULL);
9612 +       vxis->xid = xchg(&current->xid, (xid_t)0);
9613 +}
9614 +
9615 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
9616 +{
9617 +       (void)xchg(&current->xid, vxis->xid);
9618 +       (void)xchg(&current->vx_info, vxis->vxi);
9619 +}
9620 +
9621 +#define task_is_init(p) \
9622 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
9623 +
9624 +static inline int __task_is_init(struct task_struct *p,
9625 +       const char *_file, int _line, void *_here)
9626 +{
9627 +       int is_init = is_global_init(p);
9628 +
9629 +       task_lock(p);
9630 +       if (p->vx_info)
9631 +               is_init = p->vx_info->vx_initpid == p->pid;
9632 +       task_unlock(p);
9633 +       return is_init;
9634 +}
9635 +
9636 +extern void exit_vx_info(struct task_struct *, int);
9637 +extern void exit_vx_info_early(struct task_struct *, int);
9638 +
9639 +
9640 +#else
9641 +#warning duplicate inclusion
9642 +#endif
9643 diff -NurpP --minimal linux-3.0-rc5/include/linux/vs_cowbl.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vs_cowbl.h
9644 --- linux-3.0-rc5/include/linux/vs_cowbl.h      1970-01-01 01:00:00.000000000 +0100
9645 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vs_cowbl.h 2011-06-10 22:11:24.000000000 +0200
9646 @@ -0,0 +1,48 @@
9647 +#ifndef _VS_COWBL_H
9648 +#define _VS_COWBL_H
9649 +
9650 +#include <linux/fs.h>
9651 +#include <linux/dcache.h>
9652 +#include <linux/namei.h>
9653 +#include <linux/slab.h>
9654 +
9655 +extern struct dentry *cow_break_link(const char *pathname);
9656 +
9657 +static inline int cow_check_and_break(struct path *path)
9658 +{
9659 +       struct inode *inode = path->dentry->d_inode;
9660 +       int error = 0;
9661 +
9662 +       /* do we need this check? */
9663 +       if (IS_RDONLY(inode))
9664 +               return -EROFS;
9665 +
9666 +       if (IS_COW(inode)) {
9667 +               if (IS_COW_LINK(inode)) {
9668 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
9669 +                       char *pp, *buf;
9670 +
9671 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
9672 +                       if (!buf) {
9673 +                               return -ENOMEM;
9674 +                       }
9675 +                       pp = d_path(path, buf, PATH_MAX);
9676 +                       new_dentry = cow_break_link(pp);
9677 +                       kfree(buf);
9678 +                       if (!IS_ERR(new_dentry)) {
9679 +                               path->dentry = new_dentry;
9680 +                               dput(old_dentry);
9681 +                       } else
9682 +                               error = PTR_ERR(new_dentry);
9683 +               } else {
9684 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
9685 +                       inode->i_ctime = CURRENT_TIME;
9686 +                       mark_inode_dirty(inode);
9687 +               }
9688 +       }
9689 +       return error;
9690 +}
9691 +
9692 +#else
9693 +#warning duplicate inclusion
9694 +#endif
9695 diff -NurpP --minimal linux-3.0-rc5/include/linux/vs_cvirt.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vs_cvirt.h
9696 --- linux-3.0-rc5/include/linux/vs_cvirt.h      1970-01-01 01:00:00.000000000 +0100
9697 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vs_cvirt.h 2011-06-10 22:11:24.000000000 +0200
9698 @@ -0,0 +1,50 @@
9699 +#ifndef _VS_CVIRT_H
9700 +#define _VS_CVIRT_H
9701 +
9702 +#include "vserver/cvirt.h"
9703 +#include "vserver/context.h"
9704 +#include "vserver/base.h"
9705 +#include "vserver/check.h"
9706 +#include "vserver/debug.h"
9707 +
9708 +
9709 +static inline void vx_activate_task(struct task_struct *p)
9710 +{
9711 +       struct vx_info *vxi;
9712 +
9713 +       if ((vxi = p->vx_info)) {
9714 +               vx_update_load(vxi);
9715 +               atomic_inc(&vxi->cvirt.nr_running);
9716 +       }
9717 +}
9718 +
9719 +static inline void vx_deactivate_task(struct task_struct *p)
9720 +{
9721 +       struct vx_info *vxi;
9722 +
9723 +       if ((vxi = p->vx_info)) {
9724 +               vx_update_load(vxi);
9725 +               atomic_dec(&vxi->cvirt.nr_running);
9726 +       }
9727 +}
9728 +
9729 +static inline void vx_uninterruptible_inc(struct task_struct *p)
9730 +{
9731 +       struct vx_info *vxi;
9732 +
9733 +       if ((vxi = p->vx_info))
9734 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
9735 +}
9736 +
9737 +static inline void vx_uninterruptible_dec(struct task_struct *p)
9738 +{
9739 +       struct vx_info *vxi;
9740 +
9741 +       if ((vxi = p->vx_info))
9742 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
9743 +}
9744 +
9745 +
9746 +#else
9747 +#warning duplicate inclusion
9748 +#endif
9749 diff -NurpP --minimal linux-3.0-rc5/include/linux/vs_device.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vs_device.h
9750 --- linux-3.0-rc5/include/linux/vs_device.h     1970-01-01 01:00:00.000000000 +0100
9751 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vs_device.h        2011-06-10 22:11:24.000000000 +0200
9752 @@ -0,0 +1,45 @@
9753 +#ifndef _VS_DEVICE_H
9754 +#define _VS_DEVICE_H
9755 +
9756 +#include "vserver/base.h"
9757 +#include "vserver/device.h"
9758 +#include "vserver/debug.h"
9759 +
9760 +
9761 +#ifdef CONFIG_VSERVER_DEVICE
9762 +
9763 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
9764 +
9765 +#define vs_device_perm(v, d, m, p) \
9766 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
9767 +
9768 +#else
9769 +
9770 +static inline
9771 +int vs_map_device(struct vx_info *vxi,
9772 +       dev_t device, dev_t *target, umode_t mode)
9773 +{
9774 +       if (target)
9775 +               *target = device;
9776 +       return ~0;
9777 +}
9778 +
9779 +#define vs_device_perm(v, d, m, p) ((p) == (p))
9780 +
9781 +#endif
9782 +
9783 +
9784 +#define vs_map_chrdev(d, t, p) \
9785 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
9786 +#define vs_map_blkdev(d, t, p) \
9787 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
9788 +
9789 +#define vs_chrdev_perm(d, p) \
9790 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
9791 +#define vs_blkdev_perm(d, p) \
9792 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
9793 +
9794 +
9795 +#else
9796 +#warning duplicate inclusion
9797 +#endif
9798 diff -NurpP --minimal linux-3.0-rc5/include/linux/vs_dlimit.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vs_dlimit.h
9799 --- linux-3.0-rc5/include/linux/vs_dlimit.h     1970-01-01 01:00:00.000000000 +0100
9800 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vs_dlimit.h        2011-06-10 22:11:24.000000000 +0200
9801 @@ -0,0 +1,215 @@
9802 +#ifndef _VS_DLIMIT_H
9803 +#define _VS_DLIMIT_H
9804 +
9805 +#include <linux/fs.h>
9806 +
9807 +#include "vserver/dlimit.h"
9808 +#include "vserver/base.h"
9809 +#include "vserver/debug.h"
9810 +
9811 +
9812 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
9813 +
9814 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
9815 +       const char *_file, int _line)
9816 +{
9817 +       if (!dli)
9818 +               return NULL;
9819 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
9820 +               dli, dli ? dli->dl_tag : 0,
9821 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9822 +               _file, _line);
9823 +       atomic_inc(&dli->dl_usecnt);
9824 +       return dli;
9825 +}
9826 +
9827 +
9828 +#define free_dl_info(i) \
9829 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
9830 +
9831 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
9832 +
9833 +static inline void __put_dl_info(struct dl_info *dli,
9834 +       const char *_file, int _line)
9835 +{
9836 +       if (!dli)
9837 +               return;
9838 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
9839 +               dli, dli ? dli->dl_tag : 0,
9840 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9841 +               _file, _line);
9842 +       if (atomic_dec_and_test(&dli->dl_usecnt))
9843 +               free_dl_info(dli);
9844 +}
9845 +
9846 +
9847 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
9848 +
9849 +static inline int __dl_alloc_space(struct super_block *sb,
9850 +       tag_t tag, dlsize_t nr, const char *file, int line)
9851 +{
9852 +       struct dl_info *dli = NULL;
9853 +       int ret = 0;
9854 +
9855 +       if (nr == 0)
9856 +               goto out;
9857 +       dli = locate_dl_info(sb, tag);
9858 +       if (!dli)
9859 +               goto out;
9860 +
9861 +       spin_lock(&dli->dl_lock);
9862 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
9863 +       if (!ret)
9864 +               dli->dl_space_used += nr;
9865 +       spin_unlock(&dli->dl_lock);
9866 +       put_dl_info(dli);
9867 +out:
9868 +       vxlprintk(VXD_CBIT(dlim, 1),
9869 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
9870 +               sb, tag, __dlimit_char(dli), (long long)nr,
9871 +               ret, file, line);
9872 +       return ret ? -ENOSPC : 0;
9873 +}
9874 +
9875 +static inline void __dl_free_space(struct super_block *sb,
9876 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
9877 +{
9878 +       struct dl_info *dli = NULL;
9879 +
9880 +       if (nr == 0)
9881 +               goto out;
9882 +       dli = locate_dl_info(sb, tag);
9883 +       if (!dli)
9884 +               goto out;
9885 +
9886 +       spin_lock(&dli->dl_lock);
9887 +       if (dli->dl_space_used > nr)
9888 +               dli->dl_space_used -= nr;
9889 +       else
9890 +               dli->dl_space_used = 0;
9891 +       spin_unlock(&dli->dl_lock);
9892 +       put_dl_info(dli);
9893 +out:
9894 +       vxlprintk(VXD_CBIT(dlim, 1),
9895 +               "FREE  (%p,#%d)%c %lld bytes",
9896 +               sb, tag, __dlimit_char(dli), (long long)nr,
9897 +               _file, _line);
9898 +}
9899 +
9900 +static inline int __dl_alloc_inode(struct super_block *sb,
9901 +       tag_t tag, const char *_file, int _line)
9902 +{
9903 +       struct dl_info *dli;
9904 +       int ret = 0;
9905 +
9906 +       dli = locate_dl_info(sb, tag);
9907 +       if (!dli)
9908 +               goto out;
9909 +
9910 +       spin_lock(&dli->dl_lock);
9911 +       dli->dl_inodes_used++;
9912 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
9913 +       spin_unlock(&dli->dl_lock);
9914 +       put_dl_info(dli);
9915 +out:
9916 +       vxlprintk(VXD_CBIT(dlim, 0),
9917 +               "ALLOC (%p,#%d)%c inode (%d)",
9918 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
9919 +       return ret ? -ENOSPC : 0;
9920 +}
9921 +
9922 +static inline void __dl_free_inode(struct super_block *sb,
9923 +       tag_t tag, const char *_file, int _line)
9924 +{
9925 +       struct dl_info *dli;
9926 +
9927 +       dli = locate_dl_info(sb, tag);
9928 +       if (!dli)
9929 +               goto out;
9930 +
9931 +       spin_lock(&dli->dl_lock);
9932 +       if (dli->dl_inodes_used > 1)
9933 +               dli->dl_inodes_used--;
9934 +       else
9935 +               dli->dl_inodes_used = 0;
9936 +       spin_unlock(&dli->dl_lock);
9937 +       put_dl_info(dli);
9938 +out:
9939 +       vxlprintk(VXD_CBIT(dlim, 0),
9940 +               "FREE  (%p,#%d)%c inode",
9941 +               sb, tag, __dlimit_char(dli), _file, _line);
9942 +}
9943 +
9944 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
9945 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
9946 +       const char *_file, int _line)
9947 +{
9948 +       struct dl_info *dli;
9949 +       uint64_t broot, bfree;
9950 +
9951 +       dli = locate_dl_info(sb, tag);
9952 +       if (!dli)
9953 +               return;
9954 +
9955 +       spin_lock(&dli->dl_lock);
9956 +       broot = (dli->dl_space_total -
9957 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
9958 +               >> sb->s_blocksize_bits;
9959 +       bfree = (dli->dl_space_total - dli->dl_space_used)
9960 +                       >> sb->s_blocksize_bits;
9961 +       spin_unlock(&dli->dl_lock);
9962 +
9963 +       vxlprintk(VXD_CBIT(dlim, 2),
9964 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
9965 +               (long long)bfree, (long long)broot,
9966 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
9967 +               _file, _line);
9968 +       if (free_blocks) {
9969 +               if (*free_blocks > bfree)
9970 +                       *free_blocks = bfree;
9971 +       }
9972 +       if (root_blocks) {
9973 +               if (*root_blocks > broot)
9974 +                       *root_blocks = broot;
9975 +       }
9976 +       put_dl_info(dli);
9977 +}
9978 +
9979 +#define dl_prealloc_space(in, bytes) \
9980 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9981 +               __FILE__, __LINE__ )
9982 +
9983 +#define dl_alloc_space(in, bytes) \
9984 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9985 +               __FILE__, __LINE__ )
9986 +
9987 +#define dl_reserve_space(in, bytes) \
9988 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9989 +               __FILE__, __LINE__ )
9990 +
9991 +#define dl_claim_space(in, bytes) (0)
9992 +
9993 +#define dl_release_space(in, bytes) \
9994 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9995 +               __FILE__, __LINE__ )
9996 +
9997 +#define dl_free_space(in, bytes) \
9998 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9999 +               __FILE__, __LINE__ )
10000 +
10001 +
10002 +
10003 +#define dl_alloc_inode(in) \
10004 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10005 +
10006 +#define dl_free_inode(in) \
10007 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10008 +
10009 +
10010 +#define dl_adjust_block(sb, tag, fb, rb) \
10011 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
10012 +
10013 +
10014 +#else
10015 +#warning duplicate inclusion
10016 +#endif
10017 diff -NurpP --minimal linux-3.0-rc5/include/linux/vs_inet.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vs_inet.h
10018 --- linux-3.0-rc5/include/linux/vs_inet.h       1970-01-01 01:00:00.000000000 +0100
10019 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vs_inet.h  2011-06-10 22:11:24.000000000 +0200
10020 @@ -0,0 +1,351 @@
10021 +#ifndef _VS_INET_H
10022 +#define _VS_INET_H
10023 +
10024 +#include "vserver/base.h"
10025 +#include "vserver/network.h"
10026 +#include "vserver/debug.h"
10027 +
10028 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
10029 +
10030 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
10031 +                       NIPQUAD((a)->mask), (a)->type
10032 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
10033 +
10034 +#define NIPQUAD(addr) \
10035 +       ((unsigned char *)&addr)[0], \
10036 +       ((unsigned char *)&addr)[1], \
10037 +       ((unsigned char *)&addr)[2], \
10038 +       ((unsigned char *)&addr)[3]
10039 +
10040 +#define NIPQUAD_FMT "%u.%u.%u.%u"
10041 +
10042 +
10043 +static inline
10044 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
10045 +{
10046 +       __be32 ip = nxa->ip[0].s_addr;
10047 +       __be32 mask = nxa->mask.s_addr;
10048 +       __be32 bcast = ip | ~mask;
10049 +       int ret = 0;
10050 +
10051 +       switch (nxa->type & tmask) {
10052 +       case NXA_TYPE_MASK:
10053 +               ret = (ip == (addr & mask));
10054 +               break;
10055 +       case NXA_TYPE_ADDR:
10056 +               ret = 3;
10057 +               if (addr == ip)
10058 +                       break;
10059 +               /* fall through to broadcast */
10060 +       case NXA_MOD_BCAST:
10061 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
10062 +               break;
10063 +       case NXA_TYPE_RANGE:
10064 +               ret = ((nxa->ip[0].s_addr <= addr) &&
10065 +                       (nxa->ip[1].s_addr > addr));
10066 +               break;
10067 +       case NXA_TYPE_ANY:
10068 +               ret = 2;
10069 +               break;
10070 +       }
10071 +
10072 +       vxdprintk(VXD_CBIT(net, 0),
10073 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
10074 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
10075 +       return ret;
10076 +}
10077 +
10078 +static inline
10079 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
10080 +{
10081 +       struct nx_addr_v4 *nxa;
10082 +       int ret = 1;
10083 +
10084 +       if (!nxi)
10085 +               goto out;
10086 +
10087 +       ret = 2;
10088 +       /* allow 127.0.0.1 when remapping lback */
10089 +       if ((tmask & NXA_LOOPBACK) &&
10090 +               (addr == IPI_LOOPBACK) &&
10091 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
10092 +               goto out;
10093 +       ret = 3;
10094 +       /* check for lback address */
10095 +       if ((tmask & NXA_MOD_LBACK) &&
10096 +               (nxi->v4_lback.s_addr == addr))
10097 +               goto out;
10098 +       ret = 4;
10099 +       /* check for broadcast address */
10100 +       if ((tmask & NXA_MOD_BCAST) &&
10101 +               (nxi->v4_bcast.s_addr == addr))
10102 +               goto out;
10103 +       ret = 5;
10104 +       /* check for v4 addresses */
10105 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
10106 +               if (v4_addr_match(nxa, addr, tmask))
10107 +                       goto out;
10108 +       ret = 0;
10109 +out:
10110 +       vxdprintk(VXD_CBIT(net, 0),
10111 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
10112 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
10113 +       return ret;
10114 +}
10115 +
10116 +static inline
10117 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
10118 +{
10119 +       /* FIXME: needs full range checks */
10120 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
10121 +}
10122 +
10123 +static inline
10124 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
10125 +{
10126 +       struct nx_addr_v4 *ptr;
10127 +
10128 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
10129 +               if (v4_nx_addr_match(ptr, nxa, mask))
10130 +                       return 1;
10131 +       return 0;
10132 +}
10133 +
10134 +#include <net/inet_sock.h>
10135 +
10136 +/*
10137 + *     Check if a given address matches for a socket
10138 + *
10139 + *     nxi:            the socket's nx_info if any
10140 + *     addr:           to be verified address
10141 + */
10142 +static inline
10143 +int v4_sock_addr_match (
10144 +       struct nx_info *nxi,
10145 +       struct inet_sock *inet,
10146 +       __be32 addr)
10147 +{
10148 +       __be32 saddr = inet->inet_rcv_saddr;
10149 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
10150 +
10151 +       if (addr && (saddr == addr || bcast == addr))
10152 +               return 1;
10153 +       if (!saddr)
10154 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
10155 +       return 0;
10156 +}
10157 +
10158 +
10159 +/* inet related checks and helpers */
10160 +
10161 +
10162 +struct in_ifaddr;
10163 +struct net_device;
10164 +struct sock;
10165 +
10166 +#ifdef CONFIG_INET
10167 +
10168 +#include <linux/netdevice.h>
10169 +#include <linux/inetdevice.h>
10170 +#include <net/inet_sock.h>
10171 +#include <net/inet_timewait_sock.h>
10172 +
10173 +
10174 +int dev_in_nx_info(struct net_device *, struct nx_info *);
10175 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
10176 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
10177 +
10178 +
10179 +/*
10180 + *     check if address is covered by socket
10181 + *
10182 + *     sk:     the socket to check against
10183 + *     addr:   the address in question (must be != 0)
10184 + */
10185 +
10186 +static inline
10187 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
10188 +{
10189 +       struct nx_info *nxi = sk->sk_nx_info;
10190 +       __be32 saddr = sk_rcv_saddr(sk);
10191 +
10192 +       vxdprintk(VXD_CBIT(net, 5),
10193 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
10194 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
10195 +               (sk->sk_socket?sk->sk_socket->flags:0));
10196 +
10197 +       if (saddr) {            /* direct address match */
10198 +               return v4_addr_match(nxa, saddr, -1);
10199 +       } else if (nxi) {       /* match against nx_info */
10200 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
10201 +       } else {                /* unrestricted any socket */
10202 +               return 1;
10203 +       }
10204 +}
10205 +
10206 +
10207 +
10208 +static inline
10209 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
10210 +{
10211 +       vxdprintk(VXD_CBIT(net, 1),
10212 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
10213 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
10214 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
10215 +
10216 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
10217 +               return 1;
10218 +       if (dev_in_nx_info(dev, nxi))
10219 +               return 1;
10220 +       return 0;
10221 +}
10222 +
10223 +
10224 +static inline
10225 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
10226 +{
10227 +       if (!nxi)
10228 +               return 1;
10229 +       if (!ifa)
10230 +               return 0;
10231 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
10232 +}
10233 +
10234 +static inline
10235 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
10236 +{
10237 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
10238 +               nxi, nxi ? nxi->nx_id : 0, ifa,
10239 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
10240 +
10241 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
10242 +               return 1;
10243 +       if (v4_ifa_in_nx_info(ifa, nxi))
10244 +               return 1;
10245 +       return 0;
10246 +}
10247 +
10248 +
10249 +struct nx_v4_sock_addr {
10250 +       __be32 saddr;   /* Address used for validation */
10251 +       __be32 baddr;   /* Address used for socket bind */
10252 +};
10253 +
10254 +static inline
10255 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
10256 +       struct nx_v4_sock_addr *nsa)
10257 +{
10258 +       struct sock *sk = &inet->sk;
10259 +       struct nx_info *nxi = sk->sk_nx_info;
10260 +       __be32 saddr = addr->sin_addr.s_addr;
10261 +       __be32 baddr = saddr;
10262 +
10263 +       vxdprintk(VXD_CBIT(net, 3),
10264 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
10265 +               sk, sk->sk_nx_info, sk->sk_socket,
10266 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
10267 +               NIPQUAD(saddr));
10268 +
10269 +       if (nxi) {
10270 +               if (saddr == INADDR_ANY) {
10271 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
10272 +                               baddr = nxi->v4.ip[0].s_addr;
10273 +               } else if (saddr == IPI_LOOPBACK) {
10274 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
10275 +                               baddr = nxi->v4_lback.s_addr;
10276 +               } else {        /* normal address bind */
10277 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
10278 +                               return -EADDRNOTAVAIL;
10279 +               }
10280 +       }
10281 +
10282 +       vxdprintk(VXD_CBIT(net, 3),
10283 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
10284 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
10285 +
10286 +       nsa->saddr = saddr;
10287 +       nsa->baddr = baddr;
10288 +       return 0;
10289 +}
10290 +
10291 +static inline
10292 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
10293 +{
10294 +       inet->inet_saddr = nsa->baddr;
10295 +       inet->inet_rcv_saddr = nsa->baddr;
10296 +}
10297 +
10298 +
10299 +/*
10300 + *      helper to simplify inet_lookup_listener
10301 + *
10302 + *      nxi:   the socket's nx_info if any
10303 + *      addr:  to be verified address
10304 + *      saddr: socket address
10305 + */
10306 +static inline int v4_inet_addr_match (
10307 +       struct nx_info *nxi,
10308 +       __be32 addr,
10309 +       __be32 saddr)
10310 +{
10311 +       if (addr && (saddr == addr))
10312 +               return 1;
10313 +       if (!saddr)
10314 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
10315 +       return 0;
10316 +}
10317 +
10318 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
10319 +{
10320 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
10321 +               (addr == nxi->v4_lback.s_addr))
10322 +               return IPI_LOOPBACK;
10323 +       return addr;
10324 +}
10325 +
10326 +static inline
10327 +int nx_info_has_v4(struct nx_info *nxi)
10328 +{
10329 +       if (!nxi)
10330 +               return 1;
10331 +       if (NX_IPV4(nxi))
10332 +               return 1;
10333 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
10334 +               return 1;
10335 +       return 0;
10336 +}
10337 +
10338 +#else /* CONFIG_INET */
10339 +
10340 +static inline
10341 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
10342 +{
10343 +       return 1;
10344 +}
10345 +
10346 +static inline
10347 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
10348 +{
10349 +       return 1;
10350 +}
10351 +
10352 +static inline
10353 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
10354 +{
10355 +       return 1;
10356 +}
10357 +
10358 +static inline
10359 +int nx_info_has_v4(struct nx_info *nxi)
10360 +{
10361 +       return 0;
10362 +}
10363 +
10364 +#endif /* CONFIG_INET */
10365 +
10366 +#define current_nx_info_has_v4() \
10367 +       nx_info_has_v4(current_nx_info())
10368 +
10369 +#else
10370 +// #warning duplicate inclusion
10371 +#endif
10372 diff -NurpP --minimal linux-3.0-rc5/include/linux/vs_inet6.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vs_inet6.h
10373 --- linux-3.0-rc5/include/linux/vs_inet6.h      1970-01-01 01:00:00.000000000 +0100
10374 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vs_inet6.h 2011-06-10 22:11:24.000000000 +0200
10375 @@ -0,0 +1,246 @@
10376 +#ifndef _VS_INET6_H
10377 +#define _VS_INET6_H
10378 +
10379 +#include "vserver/base.h"
10380 +#include "vserver/network.h"
10381 +#include "vserver/debug.h"
10382 +
10383 +#include <net/ipv6.h>
10384 +
10385 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
10386 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
10387 +
10388 +
10389 +#ifdef CONFIG_IPV6
10390 +
10391 +static inline
10392 +int v6_addr_match(struct nx_addr_v6 *nxa,
10393 +       const struct in6_addr *addr, uint16_t mask)
10394 +{
10395 +       int ret = 0;
10396 +
10397 +       switch (nxa->type & mask) {
10398 +       case NXA_TYPE_MASK:
10399 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
10400 +               break;
10401 +       case NXA_TYPE_ADDR:
10402 +               ret = ipv6_addr_equal(&nxa->ip, addr);
10403 +               break;
10404 +       case NXA_TYPE_ANY:
10405 +               ret = 1;
10406 +               break;
10407 +       }
10408 +       vxdprintk(VXD_CBIT(net, 0),
10409 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
10410 +               nxa, NXAV6(nxa), addr, mask, ret);
10411 +       return ret;
10412 +}
10413 +
10414 +static inline
10415 +int v6_addr_in_nx_info(struct nx_info *nxi,
10416 +       const struct in6_addr *addr, uint16_t mask)
10417 +{
10418 +       struct nx_addr_v6 *nxa;
10419 +       int ret = 1;
10420 +
10421 +       if (!nxi)
10422 +               goto out;
10423 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
10424 +               if (v6_addr_match(nxa, addr, mask))
10425 +                       goto out;
10426 +       ret = 0;
10427 +out:
10428 +       vxdprintk(VXD_CBIT(net, 0),
10429 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
10430 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
10431 +       return ret;
10432 +}
10433 +
10434 +static inline
10435 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
10436 +{
10437 +       /* FIXME: needs full range checks */
10438 +       return v6_addr_match(nxa, &addr->ip, mask);
10439 +}
10440 +
10441 +static inline
10442 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
10443 +{
10444 +       struct nx_addr_v6 *ptr;
10445 +
10446 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
10447 +               if (v6_nx_addr_match(ptr, nxa, mask))
10448 +                       return 1;
10449 +       return 0;
10450 +}
10451 +
10452 +
10453 +/*
10454 + *     Check if a given address matches for a socket
10455 + *
10456 + *     nxi:            the socket's nx_info if any
10457 + *     addr:           to be verified address
10458 + */
10459 +static inline
10460 +int v6_sock_addr_match (
10461 +       struct nx_info *nxi,
10462 +       struct inet_sock *inet,
10463 +       struct in6_addr *addr)
10464 +{
10465 +       struct sock *sk = &inet->sk;
10466 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
10467 +
10468 +       if (!ipv6_addr_any(addr) &&
10469 +               ipv6_addr_equal(saddr, addr))
10470 +               return 1;
10471 +       if (ipv6_addr_any(saddr))
10472 +               return v6_addr_in_nx_info(nxi, addr, -1);
10473 +       return 0;
10474 +}
10475 +
10476 +/*
10477 + *     check if address is covered by socket
10478 + *
10479 + *     sk:     the socket to check against
10480 + *     addr:   the address in question (must be != 0)
10481 + */
10482 +
10483 +static inline
10484 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
10485 +{
10486 +       struct nx_info *nxi = sk->sk_nx_info;
10487 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
10488 +
10489 +       vxdprintk(VXD_CBIT(net, 5),
10490 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
10491 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
10492 +               (sk->sk_socket?sk->sk_socket->flags:0));
10493 +
10494 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
10495 +               return v6_addr_match(nxa, saddr, -1);
10496 +       } else if (nxi) {               /* match against nx_info */
10497 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
10498 +       } else {                        /* unrestricted any socket */
10499 +               return 1;
10500 +       }
10501 +}
10502 +
10503 +
10504 +/* inet related checks and helpers */
10505 +
10506 +
10507 +struct in_ifaddr;
10508 +struct net_device;
10509 +struct sock;
10510 +
10511 +
10512 +#include <linux/netdevice.h>
10513 +#include <linux/inetdevice.h>
10514 +#include <net/inet_timewait_sock.h>
10515 +
10516 +
10517 +int dev_in_nx_info(struct net_device *, struct nx_info *);
10518 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
10519 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
10520 +
10521 +
10522 +
10523 +static inline
10524 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
10525 +{
10526 +       if (!nxi)
10527 +               return 1;
10528 +       if (!ifa)
10529 +               return 0;
10530 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
10531 +}
10532 +
10533 +static inline
10534 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
10535 +{
10536 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
10537 +               nxi, nxi ? nxi->nx_id : 0, ifa,
10538 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
10539 +
10540 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
10541 +               return 1;
10542 +       if (v6_ifa_in_nx_info(ifa, nxi))
10543 +               return 1;
10544 +       return 0;
10545 +}
10546 +
10547 +
10548 +struct nx_v6_sock_addr {
10549 +       struct in6_addr saddr;  /* Address used for validation */
10550 +       struct in6_addr baddr;  /* Address used for socket bind */
10551 +};
10552 +
10553 +static inline
10554 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
10555 +       struct nx_v6_sock_addr *nsa)
10556 +{
10557 +       // struct sock *sk = &inet->sk;
10558 +       // struct nx_info *nxi = sk->sk_nx_info;
10559 +       struct in6_addr saddr = addr->sin6_addr;
10560 +       struct in6_addr baddr = saddr;
10561 +
10562 +       nsa->saddr = saddr;
10563 +       nsa->baddr = baddr;
10564 +       return 0;
10565 +}
10566 +
10567 +static inline
10568 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
10569 +{
10570 +       // struct sock *sk = &inet->sk;
10571 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
10572 +
10573 +       // *saddr = nsa->baddr;
10574 +       // inet->inet_saddr = nsa->baddr;
10575 +}
10576 +
10577 +static inline
10578 +int nx_info_has_v6(struct nx_info *nxi)
10579 +{
10580 +       if (!nxi)
10581 +               return 1;
10582 +       if (NX_IPV6(nxi))
10583 +               return 1;
10584 +       return 0;
10585 +}
10586 +
10587 +#else /* CONFIG_IPV6 */
10588 +
10589 +static inline
10590 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
10591 +{
10592 +       return 1;
10593 +}
10594 +
10595 +
10596 +static inline
10597 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
10598 +{
10599 +       return 1;
10600 +}
10601 +
10602 +static inline
10603 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
10604 +{
10605 +       return 1;
10606 +}
10607 +
10608 +static inline
10609 +int nx_info_has_v6(struct nx_info *nxi)
10610 +{
10611 +       return 0;
10612 +}
10613 +
10614 +#endif /* CONFIG_IPV6 */
10615 +
10616 +#define current_nx_info_has_v6() \
10617 +       nx_info_has_v6(current_nx_info())
10618 +
10619 +#else
10620 +#warning duplicate inclusion
10621 +#endif
10622 diff -NurpP --minimal linux-3.0-rc5/include/linux/vs_limit.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vs_limit.h
10623 --- linux-3.0-rc5/include/linux/vs_limit.h      1970-01-01 01:00:00.000000000 +0100
10624 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vs_limit.h 2011-06-10 22:11:24.000000000 +0200
10625 @@ -0,0 +1,140 @@
10626 +#ifndef _VS_LIMIT_H
10627 +#define _VS_LIMIT_H
10628 +
10629 +#include "vserver/limit.h"
10630 +#include "vserver/base.h"
10631 +#include "vserver/context.h"
10632 +#include "vserver/debug.h"
10633 +#include "vserver/context.h"
10634 +#include "vserver/limit_int.h"
10635 +
10636 +
10637 +#define vx_acc_cres(v, d, p, r) \
10638 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
10639 +
10640 +#define vx_acc_cres_cond(x, d, p, r) \
10641 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
10642 +       r, d, p, __FILE__, __LINE__)
10643 +
10644 +
10645 +#define vx_add_cres(v, a, p, r) \
10646 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
10647 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
10648 +
10649 +#define vx_add_cres_cond(x, a, p, r) \
10650 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
10651 +       r, a, p, __FILE__, __LINE__)
10652 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
10653 +
10654 +
10655 +/* process and file limits */
10656 +
10657 +#define vx_nproc_inc(p) \
10658 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
10659 +
10660 +#define vx_nproc_dec(p) \
10661 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
10662 +
10663 +#define vx_files_inc(f) \
10664 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
10665 +
10666 +#define vx_files_dec(f) \
10667 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
10668 +
10669 +#define vx_locks_inc(l) \
10670 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
10671 +
10672 +#define vx_locks_dec(l) \
10673 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
10674 +
10675 +#define vx_openfd_inc(f) \
10676 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
10677 +
10678 +#define vx_openfd_dec(f) \
10679 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
10680 +
10681 +
10682 +#define vx_cres_avail(v, n, r) \
10683 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
10684 +
10685 +
10686 +#define vx_nproc_avail(n) \
10687 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
10688 +
10689 +#define vx_files_avail(n) \
10690 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
10691 +
10692 +#define vx_locks_avail(n) \
10693 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
10694 +
10695 +#define vx_openfd_avail(n) \
10696 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
10697 +
10698 +
10699 +/* dentry limits */
10700 +
10701 +#define vx_dentry_inc(d) do {                                          \
10702 +       if ((d)->d_count == 1)                                          \
10703 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
10704 +       } while (0)
10705 +
10706 +#define vx_dentry_dec(d) do {                                          \
10707 +       if ((d)->d_count == 0)                                          \
10708 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
10709 +       } while (0)
10710 +
10711 +#define vx_dentry_avail(n) \
10712 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
10713 +
10714 +
10715 +/* socket limits */
10716 +
10717 +#define vx_sock_inc(s) \
10718 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
10719 +
10720 +#define vx_sock_dec(s) \
10721 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
10722 +
10723 +#define vx_sock_avail(n) \
10724 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
10725 +
10726 +
10727 +/* ipc resource limits */
10728 +
10729 +#define vx_ipcmsg_add(v, u, a) \
10730 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
10731 +
10732 +#define vx_ipcmsg_sub(v, u, a) \
10733 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
10734 +
10735 +#define vx_ipcmsg_avail(v, a) \
10736 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
10737 +
10738 +
10739 +#define vx_ipcshm_add(v, k, a) \
10740 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
10741 +
10742 +#define vx_ipcshm_sub(v, k, a) \
10743 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
10744 +
10745 +#define vx_ipcshm_avail(v, a) \
10746 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
10747 +
10748 +
10749 +#define vx_semary_inc(a) \
10750 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
10751 +
10752 +#define vx_semary_dec(a) \
10753 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
10754 +
10755 +
10756 +#define vx_nsems_add(a,n) \
10757 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
10758 +
10759 +#define vx_nsems_sub(a,n) \
10760 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
10761 +
10762 +
10763 +#else
10764 +#warning duplicate inclusion
10765 +#endif
10766 diff -NurpP --minimal linux-3.0-rc5/include/linux/vs_memory.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vs_memory.h
10767 --- linux-3.0-rc5/include/linux/vs_memory.h     1970-01-01 01:00:00.000000000 +0100
10768 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vs_memory.h        2011-06-10 22:11:24.000000000 +0200
10769 @@ -0,0 +1,58 @@
10770 +#ifndef _VS_MEMORY_H
10771 +#define _VS_MEMORY_H
10772 +
10773 +#include "vserver/limit.h"
10774 +#include "vserver/base.h"
10775 +#include "vserver/context.h"
10776 +#include "vserver/debug.h"
10777 +#include "vserver/context.h"
10778 +#include "vserver/limit_int.h"
10779 +
10780 +enum {
10781 +       VXPT_UNKNOWN = 0,
10782 +       VXPT_ANON,
10783 +       VXPT_NONE,
10784 +       VXPT_FILE,
10785 +       VXPT_SWAP,
10786 +       VXPT_WRITE
10787 +};
10788 +
10789 +#if 0
10790 +#define        vx_page_fault(mm, vma, type, ret)
10791 +#else
10792 +
10793 +static inline
10794 +void __vx_page_fault(struct mm_struct *mm,
10795 +       struct vm_area_struct *vma, int type, int ret)
10796 +{
10797 +       struct vx_info *vxi = mm->mm_vx_info;
10798 +       int what;
10799 +/*
10800 +       static char *page_type[6] =
10801 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
10802 +       static char *page_what[4] =
10803 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
10804 +*/
10805 +
10806 +       if (!vxi)
10807 +               return;
10808 +
10809 +       what = (ret & 0x3);
10810 +
10811 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
10812 +               type, what, ret, page_type[type], page_what[what]);
10813 +*/
10814 +       if (ret & VM_FAULT_WRITE)
10815 +               what |= 0x4;
10816 +       atomic_inc(&vxi->cacct.page[type][what]);
10817 +}
10818 +
10819 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
10820 +#endif
10821 +
10822 +
10823 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
10824 +
10825 +#else
10826 +#warning duplicate inclusion
10827 +#endif
10828 diff -NurpP --minimal linux-3.0-rc5/include/linux/vs_network.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vs_network.h
10829 --- linux-3.0-rc5/include/linux/vs_network.h    1970-01-01 01:00:00.000000000 +0100
10830 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vs_network.h       2011-06-10 22:11:24.000000000 +0200
10831 @@ -0,0 +1,169 @@
10832 +#ifndef _NX_VS_NETWORK_H
10833 +#define _NX_VS_NETWORK_H
10834 +
10835 +#include "vserver/context.h"
10836 +#include "vserver/network.h"
10837 +#include "vserver/base.h"
10838 +#include "vserver/check.h"
10839 +#include "vserver/debug.h"
10840 +
10841 +#include <linux/sched.h>
10842 +
10843 +
10844 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
10845 +
10846 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
10847 +       const char *_file, int _line)
10848 +{
10849 +       if (!nxi)
10850 +               return NULL;
10851 +
10852 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
10853 +               nxi, nxi ? nxi->nx_id : 0,
10854 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10855 +               _file, _line);
10856 +
10857 +       atomic_inc(&nxi->nx_usecnt);
10858 +       return nxi;
10859 +}
10860 +
10861 +
10862 +extern void free_nx_info(struct nx_info *);
10863 +
10864 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
10865 +
10866 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
10867 +{
10868 +       if (!nxi)
10869 +               return;
10870 +
10871 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
10872 +               nxi, nxi ? nxi->nx_id : 0,
10873 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10874 +               _file, _line);
10875 +
10876 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
10877 +               free_nx_info(nxi);
10878 +}
10879 +
10880 +
10881 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
10882 +
10883 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
10884 +               const char *_file, int _line)
10885 +{
10886 +       if (nxi) {
10887 +               vxlprintk(VXD_CBIT(nid, 3),
10888 +                       "init_nx_info(%p[#%d.%d])",
10889 +                       nxi, nxi ? nxi->nx_id : 0,
10890 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10891 +                       _file, _line);
10892 +
10893 +               atomic_inc(&nxi->nx_usecnt);
10894 +       }
10895 +       *nxp = nxi;
10896 +}
10897 +
10898 +
10899 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
10900 +
10901 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
10902 +       const char *_file, int _line)
10903 +{
10904 +       struct nx_info *nxo;
10905 +
10906 +       if (!nxi)
10907 +               return;
10908 +
10909 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
10910 +               nxi, nxi ? nxi->nx_id : 0,
10911 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10912 +               _file, _line);
10913 +
10914 +       atomic_inc(&nxi->nx_usecnt);
10915 +       nxo = xchg(nxp, nxi);
10916 +       BUG_ON(nxo);
10917 +}
10918 +
10919 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
10920 +
10921 +static inline void __clr_nx_info(struct nx_info **nxp,
10922 +       const char *_file, int _line)
10923 +{
10924 +       struct nx_info *nxo;
10925 +
10926 +       nxo = xchg(nxp, NULL);
10927 +       if (!nxo)
10928 +               return;
10929 +
10930 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
10931 +               nxo, nxo ? nxo->nx_id : 0,
10932 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
10933 +               _file, _line);
10934 +
10935 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
10936 +               free_nx_info(nxo);
10937 +}
10938 +
10939 +
10940 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
10941 +
10942 +static inline void __claim_nx_info(struct nx_info *nxi,
10943 +       struct task_struct *task, const char *_file, int _line)
10944 +{
10945 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
10946 +               nxi, nxi ? nxi->nx_id : 0,
10947 +               nxi?atomic_read(&nxi->nx_usecnt):0,
10948 +               nxi?atomic_read(&nxi->nx_tasks):0,
10949 +               task, _file, _line);
10950 +
10951 +       atomic_inc(&nxi->nx_tasks);
10952 +}
10953 +
10954 +
10955 +extern void unhash_nx_info(struct nx_info *);
10956 +
10957 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
10958 +
10959 +static inline void __release_nx_info(struct nx_info *nxi,
10960 +       struct task_struct *task, const char *_file, int _line)
10961 +{
10962 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
10963 +               nxi, nxi ? nxi->nx_id : 0,
10964 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10965 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
10966 +               task, _file, _line);
10967 +
10968 +       might_sleep();
10969 +
10970 +       if (atomic_dec_and_test(&nxi->nx_tasks))
10971 +               unhash_nx_info(nxi);
10972 +}
10973 +
10974 +
10975 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
10976 +
10977 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
10978 +       const char *_file, int _line)
10979 +{
10980 +       struct nx_info *nxi;
10981 +
10982 +       task_lock(p);
10983 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
10984 +               p, _file, _line);
10985 +       nxi = __get_nx_info(p->nx_info, _file, _line);
10986 +       task_unlock(p);
10987 +       return nxi;
10988 +}
10989 +
10990 +
10991 +static inline void exit_nx_info(struct task_struct *p)
10992 +{
10993 +       if (p->nx_info)
10994 +               release_nx_info(p->nx_info, p);
10995 +}
10996 +
10997 +
10998 +#else
10999 +#warning duplicate inclusion
11000 +#endif
11001 diff -NurpP --minimal linux-3.0-rc5/include/linux/vs_pid.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vs_pid.h
11002 --- linux-3.0-rc5/include/linux/vs_pid.h        1970-01-01 01:00:00.000000000 +0100
11003 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vs_pid.h   2011-06-10 22:11:24.000000000 +0200
11004 @@ -0,0 +1,50 @@
11005 +#ifndef _VS_PID_H
11006 +#define _VS_PID_H
11007 +
11008 +#include "vserver/base.h"
11009 +#include "vserver/check.h"
11010 +#include "vserver/context.h"
11011 +#include "vserver/debug.h"
11012 +#include "vserver/pid.h"
11013 +#include <linux/pid_namespace.h>
11014 +
11015 +
11016 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
11017 +
11018 +static inline
11019 +int vx_proc_task_visible(struct task_struct *task)
11020 +{
11021 +       if ((task->pid == 1) &&
11022 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
11023 +               /* show a blend through init */
11024 +               goto visible;
11025 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
11026 +               goto visible;
11027 +       return 0;
11028 +visible:
11029 +       return 1;
11030 +}
11031 +
11032 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
11033 +
11034 +
11035 +static inline
11036 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
11037 +{
11038 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
11039 +
11040 +       if (task && !vx_proc_task_visible(task)) {
11041 +               vxdprintk(VXD_CBIT(misc, 6),
11042 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
11043 +                       task, task->xid, task->pid,
11044 +                       current, current->xid, current->pid);
11045 +               put_task_struct(task);
11046 +               task = NULL;
11047 +       }
11048 +       return task;
11049 +}
11050 +
11051 +
11052 +#else
11053 +#warning duplicate inclusion
11054 +#endif
11055 diff -NurpP --minimal linux-3.0-rc5/include/linux/vs_sched.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vs_sched.h
11056 --- linux-3.0-rc5/include/linux/vs_sched.h      1970-01-01 01:00:00.000000000 +0100
11057 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vs_sched.h 2011-06-10 22:11:24.000000000 +0200
11058 @@ -0,0 +1,40 @@
11059 +#ifndef _VS_SCHED_H
11060 +#define _VS_SCHED_H
11061 +
11062 +#include "vserver/base.h"
11063 +#include "vserver/context.h"
11064 +#include "vserver/sched.h"
11065 +
11066 +
11067 +#define MAX_PRIO_BIAS           20
11068 +#define MIN_PRIO_BIAS          -20
11069 +
11070 +static inline
11071 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
11072 +{
11073 +       struct vx_info *vxi = p->vx_info;
11074 +
11075 +       if (vxi)
11076 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
11077 +       return prio;
11078 +}
11079 +
11080 +static inline void vx_account_user(struct vx_info *vxi,
11081 +       cputime_t cputime, int nice)
11082 +{
11083 +       if (!vxi)
11084 +               return;
11085 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
11086 +}
11087 +
11088 +static inline void vx_account_system(struct vx_info *vxi,
11089 +       cputime_t cputime, int idle)
11090 +{
11091 +       if (!vxi)
11092 +               return;
11093 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
11094 +}
11095 +
11096 +#else
11097 +#warning duplicate inclusion
11098 +#endif
11099 diff -NurpP --minimal linux-3.0-rc5/include/linux/vs_socket.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vs_socket.h
11100 --- linux-3.0-rc5/include/linux/vs_socket.h     1970-01-01 01:00:00.000000000 +0100
11101 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vs_socket.h        2011-06-10 22:11:24.000000000 +0200
11102 @@ -0,0 +1,67 @@
11103 +#ifndef _VS_SOCKET_H
11104 +#define _VS_SOCKET_H
11105 +
11106 +#include "vserver/debug.h"
11107 +#include "vserver/base.h"
11108 +#include "vserver/cacct.h"
11109 +#include "vserver/context.h"
11110 +#include "vserver/tag.h"
11111 +
11112 +
11113 +/* socket accounting */
11114 +
11115 +#include <linux/socket.h>
11116 +
11117 +static inline int vx_sock_type(int family)
11118 +{
11119 +       switch (family) {
11120 +       case PF_UNSPEC:
11121 +               return VXA_SOCK_UNSPEC;
11122 +       case PF_UNIX:
11123 +               return VXA_SOCK_UNIX;
11124 +       case PF_INET:
11125 +               return VXA_SOCK_INET;
11126 +       case PF_INET6:
11127 +               return VXA_SOCK_INET6;
11128 +       case PF_PACKET:
11129 +               return VXA_SOCK_PACKET;
11130 +       default:
11131 +               return VXA_SOCK_OTHER;
11132 +       }
11133 +}
11134 +
11135 +#define vx_acc_sock(v, f, p, s) \
11136 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
11137 +
11138 +static inline void __vx_acc_sock(struct vx_info *vxi,
11139 +       int family, int pos, int size, char *file, int line)
11140 +{
11141 +       if (vxi) {
11142 +               int type = vx_sock_type(family);
11143 +
11144 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
11145 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
11146 +       }
11147 +}
11148 +
11149 +#define vx_sock_recv(sk, s) \
11150 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
11151 +#define vx_sock_send(sk, s) \
11152 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
11153 +#define vx_sock_fail(sk, s) \
11154 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
11155 +
11156 +
11157 +#define sock_vx_init(s) do {           \
11158 +       (s)->sk_xid = 0;                \
11159 +       (s)->sk_vx_info = NULL;         \
11160 +       } while (0)
11161 +
11162 +#define sock_nx_init(s) do {           \
11163 +       (s)->sk_nid = 0;                \
11164 +       (s)->sk_nx_info = NULL;         \
11165 +       } while (0)
11166 +
11167 +#else
11168 +#warning duplicate inclusion
11169 +#endif
11170 diff -NurpP --minimal linux-3.0-rc5/include/linux/vs_tag.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vs_tag.h
11171 --- linux-3.0-rc5/include/linux/vs_tag.h        1970-01-01 01:00:00.000000000 +0100
11172 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vs_tag.h   2011-06-10 22:11:24.000000000 +0200
11173 @@ -0,0 +1,47 @@
11174 +#ifndef _VS_TAG_H
11175 +#define _VS_TAG_H
11176 +
11177 +#include <linux/vserver/tag.h>
11178 +
11179 +/* check conditions */
11180 +
11181 +#define DX_ADMIN       0x0001
11182 +#define DX_WATCH       0x0002
11183 +#define DX_HOSTID      0x0008
11184 +
11185 +#define DX_IDENT       0x0010
11186 +
11187 +#define DX_ARG_MASK    0x0010
11188 +
11189 +
11190 +#define dx_task_tag(t) ((t)->tag)
11191 +
11192 +#define dx_current_tag() dx_task_tag(current)
11193 +
11194 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
11195 +
11196 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
11197 +
11198 +
11199 +/*
11200 + * check current context for ADMIN/WATCH and
11201 + * optionally against supplied argument
11202 + */
11203 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
11204 +{
11205 +       if (mode & DX_ARG_MASK) {
11206 +               if ((mode & DX_IDENT) && (id == cid))
11207 +                       return 1;
11208 +       }
11209 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
11210 +               ((mode & DX_WATCH) && (cid == 1)) ||
11211 +               ((mode & DX_HOSTID) && (id == 0)));
11212 +}
11213 +
11214 +struct inode;
11215 +int dx_permission(const struct inode *inode, int mask);
11216 +
11217 +
11218 +#else
11219 +#warning duplicate inclusion
11220 +#endif
11221 diff -NurpP --minimal linux-3.0-rc5/include/linux/vs_time.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vs_time.h
11222 --- linux-3.0-rc5/include/linux/vs_time.h       1970-01-01 01:00:00.000000000 +0100
11223 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vs_time.h  2011-06-13 14:57:45.000000000 +0200
11224 @@ -0,0 +1,19 @@
11225 +#ifndef _VS_TIME_H
11226 +#define _VS_TIME_H
11227 +
11228 +
11229 +/* time faking stuff */
11230 +
11231 +#ifdef CONFIG_VSERVER_VTIME
11232 +
11233 +extern void vx_adjust_timespec(struct timespec *ts);
11234 +extern int vx_settimeofday(const struct timespec *ts);
11235 +
11236 +#else
11237 +#define        vx_adjust_timespec(t)   do { } while (0)
11238 +#define        vx_settimeofday(t)      do_settimeofday(t)
11239 +#endif
11240 +
11241 +#else
11242 +#warning duplicate inclusion
11243 +#endif
11244 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/Kbuild linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/Kbuild
11245 --- linux-3.0-rc5/include/linux/vserver/Kbuild  1970-01-01 01:00:00.000000000 +0100
11246 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/Kbuild     2011-06-10 22:11:24.000000000 +0200
11247 @@ -0,0 +1,8 @@
11248 +
11249 +unifdef-y += context_cmd.h network_cmd.h space_cmd.h \
11250 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
11251 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
11252 +       debug_cmd.h device_cmd.h
11253 +
11254 +unifdef-y += switch.h network.h monitor.h inode.h device.h
11255 +
11256 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/base.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/base.h
11257 --- linux-3.0-rc5/include/linux/vserver/base.h  1970-01-01 01:00:00.000000000 +0100
11258 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/base.h     2011-06-13 14:09:44.000000000 +0200
11259 @@ -0,0 +1,173 @@
11260 +#ifndef _VX_BASE_H
11261 +#define _VX_BASE_H
11262 +
11263 +
11264 +/* context state changes */
11265 +
11266 +enum {
11267 +       VSC_STARTUP = 1,
11268 +       VSC_SHUTDOWN,
11269 +
11270 +       VSC_NETUP,
11271 +       VSC_NETDOWN,
11272 +};
11273 +
11274 +
11275 +
11276 +#define vx_task_xid(t) ((t)->xid)
11277 +
11278 +#define vx_current_xid() vx_task_xid(current)
11279 +
11280 +#define current_vx_info() (current->vx_info)
11281 +
11282 +
11283 +#define nx_task_nid(t) ((t)->nid)
11284 +
11285 +#define nx_current_nid() nx_task_nid(current)
11286 +
11287 +#define current_nx_info() (current->nx_info)
11288 +
11289 +
11290 +/* generic flag merging */
11291 +
11292 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
11293 +
11294 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
11295 +
11296 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
11297 +
11298 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
11299 +
11300 +
11301 +/* context flags */
11302 +
11303 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
11304 +
11305 +#define vx_current_flags()     __vx_flags(current_vx_info())
11306 +
11307 +#define vx_info_flags(v, m, f) \
11308 +       vs_check_flags(__vx_flags(v), m, f)
11309 +
11310 +#define task_vx_flags(t, m, f) \
11311 +       ((t) && vx_info_flags((t)->vx_info, m, f))
11312 +
11313 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
11314 +
11315 +
11316 +/* context caps */
11317 +
11318 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
11319 +
11320 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
11321 +
11322 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
11323 +
11324 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
11325 +
11326 +
11327 +
11328 +/* network flags */
11329 +
11330 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
11331 +
11332 +#define nx_current_flags()     __nx_flags(current_nx_info())
11333 +
11334 +#define nx_info_flags(n, m, f) \
11335 +       vs_check_flags(__nx_flags(n), m, f)
11336 +
11337 +#define task_nx_flags(t, m, f) \
11338 +       ((t) && nx_info_flags((t)->nx_info, m, f))
11339 +
11340 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
11341 +
11342 +
11343 +/* network caps */
11344 +
11345 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
11346 +
11347 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
11348 +
11349 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
11350 +
11351 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
11352 +
11353 +
11354 +/* context mask capabilities */
11355 +
11356 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
11357 +
11358 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
11359 +
11360 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
11361 +
11362 +
11363 +/* context bcap mask */
11364 +
11365 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
11366 +
11367 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
11368 +
11369 +
11370 +/* mask given bcaps */
11371 +
11372 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
11373 +
11374 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
11375 +
11376 +
11377 +/* masked cap_bset */
11378 +
11379 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
11380 +
11381 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
11382 +
11383 +#if 0
11384 +#define vx_info_mbcap(v, b) \
11385 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
11386 +       vx_info_bcaps(v, b) : (b))
11387 +
11388 +#define task_vx_mbcap(t, b) \
11389 +       vx_info_mbcap((t)->vx_info, (t)->b)
11390 +
11391 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
11392 +#endif
11393 +
11394 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
11395 +
11396 +#define vx_capable(b, c) (capable(b) || \
11397 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
11398 +
11399 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
11400 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
11401 +
11402 +#define nx_capable(b, c) (capable(b) || \
11403 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
11404 +
11405 +#define vx_task_initpid(t, n) \
11406 +       ((t)->vx_info && \
11407 +       ((t)->vx_info->vx_initpid == (n)))
11408 +
11409 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
11410 +
11411 +
11412 +/* context unshare mask */
11413 +
11414 +#define __vx_umask(v)          ((v)->vx_umask)
11415 +
11416 +#define vx_current_umask()     __vx_umask(current_vx_info())
11417 +
11418 +#define vx_can_unshare(b, f) (capable(b) || \
11419 +       (cap_raised(current_cap(), b) && \
11420 +       !((f) & ~vx_current_umask())))
11421 +
11422 +
11423 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
11424 +
11425 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
11426 +
11427 +
11428 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
11429 +
11430 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
11431 +
11432 +#endif
11433 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/cacct.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/cacct.h
11434 --- linux-3.0-rc5/include/linux/vserver/cacct.h 1970-01-01 01:00:00.000000000 +0100
11435 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/cacct.h    2011-06-10 22:11:24.000000000 +0200
11436 @@ -0,0 +1,15 @@
11437 +#ifndef _VX_CACCT_H
11438 +#define _VX_CACCT_H
11439 +
11440 +
11441 +enum sock_acc_field {
11442 +       VXA_SOCK_UNSPEC = 0,
11443 +       VXA_SOCK_UNIX,
11444 +       VXA_SOCK_INET,
11445 +       VXA_SOCK_INET6,
11446 +       VXA_SOCK_PACKET,
11447 +       VXA_SOCK_OTHER,
11448 +       VXA_SOCK_SIZE   /* array size */
11449 +};
11450 +
11451 +#endif /* _VX_CACCT_H */
11452 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/cacct_cmd.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/cacct_cmd.h
11453 --- linux-3.0-rc5/include/linux/vserver/cacct_cmd.h     1970-01-01 01:00:00.000000000 +0100
11454 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/cacct_cmd.h        2011-06-10 22:11:24.000000000 +0200
11455 @@ -0,0 +1,23 @@
11456 +#ifndef _VX_CACCT_CMD_H
11457 +#define _VX_CACCT_CMD_H
11458 +
11459 +
11460 +/* virtual host info name commands */
11461 +
11462 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
11463 +
11464 +struct vcmd_sock_stat_v0 {
11465 +       uint32_t field;
11466 +       uint32_t count[3];
11467 +       uint64_t total[3];
11468 +};
11469 +
11470 +
11471 +#ifdef __KERNEL__
11472 +
11473 +#include <linux/compiler.h>
11474 +
11475 +extern int vc_sock_stat(struct vx_info *, void __user *);
11476 +
11477 +#endif /* __KERNEL__ */
11478 +#endif /* _VX_CACCT_CMD_H */
11479 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/cacct_def.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/cacct_def.h
11480 --- linux-3.0-rc5/include/linux/vserver/cacct_def.h     1970-01-01 01:00:00.000000000 +0100
11481 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/cacct_def.h        2011-06-10 22:11:24.000000000 +0200
11482 @@ -0,0 +1,43 @@
11483 +#ifndef _VX_CACCT_DEF_H
11484 +#define _VX_CACCT_DEF_H
11485 +
11486 +#include <asm/atomic.h>
11487 +#include <linux/vserver/cacct.h>
11488 +
11489 +
11490 +struct _vx_sock_acc {
11491 +       atomic_long_t count;
11492 +       atomic_long_t total;
11493 +};
11494 +
11495 +/* context sub struct */
11496 +
11497 +struct _vx_cacct {
11498 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
11499 +       atomic_t slab[8];
11500 +       atomic_t page[6][8];
11501 +};
11502 +
11503 +#ifdef CONFIG_VSERVER_DEBUG
11504 +
11505 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
11506 +{
11507 +       int i, j;
11508 +
11509 +       printk("\t_vx_cacct:");
11510 +       for (i = 0; i < 6; i++) {
11511 +               struct _vx_sock_acc *ptr = cacct->sock[i];
11512 +
11513 +               printk("\t [%d] =", i);
11514 +               for (j = 0; j < 3; j++) {
11515 +                       printk(" [%d] = %8lu, %8lu", j,
11516 +                               atomic_long_read(&ptr[j].count),
11517 +                               atomic_long_read(&ptr[j].total));
11518 +               }
11519 +               printk("\n");
11520 +       }
11521 +}
11522 +
11523 +#endif
11524 +
11525 +#endif /* _VX_CACCT_DEF_H */
11526 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/cacct_int.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/cacct_int.h
11527 --- linux-3.0-rc5/include/linux/vserver/cacct_int.h     1970-01-01 01:00:00.000000000 +0100
11528 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/cacct_int.h        2011-06-10 22:11:24.000000000 +0200
11529 @@ -0,0 +1,21 @@
11530 +#ifndef _VX_CACCT_INT_H
11531 +#define _VX_CACCT_INT_H
11532 +
11533 +
11534 +#ifdef __KERNEL__
11535 +
11536 +static inline
11537 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
11538 +{
11539 +       return atomic_long_read(&cacct->sock[type][pos].count);
11540 +}
11541 +
11542 +
11543 +static inline
11544 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
11545 +{
11546 +       return atomic_long_read(&cacct->sock[type][pos].total);
11547 +}
11548 +
11549 +#endif /* __KERNEL__ */
11550 +#endif /* _VX_CACCT_INT_H */
11551 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/check.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/check.h
11552 --- linux-3.0-rc5/include/linux/vserver/check.h 1970-01-01 01:00:00.000000000 +0100
11553 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/check.h    2011-06-10 22:11:24.000000000 +0200
11554 @@ -0,0 +1,89 @@
11555 +#ifndef _VS_CHECK_H
11556 +#define _VS_CHECK_H
11557 +
11558 +
11559 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
11560 +
11561 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
11562 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
11563 +#else
11564 +#define MIN_D_CONTEXT  65536
11565 +#endif
11566 +
11567 +/* check conditions */
11568 +
11569 +#define VS_ADMIN       0x0001
11570 +#define VS_WATCH       0x0002
11571 +#define VS_HIDE                0x0004
11572 +#define VS_HOSTID      0x0008
11573 +
11574 +#define VS_IDENT       0x0010
11575 +#define VS_EQUIV       0x0020
11576 +#define VS_PARENT      0x0040
11577 +#define VS_CHILD       0x0080
11578 +
11579 +#define VS_ARG_MASK    0x00F0
11580 +
11581 +#define VS_DYNAMIC     0x0100
11582 +#define VS_STATIC      0x0200
11583 +
11584 +#define VS_ATR_MASK    0x0F00
11585 +
11586 +#ifdef CONFIG_VSERVER_PRIVACY
11587 +#define VS_ADMIN_P     (0)
11588 +#define VS_WATCH_P     (0)
11589 +#else
11590 +#define VS_ADMIN_P     VS_ADMIN
11591 +#define VS_WATCH_P     VS_WATCH
11592 +#endif
11593 +
11594 +#define VS_HARDIRQ     0x1000
11595 +#define VS_SOFTIRQ     0x2000
11596 +#define VS_IRQ         0x4000
11597 +
11598 +#define VS_IRQ_MASK    0xF000
11599 +
11600 +#include <linux/hardirq.h>
11601 +
11602 +/*
11603 + * check current context for ADMIN/WATCH and
11604 + * optionally against supplied argument
11605 + */
11606 +static inline int __vs_check(int cid, int id, unsigned int mode)
11607 +{
11608 +       if (mode & VS_ARG_MASK) {
11609 +               if ((mode & VS_IDENT) && (id == cid))
11610 +                       return 1;
11611 +       }
11612 +       if (mode & VS_ATR_MASK) {
11613 +               if ((mode & VS_DYNAMIC) &&
11614 +                       (id >= MIN_D_CONTEXT) &&
11615 +                       (id <= MAX_S_CONTEXT))
11616 +                       return 1;
11617 +               if ((mode & VS_STATIC) &&
11618 +                       (id > 1) && (id < MIN_D_CONTEXT))
11619 +                       return 1;
11620 +       }
11621 +       if (mode & VS_IRQ_MASK) {
11622 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
11623 +                       return 1;
11624 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
11625 +                       return 1;
11626 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
11627 +                       return 1;
11628 +       }
11629 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
11630 +               ((mode & VS_WATCH) && (cid == 1)) ||
11631 +               ((mode & VS_HOSTID) && (id == 0)));
11632 +}
11633 +
11634 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
11635 +
11636 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
11637 +
11638 +
11639 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
11640 +
11641 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
11642 +
11643 +#endif
11644 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/context.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/context.h
11645 --- linux-3.0-rc5/include/linux/vserver/context.h       1970-01-01 01:00:00.000000000 +0100
11646 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/context.h  2011-06-10 22:11:24.000000000 +0200
11647 @@ -0,0 +1,189 @@
11648 +#ifndef _VX_CONTEXT_H
11649 +#define _VX_CONTEXT_H
11650 +
11651 +#include <linux/types.h>
11652 +#include <linux/capability.h>
11653 +
11654 +
11655 +/* context flags */
11656 +
11657 +#define VXF_INFO_SCHED         0x00000002
11658 +#define VXF_INFO_NPROC         0x00000004
11659 +#define VXF_INFO_PRIVATE       0x00000008
11660 +
11661 +#define VXF_INFO_INIT          0x00000010
11662 +#define VXF_INFO_HIDE          0x00000020
11663 +#define VXF_INFO_ULIMIT                0x00000040
11664 +#define VXF_INFO_NSPACE                0x00000080
11665 +
11666 +#define VXF_SCHED_HARD         0x00000100
11667 +#define VXF_SCHED_PRIO         0x00000200
11668 +#define VXF_SCHED_PAUSE                0x00000400
11669 +
11670 +#define VXF_VIRT_MEM           0x00010000
11671 +#define VXF_VIRT_UPTIME                0x00020000
11672 +#define VXF_VIRT_CPU           0x00040000
11673 +#define VXF_VIRT_LOAD          0x00080000
11674 +#define VXF_VIRT_TIME          0x00100000
11675 +
11676 +#define VXF_HIDE_MOUNT         0x01000000
11677 +/* was VXF_HIDE_NETIF          0x02000000 */
11678 +#define VXF_HIDE_VINFO         0x04000000
11679 +
11680 +#define VXF_STATE_SETUP                (1ULL << 32)
11681 +#define VXF_STATE_INIT         (1ULL << 33)
11682 +#define VXF_STATE_ADMIN                (1ULL << 34)
11683 +
11684 +#define VXF_SC_HELPER          (1ULL << 36)
11685 +#define VXF_REBOOT_KILL                (1ULL << 37)
11686 +#define VXF_PERSISTENT         (1ULL << 38)
11687 +
11688 +#define VXF_FORK_RSS           (1ULL << 48)
11689 +#define VXF_PROLIFIC           (1ULL << 49)
11690 +
11691 +#define VXF_IGNEG_NICE         (1ULL << 52)
11692 +
11693 +#define VXF_ONE_TIME           (0x0007ULL << 32)
11694 +
11695 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
11696 +
11697 +
11698 +/* context migration */
11699 +
11700 +#define VXM_SET_INIT           0x00000001
11701 +#define VXM_SET_REAPER         0x00000002
11702 +
11703 +/* context caps */
11704 +
11705 +#define VXC_CAP_MASK           0x00000000
11706 +
11707 +#define VXC_SET_UTSNAME                0x00000001
11708 +#define VXC_SET_RLIMIT         0x00000002
11709 +#define VXC_FS_SECURITY                0x00000004
11710 +#define VXC_FS_TRUSTED         0x00000008
11711 +#define VXC_TIOCSTI            0x00000010
11712 +
11713 +/* was VXC_RAW_ICMP            0x00000100 */
11714 +#define VXC_SYSLOG             0x00001000
11715 +#define VXC_OOM_ADJUST         0x00002000
11716 +#define VXC_AUDIT_CONTROL      0x00004000
11717 +
11718 +#define VXC_SECURE_MOUNT       0x00010000
11719 +#define VXC_SECURE_REMOUNT     0x00020000
11720 +#define VXC_BINARY_MOUNT       0x00040000
11721 +
11722 +#define VXC_QUOTA_CTL          0x00100000
11723 +#define VXC_ADMIN_MAPPER       0x00200000
11724 +#define VXC_ADMIN_CLOOP                0x00400000
11725 +
11726 +#define VXC_KTHREAD            0x01000000
11727 +#define VXC_NAMESPACE          0x02000000
11728 +
11729 +
11730 +#ifdef __KERNEL__
11731 +
11732 +#include <linux/list.h>
11733 +#include <linux/spinlock.h>
11734 +#include <linux/rcupdate.h>
11735 +
11736 +#include "limit_def.h"
11737 +#include "sched_def.h"
11738 +#include "cvirt_def.h"
11739 +#include "cacct_def.h"
11740 +#include "device_def.h"
11741 +
11742 +#define VX_SPACES      2
11743 +
11744 +struct _vx_info_pc {
11745 +       struct _vx_sched_pc sched_pc;
11746 +       struct _vx_cvirt_pc cvirt_pc;
11747 +};
11748 +
11749 +struct _vx_space {
11750 +       unsigned long vx_nsmask;                /* assignment mask */
11751 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
11752 +       struct fs_struct *vx_fs;                /* private namespace fs */
11753 +       const struct cred *vx_cred;             /* task credentials */
11754 +};
11755 +
11756 +struct vx_info {
11757 +       struct hlist_node vx_hlist;             /* linked list of contexts */
11758 +       xid_t vx_id;                            /* context id */
11759 +       atomic_t vx_usecnt;                     /* usage count */
11760 +       atomic_t vx_tasks;                      /* tasks count */
11761 +       struct vx_info *vx_parent;              /* parent context */
11762 +       int vx_state;                           /* context state */
11763 +
11764 +       struct _vx_space space[VX_SPACES];      /* namespace store */
11765 +
11766 +       uint64_t vx_flags;                      /* context flags */
11767 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
11768 +       uint64_t vx_umask;                      /* unshare mask (guest) */
11769 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
11770 +
11771 +       struct task_struct *vx_reaper;          /* guest reaper process */
11772 +       pid_t vx_initpid;                       /* PID of guest init */
11773 +       int64_t vx_badness_bias;                /* OOM points bias */
11774 +
11775 +       struct _vx_limit limit;                 /* vserver limits */
11776 +       struct _vx_sched sched;                 /* vserver scheduler */
11777 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
11778 +       struct _vx_cacct cacct;                 /* context accounting */
11779 +
11780 +       struct _vx_device dmap;                 /* default device map targets */
11781 +
11782 +#ifndef CONFIG_SMP
11783 +       struct _vx_info_pc info_pc;             /* per cpu data */
11784 +#else
11785 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
11786 +#endif
11787 +
11788 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
11789 +       int reboot_cmd;                         /* last sys_reboot() cmd */
11790 +       int exit_code;                          /* last process exit code */
11791 +
11792 +       char vx_name[65];                       /* vserver name */
11793 +};
11794 +
11795 +#ifndef CONFIG_SMP
11796 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
11797 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
11798 +#else
11799 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
11800 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
11801 +#endif
11802 +
11803 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
11804 +
11805 +
11806 +struct vx_info_save {
11807 +       struct vx_info *vxi;
11808 +       xid_t xid;
11809 +};
11810 +
11811 +
11812 +/* status flags */
11813 +
11814 +#define VXS_HASHED     0x0001
11815 +#define VXS_PAUSED     0x0010
11816 +#define VXS_SHUTDOWN   0x0100
11817 +#define VXS_HELPER     0x1000
11818 +#define VXS_RELEASED   0x8000
11819 +
11820 +
11821 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
11822 +extern void release_vx_info(struct vx_info *, struct task_struct *);
11823 +
11824 +extern struct vx_info *lookup_vx_info(int);
11825 +extern struct vx_info *lookup_or_create_vx_info(int);
11826 +
11827 +extern int get_xid_list(int, unsigned int *, int);
11828 +extern int xid_is_hashed(xid_t);
11829 +
11830 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
11831 +
11832 +extern long vs_state_change(struct vx_info *, unsigned int);
11833 +
11834 +
11835 +#endif /* __KERNEL__ */
11836 +#endif /* _VX_CONTEXT_H */
11837 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/context_cmd.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/context_cmd.h
11838 --- linux-3.0-rc5/include/linux/vserver/context_cmd.h   1970-01-01 01:00:00.000000000 +0100
11839 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/context_cmd.h      2011-06-10 22:11:24.000000000 +0200
11840 @@ -0,0 +1,145 @@
11841 +#ifndef _VX_CONTEXT_CMD_H
11842 +#define _VX_CONTEXT_CMD_H
11843 +
11844 +
11845 +/* vinfo commands */
11846 +
11847 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
11848 +
11849 +#ifdef __KERNEL__
11850 +extern int vc_task_xid(uint32_t);
11851 +
11852 +#endif /* __KERNEL__ */
11853 +
11854 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
11855 +
11856 +struct vcmd_vx_info_v0 {
11857 +       uint32_t xid;
11858 +       uint32_t initpid;
11859 +       /* more to come */
11860 +};
11861 +
11862 +#ifdef __KERNEL__
11863 +extern int vc_vx_info(struct vx_info *, void __user *);
11864 +
11865 +#endif /* __KERNEL__ */
11866 +
11867 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
11868 +
11869 +struct vcmd_ctx_stat_v0 {
11870 +       uint32_t usecnt;
11871 +       uint32_t tasks;
11872 +       /* more to come */
11873 +};
11874 +
11875 +#ifdef __KERNEL__
11876 +extern int vc_ctx_stat(struct vx_info *, void __user *);
11877 +
11878 +#endif /* __KERNEL__ */
11879 +
11880 +/* context commands */
11881 +
11882 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
11883 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
11884 +
11885 +struct vcmd_ctx_create {
11886 +       uint64_t flagword;
11887 +};
11888 +
11889 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
11890 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
11891 +
11892 +struct vcmd_ctx_migrate {
11893 +       uint64_t flagword;
11894 +};
11895 +
11896 +#ifdef __KERNEL__
11897 +extern int vc_ctx_create(uint32_t, void __user *);
11898 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
11899 +
11900 +#endif /* __KERNEL__ */
11901 +
11902 +
11903 +/* flag commands */
11904 +
11905 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
11906 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
11907 +
11908 +struct vcmd_ctx_flags_v0 {
11909 +       uint64_t flagword;
11910 +       uint64_t mask;
11911 +};
11912 +
11913 +#ifdef __KERNEL__
11914 +extern int vc_get_cflags(struct vx_info *, void __user *);
11915 +extern int vc_set_cflags(struct vx_info *, void __user *);
11916 +
11917 +#endif /* __KERNEL__ */
11918 +
11919 +
11920 +/* context caps commands */
11921 +
11922 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
11923 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
11924 +
11925 +struct vcmd_ctx_caps_v1 {
11926 +       uint64_t ccaps;
11927 +       uint64_t cmask;
11928 +};
11929 +
11930 +#ifdef __KERNEL__
11931 +extern int vc_get_ccaps(struct vx_info *, void __user *);
11932 +extern int vc_set_ccaps(struct vx_info *, void __user *);
11933 +
11934 +#endif /* __KERNEL__ */
11935 +
11936 +
11937 +/* bcaps commands */
11938 +
11939 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
11940 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
11941 +
11942 +struct vcmd_bcaps {
11943 +       uint64_t bcaps;
11944 +       uint64_t bmask;
11945 +};
11946 +
11947 +#ifdef __KERNEL__
11948 +extern int vc_get_bcaps(struct vx_info *, void __user *);
11949 +extern int vc_set_bcaps(struct vx_info *, void __user *);
11950 +
11951 +#endif /* __KERNEL__ */
11952 +
11953 +
11954 +/* umask commands */
11955 +
11956 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
11957 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
11958 +
11959 +struct vcmd_umask {
11960 +       uint64_t umask;
11961 +       uint64_t mask;
11962 +};
11963 +
11964 +#ifdef __KERNEL__
11965 +extern int vc_get_umask(struct vx_info *, void __user *);
11966 +extern int vc_set_umask(struct vx_info *, void __user *);
11967 +
11968 +#endif /* __KERNEL__ */
11969 +
11970 +
11971 +/* OOM badness */
11972 +
11973 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
11974 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
11975 +
11976 +struct vcmd_badness_v0 {
11977 +       int64_t bias;
11978 +};
11979 +
11980 +#ifdef __KERNEL__
11981 +extern int vc_get_badness(struct vx_info *, void __user *);
11982 +extern int vc_set_badness(struct vx_info *, void __user *);
11983 +
11984 +#endif /* __KERNEL__ */
11985 +#endif /* _VX_CONTEXT_CMD_H */
11986 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/cvirt.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/cvirt.h
11987 --- linux-3.0-rc5/include/linux/vserver/cvirt.h 1970-01-01 01:00:00.000000000 +0100
11988 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/cvirt.h    2011-06-10 22:11:24.000000000 +0200
11989 @@ -0,0 +1,20 @@
11990 +#ifndef _VX_CVIRT_H
11991 +#define _VX_CVIRT_H
11992 +
11993 +
11994 +#ifdef __KERNEL__
11995 +
11996 +struct timespec;
11997 +
11998 +void vx_vsi_uptime(struct timespec *, struct timespec *);
11999 +
12000 +
12001 +struct vx_info;
12002 +
12003 +void vx_update_load(struct vx_info *);
12004 +
12005 +
12006 +int vx_do_syslog(int, char __user *, int);
12007 +
12008 +#endif /* __KERNEL__ */
12009 +#endif /* _VX_CVIRT_H */
12010 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/cvirt_cmd.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/cvirt_cmd.h
12011 --- linux-3.0-rc5/include/linux/vserver/cvirt_cmd.h     1970-01-01 01:00:00.000000000 +0100
12012 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/cvirt_cmd.h        2011-06-10 22:11:24.000000000 +0200
12013 @@ -0,0 +1,53 @@
12014 +#ifndef _VX_CVIRT_CMD_H
12015 +#define _VX_CVIRT_CMD_H
12016 +
12017 +
12018 +/* virtual host info name commands */
12019 +
12020 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
12021 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
12022 +
12023 +struct vcmd_vhi_name_v0 {
12024 +       uint32_t field;
12025 +       char name[65];
12026 +};
12027 +
12028 +
12029 +enum vhi_name_field {
12030 +       VHIN_CONTEXT = 0,
12031 +       VHIN_SYSNAME,
12032 +       VHIN_NODENAME,
12033 +       VHIN_RELEASE,
12034 +       VHIN_VERSION,
12035 +       VHIN_MACHINE,
12036 +       VHIN_DOMAINNAME,
12037 +};
12038 +
12039 +
12040 +#ifdef __KERNEL__
12041 +
12042 +#include <linux/compiler.h>
12043 +
12044 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
12045 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
12046 +
12047 +#endif /* __KERNEL__ */
12048 +
12049 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
12050 +
12051 +struct vcmd_virt_stat_v0 {
12052 +       uint64_t offset;
12053 +       uint64_t uptime;
12054 +       uint32_t nr_threads;
12055 +       uint32_t nr_running;
12056 +       uint32_t nr_uninterruptible;
12057 +       uint32_t nr_onhold;
12058 +       uint32_t nr_forks;
12059 +       uint32_t load[3];
12060 +};
12061 +
12062 +#ifdef __KERNEL__
12063 +extern int vc_virt_stat(struct vx_info *, void __user *);
12064 +
12065 +#endif /* __KERNEL__ */
12066 +#endif /* _VX_CVIRT_CMD_H */
12067 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/cvirt_def.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/cvirt_def.h
12068 --- linux-3.0-rc5/include/linux/vserver/cvirt_def.h     1970-01-01 01:00:00.000000000 +0100
12069 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/cvirt_def.h        2011-06-10 22:11:24.000000000 +0200
12070 @@ -0,0 +1,80 @@
12071 +#ifndef _VX_CVIRT_DEF_H
12072 +#define _VX_CVIRT_DEF_H
12073 +
12074 +#include <linux/jiffies.h>
12075 +#include <linux/spinlock.h>
12076 +#include <linux/wait.h>
12077 +#include <linux/time.h>
12078 +#include <asm/atomic.h>
12079 +
12080 +
12081 +struct _vx_usage_stat {
12082 +       uint64_t user;
12083 +       uint64_t nice;
12084 +       uint64_t system;
12085 +       uint64_t softirq;
12086 +       uint64_t irq;
12087 +       uint64_t idle;
12088 +       uint64_t iowait;
12089 +};
12090 +
12091 +struct _vx_syslog {
12092 +       wait_queue_head_t log_wait;
12093 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
12094 +
12095 +       unsigned long log_start;        /* next char to be read by syslog() */
12096 +       unsigned long con_start;        /* next char to be sent to consoles */
12097 +       unsigned long log_end;  /* most-recently-written-char + 1 */
12098 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
12099 +
12100 +       char log_buf[1024];
12101 +};
12102 +
12103 +
12104 +/* context sub struct */
12105 +
12106 +struct _vx_cvirt {
12107 +       atomic_t nr_threads;            /* number of current threads */
12108 +       atomic_t nr_running;            /* number of running threads */
12109 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
12110 +
12111 +       atomic_t nr_onhold;             /* processes on hold */
12112 +       uint32_t onhold_last;           /* jiffies when put on hold */
12113 +
12114 +       struct timespec bias_ts;        /* time offset to the host */
12115 +       struct timespec bias_idle;
12116 +       struct timespec bias_uptime;    /* context creation point */
12117 +       uint64_t bias_clock;            /* offset in clock_t */
12118 +
12119 +       spinlock_t load_lock;           /* lock for the load averages */
12120 +       atomic_t load_updates;          /* nr of load updates done so far */
12121 +       uint32_t load_last;             /* last time load was calculated */
12122 +       uint32_t load[3];               /* load averages 1,5,15 */
12123 +
12124 +       atomic_t total_forks;           /* number of forks so far */
12125 +
12126 +       struct _vx_syslog syslog;
12127 +};
12128 +
12129 +struct _vx_cvirt_pc {
12130 +       struct _vx_usage_stat cpustat;
12131 +};
12132 +
12133 +
12134 +#ifdef CONFIG_VSERVER_DEBUG
12135 +
12136 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
12137 +{
12138 +       printk("\t_vx_cvirt:\n");
12139 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
12140 +               atomic_read(&cvirt->nr_threads),
12141 +               atomic_read(&cvirt->nr_running),
12142 +               atomic_read(&cvirt->nr_uninterruptible),
12143 +               atomic_read(&cvirt->nr_onhold));
12144 +       /* add rest here */
12145 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
12146 +}
12147 +
12148 +#endif
12149 +
12150 +#endif /* _VX_CVIRT_DEF_H */
12151 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/debug.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/debug.h
12152 --- linux-3.0-rc5/include/linux/vserver/debug.h 1970-01-01 01:00:00.000000000 +0100
12153 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/debug.h    2011-06-10 22:11:24.000000000 +0200
12154 @@ -0,0 +1,140 @@
12155 +#ifndef _VX_DEBUG_H
12156 +#define _VX_DEBUG_H
12157 +
12158 +
12159 +#define VXD_CBIT(n, m) (vx_debug_ ## n & (1 << (m)))
12160 +#define VXD_CMIN(n, m) (vx_debug_ ## n > (m))
12161 +#define VXD_MASK(n, m) (vx_debug_ ## n & (m))
12162 +
12163 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
12164 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
12165 +#define VXF_DEV                "%p[%lu,%d:%d]"
12166 +
12167 +#if    defined(CONFIG_QUOTES_UTF8)
12168 +#define        VS_Q_LQM        "\xc2\xbb"
12169 +#define        VS_Q_RQM        "\xc2\xab"
12170 +#elif  defined(CONFIG_QUOTES_ASCII)
12171 +#define        VS_Q_LQM        "\x27"
12172 +#define        VS_Q_RQM        "\x27"
12173 +#else
12174 +#define        VS_Q_LQM        "\xbb"
12175 +#define        VS_Q_RQM        "\xab"
12176 +#endif
12177 +
12178 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
12179 +
12180 +
12181 +#define vxd_path(p)                                            \
12182 +       ({ static char _buffer[PATH_MAX];                       \
12183 +          d_path(p, _buffer, sizeof(_buffer)); })
12184 +
12185 +#define vxd_cond_path(n)                                       \
12186 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
12187 +
12188 +
12189 +#ifdef CONFIG_VSERVER_DEBUG
12190 +
12191 +extern unsigned int vx_debug_switch;
12192 +extern unsigned int vx_debug_xid;
12193 +extern unsigned int vx_debug_nid;
12194 +extern unsigned int vx_debug_tag;
12195 +extern unsigned int vx_debug_net;
12196 +extern unsigned int vx_debug_limit;
12197 +extern unsigned int vx_debug_cres;
12198 +extern unsigned int vx_debug_dlim;
12199 +extern unsigned int vx_debug_quota;
12200 +extern unsigned int vx_debug_cvirt;
12201 +extern unsigned int vx_debug_space;
12202 +extern unsigned int vx_debug_misc;
12203 +
12204 +
12205 +#define VX_LOGLEVEL    "vxD: "
12206 +#define VX_PROC_FMT    "%p: "
12207 +#define VX_PROCESS     current
12208 +
12209 +#define vxdprintk(c, f, x...)                                  \
12210 +       do {                                                    \
12211 +               if (c)                                          \
12212 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
12213 +                               VX_PROCESS , ##x);              \
12214 +       } while (0)
12215 +
12216 +#define vxlprintk(c, f, x...)                                  \
12217 +       do {                                                    \
12218 +               if (c)                                          \
12219 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
12220 +       } while (0)
12221 +
12222 +#define vxfprintk(c, f, x...)                                  \
12223 +       do {                                                    \
12224 +               if (c)                                          \
12225 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
12226 +       } while (0)
12227 +
12228 +
12229 +struct vx_info;
12230 +
12231 +void dump_vx_info(struct vx_info *, int);
12232 +void dump_vx_info_inactive(int);
12233 +
12234 +#else  /* CONFIG_VSERVER_DEBUG */
12235 +
12236 +#define vx_debug_switch 0
12237 +#define vx_debug_xid   0
12238 +#define vx_debug_nid   0
12239 +#define vx_debug_tag   0
12240 +#define vx_debug_net   0
12241 +#define vx_debug_limit 0
12242 +#define vx_debug_cres  0
12243 +#define vx_debug_dlim  0
12244 +#define vx_debug_cvirt 0
12245 +
12246 +#define vxdprintk(x...) do { } while (0)
12247 +#define vxlprintk(x...) do { } while (0)
12248 +#define vxfprintk(x...) do { } while (0)
12249 +
12250 +#endif /* CONFIG_VSERVER_DEBUG */
12251 +
12252 +
12253 +#ifdef CONFIG_VSERVER_WARN
12254 +
12255 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
12256 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
12257 +#define VX_WARN_XID    "[xid #%u] "
12258 +#define VX_WARN_NID    "[nid #%u] "
12259 +#define VX_WARN_TAG    "[tag #%u] "
12260 +
12261 +#define vxwprintk(c, f, x...)                                  \
12262 +       do {                                                    \
12263 +               if (c)                                          \
12264 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
12265 +       } while (0)
12266 +
12267 +#else  /* CONFIG_VSERVER_WARN */
12268 +
12269 +#define vxwprintk(x...) do { } while (0)
12270 +
12271 +#endif /* CONFIG_VSERVER_WARN */
12272 +
12273 +#define vxwprintk_task(c, f, x...)                             \
12274 +       vxwprintk(c, VX_WARN_TASK f,                            \
12275 +               current->comm, current->pid,                    \
12276 +               current->xid, current->nid, current->tag, ##x)
12277 +#define vxwprintk_xid(c, f, x...)                              \
12278 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
12279 +#define vxwprintk_nid(c, f, x...)                              \
12280 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
12281 +#define vxwprintk_tag(c, f, x...)                              \
12282 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
12283 +
12284 +#ifdef CONFIG_VSERVER_DEBUG
12285 +#define vxd_assert_lock(l)     assert_spin_locked(l)
12286 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
12287 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
12288 +#else
12289 +#define vxd_assert_lock(l)     do { } while (0)
12290 +#define vxd_assert(c, f, x...) do { } while (0)
12291 +#endif
12292 +
12293 +
12294 +#endif /* _VX_DEBUG_H */
12295 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/debug_cmd.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/debug_cmd.h
12296 --- linux-3.0-rc5/include/linux/vserver/debug_cmd.h     1970-01-01 01:00:00.000000000 +0100
12297 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/debug_cmd.h        2011-06-10 22:11:24.000000000 +0200
12298 @@ -0,0 +1,58 @@
12299 +#ifndef _VX_DEBUG_CMD_H
12300 +#define _VX_DEBUG_CMD_H
12301 +
12302 +
12303 +/* debug commands */
12304 +
12305 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
12306 +
12307 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
12308 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
12309 +
12310 +struct  vcmd_read_history_v0 {
12311 +       uint32_t index;
12312 +       uint32_t count;
12313 +       char __user *data;
12314 +};
12315 +
12316 +struct  vcmd_read_monitor_v0 {
12317 +       uint32_t index;
12318 +       uint32_t count;
12319 +       char __user *data;
12320 +};
12321 +
12322 +
12323 +#ifdef __KERNEL__
12324 +
12325 +#ifdef CONFIG_COMPAT
12326 +
12327 +#include <asm/compat.h>
12328 +
12329 +struct vcmd_read_history_v0_x32 {
12330 +       uint32_t index;
12331 +       uint32_t count;
12332 +       compat_uptr_t data_ptr;
12333 +};
12334 +
12335 +struct vcmd_read_monitor_v0_x32 {
12336 +       uint32_t index;
12337 +       uint32_t count;
12338 +       compat_uptr_t data_ptr;
12339 +};
12340 +
12341 +#endif  /* CONFIG_COMPAT */
12342 +
12343 +extern int vc_dump_history(uint32_t);
12344 +
12345 +extern int vc_read_history(uint32_t, void __user *);
12346 +extern int vc_read_monitor(uint32_t, void __user *);
12347 +
12348 +#ifdef CONFIG_COMPAT
12349 +
12350 +extern int vc_read_history_x32(uint32_t, void __user *);
12351 +extern int vc_read_monitor_x32(uint32_t, void __user *);
12352 +
12353 +#endif  /* CONFIG_COMPAT */
12354 +
12355 +#endif /* __KERNEL__ */
12356 +#endif /* _VX_DEBUG_CMD_H */
12357 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/device.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/device.h
12358 --- linux-3.0-rc5/include/linux/vserver/device.h        1970-01-01 01:00:00.000000000 +0100
12359 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/device.h   2011-06-10 22:11:24.000000000 +0200
12360 @@ -0,0 +1,15 @@
12361 +#ifndef _VX_DEVICE_H
12362 +#define _VX_DEVICE_H
12363 +
12364 +
12365 +#define DATTR_CREATE   0x00000001
12366 +#define DATTR_OPEN     0x00000002
12367 +
12368 +#define DATTR_REMAP    0x00000010
12369 +
12370 +#define DATTR_MASK     0x00000013
12371 +
12372 +
12373 +#else  /* _VX_DEVICE_H */
12374 +#warning duplicate inclusion
12375 +#endif /* _VX_DEVICE_H */
12376 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/device_cmd.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/device_cmd.h
12377 --- linux-3.0-rc5/include/linux/vserver/device_cmd.h    1970-01-01 01:00:00.000000000 +0100
12378 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/device_cmd.h       2011-06-10 22:11:24.000000000 +0200
12379 @@ -0,0 +1,44 @@
12380 +#ifndef _VX_DEVICE_CMD_H
12381 +#define _VX_DEVICE_CMD_H
12382 +
12383 +
12384 +/*  device vserver commands */
12385 +
12386 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
12387 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
12388 +
12389 +struct vcmd_set_mapping_v0 {
12390 +       const char __user *device;
12391 +       const char __user *target;
12392 +       uint32_t flags;
12393 +};
12394 +
12395 +
12396 +#ifdef __KERNEL__
12397 +
12398 +#ifdef CONFIG_COMPAT
12399 +
12400 +#include <asm/compat.h>
12401 +
12402 +struct vcmd_set_mapping_v0_x32 {
12403 +       compat_uptr_t device_ptr;
12404 +       compat_uptr_t target_ptr;
12405 +       uint32_t flags;
12406 +};
12407 +
12408 +#endif /* CONFIG_COMPAT */
12409 +
12410 +#include <linux/compiler.h>
12411 +
12412 +extern int vc_set_mapping(struct vx_info *, void __user *);
12413 +extern int vc_unset_mapping(struct vx_info *, void __user *);
12414 +
12415 +#ifdef CONFIG_COMPAT
12416 +
12417 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
12418 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
12419 +
12420 +#endif /* CONFIG_COMPAT */
12421 +
12422 +#endif /* __KERNEL__ */
12423 +#endif /* _VX_DEVICE_CMD_H */
12424 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/device_def.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/device_def.h
12425 --- linux-3.0-rc5/include/linux/vserver/device_def.h    1970-01-01 01:00:00.000000000 +0100
12426 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/device_def.h       2011-06-10 22:11:24.000000000 +0200
12427 @@ -0,0 +1,17 @@
12428 +#ifndef _VX_DEVICE_DEF_H
12429 +#define _VX_DEVICE_DEF_H
12430 +
12431 +#include <linux/types.h>
12432 +
12433 +struct vx_dmap_target {
12434 +       dev_t target;
12435 +       uint32_t flags;
12436 +};
12437 +
12438 +struct _vx_device {
12439 +#ifdef CONFIG_VSERVER_DEVICE
12440 +       struct vx_dmap_target targets[2];
12441 +#endif
12442 +};
12443 +
12444 +#endif /* _VX_DEVICE_DEF_H */
12445 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/dlimit.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/dlimit.h
12446 --- linux-3.0-rc5/include/linux/vserver/dlimit.h        1970-01-01 01:00:00.000000000 +0100
12447 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/dlimit.h   2011-06-10 22:11:24.000000000 +0200
12448 @@ -0,0 +1,54 @@
12449 +#ifndef _VX_DLIMIT_H
12450 +#define _VX_DLIMIT_H
12451 +
12452 +#include "switch.h"
12453 +
12454 +
12455 +#ifdef __KERNEL__
12456 +
12457 +/*      keep in sync with CDLIM_INFINITY       */
12458 +
12459 +#define DLIM_INFINITY          (~0ULL)
12460 +
12461 +#include <linux/spinlock.h>
12462 +#include <linux/rcupdate.h>
12463 +
12464 +struct super_block;
12465 +
12466 +struct dl_info {
12467 +       struct hlist_node dl_hlist;             /* linked list of contexts */
12468 +       struct rcu_head dl_rcu;                 /* the rcu head */
12469 +       tag_t dl_tag;                           /* context tag */
12470 +       atomic_t dl_usecnt;                     /* usage count */
12471 +       atomic_t dl_refcnt;                     /* reference count */
12472 +
12473 +       struct super_block *dl_sb;              /* associated superblock */
12474 +
12475 +       spinlock_t dl_lock;                     /* protect the values */
12476 +
12477 +       unsigned long long dl_space_used;       /* used space in bytes */
12478 +       unsigned long long dl_space_total;      /* maximum space in bytes */
12479 +       unsigned long dl_inodes_used;           /* used inodes */
12480 +       unsigned long dl_inodes_total;          /* maximum inodes */
12481 +
12482 +       unsigned int dl_nrlmult;                /* non root limit mult */
12483 +};
12484 +
12485 +struct rcu_head;
12486 +
12487 +extern void rcu_free_dl_info(struct rcu_head *);
12488 +extern void unhash_dl_info(struct dl_info *);
12489 +
12490 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
12491 +
12492 +
12493 +struct kstatfs;
12494 +
12495 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
12496 +
12497 +typedef uint64_t dlsize_t;
12498 +
12499 +#endif /* __KERNEL__ */
12500 +#else  /* _VX_DLIMIT_H */
12501 +#warning duplicate inclusion
12502 +#endif /* _VX_DLIMIT_H */
12503 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/dlimit_cmd.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/dlimit_cmd.h
12504 --- linux-3.0-rc5/include/linux/vserver/dlimit_cmd.h    1970-01-01 01:00:00.000000000 +0100
12505 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/dlimit_cmd.h       2011-06-10 22:11:24.000000000 +0200
12506 @@ -0,0 +1,109 @@
12507 +#ifndef _VX_DLIMIT_CMD_H
12508 +#define _VX_DLIMIT_CMD_H
12509 +
12510 +
12511 +/*  dlimit vserver commands */
12512 +
12513 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
12514 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
12515 +
12516 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
12517 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
12518 +
12519 +struct vcmd_ctx_dlimit_base_v0 {
12520 +       const char __user *name;
12521 +       uint32_t flags;
12522 +};
12523 +
12524 +struct vcmd_ctx_dlimit_v0 {
12525 +       const char __user *name;
12526 +       uint32_t space_used;                    /* used space in kbytes */
12527 +       uint32_t space_total;                   /* maximum space in kbytes */
12528 +       uint32_t inodes_used;                   /* used inodes */
12529 +       uint32_t inodes_total;                  /* maximum inodes */
12530 +       uint32_t reserved;                      /* reserved for root in % */
12531 +       uint32_t flags;
12532 +};
12533 +
12534 +#define CDLIM_UNSET            ((uint32_t)0UL)
12535 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
12536 +#define CDLIM_KEEP             ((uint32_t)~1UL)
12537 +
12538 +#define DLIME_UNIT     0
12539 +#define DLIME_KILO     1
12540 +#define DLIME_MEGA     2
12541 +#define DLIME_GIGA     3
12542 +
12543 +#define DLIMF_SHIFT    0x10
12544 +
12545 +#define DLIMS_USED     0
12546 +#define DLIMS_TOTAL    2
12547 +
12548 +static inline
12549 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
12550 +{
12551 +       int exp = (flags & DLIMF_SHIFT) ?
12552 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
12553 +       return ((uint64_t)val) << (10 * exp);
12554 +}
12555 +
12556 +static inline
12557 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
12558 +{
12559 +       int exp = 0;
12560 +
12561 +       if (*flags & DLIMF_SHIFT) {
12562 +               while (val > (1LL << 32) && (exp < 3)) {
12563 +                       val >>= 10;
12564 +                       exp++;
12565 +               }
12566 +               *flags &= ~(DLIME_GIGA << shift);
12567 +               *flags |= exp << shift;
12568 +       } else
12569 +               val >>= 10;
12570 +       return val;
12571 +}
12572 +
12573 +#ifdef __KERNEL__
12574 +
12575 +#ifdef CONFIG_COMPAT
12576 +
12577 +#include <asm/compat.h>
12578 +
12579 +struct vcmd_ctx_dlimit_base_v0_x32 {
12580 +       compat_uptr_t name_ptr;
12581 +       uint32_t flags;
12582 +};
12583 +
12584 +struct vcmd_ctx_dlimit_v0_x32 {
12585 +       compat_uptr_t name_ptr;
12586 +       uint32_t space_used;                    /* used space in kbytes */
12587 +       uint32_t space_total;                   /* maximum space in kbytes */
12588 +       uint32_t inodes_used;                   /* used inodes */
12589 +       uint32_t inodes_total;                  /* maximum inodes */
12590 +       uint32_t reserved;                      /* reserved for root in % */
12591 +       uint32_t flags;
12592 +};
12593 +
12594 +#endif /* CONFIG_COMPAT */
12595 +
12596 +#include <linux/compiler.h>
12597 +
12598 +extern int vc_add_dlimit(uint32_t, void __user *);
12599 +extern int vc_rem_dlimit(uint32_t, void __user *);
12600 +
12601 +extern int vc_set_dlimit(uint32_t, void __user *);
12602 +extern int vc_get_dlimit(uint32_t, void __user *);
12603 +
12604 +#ifdef CONFIG_COMPAT
12605 +
12606 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
12607 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
12608 +
12609 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
12610 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
12611 +
12612 +#endif /* CONFIG_COMPAT */
12613 +
12614 +#endif /* __KERNEL__ */
12615 +#endif /* _VX_DLIMIT_CMD_H */
12616 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/global.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/global.h
12617 --- linux-3.0-rc5/include/linux/vserver/global.h        1970-01-01 01:00:00.000000000 +0100
12618 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/global.h   2011-06-10 22:11:24.000000000 +0200
12619 @@ -0,0 +1,19 @@
12620 +#ifndef _VX_GLOBAL_H
12621 +#define _VX_GLOBAL_H
12622 +
12623 +
12624 +extern atomic_t vx_global_ctotal;
12625 +extern atomic_t vx_global_cactive;
12626 +
12627 +extern atomic_t nx_global_ctotal;
12628 +extern atomic_t nx_global_cactive;
12629 +
12630 +extern atomic_t vs_global_nsproxy;
12631 +extern atomic_t vs_global_fs;
12632 +extern atomic_t vs_global_mnt_ns;
12633 +extern atomic_t vs_global_uts_ns;
12634 +extern atomic_t vs_global_user_ns;
12635 +extern atomic_t vs_global_pid_ns;
12636 +
12637 +
12638 +#endif /* _VX_GLOBAL_H */
12639 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/history.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/history.h
12640 --- linux-3.0-rc5/include/linux/vserver/history.h       1970-01-01 01:00:00.000000000 +0100
12641 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/history.h  2011-06-10 22:11:24.000000000 +0200
12642 @@ -0,0 +1,197 @@
12643 +#ifndef _VX_HISTORY_H
12644 +#define _VX_HISTORY_H
12645 +
12646 +
12647 +enum {
12648 +       VXH_UNUSED = 0,
12649 +       VXH_THROW_OOPS = 1,
12650 +
12651 +       VXH_GET_VX_INFO,
12652 +       VXH_PUT_VX_INFO,
12653 +       VXH_INIT_VX_INFO,
12654 +       VXH_SET_VX_INFO,
12655 +       VXH_CLR_VX_INFO,
12656 +       VXH_CLAIM_VX_INFO,
12657 +       VXH_RELEASE_VX_INFO,
12658 +       VXH_ALLOC_VX_INFO,
12659 +       VXH_DEALLOC_VX_INFO,
12660 +       VXH_HASH_VX_INFO,
12661 +       VXH_UNHASH_VX_INFO,
12662 +       VXH_LOC_VX_INFO,
12663 +       VXH_LOOKUP_VX_INFO,
12664 +       VXH_CREATE_VX_INFO,
12665 +};
12666 +
12667 +struct _vxhe_vxi {
12668 +       struct vx_info *ptr;
12669 +       unsigned xid;
12670 +       unsigned usecnt;
12671 +       unsigned tasks;
12672 +};
12673 +
12674 +struct _vxhe_set_clr {
12675 +       void *data;
12676 +};
12677 +
12678 +struct _vxhe_loc_lookup {
12679 +       unsigned arg;
12680 +};
12681 +
12682 +struct _vx_hist_entry {
12683 +       void *loc;
12684 +       unsigned short seq;
12685 +       unsigned short type;
12686 +       struct _vxhe_vxi vxi;
12687 +       union {
12688 +               struct _vxhe_set_clr sc;
12689 +               struct _vxhe_loc_lookup ll;
12690 +       };
12691 +};
12692 +
12693 +#ifdef CONFIG_VSERVER_HISTORY
12694 +
12695 +extern unsigned volatile int vxh_active;
12696 +
12697 +struct _vx_hist_entry *vxh_advance(void *loc);
12698 +
12699 +
12700 +static inline
12701 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
12702 +{
12703 +       entry->vxi.ptr = vxi;
12704 +       if (vxi) {
12705 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
12706 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
12707 +               entry->vxi.xid = vxi->vx_id;
12708 +       }
12709 +}
12710 +
12711 +
12712 +#define        __HERE__ current_text_addr()
12713 +
12714 +#define __VXH_BODY(__type, __data, __here)     \
12715 +       struct _vx_hist_entry *entry;           \
12716 +                                               \
12717 +       preempt_disable();                      \
12718 +       entry = vxh_advance(__here);            \
12719 +       __data;                                 \
12720 +       entry->type = __type;                   \
12721 +       preempt_enable();
12722 +
12723 +
12724 +       /* pass vxi only */
12725 +
12726 +#define __VXH_SMPL                             \
12727 +       __vxh_copy_vxi(entry, vxi)
12728 +
12729 +static inline
12730 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
12731 +{
12732 +       __VXH_BODY(__type, __VXH_SMPL, __here)
12733 +}
12734 +
12735 +       /* pass vxi and data (void *) */
12736 +
12737 +#define __VXH_DATA                             \
12738 +       __vxh_copy_vxi(entry, vxi);             \
12739 +       entry->sc.data = data
12740 +
12741 +static inline
12742 +void   __vxh_data(struct vx_info *vxi, void *data,
12743 +                       int __type, void *__here)
12744 +{
12745 +       __VXH_BODY(__type, __VXH_DATA, __here)
12746 +}
12747 +
12748 +       /* pass vxi and arg (long) */
12749 +
12750 +#define __VXH_LONG                             \
12751 +       __vxh_copy_vxi(entry, vxi);             \
12752 +       entry->ll.arg = arg
12753 +
12754 +static inline
12755 +void   __vxh_long(struct vx_info *vxi, long arg,
12756 +                       int __type, void *__here)
12757 +{
12758 +       __VXH_BODY(__type, __VXH_LONG, __here)
12759 +}
12760 +
12761 +
12762 +static inline
12763 +void   __vxh_throw_oops(void *__here)
12764 +{
12765 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
12766 +       /* prevent further acquisition */
12767 +       vxh_active = 0;
12768 +}
12769 +
12770 +
12771 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
12772 +
12773 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
12774 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
12775 +
12776 +#define __vxh_init_vx_info(v, d, h) \
12777 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
12778 +#define __vxh_set_vx_info(v, d, h) \
12779 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
12780 +#define __vxh_clr_vx_info(v, d, h) \
12781 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
12782 +
12783 +#define __vxh_claim_vx_info(v, d, h) \
12784 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
12785 +#define __vxh_release_vx_info(v, d, h) \
12786 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
12787 +
12788 +#define vxh_alloc_vx_info(v) \
12789 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
12790 +#define vxh_dealloc_vx_info(v) \
12791 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
12792 +
12793 +#define vxh_hash_vx_info(v) \
12794 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
12795 +#define vxh_unhash_vx_info(v) \
12796 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
12797 +
12798 +#define vxh_loc_vx_info(v, l) \
12799 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
12800 +#define vxh_lookup_vx_info(v, l) \
12801 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
12802 +#define vxh_create_vx_info(v, l) \
12803 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
12804 +
12805 +extern void vxh_dump_history(void);
12806 +
12807 +
12808 +#else  /* CONFIG_VSERVER_HISTORY */
12809 +
12810 +#define        __HERE__        0
12811 +
12812 +#define vxh_throw_oops()               do { } while (0)
12813 +
12814 +#define __vxh_get_vx_info(v, h)                do { } while (0)
12815 +#define __vxh_put_vx_info(v, h)                do { } while (0)
12816 +
12817 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
12818 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
12819 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
12820 +
12821 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
12822 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
12823 +
12824 +#define vxh_alloc_vx_info(v)           do { } while (0)
12825 +#define vxh_dealloc_vx_info(v)         do { } while (0)
12826 +
12827 +#define vxh_hash_vx_info(v)            do { } while (0)
12828 +#define vxh_unhash_vx_info(v)          do { } while (0)
12829 +
12830 +#define vxh_loc_vx_info(v, l)          do { } while (0)
12831 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
12832 +#define vxh_create_vx_info(v, l)       do { } while (0)
12833 +
12834 +#define vxh_dump_history()             do { } while (0)
12835 +
12836 +
12837 +#endif /* CONFIG_VSERVER_HISTORY */
12838 +
12839 +#endif /* _VX_HISTORY_H */
12840 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/inode.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/inode.h
12841 --- linux-3.0-rc5/include/linux/vserver/inode.h 1970-01-01 01:00:00.000000000 +0100
12842 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/inode.h    2011-06-10 22:11:24.000000000 +0200
12843 @@ -0,0 +1,39 @@
12844 +#ifndef _VX_INODE_H
12845 +#define _VX_INODE_H
12846 +
12847 +
12848 +#define IATTR_TAG      0x01000000
12849 +
12850 +#define IATTR_ADMIN    0x00000001
12851 +#define IATTR_WATCH    0x00000002
12852 +#define IATTR_HIDE     0x00000004
12853 +#define IATTR_FLAGS    0x00000007
12854 +
12855 +#define IATTR_BARRIER  0x00010000
12856 +#define IATTR_IXUNLINK 0x00020000
12857 +#define IATTR_IMMUTABLE 0x00040000
12858 +#define IATTR_COW      0x00080000
12859 +
12860 +#ifdef __KERNEL__
12861 +
12862 +
12863 +#ifdef CONFIG_VSERVER_PROC_SECURE
12864 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
12865 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
12866 +#else
12867 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
12868 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
12869 +#endif
12870 +
12871 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
12872 +
12873 +#endif /* __KERNEL__ */
12874 +
12875 +/* inode ioctls */
12876 +
12877 +#define FIOC_GETXFLG   _IOR('x', 5, long)
12878 +#define FIOC_SETXFLG   _IOW('x', 6, long)
12879 +
12880 +#else  /* _VX_INODE_H */
12881 +#warning duplicate inclusion
12882 +#endif /* _VX_INODE_H */
12883 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/inode_cmd.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/inode_cmd.h
12884 --- linux-3.0-rc5/include/linux/vserver/inode_cmd.h     1970-01-01 01:00:00.000000000 +0100
12885 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/inode_cmd.h        2011-06-10 22:11:24.000000000 +0200
12886 @@ -0,0 +1,59 @@
12887 +#ifndef _VX_INODE_CMD_H
12888 +#define _VX_INODE_CMD_H
12889 +
12890 +
12891 +/*  inode vserver commands */
12892 +
12893 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
12894 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
12895 +
12896 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
12897 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
12898 +
12899 +struct vcmd_ctx_iattr_v1 {
12900 +       const char __user *name;
12901 +       uint32_t tag;
12902 +       uint32_t flags;
12903 +       uint32_t mask;
12904 +};
12905 +
12906 +struct vcmd_ctx_fiattr_v0 {
12907 +       uint32_t tag;
12908 +       uint32_t flags;
12909 +       uint32_t mask;
12910 +};
12911 +
12912 +
12913 +#ifdef __KERNEL__
12914 +
12915 +
12916 +#ifdef CONFIG_COMPAT
12917 +
12918 +#include <asm/compat.h>
12919 +
12920 +struct vcmd_ctx_iattr_v1_x32 {
12921 +       compat_uptr_t name_ptr;
12922 +       uint32_t tag;
12923 +       uint32_t flags;
12924 +       uint32_t mask;
12925 +};
12926 +
12927 +#endif /* CONFIG_COMPAT */
12928 +
12929 +#include <linux/compiler.h>
12930 +
12931 +extern int vc_get_iattr(void __user *);
12932 +extern int vc_set_iattr(void __user *);
12933 +
12934 +extern int vc_fget_iattr(uint32_t, void __user *);
12935 +extern int vc_fset_iattr(uint32_t, void __user *);
12936 +
12937 +#ifdef CONFIG_COMPAT
12938 +
12939 +extern int vc_get_iattr_x32(void __user *);
12940 +extern int vc_set_iattr_x32(void __user *);
12941 +
12942 +#endif /* CONFIG_COMPAT */
12943 +
12944 +#endif /* __KERNEL__ */
12945 +#endif /* _VX_INODE_CMD_H */
12946 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/limit.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/limit.h
12947 --- linux-3.0-rc5/include/linux/vserver/limit.h 1970-01-01 01:00:00.000000000 +0100
12948 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/limit.h    2011-06-10 22:11:24.000000000 +0200
12949 @@ -0,0 +1,71 @@
12950 +#ifndef _VX_LIMIT_H
12951 +#define _VX_LIMIT_H
12952 +
12953 +#define VLIMIT_NSOCK   16
12954 +#define VLIMIT_OPENFD  17
12955 +#define VLIMIT_ANON    18
12956 +#define VLIMIT_SHMEM   19
12957 +#define VLIMIT_SEMARY  20
12958 +#define VLIMIT_NSEMS   21
12959 +#define VLIMIT_DENTRY  22
12960 +#define VLIMIT_MAPPED  23
12961 +
12962 +
12963 +#ifdef __KERNEL__
12964 +
12965 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
12966 +
12967 +/*     keep in sync with CRLIM_INFINITY */
12968 +
12969 +#define        VLIM_INFINITY   (~0ULL)
12970 +
12971 +#include <asm/atomic.h>
12972 +#include <asm/resource.h>
12973 +
12974 +#ifndef RLIM_INFINITY
12975 +#warning RLIM_INFINITY is undefined
12976 +#endif
12977 +
12978 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
12979 +
12980 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
12981 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
12982 +
12983 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
12984 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
12985 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
12986 +
12987 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
12988 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
12989 +
12990 +typedef atomic_long_t rlim_atomic_t;
12991 +typedef unsigned long rlim_t;
12992 +
12993 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
12994 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
12995 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
12996 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
12997 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
12998 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
12999 +
13000 +
13001 +#if    (RLIM_INFINITY == VLIM_INFINITY)
13002 +#define        VX_VLIM(r) ((long long)(long)(r))
13003 +#define        VX_RLIM(v) ((rlim_t)(v))
13004 +#else
13005 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
13006 +               ? VLIM_INFINITY : (long long)(r))
13007 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
13008 +               ? RLIM_INFINITY : (rlim_t)(v))
13009 +#endif
13010 +
13011 +struct sysinfo;
13012 +
13013 +void vx_vsi_meminfo(struct sysinfo *);
13014 +void vx_vsi_swapinfo(struct sysinfo *);
13015 +long vx_vsi_cached(struct sysinfo *);
13016 +
13017 +#define NUM_LIMITS     24
13018 +
13019 +#endif /* __KERNEL__ */
13020 +#endif /* _VX_LIMIT_H */
13021 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/limit_cmd.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/limit_cmd.h
13022 --- linux-3.0-rc5/include/linux/vserver/limit_cmd.h     1970-01-01 01:00:00.000000000 +0100
13023 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/limit_cmd.h        2011-06-10 22:11:24.000000000 +0200
13024 @@ -0,0 +1,71 @@
13025 +#ifndef _VX_LIMIT_CMD_H
13026 +#define _VX_LIMIT_CMD_H
13027 +
13028 +
13029 +/*  rlimit vserver commands */
13030 +
13031 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
13032 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
13033 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
13034 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
13035 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
13036 +
13037 +struct vcmd_ctx_rlimit_v0 {
13038 +       uint32_t id;
13039 +       uint64_t minimum;
13040 +       uint64_t softlimit;
13041 +       uint64_t maximum;
13042 +};
13043 +
13044 +struct vcmd_ctx_rlimit_mask_v0 {
13045 +       uint32_t minimum;
13046 +       uint32_t softlimit;
13047 +       uint32_t maximum;
13048 +};
13049 +
13050 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
13051 +
13052 +struct vcmd_rlimit_stat_v0 {
13053 +       uint32_t id;
13054 +       uint32_t hits;
13055 +       uint64_t value;
13056 +       uint64_t minimum;
13057 +       uint64_t maximum;
13058 +};
13059 +
13060 +#define CRLIM_UNSET            (0ULL)
13061 +#define CRLIM_INFINITY         (~0ULL)
13062 +#define CRLIM_KEEP             (~1ULL)
13063 +
13064 +#ifdef __KERNEL__
13065 +
13066 +#ifdef CONFIG_IA32_EMULATION
13067 +
13068 +struct vcmd_ctx_rlimit_v0_x32 {
13069 +       uint32_t id;
13070 +       uint64_t minimum;
13071 +       uint64_t softlimit;
13072 +       uint64_t maximum;
13073 +} __attribute__ ((packed));
13074 +
13075 +#endif /* CONFIG_IA32_EMULATION */
13076 +
13077 +#include <linux/compiler.h>
13078 +
13079 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
13080 +extern int vc_get_rlimit(struct vx_info *, void __user *);
13081 +extern int vc_set_rlimit(struct vx_info *, void __user *);
13082 +extern int vc_reset_hits(struct vx_info *, void __user *);
13083 +extern int vc_reset_minmax(struct vx_info *, void __user *);
13084 +
13085 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
13086 +
13087 +#ifdef CONFIG_IA32_EMULATION
13088 +
13089 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
13090 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
13091 +
13092 +#endif /* CONFIG_IA32_EMULATION */
13093 +
13094 +#endif /* __KERNEL__ */
13095 +#endif /* _VX_LIMIT_CMD_H */
13096 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/limit_def.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/limit_def.h
13097 --- linux-3.0-rc5/include/linux/vserver/limit_def.h     1970-01-01 01:00:00.000000000 +0100
13098 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/limit_def.h        2011-06-10 22:11:24.000000000 +0200
13099 @@ -0,0 +1,47 @@
13100 +#ifndef _VX_LIMIT_DEF_H
13101 +#define _VX_LIMIT_DEF_H
13102 +
13103 +#include <asm/atomic.h>
13104 +#include <asm/resource.h>
13105 +
13106 +#include "limit.h"
13107 +
13108 +
13109 +struct _vx_res_limit {
13110 +       rlim_t soft;            /* Context soft limit */
13111 +       rlim_t hard;            /* Context hard limit */
13112 +
13113 +       rlim_atomic_t rcur;     /* Current value */
13114 +       rlim_t rmin;            /* Context minimum */
13115 +       rlim_t rmax;            /* Context maximum */
13116 +
13117 +       atomic_t lhit;          /* Limit hits */
13118 +};
13119 +
13120 +/* context sub struct */
13121 +
13122 +struct _vx_limit {
13123 +       struct _vx_res_limit res[NUM_LIMITS];
13124 +};
13125 +
13126 +#ifdef CONFIG_VSERVER_DEBUG
13127 +
13128 +static inline void __dump_vx_limit(struct _vx_limit *limit)
13129 +{
13130 +       int i;
13131 +
13132 +       printk("\t_vx_limit:");
13133 +       for (i = 0; i < NUM_LIMITS; i++) {
13134 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
13135 +                       i, (unsigned long)__rlim_get(limit, i),
13136 +                       (unsigned long)__rlim_rmin(limit, i),
13137 +                       (unsigned long)__rlim_rmax(limit, i),
13138 +                       (long)__rlim_soft(limit, i),
13139 +                       (long)__rlim_hard(limit, i),
13140 +                       atomic_read(&__rlim_lhit(limit, i)));
13141 +       }
13142 +}
13143 +
13144 +#endif
13145 +
13146 +#endif /* _VX_LIMIT_DEF_H */
13147 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/limit_int.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/limit_int.h
13148 --- linux-3.0-rc5/include/linux/vserver/limit_int.h     1970-01-01 01:00:00.000000000 +0100
13149 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/limit_int.h        2011-06-10 22:11:24.000000000 +0200
13150 @@ -0,0 +1,198 @@
13151 +#ifndef _VX_LIMIT_INT_H
13152 +#define _VX_LIMIT_INT_H
13153 +
13154 +#include "context.h"
13155 +
13156 +#ifdef __KERNEL__
13157 +
13158 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
13159 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
13160 +
13161 +extern const char *vlimit_name[NUM_LIMITS];
13162 +
13163 +static inline void __vx_acc_cres(struct vx_info *vxi,
13164 +       int res, int dir, void *_data, char *_file, int _line)
13165 +{
13166 +       if (VXD_RCRES_COND(res))
13167 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
13168 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
13169 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
13170 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
13171 +       if (!vxi)
13172 +               return;
13173 +
13174 +       if (dir > 0)
13175 +               __rlim_inc(&vxi->limit, res);
13176 +       else
13177 +               __rlim_dec(&vxi->limit, res);
13178 +}
13179 +
13180 +static inline void __vx_add_cres(struct vx_info *vxi,
13181 +       int res, int amount, void *_data, char *_file, int _line)
13182 +{
13183 +       if (VXD_RCRES_COND(res))
13184 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
13185 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
13186 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
13187 +                       amount, _data, _file, _line);
13188 +       if (amount == 0)
13189 +               return;
13190 +       if (!vxi)
13191 +               return;
13192 +       __rlim_add(&vxi->limit, res, amount);
13193 +}
13194 +
13195 +static inline
13196 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
13197 +{
13198 +       int cond = (value > __rlim_rmax(limit, res));
13199 +
13200 +       if (cond)
13201 +               __rlim_rmax(limit, res) = value;
13202 +       return cond;
13203 +}
13204 +
13205 +static inline
13206 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
13207 +{
13208 +       int cond = (value < __rlim_rmin(limit, res));
13209 +
13210 +       if (cond)
13211 +               __rlim_rmin(limit, res) = value;
13212 +       return cond;
13213 +}
13214 +
13215 +static inline
13216 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
13217 +{
13218 +       if (!__vx_cres_adjust_max(limit, res, value))
13219 +               __vx_cres_adjust_min(limit, res, value);
13220 +}
13221 +
13222 +
13223 +/*     return values:
13224 +        +1 ... no limit hit
13225 +        -1 ... over soft limit
13226 +         0 ... over hard limit         */
13227 +
13228 +static inline int __vx_cres_avail(struct vx_info *vxi,
13229 +       int res, int num, char *_file, int _line)
13230 +{
13231 +       struct _vx_limit *limit;
13232 +       rlim_t value;
13233 +
13234 +       if (VXD_RLIMIT_COND(res))
13235 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
13236 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
13237 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
13238 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
13239 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
13240 +                       num, _file, _line);
13241 +       if (!vxi)
13242 +               return 1;
13243 +
13244 +       limit = &vxi->limit;
13245 +       value = __rlim_get(limit, res);
13246 +
13247 +       if (!__vx_cres_adjust_max(limit, res, value))
13248 +               __vx_cres_adjust_min(limit, res, value);
13249 +
13250 +       if (num == 0)
13251 +               return 1;
13252 +
13253 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
13254 +               return -1;
13255 +       if (value + num <= __rlim_soft(limit, res))
13256 +               return -1;
13257 +
13258 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
13259 +               return 1;
13260 +       if (value + num <= __rlim_hard(limit, res))
13261 +               return 1;
13262 +
13263 +       __rlim_hit(limit, res);
13264 +       return 0;
13265 +}
13266 +
13267 +
13268 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
13269 +
13270 +static inline
13271 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
13272 +{
13273 +       rlim_t value, sum = 0;
13274 +       int res;
13275 +
13276 +       while ((res = *array++)) {
13277 +               value = __rlim_get(limit, res);
13278 +               __vx_cres_fixup(limit, res, value);
13279 +               sum += value;
13280 +       }
13281 +       return sum;
13282 +}
13283 +
13284 +static inline
13285 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
13286 +{
13287 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
13288 +       int res = *array;
13289 +
13290 +       if (value == __rlim_get(limit, res))
13291 +               return value;
13292 +
13293 +       __rlim_set(limit, res, value);
13294 +       /* now adjust min/max */
13295 +       if (!__vx_cres_adjust_max(limit, res, value))
13296 +               __vx_cres_adjust_min(limit, res, value);
13297 +
13298 +       return value;
13299 +}
13300 +
13301 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
13302 +       const int *array, int num, char *_file, int _line)
13303 +{
13304 +       struct _vx_limit *limit;
13305 +       rlim_t value = 0;
13306 +       int res;
13307 +
13308 +       if (num == 0)
13309 +               return 1;
13310 +       if (!vxi)
13311 +               return 1;
13312 +
13313 +       limit = &vxi->limit;
13314 +       res = *array;
13315 +       value = __vx_cres_array_sum(limit, array + 1);
13316 +
13317 +       __rlim_set(limit, res, value);
13318 +       __vx_cres_fixup(limit, res, value);
13319 +
13320 +       return __vx_cres_avail(vxi, res, num, _file, _line);
13321 +}
13322 +
13323 +
13324 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
13325 +{
13326 +       rlim_t value;
13327 +       int res;
13328 +
13329 +       /* complex resources first */
13330 +       if ((id < 0) || (id == RLIMIT_RSS))
13331 +               __vx_cres_array_fixup(limit, VLA_RSS);
13332 +
13333 +       for (res = 0; res < NUM_LIMITS; res++) {
13334 +               if ((id > 0) && (res != id))
13335 +                       continue;
13336 +
13337 +               value = __rlim_get(limit, res);
13338 +               __vx_cres_fixup(limit, res, value);
13339 +
13340 +               /* not supposed to happen, maybe warn? */
13341 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
13342 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
13343 +       }
13344 +}
13345 +
13346 +
13347 +#endif /* __KERNEL__ */
13348 +#endif /* _VX_LIMIT_INT_H */
13349 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/monitor.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/monitor.h
13350 --- linux-3.0-rc5/include/linux/vserver/monitor.h       1970-01-01 01:00:00.000000000 +0100
13351 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/monitor.h  2011-06-10 22:11:24.000000000 +0200
13352 @@ -0,0 +1,96 @@
13353 +#ifndef _VX_MONITOR_H
13354 +#define _VX_MONITOR_H
13355 +
13356 +#include <linux/types.h>
13357 +
13358 +enum {
13359 +       VXM_UNUSED = 0,
13360 +
13361 +       VXM_SYNC = 0x10,
13362 +
13363 +       VXM_UPDATE = 0x20,
13364 +       VXM_UPDATE_1,
13365 +       VXM_UPDATE_2,
13366 +
13367 +       VXM_RQINFO_1 = 0x24,
13368 +       VXM_RQINFO_2,
13369 +
13370 +       VXM_ACTIVATE = 0x40,
13371 +       VXM_DEACTIVATE,
13372 +       VXM_IDLE,
13373 +
13374 +       VXM_HOLD = 0x44,
13375 +       VXM_UNHOLD,
13376 +
13377 +       VXM_MIGRATE = 0x48,
13378 +       VXM_RESCHED,
13379 +
13380 +       /* all other bits are flags */
13381 +       VXM_SCHED = 0x80,
13382 +};
13383 +
13384 +struct _vxm_update_1 {
13385 +       uint32_t tokens_max;
13386 +       uint32_t fill_rate;
13387 +       uint32_t interval;
13388 +};
13389 +
13390 +struct _vxm_update_2 {
13391 +       uint32_t tokens_min;
13392 +       uint32_t fill_rate;
13393 +       uint32_t interval;
13394 +};
13395 +
13396 +struct _vxm_rqinfo_1 {
13397 +       uint16_t running;
13398 +       uint16_t onhold;
13399 +       uint16_t iowait;
13400 +       uint16_t uintr;
13401 +       uint32_t idle_tokens;
13402 +};
13403 +
13404 +struct _vxm_rqinfo_2 {
13405 +       uint32_t norm_time;
13406 +       uint32_t idle_time;
13407 +       uint32_t idle_skip;
13408 +};
13409 +
13410 +struct _vxm_sched {
13411 +       uint32_t tokens;
13412 +       uint32_t norm_time;
13413 +       uint32_t idle_time;
13414 +};
13415 +
13416 +struct _vxm_task {
13417 +       uint16_t pid;
13418 +       uint16_t state;
13419 +};
13420 +
13421 +struct _vxm_event {
13422 +       uint32_t jif;
13423 +       union {
13424 +               uint32_t seq;
13425 +               uint32_t sec;
13426 +       };
13427 +       union {
13428 +               uint32_t tokens;
13429 +               uint32_t nsec;
13430 +               struct _vxm_task tsk;
13431 +       };
13432 +};
13433 +
13434 +struct _vx_mon_entry {
13435 +       uint16_t type;
13436 +       uint16_t xid;
13437 +       union {
13438 +               struct _vxm_event ev;
13439 +               struct _vxm_sched sd;
13440 +               struct _vxm_update_1 u1;
13441 +               struct _vxm_update_2 u2;
13442 +               struct _vxm_rqinfo_1 q1;
13443 +               struct _vxm_rqinfo_2 q2;
13444 +       };
13445 +};
13446 +
13447 +
13448 +#endif /* _VX_MONITOR_H */
13449 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/network.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/network.h
13450 --- linux-3.0-rc5/include/linux/vserver/network.h       1970-01-01 01:00:00.000000000 +0100
13451 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/network.h  2011-06-10 22:11:24.000000000 +0200
13452 @@ -0,0 +1,146 @@
13453 +#ifndef _VX_NETWORK_H
13454 +#define _VX_NETWORK_H
13455 +
13456 +#include <linux/types.h>
13457 +
13458 +
13459 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
13460 +
13461 +
13462 +/* network flags */
13463 +
13464 +#define NXF_INFO_PRIVATE       0x00000008
13465 +
13466 +#define NXF_SINGLE_IP          0x00000100
13467 +#define NXF_LBACK_REMAP                0x00000200
13468 +#define NXF_LBACK_ALLOW                0x00000400
13469 +
13470 +#define NXF_HIDE_NETIF         0x02000000
13471 +#define NXF_HIDE_LBACK         0x04000000
13472 +
13473 +#define NXF_STATE_SETUP                (1ULL << 32)
13474 +#define NXF_STATE_ADMIN                (1ULL << 34)
13475 +
13476 +#define NXF_SC_HELPER          (1ULL << 36)
13477 +#define NXF_PERSISTENT         (1ULL << 38)
13478 +
13479 +#define NXF_ONE_TIME           (0x0005ULL << 32)
13480 +
13481 +
13482 +#define        NXF_INIT_SET            (__nxf_init_set())
13483 +
13484 +static inline uint64_t __nxf_init_set(void) {
13485 +       return    NXF_STATE_ADMIN
13486 +#ifdef CONFIG_VSERVER_AUTO_LBACK
13487 +               | NXF_LBACK_REMAP
13488 +               | NXF_HIDE_LBACK
13489 +#endif
13490 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
13491 +               | NXF_SINGLE_IP
13492 +#endif
13493 +               | NXF_HIDE_NETIF;
13494 +}
13495 +
13496 +
13497 +/* network caps */
13498 +
13499 +#define NXC_TUN_CREATE         0x00000001
13500 +
13501 +#define NXC_RAW_ICMP           0x00000100
13502 +
13503 +
13504 +/* address types */
13505 +
13506 +#define NXA_TYPE_IPV4          0x0001
13507 +#define NXA_TYPE_IPV6          0x0002
13508 +
13509 +#define NXA_TYPE_NONE          0x0000
13510 +#define NXA_TYPE_ANY           0x00FF
13511 +
13512 +#define NXA_TYPE_ADDR          0x0010
13513 +#define NXA_TYPE_MASK          0x0020
13514 +#define NXA_TYPE_RANGE         0x0040
13515 +
13516 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
13517 +
13518 +#define NXA_MOD_BCAST          0x0100
13519 +#define NXA_MOD_LBACK          0x0200
13520 +
13521 +#define NXA_LOOPBACK           0x1000
13522 +
13523 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
13524 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
13525 +
13526 +#ifdef __KERNEL__
13527 +
13528 +#include <linux/list.h>
13529 +#include <linux/spinlock.h>
13530 +#include <linux/rcupdate.h>
13531 +#include <linux/in.h>
13532 +#include <linux/in6.h>
13533 +#include <asm/atomic.h>
13534 +
13535 +struct nx_addr_v4 {
13536 +       struct nx_addr_v4 *next;
13537 +       struct in_addr ip[2];
13538 +       struct in_addr mask;
13539 +       uint16_t type;
13540 +       uint16_t flags;
13541 +};
13542 +
13543 +struct nx_addr_v6 {
13544 +       struct nx_addr_v6 *next;
13545 +       struct in6_addr ip;
13546 +       struct in6_addr mask;
13547 +       uint32_t prefix;
13548 +       uint16_t type;
13549 +       uint16_t flags;
13550 +};
13551 +
13552 +struct nx_info {
13553 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
13554 +       nid_t nx_id;                    /* vnet id */
13555 +       atomic_t nx_usecnt;             /* usage count */
13556 +       atomic_t nx_tasks;              /* tasks count */
13557 +       int nx_state;                   /* context state */
13558 +
13559 +       uint64_t nx_flags;              /* network flag word */
13560 +       uint64_t nx_ncaps;              /* network capabilities */
13561 +
13562 +       struct in_addr v4_lback;        /* Loopback address */
13563 +       struct in_addr v4_bcast;        /* Broadcast address */
13564 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
13565 +#ifdef CONFIG_IPV6
13566 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
13567 +#endif
13568 +       char nx_name[65];               /* network context name */
13569 +};
13570 +
13571 +
13572 +/* status flags */
13573 +
13574 +#define NXS_HASHED      0x0001
13575 +#define NXS_SHUTDOWN    0x0100
13576 +#define NXS_RELEASED    0x8000
13577 +
13578 +extern struct nx_info *lookup_nx_info(int);
13579 +
13580 +extern int get_nid_list(int, unsigned int *, int);
13581 +extern int nid_is_hashed(nid_t);
13582 +
13583 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
13584 +
13585 +extern long vs_net_change(struct nx_info *, unsigned int);
13586 +
13587 +struct sock;
13588 +
13589 +
13590 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
13591 +#ifdef  CONFIG_IPV6
13592 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
13593 +#else
13594 +#define NX_IPV6(n)     (0)
13595 +#endif
13596 +
13597 +#endif /* __KERNEL__ */
13598 +#endif /* _VX_NETWORK_H */
13599 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/network_cmd.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/network_cmd.h
13600 --- linux-3.0-rc5/include/linux/vserver/network_cmd.h   1970-01-01 01:00:00.000000000 +0100
13601 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/network_cmd.h      2011-06-10 22:11:24.000000000 +0200
13602 @@ -0,0 +1,164 @@
13603 +#ifndef _VX_NETWORK_CMD_H
13604 +#define _VX_NETWORK_CMD_H
13605 +
13606 +
13607 +/* vinfo commands */
13608 +
13609 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
13610 +
13611 +#ifdef __KERNEL__
13612 +extern int vc_task_nid(uint32_t);
13613 +
13614 +#endif /* __KERNEL__ */
13615 +
13616 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
13617 +
13618 +struct vcmd_nx_info_v0 {
13619 +       uint32_t nid;
13620 +       /* more to come */
13621 +};
13622 +
13623 +#ifdef __KERNEL__
13624 +extern int vc_nx_info(struct nx_info *, void __user *);
13625 +
13626 +#endif /* __KERNEL__ */
13627 +
13628 +#include <linux/in.h>
13629 +#include <linux/in6.h>
13630 +
13631 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
13632 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
13633 +
13634 +struct  vcmd_net_create {
13635 +       uint64_t flagword;
13636 +};
13637 +
13638 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
13639 +
13640 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
13641 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
13642 +
13643 +struct vcmd_net_addr_v0 {
13644 +       uint16_t type;
13645 +       uint16_t count;
13646 +       struct in_addr ip[4];
13647 +       struct in_addr mask[4];
13648 +};
13649 +
13650 +#define VCMD_net_add_ipv4_v1   VC_CMD(NETALT, 1, 1)
13651 +#define VCMD_net_rem_ipv4_v1   VC_CMD(NETALT, 2, 1)
13652 +
13653 +struct vcmd_net_addr_ipv4_v1 {
13654 +       uint16_t type;
13655 +       uint16_t flags;
13656 +       struct in_addr ip;
13657 +       struct in_addr mask;
13658 +};
13659 +
13660 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 2)
13661 +#define VCMD_net_rem_ipv4      VC_CMD(NETALT, 2, 2)
13662 +
13663 +struct vcmd_net_addr_ipv4_v2 {
13664 +       uint16_t type;
13665 +       uint16_t flags;
13666 +       struct in_addr ip;
13667 +       struct in_addr ip2;
13668 +       struct in_addr mask;
13669 +};
13670 +
13671 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
13672 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
13673 +
13674 +struct vcmd_net_addr_ipv6_v1 {
13675 +       uint16_t type;
13676 +       uint16_t flags;
13677 +       uint32_t prefix;
13678 +       struct in6_addr ip;
13679 +       struct in6_addr mask;
13680 +};
13681 +
13682 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
13683 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
13684 +
13685 +struct vcmd_match_ipv4_v0 {
13686 +       uint16_t type;
13687 +       uint16_t flags;
13688 +       uint16_t parent;
13689 +       uint16_t prefix;
13690 +       struct in_addr ip;
13691 +       struct in_addr ip2;
13692 +       struct in_addr mask;
13693 +};
13694 +
13695 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
13696 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
13697 +
13698 +struct vcmd_match_ipv6_v0 {
13699 +       uint16_t type;
13700 +       uint16_t flags;
13701 +       uint16_t parent;
13702 +       uint16_t prefix;
13703 +       struct in6_addr ip;
13704 +       struct in6_addr ip2;
13705 +       struct in6_addr mask;
13706 +};
13707 +
13708 +
13709 +#ifdef __KERNEL__
13710 +extern int vc_net_create(uint32_t, void __user *);
13711 +extern int vc_net_migrate(struct nx_info *, void __user *);
13712 +
13713 +extern int vc_net_add(struct nx_info *, void __user *);
13714 +extern int vc_net_remove(struct nx_info *, void __user *);
13715 +
13716 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
13717 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
13718 +
13719 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
13720 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
13721 +
13722 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
13723 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
13724 +
13725 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
13726 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
13727 +
13728 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
13729 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
13730 +
13731 +#endif /* __KERNEL__ */
13732 +
13733 +
13734 +/* flag commands */
13735 +
13736 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
13737 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
13738 +
13739 +struct vcmd_net_flags_v0 {
13740 +       uint64_t flagword;
13741 +       uint64_t mask;
13742 +};
13743 +
13744 +#ifdef __KERNEL__
13745 +extern int vc_get_nflags(struct nx_info *, void __user *);
13746 +extern int vc_set_nflags(struct nx_info *, void __user *);
13747 +
13748 +#endif /* __KERNEL__ */
13749 +
13750 +
13751 +/* network caps commands */
13752 +
13753 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
13754 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
13755 +
13756 +struct vcmd_net_caps_v0 {
13757 +       uint64_t ncaps;
13758 +       uint64_t cmask;
13759 +};
13760 +
13761 +#ifdef __KERNEL__
13762 +extern int vc_get_ncaps(struct nx_info *, void __user *);
13763 +extern int vc_set_ncaps(struct nx_info *, void __user *);
13764 +
13765 +#endif /* __KERNEL__ */
13766 +#endif /* _VX_CONTEXT_CMD_H */
13767 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/percpu.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/percpu.h
13768 --- linux-3.0-rc5/include/linux/vserver/percpu.h        1970-01-01 01:00:00.000000000 +0100
13769 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/percpu.h   2011-06-10 22:11:24.000000000 +0200
13770 @@ -0,0 +1,14 @@
13771 +#ifndef _VX_PERCPU_H
13772 +#define _VX_PERCPU_H
13773 +
13774 +#include "cvirt_def.h"
13775 +#include "sched_def.h"
13776 +
13777 +struct _vx_percpu {
13778 +       struct _vx_cvirt_pc cvirt;
13779 +       struct _vx_sched_pc sched;
13780 +};
13781 +
13782 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
13783 +
13784 +#endif /* _VX_PERCPU_H */
13785 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/pid.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/pid.h
13786 --- linux-3.0-rc5/include/linux/vserver/pid.h   1970-01-01 01:00:00.000000000 +0100
13787 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/pid.h      2011-06-10 22:11:24.000000000 +0200
13788 @@ -0,0 +1,51 @@
13789 +#ifndef _VSERVER_PID_H
13790 +#define _VSERVER_PID_H
13791 +
13792 +/* pid faking stuff */
13793 +
13794 +#define vx_info_map_pid(v, p) \
13795 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
13796 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
13797 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
13798 +#define vx_map_tgid(p) vx_map_pid(p)
13799 +
13800 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
13801 +       const char *func, const char *file, int line)
13802 +{
13803 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13804 +               vxfprintk(VXD_CBIT(cvirt, 2),
13805 +                       "vx_map_tgid: %p/%llx: %d -> %d",
13806 +                       vxi, (long long)vxi->vx_flags, pid,
13807 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
13808 +                       func, file, line);
13809 +               if (pid == 0)
13810 +                       return 0;
13811 +               if (pid == vxi->vx_initpid)
13812 +                       return 1;
13813 +       }
13814 +       return pid;
13815 +}
13816 +
13817 +#define vx_info_rmap_pid(v, p) \
13818 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
13819 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
13820 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
13821 +
13822 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
13823 +       const char *func, const char *file, int line)
13824 +{
13825 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13826 +               vxfprintk(VXD_CBIT(cvirt, 2),
13827 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
13828 +                       vxi, (long long)vxi->vx_flags, pid,
13829 +                       (pid == 1) ? vxi->vx_initpid : pid,
13830 +                       func, file, line);
13831 +               if ((pid == 1) && vxi->vx_initpid)
13832 +                       return vxi->vx_initpid;
13833 +               if (pid == vxi->vx_initpid)
13834 +                       return ~0U;
13835 +       }
13836 +       return pid;
13837 +}
13838 +
13839 +#endif
13840 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/sched.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/sched.h
13841 --- linux-3.0-rc5/include/linux/vserver/sched.h 1970-01-01 01:00:00.000000000 +0100
13842 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/sched.h    2011-06-10 22:11:24.000000000 +0200
13843 @@ -0,0 +1,23 @@
13844 +#ifndef _VX_SCHED_H
13845 +#define _VX_SCHED_H
13846 +
13847 +
13848 +#ifdef __KERNEL__
13849 +
13850 +struct timespec;
13851 +
13852 +void vx_vsi_uptime(struct timespec *, struct timespec *);
13853 +
13854 +
13855 +struct vx_info;
13856 +
13857 +void vx_update_load(struct vx_info *);
13858 +
13859 +
13860 +void vx_update_sched_param(struct _vx_sched *sched,
13861 +       struct _vx_sched_pc *sched_pc);
13862 +
13863 +#endif /* __KERNEL__ */
13864 +#else  /* _VX_SCHED_H */
13865 +#warning duplicate inclusion
13866 +#endif /* _VX_SCHED_H */
13867 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/sched_cmd.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/sched_cmd.h
13868 --- linux-3.0-rc5/include/linux/vserver/sched_cmd.h     1970-01-01 01:00:00.000000000 +0100
13869 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/sched_cmd.h        2011-06-10 22:11:24.000000000 +0200
13870 @@ -0,0 +1,21 @@
13871 +#ifndef _VX_SCHED_CMD_H
13872 +#define _VX_SCHED_CMD_H
13873 +
13874 +
13875 +struct vcmd_prio_bias {
13876 +       int32_t cpu_id;
13877 +       int32_t prio_bias;
13878 +};
13879 +
13880 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
13881 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
13882 +
13883 +#ifdef __KERNEL__
13884 +
13885 +#include <linux/compiler.h>
13886 +
13887 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
13888 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
13889 +
13890 +#endif /* __KERNEL__ */
13891 +#endif /* _VX_SCHED_CMD_H */
13892 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/sched_def.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/sched_def.h
13893 --- linux-3.0-rc5/include/linux/vserver/sched_def.h     1970-01-01 01:00:00.000000000 +0100
13894 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/sched_def.h        2011-06-10 22:11:24.000000000 +0200
13895 @@ -0,0 +1,38 @@
13896 +#ifndef _VX_SCHED_DEF_H
13897 +#define _VX_SCHED_DEF_H
13898 +
13899 +#include <linux/spinlock.h>
13900 +#include <linux/jiffies.h>
13901 +#include <linux/cpumask.h>
13902 +#include <asm/atomic.h>
13903 +#include <asm/param.h>
13904 +
13905 +
13906 +/* context sub struct */
13907 +
13908 +struct _vx_sched {
13909 +       int prio_bias;                  /* bias offset for priority */
13910 +
13911 +       cpumask_t update;               /* CPUs which should update */
13912 +};
13913 +
13914 +struct _vx_sched_pc {
13915 +       int prio_bias;                  /* bias offset for priority */
13916 +
13917 +       uint64_t user_ticks;            /* token tick events */
13918 +       uint64_t sys_ticks;             /* token tick events */
13919 +       uint64_t hold_ticks;            /* token ticks paused */
13920 +};
13921 +
13922 +
13923 +#ifdef CONFIG_VSERVER_DEBUG
13924 +
13925 +static inline void __dump_vx_sched(struct _vx_sched *sched)
13926 +{
13927 +       printk("\t_vx_sched:\n");
13928 +       printk("\t priority = %4d\n", sched->prio_bias);
13929 +}
13930 +
13931 +#endif
13932 +
13933 +#endif /* _VX_SCHED_DEF_H */
13934 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/signal.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/signal.h
13935 --- linux-3.0-rc5/include/linux/vserver/signal.h        1970-01-01 01:00:00.000000000 +0100
13936 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/signal.h   2011-06-10 22:11:24.000000000 +0200
13937 @@ -0,0 +1,14 @@
13938 +#ifndef _VX_SIGNAL_H
13939 +#define _VX_SIGNAL_H
13940 +
13941 +
13942 +#ifdef __KERNEL__
13943 +
13944 +struct vx_info;
13945 +
13946 +int vx_info_kill(struct vx_info *, int, int);
13947 +
13948 +#endif /* __KERNEL__ */
13949 +#else  /* _VX_SIGNAL_H */
13950 +#warning duplicate inclusion
13951 +#endif /* _VX_SIGNAL_H */
13952 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/signal_cmd.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/signal_cmd.h
13953 --- linux-3.0-rc5/include/linux/vserver/signal_cmd.h    1970-01-01 01:00:00.000000000 +0100
13954 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/signal_cmd.h       2011-06-10 22:11:24.000000000 +0200
13955 @@ -0,0 +1,43 @@
13956 +#ifndef _VX_SIGNAL_CMD_H
13957 +#define _VX_SIGNAL_CMD_H
13958 +
13959 +
13960 +/*  signalling vserver commands */
13961 +
13962 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
13963 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
13964 +
13965 +struct vcmd_ctx_kill_v0 {
13966 +       int32_t pid;
13967 +       int32_t sig;
13968 +};
13969 +
13970 +struct vcmd_wait_exit_v0 {
13971 +       int32_t reboot_cmd;
13972 +       int32_t exit_code;
13973 +};
13974 +
13975 +#ifdef __KERNEL__
13976 +
13977 +extern int vc_ctx_kill(struct vx_info *, void __user *);
13978 +extern int vc_wait_exit(struct vx_info *, void __user *);
13979 +
13980 +#endif /* __KERNEL__ */
13981 +
13982 +/*  process alteration commands */
13983 +
13984 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
13985 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
13986 +
13987 +struct vcmd_pflags_v0 {
13988 +       uint32_t flagword;
13989 +       uint32_t mask;
13990 +};
13991 +
13992 +#ifdef __KERNEL__
13993 +
13994 +extern int vc_get_pflags(uint32_t pid, void __user *);
13995 +extern int vc_set_pflags(uint32_t pid, void __user *);
13996 +
13997 +#endif /* __KERNEL__ */
13998 +#endif /* _VX_SIGNAL_CMD_H */
13999 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/space.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/space.h
14000 --- linux-3.0-rc5/include/linux/vserver/space.h 1970-01-01 01:00:00.000000000 +0100
14001 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/space.h    2011-06-10 22:11:24.000000000 +0200
14002 @@ -0,0 +1,12 @@
14003 +#ifndef _VX_SPACE_H
14004 +#define _VX_SPACE_H
14005 +
14006 +#include <linux/types.h>
14007 +
14008 +struct vx_info;
14009 +
14010 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
14011 +
14012 +#else  /* _VX_SPACE_H */
14013 +#warning duplicate inclusion
14014 +#endif /* _VX_SPACE_H */
14015 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/space_cmd.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/space_cmd.h
14016 --- linux-3.0-rc5/include/linux/vserver/space_cmd.h     1970-01-01 01:00:00.000000000 +0100
14017 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/space_cmd.h        2011-06-10 22:11:24.000000000 +0200
14018 @@ -0,0 +1,38 @@
14019 +#ifndef _VX_SPACE_CMD_H
14020 +#define _VX_SPACE_CMD_H
14021 +
14022 +
14023 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
14024 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
14025 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
14026 +
14027 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
14028 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
14029 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
14030 +
14031 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
14032 +
14033 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
14034 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
14035 +
14036 +
14037 +struct vcmd_space_mask_v1 {
14038 +       uint64_t mask;
14039 +};
14040 +
14041 +struct vcmd_space_mask_v2 {
14042 +       uint64_t mask;
14043 +       uint32_t index;
14044 +};
14045 +
14046 +
14047 +#ifdef __KERNEL__
14048 +
14049 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
14050 +extern int vc_set_space_v1(struct vx_info *, void __user *);
14051 +extern int vc_enter_space(struct vx_info *, void __user *);
14052 +extern int vc_set_space(struct vx_info *, void __user *);
14053 +extern int vc_get_space_mask(void __user *, int);
14054 +
14055 +#endif /* __KERNEL__ */
14056 +#endif /* _VX_SPACE_CMD_H */
14057 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/switch.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/switch.h
14058 --- linux-3.0-rc5/include/linux/vserver/switch.h        1970-01-01 01:00:00.000000000 +0100
14059 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/switch.h   2011-06-10 22:11:24.000000000 +0200
14060 @@ -0,0 +1,98 @@
14061 +#ifndef _VX_SWITCH_H
14062 +#define _VX_SWITCH_H
14063 +
14064 +#include <linux/types.h>
14065 +
14066 +
14067 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
14068 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
14069 +#define VC_VERSION(c)          ((c) & 0xFFF)
14070 +
14071 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
14072 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
14073 +
14074 +/*
14075 +
14076 +  Syscall Matrix V2.8
14077 +
14078 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
14079 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
14080 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
14081 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14082 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
14083 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
14084 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14085 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
14086 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
14087 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14088 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
14089 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
14090 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14091 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
14092 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
14093 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14094 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
14095 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
14096 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14097 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
14098 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
14099 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
14100 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
14101 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
14102 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14103 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
14104 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
14105 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14106 +
14107 +*/
14108 +
14109 +#define VC_CAT_VERSION         0
14110 +
14111 +#define VC_CAT_VSETUP          1
14112 +#define VC_CAT_VHOST           2
14113 +
14114 +#define VC_CAT_DEVICE          6
14115 +
14116 +#define VC_CAT_VPROC           9
14117 +#define VC_CAT_PROCALT         10
14118 +#define VC_CAT_PROCMIG         11
14119 +#define VC_CAT_PROCTRL         12
14120 +
14121 +#define VC_CAT_SCHED           14
14122 +#define VC_CAT_MEMCTRL         20
14123 +
14124 +#define VC_CAT_VNET            25
14125 +#define VC_CAT_NETALT          26
14126 +#define VC_CAT_NETMIG          27
14127 +#define VC_CAT_NETCTRL         28
14128 +
14129 +#define VC_CAT_TAGMIG          35
14130 +#define VC_CAT_DLIMIT          36
14131 +#define VC_CAT_INODE           38
14132 +
14133 +#define VC_CAT_VSTAT           40
14134 +#define VC_CAT_VINFO           46
14135 +#define VC_CAT_EVENT           48
14136 +
14137 +#define VC_CAT_FLAGS           52
14138 +#define VC_CAT_VSPACE          54
14139 +#define VC_CAT_DEBUG           56
14140 +#define VC_CAT_RLIMIT          60
14141 +
14142 +#define VC_CAT_SYSTEST         61
14143 +#define VC_CAT_COMPAT          63
14144 +
14145 +/*  query version */
14146 +
14147 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
14148 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
14149 +
14150 +
14151 +#ifdef __KERNEL__
14152 +
14153 +#include <linux/errno.h>
14154 +
14155 +#endif /* __KERNEL__ */
14156 +
14157 +#endif /* _VX_SWITCH_H */
14158 +
14159 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/tag.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/tag.h
14160 --- linux-3.0-rc5/include/linux/vserver/tag.h   1970-01-01 01:00:00.000000000 +0100
14161 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/tag.h      2011-06-10 22:11:24.000000000 +0200
14162 @@ -0,0 +1,143 @@
14163 +#ifndef _DX_TAG_H
14164 +#define _DX_TAG_H
14165 +
14166 +#include <linux/types.h>
14167 +
14168 +
14169 +#define DX_TAG(in)     (IS_TAGGED(in))
14170 +
14171 +
14172 +#ifdef CONFIG_TAG_NFSD
14173 +#define DX_TAG_NFSD    1
14174 +#else
14175 +#define DX_TAG_NFSD    0
14176 +#endif
14177 +
14178 +
14179 +#ifdef CONFIG_TAGGING_NONE
14180 +
14181 +#define MAX_UID                0xFFFFFFFF
14182 +#define MAX_GID                0xFFFFFFFF
14183 +
14184 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
14185 +
14186 +#define TAGINO_UID(cond, uid, tag)     (uid)
14187 +#define TAGINO_GID(cond, gid, tag)     (gid)
14188 +
14189 +#endif
14190 +
14191 +
14192 +#ifdef CONFIG_TAGGING_GID16
14193 +
14194 +#define MAX_UID                0xFFFFFFFF
14195 +#define MAX_GID                0x0000FFFF
14196 +
14197 +#define INOTAG_TAG(cond, uid, gid, tag)        \
14198 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
14199 +
14200 +#define TAGINO_UID(cond, uid, tag)     (uid)
14201 +#define TAGINO_GID(cond, gid, tag)     \
14202 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
14203 +
14204 +#endif
14205 +
14206 +
14207 +#ifdef CONFIG_TAGGING_ID24
14208 +
14209 +#define MAX_UID                0x00FFFFFF
14210 +#define MAX_GID                0x00FFFFFF
14211 +
14212 +#define INOTAG_TAG(cond, uid, gid, tag)        \
14213 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
14214 +
14215 +#define TAGINO_UID(cond, uid, tag)     \
14216 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
14217 +#define TAGINO_GID(cond, gid, tag)     \
14218 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
14219 +
14220 +#endif
14221 +
14222 +
14223 +#ifdef CONFIG_TAGGING_UID16
14224 +
14225 +#define MAX_UID                0x0000FFFF
14226 +#define MAX_GID                0xFFFFFFFF
14227 +
14228 +#define INOTAG_TAG(cond, uid, gid, tag)        \
14229 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
14230 +
14231 +#define TAGINO_UID(cond, uid, tag)     \
14232 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
14233 +#define TAGINO_GID(cond, gid, tag)     (gid)
14234 +
14235 +#endif
14236 +
14237 +
14238 +#ifdef CONFIG_TAGGING_INTERN
14239 +
14240 +#define MAX_UID                0xFFFFFFFF
14241 +#define MAX_GID                0xFFFFFFFF
14242 +
14243 +#define INOTAG_TAG(cond, uid, gid, tag)        \
14244 +       ((cond) ? (tag) : 0)
14245 +
14246 +#define TAGINO_UID(cond, uid, tag)     (uid)
14247 +#define TAGINO_GID(cond, gid, tag)     (gid)
14248 +
14249 +#endif
14250 +
14251 +
14252 +#ifndef CONFIG_TAGGING_NONE
14253 +#define dx_current_fstag(sb)   \
14254 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
14255 +#else
14256 +#define dx_current_fstag(sb)   (0)
14257 +#endif
14258 +
14259 +#ifndef CONFIG_TAGGING_INTERN
14260 +#define TAGINO_TAG(cond, tag)  (0)
14261 +#else
14262 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
14263 +#endif
14264 +
14265 +#define INOTAG_UID(cond, uid, gid)     \
14266 +       ((cond) ? ((uid) & MAX_UID) : (uid))
14267 +#define INOTAG_GID(cond, uid, gid)     \
14268 +       ((cond) ? ((gid) & MAX_GID) : (gid))
14269 +
14270 +
14271 +static inline uid_t dx_map_uid(uid_t uid)
14272 +{
14273 +       if ((uid > MAX_UID) && (uid != -1))
14274 +               uid = -2;
14275 +       return (uid & MAX_UID);
14276 +}
14277 +
14278 +static inline gid_t dx_map_gid(gid_t gid)
14279 +{
14280 +       if ((gid > MAX_GID) && (gid != -1))
14281 +               gid = -2;
14282 +       return (gid & MAX_GID);
14283 +}
14284 +
14285 +struct peer_tag {
14286 +       int32_t xid;
14287 +       int32_t nid;
14288 +};
14289 +
14290 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
14291 +
14292 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
14293 +                unsigned long *flags);
14294 +
14295 +#ifdef CONFIG_PROPAGATE
14296 +
14297 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
14298 +
14299 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
14300 +
14301 +#else
14302 +#define dx_propagate_tag(n, i) do { } while (0)
14303 +#endif
14304 +
14305 +#endif /* _DX_TAG_H */
14306 diff -NurpP --minimal linux-3.0-rc5/include/linux/vserver/tag_cmd.h linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/tag_cmd.h
14307 --- linux-3.0-rc5/include/linux/vserver/tag_cmd.h       1970-01-01 01:00:00.000000000 +0100
14308 +++ linux-3.0-rc5-vs2.3.1-pre3/include/linux/vserver/tag_cmd.h  2011-06-10 22:11:24.000000000 +0200
14309 @@ -0,0 +1,22 @@
14310 +#ifndef _VX_TAG_CMD_H
14311 +#define _VX_TAG_CMD_H
14312 +
14313 +
14314 +/* vinfo commands */
14315 +
14316 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
14317 +
14318 +#ifdef __KERNEL__
14319 +extern int vc_task_tag(uint32_t);
14320 +
14321 +#endif /* __KERNEL__ */
14322 +
14323 +/* context commands */
14324 +
14325 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
14326 +
14327 +#ifdef __KERNEL__
14328 +extern int vc_tag_migrate(uint32_t);
14329 +
14330 +#endif /* __KERNEL__ */
14331 +#endif /* _VX_TAG_CMD_H */
14332 diff -NurpP --minimal linux-3.0-rc5/include/net/addrconf.h linux-3.0-rc5-vs2.3.1-pre3/include/net/addrconf.h
14333 --- linux-3.0-rc5/include/net/addrconf.h        2011-07-01 11:14:22.000000000 +0200
14334 +++ linux-3.0-rc5-vs2.3.1-pre3/include/net/addrconf.h   2011-06-10 22:11:24.000000000 +0200
14335 @@ -80,7 +80,8 @@ extern int                    ipv6_dev_get_saddr(struct n
14336                                                struct net_device *dev,
14337                                                const struct in6_addr *daddr,
14338                                                unsigned int srcprefs,
14339 -                                              struct in6_addr *saddr);
14340 +                                              struct in6_addr *saddr,
14341 +                                              struct nx_info *nxi);
14342  extern int                     ipv6_get_lladdr(struct net_device *dev,
14343                                                 struct in6_addr *addr,
14344                                                 unsigned char banned_flags);
14345 diff -NurpP --minimal linux-3.0-rc5/include/net/af_unix.h linux-3.0-rc5-vs2.3.1-pre3/include/net/af_unix.h
14346 --- linux-3.0-rc5/include/net/af_unix.h 2011-07-01 11:14:22.000000000 +0200
14347 +++ linux-3.0-rc5-vs2.3.1-pre3/include/net/af_unix.h    2011-06-10 22:11:24.000000000 +0200
14348 @@ -4,6 +4,7 @@
14349  #include <linux/socket.h>
14350  #include <linux/un.h>
14351  #include <linux/mutex.h>
14352 +#include <linux/vs_base.h>
14353  #include <net/sock.h>
14354  
14355  extern void unix_inflight(struct file *fp);
14356 diff -NurpP --minimal linux-3.0-rc5/include/net/inet_timewait_sock.h linux-3.0-rc5-vs2.3.1-pre3/include/net/inet_timewait_sock.h
14357 --- linux-3.0-rc5/include/net/inet_timewait_sock.h      2011-03-15 18:07:40.000000000 +0100
14358 +++ linux-3.0-rc5-vs2.3.1-pre3/include/net/inet_timewait_sock.h 2011-06-10 22:11:24.000000000 +0200
14359 @@ -113,6 +113,10 @@ struct inet_timewait_sock {
14360  #define tw_net                 __tw_common.skc_net
14361  #define tw_daddr               __tw_common.skc_daddr
14362  #define tw_rcv_saddr           __tw_common.skc_rcv_saddr
14363 +#define tw_xid                 __tw_common.skc_xid
14364 +#define tw_vx_info             __tw_common.skc_vx_info
14365 +#define tw_nid                 __tw_common.skc_nid
14366 +#define tw_nx_info             __tw_common.skc_nx_info
14367         int                     tw_timeout;
14368         volatile unsigned char  tw_substate;
14369         unsigned char           tw_rcv_wscale;
14370 diff -NurpP --minimal linux-3.0-rc5/include/net/ip6_route.h linux-3.0-rc5-vs2.3.1-pre3/include/net/ip6_route.h
14371 --- linux-3.0-rc5/include/net/ip6_route.h       2011-07-01 11:14:22.000000000 +0200
14372 +++ linux-3.0-rc5-vs2.3.1-pre3/include/net/ip6_route.h  2011-06-16 14:16:51.000000000 +0200
14373 @@ -86,7 +86,8 @@ extern int                    ip6_route_get_saddr(struct 
14374                                                     struct rt6_info *rt,
14375                                                     const struct in6_addr *daddr,
14376                                                     unsigned int prefs,
14377 -                                                   struct in6_addr *saddr);
14378 +                                                   struct in6_addr *saddr,
14379 +                                                   struct nx_info *nxi);
14380  
14381  extern struct rt6_info         *rt6_lookup(struct net *net,
14382                                             const struct in6_addr *daddr,
14383 diff -NurpP --minimal linux-3.0-rc5/include/net/route.h linux-3.0-rc5-vs2.3.1-pre3/include/net/route.h
14384 --- linux-3.0-rc5/include/net/route.h   2011-07-01 11:14:22.000000000 +0200
14385 +++ linux-3.0-rc5-vs2.3.1-pre3/include/net/route.h      2011-06-13 18:20:44.000000000 +0200
14386 @@ -202,6 +202,9 @@ static inline void ip_rt_put(struct rtab
14387                 dst_release(&rt->dst);
14388  }
14389  
14390 +#include <linux/vs_base.h>
14391 +#include <linux/vs_inet.h>
14392 +
14393  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
14394  
14395  extern const __u8 ip_tos2prio[16];
14396 @@ -253,6 +256,9 @@ static inline void ip_route_connect_init
14397                            protocol, flow_flags, dst, src, dport, sport);
14398  }
14399  
14400 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
14401 +       struct flowi4 *);
14402 +
14403  static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
14404                                               __be32 dst, __be32 src, u32 tos,
14405                                               int oif, u8 protocol,
14406 @@ -261,11 +267,24 @@ static inline struct rtable *ip_route_co
14407  {
14408         struct net *net = sock_net(sk);
14409         struct rtable *rt;
14410 +       struct nx_info *nx_info = current_nx_info();
14411  
14412         ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
14413                               sport, dport, sk, can_sleep);
14414  
14415 -       if (!dst || !src) {
14416 +       if (sk)
14417 +               nx_info = sk->sk_nx_info;
14418 +
14419 +       vxdprintk(VXD_CBIT(net, 4),
14420 +               "ip_route_connect(%p) %p,%p;%lx",
14421 +               sk, nx_info, sk->sk_socket,
14422 +               (sk->sk_socket?sk->sk_socket->flags:0));
14423 +
14424 +       rt = ip_v4_find_src(net, nx_info, fl4);
14425 +       if (IS_ERR(rt))
14426 +               return rt;
14427 +
14428 +       if (!fl4->daddr || !fl4->saddr) {
14429                 rt = __ip_route_output_key(net, fl4);
14430                 if (IS_ERR(rt))
14431                         return rt;
14432 diff -NurpP --minimal linux-3.0-rc5/include/net/sock.h linux-3.0-rc5-vs2.3.1-pre3/include/net/sock.h
14433 --- linux-3.0-rc5/include/net/sock.h    2011-07-01 11:14:22.000000000 +0200
14434 +++ linux-3.0-rc5-vs2.3.1-pre3/include/net/sock.h       2011-07-01 11:35:35.000000000 +0200
14435 @@ -149,6 +149,10 @@ struct sock_common {
14436  #ifdef CONFIG_NET_NS
14437         struct net              *skc_net;
14438  #endif
14439 +       xid_t                   skc_xid;
14440 +       struct vx_info          *skc_vx_info;
14441 +       nid_t                   skc_nid;
14442 +       struct nx_info          *skc_nx_info;
14443         /*
14444          * fields between dontcopy_begin/dontcopy_end
14445          * are not copied in sock_copy()
14446 @@ -256,6 +260,10 @@ struct sock {
14447  #define sk_bind_node           __sk_common.skc_bind_node
14448  #define sk_prot                        __sk_common.skc_prot
14449  #define sk_net                 __sk_common.skc_net
14450 +#define sk_xid                 __sk_common.skc_xid
14451 +#define sk_vx_info             __sk_common.skc_vx_info
14452 +#define sk_nid                 __sk_common.skc_nid
14453 +#define sk_nx_info             __sk_common.skc_nx_info
14454         socket_lock_t           sk_lock;
14455         struct sk_buff_head     sk_receive_queue;
14456         /*
14457 diff -NurpP --minimal linux-3.0-rc5/init/Kconfig linux-3.0-rc5-vs2.3.1-pre3/init/Kconfig
14458 --- linux-3.0-rc5/init/Kconfig  2011-07-01 11:14:22.000000000 +0200
14459 +++ linux-3.0-rc5-vs2.3.1-pre3/init/Kconfig     2011-06-22 12:39:15.000000000 +0200
14460 @@ -574,6 +574,7 @@ config HAVE_UNSTABLE_SCHED_CLOCK
14461  menuconfig CGROUPS
14462         boolean "Control Group support"
14463         depends on EVENTFD
14464 +       default y
14465         help
14466           This option adds support for grouping sets of processes together, for
14467           use with process control subsystems such as Cpusets, CFS, memory
14468 diff -NurpP --minimal linux-3.0-rc5/init/main.c linux-3.0-rc5-vs2.3.1-pre3/init/main.c
14469 --- linux-3.0-rc5/init/main.c   2011-07-01 11:14:22.000000000 +0200
14470 +++ linux-3.0-rc5-vs2.3.1-pre3/init/main.c      2011-06-22 12:39:15.000000000 +0200
14471 @@ -68,6 +68,7 @@
14472  #include <linux/shmem_fs.h>
14473  #include <linux/slab.h>
14474  #include <linux/perf_event.h>
14475 +#include <linux/vserver/percpu.h>
14476  
14477  #include <asm/io.h>
14478  #include <asm/bugs.h>
14479 diff -NurpP --minimal linux-3.0-rc5/ipc/mqueue.c linux-3.0-rc5-vs2.3.1-pre3/ipc/mqueue.c
14480 --- linux-3.0-rc5/ipc/mqueue.c  2011-03-15 18:07:41.000000000 +0100
14481 +++ linux-3.0-rc5-vs2.3.1-pre3/ipc/mqueue.c     2011-06-10 22:11:24.000000000 +0200
14482 @@ -33,6 +33,8 @@
14483  #include <linux/pid.h>
14484  #include <linux/ipc_namespace.h>
14485  #include <linux/slab.h>
14486 +#include <linux/vs_context.h>
14487 +#include <linux/vs_limit.h>
14488  
14489  #include <net/sock.h>
14490  #include "util.h"
14491 @@ -66,6 +68,7 @@ struct mqueue_inode_info {
14492         struct sigevent notify;
14493         struct pid* notify_owner;
14494         struct user_struct *user;       /* user who created, for accounting */
14495 +       struct vx_info *vxi;
14496         struct sock *notify_sock;
14497         struct sk_buff *notify_cookie;
14498  
14499 @@ -126,6 +129,7 @@ static struct inode *mqueue_get_inode(st
14500                 if (S_ISREG(mode)) {
14501                         struct mqueue_inode_info *info;
14502                         struct task_struct *p = current;
14503 +                       struct vx_info *vxi = p->vx_info;
14504                         unsigned long mq_bytes, mq_msg_tblsz;
14505  
14506                         inode->i_fop = &mqueue_file_operations;
14507 @@ -139,6 +143,7 @@ static struct inode *mqueue_get_inode(st
14508                         info->notify_owner = NULL;
14509                         info->qsize = 0;
14510                         info->user = NULL;      /* set when all is ok */
14511 +                       info->vxi = NULL;
14512                         memset(&info->attr, 0, sizeof(info->attr));
14513                         info->attr.mq_maxmsg = ipc_ns->mq_msg_max;
14514                         info->attr.mq_msgsize = ipc_ns->mq_msgsize_max;
14515 @@ -157,16 +162,19 @@ static struct inode *mqueue_get_inode(st
14516                         spin_lock(&mq_lock);
14517                         if (u->mq_bytes + mq_bytes < u->mq_bytes ||
14518                             u->mq_bytes + mq_bytes >
14519 -                           task_rlimit(p, RLIMIT_MSGQUEUE)) {
14520 +                           task_rlimit(p, RLIMIT_MSGQUEUE) ||
14521 +                           !vx_ipcmsg_avail(vxi, mq_bytes)) {
14522                                 spin_unlock(&mq_lock);
14523                                 /* mqueue_evict_inode() releases info->messages */
14524                                 goto out_inode;
14525                         }
14526                         u->mq_bytes += mq_bytes;
14527 +                       vx_ipcmsg_add(vxi, u, mq_bytes);
14528                         spin_unlock(&mq_lock);
14529  
14530                         /* all is ok */
14531                         info->user = get_uid(u);
14532 +                       info->vxi = get_vx_info(vxi);
14533                 } else if (S_ISDIR(mode)) {
14534                         inc_nlink(inode);
14535                         /* Some things misbehave if size == 0 on a directory */
14536 @@ -275,8 +283,11 @@ static void mqueue_evict_inode(struct in
14537             + info->attr.mq_msgsize);
14538         user = info->user;
14539         if (user) {
14540 +               struct vx_info *vxi = info->vxi;
14541 +
14542                 spin_lock(&mq_lock);
14543                 user->mq_bytes -= mq_bytes;
14544 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
14545                 /*
14546                  * get_ns_from_inode() ensures that the
14547                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
14548 @@ -286,6 +297,7 @@ static void mqueue_evict_inode(struct in
14549                 if (ipc_ns)
14550                         ipc_ns->mq_queues_count--;
14551                 spin_unlock(&mq_lock);
14552 +               put_vx_info(vxi);
14553                 free_uid(user);
14554         }
14555         if (ipc_ns)
14556 diff -NurpP --minimal linux-3.0-rc5/ipc/msg.c linux-3.0-rc5-vs2.3.1-pre3/ipc/msg.c
14557 --- linux-3.0-rc5/ipc/msg.c     2011-05-22 16:17:59.000000000 +0200
14558 +++ linux-3.0-rc5-vs2.3.1-pre3/ipc/msg.c        2011-06-10 22:11:24.000000000 +0200
14559 @@ -37,6 +37,7 @@
14560  #include <linux/rwsem.h>
14561  #include <linux/nsproxy.h>
14562  #include <linux/ipc_namespace.h>
14563 +#include <linux/vs_base.h>
14564  
14565  #include <asm/current.h>
14566  #include <asm/uaccess.h>
14567 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
14568  
14569         msq->q_perm.mode = msgflg & S_IRWXUGO;
14570         msq->q_perm.key = key;
14571 +       msq->q_perm.xid = vx_current_xid();
14572  
14573         msq->q_perm.security = NULL;
14574         retval = security_msg_queue_alloc(msq);
14575 diff -NurpP --minimal linux-3.0-rc5/ipc/namespace.c linux-3.0-rc5-vs2.3.1-pre3/ipc/namespace.c
14576 --- linux-3.0-rc5/ipc/namespace.c       2011-07-01 11:14:22.000000000 +0200
14577 +++ linux-3.0-rc5-vs2.3.1-pre3/ipc/namespace.c  2011-06-13 14:09:44.000000000 +0200
14578 @@ -13,11 +13,12 @@
14579  #include <linux/mount.h>
14580  #include <linux/user_namespace.h>
14581  #include <linux/proc_fs.h>
14582 +#include <linux/vs_base.h>
14583 +#include <linux/vserver/global.h>
14584  
14585  #include "util.h"
14586  
14587 -static struct ipc_namespace *create_ipc_ns(struct task_struct *tsk,
14588 -                                          struct ipc_namespace *old_ns)
14589 +static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns)
14590  {
14591         struct ipc_namespace *ns;
14592         int err;
14593 @@ -46,19 +47,18 @@ static struct ipc_namespace *create_ipc_
14594         ipcns_notify(IPCNS_CREATED);
14595         register_ipcns_notifier(ns);
14596  
14597 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user)->user_ns);
14598 +       ns->user_ns = get_user_ns(user_ns);
14599  
14600         return ns;
14601  }
14602  
14603  struct ipc_namespace *copy_ipcs(unsigned long flags,
14604 -                               struct task_struct *tsk)
14605 +                               struct ipc_namespace *old_ns,
14606 +                               struct user_namespace *user_ns)
14607  {
14608 -       struct ipc_namespace *ns = tsk->nsproxy->ipc_ns;
14609 -
14610         if (!(flags & CLONE_NEWIPC))
14611 -               return get_ipc_ns(ns);
14612 -       return create_ipc_ns(tsk, ns);
14613 +               return get_ipc_ns(old_ns);
14614 +       return create_ipc_ns(user_ns);
14615  }
14616  
14617  /*
14618 diff -NurpP --minimal linux-3.0-rc5/ipc/sem.c linux-3.0-rc5-vs2.3.1-pre3/ipc/sem.c
14619 --- linux-3.0-rc5/ipc/sem.c     2011-05-22 16:17:59.000000000 +0200
14620 +++ linux-3.0-rc5-vs2.3.1-pre3/ipc/sem.c        2011-06-10 22:11:24.000000000 +0200
14621 @@ -86,6 +86,8 @@
14622  #include <linux/rwsem.h>
14623  #include <linux/nsproxy.h>
14624  #include <linux/ipc_namespace.h>
14625 +#include <linux/vs_base.h>
14626 +#include <linux/vs_limit.h>
14627  
14628  #include <asm/uaccess.h>
14629  #include "util.h"
14630 @@ -260,6 +262,7 @@ static int newary(struct ipc_namespace *
14631  
14632         sma->sem_perm.mode = (semflg & S_IRWXUGO);
14633         sma->sem_perm.key = key;
14634 +       sma->sem_perm.xid = vx_current_xid();
14635  
14636         sma->sem_perm.security = NULL;
14637         retval = security_sem_alloc(sma);
14638 @@ -275,6 +278,9 @@ static int newary(struct ipc_namespace *
14639                 return id;
14640         }
14641         ns->used_sems += nsems;
14642 +       /* FIXME: obsoleted? */
14643 +       vx_semary_inc(sma);
14644 +       vx_nsems_add(sma, nsems);
14645  
14646         sma->sem_base = (struct sem *) &sma[1];
14647  
14648 @@ -730,6 +736,9 @@ static void freeary(struct ipc_namespace
14649  
14650         wake_up_sem_queue_do(&tasks);
14651         ns->used_sems -= sma->sem_nsems;
14652 +       /* FIXME: obsoleted? */
14653 +       vx_nsems_sub(sma, sma->sem_nsems);
14654 +       vx_semary_dec(sma);
14655         security_sem_free(sma);
14656         ipc_rcu_putref(sma);
14657  }
14658 diff -NurpP --minimal linux-3.0-rc5/ipc/shm.c linux-3.0-rc5-vs2.3.1-pre3/ipc/shm.c
14659 --- linux-3.0-rc5/ipc/shm.c     2011-07-01 11:14:22.000000000 +0200
14660 +++ linux-3.0-rc5-vs2.3.1-pre3/ipc/shm.c        2011-06-10 22:11:24.000000000 +0200
14661 @@ -39,6 +39,8 @@
14662  #include <linux/nsproxy.h>
14663  #include <linux/mount.h>
14664  #include <linux/ipc_namespace.h>
14665 +#include <linux/vs_context.h>
14666 +#include <linux/vs_limit.h>
14667  
14668  #include <asm/uaccess.h>
14669  
14670 @@ -173,7 +175,12 @@ static void shm_open(struct vm_area_stru
14671   */
14672  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
14673  {
14674 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14675 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
14676 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14677 +
14678 +       vx_ipcshm_sub(vxi, shp, numpages);
14679 +       ns->shm_tot -= numpages;
14680 +
14681         shm_rmid(ns, shp);
14682         shm_unlock(shp);
14683         if (!is_file_hugepages(shp->shm_file))
14684 @@ -183,6 +190,7 @@ static void shm_destroy(struct ipc_names
14685                                                 shp->mlock_user);
14686         fput (shp->shm_file);
14687         security_shm_free(shp);
14688 +       put_vx_info(vxi);
14689         ipc_rcu_putref(shp);
14690  }
14691  
14692 @@ -355,11 +363,15 @@ static int newseg(struct ipc_namespace *
14693         if (ns->shm_tot + numpages > ns->shm_ctlall)
14694                 return -ENOSPC;
14695  
14696 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
14697 +               return -ENOSPC;
14698 +
14699         shp = ipc_rcu_alloc(sizeof(*shp));
14700         if (!shp)
14701                 return -ENOMEM;
14702  
14703         shp->shm_perm.key = key;
14704 +       shp->shm_perm.xid = vx_current_xid();
14705         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
14706         shp->mlock_user = NULL;
14707  
14708 @@ -413,6 +425,7 @@ static int newseg(struct ipc_namespace *
14709         ns->shm_tot += numpages;
14710         error = shp->shm_perm.id;
14711         shm_unlock(shp);
14712 +       vx_ipcshm_add(current_vx_info(), key, numpages);
14713         return error;
14714  
14715  no_id:
14716 diff -NurpP --minimal linux-3.0-rc5/kernel/Makefile linux-3.0-rc5-vs2.3.1-pre3/kernel/Makefile
14717 --- linux-3.0-rc5/kernel/Makefile       2011-07-01 11:14:22.000000000 +0200
14718 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/Makefile  2011-06-10 22:11:24.000000000 +0200
14719 @@ -24,6 +24,7 @@ CFLAGS_REMOVE_sched_clock.o = -pg
14720  CFLAGS_REMOVE_irq_work.o = -pg
14721  endif
14722  
14723 +obj-y += vserver/
14724  obj-$(CONFIG_FREEZER) += freezer.o
14725  obj-$(CONFIG_PROFILING) += profile.o
14726  obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
14727 diff -NurpP --minimal linux-3.0-rc5/kernel/capability.c linux-3.0-rc5-vs2.3.1-pre3/kernel/capability.c
14728 --- linux-3.0-rc5/kernel/capability.c   2011-07-01 11:14:22.000000000 +0200
14729 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/capability.c      2011-06-10 22:21:49.000000000 +0200
14730 @@ -15,6 +15,7 @@
14731  #include <linux/syscalls.h>
14732  #include <linux/pid_namespace.h>
14733  #include <linux/user_namespace.h>
14734 +#include <linux/vs_context.h>
14735  #include <asm/uaccess.h>
14736  
14737  /*
14738 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
14739         return 0;
14740  }
14741  
14742 +
14743  /*
14744   * The only thing that can change the capabilities of the current
14745   * process is the current process. As such, we can't be in this code
14746 @@ -340,6 +342,8 @@ bool has_capability_noaudit(struct task_
14747         return (ret == 0);
14748  }
14749  
14750 +#include <linux/vserver/base.h>
14751 +
14752  /**
14753   * capable - Determine if the current task has a superior capability in effect
14754   * @cap: The capability to be tested for
14755 @@ -369,6 +373,9 @@ EXPORT_SYMBOL(capable);
14756   */
14757  bool ns_capable(struct user_namespace *ns, int cap)
14758  {
14759 +       /* here for now so we don't require task locking */
14760 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
14761 +               return 0;
14762         if (unlikely(!cap_valid(cap))) {
14763                 printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
14764                 BUG();
14765 diff -NurpP --minimal linux-3.0-rc5/kernel/compat.c linux-3.0-rc5-vs2.3.1-pre3/kernel/compat.c
14766 --- linux-3.0-rc5/kernel/compat.c       2011-07-01 11:14:22.000000000 +0200
14767 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/compat.c  2011-06-10 22:11:24.000000000 +0200
14768 @@ -970,7 +970,7 @@ asmlinkage long compat_sys_stime(compat_
14769         if (err)
14770                 return err;
14771  
14772 -       do_settimeofday(&tv);
14773 +       vx_settimeofday(&tv);
14774         return 0;
14775  }
14776  
14777 diff -NurpP --minimal linux-3.0-rc5/kernel/cred.c linux-3.0-rc5-vs2.3.1-pre3/kernel/cred.c
14778 --- linux-3.0-rc5/kernel/cred.c 2011-07-01 11:14:22.000000000 +0200
14779 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/cred.c    2011-06-10 22:11:24.000000000 +0200
14780 @@ -61,31 +61,6 @@ struct cred init_cred = {
14781  #endif
14782  };
14783  
14784 -static inline void set_cred_subscribers(struct cred *cred, int n)
14785 -{
14786 -#ifdef CONFIG_DEBUG_CREDENTIALS
14787 -       atomic_set(&cred->subscribers, n);
14788 -#endif
14789 -}
14790 -
14791 -static inline int read_cred_subscribers(const struct cred *cred)
14792 -{
14793 -#ifdef CONFIG_DEBUG_CREDENTIALS
14794 -       return atomic_read(&cred->subscribers);
14795 -#else
14796 -       return 0;
14797 -#endif
14798 -}
14799 -
14800 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
14801 -{
14802 -#ifdef CONFIG_DEBUG_CREDENTIALS
14803 -       struct cred *cred = (struct cred *) _cred;
14804 -
14805 -       atomic_add(n, &cred->subscribers);
14806 -#endif
14807 -}
14808 -
14809  /*
14810   * Dispose of the shared task group credentials
14811   */
14812 @@ -281,21 +256,16 @@ error:
14813   *
14814   * Call commit_creds() or abort_creds() to clean up.
14815   */
14816 -struct cred *prepare_creds(void)
14817 +struct cred *__prepare_creds(const struct cred *old)
14818  {
14819 -       struct task_struct *task = current;
14820 -       const struct cred *old;
14821         struct cred *new;
14822  
14823 -       validate_process_creds();
14824 -
14825         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
14826         if (!new)
14827                 return NULL;
14828  
14829         kdebug("prepare_creds() alloc %p", new);
14830  
14831 -       old = task->cred;
14832         memcpy(new, old, sizeof(struct cred));
14833  
14834         atomic_set(&new->usage, 1);
14835 @@ -322,6 +292,13 @@ error:
14836         abort_creds(new);
14837         return NULL;
14838  }
14839 +
14840 +struct cred *prepare_creds(void)
14841 +{
14842 +       validate_process_creds();
14843 +
14844 +       return __prepare_creds(current->cred);
14845 +}
14846  EXPORT_SYMBOL(prepare_creds);
14847  
14848  /*
14849 diff -NurpP --minimal linux-3.0-rc5/kernel/exit.c linux-3.0-rc5-vs2.3.1-pre3/kernel/exit.c
14850 --- linux-3.0-rc5/kernel/exit.c 2011-07-01 11:14:22.000000000 +0200
14851 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/exit.c    2011-06-22 12:39:15.000000000 +0200
14852 @@ -48,6 +48,10 @@
14853  #include <linux/fs_struct.h>
14854  #include <linux/init_task.h>
14855  #include <linux/perf_event.h>
14856 +#include <linux/vs_limit.h>
14857 +#include <linux/vs_context.h>
14858 +#include <linux/vs_network.h>
14859 +#include <linux/vs_pid.h>
14860  #include <trace/events/sched.h>
14861  #include <linux/hw_breakpoint.h>
14862  #include <linux/oom.h>
14863 @@ -494,9 +498,11 @@ static void close_files(struct files_str
14864                                         filp_close(file, files);
14865                                         cond_resched();
14866                                 }
14867 +                               vx_openfd_dec(i);
14868                         }
14869                         i++;
14870                         set >>= 1;
14871 +                       cond_resched();
14872                 }
14873         }
14874  }
14875 @@ -1047,11 +1053,16 @@ NORET_TYPE void do_exit(long code)
14876  
14877         validate_creds_for_do_exit(tsk);
14878  
14879 +       /* needs to stay after exit_notify() */
14880 +       exit_vx_info(tsk, code);
14881 +       exit_nx_info(tsk);
14882 +
14883         preempt_disable();
14884         exit_rcu();
14885         /* causes final put_task_struct in finish_task_switch(). */
14886         tsk->state = TASK_DEAD;
14887         schedule();
14888 +       printk("bad task: %p [%lx]\n", current, current->state);
14889         BUG();
14890         /* Avoid "noreturn function does return".  */
14891         for (;;)
14892 diff -NurpP --minimal linux-3.0-rc5/kernel/fork.c linux-3.0-rc5-vs2.3.1-pre3/kernel/fork.c
14893 --- linux-3.0-rc5/kernel/fork.c 2011-07-01 11:14:22.000000000 +0200
14894 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/fork.c    2011-06-10 22:21:02.000000000 +0200
14895 @@ -67,6 +67,10 @@
14896  #include <linux/user-return-notifier.h>
14897  #include <linux/oom.h>
14898  #include <linux/khugepaged.h>
14899 +#include <linux/vs_context.h>
14900 +#include <linux/vs_network.h>
14901 +#include <linux/vs_limit.h>
14902 +#include <linux/vs_memory.h>
14903  
14904  #include <asm/pgtable.h>
14905  #include <asm/pgalloc.h>
14906 @@ -167,6 +171,8 @@ void free_task(struct task_struct *tsk)
14907         account_kernel_stack(tsk->stack, -1);
14908         free_thread_info(tsk->stack);
14909         rt_mutex_debug_task_free(tsk);
14910 +       clr_vx_info(&tsk->vx_info);
14911 +       clr_nx_info(&tsk->nx_info);
14912         ftrace_graph_exit_task(tsk);
14913         free_task_struct(tsk);
14914  }
14915 @@ -505,6 +511,7 @@ static struct mm_struct * mm_init(struct
14916         if (likely(!mm_alloc_pgd(mm))) {
14917                 mm->def_flags = 0;
14918                 mmu_notifier_mm_init(mm);
14919 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
14920                 return mm;
14921         }
14922  
14923 @@ -542,6 +549,7 @@ void __mmdrop(struct mm_struct *mm)
14924  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
14925         VM_BUG_ON(mm->pmd_huge_pte);
14926  #endif
14927 +       clr_vx_info(&mm->mm_vx_info);
14928         free_mm(mm);
14929  }
14930  EXPORT_SYMBOL_GPL(__mmdrop);
14931 @@ -729,6 +737,7 @@ struct mm_struct *dup_mm(struct task_str
14932                 goto fail_nomem;
14933  
14934         memcpy(mm, oldmm, sizeof(*mm));
14935 +       mm->mm_vx_info = NULL;
14936         mm_init_cpumask(mm);
14937  
14938         /* Initializing for Swap token stuff */
14939 @@ -772,6 +781,7 @@ fail_nocontext:
14940          * If init_new_context() failed, we cannot use mmput() to free the mm
14941          * because it calls destroy_context()
14942          */
14943 +       clr_vx_info(&mm->mm_vx_info);
14944         mm_free_pgd(mm);
14945         free_mm(mm);
14946         return NULL;
14947 @@ -1057,6 +1067,8 @@ static struct task_struct *copy_process(
14948         int retval;
14949         struct task_struct *p;
14950         int cgroup_callbacks_done = 0;
14951 +       struct vx_info *vxi;
14952 +       struct nx_info *nxi;
14953  
14954         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
14955                 return ERR_PTR(-EINVAL);
14956 @@ -1103,7 +1115,12 @@ static struct task_struct *copy_process(
14957         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
14958         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
14959  #endif
14960 +       init_vx_info(&p->vx_info, current_vx_info());
14961 +       init_nx_info(&p->nx_info, current_nx_info());
14962 +
14963         retval = -EAGAIN;
14964 +       if (!vx_nproc_avail(1))
14965 +               goto bad_fork_free;
14966         if (atomic_read(&p->real_cred->user->processes) >=
14967                         task_rlimit(p, RLIMIT_NPROC)) {
14968                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
14969 @@ -1360,6 +1377,18 @@ static struct task_struct *copy_process(
14970  
14971         total_forks++;
14972         spin_unlock(&current->sighand->siglock);
14973 +
14974 +       /* p is copy of current */
14975 +       vxi = p->vx_info;
14976 +       if (vxi) {
14977 +               claim_vx_info(vxi, p);
14978 +               atomic_inc(&vxi->cvirt.nr_threads);
14979 +               atomic_inc(&vxi->cvirt.total_forks);
14980 +               vx_nproc_inc(p);
14981 +       }
14982 +       nxi = p->nx_info;
14983 +       if (nxi)
14984 +               claim_nx_info(nxi, p);
14985         write_unlock_irq(&tasklist_lock);
14986         proc_fork_connector(p);
14987         cgroup_post_fork(p);
14988 diff -NurpP --minimal linux-3.0-rc5/kernel/kthread.c linux-3.0-rc5-vs2.3.1-pre3/kernel/kthread.c
14989 --- linux-3.0-rc5/kernel/kthread.c      2011-07-01 11:14:22.000000000 +0200
14990 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/kthread.c 2011-06-10 22:11:24.000000000 +0200
14991 @@ -16,6 +16,7 @@
14992  #include <linux/mutex.h>
14993  #include <linux/slab.h>
14994  #include <linux/freezer.h>
14995 +#include <linux/vs_pid.h>
14996  #include <trace/events/sched.h>
14997  
14998  static DEFINE_SPINLOCK(kthread_create_lock);
14999 diff -NurpP --minimal linux-3.0-rc5/kernel/nsproxy.c linux-3.0-rc5-vs2.3.1-pre3/kernel/nsproxy.c
15000 --- linux-3.0-rc5/kernel/nsproxy.c      2011-07-01 11:14:23.000000000 +0200
15001 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/nsproxy.c 2011-06-13 14:09:44.000000000 +0200
15002 @@ -20,6 +20,8 @@
15003  #include <linux/mnt_namespace.h>
15004  #include <linux/utsname.h>
15005  #include <linux/pid_namespace.h>
15006 +#include <linux/vserver/global.h>
15007 +#include <linux/vserver/debug.h>
15008  #include <net/net_namespace.h>
15009  #include <linux/ipc_namespace.h>
15010  #include <linux/proc_fs.h>
15011 @@ -46,8 +48,11 @@ static inline struct nsproxy *create_nsp
15012         struct nsproxy *nsproxy;
15013  
15014         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
15015 -       if (nsproxy)
15016 +       if (nsproxy) {
15017                 atomic_set(&nsproxy->count, 1);
15018 +               atomic_inc(&vs_global_nsproxy);
15019 +       }
15020 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
15021         return nsproxy;
15022  }
15023  
15024 @@ -56,8 +61,11 @@ static inline struct nsproxy *create_nsp
15025   * Return the newly created nsproxy.  Do not attach this to the task,
15026   * leave it to the caller to do proper locking and attach it to task.
15027   */
15028 -static struct nsproxy *create_new_namespaces(unsigned long flags,
15029 -                       struct task_struct *tsk, struct fs_struct *new_fs)
15030 +static struct nsproxy *unshare_namespaces(unsigned long flags,
15031 +                       struct nsproxy *orig,
15032 +                       struct fs_struct *new_fs,
15033 +                       struct user_namespace *new_user,
15034 +                       struct pid_namespace *new_pid)
15035  {
15036         struct nsproxy *new_nsp;
15037         int err;
15038 @@ -66,31 +74,31 @@ static struct nsproxy *create_new_namesp
15039         if (!new_nsp)
15040                 return ERR_PTR(-ENOMEM);
15041  
15042 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
15043 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
15044         if (IS_ERR(new_nsp->mnt_ns)) {
15045                 err = PTR_ERR(new_nsp->mnt_ns);
15046                 goto out_ns;
15047         }
15048  
15049 -       new_nsp->uts_ns = copy_utsname(flags, tsk);
15050 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns, new_user);
15051         if (IS_ERR(new_nsp->uts_ns)) {
15052                 err = PTR_ERR(new_nsp->uts_ns);
15053                 goto out_uts;
15054         }
15055  
15056 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk);
15057 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns, new_user);
15058         if (IS_ERR(new_nsp->ipc_ns)) {
15059                 err = PTR_ERR(new_nsp->ipc_ns);
15060                 goto out_ipc;
15061         }
15062  
15063 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
15064 +       new_nsp->pid_ns = copy_pid_ns(flags, new_pid);
15065         if (IS_ERR(new_nsp->pid_ns)) {
15066                 err = PTR_ERR(new_nsp->pid_ns);
15067                 goto out_pid;
15068         }
15069  
15070 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
15071 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
15072         if (IS_ERR(new_nsp->net_ns)) {
15073                 err = PTR_ERR(new_nsp->net_ns);
15074                 goto out_net;
15075 @@ -115,6 +123,40 @@ out_ns:
15076         return ERR_PTR(err);
15077  }
15078  
15079 +static struct nsproxy *create_new_namespaces(unsigned long flags,
15080 +                       struct task_struct *tsk, struct fs_struct *new_fs)
15081 +{
15082 +       return unshare_namespaces(flags, tsk->nsproxy,
15083 +               new_fs, task_cred_xxx(tsk, user)->user_ns,
15084 +               task_active_pid_ns(tsk));
15085 +}
15086 +
15087 +/*
15088 + * copies the nsproxy, setting refcount to 1, and grabbing a
15089 + * reference to all contained namespaces.
15090 + */
15091 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
15092 +{
15093 +       struct nsproxy *ns = create_nsproxy();
15094 +
15095 +       if (ns) {
15096 +               memcpy(ns, orig, sizeof(struct nsproxy));
15097 +               atomic_set(&ns->count, 1);
15098 +
15099 +               if (ns->mnt_ns)
15100 +                       get_mnt_ns(ns->mnt_ns);
15101 +               if (ns->uts_ns)
15102 +                       get_uts_ns(ns->uts_ns);
15103 +               if (ns->ipc_ns)
15104 +                       get_ipc_ns(ns->ipc_ns);
15105 +               if (ns->pid_ns)
15106 +                       get_pid_ns(ns->pid_ns);
15107 +               if (ns->net_ns)
15108 +                       get_net(ns->net_ns);
15109 +       }
15110 +       return ns;
15111 +}
15112 +
15113  /*
15114   * called from clone.  This now handles copy for nsproxy and all
15115   * namespaces therein.
15116 @@ -122,9 +164,12 @@ out_ns:
15117  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
15118  {
15119         struct nsproxy *old_ns = tsk->nsproxy;
15120 -       struct nsproxy *new_ns;
15121 +       struct nsproxy *new_ns = NULL;
15122         int err = 0;
15123  
15124 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
15125 +               flags, tsk, old_ns);
15126 +
15127         if (!old_ns)
15128                 return 0;
15129  
15130 @@ -134,7 +179,7 @@ int copy_namespaces(unsigned long flags,
15131                                 CLONE_NEWPID | CLONE_NEWNET)))
15132                 return 0;
15133  
15134 -       if (!capable(CAP_SYS_ADMIN)) {
15135 +       if (!vx_can_unshare(CAP_SYS_ADMIN, flags)) {
15136                 err = -EPERM;
15137                 goto out;
15138         }
15139 @@ -161,6 +206,9 @@ int copy_namespaces(unsigned long flags,
15140  
15141  out:
15142         put_nsproxy(old_ns);
15143 +       vxdprintk(VXD_CBIT(space, 3),
15144 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
15145 +               flags, tsk, old_ns, err, new_ns);
15146         return err;
15147  }
15148  
15149 @@ -174,7 +222,9 @@ void free_nsproxy(struct nsproxy *ns)
15150                 put_ipc_ns(ns->ipc_ns);
15151         if (ns->pid_ns)
15152                 put_pid_ns(ns->pid_ns);
15153 -       put_net(ns->net_ns);
15154 +       if (ns->net_ns)
15155 +               put_net(ns->net_ns);
15156 +       atomic_dec(&vs_global_nsproxy);
15157         kmem_cache_free(nsproxy_cachep, ns);
15158  }
15159  
15160 @@ -187,11 +237,15 @@ int unshare_nsproxy_namespaces(unsigned 
15161  {
15162         int err = 0;
15163  
15164 +       vxdprintk(VXD_CBIT(space, 4),
15165 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
15166 +               unshare_flags, current->nsproxy);
15167 +
15168         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
15169                                CLONE_NEWNET)))
15170                 return 0;
15171  
15172 -       if (!capable(CAP_SYS_ADMIN))
15173 +       if (!vx_can_unshare(CAP_SYS_ADMIN, unshare_flags))
15174                 return -EPERM;
15175  
15176         *new_nsp = create_new_namespaces(unshare_flags, current,
15177 diff -NurpP --minimal linux-3.0-rc5/kernel/pid.c linux-3.0-rc5-vs2.3.1-pre3/kernel/pid.c
15178 --- linux-3.0-rc5/kernel/pid.c  2011-05-22 16:17:59.000000000 +0200
15179 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/pid.c     2011-06-10 22:11:24.000000000 +0200
15180 @@ -36,6 +36,7 @@
15181  #include <linux/pid_namespace.h>
15182  #include <linux/init_task.h>
15183  #include <linux/syscalls.h>
15184 +#include <linux/vs_pid.h>
15185  
15186  #define pid_hashfn(nr, ns)     \
15187         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
15188 @@ -342,7 +343,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
15189  
15190  struct pid *find_vpid(int nr)
15191  {
15192 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
15193 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
15194  }
15195  EXPORT_SYMBOL_GPL(find_vpid);
15196  
15197 @@ -402,6 +403,9 @@ void transfer_pid(struct task_struct *ol
15198  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
15199  {
15200         struct task_struct *result = NULL;
15201 +
15202 +       if (type == PIDTYPE_REALPID)
15203 +               type = PIDTYPE_PID;
15204         if (pid) {
15205                 struct hlist_node *first;
15206                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
15207 @@ -420,7 +424,7 @@ EXPORT_SYMBOL(pid_task);
15208  struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
15209  {
15210         rcu_lockdep_assert(rcu_read_lock_held());
15211 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
15212 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
15213  }
15214  
15215  struct task_struct *find_task_by_vpid(pid_t vnr)
15216 @@ -464,7 +468,7 @@ struct pid *find_get_pid(pid_t nr)
15217  }
15218  EXPORT_SYMBOL_GPL(find_get_pid);
15219  
15220 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15221 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
15222  {
15223         struct upid *upid;
15224         pid_t nr = 0;
15225 @@ -477,6 +481,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
15226         return nr;
15227  }
15228  
15229 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15230 +{
15231 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
15232 +}
15233 +
15234  pid_t pid_vnr(struct pid *pid)
15235  {
15236         return pid_nr_ns(pid, current->nsproxy->pid_ns);
15237 diff -NurpP --minimal linux-3.0-rc5/kernel/pid_namespace.c linux-3.0-rc5-vs2.3.1-pre3/kernel/pid_namespace.c
15238 --- linux-3.0-rc5/kernel/pid_namespace.c        2011-05-22 16:17:59.000000000 +0200
15239 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/pid_namespace.c   2011-06-10 22:17:45.000000000 +0200
15240 @@ -15,6 +15,7 @@
15241  #include <linux/acct.h>
15242  #include <linux/slab.h>
15243  #include <linux/proc_fs.h>
15244 +#include <linux/vserver/global.h>
15245  
15246  #define BITS_PER_PAGE          (PAGE_SIZE*8)
15247  
15248 @@ -88,6 +89,7 @@ static struct pid_namespace *create_pid_
15249                 goto out_free_map;
15250  
15251         kref_init(&ns->kref);
15252 +       atomic_inc(&vs_global_pid_ns);
15253         ns->level = level;
15254         ns->parent = get_pid_ns(parent_pid_ns);
15255  
15256 @@ -119,6 +121,7 @@ static void destroy_pid_namespace(struct
15257  
15258         for (i = 0; i < PIDMAP_ENTRIES; i++)
15259                 kfree(ns->pidmap[i].page);
15260 +       atomic_dec(&vs_global_pid_ns);
15261         kmem_cache_free(pid_ns_cachep, ns);
15262  }
15263  
15264 diff -NurpP --minimal linux-3.0-rc5/kernel/posix-timers.c linux-3.0-rc5-vs2.3.1-pre3/kernel/posix-timers.c
15265 --- linux-3.0-rc5/kernel/posix-timers.c 2011-07-01 11:14:23.000000000 +0200
15266 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/posix-timers.c    2011-06-10 22:11:24.000000000 +0200
15267 @@ -47,6 +47,7 @@
15268  #include <linux/wait.h>
15269  #include <linux/workqueue.h>
15270  #include <linux/module.h>
15271 +#include <linux/vs_context.h>
15272  
15273  /*
15274   * Management arrays for POSIX timers.  Timers are kept in slab memory
15275 @@ -340,6 +341,7 @@ int posix_timer_event(struct k_itimer *t
15276  {
15277         struct task_struct *task;
15278         int shared, ret = -1;
15279 +
15280         /*
15281          * FIXME: if ->sigq is queued we can race with
15282          * dequeue_signal()->do_schedule_next_timer().
15283 @@ -356,10 +358,18 @@ int posix_timer_event(struct k_itimer *t
15284         rcu_read_lock();
15285         task = pid_task(timr->it_pid, PIDTYPE_PID);
15286         if (task) {
15287 +               struct vx_info_save vxis;
15288 +               struct vx_info *vxi;
15289 +
15290 +               vxi = get_vx_info(task->vx_info);
15291 +               enter_vx_info(vxi, &vxis);
15292                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
15293                 ret = send_sigqueue(timr->sigq, task, shared);
15294 +               leave_vx_info(&vxis);
15295 +               put_vx_info(vxi);
15296         }
15297         rcu_read_unlock();
15298 +
15299         /* If we failed to send the signal the timer stops. */
15300         return ret > 0;
15301  }
15302 diff -NurpP --minimal linux-3.0-rc5/kernel/printk.c linux-3.0-rc5-vs2.3.1-pre3/kernel/printk.c
15303 --- linux-3.0-rc5/kernel/printk.c       2011-07-01 11:14:23.000000000 +0200
15304 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/printk.c  2011-06-10 22:11:24.000000000 +0200
15305 @@ -41,6 +41,7 @@
15306  #include <linux/cpu.h>
15307  #include <linux/notifier.h>
15308  #include <linux/rculist.h>
15309 +#include <linux/vs_cvirt.h>
15310  
15311  #include <asm/uaccess.h>
15312  
15313 @@ -314,7 +315,7 @@ static int check_syslog_permissions(int 
15314                 return 0;
15315  
15316         if (syslog_action_restricted(type)) {
15317 -               if (capable(CAP_SYSLOG))
15318 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
15319                         return 0;
15320                 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
15321                 if (capable(CAP_SYS_ADMIN)) {
15322 @@ -342,12 +343,9 @@ int do_syslog(int type, char __user *buf
15323         if (error)
15324                 return error;
15325  
15326 -       switch (type) {
15327 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
15328 -               break;
15329 -       case SYSLOG_ACTION_OPEN:        /* Open log */
15330 -               break;
15331 -       case SYSLOG_ACTION_READ:        /* Read from log */
15332 +       if ((type == SYSLOG_ACTION_READ) ||
15333 +           (type == SYSLOG_ACTION_READ_ALL) ||
15334 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
15335                 error = -EINVAL;
15336                 if (!buf || len < 0)
15337                         goto out;
15338 @@ -358,6 +356,16 @@ int do_syslog(int type, char __user *buf
15339                         error = -EFAULT;
15340                         goto out;
15341                 }
15342 +       }
15343 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15344 +               return vx_do_syslog(type, buf, len);
15345 +
15346 +       switch (type) {
15347 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
15348 +               break;
15349 +       case SYSLOG_ACTION_OPEN:        /* Open log */
15350 +               break;
15351 +       case SYSLOG_ACTION_READ:        /* Read from log */
15352                 error = wait_event_interruptible(log_wait,
15353                                                         (log_start - log_end));
15354                 if (error)
15355 @@ -384,16 +392,6 @@ int do_syslog(int type, char __user *buf
15356                 /* FALL THRU */
15357         /* Read last kernel messages */
15358         case SYSLOG_ACTION_READ_ALL:
15359 -               error = -EINVAL;
15360 -               if (!buf || len < 0)
15361 -                       goto out;
15362 -               error = 0;
15363 -               if (!len)
15364 -                       goto out;
15365 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
15366 -                       error = -EFAULT;
15367 -                       goto out;
15368 -               }
15369                 count = len;
15370                 if (count > log_buf_len)
15371                         count = log_buf_len;
15372 diff -NurpP --minimal linux-3.0-rc5/kernel/ptrace.c linux-3.0-rc5-vs2.3.1-pre3/kernel/ptrace.c
15373 --- linux-3.0-rc5/kernel/ptrace.c       2011-07-01 11:14:23.000000000 +0200
15374 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/ptrace.c  2011-06-10 22:11:24.000000000 +0200
15375 @@ -22,6 +22,7 @@
15376  #include <linux/syscalls.h>
15377  #include <linux/uaccess.h>
15378  #include <linux/regset.h>
15379 +#include <linux/vs_context.h>
15380  #include <linux/hw_breakpoint.h>
15381  
15382  
15383 @@ -169,6 +170,11 @@ ok:
15384                 dumpable = get_dumpable(task->mm);
15385         if (!dumpable && !task_ns_capable(task, CAP_SYS_PTRACE))
15386                 return -EPERM;
15387 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
15388 +               return -EPERM;
15389 +       if (!vx_check(task->xid, VS_IDENT) &&
15390 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
15391 +               return -EACCES;
15392  
15393         return security_ptrace_access_check(task, mode);
15394  }
15395 diff -NurpP --minimal linux-3.0-rc5/kernel/sched.c linux-3.0-rc5-vs2.3.1-pre3/kernel/sched.c
15396 --- linux-3.0-rc5/kernel/sched.c        2011-07-01 11:14:23.000000000 +0200
15397 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/sched.c   2011-06-15 02:40:14.000000000 +0200
15398 @@ -71,6 +71,8 @@
15399  #include <linux/ctype.h>
15400  #include <linux/ftrace.h>
15401  #include <linux/slab.h>
15402 +#include <linux/vs_sched.h>
15403 +#include <linux/vs_cvirt.h>
15404  
15405  #include <asm/tlb.h>
15406  #include <asm/irq_regs.h>
15407 @@ -3429,9 +3431,17 @@ static void calc_global_nohz(unsigned lo
15408   */
15409  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
15410  {
15411 -       loads[0] = (avenrun[0] + offset) << shift;
15412 -       loads[1] = (avenrun[1] + offset) << shift;
15413 -       loads[2] = (avenrun[2] + offset) << shift;
15414 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
15415 +               struct vx_info *vxi = current_vx_info();
15416 +
15417 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
15418 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
15419 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
15420 +       } else {
15421 +               loads[0] = (avenrun[0] + offset) << shift;
15422 +               loads[1] = (avenrun[1] + offset) << shift;
15423 +               loads[2] = (avenrun[2] + offset) << shift;
15424 +       }
15425  }
15426  
15427  /*
15428 @@ -3714,16 +3724,19 @@ void account_user_time(struct task_struc
15429                        cputime_t cputime_scaled)
15430  {
15431         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
15432 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15433         cputime64_t tmp;
15434 +       int nice = (TASK_NICE(p) > 0);
15435  
15436         /* Add user time to process. */
15437         p->utime = cputime_add(p->utime, cputime);
15438         p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
15439 +       vx_account_user(vxi, cputime, nice);
15440         account_group_user_time(p, cputime);
15441  
15442         /* Add user time to cpustat. */
15443         tmp = cputime_to_cputime64(cputime);
15444 -       if (TASK_NICE(p) > 0)
15445 +       if (nice)
15446                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
15447         else
15448                 cpustat->user = cputime64_add(cpustat->user, tmp);
15449 @@ -3775,10 +3788,12 @@ void __account_system_time(struct task_s
15450                         cputime_t cputime_scaled, cputime64_t *target_cputime64)
15451  {
15452         cputime64_t tmp = cputime_to_cputime64(cputime);
15453 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15454  
15455         /* Add system time to process. */
15456         p->stime = cputime_add(p->stime, cputime);
15457         p->stimescaled = cputime_add(p->stimescaled, cputime_scaled);
15458 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
15459         account_group_system_time(p, cputime);
15460  
15461         /* Add system time to cpustat. */
15462 @@ -4936,7 +4951,7 @@ SYSCALL_DEFINE1(nice, int, increment)
15463                 nice = 19;
15464  
15465         if (increment < 0 && !can_nice(current, nice))
15466 -               return -EPERM;
15467 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
15468  
15469         retval = security_task_setnice(current, nice);
15470         if (retval)
15471 diff -NurpP --minimal linux-3.0-rc5/kernel/sched_fair.c linux-3.0-rc5-vs2.3.1-pre3/kernel/sched_fair.c
15472 --- linux-3.0-rc5/kernel/sched_fair.c   2011-07-01 11:14:23.000000000 +0200
15473 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/sched_fair.c      2011-06-10 22:11:24.000000000 +0200
15474 @@ -998,6 +998,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
15475                 __enqueue_entity(cfs_rq, se);
15476         se->on_rq = 1;
15477  
15478 +       if (entity_is_task(se))
15479 +               vx_activate_task(task_of(se));
15480         if (cfs_rq->nr_running == 1)
15481                 list_add_leaf_cfs_rq(cfs_rq);
15482  }
15483 @@ -1074,6 +1076,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
15484         if (se != cfs_rq->curr)
15485                 __dequeue_entity(cfs_rq, se);
15486         se->on_rq = 0;
15487 +       if (entity_is_task(se))
15488 +               vx_deactivate_task(task_of(se));
15489         update_cfs_load(cfs_rq, 0);
15490         account_entity_dequeue(cfs_rq, se);
15491  
15492 diff -NurpP --minimal linux-3.0-rc5/kernel/signal.c linux-3.0-rc5-vs2.3.1-pre3/kernel/signal.c
15493 --- linux-3.0-rc5/kernel/signal.c       2011-07-01 11:14:23.000000000 +0200
15494 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/signal.c  2011-06-22 12:39:16.000000000 +0200
15495 @@ -28,6 +28,8 @@
15496  #include <linux/freezer.h>
15497  #include <linux/pid_namespace.h>
15498  #include <linux/nsproxy.h>
15499 +#include <linux/vs_context.h>
15500 +#include <linux/vs_pid.h>
15501  #define CREATE_TRACE_POINTS
15502  #include <trace/events/signal.h>
15503  
15504 @@ -744,9 +746,18 @@ static int check_kill_permission(int sig
15505         struct pid *sid;
15506         int error;
15507  
15508 +       vxdprintk(VXD_CBIT(misc, 7),
15509 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
15510 +               sig, info, t, vx_task_xid(t), t->pid);
15511 +
15512         if (!valid_signal(sig))
15513                 return -EINVAL;
15514  
15515 +/*     FIXME: needed? if so, why?
15516 +       if ((info != SEND_SIG_NOINFO) &&
15517 +               (is_si_special(info) || !si_fromuser(info)))
15518 +               goto skip;      */
15519 +
15520         if (!si_fromuser(info))
15521                 return 0;
15522  
15523 @@ -770,6 +781,20 @@ static int check_kill_permission(int sig
15524                 }
15525         }
15526  
15527 +       error = -EPERM;
15528 +       if (t->pid == 1 && current->xid)
15529 +               return error;
15530 +
15531 +       error = -ESRCH;
15532 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
15533 +                 loops, maybe ENOENT or EACCES? */
15534 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
15535 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
15536 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
15537 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
15538 +               return error;
15539 +       }
15540 +/* skip: */
15541         return security_task_kill(t, info, sig, 0);
15542  }
15543  
15544 @@ -1239,7 +1264,7 @@ int kill_pid_info(int sig, struct siginf
15545         rcu_read_lock();
15546  retry:
15547         p = pid_task(pid, PIDTYPE_PID);
15548 -       if (p) {
15549 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
15550                 error = group_send_sig_info(sig, info, p);
15551                 if (unlikely(error == -ESRCH))
15552                         /*
15553 @@ -1278,7 +1303,7 @@ int kill_pid_info_as_uid(int sig, struct
15554  
15555         rcu_read_lock();
15556         p = pid_task(pid, PIDTYPE_PID);
15557 -       if (!p) {
15558 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
15559                 ret = -ESRCH;
15560                 goto out_unlock;
15561         }
15562 @@ -1333,8 +1358,10 @@ static int kill_something_info(int sig, 
15563                 struct task_struct * p;
15564  
15565                 for_each_process(p) {
15566 -                       if (task_pid_vnr(p) > 1 &&
15567 -                                       !same_thread_group(p, current)) {
15568 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
15569 +                               task_pid_vnr(p) > 1 &&
15570 +                               !same_thread_group(p, current) &&
15571 +                               !vx_current_initpid(p->pid)) {
15572                                 int err = group_send_sig_info(sig, info, p);
15573                                 ++count;
15574                                 if (err != -EPERM)
15575 @@ -2133,6 +2160,11 @@ relock:
15576                                 !sig_kernel_only(signr))
15577                         continue;
15578  
15579 +               /* virtual init is protected against user signals */
15580 +               if ((info->si_code == SI_USER) &&
15581 +                       vx_current_initpid(current->pid))
15582 +                       continue;
15583 +
15584                 if (sig_kernel_stop(signr)) {
15585                         /*
15586                          * The default action is to stop all threads in
15587 diff -NurpP --minimal linux-3.0-rc5/kernel/softirq.c linux-3.0-rc5-vs2.3.1-pre3/kernel/softirq.c
15588 --- linux-3.0-rc5/kernel/softirq.c      2011-07-01 11:14:23.000000000 +0200
15589 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/softirq.c 2011-06-22 12:39:16.000000000 +0200
15590 @@ -24,6 +24,7 @@
15591  #include <linux/ftrace.h>
15592  #include <linux/smp.h>
15593  #include <linux/tick.h>
15594 +#include <linux/vs_context.h>
15595  
15596  #define CREATE_TRACE_POINTS
15597  #include <trace/events/irq.h>
15598 diff -NurpP --minimal linux-3.0-rc5/kernel/sys.c linux-3.0-rc5-vs2.3.1-pre3/kernel/sys.c
15599 --- linux-3.0-rc5/kernel/sys.c  2011-07-01 11:14:23.000000000 +0200
15600 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/sys.c     2011-06-10 22:11:24.000000000 +0200
15601 @@ -43,6 +43,7 @@
15602  #include <linux/syscalls.h>
15603  #include <linux/kprobes.h>
15604  #include <linux/user_namespace.h>
15605 +#include <linux/vs_pid.h>
15606  
15607  #include <linux/kmsg_dump.h>
15608  
15609 @@ -151,7 +152,10 @@ static int set_one_prio(struct task_stru
15610                 goto out;
15611         }
15612         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
15613 -               error = -EACCES;
15614 +               if (vx_flags(VXF_IGNEG_NICE, 0))
15615 +                       error = 0;
15616 +               else
15617 +                       error = -EACCES;
15618                 goto out;
15619         }
15620         no_nice = security_task_setnice(p, niceval);
15621 @@ -201,6 +205,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
15622                         else
15623                                 pgrp = task_pgrp(current);
15624                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15625 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15626 +                                       continue;
15627                                 error = set_one_prio(p, niceval, error);
15628                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
15629                         break;
15630 @@ -264,6 +270,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
15631                         else
15632                                 pgrp = task_pgrp(current);
15633                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15634 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15635 +                                       continue;
15636                                 niceval = 20 - task_nice(p);
15637                                 if (niceval > retval)
15638                                         retval = niceval;
15639 @@ -383,6 +391,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
15640  
15641  static DEFINE_MUTEX(reboot_mutex);
15642  
15643 +long vs_reboot(unsigned int, void __user *);
15644 +
15645  /*
15646   * Reboot system call: for obvious reasons only root may call it,
15647   * and even root needs to set up some magic numbers in the registers
15648 @@ -415,6 +425,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
15649         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
15650                 cmd = LINUX_REBOOT_CMD_HALT;
15651  
15652 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15653 +               return vs_reboot(cmd, arg);
15654 +
15655         mutex_lock(&reboot_mutex);
15656         switch (cmd) {
15657         case LINUX_REBOOT_CMD_RESTART:
15658 @@ -1365,7 +1378,7 @@ int do_prlimit(struct task_struct *tsk, 
15659                 /* Keep the capable check against init_user_ns until
15660                    cgroups can contain all limits */
15661                 if (new_rlim->rlim_max > rlim->rlim_max &&
15662 -                               !capable(CAP_SYS_RESOURCE))
15663 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15664                         retval = -EPERM;
15665                 if (!retval)
15666                         retval = security_task_setrlimit(tsk->group_leader,
15667 diff -NurpP --minimal linux-3.0-rc5/kernel/sysctl.c linux-3.0-rc5-vs2.3.1-pre3/kernel/sysctl.c
15668 --- linux-3.0-rc5/kernel/sysctl.c       2011-07-01 11:14:23.000000000 +0200
15669 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/sysctl.c  2011-06-15 02:40:14.000000000 +0200
15670 @@ -75,6 +75,7 @@
15671  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
15672  #include <linux/lockdep.h>
15673  #endif
15674 +extern char vshelper_path[];
15675  #ifdef CONFIG_CHR_DEV_SG
15676  #include <scsi/sg.h>
15677  #endif
15678 @@ -568,6 +569,13 @@ static struct ctl_table kern_table[] = {
15679                 .proc_handler   = proc_dostring,
15680         },
15681  #endif
15682 +       {
15683 +               .procname       = "vshelper",
15684 +               .data           = &vshelper_path,
15685 +               .maxlen         = 256,
15686 +               .mode           = 0644,
15687 +               .proc_handler   = &proc_dostring,
15688 +       },
15689  #ifdef CONFIG_CHR_DEV_SG
15690         {
15691                 .procname       = "sg-big-buff",
15692 diff -NurpP --minimal linux-3.0-rc5/kernel/sysctl_binary.c linux-3.0-rc5-vs2.3.1-pre3/kernel/sysctl_binary.c
15693 --- linux-3.0-rc5/kernel/sysctl_binary.c        2011-05-22 16:17:59.000000000 +0200
15694 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/sysctl_binary.c   2011-06-10 22:11:24.000000000 +0200
15695 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
15696  
15697         { CTL_INT,      KERN_PANIC,                     "panic" },
15698         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
15699 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
15700  
15701         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
15702         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
15703 diff -NurpP --minimal linux-3.0-rc5/kernel/time/timekeeping.c linux-3.0-rc5-vs2.3.1-pre3/kernel/time/timekeeping.c
15704 --- linux-3.0-rc5/kernel/time/timekeeping.c     2011-07-01 11:14:23.000000000 +0200
15705 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/time/timekeeping.c        2011-06-10 22:11:24.000000000 +0200
15706 @@ -233,6 +233,7 @@ void getnstimeofday(struct timespec *ts)
15707         } while (read_seqretry(&xtime_lock, seq));
15708  
15709         timespec_add_ns(ts, nsecs);
15710 +       vx_adjust_timespec(ts);
15711  }
15712  
15713  EXPORT_SYMBOL(getnstimeofday);
15714 diff -NurpP --minimal linux-3.0-rc5/kernel/time.c linux-3.0-rc5-vs2.3.1-pre3/kernel/time.c
15715 --- linux-3.0-rc5/kernel/time.c 2011-05-22 16:17:59.000000000 +0200
15716 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/time.c    2011-06-10 22:11:24.000000000 +0200
15717 @@ -92,7 +92,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
15718         if (err)
15719                 return err;
15720  
15721 -       do_settimeofday(&tv);
15722 +       vx_settimeofday(&tv);
15723         return 0;
15724  }
15725  
15726 @@ -177,7 +177,7 @@ int do_sys_settimeofday(const struct tim
15727                 /* SMP safe, again the code in arch/foo/time.c should
15728                  * globally block out interrupts when it runs.
15729                  */
15730 -               return do_settimeofday(tv);
15731 +               return vx_settimeofday(tv);
15732         }
15733         return 0;
15734  }
15735 diff -NurpP --minimal linux-3.0-rc5/kernel/timer.c linux-3.0-rc5-vs2.3.1-pre3/kernel/timer.c
15736 --- linux-3.0-rc5/kernel/timer.c        2011-07-01 11:14:23.000000000 +0200
15737 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/timer.c   2011-06-15 02:40:14.000000000 +0200
15738 @@ -40,6 +40,10 @@
15739  #include <linux/irq_work.h>
15740  #include <linux/sched.h>
15741  #include <linux/slab.h>
15742 +#include <linux/vs_base.h>
15743 +#include <linux/vs_cvirt.h>
15744 +#include <linux/vs_pid.h>
15745 +#include <linux/vserver/sched.h>
15746  
15747  #include <asm/uaccess.h>
15748  #include <asm/unistd.h>
15749 @@ -1336,12 +1340,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
15750  
15751  #endif
15752  
15753 -#ifndef __alpha__
15754 -
15755 -/*
15756 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
15757 - * should be moved into arch/i386 instead?
15758 - */
15759  
15760  /**
15761   * sys_getpid - return the thread group id of the current process
15762 @@ -1370,10 +1368,23 @@ SYSCALL_DEFINE0(getppid)
15763         rcu_read_lock();
15764         pid = task_tgid_vnr(current->real_parent);
15765         rcu_read_unlock();
15766 +       return vx_map_pid(pid);
15767 +}
15768  
15769 -       return pid;
15770 +#ifdef __alpha__
15771 +
15772 +/*
15773 + * The Alpha uses getxpid, getxuid, and getxgid instead.
15774 + */
15775 +
15776 +asmlinkage long do_getxpid(long *ppid)
15777 +{
15778 +       *ppid = sys_getppid();
15779 +       return sys_getpid();
15780  }
15781  
15782 +#else /* _alpha_ */
15783 +
15784  SYSCALL_DEFINE0(getuid)
15785  {
15786         /* Only we change this so SMP safe */
15787 diff -NurpP --minimal linux-3.0-rc5/kernel/user_namespace.c linux-3.0-rc5-vs2.3.1-pre3/kernel/user_namespace.c
15788 --- linux-3.0-rc5/kernel/user_namespace.c       2011-03-15 18:07:42.000000000 +0100
15789 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/user_namespace.c  2011-06-10 22:11:24.000000000 +0200
15790 @@ -11,6 +11,7 @@
15791  #include <linux/user_namespace.h>
15792  #include <linux/highuid.h>
15793  #include <linux/cred.h>
15794 +#include <linux/vserver/global.h>
15795  
15796  static struct kmem_cache *user_ns_cachep __read_mostly;
15797  
15798 @@ -33,6 +34,7 @@ int create_user_ns(struct cred *new)
15799                 return -ENOMEM;
15800  
15801         kref_init(&ns->kref);
15802 +       atomic_inc(&vs_global_user_ns);
15803  
15804         for (n = 0; n < UIDHASH_SZ; ++n)
15805                 INIT_HLIST_HEAD(ns->uidhash_table + n);
15806 @@ -81,6 +83,8 @@ void free_user_ns(struct kref *kref)
15807         struct user_namespace *ns =
15808                 container_of(kref, struct user_namespace, kref);
15809  
15810 +       /* FIXME: maybe move into destroyer? */
15811 +       atomic_dec(&vs_global_user_ns);
15812         INIT_WORK(&ns->destroyer, free_user_ns_work);
15813         schedule_work(&ns->destroyer);
15814  }
15815 diff -NurpP --minimal linux-3.0-rc5/kernel/utsname.c linux-3.0-rc5-vs2.3.1-pre3/kernel/utsname.c
15816 --- linux-3.0-rc5/kernel/utsname.c      2011-07-01 11:14:23.000000000 +0200
15817 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/utsname.c 2011-06-13 14:09:44.000000000 +0200
15818 @@ -16,14 +16,17 @@
15819  #include <linux/slab.h>
15820  #include <linux/user_namespace.h>
15821  #include <linux/proc_fs.h>
15822 +#include <linux/vserver/global.h>
15823  
15824  static struct uts_namespace *create_uts_ns(void)
15825  {
15826         struct uts_namespace *uts_ns;
15827  
15828         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
15829 -       if (uts_ns)
15830 +       if (uts_ns) {
15831                 kref_init(&uts_ns->kref);
15832 +               atomic_inc(&vs_global_uts_ns);
15833 +       }
15834         return uts_ns;
15835  }
15836  
15837 @@ -32,8 +35,8 @@ static struct uts_namespace *create_uts_
15838   * @old_ns: namespace to clone
15839   * Return NULL on error (failure to kmalloc), new ns otherwise
15840   */
15841 -static struct uts_namespace *clone_uts_ns(struct task_struct *tsk,
15842 -                                         struct uts_namespace *old_ns)
15843 +static struct uts_namespace *clone_uts_ns(struct uts_namespace *old_ns,
15844 +                                         struct user_namespace *old_user)
15845  {
15846         struct uts_namespace *ns;
15847  
15848 @@ -43,7 +46,7 @@ static struct uts_namespace *clone_uts_n
15849  
15850         down_read(&uts_sem);
15851         memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
15852 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user)->user_ns);
15853 +       ns->user_ns = get_user_ns(old_user);
15854         up_read(&uts_sem);
15855         return ns;
15856  }
15857 @@ -55,9 +58,9 @@ static struct uts_namespace *clone_uts_n
15858   * versa.
15859   */
15860  struct uts_namespace *copy_utsname(unsigned long flags,
15861 -                                  struct task_struct *tsk)
15862 +                                  struct uts_namespace *old_ns,
15863 +                                  struct user_namespace *user_ns)
15864  {
15865 -       struct uts_namespace *old_ns = tsk->nsproxy->uts_ns;
15866         struct uts_namespace *new_ns;
15867  
15868         BUG_ON(!old_ns);
15869 @@ -66,7 +69,7 @@ struct uts_namespace *copy_utsname(unsig
15870         if (!(flags & CLONE_NEWUTS))
15871                 return old_ns;
15872  
15873 -       new_ns = clone_uts_ns(tsk, old_ns);
15874 +       new_ns = clone_uts_ns(old_ns, user_ns);
15875  
15876         put_uts_ns(old_ns);
15877         return new_ns;
15878 @@ -78,6 +81,7 @@ void free_uts_ns(struct kref *kref)
15879  
15880         ns = container_of(kref, struct uts_namespace, kref);
15881         put_user_ns(ns->user_ns);
15882 +       atomic_dec(&vs_global_uts_ns);
15883         kfree(ns);
15884  }
15885  
15886 diff -NurpP --minimal linux-3.0-rc5/kernel/vserver/Kconfig linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/Kconfig
15887 --- linux-3.0-rc5/kernel/vserver/Kconfig        1970-01-01 01:00:00.000000000 +0100
15888 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/Kconfig   2011-06-10 22:11:24.000000000 +0200
15889 @@ -0,0 +1,228 @@
15890 +#
15891 +# Linux VServer configuration
15892 +#
15893 +
15894 +menu "Linux VServer"
15895 +
15896 +config VSERVER_AUTO_LBACK
15897 +       bool    "Automatically Assign Loopback IP"
15898 +       default y
15899 +       help
15900 +         Automatically assign a guest specific loopback
15901 +         IP and add it to the kernel network stack on
15902 +         startup.
15903 +
15904 +config VSERVER_AUTO_SINGLE
15905 +       bool    "Automatic Single IP Special Casing"
15906 +       depends on EXPERIMENTAL
15907 +       default y
15908 +       help
15909 +         This allows network contexts with a single IP to
15910 +         automatically remap 0.0.0.0 bindings to that IP,
15911 +         avoiding further network checks and improving
15912 +         performance.
15913 +
15914 +         (note: such guests do not allow to change the ip
15915 +          on the fly and do not show loopback addresses)
15916 +
15917 +config VSERVER_COWBL
15918 +       bool    "Enable COW Immutable Link Breaking"
15919 +       default y
15920 +       help
15921 +         This enables the COW (Copy-On-Write) link break code.
15922 +         It allows you to treat unified files like normal files
15923 +         when writing to them (which will implicitely break the
15924 +         link and create a copy of the unified file)
15925 +
15926 +config VSERVER_VTIME
15927 +       bool    "Enable Virtualized Guest Time"
15928 +       depends on EXPERIMENTAL
15929 +       default n
15930 +       help
15931 +         This enables per guest time offsets to allow for
15932 +         adjusting the system clock individually per guest.
15933 +         this adds some overhead to the time functions and
15934 +         therefore should not be enabled without good reason.
15935 +
15936 +config VSERVER_DEVICE
15937 +       bool    "Enable Guest Device Mapping"
15938 +       depends on EXPERIMENTAL
15939 +       default n
15940 +       help
15941 +         This enables generic device remapping.
15942 +
15943 +config VSERVER_PROC_SECURE
15944 +       bool    "Enable Proc Security"
15945 +       depends on PROC_FS
15946 +       default y
15947 +       help
15948 +         This configures ProcFS security to initially hide
15949 +         non-process entries for all contexts except the main and
15950 +         spectator context (i.e. for all guests), which is a secure
15951 +         default.
15952 +
15953 +         (note: on 1.2x the entries were visible by default)
15954 +
15955 +choice
15956 +       prompt  "Persistent Inode Tagging"
15957 +       default TAGGING_ID24
15958 +       help
15959 +         This adds persistent context information to filesystems
15960 +         mounted with the tagxid option. Tagging is a requirement
15961 +         for per-context disk limits and per-context quota.
15962 +
15963 +
15964 +config TAGGING_NONE
15965 +       bool    "Disabled"
15966 +       help
15967 +         do not store per-context information in inodes.
15968 +
15969 +config TAGGING_UID16
15970 +       bool    "UID16/GID32"
15971 +       help
15972 +         reduces UID to 16 bit, but leaves GID at 32 bit.
15973 +
15974 +config TAGGING_GID16
15975 +       bool    "UID32/GID16"
15976 +       help
15977 +         reduces GID to 16 bit, but leaves UID at 32 bit.
15978 +
15979 +config TAGGING_ID24
15980 +       bool    "UID24/GID24"
15981 +       help
15982 +         uses the upper 8bit from UID and GID for XID tagging
15983 +         which leaves 24bit for UID/GID each, which should be
15984 +         more than sufficient for normal use.
15985 +
15986 +config TAGGING_INTERN
15987 +       bool    "UID32/GID32"
15988 +       help
15989 +         this uses otherwise reserved inode fields in the on
15990 +         disk representation, which limits the use to a few
15991 +         filesystems (currently ext2 and ext3)
15992 +
15993 +endchoice
15994 +
15995 +config TAG_NFSD
15996 +       bool    "Tag NFSD User Auth and Files"
15997 +       default n
15998 +       help
15999 +         Enable this if you do want the in-kernel NFS
16000 +         Server to use the tagging specified above.
16001 +         (will require patched clients too)
16002 +
16003 +config VSERVER_PRIVACY
16004 +       bool    "Honor Privacy Aspects of Guests"
16005 +       default n
16006 +       help
16007 +         When enabled, most context checks will disallow
16008 +         access to structures assigned to a specific context,
16009 +         like ptys or loop devices.
16010 +
16011 +config VSERVER_CONTEXTS
16012 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
16013 +       range 1 65533
16014 +       default "768"   if 64BIT
16015 +       default "256"
16016 +       help
16017 +         This setting will optimize certain data structures
16018 +         and memory allocations according to the expected
16019 +         maximum.
16020 +
16021 +         note: this is not a strict upper limit.
16022 +
16023 +config VSERVER_WARN
16024 +       bool    "VServer Warnings"
16025 +       default y
16026 +       help
16027 +         This enables various runtime warnings, which will
16028 +         notify about potential manipulation attempts or
16029 +         resource shortage. It is generally considered to
16030 +         be a good idea to have that enabled.
16031 +
16032 +config VSERVER_WARN_DEVPTS
16033 +       bool    "VServer DevPTS Warnings"
16034 +       depends on VSERVER_WARN
16035 +       default y
16036 +       help
16037 +         This enables DevPTS related warnings, issued when a
16038 +         process inside a context tries to lookup or access
16039 +         a dynamic pts from the host or a different context.
16040 +
16041 +config VSERVER_DEBUG
16042 +       bool    "VServer Debugging Code"
16043 +       default n
16044 +       help
16045 +         Set this to yes if you want to be able to activate
16046 +         debugging output at runtime. It adds a very small
16047 +         overhead to all vserver related functions and
16048 +         increases the kernel size by about 20k.
16049 +
16050 +config VSERVER_HISTORY
16051 +       bool    "VServer History Tracing"
16052 +       depends on VSERVER_DEBUG
16053 +       default n
16054 +       help
16055 +         Set this to yes if you want to record the history of
16056 +         linux-vserver activities, so they can be replayed in
16057 +         the event of a kernel panic or oops.
16058 +
16059 +config VSERVER_HISTORY_SIZE
16060 +       int     "Per-CPU History Size (32-65536)"
16061 +       depends on VSERVER_HISTORY
16062 +       range 32 65536
16063 +       default 64
16064 +       help
16065 +         This allows you to specify the number of entries in
16066 +         the per-CPU history buffer.
16067 +
16068 +config VSERVER_LEGACY_MEM
16069 +       bool    "Legacy Memory Limits"
16070 +       default n
16071 +       help
16072 +         This provides fake memory limits to keep
16073 +         older tools happy in the face of memory
16074 +         cgroups
16075 +
16076 +choice
16077 +       prompt  "Quotes used in debug and warn messages"
16078 +       default QUOTES_ISO8859
16079 +
16080 +config QUOTES_ISO8859
16081 +       bool    "Extended ASCII (ISO 8859) angle quotes"
16082 +       help
16083 +         This uses the extended ASCII characters \xbb
16084 +         and \xab for quoting file and process names.
16085 +
16086 +config QUOTES_UTF8
16087 +       bool    "UTF-8 angle quotes"
16088 +       help
16089 +         This uses the the UTF-8 sequences for angle
16090 +         quotes to quote file and process names.
16091 +
16092 +config QUOTES_ASCII
16093 +       bool    "ASCII single quotes"
16094 +       help
16095 +         This uses the ASCII single quote character
16096 +         (\x27) to quote file and process names.
16097 +
16098 +endchoice
16099 +
16100 +endmenu
16101 +
16102 +
16103 +config VSERVER
16104 +       bool
16105 +       default y
16106 +       select NAMESPACES
16107 +       select UTS_NS
16108 +       select IPC_NS
16109 +       select USER_NS
16110 +       select SYSVIPC
16111 +
16112 +config VSERVER_SECURITY
16113 +       bool
16114 +       depends on SECURITY
16115 +       default y
16116 +       select SECURITY_CAPABILITIES
16117 +
16118 diff -NurpP --minimal linux-3.0-rc5/kernel/vserver/Makefile linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/Makefile
16119 --- linux-3.0-rc5/kernel/vserver/Makefile       1970-01-01 01:00:00.000000000 +0100
16120 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/Makefile  2011-06-10 22:11:24.000000000 +0200
16121 @@ -0,0 +1,18 @@
16122 +#
16123 +# Makefile for the Linux vserver routines.
16124 +#
16125 +
16126 +
16127 +obj-y          += vserver.o
16128 +
16129 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
16130 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
16131 +                  dlimit.o tag.o
16132 +
16133 +vserver-$(CONFIG_INET) += inet.o
16134 +vserver-$(CONFIG_PROC_FS) += proc.o
16135 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
16136 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
16137 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
16138 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
16139 +
16140 diff -NurpP --minimal linux-3.0-rc5/kernel/vserver/cacct.c linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/cacct.c
16141 --- linux-3.0-rc5/kernel/vserver/cacct.c        1970-01-01 01:00:00.000000000 +0100
16142 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/cacct.c   2011-06-10 22:11:24.000000000 +0200
16143 @@ -0,0 +1,42 @@
16144 +/*
16145 + *  linux/kernel/vserver/cacct.c
16146 + *
16147 + *  Virtual Server: Context Accounting
16148 + *
16149 + *  Copyright (C) 2006-2007 Herbert Pötzl
16150 + *
16151 + *  V0.01  added accounting stats
16152 + *
16153 + */
16154 +
16155 +#include <linux/types.h>
16156 +#include <linux/vs_context.h>
16157 +#include <linux/vserver/cacct_cmd.h>
16158 +#include <linux/vserver/cacct_int.h>
16159 +
16160 +#include <asm/errno.h>
16161 +#include <asm/uaccess.h>
16162 +
16163 +
16164 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
16165 +{
16166 +       struct vcmd_sock_stat_v0 vc_data;
16167 +       int j, field;
16168 +
16169 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16170 +               return -EFAULT;
16171 +
16172 +       field = vc_data.field;
16173 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
16174 +               return -EINVAL;
16175 +
16176 +       for (j = 0; j < 3; j++) {
16177 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
16178 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
16179 +       }
16180 +
16181 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16182 +               return -EFAULT;
16183 +       return 0;
16184 +}
16185 +
16186 diff -NurpP --minimal linux-3.0-rc5/kernel/vserver/cacct_init.h linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/cacct_init.h
16187 --- linux-3.0-rc5/kernel/vserver/cacct_init.h   1970-01-01 01:00:00.000000000 +0100
16188 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/cacct_init.h      2011-06-10 22:11:24.000000000 +0200
16189 @@ -0,0 +1,25 @@
16190 +
16191 +
16192 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
16193 +{
16194 +       int i, j;
16195 +
16196 +
16197 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
16198 +               for (j = 0; j < 3; j++) {
16199 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
16200 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
16201 +               }
16202 +       }
16203 +       for (i = 0; i < 8; i++)
16204 +               atomic_set(&cacct->slab[i], 0);
16205 +       for (i = 0; i < 5; i++)
16206 +               for (j = 0; j < 4; j++)
16207 +                       atomic_set(&cacct->page[i][j], 0);
16208 +}
16209 +
16210 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
16211 +{
16212 +       return;
16213 +}
16214 +
16215 diff -NurpP --minimal linux-3.0-rc5/kernel/vserver/cacct_proc.h linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/cacct_proc.h
16216 --- linux-3.0-rc5/kernel/vserver/cacct_proc.h   1970-01-01 01:00:00.000000000 +0100
16217 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/cacct_proc.h      2011-06-10 22:11:24.000000000 +0200
16218 @@ -0,0 +1,53 @@
16219 +#ifndef _VX_CACCT_PROC_H
16220 +#define _VX_CACCT_PROC_H
16221 +
16222 +#include <linux/vserver/cacct_int.h>
16223 +
16224 +
16225 +#define VX_SOCKA_TOP   \
16226 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
16227 +
16228 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
16229 +{
16230 +       int i, j, length = 0;
16231 +       static char *type[VXA_SOCK_SIZE] = {
16232 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
16233 +       };
16234 +
16235 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
16236 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
16237 +               length += sprintf(buffer + length, "%s:", type[i]);
16238 +               for (j = 0; j < 3; j++) {
16239 +                       length += sprintf(buffer + length,
16240 +                               "\t%10lu/%-10lu",
16241 +                               vx_sock_count(cacct, i, j),
16242 +                               vx_sock_total(cacct, i, j));
16243 +               }
16244 +               buffer[length++] = '\n';
16245 +       }
16246 +
16247 +       length += sprintf(buffer + length, "\n");
16248 +       length += sprintf(buffer + length,
16249 +               "slab:\t %8u %8u %8u %8u\n",
16250 +               atomic_read(&cacct->slab[1]),
16251 +               atomic_read(&cacct->slab[4]),
16252 +               atomic_read(&cacct->slab[0]),
16253 +               atomic_read(&cacct->slab[2]));
16254 +
16255 +       length += sprintf(buffer + length, "\n");
16256 +       for (i = 0; i < 5; i++) {
16257 +               length += sprintf(buffer + length,
16258 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
16259 +                       atomic_read(&cacct->page[i][0]),
16260 +                       atomic_read(&cacct->page[i][1]),
16261 +                       atomic_read(&cacct->page[i][2]),
16262 +                       atomic_read(&cacct->page[i][3]),
16263 +                       atomic_read(&cacct->page[i][4]),
16264 +                       atomic_read(&cacct->page[i][5]),
16265 +                       atomic_read(&cacct->page[i][6]),
16266 +                       atomic_read(&cacct->page[i][7]));
16267 +       }
16268 +       return length;
16269 +}
16270 +
16271 +#endif /* _VX_CACCT_PROC_H */
16272 diff -NurpP --minimal linux-3.0-rc5/kernel/vserver/context.c linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/context.c
16273 --- linux-3.0-rc5/kernel/vserver/context.c      1970-01-01 01:00:00.000000000 +0100
16274 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/context.c 2011-06-16 14:16:51.000000000 +0200
16275 @@ -0,0 +1,1080 @@
16276 +/*
16277 + *  linux/kernel/vserver/context.c
16278 + *
16279 + *  Virtual Server: Context Support
16280 + *
16281 + *  Copyright (C) 2003-2010  Herbert Pötzl
16282 + *
16283 + *  V0.01  context helper
16284 + *  V0.02  vx_ctx_kill syscall command
16285 + *  V0.03  replaced context_info calls
16286 + *  V0.04  redesign of struct (de)alloc
16287 + *  V0.05  rlimit basic implementation
16288 + *  V0.06  task_xid and info commands
16289 + *  V0.07  context flags and caps
16290 + *  V0.08  switch to RCU based hash
16291 + *  V0.09  revert to non RCU for now
16292 + *  V0.10  and back to working RCU hash
16293 + *  V0.11  and back to locking again
16294 + *  V0.12  referenced context store
16295 + *  V0.13  separate per cpu data
16296 + *  V0.14  changed vcmds to vxi arg
16297 + *  V0.15  added context stat
16298 + *  V0.16  have __create claim() the vxi
16299 + *  V0.17  removed older and legacy stuff
16300 + *  V0.18  added user credentials
16301 + *
16302 + */
16303 +
16304 +#include <linux/slab.h>
16305 +#include <linux/types.h>
16306 +#include <linux/security.h>
16307 +#include <linux/pid_namespace.h>
16308 +#include <linux/capability.h>
16309 +
16310 +#include <linux/vserver/context.h>
16311 +#include <linux/vserver/network.h>
16312 +#include <linux/vserver/debug.h>
16313 +#include <linux/vserver/limit.h>
16314 +#include <linux/vserver/limit_int.h>
16315 +#include <linux/vserver/space.h>
16316 +#include <linux/init_task.h>
16317 +#include <linux/fs_struct.h>
16318 +#include <linux/cred.h>
16319 +
16320 +#include <linux/vs_context.h>
16321 +#include <linux/vs_limit.h>
16322 +#include <linux/vs_pid.h>
16323 +#include <linux/vserver/context_cmd.h>
16324 +
16325 +#include "cvirt_init.h"
16326 +#include "cacct_init.h"
16327 +#include "limit_init.h"
16328 +#include "sched_init.h"
16329 +
16330 +
16331 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
16332 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
16333 +
16334 +
16335 +/*     now inactive context structures */
16336 +
16337 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
16338 +
16339 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
16340 +
16341 +
16342 +/*     __alloc_vx_info()
16343 +
16344 +       * allocate an initialized vx_info struct
16345 +       * doesn't make it visible (hash)                        */
16346 +
16347 +static struct vx_info *__alloc_vx_info(xid_t xid)
16348 +{
16349 +       struct vx_info *new = NULL;
16350 +       int cpu, index;
16351 +
16352 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
16353 +
16354 +       /* would this benefit from a slab cache? */
16355 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
16356 +       if (!new)
16357 +               return 0;
16358 +
16359 +       memset(new, 0, sizeof(struct vx_info));
16360 +#ifdef CONFIG_SMP
16361 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
16362 +       if (!new->ptr_pc)
16363 +               goto error;
16364 +#endif
16365 +       new->vx_id = xid;
16366 +       INIT_HLIST_NODE(&new->vx_hlist);
16367 +       atomic_set(&new->vx_usecnt, 0);
16368 +       atomic_set(&new->vx_tasks, 0);
16369 +       new->vx_parent = NULL;
16370 +       new->vx_state = 0;
16371 +       init_waitqueue_head(&new->vx_wait);
16372 +
16373 +       /* prepare reaper */
16374 +       get_task_struct(init_pid_ns.child_reaper);
16375 +       new->vx_reaper = init_pid_ns.child_reaper;
16376 +       new->vx_badness_bias = 0;
16377 +
16378 +       /* rest of init goes here */
16379 +       vx_info_init_limit(&new->limit);
16380 +       vx_info_init_sched(&new->sched);
16381 +       vx_info_init_cvirt(&new->cvirt);
16382 +       vx_info_init_cacct(&new->cacct);
16383 +
16384 +       /* per cpu data structures */
16385 +       for_each_possible_cpu(cpu) {
16386 +               vx_info_init_sched_pc(
16387 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
16388 +               vx_info_init_cvirt_pc(
16389 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
16390 +       }
16391 +
16392 +       new->vx_flags = VXF_INIT_SET;
16393 +       new->vx_bcaps = CAP_FULL_SET;
16394 +       new->vx_ccaps = 0;
16395 +       new->vx_umask = 0;
16396 +
16397 +       new->reboot_cmd = 0;
16398 +       new->exit_code = 0;
16399 +
16400 +       // preconfig spaces
16401 +       for (index = 0; index < VX_SPACES; index++) {
16402 +               struct _vx_space *space = &new->space[index];
16403 +
16404 +               // filesystem
16405 +               spin_lock(&init_fs.lock);
16406 +               init_fs.users++;
16407 +               spin_unlock(&init_fs.lock);
16408 +               space->vx_fs = &init_fs;
16409 +
16410 +               /* FIXME: do we want defaults? */
16411 +               // space->vx_real_cred = 0;
16412 +               // space->vx_cred = 0;
16413 +       }
16414 +
16415 +
16416 +       vxdprintk(VXD_CBIT(xid, 0),
16417 +               "alloc_vx_info(%d) = %p", xid, new);
16418 +       vxh_alloc_vx_info(new);
16419 +       atomic_inc(&vx_global_ctotal);
16420 +       return new;
16421 +#ifdef CONFIG_SMP
16422 +error:
16423 +       kfree(new);
16424 +       return 0;
16425 +#endif
16426 +}
16427 +
16428 +/*     __dealloc_vx_info()
16429 +
16430 +       * final disposal of vx_info                             */
16431 +
16432 +static void __dealloc_vx_info(struct vx_info *vxi)
16433 +{
16434 +#ifdef CONFIG_VSERVER_WARN
16435 +       struct vx_info_save vxis;
16436 +       int cpu;
16437 +#endif
16438 +       vxdprintk(VXD_CBIT(xid, 0),
16439 +               "dealloc_vx_info(%p)", vxi);
16440 +       vxh_dealloc_vx_info(vxi);
16441 +
16442 +#ifdef CONFIG_VSERVER_WARN
16443 +       enter_vx_info(vxi, &vxis);
16444 +       vx_info_exit_limit(&vxi->limit);
16445 +       vx_info_exit_sched(&vxi->sched);
16446 +       vx_info_exit_cvirt(&vxi->cvirt);
16447 +       vx_info_exit_cacct(&vxi->cacct);
16448 +
16449 +       for_each_possible_cpu(cpu) {
16450 +               vx_info_exit_sched_pc(
16451 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
16452 +               vx_info_exit_cvirt_pc(
16453 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
16454 +       }
16455 +       leave_vx_info(&vxis);
16456 +#endif
16457 +
16458 +       vxi->vx_id = -1;
16459 +       vxi->vx_state |= VXS_RELEASED;
16460 +
16461 +#ifdef CONFIG_SMP
16462 +       free_percpu(vxi->ptr_pc);
16463 +#endif
16464 +       kfree(vxi);
16465 +       atomic_dec(&vx_global_ctotal);
16466 +}
16467 +
16468 +static void __shutdown_vx_info(struct vx_info *vxi)
16469 +{
16470 +       struct nsproxy *nsproxy;
16471 +       struct fs_struct *fs;
16472 +       struct cred *cred;
16473 +       int index, kill;
16474 +
16475 +       might_sleep();
16476 +
16477 +       vxi->vx_state |= VXS_SHUTDOWN;
16478 +       vs_state_change(vxi, VSC_SHUTDOWN);
16479 +
16480 +       for (index = 0; index < VX_SPACES; index++) {
16481 +               struct _vx_space *space = &vxi->space[index];
16482 +
16483 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
16484 +               if (nsproxy)
16485 +                       put_nsproxy(nsproxy);
16486 +
16487 +               fs = xchg(&space->vx_fs, NULL);
16488 +               spin_lock(&fs->lock);
16489 +               kill = !--fs->users;
16490 +               spin_unlock(&fs->lock);
16491 +               if (kill)
16492 +                       free_fs_struct(fs);
16493 +
16494 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
16495 +               if (cred)
16496 +                       abort_creds(cred);
16497 +       }
16498 +}
16499 +
16500 +/* exported stuff */
16501 +
16502 +void free_vx_info(struct vx_info *vxi)
16503 +{
16504 +       unsigned long flags;
16505 +       unsigned index;
16506 +
16507 +       /* check for reference counts first */
16508 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
16509 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16510 +
16511 +       /* context must not be hashed */
16512 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16513 +
16514 +       /* context shutdown is mandatory */
16515 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
16516 +
16517 +       /* spaces check */
16518 +       for (index = 0; index < VX_SPACES; index++) {
16519 +               struct _vx_space *space = &vxi->space[index];
16520 +
16521 +               BUG_ON(space->vx_nsproxy);
16522 +               BUG_ON(space->vx_fs);
16523 +               // BUG_ON(space->vx_real_cred);
16524 +               // BUG_ON(space->vx_cred);
16525 +       }
16526 +
16527 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16528 +       hlist_del(&vxi->vx_hlist);
16529 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16530 +
16531 +       __dealloc_vx_info(vxi);
16532 +}
16533 +
16534 +
16535 +/*     hash table for vx_info hash */
16536 +
16537 +#define VX_HASH_SIZE   13
16538 +
16539 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
16540 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
16541 +
16542 +static DEFINE_SPINLOCK(vx_info_hash_lock);
16543 +
16544 +
16545 +static inline unsigned int __hashval(xid_t xid)
16546 +{
16547 +       return (xid % VX_HASH_SIZE);
16548 +}
16549 +
16550 +
16551 +
16552 +/*     __hash_vx_info()
16553 +
16554 +       * add the vxi to the global hash table
16555 +       * requires the hash_lock to be held                     */
16556 +
16557 +static inline void __hash_vx_info(struct vx_info *vxi)
16558 +{
16559 +       struct hlist_head *head;
16560 +
16561 +       vxd_assert_lock(&vx_info_hash_lock);
16562 +       vxdprintk(VXD_CBIT(xid, 4),
16563 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
16564 +       vxh_hash_vx_info(vxi);
16565 +
16566 +       /* context must not be hashed */
16567 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16568 +
16569 +       vxi->vx_state |= VXS_HASHED;
16570 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
16571 +       hlist_add_head(&vxi->vx_hlist, head);
16572 +       atomic_inc(&vx_global_cactive);
16573 +}
16574 +
16575 +/*     __unhash_vx_info()
16576 +
16577 +       * remove the vxi from the global hash table
16578 +       * requires the hash_lock to be held                     */
16579 +
16580 +static inline void __unhash_vx_info(struct vx_info *vxi)
16581 +{
16582 +       unsigned long flags;
16583 +
16584 +       vxd_assert_lock(&vx_info_hash_lock);
16585 +       vxdprintk(VXD_CBIT(xid, 4),
16586 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
16587 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
16588 +       vxh_unhash_vx_info(vxi);
16589 +
16590 +       /* context must be hashed */
16591 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
16592 +       /* but without tasks */
16593 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16594 +
16595 +       vxi->vx_state &= ~VXS_HASHED;
16596 +       hlist_del_init(&vxi->vx_hlist);
16597 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16598 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
16599 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16600 +       atomic_dec(&vx_global_cactive);
16601 +}
16602 +
16603 +
16604 +/*     __lookup_vx_info()
16605 +
16606 +       * requires the hash_lock to be held
16607 +       * doesn't increment the vx_refcnt                       */
16608 +
16609 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
16610 +{
16611 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
16612 +       struct hlist_node *pos;
16613 +       struct vx_info *vxi;
16614 +
16615 +       vxd_assert_lock(&vx_info_hash_lock);
16616 +       hlist_for_each(pos, head) {
16617 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16618 +
16619 +               if (vxi->vx_id == xid)
16620 +                       goto found;
16621 +       }
16622 +       vxi = NULL;
16623 +found:
16624 +       vxdprintk(VXD_CBIT(xid, 0),
16625 +               "__lookup_vx_info(#%u): %p[#%u]",
16626 +               xid, vxi, vxi ? vxi->vx_id : 0);
16627 +       vxh_lookup_vx_info(vxi, xid);
16628 +       return vxi;
16629 +}
16630 +
16631 +
16632 +/*     __create_vx_info()
16633 +
16634 +       * create the requested context
16635 +       * get(), claim() and hash it                            */
16636 +
16637 +static struct vx_info *__create_vx_info(int id)
16638 +{
16639 +       struct vx_info *new, *vxi = NULL;
16640 +
16641 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
16642 +
16643 +       if (!(new = __alloc_vx_info(id)))
16644 +               return ERR_PTR(-ENOMEM);
16645 +
16646 +       /* required to make dynamic xids unique */
16647 +       spin_lock(&vx_info_hash_lock);
16648 +
16649 +       /* static context requested */
16650 +       if ((vxi = __lookup_vx_info(id))) {
16651 +               vxdprintk(VXD_CBIT(xid, 0),
16652 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
16653 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16654 +                       vxi = ERR_PTR(-EBUSY);
16655 +               else
16656 +                       vxi = ERR_PTR(-EEXIST);
16657 +               goto out_unlock;
16658 +       }
16659 +       /* new context */
16660 +       vxdprintk(VXD_CBIT(xid, 0),
16661 +               "create_vx_info(%d) = %p (new)", id, new);
16662 +       claim_vx_info(new, NULL);
16663 +       __hash_vx_info(get_vx_info(new));
16664 +       vxi = new, new = NULL;
16665 +
16666 +out_unlock:
16667 +       spin_unlock(&vx_info_hash_lock);
16668 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
16669 +       if (new)
16670 +               __dealloc_vx_info(new);
16671 +       return vxi;
16672 +}
16673 +
16674 +
16675 +/*     exported stuff                                          */
16676 +
16677 +
16678 +void unhash_vx_info(struct vx_info *vxi)
16679 +{
16680 +       spin_lock(&vx_info_hash_lock);
16681 +       __unhash_vx_info(vxi);
16682 +       spin_unlock(&vx_info_hash_lock);
16683 +       __shutdown_vx_info(vxi);
16684 +       __wakeup_vx_info(vxi);
16685 +}
16686 +
16687 +
16688 +/*     lookup_vx_info()
16689 +
16690 +       * search for a vx_info and get() it
16691 +       * negative id means current                             */
16692 +
16693 +struct vx_info *lookup_vx_info(int id)
16694 +{
16695 +       struct vx_info *vxi = NULL;
16696 +
16697 +       if (id < 0) {
16698 +               vxi = get_vx_info(current_vx_info());
16699 +       } else if (id > 1) {
16700 +               spin_lock(&vx_info_hash_lock);
16701 +               vxi = get_vx_info(__lookup_vx_info(id));
16702 +               spin_unlock(&vx_info_hash_lock);
16703 +       }
16704 +       return vxi;
16705 +}
16706 +
16707 +/*     xid_is_hashed()
16708 +
16709 +       * verify that xid is still hashed                       */
16710 +
16711 +int xid_is_hashed(xid_t xid)
16712 +{
16713 +       int hashed;
16714 +
16715 +       spin_lock(&vx_info_hash_lock);
16716 +       hashed = (__lookup_vx_info(xid) != NULL);
16717 +       spin_unlock(&vx_info_hash_lock);
16718 +       return hashed;
16719 +}
16720 +
16721 +#ifdef CONFIG_PROC_FS
16722 +
16723 +/*     get_xid_list()
16724 +
16725 +       * get a subset of hashed xids for proc
16726 +       * assumes size is at least one                          */
16727 +
16728 +int get_xid_list(int index, unsigned int *xids, int size)
16729 +{
16730 +       int hindex, nr_xids = 0;
16731 +
16732 +       /* only show current and children */
16733 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
16734 +               if (index > 0)
16735 +                       return 0;
16736 +               xids[nr_xids] = vx_current_xid();
16737 +               return 1;
16738 +       }
16739 +
16740 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
16741 +               struct hlist_head *head = &vx_info_hash[hindex];
16742 +               struct hlist_node *pos;
16743 +
16744 +               spin_lock(&vx_info_hash_lock);
16745 +               hlist_for_each(pos, head) {
16746 +                       struct vx_info *vxi;
16747 +
16748 +                       if (--index > 0)
16749 +                               continue;
16750 +
16751 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16752 +                       xids[nr_xids] = vxi->vx_id;
16753 +                       if (++nr_xids >= size) {
16754 +                               spin_unlock(&vx_info_hash_lock);
16755 +                               goto out;
16756 +                       }
16757 +               }
16758 +               /* keep the lock time short */
16759 +               spin_unlock(&vx_info_hash_lock);
16760 +       }
16761 +out:
16762 +       return nr_xids;
16763 +}
16764 +#endif
16765 +
16766 +#ifdef CONFIG_VSERVER_DEBUG
16767 +
16768 +void   dump_vx_info_inactive(int level)
16769 +{
16770 +       struct hlist_node *entry, *next;
16771 +
16772 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
16773 +               struct vx_info *vxi =
16774 +                       list_entry(entry, struct vx_info, vx_hlist);
16775 +
16776 +               dump_vx_info(vxi, level);
16777 +       }
16778 +}
16779 +
16780 +#endif
16781 +
16782 +#if 0
16783 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16784 +{
16785 +       struct user_struct *new_user, *old_user;
16786 +
16787 +       if (!p || !vxi)
16788 +               BUG();
16789 +
16790 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16791 +               return -EACCES;
16792 +
16793 +       new_user = alloc_uid(vxi->vx_id, p->uid);
16794 +       if (!new_user)
16795 +               return -ENOMEM;
16796 +
16797 +       old_user = p->user;
16798 +       if (new_user != old_user) {
16799 +               atomic_inc(&new_user->processes);
16800 +               atomic_dec(&old_user->processes);
16801 +               p->user = new_user;
16802 +       }
16803 +       free_uid(old_user);
16804 +       return 0;
16805 +}
16806 +#endif
16807 +
16808 +#if 0
16809 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16810 +{
16811 +       // p->cap_effective &= vxi->vx_cap_bset;
16812 +       p->cap_effective =
16813 +               cap_intersect(p->cap_effective, vxi->cap_bset);
16814 +       // p->cap_inheritable &= vxi->vx_cap_bset;
16815 +       p->cap_inheritable =
16816 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
16817 +       // p->cap_permitted &= vxi->vx_cap_bset;
16818 +       p->cap_permitted =
16819 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
16820 +}
16821 +#endif
16822 +
16823 +
16824 +#include <linux/file.h>
16825 +#include <linux/fdtable.h>
16826 +
16827 +static int vx_openfd_task(struct task_struct *tsk)
16828 +{
16829 +       struct files_struct *files = tsk->files;
16830 +       struct fdtable *fdt;
16831 +       const unsigned long *bptr;
16832 +       int count, total;
16833 +
16834 +       /* no rcu_read_lock() because of spin_lock() */
16835 +       spin_lock(&files->file_lock);
16836 +       fdt = files_fdtable(files);
16837 +       bptr = fdt->open_fds->fds_bits;
16838 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
16839 +       for (total = 0; count > 0; count--) {
16840 +               if (*bptr)
16841 +                       total += hweight_long(*bptr);
16842 +               bptr++;
16843 +       }
16844 +       spin_unlock(&files->file_lock);
16845 +       return total;
16846 +}
16847 +
16848 +
16849 +/*     for *space compatibility */
16850 +
16851 +asmlinkage long sys_unshare(unsigned long);
16852 +
16853 +/*
16854 + *     migrate task to new context
16855 + *     gets vxi, puts old_vxi on change
16856 + *     optionally unshares namespaces (hack)
16857 + */
16858 +
16859 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
16860 +{
16861 +       struct vx_info *old_vxi;
16862 +       int ret = 0;
16863 +
16864 +       if (!p || !vxi)
16865 +               BUG();
16866 +
16867 +       vxdprintk(VXD_CBIT(xid, 5),
16868 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
16869 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
16870 +
16871 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
16872 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16873 +               return -EACCES;
16874 +
16875 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
16876 +               return -EFAULT;
16877 +
16878 +       old_vxi = task_get_vx_info(p);
16879 +       if (old_vxi == vxi)
16880 +               goto out;
16881 +
16882 +//     if (!(ret = vx_migrate_user(p, vxi))) {
16883 +       {
16884 +               int openfd;
16885 +
16886 +               task_lock(p);
16887 +               openfd = vx_openfd_task(p);
16888 +
16889 +               if (old_vxi) {
16890 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
16891 +                       atomic_dec(&old_vxi->cvirt.nr_running);
16892 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
16893 +                       /* FIXME: what about the struct files here? */
16894 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
16895 +                       /* account for the executable */
16896 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
16897 +               }
16898 +               atomic_inc(&vxi->cvirt.nr_threads);
16899 +               atomic_inc(&vxi->cvirt.nr_running);
16900 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
16901 +               /* FIXME: what about the struct files here? */
16902 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
16903 +               /* account for the executable */
16904 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
16905 +
16906 +               if (old_vxi) {
16907 +                       release_vx_info(old_vxi, p);
16908 +                       clr_vx_info(&p->vx_info);
16909 +               }
16910 +               claim_vx_info(vxi, p);
16911 +               set_vx_info(&p->vx_info, vxi);
16912 +               p->xid = vxi->vx_id;
16913 +
16914 +               vxdprintk(VXD_CBIT(xid, 5),
16915 +                       "moved task %p into vxi:%p[#%d]",
16916 +                       p, vxi, vxi->vx_id);
16917 +
16918 +               // vx_mask_cap_bset(vxi, p);
16919 +               task_unlock(p);
16920 +
16921 +               /* hack for *spaces to provide compatibility */
16922 +               if (unshare) {
16923 +                       struct nsproxy *old_nsp, *new_nsp;
16924 +
16925 +                       ret = unshare_nsproxy_namespaces(
16926 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
16927 +                               &new_nsp, NULL);
16928 +                       if (ret)
16929 +                               goto out;
16930 +
16931 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
16932 +                       vx_set_space(vxi,
16933 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
16934 +                       put_nsproxy(old_nsp);
16935 +               }
16936 +       }
16937 +out:
16938 +       put_vx_info(old_vxi);
16939 +       return ret;
16940 +}
16941 +
16942 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
16943 +{
16944 +       struct task_struct *old_reaper;
16945 +
16946 +       if (!vxi)
16947 +               return -EINVAL;
16948 +
16949 +       vxdprintk(VXD_CBIT(xid, 6),
16950 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
16951 +               vxi, vxi->vx_id, p, p->xid, p->pid);
16952 +
16953 +       old_reaper = vxi->vx_reaper;
16954 +       if (old_reaper == p)
16955 +               return 0;
16956 +
16957 +       /* set new child reaper */
16958 +       get_task_struct(p);
16959 +       vxi->vx_reaper = p;
16960 +       put_task_struct(old_reaper);
16961 +       return 0;
16962 +}
16963 +
16964 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
16965 +{
16966 +       if (!vxi)
16967 +               return -EINVAL;
16968 +
16969 +       vxdprintk(VXD_CBIT(xid, 6),
16970 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
16971 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16972 +
16973 +       vxi->vx_flags &= ~VXF_STATE_INIT;
16974 +       // vxi->vx_initpid = p->tgid;
16975 +       vxi->vx_initpid = p->pid;
16976 +       return 0;
16977 +}
16978 +
16979 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
16980 +{
16981 +       vxdprintk(VXD_CBIT(xid, 6),
16982 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
16983 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16984 +
16985 +       vxi->exit_code = code;
16986 +       vxi->vx_initpid = 0;
16987 +}
16988 +
16989 +
16990 +void vx_set_persistent(struct vx_info *vxi)
16991 +{
16992 +       vxdprintk(VXD_CBIT(xid, 6),
16993 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
16994 +
16995 +       get_vx_info(vxi);
16996 +       claim_vx_info(vxi, NULL);
16997 +}
16998 +
16999 +void vx_clear_persistent(struct vx_info *vxi)
17000 +{
17001 +       vxdprintk(VXD_CBIT(xid, 6),
17002 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
17003 +
17004 +       release_vx_info(vxi, NULL);
17005 +       put_vx_info(vxi);
17006 +}
17007 +
17008 +void vx_update_persistent(struct vx_info *vxi)
17009 +{
17010 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
17011 +               vx_set_persistent(vxi);
17012 +       else
17013 +               vx_clear_persistent(vxi);
17014 +}
17015 +
17016 +
17017 +/*     task must be current or locked          */
17018 +
17019 +void   exit_vx_info(struct task_struct *p, int code)
17020 +{
17021 +       struct vx_info *vxi = p->vx_info;
17022 +
17023 +       if (vxi) {
17024 +               atomic_dec(&vxi->cvirt.nr_threads);
17025 +               vx_nproc_dec(p);
17026 +
17027 +               vxi->exit_code = code;
17028 +               release_vx_info(vxi, p);
17029 +       }
17030 +}
17031 +
17032 +void   exit_vx_info_early(struct task_struct *p, int code)
17033 +{
17034 +       struct vx_info *vxi = p->vx_info;
17035 +
17036 +       if (vxi) {
17037 +               if (vxi->vx_initpid == p->pid)
17038 +                       vx_exit_init(vxi, p, code);
17039 +               if (vxi->vx_reaper == p)
17040 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
17041 +       }
17042 +}
17043 +
17044 +
17045 +/* vserver syscall commands below here */
17046 +
17047 +/* taks xid and vx_info functions */
17048 +
17049 +#include <asm/uaccess.h>
17050 +
17051 +
17052 +int vc_task_xid(uint32_t id)
17053 +{
17054 +       xid_t xid;
17055 +
17056 +       if (id) {
17057 +               struct task_struct *tsk;
17058 +
17059 +               rcu_read_lock();
17060 +               tsk = find_task_by_real_pid(id);
17061 +               xid = (tsk) ? tsk->xid : -ESRCH;
17062 +               rcu_read_unlock();
17063 +       } else
17064 +               xid = vx_current_xid();
17065 +       return xid;
17066 +}
17067 +
17068 +
17069 +int vc_vx_info(struct vx_info *vxi, void __user *data)
17070 +{
17071 +       struct vcmd_vx_info_v0 vc_data;
17072 +
17073 +       vc_data.xid = vxi->vx_id;
17074 +       vc_data.initpid = vxi->vx_initpid;
17075 +
17076 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17077 +               return -EFAULT;
17078 +       return 0;
17079 +}
17080 +
17081 +
17082 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
17083 +{
17084 +       struct vcmd_ctx_stat_v0 vc_data;
17085 +
17086 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
17087 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
17088 +
17089 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17090 +               return -EFAULT;
17091 +       return 0;
17092 +}
17093 +
17094 +
17095 +/* context functions */
17096 +
17097 +int vc_ctx_create(uint32_t xid, void __user *data)
17098 +{
17099 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
17100 +       struct vx_info *new_vxi;
17101 +       int ret;
17102 +
17103 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
17104 +               return -EFAULT;
17105 +
17106 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
17107 +               return -EINVAL;
17108 +
17109 +       new_vxi = __create_vx_info(xid);
17110 +       if (IS_ERR(new_vxi))
17111 +               return PTR_ERR(new_vxi);
17112 +
17113 +       /* initial flags */
17114 +       new_vxi->vx_flags = vc_data.flagword;
17115 +
17116 +       ret = -ENOEXEC;
17117 +       if (vs_state_change(new_vxi, VSC_STARTUP))
17118 +               goto out;
17119 +
17120 +       ret = vx_migrate_task(current, new_vxi, (!data));
17121 +       if (ret)
17122 +               goto out;
17123 +
17124 +       /* return context id on success */
17125 +       ret = new_vxi->vx_id;
17126 +
17127 +       /* get a reference for persistent contexts */
17128 +       if ((vc_data.flagword & VXF_PERSISTENT))
17129 +               vx_set_persistent(new_vxi);
17130 +out:
17131 +       release_vx_info(new_vxi, NULL);
17132 +       put_vx_info(new_vxi);
17133 +       return ret;
17134 +}
17135 +
17136 +
17137 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
17138 +{
17139 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
17140 +       int ret;
17141 +
17142 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
17143 +               return -EFAULT;
17144 +
17145 +       ret = vx_migrate_task(current, vxi, 0);
17146 +       if (ret)
17147 +               return ret;
17148 +       if (vc_data.flagword & VXM_SET_INIT)
17149 +               ret = vx_set_init(vxi, current);
17150 +       if (ret)
17151 +               return ret;
17152 +       if (vc_data.flagword & VXM_SET_REAPER)
17153 +               ret = vx_set_reaper(vxi, current);
17154 +       return ret;
17155 +}
17156 +
17157 +
17158 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
17159 +{
17160 +       struct vcmd_ctx_flags_v0 vc_data;
17161 +
17162 +       vc_data.flagword = vxi->vx_flags;
17163 +
17164 +       /* special STATE flag handling */
17165 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
17166 +
17167 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17168 +               return -EFAULT;
17169 +       return 0;
17170 +}
17171 +
17172 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
17173 +{
17174 +       struct vcmd_ctx_flags_v0 vc_data;
17175 +       uint64_t mask, trigger;
17176 +
17177 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17178 +               return -EFAULT;
17179 +
17180 +       /* special STATE flag handling */
17181 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
17182 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
17183 +
17184 +       if (vxi == current_vx_info()) {
17185 +               /* if (trigger & VXF_STATE_SETUP)
17186 +                       vx_mask_cap_bset(vxi, current); */
17187 +               if (trigger & VXF_STATE_INIT) {
17188 +                       int ret;
17189 +
17190 +                       ret = vx_set_init(vxi, current);
17191 +                       if (ret)
17192 +                               return ret;
17193 +                       ret = vx_set_reaper(vxi, current);
17194 +                       if (ret)
17195 +                               return ret;
17196 +               }
17197 +       }
17198 +
17199 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
17200 +               vc_data.flagword, mask);
17201 +       if (trigger & VXF_PERSISTENT)
17202 +               vx_update_persistent(vxi);
17203 +
17204 +       return 0;
17205 +}
17206 +
17207 +
17208 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
17209 +{
17210 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
17211 +
17212 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
17213 +       return v;
17214 +}
17215 +
17216 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
17217 +{
17218 +       kernel_cap_t c = __cap_empty_set;
17219 +
17220 +       c.cap[0] = v & 0xFFFFFFFF;
17221 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
17222 +
17223 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
17224 +       return c;
17225 +}
17226 +
17227 +
17228 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
17229 +{
17230 +       if (bcaps)
17231 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
17232 +       if (ccaps)
17233 +               *ccaps = vxi->vx_ccaps;
17234 +
17235 +       return 0;
17236 +}
17237 +
17238 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
17239 +{
17240 +       struct vcmd_ctx_caps_v1 vc_data;
17241 +       int ret;
17242 +
17243 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
17244 +       if (ret)
17245 +               return ret;
17246 +       vc_data.cmask = ~0ULL;
17247 +
17248 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17249 +               return -EFAULT;
17250 +       return 0;
17251 +}
17252 +
17253 +static int do_set_caps(struct vx_info *vxi,
17254 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
17255 +{
17256 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
17257 +
17258 +#if 0
17259 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
17260 +               bcaps, bmask, ccaps, cmask);
17261 +#endif
17262 +       vxi->vx_bcaps = cap_t_from_caps(
17263 +               vs_mask_flags(bcold, bcaps, bmask));
17264 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
17265 +
17266 +       return 0;
17267 +}
17268 +
17269 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
17270 +{
17271 +       struct vcmd_ctx_caps_v1 vc_data;
17272 +
17273 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17274 +               return -EFAULT;
17275 +
17276 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
17277 +}
17278 +
17279 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
17280 +{
17281 +       struct vcmd_bcaps vc_data;
17282 +       int ret;
17283 +
17284 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
17285 +       if (ret)
17286 +               return ret;
17287 +       vc_data.bmask = ~0ULL;
17288 +
17289 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17290 +               return -EFAULT;
17291 +       return 0;
17292 +}
17293 +
17294 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
17295 +{
17296 +       struct vcmd_bcaps vc_data;
17297 +
17298 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17299 +               return -EFAULT;
17300 +
17301 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
17302 +}
17303 +
17304 +
17305 +int vc_get_umask(struct vx_info *vxi, void __user *data)
17306 +{
17307 +       struct vcmd_umask vc_data;
17308 +
17309 +       vc_data.umask = vxi->vx_umask;
17310 +       vc_data.mask = ~0ULL;
17311 +
17312 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17313 +               return -EFAULT;
17314 +       return 0;
17315 +}
17316 +
17317 +int vc_set_umask(struct vx_info *vxi, void __user *data)
17318 +{
17319 +       struct vcmd_umask vc_data;
17320 +
17321 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17322 +               return -EFAULT;
17323 +
17324 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
17325 +               vc_data.umask, vc_data.mask);
17326 +       return 0;
17327 +}
17328 +
17329 +
17330 +int vc_get_badness(struct vx_info *vxi, void __user *data)
17331 +{
17332 +       struct vcmd_badness_v0 vc_data;
17333 +
17334 +       vc_data.bias = vxi->vx_badness_bias;
17335 +
17336 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17337 +               return -EFAULT;
17338 +       return 0;
17339 +}
17340 +
17341 +int vc_set_badness(struct vx_info *vxi, void __user *data)
17342 +{
17343 +       struct vcmd_badness_v0 vc_data;
17344 +
17345 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17346 +               return -EFAULT;
17347 +
17348 +       vxi->vx_badness_bias = vc_data.bias;
17349 +       return 0;
17350 +}
17351 +
17352 +#include <linux/module.h>
17353 +
17354 +EXPORT_SYMBOL_GPL(free_vx_info);
17355 +
17356 diff -NurpP --minimal linux-3.0-rc5/kernel/vserver/cvirt.c linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/cvirt.c
17357 --- linux-3.0-rc5/kernel/vserver/cvirt.c        1970-01-01 01:00:00.000000000 +0100
17358 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/cvirt.c   2011-06-13 14:57:26.000000000 +0200
17359 @@ -0,0 +1,303 @@
17360 +/*
17361 + *  linux/kernel/vserver/cvirt.c
17362 + *
17363 + *  Virtual Server: Context Virtualization
17364 + *
17365 + *  Copyright (C) 2004-2007  Herbert Pötzl
17366 + *
17367 + *  V0.01  broken out from limit.c
17368 + *  V0.02  added utsname stuff
17369 + *  V0.03  changed vcmds to vxi arg
17370 + *
17371 + */
17372 +
17373 +#include <linux/types.h>
17374 +#include <linux/utsname.h>
17375 +#include <linux/vs_cvirt.h>
17376 +#include <linux/vserver/switch.h>
17377 +#include <linux/vserver/cvirt_cmd.h>
17378 +
17379 +#include <asm/uaccess.h>
17380 +
17381 +
17382 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
17383 +{
17384 +       struct vx_info *vxi = current_vx_info();
17385 +
17386 +       set_normalized_timespec(uptime,
17387 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
17388 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
17389 +       if (!idle)
17390 +               return;
17391 +       set_normalized_timespec(idle,
17392 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
17393 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
17394 +       return;
17395 +}
17396 +
17397 +uint64_t vx_idle_jiffies(void)
17398 +{
17399 +       return init_task.utime + init_task.stime;
17400 +}
17401 +
17402 +
17403 +
17404 +static inline uint32_t __update_loadavg(uint32_t load,
17405 +       int wsize, int delta, int n)
17406 +{
17407 +       unsigned long long calc, prev;
17408 +
17409 +       /* just set it to n */
17410 +       if (unlikely(delta >= wsize))
17411 +               return (n << FSHIFT);
17412 +
17413 +       calc = delta * n;
17414 +       calc <<= FSHIFT;
17415 +       prev = (wsize - delta);
17416 +       prev *= load;
17417 +       calc += prev;
17418 +       do_div(calc, wsize);
17419 +       return calc;
17420 +}
17421 +
17422 +
17423 +void vx_update_load(struct vx_info *vxi)
17424 +{
17425 +       uint32_t now, last, delta;
17426 +       unsigned int nr_running, nr_uninterruptible;
17427 +       unsigned int total;
17428 +       unsigned long flags;
17429 +
17430 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
17431 +
17432 +       now = jiffies;
17433 +       last = vxi->cvirt.load_last;
17434 +       delta = now - last;
17435 +
17436 +       if (delta < 5*HZ)
17437 +               goto out;
17438 +
17439 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
17440 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
17441 +       total = nr_running + nr_uninterruptible;
17442 +
17443 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
17444 +               60*HZ, delta, total);
17445 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
17446 +               5*60*HZ, delta, total);
17447 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
17448 +               15*60*HZ, delta, total);
17449 +
17450 +       vxi->cvirt.load_last = now;
17451 +out:
17452 +       atomic_inc(&vxi->cvirt.load_updates);
17453 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
17454 +}
17455 +
17456 +
17457 +/*
17458 + * Commands to do_syslog:
17459 + *
17460 + *      0 -- Close the log.  Currently a NOP.
17461 + *      1 -- Open the log. Currently a NOP.
17462 + *      2 -- Read from the log.
17463 + *      3 -- Read all messages remaining in the ring buffer.
17464 + *      4 -- Read and clear all messages remaining in the ring buffer
17465 + *      5 -- Clear ring buffer.
17466 + *      6 -- Disable printk's to console
17467 + *      7 -- Enable printk's to console
17468 + *      8 -- Set level of messages printed to console
17469 + *      9 -- Return number of unread characters in the log buffer
17470 + *     10 -- Return size of the log buffer
17471 + */
17472 +int vx_do_syslog(int type, char __user *buf, int len)
17473 +{
17474 +       int error = 0;
17475 +       int do_clear = 0;
17476 +       struct vx_info *vxi = current_vx_info();
17477 +       struct _vx_syslog *log;
17478 +
17479 +       if (!vxi)
17480 +               return -EINVAL;
17481 +       log = &vxi->cvirt.syslog;
17482 +
17483 +       switch (type) {
17484 +       case 0:         /* Close log */
17485 +       case 1:         /* Open log */
17486 +               break;
17487 +       case 2:         /* Read from log */
17488 +               error = wait_event_interruptible(log->log_wait,
17489 +                       (log->log_start - log->log_end));
17490 +               if (error)
17491 +                       break;
17492 +               spin_lock_irq(&log->logbuf_lock);
17493 +               spin_unlock_irq(&log->logbuf_lock);
17494 +               break;
17495 +       case 4:         /* Read/clear last kernel messages */
17496 +               do_clear = 1;
17497 +               /* fall through */
17498 +       case 3:         /* Read last kernel messages */
17499 +               return 0;
17500 +
17501 +       case 5:         /* Clear ring buffer */
17502 +               return 0;
17503 +
17504 +       case 6:         /* Disable logging to console */
17505 +       case 7:         /* Enable logging to console */
17506 +       case 8:         /* Set level of messages printed to console */
17507 +               break;
17508 +
17509 +       case 9:         /* Number of chars in the log buffer */
17510 +               return 0;
17511 +       case 10:        /* Size of the log buffer */
17512 +               return 0;
17513 +       default:
17514 +               error = -EINVAL;
17515 +               break;
17516 +       }
17517 +       return error;
17518 +}
17519 +
17520 +
17521 +/* virtual host info names */
17522 +
17523 +static char *vx_vhi_name(struct vx_info *vxi, int id)
17524 +{
17525 +       struct nsproxy *nsproxy;
17526 +       struct uts_namespace *uts;
17527 +
17528 +       if (id == VHIN_CONTEXT)
17529 +               return vxi->vx_name;
17530 +
17531 +       nsproxy = vxi->space[0].vx_nsproxy;
17532 +       if (!nsproxy)
17533 +               return NULL;
17534 +
17535 +       uts = nsproxy->uts_ns;
17536 +       if (!uts)
17537 +               return NULL;
17538 +
17539 +       switch (id) {
17540 +       case VHIN_SYSNAME:
17541 +               return uts->name.sysname;
17542 +       case VHIN_NODENAME:
17543 +               return uts->name.nodename;
17544 +       case VHIN_RELEASE:
17545 +               return uts->name.release;
17546 +       case VHIN_VERSION:
17547 +               return uts->name.version;
17548 +       case VHIN_MACHINE:
17549 +               return uts->name.machine;
17550 +       case VHIN_DOMAINNAME:
17551 +               return uts->name.domainname;
17552 +       default:
17553 +               return NULL;
17554 +       }
17555 +       return NULL;
17556 +}
17557 +
17558 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
17559 +{
17560 +       struct vcmd_vhi_name_v0 vc_data;
17561 +       char *name;
17562 +
17563 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17564 +               return -EFAULT;
17565 +
17566 +       name = vx_vhi_name(vxi, vc_data.field);
17567 +       if (!name)
17568 +               return -EINVAL;
17569 +
17570 +       memcpy(name, vc_data.name, 65);
17571 +       return 0;
17572 +}
17573 +
17574 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
17575 +{
17576 +       struct vcmd_vhi_name_v0 vc_data;
17577 +       char *name;
17578 +
17579 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17580 +               return -EFAULT;
17581 +
17582 +       name = vx_vhi_name(vxi, vc_data.field);
17583 +       if (!name)
17584 +               return -EINVAL;
17585 +
17586 +       memcpy(vc_data.name, name, 65);
17587 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17588 +               return -EFAULT;
17589 +       return 0;
17590 +}
17591 +
17592 +
17593 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
17594 +{
17595 +       struct vcmd_virt_stat_v0 vc_data;
17596 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
17597 +       struct timespec uptime;
17598 +
17599 +       do_posix_clock_monotonic_gettime(&uptime);
17600 +       set_normalized_timespec(&uptime,
17601 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
17602 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
17603 +
17604 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
17605 +       vc_data.uptime = timespec_to_ns(&uptime);
17606 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
17607 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
17608 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
17609 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
17610 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
17611 +       vc_data.load[0] = cvirt->load[0];
17612 +       vc_data.load[1] = cvirt->load[1];
17613 +       vc_data.load[2] = cvirt->load[2];
17614 +
17615 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17616 +               return -EFAULT;
17617 +       return 0;
17618 +}
17619 +
17620 +
17621 +#ifdef CONFIG_VSERVER_VTIME
17622 +
17623 +/* virtualized time base */
17624 +
17625 +void vx_adjust_timespec(struct timespec *ts)
17626 +{
17627 +       struct vx_info *vxi;
17628 +
17629 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17630 +               return;
17631 +
17632 +       vxi = current_vx_info();
17633 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
17634 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
17635 +
17636 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
17637 +               ts->tv_sec++;
17638 +               ts->tv_nsec -= NSEC_PER_SEC;
17639 +       } else if (ts->tv_nsec < 0) {
17640 +               ts->tv_sec--;
17641 +               ts->tv_nsec += NSEC_PER_SEC;
17642 +       }
17643 +}
17644 +
17645 +int vx_settimeofday(const struct timespec *ts)
17646 +{
17647 +       struct timespec ats, delta;
17648 +       struct vx_info *vxi;
17649 +
17650 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17651 +               return do_settimeofday(ts);
17652 +
17653 +       getnstimeofday(&ats);
17654 +       delta = timespec_sub(*ts, ats);
17655 +
17656 +       vxi = current_vx_info();
17657 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
17658 +       return 0;
17659 +}
17660 +
17661 +#endif
17662 +
17663 diff -NurpP --minimal linux-3.0-rc5/kernel/vserver/cvirt_init.h linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/cvirt_init.h
17664 --- linux-3.0-rc5/kernel/vserver/cvirt_init.h   1970-01-01 01:00:00.000000000 +0100
17665 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/cvirt_init.h      2011-06-10 22:11:24.000000000 +0200
17666 @@ -0,0 +1,70 @@
17667 +
17668 +
17669 +extern uint64_t vx_idle_jiffies(void);
17670 +
17671 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
17672 +{
17673 +       uint64_t idle_jiffies = vx_idle_jiffies();
17674 +       uint64_t nsuptime;
17675 +
17676 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
17677 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
17678 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
17679 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
17680 +       cvirt->bias_ts.tv_sec = 0;
17681 +       cvirt->bias_ts.tv_nsec = 0;
17682 +
17683 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
17684 +       atomic_set(&cvirt->nr_threads, 0);
17685 +       atomic_set(&cvirt->nr_running, 0);
17686 +       atomic_set(&cvirt->nr_uninterruptible, 0);
17687 +       atomic_set(&cvirt->nr_onhold, 0);
17688 +
17689 +       spin_lock_init(&cvirt->load_lock);
17690 +       cvirt->load_last = jiffies;
17691 +       atomic_set(&cvirt->load_updates, 0);
17692 +       cvirt->load[0] = 0;
17693 +       cvirt->load[1] = 0;
17694 +       cvirt->load[2] = 0;
17695 +       atomic_set(&cvirt->total_forks, 0);
17696 +
17697 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
17698 +       init_waitqueue_head(&cvirt->syslog.log_wait);
17699 +       cvirt->syslog.log_start = 0;
17700 +       cvirt->syslog.log_end = 0;
17701 +       cvirt->syslog.con_start = 0;
17702 +       cvirt->syslog.logged_chars = 0;
17703 +}
17704 +
17705 +static inline
17706 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17707 +{
17708 +       // cvirt_pc->cpustat = { 0 };
17709 +}
17710 +
17711 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
17712 +{
17713 +#ifdef CONFIG_VSERVER_WARN
17714 +       int value;
17715 +#endif
17716 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
17717 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
17718 +               cvirt, value);
17719 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
17720 +               "!!! cvirt: %p[nr_running] = %d on exit.",
17721 +               cvirt, value);
17722 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
17723 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
17724 +               cvirt, value);
17725 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
17726 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
17727 +               cvirt, value);
17728 +       return;
17729 +}
17730 +
17731 +static inline
17732 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17733 +{
17734 +       return;
17735 +}
17736 +
17737 diff -NurpP --minimal linux-3.0-rc5/kernel/vserver/cvirt_proc.h linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/cvirt_proc.h
17738 --- linux-3.0-rc5/kernel/vserver/cvirt_proc.h   1970-01-01 01:00:00.000000000 +0100
17739 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/cvirt_proc.h      2011-06-10 22:11:24.000000000 +0200
17740 @@ -0,0 +1,135 @@
17741 +#ifndef _VX_CVIRT_PROC_H
17742 +#define _VX_CVIRT_PROC_H
17743 +
17744 +#include <linux/nsproxy.h>
17745 +#include <linux/mnt_namespace.h>
17746 +#include <linux/ipc_namespace.h>
17747 +#include <linux/utsname.h>
17748 +#include <linux/ipc.h>
17749 +
17750 +
17751 +static inline
17752 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17753 +{
17754 +       struct mnt_namespace *ns;
17755 +       struct uts_namespace *uts;
17756 +       struct ipc_namespace *ipc;
17757 +       struct path path;
17758 +       char *pstr, *root;
17759 +       int length = 0;
17760 +
17761 +       if (!nsproxy)
17762 +               goto out;
17763 +
17764 +       length += sprintf(buffer + length,
17765 +               "NSProxy:\t%p [%p,%p,%p]\n",
17766 +               nsproxy, nsproxy->mnt_ns,
17767 +               nsproxy->uts_ns, nsproxy->ipc_ns);
17768 +
17769 +       ns = nsproxy->mnt_ns;
17770 +       if (!ns)
17771 +               goto skip_ns;
17772 +
17773 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
17774 +       if (!pstr)
17775 +               goto skip_ns;
17776 +
17777 +       path.mnt = ns->root;
17778 +       path.dentry = ns->root->mnt_root;
17779 +       root = d_path(&path, pstr, PATH_MAX - 2);
17780 +       length += sprintf(buffer + length,
17781 +               "Namespace:\t%p [#%u]\n"
17782 +               "RootPath:\t%s\n",
17783 +               ns, atomic_read(&ns->count),
17784 +               root);
17785 +       kfree(pstr);
17786 +skip_ns:
17787 +
17788 +       uts = nsproxy->uts_ns;
17789 +       if (!uts)
17790 +               goto skip_uts;
17791 +
17792 +       length += sprintf(buffer + length,
17793 +               "SysName:\t%.*s\n"
17794 +               "NodeName:\t%.*s\n"
17795 +               "Release:\t%.*s\n"
17796 +               "Version:\t%.*s\n"
17797 +               "Machine:\t%.*s\n"
17798 +               "DomainName:\t%.*s\n",
17799 +               __NEW_UTS_LEN, uts->name.sysname,
17800 +               __NEW_UTS_LEN, uts->name.nodename,
17801 +               __NEW_UTS_LEN, uts->name.release,
17802 +               __NEW_UTS_LEN, uts->name.version,
17803 +               __NEW_UTS_LEN, uts->name.machine,
17804 +               __NEW_UTS_LEN, uts->name.domainname);
17805 +skip_uts:
17806 +
17807 +       ipc = nsproxy->ipc_ns;
17808 +       if (!ipc)
17809 +               goto skip_ipc;
17810 +
17811 +       length += sprintf(buffer + length,
17812 +               "SEMS:\t\t%d %d %d %d  %d\n"
17813 +               "MSG:\t\t%d %d %d\n"
17814 +               "SHM:\t\t%lu %lu  %d %d\n",
17815 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
17816 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
17817 +               ipc->used_sems,
17818 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17819 +               (unsigned long)ipc->shm_ctlmax,
17820 +               (unsigned long)ipc->shm_ctlall,
17821 +               ipc->shm_ctlmni, ipc->shm_tot);
17822 +skip_ipc:
17823 +out:
17824 +       return length;
17825 +}
17826 +
17827 +
17828 +#include <linux/sched.h>
17829 +
17830 +#define LOAD_INT(x) ((x) >> FSHIFT)
17831 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
17832 +
17833 +static inline
17834 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
17835 +{
17836 +       int length = 0;
17837 +       int a, b, c;
17838 +
17839 +       length += sprintf(buffer + length,
17840 +               "BiasUptime:\t%lu.%02lu\n",
17841 +               (unsigned long)cvirt->bias_uptime.tv_sec,
17842 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
17843 +
17844 +       a = cvirt->load[0] + (FIXED_1 / 200);
17845 +       b = cvirt->load[1] + (FIXED_1 / 200);
17846 +       c = cvirt->load[2] + (FIXED_1 / 200);
17847 +       length += sprintf(buffer + length,
17848 +               "nr_threads:\t%d\n"
17849 +               "nr_running:\t%d\n"
17850 +               "nr_unintr:\t%d\n"
17851 +               "nr_onhold:\t%d\n"
17852 +               "load_updates:\t%d\n"
17853 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
17854 +               "total_forks:\t%d\n",
17855 +               atomic_read(&cvirt->nr_threads),
17856 +               atomic_read(&cvirt->nr_running),
17857 +               atomic_read(&cvirt->nr_uninterruptible),
17858 +               atomic_read(&cvirt->nr_onhold),
17859 +               atomic_read(&cvirt->load_updates),
17860 +               LOAD_INT(a), LOAD_FRAC(a),
17861 +               LOAD_INT(b), LOAD_FRAC(b),
17862 +               LOAD_INT(c), LOAD_FRAC(c),
17863 +               atomic_read(&cvirt->total_forks));
17864 +       return length;
17865 +}
17866 +
17867 +static inline
17868 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
17869 +       char *buffer, int cpu)
17870 +{
17871 +       int length = 0;
17872 +       return length;
17873 +}
17874 +
17875 +#endif /* _VX_CVIRT_PROC_H */
17876 diff -NurpP --minimal linux-3.0-rc5/kernel/vserver/debug.c linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/debug.c
17877 --- linux-3.0-rc5/kernel/vserver/debug.c        1970-01-01 01:00:00.000000000 +0100
17878 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/debug.c   2011-06-10 22:11:24.000000000 +0200
17879 @@ -0,0 +1,32 @@
17880 +/*
17881 + *  kernel/vserver/debug.c
17882 + *
17883 + *  Copyright (C) 2005-2007 Herbert Pötzl
17884 + *
17885 + *  V0.01  vx_info dump support
17886 + *
17887 + */
17888 +
17889 +#include <linux/module.h>
17890 +
17891 +#include <linux/vserver/context.h>
17892 +
17893 +
17894 +void   dump_vx_info(struct vx_info *vxi, int level)
17895 +{
17896 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
17897 +               atomic_read(&vxi->vx_usecnt),
17898 +               atomic_read(&vxi->vx_tasks),
17899 +               vxi->vx_state);
17900 +       if (level > 0) {
17901 +               __dump_vx_limit(&vxi->limit);
17902 +               __dump_vx_sched(&vxi->sched);
17903 +               __dump_vx_cvirt(&vxi->cvirt);
17904 +               __dump_vx_cacct(&vxi->cacct);
17905 +       }
17906 +       printk("---\n");
17907 +}
17908 +
17909 +
17910 +EXPORT_SYMBOL_GPL(dump_vx_info);
17911 +
17912 diff -NurpP --minimal linux-3.0-rc5/kernel/vserver/device.c linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/device.c
17913 --- linux-3.0-rc5/kernel/vserver/device.c       1970-01-01 01:00:00.000000000 +0100
17914 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/device.c  2011-06-10 23:20:56.000000000 +0200
17915 @@ -0,0 +1,443 @@
17916 +/*
17917 + *  linux/kernel/vserver/device.c
17918 + *
17919 + *  Linux-VServer: Device Support
17920 + *
17921 + *  Copyright (C) 2006  Herbert Pötzl
17922 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
17923 + *
17924 + *  V0.01  device mapping basics
17925 + *  V0.02  added defaults
17926 + *
17927 + */
17928 +
17929 +#include <linux/slab.h>
17930 +#include <linux/rcupdate.h>
17931 +#include <linux/fs.h>
17932 +#include <linux/namei.h>
17933 +#include <linux/hash.h>
17934 +
17935 +#include <asm/errno.h>
17936 +#include <asm/uaccess.h>
17937 +#include <linux/vserver/base.h>
17938 +#include <linux/vserver/debug.h>
17939 +#include <linux/vserver/context.h>
17940 +#include <linux/vserver/device.h>
17941 +#include <linux/vserver/device_cmd.h>
17942 +
17943 +
17944 +#define DMAP_HASH_BITS 4
17945 +
17946 +
17947 +struct vs_mapping {
17948 +       union {
17949 +               struct hlist_node hlist;
17950 +               struct list_head list;
17951 +       } u;
17952 +#define dm_hlist       u.hlist
17953 +#define dm_list                u.list
17954 +       xid_t xid;
17955 +       dev_t device;
17956 +       struct vx_dmap_target target;
17957 +};
17958 +
17959 +
17960 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
17961 +
17962 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
17963 +
17964 +static struct vx_dmap_target dmap_defaults[2] = {
17965 +       { .flags = DATTR_OPEN },
17966 +       { .flags = DATTR_OPEN },
17967 +};
17968 +
17969 +
17970 +struct kmem_cache *dmap_cachep __read_mostly;
17971 +
17972 +int __init dmap_cache_init(void)
17973 +{
17974 +       dmap_cachep = kmem_cache_create("dmap_cache",
17975 +               sizeof(struct vs_mapping), 0,
17976 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
17977 +       return 0;
17978 +}
17979 +
17980 +__initcall(dmap_cache_init);
17981 +
17982 +
17983 +static inline unsigned int __hashval(dev_t dev, int bits)
17984 +{
17985 +       return hash_long((unsigned long)dev, bits);
17986 +}
17987 +
17988 +
17989 +/*     __hash_mapping()
17990 + *     add the mapping to the hash table
17991 + */
17992 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
17993 +{
17994 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17995 +       struct hlist_head *head, *hash = dmap_main_hash;
17996 +       int device = vdm->device;
17997 +
17998 +       spin_lock(hash_lock);
17999 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
18000 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
18001 +
18002 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
18003 +       hlist_add_head(&vdm->dm_hlist, head);
18004 +       spin_unlock(hash_lock);
18005 +}
18006 +
18007 +
18008 +static inline int __mode_to_default(umode_t mode)
18009 +{
18010 +       switch (mode) {
18011 +       case S_IFBLK:
18012 +               return 0;
18013 +       case S_IFCHR:
18014 +               return 1;
18015 +       default:
18016 +               BUG();
18017 +       }
18018 +}
18019 +
18020 +
18021 +/*     __set_default()
18022 + *     set a default
18023 + */
18024 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
18025 +       struct vx_dmap_target *vdmt)
18026 +{
18027 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18028 +       spin_lock(hash_lock);
18029 +
18030 +       if (vxi)
18031 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
18032 +       else
18033 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
18034 +
18035 +
18036 +       spin_unlock(hash_lock);
18037 +
18038 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
18039 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
18040 +}
18041 +
18042 +
18043 +/*     __remove_default()
18044 + *     remove a default
18045 + */
18046 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
18047 +{
18048 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18049 +       spin_lock(hash_lock);
18050 +
18051 +       if (vxi)
18052 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
18053 +       else    /* remove == reset */
18054 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
18055 +
18056 +       spin_unlock(hash_lock);
18057 +       return 0;
18058 +}
18059 +
18060 +
18061 +/*     __find_mapping()
18062 + *     find a mapping in the hash table
18063 + *
18064 + *     caller must hold hash_lock
18065 + */
18066 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
18067 +       struct vs_mapping **local, struct vs_mapping **global)
18068 +{
18069 +       struct hlist_head *hash = dmap_main_hash;
18070 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
18071 +       struct hlist_node *pos;
18072 +       struct vs_mapping *vdm;
18073 +
18074 +       *local = NULL;
18075 +       if (global)
18076 +               *global = NULL;
18077 +
18078 +       hlist_for_each(pos, head) {
18079 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
18080 +
18081 +               if ((vdm->device == device) &&
18082 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
18083 +                       if (vdm->xid == xid) {
18084 +                               *local = vdm;
18085 +                               return 1;
18086 +                       } else if (global && vdm->xid == 0)
18087 +                               *global = vdm;
18088 +               }
18089 +       }
18090 +
18091 +       if (global && *global)
18092 +               return 0;
18093 +       else
18094 +               return -ENOENT;
18095 +}
18096 +
18097 +
18098 +/*     __lookup_mapping()
18099 + *     find a mapping and store the result in target and flags
18100 + */
18101 +static inline int __lookup_mapping(struct vx_info *vxi,
18102 +       dev_t device, dev_t *target, int *flags, umode_t mode)
18103 +{
18104 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18105 +       struct vs_mapping *vdm, *global;
18106 +       struct vx_dmap_target *vdmt;
18107 +       int ret = 0;
18108 +       xid_t xid = vxi->vx_id;
18109 +       int index;
18110 +
18111 +       spin_lock(hash_lock);
18112 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
18113 +               ret = 1;
18114 +               vdmt = &vdm->target;
18115 +               goto found;
18116 +       }
18117 +
18118 +       index = __mode_to_default(mode);
18119 +       if (vxi && vxi->dmap.targets[index].flags) {
18120 +               ret = 2;
18121 +               vdmt = &vxi->dmap.targets[index];
18122 +       } else if (global) {
18123 +               ret = 3;
18124 +               vdmt = &global->target;
18125 +               goto found;
18126 +       } else {
18127 +               ret = 4;
18128 +               vdmt = &dmap_defaults[index];
18129 +       }
18130 +
18131 +found:
18132 +       if (target && (vdmt->flags & DATTR_REMAP))
18133 +               *target = vdmt->target;
18134 +       else if (target)
18135 +               *target = device;
18136 +       if (flags)
18137 +               *flags = vdmt->flags;
18138 +
18139 +       spin_unlock(hash_lock);
18140 +
18141 +       return ret;
18142 +}
18143 +
18144 +
18145 +/*     __remove_mapping()
18146 + *     remove a mapping from the hash table
18147 + */
18148 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
18149 +       umode_t mode)
18150 +{
18151 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18152 +       struct vs_mapping *vdm = NULL;
18153 +       int ret = 0;
18154 +
18155 +       spin_lock(hash_lock);
18156 +
18157 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
18158 +               NULL);
18159 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
18160 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
18161 +       if (ret < 0)
18162 +               goto out;
18163 +       hlist_del(&vdm->dm_hlist);
18164 +
18165 +out:
18166 +       spin_unlock(hash_lock);
18167 +       if (vdm)
18168 +               kmem_cache_free(dmap_cachep, vdm);
18169 +       return ret;
18170 +}
18171 +
18172 +
18173 +
18174 +int vs_map_device(struct vx_info *vxi,
18175 +       dev_t device, dev_t *target, umode_t mode)
18176 +{
18177 +       int ret, flags = DATTR_MASK;
18178 +
18179 +       if (!vxi) {
18180 +               if (target)
18181 +                       *target = device;
18182 +               goto out;
18183 +       }
18184 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
18185 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
18186 +               device, target ? *target : 0, flags, mode, ret);
18187 +out:
18188 +       return (flags & DATTR_MASK);
18189 +}
18190 +
18191 +
18192 +
18193 +static int do_set_mapping(struct vx_info *vxi,
18194 +       dev_t device, dev_t target, int flags, umode_t mode)
18195 +{
18196 +       if (device) {
18197 +               struct vs_mapping *new;
18198 +
18199 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
18200 +               if (!new)
18201 +                       return -ENOMEM;
18202 +
18203 +               INIT_HLIST_NODE(&new->dm_hlist);
18204 +               new->device = device;
18205 +               new->target.target = target;
18206 +               new->target.flags = flags | mode;
18207 +               new->xid = (vxi ? vxi->vx_id : 0);
18208 +
18209 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
18210 +               __hash_mapping(vxi, new);
18211 +       } else {
18212 +               struct vx_dmap_target new = {
18213 +                       .target = target,
18214 +                       .flags = flags | mode,
18215 +               };
18216 +               __set_default(vxi, mode, &new);
18217 +       }
18218 +       return 0;
18219 +}
18220 +
18221 +
18222 +static int do_unset_mapping(struct vx_info *vxi,
18223 +       dev_t device, dev_t target, int flags, umode_t mode)
18224 +{
18225 +       int ret = -EINVAL;
18226 +
18227 +       if (device) {
18228 +               ret = __remove_mapping(vxi, device, mode);
18229 +               if (ret < 0)
18230 +                       goto out;
18231 +       } else {
18232 +               ret = __remove_default(vxi, mode);
18233 +               if (ret < 0)
18234 +                       goto out;
18235 +       }
18236 +
18237 +out:
18238 +       return ret;
18239 +}
18240 +
18241 +
18242 +static inline int __user_device(const char __user *name, dev_t *dev,
18243 +       umode_t *mode)
18244 +{
18245 +       struct nameidata nd;
18246 +       int ret;
18247 +
18248 +       if (!name) {
18249 +               *dev = 0;
18250 +               return 0;
18251 +       }
18252 +       ret = user_lpath(name, &nd.path);
18253 +       if (ret)
18254 +               return ret;
18255 +       if (nd.path.dentry->d_inode) {
18256 +               *dev = nd.path.dentry->d_inode->i_rdev;
18257 +               *mode = nd.path.dentry->d_inode->i_mode;
18258 +       }
18259 +       path_put(&nd.path);
18260 +       return 0;
18261 +}
18262 +
18263 +static inline int __mapping_mode(dev_t device, dev_t target,
18264 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
18265 +{
18266 +       if (device)
18267 +               *mode = device_mode & S_IFMT;
18268 +       else if (target)
18269 +               *mode = target_mode & S_IFMT;
18270 +       else
18271 +               return -EINVAL;
18272 +
18273 +       /* if both given, device and target mode have to match */
18274 +       if (device && target &&
18275 +               ((device_mode ^ target_mode) & S_IFMT))
18276 +               return -EINVAL;
18277 +       return 0;
18278 +}
18279 +
18280 +
18281 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
18282 +       const char __user *target_path, int flags, int set)
18283 +{
18284 +       dev_t device = ~0, target = ~0;
18285 +       umode_t device_mode = 0, target_mode = 0, mode;
18286 +       int ret;
18287 +
18288 +       ret = __user_device(device_path, &device, &device_mode);
18289 +       if (ret)
18290 +               return ret;
18291 +       ret = __user_device(target_path, &target, &target_mode);
18292 +       if (ret)
18293 +               return ret;
18294 +
18295 +       ret = __mapping_mode(device, target,
18296 +               device_mode, target_mode, &mode);
18297 +       if (ret)
18298 +               return ret;
18299 +
18300 +       if (set)
18301 +               return do_set_mapping(vxi, device, target,
18302 +                       flags, mode);
18303 +       else
18304 +               return do_unset_mapping(vxi, device, target,
18305 +                       flags, mode);
18306 +}
18307 +
18308 +
18309 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
18310 +{
18311 +       struct vcmd_set_mapping_v0 vc_data;
18312 +
18313 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18314 +               return -EFAULT;
18315 +
18316 +       return do_mapping(vxi, vc_data.device, vc_data.target,
18317 +               vc_data.flags, 1);
18318 +}
18319 +
18320 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
18321 +{
18322 +       struct vcmd_set_mapping_v0 vc_data;
18323 +
18324 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18325 +               return -EFAULT;
18326 +
18327 +       return do_mapping(vxi, vc_data.device, vc_data.target,
18328 +               vc_data.flags, 0);
18329 +}
18330 +
18331 +
18332 +#ifdef CONFIG_COMPAT
18333 +
18334 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
18335 +{
18336 +       struct vcmd_set_mapping_v0_x32 vc_data;
18337 +
18338 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18339 +               return -EFAULT;
18340 +
18341 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
18342 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
18343 +}
18344 +
18345 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
18346 +{
18347 +       struct vcmd_set_mapping_v0_x32 vc_data;
18348 +
18349 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18350 +               return -EFAULT;
18351 +
18352 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
18353 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
18354 +}
18355 +
18356 +#endif /* CONFIG_COMPAT */
18357 +
18358 +
18359 diff -NurpP --minimal linux-3.0-rc5/kernel/vserver/dlimit.c linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/dlimit.c
18360 --- linux-3.0-rc5/kernel/vserver/dlimit.c       1970-01-01 01:00:00.000000000 +0100
18361 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/dlimit.c  2011-06-10 23:20:56.000000000 +0200
18362 @@ -0,0 +1,531 @@
18363 +/*
18364 + *  linux/kernel/vserver/dlimit.c
18365 + *
18366 + *  Virtual Server: Context Disk Limits
18367 + *
18368 + *  Copyright (C) 2004-2009  Herbert Pötzl
18369 + *
18370 + *  V0.01  initial version
18371 + *  V0.02  compat32 splitup
18372 + *  V0.03  extended interface
18373 + *
18374 + */
18375 +
18376 +#include <linux/statfs.h>
18377 +#include <linux/sched.h>
18378 +#include <linux/namei.h>
18379 +#include <linux/vs_tag.h>
18380 +#include <linux/vs_dlimit.h>
18381 +#include <linux/vserver/dlimit_cmd.h>
18382 +#include <linux/slab.h>
18383 +// #include <linux/gfp.h>
18384 +
18385 +#include <asm/uaccess.h>
18386 +
18387 +/*     __alloc_dl_info()
18388 +
18389 +       * allocate an initialized dl_info struct
18390 +       * doesn't make it visible (hash)                        */
18391 +
18392 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
18393 +{
18394 +       struct dl_info *new = NULL;
18395 +
18396 +       vxdprintk(VXD_CBIT(dlim, 5),
18397 +               "alloc_dl_info(%p,%d)*", sb, tag);
18398 +
18399 +       /* would this benefit from a slab cache? */
18400 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
18401 +       if (!new)
18402 +               return 0;
18403 +
18404 +       memset(new, 0, sizeof(struct dl_info));
18405 +       new->dl_tag = tag;
18406 +       new->dl_sb = sb;
18407 +       // INIT_RCU_HEAD(&new->dl_rcu);
18408 +       INIT_HLIST_NODE(&new->dl_hlist);
18409 +       spin_lock_init(&new->dl_lock);
18410 +       atomic_set(&new->dl_refcnt, 0);
18411 +       atomic_set(&new->dl_usecnt, 0);
18412 +
18413 +       /* rest of init goes here */
18414 +
18415 +       vxdprintk(VXD_CBIT(dlim, 4),
18416 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
18417 +       return new;
18418 +}
18419 +
18420 +/*     __dealloc_dl_info()
18421 +
18422 +       * final disposal of dl_info                             */
18423 +
18424 +static void __dealloc_dl_info(struct dl_info *dli)
18425 +{
18426 +       vxdprintk(VXD_CBIT(dlim, 4),
18427 +               "dealloc_dl_info(%p)", dli);
18428 +
18429 +       dli->dl_hlist.next = LIST_POISON1;
18430 +       dli->dl_tag = -1;
18431 +       dli->dl_sb = 0;
18432 +
18433 +       BUG_ON(atomic_read(&dli->dl_usecnt));
18434 +       BUG_ON(atomic_read(&dli->dl_refcnt));
18435 +
18436 +       kfree(dli);
18437 +}
18438 +
18439 +
18440 +/*     hash table for dl_info hash */
18441 +
18442 +#define DL_HASH_SIZE   13
18443 +
18444 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
18445 +
18446 +static DEFINE_SPINLOCK(dl_info_hash_lock);
18447 +
18448 +
18449 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
18450 +{
18451 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
18452 +}
18453 +
18454 +
18455 +
18456 +/*     __hash_dl_info()
18457 +
18458 +       * add the dli to the global hash table
18459 +       * requires the hash_lock to be held                     */
18460 +
18461 +static inline void __hash_dl_info(struct dl_info *dli)
18462 +{
18463 +       struct hlist_head *head;
18464 +
18465 +       vxdprintk(VXD_CBIT(dlim, 6),
18466 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
18467 +       get_dl_info(dli);
18468 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
18469 +       hlist_add_head_rcu(&dli->dl_hlist, head);
18470 +}
18471 +
18472 +/*     __unhash_dl_info()
18473 +
18474 +       * remove the dli from the global hash table
18475 +       * requires the hash_lock to be held                     */
18476 +
18477 +static inline void __unhash_dl_info(struct dl_info *dli)
18478 +{
18479 +       vxdprintk(VXD_CBIT(dlim, 6),
18480 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
18481 +       hlist_del_rcu(&dli->dl_hlist);
18482 +       put_dl_info(dli);
18483 +}
18484 +
18485 +
18486 +/*     __lookup_dl_info()
18487 +
18488 +       * requires the rcu_read_lock()
18489 +       * doesn't increment the dl_refcnt                       */
18490 +
18491 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
18492 +{
18493 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
18494 +       struct hlist_node *pos;
18495 +       struct dl_info *dli;
18496 +
18497 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
18498 +
18499 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
18500 +                       return dli;
18501 +               }
18502 +       }
18503 +       return NULL;
18504 +}
18505 +
18506 +
18507 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
18508 +{
18509 +       struct dl_info *dli;
18510 +
18511 +       rcu_read_lock();
18512 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
18513 +       vxdprintk(VXD_CBIT(dlim, 7),
18514 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
18515 +       rcu_read_unlock();
18516 +       return dli;
18517 +}
18518 +
18519 +void rcu_free_dl_info(struct rcu_head *head)
18520 +{
18521 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
18522 +       int usecnt, refcnt;
18523 +
18524 +       BUG_ON(!dli || !head);
18525 +
18526 +       usecnt = atomic_read(&dli->dl_usecnt);
18527 +       BUG_ON(usecnt < 0);
18528 +
18529 +       refcnt = atomic_read(&dli->dl_refcnt);
18530 +       BUG_ON(refcnt < 0);
18531 +
18532 +       vxdprintk(VXD_CBIT(dlim, 3),
18533 +               "rcu_free_dl_info(%p)", dli);
18534 +       if (!usecnt)
18535 +               __dealloc_dl_info(dli);
18536 +       else
18537 +               printk("!!! rcu didn't free\n");
18538 +}
18539 +
18540 +
18541 +
18542 +
18543 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
18544 +       uint32_t flags, int add)
18545 +{
18546 +       struct path path;
18547 +       int ret;
18548 +
18549 +       ret = user_lpath(name, &path);
18550 +       if (!ret) {
18551 +               struct super_block *sb;
18552 +               struct dl_info *dli;
18553 +
18554 +               ret = -EINVAL;
18555 +               if (!path.dentry->d_inode)
18556 +                       goto out_release;
18557 +               if (!(sb = path.dentry->d_inode->i_sb))
18558 +                       goto out_release;
18559 +
18560 +               if (add) {
18561 +                       dli = __alloc_dl_info(sb, id);
18562 +                       spin_lock(&dl_info_hash_lock);
18563 +
18564 +                       ret = -EEXIST;
18565 +                       if (__lookup_dl_info(sb, id))
18566 +                               goto out_unlock;
18567 +                       __hash_dl_info(dli);
18568 +                       dli = NULL;
18569 +               } else {
18570 +                       spin_lock(&dl_info_hash_lock);
18571 +                       dli = __lookup_dl_info(sb, id);
18572 +
18573 +                       ret = -ESRCH;
18574 +                       if (!dli)
18575 +                               goto out_unlock;
18576 +                       __unhash_dl_info(dli);
18577 +               }
18578 +               ret = 0;
18579 +       out_unlock:
18580 +               spin_unlock(&dl_info_hash_lock);
18581 +               if (add && dli)
18582 +                       __dealloc_dl_info(dli);
18583 +       out_release:
18584 +               path_put(&path);
18585 +       }
18586 +       return ret;
18587 +}
18588 +
18589 +int vc_add_dlimit(uint32_t id, void __user *data)
18590 +{
18591 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18592 +
18593 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18594 +               return -EFAULT;
18595 +
18596 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
18597 +}
18598 +
18599 +int vc_rem_dlimit(uint32_t id, void __user *data)
18600 +{
18601 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18602 +
18603 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18604 +               return -EFAULT;
18605 +
18606 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
18607 +}
18608 +
18609 +#ifdef CONFIG_COMPAT
18610 +
18611 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
18612 +{
18613 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18614 +
18615 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18616 +               return -EFAULT;
18617 +
18618 +       return do_addrem_dlimit(id,
18619 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
18620 +}
18621 +
18622 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
18623 +{
18624 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18625 +
18626 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18627 +               return -EFAULT;
18628 +
18629 +       return do_addrem_dlimit(id,
18630 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
18631 +}
18632 +
18633 +#endif /* CONFIG_COMPAT */
18634 +
18635 +
18636 +static inline
18637 +int do_set_dlimit(uint32_t id, const char __user *name,
18638 +       uint32_t space_used, uint32_t space_total,
18639 +       uint32_t inodes_used, uint32_t inodes_total,
18640 +       uint32_t reserved, uint32_t flags)
18641 +{
18642 +       struct path path;
18643 +       int ret;
18644 +
18645 +       ret = user_lpath(name, &path);
18646 +       if (!ret) {
18647 +               struct super_block *sb;
18648 +               struct dl_info *dli;
18649 +
18650 +               ret = -EINVAL;
18651 +               if (!path.dentry->d_inode)
18652 +                       goto out_release;
18653 +               if (!(sb = path.dentry->d_inode->i_sb))
18654 +                       goto out_release;
18655 +
18656 +               /* sanity checks */
18657 +               if ((reserved != CDLIM_KEEP &&
18658 +                       reserved > 100) ||
18659 +                       (inodes_used != CDLIM_KEEP &&
18660 +                       inodes_used > inodes_total) ||
18661 +                       (space_used != CDLIM_KEEP &&
18662 +                       space_used > space_total))
18663 +                       goto out_release;
18664 +
18665 +               ret = -ESRCH;
18666 +               dli = locate_dl_info(sb, id);
18667 +               if (!dli)
18668 +                       goto out_release;
18669 +
18670 +               spin_lock(&dli->dl_lock);
18671 +
18672 +               if (inodes_used != CDLIM_KEEP)
18673 +                       dli->dl_inodes_used = inodes_used;
18674 +               if (inodes_total != CDLIM_KEEP)
18675 +                       dli->dl_inodes_total = inodes_total;
18676 +               if (space_used != CDLIM_KEEP)
18677 +                       dli->dl_space_used = dlimit_space_32to64(
18678 +                               space_used, flags, DLIMS_USED);
18679 +
18680 +               if (space_total == CDLIM_INFINITY)
18681 +                       dli->dl_space_total = DLIM_INFINITY;
18682 +               else if (space_total != CDLIM_KEEP)
18683 +                       dli->dl_space_total = dlimit_space_32to64(
18684 +                               space_total, flags, DLIMS_TOTAL);
18685 +
18686 +               if (reserved != CDLIM_KEEP)
18687 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
18688 +
18689 +               spin_unlock(&dli->dl_lock);
18690 +
18691 +               put_dl_info(dli);
18692 +               ret = 0;
18693 +
18694 +       out_release:
18695 +               path_put(&path);
18696 +       }
18697 +       return ret;
18698 +}
18699 +
18700 +int vc_set_dlimit(uint32_t id, void __user *data)
18701 +{
18702 +       struct vcmd_ctx_dlimit_v0 vc_data;
18703 +
18704 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18705 +               return -EFAULT;
18706 +
18707 +       return do_set_dlimit(id, vc_data.name,
18708 +               vc_data.space_used, vc_data.space_total,
18709 +               vc_data.inodes_used, vc_data.inodes_total,
18710 +               vc_data.reserved, vc_data.flags);
18711 +}
18712 +
18713 +#ifdef CONFIG_COMPAT
18714 +
18715 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
18716 +{
18717 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18718 +
18719 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18720 +               return -EFAULT;
18721 +
18722 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
18723 +               vc_data.space_used, vc_data.space_total,
18724 +               vc_data.inodes_used, vc_data.inodes_total,
18725 +               vc_data.reserved, vc_data.flags);
18726 +}
18727 +
18728 +#endif /* CONFIG_COMPAT */
18729 +
18730 +
18731 +static inline
18732 +int do_get_dlimit(uint32_t id, const char __user *name,
18733 +       uint32_t *space_used, uint32_t *space_total,
18734 +       uint32_t *inodes_used, uint32_t *inodes_total,
18735 +       uint32_t *reserved, uint32_t *flags)
18736 +{
18737 +       struct path path;
18738 +       int ret;
18739 +
18740 +       ret = user_lpath(name, &path);
18741 +       if (!ret) {
18742 +               struct super_block *sb;
18743 +               struct dl_info *dli;
18744 +
18745 +               ret = -EINVAL;
18746 +               if (!path.dentry->d_inode)
18747 +                       goto out_release;
18748 +               if (!(sb = path.dentry->d_inode->i_sb))
18749 +                       goto out_release;
18750 +
18751 +               ret = -ESRCH;
18752 +               dli = locate_dl_info(sb, id);
18753 +               if (!dli)
18754 +                       goto out_release;
18755 +
18756 +               spin_lock(&dli->dl_lock);
18757 +               *inodes_used = dli->dl_inodes_used;
18758 +               *inodes_total = dli->dl_inodes_total;
18759 +
18760 +               *space_used = dlimit_space_64to32(
18761 +                       dli->dl_space_used, flags, DLIMS_USED);
18762 +
18763 +               if (dli->dl_space_total == DLIM_INFINITY)
18764 +                       *space_total = CDLIM_INFINITY;
18765 +               else
18766 +                       *space_total = dlimit_space_64to32(
18767 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
18768 +
18769 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18770 +               spin_unlock(&dli->dl_lock);
18771 +
18772 +               put_dl_info(dli);
18773 +               ret = -EFAULT;
18774 +
18775 +               ret = 0;
18776 +       out_release:
18777 +               path_put(&path);
18778 +       }
18779 +       return ret;
18780 +}
18781 +
18782 +
18783 +int vc_get_dlimit(uint32_t id, void __user *data)
18784 +{
18785 +       struct vcmd_ctx_dlimit_v0 vc_data;
18786 +       int ret;
18787 +
18788 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18789 +               return -EFAULT;
18790 +
18791 +       ret = do_get_dlimit(id, vc_data.name,
18792 +               &vc_data.space_used, &vc_data.space_total,
18793 +               &vc_data.inodes_used, &vc_data.inodes_total,
18794 +               &vc_data.reserved, &vc_data.flags);
18795 +       if (ret)
18796 +               return ret;
18797 +
18798 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18799 +               return -EFAULT;
18800 +       return 0;
18801 +}
18802 +
18803 +#ifdef CONFIG_COMPAT
18804 +
18805 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18806 +{
18807 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18808 +       int ret;
18809 +
18810 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18811 +               return -EFAULT;
18812 +
18813 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18814 +               &vc_data.space_used, &vc_data.space_total,
18815 +               &vc_data.inodes_used, &vc_data.inodes_total,
18816 +               &vc_data.reserved, &vc_data.flags);
18817 +       if (ret)
18818 +               return ret;
18819 +
18820 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18821 +               return -EFAULT;
18822 +       return 0;
18823 +}
18824 +
18825 +#endif /* CONFIG_COMPAT */
18826 +
18827 +
18828 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
18829 +{
18830 +       struct dl_info *dli;
18831 +       __u64 blimit, bfree, bavail;
18832 +       __u32 ifree;
18833 +
18834 +       dli = locate_dl_info(sb, dx_current_tag());
18835 +       if (!dli)
18836 +               return;
18837 +
18838 +       spin_lock(&dli->dl_lock);
18839 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
18840 +               goto no_ilim;
18841 +
18842 +       /* reduce max inodes available to limit */
18843 +       if (buf->f_files > dli->dl_inodes_total)
18844 +               buf->f_files = dli->dl_inodes_total;
18845 +
18846 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
18847 +       /* reduce free inodes to min */
18848 +       if (ifree < buf->f_ffree)
18849 +               buf->f_ffree = ifree;
18850 +
18851 +no_ilim:
18852 +       if (dli->dl_space_total == DLIM_INFINITY)
18853 +               goto no_blim;
18854 +
18855 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
18856 +
18857 +       if (dli->dl_space_total < dli->dl_space_used)
18858 +               bfree = 0;
18859 +       else
18860 +               bfree = (dli->dl_space_total - dli->dl_space_used)
18861 +                       >> sb->s_blocksize_bits;
18862 +
18863 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
18864 +       if (bavail < dli->dl_space_used)
18865 +               bavail = 0;
18866 +       else
18867 +               bavail = (bavail - dli->dl_space_used)
18868 +                       >> sb->s_blocksize_bits;
18869 +
18870 +       /* reduce max space available to limit */
18871 +       if (buf->f_blocks > blimit)
18872 +               buf->f_blocks = blimit;
18873 +
18874 +       /* reduce free space to min */
18875 +       if (bfree < buf->f_bfree)
18876 +               buf->f_bfree = bfree;
18877 +
18878 +       /* reduce avail space to min */
18879 +       if (bavail < buf->f_bavail)
18880 +               buf->f_bavail = bavail;
18881 +
18882 +no_blim:
18883 +       spin_unlock(&dli->dl_lock);
18884 +       put_dl_info(dli);
18885 +
18886 +       return;
18887 +}
18888 +
18889 +#include <linux/module.h>
18890 +
18891 +EXPORT_SYMBOL_GPL(locate_dl_info);
18892 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
18893 +
18894 diff -NurpP --minimal linux-3.0-rc5/kernel/vserver/helper.c linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/helper.c
18895 --- linux-3.0-rc5/kernel/vserver/helper.c       1970-01-01 01:00:00.000000000 +0100
18896 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/helper.c  2011-06-10 22:11:24.000000000 +0200
18897 @@ -0,0 +1,223 @@
18898 +/*
18899 + *  linux/kernel/vserver/helper.c
18900 + *
18901 + *  Virtual Context Support
18902 + *
18903 + *  Copyright (C) 2004-2007  Herbert Pötzl
18904 + *
18905 + *  V0.01  basic helper
18906 + *
18907 + */
18908 +
18909 +#include <linux/kmod.h>
18910 +#include <linux/reboot.h>
18911 +#include <linux/vs_context.h>
18912 +#include <linux/vs_network.h>
18913 +#include <linux/vserver/signal.h>
18914 +
18915 +
18916 +char vshelper_path[255] = "/sbin/vshelper";
18917 +
18918 +
18919 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
18920 +{
18921 +       int ret;
18922 +
18923 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
18924 +               printk( KERN_WARNING
18925 +                       "%s: (%s %s) returned %s with %d\n",
18926 +                       name, argv[1], argv[2],
18927 +                       sync ? "sync" : "async", ret);
18928 +       }
18929 +       vxdprintk(VXD_CBIT(switch, 4),
18930 +               "%s: (%s %s) returned %s with %d",
18931 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
18932 +       return ret;
18933 +}
18934 +
18935 +/*
18936 + *      vshelper path is set via /proc/sys
18937 + *      invoked by vserver sys_reboot(), with
18938 + *      the following arguments
18939 + *
18940 + *      argv [0] = vshelper_path;
18941 + *      argv [1] = action: "restart", "halt", "poweroff", ...
18942 + *      argv [2] = context identifier
18943 + *
18944 + *      envp [*] = type-specific parameters
18945 + */
18946 +
18947 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
18948 +{
18949 +       char id_buf[8], cmd_buf[16];
18950 +       char uid_buf[16], pid_buf[16];
18951 +       int ret;
18952 +
18953 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18954 +       char *envp[] = {"HOME=/", "TERM=linux",
18955 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
18956 +                       uid_buf, pid_buf, cmd_buf, 0};
18957 +
18958 +       if (vx_info_state(vxi, VXS_HELPER))
18959 +               return -EAGAIN;
18960 +       vxi->vx_state |= VXS_HELPER;
18961 +
18962 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
18963 +
18964 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
18965 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current_uid());
18966 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
18967 +
18968 +       switch (cmd) {
18969 +       case LINUX_REBOOT_CMD_RESTART:
18970 +               argv[1] = "restart";
18971 +               break;
18972 +
18973 +       case LINUX_REBOOT_CMD_HALT:
18974 +               argv[1] = "halt";
18975 +               break;
18976 +
18977 +       case LINUX_REBOOT_CMD_POWER_OFF:
18978 +               argv[1] = "poweroff";
18979 +               break;
18980 +
18981 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
18982 +               argv[1] = "swsusp";
18983 +               break;
18984 +
18985 +       case LINUX_REBOOT_CMD_OOM:
18986 +               argv[1] = "oom";
18987 +               break;
18988 +
18989 +       default:
18990 +               vxi->vx_state &= ~VXS_HELPER;
18991 +               return 0;
18992 +       }
18993 +
18994 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
18995 +       vxi->vx_state &= ~VXS_HELPER;
18996 +       __wakeup_vx_info(vxi);
18997 +       return (ret) ? -EPERM : 0;
18998 +}
18999 +
19000 +
19001 +long vs_reboot(unsigned int cmd, void __user *arg)
19002 +{
19003 +       struct vx_info *vxi = current_vx_info();
19004 +       long ret = 0;
19005 +
19006 +       vxdprintk(VXD_CBIT(misc, 5),
19007 +               "vs_reboot(%p[#%d],%u)",
19008 +               vxi, vxi ? vxi->vx_id : 0, cmd);
19009 +
19010 +       ret = vs_reboot_helper(vxi, cmd, arg);
19011 +       if (ret)
19012 +               return ret;
19013 +
19014 +       vxi->reboot_cmd = cmd;
19015 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
19016 +               switch (cmd) {
19017 +               case LINUX_REBOOT_CMD_RESTART:
19018 +               case LINUX_REBOOT_CMD_HALT:
19019 +               case LINUX_REBOOT_CMD_POWER_OFF:
19020 +                       vx_info_kill(vxi, 0, SIGKILL);
19021 +                       vx_info_kill(vxi, 1, SIGKILL);
19022 +               default:
19023 +                       break;
19024 +               }
19025 +       }
19026 +       return 0;
19027 +}
19028 +
19029 +long vs_oom_action(unsigned int cmd)
19030 +{
19031 +       struct vx_info *vxi = current_vx_info();
19032 +       long ret = 0;
19033 +
19034 +       vxdprintk(VXD_CBIT(misc, 5),
19035 +               "vs_oom_action(%p[#%d],%u)",
19036 +               vxi, vxi ? vxi->vx_id : 0, cmd);
19037 +
19038 +       ret = vs_reboot_helper(vxi, cmd, NULL);
19039 +       if (ret)
19040 +               return ret;
19041 +
19042 +       vxi->reboot_cmd = cmd;
19043 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
19044 +               vx_info_kill(vxi, 0, SIGKILL);
19045 +               vx_info_kill(vxi, 1, SIGKILL);
19046 +       }
19047 +       return 0;
19048 +}
19049 +
19050 +/*
19051 + *      argv [0] = vshelper_path;
19052 + *      argv [1] = action: "startup", "shutdown"
19053 + *      argv [2] = context identifier
19054 + *
19055 + *      envp [*] = type-specific parameters
19056 + */
19057 +
19058 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
19059 +{
19060 +       char id_buf[8], cmd_buf[16];
19061 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
19062 +       char *envp[] = {"HOME=/", "TERM=linux",
19063 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
19064 +
19065 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
19066 +               return 0;
19067 +
19068 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
19069 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
19070 +
19071 +       switch (cmd) {
19072 +       case VSC_STARTUP:
19073 +               argv[1] = "startup";
19074 +               break;
19075 +       case VSC_SHUTDOWN:
19076 +               argv[1] = "shutdown";
19077 +               break;
19078 +       default:
19079 +               return 0;
19080 +       }
19081 +
19082 +       return do_vshelper(vshelper_path, argv, envp, 1);
19083 +}
19084 +
19085 +
19086 +/*
19087 + *      argv [0] = vshelper_path;
19088 + *      argv [1] = action: "netup", "netdown"
19089 + *      argv [2] = context identifier
19090 + *
19091 + *      envp [*] = type-specific parameters
19092 + */
19093 +
19094 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
19095 +{
19096 +       char id_buf[8], cmd_buf[16];
19097 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
19098 +       char *envp[] = {"HOME=/", "TERM=linux",
19099 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
19100 +
19101 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
19102 +               return 0;
19103 +
19104 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
19105 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
19106 +
19107 +       switch (cmd) {
19108 +       case VSC_NETUP:
19109 +               argv[1] = "netup";
19110 +               break;
19111 +       case VSC_NETDOWN:
19112 +               argv[1] = "netdown";
19113 +               break;
19114 +       default:
19115 +               return 0;
19116 +       }
19117 +
19118 +       return do_vshelper(vshelper_path, argv, envp, 1);
19119 +}
19120 +
19121 diff -NurpP --minimal linux-3.0-rc5/kernel/vserver/history.c linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/history.c
19122 --- linux-3.0-rc5/kernel/vserver/history.c      1970-01-01 01:00:00.000000000 +0100
19123 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/history.c 2011-06-10 22:11:24.000000000 +0200
19124 @@ -0,0 +1,258 @@
19125 +/*
19126 + *  kernel/vserver/history.c
19127 + *
19128 + *  Virtual Context History Backtrace
19129 + *
19130 + *  Copyright (C) 2004-2007  Herbert Pötzl
19131 + *
19132 + *  V0.01  basic structure
19133 + *  V0.02  hash/unhash and trace
19134 + *  V0.03  preemption fixes
19135 + *
19136 + */
19137 +
19138 +#include <linux/module.h>
19139 +#include <asm/uaccess.h>
19140 +
19141 +#include <linux/vserver/context.h>
19142 +#include <linux/vserver/debug.h>
19143 +#include <linux/vserver/debug_cmd.h>
19144 +#include <linux/vserver/history.h>
19145 +
19146 +
19147 +#ifdef CONFIG_VSERVER_HISTORY
19148 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
19149 +#else
19150 +#define VXH_SIZE       64
19151 +#endif
19152 +
19153 +struct _vx_history {
19154 +       unsigned int counter;
19155 +
19156 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
19157 +};
19158 +
19159 +
19160 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
19161 +
19162 +unsigned volatile int vxh_active = 1;
19163 +
19164 +static atomic_t sequence = ATOMIC_INIT(0);
19165 +
19166 +
19167 +/*     vxh_advance()
19168 +
19169 +       * requires disabled preemption                          */
19170 +
19171 +struct _vx_hist_entry *vxh_advance(void *loc)
19172 +{
19173 +       unsigned int cpu = smp_processor_id();
19174 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
19175 +       struct _vx_hist_entry *entry;
19176 +       unsigned int index;
19177 +
19178 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
19179 +       entry = &hist->entry[index];
19180 +
19181 +       entry->seq = atomic_inc_return(&sequence);
19182 +       entry->loc = loc;
19183 +       return entry;
19184 +}
19185 +
19186 +EXPORT_SYMBOL_GPL(vxh_advance);
19187 +
19188 +
19189 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
19190 +
19191 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
19192 +
19193 +
19194 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
19195 +
19196 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
19197 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
19198 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
19199 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
19200 +
19201 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
19202 +{
19203 +       switch (e->type) {
19204 +       case VXH_THROW_OOPS:
19205 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
19206 +               break;
19207 +
19208 +       case VXH_GET_VX_INFO:
19209 +       case VXH_PUT_VX_INFO:
19210 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
19211 +                       VXH_LOC_ARGS(e),
19212 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
19213 +                       VXH_VXI_ARGS(e));
19214 +               break;
19215 +
19216 +       case VXH_INIT_VX_INFO:
19217 +       case VXH_SET_VX_INFO:
19218 +       case VXH_CLR_VX_INFO:
19219 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
19220 +                       VXH_LOC_ARGS(e),
19221 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
19222 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
19223 +                       VXH_VXI_ARGS(e), e->sc.data);
19224 +               break;
19225 +
19226 +       case VXH_CLAIM_VX_INFO:
19227 +       case VXH_RELEASE_VX_INFO:
19228 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
19229 +                       VXH_LOC_ARGS(e),
19230 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
19231 +                       VXH_VXI_ARGS(e), e->sc.data);
19232 +               break;
19233 +
19234 +       case VXH_ALLOC_VX_INFO:
19235 +       case VXH_DEALLOC_VX_INFO:
19236 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
19237 +                       VXH_LOC_ARGS(e),
19238 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
19239 +                       VXH_VXI_ARGS(e));
19240 +               break;
19241 +
19242 +       case VXH_HASH_VX_INFO:
19243 +       case VXH_UNHASH_VX_INFO:
19244 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
19245 +                       VXH_LOC_ARGS(e),
19246 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
19247 +                       VXH_VXI_ARGS(e));
19248 +               break;
19249 +
19250 +       case VXH_LOC_VX_INFO:
19251 +       case VXH_LOOKUP_VX_INFO:
19252 +       case VXH_CREATE_VX_INFO:
19253 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
19254 +                       VXH_LOC_ARGS(e),
19255 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
19256 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
19257 +                       e->ll.arg, VXH_VXI_ARGS(e));
19258 +               break;
19259 +       }
19260 +}
19261 +
19262 +static void __vxh_dump_history(void)
19263 +{
19264 +       unsigned int i, cpu;
19265 +
19266 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
19267 +               atomic_read(&sequence), NR_CPUS);
19268 +
19269 +       for (i = 0; i < VXH_SIZE; i++) {
19270 +               for_each_online_cpu(cpu) {
19271 +                       struct _vx_history *hist =
19272 +                               &per_cpu(vx_history_buffer, cpu);
19273 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
19274 +                       struct _vx_hist_entry *entry = &hist->entry[index];
19275 +
19276 +                       vxh_dump_entry(entry, cpu);
19277 +               }
19278 +       }
19279 +}
19280 +
19281 +void   vxh_dump_history(void)
19282 +{
19283 +       vxh_active = 0;
19284 +#ifdef CONFIG_SMP
19285 +       local_irq_enable();
19286 +       smp_send_stop();
19287 +       local_irq_disable();
19288 +#endif
19289 +       __vxh_dump_history();
19290 +}
19291 +
19292 +
19293 +/* vserver syscall commands below here */
19294 +
19295 +
19296 +int vc_dump_history(uint32_t id)
19297 +{
19298 +       vxh_active = 0;
19299 +       __vxh_dump_history();
19300 +       vxh_active = 1;
19301 +
19302 +       return 0;
19303 +}
19304 +
19305 +
19306 +int do_read_history(struct __user _vx_hist_entry *data,
19307 +       int cpu, uint32_t *index, uint32_t *count)
19308 +{
19309 +       int pos, ret = 0;
19310 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
19311 +       int end = hist->counter;
19312 +       int start = end - VXH_SIZE + 2;
19313 +       int idx = *index;
19314 +
19315 +       /* special case: get current pos */
19316 +       if (!*count) {
19317 +               *index = end;
19318 +               return 0;
19319 +       }
19320 +
19321 +       /* have we lost some data? */
19322 +       if (idx < start)
19323 +               idx = start;
19324 +
19325 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
19326 +               struct _vx_hist_entry *entry =
19327 +                       &hist->entry[idx % VXH_SIZE];
19328 +
19329 +               /* send entry to userspace */
19330 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
19331 +               if (ret)
19332 +                       break;
19333 +       }
19334 +       /* save new index and count */
19335 +       *index = idx;
19336 +       *count = pos;
19337 +       return ret ? ret : (*index < end);
19338 +}
19339 +
19340 +int vc_read_history(uint32_t id, void __user *data)
19341 +{
19342 +       struct vcmd_read_history_v0 vc_data;
19343 +       int ret;
19344 +
19345 +       if (id >= NR_CPUS)
19346 +               return -EINVAL;
19347 +
19348 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19349 +               return -EFAULT;
19350 +
19351 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
19352 +               id, &vc_data.index, &vc_data.count);
19353 +
19354 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19355 +               return -EFAULT;
19356 +       return ret;
19357 +}
19358 +
19359 +#ifdef CONFIG_COMPAT
19360 +
19361 +int vc_read_history_x32(uint32_t id, void __user *data)
19362 +{
19363 +       struct vcmd_read_history_v0_x32 vc_data;
19364 +       int ret;
19365 +
19366 +       if (id >= NR_CPUS)
19367 +               return -EINVAL;
19368 +
19369 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19370 +               return -EFAULT;
19371 +
19372 +       ret = do_read_history((struct __user _vx_hist_entry *)
19373 +               compat_ptr(vc_data.data_ptr),
19374 +               id, &vc_data.index, &vc_data.count);
19375 +
19376 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19377 +               return -EFAULT;
19378 +       return ret;
19379 +}
19380 +
19381 +#endif /* CONFIG_COMPAT */
19382 +
19383 diff -NurpP --minimal linux-3.0-rc5/kernel/vserver/inet.c linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/inet.c
19384 --- linux-3.0-rc5/kernel/vserver/inet.c 1970-01-01 01:00:00.000000000 +0100
19385 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/inet.c    2011-06-13 18:20:44.000000000 +0200
19386 @@ -0,0 +1,225 @@
19387 +
19388 +#include <linux/in.h>
19389 +#include <linux/inetdevice.h>
19390 +#include <linux/vs_inet.h>
19391 +#include <linux/vs_inet6.h>
19392 +#include <linux/vserver/debug.h>
19393 +#include <net/route.h>
19394 +#include <net/addrconf.h>
19395 +
19396 +
19397 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19398 +{
19399 +       int ret = 0;
19400 +
19401 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19402 +               ret = 1;
19403 +       else {
19404 +               struct nx_addr_v4 *ptr;
19405 +
19406 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
19407 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19408 +                               ret = 1;
19409 +                               break;
19410 +                       }
19411 +               }
19412 +       }
19413 +
19414 +       vxdprintk(VXD_CBIT(net, 2),
19415 +               "nx_v4_addr_conflict(%p,%p): %d",
19416 +               nxi1, nxi2, ret);
19417 +
19418 +       return ret;
19419 +}
19420 +
19421 +
19422 +#ifdef CONFIG_IPV6
19423 +
19424 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19425 +{
19426 +       int ret = 0;
19427 +
19428 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19429 +               ret = 1;
19430 +       else {
19431 +               struct nx_addr_v6 *ptr;
19432 +
19433 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
19434 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19435 +                               ret = 1;
19436 +                               break;
19437 +                       }
19438 +               }
19439 +       }
19440 +
19441 +       vxdprintk(VXD_CBIT(net, 2),
19442 +               "nx_v6_addr_conflict(%p,%p): %d",
19443 +               nxi1, nxi2, ret);
19444 +
19445 +       return ret;
19446 +}
19447 +
19448 +#endif
19449 +
19450 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19451 +{
19452 +       struct in_device *in_dev;
19453 +       struct in_ifaddr **ifap;
19454 +       struct in_ifaddr *ifa;
19455 +       int ret = 0;
19456 +
19457 +       if (!dev)
19458 +               goto out;
19459 +       in_dev = in_dev_get(dev);
19460 +       if (!in_dev)
19461 +               goto out;
19462 +
19463 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
19464 +               ifap = &ifa->ifa_next) {
19465 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
19466 +                       ret = 1;
19467 +                       break;
19468 +               }
19469 +       }
19470 +       in_dev_put(in_dev);
19471 +out:
19472 +       return ret;
19473 +}
19474 +
19475 +
19476 +#ifdef CONFIG_IPV6
19477 +
19478 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19479 +{
19480 +       struct inet6_dev *in_dev;
19481 +       struct inet6_ifaddr *ifa;
19482 +       int ret = 0;
19483 +
19484 +       if (!dev)
19485 +               goto out;
19486 +       in_dev = in6_dev_get(dev);
19487 +       if (!in_dev)
19488 +               goto out;
19489 +
19490 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
19491 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
19492 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
19493 +                       ret = 1;
19494 +                       break;
19495 +               }
19496 +       }
19497 +       in6_dev_put(in_dev);
19498 +out:
19499 +       return ret;
19500 +}
19501 +
19502 +#endif
19503 +
19504 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19505 +{
19506 +       int ret = 1;
19507 +
19508 +       if (!nxi)
19509 +               goto out;
19510 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
19511 +               goto out;
19512 +#ifdef CONFIG_IPV6
19513 +       ret = 2;
19514 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
19515 +               goto out;
19516 +#endif
19517 +       ret = 0;
19518 +out:
19519 +       vxdprintk(VXD_CBIT(net, 3),
19520 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
19521 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
19522 +       return ret;
19523 +}
19524 +
19525 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
19526 +       struct flowi4 *fl4)
19527 +{
19528 +       struct rtable *rt;
19529 +
19530 +       if (!nxi)
19531 +               return NULL;
19532 +
19533 +       /* FIXME: handle lback only case */
19534 +       if (!NX_IPV4(nxi))
19535 +               return ERR_PTR(EPERM);
19536 +
19537 +       vxdprintk(VXD_CBIT(net, 4),
19538 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
19539 +               nxi, nxi ? nxi->nx_id : 0,
19540 +               NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
19541 +
19542 +       /* single IP is unconditional */
19543 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
19544 +               (fl4->saddr == INADDR_ANY))
19545 +               fl4->saddr = nxi->v4.ip[0].s_addr;
19546 +
19547 +       if (fl4->saddr == INADDR_ANY) {
19548 +               struct nx_addr_v4 *ptr;
19549 +               __be32 found = 0;
19550 +
19551 +               rt = __ip_route_output_key(net, fl4);
19552 +               if (!IS_ERR(rt)) {
19553 +                       found = fl4->saddr;
19554 +                       ip_rt_put(rt);
19555 +                       vxdprintk(VXD_CBIT(net, 4),
19556 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19557 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
19558 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
19559 +                               goto found;
19560 +               }
19561 +
19562 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
19563 +                       __be32 primary = ptr->ip[0].s_addr;
19564 +                       __be32 mask = ptr->mask.s_addr;
19565 +                       __be32 neta = primary & mask;
19566 +
19567 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
19568 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
19569 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
19570 +                               NIPQUAD(mask), NIPQUAD(neta));
19571 +                       if ((found & mask) != neta)
19572 +                               continue;
19573 +
19574 +                       fl4->saddr = primary;
19575 +                       rt = __ip_route_output_key(net, fl4);
19576 +                       vxdprintk(VXD_CBIT(net, 4),
19577 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19578 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
19579 +                       if (!IS_ERR(rt)) {
19580 +                               found = fl4->saddr;
19581 +                               ip_rt_put(rt);
19582 +                               if (found == primary)
19583 +                                       goto found;
19584 +                       }
19585 +               }
19586 +               /* still no source ip? */
19587 +               found = ipv4_is_loopback(fl4->daddr)
19588 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
19589 +       found:
19590 +               /* assign src ip to flow */
19591 +               fl4->saddr = found;
19592 +
19593 +       } else {
19594 +               if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
19595 +                       return ERR_PTR(EPERM);
19596 +       }
19597 +
19598 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
19599 +               if (ipv4_is_loopback(fl4->daddr))
19600 +                       fl4->daddr = nxi->v4_lback.s_addr;
19601 +               if (ipv4_is_loopback(fl4->saddr))
19602 +                       fl4->saddr = nxi->v4_lback.s_addr;
19603 +       } else if (ipv4_is_loopback(fl4->daddr) &&
19604 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
19605 +               return ERR_PTR(EPERM);
19606 +
19607 +       return NULL;
19608 +}
19609 +
19610 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
19611 +
19612 diff -NurpP --minimal linux-3.0-rc5/kernel/vserver/init.c linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/init.c
19613 --- linux-3.0-rc5/kernel/vserver/init.c 1970-01-01 01:00:00.000000000 +0100
19614 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/init.c    2011-06-10 22:11:24.000000000 +0200
19615 @@ -0,0 +1,45 @@
19616 +/*
19617 + *  linux/kernel/init.c
19618 + *
19619 + *  Virtual Server Init
19620 + *
19621 + *  Copyright (C) 2004-2007  Herbert Pötzl
19622 + *
19623 + *  V0.01  basic structure
19624 + *
19625 + */
19626 +
19627 +#include <linux/init.h>
19628 +
19629 +int    vserver_register_sysctl(void);
19630 +void   vserver_unregister_sysctl(void);
19631 +
19632 +
19633 +static int __init init_vserver(void)
19634 +{
19635 +       int ret = 0;
19636 +
19637 +#ifdef CONFIG_VSERVER_DEBUG
19638 +       vserver_register_sysctl();
19639 +#endif
19640 +       return ret;
19641 +}
19642 +
19643 +
19644 +static void __exit exit_vserver(void)
19645 +{
19646 +
19647 +#ifdef CONFIG_VSERVER_DEBUG
19648 +       vserver_unregister_sysctl();
19649 +#endif
19650 +       return;
19651 +}
19652 +
19653 +/* FIXME: GFP_ZONETYPES gone
19654 +long vx_slab[GFP_ZONETYPES]; */
19655 +long vx_area;
19656 +
19657 +
19658 +module_init(init_vserver);
19659 +module_exit(exit_vserver);
19660 +
19661 diff -NurpP --minimal linux-3.0-rc5/kernel/vserver/inode.c linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/inode.c
19662 --- linux-3.0-rc5/kernel/vserver/inode.c        1970-01-01 01:00:00.000000000 +0100
19663 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/inode.c   2011-06-10 22:11:24.000000000 +0200
19664 @@ -0,0 +1,437 @@
19665 +/*
19666 + *  linux/kernel/vserver/inode.c
19667 + *
19668 + *  Virtual Server: File System Support
19669 + *
19670 + *  Copyright (C) 2004-2007  Herbert Pötzl
19671 + *
19672 + *  V0.01  separated from vcontext V0.05
19673 + *  V0.02  moved to tag (instead of xid)
19674 + *
19675 + */
19676 +
19677 +#include <linux/tty.h>
19678 +#include <linux/proc_fs.h>
19679 +#include <linux/devpts_fs.h>
19680 +#include <linux/fs.h>
19681 +#include <linux/file.h>
19682 +#include <linux/mount.h>
19683 +#include <linux/parser.h>
19684 +#include <linux/namei.h>
19685 +#include <linux/vserver/inode.h>
19686 +#include <linux/vserver/inode_cmd.h>
19687 +#include <linux/vs_base.h>
19688 +#include <linux/vs_tag.h>
19689 +
19690 +#include <asm/uaccess.h>
19691 +
19692 +
19693 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19694 +{
19695 +       struct proc_dir_entry *entry;
19696 +
19697 +       if (!in || !in->i_sb)
19698 +               return -ESRCH;
19699 +
19700 +       *flags = IATTR_TAG
19701 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
19702 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
19703 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
19704 +               | (IS_COW(in) ? IATTR_COW : 0);
19705 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
19706 +
19707 +       if (S_ISDIR(in->i_mode))
19708 +               *mask |= IATTR_BARRIER;
19709 +
19710 +       if (IS_TAGGED(in)) {
19711 +               *tag = in->i_tag;
19712 +               *mask |= IATTR_TAG;
19713 +       }
19714 +
19715 +       switch (in->i_sb->s_magic) {
19716 +       case PROC_SUPER_MAGIC:
19717 +               entry = PROC_I(in)->pde;
19718 +
19719 +               /* check for specific inodes? */
19720 +               if (entry)
19721 +                       *mask |= IATTR_FLAGS;
19722 +               if (entry)
19723 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
19724 +               else
19725 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19726 +               break;
19727 +
19728 +       case DEVPTS_SUPER_MAGIC:
19729 +               *tag = in->i_tag;
19730 +               *mask |= IATTR_TAG;
19731 +               break;
19732 +
19733 +       default:
19734 +               break;
19735 +       }
19736 +       return 0;
19737 +}
19738 +
19739 +int vc_get_iattr(void __user *data)
19740 +{
19741 +       struct path path;
19742 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19743 +       int ret;
19744 +
19745 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19746 +               return -EFAULT;
19747 +
19748 +       ret = user_lpath(vc_data.name, &path);
19749 +       if (!ret) {
19750 +               ret = __vc_get_iattr(path.dentry->d_inode,
19751 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19752 +               path_put(&path);
19753 +       }
19754 +       if (ret)
19755 +               return ret;
19756 +
19757 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19758 +               ret = -EFAULT;
19759 +       return ret;
19760 +}
19761 +
19762 +#ifdef CONFIG_COMPAT
19763 +
19764 +int vc_get_iattr_x32(void __user *data)
19765 +{
19766 +       struct path path;
19767 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19768 +       int ret;
19769 +
19770 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19771 +               return -EFAULT;
19772 +
19773 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19774 +       if (!ret) {
19775 +               ret = __vc_get_iattr(path.dentry->d_inode,
19776 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19777 +               path_put(&path);
19778 +       }
19779 +       if (ret)
19780 +               return ret;
19781 +
19782 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19783 +               ret = -EFAULT;
19784 +       return ret;
19785 +}
19786 +
19787 +#endif /* CONFIG_COMPAT */
19788 +
19789 +
19790 +int vc_fget_iattr(uint32_t fd, void __user *data)
19791 +{
19792 +       struct file *filp;
19793 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19794 +       int ret;
19795 +
19796 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19797 +               return -EFAULT;
19798 +
19799 +       filp = fget(fd);
19800 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19801 +               return -EBADF;
19802 +
19803 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
19804 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
19805 +
19806 +       fput(filp);
19807 +
19808 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19809 +               ret = -EFAULT;
19810 +       return ret;
19811 +}
19812 +
19813 +
19814 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19815 +{
19816 +       struct inode *in = de->d_inode;
19817 +       int error = 0, is_proc = 0, has_tag = 0;
19818 +       struct iattr attr = { 0 };
19819 +
19820 +       if (!in || !in->i_sb)
19821 +               return -ESRCH;
19822 +
19823 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19824 +       if ((*mask & IATTR_FLAGS) && !is_proc)
19825 +               return -EINVAL;
19826 +
19827 +       has_tag = IS_TAGGED(in) ||
19828 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
19829 +       if ((*mask & IATTR_TAG) && !has_tag)
19830 +               return -EINVAL;
19831 +
19832 +       mutex_lock(&in->i_mutex);
19833 +       if (*mask & IATTR_TAG) {
19834 +               attr.ia_tag = *tag;
19835 +               attr.ia_valid |= ATTR_TAG;
19836 +       }
19837 +
19838 +       if (*mask & IATTR_FLAGS) {
19839 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
19840 +               unsigned int iflags = PROC_I(in)->vx_flags;
19841 +
19842 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
19843 +                       | (*flags & IATTR_FLAGS);
19844 +               PROC_I(in)->vx_flags = iflags;
19845 +               if (entry)
19846 +                       entry->vx_flags = iflags;
19847 +       }
19848 +
19849 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
19850 +               IATTR_BARRIER | IATTR_COW)) {
19851 +               int iflags = in->i_flags;
19852 +               int vflags = in->i_vflags;
19853 +
19854 +               if (*mask & IATTR_IMMUTABLE) {
19855 +                       if (*flags & IATTR_IMMUTABLE)
19856 +                               iflags |= S_IMMUTABLE;
19857 +                       else
19858 +                               iflags &= ~S_IMMUTABLE;
19859 +               }
19860 +               if (*mask & IATTR_IXUNLINK) {
19861 +                       if (*flags & IATTR_IXUNLINK)
19862 +                               iflags |= S_IXUNLINK;
19863 +                       else
19864 +                               iflags &= ~S_IXUNLINK;
19865 +               }
19866 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
19867 +                       if (*flags & IATTR_BARRIER)
19868 +                               vflags |= V_BARRIER;
19869 +                       else
19870 +                               vflags &= ~V_BARRIER;
19871 +               }
19872 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
19873 +                       if (*flags & IATTR_COW)
19874 +                               vflags |= V_COW;
19875 +                       else
19876 +                               vflags &= ~V_COW;
19877 +               }
19878 +               if (in->i_op && in->i_op->sync_flags) {
19879 +                       error = in->i_op->sync_flags(in, iflags, vflags);
19880 +                       if (error)
19881 +                               goto out;
19882 +               }
19883 +       }
19884 +
19885 +       if (attr.ia_valid) {
19886 +               if (in->i_op && in->i_op->setattr)
19887 +                       error = in->i_op->setattr(de, &attr);
19888 +               else {
19889 +                       error = inode_change_ok(in, &attr);
19890 +                       if (!error) {
19891 +                               setattr_copy(in, &attr);
19892 +                               mark_inode_dirty(in);
19893 +                       }
19894 +               }
19895 +       }
19896 +
19897 +out:
19898 +       mutex_unlock(&in->i_mutex);
19899 +       return error;
19900 +}
19901 +
19902 +int vc_set_iattr(void __user *data)
19903 +{
19904 +       struct path path;
19905 +       struct vcmd_ctx_iattr_v1 vc_data;
19906 +       int ret;
19907 +
19908 +       if (!capable(CAP_LINUX_IMMUTABLE))
19909 +               return -EPERM;
19910 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19911 +               return -EFAULT;
19912 +
19913 +       ret = user_lpath(vc_data.name, &path);
19914 +       if (!ret) {
19915 +               ret = __vc_set_iattr(path.dentry,
19916 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19917 +               path_put(&path);
19918 +       }
19919 +
19920 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19921 +               ret = -EFAULT;
19922 +       return ret;
19923 +}
19924 +
19925 +#ifdef CONFIG_COMPAT
19926 +
19927 +int vc_set_iattr_x32(void __user *data)
19928 +{
19929 +       struct path path;
19930 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
19931 +       int ret;
19932 +
19933 +       if (!capable(CAP_LINUX_IMMUTABLE))
19934 +               return -EPERM;
19935 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19936 +               return -EFAULT;
19937 +
19938 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19939 +       if (!ret) {
19940 +               ret = __vc_set_iattr(path.dentry,
19941 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19942 +               path_put(&path);
19943 +       }
19944 +
19945 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19946 +               ret = -EFAULT;
19947 +       return ret;
19948 +}
19949 +
19950 +#endif /* CONFIG_COMPAT */
19951 +
19952 +int vc_fset_iattr(uint32_t fd, void __user *data)
19953 +{
19954 +       struct file *filp;
19955 +       struct vcmd_ctx_fiattr_v0 vc_data;
19956 +       int ret;
19957 +
19958 +       if (!capable(CAP_LINUX_IMMUTABLE))
19959 +               return -EPERM;
19960 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19961 +               return -EFAULT;
19962 +
19963 +       filp = fget(fd);
19964 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19965 +               return -EBADF;
19966 +
19967 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
19968 +               &vc_data.flags, &vc_data.mask);
19969 +
19970 +       fput(filp);
19971 +
19972 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19973 +               return -EFAULT;
19974 +       return ret;
19975 +}
19976 +
19977 +
19978 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
19979 +
19980 +static match_table_t tokens = {
19981 +       {Opt_notagcheck, "notagcheck"},
19982 +#ifdef CONFIG_PROPAGATE
19983 +       {Opt_notag, "notag"},
19984 +       {Opt_tag, "tag"},
19985 +       {Opt_tagid, "tagid=%u"},
19986 +#endif
19987 +       {Opt_err, NULL}
19988 +};
19989 +
19990 +
19991 +static void __dx_parse_remove(char *string, char *opt)
19992 +{
19993 +       char *p = strstr(string, opt);
19994 +       char *q = p;
19995 +
19996 +       if (p) {
19997 +               while (*q != '\0' && *q != ',')
19998 +                       q++;
19999 +               while (*q)
20000 +                       *p++ = *q++;
20001 +               while (*p)
20002 +                       *p++ = '\0';
20003 +       }
20004 +}
20005 +
20006 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
20007 +                unsigned long *flags)
20008 +{
20009 +       int set = 0;
20010 +       substring_t args[MAX_OPT_ARGS];
20011 +       int token;
20012 +       char *s, *p, *opts;
20013 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_WARN)
20014 +       int option = 0;
20015 +#endif
20016 +
20017 +       if (!string)
20018 +               return 0;
20019 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
20020 +       if (!s)
20021 +               return 0;
20022 +
20023 +       opts = s;
20024 +       while ((p = strsep(&opts, ",")) != NULL) {
20025 +               token = match_token(p, tokens, args);
20026 +
20027 +               switch (token) {
20028 +#ifdef CONFIG_PROPAGATE
20029 +               case Opt_tag:
20030 +                       if (tag)
20031 +                               *tag = 0;
20032 +                       if (remove)
20033 +                               __dx_parse_remove(s, "tag");
20034 +                       *mnt_flags |= MNT_TAGID;
20035 +                       set |= MNT_TAGID;
20036 +                       break;
20037 +               case Opt_notag:
20038 +                       if (remove)
20039 +                               __dx_parse_remove(s, "notag");
20040 +                       *mnt_flags |= MNT_NOTAG;
20041 +                       set |= MNT_NOTAG;
20042 +                       break;
20043 +               case Opt_tagid:
20044 +                       if (tag && !match_int(args, &option))
20045 +                               *tag = option;
20046 +                       if (remove)
20047 +                               __dx_parse_remove(s, "tagid");
20048 +                       *mnt_flags |= MNT_TAGID;
20049 +                       set |= MNT_TAGID;
20050 +                       break;
20051 +#endif
20052 +               case Opt_notagcheck:
20053 +                       if (remove)
20054 +                               __dx_parse_remove(s, "notagcheck");
20055 +                       *flags |= MS_NOTAGCHECK;
20056 +                       set |= MS_NOTAGCHECK;
20057 +                       break;
20058 +               }
20059 +               vxdprintk(VXD_CBIT(tag, 7),
20060 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
20061 +                       p, token, option);
20062 +       }
20063 +       if (set)
20064 +               strcpy(string, s);
20065 +       kfree(s);
20066 +       return set;
20067 +}
20068 +
20069 +#ifdef CONFIG_PROPAGATE
20070 +
20071 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
20072 +{
20073 +       tag_t new_tag = 0;
20074 +       struct vfsmount *mnt;
20075 +       int propagate;
20076 +
20077 +       if (!nd)
20078 +               return;
20079 +       mnt = nd->path.mnt;
20080 +       if (!mnt)
20081 +               return;
20082 +
20083 +       propagate = (mnt->mnt_flags & MNT_TAGID);
20084 +       if (propagate)
20085 +               new_tag = mnt->mnt_tag;
20086 +
20087 +       vxdprintk(VXD_CBIT(tag, 7),
20088 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
20089 +               inode, inode->i_ino, inode->i_tag,
20090 +               new_tag, (propagate) ? 1 : 0);
20091 +
20092 +       if (propagate)
20093 +               inode->i_tag = new_tag;
20094 +}
20095 +
20096 +#include <linux/module.h>
20097 +
20098 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
20099 +
20100 +#endif /* CONFIG_PROPAGATE */
20101 +
20102 diff -NurpP --minimal linux-3.0-rc5/kernel/vserver/limit.c linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/limit.c
20103 --- linux-3.0-rc5/kernel/vserver/limit.c        1970-01-01 01:00:00.000000000 +0100
20104 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/limit.c   2011-06-10 22:11:24.000000000 +0200
20105 @@ -0,0 +1,354 @@
20106 +/*
20107 + *  linux/kernel/vserver/limit.c
20108 + *
20109 + *  Virtual Server: Context Limits
20110 + *
20111 + *  Copyright (C) 2004-2010  Herbert Pötzl
20112 + *
20113 + *  V0.01  broken out from vcontext V0.05
20114 + *  V0.02  changed vcmds to vxi arg
20115 + *  V0.03  added memory cgroup support
20116 + *
20117 + */
20118 +
20119 +#include <linux/sched.h>
20120 +#include <linux/module.h>
20121 +#include <linux/memcontrol.h>
20122 +#include <linux/res_counter.h>
20123 +#include <linux/vs_limit.h>
20124 +#include <linux/vserver/limit.h>
20125 +#include <linux/vserver/limit_cmd.h>
20126 +
20127 +#include <asm/uaccess.h>
20128 +
20129 +
20130 +const char *vlimit_name[NUM_LIMITS] = {
20131 +#ifdef CONFIG_VSERVER_LEGACY_MEM
20132 +       [RLIMIT_RSS]            = "RSS",
20133 +       [RLIMIT_AS]             = "VM",
20134 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
20135 +       [RLIMIT_CPU]            = "CPU",
20136 +       [RLIMIT_NPROC]          = "NPROC",
20137 +       [RLIMIT_NOFILE]         = "NOFILE",
20138 +       [RLIMIT_LOCKS]          = "LOCKS",
20139 +       [RLIMIT_SIGPENDING]     = "SIGP",
20140 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
20141 +
20142 +       [VLIMIT_NSOCK]          = "NSOCK",
20143 +       [VLIMIT_OPENFD]         = "OPENFD",
20144 +       [VLIMIT_SHMEM]          = "SHMEM",
20145 +       [VLIMIT_DENTRY]         = "DENTRY",
20146 +};
20147 +
20148 +EXPORT_SYMBOL_GPL(vlimit_name);
20149 +
20150 +#define MASK_ENTRY(x)  (1 << (x))
20151 +
20152 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
20153 +               /* minimum */
20154 +       0
20155 +       ,       /* softlimit */
20156 +#ifdef CONFIG_VSERVER_LEGACY_MEM
20157 +       MASK_ENTRY( RLIMIT_RSS          ) |
20158 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
20159 +       0
20160 +       ,       /* maximum */
20161 +#ifdef CONFIG_VSERVER_LEGACY_MEM
20162 +       MASK_ENTRY( RLIMIT_RSS          ) |
20163 +       MASK_ENTRY( RLIMIT_AS           ) |
20164 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
20165 +       MASK_ENTRY( RLIMIT_NPROC        ) |
20166 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
20167 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
20168 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
20169 +
20170 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
20171 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
20172 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
20173 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
20174 +       0
20175 +};
20176 +               /* accounting only */
20177 +uint32_t account_mask =
20178 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
20179 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
20180 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
20181 +       0;
20182 +
20183 +
20184 +static int is_valid_vlimit(int id)
20185 +{
20186 +       uint32_t mask = vlimit_mask.minimum |
20187 +               vlimit_mask.softlimit | vlimit_mask.maximum;
20188 +       return mask & (1 << id);
20189 +}
20190 +
20191 +static int is_accounted_vlimit(int id)
20192 +{
20193 +       if (is_valid_vlimit(id))
20194 +               return 1;
20195 +       return account_mask & (1 << id);
20196 +}
20197 +
20198 +
20199 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
20200 +{
20201 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
20202 +       return VX_VLIM(limit);
20203 +}
20204 +
20205 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
20206 +{
20207 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
20208 +       return VX_VLIM(limit);
20209 +}
20210 +
20211 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
20212 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
20213 +{
20214 +       if (!is_valid_vlimit(id))
20215 +               return -EINVAL;
20216 +
20217 +       if (minimum)
20218 +               *minimum = CRLIM_UNSET;
20219 +       if (softlimit)
20220 +               *softlimit = vc_get_soft(vxi, id);
20221 +       if (maximum)
20222 +               *maximum = vc_get_hard(vxi, id);
20223 +       return 0;
20224 +}
20225 +
20226 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
20227 +{
20228 +       struct vcmd_ctx_rlimit_v0 vc_data;
20229 +       int ret;
20230 +
20231 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20232 +               return -EFAULT;
20233 +
20234 +       ret = do_get_rlimit(vxi, vc_data.id,
20235 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
20236 +       if (ret)
20237 +               return ret;
20238 +
20239 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20240 +               return -EFAULT;
20241 +       return 0;
20242 +}
20243 +
20244 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
20245 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
20246 +{
20247 +       if (!is_valid_vlimit(id))
20248 +               return -EINVAL;
20249 +
20250 +       if (maximum != CRLIM_KEEP)
20251 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
20252 +       if (softlimit != CRLIM_KEEP)
20253 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
20254 +
20255 +       /* clamp soft limit */
20256 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
20257 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
20258 +
20259 +       return 0;
20260 +}
20261 +
20262 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
20263 +{
20264 +       struct vcmd_ctx_rlimit_v0 vc_data;
20265 +
20266 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20267 +               return -EFAULT;
20268 +
20269 +       return do_set_rlimit(vxi, vc_data.id,
20270 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
20271 +}
20272 +
20273 +#ifdef CONFIG_IA32_EMULATION
20274 +
20275 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
20276 +{
20277 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
20278 +
20279 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20280 +               return -EFAULT;
20281 +
20282 +       return do_set_rlimit(vxi, vc_data.id,
20283 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
20284 +}
20285 +
20286 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
20287 +{
20288 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
20289 +       int ret;
20290 +
20291 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20292 +               return -EFAULT;
20293 +
20294 +       ret = do_get_rlimit(vxi, vc_data.id,
20295 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
20296 +       if (ret)
20297 +               return ret;
20298 +
20299 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20300 +               return -EFAULT;
20301 +       return 0;
20302 +}
20303 +
20304 +#endif /* CONFIG_IA32_EMULATION */
20305 +
20306 +
20307 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
20308 +{
20309 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
20310 +               return -EFAULT;
20311 +       return 0;
20312 +}
20313 +
20314 +
20315 +static inline void vx_reset_hits(struct _vx_limit *limit)
20316 +{
20317 +       int lim;
20318 +
20319 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20320 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20321 +       }
20322 +}
20323 +
20324 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
20325 +{
20326 +       vx_reset_hits(&vxi->limit);
20327 +       return 0;
20328 +}
20329 +
20330 +static inline void vx_reset_minmax(struct _vx_limit *limit)
20331 +{
20332 +       rlim_t value;
20333 +       int lim;
20334 +
20335 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20336 +               value = __rlim_get(limit, lim);
20337 +               __rlim_rmax(limit, lim) = value;
20338 +               __rlim_rmin(limit, lim) = value;
20339 +       }
20340 +}
20341 +
20342 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
20343 +{
20344 +       vx_reset_minmax(&vxi->limit);
20345 +       return 0;
20346 +}
20347 +
20348 +
20349 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
20350 +{
20351 +       struct vcmd_rlimit_stat_v0 vc_data;
20352 +       struct _vx_limit *limit = &vxi->limit;
20353 +       int id;
20354 +
20355 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20356 +               return -EFAULT;
20357 +
20358 +       id = vc_data.id;
20359 +       if (!is_accounted_vlimit(id))
20360 +               return -EINVAL;
20361 +
20362 +       vx_limit_fixup(limit, id);
20363 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
20364 +       vc_data.value = __rlim_get(limit, id);
20365 +       vc_data.minimum = __rlim_rmin(limit, id);
20366 +       vc_data.maximum = __rlim_rmax(limit, id);
20367 +
20368 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20369 +               return -EFAULT;
20370 +       return 0;
20371 +}
20372 +
20373 +
20374 +void vx_vsi_meminfo(struct sysinfo *val)
20375 +{
20376 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20377 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20378 +       u64 res_limit, res_usage;
20379 +
20380 +       if (!mcg)
20381 +               return;
20382 +
20383 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
20384 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
20385 +
20386 +       if (res_limit != RESOURCE_MAX)
20387 +               val->totalram = (res_limit >> PAGE_SHIFT);
20388 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
20389 +       val->bufferram = 0;
20390 +       val->totalhigh = 0;
20391 +       val->freehigh = 0;
20392 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
20393 +       return;
20394 +}
20395 +
20396 +void vx_vsi_swapinfo(struct sysinfo *val)
20397 +{
20398 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20399 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
20400 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20401 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
20402 +       s64 swap_limit, swap_usage;
20403 +
20404 +       if (!mcg)
20405 +               return;
20406 +
20407 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
20408 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
20409 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
20410 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
20411 +
20412 +       if (res_limit == RESOURCE_MAX)
20413 +               return;
20414 +
20415 +       swap_limit = memsw_limit - res_limit;
20416 +       if (memsw_limit != RESOURCE_MAX)
20417 +               val->totalswap = swap_limit >> PAGE_SHIFT;
20418 +
20419 +       swap_usage = memsw_usage - res_usage;
20420 +       val->freeswap = (swap_usage < swap_limit) ?
20421 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
20422 +#else  /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20423 +       val->totalswap = 0;
20424 +       val->freeswap = 0;
20425 +#endif /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20426 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
20427 +       return;
20428 +}
20429 +
20430 +long vx_vsi_cached(struct sysinfo *val)
20431 +{
20432 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20433 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20434 +
20435 +       return mem_cgroup_stat_read_cache(mcg);
20436 +#else
20437 +       return 0;
20438 +#endif
20439 +}
20440 +
20441 +
20442 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
20443 +{
20444 +       struct vx_info *vxi = mm->mm_vx_info;
20445 +       unsigned long points;
20446 +       rlim_t v, w;
20447 +
20448 +       if (!vxi)
20449 +               return 0;
20450 +
20451 +       points = vxi->vx_badness_bias;
20452 +
20453 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
20454 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
20455 +       points += (v > w) ? (v - w) : 0;
20456 +
20457 +       return points;
20458 +}
20459 +
20460 diff -NurpP --minimal linux-3.0-rc5/kernel/vserver/limit_init.h linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/limit_init.h
20461 --- linux-3.0-rc5/kernel/vserver/limit_init.h   1970-01-01 01:00:00.000000000 +0100
20462 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/limit_init.h      2011-06-10 22:11:24.000000000 +0200
20463 @@ -0,0 +1,31 @@
20464 +
20465 +
20466 +static inline void vx_info_init_limit(struct _vx_limit *limit)
20467 +{
20468 +       int lim;
20469 +
20470 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20471 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
20472 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
20473 +               __rlim_set(limit, lim, 0);
20474 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20475 +               __rlim_rmin(limit, lim) = 0;
20476 +               __rlim_rmax(limit, lim) = 0;
20477 +       }
20478 +}
20479 +
20480 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
20481 +{
20482 +       rlim_t value;
20483 +       int lim;
20484 +
20485 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20486 +               if ((1 << lim) & VLIM_NOCHECK)
20487 +                       continue;
20488 +               value = __rlim_get(limit, lim);
20489 +               vxwprintk_xid(value,
20490 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
20491 +                       limit, vlimit_name[lim], lim, (long)value);
20492 +       }
20493 +}
20494 +
20495 diff -NurpP --minimal linux-3.0-rc5/kernel/vserver/limit_proc.h linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/limit_proc.h
20496 --- linux-3.0-rc5/kernel/vserver/limit_proc.h   1970-01-01 01:00:00.000000000 +0100
20497 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/limit_proc.h      2011-06-10 22:11:24.000000000 +0200
20498 @@ -0,0 +1,57 @@
20499 +#ifndef _VX_LIMIT_PROC_H
20500 +#define _VX_LIMIT_PROC_H
20501 +
20502 +#include <linux/vserver/limit_int.h>
20503 +
20504 +
20505 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
20506 +#define VX_LIMIT_TOP   \
20507 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
20508 +
20509 +#define VX_LIMIT_ARG(r)                                \
20510 +       (unsigned long)__rlim_get(limit, r),    \
20511 +       (unsigned long)__rlim_rmin(limit, r),   \
20512 +       (unsigned long)__rlim_rmax(limit, r),   \
20513 +       VX_VLIM(__rlim_soft(limit, r)),         \
20514 +       VX_VLIM(__rlim_hard(limit, r)),         \
20515 +       atomic_read(&__rlim_lhit(limit, r))
20516 +
20517 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
20518 +{
20519 +       vx_limit_fixup(limit, -1);
20520 +       return sprintf(buffer, VX_LIMIT_TOP
20521 +               "PROC"  VX_LIMIT_FMT
20522 +               "VM"    VX_LIMIT_FMT
20523 +               "VML"   VX_LIMIT_FMT
20524 +               "RSS"   VX_LIMIT_FMT
20525 +               "ANON"  VX_LIMIT_FMT
20526 +               "RMAP"  VX_LIMIT_FMT
20527 +               "FILES" VX_LIMIT_FMT
20528 +               "OFD"   VX_LIMIT_FMT
20529 +               "LOCKS" VX_LIMIT_FMT
20530 +               "SOCK"  VX_LIMIT_FMT
20531 +               "MSGQ"  VX_LIMIT_FMT
20532 +               "SHM"   VX_LIMIT_FMT
20533 +               "SEMA"  VX_LIMIT_FMT
20534 +               "SEMS"  VX_LIMIT_FMT
20535 +               "DENT"  VX_LIMIT_FMT,
20536 +               VX_LIMIT_ARG(RLIMIT_NPROC),
20537 +               VX_LIMIT_ARG(RLIMIT_AS),
20538 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
20539 +               VX_LIMIT_ARG(RLIMIT_RSS),
20540 +               VX_LIMIT_ARG(VLIMIT_ANON),
20541 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
20542 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
20543 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
20544 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
20545 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
20546 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
20547 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
20548 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
20549 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
20550 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
20551 +}
20552 +
20553 +#endif /* _VX_LIMIT_PROC_H */
20554 +
20555 +
20556 diff -NurpP --minimal linux-3.0-rc5/kernel/vserver/network.c linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/network.c
20557 --- linux-3.0-rc5/kernel/vserver/network.c      1970-01-01 01:00:00.000000000 +0100
20558 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/network.c 2011-06-10 23:20:56.000000000 +0200
20559 @@ -0,0 +1,912 @@
20560 +/*
20561 + *  linux/kernel/vserver/network.c
20562 + *
20563 + *  Virtual Server: Network Support
20564 + *
20565 + *  Copyright (C) 2003-2007  Herbert Pötzl
20566 + *
20567 + *  V0.01  broken out from vcontext V0.05
20568 + *  V0.02  cleaned up implementation
20569 + *  V0.03  added equiv nx commands
20570 + *  V0.04  switch to RCU based hash
20571 + *  V0.05  and back to locking again
20572 + *  V0.06  changed vcmds to nxi arg
20573 + *  V0.07  have __create claim() the nxi
20574 + *
20575 + */
20576 +
20577 +#include <linux/err.h>
20578 +#include <linux/slab.h>
20579 +#include <linux/rcupdate.h>
20580 +
20581 +#include <linux/vs_network.h>
20582 +#include <linux/vs_pid.h>
20583 +#include <linux/vserver/network_cmd.h>
20584 +
20585 +
20586 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
20587 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
20588 +
20589 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
20590 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
20591 +
20592 +
20593 +static int __init init_network(void)
20594 +{
20595 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
20596 +               sizeof(struct nx_addr_v4), 0,
20597 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20598 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
20599 +               sizeof(struct nx_addr_v6), 0,
20600 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20601 +       return 0;
20602 +}
20603 +
20604 +
20605 +/*     __alloc_nx_addr_v4()                                    */
20606 +
20607 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
20608 +{
20609 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
20610 +               nx_addr_v4_cachep, GFP_KERNEL);
20611 +
20612 +       if (!IS_ERR(nxa))
20613 +               memset(nxa, 0, sizeof(*nxa));
20614 +       return nxa;
20615 +}
20616 +
20617 +/*     __dealloc_nx_addr_v4()                                  */
20618 +
20619 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
20620 +{
20621 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
20622 +}
20623 +
20624 +/*     __dealloc_nx_addr_v4_all()                              */
20625 +
20626 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
20627 +{
20628 +       while (nxa) {
20629 +               struct nx_addr_v4 *next = nxa->next;
20630 +
20631 +               __dealloc_nx_addr_v4(nxa);
20632 +               nxa = next;
20633 +       }
20634 +}
20635 +
20636 +
20637 +#ifdef CONFIG_IPV6
20638 +
20639 +/*     __alloc_nx_addr_v6()                                    */
20640 +
20641 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
20642 +{
20643 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
20644 +               nx_addr_v6_cachep, GFP_KERNEL);
20645 +
20646 +       if (!IS_ERR(nxa))
20647 +               memset(nxa, 0, sizeof(*nxa));
20648 +       return nxa;
20649 +}
20650 +
20651 +/*     __dealloc_nx_addr_v6()                                  */
20652 +
20653 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
20654 +{
20655 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
20656 +}
20657 +
20658 +/*     __dealloc_nx_addr_v6_all()                              */
20659 +
20660 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
20661 +{
20662 +       while (nxa) {
20663 +               struct nx_addr_v6 *next = nxa->next;
20664 +
20665 +               __dealloc_nx_addr_v6(nxa);
20666 +               nxa = next;
20667 +       }
20668 +}
20669 +
20670 +#endif /* CONFIG_IPV6 */
20671 +
20672 +/*     __alloc_nx_info()
20673 +
20674 +       * allocate an initialized nx_info struct
20675 +       * doesn't make it visible (hash)                        */
20676 +
20677 +static struct nx_info *__alloc_nx_info(nid_t nid)
20678 +{
20679 +       struct nx_info *new = NULL;
20680 +
20681 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
20682 +
20683 +       /* would this benefit from a slab cache? */
20684 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
20685 +       if (!new)
20686 +               return 0;
20687 +
20688 +       memset(new, 0, sizeof(struct nx_info));
20689 +       new->nx_id = nid;
20690 +       INIT_HLIST_NODE(&new->nx_hlist);
20691 +       atomic_set(&new->nx_usecnt, 0);
20692 +       atomic_set(&new->nx_tasks, 0);
20693 +       new->nx_state = 0;
20694 +
20695 +       new->nx_flags = NXF_INIT_SET;
20696 +
20697 +       /* rest of init goes here */
20698 +
20699 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
20700 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
20701 +
20702 +       vxdprintk(VXD_CBIT(nid, 0),
20703 +               "alloc_nx_info(%d) = %p", nid, new);
20704 +       atomic_inc(&nx_global_ctotal);
20705 +       return new;
20706 +}
20707 +
20708 +/*     __dealloc_nx_info()
20709 +
20710 +       * final disposal of nx_info                             */
20711 +
20712 +static void __dealloc_nx_info(struct nx_info *nxi)
20713 +{
20714 +       vxdprintk(VXD_CBIT(nid, 0),
20715 +               "dealloc_nx_info(%p)", nxi);
20716 +
20717 +       nxi->nx_hlist.next = LIST_POISON1;
20718 +       nxi->nx_id = -1;
20719 +
20720 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20721 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20722 +
20723 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
20724 +
20725 +       nxi->nx_state |= NXS_RELEASED;
20726 +       kfree(nxi);
20727 +       atomic_dec(&nx_global_ctotal);
20728 +}
20729 +
20730 +static void __shutdown_nx_info(struct nx_info *nxi)
20731 +{
20732 +       nxi->nx_state |= NXS_SHUTDOWN;
20733 +       vs_net_change(nxi, VSC_NETDOWN);
20734 +}
20735 +
20736 +/*     exported stuff                                          */
20737 +
20738 +void free_nx_info(struct nx_info *nxi)
20739 +{
20740 +       /* context shutdown is mandatory */
20741 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
20742 +
20743 +       /* context must not be hashed */
20744 +       BUG_ON(nxi->nx_state & NXS_HASHED);
20745 +
20746 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20747 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20748 +
20749 +       __dealloc_nx_info(nxi);
20750 +}
20751 +
20752 +
20753 +void __nx_set_lback(struct nx_info *nxi)
20754 +{
20755 +       int nid = nxi->nx_id;
20756 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
20757 +
20758 +       nxi->v4_lback.s_addr = lback;
20759 +}
20760 +
20761 +extern int __nx_inet_add_lback(__be32 addr);
20762 +extern int __nx_inet_del_lback(__be32 addr);
20763 +
20764 +
20765 +/*     hash table for nx_info hash */
20766 +
20767 +#define NX_HASH_SIZE   13
20768 +
20769 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
20770 +
20771 +static DEFINE_SPINLOCK(nx_info_hash_lock);
20772 +
20773 +
20774 +static inline unsigned int __hashval(nid_t nid)
20775 +{
20776 +       return (nid % NX_HASH_SIZE);
20777 +}
20778 +
20779 +
20780 +
20781 +/*     __hash_nx_info()
20782 +
20783 +       * add the nxi to the global hash table
20784 +       * requires the hash_lock to be held                     */
20785 +
20786 +static inline void __hash_nx_info(struct nx_info *nxi)
20787 +{
20788 +       struct hlist_head *head;
20789 +
20790 +       vxd_assert_lock(&nx_info_hash_lock);
20791 +       vxdprintk(VXD_CBIT(nid, 4),
20792 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
20793 +
20794 +       /* context must not be hashed */
20795 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
20796 +
20797 +       nxi->nx_state |= NXS_HASHED;
20798 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
20799 +       hlist_add_head(&nxi->nx_hlist, head);
20800 +       atomic_inc(&nx_global_cactive);
20801 +}
20802 +
20803 +/*     __unhash_nx_info()
20804 +
20805 +       * remove the nxi from the global hash table
20806 +       * requires the hash_lock to be held                     */
20807 +
20808 +static inline void __unhash_nx_info(struct nx_info *nxi)
20809 +{
20810 +       vxd_assert_lock(&nx_info_hash_lock);
20811 +       vxdprintk(VXD_CBIT(nid, 4),
20812 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
20813 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
20814 +
20815 +       /* context must be hashed */
20816 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
20817 +       /* but without tasks */
20818 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20819 +
20820 +       nxi->nx_state &= ~NXS_HASHED;
20821 +       hlist_del(&nxi->nx_hlist);
20822 +       atomic_dec(&nx_global_cactive);
20823 +}
20824 +
20825 +
20826 +/*     __lookup_nx_info()
20827 +
20828 +       * requires the hash_lock to be held
20829 +       * doesn't increment the nx_refcnt                       */
20830 +
20831 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
20832 +{
20833 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
20834 +       struct hlist_node *pos;
20835 +       struct nx_info *nxi;
20836 +
20837 +       vxd_assert_lock(&nx_info_hash_lock);
20838 +       hlist_for_each(pos, head) {
20839 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20840 +
20841 +               if (nxi->nx_id == nid)
20842 +                       goto found;
20843 +       }
20844 +       nxi = NULL;
20845 +found:
20846 +       vxdprintk(VXD_CBIT(nid, 0),
20847 +               "__lookup_nx_info(#%u): %p[#%u]",
20848 +               nid, nxi, nxi ? nxi->nx_id : 0);
20849 +       return nxi;
20850 +}
20851 +
20852 +
20853 +/*     __create_nx_info()
20854 +
20855 +       * create the requested context
20856 +       * get(), claim() and hash it                            */
20857 +
20858 +static struct nx_info *__create_nx_info(int id)
20859 +{
20860 +       struct nx_info *new, *nxi = NULL;
20861 +
20862 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
20863 +
20864 +       if (!(new = __alloc_nx_info(id)))
20865 +               return ERR_PTR(-ENOMEM);
20866 +
20867 +       /* required to make dynamic xids unique */
20868 +       spin_lock(&nx_info_hash_lock);
20869 +
20870 +       /* static context requested */
20871 +       if ((nxi = __lookup_nx_info(id))) {
20872 +               vxdprintk(VXD_CBIT(nid, 0),
20873 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
20874 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20875 +                       nxi = ERR_PTR(-EBUSY);
20876 +               else
20877 +                       nxi = ERR_PTR(-EEXIST);
20878 +               goto out_unlock;
20879 +       }
20880 +       /* new context */
20881 +       vxdprintk(VXD_CBIT(nid, 0),
20882 +               "create_nx_info(%d) = %p (new)", id, new);
20883 +       claim_nx_info(new, NULL);
20884 +       __nx_set_lback(new);
20885 +       __hash_nx_info(get_nx_info(new));
20886 +       nxi = new, new = NULL;
20887 +
20888 +out_unlock:
20889 +       spin_unlock(&nx_info_hash_lock);
20890 +       if (new)
20891 +               __dealloc_nx_info(new);
20892 +       return nxi;
20893 +}
20894 +
20895 +
20896 +
20897 +/*     exported stuff                                          */
20898 +
20899 +
20900 +void unhash_nx_info(struct nx_info *nxi)
20901 +{
20902 +       __shutdown_nx_info(nxi);
20903 +       spin_lock(&nx_info_hash_lock);
20904 +       __unhash_nx_info(nxi);
20905 +       spin_unlock(&nx_info_hash_lock);
20906 +}
20907 +
20908 +/*     lookup_nx_info()
20909 +
20910 +       * search for a nx_info and get() it
20911 +       * negative id means current                             */
20912 +
20913 +struct nx_info *lookup_nx_info(int id)
20914 +{
20915 +       struct nx_info *nxi = NULL;
20916 +
20917 +       if (id < 0) {
20918 +               nxi = get_nx_info(current_nx_info());
20919 +       } else if (id > 1) {
20920 +               spin_lock(&nx_info_hash_lock);
20921 +               nxi = get_nx_info(__lookup_nx_info(id));
20922 +               spin_unlock(&nx_info_hash_lock);
20923 +       }
20924 +       return nxi;
20925 +}
20926 +
20927 +/*     nid_is_hashed()
20928 +
20929 +       * verify that nid is still hashed                       */
20930 +
20931 +int nid_is_hashed(nid_t nid)
20932 +{
20933 +       int hashed;
20934 +
20935 +       spin_lock(&nx_info_hash_lock);
20936 +       hashed = (__lookup_nx_info(nid) != NULL);
20937 +       spin_unlock(&nx_info_hash_lock);
20938 +       return hashed;
20939 +}
20940 +
20941 +
20942 +#ifdef CONFIG_PROC_FS
20943 +
20944 +/*     get_nid_list()
20945 +
20946 +       * get a subset of hashed nids for proc
20947 +       * assumes size is at least one                          */
20948 +
20949 +int get_nid_list(int index, unsigned int *nids, int size)
20950 +{
20951 +       int hindex, nr_nids = 0;
20952 +
20953 +       /* only show current and children */
20954 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
20955 +               if (index > 0)
20956 +                       return 0;
20957 +               nids[nr_nids] = nx_current_nid();
20958 +               return 1;
20959 +       }
20960 +
20961 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
20962 +               struct hlist_head *head = &nx_info_hash[hindex];
20963 +               struct hlist_node *pos;
20964 +
20965 +               spin_lock(&nx_info_hash_lock);
20966 +               hlist_for_each(pos, head) {
20967 +                       struct nx_info *nxi;
20968 +
20969 +                       if (--index > 0)
20970 +                               continue;
20971 +
20972 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20973 +                       nids[nr_nids] = nxi->nx_id;
20974 +                       if (++nr_nids >= size) {
20975 +                               spin_unlock(&nx_info_hash_lock);
20976 +                               goto out;
20977 +                       }
20978 +               }
20979 +               /* keep the lock time short */
20980 +               spin_unlock(&nx_info_hash_lock);
20981 +       }
20982 +out:
20983 +       return nr_nids;
20984 +}
20985 +#endif
20986 +
20987 +
20988 +/*
20989 + *     migrate task to new network
20990 + *     gets nxi, puts old_nxi on change
20991 + */
20992 +
20993 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
20994 +{
20995 +       struct nx_info *old_nxi;
20996 +       int ret = 0;
20997 +
20998 +       if (!p || !nxi)
20999 +               BUG();
21000 +
21001 +       vxdprintk(VXD_CBIT(nid, 5),
21002 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
21003 +               p, nxi, nxi->nx_id,
21004 +               atomic_read(&nxi->nx_usecnt),
21005 +               atomic_read(&nxi->nx_tasks));
21006 +
21007 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
21008 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
21009 +               return -EACCES;
21010 +
21011 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
21012 +               return -EFAULT;
21013 +
21014 +       /* maybe disallow this completely? */
21015 +       old_nxi = task_get_nx_info(p);
21016 +       if (old_nxi == nxi)
21017 +               goto out;
21018 +
21019 +       task_lock(p);
21020 +       if (old_nxi)
21021 +               clr_nx_info(&p->nx_info);
21022 +       claim_nx_info(nxi, p);
21023 +       set_nx_info(&p->nx_info, nxi);
21024 +       p->nid = nxi->nx_id;
21025 +       task_unlock(p);
21026 +
21027 +       vxdprintk(VXD_CBIT(nid, 5),
21028 +               "moved task %p into nxi:%p[#%d]",
21029 +               p, nxi, nxi->nx_id);
21030 +
21031 +       if (old_nxi)
21032 +               release_nx_info(old_nxi, p);
21033 +       ret = 0;
21034 +out:
21035 +       put_nx_info(old_nxi);
21036 +       return ret;
21037 +}
21038 +
21039 +
21040 +void nx_set_persistent(struct nx_info *nxi)
21041 +{
21042 +       vxdprintk(VXD_CBIT(nid, 6),
21043 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
21044 +
21045 +       get_nx_info(nxi);
21046 +       claim_nx_info(nxi, NULL);
21047 +}
21048 +
21049 +void nx_clear_persistent(struct nx_info *nxi)
21050 +{
21051 +       vxdprintk(VXD_CBIT(nid, 6),
21052 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
21053 +
21054 +       release_nx_info(nxi, NULL);
21055 +       put_nx_info(nxi);
21056 +}
21057 +
21058 +void nx_update_persistent(struct nx_info *nxi)
21059 +{
21060 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
21061 +               nx_set_persistent(nxi);
21062 +       else
21063 +               nx_clear_persistent(nxi);
21064 +}
21065 +
21066 +/* vserver syscall commands below here */
21067 +
21068 +/* taks nid and nx_info functions */
21069 +
21070 +#include <asm/uaccess.h>
21071 +
21072 +
21073 +int vc_task_nid(uint32_t id)
21074 +{
21075 +       nid_t nid;
21076 +
21077 +       if (id) {
21078 +               struct task_struct *tsk;
21079 +
21080 +               rcu_read_lock();
21081 +               tsk = find_task_by_real_pid(id);
21082 +               nid = (tsk) ? tsk->nid : -ESRCH;
21083 +               rcu_read_unlock();
21084 +       } else
21085 +               nid = nx_current_nid();
21086 +       return nid;
21087 +}
21088 +
21089 +
21090 +int vc_nx_info(struct nx_info *nxi, void __user *data)
21091 +{
21092 +       struct vcmd_nx_info_v0 vc_data;
21093 +
21094 +       vc_data.nid = nxi->nx_id;
21095 +
21096 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21097 +               return -EFAULT;
21098 +       return 0;
21099 +}
21100 +
21101 +
21102 +/* network functions */
21103 +
21104 +int vc_net_create(uint32_t nid, void __user *data)
21105 +{
21106 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
21107 +       struct nx_info *new_nxi;
21108 +       int ret;
21109 +
21110 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21111 +               return -EFAULT;
21112 +
21113 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
21114 +               return -EINVAL;
21115 +
21116 +       new_nxi = __create_nx_info(nid);
21117 +       if (IS_ERR(new_nxi))
21118 +               return PTR_ERR(new_nxi);
21119 +
21120 +       /* initial flags */
21121 +       new_nxi->nx_flags = vc_data.flagword;
21122 +
21123 +       ret = -ENOEXEC;
21124 +       if (vs_net_change(new_nxi, VSC_NETUP))
21125 +               goto out;
21126 +
21127 +       ret = nx_migrate_task(current, new_nxi);
21128 +       if (ret)
21129 +               goto out;
21130 +
21131 +       /* return context id on success */
21132 +       ret = new_nxi->nx_id;
21133 +
21134 +       /* get a reference for persistent contexts */
21135 +       if ((vc_data.flagword & NXF_PERSISTENT))
21136 +               nx_set_persistent(new_nxi);
21137 +out:
21138 +       release_nx_info(new_nxi, NULL);
21139 +       put_nx_info(new_nxi);
21140 +       return ret;
21141 +}
21142 +
21143 +
21144 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
21145 +{
21146 +       return nx_migrate_task(current, nxi);
21147 +}
21148 +
21149 +
21150 +
21151 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
21152 +       uint16_t type, uint16_t flags)
21153 +{
21154 +       struct nx_addr_v4 *nxa = &nxi->v4;
21155 +
21156 +       if (NX_IPV4(nxi)) {
21157 +               /* locate last entry */
21158 +               for (; nxa->next; nxa = nxa->next);
21159 +               nxa->next = __alloc_nx_addr_v4();
21160 +               nxa = nxa->next;
21161 +
21162 +               if (IS_ERR(nxa))
21163 +                       return PTR_ERR(nxa);
21164 +       }
21165 +
21166 +       if (nxi->v4.next)
21167 +               /* remove single ip for ip list */
21168 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
21169 +
21170 +       nxa->ip[0].s_addr = ip;
21171 +       nxa->ip[1].s_addr = ip2;
21172 +       nxa->mask.s_addr = mask;
21173 +       nxa->type = type;
21174 +       nxa->flags = flags;
21175 +       return 0;
21176 +}
21177 +
21178 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
21179 +       uint16_t type, uint16_t flags)
21180 +{
21181 +       struct nx_addr_v4 *nxa = &nxi->v4;
21182 +
21183 +       switch (type) {
21184 +/*     case NXA_TYPE_ADDR:
21185 +               break;          */
21186 +
21187 +       case NXA_TYPE_ANY:
21188 +               __dealloc_nx_addr_v4_all(xchg(&nxa->next, NULL));
21189 +               memset(nxa, 0, sizeof(*nxa));
21190 +               break;
21191 +
21192 +       default:
21193 +               return -EINVAL;
21194 +       }
21195 +       return 0;
21196 +}
21197 +
21198 +
21199 +int vc_net_add(struct nx_info *nxi, void __user *data)
21200 +{
21201 +       struct vcmd_net_addr_v0 vc_data;
21202 +       int index, ret = 0;
21203 +
21204 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21205 +               return -EFAULT;
21206 +
21207 +       switch (vc_data.type) {
21208 +       case NXA_TYPE_IPV4:
21209 +               if ((vc_data.count < 1) || (vc_data.count > 4))
21210 +                       return -EINVAL;
21211 +
21212 +               index = 0;
21213 +               while (index < vc_data.count) {
21214 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
21215 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
21216 +                       if (ret)
21217 +                               return ret;
21218 +                       index++;
21219 +               }
21220 +               ret = index;
21221 +               break;
21222 +
21223 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
21224 +               nxi->v4_bcast = vc_data.ip[0];
21225 +               ret = 1;
21226 +               break;
21227 +
21228 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
21229 +               nxi->v4_lback = vc_data.ip[0];
21230 +               ret = 1;
21231 +               break;
21232 +
21233 +       default:
21234 +               ret = -EINVAL;
21235 +               break;
21236 +       }
21237 +       return ret;
21238 +}
21239 +
21240 +int vc_net_remove(struct nx_info *nxi, void __user *data)
21241 +{
21242 +       struct vcmd_net_addr_v0 vc_data;
21243 +
21244 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21245 +               return -EFAULT;
21246 +
21247 +       switch (vc_data.type) {
21248 +       case NXA_TYPE_ANY:
21249 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
21250 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
21251 +               break;
21252 +
21253 +       default:
21254 +               return -EINVAL;
21255 +       }
21256 +       return 0;
21257 +}
21258 +
21259 +
21260 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
21261 +{
21262 +       struct vcmd_net_addr_ipv4_v1 vc_data;
21263 +
21264 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21265 +               return -EFAULT;
21266 +
21267 +       switch (vc_data.type) {
21268 +       case NXA_TYPE_ADDR:
21269 +       case NXA_TYPE_MASK:
21270 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
21271 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
21272 +
21273 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
21274 +               nxi->v4_bcast = vc_data.ip;
21275 +               break;
21276 +
21277 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
21278 +               nxi->v4_lback = vc_data.ip;
21279 +               break;
21280 +
21281 +       default:
21282 +               return -EINVAL;
21283 +       }
21284 +       return 0;
21285 +}
21286 +
21287 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
21288 +{
21289 +       struct vcmd_net_addr_ipv4_v2 vc_data;
21290 +
21291 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21292 +               return -EFAULT;
21293 +
21294 +       switch (vc_data.type) {
21295 +       case NXA_TYPE_ADDR:
21296 +       case NXA_TYPE_MASK:
21297 +       case NXA_TYPE_RANGE:
21298 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
21299 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
21300 +
21301 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
21302 +               nxi->v4_bcast = vc_data.ip;
21303 +               break;
21304 +
21305 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
21306 +               nxi->v4_lback = vc_data.ip;
21307 +               break;
21308 +
21309 +       default:
21310 +               return -EINVAL;
21311 +       }
21312 +       return 0;
21313 +}
21314 +
21315 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
21316 +{
21317 +       struct vcmd_net_addr_ipv4_v1 vc_data;
21318 +
21319 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21320 +               return -EFAULT;
21321 +
21322 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
21323 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
21324 +}
21325 +
21326 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
21327 +{
21328 +       struct vcmd_net_addr_ipv4_v2 vc_data;
21329 +
21330 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21331 +               return -EFAULT;
21332 +
21333 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
21334 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
21335 +}
21336 +
21337 +#ifdef CONFIG_IPV6
21338 +
21339 +int do_add_v6_addr(struct nx_info *nxi,
21340 +       struct in6_addr *ip, struct in6_addr *mask,
21341 +       uint32_t prefix, uint16_t type, uint16_t flags)
21342 +{
21343 +       struct nx_addr_v6 *nxa = &nxi->v6;
21344 +
21345 +       if (NX_IPV6(nxi)) {
21346 +               /* locate last entry */
21347 +               for (; nxa->next; nxa = nxa->next);
21348 +               nxa->next = __alloc_nx_addr_v6();
21349 +               nxa = nxa->next;
21350 +
21351 +               if (IS_ERR(nxa))
21352 +                       return PTR_ERR(nxa);
21353 +       }
21354 +
21355 +       nxa->ip = *ip;
21356 +       nxa->mask = *mask;
21357 +       nxa->prefix = prefix;
21358 +       nxa->type = type;
21359 +       nxa->flags = flags;
21360 +       return 0;
21361 +}
21362 +
21363 +
21364 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
21365 +{
21366 +       struct vcmd_net_addr_ipv6_v1 vc_data;
21367 +
21368 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21369 +               return -EFAULT;
21370 +
21371 +       switch (vc_data.type) {
21372 +       case NXA_TYPE_ADDR:
21373 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
21374 +               /* fallthrough */
21375 +       case NXA_TYPE_MASK:
21376 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
21377 +                       vc_data.prefix, vc_data.type, vc_data.flags);
21378 +       default:
21379 +               return -EINVAL;
21380 +       }
21381 +       return 0;
21382 +}
21383 +
21384 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
21385 +{
21386 +       struct vcmd_net_addr_ipv6_v1 vc_data;
21387 +
21388 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21389 +               return -EFAULT;
21390 +
21391 +       switch (vc_data.type) {
21392 +       case NXA_TYPE_ANY:
21393 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
21394 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
21395 +               break;
21396 +
21397 +       default:
21398 +               return -EINVAL;
21399 +       }
21400 +       return 0;
21401 +}
21402 +
21403 +#endif /* CONFIG_IPV6 */
21404 +
21405 +
21406 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
21407 +{
21408 +       struct vcmd_net_flags_v0 vc_data;
21409 +
21410 +       vc_data.flagword = nxi->nx_flags;
21411 +
21412 +       /* special STATE flag handling */
21413 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
21414 +
21415 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21416 +               return -EFAULT;
21417 +       return 0;
21418 +}
21419 +
21420 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
21421 +{
21422 +       struct vcmd_net_flags_v0 vc_data;
21423 +       uint64_t mask, trigger;
21424 +
21425 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21426 +               return -EFAULT;
21427 +
21428 +       /* special STATE flag handling */
21429 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
21430 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
21431 +
21432 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
21433 +               vc_data.flagword, mask);
21434 +       if (trigger & NXF_PERSISTENT)
21435 +               nx_update_persistent(nxi);
21436 +
21437 +       return 0;
21438 +}
21439 +
21440 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
21441 +{
21442 +       struct vcmd_net_caps_v0 vc_data;
21443 +
21444 +       vc_data.ncaps = nxi->nx_ncaps;
21445 +       vc_data.cmask = ~0ULL;
21446 +
21447 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21448 +               return -EFAULT;
21449 +       return 0;
21450 +}
21451 +
21452 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
21453 +{
21454 +       struct vcmd_net_caps_v0 vc_data;
21455 +
21456 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21457 +               return -EFAULT;
21458 +
21459 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
21460 +               vc_data.ncaps, vc_data.cmask);
21461 +       return 0;
21462 +}
21463 +
21464 +
21465 +#include <linux/module.h>
21466 +
21467 +module_init(init_network);
21468 +
21469 +EXPORT_SYMBOL_GPL(free_nx_info);
21470 +EXPORT_SYMBOL_GPL(unhash_nx_info);
21471 +
21472 diff -NurpP --minimal linux-3.0-rc5/kernel/vserver/proc.c linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/proc.c
21473 --- linux-3.0-rc5/kernel/vserver/proc.c 1970-01-01 01:00:00.000000000 +0100
21474 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/proc.c    2011-06-10 22:11:24.000000000 +0200
21475 @@ -0,0 +1,1100 @@
21476 +/*
21477 + *  linux/kernel/vserver/proc.c
21478 + *
21479 + *  Virtual Context Support
21480 + *
21481 + *  Copyright (C) 2003-2007  Herbert Pötzl
21482 + *
21483 + *  V0.01  basic structure
21484 + *  V0.02  adaptation vs1.3.0
21485 + *  V0.03  proc permissions
21486 + *  V0.04  locking/generic
21487 + *  V0.05  next generation procfs
21488 + *  V0.06  inode validation
21489 + *  V0.07  generic rewrite vid
21490 + *  V0.08  remove inode type
21491 + *
21492 + */
21493 +
21494 +#include <linux/proc_fs.h>
21495 +#include <linux/fs_struct.h>
21496 +#include <linux/mount.h>
21497 +#include <asm/unistd.h>
21498 +
21499 +#include <linux/vs_context.h>
21500 +#include <linux/vs_network.h>
21501 +#include <linux/vs_cvirt.h>
21502 +
21503 +#include <linux/in.h>
21504 +#include <linux/inetdevice.h>
21505 +#include <linux/vs_inet.h>
21506 +#include <linux/vs_inet6.h>
21507 +
21508 +#include <linux/vserver/global.h>
21509 +
21510 +#include "cvirt_proc.h"
21511 +#include "cacct_proc.h"
21512 +#include "limit_proc.h"
21513 +#include "sched_proc.h"
21514 +#include "vci_config.h"
21515 +
21516 +
21517 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
21518 +{
21519 +       unsigned __capi;
21520 +
21521 +       CAP_FOR_EACH_U32(__capi) {
21522 +               buffer += sprintf(buffer, "%08x",
21523 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
21524 +       }
21525 +       return buffer;
21526 +}
21527 +
21528 +
21529 +static struct proc_dir_entry *proc_virtual;
21530 +
21531 +static struct proc_dir_entry *proc_virtnet;
21532 +
21533 +
21534 +/* first the actual feeds */
21535 +
21536 +
21537 +static int proc_vci(char *buffer)
21538 +{
21539 +       return sprintf(buffer,
21540 +               "VCIVersion:\t%04x:%04x\n"
21541 +               "VCISyscall:\t%d\n"
21542 +               "VCIKernel:\t%08x\n",
21543 +               VCI_VERSION >> 16,
21544 +               VCI_VERSION & 0xFFFF,
21545 +               __NR_vserver,
21546 +               vci_kernel_config());
21547 +}
21548 +
21549 +static int proc_virtual_info(char *buffer)
21550 +{
21551 +       return proc_vci(buffer);
21552 +}
21553 +
21554 +static int proc_virtual_status(char *buffer)
21555 +{
21556 +       return sprintf(buffer,
21557 +               "#CTotal:\t%d\n"
21558 +               "#CActive:\t%d\n"
21559 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
21560 +               "#InitTask:\t%d\t%d %d\n",
21561 +               atomic_read(&vx_global_ctotal),
21562 +               atomic_read(&vx_global_cactive),
21563 +               atomic_read(&vs_global_nsproxy),
21564 +               atomic_read(&vs_global_fs),
21565 +               atomic_read(&vs_global_mnt_ns),
21566 +               atomic_read(&vs_global_uts_ns),
21567 +               atomic_read(&nr_ipc_ns),
21568 +               atomic_read(&vs_global_user_ns),
21569 +               atomic_read(&vs_global_pid_ns),
21570 +               atomic_read(&init_task.usage),
21571 +               atomic_read(&init_task.nsproxy->count),
21572 +               init_task.fs->users);
21573 +}
21574 +
21575 +
21576 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
21577 +{
21578 +       int length;
21579 +
21580 +       length = sprintf(buffer,
21581 +               "ID:\t%d\n"
21582 +               "Info:\t%p\n"
21583 +               "Init:\t%d\n"
21584 +               "OOM:\t%lld\n",
21585 +               vxi->vx_id,
21586 +               vxi,
21587 +               vxi->vx_initpid,
21588 +               vxi->vx_badness_bias);
21589 +       return length;
21590 +}
21591 +
21592 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
21593 +{
21594 +       char *orig = buffer;
21595 +
21596 +       buffer += sprintf(buffer,
21597 +               "UseCnt:\t%d\n"
21598 +               "Tasks:\t%d\n"
21599 +               "Flags:\t%016llx\n",
21600 +               atomic_read(&vxi->vx_usecnt),
21601 +               atomic_read(&vxi->vx_tasks),
21602 +               (unsigned long long)vxi->vx_flags);
21603 +
21604 +       buffer += sprintf(buffer, "BCaps:\t");
21605 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21606 +       buffer += sprintf(buffer, "\n");
21607 +
21608 +       buffer += sprintf(buffer,
21609 +               "CCaps:\t%016llx\n"
21610 +               "Umask:\t%16llx\n"
21611 +               "Spaces:\t%08lx %08lx\n",
21612 +               (unsigned long long)vxi->vx_ccaps,
21613 +               (unsigned long long)vxi->vx_umask,
21614 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
21615 +       return buffer - orig;
21616 +}
21617 +
21618 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
21619 +{
21620 +       return vx_info_proc_limit(&vxi->limit, buffer);
21621 +}
21622 +
21623 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
21624 +{
21625 +       int cpu, length;
21626 +
21627 +       length = vx_info_proc_sched(&vxi->sched, buffer);
21628 +       for_each_online_cpu(cpu) {
21629 +               length += vx_info_proc_sched_pc(
21630 +                       &vx_per_cpu(vxi, sched_pc, cpu),
21631 +                       buffer + length, cpu);
21632 +       }
21633 +       return length;
21634 +}
21635 +
21636 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
21637 +{
21638 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
21639 +}
21640 +
21641 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
21642 +{
21643 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
21644 +}
21645 +
21646 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
21647 +{
21648 +       int cpu, length;
21649 +
21650 +       vx_update_load(vxi);
21651 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
21652 +       for_each_online_cpu(cpu) {
21653 +               length += vx_info_proc_cvirt_pc(
21654 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
21655 +                       buffer + length, cpu);
21656 +       }
21657 +       return length;
21658 +}
21659 +
21660 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
21661 +{
21662 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
21663 +}
21664 +
21665 +
21666 +static int proc_virtnet_info(char *buffer)
21667 +{
21668 +       return proc_vci(buffer);
21669 +}
21670 +
21671 +static int proc_virtnet_status(char *buffer)
21672 +{
21673 +       return sprintf(buffer,
21674 +               "#CTotal:\t%d\n"
21675 +               "#CActive:\t%d\n",
21676 +               atomic_read(&nx_global_ctotal),
21677 +               atomic_read(&nx_global_cactive));
21678 +}
21679 +
21680 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
21681 +{
21682 +       struct nx_addr_v4 *v4a;
21683 +#ifdef CONFIG_IPV6
21684 +       struct nx_addr_v6 *v6a;
21685 +#endif
21686 +       int length, i;
21687 +
21688 +       length = sprintf(buffer,
21689 +               "ID:\t%d\n"
21690 +               "Info:\t%p\n"
21691 +               "Bcast:\t" NIPQUAD_FMT "\n"
21692 +               "Lback:\t" NIPQUAD_FMT "\n",
21693 +               nxi->nx_id,
21694 +               nxi,
21695 +               NIPQUAD(nxi->v4_bcast.s_addr),
21696 +               NIPQUAD(nxi->v4_lback.s_addr));
21697 +
21698 +       if (!NX_IPV4(nxi))
21699 +               goto skip_v4;
21700 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21701 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
21702 +                       i, NXAV4(v4a));
21703 +skip_v4:
21704 +#ifdef CONFIG_IPV6
21705 +       if (!NX_IPV6(nxi))
21706 +               goto skip_v6;
21707 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21708 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
21709 +                       i, NXAV6(v6a));
21710 +skip_v6:
21711 +#endif
21712 +       return length;
21713 +}
21714 +
21715 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
21716 +{
21717 +       int length;
21718 +
21719 +       length = sprintf(buffer,
21720 +               "UseCnt:\t%d\n"
21721 +               "Tasks:\t%d\n"
21722 +               "Flags:\t%016llx\n"
21723 +               "NCaps:\t%016llx\n",
21724 +               atomic_read(&nxi->nx_usecnt),
21725 +               atomic_read(&nxi->nx_tasks),
21726 +               (unsigned long long)nxi->nx_flags,
21727 +               (unsigned long long)nxi->nx_ncaps);
21728 +       return length;
21729 +}
21730 +
21731 +
21732 +
21733 +/* here the inode helpers */
21734 +
21735 +struct vs_entry {
21736 +       int len;
21737 +       char *name;
21738 +       mode_t mode;
21739 +       struct inode_operations *iop;
21740 +       struct file_operations *fop;
21741 +       union proc_op op;
21742 +};
21743 +
21744 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
21745 +{
21746 +       struct inode *inode = new_inode(sb);
21747 +
21748 +       if (!inode)
21749 +               goto out;
21750 +
21751 +       inode->i_mode = p->mode;
21752 +       if (p->iop)
21753 +               inode->i_op = p->iop;
21754 +       if (p->fop)
21755 +               inode->i_fop = p->fop;
21756 +
21757 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
21758 +       inode->i_flags |= S_IMMUTABLE;
21759 +
21760 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
21761 +
21762 +       inode->i_uid = 0;
21763 +       inode->i_gid = 0;
21764 +       inode->i_tag = 0;
21765 +out:
21766 +       return inode;
21767 +}
21768 +
21769 +static struct dentry *vs_proc_instantiate(struct inode *dir,
21770 +       struct dentry *dentry, int id, void *ptr)
21771 +{
21772 +       struct vs_entry *p = ptr;
21773 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
21774 +       struct dentry *error = ERR_PTR(-EINVAL);
21775 +
21776 +       if (!inode)
21777 +               goto out;
21778 +
21779 +       PROC_I(inode)->op = p->op;
21780 +       PROC_I(inode)->fd = id;
21781 +       d_add(dentry, inode);
21782 +       error = NULL;
21783 +out:
21784 +       return error;
21785 +}
21786 +
21787 +/* Lookups */
21788 +
21789 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
21790 +
21791 +/*
21792 + * Fill a directory entry.
21793 + *
21794 + * If possible create the dcache entry and derive our inode number and
21795 + * file type from dcache entry.
21796 + *
21797 + * Since all of the proc inode numbers are dynamically generated, the inode
21798 + * numbers do not exist until the inode is cache.  This means creating the
21799 + * the dcache entry in readdir is necessary to keep the inode numbers
21800 + * reported by readdir in sync with the inode numbers reported
21801 + * by stat.
21802 + */
21803 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
21804 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
21805 +{
21806 +       struct dentry *child, *dir = filp->f_dentry;
21807 +       struct inode *inode;
21808 +       struct qstr qname;
21809 +       ino_t ino = 0;
21810 +       unsigned type = DT_UNKNOWN;
21811 +
21812 +       qname.name = name;
21813 +       qname.len  = len;
21814 +       qname.hash = full_name_hash(name, len);
21815 +
21816 +       child = d_lookup(dir, &qname);
21817 +       if (!child) {
21818 +               struct dentry *new;
21819 +               new = d_alloc(dir, &qname);
21820 +               if (new) {
21821 +                       child = instantiate(dir->d_inode, new, id, ptr);
21822 +                       if (child)
21823 +                               dput(new);
21824 +                       else
21825 +                               child = new;
21826 +               }
21827 +       }
21828 +       if (!child || IS_ERR(child) || !child->d_inode)
21829 +               goto end_instantiate;
21830 +       inode = child->d_inode;
21831 +       if (inode) {
21832 +               ino = inode->i_ino;
21833 +               type = inode->i_mode >> 12;
21834 +       }
21835 +       dput(child);
21836 +end_instantiate:
21837 +       if (!ino)
21838 +               ino = find_inode_number(dir, &qname);
21839 +       if (!ino)
21840 +               ino = 1;
21841 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
21842 +}
21843 +
21844 +
21845 +
21846 +/* get and revalidate vx_info/xid */
21847 +
21848 +static inline
21849 +struct vx_info *get_proc_vx_info(struct inode *inode)
21850 +{
21851 +       return lookup_vx_info(PROC_I(inode)->fd);
21852 +}
21853 +
21854 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
21855 +{
21856 +       struct inode *inode = dentry->d_inode;
21857 +       xid_t xid = PROC_I(inode)->fd;
21858 +
21859 +       if (!xid || xid_is_hashed(xid))
21860 +               return 1;
21861 +       d_drop(dentry);
21862 +       return 0;
21863 +}
21864 +
21865 +
21866 +/* get and revalidate nx_info/nid */
21867 +
21868 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
21869 +{
21870 +       struct inode *inode = dentry->d_inode;
21871 +       nid_t nid = PROC_I(inode)->fd;
21872 +
21873 +       if (!nid || nid_is_hashed(nid))
21874 +               return 1;
21875 +       d_drop(dentry);
21876 +       return 0;
21877 +}
21878 +
21879 +
21880 +
21881 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
21882 +
21883 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
21884 +                         size_t count, loff_t *ppos)
21885 +{
21886 +       struct inode *inode = file->f_dentry->d_inode;
21887 +       unsigned long page;
21888 +       ssize_t length = 0;
21889 +
21890 +       if (count > PROC_BLOCK_SIZE)
21891 +               count = PROC_BLOCK_SIZE;
21892 +
21893 +       /* fade that out as soon as stable */
21894 +       WARN_ON(PROC_I(inode)->fd);
21895 +
21896 +       if (!(page = __get_free_page(GFP_KERNEL)))
21897 +               return -ENOMEM;
21898 +
21899 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
21900 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
21901 +
21902 +       if (length >= 0)
21903 +               length = simple_read_from_buffer(buf, count, ppos,
21904 +                       (char *)page, length);
21905 +
21906 +       free_page(page);
21907 +       return length;
21908 +}
21909 +
21910 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
21911 +                         size_t count, loff_t *ppos)
21912 +{
21913 +       struct inode *inode = file->f_dentry->d_inode;
21914 +       struct vx_info *vxi = NULL;
21915 +       xid_t xid = PROC_I(inode)->fd;
21916 +       unsigned long page;
21917 +       ssize_t length = 0;
21918 +
21919 +       if (count > PROC_BLOCK_SIZE)
21920 +               count = PROC_BLOCK_SIZE;
21921 +
21922 +       /* fade that out as soon as stable */
21923 +       WARN_ON(!xid);
21924 +       vxi = lookup_vx_info(xid);
21925 +       if (!vxi)
21926 +               goto out;
21927 +
21928 +       length = -ENOMEM;
21929 +       if (!(page = __get_free_page(GFP_KERNEL)))
21930 +               goto out_put;
21931 +
21932 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
21933 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
21934 +
21935 +       if (length >= 0)
21936 +               length = simple_read_from_buffer(buf, count, ppos,
21937 +                       (char *)page, length);
21938 +
21939 +       free_page(page);
21940 +out_put:
21941 +       put_vx_info(vxi);
21942 +out:
21943 +       return length;
21944 +}
21945 +
21946 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
21947 +                         size_t count, loff_t *ppos)
21948 +{
21949 +       struct inode *inode = file->f_dentry->d_inode;
21950 +       struct nx_info *nxi = NULL;
21951 +       nid_t nid = PROC_I(inode)->fd;
21952 +       unsigned long page;
21953 +       ssize_t length = 0;
21954 +
21955 +       if (count > PROC_BLOCK_SIZE)
21956 +               count = PROC_BLOCK_SIZE;
21957 +
21958 +       /* fade that out as soon as stable */
21959 +       WARN_ON(!nid);
21960 +       nxi = lookup_nx_info(nid);
21961 +       if (!nxi)
21962 +               goto out;
21963 +
21964 +       length = -ENOMEM;
21965 +       if (!(page = __get_free_page(GFP_KERNEL)))
21966 +               goto out_put;
21967 +
21968 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
21969 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
21970 +
21971 +       if (length >= 0)
21972 +               length = simple_read_from_buffer(buf, count, ppos,
21973 +                       (char *)page, length);
21974 +
21975 +       free_page(page);
21976 +out_put:
21977 +       put_nx_info(nxi);
21978 +out:
21979 +       return length;
21980 +}
21981 +
21982 +
21983 +
21984 +/* here comes the lower level */
21985 +
21986 +
21987 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
21988 +       .len  = sizeof(NAME) - 1,       \
21989 +       .name = (NAME),                 \
21990 +       .mode = MODE,                   \
21991 +       .iop  = IOP,                    \
21992 +       .fop  = FOP,                    \
21993 +       .op   = OP,                     \
21994 +}
21995 +
21996 +
21997 +#define DIR(NAME, MODE, OTYPE)                         \
21998 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
21999 +               &proc_ ## OTYPE ## _inode_operations,   \
22000 +               &proc_ ## OTYPE ## _file_operations, { } )
22001 +
22002 +#define INF(NAME, MODE, OTYPE)                         \
22003 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
22004 +               &proc_vs_info_file_operations,          \
22005 +               { .proc_vs_read = &proc_##OTYPE } )
22006 +
22007 +#define VINF(NAME, MODE, OTYPE)                                \
22008 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
22009 +               &proc_vx_info_file_operations,          \
22010 +               { .proc_vxi_read = &proc_##OTYPE } )
22011 +
22012 +#define NINF(NAME, MODE, OTYPE)                                \
22013 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
22014 +               &proc_nx_info_file_operations,          \
22015 +               { .proc_nxi_read = &proc_##OTYPE } )
22016 +
22017 +
22018 +static struct file_operations proc_vs_info_file_operations = {
22019 +       .read =         proc_vs_info_read,
22020 +};
22021 +
22022 +static struct file_operations proc_vx_info_file_operations = {
22023 +       .read =         proc_vx_info_read,
22024 +};
22025 +
22026 +static struct dentry_operations proc_xid_dentry_operations = {
22027 +       .d_revalidate = proc_xid_revalidate,
22028 +};
22029 +
22030 +static struct vs_entry vx_base_stuff[] = {
22031 +       VINF("info",    S_IRUGO, vxi_info),
22032 +       VINF("status",  S_IRUGO, vxi_status),
22033 +       VINF("limit",   S_IRUGO, vxi_limit),
22034 +       VINF("sched",   S_IRUGO, vxi_sched),
22035 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
22036 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
22037 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
22038 +       VINF("cacct",   S_IRUGO, vxi_cacct),
22039 +       {}
22040 +};
22041 +
22042 +
22043 +
22044 +
22045 +static struct dentry *proc_xid_instantiate(struct inode *dir,
22046 +       struct dentry *dentry, int id, void *ptr)
22047 +{
22048 +       dentry->d_op = &proc_xid_dentry_operations;
22049 +       return vs_proc_instantiate(dir, dentry, id, ptr);
22050 +}
22051 +
22052 +static struct dentry *proc_xid_lookup(struct inode *dir,
22053 +       struct dentry *dentry, struct nameidata *nd)
22054 +{
22055 +       struct vs_entry *p = vx_base_stuff;
22056 +       struct dentry *error = ERR_PTR(-ENOENT);
22057 +
22058 +       for (; p->name; p++) {
22059 +               if (p->len != dentry->d_name.len)
22060 +                       continue;
22061 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22062 +                       break;
22063 +       }
22064 +       if (!p->name)
22065 +               goto out;
22066 +
22067 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
22068 +out:
22069 +       return error;
22070 +}
22071 +
22072 +static int proc_xid_readdir(struct file *filp,
22073 +       void *dirent, filldir_t filldir)
22074 +{
22075 +       struct dentry *dentry = filp->f_dentry;
22076 +       struct inode *inode = dentry->d_inode;
22077 +       struct vs_entry *p = vx_base_stuff;
22078 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
22079 +       int pos, index;
22080 +       u64 ino;
22081 +
22082 +       pos = filp->f_pos;
22083 +       switch (pos) {
22084 +       case 0:
22085 +               ino = inode->i_ino;
22086 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22087 +                       goto out;
22088 +               pos++;
22089 +               /* fall through */
22090 +       case 1:
22091 +               ino = parent_ino(dentry);
22092 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22093 +                       goto out;
22094 +               pos++;
22095 +               /* fall through */
22096 +       default:
22097 +               index = pos - 2;
22098 +               if (index >= size)
22099 +                       goto out;
22100 +               for (p += index; p->name; p++) {
22101 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22102 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
22103 +                               goto out;
22104 +                       pos++;
22105 +               }
22106 +       }
22107 +out:
22108 +       filp->f_pos = pos;
22109 +       return 1;
22110 +}
22111 +
22112 +
22113 +
22114 +static struct file_operations proc_nx_info_file_operations = {
22115 +       .read =         proc_nx_info_read,
22116 +};
22117 +
22118 +static struct dentry_operations proc_nid_dentry_operations = {
22119 +       .d_revalidate = proc_nid_revalidate,
22120 +};
22121 +
22122 +static struct vs_entry nx_base_stuff[] = {
22123 +       NINF("info",    S_IRUGO, nxi_info),
22124 +       NINF("status",  S_IRUGO, nxi_status),
22125 +       {}
22126 +};
22127 +
22128 +
22129 +static struct dentry *proc_nid_instantiate(struct inode *dir,
22130 +       struct dentry *dentry, int id, void *ptr)
22131 +{
22132 +       dentry->d_op = &proc_nid_dentry_operations;
22133 +       return vs_proc_instantiate(dir, dentry, id, ptr);
22134 +}
22135 +
22136 +static struct dentry *proc_nid_lookup(struct inode *dir,
22137 +       struct dentry *dentry, struct nameidata *nd)
22138 +{
22139 +       struct vs_entry *p = nx_base_stuff;
22140 +       struct dentry *error = ERR_PTR(-ENOENT);
22141 +
22142 +       for (; p->name; p++) {
22143 +               if (p->len != dentry->d_name.len)
22144 +                       continue;
22145 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22146 +                       break;
22147 +       }
22148 +       if (!p->name)
22149 +               goto out;
22150 +
22151 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
22152 +out:
22153 +       return error;
22154 +}
22155 +
22156 +static int proc_nid_readdir(struct file *filp,
22157 +       void *dirent, filldir_t filldir)
22158 +{
22159 +       struct dentry *dentry = filp->f_dentry;
22160 +       struct inode *inode = dentry->d_inode;
22161 +       struct vs_entry *p = nx_base_stuff;
22162 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
22163 +       int pos, index;
22164 +       u64 ino;
22165 +
22166 +       pos = filp->f_pos;
22167 +       switch (pos) {
22168 +       case 0:
22169 +               ino = inode->i_ino;
22170 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22171 +                       goto out;
22172 +               pos++;
22173 +               /* fall through */
22174 +       case 1:
22175 +               ino = parent_ino(dentry);
22176 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22177 +                       goto out;
22178 +               pos++;
22179 +               /* fall through */
22180 +       default:
22181 +               index = pos - 2;
22182 +               if (index >= size)
22183 +                       goto out;
22184 +               for (p += index; p->name; p++) {
22185 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22186 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
22187 +                               goto out;
22188 +                       pos++;
22189 +               }
22190 +       }
22191 +out:
22192 +       filp->f_pos = pos;
22193 +       return 1;
22194 +}
22195 +
22196 +
22197 +#define MAX_MULBY10    ((~0U - 9) / 10)
22198 +
22199 +static inline int atovid(const char *str, int len)
22200 +{
22201 +       int vid, c;
22202 +
22203 +       vid = 0;
22204 +       while (len-- > 0) {
22205 +               c = *str - '0';
22206 +               str++;
22207 +               if (c > 9)
22208 +                       return -1;
22209 +               if (vid >= MAX_MULBY10)
22210 +                       return -1;
22211 +               vid *= 10;
22212 +               vid += c;
22213 +               if (!vid)
22214 +                       return -1;
22215 +       }
22216 +       return vid;
22217 +}
22218 +
22219 +/* now the upper level (virtual) */
22220 +
22221 +
22222 +static struct file_operations proc_xid_file_operations = {
22223 +       .read =         generic_read_dir,
22224 +       .readdir =      proc_xid_readdir,
22225 +};
22226 +
22227 +static struct inode_operations proc_xid_inode_operations = {
22228 +       .lookup =       proc_xid_lookup,
22229 +};
22230 +
22231 +static struct vs_entry vx_virtual_stuff[] = {
22232 +       INF("info",     S_IRUGO, virtual_info),
22233 +       INF("status",   S_IRUGO, virtual_status),
22234 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
22235 +};
22236 +
22237 +
22238 +static struct dentry *proc_virtual_lookup(struct inode *dir,
22239 +       struct dentry *dentry, struct nameidata *nd)
22240 +{
22241 +       struct vs_entry *p = vx_virtual_stuff;
22242 +       struct dentry *error = ERR_PTR(-ENOENT);
22243 +       int id = 0;
22244 +
22245 +       for (; p->name; p++) {
22246 +               if (p->len != dentry->d_name.len)
22247 +                       continue;
22248 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22249 +                       break;
22250 +       }
22251 +       if (p->name)
22252 +               goto instantiate;
22253 +
22254 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
22255 +       if ((id < 0) || !xid_is_hashed(id))
22256 +               goto out;
22257 +
22258 +instantiate:
22259 +       error = proc_xid_instantiate(dir, dentry, id, p);
22260 +out:
22261 +       return error;
22262 +}
22263 +
22264 +static struct file_operations proc_nid_file_operations = {
22265 +       .read =         generic_read_dir,
22266 +       .readdir =      proc_nid_readdir,
22267 +};
22268 +
22269 +static struct inode_operations proc_nid_inode_operations = {
22270 +       .lookup =       proc_nid_lookup,
22271 +};
22272 +
22273 +static struct vs_entry nx_virtnet_stuff[] = {
22274 +       INF("info",     S_IRUGO, virtnet_info),
22275 +       INF("status",   S_IRUGO, virtnet_status),
22276 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
22277 +};
22278 +
22279 +
22280 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
22281 +       struct dentry *dentry, struct nameidata *nd)
22282 +{
22283 +       struct vs_entry *p = nx_virtnet_stuff;
22284 +       struct dentry *error = ERR_PTR(-ENOENT);
22285 +       int id = 0;
22286 +
22287 +       for (; p->name; p++) {
22288 +               if (p->len != dentry->d_name.len)
22289 +                       continue;
22290 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22291 +                       break;
22292 +       }
22293 +       if (p->name)
22294 +               goto instantiate;
22295 +
22296 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
22297 +       if ((id < 0) || !nid_is_hashed(id))
22298 +               goto out;
22299 +
22300 +instantiate:
22301 +       error = proc_nid_instantiate(dir, dentry, id, p);
22302 +out:
22303 +       return error;
22304 +}
22305 +
22306 +
22307 +#define PROC_MAXVIDS 32
22308 +
22309 +int proc_virtual_readdir(struct file *filp,
22310 +       void *dirent, filldir_t filldir)
22311 +{
22312 +       struct dentry *dentry = filp->f_dentry;
22313 +       struct inode *inode = dentry->d_inode;
22314 +       struct vs_entry *p = vx_virtual_stuff;
22315 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
22316 +       int pos, index;
22317 +       unsigned int xid_array[PROC_MAXVIDS];
22318 +       char buf[PROC_NUMBUF];
22319 +       unsigned int nr_xids, i;
22320 +       u64 ino;
22321 +
22322 +       pos = filp->f_pos;
22323 +       switch (pos) {
22324 +       case 0:
22325 +               ino = inode->i_ino;
22326 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22327 +                       goto out;
22328 +               pos++;
22329 +               /* fall through */
22330 +       case 1:
22331 +               ino = parent_ino(dentry);
22332 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22333 +                       goto out;
22334 +               pos++;
22335 +               /* fall through */
22336 +       default:
22337 +               index = pos - 2;
22338 +               if (index >= size)
22339 +                       goto entries;
22340 +               for (p += index; p->name; p++) {
22341 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22342 +                               vs_proc_instantiate, 0, p))
22343 +                               goto out;
22344 +                       pos++;
22345 +               }
22346 +       entries:
22347 +               index = pos - size;
22348 +               p = &vx_virtual_stuff[size - 1];
22349 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
22350 +               for (i = 0; i < nr_xids; i++) {
22351 +                       int n, xid = xid_array[i];
22352 +                       unsigned int j = PROC_NUMBUF;
22353 +
22354 +                       n = xid;
22355 +                       do
22356 +                               buf[--j] = '0' + (n % 10);
22357 +                       while (n /= 10);
22358 +
22359 +                       if (proc_fill_cache(filp, dirent, filldir,
22360 +                               buf + j, PROC_NUMBUF - j,
22361 +                               vs_proc_instantiate, xid, p))
22362 +                               goto out;
22363 +                       pos++;
22364 +               }
22365 +       }
22366 +out:
22367 +       filp->f_pos = pos;
22368 +       return 0;
22369 +}
22370 +
22371 +static int proc_virtual_getattr(struct vfsmount *mnt,
22372 +       struct dentry *dentry, struct kstat *stat)
22373 +{
22374 +       struct inode *inode = dentry->d_inode;
22375 +
22376 +       generic_fillattr(inode, stat);
22377 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
22378 +       return 0;
22379 +}
22380 +
22381 +static struct file_operations proc_virtual_dir_operations = {
22382 +       .read =         generic_read_dir,
22383 +       .readdir =      proc_virtual_readdir,
22384 +};
22385 +
22386 +static struct inode_operations proc_virtual_dir_inode_operations = {
22387 +       .getattr =      proc_virtual_getattr,
22388 +       .lookup =       proc_virtual_lookup,
22389 +};
22390 +
22391 +
22392 +
22393 +
22394 +
22395 +int proc_virtnet_readdir(struct file *filp,
22396 +       void *dirent, filldir_t filldir)
22397 +{
22398 +       struct dentry *dentry = filp->f_dentry;
22399 +       struct inode *inode = dentry->d_inode;
22400 +       struct vs_entry *p = nx_virtnet_stuff;
22401 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
22402 +       int pos, index;
22403 +       unsigned int nid_array[PROC_MAXVIDS];
22404 +       char buf[PROC_NUMBUF];
22405 +       unsigned int nr_nids, i;
22406 +       u64 ino;
22407 +
22408 +       pos = filp->f_pos;
22409 +       switch (pos) {
22410 +       case 0:
22411 +               ino = inode->i_ino;
22412 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22413 +                       goto out;
22414 +               pos++;
22415 +               /* fall through */
22416 +       case 1:
22417 +               ino = parent_ino(dentry);
22418 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22419 +                       goto out;
22420 +               pos++;
22421 +               /* fall through */
22422 +       default:
22423 +               index = pos - 2;
22424 +               if (index >= size)
22425 +                       goto entries;
22426 +               for (p += index; p->name; p++) {
22427 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22428 +                               vs_proc_instantiate, 0, p))
22429 +                               goto out;
22430 +                       pos++;
22431 +               }
22432 +       entries:
22433 +               index = pos - size;
22434 +               p = &nx_virtnet_stuff[size - 1];
22435 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
22436 +               for (i = 0; i < nr_nids; i++) {
22437 +                       int n, nid = nid_array[i];
22438 +                       unsigned int j = PROC_NUMBUF;
22439 +
22440 +                       n = nid;
22441 +                       do
22442 +                               buf[--j] = '0' + (n % 10);
22443 +                       while (n /= 10);
22444 +
22445 +                       if (proc_fill_cache(filp, dirent, filldir,
22446 +                               buf + j, PROC_NUMBUF - j,
22447 +                               vs_proc_instantiate, nid, p))
22448 +                               goto out;
22449 +                       pos++;
22450 +               }
22451 +       }
22452 +out:
22453 +       filp->f_pos = pos;
22454 +       return 0;
22455 +}
22456 +
22457 +static int proc_virtnet_getattr(struct vfsmount *mnt,
22458 +       struct dentry *dentry, struct kstat *stat)
22459 +{
22460 +       struct inode *inode = dentry->d_inode;
22461 +
22462 +       generic_fillattr(inode, stat);
22463 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
22464 +       return 0;
22465 +}
22466 +
22467 +static struct file_operations proc_virtnet_dir_operations = {
22468 +       .read =         generic_read_dir,
22469 +       .readdir =      proc_virtnet_readdir,
22470 +};
22471 +
22472 +static struct inode_operations proc_virtnet_dir_inode_operations = {
22473 +       .getattr =      proc_virtnet_getattr,
22474 +       .lookup =       proc_virtnet_lookup,
22475 +};
22476 +
22477 +
22478 +
22479 +void proc_vx_init(void)
22480 +{
22481 +       struct proc_dir_entry *ent;
22482 +
22483 +       ent = proc_mkdir("virtual", 0);
22484 +       if (ent) {
22485 +               ent->proc_fops = &proc_virtual_dir_operations;
22486 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
22487 +       }
22488 +       proc_virtual = ent;
22489 +
22490 +       ent = proc_mkdir("virtnet", 0);
22491 +       if (ent) {
22492 +               ent->proc_fops = &proc_virtnet_dir_operations;
22493 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
22494 +       }
22495 +       proc_virtnet = ent;
22496 +}
22497 +
22498 +
22499 +
22500 +
22501 +/* per pid info */
22502 +
22503 +
22504 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
22505 +{
22506 +       struct vx_info *vxi;
22507 +       char *orig = buffer;
22508 +
22509 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
22510 +
22511 +       vxi = task_get_vx_info(p);
22512 +       if (!vxi)
22513 +               goto out;
22514 +
22515 +       buffer += sprintf(buffer, "BCaps:\t");
22516 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
22517 +       buffer += sprintf(buffer, "\n");
22518 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
22519 +               (unsigned long long)vxi->vx_ccaps);
22520 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
22521 +               (unsigned long long)vxi->vx_flags);
22522 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
22523 +
22524 +       put_vx_info(vxi);
22525 +out:
22526 +       return buffer - orig;
22527 +}
22528 +
22529 +
22530 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
22531 +{
22532 +       struct nx_info *nxi;
22533 +       struct nx_addr_v4 *v4a;
22534 +#ifdef CONFIG_IPV6
22535 +       struct nx_addr_v6 *v6a;
22536 +#endif
22537 +       char *orig = buffer;
22538 +       int i;
22539 +
22540 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
22541 +
22542 +       nxi = task_get_nx_info(p);
22543 +       if (!nxi)
22544 +               goto out;
22545 +
22546 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
22547 +               (unsigned long long)nxi->nx_ncaps);
22548 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
22549 +               (unsigned long long)nxi->nx_flags);
22550 +
22551 +       buffer += sprintf(buffer,
22552 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
22553 +               NIPQUAD(nxi->v4_bcast.s_addr));
22554 +       buffer += sprintf (buffer,
22555 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
22556 +               NIPQUAD(nxi->v4_lback.s_addr));
22557 +       if (!NX_IPV4(nxi))
22558 +               goto skip_v4;
22559 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22560 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
22561 +                       i, NXAV4(v4a));
22562 +skip_v4:
22563 +#ifdef CONFIG_IPV6
22564 +       if (!NX_IPV6(nxi))
22565 +               goto skip_v6;
22566 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22567 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
22568 +                       i, NXAV6(v6a));
22569 +skip_v6:
22570 +#endif
22571 +       put_nx_info(nxi);
22572 +out:
22573 +       return buffer - orig;
22574 +}
22575 +
22576 diff -NurpP --minimal linux-3.0-rc5/kernel/vserver/sched.c linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/sched.c
22577 --- linux-3.0-rc5/kernel/vserver/sched.c        1970-01-01 01:00:00.000000000 +0100
22578 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/sched.c   2011-06-10 22:11:24.000000000 +0200
22579 @@ -0,0 +1,82 @@
22580 +/*
22581 + *  linux/kernel/vserver/sched.c
22582 + *
22583 + *  Virtual Server: Scheduler Support
22584 + *
22585 + *  Copyright (C) 2004-2010  Herbert Pötzl
22586 + *
22587 + *  V0.01  adapted Sam Vilains version to 2.6.3
22588 + *  V0.02  removed legacy interface
22589 + *  V0.03  changed vcmds to vxi arg
22590 + *  V0.04  removed older and legacy interfaces
22591 + *  V0.05  removed scheduler code/commands
22592 + *
22593 + */
22594 +
22595 +#include <linux/vs_context.h>
22596 +#include <linux/vs_sched.h>
22597 +#include <linux/vserver/sched_cmd.h>
22598 +
22599 +#include <asm/uaccess.h>
22600 +
22601 +
22602 +void vx_update_sched_param(struct _vx_sched *sched,
22603 +       struct _vx_sched_pc *sched_pc)
22604 +{
22605 +       sched_pc->prio_bias = sched->prio_bias;
22606 +}
22607 +
22608 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
22609 +{
22610 +       int cpu;
22611 +
22612 +       if (data->prio_bias > MAX_PRIO_BIAS)
22613 +               data->prio_bias = MAX_PRIO_BIAS;
22614 +       if (data->prio_bias < MIN_PRIO_BIAS)
22615 +               data->prio_bias = MIN_PRIO_BIAS;
22616 +
22617 +       if (data->cpu_id != ~0) {
22618 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
22619 +               cpus_and(vxi->sched.update, cpu_online_map,
22620 +                       vxi->sched.update);
22621 +       } else
22622 +               vxi->sched.update = cpu_online_map;
22623 +
22624 +       for_each_cpu_mask(cpu, vxi->sched.update)
22625 +               vx_update_sched_param(&vxi->sched,
22626 +                       &vx_per_cpu(vxi, sched_pc, cpu));
22627 +       return 0;
22628 +}
22629 +
22630 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
22631 +{
22632 +       struct vcmd_prio_bias vc_data;
22633 +
22634 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22635 +               return -EFAULT;
22636 +
22637 +       return do_set_prio_bias(vxi, &vc_data);
22638 +}
22639 +
22640 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
22641 +{
22642 +       struct vcmd_prio_bias vc_data;
22643 +       struct _vx_sched_pc *pcd;
22644 +       int cpu;
22645 +
22646 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22647 +               return -EFAULT;
22648 +
22649 +       cpu = vc_data.cpu_id;
22650 +
22651 +       if (!cpu_possible(cpu))
22652 +               return -EINVAL;
22653 +
22654 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
22655 +       vc_data.prio_bias = pcd->prio_bias;
22656 +
22657 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22658 +               return -EFAULT;
22659 +       return 0;
22660 +}
22661 +
22662 diff -NurpP --minimal linux-3.0-rc5/kernel/vserver/sched_init.h linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/sched_init.h
22663 --- linux-3.0-rc5/kernel/vserver/sched_init.h   1970-01-01 01:00:00.000000000 +0100
22664 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/sched_init.h      2011-06-10 22:11:24.000000000 +0200
22665 @@ -0,0 +1,27 @@
22666 +
22667 +static inline void vx_info_init_sched(struct _vx_sched *sched)
22668 +{
22669 +       /* scheduling; hard code starting values as constants */
22670 +       sched->prio_bias = 0;
22671 +}
22672 +
22673 +static inline
22674 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22675 +{
22676 +       sched_pc->prio_bias = 0;
22677 +
22678 +       sched_pc->user_ticks = 0;
22679 +       sched_pc->sys_ticks = 0;
22680 +       sched_pc->hold_ticks = 0;
22681 +}
22682 +
22683 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
22684 +{
22685 +       return;
22686 +}
22687 +
22688 +static inline
22689 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22690 +{
22691 +       return;
22692 +}
22693 diff -NurpP --minimal linux-3.0-rc5/kernel/vserver/sched_proc.h linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/sched_proc.h
22694 --- linux-3.0-rc5/kernel/vserver/sched_proc.h   1970-01-01 01:00:00.000000000 +0100
22695 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/sched_proc.h      2011-06-10 22:11:24.000000000 +0200
22696 @@ -0,0 +1,32 @@
22697 +#ifndef _VX_SCHED_PROC_H
22698 +#define _VX_SCHED_PROC_H
22699 +
22700 +
22701 +static inline
22702 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
22703 +{
22704 +       int length = 0;
22705 +
22706 +       length += sprintf(buffer,
22707 +               "PrioBias:\t%8d\n",
22708 +               sched->prio_bias);
22709 +       return length;
22710 +}
22711 +
22712 +static inline
22713 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
22714 +       char *buffer, int cpu)
22715 +{
22716 +       int length = 0;
22717 +
22718 +       length += sprintf(buffer + length,
22719 +               "cpu %d: %lld %lld %lld", cpu,
22720 +               (unsigned long long)sched_pc->user_ticks,
22721 +               (unsigned long long)sched_pc->sys_ticks,
22722 +               (unsigned long long)sched_pc->hold_ticks);
22723 +       length += sprintf(buffer + length,
22724 +               " %d\n", sched_pc->prio_bias);
22725 +       return length;
22726 +}
22727 +
22728 +#endif /* _VX_SCHED_PROC_H */
22729 diff -NurpP --minimal linux-3.0-rc5/kernel/vserver/signal.c linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/signal.c
22730 --- linux-3.0-rc5/kernel/vserver/signal.c       1970-01-01 01:00:00.000000000 +0100
22731 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/signal.c  2011-06-10 22:11:24.000000000 +0200
22732 @@ -0,0 +1,134 @@
22733 +/*
22734 + *  linux/kernel/vserver/signal.c
22735 + *
22736 + *  Virtual Server: Signal Support
22737 + *
22738 + *  Copyright (C) 2003-2007  Herbert Pötzl
22739 + *
22740 + *  V0.01  broken out from vcontext V0.05
22741 + *  V0.02  changed vcmds to vxi arg
22742 + *  V0.03  adjusted siginfo for kill
22743 + *
22744 + */
22745 +
22746 +#include <asm/uaccess.h>
22747 +
22748 +#include <linux/vs_context.h>
22749 +#include <linux/vs_pid.h>
22750 +#include <linux/vserver/signal_cmd.h>
22751 +
22752 +
22753 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
22754 +{
22755 +       int retval, count = 0;
22756 +       struct task_struct *p;
22757 +       struct siginfo *sip = SEND_SIG_PRIV;
22758 +
22759 +       retval = -ESRCH;
22760 +       vxdprintk(VXD_CBIT(misc, 4),
22761 +               "vx_info_kill(%p[#%d],%d,%d)*",
22762 +               vxi, vxi->vx_id, pid, sig);
22763 +       read_lock(&tasklist_lock);
22764 +       switch (pid) {
22765 +       case  0:
22766 +       case -1:
22767 +               for_each_process(p) {
22768 +                       int err = 0;
22769 +
22770 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
22771 +                               (pid && vxi->vx_initpid == p->pid))
22772 +                               continue;
22773 +
22774 +                       err = group_send_sig_info(sig, sip, p);
22775 +                       ++count;
22776 +                       if (err != -EPERM)
22777 +                               retval = err;
22778 +               }
22779 +               break;
22780 +
22781 +       case 1:
22782 +               if (vxi->vx_initpid) {
22783 +                       pid = vxi->vx_initpid;
22784 +                       /* for now, only SIGINT to private init ... */
22785 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22786 +                               /* ... as long as there are tasks left */
22787 +                               (atomic_read(&vxi->vx_tasks) > 1))
22788 +                               sig = SIGINT;
22789 +               }
22790 +               /* fallthrough */
22791 +       default:
22792 +               rcu_read_lock();
22793 +               p = find_task_by_real_pid(pid);
22794 +               rcu_read_unlock();
22795 +               if (p) {
22796 +                       if (vx_task_xid(p) == vxi->vx_id)
22797 +                               retval = group_send_sig_info(sig, sip, p);
22798 +               }
22799 +               break;
22800 +       }
22801 +       read_unlock(&tasklist_lock);
22802 +       vxdprintk(VXD_CBIT(misc, 4),
22803 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
22804 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
22805 +       return retval;
22806 +}
22807 +
22808 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
22809 +{
22810 +       struct vcmd_ctx_kill_v0 vc_data;
22811 +
22812 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22813 +               return -EFAULT;
22814 +
22815 +       /* special check to allow guest shutdown */
22816 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22817 +               /* forbid killall pid=0 when init is present */
22818 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
22819 +               (vc_data.pid > 1)))
22820 +               return -EACCES;
22821 +
22822 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
22823 +}
22824 +
22825 +
22826 +static int __wait_exit(struct vx_info *vxi)
22827 +{
22828 +       DECLARE_WAITQUEUE(wait, current);
22829 +       int ret = 0;
22830 +
22831 +       add_wait_queue(&vxi->vx_wait, &wait);
22832 +       set_current_state(TASK_INTERRUPTIBLE);
22833 +
22834 +wait:
22835 +       if (vx_info_state(vxi,
22836 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
22837 +               goto out;
22838 +       if (signal_pending(current)) {
22839 +               ret = -ERESTARTSYS;
22840 +               goto out;
22841 +       }
22842 +       schedule();
22843 +       goto wait;
22844 +
22845 +out:
22846 +       set_current_state(TASK_RUNNING);
22847 +       remove_wait_queue(&vxi->vx_wait, &wait);
22848 +       return ret;
22849 +}
22850 +
22851 +
22852 +
22853 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
22854 +{
22855 +       struct vcmd_wait_exit_v0 vc_data;
22856 +       int ret;
22857 +
22858 +       ret = __wait_exit(vxi);
22859 +       vc_data.reboot_cmd = vxi->reboot_cmd;
22860 +       vc_data.exit_code = vxi->exit_code;
22861 +
22862 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22863 +               ret = -EFAULT;
22864 +       return ret;
22865 +}
22866 +
22867 diff -NurpP --minimal linux-3.0-rc5/kernel/vserver/space.c linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/space.c
22868 --- linux-3.0-rc5/kernel/vserver/space.c        1970-01-01 01:00:00.000000000 +0100
22869 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/space.c   2011-06-10 22:11:24.000000000 +0200
22870 @@ -0,0 +1,417 @@
22871 +/*
22872 + *  linux/kernel/vserver/space.c
22873 + *
22874 + *  Virtual Server: Context Space Support
22875 + *
22876 + *  Copyright (C) 2003-2010  Herbert Pötzl
22877 + *
22878 + *  V0.01  broken out from context.c 0.07
22879 + *  V0.02  added task locking for namespace
22880 + *  V0.03  broken out vx_enter_namespace
22881 + *  V0.04  added *space support and commands
22882 + *  V0.05  added credential support
22883 + *
22884 + */
22885 +
22886 +#include <linux/utsname.h>
22887 +#include <linux/nsproxy.h>
22888 +#include <linux/err.h>
22889 +#include <linux/fs_struct.h>
22890 +#include <linux/cred.h>
22891 +#include <asm/uaccess.h>
22892 +
22893 +#include <linux/vs_context.h>
22894 +#include <linux/vserver/space.h>
22895 +#include <linux/vserver/space_cmd.h>
22896 +
22897 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
22898 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
22899 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
22900 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
22901 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
22902 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
22903 +
22904 +
22905 +/* namespace functions */
22906 +
22907 +#include <linux/mnt_namespace.h>
22908 +#include <linux/user_namespace.h>
22909 +#include <linux/pid_namespace.h>
22910 +#include <linux/ipc_namespace.h>
22911 +#include <net/net_namespace.h>
22912 +
22913 +
22914 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
22915 +       .mask = CLONE_FS |
22916 +               CLONE_NEWNS |
22917 +               CLONE_NEWUTS |
22918 +               CLONE_NEWIPC |
22919 +               CLONE_NEWUSER |
22920 +               0
22921 +};
22922 +
22923 +static const struct vcmd_space_mask_v1 space_mask = {
22924 +       .mask = CLONE_FS |
22925 +               CLONE_NEWNS |
22926 +               CLONE_NEWUTS |
22927 +               CLONE_NEWIPC |
22928 +               CLONE_NEWUSER |
22929 +#ifdef CONFIG_PID_NS
22930 +               CLONE_NEWPID |
22931 +#endif
22932 +#ifdef CONFIG_NET_NS
22933 +               CLONE_NEWNET |
22934 +#endif
22935 +               0
22936 +};
22937 +
22938 +static const struct vcmd_space_mask_v1 default_space_mask = {
22939 +       .mask = CLONE_FS |
22940 +               CLONE_NEWNS |
22941 +               CLONE_NEWUTS |
22942 +               CLONE_NEWIPC |
22943 +               CLONE_NEWUSER |
22944 +#ifdef CONFIG_PID_NS
22945 +//             CLONE_NEWPID |
22946 +#endif
22947 +               0
22948 +};
22949 +
22950 +/*
22951 + *     build a new nsproxy mix
22952 + *      assumes that both proxies are 'const'
22953 + *     does not touch nsproxy refcounts
22954 + *     will hold a reference on the result.
22955 + */
22956 +
22957 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
22958 +       struct nsproxy *new_nsproxy, unsigned long mask)
22959 +{
22960 +       struct mnt_namespace *old_ns;
22961 +       struct uts_namespace *old_uts;
22962 +       struct ipc_namespace *old_ipc;
22963 +#ifdef CONFIG_PID_NS
22964 +       struct pid_namespace *old_pid;
22965 +#endif
22966 +#ifdef CONFIG_NET_NS
22967 +       struct net *old_net;
22968 +#endif
22969 +       struct nsproxy *nsproxy;
22970 +
22971 +       nsproxy = copy_nsproxy(old_nsproxy);
22972 +       if (!nsproxy)
22973 +               goto out;
22974 +
22975 +       if (mask & CLONE_NEWNS) {
22976 +               old_ns = nsproxy->mnt_ns;
22977 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
22978 +               if (nsproxy->mnt_ns)
22979 +                       get_mnt_ns(nsproxy->mnt_ns);
22980 +       } else
22981 +               old_ns = NULL;
22982 +
22983 +       if (mask & CLONE_NEWUTS) {
22984 +               old_uts = nsproxy->uts_ns;
22985 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
22986 +               if (nsproxy->uts_ns)
22987 +                       get_uts_ns(nsproxy->uts_ns);
22988 +       } else
22989 +               old_uts = NULL;
22990 +
22991 +       if (mask & CLONE_NEWIPC) {
22992 +               old_ipc = nsproxy->ipc_ns;
22993 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
22994 +               if (nsproxy->ipc_ns)
22995 +                       get_ipc_ns(nsproxy->ipc_ns);
22996 +       } else
22997 +               old_ipc = NULL;
22998 +
22999 +#ifdef CONFIG_PID_NS
23000 +       if (mask & CLONE_NEWPID) {
23001 +               old_pid = nsproxy->pid_ns;
23002 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
23003 +               if (nsproxy->pid_ns)
23004 +                       get_pid_ns(nsproxy->pid_ns);
23005 +       } else
23006 +               old_pid = NULL;
23007 +#endif
23008 +#ifdef CONFIG_NET_NS
23009 +       if (mask & CLONE_NEWNET) {
23010 +               old_net = nsproxy->net_ns;
23011 +               nsproxy->net_ns = new_nsproxy->net_ns;
23012 +               if (nsproxy->net_ns)
23013 +                       get_net(nsproxy->net_ns);
23014 +       } else
23015 +               old_net = NULL;
23016 +#endif
23017 +       if (old_ns)
23018 +               put_mnt_ns(old_ns);
23019 +       if (old_uts)
23020 +               put_uts_ns(old_uts);
23021 +       if (old_ipc)
23022 +               put_ipc_ns(old_ipc);
23023 +#ifdef CONFIG_PID_NS
23024 +       if (old_pid)
23025 +               put_pid_ns(old_pid);
23026 +#endif
23027 +#ifdef CONFIG_NET_NS
23028 +       if (old_net)
23029 +               put_net(old_net);
23030 +#endif
23031 +out:
23032 +       return nsproxy;
23033 +}
23034 +
23035 +
23036 +/*
23037 + *     merge two nsproxy structs into a new one.
23038 + *     will hold a reference on the result.
23039 + */
23040 +
23041 +static inline
23042 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
23043 +       struct nsproxy *proxy, unsigned long mask)
23044 +{
23045 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
23046 +
23047 +       if (!proxy)
23048 +               return NULL;
23049 +
23050 +       if (mask) {
23051 +               /* vs_mix_nsproxy returns with reference */
23052 +               return vs_mix_nsproxy(old ? old : &null_proxy,
23053 +                       proxy, mask);
23054 +       }
23055 +       get_nsproxy(proxy);
23056 +       return proxy;
23057 +}
23058 +
23059 +
23060 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
23061 +{
23062 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
23063 +       struct fs_struct *fs_cur, *fs = NULL;
23064 +       struct _vx_space *space;
23065 +       int ret, kill = 0;
23066 +
23067 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
23068 +               vxi, vxi->vx_id, mask, index);
23069 +
23070 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
23071 +               return -EACCES;
23072 +
23073 +       if (index >= VX_SPACES)
23074 +               return -EINVAL;
23075 +
23076 +       space = &vxi->space[index];
23077 +
23078 +       if (!mask)
23079 +               mask = space->vx_nsmask;
23080 +
23081 +       if ((mask & space->vx_nsmask) != mask)
23082 +               return -EINVAL;
23083 +
23084 +       if (mask & CLONE_FS) {
23085 +               fs = copy_fs_struct(space->vx_fs);
23086 +               if (!fs)
23087 +                       return -ENOMEM;
23088 +       }
23089 +       proxy = space->vx_nsproxy;
23090 +
23091 +       vxdprintk(VXD_CBIT(space, 9),
23092 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
23093 +               vxi, vxi->vx_id, mask, index, proxy, fs);
23094 +
23095 +       task_lock(current);
23096 +       fs_cur = current->fs;
23097 +
23098 +       if (mask & CLONE_FS) {
23099 +               spin_lock(&fs_cur->lock);
23100 +               current->fs = fs;
23101 +               kill = !--fs_cur->users;
23102 +               spin_unlock(&fs_cur->lock);
23103 +       }
23104 +
23105 +       proxy_cur = current->nsproxy;
23106 +       get_nsproxy(proxy_cur);
23107 +       task_unlock(current);
23108 +
23109 +       if (kill)
23110 +               free_fs_struct(fs_cur);
23111 +
23112 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
23113 +       if (IS_ERR(proxy_new)) {
23114 +               ret = PTR_ERR(proxy_new);
23115 +               goto out_put;
23116 +       }
23117 +
23118 +       proxy_new = xchg(&current->nsproxy, proxy_new);
23119 +
23120 +       if (mask & CLONE_NEWUSER) {
23121 +               struct cred *cred;
23122 +
23123 +               vxdprintk(VXD_CBIT(space, 10),
23124 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
23125 +                       vxi, vxi->vx_id, space->vx_cred,
23126 +                       current->real_cred, current->cred);
23127 +
23128 +               if (space->vx_cred) {
23129 +                       cred = __prepare_creds(space->vx_cred);
23130 +                       if (cred)
23131 +                               commit_creds(cred);
23132 +               }
23133 +       }
23134 +
23135 +       ret = 0;
23136 +
23137 +       if (proxy_new)
23138 +               put_nsproxy(proxy_new);
23139 +out_put:
23140 +       if (proxy_cur)
23141 +               put_nsproxy(proxy_cur);
23142 +       return ret;
23143 +}
23144 +
23145 +
23146 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
23147 +{
23148 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
23149 +       struct fs_struct *fs_vxi, *fs;
23150 +       struct _vx_space *space;
23151 +       int ret, kill = 0;
23152 +
23153 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
23154 +               vxi, vxi->vx_id, mask, index);
23155 +
23156 +       if ((mask & space_mask.mask) != mask)
23157 +               return -EINVAL;
23158 +
23159 +       if (index >= VX_SPACES)
23160 +               return -EINVAL;
23161 +
23162 +       space = &vxi->space[index];
23163 +
23164 +       proxy_vxi = space->vx_nsproxy;
23165 +       fs_vxi = space->vx_fs;
23166 +
23167 +       if (mask & CLONE_FS) {
23168 +               fs = copy_fs_struct(current->fs);
23169 +               if (!fs)
23170 +                       return -ENOMEM;
23171 +       }
23172 +
23173 +       task_lock(current);
23174 +
23175 +       if (mask & CLONE_FS) {
23176 +               spin_lock(&fs_vxi->lock);
23177 +               space->vx_fs = fs;
23178 +               kill = !--fs_vxi->users;
23179 +               spin_unlock(&fs_vxi->lock);
23180 +       }
23181 +
23182 +       proxy_cur = current->nsproxy;
23183 +       get_nsproxy(proxy_cur);
23184 +       task_unlock(current);
23185 +
23186 +       if (kill)
23187 +               free_fs_struct(fs_vxi);
23188 +
23189 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
23190 +       if (IS_ERR(proxy_new)) {
23191 +               ret = PTR_ERR(proxy_new);
23192 +               goto out_put;
23193 +       }
23194 +
23195 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
23196 +       space->vx_nsmask |= mask;
23197 +
23198 +       if (mask & CLONE_NEWUSER) {
23199 +               struct cred *cred;
23200 +
23201 +               vxdprintk(VXD_CBIT(space, 10),
23202 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
23203 +                       vxi, vxi->vx_id, space->vx_cred,
23204 +                       current->real_cred, current->cred);
23205 +
23206 +               cred = prepare_creds();
23207 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
23208 +               if (cred)
23209 +                       abort_creds(cred);
23210 +       }
23211 +
23212 +       ret = 0;
23213 +
23214 +       if (proxy_new)
23215 +               put_nsproxy(proxy_new);
23216 +out_put:
23217 +       if (proxy_cur)
23218 +               put_nsproxy(proxy_cur);
23219 +       return ret;
23220 +}
23221 +
23222 +
23223 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
23224 +{
23225 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
23226 +
23227 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23228 +               return -EFAULT;
23229 +
23230 +       return vx_enter_space(vxi, vc_data.mask, 0);
23231 +}
23232 +
23233 +int vc_enter_space(struct vx_info *vxi, void __user *data)
23234 +{
23235 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
23236 +
23237 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23238 +               return -EFAULT;
23239 +
23240 +       if (vc_data.index >= VX_SPACES)
23241 +               return -EINVAL;
23242 +
23243 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
23244 +}
23245 +
23246 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
23247 +{
23248 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
23249 +
23250 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23251 +               return -EFAULT;
23252 +
23253 +       return vx_set_space(vxi, vc_data.mask, 0);
23254 +}
23255 +
23256 +int vc_set_space(struct vx_info *vxi, void __user *data)
23257 +{
23258 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
23259 +
23260 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23261 +               return -EFAULT;
23262 +
23263 +       if (vc_data.index >= VX_SPACES)
23264 +               return -EINVAL;
23265 +
23266 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
23267 +}
23268 +
23269 +int vc_get_space_mask(void __user *data, int type)
23270 +{
23271 +       const struct vcmd_space_mask_v1 *mask;
23272 +
23273 +       if (type == 0)
23274 +               mask = &space_mask_v0;
23275 +       else if (type == 1)
23276 +               mask = &space_mask;
23277 +       else
23278 +               mask = &default_space_mask;
23279 +
23280 +       vxdprintk(VXD_CBIT(space, 10),
23281 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
23282 +
23283 +       if (copy_to_user(data, mask, sizeof(*mask)))
23284 +               return -EFAULT;
23285 +       return 0;
23286 +}
23287 +
23288 diff -NurpP --minimal linux-3.0-rc5/kernel/vserver/switch.c linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/switch.c
23289 --- linux-3.0-rc5/kernel/vserver/switch.c       1970-01-01 01:00:00.000000000 +0100
23290 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/switch.c  2011-06-10 22:11:24.000000000 +0200
23291 @@ -0,0 +1,548 @@
23292 +/*
23293 + *  linux/kernel/vserver/switch.c
23294 + *
23295 + *  Virtual Server: Syscall Switch
23296 + *
23297 + *  Copyright (C) 2003-2007  Herbert Pötzl
23298 + *
23299 + *  V0.01  syscall switch
23300 + *  V0.02  added signal to context
23301 + *  V0.03  added rlimit functions
23302 + *  V0.04  added iattr, task/xid functions
23303 + *  V0.05  added debug/history stuff
23304 + *  V0.06  added compat32 layer
23305 + *  V0.07  vcmd args and perms
23306 + *  V0.08  added status commands
23307 + *  V0.09  added tag commands
23308 + *  V0.10  added oom bias
23309 + *  V0.11  added device commands
23310 + *
23311 + */
23312 +
23313 +#include <linux/vs_context.h>
23314 +#include <linux/vs_network.h>
23315 +#include <linux/vserver/switch.h>
23316 +
23317 +#include "vci_config.h"
23318 +
23319 +
23320 +static inline
23321 +int vc_get_version(uint32_t id)
23322 +{
23323 +       return VCI_VERSION;
23324 +}
23325 +
23326 +static inline
23327 +int vc_get_vci(uint32_t id)
23328 +{
23329 +       return vci_kernel_config();
23330 +}
23331 +
23332 +#include <linux/vserver/context_cmd.h>
23333 +#include <linux/vserver/cvirt_cmd.h>
23334 +#include <linux/vserver/cacct_cmd.h>
23335 +#include <linux/vserver/limit_cmd.h>
23336 +#include <linux/vserver/network_cmd.h>
23337 +#include <linux/vserver/sched_cmd.h>
23338 +#include <linux/vserver/debug_cmd.h>
23339 +#include <linux/vserver/inode_cmd.h>
23340 +#include <linux/vserver/dlimit_cmd.h>
23341 +#include <linux/vserver/signal_cmd.h>
23342 +#include <linux/vserver/space_cmd.h>
23343 +#include <linux/vserver/tag_cmd.h>
23344 +#include <linux/vserver/device_cmd.h>
23345 +
23346 +#include <linux/vserver/inode.h>
23347 +#include <linux/vserver/dlimit.h>
23348 +
23349 +
23350 +#ifdef CONFIG_COMPAT
23351 +#define __COMPAT(name, id, data, compat)       \
23352 +       (compat) ? name ## _x32(id, data) : name(id, data)
23353 +#define __COMPAT_NO_ID(name, data, compat)     \
23354 +       (compat) ? name ## _x32(data) : name(data)
23355 +#else
23356 +#define __COMPAT(name, id, data, compat)       \
23357 +       name(id, data)
23358 +#define __COMPAT_NO_ID(name, data, compat)     \
23359 +       name(data)
23360 +#endif
23361 +
23362 +
23363 +static inline
23364 +long do_vcmd(uint32_t cmd, uint32_t id,
23365 +       struct vx_info *vxi, struct nx_info *nxi,
23366 +       void __user *data, int compat)
23367 +{
23368 +       switch (cmd) {
23369 +
23370 +       case VCMD_get_version:
23371 +               return vc_get_version(id);
23372 +       case VCMD_get_vci:
23373 +               return vc_get_vci(id);
23374 +
23375 +       case VCMD_task_xid:
23376 +               return vc_task_xid(id);
23377 +       case VCMD_vx_info:
23378 +               return vc_vx_info(vxi, data);
23379 +
23380 +       case VCMD_task_nid:
23381 +               return vc_task_nid(id);
23382 +       case VCMD_nx_info:
23383 +               return vc_nx_info(nxi, data);
23384 +
23385 +       case VCMD_task_tag:
23386 +               return vc_task_tag(id);
23387 +
23388 +       case VCMD_set_space_v1:
23389 +               return vc_set_space_v1(vxi, data);
23390 +       /* this is version 2 */
23391 +       case VCMD_set_space:
23392 +               return vc_set_space(vxi, data);
23393 +
23394 +       case VCMD_get_space_mask_v0:
23395 +               return vc_get_space_mask(data, 0);
23396 +       /* this is version 1 */
23397 +       case VCMD_get_space_mask:
23398 +               return vc_get_space_mask(data, 1);
23399 +
23400 +       case VCMD_get_space_default:
23401 +               return vc_get_space_mask(data, -1);
23402 +
23403 +       case VCMD_set_umask:
23404 +               return vc_set_umask(vxi, data);
23405 +
23406 +       case VCMD_get_umask:
23407 +               return vc_get_umask(vxi, data);
23408 +
23409 +#ifdef CONFIG_IA32_EMULATION
23410 +       case VCMD_get_rlimit:
23411 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
23412 +       case VCMD_set_rlimit:
23413 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
23414 +#else
23415 +       case VCMD_get_rlimit:
23416 +               return vc_get_rlimit(vxi, data);
23417 +       case VCMD_set_rlimit:
23418 +               return vc_set_rlimit(vxi, data);
23419 +#endif
23420 +       case VCMD_get_rlimit_mask:
23421 +               return vc_get_rlimit_mask(id, data);
23422 +       case VCMD_reset_hits:
23423 +               return vc_reset_hits(vxi, data);
23424 +       case VCMD_reset_minmax:
23425 +               return vc_reset_minmax(vxi, data);
23426 +
23427 +       case VCMD_get_vhi_name:
23428 +               return vc_get_vhi_name(vxi, data);
23429 +       case VCMD_set_vhi_name:
23430 +               return vc_set_vhi_name(vxi, data);
23431 +
23432 +       case VCMD_ctx_stat:
23433 +               return vc_ctx_stat(vxi, data);
23434 +       case VCMD_virt_stat:
23435 +               return vc_virt_stat(vxi, data);
23436 +       case VCMD_sock_stat:
23437 +               return vc_sock_stat(vxi, data);
23438 +       case VCMD_rlimit_stat:
23439 +               return vc_rlimit_stat(vxi, data);
23440 +
23441 +       case VCMD_set_cflags:
23442 +               return vc_set_cflags(vxi, data);
23443 +       case VCMD_get_cflags:
23444 +               return vc_get_cflags(vxi, data);
23445 +
23446 +       /* this is version 1 */
23447 +       case VCMD_set_ccaps:
23448 +               return vc_set_ccaps(vxi, data);
23449 +       /* this is version 1 */
23450 +       case VCMD_get_ccaps:
23451 +               return vc_get_ccaps(vxi, data);
23452 +       case VCMD_set_bcaps:
23453 +               return vc_set_bcaps(vxi, data);
23454 +       case VCMD_get_bcaps:
23455 +               return vc_get_bcaps(vxi, data);
23456 +
23457 +       case VCMD_set_badness:
23458 +               return vc_set_badness(vxi, data);
23459 +       case VCMD_get_badness:
23460 +               return vc_get_badness(vxi, data);
23461 +
23462 +       case VCMD_set_nflags:
23463 +               return vc_set_nflags(nxi, data);
23464 +       case VCMD_get_nflags:
23465 +               return vc_get_nflags(nxi, data);
23466 +
23467 +       case VCMD_set_ncaps:
23468 +               return vc_set_ncaps(nxi, data);
23469 +       case VCMD_get_ncaps:
23470 +               return vc_get_ncaps(nxi, data);
23471 +
23472 +       case VCMD_set_prio_bias:
23473 +               return vc_set_prio_bias(vxi, data);
23474 +       case VCMD_get_prio_bias:
23475 +               return vc_get_prio_bias(vxi, data);
23476 +       case VCMD_add_dlimit:
23477 +               return __COMPAT(vc_add_dlimit, id, data, compat);
23478 +       case VCMD_rem_dlimit:
23479 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
23480 +       case VCMD_set_dlimit:
23481 +               return __COMPAT(vc_set_dlimit, id, data, compat);
23482 +       case VCMD_get_dlimit:
23483 +               return __COMPAT(vc_get_dlimit, id, data, compat);
23484 +
23485 +       case VCMD_ctx_kill:
23486 +               return vc_ctx_kill(vxi, data);
23487 +
23488 +       case VCMD_wait_exit:
23489 +               return vc_wait_exit(vxi, data);
23490 +
23491 +       case VCMD_get_iattr:
23492 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
23493 +       case VCMD_set_iattr:
23494 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
23495 +
23496 +       case VCMD_fget_iattr:
23497 +               return vc_fget_iattr(id, data);
23498 +       case VCMD_fset_iattr:
23499 +               return vc_fset_iattr(id, data);
23500 +
23501 +       case VCMD_enter_space_v0:
23502 +               return vc_enter_space_v1(vxi, NULL);
23503 +       case VCMD_enter_space_v1:
23504 +               return vc_enter_space_v1(vxi, data);
23505 +       /* this is version 2 */
23506 +       case VCMD_enter_space:
23507 +               return vc_enter_space(vxi, data);
23508 +
23509 +       case VCMD_ctx_create_v0:
23510 +               return vc_ctx_create(id, NULL);
23511 +       case VCMD_ctx_create:
23512 +               return vc_ctx_create(id, data);
23513 +       case VCMD_ctx_migrate_v0:
23514 +               return vc_ctx_migrate(vxi, NULL);
23515 +       case VCMD_ctx_migrate:
23516 +               return vc_ctx_migrate(vxi, data);
23517 +
23518 +       case VCMD_net_create_v0:
23519 +               return vc_net_create(id, NULL);
23520 +       case VCMD_net_create:
23521 +               return vc_net_create(id, data);
23522 +       case VCMD_net_migrate:
23523 +               return vc_net_migrate(nxi, data);
23524 +
23525 +       case VCMD_tag_migrate:
23526 +               return vc_tag_migrate(id);
23527 +
23528 +       case VCMD_net_add:
23529 +               return vc_net_add(nxi, data);
23530 +       case VCMD_net_remove:
23531 +               return vc_net_remove(nxi, data);
23532 +
23533 +       case VCMD_net_add_ipv4_v1:
23534 +               return vc_net_add_ipv4_v1(nxi, data);
23535 +       /* this is version 2 */
23536 +       case VCMD_net_add_ipv4:
23537 +               return vc_net_add_ipv4(nxi, data);
23538 +
23539 +       case VCMD_net_rem_ipv4_v1:
23540 +               return vc_net_rem_ipv4_v1(nxi, data);
23541 +       /* this is version 2 */
23542 +       case VCMD_net_rem_ipv4:
23543 +               return vc_net_rem_ipv4(nxi, data);
23544 +#ifdef CONFIG_IPV6
23545 +       case VCMD_net_add_ipv6:
23546 +               return vc_net_add_ipv6(nxi, data);
23547 +       case VCMD_net_remove_ipv6:
23548 +               return vc_net_remove_ipv6(nxi, data);
23549 +#endif
23550 +/*     case VCMD_add_match_ipv4:
23551 +               return vc_add_match_ipv4(nxi, data);
23552 +       case VCMD_get_match_ipv4:
23553 +               return vc_get_match_ipv4(nxi, data);
23554 +#ifdef CONFIG_IPV6
23555 +       case VCMD_add_match_ipv6:
23556 +               return vc_add_match_ipv6(nxi, data);
23557 +       case VCMD_get_match_ipv6:
23558 +               return vc_get_match_ipv6(nxi, data);
23559 +#endif */
23560 +
23561 +#ifdef CONFIG_VSERVER_DEVICE
23562 +       case VCMD_set_mapping:
23563 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
23564 +       case VCMD_unset_mapping:
23565 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
23566 +#endif
23567 +#ifdef CONFIG_VSERVER_HISTORY
23568 +       case VCMD_dump_history:
23569 +               return vc_dump_history(id);
23570 +       case VCMD_read_history:
23571 +               return __COMPAT(vc_read_history, id, data, compat);
23572 +#endif
23573 +       default:
23574 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
23575 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
23576 +       }
23577 +       return -ENOSYS;
23578 +}
23579 +
23580 +
23581 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
23582 +       case VCMD_ ## vcmd: perm = _perm;               \
23583 +               args = _args; flags = _flags; break
23584 +
23585 +
23586 +#define VCA_NONE       0x00
23587 +#define VCA_VXI                0x01
23588 +#define VCA_NXI                0x02
23589 +
23590 +#define VCF_NONE       0x00
23591 +#define VCF_INFO       0x01
23592 +#define VCF_ADMIN      0x02
23593 +#define VCF_ARES       0x06    /* includes admin */
23594 +#define VCF_SETUP      0x08
23595 +
23596 +#define VCF_ZIDOK      0x10    /* zero id okay */
23597 +
23598 +
23599 +static inline
23600 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
23601 +{
23602 +       long ret;
23603 +       int permit = -1, state = 0;
23604 +       int perm = -1, args = 0, flags = 0;
23605 +       struct vx_info *vxi = NULL;
23606 +       struct nx_info *nxi = NULL;
23607 +
23608 +       switch (cmd) {
23609 +       /* unpriviledged commands */
23610 +       __VCMD(get_version,      0, VCA_NONE,   0);
23611 +       __VCMD(get_vci,          0, VCA_NONE,   0);
23612 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
23613 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
23614 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
23615 +       __VCMD(get_space_default,0, VCA_NONE,   0);
23616 +
23617 +       /* info commands */
23618 +       __VCMD(task_xid,         2, VCA_NONE,   0);
23619 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
23620 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
23621 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
23622 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
23623 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
23624 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
23625 +       __VCMD(get_umask,        3, VCA_VXI,    VCF_INFO);
23626 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
23627 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
23628 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
23629 +
23630 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
23631 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
23632 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
23633 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
23634 +
23635 +       __VCMD(task_nid,         2, VCA_NONE,   0);
23636 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
23637 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
23638 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
23639 +
23640 +       __VCMD(task_tag,         2, VCA_NONE,   0);
23641 +
23642 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
23643 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
23644 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
23645 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
23646 +
23647 +       /* lower admin commands */
23648 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
23649 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
23650 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
23651 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
23652 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
23653 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
23654 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
23655 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
23656 +
23657 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
23658 +       __VCMD(net_create,       5, VCA_NONE,   0);
23659 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
23660 +
23661 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
23662 +
23663 +       /* higher admin commands */
23664 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
23665 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23666 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23667 +
23668 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23669 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23670 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23671 +       __VCMD(set_umask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23672 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23673 +
23674 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23675 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23676 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23677 +
23678 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23679 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23680 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23681 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23682 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23683 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23684 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23685 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23686 +#ifdef CONFIG_IPV6
23687 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23688 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23689 +#endif
23690 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
23691 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
23692 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
23693 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
23694 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
23695 +
23696 +#ifdef CONFIG_VSERVER_DEVICE
23697 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23698 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23699 +#endif
23700 +       /* debug level admin commands */
23701 +#ifdef CONFIG_VSERVER_HISTORY
23702 +       __VCMD(dump_history,     9, VCA_NONE,   0);
23703 +       __VCMD(read_history,     9, VCA_NONE,   0);
23704 +#endif
23705 +
23706 +       default:
23707 +               perm = -1;
23708 +       }
23709 +
23710 +       vxdprintk(VXD_CBIT(switch, 0),
23711 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
23712 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23713 +               VC_VERSION(cmd), id, data, compat,
23714 +               perm, args, flags);
23715 +
23716 +       ret = -ENOSYS;
23717 +       if (perm < 0)
23718 +               goto out;
23719 +
23720 +       state = 1;
23721 +       if (!capable(CAP_CONTEXT))
23722 +               goto out;
23723 +
23724 +       state = 2;
23725 +       /* moved here from the individual commands */
23726 +       ret = -EPERM;
23727 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
23728 +               goto out;
23729 +
23730 +       state = 3;
23731 +       /* vcmd involves resource management  */
23732 +       ret = -EPERM;
23733 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
23734 +               goto out;
23735 +
23736 +       state = 4;
23737 +       /* various legacy exceptions */
23738 +       switch (cmd) {
23739 +       /* will go away when spectator is a cap */
23740 +       case VCMD_ctx_migrate_v0:
23741 +       case VCMD_ctx_migrate:
23742 +               if (id == 1) {
23743 +                       current->xid = 1;
23744 +                       ret = 1;
23745 +                       goto out;
23746 +               }
23747 +               break;
23748 +
23749 +       /* will go away when spectator is a cap */
23750 +       case VCMD_net_migrate:
23751 +               if (id == 1) {
23752 +                       current->nid = 1;
23753 +                       ret = 1;
23754 +                       goto out;
23755 +               }
23756 +               break;
23757 +       }
23758 +
23759 +       /* vcmds are fine by default */
23760 +       permit = 1;
23761 +
23762 +       /* admin type vcmds require admin ... */
23763 +       if (flags & VCF_ADMIN)
23764 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
23765 +
23766 +       /* ... but setup type vcmds override that */
23767 +       if (!permit && (flags & VCF_SETUP))
23768 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
23769 +
23770 +       state = 5;
23771 +       ret = -EPERM;
23772 +       if (!permit)
23773 +               goto out;
23774 +
23775 +       state = 6;
23776 +       if (!id && (flags & VCF_ZIDOK))
23777 +               goto skip_id;
23778 +
23779 +       ret = -ESRCH;
23780 +       if (args & VCA_VXI) {
23781 +               vxi = lookup_vx_info(id);
23782 +               if (!vxi)
23783 +                       goto out;
23784 +
23785 +               if ((flags & VCF_ADMIN) &&
23786 +                       /* special case kill for shutdown */
23787 +                       (cmd != VCMD_ctx_kill) &&
23788 +                       /* can context be administrated? */
23789 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
23790 +                       ret = -EACCES;
23791 +                       goto out_vxi;
23792 +               }
23793 +       }
23794 +       state = 7;
23795 +       if (args & VCA_NXI) {
23796 +               nxi = lookup_nx_info(id);
23797 +               if (!nxi)
23798 +                       goto out_vxi;
23799 +
23800 +               if ((flags & VCF_ADMIN) &&
23801 +                       /* can context be administrated? */
23802 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
23803 +                       ret = -EACCES;
23804 +                       goto out_nxi;
23805 +               }
23806 +       }
23807 +skip_id:
23808 +       state = 8;
23809 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
23810 +
23811 +out_nxi:
23812 +       if ((args & VCA_NXI) && nxi)
23813 +               put_nx_info(nxi);
23814 +out_vxi:
23815 +       if ((args & VCA_VXI) && vxi)
23816 +               put_vx_info(vxi);
23817 +out:
23818 +       vxdprintk(VXD_CBIT(switch, 1),
23819 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
23820 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23821 +               VC_VERSION(cmd), ret, ret, state, permit);
23822 +       return ret;
23823 +}
23824 +
23825 +asmlinkage long
23826 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
23827 +{
23828 +       return do_vserver(cmd, id, data, 0);
23829 +}
23830 +
23831 +#ifdef CONFIG_COMPAT
23832 +
23833 +asmlinkage long
23834 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
23835 +{
23836 +       return do_vserver(cmd, id, data, 1);
23837 +}
23838 +
23839 +#endif /* CONFIG_COMPAT */
23840 diff -NurpP --minimal linux-3.0-rc5/kernel/vserver/sysctl.c linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/sysctl.c
23841 --- linux-3.0-rc5/kernel/vserver/sysctl.c       1970-01-01 01:00:00.000000000 +0100
23842 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/sysctl.c  2011-06-10 22:11:24.000000000 +0200
23843 @@ -0,0 +1,241 @@
23844 +/*
23845 + *  kernel/vserver/sysctl.c
23846 + *
23847 + *  Virtual Context Support
23848 + *
23849 + *  Copyright (C) 2004-2007  Herbert Pötzl
23850 + *
23851 + *  V0.01  basic structure
23852 + *
23853 + */
23854 +
23855 +#include <linux/module.h>
23856 +#include <linux/ctype.h>
23857 +#include <linux/sysctl.h>
23858 +#include <linux/parser.h>
23859 +#include <asm/uaccess.h>
23860 +
23861 +enum {
23862 +       CTL_DEBUG_ERROR         = 0,
23863 +       CTL_DEBUG_SWITCH        = 1,
23864 +       CTL_DEBUG_XID,
23865 +       CTL_DEBUG_NID,
23866 +       CTL_DEBUG_TAG,
23867 +       CTL_DEBUG_NET,
23868 +       CTL_DEBUG_LIMIT,
23869 +       CTL_DEBUG_CRES,
23870 +       CTL_DEBUG_DLIM,
23871 +       CTL_DEBUG_QUOTA,
23872 +       CTL_DEBUG_CVIRT,
23873 +       CTL_DEBUG_SPACE,
23874 +       CTL_DEBUG_MISC,
23875 +};
23876 +
23877 +
23878 +unsigned int vx_debug_switch   = 0;
23879 +unsigned int vx_debug_xid      = 0;
23880 +unsigned int vx_debug_nid      = 0;
23881 +unsigned int vx_debug_tag      = 0;
23882 +unsigned int vx_debug_net      = 0;
23883 +unsigned int vx_debug_limit    = 0;
23884 +unsigned int vx_debug_cres     = 0;
23885 +unsigned int vx_debug_dlim     = 0;
23886 +unsigned int vx_debug_quota    = 0;
23887 +unsigned int vx_debug_cvirt    = 0;
23888 +unsigned int vx_debug_space    = 0;
23889 +unsigned int vx_debug_misc     = 0;
23890 +
23891 +
23892 +static struct ctl_table_header *vserver_table_header;
23893 +static ctl_table vserver_root_table[];
23894 +
23895 +
23896 +void vserver_register_sysctl(void)
23897 +{
23898 +       if (!vserver_table_header) {
23899 +               vserver_table_header = register_sysctl_table(vserver_root_table);
23900 +       }
23901 +
23902 +}
23903 +
23904 +void vserver_unregister_sysctl(void)
23905 +{
23906 +       if (vserver_table_header) {
23907 +               unregister_sysctl_table(vserver_table_header);
23908 +               vserver_table_header = NULL;
23909 +       }
23910 +}
23911 +
23912 +
23913 +static int proc_dodebug(ctl_table *table, int write,
23914 +       void __user *buffer, size_t *lenp, loff_t *ppos)
23915 +{
23916 +       char            tmpbuf[20], *p, c;
23917 +       unsigned int    value;
23918 +       size_t          left, len;
23919 +
23920 +       if ((*ppos && !write) || !*lenp) {
23921 +               *lenp = 0;
23922 +               return 0;
23923 +       }
23924 +
23925 +       left = *lenp;
23926 +
23927 +       if (write) {
23928 +               if (!access_ok(VERIFY_READ, buffer, left))
23929 +                       return -EFAULT;
23930 +               p = (char *)buffer;
23931 +               while (left && __get_user(c, p) >= 0 && isspace(c))
23932 +                       left--, p++;
23933 +               if (!left)
23934 +                       goto done;
23935 +
23936 +               if (left > sizeof(tmpbuf) - 1)
23937 +                       return -EINVAL;
23938 +               if (copy_from_user(tmpbuf, p, left))
23939 +                       return -EFAULT;
23940 +               tmpbuf[left] = '\0';
23941 +
23942 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
23943 +                       value = 10 * value + (*p - '0');
23944 +               if (*p && !isspace(*p))
23945 +                       return -EINVAL;
23946 +               while (left && isspace(*p))
23947 +                       left--, p++;
23948 +               *(unsigned int *)table->data = value;
23949 +       } else {
23950 +               if (!access_ok(VERIFY_WRITE, buffer, left))
23951 +                       return -EFAULT;
23952 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
23953 +               if (len > left)
23954 +                       len = left;
23955 +               if (__copy_to_user(buffer, tmpbuf, len))
23956 +                       return -EFAULT;
23957 +               if ((left -= len) > 0) {
23958 +                       if (put_user('\n', (char *)buffer + len))
23959 +                               return -EFAULT;
23960 +                       left--;
23961 +               }
23962 +       }
23963 +
23964 +done:
23965 +       *lenp -= left;
23966 +       *ppos += *lenp;
23967 +       return 0;
23968 +}
23969 +
23970 +static int zero;
23971 +
23972 +#define        CTL_ENTRY(ctl, name)                            \
23973 +       {                                               \
23974 +               .procname       = #name,                \
23975 +               .data           = &vx_ ## name,         \
23976 +               .maxlen         = sizeof(int),          \
23977 +               .mode           = 0644,                 \
23978 +               .proc_handler   = &proc_dodebug,        \
23979 +               .extra1         = &zero,                \
23980 +               .extra2         = &zero,                \
23981 +       }
23982 +
23983 +static ctl_table vserver_debug_table[] = {
23984 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
23985 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
23986 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
23987 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
23988 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
23989 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
23990 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
23991 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
23992 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
23993 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
23994 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
23995 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
23996 +       { 0 }
23997 +};
23998 +
23999 +static ctl_table vserver_root_table[] = {
24000 +       {
24001 +               .procname       = "vserver",
24002 +               .mode           = 0555,
24003 +               .child          = vserver_debug_table
24004 +       },
24005 +       { 0 }
24006 +};
24007 +
24008 +
24009 +static match_table_t tokens = {
24010 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
24011 +       { CTL_DEBUG_XID,        "xid=%x"        },
24012 +       { CTL_DEBUG_NID,        "nid=%x"        },
24013 +       { CTL_DEBUG_TAG,        "tag=%x"        },
24014 +       { CTL_DEBUG_NET,        "net=%x"        },
24015 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
24016 +       { CTL_DEBUG_CRES,       "cres=%x"       },
24017 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
24018 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
24019 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
24020 +       { CTL_DEBUG_SPACE,      "space=%x"      },
24021 +       { CTL_DEBUG_MISC,       "misc=%x"       },
24022 +       { CTL_DEBUG_ERROR,      NULL            }
24023 +};
24024 +
24025 +#define        HANDLE_CASE(id, name, val)                              \
24026 +       case CTL_DEBUG_ ## id:                                  \
24027 +               vx_debug_ ## name = val;                        \
24028 +               printk("vs_debug_" #name "=0x%x\n", val);       \
24029 +               break
24030 +
24031 +
24032 +static int __init vs_debug_setup(char *str)
24033 +{
24034 +       char *p;
24035 +       int token;
24036 +
24037 +       printk("vs_debug_setup(%s)\n", str);
24038 +       while ((p = strsep(&str, ",")) != NULL) {
24039 +               substring_t args[MAX_OPT_ARGS];
24040 +               unsigned int value;
24041 +
24042 +               if (!*p)
24043 +                       continue;
24044 +
24045 +               token = match_token(p, tokens, args);
24046 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
24047 +
24048 +               switch (token) {
24049 +               HANDLE_CASE(SWITCH, switch, value);
24050 +               HANDLE_CASE(XID,    xid,    value);
24051 +               HANDLE_CASE(NID,    nid,    value);
24052 +               HANDLE_CASE(TAG,    tag,    value);
24053 +               HANDLE_CASE(NET,    net,    value);
24054 +               HANDLE_CASE(LIMIT,  limit,  value);
24055 +               HANDLE_CASE(CRES,   cres,   value);
24056 +               HANDLE_CASE(DLIM,   dlim,   value);
24057 +               HANDLE_CASE(QUOTA,  quota,  value);
24058 +               HANDLE_CASE(CVIRT,  cvirt,  value);
24059 +               HANDLE_CASE(SPACE,  space,  value);
24060 +               HANDLE_CASE(MISC,   misc,   value);
24061 +               default:
24062 +                       return -EINVAL;
24063 +                       break;
24064 +               }
24065 +       }
24066 +       return 1;
24067 +}
24068 +
24069 +__setup("vsdebug=", vs_debug_setup);
24070 +
24071 +
24072 +
24073 +EXPORT_SYMBOL_GPL(vx_debug_switch);
24074 +EXPORT_SYMBOL_GPL(vx_debug_xid);
24075 +EXPORT_SYMBOL_GPL(vx_debug_nid);
24076 +EXPORT_SYMBOL_GPL(vx_debug_net);
24077 +EXPORT_SYMBOL_GPL(vx_debug_limit);
24078 +EXPORT_SYMBOL_GPL(vx_debug_cres);
24079 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
24080 +EXPORT_SYMBOL_GPL(vx_debug_quota);
24081 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
24082 +EXPORT_SYMBOL_GPL(vx_debug_space);
24083 +EXPORT_SYMBOL_GPL(vx_debug_misc);
24084 +
24085 diff -NurpP --minimal linux-3.0-rc5/kernel/vserver/tag.c linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/tag.c
24086 --- linux-3.0-rc5/kernel/vserver/tag.c  1970-01-01 01:00:00.000000000 +0100
24087 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/tag.c     2011-06-10 22:11:24.000000000 +0200
24088 @@ -0,0 +1,63 @@
24089 +/*
24090 + *  linux/kernel/vserver/tag.c
24091 + *
24092 + *  Virtual Server: Shallow Tag Space
24093 + *
24094 + *  Copyright (C) 2007  Herbert Pötzl
24095 + *
24096 + *  V0.01  basic implementation
24097 + *
24098 + */
24099 +
24100 +#include <linux/sched.h>
24101 +#include <linux/vserver/debug.h>
24102 +#include <linux/vs_pid.h>
24103 +#include <linux/vs_tag.h>
24104 +
24105 +#include <linux/vserver/tag_cmd.h>
24106 +
24107 +
24108 +int dx_migrate_task(struct task_struct *p, tag_t tag)
24109 +{
24110 +       if (!p)
24111 +               BUG();
24112 +
24113 +       vxdprintk(VXD_CBIT(tag, 5),
24114 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
24115 +
24116 +       task_lock(p);
24117 +       p->tag = tag;
24118 +       task_unlock(p);
24119 +
24120 +       vxdprintk(VXD_CBIT(tag, 5),
24121 +               "moved task %p into [#%d]", p, tag);
24122 +       return 0;
24123 +}
24124 +
24125 +/* vserver syscall commands below here */
24126 +
24127 +/* taks xid and vx_info functions */
24128 +
24129 +
24130 +int vc_task_tag(uint32_t id)
24131 +{
24132 +       tag_t tag;
24133 +
24134 +       if (id) {
24135 +               struct task_struct *tsk;
24136 +               rcu_read_lock();
24137 +               tsk = find_task_by_real_pid(id);
24138 +               tag = (tsk) ? tsk->tag : -ESRCH;
24139 +               rcu_read_unlock();
24140 +       } else
24141 +               tag = dx_current_tag();
24142 +       return tag;
24143 +}
24144 +
24145 +
24146 +int vc_tag_migrate(uint32_t tag)
24147 +{
24148 +       return dx_migrate_task(current, tag & 0xFFFF);
24149 +}
24150 +
24151 +
24152 diff -NurpP --minimal linux-3.0-rc5/kernel/vserver/vci_config.h linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/vci_config.h
24153 --- linux-3.0-rc5/kernel/vserver/vci_config.h   1970-01-01 01:00:00.000000000 +0100
24154 +++ linux-3.0-rc5-vs2.3.1-pre3/kernel/vserver/vci_config.h      2011-06-10 22:11:24.000000000 +0200
24155 @@ -0,0 +1,76 @@
24156 +
24157 +/*  interface version */
24158 +
24159 +#define VCI_VERSION            0x00020308
24160 +
24161 +
24162 +enum {
24163 +       VCI_KCBIT_NO_DYNAMIC = 0,
24164 +
24165 +       VCI_KCBIT_PROC_SECURE = 4,
24166 +       /* VCI_KCBIT_HARDCPU = 5, */
24167 +       /* VCI_KCBIT_IDLELIMIT = 6, */
24168 +       /* VCI_KCBIT_IDLETIME = 7, */
24169 +
24170 +       VCI_KCBIT_COWBL = 8,
24171 +       VCI_KCBIT_FULLCOWBL = 9,
24172 +       VCI_KCBIT_SPACES = 10,
24173 +       VCI_KCBIT_NETV2 = 11,
24174 +       VCI_KCBIT_MEMCG = 12,
24175 +
24176 +       VCI_KCBIT_DEBUG = 16,
24177 +       VCI_KCBIT_HISTORY = 20,
24178 +       VCI_KCBIT_TAGGED = 24,
24179 +       VCI_KCBIT_PPTAG = 28,
24180 +
24181 +       VCI_KCBIT_MORE = 31,
24182 +};
24183 +
24184 +
24185 +static inline uint32_t vci_kernel_config(void)
24186 +{
24187 +       return
24188 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
24189 +
24190 +       /* configured features */
24191 +#ifdef CONFIG_VSERVER_PROC_SECURE
24192 +       (1 << VCI_KCBIT_PROC_SECURE) |
24193 +#endif
24194 +#ifdef CONFIG_VSERVER_COWBL
24195 +       (1 << VCI_KCBIT_COWBL) |
24196 +       (1 << VCI_KCBIT_FULLCOWBL) |
24197 +#endif
24198 +       (1 << VCI_KCBIT_SPACES) |
24199 +       (1 << VCI_KCBIT_NETV2) |
24200 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
24201 +       (1 << VCI_KCBIT_MEMCG) |
24202 +#endif
24203 +
24204 +       /* debug options */
24205 +#ifdef CONFIG_VSERVER_DEBUG
24206 +       (1 << VCI_KCBIT_DEBUG) |
24207 +#endif
24208 +#ifdef CONFIG_VSERVER_HISTORY
24209 +       (1 << VCI_KCBIT_HISTORY) |
24210 +#endif
24211 +
24212 +       /* inode context tagging */
24213 +#if    defined(CONFIG_TAGGING_NONE)
24214 +       (0 << VCI_KCBIT_TAGGED) |
24215 +#elif  defined(CONFIG_TAGGING_UID16)
24216 +       (1 << VCI_KCBIT_TAGGED) |
24217 +#elif  defined(CONFIG_TAGGING_GID16)
24218 +       (2 << VCI_KCBIT_TAGGED) |
24219 +#elif  defined(CONFIG_TAGGING_ID24)
24220 +       (3 << VCI_KCBIT_TAGGED) |
24221 +#elif  defined(CONFIG_TAGGING_INTERN)
24222 +       (4 << VCI_KCBIT_TAGGED) |
24223 +#elif  defined(CONFIG_TAGGING_RUNTIME)
24224 +       (5 << VCI_KCBIT_TAGGED) |
24225 +#else
24226 +       (7 << VCI_KCBIT_TAGGED) |
24227 +#endif
24228 +       (1 << VCI_KCBIT_PPTAG) |
24229 +       0;
24230 +}
24231 +
24232 diff -NurpP --minimal linux-3.0-rc5/mm/filemap_xip.c linux-3.0-rc5-vs2.3.1-pre3/mm/filemap_xip.c
24233 --- linux-3.0-rc5/mm/filemap_xip.c      2011-07-01 11:14:23.000000000 +0200
24234 +++ linux-3.0-rc5-vs2.3.1-pre3/mm/filemap_xip.c 2011-06-10 22:11:24.000000000 +0200
24235 @@ -18,6 +18,7 @@
24236  #include <linux/seqlock.h>
24237  #include <linux/mutex.h>
24238  #include <linux/gfp.h>
24239 +#include <linux/vs_memory.h>
24240  #include <asm/tlbflush.h>
24241  #include <asm/io.h>
24242  
24243 diff -NurpP --minimal linux-3.0-rc5/mm/fremap.c linux-3.0-rc5-vs2.3.1-pre3/mm/fremap.c
24244 --- linux-3.0-rc5/mm/fremap.c   2011-07-01 11:14:23.000000000 +0200
24245 +++ linux-3.0-rc5-vs2.3.1-pre3/mm/fremap.c      2011-06-10 22:11:24.000000000 +0200
24246 @@ -16,6 +16,7 @@
24247  #include <linux/module.h>
24248  #include <linux/syscalls.h>
24249  #include <linux/mmu_notifier.h>
24250 +#include <linux/vs_memory.h>
24251  
24252  #include <asm/mmu_context.h>
24253  #include <asm/cacheflush.h>
24254 diff -NurpP --minimal linux-3.0-rc5/mm/hugetlb.c linux-3.0-rc5-vs2.3.1-pre3/mm/hugetlb.c
24255 --- linux-3.0-rc5/mm/hugetlb.c  2011-07-01 11:14:23.000000000 +0200
24256 +++ linux-3.0-rc5-vs2.3.1-pre3/mm/hugetlb.c     2011-06-22 12:39:16.000000000 +0200
24257 @@ -28,6 +28,7 @@
24258  
24259  #include <linux/hugetlb.h>
24260  #include <linux/node.h>
24261 +#include <linux/vs_memory.h>
24262  #include "internal.h"
24263  
24264  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
24265 diff -NurpP --minimal linux-3.0-rc5/mm/memcontrol.c linux-3.0-rc5-vs2.3.1-pre3/mm/memcontrol.c
24266 --- linux-3.0-rc5/mm/memcontrol.c       2011-07-01 11:14:23.000000000 +0200
24267 +++ linux-3.0-rc5-vs2.3.1-pre3/mm/memcontrol.c  2011-07-01 11:35:35.000000000 +0200
24268 @@ -736,6 +736,31 @@ struct mem_cgroup *mem_cgroup_from_task(
24269                                 struct mem_cgroup, css);
24270  }
24271  
24272 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
24273 +{
24274 +       return res_counter_read_u64(&mem->res, member);
24275 +}
24276 +
24277 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
24278 +{
24279 +       return res_counter_read_u64(&mem->memsw, member);
24280 +}
24281 +
24282 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
24283 +{
24284 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
24285 +}
24286 +
24287 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
24288 +{
24289 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
24290 +}
24291 +
24292 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
24293 +{
24294 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
24295 +}
24296 +
24297  struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
24298  {
24299         struct mem_cgroup *mem = NULL;
24300 diff -NurpP --minimal linux-3.0-rc5/mm/memory.c linux-3.0-rc5-vs2.3.1-pre3/mm/memory.c
24301 --- linux-3.0-rc5/mm/memory.c   2011-07-01 11:14:23.000000000 +0200
24302 +++ linux-3.0-rc5-vs2.3.1-pre3/mm/memory.c      2011-07-01 11:35:35.000000000 +0200
24303 @@ -3331,6 +3331,7 @@ int handle_pte_fault(struct mm_struct *m
24304  {
24305         pte_t entry;
24306         spinlock_t *ptl;
24307 +       int ret = 0, type = VXPT_UNKNOWN;
24308  
24309         entry = *pte;
24310         if (!pte_present(entry)) {
24311 @@ -3355,9 +3356,12 @@ int handle_pte_fault(struct mm_struct *m
24312         if (unlikely(!pte_same(*pte, entry)))
24313                 goto unlock;
24314         if (flags & FAULT_FLAG_WRITE) {
24315 -               if (!pte_write(entry))
24316 -                       return do_wp_page(mm, vma, address,
24317 +               if (!pte_write(entry)) {
24318 +                       ret = do_wp_page(mm, vma, address,
24319                                         pte, pmd, ptl, entry);
24320 +                       type = VXPT_WRITE;
24321 +                       goto out;
24322 +               }
24323                 entry = pte_mkdirty(entry);
24324         }
24325         entry = pte_mkyoung(entry);
24326 @@ -3375,7 +3379,10 @@ int handle_pte_fault(struct mm_struct *m
24327         }
24328  unlock:
24329         pte_unmap_unlock(pte, ptl);
24330 -       return 0;
24331 +       ret = 0;
24332 +out:
24333 +       vx_page_fault(mm, vma, type, ret);
24334 +       return ret;
24335  }
24336  
24337  /*
24338 diff -NurpP --minimal linux-3.0-rc5/mm/mremap.c linux-3.0-rc5-vs2.3.1-pre3/mm/mremap.c
24339 --- linux-3.0-rc5/mm/mremap.c   2011-07-01 11:14:23.000000000 +0200
24340 +++ linux-3.0-rc5-vs2.3.1-pre3/mm/mremap.c      2011-06-10 22:11:24.000000000 +0200
24341 @@ -19,6 +19,7 @@
24342  #include <linux/security.h>
24343  #include <linux/syscalls.h>
24344  #include <linux/mmu_notifier.h>
24345 +#include <linux/vs_memory.h>
24346  
24347  #include <asm/uaccess.h>
24348  #include <asm/cacheflush.h>
24349 diff -NurpP --minimal linux-3.0-rc5/mm/oom_kill.c linux-3.0-rc5-vs2.3.1-pre3/mm/oom_kill.c
24350 --- linux-3.0-rc5/mm/oom_kill.c 2011-07-01 11:14:23.000000000 +0200
24351 +++ linux-3.0-rc5-vs2.3.1-pre3/mm/oom_kill.c    2011-06-10 22:11:24.000000000 +0200
24352 @@ -32,6 +32,9 @@
24353  #include <linux/mempolicy.h>
24354  #include <linux/security.h>
24355  #include <linux/ptrace.h>
24356 +#include <linux/reboot.h>
24357 +#include <linux/vs_memory.h>
24358 +#include <linux/vs_context.h>
24359  
24360  int sysctl_panic_on_oom;
24361  int sysctl_oom_kill_allocating_task;
24362 @@ -134,11 +137,18 @@ struct task_struct *find_lock_task_mm(st
24363  static bool oom_unkillable_task(struct task_struct *p,
24364                 const struct mem_cgroup *mem, const nodemask_t *nodemask)
24365  {
24366 -       if (is_global_init(p))
24367 +       unsigned xid = vx_current_xid();
24368 +
24369 +       /* skip the init task, global and per guest */
24370 +       if (task_is_init(p))
24371                 return true;
24372         if (p->flags & PF_KTHREAD)
24373                 return true;
24374  
24375 +       /* skip other guest and host processes if oom in guest */
24376 +       if (xid && vx_task_xid(p) != xid)
24377 +               return true;
24378 +
24379         /* When mem_cgroup_out_of_memory() and p is not member of the group */
24380         if (mem && !task_in_mem_cgroup(p, mem))
24381                 return true;
24382 @@ -214,6 +224,18 @@ unsigned int oom_badness(struct task_str
24383         points += p->signal->oom_score_adj;
24384  
24385         /*
24386 +        * add points for context badness and
24387 +        * reduce badness for processes belonging to
24388 +        * a different context
24389 +        */
24390 +
24391 +       points += vx_badness(p, p->mm);
24392 +
24393 +       if ((vx_current_xid() > 1) &&
24394 +               vx_current_xid() != vx_task_xid(p))
24395 +               points /= 16;
24396 +
24397 +       /*
24398          * Never return 0 for an eligible task that may be killed since it's
24399          * possible that no single user task uses more than 0.1% of memory and
24400          * no single admin tasks uses more than 3.0%.
24401 @@ -427,8 +449,8 @@ static int oom_kill_task(struct task_str
24402         /* mm cannot be safely dereferenced after task_unlock(p) */
24403         mm = p->mm;
24404  
24405 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
24406 -               task_pid_nr(p), p->comm, K(p->mm->total_vm),
24407 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
24408 +               task_pid_nr(p), p->xid, p->comm, K(p->mm->total_vm),
24409                 K(get_mm_counter(p->mm, MM_ANONPAGES)),
24410                 K(get_mm_counter(p->mm, MM_FILEPAGES)));
24411         task_unlock(p);
24412 @@ -482,8 +504,8 @@ static int oom_kill_process(struct task_
24413         }
24414  
24415         task_lock(p);
24416 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
24417 -               message, task_pid_nr(p), p->comm, points);
24418 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
24419 +               message, task_pid_nr(p), p->xid, p->comm, points);
24420         task_unlock(p);
24421  
24422         /*
24423 @@ -584,6 +606,8 @@ int unregister_oom_notifier(struct notif
24424  }
24425  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
24426  
24427 +long vs_oom_action(unsigned int);
24428 +
24429  /*
24430   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
24431   * if a parallel OOM killing is already taking place that includes a zone in
24432 @@ -742,7 +766,12 @@ retry:
24433         if (!p) {
24434                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
24435                 read_unlock(&tasklist_lock);
24436 -               panic("Out of memory and no killable processes...\n");
24437 +
24438 +               /* avoid panic for guest OOM */
24439 +               if (current->xid)
24440 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
24441 +               else
24442 +                       panic("Out of memory and no killable processes...\n");
24443         }
24444  
24445         if (oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
24446 diff -NurpP --minimal linux-3.0-rc5/mm/page_alloc.c linux-3.0-rc5-vs2.3.1-pre3/mm/page_alloc.c
24447 --- linux-3.0-rc5/mm/page_alloc.c       2011-07-01 11:14:23.000000000 +0200
24448 +++ linux-3.0-rc5-vs2.3.1-pre3/mm/page_alloc.c  2011-06-10 22:24:12.000000000 +0200
24449 @@ -57,6 +57,8 @@
24450  #include <linux/ftrace_event.h>
24451  #include <linux/memcontrol.h>
24452  #include <linux/prefetch.h>
24453 +#include <linux/vs_base.h>
24454 +#include <linux/vs_limit.h>
24455  
24456  #include <asm/tlbflush.h>
24457  #include <asm/div64.h>
24458 @@ -2470,6 +2472,9 @@ void si_meminfo(struct sysinfo *val)
24459         val->totalhigh = totalhigh_pages;
24460         val->freehigh = nr_free_highpages();
24461         val->mem_unit = PAGE_SIZE;
24462 +
24463 +       if (vx_flags(VXF_VIRT_MEM, 0))
24464 +               vx_vsi_meminfo(val);
24465  }
24466  
24467  EXPORT_SYMBOL(si_meminfo);
24468 @@ -2490,6 +2495,9 @@ void si_meminfo_node(struct sysinfo *val
24469         val->freehigh = 0;
24470  #endif
24471         val->mem_unit = PAGE_SIZE;
24472 +
24473 +       if (vx_flags(VXF_VIRT_MEM, 0))
24474 +               vx_vsi_meminfo(val);
24475  }
24476  #endif
24477  
24478 diff -NurpP --minimal linux-3.0-rc5/mm/pgtable-generic.c linux-3.0-rc5-vs2.3.1-pre3/mm/pgtable-generic.c
24479 --- linux-3.0-rc5/mm/pgtable-generic.c  2011-03-15 18:07:42.000000000 +0100
24480 +++ linux-3.0-rc5-vs2.3.1-pre3/mm/pgtable-generic.c     2011-06-10 22:11:24.000000000 +0200
24481 @@ -6,6 +6,8 @@
24482   *  Copyright (C) 2010  Linus Torvalds
24483   */
24484  
24485 +#include <linux/mm.h>
24486 +
24487  #include <linux/pagemap.h>
24488  #include <asm/tlb.h>
24489  #include <asm-generic/pgtable.h>
24490 diff -NurpP --minimal linux-3.0-rc5/mm/rmap.c linux-3.0-rc5-vs2.3.1-pre3/mm/rmap.c
24491 --- linux-3.0-rc5/mm/rmap.c     2011-07-01 11:14:23.000000000 +0200
24492 +++ linux-3.0-rc5-vs2.3.1-pre3/mm/rmap.c        2011-07-01 11:35:35.000000000 +0200
24493 @@ -57,6 +57,7 @@
24494  #include <linux/mmu_notifier.h>
24495  #include <linux/migrate.h>
24496  #include <linux/hugetlb.h>
24497 +#include <linux/vs_memory.h>
24498  
24499  #include <asm/tlbflush.h>
24500  
24501 diff -NurpP --minimal linux-3.0-rc5/mm/shmem.c linux-3.0-rc5-vs2.3.1-pre3/mm/shmem.c
24502 --- linux-3.0-rc5/mm/shmem.c    2011-07-01 11:14:23.000000000 +0200
24503 +++ linux-3.0-rc5-vs2.3.1-pre3/mm/shmem.c       2011-07-01 11:35:35.000000000 +0200
24504 @@ -1850,7 +1850,7 @@ static int shmem_statfs(struct dentry *d
24505  {
24506         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
24507  
24508 -       buf->f_type = TMPFS_MAGIC;
24509 +       buf->f_type = TMPFS_SUPER_MAGIC;
24510         buf->f_bsize = PAGE_CACHE_SIZE;
24511         buf->f_namelen = NAME_MAX;
24512         if (sbinfo->max_blocks) {
24513 @@ -2605,7 +2605,7 @@ int shmem_fill_super(struct super_block 
24514         sb->s_maxbytes = SHMEM_MAX_BYTES;
24515         sb->s_blocksize = PAGE_CACHE_SIZE;
24516         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
24517 -       sb->s_magic = TMPFS_MAGIC;
24518 +       sb->s_magic = TMPFS_SUPER_MAGIC;
24519         sb->s_op = &shmem_ops;
24520         sb->s_time_gran = 1;
24521  #ifdef CONFIG_TMPFS_XATTR
24522 diff -NurpP --minimal linux-3.0-rc5/mm/slab.c linux-3.0-rc5-vs2.3.1-pre3/mm/slab.c
24523 --- linux-3.0-rc5/mm/slab.c     2011-07-01 11:14:23.000000000 +0200
24524 +++ linux-3.0-rc5-vs2.3.1-pre3/mm/slab.c        2011-06-15 02:41:23.000000000 +0200
24525 @@ -411,6 +411,8 @@ static void kmem_list3_init(struct kmem_
24526  #define STATS_INC_FREEMISS(x)  do { } while (0)
24527  #endif
24528  
24529 +#include "slab_vs.h"
24530 +
24531  #if DEBUG
24532  
24533  /*
24534 @@ -3348,6 +3350,7 @@ retry:
24535  
24536         obj = slab_get_obj(cachep, slabp, nodeid);
24537         check_slabp(cachep, slabp);
24538 +       vx_slab_alloc(cachep, flags);
24539         l3->free_objects--;
24540         /* move slabp to correct slabp list: */
24541         list_del(&slabp->list);
24542 @@ -3425,6 +3428,7 @@ __cache_alloc_node(struct kmem_cache *ca
24543         /* ___cache_alloc_node can fall back to other nodes */
24544         ptr = ____cache_alloc_node(cachep, flags, nodeid);
24545    out:
24546 +       vx_slab_alloc(cachep, flags);
24547         local_irq_restore(save_flags);
24548         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
24549         kmemleak_alloc_recursive(ptr, obj_size(cachep), 1, cachep->flags,
24550 @@ -3612,6 +3616,7 @@ static inline void __cache_free(struct k
24551         check_irq_off();
24552         kmemleak_free_recursive(objp, cachep->flags);
24553         objp = cache_free_debugcheck(cachep, objp, caller);
24554 +       vx_slab_free(cachep);
24555  
24556         kmemcheck_slab_free(cachep, objp, obj_size(cachep));
24557  
24558 diff -NurpP --minimal linux-3.0-rc5/mm/slab_vs.h linux-3.0-rc5-vs2.3.1-pre3/mm/slab_vs.h
24559 --- linux-3.0-rc5/mm/slab_vs.h  1970-01-01 01:00:00.000000000 +0100
24560 +++ linux-3.0-rc5-vs2.3.1-pre3/mm/slab_vs.h     2011-06-10 22:11:24.000000000 +0200
24561 @@ -0,0 +1,29 @@
24562 +
24563 +#include <linux/vserver/context.h>
24564 +
24565 +#include <linux/vs_context.h>
24566 +
24567 +static inline
24568 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
24569 +{
24570 +       int what = gfp_zone(cachep->gfpflags);
24571 +       struct vx_info *vxi = current_vx_info();
24572 +
24573 +       if (!vxi)
24574 +               return;
24575 +
24576 +       atomic_add(cachep->buffer_size, &vxi->cacct.slab[what]);
24577 +}
24578 +
24579 +static inline
24580 +void vx_slab_free(struct kmem_cache *cachep)
24581 +{
24582 +       int what = gfp_zone(cachep->gfpflags);
24583 +       struct vx_info *vxi = current_vx_info();
24584 +
24585 +       if (!vxi)
24586 +               return;
24587 +
24588 +       atomic_sub(cachep->buffer_size, &vxi->cacct.slab[what]);
24589 +}
24590 +
24591 diff -NurpP --minimal linux-3.0-rc5/mm/swapfile.c linux-3.0-rc5-vs2.3.1-pre3/mm/swapfile.c
24592 --- linux-3.0-rc5/mm/swapfile.c 2011-07-01 11:14:23.000000000 +0200
24593 +++ linux-3.0-rc5-vs2.3.1-pre3/mm/swapfile.c    2011-07-01 11:35:35.000000000 +0200
24594 @@ -37,6 +37,8 @@
24595  #include <asm/tlbflush.h>
24596  #include <linux/swapops.h>
24597  #include <linux/page_cgroup.h>
24598 +#include <linux/vs_base.h>
24599 +#include <linux/vs_memory.h>
24600  
24601  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
24602                                  unsigned char);
24603 @@ -1759,6 +1761,16 @@ static int swap_show(struct seq_file *sw
24604  
24605         if (si == SEQ_START_TOKEN) {
24606                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
24607 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
24608 +                       struct sysinfo si;
24609 +
24610 +                       vx_vsi_swapinfo(&si);
24611 +                       if (si.totalswap < (1 << 10))
24612 +                               return 0;
24613 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
24614 +                               "hdv0", "partition", si.totalswap >> 10,
24615 +                               (si.totalswap - si.freeswap) >> 10, -1);
24616 +               }
24617                 return 0;
24618         }
24619  
24620 @@ -2186,6 +2198,8 @@ void si_swapinfo(struct sysinfo *val)
24621         val->freeswap = nr_swap_pages + nr_to_be_unused;
24622         val->totalswap = total_swap_pages + nr_to_be_unused;
24623         spin_unlock(&swap_lock);
24624 +       if (vx_flags(VXF_VIRT_MEM, 0))
24625 +               vx_vsi_swapinfo(val);
24626  }
24627  
24628  /*
24629 diff -NurpP --minimal linux-3.0-rc5/net/bridge/br_multicast.c linux-3.0-rc5-vs2.3.1-pre3/net/bridge/br_multicast.c
24630 --- linux-3.0-rc5/net/bridge/br_multicast.c     2011-07-01 11:14:26.000000000 +0200
24631 +++ linux-3.0-rc5-vs2.3.1-pre3/net/bridge/br_multicast.c        2011-06-22 12:39:16.000000000 +0200
24632 @@ -447,7 +447,7 @@ static struct sk_buff *br_ip6_multicast_
24633         ip6h->hop_limit = 1;
24634         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
24635         ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
24636 -                          &ip6h->saddr);
24637 +                          &ip6h->saddr, NULL);
24638         ipv6_eth_mc_map(&ip6h->daddr, eth->h_dest);
24639  
24640         hopopt = (u8 *)(ip6h + 1);
24641 diff -NurpP --minimal linux-3.0-rc5/net/core/dev.c linux-3.0-rc5-vs2.3.1-pre3/net/core/dev.c
24642 --- linux-3.0-rc5/net/core/dev.c        2011-07-01 11:14:26.000000000 +0200
24643 +++ linux-3.0-rc5-vs2.3.1-pre3/net/core/dev.c   2011-06-15 02:40:14.000000000 +0200
24644 @@ -127,6 +127,7 @@
24645  #include <linux/in.h>
24646  #include <linux/jhash.h>
24647  #include <linux/random.h>
24648 +#include <linux/vs_inet.h>
24649  #include <trace/events/napi.h>
24650  #include <trace/events/net.h>
24651  #include <trace/events/skb.h>
24652 @@ -609,7 +610,8 @@ struct net_device *__dev_get_by_name(str
24653         struct hlist_head *head = dev_name_hash(net, name);
24654  
24655         hlist_for_each_entry(dev, p, head, name_hlist)
24656 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24657 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24658 +                   nx_dev_visible(current_nx_info(), dev))
24659                         return dev;
24660  
24661         return NULL;
24662 @@ -635,7 +637,8 @@ struct net_device *dev_get_by_name_rcu(s
24663         struct hlist_head *head = dev_name_hash(net, name);
24664  
24665         hlist_for_each_entry_rcu(dev, p, head, name_hlist)
24666 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24667 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24668 +                   nx_dev_visible(current_nx_info(), dev))
24669                         return dev;
24670  
24671         return NULL;
24672 @@ -686,7 +689,8 @@ struct net_device *__dev_get_by_index(st
24673         struct hlist_head *head = dev_index_hash(net, ifindex);
24674  
24675         hlist_for_each_entry(dev, p, head, index_hlist)
24676 -               if (dev->ifindex == ifindex)
24677 +               if ((dev->ifindex == ifindex) &&
24678 +                   nx_dev_visible(current_nx_info(), dev))
24679                         return dev;
24680  
24681         return NULL;
24682 @@ -711,7 +715,8 @@ struct net_device *dev_get_by_index_rcu(
24683         struct hlist_head *head = dev_index_hash(net, ifindex);
24684  
24685         hlist_for_each_entry_rcu(dev, p, head, index_hlist)
24686 -               if (dev->ifindex == ifindex)
24687 +               if ((dev->ifindex == ifindex) &&
24688 +                   nx_dev_visible(current_nx_info(), dev))
24689                         return dev;
24690  
24691         return NULL;
24692 @@ -764,7 +769,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
24693  
24694         for_each_netdev_rcu(net, dev)
24695                 if (dev->type == type &&
24696 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
24697 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
24698 +                   nx_dev_visible(current_nx_info(), dev))
24699                         return dev;
24700  
24701         return NULL;
24702 @@ -776,9 +782,11 @@ struct net_device *__dev_getfirstbyhwtyp
24703         struct net_device *dev;
24704  
24705         ASSERT_RTNL();
24706 -       for_each_netdev(net, dev)
24707 -               if (dev->type == type)
24708 +       for_each_netdev(net, dev) {
24709 +               if ((dev->type == type) &&
24710 +                   nx_dev_visible(current_nx_info(), dev))
24711                         return dev;
24712 +       }
24713  
24714         return NULL;
24715  }
24716 @@ -896,6 +904,8 @@ static int __dev_alloc_name(struct net *
24717                                 continue;
24718                         if (i < 0 || i >= max_netdevices)
24719                                 continue;
24720 +                       if (!nx_dev_visible(current_nx_info(), d))
24721 +                               continue;
24722  
24723                         /*  avoid cases where sscanf is not exact inverse of printf */
24724                         snprintf(buf, IFNAMSIZ, name, i);
24725 @@ -3937,6 +3947,8 @@ static int dev_ifconf(struct net *net, c
24726  
24727         total = 0;
24728         for_each_netdev(net, dev) {
24729 +               if (!nx_dev_visible(current_nx_info(), dev))
24730 +                       continue;
24731                 for (i = 0; i < NPROTO; i++) {
24732                         if (gifconf_list[i]) {
24733                                 int done;
24734 @@ -4011,6 +4023,10 @@ static void dev_seq_printf_stats(struct 
24735         struct rtnl_link_stats64 temp;
24736         const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
24737  
24738 +       /* device visible inside network context? */
24739 +       if (!nx_dev_visible(current_nx_info(), dev))
24740 +               return;
24741 +
24742         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
24743                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
24744                    dev->name, stats->rx_bytes, stats->rx_packets,
24745 diff -NurpP --minimal linux-3.0-rc5/net/core/rtnetlink.c linux-3.0-rc5-vs2.3.1-pre3/net/core/rtnetlink.c
24746 --- linux-3.0-rc5/net/core/rtnetlink.c  2011-07-01 11:14:26.000000000 +0200
24747 +++ linux-3.0-rc5-vs2.3.1-pre3/net/core/rtnetlink.c     2011-06-10 22:11:24.000000000 +0200
24748 @@ -1015,6 +1015,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
24749                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
24750                         if (idx < s_idx)
24751                                 goto cont;
24752 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
24753 +                               continue;
24754                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
24755                                              NETLINK_CB(cb->skb).pid,
24756                                              cb->nlh->nlmsg_seq, 0,
24757 @@ -1848,6 +1850,9 @@ void rtmsg_ifinfo(int type, struct net_d
24758         struct sk_buff *skb;
24759         int err = -ENOBUFS;
24760  
24761 +       if (!nx_dev_visible(current_nx_info(), dev))
24762 +               return;
24763 +
24764         skb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL);
24765         if (skb == NULL)
24766                 goto errout;
24767 diff -NurpP --minimal linux-3.0-rc5/net/core/sock.c linux-3.0-rc5-vs2.3.1-pre3/net/core/sock.c
24768 --- linux-3.0-rc5/net/core/sock.c       2011-05-22 16:18:00.000000000 +0200
24769 +++ linux-3.0-rc5-vs2.3.1-pre3/net/core/sock.c  2011-06-10 22:11:24.000000000 +0200
24770 @@ -127,6 +127,10 @@
24771  #include <net/cls_cgroup.h>
24772  
24773  #include <linux/filter.h>
24774 +#include <linux/vs_socket.h>
24775 +#include <linux/vs_limit.h>
24776 +#include <linux/vs_context.h>
24777 +#include <linux/vs_network.h>
24778  
24779  #ifdef CONFIG_INET
24780  #include <net/tcp.h>
24781 @@ -1070,6 +1074,8 @@ static struct sock *sk_prot_alloc(struct
24782                         goto out_free_sec;
24783                 sk_tx_queue_clear(sk);
24784         }
24785 +               sock_vx_init(sk);
24786 +               sock_nx_init(sk);
24787  
24788         return sk;
24789  
24790 @@ -1169,6 +1175,11 @@ static void __sk_free(struct sock *sk)
24791                 put_cred(sk->sk_peer_cred);
24792         put_pid(sk->sk_peer_pid);
24793         put_net(sock_net(sk));
24794 +       vx_sock_dec(sk);
24795 +       clr_vx_info(&sk->sk_vx_info);
24796 +       sk->sk_xid = -1;
24797 +       clr_nx_info(&sk->sk_nx_info);
24798 +       sk->sk_nid = -1;
24799         sk_prot_free(sk->sk_prot_creator, sk);
24800  }
24801  
24802 @@ -1216,6 +1227,8 @@ struct sock *sk_clone(const struct sock 
24803  
24804                 /* SANITY */
24805                 get_net(sock_net(newsk));
24806 +               sock_vx_init(newsk);
24807 +               sock_nx_init(newsk);
24808                 sk_node_init(&newsk->sk_node);
24809                 sock_lock_init(newsk);
24810                 bh_lock_sock(newsk);
24811 @@ -1271,6 +1284,12 @@ struct sock *sk_clone(const struct sock 
24812                 smp_wmb();
24813                 atomic_set(&newsk->sk_refcnt, 2);
24814  
24815 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
24816 +               newsk->sk_xid = sk->sk_xid;
24817 +               vx_sock_inc(newsk);
24818 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
24819 +               newsk->sk_nid = sk->sk_nid;
24820 +
24821                 /*
24822                  * Increment the counter in the same struct proto as the master
24823                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
24824 @@ -2017,6 +2036,12 @@ void sock_init_data(struct socket *sock,
24825  
24826         sk->sk_stamp = ktime_set(-1L, 0);
24827  
24828 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
24829 +       sk->sk_xid = vx_current_xid();
24830 +       vx_sock_inc(sk);
24831 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
24832 +       sk->sk_nid = nx_current_nid();
24833 +
24834         /*
24835          * Before updating sk_refcnt, we must commit prior changes to memory
24836          * (Documentation/RCU/rculist_nulls.txt for details)
24837 diff -NurpP --minimal linux-3.0-rc5/net/ipv4/af_inet.c linux-3.0-rc5-vs2.3.1-pre3/net/ipv4/af_inet.c
24838 --- linux-3.0-rc5/net/ipv4/af_inet.c    2011-07-01 11:14:26.000000000 +0200
24839 +++ linux-3.0-rc5-vs2.3.1-pre3/net/ipv4/af_inet.c       2011-06-22 12:39:16.000000000 +0200
24840 @@ -117,6 +117,7 @@
24841  #ifdef CONFIG_IP_MROUTE
24842  #include <linux/mroute.h>
24843  #endif
24844 +#include <linux/vs_limit.h>
24845  
24846  
24847  /* The inetsw table contains everything that inet_create needs to
24848 @@ -326,9 +327,13 @@ lookup_protocol:
24849         }
24850  
24851         err = -EPERM;
24852 +       if ((protocol == IPPROTO_ICMP) &&
24853 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24854 +               goto override;
24855 +
24856         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
24857                 goto out_rcu_unlock;
24858 -
24859 +override:
24860         err = -EAFNOSUPPORT;
24861         if (!inet_netns_ok(net, protocol))
24862                 goto out_rcu_unlock;
24863 @@ -452,6 +457,7 @@ int inet_bind(struct socket *sock, struc
24864         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
24865         struct sock *sk = sock->sk;
24866         struct inet_sock *inet = inet_sk(sk);
24867 +       struct nx_v4_sock_addr nsa;
24868         unsigned short snum;
24869         int chk_addr_ret;
24870         int err;
24871 @@ -468,7 +474,11 @@ int inet_bind(struct socket *sock, struc
24872         if (addr->sin_family != AF_INET)
24873                 goto out;
24874  
24875 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24876 +       err = v4_map_sock_addr(inet, addr, &nsa);
24877 +       if (err)
24878 +               goto out;
24879 +
24880 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24881  
24882         /* Not specified by any standard per-se, however it breaks too
24883          * many applications when removed.  It is unfortunate since
24884 @@ -480,7 +490,7 @@ int inet_bind(struct socket *sock, struc
24885         err = -EADDRNOTAVAIL;
24886         if (!sysctl_ip_nonlocal_bind &&
24887             !(inet->freebind || inet->transparent) &&
24888 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
24889 +           nsa.saddr != htonl(INADDR_ANY) &&
24890             chk_addr_ret != RTN_LOCAL &&
24891             chk_addr_ret != RTN_MULTICAST &&
24892             chk_addr_ret != RTN_BROADCAST)
24893 @@ -505,7 +515,7 @@ int inet_bind(struct socket *sock, struc
24894         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
24895                 goto out_release_sock;
24896  
24897 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24898 +       v4_set_sock_addr(inet, &nsa);
24899         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24900                 inet->inet_saddr = 0;  /* Use device */
24901  
24902 @@ -708,11 +718,13 @@ int inet_getname(struct socket *sock, st
24903                      peer == 1))
24904                         return -ENOTCONN;
24905                 sin->sin_port = inet->inet_dport;
24906 -               sin->sin_addr.s_addr = inet->inet_daddr;
24907 +               sin->sin_addr.s_addr =
24908 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
24909         } else {
24910                 __be32 addr = inet->inet_rcv_saddr;
24911                 if (!addr)
24912                         addr = inet->inet_saddr;
24913 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
24914                 sin->sin_port = inet->inet_sport;
24915                 sin->sin_addr.s_addr = addr;
24916         }
24917 diff -NurpP --minimal linux-3.0-rc5/net/ipv4/devinet.c linux-3.0-rc5-vs2.3.1-pre3/net/ipv4/devinet.c
24918 --- linux-3.0-rc5/net/ipv4/devinet.c    2011-07-01 11:14:26.000000000 +0200
24919 +++ linux-3.0-rc5-vs2.3.1-pre3/net/ipv4/devinet.c       2011-06-10 22:11:24.000000000 +0200
24920 @@ -518,6 +518,7 @@ struct in_device *inetdev_by_index(struc
24921  }
24922  EXPORT_SYMBOL(inetdev_by_index);
24923  
24924 +
24925  /* Called only from RTNL semaphored context. No locks. */
24926  
24927  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
24928 @@ -759,6 +760,8 @@ int devinet_ioctl(struct net *net, unsig
24929  
24930         in_dev = __in_dev_get_rtnl(dev);
24931         if (in_dev) {
24932 +               struct nx_info *nxi = current_nx_info();
24933 +
24934                 if (tryaddrmatch) {
24935                         /* Matthias Andree */
24936                         /* compare label and address (4.4BSD style) */
24937 @@ -767,6 +770,8 @@ int devinet_ioctl(struct net *net, unsig
24938                            This is checked above. */
24939                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24940                              ifap = &ifa->ifa_next) {
24941 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24942 +                                       continue;
24943                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
24944                                     sin_orig.sin_addr.s_addr ==
24945                                                         ifa->ifa_local) {
24946 @@ -779,9 +784,12 @@ int devinet_ioctl(struct net *net, unsig
24947                    comparing just the label */
24948                 if (!ifa) {
24949                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24950 -                            ifap = &ifa->ifa_next)
24951 +                            ifap = &ifa->ifa_next) {
24952 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24953 +                                       continue;
24954                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
24955                                         break;
24956 +                       }
24957                 }
24958         }
24959  
24960 @@ -934,6 +942,8 @@ static int inet_gifconf(struct net_devic
24961                 goto out;
24962  
24963         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
24964 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
24965 +                       continue;
24966                 if (!buf) {
24967                         done += sizeof(ifr);
24968                         continue;
24969 @@ -1294,6 +1304,7 @@ static int inet_dump_ifaddr(struct sk_bu
24970         struct net_device *dev;
24971         struct in_device *in_dev;
24972         struct in_ifaddr *ifa;
24973 +       struct sock *sk = skb->sk;
24974         struct hlist_head *head;
24975         struct hlist_node *node;
24976  
24977 @@ -1316,6 +1327,8 @@ static int inet_dump_ifaddr(struct sk_bu
24978  
24979                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
24980                              ifa = ifa->ifa_next, ip_idx++) {
24981 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
24982 +                               continue;
24983                                 if (ip_idx < s_ip_idx)
24984                                         continue;
24985                                 if (inet_fill_ifaddr(skb, ifa,
24986 diff -NurpP --minimal linux-3.0-rc5/net/ipv4/inet_connection_sock.c linux-3.0-rc5-vs2.3.1-pre3/net/ipv4/inet_connection_sock.c
24987 --- linux-3.0-rc5/net/ipv4/inet_connection_sock.c       2011-07-01 11:14:26.000000000 +0200
24988 +++ linux-3.0-rc5-vs2.3.1-pre3/net/ipv4/inet_connection_sock.c  2011-06-10 22:11:24.000000000 +0200
24989 @@ -52,6 +52,37 @@ void inet_get_local_port_range(int *low,
24990  }
24991  EXPORT_SYMBOL(inet_get_local_port_range);
24992  
24993 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24994 +{
24995 +       __be32  sk1_rcv_saddr = sk_rcv_saddr(sk1),
24996 +               sk2_rcv_saddr = sk_rcv_saddr(sk2);
24997 +
24998 +       if (inet_v6_ipv6only(sk2))
24999 +               return 0;
25000 +
25001 +       if (sk1_rcv_saddr &&
25002 +           sk2_rcv_saddr &&
25003 +           sk1_rcv_saddr == sk2_rcv_saddr)
25004 +               return 1;
25005 +
25006 +       if (sk1_rcv_saddr &&
25007 +           !sk2_rcv_saddr &&
25008 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
25009 +               return 1;
25010 +
25011 +       if (sk2_rcv_saddr &&
25012 +           !sk1_rcv_saddr &&
25013 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
25014 +               return 1;
25015 +
25016 +       if (!sk1_rcv_saddr &&
25017 +           !sk2_rcv_saddr &&
25018 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
25019 +               return 1;
25020 +
25021 +       return 0;
25022 +}
25023 +
25024  int inet_csk_bind_conflict(const struct sock *sk,
25025                            const struct inet_bind_bucket *tb)
25026  {
25027 @@ -74,9 +105,7 @@ int inet_csk_bind_conflict(const struct 
25028                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
25029                         if (!reuse || !sk2->sk_reuse ||
25030                             sk2->sk_state == TCP_LISTEN) {
25031 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
25032 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
25033 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
25034 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
25035                                         break;
25036                         }
25037                 }
25038 diff -NurpP --minimal linux-3.0-rc5/net/ipv4/inet_diag.c linux-3.0-rc5-vs2.3.1-pre3/net/ipv4/inet_diag.c
25039 --- linux-3.0-rc5/net/ipv4/inet_diag.c  2011-07-01 11:14:26.000000000 +0200
25040 +++ linux-3.0-rc5-vs2.3.1-pre3/net/ipv4/inet_diag.c     2011-06-22 12:39:16.000000000 +0200
25041 @@ -33,6 +33,8 @@
25042  #include <linux/stddef.h>
25043  
25044  #include <linux/inet_diag.h>
25045 +#include <linux/vs_network.h>
25046 +#include <linux/vs_inet.h>
25047  
25048  static const struct inet_diag_handler **inet_diag_table;
25049  
25050 @@ -119,8 +121,10 @@ static int inet_csk_diag_fill(struct soc
25051  
25052         r->id.idiag_sport = inet->inet_sport;
25053         r->id.idiag_dport = inet->inet_dport;
25054 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
25055 -       r->id.idiag_dst[0] = inet->inet_daddr;
25056 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
25057 +               inet->inet_rcv_saddr);
25058 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
25059 +               inet->inet_daddr);
25060  
25061  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
25062         if (r->idiag_family == AF_INET6) {
25063 @@ -205,8 +209,8 @@ static int inet_twsk_diag_fill(struct in
25064         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
25065         r->id.idiag_sport     = tw->tw_sport;
25066         r->id.idiag_dport     = tw->tw_dport;
25067 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
25068 -       r->id.idiag_dst[0]    = tw->tw_daddr;
25069 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
25070 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
25071         r->idiag_state        = tw->tw_substate;
25072         r->idiag_timer        = 3;
25073         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
25074 @@ -263,6 +267,7 @@ static int inet_diag_get_exact(struct sk
25075         err = -EINVAL;
25076  
25077         if (req->idiag_family == AF_INET) {
25078 +               /* TODO: lback */
25079                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
25080                                  req->id.idiag_dport, req->id.idiag_src[0],
25081                                  req->id.idiag_sport, req->id.idiag_if);
25082 @@ -505,6 +510,7 @@ static int inet_csk_diag_dump(struct soc
25083                 } else
25084  #endif
25085                 {
25086 +                       /* TODO: lback */
25087                         entry.saddr = &inet->inet_rcv_saddr;
25088                         entry.daddr = &inet->inet_daddr;
25089                 }
25090 @@ -543,6 +549,7 @@ static int inet_twsk_diag_dump(struct in
25091                 } else
25092  #endif
25093                 {
25094 +                       /* TODO: lback */
25095                         entry.saddr = &tw->tw_rcv_saddr;
25096                         entry.daddr = &tw->tw_daddr;
25097                 }
25098 @@ -589,8 +596,8 @@ static int inet_diag_fill_req(struct sk_
25099  
25100         r->id.idiag_sport = inet->inet_sport;
25101         r->id.idiag_dport = ireq->rmt_port;
25102 -       r->id.idiag_src[0] = ireq->loc_addr;
25103 -       r->id.idiag_dst[0] = ireq->rmt_addr;
25104 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
25105 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
25106         r->idiag_expires = jiffies_to_msecs(tmo);
25107         r->idiag_rqueue = 0;
25108         r->idiag_wqueue = 0;
25109 @@ -661,6 +668,7 @@ static int inet_diag_dump_reqs(struct sk
25110                                 continue;
25111  
25112                         if (bc) {
25113 +                               /* TODO: lback */
25114                                 entry.saddr =
25115  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
25116                                         (entry.family == AF_INET6) ?
25117 @@ -731,6 +739,8 @@ static int inet_diag_dump(struct sk_buff
25118                         sk_nulls_for_each(sk, node, &ilb->head) {
25119                                 struct inet_sock *inet = inet_sk(sk);
25120  
25121 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25122 +                                       continue;
25123                                 if (num < s_num) {
25124                                         num++;
25125                                         continue;
25126 @@ -797,6 +807,8 @@ skip_listen_ht:
25127                 sk_nulls_for_each(sk, node, &head->chain) {
25128                         struct inet_sock *inet = inet_sk(sk);
25129  
25130 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25131 +                               continue;
25132                         if (num < s_num)
25133                                 goto next_normal;
25134                         if (!(r->idiag_states & (1 << sk->sk_state)))
25135 @@ -821,6 +833,8 @@ next_normal:
25136                         inet_twsk_for_each(tw, node,
25137                                     &head->twchain) {
25138  
25139 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
25140 +                                       continue;
25141                                 if (num < s_num)
25142                                         goto next_dying;
25143                                 if (r->id.idiag_sport != tw->tw_sport &&
25144 diff -NurpP --minimal linux-3.0-rc5/net/ipv4/inet_hashtables.c linux-3.0-rc5-vs2.3.1-pre3/net/ipv4/inet_hashtables.c
25145 --- linux-3.0-rc5/net/ipv4/inet_hashtables.c    2011-01-05 21:50:42.000000000 +0100
25146 +++ linux-3.0-rc5-vs2.3.1-pre3/net/ipv4/inet_hashtables.c       2011-06-10 22:11:24.000000000 +0200
25147 @@ -21,6 +21,7 @@
25148  
25149  #include <net/inet_connection_sock.h>
25150  #include <net/inet_hashtables.h>
25151 +#include <net/route.h>
25152  #include <net/ip.h>
25153  
25154  /*
25155 @@ -155,6 +156,11 @@ static inline int compute_score(struct s
25156                         if (rcv_saddr != daddr)
25157                                 return -1;
25158                         score += 2;
25159 +               } else {
25160 +                       /* block non nx_info ips */
25161 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
25162 +                               daddr, NXA_MASK_BIND))
25163 +                               return -1;
25164                 }
25165                 if (sk->sk_bound_dev_if) {
25166                         if (sk->sk_bound_dev_if != dif)
25167 @@ -172,7 +178,6 @@ static inline int compute_score(struct s
25168   * wildcarded during the search since they can never be otherwise.
25169   */
25170  
25171 -
25172  struct sock *__inet_lookup_listener(struct net *net,
25173                                     struct inet_hashinfo *hashinfo,
25174                                     const __be32 daddr, const unsigned short hnum,
25175 @@ -195,6 +200,7 @@ begin:
25176                         hiscore = score;
25177                 }
25178         }
25179 +
25180         /*
25181          * if the nulls value we got at the end of this lookup is
25182          * not the expected one, we must restart lookup.
25183 diff -NurpP --minimal linux-3.0-rc5/net/ipv4/netfilter/nf_nat_helper.c linux-3.0-rc5-vs2.3.1-pre3/net/ipv4/netfilter/nf_nat_helper.c
25184 --- linux-3.0-rc5/net/ipv4/netfilter/nf_nat_helper.c    2011-07-01 11:14:26.000000000 +0200
25185 +++ linux-3.0-rc5-vs2.3.1-pre3/net/ipv4/netfilter/nf_nat_helper.c       2011-06-15 02:40:14.000000000 +0200
25186 @@ -20,6 +20,7 @@
25187  #include <net/route.h>
25188  
25189  #include <linux/netfilter_ipv4.h>
25190 +#include <net/route.h>
25191  #include <net/netfilter/nf_conntrack.h>
25192  #include <net/netfilter/nf_conntrack_helper.h>
25193  #include <net/netfilter/nf_conntrack_ecache.h>
25194 diff -NurpP --minimal linux-3.0-rc5/net/ipv4/netfilter.c linux-3.0-rc5-vs2.3.1-pre3/net/ipv4/netfilter.c
25195 --- linux-3.0-rc5/net/ipv4/netfilter.c  2011-05-22 16:18:00.000000000 +0200
25196 +++ linux-3.0-rc5-vs2.3.1-pre3/net/ipv4/netfilter.c     2011-06-10 22:11:24.000000000 +0200
25197 @@ -5,7 +5,7 @@
25198  #include <linux/ip.h>
25199  #include <linux/skbuff.h>
25200  #include <linux/gfp.h>
25201 -#include <net/route.h>
25202 +// #include <net/route.h>
25203  #include <net/xfrm.h>
25204  #include <net/ip.h>
25205  #include <net/netfilter/nf_queue.h>
25206 diff -NurpP --minimal linux-3.0-rc5/net/ipv4/raw.c linux-3.0-rc5-vs2.3.1-pre3/net/ipv4/raw.c
25207 --- linux-3.0-rc5/net/ipv4/raw.c        2011-07-01 11:14:26.000000000 +0200
25208 +++ linux-3.0-rc5-vs2.3.1-pre3/net/ipv4/raw.c   2011-06-10 22:11:24.000000000 +0200
25209 @@ -117,7 +117,7 @@ static struct sock *__raw_v4_lookup(stru
25210  
25211                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
25212                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
25213 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
25214 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
25215                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
25216                         goto found; /* gotcha */
25217         }
25218 @@ -385,6 +385,12 @@ static int raw_send_hdrinc(struct sock *
25219                 icmp_out_count(net, ((struct icmphdr *)
25220                         skb_transport_header(skb))->type);
25221  
25222 +       err = -EPERM;
25223 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
25224 +               sk->sk_nx_info &&
25225 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
25226 +               goto error_free;
25227 +
25228         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
25229                       rt->dst.dev, dst_output);
25230         if (err > 0)
25231 @@ -647,17 +653,19 @@ static int raw_bind(struct sock *sk, str
25232  {
25233         struct inet_sock *inet = inet_sk(sk);
25234         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
25235 +       struct nx_v4_sock_addr nsa = { 0 };
25236         int ret = -EINVAL;
25237         int chk_addr_ret;
25238  
25239         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
25240                 goto out;
25241 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
25242 +       v4_map_sock_addr(inet, addr, &nsa);
25243 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
25244         ret = -EADDRNOTAVAIL;
25245 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
25246 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
25247             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
25248                 goto out;
25249 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
25250 +       v4_set_sock_addr(inet, &nsa);
25251         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
25252                 inet->inet_saddr = 0;  /* Use device */
25253         sk_dst_reset(sk);
25254 @@ -709,7 +717,8 @@ static int raw_recvmsg(struct kiocb *ioc
25255         /* Copy the address. */
25256         if (sin) {
25257                 sin->sin_family = AF_INET;
25258 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25259 +               sin->sin_addr.s_addr =
25260 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
25261                 sin->sin_port = 0;
25262                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
25263         }
25264 @@ -905,7 +914,8 @@ static struct sock *raw_get_first(struct
25265                 struct hlist_node *node;
25266  
25267                 sk_for_each(sk, node, &state->h->ht[state->bucket])
25268 -                       if (sock_net(sk) == seq_file_net(seq))
25269 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
25270 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25271                                 goto found;
25272         }
25273         sk = NULL;
25274 @@ -921,7 +931,8 @@ static struct sock *raw_get_next(struct 
25275                 sk = sk_next(sk);
25276  try_again:
25277                 ;
25278 -       } while (sk && sock_net(sk) != seq_file_net(seq));
25279 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
25280 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25281  
25282         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
25283                 sk = sk_head(&state->h->ht[state->bucket]);
25284 diff -NurpP --minimal linux-3.0-rc5/net/ipv4/tcp.c linux-3.0-rc5-vs2.3.1-pre3/net/ipv4/tcp.c
25285 --- linux-3.0-rc5/net/ipv4/tcp.c        2011-07-01 11:14:26.000000000 +0200
25286 +++ linux-3.0-rc5-vs2.3.1-pre3/net/ipv4/tcp.c   2011-06-10 22:11:24.000000000 +0200
25287 @@ -266,6 +266,7 @@
25288  #include <linux/crypto.h>
25289  #include <linux/time.h>
25290  #include <linux/slab.h>
25291 +#include <linux/in.h>
25292  
25293  #include <net/icmp.h>
25294  #include <net/tcp.h>
25295 diff -NurpP --minimal linux-3.0-rc5/net/ipv4/tcp_ipv4.c linux-3.0-rc5-vs2.3.1-pre3/net/ipv4/tcp_ipv4.c
25296 --- linux-3.0-rc5/net/ipv4/tcp_ipv4.c   2011-07-01 11:14:26.000000000 +0200
25297 +++ linux-3.0-rc5-vs2.3.1-pre3/net/ipv4/tcp_ipv4.c      2011-06-22 12:39:16.000000000 +0200
25298 @@ -2002,6 +2002,12 @@ static void *listening_get_next(struct s
25299                 req = req->dl_next;
25300                 while (1) {
25301                         while (req) {
25302 +                               vxdprintk(VXD_CBIT(net, 6),
25303 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
25304 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
25305 +                               if (req->sk &&
25306 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
25307 +                                       continue;
25308                                 if (req->rsk_ops->family == st->family) {
25309                                         cur = req;
25310                                         goto out;
25311 @@ -2026,6 +2032,10 @@ get_req:
25312         }
25313  get_sk:
25314         sk_nulls_for_each_from(sk, node) {
25315 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
25316 +                       sk, sk->sk_nid, nx_current_nid());
25317 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25318 +                       continue;
25319                 if (!net_eq(sock_net(sk), net))
25320                         continue;
25321                 if (sk->sk_family == st->family) {
25322 @@ -2102,6 +2112,11 @@ static void *established_get_first(struc
25323  
25324                 spin_lock_bh(lock);
25325                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
25326 +                       vxdprintk(VXD_CBIT(net, 6),
25327 +                               "sk,egf: %p [#%d] (from %d)",
25328 +                               sk, sk->sk_nid, nx_current_nid());
25329 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25330 +                               continue;
25331                         if (sk->sk_family != st->family ||
25332                             !net_eq(sock_net(sk), net)) {
25333                                 continue;
25334 @@ -2112,6 +2127,11 @@ static void *established_get_first(struc
25335                 st->state = TCP_SEQ_STATE_TIME_WAIT;
25336                 inet_twsk_for_each(tw, node,
25337                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
25338 +                       vxdprintk(VXD_CBIT(net, 6),
25339 +                               "tw: %p [#%d] (from %d)",
25340 +                               tw, tw->tw_nid, nx_current_nid());
25341 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
25342 +                               continue;
25343                         if (tw->tw_family != st->family ||
25344                             !net_eq(twsk_net(tw), net)) {
25345                                 continue;
25346 @@ -2141,7 +2161,9 @@ static void *established_get_next(struct
25347                 tw = cur;
25348                 tw = tw_next(tw);
25349  get_tw:
25350 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
25351 +               while (tw && (tw->tw_family != st->family ||
25352 +                       !net_eq(twsk_net(tw), net) ||
25353 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
25354                         tw = tw_next(tw);
25355                 }
25356                 if (tw) {
25357 @@ -2165,6 +2187,11 @@ get_tw:
25358                 sk = sk_nulls_next(sk);
25359  
25360         sk_nulls_for_each_from(sk, node) {
25361 +               vxdprintk(VXD_CBIT(net, 6),
25362 +                       "sk,egn: %p [#%d] (from %d)",
25363 +                       sk, sk->sk_nid, nx_current_nid());
25364 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25365 +                       continue;
25366                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
25367                         goto found;
25368         }
25369 @@ -2374,9 +2401,9 @@ static void get_openreq4(struct sock *sk
25370         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
25371                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %pK%n",
25372                 i,
25373 -               ireq->loc_addr,
25374 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
25375                 ntohs(inet_sk(sk)->inet_sport),
25376 -               ireq->rmt_addr,
25377 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
25378                 ntohs(ireq->rmt_port),
25379                 TCP_SYN_RECV,
25380                 0, 0, /* could print option size, but that is af dependent. */
25381 diff -NurpP --minimal linux-3.0-rc5/net/ipv4/tcp_minisocks.c linux-3.0-rc5-vs2.3.1-pre3/net/ipv4/tcp_minisocks.c
25382 --- linux-3.0-rc5/net/ipv4/tcp_minisocks.c      2011-03-15 18:07:45.000000000 +0100
25383 +++ linux-3.0-rc5-vs2.3.1-pre3/net/ipv4/tcp_minisocks.c 2011-06-10 22:11:24.000000000 +0200
25384 @@ -23,6 +23,9 @@
25385  #include <linux/slab.h>
25386  #include <linux/sysctl.h>
25387  #include <linux/workqueue.h>
25388 +#include <linux/vs_limit.h>
25389 +#include <linux/vs_socket.h>
25390 +#include <linux/vs_context.h>
25391  #include <net/tcp.h>
25392  #include <net/inet_common.h>
25393  #include <net/xfrm.h>
25394 @@ -335,6 +338,11 @@ void tcp_time_wait(struct sock *sk, int 
25395                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
25396                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
25397  
25398 +               tw->tw_xid              = sk->sk_xid;
25399 +               tw->tw_vx_info          = NULL;
25400 +               tw->tw_nid              = sk->sk_nid;
25401 +               tw->tw_nx_info          = NULL;
25402 +
25403  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
25404                 if (tw->tw_family == PF_INET6) {
25405                         struct ipv6_pinfo *np = inet6_sk(sk);
25406 diff -NurpP --minimal linux-3.0-rc5/net/ipv4/udp.c linux-3.0-rc5-vs2.3.1-pre3/net/ipv4/udp.c
25407 --- linux-3.0-rc5/net/ipv4/udp.c        2011-07-01 11:14:26.000000000 +0200
25408 +++ linux-3.0-rc5-vs2.3.1-pre3/net/ipv4/udp.c   2011-06-10 22:11:24.000000000 +0200
25409 @@ -296,14 +296,7 @@ fail:
25410  }
25411  EXPORT_SYMBOL(udp_lib_get_port);
25412  
25413 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25414 -{
25415 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
25416 -
25417 -       return  (!ipv6_only_sock(sk2)  &&
25418 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
25419 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
25420 -}
25421 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
25422  
25423  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
25424                                        unsigned int port)
25425 @@ -338,6 +331,11 @@ static inline int compute_score(struct s
25426                         if (inet->inet_rcv_saddr != daddr)
25427                                 return -1;
25428                         score += 2;
25429 +               } else {
25430 +                       /* block non nx_info ips */
25431 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
25432 +                               daddr, NXA_MASK_BIND))
25433 +                               return -1;
25434                 }
25435                 if (inet->inet_daddr) {
25436                         if (inet->inet_daddr != saddr)
25437 @@ -441,6 +439,7 @@ exact_match:
25438         return result;
25439  }
25440  
25441 +
25442  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
25443   * harder than this. -DaveM
25444   */
25445 @@ -486,6 +485,11 @@ begin:
25446         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
25447                 score = compute_score(sk, net, saddr, hnum, sport,
25448                                       daddr, dport, dif);
25449 +               /* FIXME: disabled?
25450 +               if (score == 9) {
25451 +                       result = sk;
25452 +                       break;
25453 +               } else */
25454                 if (score > badness) {
25455                         result = sk;
25456                         badness = score;
25457 @@ -499,6 +503,7 @@ begin:
25458         if (get_nulls_value(node) != slot)
25459                 goto begin;
25460  
25461 +
25462         if (result) {
25463                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
25464                         result = NULL;
25465 @@ -508,6 +513,7 @@ begin:
25466                         goto begin;
25467                 }
25468         }
25469 +
25470         rcu_read_unlock();
25471         return result;
25472  }
25473 @@ -550,8 +556,7 @@ static inline struct sock *udp_v4_mcast_
25474                     udp_sk(s)->udp_port_hash != hnum ||
25475                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
25476                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
25477 -                   (inet->inet_rcv_saddr &&
25478 -                    inet->inet_rcv_saddr != loc_addr) ||
25479 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
25480                     ipv6_only_sock(s) ||
25481                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
25482                         continue;
25483 @@ -1226,7 +1231,8 @@ try_again:
25484         if (sin) {
25485                 sin->sin_family = AF_INET;
25486                 sin->sin_port = udp_hdr(skb)->source;
25487 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25488 +               sin->sin_addr.s_addr = nx_map_sock_lback(
25489 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
25490                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
25491         }
25492         if (inet->cmsg_flags)
25493 @@ -1967,6 +1973,8 @@ static struct sock *udp_get_first(struct
25494                 sk_nulls_for_each(sk, node, &hslot->head) {
25495                         if (!net_eq(sock_net(sk), net))
25496                                 continue;
25497 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25498 +                               continue;
25499                         if (sk->sk_family == state->family)
25500                                 goto found;
25501                 }
25502 @@ -1984,7 +1992,9 @@ static struct sock *udp_get_next(struct 
25503  
25504         do {
25505                 sk = sk_nulls_next(sk);
25506 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
25507 +       } while (sk && (!net_eq(sock_net(sk), net) ||
25508 +               sk->sk_family != state->family ||
25509 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25510  
25511         if (!sk) {
25512                 if (state->bucket <= state->udp_table->mask)
25513 diff -NurpP --minimal linux-3.0-rc5/net/ipv6/Kconfig linux-3.0-rc5-vs2.3.1-pre3/net/ipv6/Kconfig
25514 --- linux-3.0-rc5/net/ipv6/Kconfig      2010-08-02 16:52:59.000000000 +0200
25515 +++ linux-3.0-rc5-vs2.3.1-pre3/net/ipv6/Kconfig 2011-06-10 22:11:24.000000000 +0200
25516 @@ -4,8 +4,8 @@
25517  
25518  #   IPv6 as module will cause a CRASH if you try to unload it
25519  menuconfig IPV6
25520 -       tristate "The IPv6 protocol"
25521 -       default m
25522 +       bool "The IPv6 protocol"
25523 +       default n
25524         ---help---
25525           This is complemental support for the IP version 6.
25526           You will still be able to do traditional IPv4 networking as well.
25527 diff -NurpP --minimal linux-3.0-rc5/net/ipv6/addrconf.c linux-3.0-rc5-vs2.3.1-pre3/net/ipv6/addrconf.c
25528 --- linux-3.0-rc5/net/ipv6/addrconf.c   2011-07-01 11:14:26.000000000 +0200
25529 +++ linux-3.0-rc5-vs2.3.1-pre3/net/ipv6/addrconf.c      2011-06-10 22:11:24.000000000 +0200
25530 @@ -87,6 +87,8 @@
25531  
25532  #include <linux/proc_fs.h>
25533  #include <linux/seq_file.h>
25534 +#include <linux/vs_network.h>
25535 +#include <linux/vs_inet6.h>
25536  
25537  /* Set to 3 to get tracing... */
25538  #define ACONF_DEBUG 2
25539 @@ -1108,7 +1110,7 @@ out:
25540  
25541  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
25542                        const struct in6_addr *daddr, unsigned int prefs,
25543 -                      struct in6_addr *saddr)
25544 +                      struct in6_addr *saddr, struct nx_info *nxi)
25545  {
25546         struct ipv6_saddr_score scores[2],
25547                                 *score = &scores[0], *hiscore = &scores[1];
25548 @@ -1180,6 +1182,8 @@ int ipv6_dev_get_saddr(struct net *net, 
25549                                                dev->name);
25550                                 continue;
25551                         }
25552 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
25553 +                               continue;
25554  
25555                         score->rule = -1;
25556                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
25557 @@ -3048,7 +3052,10 @@ static void if6_seq_stop(struct seq_file
25558  static int if6_seq_show(struct seq_file *seq, void *v)
25559  {
25560         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
25561 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25562 +
25563 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
25564 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
25565 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25566                    &ifp->addr,
25567                    ifp->idev->dev->ifindex,
25568                    ifp->prefix_len,
25569 @@ -3554,6 +3561,11 @@ static int in6_dump_addrs(struct inet6_d
25570         struct ifacaddr6 *ifaca;
25571         int err = 1;
25572         int ip_idx = *p_ip_idx;
25573 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25574 +
25575 +       /* disable ipv6 on non v6 guests */
25576 +       if (nxi && !nx_info_has_v6(nxi))
25577 +               return skb->len;
25578  
25579         read_lock_bh(&idev->lock);
25580         switch (type) {
25581 @@ -3564,6 +3576,8 @@ static int in6_dump_addrs(struct inet6_d
25582                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
25583                         if (++ip_idx < s_ip_idx)
25584                                 continue;
25585 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
25586 +                                       continue;
25587                         err = inet6_fill_ifaddr(skb, ifa,
25588                                                 NETLINK_CB(cb->skb).pid,
25589                                                 cb->nlh->nlmsg_seq,
25590 @@ -3580,6 +3594,8 @@ static int in6_dump_addrs(struct inet6_d
25591                      ifmca = ifmca->next, ip_idx++) {
25592                         if (ip_idx < s_ip_idx)
25593                                 continue;
25594 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
25595 +                                       continue;
25596                         err = inet6_fill_ifmcaddr(skb, ifmca,
25597                                                   NETLINK_CB(cb->skb).pid,
25598                                                   cb->nlh->nlmsg_seq,
25599 @@ -3595,6 +3611,8 @@ static int in6_dump_addrs(struct inet6_d
25600                      ifaca = ifaca->aca_next, ip_idx++) {
25601                         if (ip_idx < s_ip_idx)
25602                                 continue;
25603 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
25604 +                                       continue;
25605                         err = inet6_fill_ifacaddr(skb, ifaca,
25606                                                   NETLINK_CB(cb->skb).pid,
25607                                                   cb->nlh->nlmsg_seq,
25608 @@ -3980,6 +3998,11 @@ static int inet6_dump_ifinfo(struct sk_b
25609         struct inet6_dev *idev;
25610         struct hlist_head *head;
25611         struct hlist_node *node;
25612 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25613 +
25614 +       /* FIXME: maybe disable ipv6 on non v6 guests?
25615 +       if (skb->sk && skb->sk->sk_vx_info)
25616 +               return skb->len; */
25617  
25618         s_h = cb->args[0];
25619         s_idx = cb->args[1];
25620 @@ -3991,6 +4014,8 @@ static int inet6_dump_ifinfo(struct sk_b
25621                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
25622                         if (idx < s_idx)
25623                                 goto cont;
25624 +                       if (!v6_dev_in_nx_info(dev, nxi))
25625 +                               goto cont;
25626                         idev = __in6_dev_get(dev);
25627                         if (!idev)
25628                                 goto cont;
25629 diff -NurpP --minimal linux-3.0-rc5/net/ipv6/af_inet6.c linux-3.0-rc5-vs2.3.1-pre3/net/ipv6/af_inet6.c
25630 --- linux-3.0-rc5/net/ipv6/af_inet6.c   2011-07-01 11:14:26.000000000 +0200
25631 +++ linux-3.0-rc5-vs2.3.1-pre3/net/ipv6/af_inet6.c      2011-06-15 02:44:10.000000000 +0200
25632 @@ -42,6 +42,8 @@
25633  #include <linux/netdevice.h>
25634  #include <linux/icmpv6.h>
25635  #include <linux/netfilter_ipv6.h>
25636 +#include <linux/vs_inet.h>
25637 +#include <linux/vs_inet6.h>
25638  
25639  #include <net/ip.h>
25640  #include <net/ipv6.h>
25641 @@ -160,9 +162,12 @@ lookup_protocol:
25642         }
25643  
25644         err = -EPERM;
25645 +       if ((protocol == IPPROTO_ICMPV6) &&
25646 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
25647 +               goto override;
25648         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
25649                 goto out_rcu_unlock;
25650 -
25651 +override:
25652         sock->ops = answer->ops;
25653         answer_prot = answer->prot;
25654         answer_no_check = answer->no_check;
25655 @@ -261,6 +266,7 @@ int inet6_bind(struct socket *sock, stru
25656         struct inet_sock *inet = inet_sk(sk);
25657         struct ipv6_pinfo *np = inet6_sk(sk);
25658         struct net *net = sock_net(sk);
25659 +       struct nx_v6_sock_addr nsa;
25660         __be32 v4addr = 0;
25661         unsigned short snum;
25662         int addr_type = 0;
25663 @@ -276,6 +282,10 @@ int inet6_bind(struct socket *sock, stru
25664         if (addr->sin6_family != AF_INET6)
25665                 return -EINVAL;
25666  
25667 +       err = v6_map_sock_addr(inet, addr, &nsa);
25668 +       if (err)
25669 +               return err;
25670 +
25671         addr_type = ipv6_addr_type(&addr->sin6_addr);
25672         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
25673                 return -EINVAL;
25674 @@ -307,6 +317,7 @@ int inet6_bind(struct socket *sock, stru
25675                 /* Reproduce AF_INET checks to make the bindings consistent */
25676                 v4addr = addr->sin6_addr.s6_addr32[3];
25677                 chk_addr_ret = inet_addr_type(net, v4addr);
25678 +
25679                 if (!sysctl_ip_nonlocal_bind &&
25680                     !(inet->freebind || inet->transparent) &&
25681                     v4addr != htonl(INADDR_ANY) &&
25682 @@ -316,6 +327,10 @@ int inet6_bind(struct socket *sock, stru
25683                         err = -EADDRNOTAVAIL;
25684                         goto out;
25685                 }
25686 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
25687 +                       err = -EADDRNOTAVAIL;
25688 +                       goto out;
25689 +               }
25690         } else {
25691                 if (addr_type != IPV6_ADDR_ANY) {
25692                         struct net_device *dev = NULL;
25693 @@ -342,6 +357,11 @@ int inet6_bind(struct socket *sock, stru
25694                                 }
25695                         }
25696  
25697 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25698 +                               err = -EADDRNOTAVAIL;
25699 +                               goto out;
25700 +                       }
25701 +
25702                         /* ipv4 addr of the socket is invalid.  Only the
25703                          * unspecified and mapped address have a v4 equivalent.
25704                          */
25705 @@ -358,6 +378,9 @@ int inet6_bind(struct socket *sock, stru
25706                 }
25707         }
25708  
25709 +       /* what's that for? */
25710 +       v6_set_sock_addr(inet, &nsa);
25711 +
25712         inet->inet_rcv_saddr = v4addr;
25713         inet->inet_saddr = v4addr;
25714  
25715 @@ -459,9 +482,11 @@ int inet6_getname(struct socket *sock, s
25716                         return -ENOTCONN;
25717                 sin->sin6_port = inet->inet_dport;
25718                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
25719 +               /* FIXME: remap lback? */
25720                 if (np->sndflow)
25721                         sin->sin6_flowinfo = np->flow_label;
25722         } else {
25723 +               /* FIXME: remap lback? */
25724                 if (ipv6_addr_any(&np->rcv_saddr))
25725                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
25726                 else
25727 diff -NurpP --minimal linux-3.0-rc5/net/ipv6/fib6_rules.c linux-3.0-rc5-vs2.3.1-pre3/net/ipv6/fib6_rules.c
25728 --- linux-3.0-rc5/net/ipv6/fib6_rules.c 2011-05-22 16:18:00.000000000 +0200
25729 +++ linux-3.0-rc5-vs2.3.1-pre3/net/ipv6/fib6_rules.c    2011-06-10 22:11:24.000000000 +0200
25730 @@ -90,7 +90,7 @@ static int fib6_rule_action(struct fib_r
25731                                                ip6_dst_idev(&rt->dst)->dev,
25732                                                &flp6->daddr,
25733                                                rt6_flags2srcprefs(flags),
25734 -                                              &saddr))
25735 +                                              &saddr, NULL))
25736                                 goto again;
25737                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
25738                                                r->src.plen))
25739 diff -NurpP --minimal linux-3.0-rc5/net/ipv6/inet6_hashtables.c linux-3.0-rc5-vs2.3.1-pre3/net/ipv6/inet6_hashtables.c
25740 --- linux-3.0-rc5/net/ipv6/inet6_hashtables.c   2011-05-22 16:18:00.000000000 +0200
25741 +++ linux-3.0-rc5-vs2.3.1-pre3/net/ipv6/inet6_hashtables.c      2011-06-10 22:11:24.000000000 +0200
25742 @@ -16,6 +16,7 @@
25743  
25744  #include <linux/module.h>
25745  #include <linux/random.h>
25746 +#include <linux/vs_inet6.h>
25747  
25748  #include <net/inet_connection_sock.h>
25749  #include <net/inet_hashtables.h>
25750 @@ -82,7 +83,6 @@ struct sock *__inet6_lookup_established(
25751         unsigned int slot = hash & hashinfo->ehash_mask;
25752         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
25753  
25754 -
25755         rcu_read_lock();
25756  begin:
25757         sk_nulls_for_each_rcu(sk, node, &head->chain) {
25758 @@ -94,7 +94,7 @@ begin:
25759                                 sock_put(sk);
25760                                 goto begin;
25761                         }
25762 -               goto out;
25763 +                       goto out;
25764                 }
25765         }
25766         if (get_nulls_value(node) != slot)
25767 @@ -140,6 +140,9 @@ static inline int compute_score(struct s
25768                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25769                                 return -1;
25770                         score++;
25771 +               } else {
25772 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25773 +                               return -1;
25774                 }
25775                 if (sk->sk_bound_dev_if) {
25776                         if (sk->sk_bound_dev_if != dif)
25777 diff -NurpP --minimal linux-3.0-rc5/net/ipv6/ip6_output.c linux-3.0-rc5-vs2.3.1-pre3/net/ipv6/ip6_output.c
25778 --- linux-3.0-rc5/net/ipv6/ip6_output.c 2011-07-01 11:14:26.000000000 +0200
25779 +++ linux-3.0-rc5-vs2.3.1-pre3/net/ipv6/ip6_output.c    2011-06-16 14:16:51.000000000 +0200
25780 @@ -933,7 +933,8 @@ static int ip6_dst_lookup_tail(struct so
25781                 struct rt6_info *rt = (struct rt6_info *) *dst;
25782                 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
25783                                           sk ? inet6_sk(sk)->srcprefs : 0,
25784 -                                         &fl6->saddr);
25785 +                                         &fl6->saddr,
25786 +                                         sk ? sk->sk_nx_info : NULL);
25787                 if (err)
25788                         goto out_err_release;
25789         }
25790 diff -NurpP --minimal linux-3.0-rc5/net/ipv6/ndisc.c linux-3.0-rc5-vs2.3.1-pre3/net/ipv6/ndisc.c
25791 --- linux-3.0-rc5/net/ipv6/ndisc.c      2011-07-01 11:14:26.000000000 +0200
25792 +++ linux-3.0-rc5-vs2.3.1-pre3/net/ipv6/ndisc.c 2011-06-10 22:11:24.000000000 +0200
25793 @@ -597,7 +597,7 @@ static void ndisc_send_na(struct net_dev
25794         } else {
25795                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
25796                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
25797 -                                      &tmpaddr))
25798 +                                      &tmpaddr, NULL))
25799                         return;
25800                 src_addr = &tmpaddr;
25801         }
25802 diff -NurpP --minimal linux-3.0-rc5/net/ipv6/raw.c linux-3.0-rc5-vs2.3.1-pre3/net/ipv6/raw.c
25803 --- linux-3.0-rc5/net/ipv6/raw.c        2011-07-01 11:14:26.000000000 +0200
25804 +++ linux-3.0-rc5-vs2.3.1-pre3/net/ipv6/raw.c   2011-06-10 22:11:24.000000000 +0200
25805 @@ -30,6 +30,7 @@
25806  #include <linux/icmpv6.h>
25807  #include <linux/netfilter.h>
25808  #include <linux/netfilter_ipv6.h>
25809 +#include <linux/vs_inet6.h>
25810  #include <linux/skbuff.h>
25811  #include <linux/compat.h>
25812  #include <asm/uaccess.h>
25813 @@ -284,6 +285,13 @@ static int rawv6_bind(struct sock *sk, s
25814                                 goto out_unlock;
25815                 }
25816  
25817 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25818 +                       err = -EADDRNOTAVAIL;
25819 +                       if (dev)
25820 +                               dev_put(dev);
25821 +                       goto out;
25822 +               }
25823 +
25824                 /* ipv4 addr of the socket is invalid.  Only the
25825                  * unspecified and mapped address have a v4 equivalent.
25826                  */
25827 diff -NurpP --minimal linux-3.0-rc5/net/ipv6/route.c linux-3.0-rc5-vs2.3.1-pre3/net/ipv6/route.c
25828 --- linux-3.0-rc5/net/ipv6/route.c      2011-07-01 11:14:26.000000000 +0200
25829 +++ linux-3.0-rc5-vs2.3.1-pre3/net/ipv6/route.c 2011-06-16 14:16:51.000000000 +0200
25830 @@ -54,6 +54,7 @@
25831  #include <net/xfrm.h>
25832  #include <net/netevent.h>
25833  #include <net/netlink.h>
25834 +#include <linux/vs_inet6.h>
25835  
25836  #include <asm/uaccess.h>
25837  
25838 @@ -2057,15 +2058,17 @@ int ip6_route_get_saddr(struct net *net,
25839                         struct rt6_info *rt,
25840                         const struct in6_addr *daddr,
25841                         unsigned int prefs,
25842 -                       struct in6_addr *saddr)
25843 +                       struct in6_addr *saddr,
25844 +                       struct nx_info *nxi)
25845  {
25846         struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
25847         int err = 0;
25848 -       if (rt->rt6i_prefsrc.plen)
25849 +       if (rt->rt6i_prefsrc.plen && (!nxi ||
25850 +           v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
25851                 ipv6_addr_copy(saddr, &rt->rt6i_prefsrc.addr);
25852         else
25853                 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
25854 -                                        daddr, prefs, saddr);
25855 +                                        daddr, prefs, saddr, nxi);
25856         return err;
25857  }
25858  
25859 @@ -2394,7 +2397,8 @@ static int rt6_fill_node(struct net *net
25860                         NLA_PUT_U32(skb, RTA_IIF, iif);
25861         } else if (dst) {
25862                 struct in6_addr saddr_buf;
25863 -               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0)
25864 +               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
25865 +                                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
25866                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
25867         }
25868  
25869 diff -NurpP --minimal linux-3.0-rc5/net/ipv6/tcp_ipv6.c linux-3.0-rc5-vs2.3.1-pre3/net/ipv6/tcp_ipv6.c
25870 --- linux-3.0-rc5/net/ipv6/tcp_ipv6.c   2011-07-01 11:14:26.000000000 +0200
25871 +++ linux-3.0-rc5-vs2.3.1-pre3/net/ipv6/tcp_ipv6.c      2011-06-22 12:39:16.000000000 +0200
25872 @@ -69,6 +69,7 @@
25873  
25874  #include <linux/crypto.h>
25875  #include <linux/scatterlist.h>
25876 +#include <linux/vs_inet6.h>
25877  
25878  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
25879  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
25880 @@ -161,8 +162,15 @@ static int tcp_v6_connect(struct sock *s
25881          *      connect() to INADDR_ANY means loopback (BSD'ism).
25882          */
25883  
25884 -       if(ipv6_addr_any(&usin->sin6_addr))
25885 -               usin->sin6_addr.s6_addr[15] = 0x1;
25886 +       if(ipv6_addr_any(&usin->sin6_addr)) {
25887 +               struct nx_info *nxi =  sk->sk_nx_info;
25888 +
25889 +               if (nxi && nx_info_has_v6(nxi))
25890 +                       /* FIXME: remap lback? */
25891 +                       usin->sin6_addr = nxi->v6.ip;
25892 +               else
25893 +                       usin->sin6_addr.s6_addr[15] = 0x1;
25894 +       }
25895  
25896         addr_type = ipv6_addr_type(&usin->sin6_addr);
25897  
25898 diff -NurpP --minimal linux-3.0-rc5/net/ipv6/udp.c linux-3.0-rc5-vs2.3.1-pre3/net/ipv6/udp.c
25899 --- linux-3.0-rc5/net/ipv6/udp.c        2011-07-01 11:14:26.000000000 +0200
25900 +++ linux-3.0-rc5-vs2.3.1-pre3/net/ipv6/udp.c   2011-06-10 22:11:24.000000000 +0200
25901 @@ -45,41 +45,67 @@
25902  #include <net/tcp_states.h>
25903  #include <net/ip6_checksum.h>
25904  #include <net/xfrm.h>
25905 +#include <linux/vs_inet6.h>
25906  
25907  #include <linux/proc_fs.h>
25908  #include <linux/seq_file.h>
25909  #include "udp_impl.h"
25910  
25911 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
25912 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25913  {
25914 -       const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
25915 +       const struct in6_addr *sk1_rcv_saddr6 = &inet6_sk(sk1)->rcv_saddr;
25916         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
25917 -       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk);
25918 +       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1);
25919         __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
25920 -       int sk_ipv6only = ipv6_only_sock(sk);
25921 +       int sk1_ipv6only = ipv6_only_sock(sk1);
25922         int sk2_ipv6only = inet_v6_ipv6only(sk2);
25923 -       int addr_type = ipv6_addr_type(sk_rcv_saddr6);
25924 +       int addr_type = ipv6_addr_type(sk1_rcv_saddr6);
25925         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
25926  
25927         /* if both are mapped, treat as IPv4 */
25928 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
25929 -               return (!sk2_ipv6only &&
25930 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
25931 +               if (!sk2_ipv6only &&
25932                         (!sk1_rcv_saddr || !sk2_rcv_saddr ||
25933 -                         sk1_rcv_saddr == sk2_rcv_saddr));
25934 +                         sk1_rcv_saddr == sk2_rcv_saddr))
25935 +                       goto vs_v4;
25936 +               else
25937 +                       return 0;
25938 +       }
25939  
25940         if (addr_type2 == IPV6_ADDR_ANY &&
25941             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
25942 -               return 1;
25943 +               goto vs;
25944  
25945         if (addr_type == IPV6_ADDR_ANY &&
25946 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25947 -               return 1;
25948 +           !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25949 +               goto vs;
25950  
25951         if (sk2_rcv_saddr6 &&
25952 -           ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
25953 -               return 1;
25954 +           ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
25955 +               goto vs;
25956  
25957         return 0;
25958 +
25959 +vs_v4:
25960 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
25961 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25962 +       if (!sk2_rcv_saddr)
25963 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
25964 +       if (!sk1_rcv_saddr)
25965 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
25966 +       return 1;
25967 +vs:
25968 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
25969 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25970 +       else if (addr_type2 == IPV6_ADDR_ANY)
25971 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
25972 +       else if (addr_type == IPV6_ADDR_ANY) {
25973 +               if (addr_type2 == IPV6_ADDR_MAPPED)
25974 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25975 +               else
25976 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
25977 +       }
25978 +       return 1;
25979  }
25980  
25981  static unsigned int udp6_portaddr_hash(struct net *net,
25982 @@ -143,6 +169,10 @@ static inline int compute_score(struct s
25983                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25984                                 return -1;
25985                         score++;
25986 +               } else {
25987 +                       /* block non nx_info ips */
25988 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25989 +                               return -1;
25990                 }
25991                 if (!ipv6_addr_any(&np->daddr)) {
25992                         if (!ipv6_addr_equal(&np->daddr, saddr))
25993 diff -NurpP --minimal linux-3.0-rc5/net/ipv6/xfrm6_policy.c linux-3.0-rc5-vs2.3.1-pre3/net/ipv6/xfrm6_policy.c
25994 --- linux-3.0-rc5/net/ipv6/xfrm6_policy.c       2011-07-01 11:14:26.000000000 +0200
25995 +++ linux-3.0-rc5-vs2.3.1-pre3/net/ipv6/xfrm6_policy.c  2011-06-10 22:11:24.000000000 +0200
25996 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
25997         dev = ip6_dst_idev(dst)->dev;
25998         ipv6_dev_get_saddr(dev_net(dev), dev,
25999                            (struct in6_addr *)&daddr->a6, 0,
26000 -                          (struct in6_addr *)&saddr->a6);
26001 +                          (struct in6_addr *)&saddr->a6, NULL);
26002         dst_release(dst);
26003         return 0;
26004  }
26005 diff -NurpP --minimal linux-3.0-rc5/netfilter/ipvs/ip_vs_xmit.c linux-3.0-rc5-vs2.3.1-pre3/net/netfilter/ipvs/ip_vs_xmit.c
26006 --- linux-3.0-rc5/net/netfilter/ipvs/ip_vs_xmit.c
26007 +++ linux-3.0-rc5-vs2.3.1-pre3/net/netfilter/ipvs/ip_vs_xmit.c
26008 @@ -213,7 +213,7 @@ __ip_vs_route_output_v6(struct net *net,
26009                 return dst;
26010         if (ipv6_addr_any(&fl6.saddr) &&
26011             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
26012 -                              &fl6.daddr, 0, &fl6.saddr) < 0)
26013 +                              &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
26014                 goto out_err;
26015         if (do_xfrm) {
26016                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
26017 diff -NurpP --minimal linux-3.0-rc5/net/netlink/af_netlink.c linux-3.0-rc5-vs2.3.1-pre3/net/netlink/af_netlink.c
26018 --- linux-3.0-rc5/net/netlink/af_netlink.c      2011-07-01 11:14:27.000000000 +0200
26019 +++ linux-3.0-rc5-vs2.3.1-pre3/net/netlink/af_netlink.c 2011-06-10 22:11:24.000000000 +0200
26020 @@ -55,6 +55,9 @@
26021  #include <linux/types.h>
26022  #include <linux/audit.h>
26023  #include <linux/mutex.h>
26024 +#include <linux/vs_context.h>
26025 +#include <linux/vs_network.h>
26026 +#include <linux/vs_limit.h>
26027  
26028  #include <net/net_namespace.h>
26029  #include <net/sock.h>
26030 @@ -1907,6 +1910,8 @@ static struct sock *netlink_seq_socket_i
26031                         sk_for_each(s, node, &hash->table[j]) {
26032                                 if (sock_net(s) != seq_file_net(seq))
26033                                         continue;
26034 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26035 +                                       continue;
26036                                 if (off == pos) {
26037                                         iter->link = i;
26038                                         iter->hash_idx = j;
26039 @@ -1941,7 +1946,8 @@ static void *netlink_seq_next(struct seq
26040         s = v;
26041         do {
26042                 s = sk_next(s);
26043 -       } while (s && sock_net(s) != seq_file_net(seq));
26044 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
26045 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
26046         if (s)
26047                 return s;
26048  
26049 @@ -1953,7 +1959,8 @@ static void *netlink_seq_next(struct seq
26050  
26051                 for (; j <= hash->mask; j++) {
26052                         s = sk_head(&hash->table[j]);
26053 -                       while (s && sock_net(s) != seq_file_net(seq))
26054 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
26055 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
26056                                 s = sk_next(s);
26057                         if (s) {
26058                                 iter->link = i;
26059 diff -NurpP --minimal linux-3.0-rc5/net/socket.c linux-3.0-rc5-vs2.3.1-pre3/net/socket.c
26060 --- linux-3.0-rc5/net/socket.c  2011-07-01 11:14:27.000000000 +0200
26061 +++ linux-3.0-rc5-vs2.3.1-pre3/net/socket.c     2011-06-16 14:16:51.000000000 +0200
26062 @@ -98,6 +98,10 @@
26063  
26064  #include <net/sock.h>
26065  #include <linux/netfilter.h>
26066 +#include <linux/vs_base.h>
26067 +#include <linux/vs_socket.h>
26068 +#include <linux/vs_inet.h>
26069 +#include <linux/vs_inet6.h>
26070  
26071  #include <linux/if_tun.h>
26072  #include <linux/ipv6_route.h>
26073 @@ -546,6 +550,7 @@ static inline int __sock_sendmsg_nosec(s
26074                                        struct msghdr *msg, size_t size)
26075  {
26076         struct sock_iocb *si = kiocb_to_siocb(iocb);
26077 +       size_t len;
26078  
26079         sock_update_classid(sock->sk);
26080  
26081 @@ -554,7 +559,22 @@ static inline int __sock_sendmsg_nosec(s
26082         si->msg = msg;
26083         si->size = size;
26084  
26085 -       return sock->ops->sendmsg(iocb, sock, msg, size);
26086 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
26087 +       if (sock->sk) {
26088 +               if (len == size)
26089 +                       vx_sock_send(sock->sk, size);
26090 +               else
26091 +                       vx_sock_fail(sock->sk, size);
26092 +       }
26093 +       vxdprintk(VXD_CBIT(net, 7),
26094 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
26095 +               sock, sock->sk,
26096 +               (sock->sk)?sock->sk->sk_nx_info:0,
26097 +               (sock->sk)?sock->sk->sk_vx_info:0,
26098 +               (sock->sk)?sock->sk->sk_xid:0,
26099 +               (sock->sk)?sock->sk->sk_nid:0,
26100 +               (unsigned int)size, len);
26101 +       return len;
26102  }
26103  
26104  static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
26105 @@ -694,6 +714,7 @@ static inline int __sock_recvmsg_nosec(s
26106                                        struct msghdr *msg, size_t size, int flags)
26107  {
26108         struct sock_iocb *si = kiocb_to_siocb(iocb);
26109 +       int len;
26110  
26111         sock_update_classid(sock->sk);
26112  
26113 @@ -703,7 +724,18 @@ static inline int __sock_recvmsg_nosec(s
26114         si->size = size;
26115         si->flags = flags;
26116  
26117 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
26118 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
26119 +       if ((len >= 0) && sock->sk)
26120 +               vx_sock_recv(sock->sk, len);
26121 +       vxdprintk(VXD_CBIT(net, 7),
26122 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
26123 +               sock, sock->sk,
26124 +               (sock->sk)?sock->sk->sk_nx_info:0,
26125 +               (sock->sk)?sock->sk->sk_vx_info:0,
26126 +               (sock->sk)?sock->sk->sk_xid:0,
26127 +               (sock->sk)?sock->sk->sk_nid:0,
26128 +               (unsigned int)size, len);
26129 +       return len;
26130  }
26131  
26132  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
26133 @@ -1188,6 +1220,13 @@ int __sock_create(struct net *net, int f
26134         if (type < 0 || type >= SOCK_MAX)
26135                 return -EINVAL;
26136  
26137 +       if (!nx_check(0, VS_ADMIN)) {
26138 +               if (family == PF_INET && !current_nx_info_has_v4())
26139 +                       return -EAFNOSUPPORT;
26140 +               if (family == PF_INET6 && !current_nx_info_has_v6())
26141 +                       return -EAFNOSUPPORT;
26142 +       }
26143 +
26144         /* Compatibility.
26145  
26146            This uglymoron is moved from INET layer to here to avoid
26147 @@ -1323,6 +1362,7 @@ SYSCALL_DEFINE3(socket, int, family, int
26148         if (retval < 0)
26149                 goto out;
26150  
26151 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
26152         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
26153         if (retval < 0)
26154                 goto out_release;
26155 @@ -1364,10 +1404,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
26156         err = sock_create(family, type, protocol, &sock1);
26157         if (err < 0)
26158                 goto out;
26159 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
26160  
26161         err = sock_create(family, type, protocol, &sock2);
26162         if (err < 0)
26163                 goto out_release_1;
26164 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
26165  
26166         err = sock1->ops->socketpair(sock1, sock2);
26167         if (err < 0)
26168 diff -NurpP --minimal linux-3.0-rc5/net/sunrpc/auth.c linux-3.0-rc5-vs2.3.1-pre3/net/sunrpc/auth.c
26169 --- linux-3.0-rc5/net/sunrpc/auth.c     2011-07-01 11:14:27.000000000 +0200
26170 +++ linux-3.0-rc5-vs2.3.1-pre3/net/sunrpc/auth.c        2011-06-10 22:11:24.000000000 +0200
26171 @@ -14,6 +14,7 @@
26172  #include <linux/hash.h>
26173  #include <linux/sunrpc/clnt.h>
26174  #include <linux/spinlock.h>
26175 +#include <linux/vs_tag.h>
26176  
26177  #ifdef RPC_DEBUG
26178  # define RPCDBG_FACILITY       RPCDBG_AUTH
26179 @@ -427,6 +428,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
26180         memset(&acred, 0, sizeof(acred));
26181         acred.uid = cred->fsuid;
26182         acred.gid = cred->fsgid;
26183 +       acred.tag = dx_current_tag();
26184         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
26185  
26186         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
26187 @@ -467,6 +469,7 @@ rpcauth_bind_root_cred(struct rpc_task *
26188         struct auth_cred acred = {
26189                 .uid = 0,
26190                 .gid = 0,
26191 +               .tag = dx_current_tag(),
26192         };
26193  
26194         dprintk("RPC: %5u looking up %s cred\n",
26195 diff -NurpP --minimal linux-3.0-rc5/net/sunrpc/auth_unix.c linux-3.0-rc5-vs2.3.1-pre3/net/sunrpc/auth_unix.c
26196 --- linux-3.0-rc5/net/sunrpc/auth_unix.c        2010-10-21 13:08:01.000000000 +0200
26197 +++ linux-3.0-rc5-vs2.3.1-pre3/net/sunrpc/auth_unix.c   2011-06-10 22:11:24.000000000 +0200
26198 @@ -12,12 +12,14 @@
26199  #include <linux/module.h>
26200  #include <linux/sunrpc/clnt.h>
26201  #include <linux/sunrpc/auth.h>
26202 +#include <linux/vs_tag.h>
26203  
26204  #define NFS_NGROUPS    16
26205  
26206  struct unx_cred {
26207         struct rpc_cred         uc_base;
26208         gid_t                   uc_gid;
26209 +       tag_t                   uc_tag;
26210         gid_t                   uc_gids[NFS_NGROUPS];
26211  };
26212  #define uc_uid                 uc_base.cr_uid
26213 @@ -78,6 +80,7 @@ unx_create_cred(struct rpc_auth *auth, s
26214                 groups = NFS_NGROUPS;
26215  
26216         cred->uc_gid = acred->gid;
26217 +       cred->uc_tag = acred->tag;
26218         for (i = 0; i < groups; i++)
26219                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
26220         if (i < NFS_NGROUPS)
26221 @@ -119,7 +122,9 @@ unx_match(struct auth_cred *acred, struc
26222         unsigned int i;
26223  
26224  
26225 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
26226 +       if (cred->uc_uid != acred->uid ||
26227 +               cred->uc_gid != acred->gid ||
26228 +               cred->uc_tag != acred->tag)
26229                 return 0;
26230  
26231         if (acred->group_info != NULL)
26232 @@ -142,7 +147,7 @@ unx_marshal(struct rpc_task *task, __be3
26233         struct rpc_clnt *clnt = task->tk_client;
26234         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
26235         __be32          *base, *hold;
26236 -       int             i;
26237 +       int             i, tag;
26238  
26239         *p++ = htonl(RPC_AUTH_UNIX);
26240         base = p++;
26241 @@ -152,9 +157,12 @@ unx_marshal(struct rpc_task *task, __be3
26242          * Copy the UTS nodename captured when the client was created.
26243          */
26244         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
26245 +       tag = task->tk_client->cl_tag;
26246  
26247 -       *p++ = htonl((u32) cred->uc_uid);
26248 -       *p++ = htonl((u32) cred->uc_gid);
26249 +       *p++ = htonl((u32) TAGINO_UID(tag,
26250 +               cred->uc_uid, cred->uc_tag));
26251 +       *p++ = htonl((u32) TAGINO_GID(tag,
26252 +               cred->uc_gid, cred->uc_tag));
26253         hold = p++;
26254         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
26255                 *p++ = htonl((u32) cred->uc_gids[i]);
26256 diff -NurpP --minimal linux-3.0-rc5/net/sunrpc/clnt.c linux-3.0-rc5-vs2.3.1-pre3/net/sunrpc/clnt.c
26257 --- linux-3.0-rc5/net/sunrpc/clnt.c     2011-07-01 11:14:27.000000000 +0200
26258 +++ linux-3.0-rc5-vs2.3.1-pre3/net/sunrpc/clnt.c        2011-07-01 11:35:35.000000000 +0200
26259 @@ -31,6 +31,7 @@
26260  #include <linux/in.h>
26261  #include <linux/in6.h>
26262  #include <linux/un.h>
26263 +#include <linux/vs_cvirt.h>
26264  
26265  #include <linux/sunrpc/clnt.h>
26266  #include <linux/sunrpc/rpc_pipe_fs.h>
26267 @@ -362,6 +363,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
26268         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
26269                 clnt->cl_chatty = 1;
26270  
26271 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
26272 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
26273 +               clnt->cl_tag = 1; */
26274         return clnt;
26275  }
26276  EXPORT_SYMBOL_GPL(rpc_create);
26277 diff -NurpP --minimal linux-3.0-rc5/net/unix/af_unix.c linux-3.0-rc5-vs2.3.1-pre3/net/unix/af_unix.c
26278 --- linux-3.0-rc5/net/unix/af_unix.c    2011-07-01 11:14:27.000000000 +0200
26279 +++ linux-3.0-rc5-vs2.3.1-pre3/net/unix/af_unix.c       2011-06-10 22:11:24.000000000 +0200
26280 @@ -114,6 +114,8 @@
26281  #include <linux/mount.h>
26282  #include <net/checksum.h>
26283  #include <linux/security.h>
26284 +#include <linux/vs_context.h>
26285 +#include <linux/vs_limit.h>
26286  
26287  static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
26288  static DEFINE_SPINLOCK(unix_table_lock);
26289 @@ -258,6 +260,8 @@ static struct sock *__unix_find_socket_b
26290                 if (!net_eq(sock_net(s), net))
26291                         continue;
26292  
26293 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26294 +                       continue;
26295                 if (u->addr->len == len &&
26296                     !memcmp(u->addr->name, sunname, len))
26297                         goto found;
26298 @@ -2208,6 +2212,8 @@ static struct sock *unix_seq_idx(struct 
26299         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
26300                 if (sock_net(s) != seq_file_net(seq))
26301                         continue;
26302 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26303 +                       continue;
26304                 if (off == pos)
26305                         return s;
26306                 ++off;
26307 @@ -2232,7 +2238,8 @@ static void *unix_seq_next(struct seq_fi
26308                 sk = first_unix_socket(&iter->i);
26309         else
26310                 sk = next_unix_socket(&iter->i, sk);
26311 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
26312 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
26313 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
26314                 sk = next_unix_socket(&iter->i, sk);
26315         return sk;
26316  }
26317 diff -NurpP --minimal linux-3.0-rc5/scripts/checksyscalls.sh linux-3.0-rc5-vs2.3.1-pre3/scripts/checksyscalls.sh
26318 --- linux-3.0-rc5/scripts/checksyscalls.sh      2011-03-15 18:07:46.000000000 +0100
26319 +++ linux-3.0-rc5-vs2.3.1-pre3/scripts/checksyscalls.sh 2011-06-10 22:11:24.000000000 +0200
26320 @@ -193,7 +193,6 @@ cat << EOF
26321  #define __IGNORE_afs_syscall
26322  #define __IGNORE_getpmsg
26323  #define __IGNORE_putpmsg
26324 -#define __IGNORE_vserver
26325  EOF
26326  }
26327  
26328 diff -NurpP --minimal linux-3.0-rc5/security/commoncap.c linux-3.0-rc5-vs2.3.1-pre3/security/commoncap.c
26329 --- linux-3.0-rc5/security/commoncap.c  2011-07-01 11:14:27.000000000 +0200
26330 +++ linux-3.0-rc5-vs2.3.1-pre3/security/commoncap.c     2011-06-16 14:16:51.000000000 +0200
26331 @@ -62,6 +62,7 @@ int cap_netlink_recv(struct sk_buff *skb
26332                 return -EPERM;
26333         return 0;
26334  }
26335 +
26336  EXPORT_SYMBOL(cap_netlink_recv);
26337  
26338  /**
26339 @@ -83,14 +84,20 @@ EXPORT_SYMBOL(cap_netlink_recv);
26340  int cap_capable(struct task_struct *tsk, const struct cred *cred,
26341                 struct user_namespace *targ_ns, int cap, int audit)
26342  {
26343 +       struct vx_info *vxi = tsk->vx_info;
26344 +
26345         for (;;) {
26346                 /* The creator of the user namespace has all caps. */
26347                 if (targ_ns != &init_user_ns && targ_ns->creator == cred->user)
26348                         return 0;
26349  
26350                 /* Do we have the necessary capabilities? */
26351 -               if (targ_ns == cred->user->user_ns)
26352 -                       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
26353 +               if (targ_ns == cred->user->user_ns) {
26354 +                       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
26355 +                           cap_raised(cred->cap_effective, cap))
26356 +                               return 0;
26357 +                       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
26358 +               }
26359  
26360                 /* Have we tried all of the parent namespaces? */
26361                 if (targ_ns == &init_user_ns)
26362 @@ -611,7 +618,7 @@ int cap_inode_setxattr(struct dentry *de
26363  
26364         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26365                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26366 -           !capable(CAP_SYS_ADMIN))
26367 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26368                 return -EPERM;
26369         return 0;
26370  }
26371 @@ -637,7 +644,7 @@ int cap_inode_removexattr(struct dentry 
26372  
26373         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26374                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26375 -           !capable(CAP_SYS_ADMIN))
26376 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26377                 return -EPERM;
26378         return 0;
26379  }
26380 @@ -971,3 +978,4 @@ int cap_file_mmap(struct file *file, uns
26381         }
26382         return ret;
26383  }
26384 +
26385 diff -NurpP --minimal linux-3.0-rc5/security/selinux/hooks.c linux-3.0-rc5-vs2.3.1-pre3/security/selinux/hooks.c
26386 --- linux-3.0-rc5/security/selinux/hooks.c      2011-07-01 11:14:28.000000000 +0200
26387 +++ linux-3.0-rc5-vs2.3.1-pre3/security/selinux/hooks.c 2011-06-15 02:40:14.000000000 +0200
26388 @@ -67,7 +67,6 @@
26389  #include <linux/dccp.h>
26390  #include <linux/quota.h>
26391  #include <linux/un.h>          /* for Unix socket types */
26392 -#include <net/af_unix.h>       /* for Unix socket types */
26393  #include <linux/parser.h>
26394  #include <linux/nfs_mount.h>
26395  #include <net/ipv6.h>
This page took 2.142578 seconds and 4 git commands to generate.