]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
c16464aa8b802b8b51f58c1b41d080d6ecaf9422
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-3.1.1/Documentation/vserver/debug.txt linux-3.1.1-vs2.3.2/Documentation/vserver/debug.txt
2 --- linux-3.1.1/Documentation/vserver/debug.txt 1970-01-01 01:00:00.000000000 +0100
3 +++ linux-3.1.1-vs2.3.2/Documentation/vserver/debug.txt 2011-10-24 18:53:33.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.1.1/arch/alpha/Kconfig linux-3.1.1-vs2.3.2/arch/alpha/Kconfig
160 --- linux-3.1.1/arch/alpha/Kconfig      2011-10-24 18:44:54.000000000 +0200
161 +++ linux-3.1.1-vs2.3.2/arch/alpha/Kconfig      2011-10-24 18:53:33.000000000 +0200
162 @@ -670,6 +670,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.1.1/arch/alpha/kernel/entry.S linux-3.1.1-vs2.3.2/arch/alpha/kernel/entry.S
172 --- linux-3.1.1/arch/alpha/kernel/entry.S       2010-10-21 13:06:45.000000000 +0200
173 +++ linux-3.1.1-vs2.3.2/arch/alpha/kernel/entry.S       2011-10-24 18:53:33.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.1.1/arch/alpha/kernel/ptrace.c linux-3.1.1-vs2.3.2/arch/alpha/kernel/ptrace.c
207 --- linux-3.1.1/arch/alpha/kernel/ptrace.c      2011-01-05 21:48:40.000000000 +0100
208 +++ linux-3.1.1-vs2.3.2/arch/alpha/kernel/ptrace.c      2011-10-24 18:53:33.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.1.1/arch/alpha/kernel/systbls.S linux-3.1.1-vs2.3.2/arch/alpha/kernel/systbls.S
218 --- linux-3.1.1/arch/alpha/kernel/systbls.S     2011-10-24 18:44:54.000000000 +0200
219 +++ linux-3.1.1-vs2.3.2/arch/alpha/kernel/systbls.S     2011-10-24 18:53:33.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.1.1/arch/alpha/kernel/traps.c linux-3.1.1-vs2.3.2/arch/alpha/kernel/traps.c
230 --- linux-3.1.1/arch/alpha/kernel/traps.c       2010-10-21 13:06:46.000000000 +0200
231 +++ linux-3.1.1-vs2.3.2/arch/alpha/kernel/traps.c       2011-10-24 18:53:33.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.1.1/arch/arm/Kconfig linux-3.1.1-vs2.3.2/arch/arm/Kconfig
243 --- linux-3.1.1/arch/arm/Kconfig        2011-10-24 18:44:54.000000000 +0200
244 +++ linux-3.1.1-vs2.3.2/arch/arm/Kconfig        2011-10-24 18:53:33.000000000 +0200
245 @@ -2111,6 +2111,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.1.1/arch/arm/kernel/calls.S linux-3.1.1-vs2.3.2/arch/arm/kernel/calls.S
255 --- linux-3.1.1/arch/arm/kernel/calls.S 2011-10-24 18:44:54.000000000 +0200
256 +++ linux-3.1.1-vs2.3.2/arch/arm/kernel/calls.S 2011-10-24 18:53:33.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.1.1/arch/arm/kernel/process.c linux-3.1.1-vs2.3.2/arch/arm/kernel/process.c
267 --- linux-3.1.1/arch/arm/kernel/process.c       2011-10-24 18:44:54.000000000 +0200
268 +++ linux-3.1.1-vs2.3.2/arch/arm/kernel/process.c       2011-10-24 18:53:33.000000000 +0200
269 @@ -317,7 +317,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.1.1/arch/arm/kernel/traps.c linux-3.1.1-vs2.3.2/arch/arm/kernel/traps.c
280 --- linux-3.1.1/arch/arm/kernel/traps.c 2011-10-24 18:44:54.000000000 +0200
281 +++ linux-3.1.1-vs2.3.2/arch/arm/kernel/traps.c 2011-10-24 18:53:33.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.1.1/arch/cris/Kconfig linux-3.1.1-vs2.3.2/arch/cris/Kconfig
294 --- linux-3.1.1/arch/cris/Kconfig       2011-07-22 11:17:35.000000000 +0200
295 +++ linux-3.1.1-vs2.3.2/arch/cris/Kconfig       2011-10-24 18:53:33.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.1.1/arch/frv/kernel/kernel_thread.S linux-3.1.1-vs2.3.2/arch/frv/kernel/kernel_thread.S
306 --- linux-3.1.1/arch/frv/kernel/kernel_thread.S 2008-12-25 00:26:37.000000000 +0100
307 +++ linux-3.1.1-vs2.3.2/arch/frv/kernel/kernel_thread.S 2011-10-24 18:53:33.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.1.1/arch/h8300/Kconfig linux-3.1.1-vs2.3.2/arch/h8300/Kconfig
318 --- linux-3.1.1/arch/h8300/Kconfig      2011-07-22 11:17:35.000000000 +0200
319 +++ linux-3.1.1-vs2.3.2/arch/h8300/Kconfig      2011-10-24 18:53:33.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.1.1/arch/ia64/Kconfig linux-3.1.1-vs2.3.2/arch/ia64/Kconfig
330 --- linux-3.1.1/arch/ia64/Kconfig       2011-10-24 18:44:58.000000000 +0200
331 +++ linux-3.1.1-vs2.3.2/arch/ia64/Kconfig       2011-10-24 18:53:33.000000000 +0200
332 @@ -657,6 +657,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.1.1/arch/ia64/include/asm/tlb.h linux-3.1.1-vs2.3.2/arch/ia64/include/asm/tlb.h
342 --- linux-3.1.1/arch/ia64/include/asm/tlb.h     2011-07-22 11:17:35.000000000 +0200
343 +++ linux-3.1.1-vs2.3.2/arch/ia64/include/asm/tlb.h     2011-10-24 18:53:33.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.1.1/arch/ia64/kernel/entry.S linux-3.1.1-vs2.3.2/arch/ia64/kernel/entry.S
353 --- linux-3.1.1/arch/ia64/kernel/entry.S        2011-10-24 18:44:58.000000000 +0200
354 +++ linux-3.1.1-vs2.3.2/arch/ia64/kernel/entry.S        2011-10-24 18:53:33.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.1.1/arch/ia64/kernel/perfmon.c linux-3.1.1-vs2.3.2/arch/ia64/kernel/perfmon.c
365 --- linux-3.1.1/arch/ia64/kernel/perfmon.c      2011-03-15 18:06:39.000000000 +0100
366 +++ linux-3.1.1-vs2.3.2/arch/ia64/kernel/perfmon.c      2011-10-24 18:53:33.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.1.1/arch/ia64/kernel/process.c linux-3.1.1-vs2.3.2/arch/ia64/kernel/process.c
376 --- linux-3.1.1/arch/ia64/kernel/process.c      2011-03-15 18:06:39.000000000 +0100
377 +++ linux-3.1.1-vs2.3.2/arch/ia64/kernel/process.c      2011-10-24 18:53:33.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.1.1/arch/ia64/kernel/ptrace.c linux-3.1.1-vs2.3.2/arch/ia64/kernel/ptrace.c
390 --- linux-3.1.1/arch/ia64/kernel/ptrace.c       2011-01-05 21:48:59.000000000 +0100
391 +++ linux-3.1.1-vs2.3.2/arch/ia64/kernel/ptrace.c       2011-10-24 18:53:33.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.1.1/arch/ia64/kernel/traps.c linux-3.1.1-vs2.3.2/arch/ia64/kernel/traps.c
401 --- linux-3.1.1/arch/ia64/kernel/traps.c        2010-07-07 18:31:01.000000000 +0200
402 +++ linux-3.1.1-vs2.3.2/arch/ia64/kernel/traps.c        2011-10-24 18:53:33.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.1.1/arch/ia64/mm/fault.c linux-3.1.1-vs2.3.2/arch/ia64/mm/fault.c
428 --- linux-3.1.1/arch/ia64/mm/fault.c    2011-07-22 11:17:35.000000000 +0200
429 +++ linux-3.1.1-vs2.3.2/arch/ia64/mm/fault.c    2011-10-24 18:53:33.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.1.1/arch/m32r/kernel/traps.c linux-3.1.1-vs2.3.2/arch/m32r/kernel/traps.c
439 --- linux-3.1.1/arch/m32r/kernel/traps.c        2011-10-24 18:44:58.000000000 +0200
440 +++ linux-3.1.1-vs2.3.2/arch/m32r/kernel/traps.c        2011-10-24 18:53:33.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.1.1/arch/m68k/Kconfig linux-3.1.1-vs2.3.2/arch/m68k/Kconfig
454 --- linux-3.1.1/arch/m68k/Kconfig       2011-10-24 18:44:58.000000000 +0200
455 +++ linux-3.1.1-vs2.3.2/arch/m68k/Kconfig       2011-10-24 18:53:33.000000000 +0200
456 @@ -246,6 +246,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.1.1/arch/mips/Kconfig linux-3.1.1-vs2.3.2/arch/mips/Kconfig
466 --- linux-3.1.1/arch/mips/Kconfig       2011-10-24 18:44:59.000000000 +0200
467 +++ linux-3.1.1-vs2.3.2/arch/mips/Kconfig       2011-10-24 18:53:33.000000000 +0200
468 @@ -2495,6 +2495,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.1.1/arch/mips/kernel/ptrace.c linux-3.1.1-vs2.3.2/arch/mips/kernel/ptrace.c
478 --- linux-3.1.1/arch/mips/kernel/ptrace.c       2011-07-22 11:17:36.000000000 +0200
479 +++ linux-3.1.1-vs2.3.2/arch/mips/kernel/ptrace.c       2011-10-24 18:53:33.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.1.1/arch/mips/kernel/scall32-o32.S linux-3.1.1-vs2.3.2/arch/mips/kernel/scall32-o32.S
499 --- linux-3.1.1/arch/mips/kernel/scall32-o32.S  2011-10-24 18:44:59.000000000 +0200
500 +++ linux-3.1.1-vs2.3.2/arch/mips/kernel/scall32-o32.S  2011-10-24 18:53:33.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.1.1/arch/mips/kernel/scall64-64.S linux-3.1.1-vs2.3.2/arch/mips/kernel/scall64-64.S
511 --- linux-3.1.1/arch/mips/kernel/scall64-64.S   2011-10-24 18:44:59.000000000 +0200
512 +++ linux-3.1.1-vs2.3.2/arch/mips/kernel/scall64-64.S   2011-10-24 18:53:33.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.1.1/arch/mips/kernel/scall64-n32.S linux-3.1.1-vs2.3.2/arch/mips/kernel/scall64-n32.S
523 --- linux-3.1.1/arch/mips/kernel/scall64-n32.S  2011-10-24 18:44:59.000000000 +0200
524 +++ linux-3.1.1-vs2.3.2/arch/mips/kernel/scall64-n32.S  2011-10-24 18:53:33.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.1.1/arch/mips/kernel/scall64-o32.S linux-3.1.1-vs2.3.2/arch/mips/kernel/scall64-o32.S
535 --- linux-3.1.1/arch/mips/kernel/scall64-o32.S  2011-10-24 18:44:59.000000000 +0200
536 +++ linux-3.1.1-vs2.3.2/arch/mips/kernel/scall64-o32.S  2011-10-24 18:53:33.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.1.1/arch/mips/kernel/traps.c linux-3.1.1-vs2.3.2/arch/mips/kernel/traps.c
547 --- linux-3.1.1/arch/mips/kernel/traps.c        2011-10-24 18:44:59.000000000 +0200
548 +++ linux-3.1.1-vs2.3.2/arch/mips/kernel/traps.c        2011-10-24 18:53:33.000000000 +0200
549 @@ -344,9 +344,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.1.1/arch/parisc/Kconfig linux-3.1.1-vs2.3.2/arch/parisc/Kconfig
564 --- linux-3.1.1/arch/parisc/Kconfig     2011-10-24 18:44:59.000000000 +0200
565 +++ linux-3.1.1-vs2.3.2/arch/parisc/Kconfig     2011-10-24 18:53:33.000000000 +0200
566 @@ -280,6 +280,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.1.1/arch/parisc/kernel/syscall_table.S linux-3.1.1-vs2.3.2/arch/parisc/kernel/syscall_table.S
576 --- linux-3.1.1/arch/parisc/kernel/syscall_table.S      2011-10-24 18:45:00.000000000 +0200
577 +++ linux-3.1.1-vs2.3.2/arch/parisc/kernel/syscall_table.S      2011-10-24 18:53:33.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.1.1/arch/parisc/kernel/traps.c linux-3.1.1-vs2.3.2/arch/parisc/kernel/traps.c
588 --- linux-3.1.1/arch/parisc/kernel/traps.c      2011-10-24 18:45:00.000000000 +0200
589 +++ linux-3.1.1-vs2.3.2/arch/parisc/kernel/traps.c      2011-10-24 18:53:33.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.1.1/arch/parisc/mm/fault.c linux-3.1.1-vs2.3.2/arch/parisc/mm/fault.c
614 --- linux-3.1.1/arch/parisc/mm/fault.c  2010-08-02 16:52:06.000000000 +0200
615 +++ linux-3.1.1-vs2.3.2/arch/parisc/mm/fault.c  2011-10-24 18:53:33.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.1.1/arch/powerpc/Kconfig linux-3.1.1-vs2.3.2/arch/powerpc/Kconfig
629 --- linux-3.1.1/arch/powerpc/Kconfig    2011-10-24 18:45:00.000000000 +0200
630 +++ linux-3.1.1-vs2.3.2/arch/powerpc/Kconfig    2011-10-24 18:53:33.000000000 +0200
631 @@ -981,6 +981,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.1.1/arch/powerpc/include/asm/unistd.h linux-3.1.1-vs2.3.2/arch/powerpc/include/asm/unistd.h
641 --- linux-3.1.1/arch/powerpc/include/asm/unistd.h       2011-07-22 11:17:40.000000000 +0200
642 +++ linux-3.1.1-vs2.3.2/arch/powerpc/include/asm/unistd.h       2011-10-24 18:53:33.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.1.1/arch/powerpc/kernel/process.c linux-3.1.1-vs2.3.2/arch/powerpc/kernel/process.c
653 --- linux-3.1.1/arch/powerpc/kernel/process.c   2011-10-24 18:45:00.000000000 +0200
654 +++ linux-3.1.1-vs2.3.2/arch/powerpc/kernel/process.c   2011-10-24 18:53:33.000000000 +0200
655 @@ -662,8 +662,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.1.1/arch/powerpc/kernel/traps.c linux-3.1.1-vs2.3.2/arch/powerpc/kernel/traps.c
668 --- linux-3.1.1/arch/powerpc/kernel/traps.c     2011-10-24 18:45:00.000000000 +0200
669 +++ linux-3.1.1-vs2.3.2/arch/powerpc/kernel/traps.c     2011-10-24 18:53:33.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.1.1/arch/powerpc/kernel/vdso.c linux-3.1.1-vs2.3.2/arch/powerpc/kernel/vdso.c
683 --- linux-3.1.1/arch/powerpc/kernel/vdso.c      2011-05-22 16:17:02.000000000 +0200
684 +++ linux-3.1.1-vs2.3.2/arch/powerpc/kernel/vdso.c      2011-10-24 18:53:33.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.1.1/arch/s390/Kconfig linux-3.1.1-vs2.3.2/arch/s390/Kconfig
694 --- linux-3.1.1/arch/s390/Kconfig       2011-10-24 18:45:01.000000000 +0200
695 +++ linux-3.1.1-vs2.3.2/arch/s390/Kconfig       2011-10-24 18:53:33.000000000 +0200
696 @@ -629,6 +629,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.1.1/arch/s390/include/asm/tlb.h linux-3.1.1-vs2.3.2/arch/s390/include/asm/tlb.h
706 --- linux-3.1.1/arch/s390/include/asm/tlb.h     2011-07-22 11:17:41.000000000 +0200
707 +++ linux-3.1.1-vs2.3.2/arch/s390/include/asm/tlb.h     2011-10-24 18:53:33.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.1.1/arch/s390/include/asm/unistd.h linux-3.1.1-vs2.3.2/arch/s390/include/asm/unistd.h
718 --- linux-3.1.1/arch/s390/include/asm/unistd.h  2011-07-22 11:17:41.000000000 +0200
719 +++ linux-3.1.1-vs2.3.2/arch/s390/include/asm/unistd.h  2011-10-24 18:53:33.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.1.1/arch/s390/kernel/ptrace.c linux-3.1.1-vs2.3.2/arch/s390/kernel/ptrace.c
730 --- linux-3.1.1/arch/s390/kernel/ptrace.c       2011-11-15 16:44:51.000000000 +0100
731 +++ linux-3.1.1-vs2.3.2/arch/s390/kernel/ptrace.c       2011-11-15 17:08:44.000000000 +0100
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.1.1/arch/s390/kernel/syscalls.S linux-3.1.1-vs2.3.2/arch/s390/kernel/syscalls.S
741 --- linux-3.1.1/arch/s390/kernel/syscalls.S     2011-10-24 18:45:01.000000000 +0200
742 +++ linux-3.1.1-vs2.3.2/arch/s390/kernel/syscalls.S     2011-10-24 18:53:33.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.1.1/arch/sh/Kconfig linux-3.1.1-vs2.3.2/arch/sh/Kconfig
753 --- linux-3.1.1/arch/sh/Kconfig 2011-10-24 18:45:01.000000000 +0200
754 +++ linux-3.1.1-vs2.3.2/arch/sh/Kconfig 2011-10-24 18:53:33.000000000 +0200
755 @@ -894,6 +894,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.1.1/arch/sh/kernel/irq.c linux-3.1.1-vs2.3.2/arch/sh/kernel/irq.c
765 --- linux-3.1.1/arch/sh/kernel/irq.c    2011-07-22 11:17:41.000000000 +0200
766 +++ linux-3.1.1-vs2.3.2/arch/sh/kernel/irq.c    2011-10-24 18:53:33.000000000 +0200
767 @@ -14,6 +14,7 @@
768  #include <linux/ftrace.h>
769  #include <linux/delay.h>
770  #include <linux/ratelimit.h>
771 +// #include <linux/vs_context.h>
772  #include <asm/processor.h>
773  #include <asm/machvec.h>
774  #include <asm/uaccess.h>
775 diff -NurpP --minimal linux-3.1.1/arch/sh/kernel/vsyscall/vsyscall.c linux-3.1.1-vs2.3.2/arch/sh/kernel/vsyscall/vsyscall.c
776 --- linux-3.1.1/arch/sh/kernel/vsyscall/vsyscall.c      2011-05-22 16:17:07.000000000 +0200
777 +++ linux-3.1.1-vs2.3.2/arch/sh/kernel/vsyscall/vsyscall.c      2011-10-24 18:53:33.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.1.1/arch/sparc/Kconfig linux-3.1.1-vs2.3.2/arch/sparc/Kconfig
787 --- linux-3.1.1/arch/sparc/Kconfig      2011-10-24 18:45:02.000000000 +0200
788 +++ linux-3.1.1-vs2.3.2/arch/sparc/Kconfig      2011-10-24 18:53:33.000000000 +0200
789 @@ -600,6 +600,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.1.1/arch/sparc/include/asm/tlb_64.h linux-3.1.1-vs2.3.2/arch/sparc/include/asm/tlb_64.h
799 --- linux-3.1.1/arch/sparc/include/asm/tlb_64.h 2011-07-22 11:17:42.000000000 +0200
800 +++ linux-3.1.1-vs2.3.2/arch/sparc/include/asm/tlb_64.h 2011-10-24 18:53:33.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.1.1/arch/sparc/include/asm/unistd.h linux-3.1.1-vs2.3.2/arch/sparc/include/asm/unistd.h
810 --- linux-3.1.1/arch/sparc/include/asm/unistd.h 2011-07-22 11:17:42.000000000 +0200
811 +++ linux-3.1.1-vs2.3.2/arch/sparc/include/asm/unistd.h 2011-10-24 18:53:33.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.1.1/arch/sparc/kernel/systbls_32.S linux-3.1.1-vs2.3.2/arch/sparc/kernel/systbls_32.S
822 --- linux-3.1.1/arch/sparc/kernel/systbls_32.S  2011-10-24 18:45:02.000000000 +0200
823 +++ linux-3.1.1-vs2.3.2/arch/sparc/kernel/systbls_32.S  2011-10-24 18:53:33.000000000 +0200
824 @@ -70,7 +70,7 @@ sys_call_table:
825  /*250*/        .long sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_ni_syscall
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.1.1/arch/sparc/kernel/systbls_64.S linux-3.1.1-vs2.3.2/arch/sparc/kernel/systbls_64.S
834 --- linux-3.1.1/arch/sparc/kernel/systbls_64.S  2011-10-24 18:45:02.000000000 +0200
835 +++ linux-3.1.1-vs2.3.2/arch/sparc/kernel/systbls_64.S  2011-10-24 18:53:33.000000000 +0200
836 @@ -71,7 +71,7 @@ sys_call_table32:
837  /*250*/        .word sys_mremap, compat_sys_sysctl, sys32_getsid, sys_fdatasync, sys_nis_syscall
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_nis_syscall
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.1.1/arch/um/Kconfig.rest linux-3.1.1-vs2.3.2/arch/um/Kconfig.rest
855 --- linux-3.1.1/arch/um/Kconfig.rest    2009-06-11 17:12:19.000000000 +0200
856 +++ linux-3.1.1-vs2.3.2/arch/um/Kconfig.rest    2011-10-24 18:53:33.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.1.1/arch/um/include/asm/tlb.h linux-3.1.1-vs2.3.2/arch/um/include/asm/tlb.h
867 --- linux-3.1.1/arch/um/include/asm/tlb.h       2011-07-22 11:17:42.000000000 +0200
868 +++ linux-3.1.1-vs2.3.2/arch/um/include/asm/tlb.h       2011-10-24 18:53:33.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.1.1/arch/um/include/shared/kern_constants.h linux-3.1.1-vs2.3.2/arch/um/include/shared/kern_constants.h
878 --- linux-3.1.1/arch/um/include/shared/kern_constants.h 1970-01-01 01:00:00.000000000 +0100
879 +++ linux-3.1.1-vs2.3.2/arch/um/include/shared/kern_constants.h 2011-10-24 18:53:33.000000000 +0200
880 @@ -0,0 +1 @@
881 +#include "../../../../include/generated/asm-offsets.h"
882 diff -NurpP --minimal linux-3.1.1/arch/um/include/shared/user_constants.h linux-3.1.1-vs2.3.2/arch/um/include/shared/user_constants.h
883 --- linux-3.1.1/arch/um/include/shared/user_constants.h 1970-01-01 01:00:00.000000000 +0100
884 +++ linux-3.1.1-vs2.3.2/arch/um/include/shared/user_constants.h 2011-10-24 18:53:33.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.1.1/arch/x86/Kconfig linux-3.1.1-vs2.3.2/arch/x86/Kconfig
927 --- linux-3.1.1/arch/x86/Kconfig        2011-10-24 18:45:06.000000000 +0200
928 +++ linux-3.1.1-vs2.3.2/arch/x86/Kconfig        2011-10-24 18:53:33.000000000 +0200
929 @@ -2144,6 +2144,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.1.1/arch/x86/ia32/ia32entry.S linux-3.1.1-vs2.3.2/arch/x86/ia32/ia32entry.S
939 --- linux-3.1.1/arch/x86/ia32/ia32entry.S       2011-10-24 18:45:06.000000000 +0200
940 +++ linux-3.1.1-vs2.3.2/arch/x86/ia32/ia32entry.S       2011-10-24 18:53:33.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.1.1/arch/x86/include/asm/unistd_64.h linux-3.1.1-vs2.3.2/arch/x86/include/asm/unistd_64.h
951 --- linux-3.1.1/arch/x86/include/asm/unistd_64.h        2011-10-24 18:45:07.000000000 +0200
952 +++ linux-3.1.1-vs2.3.2/arch/x86/include/asm/unistd_64.h        2011-10-24 18:53:33.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.1.1/arch/x86/kernel/syscall_table_32.S linux-3.1.1-vs2.3.2/arch/x86/kernel/syscall_table_32.S
963 --- linux-3.1.1/arch/x86/kernel/syscall_table_32.S      2011-10-24 18:45:07.000000000 +0200
964 +++ linux-3.1.1-vs2.3.2/arch/x86/kernel/syscall_table_32.S      2011-10-24 18:53:33.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.1.1/drivers/block/Kconfig linux-3.1.1-vs2.3.2/drivers/block/Kconfig
975 --- linux-3.1.1/drivers/block/Kconfig   2011-10-24 18:45:08.000000000 +0200
976 +++ linux-3.1.1-vs2.3.2/drivers/block/Kconfig   2011-10-24 18:53:33.000000000 +0200
977 @@ -288,6 +288,13 @@ config BLK_DEV_CRYPTOLOOP
978  
979  source "drivers/block/drbd/Kconfig"
980  
981 +config BLK_DEV_VROOT
982 +       tristate "Virtual Root device support"
983 +       depends on QUOTACTL
984 +       ---help---
985 +         Saying Y here will allow you to use quota/fs ioctls on a shared
986 +         partition within a virtual server without compromising security.
987 +
988  config BLK_DEV_NBD
989         tristate "Network block device support"
990         depends on NET
991 diff -NurpP --minimal linux-3.1.1/drivers/block/Makefile linux-3.1.1-vs2.3.2/drivers/block/Makefile
992 --- linux-3.1.1/drivers/block/Makefile  2011-07-22 11:17:44.000000000 +0200
993 +++ linux-3.1.1-vs2.3.2/drivers/block/Makefile  2011-10-24 18:53:33.000000000 +0200
994 @@ -34,6 +34,7 @@ obj-$(CONFIG_VIODASD)         += viodasd.o
995  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
996  obj-$(CONFIG_BLK_DEV_UB)       += ub.o
997  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
998 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
999  
1000  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
1001  obj-$(CONFIG_XEN_BLKDEV_BACKEND)       += xen-blkback/
1002 diff -NurpP --minimal linux-3.1.1/drivers/block/loop.c linux-3.1.1-vs2.3.2/drivers/block/loop.c
1003 --- linux-3.1.1/drivers/block/loop.c    2011-10-24 18:45:08.000000000 +0200
1004 +++ linux-3.1.1-vs2.3.2/drivers/block/loop.c    2011-10-24 18:53:33.000000000 +0200
1005 @@ -76,6 +76,7 @@
1006  #include <linux/splice.h>
1007  #include <linux/sysfs.h>
1008  #include <linux/miscdevice.h>
1009 +#include <linux/vs_context.h>
1010  #include <asm/uaccess.h>
1011  
1012  static DEFINE_IDR(loop_index_idr);
1013 @@ -884,6 +885,7 @@ static int loop_set_fd(struct loop_devic
1014         lo->lo_blocksize = lo_blocksize;
1015         lo->lo_device = bdev;
1016         lo->lo_flags = lo_flags;
1017 +       lo->lo_xid = vx_current_xid();
1018         lo->lo_backing_file = file;
1019         lo->transfer = transfer_none;
1020         lo->ioctl = NULL;
1021 @@ -1014,6 +1016,7 @@ static int loop_clr_fd(struct loop_devic
1022         lo->lo_encrypt_key_size = 0;
1023         lo->lo_flags = 0;
1024         lo->lo_thread = NULL;
1025 +       lo->lo_xid = 0;
1026         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
1027         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
1028         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
1029 @@ -1052,7 +1055,7 @@ loop_set_status(struct loop_device *lo, 
1030  
1031         if (lo->lo_encrypt_key_size &&
1032             lo->lo_key_owner != uid &&
1033 -           !capable(CAP_SYS_ADMIN))
1034 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
1035                 return -EPERM;
1036         if (lo->lo_state != Lo_bound)
1037                 return -ENXIO;
1038 @@ -1136,7 +1139,8 @@ loop_get_status(struct loop_device *lo, 
1039         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
1040         info->lo_encrypt_type =
1041                 lo->lo_encryption ? lo->lo_encryption->number : 0;
1042 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
1043 +       if (lo->lo_encrypt_key_size &&
1044 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
1045                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
1046                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
1047                        lo->lo_encrypt_key_size);
1048 @@ -1490,6 +1494,9 @@ static int lo_open(struct block_device *
1049                 goto out;
1050         }
1051  
1052 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P))
1053 +               return -EACCES;
1054 +
1055         mutex_lock(&lo->lo_ctl_mutex);
1056         lo->lo_refcnt++;
1057         mutex_unlock(&lo->lo_ctl_mutex);
1058 diff -NurpP --minimal linux-3.1.1/drivers/block/vroot.c linux-3.1.1-vs2.3.2/drivers/block/vroot.c
1059 --- linux-3.1.1/drivers/block/vroot.c   1970-01-01 01:00:00.000000000 +0100
1060 +++ linux-3.1.1-vs2.3.2/drivers/block/vroot.c   2011-10-24 18:53:33.000000000 +0200
1061 @@ -0,0 +1,292 @@
1062 +/*
1063 + *  linux/drivers/block/vroot.c
1064 + *
1065 + *  written by Herbert Pötzl, 9/11/2002
1066 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
1067 + *
1068 + *  based on the loop.c code by Theodore Ts'o.
1069 + *
1070 + * Copyright (C) 2002-2007 by Herbert Pötzl.
1071 + * Redistribution of this file is permitted under the
1072 + * GNU General Public License.
1073 + *
1074 + */
1075 +
1076 +#include <linux/module.h>
1077 +#include <linux/moduleparam.h>
1078 +#include <linux/file.h>
1079 +#include <linux/major.h>
1080 +#include <linux/blkdev.h>
1081 +#include <linux/slab.h>
1082 +
1083 +#include <linux/vroot.h>
1084 +#include <linux/vs_context.h>
1085 +
1086 +
1087 +static int max_vroot = 8;
1088 +
1089 +static struct vroot_device *vroot_dev;
1090 +static struct gendisk **disks;
1091 +
1092 +
1093 +static int vroot_set_dev(
1094 +       struct vroot_device *vr,
1095 +       struct block_device *bdev,
1096 +       unsigned int arg)
1097 +{
1098 +       struct block_device *real_bdev;
1099 +       struct file *file;
1100 +       struct inode *inode;
1101 +       int error;
1102 +
1103 +       error = -EBUSY;
1104 +       if (vr->vr_state != Vr_unbound)
1105 +               goto out;
1106 +
1107 +       error = -EBADF;
1108 +       file = fget(arg);
1109 +       if (!file)
1110 +               goto out;
1111 +
1112 +       error = -EINVAL;
1113 +       inode = file->f_dentry->d_inode;
1114 +
1115 +
1116 +       if (S_ISBLK(inode->i_mode)) {
1117 +               real_bdev = inode->i_bdev;
1118 +               vr->vr_device = real_bdev;
1119 +               __iget(real_bdev->bd_inode);
1120 +       } else
1121 +               goto out_fput;
1122 +
1123 +       vxdprintk(VXD_CBIT(misc, 0),
1124 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
1125 +               vr->vr_number, VXD_DEV(real_bdev));
1126 +
1127 +       vr->vr_state = Vr_bound;
1128 +       error = 0;
1129 +
1130 + out_fput:
1131 +       fput(file);
1132 + out:
1133 +       return error;
1134 +}
1135 +
1136 +static int vroot_clr_dev(
1137 +       struct vroot_device *vr,
1138 +       struct block_device *bdev)
1139 +{
1140 +       struct block_device *real_bdev;
1141 +
1142 +       if (vr->vr_state != Vr_bound)
1143 +               return -ENXIO;
1144 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
1145 +               return -EBUSY;
1146 +
1147 +       real_bdev = vr->vr_device;
1148 +
1149 +       vxdprintk(VXD_CBIT(misc, 0),
1150 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
1151 +               vr->vr_number, VXD_DEV(real_bdev));
1152 +
1153 +       bdput(real_bdev);
1154 +       vr->vr_state = Vr_unbound;
1155 +       vr->vr_device = NULL;
1156 +       return 0;
1157 +}
1158 +
1159 +
1160 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
1161 +       unsigned int cmd, unsigned long arg)
1162 +{
1163 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1164 +       int err;
1165 +
1166 +       down(&vr->vr_ctl_mutex);
1167 +       switch (cmd) {
1168 +       case VROOT_SET_DEV:
1169 +               err = vroot_set_dev(vr, bdev, arg);
1170 +               break;
1171 +       case VROOT_CLR_DEV:
1172 +               err = vroot_clr_dev(vr, bdev);
1173 +               break;
1174 +       default:
1175 +               err = -EINVAL;
1176 +               break;
1177 +       }
1178 +       up(&vr->vr_ctl_mutex);
1179 +       return err;
1180 +}
1181 +
1182 +static int vr_open(struct block_device *bdev, fmode_t mode)
1183 +{
1184 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1185 +
1186 +       down(&vr->vr_ctl_mutex);
1187 +       vr->vr_refcnt++;
1188 +       up(&vr->vr_ctl_mutex);
1189 +       return 0;
1190 +}
1191 +
1192 +static int vr_release(struct gendisk *disk, fmode_t mode)
1193 +{
1194 +       struct vroot_device *vr = disk->private_data;
1195 +
1196 +       down(&vr->vr_ctl_mutex);
1197 +       --vr->vr_refcnt;
1198 +       up(&vr->vr_ctl_mutex);
1199 +       return 0;
1200 +}
1201 +
1202 +static struct block_device_operations vr_fops = {
1203 +       .owner =        THIS_MODULE,
1204 +       .open =         vr_open,
1205 +       .release =      vr_release,
1206 +       .ioctl =        vr_ioctl,
1207 +};
1208 +
1209 +static int vroot_make_request(struct request_queue *q, struct bio *bio)
1210 +{
1211 +       printk("vroot_make_request %p, %p\n", q, bio);
1212 +       bio_io_error(bio);
1213 +       return 0;
1214 +}
1215 +
1216 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
1217 +{
1218 +       struct inode *inode = bdev->bd_inode;
1219 +       struct vroot_device *vr;
1220 +       struct block_device *real_bdev;
1221 +       int minor = iminor(inode);
1222 +
1223 +       vr = &vroot_dev[minor];
1224 +       real_bdev = vr->vr_device;
1225 +
1226 +       vxdprintk(VXD_CBIT(misc, 0),
1227 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1228 +               vr->vr_number, VXD_DEV(real_bdev));
1229 +
1230 +       if (vr->vr_state != Vr_bound)
1231 +               return ERR_PTR(-ENXIO);
1232 +
1233 +       __iget(real_bdev->bd_inode);
1234 +       return real_bdev;
1235 +}
1236 +
1237 +
1238 +
1239 +/*
1240 + * And now the modules code and kernel interface.
1241 + */
1242 +
1243 +module_param(max_vroot, int, 0);
1244 +
1245 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1246 +MODULE_LICENSE("GPL");
1247 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1248 +
1249 +MODULE_AUTHOR ("Herbert Pötzl");
1250 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1251 +
1252 +
1253 +int __init vroot_init(void)
1254 +{
1255 +       int err, i;
1256 +
1257 +       if (max_vroot < 1 || max_vroot > 256) {
1258 +               max_vroot = MAX_VROOT_DEFAULT;
1259 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1260 +                       "(must be between 1 and 256), "
1261 +                       "using default (%d)\n", max_vroot);
1262 +       }
1263 +
1264 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1265 +               return -EIO;
1266 +
1267 +       err = -ENOMEM;
1268 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1269 +       if (!vroot_dev)
1270 +               goto out_mem1;
1271 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1272 +
1273 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1274 +       if (!disks)
1275 +               goto out_mem2;
1276 +
1277 +       for (i = 0; i < max_vroot; i++) {
1278 +               disks[i] = alloc_disk(1);
1279 +               if (!disks[i])
1280 +                       goto out_mem3;
1281 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1282 +               if (!disks[i]->queue)
1283 +                       goto out_mem3;
1284 +               blk_queue_make_request(disks[i]->queue, vroot_make_request);
1285 +       }
1286 +
1287 +       for (i = 0; i < max_vroot; i++) {
1288 +               struct vroot_device *vr = &vroot_dev[i];
1289 +               struct gendisk *disk = disks[i];
1290 +
1291 +               memset(vr, 0, sizeof(*vr));
1292 +               sema_init(&vr->vr_ctl_mutex, 1);
1293 +               vr->vr_number = i;
1294 +               disk->major = VROOT_MAJOR;
1295 +               disk->first_minor = i;
1296 +               disk->fops = &vr_fops;
1297 +               sprintf(disk->disk_name, "vroot%d", i);
1298 +               disk->private_data = vr;
1299 +       }
1300 +
1301 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1302 +       if (err)
1303 +               goto out_mem3;
1304 +
1305 +       for (i = 0; i < max_vroot; i++)
1306 +               add_disk(disks[i]);
1307 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1308 +       return 0;
1309 +
1310 +out_mem3:
1311 +       while (i--)
1312 +               put_disk(disks[i]);
1313 +       kfree(disks);
1314 +out_mem2:
1315 +       kfree(vroot_dev);
1316 +out_mem1:
1317 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1318 +       printk(KERN_ERR "vroot: ran out of memory\n");
1319 +       return err;
1320 +}
1321 +
1322 +void vroot_exit(void)
1323 +{
1324 +       int i;
1325 +
1326 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1327 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1328 +
1329 +       for (i = 0; i < max_vroot; i++) {
1330 +               del_gendisk(disks[i]);
1331 +               put_disk(disks[i]);
1332 +       }
1333 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1334 +
1335 +       kfree(disks);
1336 +       kfree(vroot_dev);
1337 +}
1338 +
1339 +module_init(vroot_init);
1340 +module_exit(vroot_exit);
1341 +
1342 +#ifndef MODULE
1343 +
1344 +static int __init max_vroot_setup(char *str)
1345 +{
1346 +       max_vroot = simple_strtol(str, NULL, 0);
1347 +       return 1;
1348 +}
1349 +
1350 +__setup("max_vroot=", max_vroot_setup);
1351 +
1352 +#endif
1353 +
1354 diff -NurpP --minimal linux-3.1.1/drivers/infiniband/core/addr.c linux-3.1.1-vs2.3.2/drivers/infiniband/core/addr.c
1355 --- linux-3.1.1/drivers/infiniband/core/addr.c  2011-10-24 18:45:09.000000000 +0200
1356 +++ linux-3.1.1-vs2.3.2/drivers/infiniband/core/addr.c  2011-10-24 18:53:33.000000000 +0200
1357 @@ -252,7 +252,7 @@ static int addr6_resolve(struct sockaddr
1358  
1359         if (ipv6_addr_any(&fl6.saddr)) {
1360                 ret = ipv6_dev_get_saddr(&init_net, ip6_dst_idev(dst)->dev,
1361 -                                        &fl6.daddr, 0, &fl6.saddr);
1362 +                                        &fl6.daddr, 0, &fl6.saddr, NULL);
1363                 if (ret)
1364                         goto put;
1365  
1366 diff -NurpP --minimal linux-3.1.1/drivers/infiniband/hw/ipath/ipath_user_pages.c linux-3.1.1-vs2.3.2/drivers/infiniband/hw/ipath/ipath_user_pages.c
1367 --- linux-3.1.1/drivers/infiniband/hw/ipath/ipath_user_pages.c  2011-05-22 16:17:16.000000000 +0200
1368 +++ linux-3.1.1-vs2.3.2/drivers/infiniband/hw/ipath/ipath_user_pages.c  2011-10-24 18:53:33.000000000 +0200
1369 @@ -35,6 +35,7 @@
1370  #include <linux/device.h>
1371  #include <linux/slab.h>
1372  #include <linux/sched.h>
1373 +#include <linux/vs_memory.h>
1374  
1375  #include "ipath_kernel.h"
1376  
1377 diff -NurpP --minimal linux-3.1.1/drivers/md/dm-ioctl.c linux-3.1.1-vs2.3.2/drivers/md/dm-ioctl.c
1378 --- linux-3.1.1/drivers/md/dm-ioctl.c   2011-10-24 18:45:10.000000000 +0200
1379 +++ linux-3.1.1-vs2.3.2/drivers/md/dm-ioctl.c   2011-10-24 18:53:33.000000000 +0200
1380 @@ -16,6 +16,7 @@
1381  #include <linux/dm-ioctl.h>
1382  #include <linux/hdreg.h>
1383  #include <linux/compat.h>
1384 +#include <linux/vs_context.h>
1385  
1386  #include <asm/uaccess.h>
1387  
1388 @@ -106,7 +107,8 @@ static struct hash_cell *__get_name_cell
1389         unsigned int h = hash_str(str);
1390  
1391         list_for_each_entry (hc, _name_buckets + h, name_list)
1392 -               if (!strcmp(hc->name, str)) {
1393 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1394 +                       !strcmp(hc->name, str)) {
1395                         dm_get(hc->md);
1396                         return hc;
1397                 }
1398 @@ -120,7 +122,8 @@ static struct hash_cell *__get_uuid_cell
1399         unsigned int h = hash_str(str);
1400  
1401         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1402 -               if (!strcmp(hc->uuid, str)) {
1403 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1404 +                       !strcmp(hc->uuid, str)) {
1405                         dm_get(hc->md);
1406                         return hc;
1407                 }
1408 @@ -131,13 +134,15 @@ static struct hash_cell *__get_uuid_cell
1409  static struct hash_cell *__get_dev_cell(uint64_t dev)
1410  {
1411         struct mapped_device *md;
1412 -       struct hash_cell *hc;
1413 +       struct hash_cell *hc = NULL;
1414  
1415         md = dm_get_md(huge_decode_dev(dev));
1416         if (!md)
1417                 return NULL;
1418  
1419 -       hc = dm_get_mdptr(md);
1420 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1421 +               hc = dm_get_mdptr(md);
1422 +
1423         if (!hc) {
1424                 dm_put(md);
1425                 return NULL;
1426 @@ -445,6 +450,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl 
1427  
1428  static int remove_all(struct dm_ioctl *param, size_t param_size)
1429  {
1430 +       if (!vx_check(0, VS_ADMIN))
1431 +               return -EPERM;
1432 +
1433         dm_hash_remove_all(1);
1434         param->data_size = 0;
1435         return 0;
1436 @@ -492,6 +500,8 @@ static int list_devices(struct dm_ioctl 
1437          */
1438         for (i = 0; i < NUM_BUCKETS; i++) {
1439                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1440 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1441 +                               continue;
1442                         needed += sizeof(struct dm_name_list);
1443                         needed += strlen(hc->name) + 1;
1444                         needed += ALIGN_MASK;
1445 @@ -515,6 +525,8 @@ static int list_devices(struct dm_ioctl 
1446          */
1447         for (i = 0; i < NUM_BUCKETS; i++) {
1448                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1449 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1450 +                               continue;
1451                         if (old_nl)
1452                                 old_nl->next = (uint32_t) ((void *) nl -
1453                                                            (void *) old_nl);
1454 @@ -1604,8 +1616,8 @@ static int ctl_ioctl(uint command, struc
1455         ioctl_fn fn = NULL;
1456         size_t input_param_size;
1457  
1458 -       /* only root can play with this */
1459 -       if (!capable(CAP_SYS_ADMIN))
1460 +       /* only root and certain contexts can play with this */
1461 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1462                 return -EACCES;
1463  
1464         if (_IOC_TYPE(command) != DM_IOCTL)
1465 diff -NurpP --minimal linux-3.1.1/drivers/md/dm.c linux-3.1.1-vs2.3.2/drivers/md/dm.c
1466 --- linux-3.1.1/drivers/md/dm.c 2011-10-24 18:45:10.000000000 +0200
1467 +++ linux-3.1.1-vs2.3.2/drivers/md/dm.c 2011-10-24 18:53:33.000000000 +0200
1468 @@ -20,6 +20,7 @@
1469  #include <linux/idr.h>
1470  #include <linux/hdreg.h>
1471  #include <linux/delay.h>
1472 +#include <linux/vs_base.h>
1473  
1474  #include <trace/events/block.h>
1475  
1476 @@ -122,6 +123,7 @@ struct mapped_device {
1477         rwlock_t map_lock;
1478         atomic_t holders;
1479         atomic_t open_count;
1480 +       xid_t xid;
1481  
1482         unsigned long flags;
1483  
1484 @@ -335,6 +337,7 @@ int dm_deleting_md(struct mapped_device 
1485  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1486  {
1487         struct mapped_device *md;
1488 +       int ret = -ENXIO;
1489  
1490         spin_lock(&_minor_lock);
1491  
1492 @@ -343,18 +346,19 @@ static int dm_blk_open(struct block_devi
1493                 goto out;
1494  
1495         if (test_bit(DMF_FREEING, &md->flags) ||
1496 -           dm_deleting_md(md)) {
1497 -               md = NULL;
1498 +           dm_deleting_md(md))
1499 +               goto out;
1500 +
1501 +       ret = -EACCES;
1502 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1503                 goto out;
1504 -       }
1505  
1506         dm_get(md);
1507         atomic_inc(&md->open_count);
1508 -
1509 +       ret = 0;
1510  out:
1511         spin_unlock(&_minor_lock);
1512 -
1513 -       return md ? 0 : -ENXIO;
1514 +       return ret;
1515  }
1516  
1517  static int dm_blk_close(struct gendisk *disk, fmode_t mode)
1518 @@ -575,6 +579,14 @@ int dm_set_geometry(struct mapped_device
1519         return 0;
1520  }
1521  
1522 +/*
1523 + * Get the xid associated with a dm device
1524 + */
1525 +xid_t dm_get_xid(struct mapped_device *md)
1526 +{
1527 +       return md->xid;
1528 +}
1529 +
1530  /*-----------------------------------------------------------------
1531   * CRUD START:
1532   *   A more elegant soln is in the works that uses the queue
1533 @@ -1848,6 +1860,7 @@ static struct mapped_device *alloc_dev(i
1534         INIT_LIST_HEAD(&md->uevent_list);
1535         spin_lock_init(&md->uevent_lock);
1536  
1537 +       md->xid = vx_current_xid();
1538         md->queue = blk_alloc_queue(GFP_KERNEL);
1539         if (!md->queue)
1540                 goto bad_queue;
1541 diff -NurpP --minimal linux-3.1.1/drivers/md/dm.h linux-3.1.1-vs2.3.2/drivers/md/dm.h
1542 --- linux-3.1.1/drivers/md/dm.h 2011-10-24 18:45:10.000000000 +0200
1543 +++ linux-3.1.1-vs2.3.2/drivers/md/dm.h 2011-10-24 18:53:33.000000000 +0200
1544 @@ -41,6 +41,8 @@ struct dm_dev_internal {
1545  struct dm_table;
1546  struct dm_md_mempools;
1547  
1548 +xid_t dm_get_xid(struct mapped_device *md);
1549 +
1550  /*-----------------------------------------------------------------
1551   * Internal table functions.
1552   *---------------------------------------------------------------*/
1553 diff -NurpP --minimal linux-3.1.1/drivers/net/tun.c linux-3.1.1-vs2.3.2/drivers/net/tun.c
1554 --- linux-3.1.1/drivers/net/tun.c       2011-10-24 18:45:17.000000000 +0200
1555 +++ linux-3.1.1-vs2.3.2/drivers/net/tun.c       2011-10-24 18:53:33.000000000 +0200
1556 @@ -64,6 +64,7 @@
1557  #include <linux/nsproxy.h>
1558  #include <linux/virtio_net.h>
1559  #include <linux/rcupdate.h>
1560 +#include <linux/vs_network.h>
1561  #include <net/net_namespace.h>
1562  #include <net/netns/generic.h>
1563  #include <net/rtnetlink.h>
1564 @@ -121,6 +122,7 @@ struct tun_struct {
1565         unsigned int            flags;
1566         uid_t                   owner;
1567         gid_t                   group;
1568 +       nid_t                   nid;
1569  
1570         struct net_device       *dev;
1571         u32                     set_features;
1572 @@ -909,6 +911,7 @@ static void tun_setup(struct net_device 
1573  
1574         tun->owner = -1;
1575         tun->group = -1;
1576 +       tun->nid = current->nid;
1577  
1578         dev->ethtool_ops = &tun_ethtool_ops;
1579         dev->destructor = tun_free_netdev;
1580 @@ -1059,7 +1062,7 @@ static int tun_set_iff(struct net *net, 
1581  
1582                 if (((tun->owner != -1 && cred->euid != tun->owner) ||
1583                      (tun->group != -1 && !in_egroup_p(tun->group))) &&
1584 -                   !capable(CAP_NET_ADMIN))
1585 +               !cap_raised(current_cap(), CAP_NET_ADMIN))
1586                         return -EPERM;
1587                 err = security_tun_dev_attach(tun->socket.sk);
1588                 if (err < 0)
1589 @@ -1073,7 +1076,7 @@ static int tun_set_iff(struct net *net, 
1590                 char *name;
1591                 unsigned long flags = 0;
1592  
1593 -               if (!capable(CAP_NET_ADMIN))
1594 +               if (!nx_capable(CAP_NET_ADMIN, NXC_TUN_CREATE))
1595                         return -EPERM;
1596                 err = security_tun_dev_create();
1597                 if (err < 0)
1598 @@ -1141,6 +1144,9 @@ static int tun_set_iff(struct net *net, 
1599  
1600                 sk->sk_destruct = tun_sock_destruct;
1601  
1602 +               if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
1603 +                       return -EPERM;
1604 +
1605                 err = tun_attach(tun, file);
1606                 if (err < 0)
1607                         goto failed;
1608 @@ -1322,6 +1328,16 @@ static long __tun_chr_ioctl(struct file 
1609                 tun_debug(KERN_INFO, tun, "group set to %d\n", tun->group);
1610                 break;
1611  
1612 +       case TUNSETNID:
1613 +               if (!capable(CAP_CONTEXT))
1614 +                       return -EPERM;
1615 +
1616 +               /* Set nid owner of the device */
1617 +               tun->nid = (nid_t) arg;
1618 +
1619 +               tun_debug(KERN_INFO, tun, "nid owner set to %u\n", tun->nid);
1620 +               break;
1621 +
1622         case TUNSETLINK:
1623                 /* Only allow setting the type when the interface is down */
1624                 if (tun->dev->flags & IFF_UP) {
1625 diff -NurpP --minimal linux-3.1.1/drivers/tty/sysrq.c linux-3.1.1-vs2.3.2/drivers/tty/sysrq.c
1626 --- linux-3.1.1/drivers/tty/sysrq.c     2011-05-22 16:17:44.000000000 +0200
1627 +++ linux-3.1.1-vs2.3.2/drivers/tty/sysrq.c     2011-10-24 18:53:33.000000000 +0200
1628 @@ -41,6 +41,7 @@
1629  #include <linux/oom.h>
1630  #include <linux/slab.h>
1631  #include <linux/input.h>
1632 +#include <linux/vserver/debug.h>
1633  
1634  #include <asm/ptrace.h>
1635  #include <asm/irq_regs.h>
1636 @@ -395,6 +396,21 @@ static struct sysrq_key_op sysrq_unrt_op
1637         .enable_mask    = SYSRQ_ENABLE_RTNICE,
1638  };
1639  
1640 +
1641 +#ifdef CONFIG_VSERVER_DEBUG
1642 +static void sysrq_handle_vxinfo(int key)
1643 +{
1644 +       dump_vx_info_inactive((key == 'x') ? 0 : 1);
1645 +}
1646 +
1647 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1648 +       .handler        = sysrq_handle_vxinfo,
1649 +       .help_msg       = "conteXt",
1650 +       .action_msg     = "Show Context Info",
1651 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
1652 +};
1653 +#endif
1654 +
1655  /* Key Operations table and lock */
1656  static DEFINE_SPINLOCK(sysrq_key_table_lock);
1657  
1658 @@ -449,7 +465,11 @@ static struct sysrq_key_op *sysrq_key_ta
1659         NULL,                           /* v */
1660         &sysrq_showstate_blocked_op,    /* w */
1661         /* x: May be registered on ppc/powerpc for xmon */
1662 +#ifdef CONFIG_VSERVER_DEBUG
1663 +       &sysrq_showvxinfo_op,           /* x */
1664 +#else
1665         NULL,                           /* x */
1666 +#endif
1667         /* y: May be registered on sparc64 for global register dump */
1668         NULL,                           /* y */
1669         &sysrq_ftrace_dump_op,          /* z */
1670 @@ -464,6 +484,8 @@ static int sysrq_key_table_key2index(int
1671                 retval = key - '0';
1672         else if ((key >= 'a') && (key <= 'z'))
1673                 retval = key + 10 - 'a';
1674 +       else if ((key >= 'A') && (key <= 'Z'))
1675 +               retval = key + 10 - 'A';
1676         else
1677                 retval = -1;
1678         return retval;
1679 diff -NurpP --minimal linux-3.1.1/drivers/tty/tty_io.c linux-3.1.1-vs2.3.2/drivers/tty/tty_io.c
1680 --- linux-3.1.1/drivers/tty/tty_io.c    2011-11-15 16:44:51.000000000 +0100
1681 +++ linux-3.1.1-vs2.3.2/drivers/tty/tty_io.c    2011-11-15 17:08:44.000000000 +0100
1682 @@ -105,6 +105,7 @@
1683  
1684  #include <linux/kmod.h>
1685  #include <linux/nsproxy.h>
1686 +#include <linux/vs_pid.h>
1687  
1688  #undef TTY_DEBUG_HANGUP
1689  
1690 @@ -2080,7 +2081,8 @@ static int tiocsti(struct tty_struct *tt
1691         char ch, mbz = 0;
1692         struct tty_ldisc *ld;
1693  
1694 -       if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
1695 +       if (((current->signal->tty != tty) &&
1696 +               !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
1697                 return -EPERM;
1698         if (get_user(ch, p))
1699                 return -EFAULT;
1700 @@ -2368,6 +2370,7 @@ static int tiocspgrp(struct tty_struct *
1701                 return -ENOTTY;
1702         if (get_user(pgrp_nr, p))
1703                 return -EFAULT;
1704 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
1705         if (pgrp_nr < 0)
1706                 return -EINVAL;
1707         rcu_read_lock();
1708 diff -NurpP --minimal linux-3.1.1/fs/attr.c linux-3.1.1-vs2.3.2/fs/attr.c
1709 --- linux-3.1.1/fs/attr.c       2011-10-24 18:45:26.000000000 +0200
1710 +++ linux-3.1.1-vs2.3.2/fs/attr.c       2011-10-24 18:53:33.000000000 +0200
1711 @@ -13,6 +13,9 @@
1712  #include <linux/fsnotify.h>
1713  #include <linux/fcntl.h>
1714  #include <linux/security.h>
1715 +#include <linux/proc_fs.h>
1716 +#include <linux/devpts_fs.h>
1717 +#include <linux/vs_tag.h>
1718  
1719  /**
1720   * inode_change_ok - check if attribute changes to an inode are allowed
1721 @@ -73,6 +76,10 @@ int inode_change_ok(const struct inode *
1722                         return -EPERM;
1723         }
1724  
1725 +       /* check for inode tag permission */
1726 +       if (dx_permission(inode, MAY_WRITE))
1727 +               return -EACCES;
1728 +
1729         return 0;
1730  }
1731  EXPORT_SYMBOL(inode_change_ok);
1732 @@ -143,6 +150,8 @@ void setattr_copy(struct inode *inode, c
1733                 inode->i_uid = attr->ia_uid;
1734         if (ia_valid & ATTR_GID)
1735                 inode->i_gid = attr->ia_gid;
1736 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
1737 +               inode->i_tag = attr->ia_tag;
1738         if (ia_valid & ATTR_ATIME)
1739                 inode->i_atime = timespec_trunc(attr->ia_atime,
1740                                                 inode->i_sb->s_time_gran);
1741 @@ -170,7 +179,8 @@ int notify_change(struct dentry * dentry
1742         struct timespec now;
1743         unsigned int ia_valid = attr->ia_valid;
1744  
1745 -       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
1746 +       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
1747 +               ATTR_TAG | ATTR_TIMES_SET)) {
1748                 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1749                         return -EPERM;
1750         }
1751 diff -NurpP --minimal linux-3.1.1/fs/binfmt_aout.c linux-3.1.1-vs2.3.2/fs/binfmt_aout.c
1752 --- linux-3.1.1/fs/binfmt_aout.c        2010-10-21 13:07:47.000000000 +0200
1753 +++ linux-3.1.1-vs2.3.2/fs/binfmt_aout.c        2011-10-24 18:53:33.000000000 +0200
1754 @@ -25,6 +25,7 @@
1755  #include <linux/init.h>
1756  #include <linux/coredump.h>
1757  #include <linux/slab.h>
1758 +#include <linux/vs_memory.h>
1759  
1760  #include <asm/system.h>
1761  #include <asm/uaccess.h>
1762 diff -NurpP --minimal linux-3.1.1/fs/binfmt_elf.c linux-3.1.1-vs2.3.2/fs/binfmt_elf.c
1763 --- linux-3.1.1/fs/binfmt_elf.c 2011-11-15 16:44:51.000000000 +0100
1764 +++ linux-3.1.1-vs2.3.2/fs/binfmt_elf.c 2011-11-15 17:08:44.000000000 +0100
1765 @@ -32,6 +32,7 @@
1766  #include <linux/elf.h>
1767  #include <linux/utsname.h>
1768  #include <linux/coredump.h>
1769 +#include <linux/vs_memory.h>
1770  #include <asm/uaccess.h>
1771  #include <asm/param.h>
1772  #include <asm/page.h>
1773 diff -NurpP --minimal linux-3.1.1/fs/binfmt_flat.c linux-3.1.1-vs2.3.2/fs/binfmt_flat.c
1774 --- linux-3.1.1/fs/binfmt_flat.c        2011-07-22 11:18:05.000000000 +0200
1775 +++ linux-3.1.1-vs2.3.2/fs/binfmt_flat.c        2011-10-24 18:53:33.000000000 +0200
1776 @@ -35,6 +35,7 @@
1777  #include <linux/init.h>
1778  #include <linux/flat.h>
1779  #include <linux/syscalls.h>
1780 +#include <linux/vs_memory.h>
1781  
1782  #include <asm/byteorder.h>
1783  #include <asm/system.h>
1784 diff -NurpP --minimal linux-3.1.1/fs/binfmt_som.c linux-3.1.1-vs2.3.2/fs/binfmt_som.c
1785 --- linux-3.1.1/fs/binfmt_som.c 2010-02-25 11:52:04.000000000 +0100
1786 +++ linux-3.1.1-vs2.3.2/fs/binfmt_som.c 2011-10-24 18:53:33.000000000 +0200
1787 @@ -28,6 +28,7 @@
1788  #include <linux/shm.h>
1789  #include <linux/personality.h>
1790  #include <linux/init.h>
1791 +#include <linux/vs_memory.h>
1792  
1793  #include <asm/uaccess.h>
1794  #include <asm/pgtable.h>
1795 diff -NurpP --minimal linux-3.1.1/fs/block_dev.c linux-3.1.1-vs2.3.2/fs/block_dev.c
1796 --- linux-3.1.1/fs/block_dev.c  2011-11-15 16:44:51.000000000 +0100
1797 +++ linux-3.1.1-vs2.3.2/fs/block_dev.c  2011-11-15 17:08:44.000000000 +0100
1798 @@ -25,6 +25,7 @@
1799  #include <linux/namei.h>
1800  #include <linux/log2.h>
1801  #include <linux/kmemleak.h>
1802 +#include <linux/vs_device.h>
1803  #include <asm/uaccess.h>
1804  #include "internal.h"
1805  
1806 @@ -563,6 +564,7 @@ struct block_device *bdget(dev_t dev)
1807                 bdev->bd_invalidated = 0;
1808                 inode->i_mode = S_IFBLK;
1809                 inode->i_rdev = dev;
1810 +               inode->i_mdev = dev;
1811                 inode->i_bdev = bdev;
1812                 inode->i_data.a_ops = &def_blk_aops;
1813                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
1814 @@ -609,6 +611,11 @@ EXPORT_SYMBOL(bdput);
1815  static struct block_device *bd_acquire(struct inode *inode)
1816  {
1817         struct block_device *bdev;
1818 +       dev_t mdev;
1819 +
1820 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
1821 +               return NULL;
1822 +       inode->i_mdev = mdev;
1823  
1824         spin_lock(&bdev_lock);
1825         bdev = inode->i_bdev;
1826 @@ -619,7 +626,7 @@ static struct block_device *bd_acquire(s
1827         }
1828         spin_unlock(&bdev_lock);
1829  
1830 -       bdev = bdget(inode->i_rdev);
1831 +       bdev = bdget(mdev);
1832         if (bdev) {
1833                 spin_lock(&bdev_lock);
1834                 if (!inode->i_bdev) {
1835 diff -NurpP --minimal linux-3.1.1/fs/btrfs/ctree.h linux-3.1.1-vs2.3.2/fs/btrfs/ctree.h
1836 --- linux-3.1.1/fs/btrfs/ctree.h        2011-10-24 18:45:26.000000000 +0200
1837 +++ linux-3.1.1-vs2.3.2/fs/btrfs/ctree.h        2011-10-24 18:53:33.000000000 +0200
1838 @@ -600,11 +600,14 @@ struct btrfs_inode_item {
1839         /* modification sequence number for NFS */
1840         __le64 sequence;
1841  
1842 +       __le16 tag;
1843         /*
1844          * a little future expansion, for more than this we can
1845          * just grow the inode item and version it
1846          */
1847 -       __le64 reserved[4];
1848 +       __le16 reserved16;
1849 +       __le32 reserved32;
1850 +       __le64 reserved[3];
1851         struct btrfs_timespec atime;
1852         struct btrfs_timespec ctime;
1853         struct btrfs_timespec mtime;
1854 @@ -1364,6 +1367,8 @@ struct btrfs_ioctl_defrag_range_args {
1855  #define BTRFS_MOUNT_AUTO_DEFRAG                (1 << 16)
1856  #define BTRFS_MOUNT_INODE_MAP_CACHE    (1 << 17)
1857  
1858 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
1859 +
1860  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
1861  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
1862  #define btrfs_test_opt(root, opt)      ((root)->fs_info->mount_opt & \
1863 @@ -1571,6 +1576,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
1864  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
1865  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
1866  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
1867 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
1868  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
1869  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
1870  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
1871 @@ -1624,6 +1630,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct 
1872  
1873  BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
1874  
1875 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
1876 +#define BTRFS_INODE_BARRIER            (1 << 25)
1877 +#define BTRFS_INODE_COW                        (1 << 26)
1878 +
1879  
1880  BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
1881  
1882 @@ -2603,6 +2613,7 @@ extern const struct dentry_operations bt
1883  long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
1884  void btrfs_update_iflags(struct inode *inode);
1885  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
1886 +int btrfs_sync_flags(struct inode *inode, int, int);
1887  int btrfs_defrag_file(struct inode *inode, struct file *file,
1888                       struct btrfs_ioctl_defrag_range_args *range,
1889                       u64 newer_than, unsigned long max_pages);
1890 diff -NurpP --minimal linux-3.1.1/fs/btrfs/disk-io.c linux-3.1.1-vs2.3.2/fs/btrfs/disk-io.c
1891 --- linux-3.1.1/fs/btrfs/disk-io.c      2011-10-24 18:45:26.000000000 +0200
1892 +++ linux-3.1.1-vs2.3.2/fs/btrfs/disk-io.c      2011-10-24 18:53:33.000000000 +0200
1893 @@ -1794,6 +1794,9 @@ struct btrfs_root *open_ctree(struct sup
1894                 goto fail_alloc;
1895         }
1896  
1897 +       if (btrfs_test_opt(tree_root, TAGGED))
1898 +               sb->s_flags |= MS_TAGGED;
1899 +
1900         features = btrfs_super_incompat_flags(disk_super) &
1901                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
1902         if (features) {
1903 diff -NurpP --minimal linux-3.1.1/fs/btrfs/inode.c linux-3.1.1-vs2.3.2/fs/btrfs/inode.c
1904 --- linux-3.1.1/fs/btrfs/inode.c        2011-10-24 18:45:26.000000000 +0200
1905 +++ linux-3.1.1-vs2.3.2/fs/btrfs/inode.c        2011-10-24 18:53:33.000000000 +0200
1906 @@ -38,6 +38,7 @@
1907  #include <linux/falloc.h>
1908  #include <linux/slab.h>
1909  #include <linux/ratelimit.h>
1910 +#include <linux/vs_tag.h>
1911  #include "compat.h"
1912  #include "ctree.h"
1913  #include "disk-io.h"
1914 @@ -2508,6 +2509,8 @@ static void btrfs_read_locked_inode(stru
1915         struct btrfs_key location;
1916         int maybe_acls;
1917         u32 rdev;
1918 +       uid_t uid;
1919 +       gid_t gid;
1920         int ret;
1921         bool filled = false;
1922  
1923 @@ -2535,8 +2538,13 @@ static void btrfs_read_locked_inode(stru
1924                                     struct btrfs_inode_item);
1925         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
1926         inode->i_nlink = btrfs_inode_nlink(leaf, inode_item);
1927 -       inode->i_uid = btrfs_inode_uid(leaf, inode_item);
1928 -       inode->i_gid = btrfs_inode_gid(leaf, inode_item);
1929 +
1930 +       uid = btrfs_inode_uid(leaf, inode_item);
1931 +       gid = btrfs_inode_gid(leaf, inode_item);
1932 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
1933 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
1934 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
1935 +               btrfs_inode_tag(leaf, inode_item));
1936         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
1937  
1938         tspec = btrfs_inode_atime(inode_item);
1939 @@ -2614,8 +2622,14 @@ static void fill_inode_item(struct btrfs
1940                             struct btrfs_inode_item *item,
1941                             struct inode *inode)
1942  {
1943 -       btrfs_set_inode_uid(leaf, item, inode->i_uid);
1944 -       btrfs_set_inode_gid(leaf, item, inode->i_gid);
1945 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
1946 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
1947 +
1948 +       btrfs_set_inode_uid(leaf, item, uid);
1949 +       btrfs_set_inode_gid(leaf, item, gid);
1950 +#ifdef CONFIG_TAGGING_INTERN
1951 +       btrfs_set_inode_tag(leaf, item, inode->i_tag);
1952 +#endif
1953         btrfs_set_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size);
1954         btrfs_set_inode_mode(leaf, item, inode->i_mode);
1955         btrfs_set_inode_nlink(leaf, item, inode->i_nlink);
1956 @@ -7393,11 +7407,13 @@ static const struct inode_operations btr
1957         .listxattr      = btrfs_listxattr,
1958         .removexattr    = btrfs_removexattr,
1959         .permission     = btrfs_permission,
1960 +       .sync_flags     = btrfs_sync_flags,
1961         .get_acl        = btrfs_get_acl,
1962  };
1963  static const struct inode_operations btrfs_dir_ro_inode_operations = {
1964         .lookup         = btrfs_lookup,
1965         .permission     = btrfs_permission,
1966 +       .sync_flags     = btrfs_sync_flags,
1967         .get_acl        = btrfs_get_acl,
1968  };
1969  
1970 diff -NurpP --minimal linux-3.1.1/fs/btrfs/ioctl.c linux-3.1.1-vs2.3.2/fs/btrfs/ioctl.c
1971 --- linux-3.1.1/fs/btrfs/ioctl.c        2011-10-24 18:45:26.000000000 +0200
1972 +++ linux-3.1.1-vs2.3.2/fs/btrfs/ioctl.c        2011-10-24 18:53:33.000000000 +0200
1973 @@ -70,10 +70,13 @@ static unsigned int btrfs_flags_to_ioctl
1974  {
1975         unsigned int iflags = 0;
1976  
1977 -       if (flags & BTRFS_INODE_SYNC)
1978 -               iflags |= FS_SYNC_FL;
1979         if (flags & BTRFS_INODE_IMMUTABLE)
1980                 iflags |= FS_IMMUTABLE_FL;
1981 +       if (flags & BTRFS_INODE_IXUNLINK)
1982 +               iflags |= FS_IXUNLINK_FL;
1983 +
1984 +       if (flags & BTRFS_INODE_SYNC)
1985 +               iflags |= FS_SYNC_FL;
1986         if (flags & BTRFS_INODE_APPEND)
1987                 iflags |= FS_APPEND_FL;
1988         if (flags & BTRFS_INODE_NODUMP)
1989 @@ -90,28 +93,78 @@ static unsigned int btrfs_flags_to_ioctl
1990         else if (flags & BTRFS_INODE_NOCOMPRESS)
1991                 iflags |= FS_NOCOMP_FL;
1992  
1993 +       if (flags & BTRFS_INODE_BARRIER)
1994 +               iflags |= FS_BARRIER_FL;
1995 +       if (flags & BTRFS_INODE_COW)
1996 +               iflags |= FS_COW_FL;
1997         return iflags;
1998  }
1999  
2000  /*
2001 - * Update inode->i_flags based on the btrfs internal flags.
2002 + * Update inode->i_(v)flags based on the btrfs internal flags.
2003   */
2004  void btrfs_update_iflags(struct inode *inode)
2005  {
2006         struct btrfs_inode *ip = BTRFS_I(inode);
2007  
2008 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2009 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2010 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2011  
2012 -       if (ip->flags & BTRFS_INODE_SYNC)
2013 -               inode->i_flags |= S_SYNC;
2014         if (ip->flags & BTRFS_INODE_IMMUTABLE)
2015                 inode->i_flags |= S_IMMUTABLE;
2016 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
2017 +               inode->i_flags |= S_IXUNLINK;
2018 +
2019 +       if (ip->flags & BTRFS_INODE_SYNC)
2020 +               inode->i_flags |= S_SYNC;
2021         if (ip->flags & BTRFS_INODE_APPEND)
2022                 inode->i_flags |= S_APPEND;
2023         if (ip->flags & BTRFS_INODE_NOATIME)
2024                 inode->i_flags |= S_NOATIME;
2025         if (ip->flags & BTRFS_INODE_DIRSYNC)
2026                 inode->i_flags |= S_DIRSYNC;
2027 +
2028 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2029 +
2030 +       if (ip->flags & BTRFS_INODE_BARRIER)
2031 +               inode->i_vflags |= V_BARRIER;
2032 +       if (ip->flags & BTRFS_INODE_COW)
2033 +               inode->i_vflags |= V_COW;
2034 +}
2035 +
2036 +/*
2037 + * Update btrfs internal flags from inode->i_(v)flags.
2038 + */
2039 +void btrfs_update_flags(struct inode *inode)
2040 +{
2041 +       struct btrfs_inode *ip = BTRFS_I(inode);
2042 +
2043 +       unsigned int flags = inode->i_flags;
2044 +       unsigned int vflags = inode->i_vflags;
2045 +
2046 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
2047 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
2048 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
2049 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
2050 +
2051 +       if (flags & S_IMMUTABLE)
2052 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
2053 +       if (flags & S_IXUNLINK)
2054 +               ip->flags |= BTRFS_INODE_IXUNLINK;
2055 +
2056 +       if (flags & S_SYNC)
2057 +               ip->flags |= BTRFS_INODE_SYNC;
2058 +       if (flags & S_APPEND)
2059 +               ip->flags |= BTRFS_INODE_APPEND;
2060 +       if (flags & S_NOATIME)
2061 +               ip->flags |= BTRFS_INODE_NOATIME;
2062 +       if (flags & S_DIRSYNC)
2063 +               ip->flags |= BTRFS_INODE_DIRSYNC;
2064 +
2065 +       if (vflags & V_BARRIER)
2066 +               ip->flags |= BTRFS_INODE_BARRIER;
2067 +       if (vflags & V_COW)
2068 +               ip->flags |= BTRFS_INODE_COW;
2069  }
2070  
2071  /*
2072 @@ -129,7 +182,7 @@ void btrfs_inherit_iflags(struct inode *
2073         flags = BTRFS_I(dir)->flags;
2074  
2075         if (S_ISREG(inode->i_mode))
2076 -               flags &= ~BTRFS_INODE_DIRSYNC;
2077 +               flags &= ~(BTRFS_INODE_DIRSYNC | BTRFS_INODE_BARRIER);
2078         else if (!S_ISDIR(inode->i_mode))
2079                 flags &= (BTRFS_INODE_NODUMP | BTRFS_INODE_NOATIME);
2080  
2081 @@ -137,6 +190,30 @@ void btrfs_inherit_iflags(struct inode *
2082         btrfs_update_iflags(inode);
2083  }
2084  
2085 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
2086 +{
2087 +       struct btrfs_inode *ip = BTRFS_I(inode);
2088 +       struct btrfs_root *root = ip->root;
2089 +       struct btrfs_trans_handle *trans;
2090 +       int ret;
2091 +
2092 +       trans = btrfs_join_transaction(root);
2093 +       BUG_ON(!trans);
2094 +
2095 +       inode->i_flags = flags;
2096 +       inode->i_vflags = vflags;
2097 +       btrfs_update_flags(inode);
2098 +
2099 +       ret = btrfs_update_inode(trans, root, inode);
2100 +       BUG_ON(ret);
2101 +
2102 +       btrfs_update_iflags(inode);
2103 +       inode->i_ctime = CURRENT_TIME;
2104 +       btrfs_end_transaction(trans, root);
2105 +
2106 +       return 0;
2107 +}
2108 +
2109  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
2110  {
2111         struct btrfs_inode *ip = BTRFS_I(file->f_path.dentry->d_inode);
2112 @@ -188,7 +265,8 @@ static int btrfs_ioctl_setflags(struct f
2113  
2114         flags = btrfs_mask_flags(inode->i_mode, flags);
2115         oldflags = btrfs_flags_to_ioctl(ip->flags);
2116 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
2117 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
2118 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
2119                 if (!capable(CAP_LINUX_IMMUTABLE)) {
2120                         ret = -EPERM;
2121                         goto out_unlock;
2122 @@ -199,14 +277,19 @@ static int btrfs_ioctl_setflags(struct f
2123         if (ret)
2124                 goto out_unlock;
2125  
2126 -       if (flags & FS_SYNC_FL)
2127 -               ip->flags |= BTRFS_INODE_SYNC;
2128 -       else
2129 -               ip->flags &= ~BTRFS_INODE_SYNC;
2130         if (flags & FS_IMMUTABLE_FL)
2131                 ip->flags |= BTRFS_INODE_IMMUTABLE;
2132         else
2133                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
2134 +       if (flags & FS_IXUNLINK_FL)
2135 +               ip->flags |= BTRFS_INODE_IXUNLINK;
2136 +       else
2137 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
2138 +
2139 +       if (flags & FS_SYNC_FL)
2140 +               ip->flags |= BTRFS_INODE_SYNC;
2141 +       else
2142 +               ip->flags &= ~BTRFS_INODE_SYNC;
2143         if (flags & FS_APPEND_FL)
2144                 ip->flags |= BTRFS_INODE_APPEND;
2145         else
2146 diff -NurpP --minimal linux-3.1.1/fs/btrfs/super.c linux-3.1.1-vs2.3.2/fs/btrfs/super.c
2147 --- linux-3.1.1/fs/btrfs/super.c        2011-07-22 11:18:05.000000000 +0200
2148 +++ linux-3.1.1-vs2.3.2/fs/btrfs/super.c        2011-10-24 18:53:33.000000000 +0200
2149 @@ -162,7 +162,7 @@ enum {
2150         Opt_notreelog, Opt_ratio, Opt_flushoncommit, Opt_discard,
2151         Opt_space_cache, Opt_clear_cache, Opt_user_subvol_rm_allowed,
2152         Opt_enospc_debug, Opt_subvolrootid, Opt_defrag,
2153 -       Opt_inode_cache, Opt_err,
2154 +       Opt_inode_cache, Opt_tag, Opt_notag, Opt_tagid, Opt_err,
2155  };
2156  
2157  static match_table_t tokens = {
2158 @@ -195,6 +195,9 @@ static match_table_t tokens = {
2159         {Opt_subvolrootid, "subvolrootid=%d"},
2160         {Opt_defrag, "autodefrag"},
2161         {Opt_inode_cache, "inode_cache"},
2162 +       {Opt_tag, "tag"},
2163 +       {Opt_notag, "notag"},
2164 +       {Opt_tagid, "tagid=%u"},
2165         {Opt_err, NULL},
2166  };
2167  
2168 @@ -381,6 +384,22 @@ int btrfs_parse_options(struct btrfs_roo
2169                         printk(KERN_INFO "btrfs: enabling auto defrag");
2170                         btrfs_set_opt(info->mount_opt, AUTO_DEFRAG);
2171                         break;
2172 +#ifndef CONFIG_TAGGING_NONE
2173 +               case Opt_tag:
2174 +                       printk(KERN_INFO "btrfs: use tagging\n");
2175 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2176 +                       break;
2177 +               case Opt_notag:
2178 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
2179 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
2180 +                       break;
2181 +#endif
2182 +#ifdef CONFIG_PROPAGATE
2183 +               case Opt_tagid:
2184 +                       /* use args[0] */
2185 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2186 +                       break;
2187 +#endif
2188                 case Opt_err:
2189                         printk(KERN_INFO "btrfs: unrecognized mount option "
2190                                "'%s'\n", p);
2191 @@ -907,6 +926,12 @@ static int btrfs_remount(struct super_bl
2192         if (ret)
2193                 return -EINVAL;
2194  
2195 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
2196 +               printk("btrfs: %s: tagging not permitted on remount.\n",
2197 +                       sb->s_id);
2198 +               return -EINVAL;
2199 +       }
2200 +
2201         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
2202                 return 0;
2203  
2204 diff -NurpP --minimal linux-3.1.1/fs/char_dev.c linux-3.1.1-vs2.3.2/fs/char_dev.c
2205 --- linux-3.1.1/fs/char_dev.c   2011-03-15 18:07:31.000000000 +0100
2206 +++ linux-3.1.1-vs2.3.2/fs/char_dev.c   2011-10-24 18:53:33.000000000 +0200
2207 @@ -21,6 +21,8 @@
2208  #include <linux/mutex.h>
2209  #include <linux/backing-dev.h>
2210  #include <linux/tty.h>
2211 +#include <linux/vs_context.h>
2212 +#include <linux/vs_device.h>
2213  
2214  #include "internal.h"
2215  
2216 @@ -371,14 +373,21 @@ static int chrdev_open(struct inode *ino
2217         struct cdev *p;
2218         struct cdev *new = NULL;
2219         int ret = 0;
2220 +       dev_t mdev;
2221 +
2222 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2223 +               return -EPERM;
2224 +       inode->i_mdev = mdev;
2225  
2226         spin_lock(&cdev_lock);
2227         p = inode->i_cdev;
2228         if (!p) {
2229                 struct kobject *kobj;
2230                 int idx;
2231 +
2232                 spin_unlock(&cdev_lock);
2233 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2234 +
2235 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
2236                 if (!kobj)
2237                         return -ENXIO;
2238                 new = container_of(kobj, struct cdev, kobj);
2239 diff -NurpP --minimal linux-3.1.1/fs/dcache.c linux-3.1.1-vs2.3.2/fs/dcache.c
2240 --- linux-3.1.1/fs/dcache.c     2011-10-24 18:45:26.000000000 +0200
2241 +++ linux-3.1.1-vs2.3.2/fs/dcache.c     2011-10-24 18:53:33.000000000 +0200
2242 @@ -36,6 +36,7 @@
2243  #include <linux/bit_spinlock.h>
2244  #include <linux/rculist_bl.h>
2245  #include <linux/prefetch.h>
2246 +#include <linux/vs_limit.h>
2247  #include "internal.h"
2248  
2249  /*
2250 @@ -513,6 +514,8 @@ int d_invalidate(struct dentry * dentry)
2251                 spin_lock(&dentry->d_lock);
2252         }
2253  
2254 +       vx_dentry_dec(dentry);
2255 +
2256         /*
2257          * Somebody else still using it?
2258          *
2259 @@ -540,6 +543,7 @@ EXPORT_SYMBOL(d_invalidate);
2260  static inline void __dget_dlock(struct dentry *dentry)
2261  {
2262         dentry->d_count++;
2263 +       vx_dentry_inc(dentry);
2264  }
2265  
2266  static inline void __dget(struct dentry *dentry)
2267 @@ -1175,6 +1179,9 @@ struct dentry *__d_alloc(struct super_bl
2268         struct dentry *dentry;
2269         char *dname;
2270  
2271 +       if (!vx_dentry_avail(1))
2272 +               return NULL;
2273 +
2274         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2275         if (!dentry)
2276                 return NULL;
2277 @@ -1197,6 +1204,7 @@ struct dentry *__d_alloc(struct super_bl
2278  
2279         dentry->d_count = 1;
2280         dentry->d_flags = 0;
2281 +       vx_dentry_inc(dentry);
2282         spin_lock_init(&dentry->d_lock);
2283         seqcount_init(&dentry->d_seq);
2284         dentry->d_inode = NULL;
2285 @@ -1853,6 +1861,7 @@ struct dentry *__d_lookup(struct dentry 
2286                 }
2287  
2288                 dentry->d_count++;
2289 +               vx_dentry_inc(dentry);
2290                 found = dentry;
2291                 spin_unlock(&dentry->d_lock);
2292                 break;
2293 diff -NurpP --minimal linux-3.1.1/fs/devpts/inode.c linux-3.1.1-vs2.3.2/fs/devpts/inode.c
2294 --- linux-3.1.1/fs/devpts/inode.c       2011-05-22 16:17:50.000000000 +0200
2295 +++ linux-3.1.1-vs2.3.2/fs/devpts/inode.c       2011-10-24 18:53:33.000000000 +0200
2296 @@ -25,6 +25,7 @@
2297  #include <linux/parser.h>
2298  #include <linux/fsnotify.h>
2299  #include <linux/seq_file.h>
2300 +#include <linux/vs_base.h>
2301  
2302  #define DEVPTS_DEFAULT_MODE 0600
2303  /*
2304 @@ -36,6 +37,20 @@
2305  #define DEVPTS_DEFAULT_PTMX_MODE 0000
2306  #define PTMX_MINOR     2
2307  
2308 +static int devpts_permission(struct inode *inode, int mask)
2309 +{
2310 +       int ret = -EACCES;
2311 +
2312 +       /* devpts is xid tagged */
2313 +       if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
2314 +               ret = generic_permission(inode, mask);
2315 +       return ret;
2316 +}
2317 +
2318 +static struct inode_operations devpts_file_inode_operations = {
2319 +       .permission     = devpts_permission,
2320 +};
2321 +
2322  extern int pty_limit;                  /* Config limit on Unix98 ptys */
2323  static DEFINE_MUTEX(allocated_ptys_lock);
2324  
2325 @@ -263,6 +278,34 @@ static int devpts_show_options(struct se
2326         return 0;
2327  }
2328  
2329 +static int devpts_filter(struct dentry *de)
2330 +{
2331 +       xid_t xid = 0;
2332 +
2333 +       /* devpts is xid tagged */
2334 +       if (de && de->d_inode)
2335 +               xid = (xid_t)de->d_inode->i_tag;
2336 +#ifdef CONFIG_VSERVER_WARN_DEVPTS
2337 +       else
2338 +               vxwprintk_task(1, "devpts " VS_Q("%.*s") " without inode.",
2339 +                       de->d_name.len, de->d_name.name);
2340 +#endif
2341 +       return vx_check(xid, VS_WATCH_P | VS_IDENT);
2342 +}
2343 +
2344 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2345 +{
2346 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2347 +}
2348 +
2349 +static struct file_operations devpts_dir_operations = {
2350 +       .open           = dcache_dir_open,
2351 +       .release        = dcache_dir_close,
2352 +       .llseek         = dcache_dir_lseek,
2353 +       .read           = generic_read_dir,
2354 +       .readdir        = devpts_readdir,
2355 +};
2356 +
2357  static const struct super_operations devpts_sops = {
2358         .statfs         = simple_statfs,
2359         .remount_fs     = devpts_remount,
2360 @@ -302,12 +345,15 @@ devpts_fill_super(struct super_block *s,
2361         inode = new_inode(s);
2362         if (!inode)
2363                 goto free_fsi;
2364 +
2365         inode->i_ino = 1;
2366         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2367         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2368         inode->i_op = &simple_dir_inode_operations;
2369 -       inode->i_fop = &simple_dir_operations;
2370 +       inode->i_fop = &devpts_dir_operations;
2371         inode->i_nlink = 2;
2372 +       /* devpts is xid tagged */
2373 +       inode->i_tag = (tag_t)vx_current_xid();
2374  
2375         s->s_root = d_alloc_root(inode);
2376         if (s->s_root)
2377 @@ -494,6 +540,9 @@ int devpts_pty_new(struct inode *ptmx_in
2378         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2379         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2380         init_special_inode(inode, S_IFCHR|opts->mode, device);
2381 +       /* devpts is xid tagged */
2382 +       inode->i_tag = (tag_t)vx_current_xid();
2383 +       inode->i_op = &devpts_file_inode_operations;
2384         inode->i_private = tty;
2385         tty->driver_data = inode;
2386  
2387 diff -NurpP --minimal linux-3.1.1/fs/ext2/balloc.c linux-3.1.1-vs2.3.2/fs/ext2/balloc.c
2388 --- linux-3.1.1/fs/ext2/balloc.c        2011-05-22 16:17:51.000000000 +0200
2389 +++ linux-3.1.1-vs2.3.2/fs/ext2/balloc.c        2011-10-24 18:53:33.000000000 +0200
2390 @@ -701,7 +701,6 @@ ext2_try_to_allocate(struct super_block 
2391                         start = 0;
2392                 end = EXT2_BLOCKS_PER_GROUP(sb);
2393         }
2394 -
2395         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2396  
2397  repeat:
2398 diff -NurpP --minimal linux-3.1.1/fs/ext2/ext2.h linux-3.1.1-vs2.3.2/fs/ext2/ext2.h
2399 --- linux-3.1.1/fs/ext2/ext2.h  2011-10-24 18:45:27.000000000 +0200
2400 +++ linux-3.1.1-vs2.3.2/fs/ext2/ext2.h  2011-10-24 18:53:33.000000000 +0200
2401 @@ -126,6 +126,7 @@ extern void ext2_set_inode_flags(struct 
2402  extern void ext2_get_inode_flags(struct ext2_inode_info *);
2403  extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2404                        u64 start, u64 len);
2405 +extern int ext2_sync_flags(struct inode *, int, int);
2406  
2407  /* ioctl.c */
2408  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2409 diff -NurpP --minimal linux-3.1.1/fs/ext2/file.c linux-3.1.1-vs2.3.2/fs/ext2/file.c
2410 --- linux-3.1.1/fs/ext2/file.c  2011-10-24 18:45:27.000000000 +0200
2411 +++ linux-3.1.1-vs2.3.2/fs/ext2/file.c  2011-10-24 18:53:33.000000000 +0200
2412 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
2413         .setattr        = ext2_setattr,
2414         .get_acl        = ext2_get_acl,
2415         .fiemap         = ext2_fiemap,
2416 +       .sync_flags     = ext2_sync_flags,
2417  };
2418 diff -NurpP --minimal linux-3.1.1/fs/ext2/ialloc.c linux-3.1.1-vs2.3.2/fs/ext2/ialloc.c
2419 --- linux-3.1.1/fs/ext2/ialloc.c        2011-05-22 16:17:51.000000000 +0200
2420 +++ linux-3.1.1-vs2.3.2/fs/ext2/ialloc.c        2011-10-24 18:53:33.000000000 +0200
2421 @@ -17,6 +17,7 @@
2422  #include <linux/backing-dev.h>
2423  #include <linux/buffer_head.h>
2424  #include <linux/random.h>
2425 +#include <linux/vs_tag.h>
2426  #include "ext2.h"
2427  #include "xattr.h"
2428  #include "acl.h"
2429 @@ -549,6 +550,7 @@ got:
2430                 inode->i_mode = mode;
2431                 inode->i_uid = current_fsuid();
2432                 inode->i_gid = dir->i_gid;
2433 +               inode->i_tag = dx_current_fstag(sb);
2434         } else
2435                 inode_init_owner(inode, dir, mode);
2436  
2437 diff -NurpP --minimal linux-3.1.1/fs/ext2/inode.c linux-3.1.1-vs2.3.2/fs/ext2/inode.c
2438 --- linux-3.1.1/fs/ext2/inode.c 2011-10-24 18:45:27.000000000 +0200
2439 +++ linux-3.1.1-vs2.3.2/fs/ext2/inode.c 2011-10-24 18:53:33.000000000 +0200
2440 @@ -32,6 +32,7 @@
2441  #include <linux/mpage.h>
2442  #include <linux/fiemap.h>
2443  #include <linux/namei.h>
2444 +#include <linux/vs_tag.h>
2445  #include "ext2.h"
2446  #include "acl.h"
2447  #include "xip.h"
2448 @@ -1167,7 +1168,7 @@ static void ext2_truncate_blocks(struct 
2449                 return;
2450         if (ext2_inode_is_fast_symlink(inode))
2451                 return;
2452 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2453 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2454                 return;
2455         __ext2_truncate_blocks(inode, offset);
2456  }
2457 @@ -1258,36 +1259,61 @@ void ext2_set_inode_flags(struct inode *
2458  {
2459         unsigned int flags = EXT2_I(inode)->i_flags;
2460  
2461 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2462 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2463 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2464 +
2465 +
2466 +       if (flags & EXT2_IMMUTABLE_FL)
2467 +               inode->i_flags |= S_IMMUTABLE;
2468 +       if (flags & EXT2_IXUNLINK_FL)
2469 +               inode->i_flags |= S_IXUNLINK;
2470 +
2471         if (flags & EXT2_SYNC_FL)
2472                 inode->i_flags |= S_SYNC;
2473         if (flags & EXT2_APPEND_FL)
2474                 inode->i_flags |= S_APPEND;
2475 -       if (flags & EXT2_IMMUTABLE_FL)
2476 -               inode->i_flags |= S_IMMUTABLE;
2477         if (flags & EXT2_NOATIME_FL)
2478                 inode->i_flags |= S_NOATIME;
2479         if (flags & EXT2_DIRSYNC_FL)
2480                 inode->i_flags |= S_DIRSYNC;
2481 +
2482 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2483 +
2484 +       if (flags & EXT2_BARRIER_FL)
2485 +               inode->i_vflags |= V_BARRIER;
2486 +       if (flags & EXT2_COW_FL)
2487 +               inode->i_vflags |= V_COW;
2488  }
2489  
2490  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2491  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2492  {
2493         unsigned int flags = ei->vfs_inode.i_flags;
2494 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2495 +
2496 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2497 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2498 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2499 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2500 +
2501 +       if (flags & S_IMMUTABLE)
2502 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2503 +       if (flags & S_IXUNLINK)
2504 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2505  
2506 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2507 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2508         if (flags & S_SYNC)
2509                 ei->i_flags |= EXT2_SYNC_FL;
2510         if (flags & S_APPEND)
2511                 ei->i_flags |= EXT2_APPEND_FL;
2512 -       if (flags & S_IMMUTABLE)
2513 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2514         if (flags & S_NOATIME)
2515                 ei->i_flags |= EXT2_NOATIME_FL;
2516         if (flags & S_DIRSYNC)
2517                 ei->i_flags |= EXT2_DIRSYNC_FL;
2518 +
2519 +       if (vflags & V_BARRIER)
2520 +               ei->i_flags |= EXT2_BARRIER_FL;
2521 +       if (vflags & V_COW)
2522 +               ei->i_flags |= EXT2_COW_FL;
2523  }
2524  
2525  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2526 @@ -1297,6 +1323,8 @@ struct inode *ext2_iget (struct super_bl
2527         struct ext2_inode *raw_inode;
2528         struct inode *inode;
2529         long ret = -EIO;
2530 +       uid_t uid;
2531 +       gid_t gid;
2532         int n;
2533  
2534         inode = iget_locked(sb, ino);
2535 @@ -1315,12 +1343,17 @@ struct inode *ext2_iget (struct super_bl
2536         }
2537  
2538         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2539 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2540 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2541 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2542 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2543         if (!(test_opt (inode->i_sb, NO_UID32))) {
2544 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2545 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2546 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2547 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2548         }
2549 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2550 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2551 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2552 +               le16_to_cpu(raw_inode->i_raw_tag));
2553 +
2554         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
2555         inode->i_size = le32_to_cpu(raw_inode->i_size);
2556         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2557 @@ -1418,8 +1451,8 @@ static int __ext2_write_inode(struct ino
2558         struct ext2_inode_info *ei = EXT2_I(inode);
2559         struct super_block *sb = inode->i_sb;
2560         ino_t ino = inode->i_ino;
2561 -       uid_t uid = inode->i_uid;
2562 -       gid_t gid = inode->i_gid;
2563 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2564 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2565         struct buffer_head * bh;
2566         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2567         int n;
2568 @@ -1455,6 +1488,9 @@ static int __ext2_write_inode(struct ino
2569                 raw_inode->i_uid_high = 0;
2570                 raw_inode->i_gid_high = 0;
2571         }
2572 +#ifdef CONFIG_TAGGING_INTERN
2573 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2574 +#endif
2575         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2576         raw_inode->i_size = cpu_to_le32(inode->i_size);
2577         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2578 @@ -1535,7 +1571,8 @@ int ext2_setattr(struct dentry *dentry, 
2579         if (is_quota_modification(inode, iattr))
2580                 dquot_initialize(inode);
2581         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
2582 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
2583 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
2584 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
2585                 error = dquot_transfer(inode, iattr);
2586                 if (error)
2587                         return error;
2588 diff -NurpP --minimal linux-3.1.1/fs/ext2/ioctl.c linux-3.1.1-vs2.3.2/fs/ext2/ioctl.c
2589 --- linux-3.1.1/fs/ext2/ioctl.c 2011-05-22 16:17:51.000000000 +0200
2590 +++ linux-3.1.1-vs2.3.2/fs/ext2/ioctl.c 2011-10-24 18:53:33.000000000 +0200
2591 @@ -17,6 +17,16 @@
2592  #include <asm/uaccess.h>
2593  
2594  
2595 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2596 +{
2597 +       inode->i_flags = flags;
2598 +       inode->i_vflags = vflags;
2599 +       ext2_get_inode_flags(EXT2_I(inode));
2600 +       inode->i_ctime = CURRENT_TIME_SEC;
2601 +       mark_inode_dirty(inode);
2602 +       return 0;
2603 +}
2604 +
2605  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2606  {
2607         struct inode *inode = filp->f_dentry->d_inode;
2608 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2609  
2610                 flags = ext2_mask_flags(inode->i_mode, flags);
2611  
2612 +               if (IS_BARRIER(inode)) {
2613 +                       vxwprintk_task(1, "messing with the barrier.");
2614 +                       return -EACCES;
2615 +               }
2616 +
2617                 mutex_lock(&inode->i_mutex);
2618                 /* Is it quota file? Do not allow user to mess with it */
2619                 if (IS_NOQUOTA(inode)) {
2620 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2621                  *
2622                  * This test looks nicer. Thanks to Pauline Middelink
2623                  */
2624 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2625 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2626 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2627 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2628                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2629                                 mutex_unlock(&inode->i_mutex);
2630                                 ret = -EPERM;
2631 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2632                         }
2633                 }
2634  
2635 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
2636 +               flags &= EXT2_FL_USER_MODIFIABLE;
2637                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2638                 ei->i_flags = flags;
2639                 mutex_unlock(&inode->i_mutex);
2640 diff -NurpP --minimal linux-3.1.1/fs/ext2/namei.c linux-3.1.1-vs2.3.2/fs/ext2/namei.c
2641 --- linux-3.1.1/fs/ext2/namei.c 2011-10-24 18:45:27.000000000 +0200
2642 +++ linux-3.1.1-vs2.3.2/fs/ext2/namei.c 2011-10-24 18:53:33.000000000 +0200
2643 @@ -32,6 +32,7 @@
2644  
2645  #include <linux/pagemap.h>
2646  #include <linux/quotaops.h>
2647 +#include <linux/vs_tag.h>
2648  #include "ext2.h"
2649  #include "xattr.h"
2650  #include "acl.h"
2651 @@ -73,6 +74,7 @@ static struct dentry *ext2_lookup(struct
2652                                         (unsigned long) ino);
2653                         return ERR_PTR(-EIO);
2654                 }
2655 +               dx_propagate_tag(nd, inode);
2656         }
2657         return d_splice_alias(inode, dentry);
2658  }
2659 @@ -408,6 +410,7 @@ const struct inode_operations ext2_dir_i
2660         .removexattr    = generic_removexattr,
2661  #endif
2662         .setattr        = ext2_setattr,
2663 +       .sync_flags     = ext2_sync_flags,
2664         .get_acl        = ext2_get_acl,
2665  };
2666  
2667 diff -NurpP --minimal linux-3.1.1/fs/ext2/super.c linux-3.1.1-vs2.3.2/fs/ext2/super.c
2668 --- linux-3.1.1/fs/ext2/super.c 2011-07-22 11:18:05.000000000 +0200
2669 +++ linux-3.1.1-vs2.3.2/fs/ext2/super.c 2011-10-24 18:53:33.000000000 +0200
2670 @@ -394,7 +394,8 @@ enum {
2671         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2672         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2673         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2674 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2675 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2676 +       Opt_tag, Opt_notag, Opt_tagid
2677  };
2678  
2679  static const match_table_t tokens = {
2680 @@ -422,6 +423,9 @@ static const match_table_t tokens = {
2681         {Opt_acl, "acl"},
2682         {Opt_noacl, "noacl"},
2683         {Opt_xip, "xip"},
2684 +       {Opt_tag, "tag"},
2685 +       {Opt_notag, "notag"},
2686 +       {Opt_tagid, "tagid=%u"},
2687         {Opt_grpquota, "grpquota"},
2688         {Opt_ignore, "noquota"},
2689         {Opt_quota, "quota"},
2690 @@ -492,6 +496,20 @@ static int parse_options(char *options, 
2691                 case Opt_nouid32:
2692                         set_opt (sbi->s_mount_opt, NO_UID32);
2693                         break;
2694 +#ifndef CONFIG_TAGGING_NONE
2695 +               case Opt_tag:
2696 +                       set_opt (sbi->s_mount_opt, TAGGED);
2697 +                       break;
2698 +               case Opt_notag:
2699 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2700 +                       break;
2701 +#endif
2702 +#ifdef CONFIG_PROPAGATE
2703 +               case Opt_tagid:
2704 +                       /* use args[0] */
2705 +                       set_opt (sbi->s_mount_opt, TAGGED);
2706 +                       break;
2707 +#endif
2708                 case Opt_nocheck:
2709                         clear_opt (sbi->s_mount_opt, CHECK);
2710                         break;
2711 @@ -850,6 +868,8 @@ static int ext2_fill_super(struct super_
2712         if (!parse_options((char *) data, sb))
2713                 goto failed_mount;
2714  
2715 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2716 +               sb->s_flags |= MS_TAGGED;
2717         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2718                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2719                  MS_POSIXACL : 0);
2720 @@ -1224,6 +1244,14 @@ static int ext2_remount (struct super_bl
2721                 goto restore_opts;
2722         }
2723  
2724 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2725 +               !(sb->s_flags & MS_TAGGED)) {
2726 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2727 +                      sb->s_id);
2728 +               err = -EINVAL;
2729 +               goto restore_opts;
2730 +       }
2731 +
2732         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2733                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2734  
2735 diff -NurpP --minimal linux-3.1.1/fs/ext3/file.c linux-3.1.1-vs2.3.2/fs/ext3/file.c
2736 --- linux-3.1.1/fs/ext3/file.c  2011-10-24 18:45:27.000000000 +0200
2737 +++ linux-3.1.1-vs2.3.2/fs/ext3/file.c  2011-10-24 18:53:33.000000000 +0200
2738 @@ -80,5 +80,6 @@ const struct inode_operations ext3_file_
2739  #endif
2740         .get_acl        = ext3_get_acl,
2741         .fiemap         = ext3_fiemap,
2742 +       .sync_flags     = ext3_sync_flags,
2743  };
2744  
2745 diff -NurpP --minimal linux-3.1.1/fs/ext3/ialloc.c linux-3.1.1-vs2.3.2/fs/ext3/ialloc.c
2746 --- linux-3.1.1/fs/ext3/ialloc.c        2011-10-24 18:45:27.000000000 +0200
2747 +++ linux-3.1.1-vs2.3.2/fs/ext3/ialloc.c        2011-10-24 18:53:33.000000000 +0200
2748 @@ -23,6 +23,7 @@
2749  #include <linux/buffer_head.h>
2750  #include <linux/random.h>
2751  #include <linux/bitops.h>
2752 +#include <linux/vs_tag.h>
2753  #include <trace/events/ext3.h>
2754  
2755  #include <asm/byteorder.h>
2756 @@ -535,6 +536,7 @@ got:
2757                 inode->i_mode = mode;
2758                 inode->i_uid = current_fsuid();
2759                 inode->i_gid = dir->i_gid;
2760 +               inode->i_tag = dx_current_fstag(sb);
2761         } else
2762                 inode_init_owner(inode, dir, mode);
2763  
2764 diff -NurpP --minimal linux-3.1.1/fs/ext3/inode.c linux-3.1.1-vs2.3.2/fs/ext3/inode.c
2765 --- linux-3.1.1/fs/ext3/inode.c 2011-10-24 18:45:27.000000000 +0200
2766 +++ linux-3.1.1-vs2.3.2/fs/ext3/inode.c 2011-10-24 18:53:33.000000000 +0200
2767 @@ -38,6 +38,7 @@
2768  #include <linux/bio.h>
2769  #include <linux/fiemap.h>
2770  #include <linux/namei.h>
2771 +#include <linux/vs_tag.h>
2772  #include <trace/events/ext3.h>
2773  #include "xattr.h"
2774  #include "acl.h"
2775 @@ -2834,36 +2835,60 @@ void ext3_set_inode_flags(struct inode *
2776  {
2777         unsigned int flags = EXT3_I(inode)->i_flags;
2778  
2779 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2780 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2781 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2782 +
2783 +       if (flags & EXT3_IMMUTABLE_FL)
2784 +               inode->i_flags |= S_IMMUTABLE;
2785 +       if (flags & EXT3_IXUNLINK_FL)
2786 +               inode->i_flags |= S_IXUNLINK;
2787 +
2788         if (flags & EXT3_SYNC_FL)
2789                 inode->i_flags |= S_SYNC;
2790         if (flags & EXT3_APPEND_FL)
2791                 inode->i_flags |= S_APPEND;
2792 -       if (flags & EXT3_IMMUTABLE_FL)
2793 -               inode->i_flags |= S_IMMUTABLE;
2794         if (flags & EXT3_NOATIME_FL)
2795                 inode->i_flags |= S_NOATIME;
2796         if (flags & EXT3_DIRSYNC_FL)
2797                 inode->i_flags |= S_DIRSYNC;
2798 +
2799 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2800 +
2801 +       if (flags & EXT3_BARRIER_FL)
2802 +               inode->i_vflags |= V_BARRIER;
2803 +       if (flags & EXT3_COW_FL)
2804 +               inode->i_vflags |= V_COW;
2805  }
2806  
2807  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
2808  void ext3_get_inode_flags(struct ext3_inode_info *ei)
2809  {
2810         unsigned int flags = ei->vfs_inode.i_flags;
2811 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2812 +
2813 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
2814 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
2815 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
2816 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
2817 +
2818 +       if (flags & S_IMMUTABLE)
2819 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
2820 +       if (flags & S_IXUNLINK)
2821 +               ei->i_flags |= EXT3_IXUNLINK_FL;
2822  
2823 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
2824 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
2825         if (flags & S_SYNC)
2826                 ei->i_flags |= EXT3_SYNC_FL;
2827         if (flags & S_APPEND)
2828                 ei->i_flags |= EXT3_APPEND_FL;
2829 -       if (flags & S_IMMUTABLE)
2830 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
2831         if (flags & S_NOATIME)
2832                 ei->i_flags |= EXT3_NOATIME_FL;
2833         if (flags & S_DIRSYNC)
2834                 ei->i_flags |= EXT3_DIRSYNC_FL;
2835 +
2836 +       if (vflags & V_BARRIER)
2837 +               ei->i_flags |= EXT3_BARRIER_FL;
2838 +       if (vflags & V_COW)
2839 +               ei->i_flags |= EXT3_COW_FL;
2840  }
2841  
2842  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
2843 @@ -2877,6 +2902,8 @@ struct inode *ext3_iget(struct super_blo
2844         transaction_t *transaction;
2845         long ret;
2846         int block;
2847 +       uid_t uid;
2848 +       gid_t gid;
2849  
2850         inode = iget_locked(sb, ino);
2851         if (!inode)
2852 @@ -2893,12 +2920,17 @@ struct inode *ext3_iget(struct super_blo
2853         bh = iloc.bh;
2854         raw_inode = ext3_raw_inode(&iloc);
2855         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2856 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2857 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2858 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2859 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2860         if(!(test_opt (inode->i_sb, NO_UID32))) {
2861 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2862 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2863 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2864 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2865         }
2866 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2867 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2868 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2869 +               le16_to_cpu(raw_inode->i_raw_tag));
2870 +
2871         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
2872         inode->i_size = le32_to_cpu(raw_inode->i_size);
2873         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2874 @@ -3053,6 +3085,8 @@ static int ext3_do_update_inode(handle_t
2875         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
2876         struct ext3_inode_info *ei = EXT3_I(inode);
2877         struct buffer_head *bh = iloc->bh;
2878 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2879 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2880         int err = 0, rc, block;
2881  
2882  again:
2883 @@ -3067,29 +3101,32 @@ again:
2884         ext3_get_inode_flags(ei);
2885         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2886         if(!(test_opt(inode->i_sb, NO_UID32))) {
2887 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
2888 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
2889 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
2890 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
2891  /*
2892   * Fix up interoperability with old kernels. Otherwise, old inodes get
2893   * re-used with the upper 16 bits of the uid/gid intact
2894   */
2895                 if(!ei->i_dtime) {
2896                         raw_inode->i_uid_high =
2897 -                               cpu_to_le16(high_16_bits(inode->i_uid));
2898 +                               cpu_to_le16(high_16_bits(uid));
2899                         raw_inode->i_gid_high =
2900 -                               cpu_to_le16(high_16_bits(inode->i_gid));
2901 +                               cpu_to_le16(high_16_bits(gid));
2902                 } else {
2903                         raw_inode->i_uid_high = 0;
2904                         raw_inode->i_gid_high = 0;
2905                 }
2906         } else {
2907                 raw_inode->i_uid_low =
2908 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
2909 +                       cpu_to_le16(fs_high2lowuid(uid));
2910                 raw_inode->i_gid_low =
2911 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
2912 +                       cpu_to_le16(fs_high2lowgid(gid));
2913                 raw_inode->i_uid_high = 0;
2914                 raw_inode->i_gid_high = 0;
2915         }
2916 +#ifdef CONFIG_TAGGING_INTERN
2917 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2918 +#endif
2919         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2920         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
2921         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2922 @@ -3249,7 +3286,8 @@ int ext3_setattr(struct dentry *dentry, 
2923         if (is_quota_modification(inode, attr))
2924                 dquot_initialize(inode);
2925         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
2926 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
2927 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
2928 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
2929                 handle_t *handle;
2930  
2931                 /* (user+group)*(old+new) structure, inode write (sb,
2932 @@ -3271,6 +3309,8 @@ int ext3_setattr(struct dentry *dentry, 
2933                         inode->i_uid = attr->ia_uid;
2934                 if (attr->ia_valid & ATTR_GID)
2935                         inode->i_gid = attr->ia_gid;
2936 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2937 +                       inode->i_tag = attr->ia_tag;
2938                 error = ext3_mark_inode_dirty(handle, inode);
2939                 ext3_journal_stop(handle);
2940         }
2941 diff -NurpP --minimal linux-3.1.1/fs/ext3/ioctl.c linux-3.1.1-vs2.3.2/fs/ext3/ioctl.c
2942 --- linux-3.1.1/fs/ext3/ioctl.c 2011-10-24 18:45:27.000000000 +0200
2943 +++ linux-3.1.1-vs2.3.2/fs/ext3/ioctl.c 2011-10-24 18:53:33.000000000 +0200
2944 @@ -8,6 +8,7 @@
2945   */
2946  
2947  #include <linux/fs.h>
2948 +#include <linux/mount.h>
2949  #include <linux/jbd.h>
2950  #include <linux/capability.h>
2951  #include <linux/ext3_fs.h>
2952 @@ -17,6 +18,34 @@
2953  #include <linux/compat.h>
2954  #include <asm/uaccess.h>
2955  
2956 +
2957 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
2958 +{
2959 +       handle_t *handle = NULL;
2960 +       struct ext3_iloc iloc;
2961 +       int err;
2962 +
2963 +       handle = ext3_journal_start(inode, 1);
2964 +       if (IS_ERR(handle))
2965 +               return PTR_ERR(handle);
2966 +
2967 +       if (IS_SYNC(inode))
2968 +               handle->h_sync = 1;
2969 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
2970 +       if (err)
2971 +               goto flags_err;
2972 +
2973 +       inode->i_flags = flags;
2974 +       inode->i_vflags = vflags;
2975 +       ext3_get_inode_flags(EXT3_I(inode));
2976 +       inode->i_ctime = CURRENT_TIME_SEC;
2977 +
2978 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
2979 +flags_err:
2980 +       ext3_journal_stop(handle);
2981 +       return err;
2982 +}
2983 +
2984  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2985  {
2986         struct inode *inode = filp->f_dentry->d_inode;
2987 @@ -50,6 +79,11 @@ long ext3_ioctl(struct file *filp, unsig
2988  
2989                 flags = ext3_mask_flags(inode->i_mode, flags);
2990  
2991 +               if (IS_BARRIER(inode)) {
2992 +                       vxwprintk_task(1, "messing with the barrier.");
2993 +                       return -EACCES;
2994 +               }
2995 +
2996                 mutex_lock(&inode->i_mutex);
2997  
2998                 /* Is it quota file? Do not allow user to mess with it */
2999 @@ -68,7 +102,9 @@ long ext3_ioctl(struct file *filp, unsig
3000                  *
3001                  * This test looks nicer. Thanks to Pauline Middelink
3002                  */
3003 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
3004 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
3005 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
3006 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
3007                         if (!capable(CAP_LINUX_IMMUTABLE))
3008                                 goto flags_out;
3009                 }
3010 @@ -93,7 +129,7 @@ long ext3_ioctl(struct file *filp, unsig
3011                 if (err)
3012                         goto flags_err;
3013  
3014 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
3015 +               flags &= EXT3_FL_USER_MODIFIABLE;
3016                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
3017                 ei->i_flags = flags;
3018  
3019 diff -NurpP --minimal linux-3.1.1/fs/ext3/namei.c linux-3.1.1-vs2.3.2/fs/ext3/namei.c
3020 --- linux-3.1.1/fs/ext3/namei.c 2011-10-24 18:45:27.000000000 +0200
3021 +++ linux-3.1.1-vs2.3.2/fs/ext3/namei.c 2011-10-24 18:53:33.000000000 +0200
3022 @@ -36,6 +36,7 @@
3023  #include <linux/quotaops.h>
3024  #include <linux/buffer_head.h>
3025  #include <linux/bio.h>
3026 +#include <linux/vs_tag.h>
3027  #include <trace/events/ext3.h>
3028  
3029  #include "namei.h"
3030 @@ -925,6 +926,7 @@ restart:
3031                                         ll_rw_block(READ | REQ_META | REQ_PRIO,
3032                                                     1, &bh);
3033                         }
3034 +               dx_propagate_tag(nd, inode);
3035                 }
3036                 if ((bh = bh_use[ra_ptr++]) == NULL)
3037                         goto next;
3038 @@ -2535,6 +2537,7 @@ const struct inode_operations ext3_dir_i
3039         .listxattr      = ext3_listxattr,
3040         .removexattr    = generic_removexattr,
3041  #endif
3042 +       .sync_flags     = ext3_sync_flags,
3043         .get_acl        = ext3_get_acl,
3044  };
3045  
3046 diff -NurpP --minimal linux-3.1.1/fs/ext3/super.c linux-3.1.1-vs2.3.2/fs/ext3/super.c
3047 --- linux-3.1.1/fs/ext3/super.c 2011-10-24 18:45:27.000000000 +0200
3048 +++ linux-3.1.1-vs2.3.2/fs/ext3/super.c 2011-10-24 18:53:33.000000000 +0200
3049 @@ -833,7 +833,8 @@ enum {
3050         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
3051         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
3052         Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
3053 -       Opt_resize, Opt_usrquota, Opt_grpquota
3054 +       Opt_resize, Opt_usrquota, Opt_grpquota,
3055 +       Opt_tag, Opt_notag, Opt_tagid
3056  };
3057  
3058  static const match_table_t tokens = {
3059 @@ -890,6 +891,9 @@ static const match_table_t tokens = {
3060         {Opt_barrier, "barrier"},
3061         {Opt_nobarrier, "nobarrier"},
3062         {Opt_resize, "resize"},
3063 +       {Opt_tag, "tag"},
3064 +       {Opt_notag, "notag"},
3065 +       {Opt_tagid, "tagid=%u"},
3066         {Opt_err, NULL},
3067  };
3068  
3069 @@ -1042,6 +1046,20 @@ static int parse_options (char *options,
3070                 case Opt_nouid32:
3071                         set_opt (sbi->s_mount_opt, NO_UID32);
3072                         break;
3073 +#ifndef CONFIG_TAGGING_NONE
3074 +               case Opt_tag:
3075 +                       set_opt (sbi->s_mount_opt, TAGGED);
3076 +                       break;
3077 +               case Opt_notag:
3078 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3079 +                       break;
3080 +#endif
3081 +#ifdef CONFIG_PROPAGATE
3082 +               case Opt_tagid:
3083 +                       /* use args[0] */
3084 +                       set_opt (sbi->s_mount_opt, TAGGED);
3085 +                       break;
3086 +#endif
3087                 case Opt_nocheck:
3088                         clear_opt (sbi->s_mount_opt, CHECK);
3089                         break;
3090 @@ -1738,6 +1756,9 @@ static int ext3_fill_super (struct super
3091                             NULL, 0))
3092                 goto failed_mount;
3093  
3094 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
3095 +               sb->s_flags |= MS_TAGGED;
3096 +
3097         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3098                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3099  
3100 @@ -2619,6 +2640,14 @@ static int ext3_remount (struct super_bl
3101         if (test_opt(sb, ABORT))
3102                 ext3_abort(sb, __func__, "Abort forced by user");
3103  
3104 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
3105 +               !(sb->s_flags & MS_TAGGED)) {
3106 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
3107 +                       sb->s_id);
3108 +               err = -EINVAL;
3109 +               goto restore_opts;
3110 +       }
3111 +
3112         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3113                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3114  
3115 diff -NurpP --minimal linux-3.1.1/fs/ext4/ext4.h linux-3.1.1-vs2.3.2/fs/ext4/ext4.h
3116 --- linux-3.1.1/fs/ext4/ext4.h  2011-11-15 16:44:52.000000000 +0100
3117 +++ linux-3.1.1-vs2.3.2/fs/ext4/ext4.h  2011-11-15 17:08:44.000000000 +0100
3118 @@ -351,8 +351,12 @@ struct flex_groups {
3119  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
3120  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
3121  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
3122 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
3123  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
3124  
3125 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
3126 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
3127 +
3128  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
3129  #define EXT4_FL_USER_MODIFIABLE                0x004B80FF /* User modifiable flags */
3130  
3131 @@ -609,7 +613,8 @@ struct ext4_inode {
3132                         __le16  l_i_file_acl_high;
3133                         __le16  l_i_uid_high;   /* these 2 fields */
3134                         __le16  l_i_gid_high;   /* were reserved2[0] */
3135 -                       __u32   l_i_reserved2;
3136 +                       __le16  l_i_tag;        /* Context Tag */
3137 +                       __u16   l_i_reserved2;
3138                 } linux2;
3139                 struct {
3140                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
3141 @@ -727,6 +732,7 @@ do {                                                                               \
3142  #define i_gid_low      i_gid
3143  #define i_uid_high     osd2.linux2.l_i_uid_high
3144  #define i_gid_high     osd2.linux2.l_i_gid_high
3145 +#define i_raw_tag      osd2.linux2.l_i_tag
3146  #define i_reserved2    osd2.linux2.l_i_reserved2
3147  
3148  #elif defined(__GNU__)
3149 @@ -903,6 +909,7 @@ struct ext4_inode_info {
3150  #define EXT4_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
3151  #define EXT4_MOUNT_NO_AUTO_DA_ALLOC    0x10000 /* No auto delalloc mapping */
3152  #define EXT4_MOUNT_BARRIER             0x20000 /* Use block barriers */
3153 +#define EXT4_MOUNT_TAGGED              0x40000 /* Enable Context Tags */
3154  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
3155  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
3156  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
3157 @@ -2217,6 +2224,7 @@ extern int ext4_map_blocks(handle_t *han
3158                            struct ext4_map_blocks *map, int flags);
3159  extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
3160                         __u64 start, __u64 len);
3161 +extern int ext4_sync_flags(struct inode *, int, int);
3162  /* move_extent.c */
3163  extern int ext4_move_extents(struct file *o_filp, struct file *d_filp,
3164                              __u64 start_orig, __u64 start_donor,
3165 diff -NurpP --minimal linux-3.1.1/fs/ext4/file.c linux-3.1.1-vs2.3.2/fs/ext4/file.c
3166 --- linux-3.1.1/fs/ext4/file.c  2011-10-24 18:45:27.000000000 +0200
3167 +++ linux-3.1.1-vs2.3.2/fs/ext4/file.c  2011-10-24 18:53:33.000000000 +0200
3168 @@ -303,5 +303,6 @@ const struct inode_operations ext4_file_
3169  #endif
3170         .get_acl        = ext4_get_acl,
3171         .fiemap         = ext4_fiemap,
3172 +       .sync_flags     = ext4_sync_flags,
3173  };
3174  
3175 diff -NurpP --minimal linux-3.1.1/fs/ext4/ialloc.c linux-3.1.1-vs2.3.2/fs/ext4/ialloc.c
3176 --- linux-3.1.1/fs/ext4/ialloc.c        2011-10-24 18:45:27.000000000 +0200
3177 +++ linux-3.1.1-vs2.3.2/fs/ext4/ialloc.c        2011-10-24 18:53:33.000000000 +0200
3178 @@ -22,6 +22,7 @@
3179  #include <linux/random.h>
3180  #include <linux/bitops.h>
3181  #include <linux/blkdev.h>
3182 +#include <linux/vs_tag.h>
3183  #include <asm/byteorder.h>
3184  
3185  #include "ext4.h"
3186 @@ -992,6 +993,7 @@ got:
3187                 inode->i_mode = mode;
3188                 inode->i_uid = current_fsuid();
3189                 inode->i_gid = dir->i_gid;
3190 +               inode->i_tag = dx_current_fstag(sb);
3191         } else
3192                 inode_init_owner(inode, dir, mode);
3193  
3194 diff -NurpP --minimal linux-3.1.1/fs/ext4/inode.c linux-3.1.1-vs2.3.2/fs/ext4/inode.c
3195 --- linux-3.1.1/fs/ext4/inode.c 2011-11-15 16:44:52.000000000 +0100
3196 +++ linux-3.1.1-vs2.3.2/fs/ext4/inode.c 2011-11-15 17:08:44.000000000 +0100
3197 @@ -38,6 +38,7 @@
3198  #include <linux/printk.h>
3199  #include <linux/slab.h>
3200  #include <linux/ratelimit.h>
3201 +#include <linux/vs_tag.h>
3202  
3203  #include "ext4_jbd2.h"
3204  #include "xattr.h"
3205 @@ -3323,41 +3324,64 @@ void ext4_set_inode_flags(struct inode *
3206  {
3207         unsigned int flags = EXT4_I(inode)->i_flags;
3208  
3209 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3210 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3211 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3212 +
3213 +       if (flags & EXT4_IMMUTABLE_FL)
3214 +               inode->i_flags |= S_IMMUTABLE;
3215 +       if (flags & EXT4_IXUNLINK_FL)
3216 +               inode->i_flags |= S_IXUNLINK;
3217 +
3218         if (flags & EXT4_SYNC_FL)
3219                 inode->i_flags |= S_SYNC;
3220         if (flags & EXT4_APPEND_FL)
3221                 inode->i_flags |= S_APPEND;
3222 -       if (flags & EXT4_IMMUTABLE_FL)
3223 -               inode->i_flags |= S_IMMUTABLE;
3224         if (flags & EXT4_NOATIME_FL)
3225                 inode->i_flags |= S_NOATIME;
3226         if (flags & EXT4_DIRSYNC_FL)
3227                 inode->i_flags |= S_DIRSYNC;
3228 +
3229 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3230 +
3231 +       if (flags & EXT4_BARRIER_FL)
3232 +               inode->i_vflags |= V_BARRIER;
3233 +       if (flags & EXT4_COW_FL)
3234 +               inode->i_vflags |= V_COW;
3235  }
3236  
3237  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3238  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3239  {
3240 -       unsigned int vfs_fl;
3241 +       unsigned int vfs_fl, vfs_vf;
3242         unsigned long old_fl, new_fl;
3243  
3244         do {
3245                 vfs_fl = ei->vfs_inode.i_flags;
3246 +               vfs_vf = ei->vfs_inode.i_vflags;
3247                 old_fl = ei->i_flags;
3248                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3249                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
3250 -                               EXT4_DIRSYNC_FL);
3251 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
3252 +                               EXT4_COW_FL);
3253 +
3254 +               if (vfs_fl & S_IMMUTABLE)
3255 +                       new_fl |= EXT4_IMMUTABLE_FL;
3256 +               if (vfs_fl & S_IXUNLINK)
3257 +                       new_fl |= EXT4_IXUNLINK_FL;
3258 +
3259                 if (vfs_fl & S_SYNC)
3260                         new_fl |= EXT4_SYNC_FL;
3261                 if (vfs_fl & S_APPEND)
3262                         new_fl |= EXT4_APPEND_FL;
3263 -               if (vfs_fl & S_IMMUTABLE)
3264 -                       new_fl |= EXT4_IMMUTABLE_FL;
3265                 if (vfs_fl & S_NOATIME)
3266                         new_fl |= EXT4_NOATIME_FL;
3267                 if (vfs_fl & S_DIRSYNC)
3268                         new_fl |= EXT4_DIRSYNC_FL;
3269 +
3270 +               if (vfs_vf & V_BARRIER)
3271 +                       new_fl |= EXT4_BARRIER_FL;
3272 +               if (vfs_vf & V_COW)
3273 +                       new_fl |= EXT4_COW_FL;
3274         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3275  }
3276  
3277 @@ -3393,6 +3417,8 @@ struct inode *ext4_iget(struct super_blo
3278         journal_t *journal = EXT4_SB(sb)->s_journal;
3279         long ret;
3280         int block;
3281 +       uid_t uid;
3282 +       gid_t gid;
3283  
3284         inode = iget_locked(sb, ino);
3285         if (!inode)
3286 @@ -3408,12 +3434,16 @@ struct inode *ext4_iget(struct super_blo
3287                 goto bad_inode;
3288         raw_inode = ext4_raw_inode(&iloc);
3289         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3290 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3291 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3292 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3293 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3294         if (!(test_opt(inode->i_sb, NO_UID32))) {
3295 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3296 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3297 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3298 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3299         }
3300 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3301 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3302 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3303 +               le16_to_cpu(raw_inode->i_raw_tag));
3304         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3305  
3306         ext4_clear_state_flags(ei);     /* Only relevant on 32-bit archs */
3307 @@ -3632,6 +3662,8 @@ static int ext4_do_update_inode(handle_t
3308         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
3309         struct ext4_inode_info *ei = EXT4_I(inode);
3310         struct buffer_head *bh = iloc->bh;
3311 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3312 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3313         int err = 0, rc, block;
3314  
3315         /* For fields not not tracking in the in-memory inode,
3316 @@ -3642,29 +3674,32 @@ static int ext4_do_update_inode(handle_t
3317         ext4_get_inode_flags(ei);
3318         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3319         if (!(test_opt(inode->i_sb, NO_UID32))) {
3320 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3321 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3322 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3323 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3324  /*
3325   * Fix up interoperability with old kernels. Otherwise, old inodes get
3326   * re-used with the upper 16 bits of the uid/gid intact
3327   */
3328                 if (!ei->i_dtime) {
3329                         raw_inode->i_uid_high =
3330 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3331 +                               cpu_to_le16(high_16_bits(uid));
3332                         raw_inode->i_gid_high =
3333 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3334 +                               cpu_to_le16(high_16_bits(gid));
3335                 } else {
3336                         raw_inode->i_uid_high = 0;
3337                         raw_inode->i_gid_high = 0;
3338                 }
3339         } else {
3340                 raw_inode->i_uid_low =
3341 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3342 +                       cpu_to_le16(fs_high2lowuid(uid));
3343                 raw_inode->i_gid_low =
3344 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3345 +                       cpu_to_le16(fs_high2lowgid(gid));
3346                 raw_inode->i_uid_high = 0;
3347                 raw_inode->i_gid_high = 0;
3348         }
3349 +#ifdef CONFIG_TAGGING_INTERN
3350 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3351 +#endif
3352         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3353  
3354         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3355 @@ -3850,7 +3885,8 @@ int ext4_setattr(struct dentry *dentry, 
3356         if (is_quota_modification(inode, attr))
3357                 dquot_initialize(inode);
3358         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3359 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3360 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3361 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3362                 handle_t *handle;
3363  
3364                 /* (user+group)*(old+new) structure, inode write (sb,
3365 @@ -3872,6 +3908,8 @@ int ext4_setattr(struct dentry *dentry, 
3366                         inode->i_uid = attr->ia_uid;
3367                 if (attr->ia_valid & ATTR_GID)
3368                         inode->i_gid = attr->ia_gid;
3369 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3370 +                       inode->i_tag = attr->ia_tag;
3371                 error = ext4_mark_inode_dirty(handle, inode);
3372                 ext4_journal_stop(handle);
3373         }
3374 diff -NurpP --minimal linux-3.1.1/fs/ext4/ioctl.c linux-3.1.1-vs2.3.2/fs/ext4/ioctl.c
3375 --- linux-3.1.1/fs/ext4/ioctl.c 2011-10-24 18:45:27.000000000 +0200
3376 +++ linux-3.1.1-vs2.3.2/fs/ext4/ioctl.c 2011-10-24 18:53:33.000000000 +0200
3377 @@ -14,10 +14,39 @@
3378  #include <linux/compat.h>
3379  #include <linux/mount.h>
3380  #include <linux/file.h>
3381 +#include <linux/vs_tag.h>
3382  #include <asm/uaccess.h>
3383  #include "ext4_jbd2.h"
3384  #include "ext4.h"
3385  
3386 +
3387 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3388 +{
3389 +       handle_t *handle = NULL;
3390 +       struct ext4_iloc iloc;
3391 +       int err;
3392 +
3393 +       handle = ext4_journal_start(inode, 1);
3394 +       if (IS_ERR(handle))
3395 +               return PTR_ERR(handle);
3396 +
3397 +       if (IS_SYNC(inode))
3398 +               ext4_handle_sync(handle);
3399 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3400 +       if (err)
3401 +               goto flags_err;
3402 +
3403 +       inode->i_flags = flags;
3404 +       inode->i_vflags = vflags;
3405 +       ext4_get_inode_flags(EXT4_I(inode));
3406 +       inode->i_ctime = ext4_current_time(inode);
3407 +
3408 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3409 +flags_err:
3410 +       ext4_journal_stop(handle);
3411 +       return err;
3412 +}
3413 +
3414  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3415  {
3416         struct inode *inode = filp->f_dentry->d_inode;
3417 @@ -50,6 +79,11 @@ long ext4_ioctl(struct file *filp, unsig
3418  
3419                 flags = ext4_mask_flags(inode->i_mode, flags);
3420  
3421 +               if (IS_BARRIER(inode)) {
3422 +                       vxwprintk_task(1, "messing with the barrier.");
3423 +                       return -EACCES;
3424 +               }
3425 +
3426                 err = -EPERM;
3427                 mutex_lock(&inode->i_mutex);
3428                 /* Is it quota file? Do not allow user to mess with it */
3429 @@ -67,7 +101,9 @@ long ext4_ioctl(struct file *filp, unsig
3430                  *
3431                  * This test looks nicer. Thanks to Pauline Middelink
3432                  */
3433 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3434 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3435 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3436 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3437                         if (!capable(CAP_LINUX_IMMUTABLE))
3438                                 goto flags_out;
3439                 }
3440 diff -NurpP --minimal linux-3.1.1/fs/ext4/namei.c linux-3.1.1-vs2.3.2/fs/ext4/namei.c
3441 --- linux-3.1.1/fs/ext4/namei.c 2011-11-15 16:44:52.000000000 +0100
3442 +++ linux-3.1.1-vs2.3.2/fs/ext4/namei.c 2011-11-15 17:08:44.000000000 +0100
3443 @@ -34,6 +34,7 @@
3444  #include <linux/quotaops.h>
3445  #include <linux/buffer_head.h>
3446  #include <linux/bio.h>
3447 +#include <linux/vs_tag.h>
3448  #include "ext4.h"
3449  #include "ext4_jbd2.h"
3450  
3451 @@ -925,6 +926,7 @@ restart:
3452                                         ll_rw_block(READ | REQ_META | REQ_PRIO,
3453                                                     1, &bh);
3454                         }
3455 +               dx_propagate_tag(nd, inode);
3456                 }
3457                 if ((bh = bh_use[ra_ptr++]) == NULL)
3458                         goto next;
3459 @@ -2588,6 +2590,7 @@ const struct inode_operations ext4_dir_i
3460  #endif
3461         .get_acl        = ext4_get_acl,
3462         .fiemap         = ext4_fiemap,
3463 +       .sync_flags     = ext4_sync_flags,
3464  };
3465  
3466  const struct inode_operations ext4_special_inode_operations = {
3467 diff -NurpP --minimal linux-3.1.1/fs/ext4/super.c linux-3.1.1-vs2.3.2/fs/ext4/super.c
3468 --- linux-3.1.1/fs/ext4/super.c 2011-10-24 18:45:27.000000000 +0200
3469 +++ linux-3.1.1-vs2.3.2/fs/ext4/super.c 2011-10-24 18:53:33.000000000 +0200
3470 @@ -1320,6 +1320,7 @@ enum {
3471         Opt_dioread_nolock, Opt_dioread_lock,
3472         Opt_discard, Opt_nodiscard,
3473         Opt_init_inode_table, Opt_noinit_inode_table,
3474 +       Opt_tag, Opt_notag, Opt_tagid
3475  };
3476  
3477  static const match_table_t tokens = {
3478 @@ -1395,6 +1396,9 @@ static const match_table_t tokens = {
3479         {Opt_init_inode_table, "init_itable=%u"},
3480         {Opt_init_inode_table, "init_itable"},
3481         {Opt_noinit_inode_table, "noinit_itable"},
3482 +       {Opt_tag, "tag"},
3483 +       {Opt_notag, "notag"},
3484 +       {Opt_tagid, "tagid=%u"},
3485         {Opt_err, NULL},
3486  };
3487  
3488 @@ -1563,6 +1567,20 @@ static int parse_options(char *options, 
3489                 case Opt_nouid32:
3490                         set_opt(sb, NO_UID32);
3491                         break;
3492 +#ifndef CONFIG_TAGGING_NONE
3493 +               case Opt_tag:
3494 +                       set_opt(sb, TAGGED);
3495 +                       break;
3496 +               case Opt_notag:
3497 +                       clear_opt(sb, TAGGED);
3498 +                       break;
3499 +#endif
3500 +#ifdef CONFIG_PROPAGATE
3501 +               case Opt_tagid:
3502 +                       /* use args[0] */
3503 +                       set_opt(sb, TAGGED);
3504 +                       break;
3505 +#endif
3506                 case Opt_debug:
3507                         set_opt(sb, DEBUG);
3508                         break;
3509 @@ -3224,6 +3242,9 @@ static int ext4_fill_super(struct super_
3510                            &journal_ioprio, NULL, 0))
3511                 goto failed_mount;
3512  
3513 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3514 +               sb->s_flags |= MS_TAGGED;
3515 +
3516         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3517                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3518  
3519 @@ -4351,6 +4372,14 @@ static int ext4_remount(struct super_blo
3520         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3521                 ext4_abort(sb, "Abort forced by user");
3522  
3523 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3524 +               !(sb->s_flags & MS_TAGGED)) {
3525 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3526 +                       sb->s_id);
3527 +               err = -EINVAL;
3528 +               goto restore_opts;
3529 +       }
3530 +
3531         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3532                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3533  
3534 diff -NurpP --minimal linux-3.1.1/fs/fcntl.c linux-3.1.1-vs2.3.2/fs/fcntl.c
3535 --- linux-3.1.1/fs/fcntl.c      2011-05-22 16:17:52.000000000 +0200
3536 +++ linux-3.1.1-vs2.3.2/fs/fcntl.c      2011-10-24 18:53:33.000000000 +0200
3537 @@ -20,6 +20,7 @@
3538  #include <linux/signal.h>
3539  #include <linux/rcupdate.h>
3540  #include <linux/pid_namespace.h>
3541 +#include <linux/vs_limit.h>
3542  
3543  #include <asm/poll.h>
3544  #include <asm/siginfo.h>
3545 @@ -103,6 +104,8 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldf
3546  
3547         if (tofree)
3548                 filp_close(tofree, files);
3549 +       else
3550 +               vx_openfd_inc(newfd);   /* fd was unused */
3551  
3552         return newfd;
3553  
3554 @@ -447,6 +450,8 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd,
3555         filp = fget_raw(fd);
3556         if (!filp)
3557                 goto out;
3558 +       if (!vx_files_avail(1))
3559 +               goto out;
3560  
3561         if (unlikely(filp->f_mode & FMODE_PATH)) {
3562                 if (!check_fcntl_cmd(cmd)) {
3563 diff -NurpP --minimal linux-3.1.1/fs/file.c linux-3.1.1-vs2.3.2/fs/file.c
3564 --- linux-3.1.1/fs/file.c       2011-05-22 16:17:52.000000000 +0200
3565 +++ linux-3.1.1-vs2.3.2/fs/file.c       2011-10-24 18:53:33.000000000 +0200
3566 @@ -21,6 +21,7 @@
3567  #include <linux/spinlock.h>
3568  #include <linux/rcupdate.h>
3569  #include <linux/workqueue.h>
3570 +#include <linux/vs_limit.h>
3571  
3572  struct fdtable_defer {
3573         spinlock_t lock;
3574 @@ -359,6 +360,8 @@ struct files_struct *dup_fd(struct files
3575                 struct file *f = *old_fds++;
3576                 if (f) {
3577                         get_file(f);
3578 +                       /* TODO: sum it first for check and performance */
3579 +                       vx_openfd_inc(open_files - i);
3580                 } else {
3581                         /*
3582                          * The fd may be claimed in the fd bitmap but not yet
3583 @@ -466,6 +469,7 @@ repeat:
3584         else
3585                 FD_CLR(fd, fdt->close_on_exec);
3586         error = fd;
3587 +       vx_openfd_inc(fd);
3588  #if 1
3589         /* Sanity check */
3590         if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
3591 diff -NurpP --minimal linux-3.1.1/fs/file_table.c linux-3.1.1-vs2.3.2/fs/file_table.c
3592 --- linux-3.1.1/fs/file_table.c 2011-10-24 18:45:27.000000000 +0200
3593 +++ linux-3.1.1-vs2.3.2/fs/file_table.c 2011-10-24 18:53:33.000000000 +0200
3594 @@ -24,6 +24,8 @@
3595  #include <linux/percpu_counter.h>
3596  #include <linux/percpu.h>
3597  #include <linux/ima.h>
3598 +#include <linux/vs_limit.h>
3599 +#include <linux/vs_context.h>
3600  
3601  #include <linux/atomic.h>
3602  
3603 @@ -135,6 +137,8 @@ struct file *get_empty_filp(void)
3604         spin_lock_init(&f->f_lock);
3605         eventpoll_init_file(f);
3606         /* f->f_version: 0 */
3607 +       f->f_xid = vx_current_xid();
3608 +       vx_files_inc(f);
3609         return f;
3610  
3611  over:
3612 @@ -253,6 +257,8 @@ static void __fput(struct file *file)
3613         }
3614         fops_put(file->f_op);
3615         put_pid(file->f_owner.pid);
3616 +       vx_files_dec(file);
3617 +       file->f_xid = 0;
3618         file_sb_list_del(file);
3619         if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
3620                 i_readcount_dec(inode);
3621 @@ -383,6 +389,8 @@ void put_filp(struct file *file)
3622  {
3623         if (atomic_long_dec_and_test(&file->f_count)) {
3624                 security_file_free(file);
3625 +               vx_files_dec(file);
3626 +               file->f_xid = 0;
3627                 file_sb_list_del(file);
3628                 file_free(file);
3629         }
3630 diff -NurpP --minimal linux-3.1.1/fs/fs_struct.c linux-3.1.1-vs2.3.2/fs/fs_struct.c
3631 --- linux-3.1.1/fs/fs_struct.c  2011-03-15 18:07:31.000000000 +0100
3632 +++ linux-3.1.1-vs2.3.2/fs/fs_struct.c  2011-10-24 18:53:33.000000000 +0200
3633 @@ -4,6 +4,7 @@
3634  #include <linux/path.h>
3635  #include <linux/slab.h>
3636  #include <linux/fs_struct.h>
3637 +#include <linux/vserver/global.h>
3638  #include "internal.h"
3639  
3640  static inline void path_get_longterm(struct path *path)
3641 @@ -96,6 +97,7 @@ void free_fs_struct(struct fs_struct *fs
3642  {
3643         path_put_longterm(&fs->root);
3644         path_put_longterm(&fs->pwd);
3645 +       atomic_dec(&vs_global_fs);
3646         kmem_cache_free(fs_cachep, fs);
3647  }
3648  
3649 @@ -135,6 +137,7 @@ struct fs_struct *copy_fs_struct(struct 
3650                 fs->pwd = old->pwd;
3651                 path_get_longterm(&fs->pwd);
3652                 spin_unlock(&old->lock);
3653 +               atomic_inc(&vs_global_fs);
3654         }
3655         return fs;
3656  }
3657 diff -NurpP --minimal linux-3.1.1/fs/gfs2/file.c linux-3.1.1-vs2.3.2/fs/gfs2/file.c
3658 --- linux-3.1.1/fs/gfs2/file.c  2011-10-24 18:45:27.000000000 +0200
3659 +++ linux-3.1.1-vs2.3.2/fs/gfs2/file.c  2011-10-24 18:53:33.000000000 +0200
3660 @@ -134,6 +134,9 @@ static const u32 fsflags_to_gfs2[32] = {
3661         [7] = GFS2_DIF_NOATIME,
3662         [12] = GFS2_DIF_EXHASH,
3663         [14] = GFS2_DIF_INHERIT_JDATA,
3664 +       [27] = GFS2_DIF_IXUNLINK,
3665 +       [26] = GFS2_DIF_BARRIER,
3666 +       [29] = GFS2_DIF_COW,
3667  };
3668  
3669  static const u32 gfs2_to_fsflags[32] = {
3670 @@ -143,6 +146,9 @@ static const u32 gfs2_to_fsflags[32] = {
3671         [gfs2fl_NoAtime] = FS_NOATIME_FL,
3672         [gfs2fl_ExHash] = FS_INDEX_FL,
3673         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3674 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3675 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
3676 +       [gfs2fl_Cow] = FS_COW_FL,
3677  };
3678  
3679  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3680 @@ -173,12 +179,18 @@ void gfs2_set_inode_flags(struct inode *
3681  {
3682         struct gfs2_inode *ip = GFS2_I(inode);
3683         unsigned int flags = inode->i_flags;
3684 +       unsigned int vflags = inode->i_vflags;
3685 +
3686 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3687 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC | S_NOSEC);
3688  
3689 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_NOSEC);
3690         if ((ip->i_eattr == 0) && !is_sxid(inode->i_mode))
3691                 inode->i_flags |= S_NOSEC;
3692         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3693                 flags |= S_IMMUTABLE;
3694 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3695 +               flags |= S_IXUNLINK;
3696 +
3697         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3698                 flags |= S_APPEND;
3699         if (ip->i_diskflags & GFS2_DIF_NOATIME)
3700 @@ -186,6 +198,43 @@ void gfs2_set_inode_flags(struct inode *
3701         if (ip->i_diskflags & GFS2_DIF_SYNC)
3702                 flags |= S_SYNC;
3703         inode->i_flags = flags;
3704 +
3705 +       vflags &= ~(V_BARRIER | V_COW);
3706 +
3707 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
3708 +               vflags |= V_BARRIER;
3709 +       if (ip->i_diskflags & GFS2_DIF_COW)
3710 +               vflags |= V_COW;
3711 +       inode->i_vflags = vflags;
3712 +}
3713 +
3714 +void gfs2_get_inode_flags(struct inode *inode)
3715 +{
3716 +       struct gfs2_inode *ip = GFS2_I(inode);
3717 +       unsigned int flags = inode->i_flags;
3718 +       unsigned int vflags = inode->i_vflags;
3719 +
3720 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
3721 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
3722 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
3723 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
3724 +
3725 +       if (flags & S_IMMUTABLE)
3726 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
3727 +       if (flags & S_IXUNLINK)
3728 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
3729 +
3730 +       if (flags & S_APPEND)
3731 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
3732 +       if (flags & S_NOATIME)
3733 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
3734 +       if (flags & S_SYNC)
3735 +               ip->i_diskflags |= GFS2_DIF_SYNC;
3736 +
3737 +       if (vflags & V_BARRIER)
3738 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
3739 +       if (vflags & V_COW)
3740 +               ip->i_diskflags |= GFS2_DIF_COW;
3741  }
3742  
3743  /* Flags that can be set by user space */
3744 @@ -297,6 +346,37 @@ static int gfs2_set_flags(struct file *f
3745         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
3746  }
3747  
3748 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
3749 +{
3750 +       struct gfs2_inode *ip = GFS2_I(inode);
3751 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
3752 +       struct buffer_head *bh;
3753 +       struct gfs2_holder gh;
3754 +       int error;
3755 +
3756 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
3757 +       if (error)
3758 +               return error;
3759 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
3760 +       if (error)
3761 +               goto out;
3762 +       error = gfs2_meta_inode_buffer(ip, &bh);
3763 +       if (error)
3764 +               goto out_trans_end;
3765 +       gfs2_trans_add_bh(ip->i_gl, bh, 1);
3766 +       inode->i_flags = flags;
3767 +       inode->i_vflags = vflags;
3768 +       gfs2_get_inode_flags(inode);
3769 +       gfs2_dinode_out(ip, bh->b_data);
3770 +       brelse(bh);
3771 +       gfs2_set_aops(inode);
3772 +out_trans_end:
3773 +       gfs2_trans_end(sdp);
3774 +out:
3775 +       gfs2_glock_dq_uninit(&gh);
3776 +       return error;
3777 +}
3778 +
3779  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3780  {
3781         switch(cmd) {
3782 diff -NurpP --minimal linux-3.1.1/fs/gfs2/inode.h linux-3.1.1-vs2.3.2/fs/gfs2/inode.h
3783 --- linux-3.1.1/fs/gfs2/inode.h 2011-10-24 18:45:27.000000000 +0200
3784 +++ linux-3.1.1-vs2.3.2/fs/gfs2/inode.h 2011-10-24 18:53:33.000000000 +0200
3785 @@ -120,6 +120,7 @@ extern const struct file_operations gfs2
3786  extern const struct file_operations gfs2_dir_fops_nolock;
3787  
3788  extern void gfs2_set_inode_flags(struct inode *inode);
3789 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
3790   
3791  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
3792  extern const struct file_operations gfs2_file_fops;
3793 diff -NurpP --minimal linux-3.1.1/fs/inode.c linux-3.1.1-vs2.3.2/fs/inode.c
3794 --- linux-3.1.1/fs/inode.c      2011-10-24 18:45:27.000000000 +0200
3795 +++ linux-3.1.1-vs2.3.2/fs/inode.c      2011-10-24 18:53:33.000000000 +0200
3796 @@ -26,6 +26,7 @@
3797  #include <linux/ima.h>
3798  #include <linux/cred.h>
3799  #include <linux/buffer_head.h> /* for inode_has_buffers */
3800 +#include <linux/vs_tag.h>
3801  #include "internal.h"
3802  
3803  /*
3804 @@ -137,6 +138,9 @@ int inode_init_always(struct super_block
3805         struct address_space *const mapping = &inode->i_data;
3806  
3807         inode->i_sb = sb;
3808 +
3809 +       /* essential because of inode slab reuse */
3810 +       inode->i_tag = 0;
3811         inode->i_blkbits = sb->s_blocksize_bits;
3812         inode->i_flags = 0;
3813         atomic_set(&inode->i_count, 1);
3814 @@ -158,6 +162,7 @@ int inode_init_always(struct super_block
3815         inode->i_bdev = NULL;
3816         inode->i_cdev = NULL;
3817         inode->i_rdev = 0;
3818 +       inode->i_mdev = 0;
3819         inode->dirtied_when = 0;
3820  
3821         if (security_inode_alloc(inode))
3822 @@ -399,6 +404,8 @@ void __insert_inode_hash(struct inode *i
3823  }
3824  EXPORT_SYMBOL(__insert_inode_hash);
3825  
3826 +EXPORT_SYMBOL_GPL(__iget);
3827 +
3828  /**
3829   *     __remove_inode_hash - remove an inode from the hash
3830   *     @inode: inode to unhash
3831 @@ -1626,9 +1633,11 @@ void init_special_inode(struct inode *in
3832         if (S_ISCHR(mode)) {
3833                 inode->i_fop = &def_chr_fops;
3834                 inode->i_rdev = rdev;
3835 +               inode->i_mdev = rdev;
3836         } else if (S_ISBLK(mode)) {
3837                 inode->i_fop = &def_blk_fops;
3838                 inode->i_rdev = rdev;
3839 +               inode->i_mdev = rdev;
3840         } else if (S_ISFIFO(mode))
3841                 inode->i_fop = &def_fifo_fops;
3842         else if (S_ISSOCK(mode))
3843 @@ -1657,6 +1666,7 @@ void inode_init_owner(struct inode *inod
3844         } else
3845                 inode->i_gid = current_fsgid();
3846         inode->i_mode = mode;
3847 +       inode->i_tag = dx_current_fstag(inode->i_sb);
3848  }
3849  EXPORT_SYMBOL(inode_init_owner);
3850  
3851 diff -NurpP --minimal linux-3.1.1/fs/ioctl.c linux-3.1.1-vs2.3.2/fs/ioctl.c
3852 --- linux-3.1.1/fs/ioctl.c      2011-05-22 16:17:52.000000000 +0200
3853 +++ linux-3.1.1-vs2.3.2/fs/ioctl.c      2011-10-24 18:53:33.000000000 +0200
3854 @@ -15,6 +15,9 @@
3855  #include <linux/writeback.h>
3856  #include <linux/buffer_head.h>
3857  #include <linux/falloc.h>
3858 +#include <linux/proc_fs.h>
3859 +#include <linux/vserver/inode.h>
3860 +#include <linux/vs_tag.h>
3861  
3862  #include <asm/ioctls.h>
3863  
3864 diff -NurpP --minimal linux-3.1.1/fs/ioprio.c linux-3.1.1-vs2.3.2/fs/ioprio.c
3865 --- linux-3.1.1/fs/ioprio.c     2011-01-05 21:50:24.000000000 +0100
3866 +++ linux-3.1.1-vs2.3.2/fs/ioprio.c     2011-10-24 18:53:33.000000000 +0200
3867 @@ -27,6 +27,7 @@
3868  #include <linux/syscalls.h>
3869  #include <linux/security.h>
3870  #include <linux/pid_namespace.h>
3871 +#include <linux/vs_base.h>
3872  
3873  int set_task_ioprio(struct task_struct *task, int ioprio)
3874  {
3875 @@ -119,6 +120,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which, 
3876                         else
3877                                 pgrp = find_vpid(who);
3878                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3879 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3880 +                                       continue;
3881                                 ret = set_task_ioprio(p, ioprio);
3882                                 if (ret)
3883                                         break;
3884 @@ -208,6 +211,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which, 
3885                         else
3886                                 pgrp = find_vpid(who);
3887                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3888 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3889 +                                       continue;
3890                                 tmpio = get_task_ioprio(p);
3891                                 if (tmpio < 0)
3892                                         continue;
3893 diff -NurpP --minimal linux-3.1.1/fs/jfs/file.c linux-3.1.1-vs2.3.2/fs/jfs/file.c
3894 --- linux-3.1.1/fs/jfs/file.c   2011-10-24 18:45:27.000000000 +0200
3895 +++ linux-3.1.1-vs2.3.2/fs/jfs/file.c   2011-10-24 18:53:33.000000000 +0200
3896 @@ -109,7 +109,8 @@ int jfs_setattr(struct dentry *dentry, s
3897         if (is_quota_modification(inode, iattr))
3898                 dquot_initialize(inode);
3899         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
3900 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
3901 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
3902 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
3903                 rc = dquot_transfer(inode, iattr);
3904                 if (rc)
3905                         return rc;
3906 @@ -142,6 +143,7 @@ const struct inode_operations jfs_file_i
3907  #ifdef CONFIG_JFS_POSIX_ACL
3908         .get_acl        = jfs_get_acl,
3909  #endif
3910 +       .sync_flags     = jfs_sync_flags,
3911  };
3912  
3913  const struct file_operations jfs_file_operations = {
3914 diff -NurpP --minimal linux-3.1.1/fs/jfs/ioctl.c linux-3.1.1-vs2.3.2/fs/jfs/ioctl.c
3915 --- linux-3.1.1/fs/jfs/ioctl.c  2011-05-22 16:17:52.000000000 +0200
3916 +++ linux-3.1.1-vs2.3.2/fs/jfs/ioctl.c  2011-10-24 18:53:33.000000000 +0200
3917 @@ -11,6 +11,7 @@
3918  #include <linux/mount.h>
3919  #include <linux/time.h>
3920  #include <linux/sched.h>
3921 +#include <linux/mount.h>
3922  #include <asm/current.h>
3923  #include <asm/uaccess.h>
3924  
3925 @@ -52,6 +53,16 @@ static long jfs_map_ext2(unsigned long f
3926  }
3927  
3928  
3929 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
3930 +{
3931 +       inode->i_flags = flags;
3932 +       inode->i_vflags = vflags;
3933 +       jfs_get_inode_flags(JFS_IP(inode));
3934 +       inode->i_ctime = CURRENT_TIME_SEC;
3935 +       mark_inode_dirty(inode);
3936 +       return 0;
3937 +}
3938 +
3939  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3940  {
3941         struct inode *inode = filp->f_dentry->d_inode;
3942 @@ -85,6 +96,11 @@ long jfs_ioctl(struct file *filp, unsign
3943                 if (!S_ISDIR(inode->i_mode))
3944                         flags &= ~JFS_DIRSYNC_FL;
3945  
3946 +               if (IS_BARRIER(inode)) {
3947 +                       vxwprintk_task(1, "messing with the barrier.");
3948 +                       return -EACCES;
3949 +               }
3950 +
3951                 /* Is it quota file? Do not allow user to mess with it */
3952                 if (IS_NOQUOTA(inode)) {
3953                         err = -EPERM;
3954 @@ -102,8 +118,8 @@ long jfs_ioctl(struct file *filp, unsign
3955                  * the relevant capability.
3956                  */
3957                 if ((oldflags & JFS_IMMUTABLE_FL) ||
3958 -                       ((flags ^ oldflags) &
3959 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3960 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
3961 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3962                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3963                                 mutex_unlock(&inode->i_mutex);
3964                                 err = -EPERM;
3965 @@ -111,7 +127,7 @@ long jfs_ioctl(struct file *filp, unsign
3966                         }
3967                 }
3968  
3969 -               flags = flags & JFS_FL_USER_MODIFIABLE;
3970 +               flags &= JFS_FL_USER_MODIFIABLE;
3971                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
3972                 jfs_inode->mode2 = flags;
3973  
3974 diff -NurpP --minimal linux-3.1.1/fs/jfs/jfs_dinode.h linux-3.1.1-vs2.3.2/fs/jfs/jfs_dinode.h
3975 --- linux-3.1.1/fs/jfs/jfs_dinode.h     2008-12-25 00:26:37.000000000 +0100
3976 +++ linux-3.1.1-vs2.3.2/fs/jfs/jfs_dinode.h     2011-10-24 18:53:33.000000000 +0200
3977 @@ -161,9 +161,13 @@ struct dinode {
3978  
3979  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
3980  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
3981 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
3982  
3983 -#define JFS_FL_USER_VISIBLE    0x03F80000
3984 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
3985 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
3986 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
3987 +
3988 +#define JFS_FL_USER_VISIBLE    0x07F80000
3989 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
3990  #define JFS_FL_INHERIT         0x03C80000
3991  
3992  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3993 diff -NurpP --minimal linux-3.1.1/fs/jfs/jfs_filsys.h linux-3.1.1-vs2.3.2/fs/jfs/jfs_filsys.h
3994 --- linux-3.1.1/fs/jfs/jfs_filsys.h     2008-12-25 00:26:37.000000000 +0100
3995 +++ linux-3.1.1-vs2.3.2/fs/jfs/jfs_filsys.h     2011-10-24 18:53:33.000000000 +0200
3996 @@ -263,6 +263,7 @@
3997  #define JFS_NAME_MAX   255
3998  #define JFS_PATH_MAX   BPSIZE
3999  
4000 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
4001  
4002  /*
4003   *     file system state (superblock state)
4004 diff -NurpP --minimal linux-3.1.1/fs/jfs/jfs_imap.c linux-3.1.1-vs2.3.2/fs/jfs/jfs_imap.c
4005 --- linux-3.1.1/fs/jfs/jfs_imap.c       2011-07-22 11:18:05.000000000 +0200
4006 +++ linux-3.1.1-vs2.3.2/fs/jfs/jfs_imap.c       2011-10-24 18:53:33.000000000 +0200
4007 @@ -46,6 +46,7 @@
4008  #include <linux/pagemap.h>
4009  #include <linux/quotaops.h>
4010  #include <linux/slab.h>
4011 +#include <linux/vs_tag.h>
4012  
4013  #include "jfs_incore.h"
4014  #include "jfs_inode.h"
4015 @@ -3058,6 +3059,8 @@ static int copy_from_dinode(struct dinod
4016  {
4017         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
4018         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
4019 +       uid_t uid;
4020 +       gid_t gid;
4021  
4022         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
4023         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
4024 @@ -3078,14 +3081,18 @@ static int copy_from_dinode(struct dinod
4025         }
4026         ip->i_nlink = le32_to_cpu(dip->di_nlink);
4027  
4028 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
4029 +       uid = le32_to_cpu(dip->di_uid);
4030 +       gid = le32_to_cpu(dip->di_gid);
4031 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
4032 +
4033 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
4034         if (sbi->uid == -1)
4035                 ip->i_uid = jfs_ip->saved_uid;
4036         else {
4037                 ip->i_uid = sbi->uid;
4038         }
4039  
4040 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
4041 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
4042         if (sbi->gid == -1)
4043                 ip->i_gid = jfs_ip->saved_gid;
4044         else {
4045 @@ -3150,14 +3157,12 @@ static void copy_to_dinode(struct dinode
4046         dip->di_size = cpu_to_le64(ip->i_size);
4047         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
4048         dip->di_nlink = cpu_to_le32(ip->i_nlink);
4049 -       if (sbi->uid == -1)
4050 -               dip->di_uid = cpu_to_le32(ip->i_uid);
4051 -       else
4052 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
4053 -       if (sbi->gid == -1)
4054 -               dip->di_gid = cpu_to_le32(ip->i_gid);
4055 -       else
4056 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
4057 +
4058 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
4059 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
4060 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
4061 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
4062 +
4063         jfs_get_inode_flags(jfs_ip);
4064         /*
4065          * mode2 is only needed for storing the higher order bits.
4066 diff -NurpP --minimal linux-3.1.1/fs/jfs/jfs_inode.c linux-3.1.1-vs2.3.2/fs/jfs/jfs_inode.c
4067 --- linux-3.1.1/fs/jfs/jfs_inode.c      2010-08-02 16:52:49.000000000 +0200
4068 +++ linux-3.1.1-vs2.3.2/fs/jfs/jfs_inode.c      2011-10-24 18:53:33.000000000 +0200
4069 @@ -18,6 +18,7 @@
4070  
4071  #include <linux/fs.h>
4072  #include <linux/quotaops.h>
4073 +#include <linux/vs_tag.h>
4074  #include "jfs_incore.h"
4075  #include "jfs_inode.h"
4076  #include "jfs_filsys.h"
4077 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
4078  {
4079         unsigned int flags = JFS_IP(inode)->mode2;
4080  
4081 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
4082 -               S_NOATIME | S_DIRSYNC | S_SYNC);
4083 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4084 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4085  
4086         if (flags & JFS_IMMUTABLE_FL)
4087                 inode->i_flags |= S_IMMUTABLE;
4088 +       if (flags & JFS_IXUNLINK_FL)
4089 +               inode->i_flags |= S_IXUNLINK;
4090 +
4091 +       if (flags & JFS_SYNC_FL)
4092 +               inode->i_flags |= S_SYNC;
4093         if (flags & JFS_APPEND_FL)
4094                 inode->i_flags |= S_APPEND;
4095         if (flags & JFS_NOATIME_FL)
4096                 inode->i_flags |= S_NOATIME;
4097         if (flags & JFS_DIRSYNC_FL)
4098                 inode->i_flags |= S_DIRSYNC;
4099 -       if (flags & JFS_SYNC_FL)
4100 -               inode->i_flags |= S_SYNC;
4101 +
4102 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
4103 +
4104 +       if (flags & JFS_BARRIER_FL)
4105 +               inode->i_vflags |= V_BARRIER;
4106 +       if (flags & JFS_COW_FL)
4107 +               inode->i_vflags |= V_COW;
4108  }
4109  
4110  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
4111  {
4112         unsigned int flags = jfs_ip->vfs_inode.i_flags;
4113 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
4114 +
4115 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
4116 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
4117 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
4118 +                          JFS_BARRIER_FL | JFS_COW_FL);
4119  
4120 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
4121 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
4122         if (flags & S_IMMUTABLE)
4123                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
4124 +       if (flags & S_IXUNLINK)
4125 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
4126 +
4127         if (flags & S_APPEND)
4128                 jfs_ip->mode2 |= JFS_APPEND_FL;
4129         if (flags & S_NOATIME)
4130 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
4131                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
4132         if (flags & S_SYNC)
4133                 jfs_ip->mode2 |= JFS_SYNC_FL;
4134 +
4135 +       if (vflags & V_BARRIER)
4136 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
4137 +       if (vflags & V_COW)
4138 +               jfs_ip->mode2 |= JFS_COW_FL;
4139  }
4140  
4141  /*
4142 diff -NurpP --minimal linux-3.1.1/fs/jfs/jfs_inode.h linux-3.1.1-vs2.3.2/fs/jfs/jfs_inode.h
4143 --- linux-3.1.1/fs/jfs/jfs_inode.h      2011-10-24 18:45:27.000000000 +0200
4144 +++ linux-3.1.1-vs2.3.2/fs/jfs/jfs_inode.h      2011-10-24 18:53:33.000000000 +0200
4145 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
4146  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
4147         int fh_len, int fh_type);
4148  extern void jfs_set_inode_flags(struct inode *);
4149 +extern int jfs_sync_flags(struct inode *, int, int);
4150  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
4151  extern int jfs_setattr(struct dentry *, struct iattr *);
4152  
4153 diff -NurpP --minimal linux-3.1.1/fs/jfs/namei.c linux-3.1.1-vs2.3.2/fs/jfs/namei.c
4154 --- linux-3.1.1/fs/jfs/namei.c  2011-10-24 18:45:27.000000000 +0200
4155 +++ linux-3.1.1-vs2.3.2/fs/jfs/namei.c  2011-10-24 18:53:33.000000000 +0200
4156 @@ -22,6 +22,7 @@
4157  #include <linux/ctype.h>
4158  #include <linux/quotaops.h>
4159  #include <linux/exportfs.h>
4160 +#include <linux/vs_tag.h>
4161  #include "jfs_incore.h"
4162  #include "jfs_superblock.h"
4163  #include "jfs_inode.h"
4164 @@ -1474,6 +1475,7 @@ static struct dentry *jfs_lookup(struct 
4165                         jfs_err("jfs_lookup: iget failed on inum %d", (uint)inum);
4166         }
4167  
4168 +       dx_propagate_tag(nd, ip);
4169         return d_splice_alias(ip, dentry);
4170  }
4171  
4172 @@ -1538,6 +1540,7 @@ const struct inode_operations jfs_dir_in
4173  #ifdef CONFIG_JFS_POSIX_ACL
4174         .get_acl        = jfs_get_acl,
4175  #endif
4176 +       .sync_flags     = jfs_sync_flags,
4177  };
4178  
4179  const struct file_operations jfs_dir_operations = {
4180 diff -NurpP --minimal linux-3.1.1/fs/jfs/super.c linux-3.1.1-vs2.3.2/fs/jfs/super.c
4181 --- linux-3.1.1/fs/jfs/super.c  2011-05-22 16:17:53.000000000 +0200
4182 +++ linux-3.1.1-vs2.3.2/fs/jfs/super.c  2011-10-24 18:53:33.000000000 +0200
4183 @@ -198,7 +198,8 @@ static void jfs_put_super(struct super_b
4184  enum {
4185         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4186         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4187 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
4188 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4189 +       Opt_tag, Opt_notag, Opt_tagid
4190  };
4191  
4192  static const match_table_t tokens = {
4193 @@ -208,6 +209,10 @@ static const match_table_t tokens = {
4194         {Opt_resize, "resize=%u"},
4195         {Opt_resize_nosize, "resize"},
4196         {Opt_errors, "errors=%s"},
4197 +       {Opt_tag, "tag"},
4198 +       {Opt_notag, "notag"},
4199 +       {Opt_tagid, "tagid=%u"},
4200 +       {Opt_tag, "tagxid"},
4201         {Opt_ignore, "noquota"},
4202         {Opt_ignore, "quota"},
4203         {Opt_usrquota, "usrquota"},
4204 @@ -342,6 +347,20 @@ static int parse_options(char *options, 
4205                         }
4206                         break;
4207                 }
4208 +#ifndef CONFIG_TAGGING_NONE
4209 +               case Opt_tag:
4210 +                       *flag |= JFS_TAGGED;
4211 +                       break;
4212 +               case Opt_notag:
4213 +                       *flag &= JFS_TAGGED;
4214 +                       break;
4215 +#endif
4216 +#ifdef CONFIG_PROPAGATE
4217 +               case Opt_tagid:
4218 +                       /* use args[0] */
4219 +                       *flag |= JFS_TAGGED;
4220 +                       break;
4221 +#endif
4222                 default:
4223                         printk("jfs: Unrecognized mount option \"%s\" "
4224                                         " or missing value\n", p);
4225 @@ -373,6 +392,12 @@ static int jfs_remount(struct super_bloc
4226                 return -EINVAL;
4227         }
4228  
4229 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4230 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4231 +                       sb->s_id);
4232 +               return -EINVAL;
4233 +       }
4234 +
4235         if (newLVSize) {
4236                 if (sb->s_flags & MS_RDONLY) {
4237                         printk(KERN_ERR
4238 @@ -455,6 +480,9 @@ static int jfs_fill_super(struct super_b
4239  #ifdef CONFIG_JFS_POSIX_ACL
4240         sb->s_flags |= MS_POSIXACL;
4241  #endif
4242 +       /* map mount option tagxid */
4243 +       if (sbi->flag & JFS_TAGGED)
4244 +               sb->s_flags |= MS_TAGGED;
4245  
4246         if (newLVSize) {
4247                 printk(KERN_ERR "resize option for remount only\n");
4248 diff -NurpP --minimal linux-3.1.1/fs/libfs.c linux-3.1.1-vs2.3.2/fs/libfs.c
4249 --- linux-3.1.1/fs/libfs.c      2011-10-24 18:45:27.000000000 +0200
4250 +++ linux-3.1.1-vs2.3.2/fs/libfs.c      2011-10-24 18:53:33.000000000 +0200
4251 @@ -135,7 +135,8 @@ static inline unsigned char dt_type(stru
4252   * both impossible due to the lock on directory.
4253   */
4254  
4255 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4256 +static inline int do_dcache_readdir_filter(struct file *filp,
4257 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4258  {
4259         struct dentry *dentry = filp->f_path.dentry;
4260         struct dentry *cursor = filp->private_data;
4261 @@ -166,6 +167,8 @@ int dcache_readdir(struct file * filp, v
4262                         for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
4263                                 struct dentry *next;
4264                                 next = list_entry(p, struct dentry, d_u.d_child);
4265 +                               if (filter && !filter(next))
4266 +                                       continue;
4267                                 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
4268                                 if (!simple_positive(next)) {
4269                                         spin_unlock(&next->d_lock);
4270 @@ -192,6 +195,17 @@ int dcache_readdir(struct file * filp, v
4271         return 0;
4272  }
4273  
4274 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4275 +{
4276 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4277 +}
4278 +
4279 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4280 +       int (*filter)(struct dentry *))
4281 +{
4282 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4283 +}
4284 +
4285  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4286  {
4287         return -EISDIR;
4288 @@ -975,6 +989,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4289  EXPORT_SYMBOL(dcache_dir_lseek);
4290  EXPORT_SYMBOL(dcache_dir_open);
4291  EXPORT_SYMBOL(dcache_readdir);
4292 +EXPORT_SYMBOL(dcache_readdir_filter);
4293  EXPORT_SYMBOL(generic_read_dir);
4294  EXPORT_SYMBOL(mount_pseudo);
4295  EXPORT_SYMBOL(simple_write_begin);
4296 diff -NurpP --minimal linux-3.1.1/fs/locks.c linux-3.1.1-vs2.3.2/fs/locks.c
4297 --- linux-3.1.1/fs/locks.c      2011-10-24 18:45:27.000000000 +0200
4298 +++ linux-3.1.1-vs2.3.2/fs/locks.c      2011-10-24 18:53:33.000000000 +0200
4299 @@ -126,6 +126,8 @@
4300  #include <linux/time.h>
4301  #include <linux/rcupdate.h>
4302  #include <linux/pid_namespace.h>
4303 +#include <linux/vs_base.h>
4304 +#include <linux/vs_limit.h>
4305  
4306  #include <asm/uaccess.h>
4307  
4308 @@ -170,11 +172,17 @@ static void locks_init_lock_heads(struct
4309  /* Allocate an empty lock structure. */
4310  struct file_lock *locks_alloc_lock(void)
4311  {
4312 -       struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4313 +       struct file_lock *fl;
4314  
4315 -       if (fl)
4316 -               locks_init_lock_heads(fl);
4317 +       if (!vx_locks_avail(1))
4318 +               return NULL;
4319  
4320 +       fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4321 +
4322 +       if (fl) {
4323 +               locks_init_lock_heads(fl);
4324 +               fl->fl_xid = -1;
4325 +       }
4326         return fl;
4327  }
4328  EXPORT_SYMBOL_GPL(locks_alloc_lock);
4329 @@ -202,6 +210,7 @@ void locks_free_lock(struct file_lock *f
4330         BUG_ON(!list_empty(&fl->fl_block));
4331         BUG_ON(!list_empty(&fl->fl_link));
4332  
4333 +       vx_locks_dec(fl);
4334         locks_release_private(fl);
4335         kmem_cache_free(filelock_cache, fl);
4336  }
4337 @@ -211,6 +220,7 @@ void locks_init_lock(struct file_lock *f
4338  {
4339         memset(fl, 0, sizeof(struct file_lock));
4340         locks_init_lock_heads(fl);
4341 +       fl->fl_xid = -1;
4342  }
4343  
4344  EXPORT_SYMBOL(locks_init_lock);
4345 @@ -251,6 +261,7 @@ void locks_copy_lock(struct file_lock *n
4346         new->fl_file = fl->fl_file;
4347         new->fl_ops = fl->fl_ops;
4348         new->fl_lmops = fl->fl_lmops;
4349 +       new->fl_xid = fl->fl_xid;
4350  
4351         locks_copy_private(new, fl);
4352  }
4353 @@ -289,6 +300,11 @@ static int flock_make_lock(struct file *
4354         fl->fl_flags = FL_FLOCK;
4355         fl->fl_type = type;
4356         fl->fl_end = OFFSET_MAX;
4357 +
4358 +       vxd_assert(filp->f_xid == vx_current_xid(),
4359 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4360 +       fl->fl_xid = filp->f_xid;
4361 +       vx_locks_inc(fl);
4362         
4363         *lock = fl;
4364         return 0;
4365 @@ -438,6 +454,7 @@ static int lease_init(struct file *filp,
4366  
4367         fl->fl_owner = current->files;
4368         fl->fl_pid = current->tgid;
4369 +       fl->fl_xid = vx_current_xid();
4370  
4371         fl->fl_file = filp;
4372         fl->fl_flags = FL_LEASE;
4373 @@ -457,6 +474,11 @@ static struct file_lock *lease_alloc(str
4374         if (fl == NULL)
4375                 return ERR_PTR(error);
4376  
4377 +       fl->fl_xid = vx_current_xid();
4378 +       if (filp)
4379 +               vxd_assert(filp->f_xid == fl->fl_xid,
4380 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4381 +       vx_locks_inc(fl);
4382         error = lease_init(filp, type, fl);
4383         if (error) {
4384                 locks_free_lock(fl);
4385 @@ -758,6 +780,7 @@ static int flock_lock_file(struct file *
4386                 lock_flocks();
4387         }
4388  
4389 +       new_fl->fl_xid = -1;
4390  find_conflict:
4391         for_each_lock(inode, before) {
4392                 struct file_lock *fl = *before;
4393 @@ -778,6 +801,7 @@ find_conflict:
4394                 goto out;
4395         locks_copy_lock(new_fl, request);
4396         locks_insert_lock(before, new_fl);
4397 +       vx_locks_inc(new_fl);
4398         new_fl = NULL;
4399         error = 0;
4400  
4401 @@ -788,7 +812,8 @@ out:
4402         return error;
4403  }
4404  
4405 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4406 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4407 +       struct file_lock *conflock, xid_t xid)
4408  {
4409         struct file_lock *fl;
4410         struct file_lock *new_fl = NULL;
4411 @@ -798,6 +823,8 @@ static int __posix_lock_file(struct inod
4412         struct file_lock **before;
4413         int error, added = 0;
4414  
4415 +       vxd_assert(xid == vx_current_xid(),
4416 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4417         /*
4418          * We may need two file_lock structures for this operation,
4419          * so we get them in advance to avoid races.
4420 @@ -808,7 +835,11 @@ static int __posix_lock_file(struct inod
4421             (request->fl_type != F_UNLCK ||
4422              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4423                 new_fl = locks_alloc_lock();
4424 +               new_fl->fl_xid = xid;
4425 +               vx_locks_inc(new_fl);
4426                 new_fl2 = locks_alloc_lock();
4427 +               new_fl2->fl_xid = xid;
4428 +               vx_locks_inc(new_fl2);
4429         }
4430  
4431         lock_flocks();
4432 @@ -1007,7 +1038,8 @@ static int __posix_lock_file(struct inod
4433  int posix_lock_file(struct file *filp, struct file_lock *fl,
4434                         struct file_lock *conflock)
4435  {
4436 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
4437 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
4438 +               fl, conflock, filp->f_xid);
4439  }
4440  EXPORT_SYMBOL(posix_lock_file);
4441  
4442 @@ -1097,7 +1129,7 @@ int locks_mandatory_area(int read_write,
4443         fl.fl_end = offset + count - 1;
4444  
4445         for (;;) {
4446 -               error = __posix_lock_file(inode, &fl, NULL);
4447 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4448                 if (error != FILE_LOCK_DEFERRED)
4449                         break;
4450                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4451 @@ -1410,6 +1442,7 @@ int generic_setlease(struct file *filp, 
4452                 goto out;
4453  
4454         locks_insert_lock(before, lease);
4455 +       vx_locks_inc(lease);
4456         return 0;
4457  
4458  out:
4459 @@ -1794,6 +1827,11 @@ int fcntl_setlk(unsigned int fd, struct 
4460         if (file_lock == NULL)
4461                 return -ENOLCK;
4462  
4463 +       vxd_assert(filp->f_xid == vx_current_xid(),
4464 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4465 +       file_lock->fl_xid = filp->f_xid;
4466 +       vx_locks_inc(file_lock);
4467 +
4468         /*
4469          * This might block, so we do it before checking the inode.
4470          */
4471 @@ -1912,6 +1950,11 @@ int fcntl_setlk64(unsigned int fd, struc
4472         if (file_lock == NULL)
4473                 return -ENOLCK;
4474  
4475 +       vxd_assert(filp->f_xid == vx_current_xid(),
4476 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4477 +       file_lock->fl_xid = filp->f_xid;
4478 +       vx_locks_inc(file_lock);
4479 +
4480         /*
4481          * This might block, so we do it before checking the inode.
4482          */
4483 @@ -2177,8 +2220,11 @@ static int locks_show(struct seq_file *f
4484  
4485         lock_get_status(f, fl, *((loff_t *)f->private), "");
4486  
4487 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4488 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4489 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4490 +                       continue;
4491                 lock_get_status(f, bfl, *((loff_t *)f->private), " ->");
4492 +       }
4493  
4494         return 0;
4495  }
4496 diff -NurpP --minimal linux-3.1.1/fs/namei.c linux-3.1.1-vs2.3.2/fs/namei.c
4497 --- linux-3.1.1/fs/namei.c      2011-11-15 16:44:52.000000000 +0100
4498 +++ linux-3.1.1-vs2.3.2/fs/namei.c      2011-11-16 14:28:54.000000000 +0100
4499 @@ -33,6 +33,14 @@
4500  #include <linux/device_cgroup.h>
4501  #include <linux/fs_struct.h>
4502  #include <linux/posix_acl.h>
4503 +#include <linux/proc_fs.h>
4504 +#include <linux/vserver/inode.h>
4505 +#include <linux/vs_base.h>
4506 +#include <linux/vs_tag.h>
4507 +#include <linux/vs_cowbl.h>
4508 +#include <linux/vs_device.h>
4509 +#include <linux/vs_context.h>
4510 +#include <linux/pid_namespace.h>
4511  #include <asm/uaccess.h>
4512  
4513  #include "internal.h"
4514 @@ -222,6 +230,89 @@ static int check_acl(struct inode *inode
4515         return -EAGAIN;
4516  }
4517  
4518 +static inline int dx_barrier(const struct inode *inode)
4519 +{
4520 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4521 +               vxwprintk_task(1, "did hit the barrier.");
4522 +               return 1;
4523 +       }
4524 +       return 0;
4525 +}
4526 +
4527 +static int __dx_permission(const struct inode *inode, int mask)
4528 +{
4529 +       if (dx_barrier(inode))
4530 +               return -EACCES;
4531 +
4532 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4533 +               /* devpts is xid tagged */
4534 +               if (S_ISDIR(inode->i_mode) ||
4535 +                   vx_check((xid_t)inode->i_tag, VS_IDENT | VS_WATCH_P))
4536 +                       return 0;
4537 +
4538 +               /* just pretend we didn't find anything */
4539 +               return -ENOENT;
4540 +       }
4541 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4542 +               struct proc_dir_entry *de = PDE(inode);
4543 +
4544 +               if (de && !vx_hide_check(0, de->vx_flags))
4545 +                       goto out;
4546 +
4547 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4548 +                       struct pid *pid;
4549 +                       struct task_struct *tsk;
4550 +
4551 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4552 +                           vx_flags(VXF_STATE_SETUP, 0))
4553 +                               return 0;
4554 +
4555 +                       pid = PROC_I(inode)->pid;
4556 +                       if (!pid)
4557 +                               goto out;
4558 +
4559 +                       rcu_read_lock();
4560 +                       tsk = pid_task(pid, PIDTYPE_PID);
4561 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4562 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4563 +                       if (tsk &&
4564 +                               vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P)) {
4565 +                               rcu_read_unlock();
4566 +                               return 0;
4567 +                       }
4568 +                       rcu_read_unlock();
4569 +               }
4570 +               else {
4571 +                       /* FIXME: Should we block some entries here? */
4572 +                       return 0;
4573 +               }
4574 +       }
4575 +       else {
4576 +               if (dx_notagcheck(inode->i_sb) ||
4577 +                   dx_check(inode->i_tag, DX_HOSTID | DX_ADMIN | DX_WATCH |
4578 +                            DX_IDENT))
4579 +                       return 0;
4580 +       }
4581 +
4582 +out:
4583 +       return -EACCES;
4584 +}
4585 +
4586 +int dx_permission(const struct inode *inode, int mask)
4587 +{
4588 +       int ret = __dx_permission(inode, mask);
4589 +       if (unlikely(ret)) {
4590 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
4591 +               if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4592 +#endif
4593 +                   vxwprintk_task(1,
4594 +                       "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4595 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
4596 +                       inode->i_ino);
4597 +       }
4598 +       return ret;
4599 +}
4600 +
4601  /*
4602   * This does basic POSIX ACL permission checking
4603   */
4604 @@ -357,10 +448,14 @@ int inode_permission(struct inode *inode
4605                 /*
4606                  * Nobody gets write access to an immutable file.
4607                  */
4608 -               if (IS_IMMUTABLE(inode))
4609 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4610                         return -EACCES;
4611         }
4612  
4613 +       retval = dx_permission(inode, mask);
4614 +       if (retval)
4615 +               return retval;
4616 +
4617         retval = do_inode_permission(inode, mask);
4618         if (retval)
4619                 return retval;
4620 @@ -1037,7 +1132,8 @@ static void follow_dotdot(struct nameida
4621  
4622                 if (nd->path.dentry == nd->root.dentry &&
4623                     nd->path.mnt == nd->root.mnt) {
4624 -                       break;
4625 +                       /* for sane '/' avoid follow_mount() */
4626 +                       return;
4627                 }
4628                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4629                         /* rare case of legitimate dget_parent()... */
4630 @@ -1146,6 +1242,9 @@ static int do_lookup(struct nameidata *n
4631                 }
4632                 if (unlikely(d_need_lookup(dentry)))
4633                         goto unlazy;
4634 +
4635 +               /* FIXME: check dx permission */
4636 +
4637                 path->mnt = mnt;
4638                 path->dentry = dentry;
4639                 if (unlikely(!__follow_mount_rcu(nd, path, inode)))
4640 @@ -1207,6 +1306,8 @@ retry:
4641                 }
4642         }
4643  
4644 +       /* FIXME: check dx permission */
4645 +
4646         path->mnt = mnt;
4647         path->dentry = dentry;
4648         err = follow_managed(path, nd->flags);
4649 @@ -1901,7 +2002,7 @@ static int may_delete(struct inode *dir,
4650         if (IS_APPEND(dir))
4651                 return -EPERM;
4652         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
4653 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4654 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4655                 return -EPERM;
4656         if (isdir) {
4657                 if (!S_ISDIR(victim->d_inode->i_mode))
4658 @@ -1981,19 +2082,25 @@ int vfs_create(struct inode *dir, struct
4659  {
4660         int error = may_create(dir, dentry);
4661  
4662 -       if (error)
4663 +       if (error) {
4664 +               vxdprintk(VXD_CBIT(misc, 3), "may_create failed with %d", error);
4665                 return error;
4666 +       }
4667  
4668         if (!dir->i_op->create)
4669                 return -EACCES; /* shouldn't it be ENOSYS? */
4670         mode &= S_IALLUGO;
4671         mode |= S_IFREG;
4672         error = security_inode_create(dir, dentry, mode);
4673 -       if (error)
4674 +       if (error) {
4675 +               vxdprintk(VXD_CBIT(misc, 3), "security_inode_create failed with %d", error);
4676                 return error;
4677 +       }
4678         error = dir->i_op->create(dir, dentry, mode, nd);
4679         if (!error)
4680                 fsnotify_create(dir, dentry);
4681 +       else
4682 +               vxdprintk(VXD_CBIT(misc, 3), "i_op->create failed with %d", error);
4683         return error;
4684  }
4685  
4686 @@ -2028,6 +2135,15 @@ static int may_open(struct path *path, i
4687                 break;
4688         }
4689  
4690 +#ifdef CONFIG_VSERVER_COWBL
4691 +       if (IS_COW(inode) &&
4692 +               ((flag & O_ACCMODE) != O_RDONLY)) {
4693 +               if (IS_COW_LINK(inode))
4694 +                       return -EMLINK;
4695 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4696 +               mark_inode_dirty(inode);
4697 +       }
4698 +#endif
4699         error = inode_permission(inode, acc_mode);
4700         if (error)
4701                 return error;
4702 @@ -2255,6 +2371,16 @@ ok:
4703         }
4704  common:
4705         error = may_open(&nd->path, acc_mode, open_flag);
4706 +#ifdef CONFIG_VSERVER_COWBL
4707 +       if (error == -EMLINK) {
4708 +               struct dentry *dentry;
4709 +               dentry = cow_break_link(pathname);
4710 +               if (IS_ERR(dentry))
4711 +                       error = PTR_ERR(dentry);
4712 +               else
4713 +                       dput(dentry);
4714 +       }
4715 +#endif
4716         if (error)
4717                 goto exit;
4718         filp = nameidata_to_filp(nd);
4719 @@ -2297,6 +2423,7 @@ static struct file *path_openat(int dfd,
4720         struct path path;
4721         int error;
4722  
4723 +restart:
4724         filp = get_empty_filp();
4725         if (!filp)
4726                 return ERR_PTR(-ENFILE);
4727 @@ -2334,6 +2461,17 @@ static struct file *path_openat(int dfd,
4728                         filp = do_last(nd, &path, op, pathname);
4729                 put_link(nd, &link, cookie);
4730         }
4731 +
4732 +#ifdef CONFIG_VSERVER_COWBL
4733 +       if (filp == ERR_PTR(-EMLINK)) {
4734 +               if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4735 +                       path_put(&nd->root);
4736 +               if (base)
4737 +                       fput(base);
4738 +               release_open_intent(nd);
4739 +               goto restart;
4740 +       }
4741 +#endif
4742  out:
4743         if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4744                 path_put(&nd->root);
4745 @@ -2423,6 +2561,11 @@ struct dentry *kern_path_create(int dfd,
4746                 goto fail;
4747         }
4748         *path = nd.path;
4749 +       vxdprintk(VXD_CBIT(misc, 3), "kern_path_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4750 +               path->dentry, path->dentry->d_name.len,
4751 +               path->dentry->d_name.name, dentry,
4752 +               dentry->d_name.len, dentry->d_name.name,
4753 +               path->dentry->d_inode);
4754         return dentry;
4755  eexist:
4756         dput(dentry);
4757 @@ -2904,7 +3047,7 @@ int vfs_link(struct dentry *old_dentry, 
4758         /*
4759          * A link to an append-only or immutable file cannot be created.
4760          */
4761 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4762 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4763                 return -EPERM;
4764         if (!dir->i_op->link)
4765                 return -EPERM;
4766 @@ -3285,6 +3428,227 @@ int vfs_follow_link(struct nameidata *nd
4767         return __vfs_follow_link(nd, link);
4768  }
4769  
4770 +
4771 +#ifdef CONFIG_VSERVER_COWBL
4772 +
4773 +static inline
4774 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4775 +{
4776 +       loff_t ppos = 0;
4777 +
4778 +       return do_splice_direct(in, &ppos, out, len, 0);
4779 +}
4780 +
4781 +struct dentry *cow_break_link(const char *pathname)
4782 +{
4783 +       int ret, mode, pathlen, redo = 0;
4784 +       struct nameidata old_nd, dir_nd;
4785 +       struct path old_path, dir_path;
4786 +       struct dentry *dir, *old_dentry, *new_dentry = NULL;
4787 +       struct file *old_file;
4788 +       struct file *new_file;
4789 +       char *to, *path, pad='\251';
4790 +       loff_t size;
4791 +
4792 +       vxdprintk(VXD_CBIT(misc, 1),
4793 +               "cow_break_link(" VS_Q("%s") ")", pathname);
4794 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
4795 +       ret = -ENOMEM;
4796 +       if (!path)
4797 +               goto out;
4798 +
4799 +       /* old_nd will have refs to dentry and mnt */
4800 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4801 +       vxdprintk(VXD_CBIT(misc, 2),
4802 +               "do_path_lookup(old): %d [r=%d]",
4803 +               ret, mnt_get_count(old_nd.path.mnt));
4804 +       if (ret < 0)
4805 +               goto out_free_path;
4806 +
4807 +       old_path = old_nd.path;
4808 +       old_dentry = old_path.dentry;
4809 +       mode = old_dentry->d_inode->i_mode;
4810 +
4811 +       to = d_path(&old_path, path, PATH_MAX-2);
4812 +       pathlen = strlen(to);
4813 +       vxdprintk(VXD_CBIT(misc, 2),
4814 +               "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4815 +               old_dentry,
4816 +               old_dentry->d_name.len, old_dentry->d_name.name,
4817 +               old_dentry->d_name.len);
4818 +
4819 +       to[pathlen + 1] = 0;
4820 +retry:
4821 +       new_dentry = NULL;
4822 +       to[pathlen] = pad--;
4823 +       ret = -ELOOP;
4824 +       if (pad <= '\240')
4825 +               goto out_rel_old;
4826 +
4827 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4828 +       /* dir_nd will have refs to dentry and mnt */
4829 +       ret = do_path_lookup(AT_FDCWD, to,
4830 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
4831 +       vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(new): %d", ret);
4832 +       if (ret < 0)
4833 +               goto retry;
4834 +
4835 +       /* this puppy downs the dir inode mutex if successful */
4836 +       new_dentry = kern_path_create(AT_FDCWD, to, &dir_path, 0);
4837 +       if (!new_dentry || IS_ERR(new_dentry)) {
4838 +               path_put(&dir_nd.path);
4839 +               vxdprintk(VXD_CBIT(misc, 2),
4840 +                       "kern_path_create(new) failed with %ld",
4841 +                       PTR_ERR(new_dentry));
4842 +               goto retry;
4843 +       }
4844 +       path_put(&dir_path);
4845 +       vxdprintk(VXD_CBIT(misc, 2),
4846 +               "kern_path_create(new): %p [" VS_Q("%.*s") ":%d]",
4847 +               new_dentry,
4848 +               new_dentry->d_name.len, new_dentry->d_name.name,
4849 +               new_dentry->d_name.len);
4850 +
4851 +       dir = dir_nd.path.dentry;
4852 +
4853 +       ret = vfs_create(dir->d_inode, new_dentry, mode, &dir_nd);
4854 +       vxdprintk(VXD_CBIT(misc, 2),
4855 +               "vfs_create(new): %d", ret);
4856 +       if (ret == -EEXIST) {
4857 +               mutex_unlock(&dir->d_inode->i_mutex);
4858 +               path_put(&dir_nd.path);
4859 +               dput(new_dentry);
4860 +               goto retry;
4861 +       }
4862 +       else if (ret < 0)
4863 +               goto out_unlock_new;
4864 +
4865 +       /* drop out early, ret passes ENOENT */
4866 +       ret = -ENOENT;
4867 +       if ((redo = d_unhashed(old_dentry)))
4868 +               goto out_unlock_new;
4869 +
4870 +       path_get(&old_path);
4871 +       /* this one cleans up the dentry/mnt in case of failure */
4872 +       old_file = dentry_open(old_dentry, old_path.mnt,
4873 +               O_RDONLY, current_cred());
4874 +       vxdprintk(VXD_CBIT(misc, 2),
4875 +               "dentry_open(old): %p", old_file);
4876 +       if (IS_ERR(old_file)) {
4877 +               ret = PTR_ERR(old_file);
4878 +               goto out_unlock_new;
4879 +       }
4880 +
4881 +       dget(new_dentry);
4882 +       mntget(old_path.mnt);
4883 +       /* this one cleans up the dentry/mnt in case of failure */
4884 +       new_file = dentry_open(new_dentry, old_path.mnt,
4885 +               O_WRONLY, current_cred());
4886 +       vxdprintk(VXD_CBIT(misc, 2),
4887 +               "dentry_open(new): %p", new_file);
4888 +       if (IS_ERR(new_file)) {
4889 +               ret = PTR_ERR(new_file);
4890 +               goto out_fput_old;
4891 +       }
4892 +
4893 +       size = i_size_read(old_file->f_dentry->d_inode);
4894 +       ret = do_cow_splice(old_file, new_file, size);
4895 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4896 +       if (ret < 0) {
4897 +               goto out_fput_both;
4898 +       } else if (ret < size) {
4899 +               ret = -ENOSPC;
4900 +               goto out_fput_both;
4901 +       } else {
4902 +               struct inode *old_inode = old_dentry->d_inode;
4903 +               struct inode *new_inode = new_dentry->d_inode;
4904 +               struct iattr attr = {
4905 +                       .ia_uid = old_inode->i_uid,
4906 +                       .ia_gid = old_inode->i_gid,
4907 +                       .ia_valid = ATTR_UID | ATTR_GID
4908 +                       };
4909 +
4910 +               setattr_copy(new_inode, &attr);
4911 +               mark_inode_dirty(new_inode);
4912 +       }
4913 +
4914 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4915 +
4916 +       /* drop out late */
4917 +       ret = -ENOENT;
4918 +       if ((redo = d_unhashed(old_dentry)))
4919 +               goto out_unlock;
4920 +
4921 +       vxdprintk(VXD_CBIT(misc, 2),
4922 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4923 +               new_dentry->d_name.len, new_dentry->d_name.name,
4924 +               new_dentry->d_name.len,
4925 +               old_dentry->d_name.len, old_dentry->d_name.name,
4926 +               old_dentry->d_name.len);
4927 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_dentry,
4928 +               old_dentry->d_parent->d_inode, old_dentry);
4929 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4930 +
4931 +out_unlock:
4932 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4933 +
4934 +out_fput_both:
4935 +       vxdprintk(VXD_CBIT(misc, 3),
4936 +               "fput(new_file=%p[#%ld])", new_file,
4937 +               atomic_long_read(&new_file->f_count));
4938 +       fput(new_file);
4939 +
4940 +out_fput_old:
4941 +       vxdprintk(VXD_CBIT(misc, 3),
4942 +               "fput(old_file=%p[#%ld])", old_file,
4943 +               atomic_long_read(&old_file->f_count));
4944 +       fput(old_file);
4945 +
4946 +out_unlock_new:
4947 +       mutex_unlock(&dir->d_inode->i_mutex);
4948 +       if (!ret)
4949 +               goto out_redo;
4950 +
4951 +       /* error path cleanup */
4952 +       vfs_unlink(dir->d_inode, new_dentry);
4953 +
4954 +out_redo:
4955 +       if (!redo)
4956 +               goto out_rel_both;
4957 +       /* lookup dentry once again */
4958 +       /* old_nd.path is freed as old_path in out_rel_old */
4959 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4960 +       if (ret)
4961 +               goto out_rel_both;
4962 +
4963 +       dput(new_dentry);
4964 +       new_dentry = old_nd.path.dentry;
4965 +       vxdprintk(VXD_CBIT(misc, 2),
4966 +               "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4967 +               new_dentry,
4968 +               new_dentry->d_name.len, new_dentry->d_name.name,
4969 +               new_dentry->d_name.len);
4970 +       dget(new_dentry);
4971 +
4972 +out_rel_both:
4973 +       path_put(&dir_nd.path);
4974 +out_rel_old:
4975 +       path_put(&old_path);
4976 +out_free_path:
4977 +       kfree(path);
4978 +out:
4979 +       if (ret) {
4980 +               dput(new_dentry);
4981 +               new_dentry = ERR_PTR(ret);
4982 +       }
4983 +       vxdprintk(VXD_CBIT(misc, 3),
4984 +               "cow_break_link returning with %p [r=%d]",
4985 +               new_dentry, mnt_get_count(old_nd.path.mnt));
4986 +       return new_dentry;
4987 +}
4988 +
4989 +#endif
4990 +
4991  /* get the link contents into pagecache */
4992  static char *page_getlink(struct dentry * dentry, struct page **ppage)
4993  {
4994 diff -NurpP --minimal linux-3.1.1/fs/namespace.c linux-3.1.1-vs2.3.2/fs/namespace.c
4995 --- linux-3.1.1/fs/namespace.c  2011-11-15 16:44:52.000000000 +0100
4996 +++ linux-3.1.1-vs2.3.2/fs/namespace.c  2011-11-15 17:13:06.000000000 +0100
4997 @@ -31,6 +31,11 @@
4998  #include <linux/idr.h>
4999  #include <linux/fs_struct.h>
5000  #include <linux/fsnotify.h>
5001 +#include <linux/vs_base.h>
5002 +#include <linux/vs_context.h>
5003 +#include <linux/vs_tag.h>
5004 +#include <linux/vserver/space.h>
5005 +#include <linux/vserver/global.h>
5006  #include <asm/uaccess.h>
5007  #include <asm/unistd.h>
5008  #include "pnode.h"
5009 @@ -679,6 +684,10 @@ vfs_kern_mount(struct file_system_type *
5010         if (!type)
5011                 return ERR_PTR(-ENODEV);
5012  
5013 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
5014 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
5015 +               return ERR_PTR(-EPERM);
5016 +
5017         mnt = alloc_vfsmnt(name);
5018         if (!mnt)
5019                 return ERR_PTR(-ENOMEM);
5020 @@ -724,6 +733,7 @@ static struct vfsmount *clone_mnt(struct
5021                 mnt->mnt_root = dget(root);
5022                 mnt->mnt_mountpoint = mnt->mnt_root;
5023                 mnt->mnt_parent = mnt;
5024 +               mnt->mnt_tag = old->mnt_tag;
5025  
5026                 if (flag & CL_SLAVE) {
5027                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
5028 @@ -852,6 +862,31 @@ static inline void mangle(struct seq_fil
5029         seq_escape(m, s, " \t\n\\");
5030  }
5031  
5032 +static int mnt_is_reachable(struct vfsmount *mnt)
5033 +{
5034 +       struct path root;
5035 +       struct dentry *point;
5036 +       int ret;
5037 +
5038 +       if (mnt == mnt->mnt_ns->root)
5039 +               return 1;
5040 +
5041 +       br_read_lock(vfsmount_lock);
5042 +       root = current->fs->root;
5043 +       point = root.dentry;
5044 +
5045 +       while ((mnt != mnt->mnt_parent) && (mnt != root.mnt)) {
5046 +               point = mnt->mnt_mountpoint;
5047 +               mnt = mnt->mnt_parent;
5048 +       }
5049 +
5050 +       ret = (mnt == root.mnt) && is_subdir(point, root.dentry);
5051 +
5052 +       br_read_unlock(vfsmount_lock);
5053 +
5054 +       return ret;
5055 +}
5056 +
5057  /*
5058   * Simple .show_options callback for filesystems which don't want to
5059   * implement more complex mount option showing.
5060 @@ -954,6 +989,8 @@ static int show_sb_opts(struct seq_file 
5061                 { MS_SYNCHRONOUS, ",sync" },
5062                 { MS_DIRSYNC, ",dirsync" },
5063                 { MS_MANDLOCK, ",mand" },
5064 +               { MS_TAGGED, ",tag" },
5065 +               { MS_NOTAGCHECK, ",notagcheck" },
5066                 { 0, NULL }
5067         };
5068         const struct proc_fs_info *fs_infop;
5069 @@ -1000,16 +1037,26 @@ static int show_vfsmnt(struct seq_file *
5070         int err = 0;
5071         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5072  
5073 -       if (mnt->mnt_sb->s_op->show_devname) {
5074 -               err = mnt->mnt_sb->s_op->show_devname(m, mnt);
5075 -               if (err)
5076 -                       goto out;
5077 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5078 +               return SEQ_SKIP;
5079 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5080 +               return SEQ_SKIP;
5081 +
5082 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5083 +               mnt == current->fs->root.mnt) {
5084 +               seq_puts(m, "/dev/root / ");
5085         } else {
5086 -               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5087 +               if (mnt->mnt_sb->s_op->show_devname) {
5088 +                       err = mnt->mnt_sb->s_op->show_devname(m, mnt);
5089 +                       if (err)
5090 +                               goto out;
5091 +               } else {
5092 +                       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5093 +               }
5094 +               seq_putc(m, ' ');
5095 +               seq_path(m, &mnt_path, " \t\n\\");
5096 +               seq_putc(m, ' ');
5097         }
5098 -       seq_putc(m, ' ');
5099 -       seq_path(m, &mnt_path, " \t\n\\");
5100 -       seq_putc(m, ' ');
5101         show_type(m, mnt->mnt_sb);
5102         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
5103         err = show_sb_opts(m, mnt->mnt_sb);
5104 @@ -1039,6 +1086,11 @@ static int show_mountinfo(struct seq_fil
5105         struct path root = p->root;
5106         int err = 0;
5107  
5108 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5109 +               return SEQ_SKIP;
5110 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5111 +               return SEQ_SKIP;
5112 +
5113         seq_printf(m, "%i %i %u:%u ", mnt->mnt_id, mnt->mnt_parent->mnt_id,
5114                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
5115         if (sb->s_op->show_path)
5116 @@ -1107,22 +1159,32 @@ static int show_vfsstat(struct seq_file 
5117         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5118         int err = 0;
5119  
5120 -       /* device */
5121 -       if (mnt->mnt_sb->s_op->show_devname) {
5122 -               seq_puts(m, "device ");
5123 -               err = mnt->mnt_sb->s_op->show_devname(m, mnt);
5124 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5125 +               return SEQ_SKIP;
5126 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5127 +               return SEQ_SKIP;
5128 +
5129 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5130 +               mnt == current->fs->root.mnt) {
5131 +               seq_puts(m, "device /dev/root mounted on / ");
5132         } else {
5133 -               if (mnt->mnt_devname) {
5134 +               /* device */
5135 +               if (mnt->mnt_sb->s_op->show_devname) {
5136                         seq_puts(m, "device ");
5137 -                       mangle(m, mnt->mnt_devname);
5138 -               } else
5139 -                       seq_puts(m, "no device");
5140 -       }
5141 +                       err = mnt->mnt_sb->s_op->show_devname(m, mnt);
5142 +               } else {
5143 +                       if (mnt->mnt_devname) {
5144 +                               seq_puts(m, "device ");
5145 +                               mangle(m, mnt->mnt_devname);
5146 +                       } else
5147 +                               seq_puts(m, "no device");
5148 +               }
5149  
5150 -       /* mount point */
5151 -       seq_puts(m, " mounted on ");
5152 -       seq_path(m, &mnt_path, " \t\n\\");
5153 -       seq_putc(m, ' ');
5154 +               /* mount point */
5155 +               seq_puts(m, " mounted on ");
5156 +               seq_path(m, &mnt_path, " \t\n\\");
5157 +               seq_putc(m, ' ');
5158 +       }
5159  
5160         /* file system type */
5161         seq_puts(m, "with fstype ");
5162 @@ -1381,7 +1443,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
5163                 goto dput_and_out;
5164  
5165         retval = -EPERM;
5166 -       if (!capable(CAP_SYS_ADMIN))
5167 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5168                 goto dput_and_out;
5169  
5170         retval = do_umount(path.mnt, flags);
5171 @@ -1407,7 +1469,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
5172  
5173  static int mount_is_safe(struct path *path)
5174  {
5175 -       if (capable(CAP_SYS_ADMIN))
5176 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5177                 return 0;
5178         return -EPERM;
5179  #ifdef notyet
5180 @@ -1717,7 +1779,7 @@ static int do_change_type(struct path *p
5181         int type;
5182         int err = 0;
5183  
5184 -       if (!capable(CAP_SYS_ADMIN))
5185 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_NAMESPACE))
5186                 return -EPERM;
5187  
5188         if (path->dentry != path->mnt->mnt_root)
5189 @@ -1733,6 +1795,7 @@ static int do_change_type(struct path *p
5190                 if (err)
5191                         goto out_unlock;
5192         }
5193 +       // mnt->mnt_flags = mnt_flags;
5194  
5195         br_write_lock(vfsmount_lock);
5196         for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
5197 @@ -1748,12 +1811,14 @@ static int do_change_type(struct path *p
5198   * do loopback mount.
5199   */
5200  static int do_loopback(struct path *path, char *old_name,
5201 -                               int recurse)
5202 +       tag_t tag, unsigned long flags, int mnt_flags)
5203  {
5204         LIST_HEAD(umount_list);
5205         struct path old_path;
5206         struct vfsmount *mnt = NULL;
5207         int err = mount_is_safe(path);
5208 +       int recurse = flags & MS_REC;
5209 +
5210         if (err)
5211                 return err;
5212         if (!old_name || !*old_name)
5213 @@ -1819,12 +1884,12 @@ static int change_mount_flags(struct vfs
5214   * on it - tough luck.
5215   */
5216  static int do_remount(struct path *path, int flags, int mnt_flags,
5217 -                     void *data)
5218 +       void *data, xid_t xid)
5219  {
5220         int err;
5221         struct super_block *sb = path->mnt->mnt_sb;
5222  
5223 -       if (!capable(CAP_SYS_ADMIN))
5224 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
5225                 return -EPERM;
5226  
5227         if (!check_mnt(path->mnt))
5228 @@ -1872,7 +1937,7 @@ static int do_move_mount(struct path *pa
5229         struct path old_path, parent_path;
5230         struct vfsmount *p;
5231         int err = 0;
5232 -       if (!capable(CAP_SYS_ADMIN))
5233 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5234                 return -EPERM;
5235         if (!old_name || !*old_name)
5236                 return -EINVAL;
5237 @@ -2023,7 +2088,7 @@ static int do_new_mount(struct path *pat
5238                 return -EINVAL;
5239  
5240         /* we need capabilities... */
5241 -       if (!capable(CAP_SYS_ADMIN))
5242 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5243                 return -EPERM;
5244  
5245         mnt = do_kern_mount(type, flags, name, data);
5246 @@ -2292,6 +2357,7 @@ long do_mount(char *dev_name, char *dir_
5247         struct path path;
5248         int retval = 0;
5249         int mnt_flags = 0;
5250 +       tag_t tag = 0;
5251  
5252         /* Discard magic */
5253         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5254 @@ -2319,6 +2385,12 @@ long do_mount(char *dev_name, char *dir_
5255         if (!(flags & MS_NOATIME))
5256                 mnt_flags |= MNT_RELATIME;
5257  
5258 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5259 +               /* FIXME: bind and re-mounts get the tag flag? */
5260 +               if (flags & (MS_BIND|MS_REMOUNT))
5261 +                       flags |= MS_TAGID;
5262 +       }
5263 +
5264         /* Separate the per-mountpoint flags */
5265         if (flags & MS_NOSUID)
5266                 mnt_flags |= MNT_NOSUID;
5267 @@ -2335,15 +2407,17 @@ long do_mount(char *dev_name, char *dir_
5268         if (flags & MS_RDONLY)
5269                 mnt_flags |= MNT_READONLY;
5270  
5271 +       if (!capable(CAP_SYS_ADMIN))
5272 +               mnt_flags |= MNT_NODEV;
5273         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
5274                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
5275                    MS_STRICTATIME);
5276  
5277         if (flags & MS_REMOUNT)
5278                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5279 -                                   data_page);
5280 +                                   data_page, tag);
5281         else if (flags & MS_BIND)
5282 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5283 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5284         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5285                 retval = do_change_type(&path, flags);
5286         else if (flags & MS_MOVE)
5287 @@ -2443,6 +2517,7 @@ static struct mnt_namespace *dup_mnt_ns(
5288                 q = next_mnt(q, new_ns->root);
5289         }
5290         up_write(&namespace_sem);
5291 +       atomic_inc(&vs_global_mnt_ns);
5292  
5293         if (rootmnt)
5294                 mntput(rootmnt);
5295 @@ -2582,9 +2657,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5296                 goto out3;
5297  
5298         error = -EINVAL;
5299 -       if (IS_MNT_SHARED(old.mnt) ||
5300 +       if ((IS_MNT_SHARED(old.mnt) ||
5301                 IS_MNT_SHARED(new.mnt->mnt_parent) ||
5302 -               IS_MNT_SHARED(root.mnt->mnt_parent))
5303 +               IS_MNT_SHARED(root.mnt->mnt_parent)) &&
5304 +               !vx_flags(VXF_STATE_SETUP, 0))
5305                 goto out4;
5306         if (!check_mnt(root.mnt) || !check_mnt(new.mnt))
5307                 goto out4;
5308 @@ -2716,6 +2792,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5309         br_write_unlock(vfsmount_lock);
5310         up_write(&namespace_sem);
5311         release_mounts(&umount_list);
5312 +       atomic_dec(&vs_global_mnt_ns);
5313         kfree(ns);
5314  }
5315  EXPORT_SYMBOL(put_mnt_ns);
5316 diff -NurpP --minimal linux-3.1.1/fs/nfs/client.c linux-3.1.1-vs2.3.2/fs/nfs/client.c
5317 --- linux-3.1.1/fs/nfs/client.c 2011-10-24 18:45:27.000000000 +0200
5318 +++ linux-3.1.1-vs2.3.2/fs/nfs/client.c 2011-10-24 18:53:33.000000000 +0200
5319 @@ -778,6 +778,9 @@ static int nfs_init_server_rpcclient(str
5320         if (server->flags & NFS_MOUNT_SOFT)
5321                 server->client->cl_softrtry = 1;
5322  
5323 +       server->client->cl_tag = 0;
5324 +       if (server->flags & NFS_MOUNT_TAGGED)
5325 +               server->client->cl_tag = 1;
5326         return 0;
5327  }
5328  
5329 @@ -952,6 +955,10 @@ static void nfs_server_set_fsinfo(struct
5330                 server->acdirmin = server->acdirmax = 0;
5331         }
5332  
5333 +       /* FIXME: needs fsinfo
5334 +       if (server->flags & NFS_MOUNT_TAGGED)
5335 +               sb->s_flags |= MS_TAGGED;       */
5336 +
5337         server->maxfilesize = fsinfo->maxfilesize;
5338  
5339         server->time_delta = fsinfo->time_delta;
5340 diff -NurpP --minimal linux-3.1.1/fs/nfs/dir.c linux-3.1.1-vs2.3.2/fs/nfs/dir.c
5341 --- linux-3.1.1/fs/nfs/dir.c    2011-10-24 18:45:27.000000000 +0200
5342 +++ linux-3.1.1-vs2.3.2/fs/nfs/dir.c    2011-10-24 18:53:33.000000000 +0200
5343 @@ -35,6 +35,7 @@
5344  #include <linux/sched.h>
5345  #include <linux/kmemleak.h>
5346  #include <linux/xattr.h>
5347 +#include <linux/vs_tag.h>
5348  
5349  #include "delegation.h"
5350  #include "iostat.h"
5351 @@ -1311,6 +1312,7 @@ static struct dentry *nfs_lookup(struct 
5352         if (IS_ERR(res))
5353                 goto out_unblock_sillyrename;
5354  
5355 +       dx_propagate_tag(nd, inode);
5356  no_entry:
5357         res = d_materialise_unique(dentry, inode);
5358         if (res != NULL) {
5359 diff -NurpP --minimal linux-3.1.1/fs/nfs/inode.c linux-3.1.1-vs2.3.2/fs/nfs/inode.c
5360 --- linux-3.1.1/fs/nfs/inode.c  2011-10-24 18:45:27.000000000 +0200
5361 +++ linux-3.1.1-vs2.3.2/fs/nfs/inode.c  2011-10-24 18:53:33.000000000 +0200
5362 @@ -38,6 +38,7 @@
5363  #include <linux/nfs_xdr.h>
5364  #include <linux/slab.h>
5365  #include <linux/compat.h>
5366 +#include <linux/vs_tag.h>
5367  
5368  #include <asm/system.h>
5369  #include <asm/uaccess.h>
5370 @@ -273,6 +274,8 @@ nfs_fhget(struct super_block *sb, struct
5371         if (inode->i_state & I_NEW) {
5372                 struct nfs_inode *nfsi = NFS_I(inode);
5373                 unsigned long now = jiffies;
5374 +               uid_t uid;
5375 +               gid_t gid;
5376  
5377                 /* We set i_ino for the few things that still rely on it,
5378                  * such as stat(2) */
5379 @@ -321,8 +324,8 @@ nfs_fhget(struct super_block *sb, struct
5380                 nfsi->change_attr = 0;
5381                 inode->i_size = 0;
5382                 inode->i_nlink = 0;
5383 -               inode->i_uid = -2;
5384 -               inode->i_gid = -2;
5385 +               uid = -2;
5386 +               gid = -2;
5387                 inode->i_blocks = 0;
5388                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5389  
5390 @@ -359,13 +362,13 @@ nfs_fhget(struct super_block *sb, struct
5391                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5392                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5393                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5394 -                       inode->i_uid = fattr->uid;
5395 +                       uid = fattr->uid;
5396                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5397                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5398                                 | NFS_INO_INVALID_ACCESS
5399                                 | NFS_INO_INVALID_ACL;
5400                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5401 -                       inode->i_gid = fattr->gid;
5402 +                       gid = fattr->gid;
5403                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5404                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5405                                 | NFS_INO_INVALID_ACCESS
5406 @@ -378,6 +381,11 @@ nfs_fhget(struct super_block *sb, struct
5407                          */
5408                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5409                 }
5410 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5411 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5412 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
5413 +                               /* maybe fattr->xid someday */
5414 +
5415                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5416                 nfsi->attrtimeo_timestamp = now;
5417                 nfsi->access_cache = RB_ROOT;
5418 @@ -494,6 +502,8 @@ void nfs_setattr_update_inode(struct ino
5419                         inode->i_uid = attr->ia_uid;
5420                 if ((attr->ia_valid & ATTR_GID) != 0)
5421                         inode->i_gid = attr->ia_gid;
5422 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5423 +                       inode->i_tag = attr->ia_tag;
5424                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5425                 spin_unlock(&inode->i_lock);
5426         }
5427 @@ -943,6 +953,9 @@ static int nfs_check_inode_attributes(st
5428         struct nfs_inode *nfsi = NFS_I(inode);
5429         loff_t cur_size, new_isize;
5430         unsigned long invalid = 0;
5431 +       uid_t uid;
5432 +       gid_t gid;
5433 +       tag_t tag;
5434  
5435  
5436         /* Has the inode gone and changed behind our back? */
5437 @@ -966,13 +979,18 @@ static int nfs_check_inode_attributes(st
5438                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5439         }
5440  
5441 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5442 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5443 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5444 +
5445         /* Have any file permissions changed? */
5446         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5447                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5448 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && inode->i_uid != fattr->uid)
5449 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && uid != fattr->uid)
5450                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5451 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && inode->i_gid != fattr->gid)
5452 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && gid != fattr->gid)
5453                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5454 +               /* maybe check for tag too? */
5455  
5456         /* Has the link count changed? */
5457         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5458 @@ -1207,6 +1225,9 @@ static int nfs_update_inode(struct inode
5459         unsigned long invalid = 0;
5460         unsigned long now = jiffies;
5461         unsigned long save_cache_validity;
5462 +       uid_t uid;
5463 +       gid_t gid;
5464 +       tag_t tag;
5465  
5466         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
5467                         __func__, inode->i_sb->s_id, inode->i_ino,
5468 @@ -1314,6 +1335,9 @@ static int nfs_update_inode(struct inode
5469                                 | NFS_INO_REVAL_PAGECACHE
5470                                 | NFS_INO_REVAL_FORCED);
5471  
5472 +       uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5473 +       gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5474 +       tag = inode->i_tag;
5475  
5476         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5477                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5478 @@ -1335,9 +1359,9 @@ static int nfs_update_inode(struct inode
5479                                 | NFS_INO_REVAL_FORCED);
5480  
5481         if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
5482 -               if (inode->i_uid != fattr->uid) {
5483 +               if (uid != fattr->uid) {
5484                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5485 -                       inode->i_uid = fattr->uid;
5486 +                       uid = fattr->uid;
5487                 }
5488         } else if (server->caps & NFS_CAP_OWNER)
5489                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5490 @@ -1346,9 +1370,9 @@ static int nfs_update_inode(struct inode
5491                                 | NFS_INO_REVAL_FORCED);
5492  
5493         if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
5494 -               if (inode->i_gid != fattr->gid) {
5495 +               if (gid != fattr->gid) {
5496                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5497 -                       inode->i_gid = fattr->gid;
5498 +                       gid = fattr->gid;
5499                 }
5500         } else if (server->caps & NFS_CAP_OWNER_GROUP)
5501                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5502 @@ -1356,6 +1380,10 @@ static int nfs_update_inode(struct inode
5503                                 | NFS_INO_INVALID_ACL
5504                                 | NFS_INO_REVAL_FORCED);
5505  
5506 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5507 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5508 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, tag);
5509 +
5510         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5511                 if (inode->i_nlink != fattr->nlink) {
5512                         invalid |= NFS_INO_INVALID_ATTR;
5513 diff -NurpP --minimal linux-3.1.1/fs/nfs/nfs3xdr.c linux-3.1.1-vs2.3.2/fs/nfs/nfs3xdr.c
5514 --- linux-3.1.1/fs/nfs/nfs3xdr.c        2011-03-15 18:07:32.000000000 +0100
5515 +++ linux-3.1.1-vs2.3.2/fs/nfs/nfs3xdr.c        2011-10-24 18:53:33.000000000 +0200
5516 @@ -20,6 +20,7 @@
5517  #include <linux/nfs3.h>
5518  #include <linux/nfs_fs.h>
5519  #include <linux/nfsacl.h>
5520 +#include <linux/vs_tag.h>
5521  #include "internal.h"
5522  
5523  #define NFSDBG_FACILITY                NFSDBG_XDR
5524 @@ -562,7 +563,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5525   *             set_mtime       mtime;
5526   *     };
5527   */
5528 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5529 +static void encode_sattr3(struct xdr_stream *xdr,
5530 +       const struct iattr *attr, int tag)
5531  {
5532         u32 nbytes;
5533         __be32 *p;
5534 @@ -594,15 +596,19 @@ static void encode_sattr3(struct xdr_str
5535         } else
5536                 *p++ = xdr_zero;
5537  
5538 -       if (attr->ia_valid & ATTR_UID) {
5539 +       if (attr->ia_valid & ATTR_UID ||
5540 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5541                 *p++ = xdr_one;
5542 -               *p++ = cpu_to_be32(attr->ia_uid);
5543 +               *p++ = cpu_to_be32(TAGINO_UID(tag,
5544 +                       attr->ia_uid, attr->ia_tag));
5545         } else
5546                 *p++ = xdr_zero;
5547  
5548 -       if (attr->ia_valid & ATTR_GID) {
5549 +       if (attr->ia_valid & ATTR_GID ||
5550 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5551                 *p++ = xdr_one;
5552 -               *p++ = cpu_to_be32(attr->ia_gid);
5553 +               *p++ = cpu_to_be32(TAGINO_GID(tag,
5554 +                       attr->ia_gid, attr->ia_tag));
5555         } else
5556                 *p++ = xdr_zero;
5557  
5558 @@ -878,7 +884,7 @@ static void nfs3_xdr_enc_setattr3args(st
5559                                       const struct nfs3_sattrargs *args)
5560  {
5561         encode_nfs_fh3(xdr, args->fh);
5562 -       encode_sattr3(xdr, args->sattr);
5563 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5564         encode_sattrguard3(xdr, args);
5565  }
5566  
5567 @@ -1028,13 +1034,13 @@ static void nfs3_xdr_enc_write3args(stru
5568   *     };
5569   */
5570  static void encode_createhow3(struct xdr_stream *xdr,
5571 -                             const struct nfs3_createargs *args)
5572 +       const struct nfs3_createargs *args, int tag)
5573  {
5574         encode_uint32(xdr, args->createmode);
5575         switch (args->createmode) {
5576         case NFS3_CREATE_UNCHECKED:
5577         case NFS3_CREATE_GUARDED:
5578 -               encode_sattr3(xdr, args->sattr);
5579 +               encode_sattr3(xdr, args->sattr, tag);
5580                 break;
5581         case NFS3_CREATE_EXCLUSIVE:
5582                 encode_createverf3(xdr, args->verifier);
5583 @@ -1049,7 +1055,7 @@ static void nfs3_xdr_enc_create3args(str
5584                                      const struct nfs3_createargs *args)
5585  {
5586         encode_diropargs3(xdr, args->fh, args->name, args->len);
5587 -       encode_createhow3(xdr, args);
5588 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5589  }
5590  
5591  /*
5592 @@ -1065,7 +1071,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5593                                     const struct nfs3_mkdirargs *args)
5594  {
5595         encode_diropargs3(xdr, args->fh, args->name, args->len);
5596 -       encode_sattr3(xdr, args->sattr);
5597 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5598  }
5599  
5600  /*
5601 @@ -1082,9 +1088,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
5602   *     };
5603   */
5604  static void encode_symlinkdata3(struct xdr_stream *xdr,
5605 -                               const struct nfs3_symlinkargs *args)
5606 +       const struct nfs3_symlinkargs *args, int tag)
5607  {
5608 -       encode_sattr3(xdr, args->sattr);
5609 +       encode_sattr3(xdr, args->sattr, tag);
5610         encode_nfspath3(xdr, args->pages, args->pathlen);
5611  }
5612  
5613 @@ -1093,7 +1099,7 @@ static void nfs3_xdr_enc_symlink3args(st
5614                                       const struct nfs3_symlinkargs *args)
5615  {
5616         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
5617 -       encode_symlinkdata3(xdr, args);
5618 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
5619  }
5620  
5621  /*
5622 @@ -1121,24 +1127,24 @@ static void nfs3_xdr_enc_symlink3args(st
5623   *     };
5624   */
5625  static void encode_devicedata3(struct xdr_stream *xdr,
5626 -                              const struct nfs3_mknodargs *args)
5627 +       const struct nfs3_mknodargs *args, int tag)
5628  {
5629 -       encode_sattr3(xdr, args->sattr);
5630 +       encode_sattr3(xdr, args->sattr, tag);
5631         encode_specdata3(xdr, args->rdev);
5632  }
5633  
5634  static void encode_mknoddata3(struct xdr_stream *xdr,
5635 -                             const struct nfs3_mknodargs *args)
5636 +       const struct nfs3_mknodargs *args, int tag)
5637  {
5638         encode_ftype3(xdr, args->type);
5639         switch (args->type) {
5640         case NF3CHR:
5641         case NF3BLK:
5642 -               encode_devicedata3(xdr, args);
5643 +               encode_devicedata3(xdr, args, tag);
5644                 break;
5645         case NF3SOCK:
5646         case NF3FIFO:
5647 -               encode_sattr3(xdr, args->sattr);
5648 +               encode_sattr3(xdr, args->sattr, tag);
5649                 break;
5650         case NF3REG:
5651         case NF3DIR:
5652 @@ -1153,7 +1159,7 @@ static void nfs3_xdr_enc_mknod3args(stru
5653                                     const struct nfs3_mknodargs *args)
5654  {
5655         encode_diropargs3(xdr, args->fh, args->name, args->len);
5656 -       encode_mknoddata3(xdr, args);
5657 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
5658  }
5659  
5660  /*
5661 diff -NurpP --minimal linux-3.1.1/fs/nfs/super.c linux-3.1.1-vs2.3.2/fs/nfs/super.c
5662 --- linux-3.1.1/fs/nfs/super.c  2011-10-24 18:45:27.000000000 +0200
5663 +++ linux-3.1.1-vs2.3.2/fs/nfs/super.c  2011-10-24 18:53:33.000000000 +0200
5664 @@ -53,6 +53,7 @@
5665  #include <linux/nfs_xdr.h>
5666  #include <linux/magic.h>
5667  #include <linux/parser.h>
5668 +#include <linux/vs_tag.h>
5669  
5670  #include <asm/system.h>
5671  #include <asm/uaccess.h>
5672 @@ -87,6 +88,7 @@ enum {
5673         Opt_sharecache, Opt_nosharecache,
5674         Opt_resvport, Opt_noresvport,
5675         Opt_fscache, Opt_nofscache,
5676 +       Opt_tag, Opt_notag,
5677  
5678         /* Mount options that take integer arguments */
5679         Opt_port,
5680 @@ -100,6 +102,7 @@ enum {
5681         Opt_mountvers,
5682         Opt_nfsvers,
5683         Opt_minorversion,
5684 +       Opt_tagid,
5685  
5686         /* Mount options that take string arguments */
5687         Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
5688 @@ -180,6 +183,10 @@ static const match_table_t nfs_mount_opt
5689         { Opt_fscache_uniq, "fsc=%s" },
5690         { Opt_local_lock, "local_lock=%s" },
5691  
5692 +       { Opt_tag, "tag" },
5693 +       { Opt_notag, "notag" },
5694 +       { Opt_tagid, "tagid=%u" },
5695 +
5696         { Opt_err, NULL }
5697  };
5698  
5699 @@ -650,6 +657,7 @@ static void nfs_show_mount_options(struc
5700                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5701                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5702                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5703 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5704                 { 0, NULL, NULL }
5705         };
5706         const struct proc_nfs_info *nfs_infop;
5707 @@ -1198,6 +1206,14 @@ static int nfs_parse_mount_options(char 
5708                         kfree(mnt->fscache_uniq);
5709                         mnt->fscache_uniq = NULL;
5710                         break;
5711 +#ifndef CONFIG_TAGGING_NONE
5712 +               case Opt_tag:
5713 +                       mnt->flags |= NFS_MOUNT_TAGGED;
5714 +                       break;
5715 +               case Opt_notag:
5716 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
5717 +                       break;
5718 +#endif
5719  
5720                 /*
5721                  * options that take numeric values
5722 @@ -1304,6 +1320,12 @@ static int nfs_parse_mount_options(char 
5723                                 goto out_invalid_value;
5724                         mnt->minorversion = option;
5725                         break;
5726 +#ifdef CONFIG_PROPAGATE
5727 +               case Opt_tagid:
5728 +                       /* use args[0] */
5729 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
5730 +                       break;
5731 +#endif
5732  
5733                 /*
5734                  * options that take text values
5735 diff -NurpP --minimal linux-3.1.1/fs/nfsd/auth.c linux-3.1.1-vs2.3.2/fs/nfsd/auth.c
5736 --- linux-3.1.1/fs/nfsd/auth.c  2010-02-25 11:52:05.000000000 +0100
5737 +++ linux-3.1.1-vs2.3.2/fs/nfsd/auth.c  2011-10-24 18:53:33.000000000 +0200
5738 @@ -1,6 +1,7 @@
5739  /* Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> */
5740  
5741  #include <linux/sched.h>
5742 +#include <linux/vs_tag.h>
5743  #include "nfsd.h"
5744  #include "auth.h"
5745  
5746 @@ -36,6 +37,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5747  
5748         new->fsuid = rqstp->rq_cred.cr_uid;
5749         new->fsgid = rqstp->rq_cred.cr_gid;
5750 +       /* FIXME: this desperately needs a tag :)
5751 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5752 +                       */
5753  
5754         rqgi = rqstp->rq_cred.cr_group_info;
5755  
5756 diff -NurpP --minimal linux-3.1.1/fs/nfsd/nfs3xdr.c linux-3.1.1-vs2.3.2/fs/nfsd/nfs3xdr.c
5757 --- linux-3.1.1/fs/nfsd/nfs3xdr.c       2011-07-22 11:18:05.000000000 +0200
5758 +++ linux-3.1.1-vs2.3.2/fs/nfsd/nfs3xdr.c       2011-10-24 18:53:33.000000000 +0200
5759 @@ -7,6 +7,7 @@
5760   */
5761  
5762  #include <linux/namei.h>
5763 +#include <linux/vs_tag.h>
5764  #include "xdr3.h"
5765  #include "auth.h"
5766  
5767 @@ -95,6 +96,8 @@ static __be32 *
5768  decode_sattr3(__be32 *p, struct iattr *iap)
5769  {
5770         u32     tmp;
5771 +       uid_t   uid = 0;
5772 +       gid_t   gid = 0;
5773  
5774         iap->ia_valid = 0;
5775  
5776 @@ -104,12 +107,15 @@ decode_sattr3(__be32 *p, struct iattr *i
5777         }
5778         if (*p++) {
5779                 iap->ia_valid |= ATTR_UID;
5780 -               iap->ia_uid = ntohl(*p++);
5781 +               uid = ntohl(*p++);
5782         }
5783         if (*p++) {
5784                 iap->ia_valid |= ATTR_GID;
5785 -               iap->ia_gid = ntohl(*p++);
5786 +               gid = ntohl(*p++);
5787         }
5788 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5789 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5790 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5791         if (*p++) {
5792                 u64     newsize;
5793  
5794 @@ -165,8 +171,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5795         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5796         *p++ = htonl((u32) stat->mode);
5797         *p++ = htonl((u32) stat->nlink);
5798 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
5799 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
5800 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
5801 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5802 +               stat->uid, stat->tag)));
5803 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
5804 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5805 +               stat->gid, stat->tag)));
5806         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5807                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5808         } else {
5809 diff -NurpP --minimal linux-3.1.1/fs/nfsd/nfs4xdr.c linux-3.1.1-vs2.3.2/fs/nfsd/nfs4xdr.c
5810 --- linux-3.1.1/fs/nfsd/nfs4xdr.c       2011-11-15 16:44:52.000000000 +0100
5811 +++ linux-3.1.1-vs2.3.2/fs/nfsd/nfs4xdr.c       2011-11-15 17:08:44.000000000 +0100
5812 @@ -46,6 +46,7 @@
5813  #include <linux/utsname.h>
5814  #include <linux/pagemap.h>
5815  #include <linux/sunrpc/svcauth_gss.h>
5816 +#include <linux/vs_tag.h>
5817  
5818  #include "idmap.h"
5819  #include "acl.h"
5820 @@ -2177,14 +2178,18 @@ out_acl:
5821                 WRITE32(stat.nlink);
5822         }
5823         if (bmval1 & FATTR4_WORD1_OWNER) {
5824 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
5825 +               status = nfsd4_encode_user(rqstp,
5826 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
5827 +                       stat.uid, stat.tag), &p, &buflen);
5828                 if (status == nfserr_resource)
5829                         goto out_resource;
5830                 if (status)
5831                         goto out;
5832         }
5833         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5834 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
5835 +               status = nfsd4_encode_group(rqstp,
5836 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
5837 +                       stat.gid, stat.tag), &p, &buflen);
5838                 if (status == nfserr_resource)
5839                         goto out_resource;
5840                 if (status)
5841 diff -NurpP --minimal linux-3.1.1/fs/nfsd/nfsxdr.c linux-3.1.1-vs2.3.2/fs/nfsd/nfsxdr.c
5842 --- linux-3.1.1/fs/nfsd/nfsxdr.c        2011-05-22 16:17:53.000000000 +0200
5843 +++ linux-3.1.1-vs2.3.2/fs/nfsd/nfsxdr.c        2011-10-24 18:53:33.000000000 +0200
5844 @@ -6,6 +6,7 @@
5845  
5846  #include "xdr.h"
5847  #include "auth.h"
5848 +#include <linux/vs_tag.h>
5849  
5850  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5851  
5852 @@ -88,6 +89,8 @@ static __be32 *
5853  decode_sattr(__be32 *p, struct iattr *iap)
5854  {
5855         u32     tmp, tmp1;
5856 +       uid_t   uid = 0;
5857 +       gid_t   gid = 0;
5858  
5859         iap->ia_valid = 0;
5860  
5861 @@ -101,12 +104,15 @@ decode_sattr(__be32 *p, struct iattr *ia
5862         }
5863         if ((tmp = ntohl(*p++)) != (u32)-1) {
5864                 iap->ia_valid |= ATTR_UID;
5865 -               iap->ia_uid = tmp;
5866 +               uid = tmp;
5867         }
5868         if ((tmp = ntohl(*p++)) != (u32)-1) {
5869                 iap->ia_valid |= ATTR_GID;
5870 -               iap->ia_gid = tmp;
5871 +               gid = tmp;
5872         }
5873 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5874 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5875 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5876         if ((tmp = ntohl(*p++)) != (u32)-1) {
5877                 iap->ia_valid |= ATTR_SIZE;
5878                 iap->ia_size = tmp;
5879 @@ -151,8 +157,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5880         *p++ = htonl(nfs_ftypes[type >> 12]);
5881         *p++ = htonl((u32) stat->mode);
5882         *p++ = htonl((u32) stat->nlink);
5883 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
5884 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
5885 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
5886 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5887 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
5888 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5889  
5890         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5891                 *p++ = htonl(NFS_MAXPATHLEN);
5892 diff -NurpP --minimal linux-3.1.1/fs/ocfs2/dlmglue.c linux-3.1.1-vs2.3.2/fs/ocfs2/dlmglue.c
5893 --- linux-3.1.1/fs/ocfs2/dlmglue.c      2011-05-22 16:17:53.000000000 +0200
5894 +++ linux-3.1.1-vs2.3.2/fs/ocfs2/dlmglue.c      2011-10-24 18:53:33.000000000 +0200
5895 @@ -2041,6 +2041,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5896         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5897         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
5898         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
5899 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
5900         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
5901         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
5902         lvb->lvb_iatime_packed  =
5903 @@ -2091,6 +2092,7 @@ static void ocfs2_refresh_inode_from_lvb
5904  
5905         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
5906         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
5907 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
5908         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
5909         inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
5910         ocfs2_unpack_timespec(&inode->i_atime,
5911 diff -NurpP --minimal linux-3.1.1/fs/ocfs2/dlmglue.h linux-3.1.1-vs2.3.2/fs/ocfs2/dlmglue.h
5912 --- linux-3.1.1/fs/ocfs2/dlmglue.h      2010-10-21 13:07:50.000000000 +0200
5913 +++ linux-3.1.1-vs2.3.2/fs/ocfs2/dlmglue.h      2011-10-24 18:53:33.000000000 +0200
5914 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5915         __be16       lvb_inlink;
5916         __be32       lvb_iattr;
5917         __be32       lvb_igeneration;
5918 -       __be32       lvb_reserved2;
5919 +       __be16       lvb_itag;
5920 +       __be16       lvb_reserved2;
5921  };
5922  
5923  #define OCFS2_QINFO_LVB_VERSION 1
5924 diff -NurpP --minimal linux-3.1.1/fs/ocfs2/file.c linux-3.1.1-vs2.3.2/fs/ocfs2/file.c
5925 --- linux-3.1.1/fs/ocfs2/file.c 2011-10-24 18:45:27.000000000 +0200
5926 +++ linux-3.1.1-vs2.3.2/fs/ocfs2/file.c 2011-10-24 18:53:33.000000000 +0200
5927 @@ -1123,7 +1123,7 @@ int ocfs2_setattr(struct dentry *dentry,
5928                 attr->ia_valid &= ~ATTR_SIZE;
5929  
5930  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5931 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
5932 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5933         if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5934                 return 0;
5935  
5936 diff -NurpP --minimal linux-3.1.1/fs/ocfs2/inode.c linux-3.1.1-vs2.3.2/fs/ocfs2/inode.c
5937 --- linux-3.1.1/fs/ocfs2/inode.c        2011-05-22 16:17:53.000000000 +0200
5938 +++ linux-3.1.1-vs2.3.2/fs/ocfs2/inode.c        2011-10-24 18:53:33.000000000 +0200
5939 @@ -28,6 +28,7 @@
5940  #include <linux/highmem.h>
5941  #include <linux/pagemap.h>
5942  #include <linux/quotaops.h>
5943 +#include <linux/vs_tag.h>
5944  
5945  #include <asm/byteorder.h>
5946  
5947 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode 
5948  {
5949         unsigned int flags = OCFS2_I(inode)->ip_attr;
5950  
5951 -       inode->i_flags &= ~(S_IMMUTABLE |
5952 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5953                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5954  
5955         if (flags & OCFS2_IMMUTABLE_FL)
5956                 inode->i_flags |= S_IMMUTABLE;
5957 +       if (flags & OCFS2_IXUNLINK_FL)
5958 +               inode->i_flags |= S_IXUNLINK;
5959  
5960         if (flags & OCFS2_SYNC_FL)
5961                 inode->i_flags |= S_SYNC;
5962 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode 
5963                 inode->i_flags |= S_NOATIME;
5964         if (flags & OCFS2_DIRSYNC_FL)
5965                 inode->i_flags |= S_DIRSYNC;
5966 +
5967 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
5968 +
5969 +       if (flags & OCFS2_BARRIER_FL)
5970 +               inode->i_vflags |= V_BARRIER;
5971 +       if (flags & OCFS2_COW_FL)
5972 +               inode->i_vflags |= V_COW;
5973  }
5974  
5975  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5976  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5977  {
5978         unsigned int flags = oi->vfs_inode.i_flags;
5979 +       unsigned int vflags = oi->vfs_inode.i_vflags;
5980 +
5981 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5982 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5983 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5984 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
5985 +
5986 +       if (flags & S_IMMUTABLE)
5987 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5988 +       if (flags & S_IXUNLINK)
5989 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
5990  
5991 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5992 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5993         if (flags & S_SYNC)
5994                 oi->ip_attr |= OCFS2_SYNC_FL;
5995         if (flags & S_APPEND)
5996                 oi->ip_attr |= OCFS2_APPEND_FL;
5997 -       if (flags & S_IMMUTABLE)
5998 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5999         if (flags & S_NOATIME)
6000                 oi->ip_attr |= OCFS2_NOATIME_FL;
6001         if (flags & S_DIRSYNC)
6002                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
6003 +
6004 +       if (vflags & V_BARRIER)
6005 +               oi->ip_attr |= OCFS2_BARRIER_FL;
6006 +       if (vflags & V_COW)
6007 +               oi->ip_attr |= OCFS2_COW_FL;
6008  }
6009  
6010  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
6011 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
6012         struct super_block *sb;
6013         struct ocfs2_super *osb;
6014         int use_plocks = 1;
6015 +       uid_t uid;
6016 +       gid_t gid;
6017  
6018         sb = inode->i_sb;
6019         osb = OCFS2_SB(sb);
6020 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
6021         inode->i_generation = le32_to_cpu(fe->i_generation);
6022         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
6023         inode->i_mode = le16_to_cpu(fe->i_mode);
6024 -       inode->i_uid = le32_to_cpu(fe->i_uid);
6025 -       inode->i_gid = le32_to_cpu(fe->i_gid);
6026 +       uid = le32_to_cpu(fe->i_uid);
6027 +       gid = le32_to_cpu(fe->i_gid);
6028 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6029 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6030 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
6031 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
6032  
6033         /* Fast symlinks will have i_size but no allocated clusters. */
6034         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
6035 diff -NurpP --minimal linux-3.1.1/fs/ocfs2/inode.h linux-3.1.1-vs2.3.2/fs/ocfs2/inode.h
6036 --- linux-3.1.1/fs/ocfs2/inode.h        2011-01-05 21:50:26.000000000 +0100
6037 +++ linux-3.1.1-vs2.3.2/fs/ocfs2/inode.h        2011-10-24 18:53:33.000000000 +0200
6038 @@ -151,6 +151,7 @@ struct buffer_head *ocfs2_bread(struct i
6039  
6040  void ocfs2_set_inode_flags(struct inode *inode);
6041  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
6042 +int ocfs2_sync_flags(struct inode *inode, int, int);
6043  
6044  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
6045  {
6046 diff -NurpP --minimal linux-3.1.1/fs/ocfs2/ioctl.c linux-3.1.1-vs2.3.2/fs/ocfs2/ioctl.c
6047 --- linux-3.1.1/fs/ocfs2/ioctl.c        2011-07-22 11:18:06.000000000 +0200
6048 +++ linux-3.1.1-vs2.3.2/fs/ocfs2/ioctl.c        2011-10-24 18:53:33.000000000 +0200
6049 @@ -78,7 +78,41 @@ static int ocfs2_get_inode_attr(struct i
6050         return status;
6051  }
6052  
6053 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6054 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
6055 +{
6056 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
6057 +       struct buffer_head *bh = NULL;
6058 +       handle_t *handle = NULL;
6059 +       int status;
6060 +
6061 +       status = ocfs2_inode_lock(inode, &bh, 1);
6062 +       if (status < 0) {
6063 +               mlog_errno(status);
6064 +               return status;
6065 +       }
6066 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6067 +       if (IS_ERR(handle)) {
6068 +               status = PTR_ERR(handle);
6069 +               mlog_errno(status);
6070 +               goto bail_unlock;
6071 +       }
6072 +
6073 +       inode->i_flags = flags;
6074 +       inode->i_vflags = vflags;
6075 +       ocfs2_get_inode_flags(OCFS2_I(inode));
6076 +
6077 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
6078 +       if (status < 0)
6079 +               mlog_errno(status);
6080 +
6081 +       ocfs2_commit_trans(osb, handle);
6082 +bail_unlock:
6083 +       ocfs2_inode_unlock(inode, 1);
6084 +       brelse(bh);
6085 +       return status;
6086 +}
6087 +
6088 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6089                                 unsigned mask)
6090  {
6091         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
6092 @@ -103,6 +137,11 @@ static int ocfs2_set_inode_attr(struct i
6093         if (!S_ISDIR(inode->i_mode))
6094                 flags &= ~OCFS2_DIRSYNC_FL;
6095  
6096 +       if (IS_BARRIER(inode)) {
6097 +               vxwprintk_task(1, "messing with the barrier.");
6098 +               goto bail_unlock;
6099 +       }
6100 +
6101         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6102         if (IS_ERR(handle)) {
6103                 status = PTR_ERR(handle);
6104 @@ -880,6 +919,7 @@ bail:
6105         return status;
6106  }
6107  
6108 +
6109  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
6110  {
6111         struct inode *inode = filp->f_path.dentry->d_inode;
6112 diff -NurpP --minimal linux-3.1.1/fs/ocfs2/namei.c linux-3.1.1-vs2.3.2/fs/ocfs2/namei.c
6113 --- linux-3.1.1/fs/ocfs2/namei.c        2011-10-24 18:45:27.000000000 +0200
6114 +++ linux-3.1.1-vs2.3.2/fs/ocfs2/namei.c        2011-10-24 18:53:33.000000000 +0200
6115 @@ -41,6 +41,7 @@
6116  #include <linux/slab.h>
6117  #include <linux/highmem.h>
6118  #include <linux/quotaops.h>
6119 +#include <linux/vs_tag.h>
6120  
6121  #include <cluster/masklog.h>
6122  
6123 @@ -477,6 +478,7 @@ static int __ocfs2_mknod_locked(struct i
6124         struct ocfs2_dinode *fe = NULL;
6125         struct ocfs2_extent_list *fel;
6126         u16 feat;
6127 +       tag_t tag;
6128  
6129         *new_fe_bh = NULL;
6130  
6131 @@ -514,8 +516,11 @@ static int __ocfs2_mknod_locked(struct i
6132         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
6133         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
6134         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
6135 -       fe->i_uid = cpu_to_le32(inode->i_uid);
6136 -       fe->i_gid = cpu_to_le32(inode->i_gid);
6137 +
6138 +       tag = dx_current_fstag(osb->sb);
6139 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
6140 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
6141 +       inode->i_tag = tag;
6142         fe->i_mode = cpu_to_le16(inode->i_mode);
6143         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
6144                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
6145 diff -NurpP --minimal linux-3.1.1/fs/ocfs2/ocfs2.h linux-3.1.1-vs2.3.2/fs/ocfs2/ocfs2.h
6146 --- linux-3.1.1/fs/ocfs2/ocfs2.h        2011-05-22 16:17:53.000000000 +0200
6147 +++ linux-3.1.1-vs2.3.2/fs/ocfs2/ocfs2.h        2011-10-24 18:53:33.000000000 +0200
6148 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
6149                                                      writes */
6150         OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
6151         OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
6152 +       OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
6153  };
6154  
6155  #define OCFS2_OSB_SOFT_RO                      0x0001
6156 diff -NurpP --minimal linux-3.1.1/fs/ocfs2/ocfs2_fs.h linux-3.1.1-vs2.3.2/fs/ocfs2/ocfs2_fs.h
6157 --- linux-3.1.1/fs/ocfs2/ocfs2_fs.h     2011-05-22 16:17:53.000000000 +0200
6158 +++ linux-3.1.1-vs2.3.2/fs/ocfs2/ocfs2_fs.h     2011-10-24 18:53:33.000000000 +0200
6159 @@ -266,6 +266,11 @@
6160  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
6161  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
6162  
6163 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
6164 +
6165 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
6166 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
6167 +
6168  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
6169  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
6170  
6171 diff -NurpP --minimal linux-3.1.1/fs/ocfs2/super.c linux-3.1.1-vs2.3.2/fs/ocfs2/super.c
6172 --- linux-3.1.1/fs/ocfs2/super.c        2011-07-22 11:18:06.000000000 +0200
6173 +++ linux-3.1.1-vs2.3.2/fs/ocfs2/super.c        2011-10-24 18:53:33.000000000 +0200
6174 @@ -184,6 +184,7 @@ enum {
6175         Opt_coherency_full,
6176         Opt_resv_level,
6177         Opt_dir_resv_level,
6178 +       Opt_tag, Opt_notag, Opt_tagid,
6179         Opt_err,
6180  };
6181  
6182 @@ -215,6 +216,9 @@ static const match_table_t tokens = {
6183         {Opt_coherency_full, "coherency=full"},
6184         {Opt_resv_level, "resv_level=%u"},
6185         {Opt_dir_resv_level, "dir_resv_level=%u"},
6186 +       {Opt_tag, "tag"},
6187 +       {Opt_notag, "notag"},
6188 +       {Opt_tagid, "tagid=%u"},
6189         {Opt_err, NULL}
6190  };
6191  
6192 @@ -662,6 +666,13 @@ static int ocfs2_remount(struct super_bl
6193                 goto out;
6194         }
6195  
6196 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
6197 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
6198 +               ret = -EINVAL;
6199 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
6200 +               goto out;
6201 +       }
6202 +
6203         /* We're going to/from readonly mode. */
6204         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
6205                 /* Disable quota accounting before remounting RO */
6206 @@ -1177,6 +1188,9 @@ static int ocfs2_fill_super(struct super
6207  
6208         ocfs2_complete_mount_recovery(osb);
6209  
6210 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
6211 +               sb->s_flags |= MS_TAGGED;
6212 +
6213         if (ocfs2_mount_local(osb))
6214                 snprintf(nodestr, sizeof(nodestr), "local");
6215         else
6216 @@ -1506,6 +1520,20 @@ static int ocfs2_parse_options(struct su
6217                             option < OCFS2_MAX_RESV_LEVEL)
6218                                 mopt->dir_resv_level = option;
6219                         break;
6220 +#ifndef CONFIG_TAGGING_NONE
6221 +               case Opt_tag:
6222 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6223 +                       break;
6224 +               case Opt_notag:
6225 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
6226 +                       break;
6227 +#endif
6228 +#ifdef CONFIG_PROPAGATE
6229 +               case Opt_tagid:
6230 +                       /* use args[0] */
6231 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6232 +                       break;
6233 +#endif
6234                 default:
6235                         mlog(ML_ERROR,
6236                              "Unrecognized mount option \"%s\" "
6237 diff -NurpP --minimal linux-3.1.1/fs/open.c linux-3.1.1-vs2.3.2/fs/open.c
6238 --- linux-3.1.1/fs/open.c       2011-10-24 18:45:27.000000000 +0200
6239 +++ linux-3.1.1-vs2.3.2/fs/open.c       2011-10-30 02:06:37.000000000 +0100
6240 @@ -30,6 +30,11 @@
6241  #include <linux/fs_struct.h>
6242  #include <linux/ima.h>
6243  #include <linux/dnotify.h>
6244 +#include <linux/vs_base.h>
6245 +#include <linux/vs_limit.h>
6246 +#include <linux/vs_tag.h>
6247 +#include <linux/vs_cowbl.h>
6248 +#include <linux/vserver/dlimit.h>
6249  
6250  #include "internal.h"
6251  
6252 @@ -74,6 +79,12 @@ static long do_sys_truncate(const char _
6253         error = user_path(pathname, &path);
6254         if (error)
6255                 goto out;
6256 +
6257 +#ifdef CONFIG_VSERVER_COWBL
6258 +       error = cow_check_and_break(&path);
6259 +       if (error)
6260 +               goto dput_and_out;
6261 +#endif
6262         inode = path.dentry->d_inode;
6263  
6264         /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
6265 @@ -489,6 +500,10 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6266  
6267         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
6268         if (!error) {
6269 +#ifdef CONFIG_VSERVER_COWBL
6270 +               error = cow_check_and_break(&path);
6271 +               if (!error)
6272 +#endif
6273                 error = chmod_common(&path, mode);
6274                 path_put(&path);
6275         }
6276 @@ -509,11 +524,11 @@ static int chown_common(struct path *pat
6277         newattrs.ia_valid =  ATTR_CTIME;
6278         if (user != (uid_t) -1) {
6279                 newattrs.ia_valid |= ATTR_UID;
6280 -               newattrs.ia_uid = user;
6281 +               newattrs.ia_uid = dx_map_uid(user);
6282         }
6283         if (group != (gid_t) -1) {
6284                 newattrs.ia_valid |= ATTR_GID;
6285 -               newattrs.ia_gid = group;
6286 +               newattrs.ia_gid = dx_map_gid(group);
6287         }
6288         if (!S_ISDIR(inode->i_mode))
6289                 newattrs.ia_valid |=
6290 @@ -538,6 +553,10 @@ SYSCALL_DEFINE3(chown, const char __user
6291         error = mnt_want_write(path.mnt);
6292         if (error)
6293                 goto out_release;
6294 +#ifdef CONFIG_VSERVER_COWBL
6295 +       error = cow_check_and_break(&path);
6296 +       if (!error)
6297 +#endif
6298         error = chown_common(&path, user, group);
6299         mnt_drop_write(path.mnt);
6300  out_release:
6301 @@ -565,6 +584,10 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
6302         error = mnt_want_write(path.mnt);
6303         if (error)
6304                 goto out_release;
6305 +#ifdef CONFIG_VSERVER_COWBL
6306 +       error = cow_check_and_break(&path);
6307 +       if (!error)
6308 +#endif
6309         error = chown_common(&path, user, group);
6310         mnt_drop_write(path.mnt);
6311  out_release:
6312 @@ -584,6 +607,10 @@ SYSCALL_DEFINE3(lchown, const char __use
6313         error = mnt_want_write(path.mnt);
6314         if (error)
6315                 goto out_release;
6316 +#ifdef CONFIG_VSERVER_COWBL
6317 +       error = cow_check_and_break(&path);
6318 +       if (!error)
6319 +#endif
6320         error = chown_common(&path, user, group);
6321         mnt_drop_write(path.mnt);
6322  out_release:
6323 @@ -835,6 +862,7 @@ static void __put_unused_fd(struct files
6324         __FD_CLR(fd, fdt->open_fds);
6325         if (fd < files->next_fd)
6326                 files->next_fd = fd;
6327 +       vx_openfd_dec(fd);
6328  }
6329  
6330  void put_unused_fd(unsigned int fd)
6331 diff -NurpP --minimal linux-3.1.1/fs/proc/array.c linux-3.1.1-vs2.3.2/fs/proc/array.c
6332 --- linux-3.1.1/fs/proc/array.c 2011-10-24 18:45:27.000000000 +0200
6333 +++ linux-3.1.1-vs2.3.2/fs/proc/array.c 2011-10-24 18:53:33.000000000 +0200
6334 @@ -81,6 +81,8 @@
6335  #include <linux/pid_namespace.h>
6336  #include <linux/ptrace.h>
6337  #include <linux/tracehook.h>
6338 +#include <linux/vs_context.h>
6339 +#include <linux/vs_network.h>
6340  
6341  #include <asm/pgtable.h>
6342  #include <asm/processor.h>
6343 @@ -170,6 +172,9 @@ static inline void task_state(struct seq
6344         rcu_read_lock();
6345         ppid = pid_alive(p) ?
6346                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6347 +       if (unlikely(vx_current_initpid(p->pid)))
6348 +               ppid = 0;
6349 +
6350         tpid = 0;
6351         if (pid_alive(p)) {
6352                 struct task_struct *tracer = ptrace_parent(p);
6353 @@ -287,7 +292,7 @@ static inline void task_sig(struct seq_f
6354  }
6355  
6356  static void render_cap_t(struct seq_file *m, const char *header,
6357 -                       kernel_cap_t *a)
6358 +                       struct vx_info *vxi, kernel_cap_t *a)
6359  {
6360         unsigned __capi;
6361  
6362 @@ -312,10 +317,11 @@ static inline void task_cap(struct seq_f
6363         cap_bset        = cred->cap_bset;
6364         rcu_read_unlock();
6365  
6366 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6367 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6368 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6369 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6370 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6371 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6372 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6373 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6374 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6375  }
6376  
6377  static inline void task_context_switch_counts(struct seq_file *m,
6378 @@ -337,6 +343,42 @@ static void task_cpus_allowed(struct seq
6379         seq_putc(m, '\n');
6380  }
6381  
6382 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6383 +                       struct pid *pid, struct task_struct *task)
6384 +{
6385 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6386 +                       "Count:\t%u\n"
6387 +                       "uts:\t%p(%c)\n"
6388 +                       "ipc:\t%p(%c)\n"
6389 +                       "mnt:\t%p(%c)\n"
6390 +                       "pid:\t%p(%c)\n"
6391 +                       "net:\t%p(%c)\n",
6392 +                       task->nsproxy,
6393 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6394 +                       atomic_read(&task->nsproxy->count),
6395 +                       task->nsproxy->uts_ns,
6396 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6397 +                       task->nsproxy->ipc_ns,
6398 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6399 +                       task->nsproxy->mnt_ns,
6400 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6401 +                       task->nsproxy->pid_ns,
6402 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6403 +                       task->nsproxy->net_ns,
6404 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6405 +       return 0;
6406 +}
6407 +
6408 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6409 +{
6410 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6411 +               return;
6412 +
6413 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6414 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6415 +}
6416 +
6417 +
6418  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6419                         struct pid *pid, struct task_struct *task)
6420  {
6421 @@ -353,6 +395,7 @@ int proc_pid_status(struct seq_file *m, 
6422         task_cap(m, task);
6423         task_cpus_allowed(m, task);
6424         cpuset_task_status_allowed(m, task);
6425 +       task_vs_id(m, task);
6426         task_context_switch_counts(m, task);
6427         return 0;
6428  }
6429 @@ -462,6 +505,17 @@ static int do_task_stat(struct seq_file 
6430         /* convert nsec -> ticks */
6431         start_time = nsec_to_clock_t(start_time);
6432  
6433 +       /* fixup start time for virt uptime */
6434 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6435 +               unsigned long long bias =
6436 +                       current->vx_info->cvirt.bias_clock;
6437 +
6438 +               if (start_time > bias)
6439 +                       start_time -= bias;
6440 +               else
6441 +                       start_time = 0;
6442 +       }
6443 +
6444         seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \
6445  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
6446  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
6447 diff -NurpP --minimal linux-3.1.1/fs/proc/base.c linux-3.1.1-vs2.3.2/fs/proc/base.c
6448 --- linux-3.1.1/fs/proc/base.c  2011-10-24 18:45:27.000000000 +0200
6449 +++ linux-3.1.1-vs2.3.2/fs/proc/base.c  2011-10-24 18:53:33.000000000 +0200
6450 @@ -83,6 +83,8 @@
6451  #include <linux/pid_namespace.h>
6452  #include <linux/fs_struct.h>
6453  #include <linux/slab.h>
6454 +#include <linux/vs_context.h>
6455 +#include <linux/vs_network.h>
6456  #ifdef CONFIG_HARDWALL
6457  #include <asm/hardwall.h>
6458  #endif
6459 @@ -1102,11 +1104,16 @@ static ssize_t oom_adjust_write(struct f
6460                 goto err_task_lock;
6461         }
6462  
6463 -       if (oom_adjust < task->signal->oom_adj && !capable(CAP_SYS_RESOURCE)) {
6464 +       if (oom_adjust < task->signal->oom_adj &&
6465 +               !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6466                 err = -EACCES;
6467                 goto err_sighand;
6468         }
6469  
6470 +       /* prevent guest processes from circumventing the oom killer */
6471 +       if (vx_current_xid() && (oom_adjust == OOM_DISABLE))
6472 +               oom_adjust = OOM_ADJUST_MIN;
6473 +
6474         if (oom_adjust != task->signal->oom_adj) {
6475                 if (oom_adjust == OOM_DISABLE)
6476                         atomic_inc(&task->mm->oom_disable_count);
6477 @@ -1274,7 +1281,7 @@ static ssize_t proc_loginuid_write(struc
6478         ssize_t length;
6479         uid_t loginuid;
6480  
6481 -       if (!capable(CAP_AUDIT_CONTROL))
6482 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
6483                 return -EPERM;
6484  
6485         rcu_read_lock();
6486 @@ -1721,6 +1728,8 @@ struct inode *proc_pid_make_inode(struct
6487                 inode->i_gid = cred->egid;
6488                 rcu_read_unlock();
6489         }
6490 +       /* procfs is xid tagged */
6491 +       inode->i_tag = (tag_t)vx_task_xid(task);
6492         security_task_to_inode(task, inode);
6493  
6494  out:
6495 @@ -1757,6 +1766,8 @@ int pid_getattr(struct vfsmount *mnt, st
6496  
6497  /* dentry stuff */
6498  
6499 +static unsigned name_to_int(struct dentry *dentry);
6500 +
6501  /*
6502   *     Exceptional case: normally we are not allowed to unhash a busy
6503   * directory. In this case, however, we can do it - no aliasing problems
6504 @@ -1785,6 +1796,12 @@ int pid_revalidate(struct dentry *dentry
6505         task = get_proc_task(inode);
6506  
6507         if (task) {
6508 +               unsigned pid = name_to_int(dentry);
6509 +
6510 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6511 +                       put_task_struct(task);
6512 +                       goto drop;
6513 +               }
6514                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6515                     task_dumpable(task)) {
6516                         rcu_read_lock();
6517 @@ -1801,6 +1818,7 @@ int pid_revalidate(struct dentry *dentry
6518                 put_task_struct(task);
6519                 return 1;
6520         }
6521 +drop:
6522         d_drop(dentry);
6523         return 0;
6524  }
6525 @@ -2290,6 +2308,13 @@ static struct dentry *proc_pident_lookup
6526         if (!task)
6527                 goto out_no_task;
6528  
6529 +       /* TODO: maybe we can come up with a generic approach? */
6530 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6531 +               (dentry->d_name.len == 5) &&
6532 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6533 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6534 +               goto out;
6535 +
6536         /*
6537          * Yes, it does not scale. And it should not. Don't add
6538          * new entries into /proc/<tgid>/ without very good reasons.
6539 @@ -2675,7 +2700,7 @@ out_iput:
6540  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
6541  {
6542         struct dentry *error;
6543 -       struct task_struct *task = get_proc_task(dir);
6544 +       struct task_struct *task = get_proc_task_real(dir);
6545         const struct pid_entry *p, *last;
6546  
6547         error = ERR_PTR(-ENOENT);
6548 @@ -2782,6 +2807,9 @@ static int proc_pid_personality(struct s
6549  static const struct file_operations proc_task_operations;
6550  static const struct inode_operations proc_task_inode_operations;
6551  
6552 +extern int proc_pid_vx_info(struct task_struct *, char *);
6553 +extern int proc_pid_nx_info(struct task_struct *, char *);
6554 +
6555  static const struct pid_entry tgid_base_stuff[] = {
6556         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6557         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6558 @@ -2845,6 +2873,8 @@ static const struct pid_entry tgid_base_
6559  #ifdef CONFIG_CGROUPS
6560         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6561  #endif
6562 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6563 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6564         INF("oom_score",  S_IRUGO, proc_oom_score),
6565         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
6566         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6567 @@ -2864,6 +2894,7 @@ static const struct pid_entry tgid_base_
6568  #ifdef CONFIG_HARDWALL
6569         INF("hardwall",   S_IRUGO, proc_pid_hardwall),
6570  #endif
6571 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6572  };
6573  
6574  static int proc_tgid_base_readdir(struct file * filp,
6575 @@ -3056,7 +3087,7 @@ retry:
6576         iter.task = NULL;
6577         pid = find_ge_pid(iter.tgid, ns);
6578         if (pid) {
6579 -               iter.tgid = pid_nr_ns(pid, ns);
6580 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6581                 iter.task = pid_task(pid, PIDTYPE_PID);
6582                 /* What we to know is if the pid we have find is the
6583                  * pid of a thread_group_leader.  Testing for task
6584 @@ -3086,7 +3117,7 @@ static int proc_pid_fill_cache(struct fi
6585         struct tgid_iter iter)
6586  {
6587         char name[PROC_NUMBUF];
6588 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6589 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6590         return proc_fill_cache(filp, dirent, filldir, name, len,
6591                                 proc_pid_instantiate, iter.task, NULL);
6592  }
6593 @@ -3103,7 +3134,7 @@ int proc_pid_readdir(struct file * filp,
6594                 goto out_no_task;
6595         nr = filp->f_pos - FIRST_PROCESS_ENTRY;
6596  
6597 -       reaper = get_proc_task(filp->f_path.dentry->d_inode);
6598 +       reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
6599         if (!reaper)
6600                 goto out_no_task;
6601  
6602 @@ -3120,6 +3151,8 @@ int proc_pid_readdir(struct file * filp,
6603              iter.task;
6604              iter.tgid += 1, iter = next_tgid(ns, iter)) {
6605                 filp->f_pos = iter.tgid + TGID_OFFSET;
6606 +               if (!vx_proc_task_visible(iter.task))
6607 +                       continue;
6608                 if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
6609                         put_task_struct(iter.task);
6610                         goto out;
6611 @@ -3273,6 +3306,8 @@ static struct dentry *proc_task_lookup(s
6612         tid = name_to_int(dentry);
6613         if (tid == ~0U)
6614                 goto out;
6615 +       if (vx_current_initpid(tid))
6616 +               goto out;
6617  
6618         ns = dentry->d_sb->s_fs_info;
6619         rcu_read_lock();
6620 diff -NurpP --minimal linux-3.1.1/fs/proc/generic.c linux-3.1.1-vs2.3.2/fs/proc/generic.c
6621 --- linux-3.1.1/fs/proc/generic.c       2011-10-24 18:45:27.000000000 +0200
6622 +++ linux-3.1.1-vs2.3.2/fs/proc/generic.c       2011-10-24 18:53:33.000000000 +0200
6623 @@ -22,6 +22,7 @@
6624  #include <linux/bitops.h>
6625  #include <linux/spinlock.h>
6626  #include <linux/completion.h>
6627 +#include <linux/vserver/inode.h>
6628  #include <asm/uaccess.h>
6629  
6630  #include "internal.h"
6631 @@ -424,11 +425,15 @@ struct dentry *proc_lookup_de(struct pro
6632         for (de = de->subdir; de ; de = de->next) {
6633                 if (de->namelen != dentry->d_name.len)
6634                         continue;
6635 +               if (!vx_hide_check(0, de->vx_flags))
6636 +                       continue;
6637                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6638                         pde_get(de);
6639                         spin_unlock(&proc_subdir_lock);
6640                         error = -EINVAL;
6641                         inode = proc_get_inode(dir->i_sb, de);
6642 +                       /* generic proc entries belong to the host */
6643 +                       inode->i_tag = 0;
6644                         goto out_unlock;
6645                 }
6646         }
6647 @@ -506,6 +511,8 @@ int proc_readdir_de(struct proc_dir_entr
6648  
6649                                 /* filldir passes info to user space */
6650                                 pde_get(de);
6651 +                               if (!vx_hide_check(0, de->vx_flags))
6652 +                                       goto skip;
6653                                 spin_unlock(&proc_subdir_lock);
6654                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6655                                             de->low_ino, de->mode >> 12) < 0) {
6656 @@ -513,6 +520,7 @@ int proc_readdir_de(struct proc_dir_entr
6657                                         goto out;
6658                                 }
6659                                 spin_lock(&proc_subdir_lock);
6660 +                       skip:
6661                                 filp->f_pos++;
6662                                 next = de->next;
6663                                 pde_put(de);
6664 @@ -626,6 +634,7 @@ static struct proc_dir_entry *__proc_cre
6665         ent->nlink = nlink;
6666         atomic_set(&ent->count, 1);
6667         ent->pde_users = 0;
6668 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6669         spin_lock_init(&ent->pde_unload_lock);
6670         ent->pde_unload_completion = NULL;
6671         INIT_LIST_HEAD(&ent->pde_openers);
6672 @@ -649,7 +658,8 @@ struct proc_dir_entry *proc_symlink(cons
6673                                 kfree(ent->data);
6674                                 kfree(ent);
6675                                 ent = NULL;
6676 -                       }
6677 +                       } else
6678 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6679                 } else {
6680                         kfree(ent);
6681                         ent = NULL;
6682 diff -NurpP --minimal linux-3.1.1/fs/proc/inode.c linux-3.1.1-vs2.3.2/fs/proc/inode.c
6683 --- linux-3.1.1/fs/proc/inode.c 2011-10-24 18:45:27.000000000 +0200
6684 +++ linux-3.1.1-vs2.3.2/fs/proc/inode.c 2011-10-24 18:53:33.000000000 +0200
6685 @@ -442,6 +442,8 @@ struct inode *proc_get_inode(struct supe
6686                         inode->i_uid = de->uid;
6687                         inode->i_gid = de->gid;
6688                 }
6689 +               if (de->vx_flags)
6690 +                       PROC_I(inode)->vx_flags = de->vx_flags;
6691                 if (de->size)
6692                         inode->i_size = de->size;
6693                 if (de->nlink)
6694 diff -NurpP --minimal linux-3.1.1/fs/proc/internal.h linux-3.1.1-vs2.3.2/fs/proc/internal.h
6695 --- linux-3.1.1/fs/proc/internal.h      2011-07-22 11:18:06.000000000 +0200
6696 +++ linux-3.1.1-vs2.3.2/fs/proc/internal.h      2011-10-24 18:53:33.000000000 +0200
6697 @@ -10,6 +10,7 @@
6698   */
6699  
6700  #include <linux/proc_fs.h>
6701 +#include <linux/vs_pid.h>
6702  
6703  extern struct proc_dir_entry proc_root;
6704  #ifdef CONFIG_PROC_SYSCTL
6705 @@ -51,6 +52,9 @@ extern int proc_pid_status(struct seq_fi
6706                                 struct pid *pid, struct task_struct *task);
6707  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
6708                                 struct pid *pid, struct task_struct *task);
6709 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6710 +                               struct pid *pid, struct task_struct *task);
6711 +
6712  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
6713  
6714  extern const struct file_operations proc_maps_operations;
6715 @@ -76,11 +80,16 @@ static inline struct pid *proc_pid(struc
6716         return PROC_I(inode)->pid;
6717  }
6718  
6719 -static inline struct task_struct *get_proc_task(struct inode *inode)
6720 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6721  {
6722         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6723  }
6724  
6725 +static inline struct task_struct *get_proc_task(struct inode *inode)
6726 +{
6727 +       return vx_get_proc_task(inode, proc_pid(inode));
6728 +}
6729 +
6730  static inline int proc_fd(struct inode *inode)
6731  {
6732         return PROC_I(inode)->fd;
6733 diff -NurpP --minimal linux-3.1.1/fs/proc/loadavg.c linux-3.1.1-vs2.3.2/fs/proc/loadavg.c
6734 --- linux-3.1.1/fs/proc/loadavg.c       2009-09-10 15:26:23.000000000 +0200
6735 +++ linux-3.1.1-vs2.3.2/fs/proc/loadavg.c       2011-10-24 18:53:33.000000000 +0200
6736 @@ -12,15 +12,27 @@
6737  
6738  static int loadavg_proc_show(struct seq_file *m, void *v)
6739  {
6740 +       unsigned long running;
6741 +       unsigned int threads;
6742         unsigned long avnrun[3];
6743  
6744         get_avenrun(avnrun, FIXED_1/200, 0);
6745  
6746 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
6747 +               struct vx_info *vxi = current_vx_info();
6748 +
6749 +               running = atomic_read(&vxi->cvirt.nr_running);
6750 +               threads = atomic_read(&vxi->cvirt.nr_threads);
6751 +       } else {
6752 +               running = nr_running();
6753 +               threads = nr_threads;
6754 +       }
6755 +
6756         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6757                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6758                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6759                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6760 -               nr_running(), nr_threads,
6761 +               running, threads,
6762                 task_active_pid_ns(current)->last_pid);
6763         return 0;
6764  }
6765 diff -NurpP --minimal linux-3.1.1/fs/proc/meminfo.c linux-3.1.1-vs2.3.2/fs/proc/meminfo.c
6766 --- linux-3.1.1/fs/proc/meminfo.c       2011-10-24 18:45:27.000000000 +0200
6767 +++ linux-3.1.1-vs2.3.2/fs/proc/meminfo.c       2011-10-24 18:53:33.000000000 +0200
6768 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
6769         allowed = ((totalram_pages - hugetlb_total_pages())
6770                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
6771  
6772 -       cached = global_page_state(NR_FILE_PAGES) -
6773 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
6774 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6775                         total_swapcache_pages - i.bufferram;
6776         if (cached < 0)
6777                 cached = 0;
6778 diff -NurpP --minimal linux-3.1.1/fs/proc/root.c linux-3.1.1-vs2.3.2/fs/proc/root.c
6779 --- linux-3.1.1/fs/proc/root.c  2011-10-24 18:45:27.000000000 +0200
6780 +++ linux-3.1.1-vs2.3.2/fs/proc/root.c  2011-10-24 18:53:33.000000000 +0200
6781 @@ -18,9 +18,14 @@
6782  #include <linux/bitops.h>
6783  #include <linux/mount.h>
6784  #include <linux/pid_namespace.h>
6785 +#include <linux/vserver/inode.h>
6786  
6787  #include "internal.h"
6788  
6789 +struct proc_dir_entry *proc_virtual;
6790 +
6791 +extern void proc_vx_init(void);
6792 +
6793  static int proc_test_super(struct super_block *sb, void *data)
6794  {
6795         return sb->s_fs_info == data;
6796 @@ -125,6 +130,7 @@ void __init proc_root_init(void)
6797  #endif
6798         proc_mkdir("bus", NULL);
6799         proc_sys_init();
6800 +       proc_vx_init();
6801  }
6802  
6803  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6804 @@ -192,6 +198,7 @@ struct proc_dir_entry proc_root = {
6805         .proc_iops      = &proc_root_inode_operations, 
6806         .proc_fops      = &proc_root_operations,
6807         .parent         = &proc_root,
6808 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
6809         .name           = "/proc",
6810  };
6811  
6812 diff -NurpP --minimal linux-3.1.1/fs/proc/uptime.c linux-3.1.1-vs2.3.2/fs/proc/uptime.c
6813 --- linux-3.1.1/fs/proc/uptime.c        2009-12-03 20:02:53.000000000 +0100
6814 +++ linux-3.1.1-vs2.3.2/fs/proc/uptime.c        2011-10-24 18:53:33.000000000 +0200
6815 @@ -4,22 +4,22 @@
6816  #include <linux/sched.h>
6817  #include <linux/seq_file.h>
6818  #include <linux/time.h>
6819 -#include <linux/kernel_stat.h>
6820 +#include <linux/vserver/cvirt.h>
6821  #include <asm/cputime.h>
6822  
6823  static int uptime_proc_show(struct seq_file *m, void *v)
6824  {
6825         struct timespec uptime;
6826         struct timespec idle;
6827 -       int i;
6828 -       cputime_t idletime = cputime_zero;
6829 -
6830 -       for_each_possible_cpu(i)
6831 -               idletime = cputime64_add(idletime, kstat_cpu(i).cpustat.idle);
6832 +       cputime_t idletime = cputime_add(init_task.utime, init_task.stime);
6833  
6834         do_posix_clock_monotonic_gettime(&uptime);
6835         monotonic_to_bootbased(&uptime);
6836         cputime_to_timespec(idletime, &idle);
6837 +
6838 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6839 +               vx_vsi_uptime(&uptime, &idle);
6840 +
6841         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6842                         (unsigned long) uptime.tv_sec,
6843                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6844 diff -NurpP --minimal linux-3.1.1/fs/quota/dquot.c linux-3.1.1-vs2.3.2/fs/quota/dquot.c
6845 --- linux-3.1.1/fs/quota/dquot.c        2011-07-22 11:18:06.000000000 +0200
6846 +++ linux-3.1.1-vs2.3.2/fs/quota/dquot.c        2011-10-24 18:53:33.000000000 +0200
6847 @@ -1548,6 +1548,9 @@ int __dquot_alloc_space(struct inode *in
6848         int reserve = flags & DQUOT_SPACE_RESERVE;
6849         int nofail = flags & DQUOT_SPACE_NOFAIL;
6850  
6851 +       if ((ret = dl_alloc_space(inode, number)))
6852 +               return ret;
6853 +
6854         /*
6855          * First test before acquiring mutex - solves deadlocks when we
6856          * re-enter the quota code and are already holding the mutex
6857 @@ -1602,6 +1605,9 @@ int dquot_alloc_inode(const struct inode
6858         int cnt, ret = 0;
6859         char warntype[MAXQUOTAS];
6860  
6861 +       if ((ret = dl_alloc_inode(inode)))
6862 +               return ret;
6863 +
6864         /* First test before acquiring mutex - solves deadlocks when we
6865           * re-enter the quota code and are already holding the mutex */
6866         if (!dquot_active(inode))
6867 @@ -1672,6 +1678,8 @@ void __dquot_free_space(struct inode *in
6868         char warntype[MAXQUOTAS];
6869         int reserve = flags & DQUOT_SPACE_RESERVE;
6870  
6871 +       dl_free_space(inode, number);
6872 +
6873         /* First test before acquiring mutex - solves deadlocks when we
6874           * re-enter the quota code and are already holding the mutex */
6875         if (!dquot_active(inode)) {
6876 @@ -1710,6 +1718,8 @@ void dquot_free_inode(const struct inode
6877         unsigned int cnt;
6878         char warntype[MAXQUOTAS];
6879  
6880 +       dl_free_inode(inode);
6881 +
6882         /* First test before acquiring mutex - solves deadlocks when we
6883           * re-enter the quota code and are already holding the mutex */
6884         if (!dquot_active(inode))
6885 diff -NurpP --minimal linux-3.1.1/fs/quota/quota.c linux-3.1.1-vs2.3.2/fs/quota/quota.c
6886 --- linux-3.1.1/fs/quota/quota.c        2011-10-24 18:45:27.000000000 +0200
6887 +++ linux-3.1.1-vs2.3.2/fs/quota/quota.c        2011-10-24 18:53:33.000000000 +0200
6888 @@ -8,6 +8,7 @@
6889  #include <linux/fs.h>
6890  #include <linux/namei.h>
6891  #include <linux/slab.h>
6892 +#include <linux/vs_context.h>
6893  #include <asm/current.h>
6894  #include <asm/uaccess.h>
6895  #include <linux/kernel.h>
6896 @@ -38,7 +39,7 @@ static int check_quotactl_permission(str
6897                         break;
6898                 /*FALLTHROUGH*/
6899         default:
6900 -               if (!capable(CAP_SYS_ADMIN))
6901 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6902                         return -EPERM;
6903         }
6904  
6905 @@ -293,6 +294,46 @@ static int do_quotactl(struct super_bloc
6906         }
6907  }
6908  
6909 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6910 +
6911 +#include <linux/vroot.h>
6912 +#include <linux/major.h>
6913 +#include <linux/module.h>
6914 +#include <linux/kallsyms.h>
6915 +#include <linux/vserver/debug.h>
6916 +
6917 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6918 +
6919 +static DEFINE_SPINLOCK(vroot_grb_lock);
6920 +
6921 +int register_vroot_grb(vroot_grb_func *func) {
6922 +       int ret = -EBUSY;
6923 +
6924 +       spin_lock(&vroot_grb_lock);
6925 +       if (!vroot_get_real_bdev) {
6926 +               vroot_get_real_bdev = func;
6927 +               ret = 0;
6928 +       }
6929 +       spin_unlock(&vroot_grb_lock);
6930 +       return ret;
6931 +}
6932 +EXPORT_SYMBOL(register_vroot_grb);
6933 +
6934 +int unregister_vroot_grb(vroot_grb_func *func) {
6935 +       int ret = -EINVAL;
6936 +
6937 +       spin_lock(&vroot_grb_lock);
6938 +       if (vroot_get_real_bdev) {
6939 +               vroot_get_real_bdev = NULL;
6940 +               ret = 0;
6941 +       }
6942 +       spin_unlock(&vroot_grb_lock);
6943 +       return ret;
6944 +}
6945 +EXPORT_SYMBOL(unregister_vroot_grb);
6946 +
6947 +#endif
6948 +
6949  /*
6950   * look up a superblock on which quota ops will be performed
6951   * - use the name of a block device to find the superblock thereon
6952 @@ -310,6 +351,22 @@ static struct super_block *quotactl_bloc
6953         putname(tmp);
6954         if (IS_ERR(bdev))
6955                 return ERR_CAST(bdev);
6956 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6957 +       if (bdev && bdev->bd_inode &&
6958 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
6959 +               struct block_device *bdnew = (void *)-EINVAL;
6960 +
6961 +               if (vroot_get_real_bdev)
6962 +                       bdnew = vroot_get_real_bdev(bdev);
6963 +               else
6964 +                       vxdprintk(VXD_CBIT(misc, 0),
6965 +                                       "vroot_get_real_bdev not set");
6966 +               bdput(bdev);
6967 +               if (IS_ERR(bdnew))
6968 +                       return ERR_PTR(PTR_ERR(bdnew));
6969 +               bdev = bdnew;
6970 +       }
6971 +#endif
6972         sb = get_super(bdev);
6973         bdput(bdev);
6974         if (!sb)
6975 diff -NurpP --minimal linux-3.1.1/fs/reiserfs/file.c linux-3.1.1-vs2.3.2/fs/reiserfs/file.c
6976 --- linux-3.1.1/fs/reiserfs/file.c      2011-10-24 18:45:27.000000000 +0200
6977 +++ linux-3.1.1-vs2.3.2/fs/reiserfs/file.c      2011-10-24 18:53:33.000000000 +0200
6978 @@ -319,5 +319,6 @@ const struct inode_operations reiserfs_f
6979         .listxattr = reiserfs_listxattr,
6980         .removexattr = reiserfs_removexattr,
6981         .permission = reiserfs_permission,
6982 +       .sync_flags = reiserfs_sync_flags,
6983         .get_acl = reiserfs_get_acl,
6984  };
6985 diff -NurpP --minimal linux-3.1.1/fs/reiserfs/inode.c linux-3.1.1-vs2.3.2/fs/reiserfs/inode.c
6986 --- linux-3.1.1/fs/reiserfs/inode.c     2011-10-24 18:45:27.000000000 +0200
6987 +++ linux-3.1.1-vs2.3.2/fs/reiserfs/inode.c     2011-10-24 18:53:33.000000000 +0200
6988 @@ -18,6 +18,7 @@
6989  #include <linux/writeback.h>
6990  #include <linux/quotaops.h>
6991  #include <linux/swap.h>
6992 +#include <linux/vs_tag.h>
6993  
6994  int reiserfs_commit_write(struct file *f, struct page *page,
6995                           unsigned from, unsigned to);
6996 @@ -1131,6 +1132,8 @@ static void init_inode(struct inode *ino
6997         struct buffer_head *bh;
6998         struct item_head *ih;
6999         __u32 rdev;
7000 +       uid_t uid;
7001 +       gid_t gid;
7002         //int version = ITEM_VERSION_1;
7003  
7004         bh = PATH_PLAST_BUFFER(path);
7005 @@ -1151,12 +1154,13 @@ static void init_inode(struct inode *ino
7006                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
7007                 unsigned long blocks;
7008  
7009 +               uid = sd_v1_uid(sd);
7010 +               gid = sd_v1_gid(sd);
7011 +
7012                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
7013                 set_inode_sd_version(inode, STAT_DATA_V1);
7014                 inode->i_mode = sd_v1_mode(sd);
7015                 inode->i_nlink = sd_v1_nlink(sd);
7016 -               inode->i_uid = sd_v1_uid(sd);
7017 -               inode->i_gid = sd_v1_gid(sd);
7018                 inode->i_size = sd_v1_size(sd);
7019                 inode->i_atime.tv_sec = sd_v1_atime(sd);
7020                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
7021 @@ -1198,11 +1202,12 @@ static void init_inode(struct inode *ino
7022                 // (directories and symlinks)
7023                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
7024  
7025 +               uid    = sd_v2_uid(sd);
7026 +               gid    = sd_v2_gid(sd);
7027 +
7028                 inode->i_mode = sd_v2_mode(sd);
7029                 inode->i_nlink = sd_v2_nlink(sd);
7030 -               inode->i_uid = sd_v2_uid(sd);
7031                 inode->i_size = sd_v2_size(sd);
7032 -               inode->i_gid = sd_v2_gid(sd);
7033                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
7034                 inode->i_atime.tv_sec = sd_v2_atime(sd);
7035                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
7036 @@ -1232,6 +1237,10 @@ static void init_inode(struct inode *ino
7037                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
7038         }
7039  
7040 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7041 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7042 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
7043 +
7044         pathrelse(path);
7045         if (S_ISREG(inode->i_mode)) {
7046                 inode->i_op = &reiserfs_file_inode_operations;
7047 @@ -1254,13 +1263,15 @@ static void init_inode(struct inode *ino
7048  static void inode2sd(void *sd, struct inode *inode, loff_t size)
7049  {
7050         struct stat_data *sd_v2 = (struct stat_data *)sd;
7051 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
7052 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
7053         __u16 flags;
7054  
7055 +       set_sd_v2_uid(sd_v2, uid);
7056 +       set_sd_v2_gid(sd_v2, gid);
7057         set_sd_v2_mode(sd_v2, inode->i_mode);
7058         set_sd_v2_nlink(sd_v2, inode->i_nlink);
7059 -       set_sd_v2_uid(sd_v2, inode->i_uid);
7060         set_sd_v2_size(sd_v2, size);
7061 -       set_sd_v2_gid(sd_v2, inode->i_gid);
7062         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
7063         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
7064         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
7065 @@ -2868,14 +2879,19 @@ int reiserfs_commit_write(struct file *f
7066  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
7067  {
7068         if (reiserfs_attrs(inode->i_sb)) {
7069 -               if (sd_attrs & REISERFS_SYNC_FL)
7070 -                       inode->i_flags |= S_SYNC;
7071 -               else
7072 -                       inode->i_flags &= ~S_SYNC;
7073                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
7074                         inode->i_flags |= S_IMMUTABLE;
7075                 else
7076                         inode->i_flags &= ~S_IMMUTABLE;
7077 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
7078 +                       inode->i_flags |= S_IXUNLINK;
7079 +               else
7080 +                       inode->i_flags &= ~S_IXUNLINK;
7081 +
7082 +               if (sd_attrs & REISERFS_SYNC_FL)
7083 +                       inode->i_flags |= S_SYNC;
7084 +               else
7085 +                       inode->i_flags &= ~S_SYNC;
7086                 if (sd_attrs & REISERFS_APPEND_FL)
7087                         inode->i_flags |= S_APPEND;
7088                 else
7089 @@ -2888,6 +2904,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
7090                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
7091                 else
7092                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
7093 +
7094 +               if (sd_attrs & REISERFS_BARRIER_FL)
7095 +                       inode->i_vflags |= V_BARRIER;
7096 +               else
7097 +                       inode->i_vflags &= ~V_BARRIER;
7098 +               if (sd_attrs & REISERFS_COW_FL)
7099 +                       inode->i_vflags |= V_COW;
7100 +               else
7101 +                       inode->i_vflags &= ~V_COW;
7102         }
7103  }
7104  
7105 @@ -2898,6 +2923,11 @@ void i_attrs_to_sd_attrs(struct inode *i
7106                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
7107                 else
7108                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
7109 +               if (inode->i_flags & S_IXUNLINK)
7110 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
7111 +               else
7112 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
7113 +
7114                 if (inode->i_flags & S_SYNC)
7115                         *sd_attrs |= REISERFS_SYNC_FL;
7116                 else
7117 @@ -2910,6 +2940,15 @@ void i_attrs_to_sd_attrs(struct inode *i
7118                         *sd_attrs |= REISERFS_NOTAIL_FL;
7119                 else
7120                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
7121 +
7122 +               if (inode->i_vflags & V_BARRIER)
7123 +                       *sd_attrs |= REISERFS_BARRIER_FL;
7124 +               else
7125 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
7126 +               if (inode->i_vflags & V_COW)
7127 +                       *sd_attrs |= REISERFS_COW_FL;
7128 +               else
7129 +                       *sd_attrs &= ~REISERFS_COW_FL;
7130         }
7131  }
7132  
7133 @@ -3155,7 +3194,8 @@ int reiserfs_setattr(struct dentry *dent
7134         }
7135  
7136         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
7137 -           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
7138 +           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
7139 +           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
7140                 struct reiserfs_transaction_handle th;
7141                 int jbegin_count =
7142                     2 *
7143 @@ -3184,6 +3224,9 @@ int reiserfs_setattr(struct dentry *dent
7144                         inode->i_uid = attr->ia_uid;
7145                 if (attr->ia_valid & ATTR_GID)
7146                         inode->i_gid = attr->ia_gid;
7147 +                               if ((attr->ia_valid & ATTR_TAG) &&
7148 +                                       IS_TAGGED(inode))
7149 +                                       inode->i_tag = attr->ia_tag;
7150                 mark_inode_dirty(inode);
7151                 error = journal_end(&th, inode->i_sb, jbegin_count);
7152                 if (error)
7153 diff -NurpP --minimal linux-3.1.1/fs/reiserfs/ioctl.c linux-3.1.1-vs2.3.2/fs/reiserfs/ioctl.c
7154 --- linux-3.1.1/fs/reiserfs/ioctl.c     2011-05-22 16:17:53.000000000 +0200
7155 +++ linux-3.1.1-vs2.3.2/fs/reiserfs/ioctl.c     2011-10-24 18:53:33.000000000 +0200
7156 @@ -11,6 +11,21 @@
7157  #include <linux/pagemap.h>
7158  #include <linux/compat.h>
7159  
7160 +
7161 +int reiserfs_sync_flags(struct inode *inode, int flags, int vflags)
7162 +{
7163 +       __u16 sd_attrs = 0;
7164 +
7165 +       inode->i_flags = flags;
7166 +       inode->i_vflags = vflags;
7167 +
7168 +       i_attrs_to_sd_attrs(inode, &sd_attrs);
7169 +       REISERFS_I(inode)->i_attrs = sd_attrs;
7170 +       inode->i_ctime = CURRENT_TIME_SEC;
7171 +       mark_inode_dirty(inode);
7172 +       return 0;
7173 +}
7174 +
7175  /*
7176   * reiserfs_ioctl - handler for ioctl for inode
7177   * supported commands:
7178 @@ -22,7 +37,7 @@
7179  long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
7180  {
7181         struct inode *inode = filp->f_path.dentry->d_inode;
7182 -       unsigned int flags;
7183 +       unsigned int flags, oldflags;
7184         int err = 0;
7185  
7186         reiserfs_write_lock(inode->i_sb);
7187 @@ -47,6 +62,7 @@ long reiserfs_ioctl(struct file *filp, u
7188  
7189                 flags = REISERFS_I(inode)->i_attrs;
7190                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
7191 +               flags &= REISERFS_FL_USER_VISIBLE;
7192                 err = put_user(flags, (int __user *)arg);
7193                 break;
7194         case REISERFS_IOC_SETFLAGS:{
7195 @@ -67,6 +83,10 @@ long reiserfs_ioctl(struct file *filp, u
7196                                 err = -EFAULT;
7197                                 goto setflags_out;
7198                         }
7199 +                       if (IS_BARRIER(inode)) {
7200 +                               vxwprintk_task(1, "messing with the barrier.");
7201 +                               return -EACCES;
7202 +                       }
7203                         /*
7204                          * Is it quota file? Do not allow user to mess with it
7205                          */
7206 @@ -91,6 +111,10 @@ long reiserfs_ioctl(struct file *filp, u
7207                                         goto setflags_out;
7208                                 }
7209                         }
7210 +
7211 +                       oldflags = REISERFS_I(inode)->i_attrs;
7212 +                       flags &= REISERFS_FL_USER_MODIFIABLE;
7213 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
7214                         sd_attrs_to_i_attrs(flags, inode);
7215                         REISERFS_I(inode)->i_attrs = flags;
7216                         inode->i_ctime = CURRENT_TIME_SEC;
7217 diff -NurpP --minimal linux-3.1.1/fs/reiserfs/namei.c linux-3.1.1-vs2.3.2/fs/reiserfs/namei.c
7218 --- linux-3.1.1/fs/reiserfs/namei.c     2011-10-24 18:45:27.000000000 +0200
7219 +++ linux-3.1.1-vs2.3.2/fs/reiserfs/namei.c     2011-10-24 18:53:33.000000000 +0200
7220 @@ -18,6 +18,7 @@
7221  #include <linux/reiserfs_acl.h>
7222  #include <linux/reiserfs_xattr.h>
7223  #include <linux/quotaops.h>
7224 +#include <linux/vs_tag.h>
7225  
7226  #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; }
7227  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
7228 @@ -362,6 +363,7 @@ static struct dentry *reiserfs_lookup(st
7229         if (retval == IO_ERROR) {
7230                 return ERR_PTR(-EIO);
7231         }
7232 +               dx_propagate_tag(nd, inode);
7233  
7234         return d_splice_alias(inode, dentry);
7235  }
7236 diff -NurpP --minimal linux-3.1.1/fs/reiserfs/super.c linux-3.1.1-vs2.3.2/fs/reiserfs/super.c
7237 --- linux-3.1.1/fs/reiserfs/super.c     2011-10-24 18:45:27.000000000 +0200
7238 +++ linux-3.1.1-vs2.3.2/fs/reiserfs/super.c     2011-10-24 18:53:33.000000000 +0200
7239 @@ -899,6 +899,14 @@ static int reiserfs_parse_options(struct
7240                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
7241                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
7242  #endif
7243 +#ifndef CONFIG_TAGGING_NONE
7244 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
7245 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
7246 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
7247 +#endif
7248 +#ifdef CONFIG_PROPAGATE
7249 +               {"tag",.arg_required = 'T',.values = NULL},
7250 +#endif
7251  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
7252                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
7253                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
7254 @@ -1208,6 +1216,14 @@ static int reiserfs_remount(struct super
7255         handle_quota_files(s, qf_names, &qfmt);
7256  #endif
7257  
7258 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
7259 +               !(s->s_flags & MS_TAGGED)) {
7260 +               reiserfs_warning(s, "super-vs01",
7261 +                       "reiserfs: tagging not permitted on remount.");
7262 +               err = -EINVAL;
7263 +               goto out_err;
7264 +       }
7265 +
7266         handle_attrs(s);
7267  
7268         /* Add options that are safe here */
7269 @@ -1691,6 +1707,10 @@ static int reiserfs_fill_super(struct su
7270                 goto error;
7271         }
7272  
7273 +       /* map mount option tagxid */
7274 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
7275 +               s->s_flags |= MS_TAGGED;
7276 +
7277         rs = SB_DISK_SUPER_BLOCK(s);
7278         /* Let's do basic sanity check to verify that underlying device is not
7279            smaller than the filesystem. If the check fails then abort and scream,
7280 diff -NurpP --minimal linux-3.1.1/fs/reiserfs/xattr.c linux-3.1.1-vs2.3.2/fs/reiserfs/xattr.c
7281 --- linux-3.1.1/fs/reiserfs/xattr.c     2011-10-24 18:45:27.000000000 +0200
7282 +++ linux-3.1.1-vs2.3.2/fs/reiserfs/xattr.c     2011-10-24 18:53:33.000000000 +0200
7283 @@ -40,6 +40,7 @@
7284  #include <linux/errno.h>
7285  #include <linux/gfp.h>
7286  #include <linux/fs.h>
7287 +#include <linux/mount.h>
7288  #include <linux/file.h>
7289  #include <linux/pagemap.h>
7290  #include <linux/xattr.h>
7291 diff -NurpP --minimal linux-3.1.1/fs/stat.c linux-3.1.1-vs2.3.2/fs/stat.c
7292 --- linux-3.1.1/fs/stat.c       2011-11-15 16:44:52.000000000 +0100
7293 +++ linux-3.1.1-vs2.3.2/fs/stat.c       2011-11-15 17:08:44.000000000 +0100
7294 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
7295         stat->nlink = inode->i_nlink;
7296         stat->uid = inode->i_uid;
7297         stat->gid = inode->i_gid;
7298 +       stat->tag = inode->i_tag;
7299         stat->rdev = inode->i_rdev;
7300         stat->size = i_size_read(inode);
7301         stat->atime = inode->i_atime;
7302 diff -NurpP --minimal linux-3.1.1/fs/statfs.c linux-3.1.1-vs2.3.2/fs/statfs.c
7303 --- linux-3.1.1/fs/statfs.c     2011-11-15 16:44:52.000000000 +0100
7304 +++ linux-3.1.1-vs2.3.2/fs/statfs.c     2011-11-15 17:08:44.000000000 +0100
7305 @@ -7,6 +7,8 @@
7306  #include <linux/statfs.h>
7307  #include <linux/security.h>
7308  #include <linux/uaccess.h>
7309 +#include <linux/vs_base.h>
7310 +#include <linux/vs_dlimit.h>
7311  
7312  static int flags_by_mnt(int mnt_flags)
7313  {
7314 @@ -59,6 +61,8 @@ int statfs_by_dentry(struct dentry *dent
7315         retval = dentry->d_sb->s_op->statfs(dentry, buf);
7316         if (retval == 0 && buf->f_frsize == 0)
7317                 buf->f_frsize = buf->f_bsize;
7318 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
7319 +               vx_vsi_statfs(dentry->d_sb, buf);
7320         return retval;
7321  }
7322  
7323 diff -NurpP --minimal linux-3.1.1/fs/super.c linux-3.1.1-vs2.3.2/fs/super.c
7324 --- linux-3.1.1/fs/super.c      2011-10-24 18:45:27.000000000 +0200
7325 +++ linux-3.1.1-vs2.3.2/fs/super.c      2011-10-24 18:53:33.000000000 +0200
7326 @@ -32,6 +32,9 @@
7327  #include <linux/backing-dev.h>
7328  #include <linux/rculist_bl.h>
7329  #include <linux/cleancache.h>
7330 +#include <linux/devpts_fs.h>
7331 +#include <linux/proc_fs.h>
7332 +#include <linux/vs_context.h>
7333  #include "internal.h"
7334  
7335  
7336 @@ -1095,6 +1098,13 @@ mount_fs(struct file_system_type *type, 
7337         WARN_ON(sb->s_bdi == &default_backing_dev_info);
7338         sb->s_flags |= MS_BORN;
7339  
7340 +       error = -EPERM;
7341 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
7342 +               !sb->s_bdev &&
7343 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
7344 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
7345 +               goto out_sb;
7346 +
7347         error = security_sb_kern_mount(sb, flags, secdata);
7348         if (error)
7349                 goto out_sb;
7350 diff -NurpP --minimal linux-3.1.1/fs/sysfs/mount.c linux-3.1.1-vs2.3.2/fs/sysfs/mount.c
7351 --- linux-3.1.1/fs/sysfs/mount.c        2011-07-22 11:18:06.000000000 +0200
7352 +++ linux-3.1.1-vs2.3.2/fs/sysfs/mount.c        2011-10-24 18:53:33.000000000 +0200
7353 @@ -47,7 +47,7 @@ static int sysfs_fill_super(struct super
7354  
7355         sb->s_blocksize = PAGE_CACHE_SIZE;
7356         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
7357 -       sb->s_magic = SYSFS_MAGIC;
7358 +       sb->s_magic = SYSFS_SUPER_MAGIC;
7359         sb->s_op = &sysfs_ops;
7360         sb->s_time_gran = 1;
7361  
7362 diff -NurpP --minimal linux-3.1.1/fs/utimes.c linux-3.1.1-vs2.3.2/fs/utimes.c
7363 --- linux-3.1.1/fs/utimes.c     2011-05-22 16:17:54.000000000 +0200
7364 +++ linux-3.1.1-vs2.3.2/fs/utimes.c     2011-10-24 18:53:33.000000000 +0200
7365 @@ -8,6 +8,8 @@
7366  #include <linux/stat.h>
7367  #include <linux/utime.h>
7368  #include <linux/syscalls.h>
7369 +#include <linux/mount.h>
7370 +#include <linux/vs_cowbl.h>
7371  #include <asm/uaccess.h>
7372  #include <asm/unistd.h>
7373  
7374 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
7375  {
7376         int error;
7377         struct iattr newattrs;
7378 -       struct inode *inode = path->dentry->d_inode;
7379 +       struct inode *inode;
7380  
7381         error = mnt_want_write(path->mnt);
7382         if (error)
7383                 goto out;
7384  
7385 +       error = cow_check_and_break(path);
7386 +       if (error)
7387 +               goto mnt_drop_write_and_out;
7388 +
7389 +       inode = path->dentry->d_inode;
7390 +
7391         if (times && times[0].tv_nsec == UTIME_NOW &&
7392                      times[1].tv_nsec == UTIME_NOW)
7393                 times = NULL;
7394 diff -NurpP --minimal linux-3.1.1/fs/xattr.c linux-3.1.1-vs2.3.2/fs/xattr.c
7395 --- linux-3.1.1/fs/xattr.c      2011-07-22 11:18:09.000000000 +0200
7396 +++ linux-3.1.1-vs2.3.2/fs/xattr.c      2011-10-24 18:53:33.000000000 +0200
7397 @@ -18,6 +18,7 @@
7398  #include <linux/module.h>
7399  #include <linux/fsnotify.h>
7400  #include <linux/audit.h>
7401 +#include <linux/mount.h>
7402  #include <asm/uaccess.h>
7403  
7404  
7405 @@ -49,7 +50,7 @@ xattr_permission(struct inode *inode, co
7406          * The trusted.* namespace can only be accessed by privileged users.
7407          */
7408         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
7409 -               if (!capable(CAP_SYS_ADMIN))
7410 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
7411                         return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
7412                 return 0;
7413         }
7414 diff -NurpP --minimal linux-3.1.1/fs/xfs/xfs_dinode.h linux-3.1.1-vs2.3.2/fs/xfs/xfs_dinode.h
7415 --- linux-3.1.1/fs/xfs/xfs_dinode.h     2011-10-24 18:45:31.000000000 +0200
7416 +++ linux-3.1.1-vs2.3.2/fs/xfs/xfs_dinode.h     2011-10-24 18:53:33.000000000 +0200
7417 @@ -51,7 +51,9 @@ typedef struct xfs_dinode {
7418         __be32          di_nlink;       /* number of links to file */
7419         __be16          di_projid_lo;   /* lower part of owner's project id */
7420         __be16          di_projid_hi;   /* higher part owner's project id */
7421 -       __u8            di_pad[6];      /* unused, zeroed space */
7422 +       __u8            di_pad[2];      /* unused, zeroed space */
7423 +       __be16          di_tag;         /* context tagging */
7424 +       __be16          di_vflags;      /* vserver specific flags */
7425         __be16          di_flushiter;   /* incremented on flush */
7426         xfs_timestamp_t di_atime;       /* time last accessed */
7427         xfs_timestamp_t di_mtime;       /* time last modified */
7428 @@ -184,6 +186,8 @@ static inline void xfs_dinode_put_rdev(s
7429  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
7430  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
7431  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
7432 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
7433 +
7434  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
7435  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
7436  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
7437 @@ -199,6 +203,7 @@ static inline void xfs_dinode_put_rdev(s
7438  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
7439  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
7440  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
7441 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
7442  
7443  #ifdef CONFIG_XFS_RT
7444  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
7445 @@ -211,6 +216,10 @@ static inline void xfs_dinode_put_rdev(s
7446          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
7447          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
7448          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
7449 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
7450 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
7451 +        XFS_DIFLAG_IXUNLINK)
7452 +
7453 +#define XFS_DIVFLAG_BARRIER    0x01
7454 +#define XFS_DIVFLAG_COW                0x02
7455  
7456  #endif /* __XFS_DINODE_H__ */
7457 diff -NurpP --minimal linux-3.1.1/fs/xfs/xfs_fs.h linux-3.1.1-vs2.3.2/fs/xfs/xfs_fs.h
7458 --- linux-3.1.1/fs/xfs/xfs_fs.h 2011-10-24 18:45:31.000000000 +0200
7459 +++ linux-3.1.1-vs2.3.2/fs/xfs/xfs_fs.h 2011-10-24 18:53:33.000000000 +0200
7460 @@ -67,6 +67,9 @@ struct fsxattr {
7461  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
7462  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
7463  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
7464 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
7465 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
7466 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
7467  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
7468  
7469  /*
7470 @@ -302,7 +305,8 @@ typedef struct xfs_bstat {
7471  #define        bs_projid       bs_projid_lo    /* (previously just bs_projid)  */
7472         __u16           bs_forkoff;     /* inode fork offset in bytes   */
7473         __u16           bs_projid_hi;   /* higher part of project id    */
7474 -       unsigned char   bs_pad[10];     /* pad space, unused            */
7475 +       unsigned char   bs_pad[8];      /* pad space, unused            */
7476 +       __u16           bs_tag;         /* context tagging              */
7477         __u32           bs_dmevmask;    /* DMIG event mask              */
7478         __u16           bs_dmstate;     /* DMIG state info              */
7479         __u16           bs_aextents;    /* attribute number of extents  */
7480 diff -NurpP --minimal linux-3.1.1/fs/xfs/xfs_ialloc.c linux-3.1.1-vs2.3.2/fs/xfs/xfs_ialloc.c
7481 --- linux-3.1.1/fs/xfs/xfs_ialloc.c     2011-10-24 18:45:31.000000000 +0200
7482 +++ linux-3.1.1-vs2.3.2/fs/xfs/xfs_ialloc.c     2011-10-24 18:53:33.000000000 +0200
7483 @@ -37,7 +37,6 @@
7484  #include "xfs_error.h"
7485  #include "xfs_bmap.h"
7486  
7487 -
7488  /*
7489   * Allocation group level functions.
7490   */
7491 diff -NurpP --minimal linux-3.1.1/fs/xfs/xfs_inode.c linux-3.1.1-vs2.3.2/fs/xfs/xfs_inode.c
7492 --- linux-3.1.1/fs/xfs/xfs_inode.c      2011-10-24 18:45:31.000000000 +0200
7493 +++ linux-3.1.1-vs2.3.2/fs/xfs/xfs_inode.c      2011-10-24 18:53:33.000000000 +0200
7494 @@ -242,6 +242,7 @@ xfs_inotobp(
7495         return 0;
7496  }
7497  
7498 +#include <linux/vs_tag.h>
7499  
7500  /*
7501   * This routine is called to map an inode to the buffer containing
7502 @@ -640,15 +641,25 @@ xfs_iformat_btree(
7503  STATIC void
7504  xfs_dinode_from_disk(
7505         xfs_icdinode_t          *to,
7506 -       xfs_dinode_t            *from)
7507 +       xfs_dinode_t            *from,
7508 +       int tagged)
7509  {
7510 +       uint32_t uid, gid, tag;
7511 +
7512         to->di_magic = be16_to_cpu(from->di_magic);
7513         to->di_mode = be16_to_cpu(from->di_mode);
7514         to->di_version = from ->di_version;
7515         to->di_format = from->di_format;
7516         to->di_onlink = be16_to_cpu(from->di_onlink);
7517 -       to->di_uid = be32_to_cpu(from->di_uid);
7518 -       to->di_gid = be32_to_cpu(from->di_gid);
7519 +
7520 +       uid = be32_to_cpu(from->di_uid);
7521 +       gid = be32_to_cpu(from->di_gid);
7522 +       tag = be16_to_cpu(from->di_tag);
7523 +
7524 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
7525 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
7526 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
7527 +
7528         to->di_nlink = be32_to_cpu(from->di_nlink);
7529         to->di_projid_lo = be16_to_cpu(from->di_projid_lo);
7530         to->di_projid_hi = be16_to_cpu(from->di_projid_hi);
7531 @@ -670,21 +681,26 @@ xfs_dinode_from_disk(
7532         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
7533         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
7534         to->di_flags    = be16_to_cpu(from->di_flags);
7535 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
7536         to->di_gen      = be32_to_cpu(from->di_gen);
7537  }
7538  
7539  void
7540  xfs_dinode_to_disk(
7541         xfs_dinode_t            *to,
7542 -       xfs_icdinode_t          *from)
7543 +       xfs_icdinode_t          *from,
7544 +       int tagged)
7545  {
7546         to->di_magic = cpu_to_be16(from->di_magic);
7547         to->di_mode = cpu_to_be16(from->di_mode);
7548         to->di_version = from ->di_version;
7549         to->di_format = from->di_format;
7550         to->di_onlink = cpu_to_be16(from->di_onlink);
7551 -       to->di_uid = cpu_to_be32(from->di_uid);
7552 -       to->di_gid = cpu_to_be32(from->di_gid);
7553 +
7554 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
7555 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
7556 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
7557 +
7558         to->di_nlink = cpu_to_be32(from->di_nlink);
7559         to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
7560         to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
7561 @@ -706,12 +722,14 @@ xfs_dinode_to_disk(
7562         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
7563         to->di_dmstate = cpu_to_be16(from->di_dmstate);
7564         to->di_flags = cpu_to_be16(from->di_flags);
7565 +       to->di_vflags = cpu_to_be16(from->di_vflags);
7566         to->di_gen = cpu_to_be32(from->di_gen);
7567  }
7568  
7569  STATIC uint
7570  _xfs_dic2xflags(
7571 -       __uint16_t              di_flags)
7572 +       __uint16_t              di_flags,
7573 +       __uint16_t              di_vflags)
7574  {
7575         uint                    flags = 0;
7576  
7577 @@ -722,6 +740,8 @@ _xfs_dic2xflags(
7578                         flags |= XFS_XFLAG_PREALLOC;
7579                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
7580                         flags |= XFS_XFLAG_IMMUTABLE;
7581 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
7582 +                       flags |= XFS_XFLAG_IXUNLINK;
7583                 if (di_flags & XFS_DIFLAG_APPEND)
7584                         flags |= XFS_XFLAG_APPEND;
7585                 if (di_flags & XFS_DIFLAG_SYNC)
7586 @@ -746,6 +766,10 @@ _xfs_dic2xflags(
7587                         flags |= XFS_XFLAG_FILESTREAM;
7588         }
7589  
7590 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
7591 +               flags |= FS_BARRIER_FL;
7592 +       if (di_vflags & XFS_DIVFLAG_COW)
7593 +               flags |= FS_COW_FL;
7594         return flags;
7595  }
7596  
7597 @@ -755,7 +779,7 @@ xfs_ip2xflags(
7598  {
7599         xfs_icdinode_t          *dic = &ip->i_d;
7600  
7601 -       return _xfs_dic2xflags(dic->di_flags) |
7602 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
7603                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
7604  }
7605  
7606 @@ -763,7 +787,8 @@ uint
7607  xfs_dic2xflags(
7608         xfs_dinode_t            *dip)
7609  {
7610 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
7611 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
7612 +                               be16_to_cpu(dip->di_vflags)) |
7613                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
7614  }
7615  
7616 @@ -796,7 +821,6 @@ xfs_iread(
7617         if (error)
7618                 return error;
7619         dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);
7620 -
7621         /*
7622          * If we got something that isn't an inode it means someone
7623          * (nfs or dmi) has a stale handle.
7624 @@ -819,7 +843,8 @@ xfs_iread(
7625          * Otherwise, just get the truly permanent information.
7626          */
7627         if (dip->di_mode) {
7628 -               xfs_dinode_from_disk(&ip->i_d, dip);
7629 +               xfs_dinode_from_disk(&ip->i_d, dip,
7630 +                       mp->m_flags & XFS_MOUNT_TAGGED);
7631                 error = xfs_iformat(ip, dip);
7632                 if (error)  {
7633  #ifdef DEBUG
7634 @@ -1014,6 +1039,7 @@ xfs_ialloc(
7635         ASSERT(ip->i_d.di_nlink == nlink);
7636         ip->i_d.di_uid = current_fsuid();
7637         ip->i_d.di_gid = current_fsgid();
7638 +       ip->i_d.di_tag = current_fstag(&ip->i_vnode);
7639         xfs_set_projid(ip, prid);
7640         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
7641  
7642 @@ -1074,6 +1100,7 @@ xfs_ialloc(
7643         ip->i_d.di_dmevmask = 0;
7644         ip->i_d.di_dmstate = 0;
7645         ip->i_d.di_flags = 0;
7646 +       ip->i_d.di_vflags = 0;
7647         flags = XFS_ILOG_CORE;
7648         switch (mode & S_IFMT) {
7649         case S_IFIFO:
7650 @@ -1845,6 +1872,7 @@ xfs_ifree(
7651         }
7652         ip->i_d.di_mode = 0;            /* mark incore inode as free */
7653         ip->i_d.di_flags = 0;
7654 +       ip->i_d.di_vflags = 0;
7655         ip->i_d.di_dmevmask = 0;
7656         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
7657         ip->i_df.if_ext_max =
7658 @@ -2724,7 +2752,8 @@ xfs_iflush_int(
7659          * because if the inode is dirty at all the core must
7660          * be.
7661          */
7662 -       xfs_dinode_to_disk(dip, &ip->i_d);
7663 +       xfs_dinode_to_disk(dip, &ip->i_d,
7664 +               mp->m_flags & XFS_MOUNT_TAGGED);
7665  
7666         /* Wrap, we never let the log put out DI_MAX_FLUSH */
7667         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
7668 diff -NurpP --minimal linux-3.1.1/fs/xfs/xfs_inode.h linux-3.1.1-vs2.3.2/fs/xfs/xfs_inode.h
7669 --- linux-3.1.1/fs/xfs/xfs_inode.h      2011-10-24 18:45:31.000000000 +0200
7670 +++ linux-3.1.1-vs2.3.2/fs/xfs/xfs_inode.h      2011-10-24 18:53:33.000000000 +0200
7671 @@ -135,7 +135,9 @@ typedef struct xfs_icdinode {
7672         __uint32_t      di_nlink;       /* number of links to file */
7673         __uint16_t      di_projid_lo;   /* lower part of owner's project id */
7674         __uint16_t      di_projid_hi;   /* higher part of owner's project id */
7675 -       __uint8_t       di_pad[6];      /* unused, zeroed space */
7676 +       __uint8_t       di_pad[2];      /* unused, zeroed space */
7677 +       __uint16_t      di_tag;         /* context tagging */
7678 +       __uint16_t      di_vflags;      /* vserver specific flags */
7679         __uint16_t      di_flushiter;   /* incremented on flush */
7680         xfs_ictimestamp_t di_atime;     /* time last accessed */
7681         xfs_ictimestamp_t di_mtime;     /* time last modified */
7682 @@ -536,7 +538,7 @@ int         xfs_itobp(struct xfs_mount *, struc
7683  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
7684                           struct xfs_inode *, uint);
7685  void           xfs_dinode_to_disk(struct xfs_dinode *,
7686 -                                  struct xfs_icdinode *);
7687 +                                  struct xfs_icdinode *, int);
7688  void           xfs_idestroy_fork(struct xfs_inode *, int);
7689  void           xfs_idata_realloc(struct xfs_inode *, int, int);
7690  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
7691 diff -NurpP --minimal linux-3.1.1/fs/xfs/xfs_ioctl.c linux-3.1.1-vs2.3.2/fs/xfs/xfs_ioctl.c
7692 --- linux-3.1.1/fs/xfs/xfs_ioctl.c      2011-10-24 18:45:31.000000000 +0200
7693 +++ linux-3.1.1-vs2.3.2/fs/xfs/xfs_ioctl.c      2011-10-24 18:53:33.000000000 +0200
7694 @@ -28,7 +28,7 @@
7695  #include "xfs_bmap_btree.h"
7696  #include "xfs_dinode.h"
7697  #include "xfs_inode.h"
7698 -#include "xfs_ioctl.h"
7699 +// #include "xfs_ioctl.h"
7700  #include "xfs_rtalloc.h"
7701  #include "xfs_itable.h"
7702  #include "xfs_error.h"
7703 @@ -748,6 +748,10 @@ xfs_merge_ioc_xflags(
7704                 xflags |= XFS_XFLAG_IMMUTABLE;
7705         else
7706                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7707 +       if (flags & FS_IXUNLINK_FL)
7708 +               xflags |= XFS_XFLAG_IXUNLINK;
7709 +       else
7710 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7711         if (flags & FS_APPEND_FL)
7712                 xflags |= XFS_XFLAG_APPEND;
7713         else
7714 @@ -776,6 +780,8 @@ xfs_di2lxflags(
7715  
7716         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7717                 flags |= FS_IMMUTABLE_FL;
7718 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7719 +               flags |= FS_IXUNLINK_FL;
7720         if (di_flags & XFS_DIFLAG_APPEND)
7721                 flags |= FS_APPEND_FL;
7722         if (di_flags & XFS_DIFLAG_SYNC)
7723 @@ -836,6 +842,8 @@ xfs_set_diflags(
7724         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7725         if (xflags & XFS_XFLAG_IMMUTABLE)
7726                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7727 +       if (xflags & XFS_XFLAG_IXUNLINK)
7728 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7729         if (xflags & XFS_XFLAG_APPEND)
7730                 di_flags |= XFS_DIFLAG_APPEND;
7731         if (xflags & XFS_XFLAG_SYNC)
7732 @@ -878,6 +886,10 @@ xfs_diflags_to_linux(
7733                 inode->i_flags |= S_IMMUTABLE;
7734         else
7735                 inode->i_flags &= ~S_IMMUTABLE;
7736 +       if (xflags & XFS_XFLAG_IXUNLINK)
7737 +               inode->i_flags |= S_IXUNLINK;
7738 +       else
7739 +               inode->i_flags &= ~S_IXUNLINK;
7740         if (xflags & XFS_XFLAG_APPEND)
7741                 inode->i_flags |= S_APPEND;
7742         else
7743 @@ -1370,10 +1382,18 @@ xfs_file_ioctl(
7744         case XFS_IOC_FSGETXATTRA:
7745                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7746         case XFS_IOC_FSSETXATTR:
7747 +               if (IS_BARRIER(inode)) {
7748 +                       vxwprintk_task(1, "messing with the barrier.");
7749 +                       return -XFS_ERROR(EACCES);
7750 +               }
7751                 return xfs_ioc_fssetxattr(ip, filp, arg);
7752         case XFS_IOC_GETXFLAGS:
7753                 return xfs_ioc_getxflags(ip, arg);
7754         case XFS_IOC_SETXFLAGS:
7755 +               if (IS_BARRIER(inode)) {
7756 +                       vxwprintk_task(1, "messing with the barrier.");
7757 +                       return -XFS_ERROR(EACCES);
7758 +               }
7759                 return xfs_ioc_setxflags(ip, filp, arg);
7760  
7761         case XFS_IOC_FSSETDM: {
7762 diff -NurpP --minimal linux-3.1.1/fs/xfs/xfs_ioctl.h linux-3.1.1-vs2.3.2/fs/xfs/xfs_ioctl.h
7763 --- linux-3.1.1/fs/xfs/xfs_ioctl.h      2011-10-24 18:45:31.000000000 +0200
7764 +++ linux-3.1.1-vs2.3.2/fs/xfs/xfs_ioctl.h      2011-10-24 18:53:33.000000000 +0200
7765 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7766         void __user             *uhandle,
7767         u32                     hlen);
7768  
7769 +extern int
7770 +xfs_sync_flags(
7771 +       struct inode            *inode,
7772 +       int                     flags,
7773 +       int                     vflags);
7774 +
7775  extern long
7776  xfs_file_ioctl(
7777         struct file             *filp,
7778 diff -NurpP --minimal linux-3.1.1/fs/xfs/xfs_iops.c linux-3.1.1-vs2.3.2/fs/xfs/xfs_iops.c
7779 --- linux-3.1.1/fs/xfs/xfs_iops.c       2011-10-24 18:45:31.000000000 +0200
7780 +++ linux-3.1.1-vs2.3.2/fs/xfs/xfs_iops.c       2011-10-24 18:53:33.000000000 +0200
7781 @@ -30,6 +30,7 @@
7782  #include "xfs_bmap_btree.h"
7783  #include "xfs_dinode.h"
7784  #include "xfs_inode.h"
7785 +#include "xfs_ioctl.h"
7786  #include "xfs_bmap.h"
7787  #include "xfs_rtalloc.h"
7788  #include "xfs_error.h"
7789 @@ -49,6 +50,7 @@
7790  #include <linux/security.h>
7791  #include <linux/fiemap.h>
7792  #include <linux/slab.h>
7793 +#include <linux/vs_tag.h>
7794  
7795  /*
7796   * Bring the timestamps in the XFS inode uptodate.
7797 @@ -473,6 +475,7 @@ xfs_vn_getattr(
7798         stat->nlink = ip->i_d.di_nlink;
7799         stat->uid = ip->i_d.di_uid;
7800         stat->gid = ip->i_d.di_gid;
7801 +       stat->tag = ip->i_d.di_tag;
7802         stat->ino = ip->i_ino;
7803         stat->atime = inode->i_atime;
7804         stat->mtime = inode->i_mtime;
7805 @@ -1038,6 +1041,7 @@ static const struct inode_operations xfs
7806         .removexattr            = generic_removexattr,
7807         .listxattr              = xfs_vn_listxattr,
7808         .fiemap                 = xfs_vn_fiemap,
7809 +       .sync_flags             = xfs_sync_flags,
7810  };
7811  
7812  static const struct inode_operations xfs_dir_inode_operations = {
7813 @@ -1063,6 +1067,7 @@ static const struct inode_operations xfs
7814         .getxattr               = generic_getxattr,
7815         .removexattr            = generic_removexattr,
7816         .listxattr              = xfs_vn_listxattr,
7817 +       .sync_flags             = xfs_sync_flags,
7818  };
7819  
7820  static const struct inode_operations xfs_dir_ci_inode_operations = {
7821 @@ -1112,6 +1117,10 @@ xfs_diflags_to_iflags(
7822                 inode->i_flags |= S_IMMUTABLE;
7823         else
7824                 inode->i_flags &= ~S_IMMUTABLE;
7825 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7826 +               inode->i_flags |= S_IXUNLINK;
7827 +       else
7828 +               inode->i_flags &= ~S_IXUNLINK;
7829         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7830                 inode->i_flags |= S_APPEND;
7831         else
7832 @@ -1124,6 +1133,15 @@ xfs_diflags_to_iflags(
7833                 inode->i_flags |= S_NOATIME;
7834         else
7835                 inode->i_flags &= ~S_NOATIME;
7836 +
7837 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7838 +               inode->i_vflags |= V_BARRIER;
7839 +       else
7840 +               inode->i_vflags &= ~V_BARRIER;
7841 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7842 +               inode->i_vflags |= V_COW;
7843 +       else
7844 +               inode->i_vflags &= ~V_COW;
7845  }
7846  
7847  /*
7848 @@ -1155,6 +1173,7 @@ xfs_setup_inode(
7849         inode->i_nlink  = ip->i_d.di_nlink;
7850         inode->i_uid    = ip->i_d.di_uid;
7851         inode->i_gid    = ip->i_d.di_gid;
7852 +       inode->i_tag    = ip->i_d.di_tag;
7853  
7854         switch (inode->i_mode & S_IFMT) {
7855         case S_IFBLK:
7856 diff -NurpP --minimal linux-3.1.1/fs/xfs/xfs_itable.c linux-3.1.1-vs2.3.2/fs/xfs/xfs_itable.c
7857 --- linux-3.1.1/fs/xfs/xfs_itable.c     2011-05-22 16:17:54.000000000 +0200
7858 +++ linux-3.1.1-vs2.3.2/fs/xfs/xfs_itable.c     2011-10-24 18:53:33.000000000 +0200
7859 @@ -98,6 +98,7 @@ xfs_bulkstat_one_int(
7860         buf->bs_mode = dic->di_mode;
7861         buf->bs_uid = dic->di_uid;
7862         buf->bs_gid = dic->di_gid;
7863 +       buf->bs_tag = dic->di_tag;
7864         buf->bs_size = dic->di_size;
7865  
7866         /*
7867 diff -NurpP --minimal linux-3.1.1/fs/xfs/xfs_linux.h linux-3.1.1-vs2.3.2/fs/xfs/xfs_linux.h
7868 --- linux-3.1.1/fs/xfs/xfs_linux.h      2011-10-24 18:45:31.000000000 +0200
7869 +++ linux-3.1.1-vs2.3.2/fs/xfs/xfs_linux.h      2011-10-24 18:53:33.000000000 +0200
7870 @@ -121,6 +121,7 @@
7871  
7872  #define current_cpu()          (raw_smp_processor_id())
7873  #define current_pid()          (current->pid)
7874 +#define current_fstag(vp)      (dx_current_fstag((vp)->i_sb))
7875  #define current_test_flags(f)  (current->flags & (f))
7876  #define current_set_flags_nested(sp, f)                \
7877                 (*(sp) = current->flags, current->flags |= (f))
7878 diff -NurpP --minimal linux-3.1.1/fs/xfs/xfs_log_recover.c linux-3.1.1-vs2.3.2/fs/xfs/xfs_log_recover.c
7879 --- linux-3.1.1/fs/xfs/xfs_log_recover.c        2011-10-24 18:45:31.000000000 +0200
7880 +++ linux-3.1.1-vs2.3.2/fs/xfs/xfs_log_recover.c        2011-10-24 18:53:33.000000000 +0200
7881 @@ -2347,7 +2347,8 @@ xlog_recover_inode_pass2(
7882         }
7883  
7884         /* The core is in in-core format */
7885 -       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr);
7886 +       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr,
7887 +               mp->m_flags & XFS_MOUNT_TAGGED);
7888  
7889         /* the rest is in on-disk format */
7890         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
7891 diff -NurpP --minimal linux-3.1.1/fs/xfs/xfs_mount.h linux-3.1.1-vs2.3.2/fs/xfs/xfs_mount.h
7892 --- linux-3.1.1/fs/xfs/xfs_mount.h      2011-10-24 18:45:31.000000000 +0200
7893 +++ linux-3.1.1-vs2.3.2/fs/xfs/xfs_mount.h      2011-10-24 18:53:33.000000000 +0200
7894 @@ -249,6 +249,7 @@ typedef struct xfs_mount {
7895                                                    allocator */
7896  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
7897  
7898 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
7899  
7900  /*
7901   * Default minimum read and write sizes.
7902 diff -NurpP --minimal linux-3.1.1/fs/xfs/xfs_super.c linux-3.1.1-vs2.3.2/fs/xfs/xfs_super.c
7903 --- linux-3.1.1/fs/xfs/xfs_super.c      2011-10-24 18:45:31.000000000 +0200
7904 +++ linux-3.1.1-vs2.3.2/fs/xfs/xfs_super.c      2011-10-24 18:53:33.000000000 +0200
7905 @@ -113,6 +113,9 @@ mempool_t *xfs_ioend_pool;
7906  #define MNTOPT_NODELAYLOG  "nodelaylog"        /* Delayed logging disabled */
7907  #define MNTOPT_DISCARD    "discard"    /* Discard unused blocks */
7908  #define MNTOPT_NODISCARD   "nodiscard" /* Do not discard unused blocks */
7909 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
7910 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
7911 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
7912  
7913  /*
7914   * Table driven mount option parser.
7915 @@ -121,10 +124,14 @@ mempool_t *xfs_ioend_pool;
7916   * in the future, too.
7917   */
7918  enum {
7919 +       Opt_tag, Opt_notag,
7920         Opt_barrier, Opt_nobarrier, Opt_err
7921  };
7922  
7923  static const match_table_t tokens = {
7924 +       {Opt_tag, "tagxid"},
7925 +       {Opt_tag, "tag"},
7926 +       {Opt_notag, "notag"},
7927         {Opt_barrier, "barrier"},
7928         {Opt_nobarrier, "nobarrier"},
7929         {Opt_err, NULL}
7930 @@ -374,6 +381,19 @@ xfs_parseargs(
7931                 } else if (!strcmp(this_char, "irixsgid")) {
7932                         xfs_warn(mp,
7933         "irixsgid is now a sysctl(2) variable, option is deprecated.");
7934 +#ifndef CONFIG_TAGGING_NONE
7935 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7936 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7937 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7938 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
7939 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7940 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7941 +#endif
7942 +#ifdef CONFIG_PROPAGATE
7943 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7944 +                       /* use value */
7945 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7946 +#endif
7947                 } else {
7948                         xfs_warn(mp, "unknown mount option [%s].", this_char);
7949                         return EINVAL;
7950 @@ -1162,6 +1182,16 @@ xfs_fs_remount(
7951                 case Opt_nobarrier:
7952                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
7953                         break;
7954 +               case Opt_tag:
7955 +                       if (!(sb->s_flags & MS_TAGGED)) {
7956 +                               printk(KERN_INFO
7957 +                                       "XFS: %s: tagging not permitted on remount.\n",
7958 +                                       sb->s_id);
7959 +                               return -EINVAL;
7960 +                       }
7961 +                       break;
7962 +               case Opt_notag:
7963 +                       break;
7964                 default:
7965                         /*
7966                          * Logically we would return an error here to prevent
7967 @@ -1377,6 +1407,9 @@ xfs_fs_fill_super(
7968         if (error)
7969                 goto out_free_sb;
7970  
7971 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
7972 +               sb->s_flags |= MS_TAGGED;
7973 +
7974         /*
7975          * we must configure the block size in the superblock before we run the
7976          * full mount process as the mount process can lookup and cache inodes.
7977 diff -NurpP --minimal linux-3.1.1/fs/xfs/xfs_vnodeops.c linux-3.1.1-vs2.3.2/fs/xfs/xfs_vnodeops.c
7978 --- linux-3.1.1/fs/xfs/xfs_vnodeops.c   2011-10-24 18:45:31.000000000 +0200
7979 +++ linux-3.1.1-vs2.3.2/fs/xfs/xfs_vnodeops.c   2011-10-24 18:53:33.000000000 +0200
7980 @@ -107,6 +107,78 @@ xfs_readlink_bmap(
7981         return error;
7982  }
7983  
7984 +
7985 +STATIC void
7986 +xfs_get_inode_flags(
7987 +       xfs_inode_t     *ip)
7988 +{
7989 +       struct inode    *inode = VFS_I(ip);
7990 +       unsigned int    flags = inode->i_flags;
7991 +       unsigned int    vflags = inode->i_vflags;
7992 +
7993 +       if (flags & S_IMMUTABLE)
7994 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
7995 +       else
7996 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
7997 +       if (flags & S_IXUNLINK)
7998 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
7999 +       else
8000 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
8001 +
8002 +       if (vflags & V_BARRIER)
8003 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
8004 +       else
8005 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
8006 +       if (vflags & V_COW)
8007 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
8008 +       else
8009 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
8010 +}
8011 +
8012 +int
8013 +xfs_sync_flags(
8014 +       struct inode            *inode,
8015 +       int                     flags,
8016 +       int                     vflags)
8017 +{
8018 +       struct xfs_inode        *ip = XFS_I(inode);
8019 +       struct xfs_mount        *mp = ip->i_mount;
8020 +       struct xfs_trans        *tp;
8021 +       unsigned int            lock_flags = 0;
8022 +       int                     code;
8023 +
8024 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
8025 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
8026 +       if (code)
8027 +               goto error_out;
8028 +
8029 +       xfs_ilock(ip, XFS_ILOCK_EXCL);
8030 +
8031 +       xfs_trans_ijoin(tp, ip);
8032 +
8033 +       inode->i_flags = flags;
8034 +       inode->i_vflags = vflags;
8035 +       xfs_get_inode_flags(ip);
8036 +
8037 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
8038 +       xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
8039 +
8040 +       XFS_STATS_INC(xs_ig_attrchg);
8041 +
8042 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
8043 +               xfs_trans_set_sync(tp);
8044 +       code = xfs_trans_commit(tp, 0);
8045 +       xfs_iunlock(ip, XFS_ILOCK_EXCL);
8046 +       return code;
8047 +
8048 +error_out:
8049 +       xfs_trans_cancel(tp, 0);
8050 +       if (lock_flags)
8051 +               xfs_iunlock(ip, XFS_ILOCK_EXCL);
8052 +       return code;
8053 +}
8054 +
8055 +
8056  int
8057  xfs_readlink(
8058         xfs_inode_t     *ip,
8059 diff -NurpP --minimal linux-3.1.1/include/asm-generic/tlb.h linux-3.1.1-vs2.3.2/include/asm-generic/tlb.h
8060 --- linux-3.1.1/include/asm-generic/tlb.h       2011-07-22 11:18:10.000000000 +0200
8061 +++ linux-3.1.1-vs2.3.2/include/asm-generic/tlb.h       2011-10-24 18:53:33.000000000 +0200
8062 @@ -16,6 +16,7 @@
8063  #define _ASM_GENERIC__TLB_H
8064  
8065  #include <linux/swap.h>
8066 +#include <linux/vs_memory.h>
8067  #include <asm/pgalloc.h>
8068  #include <asm/tlbflush.h>
8069  
8070 diff -NurpP --minimal linux-3.1.1/include/linux/Kbuild linux-3.1.1-vs2.3.2/include/linux/Kbuild
8071 --- linux-3.1.1/include/linux/Kbuild    2011-10-24 18:45:31.000000000 +0200
8072 +++ linux-3.1.1-vs2.3.2/include/linux/Kbuild    2011-10-24 18:53:33.000000000 +0200
8073 @@ -17,6 +17,7 @@ header-y += netfilter_bridge/
8074  header-y += netfilter_ipv4/
8075  header-y += netfilter_ipv6/
8076  header-y += usb/
8077 +header-y += vserver/
8078  header-y += wimax/
8079  
8080  objhdr-y += version.h
8081 diff -NurpP --minimal linux-3.1.1/include/linux/capability.h linux-3.1.1-vs2.3.2/include/linux/capability.h
8082 --- linux-3.1.1/include/linux/capability.h      2011-07-22 11:18:10.000000000 +0200
8083 +++ linux-3.1.1-vs2.3.2/include/linux/capability.h      2011-10-24 18:53:33.000000000 +0200
8084 @@ -279,6 +279,7 @@ struct cpu_vfs_cap_data {
8085     arbitrary SCSI commands */
8086  /* Allow setting encryption key on loopback filesystem */
8087  /* Allow setting zone reclaim policy */
8088 +/* Allow the selection of a security context */
8089  
8090  #define CAP_SYS_ADMIN        21
8091  
8092 @@ -362,7 +363,12 @@ struct cpu_vfs_cap_data {
8093  
8094  #define CAP_LAST_CAP         CAP_WAKE_ALARM
8095  
8096 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
8097 +/* Allow context manipulations */
8098 +/* Allow changing context info on files */
8099 +
8100 +#define CAP_CONTEXT         63
8101 +
8102 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
8103  
8104  /*
8105   * Bit location of each capability (used by user-space library and kernel)
8106 diff -NurpP --minimal linux-3.1.1/include/linux/cred.h linux-3.1.1-vs2.3.2/include/linux/cred.h
8107 --- linux-3.1.1/include/linux/cred.h    2011-10-24 18:45:31.000000000 +0200
8108 +++ linux-3.1.1-vs2.3.2/include/linux/cred.h    2011-10-24 18:53:33.000000000 +0200
8109 @@ -156,6 +156,7 @@ extern void exit_creds(struct task_struc
8110  extern int copy_creds(struct task_struct *, unsigned long);
8111  extern const struct cred *get_task_cred(struct task_struct *);
8112  extern struct cred *cred_alloc_blank(void);
8113 +extern struct cred *__prepare_creds(const struct cred *);
8114  extern struct cred *prepare_creds(void);
8115  extern struct cred *prepare_exec_creds(void);
8116  extern int commit_creds(struct cred *);
8117 @@ -209,6 +210,31 @@ static inline void validate_process_cred
8118  }
8119  #endif
8120  
8121 +static inline void set_cred_subscribers(struct cred *cred, int n)
8122 +{
8123 +#ifdef CONFIG_DEBUG_CREDENTIALS
8124 +       atomic_set(&cred->subscribers, n);
8125 +#endif
8126 +}
8127 +
8128 +static inline int read_cred_subscribers(const struct cred *cred)
8129 +{
8130 +#ifdef CONFIG_DEBUG_CREDENTIALS
8131 +       return atomic_read(&cred->subscribers);
8132 +#else
8133 +       return 0;
8134 +#endif
8135 +}
8136 +
8137 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
8138 +{
8139 +#ifdef CONFIG_DEBUG_CREDENTIALS
8140 +       struct cred *cred = (struct cred *) _cred;
8141 +
8142 +       atomic_add(n, &cred->subscribers);
8143 +#endif
8144 +}
8145 +
8146  /**
8147   * get_new_cred - Get a reference on a new set of credentials
8148   * @cred: The new credentials to reference
8149 diff -NurpP --minimal linux-3.1.1/include/linux/devpts_fs.h linux-3.1.1-vs2.3.2/include/linux/devpts_fs.h
8150 --- linux-3.1.1/include/linux/devpts_fs.h       2008-12-25 00:26:37.000000000 +0100
8151 +++ linux-3.1.1-vs2.3.2/include/linux/devpts_fs.h       2011-10-24 18:53:33.000000000 +0200
8152 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
8153  
8154  #endif
8155  
8156 -
8157  #endif /* _LINUX_DEVPTS_FS_H */
8158 diff -NurpP --minimal linux-3.1.1/include/linux/ext2_fs.h linux-3.1.1-vs2.3.2/include/linux/ext2_fs.h
8159 --- linux-3.1.1/include/linux/ext2_fs.h 2011-11-15 16:44:52.000000000 +0100
8160 +++ linux-3.1.1-vs2.3.2/include/linux/ext2_fs.h 2011-11-15 17:08:44.000000000 +0100
8161 @@ -190,8 +190,12 @@ struct ext2_group_desc
8162  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
8163  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
8164  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
8165 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
8166  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
8167  
8168 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
8169 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
8170 +
8171  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
8172  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
8173  
8174 @@ -275,7 +279,8 @@ struct ext2_inode {
8175                         __u16   i_pad1;
8176                         __le16  l_i_uid_high;   /* these 2 fields    */
8177                         __le16  l_i_gid_high;   /* were reserved2[0] */
8178 -                       __u32   l_i_reserved2;
8179 +                       __le16  l_i_tag;        /* Context Tag */
8180 +                       __u16   l_i_reserved2;
8181                 } linux2;
8182                 struct {
8183                         __u8    h_i_frag;       /* Fragment number */
8184 @@ -304,6 +309,7 @@ struct ext2_inode {
8185  #define i_gid_low      i_gid
8186  #define i_uid_high     osd2.linux2.l_i_uid_high
8187  #define i_gid_high     osd2.linux2.l_i_gid_high
8188 +#define i_raw_tag      osd2.linux2.l_i_tag
8189  #define i_reserved2    osd2.linux2.l_i_reserved2
8190  #endif
8191  
8192 @@ -348,6 +354,7 @@ struct ext2_inode {
8193  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
8194  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
8195  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
8196 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
8197  
8198  
8199  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
8200 diff -NurpP --minimal linux-3.1.1/include/linux/ext3_fs.h linux-3.1.1-vs2.3.2/include/linux/ext3_fs.h
8201 --- linux-3.1.1/include/linux/ext3_fs.h 2011-11-15 16:44:52.000000000 +0100
8202 +++ linux-3.1.1-vs2.3.2/include/linux/ext3_fs.h 2011-11-15 17:08:44.000000000 +0100
8203 @@ -173,10 +173,14 @@ struct ext3_group_desc
8204  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
8205  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
8206  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
8207 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
8208  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
8209  
8210 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
8211 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
8212 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
8213 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
8214 +
8215 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
8216 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
8217  
8218  /* Flags that should be inherited by new inodes from their parent. */
8219  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
8220 @@ -312,7 +316,8 @@ struct ext3_inode {
8221                         __u16   i_pad1;
8222                         __le16  l_i_uid_high;   /* these 2 fields    */
8223                         __le16  l_i_gid_high;   /* were reserved2[0] */
8224 -                       __u32   l_i_reserved2;
8225 +                       __le16  l_i_tag;        /* Context Tag */
8226 +                       __u16   l_i_reserved2;
8227                 } linux2;
8228                 struct {
8229                         __u8    h_i_frag;       /* Fragment number */
8230 @@ -343,6 +348,7 @@ struct ext3_inode {
8231  #define i_gid_low      i_gid
8232  #define i_uid_high     osd2.linux2.l_i_uid_high
8233  #define i_gid_high     osd2.linux2.l_i_gid_high
8234 +#define i_raw_tag      osd2.linux2.l_i_tag
8235  #define i_reserved2    osd2.linux2.l_i_reserved2
8236  
8237  #elif defined(__GNU__)
8238 @@ -405,6 +411,7 @@ struct ext3_inode {
8239  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
8240  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
8241                                                   * error in ordered mode */
8242 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
8243  
8244  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
8245  #ifndef _LINUX_EXT2_FS_H
8246 @@ -918,6 +925,7 @@ extern void ext3_get_inode_flags(struct 
8247  extern void ext3_set_aops(struct inode *inode);
8248  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
8249                        u64 start, u64 len);
8250 +extern int ext3_sync_flags(struct inode *, int, int);
8251  
8252  /* ioctl.c */
8253  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
8254 diff -NurpP --minimal linux-3.1.1/include/linux/fs.h linux-3.1.1-vs2.3.2/include/linux/fs.h
8255 --- linux-3.1.1/include/linux/fs.h      2011-10-24 18:45:32.000000000 +0200
8256 +++ linux-3.1.1-vs2.3.2/include/linux/fs.h      2011-10-24 18:53:33.000000000 +0200
8257 @@ -209,6 +209,9 @@ struct inodes_stat_t {
8258  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
8259  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
8260  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
8261 +#define MS_TAGGED      (1<<25) /* use generic inode tagging */
8262 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
8263 +#define MS_NOTAGCHECK  (1<<27) /* don't check tags */
8264  #define MS_NOSEC       (1<<28)
8265  #define MS_BORN                (1<<29)
8266  #define MS_ACTIVE      (1<<30)
8267 @@ -240,6 +243,14 @@ struct inodes_stat_t {
8268  #define S_IMA          1024    /* Inode has an associated IMA struct */
8269  #define S_AUTOMOUNT    2048    /* Automount/referral quasi-directory */
8270  #define S_NOSEC                4096    /* no suid or xattr security attributes */
8271 +#define S_IXUNLINK     8192    /* Immutable Invert on unlink */
8272 +
8273 +/* Linux-VServer related Inode flags */
8274 +
8275 +#define V_VALID                1
8276 +#define V_XATTR                2
8277 +#define V_BARRIER      4       /* Barrier for chroot() */
8278 +#define V_COW          8       /* Copy on Write */
8279  
8280  /*
8281   * Note that nosuid etc flags are inode-specific: setting some file-system
8282 @@ -262,12 +273,15 @@ struct inodes_stat_t {
8283  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
8284                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
8285  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
8286 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8287 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
8288 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8289 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
8290 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
8291  
8292  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
8293  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
8294  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
8295 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
8296 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
8297  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
8298  
8299  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
8300 @@ -278,6 +292,16 @@ struct inodes_stat_t {
8301  #define IS_AUTOMOUNT(inode)    ((inode)->i_flags & S_AUTOMOUNT)
8302  #define IS_NOSEC(inode)                ((inode)->i_flags & S_NOSEC)
8303  
8304 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
8305 +
8306 +#ifdef CONFIG_VSERVER_COWBL
8307 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
8308 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
8309 +#else
8310 +#  define IS_COW(inode)                (0)
8311 +#  define IS_COW_LINK(inode)   (0)
8312 +#endif
8313 +
8314  /* the read-only stuff doesn't really belong here, but any other place is
8315     probably as bad and I don't want to create yet another include file. */
8316  
8317 @@ -363,11 +387,14 @@ struct inodes_stat_t {
8318  #define FS_EXTENT_FL                   0x00080000 /* Extents */
8319  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
8320  #define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
8321 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
8322  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
8323  
8324 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
8325 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
8326 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
8327 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
8328  
8329 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
8330 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
8331  
8332  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
8333  #define SYNC_FILE_RANGE_WRITE          2
8334 @@ -448,6 +475,7 @@ typedef void (dio_iodone_t)(struct kiocb
8335  #define ATTR_KILL_PRIV (1 << 14)
8336  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
8337  #define ATTR_TIMES_SET (1 << 16)
8338 +#define ATTR_TAG       (1 << 17)
8339  
8340  /*
8341   * This is the Inode Attributes structure, used for notify_change().  It
8342 @@ -463,6 +491,7 @@ struct iattr {
8343         umode_t         ia_mode;
8344         uid_t           ia_uid;
8345         gid_t           ia_gid;
8346 +       tag_t           ia_tag;
8347         loff_t          ia_size;
8348         struct timespec ia_atime;
8349         struct timespec ia_mtime;
8350 @@ -476,6 +505,9 @@ struct iattr {
8351         struct file     *ia_file;
8352  };
8353  
8354 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
8355 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
8356 +
8357  /*
8358   * Includes for diskquotas.
8359   */
8360 @@ -750,7 +782,9 @@ struct inode {
8361         unsigned short          i_opflags;
8362         uid_t                   i_uid;
8363         gid_t                   i_gid;
8364 -       unsigned int            i_flags;
8365 +       tag_t                   i_tag;
8366 +       unsigned short          i_flags;
8367 +       unsigned short          i_vflags;
8368  
8369  #ifdef CONFIG_FS_POSIX_ACL
8370         struct posix_acl        *i_acl;
8371 @@ -769,6 +803,7 @@ struct inode {
8372         unsigned long           i_ino;
8373         unsigned int            i_nlink;
8374         dev_t                   i_rdev;
8375 +       dev_t                   i_mdev;
8376         loff_t                  i_size;
8377         struct timespec         i_atime;
8378         struct timespec         i_mtime;
8379 @@ -906,12 +941,12 @@ static inline void i_size_write(struct i
8380  
8381  static inline unsigned iminor(const struct inode *inode)
8382  {
8383 -       return MINOR(inode->i_rdev);
8384 +       return MINOR(inode->i_mdev);
8385  }
8386  
8387  static inline unsigned imajor(const struct inode *inode)
8388  {
8389 -       return MAJOR(inode->i_rdev);
8390 +       return MAJOR(inode->i_mdev);
8391  }
8392  
8393  extern struct block_device *I_BDEV(struct inode *inode);
8394 @@ -973,6 +1008,7 @@ struct file {
8395         loff_t                  f_pos;
8396         struct fown_struct      f_owner;
8397         const struct cred       *f_cred;
8398 +       xid_t                   f_xid;
8399         struct file_ra_state    f_ra;
8400  
8401         u64                     f_version;
8402 @@ -1117,6 +1153,7 @@ struct file_lock {
8403         struct file *fl_file;
8404         loff_t fl_start;
8405         loff_t fl_end;
8406 +       xid_t fl_xid;
8407  
8408         struct fasync_struct *  fl_fasync; /* for lease break notifications */
8409         unsigned long fl_break_time;    /* for nonblocking lease breaks */
8410 @@ -1615,6 +1652,7 @@ struct inode_operations {
8411         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
8412         ssize_t (*listxattr) (struct dentry *, char *, size_t);
8413         int (*removexattr) (struct dentry *, const char *);
8414 +       int (*sync_flags) (struct inode *, int, int);
8415         void (*truncate_range)(struct inode *, loff_t, loff_t);
8416         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
8417                       u64 len);
8418 @@ -1633,6 +1671,7 @@ extern ssize_t vfs_readv(struct file *, 
8419                 unsigned long, loff_t *);
8420  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
8421                 unsigned long, loff_t *);
8422 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
8423  
8424  struct super_operations {
8425         struct inode *(*alloc_inode)(struct super_block *sb);
8426 @@ -2505,6 +2544,7 @@ extern int dcache_dir_open(struct inode 
8427  extern int dcache_dir_close(struct inode *, struct file *);
8428  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
8429  extern int dcache_readdir(struct file *, void *, filldir_t);
8430 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
8431  extern int simple_setattr(struct dentry *, struct iattr *);
8432  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
8433  extern int simple_statfs(struct dentry *, struct kstatfs *);
8434 diff -NurpP --minimal linux-3.1.1/include/linux/gfs2_ondisk.h linux-3.1.1-vs2.3.2/include/linux/gfs2_ondisk.h
8435 --- linux-3.1.1/include/linux/gfs2_ondisk.h     2010-07-07 18:31:55.000000000 +0200
8436 +++ linux-3.1.1-vs2.3.2/include/linux/gfs2_ondisk.h     2011-10-24 18:53:33.000000000 +0200
8437 @@ -211,6 +211,9 @@ enum {
8438         gfs2fl_NoAtime          = 7,
8439         gfs2fl_Sync             = 8,
8440         gfs2fl_System           = 9,
8441 +       gfs2fl_IXUnlink         = 16,
8442 +       gfs2fl_Barrier          = 17,
8443 +       gfs2fl_Cow              = 18,
8444         gfs2fl_TruncInProg      = 29,
8445         gfs2fl_InheritDirectio  = 30,
8446         gfs2fl_InheritJdata     = 31,
8447 @@ -227,6 +230,9 @@ enum {
8448  #define GFS2_DIF_NOATIME               0x00000080
8449  #define GFS2_DIF_SYNC                  0x00000100
8450  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
8451 +#define GFS2_DIF_IXUNLINK              0x00010000
8452 +#define GFS2_DIF_BARRIER               0x00020000
8453 +#define GFS2_DIF_COW                   0x00040000
8454  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
8455  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000
8456  #define GFS2_DIF_INHERIT_JDATA         0x80000000
8457 diff -NurpP --minimal linux-3.1.1/include/linux/if_tun.h linux-3.1.1-vs2.3.2/include/linux/if_tun.h
8458 --- linux-3.1.1/include/linux/if_tun.h  2010-08-02 16:52:54.000000000 +0200
8459 +++ linux-3.1.1-vs2.3.2/include/linux/if_tun.h  2011-10-24 18:53:33.000000000 +0200
8460 @@ -53,6 +53,7 @@
8461  #define TUNDETACHFILTER _IOW('T', 214, struct sock_fprog)
8462  #define TUNGETVNETHDRSZ _IOR('T', 215, int)
8463  #define TUNSETVNETHDRSZ _IOW('T', 216, int)
8464 +#define TUNSETNID     _IOW('T', 217, int)
8465  
8466  /* TUNSETIFF ifr flags */
8467  #define IFF_TUN                0x0001
8468 diff -NurpP --minimal linux-3.1.1/include/linux/init_task.h linux-3.1.1-vs2.3.2/include/linux/init_task.h
8469 --- linux-3.1.1/include/linux/init_task.h       2011-10-24 18:45:32.000000000 +0200
8470 +++ linux-3.1.1-vs2.3.2/include/linux/init_task.h       2011-10-24 18:53:33.000000000 +0200
8471 @@ -192,6 +192,10 @@ extern struct cred init_cred;
8472         INIT_FTRACE_GRAPH                                               \
8473         INIT_TRACE_RECURSION                                            \
8474         INIT_TASK_RCU_PREEMPT(tsk)                                      \
8475 +       .xid            = 0,                                            \
8476 +       .vx_info        = NULL,                                         \
8477 +       .nid            = 0,                                            \
8478 +       .nx_info        = NULL,                                         \
8479  }
8480  
8481  
8482 diff -NurpP --minimal linux-3.1.1/include/linux/ipc.h linux-3.1.1-vs2.3.2/include/linux/ipc.h
8483 --- linux-3.1.1/include/linux/ipc.h     2009-12-03 20:02:55.000000000 +0100
8484 +++ linux-3.1.1-vs2.3.2/include/linux/ipc.h     2011-10-24 18:53:33.000000000 +0200
8485 @@ -91,6 +91,7 @@ struct kern_ipc_perm
8486         key_t           key;
8487         uid_t           uid;
8488         gid_t           gid;
8489 +       xid_t           xid;
8490         uid_t           cuid;
8491         gid_t           cgid;
8492         mode_t          mode; 
8493 diff -NurpP --minimal linux-3.1.1/include/linux/ipc_namespace.h linux-3.1.1-vs2.3.2/include/linux/ipc_namespace.h
8494 --- linux-3.1.1/include/linux/ipc_namespace.h   2011-10-24 18:45:32.000000000 +0200
8495 +++ linux-3.1.1-vs2.3.2/include/linux/ipc_namespace.h   2011-10-24 18:53:33.000000000 +0200
8496 @@ -101,7 +101,8 @@ static inline int mq_init_ns(struct ipc_
8497  
8498  #if defined(CONFIG_IPC_NS)
8499  extern struct ipc_namespace *copy_ipcs(unsigned long flags,
8500 -                                      struct task_struct *tsk);
8501 +                                      struct ipc_namespace *old_ns,
8502 +                                      struct user_namespace *user_ns);
8503  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
8504  {
8505         if (ns)
8506 @@ -112,12 +113,13 @@ static inline struct ipc_namespace *get_
8507  extern void put_ipc_ns(struct ipc_namespace *ns);
8508  #else
8509  static inline struct ipc_namespace *copy_ipcs(unsigned long flags,
8510 -                                             struct task_struct *tsk)
8511 +                                             struct ipc_namespace *old_ns,
8512 +                                             struct user_namespace *user_ns)
8513  {
8514         if (flags & CLONE_NEWIPC)
8515                 return ERR_PTR(-EINVAL);
8516  
8517 -       return tsk->nsproxy->ipc_ns;
8518 +       return old_ns;
8519  }
8520  
8521  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
8522 diff -NurpP --minimal linux-3.1.1/include/linux/loop.h linux-3.1.1-vs2.3.2/include/linux/loop.h
8523 --- linux-3.1.1/include/linux/loop.h    2011-10-24 18:45:32.000000000 +0200
8524 +++ linux-3.1.1-vs2.3.2/include/linux/loop.h    2011-10-24 18:53:33.000000000 +0200
8525 @@ -45,6 +45,7 @@ struct loop_device {
8526         struct loop_func_table *lo_encryption;
8527         __u32           lo_init[2];
8528         uid_t           lo_key_owner;   /* Who set the key */
8529 +       xid_t           lo_xid;
8530         int             (*ioctl)(struct loop_device *, int cmd, 
8531                                  unsigned long arg); 
8532  
8533 diff -NurpP --minimal linux-3.1.1/include/linux/magic.h linux-3.1.1-vs2.3.2/include/linux/magic.h
8534 --- linux-3.1.1/include/linux/magic.h   2011-05-22 16:17:55.000000000 +0200
8535 +++ linux-3.1.1-vs2.3.2/include/linux/magic.h   2011-10-24 18:53:33.000000000 +0200
8536 @@ -3,7 +3,7 @@
8537  
8538  #define ADFS_SUPER_MAGIC       0xadf5
8539  #define AFFS_SUPER_MAGIC       0xadff
8540 -#define AFS_SUPER_MAGIC                0x5346414F
8541 +#define AFS_SUPER_MAGIC                0x5346414F
8542  #define AUTOFS_SUPER_MAGIC     0x0187
8543  #define CODA_SUPER_MAGIC       0x73757245
8544  #define CRAMFS_MAGIC           0x28cd3d45      /* some random number */
8545 @@ -41,6 +41,7 @@
8546  #define NFS_SUPER_MAGIC                0x6969
8547  #define OPENPROM_SUPER_MAGIC   0x9fa1
8548  #define PROC_SUPER_MAGIC       0x9fa0
8549 +#define DEVPTS_SUPER_MAGIC     0x1cd1
8550  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
8551  
8552  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
8553 diff -NurpP --minimal linux-3.1.1/include/linux/major.h linux-3.1.1-vs2.3.2/include/linux/major.h
8554 --- linux-3.1.1/include/linux/major.h   2009-09-10 15:26:25.000000000 +0200
8555 +++ linux-3.1.1-vs2.3.2/include/linux/major.h   2011-10-24 18:53:33.000000000 +0200
8556 @@ -15,6 +15,7 @@
8557  #define HD_MAJOR               IDE0_MAJOR
8558  #define PTY_SLAVE_MAJOR                3
8559  #define TTY_MAJOR              4
8560 +#define VROOT_MAJOR            4
8561  #define TTYAUX_MAJOR           5
8562  #define LP_MAJOR               6
8563  #define VCS_MAJOR              7
8564 diff -NurpP --minimal linux-3.1.1/include/linux/memcontrol.h linux-3.1.1-vs2.3.2/include/linux/memcontrol.h
8565 --- linux-3.1.1/include/linux/memcontrol.h      2011-10-24 18:45:32.000000000 +0200
8566 +++ linux-3.1.1-vs2.3.2/include/linux/memcontrol.h      2011-10-24 18:53:33.000000000 +0200
8567 @@ -84,6 +84,13 @@ extern struct mem_cgroup *try_get_mem_cg
8568  extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
8569  extern struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm);
8570  
8571 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
8572 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
8573 +
8574 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
8575 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
8576 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
8577 +
8578  static inline
8579  int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
8580  {
8581 diff -NurpP --minimal linux-3.1.1/include/linux/mm_types.h linux-3.1.1-vs2.3.2/include/linux/mm_types.h
8582 --- linux-3.1.1/include/linux/mm_types.h        2011-11-15 16:44:52.000000000 +0100
8583 +++ linux-3.1.1-vs2.3.2/include/linux/mm_types.h        2011-11-15 17:08:44.000000000 +0100
8584 @@ -314,6 +314,7 @@ struct mm_struct {
8585  
8586         /* Architecture-specific MM context */
8587         mm_context_t context;
8588 +       struct vx_info *mm_vx_info;
8589  
8590         /* Swap token stuff */
8591         /*
8592 diff -NurpP --minimal linux-3.1.1/include/linux/mmzone.h linux-3.1.1-vs2.3.2/include/linux/mmzone.h
8593 --- linux-3.1.1/include/linux/mmzone.h  2011-10-24 18:45:32.000000000 +0200
8594 +++ linux-3.1.1-vs2.3.2/include/linux/mmzone.h  2011-10-24 18:53:33.000000000 +0200
8595 @@ -660,6 +660,13 @@ typedef struct pglist_data {
8596         __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
8597  })
8598  
8599 +#define node_start_pfn(nid)    (NODE_DATA(nid)->node_start_pfn)
8600 +
8601 +#define node_end_pfn(nid) ({\
8602 +       pg_data_t *__pgdat = NODE_DATA(nid);\
8603 +       __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
8604 +})
8605 +
8606  #include <linux/memory_hotplug.h>
8607  
8608  extern struct mutex zonelists_mutex;
8609 diff -NurpP --minimal linux-3.1.1/include/linux/mount.h linux-3.1.1-vs2.3.2/include/linux/mount.h
8610 --- linux-3.1.1/include/linux/mount.h   2011-10-24 18:45:32.000000000 +0200
8611 +++ linux-3.1.1-vs2.3.2/include/linux/mount.h   2011-10-24 18:53:33.000000000 +0200
8612 @@ -52,6 +52,9 @@ struct mnt_pcp {
8613         int mnt_writers;
8614  };
8615  
8616 +#define MNT_TAGID      0x10000
8617 +#define MNT_NOTAG      0x20000
8618 +
8619  struct vfsmount {
8620         struct list_head mnt_hash;
8621         struct vfsmount *mnt_parent;    /* fs we are mounted on */
8622 @@ -86,6 +89,7 @@ struct vfsmount {
8623         int mnt_expiry_mark;            /* true if marked for expiry */
8624         int mnt_pinned;
8625         int mnt_ghosts;
8626 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
8627  };
8628  
8629  struct file; /* forward dec */
8630 diff -NurpP --minimal linux-3.1.1/include/linux/net.h linux-3.1.1-vs2.3.2/include/linux/net.h
8631 --- linux-3.1.1/include/linux/net.h     2011-07-22 11:18:11.000000000 +0200
8632 +++ linux-3.1.1-vs2.3.2/include/linux/net.h     2011-10-24 18:53:33.000000000 +0200
8633 @@ -72,6 +72,7 @@ struct net;
8634  #define SOCK_NOSPACE           2
8635  #define SOCK_PASSCRED          3
8636  #define SOCK_PASSSEC           4
8637 +#define SOCK_USER_SOCKET       5
8638  
8639  #ifndef ARCH_HAS_SOCKET_TYPES
8640  /**
8641 diff -NurpP --minimal linux-3.1.1/include/linux/netdevice.h linux-3.1.1-vs2.3.2/include/linux/netdevice.h
8642 --- linux-3.1.1/include/linux/netdevice.h       2011-10-24 18:45:32.000000000 +0200
8643 +++ linux-3.1.1-vs2.3.2/include/linux/netdevice.h       2011-10-24 18:53:33.000000000 +0200
8644 @@ -1641,6 +1641,7 @@ extern void               netdev_resync_ops(struct ne
8645  
8646  extern struct net_device       *dev_get_by_index(struct net *net, int ifindex);
8647  extern struct net_device       *__dev_get_by_index(struct net *net, int ifindex);
8648 +extern struct net_device       *dev_get_by_index_real_rcu(struct net *net, int ifindex);
8649  extern struct net_device       *dev_get_by_index_rcu(struct net *net, int ifindex);
8650  extern int             dev_restart(struct net_device *dev);
8651  #ifdef CONFIG_NETPOLL_TRAP
8652 diff -NurpP --minimal linux-3.1.1/include/linux/nfs_mount.h linux-3.1.1-vs2.3.2/include/linux/nfs_mount.h
8653 --- linux-3.1.1/include/linux/nfs_mount.h       2011-01-05 21:50:31.000000000 +0100
8654 +++ linux-3.1.1-vs2.3.2/include/linux/nfs_mount.h       2011-10-24 18:53:33.000000000 +0200
8655 @@ -63,7 +63,8 @@ struct nfs_mount_data {
8656  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
8657  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
8658  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
8659 -#define NFS_MOUNT_FLAGMASK     0xFFFF
8660 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
8661 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
8662  
8663  /* The following are for internal use only */
8664  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
8665 diff -NurpP --minimal linux-3.1.1/include/linux/nsproxy.h linux-3.1.1-vs2.3.2/include/linux/nsproxy.h
8666 --- linux-3.1.1/include/linux/nsproxy.h 2011-10-24 18:45:32.000000000 +0200
8667 +++ linux-3.1.1-vs2.3.2/include/linux/nsproxy.h 2011-10-24 18:53:33.000000000 +0200
8668 @@ -3,6 +3,7 @@
8669  
8670  #include <linux/spinlock.h>
8671  #include <linux/sched.h>
8672 +#include <linux/vserver/debug.h>
8673  
8674  struct mnt_namespace;
8675  struct uts_namespace;
8676 @@ -63,6 +64,7 @@ static inline struct nsproxy *task_nspro
8677  }
8678  
8679  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
8680 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
8681  void exit_task_namespaces(struct task_struct *tsk);
8682  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
8683  void free_nsproxy(struct nsproxy *ns);
8684 @@ -70,16 +72,26 @@ int unshare_nsproxy_namespaces(unsigned 
8685         struct fs_struct *);
8686  int __init nsproxy_cache_init(void);
8687  
8688 -static inline void put_nsproxy(struct nsproxy *ns)
8689 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
8690 +
8691 +static inline void __get_nsproxy(struct nsproxy *ns,
8692 +       const char *_file, int _line)
8693  {
8694 -       if (atomic_dec_and_test(&ns->count)) {
8695 -               free_nsproxy(ns);
8696 -       }
8697 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
8698 +               ns, atomic_read(&ns->count), _file, _line);
8699 +       atomic_inc(&ns->count);
8700  }
8701  
8702 -static inline void get_nsproxy(struct nsproxy *ns)
8703 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
8704 +
8705 +static inline void __put_nsproxy(struct nsproxy *ns,
8706 +       const char *_file, int _line)
8707  {
8708 -       atomic_inc(&ns->count);
8709 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
8710 +               ns, atomic_read(&ns->count), _file, _line);
8711 +       if (atomic_dec_and_test(&ns->count)) {
8712 +               free_nsproxy(ns);
8713 +       }
8714  }
8715  
8716  #endif
8717 diff -NurpP --minimal linux-3.1.1/include/linux/pid.h linux-3.1.1-vs2.3.2/include/linux/pid.h
8718 --- linux-3.1.1/include/linux/pid.h     2011-07-22 11:18:11.000000000 +0200
8719 +++ linux-3.1.1-vs2.3.2/include/linux/pid.h     2011-10-24 18:53:33.000000000 +0200
8720 @@ -8,7 +8,8 @@ enum pid_type
8721         PIDTYPE_PID,
8722         PIDTYPE_PGID,
8723         PIDTYPE_SID,
8724 -       PIDTYPE_MAX
8725 +       PIDTYPE_MAX,
8726 +       PIDTYPE_REALPID
8727  };
8728  
8729  /*
8730 @@ -171,6 +172,7 @@ static inline pid_t pid_nr(struct pid *p
8731  }
8732  
8733  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
8734 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
8735  pid_t pid_vnr(struct pid *pid);
8736  
8737  #define do_each_pid_task(pid, type, task)                              \
8738 diff -NurpP --minimal linux-3.1.1/include/linux/proc_fs.h linux-3.1.1-vs2.3.2/include/linux/proc_fs.h
8739 --- linux-3.1.1/include/linux/proc_fs.h 2011-10-24 18:45:32.000000000 +0200
8740 +++ linux-3.1.1-vs2.3.2/include/linux/proc_fs.h 2011-10-24 18:53:33.000000000 +0200
8741 @@ -54,6 +54,7 @@ struct proc_dir_entry {
8742         nlink_t nlink;
8743         uid_t uid;
8744         gid_t gid;
8745 +       int vx_flags;
8746         loff_t size;
8747         const struct inode_operations *proc_iops;
8748         /*
8749 @@ -252,12 +253,18 @@ extern const struct proc_ns_operations n
8750  extern const struct proc_ns_operations utsns_operations;
8751  extern const struct proc_ns_operations ipcns_operations;
8752  
8753 +struct vx_info;
8754 +struct nx_info;
8755 +
8756  union proc_op {
8757         int (*proc_get_link)(struct inode *, struct path *);
8758         int (*proc_read)(struct task_struct *task, char *page);
8759         int (*proc_show)(struct seq_file *m,
8760                 struct pid_namespace *ns, struct pid *pid,
8761                 struct task_struct *task);
8762 +       int (*proc_vs_read)(char *page);
8763 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
8764 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
8765  };
8766  
8767  struct ctl_table_header;
8768 @@ -265,6 +272,7 @@ struct ctl_table;
8769  
8770  struct proc_inode {
8771         struct pid *pid;
8772 +       int vx_flags;
8773         int fd;
8774         union proc_op op;
8775         struct proc_dir_entry *pde;
8776 diff -NurpP --minimal linux-3.1.1/include/linux/quotaops.h linux-3.1.1-vs2.3.2/include/linux/quotaops.h
8777 --- linux-3.1.1/include/linux/quotaops.h        2011-05-22 16:17:57.000000000 +0200
8778 +++ linux-3.1.1-vs2.3.2/include/linux/quotaops.h        2011-10-24 18:53:33.000000000 +0200
8779 @@ -8,6 +8,7 @@
8780  #define _LINUX_QUOTAOPS_
8781  
8782  #include <linux/fs.h>
8783 +#include <linux/vs_dlimit.h>
8784  
8785  #define DQUOT_SPACE_WARN       0x1
8786  #define DQUOT_SPACE_RESERVE    0x2
8787 @@ -204,11 +205,12 @@ static inline void dquot_drop(struct ino
8788  
8789  static inline int dquot_alloc_inode(const struct inode *inode)
8790  {
8791 -       return 0;
8792 +       return dl_alloc_inode(inode);
8793  }
8794  
8795  static inline void dquot_free_inode(const struct inode *inode)
8796  {
8797 +       dl_free_inode(inode);
8798  }
8799  
8800  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
8801 @@ -219,6 +221,10 @@ static inline int dquot_transfer(struct 
8802  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
8803                 int flags)
8804  {
8805 +       int ret = 0;
8806 +
8807 +       if ((ret = dl_alloc_space(inode, number)))
8808 +               return ret;
8809         if (!(flags & DQUOT_SPACE_RESERVE))
8810                 inode_add_bytes(inode, number);
8811         return 0;
8812 @@ -229,6 +235,7 @@ static inline void __dquot_free_space(st
8813  {
8814         if (!(flags & DQUOT_SPACE_RESERVE))
8815                 inode_sub_bytes(inode, number);
8816 +       dl_free_space(inode, number);
8817  }
8818  
8819  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
8820 diff -NurpP --minimal linux-3.1.1/include/linux/reboot.h linux-3.1.1-vs2.3.2/include/linux/reboot.h
8821 --- linux-3.1.1/include/linux/reboot.h  2011-10-24 18:45:32.000000000 +0200
8822 +++ linux-3.1.1-vs2.3.2/include/linux/reboot.h  2011-10-24 18:53:33.000000000 +0200
8823 @@ -33,6 +33,7 @@
8824  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
8825  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
8826  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
8827 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
8828  
8829  
8830  #ifdef __KERNEL__
8831 diff -NurpP --minimal linux-3.1.1/include/linux/reiserfs_fs.h linux-3.1.1-vs2.3.2/include/linux/reiserfs_fs.h
8832 --- linux-3.1.1/include/linux/reiserfs_fs.h     2011-10-24 18:45:32.000000000 +0200
8833 +++ linux-3.1.1-vs2.3.2/include/linux/reiserfs_fs.h     2011-10-24 18:53:33.000000000 +0200
8834 @@ -976,6 +976,11 @@ struct stat_data_v1 {
8835  #define REISERFS_COMPR_FL     FS_COMPR_FL
8836  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
8837  
8838 +/* unfortunately reiserfs sdattr is only 16 bit */
8839 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
8840 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
8841 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
8842 +
8843  /* persistent flags that file inherits from the parent directory */
8844  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
8845                                 REISERFS_SYNC_FL |      \
8846 @@ -985,6 +990,9 @@ struct stat_data_v1 {
8847                                 REISERFS_COMPR_FL |     \
8848                                 REISERFS_NOTAIL_FL )
8849  
8850 +#define REISERFS_FL_USER_VISIBLE       0x80FF
8851 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
8852 +
8853  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
8854     address blocks) */
8855  struct stat_data {
8856 @@ -2073,6 +2081,7 @@ static inline void reiserfs_update_sd(st
8857  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
8858  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
8859  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
8860 +int reiserfs_sync_flags(struct inode *inode, int, int);
8861  
8862  int __reiserfs_write_begin(struct page *page, unsigned from, unsigned len);
8863  
8864 diff -NurpP --minimal linux-3.1.1/include/linux/reiserfs_fs_sb.h linux-3.1.1-vs2.3.2/include/linux/reiserfs_fs_sb.h
8865 --- linux-3.1.1/include/linux/reiserfs_fs_sb.h  2010-02-25 11:52:07.000000000 +0100
8866 +++ linux-3.1.1-vs2.3.2/include/linux/reiserfs_fs_sb.h  2011-10-24 18:53:33.000000000 +0200
8867 @@ -476,6 +476,7 @@ enum reiserfs_mount_options {
8868         REISERFS_EXPOSE_PRIVROOT,
8869         REISERFS_BARRIER_NONE,
8870         REISERFS_BARRIER_FLUSH,
8871 +       REISERFS_TAGGED,
8872  
8873         /* Actions on error */
8874         REISERFS_ERROR_PANIC,
8875 diff -NurpP --minimal linux-3.1.1/include/linux/sched.h linux-3.1.1-vs2.3.2/include/linux/sched.h
8876 --- linux-3.1.1/include/linux/sched.h   2011-10-24 18:45:32.000000000 +0200
8877 +++ linux-3.1.1-vs2.3.2/include/linux/sched.h   2011-10-24 18:53:33.000000000 +0200
8878 @@ -1406,6 +1406,14 @@ struct task_struct {
8879  #endif
8880         seccomp_t seccomp;
8881  
8882 +/* vserver context data */
8883 +       struct vx_info *vx_info;
8884 +       struct nx_info *nx_info;
8885 +
8886 +       xid_t xid;
8887 +       nid_t nid;
8888 +       tag_t tag;
8889 +
8890  /* Thread group tracking */
8891         u32 parent_exec_id;
8892         u32 self_exec_id;
8893 @@ -1648,6 +1656,11 @@ struct pid_namespace;
8894  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
8895                         struct pid_namespace *ns);
8896  
8897 +#include <linux/vserver/base.h>
8898 +#include <linux/vserver/context.h>
8899 +#include <linux/vserver/debug.h>
8900 +#include <linux/vserver/pid.h>
8901 +
8902  static inline pid_t task_pid_nr(struct task_struct *tsk)
8903  {
8904         return tsk->pid;
8905 @@ -1661,7 +1674,8 @@ static inline pid_t task_pid_nr_ns(struc
8906  
8907  static inline pid_t task_pid_vnr(struct task_struct *tsk)
8908  {
8909 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8910 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8911 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
8912  }
8913  
8914  
8915 @@ -1674,7 +1688,7 @@ pid_t task_tgid_nr_ns(struct task_struct
8916  
8917  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
8918  {
8919 -       return pid_vnr(task_tgid(tsk));
8920 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
8921  }
8922  
8923  
8924 diff -NurpP --minimal linux-3.1.1/include/linux/shmem_fs.h linux-3.1.1-vs2.3.2/include/linux/shmem_fs.h
8925 --- linux-3.1.1/include/linux/shmem_fs.h        2011-10-24 18:45:32.000000000 +0200
8926 +++ linux-3.1.1-vs2.3.2/include/linux/shmem_fs.h        2011-10-24 18:53:33.000000000 +0200
8927 @@ -8,6 +8,9 @@
8928  
8929  /* inode in-kernel data */
8930  
8931 +#define TMPFS_SUPER_MAGIC      0x01021994
8932 +
8933 +
8934  struct shmem_inode_info {
8935         spinlock_t              lock;
8936         unsigned long           flags;
8937 diff -NurpP --minimal linux-3.1.1/include/linux/stat.h linux-3.1.1-vs2.3.2/include/linux/stat.h
8938 --- linux-3.1.1/include/linux/stat.h    2008-12-25 00:26:37.000000000 +0100
8939 +++ linux-3.1.1-vs2.3.2/include/linux/stat.h    2011-10-24 18:53:33.000000000 +0200
8940 @@ -66,6 +66,7 @@ struct kstat {
8941         unsigned int    nlink;
8942         uid_t           uid;
8943         gid_t           gid;
8944 +       tag_t           tag;
8945         dev_t           rdev;
8946         loff_t          size;
8947         struct timespec  atime;
8948 diff -NurpP --minimal linux-3.1.1/include/linux/sunrpc/auth.h linux-3.1.1-vs2.3.2/include/linux/sunrpc/auth.h
8949 --- linux-3.1.1/include/linux/sunrpc/auth.h     2011-10-24 18:45:32.000000000 +0200
8950 +++ linux-3.1.1-vs2.3.2/include/linux/sunrpc/auth.h     2011-10-24 18:53:33.000000000 +0200
8951 @@ -25,6 +25,7 @@
8952  struct auth_cred {
8953         uid_t   uid;
8954         gid_t   gid;
8955 +       tag_t   tag;
8956         struct group_info *group_info;
8957         unsigned char machine_cred : 1;
8958  };
8959 diff -NurpP --minimal linux-3.1.1/include/linux/sunrpc/clnt.h linux-3.1.1-vs2.3.2/include/linux/sunrpc/clnt.h
8960 --- linux-3.1.1/include/linux/sunrpc/clnt.h     2011-05-22 16:17:58.000000000 +0200
8961 +++ linux-3.1.1-vs2.3.2/include/linux/sunrpc/clnt.h     2011-10-24 18:53:33.000000000 +0200
8962 @@ -49,7 +49,8 @@ struct rpc_clnt {
8963         unsigned int            cl_softrtry : 1,/* soft timeouts */
8964                                 cl_discrtry : 1,/* disconnect before retry */
8965                                 cl_autobind : 1,/* use getport() */
8966 -                               cl_chatty   : 1;/* be verbose */
8967 +                               cl_chatty   : 1,/* be verbose */
8968 +                               cl_tag      : 1;/* context tagging */
8969  
8970         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
8971         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
8972 diff -NurpP --minimal linux-3.1.1/include/linux/syscalls.h linux-3.1.1-vs2.3.2/include/linux/syscalls.h
8973 --- linux-3.1.1/include/linux/syscalls.h        2011-10-24 18:45:32.000000000 +0200
8974 +++ linux-3.1.1-vs2.3.2/include/linux/syscalls.h        2011-10-24 18:53:33.000000000 +0200
8975 @@ -483,6 +483,8 @@ asmlinkage long sys_symlink(const char _
8976  asmlinkage long sys_unlink(const char __user *pathname);
8977  asmlinkage long sys_rename(const char __user *oldname,
8978                                 const char __user *newname);
8979 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
8980 +                               umode_t mode);
8981  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
8982  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
8983  
8984 diff -NurpP --minimal linux-3.1.1/include/linux/sysctl.h linux-3.1.1-vs2.3.2/include/linux/sysctl.h
8985 --- linux-3.1.1/include/linux/sysctl.h  2011-03-15 18:07:40.000000000 +0100
8986 +++ linux-3.1.1-vs2.3.2/include/linux/sysctl.h  2011-10-24 18:53:33.000000000 +0200
8987 @@ -60,6 +60,7 @@ enum
8988         CTL_ABI=9,              /* Binary emulation */
8989         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
8990         CTL_ARLAN=254,          /* arlan wireless driver */
8991 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
8992         CTL_S390DBF=5677,       /* s390 debug */
8993         CTL_SUNRPC=7249,        /* sunrpc debug */
8994         CTL_PM=9899,            /* frv power management */
8995 @@ -94,6 +95,7 @@ enum
8996  
8997         KERN_PANIC=15,          /* int: panic timeout */
8998         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
8999 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
9000  
9001         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
9002         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
9003 diff -NurpP --minimal linux-3.1.1/include/linux/sysfs.h linux-3.1.1-vs2.3.2/include/linux/sysfs.h
9004 --- linux-3.1.1/include/linux/sysfs.h   2011-10-24 18:45:32.000000000 +0200
9005 +++ linux-3.1.1-vs2.3.2/include/linux/sysfs.h   2011-10-24 18:53:33.000000000 +0200
9006 @@ -19,6 +19,8 @@
9007  #include <linux/kobject_ns.h>
9008  #include <linux/atomic.h>
9009  
9010 +#define SYSFS_SUPER_MAGIC      0x62656572
9011 +
9012  struct kobject;
9013  struct module;
9014  enum kobj_ns_type;
9015 diff -NurpP --minimal linux-3.1.1/include/linux/time.h linux-3.1.1-vs2.3.2/include/linux/time.h
9016 --- linux-3.1.1/include/linux/time.h    2011-07-22 11:18:11.000000000 +0200
9017 +++ linux-3.1.1-vs2.3.2/include/linux/time.h    2011-10-24 18:53:33.000000000 +0200
9018 @@ -256,6 +256,9 @@ static __always_inline void timespec_add
9019         a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
9020         a->tv_nsec = ns;
9021  }
9022 +
9023 +#include <linux/vs_time.h>
9024 +
9025  #endif /* __KERNEL__ */
9026  
9027  #define NFDBITS                        __NFDBITS
9028 diff -NurpP --minimal linux-3.1.1/include/linux/types.h linux-3.1.1-vs2.3.2/include/linux/types.h
9029 --- linux-3.1.1/include/linux/types.h   2011-05-22 16:17:58.000000000 +0200
9030 +++ linux-3.1.1-vs2.3.2/include/linux/types.h   2011-10-24 18:53:33.000000000 +0200
9031 @@ -40,6 +40,9 @@ typedef __kernel_uid32_t      uid_t;
9032  typedef __kernel_gid32_t       gid_t;
9033  typedef __kernel_uid16_t        uid16_t;
9034  typedef __kernel_gid16_t        gid16_t;
9035 +typedef unsigned int           xid_t;
9036 +typedef unsigned int           nid_t;
9037 +typedef unsigned int           tag_t;
9038  
9039  typedef unsigned long          uintptr_t;
9040  
9041 diff -NurpP --minimal linux-3.1.1/include/linux/utsname.h linux-3.1.1-vs2.3.2/include/linux/utsname.h
9042 --- linux-3.1.1/include/linux/utsname.h 2011-05-22 16:17:58.000000000 +0200
9043 +++ linux-3.1.1-vs2.3.2/include/linux/utsname.h 2011-10-24 18:53:33.000000000 +0200
9044 @@ -54,7 +54,8 @@ static inline void get_uts_ns(struct uts
9045  }
9046  
9047  extern struct uts_namespace *copy_utsname(unsigned long flags,
9048 -                                         struct task_struct *tsk);
9049 +                                         struct uts_namespace *old_ns,
9050 +                                         struct user_namespace *user_ns);
9051  extern void free_uts_ns(struct kref *kref);
9052  
9053  static inline void put_uts_ns(struct uts_namespace *ns)
9054 @@ -71,12 +72,13 @@ static inline void put_uts_ns(struct uts
9055  }
9056  
9057  static inline struct uts_namespace *copy_utsname(unsigned long flags,
9058 -                                                struct task_struct *tsk)
9059 +                                                struct uts_namespace *old_ns,
9060 +                                                struct user_namespace *user_ns)
9061  {
9062         if (flags & CLONE_NEWUTS)
9063                 return ERR_PTR(-EINVAL);
9064  
9065 -       return tsk->nsproxy->uts_ns;
9066 +       return old_ns;
9067  }
9068  #endif
9069  
9070 diff -NurpP --minimal linux-3.1.1/include/linux/vroot.h linux-3.1.1-vs2.3.2/include/linux/vroot.h
9071 --- linux-3.1.1/include/linux/vroot.h   1970-01-01 01:00:00.000000000 +0100
9072 +++ linux-3.1.1-vs2.3.2/include/linux/vroot.h   2011-10-24 18:53:33.000000000 +0200
9073 @@ -0,0 +1,51 @@
9074 +
9075 +/*
9076 + * include/linux/vroot.h
9077 + *
9078 + * written by Herbert Pötzl, 9/11/2002
9079 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
9080 + *
9081 + * Copyright (C) 2002-2007 by Herbert Pötzl.
9082 + * Redistribution of this file is permitted under the
9083 + * GNU General Public License.
9084 + */
9085 +
9086 +#ifndef _LINUX_VROOT_H
9087 +#define _LINUX_VROOT_H
9088 +
9089 +
9090 +#ifdef __KERNEL__
9091 +
9092 +/* Possible states of device */
9093 +enum {
9094 +       Vr_unbound,
9095 +       Vr_bound,
9096 +};
9097 +
9098 +struct vroot_device {
9099 +       int             vr_number;
9100 +       int             vr_refcnt;
9101 +
9102 +       struct semaphore        vr_ctl_mutex;
9103 +       struct block_device    *vr_device;
9104 +       int                     vr_state;
9105 +};
9106 +
9107 +
9108 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
9109 +
9110 +extern int register_vroot_grb(vroot_grb_func *);
9111 +extern int unregister_vroot_grb(vroot_grb_func *);
9112 +
9113 +#endif /* __KERNEL__ */
9114 +
9115 +#define MAX_VROOT_DEFAULT      8
9116 +
9117 +/*
9118 + * IOCTL commands --- we will commandeer 0x56 ('V')
9119 + */
9120 +
9121 +#define VROOT_SET_DEV          0x5600
9122 +#define VROOT_CLR_DEV          0x5601
9123 +
9124 +#endif /* _LINUX_VROOT_H */
9125 diff -NurpP --minimal linux-3.1.1/include/linux/vs_base.h linux-3.1.1-vs2.3.2/include/linux/vs_base.h
9126 --- linux-3.1.1/include/linux/vs_base.h 1970-01-01 01:00:00.000000000 +0100
9127 +++ linux-3.1.1-vs2.3.2/include/linux/vs_base.h 2011-10-24 18:53:33.000000000 +0200
9128 @@ -0,0 +1,10 @@
9129 +#ifndef _VS_BASE_H
9130 +#define _VS_BASE_H
9131 +
9132 +#include "vserver/base.h"
9133 +#include "vserver/check.h"
9134 +#include "vserver/debug.h"
9135 +
9136 +#else
9137 +#warning duplicate inclusion
9138 +#endif
9139 diff -NurpP --minimal linux-3.1.1/include/linux/vs_context.h linux-3.1.1-vs2.3.2/include/linux/vs_context.h
9140 --- linux-3.1.1/include/linux/vs_context.h      1970-01-01 01:00:00.000000000 +0100
9141 +++ linux-3.1.1-vs2.3.2/include/linux/vs_context.h      2011-10-24 18:53:33.000000000 +0200
9142 @@ -0,0 +1,242 @@
9143 +#ifndef _VS_CONTEXT_H
9144 +#define _VS_CONTEXT_H
9145 +
9146 +#include "vserver/base.h"
9147 +#include "vserver/check.h"
9148 +#include "vserver/context.h"
9149 +#include "vserver/history.h"
9150 +#include "vserver/debug.h"
9151 +
9152 +#include <linux/sched.h>
9153 +
9154 +
9155 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
9156 +
9157 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
9158 +       const char *_file, int _line, void *_here)
9159 +{
9160 +       if (!vxi)
9161 +               return NULL;
9162 +
9163 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
9164 +               vxi, vxi ? vxi->vx_id : 0,
9165 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9166 +               _file, _line);
9167 +       __vxh_get_vx_info(vxi, _here);
9168 +
9169 +       atomic_inc(&vxi->vx_usecnt);
9170 +       return vxi;
9171 +}
9172 +
9173 +
9174 +extern void free_vx_info(struct vx_info *);
9175 +
9176 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
9177 +
9178 +static inline void __put_vx_info(struct vx_info *vxi,
9179 +       const char *_file, int _line, void *_here)
9180 +{
9181 +       if (!vxi)
9182 +               return;
9183 +
9184 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
9185 +               vxi, vxi ? vxi->vx_id : 0,
9186 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9187 +               _file, _line);
9188 +       __vxh_put_vx_info(vxi, _here);
9189 +
9190 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
9191 +               free_vx_info(vxi);
9192 +}
9193 +
9194 +
9195 +#define init_vx_info(p, i) \
9196 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9197 +
9198 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9199 +       const char *_file, int _line, void *_here)
9200 +{
9201 +       if (vxi) {
9202 +               vxlprintk(VXD_CBIT(xid, 3),
9203 +                       "init_vx_info(%p[#%d.%d])",
9204 +                       vxi, vxi ? vxi->vx_id : 0,
9205 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9206 +                       _file, _line);
9207 +               __vxh_init_vx_info(vxi, vxp, _here);
9208 +
9209 +               atomic_inc(&vxi->vx_usecnt);
9210 +       }
9211 +       *vxp = vxi;
9212 +}
9213 +
9214 +
9215 +#define set_vx_info(p, i) \
9216 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9217 +
9218 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9219 +       const char *_file, int _line, void *_here)
9220 +{
9221 +       struct vx_info *vxo;
9222 +
9223 +       if (!vxi)
9224 +               return;
9225 +
9226 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
9227 +               vxi, vxi ? vxi->vx_id : 0,
9228 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9229 +               _file, _line);
9230 +       __vxh_set_vx_info(vxi, vxp, _here);
9231 +
9232 +       atomic_inc(&vxi->vx_usecnt);
9233 +       vxo = xchg(vxp, vxi);
9234 +       BUG_ON(vxo);
9235 +}
9236 +
9237 +
9238 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
9239 +
9240 +static inline void __clr_vx_info(struct vx_info **vxp,
9241 +       const char *_file, int _line, void *_here)
9242 +{
9243 +       struct vx_info *vxo;
9244 +
9245 +       vxo = xchg(vxp, NULL);
9246 +       if (!vxo)
9247 +               return;
9248 +
9249 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
9250 +               vxo, vxo ? vxo->vx_id : 0,
9251 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
9252 +               _file, _line);
9253 +       __vxh_clr_vx_info(vxo, vxp, _here);
9254 +
9255 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
9256 +               free_vx_info(vxo);
9257 +}
9258 +
9259 +
9260 +#define claim_vx_info(v, p) \
9261 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9262 +
9263 +static inline void __claim_vx_info(struct vx_info *vxi,
9264 +       struct task_struct *task,
9265 +       const char *_file, int _line, void *_here)
9266 +{
9267 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
9268 +               vxi, vxi ? vxi->vx_id : 0,
9269 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9270 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9271 +               task, _file, _line);
9272 +       __vxh_claim_vx_info(vxi, task, _here);
9273 +
9274 +       atomic_inc(&vxi->vx_tasks);
9275 +}
9276 +
9277 +
9278 +extern void unhash_vx_info(struct vx_info *);
9279 +
9280 +#define release_vx_info(v, p) \
9281 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9282 +
9283 +static inline void __release_vx_info(struct vx_info *vxi,
9284 +       struct task_struct *task,
9285 +       const char *_file, int _line, void *_here)
9286 +{
9287 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
9288 +               vxi, vxi ? vxi->vx_id : 0,
9289 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9290 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9291 +               task, _file, _line);
9292 +       __vxh_release_vx_info(vxi, task, _here);
9293 +
9294 +       might_sleep();
9295 +
9296 +       if (atomic_dec_and_test(&vxi->vx_tasks))
9297 +               unhash_vx_info(vxi);
9298 +}
9299 +
9300 +
9301 +#define task_get_vx_info(p) \
9302 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
9303 +
9304 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
9305 +       const char *_file, int _line, void *_here)
9306 +{
9307 +       struct vx_info *vxi;
9308 +
9309 +       task_lock(p);
9310 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
9311 +               p, _file, _line);
9312 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
9313 +       task_unlock(p);
9314 +       return vxi;
9315 +}
9316 +
9317 +
9318 +static inline void __wakeup_vx_info(struct vx_info *vxi)
9319 +{
9320 +       if (waitqueue_active(&vxi->vx_wait))
9321 +               wake_up_interruptible(&vxi->vx_wait);
9322 +}
9323 +
9324 +
9325 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
9326 +
9327 +static inline void __enter_vx_info(struct vx_info *vxi,
9328 +       struct vx_info_save *vxis, const char *_file, int _line)
9329 +{
9330 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
9331 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
9332 +               current->xid, current->vx_info, _file, _line);
9333 +       vxis->vxi = xchg(&current->vx_info, vxi);
9334 +       vxis->xid = current->xid;
9335 +       current->xid = vxi ? vxi->vx_id : 0;
9336 +}
9337 +
9338 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
9339 +
9340 +static inline void __leave_vx_info(struct vx_info_save *vxis,
9341 +       const char *_file, int _line)
9342 +{
9343 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
9344 +               vxis, vxis->xid, vxis->vxi, current,
9345 +               current->xid, current->vx_info, _file, _line);
9346 +       (void)xchg(&current->vx_info, vxis->vxi);
9347 +       current->xid = vxis->xid;
9348 +}
9349 +
9350 +
9351 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
9352 +{
9353 +       vxis->vxi = xchg(&current->vx_info, NULL);
9354 +       vxis->xid = xchg(&current->xid, (xid_t)0);
9355 +}
9356 +
9357 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
9358 +{
9359 +       (void)xchg(&current->xid, vxis->xid);
9360 +       (void)xchg(&current->vx_info, vxis->vxi);
9361 +}
9362 +
9363 +#define task_is_init(p) \
9364 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
9365 +
9366 +static inline int __task_is_init(struct task_struct *p,
9367 +       const char *_file, int _line, void *_here)
9368 +{
9369 +       int is_init = is_global_init(p);
9370 +
9371 +       task_lock(p);
9372 +       if (p->vx_info)
9373 +               is_init = p->vx_info->vx_initpid == p->pid;
9374 +       task_unlock(p);
9375 +       return is_init;
9376 +}
9377 +
9378 +extern void exit_vx_info(struct task_struct *, int);
9379 +extern void exit_vx_info_early(struct task_struct *, int);
9380 +
9381 +
9382 +#else
9383 +#warning duplicate inclusion
9384 +#endif
9385 diff -NurpP --minimal linux-3.1.1/include/linux/vs_cowbl.h linux-3.1.1-vs2.3.2/include/linux/vs_cowbl.h
9386 --- linux-3.1.1/include/linux/vs_cowbl.h        1970-01-01 01:00:00.000000000 +0100
9387 +++ linux-3.1.1-vs2.3.2/include/linux/vs_cowbl.h        2011-10-24 18:53:33.000000000 +0200
9388 @@ -0,0 +1,48 @@
9389 +#ifndef _VS_COWBL_H
9390 +#define _VS_COWBL_H
9391 +
9392 +#include <linux/fs.h>
9393 +#include <linux/dcache.h>
9394 +#include <linux/namei.h>
9395 +#include <linux/slab.h>
9396 +
9397 +extern struct dentry *cow_break_link(const char *pathname);
9398 +
9399 +static inline int cow_check_and_break(struct path *path)
9400 +{
9401 +       struct inode *inode = path->dentry->d_inode;
9402 +       int error = 0;
9403 +
9404 +       /* do we need this check? */
9405 +       if (IS_RDONLY(inode))
9406 +               return -EROFS;
9407 +
9408 +       if (IS_COW(inode)) {
9409 +               if (IS_COW_LINK(inode)) {
9410 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
9411 +                       char *pp, *buf;
9412 +
9413 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
9414 +                       if (!buf) {
9415 +                               return -ENOMEM;
9416 +                       }
9417 +                       pp = d_path(path, buf, PATH_MAX);
9418 +                       new_dentry = cow_break_link(pp);
9419 +                       kfree(buf);
9420 +                       if (!IS_ERR(new_dentry)) {
9421 +                               path->dentry = new_dentry;
9422 +                               dput(old_dentry);
9423 +                       } else
9424 +                               error = PTR_ERR(new_dentry);
9425 +               } else {
9426 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
9427 +                       inode->i_ctime = CURRENT_TIME;
9428 +                       mark_inode_dirty(inode);
9429 +               }
9430 +       }
9431 +       return error;
9432 +}
9433 +
9434 +#else
9435 +#warning duplicate inclusion
9436 +#endif
9437 diff -NurpP --minimal linux-3.1.1/include/linux/vs_cvirt.h linux-3.1.1-vs2.3.2/include/linux/vs_cvirt.h
9438 --- linux-3.1.1/include/linux/vs_cvirt.h        1970-01-01 01:00:00.000000000 +0100
9439 +++ linux-3.1.1-vs2.3.2/include/linux/vs_cvirt.h        2011-10-24 18:53:33.000000000 +0200
9440 @@ -0,0 +1,50 @@
9441 +#ifndef _VS_CVIRT_H
9442 +#define _VS_CVIRT_H
9443 +
9444 +#include "vserver/cvirt.h"
9445 +#include "vserver/context.h"
9446 +#include "vserver/base.h"
9447 +#include "vserver/check.h"
9448 +#include "vserver/debug.h"
9449 +
9450 +
9451 +static inline void vx_activate_task(struct task_struct *p)
9452 +{
9453 +       struct vx_info *vxi;
9454 +
9455 +       if ((vxi = p->vx_info)) {
9456 +               vx_update_load(vxi);
9457 +               atomic_inc(&vxi->cvirt.nr_running);
9458 +       }
9459 +}
9460 +
9461 +static inline void vx_deactivate_task(struct task_struct *p)
9462 +{
9463 +       struct vx_info *vxi;
9464 +
9465 +       if ((vxi = p->vx_info)) {
9466 +               vx_update_load(vxi);
9467 +               atomic_dec(&vxi->cvirt.nr_running);
9468 +       }
9469 +}
9470 +
9471 +static inline void vx_uninterruptible_inc(struct task_struct *p)
9472 +{
9473 +       struct vx_info *vxi;
9474 +
9475 +       if ((vxi = p->vx_info))
9476 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
9477 +}
9478 +
9479 +static inline void vx_uninterruptible_dec(struct task_struct *p)
9480 +{
9481 +       struct vx_info *vxi;
9482 +
9483 +       if ((vxi = p->vx_info))
9484 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
9485 +}
9486 +
9487 +
9488 +#else
9489 +#warning duplicate inclusion
9490 +#endif
9491 diff -NurpP --minimal linux-3.1.1/include/linux/vs_device.h linux-3.1.1-vs2.3.2/include/linux/vs_device.h
9492 --- linux-3.1.1/include/linux/vs_device.h       1970-01-01 01:00:00.000000000 +0100
9493 +++ linux-3.1.1-vs2.3.2/include/linux/vs_device.h       2011-10-24 18:53:33.000000000 +0200
9494 @@ -0,0 +1,45 @@
9495 +#ifndef _VS_DEVICE_H
9496 +#define _VS_DEVICE_H
9497 +
9498 +#include "vserver/base.h"
9499 +#include "vserver/device.h"
9500 +#include "vserver/debug.h"
9501 +
9502 +
9503 +#ifdef CONFIG_VSERVER_DEVICE
9504 +
9505 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
9506 +
9507 +#define vs_device_perm(v, d, m, p) \
9508 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
9509 +
9510 +#else
9511 +
9512 +static inline
9513 +int vs_map_device(struct vx_info *vxi,
9514 +       dev_t device, dev_t *target, umode_t mode)
9515 +{
9516 +       if (target)
9517 +               *target = device;
9518 +       return ~0;
9519 +}
9520 +
9521 +#define vs_device_perm(v, d, m, p) ((p) == (p))
9522 +
9523 +#endif
9524 +
9525 +
9526 +#define vs_map_chrdev(d, t, p) \
9527 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
9528 +#define vs_map_blkdev(d, t, p) \
9529 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
9530 +
9531 +#define vs_chrdev_perm(d, p) \
9532 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
9533 +#define vs_blkdev_perm(d, p) \
9534 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
9535 +
9536 +
9537 +#else
9538 +#warning duplicate inclusion
9539 +#endif
9540 diff -NurpP --minimal linux-3.1.1/include/linux/vs_dlimit.h linux-3.1.1-vs2.3.2/include/linux/vs_dlimit.h
9541 --- linux-3.1.1/include/linux/vs_dlimit.h       1970-01-01 01:00:00.000000000 +0100
9542 +++ linux-3.1.1-vs2.3.2/include/linux/vs_dlimit.h       2011-10-24 18:53:33.000000000 +0200
9543 @@ -0,0 +1,215 @@
9544 +#ifndef _VS_DLIMIT_H
9545 +#define _VS_DLIMIT_H
9546 +
9547 +#include <linux/fs.h>
9548 +
9549 +#include "vserver/dlimit.h"
9550 +#include "vserver/base.h"
9551 +#include "vserver/debug.h"
9552 +
9553 +
9554 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
9555 +
9556 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
9557 +       const char *_file, int _line)
9558 +{
9559 +       if (!dli)
9560 +               return NULL;
9561 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
9562 +               dli, dli ? dli->dl_tag : 0,
9563 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9564 +               _file, _line);
9565 +       atomic_inc(&dli->dl_usecnt);
9566 +       return dli;
9567 +}
9568 +
9569 +
9570 +#define free_dl_info(i) \
9571 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
9572 +
9573 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
9574 +
9575 +static inline void __put_dl_info(struct dl_info *dli,
9576 +       const char *_file, int _line)
9577 +{
9578 +       if (!dli)
9579 +               return;
9580 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
9581 +               dli, dli ? dli->dl_tag : 0,
9582 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9583 +               _file, _line);
9584 +       if (atomic_dec_and_test(&dli->dl_usecnt))
9585 +               free_dl_info(dli);
9586 +}
9587 +
9588 +
9589 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
9590 +
9591 +static inline int __dl_alloc_space(struct super_block *sb,
9592 +       tag_t tag, dlsize_t nr, const char *file, int line)
9593 +{
9594 +       struct dl_info *dli = NULL;
9595 +       int ret = 0;
9596 +
9597 +       if (nr == 0)
9598 +               goto out;
9599 +       dli = locate_dl_info(sb, tag);
9600 +       if (!dli)
9601 +               goto out;
9602 +
9603 +       spin_lock(&dli->dl_lock);
9604 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
9605 +       if (!ret)
9606 +               dli->dl_space_used += nr;
9607 +       spin_unlock(&dli->dl_lock);
9608 +       put_dl_info(dli);
9609 +out:
9610 +       vxlprintk(VXD_CBIT(dlim, 1),
9611 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
9612 +               sb, tag, __dlimit_char(dli), (long long)nr,
9613 +               ret, file, line);
9614 +       return ret ? -ENOSPC : 0;
9615 +}
9616 +
9617 +static inline void __dl_free_space(struct super_block *sb,
9618 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
9619 +{
9620 +       struct dl_info *dli = NULL;
9621 +
9622 +       if (nr == 0)
9623 +               goto out;
9624 +       dli = locate_dl_info(sb, tag);
9625 +       if (!dli)
9626 +               goto out;
9627 +
9628 +       spin_lock(&dli->dl_lock);
9629 +       if (dli->dl_space_used > nr)
9630 +               dli->dl_space_used -= nr;
9631 +       else
9632 +               dli->dl_space_used = 0;
9633 +       spin_unlock(&dli->dl_lock);
9634 +       put_dl_info(dli);
9635 +out:
9636 +       vxlprintk(VXD_CBIT(dlim, 1),
9637 +               "FREE  (%p,#%d)%c %lld bytes",
9638 +               sb, tag, __dlimit_char(dli), (long long)nr,
9639 +               _file, _line);
9640 +}
9641 +
9642 +static inline int __dl_alloc_inode(struct super_block *sb,
9643 +       tag_t tag, const char *_file, int _line)
9644 +{
9645 +       struct dl_info *dli;
9646 +       int ret = 0;
9647 +
9648 +       dli = locate_dl_info(sb, tag);
9649 +       if (!dli)
9650 +               goto out;
9651 +
9652 +       spin_lock(&dli->dl_lock);
9653 +       dli->dl_inodes_used++;
9654 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
9655 +       spin_unlock(&dli->dl_lock);
9656 +       put_dl_info(dli);
9657 +out:
9658 +       vxlprintk(VXD_CBIT(dlim, 0),
9659 +               "ALLOC (%p,#%d)%c inode (%d)",
9660 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
9661 +       return ret ? -ENOSPC : 0;
9662 +}
9663 +
9664 +static inline void __dl_free_inode(struct super_block *sb,
9665 +       tag_t tag, const char *_file, int _line)
9666 +{
9667 +       struct dl_info *dli;
9668 +
9669 +       dli = locate_dl_info(sb, tag);
9670 +       if (!dli)
9671 +               goto out;
9672 +
9673 +       spin_lock(&dli->dl_lock);
9674 +       if (dli->dl_inodes_used > 1)
9675 +               dli->dl_inodes_used--;
9676 +       else
9677 +               dli->dl_inodes_used = 0;
9678 +       spin_unlock(&dli->dl_lock);
9679 +       put_dl_info(dli);
9680 +out:
9681 +       vxlprintk(VXD_CBIT(dlim, 0),
9682 +               "FREE  (%p,#%d)%c inode",
9683 +               sb, tag, __dlimit_char(dli), _file, _line);
9684 +}
9685 +
9686 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
9687 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
9688 +       const char *_file, int _line)
9689 +{
9690 +       struct dl_info *dli;
9691 +       uint64_t broot, bfree;
9692 +
9693 +       dli = locate_dl_info(sb, tag);
9694 +       if (!dli)
9695 +               return;
9696 +
9697 +       spin_lock(&dli->dl_lock);
9698 +       broot = (dli->dl_space_total -
9699 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
9700 +               >> sb->s_blocksize_bits;
9701 +       bfree = (dli->dl_space_total - dli->dl_space_used)
9702 +                       >> sb->s_blocksize_bits;
9703 +       spin_unlock(&dli->dl_lock);
9704 +
9705 +       vxlprintk(VXD_CBIT(dlim, 2),
9706 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
9707 +               (long long)bfree, (long long)broot,
9708 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
9709 +               _file, _line);
9710 +       if (free_blocks) {
9711 +               if (*free_blocks > bfree)
9712 +                       *free_blocks = bfree;
9713 +       }
9714 +       if (root_blocks) {
9715 +               if (*root_blocks > broot)
9716 +                       *root_blocks = broot;
9717 +       }
9718 +       put_dl_info(dli);
9719 +}
9720 +
9721 +#define dl_prealloc_space(in, bytes) \
9722 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9723 +               __FILE__, __LINE__ )
9724 +
9725 +#define dl_alloc_space(in, bytes) \
9726 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9727 +               __FILE__, __LINE__ )
9728 +
9729 +#define dl_reserve_space(in, bytes) \
9730 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9731 +               __FILE__, __LINE__ )
9732 +
9733 +#define dl_claim_space(in, bytes) (0)
9734 +
9735 +#define dl_release_space(in, bytes) \
9736 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9737 +               __FILE__, __LINE__ )
9738 +
9739 +#define dl_free_space(in, bytes) \
9740 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9741 +               __FILE__, __LINE__ )
9742 +
9743 +
9744 +
9745 +#define dl_alloc_inode(in) \
9746 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
9747 +
9748 +#define dl_free_inode(in) \
9749 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
9750 +
9751 +
9752 +#define dl_adjust_block(sb, tag, fb, rb) \
9753 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
9754 +
9755 +
9756 +#else
9757 +#warning duplicate inclusion
9758 +#endif
9759 diff -NurpP --minimal linux-3.1.1/include/linux/vs_inet.h linux-3.1.1-vs2.3.2/include/linux/vs_inet.h
9760 --- linux-3.1.1/include/linux/vs_inet.h 1970-01-01 01:00:00.000000000 +0100
9761 +++ linux-3.1.1-vs2.3.2/include/linux/vs_inet.h 2011-10-24 18:53:33.000000000 +0200
9762 @@ -0,0 +1,353 @@
9763 +#ifndef _VS_INET_H
9764 +#define _VS_INET_H
9765 +
9766 +#include "vserver/base.h"
9767 +#include "vserver/network.h"
9768 +#include "vserver/debug.h"
9769 +
9770 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
9771 +
9772 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
9773 +                       NIPQUAD((a)->mask), (a)->type
9774 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
9775 +
9776 +#define NIPQUAD(addr) \
9777 +       ((unsigned char *)&addr)[0], \
9778 +       ((unsigned char *)&addr)[1], \
9779 +       ((unsigned char *)&addr)[2], \
9780 +       ((unsigned char *)&addr)[3]
9781 +
9782 +#define NIPQUAD_FMT "%u.%u.%u.%u"
9783 +
9784 +
9785 +static inline
9786 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
9787 +{
9788 +       __be32 ip = nxa->ip[0].s_addr;
9789 +       __be32 mask = nxa->mask.s_addr;
9790 +       __be32 bcast = ip | ~mask;
9791 +       int ret = 0;
9792 +
9793 +       switch (nxa->type & tmask) {
9794 +       case NXA_TYPE_MASK:
9795 +               ret = (ip == (addr & mask));
9796 +               break;
9797 +       case NXA_TYPE_ADDR:
9798 +               ret = 3;
9799 +               if (addr == ip)
9800 +                       break;
9801 +               /* fall through to broadcast */
9802 +       case NXA_MOD_BCAST:
9803 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
9804 +               break;
9805 +       case NXA_TYPE_RANGE:
9806 +               ret = ((nxa->ip[0].s_addr <= addr) &&
9807 +                       (nxa->ip[1].s_addr > addr));
9808 +               break;
9809 +       case NXA_TYPE_ANY:
9810 +               ret = 2;
9811 +               break;
9812 +       }
9813 +
9814 +       vxdprintk(VXD_CBIT(net, 0),
9815 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
9816 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
9817 +       return ret;
9818 +}
9819 +
9820 +static inline
9821 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
9822 +{
9823 +       struct nx_addr_v4 *nxa;
9824 +       int ret = 1;
9825 +
9826 +       if (!nxi)
9827 +               goto out;
9828 +
9829 +       ret = 2;
9830 +       /* allow 127.0.0.1 when remapping lback */
9831 +       if ((tmask & NXA_LOOPBACK) &&
9832 +               (addr == IPI_LOOPBACK) &&
9833 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9834 +               goto out;
9835 +       ret = 3;
9836 +       /* check for lback address */
9837 +       if ((tmask & NXA_MOD_LBACK) &&
9838 +               (nxi->v4_lback.s_addr == addr))
9839 +               goto out;
9840 +       ret = 4;
9841 +       /* check for broadcast address */
9842 +       if ((tmask & NXA_MOD_BCAST) &&
9843 +               (nxi->v4_bcast.s_addr == addr))
9844 +               goto out;
9845 +       ret = 5;
9846 +       /* check for v4 addresses */
9847 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
9848 +               if (v4_addr_match(nxa, addr, tmask))
9849 +                       goto out;
9850 +       ret = 0;
9851 +out:
9852 +       vxdprintk(VXD_CBIT(net, 0),
9853 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
9854 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
9855 +       return ret;
9856 +}
9857 +
9858 +static inline
9859 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
9860 +{
9861 +       /* FIXME: needs full range checks */
9862 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
9863 +}
9864 +
9865 +static inline
9866 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
9867 +{
9868 +       struct nx_addr_v4 *ptr;
9869 +
9870 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
9871 +               if (v4_nx_addr_match(ptr, nxa, mask))
9872 +                       return 1;
9873 +       return 0;
9874 +}
9875 +
9876 +#include <net/inet_sock.h>
9877 +
9878 +/*
9879 + *     Check if a given address matches for a socket
9880 + *
9881 + *     nxi:            the socket's nx_info if any
9882 + *     addr:           to be verified address
9883 + */
9884 +static inline
9885 +int v4_sock_addr_match (
9886 +       struct nx_info *nxi,
9887 +       struct inet_sock *inet,
9888 +       __be32 addr)
9889 +{
9890 +       __be32 saddr = inet->inet_rcv_saddr;
9891 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
9892 +
9893 +       if (addr && (saddr == addr || bcast == addr))
9894 +               return 1;
9895 +       if (!saddr)
9896 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
9897 +       return 0;
9898 +}
9899 +
9900 +
9901 +/* inet related checks and helpers */
9902 +
9903 +
9904 +struct in_ifaddr;
9905 +struct net_device;
9906 +struct sock;
9907 +
9908 +#ifdef CONFIG_INET
9909 +
9910 +#include <linux/netdevice.h>
9911 +#include <linux/inetdevice.h>
9912 +#include <net/inet_sock.h>
9913 +#include <net/inet_timewait_sock.h>
9914 +
9915 +
9916 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9917 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
9918 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
9919 +
9920 +
9921 +/*
9922 + *     check if address is covered by socket
9923 + *
9924 + *     sk:     the socket to check against
9925 + *     addr:   the address in question (must be != 0)
9926 + */
9927 +
9928 +static inline
9929 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
9930 +{
9931 +       struct nx_info *nxi = sk->sk_nx_info;
9932 +       __be32 saddr = sk_rcv_saddr(sk);
9933 +
9934 +       vxdprintk(VXD_CBIT(net, 5),
9935 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
9936 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
9937 +               (sk->sk_socket?sk->sk_socket->flags:0));
9938 +
9939 +       if (saddr) {            /* direct address match */
9940 +               return v4_addr_match(nxa, saddr, -1);
9941 +       } else if (nxi) {       /* match against nx_info */
9942 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
9943 +       } else {                /* unrestricted any socket */
9944 +               return 1;
9945 +       }
9946 +}
9947 +
9948 +
9949 +
9950 +static inline
9951 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
9952 +{
9953 +       vxdprintk(VXD_CBIT(net, 1),
9954 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
9955 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
9956 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
9957 +
9958 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9959 +               return 1;
9960 +       if (dev_in_nx_info(dev, nxi))
9961 +               return 1;
9962 +       return 0;
9963 +}
9964 +
9965 +
9966 +static inline
9967 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
9968 +{
9969 +       if (!nxi)
9970 +               return 1;
9971 +       if (!ifa)
9972 +               return 0;
9973 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
9974 +}
9975 +
9976 +static inline
9977 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
9978 +{
9979 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
9980 +               nxi, nxi ? nxi->nx_id : 0, ifa,
9981 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
9982 +
9983 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9984 +               return 1;
9985 +       if (v4_ifa_in_nx_info(ifa, nxi))
9986 +               return 1;
9987 +       return 0;
9988 +}
9989 +
9990 +
9991 +struct nx_v4_sock_addr {
9992 +       __be32 saddr;   /* Address used for validation */
9993 +       __be32 baddr;   /* Address used for socket bind */
9994 +};
9995 +
9996 +static inline
9997 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
9998 +       struct nx_v4_sock_addr *nsa)
9999 +{
10000 +       struct sock *sk = &inet->sk;
10001 +       struct nx_info *nxi = sk->sk_nx_info;
10002 +       __be32 saddr = addr->sin_addr.s_addr;
10003 +       __be32 baddr = saddr;
10004 +
10005 +       vxdprintk(VXD_CBIT(net, 3),
10006 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
10007 +               sk, sk->sk_nx_info, sk->sk_socket,
10008 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
10009 +               NIPQUAD(saddr));
10010 +
10011 +       if (nxi) {
10012 +               if (saddr == INADDR_ANY) {
10013 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
10014 +                               baddr = nxi->v4.ip[0].s_addr;
10015 +               } else if (saddr == IPI_LOOPBACK) {
10016 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
10017 +                               baddr = nxi->v4_lback.s_addr;
10018 +               } else if (!ipv4_is_multicast(saddr) ||
10019 +                       !nx_info_ncaps(nxi, NXC_MULTICAST)) {
10020 +                       /* normal address bind */
10021 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
10022 +                               return -EADDRNOTAVAIL;
10023 +               }
10024 +       }
10025 +
10026 +       vxdprintk(VXD_CBIT(net, 3),
10027 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
10028 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
10029 +
10030 +       nsa->saddr = saddr;
10031 +       nsa->baddr = baddr;
10032 +       return 0;
10033 +}
10034 +
10035 +static inline
10036 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
10037 +{
10038 +       inet->inet_saddr = nsa->baddr;
10039 +       inet->inet_rcv_saddr = nsa->baddr;
10040 +}
10041 +
10042 +
10043 +/*
10044 + *      helper to simplify inet_lookup_listener
10045 + *
10046 + *      nxi:   the socket's nx_info if any
10047 + *      addr:  to be verified address
10048 + *      saddr: socket address
10049 + */
10050 +static inline int v4_inet_addr_match (
10051 +       struct nx_info *nxi,
10052 +       __be32 addr,
10053 +       __be32 saddr)
10054 +{
10055 +       if (addr && (saddr == addr))
10056 +               return 1;
10057 +       if (!saddr)
10058 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
10059 +       return 0;
10060 +}
10061 +
10062 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
10063 +{
10064 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
10065 +               (addr == nxi->v4_lback.s_addr))
10066 +               return IPI_LOOPBACK;
10067 +       return addr;
10068 +}
10069 +
10070 +static inline
10071 +int nx_info_has_v4(struct nx_info *nxi)
10072 +{
10073 +       if (!nxi)
10074 +               return 1;
10075 +       if (NX_IPV4(nxi))
10076 +               return 1;
10077 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
10078 +               return 1;
10079 +       return 0;
10080 +}
10081 +
10082 +#else /* CONFIG_INET */
10083 +
10084 +static inline
10085 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
10086 +{
10087 +       return 1;
10088 +}
10089 +
10090 +static inline
10091 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
10092 +{
10093 +       return 1;
10094 +}
10095 +
10096 +static inline
10097 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
10098 +{
10099 +       return 1;
10100 +}
10101 +
10102 +static inline
10103 +int nx_info_has_v4(struct nx_info *nxi)
10104 +{
10105 +       return 0;
10106 +}
10107 +
10108 +#endif /* CONFIG_INET */
10109 +
10110 +#define current_nx_info_has_v4() \
10111 +       nx_info_has_v4(current_nx_info())
10112 +
10113 +#else
10114 +// #warning duplicate inclusion
10115 +#endif
10116 diff -NurpP --minimal linux-3.1.1/include/linux/vs_inet6.h linux-3.1.1-vs2.3.2/include/linux/vs_inet6.h
10117 --- linux-3.1.1/include/linux/vs_inet6.h        1970-01-01 01:00:00.000000000 +0100
10118 +++ linux-3.1.1-vs2.3.2/include/linux/vs_inet6.h        2011-10-24 18:53:33.000000000 +0200
10119 @@ -0,0 +1,246 @@
10120 +#ifndef _VS_INET6_H
10121 +#define _VS_INET6_H
10122 +
10123 +#include "vserver/base.h"
10124 +#include "vserver/network.h"
10125 +#include "vserver/debug.h"
10126 +
10127 +#include <net/ipv6.h>
10128 +
10129 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
10130 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
10131 +
10132 +
10133 +#ifdef CONFIG_IPV6
10134 +
10135 +static inline
10136 +int v6_addr_match(struct nx_addr_v6 *nxa,
10137 +       const struct in6_addr *addr, uint16_t mask)
10138 +{
10139 +       int ret = 0;
10140 +
10141 +       switch (nxa->type & mask) {
10142 +       case NXA_TYPE_MASK:
10143 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
10144 +               break;
10145 +       case NXA_TYPE_ADDR:
10146 +               ret = ipv6_addr_equal(&nxa->ip, addr);
10147 +               break;
10148 +       case NXA_TYPE_ANY:
10149 +               ret = 1;
10150 +               break;
10151 +       }
10152 +       vxdprintk(VXD_CBIT(net, 0),
10153 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
10154 +               nxa, NXAV6(nxa), addr, mask, ret);
10155 +       return ret;
10156 +}
10157 +
10158 +static inline
10159 +int v6_addr_in_nx_info(struct nx_info *nxi,
10160 +       const struct in6_addr *addr, uint16_t mask)
10161 +{
10162 +       struct nx_addr_v6 *nxa;
10163 +       int ret = 1;
10164 +
10165 +       if (!nxi)
10166 +               goto out;
10167 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
10168 +               if (v6_addr_match(nxa, addr, mask))
10169 +                       goto out;
10170 +       ret = 0;
10171 +out:
10172 +       vxdprintk(VXD_CBIT(net, 0),
10173 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
10174 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
10175 +       return ret;
10176 +}
10177 +
10178 +static inline
10179 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
10180 +{
10181 +       /* FIXME: needs full range checks */
10182 +       return v6_addr_match(nxa, &addr->ip, mask);
10183 +}
10184 +
10185 +static inline
10186 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
10187 +{
10188 +       struct nx_addr_v6 *ptr;
10189 +
10190 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
10191 +               if (v6_nx_addr_match(ptr, nxa, mask))
10192 +                       return 1;
10193 +       return 0;
10194 +}
10195 +
10196 +
10197 +/*
10198 + *     Check if a given address matches for a socket
10199 + *
10200 + *     nxi:            the socket's nx_info if any
10201 + *     addr:           to be verified address
10202 + */
10203 +static inline
10204 +int v6_sock_addr_match (
10205 +       struct nx_info *nxi,
10206 +       struct inet_sock *inet,
10207 +       struct in6_addr *addr)
10208 +{
10209 +       struct sock *sk = &inet->sk;
10210 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
10211 +
10212 +       if (!ipv6_addr_any(addr) &&
10213 +               ipv6_addr_equal(saddr, addr))
10214 +               return 1;
10215 +       if (ipv6_addr_any(saddr))
10216 +               return v6_addr_in_nx_info(nxi, addr, -1);
10217 +       return 0;
10218 +}
10219 +
10220 +/*
10221 + *     check if address is covered by socket
10222 + *
10223 + *     sk:     the socket to check against
10224 + *     addr:   the address in question (must be != 0)
10225 + */
10226 +
10227 +static inline
10228 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
10229 +{
10230 +       struct nx_info *nxi = sk->sk_nx_info;
10231 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
10232 +
10233 +       vxdprintk(VXD_CBIT(net, 5),
10234 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
10235 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
10236 +               (sk->sk_socket?sk->sk_socket->flags:0));
10237 +
10238 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
10239 +               return v6_addr_match(nxa, saddr, -1);
10240 +       } else if (nxi) {               /* match against nx_info */
10241 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
10242 +       } else {                        /* unrestricted any socket */
10243 +               return 1;
10244 +       }
10245 +}
10246 +
10247 +
10248 +/* inet related checks and helpers */
10249 +
10250 +
10251 +struct in_ifaddr;
10252 +struct net_device;
10253 +struct sock;
10254 +
10255 +
10256 +#include <linux/netdevice.h>
10257 +#include <linux/inetdevice.h>
10258 +#include <net/inet_timewait_sock.h>
10259 +
10260 +
10261 +int dev_in_nx_info(struct net_device *, struct nx_info *);
10262 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
10263 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
10264 +
10265 +
10266 +
10267 +static inline
10268 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
10269 +{
10270 +       if (!nxi)
10271 +               return 1;
10272 +       if (!ifa)
10273 +               return 0;
10274 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
10275 +}
10276 +
10277 +static inline
10278 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
10279 +{
10280 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
10281 +               nxi, nxi ? nxi->nx_id : 0, ifa,
10282 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
10283 +
10284 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
10285 +               return 1;
10286 +       if (v6_ifa_in_nx_info(ifa, nxi))
10287 +               return 1;
10288 +       return 0;
10289 +}
10290 +
10291 +
10292 +struct nx_v6_sock_addr {
10293 +       struct in6_addr saddr;  /* Address used for validation */
10294 +       struct in6_addr baddr;  /* Address used for socket bind */
10295 +};
10296 +
10297 +static inline
10298 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
10299 +       struct nx_v6_sock_addr *nsa)
10300 +{
10301 +       // struct sock *sk = &inet->sk;
10302 +       // struct nx_info *nxi = sk->sk_nx_info;
10303 +       struct in6_addr saddr = addr->sin6_addr;
10304 +       struct in6_addr baddr = saddr;
10305 +
10306 +       nsa->saddr = saddr;
10307 +       nsa->baddr = baddr;
10308 +       return 0;
10309 +}
10310 +
10311 +static inline
10312 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
10313 +{
10314 +       // struct sock *sk = &inet->sk;
10315 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
10316 +
10317 +       // *saddr = nsa->baddr;
10318 +       // inet->inet_saddr = nsa->baddr;
10319 +}
10320 +
10321 +static inline
10322 +int nx_info_has_v6(struct nx_info *nxi)
10323 +{
10324 +       if (!nxi)
10325 +               return 1;
10326 +       if (NX_IPV6(nxi))
10327 +               return 1;
10328 +       return 0;
10329 +}
10330 +
10331 +#else /* CONFIG_IPV6 */
10332 +
10333 +static inline
10334 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
10335 +{
10336 +       return 1;
10337 +}
10338 +
10339 +
10340 +static inline
10341 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
10342 +{
10343 +       return 1;
10344 +}
10345 +
10346 +static inline
10347 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
10348 +{
10349 +       return 1;
10350 +}
10351 +
10352 +static inline
10353 +int nx_info_has_v6(struct nx_info *nxi)
10354 +{
10355 +       return 0;
10356 +}
10357 +
10358 +#endif /* CONFIG_IPV6 */
10359 +
10360 +#define current_nx_info_has_v6() \
10361 +       nx_info_has_v6(current_nx_info())
10362 +
10363 +#else
10364 +#warning duplicate inclusion
10365 +#endif
10366 diff -NurpP --minimal linux-3.1.1/include/linux/vs_limit.h linux-3.1.1-vs2.3.2/include/linux/vs_limit.h
10367 --- linux-3.1.1/include/linux/vs_limit.h        1970-01-01 01:00:00.000000000 +0100
10368 +++ linux-3.1.1-vs2.3.2/include/linux/vs_limit.h        2011-10-24 18:53:33.000000000 +0200
10369 @@ -0,0 +1,140 @@
10370 +#ifndef _VS_LIMIT_H
10371 +#define _VS_LIMIT_H
10372 +
10373 +#include "vserver/limit.h"
10374 +#include "vserver/base.h"
10375 +#include "vserver/context.h"
10376 +#include "vserver/debug.h"
10377 +#include "vserver/context.h"
10378 +#include "vserver/limit_int.h"
10379 +
10380 +
10381 +#define vx_acc_cres(v, d, p, r) \
10382 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
10383 +
10384 +#define vx_acc_cres_cond(x, d, p, r) \
10385 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
10386 +       r, d, p, __FILE__, __LINE__)
10387 +
10388 +
10389 +#define vx_add_cres(v, a, p, r) \
10390 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
10391 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
10392 +
10393 +#define vx_add_cres_cond(x, a, p, r) \
10394 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
10395 +       r, a, p, __FILE__, __LINE__)
10396 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
10397 +
10398 +
10399 +/* process and file limits */
10400 +
10401 +#define vx_nproc_inc(p) \
10402 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
10403 +
10404 +#define vx_nproc_dec(p) \
10405 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
10406 +
10407 +#define vx_files_inc(f) \
10408 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
10409 +
10410 +#define vx_files_dec(f) \
10411 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
10412 +
10413 +#define vx_locks_inc(l) \
10414 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
10415 +
10416 +#define vx_locks_dec(l) \
10417 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
10418 +
10419 +#define vx_openfd_inc(f) \
10420 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
10421 +
10422 +#define vx_openfd_dec(f) \
10423 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
10424 +
10425 +
10426 +#define vx_cres_avail(v, n, r) \
10427 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
10428 +
10429 +
10430 +#define vx_nproc_avail(n) \
10431 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
10432 +
10433 +#define vx_files_avail(n) \
10434 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
10435 +
10436 +#define vx_locks_avail(n) \
10437 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
10438 +
10439 +#define vx_openfd_avail(n) \
10440 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
10441 +
10442 +
10443 +/* dentry limits */
10444 +
10445 +#define vx_dentry_inc(d) do {                                          \
10446 +       if ((d)->d_count == 1)                                          \
10447 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
10448 +       } while (0)
10449 +
10450 +#define vx_dentry_dec(d) do {                                          \
10451 +       if ((d)->d_count == 0)                                          \
10452 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
10453 +       } while (0)
10454 +
10455 +#define vx_dentry_avail(n) \
10456 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
10457 +
10458 +
10459 +/* socket limits */
10460 +
10461 +#define vx_sock_inc(s) \
10462 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
10463 +
10464 +#define vx_sock_dec(s) \
10465 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
10466 +
10467 +#define vx_sock_avail(n) \
10468 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
10469 +
10470 +
10471 +/* ipc resource limits */
10472 +
10473 +#define vx_ipcmsg_add(v, u, a) \
10474 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
10475 +
10476 +#define vx_ipcmsg_sub(v, u, a) \
10477 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
10478 +
10479 +#define vx_ipcmsg_avail(v, a) \
10480 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
10481 +
10482 +
10483 +#define vx_ipcshm_add(v, k, a) \
10484 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
10485 +
10486 +#define vx_ipcshm_sub(v, k, a) \
10487 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
10488 +
10489 +#define vx_ipcshm_avail(v, a) \
10490 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
10491 +
10492 +
10493 +#define vx_semary_inc(a) \
10494 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
10495 +
10496 +#define vx_semary_dec(a) \
10497 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
10498 +
10499 +
10500 +#define vx_nsems_add(a,n) \
10501 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
10502 +
10503 +#define vx_nsems_sub(a,n) \
10504 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
10505 +
10506 +
10507 +#else
10508 +#warning duplicate inclusion
10509 +#endif
10510 diff -NurpP --minimal linux-3.1.1/include/linux/vs_memory.h linux-3.1.1-vs2.3.2/include/linux/vs_memory.h
10511 --- linux-3.1.1/include/linux/vs_memory.h       1970-01-01 01:00:00.000000000 +0100
10512 +++ linux-3.1.1-vs2.3.2/include/linux/vs_memory.h       2011-10-24 18:53:33.000000000 +0200
10513 @@ -0,0 +1,58 @@
10514 +#ifndef _VS_MEMORY_H
10515 +#define _VS_MEMORY_H
10516 +
10517 +#include "vserver/limit.h"
10518 +#include "vserver/base.h"
10519 +#include "vserver/context.h"
10520 +#include "vserver/debug.h"
10521 +#include "vserver/context.h"
10522 +#include "vserver/limit_int.h"
10523 +
10524 +enum {
10525 +       VXPT_UNKNOWN = 0,
10526 +       VXPT_ANON,
10527 +       VXPT_NONE,
10528 +       VXPT_FILE,
10529 +       VXPT_SWAP,
10530 +       VXPT_WRITE
10531 +};
10532 +
10533 +#if 0
10534 +#define        vx_page_fault(mm, vma, type, ret)
10535 +#else
10536 +
10537 +static inline
10538 +void __vx_page_fault(struct mm_struct *mm,
10539 +       struct vm_area_struct *vma, int type, int ret)
10540 +{
10541 +       struct vx_info *vxi = mm->mm_vx_info;
10542 +       int what;
10543 +/*
10544 +       static char *page_type[6] =
10545 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
10546 +       static char *page_what[4] =
10547 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
10548 +*/
10549 +
10550 +       if (!vxi)
10551 +               return;
10552 +
10553 +       what = (ret & 0x3);
10554 +
10555 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
10556 +               type, what, ret, page_type[type], page_what[what]);
10557 +*/
10558 +       if (ret & VM_FAULT_WRITE)
10559 +               what |= 0x4;
10560 +       atomic_inc(&vxi->cacct.page[type][what]);
10561 +}
10562 +
10563 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
10564 +#endif
10565 +
10566 +
10567 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
10568 +
10569 +#else
10570 +#warning duplicate inclusion
10571 +#endif
10572 diff -NurpP --minimal linux-3.1.1/include/linux/vs_network.h linux-3.1.1-vs2.3.2/include/linux/vs_network.h
10573 --- linux-3.1.1/include/linux/vs_network.h      1970-01-01 01:00:00.000000000 +0100
10574 +++ linux-3.1.1-vs2.3.2/include/linux/vs_network.h      2011-10-24 18:53:33.000000000 +0200
10575 @@ -0,0 +1,169 @@
10576 +#ifndef _NX_VS_NETWORK_H
10577 +#define _NX_VS_NETWORK_H
10578 +
10579 +#include "vserver/context.h"
10580 +#include "vserver/network.h"
10581 +#include "vserver/base.h"
10582 +#include "vserver/check.h"
10583 +#include "vserver/debug.h"
10584 +
10585 +#include <linux/sched.h>
10586 +
10587 +
10588 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
10589 +
10590 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
10591 +       const char *_file, int _line)
10592 +{
10593 +       if (!nxi)
10594 +               return NULL;
10595 +
10596 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
10597 +               nxi, nxi ? nxi->nx_id : 0,
10598 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10599 +               _file, _line);
10600 +
10601 +       atomic_inc(&nxi->nx_usecnt);
10602 +       return nxi;
10603 +}
10604 +
10605 +
10606 +extern void free_nx_info(struct nx_info *);
10607 +
10608 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
10609 +
10610 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
10611 +{
10612 +       if (!nxi)
10613 +               return;
10614 +
10615 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
10616 +               nxi, nxi ? nxi->nx_id : 0,
10617 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10618 +               _file, _line);
10619 +
10620 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
10621 +               free_nx_info(nxi);
10622 +}
10623 +
10624 +
10625 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
10626 +
10627 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
10628 +               const char *_file, int _line)
10629 +{
10630 +       if (nxi) {
10631 +               vxlprintk(VXD_CBIT(nid, 3),
10632 +                       "init_nx_info(%p[#%d.%d])",
10633 +                       nxi, nxi ? nxi->nx_id : 0,
10634 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10635 +                       _file, _line);
10636 +
10637 +               atomic_inc(&nxi->nx_usecnt);
10638 +       }
10639 +       *nxp = nxi;
10640 +}
10641 +
10642 +
10643 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
10644 +
10645 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
10646 +       const char *_file, int _line)
10647 +{
10648 +       struct nx_info *nxo;
10649 +
10650 +       if (!nxi)
10651 +               return;
10652 +
10653 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
10654 +               nxi, nxi ? nxi->nx_id : 0,
10655 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10656 +               _file, _line);
10657 +
10658 +       atomic_inc(&nxi->nx_usecnt);
10659 +       nxo = xchg(nxp, nxi);
10660 +       BUG_ON(nxo);
10661 +}
10662 +
10663 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
10664 +
10665 +static inline void __clr_nx_info(struct nx_info **nxp,
10666 +       const char *_file, int _line)
10667 +{
10668 +       struct nx_info *nxo;
10669 +
10670 +       nxo = xchg(nxp, NULL);
10671 +       if (!nxo)
10672 +               return;
10673 +
10674 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
10675 +               nxo, nxo ? nxo->nx_id : 0,
10676 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
10677 +               _file, _line);
10678 +
10679 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
10680 +               free_nx_info(nxo);
10681 +}
10682 +
10683 +
10684 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
10685 +
10686 +static inline void __claim_nx_info(struct nx_info *nxi,
10687 +       struct task_struct *task, const char *_file, int _line)
10688 +{
10689 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
10690 +               nxi, nxi ? nxi->nx_id : 0,
10691 +               nxi?atomic_read(&nxi->nx_usecnt):0,
10692 +               nxi?atomic_read(&nxi->nx_tasks):0,
10693 +               task, _file, _line);
10694 +
10695 +       atomic_inc(&nxi->nx_tasks);
10696 +}
10697 +
10698 +
10699 +extern void unhash_nx_info(struct nx_info *);
10700 +
10701 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
10702 +
10703 +static inline void __release_nx_info(struct nx_info *nxi,
10704 +       struct task_struct *task, const char *_file, int _line)
10705 +{
10706 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
10707 +               nxi, nxi ? nxi->nx_id : 0,
10708 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10709 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
10710 +               task, _file, _line);
10711 +
10712 +       might_sleep();
10713 +
10714 +       if (atomic_dec_and_test(&nxi->nx_tasks))
10715 +               unhash_nx_info(nxi);
10716 +}
10717 +
10718 +
10719 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
10720 +
10721 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
10722 +       const char *_file, int _line)
10723 +{
10724 +       struct nx_info *nxi;
10725 +
10726 +       task_lock(p);
10727 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
10728 +               p, _file, _line);
10729 +       nxi = __get_nx_info(p->nx_info, _file, _line);
10730 +       task_unlock(p);
10731 +       return nxi;
10732 +}
10733 +
10734 +
10735 +static inline void exit_nx_info(struct task_struct *p)
10736 +{
10737 +       if (p->nx_info)
10738 +               release_nx_info(p->nx_info, p);
10739 +}
10740 +
10741 +
10742 +#else
10743 +#warning duplicate inclusion
10744 +#endif
10745 diff -NurpP --minimal linux-3.1.1/include/linux/vs_pid.h linux-3.1.1-vs2.3.2/include/linux/vs_pid.h
10746 --- linux-3.1.1/include/linux/vs_pid.h  1970-01-01 01:00:00.000000000 +0100
10747 +++ linux-3.1.1-vs2.3.2/include/linux/vs_pid.h  2011-10-24 18:53:33.000000000 +0200
10748 @@ -0,0 +1,50 @@
10749 +#ifndef _VS_PID_H
10750 +#define _VS_PID_H
10751 +
10752 +#include "vserver/base.h"
10753 +#include "vserver/check.h"
10754 +#include "vserver/context.h"
10755 +#include "vserver/debug.h"
10756 +#include "vserver/pid.h"
10757 +#include <linux/pid_namespace.h>
10758 +
10759 +
10760 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
10761 +
10762 +static inline
10763 +int vx_proc_task_visible(struct task_struct *task)
10764 +{
10765 +       if ((task->pid == 1) &&
10766 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
10767 +               /* show a blend through init */
10768 +               goto visible;
10769 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
10770 +               goto visible;
10771 +       return 0;
10772 +visible:
10773 +       return 1;
10774 +}
10775 +
10776 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
10777 +
10778 +
10779 +static inline
10780 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
10781 +{
10782 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
10783 +
10784 +       if (task && !vx_proc_task_visible(task)) {
10785 +               vxdprintk(VXD_CBIT(misc, 6),
10786 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
10787 +                       task, task->xid, task->pid,
10788 +                       current, current->xid, current->pid);
10789 +               put_task_struct(task);
10790 +               task = NULL;
10791 +       }
10792 +       return task;
10793 +}
10794 +
10795 +
10796 +#else
10797 +#warning duplicate inclusion
10798 +#endif
10799 diff -NurpP --minimal linux-3.1.1/include/linux/vs_sched.h linux-3.1.1-vs2.3.2/include/linux/vs_sched.h
10800 --- linux-3.1.1/include/linux/vs_sched.h        1970-01-01 01:00:00.000000000 +0100
10801 +++ linux-3.1.1-vs2.3.2/include/linux/vs_sched.h        2011-10-24 18:53:33.000000000 +0200
10802 @@ -0,0 +1,40 @@
10803 +#ifndef _VS_SCHED_H
10804 +#define _VS_SCHED_H
10805 +
10806 +#include "vserver/base.h"
10807 +#include "vserver/context.h"
10808 +#include "vserver/sched.h"
10809 +
10810 +
10811 +#define MAX_PRIO_BIAS           20
10812 +#define MIN_PRIO_BIAS          -20
10813 +
10814 +static inline
10815 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
10816 +{
10817 +       struct vx_info *vxi = p->vx_info;
10818 +
10819 +       if (vxi)
10820 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
10821 +       return prio;
10822 +}
10823 +
10824 +static inline void vx_account_user(struct vx_info *vxi,
10825 +       cputime_t cputime, int nice)
10826 +{
10827 +       if (!vxi)
10828 +               return;
10829 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
10830 +}
10831 +
10832 +static inline void vx_account_system(struct vx_info *vxi,
10833 +       cputime_t cputime, int idle)
10834 +{
10835 +       if (!vxi)
10836 +               return;
10837 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
10838 +}
10839 +
10840 +#else
10841 +#warning duplicate inclusion
10842 +#endif
10843 diff -NurpP --minimal linux-3.1.1/include/linux/vs_socket.h linux-3.1.1-vs2.3.2/include/linux/vs_socket.h
10844 --- linux-3.1.1/include/linux/vs_socket.h       1970-01-01 01:00:00.000000000 +0100
10845 +++ linux-3.1.1-vs2.3.2/include/linux/vs_socket.h       2011-10-24 18:53:33.000000000 +0200
10846 @@ -0,0 +1,67 @@
10847 +#ifndef _VS_SOCKET_H
10848 +#define _VS_SOCKET_H
10849 +
10850 +#include "vserver/debug.h"
10851 +#include "vserver/base.h"
10852 +#include "vserver/cacct.h"
10853 +#include "vserver/context.h"
10854 +#include "vserver/tag.h"
10855 +
10856 +
10857 +/* socket accounting */
10858 +
10859 +#include <linux/socket.h>
10860 +
10861 +static inline int vx_sock_type(int family)
10862 +{
10863 +       switch (family) {
10864 +       case PF_UNSPEC:
10865 +               return VXA_SOCK_UNSPEC;
10866 +       case PF_UNIX:
10867 +               return VXA_SOCK_UNIX;
10868 +       case PF_INET:
10869 +               return VXA_SOCK_INET;
10870 +       case PF_INET6:
10871 +               return VXA_SOCK_INET6;
10872 +       case PF_PACKET:
10873 +               return VXA_SOCK_PACKET;
10874 +       default:
10875 +               return VXA_SOCK_OTHER;
10876 +       }
10877 +}
10878 +
10879 +#define vx_acc_sock(v, f, p, s) \
10880 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
10881 +
10882 +static inline void __vx_acc_sock(struct vx_info *vxi,
10883 +       int family, int pos, int size, char *file, int line)
10884 +{
10885 +       if (vxi) {
10886 +               int type = vx_sock_type(family);
10887 +
10888 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
10889 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
10890 +       }
10891 +}
10892 +
10893 +#define vx_sock_recv(sk, s) \
10894 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
10895 +#define vx_sock_send(sk, s) \
10896 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
10897 +#define vx_sock_fail(sk, s) \
10898 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
10899 +
10900 +
10901 +#define sock_vx_init(s) do {           \
10902 +       (s)->sk_xid = 0;                \
10903 +       (s)->sk_vx_info = NULL;         \
10904 +       } while (0)
10905 +
10906 +#define sock_nx_init(s) do {           \
10907 +       (s)->sk_nid = 0;                \
10908 +       (s)->sk_nx_info = NULL;         \
10909 +       } while (0)
10910 +
10911 +#else
10912 +#warning duplicate inclusion
10913 +#endif
10914 diff -NurpP --minimal linux-3.1.1/include/linux/vs_tag.h linux-3.1.1-vs2.3.2/include/linux/vs_tag.h
10915 --- linux-3.1.1/include/linux/vs_tag.h  1970-01-01 01:00:00.000000000 +0100
10916 +++ linux-3.1.1-vs2.3.2/include/linux/vs_tag.h  2011-10-24 18:53:33.000000000 +0200
10917 @@ -0,0 +1,47 @@
10918 +#ifndef _VS_TAG_H
10919 +#define _VS_TAG_H
10920 +
10921 +#include <linux/vserver/tag.h>
10922 +
10923 +/* check conditions */
10924 +
10925 +#define DX_ADMIN       0x0001
10926 +#define DX_WATCH       0x0002
10927 +#define DX_HOSTID      0x0008
10928 +
10929 +#define DX_IDENT       0x0010
10930 +
10931 +#define DX_ARG_MASK    0x0010
10932 +
10933 +
10934 +#define dx_task_tag(t) ((t)->tag)
10935 +
10936 +#define dx_current_tag() dx_task_tag(current)
10937 +
10938 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
10939 +
10940 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
10941 +
10942 +
10943 +/*
10944 + * check current context for ADMIN/WATCH and
10945 + * optionally against supplied argument
10946 + */
10947 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
10948 +{
10949 +       if (mode & DX_ARG_MASK) {
10950 +               if ((mode & DX_IDENT) && (id == cid))
10951 +                       return 1;
10952 +       }
10953 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
10954 +               ((mode & DX_WATCH) && (cid == 1)) ||
10955 +               ((mode & DX_HOSTID) && (id == 0)));
10956 +}
10957 +
10958 +struct inode;
10959 +int dx_permission(const struct inode *inode, int mask);
10960 +
10961 +
10962 +#else
10963 +#warning duplicate inclusion
10964 +#endif
10965 diff -NurpP --minimal linux-3.1.1/include/linux/vs_time.h linux-3.1.1-vs2.3.2/include/linux/vs_time.h
10966 --- linux-3.1.1/include/linux/vs_time.h 1970-01-01 01:00:00.000000000 +0100
10967 +++ linux-3.1.1-vs2.3.2/include/linux/vs_time.h 2011-10-24 18:53:33.000000000 +0200
10968 @@ -0,0 +1,19 @@
10969 +#ifndef _VS_TIME_H
10970 +#define _VS_TIME_H
10971 +
10972 +
10973 +/* time faking stuff */
10974 +
10975 +#ifdef CONFIG_VSERVER_VTIME
10976 +
10977 +extern void vx_adjust_timespec(struct timespec *ts);
10978 +extern int vx_settimeofday(const struct timespec *ts);
10979 +
10980 +#else
10981 +#define        vx_adjust_timespec(t)   do { } while (0)
10982 +#define        vx_settimeofday(t)      do_settimeofday(t)
10983 +#endif
10984 +
10985 +#else
10986 +#warning duplicate inclusion
10987 +#endif
10988 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/Kbuild linux-3.1.1-vs2.3.2/include/linux/vserver/Kbuild
10989 --- linux-3.1.1/include/linux/vserver/Kbuild    1970-01-01 01:00:00.000000000 +0100
10990 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/Kbuild    2011-10-24 18:53:33.000000000 +0200
10991 @@ -0,0 +1,8 @@
10992 +
10993 +header-y += context_cmd.h network_cmd.h space_cmd.h \
10994 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
10995 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
10996 +       debug_cmd.h device_cmd.h
10997 +
10998 +header-y += switch.h network.h monitor.h inode.h device.h
10999 +
11000 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/base.h linux-3.1.1-vs2.3.2/include/linux/vserver/base.h
11001 --- linux-3.1.1/include/linux/vserver/base.h    1970-01-01 01:00:00.000000000 +0100
11002 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/base.h    2011-10-24 18:53:33.000000000 +0200
11003 @@ -0,0 +1,178 @@
11004 +#ifndef _VX_BASE_H
11005 +#define _VX_BASE_H
11006 +
11007 +
11008 +/* context state changes */
11009 +
11010 +enum {
11011 +       VSC_STARTUP = 1,
11012 +       VSC_SHUTDOWN,
11013 +
11014 +       VSC_NETUP,
11015 +       VSC_NETDOWN,
11016 +};
11017 +
11018 +
11019 +
11020 +#define vx_task_xid(t) ((t)->xid)
11021 +
11022 +#define vx_current_xid() vx_task_xid(current)
11023 +
11024 +#define current_vx_info() (current->vx_info)
11025 +
11026 +
11027 +#define nx_task_nid(t) ((t)->nid)
11028 +
11029 +#define nx_current_nid() nx_task_nid(current)
11030 +
11031 +#define current_nx_info() (current->nx_info)
11032 +
11033 +
11034 +/* generic flag merging */
11035 +
11036 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
11037 +
11038 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
11039 +
11040 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
11041 +
11042 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
11043 +
11044 +
11045 +/* context flags */
11046 +
11047 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
11048 +
11049 +#define vx_current_flags()     __vx_flags(current_vx_info())
11050 +
11051 +#define vx_info_flags(v, m, f) \
11052 +       vs_check_flags(__vx_flags(v), m, f)
11053 +
11054 +#define task_vx_flags(t, m, f) \
11055 +       ((t) && vx_info_flags((t)->vx_info, m, f))
11056 +
11057 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
11058 +
11059 +
11060 +/* context caps */
11061 +
11062 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
11063 +
11064 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
11065 +
11066 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
11067 +
11068 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
11069 +
11070 +
11071 +
11072 +/* network flags */
11073 +
11074 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
11075 +
11076 +#define nx_current_flags()     __nx_flags(current_nx_info())
11077 +
11078 +#define nx_info_flags(n, m, f) \
11079 +       vs_check_flags(__nx_flags(n), m, f)
11080 +
11081 +#define task_nx_flags(t, m, f) \
11082 +       ((t) && nx_info_flags((t)->nx_info, m, f))
11083 +
11084 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
11085 +
11086 +
11087 +/* network caps */
11088 +
11089 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
11090 +
11091 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
11092 +
11093 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
11094 +
11095 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
11096 +
11097 +
11098 +/* context mask capabilities */
11099 +
11100 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
11101 +
11102 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
11103 +
11104 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
11105 +
11106 +
11107 +/* context bcap mask */
11108 +
11109 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
11110 +
11111 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
11112 +
11113 +
11114 +/* mask given bcaps */
11115 +
11116 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
11117 +
11118 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
11119 +
11120 +
11121 +/* masked cap_bset */
11122 +
11123 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
11124 +
11125 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
11126 +
11127 +#if 0
11128 +#define vx_info_mbcap(v, b) \
11129 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
11130 +       vx_info_bcaps(v, b) : (b))
11131 +
11132 +#define task_vx_mbcap(t, b) \
11133 +       vx_info_mbcap((t)->vx_info, (t)->b)
11134 +
11135 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
11136 +#endif
11137 +
11138 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
11139 +
11140 +#define vx_capable(b, c) (capable(b) || \
11141 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
11142 +
11143 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
11144 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
11145 +
11146 +#define nx_capable(b, c) (capable(b) || \
11147 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
11148 +
11149 +#define vx_task_initpid(t, n) \
11150 +       ((t)->vx_info && \
11151 +       ((t)->vx_info->vx_initpid == (n)))
11152 +
11153 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
11154 +
11155 +
11156 +/* context unshare mask */
11157 +
11158 +#define __vx_umask(v)          ((v)->vx_umask)
11159 +
11160 +#define vx_current_umask()     __vx_umask(current_vx_info())
11161 +
11162 +#define vx_can_unshare(b, f) (capable(b) || \
11163 +       (cap_raised(current_cap(), b) && \
11164 +       !((f) & ~vx_current_umask())))
11165 +
11166 +
11167 +#define __vx_wmask(v)          ((v)->vx_wmask)
11168 +
11169 +#define vx_current_wmask()     __vx_wmask(current_vx_info())
11170 +
11171 +
11172 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
11173 +
11174 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
11175 +
11176 +
11177 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
11178 +
11179 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
11180 +
11181 +#endif
11182 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/cacct.h linux-3.1.1-vs2.3.2/include/linux/vserver/cacct.h
11183 --- linux-3.1.1/include/linux/vserver/cacct.h   1970-01-01 01:00:00.000000000 +0100
11184 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/cacct.h   2011-10-24 18:53:33.000000000 +0200
11185 @@ -0,0 +1,15 @@
11186 +#ifndef _VX_CACCT_H
11187 +#define _VX_CACCT_H
11188 +
11189 +
11190 +enum sock_acc_field {
11191 +       VXA_SOCK_UNSPEC = 0,
11192 +       VXA_SOCK_UNIX,
11193 +       VXA_SOCK_INET,
11194 +       VXA_SOCK_INET6,
11195 +       VXA_SOCK_PACKET,
11196 +       VXA_SOCK_OTHER,
11197 +       VXA_SOCK_SIZE   /* array size */
11198 +};
11199 +
11200 +#endif /* _VX_CACCT_H */
11201 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/cacct_cmd.h linux-3.1.1-vs2.3.2/include/linux/vserver/cacct_cmd.h
11202 --- linux-3.1.1/include/linux/vserver/cacct_cmd.h       1970-01-01 01:00:00.000000000 +0100
11203 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/cacct_cmd.h       2011-10-24 18:53:33.000000000 +0200
11204 @@ -0,0 +1,23 @@
11205 +#ifndef _VX_CACCT_CMD_H
11206 +#define _VX_CACCT_CMD_H
11207 +
11208 +
11209 +/* virtual host info name commands */
11210 +
11211 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
11212 +
11213 +struct vcmd_sock_stat_v0 {
11214 +       uint32_t field;
11215 +       uint32_t count[3];
11216 +       uint64_t total[3];
11217 +};
11218 +
11219 +
11220 +#ifdef __KERNEL__
11221 +
11222 +#include <linux/compiler.h>
11223 +
11224 +extern int vc_sock_stat(struct vx_info *, void __user *);
11225 +
11226 +#endif /* __KERNEL__ */
11227 +#endif /* _VX_CACCT_CMD_H */
11228 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/cacct_def.h linux-3.1.1-vs2.3.2/include/linux/vserver/cacct_def.h
11229 --- linux-3.1.1/include/linux/vserver/cacct_def.h       1970-01-01 01:00:00.000000000 +0100
11230 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/cacct_def.h       2011-10-24 18:53:33.000000000 +0200
11231 @@ -0,0 +1,43 @@
11232 +#ifndef _VX_CACCT_DEF_H
11233 +#define _VX_CACCT_DEF_H
11234 +
11235 +#include <asm/atomic.h>
11236 +#include <linux/vserver/cacct.h>
11237 +
11238 +
11239 +struct _vx_sock_acc {
11240 +       atomic_long_t count;
11241 +       atomic_long_t total;
11242 +};
11243 +
11244 +/* context sub struct */
11245 +
11246 +struct _vx_cacct {
11247 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
11248 +       atomic_t slab[8];
11249 +       atomic_t page[6][8];
11250 +};
11251 +
11252 +#ifdef CONFIG_VSERVER_DEBUG
11253 +
11254 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
11255 +{
11256 +       int i, j;
11257 +
11258 +       printk("\t_vx_cacct:");
11259 +       for (i = 0; i < 6; i++) {
11260 +               struct _vx_sock_acc *ptr = cacct->sock[i];
11261 +
11262 +               printk("\t [%d] =", i);
11263 +               for (j = 0; j < 3; j++) {
11264 +                       printk(" [%d] = %8lu, %8lu", j,
11265 +                               atomic_long_read(&ptr[j].count),
11266 +                               atomic_long_read(&ptr[j].total));
11267 +               }
11268 +               printk("\n");
11269 +       }
11270 +}
11271 +
11272 +#endif
11273 +
11274 +#endif /* _VX_CACCT_DEF_H */
11275 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/cacct_int.h linux-3.1.1-vs2.3.2/include/linux/vserver/cacct_int.h
11276 --- linux-3.1.1/include/linux/vserver/cacct_int.h       1970-01-01 01:00:00.000000000 +0100
11277 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/cacct_int.h       2011-10-24 18:53:33.000000000 +0200
11278 @@ -0,0 +1,21 @@
11279 +#ifndef _VX_CACCT_INT_H
11280 +#define _VX_CACCT_INT_H
11281 +
11282 +
11283 +#ifdef __KERNEL__
11284 +
11285 +static inline
11286 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
11287 +{
11288 +       return atomic_long_read(&cacct->sock[type][pos].count);
11289 +}
11290 +
11291 +
11292 +static inline
11293 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
11294 +{
11295 +       return atomic_long_read(&cacct->sock[type][pos].total);
11296 +}
11297 +
11298 +#endif /* __KERNEL__ */
11299 +#endif /* _VX_CACCT_INT_H */
11300 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/check.h linux-3.1.1-vs2.3.2/include/linux/vserver/check.h
11301 --- linux-3.1.1/include/linux/vserver/check.h   1970-01-01 01:00:00.000000000 +0100
11302 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/check.h   2011-10-24 18:53:33.000000000 +0200
11303 @@ -0,0 +1,89 @@
11304 +#ifndef _VS_CHECK_H
11305 +#define _VS_CHECK_H
11306 +
11307 +
11308 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
11309 +
11310 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
11311 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
11312 +#else
11313 +#define MIN_D_CONTEXT  65536
11314 +#endif
11315 +
11316 +/* check conditions */
11317 +
11318 +#define VS_ADMIN       0x0001
11319 +#define VS_WATCH       0x0002
11320 +#define VS_HIDE                0x0004
11321 +#define VS_HOSTID      0x0008
11322 +
11323 +#define VS_IDENT       0x0010
11324 +#define VS_EQUIV       0x0020
11325 +#define VS_PARENT      0x0040
11326 +#define VS_CHILD       0x0080
11327 +
11328 +#define VS_ARG_MASK    0x00F0
11329 +
11330 +#define VS_DYNAMIC     0x0100
11331 +#define VS_STATIC      0x0200
11332 +
11333 +#define VS_ATR_MASK    0x0F00
11334 +
11335 +#ifdef CONFIG_VSERVER_PRIVACY
11336 +#define VS_ADMIN_P     (0)
11337 +#define VS_WATCH_P     (0)
11338 +#else
11339 +#define VS_ADMIN_P     VS_ADMIN
11340 +#define VS_WATCH_P     VS_WATCH
11341 +#endif
11342 +
11343 +#define VS_HARDIRQ     0x1000
11344 +#define VS_SOFTIRQ     0x2000
11345 +#define VS_IRQ         0x4000
11346 +
11347 +#define VS_IRQ_MASK    0xF000
11348 +
11349 +#include <linux/hardirq.h>
11350 +
11351 +/*
11352 + * check current context for ADMIN/WATCH and
11353 + * optionally against supplied argument
11354 + */
11355 +static inline int __vs_check(int cid, int id, unsigned int mode)
11356 +{
11357 +       if (mode & VS_ARG_MASK) {
11358 +               if ((mode & VS_IDENT) && (id == cid))
11359 +                       return 1;
11360 +       }
11361 +       if (mode & VS_ATR_MASK) {
11362 +               if ((mode & VS_DYNAMIC) &&
11363 +                       (id >= MIN_D_CONTEXT) &&
11364 +                       (id <= MAX_S_CONTEXT))
11365 +                       return 1;
11366 +               if ((mode & VS_STATIC) &&
11367 +                       (id > 1) && (id < MIN_D_CONTEXT))
11368 +                       return 1;
11369 +       }
11370 +       if (mode & VS_IRQ_MASK) {
11371 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
11372 +                       return 1;
11373 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
11374 +                       return 1;
11375 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
11376 +                       return 1;
11377 +       }
11378 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
11379 +               ((mode & VS_WATCH) && (cid == 1)) ||
11380 +               ((mode & VS_HOSTID) && (id == 0)));
11381 +}
11382 +
11383 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
11384 +
11385 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
11386 +
11387 +
11388 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
11389 +
11390 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
11391 +
11392 +#endif
11393 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/context.h linux-3.1.1-vs2.3.2/include/linux/vserver/context.h
11394 --- linux-3.1.1/include/linux/vserver/context.h 1970-01-01 01:00:00.000000000 +0100
11395 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/context.h 2011-10-24 18:53:33.000000000 +0200
11396 @@ -0,0 +1,190 @@
11397 +#ifndef _VX_CONTEXT_H
11398 +#define _VX_CONTEXT_H
11399 +
11400 +#include <linux/types.h>
11401 +#include <linux/capability.h>
11402 +
11403 +
11404 +/* context flags */
11405 +
11406 +#define VXF_INFO_SCHED         0x00000002
11407 +#define VXF_INFO_NPROC         0x00000004
11408 +#define VXF_INFO_PRIVATE       0x00000008
11409 +
11410 +#define VXF_INFO_INIT          0x00000010
11411 +#define VXF_INFO_HIDE          0x00000020
11412 +#define VXF_INFO_ULIMIT                0x00000040
11413 +#define VXF_INFO_NSPACE                0x00000080
11414 +
11415 +#define VXF_SCHED_HARD         0x00000100
11416 +#define VXF_SCHED_PRIO         0x00000200
11417 +#define VXF_SCHED_PAUSE                0x00000400
11418 +
11419 +#define VXF_VIRT_MEM           0x00010000
11420 +#define VXF_VIRT_UPTIME                0x00020000
11421 +#define VXF_VIRT_CPU           0x00040000
11422 +#define VXF_VIRT_LOAD          0x00080000
11423 +#define VXF_VIRT_TIME          0x00100000
11424 +
11425 +#define VXF_HIDE_MOUNT         0x01000000
11426 +/* was VXF_HIDE_NETIF          0x02000000 */
11427 +#define VXF_HIDE_VINFO         0x04000000
11428 +
11429 +#define VXF_STATE_SETUP                (1ULL << 32)
11430 +#define VXF_STATE_INIT         (1ULL << 33)
11431 +#define VXF_STATE_ADMIN                (1ULL << 34)
11432 +
11433 +#define VXF_SC_HELPER          (1ULL << 36)
11434 +#define VXF_REBOOT_KILL                (1ULL << 37)
11435 +#define VXF_PERSISTENT         (1ULL << 38)
11436 +
11437 +#define VXF_FORK_RSS           (1ULL << 48)
11438 +#define VXF_PROLIFIC           (1ULL << 49)
11439 +
11440 +#define VXF_IGNEG_NICE         (1ULL << 52)
11441 +
11442 +#define VXF_ONE_TIME           (0x0007ULL << 32)
11443 +
11444 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
11445 +
11446 +
11447 +/* context migration */
11448 +
11449 +#define VXM_SET_INIT           0x00000001
11450 +#define VXM_SET_REAPER         0x00000002
11451 +
11452 +/* context caps */
11453 +
11454 +#define VXC_CAP_MASK           0x00000000
11455 +
11456 +#define VXC_SET_UTSNAME                0x00000001
11457 +#define VXC_SET_RLIMIT         0x00000002
11458 +#define VXC_FS_SECURITY                0x00000004
11459 +#define VXC_FS_TRUSTED         0x00000008
11460 +#define VXC_TIOCSTI            0x00000010
11461 +
11462 +/* was VXC_RAW_ICMP            0x00000100 */
11463 +#define VXC_SYSLOG             0x00001000
11464 +#define VXC_OOM_ADJUST         0x00002000
11465 +#define VXC_AUDIT_CONTROL      0x00004000
11466 +
11467 +#define VXC_SECURE_MOUNT       0x00010000
11468 +#define VXC_SECURE_REMOUNT     0x00020000
11469 +#define VXC_BINARY_MOUNT       0x00040000
11470 +
11471 +#define VXC_QUOTA_CTL          0x00100000
11472 +#define VXC_ADMIN_MAPPER       0x00200000
11473 +#define VXC_ADMIN_CLOOP                0x00400000
11474 +
11475 +#define VXC_KTHREAD            0x01000000
11476 +#define VXC_NAMESPACE          0x02000000
11477 +
11478 +
11479 +#ifdef __KERNEL__
11480 +
11481 +#include <linux/list.h>
11482 +#include <linux/spinlock.h>
11483 +#include <linux/rcupdate.h>
11484 +
11485 +#include "limit_def.h"
11486 +#include "sched_def.h"
11487 +#include "cvirt_def.h"
11488 +#include "cacct_def.h"
11489 +#include "device_def.h"
11490 +
11491 +#define VX_SPACES      2
11492 +
11493 +struct _vx_info_pc {
11494 +       struct _vx_sched_pc sched_pc;
11495 +       struct _vx_cvirt_pc cvirt_pc;
11496 +};
11497 +
11498 +struct _vx_space {
11499 +       unsigned long vx_nsmask;                /* assignment mask */
11500 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
11501 +       struct fs_struct *vx_fs;                /* private namespace fs */
11502 +       const struct cred *vx_cred;             /* task credentials */
11503 +};
11504 +
11505 +struct vx_info {
11506 +       struct hlist_node vx_hlist;             /* linked list of contexts */
11507 +       xid_t vx_id;                            /* context id */
11508 +       atomic_t vx_usecnt;                     /* usage count */
11509 +       atomic_t vx_tasks;                      /* tasks count */
11510 +       struct vx_info *vx_parent;              /* parent context */
11511 +       int vx_state;                           /* context state */
11512 +
11513 +       struct _vx_space space[VX_SPACES];      /* namespace store */
11514 +
11515 +       uint64_t vx_flags;                      /* context flags */
11516 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
11517 +       uint64_t vx_umask;                      /* unshare mask (guest) */
11518 +       uint64_t vx_wmask;                      /* warn mask (guest) */
11519 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
11520 +
11521 +       struct task_struct *vx_reaper;          /* guest reaper process */
11522 +       pid_t vx_initpid;                       /* PID of guest init */
11523 +       int64_t vx_badness_bias;                /* OOM points bias */
11524 +
11525 +       struct _vx_limit limit;                 /* vserver limits */
11526 +       struct _vx_sched sched;                 /* vserver scheduler */
11527 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
11528 +       struct _vx_cacct cacct;                 /* context accounting */
11529 +
11530 +       struct _vx_device dmap;                 /* default device map targets */
11531 +
11532 +#ifndef CONFIG_SMP
11533 +       struct _vx_info_pc info_pc;             /* per cpu data */
11534 +#else
11535 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
11536 +#endif
11537 +
11538 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
11539 +       int reboot_cmd;                         /* last sys_reboot() cmd */
11540 +       int exit_code;                          /* last process exit code */
11541 +
11542 +       char vx_name[65];                       /* vserver name */
11543 +};
11544 +
11545 +#ifndef CONFIG_SMP
11546 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
11547 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
11548 +#else
11549 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
11550 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
11551 +#endif
11552 +
11553 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
11554 +
11555 +
11556 +struct vx_info_save {
11557 +       struct vx_info *vxi;
11558 +       xid_t xid;
11559 +};
11560 +
11561 +
11562 +/* status flags */
11563 +
11564 +#define VXS_HASHED     0x0001
11565 +#define VXS_PAUSED     0x0010
11566 +#define VXS_SHUTDOWN   0x0100
11567 +#define VXS_HELPER     0x1000
11568 +#define VXS_RELEASED   0x8000
11569 +
11570 +
11571 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
11572 +extern void release_vx_info(struct vx_info *, struct task_struct *);
11573 +
11574 +extern struct vx_info *lookup_vx_info(int);
11575 +extern struct vx_info *lookup_or_create_vx_info(int);
11576 +
11577 +extern int get_xid_list(int, unsigned int *, int);
11578 +extern int xid_is_hashed(xid_t);
11579 +
11580 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
11581 +
11582 +extern long vs_state_change(struct vx_info *, unsigned int);
11583 +
11584 +
11585 +#endif /* __KERNEL__ */
11586 +#endif /* _VX_CONTEXT_H */
11587 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/context_cmd.h linux-3.1.1-vs2.3.2/include/linux/vserver/context_cmd.h
11588 --- linux-3.1.1/include/linux/vserver/context_cmd.h     1970-01-01 01:00:00.000000000 +0100
11589 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/context_cmd.h     2011-10-24 18:53:33.000000000 +0200
11590 @@ -0,0 +1,162 @@
11591 +#ifndef _VX_CONTEXT_CMD_H
11592 +#define _VX_CONTEXT_CMD_H
11593 +
11594 +
11595 +/* vinfo commands */
11596 +
11597 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
11598 +
11599 +#ifdef __KERNEL__
11600 +extern int vc_task_xid(uint32_t);
11601 +
11602 +#endif /* __KERNEL__ */
11603 +
11604 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
11605 +
11606 +struct vcmd_vx_info_v0 {
11607 +       uint32_t xid;
11608 +       uint32_t initpid;
11609 +       /* more to come */
11610 +};
11611 +
11612 +#ifdef __KERNEL__
11613 +extern int vc_vx_info(struct vx_info *, void __user *);
11614 +
11615 +#endif /* __KERNEL__ */
11616 +
11617 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
11618 +
11619 +struct vcmd_ctx_stat_v0 {
11620 +       uint32_t usecnt;
11621 +       uint32_t tasks;
11622 +       /* more to come */
11623 +};
11624 +
11625 +#ifdef __KERNEL__
11626 +extern int vc_ctx_stat(struct vx_info *, void __user *);
11627 +
11628 +#endif /* __KERNEL__ */
11629 +
11630 +/* context commands */
11631 +
11632 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
11633 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
11634 +
11635 +struct vcmd_ctx_create {
11636 +       uint64_t flagword;
11637 +};
11638 +
11639 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
11640 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
11641 +
11642 +struct vcmd_ctx_migrate {
11643 +       uint64_t flagword;
11644 +};
11645 +
11646 +#ifdef __KERNEL__
11647 +extern int vc_ctx_create(uint32_t, void __user *);
11648 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
11649 +
11650 +#endif /* __KERNEL__ */
11651 +
11652 +
11653 +/* flag commands */
11654 +
11655 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
11656 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
11657 +
11658 +struct vcmd_ctx_flags_v0 {
11659 +       uint64_t flagword;
11660 +       uint64_t mask;
11661 +};
11662 +
11663 +#ifdef __KERNEL__
11664 +extern int vc_get_cflags(struct vx_info *, void __user *);
11665 +extern int vc_set_cflags(struct vx_info *, void __user *);
11666 +
11667 +#endif /* __KERNEL__ */
11668 +
11669 +
11670 +/* context caps commands */
11671 +
11672 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
11673 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
11674 +
11675 +struct vcmd_ctx_caps_v1 {
11676 +       uint64_t ccaps;
11677 +       uint64_t cmask;
11678 +};
11679 +
11680 +#ifdef __KERNEL__
11681 +extern int vc_get_ccaps(struct vx_info *, void __user *);
11682 +extern int vc_set_ccaps(struct vx_info *, void __user *);
11683 +
11684 +#endif /* __KERNEL__ */
11685 +
11686 +
11687 +/* bcaps commands */
11688 +
11689 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
11690 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
11691 +
11692 +struct vcmd_bcaps {
11693 +       uint64_t bcaps;
11694 +       uint64_t bmask;
11695 +};
11696 +
11697 +#ifdef __KERNEL__
11698 +extern int vc_get_bcaps(struct vx_info *, void __user *);
11699 +extern int vc_set_bcaps(struct vx_info *, void __user *);
11700 +
11701 +#endif /* __KERNEL__ */
11702 +
11703 +
11704 +/* umask commands */
11705 +
11706 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
11707 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
11708 +
11709 +struct vcmd_umask {
11710 +       uint64_t umask;
11711 +       uint64_t mask;
11712 +};
11713 +
11714 +#ifdef __KERNEL__
11715 +extern int vc_get_umask(struct vx_info *, void __user *);
11716 +extern int vc_set_umask(struct vx_info *, void __user *);
11717 +
11718 +#endif /* __KERNEL__ */
11719 +
11720 +
11721 +/* wmask commands */
11722 +
11723 +#define VCMD_get_wmask         VC_CMD(FLAGS, 15, 0)
11724 +#define VCMD_set_wmask         VC_CMD(FLAGS, 16, 0)
11725 +
11726 +struct vcmd_wmask {
11727 +       uint64_t wmask;
11728 +       uint64_t mask;
11729 +};
11730 +
11731 +#ifdef __KERNEL__
11732 +extern int vc_get_wmask(struct vx_info *, void __user *);
11733 +extern int vc_set_wmask(struct vx_info *, void __user *);
11734 +
11735 +#endif /* __KERNEL__ */
11736 +
11737 +
11738 +/* OOM badness */
11739 +
11740 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
11741 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
11742 +
11743 +struct vcmd_badness_v0 {
11744 +       int64_t bias;
11745 +};
11746 +
11747 +#ifdef __KERNEL__
11748 +extern int vc_get_badness(struct vx_info *, void __user *);
11749 +extern int vc_set_badness(struct vx_info *, void __user *);
11750 +
11751 +#endif /* __KERNEL__ */
11752 +#endif /* _VX_CONTEXT_CMD_H */
11753 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/cvirt.h linux-3.1.1-vs2.3.2/include/linux/vserver/cvirt.h
11754 --- linux-3.1.1/include/linux/vserver/cvirt.h   1970-01-01 01:00:00.000000000 +0100
11755 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/cvirt.h   2011-10-24 18:53:33.000000000 +0200
11756 @@ -0,0 +1,20 @@
11757 +#ifndef _VX_CVIRT_H
11758 +#define _VX_CVIRT_H
11759 +
11760 +
11761 +#ifdef __KERNEL__
11762 +
11763 +struct timespec;
11764 +
11765 +void vx_vsi_uptime(struct timespec *, struct timespec *);
11766 +
11767 +
11768 +struct vx_info;
11769 +
11770 +void vx_update_load(struct vx_info *);
11771 +
11772 +
11773 +int vx_do_syslog(int, char __user *, int);
11774 +
11775 +#endif /* __KERNEL__ */
11776 +#endif /* _VX_CVIRT_H */
11777 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/cvirt_cmd.h linux-3.1.1-vs2.3.2/include/linux/vserver/cvirt_cmd.h
11778 --- linux-3.1.1/include/linux/vserver/cvirt_cmd.h       1970-01-01 01:00:00.000000000 +0100
11779 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/cvirt_cmd.h       2011-10-24 18:53:33.000000000 +0200
11780 @@ -0,0 +1,53 @@
11781 +#ifndef _VX_CVIRT_CMD_H
11782 +#define _VX_CVIRT_CMD_H
11783 +
11784 +
11785 +/* virtual host info name commands */
11786 +
11787 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
11788 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
11789 +
11790 +struct vcmd_vhi_name_v0 {
11791 +       uint32_t field;
11792 +       char name[65];
11793 +};
11794 +
11795 +
11796 +enum vhi_name_field {
11797 +       VHIN_CONTEXT = 0,
11798 +       VHIN_SYSNAME,
11799 +       VHIN_NODENAME,
11800 +       VHIN_RELEASE,
11801 +       VHIN_VERSION,
11802 +       VHIN_MACHINE,
11803 +       VHIN_DOMAINNAME,
11804 +};
11805 +
11806 +
11807 +#ifdef __KERNEL__
11808 +
11809 +#include <linux/compiler.h>
11810 +
11811 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
11812 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
11813 +
11814 +#endif /* __KERNEL__ */
11815 +
11816 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
11817 +
11818 +struct vcmd_virt_stat_v0 {
11819 +       uint64_t offset;
11820 +       uint64_t uptime;
11821 +       uint32_t nr_threads;
11822 +       uint32_t nr_running;
11823 +       uint32_t nr_uninterruptible;
11824 +       uint32_t nr_onhold;
11825 +       uint32_t nr_forks;
11826 +       uint32_t load[3];
11827 +};
11828 +
11829 +#ifdef __KERNEL__
11830 +extern int vc_virt_stat(struct vx_info *, void __user *);
11831 +
11832 +#endif /* __KERNEL__ */
11833 +#endif /* _VX_CVIRT_CMD_H */
11834 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/cvirt_def.h linux-3.1.1-vs2.3.2/include/linux/vserver/cvirt_def.h
11835 --- linux-3.1.1/include/linux/vserver/cvirt_def.h       1970-01-01 01:00:00.000000000 +0100
11836 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/cvirt_def.h       2011-10-24 18:53:33.000000000 +0200
11837 @@ -0,0 +1,80 @@
11838 +#ifndef _VX_CVIRT_DEF_H
11839 +#define _VX_CVIRT_DEF_H
11840 +
11841 +#include <linux/jiffies.h>
11842 +#include <linux/spinlock.h>
11843 +#include <linux/wait.h>
11844 +#include <linux/time.h>
11845 +#include <asm/atomic.h>
11846 +
11847 +
11848 +struct _vx_usage_stat {
11849 +       uint64_t user;
11850 +       uint64_t nice;
11851 +       uint64_t system;
11852 +       uint64_t softirq;
11853 +       uint64_t irq;
11854 +       uint64_t idle;
11855 +       uint64_t iowait;
11856 +};
11857 +
11858 +struct _vx_syslog {
11859 +       wait_queue_head_t log_wait;
11860 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
11861 +
11862 +       unsigned long log_start;        /* next char to be read by syslog() */
11863 +       unsigned long con_start;        /* next char to be sent to consoles */
11864 +       unsigned long log_end;  /* most-recently-written-char + 1 */
11865 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
11866 +
11867 +       char log_buf[1024];
11868 +};
11869 +
11870 +
11871 +/* context sub struct */
11872 +
11873 +struct _vx_cvirt {
11874 +       atomic_t nr_threads;            /* number of current threads */
11875 +       atomic_t nr_running;            /* number of running threads */
11876 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
11877 +
11878 +       atomic_t nr_onhold;             /* processes on hold */
11879 +       uint32_t onhold_last;           /* jiffies when put on hold */
11880 +
11881 +       struct timespec bias_ts;        /* time offset to the host */
11882 +       struct timespec bias_idle;
11883 +       struct timespec bias_uptime;    /* context creation point */
11884 +       uint64_t bias_clock;            /* offset in clock_t */
11885 +
11886 +       spinlock_t load_lock;           /* lock for the load averages */
11887 +       atomic_t load_updates;          /* nr of load updates done so far */
11888 +       uint32_t load_last;             /* last time load was calculated */
11889 +       uint32_t load[3];               /* load averages 1,5,15 */
11890 +
11891 +       atomic_t total_forks;           /* number of forks so far */
11892 +
11893 +       struct _vx_syslog syslog;
11894 +};
11895 +
11896 +struct _vx_cvirt_pc {
11897 +       struct _vx_usage_stat cpustat;
11898 +};
11899 +
11900 +
11901 +#ifdef CONFIG_VSERVER_DEBUG
11902 +
11903 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
11904 +{
11905 +       printk("\t_vx_cvirt:\n");
11906 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
11907 +               atomic_read(&cvirt->nr_threads),
11908 +               atomic_read(&cvirt->nr_running),
11909 +               atomic_read(&cvirt->nr_uninterruptible),
11910 +               atomic_read(&cvirt->nr_onhold));
11911 +       /* add rest here */
11912 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
11913 +}
11914 +
11915 +#endif
11916 +
11917 +#endif /* _VX_CVIRT_DEF_H */
11918 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/debug.h linux-3.1.1-vs2.3.2/include/linux/vserver/debug.h
11919 --- linux-3.1.1/include/linux/vserver/debug.h   1970-01-01 01:00:00.000000000 +0100
11920 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/debug.h   2011-10-24 18:53:33.000000000 +0200
11921 @@ -0,0 +1,140 @@
11922 +#ifndef _VX_DEBUG_H
11923 +#define _VX_DEBUG_H
11924 +
11925 +
11926 +#define VXD_CBIT(n, m) (vx_debug_ ## n & (1 << (m)))
11927 +#define VXD_CMIN(n, m) (vx_debug_ ## n > (m))
11928 +#define VXD_MASK(n, m) (vx_debug_ ## n & (m))
11929 +
11930 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
11931 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
11932 +#define VXF_DEV                "%p[%lu,%d:%d]"
11933 +
11934 +#if    defined(CONFIG_QUOTES_UTF8)
11935 +#define        VS_Q_LQM        "\xc2\xbb"
11936 +#define        VS_Q_RQM        "\xc2\xab"
11937 +#elif  defined(CONFIG_QUOTES_ASCII)
11938 +#define        VS_Q_LQM        "\x27"
11939 +#define        VS_Q_RQM        "\x27"
11940 +#else
11941 +#define        VS_Q_LQM        "\xbb"
11942 +#define        VS_Q_RQM        "\xab"
11943 +#endif
11944 +
11945 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
11946 +
11947 +
11948 +#define vxd_path(p)                                            \
11949 +       ({ static char _buffer[PATH_MAX];                       \
11950 +          d_path(p, _buffer, sizeof(_buffer)); })
11951 +
11952 +#define vxd_cond_path(n)                                       \
11953 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
11954 +
11955 +
11956 +#ifdef CONFIG_VSERVER_DEBUG
11957 +
11958 +extern unsigned int vx_debug_switch;
11959 +extern unsigned int vx_debug_xid;
11960 +extern unsigned int vx_debug_nid;
11961 +extern unsigned int vx_debug_tag;
11962 +extern unsigned int vx_debug_net;
11963 +extern unsigned int vx_debug_limit;
11964 +extern unsigned int vx_debug_cres;
11965 +extern unsigned int vx_debug_dlim;
11966 +extern unsigned int vx_debug_quota;
11967 +extern unsigned int vx_debug_cvirt;
11968 +extern unsigned int vx_debug_space;
11969 +extern unsigned int vx_debug_misc;
11970 +
11971 +
11972 +#define VX_LOGLEVEL    "vxD: "
11973 +#define VX_PROC_FMT    "%p: "
11974 +#define VX_PROCESS     current
11975 +
11976 +#define vxdprintk(c, f, x...)                                  \
11977 +       do {                                                    \
11978 +               if (c)                                          \
11979 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
11980 +                               VX_PROCESS , ##x);              \
11981 +       } while (0)
11982 +
11983 +#define vxlprintk(c, f, x...)                                  \
11984 +       do {                                                    \
11985 +               if (c)                                          \
11986 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
11987 +       } while (0)
11988 +
11989 +#define vxfprintk(c, f, x...)                                  \
11990 +       do {                                                    \
11991 +               if (c)                                          \
11992 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
11993 +       } while (0)
11994 +
11995 +
11996 +struct vx_info;
11997 +
11998 +void dump_vx_info(struct vx_info *, int);
11999 +void dump_vx_info_inactive(int);
12000 +
12001 +#else  /* CONFIG_VSERVER_DEBUG */
12002 +
12003 +#define vx_debug_switch 0
12004 +#define vx_debug_xid   0
12005 +#define vx_debug_nid   0
12006 +#define vx_debug_tag   0
12007 +#define vx_debug_net   0
12008 +#define vx_debug_limit 0
12009 +#define vx_debug_cres  0
12010 +#define vx_debug_dlim  0
12011 +#define vx_debug_cvirt 0
12012 +
12013 +#define vxdprintk(x...) do { } while (0)
12014 +#define vxlprintk(x...) do { } while (0)
12015 +#define vxfprintk(x...) do { } while (0)
12016 +
12017 +#endif /* CONFIG_VSERVER_DEBUG */
12018 +
12019 +
12020 +#ifdef CONFIG_VSERVER_WARN
12021 +
12022 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
12023 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
12024 +#define VX_WARN_XID    "[xid #%u] "
12025 +#define VX_WARN_NID    "[nid #%u] "
12026 +#define VX_WARN_TAG    "[tag #%u] "
12027 +
12028 +#define vxwprintk(c, f, x...)                                  \
12029 +       do {                                                    \
12030 +               if (c)                                          \
12031 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
12032 +       } while (0)
12033 +
12034 +#else  /* CONFIG_VSERVER_WARN */
12035 +
12036 +#define vxwprintk(x...) do { } while (0)
12037 +
12038 +#endif /* CONFIG_VSERVER_WARN */
12039 +
12040 +#define vxwprintk_task(c, f, x...)                             \
12041 +       vxwprintk(c, VX_WARN_TASK f,                            \
12042 +               current->comm, current->pid,                    \
12043 +               current->xid, current->nid, current->tag, ##x)
12044 +#define vxwprintk_xid(c, f, x...)                              \
12045 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
12046 +#define vxwprintk_nid(c, f, x...)                              \
12047 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
12048 +#define vxwprintk_tag(c, f, x...)                              \
12049 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
12050 +
12051 +#ifdef CONFIG_VSERVER_DEBUG
12052 +#define vxd_assert_lock(l)     assert_spin_locked(l)
12053 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
12054 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
12055 +#else
12056 +#define vxd_assert_lock(l)     do { } while (0)
12057 +#define vxd_assert(c, f, x...) do { } while (0)
12058 +#endif
12059 +
12060 +
12061 +#endif /* _VX_DEBUG_H */
12062 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/debug_cmd.h linux-3.1.1-vs2.3.2/include/linux/vserver/debug_cmd.h
12063 --- linux-3.1.1/include/linux/vserver/debug_cmd.h       1970-01-01 01:00:00.000000000 +0100
12064 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/debug_cmd.h       2011-10-24 18:53:33.000000000 +0200
12065 @@ -0,0 +1,58 @@
12066 +#ifndef _VX_DEBUG_CMD_H
12067 +#define _VX_DEBUG_CMD_H
12068 +
12069 +
12070 +/* debug commands */
12071 +
12072 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
12073 +
12074 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
12075 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
12076 +
12077 +struct  vcmd_read_history_v0 {
12078 +       uint32_t index;
12079 +       uint32_t count;
12080 +       char __user *data;
12081 +};
12082 +
12083 +struct  vcmd_read_monitor_v0 {
12084 +       uint32_t index;
12085 +       uint32_t count;
12086 +       char __user *data;
12087 +};
12088 +
12089 +
12090 +#ifdef __KERNEL__
12091 +
12092 +#ifdef CONFIG_COMPAT
12093 +
12094 +#include <asm/compat.h>
12095 +
12096 +struct vcmd_read_history_v0_x32 {
12097 +       uint32_t index;
12098 +       uint32_t count;
12099 +       compat_uptr_t data_ptr;
12100 +};
12101 +
12102 +struct vcmd_read_monitor_v0_x32 {
12103 +       uint32_t index;
12104 +       uint32_t count;
12105 +       compat_uptr_t data_ptr;
12106 +};
12107 +
12108 +#endif  /* CONFIG_COMPAT */
12109 +
12110 +extern int vc_dump_history(uint32_t);
12111 +
12112 +extern int vc_read_history(uint32_t, void __user *);
12113 +extern int vc_read_monitor(uint32_t, void __user *);
12114 +
12115 +#ifdef CONFIG_COMPAT
12116 +
12117 +extern int vc_read_history_x32(uint32_t, void __user *);
12118 +extern int vc_read_monitor_x32(uint32_t, void __user *);
12119 +
12120 +#endif  /* CONFIG_COMPAT */
12121 +
12122 +#endif /* __KERNEL__ */
12123 +#endif /* _VX_DEBUG_CMD_H */
12124 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/device.h linux-3.1.1-vs2.3.2/include/linux/vserver/device.h
12125 --- linux-3.1.1/include/linux/vserver/device.h  1970-01-01 01:00:00.000000000 +0100
12126 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/device.h  2011-10-24 18:53:33.000000000 +0200
12127 @@ -0,0 +1,15 @@
12128 +#ifndef _VX_DEVICE_H
12129 +#define _VX_DEVICE_H
12130 +
12131 +
12132 +#define DATTR_CREATE   0x00000001
12133 +#define DATTR_OPEN     0x00000002
12134 +
12135 +#define DATTR_REMAP    0x00000010
12136 +
12137 +#define DATTR_MASK     0x00000013
12138 +
12139 +
12140 +#else  /* _VX_DEVICE_H */
12141 +#warning duplicate inclusion
12142 +#endif /* _VX_DEVICE_H */
12143 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/device_cmd.h linux-3.1.1-vs2.3.2/include/linux/vserver/device_cmd.h
12144 --- linux-3.1.1/include/linux/vserver/device_cmd.h      1970-01-01 01:00:00.000000000 +0100
12145 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/device_cmd.h      2011-10-24 18:53:33.000000000 +0200
12146 @@ -0,0 +1,44 @@
12147 +#ifndef _VX_DEVICE_CMD_H
12148 +#define _VX_DEVICE_CMD_H
12149 +
12150 +
12151 +/*  device vserver commands */
12152 +
12153 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
12154 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
12155 +
12156 +struct vcmd_set_mapping_v0 {
12157 +       const char __user *device;
12158 +       const char __user *target;
12159 +       uint32_t flags;
12160 +};
12161 +
12162 +
12163 +#ifdef __KERNEL__
12164 +
12165 +#ifdef CONFIG_COMPAT
12166 +
12167 +#include <asm/compat.h>
12168 +
12169 +struct vcmd_set_mapping_v0_x32 {
12170 +       compat_uptr_t device_ptr;
12171 +       compat_uptr_t target_ptr;
12172 +       uint32_t flags;
12173 +};
12174 +
12175 +#endif /* CONFIG_COMPAT */
12176 +
12177 +#include <linux/compiler.h>
12178 +
12179 +extern int vc_set_mapping(struct vx_info *, void __user *);
12180 +extern int vc_unset_mapping(struct vx_info *, void __user *);
12181 +
12182 +#ifdef CONFIG_COMPAT
12183 +
12184 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
12185 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
12186 +
12187 +#endif /* CONFIG_COMPAT */
12188 +
12189 +#endif /* __KERNEL__ */
12190 +#endif /* _VX_DEVICE_CMD_H */
12191 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/device_def.h linux-3.1.1-vs2.3.2/include/linux/vserver/device_def.h
12192 --- linux-3.1.1/include/linux/vserver/device_def.h      1970-01-01 01:00:00.000000000 +0100
12193 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/device_def.h      2011-10-24 18:53:33.000000000 +0200
12194 @@ -0,0 +1,17 @@
12195 +#ifndef _VX_DEVICE_DEF_H
12196 +#define _VX_DEVICE_DEF_H
12197 +
12198 +#include <linux/types.h>
12199 +
12200 +struct vx_dmap_target {
12201 +       dev_t target;
12202 +       uint32_t flags;
12203 +};
12204 +
12205 +struct _vx_device {
12206 +#ifdef CONFIG_VSERVER_DEVICE
12207 +       struct vx_dmap_target targets[2];
12208 +#endif
12209 +};
12210 +
12211 +#endif /* _VX_DEVICE_DEF_H */
12212 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/dlimit.h linux-3.1.1-vs2.3.2/include/linux/vserver/dlimit.h
12213 --- linux-3.1.1/include/linux/vserver/dlimit.h  1970-01-01 01:00:00.000000000 +0100
12214 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/dlimit.h  2011-10-24 18:53:33.000000000 +0200
12215 @@ -0,0 +1,54 @@
12216 +#ifndef _VX_DLIMIT_H
12217 +#define _VX_DLIMIT_H
12218 +
12219 +#include "switch.h"
12220 +
12221 +
12222 +#ifdef __KERNEL__
12223 +
12224 +/*      keep in sync with CDLIM_INFINITY       */
12225 +
12226 +#define DLIM_INFINITY          (~0ULL)
12227 +
12228 +#include <linux/spinlock.h>
12229 +#include <linux/rcupdate.h>
12230 +
12231 +struct super_block;
12232 +
12233 +struct dl_info {
12234 +       struct hlist_node dl_hlist;             /* linked list of contexts */
12235 +       struct rcu_head dl_rcu;                 /* the rcu head */
12236 +       tag_t dl_tag;                           /* context tag */
12237 +       atomic_t dl_usecnt;                     /* usage count */
12238 +       atomic_t dl_refcnt;                     /* reference count */
12239 +
12240 +       struct super_block *dl_sb;              /* associated superblock */
12241 +
12242 +       spinlock_t dl_lock;                     /* protect the values */
12243 +
12244 +       unsigned long long dl_space_used;       /* used space in bytes */
12245 +       unsigned long long dl_space_total;      /* maximum space in bytes */
12246 +       unsigned long dl_inodes_used;           /* used inodes */
12247 +       unsigned long dl_inodes_total;          /* maximum inodes */
12248 +
12249 +       unsigned int dl_nrlmult;                /* non root limit mult */
12250 +};
12251 +
12252 +struct rcu_head;
12253 +
12254 +extern void rcu_free_dl_info(struct rcu_head *);
12255 +extern void unhash_dl_info(struct dl_info *);
12256 +
12257 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
12258 +
12259 +
12260 +struct kstatfs;
12261 +
12262 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
12263 +
12264 +typedef uint64_t dlsize_t;
12265 +
12266 +#endif /* __KERNEL__ */
12267 +#else  /* _VX_DLIMIT_H */
12268 +#warning duplicate inclusion
12269 +#endif /* _VX_DLIMIT_H */
12270 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/dlimit_cmd.h linux-3.1.1-vs2.3.2/include/linux/vserver/dlimit_cmd.h
12271 --- linux-3.1.1/include/linux/vserver/dlimit_cmd.h      1970-01-01 01:00:00.000000000 +0100
12272 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/dlimit_cmd.h      2011-10-24 18:53:33.000000000 +0200
12273 @@ -0,0 +1,109 @@
12274 +#ifndef _VX_DLIMIT_CMD_H
12275 +#define _VX_DLIMIT_CMD_H
12276 +
12277 +
12278 +/*  dlimit vserver commands */
12279 +
12280 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
12281 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
12282 +
12283 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
12284 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
12285 +
12286 +struct vcmd_ctx_dlimit_base_v0 {
12287 +       const char __user *name;
12288 +       uint32_t flags;
12289 +};
12290 +
12291 +struct vcmd_ctx_dlimit_v0 {
12292 +       const char __user *name;
12293 +       uint32_t space_used;                    /* used space in kbytes */
12294 +       uint32_t space_total;                   /* maximum space in kbytes */
12295 +       uint32_t inodes_used;                   /* used inodes */
12296 +       uint32_t inodes_total;                  /* maximum inodes */
12297 +       uint32_t reserved;                      /* reserved for root in % */
12298 +       uint32_t flags;
12299 +};
12300 +
12301 +#define CDLIM_UNSET            ((uint32_t)0UL)
12302 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
12303 +#define CDLIM_KEEP             ((uint32_t)~1UL)
12304 +
12305 +#define DLIME_UNIT     0
12306 +#define DLIME_KILO     1
12307 +#define DLIME_MEGA     2
12308 +#define DLIME_GIGA     3
12309 +
12310 +#define DLIMF_SHIFT    0x10
12311 +
12312 +#define DLIMS_USED     0
12313 +#define DLIMS_TOTAL    2
12314 +
12315 +static inline
12316 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
12317 +{
12318 +       int exp = (flags & DLIMF_SHIFT) ?
12319 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
12320 +       return ((uint64_t)val) << (10 * exp);
12321 +}
12322 +
12323 +static inline
12324 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
12325 +{
12326 +       int exp = 0;
12327 +
12328 +       if (*flags & DLIMF_SHIFT) {
12329 +               while (val > (1LL << 32) && (exp < 3)) {
12330 +                       val >>= 10;
12331 +                       exp++;
12332 +               }
12333 +               *flags &= ~(DLIME_GIGA << shift);
12334 +               *flags |= exp << shift;
12335 +       } else
12336 +               val >>= 10;
12337 +       return val;
12338 +}
12339 +
12340 +#ifdef __KERNEL__
12341 +
12342 +#ifdef CONFIG_COMPAT
12343 +
12344 +#include <asm/compat.h>
12345 +
12346 +struct vcmd_ctx_dlimit_base_v0_x32 {
12347 +       compat_uptr_t name_ptr;
12348 +       uint32_t flags;
12349 +};
12350 +
12351 +struct vcmd_ctx_dlimit_v0_x32 {
12352 +       compat_uptr_t name_ptr;
12353 +       uint32_t space_used;                    /* used space in kbytes */
12354 +       uint32_t space_total;                   /* maximum space in kbytes */
12355 +       uint32_t inodes_used;                   /* used inodes */
12356 +       uint32_t inodes_total;                  /* maximum inodes */
12357 +       uint32_t reserved;                      /* reserved for root in % */
12358 +       uint32_t flags;
12359 +};
12360 +
12361 +#endif /* CONFIG_COMPAT */
12362 +
12363 +#include <linux/compiler.h>
12364 +
12365 +extern int vc_add_dlimit(uint32_t, void __user *);
12366 +extern int vc_rem_dlimit(uint32_t, void __user *);
12367 +
12368 +extern int vc_set_dlimit(uint32_t, void __user *);
12369 +extern int vc_get_dlimit(uint32_t, void __user *);
12370 +
12371 +#ifdef CONFIG_COMPAT
12372 +
12373 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
12374 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
12375 +
12376 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
12377 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
12378 +
12379 +#endif /* CONFIG_COMPAT */
12380 +
12381 +#endif /* __KERNEL__ */
12382 +#endif /* _VX_DLIMIT_CMD_H */
12383 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/global.h linux-3.1.1-vs2.3.2/include/linux/vserver/global.h
12384 --- linux-3.1.1/include/linux/vserver/global.h  1970-01-01 01:00:00.000000000 +0100
12385 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/global.h  2011-10-24 18:53:33.000000000 +0200
12386 @@ -0,0 +1,19 @@
12387 +#ifndef _VX_GLOBAL_H
12388 +#define _VX_GLOBAL_H
12389 +
12390 +
12391 +extern atomic_t vx_global_ctotal;
12392 +extern atomic_t vx_global_cactive;
12393 +
12394 +extern atomic_t nx_global_ctotal;
12395 +extern atomic_t nx_global_cactive;
12396 +
12397 +extern atomic_t vs_global_nsproxy;
12398 +extern atomic_t vs_global_fs;
12399 +extern atomic_t vs_global_mnt_ns;
12400 +extern atomic_t vs_global_uts_ns;
12401 +extern atomic_t vs_global_user_ns;
12402 +extern atomic_t vs_global_pid_ns;
12403 +
12404 +
12405 +#endif /* _VX_GLOBAL_H */
12406 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/history.h linux-3.1.1-vs2.3.2/include/linux/vserver/history.h
12407 --- linux-3.1.1/include/linux/vserver/history.h 1970-01-01 01:00:00.000000000 +0100
12408 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/history.h 2011-10-24 18:53:33.000000000 +0200
12409 @@ -0,0 +1,197 @@
12410 +#ifndef _VX_HISTORY_H
12411 +#define _VX_HISTORY_H
12412 +
12413 +
12414 +enum {
12415 +       VXH_UNUSED = 0,
12416 +       VXH_THROW_OOPS = 1,
12417 +
12418 +       VXH_GET_VX_INFO,
12419 +       VXH_PUT_VX_INFO,
12420 +       VXH_INIT_VX_INFO,
12421 +       VXH_SET_VX_INFO,
12422 +       VXH_CLR_VX_INFO,
12423 +       VXH_CLAIM_VX_INFO,
12424 +       VXH_RELEASE_VX_INFO,
12425 +       VXH_ALLOC_VX_INFO,
12426 +       VXH_DEALLOC_VX_INFO,
12427 +       VXH_HASH_VX_INFO,
12428 +       VXH_UNHASH_VX_INFO,
12429 +       VXH_LOC_VX_INFO,
12430 +       VXH_LOOKUP_VX_INFO,
12431 +       VXH_CREATE_VX_INFO,
12432 +};
12433 +
12434 +struct _vxhe_vxi {
12435 +       struct vx_info *ptr;
12436 +       unsigned xid;
12437 +       unsigned usecnt;
12438 +       unsigned tasks;
12439 +};
12440 +
12441 +struct _vxhe_set_clr {
12442 +       void *data;
12443 +};
12444 +
12445 +struct _vxhe_loc_lookup {
12446 +       unsigned arg;
12447 +};
12448 +
12449 +struct _vx_hist_entry {
12450 +       void *loc;
12451 +       unsigned short seq;
12452 +       unsigned short type;
12453 +       struct _vxhe_vxi vxi;
12454 +       union {
12455 +               struct _vxhe_set_clr sc;
12456 +               struct _vxhe_loc_lookup ll;
12457 +       };
12458 +};
12459 +
12460 +#ifdef CONFIG_VSERVER_HISTORY
12461 +
12462 +extern unsigned volatile int vxh_active;
12463 +
12464 +struct _vx_hist_entry *vxh_advance(void *loc);
12465 +
12466 +
12467 +static inline
12468 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
12469 +{
12470 +       entry->vxi.ptr = vxi;
12471 +       if (vxi) {
12472 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
12473 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
12474 +               entry->vxi.xid = vxi->vx_id;
12475 +       }
12476 +}
12477 +
12478 +
12479 +#define        __HERE__ current_text_addr()
12480 +
12481 +#define __VXH_BODY(__type, __data, __here)     \
12482 +       struct _vx_hist_entry *entry;           \
12483 +                                               \
12484 +       preempt_disable();                      \
12485 +       entry = vxh_advance(__here);            \
12486 +       __data;                                 \
12487 +       entry->type = __type;                   \
12488 +       preempt_enable();
12489 +
12490 +
12491 +       /* pass vxi only */
12492 +
12493 +#define __VXH_SMPL                             \
12494 +       __vxh_copy_vxi(entry, vxi)
12495 +
12496 +static inline
12497 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
12498 +{
12499 +       __VXH_BODY(__type, __VXH_SMPL, __here)
12500 +}
12501 +
12502 +       /* pass vxi and data (void *) */
12503 +
12504 +#define __VXH_DATA                             \
12505 +       __vxh_copy_vxi(entry, vxi);             \
12506 +       entry->sc.data = data
12507 +
12508 +static inline
12509 +void   __vxh_data(struct vx_info *vxi, void *data,
12510 +                       int __type, void *__here)
12511 +{
12512 +       __VXH_BODY(__type, __VXH_DATA, __here)
12513 +}
12514 +
12515 +       /* pass vxi and arg (long) */
12516 +
12517 +#define __VXH_LONG                             \
12518 +       __vxh_copy_vxi(entry, vxi);             \
12519 +       entry->ll.arg = arg
12520 +
12521 +static inline
12522 +void   __vxh_long(struct vx_info *vxi, long arg,
12523 +                       int __type, void *__here)
12524 +{
12525 +       __VXH_BODY(__type, __VXH_LONG, __here)
12526 +}
12527 +
12528 +
12529 +static inline
12530 +void   __vxh_throw_oops(void *__here)
12531 +{
12532 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
12533 +       /* prevent further acquisition */
12534 +       vxh_active = 0;
12535 +}
12536 +
12537 +
12538 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
12539 +
12540 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
12541 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
12542 +
12543 +#define __vxh_init_vx_info(v, d, h) \
12544 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
12545 +#define __vxh_set_vx_info(v, d, h) \
12546 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
12547 +#define __vxh_clr_vx_info(v, d, h) \
12548 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
12549 +
12550 +#define __vxh_claim_vx_info(v, d, h) \
12551 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
12552 +#define __vxh_release_vx_info(v, d, h) \
12553 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
12554 +
12555 +#define vxh_alloc_vx_info(v) \
12556 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
12557 +#define vxh_dealloc_vx_info(v) \
12558 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
12559 +
12560 +#define vxh_hash_vx_info(v) \
12561 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
12562 +#define vxh_unhash_vx_info(v) \
12563 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
12564 +
12565 +#define vxh_loc_vx_info(v, l) \
12566 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
12567 +#define vxh_lookup_vx_info(v, l) \
12568 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
12569 +#define vxh_create_vx_info(v, l) \
12570 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
12571 +
12572 +extern void vxh_dump_history(void);
12573 +
12574 +
12575 +#else  /* CONFIG_VSERVER_HISTORY */
12576 +
12577 +#define        __HERE__        0
12578 +
12579 +#define vxh_throw_oops()               do { } while (0)
12580 +
12581 +#define __vxh_get_vx_info(v, h)                do { } while (0)
12582 +#define __vxh_put_vx_info(v, h)                do { } while (0)
12583 +
12584 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
12585 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
12586 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
12587 +
12588 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
12589 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
12590 +
12591 +#define vxh_alloc_vx_info(v)           do { } while (0)
12592 +#define vxh_dealloc_vx_info(v)         do { } while (0)
12593 +
12594 +#define vxh_hash_vx_info(v)            do { } while (0)
12595 +#define vxh_unhash_vx_info(v)          do { } while (0)
12596 +
12597 +#define vxh_loc_vx_info(v, l)          do { } while (0)
12598 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
12599 +#define vxh_create_vx_info(v, l)       do { } while (0)
12600 +
12601 +#define vxh_dump_history()             do { } while (0)
12602 +
12603 +
12604 +#endif /* CONFIG_VSERVER_HISTORY */
12605 +
12606 +#endif /* _VX_HISTORY_H */
12607 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/inode.h linux-3.1.1-vs2.3.2/include/linux/vserver/inode.h
12608 --- linux-3.1.1/include/linux/vserver/inode.h   1970-01-01 01:00:00.000000000 +0100
12609 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/inode.h   2011-10-24 18:53:33.000000000 +0200
12610 @@ -0,0 +1,39 @@
12611 +#ifndef _VX_INODE_H
12612 +#define _VX_INODE_H
12613 +
12614 +
12615 +#define IATTR_TAG      0x01000000
12616 +
12617 +#define IATTR_ADMIN    0x00000001
12618 +#define IATTR_WATCH    0x00000002
12619 +#define IATTR_HIDE     0x00000004
12620 +#define IATTR_FLAGS    0x00000007
12621 +
12622 +#define IATTR_BARRIER  0x00010000
12623 +#define IATTR_IXUNLINK 0x00020000
12624 +#define IATTR_IMMUTABLE 0x00040000
12625 +#define IATTR_COW      0x00080000
12626 +
12627 +#ifdef __KERNEL__
12628 +
12629 +
12630 +#ifdef CONFIG_VSERVER_PROC_SECURE
12631 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
12632 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
12633 +#else
12634 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
12635 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
12636 +#endif
12637 +
12638 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
12639 +
12640 +#endif /* __KERNEL__ */
12641 +
12642 +/* inode ioctls */
12643 +
12644 +#define FIOC_GETXFLG   _IOR('x', 5, long)
12645 +#define FIOC_SETXFLG   _IOW('x', 6, long)
12646 +
12647 +#else  /* _VX_INODE_H */
12648 +#warning duplicate inclusion
12649 +#endif /* _VX_INODE_H */
12650 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/inode_cmd.h linux-3.1.1-vs2.3.2/include/linux/vserver/inode_cmd.h
12651 --- linux-3.1.1/include/linux/vserver/inode_cmd.h       1970-01-01 01:00:00.000000000 +0100
12652 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/inode_cmd.h       2011-10-24 18:53:33.000000000 +0200
12653 @@ -0,0 +1,59 @@
12654 +#ifndef _VX_INODE_CMD_H
12655 +#define _VX_INODE_CMD_H
12656 +
12657 +
12658 +/*  inode vserver commands */
12659 +
12660 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
12661 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
12662 +
12663 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
12664 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
12665 +
12666 +struct vcmd_ctx_iattr_v1 {
12667 +       const char __user *name;
12668 +       uint32_t tag;
12669 +       uint32_t flags;
12670 +       uint32_t mask;
12671 +};
12672 +
12673 +struct vcmd_ctx_fiattr_v0 {
12674 +       uint32_t tag;
12675 +       uint32_t flags;
12676 +       uint32_t mask;
12677 +};
12678 +
12679 +
12680 +#ifdef __KERNEL__
12681 +
12682 +
12683 +#ifdef CONFIG_COMPAT
12684 +
12685 +#include <asm/compat.h>
12686 +
12687 +struct vcmd_ctx_iattr_v1_x32 {
12688 +       compat_uptr_t name_ptr;
12689 +       uint32_t tag;
12690 +       uint32_t flags;
12691 +       uint32_t mask;
12692 +};
12693 +
12694 +#endif /* CONFIG_COMPAT */
12695 +
12696 +#include <linux/compiler.h>
12697 +
12698 +extern int vc_get_iattr(void __user *);
12699 +extern int vc_set_iattr(void __user *);
12700 +
12701 +extern int vc_fget_iattr(uint32_t, void __user *);
12702 +extern int vc_fset_iattr(uint32_t, void __user *);
12703 +
12704 +#ifdef CONFIG_COMPAT
12705 +
12706 +extern int vc_get_iattr_x32(void __user *);
12707 +extern int vc_set_iattr_x32(void __user *);
12708 +
12709 +#endif /* CONFIG_COMPAT */
12710 +
12711 +#endif /* __KERNEL__ */
12712 +#endif /* _VX_INODE_CMD_H */
12713 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/limit.h linux-3.1.1-vs2.3.2/include/linux/vserver/limit.h
12714 --- linux-3.1.1/include/linux/vserver/limit.h   1970-01-01 01:00:00.000000000 +0100
12715 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/limit.h   2011-10-24 18:53:33.000000000 +0200
12716 @@ -0,0 +1,71 @@
12717 +#ifndef _VX_LIMIT_H
12718 +#define _VX_LIMIT_H
12719 +
12720 +#define VLIMIT_NSOCK   16
12721 +#define VLIMIT_OPENFD  17
12722 +#define VLIMIT_ANON    18
12723 +#define VLIMIT_SHMEM   19
12724 +#define VLIMIT_SEMARY  20
12725 +#define VLIMIT_NSEMS   21
12726 +#define VLIMIT_DENTRY  22
12727 +#define VLIMIT_MAPPED  23
12728 +
12729 +
12730 +#ifdef __KERNEL__
12731 +
12732 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
12733 +
12734 +/*     keep in sync with CRLIM_INFINITY */
12735 +
12736 +#define        VLIM_INFINITY   (~0ULL)
12737 +
12738 +#include <asm/atomic.h>
12739 +#include <asm/resource.h>
12740 +
12741 +#ifndef RLIM_INFINITY
12742 +#warning RLIM_INFINITY is undefined
12743 +#endif
12744 +
12745 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
12746 +
12747 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
12748 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
12749 +
12750 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
12751 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
12752 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
12753 +
12754 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
12755 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
12756 +
12757 +typedef atomic_long_t rlim_atomic_t;
12758 +typedef unsigned long rlim_t;
12759 +
12760 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
12761 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
12762 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
12763 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
12764 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
12765 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
12766 +
12767 +
12768 +#if    (RLIM_INFINITY == VLIM_INFINITY)
12769 +#define        VX_VLIM(r) ((long long)(long)(r))
12770 +#define        VX_RLIM(v) ((rlim_t)(v))
12771 +#else
12772 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
12773 +               ? VLIM_INFINITY : (long long)(r))
12774 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
12775 +               ? RLIM_INFINITY : (rlim_t)(v))
12776 +#endif
12777 +
12778 +struct sysinfo;
12779 +
12780 +void vx_vsi_meminfo(struct sysinfo *);
12781 +void vx_vsi_swapinfo(struct sysinfo *);
12782 +long vx_vsi_cached(struct sysinfo *);
12783 +
12784 +#define NUM_LIMITS     24
12785 +
12786 +#endif /* __KERNEL__ */
12787 +#endif /* _VX_LIMIT_H */
12788 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/limit_cmd.h linux-3.1.1-vs2.3.2/include/linux/vserver/limit_cmd.h
12789 --- linux-3.1.1/include/linux/vserver/limit_cmd.h       1970-01-01 01:00:00.000000000 +0100
12790 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/limit_cmd.h       2011-10-24 18:53:33.000000000 +0200
12791 @@ -0,0 +1,71 @@
12792 +#ifndef _VX_LIMIT_CMD_H
12793 +#define _VX_LIMIT_CMD_H
12794 +
12795 +
12796 +/*  rlimit vserver commands */
12797 +
12798 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
12799 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
12800 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
12801 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
12802 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
12803 +
12804 +struct vcmd_ctx_rlimit_v0 {
12805 +       uint32_t id;
12806 +       uint64_t minimum;
12807 +       uint64_t softlimit;
12808 +       uint64_t maximum;
12809 +};
12810 +
12811 +struct vcmd_ctx_rlimit_mask_v0 {
12812 +       uint32_t minimum;
12813 +       uint32_t softlimit;
12814 +       uint32_t maximum;
12815 +};
12816 +
12817 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
12818 +
12819 +struct vcmd_rlimit_stat_v0 {
12820 +       uint32_t id;
12821 +       uint32_t hits;
12822 +       uint64_t value;
12823 +       uint64_t minimum;
12824 +       uint64_t maximum;
12825 +};
12826 +
12827 +#define CRLIM_UNSET            (0ULL)
12828 +#define CRLIM_INFINITY         (~0ULL)
12829 +#define CRLIM_KEEP             (~1ULL)
12830 +
12831 +#ifdef __KERNEL__
12832 +
12833 +#ifdef CONFIG_IA32_EMULATION
12834 +
12835 +struct vcmd_ctx_rlimit_v0_x32 {
12836 +       uint32_t id;
12837 +       uint64_t minimum;
12838 +       uint64_t softlimit;
12839 +       uint64_t maximum;
12840 +} __attribute__ ((packed));
12841 +
12842 +#endif /* CONFIG_IA32_EMULATION */
12843 +
12844 +#include <linux/compiler.h>
12845 +
12846 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
12847 +extern int vc_get_rlimit(struct vx_info *, void __user *);
12848 +extern int vc_set_rlimit(struct vx_info *, void __user *);
12849 +extern int vc_reset_hits(struct vx_info *, void __user *);
12850 +extern int vc_reset_minmax(struct vx_info *, void __user *);
12851 +
12852 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
12853 +
12854 +#ifdef CONFIG_IA32_EMULATION
12855 +
12856 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
12857 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
12858 +
12859 +#endif /* CONFIG_IA32_EMULATION */
12860 +
12861 +#endif /* __KERNEL__ */
12862 +#endif /* _VX_LIMIT_CMD_H */
12863 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/limit_def.h linux-3.1.1-vs2.3.2/include/linux/vserver/limit_def.h
12864 --- linux-3.1.1/include/linux/vserver/limit_def.h       1970-01-01 01:00:00.000000000 +0100
12865 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/limit_def.h       2011-10-24 18:53:33.000000000 +0200
12866 @@ -0,0 +1,47 @@
12867 +#ifndef _VX_LIMIT_DEF_H
12868 +#define _VX_LIMIT_DEF_H
12869 +
12870 +#include <asm/atomic.h>
12871 +#include <asm/resource.h>
12872 +
12873 +#include "limit.h"
12874 +
12875 +
12876 +struct _vx_res_limit {
12877 +       rlim_t soft;            /* Context soft limit */
12878 +       rlim_t hard;            /* Context hard limit */
12879 +
12880 +       rlim_atomic_t rcur;     /* Current value */
12881 +       rlim_t rmin;            /* Context minimum */
12882 +       rlim_t rmax;            /* Context maximum */
12883 +
12884 +       atomic_t lhit;          /* Limit hits */
12885 +};
12886 +
12887 +/* context sub struct */
12888 +
12889 +struct _vx_limit {
12890 +       struct _vx_res_limit res[NUM_LIMITS];
12891 +};
12892 +
12893 +#ifdef CONFIG_VSERVER_DEBUG
12894 +
12895 +static inline void __dump_vx_limit(struct _vx_limit *limit)
12896 +{
12897 +       int i;
12898 +
12899 +       printk("\t_vx_limit:");
12900 +       for (i = 0; i < NUM_LIMITS; i++) {
12901 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
12902 +                       i, (unsigned long)__rlim_get(limit, i),
12903 +                       (unsigned long)__rlim_rmin(limit, i),
12904 +                       (unsigned long)__rlim_rmax(limit, i),
12905 +                       (long)__rlim_soft(limit, i),
12906 +                       (long)__rlim_hard(limit, i),
12907 +                       atomic_read(&__rlim_lhit(limit, i)));
12908 +       }
12909 +}
12910 +
12911 +#endif
12912 +
12913 +#endif /* _VX_LIMIT_DEF_H */
12914 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/limit_int.h linux-3.1.1-vs2.3.2/include/linux/vserver/limit_int.h
12915 --- linux-3.1.1/include/linux/vserver/limit_int.h       1970-01-01 01:00:00.000000000 +0100
12916 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/limit_int.h       2011-10-24 18:53:33.000000000 +0200
12917 @@ -0,0 +1,198 @@
12918 +#ifndef _VX_LIMIT_INT_H
12919 +#define _VX_LIMIT_INT_H
12920 +
12921 +#include "context.h"
12922 +
12923 +#ifdef __KERNEL__
12924 +
12925 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
12926 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
12927 +
12928 +extern const char *vlimit_name[NUM_LIMITS];
12929 +
12930 +static inline void __vx_acc_cres(struct vx_info *vxi,
12931 +       int res, int dir, void *_data, char *_file, int _line)
12932 +{
12933 +       if (VXD_RCRES_COND(res))
12934 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
12935 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12936 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12937 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
12938 +       if (!vxi)
12939 +               return;
12940 +
12941 +       if (dir > 0)
12942 +               __rlim_inc(&vxi->limit, res);
12943 +       else
12944 +               __rlim_dec(&vxi->limit, res);
12945 +}
12946 +
12947 +static inline void __vx_add_cres(struct vx_info *vxi,
12948 +       int res, int amount, void *_data, char *_file, int _line)
12949 +{
12950 +       if (VXD_RCRES_COND(res))
12951 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
12952 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12953 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12954 +                       amount, _data, _file, _line);
12955 +       if (amount == 0)
12956 +               return;
12957 +       if (!vxi)
12958 +               return;
12959 +       __rlim_add(&vxi->limit, res, amount);
12960 +}
12961 +
12962 +static inline
12963 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
12964 +{
12965 +       int cond = (value > __rlim_rmax(limit, res));
12966 +
12967 +       if (cond)
12968 +               __rlim_rmax(limit, res) = value;
12969 +       return cond;
12970 +}
12971 +
12972 +static inline
12973 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
12974 +{
12975 +       int cond = (value < __rlim_rmin(limit, res));
12976 +
12977 +       if (cond)
12978 +               __rlim_rmin(limit, res) = value;
12979 +       return cond;
12980 +}
12981 +
12982 +static inline
12983 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
12984 +{
12985 +       if (!__vx_cres_adjust_max(limit, res, value))
12986 +               __vx_cres_adjust_min(limit, res, value);
12987 +}
12988 +
12989 +
12990 +/*     return values:
12991 +        +1 ... no limit hit
12992 +        -1 ... over soft limit
12993 +         0 ... over hard limit         */
12994 +
12995 +static inline int __vx_cres_avail(struct vx_info *vxi,
12996 +       int res, int num, char *_file, int _line)
12997 +{
12998 +       struct _vx_limit *limit;
12999 +       rlim_t value;
13000 +
13001 +       if (VXD_RLIMIT_COND(res))
13002 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
13003 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
13004 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
13005 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
13006 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
13007 +                       num, _file, _line);
13008 +       if (!vxi)
13009 +               return 1;
13010 +
13011 +       limit = &vxi->limit;
13012 +       value = __rlim_get(limit, res);
13013 +
13014 +       if (!__vx_cres_adjust_max(limit, res, value))
13015 +               __vx_cres_adjust_min(limit, res, value);
13016 +
13017 +       if (num == 0)
13018 +               return 1;
13019 +
13020 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
13021 +               return -1;
13022 +       if (value + num <= __rlim_soft(limit, res))
13023 +               return -1;
13024 +
13025 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
13026 +               return 1;
13027 +       if (value + num <= __rlim_hard(limit, res))
13028 +               return 1;
13029 +
13030 +       __rlim_hit(limit, res);
13031 +       return 0;
13032 +}
13033 +
13034 +
13035 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
13036 +
13037 +static inline
13038 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
13039 +{
13040 +       rlim_t value, sum = 0;
13041 +       int res;
13042 +
13043 +       while ((res = *array++)) {
13044 +               value = __rlim_get(limit, res);
13045 +               __vx_cres_fixup(limit, res, value);
13046 +               sum += value;
13047 +       }
13048 +       return sum;
13049 +}
13050 +
13051 +static inline
13052 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
13053 +{
13054 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
13055 +       int res = *array;
13056 +
13057 +       if (value == __rlim_get(limit, res))
13058 +               return value;
13059 +
13060 +       __rlim_set(limit, res, value);
13061 +       /* now adjust min/max */
13062 +       if (!__vx_cres_adjust_max(limit, res, value))
13063 +               __vx_cres_adjust_min(limit, res, value);
13064 +
13065 +       return value;
13066 +}
13067 +
13068 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
13069 +       const int *array, int num, char *_file, int _line)
13070 +{
13071 +       struct _vx_limit *limit;
13072 +       rlim_t value = 0;
13073 +       int res;
13074 +
13075 +       if (num == 0)
13076 +               return 1;
13077 +       if (!vxi)
13078 +               return 1;
13079 +
13080 +       limit = &vxi->limit;
13081 +       res = *array;
13082 +       value = __vx_cres_array_sum(limit, array + 1);
13083 +
13084 +       __rlim_set(limit, res, value);
13085 +       __vx_cres_fixup(limit, res, value);
13086 +
13087 +       return __vx_cres_avail(vxi, res, num, _file, _line);
13088 +}
13089 +
13090 +
13091 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
13092 +{
13093 +       rlim_t value;
13094 +       int res;
13095 +
13096 +       /* complex resources first */
13097 +       if ((id < 0) || (id == RLIMIT_RSS))
13098 +               __vx_cres_array_fixup(limit, VLA_RSS);
13099 +
13100 +       for (res = 0; res < NUM_LIMITS; res++) {
13101 +               if ((id > 0) && (res != id))
13102 +                       continue;
13103 +
13104 +               value = __rlim_get(limit, res);
13105 +               __vx_cres_fixup(limit, res, value);
13106 +
13107 +               /* not supposed to happen, maybe warn? */
13108 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
13109 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
13110 +       }
13111 +}
13112 +
13113 +
13114 +#endif /* __KERNEL__ */
13115 +#endif /* _VX_LIMIT_INT_H */
13116 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/monitor.h linux-3.1.1-vs2.3.2/include/linux/vserver/monitor.h
13117 --- linux-3.1.1/include/linux/vserver/monitor.h 1970-01-01 01:00:00.000000000 +0100
13118 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/monitor.h 2011-10-24 18:53:33.000000000 +0200
13119 @@ -0,0 +1,96 @@
13120 +#ifndef _VX_MONITOR_H
13121 +#define _VX_MONITOR_H
13122 +
13123 +#include <linux/types.h>
13124 +
13125 +enum {
13126 +       VXM_UNUSED = 0,
13127 +
13128 +       VXM_SYNC = 0x10,
13129 +
13130 +       VXM_UPDATE = 0x20,
13131 +       VXM_UPDATE_1,
13132 +       VXM_UPDATE_2,
13133 +
13134 +       VXM_RQINFO_1 = 0x24,
13135 +       VXM_RQINFO_2,
13136 +
13137 +       VXM_ACTIVATE = 0x40,
13138 +       VXM_DEACTIVATE,
13139 +       VXM_IDLE,
13140 +
13141 +       VXM_HOLD = 0x44,
13142 +       VXM_UNHOLD,
13143 +
13144 +       VXM_MIGRATE = 0x48,
13145 +       VXM_RESCHED,
13146 +
13147 +       /* all other bits are flags */
13148 +       VXM_SCHED = 0x80,
13149 +};
13150 +
13151 +struct _vxm_update_1 {
13152 +       uint32_t tokens_max;
13153 +       uint32_t fill_rate;
13154 +       uint32_t interval;
13155 +};
13156 +
13157 +struct _vxm_update_2 {
13158 +       uint32_t tokens_min;
13159 +       uint32_t fill_rate;
13160 +       uint32_t interval;
13161 +};
13162 +
13163 +struct _vxm_rqinfo_1 {
13164 +       uint16_t running;
13165 +       uint16_t onhold;
13166 +       uint16_t iowait;
13167 +       uint16_t uintr;
13168 +       uint32_t idle_tokens;
13169 +};
13170 +
13171 +struct _vxm_rqinfo_2 {
13172 +       uint32_t norm_time;
13173 +       uint32_t idle_time;
13174 +       uint32_t idle_skip;
13175 +};
13176 +
13177 +struct _vxm_sched {
13178 +       uint32_t tokens;
13179 +       uint32_t norm_time;
13180 +       uint32_t idle_time;
13181 +};
13182 +
13183 +struct _vxm_task {
13184 +       uint16_t pid;
13185 +       uint16_t state;
13186 +};
13187 +
13188 +struct _vxm_event {
13189 +       uint32_t jif;
13190 +       union {
13191 +               uint32_t seq;
13192 +               uint32_t sec;
13193 +       };
13194 +       union {
13195 +               uint32_t tokens;
13196 +               uint32_t nsec;
13197 +               struct _vxm_task tsk;
13198 +       };
13199 +};
13200 +
13201 +struct _vx_mon_entry {
13202 +       uint16_t type;
13203 +       uint16_t xid;
13204 +       union {
13205 +               struct _vxm_event ev;
13206 +               struct _vxm_sched sd;
13207 +               struct _vxm_update_1 u1;
13208 +               struct _vxm_update_2 u2;
13209 +               struct _vxm_rqinfo_1 q1;
13210 +               struct _vxm_rqinfo_2 q2;
13211 +       };
13212 +};
13213 +
13214 +
13215 +#endif /* _VX_MONITOR_H */
13216 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/network.h linux-3.1.1-vs2.3.2/include/linux/vserver/network.h
13217 --- linux-3.1.1/include/linux/vserver/network.h 1970-01-01 01:00:00.000000000 +0100
13218 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/network.h 2011-10-24 18:53:33.000000000 +0200
13219 @@ -0,0 +1,148 @@
13220 +#ifndef _VX_NETWORK_H
13221 +#define _VX_NETWORK_H
13222 +
13223 +#include <linux/types.h>
13224 +
13225 +
13226 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
13227 +
13228 +
13229 +/* network flags */
13230 +
13231 +#define NXF_INFO_PRIVATE       0x00000008
13232 +
13233 +#define NXF_SINGLE_IP          0x00000100
13234 +#define NXF_LBACK_REMAP                0x00000200
13235 +#define NXF_LBACK_ALLOW                0x00000400
13236 +
13237 +#define NXF_HIDE_NETIF         0x02000000
13238 +#define NXF_HIDE_LBACK         0x04000000
13239 +
13240 +#define NXF_STATE_SETUP                (1ULL << 32)
13241 +#define NXF_STATE_ADMIN                (1ULL << 34)
13242 +
13243 +#define NXF_SC_HELPER          (1ULL << 36)
13244 +#define NXF_PERSISTENT         (1ULL << 38)
13245 +
13246 +#define NXF_ONE_TIME           (0x0005ULL << 32)
13247 +
13248 +
13249 +#define        NXF_INIT_SET            (__nxf_init_set())
13250 +
13251 +static inline uint64_t __nxf_init_set(void) {
13252 +       return    NXF_STATE_ADMIN
13253 +#ifdef CONFIG_VSERVER_AUTO_LBACK
13254 +               | NXF_LBACK_REMAP
13255 +               | NXF_HIDE_LBACK
13256 +#endif
13257 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
13258 +               | NXF_SINGLE_IP
13259 +#endif
13260 +               | NXF_HIDE_NETIF;
13261 +}
13262 +
13263 +
13264 +/* network caps */
13265 +
13266 +#define NXC_TUN_CREATE         0x00000001
13267 +
13268 +#define NXC_RAW_ICMP           0x00000100
13269 +
13270 +#define NXC_MULTICAST          0x00001000
13271 +
13272 +
13273 +/* address types */
13274 +
13275 +#define NXA_TYPE_IPV4          0x0001
13276 +#define NXA_TYPE_IPV6          0x0002
13277 +
13278 +#define NXA_TYPE_NONE          0x0000
13279 +#define NXA_TYPE_ANY           0x00FF
13280 +
13281 +#define NXA_TYPE_ADDR          0x0010
13282 +#define NXA_TYPE_MASK          0x0020
13283 +#define NXA_TYPE_RANGE         0x0040
13284 +
13285 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
13286 +
13287 +#define NXA_MOD_BCAST          0x0100
13288 +#define NXA_MOD_LBACK          0x0200
13289 +
13290 +#define NXA_LOOPBACK           0x1000
13291 +
13292 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
13293 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
13294 +
13295 +#ifdef __KERNEL__
13296 +
13297 +#include <linux/list.h>
13298 +#include <linux/spinlock.h>
13299 +#include <linux/rcupdate.h>
13300 +#include <linux/in.h>
13301 +#include <linux/in6.h>
13302 +#include <asm/atomic.h>
13303 +
13304 +struct nx_addr_v4 {
13305 +       struct nx_addr_v4 *next;
13306 +       struct in_addr ip[2];
13307 +       struct in_addr mask;
13308 +       uint16_t type;
13309 +       uint16_t flags;
13310 +};
13311 +
13312 +struct nx_addr_v6 {
13313 +       struct nx_addr_v6 *next;
13314 +       struct in6_addr ip;
13315 +       struct in6_addr mask;
13316 +       uint32_t prefix;
13317 +       uint16_t type;
13318 +       uint16_t flags;
13319 +};
13320 +
13321 +struct nx_info {
13322 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
13323 +       nid_t nx_id;                    /* vnet id */
13324 +       atomic_t nx_usecnt;             /* usage count */
13325 +       atomic_t nx_tasks;              /* tasks count */
13326 +       int nx_state;                   /* context state */
13327 +
13328 +       uint64_t nx_flags;              /* network flag word */
13329 +       uint64_t nx_ncaps;              /* network capabilities */
13330 +
13331 +       struct in_addr v4_lback;        /* Loopback address */
13332 +       struct in_addr v4_bcast;        /* Broadcast address */
13333 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
13334 +#ifdef CONFIG_IPV6
13335 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
13336 +#endif
13337 +       char nx_name[65];               /* network context name */
13338 +};
13339 +
13340 +
13341 +/* status flags */
13342 +
13343 +#define NXS_HASHED      0x0001
13344 +#define NXS_SHUTDOWN    0x0100
13345 +#define NXS_RELEASED    0x8000
13346 +
13347 +extern struct nx_info *lookup_nx_info(int);
13348 +
13349 +extern int get_nid_list(int, unsigned int *, int);
13350 +extern int nid_is_hashed(nid_t);
13351 +
13352 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
13353 +
13354 +extern long vs_net_change(struct nx_info *, unsigned int);
13355 +
13356 +struct sock;
13357 +
13358 +
13359 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
13360 +#ifdef  CONFIG_IPV6
13361 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
13362 +#else
13363 +#define NX_IPV6(n)     (0)
13364 +#endif
13365 +
13366 +#endif /* __KERNEL__ */
13367 +#endif /* _VX_NETWORK_H */
13368 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/network_cmd.h linux-3.1.1-vs2.3.2/include/linux/vserver/network_cmd.h
13369 --- linux-3.1.1/include/linux/vserver/network_cmd.h     1970-01-01 01:00:00.000000000 +0100
13370 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/network_cmd.h     2011-10-24 18:53:33.000000000 +0200
13371 @@ -0,0 +1,164 @@
13372 +#ifndef _VX_NETWORK_CMD_H
13373 +#define _VX_NETWORK_CMD_H
13374 +
13375 +
13376 +/* vinfo commands */
13377 +
13378 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
13379 +
13380 +#ifdef __KERNEL__
13381 +extern int vc_task_nid(uint32_t);
13382 +
13383 +#endif /* __KERNEL__ */
13384 +
13385 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
13386 +
13387 +struct vcmd_nx_info_v0 {
13388 +       uint32_t nid;
13389 +       /* more to come */
13390 +};
13391 +
13392 +#ifdef __KERNEL__
13393 +extern int vc_nx_info(struct nx_info *, void __user *);
13394 +
13395 +#endif /* __KERNEL__ */
13396 +
13397 +#include <linux/in.h>
13398 +#include <linux/in6.h>
13399 +
13400 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
13401 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
13402 +
13403 +struct  vcmd_net_create {
13404 +       uint64_t flagword;
13405 +};
13406 +
13407 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
13408 +
13409 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
13410 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
13411 +
13412 +struct vcmd_net_addr_v0 {
13413 +       uint16_t type;
13414 +       uint16_t count;
13415 +       struct in_addr ip[4];
13416 +       struct in_addr mask[4];
13417 +};
13418 +
13419 +#define VCMD_net_add_ipv4_v1   VC_CMD(NETALT, 1, 1)
13420 +#define VCMD_net_rem_ipv4_v1   VC_CMD(NETALT, 2, 1)
13421 +
13422 +struct vcmd_net_addr_ipv4_v1 {
13423 +       uint16_t type;
13424 +       uint16_t flags;
13425 +       struct in_addr ip;
13426 +       struct in_addr mask;
13427 +};
13428 +
13429 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 2)
13430 +#define VCMD_net_rem_ipv4      VC_CMD(NETALT, 2, 2)
13431 +
13432 +struct vcmd_net_addr_ipv4_v2 {
13433 +       uint16_t type;
13434 +       uint16_t flags;
13435 +       struct in_addr ip;
13436 +       struct in_addr ip2;
13437 +       struct in_addr mask;
13438 +};
13439 +
13440 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
13441 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
13442 +
13443 +struct vcmd_net_addr_ipv6_v1 {
13444 +       uint16_t type;
13445 +       uint16_t flags;
13446 +       uint32_t prefix;
13447 +       struct in6_addr ip;
13448 +       struct in6_addr mask;
13449 +};
13450 +
13451 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
13452 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
13453 +
13454 +struct vcmd_match_ipv4_v0 {
13455 +       uint16_t type;
13456 +       uint16_t flags;
13457 +       uint16_t parent;
13458 +       uint16_t prefix;
13459 +       struct in_addr ip;
13460 +       struct in_addr ip2;
13461 +       struct in_addr mask;
13462 +};
13463 +
13464 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
13465 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
13466 +
13467 +struct vcmd_match_ipv6_v0 {
13468 +       uint16_t type;
13469 +       uint16_t flags;
13470 +       uint16_t parent;
13471 +       uint16_t prefix;
13472 +       struct in6_addr ip;
13473 +       struct in6_addr ip2;
13474 +       struct in6_addr mask;
13475 +};
13476 +
13477 +
13478 +#ifdef __KERNEL__
13479 +extern int vc_net_create(uint32_t, void __user *);
13480 +extern int vc_net_migrate(struct nx_info *, void __user *);
13481 +
13482 +extern int vc_net_add(struct nx_info *, void __user *);
13483 +extern int vc_net_remove(struct nx_info *, void __user *);
13484 +
13485 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
13486 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
13487 +
13488 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
13489 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
13490 +
13491 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
13492 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
13493 +
13494 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
13495 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
13496 +
13497 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
13498 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
13499 +
13500 +#endif /* __KERNEL__ */
13501 +
13502 +
13503 +/* flag commands */
13504 +
13505 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
13506 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
13507 +
13508 +struct vcmd_net_flags_v0 {
13509 +       uint64_t flagword;
13510 +       uint64_t mask;
13511 +};
13512 +
13513 +#ifdef __KERNEL__
13514 +extern int vc_get_nflags(struct nx_info *, void __user *);
13515 +extern int vc_set_nflags(struct nx_info *, void __user *);
13516 +
13517 +#endif /* __KERNEL__ */
13518 +
13519 +
13520 +/* network caps commands */
13521 +
13522 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
13523 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
13524 +
13525 +struct vcmd_net_caps_v0 {
13526 +       uint64_t ncaps;
13527 +       uint64_t cmask;
13528 +};
13529 +
13530 +#ifdef __KERNEL__
13531 +extern int vc_get_ncaps(struct nx_info *, void __user *);
13532 +extern int vc_set_ncaps(struct nx_info *, void __user *);
13533 +
13534 +#endif /* __KERNEL__ */
13535 +#endif /* _VX_CONTEXT_CMD_H */
13536 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/percpu.h linux-3.1.1-vs2.3.2/include/linux/vserver/percpu.h
13537 --- linux-3.1.1/include/linux/vserver/percpu.h  1970-01-01 01:00:00.000000000 +0100
13538 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/percpu.h  2011-10-24 18:53:33.000000000 +0200
13539 @@ -0,0 +1,14 @@
13540 +#ifndef _VX_PERCPU_H
13541 +#define _VX_PERCPU_H
13542 +
13543 +#include "cvirt_def.h"
13544 +#include "sched_def.h"
13545 +
13546 +struct _vx_percpu {
13547 +       struct _vx_cvirt_pc cvirt;
13548 +       struct _vx_sched_pc sched;
13549 +};
13550 +
13551 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
13552 +
13553 +#endif /* _VX_PERCPU_H */
13554 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/pid.h linux-3.1.1-vs2.3.2/include/linux/vserver/pid.h
13555 --- linux-3.1.1/include/linux/vserver/pid.h     1970-01-01 01:00:00.000000000 +0100
13556 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/pid.h     2011-10-24 18:53:33.000000000 +0200
13557 @@ -0,0 +1,51 @@
13558 +#ifndef _VSERVER_PID_H
13559 +#define _VSERVER_PID_H
13560 +
13561 +/* pid faking stuff */
13562 +
13563 +#define vx_info_map_pid(v, p) \
13564 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
13565 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
13566 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
13567 +#define vx_map_tgid(p) vx_map_pid(p)
13568 +
13569 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
13570 +       const char *func, const char *file, int line)
13571 +{
13572 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13573 +               vxfprintk(VXD_CBIT(cvirt, 2),
13574 +                       "vx_map_tgid: %p/%llx: %d -> %d",
13575 +                       vxi, (long long)vxi->vx_flags, pid,
13576 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
13577 +                       func, file, line);
13578 +               if (pid == 0)
13579 +                       return 0;
13580 +               if (pid == vxi->vx_initpid)
13581 +                       return 1;
13582 +       }
13583 +       return pid;
13584 +}
13585 +
13586 +#define vx_info_rmap_pid(v, p) \
13587 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
13588 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
13589 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
13590 +
13591 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
13592 +       const char *func, const char *file, int line)
13593 +{
13594 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13595 +               vxfprintk(VXD_CBIT(cvirt, 2),
13596 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
13597 +                       vxi, (long long)vxi->vx_flags, pid,
13598 +                       (pid == 1) ? vxi->vx_initpid : pid,
13599 +                       func, file, line);
13600 +               if ((pid == 1) && vxi->vx_initpid)
13601 +                       return vxi->vx_initpid;
13602 +               if (pid == vxi->vx_initpid)
13603 +                       return ~0U;
13604 +       }
13605 +       return pid;
13606 +}
13607 +
13608 +#endif
13609 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/sched.h linux-3.1.1-vs2.3.2/include/linux/vserver/sched.h
13610 --- linux-3.1.1/include/linux/vserver/sched.h   1970-01-01 01:00:00.000000000 +0100
13611 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/sched.h   2011-10-24 18:53:33.000000000 +0200
13612 @@ -0,0 +1,23 @@
13613 +#ifndef _VX_SCHED_H
13614 +#define _VX_SCHED_H
13615 +
13616 +
13617 +#ifdef __KERNEL__
13618 +
13619 +struct timespec;
13620 +
13621 +void vx_vsi_uptime(struct timespec *, struct timespec *);
13622 +
13623 +
13624 +struct vx_info;
13625 +
13626 +void vx_update_load(struct vx_info *);
13627 +
13628 +
13629 +void vx_update_sched_param(struct _vx_sched *sched,
13630 +       struct _vx_sched_pc *sched_pc);
13631 +
13632 +#endif /* __KERNEL__ */
13633 +#else  /* _VX_SCHED_H */
13634 +#warning duplicate inclusion
13635 +#endif /* _VX_SCHED_H */
13636 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/sched_cmd.h linux-3.1.1-vs2.3.2/include/linux/vserver/sched_cmd.h
13637 --- linux-3.1.1/include/linux/vserver/sched_cmd.h       1970-01-01 01:00:00.000000000 +0100
13638 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/sched_cmd.h       2011-10-24 18:53:33.000000000 +0200
13639 @@ -0,0 +1,21 @@
13640 +#ifndef _VX_SCHED_CMD_H
13641 +#define _VX_SCHED_CMD_H
13642 +
13643 +
13644 +struct vcmd_prio_bias {
13645 +       int32_t cpu_id;
13646 +       int32_t prio_bias;
13647 +};
13648 +
13649 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
13650 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
13651 +
13652 +#ifdef __KERNEL__
13653 +
13654 +#include <linux/compiler.h>
13655 +
13656 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
13657 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
13658 +
13659 +#endif /* __KERNEL__ */
13660 +#endif /* _VX_SCHED_CMD_H */
13661 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/sched_def.h linux-3.1.1-vs2.3.2/include/linux/vserver/sched_def.h
13662 --- linux-3.1.1/include/linux/vserver/sched_def.h       1970-01-01 01:00:00.000000000 +0100
13663 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/sched_def.h       2011-10-24 18:53:33.000000000 +0200
13664 @@ -0,0 +1,38 @@
13665 +#ifndef _VX_SCHED_DEF_H
13666 +#define _VX_SCHED_DEF_H
13667 +
13668 +#include <linux/spinlock.h>
13669 +#include <linux/jiffies.h>
13670 +#include <linux/cpumask.h>
13671 +#include <asm/atomic.h>
13672 +#include <asm/param.h>
13673 +
13674 +
13675 +/* context sub struct */
13676 +
13677 +struct _vx_sched {
13678 +       int prio_bias;                  /* bias offset for priority */
13679 +
13680 +       cpumask_t update;               /* CPUs which should update */
13681 +};
13682 +
13683 +struct _vx_sched_pc {
13684 +       int prio_bias;                  /* bias offset for priority */
13685 +
13686 +       uint64_t user_ticks;            /* token tick events */
13687 +       uint64_t sys_ticks;             /* token tick events */
13688 +       uint64_t hold_ticks;            /* token ticks paused */
13689 +};
13690 +
13691 +
13692 +#ifdef CONFIG_VSERVER_DEBUG
13693 +
13694 +static inline void __dump_vx_sched(struct _vx_sched *sched)
13695 +{
13696 +       printk("\t_vx_sched:\n");
13697 +       printk("\t priority = %4d\n", sched->prio_bias);
13698 +}
13699 +
13700 +#endif
13701 +
13702 +#endif /* _VX_SCHED_DEF_H */
13703 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/signal.h linux-3.1.1-vs2.3.2/include/linux/vserver/signal.h
13704 --- linux-3.1.1/include/linux/vserver/signal.h  1970-01-01 01:00:00.000000000 +0100
13705 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/signal.h  2011-10-24 18:53:33.000000000 +0200
13706 @@ -0,0 +1,14 @@
13707 +#ifndef _VX_SIGNAL_H
13708 +#define _VX_SIGNAL_H
13709 +
13710 +
13711 +#ifdef __KERNEL__
13712 +
13713 +struct vx_info;
13714 +
13715 +int vx_info_kill(struct vx_info *, int, int);
13716 +
13717 +#endif /* __KERNEL__ */
13718 +#else  /* _VX_SIGNAL_H */
13719 +#warning duplicate inclusion
13720 +#endif /* _VX_SIGNAL_H */
13721 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/signal_cmd.h linux-3.1.1-vs2.3.2/include/linux/vserver/signal_cmd.h
13722 --- linux-3.1.1/include/linux/vserver/signal_cmd.h      1970-01-01 01:00:00.000000000 +0100
13723 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/signal_cmd.h      2011-10-24 18:53:33.000000000 +0200
13724 @@ -0,0 +1,43 @@
13725 +#ifndef _VX_SIGNAL_CMD_H
13726 +#define _VX_SIGNAL_CMD_H
13727 +
13728 +
13729 +/*  signalling vserver commands */
13730 +
13731 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
13732 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
13733 +
13734 +struct vcmd_ctx_kill_v0 {
13735 +       int32_t pid;
13736 +       int32_t sig;
13737 +};
13738 +
13739 +struct vcmd_wait_exit_v0 {
13740 +       int32_t reboot_cmd;
13741 +       int32_t exit_code;
13742 +};
13743 +
13744 +#ifdef __KERNEL__
13745 +
13746 +extern int vc_ctx_kill(struct vx_info *, void __user *);
13747 +extern int vc_wait_exit(struct vx_info *, void __user *);
13748 +
13749 +#endif /* __KERNEL__ */
13750 +
13751 +/*  process alteration commands */
13752 +
13753 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
13754 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
13755 +
13756 +struct vcmd_pflags_v0 {
13757 +       uint32_t flagword;
13758 +       uint32_t mask;
13759 +};
13760 +
13761 +#ifdef __KERNEL__
13762 +
13763 +extern int vc_get_pflags(uint32_t pid, void __user *);
13764 +extern int vc_set_pflags(uint32_t pid, void __user *);
13765 +
13766 +#endif /* __KERNEL__ */
13767 +#endif /* _VX_SIGNAL_CMD_H */
13768 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/space.h linux-3.1.1-vs2.3.2/include/linux/vserver/space.h
13769 --- linux-3.1.1/include/linux/vserver/space.h   1970-01-01 01:00:00.000000000 +0100
13770 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/space.h   2011-10-24 18:53:33.000000000 +0200
13771 @@ -0,0 +1,12 @@
13772 +#ifndef _VX_SPACE_H
13773 +#define _VX_SPACE_H
13774 +
13775 +#include <linux/types.h>
13776 +
13777 +struct vx_info;
13778 +
13779 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
13780 +
13781 +#else  /* _VX_SPACE_H */
13782 +#warning duplicate inclusion
13783 +#endif /* _VX_SPACE_H */
13784 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/space_cmd.h linux-3.1.1-vs2.3.2/include/linux/vserver/space_cmd.h
13785 --- linux-3.1.1/include/linux/vserver/space_cmd.h       1970-01-01 01:00:00.000000000 +0100
13786 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/space_cmd.h       2011-10-24 18:53:33.000000000 +0200
13787 @@ -0,0 +1,38 @@
13788 +#ifndef _VX_SPACE_CMD_H
13789 +#define _VX_SPACE_CMD_H
13790 +
13791 +
13792 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
13793 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
13794 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
13795 +
13796 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
13797 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
13798 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
13799 +
13800 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
13801 +
13802 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
13803 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
13804 +
13805 +
13806 +struct vcmd_space_mask_v1 {
13807 +       uint64_t mask;
13808 +};
13809 +
13810 +struct vcmd_space_mask_v2 {
13811 +       uint64_t mask;
13812 +       uint32_t index;
13813 +};
13814 +
13815 +
13816 +#ifdef __KERNEL__
13817 +
13818 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
13819 +extern int vc_set_space_v1(struct vx_info *, void __user *);
13820 +extern int vc_enter_space(struct vx_info *, void __user *);
13821 +extern int vc_set_space(struct vx_info *, void __user *);
13822 +extern int vc_get_space_mask(void __user *, int);
13823 +
13824 +#endif /* __KERNEL__ */
13825 +#endif /* _VX_SPACE_CMD_H */
13826 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/switch.h linux-3.1.1-vs2.3.2/include/linux/vserver/switch.h
13827 --- linux-3.1.1/include/linux/vserver/switch.h  1970-01-01 01:00:00.000000000 +0100
13828 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/switch.h  2011-10-24 18:53:33.000000000 +0200
13829 @@ -0,0 +1,98 @@
13830 +#ifndef _VX_SWITCH_H
13831 +#define _VX_SWITCH_H
13832 +
13833 +#include <linux/types.h>
13834 +
13835 +
13836 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
13837 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
13838 +#define VC_VERSION(c)          ((c) & 0xFFF)
13839 +
13840 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
13841 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13842 +
13843 +/*
13844 +
13845 +  Syscall Matrix V2.8
13846 +
13847 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13848 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
13849 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
13850 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13851 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13852 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13853 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13854 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13855 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13856 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13857 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13858 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13859 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13860 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13861 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13862 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13863 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13864 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13865 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13866 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13867 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13868 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13869 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13870 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13871 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13872 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13873 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13874 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13875 +
13876 +*/
13877 +
13878 +#define VC_CAT_VERSION         0
13879 +
13880 +#define VC_CAT_VSETUP          1
13881 +#define VC_CAT_VHOST           2
13882 +
13883 +#define VC_CAT_DEVICE          6
13884 +
13885 +#define VC_CAT_VPROC           9
13886 +#define VC_CAT_PROCALT         10
13887 +#define VC_CAT_PROCMIG         11
13888 +#define VC_CAT_PROCTRL         12
13889 +
13890 +#define VC_CAT_SCHED           14
13891 +#define VC_CAT_MEMCTRL         20
13892 +
13893 +#define VC_CAT_VNET            25
13894 +#define VC_CAT_NETALT          26
13895 +#define VC_CAT_NETMIG          27
13896 +#define VC_CAT_NETCTRL         28
13897 +
13898 +#define VC_CAT_TAGMIG          35
13899 +#define VC_CAT_DLIMIT          36
13900 +#define VC_CAT_INODE           38
13901 +
13902 +#define VC_CAT_VSTAT           40
13903 +#define VC_CAT_VINFO           46
13904 +#define VC_CAT_EVENT           48
13905 +
13906 +#define VC_CAT_FLAGS           52
13907 +#define VC_CAT_VSPACE          54
13908 +#define VC_CAT_DEBUG           56
13909 +#define VC_CAT_RLIMIT          60
13910 +
13911 +#define VC_CAT_SYSTEST         61
13912 +#define VC_CAT_COMPAT          63
13913 +
13914 +/*  query version */
13915 +
13916 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13917 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13918 +
13919 +
13920 +#ifdef __KERNEL__
13921 +
13922 +#include <linux/errno.h>
13923 +
13924 +#endif /* __KERNEL__ */
13925 +
13926 +#endif /* _VX_SWITCH_H */
13927 +
13928 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/tag.h linux-3.1.1-vs2.3.2/include/linux/vserver/tag.h
13929 --- linux-3.1.1/include/linux/vserver/tag.h     1970-01-01 01:00:00.000000000 +0100
13930 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/tag.h     2011-10-24 18:53:33.000000000 +0200
13931 @@ -0,0 +1,143 @@
13932 +#ifndef _DX_TAG_H
13933 +#define _DX_TAG_H
13934 +
13935 +#include <linux/types.h>
13936 +
13937 +
13938 +#define DX_TAG(in)     (IS_TAGGED(in))
13939 +
13940 +
13941 +#ifdef CONFIG_TAG_NFSD
13942 +#define DX_TAG_NFSD    1
13943 +#else
13944 +#define DX_TAG_NFSD    0
13945 +#endif
13946 +
13947 +
13948 +#ifdef CONFIG_TAGGING_NONE
13949 +
13950 +#define MAX_UID                0xFFFFFFFF
13951 +#define MAX_GID                0xFFFFFFFF
13952 +
13953 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
13954 +
13955 +#define TAGINO_UID(cond, uid, tag)     (uid)
13956 +#define TAGINO_GID(cond, gid, tag)     (gid)
13957 +
13958 +#endif
13959 +
13960 +
13961 +#ifdef CONFIG_TAGGING_GID16
13962 +
13963 +#define MAX_UID                0xFFFFFFFF
13964 +#define MAX_GID                0x0000FFFF
13965 +
13966 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13967 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
13968 +
13969 +#define TAGINO_UID(cond, uid, tag)     (uid)
13970 +#define TAGINO_GID(cond, gid, tag)     \
13971 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
13972 +
13973 +#endif
13974 +
13975 +
13976 +#ifdef CONFIG_TAGGING_ID24
13977 +
13978 +#define MAX_UID                0x00FFFFFF
13979 +#define MAX_GID                0x00FFFFFF
13980 +
13981 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13982 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
13983 +
13984 +#define TAGINO_UID(cond, uid, tag)     \
13985 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
13986 +#define TAGINO_GID(cond, gid, tag)     \
13987 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
13988 +
13989 +#endif
13990 +
13991 +
13992 +#ifdef CONFIG_TAGGING_UID16
13993 +
13994 +#define MAX_UID                0x0000FFFF
13995 +#define MAX_GID                0xFFFFFFFF
13996 +
13997 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13998 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
13999 +
14000 +#define TAGINO_UID(cond, uid, tag)     \
14001 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
14002 +#define TAGINO_GID(cond, gid, tag)     (gid)
14003 +
14004 +#endif
14005 +
14006 +
14007 +#ifdef CONFIG_TAGGING_INTERN
14008 +
14009 +#define MAX_UID                0xFFFFFFFF
14010 +#define MAX_GID                0xFFFFFFFF
14011 +
14012 +#define INOTAG_TAG(cond, uid, gid, tag)        \
14013 +       ((cond) ? (tag) : 0)
14014 +
14015 +#define TAGINO_UID(cond, uid, tag)     (uid)
14016 +#define TAGINO_GID(cond, gid, tag)     (gid)
14017 +
14018 +#endif
14019 +
14020 +
14021 +#ifndef CONFIG_TAGGING_NONE
14022 +#define dx_current_fstag(sb)   \
14023 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
14024 +#else
14025 +#define dx_current_fstag(sb)   (0)
14026 +#endif
14027 +
14028 +#ifndef CONFIG_TAGGING_INTERN
14029 +#define TAGINO_TAG(cond, tag)  (0)
14030 +#else
14031 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
14032 +#endif
14033 +
14034 +#define INOTAG_UID(cond, uid, gid)     \
14035 +       ((cond) ? ((uid) & MAX_UID) : (uid))
14036 +#define INOTAG_GID(cond, uid, gid)     \
14037 +       ((cond) ? ((gid) & MAX_GID) : (gid))
14038 +
14039 +
14040 +static inline uid_t dx_map_uid(uid_t uid)
14041 +{
14042 +       if ((uid > MAX_UID) && (uid != -1))
14043 +               uid = -2;
14044 +       return (uid & MAX_UID);
14045 +}
14046 +
14047 +static inline gid_t dx_map_gid(gid_t gid)
14048 +{
14049 +       if ((gid > MAX_GID) && (gid != -1))
14050 +               gid = -2;
14051 +       return (gid & MAX_GID);
14052 +}
14053 +
14054 +struct peer_tag {
14055 +       int32_t xid;
14056 +       int32_t nid;
14057 +};
14058 +
14059 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
14060 +
14061 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
14062 +                unsigned long *flags);
14063 +
14064 +#ifdef CONFIG_PROPAGATE
14065 +
14066 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
14067 +
14068 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
14069 +
14070 +#else
14071 +#define dx_propagate_tag(n, i) do { } while (0)
14072 +#endif
14073 +
14074 +#endif /* _DX_TAG_H */
14075 diff -NurpP --minimal linux-3.1.1/include/linux/vserver/tag_cmd.h linux-3.1.1-vs2.3.2/include/linux/vserver/tag_cmd.h
14076 --- linux-3.1.1/include/linux/vserver/tag_cmd.h 1970-01-01 01:00:00.000000000 +0100
14077 +++ linux-3.1.1-vs2.3.2/include/linux/vserver/tag_cmd.h 2011-10-24 18:53:33.000000000 +0200
14078 @@ -0,0 +1,22 @@
14079 +#ifndef _VX_TAG_CMD_H
14080 +#define _VX_TAG_CMD_H
14081 +
14082 +
14083 +/* vinfo commands */
14084 +
14085 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
14086 +
14087 +#ifdef __KERNEL__
14088 +extern int vc_task_tag(uint32_t);
14089 +
14090 +#endif /* __KERNEL__ */
14091 +
14092 +/* context commands */
14093 +
14094 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
14095 +
14096 +#ifdef __KERNEL__
14097 +extern int vc_tag_migrate(uint32_t);
14098 +
14099 +#endif /* __KERNEL__ */
14100 +#endif /* _VX_TAG_CMD_H */
14101 diff -NurpP --minimal linux-3.1.1/include/net/addrconf.h linux-3.1.1-vs2.3.2/include/net/addrconf.h
14102 --- linux-3.1.1/include/net/addrconf.h  2011-07-22 11:18:11.000000000 +0200
14103 +++ linux-3.1.1-vs2.3.2/include/net/addrconf.h  2011-10-24 18:53:33.000000000 +0200
14104 @@ -80,7 +80,8 @@ extern int                    ipv6_dev_get_saddr(struct n
14105                                                struct net_device *dev,
14106                                                const struct in6_addr *daddr,
14107                                                unsigned int srcprefs,
14108 -                                              struct in6_addr *saddr);
14109 +                                              struct in6_addr *saddr,
14110 +                                              struct nx_info *nxi);
14111  extern int                     ipv6_get_lladdr(struct net_device *dev,
14112                                                 struct in6_addr *addr,
14113                                                 unsigned char banned_flags);
14114 diff -NurpP --minimal linux-3.1.1/include/net/af_unix.h linux-3.1.1-vs2.3.2/include/net/af_unix.h
14115 --- linux-3.1.1/include/net/af_unix.h   2011-07-22 11:18:11.000000000 +0200
14116 +++ linux-3.1.1-vs2.3.2/include/net/af_unix.h   2011-10-24 18:53:33.000000000 +0200
14117 @@ -4,6 +4,7 @@
14118  #include <linux/socket.h>
14119  #include <linux/un.h>
14120  #include <linux/mutex.h>
14121 +#include <linux/vs_base.h>
14122  #include <net/sock.h>
14123  
14124  extern void unix_inflight(struct file *fp);
14125 diff -NurpP --minimal linux-3.1.1/include/net/inet_timewait_sock.h linux-3.1.1-vs2.3.2/include/net/inet_timewait_sock.h
14126 --- linux-3.1.1/include/net/inet_timewait_sock.h        2011-10-24 18:45:32.000000000 +0200
14127 +++ linux-3.1.1-vs2.3.2/include/net/inet_timewait_sock.h        2011-10-24 18:53:33.000000000 +0200
14128 @@ -113,6 +113,10 @@ struct inet_timewait_sock {
14129  #define tw_net                 __tw_common.skc_net
14130  #define tw_daddr               __tw_common.skc_daddr
14131  #define tw_rcv_saddr           __tw_common.skc_rcv_saddr
14132 +#define tw_xid                 __tw_common.skc_xid
14133 +#define tw_vx_info             __tw_common.skc_vx_info
14134 +#define tw_nid                 __tw_common.skc_nid
14135 +#define tw_nx_info             __tw_common.skc_nx_info
14136         int                     tw_timeout;
14137         volatile unsigned char  tw_substate;
14138         unsigned char           tw_rcv_wscale;
14139 diff -NurpP --minimal linux-3.1.1/include/net/ip6_route.h linux-3.1.1-vs2.3.2/include/net/ip6_route.h
14140 --- linux-3.1.1/include/net/ip6_route.h 2011-07-22 11:18:11.000000000 +0200
14141 +++ linux-3.1.1-vs2.3.2/include/net/ip6_route.h 2011-10-24 18:53:33.000000000 +0200
14142 @@ -86,7 +86,8 @@ extern int                    ip6_route_get_saddr(struct 
14143                                                     struct rt6_info *rt,
14144                                                     const struct in6_addr *daddr,
14145                                                     unsigned int prefs,
14146 -                                                   struct in6_addr *saddr);
14147 +                                                   struct in6_addr *saddr,
14148 +                                                   struct nx_info *nxi);
14149  
14150  extern struct rt6_info         *rt6_lookup(struct net *net,
14151                                             const struct in6_addr *daddr,
14152 diff -NurpP --minimal linux-3.1.1/include/net/route.h linux-3.1.1-vs2.3.2/include/net/route.h
14153 --- linux-3.1.1/include/net/route.h     2011-07-22 11:18:11.000000000 +0200
14154 +++ linux-3.1.1-vs2.3.2/include/net/route.h     2011-10-24 18:53:33.000000000 +0200
14155 @@ -202,6 +202,9 @@ static inline void ip_rt_put(struct rtab
14156                 dst_release(&rt->dst);
14157  }
14158  
14159 +#include <linux/vs_base.h>
14160 +#include <linux/vs_inet.h>
14161 +
14162  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
14163  
14164  extern const __u8 ip_tos2prio[16];
14165 @@ -253,6 +256,9 @@ static inline void ip_route_connect_init
14166                            protocol, flow_flags, dst, src, dport, sport);
14167  }
14168  
14169 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
14170 +       struct flowi4 *);
14171 +
14172  static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
14173                                               __be32 dst, __be32 src, u32 tos,
14174                                               int oif, u8 protocol,
14175 @@ -261,11 +267,25 @@ static inline struct rtable *ip_route_co
14176  {
14177         struct net *net = sock_net(sk);
14178         struct rtable *rt;
14179 +       struct nx_info *nx_info = current_nx_info();
14180  
14181         ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
14182                               sport, dport, sk, can_sleep);
14183  
14184 -       if (!dst || !src) {
14185 +       if (sk)
14186 +               nx_info = sk->sk_nx_info;
14187 +
14188 +       vxdprintk(VXD_CBIT(net, 4),
14189 +               "ip_route_connect(%p) %p,%p;%lx",
14190 +               sk, nx_info, sk->sk_socket,
14191 +               (sk->sk_socket?sk->sk_socket->flags:0));
14192 +
14193 +       rt = ip_v4_find_src(net, nx_info, fl4);
14194 +       if (IS_ERR(rt))
14195 +               return rt;
14196 +       ip_rt_put(rt);
14197 +
14198 +       if (!fl4->daddr || !fl4->saddr) {
14199                 rt = __ip_route_output_key(net, fl4);
14200                 if (IS_ERR(rt))
14201                         return rt;
14202 diff -NurpP --minimal linux-3.1.1/include/net/sock.h linux-3.1.1-vs2.3.2/include/net/sock.h
14203 --- linux-3.1.1/include/net/sock.h      2011-10-24 18:45:32.000000000 +0200
14204 +++ linux-3.1.1-vs2.3.2/include/net/sock.h      2011-10-24 18:53:33.000000000 +0200
14205 @@ -150,6 +150,10 @@ struct sock_common {
14206  #ifdef CONFIG_NET_NS
14207         struct net              *skc_net;
14208  #endif
14209 +       xid_t                   skc_xid;
14210 +       struct vx_info          *skc_vx_info;
14211 +       nid_t                   skc_nid;
14212 +       struct nx_info          *skc_nx_info;
14213         /*
14214          * fields between dontcopy_begin/dontcopy_end
14215          * are not copied in sock_copy()
14216 @@ -257,6 +261,10 @@ struct sock {
14217  #define sk_bind_node           __sk_common.skc_bind_node
14218  #define sk_prot                        __sk_common.skc_prot
14219  #define sk_net                 __sk_common.skc_net
14220 +#define sk_xid                 __sk_common.skc_xid
14221 +#define sk_vx_info             __sk_common.skc_vx_info
14222 +#define sk_nid                 __sk_common.skc_nid
14223 +#define sk_nx_info             __sk_common.skc_nx_info
14224         socket_lock_t           sk_lock;
14225         struct sk_buff_head     sk_receive_queue;
14226         /*
14227 diff -NurpP --minimal linux-3.1.1/init/Kconfig linux-3.1.1-vs2.3.2/init/Kconfig
14228 --- linux-3.1.1/init/Kconfig    2011-10-24 18:45:33.000000000 +0200
14229 +++ linux-3.1.1-vs2.3.2/init/Kconfig    2011-10-24 18:53:33.000000000 +0200
14230 @@ -574,6 +574,7 @@ config HAVE_UNSTABLE_SCHED_CLOCK
14231  menuconfig CGROUPS
14232         boolean "Control Group support"
14233         depends on EVENTFD
14234 +       default y
14235         help
14236           This option adds support for grouping sets of processes together, for
14237           use with process control subsystems such as Cpusets, CFS, memory
14238 @@ -790,6 +791,7 @@ config IPC_NS
14239  config USER_NS
14240         bool "User namespace (EXPERIMENTAL)"
14241         depends on EXPERIMENTAL
14242 +       depends on VSERVER_DISABLED
14243         default y
14244         help
14245           This allows containers, i.e. vservers, to use user namespaces
14246 diff -NurpP --minimal linux-3.1.1/init/main.c linux-3.1.1-vs2.3.2/init/main.c
14247 --- linux-3.1.1/init/main.c     2011-10-24 18:45:33.000000000 +0200
14248 +++ linux-3.1.1-vs2.3.2/init/main.c     2011-10-24 18:53:33.000000000 +0200
14249 @@ -68,6 +68,7 @@
14250  #include <linux/shmem_fs.h>
14251  #include <linux/slab.h>
14252  #include <linux/perf_event.h>
14253 +#include <linux/vserver/percpu.h>
14254  
14255  #include <asm/io.h>
14256  #include <asm/bugs.h>
14257 diff -NurpP --minimal linux-3.1.1/ipc/mqueue.c linux-3.1.1-vs2.3.2/ipc/mqueue.c
14258 --- linux-3.1.1/ipc/mqueue.c    2011-10-24 18:45:33.000000000 +0200
14259 +++ linux-3.1.1-vs2.3.2/ipc/mqueue.c    2011-10-24 18:53:33.000000000 +0200
14260 @@ -33,6 +33,8 @@
14261  #include <linux/pid.h>
14262  #include <linux/ipc_namespace.h>
14263  #include <linux/slab.h>
14264 +#include <linux/vs_context.h>
14265 +#include <linux/vs_limit.h>
14266  
14267  #include <net/sock.h>
14268  #include "util.h"
14269 @@ -66,6 +68,7 @@ struct mqueue_inode_info {
14270         struct sigevent notify;
14271         struct pid* notify_owner;
14272         struct user_struct *user;       /* user who created, for accounting */
14273 +       struct vx_info *vxi;
14274         struct sock *notify_sock;
14275         struct sk_buff *notify_cookie;
14276  
14277 @@ -128,6 +131,7 @@ static struct inode *mqueue_get_inode(st
14278         if (S_ISREG(mode)) {
14279                 struct mqueue_inode_info *info;
14280                 struct task_struct *p = current;
14281 +               struct vx_info *vxi = p->vx_info;
14282                 unsigned long mq_bytes, mq_msg_tblsz;
14283  
14284                 inode->i_fop = &mqueue_file_operations;
14285 @@ -141,6 +145,7 @@ static struct inode *mqueue_get_inode(st
14286                 info->notify_owner = NULL;
14287                 info->qsize = 0;
14288                 info->user = NULL;      /* set when all is ok */
14289 +               info->vxi = NULL;
14290                 memset(&info->attr, 0, sizeof(info->attr));
14291                 info->attr.mq_maxmsg = ipc_ns->mq_msg_max;
14292                 info->attr.mq_msgsize = ipc_ns->mq_msgsize_max;
14293 @@ -158,17 +163,20 @@ static struct inode *mqueue_get_inode(st
14294  
14295                 spin_lock(&mq_lock);
14296                 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
14297 -                   u->mq_bytes + mq_bytes > task_rlimit(p, RLIMIT_MSGQUEUE)) {
14298 +                   u->mq_bytes + mq_bytes > task_rlimit(p, RLIMIT_MSGQUEUE) ||
14299 +                   !vx_ipcmsg_avail(vxi, mq_bytes)) {
14300                         spin_unlock(&mq_lock);
14301                         /* mqueue_evict_inode() releases info->messages */
14302                         ret = -EMFILE;
14303                         goto out_inode;
14304                 }
14305                 u->mq_bytes += mq_bytes;
14306 +               vx_ipcmsg_add(vxi, u, mq_bytes);
14307                 spin_unlock(&mq_lock);
14308  
14309                 /* all is ok */
14310                 info->user = get_uid(u);
14311 +               info->vxi = get_vx_info(vxi);
14312         } else if (S_ISDIR(mode)) {
14313                 inc_nlink(inode);
14314                 /* Some things misbehave if size == 0 on a directory */
14315 @@ -278,8 +286,11 @@ static void mqueue_evict_inode(struct in
14316             + info->attr.mq_msgsize);
14317         user = info->user;
14318         if (user) {
14319 +               struct vx_info *vxi = info->vxi;
14320 +
14321                 spin_lock(&mq_lock);
14322                 user->mq_bytes -= mq_bytes;
14323 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
14324                 /*
14325                  * get_ns_from_inode() ensures that the
14326                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
14327 @@ -289,6 +300,7 @@ static void mqueue_evict_inode(struct in
14328                 if (ipc_ns)
14329                         ipc_ns->mq_queues_count--;
14330                 spin_unlock(&mq_lock);
14331 +               put_vx_info(vxi);
14332                 free_uid(user);
14333         }
14334         if (ipc_ns)
14335 diff -NurpP --minimal linux-3.1.1/ipc/msg.c linux-3.1.1-vs2.3.2/ipc/msg.c
14336 --- linux-3.1.1/ipc/msg.c       2011-05-22 16:17:59.000000000 +0200
14337 +++ linux-3.1.1-vs2.3.2/ipc/msg.c       2011-10-24 18:53:33.000000000 +0200
14338 @@ -37,6 +37,7 @@
14339  #include <linux/rwsem.h>
14340  #include <linux/nsproxy.h>
14341  #include <linux/ipc_namespace.h>
14342 +#include <linux/vs_base.h>
14343  
14344  #include <asm/current.h>
14345  #include <asm/uaccess.h>
14346 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
14347  
14348         msq->q_perm.mode = msgflg & S_IRWXUGO;
14349         msq->q_perm.key = key;
14350 +       msq->q_perm.xid = vx_current_xid();
14351  
14352         msq->q_perm.security = NULL;
14353         retval = security_msg_queue_alloc(msq);
14354 diff -NurpP --minimal linux-3.1.1/ipc/namespace.c linux-3.1.1-vs2.3.2/ipc/namespace.c
14355 --- linux-3.1.1/ipc/namespace.c 2011-07-22 11:18:12.000000000 +0200
14356 +++ linux-3.1.1-vs2.3.2/ipc/namespace.c 2011-10-24 18:53:33.000000000 +0200
14357 @@ -13,11 +13,12 @@
14358  #include <linux/mount.h>
14359  #include <linux/user_namespace.h>
14360  #include <linux/proc_fs.h>
14361 +#include <linux/vs_base.h>
14362 +#include <linux/vserver/global.h>
14363  
14364  #include "util.h"
14365  
14366 -static struct ipc_namespace *create_ipc_ns(struct task_struct *tsk,
14367 -                                          struct ipc_namespace *old_ns)
14368 +static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns)
14369  {
14370         struct ipc_namespace *ns;
14371         int err;
14372 @@ -46,19 +47,18 @@ static struct ipc_namespace *create_ipc_
14373         ipcns_notify(IPCNS_CREATED);
14374         register_ipcns_notifier(ns);
14375  
14376 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user)->user_ns);
14377 +       ns->user_ns = get_user_ns(user_ns);
14378  
14379         return ns;
14380  }
14381  
14382  struct ipc_namespace *copy_ipcs(unsigned long flags,
14383 -                               struct task_struct *tsk)
14384 +                               struct ipc_namespace *old_ns,
14385 +                               struct user_namespace *user_ns)
14386  {
14387 -       struct ipc_namespace *ns = tsk->nsproxy->ipc_ns;
14388 -
14389         if (!(flags & CLONE_NEWIPC))
14390 -               return get_ipc_ns(ns);
14391 -       return create_ipc_ns(tsk, ns);
14392 +               return get_ipc_ns(old_ns);
14393 +       return create_ipc_ns(user_ns);
14394  }
14395  
14396  /*
14397 diff -NurpP --minimal linux-3.1.1/ipc/sem.c linux-3.1.1-vs2.3.2/ipc/sem.c
14398 --- linux-3.1.1/ipc/sem.c       2011-10-24 18:45:33.000000000 +0200
14399 +++ linux-3.1.1-vs2.3.2/ipc/sem.c       2011-10-24 18:53:33.000000000 +0200
14400 @@ -86,6 +86,8 @@
14401  #include <linux/rwsem.h>
14402  #include <linux/nsproxy.h>
14403  #include <linux/ipc_namespace.h>
14404 +#include <linux/vs_base.h>
14405 +#include <linux/vs_limit.h>
14406  
14407  #include <asm/uaccess.h>
14408  #include "util.h"
14409 @@ -260,6 +262,7 @@ static int newary(struct ipc_namespace *
14410  
14411         sma->sem_perm.mode = (semflg & S_IRWXUGO);
14412         sma->sem_perm.key = key;
14413 +       sma->sem_perm.xid = vx_current_xid();
14414  
14415         sma->sem_perm.security = NULL;
14416         retval = security_sem_alloc(sma);
14417 @@ -275,6 +278,9 @@ static int newary(struct ipc_namespace *
14418                 return id;
14419         }
14420         ns->used_sems += nsems;
14421 +       /* FIXME: obsoleted? */
14422 +       vx_semary_inc(sma);
14423 +       vx_nsems_add(sma, nsems);
14424  
14425         sma->sem_base = (struct sem *) &sma[1];
14426  
14427 @@ -724,6 +730,9 @@ static void freeary(struct ipc_namespace
14428  
14429         wake_up_sem_queue_do(&tasks);
14430         ns->used_sems -= sma->sem_nsems;
14431 +       /* FIXME: obsoleted? */
14432 +       vx_nsems_sub(sma, sma->sem_nsems);
14433 +       vx_semary_dec(sma);
14434         security_sem_free(sma);
14435         ipc_rcu_putref(sma);
14436  }
14437 diff -NurpP --minimal linux-3.1.1/ipc/shm.c linux-3.1.1-vs2.3.2/ipc/shm.c
14438 --- linux-3.1.1/ipc/shm.c       2011-10-24 18:45:33.000000000 +0200
14439 +++ linux-3.1.1-vs2.3.2/ipc/shm.c       2011-10-24 18:53:33.000000000 +0200
14440 @@ -39,6 +39,8 @@
14441  #include <linux/nsproxy.h>
14442  #include <linux/mount.h>
14443  #include <linux/ipc_namespace.h>
14444 +#include <linux/vs_context.h>
14445 +#include <linux/vs_limit.h>
14446  
14447  #include <asm/uaccess.h>
14448  
14449 @@ -187,7 +189,12 @@ static void shm_open(struct vm_area_stru
14450   */
14451  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
14452  {
14453 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14454 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
14455 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14456 +
14457 +       vx_ipcshm_sub(vxi, shp, numpages);
14458 +       ns->shm_tot -= numpages;
14459 +
14460         shm_rmid(ns, shp);
14461         shm_unlock(shp);
14462         if (!is_file_hugepages(shp->shm_file))
14463 @@ -197,6 +204,7 @@ static void shm_destroy(struct ipc_names
14464                                                 shp->mlock_user);
14465         fput (shp->shm_file);
14466         security_shm_free(shp);
14467 +       put_vx_info(vxi);
14468         ipc_rcu_putref(shp);
14469  }
14470  
14471 @@ -462,11 +470,15 @@ static int newseg(struct ipc_namespace *
14472         if (ns->shm_tot + numpages > ns->shm_ctlall)
14473                 return -ENOSPC;
14474  
14475 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
14476 +               return -ENOSPC;
14477 +
14478         shp = ipc_rcu_alloc(sizeof(*shp));
14479         if (!shp)
14480                 return -ENOMEM;
14481  
14482         shp->shm_perm.key = key;
14483 +       shp->shm_perm.xid = vx_current_xid();
14484         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
14485         shp->mlock_user = NULL;
14486  
14487 @@ -521,6 +533,7 @@ static int newseg(struct ipc_namespace *
14488         ns->shm_tot += numpages;
14489         error = shp->shm_perm.id;
14490         shm_unlock(shp);
14491 +       vx_ipcshm_add(current_vx_info(), key, numpages);
14492         return error;
14493  
14494  no_id:
14495 diff -NurpP --minimal linux-3.1.1/kernel/Makefile linux-3.1.1-vs2.3.2/kernel/Makefile
14496 --- linux-3.1.1/kernel/Makefile 2011-10-24 18:45:33.000000000 +0200
14497 +++ linux-3.1.1-vs2.3.2/kernel/Makefile 2011-10-24 18:53:33.000000000 +0200
14498 @@ -24,6 +24,7 @@ CFLAGS_REMOVE_sched_clock.o = -pg
14499  CFLAGS_REMOVE_irq_work.o = -pg
14500  endif
14501  
14502 +obj-y += vserver/
14503  obj-$(CONFIG_FREEZER) += freezer.o
14504  obj-$(CONFIG_PROFILING) += profile.o
14505  obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
14506 diff -NurpP --minimal linux-3.1.1/kernel/capability.c linux-3.1.1-vs2.3.2/kernel/capability.c
14507 --- linux-3.1.1/kernel/capability.c     2011-07-22 11:18:12.000000000 +0200
14508 +++ linux-3.1.1-vs2.3.2/kernel/capability.c     2011-10-24 18:53:33.000000000 +0200
14509 @@ -15,6 +15,7 @@
14510  #include <linux/syscalls.h>
14511  #include <linux/pid_namespace.h>
14512  #include <linux/user_namespace.h>
14513 +#include <linux/vs_context.h>
14514  #include <asm/uaccess.h>
14515  
14516  /*
14517 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
14518         return 0;
14519  }
14520  
14521 +
14522  /*
14523   * The only thing that can change the capabilities of the current
14524   * process is the current process. As such, we can't be in this code
14525 @@ -340,6 +342,8 @@ bool has_capability_noaudit(struct task_
14526         return (ret == 0);
14527  }
14528  
14529 +#include <linux/vserver/base.h>
14530 +
14531  /**
14532   * capable - Determine if the current task has a superior capability in effect
14533   * @cap: The capability to be tested for
14534 @@ -374,6 +378,9 @@ bool ns_capable(struct user_namespace *n
14535                 BUG();
14536         }
14537  
14538 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
14539 +               return true;
14540 +
14541         if (security_capable(ns, current_cred(), cap) == 0) {
14542                 current->flags |= PF_SUPERPRIV;
14543                 return true;
14544 diff -NurpP --minimal linux-3.1.1/kernel/compat.c linux-3.1.1-vs2.3.2/kernel/compat.c
14545 --- linux-3.1.1/kernel/compat.c 2011-10-24 18:45:33.000000000 +0200
14546 +++ linux-3.1.1-vs2.3.2/kernel/compat.c 2011-10-24 18:53:33.000000000 +0200
14547 @@ -972,7 +972,7 @@ asmlinkage long compat_sys_stime(compat_
14548         if (err)
14549                 return err;
14550  
14551 -       do_settimeofday(&tv);
14552 +       vx_settimeofday(&tv);
14553         return 0;
14554  }
14555  
14556 diff -NurpP --minimal linux-3.1.1/kernel/cred.c linux-3.1.1-vs2.3.2/kernel/cred.c
14557 --- linux-3.1.1/kernel/cred.c   2011-10-24 18:45:33.000000000 +0200
14558 +++ linux-3.1.1-vs2.3.2/kernel/cred.c   2011-10-24 18:53:33.000000000 +0200
14559 @@ -61,31 +61,6 @@ struct cred init_cred = {
14560  #endif
14561  };
14562  
14563 -static inline void set_cred_subscribers(struct cred *cred, int n)
14564 -{
14565 -#ifdef CONFIG_DEBUG_CREDENTIALS
14566 -       atomic_set(&cred->subscribers, n);
14567 -#endif
14568 -}
14569 -
14570 -static inline int read_cred_subscribers(const struct cred *cred)
14571 -{
14572 -#ifdef CONFIG_DEBUG_CREDENTIALS
14573 -       return atomic_read(&cred->subscribers);
14574 -#else
14575 -       return 0;
14576 -#endif
14577 -}
14578 -
14579 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
14580 -{
14581 -#ifdef CONFIG_DEBUG_CREDENTIALS
14582 -       struct cred *cred = (struct cred *) _cred;
14583 -
14584 -       atomic_add(n, &cred->subscribers);
14585 -#endif
14586 -}
14587 -
14588  /*
14589   * Dispose of the shared task group credentials
14590   */
14591 @@ -281,21 +256,16 @@ error:
14592   *
14593   * Call commit_creds() or abort_creds() to clean up.
14594   */
14595 -struct cred *prepare_creds(void)
14596 +struct cred *__prepare_creds(const struct cred *old)
14597  {
14598 -       struct task_struct *task = current;
14599 -       const struct cred *old;
14600         struct cred *new;
14601  
14602 -       validate_process_creds();
14603 -
14604         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
14605         if (!new)
14606                 return NULL;
14607  
14608         kdebug("prepare_creds() alloc %p", new);
14609  
14610 -       old = task->cred;
14611         memcpy(new, old, sizeof(struct cred));
14612  
14613         atomic_set(&new->usage, 1);
14614 @@ -322,6 +292,13 @@ error:
14615         abort_creds(new);
14616         return NULL;
14617  }
14618 +
14619 +struct cred *prepare_creds(void)
14620 +{
14621 +       validate_process_creds();
14622 +
14623 +       return __prepare_creds(current->cred);
14624 +}
14625  EXPORT_SYMBOL(prepare_creds);
14626  
14627  /*
14628 diff -NurpP --minimal linux-3.1.1/kernel/exit.c linux-3.1.1-vs2.3.2/kernel/exit.c
14629 --- linux-3.1.1/kernel/exit.c   2011-10-24 18:45:33.000000000 +0200
14630 +++ linux-3.1.1-vs2.3.2/kernel/exit.c   2011-10-24 18:53:33.000000000 +0200
14631 @@ -48,6 +48,10 @@
14632  #include <linux/fs_struct.h>
14633  #include <linux/init_task.h>
14634  #include <linux/perf_event.h>
14635 +#include <linux/vs_limit.h>
14636 +#include <linux/vs_context.h>
14637 +#include <linux/vs_network.h>
14638 +#include <linux/vs_pid.h>
14639  #include <trace/events/sched.h>
14640  #include <linux/hw_breakpoint.h>
14641  #include <linux/oom.h>
14642 @@ -480,9 +484,11 @@ static void close_files(struct files_str
14643                                         filp_close(file, files);
14644                                         cond_resched();
14645                                 }
14646 +                               vx_openfd_dec(i);
14647                         }
14648                         i++;
14649                         set >>= 1;
14650 +                       cond_resched();
14651                 }
14652         }
14653  }
14654 @@ -1038,11 +1044,16 @@ NORET_TYPE void do_exit(long code)
14655  
14656         validate_creds_for_do_exit(tsk);
14657  
14658 +       /* needs to stay after exit_notify() */
14659 +       exit_vx_info(tsk, code);
14660 +       exit_nx_info(tsk);
14661 +
14662         preempt_disable();
14663         exit_rcu();
14664         /* causes final put_task_struct in finish_task_switch(). */
14665         tsk->state = TASK_DEAD;
14666         schedule();
14667 +       printk("bad task: %p [%lx]\n", current, current->state);
14668         BUG();
14669         /* Avoid "noreturn function does return".  */
14670         for (;;)
14671 diff -NurpP --minimal linux-3.1.1/kernel/fork.c linux-3.1.1-vs2.3.2/kernel/fork.c
14672 --- linux-3.1.1/kernel/fork.c   2011-10-24 18:45:33.000000000 +0200
14673 +++ linux-3.1.1-vs2.3.2/kernel/fork.c   2011-10-24 18:53:33.000000000 +0200
14674 @@ -66,6 +66,10 @@
14675  #include <linux/user-return-notifier.h>
14676  #include <linux/oom.h>
14677  #include <linux/khugepaged.h>
14678 +#include <linux/vs_context.h>
14679 +#include <linux/vs_network.h>
14680 +#include <linux/vs_limit.h>
14681 +#include <linux/vs_memory.h>
14682  
14683  #include <asm/pgtable.h>
14684  #include <asm/pgalloc.h>
14685 @@ -166,6 +170,8 @@ void free_task(struct task_struct *tsk)
14686         account_kernel_stack(tsk->stack, -1);
14687         free_thread_info(tsk->stack);
14688         rt_mutex_debug_task_free(tsk);
14689 +       clr_vx_info(&tsk->vx_info);
14690 +       clr_nx_info(&tsk->nx_info);
14691         ftrace_graph_exit_task(tsk);
14692         free_task_struct(tsk);
14693  }
14694 @@ -506,6 +512,7 @@ static struct mm_struct *mm_init(struct 
14695         if (likely(!mm_alloc_pgd(mm))) {
14696                 mm->def_flags = 0;
14697                 mmu_notifier_mm_init(mm);
14698 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
14699                 return mm;
14700         }
14701  
14702 @@ -543,6 +550,7 @@ void __mmdrop(struct mm_struct *mm)
14703  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
14704         VM_BUG_ON(mm->pmd_huge_pte);
14705  #endif
14706 +       clr_vx_info(&mm->mm_vx_info);
14707         free_mm(mm);
14708  }
14709  EXPORT_SYMBOL_GPL(__mmdrop);
14710 @@ -730,6 +738,7 @@ struct mm_struct *dup_mm(struct task_str
14711                 goto fail_nomem;
14712  
14713         memcpy(mm, oldmm, sizeof(*mm));
14714 +       mm->mm_vx_info = NULL;
14715         mm_init_cpumask(mm);
14716  
14717         /* Initializing for Swap token stuff */
14718 @@ -773,6 +782,7 @@ fail_nocontext:
14719          * If init_new_context() failed, we cannot use mmput() to free the mm
14720          * because it calls destroy_context()
14721          */
14722 +       clr_vx_info(&mm->mm_vx_info);
14723         mm_free_pgd(mm);
14724         free_mm(mm);
14725         return NULL;
14726 @@ -1058,6 +1068,8 @@ static struct task_struct *copy_process(
14727         int retval;
14728         struct task_struct *p;
14729         int cgroup_callbacks_done = 0;
14730 +       struct vx_info *vxi;
14731 +       struct nx_info *nxi;
14732  
14733         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
14734                 return ERR_PTR(-EINVAL);
14735 @@ -1104,7 +1116,12 @@ static struct task_struct *copy_process(
14736         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
14737         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
14738  #endif
14739 +       init_vx_info(&p->vx_info, current_vx_info());
14740 +       init_nx_info(&p->nx_info, current_nx_info());
14741 +
14742         retval = -EAGAIN;
14743 +       if (!vx_nproc_avail(1))
14744 +               goto bad_fork_free;
14745         if (atomic_read(&p->real_cred->user->processes) >=
14746                         task_rlimit(p, RLIMIT_NPROC)) {
14747                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
14748 @@ -1374,6 +1391,18 @@ static struct task_struct *copy_process(
14749  
14750         total_forks++;
14751         spin_unlock(&current->sighand->siglock);
14752 +
14753 +       /* p is copy of current */
14754 +       vxi = p->vx_info;
14755 +       if (vxi) {
14756 +               claim_vx_info(vxi, p);
14757 +               atomic_inc(&vxi->cvirt.nr_threads);
14758 +               atomic_inc(&vxi->cvirt.total_forks);
14759 +               vx_nproc_inc(p);
14760 +       }
14761 +       nxi = p->nx_info;
14762 +       if (nxi)
14763 +               claim_nx_info(nxi, p);
14764         write_unlock_irq(&tasklist_lock);
14765         proc_fork_connector(p);
14766         cgroup_post_fork(p);
14767 diff -NurpP --minimal linux-3.1.1/kernel/kthread.c linux-3.1.1-vs2.3.2/kernel/kthread.c
14768 --- linux-3.1.1/kernel/kthread.c        2011-07-22 11:18:12.000000000 +0200
14769 +++ linux-3.1.1-vs2.3.2/kernel/kthread.c        2011-10-24 18:53:33.000000000 +0200
14770 @@ -16,6 +16,7 @@
14771  #include <linux/mutex.h>
14772  #include <linux/slab.h>
14773  #include <linux/freezer.h>
14774 +#include <linux/vs_pid.h>
14775  #include <trace/events/sched.h>
14776  
14777  static DEFINE_SPINLOCK(kthread_create_lock);
14778 diff -NurpP --minimal linux-3.1.1/kernel/nsproxy.c linux-3.1.1-vs2.3.2/kernel/nsproxy.c
14779 --- linux-3.1.1/kernel/nsproxy.c        2011-10-24 18:45:33.000000000 +0200
14780 +++ linux-3.1.1-vs2.3.2/kernel/nsproxy.c        2011-10-24 18:53:33.000000000 +0200
14781 @@ -20,6 +20,8 @@
14782  #include <linux/mnt_namespace.h>
14783  #include <linux/utsname.h>
14784  #include <linux/pid_namespace.h>
14785 +#include <linux/vserver/global.h>
14786 +#include <linux/vserver/debug.h>
14787  #include <net/net_namespace.h>
14788  #include <linux/ipc_namespace.h>
14789  #include <linux/proc_fs.h>
14790 @@ -46,8 +48,11 @@ static inline struct nsproxy *create_nsp
14791         struct nsproxy *nsproxy;
14792  
14793         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
14794 -       if (nsproxy)
14795 +       if (nsproxy) {
14796                 atomic_set(&nsproxy->count, 1);
14797 +               atomic_inc(&vs_global_nsproxy);
14798 +       }
14799 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
14800         return nsproxy;
14801  }
14802  
14803 @@ -56,8 +61,11 @@ static inline struct nsproxy *create_nsp
14804   * Return the newly created nsproxy.  Do not attach this to the task,
14805   * leave it to the caller to do proper locking and attach it to task.
14806   */
14807 -static struct nsproxy *create_new_namespaces(unsigned long flags,
14808 -                       struct task_struct *tsk, struct fs_struct *new_fs)
14809 +static struct nsproxy *unshare_namespaces(unsigned long flags,
14810 +                       struct nsproxy *orig,
14811 +                       struct fs_struct *new_fs,
14812 +                       struct user_namespace *new_user,
14813 +                       struct pid_namespace *new_pid)
14814  {
14815         struct nsproxy *new_nsp;
14816         int err;
14817 @@ -66,31 +74,31 @@ static struct nsproxy *create_new_namesp
14818         if (!new_nsp)
14819                 return ERR_PTR(-ENOMEM);
14820  
14821 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
14822 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
14823         if (IS_ERR(new_nsp->mnt_ns)) {
14824                 err = PTR_ERR(new_nsp->mnt_ns);
14825                 goto out_ns;
14826         }
14827  
14828 -       new_nsp->uts_ns = copy_utsname(flags, tsk);
14829 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns, new_user);
14830         if (IS_ERR(new_nsp->uts_ns)) {
14831                 err = PTR_ERR(new_nsp->uts_ns);
14832                 goto out_uts;
14833         }
14834  
14835 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk);
14836 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns, new_user);
14837         if (IS_ERR(new_nsp->ipc_ns)) {
14838                 err = PTR_ERR(new_nsp->ipc_ns);
14839                 goto out_ipc;
14840         }
14841  
14842 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
14843 +       new_nsp->pid_ns = copy_pid_ns(flags, new_pid);
14844         if (IS_ERR(new_nsp->pid_ns)) {
14845                 err = PTR_ERR(new_nsp->pid_ns);
14846                 goto out_pid;
14847         }
14848  
14849 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
14850 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
14851         if (IS_ERR(new_nsp->net_ns)) {
14852                 err = PTR_ERR(new_nsp->net_ns);
14853                 goto out_net;
14854 @@ -115,6 +123,40 @@ out_ns:
14855         return ERR_PTR(err);
14856  }
14857  
14858 +static struct nsproxy *create_new_namespaces(unsigned long flags,
14859 +                       struct task_struct *tsk, struct fs_struct *new_fs)
14860 +{
14861 +       return unshare_namespaces(flags, tsk->nsproxy,
14862 +               new_fs, task_cred_xxx(tsk, user)->user_ns,
14863 +               task_active_pid_ns(tsk));
14864 +}
14865 +
14866 +/*
14867 + * copies the nsproxy, setting refcount to 1, and grabbing a
14868 + * reference to all contained namespaces.
14869 + */
14870 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
14871 +{
14872 +       struct nsproxy *ns = create_nsproxy();
14873 +
14874 +       if (ns) {
14875 +               memcpy(ns, orig, sizeof(struct nsproxy));
14876 +               atomic_set(&ns->count, 1);
14877 +
14878 +               if (ns->mnt_ns)
14879 +                       get_mnt_ns(ns->mnt_ns);
14880 +               if (ns->uts_ns)
14881 +                       get_uts_ns(ns->uts_ns);
14882 +               if (ns->ipc_ns)
14883 +                       get_ipc_ns(ns->ipc_ns);
14884 +               if (ns->pid_ns)
14885 +                       get_pid_ns(ns->pid_ns);
14886 +               if (ns->net_ns)
14887 +                       get_net(ns->net_ns);
14888 +       }
14889 +       return ns;
14890 +}
14891 +
14892  /*
14893   * called from clone.  This now handles copy for nsproxy and all
14894   * namespaces therein.
14895 @@ -122,9 +164,12 @@ out_ns:
14896  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
14897  {
14898         struct nsproxy *old_ns = tsk->nsproxy;
14899 -       struct nsproxy *new_ns;
14900 +       struct nsproxy *new_ns = NULL;
14901         int err = 0;
14902  
14903 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
14904 +               flags, tsk, old_ns);
14905 +
14906         if (!old_ns)
14907                 return 0;
14908  
14909 @@ -134,7 +179,7 @@ int copy_namespaces(unsigned long flags,
14910                                 CLONE_NEWPID | CLONE_NEWNET)))
14911                 return 0;
14912  
14913 -       if (!capable(CAP_SYS_ADMIN)) {
14914 +       if (!vx_can_unshare(CAP_SYS_ADMIN, flags)) {
14915                 err = -EPERM;
14916                 goto out;
14917         }
14918 @@ -161,6 +206,9 @@ int copy_namespaces(unsigned long flags,
14919  
14920  out:
14921         put_nsproxy(old_ns);
14922 +       vxdprintk(VXD_CBIT(space, 3),
14923 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
14924 +               flags, tsk, old_ns, err, new_ns);
14925         return err;
14926  }
14927  
14928 @@ -174,7 +222,9 @@ void free_nsproxy(struct nsproxy *ns)
14929                 put_ipc_ns(ns->ipc_ns);
14930         if (ns->pid_ns)
14931                 put_pid_ns(ns->pid_ns);
14932 -       put_net(ns->net_ns);
14933 +       if (ns->net_ns)
14934 +               put_net(ns->net_ns);
14935 +       atomic_dec(&vs_global_nsproxy);
14936         kmem_cache_free(nsproxy_cachep, ns);
14937  }
14938  
14939 @@ -187,11 +237,15 @@ int unshare_nsproxy_namespaces(unsigned 
14940  {
14941         int err = 0;
14942  
14943 +       vxdprintk(VXD_CBIT(space, 4),
14944 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
14945 +               unshare_flags, current->nsproxy);
14946 +
14947         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
14948                                CLONE_NEWNET)))
14949                 return 0;
14950  
14951 -       if (!capable(CAP_SYS_ADMIN))
14952 +       if (!vx_can_unshare(CAP_SYS_ADMIN, unshare_flags))
14953                 return -EPERM;
14954  
14955         *new_nsp = create_new_namespaces(unshare_flags, current,
14956 diff -NurpP --minimal linux-3.1.1/kernel/pid.c linux-3.1.1-vs2.3.2/kernel/pid.c
14957 --- linux-3.1.1/kernel/pid.c    2011-10-24 18:45:33.000000000 +0200
14958 +++ linux-3.1.1-vs2.3.2/kernel/pid.c    2011-10-24 18:53:33.000000000 +0200
14959 @@ -36,6 +36,7 @@
14960  #include <linux/pid_namespace.h>
14961  #include <linux/init_task.h>
14962  #include <linux/syscalls.h>
14963 +#include <linux/vs_pid.h>
14964  
14965  #define pid_hashfn(nr, ns)     \
14966         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
14967 @@ -342,7 +343,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
14968  
14969  struct pid *find_vpid(int nr)
14970  {
14971 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
14972 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
14973  }
14974  EXPORT_SYMBOL_GPL(find_vpid);
14975  
14976 @@ -402,6 +403,9 @@ void transfer_pid(struct task_struct *ol
14977  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
14978  {
14979         struct task_struct *result = NULL;
14980 +
14981 +       if (type == PIDTYPE_REALPID)
14982 +               type = PIDTYPE_PID;
14983         if (pid) {
14984                 struct hlist_node *first;
14985                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
14986 @@ -419,7 +423,7 @@ EXPORT_SYMBOL(pid_task);
14987  struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
14988  {
14989         rcu_lockdep_assert(rcu_read_lock_held());
14990 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
14991 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
14992  }
14993  
14994  struct task_struct *find_task_by_vpid(pid_t vnr)
14995 @@ -463,7 +467,7 @@ struct pid *find_get_pid(pid_t nr)
14996  }
14997  EXPORT_SYMBOL_GPL(find_get_pid);
14998  
14999 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15000 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
15001  {
15002         struct upid *upid;
15003         pid_t nr = 0;
15004 @@ -476,6 +480,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
15005         return nr;
15006  }
15007  
15008 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15009 +{
15010 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
15011 +}
15012 +
15013  pid_t pid_vnr(struct pid *pid)
15014  {
15015         return pid_nr_ns(pid, current->nsproxy->pid_ns);
15016 diff -NurpP --minimal linux-3.1.1/kernel/pid_namespace.c linux-3.1.1-vs2.3.2/kernel/pid_namespace.c
15017 --- linux-3.1.1/kernel/pid_namespace.c  2011-05-22 16:17:59.000000000 +0200
15018 +++ linux-3.1.1-vs2.3.2/kernel/pid_namespace.c  2011-10-24 18:53:33.000000000 +0200
15019 @@ -15,6 +15,7 @@
15020  #include <linux/acct.h>
15021  #include <linux/slab.h>
15022  #include <linux/proc_fs.h>
15023 +#include <linux/vserver/global.h>
15024  
15025  #define BITS_PER_PAGE          (PAGE_SIZE*8)
15026  
15027 @@ -88,6 +89,7 @@ static struct pid_namespace *create_pid_
15028                 goto out_free_map;
15029  
15030         kref_init(&ns->kref);
15031 +       atomic_inc(&vs_global_pid_ns);
15032         ns->level = level;
15033         ns->parent = get_pid_ns(parent_pid_ns);
15034  
15035 @@ -119,6 +121,7 @@ static void destroy_pid_namespace(struct
15036  
15037         for (i = 0; i < PIDMAP_ENTRIES; i++)
15038                 kfree(ns->pidmap[i].page);
15039 +       atomic_dec(&vs_global_pid_ns);
15040         kmem_cache_free(pid_ns_cachep, ns);
15041  }
15042  
15043 diff -NurpP --minimal linux-3.1.1/kernel/posix-timers.c linux-3.1.1-vs2.3.2/kernel/posix-timers.c
15044 --- linux-3.1.1/kernel/posix-timers.c   2011-07-22 11:18:12.000000000 +0200
15045 +++ linux-3.1.1-vs2.3.2/kernel/posix-timers.c   2011-10-24 18:53:33.000000000 +0200
15046 @@ -47,6 +47,7 @@
15047  #include <linux/wait.h>
15048  #include <linux/workqueue.h>
15049  #include <linux/module.h>
15050 +#include <linux/vs_context.h>
15051  
15052  /*
15053   * Management arrays for POSIX timers.  Timers are kept in slab memory
15054 @@ -340,6 +341,7 @@ int posix_timer_event(struct k_itimer *t
15055  {
15056         struct task_struct *task;
15057         int shared, ret = -1;
15058 +
15059         /*
15060          * FIXME: if ->sigq is queued we can race with
15061          * dequeue_signal()->do_schedule_next_timer().
15062 @@ -356,10 +358,18 @@ int posix_timer_event(struct k_itimer *t
15063         rcu_read_lock();
15064         task = pid_task(timr->it_pid, PIDTYPE_PID);
15065         if (task) {
15066 +               struct vx_info_save vxis;
15067 +               struct vx_info *vxi;
15068 +
15069 +               vxi = get_vx_info(task->vx_info);
15070 +               enter_vx_info(vxi, &vxis);
15071                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
15072                 ret = send_sigqueue(timr->sigq, task, shared);
15073 +               leave_vx_info(&vxis);
15074 +               put_vx_info(vxi);
15075         }
15076         rcu_read_unlock();
15077 +
15078         /* If we failed to send the signal the timer stops. */
15079         return ret > 0;
15080  }
15081 diff -NurpP --minimal linux-3.1.1/kernel/printk.c linux-3.1.1-vs2.3.2/kernel/printk.c
15082 --- linux-3.1.1/kernel/printk.c 2011-10-24 18:45:33.000000000 +0200
15083 +++ linux-3.1.1-vs2.3.2/kernel/printk.c 2011-10-24 18:53:33.000000000 +0200
15084 @@ -41,6 +41,7 @@
15085  #include <linux/cpu.h>
15086  #include <linux/notifier.h>
15087  #include <linux/rculist.h>
15088 +#include <linux/vs_cvirt.h>
15089  
15090  #include <asm/uaccess.h>
15091  
15092 @@ -314,7 +315,7 @@ static int check_syslog_permissions(int 
15093                 return 0;
15094  
15095         if (syslog_action_restricted(type)) {
15096 -               if (capable(CAP_SYSLOG))
15097 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
15098                         return 0;
15099                 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
15100                 if (capable(CAP_SYS_ADMIN)) {
15101 @@ -344,12 +345,9 @@ int do_syslog(int type, char __user *buf
15102         if (error)
15103                 return error;
15104  
15105 -       switch (type) {
15106 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
15107 -               break;
15108 -       case SYSLOG_ACTION_OPEN:        /* Open log */
15109 -               break;
15110 -       case SYSLOG_ACTION_READ:        /* Read from log */
15111 +       if ((type == SYSLOG_ACTION_READ) ||
15112 +           (type == SYSLOG_ACTION_READ_ALL) ||
15113 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
15114                 error = -EINVAL;
15115                 if (!buf || len < 0)
15116                         goto out;
15117 @@ -360,6 +358,16 @@ int do_syslog(int type, char __user *buf
15118                         error = -EFAULT;
15119                         goto out;
15120                 }
15121 +       }
15122 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15123 +               return vx_do_syslog(type, buf, len);
15124 +
15125 +       switch (type) {
15126 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
15127 +               break;
15128 +       case SYSLOG_ACTION_OPEN:        /* Open log */
15129 +               break;
15130 +       case SYSLOG_ACTION_READ:        /* Read from log */
15131                 error = wait_event_interruptible(log_wait,
15132                                                         (log_start - log_end));
15133                 if (error)
15134 @@ -386,16 +394,6 @@ int do_syslog(int type, char __user *buf
15135                 /* FALL THRU */
15136         /* Read last kernel messages */
15137         case SYSLOG_ACTION_READ_ALL:
15138 -               error = -EINVAL;
15139 -               if (!buf || len < 0)
15140 -                       goto out;
15141 -               error = 0;
15142 -               if (!len)
15143 -                       goto out;
15144 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
15145 -                       error = -EFAULT;
15146 -                       goto out;
15147 -               }
15148                 count = len;
15149                 if (count > log_buf_len)
15150                         count = log_buf_len;
15151 diff -NurpP --minimal linux-3.1.1/kernel/ptrace.c linux-3.1.1-vs2.3.2/kernel/ptrace.c
15152 --- linux-3.1.1/kernel/ptrace.c 2011-10-24 18:45:33.000000000 +0200
15153 +++ linux-3.1.1-vs2.3.2/kernel/ptrace.c 2011-10-24 18:53:33.000000000 +0200
15154 @@ -22,6 +22,7 @@
15155  #include <linux/syscalls.h>
15156  #include <linux/uaccess.h>
15157  #include <linux/regset.h>
15158 +#include <linux/vs_context.h>
15159  #include <linux/hw_breakpoint.h>
15160  #include <linux/cn_proc.h>
15161  
15162 @@ -198,6 +199,11 @@ ok:
15163                 dumpable = get_dumpable(task->mm);
15164         if (!dumpable && !task_ns_capable(task, CAP_SYS_PTRACE))
15165                 return -EPERM;
15166 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
15167 +               return -EPERM;
15168 +       if (!vx_check(task->xid, VS_IDENT) &&
15169 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
15170 +               return -EACCES;
15171  
15172         return security_ptrace_access_check(task, mode);
15173  }
15174 diff -NurpP --minimal linux-3.1.1/kernel/sched.c linux-3.1.1-vs2.3.2/kernel/sched.c
15175 --- linux-3.1.1/kernel/sched.c  2011-10-24 18:45:33.000000000 +0200
15176 +++ linux-3.1.1-vs2.3.2/kernel/sched.c  2011-10-24 18:53:33.000000000 +0200
15177 @@ -71,6 +71,8 @@
15178  #include <linux/ctype.h>
15179  #include <linux/ftrace.h>
15180  #include <linux/slab.h>
15181 +#include <linux/vs_sched.h>
15182 +#include <linux/vs_cvirt.h>
15183  
15184  #include <asm/tlb.h>
15185  #include <asm/irq_regs.h>
15186 @@ -3473,9 +3475,17 @@ static void calc_global_nohz(unsigned lo
15187   */
15188  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
15189  {
15190 -       loads[0] = (avenrun[0] + offset) << shift;
15191 -       loads[1] = (avenrun[1] + offset) << shift;
15192 -       loads[2] = (avenrun[2] + offset) << shift;
15193 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
15194 +               struct vx_info *vxi = current_vx_info();
15195 +
15196 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
15197 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
15198 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
15199 +       } else {
15200 +               loads[0] = (avenrun[0] + offset) << shift;
15201 +               loads[1] = (avenrun[1] + offset) << shift;
15202 +               loads[2] = (avenrun[2] + offset) << shift;
15203 +       }
15204  }
15205  
15206  /*
15207 @@ -3734,16 +3744,19 @@ void account_user_time(struct task_struc
15208                        cputime_t cputime_scaled)
15209  {
15210         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
15211 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15212         cputime64_t tmp;
15213 +       int nice = (TASK_NICE(p) > 0);
15214  
15215         /* Add user time to process. */
15216         p->utime = cputime_add(p->utime, cputime);
15217         p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
15218 +       vx_account_user(vxi, cputime, nice);
15219         account_group_user_time(p, cputime);
15220  
15221         /* Add user time to cpustat. */
15222         tmp = cputime_to_cputime64(cputime);
15223 -       if (TASK_NICE(p) > 0)
15224 +       if (nice)
15225                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
15226         else
15227                 cpustat->user = cputime64_add(cpustat->user, tmp);
15228 @@ -3795,10 +3808,12 @@ void __account_system_time(struct task_s
15229                         cputime_t cputime_scaled, cputime64_t *target_cputime64)
15230  {
15231         cputime64_t tmp = cputime_to_cputime64(cputime);
15232 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15233  
15234         /* Add system time to process. */
15235         p->stime = cputime_add(p->stime, cputime);
15236         p->stimescaled = cputime_add(p->stimescaled, cputime_scaled);
15237 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
15238         account_group_system_time(p, cputime);
15239  
15240         /* Add system time to cpustat. */
15241 @@ -4984,7 +4999,7 @@ SYSCALL_DEFINE1(nice, int, increment)
15242                 nice = 19;
15243  
15244         if (increment < 0 && !can_nice(current, nice))
15245 -               return -EPERM;
15246 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
15247  
15248         retval = security_task_setnice(current, nice);
15249         if (retval)
15250 diff -NurpP --minimal linux-3.1.1/kernel/sched_fair.c linux-3.1.1-vs2.3.2/kernel/sched_fair.c
15251 --- linux-3.1.1/kernel/sched_fair.c     2011-10-24 18:45:33.000000000 +0200
15252 +++ linux-3.1.1-vs2.3.2/kernel/sched_fair.c     2011-10-24 18:53:33.000000000 +0200
15253 @@ -979,6 +979,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
15254                 __enqueue_entity(cfs_rq, se);
15255         se->on_rq = 1;
15256  
15257 +       if (entity_is_task(se))
15258 +               vx_activate_task(task_of(se));
15259         if (cfs_rq->nr_running == 1)
15260                 list_add_leaf_cfs_rq(cfs_rq);
15261  }
15262 @@ -1055,6 +1057,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
15263         if (se != cfs_rq->curr)
15264                 __dequeue_entity(cfs_rq, se);
15265         se->on_rq = 0;
15266 +       if (entity_is_task(se))
15267 +               vx_deactivate_task(task_of(se));
15268         update_cfs_load(cfs_rq, 0);
15269         account_entity_dequeue(cfs_rq, se);
15270  
15271 diff -NurpP --minimal linux-3.1.1/kernel/signal.c linux-3.1.1-vs2.3.2/kernel/signal.c
15272 --- linux-3.1.1/kernel/signal.c 2011-10-24 18:45:33.000000000 +0200
15273 +++ linux-3.1.1-vs2.3.2/kernel/signal.c 2011-10-24 18:53:33.000000000 +0200
15274 @@ -28,6 +28,8 @@
15275  #include <linux/freezer.h>
15276  #include <linux/pid_namespace.h>
15277  #include <linux/nsproxy.h>
15278 +#include <linux/vs_context.h>
15279 +#include <linux/vs_pid.h>
15280  #define CREATE_TRACE_POINTS
15281  #include <trace/events/signal.h>
15282  
15283 @@ -789,9 +791,18 @@ static int check_kill_permission(int sig
15284         struct pid *sid;
15285         int error;
15286  
15287 +       vxdprintk(VXD_CBIT(misc, 7),
15288 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
15289 +               sig, info, t, vx_task_xid(t), t->pid);
15290 +
15291         if (!valid_signal(sig))
15292                 return -EINVAL;
15293  
15294 +/*     FIXME: needed? if so, why?
15295 +       if ((info != SEND_SIG_NOINFO) &&
15296 +               (is_si_special(info) || !si_fromuser(info)))
15297 +               goto skip;      */
15298 +
15299         if (!si_fromuser(info))
15300                 return 0;
15301  
15302 @@ -815,6 +826,20 @@ static int check_kill_permission(int sig
15303                 }
15304         }
15305  
15306 +       error = -EPERM;
15307 +       if (t->pid == 1 && current->xid)
15308 +               return error;
15309 +
15310 +       error = -ESRCH;
15311 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
15312 +                 loops, maybe ENOENT or EACCES? */
15313 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
15314 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
15315 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
15316 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
15317 +               return error;
15318 +       }
15319 +/* skip: */
15320         return security_task_kill(t, info, sig, 0);
15321  }
15322  
15323 @@ -1319,7 +1344,7 @@ int kill_pid_info(int sig, struct siginf
15324         rcu_read_lock();
15325  retry:
15326         p = pid_task(pid, PIDTYPE_PID);
15327 -       if (p) {
15328 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
15329                 error = group_send_sig_info(sig, info, p);
15330                 if (unlikely(error == -ESRCH))
15331                         /*
15332 @@ -1358,7 +1383,7 @@ int kill_pid_info_as_uid(int sig, struct
15333  
15334         rcu_read_lock();
15335         p = pid_task(pid, PIDTYPE_PID);
15336 -       if (!p) {
15337 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
15338                 ret = -ESRCH;
15339                 goto out_unlock;
15340         }
15341 @@ -1413,8 +1438,10 @@ static int kill_something_info(int sig, 
15342                 struct task_struct * p;
15343  
15344                 for_each_process(p) {
15345 -                       if (task_pid_vnr(p) > 1 &&
15346 -                                       !same_thread_group(p, current)) {
15347 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
15348 +                               task_pid_vnr(p) > 1 &&
15349 +                               !same_thread_group(p, current) &&
15350 +                               !vx_current_initpid(p->pid)) {
15351                                 int err = group_send_sig_info(sig, info, p);
15352                                 ++count;
15353                                 if (err != -EPERM)
15354 @@ -2249,6 +2276,11 @@ relock:
15355                                 !sig_kernel_only(signr))
15356                         continue;
15357  
15358 +               /* virtual init is protected against user signals */
15359 +               if ((info->si_code == SI_USER) &&
15360 +                       vx_current_initpid(current->pid))
15361 +                       continue;
15362 +
15363                 if (sig_kernel_stop(signr)) {
15364                         /*
15365                          * The default action is to stop all threads in
15366 diff -NurpP --minimal linux-3.1.1/kernel/softirq.c linux-3.1.1-vs2.3.2/kernel/softirq.c
15367 --- linux-3.1.1/kernel/softirq.c        2011-07-22 11:18:12.000000000 +0200
15368 +++ linux-3.1.1-vs2.3.2/kernel/softirq.c        2011-10-24 18:53:33.000000000 +0200
15369 @@ -24,6 +24,7 @@
15370  #include <linux/ftrace.h>
15371  #include <linux/smp.h>
15372  #include <linux/tick.h>
15373 +#include <linux/vs_context.h>
15374  
15375  #define CREATE_TRACE_POINTS
15376  #include <trace/events/irq.h>
15377 diff -NurpP --minimal linux-3.1.1/kernel/sys.c linux-3.1.1-vs2.3.2/kernel/sys.c
15378 --- linux-3.1.1/kernel/sys.c    2011-10-24 18:45:33.000000000 +0200
15379 +++ linux-3.1.1-vs2.3.2/kernel/sys.c    2011-10-24 18:53:33.000000000 +0200
15380 @@ -44,6 +44,7 @@
15381  #include <linux/syscalls.h>
15382  #include <linux/kprobes.h>
15383  #include <linux/user_namespace.h>
15384 +#include <linux/vs_pid.h>
15385  
15386  #include <linux/kmsg_dump.h>
15387  /* Move somewhere else to avoid recompiling? */
15388 @@ -154,7 +155,10 @@ static int set_one_prio(struct task_stru
15389                 goto out;
15390         }
15391         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
15392 -               error = -EACCES;
15393 +               if (vx_flags(VXF_IGNEG_NICE, 0))
15394 +                       error = 0;
15395 +               else
15396 +                       error = -EACCES;
15397                 goto out;
15398         }
15399         no_nice = security_task_setnice(p, niceval);
15400 @@ -204,6 +208,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
15401                         else
15402                                 pgrp = task_pgrp(current);
15403                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15404 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15405 +                                       continue;
15406                                 error = set_one_prio(p, niceval, error);
15407                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
15408                         break;
15409 @@ -267,6 +273,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
15410                         else
15411                                 pgrp = task_pgrp(current);
15412                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15413 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15414 +                                       continue;
15415                                 niceval = 20 - task_nice(p);
15416                                 if (niceval > retval)
15417                                         retval = niceval;
15418 @@ -417,6 +425,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
15419  
15420  static DEFINE_MUTEX(reboot_mutex);
15421  
15422 +long vs_reboot(unsigned int, void __user *);
15423 +
15424  /*
15425   * Reboot system call: for obvious reasons only root may call it,
15426   * and even root needs to set up some magic numbers in the registers
15427 @@ -449,6 +459,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
15428         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
15429                 cmd = LINUX_REBOOT_CMD_HALT;
15430  
15431 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15432 +               return vs_reboot(cmd, arg);
15433 +
15434         mutex_lock(&reboot_mutex);
15435         switch (cmd) {
15436         case LINUX_REBOOT_CMD_RESTART:
15437 @@ -1272,7 +1285,8 @@ SYSCALL_DEFINE2(sethostname, char __user
15438         int errno;
15439         char tmp[__NEW_UTS_LEN];
15440  
15441 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
15442 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
15443 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15444                 return -EPERM;
15445  
15446         if (len < 0 || len > __NEW_UTS_LEN)
15447 @@ -1322,7 +1336,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
15448         int errno;
15449         char tmp[__NEW_UTS_LEN];
15450  
15451 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
15452 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
15453 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15454                 return -EPERM;
15455         if (len < 0 || len > __NEW_UTS_LEN)
15456                 return -EINVAL;
15457 @@ -1440,7 +1455,7 @@ int do_prlimit(struct task_struct *tsk, 
15458                 /* Keep the capable check against init_user_ns until
15459                    cgroups can contain all limits */
15460                 if (new_rlim->rlim_max > rlim->rlim_max &&
15461 -                               !capable(CAP_SYS_RESOURCE))
15462 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15463                         retval = -EPERM;
15464                 if (!retval)
15465                         retval = security_task_setrlimit(tsk->group_leader,
15466 @@ -1494,7 +1509,8 @@ static int check_prlimit_permission(stru
15467              cred->gid == tcred->sgid &&
15468              cred->gid == tcred->gid))
15469                 return 0;
15470 -       if (ns_capable(tcred->user->user_ns, CAP_SYS_RESOURCE))
15471 +       if (vx_ns_capable(tcred->user->user_ns,
15472 +               CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15473                 return 0;
15474  
15475         return -EPERM;
15476 diff -NurpP --minimal linux-3.1.1/kernel/sysctl.c linux-3.1.1-vs2.3.2/kernel/sysctl.c
15477 --- linux-3.1.1/kernel/sysctl.c 2011-10-24 18:45:33.000000000 +0200
15478 +++ linux-3.1.1-vs2.3.2/kernel/sysctl.c 2011-10-24 18:53:33.000000000 +0200
15479 @@ -75,6 +75,7 @@
15480  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
15481  #include <linux/lockdep.h>
15482  #endif
15483 +extern char vshelper_path[];
15484  #ifdef CONFIG_CHR_DEV_SG
15485  #include <scsi/sg.h>
15486  #endif
15487 @@ -568,6 +569,13 @@ static struct ctl_table kern_table[] = {
15488                 .proc_handler   = proc_dostring,
15489         },
15490  #endif
15491 +       {
15492 +               .procname       = "vshelper",
15493 +               .data           = &vshelper_path,
15494 +               .maxlen         = 256,
15495 +               .mode           = 0644,
15496 +               .proc_handler   = &proc_dostring,
15497 +       },
15498  #ifdef CONFIG_CHR_DEV_SG
15499         {
15500                 .procname       = "sg-big-buff",
15501 diff -NurpP --minimal linux-3.1.1/kernel/sysctl_binary.c linux-3.1.1-vs2.3.2/kernel/sysctl_binary.c
15502 --- linux-3.1.1/kernel/sysctl_binary.c  2011-10-24 18:45:33.000000000 +0200
15503 +++ linux-3.1.1-vs2.3.2/kernel/sysctl_binary.c  2011-10-24 18:53:33.000000000 +0200
15504 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
15505  
15506         { CTL_INT,      KERN_PANIC,                     "panic" },
15507         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
15508 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
15509  
15510         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
15511         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
15512 diff -NurpP --minimal linux-3.1.1/kernel/time/timekeeping.c linux-3.1.1-vs2.3.2/kernel/time/timekeeping.c
15513 --- linux-3.1.1/kernel/time/timekeeping.c       2011-10-24 18:45:33.000000000 +0200
15514 +++ linux-3.1.1-vs2.3.2/kernel/time/timekeeping.c       2011-10-24 18:53:33.000000000 +0200
15515 @@ -233,6 +233,7 @@ void getnstimeofday(struct timespec *ts)
15516         } while (read_seqretry(&xtime_lock, seq));
15517  
15518         timespec_add_ns(ts, nsecs);
15519 +       vx_adjust_timespec(ts);
15520  }
15521  
15522  EXPORT_SYMBOL(getnstimeofday);
15523 diff -NurpP --minimal linux-3.1.1/kernel/time.c linux-3.1.1-vs2.3.2/kernel/time.c
15524 --- linux-3.1.1/kernel/time.c   2011-11-15 16:44:52.000000000 +0100
15525 +++ linux-3.1.1-vs2.3.2/kernel/time.c   2011-11-15 17:08:44.000000000 +0100
15526 @@ -92,7 +92,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
15527         if (err)
15528                 return err;
15529  
15530 -       do_settimeofday(&tv);
15531 +       vx_settimeofday(&tv);
15532         return 0;
15533  }
15534  
15535 @@ -177,7 +177,7 @@ int do_sys_settimeofday(const struct tim
15536                 /* SMP safe, again the code in arch/foo/time.c should
15537                  * globally block out interrupts when it runs.
15538                  */
15539 -               return do_settimeofday(tv);
15540 +               return vx_settimeofday(tv);
15541         }
15542         return 0;
15543  }
15544 diff -NurpP --minimal linux-3.1.1/kernel/timer.c linux-3.1.1-vs2.3.2/kernel/timer.c
15545 --- linux-3.1.1/kernel/timer.c  2011-07-22 11:18:12.000000000 +0200
15546 +++ linux-3.1.1-vs2.3.2/kernel/timer.c  2011-10-24 18:53:33.000000000 +0200
15547 @@ -40,6 +40,10 @@
15548  #include <linux/irq_work.h>
15549  #include <linux/sched.h>
15550  #include <linux/slab.h>
15551 +#include <linux/vs_base.h>
15552 +#include <linux/vs_cvirt.h>
15553 +#include <linux/vs_pid.h>
15554 +#include <linux/vserver/sched.h>
15555  
15556  #include <asm/uaccess.h>
15557  #include <asm/unistd.h>
15558 @@ -1336,12 +1340,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
15559  
15560  #endif
15561  
15562 -#ifndef __alpha__
15563 -
15564 -/*
15565 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
15566 - * should be moved into arch/i386 instead?
15567 - */
15568  
15569  /**
15570   * sys_getpid - return the thread group id of the current process
15571 @@ -1370,10 +1368,23 @@ SYSCALL_DEFINE0(getppid)
15572         rcu_read_lock();
15573         pid = task_tgid_vnr(current->real_parent);
15574         rcu_read_unlock();
15575 +       return vx_map_pid(pid);
15576 +}
15577  
15578 -       return pid;
15579 +#ifdef __alpha__
15580 +
15581 +/*
15582 + * The Alpha uses getxpid, getxuid, and getxgid instead.
15583 + */
15584 +
15585 +asmlinkage long do_getxpid(long *ppid)
15586 +{
15587 +       *ppid = sys_getppid();
15588 +       return sys_getpid();
15589  }
15590  
15591 +#else /* _alpha_ */
15592 +
15593  SYSCALL_DEFINE0(getuid)
15594  {
15595         /* Only we change this so SMP safe */
15596 diff -NurpP --minimal linux-3.1.1/kernel/user_namespace.c linux-3.1.1-vs2.3.2/kernel/user_namespace.c
15597 --- linux-3.1.1/kernel/user_namespace.c 2011-03-15 18:07:42.000000000 +0100
15598 +++ linux-3.1.1-vs2.3.2/kernel/user_namespace.c 2011-10-24 18:53:33.000000000 +0200
15599 @@ -11,6 +11,7 @@
15600  #include <linux/user_namespace.h>
15601  #include <linux/highuid.h>
15602  #include <linux/cred.h>
15603 +#include <linux/vserver/global.h>
15604  
15605  static struct kmem_cache *user_ns_cachep __read_mostly;
15606  
15607 @@ -33,6 +34,7 @@ int create_user_ns(struct cred *new)
15608                 return -ENOMEM;
15609  
15610         kref_init(&ns->kref);
15611 +       atomic_inc(&vs_global_user_ns);
15612  
15613         for (n = 0; n < UIDHASH_SZ; ++n)
15614                 INIT_HLIST_HEAD(ns->uidhash_table + n);
15615 @@ -81,6 +83,8 @@ void free_user_ns(struct kref *kref)
15616         struct user_namespace *ns =
15617                 container_of(kref, struct user_namespace, kref);
15618  
15619 +       /* FIXME: maybe move into destroyer? */
15620 +       atomic_dec(&vs_global_user_ns);
15621         INIT_WORK(&ns->destroyer, free_user_ns_work);
15622         schedule_work(&ns->destroyer);
15623  }
15624 diff -NurpP --minimal linux-3.1.1/kernel/utsname.c linux-3.1.1-vs2.3.2/kernel/utsname.c
15625 --- linux-3.1.1/kernel/utsname.c        2011-07-22 11:18:12.000000000 +0200
15626 +++ linux-3.1.1-vs2.3.2/kernel/utsname.c        2011-10-24 18:53:33.000000000 +0200
15627 @@ -16,14 +16,17 @@
15628  #include <linux/slab.h>
15629  #include <linux/user_namespace.h>
15630  #include <linux/proc_fs.h>
15631 +#include <linux/vserver/global.h>
15632  
15633  static struct uts_namespace *create_uts_ns(void)
15634  {
15635         struct uts_namespace *uts_ns;
15636  
15637         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
15638 -       if (uts_ns)
15639 +       if (uts_ns) {
15640                 kref_init(&uts_ns->kref);
15641 +               atomic_inc(&vs_global_uts_ns);
15642 +       }
15643         return uts_ns;
15644  }
15645  
15646 @@ -32,8 +35,8 @@ static struct uts_namespace *create_uts_
15647   * @old_ns: namespace to clone
15648   * Return NULL on error (failure to kmalloc), new ns otherwise
15649   */
15650 -static struct uts_namespace *clone_uts_ns(struct task_struct *tsk,
15651 -                                         struct uts_namespace *old_ns)
15652 +static struct uts_namespace *clone_uts_ns(struct uts_namespace *old_ns,
15653 +                                         struct user_namespace *old_user)
15654  {
15655         struct uts_namespace *ns;
15656  
15657 @@ -43,7 +46,7 @@ static struct uts_namespace *clone_uts_n
15658  
15659         down_read(&uts_sem);
15660         memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
15661 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user)->user_ns);
15662 +       ns->user_ns = get_user_ns(old_user);
15663         up_read(&uts_sem);
15664         return ns;
15665  }
15666 @@ -55,9 +58,9 @@ static struct uts_namespace *clone_uts_n
15667   * versa.
15668   */
15669  struct uts_namespace *copy_utsname(unsigned long flags,
15670 -                                  struct task_struct *tsk)
15671 +                                  struct uts_namespace *old_ns,
15672 +                                  struct user_namespace *user_ns)
15673  {
15674 -       struct uts_namespace *old_ns = tsk->nsproxy->uts_ns;
15675         struct uts_namespace *new_ns;
15676  
15677         BUG_ON(!old_ns);
15678 @@ -66,7 +69,7 @@ struct uts_namespace *copy_utsname(unsig
15679         if (!(flags & CLONE_NEWUTS))
15680                 return old_ns;
15681  
15682 -       new_ns = clone_uts_ns(tsk, old_ns);
15683 +       new_ns = clone_uts_ns(old_ns, user_ns);
15684  
15685         put_uts_ns(old_ns);
15686         return new_ns;
15687 @@ -78,6 +81,7 @@ void free_uts_ns(struct kref *kref)
15688  
15689         ns = container_of(kref, struct uts_namespace, kref);
15690         put_user_ns(ns->user_ns);
15691 +       atomic_dec(&vs_global_uts_ns);
15692         kfree(ns);
15693  }
15694  
15695 diff -NurpP --minimal linux-3.1.1/kernel/vserver/Kconfig linux-3.1.1-vs2.3.2/kernel/vserver/Kconfig
15696 --- linux-3.1.1/kernel/vserver/Kconfig  1970-01-01 01:00:00.000000000 +0100
15697 +++ linux-3.1.1-vs2.3.2/kernel/vserver/Kconfig  2011-10-24 18:53:33.000000000 +0200
15698 @@ -0,0 +1,232 @@
15699 +#
15700 +# Linux VServer configuration
15701 +#
15702 +
15703 +menu "Linux VServer"
15704 +
15705 +config VSERVER_AUTO_LBACK
15706 +       bool    "Automatically Assign Loopback IP"
15707 +       default y
15708 +       help
15709 +         Automatically assign a guest specific loopback
15710 +         IP and add it to the kernel network stack on
15711 +         startup.
15712 +
15713 +config VSERVER_AUTO_SINGLE
15714 +       bool    "Automatic Single IP Special Casing"
15715 +       depends on EXPERIMENTAL
15716 +       default y
15717 +       help
15718 +         This allows network contexts with a single IP to
15719 +         automatically remap 0.0.0.0 bindings to that IP,
15720 +         avoiding further network checks and improving
15721 +         performance.
15722 +
15723 +         (note: such guests do not allow to change the ip
15724 +          on the fly and do not show loopback addresses)
15725 +
15726 +config VSERVER_COWBL
15727 +       bool    "Enable COW Immutable Link Breaking"
15728 +       default y
15729 +       help
15730 +         This enables the COW (Copy-On-Write) link break code.
15731 +         It allows you to treat unified files like normal files
15732 +         when writing to them (which will implicitely break the
15733 +         link and create a copy of the unified file)
15734 +
15735 +config VSERVER_VTIME
15736 +       bool    "Enable Virtualized Guest Time"
15737 +       depends on EXPERIMENTAL
15738 +       default n
15739 +       help
15740 +         This enables per guest time offsets to allow for
15741 +         adjusting the system clock individually per guest.
15742 +         this adds some overhead to the time functions and
15743 +         therefore should not be enabled without good reason.
15744 +
15745 +config VSERVER_DEVICE
15746 +       bool    "Enable Guest Device Mapping"
15747 +       depends on EXPERIMENTAL
15748 +       default n
15749 +       help
15750 +         This enables generic device remapping.
15751 +
15752 +config VSERVER_PROC_SECURE
15753 +       bool    "Enable Proc Security"
15754 +       depends on PROC_FS
15755 +       default y
15756 +       help
15757 +         This configures ProcFS security to initially hide
15758 +         non-process entries for all contexts except the main and
15759 +         spectator context (i.e. for all guests), which is a secure
15760 +         default.
15761 +
15762 +         (note: on 1.2x the entries were visible by default)
15763 +
15764 +choice
15765 +       prompt  "Persistent Inode Tagging"
15766 +       default TAGGING_ID24
15767 +       help
15768 +         This adds persistent context information to filesystems
15769 +         mounted with the tagxid option. Tagging is a requirement
15770 +         for per-context disk limits and per-context quota.
15771 +
15772 +
15773 +config TAGGING_NONE
15774 +       bool    "Disabled"
15775 +       help
15776 +         do not store per-context information in inodes.
15777 +
15778 +config TAGGING_UID16
15779 +       bool    "UID16/GID32"
15780 +       help
15781 +         reduces UID to 16 bit, but leaves GID at 32 bit.
15782 +
15783 +config TAGGING_GID16
15784 +       bool    "UID32/GID16"
15785 +       help
15786 +         reduces GID to 16 bit, but leaves UID at 32 bit.
15787 +
15788 +config TAGGING_ID24
15789 +       bool    "UID24/GID24"
15790 +       help
15791 +         uses the upper 8bit from UID and GID for XID tagging
15792 +         which leaves 24bit for UID/GID each, which should be
15793 +         more than sufficient for normal use.
15794 +
15795 +config TAGGING_INTERN
15796 +       bool    "UID32/GID32"
15797 +       help
15798 +         this uses otherwise reserved inode fields in the on
15799 +         disk representation, which limits the use to a few
15800 +         filesystems (currently ext2 and ext3)
15801 +
15802 +endchoice
15803 +
15804 +config TAG_NFSD
15805 +       bool    "Tag NFSD User Auth and Files"
15806 +       default n
15807 +       help
15808 +         Enable this if you do want the in-kernel NFS
15809 +         Server to use the tagging specified above.
15810 +         (will require patched clients too)
15811 +
15812 +config VSERVER_PRIVACY
15813 +       bool    "Honor Privacy Aspects of Guests"
15814 +       default n
15815 +       help
15816 +         When enabled, most context checks will disallow
15817 +         access to structures assigned to a specific context,
15818 +         like ptys or loop devices.
15819 +
15820 +config VSERVER_CONTEXTS
15821 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
15822 +       range 1 65533
15823 +       default "768"   if 64BIT
15824 +       default "256"
15825 +       help
15826 +         This setting will optimize certain data structures
15827 +         and memory allocations according to the expected
15828 +         maximum.
15829 +
15830 +         note: this is not a strict upper limit.
15831 +
15832 +config VSERVER_WARN
15833 +       bool    "VServer Warnings"
15834 +       default y
15835 +       help
15836 +         This enables various runtime warnings, which will
15837 +         notify about potential manipulation attempts or
15838 +         resource shortage. It is generally considered to
15839 +         be a good idea to have that enabled.
15840 +
15841 +config VSERVER_WARN_DEVPTS
15842 +       bool    "VServer DevPTS Warnings"
15843 +       depends on VSERVER_WARN
15844 +       default y
15845 +       help
15846 +         This enables DevPTS related warnings, issued when a
15847 +         process inside a context tries to lookup or access
15848 +         a dynamic pts from the host or a different context.
15849 +
15850 +config VSERVER_DEBUG
15851 +       bool    "VServer Debugging Code"
15852 +       default n
15853 +       help
15854 +         Set this to yes if you want to be able to activate
15855 +         debugging output at runtime. It adds a very small
15856 +         overhead to all vserver related functions and
15857 +         increases the kernel size by about 20k.
15858 +
15859 +config VSERVER_HISTORY
15860 +       bool    "VServer History Tracing"
15861 +       depends on VSERVER_DEBUG
15862 +       default n
15863 +       help
15864 +         Set this to yes if you want to record the history of
15865 +         linux-vserver activities, so they can be replayed in
15866 +         the event of a kernel panic or oops.
15867 +
15868 +config VSERVER_HISTORY_SIZE
15869 +       int     "Per-CPU History Size (32-65536)"
15870 +       depends on VSERVER_HISTORY
15871 +       range 32 65536
15872 +       default 64
15873 +       help
15874 +         This allows you to specify the number of entries in
15875 +         the per-CPU history buffer.
15876 +
15877 +config VSERVER_LEGACY_MEM
15878 +       bool    "Legacy Memory Limits"
15879 +       default n
15880 +       help
15881 +         This provides fake memory limits to keep
15882 +         older tools happy in the face of memory
15883 +         cgroups
15884 +
15885 +choice
15886 +       prompt  "Quotes used in debug and warn messages"
15887 +       default QUOTES_ISO8859
15888 +
15889 +config QUOTES_ISO8859
15890 +       bool    "Extended ASCII (ISO 8859) angle quotes"
15891 +       help
15892 +         This uses the extended ASCII characters \xbb
15893 +         and \xab for quoting file and process names.
15894 +
15895 +config QUOTES_UTF8
15896 +       bool    "UTF-8 angle quotes"
15897 +       help
15898 +         This uses the the UTF-8 sequences for angle
15899 +         quotes to quote file and process names.
15900 +
15901 +config QUOTES_ASCII
15902 +       bool    "ASCII single quotes"
15903 +       help
15904 +         This uses the ASCII single quote character
15905 +         (\x27) to quote file and process names.
15906 +
15907 +endchoice
15908 +
15909 +endmenu
15910 +
15911 +
15912 +config VSERVER
15913 +       bool
15914 +       default y
15915 +       select NAMESPACES
15916 +       select UTS_NS
15917 +       select IPC_NS
15918 +#      select USER_NS
15919 +       select SYSVIPC
15920 +
15921 +config VSERVER_SECURITY
15922 +       bool
15923 +       depends on SECURITY
15924 +       default y
15925 +       select SECURITY_CAPABILITIES
15926 +
15927 +config VSERVER_DISABLED
15928 +       bool
15929 +       default n
15930 +
15931 diff -NurpP --minimal linux-3.1.1/kernel/vserver/Makefile linux-3.1.1-vs2.3.2/kernel/vserver/Makefile
15932 --- linux-3.1.1/kernel/vserver/Makefile 1970-01-01 01:00:00.000000000 +0100
15933 +++ linux-3.1.1-vs2.3.2/kernel/vserver/Makefile 2011-10-24 18:53:33.000000000 +0200
15934 @@ -0,0 +1,18 @@
15935 +#
15936 +# Makefile for the Linux vserver routines.
15937 +#
15938 +
15939 +
15940 +obj-y          += vserver.o
15941 +
15942 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
15943 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
15944 +                  dlimit.o tag.o
15945 +
15946 +vserver-$(CONFIG_INET) += inet.o
15947 +vserver-$(CONFIG_PROC_FS) += proc.o
15948 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
15949 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
15950 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
15951 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
15952 +
15953 diff -NurpP --minimal linux-3.1.1/kernel/vserver/cacct.c linux-3.1.1-vs2.3.2/kernel/vserver/cacct.c
15954 --- linux-3.1.1/kernel/vserver/cacct.c  1970-01-01 01:00:00.000000000 +0100
15955 +++ linux-3.1.1-vs2.3.2/kernel/vserver/cacct.c  2011-10-24 18:53:33.000000000 +0200
15956 @@ -0,0 +1,42 @@
15957 +/*
15958 + *  linux/kernel/vserver/cacct.c
15959 + *
15960 + *  Virtual Server: Context Accounting
15961 + *
15962 + *  Copyright (C) 2006-2007 Herbert Pötzl
15963 + *
15964 + *  V0.01  added accounting stats
15965 + *
15966 + */
15967 +
15968 +#include <linux/types.h>
15969 +#include <linux/vs_context.h>
15970 +#include <linux/vserver/cacct_cmd.h>
15971 +#include <linux/vserver/cacct_int.h>
15972 +
15973 +#include <asm/errno.h>
15974 +#include <asm/uaccess.h>
15975 +
15976 +
15977 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
15978 +{
15979 +       struct vcmd_sock_stat_v0 vc_data;
15980 +       int j, field;
15981 +
15982 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15983 +               return -EFAULT;
15984 +
15985 +       field = vc_data.field;
15986 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
15987 +               return -EINVAL;
15988 +
15989 +       for (j = 0; j < 3; j++) {
15990 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
15991 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
15992 +       }
15993 +
15994 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15995 +               return -EFAULT;
15996 +       return 0;
15997 +}
15998 +
15999 diff -NurpP --minimal linux-3.1.1/kernel/vserver/cacct_init.h linux-3.1.1-vs2.3.2/kernel/vserver/cacct_init.h
16000 --- linux-3.1.1/kernel/vserver/cacct_init.h     1970-01-01 01:00:00.000000000 +0100
16001 +++ linux-3.1.1-vs2.3.2/kernel/vserver/cacct_init.h     2011-10-24 18:53:33.000000000 +0200
16002 @@ -0,0 +1,25 @@
16003 +
16004 +
16005 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
16006 +{
16007 +       int i, j;
16008 +
16009 +
16010 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
16011 +               for (j = 0; j < 3; j++) {
16012 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
16013 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
16014 +               }
16015 +       }
16016 +       for (i = 0; i < 8; i++)
16017 +               atomic_set(&cacct->slab[i], 0);
16018 +       for (i = 0; i < 5; i++)
16019 +               for (j = 0; j < 4; j++)
16020 +                       atomic_set(&cacct->page[i][j], 0);
16021 +}
16022 +
16023 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
16024 +{
16025 +       return;
16026 +}
16027 +
16028 diff -NurpP --minimal linux-3.1.1/kernel/vserver/cacct_proc.h linux-3.1.1-vs2.3.2/kernel/vserver/cacct_proc.h
16029 --- linux-3.1.1/kernel/vserver/cacct_proc.h     1970-01-01 01:00:00.000000000 +0100
16030 +++ linux-3.1.1-vs2.3.2/kernel/vserver/cacct_proc.h     2011-10-24 18:53:33.000000000 +0200
16031 @@ -0,0 +1,53 @@
16032 +#ifndef _VX_CACCT_PROC_H
16033 +#define _VX_CACCT_PROC_H
16034 +
16035 +#include <linux/vserver/cacct_int.h>
16036 +
16037 +
16038 +#define VX_SOCKA_TOP   \
16039 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
16040 +
16041 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
16042 +{
16043 +       int i, j, length = 0;
16044 +       static char *type[VXA_SOCK_SIZE] = {
16045 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
16046 +       };
16047 +
16048 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
16049 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
16050 +               length += sprintf(buffer + length, "%s:", type[i]);
16051 +               for (j = 0; j < 3; j++) {
16052 +                       length += sprintf(buffer + length,
16053 +                               "\t%10lu/%-10lu",
16054 +                               vx_sock_count(cacct, i, j),
16055 +                               vx_sock_total(cacct, i, j));
16056 +               }
16057 +               buffer[length++] = '\n';
16058 +       }
16059 +
16060 +       length += sprintf(buffer + length, "\n");
16061 +       length += sprintf(buffer + length,
16062 +               "slab:\t %8u %8u %8u %8u\n",
16063 +               atomic_read(&cacct->slab[1]),
16064 +               atomic_read(&cacct->slab[4]),
16065 +               atomic_read(&cacct->slab[0]),
16066 +               atomic_read(&cacct->slab[2]));
16067 +
16068 +       length += sprintf(buffer + length, "\n");
16069 +       for (i = 0; i < 5; i++) {
16070 +               length += sprintf(buffer + length,
16071 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
16072 +                       atomic_read(&cacct->page[i][0]),
16073 +                       atomic_read(&cacct->page[i][1]),
16074 +                       atomic_read(&cacct->page[i][2]),
16075 +                       atomic_read(&cacct->page[i][3]),
16076 +                       atomic_read(&cacct->page[i][4]),
16077 +                       atomic_read(&cacct->page[i][5]),
16078 +                       atomic_read(&cacct->page[i][6]),
16079 +                       atomic_read(&cacct->page[i][7]));
16080 +       }
16081 +       return length;
16082 +}
16083 +
16084 +#endif /* _VX_CACCT_PROC_H */
16085 diff -NurpP --minimal linux-3.1.1/kernel/vserver/context.c linux-3.1.1-vs2.3.2/kernel/vserver/context.c
16086 --- linux-3.1.1/kernel/vserver/context.c        1970-01-01 01:00:00.000000000 +0100
16087 +++ linux-3.1.1-vs2.3.2/kernel/vserver/context.c        2011-10-24 18:53:33.000000000 +0200
16088 @@ -0,0 +1,1107 @@
16089 +/*
16090 + *  linux/kernel/vserver/context.c
16091 + *
16092 + *  Virtual Server: Context Support
16093 + *
16094 + *  Copyright (C) 2003-2011  Herbert Pötzl
16095 + *
16096 + *  V0.01  context helper
16097 + *  V0.02  vx_ctx_kill syscall command
16098 + *  V0.03  replaced context_info calls
16099 + *  V0.04  redesign of struct (de)alloc
16100 + *  V0.05  rlimit basic implementation
16101 + *  V0.06  task_xid and info commands
16102 + *  V0.07  context flags and caps
16103 + *  V0.08  switch to RCU based hash
16104 + *  V0.09  revert to non RCU for now
16105 + *  V0.10  and back to working RCU hash
16106 + *  V0.11  and back to locking again
16107 + *  V0.12  referenced context store
16108 + *  V0.13  separate per cpu data
16109 + *  V0.14  changed vcmds to vxi arg
16110 + *  V0.15  added context stat
16111 + *  V0.16  have __create claim() the vxi
16112 + *  V0.17  removed older and legacy stuff
16113 + *  V0.18  added user credentials
16114 + *  V0.19  added warn mask
16115 + *
16116 + */
16117 +
16118 +#include <linux/slab.h>
16119 +#include <linux/types.h>
16120 +#include <linux/security.h>
16121 +#include <linux/pid_namespace.h>
16122 +#include <linux/capability.h>
16123 +
16124 +#include <linux/vserver/context.h>
16125 +#include <linux/vserver/network.h>
16126 +#include <linux/vserver/debug.h>
16127 +#include <linux/vserver/limit.h>
16128 +#include <linux/vserver/limit_int.h>
16129 +#include <linux/vserver/space.h>
16130 +#include <linux/init_task.h>
16131 +#include <linux/fs_struct.h>
16132 +#include <linux/cred.h>
16133 +
16134 +#include <linux/vs_context.h>
16135 +#include <linux/vs_limit.h>
16136 +#include <linux/vs_pid.h>
16137 +#include <linux/vserver/context_cmd.h>
16138 +
16139 +#include "cvirt_init.h"
16140 +#include "cacct_init.h"
16141 +#include "limit_init.h"
16142 +#include "sched_init.h"
16143 +
16144 +
16145 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
16146 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
16147 +
16148 +
16149 +/*     now inactive context structures */
16150 +
16151 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
16152 +
16153 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
16154 +
16155 +
16156 +/*     __alloc_vx_info()
16157 +
16158 +       * allocate an initialized vx_info struct
16159 +       * doesn't make it visible (hash)                        */
16160 +
16161 +static struct vx_info *__alloc_vx_info(xid_t xid)
16162 +{
16163 +       struct vx_info *new = NULL;
16164 +       int cpu, index;
16165 +
16166 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
16167 +
16168 +       /* would this benefit from a slab cache? */
16169 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
16170 +       if (!new)
16171 +               return 0;
16172 +
16173 +       memset(new, 0, sizeof(struct vx_info));
16174 +#ifdef CONFIG_SMP
16175 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
16176 +       if (!new->ptr_pc)
16177 +               goto error;
16178 +#endif
16179 +       new->vx_id = xid;
16180 +       INIT_HLIST_NODE(&new->vx_hlist);
16181 +       atomic_set(&new->vx_usecnt, 0);
16182 +       atomic_set(&new->vx_tasks, 0);
16183 +       new->vx_parent = NULL;
16184 +       new->vx_state = 0;
16185 +       init_waitqueue_head(&new->vx_wait);
16186 +
16187 +       /* prepare reaper */
16188 +       get_task_struct(init_pid_ns.child_reaper);
16189 +       new->vx_reaper = init_pid_ns.child_reaper;
16190 +       new->vx_badness_bias = 0;
16191 +
16192 +       /* rest of init goes here */
16193 +       vx_info_init_limit(&new->limit);
16194 +       vx_info_init_sched(&new->sched);
16195 +       vx_info_init_cvirt(&new->cvirt);
16196 +       vx_info_init_cacct(&new->cacct);
16197 +
16198 +       /* per cpu data structures */
16199 +       for_each_possible_cpu(cpu) {
16200 +               vx_info_init_sched_pc(
16201 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
16202 +               vx_info_init_cvirt_pc(
16203 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
16204 +       }
16205 +
16206 +       new->vx_flags = VXF_INIT_SET;
16207 +       new->vx_bcaps = CAP_FULL_SET;   // maybe ~CAP_SETPCAP
16208 +       new->vx_ccaps = 0;
16209 +       new->vx_umask = 0;
16210 +       new->vx_wmask = 0;
16211 +
16212 +       new->reboot_cmd = 0;
16213 +       new->exit_code = 0;
16214 +
16215 +       // preconfig spaces
16216 +       for (index = 0; index < VX_SPACES; index++) {
16217 +               struct _vx_space *space = &new->space[index];
16218 +
16219 +               // filesystem
16220 +               spin_lock(&init_fs.lock);
16221 +               init_fs.users++;
16222 +               spin_unlock(&init_fs.lock);
16223 +               space->vx_fs = &init_fs;
16224 +
16225 +               /* FIXME: do we want defaults? */
16226 +               // space->vx_real_cred = 0;
16227 +               // space->vx_cred = 0;
16228 +       }
16229 +
16230 +
16231 +       vxdprintk(VXD_CBIT(xid, 0),
16232 +               "alloc_vx_info(%d) = %p", xid, new);
16233 +       vxh_alloc_vx_info(new);
16234 +       atomic_inc(&vx_global_ctotal);
16235 +       return new;
16236 +#ifdef CONFIG_SMP
16237 +error:
16238 +       kfree(new);
16239 +       return 0;
16240 +#endif
16241 +}
16242 +
16243 +/*     __dealloc_vx_info()
16244 +
16245 +       * final disposal of vx_info                             */
16246 +
16247 +static void __dealloc_vx_info(struct vx_info *vxi)
16248 +{
16249 +#ifdef CONFIG_VSERVER_WARN
16250 +       struct vx_info_save vxis;
16251 +       int cpu;
16252 +#endif
16253 +       vxdprintk(VXD_CBIT(xid, 0),
16254 +               "dealloc_vx_info(%p)", vxi);
16255 +       vxh_dealloc_vx_info(vxi);
16256 +
16257 +#ifdef CONFIG_VSERVER_WARN
16258 +       enter_vx_info(vxi, &vxis);
16259 +       vx_info_exit_limit(&vxi->limit);
16260 +       vx_info_exit_sched(&vxi->sched);
16261 +       vx_info_exit_cvirt(&vxi->cvirt);
16262 +       vx_info_exit_cacct(&vxi->cacct);
16263 +
16264 +       for_each_possible_cpu(cpu) {
16265 +               vx_info_exit_sched_pc(
16266 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
16267 +               vx_info_exit_cvirt_pc(
16268 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
16269 +       }
16270 +       leave_vx_info(&vxis);
16271 +#endif
16272 +
16273 +       vxi->vx_id = -1;
16274 +       vxi->vx_state |= VXS_RELEASED;
16275 +
16276 +#ifdef CONFIG_SMP
16277 +       free_percpu(vxi->ptr_pc);
16278 +#endif
16279 +       kfree(vxi);
16280 +       atomic_dec(&vx_global_ctotal);
16281 +}
16282 +
16283 +static void __shutdown_vx_info(struct vx_info *vxi)
16284 +{
16285 +       struct nsproxy *nsproxy;
16286 +       struct fs_struct *fs;
16287 +       struct cred *cred;
16288 +       int index, kill;
16289 +
16290 +       might_sleep();
16291 +
16292 +       vxi->vx_state |= VXS_SHUTDOWN;
16293 +       vs_state_change(vxi, VSC_SHUTDOWN);
16294 +
16295 +       for (index = 0; index < VX_SPACES; index++) {
16296 +               struct _vx_space *space = &vxi->space[index];
16297 +
16298 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
16299 +               if (nsproxy)
16300 +                       put_nsproxy(nsproxy);
16301 +
16302 +               fs = xchg(&space->vx_fs, NULL);
16303 +               spin_lock(&fs->lock);
16304 +               kill = !--fs->users;
16305 +               spin_unlock(&fs->lock);
16306 +               if (kill)
16307 +                       free_fs_struct(fs);
16308 +
16309 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
16310 +               if (cred)
16311 +                       abort_creds(cred);
16312 +       }
16313 +}
16314 +
16315 +/* exported stuff */
16316 +
16317 +void free_vx_info(struct vx_info *vxi)
16318 +{
16319 +       unsigned long flags;
16320 +       unsigned index;
16321 +
16322 +       /* check for reference counts first */
16323 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
16324 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16325 +
16326 +       /* context must not be hashed */
16327 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16328 +
16329 +       /* context shutdown is mandatory */
16330 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
16331 +
16332 +       /* spaces check */
16333 +       for (index = 0; index < VX_SPACES; index++) {
16334 +               struct _vx_space *space = &vxi->space[index];
16335 +
16336 +               BUG_ON(space->vx_nsproxy);
16337 +               BUG_ON(space->vx_fs);
16338 +               // BUG_ON(space->vx_real_cred);
16339 +               // BUG_ON(space->vx_cred);
16340 +       }
16341 +
16342 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16343 +       hlist_del(&vxi->vx_hlist);
16344 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16345 +
16346 +       __dealloc_vx_info(vxi);
16347 +}
16348 +
16349 +
16350 +/*     hash table for vx_info hash */
16351 +
16352 +#define VX_HASH_SIZE   13
16353 +
16354 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
16355 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
16356 +
16357 +static DEFINE_SPINLOCK(vx_info_hash_lock);
16358 +
16359 +
16360 +static inline unsigned int __hashval(xid_t xid)
16361 +{
16362 +       return (xid % VX_HASH_SIZE);
16363 +}
16364 +
16365 +
16366 +
16367 +/*     __hash_vx_info()
16368 +
16369 +       * add the vxi to the global hash table
16370 +       * requires the hash_lock to be held                     */
16371 +
16372 +static inline void __hash_vx_info(struct vx_info *vxi)
16373 +{
16374 +       struct hlist_head *head;
16375 +
16376 +       vxd_assert_lock(&vx_info_hash_lock);
16377 +       vxdprintk(VXD_CBIT(xid, 4),
16378 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
16379 +       vxh_hash_vx_info(vxi);
16380 +
16381 +       /* context must not be hashed */
16382 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16383 +
16384 +       vxi->vx_state |= VXS_HASHED;
16385 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
16386 +       hlist_add_head(&vxi->vx_hlist, head);
16387 +       atomic_inc(&vx_global_cactive);
16388 +}
16389 +
16390 +/*     __unhash_vx_info()
16391 +
16392 +       * remove the vxi from the global hash table
16393 +       * requires the hash_lock to be held                     */
16394 +
16395 +static inline void __unhash_vx_info(struct vx_info *vxi)
16396 +{
16397 +       unsigned long flags;
16398 +
16399 +       vxd_assert_lock(&vx_info_hash_lock);
16400 +       vxdprintk(VXD_CBIT(xid, 4),
16401 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
16402 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
16403 +       vxh_unhash_vx_info(vxi);
16404 +
16405 +       /* context must be hashed */
16406 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
16407 +       /* but without tasks */
16408 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16409 +
16410 +       vxi->vx_state &= ~VXS_HASHED;
16411 +       hlist_del_init(&vxi->vx_hlist);
16412 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16413 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
16414 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16415 +       atomic_dec(&vx_global_cactive);
16416 +}
16417 +
16418 +
16419 +/*     __lookup_vx_info()
16420 +
16421 +       * requires the hash_lock to be held
16422 +       * doesn't increment the vx_refcnt                       */
16423 +
16424 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
16425 +{
16426 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
16427 +       struct hlist_node *pos;
16428 +       struct vx_info *vxi;
16429 +
16430 +       vxd_assert_lock(&vx_info_hash_lock);
16431 +       hlist_for_each(pos, head) {
16432 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16433 +
16434 +               if (vxi->vx_id == xid)
16435 +                       goto found;
16436 +       }
16437 +       vxi = NULL;
16438 +found:
16439 +       vxdprintk(VXD_CBIT(xid, 0),
16440 +               "__lookup_vx_info(#%u): %p[#%u]",
16441 +               xid, vxi, vxi ? vxi->vx_id : 0);
16442 +       vxh_lookup_vx_info(vxi, xid);
16443 +       return vxi;
16444 +}
16445 +
16446 +
16447 +/*     __create_vx_info()
16448 +
16449 +       * create the requested context
16450 +       * get(), claim() and hash it                            */
16451 +
16452 +static struct vx_info *__create_vx_info(int id)
16453 +{
16454 +       struct vx_info *new, *vxi = NULL;
16455 +
16456 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
16457 +
16458 +       if (!(new = __alloc_vx_info(id)))
16459 +               return ERR_PTR(-ENOMEM);
16460 +
16461 +       /* required to make dynamic xids unique */
16462 +       spin_lock(&vx_info_hash_lock);
16463 +
16464 +       /* static context requested */
16465 +       if ((vxi = __lookup_vx_info(id))) {
16466 +               vxdprintk(VXD_CBIT(xid, 0),
16467 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
16468 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16469 +                       vxi = ERR_PTR(-EBUSY);
16470 +               else
16471 +                       vxi = ERR_PTR(-EEXIST);
16472 +               goto out_unlock;
16473 +       }
16474 +       /* new context */
16475 +       vxdprintk(VXD_CBIT(xid, 0),
16476 +               "create_vx_info(%d) = %p (new)", id, new);
16477 +       claim_vx_info(new, NULL);
16478 +       __hash_vx_info(get_vx_info(new));
16479 +       vxi = new, new = NULL;
16480 +
16481 +out_unlock:
16482 +       spin_unlock(&vx_info_hash_lock);
16483 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
16484 +       if (new)
16485 +               __dealloc_vx_info(new);
16486 +       return vxi;
16487 +}
16488 +
16489 +
16490 +/*     exported stuff                                          */
16491 +
16492 +
16493 +void unhash_vx_info(struct vx_info *vxi)
16494 +{
16495 +       spin_lock(&vx_info_hash_lock);
16496 +       __unhash_vx_info(vxi);
16497 +       spin_unlock(&vx_info_hash_lock);
16498 +       __shutdown_vx_info(vxi);
16499 +       __wakeup_vx_info(vxi);
16500 +}
16501 +
16502 +
16503 +/*     lookup_vx_info()
16504 +
16505 +       * search for a vx_info and get() it
16506 +       * negative id means current                             */
16507 +
16508 +struct vx_info *lookup_vx_info(int id)
16509 +{
16510 +       struct vx_info *vxi = NULL;
16511 +
16512 +       if (id < 0) {
16513 +               vxi = get_vx_info(current_vx_info());
16514 +       } else if (id > 1) {
16515 +               spin_lock(&vx_info_hash_lock);
16516 +               vxi = get_vx_info(__lookup_vx_info(id));
16517 +               spin_unlock(&vx_info_hash_lock);
16518 +       }
16519 +       return vxi;
16520 +}
16521 +
16522 +/*     xid_is_hashed()
16523 +
16524 +       * verify that xid is still hashed                       */
16525 +
16526 +int xid_is_hashed(xid_t xid)
16527 +{
16528 +       int hashed;
16529 +
16530 +       spin_lock(&vx_info_hash_lock);
16531 +       hashed = (__lookup_vx_info(xid) != NULL);
16532 +       spin_unlock(&vx_info_hash_lock);
16533 +       return hashed;
16534 +}
16535 +
16536 +#ifdef CONFIG_PROC_FS
16537 +
16538 +/*     get_xid_list()
16539 +
16540 +       * get a subset of hashed xids for proc
16541 +       * assumes size is at least one                          */
16542 +
16543 +int get_xid_list(int index, unsigned int *xids, int size)
16544 +{
16545 +       int hindex, nr_xids = 0;
16546 +
16547 +       /* only show current and children */
16548 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
16549 +               if (index > 0)
16550 +                       return 0;
16551 +               xids[nr_xids] = vx_current_xid();
16552 +               return 1;
16553 +       }
16554 +
16555 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
16556 +               struct hlist_head *head = &vx_info_hash[hindex];
16557 +               struct hlist_node *pos;
16558 +
16559 +               spin_lock(&vx_info_hash_lock);
16560 +               hlist_for_each(pos, head) {
16561 +                       struct vx_info *vxi;
16562 +
16563 +                       if (--index > 0)
16564 +                               continue;
16565 +
16566 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16567 +                       xids[nr_xids] = vxi->vx_id;
16568 +                       if (++nr_xids >= size) {
16569 +                               spin_unlock(&vx_info_hash_lock);
16570 +                               goto out;
16571 +                       }
16572 +               }
16573 +               /* keep the lock time short */
16574 +               spin_unlock(&vx_info_hash_lock);
16575 +       }
16576 +out:
16577 +       return nr_xids;
16578 +}
16579 +#endif
16580 +
16581 +#ifdef CONFIG_VSERVER_DEBUG
16582 +
16583 +void   dump_vx_info_inactive(int level)
16584 +{
16585 +       struct hlist_node *entry, *next;
16586 +
16587 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
16588 +               struct vx_info *vxi =
16589 +                       list_entry(entry, struct vx_info, vx_hlist);
16590 +
16591 +               dump_vx_info(vxi, level);
16592 +       }
16593 +}
16594 +
16595 +#endif
16596 +
16597 +#if 0
16598 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16599 +{
16600 +       struct user_struct *new_user, *old_user;
16601 +
16602 +       if (!p || !vxi)
16603 +               BUG();
16604 +
16605 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16606 +               return -EACCES;
16607 +
16608 +       new_user = alloc_uid(vxi->vx_id, p->uid);
16609 +       if (!new_user)
16610 +               return -ENOMEM;
16611 +
16612 +       old_user = p->user;
16613 +       if (new_user != old_user) {
16614 +               atomic_inc(&new_user->processes);
16615 +               atomic_dec(&old_user->processes);
16616 +               p->user = new_user;
16617 +       }
16618 +       free_uid(old_user);
16619 +       return 0;
16620 +}
16621 +#endif
16622 +
16623 +#if 0
16624 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16625 +{
16626 +       // p->cap_effective &= vxi->vx_cap_bset;
16627 +       p->cap_effective =
16628 +               cap_intersect(p->cap_effective, vxi->cap_bset);
16629 +       // p->cap_inheritable &= vxi->vx_cap_bset;
16630 +       p->cap_inheritable =
16631 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
16632 +       // p->cap_permitted &= vxi->vx_cap_bset;
16633 +       p->cap_permitted =
16634 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
16635 +}
16636 +#endif
16637 +
16638 +
16639 +#include <linux/file.h>
16640 +#include <linux/fdtable.h>
16641 +
16642 +static int vx_openfd_task(struct task_struct *tsk)
16643 +{
16644 +       struct files_struct *files = tsk->files;
16645 +       struct fdtable *fdt;
16646 +       const unsigned long *bptr;
16647 +       int count, total;
16648 +
16649 +       /* no rcu_read_lock() because of spin_lock() */
16650 +       spin_lock(&files->file_lock);
16651 +       fdt = files_fdtable(files);
16652 +       bptr = fdt->open_fds->fds_bits;
16653 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
16654 +       for (total = 0; count > 0; count--) {
16655 +               if (*bptr)
16656 +                       total += hweight_long(*bptr);
16657 +               bptr++;
16658 +       }
16659 +       spin_unlock(&files->file_lock);
16660 +       return total;
16661 +}
16662 +
16663 +
16664 +/*     for *space compatibility */
16665 +
16666 +asmlinkage long sys_unshare(unsigned long);
16667 +
16668 +/*
16669 + *     migrate task to new context
16670 + *     gets vxi, puts old_vxi on change
16671 + *     optionally unshares namespaces (hack)
16672 + */
16673 +
16674 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
16675 +{
16676 +       struct vx_info *old_vxi;
16677 +       int ret = 0;
16678 +
16679 +       if (!p || !vxi)
16680 +               BUG();
16681 +
16682 +       vxdprintk(VXD_CBIT(xid, 5),
16683 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
16684 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
16685 +
16686 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
16687 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16688 +               return -EACCES;
16689 +
16690 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
16691 +               return -EFAULT;
16692 +
16693 +       old_vxi = task_get_vx_info(p);
16694 +       if (old_vxi == vxi)
16695 +               goto out;
16696 +
16697 +//     if (!(ret = vx_migrate_user(p, vxi))) {
16698 +       {
16699 +               int openfd;
16700 +
16701 +               task_lock(p);
16702 +               openfd = vx_openfd_task(p);
16703 +
16704 +               if (old_vxi) {
16705 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
16706 +                       atomic_dec(&old_vxi->cvirt.nr_running);
16707 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
16708 +                       /* FIXME: what about the struct files here? */
16709 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
16710 +                       /* account for the executable */
16711 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
16712 +               }
16713 +               atomic_inc(&vxi->cvirt.nr_threads);
16714 +               atomic_inc(&vxi->cvirt.nr_running);
16715 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
16716 +               /* FIXME: what about the struct files here? */
16717 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
16718 +               /* account for the executable */
16719 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
16720 +
16721 +               if (old_vxi) {
16722 +                       release_vx_info(old_vxi, p);
16723 +                       clr_vx_info(&p->vx_info);
16724 +               }
16725 +               claim_vx_info(vxi, p);
16726 +               set_vx_info(&p->vx_info, vxi);
16727 +               p->xid = vxi->vx_id;
16728 +
16729 +               vxdprintk(VXD_CBIT(xid, 5),
16730 +                       "moved task %p into vxi:%p[#%d]",
16731 +                       p, vxi, vxi->vx_id);
16732 +
16733 +               // vx_mask_cap_bset(vxi, p);
16734 +               task_unlock(p);
16735 +
16736 +               /* hack for *spaces to provide compatibility */
16737 +               if (unshare) {
16738 +                       struct nsproxy *old_nsp, *new_nsp;
16739 +
16740 +                       ret = unshare_nsproxy_namespaces(
16741 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
16742 +                               &new_nsp, NULL);
16743 +                       if (ret)
16744 +                               goto out;
16745 +
16746 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
16747 +                       vx_set_space(vxi,
16748 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
16749 +                       put_nsproxy(old_nsp);
16750 +               }
16751 +       }
16752 +out:
16753 +       put_vx_info(old_vxi);
16754 +       return ret;
16755 +}
16756 +
16757 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
16758 +{
16759 +       struct task_struct *old_reaper;
16760 +
16761 +       if (!vxi)
16762 +               return -EINVAL;
16763 +
16764 +       vxdprintk(VXD_CBIT(xid, 6),
16765 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
16766 +               vxi, vxi->vx_id, p, p->xid, p->pid);
16767 +
16768 +       old_reaper = vxi->vx_reaper;
16769 +       if (old_reaper == p)
16770 +               return 0;
16771 +
16772 +       /* set new child reaper */
16773 +       get_task_struct(p);
16774 +       vxi->vx_reaper = p;
16775 +       put_task_struct(old_reaper);
16776 +       return 0;
16777 +}
16778 +
16779 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
16780 +{
16781 +       if (!vxi)
16782 +               return -EINVAL;
16783 +
16784 +       vxdprintk(VXD_CBIT(xid, 6),
16785 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
16786 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16787 +
16788 +       vxi->vx_flags &= ~VXF_STATE_INIT;
16789 +       // vxi->vx_initpid = p->tgid;
16790 +       vxi->vx_initpid = p->pid;
16791 +       return 0;
16792 +}
16793 +
16794 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
16795 +{
16796 +       vxdprintk(VXD_CBIT(xid, 6),
16797 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
16798 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16799 +
16800 +       vxi->exit_code = code;
16801 +       vxi->vx_initpid = 0;
16802 +}
16803 +
16804 +
16805 +void vx_set_persistent(struct vx_info *vxi)
16806 +{
16807 +       vxdprintk(VXD_CBIT(xid, 6),
16808 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
16809 +
16810 +       get_vx_info(vxi);
16811 +       claim_vx_info(vxi, NULL);
16812 +}
16813 +
16814 +void vx_clear_persistent(struct vx_info *vxi)
16815 +{
16816 +       vxdprintk(VXD_CBIT(xid, 6),
16817 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
16818 +
16819 +       release_vx_info(vxi, NULL);
16820 +       put_vx_info(vxi);
16821 +}
16822 +
16823 +void vx_update_persistent(struct vx_info *vxi)
16824 +{
16825 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
16826 +               vx_set_persistent(vxi);
16827 +       else
16828 +               vx_clear_persistent(vxi);
16829 +}
16830 +
16831 +
16832 +/*     task must be current or locked          */
16833 +
16834 +void   exit_vx_info(struct task_struct *p, int code)
16835 +{
16836 +       struct vx_info *vxi = p->vx_info;
16837 +
16838 +       if (vxi) {
16839 +               atomic_dec(&vxi->cvirt.nr_threads);
16840 +               vx_nproc_dec(p);
16841 +
16842 +               vxi->exit_code = code;
16843 +               release_vx_info(vxi, p);
16844 +       }
16845 +}
16846 +
16847 +void   exit_vx_info_early(struct task_struct *p, int code)
16848 +{
16849 +       struct vx_info *vxi = p->vx_info;
16850 +
16851 +       if (vxi) {
16852 +               if (vxi->vx_initpid == p->pid)
16853 +                       vx_exit_init(vxi, p, code);
16854 +               if (vxi->vx_reaper == p)
16855 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
16856 +       }
16857 +}
16858 +
16859 +
16860 +/* vserver syscall commands below here */
16861 +
16862 +/* taks xid and vx_info functions */
16863 +
16864 +#include <asm/uaccess.h>
16865 +
16866 +
16867 +int vc_task_xid(uint32_t id)
16868 +{
16869 +       xid_t xid;
16870 +
16871 +       if (id) {
16872 +               struct task_struct *tsk;
16873 +
16874 +               rcu_read_lock();
16875 +               tsk = find_task_by_real_pid(id);
16876 +               xid = (tsk) ? tsk->xid : -ESRCH;
16877 +               rcu_read_unlock();
16878 +       } else
16879 +               xid = vx_current_xid();
16880 +       return xid;
16881 +}
16882 +
16883 +
16884 +int vc_vx_info(struct vx_info *vxi, void __user *data)
16885 +{
16886 +       struct vcmd_vx_info_v0 vc_data;
16887 +
16888 +       vc_data.xid = vxi->vx_id;
16889 +       vc_data.initpid = vxi->vx_initpid;
16890 +
16891 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16892 +               return -EFAULT;
16893 +       return 0;
16894 +}
16895 +
16896 +
16897 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
16898 +{
16899 +       struct vcmd_ctx_stat_v0 vc_data;
16900 +
16901 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
16902 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
16903 +
16904 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16905 +               return -EFAULT;
16906 +       return 0;
16907 +}
16908 +
16909 +
16910 +/* context functions */
16911 +
16912 +int vc_ctx_create(uint32_t xid, void __user *data)
16913 +{
16914 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
16915 +       struct vx_info *new_vxi;
16916 +       int ret;
16917 +
16918 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16919 +               return -EFAULT;
16920 +
16921 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
16922 +               return -EINVAL;
16923 +
16924 +       new_vxi = __create_vx_info(xid);
16925 +       if (IS_ERR(new_vxi))
16926 +               return PTR_ERR(new_vxi);
16927 +
16928 +       /* initial flags */
16929 +       new_vxi->vx_flags = vc_data.flagword;
16930 +
16931 +       ret = -ENOEXEC;
16932 +       if (vs_state_change(new_vxi, VSC_STARTUP))
16933 +               goto out;
16934 +
16935 +       ret = vx_migrate_task(current, new_vxi, (!data));
16936 +       if (ret)
16937 +               goto out;
16938 +
16939 +       /* return context id on success */
16940 +       ret = new_vxi->vx_id;
16941 +
16942 +       /* get a reference for persistent contexts */
16943 +       if ((vc_data.flagword & VXF_PERSISTENT))
16944 +               vx_set_persistent(new_vxi);
16945 +out:
16946 +       release_vx_info(new_vxi, NULL);
16947 +       put_vx_info(new_vxi);
16948 +       return ret;
16949 +}
16950 +
16951 +
16952 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
16953 +{
16954 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
16955 +       int ret;
16956 +
16957 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16958 +               return -EFAULT;
16959 +
16960 +       ret = vx_migrate_task(current, vxi, 0);
16961 +       if (ret)
16962 +               return ret;
16963 +       if (vc_data.flagword & VXM_SET_INIT)
16964 +               ret = vx_set_init(vxi, current);
16965 +       if (ret)
16966 +               return ret;
16967 +       if (vc_data.flagword & VXM_SET_REAPER)
16968 +               ret = vx_set_reaper(vxi, current);
16969 +       return ret;
16970 +}
16971 +
16972 +
16973 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
16974 +{
16975 +       struct vcmd_ctx_flags_v0 vc_data;
16976 +
16977 +       vc_data.flagword = vxi->vx_flags;
16978 +
16979 +       /* special STATE flag handling */
16980 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
16981 +
16982 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16983 +               return -EFAULT;
16984 +       return 0;
16985 +}
16986 +
16987 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
16988 +{
16989 +       struct vcmd_ctx_flags_v0 vc_data;
16990 +       uint64_t mask, trigger;
16991 +
16992 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16993 +               return -EFAULT;
16994 +
16995 +       /* special STATE flag handling */
16996 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
16997 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
16998 +
16999 +       if (vxi == current_vx_info()) {
17000 +               /* if (trigger & VXF_STATE_SETUP)
17001 +                       vx_mask_cap_bset(vxi, current); */
17002 +               if (trigger & VXF_STATE_INIT) {
17003 +                       int ret;
17004 +
17005 +                       ret = vx_set_init(vxi, current);
17006 +                       if (ret)
17007 +                               return ret;
17008 +                       ret = vx_set_reaper(vxi, current);
17009 +                       if (ret)
17010 +                               return ret;
17011 +               }
17012 +       }
17013 +
17014 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
17015 +               vc_data.flagword, mask);
17016 +       if (trigger & VXF_PERSISTENT)
17017 +               vx_update_persistent(vxi);
17018 +
17019 +       return 0;
17020 +}
17021 +
17022 +
17023 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
17024 +{
17025 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
17026 +
17027 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
17028 +       return v;
17029 +}
17030 +
17031 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
17032 +{
17033 +       kernel_cap_t c = __cap_empty_set;
17034 +
17035 +       c.cap[0] = v & 0xFFFFFFFF;
17036 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
17037 +
17038 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
17039 +       return c;
17040 +}
17041 +
17042 +
17043 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
17044 +{
17045 +       if (bcaps)
17046 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
17047 +       if (ccaps)
17048 +               *ccaps = vxi->vx_ccaps;
17049 +
17050 +       return 0;
17051 +}
17052 +
17053 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
17054 +{
17055 +       struct vcmd_ctx_caps_v1 vc_data;
17056 +       int ret;
17057 +
17058 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
17059 +       if (ret)
17060 +               return ret;
17061 +       vc_data.cmask = ~0ULL;
17062 +
17063 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17064 +               return -EFAULT;
17065 +       return 0;
17066 +}
17067 +
17068 +static int do_set_caps(struct vx_info *vxi,
17069 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
17070 +{
17071 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
17072 +
17073 +#if 0
17074 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
17075 +               bcaps, bmask, ccaps, cmask);
17076 +#endif
17077 +       vxi->vx_bcaps = cap_t_from_caps(
17078 +               vs_mask_flags(bcold, bcaps, bmask));
17079 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
17080 +
17081 +       return 0;
17082 +}
17083 +
17084 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
17085 +{
17086 +       struct vcmd_ctx_caps_v1 vc_data;
17087 +
17088 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17089 +               return -EFAULT;
17090 +
17091 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
17092 +}
17093 +
17094 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
17095 +{
17096 +       struct vcmd_bcaps vc_data;
17097 +       int ret;
17098 +
17099 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
17100 +       if (ret)
17101 +               return ret;
17102 +       vc_data.bmask = ~0ULL;
17103 +
17104 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17105 +               return -EFAULT;
17106 +       return 0;
17107 +}
17108 +
17109 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
17110 +{
17111 +       struct vcmd_bcaps vc_data;
17112 +
17113 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17114 +               return -EFAULT;
17115 +
17116 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
17117 +}
17118 +
17119 +
17120 +int vc_get_umask(struct vx_info *vxi, void __user *data)
17121 +{
17122 +       struct vcmd_umask vc_data;
17123 +
17124 +       vc_data.umask = vxi->vx_umask;
17125 +       vc_data.mask = ~0ULL;
17126 +
17127 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17128 +               return -EFAULT;
17129 +       return 0;
17130 +}
17131 +
17132 +int vc_set_umask(struct vx_info *vxi, void __user *data)
17133 +{
17134 +       struct vcmd_umask vc_data;
17135 +
17136 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17137 +               return -EFAULT;
17138 +
17139 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
17140 +               vc_data.umask, vc_data.mask);
17141 +       return 0;
17142 +}
17143 +
17144 +
17145 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
17146 +{
17147 +       struct vcmd_wmask vc_data;
17148 +
17149 +       vc_data.wmask = vxi->vx_wmask;
17150 +       vc_data.mask = ~0ULL;
17151 +
17152 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17153 +               return -EFAULT;
17154 +       return 0;
17155 +}
17156 +
17157 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
17158 +{
17159 +       struct vcmd_wmask vc_data;
17160 +
17161 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17162 +               return -EFAULT;
17163 +
17164 +       vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
17165 +               vc_data.wmask, vc_data.mask);
17166 +       return 0;
17167 +}
17168 +
17169 +
17170 +int vc_get_badness(struct vx_info *vxi, void __user *data)
17171 +{
17172 +       struct vcmd_badness_v0 vc_data;
17173 +
17174 +       vc_data.bias = vxi->vx_badness_bias;
17175 +
17176 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17177 +               return -EFAULT;
17178 +       return 0;
17179 +}
17180 +
17181 +int vc_set_badness(struct vx_info *vxi, void __user *data)
17182 +{
17183 +       struct vcmd_badness_v0 vc_data;
17184 +
17185 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17186 +               return -EFAULT;
17187 +
17188 +       vxi->vx_badness_bias = vc_data.bias;
17189 +       return 0;
17190 +}
17191 +
17192 +#include <linux/module.h>
17193 +
17194 +EXPORT_SYMBOL_GPL(free_vx_info);
17195 +
17196 diff -NurpP --minimal linux-3.1.1/kernel/vserver/cvirt.c linux-3.1.1-vs2.3.2/kernel/vserver/cvirt.c
17197 --- linux-3.1.1/kernel/vserver/cvirt.c  1970-01-01 01:00:00.000000000 +0100
17198 +++ linux-3.1.1-vs2.3.2/kernel/vserver/cvirt.c  2011-10-24 18:53:33.000000000 +0200
17199 @@ -0,0 +1,303 @@
17200 +/*
17201 + *  linux/kernel/vserver/cvirt.c
17202 + *
17203 + *  Virtual Server: Context Virtualization
17204 + *
17205 + *  Copyright (C) 2004-2007  Herbert Pötzl
17206 + *
17207 + *  V0.01  broken out from limit.c
17208 + *  V0.02  added utsname stuff
17209 + *  V0.03  changed vcmds to vxi arg
17210 + *
17211 + */
17212 +
17213 +#include <linux/types.h>
17214 +#include <linux/utsname.h>
17215 +#include <linux/vs_cvirt.h>
17216 +#include <linux/vserver/switch.h>
17217 +#include <linux/vserver/cvirt_cmd.h>
17218 +
17219 +#include <asm/uaccess.h>
17220 +
17221 +
17222 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
17223 +{
17224 +       struct vx_info *vxi = current_vx_info();
17225 +
17226 +       set_normalized_timespec(uptime,
17227 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
17228 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
17229 +       if (!idle)
17230 +               return;
17231 +       set_normalized_timespec(idle,
17232 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
17233 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
17234 +       return;
17235 +}
17236 +
17237 +uint64_t vx_idle_jiffies(void)
17238 +{
17239 +       return init_task.utime + init_task.stime;
17240 +}
17241 +
17242 +
17243 +
17244 +static inline uint32_t __update_loadavg(uint32_t load,
17245 +       int wsize, int delta, int n)
17246 +{
17247 +       unsigned long long calc, prev;
17248 +
17249 +       /* just set it to n */
17250 +       if (unlikely(delta >= wsize))
17251 +               return (n << FSHIFT);
17252 +
17253 +       calc = delta * n;
17254 +       calc <<= FSHIFT;
17255 +       prev = (wsize - delta);
17256 +       prev *= load;
17257 +       calc += prev;
17258 +       do_div(calc, wsize);
17259 +       return calc;
17260 +}
17261 +
17262 +
17263 +void vx_update_load(struct vx_info *vxi)
17264 +{
17265 +       uint32_t now, last, delta;
17266 +       unsigned int nr_running, nr_uninterruptible;
17267 +       unsigned int total;
17268 +       unsigned long flags;
17269 +
17270 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
17271 +
17272 +       now = jiffies;
17273 +       last = vxi->cvirt.load_last;
17274 +       delta = now - last;
17275 +
17276 +       if (delta < 5*HZ)
17277 +               goto out;
17278 +
17279 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
17280 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
17281 +       total = nr_running + nr_uninterruptible;
17282 +
17283 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
17284 +               60*HZ, delta, total);
17285 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
17286 +               5*60*HZ, delta, total);
17287 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
17288 +               15*60*HZ, delta, total);
17289 +
17290 +       vxi->cvirt.load_last = now;
17291 +out:
17292 +       atomic_inc(&vxi->cvirt.load_updates);
17293 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
17294 +}
17295 +
17296 +
17297 +/*
17298 + * Commands to do_syslog:
17299 + *
17300 + *      0 -- Close the log.  Currently a NOP.
17301 + *      1 -- Open the log. Currently a NOP.
17302 + *      2 -- Read from the log.
17303 + *      3 -- Read all messages remaining in the ring buffer.
17304 + *      4 -- Read and clear all messages remaining in the ring buffer
17305 + *      5 -- Clear ring buffer.
17306 + *      6 -- Disable printk's to console
17307 + *      7 -- Enable printk's to console
17308 + *      8 -- Set level of messages printed to console
17309 + *      9 -- Return number of unread characters in the log buffer
17310 + *     10 -- Return size of the log buffer
17311 + */
17312 +int vx_do_syslog(int type, char __user *buf, int len)
17313 +{
17314 +       int error = 0;
17315 +       int do_clear = 0;
17316 +       struct vx_info *vxi = current_vx_info();
17317 +       struct _vx_syslog *log;
17318 +
17319 +       if (!vxi)
17320 +               return -EINVAL;
17321 +       log = &vxi->cvirt.syslog;
17322 +
17323 +       switch (type) {
17324 +       case 0:         /* Close log */
17325 +       case 1:         /* Open log */
17326 +               break;
17327 +       case 2:         /* Read from log */
17328 +               error = wait_event_interruptible(log->log_wait,
17329 +                       (log->log_start - log->log_end));
17330 +               if (error)
17331 +                       break;
17332 +               spin_lock_irq(&log->logbuf_lock);
17333 +               spin_unlock_irq(&log->logbuf_lock);
17334 +               break;
17335 +       case 4:         /* Read/clear last kernel messages */
17336 +               do_clear = 1;
17337 +               /* fall through */
17338 +       case 3:         /* Read last kernel messages */
17339 +               return 0;
17340 +
17341 +       case 5:         /* Clear ring buffer */
17342 +               return 0;
17343 +
17344 +       case 6:         /* Disable logging to console */
17345 +       case 7:         /* Enable logging to console */
17346 +       case 8:         /* Set level of messages printed to console */
17347 +               break;
17348 +
17349 +       case 9:         /* Number of chars in the log buffer */
17350 +               return 0;
17351 +       case 10:        /* Size of the log buffer */
17352 +               return 0;
17353 +       default:
17354 +               error = -EINVAL;
17355 +               break;
17356 +       }
17357 +       return error;
17358 +}
17359 +
17360 +
17361 +/* virtual host info names */
17362 +
17363 +static char *vx_vhi_name(struct vx_info *vxi, int id)
17364 +{
17365 +       struct nsproxy *nsproxy;
17366 +       struct uts_namespace *uts;
17367 +
17368 +       if (id == VHIN_CONTEXT)
17369 +               return vxi->vx_name;
17370 +
17371 +       nsproxy = vxi->space[0].vx_nsproxy;
17372 +       if (!nsproxy)
17373 +               return NULL;
17374 +
17375 +       uts = nsproxy->uts_ns;
17376 +       if (!uts)
17377 +               return NULL;
17378 +
17379 +       switch (id) {
17380 +       case VHIN_SYSNAME:
17381 +               return uts->name.sysname;
17382 +       case VHIN_NODENAME:
17383 +               return uts->name.nodename;
17384 +       case VHIN_RELEASE:
17385 +               return uts->name.release;
17386 +       case VHIN_VERSION:
17387 +               return uts->name.version;
17388 +       case VHIN_MACHINE:
17389 +               return uts->name.machine;
17390 +       case VHIN_DOMAINNAME:
17391 +               return uts->name.domainname;
17392 +       default:
17393 +               return NULL;
17394 +       }
17395 +       return NULL;
17396 +}
17397 +
17398 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
17399 +{
17400 +       struct vcmd_vhi_name_v0 vc_data;
17401 +       char *name;
17402 +
17403 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17404 +               return -EFAULT;
17405 +
17406 +       name = vx_vhi_name(vxi, vc_data.field);
17407 +       if (!name)
17408 +               return -EINVAL;
17409 +
17410 +       memcpy(name, vc_data.name, 65);
17411 +       return 0;
17412 +}
17413 +
17414 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
17415 +{
17416 +       struct vcmd_vhi_name_v0 vc_data;
17417 +       char *name;
17418 +
17419 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17420 +               return -EFAULT;
17421 +
17422 +       name = vx_vhi_name(vxi, vc_data.field);
17423 +       if (!name)
17424 +               return -EINVAL;
17425 +
17426 +       memcpy(vc_data.name, name, 65);
17427 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17428 +               return -EFAULT;
17429 +       return 0;
17430 +}
17431 +
17432 +
17433 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
17434 +{
17435 +       struct vcmd_virt_stat_v0 vc_data;
17436 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
17437 +       struct timespec uptime;
17438 +
17439 +       do_posix_clock_monotonic_gettime(&uptime);
17440 +       set_normalized_timespec(&uptime,
17441 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
17442 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
17443 +
17444 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
17445 +       vc_data.uptime = timespec_to_ns(&uptime);
17446 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
17447 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
17448 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
17449 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
17450 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
17451 +       vc_data.load[0] = cvirt->load[0];
17452 +       vc_data.load[1] = cvirt->load[1];
17453 +       vc_data.load[2] = cvirt->load[2];
17454 +
17455 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17456 +               return -EFAULT;
17457 +       return 0;
17458 +}
17459 +
17460 +
17461 +#ifdef CONFIG_VSERVER_VTIME
17462 +
17463 +/* virtualized time base */
17464 +
17465 +void vx_adjust_timespec(struct timespec *ts)
17466 +{
17467 +       struct vx_info *vxi;
17468 +
17469 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17470 +               return;
17471 +
17472 +       vxi = current_vx_info();
17473 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
17474 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
17475 +
17476 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
17477 +               ts->tv_sec++;
17478 +               ts->tv_nsec -= NSEC_PER_SEC;
17479 +       } else if (ts->tv_nsec < 0) {
17480 +               ts->tv_sec--;
17481 +               ts->tv_nsec += NSEC_PER_SEC;
17482 +       }
17483 +}
17484 +
17485 +int vx_settimeofday(const struct timespec *ts)
17486 +{
17487 +       struct timespec ats, delta;
17488 +       struct vx_info *vxi;
17489 +
17490 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17491 +               return do_settimeofday(ts);
17492 +
17493 +       getnstimeofday(&ats);
17494 +       delta = timespec_sub(*ts, ats);
17495 +
17496 +       vxi = current_vx_info();
17497 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
17498 +       return 0;
17499 +}
17500 +
17501 +#endif
17502 +
17503 diff -NurpP --minimal linux-3.1.1/kernel/vserver/cvirt_init.h linux-3.1.1-vs2.3.2/kernel/vserver/cvirt_init.h
17504 --- linux-3.1.1/kernel/vserver/cvirt_init.h     1970-01-01 01:00:00.000000000 +0100
17505 +++ linux-3.1.1-vs2.3.2/kernel/vserver/cvirt_init.h     2011-10-24 18:53:33.000000000 +0200
17506 @@ -0,0 +1,70 @@
17507 +
17508 +
17509 +extern uint64_t vx_idle_jiffies(void);
17510 +
17511 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
17512 +{
17513 +       uint64_t idle_jiffies = vx_idle_jiffies();
17514 +       uint64_t nsuptime;
17515 +
17516 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
17517 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
17518 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
17519 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
17520 +       cvirt->bias_ts.tv_sec = 0;
17521 +       cvirt->bias_ts.tv_nsec = 0;
17522 +
17523 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
17524 +       atomic_set(&cvirt->nr_threads, 0);
17525 +       atomic_set(&cvirt->nr_running, 0);
17526 +       atomic_set(&cvirt->nr_uninterruptible, 0);
17527 +       atomic_set(&cvirt->nr_onhold, 0);
17528 +
17529 +       spin_lock_init(&cvirt->load_lock);
17530 +       cvirt->load_last = jiffies;
17531 +       atomic_set(&cvirt->load_updates, 0);
17532 +       cvirt->load[0] = 0;
17533 +       cvirt->load[1] = 0;
17534 +       cvirt->load[2] = 0;
17535 +       atomic_set(&cvirt->total_forks, 0);
17536 +
17537 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
17538 +       init_waitqueue_head(&cvirt->syslog.log_wait);
17539 +       cvirt->syslog.log_start = 0;
17540 +       cvirt->syslog.log_end = 0;
17541 +       cvirt->syslog.con_start = 0;
17542 +       cvirt->syslog.logged_chars = 0;
17543 +}
17544 +
17545 +static inline
17546 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17547 +{
17548 +       // cvirt_pc->cpustat = { 0 };
17549 +}
17550 +
17551 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
17552 +{
17553 +#ifdef CONFIG_VSERVER_WARN
17554 +       int value;
17555 +#endif
17556 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
17557 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
17558 +               cvirt, value);
17559 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
17560 +               "!!! cvirt: %p[nr_running] = %d on exit.",
17561 +               cvirt, value);
17562 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
17563 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
17564 +               cvirt, value);
17565 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
17566 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
17567 +               cvirt, value);
17568 +       return;
17569 +}
17570 +
17571 +static inline
17572 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17573 +{
17574 +       return;
17575 +}
17576 +
17577 diff -NurpP --minimal linux-3.1.1/kernel/vserver/cvirt_proc.h linux-3.1.1-vs2.3.2/kernel/vserver/cvirt_proc.h
17578 --- linux-3.1.1/kernel/vserver/cvirt_proc.h     1970-01-01 01:00:00.000000000 +0100
17579 +++ linux-3.1.1-vs2.3.2/kernel/vserver/cvirt_proc.h     2011-10-24 18:53:33.000000000 +0200
17580 @@ -0,0 +1,135 @@
17581 +#ifndef _VX_CVIRT_PROC_H
17582 +#define _VX_CVIRT_PROC_H
17583 +
17584 +#include <linux/nsproxy.h>
17585 +#include <linux/mnt_namespace.h>
17586 +#include <linux/ipc_namespace.h>
17587 +#include <linux/utsname.h>
17588 +#include <linux/ipc.h>
17589 +
17590 +
17591 +static inline
17592 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17593 +{
17594 +       struct mnt_namespace *ns;
17595 +       struct uts_namespace *uts;
17596 +       struct ipc_namespace *ipc;
17597 +       struct path path;
17598 +       char *pstr, *root;
17599 +       int length = 0;
17600 +
17601 +       if (!nsproxy)
17602 +               goto out;
17603 +
17604 +       length += sprintf(buffer + length,
17605 +               "NSProxy:\t%p [%p,%p,%p]\n",
17606 +               nsproxy, nsproxy->mnt_ns,
17607 +               nsproxy->uts_ns, nsproxy->ipc_ns);
17608 +
17609 +       ns = nsproxy->mnt_ns;
17610 +       if (!ns)
17611 +               goto skip_ns;
17612 +
17613 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
17614 +       if (!pstr)
17615 +               goto skip_ns;
17616 +
17617 +       path.mnt = ns->root;
17618 +       path.dentry = ns->root->mnt_root;
17619 +       root = d_path(&path, pstr, PATH_MAX - 2);
17620 +       length += sprintf(buffer + length,
17621 +               "Namespace:\t%p [#%u]\n"
17622 +               "RootPath:\t%s\n",
17623 +               ns, atomic_read(&ns->count),
17624 +               root);
17625 +       kfree(pstr);
17626 +skip_ns:
17627 +
17628 +       uts = nsproxy->uts_ns;
17629 +       if (!uts)
17630 +               goto skip_uts;
17631 +
17632 +       length += sprintf(buffer + length,
17633 +               "SysName:\t%.*s\n"
17634 +               "NodeName:\t%.*s\n"
17635 +               "Release:\t%.*s\n"
17636 +               "Version:\t%.*s\n"
17637 +               "Machine:\t%.*s\n"
17638 +               "DomainName:\t%.*s\n",
17639 +               __NEW_UTS_LEN, uts->name.sysname,
17640 +               __NEW_UTS_LEN, uts->name.nodename,
17641 +               __NEW_UTS_LEN, uts->name.release,
17642 +               __NEW_UTS_LEN, uts->name.version,
17643 +               __NEW_UTS_LEN, uts->name.machine,
17644 +               __NEW_UTS_LEN, uts->name.domainname);
17645 +skip_uts:
17646 +
17647 +       ipc = nsproxy->ipc_ns;
17648 +       if (!ipc)
17649 +               goto skip_ipc;
17650 +
17651 +       length += sprintf(buffer + length,
17652 +               "SEMS:\t\t%d %d %d %d  %d\n"
17653 +               "MSG:\t\t%d %d %d\n"
17654 +               "SHM:\t\t%lu %lu  %d %d\n",
17655 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
17656 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
17657 +               ipc->used_sems,
17658 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17659 +               (unsigned long)ipc->shm_ctlmax,
17660 +               (unsigned long)ipc->shm_ctlall,
17661 +               ipc->shm_ctlmni, ipc->shm_tot);
17662 +skip_ipc:
17663 +out:
17664 +       return length;
17665 +}
17666 +
17667 +
17668 +#include <linux/sched.h>
17669 +
17670 +#define LOAD_INT(x) ((x) >> FSHIFT)
17671 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
17672 +
17673 +static inline
17674 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
17675 +{
17676 +       int length = 0;
17677 +       int a, b, c;
17678 +
17679 +       length += sprintf(buffer + length,
17680 +               "BiasUptime:\t%lu.%02lu\n",
17681 +               (unsigned long)cvirt->bias_uptime.tv_sec,
17682 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
17683 +
17684 +       a = cvirt->load[0] + (FIXED_1 / 200);
17685 +       b = cvirt->load[1] + (FIXED_1 / 200);
17686 +       c = cvirt->load[2] + (FIXED_1 / 200);
17687 +       length += sprintf(buffer + length,
17688 +               "nr_threads:\t%d\n"
17689 +               "nr_running:\t%d\n"
17690 +               "nr_unintr:\t%d\n"
17691 +               "nr_onhold:\t%d\n"
17692 +               "load_updates:\t%d\n"
17693 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
17694 +               "total_forks:\t%d\n",
17695 +               atomic_read(&cvirt->nr_threads),
17696 +               atomic_read(&cvirt->nr_running),
17697 +               atomic_read(&cvirt->nr_uninterruptible),
17698 +               atomic_read(&cvirt->nr_onhold),
17699 +               atomic_read(&cvirt->load_updates),
17700 +               LOAD_INT(a), LOAD_FRAC(a),
17701 +               LOAD_INT(b), LOAD_FRAC(b),
17702 +               LOAD_INT(c), LOAD_FRAC(c),
17703 +               atomic_read(&cvirt->total_forks));
17704 +       return length;
17705 +}
17706 +
17707 +static inline
17708 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
17709 +       char *buffer, int cpu)
17710 +{
17711 +       int length = 0;
17712 +       return length;
17713 +}
17714 +
17715 +#endif /* _VX_CVIRT_PROC_H */
17716 diff -NurpP --minimal linux-3.1.1/kernel/vserver/debug.c linux-3.1.1-vs2.3.2/kernel/vserver/debug.c
17717 --- linux-3.1.1/kernel/vserver/debug.c  1970-01-01 01:00:00.000000000 +0100
17718 +++ linux-3.1.1-vs2.3.2/kernel/vserver/debug.c  2011-10-24 18:53:33.000000000 +0200
17719 @@ -0,0 +1,32 @@
17720 +/*
17721 + *  kernel/vserver/debug.c
17722 + *
17723 + *  Copyright (C) 2005-2007 Herbert Pötzl
17724 + *
17725 + *  V0.01  vx_info dump support
17726 + *
17727 + */
17728 +
17729 +#include <linux/module.h>
17730 +
17731 +#include <linux/vserver/context.h>
17732 +
17733 +
17734 +void   dump_vx_info(struct vx_info *vxi, int level)
17735 +{
17736 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
17737 +               atomic_read(&vxi->vx_usecnt),
17738 +               atomic_read(&vxi->vx_tasks),
17739 +               vxi->vx_state);
17740 +       if (level > 0) {
17741 +               __dump_vx_limit(&vxi->limit);
17742 +               __dump_vx_sched(&vxi->sched);
17743 +               __dump_vx_cvirt(&vxi->cvirt);
17744 +               __dump_vx_cacct(&vxi->cacct);
17745 +       }
17746 +       printk("---\n");
17747 +}
17748 +
17749 +
17750 +EXPORT_SYMBOL_GPL(dump_vx_info);
17751 +
17752 diff -NurpP --minimal linux-3.1.1/kernel/vserver/device.c linux-3.1.1-vs2.3.2/kernel/vserver/device.c
17753 --- linux-3.1.1/kernel/vserver/device.c 1970-01-01 01:00:00.000000000 +0100
17754 +++ linux-3.1.1-vs2.3.2/kernel/vserver/device.c 2011-10-24 18:53:33.000000000 +0200
17755 @@ -0,0 +1,443 @@
17756 +/*
17757 + *  linux/kernel/vserver/device.c
17758 + *
17759 + *  Linux-VServer: Device Support
17760 + *
17761 + *  Copyright (C) 2006  Herbert Pötzl
17762 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
17763 + *
17764 + *  V0.01  device mapping basics
17765 + *  V0.02  added defaults
17766 + *
17767 + */
17768 +
17769 +#include <linux/slab.h>
17770 +#include <linux/rcupdate.h>
17771 +#include <linux/fs.h>
17772 +#include <linux/namei.h>
17773 +#include <linux/hash.h>
17774 +
17775 +#include <asm/errno.h>
17776 +#include <asm/uaccess.h>
17777 +#include <linux/vserver/base.h>
17778 +#include <linux/vserver/debug.h>
17779 +#include <linux/vserver/context.h>
17780 +#include <linux/vserver/device.h>
17781 +#include <linux/vserver/device_cmd.h>
17782 +
17783 +
17784 +#define DMAP_HASH_BITS 4
17785 +
17786 +
17787 +struct vs_mapping {
17788 +       union {
17789 +               struct hlist_node hlist;
17790 +               struct list_head list;
17791 +       } u;
17792 +#define dm_hlist       u.hlist
17793 +#define dm_list                u.list
17794 +       xid_t xid;
17795 +       dev_t device;
17796 +       struct vx_dmap_target target;
17797 +};
17798 +
17799 +
17800 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
17801 +
17802 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
17803 +
17804 +static struct vx_dmap_target dmap_defaults[2] = {
17805 +       { .flags = DATTR_OPEN },
17806 +       { .flags = DATTR_OPEN },
17807 +};
17808 +
17809 +
17810 +struct kmem_cache *dmap_cachep __read_mostly;
17811 +
17812 +int __init dmap_cache_init(void)
17813 +{
17814 +       dmap_cachep = kmem_cache_create("dmap_cache",
17815 +               sizeof(struct vs_mapping), 0,
17816 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
17817 +       return 0;
17818 +}
17819 +
17820 +__initcall(dmap_cache_init);
17821 +
17822 +
17823 +static inline unsigned int __hashval(dev_t dev, int bits)
17824 +{
17825 +       return hash_long((unsigned long)dev, bits);
17826 +}
17827 +
17828 +
17829 +/*     __hash_mapping()
17830 + *     add the mapping to the hash table
17831 + */
17832 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
17833 +{
17834 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17835 +       struct hlist_head *head, *hash = dmap_main_hash;
17836 +       int device = vdm->device;
17837 +
17838 +       spin_lock(hash_lock);
17839 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
17840 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
17841 +
17842 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
17843 +       hlist_add_head(&vdm->dm_hlist, head);
17844 +       spin_unlock(hash_lock);
17845 +}
17846 +
17847 +
17848 +static inline int __mode_to_default(umode_t mode)
17849 +{
17850 +       switch (mode) {
17851 +       case S_IFBLK:
17852 +               return 0;
17853 +       case S_IFCHR:
17854 +               return 1;
17855 +       default:
17856 +               BUG();
17857 +       }
17858 +}
17859 +
17860 +
17861 +/*     __set_default()
17862 + *     set a default
17863 + */
17864 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
17865 +       struct vx_dmap_target *vdmt)
17866 +{
17867 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17868 +       spin_lock(hash_lock);
17869 +
17870 +       if (vxi)
17871 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
17872 +       else
17873 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
17874 +
17875 +
17876 +       spin_unlock(hash_lock);
17877 +
17878 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
17879 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
17880 +}
17881 +
17882 +
17883 +/*     __remove_default()
17884 + *     remove a default
17885 + */
17886 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
17887 +{
17888 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17889 +       spin_lock(hash_lock);
17890 +
17891 +       if (vxi)
17892 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
17893 +       else    /* remove == reset */
17894 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
17895 +
17896 +       spin_unlock(hash_lock);
17897 +       return 0;
17898 +}
17899 +
17900 +
17901 +/*     __find_mapping()
17902 + *     find a mapping in the hash table
17903 + *
17904 + *     caller must hold hash_lock
17905 + */
17906 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
17907 +       struct vs_mapping **local, struct vs_mapping **global)
17908 +{
17909 +       struct hlist_head *hash = dmap_main_hash;
17910 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
17911 +       struct hlist_node *pos;
17912 +       struct vs_mapping *vdm;
17913 +
17914 +       *local = NULL;
17915 +       if (global)
17916 +               *global = NULL;
17917 +
17918 +       hlist_for_each(pos, head) {
17919 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
17920 +
17921 +               if ((vdm->device == device) &&
17922 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
17923 +                       if (vdm->xid == xid) {
17924 +                               *local = vdm;
17925 +                               return 1;
17926 +                       } else if (global && vdm->xid == 0)
17927 +                               *global = vdm;
17928 +               }
17929 +       }
17930 +
17931 +       if (global && *global)
17932 +               return 0;
17933 +       else
17934 +               return -ENOENT;
17935 +}
17936 +
17937 +
17938 +/*     __lookup_mapping()
17939 + *     find a mapping and store the result in target and flags
17940 + */
17941 +static inline int __lookup_mapping(struct vx_info *vxi,
17942 +       dev_t device, dev_t *target, int *flags, umode_t mode)
17943 +{
17944 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17945 +       struct vs_mapping *vdm, *global;
17946 +       struct vx_dmap_target *vdmt;
17947 +       int ret = 0;
17948 +       xid_t xid = vxi->vx_id;
17949 +       int index;
17950 +
17951 +       spin_lock(hash_lock);
17952 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
17953 +               ret = 1;
17954 +               vdmt = &vdm->target;
17955 +               goto found;
17956 +       }
17957 +
17958 +       index = __mode_to_default(mode);
17959 +       if (vxi && vxi->dmap.targets[index].flags) {
17960 +               ret = 2;
17961 +               vdmt = &vxi->dmap.targets[index];
17962 +       } else if (global) {
17963 +               ret = 3;
17964 +               vdmt = &global->target;
17965 +               goto found;
17966 +       } else {
17967 +               ret = 4;
17968 +               vdmt = &dmap_defaults[index];
17969 +       }
17970 +
17971 +found:
17972 +       if (target && (vdmt->flags & DATTR_REMAP))
17973 +               *target = vdmt->target;
17974 +       else if (target)
17975 +               *target = device;
17976 +       if (flags)
17977 +               *flags = vdmt->flags;
17978 +
17979 +       spin_unlock(hash_lock);
17980 +
17981 +       return ret;
17982 +}
17983 +
17984 +
17985 +/*     __remove_mapping()
17986 + *     remove a mapping from the hash table
17987 + */
17988 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
17989 +       umode_t mode)
17990 +{
17991 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17992 +       struct vs_mapping *vdm = NULL;
17993 +       int ret = 0;
17994 +
17995 +       spin_lock(hash_lock);
17996 +
17997 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
17998 +               NULL);
17999 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
18000 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
18001 +       if (ret < 0)
18002 +               goto out;
18003 +       hlist_del(&vdm->dm_hlist);
18004 +
18005 +out:
18006 +       spin_unlock(hash_lock);
18007 +       if (vdm)
18008 +               kmem_cache_free(dmap_cachep, vdm);
18009 +       return ret;
18010 +}
18011 +
18012 +
18013 +
18014 +int vs_map_device(struct vx_info *vxi,
18015 +       dev_t device, dev_t *target, umode_t mode)
18016 +{
18017 +       int ret, flags = DATTR_MASK;
18018 +
18019 +       if (!vxi) {
18020 +               if (target)
18021 +                       *target = device;
18022 +               goto out;
18023 +       }
18024 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
18025 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
18026 +               device, target ? *target : 0, flags, mode, ret);
18027 +out:
18028 +       return (flags & DATTR_MASK);
18029 +}
18030 +
18031 +
18032 +
18033 +static int do_set_mapping(struct vx_info *vxi,
18034 +       dev_t device, dev_t target, int flags, umode_t mode)
18035 +{
18036 +       if (device) {
18037 +               struct vs_mapping *new;
18038 +
18039 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
18040 +               if (!new)
18041 +                       return -ENOMEM;
18042 +
18043 +               INIT_HLIST_NODE(&new->dm_hlist);
18044 +               new->device = device;
18045 +               new->target.target = target;
18046 +               new->target.flags = flags | mode;
18047 +               new->xid = (vxi ? vxi->vx_id : 0);
18048 +
18049 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
18050 +               __hash_mapping(vxi, new);
18051 +       } else {
18052 +               struct vx_dmap_target new = {
18053 +                       .target = target,
18054 +                       .flags = flags | mode,
18055 +               };
18056 +               __set_default(vxi, mode, &new);
18057 +       }
18058 +       return 0;
18059 +}
18060 +
18061 +
18062 +static int do_unset_mapping(struct vx_info *vxi,
18063 +       dev_t device, dev_t target, int flags, umode_t mode)
18064 +{
18065 +       int ret = -EINVAL;
18066 +
18067 +       if (device) {
18068 +               ret = __remove_mapping(vxi, device, mode);
18069 +               if (ret < 0)
18070 +                       goto out;
18071 +       } else {
18072 +               ret = __remove_default(vxi, mode);
18073 +               if (ret < 0)
18074 +                       goto out;
18075 +       }
18076 +
18077 +out:
18078 +       return ret;
18079 +}
18080 +
18081 +
18082 +static inline int __user_device(const char __user *name, dev_t *dev,
18083 +       umode_t *mode)
18084 +{
18085 +       struct nameidata nd;
18086 +       int ret;
18087 +
18088 +       if (!name) {
18089 +               *dev = 0;
18090 +               return 0;
18091 +       }
18092 +       ret = user_lpath(name, &nd.path);
18093 +       if (ret)
18094 +               return ret;
18095 +       if (nd.path.dentry->d_inode) {
18096 +               *dev = nd.path.dentry->d_inode->i_rdev;
18097 +               *mode = nd.path.dentry->d_inode->i_mode;
18098 +       }
18099 +       path_put(&nd.path);
18100 +       return 0;
18101 +}
18102 +
18103 +static inline int __mapping_mode(dev_t device, dev_t target,
18104 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
18105 +{
18106 +       if (device)
18107 +               *mode = device_mode & S_IFMT;
18108 +       else if (target)
18109 +               *mode = target_mode & S_IFMT;
18110 +       else
18111 +               return -EINVAL;
18112 +
18113 +       /* if both given, device and target mode have to match */
18114 +       if (device && target &&
18115 +               ((device_mode ^ target_mode) & S_IFMT))
18116 +               return -EINVAL;
18117 +       return 0;
18118 +}
18119 +
18120 +
18121 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
18122 +       const char __user *target_path, int flags, int set)
18123 +{
18124 +       dev_t device = ~0, target = ~0;
18125 +       umode_t device_mode = 0, target_mode = 0, mode;
18126 +       int ret;
18127 +
18128 +       ret = __user_device(device_path, &device, &device_mode);
18129 +       if (ret)
18130 +               return ret;
18131 +       ret = __user_device(target_path, &target, &target_mode);
18132 +       if (ret)
18133 +               return ret;
18134 +
18135 +       ret = __mapping_mode(device, target,
18136 +               device_mode, target_mode, &mode);
18137 +       if (ret)
18138 +               return ret;
18139 +
18140 +       if (set)
18141 +               return do_set_mapping(vxi, device, target,
18142 +                       flags, mode);
18143 +       else
18144 +               return do_unset_mapping(vxi, device, target,
18145 +                       flags, mode);
18146 +}
18147 +
18148 +
18149 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
18150 +{
18151 +       struct vcmd_set_mapping_v0 vc_data;
18152 +
18153 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18154 +               return -EFAULT;
18155 +
18156 +       return do_mapping(vxi, vc_data.device, vc_data.target,
18157 +               vc_data.flags, 1);
18158 +}
18159 +
18160 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
18161 +{
18162 +       struct vcmd_set_mapping_v0 vc_data;
18163 +
18164 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18165 +               return -EFAULT;
18166 +
18167 +       return do_mapping(vxi, vc_data.device, vc_data.target,
18168 +               vc_data.flags, 0);
18169 +}
18170 +
18171 +
18172 +#ifdef CONFIG_COMPAT
18173 +
18174 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
18175 +{
18176 +       struct vcmd_set_mapping_v0_x32 vc_data;
18177 +
18178 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18179 +               return -EFAULT;
18180 +
18181 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
18182 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
18183 +}
18184 +
18185 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
18186 +{
18187 +       struct vcmd_set_mapping_v0_x32 vc_data;
18188 +
18189 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18190 +               return -EFAULT;
18191 +
18192 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
18193 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
18194 +}
18195 +
18196 +#endif /* CONFIG_COMPAT */
18197 +
18198 +
18199 diff -NurpP --minimal linux-3.1.1/kernel/vserver/dlimit.c linux-3.1.1-vs2.3.2/kernel/vserver/dlimit.c
18200 --- linux-3.1.1/kernel/vserver/dlimit.c 1970-01-01 01:00:00.000000000 +0100
18201 +++ linux-3.1.1-vs2.3.2/kernel/vserver/dlimit.c 2011-10-24 18:53:33.000000000 +0200
18202 @@ -0,0 +1,531 @@
18203 +/*
18204 + *  linux/kernel/vserver/dlimit.c
18205 + *
18206 + *  Virtual Server: Context Disk Limits
18207 + *
18208 + *  Copyright (C) 2004-2009  Herbert Pötzl
18209 + *
18210 + *  V0.01  initial version
18211 + *  V0.02  compat32 splitup
18212 + *  V0.03  extended interface
18213 + *
18214 + */
18215 +
18216 +#include <linux/statfs.h>
18217 +#include <linux/sched.h>
18218 +#include <linux/namei.h>
18219 +#include <linux/vs_tag.h>
18220 +#include <linux/vs_dlimit.h>
18221 +#include <linux/vserver/dlimit_cmd.h>
18222 +#include <linux/slab.h>
18223 +// #include <linux/gfp.h>
18224 +
18225 +#include <asm/uaccess.h>
18226 +
18227 +/*     __alloc_dl_info()
18228 +
18229 +       * allocate an initialized dl_info struct
18230 +       * doesn't make it visible (hash)                        */
18231 +
18232 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
18233 +{
18234 +       struct dl_info *new = NULL;
18235 +
18236 +       vxdprintk(VXD_CBIT(dlim, 5),
18237 +               "alloc_dl_info(%p,%d)*", sb, tag);
18238 +
18239 +       /* would this benefit from a slab cache? */
18240 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
18241 +       if (!new)
18242 +               return 0;
18243 +
18244 +       memset(new, 0, sizeof(struct dl_info));
18245 +       new->dl_tag = tag;
18246 +       new->dl_sb = sb;
18247 +       // INIT_RCU_HEAD(&new->dl_rcu);
18248 +       INIT_HLIST_NODE(&new->dl_hlist);
18249 +       spin_lock_init(&new->dl_lock);
18250 +       atomic_set(&new->dl_refcnt, 0);
18251 +       atomic_set(&new->dl_usecnt, 0);
18252 +
18253 +       /* rest of init goes here */
18254 +
18255 +       vxdprintk(VXD_CBIT(dlim, 4),
18256 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
18257 +       return new;
18258 +}
18259 +
18260 +/*     __dealloc_dl_info()
18261 +
18262 +       * final disposal of dl_info                             */
18263 +
18264 +static void __dealloc_dl_info(struct dl_info *dli)
18265 +{
18266 +       vxdprintk(VXD_CBIT(dlim, 4),
18267 +               "dealloc_dl_info(%p)", dli);
18268 +
18269 +       dli->dl_hlist.next = LIST_POISON1;
18270 +       dli->dl_tag = -1;
18271 +       dli->dl_sb = 0;
18272 +
18273 +       BUG_ON(atomic_read(&dli->dl_usecnt));
18274 +       BUG_ON(atomic_read(&dli->dl_refcnt));
18275 +
18276 +       kfree(dli);
18277 +}
18278 +
18279 +
18280 +/*     hash table for dl_info hash */
18281 +
18282 +#define DL_HASH_SIZE   13
18283 +
18284 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
18285 +
18286 +static DEFINE_SPINLOCK(dl_info_hash_lock);
18287 +
18288 +
18289 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
18290 +{
18291 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
18292 +}
18293 +
18294 +
18295 +
18296 +/*     __hash_dl_info()
18297 +
18298 +       * add the dli to the global hash table
18299 +       * requires the hash_lock to be held                     */
18300 +
18301 +static inline void __hash_dl_info(struct dl_info *dli)
18302 +{
18303 +       struct hlist_head *head;
18304 +
18305 +       vxdprintk(VXD_CBIT(dlim, 6),
18306 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
18307 +       get_dl_info(dli);
18308 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
18309 +       hlist_add_head_rcu(&dli->dl_hlist, head);
18310 +}
18311 +
18312 +/*     __unhash_dl_info()
18313 +
18314 +       * remove the dli from the global hash table
18315 +       * requires the hash_lock to be held                     */
18316 +
18317 +static inline void __unhash_dl_info(struct dl_info *dli)
18318 +{
18319 +       vxdprintk(VXD_CBIT(dlim, 6),
18320 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
18321 +       hlist_del_rcu(&dli->dl_hlist);
18322 +       put_dl_info(dli);
18323 +}
18324 +
18325 +
18326 +/*     __lookup_dl_info()
18327 +
18328 +       * requires the rcu_read_lock()
18329 +       * doesn't increment the dl_refcnt                       */
18330 +
18331 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
18332 +{
18333 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
18334 +       struct hlist_node *pos;
18335 +       struct dl_info *dli;
18336 +
18337 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
18338 +
18339 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
18340 +                       return dli;
18341 +               }
18342 +       }
18343 +       return NULL;
18344 +}
18345 +
18346 +
18347 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
18348 +{
18349 +       struct dl_info *dli;
18350 +
18351 +       rcu_read_lock();
18352 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
18353 +       vxdprintk(VXD_CBIT(dlim, 7),
18354 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
18355 +       rcu_read_unlock();
18356 +       return dli;
18357 +}
18358 +
18359 +void rcu_free_dl_info(struct rcu_head *head)
18360 +{
18361 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
18362 +       int usecnt, refcnt;
18363 +
18364 +       BUG_ON(!dli || !head);
18365 +
18366 +       usecnt = atomic_read(&dli->dl_usecnt);
18367 +       BUG_ON(usecnt < 0);
18368 +
18369 +       refcnt = atomic_read(&dli->dl_refcnt);
18370 +       BUG_ON(refcnt < 0);
18371 +
18372 +       vxdprintk(VXD_CBIT(dlim, 3),
18373 +               "rcu_free_dl_info(%p)", dli);
18374 +       if (!usecnt)
18375 +               __dealloc_dl_info(dli);
18376 +       else
18377 +               printk("!!! rcu didn't free\n");
18378 +}
18379 +
18380 +
18381 +
18382 +
18383 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
18384 +       uint32_t flags, int add)
18385 +{
18386 +       struct path path;
18387 +       int ret;
18388 +
18389 +       ret = user_lpath(name, &path);
18390 +       if (!ret) {
18391 +               struct super_block *sb;
18392 +               struct dl_info *dli;
18393 +
18394 +               ret = -EINVAL;
18395 +               if (!path.dentry->d_inode)
18396 +                       goto out_release;
18397 +               if (!(sb = path.dentry->d_inode->i_sb))
18398 +                       goto out_release;
18399 +
18400 +               if (add) {
18401 +                       dli = __alloc_dl_info(sb, id);
18402 +                       spin_lock(&dl_info_hash_lock);
18403 +
18404 +                       ret = -EEXIST;
18405 +                       if (__lookup_dl_info(sb, id))
18406 +                               goto out_unlock;
18407 +                       __hash_dl_info(dli);
18408 +                       dli = NULL;
18409 +               } else {
18410 +                       spin_lock(&dl_info_hash_lock);
18411 +                       dli = __lookup_dl_info(sb, id);
18412 +
18413 +                       ret = -ESRCH;
18414 +                       if (!dli)
18415 +                               goto out_unlock;
18416 +                       __unhash_dl_info(dli);
18417 +               }
18418 +               ret = 0;
18419 +       out_unlock:
18420 +               spin_unlock(&dl_info_hash_lock);
18421 +               if (add && dli)
18422 +                       __dealloc_dl_info(dli);
18423 +       out_release:
18424 +               path_put(&path);
18425 +       }
18426 +       return ret;
18427 +}
18428 +
18429 +int vc_add_dlimit(uint32_t id, void __user *data)
18430 +{
18431 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18432 +
18433 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18434 +               return -EFAULT;
18435 +
18436 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
18437 +}
18438 +
18439 +int vc_rem_dlimit(uint32_t id, void __user *data)
18440 +{
18441 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18442 +
18443 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18444 +               return -EFAULT;
18445 +
18446 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
18447 +}
18448 +
18449 +#ifdef CONFIG_COMPAT
18450 +
18451 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
18452 +{
18453 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18454 +
18455 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18456 +               return -EFAULT;
18457 +
18458 +       return do_addrem_dlimit(id,
18459 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
18460 +}
18461 +
18462 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
18463 +{
18464 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18465 +
18466 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18467 +               return -EFAULT;
18468 +
18469 +       return do_addrem_dlimit(id,
18470 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
18471 +}
18472 +
18473 +#endif /* CONFIG_COMPAT */
18474 +
18475 +
18476 +static inline
18477 +int do_set_dlimit(uint32_t id, const char __user *name,
18478 +       uint32_t space_used, uint32_t space_total,
18479 +       uint32_t inodes_used, uint32_t inodes_total,
18480 +       uint32_t reserved, uint32_t flags)
18481 +{
18482 +       struct path path;
18483 +       int ret;
18484 +
18485 +       ret = user_lpath(name, &path);
18486 +       if (!ret) {
18487 +               struct super_block *sb;
18488 +               struct dl_info *dli;
18489 +
18490 +               ret = -EINVAL;
18491 +               if (!path.dentry->d_inode)
18492 +                       goto out_release;
18493 +               if (!(sb = path.dentry->d_inode->i_sb))
18494 +                       goto out_release;
18495 +
18496 +               /* sanity checks */
18497 +               if ((reserved != CDLIM_KEEP &&
18498 +                       reserved > 100) ||
18499 +                       (inodes_used != CDLIM_KEEP &&
18500 +                       inodes_used > inodes_total) ||
18501 +                       (space_used != CDLIM_KEEP &&
18502 +                       space_used > space_total))
18503 +                       goto out_release;
18504 +
18505 +               ret = -ESRCH;
18506 +               dli = locate_dl_info(sb, id);
18507 +               if (!dli)
18508 +                       goto out_release;
18509 +
18510 +               spin_lock(&dli->dl_lock);
18511 +
18512 +               if (inodes_used != CDLIM_KEEP)
18513 +                       dli->dl_inodes_used = inodes_used;
18514 +               if (inodes_total != CDLIM_KEEP)
18515 +                       dli->dl_inodes_total = inodes_total;
18516 +               if (space_used != CDLIM_KEEP)
18517 +                       dli->dl_space_used = dlimit_space_32to64(
18518 +                               space_used, flags, DLIMS_USED);
18519 +
18520 +               if (space_total == CDLIM_INFINITY)
18521 +                       dli->dl_space_total = DLIM_INFINITY;
18522 +               else if (space_total != CDLIM_KEEP)
18523 +                       dli->dl_space_total = dlimit_space_32to64(
18524 +                               space_total, flags, DLIMS_TOTAL);
18525 +
18526 +               if (reserved != CDLIM_KEEP)
18527 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
18528 +
18529 +               spin_unlock(&dli->dl_lock);
18530 +
18531 +               put_dl_info(dli);
18532 +               ret = 0;
18533 +
18534 +       out_release:
18535 +               path_put(&path);
18536 +       }
18537 +       return ret;
18538 +}
18539 +
18540 +int vc_set_dlimit(uint32_t id, void __user *data)
18541 +{
18542 +       struct vcmd_ctx_dlimit_v0 vc_data;
18543 +
18544 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18545 +               return -EFAULT;
18546 +
18547 +       return do_set_dlimit(id, vc_data.name,
18548 +               vc_data.space_used, vc_data.space_total,
18549 +               vc_data.inodes_used, vc_data.inodes_total,
18550 +               vc_data.reserved, vc_data.flags);
18551 +}
18552 +
18553 +#ifdef CONFIG_COMPAT
18554 +
18555 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
18556 +{
18557 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18558 +
18559 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18560 +               return -EFAULT;
18561 +
18562 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
18563 +               vc_data.space_used, vc_data.space_total,
18564 +               vc_data.inodes_used, vc_data.inodes_total,
18565 +               vc_data.reserved, vc_data.flags);
18566 +}
18567 +
18568 +#endif /* CONFIG_COMPAT */
18569 +
18570 +
18571 +static inline
18572 +int do_get_dlimit(uint32_t id, const char __user *name,
18573 +       uint32_t *space_used, uint32_t *space_total,
18574 +       uint32_t *inodes_used, uint32_t *inodes_total,
18575 +       uint32_t *reserved, uint32_t *flags)
18576 +{
18577 +       struct path path;
18578 +       int ret;
18579 +
18580 +       ret = user_lpath(name, &path);
18581 +       if (!ret) {
18582 +               struct super_block *sb;
18583 +               struct dl_info *dli;
18584 +
18585 +               ret = -EINVAL;
18586 +               if (!path.dentry->d_inode)
18587 +                       goto out_release;
18588 +               if (!(sb = path.dentry->d_inode->i_sb))
18589 +                       goto out_release;
18590 +
18591 +               ret = -ESRCH;
18592 +               dli = locate_dl_info(sb, id);
18593 +               if (!dli)
18594 +                       goto out_release;
18595 +
18596 +               spin_lock(&dli->dl_lock);
18597 +               *inodes_used = dli->dl_inodes_used;
18598 +               *inodes_total = dli->dl_inodes_total;
18599 +
18600 +               *space_used = dlimit_space_64to32(
18601 +                       dli->dl_space_used, flags, DLIMS_USED);
18602 +
18603 +               if (dli->dl_space_total == DLIM_INFINITY)
18604 +                       *space_total = CDLIM_INFINITY;
18605 +               else
18606 +                       *space_total = dlimit_space_64to32(
18607 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
18608 +
18609 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18610 +               spin_unlock(&dli->dl_lock);
18611 +
18612 +               put_dl_info(dli);
18613 +               ret = -EFAULT;
18614 +
18615 +               ret = 0;
18616 +       out_release:
18617 +               path_put(&path);
18618 +       }
18619 +       return ret;
18620 +}
18621 +
18622 +
18623 +int vc_get_dlimit(uint32_t id, void __user *data)
18624 +{
18625 +       struct vcmd_ctx_dlimit_v0 vc_data;
18626 +       int ret;
18627 +
18628 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18629 +               return -EFAULT;
18630 +
18631 +       ret = do_get_dlimit(id, vc_data.name,
18632 +               &vc_data.space_used, &vc_data.space_total,
18633 +               &vc_data.inodes_used, &vc_data.inodes_total,
18634 +               &vc_data.reserved, &vc_data.flags);
18635 +       if (ret)
18636 +               return ret;
18637 +
18638 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18639 +               return -EFAULT;
18640 +       return 0;
18641 +}
18642 +
18643 +#ifdef CONFIG_COMPAT
18644 +
18645 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18646 +{
18647 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18648 +       int ret;
18649 +
18650 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18651 +               return -EFAULT;
18652 +
18653 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18654 +               &vc_data.space_used, &vc_data.space_total,
18655 +               &vc_data.inodes_used, &vc_data.inodes_total,
18656 +               &vc_data.reserved, &vc_data.flags);
18657 +       if (ret)
18658 +               return ret;
18659 +
18660 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18661 +               return -EFAULT;
18662 +       return 0;
18663 +}
18664 +
18665 +#endif /* CONFIG_COMPAT */
18666 +
18667 +
18668 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
18669 +{
18670 +       struct dl_info *dli;
18671 +       __u64 blimit, bfree, bavail;
18672 +       __u32 ifree;
18673 +
18674 +       dli = locate_dl_info(sb, dx_current_tag());
18675 +       if (!dli)
18676 +               return;
18677 +
18678 +       spin_lock(&dli->dl_lock);
18679 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
18680 +               goto no_ilim;
18681 +
18682 +       /* reduce max inodes available to limit */
18683 +       if (buf->f_files > dli->dl_inodes_total)
18684 +               buf->f_files = dli->dl_inodes_total;
18685 +
18686 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
18687 +       /* reduce free inodes to min */
18688 +       if (ifree < buf->f_ffree)
18689 +               buf->f_ffree = ifree;
18690 +
18691 +no_ilim:
18692 +       if (dli->dl_space_total == DLIM_INFINITY)
18693 +               goto no_blim;
18694 +
18695 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
18696 +
18697 +       if (dli->dl_space_total < dli->dl_space_used)
18698 +               bfree = 0;
18699 +       else
18700 +               bfree = (dli->dl_space_total - dli->dl_space_used)
18701 +                       >> sb->s_blocksize_bits;
18702 +
18703 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
18704 +       if (bavail < dli->dl_space_used)
18705 +               bavail = 0;
18706 +       else
18707 +               bavail = (bavail - dli->dl_space_used)
18708 +                       >> sb->s_blocksize_bits;
18709 +
18710 +       /* reduce max space available to limit */
18711 +       if (buf->f_blocks > blimit)
18712 +               buf->f_blocks = blimit;
18713 +
18714 +       /* reduce free space to min */
18715 +       if (bfree < buf->f_bfree)
18716 +               buf->f_bfree = bfree;
18717 +
18718 +       /* reduce avail space to min */
18719 +       if (bavail < buf->f_bavail)
18720 +               buf->f_bavail = bavail;
18721 +
18722 +no_blim:
18723 +       spin_unlock(&dli->dl_lock);
18724 +       put_dl_info(dli);
18725 +
18726 +       return;
18727 +}
18728 +
18729 +#include <linux/module.h>
18730 +
18731 +EXPORT_SYMBOL_GPL(locate_dl_info);
18732 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
18733 +
18734 diff -NurpP --minimal linux-3.1.1/kernel/vserver/helper.c linux-3.1.1-vs2.3.2/kernel/vserver/helper.c
18735 --- linux-3.1.1/kernel/vserver/helper.c 1970-01-01 01:00:00.000000000 +0100
18736 +++ linux-3.1.1-vs2.3.2/kernel/vserver/helper.c 2011-10-24 18:53:33.000000000 +0200
18737 @@ -0,0 +1,223 @@
18738 +/*
18739 + *  linux/kernel/vserver/helper.c
18740 + *
18741 + *  Virtual Context Support
18742 + *
18743 + *  Copyright (C) 2004-2007  Herbert Pötzl
18744 + *
18745 + *  V0.01  basic helper
18746 + *
18747 + */
18748 +
18749 +#include <linux/kmod.h>
18750 +#include <linux/reboot.h>
18751 +#include <linux/vs_context.h>
18752 +#include <linux/vs_network.h>
18753 +#include <linux/vserver/signal.h>
18754 +
18755 +
18756 +char vshelper_path[255] = "/sbin/vshelper";
18757 +
18758 +
18759 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
18760 +{
18761 +       int ret;
18762 +
18763 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
18764 +               printk( KERN_WARNING
18765 +                       "%s: (%s %s) returned %s with %d\n",
18766 +                       name, argv[1], argv[2],
18767 +                       sync ? "sync" : "async", ret);
18768 +       }
18769 +       vxdprintk(VXD_CBIT(switch, 4),
18770 +               "%s: (%s %s) returned %s with %d",
18771 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
18772 +       return ret;
18773 +}
18774 +
18775 +/*
18776 + *      vshelper path is set via /proc/sys
18777 + *      invoked by vserver sys_reboot(), with
18778 + *      the following arguments
18779 + *
18780 + *      argv [0] = vshelper_path;
18781 + *      argv [1] = action: "restart", "halt", "poweroff", ...
18782 + *      argv [2] = context identifier
18783 + *
18784 + *      envp [*] = type-specific parameters
18785 + */
18786 +
18787 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
18788 +{
18789 +       char id_buf[8], cmd_buf[16];
18790 +       char uid_buf[16], pid_buf[16];
18791 +       int ret;
18792 +
18793 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18794 +       char *envp[] = {"HOME=/", "TERM=linux",
18795 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
18796 +                       uid_buf, pid_buf, cmd_buf, 0};
18797 +
18798 +       if (vx_info_state(vxi, VXS_HELPER))
18799 +               return -EAGAIN;
18800 +       vxi->vx_state |= VXS_HELPER;
18801 +
18802 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
18803 +
18804 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
18805 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current_uid());
18806 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
18807 +
18808 +       switch (cmd) {
18809 +       case LINUX_REBOOT_CMD_RESTART:
18810 +               argv[1] = "restart";
18811 +               break;
18812 +
18813 +       case LINUX_REBOOT_CMD_HALT:
18814 +               argv[1] = "halt";
18815 +               break;
18816 +
18817 +       case LINUX_REBOOT_CMD_POWER_OFF:
18818 +               argv[1] = "poweroff";
18819 +               break;
18820 +
18821 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
18822 +               argv[1] = "swsusp";
18823 +               break;
18824 +
18825 +       case LINUX_REBOOT_CMD_OOM:
18826 +               argv[1] = "oom";
18827 +               break;
18828 +
18829 +       default:
18830 +               vxi->vx_state &= ~VXS_HELPER;
18831 +               return 0;
18832 +       }
18833 +
18834 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
18835 +       vxi->vx_state &= ~VXS_HELPER;
18836 +       __wakeup_vx_info(vxi);
18837 +       return (ret) ? -EPERM : 0;
18838 +}
18839 +
18840 +
18841 +long vs_reboot(unsigned int cmd, void __user *arg)
18842 +{
18843 +       struct vx_info *vxi = current_vx_info();
18844 +       long ret = 0;
18845 +
18846 +       vxdprintk(VXD_CBIT(misc, 5),
18847 +               "vs_reboot(%p[#%d],%u)",
18848 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18849 +
18850 +       ret = vs_reboot_helper(vxi, cmd, arg);
18851 +       if (ret)
18852 +               return ret;
18853 +
18854 +       vxi->reboot_cmd = cmd;
18855 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18856 +               switch (cmd) {
18857 +               case LINUX_REBOOT_CMD_RESTART:
18858 +               case LINUX_REBOOT_CMD_HALT:
18859 +               case LINUX_REBOOT_CMD_POWER_OFF:
18860 +                       vx_info_kill(vxi, 0, SIGKILL);
18861 +                       vx_info_kill(vxi, 1, SIGKILL);
18862 +               default:
18863 +                       break;
18864 +               }
18865 +       }
18866 +       return 0;
18867 +}
18868 +
18869 +long vs_oom_action(unsigned int cmd)
18870 +{
18871 +       struct vx_info *vxi = current_vx_info();
18872 +       long ret = 0;
18873 +
18874 +       vxdprintk(VXD_CBIT(misc, 5),
18875 +               "vs_oom_action(%p[#%d],%u)",
18876 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18877 +
18878 +       ret = vs_reboot_helper(vxi, cmd, NULL);
18879 +       if (ret)
18880 +               return ret;
18881 +
18882 +       vxi->reboot_cmd = cmd;
18883 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18884 +               vx_info_kill(vxi, 0, SIGKILL);
18885 +               vx_info_kill(vxi, 1, SIGKILL);
18886 +       }
18887 +       return 0;
18888 +}
18889 +
18890 +/*
18891 + *      argv [0] = vshelper_path;
18892 + *      argv [1] = action: "startup", "shutdown"
18893 + *      argv [2] = context identifier
18894 + *
18895 + *      envp [*] = type-specific parameters
18896 + */
18897 +
18898 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
18899 +{
18900 +       char id_buf[8], cmd_buf[16];
18901 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18902 +       char *envp[] = {"HOME=/", "TERM=linux",
18903 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18904 +
18905 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
18906 +               return 0;
18907 +
18908 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
18909 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
18910 +
18911 +       switch (cmd) {
18912 +       case VSC_STARTUP:
18913 +               argv[1] = "startup";
18914 +               break;
18915 +       case VSC_SHUTDOWN:
18916 +               argv[1] = "shutdown";
18917 +               break;
18918 +       default:
18919 +               return 0;
18920 +       }
18921 +
18922 +       return do_vshelper(vshelper_path, argv, envp, 1);
18923 +}
18924 +
18925 +
18926 +/*
18927 + *      argv [0] = vshelper_path;
18928 + *      argv [1] = action: "netup", "netdown"
18929 + *      argv [2] = context identifier
18930 + *
18931 + *      envp [*] = type-specific parameters
18932 + */
18933 +
18934 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
18935 +{
18936 +       char id_buf[8], cmd_buf[16];
18937 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18938 +       char *envp[] = {"HOME=/", "TERM=linux",
18939 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18940 +
18941 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
18942 +               return 0;
18943 +
18944 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
18945 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
18946 +
18947 +       switch (cmd) {
18948 +       case VSC_NETUP:
18949 +               argv[1] = "netup";
18950 +               break;
18951 +       case VSC_NETDOWN:
18952 +               argv[1] = "netdown";
18953 +               break;
18954 +       default:
18955 +               return 0;
18956 +       }
18957 +
18958 +       return do_vshelper(vshelper_path, argv, envp, 1);
18959 +}
18960 +
18961 diff -NurpP --minimal linux-3.1.1/kernel/vserver/history.c linux-3.1.1-vs2.3.2/kernel/vserver/history.c
18962 --- linux-3.1.1/kernel/vserver/history.c        1970-01-01 01:00:00.000000000 +0100
18963 +++ linux-3.1.1-vs2.3.2/kernel/vserver/history.c        2011-10-24 18:53:33.000000000 +0200
18964 @@ -0,0 +1,258 @@
18965 +/*
18966 + *  kernel/vserver/history.c
18967 + *
18968 + *  Virtual Context History Backtrace
18969 + *
18970 + *  Copyright (C) 2004-2007  Herbert Pötzl
18971 + *
18972 + *  V0.01  basic structure
18973 + *  V0.02  hash/unhash and trace
18974 + *  V0.03  preemption fixes
18975 + *
18976 + */
18977 +
18978 +#include <linux/module.h>
18979 +#include <asm/uaccess.h>
18980 +
18981 +#include <linux/vserver/context.h>
18982 +#include <linux/vserver/debug.h>
18983 +#include <linux/vserver/debug_cmd.h>
18984 +#include <linux/vserver/history.h>
18985 +
18986 +
18987 +#ifdef CONFIG_VSERVER_HISTORY
18988 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
18989 +#else
18990 +#define VXH_SIZE       64
18991 +#endif
18992 +
18993 +struct _vx_history {
18994 +       unsigned int counter;
18995 +
18996 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
18997 +};
18998 +
18999 +
19000 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
19001 +
19002 +unsigned volatile int vxh_active = 1;
19003 +
19004 +static atomic_t sequence = ATOMIC_INIT(0);
19005 +
19006 +
19007 +/*     vxh_advance()
19008 +
19009 +       * requires disabled preemption                          */
19010 +
19011 +struct _vx_hist_entry *vxh_advance(void *loc)
19012 +{
19013 +       unsigned int cpu = smp_processor_id();
19014 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
19015 +       struct _vx_hist_entry *entry;
19016 +       unsigned int index;
19017 +
19018 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
19019 +       entry = &hist->entry[index];
19020 +
19021 +       entry->seq = atomic_inc_return(&sequence);
19022 +       entry->loc = loc;
19023 +       return entry;
19024 +}
19025 +
19026 +EXPORT_SYMBOL_GPL(vxh_advance);
19027 +
19028 +
19029 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
19030 +
19031 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
19032 +
19033 +
19034 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
19035 +
19036 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
19037 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
19038 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
19039 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
19040 +
19041 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
19042 +{
19043 +       switch (e->type) {
19044 +       case VXH_THROW_OOPS:
19045 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
19046 +               break;
19047 +
19048 +       case VXH_GET_VX_INFO:
19049 +       case VXH_PUT_VX_INFO:
19050 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
19051 +                       VXH_LOC_ARGS(e),
19052 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
19053 +                       VXH_VXI_ARGS(e));
19054 +               break;
19055 +
19056 +       case VXH_INIT_VX_INFO:
19057 +       case VXH_SET_VX_INFO:
19058 +       case VXH_CLR_VX_INFO:
19059 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
19060 +                       VXH_LOC_ARGS(e),
19061 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
19062 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
19063 +                       VXH_VXI_ARGS(e), e->sc.data);
19064 +               break;
19065 +
19066 +       case VXH_CLAIM_VX_INFO:
19067 +       case VXH_RELEASE_VX_INFO:
19068 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
19069 +                       VXH_LOC_ARGS(e),
19070 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
19071 +                       VXH_VXI_ARGS(e), e->sc.data);
19072 +               break;
19073 +
19074 +       case VXH_ALLOC_VX_INFO:
19075 +       case VXH_DEALLOC_VX_INFO:
19076 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
19077 +                       VXH_LOC_ARGS(e),
19078 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
19079 +                       VXH_VXI_ARGS(e));
19080 +               break;
19081 +
19082 +       case VXH_HASH_VX_INFO:
19083 +       case VXH_UNHASH_VX_INFO:
19084 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
19085 +                       VXH_LOC_ARGS(e),
19086 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
19087 +                       VXH_VXI_ARGS(e));
19088 +               break;
19089 +
19090 +       case VXH_LOC_VX_INFO:
19091 +       case VXH_LOOKUP_VX_INFO:
19092 +       case VXH_CREATE_VX_INFO:
19093 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
19094 +                       VXH_LOC_ARGS(e),
19095 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
19096 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
19097 +                       e->ll.arg, VXH_VXI_ARGS(e));
19098 +               break;
19099 +       }
19100 +}
19101 +
19102 +static void __vxh_dump_history(void)
19103 +{
19104 +       unsigned int i, cpu;
19105 +
19106 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
19107 +               atomic_read(&sequence), NR_CPUS);
19108 +
19109 +       for (i = 0; i < VXH_SIZE; i++) {
19110 +               for_each_online_cpu(cpu) {
19111 +                       struct _vx_history *hist =
19112 +                               &per_cpu(vx_history_buffer, cpu);
19113 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
19114 +                       struct _vx_hist_entry *entry = &hist->entry[index];
19115 +
19116 +                       vxh_dump_entry(entry, cpu);
19117 +               }
19118 +       }
19119 +}
19120 +
19121 +void   vxh_dump_history(void)
19122 +{
19123 +       vxh_active = 0;
19124 +#ifdef CONFIG_SMP
19125 +       local_irq_enable();
19126 +       smp_send_stop();
19127 +       local_irq_disable();
19128 +#endif
19129 +       __vxh_dump_history();
19130 +}
19131 +
19132 +
19133 +/* vserver syscall commands below here */
19134 +
19135 +
19136 +int vc_dump_history(uint32_t id)
19137 +{
19138 +       vxh_active = 0;
19139 +       __vxh_dump_history();
19140 +       vxh_active = 1;
19141 +
19142 +       return 0;
19143 +}
19144 +
19145 +
19146 +int do_read_history(struct __user _vx_hist_entry *data,
19147 +       int cpu, uint32_t *index, uint32_t *count)
19148 +{
19149 +       int pos, ret = 0;
19150 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
19151 +       int end = hist->counter;
19152 +       int start = end - VXH_SIZE + 2;
19153 +       int idx = *index;
19154 +
19155 +       /* special case: get current pos */
19156 +       if (!*count) {
19157 +               *index = end;
19158 +               return 0;
19159 +       }
19160 +
19161 +       /* have we lost some data? */
19162 +       if (idx < start)
19163 +               idx = start;
19164 +
19165 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
19166 +               struct _vx_hist_entry *entry =
19167 +                       &hist->entry[idx % VXH_SIZE];
19168 +
19169 +               /* send entry to userspace */
19170 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
19171 +               if (ret)
19172 +                       break;
19173 +       }
19174 +       /* save new index and count */
19175 +       *index = idx;
19176 +       *count = pos;
19177 +       return ret ? ret : (*index < end);
19178 +}
19179 +
19180 +int vc_read_history(uint32_t id, void __user *data)
19181 +{
19182 +       struct vcmd_read_history_v0 vc_data;
19183 +       int ret;
19184 +
19185 +       if (id >= NR_CPUS)
19186 +               return -EINVAL;
19187 +
19188 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19189 +               return -EFAULT;
19190 +
19191 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
19192 +               id, &vc_data.index, &vc_data.count);
19193 +
19194 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19195 +               return -EFAULT;
19196 +       return ret;
19197 +}
19198 +
19199 +#ifdef CONFIG_COMPAT
19200 +
19201 +int vc_read_history_x32(uint32_t id, void __user *data)
19202 +{
19203 +       struct vcmd_read_history_v0_x32 vc_data;
19204 +       int ret;
19205 +
19206 +       if (id >= NR_CPUS)
19207 +               return -EINVAL;
19208 +
19209 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19210 +               return -EFAULT;
19211 +
19212 +       ret = do_read_history((struct __user _vx_hist_entry *)
19213 +               compat_ptr(vc_data.data_ptr),
19214 +               id, &vc_data.index, &vc_data.count);
19215 +
19216 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19217 +               return -EFAULT;
19218 +       return ret;
19219 +}
19220 +
19221 +#endif /* CONFIG_COMPAT */
19222 +
19223 diff -NurpP --minimal linux-3.1.1/kernel/vserver/inet.c linux-3.1.1-vs2.3.2/kernel/vserver/inet.c
19224 --- linux-3.1.1/kernel/vserver/inet.c   1970-01-01 01:00:00.000000000 +0100
19225 +++ linux-3.1.1-vs2.3.2/kernel/vserver/inet.c   2011-10-24 18:53:33.000000000 +0200
19226 @@ -0,0 +1,225 @@
19227 +
19228 +#include <linux/in.h>
19229 +#include <linux/inetdevice.h>
19230 +#include <linux/vs_inet.h>
19231 +#include <linux/vs_inet6.h>
19232 +#include <linux/vserver/debug.h>
19233 +#include <net/route.h>
19234 +#include <net/addrconf.h>
19235 +
19236 +
19237 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19238 +{
19239 +       int ret = 0;
19240 +
19241 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19242 +               ret = 1;
19243 +       else {
19244 +               struct nx_addr_v4 *ptr;
19245 +
19246 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
19247 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19248 +                               ret = 1;
19249 +                               break;
19250 +                       }
19251 +               }
19252 +       }
19253 +
19254 +       vxdprintk(VXD_CBIT(net, 2),
19255 +               "nx_v4_addr_conflict(%p,%p): %d",
19256 +               nxi1, nxi2, ret);
19257 +
19258 +       return ret;
19259 +}
19260 +
19261 +
19262 +#ifdef CONFIG_IPV6
19263 +
19264 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19265 +{
19266 +       int ret = 0;
19267 +
19268 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19269 +               ret = 1;
19270 +       else {
19271 +               struct nx_addr_v6 *ptr;
19272 +
19273 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
19274 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19275 +                               ret = 1;
19276 +                               break;
19277 +                       }
19278 +               }
19279 +       }
19280 +
19281 +       vxdprintk(VXD_CBIT(net, 2),
19282 +               "nx_v6_addr_conflict(%p,%p): %d",
19283 +               nxi1, nxi2, ret);
19284 +
19285 +       return ret;
19286 +}
19287 +
19288 +#endif
19289 +
19290 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19291 +{
19292 +       struct in_device *in_dev;
19293 +       struct in_ifaddr **ifap;
19294 +       struct in_ifaddr *ifa;
19295 +       int ret = 0;
19296 +
19297 +       if (!dev)
19298 +               goto out;
19299 +       in_dev = in_dev_get(dev);
19300 +       if (!in_dev)
19301 +               goto out;
19302 +
19303 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
19304 +               ifap = &ifa->ifa_next) {
19305 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
19306 +                       ret = 1;
19307 +                       break;
19308 +               }
19309 +       }
19310 +       in_dev_put(in_dev);
19311 +out:
19312 +       return ret;
19313 +}
19314 +
19315 +
19316 +#ifdef CONFIG_IPV6
19317 +
19318 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19319 +{
19320 +       struct inet6_dev *in_dev;
19321 +       struct inet6_ifaddr *ifa;
19322 +       int ret = 0;
19323 +
19324 +       if (!dev)
19325 +               goto out;
19326 +       in_dev = in6_dev_get(dev);
19327 +       if (!in_dev)
19328 +               goto out;
19329 +
19330 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
19331 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
19332 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
19333 +                       ret = 1;
19334 +                       break;
19335 +               }
19336 +       }
19337 +       in6_dev_put(in_dev);
19338 +out:
19339 +       return ret;
19340 +}
19341 +
19342 +#endif
19343 +
19344 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19345 +{
19346 +       int ret = 1;
19347 +
19348 +       if (!nxi)
19349 +               goto out;
19350 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
19351 +               goto out;
19352 +#ifdef CONFIG_IPV6
19353 +       ret = 2;
19354 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
19355 +               goto out;
19356 +#endif
19357 +       ret = 0;
19358 +out:
19359 +       vxdprintk(VXD_CBIT(net, 3),
19360 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
19361 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
19362 +       return ret;
19363 +}
19364 +
19365 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
19366 +       struct flowi4 *fl4)
19367 +{
19368 +       struct rtable *rt;
19369 +
19370 +       if (!nxi)
19371 +               return NULL;
19372 +
19373 +       /* FIXME: handle lback only case */
19374 +       if (!NX_IPV4(nxi))
19375 +               return ERR_PTR(-EPERM);
19376 +
19377 +       vxdprintk(VXD_CBIT(net, 4),
19378 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
19379 +               nxi, nxi ? nxi->nx_id : 0,
19380 +               NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
19381 +
19382 +       /* single IP is unconditional */
19383 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
19384 +               (fl4->saddr == INADDR_ANY))
19385 +               fl4->saddr = nxi->v4.ip[0].s_addr;
19386 +
19387 +       if (fl4->saddr == INADDR_ANY) {
19388 +               struct nx_addr_v4 *ptr;
19389 +               __be32 found = 0;
19390 +
19391 +               rt = __ip_route_output_key(net, fl4);
19392 +               if (!IS_ERR(rt)) {
19393 +                       found = fl4->saddr;
19394 +                       ip_rt_put(rt);
19395 +                       vxdprintk(VXD_CBIT(net, 4),
19396 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19397 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
19398 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
19399 +                               goto found;
19400 +               }
19401 +
19402 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
19403 +                       __be32 primary = ptr->ip[0].s_addr;
19404 +                       __be32 mask = ptr->mask.s_addr;
19405 +                       __be32 neta = primary & mask;
19406 +
19407 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
19408 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
19409 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
19410 +                               NIPQUAD(mask), NIPQUAD(neta));
19411 +                       if ((found & mask) != neta)
19412 +                               continue;
19413 +
19414 +                       fl4->saddr = primary;
19415 +                       rt = __ip_route_output_key(net, fl4);
19416 +                       vxdprintk(VXD_CBIT(net, 4),
19417 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19418 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
19419 +                       if (!IS_ERR(rt)) {
19420 +                               found = fl4->saddr;
19421 +                               ip_rt_put(rt);
19422 +                               if (found == primary)
19423 +                                       goto found;
19424 +                       }
19425 +               }
19426 +               /* still no source ip? */
19427 +               found = ipv4_is_loopback(fl4->daddr)
19428 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
19429 +       found:
19430 +               /* assign src ip to flow */
19431 +               fl4->saddr = found;
19432 +
19433 +       } else {
19434 +               if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
19435 +                       return ERR_PTR(-EPERM);
19436 +       }
19437 +
19438 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
19439 +               if (ipv4_is_loopback(fl4->daddr))
19440 +                       fl4->daddr = nxi->v4_lback.s_addr;
19441 +               if (ipv4_is_loopback(fl4->saddr))
19442 +                       fl4->saddr = nxi->v4_lback.s_addr;
19443 +       } else if (ipv4_is_loopback(fl4->daddr) &&
19444 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
19445 +               return ERR_PTR(-EPERM);
19446 +
19447 +       return NULL;
19448 +}
19449 +
19450 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
19451 +
19452 diff -NurpP --minimal linux-3.1.1/kernel/vserver/init.c linux-3.1.1-vs2.3.2/kernel/vserver/init.c
19453 --- linux-3.1.1/kernel/vserver/init.c   1970-01-01 01:00:00.000000000 +0100
19454 +++ linux-3.1.1-vs2.3.2/kernel/vserver/init.c   2011-10-24 18:53:33.000000000 +0200
19455 @@ -0,0 +1,45 @@
19456 +/*
19457 + *  linux/kernel/init.c
19458 + *
19459 + *  Virtual Server Init
19460 + *
19461 + *  Copyright (C) 2004-2007  Herbert Pötzl
19462 + *
19463 + *  V0.01  basic structure
19464 + *
19465 + */
19466 +
19467 +#include <linux/init.h>
19468 +
19469 +int    vserver_register_sysctl(void);
19470 +void   vserver_unregister_sysctl(void);
19471 +
19472 +
19473 +static int __init init_vserver(void)
19474 +{
19475 +       int ret = 0;
19476 +
19477 +#ifdef CONFIG_VSERVER_DEBUG
19478 +       vserver_register_sysctl();
19479 +#endif
19480 +       return ret;
19481 +}
19482 +
19483 +
19484 +static void __exit exit_vserver(void)
19485 +{
19486 +
19487 +#ifdef CONFIG_VSERVER_DEBUG
19488 +       vserver_unregister_sysctl();
19489 +#endif
19490 +       return;
19491 +}
19492 +
19493 +/* FIXME: GFP_ZONETYPES gone
19494 +long vx_slab[GFP_ZONETYPES]; */
19495 +long vx_area;
19496 +
19497 +
19498 +module_init(init_vserver);
19499 +module_exit(exit_vserver);
19500 +
19501 diff -NurpP --minimal linux-3.1.1/kernel/vserver/inode.c linux-3.1.1-vs2.3.2/kernel/vserver/inode.c
19502 --- linux-3.1.1/kernel/vserver/inode.c  1970-01-01 01:00:00.000000000 +0100
19503 +++ linux-3.1.1-vs2.3.2/kernel/vserver/inode.c  2011-10-24 18:53:33.000000000 +0200
19504 @@ -0,0 +1,437 @@
19505 +/*
19506 + *  linux/kernel/vserver/inode.c
19507 + *
19508 + *  Virtual Server: File System Support
19509 + *
19510 + *  Copyright (C) 2004-2007  Herbert Pötzl
19511 + *
19512 + *  V0.01  separated from vcontext V0.05
19513 + *  V0.02  moved to tag (instead of xid)
19514 + *
19515 + */
19516 +
19517 +#include <linux/tty.h>
19518 +#include <linux/proc_fs.h>
19519 +#include <linux/devpts_fs.h>
19520 +#include <linux/fs.h>
19521 +#include <linux/file.h>
19522 +#include <linux/mount.h>
19523 +#include <linux/parser.h>
19524 +#include <linux/namei.h>
19525 +#include <linux/vserver/inode.h>
19526 +#include <linux/vserver/inode_cmd.h>
19527 +#include <linux/vs_base.h>
19528 +#include <linux/vs_tag.h>
19529 +
19530 +#include <asm/uaccess.h>
19531 +
19532 +
19533 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19534 +{
19535 +       struct proc_dir_entry *entry;
19536 +
19537 +       if (!in || !in->i_sb)
19538 +               return -ESRCH;
19539 +
19540 +       *flags = IATTR_TAG
19541 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
19542 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
19543 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
19544 +               | (IS_COW(in) ? IATTR_COW : 0);
19545 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
19546 +
19547 +       if (S_ISDIR(in->i_mode))
19548 +               *mask |= IATTR_BARRIER;
19549 +
19550 +       if (IS_TAGGED(in)) {
19551 +               *tag = in->i_tag;
19552 +               *mask |= IATTR_TAG;
19553 +       }
19554 +
19555 +       switch (in->i_sb->s_magic) {
19556 +       case PROC_SUPER_MAGIC:
19557 +               entry = PROC_I(in)->pde;
19558 +
19559 +               /* check for specific inodes? */
19560 +               if (entry)
19561 +                       *mask |= IATTR_FLAGS;
19562 +               if (entry)
19563 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
19564 +               else
19565 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19566 +               break;
19567 +
19568 +       case DEVPTS_SUPER_MAGIC:
19569 +               *tag = in->i_tag;
19570 +               *mask |= IATTR_TAG;
19571 +               break;
19572 +
19573 +       default:
19574 +               break;
19575 +       }
19576 +       return 0;
19577 +}
19578 +
19579 +int vc_get_iattr(void __user *data)
19580 +{
19581 +       struct path path;
19582 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19583 +       int ret;
19584 +
19585 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19586 +               return -EFAULT;
19587 +
19588 +       ret = user_lpath(vc_data.name, &path);
19589 +       if (!ret) {
19590 +               ret = __vc_get_iattr(path.dentry->d_inode,
19591 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19592 +               path_put(&path);
19593 +       }
19594 +       if (ret)
19595 +               return ret;
19596 +
19597 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19598 +               ret = -EFAULT;
19599 +       return ret;
19600 +}
19601 +
19602 +#ifdef CONFIG_COMPAT
19603 +
19604 +int vc_get_iattr_x32(void __user *data)
19605 +{
19606 +       struct path path;
19607 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19608 +       int ret;
19609 +
19610 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19611 +               return -EFAULT;
19612 +
19613 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19614 +       if (!ret) {
19615 +               ret = __vc_get_iattr(path.dentry->d_inode,
19616 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19617 +               path_put(&path);
19618 +       }
19619 +       if (ret)
19620 +               return ret;
19621 +
19622 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19623 +               ret = -EFAULT;
19624 +       return ret;
19625 +}
19626 +
19627 +#endif /* CONFIG_COMPAT */
19628 +
19629 +
19630 +int vc_fget_iattr(uint32_t fd, void __user *data)
19631 +{
19632 +       struct file *filp;
19633 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19634 +       int ret;
19635 +
19636 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19637 +               return -EFAULT;
19638 +
19639 +       filp = fget(fd);
19640 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19641 +               return -EBADF;
19642 +
19643 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
19644 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
19645 +
19646 +       fput(filp);
19647 +
19648 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19649 +               ret = -EFAULT;
19650 +       return ret;
19651 +}
19652 +
19653 +
19654 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19655 +{
19656 +       struct inode *in = de->d_inode;
19657 +       int error = 0, is_proc = 0, has_tag = 0;
19658 +       struct iattr attr = { 0 };
19659 +
19660 +       if (!in || !in->i_sb)
19661 +               return -ESRCH;
19662 +
19663 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19664 +       if ((*mask & IATTR_FLAGS) && !is_proc)
19665 +               return -EINVAL;
19666 +
19667 +       has_tag = IS_TAGGED(in) ||
19668 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
19669 +       if ((*mask & IATTR_TAG) && !has_tag)
19670 +               return -EINVAL;
19671 +
19672 +       mutex_lock(&in->i_mutex);
19673 +       if (*mask & IATTR_TAG) {
19674 +               attr.ia_tag = *tag;
19675 +               attr.ia_valid |= ATTR_TAG;
19676 +       }
19677 +
19678 +       if (*mask & IATTR_FLAGS) {
19679 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
19680 +               unsigned int iflags = PROC_I(in)->vx_flags;
19681 +
19682 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
19683 +                       | (*flags & IATTR_FLAGS);
19684 +               PROC_I(in)->vx_flags = iflags;
19685 +               if (entry)
19686 +                       entry->vx_flags = iflags;
19687 +       }
19688 +
19689 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
19690 +               IATTR_BARRIER | IATTR_COW)) {
19691 +               int iflags = in->i_flags;
19692 +               int vflags = in->i_vflags;
19693 +
19694 +               if (*mask & IATTR_IMMUTABLE) {
19695 +                       if (*flags & IATTR_IMMUTABLE)
19696 +                               iflags |= S_IMMUTABLE;
19697 +                       else
19698 +                               iflags &= ~S_IMMUTABLE;
19699 +               }
19700 +               if (*mask & IATTR_IXUNLINK) {
19701 +                       if (*flags & IATTR_IXUNLINK)
19702 +                               iflags |= S_IXUNLINK;
19703 +                       else
19704 +                               iflags &= ~S_IXUNLINK;
19705 +               }
19706 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
19707 +                       if (*flags & IATTR_BARRIER)
19708 +                               vflags |= V_BARRIER;
19709 +                       else
19710 +                               vflags &= ~V_BARRIER;
19711 +               }
19712 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
19713 +                       if (*flags & IATTR_COW)
19714 +                               vflags |= V_COW;
19715 +                       else
19716 +                               vflags &= ~V_COW;
19717 +               }
19718 +               if (in->i_op && in->i_op->sync_flags) {
19719 +                       error = in->i_op->sync_flags(in, iflags, vflags);
19720 +                       if (error)
19721 +                               goto out;
19722 +               }
19723 +       }
19724 +
19725 +       if (attr.ia_valid) {
19726 +               if (in->i_op && in->i_op->setattr)
19727 +                       error = in->i_op->setattr(de, &attr);
19728 +               else {
19729 +                       error = inode_change_ok(in, &attr);
19730 +                       if (!error) {
19731 +                               setattr_copy(in, &attr);
19732 +                               mark_inode_dirty(in);
19733 +                       }
19734 +               }
19735 +       }
19736 +
19737 +out:
19738 +       mutex_unlock(&in->i_mutex);
19739 +       return error;
19740 +}
19741 +
19742 +int vc_set_iattr(void __user *data)
19743 +{
19744 +       struct path path;
19745 +       struct vcmd_ctx_iattr_v1 vc_data;
19746 +       int ret;
19747 +
19748 +       if (!capable(CAP_LINUX_IMMUTABLE))
19749 +               return -EPERM;
19750 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19751 +               return -EFAULT;
19752 +
19753 +       ret = user_lpath(vc_data.name, &path);
19754 +       if (!ret) {
19755 +               ret = __vc_set_iattr(path.dentry,
19756 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19757 +               path_put(&path);
19758 +       }
19759 +
19760 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19761 +               ret = -EFAULT;
19762 +       return ret;
19763 +}
19764 +
19765 +#ifdef CONFIG_COMPAT
19766 +
19767 +int vc_set_iattr_x32(void __user *data)
19768 +{
19769 +       struct path path;
19770 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
19771 +       int ret;
19772 +
19773 +       if (!capable(CAP_LINUX_IMMUTABLE))
19774 +               return -EPERM;
19775 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19776 +               return -EFAULT;
19777 +
19778 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19779 +       if (!ret) {
19780 +               ret = __vc_set_iattr(path.dentry,
19781 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19782 +               path_put(&path);
19783 +       }
19784 +
19785 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19786 +               ret = -EFAULT;
19787 +       return ret;
19788 +}
19789 +
19790 +#endif /* CONFIG_COMPAT */
19791 +
19792 +int vc_fset_iattr(uint32_t fd, void __user *data)
19793 +{
19794 +       struct file *filp;
19795 +       struct vcmd_ctx_fiattr_v0 vc_data;
19796 +       int ret;
19797 +
19798 +       if (!capable(CAP_LINUX_IMMUTABLE))
19799 +               return -EPERM;
19800 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19801 +               return -EFAULT;
19802 +
19803 +       filp = fget(fd);
19804 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19805 +               return -EBADF;
19806 +
19807 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
19808 +               &vc_data.flags, &vc_data.mask);
19809 +
19810 +       fput(filp);
19811 +
19812 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19813 +               return -EFAULT;
19814 +       return ret;
19815 +}
19816 +
19817 +
19818 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
19819 +
19820 +static match_table_t tokens = {
19821 +       {Opt_notagcheck, "notagcheck"},
19822 +#ifdef CONFIG_PROPAGATE
19823 +       {Opt_notag, "notag"},
19824 +       {Opt_tag, "tag"},
19825 +       {Opt_tagid, "tagid=%u"},
19826 +#endif
19827 +       {Opt_err, NULL}
19828 +};
19829 +
19830 +
19831 +static void __dx_parse_remove(char *string, char *opt)
19832 +{
19833 +       char *p = strstr(string, opt);
19834 +       char *q = p;
19835 +
19836 +       if (p) {
19837 +               while (*q != '\0' && *q != ',')
19838 +                       q++;
19839 +               while (*q)
19840 +                       *p++ = *q++;
19841 +               while (*p)
19842 +                       *p++ = '\0';
19843 +       }
19844 +}
19845 +
19846 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
19847 +                unsigned long *flags)
19848 +{
19849 +       int set = 0;
19850 +       substring_t args[MAX_OPT_ARGS];
19851 +       int token;
19852 +       char *s, *p, *opts;
19853 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_WARN)
19854 +       int option = 0;
19855 +#endif
19856 +
19857 +       if (!string)
19858 +               return 0;
19859 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
19860 +       if (!s)
19861 +               return 0;
19862 +
19863 +       opts = s;
19864 +       while ((p = strsep(&opts, ",")) != NULL) {
19865 +               token = match_token(p, tokens, args);
19866 +
19867 +               switch (token) {
19868 +#ifdef CONFIG_PROPAGATE
19869 +               case Opt_tag:
19870 +                       if (tag)
19871 +                               *tag = 0;
19872 +                       if (remove)
19873 +                               __dx_parse_remove(s, "tag");
19874 +                       *mnt_flags |= MNT_TAGID;
19875 +                       set |= MNT_TAGID;
19876 +                       break;
19877 +               case Opt_notag:
19878 +                       if (remove)
19879 +                               __dx_parse_remove(s, "notag");
19880 +                       *mnt_flags |= MNT_NOTAG;
19881 +                       set |= MNT_NOTAG;
19882 +                       break;
19883 +               case Opt_tagid:
19884 +                       if (tag && !match_int(args, &option))
19885 +                               *tag = option;
19886 +                       if (remove)
19887 +                               __dx_parse_remove(s, "tagid");
19888 +                       *mnt_flags |= MNT_TAGID;
19889 +                       set |= MNT_TAGID;
19890 +                       break;
19891 +#endif
19892 +               case Opt_notagcheck:
19893 +                       if (remove)
19894 +                               __dx_parse_remove(s, "notagcheck");
19895 +                       *flags |= MS_NOTAGCHECK;
19896 +                       set |= MS_NOTAGCHECK;
19897 +                       break;
19898 +               }
19899 +               vxdprintk(VXD_CBIT(tag, 7),
19900 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
19901 +                       p, token, option);
19902 +       }
19903 +       if (set)
19904 +               strcpy(string, s);
19905 +       kfree(s);
19906 +       return set;
19907 +}
19908 +
19909 +#ifdef CONFIG_PROPAGATE
19910 +
19911 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
19912 +{
19913 +       tag_t new_tag = 0;
19914 +       struct vfsmount *mnt;
19915 +       int propagate;
19916 +
19917 +       if (!nd)
19918 +               return;
19919 +       mnt = nd->path.mnt;
19920 +       if (!mnt)
19921 +               return;
19922 +
19923 +       propagate = (mnt->mnt_flags & MNT_TAGID);
19924 +       if (propagate)
19925 +               new_tag = mnt->mnt_tag;
19926 +
19927 +       vxdprintk(VXD_CBIT(tag, 7),
19928 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
19929 +               inode, inode->i_ino, inode->i_tag,
19930 +               new_tag, (propagate) ? 1 : 0);
19931 +
19932 +       if (propagate)
19933 +               inode->i_tag = new_tag;
19934 +}
19935 +
19936 +#include <linux/module.h>
19937 +
19938 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
19939 +
19940 +#endif /* CONFIG_PROPAGATE */
19941 +
19942 diff -NurpP --minimal linux-3.1.1/kernel/vserver/limit.c linux-3.1.1-vs2.3.2/kernel/vserver/limit.c
19943 --- linux-3.1.1/kernel/vserver/limit.c  1970-01-01 01:00:00.000000000 +0100
19944 +++ linux-3.1.1-vs2.3.2/kernel/vserver/limit.c  2011-10-24 18:53:33.000000000 +0200
19945 @@ -0,0 +1,360 @@
19946 +/*
19947 + *  linux/kernel/vserver/limit.c
19948 + *
19949 + *  Virtual Server: Context Limits
19950 + *
19951 + *  Copyright (C) 2004-2010  Herbert Pötzl
19952 + *
19953 + *  V0.01  broken out from vcontext V0.05
19954 + *  V0.02  changed vcmds to vxi arg
19955 + *  V0.03  added memory cgroup support
19956 + *
19957 + */
19958 +
19959 +#include <linux/sched.h>
19960 +#include <linux/module.h>
19961 +#include <linux/memcontrol.h>
19962 +#include <linux/res_counter.h>
19963 +#include <linux/vs_limit.h>
19964 +#include <linux/vserver/limit.h>
19965 +#include <linux/vserver/limit_cmd.h>
19966 +
19967 +#include <asm/uaccess.h>
19968 +
19969 +
19970 +const char *vlimit_name[NUM_LIMITS] = {
19971 +#ifdef CONFIG_VSERVER_LEGACY_MEM
19972 +       [RLIMIT_RSS]            = "RSS",
19973 +       [RLIMIT_AS]             = "VM",
19974 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
19975 +       [RLIMIT_CPU]            = "CPU",
19976 +       [RLIMIT_NPROC]          = "NPROC",
19977 +       [RLIMIT_NOFILE]         = "NOFILE",
19978 +       [RLIMIT_LOCKS]          = "LOCKS",
19979 +       [RLIMIT_SIGPENDING]     = "SIGP",
19980 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
19981 +
19982 +       [VLIMIT_NSOCK]          = "NSOCK",
19983 +       [VLIMIT_OPENFD]         = "OPENFD",
19984 +       [VLIMIT_SHMEM]          = "SHMEM",
19985 +       [VLIMIT_DENTRY]         = "DENTRY",
19986 +};
19987 +
19988 +EXPORT_SYMBOL_GPL(vlimit_name);
19989 +
19990 +#define MASK_ENTRY(x)  (1 << (x))
19991 +
19992 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
19993 +               /* minimum */
19994 +       0
19995 +       ,       /* softlimit */
19996 +#ifdef CONFIG_VSERVER_LEGACY_MEM
19997 +       MASK_ENTRY( RLIMIT_RSS          ) |
19998 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
19999 +       0
20000 +       ,       /* maximum */
20001 +#ifdef CONFIG_VSERVER_LEGACY_MEM
20002 +       MASK_ENTRY( RLIMIT_RSS          ) |
20003 +       MASK_ENTRY( RLIMIT_AS           ) |
20004 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
20005 +       MASK_ENTRY( RLIMIT_NPROC        ) |
20006 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
20007 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
20008 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
20009 +
20010 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
20011 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
20012 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
20013 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
20014 +       0
20015 +};
20016 +               /* accounting only */
20017 +uint32_t account_mask =
20018 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
20019 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
20020 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
20021 +       0;
20022 +
20023 +
20024 +static int is_valid_vlimit(int id)
20025 +{
20026 +       uint32_t mask = vlimit_mask.minimum |
20027 +               vlimit_mask.softlimit | vlimit_mask.maximum;
20028 +       return mask & (1 << id);
20029 +}
20030 +
20031 +static int is_accounted_vlimit(int id)
20032 +{
20033 +       if (is_valid_vlimit(id))
20034 +               return 1;
20035 +       return account_mask & (1 << id);
20036 +}
20037 +
20038 +
20039 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
20040 +{
20041 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
20042 +       return VX_VLIM(limit);
20043 +}
20044 +
20045 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
20046 +{
20047 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
20048 +       return VX_VLIM(limit);
20049 +}
20050 +
20051 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
20052 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
20053 +{
20054 +       if (!is_valid_vlimit(id))
20055 +               return -EINVAL;
20056 +
20057 +       if (minimum)
20058 +               *minimum = CRLIM_UNSET;
20059 +       if (softlimit)
20060 +               *softlimit = vc_get_soft(vxi, id);
20061 +       if (maximum)
20062 +               *maximum = vc_get_hard(vxi, id);
20063 +       return 0;
20064 +}
20065 +
20066 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
20067 +{
20068 +       struct vcmd_ctx_rlimit_v0 vc_data;
20069 +       int ret;
20070 +
20071 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20072 +               return -EFAULT;
20073 +
20074 +       ret = do_get_rlimit(vxi, vc_data.id,
20075 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
20076 +       if (ret)
20077 +               return ret;
20078 +
20079 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20080 +               return -EFAULT;
20081 +       return 0;
20082 +}
20083 +
20084 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
20085 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
20086 +{
20087 +       if (!is_valid_vlimit(id))
20088 +               return -EINVAL;
20089 +
20090 +       if (maximum != CRLIM_KEEP)
20091 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
20092 +       if (softlimit != CRLIM_KEEP)
20093 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
20094 +
20095 +       /* clamp soft limit */
20096 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
20097 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
20098 +
20099 +       return 0;
20100 +}
20101 +
20102 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
20103 +{
20104 +       struct vcmd_ctx_rlimit_v0 vc_data;
20105 +
20106 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20107 +               return -EFAULT;
20108 +
20109 +       return do_set_rlimit(vxi, vc_data.id,
20110 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
20111 +}
20112 +
20113 +#ifdef CONFIG_IA32_EMULATION
20114 +
20115 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
20116 +{
20117 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
20118 +
20119 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20120 +               return -EFAULT;
20121 +
20122 +       return do_set_rlimit(vxi, vc_data.id,
20123 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
20124 +}
20125 +
20126 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
20127 +{
20128 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
20129 +       int ret;
20130 +
20131 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20132 +               return -EFAULT;
20133 +
20134 +       ret = do_get_rlimit(vxi, vc_data.id,
20135 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
20136 +       if (ret)
20137 +               return ret;
20138 +
20139 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20140 +               return -EFAULT;
20141 +       return 0;
20142 +}
20143 +
20144 +#endif /* CONFIG_IA32_EMULATION */
20145 +
20146 +
20147 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
20148 +{
20149 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
20150 +               return -EFAULT;
20151 +       return 0;
20152 +}
20153 +
20154 +
20155 +static inline void vx_reset_hits(struct _vx_limit *limit)
20156 +{
20157 +       int lim;
20158 +
20159 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20160 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20161 +       }
20162 +}
20163 +
20164 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
20165 +{
20166 +       vx_reset_hits(&vxi->limit);
20167 +       return 0;
20168 +}
20169 +
20170 +static inline void vx_reset_minmax(struct _vx_limit *limit)
20171 +{
20172 +       rlim_t value;
20173 +       int lim;
20174 +
20175 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20176 +               value = __rlim_get(limit, lim);
20177 +               __rlim_rmax(limit, lim) = value;
20178 +               __rlim_rmin(limit, lim) = value;
20179 +       }
20180 +}
20181 +
20182 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
20183 +{
20184 +       vx_reset_minmax(&vxi->limit);
20185 +       return 0;
20186 +}
20187 +
20188 +
20189 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
20190 +{
20191 +       struct vcmd_rlimit_stat_v0 vc_data;
20192 +       struct _vx_limit *limit = &vxi->limit;
20193 +       int id;
20194 +
20195 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20196 +               return -EFAULT;
20197 +
20198 +       id = vc_data.id;
20199 +       if (!is_accounted_vlimit(id))
20200 +               return -EINVAL;
20201 +
20202 +       vx_limit_fixup(limit, id);
20203 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
20204 +       vc_data.value = __rlim_get(limit, id);
20205 +       vc_data.minimum = __rlim_rmin(limit, id);
20206 +       vc_data.maximum = __rlim_rmax(limit, id);
20207 +
20208 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20209 +               return -EFAULT;
20210 +       return 0;
20211 +}
20212 +
20213 +
20214 +void vx_vsi_meminfo(struct sysinfo *val)
20215 +{
20216 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20217 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20218 +       u64 res_limit, res_usage;
20219 +
20220 +       if (!mcg)
20221 +               return;
20222 +
20223 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
20224 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
20225 +
20226 +       if (res_limit != RESOURCE_MAX)
20227 +               val->totalram = (res_limit >> PAGE_SHIFT);
20228 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
20229 +       val->bufferram = 0;
20230 +       val->totalhigh = 0;
20231 +       val->freehigh = 0;
20232 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
20233 +       return;
20234 +}
20235 +
20236 +void vx_vsi_swapinfo(struct sysinfo *val)
20237 +{
20238 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20239 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
20240 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20241 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
20242 +       s64 swap_limit, swap_usage;
20243 +
20244 +       if (!mcg)
20245 +               return;
20246 +
20247 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
20248 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
20249 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
20250 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
20251 +
20252 +       /* memory unlimited */
20253 +       if (res_limit == RESOURCE_MAX)
20254 +               return;
20255 +
20256 +       swap_limit = memsw_limit - res_limit;
20257 +       /* we have a swap limit? */
20258 +       if (memsw_limit != RESOURCE_MAX)
20259 +               val->totalswap = swap_limit >> PAGE_SHIFT;
20260 +
20261 +       /* calculate swap part */
20262 +       swap_usage = (memsw_usage > res_usage) ?
20263 +               memsw_usage - res_usage : 0;
20264 +
20265 +       /* total shown minus usage gives free swap */
20266 +       val->freeswap = (swap_usage < swap_limit) ?
20267 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
20268 +#else  /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20269 +       val->totalswap = 0;
20270 +       val->freeswap = 0;
20271 +#endif /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20272 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
20273 +       return;
20274 +}
20275 +
20276 +long vx_vsi_cached(struct sysinfo *val)
20277 +{
20278 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20279 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20280 +
20281 +       return mem_cgroup_stat_read_cache(mcg);
20282 +#else
20283 +       return 0;
20284 +#endif
20285 +}
20286 +
20287 +
20288 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
20289 +{
20290 +       struct vx_info *vxi = mm->mm_vx_info;
20291 +       unsigned long points;
20292 +       rlim_t v, w;
20293 +
20294 +       if (!vxi)
20295 +               return 0;
20296 +
20297 +       points = vxi->vx_badness_bias;
20298 +
20299 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
20300 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
20301 +       points += (v > w) ? (v - w) : 0;
20302 +
20303 +       return points;
20304 +}
20305 +
20306 diff -NurpP --minimal linux-3.1.1/kernel/vserver/limit_init.h linux-3.1.1-vs2.3.2/kernel/vserver/limit_init.h
20307 --- linux-3.1.1/kernel/vserver/limit_init.h     1970-01-01 01:00:00.000000000 +0100
20308 +++ linux-3.1.1-vs2.3.2/kernel/vserver/limit_init.h     2011-10-24 18:53:33.000000000 +0200
20309 @@ -0,0 +1,31 @@
20310 +
20311 +
20312 +static inline void vx_info_init_limit(struct _vx_limit *limit)
20313 +{
20314 +       int lim;
20315 +
20316 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20317 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
20318 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
20319 +               __rlim_set(limit, lim, 0);
20320 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20321 +               __rlim_rmin(limit, lim) = 0;
20322 +               __rlim_rmax(limit, lim) = 0;
20323 +       }
20324 +}
20325 +
20326 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
20327 +{
20328 +       rlim_t value;
20329 +       int lim;
20330 +
20331 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20332 +               if ((1 << lim) & VLIM_NOCHECK)
20333 +                       continue;
20334 +               value = __rlim_get(limit, lim);
20335 +               vxwprintk_xid(value,
20336 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
20337 +                       limit, vlimit_name[lim], lim, (long)value);
20338 +       }
20339 +}
20340 +
20341 diff -NurpP --minimal linux-3.1.1/kernel/vserver/limit_proc.h linux-3.1.1-vs2.3.2/kernel/vserver/limit_proc.h
20342 --- linux-3.1.1/kernel/vserver/limit_proc.h     1970-01-01 01:00:00.000000000 +0100
20343 +++ linux-3.1.1-vs2.3.2/kernel/vserver/limit_proc.h     2011-10-24 18:53:33.000000000 +0200
20344 @@ -0,0 +1,57 @@
20345 +#ifndef _VX_LIMIT_PROC_H
20346 +#define _VX_LIMIT_PROC_H
20347 +
20348 +#include <linux/vserver/limit_int.h>
20349 +
20350 +
20351 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
20352 +#define VX_LIMIT_TOP   \
20353 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
20354 +
20355 +#define VX_LIMIT_ARG(r)                                \
20356 +       (unsigned long)__rlim_get(limit, r),    \
20357 +       (unsigned long)__rlim_rmin(limit, r),   \
20358 +       (unsigned long)__rlim_rmax(limit, r),   \
20359 +       VX_VLIM(__rlim_soft(limit, r)),         \
20360 +       VX_VLIM(__rlim_hard(limit, r)),         \
20361 +       atomic_read(&__rlim_lhit(limit, r))
20362 +
20363 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
20364 +{
20365 +       vx_limit_fixup(limit, -1);
20366 +       return sprintf(buffer, VX_LIMIT_TOP
20367 +               "PROC"  VX_LIMIT_FMT
20368 +               "VM"    VX_LIMIT_FMT
20369 +               "VML"   VX_LIMIT_FMT
20370 +               "RSS"   VX_LIMIT_FMT
20371 +               "ANON"  VX_LIMIT_FMT
20372 +               "RMAP"  VX_LIMIT_FMT
20373 +               "FILES" VX_LIMIT_FMT
20374 +               "OFD"   VX_LIMIT_FMT
20375 +               "LOCKS" VX_LIMIT_FMT
20376 +               "SOCK"  VX_LIMIT_FMT
20377 +               "MSGQ"  VX_LIMIT_FMT
20378 +               "SHM"   VX_LIMIT_FMT
20379 +               "SEMA"  VX_LIMIT_FMT
20380 +               "SEMS"  VX_LIMIT_FMT
20381 +               "DENT"  VX_LIMIT_FMT,
20382 +               VX_LIMIT_ARG(RLIMIT_NPROC),
20383 +               VX_LIMIT_ARG(RLIMIT_AS),
20384 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
20385 +               VX_LIMIT_ARG(RLIMIT_RSS),
20386 +               VX_LIMIT_ARG(VLIMIT_ANON),
20387 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
20388 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
20389 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
20390 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
20391 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
20392 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
20393 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
20394 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
20395 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
20396 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
20397 +}
20398 +
20399 +#endif /* _VX_LIMIT_PROC_H */
20400 +
20401 +
20402 diff -NurpP --minimal linux-3.1.1/kernel/vserver/network.c linux-3.1.1-vs2.3.2/kernel/vserver/network.c
20403 --- linux-3.1.1/kernel/vserver/network.c        1970-01-01 01:00:00.000000000 +0100
20404 +++ linux-3.1.1-vs2.3.2/kernel/vserver/network.c        2011-10-24 18:53:33.000000000 +0200
20405 @@ -0,0 +1,912 @@
20406 +/*
20407 + *  linux/kernel/vserver/network.c
20408 + *
20409 + *  Virtual Server: Network Support
20410 + *
20411 + *  Copyright (C) 2003-2007  Herbert Pötzl
20412 + *
20413 + *  V0.01  broken out from vcontext V0.05
20414 + *  V0.02  cleaned up implementation
20415 + *  V0.03  added equiv nx commands
20416 + *  V0.04  switch to RCU based hash
20417 + *  V0.05  and back to locking again
20418 + *  V0.06  changed vcmds to nxi arg
20419 + *  V0.07  have __create claim() the nxi
20420 + *
20421 + */
20422 +
20423 +#include <linux/err.h>
20424 +#include <linux/slab.h>
20425 +#include <linux/rcupdate.h>
20426 +
20427 +#include <linux/vs_network.h>
20428 +#include <linux/vs_pid.h>
20429 +#include <linux/vserver/network_cmd.h>
20430 +
20431 +
20432 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
20433 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
20434 +
20435 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
20436 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
20437 +
20438 +
20439 +static int __init init_network(void)
20440 +{
20441 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
20442 +               sizeof(struct nx_addr_v4), 0,
20443 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20444 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
20445 +               sizeof(struct nx_addr_v6), 0,
20446 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20447 +       return 0;
20448 +}
20449 +
20450 +
20451 +/*     __alloc_nx_addr_v4()                                    */
20452 +
20453 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
20454 +{
20455 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
20456 +               nx_addr_v4_cachep, GFP_KERNEL);
20457 +
20458 +       if (!IS_ERR(nxa))
20459 +               memset(nxa, 0, sizeof(*nxa));
20460 +       return nxa;
20461 +}
20462 +
20463 +/*     __dealloc_nx_addr_v4()                                  */
20464 +
20465 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
20466 +{
20467 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
20468 +}
20469 +
20470 +/*     __dealloc_nx_addr_v4_all()                              */
20471 +
20472 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
20473 +{
20474 +       while (nxa) {
20475 +               struct nx_addr_v4 *next = nxa->next;
20476 +
20477 +               __dealloc_nx_addr_v4(nxa);
20478 +               nxa = next;
20479 +       }
20480 +}
20481 +
20482 +
20483 +#ifdef CONFIG_IPV6
20484 +
20485 +/*     __alloc_nx_addr_v6()                                    */
20486 +
20487 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
20488 +{
20489 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
20490 +               nx_addr_v6_cachep, GFP_KERNEL);
20491 +
20492 +       if (!IS_ERR(nxa))
20493 +               memset(nxa, 0, sizeof(*nxa));
20494 +       return nxa;
20495 +}
20496 +
20497 +/*     __dealloc_nx_addr_v6()                                  */
20498 +
20499 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
20500 +{
20501 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
20502 +}
20503 +
20504 +/*     __dealloc_nx_addr_v6_all()                              */
20505 +
20506 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
20507 +{
20508 +       while (nxa) {
20509 +               struct nx_addr_v6 *next = nxa->next;
20510 +
20511 +               __dealloc_nx_addr_v6(nxa);
20512 +               nxa = next;
20513 +       }
20514 +}
20515 +
20516 +#endif /* CONFIG_IPV6 */
20517 +
20518 +/*     __alloc_nx_info()
20519 +
20520 +       * allocate an initialized nx_info struct
20521 +       * doesn't make it visible (hash)                        */
20522 +
20523 +static struct nx_info *__alloc_nx_info(nid_t nid)
20524 +{
20525 +       struct nx_info *new = NULL;
20526 +
20527 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
20528 +
20529 +       /* would this benefit from a slab cache? */
20530 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
20531 +       if (!new)
20532 +               return 0;
20533 +
20534 +       memset(new, 0, sizeof(struct nx_info));
20535 +       new->nx_id = nid;
20536 +       INIT_HLIST_NODE(&new->nx_hlist);
20537 +       atomic_set(&new->nx_usecnt, 0);
20538 +       atomic_set(&new->nx_tasks, 0);
20539 +       new->nx_state = 0;
20540 +
20541 +       new->nx_flags = NXF_INIT_SET;
20542 +
20543 +       /* rest of init goes here */
20544 +
20545 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
20546 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
20547 +
20548 +       vxdprintk(VXD_CBIT(nid, 0),
20549 +               "alloc_nx_info(%d) = %p", nid, new);
20550 +       atomic_inc(&nx_global_ctotal);
20551 +       return new;
20552 +}
20553 +
20554 +/*     __dealloc_nx_info()
20555 +
20556 +       * final disposal of nx_info                             */
20557 +
20558 +static void __dealloc_nx_info(struct nx_info *nxi)
20559 +{
20560 +       vxdprintk(VXD_CBIT(nid, 0),
20561 +               "dealloc_nx_info(%p)", nxi);
20562 +
20563 +       nxi->nx_hlist.next = LIST_POISON1;
20564 +       nxi->nx_id = -1;
20565 +
20566 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20567 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20568 +
20569 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
20570 +
20571 +       nxi->nx_state |= NXS_RELEASED;
20572 +       kfree(nxi);
20573 +       atomic_dec(&nx_global_ctotal);
20574 +}
20575 +
20576 +static void __shutdown_nx_info(struct nx_info *nxi)
20577 +{
20578 +       nxi->nx_state |= NXS_SHUTDOWN;
20579 +       vs_net_change(nxi, VSC_NETDOWN);
20580 +}
20581 +
20582 +/*     exported stuff                                          */
20583 +
20584 +void free_nx_info(struct nx_info *nxi)
20585 +{
20586 +       /* context shutdown is mandatory */
20587 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
20588 +
20589 +       /* context must not be hashed */
20590 +       BUG_ON(nxi->nx_state & NXS_HASHED);
20591 +
20592 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20593 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20594 +
20595 +       __dealloc_nx_info(nxi);
20596 +}
20597 +
20598 +
20599 +void __nx_set_lback(struct nx_info *nxi)
20600 +{
20601 +       int nid = nxi->nx_id;
20602 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
20603 +
20604 +       nxi->v4_lback.s_addr = lback;
20605 +}
20606 +
20607 +extern int __nx_inet_add_lback(__be32 addr);
20608 +extern int __nx_inet_del_lback(__be32 addr);
20609 +
20610 +
20611 +/*     hash table for nx_info hash */
20612 +
20613 +#define NX_HASH_SIZE   13
20614 +
20615 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
20616 +
20617 +static DEFINE_SPINLOCK(nx_info_hash_lock);
20618 +
20619 +
20620 +static inline unsigned int __hashval(nid_t nid)
20621 +{
20622 +       return (nid % NX_HASH_SIZE);
20623 +}
20624 +
20625 +
20626 +
20627 +/*     __hash_nx_info()
20628 +
20629 +       * add the nxi to the global hash table
20630 +       * requires the hash_lock to be held                     */
20631 +
20632 +static inline void __hash_nx_info(struct nx_info *nxi)
20633 +{
20634 +       struct hlist_head *head;
20635 +
20636 +       vxd_assert_lock(&nx_info_hash_lock);
20637 +       vxdprintk(VXD_CBIT(nid, 4),
20638 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
20639 +
20640 +       /* context must not be hashed */
20641 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
20642 +
20643 +       nxi->nx_state |= NXS_HASHED;
20644 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
20645 +       hlist_add_head(&nxi->nx_hlist, head);
20646 +       atomic_inc(&nx_global_cactive);
20647 +}
20648 +
20649 +/*     __unhash_nx_info()
20650 +
20651 +       * remove the nxi from the global hash table
20652 +       * requires the hash_lock to be held                     */
20653 +
20654 +static inline void __unhash_nx_info(struct nx_info *nxi)
20655 +{
20656 +       vxd_assert_lock(&nx_info_hash_lock);
20657 +       vxdprintk(VXD_CBIT(nid, 4),
20658 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
20659 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
20660 +
20661 +       /* context must be hashed */
20662 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
20663 +       /* but without tasks */
20664 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20665 +
20666 +       nxi->nx_state &= ~NXS_HASHED;
20667 +       hlist_del(&nxi->nx_hlist);
20668 +       atomic_dec(&nx_global_cactive);
20669 +}
20670 +
20671 +
20672 +/*     __lookup_nx_info()
20673 +
20674 +       * requires the hash_lock to be held
20675 +       * doesn't increment the nx_refcnt                       */
20676 +
20677 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
20678 +{
20679 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
20680 +       struct hlist_node *pos;
20681 +       struct nx_info *nxi;
20682 +
20683 +       vxd_assert_lock(&nx_info_hash_lock);
20684 +       hlist_for_each(pos, head) {
20685 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20686 +
20687 +               if (nxi->nx_id == nid)
20688 +                       goto found;
20689 +       }
20690 +       nxi = NULL;
20691 +found:
20692 +       vxdprintk(VXD_CBIT(nid, 0),
20693 +               "__lookup_nx_info(#%u): %p[#%u]",
20694 +               nid, nxi, nxi ? nxi->nx_id : 0);
20695 +       return nxi;
20696 +}
20697 +
20698 +
20699 +/*     __create_nx_info()
20700 +
20701 +       * create the requested context
20702 +       * get(), claim() and hash it                            */
20703 +
20704 +static struct nx_info *__create_nx_info(int id)
20705 +{
20706 +       struct nx_info *new, *nxi = NULL;
20707 +
20708 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
20709 +
20710 +       if (!(new = __alloc_nx_info(id)))
20711 +               return ERR_PTR(-ENOMEM);
20712 +
20713 +       /* required to make dynamic xids unique */
20714 +       spin_lock(&nx_info_hash_lock);
20715 +
20716 +       /* static context requested */
20717 +       if ((nxi = __lookup_nx_info(id))) {
20718 +               vxdprintk(VXD_CBIT(nid, 0),
20719 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
20720 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20721 +                       nxi = ERR_PTR(-EBUSY);
20722 +               else
20723 +                       nxi = ERR_PTR(-EEXIST);
20724 +               goto out_unlock;
20725 +       }
20726 +       /* new context */
20727 +       vxdprintk(VXD_CBIT(nid, 0),
20728 +               "create_nx_info(%d) = %p (new)", id, new);
20729 +       claim_nx_info(new, NULL);
20730 +       __nx_set_lback(new);
20731 +       __hash_nx_info(get_nx_info(new));
20732 +       nxi = new, new = NULL;
20733 +
20734 +out_unlock:
20735 +       spin_unlock(&nx_info_hash_lock);
20736 +       if (new)
20737 +               __dealloc_nx_info(new);
20738 +       return nxi;
20739 +}
20740 +
20741 +
20742 +
20743 +/*     exported stuff                                          */
20744 +
20745 +
20746 +void unhash_nx_info(struct nx_info *nxi)
20747 +{
20748 +       __shutdown_nx_info(nxi);
20749 +       spin_lock(&nx_info_hash_lock);
20750 +       __unhash_nx_info(nxi);
20751 +       spin_unlock(&nx_info_hash_lock);
20752 +}
20753 +
20754 +/*     lookup_nx_info()
20755 +
20756 +       * search for a nx_info and get() it
20757 +       * negative id means current                             */
20758 +
20759 +struct nx_info *lookup_nx_info(int id)
20760 +{
20761 +       struct nx_info *nxi = NULL;
20762 +
20763 +       if (id < 0) {
20764 +               nxi = get_nx_info(current_nx_info());
20765 +       } else if (id > 1) {
20766 +               spin_lock(&nx_info_hash_lock);
20767 +               nxi = get_nx_info(__lookup_nx_info(id));
20768 +               spin_unlock(&nx_info_hash_lock);
20769 +       }
20770 +       return nxi;
20771 +}
20772 +
20773 +/*     nid_is_hashed()
20774 +
20775 +       * verify that nid is still hashed                       */
20776 +
20777 +int nid_is_hashed(nid_t nid)
20778 +{
20779 +       int hashed;
20780 +
20781 +       spin_lock(&nx_info_hash_lock);
20782 +       hashed = (__lookup_nx_info(nid) != NULL);
20783 +       spin_unlock(&nx_info_hash_lock);
20784 +       return hashed;
20785 +}
20786 +
20787 +
20788 +#ifdef CONFIG_PROC_FS
20789 +
20790 +/*     get_nid_list()
20791 +
20792 +       * get a subset of hashed nids for proc
20793 +       * assumes size is at least one                          */
20794 +
20795 +int get_nid_list(int index, unsigned int *nids, int size)
20796 +{
20797 +       int hindex, nr_nids = 0;
20798 +
20799 +       /* only show current and children */
20800 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
20801 +               if (index > 0)
20802 +                       return 0;
20803 +               nids[nr_nids] = nx_current_nid();
20804 +               return 1;
20805 +       }
20806 +
20807 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
20808 +               struct hlist_head *head = &nx_info_hash[hindex];
20809 +               struct hlist_node *pos;
20810 +
20811 +               spin_lock(&nx_info_hash_lock);
20812 +               hlist_for_each(pos, head) {
20813 +                       struct nx_info *nxi;
20814 +
20815 +                       if (--index > 0)
20816 +                               continue;
20817 +
20818 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20819 +                       nids[nr_nids] = nxi->nx_id;
20820 +                       if (++nr_nids >= size) {
20821 +                               spin_unlock(&nx_info_hash_lock);
20822 +                               goto out;
20823 +                       }
20824 +               }
20825 +               /* keep the lock time short */
20826 +               spin_unlock(&nx_info_hash_lock);
20827 +       }
20828 +out:
20829 +       return nr_nids;
20830 +}
20831 +#endif
20832 +
20833 +
20834 +/*
20835 + *     migrate task to new network
20836 + *     gets nxi, puts old_nxi on change
20837 + */
20838 +
20839 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
20840 +{
20841 +       struct nx_info *old_nxi;
20842 +       int ret = 0;
20843 +
20844 +       if (!p || !nxi)
20845 +               BUG();
20846 +
20847 +       vxdprintk(VXD_CBIT(nid, 5),
20848 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
20849 +               p, nxi, nxi->nx_id,
20850 +               atomic_read(&nxi->nx_usecnt),
20851 +               atomic_read(&nxi->nx_tasks));
20852 +
20853 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
20854 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20855 +               return -EACCES;
20856 +
20857 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
20858 +               return -EFAULT;
20859 +
20860 +       /* maybe disallow this completely? */
20861 +       old_nxi = task_get_nx_info(p);
20862 +       if (old_nxi == nxi)
20863 +               goto out;
20864 +
20865 +       task_lock(p);
20866 +       if (old_nxi)
20867 +               clr_nx_info(&p->nx_info);
20868 +       claim_nx_info(nxi, p);
20869 +       set_nx_info(&p->nx_info, nxi);
20870 +       p->nid = nxi->nx_id;
20871 +       task_unlock(p);
20872 +
20873 +       vxdprintk(VXD_CBIT(nid, 5),
20874 +               "moved task %p into nxi:%p[#%d]",
20875 +               p, nxi, nxi->nx_id);
20876 +
20877 +       if (old_nxi)
20878 +               release_nx_info(old_nxi, p);
20879 +       ret = 0;
20880 +out:
20881 +       put_nx_info(old_nxi);
20882 +       return ret;
20883 +}
20884 +
20885 +
20886 +void nx_set_persistent(struct nx_info *nxi)
20887 +{
20888 +       vxdprintk(VXD_CBIT(nid, 6),
20889 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
20890 +
20891 +       get_nx_info(nxi);
20892 +       claim_nx_info(nxi, NULL);
20893 +}
20894 +
20895 +void nx_clear_persistent(struct nx_info *nxi)
20896 +{
20897 +       vxdprintk(VXD_CBIT(nid, 6),
20898 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
20899 +
20900 +       release_nx_info(nxi, NULL);
20901 +       put_nx_info(nxi);
20902 +}
20903 +
20904 +void nx_update_persistent(struct nx_info *nxi)
20905 +{
20906 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
20907 +               nx_set_persistent(nxi);
20908 +       else
20909 +               nx_clear_persistent(nxi);
20910 +}
20911 +
20912 +/* vserver syscall commands below here */
20913 +
20914 +/* taks nid and nx_info functions */
20915 +
20916 +#include <asm/uaccess.h>
20917 +
20918 +
20919 +int vc_task_nid(uint32_t id)
20920 +{
20921 +       nid_t nid;
20922 +
20923 +       if (id) {
20924 +               struct task_struct *tsk;
20925 +
20926 +               rcu_read_lock();
20927 +               tsk = find_task_by_real_pid(id);
20928 +               nid = (tsk) ? tsk->nid : -ESRCH;
20929 +               rcu_read_unlock();
20930 +       } else
20931 +               nid = nx_current_nid();
20932 +       return nid;
20933 +}
20934 +
20935 +
20936 +int vc_nx_info(struct nx_info *nxi, void __user *data)
20937 +{
20938 +       struct vcmd_nx_info_v0 vc_data;
20939 +
20940 +       vc_data.nid = nxi->nx_id;
20941 +
20942 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20943 +               return -EFAULT;
20944 +       return 0;
20945 +}
20946 +
20947 +
20948 +/* network functions */
20949 +
20950 +int vc_net_create(uint32_t nid, void __user *data)
20951 +{
20952 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
20953 +       struct nx_info *new_nxi;
20954 +       int ret;
20955 +
20956 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20957 +               return -EFAULT;
20958 +
20959 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
20960 +               return -EINVAL;
20961 +
20962 +       new_nxi = __create_nx_info(nid);
20963 +       if (IS_ERR(new_nxi))
20964 +               return PTR_ERR(new_nxi);
20965 +
20966 +       /* initial flags */
20967 +       new_nxi->nx_flags = vc_data.flagword;
20968 +
20969 +       ret = -ENOEXEC;
20970 +       if (vs_net_change(new_nxi, VSC_NETUP))
20971 +               goto out;
20972 +
20973 +       ret = nx_migrate_task(current, new_nxi);
20974 +       if (ret)
20975 +               goto out;
20976 +
20977 +       /* return context id on success */
20978 +       ret = new_nxi->nx_id;
20979 +
20980 +       /* get a reference for persistent contexts */
20981 +       if ((vc_data.flagword & NXF_PERSISTENT))
20982 +               nx_set_persistent(new_nxi);
20983 +out:
20984 +       release_nx_info(new_nxi, NULL);
20985 +       put_nx_info(new_nxi);
20986 +       return ret;
20987 +}
20988 +
20989 +
20990 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
20991 +{
20992 +       return nx_migrate_task(current, nxi);
20993 +}
20994 +
20995 +
20996 +
20997 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20998 +       uint16_t type, uint16_t flags)
20999 +{
21000 +       struct nx_addr_v4 *nxa = &nxi->v4;
21001 +
21002 +       if (NX_IPV4(nxi)) {
21003 +               /* locate last entry */
21004 +               for (; nxa->next; nxa = nxa->next);
21005 +               nxa->next = __alloc_nx_addr_v4();
21006 +               nxa = nxa->next;
21007 +
21008 +               if (IS_ERR(nxa))
21009 +                       return PTR_ERR(nxa);
21010 +       }
21011 +
21012 +       if (nxi->v4.next)
21013 +               /* remove single ip for ip list */
21014 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
21015 +
21016 +       nxa->ip[0].s_addr = ip;
21017 +       nxa->ip[1].s_addr = ip2;
21018 +       nxa->mask.s_addr = mask;
21019 +       nxa->type = type;
21020 +       nxa->flags = flags;
21021 +       return 0;
21022 +}
21023 +
21024 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
21025 +       uint16_t type, uint16_t flags)
21026 +{
21027 +       struct nx_addr_v4 *nxa = &nxi->v4;
21028 +
21029 +       switch (type) {
21030 +/*     case NXA_TYPE_ADDR:
21031 +               break;          */
21032 +
21033 +       case NXA_TYPE_ANY:
21034 +               __dealloc_nx_addr_v4_all(xchg(&nxa->next, NULL));
21035 +               memset(nxa, 0, sizeof(*nxa));
21036 +               break;
21037 +
21038 +       default:
21039 +               return -EINVAL;
21040 +       }
21041 +       return 0;
21042 +}
21043 +
21044 +
21045 +int vc_net_add(struct nx_info *nxi, void __user *data)
21046 +{
21047 +       struct vcmd_net_addr_v0 vc_data;
21048 +       int index, ret = 0;
21049 +
21050 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21051 +               return -EFAULT;
21052 +
21053 +       switch (vc_data.type) {
21054 +       case NXA_TYPE_IPV4:
21055 +               if ((vc_data.count < 1) || (vc_data.count > 4))
21056 +                       return -EINVAL;
21057 +
21058 +               index = 0;
21059 +               while (index < vc_data.count) {
21060 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
21061 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
21062 +                       if (ret)
21063 +                               return ret;
21064 +                       index++;
21065 +               }
21066 +               ret = index;
21067 +               break;
21068 +
21069 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
21070 +               nxi->v4_bcast = vc_data.ip[0];
21071 +               ret = 1;
21072 +               break;
21073 +
21074 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
21075 +               nxi->v4_lback = vc_data.ip[0];
21076 +               ret = 1;
21077 +               break;
21078 +
21079 +       default:
21080 +               ret = -EINVAL;
21081 +               break;
21082 +       }
21083 +       return ret;
21084 +}
21085 +
21086 +int vc_net_remove(struct nx_info *nxi, void __user *data)
21087 +{
21088 +       struct vcmd_net_addr_v0 vc_data;
21089 +
21090 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21091 +               return -EFAULT;
21092 +
21093 +       switch (vc_data.type) {
21094 +       case NXA_TYPE_ANY:
21095 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
21096 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
21097 +               break;
21098 +
21099 +       default:
21100 +               return -EINVAL;
21101 +       }
21102 +       return 0;
21103 +}
21104 +
21105 +
21106 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
21107 +{
21108 +       struct vcmd_net_addr_ipv4_v1 vc_data;
21109 +
21110 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21111 +               return -EFAULT;
21112 +
21113 +       switch (vc_data.type) {
21114 +       case NXA_TYPE_ADDR:
21115 +       case NXA_TYPE_MASK:
21116 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
21117 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
21118 +
21119 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
21120 +               nxi->v4_bcast = vc_data.ip;
21121 +               break;
21122 +
21123 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
21124 +               nxi->v4_lback = vc_data.ip;
21125 +               break;
21126 +
21127 +       default:
21128 +               return -EINVAL;
21129 +       }
21130 +       return 0;
21131 +}
21132 +
21133 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
21134 +{
21135 +       struct vcmd_net_addr_ipv4_v2 vc_data;
21136 +
21137 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21138 +               return -EFAULT;
21139 +
21140 +       switch (vc_data.type) {
21141 +       case NXA_TYPE_ADDR:
21142 +       case NXA_TYPE_MASK:
21143 +       case NXA_TYPE_RANGE:
21144 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
21145 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
21146 +
21147 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
21148 +               nxi->v4_bcast = vc_data.ip;
21149 +               break;
21150 +
21151 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
21152 +               nxi->v4_lback = vc_data.ip;
21153 +               break;
21154 +
21155 +       default:
21156 +               return -EINVAL;
21157 +       }
21158 +       return 0;
21159 +}
21160 +
21161 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
21162 +{
21163 +       struct vcmd_net_addr_ipv4_v1 vc_data;
21164 +
21165 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21166 +               return -EFAULT;
21167 +
21168 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
21169 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
21170 +}
21171 +
21172 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
21173 +{
21174 +       struct vcmd_net_addr_ipv4_v2 vc_data;
21175 +
21176 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21177 +               return -EFAULT;
21178 +
21179 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
21180 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
21181 +}
21182 +
21183 +#ifdef CONFIG_IPV6
21184 +
21185 +int do_add_v6_addr(struct nx_info *nxi,
21186 +       struct in6_addr *ip, struct in6_addr *mask,
21187 +       uint32_t prefix, uint16_t type, uint16_t flags)
21188 +{
21189 +       struct nx_addr_v6 *nxa = &nxi->v6;
21190 +
21191 +       if (NX_IPV6(nxi)) {
21192 +               /* locate last entry */
21193 +               for (; nxa->next; nxa = nxa->next);
21194 +               nxa->next = __alloc_nx_addr_v6();
21195 +               nxa = nxa->next;
21196 +
21197 +               if (IS_ERR(nxa))
21198 +                       return PTR_ERR(nxa);
21199 +       }
21200 +
21201 +       nxa->ip = *ip;
21202 +       nxa->mask = *mask;
21203 +       nxa->prefix = prefix;
21204 +       nxa->type = type;
21205 +       nxa->flags = flags;
21206 +       return 0;
21207 +}
21208 +
21209 +
21210 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
21211 +{
21212 +       struct vcmd_net_addr_ipv6_v1 vc_data;
21213 +
21214 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21215 +               return -EFAULT;
21216 +
21217 +       switch (vc_data.type) {
21218 +       case NXA_TYPE_ADDR:
21219 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
21220 +               /* fallthrough */
21221 +       case NXA_TYPE_MASK:
21222 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
21223 +                       vc_data.prefix, vc_data.type, vc_data.flags);
21224 +       default:
21225 +               return -EINVAL;
21226 +       }
21227 +       return 0;
21228 +}
21229 +
21230 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
21231 +{
21232 +       struct vcmd_net_addr_ipv6_v1 vc_data;
21233 +
21234 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21235 +               return -EFAULT;
21236 +
21237 +       switch (vc_data.type) {
21238 +       case NXA_TYPE_ANY:
21239 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
21240 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
21241 +               break;
21242 +
21243 +       default:
21244 +               return -EINVAL;
21245 +       }
21246 +       return 0;
21247 +}
21248 +
21249 +#endif /* CONFIG_IPV6 */
21250 +
21251 +
21252 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
21253 +{
21254 +       struct vcmd_net_flags_v0 vc_data;
21255 +
21256 +       vc_data.flagword = nxi->nx_flags;
21257 +
21258 +       /* special STATE flag handling */
21259 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
21260 +
21261 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21262 +               return -EFAULT;
21263 +       return 0;
21264 +}
21265 +
21266 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
21267 +{
21268 +       struct vcmd_net_flags_v0 vc_data;
21269 +       uint64_t mask, trigger;
21270 +
21271 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21272 +               return -EFAULT;
21273 +
21274 +       /* special STATE flag handling */
21275 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
21276 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
21277 +
21278 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
21279 +               vc_data.flagword, mask);
21280 +       if (trigger & NXF_PERSISTENT)
21281 +               nx_update_persistent(nxi);
21282 +
21283 +       return 0;
21284 +}
21285 +
21286 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
21287 +{
21288 +       struct vcmd_net_caps_v0 vc_data;
21289 +
21290 +       vc_data.ncaps = nxi->nx_ncaps;
21291 +       vc_data.cmask = ~0ULL;
21292 +
21293 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21294 +               return -EFAULT;
21295 +       return 0;
21296 +}
21297 +
21298 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
21299 +{
21300 +       struct vcmd_net_caps_v0 vc_data;
21301 +
21302 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21303 +               return -EFAULT;
21304 +
21305 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
21306 +               vc_data.ncaps, vc_data.cmask);
21307 +       return 0;
21308 +}
21309 +
21310 +
21311 +#include <linux/module.h>
21312 +
21313 +module_init(init_network);
21314 +
21315 +EXPORT_SYMBOL_GPL(free_nx_info);
21316 +EXPORT_SYMBOL_GPL(unhash_nx_info);
21317 +
21318 diff -NurpP --minimal linux-3.1.1/kernel/vserver/proc.c linux-3.1.1-vs2.3.2/kernel/vserver/proc.c
21319 --- linux-3.1.1/kernel/vserver/proc.c   1970-01-01 01:00:00.000000000 +0100
21320 +++ linux-3.1.1-vs2.3.2/kernel/vserver/proc.c   2011-10-24 18:53:33.000000000 +0200
21321 @@ -0,0 +1,1103 @@
21322 +/*
21323 + *  linux/kernel/vserver/proc.c
21324 + *
21325 + *  Virtual Context Support
21326 + *
21327 + *  Copyright (C) 2003-2011  Herbert Pötzl
21328 + *
21329 + *  V0.01  basic structure
21330 + *  V0.02  adaptation vs1.3.0
21331 + *  V0.03  proc permissions
21332 + *  V0.04  locking/generic
21333 + *  V0.05  next generation procfs
21334 + *  V0.06  inode validation
21335 + *  V0.07  generic rewrite vid
21336 + *  V0.08  remove inode type
21337 + *  V0.09  added u/wmask info
21338 + *
21339 + */
21340 +
21341 +#include <linux/proc_fs.h>
21342 +#include <linux/fs_struct.h>
21343 +#include <linux/mount.h>
21344 +#include <asm/unistd.h>
21345 +
21346 +#include <linux/vs_context.h>
21347 +#include <linux/vs_network.h>
21348 +#include <linux/vs_cvirt.h>
21349 +
21350 +#include <linux/in.h>
21351 +#include <linux/inetdevice.h>
21352 +#include <linux/vs_inet.h>
21353 +#include <linux/vs_inet6.h>
21354 +
21355 +#include <linux/vserver/global.h>
21356 +
21357 +#include "cvirt_proc.h"
21358 +#include "cacct_proc.h"
21359 +#include "limit_proc.h"
21360 +#include "sched_proc.h"
21361 +#include "vci_config.h"
21362 +
21363 +
21364 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
21365 +{
21366 +       unsigned __capi;
21367 +
21368 +       CAP_FOR_EACH_U32(__capi) {
21369 +               buffer += sprintf(buffer, "%08x",
21370 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
21371 +       }
21372 +       return buffer;
21373 +}
21374 +
21375 +
21376 +static struct proc_dir_entry *proc_virtual;
21377 +
21378 +static struct proc_dir_entry *proc_virtnet;
21379 +
21380 +
21381 +/* first the actual feeds */
21382 +
21383 +
21384 +static int proc_vci(char *buffer)
21385 +{
21386 +       return sprintf(buffer,
21387 +               "VCIVersion:\t%04x:%04x\n"
21388 +               "VCISyscall:\t%d\n"
21389 +               "VCIKernel:\t%08x\n",
21390 +               VCI_VERSION >> 16,
21391 +               VCI_VERSION & 0xFFFF,
21392 +               __NR_vserver,
21393 +               vci_kernel_config());
21394 +}
21395 +
21396 +static int proc_virtual_info(char *buffer)
21397 +{
21398 +       return proc_vci(buffer);
21399 +}
21400 +
21401 +static int proc_virtual_status(char *buffer)
21402 +{
21403 +       return sprintf(buffer,
21404 +               "#CTotal:\t%d\n"
21405 +               "#CActive:\t%d\n"
21406 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
21407 +               "#InitTask:\t%d\t%d %d\n",
21408 +               atomic_read(&vx_global_ctotal),
21409 +               atomic_read(&vx_global_cactive),
21410 +               atomic_read(&vs_global_nsproxy),
21411 +               atomic_read(&vs_global_fs),
21412 +               atomic_read(&vs_global_mnt_ns),
21413 +               atomic_read(&vs_global_uts_ns),
21414 +               atomic_read(&nr_ipc_ns),
21415 +               atomic_read(&vs_global_user_ns),
21416 +               atomic_read(&vs_global_pid_ns),
21417 +               atomic_read(&init_task.usage),
21418 +               atomic_read(&init_task.nsproxy->count),
21419 +               init_task.fs->users);
21420 +}
21421 +
21422 +
21423 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
21424 +{
21425 +       int length;
21426 +
21427 +       length = sprintf(buffer,
21428 +               "ID:\t%d\n"
21429 +               "Info:\t%p\n"
21430 +               "Init:\t%d\n"
21431 +               "OOM:\t%lld\n",
21432 +               vxi->vx_id,
21433 +               vxi,
21434 +               vxi->vx_initpid,
21435 +               vxi->vx_badness_bias);
21436 +       return length;
21437 +}
21438 +
21439 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
21440 +{
21441 +       char *orig = buffer;
21442 +
21443 +       buffer += sprintf(buffer,
21444 +               "UseCnt:\t%d\n"
21445 +               "Tasks:\t%d\n"
21446 +               "Flags:\t%016llx\n",
21447 +               atomic_read(&vxi->vx_usecnt),
21448 +               atomic_read(&vxi->vx_tasks),
21449 +               (unsigned long long)vxi->vx_flags);
21450 +
21451 +       buffer += sprintf(buffer, "BCaps:\t");
21452 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21453 +       buffer += sprintf(buffer, "\n");
21454 +
21455 +       buffer += sprintf(buffer,
21456 +               "CCaps:\t%016llx\n"
21457 +               "Umask:\t%16llx\n"
21458 +               "Wmask:\t%16llx\n"
21459 +               "Spaces:\t%08lx %08lx\n",
21460 +               (unsigned long long)vxi->vx_ccaps,
21461 +               (unsigned long long)vxi->vx_umask,
21462 +               (unsigned long long)vxi->vx_wmask,
21463 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
21464 +       return buffer - orig;
21465 +}
21466 +
21467 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
21468 +{
21469 +       return vx_info_proc_limit(&vxi->limit, buffer);
21470 +}
21471 +
21472 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
21473 +{
21474 +       int cpu, length;
21475 +
21476 +       length = vx_info_proc_sched(&vxi->sched, buffer);
21477 +       for_each_online_cpu(cpu) {
21478 +               length += vx_info_proc_sched_pc(
21479 +                       &vx_per_cpu(vxi, sched_pc, cpu),
21480 +                       buffer + length, cpu);
21481 +       }
21482 +       return length;
21483 +}
21484 +
21485 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
21486 +{
21487 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
21488 +}
21489 +
21490 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
21491 +{
21492 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
21493 +}
21494 +
21495 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
21496 +{
21497 +       int cpu, length;
21498 +
21499 +       vx_update_load(vxi);
21500 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
21501 +       for_each_online_cpu(cpu) {
21502 +               length += vx_info_proc_cvirt_pc(
21503 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
21504 +                       buffer + length, cpu);
21505 +       }
21506 +       return length;
21507 +}
21508 +
21509 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
21510 +{
21511 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
21512 +}
21513 +
21514 +
21515 +static int proc_virtnet_info(char *buffer)
21516 +{
21517 +       return proc_vci(buffer);
21518 +}
21519 +
21520 +static int proc_virtnet_status(char *buffer)
21521 +{
21522 +       return sprintf(buffer,
21523 +               "#CTotal:\t%d\n"
21524 +               "#CActive:\t%d\n",
21525 +               atomic_read(&nx_global_ctotal),
21526 +               atomic_read(&nx_global_cactive));
21527 +}
21528 +
21529 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
21530 +{
21531 +       struct nx_addr_v4 *v4a;
21532 +#ifdef CONFIG_IPV6
21533 +       struct nx_addr_v6 *v6a;
21534 +#endif
21535 +       int length, i;
21536 +
21537 +       length = sprintf(buffer,
21538 +               "ID:\t%d\n"
21539 +               "Info:\t%p\n"
21540 +               "Bcast:\t" NIPQUAD_FMT "\n"
21541 +               "Lback:\t" NIPQUAD_FMT "\n",
21542 +               nxi->nx_id,
21543 +               nxi,
21544 +               NIPQUAD(nxi->v4_bcast.s_addr),
21545 +               NIPQUAD(nxi->v4_lback.s_addr));
21546 +
21547 +       if (!NX_IPV4(nxi))
21548 +               goto skip_v4;
21549 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21550 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
21551 +                       i, NXAV4(v4a));
21552 +skip_v4:
21553 +#ifdef CONFIG_IPV6
21554 +       if (!NX_IPV6(nxi))
21555 +               goto skip_v6;
21556 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21557 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
21558 +                       i, NXAV6(v6a));
21559 +skip_v6:
21560 +#endif
21561 +       return length;
21562 +}
21563 +
21564 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
21565 +{
21566 +       int length;
21567 +
21568 +       length = sprintf(buffer,
21569 +               "UseCnt:\t%d\n"
21570 +               "Tasks:\t%d\n"
21571 +               "Flags:\t%016llx\n"
21572 +               "NCaps:\t%016llx\n",
21573 +               atomic_read(&nxi->nx_usecnt),
21574 +               atomic_read(&nxi->nx_tasks),
21575 +               (unsigned long long)nxi->nx_flags,
21576 +               (unsigned long long)nxi->nx_ncaps);
21577 +       return length;
21578 +}
21579 +
21580 +
21581 +
21582 +/* here the inode helpers */
21583 +
21584 +struct vs_entry {
21585 +       int len;
21586 +       char *name;
21587 +       mode_t mode;
21588 +       struct inode_operations *iop;
21589 +       struct file_operations *fop;
21590 +       union proc_op op;
21591 +};
21592 +
21593 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
21594 +{
21595 +       struct inode *inode = new_inode(sb);
21596 +
21597 +       if (!inode)
21598 +               goto out;
21599 +
21600 +       inode->i_mode = p->mode;
21601 +       if (p->iop)
21602 +               inode->i_op = p->iop;
21603 +       if (p->fop)
21604 +               inode->i_fop = p->fop;
21605 +
21606 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
21607 +       inode->i_flags |= S_IMMUTABLE;
21608 +
21609 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
21610 +
21611 +       inode->i_uid = 0;
21612 +       inode->i_gid = 0;
21613 +       inode->i_tag = 0;
21614 +out:
21615 +       return inode;
21616 +}
21617 +
21618 +static struct dentry *vs_proc_instantiate(struct inode *dir,
21619 +       struct dentry *dentry, int id, void *ptr)
21620 +{
21621 +       struct vs_entry *p = ptr;
21622 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
21623 +       struct dentry *error = ERR_PTR(-EINVAL);
21624 +
21625 +       if (!inode)
21626 +               goto out;
21627 +
21628 +       PROC_I(inode)->op = p->op;
21629 +       PROC_I(inode)->fd = id;
21630 +       d_add(dentry, inode);
21631 +       error = NULL;
21632 +out:
21633 +       return error;
21634 +}
21635 +
21636 +/* Lookups */
21637 +
21638 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
21639 +
21640 +/*
21641 + * Fill a directory entry.
21642 + *
21643 + * If possible create the dcache entry and derive our inode number and
21644 + * file type from dcache entry.
21645 + *
21646 + * Since all of the proc inode numbers are dynamically generated, the inode
21647 + * numbers do not exist until the inode is cache.  This means creating the
21648 + * the dcache entry in readdir is necessary to keep the inode numbers
21649 + * reported by readdir in sync with the inode numbers reported
21650 + * by stat.
21651 + */
21652 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
21653 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
21654 +{
21655 +       struct dentry *child, *dir = filp->f_dentry;
21656 +       struct inode *inode;
21657 +       struct qstr qname;
21658 +       ino_t ino = 0;
21659 +       unsigned type = DT_UNKNOWN;
21660 +
21661 +       qname.name = name;
21662 +       qname.len  = len;
21663 +       qname.hash = full_name_hash(name, len);
21664 +
21665 +       child = d_lookup(dir, &qname);
21666 +       if (!child) {
21667 +               struct dentry *new;
21668 +               new = d_alloc(dir, &qname);
21669 +               if (new) {
21670 +                       child = instantiate(dir->d_inode, new, id, ptr);
21671 +                       if (child)
21672 +                               dput(new);
21673 +                       else
21674 +                               child = new;
21675 +               }
21676 +       }
21677 +       if (!child || IS_ERR(child) || !child->d_inode)
21678 +               goto end_instantiate;
21679 +       inode = child->d_inode;
21680 +       if (inode) {
21681 +               ino = inode->i_ino;
21682 +               type = inode->i_mode >> 12;
21683 +       }
21684 +       dput(child);
21685 +end_instantiate:
21686 +       if (!ino)
21687 +               ino = find_inode_number(dir, &qname);
21688 +       if (!ino)
21689 +               ino = 1;
21690 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
21691 +}
21692 +
21693 +
21694 +
21695 +/* get and revalidate vx_info/xid */
21696 +
21697 +static inline
21698 +struct vx_info *get_proc_vx_info(struct inode *inode)
21699 +{
21700 +       return lookup_vx_info(PROC_I(inode)->fd);
21701 +}
21702 +
21703 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
21704 +{
21705 +       struct inode *inode = dentry->d_inode;
21706 +       xid_t xid = PROC_I(inode)->fd;
21707 +
21708 +       if (!xid || xid_is_hashed(xid))
21709 +               return 1;
21710 +       d_drop(dentry);
21711 +       return 0;
21712 +}
21713 +
21714 +
21715 +/* get and revalidate nx_info/nid */
21716 +
21717 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
21718 +{
21719 +       struct inode *inode = dentry->d_inode;
21720 +       nid_t nid = PROC_I(inode)->fd;
21721 +
21722 +       if (!nid || nid_is_hashed(nid))
21723 +               return 1;
21724 +       d_drop(dentry);
21725 +       return 0;
21726 +}
21727 +
21728 +
21729 +
21730 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
21731 +
21732 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
21733 +                         size_t count, loff_t *ppos)
21734 +{
21735 +       struct inode *inode = file->f_dentry->d_inode;
21736 +       unsigned long page;
21737 +       ssize_t length = 0;
21738 +
21739 +       if (count > PROC_BLOCK_SIZE)
21740 +               count = PROC_BLOCK_SIZE;
21741 +
21742 +       /* fade that out as soon as stable */
21743 +       WARN_ON(PROC_I(inode)->fd);
21744 +
21745 +       if (!(page = __get_free_page(GFP_KERNEL)))
21746 +               return -ENOMEM;
21747 +
21748 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
21749 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
21750 +
21751 +       if (length >= 0)
21752 +               length = simple_read_from_buffer(buf, count, ppos,
21753 +                       (char *)page, length);
21754 +
21755 +       free_page(page);
21756 +       return length;
21757 +}
21758 +
21759 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
21760 +                         size_t count, loff_t *ppos)
21761 +{
21762 +       struct inode *inode = file->f_dentry->d_inode;
21763 +       struct vx_info *vxi = NULL;
21764 +       xid_t xid = PROC_I(inode)->fd;
21765 +       unsigned long page;
21766 +       ssize_t length = 0;
21767 +
21768 +       if (count > PROC_BLOCK_SIZE)
21769 +               count = PROC_BLOCK_SIZE;
21770 +
21771 +       /* fade that out as soon as stable */
21772 +       WARN_ON(!xid);
21773 +       vxi = lookup_vx_info(xid);
21774 +       if (!vxi)
21775 +               goto out;
21776 +
21777 +       length = -ENOMEM;
21778 +       if (!(page = __get_free_page(GFP_KERNEL)))
21779 +               goto out_put;
21780 +
21781 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
21782 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
21783 +
21784 +       if (length >= 0)
21785 +               length = simple_read_from_buffer(buf, count, ppos,
21786 +                       (char *)page, length);
21787 +
21788 +       free_page(page);
21789 +out_put:
21790 +       put_vx_info(vxi);
21791 +out:
21792 +       return length;
21793 +}
21794 +
21795 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
21796 +                         size_t count, loff_t *ppos)
21797 +{
21798 +       struct inode *inode = file->f_dentry->d_inode;
21799 +       struct nx_info *nxi = NULL;
21800 +       nid_t nid = PROC_I(inode)->fd;
21801 +       unsigned long page;
21802 +       ssize_t length = 0;
21803 +
21804 +       if (count > PROC_BLOCK_SIZE)
21805 +               count = PROC_BLOCK_SIZE;
21806 +
21807 +       /* fade that out as soon as stable */
21808 +       WARN_ON(!nid);
21809 +       nxi = lookup_nx_info(nid);
21810 +       if (!nxi)
21811 +               goto out;
21812 +
21813 +       length = -ENOMEM;
21814 +       if (!(page = __get_free_page(GFP_KERNEL)))
21815 +               goto out_put;
21816 +
21817 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
21818 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
21819 +
21820 +       if (length >= 0)
21821 +               length = simple_read_from_buffer(buf, count, ppos,
21822 +                       (char *)page, length);
21823 +
21824 +       free_page(page);
21825 +out_put:
21826 +       put_nx_info(nxi);
21827 +out:
21828 +       return length;
21829 +}
21830 +
21831 +
21832 +
21833 +/* here comes the lower level */
21834 +
21835 +
21836 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
21837 +       .len  = sizeof(NAME) - 1,       \
21838 +       .name = (NAME),                 \
21839 +       .mode = MODE,                   \
21840 +       .iop  = IOP,                    \
21841 +       .fop  = FOP,                    \
21842 +       .op   = OP,                     \
21843 +}
21844 +
21845 +
21846 +#define DIR(NAME, MODE, OTYPE)                         \
21847 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
21848 +               &proc_ ## OTYPE ## _inode_operations,   \
21849 +               &proc_ ## OTYPE ## _file_operations, { } )
21850 +
21851 +#define INF(NAME, MODE, OTYPE)                         \
21852 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21853 +               &proc_vs_info_file_operations,          \
21854 +               { .proc_vs_read = &proc_##OTYPE } )
21855 +
21856 +#define VINF(NAME, MODE, OTYPE)                                \
21857 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21858 +               &proc_vx_info_file_operations,          \
21859 +               { .proc_vxi_read = &proc_##OTYPE } )
21860 +
21861 +#define NINF(NAME, MODE, OTYPE)                                \
21862 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21863 +               &proc_nx_info_file_operations,          \
21864 +               { .proc_nxi_read = &proc_##OTYPE } )
21865 +
21866 +
21867 +static struct file_operations proc_vs_info_file_operations = {
21868 +       .read =         proc_vs_info_read,
21869 +};
21870 +
21871 +static struct file_operations proc_vx_info_file_operations = {
21872 +       .read =         proc_vx_info_read,
21873 +};
21874 +
21875 +static struct dentry_operations proc_xid_dentry_operations = {
21876 +       .d_revalidate = proc_xid_revalidate,
21877 +};
21878 +
21879 +static struct vs_entry vx_base_stuff[] = {
21880 +       VINF("info",    S_IRUGO, vxi_info),
21881 +       VINF("status",  S_IRUGO, vxi_status),
21882 +       VINF("limit",   S_IRUGO, vxi_limit),
21883 +       VINF("sched",   S_IRUGO, vxi_sched),
21884 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
21885 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
21886 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
21887 +       VINF("cacct",   S_IRUGO, vxi_cacct),
21888 +       {}
21889 +};
21890 +
21891 +
21892 +
21893 +
21894 +static struct dentry *proc_xid_instantiate(struct inode *dir,
21895 +       struct dentry *dentry, int id, void *ptr)
21896 +{
21897 +       dentry->d_op = &proc_xid_dentry_operations;
21898 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21899 +}
21900 +
21901 +static struct dentry *proc_xid_lookup(struct inode *dir,
21902 +       struct dentry *dentry, struct nameidata *nd)
21903 +{
21904 +       struct vs_entry *p = vx_base_stuff;
21905 +       struct dentry *error = ERR_PTR(-ENOENT);
21906 +
21907 +       for (; p->name; p++) {
21908 +               if (p->len != dentry->d_name.len)
21909 +                       continue;
21910 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21911 +                       break;
21912 +       }
21913 +       if (!p->name)
21914 +               goto out;
21915 +
21916 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21917 +out:
21918 +       return error;
21919 +}
21920 +
21921 +static int proc_xid_readdir(struct file *filp,
21922 +       void *dirent, filldir_t filldir)
21923 +{
21924 +       struct dentry *dentry = filp->f_dentry;
21925 +       struct inode *inode = dentry->d_inode;
21926 +       struct vs_entry *p = vx_base_stuff;
21927 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
21928 +       int pos, index;
21929 +       u64 ino;
21930 +
21931 +       pos = filp->f_pos;
21932 +       switch (pos) {
21933 +       case 0:
21934 +               ino = inode->i_ino;
21935 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21936 +                       goto out;
21937 +               pos++;
21938 +               /* fall through */
21939 +       case 1:
21940 +               ino = parent_ino(dentry);
21941 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21942 +                       goto out;
21943 +               pos++;
21944 +               /* fall through */
21945 +       default:
21946 +               index = pos - 2;
21947 +               if (index >= size)
21948 +                       goto out;
21949 +               for (p += index; p->name; p++) {
21950 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21951 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21952 +                               goto out;
21953 +                       pos++;
21954 +               }
21955 +       }
21956 +out:
21957 +       filp->f_pos = pos;
21958 +       return 1;
21959 +}
21960 +
21961 +
21962 +
21963 +static struct file_operations proc_nx_info_file_operations = {
21964 +       .read =         proc_nx_info_read,
21965 +};
21966 +
21967 +static struct dentry_operations proc_nid_dentry_operations = {
21968 +       .d_revalidate = proc_nid_revalidate,
21969 +};
21970 +
21971 +static struct vs_entry nx_base_stuff[] = {
21972 +       NINF("info",    S_IRUGO, nxi_info),
21973 +       NINF("status",  S_IRUGO, nxi_status),
21974 +       {}
21975 +};
21976 +
21977 +
21978 +static struct dentry *proc_nid_instantiate(struct inode *dir,
21979 +       struct dentry *dentry, int id, void *ptr)
21980 +{
21981 +       dentry->d_op = &proc_nid_dentry_operations;
21982 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21983 +}
21984 +
21985 +static struct dentry *proc_nid_lookup(struct inode *dir,
21986 +       struct dentry *dentry, struct nameidata *nd)
21987 +{
21988 +       struct vs_entry *p = nx_base_stuff;
21989 +       struct dentry *error = ERR_PTR(-ENOENT);
21990 +
21991 +       for (; p->name; p++) {
21992 +               if (p->len != dentry->d_name.len)
21993 +                       continue;
21994 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21995 +                       break;
21996 +       }
21997 +       if (!p->name)
21998 +               goto out;
21999 +
22000 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
22001 +out:
22002 +       return error;
22003 +}
22004 +
22005 +static int proc_nid_readdir(struct file *filp,
22006 +       void *dirent, filldir_t filldir)
22007 +{
22008 +       struct dentry *dentry = filp->f_dentry;
22009 +       struct inode *inode = dentry->d_inode;
22010 +       struct vs_entry *p = nx_base_stuff;
22011 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
22012 +       int pos, index;
22013 +       u64 ino;
22014 +
22015 +       pos = filp->f_pos;
22016 +       switch (pos) {
22017 +       case 0:
22018 +               ino = inode->i_ino;
22019 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22020 +                       goto out;
22021 +               pos++;
22022 +               /* fall through */
22023 +       case 1:
22024 +               ino = parent_ino(dentry);
22025 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22026 +                       goto out;
22027 +               pos++;
22028 +               /* fall through */
22029 +       default:
22030 +               index = pos - 2;
22031 +               if (index >= size)
22032 +                       goto out;
22033 +               for (p += index; p->name; p++) {
22034 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22035 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
22036 +                               goto out;
22037 +                       pos++;
22038 +               }
22039 +       }
22040 +out:
22041 +       filp->f_pos = pos;
22042 +       return 1;
22043 +}
22044 +
22045 +
22046 +#define MAX_MULBY10    ((~0U - 9) / 10)
22047 +
22048 +static inline int atovid(const char *str, int len)
22049 +{
22050 +       int vid, c;
22051 +
22052 +       vid = 0;
22053 +       while (len-- > 0) {
22054 +               c = *str - '0';
22055 +               str++;
22056 +               if (c > 9)
22057 +                       return -1;
22058 +               if (vid >= MAX_MULBY10)
22059 +                       return -1;
22060 +               vid *= 10;
22061 +               vid += c;
22062 +               if (!vid)
22063 +                       return -1;
22064 +       }
22065 +       return vid;
22066 +}
22067 +
22068 +/* now the upper level (virtual) */
22069 +
22070 +
22071 +static struct file_operations proc_xid_file_operations = {
22072 +       .read =         generic_read_dir,
22073 +       .readdir =      proc_xid_readdir,
22074 +};
22075 +
22076 +static struct inode_operations proc_xid_inode_operations = {
22077 +       .lookup =       proc_xid_lookup,
22078 +};
22079 +
22080 +static struct vs_entry vx_virtual_stuff[] = {
22081 +       INF("info",     S_IRUGO, virtual_info),
22082 +       INF("status",   S_IRUGO, virtual_status),
22083 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
22084 +};
22085 +
22086 +
22087 +static struct dentry *proc_virtual_lookup(struct inode *dir,
22088 +       struct dentry *dentry, struct nameidata *nd)
22089 +{
22090 +       struct vs_entry *p = vx_virtual_stuff;
22091 +       struct dentry *error = ERR_PTR(-ENOENT);
22092 +       int id = 0;
22093 +
22094 +       for (; p->name; p++) {
22095 +               if (p->len != dentry->d_name.len)
22096 +                       continue;
22097 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22098 +                       break;
22099 +       }
22100 +       if (p->name)
22101 +               goto instantiate;
22102 +
22103 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
22104 +       if ((id < 0) || !xid_is_hashed(id))
22105 +               goto out;
22106 +
22107 +instantiate:
22108 +       error = proc_xid_instantiate(dir, dentry, id, p);
22109 +out:
22110 +       return error;
22111 +}
22112 +
22113 +static struct file_operations proc_nid_file_operations = {
22114 +       .read =         generic_read_dir,
22115 +       .readdir =      proc_nid_readdir,
22116 +};
22117 +
22118 +static struct inode_operations proc_nid_inode_operations = {
22119 +       .lookup =       proc_nid_lookup,
22120 +};
22121 +
22122 +static struct vs_entry nx_virtnet_stuff[] = {
22123 +       INF("info",     S_IRUGO, virtnet_info),
22124 +       INF("status",   S_IRUGO, virtnet_status),
22125 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
22126 +};
22127 +
22128 +
22129 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
22130 +       struct dentry *dentry, struct nameidata *nd)
22131 +{
22132 +       struct vs_entry *p = nx_virtnet_stuff;
22133 +       struct dentry *error = ERR_PTR(-ENOENT);
22134 +       int id = 0;
22135 +
22136 +       for (; p->name; p++) {
22137 +               if (p->len != dentry->d_name.len)
22138 +                       continue;
22139 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22140 +                       break;
22141 +       }
22142 +       if (p->name)
22143 +               goto instantiate;
22144 +
22145 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
22146 +       if ((id < 0) || !nid_is_hashed(id))
22147 +               goto out;
22148 +
22149 +instantiate:
22150 +       error = proc_nid_instantiate(dir, dentry, id, p);
22151 +out:
22152 +       return error;
22153 +}
22154 +
22155 +
22156 +#define PROC_MAXVIDS 32
22157 +
22158 +int proc_virtual_readdir(struct file *filp,
22159 +       void *dirent, filldir_t filldir)
22160 +{
22161 +       struct dentry *dentry = filp->f_dentry;
22162 +       struct inode *inode = dentry->d_inode;
22163 +       struct vs_entry *p = vx_virtual_stuff;
22164 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
22165 +       int pos, index;
22166 +       unsigned int xid_array[PROC_MAXVIDS];
22167 +       char buf[PROC_NUMBUF];
22168 +       unsigned int nr_xids, i;
22169 +       u64 ino;
22170 +
22171 +       pos = filp->f_pos;
22172 +       switch (pos) {
22173 +       case 0:
22174 +               ino = inode->i_ino;
22175 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22176 +                       goto out;
22177 +               pos++;
22178 +               /* fall through */
22179 +       case 1:
22180 +               ino = parent_ino(dentry);
22181 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22182 +                       goto out;
22183 +               pos++;
22184 +               /* fall through */
22185 +       default:
22186 +               index = pos - 2;
22187 +               if (index >= size)
22188 +                       goto entries;
22189 +               for (p += index; p->name; p++) {
22190 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22191 +                               vs_proc_instantiate, 0, p))
22192 +                               goto out;
22193 +                       pos++;
22194 +               }
22195 +       entries:
22196 +               index = pos - size;
22197 +               p = &vx_virtual_stuff[size - 1];
22198 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
22199 +               for (i = 0; i < nr_xids; i++) {
22200 +                       int n, xid = xid_array[i];
22201 +                       unsigned int j = PROC_NUMBUF;
22202 +
22203 +                       n = xid;
22204 +                       do
22205 +                               buf[--j] = '0' + (n % 10);
22206 +                       while (n /= 10);
22207 +
22208 +                       if (proc_fill_cache(filp, dirent, filldir,
22209 +                               buf + j, PROC_NUMBUF - j,
22210 +                               vs_proc_instantiate, xid, p))
22211 +                               goto out;
22212 +                       pos++;
22213 +               }
22214 +       }
22215 +out:
22216 +       filp->f_pos = pos;
22217 +       return 0;
22218 +}
22219 +
22220 +static int proc_virtual_getattr(struct vfsmount *mnt,
22221 +       struct dentry *dentry, struct kstat *stat)
22222 +{
22223 +       struct inode *inode = dentry->d_inode;
22224 +
22225 +       generic_fillattr(inode, stat);
22226 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
22227 +       return 0;
22228 +}
22229 +
22230 +static struct file_operations proc_virtual_dir_operations = {
22231 +       .read =         generic_read_dir,
22232 +       .readdir =      proc_virtual_readdir,
22233 +};
22234 +
22235 +static struct inode_operations proc_virtual_dir_inode_operations = {
22236 +       .getattr =      proc_virtual_getattr,
22237 +       .lookup =       proc_virtual_lookup,
22238 +};
22239 +
22240 +
22241 +
22242 +
22243 +
22244 +int proc_virtnet_readdir(struct file *filp,
22245 +       void *dirent, filldir_t filldir)
22246 +{
22247 +       struct dentry *dentry = filp->f_dentry;
22248 +       struct inode *inode = dentry->d_inode;
22249 +       struct vs_entry *p = nx_virtnet_stuff;
22250 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
22251 +       int pos, index;
22252 +       unsigned int nid_array[PROC_MAXVIDS];
22253 +       char buf[PROC_NUMBUF];
22254 +       unsigned int nr_nids, i;
22255 +       u64 ino;
22256 +
22257 +       pos = filp->f_pos;
22258 +       switch (pos) {
22259 +       case 0:
22260 +               ino = inode->i_ino;
22261 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22262 +                       goto out;
22263 +               pos++;
22264 +               /* fall through */
22265 +       case 1:
22266 +               ino = parent_ino(dentry);
22267 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22268 +                       goto out;
22269 +               pos++;
22270 +               /* fall through */
22271 +       default:
22272 +               index = pos - 2;
22273 +               if (index >= size)
22274 +                       goto entries;
22275 +               for (p += index; p->name; p++) {
22276 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22277 +                               vs_proc_instantiate, 0, p))
22278 +                               goto out;
22279 +                       pos++;
22280 +               }
22281 +       entries:
22282 +               index = pos - size;
22283 +               p = &nx_virtnet_stuff[size - 1];
22284 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
22285 +               for (i = 0; i < nr_nids; i++) {
22286 +                       int n, nid = nid_array[i];
22287 +                       unsigned int j = PROC_NUMBUF;
22288 +
22289 +                       n = nid;
22290 +                       do
22291 +                               buf[--j] = '0' + (n % 10);
22292 +                       while (n /= 10);
22293 +
22294 +                       if (proc_fill_cache(filp, dirent, filldir,
22295 +                               buf + j, PROC_NUMBUF - j,
22296 +                               vs_proc_instantiate, nid, p))
22297 +                               goto out;
22298 +                       pos++;
22299 +               }
22300 +       }
22301 +out:
22302 +       filp->f_pos = pos;
22303 +       return 0;
22304 +}
22305 +
22306 +static int proc_virtnet_getattr(struct vfsmount *mnt,
22307 +       struct dentry *dentry, struct kstat *stat)
22308 +{
22309 +       struct inode *inode = dentry->d_inode;
22310 +
22311 +       generic_fillattr(inode, stat);
22312 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
22313 +       return 0;
22314 +}
22315 +
22316 +static struct file_operations proc_virtnet_dir_operations = {
22317 +       .read =         generic_read_dir,
22318 +       .readdir =      proc_virtnet_readdir,
22319 +};
22320 +
22321 +static struct inode_operations proc_virtnet_dir_inode_operations = {
22322 +       .getattr =      proc_virtnet_getattr,
22323 +       .lookup =       proc_virtnet_lookup,
22324 +};
22325 +
22326 +
22327 +
22328 +void proc_vx_init(void)
22329 +{
22330 +       struct proc_dir_entry *ent;
22331 +
22332 +       ent = proc_mkdir("virtual", 0);
22333 +       if (ent) {
22334 +               ent->proc_fops = &proc_virtual_dir_operations;
22335 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
22336 +       }
22337 +       proc_virtual = ent;
22338 +
22339 +       ent = proc_mkdir("virtnet", 0);
22340 +       if (ent) {
22341 +               ent->proc_fops = &proc_virtnet_dir_operations;
22342 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
22343 +       }
22344 +       proc_virtnet = ent;
22345 +}
22346 +
22347 +
22348 +
22349 +
22350 +/* per pid info */
22351 +
22352 +
22353 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
22354 +{
22355 +       struct vx_info *vxi;
22356 +       char *orig = buffer;
22357 +
22358 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
22359 +
22360 +       vxi = task_get_vx_info(p);
22361 +       if (!vxi)
22362 +               goto out;
22363 +
22364 +       buffer += sprintf(buffer, "BCaps:\t");
22365 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
22366 +       buffer += sprintf(buffer, "\n");
22367 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
22368 +               (unsigned long long)vxi->vx_ccaps);
22369 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
22370 +               (unsigned long long)vxi->vx_flags);
22371 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
22372 +
22373 +       put_vx_info(vxi);
22374 +out:
22375 +       return buffer - orig;
22376 +}
22377 +
22378 +
22379 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
22380 +{
22381 +       struct nx_info *nxi;
22382 +       struct nx_addr_v4 *v4a;
22383 +#ifdef CONFIG_IPV6
22384 +       struct nx_addr_v6 *v6a;
22385 +#endif
22386 +       char *orig = buffer;
22387 +       int i;
22388 +
22389 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
22390 +
22391 +       nxi = task_get_nx_info(p);
22392 +       if (!nxi)
22393 +               goto out;
22394 +
22395 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
22396 +               (unsigned long long)nxi->nx_ncaps);
22397 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
22398 +               (unsigned long long)nxi->nx_flags);
22399 +
22400 +       buffer += sprintf(buffer,
22401 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
22402 +               NIPQUAD(nxi->v4_bcast.s_addr));
22403 +       buffer += sprintf (buffer,
22404 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
22405 +               NIPQUAD(nxi->v4_lback.s_addr));
22406 +       if (!NX_IPV4(nxi))
22407 +               goto skip_v4;
22408 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22409 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
22410 +                       i, NXAV4(v4a));
22411 +skip_v4:
22412 +#ifdef CONFIG_IPV6
22413 +       if (!NX_IPV6(nxi))
22414 +               goto skip_v6;
22415 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22416 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
22417 +                       i, NXAV6(v6a));
22418 +skip_v6:
22419 +#endif
22420 +       put_nx_info(nxi);
22421 +out:
22422 +       return buffer - orig;
22423 +}
22424 +
22425 diff -NurpP --minimal linux-3.1.1/kernel/vserver/sched.c linux-3.1.1-vs2.3.2/kernel/vserver/sched.c
22426 --- linux-3.1.1/kernel/vserver/sched.c  1970-01-01 01:00:00.000000000 +0100
22427 +++ linux-3.1.1-vs2.3.2/kernel/vserver/sched.c  2011-10-24 18:53:33.000000000 +0200
22428 @@ -0,0 +1,82 @@
22429 +/*
22430 + *  linux/kernel/vserver/sched.c
22431 + *
22432 + *  Virtual Server: Scheduler Support
22433 + *
22434 + *  Copyright (C) 2004-2010  Herbert Pötzl
22435 + *
22436 + *  V0.01  adapted Sam Vilains version to 2.6.3
22437 + *  V0.02  removed legacy interface
22438 + *  V0.03  changed vcmds to vxi arg
22439 + *  V0.04  removed older and legacy interfaces
22440 + *  V0.05  removed scheduler code/commands
22441 + *
22442 + */
22443 +
22444 +#include <linux/vs_context.h>
22445 +#include <linux/vs_sched.h>
22446 +#include <linux/vserver/sched_cmd.h>
22447 +
22448 +#include <asm/uaccess.h>
22449 +
22450 +
22451 +void vx_update_sched_param(struct _vx_sched *sched,
22452 +       struct _vx_sched_pc *sched_pc)
22453 +{
22454 +       sched_pc->prio_bias = sched->prio_bias;
22455 +}
22456 +
22457 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
22458 +{
22459 +       int cpu;
22460 +
22461 +       if (data->prio_bias > MAX_PRIO_BIAS)
22462 +               data->prio_bias = MAX_PRIO_BIAS;
22463 +       if (data->prio_bias < MIN_PRIO_BIAS)
22464 +               data->prio_bias = MIN_PRIO_BIAS;
22465 +
22466 +       if (data->cpu_id != ~0) {
22467 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
22468 +               cpus_and(vxi->sched.update, cpu_online_map,
22469 +                       vxi->sched.update);
22470 +       } else
22471 +               vxi->sched.update = cpu_online_map;
22472 +
22473 +       for_each_cpu_mask(cpu, vxi->sched.update)
22474 +               vx_update_sched_param(&vxi->sched,
22475 +                       &vx_per_cpu(vxi, sched_pc, cpu));
22476 +       return 0;
22477 +}
22478 +
22479 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
22480 +{
22481 +       struct vcmd_prio_bias vc_data;
22482 +
22483 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22484 +               return -EFAULT;
22485 +
22486 +       return do_set_prio_bias(vxi, &vc_data);
22487 +}
22488 +
22489 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
22490 +{
22491 +       struct vcmd_prio_bias vc_data;
22492 +       struct _vx_sched_pc *pcd;
22493 +       int cpu;
22494 +
22495 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22496 +               return -EFAULT;
22497 +
22498 +       cpu = vc_data.cpu_id;
22499 +
22500 +       if (!cpu_possible(cpu))
22501 +               return -EINVAL;
22502 +
22503 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
22504 +       vc_data.prio_bias = pcd->prio_bias;
22505 +
22506 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22507 +               return -EFAULT;
22508 +       return 0;
22509 +}
22510 +
22511 diff -NurpP --minimal linux-3.1.1/kernel/vserver/sched_init.h linux-3.1.1-vs2.3.2/kernel/vserver/sched_init.h
22512 --- linux-3.1.1/kernel/vserver/sched_init.h     1970-01-01 01:00:00.000000000 +0100
22513 +++ linux-3.1.1-vs2.3.2/kernel/vserver/sched_init.h     2011-10-24 18:53:33.000000000 +0200
22514 @@ -0,0 +1,27 @@
22515 +
22516 +static inline void vx_info_init_sched(struct _vx_sched *sched)
22517 +{
22518 +       /* scheduling; hard code starting values as constants */
22519 +       sched->prio_bias = 0;
22520 +}
22521 +
22522 +static inline
22523 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22524 +{
22525 +       sched_pc->prio_bias = 0;
22526 +
22527 +       sched_pc->user_ticks = 0;
22528 +       sched_pc->sys_ticks = 0;
22529 +       sched_pc->hold_ticks = 0;
22530 +}
22531 +
22532 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
22533 +{
22534 +       return;
22535 +}
22536 +
22537 +static inline
22538 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22539 +{
22540 +       return;
22541 +}
22542 diff -NurpP --minimal linux-3.1.1/kernel/vserver/sched_proc.h linux-3.1.1-vs2.3.2/kernel/vserver/sched_proc.h
22543 --- linux-3.1.1/kernel/vserver/sched_proc.h     1970-01-01 01:00:00.000000000 +0100
22544 +++ linux-3.1.1-vs2.3.2/kernel/vserver/sched_proc.h     2011-10-24 18:53:33.000000000 +0200
22545 @@ -0,0 +1,32 @@
22546 +#ifndef _VX_SCHED_PROC_H
22547 +#define _VX_SCHED_PROC_H
22548 +
22549 +
22550 +static inline
22551 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
22552 +{
22553 +       int length = 0;
22554 +
22555 +       length += sprintf(buffer,
22556 +               "PrioBias:\t%8d\n",
22557 +               sched->prio_bias);
22558 +       return length;
22559 +}
22560 +
22561 +static inline
22562 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
22563 +       char *buffer, int cpu)
22564 +{
22565 +       int length = 0;
22566 +
22567 +       length += sprintf(buffer + length,
22568 +               "cpu %d: %lld %lld %lld", cpu,
22569 +               (unsigned long long)sched_pc->user_ticks,
22570 +               (unsigned long long)sched_pc->sys_ticks,
22571 +               (unsigned long long)sched_pc->hold_ticks);
22572 +       length += sprintf(buffer + length,
22573 +               " %d\n", sched_pc->prio_bias);
22574 +       return length;
22575 +}
22576 +
22577 +#endif /* _VX_SCHED_PROC_H */
22578 diff -NurpP --minimal linux-3.1.1/kernel/vserver/signal.c linux-3.1.1-vs2.3.2/kernel/vserver/signal.c
22579 --- linux-3.1.1/kernel/vserver/signal.c 1970-01-01 01:00:00.000000000 +0100
22580 +++ linux-3.1.1-vs2.3.2/kernel/vserver/signal.c 2011-10-24 18:53:33.000000000 +0200
22581 @@ -0,0 +1,134 @@
22582 +/*
22583 + *  linux/kernel/vserver/signal.c
22584 + *
22585 + *  Virtual Server: Signal Support
22586 + *
22587 + *  Copyright (C) 2003-2007  Herbert Pötzl
22588 + *
22589 + *  V0.01  broken out from vcontext V0.05
22590 + *  V0.02  changed vcmds to vxi arg
22591 + *  V0.03  adjusted siginfo for kill
22592 + *
22593 + */
22594 +
22595 +#include <asm/uaccess.h>
22596 +
22597 +#include <linux/vs_context.h>
22598 +#include <linux/vs_pid.h>
22599 +#include <linux/vserver/signal_cmd.h>
22600 +
22601 +
22602 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
22603 +{
22604 +       int retval, count = 0;
22605 +       struct task_struct *p;
22606 +       struct siginfo *sip = SEND_SIG_PRIV;
22607 +
22608 +       retval = -ESRCH;
22609 +       vxdprintk(VXD_CBIT(misc, 4),
22610 +               "vx_info_kill(%p[#%d],%d,%d)*",
22611 +               vxi, vxi->vx_id, pid, sig);
22612 +       read_lock(&tasklist_lock);
22613 +       switch (pid) {
22614 +       case  0:
22615 +       case -1:
22616 +               for_each_process(p) {
22617 +                       int err = 0;
22618 +
22619 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
22620 +                               (pid && vxi->vx_initpid == p->pid))
22621 +                               continue;
22622 +
22623 +                       err = group_send_sig_info(sig, sip, p);
22624 +                       ++count;
22625 +                       if (err != -EPERM)
22626 +                               retval = err;
22627 +               }
22628 +               break;
22629 +
22630 +       case 1:
22631 +               if (vxi->vx_initpid) {
22632 +                       pid = vxi->vx_initpid;
22633 +                       /* for now, only SIGINT to private init ... */
22634 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22635 +                               /* ... as long as there are tasks left */
22636 +                               (atomic_read(&vxi->vx_tasks) > 1))
22637 +                               sig = SIGINT;
22638 +               }
22639 +               /* fallthrough */
22640 +       default:
22641 +               rcu_read_lock();
22642 +               p = find_task_by_real_pid(pid);
22643 +               rcu_read_unlock();
22644 +               if (p) {
22645 +                       if (vx_task_xid(p) == vxi->vx_id)
22646 +                               retval = group_send_sig_info(sig, sip, p);
22647 +               }
22648 +               break;
22649 +       }
22650 +       read_unlock(&tasklist_lock);
22651 +       vxdprintk(VXD_CBIT(misc, 4),
22652 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
22653 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
22654 +       return retval;
22655 +}
22656 +
22657 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
22658 +{
22659 +       struct vcmd_ctx_kill_v0 vc_data;
22660 +
22661 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22662 +               return -EFAULT;
22663 +
22664 +       /* special check to allow guest shutdown */
22665 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22666 +               /* forbid killall pid=0 when init is present */
22667 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
22668 +               (vc_data.pid > 1)))
22669 +               return -EACCES;
22670 +
22671 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
22672 +}
22673 +
22674 +
22675 +static int __wait_exit(struct vx_info *vxi)
22676 +{
22677 +       DECLARE_WAITQUEUE(wait, current);
22678 +       int ret = 0;
22679 +
22680 +       add_wait_queue(&vxi->vx_wait, &wait);
22681 +       set_current_state(TASK_INTERRUPTIBLE);
22682 +
22683 +wait:
22684 +       if (vx_info_state(vxi,
22685 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
22686 +               goto out;
22687 +       if (signal_pending(current)) {
22688 +               ret = -ERESTARTSYS;
22689 +               goto out;
22690 +       }
22691 +       schedule();
22692 +       goto wait;
22693 +
22694 +out:
22695 +       set_current_state(TASK_RUNNING);
22696 +       remove_wait_queue(&vxi->vx_wait, &wait);
22697 +       return ret;
22698 +}
22699 +
22700 +
22701 +
22702 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
22703 +{
22704 +       struct vcmd_wait_exit_v0 vc_data;
22705 +       int ret;
22706 +
22707 +       ret = __wait_exit(vxi);
22708 +       vc_data.reboot_cmd = vxi->reboot_cmd;
22709 +       vc_data.exit_code = vxi->exit_code;
22710 +
22711 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22712 +               ret = -EFAULT;
22713 +       return ret;
22714 +}
22715 +
22716 diff -NurpP --minimal linux-3.1.1/kernel/vserver/space.c linux-3.1.1-vs2.3.2/kernel/vserver/space.c
22717 --- linux-3.1.1/kernel/vserver/space.c  1970-01-01 01:00:00.000000000 +0100
22718 +++ linux-3.1.1-vs2.3.2/kernel/vserver/space.c  2011-10-24 18:53:33.000000000 +0200
22719 @@ -0,0 +1,435 @@
22720 +/*
22721 + *  linux/kernel/vserver/space.c
22722 + *
22723 + *  Virtual Server: Context Space Support
22724 + *
22725 + *  Copyright (C) 2003-2010  Herbert Pötzl
22726 + *
22727 + *  V0.01  broken out from context.c 0.07
22728 + *  V0.02  added task locking for namespace
22729 + *  V0.03  broken out vx_enter_namespace
22730 + *  V0.04  added *space support and commands
22731 + *  V0.05  added credential support
22732 + *
22733 + */
22734 +
22735 +#include <linux/utsname.h>
22736 +#include <linux/nsproxy.h>
22737 +#include <linux/err.h>
22738 +#include <linux/fs_struct.h>
22739 +#include <linux/cred.h>
22740 +#include <asm/uaccess.h>
22741 +
22742 +#include <linux/vs_context.h>
22743 +#include <linux/vserver/space.h>
22744 +#include <linux/vserver/space_cmd.h>
22745 +
22746 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
22747 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
22748 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
22749 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
22750 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
22751 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
22752 +
22753 +
22754 +/* namespace functions */
22755 +
22756 +#include <linux/mnt_namespace.h>
22757 +#include <linux/user_namespace.h>
22758 +#include <linux/pid_namespace.h>
22759 +#include <linux/ipc_namespace.h>
22760 +#include <net/net_namespace.h>
22761 +
22762 +
22763 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
22764 +       .mask = CLONE_FS |
22765 +               CLONE_NEWNS |
22766 +#ifdef CONFIG_UTS_NS
22767 +               CLONE_NEWUTS |
22768 +#endif
22769 +#ifdef CONFIG_IPC_NS
22770 +               CLONE_NEWIPC |
22771 +#endif
22772 +#ifdef CONFIG_USER_NS
22773 +               CLONE_NEWUSER |
22774 +#endif
22775 +               0
22776 +};
22777 +
22778 +static const struct vcmd_space_mask_v1 space_mask = {
22779 +       .mask = CLONE_FS |
22780 +               CLONE_NEWNS |
22781 +#ifdef CONFIG_UTS_NS
22782 +               CLONE_NEWUTS |
22783 +#endif
22784 +#ifdef CONFIG_IPC_NS
22785 +               CLONE_NEWIPC |
22786 +#endif
22787 +#ifdef CONFIG_USER_NS
22788 +               CLONE_NEWUSER |
22789 +#endif
22790 +#ifdef CONFIG_PID_NS
22791 +               CLONE_NEWPID |
22792 +#endif
22793 +#ifdef CONFIG_NET_NS
22794 +               CLONE_NEWNET |
22795 +#endif
22796 +               0
22797 +};
22798 +
22799 +static const struct vcmd_space_mask_v1 default_space_mask = {
22800 +       .mask = CLONE_FS |
22801 +               CLONE_NEWNS |
22802 +#ifdef CONFIG_UTS_NS
22803 +               CLONE_NEWUTS |
22804 +#endif
22805 +#ifdef CONFIG_IPC_NS
22806 +               CLONE_NEWIPC |
22807 +#endif
22808 +#ifdef CONFIG_USER_NS
22809 +               CLONE_NEWUSER |
22810 +#endif
22811 +#ifdef CONFIG_PID_NS
22812 +//             CLONE_NEWPID |
22813 +#endif
22814 +               0
22815 +};
22816 +
22817 +/*
22818 + *     build a new nsproxy mix
22819 + *      assumes that both proxies are 'const'
22820 + *     does not touch nsproxy refcounts
22821 + *     will hold a reference on the result.
22822 + */
22823 +
22824 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
22825 +       struct nsproxy *new_nsproxy, unsigned long mask)
22826 +{
22827 +       struct mnt_namespace *old_ns;
22828 +       struct uts_namespace *old_uts;
22829 +       struct ipc_namespace *old_ipc;
22830 +#ifdef CONFIG_PID_NS
22831 +       struct pid_namespace *old_pid;
22832 +#endif
22833 +#ifdef CONFIG_NET_NS
22834 +       struct net *old_net;
22835 +#endif
22836 +       struct nsproxy *nsproxy;
22837 +
22838 +       nsproxy = copy_nsproxy(old_nsproxy);
22839 +       if (!nsproxy)
22840 +               goto out;
22841 +
22842 +       if (mask & CLONE_NEWNS) {
22843 +               old_ns = nsproxy->mnt_ns;
22844 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
22845 +               if (nsproxy->mnt_ns)
22846 +                       get_mnt_ns(nsproxy->mnt_ns);
22847 +       } else
22848 +               old_ns = NULL;
22849 +
22850 +       if (mask & CLONE_NEWUTS) {
22851 +               old_uts = nsproxy->uts_ns;
22852 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
22853 +               if (nsproxy->uts_ns)
22854 +                       get_uts_ns(nsproxy->uts_ns);
22855 +       } else
22856 +               old_uts = NULL;
22857 +
22858 +       if (mask & CLONE_NEWIPC) {
22859 +               old_ipc = nsproxy->ipc_ns;
22860 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
22861 +               if (nsproxy->ipc_ns)
22862 +                       get_ipc_ns(nsproxy->ipc_ns);
22863 +       } else
22864 +               old_ipc = NULL;
22865 +
22866 +#ifdef CONFIG_PID_NS
22867 +       if (mask & CLONE_NEWPID) {
22868 +               old_pid = nsproxy->pid_ns;
22869 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
22870 +               if (nsproxy->pid_ns)
22871 +                       get_pid_ns(nsproxy->pid_ns);
22872 +       } else
22873 +               old_pid = NULL;
22874 +#endif
22875 +#ifdef CONFIG_NET_NS
22876 +       if (mask & CLONE_NEWNET) {
22877 +               old_net = nsproxy->net_ns;
22878 +               nsproxy->net_ns = new_nsproxy->net_ns;
22879 +               if (nsproxy->net_ns)
22880 +                       get_net(nsproxy->net_ns);
22881 +       } else
22882 +               old_net = NULL;
22883 +#endif
22884 +       if (old_ns)
22885 +               put_mnt_ns(old_ns);
22886 +       if (old_uts)
22887 +               put_uts_ns(old_uts);
22888 +       if (old_ipc)
22889 +               put_ipc_ns(old_ipc);
22890 +#ifdef CONFIG_PID_NS
22891 +       if (old_pid)
22892 +               put_pid_ns(old_pid);
22893 +#endif
22894 +#ifdef CONFIG_NET_NS
22895 +       if (old_net)
22896 +               put_net(old_net);
22897 +#endif
22898 +out:
22899 +       return nsproxy;
22900 +}
22901 +
22902 +
22903 +/*
22904 + *     merge two nsproxy structs into a new one.
22905 + *     will hold a reference on the result.
22906 + */
22907 +
22908 +static inline
22909 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
22910 +       struct nsproxy *proxy, unsigned long mask)
22911 +{
22912 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
22913 +
22914 +       if (!proxy)
22915 +               return NULL;
22916 +
22917 +       if (mask) {
22918 +               /* vs_mix_nsproxy returns with reference */
22919 +               return vs_mix_nsproxy(old ? old : &null_proxy,
22920 +                       proxy, mask);
22921 +       }
22922 +       get_nsproxy(proxy);
22923 +       return proxy;
22924 +}
22925 +
22926 +
22927 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22928 +{
22929 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
22930 +       struct fs_struct *fs_cur, *fs = NULL;
22931 +       struct _vx_space *space;
22932 +       int ret, kill = 0;
22933 +
22934 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
22935 +               vxi, vxi->vx_id, mask, index);
22936 +
22937 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
22938 +               return -EACCES;
22939 +
22940 +       if (index >= VX_SPACES)
22941 +               return -EINVAL;
22942 +
22943 +       space = &vxi->space[index];
22944 +
22945 +       if (!mask)
22946 +               mask = space->vx_nsmask;
22947 +
22948 +       if ((mask & space->vx_nsmask) != mask)
22949 +               return -EINVAL;
22950 +
22951 +       if (mask & CLONE_FS) {
22952 +               fs = copy_fs_struct(space->vx_fs);
22953 +               if (!fs)
22954 +                       return -ENOMEM;
22955 +       }
22956 +       proxy = space->vx_nsproxy;
22957 +
22958 +       vxdprintk(VXD_CBIT(space, 9),
22959 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
22960 +               vxi, vxi->vx_id, mask, index, proxy, fs);
22961 +
22962 +       task_lock(current);
22963 +       fs_cur = current->fs;
22964 +
22965 +       if (mask & CLONE_FS) {
22966 +               spin_lock(&fs_cur->lock);
22967 +               current->fs = fs;
22968 +               kill = !--fs_cur->users;
22969 +               spin_unlock(&fs_cur->lock);
22970 +       }
22971 +
22972 +       proxy_cur = current->nsproxy;
22973 +       get_nsproxy(proxy_cur);
22974 +       task_unlock(current);
22975 +
22976 +       if (kill)
22977 +               free_fs_struct(fs_cur);
22978 +
22979 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
22980 +       if (IS_ERR(proxy_new)) {
22981 +               ret = PTR_ERR(proxy_new);
22982 +               goto out_put;
22983 +       }
22984 +
22985 +       proxy_new = xchg(&current->nsproxy, proxy_new);
22986 +
22987 +       if (mask & CLONE_NEWUSER) {
22988 +               struct cred *cred;
22989 +
22990 +               vxdprintk(VXD_CBIT(space, 10),
22991 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
22992 +                       vxi, vxi->vx_id, space->vx_cred,
22993 +                       current->real_cred, current->cred);
22994 +
22995 +               if (space->vx_cred) {
22996 +                       cred = __prepare_creds(space->vx_cred);
22997 +                       if (cred)
22998 +                               commit_creds(cred);
22999 +               }
23000 +       }
23001 +
23002 +       ret = 0;
23003 +
23004 +       if (proxy_new)
23005 +               put_nsproxy(proxy_new);
23006 +out_put:
23007 +       if (proxy_cur)
23008 +               put_nsproxy(proxy_cur);
23009 +       return ret;
23010 +}
23011 +
23012 +
23013 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
23014 +{
23015 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
23016 +       struct fs_struct *fs_vxi, *fs;
23017 +       struct _vx_space *space;
23018 +       int ret, kill = 0;
23019 +
23020 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
23021 +               vxi, vxi->vx_id, mask, index);
23022 +
23023 +       if ((mask & space_mask.mask) != mask)
23024 +               return -EINVAL;
23025 +
23026 +       if (index >= VX_SPACES)
23027 +               return -EINVAL;
23028 +
23029 +       space = &vxi->space[index];
23030 +
23031 +       proxy_vxi = space->vx_nsproxy;
23032 +       fs_vxi = space->vx_fs;
23033 +
23034 +       if (mask & CLONE_FS) {
23035 +               fs = copy_fs_struct(current->fs);
23036 +               if (!fs)
23037 +                       return -ENOMEM;
23038 +       }
23039 +
23040 +       task_lock(current);
23041 +
23042 +       if (mask & CLONE_FS) {
23043 +               spin_lock(&fs_vxi->lock);
23044 +               space->vx_fs = fs;
23045 +               kill = !--fs_vxi->users;
23046 +               spin_unlock(&fs_vxi->lock);
23047 +       }
23048 +
23049 +       proxy_cur = current->nsproxy;
23050 +       get_nsproxy(proxy_cur);
23051 +       task_unlock(current);
23052 +
23053 +       if (kill)
23054 +               free_fs_struct(fs_vxi);
23055 +
23056 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
23057 +       if (IS_ERR(proxy_new)) {
23058 +               ret = PTR_ERR(proxy_new);
23059 +               goto out_put;
23060 +       }
23061 +
23062 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
23063 +       space->vx_nsmask |= mask;
23064 +
23065 +       if (mask & CLONE_NEWUSER) {
23066 +               struct cred *cred;
23067 +
23068 +               vxdprintk(VXD_CBIT(space, 10),
23069 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
23070 +                       vxi, vxi->vx_id, space->vx_cred,
23071 +                       current->real_cred, current->cred);
23072 +
23073 +               cred = prepare_creds();
23074 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
23075 +               if (cred)
23076 +                       abort_creds(cred);
23077 +       }
23078 +
23079 +       ret = 0;
23080 +
23081 +       if (proxy_new)
23082 +               put_nsproxy(proxy_new);
23083 +out_put:
23084 +       if (proxy_cur)
23085 +               put_nsproxy(proxy_cur);
23086 +       return ret;
23087 +}
23088 +
23089 +
23090 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
23091 +{
23092 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
23093 +
23094 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23095 +               return -EFAULT;
23096 +
23097 +       return vx_enter_space(vxi, vc_data.mask, 0);
23098 +}
23099 +
23100 +int vc_enter_space(struct vx_info *vxi, void __user *data)
23101 +{
23102 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
23103 +
23104 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23105 +               return -EFAULT;
23106 +
23107 +       if (vc_data.index >= VX_SPACES)
23108 +               return -EINVAL;
23109 +
23110 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
23111 +}
23112 +
23113 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
23114 +{
23115 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
23116 +
23117 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23118 +               return -EFAULT;
23119 +
23120 +       return vx_set_space(vxi, vc_data.mask, 0);
23121 +}
23122 +
23123 +int vc_set_space(struct vx_info *vxi, void __user *data)
23124 +{
23125 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
23126 +
23127 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23128 +               return -EFAULT;
23129 +
23130 +       if (vc_data.index >= VX_SPACES)
23131 +               return -EINVAL;
23132 +
23133 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
23134 +}
23135 +
23136 +int vc_get_space_mask(void __user *data, int type)
23137 +{
23138 +       const struct vcmd_space_mask_v1 *mask;
23139 +
23140 +       if (type == 0)
23141 +               mask = &space_mask_v0;
23142 +       else if (type == 1)
23143 +               mask = &space_mask;
23144 +       else
23145 +               mask = &default_space_mask;
23146 +
23147 +       vxdprintk(VXD_CBIT(space, 10),
23148 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
23149 +
23150 +       if (copy_to_user(data, mask, sizeof(*mask)))
23151 +               return -EFAULT;
23152 +       return 0;
23153 +}
23154 +
23155 diff -NurpP --minimal linux-3.1.1/kernel/vserver/switch.c linux-3.1.1-vs2.3.2/kernel/vserver/switch.c
23156 --- linux-3.1.1/kernel/vserver/switch.c 1970-01-01 01:00:00.000000000 +0100
23157 +++ linux-3.1.1-vs2.3.2/kernel/vserver/switch.c 2011-10-24 18:53:33.000000000 +0200
23158 @@ -0,0 +1,556 @@
23159 +/*
23160 + *  linux/kernel/vserver/switch.c
23161 + *
23162 + *  Virtual Server: Syscall Switch
23163 + *
23164 + *  Copyright (C) 2003-2011  Herbert Pötzl
23165 + *
23166 + *  V0.01  syscall switch
23167 + *  V0.02  added signal to context
23168 + *  V0.03  added rlimit functions
23169 + *  V0.04  added iattr, task/xid functions
23170 + *  V0.05  added debug/history stuff
23171 + *  V0.06  added compat32 layer
23172 + *  V0.07  vcmd args and perms
23173 + *  V0.08  added status commands
23174 + *  V0.09  added tag commands
23175 + *  V0.10  added oom bias
23176 + *  V0.11  added device commands
23177 + *  V0.12  added warn mask
23178 + *
23179 + */
23180 +
23181 +#include <linux/vs_context.h>
23182 +#include <linux/vs_network.h>
23183 +#include <linux/vserver/switch.h>
23184 +
23185 +#include "vci_config.h"
23186 +
23187 +
23188 +static inline
23189 +int vc_get_version(uint32_t id)
23190 +{
23191 +       return VCI_VERSION;
23192 +}
23193 +
23194 +static inline
23195 +int vc_get_vci(uint32_t id)
23196 +{
23197 +       return vci_kernel_config();
23198 +}
23199 +
23200 +#include <linux/vserver/context_cmd.h>
23201 +#include <linux/vserver/cvirt_cmd.h>
23202 +#include <linux/vserver/cacct_cmd.h>
23203 +#include <linux/vserver/limit_cmd.h>
23204 +#include <linux/vserver/network_cmd.h>
23205 +#include <linux/vserver/sched_cmd.h>
23206 +#include <linux/vserver/debug_cmd.h>
23207 +#include <linux/vserver/inode_cmd.h>
23208 +#include <linux/vserver/dlimit_cmd.h>
23209 +#include <linux/vserver/signal_cmd.h>
23210 +#include <linux/vserver/space_cmd.h>
23211 +#include <linux/vserver/tag_cmd.h>
23212 +#include <linux/vserver/device_cmd.h>
23213 +
23214 +#include <linux/vserver/inode.h>
23215 +#include <linux/vserver/dlimit.h>
23216 +
23217 +
23218 +#ifdef CONFIG_COMPAT
23219 +#define __COMPAT(name, id, data, compat)       \
23220 +       (compat) ? name ## _x32(id, data) : name(id, data)
23221 +#define __COMPAT_NO_ID(name, data, compat)     \
23222 +       (compat) ? name ## _x32(data) : name(data)
23223 +#else
23224 +#define __COMPAT(name, id, data, compat)       \
23225 +       name(id, data)
23226 +#define __COMPAT_NO_ID(name, data, compat)     \
23227 +       name(data)
23228 +#endif
23229 +
23230 +
23231 +static inline
23232 +long do_vcmd(uint32_t cmd, uint32_t id,
23233 +       struct vx_info *vxi, struct nx_info *nxi,
23234 +       void __user *data, int compat)
23235 +{
23236 +       switch (cmd) {
23237 +
23238 +       case VCMD_get_version:
23239 +               return vc_get_version(id);
23240 +       case VCMD_get_vci:
23241 +               return vc_get_vci(id);
23242 +
23243 +       case VCMD_task_xid:
23244 +               return vc_task_xid(id);
23245 +       case VCMD_vx_info:
23246 +               return vc_vx_info(vxi, data);
23247 +
23248 +       case VCMD_task_nid:
23249 +               return vc_task_nid(id);
23250 +       case VCMD_nx_info:
23251 +               return vc_nx_info(nxi, data);
23252 +
23253 +       case VCMD_task_tag:
23254 +               return vc_task_tag(id);
23255 +
23256 +       case VCMD_set_space_v1:
23257 +               return vc_set_space_v1(vxi, data);
23258 +       /* this is version 2 */
23259 +       case VCMD_set_space:
23260 +               return vc_set_space(vxi, data);
23261 +
23262 +       case VCMD_get_space_mask_v0:
23263 +               return vc_get_space_mask(data, 0);
23264 +       /* this is version 1 */
23265 +       case VCMD_get_space_mask:
23266 +               return vc_get_space_mask(data, 1);
23267 +
23268 +       case VCMD_get_space_default:
23269 +               return vc_get_space_mask(data, -1);
23270 +
23271 +       case VCMD_set_umask:
23272 +               return vc_set_umask(vxi, data);
23273 +
23274 +       case VCMD_get_umask:
23275 +               return vc_get_umask(vxi, data);
23276 +
23277 +       case VCMD_set_wmask:
23278 +               return vc_set_wmask(vxi, data);
23279 +
23280 +       case VCMD_get_wmask:
23281 +               return vc_get_wmask(vxi, data);
23282 +#ifdef CONFIG_IA32_EMULATION
23283 +       case VCMD_get_rlimit:
23284 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
23285 +       case VCMD_set_rlimit:
23286 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
23287 +#else
23288 +       case VCMD_get_rlimit:
23289 +               return vc_get_rlimit(vxi, data);
23290 +       case VCMD_set_rlimit:
23291 +               return vc_set_rlimit(vxi, data);
23292 +#endif
23293 +       case VCMD_get_rlimit_mask:
23294 +               return vc_get_rlimit_mask(id, data);
23295 +       case VCMD_reset_hits:
23296 +               return vc_reset_hits(vxi, data);
23297 +       case VCMD_reset_minmax:
23298 +               return vc_reset_minmax(vxi, data);
23299 +
23300 +       case VCMD_get_vhi_name:
23301 +               return vc_get_vhi_name(vxi, data);
23302 +       case VCMD_set_vhi_name:
23303 +               return vc_set_vhi_name(vxi, data);
23304 +
23305 +       case VCMD_ctx_stat:
23306 +               return vc_ctx_stat(vxi, data);
23307 +       case VCMD_virt_stat:
23308 +               return vc_virt_stat(vxi, data);
23309 +       case VCMD_sock_stat:
23310 +               return vc_sock_stat(vxi, data);
23311 +       case VCMD_rlimit_stat:
23312 +               return vc_rlimit_stat(vxi, data);
23313 +
23314 +       case VCMD_set_cflags:
23315 +               return vc_set_cflags(vxi, data);
23316 +       case VCMD_get_cflags:
23317 +               return vc_get_cflags(vxi, data);
23318 +
23319 +       /* this is version 1 */
23320 +       case VCMD_set_ccaps:
23321 +               return vc_set_ccaps(vxi, data);
23322 +       /* this is version 1 */
23323 +       case VCMD_get_ccaps:
23324 +               return vc_get_ccaps(vxi, data);
23325 +       case VCMD_set_bcaps:
23326 +               return vc_set_bcaps(vxi, data);
23327 +       case VCMD_get_bcaps:
23328 +               return vc_get_bcaps(vxi, data);
23329 +
23330 +       case VCMD_set_badness:
23331 +               return vc_set_badness(vxi, data);
23332 +       case VCMD_get_badness:
23333 +               return vc_get_badness(vxi, data);
23334 +
23335 +       case VCMD_set_nflags:
23336 +               return vc_set_nflags(nxi, data);
23337 +       case VCMD_get_nflags:
23338 +               return vc_get_nflags(nxi, data);
23339 +
23340 +       case VCMD_set_ncaps:
23341 +               return vc_set_ncaps(nxi, data);
23342 +       case VCMD_get_ncaps:
23343 +               return vc_get_ncaps(nxi, data);
23344 +
23345 +       case VCMD_set_prio_bias:
23346 +               return vc_set_prio_bias(vxi, data);
23347 +       case VCMD_get_prio_bias:
23348 +               return vc_get_prio_bias(vxi, data);
23349 +       case VCMD_add_dlimit:
23350 +               return __COMPAT(vc_add_dlimit, id, data, compat);
23351 +       case VCMD_rem_dlimit:
23352 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
23353 +       case VCMD_set_dlimit:
23354 +               return __COMPAT(vc_set_dlimit, id, data, compat);
23355 +       case VCMD_get_dlimit:
23356 +               return __COMPAT(vc_get_dlimit, id, data, compat);
23357 +
23358 +       case VCMD_ctx_kill:
23359 +               return vc_ctx_kill(vxi, data);
23360 +
23361 +       case VCMD_wait_exit:
23362 +               return vc_wait_exit(vxi, data);
23363 +
23364 +       case VCMD_get_iattr:
23365 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
23366 +       case VCMD_set_iattr:
23367 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
23368 +
23369 +       case VCMD_fget_iattr:
23370 +               return vc_fget_iattr(id, data);
23371 +       case VCMD_fset_iattr:
23372 +               return vc_fset_iattr(id, data);
23373 +
23374 +       case VCMD_enter_space_v0:
23375 +               return vc_enter_space_v1(vxi, NULL);
23376 +       case VCMD_enter_space_v1:
23377 +               return vc_enter_space_v1(vxi, data);
23378 +       /* this is version 2 */
23379 +       case VCMD_enter_space:
23380 +               return vc_enter_space(vxi, data);
23381 +
23382 +       case VCMD_ctx_create_v0:
23383 +               return vc_ctx_create(id, NULL);
23384 +       case VCMD_ctx_create:
23385 +               return vc_ctx_create(id, data);
23386 +       case VCMD_ctx_migrate_v0:
23387 +               return vc_ctx_migrate(vxi, NULL);
23388 +       case VCMD_ctx_migrate:
23389 +               return vc_ctx_migrate(vxi, data);
23390 +
23391 +       case VCMD_net_create_v0:
23392 +               return vc_net_create(id, NULL);
23393 +       case VCMD_net_create:
23394 +               return vc_net_create(id, data);
23395 +       case VCMD_net_migrate:
23396 +               return vc_net_migrate(nxi, data);
23397 +
23398 +       case VCMD_tag_migrate:
23399 +               return vc_tag_migrate(id);
23400 +
23401 +       case VCMD_net_add:
23402 +               return vc_net_add(nxi, data);
23403 +       case VCMD_net_remove:
23404 +               return vc_net_remove(nxi, data);
23405 +
23406 +       case VCMD_net_add_ipv4_v1:
23407 +               return vc_net_add_ipv4_v1(nxi, data);
23408 +       /* this is version 2 */
23409 +       case VCMD_net_add_ipv4:
23410 +               return vc_net_add_ipv4(nxi, data);
23411 +
23412 +       case VCMD_net_rem_ipv4_v1:
23413 +               return vc_net_rem_ipv4_v1(nxi, data);
23414 +       /* this is version 2 */
23415 +       case VCMD_net_rem_ipv4:
23416 +               return vc_net_rem_ipv4(nxi, data);
23417 +#ifdef CONFIG_IPV6
23418 +       case VCMD_net_add_ipv6:
23419 +               return vc_net_add_ipv6(nxi, data);
23420 +       case VCMD_net_remove_ipv6:
23421 +               return vc_net_remove_ipv6(nxi, data);
23422 +#endif
23423 +/*     case VCMD_add_match_ipv4:
23424 +               return vc_add_match_ipv4(nxi, data);
23425 +       case VCMD_get_match_ipv4:
23426 +               return vc_get_match_ipv4(nxi, data);
23427 +#ifdef CONFIG_IPV6
23428 +       case VCMD_add_match_ipv6:
23429 +               return vc_add_match_ipv6(nxi, data);
23430 +       case VCMD_get_match_ipv6:
23431 +               return vc_get_match_ipv6(nxi, data);
23432 +#endif */
23433 +
23434 +#ifdef CONFIG_VSERVER_DEVICE
23435 +       case VCMD_set_mapping:
23436 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
23437 +       case VCMD_unset_mapping:
23438 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
23439 +#endif
23440 +#ifdef CONFIG_VSERVER_HISTORY
23441 +       case VCMD_dump_history:
23442 +               return vc_dump_history(id);
23443 +       case VCMD_read_history:
23444 +               return __COMPAT(vc_read_history, id, data, compat);
23445 +#endif
23446 +       default:
23447 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
23448 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
23449 +       }
23450 +       return -ENOSYS;
23451 +}
23452 +
23453 +
23454 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
23455 +       case VCMD_ ## vcmd: perm = _perm;               \
23456 +               args = _args; flags = _flags; break
23457 +
23458 +
23459 +#define VCA_NONE       0x00
23460 +#define VCA_VXI                0x01
23461 +#define VCA_NXI                0x02
23462 +
23463 +#define VCF_NONE       0x00
23464 +#define VCF_INFO       0x01
23465 +#define VCF_ADMIN      0x02
23466 +#define VCF_ARES       0x06    /* includes admin */
23467 +#define VCF_SETUP      0x08
23468 +
23469 +#define VCF_ZIDOK      0x10    /* zero id okay */
23470 +
23471 +
23472 +static inline
23473 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
23474 +{
23475 +       long ret;
23476 +       int permit = -1, state = 0;
23477 +       int perm = -1, args = 0, flags = 0;
23478 +       struct vx_info *vxi = NULL;
23479 +       struct nx_info *nxi = NULL;
23480 +
23481 +       switch (cmd) {
23482 +       /* unpriviledged commands */
23483 +       __VCMD(get_version,      0, VCA_NONE,   0);
23484 +       __VCMD(get_vci,          0, VCA_NONE,   0);
23485 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
23486 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
23487 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
23488 +       __VCMD(get_space_default,0, VCA_NONE,   0);
23489 +
23490 +       /* info commands */
23491 +       __VCMD(task_xid,         2, VCA_NONE,   0);
23492 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
23493 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
23494 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
23495 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
23496 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
23497 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
23498 +       __VCMD(get_umask,        3, VCA_VXI,    VCF_INFO);
23499 +       __VCMD(get_wmask,        3, VCA_VXI,    VCF_INFO);
23500 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
23501 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
23502 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
23503 +
23504 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
23505 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
23506 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
23507 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
23508 +
23509 +       __VCMD(task_nid,         2, VCA_NONE,   0);
23510 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
23511 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
23512 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
23513 +
23514 +       __VCMD(task_tag,         2, VCA_NONE,   0);
23515 +
23516 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
23517 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
23518 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
23519 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
23520 +
23521 +       /* lower admin commands */
23522 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
23523 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
23524 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
23525 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
23526 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
23527 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
23528 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
23529 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
23530 +
23531 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
23532 +       __VCMD(net_create,       5, VCA_NONE,   0);
23533 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
23534 +
23535 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
23536 +
23537 +       /* higher admin commands */
23538 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
23539 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23540 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23541 +
23542 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23543 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23544 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23545 +       __VCMD(set_umask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23546 +       __VCMD(set_wmask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23547 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23548 +
23549 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23550 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23551 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23552 +
23553 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23554 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23555 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23556 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23557 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23558 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23559 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23560 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23561 +#ifdef CONFIG_IPV6
23562 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23563 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23564 +#endif
23565 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
23566 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
23567 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
23568 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
23569 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
23570 +
23571 +#ifdef CONFIG_VSERVER_DEVICE
23572 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23573 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23574 +#endif
23575 +       /* debug level admin commands */
23576 +#ifdef CONFIG_VSERVER_HISTORY
23577 +       __VCMD(dump_history,     9, VCA_NONE,   0);
23578 +       __VCMD(read_history,     9, VCA_NONE,   0);
23579 +#endif
23580 +
23581 +       default:
23582 +               perm = -1;
23583 +       }
23584 +
23585 +       vxdprintk(VXD_CBIT(switch, 0),
23586 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
23587 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23588 +               VC_VERSION(cmd), id, data, compat,
23589 +               perm, args, flags);
23590 +
23591 +       ret = -ENOSYS;
23592 +       if (perm < 0)
23593 +               goto out;
23594 +
23595 +       state = 1;
23596 +       if (!capable(CAP_CONTEXT))
23597 +               goto out;
23598 +
23599 +       state = 2;
23600 +       /* moved here from the individual commands */
23601 +       ret = -EPERM;
23602 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
23603 +               goto out;
23604 +
23605 +       state = 3;
23606 +       /* vcmd involves resource management  */
23607 +       ret = -EPERM;
23608 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
23609 +               goto out;
23610 +
23611 +       state = 4;
23612 +       /* various legacy exceptions */
23613 +       switch (cmd) {
23614 +       /* will go away when spectator is a cap */
23615 +       case VCMD_ctx_migrate_v0:
23616 +       case VCMD_ctx_migrate:
23617 +               if (id == 1) {
23618 +                       current->xid = 1;
23619 +                       ret = 1;
23620 +                       goto out;
23621 +               }
23622 +               break;
23623 +
23624 +       /* will go away when spectator is a cap */
23625 +       case VCMD_net_migrate:
23626 +               if (id == 1) {
23627 +                       current->nid = 1;
23628 +                       ret = 1;
23629 +                       goto out;
23630 +               }
23631 +               break;
23632 +       }
23633 +
23634 +       /* vcmds are fine by default */
23635 +       permit = 1;
23636 +
23637 +       /* admin type vcmds require admin ... */
23638 +       if (flags & VCF_ADMIN)
23639 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
23640 +
23641 +       /* ... but setup type vcmds override that */
23642 +       if (!permit && (flags & VCF_SETUP))
23643 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
23644 +
23645 +       state = 5;
23646 +       ret = -EPERM;
23647 +       if (!permit)
23648 +               goto out;
23649 +
23650 +       state = 6;
23651 +       if (!id && (flags & VCF_ZIDOK))
23652 +               goto skip_id;
23653 +
23654 +       ret = -ESRCH;
23655 +       if (args & VCA_VXI) {
23656 +               vxi = lookup_vx_info(id);
23657 +               if (!vxi)
23658 +                       goto out;
23659 +
23660 +               if ((flags & VCF_ADMIN) &&
23661 +                       /* special case kill for shutdown */
23662 +                       (cmd != VCMD_ctx_kill) &&
23663 +                       /* can context be administrated? */
23664 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
23665 +                       ret = -EACCES;
23666 +                       goto out_vxi;
23667 +               }
23668 +       }
23669 +       state = 7;
23670 +       if (args & VCA_NXI) {
23671 +               nxi = lookup_nx_info(id);
23672 +               if (!nxi)
23673 +                       goto out_vxi;
23674 +
23675 +               if ((flags & VCF_ADMIN) &&
23676 +                       /* can context be administrated? */
23677 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
23678 +                       ret = -EACCES;
23679 +                       goto out_nxi;
23680 +               }
23681 +       }
23682 +skip_id:
23683 +       state = 8;
23684 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
23685 +
23686 +out_nxi:
23687 +       if ((args & VCA_NXI) && nxi)
23688 +               put_nx_info(nxi);
23689 +out_vxi:
23690 +       if ((args & VCA_VXI) && vxi)
23691 +               put_vx_info(vxi);
23692 +out:
23693 +       vxdprintk(VXD_CBIT(switch, 1),
23694 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
23695 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23696 +               VC_VERSION(cmd), ret, ret, state, permit);
23697 +       return ret;
23698 +}
23699 +
23700 +asmlinkage long
23701 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
23702 +{
23703 +       return do_vserver(cmd, id, data, 0);
23704 +}
23705 +
23706 +#ifdef CONFIG_COMPAT
23707 +
23708 +asmlinkage long
23709 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
23710 +{
23711 +       return do_vserver(cmd, id, data, 1);
23712 +}
23713 +
23714 +#endif /* CONFIG_COMPAT */
23715 diff -NurpP --minimal linux-3.1.1/kernel/vserver/sysctl.c linux-3.1.1-vs2.3.2/kernel/vserver/sysctl.c
23716 --- linux-3.1.1/kernel/vserver/sysctl.c 1970-01-01 01:00:00.000000000 +0100
23717 +++ linux-3.1.1-vs2.3.2/kernel/vserver/sysctl.c 2011-10-24 18:53:33.000000000 +0200
23718 @@ -0,0 +1,241 @@
23719 +/*
23720 + *  kernel/vserver/sysctl.c
23721 + *
23722 + *  Virtual Context Support
23723 + *
23724 + *  Copyright (C) 2004-2007  Herbert Pötzl
23725 + *
23726 + *  V0.01  basic structure
23727 + *
23728 + */
23729 +
23730 +#include <linux/module.h>
23731 +#include <linux/ctype.h>
23732 +#include <linux/sysctl.h>
23733 +#include <linux/parser.h>
23734 +#include <asm/uaccess.h>
23735 +
23736 +enum {
23737 +       CTL_DEBUG_ERROR         = 0,
23738 +       CTL_DEBUG_SWITCH        = 1,
23739 +       CTL_DEBUG_XID,
23740 +       CTL_DEBUG_NID,
23741 +       CTL_DEBUG_TAG,
23742 +       CTL_DEBUG_NET,
23743 +       CTL_DEBUG_LIMIT,
23744 +       CTL_DEBUG_CRES,
23745 +       CTL_DEBUG_DLIM,
23746 +       CTL_DEBUG_QUOTA,
23747 +       CTL_DEBUG_CVIRT,
23748 +       CTL_DEBUG_SPACE,
23749 +       CTL_DEBUG_MISC,
23750 +};
23751 +
23752 +
23753 +unsigned int vx_debug_switch   = 0;
23754 +unsigned int vx_debug_xid      = 0;
23755 +unsigned int vx_debug_nid      = 0;
23756 +unsigned int vx_debug_tag      = 0;
23757 +unsigned int vx_debug_net      = 0;
23758 +unsigned int vx_debug_limit    = 0;
23759 +unsigned int vx_debug_cres     = 0;
23760 +unsigned int vx_debug_dlim     = 0;
23761 +unsigned int vx_debug_quota    = 0;
23762 +unsigned int vx_debug_cvirt    = 0;
23763 +unsigned int vx_debug_space    = 0;
23764 +unsigned int vx_debug_misc     = 0;
23765 +
23766 +
23767 +static struct ctl_table_header *vserver_table_header;
23768 +static ctl_table vserver_root_table[];
23769 +
23770 +
23771 +void vserver_register_sysctl(void)
23772 +{
23773 +       if (!vserver_table_header) {
23774 +               vserver_table_header = register_sysctl_table(vserver_root_table);
23775 +       }
23776 +
23777 +}
23778 +
23779 +void vserver_unregister_sysctl(void)
23780 +{
23781 +       if (vserver_table_header) {
23782 +               unregister_sysctl_table(vserver_table_header);
23783 +               vserver_table_header = NULL;
23784 +       }
23785 +}
23786 +
23787 +
23788 +static int proc_dodebug(ctl_table *table, int write,
23789 +       void __user *buffer, size_t *lenp, loff_t *ppos)
23790 +{
23791 +       char            tmpbuf[20], *p, c;
23792 +       unsigned int    value;
23793 +       size_t          left, len;
23794 +
23795 +       if ((*ppos && !write) || !*lenp) {
23796 +               *lenp = 0;
23797 +               return 0;
23798 +       }
23799 +
23800 +       left = *lenp;
23801 +
23802 +       if (write) {
23803 +               if (!access_ok(VERIFY_READ, buffer, left))
23804 +                       return -EFAULT;
23805 +               p = (char *)buffer;
23806 +               while (left && __get_user(c, p) >= 0 && isspace(c))
23807 +                       left--, p++;
23808 +               if (!left)
23809 +                       goto done;
23810 +
23811 +               if (left > sizeof(tmpbuf) - 1)
23812 +                       return -EINVAL;
23813 +               if (copy_from_user(tmpbuf, p, left))
23814 +                       return -EFAULT;
23815 +               tmpbuf[left] = '\0';
23816 +
23817 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
23818 +                       value = 10 * value + (*p - '0');
23819 +               if (*p && !isspace(*p))
23820 +                       return -EINVAL;
23821 +               while (left && isspace(*p))
23822 +                       left--, p++;
23823 +               *(unsigned int *)table->data = value;
23824 +       } else {
23825 +               if (!access_ok(VERIFY_WRITE, buffer, left))
23826 +                       return -EFAULT;
23827 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
23828 +               if (len > left)
23829 +                       len = left;
23830 +               if (__copy_to_user(buffer, tmpbuf, len))
23831 +                       return -EFAULT;
23832 +               if ((left -= len) > 0) {
23833 +                       if (put_user('\n', (char *)buffer + len))
23834 +                               return -EFAULT;
23835 +                       left--;
23836 +               }
23837 +       }
23838 +
23839 +done:
23840 +       *lenp -= left;
23841 +       *ppos += *lenp;
23842 +       return 0;
23843 +}
23844 +
23845 +static int zero;
23846 +
23847 +#define        CTL_ENTRY(ctl, name)                            \
23848 +       {                                               \
23849 +               .procname       = #name,                \
23850 +               .data           = &vx_ ## name,         \
23851 +               .maxlen         = sizeof(int),          \
23852 +               .mode           = 0644,                 \
23853 +               .proc_handler   = &proc_dodebug,        \
23854 +               .extra1         = &zero,                \
23855 +               .extra2         = &zero,                \
23856 +       }
23857 +
23858 +static ctl_table vserver_debug_table[] = {
23859 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
23860 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
23861 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
23862 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
23863 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
23864 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
23865 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
23866 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
23867 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
23868 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
23869 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
23870 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
23871 +       { 0 }
23872 +};
23873 +
23874 +static ctl_table vserver_root_table[] = {
23875 +       {
23876 +               .procname       = "vserver",
23877 +               .mode           = 0555,
23878 +               .child          = vserver_debug_table
23879 +       },
23880 +       { 0 }
23881 +};
23882 +
23883 +
23884 +static match_table_t tokens = {
23885 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
23886 +       { CTL_DEBUG_XID,        "xid=%x"        },
23887 +       { CTL_DEBUG_NID,        "nid=%x"        },
23888 +       { CTL_DEBUG_TAG,        "tag=%x"        },
23889 +       { CTL_DEBUG_NET,        "net=%x"        },
23890 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
23891 +       { CTL_DEBUG_CRES,       "cres=%x"       },
23892 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
23893 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
23894 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
23895 +       { CTL_DEBUG_SPACE,      "space=%x"      },
23896 +       { CTL_DEBUG_MISC,       "misc=%x"       },
23897 +       { CTL_DEBUG_ERROR,      NULL            }
23898 +};
23899 +
23900 +#define        HANDLE_CASE(id, name, val)                              \
23901 +       case CTL_DEBUG_ ## id:                                  \
23902 +               vx_debug_ ## name = val;                        \
23903 +               printk("vs_debug_" #name "=0x%x\n", val);       \
23904 +               break
23905 +
23906 +
23907 +static int __init vs_debug_setup(char *str)
23908 +{
23909 +       char *p;
23910 +       int token;
23911 +
23912 +       printk("vs_debug_setup(%s)\n", str);
23913 +       while ((p = strsep(&str, ",")) != NULL) {
23914 +               substring_t args[MAX_OPT_ARGS];
23915 +               unsigned int value;
23916 +
23917 +               if (!*p)
23918 +                       continue;
23919 +
23920 +               token = match_token(p, tokens, args);
23921 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
23922 +
23923 +               switch (token) {
23924 +               HANDLE_CASE(SWITCH, switch, value);
23925 +               HANDLE_CASE(XID,    xid,    value);
23926 +               HANDLE_CASE(NID,    nid,    value);
23927 +               HANDLE_CASE(TAG,    tag,    value);
23928 +               HANDLE_CASE(NET,    net,    value);
23929 +               HANDLE_CASE(LIMIT,  limit,  value);
23930 +               HANDLE_CASE(CRES,   cres,   value);
23931 +               HANDLE_CASE(DLIM,   dlim,   value);
23932 +               HANDLE_CASE(QUOTA,  quota,  value);
23933 +               HANDLE_CASE(CVIRT,  cvirt,  value);
23934 +               HANDLE_CASE(SPACE,  space,  value);
23935 +               HANDLE_CASE(MISC,   misc,   value);
23936 +               default:
23937 +                       return -EINVAL;
23938 +                       break;
23939 +               }
23940 +       }
23941 +       return 1;
23942 +}
23943 +
23944 +__setup("vsdebug=", vs_debug_setup);
23945 +
23946 +
23947 +
23948 +EXPORT_SYMBOL_GPL(vx_debug_switch);
23949 +EXPORT_SYMBOL_GPL(vx_debug_xid);
23950 +EXPORT_SYMBOL_GPL(vx_debug_nid);
23951 +EXPORT_SYMBOL_GPL(vx_debug_net);
23952 +EXPORT_SYMBOL_GPL(vx_debug_limit);
23953 +EXPORT_SYMBOL_GPL(vx_debug_cres);
23954 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
23955 +EXPORT_SYMBOL_GPL(vx_debug_quota);
23956 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
23957 +EXPORT_SYMBOL_GPL(vx_debug_space);
23958 +EXPORT_SYMBOL_GPL(vx_debug_misc);
23959 +
23960 diff -NurpP --minimal linux-3.1.1/kernel/vserver/tag.c linux-3.1.1-vs2.3.2/kernel/vserver/tag.c
23961 --- linux-3.1.1/kernel/vserver/tag.c    1970-01-01 01:00:00.000000000 +0100
23962 +++ linux-3.1.1-vs2.3.2/kernel/vserver/tag.c    2011-10-24 18:53:33.000000000 +0200
23963 @@ -0,0 +1,63 @@
23964 +/*
23965 + *  linux/kernel/vserver/tag.c
23966 + *
23967 + *  Virtual Server: Shallow Tag Space
23968 + *
23969 + *  Copyright (C) 2007  Herbert Pötzl
23970 + *
23971 + *  V0.01  basic implementation
23972 + *
23973 + */
23974 +
23975 +#include <linux/sched.h>
23976 +#include <linux/vserver/debug.h>
23977 +#include <linux/vs_pid.h>
23978 +#include <linux/vs_tag.h>
23979 +
23980 +#include <linux/vserver/tag_cmd.h>
23981 +
23982 +
23983 +int dx_migrate_task(struct task_struct *p, tag_t tag)
23984 +{
23985 +       if (!p)
23986 +               BUG();
23987 +
23988 +       vxdprintk(VXD_CBIT(tag, 5),
23989 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
23990 +
23991 +       task_lock(p);
23992 +       p->tag = tag;
23993 +       task_unlock(p);
23994 +
23995 +       vxdprintk(VXD_CBIT(tag, 5),
23996 +               "moved task %p into [#%d]", p, tag);
23997 +       return 0;
23998 +}
23999 +
24000 +/* vserver syscall commands below here */
24001 +
24002 +/* taks xid and vx_info functions */
24003 +
24004 +
24005 +int vc_task_tag(uint32_t id)
24006 +{
24007 +       tag_t tag;
24008 +
24009 +       if (id) {
24010 +               struct task_struct *tsk;
24011 +               rcu_read_lock();
24012 +               tsk = find_task_by_real_pid(id);
24013 +               tag = (tsk) ? tsk->tag : -ESRCH;
24014 +               rcu_read_unlock();
24015 +       } else
24016 +               tag = dx_current_tag();
24017 +       return tag;
24018 +}
24019 +
24020 +
24021 +int vc_tag_migrate(uint32_t tag)
24022 +{
24023 +       return dx_migrate_task(current, tag & 0xFFFF);
24024 +}
24025 +
24026 +
24027 diff -NurpP --minimal linux-3.1.1/kernel/vserver/vci_config.h linux-3.1.1-vs2.3.2/kernel/vserver/vci_config.h
24028 --- linux-3.1.1/kernel/vserver/vci_config.h     1970-01-01 01:00:00.000000000 +0100
24029 +++ linux-3.1.1-vs2.3.2/kernel/vserver/vci_config.h     2011-10-24 18:53:33.000000000 +0200
24030 @@ -0,0 +1,76 @@
24031 +
24032 +/*  interface version */
24033 +
24034 +#define VCI_VERSION            0x00020308
24035 +
24036 +
24037 +enum {
24038 +       VCI_KCBIT_NO_DYNAMIC = 0,
24039 +
24040 +       VCI_KCBIT_PROC_SECURE = 4,
24041 +       /* VCI_KCBIT_HARDCPU = 5, */
24042 +       /* VCI_KCBIT_IDLELIMIT = 6, */
24043 +       /* VCI_KCBIT_IDLETIME = 7, */
24044 +
24045 +       VCI_KCBIT_COWBL = 8,
24046 +       VCI_KCBIT_FULLCOWBL = 9,
24047 +       VCI_KCBIT_SPACES = 10,
24048 +       VCI_KCBIT_NETV2 = 11,
24049 +       VCI_KCBIT_MEMCG = 12,
24050 +
24051 +       VCI_KCBIT_DEBUG = 16,
24052 +       VCI_KCBIT_HISTORY = 20,
24053 +       VCI_KCBIT_TAGGED = 24,
24054 +       VCI_KCBIT_PPTAG = 28,
24055 +
24056 +       VCI_KCBIT_MORE = 31,
24057 +};
24058 +
24059 +
24060 +static inline uint32_t vci_kernel_config(void)
24061 +{
24062 +       return
24063 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
24064 +
24065 +       /* configured features */
24066 +#ifdef CONFIG_VSERVER_PROC_SECURE
24067 +       (1 << VCI_KCBIT_PROC_SECURE) |
24068 +#endif
24069 +#ifdef CONFIG_VSERVER_COWBL
24070 +       (1 << VCI_KCBIT_COWBL) |
24071 +       (1 << VCI_KCBIT_FULLCOWBL) |
24072 +#endif
24073 +       (1 << VCI_KCBIT_SPACES) |
24074 +       (1 << VCI_KCBIT_NETV2) |
24075 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
24076 +       (1 << VCI_KCBIT_MEMCG) |
24077 +#endif
24078 +
24079 +       /* debug options */
24080 +#ifdef CONFIG_VSERVER_DEBUG
24081 +       (1 << VCI_KCBIT_DEBUG) |
24082 +#endif
24083 +#ifdef CONFIG_VSERVER_HISTORY
24084 +       (1 << VCI_KCBIT_HISTORY) |
24085 +#endif
24086 +
24087 +       /* inode context tagging */
24088 +#if    defined(CONFIG_TAGGING_NONE)
24089 +       (0 << VCI_KCBIT_TAGGED) |
24090 +#elif  defined(CONFIG_TAGGING_UID16)
24091 +       (1 << VCI_KCBIT_TAGGED) |
24092 +#elif  defined(CONFIG_TAGGING_GID16)
24093 +       (2 << VCI_KCBIT_TAGGED) |
24094 +#elif  defined(CONFIG_TAGGING_ID24)
24095 +       (3 << VCI_KCBIT_TAGGED) |
24096 +#elif  defined(CONFIG_TAGGING_INTERN)
24097 +       (4 << VCI_KCBIT_TAGGED) |
24098 +#elif  defined(CONFIG_TAGGING_RUNTIME)
24099 +       (5 << VCI_KCBIT_TAGGED) |
24100 +#else
24101 +       (7 << VCI_KCBIT_TAGGED) |
24102 +#endif
24103 +       (1 << VCI_KCBIT_PPTAG) |
24104 +       0;
24105 +}
24106 +
24107 diff -NurpP --minimal linux-3.1.1/mm/filemap_xip.c linux-3.1.1-vs2.3.2/mm/filemap_xip.c
24108 --- linux-3.1.1/mm/filemap_xip.c        2011-07-22 11:18:12.000000000 +0200
24109 +++ linux-3.1.1-vs2.3.2/mm/filemap_xip.c        2011-10-24 18:53:33.000000000 +0200
24110 @@ -18,6 +18,7 @@
24111  #include <linux/seqlock.h>
24112  #include <linux/mutex.h>
24113  #include <linux/gfp.h>
24114 +#include <linux/vs_memory.h>
24115  #include <asm/tlbflush.h>
24116  #include <asm/io.h>
24117  
24118 diff -NurpP --minimal linux-3.1.1/mm/fremap.c linux-3.1.1-vs2.3.2/mm/fremap.c
24119 --- linux-3.1.1/mm/fremap.c     2011-07-22 11:18:12.000000000 +0200
24120 +++ linux-3.1.1-vs2.3.2/mm/fremap.c     2011-10-24 18:53:33.000000000 +0200
24121 @@ -16,6 +16,7 @@
24122  #include <linux/module.h>
24123  #include <linux/syscalls.h>
24124  #include <linux/mmu_notifier.h>
24125 +#include <linux/vs_memory.h>
24126  
24127  #include <asm/mmu_context.h>
24128  #include <asm/cacheflush.h>
24129 diff -NurpP --minimal linux-3.1.1/mm/hugetlb.c linux-3.1.1-vs2.3.2/mm/hugetlb.c
24130 --- linux-3.1.1/mm/hugetlb.c    2011-10-24 18:45:33.000000000 +0200
24131 +++ linux-3.1.1-vs2.3.2/mm/hugetlb.c    2011-10-24 18:53:33.000000000 +0200
24132 @@ -28,6 +28,7 @@
24133  
24134  #include <linux/hugetlb.h>
24135  #include <linux/node.h>
24136 +#include <linux/vs_memory.h>
24137  #include "internal.h"
24138  
24139  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
24140 diff -NurpP --minimal linux-3.1.1/mm/memcontrol.c linux-3.1.1-vs2.3.2/mm/memcontrol.c
24141 --- linux-3.1.1/mm/memcontrol.c 2011-10-24 18:45:33.000000000 +0200
24142 +++ linux-3.1.1-vs2.3.2/mm/memcontrol.c 2011-10-24 18:53:33.000000000 +0200
24143 @@ -760,6 +760,31 @@ struct mem_cgroup *mem_cgroup_from_task(
24144                                 struct mem_cgroup, css);
24145  }
24146  
24147 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
24148 +{
24149 +       return res_counter_read_u64(&mem->res, member);
24150 +}
24151 +
24152 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
24153 +{
24154 +       return res_counter_read_u64(&mem->memsw, member);
24155 +}
24156 +
24157 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
24158 +{
24159 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
24160 +}
24161 +
24162 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
24163 +{
24164 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
24165 +}
24166 +
24167 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
24168 +{
24169 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
24170 +}
24171 +
24172  struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
24173  {
24174         struct mem_cgroup *mem = NULL;
24175 diff -NurpP --minimal linux-3.1.1/mm/memory.c linux-3.1.1-vs2.3.2/mm/memory.c
24176 --- linux-3.1.1/mm/memory.c     2011-11-15 16:44:52.000000000 +0100
24177 +++ linux-3.1.1-vs2.3.2/mm/memory.c     2011-11-15 17:08:44.000000000 +0100
24178 @@ -3389,6 +3389,7 @@ int handle_pte_fault(struct mm_struct *m
24179  {
24180         pte_t entry;
24181         spinlock_t *ptl;
24182 +       int ret = 0, type = VXPT_UNKNOWN;
24183  
24184         entry = *pte;
24185         if (!pte_present(entry)) {
24186 @@ -3413,9 +3414,12 @@ int handle_pte_fault(struct mm_struct *m
24187         if (unlikely(!pte_same(*pte, entry)))
24188                 goto unlock;
24189         if (flags & FAULT_FLAG_WRITE) {
24190 -               if (!pte_write(entry))
24191 -                       return do_wp_page(mm, vma, address,
24192 +               if (!pte_write(entry)) {
24193 +                       ret = do_wp_page(mm, vma, address,
24194                                         pte, pmd, ptl, entry);
24195 +                       type = VXPT_WRITE;
24196 +                       goto out;
24197 +               }
24198                 entry = pte_mkdirty(entry);
24199         }
24200         entry = pte_mkyoung(entry);
24201 @@ -3433,7 +3437,10 @@ int handle_pte_fault(struct mm_struct *m
24202         }
24203  unlock:
24204         pte_unmap_unlock(pte, ptl);
24205 -       return 0;
24206 +       ret = 0;
24207 +out:
24208 +       vx_page_fault(mm, vma, type, ret);
24209 +       return ret;
24210  }
24211  
24212  /*
24213 diff -NurpP --minimal linux-3.1.1/mm/mremap.c linux-3.1.1-vs2.3.2/mm/mremap.c
24214 --- linux-3.1.1/mm/mremap.c     2011-07-22 11:18:12.000000000 +0200
24215 +++ linux-3.1.1-vs2.3.2/mm/mremap.c     2011-10-24 18:53:33.000000000 +0200
24216 @@ -19,6 +19,7 @@
24217  #include <linux/security.h>
24218  #include <linux/syscalls.h>
24219  #include <linux/mmu_notifier.h>
24220 +#include <linux/vs_memory.h>
24221  
24222  #include <asm/uaccess.h>
24223  #include <asm/cacheflush.h>
24224 diff -NurpP --minimal linux-3.1.1/mm/oom_kill.c linux-3.1.1-vs2.3.2/mm/oom_kill.c
24225 --- linux-3.1.1/mm/oom_kill.c   2011-10-24 18:45:33.000000000 +0200
24226 +++ linux-3.1.1-vs2.3.2/mm/oom_kill.c   2011-10-24 18:53:33.000000000 +0200
24227 @@ -32,6 +32,9 @@
24228  #include <linux/mempolicy.h>
24229  #include <linux/security.h>
24230  #include <linux/ptrace.h>
24231 +#include <linux/reboot.h>
24232 +#include <linux/vs_memory.h>
24233 +#include <linux/vs_context.h>
24234  
24235  int sysctl_panic_on_oom;
24236  int sysctl_oom_kill_allocating_task;
24237 @@ -134,11 +137,18 @@ struct task_struct *find_lock_task_mm(st
24238  static bool oom_unkillable_task(struct task_struct *p,
24239                 const struct mem_cgroup *mem, const nodemask_t *nodemask)
24240  {
24241 -       if (is_global_init(p))
24242 +       unsigned xid = vx_current_xid();
24243 +
24244 +       /* skip the init task, global and per guest */
24245 +       if (task_is_init(p))
24246                 return true;
24247         if (p->flags & PF_KTHREAD)
24248                 return true;
24249  
24250 +       /* skip other guest and host processes if oom in guest */
24251 +       if (xid && vx_task_xid(p) != xid)
24252 +               return true;
24253 +
24254         /* When mem_cgroup_out_of_memory() and p is not member of the group */
24255         if (mem && !task_in_mem_cgroup(p, mem))
24256                 return true;
24257 @@ -214,6 +224,18 @@ unsigned int oom_badness(struct task_str
24258         points += p->signal->oom_score_adj;
24259  
24260         /*
24261 +        * add points for context badness and
24262 +        * reduce badness for processes belonging to
24263 +        * a different context
24264 +        */
24265 +
24266 +       points += vx_badness(p, p->mm);
24267 +
24268 +       if ((vx_current_xid() > 1) &&
24269 +               vx_current_xid() != vx_task_xid(p))
24270 +               points /= 16;
24271 +
24272 +       /*
24273          * Never return 0 for an eligible task that may be killed since it's
24274          * possible that no single user task uses more than 0.1% of memory and
24275          * no single admin tasks uses more than 3.0%.
24276 @@ -428,8 +450,8 @@ static int oom_kill_task(struct task_str
24277         /* mm cannot be safely dereferenced after task_unlock(p) */
24278         mm = p->mm;
24279  
24280 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
24281 -               task_pid_nr(p), p->comm, K(p->mm->total_vm),
24282 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
24283 +               task_pid_nr(p), p->xid, p->comm, K(p->mm->total_vm),
24284                 K(get_mm_counter(p->mm, MM_ANONPAGES)),
24285                 K(get_mm_counter(p->mm, MM_FILEPAGES)));
24286         task_unlock(p);
24287 @@ -483,8 +505,8 @@ static int oom_kill_process(struct task_
24288         }
24289  
24290         task_lock(p);
24291 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
24292 -               message, task_pid_nr(p), p->comm, points);
24293 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
24294 +               message, task_pid_nr(p), p->xid, p->comm, points);
24295         task_unlock(p);
24296  
24297         /*
24298 @@ -585,6 +607,8 @@ int unregister_oom_notifier(struct notif
24299  }
24300  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
24301  
24302 +long vs_oom_action(unsigned int);
24303 +
24304  /*
24305   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
24306   * if a parallel OOM killing is already taking place that includes a zone in
24307 @@ -743,7 +767,12 @@ retry:
24308         if (!p) {
24309                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
24310                 read_unlock(&tasklist_lock);
24311 -               panic("Out of memory and no killable processes...\n");
24312 +
24313 +               /* avoid panic for guest OOM */
24314 +               if (current->xid)
24315 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
24316 +               else
24317 +                       panic("Out of memory and no killable processes...\n");
24318         }
24319  
24320         if (oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
24321 diff -NurpP --minimal linux-3.1.1/mm/page_alloc.c linux-3.1.1-vs2.3.2/mm/page_alloc.c
24322 --- linux-3.1.1/mm/page_alloc.c 2011-10-24 18:45:33.000000000 +0200
24323 +++ linux-3.1.1-vs2.3.2/mm/page_alloc.c 2011-10-24 18:53:33.000000000 +0200
24324 @@ -57,6 +57,8 @@
24325  #include <linux/ftrace_event.h>
24326  #include <linux/memcontrol.h>
24327  #include <linux/prefetch.h>
24328 +#include <linux/vs_base.h>
24329 +#include <linux/vs_limit.h>
24330  
24331  #include <asm/tlbflush.h>
24332  #include <asm/div64.h>
24333 @@ -2484,6 +2486,9 @@ void si_meminfo(struct sysinfo *val)
24334         val->totalhigh = totalhigh_pages;
24335         val->freehigh = nr_free_highpages();
24336         val->mem_unit = PAGE_SIZE;
24337 +
24338 +       if (vx_flags(VXF_VIRT_MEM, 0))
24339 +               vx_vsi_meminfo(val);
24340  }
24341  
24342  EXPORT_SYMBOL(si_meminfo);
24343 @@ -2504,6 +2509,9 @@ void si_meminfo_node(struct sysinfo *val
24344         val->freehigh = 0;
24345  #endif
24346         val->mem_unit = PAGE_SIZE;
24347 +
24348 +       if (vx_flags(VXF_VIRT_MEM, 0))
24349 +               vx_vsi_meminfo(val);
24350  }
24351  #endif
24352  
24353 diff -NurpP --minimal linux-3.1.1/mm/pgtable-generic.c linux-3.1.1-vs2.3.2/mm/pgtable-generic.c
24354 --- linux-3.1.1/mm/pgtable-generic.c    2011-03-15 18:07:42.000000000 +0100
24355 +++ linux-3.1.1-vs2.3.2/mm/pgtable-generic.c    2011-10-24 18:53:33.000000000 +0200
24356 @@ -6,6 +6,8 @@
24357   *  Copyright (C) 2010  Linus Torvalds
24358   */
24359  
24360 +#include <linux/mm.h>
24361 +
24362  #include <linux/pagemap.h>
24363  #include <asm/tlb.h>
24364  #include <asm-generic/pgtable.h>
24365 diff -NurpP --minimal linux-3.1.1/mm/rmap.c linux-3.1.1-vs2.3.2/mm/rmap.c
24366 --- linux-3.1.1/mm/rmap.c       2011-10-24 18:45:33.000000000 +0200
24367 +++ linux-3.1.1-vs2.3.2/mm/rmap.c       2011-10-24 18:53:33.000000000 +0200
24368 @@ -56,6 +56,7 @@
24369  #include <linux/mmu_notifier.h>
24370  #include <linux/migrate.h>
24371  #include <linux/hugetlb.h>
24372 +#include <linux/vs_memory.h>
24373  
24374  #include <asm/tlbflush.h>
24375  
24376 diff -NurpP --minimal linux-3.1.1/mm/shmem.c linux-3.1.1-vs2.3.2/mm/shmem.c
24377 --- linux-3.1.1/mm/shmem.c      2011-10-24 18:45:33.000000000 +0200
24378 +++ linux-3.1.1-vs2.3.2/mm/shmem.c      2011-10-24 18:53:33.000000000 +0200
24379 @@ -1429,7 +1429,7 @@ static int shmem_statfs(struct dentry *d
24380  {
24381         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
24382  
24383 -       buf->f_type = TMPFS_MAGIC;
24384 +       buf->f_type = TMPFS_SUPER_MAGIC;
24385         buf->f_bsize = PAGE_CACHE_SIZE;
24386         buf->f_namelen = NAME_MAX;
24387         if (sbinfo->max_blocks) {
24388 @@ -2186,7 +2186,7 @@ int shmem_fill_super(struct super_block 
24389         sb->s_maxbytes = MAX_LFS_FILESIZE;
24390         sb->s_blocksize = PAGE_CACHE_SIZE;
24391         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
24392 -       sb->s_magic = TMPFS_MAGIC;
24393 +       sb->s_magic = TMPFS_SUPER_MAGIC;
24394         sb->s_op = &shmem_ops;
24395         sb->s_time_gran = 1;
24396  #ifdef CONFIG_TMPFS_XATTR
24397 diff -NurpP --minimal linux-3.1.1/mm/slab.c linux-3.1.1-vs2.3.2/mm/slab.c
24398 --- linux-3.1.1/mm/slab.c       2011-10-24 18:45:33.000000000 +0200
24399 +++ linux-3.1.1-vs2.3.2/mm/slab.c       2011-10-24 18:53:33.000000000 +0200
24400 @@ -411,6 +411,8 @@ static void kmem_list3_init(struct kmem_
24401  #define STATS_INC_FREEMISS(x)  do { } while (0)
24402  #endif
24403  
24404 +#include "slab_vs.h"
24405 +
24406  #if DEBUG
24407  
24408  /*
24409 @@ -3399,6 +3401,7 @@ retry:
24410  
24411         obj = slab_get_obj(cachep, slabp, nodeid);
24412         check_slabp(cachep, slabp);
24413 +       vx_slab_alloc(cachep, flags);
24414         l3->free_objects--;
24415         /* move slabp to correct slabp list: */
24416         list_del(&slabp->list);
24417 @@ -3476,6 +3479,7 @@ __cache_alloc_node(struct kmem_cache *ca
24418         /* ___cache_alloc_node can fall back to other nodes */
24419         ptr = ____cache_alloc_node(cachep, flags, nodeid);
24420    out:
24421 +       vx_slab_alloc(cachep, flags);
24422         local_irq_restore(save_flags);
24423         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
24424         kmemleak_alloc_recursive(ptr, obj_size(cachep), 1, cachep->flags,
24425 @@ -3663,6 +3667,7 @@ static inline void __cache_free(struct k
24426         check_irq_off();
24427         kmemleak_free_recursive(objp, cachep->flags);
24428         objp = cache_free_debugcheck(cachep, objp, caller);
24429 +       vx_slab_free(cachep);
24430  
24431         kmemcheck_slab_free(cachep, objp, obj_size(cachep));
24432  
24433 diff -NurpP --minimal linux-3.1.1/mm/slab_vs.h linux-3.1.1-vs2.3.2/mm/slab_vs.h
24434 --- linux-3.1.1/mm/slab_vs.h    1970-01-01 01:00:00.000000000 +0100
24435 +++ linux-3.1.1-vs2.3.2/mm/slab_vs.h    2011-10-24 18:53:33.000000000 +0200
24436 @@ -0,0 +1,29 @@
24437 +
24438 +#include <linux/vserver/context.h>
24439 +
24440 +#include <linux/vs_context.h>
24441 +
24442 +static inline
24443 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
24444 +{
24445 +       int what = gfp_zone(cachep->gfpflags);
24446 +       struct vx_info *vxi = current_vx_info();
24447 +
24448 +       if (!vxi)
24449 +               return;
24450 +
24451 +       atomic_add(cachep->buffer_size, &vxi->cacct.slab[what]);
24452 +}
24453 +
24454 +static inline
24455 +void vx_slab_free(struct kmem_cache *cachep)
24456 +{
24457 +       int what = gfp_zone(cachep->gfpflags);
24458 +       struct vx_info *vxi = current_vx_info();
24459 +
24460 +       if (!vxi)
24461 +               return;
24462 +
24463 +       atomic_sub(cachep->buffer_size, &vxi->cacct.slab[what]);
24464 +}
24465 +
24466 diff -NurpP --minimal linux-3.1.1/mm/swapfile.c linux-3.1.1-vs2.3.2/mm/swapfile.c
24467 --- linux-3.1.1/mm/swapfile.c   2011-10-24 18:45:33.000000000 +0200
24468 +++ linux-3.1.1-vs2.3.2/mm/swapfile.c   2011-10-24 18:53:33.000000000 +0200
24469 @@ -37,6 +37,8 @@
24470  #include <asm/tlbflush.h>
24471  #include <linux/swapops.h>
24472  #include <linux/page_cgroup.h>
24473 +#include <linux/vs_base.h>
24474 +#include <linux/vs_memory.h>
24475  
24476  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
24477                                  unsigned char);
24478 @@ -1754,6 +1756,16 @@ static int swap_show(struct seq_file *sw
24479  
24480         if (si == SEQ_START_TOKEN) {
24481                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
24482 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
24483 +                       struct sysinfo si;
24484 +
24485 +                       vx_vsi_swapinfo(&si);
24486 +                       if (si.totalswap < (1 << 10))
24487 +                               return 0;
24488 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
24489 +                               "hdv0", "partition", si.totalswap >> 10,
24490 +                               (si.totalswap - si.freeswap) >> 10, -1);
24491 +               }
24492                 return 0;
24493         }
24494  
24495 @@ -2177,6 +2189,8 @@ void si_swapinfo(struct sysinfo *val)
24496         val->freeswap = nr_swap_pages + nr_to_be_unused;
24497         val->totalswap = total_swap_pages + nr_to_be_unused;
24498         spin_unlock(&swap_lock);
24499 +       if (vx_flags(VXF_VIRT_MEM, 0))
24500 +               vx_vsi_swapinfo(val);
24501  }
24502  
24503  /*
24504 diff -NurpP --minimal linux-3.1.1/net/bridge/br_multicast.c linux-3.1.1-vs2.3.2/net/bridge/br_multicast.c
24505 --- linux-3.1.1/net/bridge/br_multicast.c       2011-10-24 18:45:34.000000000 +0200
24506 +++ linux-3.1.1-vs2.3.2/net/bridge/br_multicast.c       2011-10-24 18:53:33.000000000 +0200
24507 @@ -447,7 +447,7 @@ static struct sk_buff *br_ip6_multicast_
24508         ip6h->hop_limit = 1;
24509         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
24510         ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
24511 -                          &ip6h->saddr);
24512 +                          &ip6h->saddr, NULL);
24513         ipv6_eth_mc_map(&ip6h->daddr, eth->h_dest);
24514  
24515         hopopt = (u8 *)(ip6h + 1);
24516 diff -NurpP --minimal linux-3.1.1/net/core/dev.c linux-3.1.1-vs2.3.2/net/core/dev.c
24517 --- linux-3.1.1/net/core/dev.c  2011-11-15 16:44:52.000000000 +0100
24518 +++ linux-3.1.1-vs2.3.2/net/core/dev.c  2011-11-15 17:08:44.000000000 +0100
24519 @@ -127,6 +127,7 @@
24520  #include <linux/in.h>
24521  #include <linux/jhash.h>
24522  #include <linux/random.h>
24523 +#include <linux/vs_inet.h>
24524  #include <trace/events/napi.h>
24525  #include <trace/events/net.h>
24526  #include <trace/events/skb.h>
24527 @@ -619,7 +620,8 @@ struct net_device *__dev_get_by_name(str
24528         struct hlist_head *head = dev_name_hash(net, name);
24529  
24530         hlist_for_each_entry(dev, p, head, name_hlist)
24531 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24532 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24533 +                   nx_dev_visible(current_nx_info(), dev))
24534                         return dev;
24535  
24536         return NULL;
24537 @@ -645,7 +647,8 @@ struct net_device *dev_get_by_name_rcu(s
24538         struct hlist_head *head = dev_name_hash(net, name);
24539  
24540         hlist_for_each_entry_rcu(dev, p, head, name_hlist)
24541 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24542 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24543 +                   nx_dev_visible(current_nx_info(), dev))
24544                         return dev;
24545  
24546         return NULL;
24547 @@ -696,7 +699,8 @@ struct net_device *__dev_get_by_index(st
24548         struct hlist_head *head = dev_index_hash(net, ifindex);
24549  
24550         hlist_for_each_entry(dev, p, head, index_hlist)
24551 -               if (dev->ifindex == ifindex)
24552 +               if ((dev->ifindex == ifindex) &&
24553 +                   nx_dev_visible(current_nx_info(), dev))
24554                         return dev;
24555  
24556         return NULL;
24557 @@ -714,7 +718,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
24558   *     about locking. The caller must hold RCU lock.
24559   */
24560  
24561 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24562 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
24563  {
24564         struct hlist_node *p;
24565         struct net_device *dev;
24566 @@ -726,6 +730,16 @@ struct net_device *dev_get_by_index_rcu(
24567  
24568         return NULL;
24569  }
24570 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
24571 +
24572 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24573 +{
24574 +       struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
24575 +
24576 +       if (nx_dev_visible(current_nx_info(), dev))
24577 +               return dev;
24578 +       return NULL;
24579 +}
24580  EXPORT_SYMBOL(dev_get_by_index_rcu);
24581  
24582  
24583 @@ -774,7 +788,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
24584  
24585         for_each_netdev_rcu(net, dev)
24586                 if (dev->type == type &&
24587 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
24588 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
24589 +                   nx_dev_visible(current_nx_info(), dev))
24590                         return dev;
24591  
24592         return NULL;
24593 @@ -786,9 +801,11 @@ struct net_device *__dev_getfirstbyhwtyp
24594         struct net_device *dev;
24595  
24596         ASSERT_RTNL();
24597 -       for_each_netdev(net, dev)
24598 -               if (dev->type == type)
24599 +       for_each_netdev(net, dev) {
24600 +               if ((dev->type == type) &&
24601 +                   nx_dev_visible(current_nx_info(), dev))
24602                         return dev;
24603 +       }
24604  
24605         return NULL;
24606  }
24607 @@ -906,6 +923,8 @@ static int __dev_alloc_name(struct net *
24608                                 continue;
24609                         if (i < 0 || i >= max_netdevices)
24610                                 continue;
24611 +                       if (!nx_dev_visible(current_nx_info(), d))
24612 +                               continue;
24613  
24614                         /*  avoid cases where sscanf is not exact inverse of printf */
24615                         snprintf(buf, IFNAMSIZ, name, i);
24616 @@ -3955,6 +3974,8 @@ static int dev_ifconf(struct net *net, c
24617  
24618         total = 0;
24619         for_each_netdev(net, dev) {
24620 +               if (!nx_dev_visible(current_nx_info(), dev))
24621 +                       continue;
24622                 for (i = 0; i < NPROTO; i++) {
24623                         if (gifconf_list[i]) {
24624                                 int done;
24625 @@ -4029,6 +4050,10 @@ static void dev_seq_printf_stats(struct 
24626         struct rtnl_link_stats64 temp;
24627         const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
24628  
24629 +       /* device visible inside network context? */
24630 +       if (!nx_dev_visible(current_nx_info(), dev))
24631 +               return;
24632 +
24633         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
24634                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
24635                    dev->name, stats->rx_bytes, stats->rx_packets,
24636 diff -NurpP --minimal linux-3.1.1/net/core/rtnetlink.c linux-3.1.1-vs2.3.2/net/core/rtnetlink.c
24637 --- linux-3.1.1/net/core/rtnetlink.c    2011-10-24 18:45:34.000000000 +0200
24638 +++ linux-3.1.1-vs2.3.2/net/core/rtnetlink.c    2011-10-24 18:53:33.000000000 +0200
24639 @@ -1040,6 +1040,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
24640                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
24641                         if (idx < s_idx)
24642                                 goto cont;
24643 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
24644 +                               continue;
24645                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
24646                                              NETLINK_CB(cb->skb).pid,
24647                                              cb->nlh->nlmsg_seq, 0,
24648 @@ -1881,6 +1883,9 @@ void rtmsg_ifinfo(int type, struct net_d
24649         int err = -ENOBUFS;
24650         size_t if_info_size;
24651  
24652 +       if (!nx_dev_visible(current_nx_info(), dev))
24653 +               return;
24654 +
24655         skb = nlmsg_new((if_info_size = if_nlmsg_size(dev)), GFP_KERNEL);
24656         if (skb == NULL)
24657                 goto errout;
24658 diff -NurpP --minimal linux-3.1.1/net/core/sock.c linux-3.1.1-vs2.3.2/net/core/sock.c
24659 --- linux-3.1.1/net/core/sock.c 2011-11-15 16:44:52.000000000 +0100
24660 +++ linux-3.1.1-vs2.3.2/net/core/sock.c 2011-11-15 17:08:44.000000000 +0100
24661 @@ -127,6 +127,10 @@
24662  #include <net/cls_cgroup.h>
24663  
24664  #include <linux/filter.h>
24665 +#include <linux/vs_socket.h>
24666 +#include <linux/vs_limit.h>
24667 +#include <linux/vs_context.h>
24668 +#include <linux/vs_network.h>
24669  
24670  #include <trace/events/sock.h>
24671  
24672 @@ -1073,6 +1077,8 @@ static struct sock *sk_prot_alloc(struct
24673                         goto out_free_sec;
24674                 sk_tx_queue_clear(sk);
24675         }
24676 +               sock_vx_init(sk);
24677 +               sock_nx_init(sk);
24678  
24679         return sk;
24680  
24681 @@ -1172,6 +1178,11 @@ static void __sk_free(struct sock *sk)
24682                 put_cred(sk->sk_peer_cred);
24683         put_pid(sk->sk_peer_pid);
24684         put_net(sock_net(sk));
24685 +       vx_sock_dec(sk);
24686 +       clr_vx_info(&sk->sk_vx_info);
24687 +       sk->sk_xid = -1;
24688 +       clr_nx_info(&sk->sk_nx_info);
24689 +       sk->sk_nid = -1;
24690         sk_prot_free(sk->sk_prot_creator, sk);
24691  }
24692  
24693 @@ -1219,6 +1230,8 @@ struct sock *sk_clone(const struct sock 
24694  
24695                 /* SANITY */
24696                 get_net(sock_net(newsk));
24697 +               sock_vx_init(newsk);
24698 +               sock_nx_init(newsk);
24699                 sk_node_init(&newsk->sk_node);
24700                 sock_lock_init(newsk);
24701                 bh_lock_sock(newsk);
24702 @@ -1275,6 +1288,12 @@ struct sock *sk_clone(const struct sock 
24703                 smp_wmb();
24704                 atomic_set(&newsk->sk_refcnt, 2);
24705  
24706 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
24707 +               newsk->sk_xid = sk->sk_xid;
24708 +               vx_sock_inc(newsk);
24709 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
24710 +               newsk->sk_nid = sk->sk_nid;
24711 +
24712                 /*
24713                  * Increment the counter in the same struct proto as the master
24714                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
24715 @@ -2023,6 +2042,12 @@ void sock_init_data(struct socket *sock,
24716  
24717         sk->sk_stamp = ktime_set(-1L, 0);
24718  
24719 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
24720 +       sk->sk_xid = vx_current_xid();
24721 +       vx_sock_inc(sk);
24722 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
24723 +       sk->sk_nid = nx_current_nid();
24724 +
24725         /*
24726          * Before updating sk_refcnt, we must commit prior changes to memory
24727          * (Documentation/RCU/rculist_nulls.txt for details)
24728 diff -NurpP --minimal linux-3.1.1/net/ipv4/af_inet.c linux-3.1.1-vs2.3.2/net/ipv4/af_inet.c
24729 --- linux-3.1.1/net/ipv4/af_inet.c      2011-10-24 18:45:34.000000000 +0200
24730 +++ linux-3.1.1-vs2.3.2/net/ipv4/af_inet.c      2011-10-24 18:53:33.000000000 +0200
24731 @@ -117,6 +117,7 @@
24732  #ifdef CONFIG_IP_MROUTE
24733  #include <linux/mroute.h>
24734  #endif
24735 +#include <linux/vs_limit.h>
24736  
24737  
24738  /* The inetsw table contains everything that inet_create needs to
24739 @@ -326,9 +327,13 @@ lookup_protocol:
24740         }
24741  
24742         err = -EPERM;
24743 +       if ((protocol == IPPROTO_ICMP) &&
24744 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24745 +               goto override;
24746 +
24747         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
24748                 goto out_rcu_unlock;
24749 -
24750 +override:
24751         err = -EAFNOSUPPORT;
24752         if (!inet_netns_ok(net, protocol))
24753                 goto out_rcu_unlock;
24754 @@ -452,6 +457,7 @@ int inet_bind(struct socket *sock, struc
24755         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
24756         struct sock *sk = sock->sk;
24757         struct inet_sock *inet = inet_sk(sk);
24758 +       struct nx_v4_sock_addr nsa;
24759         unsigned short snum;
24760         int chk_addr_ret;
24761         int err;
24762 @@ -475,7 +481,11 @@ int inet_bind(struct socket *sock, struc
24763                         goto out;
24764         }
24765  
24766 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24767 +       err = v4_map_sock_addr(inet, addr, &nsa);
24768 +       if (err)
24769 +               goto out;
24770 +
24771 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24772  
24773         /* Not specified by any standard per-se, however it breaks too
24774          * many applications when removed.  It is unfortunate since
24775 @@ -487,7 +497,7 @@ int inet_bind(struct socket *sock, struc
24776         err = -EADDRNOTAVAIL;
24777         if (!sysctl_ip_nonlocal_bind &&
24778             !(inet->freebind || inet->transparent) &&
24779 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
24780 +           nsa.saddr != htonl(INADDR_ANY) &&
24781             chk_addr_ret != RTN_LOCAL &&
24782             chk_addr_ret != RTN_MULTICAST &&
24783             chk_addr_ret != RTN_BROADCAST)
24784 @@ -512,7 +522,7 @@ int inet_bind(struct socket *sock, struc
24785         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
24786                 goto out_release_sock;
24787  
24788 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24789 +       v4_set_sock_addr(inet, &nsa);
24790         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24791                 inet->inet_saddr = 0;  /* Use device */
24792  
24793 @@ -715,11 +725,13 @@ int inet_getname(struct socket *sock, st
24794                      peer == 1))
24795                         return -ENOTCONN;
24796                 sin->sin_port = inet->inet_dport;
24797 -               sin->sin_addr.s_addr = inet->inet_daddr;
24798 +               sin->sin_addr.s_addr =
24799 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
24800         } else {
24801                 __be32 addr = inet->inet_rcv_saddr;
24802                 if (!addr)
24803                         addr = inet->inet_saddr;
24804 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
24805                 sin->sin_port = inet->inet_sport;
24806                 sin->sin_addr.s_addr = addr;
24807         }
24808 diff -NurpP --minimal linux-3.1.1/net/ipv4/arp.c linux-3.1.1-vs2.3.2/net/ipv4/arp.c
24809 --- linux-3.1.1/net/ipv4/arp.c  2011-10-24 18:45:34.000000000 +0200
24810 +++ linux-3.1.1-vs2.3.2/net/ipv4/arp.c  2011-10-24 18:53:33.000000000 +0200
24811 @@ -1332,6 +1332,7 @@ static void arp_format_neigh_entry(struc
24812         struct net_device *dev = n->dev;
24813         int hatype = dev->type;
24814  
24815 +       /* FIXME: check for network context */
24816         read_lock(&n->lock);
24817         /* Convert hardware address to XX:XX:XX:XX ... form. */
24818  #if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
24819 @@ -1363,6 +1364,7 @@ static void arp_format_pneigh_entry(stru
24820         int hatype = dev ? dev->type : 0;
24821         char tbuf[16];
24822  
24823 +       /* FIXME: check for network context */
24824         sprintf(tbuf, "%pI4", n->key);
24825         seq_printf(seq, "%-16s 0x%-10x0x%-10x%s     *        %s\n",
24826                    tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
24827 diff -NurpP --minimal linux-3.1.1/net/ipv4/devinet.c linux-3.1.1-vs2.3.2/net/ipv4/devinet.c
24828 --- linux-3.1.1/net/ipv4/devinet.c      2011-10-24 18:45:34.000000000 +0200
24829 +++ linux-3.1.1-vs2.3.2/net/ipv4/devinet.c      2011-10-24 18:53:33.000000000 +0200
24830 @@ -518,6 +518,7 @@ struct in_device *inetdev_by_index(struc
24831  }
24832  EXPORT_SYMBOL(inetdev_by_index);
24833  
24834 +
24835  /* Called only from RTNL semaphored context. No locks. */
24836  
24837  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
24838 @@ -759,6 +760,8 @@ int devinet_ioctl(struct net *net, unsig
24839  
24840         in_dev = __in_dev_get_rtnl(dev);
24841         if (in_dev) {
24842 +               struct nx_info *nxi = current_nx_info();
24843 +
24844                 if (tryaddrmatch) {
24845                         /* Matthias Andree */
24846                         /* compare label and address (4.4BSD style) */
24847 @@ -767,6 +770,8 @@ int devinet_ioctl(struct net *net, unsig
24848                            This is checked above. */
24849                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24850                              ifap = &ifa->ifa_next) {
24851 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24852 +                                       continue;
24853                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
24854                                     sin_orig.sin_addr.s_addr ==
24855                                                         ifa->ifa_local) {
24856 @@ -779,9 +784,12 @@ int devinet_ioctl(struct net *net, unsig
24857                    comparing just the label */
24858                 if (!ifa) {
24859                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24860 -                            ifap = &ifa->ifa_next)
24861 +                            ifap = &ifa->ifa_next) {
24862 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24863 +                                       continue;
24864                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
24865                                         break;
24866 +                       }
24867                 }
24868         }
24869  
24870 @@ -934,6 +942,8 @@ static int inet_gifconf(struct net_devic
24871                 goto out;
24872  
24873         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
24874 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
24875 +                       continue;
24876                 if (!buf) {
24877                         done += sizeof(ifr);
24878                         continue;
24879 @@ -1294,6 +1304,7 @@ static int inet_dump_ifaddr(struct sk_bu
24880         struct net_device *dev;
24881         struct in_device *in_dev;
24882         struct in_ifaddr *ifa;
24883 +       struct sock *sk = skb->sk;
24884         struct hlist_head *head;
24885         struct hlist_node *node;
24886  
24887 @@ -1316,6 +1327,8 @@ static int inet_dump_ifaddr(struct sk_bu
24888  
24889                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
24890                              ifa = ifa->ifa_next, ip_idx++) {
24891 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
24892 +                               continue;
24893                                 if (ip_idx < s_ip_idx)
24894                                         continue;
24895                                 if (inet_fill_ifaddr(skb, ifa,
24896 diff -NurpP --minimal linux-3.1.1/net/ipv4/fib_trie.c linux-3.1.1-vs2.3.2/net/ipv4/fib_trie.c
24897 --- linux-3.1.1/net/ipv4/fib_trie.c     2011-10-24 18:45:34.000000000 +0200
24898 +++ linux-3.1.1-vs2.3.2/net/ipv4/fib_trie.c     2011-10-24 18:53:33.000000000 +0200
24899 @@ -2554,6 +2554,7 @@ static int fib_route_seq_show(struct seq
24900                             || fa->fa_type == RTN_MULTICAST)
24901                                 continue;
24902  
24903 +                       /* FIXME: check for network context? */
24904                         if (fi)
24905                                 seq_printf(seq,
24906                                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
24907 diff -NurpP --minimal linux-3.1.1/net/ipv4/inet_connection_sock.c linux-3.1.1-vs2.3.2/net/ipv4/inet_connection_sock.c
24908 --- linux-3.1.1/net/ipv4/inet_connection_sock.c 2011-07-22 11:18:13.000000000 +0200
24909 +++ linux-3.1.1-vs2.3.2/net/ipv4/inet_connection_sock.c 2011-10-24 18:53:33.000000000 +0200
24910 @@ -52,6 +52,37 @@ void inet_get_local_port_range(int *low,
24911  }
24912  EXPORT_SYMBOL(inet_get_local_port_range);
24913  
24914 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24915 +{
24916 +       __be32  sk1_rcv_saddr = sk_rcv_saddr(sk1),
24917 +               sk2_rcv_saddr = sk_rcv_saddr(sk2);
24918 +
24919 +       if (inet_v6_ipv6only(sk2))
24920 +               return 0;
24921 +
24922 +       if (sk1_rcv_saddr &&
24923 +           sk2_rcv_saddr &&
24924 +           sk1_rcv_saddr == sk2_rcv_saddr)
24925 +               return 1;
24926 +
24927 +       if (sk1_rcv_saddr &&
24928 +           !sk2_rcv_saddr &&
24929 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
24930 +               return 1;
24931 +
24932 +       if (sk2_rcv_saddr &&
24933 +           !sk1_rcv_saddr &&
24934 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
24935 +               return 1;
24936 +
24937 +       if (!sk1_rcv_saddr &&
24938 +           !sk2_rcv_saddr &&
24939 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
24940 +               return 1;
24941 +
24942 +       return 0;
24943 +}
24944 +
24945  int inet_csk_bind_conflict(const struct sock *sk,
24946                            const struct inet_bind_bucket *tb)
24947  {
24948 @@ -74,9 +105,7 @@ int inet_csk_bind_conflict(const struct 
24949                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
24950                         if (!reuse || !sk2->sk_reuse ||
24951                             sk2->sk_state == TCP_LISTEN) {
24952 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24953 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24954 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
24955 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
24956                                         break;
24957                         }
24958                 }
24959 diff -NurpP --minimal linux-3.1.1/net/ipv4/inet_diag.c linux-3.1.1-vs2.3.2/net/ipv4/inet_diag.c
24960 --- linux-3.1.1/net/ipv4/inet_diag.c    2011-10-24 18:45:34.000000000 +0200
24961 +++ linux-3.1.1-vs2.3.2/net/ipv4/inet_diag.c    2011-10-24 18:53:33.000000000 +0200
24962 @@ -33,6 +33,8 @@
24963  #include <linux/stddef.h>
24964  
24965  #include <linux/inet_diag.h>
24966 +#include <linux/vs_network.h>
24967 +#include <linux/vs_inet.h>
24968  
24969  static const struct inet_diag_handler **inet_diag_table;
24970  
24971 @@ -119,8 +121,10 @@ static int inet_csk_diag_fill(struct soc
24972  
24973         r->id.idiag_sport = inet->inet_sport;
24974         r->id.idiag_dport = inet->inet_dport;
24975 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
24976 -       r->id.idiag_dst[0] = inet->inet_daddr;
24977 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
24978 +               inet->inet_rcv_saddr);
24979 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
24980 +               inet->inet_daddr);
24981  
24982  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
24983         if (r->idiag_family == AF_INET6) {
24984 @@ -205,8 +209,8 @@ static int inet_twsk_diag_fill(struct in
24985         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
24986         r->id.idiag_sport     = tw->tw_sport;
24987         r->id.idiag_dport     = tw->tw_dport;
24988 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
24989 -       r->id.idiag_dst[0]    = tw->tw_daddr;
24990 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
24991 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
24992         r->idiag_state        = tw->tw_substate;
24993         r->idiag_timer        = 3;
24994         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
24995 @@ -263,6 +267,7 @@ static int inet_diag_get_exact(struct sk
24996         err = -EINVAL;
24997  
24998         if (req->idiag_family == AF_INET) {
24999 +               /* TODO: lback */
25000                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
25001                                  req->id.idiag_dport, req->id.idiag_src[0],
25002                                  req->id.idiag_sport, req->id.idiag_if);
25003 @@ -505,6 +510,7 @@ static int inet_csk_diag_dump(struct soc
25004                 } else
25005  #endif
25006                 {
25007 +                       /* TODO: lback */
25008                         entry.saddr = &inet->inet_rcv_saddr;
25009                         entry.daddr = &inet->inet_daddr;
25010                 }
25011 @@ -543,6 +549,7 @@ static int inet_twsk_diag_dump(struct in
25012                 } else
25013  #endif
25014                 {
25015 +                       /* TODO: lback */
25016                         entry.saddr = &tw->tw_rcv_saddr;
25017                         entry.daddr = &tw->tw_daddr;
25018                 }
25019 @@ -589,8 +596,8 @@ static int inet_diag_fill_req(struct sk_
25020  
25021         r->id.idiag_sport = inet->inet_sport;
25022         r->id.idiag_dport = ireq->rmt_port;
25023 -       r->id.idiag_src[0] = ireq->loc_addr;
25024 -       r->id.idiag_dst[0] = ireq->rmt_addr;
25025 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
25026 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
25027         r->idiag_expires = jiffies_to_msecs(tmo);
25028         r->idiag_rqueue = 0;
25029         r->idiag_wqueue = 0;
25030 @@ -661,6 +668,7 @@ static int inet_diag_dump_reqs(struct sk
25031                                 continue;
25032  
25033                         if (bc) {
25034 +                               /* TODO: lback */
25035                                 entry.saddr =
25036  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
25037                                         (entry.family == AF_INET6) ?
25038 @@ -731,6 +739,8 @@ static int inet_diag_dump(struct sk_buff
25039                         sk_nulls_for_each(sk, node, &ilb->head) {
25040                                 struct inet_sock *inet = inet_sk(sk);
25041  
25042 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25043 +                                       continue;
25044                                 if (num < s_num) {
25045                                         num++;
25046                                         continue;
25047 @@ -797,6 +807,8 @@ skip_listen_ht:
25048                 sk_nulls_for_each(sk, node, &head->chain) {
25049                         struct inet_sock *inet = inet_sk(sk);
25050  
25051 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25052 +                               continue;
25053                         if (num < s_num)
25054                                 goto next_normal;
25055                         if (!(r->idiag_states & (1 << sk->sk_state)))
25056 @@ -821,6 +833,8 @@ next_normal:
25057                         inet_twsk_for_each(tw, node,
25058                                     &head->twchain) {
25059  
25060 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
25061 +                                       continue;
25062                                 if (num < s_num)
25063                                         goto next_dying;
25064                                 if (r->id.idiag_sport != tw->tw_sport &&
25065 diff -NurpP --minimal linux-3.1.1/net/ipv4/inet_hashtables.c linux-3.1.1-vs2.3.2/net/ipv4/inet_hashtables.c
25066 --- linux-3.1.1/net/ipv4/inet_hashtables.c      2011-10-24 18:45:34.000000000 +0200
25067 +++ linux-3.1.1-vs2.3.2/net/ipv4/inet_hashtables.c      2011-10-24 18:53:33.000000000 +0200
25068 @@ -22,6 +22,7 @@
25069  #include <net/inet_connection_sock.h>
25070  #include <net/inet_hashtables.h>
25071  #include <net/secure_seq.h>
25072 +#include <net/route.h>
25073  #include <net/ip.h>
25074  
25075  /*
25076 @@ -156,6 +157,11 @@ static inline int compute_score(struct s
25077                         if (rcv_saddr != daddr)
25078                                 return -1;
25079                         score += 2;
25080 +               } else {
25081 +                       /* block non nx_info ips */
25082 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
25083 +                               daddr, NXA_MASK_BIND))
25084 +                               return -1;
25085                 }
25086                 if (sk->sk_bound_dev_if) {
25087                         if (sk->sk_bound_dev_if != dif)
25088 @@ -173,7 +179,6 @@ static inline int compute_score(struct s
25089   * wildcarded during the search since they can never be otherwise.
25090   */
25091  
25092 -
25093  struct sock *__inet_lookup_listener(struct net *net,
25094                                     struct inet_hashinfo *hashinfo,
25095                                     const __be32 daddr, const unsigned short hnum,
25096 @@ -196,6 +201,7 @@ begin:
25097                         hiscore = score;
25098                 }
25099         }
25100 +
25101         /*
25102          * if the nulls value we got at the end of this lookup is
25103          * not the expected one, we must restart lookup.
25104 diff -NurpP --minimal linux-3.1.1/net/ipv4/netfilter/nf_nat_helper.c linux-3.1.1-vs2.3.2/net/ipv4/netfilter/nf_nat_helper.c
25105 --- linux-3.1.1/net/ipv4/netfilter/nf_nat_helper.c      2011-07-22 11:18:13.000000000 +0200
25106 +++ linux-3.1.1-vs2.3.2/net/ipv4/netfilter/nf_nat_helper.c      2011-10-24 18:53:33.000000000 +0200
25107 @@ -20,6 +20,7 @@
25108  #include <net/route.h>
25109  
25110  #include <linux/netfilter_ipv4.h>
25111 +#include <net/route.h>
25112  #include <net/netfilter/nf_conntrack.h>
25113  #include <net/netfilter/nf_conntrack_helper.h>
25114  #include <net/netfilter/nf_conntrack_ecache.h>
25115 diff -NurpP --minimal linux-3.1.1/net/ipv4/netfilter.c linux-3.1.1-vs2.3.2/net/ipv4/netfilter.c
25116 --- linux-3.1.1/net/ipv4/netfilter.c    2011-10-24 18:45:34.000000000 +0200
25117 +++ linux-3.1.1-vs2.3.2/net/ipv4/netfilter.c    2011-10-24 18:53:33.000000000 +0200
25118 @@ -5,7 +5,7 @@
25119  #include <linux/ip.h>
25120  #include <linux/skbuff.h>
25121  #include <linux/gfp.h>
25122 -#include <net/route.h>
25123 +// #include <net/route.h>
25124  #include <net/xfrm.h>
25125  #include <net/ip.h>
25126  #include <net/netfilter/nf_queue.h>
25127 diff -NurpP --minimal linux-3.1.1/net/ipv4/raw.c linux-3.1.1-vs2.3.2/net/ipv4/raw.c
25128 --- linux-3.1.1/net/ipv4/raw.c  2011-10-24 18:45:34.000000000 +0200
25129 +++ linux-3.1.1-vs2.3.2/net/ipv4/raw.c  2011-10-24 18:53:33.000000000 +0200
25130 @@ -117,7 +117,7 @@ static struct sock *__raw_v4_lookup(stru
25131  
25132                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
25133                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
25134 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
25135 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
25136                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
25137                         goto found; /* gotcha */
25138         }
25139 @@ -385,6 +385,12 @@ static int raw_send_hdrinc(struct sock *
25140                 icmp_out_count(net, ((struct icmphdr *)
25141                         skb_transport_header(skb))->type);
25142  
25143 +       err = -EPERM;
25144 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
25145 +               sk->sk_nx_info &&
25146 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
25147 +               goto error_free;
25148 +
25149         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
25150                       rt->dst.dev, dst_output);
25151         if (err > 0)
25152 @@ -572,6 +578,16 @@ static int raw_sendmsg(struct kiocb *ioc
25153                         goto done;
25154         }
25155  
25156 +       if (sk->sk_nx_info) {
25157 +               rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
25158 +               if (IS_ERR(rt)) {
25159 +                       err = PTR_ERR(rt);
25160 +                       rt = NULL;
25161 +                       goto done;
25162 +               }
25163 +               ip_rt_put(rt);
25164 +       }
25165 +
25166         security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
25167         rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
25168         if (IS_ERR(rt)) {
25169 @@ -648,17 +664,19 @@ static int raw_bind(struct sock *sk, str
25170  {
25171         struct inet_sock *inet = inet_sk(sk);
25172         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
25173 +       struct nx_v4_sock_addr nsa = { 0 };
25174         int ret = -EINVAL;
25175         int chk_addr_ret;
25176  
25177         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
25178                 goto out;
25179 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
25180 +       v4_map_sock_addr(inet, addr, &nsa);
25181 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
25182         ret = -EADDRNOTAVAIL;
25183 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
25184 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
25185             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
25186                 goto out;
25187 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
25188 +       v4_set_sock_addr(inet, &nsa);
25189         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
25190                 inet->inet_saddr = 0;  /* Use device */
25191         sk_dst_reset(sk);
25192 @@ -710,7 +728,8 @@ static int raw_recvmsg(struct kiocb *ioc
25193         /* Copy the address. */
25194         if (sin) {
25195                 sin->sin_family = AF_INET;
25196 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25197 +               sin->sin_addr.s_addr =
25198 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
25199                 sin->sin_port = 0;
25200                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
25201         }
25202 @@ -906,7 +925,8 @@ static struct sock *raw_get_first(struct
25203                 struct hlist_node *node;
25204  
25205                 sk_for_each(sk, node, &state->h->ht[state->bucket])
25206 -                       if (sock_net(sk) == seq_file_net(seq))
25207 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
25208 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25209                                 goto found;
25210         }
25211         sk = NULL;
25212 @@ -922,7 +942,8 @@ static struct sock *raw_get_next(struct 
25213                 sk = sk_next(sk);
25214  try_again:
25215                 ;
25216 -       } while (sk && sock_net(sk) != seq_file_net(seq));
25217 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
25218 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25219  
25220         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
25221                 sk = sk_head(&state->h->ht[state->bucket]);
25222 diff -NurpP --minimal linux-3.1.1/net/ipv4/route.c linux-3.1.1-vs2.3.2/net/ipv4/route.c
25223 --- linux-3.1.1/net/ipv4/route.c        2011-10-24 18:45:34.000000000 +0200
25224 +++ linux-3.1.1-vs2.3.2/net/ipv4/route.c        2011-10-24 18:53:33.000000000 +0200
25225 @@ -2562,7 +2562,7 @@ static struct rtable *ip_route_output_sl
25226  
25227  
25228         if (fl4->flowi4_oif) {
25229 -               dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
25230 +               dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
25231                 rth = ERR_PTR(-ENODEV);
25232                 if (dev_out == NULL)
25233                         goto out;
25234 diff -NurpP --minimal linux-3.1.1/net/ipv4/tcp.c linux-3.1.1-vs2.3.2/net/ipv4/tcp.c
25235 --- linux-3.1.1/net/ipv4/tcp.c  2011-07-22 11:18:13.000000000 +0200
25236 +++ linux-3.1.1-vs2.3.2/net/ipv4/tcp.c  2011-10-24 18:53:33.000000000 +0200
25237 @@ -266,6 +266,7 @@
25238  #include <linux/crypto.h>
25239  #include <linux/time.h>
25240  #include <linux/slab.h>
25241 +#include <linux/in.h>
25242  
25243  #include <net/icmp.h>
25244  #include <net/tcp.h>
25245 diff -NurpP --minimal linux-3.1.1/net/ipv4/tcp_ipv4.c linux-3.1.1-vs2.3.2/net/ipv4/tcp_ipv4.c
25246 --- linux-3.1.1/net/ipv4/tcp_ipv4.c     2011-10-24 18:45:34.000000000 +0200
25247 +++ linux-3.1.1-vs2.3.2/net/ipv4/tcp_ipv4.c     2011-10-24 18:53:33.000000000 +0200
25248 @@ -2018,6 +2018,12 @@ static void *listening_get_next(struct s
25249                 req = req->dl_next;
25250                 while (1) {
25251                         while (req) {
25252 +                               vxdprintk(VXD_CBIT(net, 6),
25253 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
25254 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
25255 +                               if (req->sk &&
25256 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
25257 +                                       continue;
25258                                 if (req->rsk_ops->family == st->family) {
25259                                         cur = req;
25260                                         goto out;
25261 @@ -2042,6 +2048,10 @@ get_req:
25262         }
25263  get_sk:
25264         sk_nulls_for_each_from(sk, node) {
25265 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
25266 +                       sk, sk->sk_nid, nx_current_nid());
25267 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25268 +                       continue;
25269                 if (!net_eq(sock_net(sk), net))
25270                         continue;
25271                 if (sk->sk_family == st->family) {
25272 @@ -2118,6 +2128,11 @@ static void *established_get_first(struc
25273  
25274                 spin_lock_bh(lock);
25275                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
25276 +                       vxdprintk(VXD_CBIT(net, 6),
25277 +                               "sk,egf: %p [#%d] (from %d)",
25278 +                               sk, sk->sk_nid, nx_current_nid());
25279 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25280 +                               continue;
25281                         if (sk->sk_family != st->family ||
25282                             !net_eq(sock_net(sk), net)) {
25283                                 continue;
25284 @@ -2128,6 +2143,11 @@ static void *established_get_first(struc
25285                 st->state = TCP_SEQ_STATE_TIME_WAIT;
25286                 inet_twsk_for_each(tw, node,
25287                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
25288 +                       vxdprintk(VXD_CBIT(net, 6),
25289 +                               "tw: %p [#%d] (from %d)",
25290 +                               tw, tw->tw_nid, nx_current_nid());
25291 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
25292 +                               continue;
25293                         if (tw->tw_family != st->family ||
25294                             !net_eq(twsk_net(tw), net)) {
25295                                 continue;
25296 @@ -2157,7 +2177,9 @@ static void *established_get_next(struct
25297                 tw = cur;
25298                 tw = tw_next(tw);
25299  get_tw:
25300 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
25301 +               while (tw && (tw->tw_family != st->family ||
25302 +                       !net_eq(twsk_net(tw), net) ||
25303 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
25304                         tw = tw_next(tw);
25305                 }
25306                 if (tw) {
25307 @@ -2181,6 +2203,11 @@ get_tw:
25308                 sk = sk_nulls_next(sk);
25309  
25310         sk_nulls_for_each_from(sk, node) {
25311 +               vxdprintk(VXD_CBIT(net, 6),
25312 +                       "sk,egn: %p [#%d] (from %d)",
25313 +                       sk, sk->sk_nid, nx_current_nid());
25314 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25315 +                       continue;
25316                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
25317                         goto found;
25318         }
25319 @@ -2390,9 +2417,9 @@ static void get_openreq4(struct sock *sk
25320         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
25321                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %pK%n",
25322                 i,
25323 -               ireq->loc_addr,
25324 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
25325                 ntohs(inet_sk(sk)->inet_sport),
25326 -               ireq->rmt_addr,
25327 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
25328                 ntohs(ireq->rmt_port),
25329                 TCP_SYN_RECV,
25330                 0, 0, /* could print option size, but that is af dependent. */
25331 @@ -2414,8 +2441,8 @@ static void get_tcp4_sock(struct sock *s
25332         struct tcp_sock *tp = tcp_sk(sk);
25333         const struct inet_connection_sock *icsk = inet_csk(sk);
25334         struct inet_sock *inet = inet_sk(sk);
25335 -       __be32 dest = inet->inet_daddr;
25336 -       __be32 src = inet->inet_rcv_saddr;
25337 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
25338 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
25339         __u16 destp = ntohs(inet->inet_dport);
25340         __u16 srcp = ntohs(inet->inet_sport);
25341         int rx_queue;
25342 @@ -2472,8 +2499,8 @@ static void get_timewait4_sock(struct in
25343         if (ttd < 0)
25344                 ttd = 0;
25345  
25346 -       dest  = tw->tw_daddr;
25347 -       src   = tw->tw_rcv_saddr;
25348 +       dest  = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
25349 +       src   = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
25350         destp = ntohs(tw->tw_dport);
25351         srcp  = ntohs(tw->tw_sport);
25352  
25353 diff -NurpP --minimal linux-3.1.1/net/ipv4/tcp_minisocks.c linux-3.1.1-vs2.3.2/net/ipv4/tcp_minisocks.c
25354 --- linux-3.1.1/net/ipv4/tcp_minisocks.c        2011-10-24 18:45:34.000000000 +0200
25355 +++ linux-3.1.1-vs2.3.2/net/ipv4/tcp_minisocks.c        2011-10-24 18:53:33.000000000 +0200
25356 @@ -23,6 +23,9 @@
25357  #include <linux/slab.h>
25358  #include <linux/sysctl.h>
25359  #include <linux/workqueue.h>
25360 +#include <linux/vs_limit.h>
25361 +#include <linux/vs_socket.h>
25362 +#include <linux/vs_context.h>
25363  #include <net/tcp.h>
25364  #include <net/inet_common.h>
25365  #include <net/xfrm.h>
25366 @@ -336,6 +339,11 @@ void tcp_time_wait(struct sock *sk, int 
25367                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
25368                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
25369  
25370 +               tw->tw_xid              = sk->sk_xid;
25371 +               tw->tw_vx_info          = NULL;
25372 +               tw->tw_nid              = sk->sk_nid;
25373 +               tw->tw_nx_info          = NULL;
25374 +
25375  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
25376                 if (tw->tw_family == PF_INET6) {
25377                         struct ipv6_pinfo *np = inet6_sk(sk);
25378 diff -NurpP --minimal linux-3.1.1/net/ipv4/udp.c linux-3.1.1-vs2.3.2/net/ipv4/udp.c
25379 --- linux-3.1.1/net/ipv4/udp.c  2011-10-24 18:45:34.000000000 +0200
25380 +++ linux-3.1.1-vs2.3.2/net/ipv4/udp.c  2011-10-24 18:53:33.000000000 +0200
25381 @@ -297,14 +297,7 @@ fail:
25382  }
25383  EXPORT_SYMBOL(udp_lib_get_port);
25384  
25385 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25386 -{
25387 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
25388 -
25389 -       return  (!ipv6_only_sock(sk2)  &&
25390 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
25391 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
25392 -}
25393 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
25394  
25395  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
25396                                        unsigned int port)
25397 @@ -339,6 +332,11 @@ static inline int compute_score(struct s
25398                         if (inet->inet_rcv_saddr != daddr)
25399                                 return -1;
25400                         score += 2;
25401 +               } else {
25402 +                       /* block non nx_info ips */
25403 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
25404 +                               daddr, NXA_MASK_BIND))
25405 +                               return -1;
25406                 }
25407                 if (inet->inet_daddr) {
25408                         if (inet->inet_daddr != saddr)
25409 @@ -442,6 +440,7 @@ exact_match:
25410         return result;
25411  }
25412  
25413 +
25414  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
25415   * harder than this. -DaveM
25416   */
25417 @@ -487,6 +486,11 @@ begin:
25418         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
25419                 score = compute_score(sk, net, saddr, hnum, sport,
25420                                       daddr, dport, dif);
25421 +               /* FIXME: disabled?
25422 +               if (score == 9) {
25423 +                       result = sk;
25424 +                       break;
25425 +               } else */
25426                 if (score > badness) {
25427                         result = sk;
25428                         badness = score;
25429 @@ -500,6 +504,7 @@ begin:
25430         if (get_nulls_value(node) != slot)
25431                 goto begin;
25432  
25433 +
25434         if (result) {
25435                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
25436                         result = NULL;
25437 @@ -509,6 +514,7 @@ begin:
25438                         goto begin;
25439                 }
25440         }
25441 +
25442         rcu_read_unlock();
25443         return result;
25444  }
25445 @@ -551,8 +557,7 @@ static inline struct sock *udp_v4_mcast_
25446                     udp_sk(s)->udp_port_hash != hnum ||
25447                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
25448                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
25449 -                   (inet->inet_rcv_saddr &&
25450 -                    inet->inet_rcv_saddr != loc_addr) ||
25451 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
25452                     ipv6_only_sock(s) ||
25453                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
25454                         continue;
25455 @@ -930,6 +935,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
25456                                    inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
25457                                    faddr, saddr, dport, inet->inet_sport);
25458  
25459 +               if (sk->sk_nx_info) {
25460 +                       rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
25461 +                       if (IS_ERR(rt)) {
25462 +                               err = PTR_ERR(rt);
25463 +                               rt = NULL;
25464 +                               goto out;
25465 +                       }
25466 +                       ip_rt_put(rt);
25467 +               }
25468 +
25469                 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
25470                 rt = ip_route_output_flow(net, fl4, sk);
25471                 if (IS_ERR(rt)) {
25472 @@ -1227,7 +1242,8 @@ try_again:
25473         if (sin) {
25474                 sin->sin_family = AF_INET;
25475                 sin->sin_port = udp_hdr(skb)->source;
25476 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25477 +               sin->sin_addr.s_addr = nx_map_sock_lback(
25478 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
25479                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
25480         }
25481         if (inet->cmsg_flags)
25482 @@ -1972,6 +1988,8 @@ static struct sock *udp_get_first(struct
25483                 sk_nulls_for_each(sk, node, &hslot->head) {
25484                         if (!net_eq(sock_net(sk), net))
25485                                 continue;
25486 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25487 +                               continue;
25488                         if (sk->sk_family == state->family)
25489                                 goto found;
25490                 }
25491 @@ -1989,7 +2007,9 @@ static struct sock *udp_get_next(struct 
25492  
25493         do {
25494                 sk = sk_nulls_next(sk);
25495 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
25496 +       } while (sk && (!net_eq(sock_net(sk), net) ||
25497 +               sk->sk_family != state->family ||
25498 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25499  
25500         if (!sk) {
25501                 if (state->bucket <= state->udp_table->mask)
25502 diff -NurpP --minimal linux-3.1.1/net/ipv6/Kconfig linux-3.1.1-vs2.3.2/net/ipv6/Kconfig
25503 --- linux-3.1.1/net/ipv6/Kconfig        2010-08-02 16:52:59.000000000 +0200
25504 +++ linux-3.1.1-vs2.3.2/net/ipv6/Kconfig        2011-10-24 18:53:33.000000000 +0200
25505 @@ -4,8 +4,8 @@
25506  
25507  #   IPv6 as module will cause a CRASH if you try to unload it
25508  menuconfig IPV6
25509 -       tristate "The IPv6 protocol"
25510 -       default m
25511 +       bool "The IPv6 protocol"
25512 +       default n
25513         ---help---
25514           This is complemental support for the IP version 6.
25515           You will still be able to do traditional IPv4 networking as well.
25516 diff -NurpP --minimal linux-3.1.1/net/ipv6/addrconf.c linux-3.1.1-vs2.3.2/net/ipv6/addrconf.c
25517 --- linux-3.1.1/net/ipv6/addrconf.c     2011-10-24 18:45:34.000000000 +0200
25518 +++ linux-3.1.1-vs2.3.2/net/ipv6/addrconf.c     2011-10-24 18:53:33.000000000 +0200
25519 @@ -87,6 +87,8 @@
25520  
25521  #include <linux/proc_fs.h>
25522  #include <linux/seq_file.h>
25523 +#include <linux/vs_network.h>
25524 +#include <linux/vs_inet6.h>
25525  
25526  /* Set to 3 to get tracing... */
25527  #define ACONF_DEBUG 2
25528 @@ -1108,7 +1110,7 @@ out:
25529  
25530  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
25531                        const struct in6_addr *daddr, unsigned int prefs,
25532 -                      struct in6_addr *saddr)
25533 +                      struct in6_addr *saddr, struct nx_info *nxi)
25534  {
25535         struct ipv6_saddr_score scores[2],
25536                                 *score = &scores[0], *hiscore = &scores[1];
25537 @@ -1180,6 +1182,8 @@ int ipv6_dev_get_saddr(struct net *net, 
25538                                                dev->name);
25539                                 continue;
25540                         }
25541 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
25542 +                               continue;
25543  
25544                         score->rule = -1;
25545                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
25546 @@ -3087,7 +3091,10 @@ static void if6_seq_stop(struct seq_file
25547  static int if6_seq_show(struct seq_file *seq, void *v)
25548  {
25549         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
25550 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25551 +
25552 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
25553 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
25554 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25555                    &ifp->addr,
25556                    ifp->idev->dev->ifindex,
25557                    ifp->prefix_len,
25558 @@ -3593,6 +3600,11 @@ static int in6_dump_addrs(struct inet6_d
25559         struct ifacaddr6 *ifaca;
25560         int err = 1;
25561         int ip_idx = *p_ip_idx;
25562 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25563 +
25564 +       /* disable ipv6 on non v6 guests */
25565 +       if (nxi && !nx_info_has_v6(nxi))
25566 +               return skb->len;
25567  
25568         read_lock_bh(&idev->lock);
25569         switch (type) {
25570 @@ -3603,6 +3615,8 @@ static int in6_dump_addrs(struct inet6_d
25571                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
25572                         if (++ip_idx < s_ip_idx)
25573                                 continue;
25574 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
25575 +                                       continue;
25576                         err = inet6_fill_ifaddr(skb, ifa,
25577                                                 NETLINK_CB(cb->skb).pid,
25578                                                 cb->nlh->nlmsg_seq,
25579 @@ -3619,6 +3633,8 @@ static int in6_dump_addrs(struct inet6_d
25580                      ifmca = ifmca->next, ip_idx++) {
25581                         if (ip_idx < s_ip_idx)
25582                                 continue;
25583 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
25584 +                                       continue;
25585                         err = inet6_fill_ifmcaddr(skb, ifmca,
25586                                                   NETLINK_CB(cb->skb).pid,
25587                                                   cb->nlh->nlmsg_seq,
25588 @@ -3634,6 +3650,8 @@ static int in6_dump_addrs(struct inet6_d
25589                      ifaca = ifaca->aca_next, ip_idx++) {
25590                         if (ip_idx < s_ip_idx)
25591                                 continue;
25592 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
25593 +                                       continue;
25594                         err = inet6_fill_ifacaddr(skb, ifaca,
25595                                                   NETLINK_CB(cb->skb).pid,
25596                                                   cb->nlh->nlmsg_seq,
25597 @@ -4019,6 +4037,11 @@ static int inet6_dump_ifinfo(struct sk_b
25598         struct inet6_dev *idev;
25599         struct hlist_head *head;
25600         struct hlist_node *node;
25601 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25602 +
25603 +       /* FIXME: maybe disable ipv6 on non v6 guests?
25604 +       if (skb->sk && skb->sk->sk_vx_info)
25605 +               return skb->len; */
25606  
25607         s_h = cb->args[0];
25608         s_idx = cb->args[1];
25609 @@ -4030,6 +4053,8 @@ static int inet6_dump_ifinfo(struct sk_b
25610                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
25611                         if (idx < s_idx)
25612                                 goto cont;
25613 +                       if (!v6_dev_in_nx_info(dev, nxi))
25614 +                               goto cont;
25615                         idev = __in6_dev_get(dev);
25616                         if (!idev)
25617                                 goto cont;
25618 diff -NurpP --minimal linux-3.1.1/net/ipv6/af_inet6.c linux-3.1.1-vs2.3.2/net/ipv6/af_inet6.c
25619 --- linux-3.1.1/net/ipv6/af_inet6.c     2011-10-24 18:45:34.000000000 +0200
25620 +++ linux-3.1.1-vs2.3.2/net/ipv6/af_inet6.c     2011-10-24 18:53:33.000000000 +0200
25621 @@ -42,6 +42,8 @@
25622  #include <linux/netdevice.h>
25623  #include <linux/icmpv6.h>
25624  #include <linux/netfilter_ipv6.h>
25625 +#include <linux/vs_inet.h>
25626 +#include <linux/vs_inet6.h>
25627  
25628  #include <net/ip.h>
25629  #include <net/ipv6.h>
25630 @@ -160,9 +162,12 @@ lookup_protocol:
25631         }
25632  
25633         err = -EPERM;
25634 +       if ((protocol == IPPROTO_ICMPV6) &&
25635 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
25636 +               goto override;
25637         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
25638                 goto out_rcu_unlock;
25639 -
25640 +override:
25641         sock->ops = answer->ops;
25642         answer_prot = answer->prot;
25643         answer_no_check = answer->no_check;
25644 @@ -261,6 +266,7 @@ int inet6_bind(struct socket *sock, stru
25645         struct inet_sock *inet = inet_sk(sk);
25646         struct ipv6_pinfo *np = inet6_sk(sk);
25647         struct net *net = sock_net(sk);
25648 +       struct nx_v6_sock_addr nsa;
25649         __be32 v4addr = 0;
25650         unsigned short snum;
25651         int addr_type = 0;
25652 @@ -276,6 +282,10 @@ int inet6_bind(struct socket *sock, stru
25653         if (addr->sin6_family != AF_INET6)
25654                 return -EAFNOSUPPORT;
25655  
25656 +       err = v6_map_sock_addr(inet, addr, &nsa);
25657 +       if (err)
25658 +               return err;
25659 +
25660         addr_type = ipv6_addr_type(&addr->sin6_addr);
25661         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
25662                 return -EINVAL;
25663 @@ -307,6 +317,7 @@ int inet6_bind(struct socket *sock, stru
25664                 /* Reproduce AF_INET checks to make the bindings consistent */
25665                 v4addr = addr->sin6_addr.s6_addr32[3];
25666                 chk_addr_ret = inet_addr_type(net, v4addr);
25667 +
25668                 if (!sysctl_ip_nonlocal_bind &&
25669                     !(inet->freebind || inet->transparent) &&
25670                     v4addr != htonl(INADDR_ANY) &&
25671 @@ -316,6 +327,10 @@ int inet6_bind(struct socket *sock, stru
25672                         err = -EADDRNOTAVAIL;
25673                         goto out;
25674                 }
25675 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
25676 +                       err = -EADDRNOTAVAIL;
25677 +                       goto out;
25678 +               }
25679         } else {
25680                 if (addr_type != IPV6_ADDR_ANY) {
25681                         struct net_device *dev = NULL;
25682 @@ -342,6 +357,11 @@ int inet6_bind(struct socket *sock, stru
25683                                 }
25684                         }
25685  
25686 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25687 +                               err = -EADDRNOTAVAIL;
25688 +                               goto out;
25689 +                       }
25690 +
25691                         /* ipv4 addr of the socket is invalid.  Only the
25692                          * unspecified and mapped address have a v4 equivalent.
25693                          */
25694 @@ -358,6 +378,9 @@ int inet6_bind(struct socket *sock, stru
25695                 }
25696         }
25697  
25698 +       /* what's that for? */
25699 +       v6_set_sock_addr(inet, &nsa);
25700 +
25701         inet->inet_rcv_saddr = v4addr;
25702         inet->inet_saddr = v4addr;
25703  
25704 @@ -459,9 +482,11 @@ int inet6_getname(struct socket *sock, s
25705                         return -ENOTCONN;
25706                 sin->sin6_port = inet->inet_dport;
25707                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
25708 +               /* FIXME: remap lback? */
25709                 if (np->sndflow)
25710                         sin->sin6_flowinfo = np->flow_label;
25711         } else {
25712 +               /* FIXME: remap lback? */
25713                 if (ipv6_addr_any(&np->rcv_saddr))
25714                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
25715                 else
25716 diff -NurpP --minimal linux-3.1.1/net/ipv6/datagram.c linux-3.1.1-vs2.3.2/net/ipv6/datagram.c
25717 --- linux-3.1.1/net/ipv6/datagram.c     2011-10-24 18:45:34.000000000 +0200
25718 +++ linux-3.1.1-vs2.3.2/net/ipv6/datagram.c     2011-10-24 18:53:33.000000000 +0200
25719 @@ -646,7 +646,7 @@ int datagram_send_ctl(struct net *net, s
25720  
25721                         rcu_read_lock();
25722                         if (fl6->flowi6_oif) {
25723 -                               dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
25724 +                               dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
25725                                 if (!dev) {
25726                                         rcu_read_unlock();
25727                                         return -ENODEV;
25728 diff -NurpP --minimal linux-3.1.1/net/ipv6/fib6_rules.c linux-3.1.1-vs2.3.2/net/ipv6/fib6_rules.c
25729 --- linux-3.1.1/net/ipv6/fib6_rules.c   2011-05-22 16:18:00.000000000 +0200
25730 +++ linux-3.1.1-vs2.3.2/net/ipv6/fib6_rules.c   2011-10-24 18:53:33.000000000 +0200
25731 @@ -90,7 +90,7 @@ static int fib6_rule_action(struct fib_r
25732                                                ip6_dst_idev(&rt->dst)->dev,
25733                                                &flp6->daddr,
25734                                                rt6_flags2srcprefs(flags),
25735 -                                              &saddr))
25736 +                                              &saddr, NULL))
25737                                 goto again;
25738                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
25739                                                r->src.plen))
25740 diff -NurpP --minimal linux-3.1.1/net/ipv6/inet6_hashtables.c linux-3.1.1-vs2.3.2/net/ipv6/inet6_hashtables.c
25741 --- linux-3.1.1/net/ipv6/inet6_hashtables.c     2011-10-24 18:45:34.000000000 +0200
25742 +++ linux-3.1.1-vs2.3.2/net/ipv6/inet6_hashtables.c     2011-10-24 18:53:33.000000000 +0200
25743 @@ -16,6 +16,7 @@
25744  
25745  #include <linux/module.h>
25746  #include <linux/random.h>
25747 +#include <linux/vs_inet6.h>
25748  
25749  #include <net/inet_connection_sock.h>
25750  #include <net/inet_hashtables.h>
25751 @@ -83,7 +84,6 @@ struct sock *__inet6_lookup_established(
25752         unsigned int slot = hash & hashinfo->ehash_mask;
25753         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
25754  
25755 -
25756         rcu_read_lock();
25757  begin:
25758         sk_nulls_for_each_rcu(sk, node, &head->chain) {
25759 @@ -95,7 +95,7 @@ begin:
25760                                 sock_put(sk);
25761                                 goto begin;
25762                         }
25763 -               goto out;
25764 +                       goto out;
25765                 }
25766         }
25767         if (get_nulls_value(node) != slot)
25768 @@ -141,6 +141,9 @@ static inline int compute_score(struct s
25769                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25770                                 return -1;
25771                         score++;
25772 +               } else {
25773 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25774 +                               return -1;
25775                 }
25776                 if (sk->sk_bound_dev_if) {
25777                         if (sk->sk_bound_dev_if != dif)
25778 diff -NurpP --minimal linux-3.1.1/net/ipv6/ip6_output.c linux-3.1.1-vs2.3.2/net/ipv6/ip6_output.c
25779 --- linux-3.1.1/net/ipv6/ip6_output.c   2011-10-24 18:45:34.000000000 +0200
25780 +++ linux-3.1.1-vs2.3.2/net/ipv6/ip6_output.c   2011-10-24 18:53:33.000000000 +0200
25781 @@ -966,7 +966,8 @@ static int ip6_dst_lookup_tail(struct so
25782                 struct rt6_info *rt = (struct rt6_info *) *dst;
25783                 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
25784                                           sk ? inet6_sk(sk)->srcprefs : 0,
25785 -                                         &fl6->saddr);
25786 +                                         &fl6->saddr,
25787 +                                         sk ? sk->sk_nx_info : NULL);
25788                 if (err)
25789                         goto out_err_release;
25790         }
25791 diff -NurpP --minimal linux-3.1.1/net/ipv6/ndisc.c linux-3.1.1-vs2.3.2/net/ipv6/ndisc.c
25792 --- linux-3.1.1/net/ipv6/ndisc.c        2011-10-24 18:45:34.000000000 +0200
25793 +++ linux-3.1.1-vs2.3.2/net/ipv6/ndisc.c        2011-10-24 18:53:33.000000000 +0200
25794 @@ -591,7 +591,7 @@ static void ndisc_send_na(struct net_dev
25795         } else {
25796                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
25797                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
25798 -                                      &tmpaddr))
25799 +                                      &tmpaddr, NULL))
25800                         return;
25801                 src_addr = &tmpaddr;
25802         }
25803 diff -NurpP --minimal linux-3.1.1/net/ipv6/raw.c linux-3.1.1-vs2.3.2/net/ipv6/raw.c
25804 --- linux-3.1.1/net/ipv6/raw.c  2011-10-24 18:45:34.000000000 +0200
25805 +++ linux-3.1.1-vs2.3.2/net/ipv6/raw.c  2011-10-24 18:53:33.000000000 +0200
25806 @@ -30,6 +30,7 @@
25807  #include <linux/icmpv6.h>
25808  #include <linux/netfilter.h>
25809  #include <linux/netfilter_ipv6.h>
25810 +#include <linux/vs_inet6.h>
25811  #include <linux/skbuff.h>
25812  #include <linux/compat.h>
25813  #include <asm/uaccess.h>
25814 @@ -284,6 +285,13 @@ static int rawv6_bind(struct sock *sk, s
25815                                 goto out_unlock;
25816                 }
25817  
25818 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25819 +                       err = -EADDRNOTAVAIL;
25820 +                       if (dev)
25821 +                               dev_put(dev);
25822 +                       goto out;
25823 +               }
25824 +
25825                 /* ipv4 addr of the socket is invalid.  Only the
25826                  * unspecified and mapped address have a v4 equivalent.
25827                  */
25828 diff -NurpP --minimal linux-3.1.1/net/ipv6/route.c linux-3.1.1-vs2.3.2/net/ipv6/route.c
25829 --- linux-3.1.1/net/ipv6/route.c        2011-11-15 16:44:52.000000000 +0100
25830 +++ linux-3.1.1-vs2.3.2/net/ipv6/route.c        2011-11-15 17:08:44.000000000 +0100
25831 @@ -54,6 +54,7 @@
25832  #include <net/xfrm.h>
25833  #include <net/netevent.h>
25834  #include <net/netlink.h>
25835 +#include <linux/vs_inet6.h>
25836  
25837  #include <asm/uaccess.h>
25838  
25839 @@ -2085,15 +2086,17 @@ int ip6_route_get_saddr(struct net *net,
25840                         struct rt6_info *rt,
25841                         const struct in6_addr *daddr,
25842                         unsigned int prefs,
25843 -                       struct in6_addr *saddr)
25844 +                       struct in6_addr *saddr,
25845 +                       struct nx_info *nxi)
25846  {
25847         struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
25848         int err = 0;
25849 -       if (rt->rt6i_prefsrc.plen)
25850 +       if (rt->rt6i_prefsrc.plen && (!nxi ||
25851 +           v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
25852                 ipv6_addr_copy(saddr, &rt->rt6i_prefsrc.addr);
25853         else
25854                 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
25855 -                                        daddr, prefs, saddr);
25856 +                                        daddr, prefs, saddr, nxi);
25857         return err;
25858  }
25859  
25860 @@ -2423,7 +2426,8 @@ static int rt6_fill_node(struct net *net
25861                         NLA_PUT_U32(skb, RTA_IIF, iif);
25862         } else if (dst) {
25863                 struct in6_addr saddr_buf;
25864 -               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0)
25865 +               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
25866 +                                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
25867                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
25868         }
25869  
25870 @@ -2626,6 +2630,7 @@ static int rt6_info_route(struct rt6_inf
25871         struct seq_file *m = p_arg;
25872         struct neighbour *n;
25873  
25874 +       /* FIXME: check for network context? */
25875         seq_printf(m, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
25876  
25877  #ifdef CONFIG_IPV6_SUBTREES
25878 diff -NurpP --minimal linux-3.1.1/net/ipv6/tcp_ipv6.c linux-3.1.1-vs2.3.2/net/ipv6/tcp_ipv6.c
25879 --- linux-3.1.1/net/ipv6/tcp_ipv6.c     2011-10-24 18:45:34.000000000 +0200
25880 +++ linux-3.1.1-vs2.3.2/net/ipv6/tcp_ipv6.c     2011-10-24 18:53:33.000000000 +0200
25881 @@ -70,6 +70,7 @@
25882  
25883  #include <linux/crypto.h>
25884  #include <linux/scatterlist.h>
25885 +#include <linux/vs_inet6.h>
25886  
25887  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
25888  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
25889 @@ -162,8 +163,15 @@ static int tcp_v6_connect(struct sock *s
25890          *      connect() to INADDR_ANY means loopback (BSD'ism).
25891          */
25892  
25893 -       if(ipv6_addr_any(&usin->sin6_addr))
25894 -               usin->sin6_addr.s6_addr[15] = 0x1;
25895 +       if(ipv6_addr_any(&usin->sin6_addr)) {
25896 +               struct nx_info *nxi =  sk->sk_nx_info;
25897 +
25898 +               if (nxi && nx_info_has_v6(nxi))
25899 +                       /* FIXME: remap lback? */
25900 +                       usin->sin6_addr = nxi->v6.ip;
25901 +               else
25902 +                       usin->sin6_addr.s6_addr[15] = 0x1;
25903 +       }
25904  
25905         addr_type = ipv6_addr_type(&usin->sin6_addr);
25906  
25907 diff -NurpP --minimal linux-3.1.1/net/ipv6/udp.c linux-3.1.1-vs2.3.2/net/ipv6/udp.c
25908 --- linux-3.1.1/net/ipv6/udp.c  2011-10-24 18:45:34.000000000 +0200
25909 +++ linux-3.1.1-vs2.3.2/net/ipv6/udp.c  2011-10-24 18:53:33.000000000 +0200
25910 @@ -45,41 +45,67 @@
25911  #include <net/tcp_states.h>
25912  #include <net/ip6_checksum.h>
25913  #include <net/xfrm.h>
25914 +#include <linux/vs_inet6.h>
25915  
25916  #include <linux/proc_fs.h>
25917  #include <linux/seq_file.h>
25918  #include "udp_impl.h"
25919  
25920 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
25921 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25922  {
25923 -       const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
25924 +       const struct in6_addr *sk1_rcv_saddr6 = &inet6_sk(sk1)->rcv_saddr;
25925         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
25926 -       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk);
25927 +       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1);
25928         __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
25929 -       int sk_ipv6only = ipv6_only_sock(sk);
25930 +       int sk1_ipv6only = ipv6_only_sock(sk1);
25931         int sk2_ipv6only = inet_v6_ipv6only(sk2);
25932 -       int addr_type = ipv6_addr_type(sk_rcv_saddr6);
25933 +       int addr_type = ipv6_addr_type(sk1_rcv_saddr6);
25934         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
25935  
25936         /* if both are mapped, treat as IPv4 */
25937 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
25938 -               return (!sk2_ipv6only &&
25939 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
25940 +               if (!sk2_ipv6only &&
25941                         (!sk1_rcv_saddr || !sk2_rcv_saddr ||
25942 -                         sk1_rcv_saddr == sk2_rcv_saddr));
25943 +                         sk1_rcv_saddr == sk2_rcv_saddr))
25944 +                       goto vs_v4;
25945 +               else
25946 +                       return 0;
25947 +       }
25948  
25949         if (addr_type2 == IPV6_ADDR_ANY &&
25950             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
25951 -               return 1;
25952 +               goto vs;
25953  
25954         if (addr_type == IPV6_ADDR_ANY &&
25955 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25956 -               return 1;
25957 +           !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25958 +               goto vs;
25959  
25960         if (sk2_rcv_saddr6 &&
25961 -           ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
25962 -               return 1;
25963 +           ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
25964 +               goto vs;
25965  
25966         return 0;
25967 +
25968 +vs_v4:
25969 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
25970 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25971 +       if (!sk2_rcv_saddr)
25972 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
25973 +       if (!sk1_rcv_saddr)
25974 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
25975 +       return 1;
25976 +vs:
25977 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
25978 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25979 +       else if (addr_type2 == IPV6_ADDR_ANY)
25980 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
25981 +       else if (addr_type == IPV6_ADDR_ANY) {
25982 +               if (addr_type2 == IPV6_ADDR_MAPPED)
25983 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25984 +               else
25985 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
25986 +       }
25987 +       return 1;
25988  }
25989  
25990  static unsigned int udp6_portaddr_hash(struct net *net,
25991 @@ -143,6 +169,10 @@ static inline int compute_score(struct s
25992                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25993                                 return -1;
25994                         score++;
25995 +               } else {
25996 +                       /* block non nx_info ips */
25997 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25998 +                               return -1;
25999                 }
26000                 if (!ipv6_addr_any(&np->daddr)) {
26001                         if (!ipv6_addr_equal(&np->daddr, saddr))
26002 diff -NurpP --minimal linux-3.1.1/net/ipv6/xfrm6_policy.c linux-3.1.1-vs2.3.2/net/ipv6/xfrm6_policy.c
26003 --- linux-3.1.1/net/ipv6/xfrm6_policy.c 2011-07-22 11:18:13.000000000 +0200
26004 +++ linux-3.1.1-vs2.3.2/net/ipv6/xfrm6_policy.c 2011-10-24 18:53:33.000000000 +0200
26005 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
26006         dev = ip6_dst_idev(dst)->dev;
26007         ipv6_dev_get_saddr(dev_net(dev), dev,
26008                            (struct in6_addr *)&daddr->a6, 0,
26009 -                          (struct in6_addr *)&saddr->a6);
26010 +                          (struct in6_addr *)&saddr->a6, NULL);
26011         dst_release(dst);
26012         return 0;
26013  }
26014 diff -NurpP --minimal linux-3.1.1/net/netfilter/ipvs/ip_vs_xmit.c linux-3.1.1-vs2.3.2/net/netfilter/ipvs/ip_vs_xmit.c
26015 --- linux-3.1.1/net/netfilter/ipvs/ip_vs_xmit.c 2011-07-22 11:18:13.000000000 +0200
26016 +++ linux-3.1.1-vs2.3.2/net/netfilter/ipvs/ip_vs_xmit.c 2011-10-24 18:53:33.000000000 +0200
26017 @@ -226,7 +226,7 @@ __ip_vs_route_output_v6(struct net *net,
26018                 return dst;
26019         if (ipv6_addr_any(&fl6.saddr) &&
26020             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
26021 -                              &fl6.daddr, 0, &fl6.saddr) < 0)
26022 +                              &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
26023                 goto out_err;
26024         if (do_xfrm) {
26025                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
26026 diff -NurpP --minimal linux-3.1.1/net/netlink/af_netlink.c linux-3.1.1-vs2.3.2/net/netlink/af_netlink.c
26027 --- linux-3.1.1/net/netlink/af_netlink.c        2011-10-24 18:45:34.000000000 +0200
26028 +++ linux-3.1.1-vs2.3.2/net/netlink/af_netlink.c        2011-10-24 18:53:33.000000000 +0200
26029 @@ -55,6 +55,9 @@
26030  #include <linux/types.h>
26031  #include <linux/audit.h>
26032  #include <linux/mutex.h>
26033 +#include <linux/vs_context.h>
26034 +#include <linux/vs_network.h>
26035 +#include <linux/vs_limit.h>
26036  
26037  #include <net/net_namespace.h>
26038  #include <net/sock.h>
26039 @@ -1913,6 +1916,8 @@ static struct sock *netlink_seq_socket_i
26040                         sk_for_each(s, node, &hash->table[j]) {
26041                                 if (sock_net(s) != seq_file_net(seq))
26042                                         continue;
26043 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26044 +                                       continue;
26045                                 if (off == pos) {
26046                                         iter->link = i;
26047                                         iter->hash_idx = j;
26048 @@ -1947,7 +1952,8 @@ static void *netlink_seq_next(struct seq
26049         s = v;
26050         do {
26051                 s = sk_next(s);
26052 -       } while (s && sock_net(s) != seq_file_net(seq));
26053 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
26054 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
26055         if (s)
26056                 return s;
26057  
26058 @@ -1959,7 +1965,8 @@ static void *netlink_seq_next(struct seq
26059  
26060                 for (; j <= hash->mask; j++) {
26061                         s = sk_head(&hash->table[j]);
26062 -                       while (s && sock_net(s) != seq_file_net(seq))
26063 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
26064 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
26065                                 s = sk_next(s);
26066                         if (s) {
26067                                 iter->link = i;
26068 diff -NurpP --minimal linux-3.1.1/net/socket.c linux-3.1.1-vs2.3.2/net/socket.c
26069 --- linux-3.1.1/net/socket.c    2011-10-24 18:45:34.000000000 +0200
26070 +++ linux-3.1.1-vs2.3.2/net/socket.c    2011-10-24 18:53:33.000000000 +0200
26071 @@ -98,6 +98,10 @@
26072  
26073  #include <net/sock.h>
26074  #include <linux/netfilter.h>
26075 +#include <linux/vs_base.h>
26076 +#include <linux/vs_socket.h>
26077 +#include <linux/vs_inet.h>
26078 +#include <linux/vs_inet6.h>
26079  
26080  #include <linux/if_tun.h>
26081  #include <linux/ipv6_route.h>
26082 @@ -546,6 +550,7 @@ static inline int __sock_sendmsg_nosec(s
26083                                        struct msghdr *msg, size_t size)
26084  {
26085         struct sock_iocb *si = kiocb_to_siocb(iocb);
26086 +       size_t len;
26087  
26088         sock_update_classid(sock->sk);
26089  
26090 @@ -554,7 +559,22 @@ static inline int __sock_sendmsg_nosec(s
26091         si->msg = msg;
26092         si->size = size;
26093  
26094 -       return sock->ops->sendmsg(iocb, sock, msg, size);
26095 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
26096 +       if (sock->sk) {
26097 +               if (len == size)
26098 +                       vx_sock_send(sock->sk, size);
26099 +               else
26100 +                       vx_sock_fail(sock->sk, size);
26101 +       }
26102 +       vxdprintk(VXD_CBIT(net, 7),
26103 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
26104 +               sock, sock->sk,
26105 +               (sock->sk)?sock->sk->sk_nx_info:0,
26106 +               (sock->sk)?sock->sk->sk_vx_info:0,
26107 +               (sock->sk)?sock->sk->sk_xid:0,
26108 +               (sock->sk)?sock->sk->sk_nid:0,
26109 +               (unsigned int)size, len);
26110 +       return len;
26111  }
26112  
26113  static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
26114 @@ -694,6 +714,7 @@ static inline int __sock_recvmsg_nosec(s
26115                                        struct msghdr *msg, size_t size, int flags)
26116  {
26117         struct sock_iocb *si = kiocb_to_siocb(iocb);
26118 +       int len;
26119  
26120         sock_update_classid(sock->sk);
26121  
26122 @@ -703,7 +724,18 @@ static inline int __sock_recvmsg_nosec(s
26123         si->size = size;
26124         si->flags = flags;
26125  
26126 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
26127 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
26128 +       if ((len >= 0) && sock->sk)
26129 +               vx_sock_recv(sock->sk, len);
26130 +       vxdprintk(VXD_CBIT(net, 7),
26131 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
26132 +               sock, sock->sk,
26133 +               (sock->sk)?sock->sk->sk_nx_info:0,
26134 +               (sock->sk)?sock->sk->sk_vx_info:0,
26135 +               (sock->sk)?sock->sk->sk_xid:0,
26136 +               (sock->sk)?sock->sk->sk_nid:0,
26137 +               (unsigned int)size, len);
26138 +       return len;
26139  }
26140  
26141  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
26142 @@ -1188,6 +1220,13 @@ int __sock_create(struct net *net, int f
26143         if (type < 0 || type >= SOCK_MAX)
26144                 return -EINVAL;
26145  
26146 +       if (!nx_check(0, VS_ADMIN)) {
26147 +               if (family == PF_INET && !current_nx_info_has_v4())
26148 +                       return -EAFNOSUPPORT;
26149 +               if (family == PF_INET6 && !current_nx_info_has_v6())
26150 +                       return -EAFNOSUPPORT;
26151 +       }
26152 +
26153         /* Compatibility.
26154  
26155            This uglymoron is moved from INET layer to here to avoid
26156 @@ -1323,6 +1362,7 @@ SYSCALL_DEFINE3(socket, int, family, int
26157         if (retval < 0)
26158                 goto out;
26159  
26160 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
26161         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
26162         if (retval < 0)
26163                 goto out_release;
26164 @@ -1364,10 +1404,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
26165         err = sock_create(family, type, protocol, &sock1);
26166         if (err < 0)
26167                 goto out;
26168 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
26169  
26170         err = sock_create(family, type, protocol, &sock2);
26171         if (err < 0)
26172                 goto out_release_1;
26173 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
26174  
26175         err = sock1->ops->socketpair(sock1, sock2);
26176         if (err < 0)
26177 diff -NurpP --minimal linux-3.1.1/net/sunrpc/auth.c linux-3.1.1-vs2.3.2/net/sunrpc/auth.c
26178 --- linux-3.1.1/net/sunrpc/auth.c       2011-10-24 18:45:34.000000000 +0200
26179 +++ linux-3.1.1-vs2.3.2/net/sunrpc/auth.c       2011-10-24 18:53:33.000000000 +0200
26180 @@ -14,6 +14,7 @@
26181  #include <linux/hash.h>
26182  #include <linux/sunrpc/clnt.h>
26183  #include <linux/spinlock.h>
26184 +#include <linux/vs_tag.h>
26185  
26186  #ifdef RPC_DEBUG
26187  # define RPCDBG_FACILITY       RPCDBG_AUTH
26188 @@ -427,6 +428,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
26189         memset(&acred, 0, sizeof(acred));
26190         acred.uid = cred->fsuid;
26191         acred.gid = cred->fsgid;
26192 +       acred.tag = dx_current_tag();
26193         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
26194  
26195         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
26196 @@ -467,6 +469,7 @@ rpcauth_bind_root_cred(struct rpc_task *
26197         struct auth_cred acred = {
26198                 .uid = 0,
26199                 .gid = 0,
26200 +               .tag = dx_current_tag(),
26201         };
26202  
26203         dprintk("RPC: %5u looking up %s cred\n",
26204 diff -NurpP --minimal linux-3.1.1/net/sunrpc/auth_unix.c linux-3.1.1-vs2.3.2/net/sunrpc/auth_unix.c
26205 --- linux-3.1.1/net/sunrpc/auth_unix.c  2011-11-15 16:44:52.000000000 +0100
26206 +++ linux-3.1.1-vs2.3.2/net/sunrpc/auth_unix.c  2011-11-15 17:08:44.000000000 +0100
26207 @@ -12,12 +12,14 @@
26208  #include <linux/module.h>
26209  #include <linux/sunrpc/clnt.h>
26210  #include <linux/sunrpc/auth.h>
26211 +#include <linux/vs_tag.h>
26212  
26213  #define NFS_NGROUPS    16
26214  
26215  struct unx_cred {
26216         struct rpc_cred         uc_base;
26217         gid_t                   uc_gid;
26218 +       tag_t                   uc_tag;
26219         gid_t                   uc_gids[NFS_NGROUPS];
26220  };
26221  #define uc_uid                 uc_base.cr_uid
26222 @@ -78,6 +80,7 @@ unx_create_cred(struct rpc_auth *auth, s
26223                 groups = NFS_NGROUPS;
26224  
26225         cred->uc_gid = acred->gid;
26226 +       cred->uc_tag = acred->tag;
26227         for (i = 0; i < groups; i++)
26228                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
26229         if (i < NFS_NGROUPS)
26230 @@ -119,7 +122,9 @@ unx_match(struct auth_cred *acred, struc
26231         unsigned int i;
26232  
26233  
26234 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
26235 +       if (cred->uc_uid != acred->uid ||
26236 +               cred->uc_gid != acred->gid ||
26237 +               cred->uc_tag != acred->tag)
26238                 return 0;
26239  
26240         if (acred->group_info != NULL)
26241 @@ -145,7 +150,7 @@ unx_marshal(struct rpc_task *task, __be3
26242         struct rpc_clnt *clnt = task->tk_client;
26243         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
26244         __be32          *base, *hold;
26245 -       int             i;
26246 +       int             i, tag;
26247  
26248         *p++ = htonl(RPC_AUTH_UNIX);
26249         base = p++;
26250 @@ -155,9 +160,12 @@ unx_marshal(struct rpc_task *task, __be3
26251          * Copy the UTS nodename captured when the client was created.
26252          */
26253         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
26254 +       tag = task->tk_client->cl_tag;
26255  
26256 -       *p++ = htonl((u32) cred->uc_uid);
26257 -       *p++ = htonl((u32) cred->uc_gid);
26258 +       *p++ = htonl((u32) TAGINO_UID(tag,
26259 +               cred->uc_uid, cred->uc_tag));
26260 +       *p++ = htonl((u32) TAGINO_GID(tag,
26261 +               cred->uc_gid, cred->uc_tag));
26262         hold = p++;
26263         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
26264                 *p++ = htonl((u32) cred->uc_gids[i]);
26265 diff -NurpP --minimal linux-3.1.1/net/sunrpc/clnt.c linux-3.1.1-vs2.3.2/net/sunrpc/clnt.c
26266 --- linux-3.1.1/net/sunrpc/clnt.c       2011-10-24 18:45:34.000000000 +0200
26267 +++ linux-3.1.1-vs2.3.2/net/sunrpc/clnt.c       2011-10-24 18:53:33.000000000 +0200
26268 @@ -31,6 +31,7 @@
26269  #include <linux/in.h>
26270  #include <linux/in6.h>
26271  #include <linux/un.h>
26272 +#include <linux/vs_cvirt.h>
26273  
26274  #include <linux/sunrpc/clnt.h>
26275  #include <linux/sunrpc/rpc_pipe_fs.h>
26276 @@ -361,6 +362,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
26277         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
26278                 clnt->cl_chatty = 1;
26279  
26280 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
26281 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
26282 +               clnt->cl_tag = 1; */
26283         return clnt;
26284  }
26285  EXPORT_SYMBOL_GPL(rpc_create);
26286 diff -NurpP --minimal linux-3.1.1/net/unix/af_unix.c linux-3.1.1-vs2.3.2/net/unix/af_unix.c
26287 --- linux-3.1.1/net/unix/af_unix.c      2011-10-24 18:45:34.000000000 +0200
26288 +++ linux-3.1.1-vs2.3.2/net/unix/af_unix.c      2011-10-24 18:53:33.000000000 +0200
26289 @@ -114,6 +114,8 @@
26290  #include <linux/mount.h>
26291  #include <net/checksum.h>
26292  #include <linux/security.h>
26293 +#include <linux/vs_context.h>
26294 +#include <linux/vs_limit.h>
26295  
26296  static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
26297  static DEFINE_SPINLOCK(unix_table_lock);
26298 @@ -258,6 +260,8 @@ static struct sock *__unix_find_socket_b
26299                 if (!net_eq(sock_net(s), net))
26300                         continue;
26301  
26302 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26303 +                       continue;
26304                 if (u->addr->len == len &&
26305                     !memcmp(u->addr->name, sunname, len))
26306                         goto found;
26307 @@ -2204,6 +2208,8 @@ static struct sock *unix_seq_idx(struct 
26308         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
26309                 if (sock_net(s) != seq_file_net(seq))
26310                         continue;
26311 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26312 +                       continue;
26313                 if (off == pos)
26314                         return s;
26315                 ++off;
26316 @@ -2228,7 +2234,8 @@ static void *unix_seq_next(struct seq_fi
26317                 sk = first_unix_socket(&iter->i);
26318         else
26319                 sk = next_unix_socket(&iter->i, sk);
26320 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
26321 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
26322 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
26323                 sk = next_unix_socket(&iter->i, sk);
26324         return sk;
26325  }
26326 diff -NurpP --minimal linux-3.1.1/scripts/checksyscalls.sh linux-3.1.1-vs2.3.2/scripts/checksyscalls.sh
26327 --- linux-3.1.1/scripts/checksyscalls.sh        2011-03-15 18:07:46.000000000 +0100
26328 +++ linux-3.1.1-vs2.3.2/scripts/checksyscalls.sh        2011-10-24 18:53:33.000000000 +0200
26329 @@ -193,7 +193,6 @@ cat << EOF
26330  #define __IGNORE_afs_syscall
26331  #define __IGNORE_getpmsg
26332  #define __IGNORE_putpmsg
26333 -#define __IGNORE_vserver
26334  EOF
26335  }
26336  
26337 diff -NurpP --minimal linux-3.1.1/security/commoncap.c linux-3.1.1-vs2.3.2/security/commoncap.c
26338 --- linux-3.1.1/security/commoncap.c    2011-07-22 11:18:14.000000000 +0200
26339 +++ linux-3.1.1-vs2.3.2/security/commoncap.c    2011-10-24 18:53:33.000000000 +0200
26340 @@ -62,6 +62,7 @@ int cap_netlink_recv(struct sk_buff *skb
26341                 return -EPERM;
26342         return 0;
26343  }
26344 +
26345  EXPORT_SYMBOL(cap_netlink_recv);
26346  
26347  /**
26348 @@ -83,14 +84,20 @@ EXPORT_SYMBOL(cap_netlink_recv);
26349  int cap_capable(struct task_struct *tsk, const struct cred *cred,
26350                 struct user_namespace *targ_ns, int cap, int audit)
26351  {
26352 +       struct vx_info *vxi = tsk->vx_info;
26353 +
26354         for (;;) {
26355                 /* The creator of the user namespace has all caps. */
26356                 if (targ_ns != &init_user_ns && targ_ns->creator == cred->user)
26357                         return 0;
26358  
26359                 /* Do we have the necessary capabilities? */
26360 -               if (targ_ns == cred->user->user_ns)
26361 -                       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
26362 +               if (targ_ns == cred->user->user_ns) {
26363 +                       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
26364 +                           cap_raised(cred->cap_effective, cap))
26365 +                               return 0;
26366 +                       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
26367 +               }
26368  
26369                 /* Have we tried all of the parent namespaces? */
26370                 if (targ_ns == &init_user_ns)
26371 @@ -611,7 +618,7 @@ int cap_inode_setxattr(struct dentry *de
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 @@ -637,7 +644,7 @@ int cap_inode_removexattr(struct dentry 
26381  
26382         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26383                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26384 -           !capable(CAP_SYS_ADMIN))
26385 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26386                 return -EPERM;
26387         return 0;
26388  }
26389 diff -NurpP --minimal linux-3.1.1/security/selinux/hooks.c linux-3.1.1-vs2.3.2/security/selinux/hooks.c
26390 --- linux-3.1.1/security/selinux/hooks.c        2011-10-24 18:45:35.000000000 +0200
26391 +++ linux-3.1.1-vs2.3.2/security/selinux/hooks.c        2011-10-24 18:53:33.000000000 +0200
26392 @@ -67,7 +67,6 @@
26393  #include <linux/dccp.h>
26394  #include <linux/quota.h>
26395  #include <linux/un.h>          /* for Unix socket types */
26396 -#include <net/af_unix.h>       /* for Unix socket types */
26397  #include <linux/parser.h>
26398  #include <linux/nfs_mount.h>
26399  #include <net/ipv6.h>
This page took 2.385192 seconds and 3 git commands to generate.