]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- vserver-2.3.2.5
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-3.1.6/Documentation/vserver/debug.txt linux-3.1.6-vs2.3.2.5/Documentation/vserver/debug.txt
2 --- linux-3.1.6/Documentation/vserver/debug.txt 1970-01-01 01:00:00.000000000 +0100
3 +++ linux-3.1.6-vs2.3.2.5/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.6/arch/alpha/Kconfig linux-3.1.6-vs2.3.2.5/arch/alpha/Kconfig
160 --- linux-3.1.6/arch/alpha/Kconfig      2011-10-24 18:44:54.000000000 +0200
161 +++ linux-3.1.6-vs2.3.2.5/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.6/arch/alpha/kernel/entry.S linux-3.1.6-vs2.3.2.5/arch/alpha/kernel/entry.S
172 --- linux-3.1.6/arch/alpha/kernel/entry.S       2010-10-21 13:06:45.000000000 +0200
173 +++ linux-3.1.6-vs2.3.2.5/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.6/arch/alpha/kernel/ptrace.c linux-3.1.6-vs2.3.2.5/arch/alpha/kernel/ptrace.c
207 --- linux-3.1.6/arch/alpha/kernel/ptrace.c      2011-01-05 21:48:40.000000000 +0100
208 +++ linux-3.1.6-vs2.3.2.5/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.6/arch/alpha/kernel/systbls.S linux-3.1.6-vs2.3.2.5/arch/alpha/kernel/systbls.S
218 --- linux-3.1.6/arch/alpha/kernel/systbls.S     2011-10-24 18:44:54.000000000 +0200
219 +++ linux-3.1.6-vs2.3.2.5/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.6/arch/alpha/kernel/traps.c linux-3.1.6-vs2.3.2.5/arch/alpha/kernel/traps.c
230 --- linux-3.1.6/arch/alpha/kernel/traps.c       2010-10-21 13:06:46.000000000 +0200
231 +++ linux-3.1.6-vs2.3.2.5/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.6/arch/arm/Kconfig linux-3.1.6-vs2.3.2.5/arch/arm/Kconfig
243 --- linux-3.1.6/arch/arm/Kconfig        2011-12-23 16:04:05.000000000 +0100
244 +++ linux-3.1.6-vs2.3.2.5/arch/arm/Kconfig      2011-12-15 01:07:58.000000000 +0100
245 @@ -2123,6 +2123,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.6/arch/arm/kernel/calls.S linux-3.1.6-vs2.3.2.5/arch/arm/kernel/calls.S
255 --- linux-3.1.6/arch/arm/kernel/calls.S 2011-10-24 18:44:54.000000000 +0200
256 +++ linux-3.1.6-vs2.3.2.5/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.6/arch/arm/kernel/process.c linux-3.1.6-vs2.3.2.5/arch/arm/kernel/process.c
267 --- linux-3.1.6/arch/arm/kernel/process.c       2011-12-23 16:04:05.000000000 +0100
268 +++ linux-3.1.6-vs2.3.2.5/arch/arm/kernel/process.c     2011-12-15 01:07:58.000000000 +0100
269 @@ -320,7 +320,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.6/arch/arm/kernel/traps.c linux-3.1.6-vs2.3.2.5/arch/arm/kernel/traps.c
280 --- linux-3.1.6/arch/arm/kernel/traps.c 2011-10-24 18:44:54.000000000 +0200
281 +++ linux-3.1.6-vs2.3.2.5/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.6/arch/cris/Kconfig linux-3.1.6-vs2.3.2.5/arch/cris/Kconfig
294 --- linux-3.1.6/arch/cris/Kconfig       2011-07-22 11:17:35.000000000 +0200
295 +++ linux-3.1.6-vs2.3.2.5/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.6/arch/frv/kernel/kernel_thread.S linux-3.1.6-vs2.3.2.5/arch/frv/kernel/kernel_thread.S
306 --- linux-3.1.6/arch/frv/kernel/kernel_thread.S 2008-12-25 00:26:37.000000000 +0100
307 +++ linux-3.1.6-vs2.3.2.5/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.6/arch/h8300/Kconfig linux-3.1.6-vs2.3.2.5/arch/h8300/Kconfig
318 --- linux-3.1.6/arch/h8300/Kconfig      2011-07-22 11:17:35.000000000 +0200
319 +++ linux-3.1.6-vs2.3.2.5/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.6/arch/ia64/Kconfig linux-3.1.6-vs2.3.2.5/arch/ia64/Kconfig
330 --- linux-3.1.6/arch/ia64/Kconfig       2011-10-24 18:44:58.000000000 +0200
331 +++ linux-3.1.6-vs2.3.2.5/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.6/arch/ia64/kernel/entry.S linux-3.1.6-vs2.3.2.5/arch/ia64/kernel/entry.S
342 --- linux-3.1.6/arch/ia64/kernel/entry.S        2011-10-24 18:44:58.000000000 +0200
343 +++ linux-3.1.6-vs2.3.2.5/arch/ia64/kernel/entry.S      2011-10-24 18:53:33.000000000 +0200
344 @@ -1714,7 +1714,7 @@ sys_call_table:
345         data8 sys_mq_notify
346         data8 sys_mq_getsetattr
347         data8 sys_kexec_load
348 -       data8 sys_ni_syscall                    // reserved for vserver
349 +       data8 sys_vserver
350         data8 sys_waitid                        // 1270
351         data8 sys_add_key
352         data8 sys_request_key
353 diff -NurpP --minimal linux-3.1.6/arch/ia64/kernel/process.c linux-3.1.6-vs2.3.2.5/arch/ia64/kernel/process.c
354 --- linux-3.1.6/arch/ia64/kernel/process.c      2011-03-15 18:06:39.000000000 +0100
355 +++ linux-3.1.6-vs2.3.2.5/arch/ia64/kernel/process.c    2011-10-24 18:53:33.000000000 +0200
356 @@ -109,8 +109,8 @@ show_regs (struct pt_regs *regs)
357         unsigned long ip = regs->cr_iip + ia64_psr(regs)->ri;
358  
359         print_modules();
360 -       printk("\nPid: %d, CPU %d, comm: %20s\n", task_pid_nr(current),
361 -                       smp_processor_id(), current->comm);
362 +       printk("\nPid: %d[#%u], CPU %d, comm: %20s\n", task_pid_nr(current),
363 +                       current->xid, smp_processor_id(), current->comm);
364         printk("psr : %016lx ifs : %016lx ip  : [<%016lx>]    %s (%s)\n",
365                regs->cr_ipsr, regs->cr_ifs, ip, print_tainted(),
366                init_utsname()->release);
367 diff -NurpP --minimal linux-3.1.6/arch/ia64/kernel/ptrace.c linux-3.1.6-vs2.3.2.5/arch/ia64/kernel/ptrace.c
368 --- linux-3.1.6/arch/ia64/kernel/ptrace.c       2011-01-05 21:48:59.000000000 +0100
369 +++ linux-3.1.6-vs2.3.2.5/arch/ia64/kernel/ptrace.c     2011-10-24 18:53:33.000000000 +0200
370 @@ -21,6 +21,7 @@
371  #include <linux/regset.h>
372  #include <linux/elf.h>
373  #include <linux/tracehook.h>
374 +#include <linux/vs_base.h>
375  
376  #include <asm/pgtable.h>
377  #include <asm/processor.h>
378 diff -NurpP --minimal linux-3.1.6/arch/ia64/kernel/traps.c linux-3.1.6-vs2.3.2.5/arch/ia64/kernel/traps.c
379 --- linux-3.1.6/arch/ia64/kernel/traps.c        2010-07-07 18:31:01.000000000 +0200
380 +++ linux-3.1.6-vs2.3.2.5/arch/ia64/kernel/traps.c      2011-10-24 18:53:33.000000000 +0200
381 @@ -59,8 +59,9 @@ die (const char *str, struct pt_regs *re
382         put_cpu();
383  
384         if (++die.lock_owner_depth < 3) {
385 -               printk("%s[%d]: %s %ld [%d]\n",
386 -               current->comm, task_pid_nr(current), str, err, ++die_counter);
387 +               printk("%s[%d[#%u]]: %s %ld [%d]\n",
388 +                       current->comm, task_pid_nr(current), current->xid,
389 +                       str, err, ++die_counter);
390                 if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV)
391                     != NOTIFY_STOP)
392                         show_regs(regs);
393 @@ -323,8 +324,9 @@ handle_fpu_swa (int fp_fault, struct pt_
394                         if ((last.count & 15) < 5 && (ia64_fetchadd(1, &last.count, acq) & 15) < 5) {
395                                 last.time = current_jiffies + 5 * HZ;
396                                 printk(KERN_WARNING
397 -                                       "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
398 -                                       current->comm, task_pid_nr(current), regs->cr_iip + ia64_psr(regs)->ri, isr);
399 +                                       "%s(%d[#%u]): floating-point assist fault at ip %016lx, isr %016lx\n",
400 +                                       current->comm, task_pid_nr(current), current->xid,
401 +                                       regs->cr_iip + ia64_psr(regs)->ri, isr);
402                         }
403                 }
404         }
405 diff -NurpP --minimal linux-3.1.6/arch/m32r/kernel/traps.c linux-3.1.6-vs2.3.2.5/arch/m32r/kernel/traps.c
406 --- linux-3.1.6/arch/m32r/kernel/traps.c        2011-10-24 18:44:58.000000000 +0200
407 +++ linux-3.1.6-vs2.3.2.5/arch/m32r/kernel/traps.c      2011-10-24 18:53:33.000000000 +0200
408 @@ -196,8 +196,9 @@ static void show_registers(struct pt_reg
409         } else {
410                 printk("SPI: %08lx\n", sp);
411         }
412 -       printk("Process %s (pid: %d, process nr: %d, stackpage=%08lx)",
413 -               current->comm, task_pid_nr(current), 0xffff & i, 4096+(unsigned long)current);
414 +       printk("Process %s (pid: %d[#%u], process nr: %d, stackpage=%08lx)",
415 +               current->comm, task_pid_nr(current), current->xid,
416 +               0xffff & i, 4096+(unsigned long)current);
417  
418         /*
419          * When in-kernel, we also print out the stack and code at the
420 diff -NurpP --minimal linux-3.1.6/arch/m68k/Kconfig linux-3.1.6-vs2.3.2.5/arch/m68k/Kconfig
421 --- linux-3.1.6/arch/m68k/Kconfig       2011-10-24 18:44:58.000000000 +0200
422 +++ linux-3.1.6-vs2.3.2.5/arch/m68k/Kconfig     2011-10-24 18:53:33.000000000 +0200
423 @@ -246,6 +246,8 @@ source "fs/Kconfig"
424  
425  source "arch/m68k/Kconfig.debug"
426  
427 +source "kernel/vserver/Kconfig"
428 +
429  source "security/Kconfig"
430  
431  source "crypto/Kconfig"
432 diff -NurpP --minimal linux-3.1.6/arch/mips/Kconfig linux-3.1.6-vs2.3.2.5/arch/mips/Kconfig
433 --- linux-3.1.6/arch/mips/Kconfig       2011-10-24 18:44:59.000000000 +0200
434 +++ linux-3.1.6-vs2.3.2.5/arch/mips/Kconfig     2011-10-24 18:53:33.000000000 +0200
435 @@ -2495,6 +2495,8 @@ source "fs/Kconfig"
436  
437  source "arch/mips/Kconfig.debug"
438  
439 +source "kernel/vserver/Kconfig"
440 +
441  source "security/Kconfig"
442  
443  source "crypto/Kconfig"
444 diff -NurpP --minimal linux-3.1.6/arch/mips/kernel/ptrace.c linux-3.1.6-vs2.3.2.5/arch/mips/kernel/ptrace.c
445 --- linux-3.1.6/arch/mips/kernel/ptrace.c       2011-07-22 11:17:36.000000000 +0200
446 +++ linux-3.1.6-vs2.3.2.5/arch/mips/kernel/ptrace.c     2011-10-24 18:53:33.000000000 +0200
447 @@ -25,6 +25,7 @@
448  #include <linux/security.h>
449  #include <linux/audit.h>
450  #include <linux/seccomp.h>
451 +#include <linux/vs_base.h>
452  
453  #include <asm/byteorder.h>
454  #include <asm/cpu.h>
455 @@ -263,6 +264,9 @@ long arch_ptrace(struct task_struct *chi
456         void __user *datavp = (void __user *) data;
457         unsigned long __user *datalp = (void __user *) data;
458  
459 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
460 +               goto out;
461 +
462         switch (request) {
463         /* when I and D space are separate, these will need to be fixed. */
464         case PTRACE_PEEKTEXT: /* read word at location addr. */
465 diff -NurpP --minimal linux-3.1.6/arch/mips/kernel/scall32-o32.S linux-3.1.6-vs2.3.2.5/arch/mips/kernel/scall32-o32.S
466 --- linux-3.1.6/arch/mips/kernel/scall32-o32.S  2011-10-24 18:44:59.000000000 +0200
467 +++ linux-3.1.6-vs2.3.2.5/arch/mips/kernel/scall32-o32.S        2011-10-24 18:53:33.000000000 +0200
468 @@ -523,7 +523,7 @@ einval:     li      v0, -ENOSYS
469         sys     sys_mq_timedreceive     5
470         sys     sys_mq_notify           2       /* 4275 */
471         sys     sys_mq_getsetattr       3
472 -       sys     sys_ni_syscall          0       /* sys_vserver */
473 +       sys     sys_vserver             3
474         sys     sys_waitid              5
475         sys     sys_ni_syscall          0       /* available, was setaltroot */
476         sys     sys_add_key             5       /* 4280 */
477 diff -NurpP --minimal linux-3.1.6/arch/mips/kernel/scall64-64.S linux-3.1.6-vs2.3.2.5/arch/mips/kernel/scall64-64.S
478 --- linux-3.1.6/arch/mips/kernel/scall64-64.S   2011-10-24 18:44:59.000000000 +0200
479 +++ linux-3.1.6-vs2.3.2.5/arch/mips/kernel/scall64-64.S 2011-10-24 18:53:33.000000000 +0200
480 @@ -362,7 +362,7 @@ sys_call_table:
481         PTR     sys_mq_timedreceive
482         PTR     sys_mq_notify
483         PTR     sys_mq_getsetattr               /* 5235 */
484 -       PTR     sys_ni_syscall                  /* sys_vserver */
485 +       PTR     sys_vserver
486         PTR     sys_waitid
487         PTR     sys_ni_syscall                  /* available, was setaltroot */
488         PTR     sys_add_key
489 diff -NurpP --minimal linux-3.1.6/arch/mips/kernel/scall64-n32.S linux-3.1.6-vs2.3.2.5/arch/mips/kernel/scall64-n32.S
490 --- linux-3.1.6/arch/mips/kernel/scall64-n32.S  2011-10-24 18:44:59.000000000 +0200
491 +++ linux-3.1.6-vs2.3.2.5/arch/mips/kernel/scall64-n32.S        2011-10-24 18:53:33.000000000 +0200
492 @@ -361,7 +361,7 @@ EXPORT(sysn32_call_table)
493         PTR     compat_sys_mq_timedreceive
494         PTR     compat_sys_mq_notify
495         PTR     compat_sys_mq_getsetattr
496 -       PTR     sys_ni_syscall                  /* 6240, sys_vserver */
497 +       PTR     sys32_vserver                   /* 6240 */
498         PTR     compat_sys_waitid
499         PTR     sys_ni_syscall                  /* available, was setaltroot */
500         PTR     sys_add_key
501 diff -NurpP --minimal linux-3.1.6/arch/mips/kernel/scall64-o32.S linux-3.1.6-vs2.3.2.5/arch/mips/kernel/scall64-o32.S
502 --- linux-3.1.6/arch/mips/kernel/scall64-o32.S  2011-10-24 18:44:59.000000000 +0200
503 +++ linux-3.1.6-vs2.3.2.5/arch/mips/kernel/scall64-o32.S        2011-10-24 18:53:33.000000000 +0200
504 @@ -480,7 +480,7 @@ sys_call_table:
505         PTR     compat_sys_mq_timedreceive
506         PTR     compat_sys_mq_notify            /* 4275 */
507         PTR     compat_sys_mq_getsetattr
508 -       PTR     sys_ni_syscall                  /* sys_vserver */
509 +       PTR     sys32_vserver
510         PTR     sys_32_waitid
511         PTR     sys_ni_syscall                  /* available, was setaltroot */
512         PTR     sys_add_key                     /* 4280 */
513 diff -NurpP --minimal linux-3.1.6/arch/mips/kernel/traps.c linux-3.1.6-vs2.3.2.5/arch/mips/kernel/traps.c
514 --- linux-3.1.6/arch/mips/kernel/traps.c        2011-10-24 18:44:59.000000000 +0200
515 +++ linux-3.1.6-vs2.3.2.5/arch/mips/kernel/traps.c      2011-10-24 18:53:33.000000000 +0200
516 @@ -344,9 +344,10 @@ void show_registers(struct pt_regs *regs
517  
518         __show_regs(regs);
519         print_modules();
520 -       printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
521 -              current->comm, current->pid, current_thread_info(), current,
522 -             field, current_thread_info()->tp_value);
523 +       printk("Process %s (pid: %d:#%u, threadinfo=%p, task=%p, tls=%0*lx)\n",
524 +               current->comm, task_pid_nr(current), current->xid,
525 +               current_thread_info(), current,
526 +               field, current_thread_info()->tp_value);
527         if (cpu_has_userlocal) {
528                 unsigned long tls;
529  
530 diff -NurpP --minimal linux-3.1.6/arch/parisc/Kconfig linux-3.1.6-vs2.3.2.5/arch/parisc/Kconfig
531 --- linux-3.1.6/arch/parisc/Kconfig     2011-10-24 18:44:59.000000000 +0200
532 +++ linux-3.1.6-vs2.3.2.5/arch/parisc/Kconfig   2011-10-24 18:53:33.000000000 +0200
533 @@ -280,6 +280,8 @@ source "fs/Kconfig"
534  
535  source "arch/parisc/Kconfig.debug"
536  
537 +source "kernel/vserver/Kconfig"
538 +
539  source "security/Kconfig"
540  
541  source "crypto/Kconfig"
542 diff -NurpP --minimal linux-3.1.6/arch/parisc/kernel/syscall_table.S linux-3.1.6-vs2.3.2.5/arch/parisc/kernel/syscall_table.S
543 --- linux-3.1.6/arch/parisc/kernel/syscall_table.S      2011-10-24 18:45:00.000000000 +0200
544 +++ linux-3.1.6-vs2.3.2.5/arch/parisc/kernel/syscall_table.S    2011-10-24 18:53:33.000000000 +0200
545 @@ -361,7 +361,7 @@
546         ENTRY_COMP(mbind)               /* 260 */
547         ENTRY_COMP(get_mempolicy)
548         ENTRY_COMP(set_mempolicy)
549 -       ENTRY_SAME(ni_syscall)  /* 263: reserved for vserver */
550 +       ENTRY_DIFF(vserver)
551         ENTRY_SAME(add_key)
552         ENTRY_SAME(request_key)         /* 265 */
553         ENTRY_SAME(keyctl)
554 diff -NurpP --minimal linux-3.1.6/arch/parisc/kernel/traps.c linux-3.1.6-vs2.3.2.5/arch/parisc/kernel/traps.c
555 --- linux-3.1.6/arch/parisc/kernel/traps.c      2011-10-24 18:45:00.000000000 +0200
556 +++ linux-3.1.6-vs2.3.2.5/arch/parisc/kernel/traps.c    2011-10-24 18:53:33.000000000 +0200
557 @@ -236,8 +236,9 @@ void die_if_kernel(char *str, struct pt_
558                 if (err == 0)
559                         return; /* STFU */
560  
561 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
562 -                       current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
563 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld) at " RFMT "\n",
564 +                       current->comm, task_pid_nr(current), current->xid,
565 +                       str, err, regs->iaoq[0]);
566  #ifdef PRINT_USER_FAULTS
567                 /* XXX for debugging only */
568                 show_regs(regs);
569 @@ -270,8 +271,8 @@ void die_if_kernel(char *str, struct pt_
570                 pdc_console_restart();
571         
572         if (err)
573 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
574 -                       current->comm, task_pid_nr(current), str, err);
575 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld)\n",
576 +                       current->comm, task_pid_nr(current), current->xid, str, err);
577  
578         /* Wot's wrong wif bein' racy? */
579         if (current->thread.flags & PARISC_KERNEL_DEATH) {
580 diff -NurpP --minimal linux-3.1.6/arch/parisc/mm/fault.c linux-3.1.6-vs2.3.2.5/arch/parisc/mm/fault.c
581 --- linux-3.1.6/arch/parisc/mm/fault.c  2010-08-02 16:52:06.000000000 +0200
582 +++ linux-3.1.6-vs2.3.2.5/arch/parisc/mm/fault.c        2011-10-24 18:53:33.000000000 +0200
583 @@ -237,8 +237,9 @@ bad_area:
584  
585  #ifdef PRINT_USER_FAULTS
586                 printk(KERN_DEBUG "\n");
587 -               printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n",
588 -                   task_pid_nr(tsk), tsk->comm, code, address);
589 +               printk(KERN_DEBUG "do_page_fault() pid=%d:#%u "
590 +                   "command='%s' type=%lu address=0x%08lx\n",
591 +                   task_pid_nr(tsk), tsk->xid, tsk->comm, code, address);
592                 if (vma) {
593                         printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n",
594                                         vma->vm_start, vma->vm_end);
595 diff -NurpP --minimal linux-3.1.6/arch/powerpc/Kconfig linux-3.1.6-vs2.3.2.5/arch/powerpc/Kconfig
596 --- linux-3.1.6/arch/powerpc/Kconfig    2011-10-24 18:45:00.000000000 +0200
597 +++ linux-3.1.6-vs2.3.2.5/arch/powerpc/Kconfig  2011-10-24 18:53:33.000000000 +0200
598 @@ -981,6 +981,8 @@ source "lib/Kconfig"
599  
600  source "arch/powerpc/Kconfig.debug"
601  
602 +source "kernel/vserver/Kconfig"
603 +
604  source "security/Kconfig"
605  
606  config KEYS_COMPAT
607 diff -NurpP --minimal linux-3.1.6/arch/powerpc/include/asm/unistd.h linux-3.1.6-vs2.3.2.5/arch/powerpc/include/asm/unistd.h
608 --- linux-3.1.6/arch/powerpc/include/asm/unistd.h       2011-07-22 11:17:40.000000000 +0200
609 +++ linux-3.1.6-vs2.3.2.5/arch/powerpc/include/asm/unistd.h     2011-10-24 18:53:33.000000000 +0200
610 @@ -275,7 +275,7 @@
611  #endif
612  #define __NR_rtas              255
613  #define __NR_sys_debug_setcontext 256
614 -/* Number 257 is reserved for vserver */
615 +#define __NR_vserver           257
616  #define __NR_migrate_pages     258
617  #define __NR_mbind             259
618  #define __NR_get_mempolicy     260
619 diff -NurpP --minimal linux-3.1.6/arch/powerpc/kernel/process.c linux-3.1.6-vs2.3.2.5/arch/powerpc/kernel/process.c
620 --- linux-3.1.6/arch/powerpc/kernel/process.c   2011-10-24 18:45:00.000000000 +0200
621 +++ linux-3.1.6-vs2.3.2.5/arch/powerpc/kernel/process.c 2011-10-24 18:53:33.000000000 +0200
622 @@ -662,8 +662,9 @@ void show_regs(struct pt_regs * regs)
623  #else
624                 printk("DAR: "REG", DSISR: %08lx\n", regs->dar, regs->dsisr);
625  #endif
626 -       printk("TASK = %p[%d] '%s' THREAD: %p",
627 -              current, task_pid_nr(current), current->comm, task_thread_info(current));
628 +       printk("TASK = %p[%d,#%u] '%s' THREAD: %p",
629 +              current, task_pid_nr(current), current->xid,
630 +              current->comm, task_thread_info(current));
631  
632  #ifdef CONFIG_SMP
633         printk(" CPU: %d", raw_smp_processor_id());
634 diff -NurpP --minimal linux-3.1.6/arch/powerpc/kernel/traps.c linux-3.1.6-vs2.3.2.5/arch/powerpc/kernel/traps.c
635 --- linux-3.1.6/arch/powerpc/kernel/traps.c     2011-10-24 18:45:00.000000000 +0200
636 +++ linux-3.1.6-vs2.3.2.5/arch/powerpc/kernel/traps.c   2011-10-24 18:53:33.000000000 +0200
637 @@ -1075,8 +1075,9 @@ void nonrecoverable_exception(struct pt_
638  
639  void trace_syscall(struct pt_regs *regs)
640  {
641 -       printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
642 -              current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
643 +       printk("Task: %p(%d[#%u]), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
644 +              current, task_pid_nr(current), current->xid,
645 +              regs->nip, regs->link, regs->gpr[0],
646                regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
647  }
648  
649 diff -NurpP --minimal linux-3.1.6/arch/s390/Kconfig linux-3.1.6-vs2.3.2.5/arch/s390/Kconfig
650 --- linux-3.1.6/arch/s390/Kconfig       2011-10-24 18:45:01.000000000 +0200
651 +++ linux-3.1.6-vs2.3.2.5/arch/s390/Kconfig     2011-10-24 18:53:33.000000000 +0200
652 @@ -629,6 +629,8 @@ source "fs/Kconfig"
653  
654  source "arch/s390/Kconfig.debug"
655  
656 +source "kernel/vserver/Kconfig"
657 +
658  source "security/Kconfig"
659  
660  source "crypto/Kconfig"
661 diff -NurpP --minimal linux-3.1.6/arch/s390/include/asm/tlb.h linux-3.1.6-vs2.3.2.5/arch/s390/include/asm/tlb.h
662 --- linux-3.1.6/arch/s390/include/asm/tlb.h     2011-07-22 11:17:41.000000000 +0200
663 +++ linux-3.1.6-vs2.3.2.5/arch/s390/include/asm/tlb.h   2011-12-07 04:18:50.000000000 +0100
664 @@ -24,6 +24,7 @@
665  #include <linux/mm.h>
666  #include <linux/pagemap.h>
667  #include <linux/swap.h>
668 +
669  #include <asm/processor.h>
670  #include <asm/pgalloc.h>
671  #include <asm/tlbflush.h>
672 diff -NurpP --minimal linux-3.1.6/arch/s390/include/asm/unistd.h linux-3.1.6-vs2.3.2.5/arch/s390/include/asm/unistd.h
673 --- linux-3.1.6/arch/s390/include/asm/unistd.h  2011-07-22 11:17:41.000000000 +0200
674 +++ linux-3.1.6-vs2.3.2.5/arch/s390/include/asm/unistd.h        2011-10-24 18:53:33.000000000 +0200
675 @@ -202,7 +202,7 @@
676  #define __NR_clock_gettime     (__NR_timer_create+6)
677  #define __NR_clock_getres      (__NR_timer_create+7)
678  #define __NR_clock_nanosleep   (__NR_timer_create+8)
679 -/* Number 263 is reserved for vserver */
680 +#define __NR_vserver           263
681  #define __NR_statfs64          265
682  #define __NR_fstatfs64         266
683  #define __NR_remap_file_pages  267
684 diff -NurpP --minimal linux-3.1.6/arch/s390/kernel/ptrace.c linux-3.1.6-vs2.3.2.5/arch/s390/kernel/ptrace.c
685 --- linux-3.1.6/arch/s390/kernel/ptrace.c       2011-12-23 16:04:05.000000000 +0100
686 +++ linux-3.1.6-vs2.3.2.5/arch/s390/kernel/ptrace.c     2011-12-15 01:07:58.000000000 +0100
687 @@ -20,6 +20,7 @@
688  #include <linux/regset.h>
689  #include <linux/tracehook.h>
690  #include <linux/seccomp.h>
691 +#include <linux/vs_base.h>
692  #include <trace/syscall.h>
693  #include <asm/compat.h>
694  #include <asm/segment.h>
695 diff -NurpP --minimal linux-3.1.6/arch/s390/kernel/syscalls.S linux-3.1.6-vs2.3.2.5/arch/s390/kernel/syscalls.S
696 --- linux-3.1.6/arch/s390/kernel/syscalls.S     2011-10-24 18:45:01.000000000 +0200
697 +++ linux-3.1.6-vs2.3.2.5/arch/s390/kernel/syscalls.S   2011-10-24 18:53:33.000000000 +0200
698 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
699  SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper)       /* 260 */
700  SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
701  SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
702 -NI_SYSCALL                                                     /* reserved for vserver */
703 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
704  SYSCALL(sys_s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
705  SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
706  SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
707 diff -NurpP --minimal linux-3.1.6/arch/sh/Kconfig linux-3.1.6-vs2.3.2.5/arch/sh/Kconfig
708 --- linux-3.1.6/arch/sh/Kconfig 2011-10-24 18:45:01.000000000 +0200
709 +++ linux-3.1.6-vs2.3.2.5/arch/sh/Kconfig       2011-10-24 18:53:33.000000000 +0200
710 @@ -894,6 +894,8 @@ source "fs/Kconfig"
711  
712  source "arch/sh/Kconfig.debug"
713  
714 +source "kernel/vserver/Kconfig"
715 +
716  source "security/Kconfig"
717  
718  source "crypto/Kconfig"
719 diff -NurpP --minimal linux-3.1.6/arch/sh/kernel/irq.c linux-3.1.6-vs2.3.2.5/arch/sh/kernel/irq.c
720 --- linux-3.1.6/arch/sh/kernel/irq.c    2011-07-22 11:17:41.000000000 +0200
721 +++ linux-3.1.6-vs2.3.2.5/arch/sh/kernel/irq.c  2011-10-24 18:53:33.000000000 +0200
722 @@ -14,6 +14,7 @@
723  #include <linux/ftrace.h>
724  #include <linux/delay.h>
725  #include <linux/ratelimit.h>
726 +// #include <linux/vs_context.h>
727  #include <asm/processor.h>
728  #include <asm/machvec.h>
729  #include <asm/uaccess.h>
730 diff -NurpP --minimal linux-3.1.6/arch/sparc/Kconfig linux-3.1.6-vs2.3.2.5/arch/sparc/Kconfig
731 --- linux-3.1.6/arch/sparc/Kconfig      2011-10-24 18:45:02.000000000 +0200
732 +++ linux-3.1.6-vs2.3.2.5/arch/sparc/Kconfig    2011-10-24 18:53:33.000000000 +0200
733 @@ -600,6 +600,8 @@ source "fs/Kconfig"
734  
735  source "arch/sparc/Kconfig.debug"
736  
737 +source "kernel/vserver/Kconfig"
738 +
739  source "security/Kconfig"
740  
741  source "crypto/Kconfig"
742 diff -NurpP --minimal linux-3.1.6/arch/sparc/include/asm/unistd.h linux-3.1.6-vs2.3.2.5/arch/sparc/include/asm/unistd.h
743 --- linux-3.1.6/arch/sparc/include/asm/unistd.h 2011-07-22 11:17:42.000000000 +0200
744 +++ linux-3.1.6-vs2.3.2.5/arch/sparc/include/asm/unistd.h       2011-10-24 18:53:33.000000000 +0200
745 @@ -335,7 +335,7 @@
746  #define __NR_timer_getoverrun  264
747  #define __NR_timer_delete      265
748  #define __NR_timer_create      266
749 -/* #define __NR_vserver                267 Reserved for VSERVER */
750 +#define __NR_vserver           267
751  #define __NR_io_setup          268
752  #define __NR_io_destroy                269
753  #define __NR_io_submit         270
754 diff -NurpP --minimal linux-3.1.6/arch/sparc/kernel/systbls_32.S linux-3.1.6-vs2.3.2.5/arch/sparc/kernel/systbls_32.S
755 --- linux-3.1.6/arch/sparc/kernel/systbls_32.S  2011-10-24 18:45:02.000000000 +0200
756 +++ linux-3.1.6-vs2.3.2.5/arch/sparc/kernel/systbls_32.S        2011-10-24 18:53:33.000000000 +0200
757 @@ -70,7 +70,7 @@ sys_call_table:
758  /*250*/        .long sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_ni_syscall
759  /*255*/        .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
760  /*260*/        .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
761 -/*265*/        .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
762 +/*265*/        .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
763  /*270*/        .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
764  /*275*/        .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
765  /*280*/        .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
766 diff -NurpP --minimal linux-3.1.6/arch/sparc/kernel/systbls_64.S linux-3.1.6-vs2.3.2.5/arch/sparc/kernel/systbls_64.S
767 --- linux-3.1.6/arch/sparc/kernel/systbls_64.S  2011-10-24 18:45:02.000000000 +0200
768 +++ linux-3.1.6-vs2.3.2.5/arch/sparc/kernel/systbls_64.S        2011-10-24 18:53:33.000000000 +0200
769 @@ -71,7 +71,7 @@ sys_call_table32:
770  /*250*/        .word sys_mremap, compat_sys_sysctl, sys32_getsid, sys_fdatasync, sys_nis_syscall
771         .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
772  /*260*/        .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
773 -       .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
774 +       .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
775  /*270*/        .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
776         .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
777  /*280*/        .word sys32_tee, sys_add_key, sys_request_key, sys_keyctl, compat_sys_openat
778 @@ -148,7 +148,7 @@ sys_call_table:
779  /*250*/        .word sys_64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nis_syscall
780         .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
781  /*260*/        .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
782 -       .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
783 +       .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
784  /*270*/        .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
785         .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
786  /*280*/        .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
787 diff -NurpP --minimal linux-3.1.6/arch/um/Kconfig.rest linux-3.1.6-vs2.3.2.5/arch/um/Kconfig.rest
788 --- linux-3.1.6/arch/um/Kconfig.rest    2009-06-11 17:12:19.000000000 +0200
789 +++ linux-3.1.6-vs2.3.2.5/arch/um/Kconfig.rest  2011-10-24 18:53:33.000000000 +0200
790 @@ -18,6 +18,8 @@ source "drivers/connector/Kconfig"
791  
792  source "fs/Kconfig"
793  
794 +source "kernel/vserver/Kconfig"
795 +
796  source "security/Kconfig"
797  
798  source "crypto/Kconfig"
799 diff -NurpP --minimal linux-3.1.6/arch/um/include/shared/kern_constants.h linux-3.1.6-vs2.3.2.5/arch/um/include/shared/kern_constants.h
800 --- linux-3.1.6/arch/um/include/shared/kern_constants.h 1970-01-01 01:00:00.000000000 +0100
801 +++ linux-3.1.6-vs2.3.2.5/arch/um/include/shared/kern_constants.h       2011-10-24 18:53:33.000000000 +0200
802 @@ -0,0 +1 @@
803 +#include "../../../../include/generated/asm-offsets.h"
804 diff -NurpP --minimal linux-3.1.6/arch/um/include/shared/user_constants.h linux-3.1.6-vs2.3.2.5/arch/um/include/shared/user_constants.h
805 --- linux-3.1.6/arch/um/include/shared/user_constants.h 1970-01-01 01:00:00.000000000 +0100
806 +++ linux-3.1.6-vs2.3.2.5/arch/um/include/shared/user_constants.h       2011-10-24 18:53:33.000000000 +0200
807 @@ -0,0 +1,40 @@
808 +/*
809 + * DO NOT MODIFY.
810 + *
811 + * This file was generated by arch/um/Makefile
812 + *
813 + */
814 +
815 +#define HOST_SC_CR2 176 /* offsetof(struct sigcontext, cr2)    # */
816 +#define HOST_SC_ERR 152 /* offsetof(struct sigcontext, err)    # */
817 +#define HOST_SC_TRAPNO 160 /* offsetof(struct sigcontext, trapno)      # */
818 +#define HOST_FP_SIZE 64 /* sizeof(struct _fpstate) / sizeof(unsigned long)     # */
819 +#define HOST_RBX 5 /* RBX      # */
820 +#define HOST_RCX 11 /* RCX     # */
821 +#define HOST_RDI 14 /* RDI     # */
822 +#define HOST_RSI 13 /* RSI     # */
823 +#define HOST_RDX 12 /* RDX     # */
824 +#define HOST_RBP 4 /* RBP      # */
825 +#define HOST_RAX 10 /* RAX     # */
826 +#define HOST_R8 9 /* R8        # */
827 +#define HOST_R9 8 /* R9        # */
828 +#define HOST_R10 7 /* R10      # */
829 +#define HOST_R11 6 /* R11      # */
830 +#define HOST_R12 3 /* R12      # */
831 +#define HOST_R13 2 /* R13      # */
832 +#define HOST_R14 1 /* R14      # */
833 +#define HOST_R15 0 /* R15      # */
834 +#define HOST_ORIG_RAX 15 /* ORIG_RAX   # */
835 +#define HOST_CS 17 /* CS       # */
836 +#define HOST_SS 20 /* SS       # */
837 +#define HOST_EFLAGS 18 /* EFLAGS       # */
838 +#define HOST_IP 16 /* RIP      # */
839 +#define HOST_SP 19 /* RSP      # */
840 +#define UM_FRAME_SIZE 216 /* sizeof(struct user_regs_struct)   # */
841 +#define UM_POLLIN 1 /* POLLIN  # */
842 +#define UM_POLLPRI 2 /* POLLPRI        # */
843 +#define UM_POLLOUT 4 /* POLLOUT        # */
844 +#define UM_PROT_READ 1 /* PROT_READ    # */
845 +#define UM_PROT_WRITE 2 /* PROT_WRITE  # */
846 +#define UM_PROT_EXEC 4 /* PROT_EXEC    # */
847 +
848 diff -NurpP --minimal linux-3.1.6/arch/x86/Kconfig linux-3.1.6-vs2.3.2.5/arch/x86/Kconfig
849 --- linux-3.1.6/arch/x86/Kconfig        2011-10-24 18:45:06.000000000 +0200
850 +++ linux-3.1.6-vs2.3.2.5/arch/x86/Kconfig      2011-10-24 18:53:33.000000000 +0200
851 @@ -2144,6 +2144,8 @@ source "fs/Kconfig"
852  
853  source "arch/x86/Kconfig.debug"
854  
855 +source "kernel/vserver/Kconfig"
856 +
857  source "security/Kconfig"
858  
859  source "crypto/Kconfig"
860 diff -NurpP --minimal linux-3.1.6/arch/x86/ia32/ia32entry.S linux-3.1.6-vs2.3.2.5/arch/x86/ia32/ia32entry.S
861 --- linux-3.1.6/arch/x86/ia32/ia32entry.S       2011-10-24 18:45:06.000000000 +0200
862 +++ linux-3.1.6-vs2.3.2.5/arch/x86/ia32/ia32entry.S     2011-10-24 18:53:33.000000000 +0200
863 @@ -776,7 +776,7 @@ ia32_sys_call_table:
864         .quad sys_tgkill                /* 270 */
865         .quad compat_sys_utimes
866         .quad sys32_fadvise64_64
867 -       .quad quiet_ni_syscall  /* sys_vserver */
868 +       .quad sys32_vserver
869         .quad sys_mbind
870         .quad compat_sys_get_mempolicy  /* 275 */
871         .quad sys_set_mempolicy
872 diff -NurpP --minimal linux-3.1.6/arch/x86/include/asm/unistd_64.h linux-3.1.6-vs2.3.2.5/arch/x86/include/asm/unistd_64.h
873 --- linux-3.1.6/arch/x86/include/asm/unistd_64.h        2011-10-24 18:45:07.000000000 +0200
874 +++ linux-3.1.6-vs2.3.2.5/arch/x86/include/asm/unistd_64.h      2011-10-24 18:53:33.000000000 +0200
875 @@ -535,7 +535,7 @@ __SYSCALL(__NR_tgkill, sys_tgkill)
876  #define __NR_utimes                            235
877  __SYSCALL(__NR_utimes, sys_utimes)
878  #define __NR_vserver                           236
879 -__SYSCALL(__NR_vserver, sys_ni_syscall)
880 +__SYSCALL(__NR_vserver, sys_vserver)
881  #define __NR_mbind                             237
882  __SYSCALL(__NR_mbind, sys_mbind)
883  #define __NR_set_mempolicy                     238
884 diff -NurpP --minimal linux-3.1.6/arch/x86/kernel/syscall_table_32.S linux-3.1.6-vs2.3.2.5/arch/x86/kernel/syscall_table_32.S
885 --- linux-3.1.6/arch/x86/kernel/syscall_table_32.S      2011-10-24 18:45:07.000000000 +0200
886 +++ linux-3.1.6-vs2.3.2.5/arch/x86/kernel/syscall_table_32.S    2011-10-24 18:53:33.000000000 +0200
887 @@ -272,7 +272,7 @@ ENTRY(sys_call_table)
888         .long sys_tgkill        /* 270 */
889         .long sys_utimes
890         .long sys_fadvise64_64
891 -       .long sys_ni_syscall    /* sys_vserver */
892 +       .long sys_vserver
893         .long sys_mbind
894         .long sys_get_mempolicy
895         .long sys_set_mempolicy
896 diff -NurpP --minimal linux-3.1.6/drivers/block/Kconfig linux-3.1.6-vs2.3.2.5/drivers/block/Kconfig
897 --- linux-3.1.6/drivers/block/Kconfig   2011-10-24 18:45:08.000000000 +0200
898 +++ linux-3.1.6-vs2.3.2.5/drivers/block/Kconfig 2011-10-24 18:53:33.000000000 +0200
899 @@ -288,6 +288,13 @@ config BLK_DEV_CRYPTOLOOP
900  
901  source "drivers/block/drbd/Kconfig"
902  
903 +config BLK_DEV_VROOT
904 +       tristate "Virtual Root device support"
905 +       depends on QUOTACTL
906 +       ---help---
907 +         Saying Y here will allow you to use quota/fs ioctls on a shared
908 +         partition within a virtual server without compromising security.
909 +
910  config BLK_DEV_NBD
911         tristate "Network block device support"
912         depends on NET
913 diff -NurpP --minimal linux-3.1.6/drivers/block/Makefile linux-3.1.6-vs2.3.2.5/drivers/block/Makefile
914 --- linux-3.1.6/drivers/block/Makefile  2011-07-22 11:17:44.000000000 +0200
915 +++ linux-3.1.6-vs2.3.2.5/drivers/block/Makefile        2011-10-24 18:53:33.000000000 +0200
916 @@ -34,6 +34,7 @@ obj-$(CONFIG_VIODASD)         += viodasd.o
917  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
918  obj-$(CONFIG_BLK_DEV_UB)       += ub.o
919  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
920 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
921  
922  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
923  obj-$(CONFIG_XEN_BLKDEV_BACKEND)       += xen-blkback/
924 diff -NurpP --minimal linux-3.1.6/drivers/block/loop.c linux-3.1.6-vs2.3.2.5/drivers/block/loop.c
925 --- linux-3.1.6/drivers/block/loop.c    2011-10-24 18:45:08.000000000 +0200
926 +++ linux-3.1.6-vs2.3.2.5/drivers/block/loop.c  2011-12-17 20:00:17.000000000 +0100
927 @@ -76,6 +76,7 @@
928  #include <linux/splice.h>
929  #include <linux/sysfs.h>
930  #include <linux/miscdevice.h>
931 +#include <linux/vs_context.h>
932  #include <asm/uaccess.h>
933  
934  static DEFINE_IDR(loop_index_idr);
935 @@ -884,6 +885,7 @@ static int loop_set_fd(struct loop_devic
936         lo->lo_blocksize = lo_blocksize;
937         lo->lo_device = bdev;
938         lo->lo_flags = lo_flags;
939 +       lo->lo_xid = vx_current_xid();
940         lo->lo_backing_file = file;
941         lo->transfer = transfer_none;
942         lo->ioctl = NULL;
943 @@ -1014,6 +1016,7 @@ static int loop_clr_fd(struct loop_devic
944         lo->lo_encrypt_key_size = 0;
945         lo->lo_flags = 0;
946         lo->lo_thread = NULL;
947 +       lo->lo_xid = 0;
948         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
949         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
950         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
951 @@ -1052,7 +1055,7 @@ loop_set_status(struct loop_device *lo, 
952  
953         if (lo->lo_encrypt_key_size &&
954             lo->lo_key_owner != uid &&
955 -           !capable(CAP_SYS_ADMIN))
956 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
957                 return -EPERM;
958         if (lo->lo_state != Lo_bound)
959                 return -ENXIO;
960 @@ -1136,7 +1139,8 @@ loop_get_status(struct loop_device *lo, 
961         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
962         info->lo_encrypt_type =
963                 lo->lo_encryption ? lo->lo_encryption->number : 0;
964 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
965 +       if (lo->lo_encrypt_key_size &&
966 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
967                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
968                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
969                        lo->lo_encrypt_key_size);
970 @@ -1490,6 +1494,11 @@ static int lo_open(struct block_device *
971                 goto out;
972         }
973  
974 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P)) {
975 +               err = -EACCES;
976 +               goto out;
977 +       }
978 +
979         mutex_lock(&lo->lo_ctl_mutex);
980         lo->lo_refcnt++;
981         mutex_unlock(&lo->lo_ctl_mutex);
982 diff -NurpP --minimal linux-3.1.6/drivers/block/vroot.c linux-3.1.6-vs2.3.2.5/drivers/block/vroot.c
983 --- linux-3.1.6/drivers/block/vroot.c   1970-01-01 01:00:00.000000000 +0100
984 +++ linux-3.1.6-vs2.3.2.5/drivers/block/vroot.c 2011-10-24 18:53:33.000000000 +0200
985 @@ -0,0 +1,292 @@
986 +/*
987 + *  linux/drivers/block/vroot.c
988 + *
989 + *  written by Herbert Pötzl, 9/11/2002
990 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
991 + *
992 + *  based on the loop.c code by Theodore Ts'o.
993 + *
994 + * Copyright (C) 2002-2007 by Herbert Pötzl.
995 + * Redistribution of this file is permitted under the
996 + * GNU General Public License.
997 + *
998 + */
999 +
1000 +#include <linux/module.h>
1001 +#include <linux/moduleparam.h>
1002 +#include <linux/file.h>
1003 +#include <linux/major.h>
1004 +#include <linux/blkdev.h>
1005 +#include <linux/slab.h>
1006 +
1007 +#include <linux/vroot.h>
1008 +#include <linux/vs_context.h>
1009 +
1010 +
1011 +static int max_vroot = 8;
1012 +
1013 +static struct vroot_device *vroot_dev;
1014 +static struct gendisk **disks;
1015 +
1016 +
1017 +static int vroot_set_dev(
1018 +       struct vroot_device *vr,
1019 +       struct block_device *bdev,
1020 +       unsigned int arg)
1021 +{
1022 +       struct block_device *real_bdev;
1023 +       struct file *file;
1024 +       struct inode *inode;
1025 +       int error;
1026 +
1027 +       error = -EBUSY;
1028 +       if (vr->vr_state != Vr_unbound)
1029 +               goto out;
1030 +
1031 +       error = -EBADF;
1032 +       file = fget(arg);
1033 +       if (!file)
1034 +               goto out;
1035 +
1036 +       error = -EINVAL;
1037 +       inode = file->f_dentry->d_inode;
1038 +
1039 +
1040 +       if (S_ISBLK(inode->i_mode)) {
1041 +               real_bdev = inode->i_bdev;
1042 +               vr->vr_device = real_bdev;
1043 +               __iget(real_bdev->bd_inode);
1044 +       } else
1045 +               goto out_fput;
1046 +
1047 +       vxdprintk(VXD_CBIT(misc, 0),
1048 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
1049 +               vr->vr_number, VXD_DEV(real_bdev));
1050 +
1051 +       vr->vr_state = Vr_bound;
1052 +       error = 0;
1053 +
1054 + out_fput:
1055 +       fput(file);
1056 + out:
1057 +       return error;
1058 +}
1059 +
1060 +static int vroot_clr_dev(
1061 +       struct vroot_device *vr,
1062 +       struct block_device *bdev)
1063 +{
1064 +       struct block_device *real_bdev;
1065 +
1066 +       if (vr->vr_state != Vr_bound)
1067 +               return -ENXIO;
1068 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
1069 +               return -EBUSY;
1070 +
1071 +       real_bdev = vr->vr_device;
1072 +
1073 +       vxdprintk(VXD_CBIT(misc, 0),
1074 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
1075 +               vr->vr_number, VXD_DEV(real_bdev));
1076 +
1077 +       bdput(real_bdev);
1078 +       vr->vr_state = Vr_unbound;
1079 +       vr->vr_device = NULL;
1080 +       return 0;
1081 +}
1082 +
1083 +
1084 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
1085 +       unsigned int cmd, unsigned long arg)
1086 +{
1087 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1088 +       int err;
1089 +
1090 +       down(&vr->vr_ctl_mutex);
1091 +       switch (cmd) {
1092 +       case VROOT_SET_DEV:
1093 +               err = vroot_set_dev(vr, bdev, arg);
1094 +               break;
1095 +       case VROOT_CLR_DEV:
1096 +               err = vroot_clr_dev(vr, bdev);
1097 +               break;
1098 +       default:
1099 +               err = -EINVAL;
1100 +               break;
1101 +       }
1102 +       up(&vr->vr_ctl_mutex);
1103 +       return err;
1104 +}
1105 +
1106 +static int vr_open(struct block_device *bdev, fmode_t mode)
1107 +{
1108 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1109 +
1110 +       down(&vr->vr_ctl_mutex);
1111 +       vr->vr_refcnt++;
1112 +       up(&vr->vr_ctl_mutex);
1113 +       return 0;
1114 +}
1115 +
1116 +static int vr_release(struct gendisk *disk, fmode_t mode)
1117 +{
1118 +       struct vroot_device *vr = disk->private_data;
1119 +
1120 +       down(&vr->vr_ctl_mutex);
1121 +       --vr->vr_refcnt;
1122 +       up(&vr->vr_ctl_mutex);
1123 +       return 0;
1124 +}
1125 +
1126 +static struct block_device_operations vr_fops = {
1127 +       .owner =        THIS_MODULE,
1128 +       .open =         vr_open,
1129 +       .release =      vr_release,
1130 +       .ioctl =        vr_ioctl,
1131 +};
1132 +
1133 +static int vroot_make_request(struct request_queue *q, struct bio *bio)
1134 +{
1135 +       printk("vroot_make_request %p, %p\n", q, bio);
1136 +       bio_io_error(bio);
1137 +       return 0;
1138 +}
1139 +
1140 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
1141 +{
1142 +       struct inode *inode = bdev->bd_inode;
1143 +       struct vroot_device *vr;
1144 +       struct block_device *real_bdev;
1145 +       int minor = iminor(inode);
1146 +
1147 +       vr = &vroot_dev[minor];
1148 +       real_bdev = vr->vr_device;
1149 +
1150 +       vxdprintk(VXD_CBIT(misc, 0),
1151 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1152 +               vr->vr_number, VXD_DEV(real_bdev));
1153 +
1154 +       if (vr->vr_state != Vr_bound)
1155 +               return ERR_PTR(-ENXIO);
1156 +
1157 +       __iget(real_bdev->bd_inode);
1158 +       return real_bdev;
1159 +}
1160 +
1161 +
1162 +
1163 +/*
1164 + * And now the modules code and kernel interface.
1165 + */
1166 +
1167 +module_param(max_vroot, int, 0);
1168 +
1169 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1170 +MODULE_LICENSE("GPL");
1171 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1172 +
1173 +MODULE_AUTHOR ("Herbert Pötzl");
1174 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1175 +
1176 +
1177 +int __init vroot_init(void)
1178 +{
1179 +       int err, i;
1180 +
1181 +       if (max_vroot < 1 || max_vroot > 256) {
1182 +               max_vroot = MAX_VROOT_DEFAULT;
1183 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1184 +                       "(must be between 1 and 256), "
1185 +                       "using default (%d)\n", max_vroot);
1186 +       }
1187 +
1188 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1189 +               return -EIO;
1190 +
1191 +       err = -ENOMEM;
1192 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1193 +       if (!vroot_dev)
1194 +               goto out_mem1;
1195 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1196 +
1197 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1198 +       if (!disks)
1199 +               goto out_mem2;
1200 +
1201 +       for (i = 0; i < max_vroot; i++) {
1202 +               disks[i] = alloc_disk(1);
1203 +               if (!disks[i])
1204 +                       goto out_mem3;
1205 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1206 +               if (!disks[i]->queue)
1207 +                       goto out_mem3;
1208 +               blk_queue_make_request(disks[i]->queue, vroot_make_request);
1209 +       }
1210 +
1211 +       for (i = 0; i < max_vroot; i++) {
1212 +               struct vroot_device *vr = &vroot_dev[i];
1213 +               struct gendisk *disk = disks[i];
1214 +
1215 +               memset(vr, 0, sizeof(*vr));
1216 +               sema_init(&vr->vr_ctl_mutex, 1);
1217 +               vr->vr_number = i;
1218 +               disk->major = VROOT_MAJOR;
1219 +               disk->first_minor = i;
1220 +               disk->fops = &vr_fops;
1221 +               sprintf(disk->disk_name, "vroot%d", i);
1222 +               disk->private_data = vr;
1223 +       }
1224 +
1225 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1226 +       if (err)
1227 +               goto out_mem3;
1228 +
1229 +       for (i = 0; i < max_vroot; i++)
1230 +               add_disk(disks[i]);
1231 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1232 +       return 0;
1233 +
1234 +out_mem3:
1235 +       while (i--)
1236 +               put_disk(disks[i]);
1237 +       kfree(disks);
1238 +out_mem2:
1239 +       kfree(vroot_dev);
1240 +out_mem1:
1241 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1242 +       printk(KERN_ERR "vroot: ran out of memory\n");
1243 +       return err;
1244 +}
1245 +
1246 +void vroot_exit(void)
1247 +{
1248 +       int i;
1249 +
1250 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1251 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1252 +
1253 +       for (i = 0; i < max_vroot; i++) {
1254 +               del_gendisk(disks[i]);
1255 +               put_disk(disks[i]);
1256 +       }
1257 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1258 +
1259 +       kfree(disks);
1260 +       kfree(vroot_dev);
1261 +}
1262 +
1263 +module_init(vroot_init);
1264 +module_exit(vroot_exit);
1265 +
1266 +#ifndef MODULE
1267 +
1268 +static int __init max_vroot_setup(char *str)
1269 +{
1270 +       max_vroot = simple_strtol(str, NULL, 0);
1271 +       return 1;
1272 +}
1273 +
1274 +__setup("max_vroot=", max_vroot_setup);
1275 +
1276 +#endif
1277 +
1278 diff -NurpP --minimal linux-3.1.6/drivers/infiniband/core/addr.c linux-3.1.6-vs2.3.2.5/drivers/infiniband/core/addr.c
1279 --- linux-3.1.6/drivers/infiniband/core/addr.c  2011-12-23 16:04:05.000000000 +0100
1280 +++ linux-3.1.6-vs2.3.2.5/drivers/infiniband/core/addr.c        2011-12-15 01:07:58.000000000 +0100
1281 @@ -254,7 +254,7 @@ static int addr6_resolve(struct sockaddr
1282  
1283         if (ipv6_addr_any(&fl6.saddr)) {
1284                 ret = ipv6_dev_get_saddr(&init_net, ip6_dst_idev(dst)->dev,
1285 -                                        &fl6.daddr, 0, &fl6.saddr);
1286 +                                        &fl6.daddr, 0, &fl6.saddr, NULL);
1287                 if (ret)
1288                         goto put;
1289  
1290 diff -NurpP --minimal linux-3.1.6/drivers/md/dm-ioctl.c linux-3.1.6-vs2.3.2.5/drivers/md/dm-ioctl.c
1291 --- linux-3.1.6/drivers/md/dm-ioctl.c   2011-10-24 18:45:10.000000000 +0200
1292 +++ linux-3.1.6-vs2.3.2.5/drivers/md/dm-ioctl.c 2011-10-24 18:53:33.000000000 +0200
1293 @@ -16,6 +16,7 @@
1294  #include <linux/dm-ioctl.h>
1295  #include <linux/hdreg.h>
1296  #include <linux/compat.h>
1297 +#include <linux/vs_context.h>
1298  
1299  #include <asm/uaccess.h>
1300  
1301 @@ -106,7 +107,8 @@ static struct hash_cell *__get_name_cell
1302         unsigned int h = hash_str(str);
1303  
1304         list_for_each_entry (hc, _name_buckets + h, name_list)
1305 -               if (!strcmp(hc->name, str)) {
1306 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1307 +                       !strcmp(hc->name, str)) {
1308                         dm_get(hc->md);
1309                         return hc;
1310                 }
1311 @@ -120,7 +122,8 @@ static struct hash_cell *__get_uuid_cell
1312         unsigned int h = hash_str(str);
1313  
1314         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1315 -               if (!strcmp(hc->uuid, str)) {
1316 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1317 +                       !strcmp(hc->uuid, str)) {
1318                         dm_get(hc->md);
1319                         return hc;
1320                 }
1321 @@ -131,13 +134,15 @@ static struct hash_cell *__get_uuid_cell
1322  static struct hash_cell *__get_dev_cell(uint64_t dev)
1323  {
1324         struct mapped_device *md;
1325 -       struct hash_cell *hc;
1326 +       struct hash_cell *hc = NULL;
1327  
1328         md = dm_get_md(huge_decode_dev(dev));
1329         if (!md)
1330                 return NULL;
1331  
1332 -       hc = dm_get_mdptr(md);
1333 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1334 +               hc = dm_get_mdptr(md);
1335 +
1336         if (!hc) {
1337                 dm_put(md);
1338                 return NULL;
1339 @@ -445,6 +450,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl 
1340  
1341  static int remove_all(struct dm_ioctl *param, size_t param_size)
1342  {
1343 +       if (!vx_check(0, VS_ADMIN))
1344 +               return -EPERM;
1345 +
1346         dm_hash_remove_all(1);
1347         param->data_size = 0;
1348         return 0;
1349 @@ -492,6 +500,8 @@ static int list_devices(struct dm_ioctl 
1350          */
1351         for (i = 0; i < NUM_BUCKETS; i++) {
1352                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1353 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1354 +                               continue;
1355                         needed += sizeof(struct dm_name_list);
1356                         needed += strlen(hc->name) + 1;
1357                         needed += ALIGN_MASK;
1358 @@ -515,6 +525,8 @@ static int list_devices(struct dm_ioctl 
1359          */
1360         for (i = 0; i < NUM_BUCKETS; i++) {
1361                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1362 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1363 +                               continue;
1364                         if (old_nl)
1365                                 old_nl->next = (uint32_t) ((void *) nl -
1366                                                            (void *) old_nl);
1367 @@ -1604,8 +1616,8 @@ static int ctl_ioctl(uint command, struc
1368         ioctl_fn fn = NULL;
1369         size_t input_param_size;
1370  
1371 -       /* only root can play with this */
1372 -       if (!capable(CAP_SYS_ADMIN))
1373 +       /* only root and certain contexts can play with this */
1374 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1375                 return -EACCES;
1376  
1377         if (_IOC_TYPE(command) != DM_IOCTL)
1378 diff -NurpP --minimal linux-3.1.6/drivers/md/dm.c linux-3.1.6-vs2.3.2.5/drivers/md/dm.c
1379 --- linux-3.1.6/drivers/md/dm.c 2011-10-24 18:45:10.000000000 +0200
1380 +++ linux-3.1.6-vs2.3.2.5/drivers/md/dm.c       2011-10-24 18:53:33.000000000 +0200
1381 @@ -20,6 +20,7 @@
1382  #include <linux/idr.h>
1383  #include <linux/hdreg.h>
1384  #include <linux/delay.h>
1385 +#include <linux/vs_base.h>
1386  
1387  #include <trace/events/block.h>
1388  
1389 @@ -122,6 +123,7 @@ struct mapped_device {
1390         rwlock_t map_lock;
1391         atomic_t holders;
1392         atomic_t open_count;
1393 +       xid_t xid;
1394  
1395         unsigned long flags;
1396  
1397 @@ -335,6 +337,7 @@ int dm_deleting_md(struct mapped_device 
1398  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1399  {
1400         struct mapped_device *md;
1401 +       int ret = -ENXIO;
1402  
1403         spin_lock(&_minor_lock);
1404  
1405 @@ -343,18 +346,19 @@ static int dm_blk_open(struct block_devi
1406                 goto out;
1407  
1408         if (test_bit(DMF_FREEING, &md->flags) ||
1409 -           dm_deleting_md(md)) {
1410 -               md = NULL;
1411 +           dm_deleting_md(md))
1412 +               goto out;
1413 +
1414 +       ret = -EACCES;
1415 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1416                 goto out;
1417 -       }
1418  
1419         dm_get(md);
1420         atomic_inc(&md->open_count);
1421 -
1422 +       ret = 0;
1423  out:
1424         spin_unlock(&_minor_lock);
1425 -
1426 -       return md ? 0 : -ENXIO;
1427 +       return ret;
1428  }
1429  
1430  static int dm_blk_close(struct gendisk *disk, fmode_t mode)
1431 @@ -575,6 +579,14 @@ int dm_set_geometry(struct mapped_device
1432         return 0;
1433  }
1434  
1435 +/*
1436 + * Get the xid associated with a dm device
1437 + */
1438 +xid_t dm_get_xid(struct mapped_device *md)
1439 +{
1440 +       return md->xid;
1441 +}
1442 +
1443  /*-----------------------------------------------------------------
1444   * CRUD START:
1445   *   A more elegant soln is in the works that uses the queue
1446 @@ -1848,6 +1860,7 @@ static struct mapped_device *alloc_dev(i
1447         INIT_LIST_HEAD(&md->uevent_list);
1448         spin_lock_init(&md->uevent_lock);
1449  
1450 +       md->xid = vx_current_xid();
1451         md->queue = blk_alloc_queue(GFP_KERNEL);
1452         if (!md->queue)
1453                 goto bad_queue;
1454 diff -NurpP --minimal linux-3.1.6/drivers/md/dm.h linux-3.1.6-vs2.3.2.5/drivers/md/dm.h
1455 --- linux-3.1.6/drivers/md/dm.h 2011-10-24 18:45:10.000000000 +0200
1456 +++ linux-3.1.6-vs2.3.2.5/drivers/md/dm.h       2011-10-24 18:53:33.000000000 +0200
1457 @@ -41,6 +41,8 @@ struct dm_dev_internal {
1458  struct dm_table;
1459  struct dm_md_mempools;
1460  
1461 +xid_t dm_get_xid(struct mapped_device *md);
1462 +
1463  /*-----------------------------------------------------------------
1464   * Internal table functions.
1465   *---------------------------------------------------------------*/
1466 diff -NurpP --minimal linux-3.1.6/drivers/net/tun.c linux-3.1.6-vs2.3.2.5/drivers/net/tun.c
1467 --- linux-3.1.6/drivers/net/tun.c       2011-10-24 18:45:17.000000000 +0200
1468 +++ linux-3.1.6-vs2.3.2.5/drivers/net/tun.c     2011-10-24 18:53:33.000000000 +0200
1469 @@ -64,6 +64,7 @@
1470  #include <linux/nsproxy.h>
1471  #include <linux/virtio_net.h>
1472  #include <linux/rcupdate.h>
1473 +#include <linux/vs_network.h>
1474  #include <net/net_namespace.h>
1475  #include <net/netns/generic.h>
1476  #include <net/rtnetlink.h>
1477 @@ -121,6 +122,7 @@ struct tun_struct {
1478         unsigned int            flags;
1479         uid_t                   owner;
1480         gid_t                   group;
1481 +       nid_t                   nid;
1482  
1483         struct net_device       *dev;
1484         u32                     set_features;
1485 @@ -909,6 +911,7 @@ static void tun_setup(struct net_device 
1486  
1487         tun->owner = -1;
1488         tun->group = -1;
1489 +       tun->nid = current->nid;
1490  
1491         dev->ethtool_ops = &tun_ethtool_ops;
1492         dev->destructor = tun_free_netdev;
1493 @@ -1059,7 +1062,7 @@ static int tun_set_iff(struct net *net, 
1494  
1495                 if (((tun->owner != -1 && cred->euid != tun->owner) ||
1496                      (tun->group != -1 && !in_egroup_p(tun->group))) &&
1497 -                   !capable(CAP_NET_ADMIN))
1498 +               !cap_raised(current_cap(), CAP_NET_ADMIN))
1499                         return -EPERM;
1500                 err = security_tun_dev_attach(tun->socket.sk);
1501                 if (err < 0)
1502 @@ -1073,7 +1076,7 @@ static int tun_set_iff(struct net *net, 
1503                 char *name;
1504                 unsigned long flags = 0;
1505  
1506 -               if (!capable(CAP_NET_ADMIN))
1507 +               if (!nx_capable(CAP_NET_ADMIN, NXC_TUN_CREATE))
1508                         return -EPERM;
1509                 err = security_tun_dev_create();
1510                 if (err < 0)
1511 @@ -1141,6 +1144,9 @@ static int tun_set_iff(struct net *net, 
1512  
1513                 sk->sk_destruct = tun_sock_destruct;
1514  
1515 +               if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
1516 +                       return -EPERM;
1517 +
1518                 err = tun_attach(tun, file);
1519                 if (err < 0)
1520                         goto failed;
1521 @@ -1322,6 +1328,16 @@ static long __tun_chr_ioctl(struct file 
1522                 tun_debug(KERN_INFO, tun, "group set to %d\n", tun->group);
1523                 break;
1524  
1525 +       case TUNSETNID:
1526 +               if (!capable(CAP_CONTEXT))
1527 +                       return -EPERM;
1528 +
1529 +               /* Set nid owner of the device */
1530 +               tun->nid = (nid_t) arg;
1531 +
1532 +               tun_debug(KERN_INFO, tun, "nid owner set to %u\n", tun->nid);
1533 +               break;
1534 +
1535         case TUNSETLINK:
1536                 /* Only allow setting the type when the interface is down */
1537                 if (tun->dev->flags & IFF_UP) {
1538 diff -NurpP --minimal linux-3.1.6/drivers/tty/sysrq.c linux-3.1.6-vs2.3.2.5/drivers/tty/sysrq.c
1539 --- linux-3.1.6/drivers/tty/sysrq.c     2011-05-22 16:17:44.000000000 +0200
1540 +++ linux-3.1.6-vs2.3.2.5/drivers/tty/sysrq.c   2011-10-24 18:53:33.000000000 +0200
1541 @@ -41,6 +41,7 @@
1542  #include <linux/oom.h>
1543  #include <linux/slab.h>
1544  #include <linux/input.h>
1545 +#include <linux/vserver/debug.h>
1546  
1547  #include <asm/ptrace.h>
1548  #include <asm/irq_regs.h>
1549 @@ -395,6 +396,21 @@ static struct sysrq_key_op sysrq_unrt_op
1550         .enable_mask    = SYSRQ_ENABLE_RTNICE,
1551  };
1552  
1553 +
1554 +#ifdef CONFIG_VSERVER_DEBUG
1555 +static void sysrq_handle_vxinfo(int key)
1556 +{
1557 +       dump_vx_info_inactive((key == 'x') ? 0 : 1);
1558 +}
1559 +
1560 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1561 +       .handler        = sysrq_handle_vxinfo,
1562 +       .help_msg       = "conteXt",
1563 +       .action_msg     = "Show Context Info",
1564 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
1565 +};
1566 +#endif
1567 +
1568  /* Key Operations table and lock */
1569  static DEFINE_SPINLOCK(sysrq_key_table_lock);
1570  
1571 @@ -449,7 +465,11 @@ static struct sysrq_key_op *sysrq_key_ta
1572         NULL,                           /* v */
1573         &sysrq_showstate_blocked_op,    /* w */
1574         /* x: May be registered on ppc/powerpc for xmon */
1575 +#ifdef CONFIG_VSERVER_DEBUG
1576 +       &sysrq_showvxinfo_op,           /* x */
1577 +#else
1578         NULL,                           /* x */
1579 +#endif
1580         /* y: May be registered on sparc64 for global register dump */
1581         NULL,                           /* y */
1582         &sysrq_ftrace_dump_op,          /* z */
1583 @@ -464,6 +484,8 @@ static int sysrq_key_table_key2index(int
1584                 retval = key - '0';
1585         else if ((key >= 'a') && (key <= 'z'))
1586                 retval = key + 10 - 'a';
1587 +       else if ((key >= 'A') && (key <= 'Z'))
1588 +               retval = key + 10 - 'A';
1589         else
1590                 retval = -1;
1591         return retval;
1592 diff -NurpP --minimal linux-3.1.6/drivers/tty/tty_io.c linux-3.1.6-vs2.3.2.5/drivers/tty/tty_io.c
1593 --- linux-3.1.6/drivers/tty/tty_io.c    2011-12-23 16:04:06.000000000 +0100
1594 +++ linux-3.1.6-vs2.3.2.5/drivers/tty/tty_io.c  2011-11-15 17:08:44.000000000 +0100
1595 @@ -105,6 +105,7 @@
1596  
1597  #include <linux/kmod.h>
1598  #include <linux/nsproxy.h>
1599 +#include <linux/vs_pid.h>
1600  
1601  #undef TTY_DEBUG_HANGUP
1602  
1603 @@ -2080,7 +2081,8 @@ static int tiocsti(struct tty_struct *tt
1604         char ch, mbz = 0;
1605         struct tty_ldisc *ld;
1606  
1607 -       if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
1608 +       if (((current->signal->tty != tty) &&
1609 +               !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
1610                 return -EPERM;
1611         if (get_user(ch, p))
1612                 return -EFAULT;
1613 @@ -2368,6 +2370,7 @@ static int tiocspgrp(struct tty_struct *
1614                 return -ENOTTY;
1615         if (get_user(pgrp_nr, p))
1616                 return -EFAULT;
1617 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
1618         if (pgrp_nr < 0)
1619                 return -EINVAL;
1620         rcu_read_lock();
1621 diff -NurpP --minimal linux-3.1.6/fs/attr.c linux-3.1.6-vs2.3.2.5/fs/attr.c
1622 --- linux-3.1.6/fs/attr.c       2011-10-24 18:45:26.000000000 +0200
1623 +++ linux-3.1.6-vs2.3.2.5/fs/attr.c     2011-10-24 18:53:33.000000000 +0200
1624 @@ -13,6 +13,9 @@
1625  #include <linux/fsnotify.h>
1626  #include <linux/fcntl.h>
1627  #include <linux/security.h>
1628 +#include <linux/proc_fs.h>
1629 +#include <linux/devpts_fs.h>
1630 +#include <linux/vs_tag.h>
1631  
1632  /**
1633   * inode_change_ok - check if attribute changes to an inode are allowed
1634 @@ -73,6 +76,10 @@ int inode_change_ok(const struct inode *
1635                         return -EPERM;
1636         }
1637  
1638 +       /* check for inode tag permission */
1639 +       if (dx_permission(inode, MAY_WRITE))
1640 +               return -EACCES;
1641 +
1642         return 0;
1643  }
1644  EXPORT_SYMBOL(inode_change_ok);
1645 @@ -143,6 +150,8 @@ void setattr_copy(struct inode *inode, c
1646                 inode->i_uid = attr->ia_uid;
1647         if (ia_valid & ATTR_GID)
1648                 inode->i_gid = attr->ia_gid;
1649 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
1650 +               inode->i_tag = attr->ia_tag;
1651         if (ia_valid & ATTR_ATIME)
1652                 inode->i_atime = timespec_trunc(attr->ia_atime,
1653                                                 inode->i_sb->s_time_gran);
1654 @@ -170,7 +179,8 @@ int notify_change(struct dentry * dentry
1655         struct timespec now;
1656         unsigned int ia_valid = attr->ia_valid;
1657  
1658 -       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
1659 +       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
1660 +               ATTR_TAG | ATTR_TIMES_SET)) {
1661                 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1662                         return -EPERM;
1663         }
1664 diff -NurpP --minimal linux-3.1.6/fs/block_dev.c linux-3.1.6-vs2.3.2.5/fs/block_dev.c
1665 --- linux-3.1.6/fs/block_dev.c  2011-12-23 16:04:06.000000000 +0100
1666 +++ linux-3.1.6-vs2.3.2.5/fs/block_dev.c        2011-11-15 17:08:44.000000000 +0100
1667 @@ -25,6 +25,7 @@
1668  #include <linux/namei.h>
1669  #include <linux/log2.h>
1670  #include <linux/kmemleak.h>
1671 +#include <linux/vs_device.h>
1672  #include <asm/uaccess.h>
1673  #include "internal.h"
1674  
1675 @@ -563,6 +564,7 @@ struct block_device *bdget(dev_t dev)
1676                 bdev->bd_invalidated = 0;
1677                 inode->i_mode = S_IFBLK;
1678                 inode->i_rdev = dev;
1679 +               inode->i_mdev = dev;
1680                 inode->i_bdev = bdev;
1681                 inode->i_data.a_ops = &def_blk_aops;
1682                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
1683 @@ -609,6 +611,11 @@ EXPORT_SYMBOL(bdput);
1684  static struct block_device *bd_acquire(struct inode *inode)
1685  {
1686         struct block_device *bdev;
1687 +       dev_t mdev;
1688 +
1689 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
1690 +               return NULL;
1691 +       inode->i_mdev = mdev;
1692  
1693         spin_lock(&bdev_lock);
1694         bdev = inode->i_bdev;
1695 @@ -619,7 +626,7 @@ static struct block_device *bd_acquire(s
1696         }
1697         spin_unlock(&bdev_lock);
1698  
1699 -       bdev = bdget(inode->i_rdev);
1700 +       bdev = bdget(mdev);
1701         if (bdev) {
1702                 spin_lock(&bdev_lock);
1703                 if (!inode->i_bdev) {
1704 diff -NurpP --minimal linux-3.1.6/fs/btrfs/ctree.h linux-3.1.6-vs2.3.2.5/fs/btrfs/ctree.h
1705 --- linux-3.1.6/fs/btrfs/ctree.h        2011-10-24 18:45:26.000000000 +0200
1706 +++ linux-3.1.6-vs2.3.2.5/fs/btrfs/ctree.h      2011-10-24 18:53:33.000000000 +0200
1707 @@ -600,11 +600,14 @@ struct btrfs_inode_item {
1708         /* modification sequence number for NFS */
1709         __le64 sequence;
1710  
1711 +       __le16 tag;
1712         /*
1713          * a little future expansion, for more than this we can
1714          * just grow the inode item and version it
1715          */
1716 -       __le64 reserved[4];
1717 +       __le16 reserved16;
1718 +       __le32 reserved32;
1719 +       __le64 reserved[3];
1720         struct btrfs_timespec atime;
1721         struct btrfs_timespec ctime;
1722         struct btrfs_timespec mtime;
1723 @@ -1364,6 +1367,8 @@ struct btrfs_ioctl_defrag_range_args {
1724  #define BTRFS_MOUNT_AUTO_DEFRAG                (1 << 16)
1725  #define BTRFS_MOUNT_INODE_MAP_CACHE    (1 << 17)
1726  
1727 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
1728 +
1729  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
1730  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
1731  #define btrfs_test_opt(root, opt)      ((root)->fs_info->mount_opt & \
1732 @@ -1571,6 +1576,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
1733  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
1734  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
1735  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
1736 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
1737  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
1738  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
1739  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
1740 @@ -1624,6 +1630,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct 
1741  
1742  BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
1743  
1744 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
1745 +#define BTRFS_INODE_BARRIER            (1 << 25)
1746 +#define BTRFS_INODE_COW                        (1 << 26)
1747 +
1748  
1749  BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
1750  
1751 @@ -2603,6 +2613,7 @@ extern const struct dentry_operations bt
1752  long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
1753  void btrfs_update_iflags(struct inode *inode);
1754  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
1755 +int btrfs_sync_flags(struct inode *inode, int, int);
1756  int btrfs_defrag_file(struct inode *inode, struct file *file,
1757                       struct btrfs_ioctl_defrag_range_args *range,
1758                       u64 newer_than, unsigned long max_pages);
1759 diff -NurpP --minimal linux-3.1.6/fs/btrfs/disk-io.c linux-3.1.6-vs2.3.2.5/fs/btrfs/disk-io.c
1760 --- linux-3.1.6/fs/btrfs/disk-io.c      2011-10-24 18:45:26.000000000 +0200
1761 +++ linux-3.1.6-vs2.3.2.5/fs/btrfs/disk-io.c    2011-10-24 18:53:33.000000000 +0200
1762 @@ -1794,6 +1794,9 @@ struct btrfs_root *open_ctree(struct sup
1763                 goto fail_alloc;
1764         }
1765  
1766 +       if (btrfs_test_opt(tree_root, TAGGED))
1767 +               sb->s_flags |= MS_TAGGED;
1768 +
1769         features = btrfs_super_incompat_flags(disk_super) &
1770                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
1771         if (features) {
1772 diff -NurpP --minimal linux-3.1.6/fs/btrfs/inode.c linux-3.1.6-vs2.3.2.5/fs/btrfs/inode.c
1773 --- linux-3.1.6/fs/btrfs/inode.c        2011-10-24 18:45:26.000000000 +0200
1774 +++ linux-3.1.6-vs2.3.2.5/fs/btrfs/inode.c      2011-10-24 18:53:33.000000000 +0200
1775 @@ -38,6 +38,7 @@
1776  #include <linux/falloc.h>
1777  #include <linux/slab.h>
1778  #include <linux/ratelimit.h>
1779 +#include <linux/vs_tag.h>
1780  #include "compat.h"
1781  #include "ctree.h"
1782  #include "disk-io.h"
1783 @@ -2508,6 +2509,8 @@ static void btrfs_read_locked_inode(stru
1784         struct btrfs_key location;
1785         int maybe_acls;
1786         u32 rdev;
1787 +       uid_t uid;
1788 +       gid_t gid;
1789         int ret;
1790         bool filled = false;
1791  
1792 @@ -2535,8 +2538,13 @@ static void btrfs_read_locked_inode(stru
1793                                     struct btrfs_inode_item);
1794         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
1795         inode->i_nlink = btrfs_inode_nlink(leaf, inode_item);
1796 -       inode->i_uid = btrfs_inode_uid(leaf, inode_item);
1797 -       inode->i_gid = btrfs_inode_gid(leaf, inode_item);
1798 +
1799 +       uid = btrfs_inode_uid(leaf, inode_item);
1800 +       gid = btrfs_inode_gid(leaf, inode_item);
1801 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
1802 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
1803 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
1804 +               btrfs_inode_tag(leaf, inode_item));
1805         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
1806  
1807         tspec = btrfs_inode_atime(inode_item);
1808 @@ -2614,8 +2622,14 @@ static void fill_inode_item(struct btrfs
1809                             struct btrfs_inode_item *item,
1810                             struct inode *inode)
1811  {
1812 -       btrfs_set_inode_uid(leaf, item, inode->i_uid);
1813 -       btrfs_set_inode_gid(leaf, item, inode->i_gid);
1814 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
1815 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
1816 +
1817 +       btrfs_set_inode_uid(leaf, item, uid);
1818 +       btrfs_set_inode_gid(leaf, item, gid);
1819 +#ifdef CONFIG_TAGGING_INTERN
1820 +       btrfs_set_inode_tag(leaf, item, inode->i_tag);
1821 +#endif
1822         btrfs_set_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size);
1823         btrfs_set_inode_mode(leaf, item, inode->i_mode);
1824         btrfs_set_inode_nlink(leaf, item, inode->i_nlink);
1825 @@ -7393,11 +7407,13 @@ static const struct inode_operations btr
1826         .listxattr      = btrfs_listxattr,
1827         .removexattr    = btrfs_removexattr,
1828         .permission     = btrfs_permission,
1829 +       .sync_flags     = btrfs_sync_flags,
1830         .get_acl        = btrfs_get_acl,
1831  };
1832  static const struct inode_operations btrfs_dir_ro_inode_operations = {
1833         .lookup         = btrfs_lookup,
1834         .permission     = btrfs_permission,
1835 +       .sync_flags     = btrfs_sync_flags,
1836         .get_acl        = btrfs_get_acl,
1837  };
1838  
1839 diff -NurpP --minimal linux-3.1.6/fs/btrfs/ioctl.c linux-3.1.6-vs2.3.2.5/fs/btrfs/ioctl.c
1840 --- linux-3.1.6/fs/btrfs/ioctl.c        2011-10-24 18:45:26.000000000 +0200
1841 +++ linux-3.1.6-vs2.3.2.5/fs/btrfs/ioctl.c      2011-10-24 18:53:33.000000000 +0200
1842 @@ -70,10 +70,13 @@ static unsigned int btrfs_flags_to_ioctl
1843  {
1844         unsigned int iflags = 0;
1845  
1846 -       if (flags & BTRFS_INODE_SYNC)
1847 -               iflags |= FS_SYNC_FL;
1848         if (flags & BTRFS_INODE_IMMUTABLE)
1849                 iflags |= FS_IMMUTABLE_FL;
1850 +       if (flags & BTRFS_INODE_IXUNLINK)
1851 +               iflags |= FS_IXUNLINK_FL;
1852 +
1853 +       if (flags & BTRFS_INODE_SYNC)
1854 +               iflags |= FS_SYNC_FL;
1855         if (flags & BTRFS_INODE_APPEND)
1856                 iflags |= FS_APPEND_FL;
1857         if (flags & BTRFS_INODE_NODUMP)
1858 @@ -90,28 +93,78 @@ static unsigned int btrfs_flags_to_ioctl
1859         else if (flags & BTRFS_INODE_NOCOMPRESS)
1860                 iflags |= FS_NOCOMP_FL;
1861  
1862 +       if (flags & BTRFS_INODE_BARRIER)
1863 +               iflags |= FS_BARRIER_FL;
1864 +       if (flags & BTRFS_INODE_COW)
1865 +               iflags |= FS_COW_FL;
1866         return iflags;
1867  }
1868  
1869  /*
1870 - * Update inode->i_flags based on the btrfs internal flags.
1871 + * Update inode->i_(v)flags based on the btrfs internal flags.
1872   */
1873  void btrfs_update_iflags(struct inode *inode)
1874  {
1875         struct btrfs_inode *ip = BTRFS_I(inode);
1876  
1877 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
1878 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
1879 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
1880  
1881 -       if (ip->flags & BTRFS_INODE_SYNC)
1882 -               inode->i_flags |= S_SYNC;
1883         if (ip->flags & BTRFS_INODE_IMMUTABLE)
1884                 inode->i_flags |= S_IMMUTABLE;
1885 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
1886 +               inode->i_flags |= S_IXUNLINK;
1887 +
1888 +       if (ip->flags & BTRFS_INODE_SYNC)
1889 +               inode->i_flags |= S_SYNC;
1890         if (ip->flags & BTRFS_INODE_APPEND)
1891                 inode->i_flags |= S_APPEND;
1892         if (ip->flags & BTRFS_INODE_NOATIME)
1893                 inode->i_flags |= S_NOATIME;
1894         if (ip->flags & BTRFS_INODE_DIRSYNC)
1895                 inode->i_flags |= S_DIRSYNC;
1896 +
1897 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
1898 +
1899 +       if (ip->flags & BTRFS_INODE_BARRIER)
1900 +               inode->i_vflags |= V_BARRIER;
1901 +       if (ip->flags & BTRFS_INODE_COW)
1902 +               inode->i_vflags |= V_COW;
1903 +}
1904 +
1905 +/*
1906 + * Update btrfs internal flags from inode->i_(v)flags.
1907 + */
1908 +void btrfs_update_flags(struct inode *inode)
1909 +{
1910 +       struct btrfs_inode *ip = BTRFS_I(inode);
1911 +
1912 +       unsigned int flags = inode->i_flags;
1913 +       unsigned int vflags = inode->i_vflags;
1914 +
1915 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
1916 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
1917 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
1918 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
1919 +
1920 +       if (flags & S_IMMUTABLE)
1921 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
1922 +       if (flags & S_IXUNLINK)
1923 +               ip->flags |= BTRFS_INODE_IXUNLINK;
1924 +
1925 +       if (flags & S_SYNC)
1926 +               ip->flags |= BTRFS_INODE_SYNC;
1927 +       if (flags & S_APPEND)
1928 +               ip->flags |= BTRFS_INODE_APPEND;
1929 +       if (flags & S_NOATIME)
1930 +               ip->flags |= BTRFS_INODE_NOATIME;
1931 +       if (flags & S_DIRSYNC)
1932 +               ip->flags |= BTRFS_INODE_DIRSYNC;
1933 +
1934 +       if (vflags & V_BARRIER)
1935 +               ip->flags |= BTRFS_INODE_BARRIER;
1936 +       if (vflags & V_COW)
1937 +               ip->flags |= BTRFS_INODE_COW;
1938  }
1939  
1940  /*
1941 @@ -129,7 +182,7 @@ void btrfs_inherit_iflags(struct inode *
1942         flags = BTRFS_I(dir)->flags;
1943  
1944         if (S_ISREG(inode->i_mode))
1945 -               flags &= ~BTRFS_INODE_DIRSYNC;
1946 +               flags &= ~(BTRFS_INODE_DIRSYNC | BTRFS_INODE_BARRIER);
1947         else if (!S_ISDIR(inode->i_mode))
1948                 flags &= (BTRFS_INODE_NODUMP | BTRFS_INODE_NOATIME);
1949  
1950 @@ -137,6 +190,30 @@ void btrfs_inherit_iflags(struct inode *
1951         btrfs_update_iflags(inode);
1952  }
1953  
1954 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
1955 +{
1956 +       struct btrfs_inode *ip = BTRFS_I(inode);
1957 +       struct btrfs_root *root = ip->root;
1958 +       struct btrfs_trans_handle *trans;
1959 +       int ret;
1960 +
1961 +       trans = btrfs_join_transaction(root);
1962 +       BUG_ON(!trans);
1963 +
1964 +       inode->i_flags = flags;
1965 +       inode->i_vflags = vflags;
1966 +       btrfs_update_flags(inode);
1967 +
1968 +       ret = btrfs_update_inode(trans, root, inode);
1969 +       BUG_ON(ret);
1970 +
1971 +       btrfs_update_iflags(inode);
1972 +       inode->i_ctime = CURRENT_TIME;
1973 +       btrfs_end_transaction(trans, root);
1974 +
1975 +       return 0;
1976 +}
1977 +
1978  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
1979  {
1980         struct btrfs_inode *ip = BTRFS_I(file->f_path.dentry->d_inode);
1981 @@ -188,7 +265,8 @@ static int btrfs_ioctl_setflags(struct f
1982  
1983         flags = btrfs_mask_flags(inode->i_mode, flags);
1984         oldflags = btrfs_flags_to_ioctl(ip->flags);
1985 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
1986 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
1987 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
1988                 if (!capable(CAP_LINUX_IMMUTABLE)) {
1989                         ret = -EPERM;
1990                         goto out_unlock;
1991 @@ -199,14 +277,19 @@ static int btrfs_ioctl_setflags(struct f
1992         if (ret)
1993                 goto out_unlock;
1994  
1995 -       if (flags & FS_SYNC_FL)
1996 -               ip->flags |= BTRFS_INODE_SYNC;
1997 -       else
1998 -               ip->flags &= ~BTRFS_INODE_SYNC;
1999         if (flags & FS_IMMUTABLE_FL)
2000                 ip->flags |= BTRFS_INODE_IMMUTABLE;
2001         else
2002                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
2003 +       if (flags & FS_IXUNLINK_FL)
2004 +               ip->flags |= BTRFS_INODE_IXUNLINK;
2005 +       else
2006 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
2007 +
2008 +       if (flags & FS_SYNC_FL)
2009 +               ip->flags |= BTRFS_INODE_SYNC;
2010 +       else
2011 +               ip->flags &= ~BTRFS_INODE_SYNC;
2012         if (flags & FS_APPEND_FL)
2013                 ip->flags |= BTRFS_INODE_APPEND;
2014         else
2015 diff -NurpP --minimal linux-3.1.6/fs/btrfs/super.c linux-3.1.6-vs2.3.2.5/fs/btrfs/super.c
2016 --- linux-3.1.6/fs/btrfs/super.c        2011-07-22 11:18:05.000000000 +0200
2017 +++ linux-3.1.6-vs2.3.2.5/fs/btrfs/super.c      2011-10-24 18:53:33.000000000 +0200
2018 @@ -162,7 +162,7 @@ enum {
2019         Opt_notreelog, Opt_ratio, Opt_flushoncommit, Opt_discard,
2020         Opt_space_cache, Opt_clear_cache, Opt_user_subvol_rm_allowed,
2021         Opt_enospc_debug, Opt_subvolrootid, Opt_defrag,
2022 -       Opt_inode_cache, Opt_err,
2023 +       Opt_inode_cache, Opt_tag, Opt_notag, Opt_tagid, Opt_err,
2024  };
2025  
2026  static match_table_t tokens = {
2027 @@ -195,6 +195,9 @@ static match_table_t tokens = {
2028         {Opt_subvolrootid, "subvolrootid=%d"},
2029         {Opt_defrag, "autodefrag"},
2030         {Opt_inode_cache, "inode_cache"},
2031 +       {Opt_tag, "tag"},
2032 +       {Opt_notag, "notag"},
2033 +       {Opt_tagid, "tagid=%u"},
2034         {Opt_err, NULL},
2035  };
2036  
2037 @@ -381,6 +384,22 @@ int btrfs_parse_options(struct btrfs_roo
2038                         printk(KERN_INFO "btrfs: enabling auto defrag");
2039                         btrfs_set_opt(info->mount_opt, AUTO_DEFRAG);
2040                         break;
2041 +#ifndef CONFIG_TAGGING_NONE
2042 +               case Opt_tag:
2043 +                       printk(KERN_INFO "btrfs: use tagging\n");
2044 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2045 +                       break;
2046 +               case Opt_notag:
2047 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
2048 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
2049 +                       break;
2050 +#endif
2051 +#ifdef CONFIG_PROPAGATE
2052 +               case Opt_tagid:
2053 +                       /* use args[0] */
2054 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2055 +                       break;
2056 +#endif
2057                 case Opt_err:
2058                         printk(KERN_INFO "btrfs: unrecognized mount option "
2059                                "'%s'\n", p);
2060 @@ -907,6 +926,12 @@ static int btrfs_remount(struct super_bl
2061         if (ret)
2062                 return -EINVAL;
2063  
2064 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
2065 +               printk("btrfs: %s: tagging not permitted on remount.\n",
2066 +                       sb->s_id);
2067 +               return -EINVAL;
2068 +       }
2069 +
2070         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
2071                 return 0;
2072  
2073 diff -NurpP --minimal linux-3.1.6/fs/char_dev.c linux-3.1.6-vs2.3.2.5/fs/char_dev.c
2074 --- linux-3.1.6/fs/char_dev.c   2011-03-15 18:07:31.000000000 +0100
2075 +++ linux-3.1.6-vs2.3.2.5/fs/char_dev.c 2011-10-24 18:53:33.000000000 +0200
2076 @@ -21,6 +21,8 @@
2077  #include <linux/mutex.h>
2078  #include <linux/backing-dev.h>
2079  #include <linux/tty.h>
2080 +#include <linux/vs_context.h>
2081 +#include <linux/vs_device.h>
2082  
2083  #include "internal.h"
2084  
2085 @@ -371,14 +373,21 @@ static int chrdev_open(struct inode *ino
2086         struct cdev *p;
2087         struct cdev *new = NULL;
2088         int ret = 0;
2089 +       dev_t mdev;
2090 +
2091 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2092 +               return -EPERM;
2093 +       inode->i_mdev = mdev;
2094  
2095         spin_lock(&cdev_lock);
2096         p = inode->i_cdev;
2097         if (!p) {
2098                 struct kobject *kobj;
2099                 int idx;
2100 +
2101                 spin_unlock(&cdev_lock);
2102 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2103 +
2104 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
2105                 if (!kobj)
2106                         return -ENXIO;
2107                 new = container_of(kobj, struct cdev, kobj);
2108 diff -NurpP --minimal linux-3.1.6/fs/dcache.c linux-3.1.6-vs2.3.2.5/fs/dcache.c
2109 --- linux-3.1.6/fs/dcache.c     2011-12-23 16:04:06.000000000 +0100
2110 +++ linux-3.1.6-vs2.3.2.5/fs/dcache.c   2011-12-23 16:11:57.000000000 +0100
2111 @@ -36,6 +36,7 @@
2112  #include <linux/bit_spinlock.h>
2113  #include <linux/rculist_bl.h>
2114  #include <linux/prefetch.h>
2115 +#include <linux/vs_limit.h>
2116  #include "internal.h"
2117  
2118  /*
2119 @@ -513,6 +514,8 @@ int d_invalidate(struct dentry * dentry)
2120                 spin_lock(&dentry->d_lock);
2121         }
2122  
2123 +       vx_dentry_dec(dentry);
2124 +
2125         /*
2126          * Somebody else still using it?
2127          *
2128 @@ -540,6 +543,7 @@ EXPORT_SYMBOL(d_invalidate);
2129  static inline void __dget_dlock(struct dentry *dentry)
2130  {
2131         dentry->d_count++;
2132 +       vx_dentry_inc(dentry);
2133  }
2134  
2135  static inline void __dget(struct dentry *dentry)
2136 @@ -1175,6 +1179,9 @@ struct dentry *__d_alloc(struct super_bl
2137         struct dentry *dentry;
2138         char *dname;
2139  
2140 +       if (!vx_dentry_avail(1))
2141 +               return NULL;
2142 +
2143         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2144         if (!dentry)
2145                 return NULL;
2146 @@ -1197,6 +1204,7 @@ struct dentry *__d_alloc(struct super_bl
2147  
2148         dentry->d_count = 1;
2149         dentry->d_flags = 0;
2150 +       vx_dentry_inc(dentry);
2151         spin_lock_init(&dentry->d_lock);
2152         seqcount_init(&dentry->d_seq);
2153         dentry->d_inode = NULL;
2154 @@ -1853,6 +1861,7 @@ struct dentry *__d_lookup(struct dentry 
2155                 }
2156  
2157                 dentry->d_count++;
2158 +               vx_dentry_inc(dentry);
2159                 found = dentry;
2160                 spin_unlock(&dentry->d_lock);
2161                 break;
2162 diff -NurpP --minimal linux-3.1.6/fs/devpts/inode.c linux-3.1.6-vs2.3.2.5/fs/devpts/inode.c
2163 --- linux-3.1.6/fs/devpts/inode.c       2011-05-22 16:17:50.000000000 +0200
2164 +++ linux-3.1.6-vs2.3.2.5/fs/devpts/inode.c     2011-10-24 18:53:33.000000000 +0200
2165 @@ -25,6 +25,7 @@
2166  #include <linux/parser.h>
2167  #include <linux/fsnotify.h>
2168  #include <linux/seq_file.h>
2169 +#include <linux/vs_base.h>
2170  
2171  #define DEVPTS_DEFAULT_MODE 0600
2172  /*
2173 @@ -36,6 +37,20 @@
2174  #define DEVPTS_DEFAULT_PTMX_MODE 0000
2175  #define PTMX_MINOR     2
2176  
2177 +static int devpts_permission(struct inode *inode, int mask)
2178 +{
2179 +       int ret = -EACCES;
2180 +
2181 +       /* devpts is xid tagged */
2182 +       if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
2183 +               ret = generic_permission(inode, mask);
2184 +       return ret;
2185 +}
2186 +
2187 +static struct inode_operations devpts_file_inode_operations = {
2188 +       .permission     = devpts_permission,
2189 +};
2190 +
2191  extern int pty_limit;                  /* Config limit on Unix98 ptys */
2192  static DEFINE_MUTEX(allocated_ptys_lock);
2193  
2194 @@ -263,6 +278,34 @@ static int devpts_show_options(struct se
2195         return 0;
2196  }
2197  
2198 +static int devpts_filter(struct dentry *de)
2199 +{
2200 +       xid_t xid = 0;
2201 +
2202 +       /* devpts is xid tagged */
2203 +       if (de && de->d_inode)
2204 +               xid = (xid_t)de->d_inode->i_tag;
2205 +#ifdef CONFIG_VSERVER_WARN_DEVPTS
2206 +       else
2207 +               vxwprintk_task(1, "devpts " VS_Q("%.*s") " without inode.",
2208 +                       de->d_name.len, de->d_name.name);
2209 +#endif
2210 +       return vx_check(xid, VS_WATCH_P | VS_IDENT);
2211 +}
2212 +
2213 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2214 +{
2215 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2216 +}
2217 +
2218 +static struct file_operations devpts_dir_operations = {
2219 +       .open           = dcache_dir_open,
2220 +       .release        = dcache_dir_close,
2221 +       .llseek         = dcache_dir_lseek,
2222 +       .read           = generic_read_dir,
2223 +       .readdir        = devpts_readdir,
2224 +};
2225 +
2226  static const struct super_operations devpts_sops = {
2227         .statfs         = simple_statfs,
2228         .remount_fs     = devpts_remount,
2229 @@ -302,12 +345,15 @@ devpts_fill_super(struct super_block *s,
2230         inode = new_inode(s);
2231         if (!inode)
2232                 goto free_fsi;
2233 +
2234         inode->i_ino = 1;
2235         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2236         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2237         inode->i_op = &simple_dir_inode_operations;
2238 -       inode->i_fop = &simple_dir_operations;
2239 +       inode->i_fop = &devpts_dir_operations;
2240         inode->i_nlink = 2;
2241 +       /* devpts is xid tagged */
2242 +       inode->i_tag = (tag_t)vx_current_xid();
2243  
2244         s->s_root = d_alloc_root(inode);
2245         if (s->s_root)
2246 @@ -494,6 +540,9 @@ int devpts_pty_new(struct inode *ptmx_in
2247         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2248         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2249         init_special_inode(inode, S_IFCHR|opts->mode, device);
2250 +       /* devpts is xid tagged */
2251 +       inode->i_tag = (tag_t)vx_current_xid();
2252 +       inode->i_op = &devpts_file_inode_operations;
2253         inode->i_private = tty;
2254         tty->driver_data = inode;
2255  
2256 diff -NurpP --minimal linux-3.1.6/fs/ext2/balloc.c linux-3.1.6-vs2.3.2.5/fs/ext2/balloc.c
2257 --- linux-3.1.6/fs/ext2/balloc.c        2011-05-22 16:17:51.000000000 +0200
2258 +++ linux-3.1.6-vs2.3.2.5/fs/ext2/balloc.c      2011-10-24 18:53:33.000000000 +0200
2259 @@ -701,7 +701,6 @@ ext2_try_to_allocate(struct super_block 
2260                         start = 0;
2261                 end = EXT2_BLOCKS_PER_GROUP(sb);
2262         }
2263 -
2264         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2265  
2266  repeat:
2267 diff -NurpP --minimal linux-3.1.6/fs/ext2/ext2.h linux-3.1.6-vs2.3.2.5/fs/ext2/ext2.h
2268 --- linux-3.1.6/fs/ext2/ext2.h  2011-10-24 18:45:27.000000000 +0200
2269 +++ linux-3.1.6-vs2.3.2.5/fs/ext2/ext2.h        2011-10-24 18:53:33.000000000 +0200
2270 @@ -126,6 +126,7 @@ extern void ext2_set_inode_flags(struct 
2271  extern void ext2_get_inode_flags(struct ext2_inode_info *);
2272  extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2273                        u64 start, u64 len);
2274 +extern int ext2_sync_flags(struct inode *, int, int);
2275  
2276  /* ioctl.c */
2277  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2278 diff -NurpP --minimal linux-3.1.6/fs/ext2/file.c linux-3.1.6-vs2.3.2.5/fs/ext2/file.c
2279 --- linux-3.1.6/fs/ext2/file.c  2011-10-24 18:45:27.000000000 +0200
2280 +++ linux-3.1.6-vs2.3.2.5/fs/ext2/file.c        2011-10-24 18:53:33.000000000 +0200
2281 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
2282         .setattr        = ext2_setattr,
2283         .get_acl        = ext2_get_acl,
2284         .fiemap         = ext2_fiemap,
2285 +       .sync_flags     = ext2_sync_flags,
2286  };
2287 diff -NurpP --minimal linux-3.1.6/fs/ext2/ialloc.c linux-3.1.6-vs2.3.2.5/fs/ext2/ialloc.c
2288 --- linux-3.1.6/fs/ext2/ialloc.c        2011-05-22 16:17:51.000000000 +0200
2289 +++ linux-3.1.6-vs2.3.2.5/fs/ext2/ialloc.c      2011-10-24 18:53:33.000000000 +0200
2290 @@ -17,6 +17,7 @@
2291  #include <linux/backing-dev.h>
2292  #include <linux/buffer_head.h>
2293  #include <linux/random.h>
2294 +#include <linux/vs_tag.h>
2295  #include "ext2.h"
2296  #include "xattr.h"
2297  #include "acl.h"
2298 @@ -549,6 +550,7 @@ got:
2299                 inode->i_mode = mode;
2300                 inode->i_uid = current_fsuid();
2301                 inode->i_gid = dir->i_gid;
2302 +               inode->i_tag = dx_current_fstag(sb);
2303         } else
2304                 inode_init_owner(inode, dir, mode);
2305  
2306 diff -NurpP --minimal linux-3.1.6/fs/ext2/inode.c linux-3.1.6-vs2.3.2.5/fs/ext2/inode.c
2307 --- linux-3.1.6/fs/ext2/inode.c 2011-10-24 18:45:27.000000000 +0200
2308 +++ linux-3.1.6-vs2.3.2.5/fs/ext2/inode.c       2011-10-24 18:53:33.000000000 +0200
2309 @@ -32,6 +32,7 @@
2310  #include <linux/mpage.h>
2311  #include <linux/fiemap.h>
2312  #include <linux/namei.h>
2313 +#include <linux/vs_tag.h>
2314  #include "ext2.h"
2315  #include "acl.h"
2316  #include "xip.h"
2317 @@ -1167,7 +1168,7 @@ static void ext2_truncate_blocks(struct 
2318                 return;
2319         if (ext2_inode_is_fast_symlink(inode))
2320                 return;
2321 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2322 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2323                 return;
2324         __ext2_truncate_blocks(inode, offset);
2325  }
2326 @@ -1258,36 +1259,61 @@ void ext2_set_inode_flags(struct inode *
2327  {
2328         unsigned int flags = EXT2_I(inode)->i_flags;
2329  
2330 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2331 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2332 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2333 +
2334 +
2335 +       if (flags & EXT2_IMMUTABLE_FL)
2336 +               inode->i_flags |= S_IMMUTABLE;
2337 +       if (flags & EXT2_IXUNLINK_FL)
2338 +               inode->i_flags |= S_IXUNLINK;
2339 +
2340         if (flags & EXT2_SYNC_FL)
2341                 inode->i_flags |= S_SYNC;
2342         if (flags & EXT2_APPEND_FL)
2343                 inode->i_flags |= S_APPEND;
2344 -       if (flags & EXT2_IMMUTABLE_FL)
2345 -               inode->i_flags |= S_IMMUTABLE;
2346         if (flags & EXT2_NOATIME_FL)
2347                 inode->i_flags |= S_NOATIME;
2348         if (flags & EXT2_DIRSYNC_FL)
2349                 inode->i_flags |= S_DIRSYNC;
2350 +
2351 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2352 +
2353 +       if (flags & EXT2_BARRIER_FL)
2354 +               inode->i_vflags |= V_BARRIER;
2355 +       if (flags & EXT2_COW_FL)
2356 +               inode->i_vflags |= V_COW;
2357  }
2358  
2359  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2360  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2361  {
2362         unsigned int flags = ei->vfs_inode.i_flags;
2363 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2364 +
2365 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2366 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2367 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2368 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2369 +
2370 +       if (flags & S_IMMUTABLE)
2371 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2372 +       if (flags & S_IXUNLINK)
2373 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2374  
2375 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2376 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2377         if (flags & S_SYNC)
2378                 ei->i_flags |= EXT2_SYNC_FL;
2379         if (flags & S_APPEND)
2380                 ei->i_flags |= EXT2_APPEND_FL;
2381 -       if (flags & S_IMMUTABLE)
2382 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2383         if (flags & S_NOATIME)
2384                 ei->i_flags |= EXT2_NOATIME_FL;
2385         if (flags & S_DIRSYNC)
2386                 ei->i_flags |= EXT2_DIRSYNC_FL;
2387 +
2388 +       if (vflags & V_BARRIER)
2389 +               ei->i_flags |= EXT2_BARRIER_FL;
2390 +       if (vflags & V_COW)
2391 +               ei->i_flags |= EXT2_COW_FL;
2392  }
2393  
2394  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2395 @@ -1297,6 +1323,8 @@ struct inode *ext2_iget (struct super_bl
2396         struct ext2_inode *raw_inode;
2397         struct inode *inode;
2398         long ret = -EIO;
2399 +       uid_t uid;
2400 +       gid_t gid;
2401         int n;
2402  
2403         inode = iget_locked(sb, ino);
2404 @@ -1315,12 +1343,17 @@ struct inode *ext2_iget (struct super_bl
2405         }
2406  
2407         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2408 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2409 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2410 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2411 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2412         if (!(test_opt (inode->i_sb, NO_UID32))) {
2413 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2414 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2415 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2416 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2417         }
2418 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2419 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2420 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2421 +               le16_to_cpu(raw_inode->i_raw_tag));
2422 +
2423         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
2424         inode->i_size = le32_to_cpu(raw_inode->i_size);
2425         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2426 @@ -1418,8 +1451,8 @@ static int __ext2_write_inode(struct ino
2427         struct ext2_inode_info *ei = EXT2_I(inode);
2428         struct super_block *sb = inode->i_sb;
2429         ino_t ino = inode->i_ino;
2430 -       uid_t uid = inode->i_uid;
2431 -       gid_t gid = inode->i_gid;
2432 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2433 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2434         struct buffer_head * bh;
2435         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2436         int n;
2437 @@ -1455,6 +1488,9 @@ static int __ext2_write_inode(struct ino
2438                 raw_inode->i_uid_high = 0;
2439                 raw_inode->i_gid_high = 0;
2440         }
2441 +#ifdef CONFIG_TAGGING_INTERN
2442 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2443 +#endif
2444         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2445         raw_inode->i_size = cpu_to_le32(inode->i_size);
2446         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2447 @@ -1535,7 +1571,8 @@ int ext2_setattr(struct dentry *dentry, 
2448         if (is_quota_modification(inode, iattr))
2449                 dquot_initialize(inode);
2450         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
2451 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
2452 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
2453 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
2454                 error = dquot_transfer(inode, iattr);
2455                 if (error)
2456                         return error;
2457 diff -NurpP --minimal linux-3.1.6/fs/ext2/ioctl.c linux-3.1.6-vs2.3.2.5/fs/ext2/ioctl.c
2458 --- linux-3.1.6/fs/ext2/ioctl.c 2011-05-22 16:17:51.000000000 +0200
2459 +++ linux-3.1.6-vs2.3.2.5/fs/ext2/ioctl.c       2011-10-24 18:53:33.000000000 +0200
2460 @@ -17,6 +17,16 @@
2461  #include <asm/uaccess.h>
2462  
2463  
2464 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2465 +{
2466 +       inode->i_flags = flags;
2467 +       inode->i_vflags = vflags;
2468 +       ext2_get_inode_flags(EXT2_I(inode));
2469 +       inode->i_ctime = CURRENT_TIME_SEC;
2470 +       mark_inode_dirty(inode);
2471 +       return 0;
2472 +}
2473 +
2474  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2475  {
2476         struct inode *inode = filp->f_dentry->d_inode;
2477 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2478  
2479                 flags = ext2_mask_flags(inode->i_mode, flags);
2480  
2481 +               if (IS_BARRIER(inode)) {
2482 +                       vxwprintk_task(1, "messing with the barrier.");
2483 +                       return -EACCES;
2484 +               }
2485 +
2486                 mutex_lock(&inode->i_mutex);
2487                 /* Is it quota file? Do not allow user to mess with it */
2488                 if (IS_NOQUOTA(inode)) {
2489 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2490                  *
2491                  * This test looks nicer. Thanks to Pauline Middelink
2492                  */
2493 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2494 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2495 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2496 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2497                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2498                                 mutex_unlock(&inode->i_mutex);
2499                                 ret = -EPERM;
2500 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2501                         }
2502                 }
2503  
2504 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
2505 +               flags &= EXT2_FL_USER_MODIFIABLE;
2506                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2507                 ei->i_flags = flags;
2508                 mutex_unlock(&inode->i_mutex);
2509 diff -NurpP --minimal linux-3.1.6/fs/ext2/namei.c linux-3.1.6-vs2.3.2.5/fs/ext2/namei.c
2510 --- linux-3.1.6/fs/ext2/namei.c 2011-10-24 18:45:27.000000000 +0200
2511 +++ linux-3.1.6-vs2.3.2.5/fs/ext2/namei.c       2011-10-24 18:53:33.000000000 +0200
2512 @@ -32,6 +32,7 @@
2513  
2514  #include <linux/pagemap.h>
2515  #include <linux/quotaops.h>
2516 +#include <linux/vs_tag.h>
2517  #include "ext2.h"
2518  #include "xattr.h"
2519  #include "acl.h"
2520 @@ -73,6 +74,7 @@ static struct dentry *ext2_lookup(struct
2521                                         (unsigned long) ino);
2522                         return ERR_PTR(-EIO);
2523                 }
2524 +               dx_propagate_tag(nd, inode);
2525         }
2526         return d_splice_alias(inode, dentry);
2527  }
2528 @@ -408,6 +410,7 @@ const struct inode_operations ext2_dir_i
2529         .removexattr    = generic_removexattr,
2530  #endif
2531         .setattr        = ext2_setattr,
2532 +       .sync_flags     = ext2_sync_flags,
2533         .get_acl        = ext2_get_acl,
2534  };
2535  
2536 diff -NurpP --minimal linux-3.1.6/fs/ext2/super.c linux-3.1.6-vs2.3.2.5/fs/ext2/super.c
2537 --- linux-3.1.6/fs/ext2/super.c 2011-07-22 11:18:05.000000000 +0200
2538 +++ linux-3.1.6-vs2.3.2.5/fs/ext2/super.c       2011-10-24 18:53:33.000000000 +0200
2539 @@ -394,7 +394,8 @@ enum {
2540         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2541         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2542         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2543 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2544 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2545 +       Opt_tag, Opt_notag, Opt_tagid
2546  };
2547  
2548  static const match_table_t tokens = {
2549 @@ -422,6 +423,9 @@ static const match_table_t tokens = {
2550         {Opt_acl, "acl"},
2551         {Opt_noacl, "noacl"},
2552         {Opt_xip, "xip"},
2553 +       {Opt_tag, "tag"},
2554 +       {Opt_notag, "notag"},
2555 +       {Opt_tagid, "tagid=%u"},
2556         {Opt_grpquota, "grpquota"},
2557         {Opt_ignore, "noquota"},
2558         {Opt_quota, "quota"},
2559 @@ -492,6 +496,20 @@ static int parse_options(char *options, 
2560                 case Opt_nouid32:
2561                         set_opt (sbi->s_mount_opt, NO_UID32);
2562                         break;
2563 +#ifndef CONFIG_TAGGING_NONE
2564 +               case Opt_tag:
2565 +                       set_opt (sbi->s_mount_opt, TAGGED);
2566 +                       break;
2567 +               case Opt_notag:
2568 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2569 +                       break;
2570 +#endif
2571 +#ifdef CONFIG_PROPAGATE
2572 +               case Opt_tagid:
2573 +                       /* use args[0] */
2574 +                       set_opt (sbi->s_mount_opt, TAGGED);
2575 +                       break;
2576 +#endif
2577                 case Opt_nocheck:
2578                         clear_opt (sbi->s_mount_opt, CHECK);
2579                         break;
2580 @@ -850,6 +868,8 @@ static int ext2_fill_super(struct super_
2581         if (!parse_options((char *) data, sb))
2582                 goto failed_mount;
2583  
2584 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2585 +               sb->s_flags |= MS_TAGGED;
2586         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2587                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2588                  MS_POSIXACL : 0);
2589 @@ -1224,6 +1244,14 @@ static int ext2_remount (struct super_bl
2590                 goto restore_opts;
2591         }
2592  
2593 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2594 +               !(sb->s_flags & MS_TAGGED)) {
2595 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2596 +                      sb->s_id);
2597 +               err = -EINVAL;
2598 +               goto restore_opts;
2599 +       }
2600 +
2601         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2602                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2603  
2604 diff -NurpP --minimal linux-3.1.6/fs/ext3/file.c linux-3.1.6-vs2.3.2.5/fs/ext3/file.c
2605 --- linux-3.1.6/fs/ext3/file.c  2011-10-24 18:45:27.000000000 +0200
2606 +++ linux-3.1.6-vs2.3.2.5/fs/ext3/file.c        2011-10-24 18:53:33.000000000 +0200
2607 @@ -80,5 +80,6 @@ const struct inode_operations ext3_file_
2608  #endif
2609         .get_acl        = ext3_get_acl,
2610         .fiemap         = ext3_fiemap,
2611 +       .sync_flags     = ext3_sync_flags,
2612  };
2613  
2614 diff -NurpP --minimal linux-3.1.6/fs/ext3/ialloc.c linux-3.1.6-vs2.3.2.5/fs/ext3/ialloc.c
2615 --- linux-3.1.6/fs/ext3/ialloc.c        2011-10-24 18:45:27.000000000 +0200
2616 +++ linux-3.1.6-vs2.3.2.5/fs/ext3/ialloc.c      2011-10-24 18:53:33.000000000 +0200
2617 @@ -23,6 +23,7 @@
2618  #include <linux/buffer_head.h>
2619  #include <linux/random.h>
2620  #include <linux/bitops.h>
2621 +#include <linux/vs_tag.h>
2622  #include <trace/events/ext3.h>
2623  
2624  #include <asm/byteorder.h>
2625 @@ -535,6 +536,7 @@ got:
2626                 inode->i_mode = mode;
2627                 inode->i_uid = current_fsuid();
2628                 inode->i_gid = dir->i_gid;
2629 +               inode->i_tag = dx_current_fstag(sb);
2630         } else
2631                 inode_init_owner(inode, dir, mode);
2632  
2633 diff -NurpP --minimal linux-3.1.6/fs/ext3/inode.c linux-3.1.6-vs2.3.2.5/fs/ext3/inode.c
2634 --- linux-3.1.6/fs/ext3/inode.c 2011-10-24 18:45:27.000000000 +0200
2635 +++ linux-3.1.6-vs2.3.2.5/fs/ext3/inode.c       2011-10-24 18:53:33.000000000 +0200
2636 @@ -38,6 +38,7 @@
2637  #include <linux/bio.h>
2638  #include <linux/fiemap.h>
2639  #include <linux/namei.h>
2640 +#include <linux/vs_tag.h>
2641  #include <trace/events/ext3.h>
2642  #include "xattr.h"
2643  #include "acl.h"
2644 @@ -2834,36 +2835,60 @@ void ext3_set_inode_flags(struct inode *
2645  {
2646         unsigned int flags = EXT3_I(inode)->i_flags;
2647  
2648 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2649 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2650 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2651 +
2652 +       if (flags & EXT3_IMMUTABLE_FL)
2653 +               inode->i_flags |= S_IMMUTABLE;
2654 +       if (flags & EXT3_IXUNLINK_FL)
2655 +               inode->i_flags |= S_IXUNLINK;
2656 +
2657         if (flags & EXT3_SYNC_FL)
2658                 inode->i_flags |= S_SYNC;
2659         if (flags & EXT3_APPEND_FL)
2660                 inode->i_flags |= S_APPEND;
2661 -       if (flags & EXT3_IMMUTABLE_FL)
2662 -               inode->i_flags |= S_IMMUTABLE;
2663         if (flags & EXT3_NOATIME_FL)
2664                 inode->i_flags |= S_NOATIME;
2665         if (flags & EXT3_DIRSYNC_FL)
2666                 inode->i_flags |= S_DIRSYNC;
2667 +
2668 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2669 +
2670 +       if (flags & EXT3_BARRIER_FL)
2671 +               inode->i_vflags |= V_BARRIER;
2672 +       if (flags & EXT3_COW_FL)
2673 +               inode->i_vflags |= V_COW;
2674  }
2675  
2676  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
2677  void ext3_get_inode_flags(struct ext3_inode_info *ei)
2678  {
2679         unsigned int flags = ei->vfs_inode.i_flags;
2680 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2681 +
2682 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
2683 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
2684 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
2685 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
2686 +
2687 +       if (flags & S_IMMUTABLE)
2688 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
2689 +       if (flags & S_IXUNLINK)
2690 +               ei->i_flags |= EXT3_IXUNLINK_FL;
2691  
2692 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
2693 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
2694         if (flags & S_SYNC)
2695                 ei->i_flags |= EXT3_SYNC_FL;
2696         if (flags & S_APPEND)
2697                 ei->i_flags |= EXT3_APPEND_FL;
2698 -       if (flags & S_IMMUTABLE)
2699 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
2700         if (flags & S_NOATIME)
2701                 ei->i_flags |= EXT3_NOATIME_FL;
2702         if (flags & S_DIRSYNC)
2703                 ei->i_flags |= EXT3_DIRSYNC_FL;
2704 +
2705 +       if (vflags & V_BARRIER)
2706 +               ei->i_flags |= EXT3_BARRIER_FL;
2707 +       if (vflags & V_COW)
2708 +               ei->i_flags |= EXT3_COW_FL;
2709  }
2710  
2711  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
2712 @@ -2877,6 +2902,8 @@ struct inode *ext3_iget(struct super_blo
2713         transaction_t *transaction;
2714         long ret;
2715         int block;
2716 +       uid_t uid;
2717 +       gid_t gid;
2718  
2719         inode = iget_locked(sb, ino);
2720         if (!inode)
2721 @@ -2893,12 +2920,17 @@ struct inode *ext3_iget(struct super_blo
2722         bh = iloc.bh;
2723         raw_inode = ext3_raw_inode(&iloc);
2724         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2725 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2726 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2727 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2728 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2729         if(!(test_opt (inode->i_sb, NO_UID32))) {
2730 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2731 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2732 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2733 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2734         }
2735 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2736 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2737 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2738 +               le16_to_cpu(raw_inode->i_raw_tag));
2739 +
2740         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
2741         inode->i_size = le32_to_cpu(raw_inode->i_size);
2742         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2743 @@ -3053,6 +3085,8 @@ static int ext3_do_update_inode(handle_t
2744         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
2745         struct ext3_inode_info *ei = EXT3_I(inode);
2746         struct buffer_head *bh = iloc->bh;
2747 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2748 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2749         int err = 0, rc, block;
2750  
2751  again:
2752 @@ -3067,29 +3101,32 @@ again:
2753         ext3_get_inode_flags(ei);
2754         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2755         if(!(test_opt(inode->i_sb, NO_UID32))) {
2756 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
2757 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
2758 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
2759 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
2760  /*
2761   * Fix up interoperability with old kernels. Otherwise, old inodes get
2762   * re-used with the upper 16 bits of the uid/gid intact
2763   */
2764                 if(!ei->i_dtime) {
2765                         raw_inode->i_uid_high =
2766 -                               cpu_to_le16(high_16_bits(inode->i_uid));
2767 +                               cpu_to_le16(high_16_bits(uid));
2768                         raw_inode->i_gid_high =
2769 -                               cpu_to_le16(high_16_bits(inode->i_gid));
2770 +                               cpu_to_le16(high_16_bits(gid));
2771                 } else {
2772                         raw_inode->i_uid_high = 0;
2773                         raw_inode->i_gid_high = 0;
2774                 }
2775         } else {
2776                 raw_inode->i_uid_low =
2777 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
2778 +                       cpu_to_le16(fs_high2lowuid(uid));
2779                 raw_inode->i_gid_low =
2780 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
2781 +                       cpu_to_le16(fs_high2lowgid(gid));
2782                 raw_inode->i_uid_high = 0;
2783                 raw_inode->i_gid_high = 0;
2784         }
2785 +#ifdef CONFIG_TAGGING_INTERN
2786 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2787 +#endif
2788         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2789         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
2790         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2791 @@ -3249,7 +3286,8 @@ int ext3_setattr(struct dentry *dentry, 
2792         if (is_quota_modification(inode, attr))
2793                 dquot_initialize(inode);
2794         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
2795 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
2796 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
2797 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
2798                 handle_t *handle;
2799  
2800                 /* (user+group)*(old+new) structure, inode write (sb,
2801 @@ -3271,6 +3309,8 @@ int ext3_setattr(struct dentry *dentry, 
2802                         inode->i_uid = attr->ia_uid;
2803                 if (attr->ia_valid & ATTR_GID)
2804                         inode->i_gid = attr->ia_gid;
2805 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2806 +                       inode->i_tag = attr->ia_tag;
2807                 error = ext3_mark_inode_dirty(handle, inode);
2808                 ext3_journal_stop(handle);
2809         }
2810 diff -NurpP --minimal linux-3.1.6/fs/ext3/ioctl.c linux-3.1.6-vs2.3.2.5/fs/ext3/ioctl.c
2811 --- linux-3.1.6/fs/ext3/ioctl.c 2011-10-24 18:45:27.000000000 +0200
2812 +++ linux-3.1.6-vs2.3.2.5/fs/ext3/ioctl.c       2011-10-24 18:53:33.000000000 +0200
2813 @@ -8,6 +8,7 @@
2814   */
2815  
2816  #include <linux/fs.h>
2817 +#include <linux/mount.h>
2818  #include <linux/jbd.h>
2819  #include <linux/capability.h>
2820  #include <linux/ext3_fs.h>
2821 @@ -17,6 +18,34 @@
2822  #include <linux/compat.h>
2823  #include <asm/uaccess.h>
2824  
2825 +
2826 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
2827 +{
2828 +       handle_t *handle = NULL;
2829 +       struct ext3_iloc iloc;
2830 +       int err;
2831 +
2832 +       handle = ext3_journal_start(inode, 1);
2833 +       if (IS_ERR(handle))
2834 +               return PTR_ERR(handle);
2835 +
2836 +       if (IS_SYNC(inode))
2837 +               handle->h_sync = 1;
2838 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
2839 +       if (err)
2840 +               goto flags_err;
2841 +
2842 +       inode->i_flags = flags;
2843 +       inode->i_vflags = vflags;
2844 +       ext3_get_inode_flags(EXT3_I(inode));
2845 +       inode->i_ctime = CURRENT_TIME_SEC;
2846 +
2847 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
2848 +flags_err:
2849 +       ext3_journal_stop(handle);
2850 +       return err;
2851 +}
2852 +
2853  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2854  {
2855         struct inode *inode = filp->f_dentry->d_inode;
2856 @@ -50,6 +79,11 @@ long ext3_ioctl(struct file *filp, unsig
2857  
2858                 flags = ext3_mask_flags(inode->i_mode, flags);
2859  
2860 +               if (IS_BARRIER(inode)) {
2861 +                       vxwprintk_task(1, "messing with the barrier.");
2862 +                       return -EACCES;
2863 +               }
2864 +
2865                 mutex_lock(&inode->i_mutex);
2866  
2867                 /* Is it quota file? Do not allow user to mess with it */
2868 @@ -68,7 +102,9 @@ long ext3_ioctl(struct file *filp, unsig
2869                  *
2870                  * This test looks nicer. Thanks to Pauline Middelink
2871                  */
2872 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
2873 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
2874 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
2875 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
2876                         if (!capable(CAP_LINUX_IMMUTABLE))
2877                                 goto flags_out;
2878                 }
2879 @@ -93,7 +129,7 @@ long ext3_ioctl(struct file *filp, unsig
2880                 if (err)
2881                         goto flags_err;
2882  
2883 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
2884 +               flags &= EXT3_FL_USER_MODIFIABLE;
2885                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
2886                 ei->i_flags = flags;
2887  
2888 diff -NurpP --minimal linux-3.1.6/fs/ext3/namei.c linux-3.1.6-vs2.3.2.5/fs/ext3/namei.c
2889 --- linux-3.1.6/fs/ext3/namei.c 2011-10-24 18:45:27.000000000 +0200
2890 +++ linux-3.1.6-vs2.3.2.5/fs/ext3/namei.c       2011-10-24 18:53:33.000000000 +0200
2891 @@ -36,6 +36,7 @@
2892  #include <linux/quotaops.h>
2893  #include <linux/buffer_head.h>
2894  #include <linux/bio.h>
2895 +#include <linux/vs_tag.h>
2896  #include <trace/events/ext3.h>
2897  
2898  #include "namei.h"
2899 @@ -925,6 +926,7 @@ restart:
2900                                         ll_rw_block(READ | REQ_META | REQ_PRIO,
2901                                                     1, &bh);
2902                         }
2903 +               dx_propagate_tag(nd, inode);
2904                 }
2905                 if ((bh = bh_use[ra_ptr++]) == NULL)
2906                         goto next;
2907 @@ -2535,6 +2537,7 @@ const struct inode_operations ext3_dir_i
2908         .listxattr      = ext3_listxattr,
2909         .removexattr    = generic_removexattr,
2910  #endif
2911 +       .sync_flags     = ext3_sync_flags,
2912         .get_acl        = ext3_get_acl,
2913  };
2914  
2915 diff -NurpP --minimal linux-3.1.6/fs/ext3/super.c linux-3.1.6-vs2.3.2.5/fs/ext3/super.c
2916 --- linux-3.1.6/fs/ext3/super.c 2011-10-24 18:45:27.000000000 +0200
2917 +++ linux-3.1.6-vs2.3.2.5/fs/ext3/super.c       2011-10-24 18:53:33.000000000 +0200
2918 @@ -833,7 +833,8 @@ enum {
2919         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
2920         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
2921         Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
2922 -       Opt_resize, Opt_usrquota, Opt_grpquota
2923 +       Opt_resize, Opt_usrquota, Opt_grpquota,
2924 +       Opt_tag, Opt_notag, Opt_tagid
2925  };
2926  
2927  static const match_table_t tokens = {
2928 @@ -890,6 +891,9 @@ static const match_table_t tokens = {
2929         {Opt_barrier, "barrier"},
2930         {Opt_nobarrier, "nobarrier"},
2931         {Opt_resize, "resize"},
2932 +       {Opt_tag, "tag"},
2933 +       {Opt_notag, "notag"},
2934 +       {Opt_tagid, "tagid=%u"},
2935         {Opt_err, NULL},
2936  };
2937  
2938 @@ -1042,6 +1046,20 @@ static int parse_options (char *options,
2939                 case Opt_nouid32:
2940                         set_opt (sbi->s_mount_opt, NO_UID32);
2941                         break;
2942 +#ifndef CONFIG_TAGGING_NONE
2943 +               case Opt_tag:
2944 +                       set_opt (sbi->s_mount_opt, TAGGED);
2945 +                       break;
2946 +               case Opt_notag:
2947 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2948 +                       break;
2949 +#endif
2950 +#ifdef CONFIG_PROPAGATE
2951 +               case Opt_tagid:
2952 +                       /* use args[0] */
2953 +                       set_opt (sbi->s_mount_opt, TAGGED);
2954 +                       break;
2955 +#endif
2956                 case Opt_nocheck:
2957                         clear_opt (sbi->s_mount_opt, CHECK);
2958                         break;
2959 @@ -1738,6 +1756,9 @@ static int ext3_fill_super (struct super
2960                             NULL, 0))
2961                 goto failed_mount;
2962  
2963 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
2964 +               sb->s_flags |= MS_TAGGED;
2965 +
2966         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2967                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2968  
2969 @@ -2619,6 +2640,14 @@ static int ext3_remount (struct super_bl
2970         if (test_opt(sb, ABORT))
2971                 ext3_abort(sb, __func__, "Abort forced by user");
2972  
2973 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
2974 +               !(sb->s_flags & MS_TAGGED)) {
2975 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
2976 +                       sb->s_id);
2977 +               err = -EINVAL;
2978 +               goto restore_opts;
2979 +       }
2980 +
2981         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2982                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2983  
2984 diff -NurpP --minimal linux-3.1.6/fs/ext4/ext4.h linux-3.1.6-vs2.3.2.5/fs/ext4/ext4.h
2985 --- linux-3.1.6/fs/ext4/ext4.h  2011-12-23 16:04:07.000000000 +0100
2986 +++ linux-3.1.6-vs2.3.2.5/fs/ext4/ext4.h        2011-11-15 17:08:44.000000000 +0100
2987 @@ -351,8 +351,12 @@ struct flex_groups {
2988  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
2989  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
2990  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
2991 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
2992  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
2993  
2994 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
2995 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
2996 +
2997  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
2998  #define EXT4_FL_USER_MODIFIABLE                0x004B80FF /* User modifiable flags */
2999  
3000 @@ -609,7 +613,8 @@ struct ext4_inode {
3001                         __le16  l_i_file_acl_high;
3002                         __le16  l_i_uid_high;   /* these 2 fields */
3003                         __le16  l_i_gid_high;   /* were reserved2[0] */
3004 -                       __u32   l_i_reserved2;
3005 +                       __le16  l_i_tag;        /* Context Tag */
3006 +                       __u16   l_i_reserved2;
3007                 } linux2;
3008                 struct {
3009                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
3010 @@ -727,6 +732,7 @@ do {                                                                               \
3011  #define i_gid_low      i_gid
3012  #define i_uid_high     osd2.linux2.l_i_uid_high
3013  #define i_gid_high     osd2.linux2.l_i_gid_high
3014 +#define i_raw_tag      osd2.linux2.l_i_tag
3015  #define i_reserved2    osd2.linux2.l_i_reserved2
3016  
3017  #elif defined(__GNU__)
3018 @@ -903,6 +909,7 @@ struct ext4_inode_info {
3019  #define EXT4_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
3020  #define EXT4_MOUNT_NO_AUTO_DA_ALLOC    0x10000 /* No auto delalloc mapping */
3021  #define EXT4_MOUNT_BARRIER             0x20000 /* Use block barriers */
3022 +#define EXT4_MOUNT_TAGGED              0x40000 /* Enable Context Tags */
3023  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
3024  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
3025  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
3026 @@ -2217,6 +2224,7 @@ extern int ext4_map_blocks(handle_t *han
3027                            struct ext4_map_blocks *map, int flags);
3028  extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
3029                         __u64 start, __u64 len);
3030 +extern int ext4_sync_flags(struct inode *, int, int);
3031  /* move_extent.c */
3032  extern int ext4_move_extents(struct file *o_filp, struct file *d_filp,
3033                              __u64 start_orig, __u64 start_donor,
3034 diff -NurpP --minimal linux-3.1.6/fs/ext4/file.c linux-3.1.6-vs2.3.2.5/fs/ext4/file.c
3035 --- linux-3.1.6/fs/ext4/file.c  2011-10-24 18:45:27.000000000 +0200
3036 +++ linux-3.1.6-vs2.3.2.5/fs/ext4/file.c        2011-10-24 18:53:33.000000000 +0200
3037 @@ -303,5 +303,6 @@ const struct inode_operations ext4_file_
3038  #endif
3039         .get_acl        = ext4_get_acl,
3040         .fiemap         = ext4_fiemap,
3041 +       .sync_flags     = ext4_sync_flags,
3042  };
3043  
3044 diff -NurpP --minimal linux-3.1.6/fs/ext4/ialloc.c linux-3.1.6-vs2.3.2.5/fs/ext4/ialloc.c
3045 --- linux-3.1.6/fs/ext4/ialloc.c        2011-10-24 18:45:27.000000000 +0200
3046 +++ linux-3.1.6-vs2.3.2.5/fs/ext4/ialloc.c      2011-10-24 18:53:33.000000000 +0200
3047 @@ -22,6 +22,7 @@
3048  #include <linux/random.h>
3049  #include <linux/bitops.h>
3050  #include <linux/blkdev.h>
3051 +#include <linux/vs_tag.h>
3052  #include <asm/byteorder.h>
3053  
3054  #include "ext4.h"
3055 @@ -992,6 +993,7 @@ got:
3056                 inode->i_mode = mode;
3057                 inode->i_uid = current_fsuid();
3058                 inode->i_gid = dir->i_gid;
3059 +               inode->i_tag = dx_current_fstag(sb);
3060         } else
3061                 inode_init_owner(inode, dir, mode);
3062  
3063 diff -NurpP --minimal linux-3.1.6/fs/ext4/inode.c linux-3.1.6-vs2.3.2.5/fs/ext4/inode.c
3064 --- linux-3.1.6/fs/ext4/inode.c 2011-12-23 16:04:07.000000000 +0100
3065 +++ linux-3.1.6-vs2.3.2.5/fs/ext4/inode.c       2011-12-23 16:11:57.000000000 +0100
3066 @@ -38,6 +38,7 @@
3067  #include <linux/printk.h>
3068  #include <linux/slab.h>
3069  #include <linux/ratelimit.h>
3070 +#include <linux/vs_tag.h>
3071  
3072  #include "ext4_jbd2.h"
3073  #include "xattr.h"
3074 @@ -3326,41 +3327,64 @@ void ext4_set_inode_flags(struct inode *
3075  {
3076         unsigned int flags = EXT4_I(inode)->i_flags;
3077  
3078 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3079 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3080 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3081 +
3082 +       if (flags & EXT4_IMMUTABLE_FL)
3083 +               inode->i_flags |= S_IMMUTABLE;
3084 +       if (flags & EXT4_IXUNLINK_FL)
3085 +               inode->i_flags |= S_IXUNLINK;
3086 +
3087         if (flags & EXT4_SYNC_FL)
3088                 inode->i_flags |= S_SYNC;
3089         if (flags & EXT4_APPEND_FL)
3090                 inode->i_flags |= S_APPEND;
3091 -       if (flags & EXT4_IMMUTABLE_FL)
3092 -               inode->i_flags |= S_IMMUTABLE;
3093         if (flags & EXT4_NOATIME_FL)
3094                 inode->i_flags |= S_NOATIME;
3095         if (flags & EXT4_DIRSYNC_FL)
3096                 inode->i_flags |= S_DIRSYNC;
3097 +
3098 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3099 +
3100 +       if (flags & EXT4_BARRIER_FL)
3101 +               inode->i_vflags |= V_BARRIER;
3102 +       if (flags & EXT4_COW_FL)
3103 +               inode->i_vflags |= V_COW;
3104  }
3105  
3106  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3107  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3108  {
3109 -       unsigned int vfs_fl;
3110 +       unsigned int vfs_fl, vfs_vf;
3111         unsigned long old_fl, new_fl;
3112  
3113         do {
3114                 vfs_fl = ei->vfs_inode.i_flags;
3115 +               vfs_vf = ei->vfs_inode.i_vflags;
3116                 old_fl = ei->i_flags;
3117                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3118                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
3119 -                               EXT4_DIRSYNC_FL);
3120 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
3121 +                               EXT4_COW_FL);
3122 +
3123 +               if (vfs_fl & S_IMMUTABLE)
3124 +                       new_fl |= EXT4_IMMUTABLE_FL;
3125 +               if (vfs_fl & S_IXUNLINK)
3126 +                       new_fl |= EXT4_IXUNLINK_FL;
3127 +
3128                 if (vfs_fl & S_SYNC)
3129                         new_fl |= EXT4_SYNC_FL;
3130                 if (vfs_fl & S_APPEND)
3131                         new_fl |= EXT4_APPEND_FL;
3132 -               if (vfs_fl & S_IMMUTABLE)
3133 -                       new_fl |= EXT4_IMMUTABLE_FL;
3134                 if (vfs_fl & S_NOATIME)
3135                         new_fl |= EXT4_NOATIME_FL;
3136                 if (vfs_fl & S_DIRSYNC)
3137                         new_fl |= EXT4_DIRSYNC_FL;
3138 +
3139 +               if (vfs_vf & V_BARRIER)
3140 +                       new_fl |= EXT4_BARRIER_FL;
3141 +               if (vfs_vf & V_COW)
3142 +                       new_fl |= EXT4_COW_FL;
3143         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3144  }
3145  
3146 @@ -3396,6 +3420,8 @@ struct inode *ext4_iget(struct super_blo
3147         journal_t *journal = EXT4_SB(sb)->s_journal;
3148         long ret;
3149         int block;
3150 +       uid_t uid;
3151 +       gid_t gid;
3152  
3153         inode = iget_locked(sb, ino);
3154         if (!inode)
3155 @@ -3411,12 +3437,16 @@ struct inode *ext4_iget(struct super_blo
3156                 goto bad_inode;
3157         raw_inode = ext4_raw_inode(&iloc);
3158         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3159 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3160 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3161 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3162 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3163         if (!(test_opt(inode->i_sb, NO_UID32))) {
3164 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3165 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3166 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3167 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3168         }
3169 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3170 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3171 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3172 +               le16_to_cpu(raw_inode->i_raw_tag));
3173         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3174  
3175         ext4_clear_state_flags(ei);     /* Only relevant on 32-bit archs */
3176 @@ -3635,6 +3665,8 @@ static int ext4_do_update_inode(handle_t
3177         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
3178         struct ext4_inode_info *ei = EXT4_I(inode);
3179         struct buffer_head *bh = iloc->bh;
3180 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3181 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3182         int err = 0, rc, block;
3183  
3184         /* For fields not not tracking in the in-memory inode,
3185 @@ -3645,29 +3677,32 @@ static int ext4_do_update_inode(handle_t
3186         ext4_get_inode_flags(ei);
3187         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3188         if (!(test_opt(inode->i_sb, NO_UID32))) {
3189 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3190 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3191 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3192 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3193  /*
3194   * Fix up interoperability with old kernels. Otherwise, old inodes get
3195   * re-used with the upper 16 bits of the uid/gid intact
3196   */
3197                 if (!ei->i_dtime) {
3198                         raw_inode->i_uid_high =
3199 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3200 +                               cpu_to_le16(high_16_bits(uid));
3201                         raw_inode->i_gid_high =
3202 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3203 +                               cpu_to_le16(high_16_bits(gid));
3204                 } else {
3205                         raw_inode->i_uid_high = 0;
3206                         raw_inode->i_gid_high = 0;
3207                 }
3208         } else {
3209                 raw_inode->i_uid_low =
3210 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3211 +                       cpu_to_le16(fs_high2lowuid(uid));
3212                 raw_inode->i_gid_low =
3213 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3214 +                       cpu_to_le16(fs_high2lowgid(gid));
3215                 raw_inode->i_uid_high = 0;
3216                 raw_inode->i_gid_high = 0;
3217         }
3218 +#ifdef CONFIG_TAGGING_INTERN
3219 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3220 +#endif
3221         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3222  
3223         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3224 @@ -3853,7 +3888,8 @@ int ext4_setattr(struct dentry *dentry, 
3225         if (is_quota_modification(inode, attr))
3226                 dquot_initialize(inode);
3227         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3228 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3229 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3230 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3231                 handle_t *handle;
3232  
3233                 /* (user+group)*(old+new) structure, inode write (sb,
3234 @@ -3875,6 +3911,8 @@ int ext4_setattr(struct dentry *dentry, 
3235                         inode->i_uid = attr->ia_uid;
3236                 if (attr->ia_valid & ATTR_GID)
3237                         inode->i_gid = attr->ia_gid;
3238 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3239 +                       inode->i_tag = attr->ia_tag;
3240                 error = ext4_mark_inode_dirty(handle, inode);
3241                 ext4_journal_stop(handle);
3242         }
3243 diff -NurpP --minimal linux-3.1.6/fs/ext4/ioctl.c linux-3.1.6-vs2.3.2.5/fs/ext4/ioctl.c
3244 --- linux-3.1.6/fs/ext4/ioctl.c 2011-10-24 18:45:27.000000000 +0200
3245 +++ linux-3.1.6-vs2.3.2.5/fs/ext4/ioctl.c       2011-10-24 18:53:33.000000000 +0200
3246 @@ -14,10 +14,39 @@
3247  #include <linux/compat.h>
3248  #include <linux/mount.h>
3249  #include <linux/file.h>
3250 +#include <linux/vs_tag.h>
3251  #include <asm/uaccess.h>
3252  #include "ext4_jbd2.h"
3253  #include "ext4.h"
3254  
3255 +
3256 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3257 +{
3258 +       handle_t *handle = NULL;
3259 +       struct ext4_iloc iloc;
3260 +       int err;
3261 +
3262 +       handle = ext4_journal_start(inode, 1);
3263 +       if (IS_ERR(handle))
3264 +               return PTR_ERR(handle);
3265 +
3266 +       if (IS_SYNC(inode))
3267 +               ext4_handle_sync(handle);
3268 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3269 +       if (err)
3270 +               goto flags_err;
3271 +
3272 +       inode->i_flags = flags;
3273 +       inode->i_vflags = vflags;
3274 +       ext4_get_inode_flags(EXT4_I(inode));
3275 +       inode->i_ctime = ext4_current_time(inode);
3276 +
3277 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3278 +flags_err:
3279 +       ext4_journal_stop(handle);
3280 +       return err;
3281 +}
3282 +
3283  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3284  {
3285         struct inode *inode = filp->f_dentry->d_inode;
3286 @@ -50,6 +79,11 @@ long ext4_ioctl(struct file *filp, unsig
3287  
3288                 flags = ext4_mask_flags(inode->i_mode, flags);
3289  
3290 +               if (IS_BARRIER(inode)) {
3291 +                       vxwprintk_task(1, "messing with the barrier.");
3292 +                       return -EACCES;
3293 +               }
3294 +
3295                 err = -EPERM;
3296                 mutex_lock(&inode->i_mutex);
3297                 /* Is it quota file? Do not allow user to mess with it */
3298 @@ -67,7 +101,9 @@ long ext4_ioctl(struct file *filp, unsig
3299                  *
3300                  * This test looks nicer. Thanks to Pauline Middelink
3301                  */
3302 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3303 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3304 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3305 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3306                         if (!capable(CAP_LINUX_IMMUTABLE))
3307                                 goto flags_out;
3308                 }
3309 diff -NurpP --minimal linux-3.1.6/fs/ext4/namei.c linux-3.1.6-vs2.3.2.5/fs/ext4/namei.c
3310 --- linux-3.1.6/fs/ext4/namei.c 2011-12-23 16:04:07.000000000 +0100
3311 +++ linux-3.1.6-vs2.3.2.5/fs/ext4/namei.c       2011-11-15 17:08:44.000000000 +0100
3312 @@ -34,6 +34,7 @@
3313  #include <linux/quotaops.h>
3314  #include <linux/buffer_head.h>
3315  #include <linux/bio.h>
3316 +#include <linux/vs_tag.h>
3317  #include "ext4.h"
3318  #include "ext4_jbd2.h"
3319  
3320 @@ -925,6 +926,7 @@ restart:
3321                                         ll_rw_block(READ | REQ_META | REQ_PRIO,
3322                                                     1, &bh);
3323                         }
3324 +               dx_propagate_tag(nd, inode);
3325                 }
3326                 if ((bh = bh_use[ra_ptr++]) == NULL)
3327                         goto next;
3328 @@ -2588,6 +2590,7 @@ const struct inode_operations ext4_dir_i
3329  #endif
3330         .get_acl        = ext4_get_acl,
3331         .fiemap         = ext4_fiemap,
3332 +       .sync_flags     = ext4_sync_flags,
3333  };
3334  
3335  const struct inode_operations ext4_special_inode_operations = {
3336 diff -NurpP --minimal linux-3.1.6/fs/ext4/super.c linux-3.1.6-vs2.3.2.5/fs/ext4/super.c
3337 --- linux-3.1.6/fs/ext4/super.c 2011-12-23 16:04:07.000000000 +0100
3338 +++ linux-3.1.6-vs2.3.2.5/fs/ext4/super.c       2011-12-23 16:13:10.000000000 +0100
3339 @@ -1319,6 +1319,7 @@ enum {
3340         Opt_inode_readahead_blks, Opt_journal_ioprio,
3341         Opt_dioread_nolock, Opt_dioread_lock,
3342         Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
3343 +       Opt_tag, Opt_notag, Opt_tagid
3344  };
3345  
3346  static const match_table_t tokens = {
3347 @@ -1394,6 +1395,9 @@ static const match_table_t tokens = {
3348         {Opt_init_itable, "init_itable=%u"},
3349         {Opt_init_itable, "init_itable"},
3350         {Opt_noinit_itable, "noinit_itable"},
3351 +       {Opt_tag, "tag"},
3352 +       {Opt_notag, "notag"},
3353 +       {Opt_tagid, "tagid=%u"},
3354         {Opt_err, NULL},
3355  };
3356  
3357 @@ -1562,6 +1566,20 @@ static int parse_options(char *options, 
3358                 case Opt_nouid32:
3359                         set_opt(sb, NO_UID32);
3360                         break;
3361 +#ifndef CONFIG_TAGGING_NONE
3362 +               case Opt_tag:
3363 +                       set_opt(sb, TAGGED);
3364 +                       break;
3365 +               case Opt_notag:
3366 +                       clear_opt(sb, TAGGED);
3367 +                       break;
3368 +#endif
3369 +#ifdef CONFIG_PROPAGATE
3370 +               case Opt_tagid:
3371 +                       /* use args[0] */
3372 +                       set_opt(sb, TAGGED);
3373 +                       break;
3374 +#endif
3375                 case Opt_debug:
3376                         set_opt(sb, DEBUG);
3377                         break;
3378 @@ -3223,6 +3241,9 @@ static int ext4_fill_super(struct super_
3379                            &journal_ioprio, NULL, 0))
3380                 goto failed_mount;
3381  
3382 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3383 +               sb->s_flags |= MS_TAGGED;
3384 +
3385         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3386                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3387  
3388 @@ -4350,6 +4371,14 @@ static int ext4_remount(struct super_blo
3389         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3390                 ext4_abort(sb, "Abort forced by user");
3391  
3392 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3393 +               !(sb->s_flags & MS_TAGGED)) {
3394 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3395 +                       sb->s_id);
3396 +               err = -EINVAL;
3397 +               goto restore_opts;
3398 +       }
3399 +
3400         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3401                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3402  
3403 diff -NurpP --minimal linux-3.1.6/fs/fcntl.c linux-3.1.6-vs2.3.2.5/fs/fcntl.c
3404 --- linux-3.1.6/fs/fcntl.c      2011-05-22 16:17:52.000000000 +0200
3405 +++ linux-3.1.6-vs2.3.2.5/fs/fcntl.c    2011-10-24 18:53:33.000000000 +0200
3406 @@ -20,6 +20,7 @@
3407  #include <linux/signal.h>
3408  #include <linux/rcupdate.h>
3409  #include <linux/pid_namespace.h>
3410 +#include <linux/vs_limit.h>
3411  
3412  #include <asm/poll.h>
3413  #include <asm/siginfo.h>
3414 @@ -103,6 +104,8 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldf
3415  
3416         if (tofree)
3417                 filp_close(tofree, files);
3418 +       else
3419 +               vx_openfd_inc(newfd);   /* fd was unused */
3420  
3421         return newfd;
3422  
3423 @@ -447,6 +450,8 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd,
3424         filp = fget_raw(fd);
3425         if (!filp)
3426                 goto out;
3427 +       if (!vx_files_avail(1))
3428 +               goto out;
3429  
3430         if (unlikely(filp->f_mode & FMODE_PATH)) {
3431                 if (!check_fcntl_cmd(cmd)) {
3432 diff -NurpP --minimal linux-3.1.6/fs/file.c linux-3.1.6-vs2.3.2.5/fs/file.c
3433 --- linux-3.1.6/fs/file.c       2011-05-22 16:17:52.000000000 +0200
3434 +++ linux-3.1.6-vs2.3.2.5/fs/file.c     2011-10-24 18:53:33.000000000 +0200
3435 @@ -21,6 +21,7 @@
3436  #include <linux/spinlock.h>
3437  #include <linux/rcupdate.h>
3438  #include <linux/workqueue.h>
3439 +#include <linux/vs_limit.h>
3440  
3441  struct fdtable_defer {
3442         spinlock_t lock;
3443 @@ -359,6 +360,8 @@ struct files_struct *dup_fd(struct files
3444                 struct file *f = *old_fds++;
3445                 if (f) {
3446                         get_file(f);
3447 +                       /* TODO: sum it first for check and performance */
3448 +                       vx_openfd_inc(open_files - i);
3449                 } else {
3450                         /*
3451                          * The fd may be claimed in the fd bitmap but not yet
3452 @@ -466,6 +469,7 @@ repeat:
3453         else
3454                 FD_CLR(fd, fdt->close_on_exec);
3455         error = fd;
3456 +       vx_openfd_inc(fd);
3457  #if 1
3458         /* Sanity check */
3459         if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
3460 diff -NurpP --minimal linux-3.1.6/fs/file_table.c linux-3.1.6-vs2.3.2.5/fs/file_table.c
3461 --- linux-3.1.6/fs/file_table.c 2011-10-24 18:45:27.000000000 +0200
3462 +++ linux-3.1.6-vs2.3.2.5/fs/file_table.c       2011-10-24 18:53:33.000000000 +0200
3463 @@ -24,6 +24,8 @@
3464  #include <linux/percpu_counter.h>
3465  #include <linux/percpu.h>
3466  #include <linux/ima.h>
3467 +#include <linux/vs_limit.h>
3468 +#include <linux/vs_context.h>
3469  
3470  #include <linux/atomic.h>
3471  
3472 @@ -135,6 +137,8 @@ struct file *get_empty_filp(void)
3473         spin_lock_init(&f->f_lock);
3474         eventpoll_init_file(f);
3475         /* f->f_version: 0 */
3476 +       f->f_xid = vx_current_xid();
3477 +       vx_files_inc(f);
3478         return f;
3479  
3480  over:
3481 @@ -253,6 +257,8 @@ static void __fput(struct file *file)
3482         }
3483         fops_put(file->f_op);
3484         put_pid(file->f_owner.pid);
3485 +       vx_files_dec(file);
3486 +       file->f_xid = 0;
3487         file_sb_list_del(file);
3488         if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
3489                 i_readcount_dec(inode);
3490 @@ -383,6 +389,8 @@ void put_filp(struct file *file)
3491  {
3492         if (atomic_long_dec_and_test(&file->f_count)) {
3493                 security_file_free(file);
3494 +               vx_files_dec(file);
3495 +               file->f_xid = 0;
3496                 file_sb_list_del(file);
3497                 file_free(file);
3498         }
3499 diff -NurpP --minimal linux-3.1.6/fs/fs_struct.c linux-3.1.6-vs2.3.2.5/fs/fs_struct.c
3500 --- linux-3.1.6/fs/fs_struct.c  2011-03-15 18:07:31.000000000 +0100
3501 +++ linux-3.1.6-vs2.3.2.5/fs/fs_struct.c        2011-10-24 18:53:33.000000000 +0200
3502 @@ -4,6 +4,7 @@
3503  #include <linux/path.h>
3504  #include <linux/slab.h>
3505  #include <linux/fs_struct.h>
3506 +#include <linux/vserver/global.h>
3507  #include "internal.h"
3508  
3509  static inline void path_get_longterm(struct path *path)
3510 @@ -96,6 +97,7 @@ void free_fs_struct(struct fs_struct *fs
3511  {
3512         path_put_longterm(&fs->root);
3513         path_put_longterm(&fs->pwd);
3514 +       atomic_dec(&vs_global_fs);
3515         kmem_cache_free(fs_cachep, fs);
3516  }
3517  
3518 @@ -135,6 +137,7 @@ struct fs_struct *copy_fs_struct(struct 
3519                 fs->pwd = old->pwd;
3520                 path_get_longterm(&fs->pwd);
3521                 spin_unlock(&old->lock);
3522 +               atomic_inc(&vs_global_fs);
3523         }
3524         return fs;
3525  }
3526 diff -NurpP --minimal linux-3.1.6/fs/gfs2/file.c linux-3.1.6-vs2.3.2.5/fs/gfs2/file.c
3527 --- linux-3.1.6/fs/gfs2/file.c  2011-10-24 18:45:27.000000000 +0200
3528 +++ linux-3.1.6-vs2.3.2.5/fs/gfs2/file.c        2011-10-24 18:53:33.000000000 +0200
3529 @@ -134,6 +134,9 @@ static const u32 fsflags_to_gfs2[32] = {
3530         [7] = GFS2_DIF_NOATIME,
3531         [12] = GFS2_DIF_EXHASH,
3532         [14] = GFS2_DIF_INHERIT_JDATA,
3533 +       [27] = GFS2_DIF_IXUNLINK,
3534 +       [26] = GFS2_DIF_BARRIER,
3535 +       [29] = GFS2_DIF_COW,
3536  };
3537  
3538  static const u32 gfs2_to_fsflags[32] = {
3539 @@ -143,6 +146,9 @@ static const u32 gfs2_to_fsflags[32] = {
3540         [gfs2fl_NoAtime] = FS_NOATIME_FL,
3541         [gfs2fl_ExHash] = FS_INDEX_FL,
3542         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3543 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3544 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
3545 +       [gfs2fl_Cow] = FS_COW_FL,
3546  };
3547  
3548  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3549 @@ -173,12 +179,18 @@ void gfs2_set_inode_flags(struct inode *
3550  {
3551         struct gfs2_inode *ip = GFS2_I(inode);
3552         unsigned int flags = inode->i_flags;
3553 +       unsigned int vflags = inode->i_vflags;
3554 +
3555 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3556 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC | S_NOSEC);
3557  
3558 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_NOSEC);
3559         if ((ip->i_eattr == 0) && !is_sxid(inode->i_mode))
3560                 inode->i_flags |= S_NOSEC;
3561         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3562                 flags |= S_IMMUTABLE;
3563 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3564 +               flags |= S_IXUNLINK;
3565 +
3566         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3567                 flags |= S_APPEND;
3568         if (ip->i_diskflags & GFS2_DIF_NOATIME)
3569 @@ -186,6 +198,43 @@ void gfs2_set_inode_flags(struct inode *
3570         if (ip->i_diskflags & GFS2_DIF_SYNC)
3571                 flags |= S_SYNC;
3572         inode->i_flags = flags;
3573 +
3574 +       vflags &= ~(V_BARRIER | V_COW);
3575 +
3576 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
3577 +               vflags |= V_BARRIER;
3578 +       if (ip->i_diskflags & GFS2_DIF_COW)
3579 +               vflags |= V_COW;
3580 +       inode->i_vflags = vflags;
3581 +}
3582 +
3583 +void gfs2_get_inode_flags(struct inode *inode)
3584 +{
3585 +       struct gfs2_inode *ip = GFS2_I(inode);
3586 +       unsigned int flags = inode->i_flags;
3587 +       unsigned int vflags = inode->i_vflags;
3588 +
3589 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
3590 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
3591 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
3592 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
3593 +
3594 +       if (flags & S_IMMUTABLE)
3595 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
3596 +       if (flags & S_IXUNLINK)
3597 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
3598 +
3599 +       if (flags & S_APPEND)
3600 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
3601 +       if (flags & S_NOATIME)
3602 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
3603 +       if (flags & S_SYNC)
3604 +               ip->i_diskflags |= GFS2_DIF_SYNC;
3605 +
3606 +       if (vflags & V_BARRIER)
3607 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
3608 +       if (vflags & V_COW)
3609 +               ip->i_diskflags |= GFS2_DIF_COW;
3610  }
3611  
3612  /* Flags that can be set by user space */
3613 @@ -297,6 +346,37 @@ static int gfs2_set_flags(struct file *f
3614         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
3615  }
3616  
3617 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
3618 +{
3619 +       struct gfs2_inode *ip = GFS2_I(inode);
3620 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
3621 +       struct buffer_head *bh;
3622 +       struct gfs2_holder gh;
3623 +       int error;
3624 +
3625 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
3626 +       if (error)
3627 +               return error;
3628 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
3629 +       if (error)
3630 +               goto out;
3631 +       error = gfs2_meta_inode_buffer(ip, &bh);
3632 +       if (error)
3633 +               goto out_trans_end;
3634 +       gfs2_trans_add_bh(ip->i_gl, bh, 1);
3635 +       inode->i_flags = flags;
3636 +       inode->i_vflags = vflags;
3637 +       gfs2_get_inode_flags(inode);
3638 +       gfs2_dinode_out(ip, bh->b_data);
3639 +       brelse(bh);
3640 +       gfs2_set_aops(inode);
3641 +out_trans_end:
3642 +       gfs2_trans_end(sdp);
3643 +out:
3644 +       gfs2_glock_dq_uninit(&gh);
3645 +       return error;
3646 +}
3647 +
3648  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3649  {
3650         switch(cmd) {
3651 diff -NurpP --minimal linux-3.1.6/fs/gfs2/inode.h linux-3.1.6-vs2.3.2.5/fs/gfs2/inode.h
3652 --- linux-3.1.6/fs/gfs2/inode.h 2011-10-24 18:45:27.000000000 +0200
3653 +++ linux-3.1.6-vs2.3.2.5/fs/gfs2/inode.h       2011-10-24 18:53:33.000000000 +0200
3654 @@ -120,6 +120,7 @@ extern const struct file_operations gfs2
3655  extern const struct file_operations gfs2_dir_fops_nolock;
3656  
3657  extern void gfs2_set_inode_flags(struct inode *inode);
3658 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
3659   
3660  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
3661  extern const struct file_operations gfs2_file_fops;
3662 diff -NurpP --minimal linux-3.1.6/fs/inode.c linux-3.1.6-vs2.3.2.5/fs/inode.c
3663 --- linux-3.1.6/fs/inode.c      2011-10-24 18:45:27.000000000 +0200
3664 +++ linux-3.1.6-vs2.3.2.5/fs/inode.c    2011-10-24 18:53:33.000000000 +0200
3665 @@ -26,6 +26,7 @@
3666  #include <linux/ima.h>
3667  #include <linux/cred.h>
3668  #include <linux/buffer_head.h> /* for inode_has_buffers */
3669 +#include <linux/vs_tag.h>
3670  #include "internal.h"
3671  
3672  /*
3673 @@ -137,6 +138,9 @@ int inode_init_always(struct super_block
3674         struct address_space *const mapping = &inode->i_data;
3675  
3676         inode->i_sb = sb;
3677 +
3678 +       /* essential because of inode slab reuse */
3679 +       inode->i_tag = 0;
3680         inode->i_blkbits = sb->s_blocksize_bits;
3681         inode->i_flags = 0;
3682         atomic_set(&inode->i_count, 1);
3683 @@ -158,6 +162,7 @@ int inode_init_always(struct super_block
3684         inode->i_bdev = NULL;
3685         inode->i_cdev = NULL;
3686         inode->i_rdev = 0;
3687 +       inode->i_mdev = 0;
3688         inode->dirtied_when = 0;
3689  
3690         if (security_inode_alloc(inode))
3691 @@ -399,6 +404,8 @@ void __insert_inode_hash(struct inode *i
3692  }
3693  EXPORT_SYMBOL(__insert_inode_hash);
3694  
3695 +EXPORT_SYMBOL_GPL(__iget);
3696 +
3697  /**
3698   *     __remove_inode_hash - remove an inode from the hash
3699   *     @inode: inode to unhash
3700 @@ -1626,9 +1633,11 @@ void init_special_inode(struct inode *in
3701         if (S_ISCHR(mode)) {
3702                 inode->i_fop = &def_chr_fops;
3703                 inode->i_rdev = rdev;
3704 +               inode->i_mdev = rdev;
3705         } else if (S_ISBLK(mode)) {
3706                 inode->i_fop = &def_blk_fops;
3707                 inode->i_rdev = rdev;
3708 +               inode->i_mdev = rdev;
3709         } else if (S_ISFIFO(mode))
3710                 inode->i_fop = &def_fifo_fops;
3711         else if (S_ISSOCK(mode))
3712 @@ -1657,6 +1666,7 @@ void inode_init_owner(struct inode *inod
3713         } else
3714                 inode->i_gid = current_fsgid();
3715         inode->i_mode = mode;
3716 +       inode->i_tag = dx_current_fstag(inode->i_sb);
3717  }
3718  EXPORT_SYMBOL(inode_init_owner);
3719  
3720 diff -NurpP --minimal linux-3.1.6/fs/ioctl.c linux-3.1.6-vs2.3.2.5/fs/ioctl.c
3721 --- linux-3.1.6/fs/ioctl.c      2011-05-22 16:17:52.000000000 +0200
3722 +++ linux-3.1.6-vs2.3.2.5/fs/ioctl.c    2011-10-24 18:53:33.000000000 +0200
3723 @@ -15,6 +15,9 @@
3724  #include <linux/writeback.h>
3725  #include <linux/buffer_head.h>
3726  #include <linux/falloc.h>
3727 +#include <linux/proc_fs.h>
3728 +#include <linux/vserver/inode.h>
3729 +#include <linux/vs_tag.h>
3730  
3731  #include <asm/ioctls.h>
3732  
3733 diff -NurpP --minimal linux-3.1.6/fs/ioprio.c linux-3.1.6-vs2.3.2.5/fs/ioprio.c
3734 --- linux-3.1.6/fs/ioprio.c     2011-01-05 21:50:24.000000000 +0100
3735 +++ linux-3.1.6-vs2.3.2.5/fs/ioprio.c   2011-10-24 18:53:33.000000000 +0200
3736 @@ -27,6 +27,7 @@
3737  #include <linux/syscalls.h>
3738  #include <linux/security.h>
3739  #include <linux/pid_namespace.h>
3740 +#include <linux/vs_base.h>
3741  
3742  int set_task_ioprio(struct task_struct *task, int ioprio)
3743  {
3744 @@ -119,6 +120,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which, 
3745                         else
3746                                 pgrp = find_vpid(who);
3747                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3748 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3749 +                                       continue;
3750                                 ret = set_task_ioprio(p, ioprio);
3751                                 if (ret)
3752                                         break;
3753 @@ -208,6 +211,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which, 
3754                         else
3755                                 pgrp = find_vpid(who);
3756                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3757 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3758 +                                       continue;
3759                                 tmpio = get_task_ioprio(p);
3760                                 if (tmpio < 0)
3761                                         continue;
3762 diff -NurpP --minimal linux-3.1.6/fs/jfs/file.c linux-3.1.6-vs2.3.2.5/fs/jfs/file.c
3763 --- linux-3.1.6/fs/jfs/file.c   2011-10-24 18:45:27.000000000 +0200
3764 +++ linux-3.1.6-vs2.3.2.5/fs/jfs/file.c 2011-10-24 18:53:33.000000000 +0200
3765 @@ -109,7 +109,8 @@ int jfs_setattr(struct dentry *dentry, s
3766         if (is_quota_modification(inode, iattr))
3767                 dquot_initialize(inode);
3768         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
3769 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
3770 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
3771 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
3772                 rc = dquot_transfer(inode, iattr);
3773                 if (rc)
3774                         return rc;
3775 @@ -142,6 +143,7 @@ const struct inode_operations jfs_file_i
3776  #ifdef CONFIG_JFS_POSIX_ACL
3777         .get_acl        = jfs_get_acl,
3778  #endif
3779 +       .sync_flags     = jfs_sync_flags,
3780  };
3781  
3782  const struct file_operations jfs_file_operations = {
3783 diff -NurpP --minimal linux-3.1.6/fs/jfs/ioctl.c linux-3.1.6-vs2.3.2.5/fs/jfs/ioctl.c
3784 --- linux-3.1.6/fs/jfs/ioctl.c  2011-05-22 16:17:52.000000000 +0200
3785 +++ linux-3.1.6-vs2.3.2.5/fs/jfs/ioctl.c        2011-10-24 18:53:33.000000000 +0200
3786 @@ -11,6 +11,7 @@
3787  #include <linux/mount.h>
3788  #include <linux/time.h>
3789  #include <linux/sched.h>
3790 +#include <linux/mount.h>
3791  #include <asm/current.h>
3792  #include <asm/uaccess.h>
3793  
3794 @@ -52,6 +53,16 @@ static long jfs_map_ext2(unsigned long f
3795  }
3796  
3797  
3798 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
3799 +{
3800 +       inode->i_flags = flags;
3801 +       inode->i_vflags = vflags;
3802 +       jfs_get_inode_flags(JFS_IP(inode));
3803 +       inode->i_ctime = CURRENT_TIME_SEC;
3804 +       mark_inode_dirty(inode);
3805 +       return 0;
3806 +}
3807 +
3808  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3809  {
3810         struct inode *inode = filp->f_dentry->d_inode;
3811 @@ -85,6 +96,11 @@ long jfs_ioctl(struct file *filp, unsign
3812                 if (!S_ISDIR(inode->i_mode))
3813                         flags &= ~JFS_DIRSYNC_FL;
3814  
3815 +               if (IS_BARRIER(inode)) {
3816 +                       vxwprintk_task(1, "messing with the barrier.");
3817 +                       return -EACCES;
3818 +               }
3819 +
3820                 /* Is it quota file? Do not allow user to mess with it */
3821                 if (IS_NOQUOTA(inode)) {
3822                         err = -EPERM;
3823 @@ -102,8 +118,8 @@ long jfs_ioctl(struct file *filp, unsign
3824                  * the relevant capability.
3825                  */
3826                 if ((oldflags & JFS_IMMUTABLE_FL) ||
3827 -                       ((flags ^ oldflags) &
3828 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3829 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
3830 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3831                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3832                                 mutex_unlock(&inode->i_mutex);
3833                                 err = -EPERM;
3834 @@ -111,7 +127,7 @@ long jfs_ioctl(struct file *filp, unsign
3835                         }
3836                 }
3837  
3838 -               flags = flags & JFS_FL_USER_MODIFIABLE;
3839 +               flags &= JFS_FL_USER_MODIFIABLE;
3840                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
3841                 jfs_inode->mode2 = flags;
3842  
3843 diff -NurpP --minimal linux-3.1.6/fs/jfs/jfs_dinode.h linux-3.1.6-vs2.3.2.5/fs/jfs/jfs_dinode.h
3844 --- linux-3.1.6/fs/jfs/jfs_dinode.h     2008-12-25 00:26:37.000000000 +0100
3845 +++ linux-3.1.6-vs2.3.2.5/fs/jfs/jfs_dinode.h   2011-10-24 18:53:33.000000000 +0200
3846 @@ -161,9 +161,13 @@ struct dinode {
3847  
3848  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
3849  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
3850 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
3851  
3852 -#define JFS_FL_USER_VISIBLE    0x03F80000
3853 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
3854 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
3855 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
3856 +
3857 +#define JFS_FL_USER_VISIBLE    0x07F80000
3858 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
3859  #define JFS_FL_INHERIT         0x03C80000
3860  
3861  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3862 diff -NurpP --minimal linux-3.1.6/fs/jfs/jfs_filsys.h linux-3.1.6-vs2.3.2.5/fs/jfs/jfs_filsys.h
3863 --- linux-3.1.6/fs/jfs/jfs_filsys.h     2008-12-25 00:26:37.000000000 +0100
3864 +++ linux-3.1.6-vs2.3.2.5/fs/jfs/jfs_filsys.h   2011-10-24 18:53:33.000000000 +0200
3865 @@ -263,6 +263,7 @@
3866  #define JFS_NAME_MAX   255
3867  #define JFS_PATH_MAX   BPSIZE
3868  
3869 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
3870  
3871  /*
3872   *     file system state (superblock state)
3873 diff -NurpP --minimal linux-3.1.6/fs/jfs/jfs_imap.c linux-3.1.6-vs2.3.2.5/fs/jfs/jfs_imap.c
3874 --- linux-3.1.6/fs/jfs/jfs_imap.c       2011-07-22 11:18:05.000000000 +0200
3875 +++ linux-3.1.6-vs2.3.2.5/fs/jfs/jfs_imap.c     2011-10-24 18:53:33.000000000 +0200
3876 @@ -46,6 +46,7 @@
3877  #include <linux/pagemap.h>
3878  #include <linux/quotaops.h>
3879  #include <linux/slab.h>
3880 +#include <linux/vs_tag.h>
3881  
3882  #include "jfs_incore.h"
3883  #include "jfs_inode.h"
3884 @@ -3058,6 +3059,8 @@ static int copy_from_dinode(struct dinod
3885  {
3886         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3887         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
3888 +       uid_t uid;
3889 +       gid_t gid;
3890  
3891         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
3892         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
3893 @@ -3078,14 +3081,18 @@ static int copy_from_dinode(struct dinod
3894         }
3895         ip->i_nlink = le32_to_cpu(dip->di_nlink);
3896  
3897 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
3898 +       uid = le32_to_cpu(dip->di_uid);
3899 +       gid = le32_to_cpu(dip->di_gid);
3900 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
3901 +
3902 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
3903         if (sbi->uid == -1)
3904                 ip->i_uid = jfs_ip->saved_uid;
3905         else {
3906                 ip->i_uid = sbi->uid;
3907         }
3908  
3909 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
3910 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
3911         if (sbi->gid == -1)
3912                 ip->i_gid = jfs_ip->saved_gid;
3913         else {
3914 @@ -3150,14 +3157,12 @@ static void copy_to_dinode(struct dinode
3915         dip->di_size = cpu_to_le64(ip->i_size);
3916         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
3917         dip->di_nlink = cpu_to_le32(ip->i_nlink);
3918 -       if (sbi->uid == -1)
3919 -               dip->di_uid = cpu_to_le32(ip->i_uid);
3920 -       else
3921 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
3922 -       if (sbi->gid == -1)
3923 -               dip->di_gid = cpu_to_le32(ip->i_gid);
3924 -       else
3925 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
3926 +
3927 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
3928 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
3929 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
3930 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
3931 +
3932         jfs_get_inode_flags(jfs_ip);
3933         /*
3934          * mode2 is only needed for storing the higher order bits.
3935 diff -NurpP --minimal linux-3.1.6/fs/jfs/jfs_inode.c linux-3.1.6-vs2.3.2.5/fs/jfs/jfs_inode.c
3936 --- linux-3.1.6/fs/jfs/jfs_inode.c      2010-08-02 16:52:49.000000000 +0200
3937 +++ linux-3.1.6-vs2.3.2.5/fs/jfs/jfs_inode.c    2011-10-24 18:53:33.000000000 +0200
3938 @@ -18,6 +18,7 @@
3939  
3940  #include <linux/fs.h>
3941  #include <linux/quotaops.h>
3942 +#include <linux/vs_tag.h>
3943  #include "jfs_incore.h"
3944  #include "jfs_inode.h"
3945  #include "jfs_filsys.h"
3946 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
3947  {
3948         unsigned int flags = JFS_IP(inode)->mode2;
3949  
3950 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
3951 -               S_NOATIME | S_DIRSYNC | S_SYNC);
3952 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3953 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3954  
3955         if (flags & JFS_IMMUTABLE_FL)
3956                 inode->i_flags |= S_IMMUTABLE;
3957 +       if (flags & JFS_IXUNLINK_FL)
3958 +               inode->i_flags |= S_IXUNLINK;
3959 +
3960 +       if (flags & JFS_SYNC_FL)
3961 +               inode->i_flags |= S_SYNC;
3962         if (flags & JFS_APPEND_FL)
3963                 inode->i_flags |= S_APPEND;
3964         if (flags & JFS_NOATIME_FL)
3965                 inode->i_flags |= S_NOATIME;
3966         if (flags & JFS_DIRSYNC_FL)
3967                 inode->i_flags |= S_DIRSYNC;
3968 -       if (flags & JFS_SYNC_FL)
3969 -               inode->i_flags |= S_SYNC;
3970 +
3971 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3972 +
3973 +       if (flags & JFS_BARRIER_FL)
3974 +               inode->i_vflags |= V_BARRIER;
3975 +       if (flags & JFS_COW_FL)
3976 +               inode->i_vflags |= V_COW;
3977  }
3978  
3979  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
3980  {
3981         unsigned int flags = jfs_ip->vfs_inode.i_flags;
3982 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
3983 +
3984 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
3985 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
3986 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
3987 +                          JFS_BARRIER_FL | JFS_COW_FL);
3988  
3989 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
3990 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
3991         if (flags & S_IMMUTABLE)
3992                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
3993 +       if (flags & S_IXUNLINK)
3994 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
3995 +
3996         if (flags & S_APPEND)
3997                 jfs_ip->mode2 |= JFS_APPEND_FL;
3998         if (flags & S_NOATIME)
3999 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
4000                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
4001         if (flags & S_SYNC)
4002                 jfs_ip->mode2 |= JFS_SYNC_FL;
4003 +
4004 +       if (vflags & V_BARRIER)
4005 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
4006 +       if (vflags & V_COW)
4007 +               jfs_ip->mode2 |= JFS_COW_FL;
4008  }
4009  
4010  /*
4011 diff -NurpP --minimal linux-3.1.6/fs/jfs/jfs_inode.h linux-3.1.6-vs2.3.2.5/fs/jfs/jfs_inode.h
4012 --- linux-3.1.6/fs/jfs/jfs_inode.h      2011-10-24 18:45:27.000000000 +0200
4013 +++ linux-3.1.6-vs2.3.2.5/fs/jfs/jfs_inode.h    2011-10-24 18:53:33.000000000 +0200
4014 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
4015  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
4016         int fh_len, int fh_type);
4017  extern void jfs_set_inode_flags(struct inode *);
4018 +extern int jfs_sync_flags(struct inode *, int, int);
4019  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
4020  extern int jfs_setattr(struct dentry *, struct iattr *);
4021  
4022 diff -NurpP --minimal linux-3.1.6/fs/jfs/namei.c linux-3.1.6-vs2.3.2.5/fs/jfs/namei.c
4023 --- linux-3.1.6/fs/jfs/namei.c  2011-10-24 18:45:27.000000000 +0200
4024 +++ linux-3.1.6-vs2.3.2.5/fs/jfs/namei.c        2011-10-24 18:53:33.000000000 +0200
4025 @@ -22,6 +22,7 @@
4026  #include <linux/ctype.h>
4027  #include <linux/quotaops.h>
4028  #include <linux/exportfs.h>
4029 +#include <linux/vs_tag.h>
4030  #include "jfs_incore.h"
4031  #include "jfs_superblock.h"
4032  #include "jfs_inode.h"
4033 @@ -1474,6 +1475,7 @@ static struct dentry *jfs_lookup(struct 
4034                         jfs_err("jfs_lookup: iget failed on inum %d", (uint)inum);
4035         }
4036  
4037 +       dx_propagate_tag(nd, ip);
4038         return d_splice_alias(ip, dentry);
4039  }
4040  
4041 @@ -1538,6 +1540,7 @@ const struct inode_operations jfs_dir_in
4042  #ifdef CONFIG_JFS_POSIX_ACL
4043         .get_acl        = jfs_get_acl,
4044  #endif
4045 +       .sync_flags     = jfs_sync_flags,
4046  };
4047  
4048  const struct file_operations jfs_dir_operations = {
4049 diff -NurpP --minimal linux-3.1.6/fs/jfs/super.c linux-3.1.6-vs2.3.2.5/fs/jfs/super.c
4050 --- linux-3.1.6/fs/jfs/super.c  2011-05-22 16:17:53.000000000 +0200
4051 +++ linux-3.1.6-vs2.3.2.5/fs/jfs/super.c        2011-10-24 18:53:33.000000000 +0200
4052 @@ -198,7 +198,8 @@ static void jfs_put_super(struct super_b
4053  enum {
4054         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4055         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4056 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
4057 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4058 +       Opt_tag, Opt_notag, Opt_tagid
4059  };
4060  
4061  static const match_table_t tokens = {
4062 @@ -208,6 +209,10 @@ static const match_table_t tokens = {
4063         {Opt_resize, "resize=%u"},
4064         {Opt_resize_nosize, "resize"},
4065         {Opt_errors, "errors=%s"},
4066 +       {Opt_tag, "tag"},
4067 +       {Opt_notag, "notag"},
4068 +       {Opt_tagid, "tagid=%u"},
4069 +       {Opt_tag, "tagxid"},
4070         {Opt_ignore, "noquota"},
4071         {Opt_ignore, "quota"},
4072         {Opt_usrquota, "usrquota"},
4073 @@ -342,6 +347,20 @@ static int parse_options(char *options, 
4074                         }
4075                         break;
4076                 }
4077 +#ifndef CONFIG_TAGGING_NONE
4078 +               case Opt_tag:
4079 +                       *flag |= JFS_TAGGED;
4080 +                       break;
4081 +               case Opt_notag:
4082 +                       *flag &= JFS_TAGGED;
4083 +                       break;
4084 +#endif
4085 +#ifdef CONFIG_PROPAGATE
4086 +               case Opt_tagid:
4087 +                       /* use args[0] */
4088 +                       *flag |= JFS_TAGGED;
4089 +                       break;
4090 +#endif
4091                 default:
4092                         printk("jfs: Unrecognized mount option \"%s\" "
4093                                         " or missing value\n", p);
4094 @@ -373,6 +392,12 @@ static int jfs_remount(struct super_bloc
4095                 return -EINVAL;
4096         }
4097  
4098 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4099 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4100 +                       sb->s_id);
4101 +               return -EINVAL;
4102 +       }
4103 +
4104         if (newLVSize) {
4105                 if (sb->s_flags & MS_RDONLY) {
4106                         printk(KERN_ERR
4107 @@ -455,6 +480,9 @@ static int jfs_fill_super(struct super_b
4108  #ifdef CONFIG_JFS_POSIX_ACL
4109         sb->s_flags |= MS_POSIXACL;
4110  #endif
4111 +       /* map mount option tagxid */
4112 +       if (sbi->flag & JFS_TAGGED)
4113 +               sb->s_flags |= MS_TAGGED;
4114  
4115         if (newLVSize) {
4116                 printk(KERN_ERR "resize option for remount only\n");
4117 diff -NurpP --minimal linux-3.1.6/fs/libfs.c linux-3.1.6-vs2.3.2.5/fs/libfs.c
4118 --- linux-3.1.6/fs/libfs.c      2011-10-24 18:45:27.000000000 +0200
4119 +++ linux-3.1.6-vs2.3.2.5/fs/libfs.c    2011-10-24 18:53:33.000000000 +0200
4120 @@ -135,7 +135,8 @@ static inline unsigned char dt_type(stru
4121   * both impossible due to the lock on directory.
4122   */
4123  
4124 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4125 +static inline int do_dcache_readdir_filter(struct file *filp,
4126 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4127  {
4128         struct dentry *dentry = filp->f_path.dentry;
4129         struct dentry *cursor = filp->private_data;
4130 @@ -166,6 +167,8 @@ int dcache_readdir(struct file * filp, v
4131                         for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
4132                                 struct dentry *next;
4133                                 next = list_entry(p, struct dentry, d_u.d_child);
4134 +                               if (filter && !filter(next))
4135 +                                       continue;
4136                                 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
4137                                 if (!simple_positive(next)) {
4138                                         spin_unlock(&next->d_lock);
4139 @@ -192,6 +195,17 @@ int dcache_readdir(struct file * filp, v
4140         return 0;
4141  }
4142  
4143 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4144 +{
4145 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4146 +}
4147 +
4148 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4149 +       int (*filter)(struct dentry *))
4150 +{
4151 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4152 +}
4153 +
4154  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4155  {
4156         return -EISDIR;
4157 @@ -975,6 +989,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4158  EXPORT_SYMBOL(dcache_dir_lseek);
4159  EXPORT_SYMBOL(dcache_dir_open);
4160  EXPORT_SYMBOL(dcache_readdir);
4161 +EXPORT_SYMBOL(dcache_readdir_filter);
4162  EXPORT_SYMBOL(generic_read_dir);
4163  EXPORT_SYMBOL(mount_pseudo);
4164  EXPORT_SYMBOL(simple_write_begin);
4165 diff -NurpP --minimal linux-3.1.6/fs/locks.c linux-3.1.6-vs2.3.2.5/fs/locks.c
4166 --- linux-3.1.6/fs/locks.c      2011-10-24 18:45:27.000000000 +0200
4167 +++ linux-3.1.6-vs2.3.2.5/fs/locks.c    2011-10-24 18:53:33.000000000 +0200
4168 @@ -126,6 +126,8 @@
4169  #include <linux/time.h>
4170  #include <linux/rcupdate.h>
4171  #include <linux/pid_namespace.h>
4172 +#include <linux/vs_base.h>
4173 +#include <linux/vs_limit.h>
4174  
4175  #include <asm/uaccess.h>
4176  
4177 @@ -170,11 +172,17 @@ static void locks_init_lock_heads(struct
4178  /* Allocate an empty lock structure. */
4179  struct file_lock *locks_alloc_lock(void)
4180  {
4181 -       struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4182 +       struct file_lock *fl;
4183  
4184 -       if (fl)
4185 -               locks_init_lock_heads(fl);
4186 +       if (!vx_locks_avail(1))
4187 +               return NULL;
4188  
4189 +       fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4190 +
4191 +       if (fl) {
4192 +               locks_init_lock_heads(fl);
4193 +               fl->fl_xid = -1;
4194 +       }
4195         return fl;
4196  }
4197  EXPORT_SYMBOL_GPL(locks_alloc_lock);
4198 @@ -202,6 +210,7 @@ void locks_free_lock(struct file_lock *f
4199         BUG_ON(!list_empty(&fl->fl_block));
4200         BUG_ON(!list_empty(&fl->fl_link));
4201  
4202 +       vx_locks_dec(fl);
4203         locks_release_private(fl);
4204         kmem_cache_free(filelock_cache, fl);
4205  }
4206 @@ -211,6 +220,7 @@ void locks_init_lock(struct file_lock *f
4207  {
4208         memset(fl, 0, sizeof(struct file_lock));
4209         locks_init_lock_heads(fl);
4210 +       fl->fl_xid = -1;
4211  }
4212  
4213  EXPORT_SYMBOL(locks_init_lock);
4214 @@ -251,6 +261,7 @@ void locks_copy_lock(struct file_lock *n
4215         new->fl_file = fl->fl_file;
4216         new->fl_ops = fl->fl_ops;
4217         new->fl_lmops = fl->fl_lmops;
4218 +       new->fl_xid = fl->fl_xid;
4219  
4220         locks_copy_private(new, fl);
4221  }
4222 @@ -289,6 +300,11 @@ static int flock_make_lock(struct file *
4223         fl->fl_flags = FL_FLOCK;
4224         fl->fl_type = type;
4225         fl->fl_end = OFFSET_MAX;
4226 +
4227 +       vxd_assert(filp->f_xid == vx_current_xid(),
4228 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4229 +       fl->fl_xid = filp->f_xid;
4230 +       vx_locks_inc(fl);
4231         
4232         *lock = fl;
4233         return 0;
4234 @@ -438,6 +454,7 @@ static int lease_init(struct file *filp,
4235  
4236         fl->fl_owner = current->files;
4237         fl->fl_pid = current->tgid;
4238 +       fl->fl_xid = vx_current_xid();
4239  
4240         fl->fl_file = filp;
4241         fl->fl_flags = FL_LEASE;
4242 @@ -457,6 +474,11 @@ static struct file_lock *lease_alloc(str
4243         if (fl == NULL)
4244                 return ERR_PTR(error);
4245  
4246 +       fl->fl_xid = vx_current_xid();
4247 +       if (filp)
4248 +               vxd_assert(filp->f_xid == fl->fl_xid,
4249 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4250 +       vx_locks_inc(fl);
4251         error = lease_init(filp, type, fl);
4252         if (error) {
4253                 locks_free_lock(fl);
4254 @@ -758,6 +780,7 @@ static int flock_lock_file(struct file *
4255                 lock_flocks();
4256         }
4257  
4258 +       new_fl->fl_xid = -1;
4259  find_conflict:
4260         for_each_lock(inode, before) {
4261                 struct file_lock *fl = *before;
4262 @@ -778,6 +801,7 @@ find_conflict:
4263                 goto out;
4264         locks_copy_lock(new_fl, request);
4265         locks_insert_lock(before, new_fl);
4266 +       vx_locks_inc(new_fl);
4267         new_fl = NULL;
4268         error = 0;
4269  
4270 @@ -788,7 +812,8 @@ out:
4271         return error;
4272  }
4273  
4274 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4275 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4276 +       struct file_lock *conflock, xid_t xid)
4277  {
4278         struct file_lock *fl;
4279         struct file_lock *new_fl = NULL;
4280 @@ -798,6 +823,8 @@ static int __posix_lock_file(struct inod
4281         struct file_lock **before;
4282         int error, added = 0;
4283  
4284 +       vxd_assert(xid == vx_current_xid(),
4285 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4286         /*
4287          * We may need two file_lock structures for this operation,
4288          * so we get them in advance to avoid races.
4289 @@ -808,7 +835,11 @@ static int __posix_lock_file(struct inod
4290             (request->fl_type != F_UNLCK ||
4291              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4292                 new_fl = locks_alloc_lock();
4293 +               new_fl->fl_xid = xid;
4294 +               vx_locks_inc(new_fl);
4295                 new_fl2 = locks_alloc_lock();
4296 +               new_fl2->fl_xid = xid;
4297 +               vx_locks_inc(new_fl2);
4298         }
4299  
4300         lock_flocks();
4301 @@ -1007,7 +1038,8 @@ static int __posix_lock_file(struct inod
4302  int posix_lock_file(struct file *filp, struct file_lock *fl,
4303                         struct file_lock *conflock)
4304  {
4305 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
4306 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
4307 +               fl, conflock, filp->f_xid);
4308  }
4309  EXPORT_SYMBOL(posix_lock_file);
4310  
4311 @@ -1097,7 +1129,7 @@ int locks_mandatory_area(int read_write,
4312         fl.fl_end = offset + count - 1;
4313  
4314         for (;;) {
4315 -               error = __posix_lock_file(inode, &fl, NULL);
4316 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4317                 if (error != FILE_LOCK_DEFERRED)
4318                         break;
4319                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4320 @@ -1410,6 +1442,7 @@ int generic_setlease(struct file *filp, 
4321                 goto out;
4322  
4323         locks_insert_lock(before, lease);
4324 +       vx_locks_inc(lease);
4325         return 0;
4326  
4327  out:
4328 @@ -1794,6 +1827,11 @@ int fcntl_setlk(unsigned int fd, struct 
4329         if (file_lock == NULL)
4330                 return -ENOLCK;
4331  
4332 +       vxd_assert(filp->f_xid == vx_current_xid(),
4333 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4334 +       file_lock->fl_xid = filp->f_xid;
4335 +       vx_locks_inc(file_lock);
4336 +
4337         /*
4338          * This might block, so we do it before checking the inode.
4339          */
4340 @@ -1912,6 +1950,11 @@ int fcntl_setlk64(unsigned int fd, struc
4341         if (file_lock == NULL)
4342                 return -ENOLCK;
4343  
4344 +       vxd_assert(filp->f_xid == vx_current_xid(),
4345 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4346 +       file_lock->fl_xid = filp->f_xid;
4347 +       vx_locks_inc(file_lock);
4348 +
4349         /*
4350          * This might block, so we do it before checking the inode.
4351          */
4352 @@ -2177,8 +2220,11 @@ static int locks_show(struct seq_file *f
4353  
4354         lock_get_status(f, fl, *((loff_t *)f->private), "");
4355  
4356 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4357 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4358 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4359 +                       continue;
4360                 lock_get_status(f, bfl, *((loff_t *)f->private), " ->");
4361 +       }
4362  
4363         return 0;
4364  }
4365 diff -NurpP --minimal linux-3.1.6/fs/namei.c linux-3.1.6-vs2.3.2.5/fs/namei.c
4366 --- linux-3.1.6/fs/namei.c      2011-12-23 16:04:07.000000000 +0100
4367 +++ linux-3.1.6-vs2.3.2.5/fs/namei.c    2011-11-16 14:28:54.000000000 +0100
4368 @@ -33,6 +33,14 @@
4369  #include <linux/device_cgroup.h>
4370  #include <linux/fs_struct.h>
4371  #include <linux/posix_acl.h>
4372 +#include <linux/proc_fs.h>
4373 +#include <linux/vserver/inode.h>
4374 +#include <linux/vs_base.h>
4375 +#include <linux/vs_tag.h>
4376 +#include <linux/vs_cowbl.h>
4377 +#include <linux/vs_device.h>
4378 +#include <linux/vs_context.h>
4379 +#include <linux/pid_namespace.h>
4380  #include <asm/uaccess.h>
4381  
4382  #include "internal.h"
4383 @@ -222,6 +230,89 @@ static int check_acl(struct inode *inode
4384         return -EAGAIN;
4385  }
4386  
4387 +static inline int dx_barrier(const struct inode *inode)
4388 +{
4389 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4390 +               vxwprintk_task(1, "did hit the barrier.");
4391 +               return 1;
4392 +       }
4393 +       return 0;
4394 +}
4395 +
4396 +static int __dx_permission(const struct inode *inode, int mask)
4397 +{
4398 +       if (dx_barrier(inode))
4399 +               return -EACCES;
4400 +
4401 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4402 +               /* devpts is xid tagged */
4403 +               if (S_ISDIR(inode->i_mode) ||
4404 +                   vx_check((xid_t)inode->i_tag, VS_IDENT | VS_WATCH_P))
4405 +                       return 0;
4406 +
4407 +               /* just pretend we didn't find anything */
4408 +               return -ENOENT;
4409 +       }
4410 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4411 +               struct proc_dir_entry *de = PDE(inode);
4412 +
4413 +               if (de && !vx_hide_check(0, de->vx_flags))
4414 +                       goto out;
4415 +
4416 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4417 +                       struct pid *pid;
4418 +                       struct task_struct *tsk;
4419 +
4420 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4421 +                           vx_flags(VXF_STATE_SETUP, 0))
4422 +                               return 0;
4423 +
4424 +                       pid = PROC_I(inode)->pid;
4425 +                       if (!pid)
4426 +                               goto out;
4427 +
4428 +                       rcu_read_lock();
4429 +                       tsk = pid_task(pid, PIDTYPE_PID);
4430 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4431 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4432 +                       if (tsk &&
4433 +                               vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P)) {
4434 +                               rcu_read_unlock();
4435 +                               return 0;
4436 +                       }
4437 +                       rcu_read_unlock();
4438 +               }
4439 +               else {
4440 +                       /* FIXME: Should we block some entries here? */
4441 +                       return 0;
4442 +               }
4443 +       }
4444 +       else {
4445 +               if (dx_notagcheck(inode->i_sb) ||
4446 +                   dx_check(inode->i_tag, DX_HOSTID | DX_ADMIN | DX_WATCH |
4447 +                            DX_IDENT))
4448 +                       return 0;
4449 +       }
4450 +
4451 +out:
4452 +       return -EACCES;
4453 +}
4454 +
4455 +int dx_permission(const struct inode *inode, int mask)
4456 +{
4457 +       int ret = __dx_permission(inode, mask);
4458 +       if (unlikely(ret)) {
4459 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
4460 +               if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4461 +#endif
4462 +                   vxwprintk_task(1,
4463 +                       "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4464 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
4465 +                       inode->i_ino);
4466 +       }
4467 +       return ret;
4468 +}
4469 +
4470  /*
4471   * This does basic POSIX ACL permission checking
4472   */
4473 @@ -357,10 +448,14 @@ int inode_permission(struct inode *inode
4474                 /*
4475                  * Nobody gets write access to an immutable file.
4476                  */
4477 -               if (IS_IMMUTABLE(inode))
4478 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4479                         return -EACCES;
4480         }
4481  
4482 +       retval = dx_permission(inode, mask);
4483 +       if (retval)
4484 +               return retval;
4485 +
4486         retval = do_inode_permission(inode, mask);
4487         if (retval)
4488                 return retval;
4489 @@ -1037,7 +1132,8 @@ static void follow_dotdot(struct nameida
4490  
4491                 if (nd->path.dentry == nd->root.dentry &&
4492                     nd->path.mnt == nd->root.mnt) {
4493 -                       break;
4494 +                       /* for sane '/' avoid follow_mount() */
4495 +                       return;
4496                 }
4497                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4498                         /* rare case of legitimate dget_parent()... */
4499 @@ -1146,6 +1242,9 @@ static int do_lookup(struct nameidata *n
4500                 }
4501                 if (unlikely(d_need_lookup(dentry)))
4502                         goto unlazy;
4503 +
4504 +               /* FIXME: check dx permission */
4505 +
4506                 path->mnt = mnt;
4507                 path->dentry = dentry;
4508                 if (unlikely(!__follow_mount_rcu(nd, path, inode)))
4509 @@ -1207,6 +1306,8 @@ retry:
4510                 }
4511         }
4512  
4513 +       /* FIXME: check dx permission */
4514 +
4515         path->mnt = mnt;
4516         path->dentry = dentry;
4517         err = follow_managed(path, nd->flags);
4518 @@ -1901,7 +2002,7 @@ static int may_delete(struct inode *dir,
4519         if (IS_APPEND(dir))
4520                 return -EPERM;
4521         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
4522 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4523 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4524                 return -EPERM;
4525         if (isdir) {
4526                 if (!S_ISDIR(victim->d_inode->i_mode))
4527 @@ -1981,19 +2082,25 @@ int vfs_create(struct inode *dir, struct
4528  {
4529         int error = may_create(dir, dentry);
4530  
4531 -       if (error)
4532 +       if (error) {
4533 +               vxdprintk(VXD_CBIT(misc, 3), "may_create failed with %d", error);
4534                 return error;
4535 +       }
4536  
4537         if (!dir->i_op->create)
4538                 return -EACCES; /* shouldn't it be ENOSYS? */
4539         mode &= S_IALLUGO;
4540         mode |= S_IFREG;
4541         error = security_inode_create(dir, dentry, mode);
4542 -       if (error)
4543 +       if (error) {
4544 +               vxdprintk(VXD_CBIT(misc, 3), "security_inode_create failed with %d", error);
4545                 return error;
4546 +       }
4547         error = dir->i_op->create(dir, dentry, mode, nd);
4548         if (!error)
4549                 fsnotify_create(dir, dentry);
4550 +       else
4551 +               vxdprintk(VXD_CBIT(misc, 3), "i_op->create failed with %d", error);
4552         return error;
4553  }
4554  
4555 @@ -2028,6 +2135,15 @@ static int may_open(struct path *path, i
4556                 break;
4557         }
4558  
4559 +#ifdef CONFIG_VSERVER_COWBL
4560 +       if (IS_COW(inode) &&
4561 +               ((flag & O_ACCMODE) != O_RDONLY)) {
4562 +               if (IS_COW_LINK(inode))
4563 +                       return -EMLINK;
4564 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4565 +               mark_inode_dirty(inode);
4566 +       }
4567 +#endif
4568         error = inode_permission(inode, acc_mode);
4569         if (error)
4570                 return error;
4571 @@ -2255,6 +2371,16 @@ ok:
4572         }
4573  common:
4574         error = may_open(&nd->path, acc_mode, open_flag);
4575 +#ifdef CONFIG_VSERVER_COWBL
4576 +       if (error == -EMLINK) {
4577 +               struct dentry *dentry;
4578 +               dentry = cow_break_link(pathname);
4579 +               if (IS_ERR(dentry))
4580 +                       error = PTR_ERR(dentry);
4581 +               else
4582 +                       dput(dentry);
4583 +       }
4584 +#endif
4585         if (error)
4586                 goto exit;
4587         filp = nameidata_to_filp(nd);
4588 @@ -2297,6 +2423,7 @@ static struct file *path_openat(int dfd,
4589         struct path path;
4590         int error;
4591  
4592 +restart:
4593         filp = get_empty_filp();
4594         if (!filp)
4595                 return ERR_PTR(-ENFILE);
4596 @@ -2334,6 +2461,17 @@ static struct file *path_openat(int dfd,
4597                         filp = do_last(nd, &path, op, pathname);
4598                 put_link(nd, &link, cookie);
4599         }
4600 +
4601 +#ifdef CONFIG_VSERVER_COWBL
4602 +       if (filp == ERR_PTR(-EMLINK)) {
4603 +               if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4604 +                       path_put(&nd->root);
4605 +               if (base)
4606 +                       fput(base);
4607 +               release_open_intent(nd);
4608 +               goto restart;
4609 +       }
4610 +#endif
4611  out:
4612         if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4613                 path_put(&nd->root);
4614 @@ -2423,6 +2561,11 @@ struct dentry *kern_path_create(int dfd,
4615                 goto fail;
4616         }
4617         *path = nd.path;
4618 +       vxdprintk(VXD_CBIT(misc, 3), "kern_path_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4619 +               path->dentry, path->dentry->d_name.len,
4620 +               path->dentry->d_name.name, dentry,
4621 +               dentry->d_name.len, dentry->d_name.name,
4622 +               path->dentry->d_inode);
4623         return dentry;
4624  eexist:
4625         dput(dentry);
4626 @@ -2904,7 +3047,7 @@ int vfs_link(struct dentry *old_dentry, 
4627         /*
4628          * A link to an append-only or immutable file cannot be created.
4629          */
4630 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4631 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4632                 return -EPERM;
4633         if (!dir->i_op->link)
4634                 return -EPERM;
4635 @@ -3285,6 +3428,227 @@ int vfs_follow_link(struct nameidata *nd
4636         return __vfs_follow_link(nd, link);
4637  }
4638  
4639 +
4640 +#ifdef CONFIG_VSERVER_COWBL
4641 +
4642 +static inline
4643 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4644 +{
4645 +       loff_t ppos = 0;
4646 +
4647 +       return do_splice_direct(in, &ppos, out, len, 0);
4648 +}
4649 +
4650 +struct dentry *cow_break_link(const char *pathname)
4651 +{
4652 +       int ret, mode, pathlen, redo = 0;
4653 +       struct nameidata old_nd, dir_nd;
4654 +       struct path old_path, dir_path;
4655 +       struct dentry *dir, *old_dentry, *new_dentry = NULL;
4656 +       struct file *old_file;
4657 +       struct file *new_file;
4658 +       char *to, *path, pad='\251';
4659 +       loff_t size;
4660 +
4661 +       vxdprintk(VXD_CBIT(misc, 1),
4662 +               "cow_break_link(" VS_Q("%s") ")", pathname);
4663 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
4664 +       ret = -ENOMEM;
4665 +       if (!path)
4666 +               goto out;
4667 +
4668 +       /* old_nd will have refs to dentry and mnt */
4669 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4670 +       vxdprintk(VXD_CBIT(misc, 2),
4671 +               "do_path_lookup(old): %d [r=%d]",
4672 +               ret, mnt_get_count(old_nd.path.mnt));
4673 +       if (ret < 0)
4674 +               goto out_free_path;
4675 +
4676 +       old_path = old_nd.path;
4677 +       old_dentry = old_path.dentry;
4678 +       mode = old_dentry->d_inode->i_mode;
4679 +
4680 +       to = d_path(&old_path, path, PATH_MAX-2);
4681 +       pathlen = strlen(to);
4682 +       vxdprintk(VXD_CBIT(misc, 2),
4683 +               "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4684 +               old_dentry,
4685 +               old_dentry->d_name.len, old_dentry->d_name.name,
4686 +               old_dentry->d_name.len);
4687 +
4688 +       to[pathlen + 1] = 0;
4689 +retry:
4690 +       new_dentry = NULL;
4691 +       to[pathlen] = pad--;
4692 +       ret = -ELOOP;
4693 +       if (pad <= '\240')
4694 +               goto out_rel_old;
4695 +
4696 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4697 +       /* dir_nd will have refs to dentry and mnt */
4698 +       ret = do_path_lookup(AT_FDCWD, to,
4699 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
4700 +       vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(new): %d", ret);
4701 +       if (ret < 0)
4702 +               goto retry;
4703 +
4704 +       /* this puppy downs the dir inode mutex if successful */
4705 +       new_dentry = kern_path_create(AT_FDCWD, to, &dir_path, 0);
4706 +       if (!new_dentry || IS_ERR(new_dentry)) {
4707 +               path_put(&dir_nd.path);
4708 +               vxdprintk(VXD_CBIT(misc, 2),
4709 +                       "kern_path_create(new) failed with %ld",
4710 +                       PTR_ERR(new_dentry));
4711 +               goto retry;
4712 +       }
4713 +       path_put(&dir_path);
4714 +       vxdprintk(VXD_CBIT(misc, 2),
4715 +               "kern_path_create(new): %p [" VS_Q("%.*s") ":%d]",
4716 +               new_dentry,
4717 +               new_dentry->d_name.len, new_dentry->d_name.name,
4718 +               new_dentry->d_name.len);
4719 +
4720 +       dir = dir_nd.path.dentry;
4721 +
4722 +       ret = vfs_create(dir->d_inode, new_dentry, mode, &dir_nd);
4723 +       vxdprintk(VXD_CBIT(misc, 2),
4724 +               "vfs_create(new): %d", ret);
4725 +       if (ret == -EEXIST) {
4726 +               mutex_unlock(&dir->d_inode->i_mutex);
4727 +               path_put(&dir_nd.path);
4728 +               dput(new_dentry);
4729 +               goto retry;
4730 +       }
4731 +       else if (ret < 0)
4732 +               goto out_unlock_new;
4733 +
4734 +       /* drop out early, ret passes ENOENT */
4735 +       ret = -ENOENT;
4736 +       if ((redo = d_unhashed(old_dentry)))
4737 +               goto out_unlock_new;
4738 +
4739 +       path_get(&old_path);
4740 +       /* this one cleans up the dentry/mnt in case of failure */
4741 +       old_file = dentry_open(old_dentry, old_path.mnt,
4742 +               O_RDONLY, current_cred());
4743 +       vxdprintk(VXD_CBIT(misc, 2),
4744 +               "dentry_open(old): %p", old_file);
4745 +       if (IS_ERR(old_file)) {
4746 +               ret = PTR_ERR(old_file);
4747 +               goto out_unlock_new;
4748 +       }
4749 +
4750 +       dget(new_dentry);
4751 +       mntget(old_path.mnt);
4752 +       /* this one cleans up the dentry/mnt in case of failure */
4753 +       new_file = dentry_open(new_dentry, old_path.mnt,
4754 +               O_WRONLY, current_cred());
4755 +       vxdprintk(VXD_CBIT(misc, 2),
4756 +               "dentry_open(new): %p", new_file);
4757 +       if (IS_ERR(new_file)) {
4758 +               ret = PTR_ERR(new_file);
4759 +               goto out_fput_old;
4760 +       }
4761 +
4762 +       size = i_size_read(old_file->f_dentry->d_inode);
4763 +       ret = do_cow_splice(old_file, new_file, size);
4764 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4765 +       if (ret < 0) {
4766 +               goto out_fput_both;
4767 +       } else if (ret < size) {
4768 +               ret = -ENOSPC;
4769 +               goto out_fput_both;
4770 +       } else {
4771 +               struct inode *old_inode = old_dentry->d_inode;
4772 +               struct inode *new_inode = new_dentry->d_inode;
4773 +               struct iattr attr = {
4774 +                       .ia_uid = old_inode->i_uid,
4775 +                       .ia_gid = old_inode->i_gid,
4776 +                       .ia_valid = ATTR_UID | ATTR_GID
4777 +                       };
4778 +
4779 +               setattr_copy(new_inode, &attr);
4780 +               mark_inode_dirty(new_inode);
4781 +       }
4782 +
4783 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4784 +
4785 +       /* drop out late */
4786 +       ret = -ENOENT;
4787 +       if ((redo = d_unhashed(old_dentry)))
4788 +               goto out_unlock;
4789 +
4790 +       vxdprintk(VXD_CBIT(misc, 2),
4791 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4792 +               new_dentry->d_name.len, new_dentry->d_name.name,
4793 +               new_dentry->d_name.len,
4794 +               old_dentry->d_name.len, old_dentry->d_name.name,
4795 +               old_dentry->d_name.len);
4796 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_dentry,
4797 +               old_dentry->d_parent->d_inode, old_dentry);
4798 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4799 +
4800 +out_unlock:
4801 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4802 +
4803 +out_fput_both:
4804 +       vxdprintk(VXD_CBIT(misc, 3),
4805 +               "fput(new_file=%p[#%ld])", new_file,
4806 +               atomic_long_read(&new_file->f_count));
4807 +       fput(new_file);
4808 +
4809 +out_fput_old:
4810 +       vxdprintk(VXD_CBIT(misc, 3),
4811 +               "fput(old_file=%p[#%ld])", old_file,
4812 +               atomic_long_read(&old_file->f_count));
4813 +       fput(old_file);
4814 +
4815 +out_unlock_new:
4816 +       mutex_unlock(&dir->d_inode->i_mutex);
4817 +       if (!ret)
4818 +               goto out_redo;
4819 +
4820 +       /* error path cleanup */
4821 +       vfs_unlink(dir->d_inode, new_dentry);
4822 +
4823 +out_redo:
4824 +       if (!redo)
4825 +               goto out_rel_both;
4826 +       /* lookup dentry once again */
4827 +       /* old_nd.path is freed as old_path in out_rel_old */
4828 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4829 +       if (ret)
4830 +               goto out_rel_both;
4831 +
4832 +       dput(new_dentry);
4833 +       new_dentry = old_nd.path.dentry;
4834 +       vxdprintk(VXD_CBIT(misc, 2),
4835 +               "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4836 +               new_dentry,
4837 +               new_dentry->d_name.len, new_dentry->d_name.name,
4838 +               new_dentry->d_name.len);
4839 +       dget(new_dentry);
4840 +
4841 +out_rel_both:
4842 +       path_put(&dir_nd.path);
4843 +out_rel_old:
4844 +       path_put(&old_path);
4845 +out_free_path:
4846 +       kfree(path);
4847 +out:
4848 +       if (ret) {
4849 +               dput(new_dentry);
4850 +               new_dentry = ERR_PTR(ret);
4851 +       }
4852 +       vxdprintk(VXD_CBIT(misc, 3),
4853 +               "cow_break_link returning with %p [r=%d]",
4854 +               new_dentry, mnt_get_count(old_nd.path.mnt));
4855 +       return new_dentry;
4856 +}
4857 +
4858 +#endif
4859 +
4860  /* get the link contents into pagecache */
4861  static char *page_getlink(struct dentry * dentry, struct page **ppage)
4862  {
4863 diff -NurpP --minimal linux-3.1.6/fs/namespace.c linux-3.1.6-vs2.3.2.5/fs/namespace.c
4864 --- linux-3.1.6/fs/namespace.c  2011-12-23 16:04:07.000000000 +0100
4865 +++ linux-3.1.6-vs2.3.2.5/fs/namespace.c        2011-12-23 16:11:57.000000000 +0100
4866 @@ -31,6 +31,11 @@
4867  #include <linux/idr.h>
4868  #include <linux/fs_struct.h>
4869  #include <linux/fsnotify.h>
4870 +#include <linux/vs_base.h>
4871 +#include <linux/vs_context.h>
4872 +#include <linux/vs_tag.h>
4873 +#include <linux/vserver/space.h>
4874 +#include <linux/vserver/global.h>
4875  #include <asm/uaccess.h>
4876  #include <asm/unistd.h>
4877  #include "pnode.h"
4878 @@ -679,6 +684,10 @@ vfs_kern_mount(struct file_system_type *
4879         if (!type)
4880                 return ERR_PTR(-ENODEV);
4881  
4882 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
4883 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
4884 +               return ERR_PTR(-EPERM);
4885 +
4886         mnt = alloc_vfsmnt(name);
4887         if (!mnt)
4888                 return ERR_PTR(-ENOMEM);
4889 @@ -724,6 +733,7 @@ static struct vfsmount *clone_mnt(struct
4890                 mnt->mnt_root = dget(root);
4891                 mnt->mnt_mountpoint = mnt->mnt_root;
4892                 mnt->mnt_parent = mnt;
4893 +               mnt->mnt_tag = old->mnt_tag;
4894  
4895                 if (flag & CL_SLAVE) {
4896                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
4897 @@ -852,6 +862,31 @@ static inline void mangle(struct seq_fil
4898         seq_escape(m, s, " \t\n\\");
4899  }
4900  
4901 +static int mnt_is_reachable(struct vfsmount *mnt)
4902 +{
4903 +       struct path root;
4904 +       struct dentry *point;
4905 +       int ret;
4906 +
4907 +       if (mnt == mnt->mnt_ns->root)
4908 +               return 1;
4909 +
4910 +       br_read_lock(vfsmount_lock);
4911 +       root = current->fs->root;
4912 +       point = root.dentry;
4913 +
4914 +       while ((mnt != mnt->mnt_parent) && (mnt != root.mnt)) {
4915 +               point = mnt->mnt_mountpoint;
4916 +               mnt = mnt->mnt_parent;
4917 +       }
4918 +
4919 +       ret = (mnt == root.mnt) && is_subdir(point, root.dentry);
4920 +
4921 +       br_read_unlock(vfsmount_lock);
4922 +
4923 +       return ret;
4924 +}
4925 +
4926  /*
4927   * Simple .show_options callback for filesystems which don't want to
4928   * implement more complex mount option showing.
4929 @@ -954,6 +989,8 @@ static int show_sb_opts(struct seq_file 
4930                 { MS_SYNCHRONOUS, ",sync" },
4931                 { MS_DIRSYNC, ",dirsync" },
4932                 { MS_MANDLOCK, ",mand" },
4933 +               { MS_TAGGED, ",tag" },
4934 +               { MS_NOTAGCHECK, ",notagcheck" },
4935                 { 0, NULL }
4936         };
4937         const struct proc_fs_info *fs_infop;
4938 @@ -1000,16 +1037,26 @@ static int show_vfsmnt(struct seq_file *
4939         int err = 0;
4940         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
4941  
4942 -       if (mnt->mnt_sb->s_op->show_devname) {
4943 -               err = mnt->mnt_sb->s_op->show_devname(m, mnt);
4944 -               if (err)
4945 -                       goto out;
4946 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
4947 +               return SEQ_SKIP;
4948 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
4949 +               return SEQ_SKIP;
4950 +
4951 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
4952 +               mnt == current->fs->root.mnt) {
4953 +               seq_puts(m, "/dev/root / ");
4954         } else {
4955 -               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
4956 +               if (mnt->mnt_sb->s_op->show_devname) {
4957 +                       err = mnt->mnt_sb->s_op->show_devname(m, mnt);
4958 +                       if (err)
4959 +                               goto out;
4960 +               } else {
4961 +                       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
4962 +               }
4963 +               seq_putc(m, ' ');
4964 +               seq_path(m, &mnt_path, " \t\n\\");
4965 +               seq_putc(m, ' ');
4966         }
4967 -       seq_putc(m, ' ');
4968 -       seq_path(m, &mnt_path, " \t\n\\");
4969 -       seq_putc(m, ' ');
4970         show_type(m, mnt->mnt_sb);
4971         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
4972         err = show_sb_opts(m, mnt->mnt_sb);
4973 @@ -1039,6 +1086,11 @@ static int show_mountinfo(struct seq_fil
4974         struct path root = p->root;
4975         int err = 0;
4976  
4977 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
4978 +               return SEQ_SKIP;
4979 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
4980 +               return SEQ_SKIP;
4981 +
4982         seq_printf(m, "%i %i %u:%u ", mnt->mnt_id, mnt->mnt_parent->mnt_id,
4983                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
4984         if (sb->s_op->show_path)
4985 @@ -1104,22 +1156,32 @@ static int show_vfsstat(struct seq_file 
4986         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
4987         int err = 0;
4988  
4989 -       /* device */
4990 -       if (mnt->mnt_sb->s_op->show_devname) {
4991 -               seq_puts(m, "device ");
4992 -               err = mnt->mnt_sb->s_op->show_devname(m, mnt);
4993 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
4994 +               return SEQ_SKIP;
4995 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
4996 +               return SEQ_SKIP;
4997 +
4998 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
4999 +               mnt == current->fs->root.mnt) {
5000 +               seq_puts(m, "device /dev/root mounted on / ");
5001         } else {
5002 -               if (mnt->mnt_devname) {
5003 +               /* device */
5004 +               if (mnt->mnt_sb->s_op->show_devname) {
5005                         seq_puts(m, "device ");
5006 -                       mangle(m, mnt->mnt_devname);
5007 -               } else
5008 -                       seq_puts(m, "no device");
5009 -       }
5010 +                       err = mnt->mnt_sb->s_op->show_devname(m, mnt);
5011 +               } else {
5012 +                       if (mnt->mnt_devname) {
5013 +                               seq_puts(m, "device ");
5014 +                               mangle(m, mnt->mnt_devname);
5015 +                       } else
5016 +                               seq_puts(m, "no device");
5017 +               }
5018  
5019 -       /* mount point */
5020 -       seq_puts(m, " mounted on ");
5021 -       seq_path(m, &mnt_path, " \t\n\\");
5022 -       seq_putc(m, ' ');
5023 +               /* mount point */
5024 +               seq_puts(m, " mounted on ");
5025 +               seq_path(m, &mnt_path, " \t\n\\");
5026 +               seq_putc(m, ' ');
5027 +       }
5028  
5029         /* file system type */
5030         seq_puts(m, "with fstype ");
5031 @@ -1378,7 +1440,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
5032                 goto dput_and_out;
5033  
5034         retval = -EPERM;
5035 -       if (!capable(CAP_SYS_ADMIN))
5036 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5037                 goto dput_and_out;
5038  
5039         retval = do_umount(path.mnt, flags);
5040 @@ -1404,7 +1466,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
5041  
5042  static int mount_is_safe(struct path *path)
5043  {
5044 -       if (capable(CAP_SYS_ADMIN))
5045 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5046                 return 0;
5047         return -EPERM;
5048  #ifdef notyet
5049 @@ -1714,7 +1776,7 @@ static int do_change_type(struct path *p
5050         int type;
5051         int err = 0;
5052  
5053 -       if (!capable(CAP_SYS_ADMIN))
5054 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_NAMESPACE))
5055                 return -EPERM;
5056  
5057         if (path->dentry != path->mnt->mnt_root)
5058 @@ -1730,6 +1792,7 @@ static int do_change_type(struct path *p
5059                 if (err)
5060                         goto out_unlock;
5061         }
5062 +       // mnt->mnt_flags = mnt_flags;
5063  
5064         br_write_lock(vfsmount_lock);
5065         for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
5066 @@ -1745,12 +1808,14 @@ static int do_change_type(struct path *p
5067   * do loopback mount.
5068   */
5069  static int do_loopback(struct path *path, char *old_name,
5070 -                               int recurse)
5071 +       tag_t tag, unsigned long flags, int mnt_flags)
5072  {
5073         LIST_HEAD(umount_list);
5074         struct path old_path;
5075         struct vfsmount *mnt = NULL;
5076         int err = mount_is_safe(path);
5077 +       int recurse = flags & MS_REC;
5078 +
5079         if (err)
5080                 return err;
5081         if (!old_name || !*old_name)
5082 @@ -1816,12 +1881,12 @@ static int change_mount_flags(struct vfs
5083   * on it - tough luck.
5084   */
5085  static int do_remount(struct path *path, int flags, int mnt_flags,
5086 -                     void *data)
5087 +       void *data, xid_t xid)
5088  {
5089         int err;
5090         struct super_block *sb = path->mnt->mnt_sb;
5091  
5092 -       if (!capable(CAP_SYS_ADMIN))
5093 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
5094                 return -EPERM;
5095  
5096         if (!check_mnt(path->mnt))
5097 @@ -1869,7 +1934,7 @@ static int do_move_mount(struct path *pa
5098         struct path old_path, parent_path;
5099         struct vfsmount *p;
5100         int err = 0;
5101 -       if (!capable(CAP_SYS_ADMIN))
5102 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5103                 return -EPERM;
5104         if (!old_name || !*old_name)
5105                 return -EINVAL;
5106 @@ -2020,7 +2085,7 @@ static int do_new_mount(struct path *pat
5107                 return -EINVAL;
5108  
5109         /* we need capabilities... */
5110 -       if (!capable(CAP_SYS_ADMIN))
5111 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5112                 return -EPERM;
5113  
5114         mnt = do_kern_mount(type, flags, name, data);
5115 @@ -2289,6 +2354,7 @@ long do_mount(char *dev_name, char *dir_
5116         struct path path;
5117         int retval = 0;
5118         int mnt_flags = 0;
5119 +       tag_t tag = 0;
5120  
5121         /* Discard magic */
5122         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5123 @@ -2316,6 +2382,12 @@ long do_mount(char *dev_name, char *dir_
5124         if (!(flags & MS_NOATIME))
5125                 mnt_flags |= MNT_RELATIME;
5126  
5127 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5128 +               /* FIXME: bind and re-mounts get the tag flag? */
5129 +               if (flags & (MS_BIND|MS_REMOUNT))
5130 +                       flags |= MS_TAGID;
5131 +       }
5132 +
5133         /* Separate the per-mountpoint flags */
5134         if (flags & MS_NOSUID)
5135                 mnt_flags |= MNT_NOSUID;
5136 @@ -2332,15 +2404,17 @@ long do_mount(char *dev_name, char *dir_
5137         if (flags & MS_RDONLY)
5138                 mnt_flags |= MNT_READONLY;
5139  
5140 +       if (!capable(CAP_SYS_ADMIN))
5141 +               mnt_flags |= MNT_NODEV;
5142         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
5143                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
5144                    MS_STRICTATIME);
5145  
5146         if (flags & MS_REMOUNT)
5147                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5148 -                                   data_page);
5149 +                                   data_page, tag);
5150         else if (flags & MS_BIND)
5151 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5152 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5153         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5154                 retval = do_change_type(&path, flags);
5155         else if (flags & MS_MOVE)
5156 @@ -2440,6 +2514,7 @@ static struct mnt_namespace *dup_mnt_ns(
5157                 q = next_mnt(q, new_ns->root);
5158         }
5159         up_write(&namespace_sem);
5160 +       atomic_inc(&vs_global_mnt_ns);
5161  
5162         if (rootmnt)
5163                 mntput(rootmnt);
5164 @@ -2579,9 +2654,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5165                 goto out3;
5166  
5167         error = -EINVAL;
5168 -       if (IS_MNT_SHARED(old.mnt) ||
5169 +       if ((IS_MNT_SHARED(old.mnt) ||
5170                 IS_MNT_SHARED(new.mnt->mnt_parent) ||
5171 -               IS_MNT_SHARED(root.mnt->mnt_parent))
5172 +               IS_MNT_SHARED(root.mnt->mnt_parent)) &&
5173 +               !vx_flags(VXF_STATE_SETUP, 0))
5174                 goto out4;
5175         if (!check_mnt(root.mnt) || !check_mnt(new.mnt))
5176                 goto out4;
5177 @@ -2713,6 +2789,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5178         br_write_unlock(vfsmount_lock);
5179         up_write(&namespace_sem);
5180         release_mounts(&umount_list);
5181 +       atomic_dec(&vs_global_mnt_ns);
5182         kfree(ns);
5183  }
5184  EXPORT_SYMBOL(put_mnt_ns);
5185 diff -NurpP --minimal linux-3.1.6/fs/nfs/client.c linux-3.1.6-vs2.3.2.5/fs/nfs/client.c
5186 --- linux-3.1.6/fs/nfs/client.c 2011-10-24 18:45:27.000000000 +0200
5187 +++ linux-3.1.6-vs2.3.2.5/fs/nfs/client.c       2011-10-24 18:53:33.000000000 +0200
5188 @@ -778,6 +778,9 @@ static int nfs_init_server_rpcclient(str
5189         if (server->flags & NFS_MOUNT_SOFT)
5190                 server->client->cl_softrtry = 1;
5191  
5192 +       server->client->cl_tag = 0;
5193 +       if (server->flags & NFS_MOUNT_TAGGED)
5194 +               server->client->cl_tag = 1;
5195         return 0;
5196  }
5197  
5198 @@ -952,6 +955,10 @@ static void nfs_server_set_fsinfo(struct
5199                 server->acdirmin = server->acdirmax = 0;
5200         }
5201  
5202 +       /* FIXME: needs fsinfo
5203 +       if (server->flags & NFS_MOUNT_TAGGED)
5204 +               sb->s_flags |= MS_TAGGED;       */
5205 +
5206         server->maxfilesize = fsinfo->maxfilesize;
5207  
5208         server->time_delta = fsinfo->time_delta;
5209 diff -NurpP --minimal linux-3.1.6/fs/nfs/dir.c linux-3.1.6-vs2.3.2.5/fs/nfs/dir.c
5210 --- linux-3.1.6/fs/nfs/dir.c    2011-12-23 16:04:07.000000000 +0100
5211 +++ linux-3.1.6-vs2.3.2.5/fs/nfs/dir.c  2011-11-29 12:53:17.000000000 +0100
5212 @@ -35,6 +35,7 @@
5213  #include <linux/sched.h>
5214  #include <linux/kmemleak.h>
5215  #include <linux/xattr.h>
5216 +#include <linux/vs_tag.h>
5217  
5218  #include "delegation.h"
5219  #include "iostat.h"
5220 @@ -1311,6 +1312,7 @@ static struct dentry *nfs_lookup(struct 
5221         if (IS_ERR(res))
5222                 goto out_unblock_sillyrename;
5223  
5224 +       dx_propagate_tag(nd, inode);
5225  no_entry:
5226         res = d_materialise_unique(dentry, inode);
5227         if (res != NULL) {
5228 diff -NurpP --minimal linux-3.1.6/fs/nfs/inode.c linux-3.1.6-vs2.3.2.5/fs/nfs/inode.c
5229 --- linux-3.1.6/fs/nfs/inode.c  2011-12-23 16:04:07.000000000 +0100
5230 +++ linux-3.1.6-vs2.3.2.5/fs/nfs/inode.c        2011-11-29 12:53:17.000000000 +0100
5231 @@ -38,6 +38,7 @@
5232  #include <linux/nfs_xdr.h>
5233  #include <linux/slab.h>
5234  #include <linux/compat.h>
5235 +#include <linux/vs_tag.h>
5236  
5237  #include <asm/system.h>
5238  #include <asm/uaccess.h>
5239 @@ -273,6 +274,8 @@ nfs_fhget(struct super_block *sb, struct
5240         if (inode->i_state & I_NEW) {
5241                 struct nfs_inode *nfsi = NFS_I(inode);
5242                 unsigned long now = jiffies;
5243 +               uid_t uid;
5244 +               gid_t gid;
5245  
5246                 /* We set i_ino for the few things that still rely on it,
5247                  * such as stat(2) */
5248 @@ -321,8 +324,8 @@ nfs_fhget(struct super_block *sb, struct
5249                 nfsi->change_attr = 0;
5250                 inode->i_size = 0;
5251                 inode->i_nlink = 0;
5252 -               inode->i_uid = -2;
5253 -               inode->i_gid = -2;
5254 +               uid = -2;
5255 +               gid = -2;
5256                 inode->i_blocks = 0;
5257                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5258  
5259 @@ -359,13 +362,13 @@ nfs_fhget(struct super_block *sb, struct
5260                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5261                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5262                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5263 -                       inode->i_uid = fattr->uid;
5264 +                       uid = fattr->uid;
5265                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5266                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5267                                 | NFS_INO_INVALID_ACCESS
5268                                 | NFS_INO_INVALID_ACL;
5269                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5270 -                       inode->i_gid = fattr->gid;
5271 +                       gid = fattr->gid;
5272                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5273                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5274                                 | NFS_INO_INVALID_ACCESS
5275 @@ -378,6 +381,11 @@ nfs_fhget(struct super_block *sb, struct
5276                          */
5277                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5278                 }
5279 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5280 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5281 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
5282 +                               /* maybe fattr->xid someday */
5283 +
5284                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5285                 nfsi->attrtimeo_timestamp = now;
5286                 nfsi->access_cache = RB_ROOT;
5287 @@ -494,6 +502,8 @@ void nfs_setattr_update_inode(struct ino
5288                         inode->i_uid = attr->ia_uid;
5289                 if ((attr->ia_valid & ATTR_GID) != 0)
5290                         inode->i_gid = attr->ia_gid;
5291 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5292 +                       inode->i_tag = attr->ia_tag;
5293                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5294                 spin_unlock(&inode->i_lock);
5295         }
5296 @@ -943,6 +953,9 @@ static int nfs_check_inode_attributes(st
5297         struct nfs_inode *nfsi = NFS_I(inode);
5298         loff_t cur_size, new_isize;
5299         unsigned long invalid = 0;
5300 +       uid_t uid;
5301 +       gid_t gid;
5302 +       tag_t tag;
5303  
5304  
5305         /* Has the inode gone and changed behind our back? */
5306 @@ -966,13 +979,18 @@ static int nfs_check_inode_attributes(st
5307                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5308         }
5309  
5310 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5311 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5312 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5313 +
5314         /* Have any file permissions changed? */
5315         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5316                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5317 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && inode->i_uid != fattr->uid)
5318 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && uid != fattr->uid)
5319                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5320 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && inode->i_gid != fattr->gid)
5321 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && gid != fattr->gid)
5322                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5323 +               /* maybe check for tag too? */
5324  
5325         /* Has the link count changed? */
5326         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5327 @@ -1207,6 +1225,9 @@ static int nfs_update_inode(struct inode
5328         unsigned long invalid = 0;
5329         unsigned long now = jiffies;
5330         unsigned long save_cache_validity;
5331 +       uid_t uid;
5332 +       gid_t gid;
5333 +       tag_t tag;
5334  
5335         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
5336                         __func__, inode->i_sb->s_id, inode->i_ino,
5337 @@ -1314,6 +1335,9 @@ static int nfs_update_inode(struct inode
5338                                 | NFS_INO_REVAL_PAGECACHE
5339                                 | NFS_INO_REVAL_FORCED);
5340  
5341 +       uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5342 +       gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5343 +       tag = inode->i_tag;
5344  
5345         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5346                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5347 @@ -1335,9 +1359,9 @@ static int nfs_update_inode(struct inode
5348                                 | NFS_INO_REVAL_FORCED);
5349  
5350         if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
5351 -               if (inode->i_uid != fattr->uid) {
5352 +               if (uid != fattr->uid) {
5353                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5354 -                       inode->i_uid = fattr->uid;
5355 +                       uid = fattr->uid;
5356                 }
5357         } else if (server->caps & NFS_CAP_OWNER)
5358                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5359 @@ -1346,9 +1370,9 @@ static int nfs_update_inode(struct inode
5360                                 | NFS_INO_REVAL_FORCED);
5361  
5362         if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
5363 -               if (inode->i_gid != fattr->gid) {
5364 +               if (gid != fattr->gid) {
5365                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5366 -                       inode->i_gid = fattr->gid;
5367 +                       gid = fattr->gid;
5368                 }
5369         } else if (server->caps & NFS_CAP_OWNER_GROUP)
5370                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5371 @@ -1356,6 +1380,10 @@ static int nfs_update_inode(struct inode
5372                                 | NFS_INO_INVALID_ACL
5373                                 | NFS_INO_REVAL_FORCED);
5374  
5375 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5376 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5377 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, tag);
5378 +
5379         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5380                 if (inode->i_nlink != fattr->nlink) {
5381                         invalid |= NFS_INO_INVALID_ATTR;
5382 diff -NurpP --minimal linux-3.1.6/fs/nfs/nfs3xdr.c linux-3.1.6-vs2.3.2.5/fs/nfs/nfs3xdr.c
5383 --- linux-3.1.6/fs/nfs/nfs3xdr.c        2011-03-15 18:07:32.000000000 +0100
5384 +++ linux-3.1.6-vs2.3.2.5/fs/nfs/nfs3xdr.c      2011-10-24 18:53:33.000000000 +0200
5385 @@ -20,6 +20,7 @@
5386  #include <linux/nfs3.h>
5387  #include <linux/nfs_fs.h>
5388  #include <linux/nfsacl.h>
5389 +#include <linux/vs_tag.h>
5390  #include "internal.h"
5391  
5392  #define NFSDBG_FACILITY                NFSDBG_XDR
5393 @@ -562,7 +563,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5394   *             set_mtime       mtime;
5395   *     };
5396   */
5397 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5398 +static void encode_sattr3(struct xdr_stream *xdr,
5399 +       const struct iattr *attr, int tag)
5400  {
5401         u32 nbytes;
5402         __be32 *p;
5403 @@ -594,15 +596,19 @@ static void encode_sattr3(struct xdr_str
5404         } else
5405                 *p++ = xdr_zero;
5406  
5407 -       if (attr->ia_valid & ATTR_UID) {
5408 +       if (attr->ia_valid & ATTR_UID ||
5409 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5410                 *p++ = xdr_one;
5411 -               *p++ = cpu_to_be32(attr->ia_uid);
5412 +               *p++ = cpu_to_be32(TAGINO_UID(tag,
5413 +                       attr->ia_uid, attr->ia_tag));
5414         } else
5415                 *p++ = xdr_zero;
5416  
5417 -       if (attr->ia_valid & ATTR_GID) {
5418 +       if (attr->ia_valid & ATTR_GID ||
5419 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5420                 *p++ = xdr_one;
5421 -               *p++ = cpu_to_be32(attr->ia_gid);
5422 +               *p++ = cpu_to_be32(TAGINO_GID(tag,
5423 +                       attr->ia_gid, attr->ia_tag));
5424         } else
5425                 *p++ = xdr_zero;
5426  
5427 @@ -878,7 +884,7 @@ static void nfs3_xdr_enc_setattr3args(st
5428                                       const struct nfs3_sattrargs *args)
5429  {
5430         encode_nfs_fh3(xdr, args->fh);
5431 -       encode_sattr3(xdr, args->sattr);
5432 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5433         encode_sattrguard3(xdr, args);
5434  }
5435  
5436 @@ -1028,13 +1034,13 @@ static void nfs3_xdr_enc_write3args(stru
5437   *     };
5438   */
5439  static void encode_createhow3(struct xdr_stream *xdr,
5440 -                             const struct nfs3_createargs *args)
5441 +       const struct nfs3_createargs *args, int tag)
5442  {
5443         encode_uint32(xdr, args->createmode);
5444         switch (args->createmode) {
5445         case NFS3_CREATE_UNCHECKED:
5446         case NFS3_CREATE_GUARDED:
5447 -               encode_sattr3(xdr, args->sattr);
5448 +               encode_sattr3(xdr, args->sattr, tag);
5449                 break;
5450         case NFS3_CREATE_EXCLUSIVE:
5451                 encode_createverf3(xdr, args->verifier);
5452 @@ -1049,7 +1055,7 @@ static void nfs3_xdr_enc_create3args(str
5453                                      const struct nfs3_createargs *args)
5454  {
5455         encode_diropargs3(xdr, args->fh, args->name, args->len);
5456 -       encode_createhow3(xdr, args);
5457 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5458  }
5459  
5460  /*
5461 @@ -1065,7 +1071,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5462                                     const struct nfs3_mkdirargs *args)
5463  {
5464         encode_diropargs3(xdr, args->fh, args->name, args->len);
5465 -       encode_sattr3(xdr, args->sattr);
5466 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5467  }
5468  
5469  /*
5470 @@ -1082,9 +1088,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
5471   *     };
5472   */
5473  static void encode_symlinkdata3(struct xdr_stream *xdr,
5474 -                               const struct nfs3_symlinkargs *args)
5475 +       const struct nfs3_symlinkargs *args, int tag)
5476  {
5477 -       encode_sattr3(xdr, args->sattr);
5478 +       encode_sattr3(xdr, args->sattr, tag);
5479         encode_nfspath3(xdr, args->pages, args->pathlen);
5480  }
5481  
5482 @@ -1093,7 +1099,7 @@ static void nfs3_xdr_enc_symlink3args(st
5483                                       const struct nfs3_symlinkargs *args)
5484  {
5485         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
5486 -       encode_symlinkdata3(xdr, args);
5487 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
5488  }
5489  
5490  /*
5491 @@ -1121,24 +1127,24 @@ static void nfs3_xdr_enc_symlink3args(st
5492   *     };
5493   */
5494  static void encode_devicedata3(struct xdr_stream *xdr,
5495 -                              const struct nfs3_mknodargs *args)
5496 +       const struct nfs3_mknodargs *args, int tag)
5497  {
5498 -       encode_sattr3(xdr, args->sattr);
5499 +       encode_sattr3(xdr, args->sattr, tag);
5500         encode_specdata3(xdr, args->rdev);
5501  }
5502  
5503  static void encode_mknoddata3(struct xdr_stream *xdr,
5504 -                             const struct nfs3_mknodargs *args)
5505 +       const struct nfs3_mknodargs *args, int tag)
5506  {
5507         encode_ftype3(xdr, args->type);
5508         switch (args->type) {
5509         case NF3CHR:
5510         case NF3BLK:
5511 -               encode_devicedata3(xdr, args);
5512 +               encode_devicedata3(xdr, args, tag);
5513                 break;
5514         case NF3SOCK:
5515         case NF3FIFO:
5516 -               encode_sattr3(xdr, args->sattr);
5517 +               encode_sattr3(xdr, args->sattr, tag);
5518                 break;
5519         case NF3REG:
5520         case NF3DIR:
5521 @@ -1153,7 +1159,7 @@ static void nfs3_xdr_enc_mknod3args(stru
5522                                     const struct nfs3_mknodargs *args)
5523  {
5524         encode_diropargs3(xdr, args->fh, args->name, args->len);
5525 -       encode_mknoddata3(xdr, args);
5526 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
5527  }
5528  
5529  /*
5530 diff -NurpP --minimal linux-3.1.6/fs/nfs/super.c linux-3.1.6-vs2.3.2.5/fs/nfs/super.c
5531 --- linux-3.1.6/fs/nfs/super.c  2011-10-24 18:45:27.000000000 +0200
5532 +++ linux-3.1.6-vs2.3.2.5/fs/nfs/super.c        2011-10-24 18:53:33.000000000 +0200
5533 @@ -53,6 +53,7 @@
5534  #include <linux/nfs_xdr.h>
5535  #include <linux/magic.h>
5536  #include <linux/parser.h>
5537 +#include <linux/vs_tag.h>
5538  
5539  #include <asm/system.h>
5540  #include <asm/uaccess.h>
5541 @@ -87,6 +88,7 @@ enum {
5542         Opt_sharecache, Opt_nosharecache,
5543         Opt_resvport, Opt_noresvport,
5544         Opt_fscache, Opt_nofscache,
5545 +       Opt_tag, Opt_notag,
5546  
5547         /* Mount options that take integer arguments */
5548         Opt_port,
5549 @@ -100,6 +102,7 @@ enum {
5550         Opt_mountvers,
5551         Opt_nfsvers,
5552         Opt_minorversion,
5553 +       Opt_tagid,
5554  
5555         /* Mount options that take string arguments */
5556         Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost,
5557 @@ -180,6 +183,10 @@ static const match_table_t nfs_mount_opt
5558         { Opt_fscache_uniq, "fsc=%s" },
5559         { Opt_local_lock, "local_lock=%s" },
5560  
5561 +       { Opt_tag, "tag" },
5562 +       { Opt_notag, "notag" },
5563 +       { Opt_tagid, "tagid=%u" },
5564 +
5565         { Opt_err, NULL }
5566  };
5567  
5568 @@ -650,6 +657,7 @@ static void nfs_show_mount_options(struc
5569                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5570                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5571                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5572 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5573                 { 0, NULL, NULL }
5574         };
5575         const struct proc_nfs_info *nfs_infop;
5576 @@ -1198,6 +1206,14 @@ static int nfs_parse_mount_options(char 
5577                         kfree(mnt->fscache_uniq);
5578                         mnt->fscache_uniq = NULL;
5579                         break;
5580 +#ifndef CONFIG_TAGGING_NONE
5581 +               case Opt_tag:
5582 +                       mnt->flags |= NFS_MOUNT_TAGGED;
5583 +                       break;
5584 +               case Opt_notag:
5585 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
5586 +                       break;
5587 +#endif
5588  
5589                 /*
5590                  * options that take numeric values
5591 @@ -1304,6 +1320,12 @@ static int nfs_parse_mount_options(char 
5592                                 goto out_invalid_value;
5593                         mnt->minorversion = option;
5594                         break;
5595 +#ifdef CONFIG_PROPAGATE
5596 +               case Opt_tagid:
5597 +                       /* use args[0] */
5598 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
5599 +                       break;
5600 +#endif
5601  
5602                 /*
5603                  * options that take text values
5604 diff -NurpP --minimal linux-3.1.6/fs/nfsd/auth.c linux-3.1.6-vs2.3.2.5/fs/nfsd/auth.c
5605 --- linux-3.1.6/fs/nfsd/auth.c  2010-02-25 11:52:05.000000000 +0100
5606 +++ linux-3.1.6-vs2.3.2.5/fs/nfsd/auth.c        2011-10-24 18:53:33.000000000 +0200
5607 @@ -1,6 +1,7 @@
5608  /* Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> */
5609  
5610  #include <linux/sched.h>
5611 +#include <linux/vs_tag.h>
5612  #include "nfsd.h"
5613  #include "auth.h"
5614  
5615 @@ -36,6 +37,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5616  
5617         new->fsuid = rqstp->rq_cred.cr_uid;
5618         new->fsgid = rqstp->rq_cred.cr_gid;
5619 +       /* FIXME: this desperately needs a tag :)
5620 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5621 +                       */
5622  
5623         rqgi = rqstp->rq_cred.cr_group_info;
5624  
5625 diff -NurpP --minimal linux-3.1.6/fs/nfsd/nfs3xdr.c linux-3.1.6-vs2.3.2.5/fs/nfsd/nfs3xdr.c
5626 --- linux-3.1.6/fs/nfsd/nfs3xdr.c       2011-07-22 11:18:05.000000000 +0200
5627 +++ linux-3.1.6-vs2.3.2.5/fs/nfsd/nfs3xdr.c     2011-10-24 18:53:33.000000000 +0200
5628 @@ -7,6 +7,7 @@
5629   */
5630  
5631  #include <linux/namei.h>
5632 +#include <linux/vs_tag.h>
5633  #include "xdr3.h"
5634  #include "auth.h"
5635  
5636 @@ -95,6 +96,8 @@ static __be32 *
5637  decode_sattr3(__be32 *p, struct iattr *iap)
5638  {
5639         u32     tmp;
5640 +       uid_t   uid = 0;
5641 +       gid_t   gid = 0;
5642  
5643         iap->ia_valid = 0;
5644  
5645 @@ -104,12 +107,15 @@ decode_sattr3(__be32 *p, struct iattr *i
5646         }
5647         if (*p++) {
5648                 iap->ia_valid |= ATTR_UID;
5649 -               iap->ia_uid = ntohl(*p++);
5650 +               uid = ntohl(*p++);
5651         }
5652         if (*p++) {
5653                 iap->ia_valid |= ATTR_GID;
5654 -               iap->ia_gid = ntohl(*p++);
5655 +               gid = ntohl(*p++);
5656         }
5657 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5658 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5659 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5660         if (*p++) {
5661                 u64     newsize;
5662  
5663 @@ -165,8 +171,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5664         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5665         *p++ = htonl((u32) stat->mode);
5666         *p++ = htonl((u32) stat->nlink);
5667 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
5668 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
5669 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
5670 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5671 +               stat->uid, stat->tag)));
5672 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
5673 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5674 +               stat->gid, stat->tag)));
5675         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5676                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5677         } else {
5678 diff -NurpP --minimal linux-3.1.6/fs/nfsd/nfs4xdr.c linux-3.1.6-vs2.3.2.5/fs/nfsd/nfs4xdr.c
5679 --- linux-3.1.6/fs/nfsd/nfs4xdr.c       2011-12-23 16:04:07.000000000 +0100
5680 +++ linux-3.1.6-vs2.3.2.5/fs/nfsd/nfs4xdr.c     2011-11-15 17:08:44.000000000 +0100
5681 @@ -46,6 +46,7 @@
5682  #include <linux/utsname.h>
5683  #include <linux/pagemap.h>
5684  #include <linux/sunrpc/svcauth_gss.h>
5685 +#include <linux/vs_tag.h>
5686  
5687  #include "idmap.h"
5688  #include "acl.h"
5689 @@ -2177,14 +2178,18 @@ out_acl:
5690                 WRITE32(stat.nlink);
5691         }
5692         if (bmval1 & FATTR4_WORD1_OWNER) {
5693 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
5694 +               status = nfsd4_encode_user(rqstp,
5695 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
5696 +                       stat.uid, stat.tag), &p, &buflen);
5697                 if (status == nfserr_resource)
5698                         goto out_resource;
5699                 if (status)
5700                         goto out;
5701         }
5702         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5703 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
5704 +               status = nfsd4_encode_group(rqstp,
5705 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
5706 +                       stat.gid, stat.tag), &p, &buflen);
5707                 if (status == nfserr_resource)
5708                         goto out_resource;
5709                 if (status)
5710 diff -NurpP --minimal linux-3.1.6/fs/nfsd/nfsxdr.c linux-3.1.6-vs2.3.2.5/fs/nfsd/nfsxdr.c
5711 --- linux-3.1.6/fs/nfsd/nfsxdr.c        2011-05-22 16:17:53.000000000 +0200
5712 +++ linux-3.1.6-vs2.3.2.5/fs/nfsd/nfsxdr.c      2011-10-24 18:53:33.000000000 +0200
5713 @@ -6,6 +6,7 @@
5714  
5715  #include "xdr.h"
5716  #include "auth.h"
5717 +#include <linux/vs_tag.h>
5718  
5719  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5720  
5721 @@ -88,6 +89,8 @@ static __be32 *
5722  decode_sattr(__be32 *p, struct iattr *iap)
5723  {
5724         u32     tmp, tmp1;
5725 +       uid_t   uid = 0;
5726 +       gid_t   gid = 0;
5727  
5728         iap->ia_valid = 0;
5729  
5730 @@ -101,12 +104,15 @@ decode_sattr(__be32 *p, struct iattr *ia
5731         }
5732         if ((tmp = ntohl(*p++)) != (u32)-1) {
5733                 iap->ia_valid |= ATTR_UID;
5734 -               iap->ia_uid = tmp;
5735 +               uid = tmp;
5736         }
5737         if ((tmp = ntohl(*p++)) != (u32)-1) {
5738                 iap->ia_valid |= ATTR_GID;
5739 -               iap->ia_gid = tmp;
5740 +               gid = tmp;
5741         }
5742 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5743 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5744 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5745         if ((tmp = ntohl(*p++)) != (u32)-1) {
5746                 iap->ia_valid |= ATTR_SIZE;
5747                 iap->ia_size = tmp;
5748 @@ -151,8 +157,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5749         *p++ = htonl(nfs_ftypes[type >> 12]);
5750         *p++ = htonl((u32) stat->mode);
5751         *p++ = htonl((u32) stat->nlink);
5752 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
5753 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
5754 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
5755 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5756 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
5757 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5758  
5759         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5760                 *p++ = htonl(NFS_MAXPATHLEN);
5761 diff -NurpP --minimal linux-3.1.6/fs/ocfs2/dlmglue.c linux-3.1.6-vs2.3.2.5/fs/ocfs2/dlmglue.c
5762 --- linux-3.1.6/fs/ocfs2/dlmglue.c      2011-05-22 16:17:53.000000000 +0200
5763 +++ linux-3.1.6-vs2.3.2.5/fs/ocfs2/dlmglue.c    2011-10-24 18:53:33.000000000 +0200
5764 @@ -2041,6 +2041,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5765         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5766         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
5767         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
5768 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
5769         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
5770         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
5771         lvb->lvb_iatime_packed  =
5772 @@ -2091,6 +2092,7 @@ static void ocfs2_refresh_inode_from_lvb
5773  
5774         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
5775         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
5776 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
5777         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
5778         inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
5779         ocfs2_unpack_timespec(&inode->i_atime,
5780 diff -NurpP --minimal linux-3.1.6/fs/ocfs2/dlmglue.h linux-3.1.6-vs2.3.2.5/fs/ocfs2/dlmglue.h
5781 --- linux-3.1.6/fs/ocfs2/dlmglue.h      2010-10-21 13:07:50.000000000 +0200
5782 +++ linux-3.1.6-vs2.3.2.5/fs/ocfs2/dlmglue.h    2011-10-24 18:53:33.000000000 +0200
5783 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5784         __be16       lvb_inlink;
5785         __be32       lvb_iattr;
5786         __be32       lvb_igeneration;
5787 -       __be32       lvb_reserved2;
5788 +       __be16       lvb_itag;
5789 +       __be16       lvb_reserved2;
5790  };
5791  
5792  #define OCFS2_QINFO_LVB_VERSION 1
5793 diff -NurpP --minimal linux-3.1.6/fs/ocfs2/file.c linux-3.1.6-vs2.3.2.5/fs/ocfs2/file.c
5794 --- linux-3.1.6/fs/ocfs2/file.c 2011-10-24 18:45:27.000000000 +0200
5795 +++ linux-3.1.6-vs2.3.2.5/fs/ocfs2/file.c       2011-10-24 18:53:33.000000000 +0200
5796 @@ -1123,7 +1123,7 @@ int ocfs2_setattr(struct dentry *dentry,
5797                 attr->ia_valid &= ~ATTR_SIZE;
5798  
5799  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5800 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
5801 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5802         if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5803                 return 0;
5804  
5805 diff -NurpP --minimal linux-3.1.6/fs/ocfs2/inode.c linux-3.1.6-vs2.3.2.5/fs/ocfs2/inode.c
5806 --- linux-3.1.6/fs/ocfs2/inode.c        2011-05-22 16:17:53.000000000 +0200
5807 +++ linux-3.1.6-vs2.3.2.5/fs/ocfs2/inode.c      2011-10-24 18:53:33.000000000 +0200
5808 @@ -28,6 +28,7 @@
5809  #include <linux/highmem.h>
5810  #include <linux/pagemap.h>
5811  #include <linux/quotaops.h>
5812 +#include <linux/vs_tag.h>
5813  
5814  #include <asm/byteorder.h>
5815  
5816 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode 
5817  {
5818         unsigned int flags = OCFS2_I(inode)->ip_attr;
5819  
5820 -       inode->i_flags &= ~(S_IMMUTABLE |
5821 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5822                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5823  
5824         if (flags & OCFS2_IMMUTABLE_FL)
5825                 inode->i_flags |= S_IMMUTABLE;
5826 +       if (flags & OCFS2_IXUNLINK_FL)
5827 +               inode->i_flags |= S_IXUNLINK;
5828  
5829         if (flags & OCFS2_SYNC_FL)
5830                 inode->i_flags |= S_SYNC;
5831 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode 
5832                 inode->i_flags |= S_NOATIME;
5833         if (flags & OCFS2_DIRSYNC_FL)
5834                 inode->i_flags |= S_DIRSYNC;
5835 +
5836 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
5837 +
5838 +       if (flags & OCFS2_BARRIER_FL)
5839 +               inode->i_vflags |= V_BARRIER;
5840 +       if (flags & OCFS2_COW_FL)
5841 +               inode->i_vflags |= V_COW;
5842  }
5843  
5844  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5845  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5846  {
5847         unsigned int flags = oi->vfs_inode.i_flags;
5848 +       unsigned int vflags = oi->vfs_inode.i_vflags;
5849 +
5850 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5851 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5852 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5853 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
5854 +
5855 +       if (flags & S_IMMUTABLE)
5856 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5857 +       if (flags & S_IXUNLINK)
5858 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
5859  
5860 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5861 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5862         if (flags & S_SYNC)
5863                 oi->ip_attr |= OCFS2_SYNC_FL;
5864         if (flags & S_APPEND)
5865                 oi->ip_attr |= OCFS2_APPEND_FL;
5866 -       if (flags & S_IMMUTABLE)
5867 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5868         if (flags & S_NOATIME)
5869                 oi->ip_attr |= OCFS2_NOATIME_FL;
5870         if (flags & S_DIRSYNC)
5871                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5872 +
5873 +       if (vflags & V_BARRIER)
5874 +               oi->ip_attr |= OCFS2_BARRIER_FL;
5875 +       if (vflags & V_COW)
5876 +               oi->ip_attr |= OCFS2_COW_FL;
5877  }
5878  
5879  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5880 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
5881         struct super_block *sb;
5882         struct ocfs2_super *osb;
5883         int use_plocks = 1;
5884 +       uid_t uid;
5885 +       gid_t gid;
5886  
5887         sb = inode->i_sb;
5888         osb = OCFS2_SB(sb);
5889 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
5890         inode->i_generation = le32_to_cpu(fe->i_generation);
5891         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5892         inode->i_mode = le16_to_cpu(fe->i_mode);
5893 -       inode->i_uid = le32_to_cpu(fe->i_uid);
5894 -       inode->i_gid = le32_to_cpu(fe->i_gid);
5895 +       uid = le32_to_cpu(fe->i_uid);
5896 +       gid = le32_to_cpu(fe->i_gid);
5897 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5898 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5899 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
5900 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
5901  
5902         /* Fast symlinks will have i_size but no allocated clusters. */
5903         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
5904 diff -NurpP --minimal linux-3.1.6/fs/ocfs2/inode.h linux-3.1.6-vs2.3.2.5/fs/ocfs2/inode.h
5905 --- linux-3.1.6/fs/ocfs2/inode.h        2011-01-05 21:50:26.000000000 +0100
5906 +++ linux-3.1.6-vs2.3.2.5/fs/ocfs2/inode.h      2011-10-24 18:53:33.000000000 +0200
5907 @@ -151,6 +151,7 @@ struct buffer_head *ocfs2_bread(struct i
5908  
5909  void ocfs2_set_inode_flags(struct inode *inode);
5910  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5911 +int ocfs2_sync_flags(struct inode *inode, int, int);
5912  
5913  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5914  {
5915 diff -NurpP --minimal linux-3.1.6/fs/ocfs2/ioctl.c linux-3.1.6-vs2.3.2.5/fs/ocfs2/ioctl.c
5916 --- linux-3.1.6/fs/ocfs2/ioctl.c        2011-07-22 11:18:06.000000000 +0200
5917 +++ linux-3.1.6-vs2.3.2.5/fs/ocfs2/ioctl.c      2011-10-24 18:53:33.000000000 +0200
5918 @@ -78,7 +78,41 @@ static int ocfs2_get_inode_attr(struct i
5919         return status;
5920  }
5921  
5922 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5923 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5924 +{
5925 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5926 +       struct buffer_head *bh = NULL;
5927 +       handle_t *handle = NULL;
5928 +       int status;
5929 +
5930 +       status = ocfs2_inode_lock(inode, &bh, 1);
5931 +       if (status < 0) {
5932 +               mlog_errno(status);
5933 +               return status;
5934 +       }
5935 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5936 +       if (IS_ERR(handle)) {
5937 +               status = PTR_ERR(handle);
5938 +               mlog_errno(status);
5939 +               goto bail_unlock;
5940 +       }
5941 +
5942 +       inode->i_flags = flags;
5943 +       inode->i_vflags = vflags;
5944 +       ocfs2_get_inode_flags(OCFS2_I(inode));
5945 +
5946 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
5947 +       if (status < 0)
5948 +               mlog_errno(status);
5949 +
5950 +       ocfs2_commit_trans(osb, handle);
5951 +bail_unlock:
5952 +       ocfs2_inode_unlock(inode, 1);
5953 +       brelse(bh);
5954 +       return status;
5955 +}
5956 +
5957 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5958                                 unsigned mask)
5959  {
5960         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5961 @@ -103,6 +137,11 @@ static int ocfs2_set_inode_attr(struct i
5962         if (!S_ISDIR(inode->i_mode))
5963                 flags &= ~OCFS2_DIRSYNC_FL;
5964  
5965 +       if (IS_BARRIER(inode)) {
5966 +               vxwprintk_task(1, "messing with the barrier.");
5967 +               goto bail_unlock;
5968 +       }
5969 +
5970         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5971         if (IS_ERR(handle)) {
5972                 status = PTR_ERR(handle);
5973 @@ -880,6 +919,7 @@ bail:
5974         return status;
5975  }
5976  
5977 +
5978  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5979  {
5980         struct inode *inode = filp->f_path.dentry->d_inode;
5981 diff -NurpP --minimal linux-3.1.6/fs/ocfs2/namei.c linux-3.1.6-vs2.3.2.5/fs/ocfs2/namei.c
5982 --- linux-3.1.6/fs/ocfs2/namei.c        2011-10-24 18:45:27.000000000 +0200
5983 +++ linux-3.1.6-vs2.3.2.5/fs/ocfs2/namei.c      2011-10-24 18:53:33.000000000 +0200
5984 @@ -41,6 +41,7 @@
5985  #include <linux/slab.h>
5986  #include <linux/highmem.h>
5987  #include <linux/quotaops.h>
5988 +#include <linux/vs_tag.h>
5989  
5990  #include <cluster/masklog.h>
5991  
5992 @@ -477,6 +478,7 @@ static int __ocfs2_mknod_locked(struct i
5993         struct ocfs2_dinode *fe = NULL;
5994         struct ocfs2_extent_list *fel;
5995         u16 feat;
5996 +       tag_t tag;
5997  
5998         *new_fe_bh = NULL;
5999  
6000 @@ -514,8 +516,11 @@ static int __ocfs2_mknod_locked(struct i
6001         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
6002         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
6003         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
6004 -       fe->i_uid = cpu_to_le32(inode->i_uid);
6005 -       fe->i_gid = cpu_to_le32(inode->i_gid);
6006 +
6007 +       tag = dx_current_fstag(osb->sb);
6008 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
6009 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
6010 +       inode->i_tag = tag;
6011         fe->i_mode = cpu_to_le16(inode->i_mode);
6012         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
6013                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
6014 diff -NurpP --minimal linux-3.1.6/fs/ocfs2/ocfs2.h linux-3.1.6-vs2.3.2.5/fs/ocfs2/ocfs2.h
6015 --- linux-3.1.6/fs/ocfs2/ocfs2.h        2011-05-22 16:17:53.000000000 +0200
6016 +++ linux-3.1.6-vs2.3.2.5/fs/ocfs2/ocfs2.h      2011-10-24 18:53:33.000000000 +0200
6017 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
6018                                                      writes */
6019         OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
6020         OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
6021 +       OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
6022  };
6023  
6024  #define OCFS2_OSB_SOFT_RO                      0x0001
6025 diff -NurpP --minimal linux-3.1.6/fs/ocfs2/ocfs2_fs.h linux-3.1.6-vs2.3.2.5/fs/ocfs2/ocfs2_fs.h
6026 --- linux-3.1.6/fs/ocfs2/ocfs2_fs.h     2011-05-22 16:17:53.000000000 +0200
6027 +++ linux-3.1.6-vs2.3.2.5/fs/ocfs2/ocfs2_fs.h   2011-10-24 18:53:33.000000000 +0200
6028 @@ -266,6 +266,11 @@
6029  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
6030  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
6031  
6032 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
6033 +
6034 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
6035 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
6036 +
6037  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
6038  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
6039  
6040 diff -NurpP --minimal linux-3.1.6/fs/ocfs2/super.c linux-3.1.6-vs2.3.2.5/fs/ocfs2/super.c
6041 --- linux-3.1.6/fs/ocfs2/super.c        2011-07-22 11:18:06.000000000 +0200
6042 +++ linux-3.1.6-vs2.3.2.5/fs/ocfs2/super.c      2011-10-24 18:53:33.000000000 +0200
6043 @@ -184,6 +184,7 @@ enum {
6044         Opt_coherency_full,
6045         Opt_resv_level,
6046         Opt_dir_resv_level,
6047 +       Opt_tag, Opt_notag, Opt_tagid,
6048         Opt_err,
6049  };
6050  
6051 @@ -215,6 +216,9 @@ static const match_table_t tokens = {
6052         {Opt_coherency_full, "coherency=full"},
6053         {Opt_resv_level, "resv_level=%u"},
6054         {Opt_dir_resv_level, "dir_resv_level=%u"},
6055 +       {Opt_tag, "tag"},
6056 +       {Opt_notag, "notag"},
6057 +       {Opt_tagid, "tagid=%u"},
6058         {Opt_err, NULL}
6059  };
6060  
6061 @@ -662,6 +666,13 @@ static int ocfs2_remount(struct super_bl
6062                 goto out;
6063         }
6064  
6065 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
6066 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
6067 +               ret = -EINVAL;
6068 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
6069 +               goto out;
6070 +       }
6071 +
6072         /* We're going to/from readonly mode. */
6073         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
6074                 /* Disable quota accounting before remounting RO */
6075 @@ -1177,6 +1188,9 @@ static int ocfs2_fill_super(struct super
6076  
6077         ocfs2_complete_mount_recovery(osb);
6078  
6079 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
6080 +               sb->s_flags |= MS_TAGGED;
6081 +
6082         if (ocfs2_mount_local(osb))
6083                 snprintf(nodestr, sizeof(nodestr), "local");
6084         else
6085 @@ -1506,6 +1520,20 @@ static int ocfs2_parse_options(struct su
6086                             option < OCFS2_MAX_RESV_LEVEL)
6087                                 mopt->dir_resv_level = option;
6088                         break;
6089 +#ifndef CONFIG_TAGGING_NONE
6090 +               case Opt_tag:
6091 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6092 +                       break;
6093 +               case Opt_notag:
6094 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
6095 +                       break;
6096 +#endif
6097 +#ifdef CONFIG_PROPAGATE
6098 +               case Opt_tagid:
6099 +                       /* use args[0] */
6100 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6101 +                       break;
6102 +#endif
6103                 default:
6104                         mlog(ML_ERROR,
6105                              "Unrecognized mount option \"%s\" "
6106 diff -NurpP --minimal linux-3.1.6/fs/open.c linux-3.1.6-vs2.3.2.5/fs/open.c
6107 --- linux-3.1.6/fs/open.c       2011-10-24 18:45:27.000000000 +0200
6108 +++ linux-3.1.6-vs2.3.2.5/fs/open.c     2011-10-30 02:06:37.000000000 +0100
6109 @@ -30,6 +30,11 @@
6110  #include <linux/fs_struct.h>
6111  #include <linux/ima.h>
6112  #include <linux/dnotify.h>
6113 +#include <linux/vs_base.h>
6114 +#include <linux/vs_limit.h>
6115 +#include <linux/vs_tag.h>
6116 +#include <linux/vs_cowbl.h>
6117 +#include <linux/vserver/dlimit.h>
6118  
6119  #include "internal.h"
6120  
6121 @@ -74,6 +79,12 @@ static long do_sys_truncate(const char _
6122         error = user_path(pathname, &path);
6123         if (error)
6124                 goto out;
6125 +
6126 +#ifdef CONFIG_VSERVER_COWBL
6127 +       error = cow_check_and_break(&path);
6128 +       if (error)
6129 +               goto dput_and_out;
6130 +#endif
6131         inode = path.dentry->d_inode;
6132  
6133         /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
6134 @@ -489,6 +500,10 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6135  
6136         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
6137         if (!error) {
6138 +#ifdef CONFIG_VSERVER_COWBL
6139 +               error = cow_check_and_break(&path);
6140 +               if (!error)
6141 +#endif
6142                 error = chmod_common(&path, mode);
6143                 path_put(&path);
6144         }
6145 @@ -509,11 +524,11 @@ static int chown_common(struct path *pat
6146         newattrs.ia_valid =  ATTR_CTIME;
6147         if (user != (uid_t) -1) {
6148                 newattrs.ia_valid |= ATTR_UID;
6149 -               newattrs.ia_uid = user;
6150 +               newattrs.ia_uid = dx_map_uid(user);
6151         }
6152         if (group != (gid_t) -1) {
6153                 newattrs.ia_valid |= ATTR_GID;
6154 -               newattrs.ia_gid = group;
6155 +               newattrs.ia_gid = dx_map_gid(group);
6156         }
6157         if (!S_ISDIR(inode->i_mode))
6158                 newattrs.ia_valid |=
6159 @@ -538,6 +553,10 @@ SYSCALL_DEFINE3(chown, const char __user
6160         error = mnt_want_write(path.mnt);
6161         if (error)
6162                 goto out_release;
6163 +#ifdef CONFIG_VSERVER_COWBL
6164 +       error = cow_check_and_break(&path);
6165 +       if (!error)
6166 +#endif
6167         error = chown_common(&path, user, group);
6168         mnt_drop_write(path.mnt);
6169  out_release:
6170 @@ -565,6 +584,10 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
6171         error = mnt_want_write(path.mnt);
6172         if (error)
6173                 goto out_release;
6174 +#ifdef CONFIG_VSERVER_COWBL
6175 +       error = cow_check_and_break(&path);
6176 +       if (!error)
6177 +#endif
6178         error = chown_common(&path, user, group);
6179         mnt_drop_write(path.mnt);
6180  out_release:
6181 @@ -584,6 +607,10 @@ SYSCALL_DEFINE3(lchown, const char __use
6182         error = mnt_want_write(path.mnt);
6183         if (error)
6184                 goto out_release;
6185 +#ifdef CONFIG_VSERVER_COWBL
6186 +       error = cow_check_and_break(&path);
6187 +       if (!error)
6188 +#endif
6189         error = chown_common(&path, user, group);
6190         mnt_drop_write(path.mnt);
6191  out_release:
6192 @@ -835,6 +862,7 @@ static void __put_unused_fd(struct files
6193         __FD_CLR(fd, fdt->open_fds);
6194         if (fd < files->next_fd)
6195                 files->next_fd = fd;
6196 +       vx_openfd_dec(fd);
6197  }
6198  
6199  void put_unused_fd(unsigned int fd)
6200 diff -NurpP --minimal linux-3.1.6/fs/proc/array.c linux-3.1.6-vs2.3.2.5/fs/proc/array.c
6201 --- linux-3.1.6/fs/proc/array.c 2011-10-24 18:45:27.000000000 +0200
6202 +++ linux-3.1.6-vs2.3.2.5/fs/proc/array.c       2011-10-24 18:53:33.000000000 +0200
6203 @@ -81,6 +81,8 @@
6204  #include <linux/pid_namespace.h>
6205  #include <linux/ptrace.h>
6206  #include <linux/tracehook.h>
6207 +#include <linux/vs_context.h>
6208 +#include <linux/vs_network.h>
6209  
6210  #include <asm/pgtable.h>
6211  #include <asm/processor.h>
6212 @@ -170,6 +172,9 @@ static inline void task_state(struct seq
6213         rcu_read_lock();
6214         ppid = pid_alive(p) ?
6215                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6216 +       if (unlikely(vx_current_initpid(p->pid)))
6217 +               ppid = 0;
6218 +
6219         tpid = 0;
6220         if (pid_alive(p)) {
6221                 struct task_struct *tracer = ptrace_parent(p);
6222 @@ -287,7 +292,7 @@ static inline void task_sig(struct seq_f
6223  }
6224  
6225  static void render_cap_t(struct seq_file *m, const char *header,
6226 -                       kernel_cap_t *a)
6227 +                       struct vx_info *vxi, kernel_cap_t *a)
6228  {
6229         unsigned __capi;
6230  
6231 @@ -312,10 +317,11 @@ static inline void task_cap(struct seq_f
6232         cap_bset        = cred->cap_bset;
6233         rcu_read_unlock();
6234  
6235 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6236 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6237 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6238 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6239 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6240 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6241 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6242 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6243 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6244  }
6245  
6246  static inline void task_context_switch_counts(struct seq_file *m,
6247 @@ -337,6 +343,42 @@ static void task_cpus_allowed(struct seq
6248         seq_putc(m, '\n');
6249  }
6250  
6251 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6252 +                       struct pid *pid, struct task_struct *task)
6253 +{
6254 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6255 +                       "Count:\t%u\n"
6256 +                       "uts:\t%p(%c)\n"
6257 +                       "ipc:\t%p(%c)\n"
6258 +                       "mnt:\t%p(%c)\n"
6259 +                       "pid:\t%p(%c)\n"
6260 +                       "net:\t%p(%c)\n",
6261 +                       task->nsproxy,
6262 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6263 +                       atomic_read(&task->nsproxy->count),
6264 +                       task->nsproxy->uts_ns,
6265 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6266 +                       task->nsproxy->ipc_ns,
6267 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6268 +                       task->nsproxy->mnt_ns,
6269 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6270 +                       task->nsproxy->pid_ns,
6271 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6272 +                       task->nsproxy->net_ns,
6273 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6274 +       return 0;
6275 +}
6276 +
6277 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6278 +{
6279 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6280 +               return;
6281 +
6282 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6283 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6284 +}
6285 +
6286 +
6287  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6288                         struct pid *pid, struct task_struct *task)
6289  {
6290 @@ -353,6 +395,7 @@ int proc_pid_status(struct seq_file *m, 
6291         task_cap(m, task);
6292         task_cpus_allowed(m, task);
6293         cpuset_task_status_allowed(m, task);
6294 +       task_vs_id(m, task);
6295         task_context_switch_counts(m, task);
6296         return 0;
6297  }
6298 @@ -462,6 +505,17 @@ static int do_task_stat(struct seq_file 
6299         /* convert nsec -> ticks */
6300         start_time = nsec_to_clock_t(start_time);
6301  
6302 +       /* fixup start time for virt uptime */
6303 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6304 +               unsigned long long bias =
6305 +                       current->vx_info->cvirt.bias_clock;
6306 +
6307 +               if (start_time > bias)
6308 +                       start_time -= bias;
6309 +               else
6310 +                       start_time = 0;
6311 +       }
6312 +
6313         seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \
6314  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
6315  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
6316 diff -NurpP --minimal linux-3.1.6/fs/proc/base.c linux-3.1.6-vs2.3.2.5/fs/proc/base.c
6317 --- linux-3.1.6/fs/proc/base.c  2011-10-24 18:45:27.000000000 +0200
6318 +++ linux-3.1.6-vs2.3.2.5/fs/proc/base.c        2011-10-24 18:53:33.000000000 +0200
6319 @@ -83,6 +83,8 @@
6320  #include <linux/pid_namespace.h>
6321  #include <linux/fs_struct.h>
6322  #include <linux/slab.h>
6323 +#include <linux/vs_context.h>
6324 +#include <linux/vs_network.h>
6325  #ifdef CONFIG_HARDWALL
6326  #include <asm/hardwall.h>
6327  #endif
6328 @@ -1102,11 +1104,16 @@ static ssize_t oom_adjust_write(struct f
6329                 goto err_task_lock;
6330         }
6331  
6332 -       if (oom_adjust < task->signal->oom_adj && !capable(CAP_SYS_RESOURCE)) {
6333 +       if (oom_adjust < task->signal->oom_adj &&
6334 +               !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6335                 err = -EACCES;
6336                 goto err_sighand;
6337         }
6338  
6339 +       /* prevent guest processes from circumventing the oom killer */
6340 +       if (vx_current_xid() && (oom_adjust == OOM_DISABLE))
6341 +               oom_adjust = OOM_ADJUST_MIN;
6342 +
6343         if (oom_adjust != task->signal->oom_adj) {
6344                 if (oom_adjust == OOM_DISABLE)
6345                         atomic_inc(&task->mm->oom_disable_count);
6346 @@ -1274,7 +1281,7 @@ static ssize_t proc_loginuid_write(struc
6347         ssize_t length;
6348         uid_t loginuid;
6349  
6350 -       if (!capable(CAP_AUDIT_CONTROL))
6351 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
6352                 return -EPERM;
6353  
6354         rcu_read_lock();
6355 @@ -1721,6 +1728,8 @@ struct inode *proc_pid_make_inode(struct
6356                 inode->i_gid = cred->egid;
6357                 rcu_read_unlock();
6358         }
6359 +       /* procfs is xid tagged */
6360 +       inode->i_tag = (tag_t)vx_task_xid(task);
6361         security_task_to_inode(task, inode);
6362  
6363  out:
6364 @@ -1757,6 +1766,8 @@ int pid_getattr(struct vfsmount *mnt, st
6365  
6366  /* dentry stuff */
6367  
6368 +static unsigned name_to_int(struct dentry *dentry);
6369 +
6370  /*
6371   *     Exceptional case: normally we are not allowed to unhash a busy
6372   * directory. In this case, however, we can do it - no aliasing problems
6373 @@ -1785,6 +1796,12 @@ int pid_revalidate(struct dentry *dentry
6374         task = get_proc_task(inode);
6375  
6376         if (task) {
6377 +               unsigned pid = name_to_int(dentry);
6378 +
6379 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6380 +                       put_task_struct(task);
6381 +                       goto drop;
6382 +               }
6383                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6384                     task_dumpable(task)) {
6385                         rcu_read_lock();
6386 @@ -1801,6 +1818,7 @@ int pid_revalidate(struct dentry *dentry
6387                 put_task_struct(task);
6388                 return 1;
6389         }
6390 +drop:
6391         d_drop(dentry);
6392         return 0;
6393  }
6394 @@ -2290,6 +2308,13 @@ static struct dentry *proc_pident_lookup
6395         if (!task)
6396                 goto out_no_task;
6397  
6398 +       /* TODO: maybe we can come up with a generic approach? */
6399 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6400 +               (dentry->d_name.len == 5) &&
6401 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6402 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6403 +               goto out;
6404 +
6405         /*
6406          * Yes, it does not scale. And it should not. Don't add
6407          * new entries into /proc/<tgid>/ without very good reasons.
6408 @@ -2675,7 +2700,7 @@ out_iput:
6409  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
6410  {
6411         struct dentry *error;
6412 -       struct task_struct *task = get_proc_task(dir);
6413 +       struct task_struct *task = get_proc_task_real(dir);
6414         const struct pid_entry *p, *last;
6415  
6416         error = ERR_PTR(-ENOENT);
6417 @@ -2782,6 +2807,9 @@ static int proc_pid_personality(struct s
6418  static const struct file_operations proc_task_operations;
6419  static const struct inode_operations proc_task_inode_operations;
6420  
6421 +extern int proc_pid_vx_info(struct task_struct *, char *);
6422 +extern int proc_pid_nx_info(struct task_struct *, char *);
6423 +
6424  static const struct pid_entry tgid_base_stuff[] = {
6425         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6426         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6427 @@ -2845,6 +2873,8 @@ static const struct pid_entry tgid_base_
6428  #ifdef CONFIG_CGROUPS
6429         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6430  #endif
6431 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6432 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6433         INF("oom_score",  S_IRUGO, proc_oom_score),
6434         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
6435         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6436 @@ -2864,6 +2894,7 @@ static const struct pid_entry tgid_base_
6437  #ifdef CONFIG_HARDWALL
6438         INF("hardwall",   S_IRUGO, proc_pid_hardwall),
6439  #endif
6440 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6441  };
6442  
6443  static int proc_tgid_base_readdir(struct file * filp,
6444 @@ -3056,7 +3087,7 @@ retry:
6445         iter.task = NULL;
6446         pid = find_ge_pid(iter.tgid, ns);
6447         if (pid) {
6448 -               iter.tgid = pid_nr_ns(pid, ns);
6449 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6450                 iter.task = pid_task(pid, PIDTYPE_PID);
6451                 /* What we to know is if the pid we have find is the
6452                  * pid of a thread_group_leader.  Testing for task
6453 @@ -3086,7 +3117,7 @@ static int proc_pid_fill_cache(struct fi
6454         struct tgid_iter iter)
6455  {
6456         char name[PROC_NUMBUF];
6457 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6458 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6459         return proc_fill_cache(filp, dirent, filldir, name, len,
6460                                 proc_pid_instantiate, iter.task, NULL);
6461  }
6462 @@ -3103,7 +3134,7 @@ int proc_pid_readdir(struct file * filp,
6463                 goto out_no_task;
6464         nr = filp->f_pos - FIRST_PROCESS_ENTRY;
6465  
6466 -       reaper = get_proc_task(filp->f_path.dentry->d_inode);
6467 +       reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
6468         if (!reaper)
6469                 goto out_no_task;
6470  
6471 @@ -3120,6 +3151,8 @@ int proc_pid_readdir(struct file * filp,
6472              iter.task;
6473              iter.tgid += 1, iter = next_tgid(ns, iter)) {
6474                 filp->f_pos = iter.tgid + TGID_OFFSET;
6475 +               if (!vx_proc_task_visible(iter.task))
6476 +                       continue;
6477                 if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
6478                         put_task_struct(iter.task);
6479                         goto out;
6480 @@ -3273,6 +3306,8 @@ static struct dentry *proc_task_lookup(s
6481         tid = name_to_int(dentry);
6482         if (tid == ~0U)
6483                 goto out;
6484 +       if (vx_current_initpid(tid))
6485 +               goto out;
6486  
6487         ns = dentry->d_sb->s_fs_info;
6488         rcu_read_lock();
6489 diff -NurpP --minimal linux-3.1.6/fs/proc/generic.c linux-3.1.6-vs2.3.2.5/fs/proc/generic.c
6490 --- linux-3.1.6/fs/proc/generic.c       2011-10-24 18:45:27.000000000 +0200
6491 +++ linux-3.1.6-vs2.3.2.5/fs/proc/generic.c     2011-10-24 18:53:33.000000000 +0200
6492 @@ -22,6 +22,7 @@
6493  #include <linux/bitops.h>
6494  #include <linux/spinlock.h>
6495  #include <linux/completion.h>
6496 +#include <linux/vserver/inode.h>
6497  #include <asm/uaccess.h>
6498  
6499  #include "internal.h"
6500 @@ -424,11 +425,15 @@ struct dentry *proc_lookup_de(struct pro
6501         for (de = de->subdir; de ; de = de->next) {
6502                 if (de->namelen != dentry->d_name.len)
6503                         continue;
6504 +               if (!vx_hide_check(0, de->vx_flags))
6505 +                       continue;
6506                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6507                         pde_get(de);
6508                         spin_unlock(&proc_subdir_lock);
6509                         error = -EINVAL;
6510                         inode = proc_get_inode(dir->i_sb, de);
6511 +                       /* generic proc entries belong to the host */
6512 +                       inode->i_tag = 0;
6513                         goto out_unlock;
6514                 }
6515         }
6516 @@ -506,6 +511,8 @@ int proc_readdir_de(struct proc_dir_entr
6517  
6518                                 /* filldir passes info to user space */
6519                                 pde_get(de);
6520 +                               if (!vx_hide_check(0, de->vx_flags))
6521 +                                       goto skip;
6522                                 spin_unlock(&proc_subdir_lock);
6523                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6524                                             de->low_ino, de->mode >> 12) < 0) {
6525 @@ -513,6 +520,7 @@ int proc_readdir_de(struct proc_dir_entr
6526                                         goto out;
6527                                 }
6528                                 spin_lock(&proc_subdir_lock);
6529 +                       skip:
6530                                 filp->f_pos++;
6531                                 next = de->next;
6532                                 pde_put(de);
6533 @@ -626,6 +634,7 @@ static struct proc_dir_entry *__proc_cre
6534         ent->nlink = nlink;
6535         atomic_set(&ent->count, 1);
6536         ent->pde_users = 0;
6537 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6538         spin_lock_init(&ent->pde_unload_lock);
6539         ent->pde_unload_completion = NULL;
6540         INIT_LIST_HEAD(&ent->pde_openers);
6541 @@ -649,7 +658,8 @@ struct proc_dir_entry *proc_symlink(cons
6542                                 kfree(ent->data);
6543                                 kfree(ent);
6544                                 ent = NULL;
6545 -                       }
6546 +                       } else
6547 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6548                 } else {
6549                         kfree(ent);
6550                         ent = NULL;
6551 diff -NurpP --minimal linux-3.1.6/fs/proc/inode.c linux-3.1.6-vs2.3.2.5/fs/proc/inode.c
6552 --- linux-3.1.6/fs/proc/inode.c 2011-10-24 18:45:27.000000000 +0200
6553 +++ linux-3.1.6-vs2.3.2.5/fs/proc/inode.c       2011-10-24 18:53:33.000000000 +0200
6554 @@ -442,6 +442,8 @@ struct inode *proc_get_inode(struct supe
6555                         inode->i_uid = de->uid;
6556                         inode->i_gid = de->gid;
6557                 }
6558 +               if (de->vx_flags)
6559 +                       PROC_I(inode)->vx_flags = de->vx_flags;
6560                 if (de->size)
6561                         inode->i_size = de->size;
6562                 if (de->nlink)
6563 diff -NurpP --minimal linux-3.1.6/fs/proc/internal.h linux-3.1.6-vs2.3.2.5/fs/proc/internal.h
6564 --- linux-3.1.6/fs/proc/internal.h      2011-07-22 11:18:06.000000000 +0200
6565 +++ linux-3.1.6-vs2.3.2.5/fs/proc/internal.h    2011-10-24 18:53:33.000000000 +0200
6566 @@ -10,6 +10,7 @@
6567   */
6568  
6569  #include <linux/proc_fs.h>
6570 +#include <linux/vs_pid.h>
6571  
6572  extern struct proc_dir_entry proc_root;
6573  #ifdef CONFIG_PROC_SYSCTL
6574 @@ -51,6 +52,9 @@ extern int proc_pid_status(struct seq_fi
6575                                 struct pid *pid, struct task_struct *task);
6576  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
6577                                 struct pid *pid, struct task_struct *task);
6578 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6579 +                               struct pid *pid, struct task_struct *task);
6580 +
6581  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
6582  
6583  extern const struct file_operations proc_maps_operations;
6584 @@ -76,11 +80,16 @@ static inline struct pid *proc_pid(struc
6585         return PROC_I(inode)->pid;
6586  }
6587  
6588 -static inline struct task_struct *get_proc_task(struct inode *inode)
6589 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6590  {
6591         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6592  }
6593  
6594 +static inline struct task_struct *get_proc_task(struct inode *inode)
6595 +{
6596 +       return vx_get_proc_task(inode, proc_pid(inode));
6597 +}
6598 +
6599  static inline int proc_fd(struct inode *inode)
6600  {
6601         return PROC_I(inode)->fd;
6602 diff -NurpP --minimal linux-3.1.6/fs/proc/loadavg.c linux-3.1.6-vs2.3.2.5/fs/proc/loadavg.c
6603 --- linux-3.1.6/fs/proc/loadavg.c       2009-09-10 15:26:23.000000000 +0200
6604 +++ linux-3.1.6-vs2.3.2.5/fs/proc/loadavg.c     2011-10-24 18:53:33.000000000 +0200
6605 @@ -12,15 +12,27 @@
6606  
6607  static int loadavg_proc_show(struct seq_file *m, void *v)
6608  {
6609 +       unsigned long running;
6610 +       unsigned int threads;
6611         unsigned long avnrun[3];
6612  
6613         get_avenrun(avnrun, FIXED_1/200, 0);
6614  
6615 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
6616 +               struct vx_info *vxi = current_vx_info();
6617 +
6618 +               running = atomic_read(&vxi->cvirt.nr_running);
6619 +               threads = atomic_read(&vxi->cvirt.nr_threads);
6620 +       } else {
6621 +               running = nr_running();
6622 +               threads = nr_threads;
6623 +       }
6624 +
6625         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6626                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6627                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6628                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6629 -               nr_running(), nr_threads,
6630 +               running, threads,
6631                 task_active_pid_ns(current)->last_pid);
6632         return 0;
6633  }
6634 diff -NurpP --minimal linux-3.1.6/fs/proc/meminfo.c linux-3.1.6-vs2.3.2.5/fs/proc/meminfo.c
6635 --- linux-3.1.6/fs/proc/meminfo.c       2011-12-23 16:04:07.000000000 +0100
6636 +++ linux-3.1.6-vs2.3.2.5/fs/proc/meminfo.c     2011-12-23 16:11:57.000000000 +0100
6637 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
6638         allowed = ((totalram_pages - hugetlb_total_pages())
6639                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
6640  
6641 -       cached = global_page_state(NR_FILE_PAGES) -
6642 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
6643 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6644                         total_swapcache_pages - i.bufferram;
6645         if (cached < 0)
6646                 cached = 0;
6647 diff -NurpP --minimal linux-3.1.6/fs/proc/root.c linux-3.1.6-vs2.3.2.5/fs/proc/root.c
6648 --- linux-3.1.6/fs/proc/root.c  2011-10-24 18:45:27.000000000 +0200
6649 +++ linux-3.1.6-vs2.3.2.5/fs/proc/root.c        2011-10-24 18:53:33.000000000 +0200
6650 @@ -18,9 +18,14 @@
6651  #include <linux/bitops.h>
6652  #include <linux/mount.h>
6653  #include <linux/pid_namespace.h>
6654 +#include <linux/vserver/inode.h>
6655  
6656  #include "internal.h"
6657  
6658 +struct proc_dir_entry *proc_virtual;
6659 +
6660 +extern void proc_vx_init(void);
6661 +
6662  static int proc_test_super(struct super_block *sb, void *data)
6663  {
6664         return sb->s_fs_info == data;
6665 @@ -125,6 +130,7 @@ void __init proc_root_init(void)
6666  #endif
6667         proc_mkdir("bus", NULL);
6668         proc_sys_init();
6669 +       proc_vx_init();
6670  }
6671  
6672  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6673 @@ -192,6 +198,7 @@ struct proc_dir_entry proc_root = {
6674         .proc_iops      = &proc_root_inode_operations, 
6675         .proc_fops      = &proc_root_operations,
6676         .parent         = &proc_root,
6677 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
6678         .name           = "/proc",
6679  };
6680  
6681 diff -NurpP --minimal linux-3.1.6/fs/proc/uptime.c linux-3.1.6-vs2.3.2.5/fs/proc/uptime.c
6682 --- linux-3.1.6/fs/proc/uptime.c        2009-12-03 20:02:53.000000000 +0100
6683 +++ linux-3.1.6-vs2.3.2.5/fs/proc/uptime.c      2011-10-24 18:53:33.000000000 +0200
6684 @@ -4,22 +4,22 @@
6685  #include <linux/sched.h>
6686  #include <linux/seq_file.h>
6687  #include <linux/time.h>
6688 -#include <linux/kernel_stat.h>
6689 +#include <linux/vserver/cvirt.h>
6690  #include <asm/cputime.h>
6691  
6692  static int uptime_proc_show(struct seq_file *m, void *v)
6693  {
6694         struct timespec uptime;
6695         struct timespec idle;
6696 -       int i;
6697 -       cputime_t idletime = cputime_zero;
6698 -
6699 -       for_each_possible_cpu(i)
6700 -               idletime = cputime64_add(idletime, kstat_cpu(i).cpustat.idle);
6701 +       cputime_t idletime = cputime_add(init_task.utime, init_task.stime);
6702  
6703         do_posix_clock_monotonic_gettime(&uptime);
6704         monotonic_to_bootbased(&uptime);
6705         cputime_to_timespec(idletime, &idle);
6706 +
6707 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6708 +               vx_vsi_uptime(&uptime, &idle);
6709 +
6710         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6711                         (unsigned long) uptime.tv_sec,
6712                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6713 diff -NurpP --minimal linux-3.1.6/fs/quota/dquot.c linux-3.1.6-vs2.3.2.5/fs/quota/dquot.c
6714 --- linux-3.1.6/fs/quota/dquot.c        2011-07-22 11:18:06.000000000 +0200
6715 +++ linux-3.1.6-vs2.3.2.5/fs/quota/dquot.c      2011-10-24 18:53:33.000000000 +0200
6716 @@ -1548,6 +1548,9 @@ int __dquot_alloc_space(struct inode *in
6717         int reserve = flags & DQUOT_SPACE_RESERVE;
6718         int nofail = flags & DQUOT_SPACE_NOFAIL;
6719  
6720 +       if ((ret = dl_alloc_space(inode, number)))
6721 +               return ret;
6722 +
6723         /*
6724          * First test before acquiring mutex - solves deadlocks when we
6725          * re-enter the quota code and are already holding the mutex
6726 @@ -1602,6 +1605,9 @@ int dquot_alloc_inode(const struct inode
6727         int cnt, ret = 0;
6728         char warntype[MAXQUOTAS];
6729  
6730 +       if ((ret = dl_alloc_inode(inode)))
6731 +               return ret;
6732 +
6733         /* First test before acquiring mutex - solves deadlocks when we
6734           * re-enter the quota code and are already holding the mutex */
6735         if (!dquot_active(inode))
6736 @@ -1672,6 +1678,8 @@ void __dquot_free_space(struct inode *in
6737         char warntype[MAXQUOTAS];
6738         int reserve = flags & DQUOT_SPACE_RESERVE;
6739  
6740 +       dl_free_space(inode, number);
6741 +
6742         /* First test before acquiring mutex - solves deadlocks when we
6743           * re-enter the quota code and are already holding the mutex */
6744         if (!dquot_active(inode)) {
6745 @@ -1710,6 +1718,8 @@ void dquot_free_inode(const struct inode
6746         unsigned int cnt;
6747         char warntype[MAXQUOTAS];
6748  
6749 +       dl_free_inode(inode);
6750 +
6751         /* First test before acquiring mutex - solves deadlocks when we
6752           * re-enter the quota code and are already holding the mutex */
6753         if (!dquot_active(inode))
6754 diff -NurpP --minimal linux-3.1.6/fs/quota/quota.c linux-3.1.6-vs2.3.2.5/fs/quota/quota.c
6755 --- linux-3.1.6/fs/quota/quota.c        2011-10-24 18:45:27.000000000 +0200
6756 +++ linux-3.1.6-vs2.3.2.5/fs/quota/quota.c      2011-10-24 18:53:33.000000000 +0200
6757 @@ -8,6 +8,7 @@
6758  #include <linux/fs.h>
6759  #include <linux/namei.h>
6760  #include <linux/slab.h>
6761 +#include <linux/vs_context.h>
6762  #include <asm/current.h>
6763  #include <asm/uaccess.h>
6764  #include <linux/kernel.h>
6765 @@ -38,7 +39,7 @@ static int check_quotactl_permission(str
6766                         break;
6767                 /*FALLTHROUGH*/
6768         default:
6769 -               if (!capable(CAP_SYS_ADMIN))
6770 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6771                         return -EPERM;
6772         }
6773  
6774 @@ -293,6 +294,46 @@ static int do_quotactl(struct super_bloc
6775         }
6776  }
6777  
6778 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6779 +
6780 +#include <linux/vroot.h>
6781 +#include <linux/major.h>
6782 +#include <linux/module.h>
6783 +#include <linux/kallsyms.h>
6784 +#include <linux/vserver/debug.h>
6785 +
6786 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6787 +
6788 +static DEFINE_SPINLOCK(vroot_grb_lock);
6789 +
6790 +int register_vroot_grb(vroot_grb_func *func) {
6791 +       int ret = -EBUSY;
6792 +
6793 +       spin_lock(&vroot_grb_lock);
6794 +       if (!vroot_get_real_bdev) {
6795 +               vroot_get_real_bdev = func;
6796 +               ret = 0;
6797 +       }
6798 +       spin_unlock(&vroot_grb_lock);
6799 +       return ret;
6800 +}
6801 +EXPORT_SYMBOL(register_vroot_grb);
6802 +
6803 +int unregister_vroot_grb(vroot_grb_func *func) {
6804 +       int ret = -EINVAL;
6805 +
6806 +       spin_lock(&vroot_grb_lock);
6807 +       if (vroot_get_real_bdev) {
6808 +               vroot_get_real_bdev = NULL;
6809 +               ret = 0;
6810 +       }
6811 +       spin_unlock(&vroot_grb_lock);
6812 +       return ret;
6813 +}
6814 +EXPORT_SYMBOL(unregister_vroot_grb);
6815 +
6816 +#endif
6817 +
6818  /*
6819   * look up a superblock on which quota ops will be performed
6820   * - use the name of a block device to find the superblock thereon
6821 @@ -310,6 +351,22 @@ static struct super_block *quotactl_bloc
6822         putname(tmp);
6823         if (IS_ERR(bdev))
6824                 return ERR_CAST(bdev);
6825 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6826 +       if (bdev && bdev->bd_inode &&
6827 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
6828 +               struct block_device *bdnew = (void *)-EINVAL;
6829 +
6830 +               if (vroot_get_real_bdev)
6831 +                       bdnew = vroot_get_real_bdev(bdev);
6832 +               else
6833 +                       vxdprintk(VXD_CBIT(misc, 0),
6834 +                                       "vroot_get_real_bdev not set");
6835 +               bdput(bdev);
6836 +               if (IS_ERR(bdnew))
6837 +                       return ERR_PTR(PTR_ERR(bdnew));
6838 +               bdev = bdnew;
6839 +       }
6840 +#endif
6841         sb = get_super(bdev);
6842         bdput(bdev);
6843         if (!sb)
6844 diff -NurpP --minimal linux-3.1.6/fs/reiserfs/file.c linux-3.1.6-vs2.3.2.5/fs/reiserfs/file.c
6845 --- linux-3.1.6/fs/reiserfs/file.c      2011-10-24 18:45:27.000000000 +0200
6846 +++ linux-3.1.6-vs2.3.2.5/fs/reiserfs/file.c    2011-10-24 18:53:33.000000000 +0200
6847 @@ -319,5 +319,6 @@ const struct inode_operations reiserfs_f
6848         .listxattr = reiserfs_listxattr,
6849         .removexattr = reiserfs_removexattr,
6850         .permission = reiserfs_permission,
6851 +       .sync_flags = reiserfs_sync_flags,
6852         .get_acl = reiserfs_get_acl,
6853  };
6854 diff -NurpP --minimal linux-3.1.6/fs/reiserfs/inode.c linux-3.1.6-vs2.3.2.5/fs/reiserfs/inode.c
6855 --- linux-3.1.6/fs/reiserfs/inode.c     2011-10-24 18:45:27.000000000 +0200
6856 +++ linux-3.1.6-vs2.3.2.5/fs/reiserfs/inode.c   2011-10-24 18:53:33.000000000 +0200
6857 @@ -18,6 +18,7 @@
6858  #include <linux/writeback.h>
6859  #include <linux/quotaops.h>
6860  #include <linux/swap.h>
6861 +#include <linux/vs_tag.h>
6862  
6863  int reiserfs_commit_write(struct file *f, struct page *page,
6864                           unsigned from, unsigned to);
6865 @@ -1131,6 +1132,8 @@ static void init_inode(struct inode *ino
6866         struct buffer_head *bh;
6867         struct item_head *ih;
6868         __u32 rdev;
6869 +       uid_t uid;
6870 +       gid_t gid;
6871         //int version = ITEM_VERSION_1;
6872  
6873         bh = PATH_PLAST_BUFFER(path);
6874 @@ -1151,12 +1154,13 @@ static void init_inode(struct inode *ino
6875                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
6876                 unsigned long blocks;
6877  
6878 +               uid = sd_v1_uid(sd);
6879 +               gid = sd_v1_gid(sd);
6880 +
6881                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
6882                 set_inode_sd_version(inode, STAT_DATA_V1);
6883                 inode->i_mode = sd_v1_mode(sd);
6884                 inode->i_nlink = sd_v1_nlink(sd);
6885 -               inode->i_uid = sd_v1_uid(sd);
6886 -               inode->i_gid = sd_v1_gid(sd);
6887                 inode->i_size = sd_v1_size(sd);
6888                 inode->i_atime.tv_sec = sd_v1_atime(sd);
6889                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
6890 @@ -1198,11 +1202,12 @@ static void init_inode(struct inode *ino
6891                 // (directories and symlinks)
6892                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
6893  
6894 +               uid    = sd_v2_uid(sd);
6895 +               gid    = sd_v2_gid(sd);
6896 +
6897                 inode->i_mode = sd_v2_mode(sd);
6898                 inode->i_nlink = sd_v2_nlink(sd);
6899 -               inode->i_uid = sd_v2_uid(sd);
6900                 inode->i_size = sd_v2_size(sd);
6901 -               inode->i_gid = sd_v2_gid(sd);
6902                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
6903                 inode->i_atime.tv_sec = sd_v2_atime(sd);
6904                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
6905 @@ -1232,6 +1237,10 @@ static void init_inode(struct inode *ino
6906                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
6907         }
6908  
6909 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6910 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6911 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
6912 +
6913         pathrelse(path);
6914         if (S_ISREG(inode->i_mode)) {
6915                 inode->i_op = &reiserfs_file_inode_operations;
6916 @@ -1254,13 +1263,15 @@ static void init_inode(struct inode *ino
6917  static void inode2sd(void *sd, struct inode *inode, loff_t size)
6918  {
6919         struct stat_data *sd_v2 = (struct stat_data *)sd;
6920 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
6921 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
6922         __u16 flags;
6923  
6924 +       set_sd_v2_uid(sd_v2, uid);
6925 +       set_sd_v2_gid(sd_v2, gid);
6926         set_sd_v2_mode(sd_v2, inode->i_mode);
6927         set_sd_v2_nlink(sd_v2, inode->i_nlink);
6928 -       set_sd_v2_uid(sd_v2, inode->i_uid);
6929         set_sd_v2_size(sd_v2, size);
6930 -       set_sd_v2_gid(sd_v2, inode->i_gid);
6931         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
6932         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
6933         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
6934 @@ -2868,14 +2879,19 @@ int reiserfs_commit_write(struct file *f
6935  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
6936  {
6937         if (reiserfs_attrs(inode->i_sb)) {
6938 -               if (sd_attrs & REISERFS_SYNC_FL)
6939 -                       inode->i_flags |= S_SYNC;
6940 -               else
6941 -                       inode->i_flags &= ~S_SYNC;
6942                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
6943                         inode->i_flags |= S_IMMUTABLE;
6944                 else
6945                         inode->i_flags &= ~S_IMMUTABLE;
6946 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
6947 +                       inode->i_flags |= S_IXUNLINK;
6948 +               else
6949 +                       inode->i_flags &= ~S_IXUNLINK;
6950 +
6951 +               if (sd_attrs & REISERFS_SYNC_FL)
6952 +                       inode->i_flags |= S_SYNC;
6953 +               else
6954 +                       inode->i_flags &= ~S_SYNC;
6955                 if (sd_attrs & REISERFS_APPEND_FL)
6956                         inode->i_flags |= S_APPEND;
6957                 else
6958 @@ -2888,6 +2904,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
6959                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
6960                 else
6961                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
6962 +
6963 +               if (sd_attrs & REISERFS_BARRIER_FL)
6964 +                       inode->i_vflags |= V_BARRIER;
6965 +               else
6966 +                       inode->i_vflags &= ~V_BARRIER;
6967 +               if (sd_attrs & REISERFS_COW_FL)
6968 +                       inode->i_vflags |= V_COW;
6969 +               else
6970 +                       inode->i_vflags &= ~V_COW;
6971         }
6972  }
6973  
6974 @@ -2898,6 +2923,11 @@ void i_attrs_to_sd_attrs(struct inode *i
6975                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
6976                 else
6977                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
6978 +               if (inode->i_flags & S_IXUNLINK)
6979 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
6980 +               else
6981 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
6982 +
6983                 if (inode->i_flags & S_SYNC)
6984                         *sd_attrs |= REISERFS_SYNC_FL;
6985                 else
6986 @@ -2910,6 +2940,15 @@ void i_attrs_to_sd_attrs(struct inode *i
6987                         *sd_attrs |= REISERFS_NOTAIL_FL;
6988                 else
6989                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
6990 +
6991 +               if (inode->i_vflags & V_BARRIER)
6992 +                       *sd_attrs |= REISERFS_BARRIER_FL;
6993 +               else
6994 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
6995 +               if (inode->i_vflags & V_COW)
6996 +                       *sd_attrs |= REISERFS_COW_FL;
6997 +               else
6998 +                       *sd_attrs &= ~REISERFS_COW_FL;
6999         }
7000  }
7001  
7002 @@ -3155,7 +3194,8 @@ int reiserfs_setattr(struct dentry *dent
7003         }
7004  
7005         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
7006 -           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
7007 +           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
7008 +           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
7009                 struct reiserfs_transaction_handle th;
7010                 int jbegin_count =
7011                     2 *
7012 @@ -3184,6 +3224,9 @@ int reiserfs_setattr(struct dentry *dent
7013                         inode->i_uid = attr->ia_uid;
7014                 if (attr->ia_valid & ATTR_GID)
7015                         inode->i_gid = attr->ia_gid;
7016 +                               if ((attr->ia_valid & ATTR_TAG) &&
7017 +                                       IS_TAGGED(inode))
7018 +                                       inode->i_tag = attr->ia_tag;
7019                 mark_inode_dirty(inode);
7020                 error = journal_end(&th, inode->i_sb, jbegin_count);
7021                 if (error)
7022 diff -NurpP --minimal linux-3.1.6/fs/reiserfs/ioctl.c linux-3.1.6-vs2.3.2.5/fs/reiserfs/ioctl.c
7023 --- linux-3.1.6/fs/reiserfs/ioctl.c     2011-05-22 16:17:53.000000000 +0200
7024 +++ linux-3.1.6-vs2.3.2.5/fs/reiserfs/ioctl.c   2011-10-24 18:53:33.000000000 +0200
7025 @@ -11,6 +11,21 @@
7026  #include <linux/pagemap.h>
7027  #include <linux/compat.h>
7028  
7029 +
7030 +int reiserfs_sync_flags(struct inode *inode, int flags, int vflags)
7031 +{
7032 +       __u16 sd_attrs = 0;
7033 +
7034 +       inode->i_flags = flags;
7035 +       inode->i_vflags = vflags;
7036 +
7037 +       i_attrs_to_sd_attrs(inode, &sd_attrs);
7038 +       REISERFS_I(inode)->i_attrs = sd_attrs;
7039 +       inode->i_ctime = CURRENT_TIME_SEC;
7040 +       mark_inode_dirty(inode);
7041 +       return 0;
7042 +}
7043 +
7044  /*
7045   * reiserfs_ioctl - handler for ioctl for inode
7046   * supported commands:
7047 @@ -22,7 +37,7 @@
7048  long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
7049  {
7050         struct inode *inode = filp->f_path.dentry->d_inode;
7051 -       unsigned int flags;
7052 +       unsigned int flags, oldflags;
7053         int err = 0;
7054  
7055         reiserfs_write_lock(inode->i_sb);
7056 @@ -47,6 +62,7 @@ long reiserfs_ioctl(struct file *filp, u
7057  
7058                 flags = REISERFS_I(inode)->i_attrs;
7059                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
7060 +               flags &= REISERFS_FL_USER_VISIBLE;
7061                 err = put_user(flags, (int __user *)arg);
7062                 break;
7063         case REISERFS_IOC_SETFLAGS:{
7064 @@ -67,6 +83,10 @@ long reiserfs_ioctl(struct file *filp, u
7065                                 err = -EFAULT;
7066                                 goto setflags_out;
7067                         }
7068 +                       if (IS_BARRIER(inode)) {
7069 +                               vxwprintk_task(1, "messing with the barrier.");
7070 +                               return -EACCES;
7071 +                       }
7072                         /*
7073                          * Is it quota file? Do not allow user to mess with it
7074                          */
7075 @@ -91,6 +111,10 @@ long reiserfs_ioctl(struct file *filp, u
7076                                         goto setflags_out;
7077                                 }
7078                         }
7079 +
7080 +                       oldflags = REISERFS_I(inode)->i_attrs;
7081 +                       flags &= REISERFS_FL_USER_MODIFIABLE;
7082 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
7083                         sd_attrs_to_i_attrs(flags, inode);
7084                         REISERFS_I(inode)->i_attrs = flags;
7085                         inode->i_ctime = CURRENT_TIME_SEC;
7086 diff -NurpP --minimal linux-3.1.6/fs/reiserfs/namei.c linux-3.1.6-vs2.3.2.5/fs/reiserfs/namei.c
7087 --- linux-3.1.6/fs/reiserfs/namei.c     2011-10-24 18:45:27.000000000 +0200
7088 +++ linux-3.1.6-vs2.3.2.5/fs/reiserfs/namei.c   2011-10-24 18:53:33.000000000 +0200
7089 @@ -18,6 +18,7 @@
7090  #include <linux/reiserfs_acl.h>
7091  #include <linux/reiserfs_xattr.h>
7092  #include <linux/quotaops.h>
7093 +#include <linux/vs_tag.h>
7094  
7095  #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; }
7096  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
7097 @@ -362,6 +363,7 @@ static struct dentry *reiserfs_lookup(st
7098         if (retval == IO_ERROR) {
7099                 return ERR_PTR(-EIO);
7100         }
7101 +               dx_propagate_tag(nd, inode);
7102  
7103         return d_splice_alias(inode, dentry);
7104  }
7105 diff -NurpP --minimal linux-3.1.6/fs/reiserfs/super.c linux-3.1.6-vs2.3.2.5/fs/reiserfs/super.c
7106 --- linux-3.1.6/fs/reiserfs/super.c     2011-10-24 18:45:27.000000000 +0200
7107 +++ linux-3.1.6-vs2.3.2.5/fs/reiserfs/super.c   2011-10-24 18:53:33.000000000 +0200
7108 @@ -899,6 +899,14 @@ static int reiserfs_parse_options(struct
7109                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
7110                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
7111  #endif
7112 +#ifndef CONFIG_TAGGING_NONE
7113 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
7114 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
7115 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
7116 +#endif
7117 +#ifdef CONFIG_PROPAGATE
7118 +               {"tag",.arg_required = 'T',.values = NULL},
7119 +#endif
7120  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
7121                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
7122                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
7123 @@ -1208,6 +1216,14 @@ static int reiserfs_remount(struct super
7124         handle_quota_files(s, qf_names, &qfmt);
7125  #endif
7126  
7127 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
7128 +               !(s->s_flags & MS_TAGGED)) {
7129 +               reiserfs_warning(s, "super-vs01",
7130 +                       "reiserfs: tagging not permitted on remount.");
7131 +               err = -EINVAL;
7132 +               goto out_err;
7133 +       }
7134 +
7135         handle_attrs(s);
7136  
7137         /* Add options that are safe here */
7138 @@ -1691,6 +1707,10 @@ static int reiserfs_fill_super(struct su
7139                 goto error;
7140         }
7141  
7142 +       /* map mount option tagxid */
7143 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
7144 +               s->s_flags |= MS_TAGGED;
7145 +
7146         rs = SB_DISK_SUPER_BLOCK(s);
7147         /* Let's do basic sanity check to verify that underlying device is not
7148            smaller than the filesystem. If the check fails then abort and scream,
7149 diff -NurpP --minimal linux-3.1.6/fs/reiserfs/xattr.c linux-3.1.6-vs2.3.2.5/fs/reiserfs/xattr.c
7150 --- linux-3.1.6/fs/reiserfs/xattr.c     2011-10-24 18:45:27.000000000 +0200
7151 +++ linux-3.1.6-vs2.3.2.5/fs/reiserfs/xattr.c   2011-10-24 18:53:33.000000000 +0200
7152 @@ -40,6 +40,7 @@
7153  #include <linux/errno.h>
7154  #include <linux/gfp.h>
7155  #include <linux/fs.h>
7156 +#include <linux/mount.h>
7157  #include <linux/file.h>
7158  #include <linux/pagemap.h>
7159  #include <linux/xattr.h>
7160 diff -NurpP --minimal linux-3.1.6/fs/stat.c linux-3.1.6-vs2.3.2.5/fs/stat.c
7161 --- linux-3.1.6/fs/stat.c       2011-12-23 16:04:07.000000000 +0100
7162 +++ linux-3.1.6-vs2.3.2.5/fs/stat.c     2011-11-15 17:08:44.000000000 +0100
7163 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
7164         stat->nlink = inode->i_nlink;
7165         stat->uid = inode->i_uid;
7166         stat->gid = inode->i_gid;
7167 +       stat->tag = inode->i_tag;
7168         stat->rdev = inode->i_rdev;
7169         stat->size = i_size_read(inode);
7170         stat->atime = inode->i_atime;
7171 diff -NurpP --minimal linux-3.1.6/fs/statfs.c linux-3.1.6-vs2.3.2.5/fs/statfs.c
7172 --- linux-3.1.6/fs/statfs.c     2011-12-23 16:04:07.000000000 +0100
7173 +++ linux-3.1.6-vs2.3.2.5/fs/statfs.c   2011-11-15 17:08:44.000000000 +0100
7174 @@ -7,6 +7,8 @@
7175  #include <linux/statfs.h>
7176  #include <linux/security.h>
7177  #include <linux/uaccess.h>
7178 +#include <linux/vs_base.h>
7179 +#include <linux/vs_dlimit.h>
7180  
7181  static int flags_by_mnt(int mnt_flags)
7182  {
7183 @@ -59,6 +61,8 @@ int statfs_by_dentry(struct dentry *dent
7184         retval = dentry->d_sb->s_op->statfs(dentry, buf);
7185         if (retval == 0 && buf->f_frsize == 0)
7186                 buf->f_frsize = buf->f_bsize;
7187 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
7188 +               vx_vsi_statfs(dentry->d_sb, buf);
7189         return retval;
7190  }
7191  
7192 diff -NurpP --minimal linux-3.1.6/fs/super.c linux-3.1.6-vs2.3.2.5/fs/super.c
7193 --- linux-3.1.6/fs/super.c      2011-12-23 16:04:07.000000000 +0100
7194 +++ linux-3.1.6-vs2.3.2.5/fs/super.c    2011-11-29 12:53:17.000000000 +0100
7195 @@ -32,6 +32,9 @@
7196  #include <linux/backing-dev.h>
7197  #include <linux/rculist_bl.h>
7198  #include <linux/cleancache.h>
7199 +#include <linux/devpts_fs.h>
7200 +#include <linux/proc_fs.h>
7201 +#include <linux/vs_context.h>
7202  #include "internal.h"
7203  
7204  
7205 @@ -1095,6 +1098,13 @@ mount_fs(struct file_system_type *type, 
7206         WARN_ON(sb->s_bdi == &default_backing_dev_info);
7207         sb->s_flags |= MS_BORN;
7208  
7209 +       error = -EPERM;
7210 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
7211 +               !sb->s_bdev &&
7212 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
7213 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
7214 +               goto out_sb;
7215 +
7216         error = security_sb_kern_mount(sb, flags, secdata);
7217         if (error)
7218                 goto out_sb;
7219 diff -NurpP --minimal linux-3.1.6/fs/sysfs/mount.c linux-3.1.6-vs2.3.2.5/fs/sysfs/mount.c
7220 --- linux-3.1.6/fs/sysfs/mount.c        2011-07-22 11:18:06.000000000 +0200
7221 +++ linux-3.1.6-vs2.3.2.5/fs/sysfs/mount.c      2011-10-24 18:53:33.000000000 +0200
7222 @@ -47,7 +47,7 @@ static int sysfs_fill_super(struct super
7223  
7224         sb->s_blocksize = PAGE_CACHE_SIZE;
7225         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
7226 -       sb->s_magic = SYSFS_MAGIC;
7227 +       sb->s_magic = SYSFS_SUPER_MAGIC;
7228         sb->s_op = &sysfs_ops;
7229         sb->s_time_gran = 1;
7230  
7231 diff -NurpP --minimal linux-3.1.6/fs/utimes.c linux-3.1.6-vs2.3.2.5/fs/utimes.c
7232 --- linux-3.1.6/fs/utimes.c     2011-05-22 16:17:54.000000000 +0200
7233 +++ linux-3.1.6-vs2.3.2.5/fs/utimes.c   2011-10-24 18:53:33.000000000 +0200
7234 @@ -8,6 +8,8 @@
7235  #include <linux/stat.h>
7236  #include <linux/utime.h>
7237  #include <linux/syscalls.h>
7238 +#include <linux/mount.h>
7239 +#include <linux/vs_cowbl.h>
7240  #include <asm/uaccess.h>
7241  #include <asm/unistd.h>
7242  
7243 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
7244  {
7245         int error;
7246         struct iattr newattrs;
7247 -       struct inode *inode = path->dentry->d_inode;
7248 +       struct inode *inode;
7249  
7250         error = mnt_want_write(path->mnt);
7251         if (error)
7252                 goto out;
7253  
7254 +       error = cow_check_and_break(path);
7255 +       if (error)
7256 +               goto mnt_drop_write_and_out;
7257 +
7258 +       inode = path->dentry->d_inode;
7259 +
7260         if (times && times[0].tv_nsec == UTIME_NOW &&
7261                      times[1].tv_nsec == UTIME_NOW)
7262                 times = NULL;
7263 diff -NurpP --minimal linux-3.1.6/fs/xattr.c linux-3.1.6-vs2.3.2.5/fs/xattr.c
7264 --- linux-3.1.6/fs/xattr.c      2011-07-22 11:18:09.000000000 +0200
7265 +++ linux-3.1.6-vs2.3.2.5/fs/xattr.c    2011-10-24 18:53:33.000000000 +0200
7266 @@ -18,6 +18,7 @@
7267  #include <linux/module.h>
7268  #include <linux/fsnotify.h>
7269  #include <linux/audit.h>
7270 +#include <linux/mount.h>
7271  #include <asm/uaccess.h>
7272  
7273  
7274 @@ -49,7 +50,7 @@ xattr_permission(struct inode *inode, co
7275          * The trusted.* namespace can only be accessed by privileged users.
7276          */
7277         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
7278 -               if (!capable(CAP_SYS_ADMIN))
7279 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
7280                         return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
7281                 return 0;
7282         }
7283 diff -NurpP --minimal linux-3.1.6/fs/xfs/xfs_dinode.h linux-3.1.6-vs2.3.2.5/fs/xfs/xfs_dinode.h
7284 --- linux-3.1.6/fs/xfs/xfs_dinode.h     2011-10-24 18:45:31.000000000 +0200
7285 +++ linux-3.1.6-vs2.3.2.5/fs/xfs/xfs_dinode.h   2011-10-24 18:53:33.000000000 +0200
7286 @@ -51,7 +51,9 @@ typedef struct xfs_dinode {
7287         __be32          di_nlink;       /* number of links to file */
7288         __be16          di_projid_lo;   /* lower part of owner's project id */
7289         __be16          di_projid_hi;   /* higher part owner's project id */
7290 -       __u8            di_pad[6];      /* unused, zeroed space */
7291 +       __u8            di_pad[2];      /* unused, zeroed space */
7292 +       __be16          di_tag;         /* context tagging */
7293 +       __be16          di_vflags;      /* vserver specific flags */
7294         __be16          di_flushiter;   /* incremented on flush */
7295         xfs_timestamp_t di_atime;       /* time last accessed */
7296         xfs_timestamp_t di_mtime;       /* time last modified */
7297 @@ -184,6 +186,8 @@ static inline void xfs_dinode_put_rdev(s
7298  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
7299  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
7300  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
7301 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
7302 +
7303  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
7304  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
7305  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
7306 @@ -199,6 +203,7 @@ static inline void xfs_dinode_put_rdev(s
7307  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
7308  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
7309  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
7310 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
7311  
7312  #ifdef CONFIG_XFS_RT
7313  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
7314 @@ -211,6 +216,10 @@ static inline void xfs_dinode_put_rdev(s
7315          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
7316          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
7317          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
7318 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
7319 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
7320 +        XFS_DIFLAG_IXUNLINK)
7321 +
7322 +#define XFS_DIVFLAG_BARRIER    0x01
7323 +#define XFS_DIVFLAG_COW                0x02
7324  
7325  #endif /* __XFS_DINODE_H__ */
7326 diff -NurpP --minimal linux-3.1.6/fs/xfs/xfs_fs.h linux-3.1.6-vs2.3.2.5/fs/xfs/xfs_fs.h
7327 --- linux-3.1.6/fs/xfs/xfs_fs.h 2011-10-24 18:45:31.000000000 +0200
7328 +++ linux-3.1.6-vs2.3.2.5/fs/xfs/xfs_fs.h       2011-10-24 18:53:33.000000000 +0200
7329 @@ -67,6 +67,9 @@ struct fsxattr {
7330  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
7331  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
7332  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
7333 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
7334 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
7335 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
7336  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
7337  
7338  /*
7339 @@ -302,7 +305,8 @@ typedef struct xfs_bstat {
7340  #define        bs_projid       bs_projid_lo    /* (previously just bs_projid)  */
7341         __u16           bs_forkoff;     /* inode fork offset in bytes   */
7342         __u16           bs_projid_hi;   /* higher part of project id    */
7343 -       unsigned char   bs_pad[10];     /* pad space, unused            */
7344 +       unsigned char   bs_pad[8];      /* pad space, unused            */
7345 +       __u16           bs_tag;         /* context tagging              */
7346         __u32           bs_dmevmask;    /* DMIG event mask              */
7347         __u16           bs_dmstate;     /* DMIG state info              */
7348         __u16           bs_aextents;    /* attribute number of extents  */
7349 diff -NurpP --minimal linux-3.1.6/fs/xfs/xfs_ialloc.c linux-3.1.6-vs2.3.2.5/fs/xfs/xfs_ialloc.c
7350 --- linux-3.1.6/fs/xfs/xfs_ialloc.c     2011-10-24 18:45:31.000000000 +0200
7351 +++ linux-3.1.6-vs2.3.2.5/fs/xfs/xfs_ialloc.c   2011-10-24 18:53:33.000000000 +0200
7352 @@ -37,7 +37,6 @@
7353  #include "xfs_error.h"
7354  #include "xfs_bmap.h"
7355  
7356 -
7357  /*
7358   * Allocation group level functions.
7359   */
7360 diff -NurpP --minimal linux-3.1.6/fs/xfs/xfs_inode.c linux-3.1.6-vs2.3.2.5/fs/xfs/xfs_inode.c
7361 --- linux-3.1.6/fs/xfs/xfs_inode.c      2011-10-24 18:45:31.000000000 +0200
7362 +++ linux-3.1.6-vs2.3.2.5/fs/xfs/xfs_inode.c    2011-10-24 18:53:33.000000000 +0200
7363 @@ -242,6 +242,7 @@ xfs_inotobp(
7364         return 0;
7365  }
7366  
7367 +#include <linux/vs_tag.h>
7368  
7369  /*
7370   * This routine is called to map an inode to the buffer containing
7371 @@ -640,15 +641,25 @@ xfs_iformat_btree(
7372  STATIC void
7373  xfs_dinode_from_disk(
7374         xfs_icdinode_t          *to,
7375 -       xfs_dinode_t            *from)
7376 +       xfs_dinode_t            *from,
7377 +       int tagged)
7378  {
7379 +       uint32_t uid, gid, tag;
7380 +
7381         to->di_magic = be16_to_cpu(from->di_magic);
7382         to->di_mode = be16_to_cpu(from->di_mode);
7383         to->di_version = from ->di_version;
7384         to->di_format = from->di_format;
7385         to->di_onlink = be16_to_cpu(from->di_onlink);
7386 -       to->di_uid = be32_to_cpu(from->di_uid);
7387 -       to->di_gid = be32_to_cpu(from->di_gid);
7388 +
7389 +       uid = be32_to_cpu(from->di_uid);
7390 +       gid = be32_to_cpu(from->di_gid);
7391 +       tag = be16_to_cpu(from->di_tag);
7392 +
7393 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
7394 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
7395 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
7396 +
7397         to->di_nlink = be32_to_cpu(from->di_nlink);
7398         to->di_projid_lo = be16_to_cpu(from->di_projid_lo);
7399         to->di_projid_hi = be16_to_cpu(from->di_projid_hi);
7400 @@ -670,21 +681,26 @@ xfs_dinode_from_disk(
7401         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
7402         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
7403         to->di_flags    = be16_to_cpu(from->di_flags);
7404 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
7405         to->di_gen      = be32_to_cpu(from->di_gen);
7406  }
7407  
7408  void
7409  xfs_dinode_to_disk(
7410         xfs_dinode_t            *to,
7411 -       xfs_icdinode_t          *from)
7412 +       xfs_icdinode_t          *from,
7413 +       int tagged)
7414  {
7415         to->di_magic = cpu_to_be16(from->di_magic);
7416         to->di_mode = cpu_to_be16(from->di_mode);
7417         to->di_version = from ->di_version;
7418         to->di_format = from->di_format;
7419         to->di_onlink = cpu_to_be16(from->di_onlink);
7420 -       to->di_uid = cpu_to_be32(from->di_uid);
7421 -       to->di_gid = cpu_to_be32(from->di_gid);
7422 +
7423 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
7424 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
7425 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
7426 +
7427         to->di_nlink = cpu_to_be32(from->di_nlink);
7428         to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
7429         to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
7430 @@ -706,12 +722,14 @@ xfs_dinode_to_disk(
7431         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
7432         to->di_dmstate = cpu_to_be16(from->di_dmstate);
7433         to->di_flags = cpu_to_be16(from->di_flags);
7434 +       to->di_vflags = cpu_to_be16(from->di_vflags);
7435         to->di_gen = cpu_to_be32(from->di_gen);
7436  }
7437  
7438  STATIC uint
7439  _xfs_dic2xflags(
7440 -       __uint16_t              di_flags)
7441 +       __uint16_t              di_flags,
7442 +       __uint16_t              di_vflags)
7443  {
7444         uint                    flags = 0;
7445  
7446 @@ -722,6 +740,8 @@ _xfs_dic2xflags(
7447                         flags |= XFS_XFLAG_PREALLOC;
7448                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
7449                         flags |= XFS_XFLAG_IMMUTABLE;
7450 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
7451 +                       flags |= XFS_XFLAG_IXUNLINK;
7452                 if (di_flags & XFS_DIFLAG_APPEND)
7453                         flags |= XFS_XFLAG_APPEND;
7454                 if (di_flags & XFS_DIFLAG_SYNC)
7455 @@ -746,6 +766,10 @@ _xfs_dic2xflags(
7456                         flags |= XFS_XFLAG_FILESTREAM;
7457         }
7458  
7459 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
7460 +               flags |= FS_BARRIER_FL;
7461 +       if (di_vflags & XFS_DIVFLAG_COW)
7462 +               flags |= FS_COW_FL;
7463         return flags;
7464  }
7465  
7466 @@ -755,7 +779,7 @@ xfs_ip2xflags(
7467  {
7468         xfs_icdinode_t          *dic = &ip->i_d;
7469  
7470 -       return _xfs_dic2xflags(dic->di_flags) |
7471 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
7472                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
7473  }
7474  
7475 @@ -763,7 +787,8 @@ uint
7476  xfs_dic2xflags(
7477         xfs_dinode_t            *dip)
7478  {
7479 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
7480 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
7481 +                               be16_to_cpu(dip->di_vflags)) |
7482                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
7483  }
7484  
7485 @@ -796,7 +821,6 @@ xfs_iread(
7486         if (error)
7487                 return error;
7488         dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);
7489 -
7490         /*
7491          * If we got something that isn't an inode it means someone
7492          * (nfs or dmi) has a stale handle.
7493 @@ -819,7 +843,8 @@ xfs_iread(
7494          * Otherwise, just get the truly permanent information.
7495          */
7496         if (dip->di_mode) {
7497 -               xfs_dinode_from_disk(&ip->i_d, dip);
7498 +               xfs_dinode_from_disk(&ip->i_d, dip,
7499 +                       mp->m_flags & XFS_MOUNT_TAGGED);
7500                 error = xfs_iformat(ip, dip);
7501                 if (error)  {
7502  #ifdef DEBUG
7503 @@ -1014,6 +1039,7 @@ xfs_ialloc(
7504         ASSERT(ip->i_d.di_nlink == nlink);
7505         ip->i_d.di_uid = current_fsuid();
7506         ip->i_d.di_gid = current_fsgid();
7507 +       ip->i_d.di_tag = current_fstag(&ip->i_vnode);
7508         xfs_set_projid(ip, prid);
7509         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
7510  
7511 @@ -1074,6 +1100,7 @@ xfs_ialloc(
7512         ip->i_d.di_dmevmask = 0;
7513         ip->i_d.di_dmstate = 0;
7514         ip->i_d.di_flags = 0;
7515 +       ip->i_d.di_vflags = 0;
7516         flags = XFS_ILOG_CORE;
7517         switch (mode & S_IFMT) {
7518         case S_IFIFO:
7519 @@ -1845,6 +1872,7 @@ xfs_ifree(
7520         }
7521         ip->i_d.di_mode = 0;            /* mark incore inode as free */
7522         ip->i_d.di_flags = 0;
7523 +       ip->i_d.di_vflags = 0;
7524         ip->i_d.di_dmevmask = 0;
7525         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
7526         ip->i_df.if_ext_max =
7527 @@ -2724,7 +2752,8 @@ xfs_iflush_int(
7528          * because if the inode is dirty at all the core must
7529          * be.
7530          */
7531 -       xfs_dinode_to_disk(dip, &ip->i_d);
7532 +       xfs_dinode_to_disk(dip, &ip->i_d,
7533 +               mp->m_flags & XFS_MOUNT_TAGGED);
7534  
7535         /* Wrap, we never let the log put out DI_MAX_FLUSH */
7536         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
7537 diff -NurpP --minimal linux-3.1.6/fs/xfs/xfs_inode.h linux-3.1.6-vs2.3.2.5/fs/xfs/xfs_inode.h
7538 --- linux-3.1.6/fs/xfs/xfs_inode.h      2011-10-24 18:45:31.000000000 +0200
7539 +++ linux-3.1.6-vs2.3.2.5/fs/xfs/xfs_inode.h    2011-10-24 18:53:33.000000000 +0200
7540 @@ -135,7 +135,9 @@ typedef struct xfs_icdinode {
7541         __uint32_t      di_nlink;       /* number of links to file */
7542         __uint16_t      di_projid_lo;   /* lower part of owner's project id */
7543         __uint16_t      di_projid_hi;   /* higher part of owner's project id */
7544 -       __uint8_t       di_pad[6];      /* unused, zeroed space */
7545 +       __uint8_t       di_pad[2];      /* unused, zeroed space */
7546 +       __uint16_t      di_tag;         /* context tagging */
7547 +       __uint16_t      di_vflags;      /* vserver specific flags */
7548         __uint16_t      di_flushiter;   /* incremented on flush */
7549         xfs_ictimestamp_t di_atime;     /* time last accessed */
7550         xfs_ictimestamp_t di_mtime;     /* time last modified */
7551 @@ -536,7 +538,7 @@ int         xfs_itobp(struct xfs_mount *, struc
7552  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
7553                           struct xfs_inode *, uint);
7554  void           xfs_dinode_to_disk(struct xfs_dinode *,
7555 -                                  struct xfs_icdinode *);
7556 +                                  struct xfs_icdinode *, int);
7557  void           xfs_idestroy_fork(struct xfs_inode *, int);
7558  void           xfs_idata_realloc(struct xfs_inode *, int, int);
7559  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
7560 diff -NurpP --minimal linux-3.1.6/fs/xfs/xfs_ioctl.c linux-3.1.6-vs2.3.2.5/fs/xfs/xfs_ioctl.c
7561 --- linux-3.1.6/fs/xfs/xfs_ioctl.c      2011-10-24 18:45:31.000000000 +0200
7562 +++ linux-3.1.6-vs2.3.2.5/fs/xfs/xfs_ioctl.c    2011-10-24 18:53:33.000000000 +0200
7563 @@ -28,7 +28,7 @@
7564  #include "xfs_bmap_btree.h"
7565  #include "xfs_dinode.h"
7566  #include "xfs_inode.h"
7567 -#include "xfs_ioctl.h"
7568 +// #include "xfs_ioctl.h"
7569  #include "xfs_rtalloc.h"
7570  #include "xfs_itable.h"
7571  #include "xfs_error.h"
7572 @@ -748,6 +748,10 @@ xfs_merge_ioc_xflags(
7573                 xflags |= XFS_XFLAG_IMMUTABLE;
7574         else
7575                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7576 +       if (flags & FS_IXUNLINK_FL)
7577 +               xflags |= XFS_XFLAG_IXUNLINK;
7578 +       else
7579 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7580         if (flags & FS_APPEND_FL)
7581                 xflags |= XFS_XFLAG_APPEND;
7582         else
7583 @@ -776,6 +780,8 @@ xfs_di2lxflags(
7584  
7585         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7586                 flags |= FS_IMMUTABLE_FL;
7587 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7588 +               flags |= FS_IXUNLINK_FL;
7589         if (di_flags & XFS_DIFLAG_APPEND)
7590                 flags |= FS_APPEND_FL;
7591         if (di_flags & XFS_DIFLAG_SYNC)
7592 @@ -836,6 +842,8 @@ xfs_set_diflags(
7593         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7594         if (xflags & XFS_XFLAG_IMMUTABLE)
7595                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7596 +       if (xflags & XFS_XFLAG_IXUNLINK)
7597 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7598         if (xflags & XFS_XFLAG_APPEND)
7599                 di_flags |= XFS_DIFLAG_APPEND;
7600         if (xflags & XFS_XFLAG_SYNC)
7601 @@ -878,6 +886,10 @@ xfs_diflags_to_linux(
7602                 inode->i_flags |= S_IMMUTABLE;
7603         else
7604                 inode->i_flags &= ~S_IMMUTABLE;
7605 +       if (xflags & XFS_XFLAG_IXUNLINK)
7606 +               inode->i_flags |= S_IXUNLINK;
7607 +       else
7608 +               inode->i_flags &= ~S_IXUNLINK;
7609         if (xflags & XFS_XFLAG_APPEND)
7610                 inode->i_flags |= S_APPEND;
7611         else
7612 @@ -1370,10 +1382,18 @@ xfs_file_ioctl(
7613         case XFS_IOC_FSGETXATTRA:
7614                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7615         case XFS_IOC_FSSETXATTR:
7616 +               if (IS_BARRIER(inode)) {
7617 +                       vxwprintk_task(1, "messing with the barrier.");
7618 +                       return -XFS_ERROR(EACCES);
7619 +               }
7620                 return xfs_ioc_fssetxattr(ip, filp, arg);
7621         case XFS_IOC_GETXFLAGS:
7622                 return xfs_ioc_getxflags(ip, arg);
7623         case XFS_IOC_SETXFLAGS:
7624 +               if (IS_BARRIER(inode)) {
7625 +                       vxwprintk_task(1, "messing with the barrier.");
7626 +                       return -XFS_ERROR(EACCES);
7627 +               }
7628                 return xfs_ioc_setxflags(ip, filp, arg);
7629  
7630         case XFS_IOC_FSSETDM: {
7631 diff -NurpP --minimal linux-3.1.6/fs/xfs/xfs_ioctl.h linux-3.1.6-vs2.3.2.5/fs/xfs/xfs_ioctl.h
7632 --- linux-3.1.6/fs/xfs/xfs_ioctl.h      2011-10-24 18:45:31.000000000 +0200
7633 +++ linux-3.1.6-vs2.3.2.5/fs/xfs/xfs_ioctl.h    2011-10-24 18:53:33.000000000 +0200
7634 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7635         void __user             *uhandle,
7636         u32                     hlen);
7637  
7638 +extern int
7639 +xfs_sync_flags(
7640 +       struct inode            *inode,
7641 +       int                     flags,
7642 +       int                     vflags);
7643 +
7644  extern long
7645  xfs_file_ioctl(
7646         struct file             *filp,
7647 diff -NurpP --minimal linux-3.1.6/fs/xfs/xfs_iops.c linux-3.1.6-vs2.3.2.5/fs/xfs/xfs_iops.c
7648 --- linux-3.1.6/fs/xfs/xfs_iops.c       2011-12-23 16:04:07.000000000 +0100
7649 +++ linux-3.1.6-vs2.3.2.5/fs/xfs/xfs_iops.c     2011-12-15 01:07:58.000000000 +0100
7650 @@ -30,6 +30,7 @@
7651  #include "xfs_bmap_btree.h"
7652  #include "xfs_dinode.h"
7653  #include "xfs_inode.h"
7654 +#include "xfs_ioctl.h"
7655  #include "xfs_bmap.h"
7656  #include "xfs_rtalloc.h"
7657  #include "xfs_error.h"
7658 @@ -49,6 +50,7 @@
7659  #include <linux/security.h>
7660  #include <linux/fiemap.h>
7661  #include <linux/slab.h>
7662 +#include <linux/vs_tag.h>
7663  
7664  /*
7665   * Bring the timestamps in the XFS inode uptodate.
7666 @@ -473,6 +475,7 @@ xfs_vn_getattr(
7667         stat->nlink = ip->i_d.di_nlink;
7668         stat->uid = ip->i_d.di_uid;
7669         stat->gid = ip->i_d.di_gid;
7670 +       stat->tag = ip->i_d.di_tag;
7671         stat->ino = ip->i_ino;
7672         stat->atime = inode->i_atime;
7673         stat->mtime = inode->i_mtime;
7674 @@ -1038,6 +1041,7 @@ static const struct inode_operations xfs
7675         .removexattr            = generic_removexattr,
7676         .listxattr              = xfs_vn_listxattr,
7677         .fiemap                 = xfs_vn_fiemap,
7678 +       .sync_flags             = xfs_sync_flags,
7679  };
7680  
7681  static const struct inode_operations xfs_dir_inode_operations = {
7682 @@ -1063,6 +1067,7 @@ static const struct inode_operations xfs
7683         .getxattr               = generic_getxattr,
7684         .removexattr            = generic_removexattr,
7685         .listxattr              = xfs_vn_listxattr,
7686 +       .sync_flags             = xfs_sync_flags,
7687  };
7688  
7689  static const struct inode_operations xfs_dir_ci_inode_operations = {
7690 @@ -1112,6 +1117,10 @@ xfs_diflags_to_iflags(
7691                 inode->i_flags |= S_IMMUTABLE;
7692         else
7693                 inode->i_flags &= ~S_IMMUTABLE;
7694 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7695 +               inode->i_flags |= S_IXUNLINK;
7696 +       else
7697 +               inode->i_flags &= ~S_IXUNLINK;
7698         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7699                 inode->i_flags |= S_APPEND;
7700         else
7701 @@ -1124,6 +1133,15 @@ xfs_diflags_to_iflags(
7702                 inode->i_flags |= S_NOATIME;
7703         else
7704                 inode->i_flags &= ~S_NOATIME;
7705 +
7706 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7707 +               inode->i_vflags |= V_BARRIER;
7708 +       else
7709 +               inode->i_vflags &= ~V_BARRIER;
7710 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7711 +               inode->i_vflags |= V_COW;
7712 +       else
7713 +               inode->i_vflags &= ~V_COW;
7714  }
7715  
7716  /*
7717 @@ -1155,6 +1173,7 @@ xfs_setup_inode(
7718         inode->i_nlink  = ip->i_d.di_nlink;
7719         inode->i_uid    = ip->i_d.di_uid;
7720         inode->i_gid    = ip->i_d.di_gid;
7721 +       inode->i_tag    = ip->i_d.di_tag;
7722  
7723         switch (inode->i_mode & S_IFMT) {
7724         case S_IFBLK:
7725 diff -NurpP --minimal linux-3.1.6/fs/xfs/xfs_itable.c linux-3.1.6-vs2.3.2.5/fs/xfs/xfs_itable.c
7726 --- linux-3.1.6/fs/xfs/xfs_itable.c     2011-05-22 16:17:54.000000000 +0200
7727 +++ linux-3.1.6-vs2.3.2.5/fs/xfs/xfs_itable.c   2011-10-24 18:53:33.000000000 +0200
7728 @@ -98,6 +98,7 @@ xfs_bulkstat_one_int(
7729         buf->bs_mode = dic->di_mode;
7730         buf->bs_uid = dic->di_uid;
7731         buf->bs_gid = dic->di_gid;
7732 +       buf->bs_tag = dic->di_tag;
7733         buf->bs_size = dic->di_size;
7734  
7735         /*
7736 diff -NurpP --minimal linux-3.1.6/fs/xfs/xfs_linux.h linux-3.1.6-vs2.3.2.5/fs/xfs/xfs_linux.h
7737 --- linux-3.1.6/fs/xfs/xfs_linux.h      2011-10-24 18:45:31.000000000 +0200
7738 +++ linux-3.1.6-vs2.3.2.5/fs/xfs/xfs_linux.h    2011-10-24 18:53:33.000000000 +0200
7739 @@ -121,6 +121,7 @@
7740  
7741  #define current_cpu()          (raw_smp_processor_id())
7742  #define current_pid()          (current->pid)
7743 +#define current_fstag(vp)      (dx_current_fstag((vp)->i_sb))
7744  #define current_test_flags(f)  (current->flags & (f))
7745  #define current_set_flags_nested(sp, f)                \
7746                 (*(sp) = current->flags, current->flags |= (f))
7747 diff -NurpP --minimal linux-3.1.6/fs/xfs/xfs_log_recover.c linux-3.1.6-vs2.3.2.5/fs/xfs/xfs_log_recover.c
7748 --- linux-3.1.6/fs/xfs/xfs_log_recover.c        2011-10-24 18:45:31.000000000 +0200
7749 +++ linux-3.1.6-vs2.3.2.5/fs/xfs/xfs_log_recover.c      2011-10-24 18:53:33.000000000 +0200
7750 @@ -2347,7 +2347,8 @@ xlog_recover_inode_pass2(
7751         }
7752  
7753         /* The core is in in-core format */
7754 -       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr);
7755 +       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr,
7756 +               mp->m_flags & XFS_MOUNT_TAGGED);
7757  
7758         /* the rest is in on-disk format */
7759         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
7760 diff -NurpP --minimal linux-3.1.6/fs/xfs/xfs_mount.h linux-3.1.6-vs2.3.2.5/fs/xfs/xfs_mount.h
7761 --- linux-3.1.6/fs/xfs/xfs_mount.h      2011-10-24 18:45:31.000000000 +0200
7762 +++ linux-3.1.6-vs2.3.2.5/fs/xfs/xfs_mount.h    2011-10-24 18:53:33.000000000 +0200
7763 @@ -249,6 +249,7 @@ typedef struct xfs_mount {
7764                                                    allocator */
7765  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
7766  
7767 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
7768  
7769  /*
7770   * Default minimum read and write sizes.
7771 diff -NurpP --minimal linux-3.1.6/fs/xfs/xfs_super.c linux-3.1.6-vs2.3.2.5/fs/xfs/xfs_super.c
7772 --- linux-3.1.6/fs/xfs/xfs_super.c      2011-10-24 18:45:31.000000000 +0200
7773 +++ linux-3.1.6-vs2.3.2.5/fs/xfs/xfs_super.c    2011-10-24 18:53:33.000000000 +0200
7774 @@ -113,6 +113,9 @@ mempool_t *xfs_ioend_pool;
7775  #define MNTOPT_NODELAYLOG  "nodelaylog"        /* Delayed logging disabled */
7776  #define MNTOPT_DISCARD    "discard"    /* Discard unused blocks */
7777  #define MNTOPT_NODISCARD   "nodiscard" /* Do not discard unused blocks */
7778 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
7779 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
7780 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
7781  
7782  /*
7783   * Table driven mount option parser.
7784 @@ -121,10 +124,14 @@ mempool_t *xfs_ioend_pool;
7785   * in the future, too.
7786   */
7787  enum {
7788 +       Opt_tag, Opt_notag,
7789         Opt_barrier, Opt_nobarrier, Opt_err
7790  };
7791  
7792  static const match_table_t tokens = {
7793 +       {Opt_tag, "tagxid"},
7794 +       {Opt_tag, "tag"},
7795 +       {Opt_notag, "notag"},
7796         {Opt_barrier, "barrier"},
7797         {Opt_nobarrier, "nobarrier"},
7798         {Opt_err, NULL}
7799 @@ -374,6 +381,19 @@ xfs_parseargs(
7800                 } else if (!strcmp(this_char, "irixsgid")) {
7801                         xfs_warn(mp,
7802         "irixsgid is now a sysctl(2) variable, option is deprecated.");
7803 +#ifndef CONFIG_TAGGING_NONE
7804 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7805 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7806 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7807 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
7808 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7809 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7810 +#endif
7811 +#ifdef CONFIG_PROPAGATE
7812 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7813 +                       /* use value */
7814 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7815 +#endif
7816                 } else {
7817                         xfs_warn(mp, "unknown mount option [%s].", this_char);
7818                         return EINVAL;
7819 @@ -1162,6 +1182,16 @@ xfs_fs_remount(
7820                 case Opt_nobarrier:
7821                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
7822                         break;
7823 +               case Opt_tag:
7824 +                       if (!(sb->s_flags & MS_TAGGED)) {
7825 +                               printk(KERN_INFO
7826 +                                       "XFS: %s: tagging not permitted on remount.\n",
7827 +                                       sb->s_id);
7828 +                               return -EINVAL;
7829 +                       }
7830 +                       break;
7831 +               case Opt_notag:
7832 +                       break;
7833                 default:
7834                         /*
7835                          * Logically we would return an error here to prevent
7836 @@ -1377,6 +1407,9 @@ xfs_fs_fill_super(
7837         if (error)
7838                 goto out_free_sb;
7839  
7840 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
7841 +               sb->s_flags |= MS_TAGGED;
7842 +
7843         /*
7844          * we must configure the block size in the superblock before we run the
7845          * full mount process as the mount process can lookup and cache inodes.
7846 diff -NurpP --minimal linux-3.1.6/fs/xfs/xfs_vnodeops.c linux-3.1.6-vs2.3.2.5/fs/xfs/xfs_vnodeops.c
7847 --- linux-3.1.6/fs/xfs/xfs_vnodeops.c   2011-12-23 16:04:07.000000000 +0100
7848 +++ linux-3.1.6-vs2.3.2.5/fs/xfs/xfs_vnodeops.c 2011-12-15 01:07:58.000000000 +0100
7849 @@ -107,6 +107,78 @@ xfs_readlink_bmap(
7850         return error;
7851  }
7852  
7853 +
7854 +STATIC void
7855 +xfs_get_inode_flags(
7856 +       xfs_inode_t     *ip)
7857 +{
7858 +       struct inode    *inode = VFS_I(ip);
7859 +       unsigned int    flags = inode->i_flags;
7860 +       unsigned int    vflags = inode->i_vflags;
7861 +
7862 +       if (flags & S_IMMUTABLE)
7863 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
7864 +       else
7865 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
7866 +       if (flags & S_IXUNLINK)
7867 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
7868 +       else
7869 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
7870 +
7871 +       if (vflags & V_BARRIER)
7872 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
7873 +       else
7874 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
7875 +       if (vflags & V_COW)
7876 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
7877 +       else
7878 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
7879 +}
7880 +
7881 +int
7882 +xfs_sync_flags(
7883 +       struct inode            *inode,
7884 +       int                     flags,
7885 +       int                     vflags)
7886 +{
7887 +       struct xfs_inode        *ip = XFS_I(inode);
7888 +       struct xfs_mount        *mp = ip->i_mount;
7889 +       struct xfs_trans        *tp;
7890 +       unsigned int            lock_flags = 0;
7891 +       int                     code;
7892 +
7893 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
7894 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
7895 +       if (code)
7896 +               goto error_out;
7897 +
7898 +       xfs_ilock(ip, XFS_ILOCK_EXCL);
7899 +
7900 +       xfs_trans_ijoin(tp, ip);
7901 +
7902 +       inode->i_flags = flags;
7903 +       inode->i_vflags = vflags;
7904 +       xfs_get_inode_flags(ip);
7905 +
7906 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
7907 +       xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
7908 +
7909 +       XFS_STATS_INC(xs_ig_attrchg);
7910 +
7911 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
7912 +               xfs_trans_set_sync(tp);
7913 +       code = xfs_trans_commit(tp, 0);
7914 +       xfs_iunlock(ip, XFS_ILOCK_EXCL);
7915 +       return code;
7916 +
7917 +error_out:
7918 +       xfs_trans_cancel(tp, 0);
7919 +       if (lock_flags)
7920 +               xfs_iunlock(ip, XFS_ILOCK_EXCL);
7921 +       return code;
7922 +}
7923 +
7924 +
7925  int
7926  xfs_readlink(
7927         xfs_inode_t     *ip,
7928 diff -NurpP --minimal linux-3.1.6/include/linux/Kbuild linux-3.1.6-vs2.3.2.5/include/linux/Kbuild
7929 --- linux-3.1.6/include/linux/Kbuild    2011-10-24 18:45:31.000000000 +0200
7930 +++ linux-3.1.6-vs2.3.2.5/include/linux/Kbuild  2011-10-24 18:53:33.000000000 +0200
7931 @@ -17,6 +17,7 @@ header-y += netfilter_bridge/
7932  header-y += netfilter_ipv4/
7933  header-y += netfilter_ipv6/
7934  header-y += usb/
7935 +header-y += vserver/
7936  header-y += wimax/
7937  
7938  objhdr-y += version.h
7939 diff -NurpP --minimal linux-3.1.6/include/linux/capability.h linux-3.1.6-vs2.3.2.5/include/linux/capability.h
7940 --- linux-3.1.6/include/linux/capability.h      2011-07-22 11:18:10.000000000 +0200
7941 +++ linux-3.1.6-vs2.3.2.5/include/linux/capability.h    2011-10-24 18:53:33.000000000 +0200
7942 @@ -279,6 +279,7 @@ struct cpu_vfs_cap_data {
7943     arbitrary SCSI commands */
7944  /* Allow setting encryption key on loopback filesystem */
7945  /* Allow setting zone reclaim policy */
7946 +/* Allow the selection of a security context */
7947  
7948  #define CAP_SYS_ADMIN        21
7949  
7950 @@ -362,7 +363,12 @@ struct cpu_vfs_cap_data {
7951  
7952  #define CAP_LAST_CAP         CAP_WAKE_ALARM
7953  
7954 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
7955 +/* Allow context manipulations */
7956 +/* Allow changing context info on files */
7957 +
7958 +#define CAP_CONTEXT         63
7959 +
7960 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
7961  
7962  /*
7963   * Bit location of each capability (used by user-space library and kernel)
7964 diff -NurpP --minimal linux-3.1.6/include/linux/cred.h linux-3.1.6-vs2.3.2.5/include/linux/cred.h
7965 --- linux-3.1.6/include/linux/cred.h    2011-10-24 18:45:31.000000000 +0200
7966 +++ linux-3.1.6-vs2.3.2.5/include/linux/cred.h  2011-10-24 18:53:33.000000000 +0200
7967 @@ -156,6 +156,7 @@ extern void exit_creds(struct task_struc
7968  extern int copy_creds(struct task_struct *, unsigned long);
7969  extern const struct cred *get_task_cred(struct task_struct *);
7970  extern struct cred *cred_alloc_blank(void);
7971 +extern struct cred *__prepare_creds(const struct cred *);
7972  extern struct cred *prepare_creds(void);
7973  extern struct cred *prepare_exec_creds(void);
7974  extern int commit_creds(struct cred *);
7975 @@ -209,6 +210,31 @@ static inline void validate_process_cred
7976  }
7977  #endif
7978  
7979 +static inline void set_cred_subscribers(struct cred *cred, int n)
7980 +{
7981 +#ifdef CONFIG_DEBUG_CREDENTIALS
7982 +       atomic_set(&cred->subscribers, n);
7983 +#endif
7984 +}
7985 +
7986 +static inline int read_cred_subscribers(const struct cred *cred)
7987 +{
7988 +#ifdef CONFIG_DEBUG_CREDENTIALS
7989 +       return atomic_read(&cred->subscribers);
7990 +#else
7991 +       return 0;
7992 +#endif
7993 +}
7994 +
7995 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
7996 +{
7997 +#ifdef CONFIG_DEBUG_CREDENTIALS
7998 +       struct cred *cred = (struct cred *) _cred;
7999 +
8000 +       atomic_add(n, &cred->subscribers);
8001 +#endif
8002 +}
8003 +
8004  /**
8005   * get_new_cred - Get a reference on a new set of credentials
8006   * @cred: The new credentials to reference
8007 diff -NurpP --minimal linux-3.1.6/include/linux/devpts_fs.h linux-3.1.6-vs2.3.2.5/include/linux/devpts_fs.h
8008 --- linux-3.1.6/include/linux/devpts_fs.h       2008-12-25 00:26:37.000000000 +0100
8009 +++ linux-3.1.6-vs2.3.2.5/include/linux/devpts_fs.h     2011-10-24 18:53:33.000000000 +0200
8010 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
8011  
8012  #endif
8013  
8014 -
8015  #endif /* _LINUX_DEVPTS_FS_H */
8016 diff -NurpP --minimal linux-3.1.6/include/linux/ext2_fs.h linux-3.1.6-vs2.3.2.5/include/linux/ext2_fs.h
8017 --- linux-3.1.6/include/linux/ext2_fs.h 2011-12-23 16:04:07.000000000 +0100
8018 +++ linux-3.1.6-vs2.3.2.5/include/linux/ext2_fs.h       2011-11-15 17:08:44.000000000 +0100
8019 @@ -190,8 +190,12 @@ struct ext2_group_desc
8020  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
8021  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
8022  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
8023 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
8024  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
8025  
8026 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
8027 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
8028 +
8029  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
8030  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
8031  
8032 @@ -275,7 +279,8 @@ struct ext2_inode {
8033                         __u16   i_pad1;
8034                         __le16  l_i_uid_high;   /* these 2 fields    */
8035                         __le16  l_i_gid_high;   /* were reserved2[0] */
8036 -                       __u32   l_i_reserved2;
8037 +                       __le16  l_i_tag;        /* Context Tag */
8038 +                       __u16   l_i_reserved2;
8039                 } linux2;
8040                 struct {
8041                         __u8    h_i_frag;       /* Fragment number */
8042 @@ -304,6 +309,7 @@ struct ext2_inode {
8043  #define i_gid_low      i_gid
8044  #define i_uid_high     osd2.linux2.l_i_uid_high
8045  #define i_gid_high     osd2.linux2.l_i_gid_high
8046 +#define i_raw_tag      osd2.linux2.l_i_tag
8047  #define i_reserved2    osd2.linux2.l_i_reserved2
8048  #endif
8049  
8050 @@ -348,6 +354,7 @@ struct ext2_inode {
8051  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
8052  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
8053  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
8054 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
8055  
8056  
8057  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
8058 diff -NurpP --minimal linux-3.1.6/include/linux/ext3_fs.h linux-3.1.6-vs2.3.2.5/include/linux/ext3_fs.h
8059 --- linux-3.1.6/include/linux/ext3_fs.h 2011-12-23 16:04:07.000000000 +0100
8060 +++ linux-3.1.6-vs2.3.2.5/include/linux/ext3_fs.h       2011-11-15 17:08:44.000000000 +0100
8061 @@ -173,10 +173,14 @@ struct ext3_group_desc
8062  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
8063  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
8064  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
8065 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
8066  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
8067  
8068 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
8069 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
8070 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
8071 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
8072 +
8073 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
8074 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
8075  
8076  /* Flags that should be inherited by new inodes from their parent. */
8077  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
8078 @@ -312,7 +316,8 @@ struct ext3_inode {
8079                         __u16   i_pad1;
8080                         __le16  l_i_uid_high;   /* these 2 fields    */
8081                         __le16  l_i_gid_high;   /* were reserved2[0] */
8082 -                       __u32   l_i_reserved2;
8083 +                       __le16  l_i_tag;        /* Context Tag */
8084 +                       __u16   l_i_reserved2;
8085                 } linux2;
8086                 struct {
8087                         __u8    h_i_frag;       /* Fragment number */
8088 @@ -343,6 +348,7 @@ struct ext3_inode {
8089  #define i_gid_low      i_gid
8090  #define i_uid_high     osd2.linux2.l_i_uid_high
8091  #define i_gid_high     osd2.linux2.l_i_gid_high
8092 +#define i_raw_tag      osd2.linux2.l_i_tag
8093  #define i_reserved2    osd2.linux2.l_i_reserved2
8094  
8095  #elif defined(__GNU__)
8096 @@ -405,6 +411,7 @@ struct ext3_inode {
8097  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
8098  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
8099                                                   * error in ordered mode */
8100 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
8101  
8102  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
8103  #ifndef _LINUX_EXT2_FS_H
8104 @@ -918,6 +925,7 @@ extern void ext3_get_inode_flags(struct 
8105  extern void ext3_set_aops(struct inode *inode);
8106  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
8107                        u64 start, u64 len);
8108 +extern int ext3_sync_flags(struct inode *, int, int);
8109  
8110  /* ioctl.c */
8111  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
8112 diff -NurpP --minimal linux-3.1.6/include/linux/fs.h linux-3.1.6-vs2.3.2.5/include/linux/fs.h
8113 --- linux-3.1.6/include/linux/fs.h      2011-12-23 16:04:07.000000000 +0100
8114 +++ linux-3.1.6-vs2.3.2.5/include/linux/fs.h    2011-12-23 16:11:57.000000000 +0100
8115 @@ -209,6 +209,9 @@ struct inodes_stat_t {
8116  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
8117  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
8118  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
8119 +#define MS_TAGGED      (1<<25) /* use generic inode tagging */
8120 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
8121 +#define MS_NOTAGCHECK  (1<<27) /* don't check tags */
8122  #define MS_NOSEC       (1<<28)
8123  #define MS_BORN                (1<<29)
8124  #define MS_ACTIVE      (1<<30)
8125 @@ -240,6 +243,14 @@ struct inodes_stat_t {
8126  #define S_IMA          1024    /* Inode has an associated IMA struct */
8127  #define S_AUTOMOUNT    2048    /* Automount/referral quasi-directory */
8128  #define S_NOSEC                4096    /* no suid or xattr security attributes */
8129 +#define S_IXUNLINK     8192    /* Immutable Invert on unlink */
8130 +
8131 +/* Linux-VServer related Inode flags */
8132 +
8133 +#define V_VALID                1
8134 +#define V_XATTR                2
8135 +#define V_BARRIER      4       /* Barrier for chroot() */
8136 +#define V_COW          8       /* Copy on Write */
8137  
8138  /*
8139   * Note that nosuid etc flags are inode-specific: setting some file-system
8140 @@ -262,12 +273,15 @@ struct inodes_stat_t {
8141  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
8142                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
8143  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
8144 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8145 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
8146 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8147 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
8148 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
8149  
8150  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
8151  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
8152  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
8153 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
8154 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
8155  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
8156  
8157  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
8158 @@ -278,6 +292,16 @@ struct inodes_stat_t {
8159  #define IS_AUTOMOUNT(inode)    ((inode)->i_flags & S_AUTOMOUNT)
8160  #define IS_NOSEC(inode)                ((inode)->i_flags & S_NOSEC)
8161  
8162 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
8163 +
8164 +#ifdef CONFIG_VSERVER_COWBL
8165 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
8166 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
8167 +#else
8168 +#  define IS_COW(inode)                (0)
8169 +#  define IS_COW_LINK(inode)   (0)
8170 +#endif
8171 +
8172  /* the read-only stuff doesn't really belong here, but any other place is
8173     probably as bad and I don't want to create yet another include file. */
8174  
8175 @@ -363,11 +387,14 @@ struct inodes_stat_t {
8176  #define FS_EXTENT_FL                   0x00080000 /* Extents */
8177  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
8178  #define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
8179 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
8180  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
8181  
8182 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
8183 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
8184 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
8185 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
8186  
8187 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
8188 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
8189  
8190  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
8191  #define SYNC_FILE_RANGE_WRITE          2
8192 @@ -448,6 +475,7 @@ typedef void (dio_iodone_t)(struct kiocb
8193  #define ATTR_KILL_PRIV (1 << 14)
8194  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
8195  #define ATTR_TIMES_SET (1 << 16)
8196 +#define ATTR_TAG       (1 << 17)
8197  
8198  /*
8199   * This is the Inode Attributes structure, used for notify_change().  It
8200 @@ -463,6 +491,7 @@ struct iattr {
8201         umode_t         ia_mode;
8202         uid_t           ia_uid;
8203         gid_t           ia_gid;
8204 +       tag_t           ia_tag;
8205         loff_t          ia_size;
8206         struct timespec ia_atime;
8207         struct timespec ia_mtime;
8208 @@ -476,6 +505,9 @@ struct iattr {
8209         struct file     *ia_file;
8210  };
8211  
8212 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
8213 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
8214 +
8215  /*
8216   * Includes for diskquotas.
8217   */
8218 @@ -750,7 +782,9 @@ struct inode {
8219         unsigned short          i_opflags;
8220         uid_t                   i_uid;
8221         gid_t                   i_gid;
8222 -       unsigned int            i_flags;
8223 +       tag_t                   i_tag;
8224 +       unsigned short          i_flags;
8225 +       unsigned short          i_vflags;
8226  
8227  #ifdef CONFIG_FS_POSIX_ACL
8228         struct posix_acl        *i_acl;
8229 @@ -769,6 +803,7 @@ struct inode {
8230         unsigned long           i_ino;
8231         unsigned int            i_nlink;
8232         dev_t                   i_rdev;
8233 +       dev_t                   i_mdev;
8234         loff_t                  i_size;
8235         struct timespec         i_atime;
8236         struct timespec         i_mtime;
8237 @@ -906,12 +941,12 @@ static inline void i_size_write(struct i
8238  
8239  static inline unsigned iminor(const struct inode *inode)
8240  {
8241 -       return MINOR(inode->i_rdev);
8242 +       return MINOR(inode->i_mdev);
8243  }
8244  
8245  static inline unsigned imajor(const struct inode *inode)
8246  {
8247 -       return MAJOR(inode->i_rdev);
8248 +       return MAJOR(inode->i_mdev);
8249  }
8250  
8251  extern struct block_device *I_BDEV(struct inode *inode);
8252 @@ -973,6 +1008,7 @@ struct file {
8253         loff_t                  f_pos;
8254         struct fown_struct      f_owner;
8255         const struct cred       *f_cred;
8256 +       xid_t                   f_xid;
8257         struct file_ra_state    f_ra;
8258  
8259         u64                     f_version;
8260 @@ -1117,6 +1153,7 @@ struct file_lock {
8261         struct file *fl_file;
8262         loff_t fl_start;
8263         loff_t fl_end;
8264 +       xid_t fl_xid;
8265  
8266         struct fasync_struct *  fl_fasync; /* for lease break notifications */
8267         unsigned long fl_break_time;    /* for nonblocking lease breaks */
8268 @@ -1615,6 +1652,7 @@ struct inode_operations {
8269         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
8270         ssize_t (*listxattr) (struct dentry *, char *, size_t);
8271         int (*removexattr) (struct dentry *, const char *);
8272 +       int (*sync_flags) (struct inode *, int, int);
8273         void (*truncate_range)(struct inode *, loff_t, loff_t);
8274         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
8275                       u64 len);
8276 @@ -1633,6 +1671,7 @@ extern ssize_t vfs_readv(struct file *, 
8277                 unsigned long, loff_t *);
8278  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
8279                 unsigned long, loff_t *);
8280 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
8281  
8282  struct super_operations {
8283         struct inode *(*alloc_inode)(struct super_block *sb);
8284 @@ -2506,6 +2545,7 @@ extern int dcache_dir_open(struct inode 
8285  extern int dcache_dir_close(struct inode *, struct file *);
8286  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
8287  extern int dcache_readdir(struct file *, void *, filldir_t);
8288 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
8289  extern int simple_setattr(struct dentry *, struct iattr *);
8290  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
8291  extern int simple_statfs(struct dentry *, struct kstatfs *);
8292 diff -NurpP --minimal linux-3.1.6/include/linux/gfs2_ondisk.h linux-3.1.6-vs2.3.2.5/include/linux/gfs2_ondisk.h
8293 --- linux-3.1.6/include/linux/gfs2_ondisk.h     2010-07-07 18:31:55.000000000 +0200
8294 +++ linux-3.1.6-vs2.3.2.5/include/linux/gfs2_ondisk.h   2011-10-24 18:53:33.000000000 +0200
8295 @@ -211,6 +211,9 @@ enum {
8296         gfs2fl_NoAtime          = 7,
8297         gfs2fl_Sync             = 8,
8298         gfs2fl_System           = 9,
8299 +       gfs2fl_IXUnlink         = 16,
8300 +       gfs2fl_Barrier          = 17,
8301 +       gfs2fl_Cow              = 18,
8302         gfs2fl_TruncInProg      = 29,
8303         gfs2fl_InheritDirectio  = 30,
8304         gfs2fl_InheritJdata     = 31,
8305 @@ -227,6 +230,9 @@ enum {
8306  #define GFS2_DIF_NOATIME               0x00000080
8307  #define GFS2_DIF_SYNC                  0x00000100
8308  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
8309 +#define GFS2_DIF_IXUNLINK              0x00010000
8310 +#define GFS2_DIF_BARRIER               0x00020000
8311 +#define GFS2_DIF_COW                   0x00040000
8312  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
8313  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000
8314  #define GFS2_DIF_INHERIT_JDATA         0x80000000
8315 diff -NurpP --minimal linux-3.1.6/include/linux/if_tun.h linux-3.1.6-vs2.3.2.5/include/linux/if_tun.h
8316 --- linux-3.1.6/include/linux/if_tun.h  2010-08-02 16:52:54.000000000 +0200
8317 +++ linux-3.1.6-vs2.3.2.5/include/linux/if_tun.h        2011-10-24 18:53:33.000000000 +0200
8318 @@ -53,6 +53,7 @@
8319  #define TUNDETACHFILTER _IOW('T', 214, struct sock_fprog)
8320  #define TUNGETVNETHDRSZ _IOR('T', 215, int)
8321  #define TUNSETVNETHDRSZ _IOW('T', 216, int)
8322 +#define TUNSETNID     _IOW('T', 217, int)
8323  
8324  /* TUNSETIFF ifr flags */
8325  #define IFF_TUN                0x0001
8326 diff -NurpP --minimal linux-3.1.6/include/linux/init_task.h linux-3.1.6-vs2.3.2.5/include/linux/init_task.h
8327 --- linux-3.1.6/include/linux/init_task.h       2011-10-24 18:45:32.000000000 +0200
8328 +++ linux-3.1.6-vs2.3.2.5/include/linux/init_task.h     2011-10-24 18:53:33.000000000 +0200
8329 @@ -192,6 +192,10 @@ extern struct cred init_cred;
8330         INIT_FTRACE_GRAPH                                               \
8331         INIT_TRACE_RECURSION                                            \
8332         INIT_TASK_RCU_PREEMPT(tsk)                                      \
8333 +       .xid            = 0,                                            \
8334 +       .vx_info        = NULL,                                         \
8335 +       .nid            = 0,                                            \
8336 +       .nx_info        = NULL,                                         \
8337  }
8338  
8339  
8340 diff -NurpP --minimal linux-3.1.6/include/linux/ipc.h linux-3.1.6-vs2.3.2.5/include/linux/ipc.h
8341 --- linux-3.1.6/include/linux/ipc.h     2009-12-03 20:02:55.000000000 +0100
8342 +++ linux-3.1.6-vs2.3.2.5/include/linux/ipc.h   2011-10-24 18:53:33.000000000 +0200
8343 @@ -91,6 +91,7 @@ struct kern_ipc_perm
8344         key_t           key;
8345         uid_t           uid;
8346         gid_t           gid;
8347 +       xid_t           xid;
8348         uid_t           cuid;
8349         gid_t           cgid;
8350         mode_t          mode; 
8351 diff -NurpP --minimal linux-3.1.6/include/linux/ipc_namespace.h linux-3.1.6-vs2.3.2.5/include/linux/ipc_namespace.h
8352 --- linux-3.1.6/include/linux/ipc_namespace.h   2011-10-24 18:45:32.000000000 +0200
8353 +++ linux-3.1.6-vs2.3.2.5/include/linux/ipc_namespace.h 2011-10-24 18:53:33.000000000 +0200
8354 @@ -101,7 +101,8 @@ static inline int mq_init_ns(struct ipc_
8355  
8356  #if defined(CONFIG_IPC_NS)
8357  extern struct ipc_namespace *copy_ipcs(unsigned long flags,
8358 -                                      struct task_struct *tsk);
8359 +                                      struct ipc_namespace *old_ns,
8360 +                                      struct user_namespace *user_ns);
8361  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
8362  {
8363         if (ns)
8364 @@ -112,12 +113,13 @@ static inline struct ipc_namespace *get_
8365  extern void put_ipc_ns(struct ipc_namespace *ns);
8366  #else
8367  static inline struct ipc_namespace *copy_ipcs(unsigned long flags,
8368 -                                             struct task_struct *tsk)
8369 +                                             struct ipc_namespace *old_ns,
8370 +                                             struct user_namespace *user_ns)
8371  {
8372         if (flags & CLONE_NEWIPC)
8373                 return ERR_PTR(-EINVAL);
8374  
8375 -       return tsk->nsproxy->ipc_ns;
8376 +       return old_ns;
8377  }
8378  
8379  static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
8380 diff -NurpP --minimal linux-3.1.6/include/linux/loop.h linux-3.1.6-vs2.3.2.5/include/linux/loop.h
8381 --- linux-3.1.6/include/linux/loop.h    2011-10-24 18:45:32.000000000 +0200
8382 +++ linux-3.1.6-vs2.3.2.5/include/linux/loop.h  2011-10-24 18:53:33.000000000 +0200
8383 @@ -45,6 +45,7 @@ struct loop_device {
8384         struct loop_func_table *lo_encryption;
8385         __u32           lo_init[2];
8386         uid_t           lo_key_owner;   /* Who set the key */
8387 +       xid_t           lo_xid;
8388         int             (*ioctl)(struct loop_device *, int cmd, 
8389                                  unsigned long arg); 
8390  
8391 diff -NurpP --minimal linux-3.1.6/include/linux/magic.h linux-3.1.6-vs2.3.2.5/include/linux/magic.h
8392 --- linux-3.1.6/include/linux/magic.h   2011-05-22 16:17:55.000000000 +0200
8393 +++ linux-3.1.6-vs2.3.2.5/include/linux/magic.h 2011-10-24 18:53:33.000000000 +0200
8394 @@ -3,7 +3,7 @@
8395  
8396  #define ADFS_SUPER_MAGIC       0xadf5
8397  #define AFFS_SUPER_MAGIC       0xadff
8398 -#define AFS_SUPER_MAGIC                0x5346414F
8399 +#define AFS_SUPER_MAGIC                0x5346414F
8400  #define AUTOFS_SUPER_MAGIC     0x0187
8401  #define CODA_SUPER_MAGIC       0x73757245
8402  #define CRAMFS_MAGIC           0x28cd3d45      /* some random number */
8403 @@ -41,6 +41,7 @@
8404  #define NFS_SUPER_MAGIC                0x6969
8405  #define OPENPROM_SUPER_MAGIC   0x9fa1
8406  #define PROC_SUPER_MAGIC       0x9fa0
8407 +#define DEVPTS_SUPER_MAGIC     0x1cd1
8408  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
8409  
8410  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
8411 diff -NurpP --minimal linux-3.1.6/include/linux/major.h linux-3.1.6-vs2.3.2.5/include/linux/major.h
8412 --- linux-3.1.6/include/linux/major.h   2009-09-10 15:26:25.000000000 +0200
8413 +++ linux-3.1.6-vs2.3.2.5/include/linux/major.h 2011-10-24 18:53:33.000000000 +0200
8414 @@ -15,6 +15,7 @@
8415  #define HD_MAJOR               IDE0_MAJOR
8416  #define PTY_SLAVE_MAJOR                3
8417  #define TTY_MAJOR              4
8418 +#define VROOT_MAJOR            4
8419  #define TTYAUX_MAJOR           5
8420  #define LP_MAJOR               6
8421  #define VCS_MAJOR              7
8422 diff -NurpP --minimal linux-3.1.6/include/linux/memcontrol.h linux-3.1.6-vs2.3.2.5/include/linux/memcontrol.h
8423 --- linux-3.1.6/include/linux/memcontrol.h      2011-10-24 18:45:32.000000000 +0200
8424 +++ linux-3.1.6-vs2.3.2.5/include/linux/memcontrol.h    2011-10-24 18:53:33.000000000 +0200
8425 @@ -84,6 +84,13 @@ extern struct mem_cgroup *try_get_mem_cg
8426  extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
8427  extern struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm);
8428  
8429 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
8430 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
8431 +
8432 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
8433 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
8434 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
8435 +
8436  static inline
8437  int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
8438  {
8439 diff -NurpP --minimal linux-3.1.6/include/linux/mm_types.h linux-3.1.6-vs2.3.2.5/include/linux/mm_types.h
8440 --- linux-3.1.6/include/linux/mm_types.h        2011-12-23 16:04:07.000000000 +0100
8441 +++ linux-3.1.6-vs2.3.2.5/include/linux/mm_types.h      2011-11-15 17:08:44.000000000 +0100
8442 @@ -314,6 +314,7 @@ struct mm_struct {
8443  
8444         /* Architecture-specific MM context */
8445         mm_context_t context;
8446 +       struct vx_info *mm_vx_info;
8447  
8448         /* Swap token stuff */
8449         /*
8450 diff -NurpP --minimal linux-3.1.6/include/linux/mmzone.h linux-3.1.6-vs2.3.2.5/include/linux/mmzone.h
8451 --- linux-3.1.6/include/linux/mmzone.h  2011-10-24 18:45:32.000000000 +0200
8452 +++ linux-3.1.6-vs2.3.2.5/include/linux/mmzone.h        2011-10-24 18:53:33.000000000 +0200
8453 @@ -660,6 +660,13 @@ typedef struct pglist_data {
8454         __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
8455  })
8456  
8457 +#define node_start_pfn(nid)    (NODE_DATA(nid)->node_start_pfn)
8458 +
8459 +#define node_end_pfn(nid) ({\
8460 +       pg_data_t *__pgdat = NODE_DATA(nid);\
8461 +       __pgdat->node_start_pfn + __pgdat->node_spanned_pages;\
8462 +})
8463 +
8464  #include <linux/memory_hotplug.h>
8465  
8466  extern struct mutex zonelists_mutex;
8467 diff -NurpP --minimal linux-3.1.6/include/linux/mount.h linux-3.1.6-vs2.3.2.5/include/linux/mount.h
8468 --- linux-3.1.6/include/linux/mount.h   2011-10-24 18:45:32.000000000 +0200
8469 +++ linux-3.1.6-vs2.3.2.5/include/linux/mount.h 2011-10-24 18:53:33.000000000 +0200
8470 @@ -52,6 +52,9 @@ struct mnt_pcp {
8471         int mnt_writers;
8472  };
8473  
8474 +#define MNT_TAGID      0x10000
8475 +#define MNT_NOTAG      0x20000
8476 +
8477  struct vfsmount {
8478         struct list_head mnt_hash;
8479         struct vfsmount *mnt_parent;    /* fs we are mounted on */
8480 @@ -86,6 +89,7 @@ struct vfsmount {
8481         int mnt_expiry_mark;            /* true if marked for expiry */
8482         int mnt_pinned;
8483         int mnt_ghosts;
8484 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
8485  };
8486  
8487  struct file; /* forward dec */
8488 diff -NurpP --minimal linux-3.1.6/include/linux/net.h linux-3.1.6-vs2.3.2.5/include/linux/net.h
8489 --- linux-3.1.6/include/linux/net.h     2011-07-22 11:18:11.000000000 +0200
8490 +++ linux-3.1.6-vs2.3.2.5/include/linux/net.h   2011-10-24 18:53:33.000000000 +0200
8491 @@ -72,6 +72,7 @@ struct net;
8492  #define SOCK_NOSPACE           2
8493  #define SOCK_PASSCRED          3
8494  #define SOCK_PASSSEC           4
8495 +#define SOCK_USER_SOCKET       5
8496  
8497  #ifndef ARCH_HAS_SOCKET_TYPES
8498  /**
8499 diff -NurpP --minimal linux-3.1.6/include/linux/netdevice.h linux-3.1.6-vs2.3.2.5/include/linux/netdevice.h
8500 --- linux-3.1.6/include/linux/netdevice.h       2011-10-24 18:45:32.000000000 +0200
8501 +++ linux-3.1.6-vs2.3.2.5/include/linux/netdevice.h     2011-10-24 18:53:33.000000000 +0200
8502 @@ -1641,6 +1641,7 @@ extern void               netdev_resync_ops(struct ne
8503  
8504  extern struct net_device       *dev_get_by_index(struct net *net, int ifindex);
8505  extern struct net_device       *__dev_get_by_index(struct net *net, int ifindex);
8506 +extern struct net_device       *dev_get_by_index_real_rcu(struct net *net, int ifindex);
8507  extern struct net_device       *dev_get_by_index_rcu(struct net *net, int ifindex);
8508  extern int             dev_restart(struct net_device *dev);
8509  #ifdef CONFIG_NETPOLL_TRAP
8510 diff -NurpP --minimal linux-3.1.6/include/linux/nfs_mount.h linux-3.1.6-vs2.3.2.5/include/linux/nfs_mount.h
8511 --- linux-3.1.6/include/linux/nfs_mount.h       2011-01-05 21:50:31.000000000 +0100
8512 +++ linux-3.1.6-vs2.3.2.5/include/linux/nfs_mount.h     2011-10-24 18:53:33.000000000 +0200
8513 @@ -63,7 +63,8 @@ struct nfs_mount_data {
8514  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
8515  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
8516  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
8517 -#define NFS_MOUNT_FLAGMASK     0xFFFF
8518 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
8519 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
8520  
8521  /* The following are for internal use only */
8522  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
8523 diff -NurpP --minimal linux-3.1.6/include/linux/nsproxy.h linux-3.1.6-vs2.3.2.5/include/linux/nsproxy.h
8524 --- linux-3.1.6/include/linux/nsproxy.h 2011-10-24 18:45:32.000000000 +0200
8525 +++ linux-3.1.6-vs2.3.2.5/include/linux/nsproxy.h       2011-10-24 18:53:33.000000000 +0200
8526 @@ -3,6 +3,7 @@
8527  
8528  #include <linux/spinlock.h>
8529  #include <linux/sched.h>
8530 +#include <linux/vserver/debug.h>
8531  
8532  struct mnt_namespace;
8533  struct uts_namespace;
8534 @@ -63,6 +64,7 @@ static inline struct nsproxy *task_nspro
8535  }
8536  
8537  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
8538 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
8539  void exit_task_namespaces(struct task_struct *tsk);
8540  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
8541  void free_nsproxy(struct nsproxy *ns);
8542 @@ -70,16 +72,26 @@ int unshare_nsproxy_namespaces(unsigned 
8543         struct fs_struct *);
8544  int __init nsproxy_cache_init(void);
8545  
8546 -static inline void put_nsproxy(struct nsproxy *ns)
8547 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
8548 +
8549 +static inline void __get_nsproxy(struct nsproxy *ns,
8550 +       const char *_file, int _line)
8551  {
8552 -       if (atomic_dec_and_test(&ns->count)) {
8553 -               free_nsproxy(ns);
8554 -       }
8555 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
8556 +               ns, atomic_read(&ns->count), _file, _line);
8557 +       atomic_inc(&ns->count);
8558  }
8559  
8560 -static inline void get_nsproxy(struct nsproxy *ns)
8561 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
8562 +
8563 +static inline void __put_nsproxy(struct nsproxy *ns,
8564 +       const char *_file, int _line)
8565  {
8566 -       atomic_inc(&ns->count);
8567 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
8568 +               ns, atomic_read(&ns->count), _file, _line);
8569 +       if (atomic_dec_and_test(&ns->count)) {
8570 +               free_nsproxy(ns);
8571 +       }
8572  }
8573  
8574  #endif
8575 diff -NurpP --minimal linux-3.1.6/include/linux/pid.h linux-3.1.6-vs2.3.2.5/include/linux/pid.h
8576 --- linux-3.1.6/include/linux/pid.h     2011-07-22 11:18:11.000000000 +0200
8577 +++ linux-3.1.6-vs2.3.2.5/include/linux/pid.h   2011-10-24 18:53:33.000000000 +0200
8578 @@ -8,7 +8,8 @@ enum pid_type
8579         PIDTYPE_PID,
8580         PIDTYPE_PGID,
8581         PIDTYPE_SID,
8582 -       PIDTYPE_MAX
8583 +       PIDTYPE_MAX,
8584 +       PIDTYPE_REALPID
8585  };
8586  
8587  /*
8588 @@ -171,6 +172,7 @@ static inline pid_t pid_nr(struct pid *p
8589  }
8590  
8591  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
8592 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
8593  pid_t pid_vnr(struct pid *pid);
8594  
8595  #define do_each_pid_task(pid, type, task)                              \
8596 diff -NurpP --minimal linux-3.1.6/include/linux/proc_fs.h linux-3.1.6-vs2.3.2.5/include/linux/proc_fs.h
8597 --- linux-3.1.6/include/linux/proc_fs.h 2011-10-24 18:45:32.000000000 +0200
8598 +++ linux-3.1.6-vs2.3.2.5/include/linux/proc_fs.h       2011-10-24 18:53:33.000000000 +0200
8599 @@ -54,6 +54,7 @@ struct proc_dir_entry {
8600         nlink_t nlink;
8601         uid_t uid;
8602         gid_t gid;
8603 +       int vx_flags;
8604         loff_t size;
8605         const struct inode_operations *proc_iops;
8606         /*
8607 @@ -252,12 +253,18 @@ extern const struct proc_ns_operations n
8608  extern const struct proc_ns_operations utsns_operations;
8609  extern const struct proc_ns_operations ipcns_operations;
8610  
8611 +struct vx_info;
8612 +struct nx_info;
8613 +
8614  union proc_op {
8615         int (*proc_get_link)(struct inode *, struct path *);
8616         int (*proc_read)(struct task_struct *task, char *page);
8617         int (*proc_show)(struct seq_file *m,
8618                 struct pid_namespace *ns, struct pid *pid,
8619                 struct task_struct *task);
8620 +       int (*proc_vs_read)(char *page);
8621 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
8622 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
8623  };
8624  
8625  struct ctl_table_header;
8626 @@ -265,6 +272,7 @@ struct ctl_table;
8627  
8628  struct proc_inode {
8629         struct pid *pid;
8630 +       int vx_flags;
8631         int fd;
8632         union proc_op op;
8633         struct proc_dir_entry *pde;
8634 diff -NurpP --minimal linux-3.1.6/include/linux/quotaops.h linux-3.1.6-vs2.3.2.5/include/linux/quotaops.h
8635 --- linux-3.1.6/include/linux/quotaops.h        2011-05-22 16:17:57.000000000 +0200
8636 +++ linux-3.1.6-vs2.3.2.5/include/linux/quotaops.h      2011-10-24 18:53:33.000000000 +0200
8637 @@ -8,6 +8,7 @@
8638  #define _LINUX_QUOTAOPS_
8639  
8640  #include <linux/fs.h>
8641 +#include <linux/vs_dlimit.h>
8642  
8643  #define DQUOT_SPACE_WARN       0x1
8644  #define DQUOT_SPACE_RESERVE    0x2
8645 @@ -204,11 +205,12 @@ static inline void dquot_drop(struct ino
8646  
8647  static inline int dquot_alloc_inode(const struct inode *inode)
8648  {
8649 -       return 0;
8650 +       return dl_alloc_inode(inode);
8651  }
8652  
8653  static inline void dquot_free_inode(const struct inode *inode)
8654  {
8655 +       dl_free_inode(inode);
8656  }
8657  
8658  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
8659 @@ -219,6 +221,10 @@ static inline int dquot_transfer(struct 
8660  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
8661                 int flags)
8662  {
8663 +       int ret = 0;
8664 +
8665 +       if ((ret = dl_alloc_space(inode, number)))
8666 +               return ret;
8667         if (!(flags & DQUOT_SPACE_RESERVE))
8668                 inode_add_bytes(inode, number);
8669         return 0;
8670 @@ -229,6 +235,7 @@ static inline void __dquot_free_space(st
8671  {
8672         if (!(flags & DQUOT_SPACE_RESERVE))
8673                 inode_sub_bytes(inode, number);
8674 +       dl_free_space(inode, number);
8675  }
8676  
8677  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
8678 diff -NurpP --minimal linux-3.1.6/include/linux/reboot.h linux-3.1.6-vs2.3.2.5/include/linux/reboot.h
8679 --- linux-3.1.6/include/linux/reboot.h  2011-10-24 18:45:32.000000000 +0200
8680 +++ linux-3.1.6-vs2.3.2.5/include/linux/reboot.h        2011-10-24 18:53:33.000000000 +0200
8681 @@ -33,6 +33,7 @@
8682  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
8683  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
8684  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
8685 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
8686  
8687  
8688  #ifdef __KERNEL__
8689 diff -NurpP --minimal linux-3.1.6/include/linux/reiserfs_fs.h linux-3.1.6-vs2.3.2.5/include/linux/reiserfs_fs.h
8690 --- linux-3.1.6/include/linux/reiserfs_fs.h     2011-10-24 18:45:32.000000000 +0200
8691 +++ linux-3.1.6-vs2.3.2.5/include/linux/reiserfs_fs.h   2011-10-24 18:53:33.000000000 +0200
8692 @@ -976,6 +976,11 @@ struct stat_data_v1 {
8693  #define REISERFS_COMPR_FL     FS_COMPR_FL
8694  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
8695  
8696 +/* unfortunately reiserfs sdattr is only 16 bit */
8697 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
8698 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
8699 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
8700 +
8701  /* persistent flags that file inherits from the parent directory */
8702  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
8703                                 REISERFS_SYNC_FL |      \
8704 @@ -985,6 +990,9 @@ struct stat_data_v1 {
8705                                 REISERFS_COMPR_FL |     \
8706                                 REISERFS_NOTAIL_FL )
8707  
8708 +#define REISERFS_FL_USER_VISIBLE       0x80FF
8709 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
8710 +
8711  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
8712     address blocks) */
8713  struct stat_data {
8714 @@ -2073,6 +2081,7 @@ static inline void reiserfs_update_sd(st
8715  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
8716  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
8717  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
8718 +int reiserfs_sync_flags(struct inode *inode, int, int);
8719  
8720  int __reiserfs_write_begin(struct page *page, unsigned from, unsigned len);
8721  
8722 diff -NurpP --minimal linux-3.1.6/include/linux/reiserfs_fs_sb.h linux-3.1.6-vs2.3.2.5/include/linux/reiserfs_fs_sb.h
8723 --- linux-3.1.6/include/linux/reiserfs_fs_sb.h  2010-02-25 11:52:07.000000000 +0100
8724 +++ linux-3.1.6-vs2.3.2.5/include/linux/reiserfs_fs_sb.h        2011-10-24 18:53:33.000000000 +0200
8725 @@ -476,6 +476,7 @@ enum reiserfs_mount_options {
8726         REISERFS_EXPOSE_PRIVROOT,
8727         REISERFS_BARRIER_NONE,
8728         REISERFS_BARRIER_FLUSH,
8729 +       REISERFS_TAGGED,
8730  
8731         /* Actions on error */
8732         REISERFS_ERROR_PANIC,
8733 diff -NurpP --minimal linux-3.1.6/include/linux/sched.h linux-3.1.6-vs2.3.2.5/include/linux/sched.h
8734 --- linux-3.1.6/include/linux/sched.h   2011-10-24 18:45:32.000000000 +0200
8735 +++ linux-3.1.6-vs2.3.2.5/include/linux/sched.h 2011-10-24 18:53:33.000000000 +0200
8736 @@ -1406,6 +1406,14 @@ struct task_struct {
8737  #endif
8738         seccomp_t seccomp;
8739  
8740 +/* vserver context data */
8741 +       struct vx_info *vx_info;
8742 +       struct nx_info *nx_info;
8743 +
8744 +       xid_t xid;
8745 +       nid_t nid;
8746 +       tag_t tag;
8747 +
8748  /* Thread group tracking */
8749         u32 parent_exec_id;
8750         u32 self_exec_id;
8751 @@ -1648,6 +1656,11 @@ struct pid_namespace;
8752  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
8753                         struct pid_namespace *ns);
8754  
8755 +#include <linux/vserver/base.h>
8756 +#include <linux/vserver/context.h>
8757 +#include <linux/vserver/debug.h>
8758 +#include <linux/vserver/pid.h>
8759 +
8760  static inline pid_t task_pid_nr(struct task_struct *tsk)
8761  {
8762         return tsk->pid;
8763 @@ -1661,7 +1674,8 @@ static inline pid_t task_pid_nr_ns(struc
8764  
8765  static inline pid_t task_pid_vnr(struct task_struct *tsk)
8766  {
8767 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8768 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8769 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
8770  }
8771  
8772  
8773 @@ -1674,7 +1688,7 @@ pid_t task_tgid_nr_ns(struct task_struct
8774  
8775  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
8776  {
8777 -       return pid_vnr(task_tgid(tsk));
8778 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
8779  }
8780  
8781  
8782 diff -NurpP --minimal linux-3.1.6/include/linux/shmem_fs.h linux-3.1.6-vs2.3.2.5/include/linux/shmem_fs.h
8783 --- linux-3.1.6/include/linux/shmem_fs.h        2011-10-24 18:45:32.000000000 +0200
8784 +++ linux-3.1.6-vs2.3.2.5/include/linux/shmem_fs.h      2011-10-24 18:53:33.000000000 +0200
8785 @@ -8,6 +8,9 @@
8786  
8787  /* inode in-kernel data */
8788  
8789 +#define TMPFS_SUPER_MAGIC      0x01021994
8790 +
8791 +
8792  struct shmem_inode_info {
8793         spinlock_t              lock;
8794         unsigned long           flags;
8795 diff -NurpP --minimal linux-3.1.6/include/linux/stat.h linux-3.1.6-vs2.3.2.5/include/linux/stat.h
8796 --- linux-3.1.6/include/linux/stat.h    2008-12-25 00:26:37.000000000 +0100
8797 +++ linux-3.1.6-vs2.3.2.5/include/linux/stat.h  2011-10-24 18:53:33.000000000 +0200
8798 @@ -66,6 +66,7 @@ struct kstat {
8799         unsigned int    nlink;
8800         uid_t           uid;
8801         gid_t           gid;
8802 +       tag_t           tag;
8803         dev_t           rdev;
8804         loff_t          size;
8805         struct timespec  atime;
8806 diff -NurpP --minimal linux-3.1.6/include/linux/sunrpc/auth.h linux-3.1.6-vs2.3.2.5/include/linux/sunrpc/auth.h
8807 --- linux-3.1.6/include/linux/sunrpc/auth.h     2011-10-24 18:45:32.000000000 +0200
8808 +++ linux-3.1.6-vs2.3.2.5/include/linux/sunrpc/auth.h   2011-10-24 18:53:33.000000000 +0200
8809 @@ -25,6 +25,7 @@
8810  struct auth_cred {
8811         uid_t   uid;
8812         gid_t   gid;
8813 +       tag_t   tag;
8814         struct group_info *group_info;
8815         unsigned char machine_cred : 1;
8816  };
8817 diff -NurpP --minimal linux-3.1.6/include/linux/sunrpc/clnt.h linux-3.1.6-vs2.3.2.5/include/linux/sunrpc/clnt.h
8818 --- linux-3.1.6/include/linux/sunrpc/clnt.h     2011-05-22 16:17:58.000000000 +0200
8819 +++ linux-3.1.6-vs2.3.2.5/include/linux/sunrpc/clnt.h   2011-10-24 18:53:33.000000000 +0200
8820 @@ -49,7 +49,8 @@ struct rpc_clnt {
8821         unsigned int            cl_softrtry : 1,/* soft timeouts */
8822                                 cl_discrtry : 1,/* disconnect before retry */
8823                                 cl_autobind : 1,/* use getport() */
8824 -                               cl_chatty   : 1;/* be verbose */
8825 +                               cl_chatty   : 1,/* be verbose */
8826 +                               cl_tag      : 1;/* context tagging */
8827  
8828         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
8829         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
8830 diff -NurpP --minimal linux-3.1.6/include/linux/syscalls.h linux-3.1.6-vs2.3.2.5/include/linux/syscalls.h
8831 --- linux-3.1.6/include/linux/syscalls.h        2011-10-24 18:45:32.000000000 +0200
8832 +++ linux-3.1.6-vs2.3.2.5/include/linux/syscalls.h      2011-10-24 18:53:33.000000000 +0200
8833 @@ -483,6 +483,8 @@ asmlinkage long sys_symlink(const char _
8834  asmlinkage long sys_unlink(const char __user *pathname);
8835  asmlinkage long sys_rename(const char __user *oldname,
8836                                 const char __user *newname);
8837 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
8838 +                               umode_t mode);
8839  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
8840  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
8841  
8842 diff -NurpP --minimal linux-3.1.6/include/linux/sysctl.h linux-3.1.6-vs2.3.2.5/include/linux/sysctl.h
8843 --- linux-3.1.6/include/linux/sysctl.h  2011-03-15 18:07:40.000000000 +0100
8844 +++ linux-3.1.6-vs2.3.2.5/include/linux/sysctl.h        2011-10-24 18:53:33.000000000 +0200
8845 @@ -60,6 +60,7 @@ enum
8846         CTL_ABI=9,              /* Binary emulation */
8847         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
8848         CTL_ARLAN=254,          /* arlan wireless driver */
8849 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
8850         CTL_S390DBF=5677,       /* s390 debug */
8851         CTL_SUNRPC=7249,        /* sunrpc debug */
8852         CTL_PM=9899,            /* frv power management */
8853 @@ -94,6 +95,7 @@ enum
8854  
8855         KERN_PANIC=15,          /* int: panic timeout */
8856         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
8857 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
8858  
8859         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
8860         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
8861 diff -NurpP --minimal linux-3.1.6/include/linux/sysfs.h linux-3.1.6-vs2.3.2.5/include/linux/sysfs.h
8862 --- linux-3.1.6/include/linux/sysfs.h   2011-10-24 18:45:32.000000000 +0200
8863 +++ linux-3.1.6-vs2.3.2.5/include/linux/sysfs.h 2011-10-24 18:53:33.000000000 +0200
8864 @@ -19,6 +19,8 @@
8865  #include <linux/kobject_ns.h>
8866  #include <linux/atomic.h>
8867  
8868 +#define SYSFS_SUPER_MAGIC      0x62656572
8869 +
8870  struct kobject;
8871  struct module;
8872  enum kobj_ns_type;
8873 diff -NurpP --minimal linux-3.1.6/include/linux/time.h linux-3.1.6-vs2.3.2.5/include/linux/time.h
8874 --- linux-3.1.6/include/linux/time.h    2011-07-22 11:18:11.000000000 +0200
8875 +++ linux-3.1.6-vs2.3.2.5/include/linux/time.h  2011-10-24 18:53:33.000000000 +0200
8876 @@ -256,6 +256,9 @@ static __always_inline void timespec_add
8877         a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
8878         a->tv_nsec = ns;
8879  }
8880 +
8881 +#include <linux/vs_time.h>
8882 +
8883  #endif /* __KERNEL__ */
8884  
8885  #define NFDBITS                        __NFDBITS
8886 diff -NurpP --minimal linux-3.1.6/include/linux/types.h linux-3.1.6-vs2.3.2.5/include/linux/types.h
8887 --- linux-3.1.6/include/linux/types.h   2011-05-22 16:17:58.000000000 +0200
8888 +++ linux-3.1.6-vs2.3.2.5/include/linux/types.h 2011-10-24 18:53:33.000000000 +0200
8889 @@ -40,6 +40,9 @@ typedef __kernel_uid32_t      uid_t;
8890  typedef __kernel_gid32_t       gid_t;
8891  typedef __kernel_uid16_t        uid16_t;
8892  typedef __kernel_gid16_t        gid16_t;
8893 +typedef unsigned int           xid_t;
8894 +typedef unsigned int           nid_t;
8895 +typedef unsigned int           tag_t;
8896  
8897  typedef unsigned long          uintptr_t;
8898  
8899 diff -NurpP --minimal linux-3.1.6/include/linux/utsname.h linux-3.1.6-vs2.3.2.5/include/linux/utsname.h
8900 --- linux-3.1.6/include/linux/utsname.h 2011-05-22 16:17:58.000000000 +0200
8901 +++ linux-3.1.6-vs2.3.2.5/include/linux/utsname.h       2011-10-24 18:53:33.000000000 +0200
8902 @@ -54,7 +54,8 @@ static inline void get_uts_ns(struct uts
8903  }
8904  
8905  extern struct uts_namespace *copy_utsname(unsigned long flags,
8906 -                                         struct task_struct *tsk);
8907 +                                         struct uts_namespace *old_ns,
8908 +                                         struct user_namespace *user_ns);
8909  extern void free_uts_ns(struct kref *kref);
8910  
8911  static inline void put_uts_ns(struct uts_namespace *ns)
8912 @@ -71,12 +72,13 @@ static inline void put_uts_ns(struct uts
8913  }
8914  
8915  static inline struct uts_namespace *copy_utsname(unsigned long flags,
8916 -                                                struct task_struct *tsk)
8917 +                                                struct uts_namespace *old_ns,
8918 +                                                struct user_namespace *user_ns)
8919  {
8920         if (flags & CLONE_NEWUTS)
8921                 return ERR_PTR(-EINVAL);
8922  
8923 -       return tsk->nsproxy->uts_ns;
8924 +       return old_ns;
8925  }
8926  #endif
8927  
8928 diff -NurpP --minimal linux-3.1.6/include/linux/vroot.h linux-3.1.6-vs2.3.2.5/include/linux/vroot.h
8929 --- linux-3.1.6/include/linux/vroot.h   1970-01-01 01:00:00.000000000 +0100
8930 +++ linux-3.1.6-vs2.3.2.5/include/linux/vroot.h 2011-10-24 18:53:33.000000000 +0200
8931 @@ -0,0 +1,51 @@
8932 +
8933 +/*
8934 + * include/linux/vroot.h
8935 + *
8936 + * written by Herbert Pötzl, 9/11/2002
8937 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
8938 + *
8939 + * Copyright (C) 2002-2007 by Herbert Pötzl.
8940 + * Redistribution of this file is permitted under the
8941 + * GNU General Public License.
8942 + */
8943 +
8944 +#ifndef _LINUX_VROOT_H
8945 +#define _LINUX_VROOT_H
8946 +
8947 +
8948 +#ifdef __KERNEL__
8949 +
8950 +/* Possible states of device */
8951 +enum {
8952 +       Vr_unbound,
8953 +       Vr_bound,
8954 +};
8955 +
8956 +struct vroot_device {
8957 +       int             vr_number;
8958 +       int             vr_refcnt;
8959 +
8960 +       struct semaphore        vr_ctl_mutex;
8961 +       struct block_device    *vr_device;
8962 +       int                     vr_state;
8963 +};
8964 +
8965 +
8966 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
8967 +
8968 +extern int register_vroot_grb(vroot_grb_func *);
8969 +extern int unregister_vroot_grb(vroot_grb_func *);
8970 +
8971 +#endif /* __KERNEL__ */
8972 +
8973 +#define MAX_VROOT_DEFAULT      8
8974 +
8975 +/*
8976 + * IOCTL commands --- we will commandeer 0x56 ('V')
8977 + */
8978 +
8979 +#define VROOT_SET_DEV          0x5600
8980 +#define VROOT_CLR_DEV          0x5601
8981 +
8982 +#endif /* _LINUX_VROOT_H */
8983 diff -NurpP --minimal linux-3.1.6/include/linux/vs_base.h linux-3.1.6-vs2.3.2.5/include/linux/vs_base.h
8984 --- linux-3.1.6/include/linux/vs_base.h 1970-01-01 01:00:00.000000000 +0100
8985 +++ linux-3.1.6-vs2.3.2.5/include/linux/vs_base.h       2011-10-24 18:53:33.000000000 +0200
8986 @@ -0,0 +1,10 @@
8987 +#ifndef _VS_BASE_H
8988 +#define _VS_BASE_H
8989 +
8990 +#include "vserver/base.h"
8991 +#include "vserver/check.h"
8992 +#include "vserver/debug.h"
8993 +
8994 +#else
8995 +#warning duplicate inclusion
8996 +#endif
8997 diff -NurpP --minimal linux-3.1.6/include/linux/vs_context.h linux-3.1.6-vs2.3.2.5/include/linux/vs_context.h
8998 --- linux-3.1.6/include/linux/vs_context.h      1970-01-01 01:00:00.000000000 +0100
8999 +++ linux-3.1.6-vs2.3.2.5/include/linux/vs_context.h    2011-10-24 18:53:33.000000000 +0200
9000 @@ -0,0 +1,242 @@
9001 +#ifndef _VS_CONTEXT_H
9002 +#define _VS_CONTEXT_H
9003 +
9004 +#include "vserver/base.h"
9005 +#include "vserver/check.h"
9006 +#include "vserver/context.h"
9007 +#include "vserver/history.h"
9008 +#include "vserver/debug.h"
9009 +
9010 +#include <linux/sched.h>
9011 +
9012 +
9013 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
9014 +
9015 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
9016 +       const char *_file, int _line, void *_here)
9017 +{
9018 +       if (!vxi)
9019 +               return NULL;
9020 +
9021 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
9022 +               vxi, vxi ? vxi->vx_id : 0,
9023 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9024 +               _file, _line);
9025 +       __vxh_get_vx_info(vxi, _here);
9026 +
9027 +       atomic_inc(&vxi->vx_usecnt);
9028 +       return vxi;
9029 +}
9030 +
9031 +
9032 +extern void free_vx_info(struct vx_info *);
9033 +
9034 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
9035 +
9036 +static inline void __put_vx_info(struct vx_info *vxi,
9037 +       const char *_file, int _line, void *_here)
9038 +{
9039 +       if (!vxi)
9040 +               return;
9041 +
9042 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
9043 +               vxi, vxi ? vxi->vx_id : 0,
9044 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9045 +               _file, _line);
9046 +       __vxh_put_vx_info(vxi, _here);
9047 +
9048 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
9049 +               free_vx_info(vxi);
9050 +}
9051 +
9052 +
9053 +#define init_vx_info(p, i) \
9054 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9055 +
9056 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9057 +       const char *_file, int _line, void *_here)
9058 +{
9059 +       if (vxi) {
9060 +               vxlprintk(VXD_CBIT(xid, 3),
9061 +                       "init_vx_info(%p[#%d.%d])",
9062 +                       vxi, vxi ? vxi->vx_id : 0,
9063 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9064 +                       _file, _line);
9065 +               __vxh_init_vx_info(vxi, vxp, _here);
9066 +
9067 +               atomic_inc(&vxi->vx_usecnt);
9068 +       }
9069 +       *vxp = vxi;
9070 +}
9071 +
9072 +
9073 +#define set_vx_info(p, i) \
9074 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9075 +
9076 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9077 +       const char *_file, int _line, void *_here)
9078 +{
9079 +       struct vx_info *vxo;
9080 +
9081 +       if (!vxi)
9082 +               return;
9083 +
9084 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
9085 +               vxi, vxi ? vxi->vx_id : 0,
9086 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9087 +               _file, _line);
9088 +       __vxh_set_vx_info(vxi, vxp, _here);
9089 +
9090 +       atomic_inc(&vxi->vx_usecnt);
9091 +       vxo = xchg(vxp, vxi);
9092 +       BUG_ON(vxo);
9093 +}
9094 +
9095 +
9096 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
9097 +
9098 +static inline void __clr_vx_info(struct vx_info **vxp,
9099 +       const char *_file, int _line, void *_here)
9100 +{
9101 +       struct vx_info *vxo;
9102 +
9103 +       vxo = xchg(vxp, NULL);
9104 +       if (!vxo)
9105 +               return;
9106 +
9107 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
9108 +               vxo, vxo ? vxo->vx_id : 0,
9109 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
9110 +               _file, _line);
9111 +       __vxh_clr_vx_info(vxo, vxp, _here);
9112 +
9113 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
9114 +               free_vx_info(vxo);
9115 +}
9116 +
9117 +
9118 +#define claim_vx_info(v, p) \
9119 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9120 +
9121 +static inline void __claim_vx_info(struct vx_info *vxi,
9122 +       struct task_struct *task,
9123 +       const char *_file, int _line, void *_here)
9124 +{
9125 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
9126 +               vxi, vxi ? vxi->vx_id : 0,
9127 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9128 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9129 +               task, _file, _line);
9130 +       __vxh_claim_vx_info(vxi, task, _here);
9131 +
9132 +       atomic_inc(&vxi->vx_tasks);
9133 +}
9134 +
9135 +
9136 +extern void unhash_vx_info(struct vx_info *);
9137 +
9138 +#define release_vx_info(v, p) \
9139 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9140 +
9141 +static inline void __release_vx_info(struct vx_info *vxi,
9142 +       struct task_struct *task,
9143 +       const char *_file, int _line, void *_here)
9144 +{
9145 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
9146 +               vxi, vxi ? vxi->vx_id : 0,
9147 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9148 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9149 +               task, _file, _line);
9150 +       __vxh_release_vx_info(vxi, task, _here);
9151 +
9152 +       might_sleep();
9153 +
9154 +       if (atomic_dec_and_test(&vxi->vx_tasks))
9155 +               unhash_vx_info(vxi);
9156 +}
9157 +
9158 +
9159 +#define task_get_vx_info(p) \
9160 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
9161 +
9162 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
9163 +       const char *_file, int _line, void *_here)
9164 +{
9165 +       struct vx_info *vxi;
9166 +
9167 +       task_lock(p);
9168 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
9169 +               p, _file, _line);
9170 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
9171 +       task_unlock(p);
9172 +       return vxi;
9173 +}
9174 +
9175 +
9176 +static inline void __wakeup_vx_info(struct vx_info *vxi)
9177 +{
9178 +       if (waitqueue_active(&vxi->vx_wait))
9179 +               wake_up_interruptible(&vxi->vx_wait);
9180 +}
9181 +
9182 +
9183 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
9184 +
9185 +static inline void __enter_vx_info(struct vx_info *vxi,
9186 +       struct vx_info_save *vxis, const char *_file, int _line)
9187 +{
9188 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
9189 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
9190 +               current->xid, current->vx_info, _file, _line);
9191 +       vxis->vxi = xchg(&current->vx_info, vxi);
9192 +       vxis->xid = current->xid;
9193 +       current->xid = vxi ? vxi->vx_id : 0;
9194 +}
9195 +
9196 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
9197 +
9198 +static inline void __leave_vx_info(struct vx_info_save *vxis,
9199 +       const char *_file, int _line)
9200 +{
9201 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
9202 +               vxis, vxis->xid, vxis->vxi, current,
9203 +               current->xid, current->vx_info, _file, _line);
9204 +       (void)xchg(&current->vx_info, vxis->vxi);
9205 +       current->xid = vxis->xid;
9206 +}
9207 +
9208 +
9209 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
9210 +{
9211 +       vxis->vxi = xchg(&current->vx_info, NULL);
9212 +       vxis->xid = xchg(&current->xid, (xid_t)0);
9213 +}
9214 +
9215 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
9216 +{
9217 +       (void)xchg(&current->xid, vxis->xid);
9218 +       (void)xchg(&current->vx_info, vxis->vxi);
9219 +}
9220 +
9221 +#define task_is_init(p) \
9222 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
9223 +
9224 +static inline int __task_is_init(struct task_struct *p,
9225 +       const char *_file, int _line, void *_here)
9226 +{
9227 +       int is_init = is_global_init(p);
9228 +
9229 +       task_lock(p);
9230 +       if (p->vx_info)
9231 +               is_init = p->vx_info->vx_initpid == p->pid;
9232 +       task_unlock(p);
9233 +       return is_init;
9234 +}
9235 +
9236 +extern void exit_vx_info(struct task_struct *, int);
9237 +extern void exit_vx_info_early(struct task_struct *, int);
9238 +
9239 +
9240 +#else
9241 +#warning duplicate inclusion
9242 +#endif
9243 diff -NurpP --minimal linux-3.1.6/include/linux/vs_cowbl.h linux-3.1.6-vs2.3.2.5/include/linux/vs_cowbl.h
9244 --- linux-3.1.6/include/linux/vs_cowbl.h        1970-01-01 01:00:00.000000000 +0100
9245 +++ linux-3.1.6-vs2.3.2.5/include/linux/vs_cowbl.h      2011-10-24 18:53:33.000000000 +0200
9246 @@ -0,0 +1,48 @@
9247 +#ifndef _VS_COWBL_H
9248 +#define _VS_COWBL_H
9249 +
9250 +#include <linux/fs.h>
9251 +#include <linux/dcache.h>
9252 +#include <linux/namei.h>
9253 +#include <linux/slab.h>
9254 +
9255 +extern struct dentry *cow_break_link(const char *pathname);
9256 +
9257 +static inline int cow_check_and_break(struct path *path)
9258 +{
9259 +       struct inode *inode = path->dentry->d_inode;
9260 +       int error = 0;
9261 +
9262 +       /* do we need this check? */
9263 +       if (IS_RDONLY(inode))
9264 +               return -EROFS;
9265 +
9266 +       if (IS_COW(inode)) {
9267 +               if (IS_COW_LINK(inode)) {
9268 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
9269 +                       char *pp, *buf;
9270 +
9271 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
9272 +                       if (!buf) {
9273 +                               return -ENOMEM;
9274 +                       }
9275 +                       pp = d_path(path, buf, PATH_MAX);
9276 +                       new_dentry = cow_break_link(pp);
9277 +                       kfree(buf);
9278 +                       if (!IS_ERR(new_dentry)) {
9279 +                               path->dentry = new_dentry;
9280 +                               dput(old_dentry);
9281 +                       } else
9282 +                               error = PTR_ERR(new_dentry);
9283 +               } else {
9284 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
9285 +                       inode->i_ctime = CURRENT_TIME;
9286 +                       mark_inode_dirty(inode);
9287 +               }
9288 +       }
9289 +       return error;
9290 +}
9291 +
9292 +#else
9293 +#warning duplicate inclusion
9294 +#endif
9295 diff -NurpP --minimal linux-3.1.6/include/linux/vs_cvirt.h linux-3.1.6-vs2.3.2.5/include/linux/vs_cvirt.h
9296 --- linux-3.1.6/include/linux/vs_cvirt.h        1970-01-01 01:00:00.000000000 +0100
9297 +++ linux-3.1.6-vs2.3.2.5/include/linux/vs_cvirt.h      2011-10-24 18:53:33.000000000 +0200
9298 @@ -0,0 +1,50 @@
9299 +#ifndef _VS_CVIRT_H
9300 +#define _VS_CVIRT_H
9301 +
9302 +#include "vserver/cvirt.h"
9303 +#include "vserver/context.h"
9304 +#include "vserver/base.h"
9305 +#include "vserver/check.h"
9306 +#include "vserver/debug.h"
9307 +
9308 +
9309 +static inline void vx_activate_task(struct task_struct *p)
9310 +{
9311 +       struct vx_info *vxi;
9312 +
9313 +       if ((vxi = p->vx_info)) {
9314 +               vx_update_load(vxi);
9315 +               atomic_inc(&vxi->cvirt.nr_running);
9316 +       }
9317 +}
9318 +
9319 +static inline void vx_deactivate_task(struct task_struct *p)
9320 +{
9321 +       struct vx_info *vxi;
9322 +
9323 +       if ((vxi = p->vx_info)) {
9324 +               vx_update_load(vxi);
9325 +               atomic_dec(&vxi->cvirt.nr_running);
9326 +       }
9327 +}
9328 +
9329 +static inline void vx_uninterruptible_inc(struct task_struct *p)
9330 +{
9331 +       struct vx_info *vxi;
9332 +
9333 +       if ((vxi = p->vx_info))
9334 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
9335 +}
9336 +
9337 +static inline void vx_uninterruptible_dec(struct task_struct *p)
9338 +{
9339 +       struct vx_info *vxi;
9340 +
9341 +       if ((vxi = p->vx_info))
9342 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
9343 +}
9344 +
9345 +
9346 +#else
9347 +#warning duplicate inclusion
9348 +#endif
9349 diff -NurpP --minimal linux-3.1.6/include/linux/vs_device.h linux-3.1.6-vs2.3.2.5/include/linux/vs_device.h
9350 --- linux-3.1.6/include/linux/vs_device.h       1970-01-01 01:00:00.000000000 +0100
9351 +++ linux-3.1.6-vs2.3.2.5/include/linux/vs_device.h     2011-10-24 18:53:33.000000000 +0200
9352 @@ -0,0 +1,45 @@
9353 +#ifndef _VS_DEVICE_H
9354 +#define _VS_DEVICE_H
9355 +
9356 +#include "vserver/base.h"
9357 +#include "vserver/device.h"
9358 +#include "vserver/debug.h"
9359 +
9360 +
9361 +#ifdef CONFIG_VSERVER_DEVICE
9362 +
9363 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
9364 +
9365 +#define vs_device_perm(v, d, m, p) \
9366 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
9367 +
9368 +#else
9369 +
9370 +static inline
9371 +int vs_map_device(struct vx_info *vxi,
9372 +       dev_t device, dev_t *target, umode_t mode)
9373 +{
9374 +       if (target)
9375 +               *target = device;
9376 +       return ~0;
9377 +}
9378 +
9379 +#define vs_device_perm(v, d, m, p) ((p) == (p))
9380 +
9381 +#endif
9382 +
9383 +
9384 +#define vs_map_chrdev(d, t, p) \
9385 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
9386 +#define vs_map_blkdev(d, t, p) \
9387 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
9388 +
9389 +#define vs_chrdev_perm(d, p) \
9390 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
9391 +#define vs_blkdev_perm(d, p) \
9392 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
9393 +
9394 +
9395 +#else
9396 +#warning duplicate inclusion
9397 +#endif
9398 diff -NurpP --minimal linux-3.1.6/include/linux/vs_dlimit.h linux-3.1.6-vs2.3.2.5/include/linux/vs_dlimit.h
9399 --- linux-3.1.6/include/linux/vs_dlimit.h       1970-01-01 01:00:00.000000000 +0100
9400 +++ linux-3.1.6-vs2.3.2.5/include/linux/vs_dlimit.h     2011-10-24 18:53:33.000000000 +0200
9401 @@ -0,0 +1,215 @@
9402 +#ifndef _VS_DLIMIT_H
9403 +#define _VS_DLIMIT_H
9404 +
9405 +#include <linux/fs.h>
9406 +
9407 +#include "vserver/dlimit.h"
9408 +#include "vserver/base.h"
9409 +#include "vserver/debug.h"
9410 +
9411 +
9412 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
9413 +
9414 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
9415 +       const char *_file, int _line)
9416 +{
9417 +       if (!dli)
9418 +               return NULL;
9419 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
9420 +               dli, dli ? dli->dl_tag : 0,
9421 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9422 +               _file, _line);
9423 +       atomic_inc(&dli->dl_usecnt);
9424 +       return dli;
9425 +}
9426 +
9427 +
9428 +#define free_dl_info(i) \
9429 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
9430 +
9431 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
9432 +
9433 +static inline void __put_dl_info(struct dl_info *dli,
9434 +       const char *_file, int _line)
9435 +{
9436 +       if (!dli)
9437 +               return;
9438 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
9439 +               dli, dli ? dli->dl_tag : 0,
9440 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9441 +               _file, _line);
9442 +       if (atomic_dec_and_test(&dli->dl_usecnt))
9443 +               free_dl_info(dli);
9444 +}
9445 +
9446 +
9447 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
9448 +
9449 +static inline int __dl_alloc_space(struct super_block *sb,
9450 +       tag_t tag, dlsize_t nr, const char *file, int line)
9451 +{
9452 +       struct dl_info *dli = NULL;
9453 +       int ret = 0;
9454 +
9455 +       if (nr == 0)
9456 +               goto out;
9457 +       dli = locate_dl_info(sb, tag);
9458 +       if (!dli)
9459 +               goto out;
9460 +
9461 +       spin_lock(&dli->dl_lock);
9462 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
9463 +       if (!ret)
9464 +               dli->dl_space_used += nr;
9465 +       spin_unlock(&dli->dl_lock);
9466 +       put_dl_info(dli);
9467 +out:
9468 +       vxlprintk(VXD_CBIT(dlim, 1),
9469 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
9470 +               sb, tag, __dlimit_char(dli), (long long)nr,
9471 +               ret, file, line);
9472 +       return ret ? -ENOSPC : 0;
9473 +}
9474 +
9475 +static inline void __dl_free_space(struct super_block *sb,
9476 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
9477 +{
9478 +       struct dl_info *dli = NULL;
9479 +
9480 +       if (nr == 0)
9481 +               goto out;
9482 +       dli = locate_dl_info(sb, tag);
9483 +       if (!dli)
9484 +               goto out;
9485 +
9486 +       spin_lock(&dli->dl_lock);
9487 +       if (dli->dl_space_used > nr)
9488 +               dli->dl_space_used -= nr;
9489 +       else
9490 +               dli->dl_space_used = 0;
9491 +       spin_unlock(&dli->dl_lock);
9492 +       put_dl_info(dli);
9493 +out:
9494 +       vxlprintk(VXD_CBIT(dlim, 1),
9495 +               "FREE  (%p,#%d)%c %lld bytes",
9496 +               sb, tag, __dlimit_char(dli), (long long)nr,
9497 +               _file, _line);
9498 +}
9499 +
9500 +static inline int __dl_alloc_inode(struct super_block *sb,
9501 +       tag_t tag, const char *_file, int _line)
9502 +{
9503 +       struct dl_info *dli;
9504 +       int ret = 0;
9505 +
9506 +       dli = locate_dl_info(sb, tag);
9507 +       if (!dli)
9508 +               goto out;
9509 +
9510 +       spin_lock(&dli->dl_lock);
9511 +       dli->dl_inodes_used++;
9512 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
9513 +       spin_unlock(&dli->dl_lock);
9514 +       put_dl_info(dli);
9515 +out:
9516 +       vxlprintk(VXD_CBIT(dlim, 0),
9517 +               "ALLOC (%p,#%d)%c inode (%d)",
9518 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
9519 +       return ret ? -ENOSPC : 0;
9520 +}
9521 +
9522 +static inline void __dl_free_inode(struct super_block *sb,
9523 +       tag_t tag, const char *_file, int _line)
9524 +{
9525 +       struct dl_info *dli;
9526 +
9527 +       dli = locate_dl_info(sb, tag);
9528 +       if (!dli)
9529 +               goto out;
9530 +
9531 +       spin_lock(&dli->dl_lock);
9532 +       if (dli->dl_inodes_used > 1)
9533 +               dli->dl_inodes_used--;
9534 +       else
9535 +               dli->dl_inodes_used = 0;
9536 +       spin_unlock(&dli->dl_lock);
9537 +       put_dl_info(dli);
9538 +out:
9539 +       vxlprintk(VXD_CBIT(dlim, 0),
9540 +               "FREE  (%p,#%d)%c inode",
9541 +               sb, tag, __dlimit_char(dli), _file, _line);
9542 +}
9543 +
9544 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
9545 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
9546 +       const char *_file, int _line)
9547 +{
9548 +       struct dl_info *dli;
9549 +       uint64_t broot, bfree;
9550 +
9551 +       dli = locate_dl_info(sb, tag);
9552 +       if (!dli)
9553 +               return;
9554 +
9555 +       spin_lock(&dli->dl_lock);
9556 +       broot = (dli->dl_space_total -
9557 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
9558 +               >> sb->s_blocksize_bits;
9559 +       bfree = (dli->dl_space_total - dli->dl_space_used)
9560 +                       >> sb->s_blocksize_bits;
9561 +       spin_unlock(&dli->dl_lock);
9562 +
9563 +       vxlprintk(VXD_CBIT(dlim, 2),
9564 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
9565 +               (long long)bfree, (long long)broot,
9566 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
9567 +               _file, _line);
9568 +       if (free_blocks) {
9569 +               if (*free_blocks > bfree)
9570 +                       *free_blocks = bfree;
9571 +       }
9572 +       if (root_blocks) {
9573 +               if (*root_blocks > broot)
9574 +                       *root_blocks = broot;
9575 +       }
9576 +       put_dl_info(dli);
9577 +}
9578 +
9579 +#define dl_prealloc_space(in, bytes) \
9580 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9581 +               __FILE__, __LINE__ )
9582 +
9583 +#define dl_alloc_space(in, bytes) \
9584 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9585 +               __FILE__, __LINE__ )
9586 +
9587 +#define dl_reserve_space(in, bytes) \
9588 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9589 +               __FILE__, __LINE__ )
9590 +
9591 +#define dl_claim_space(in, bytes) (0)
9592 +
9593 +#define dl_release_space(in, bytes) \
9594 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9595 +               __FILE__, __LINE__ )
9596 +
9597 +#define dl_free_space(in, bytes) \
9598 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
9599 +               __FILE__, __LINE__ )
9600 +
9601 +
9602 +
9603 +#define dl_alloc_inode(in) \
9604 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
9605 +
9606 +#define dl_free_inode(in) \
9607 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
9608 +
9609 +
9610 +#define dl_adjust_block(sb, tag, fb, rb) \
9611 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
9612 +
9613 +
9614 +#else
9615 +#warning duplicate inclusion
9616 +#endif
9617 diff -NurpP --minimal linux-3.1.6/include/linux/vs_inet.h linux-3.1.6-vs2.3.2.5/include/linux/vs_inet.h
9618 --- linux-3.1.6/include/linux/vs_inet.h 1970-01-01 01:00:00.000000000 +0100
9619 +++ linux-3.1.6-vs2.3.2.5/include/linux/vs_inet.h       2011-10-24 18:53:33.000000000 +0200
9620 @@ -0,0 +1,353 @@
9621 +#ifndef _VS_INET_H
9622 +#define _VS_INET_H
9623 +
9624 +#include "vserver/base.h"
9625 +#include "vserver/network.h"
9626 +#include "vserver/debug.h"
9627 +
9628 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
9629 +
9630 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
9631 +                       NIPQUAD((a)->mask), (a)->type
9632 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
9633 +
9634 +#define NIPQUAD(addr) \
9635 +       ((unsigned char *)&addr)[0], \
9636 +       ((unsigned char *)&addr)[1], \
9637 +       ((unsigned char *)&addr)[2], \
9638 +       ((unsigned char *)&addr)[3]
9639 +
9640 +#define NIPQUAD_FMT "%u.%u.%u.%u"
9641 +
9642 +
9643 +static inline
9644 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
9645 +{
9646 +       __be32 ip = nxa->ip[0].s_addr;
9647 +       __be32 mask = nxa->mask.s_addr;
9648 +       __be32 bcast = ip | ~mask;
9649 +       int ret = 0;
9650 +
9651 +       switch (nxa->type & tmask) {
9652 +       case NXA_TYPE_MASK:
9653 +               ret = (ip == (addr & mask));
9654 +               break;
9655 +       case NXA_TYPE_ADDR:
9656 +               ret = 3;
9657 +               if (addr == ip)
9658 +                       break;
9659 +               /* fall through to broadcast */
9660 +       case NXA_MOD_BCAST:
9661 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
9662 +               break;
9663 +       case NXA_TYPE_RANGE:
9664 +               ret = ((nxa->ip[0].s_addr <= addr) &&
9665 +                       (nxa->ip[1].s_addr > addr));
9666 +               break;
9667 +       case NXA_TYPE_ANY:
9668 +               ret = 2;
9669 +               break;
9670 +       }
9671 +
9672 +       vxdprintk(VXD_CBIT(net, 0),
9673 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
9674 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
9675 +       return ret;
9676 +}
9677 +
9678 +static inline
9679 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
9680 +{
9681 +       struct nx_addr_v4 *nxa;
9682 +       int ret = 1;
9683 +
9684 +       if (!nxi)
9685 +               goto out;
9686 +
9687 +       ret = 2;
9688 +       /* allow 127.0.0.1 when remapping lback */
9689 +       if ((tmask & NXA_LOOPBACK) &&
9690 +               (addr == IPI_LOOPBACK) &&
9691 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9692 +               goto out;
9693 +       ret = 3;
9694 +       /* check for lback address */
9695 +       if ((tmask & NXA_MOD_LBACK) &&
9696 +               (nxi->v4_lback.s_addr == addr))
9697 +               goto out;
9698 +       ret = 4;
9699 +       /* check for broadcast address */
9700 +       if ((tmask & NXA_MOD_BCAST) &&
9701 +               (nxi->v4_bcast.s_addr == addr))
9702 +               goto out;
9703 +       ret = 5;
9704 +       /* check for v4 addresses */
9705 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
9706 +               if (v4_addr_match(nxa, addr, tmask))
9707 +                       goto out;
9708 +       ret = 0;
9709 +out:
9710 +       vxdprintk(VXD_CBIT(net, 0),
9711 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
9712 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
9713 +       return ret;
9714 +}
9715 +
9716 +static inline
9717 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
9718 +{
9719 +       /* FIXME: needs full range checks */
9720 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
9721 +}
9722 +
9723 +static inline
9724 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
9725 +{
9726 +       struct nx_addr_v4 *ptr;
9727 +
9728 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
9729 +               if (v4_nx_addr_match(ptr, nxa, mask))
9730 +                       return 1;
9731 +       return 0;
9732 +}
9733 +
9734 +#include <net/inet_sock.h>
9735 +
9736 +/*
9737 + *     Check if a given address matches for a socket
9738 + *
9739 + *     nxi:            the socket's nx_info if any
9740 + *     addr:           to be verified address
9741 + */
9742 +static inline
9743 +int v4_sock_addr_match (
9744 +       struct nx_info *nxi,
9745 +       struct inet_sock *inet,
9746 +       __be32 addr)
9747 +{
9748 +       __be32 saddr = inet->inet_rcv_saddr;
9749 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
9750 +
9751 +       if (addr && (saddr == addr || bcast == addr))
9752 +               return 1;
9753 +       if (!saddr)
9754 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
9755 +       return 0;
9756 +}
9757 +
9758 +
9759 +/* inet related checks and helpers */
9760 +
9761 +
9762 +struct in_ifaddr;
9763 +struct net_device;
9764 +struct sock;
9765 +
9766 +#ifdef CONFIG_INET
9767 +
9768 +#include <linux/netdevice.h>
9769 +#include <linux/inetdevice.h>
9770 +#include <net/inet_sock.h>
9771 +#include <net/inet_timewait_sock.h>
9772 +
9773 +
9774 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9775 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
9776 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
9777 +
9778 +
9779 +/*
9780 + *     check if address is covered by socket
9781 + *
9782 + *     sk:     the socket to check against
9783 + *     addr:   the address in question (must be != 0)
9784 + */
9785 +
9786 +static inline
9787 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
9788 +{
9789 +       struct nx_info *nxi = sk->sk_nx_info;
9790 +       __be32 saddr = sk_rcv_saddr(sk);
9791 +
9792 +       vxdprintk(VXD_CBIT(net, 5),
9793 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
9794 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
9795 +               (sk->sk_socket?sk->sk_socket->flags:0));
9796 +
9797 +       if (saddr) {            /* direct address match */
9798 +               return v4_addr_match(nxa, saddr, -1);
9799 +       } else if (nxi) {       /* match against nx_info */
9800 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
9801 +       } else {                /* unrestricted any socket */
9802 +               return 1;
9803 +       }
9804 +}
9805 +
9806 +
9807 +
9808 +static inline
9809 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
9810 +{
9811 +       vxdprintk(VXD_CBIT(net, 1),
9812 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
9813 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
9814 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
9815 +
9816 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9817 +               return 1;
9818 +       if (dev_in_nx_info(dev, nxi))
9819 +               return 1;
9820 +       return 0;
9821 +}
9822 +
9823 +
9824 +static inline
9825 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
9826 +{
9827 +       if (!nxi)
9828 +               return 1;
9829 +       if (!ifa)
9830 +               return 0;
9831 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
9832 +}
9833 +
9834 +static inline
9835 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
9836 +{
9837 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
9838 +               nxi, nxi ? nxi->nx_id : 0, ifa,
9839 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
9840 +
9841 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9842 +               return 1;
9843 +       if (v4_ifa_in_nx_info(ifa, nxi))
9844 +               return 1;
9845 +       return 0;
9846 +}
9847 +
9848 +
9849 +struct nx_v4_sock_addr {
9850 +       __be32 saddr;   /* Address used for validation */
9851 +       __be32 baddr;   /* Address used for socket bind */
9852 +};
9853 +
9854 +static inline
9855 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
9856 +       struct nx_v4_sock_addr *nsa)
9857 +{
9858 +       struct sock *sk = &inet->sk;
9859 +       struct nx_info *nxi = sk->sk_nx_info;
9860 +       __be32 saddr = addr->sin_addr.s_addr;
9861 +       __be32 baddr = saddr;
9862 +
9863 +       vxdprintk(VXD_CBIT(net, 3),
9864 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
9865 +               sk, sk->sk_nx_info, sk->sk_socket,
9866 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
9867 +               NIPQUAD(saddr));
9868 +
9869 +       if (nxi) {
9870 +               if (saddr == INADDR_ANY) {
9871 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
9872 +                               baddr = nxi->v4.ip[0].s_addr;
9873 +               } else if (saddr == IPI_LOOPBACK) {
9874 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9875 +                               baddr = nxi->v4_lback.s_addr;
9876 +               } else if (!ipv4_is_multicast(saddr) ||
9877 +                       !nx_info_ncaps(nxi, NXC_MULTICAST)) {
9878 +                       /* normal address bind */
9879 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
9880 +                               return -EADDRNOTAVAIL;
9881 +               }
9882 +       }
9883 +
9884 +       vxdprintk(VXD_CBIT(net, 3),
9885 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
9886 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
9887 +
9888 +       nsa->saddr = saddr;
9889 +       nsa->baddr = baddr;
9890 +       return 0;
9891 +}
9892 +
9893 +static inline
9894 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
9895 +{
9896 +       inet->inet_saddr = nsa->baddr;
9897 +       inet->inet_rcv_saddr = nsa->baddr;
9898 +}
9899 +
9900 +
9901 +/*
9902 + *      helper to simplify inet_lookup_listener
9903 + *
9904 + *      nxi:   the socket's nx_info if any
9905 + *      addr:  to be verified address
9906 + *      saddr: socket address
9907 + */
9908 +static inline int v4_inet_addr_match (
9909 +       struct nx_info *nxi,
9910 +       __be32 addr,
9911 +       __be32 saddr)
9912 +{
9913 +       if (addr && (saddr == addr))
9914 +               return 1;
9915 +       if (!saddr)
9916 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
9917 +       return 0;
9918 +}
9919 +
9920 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
9921 +{
9922 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
9923 +               (addr == nxi->v4_lback.s_addr))
9924 +               return IPI_LOOPBACK;
9925 +       return addr;
9926 +}
9927 +
9928 +static inline
9929 +int nx_info_has_v4(struct nx_info *nxi)
9930 +{
9931 +       if (!nxi)
9932 +               return 1;
9933 +       if (NX_IPV4(nxi))
9934 +               return 1;
9935 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9936 +               return 1;
9937 +       return 0;
9938 +}
9939 +
9940 +#else /* CONFIG_INET */
9941 +
9942 +static inline
9943 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
9944 +{
9945 +       return 1;
9946 +}
9947 +
9948 +static inline
9949 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9950 +{
9951 +       return 1;
9952 +}
9953 +
9954 +static inline
9955 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9956 +{
9957 +       return 1;
9958 +}
9959 +
9960 +static inline
9961 +int nx_info_has_v4(struct nx_info *nxi)
9962 +{
9963 +       return 0;
9964 +}
9965 +
9966 +#endif /* CONFIG_INET */
9967 +
9968 +#define current_nx_info_has_v4() \
9969 +       nx_info_has_v4(current_nx_info())
9970 +
9971 +#else
9972 +// #warning duplicate inclusion
9973 +#endif
9974 diff -NurpP --minimal linux-3.1.6/include/linux/vs_inet6.h linux-3.1.6-vs2.3.2.5/include/linux/vs_inet6.h
9975 --- linux-3.1.6/include/linux/vs_inet6.h        1970-01-01 01:00:00.000000000 +0100
9976 +++ linux-3.1.6-vs2.3.2.5/include/linux/vs_inet6.h      2011-10-24 18:53:33.000000000 +0200
9977 @@ -0,0 +1,246 @@
9978 +#ifndef _VS_INET6_H
9979 +#define _VS_INET6_H
9980 +
9981 +#include "vserver/base.h"
9982 +#include "vserver/network.h"
9983 +#include "vserver/debug.h"
9984 +
9985 +#include <net/ipv6.h>
9986 +
9987 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
9988 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
9989 +
9990 +
9991 +#ifdef CONFIG_IPV6
9992 +
9993 +static inline
9994 +int v6_addr_match(struct nx_addr_v6 *nxa,
9995 +       const struct in6_addr *addr, uint16_t mask)
9996 +{
9997 +       int ret = 0;
9998 +
9999 +       switch (nxa->type & mask) {
10000 +       case NXA_TYPE_MASK:
10001 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
10002 +               break;
10003 +       case NXA_TYPE_ADDR:
10004 +               ret = ipv6_addr_equal(&nxa->ip, addr);
10005 +               break;
10006 +       case NXA_TYPE_ANY:
10007 +               ret = 1;
10008 +               break;
10009 +       }
10010 +       vxdprintk(VXD_CBIT(net, 0),
10011 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
10012 +               nxa, NXAV6(nxa), addr, mask, ret);
10013 +       return ret;
10014 +}
10015 +
10016 +static inline
10017 +int v6_addr_in_nx_info(struct nx_info *nxi,
10018 +       const struct in6_addr *addr, uint16_t mask)
10019 +{
10020 +       struct nx_addr_v6 *nxa;
10021 +       int ret = 1;
10022 +
10023 +       if (!nxi)
10024 +               goto out;
10025 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
10026 +               if (v6_addr_match(nxa, addr, mask))
10027 +                       goto out;
10028 +       ret = 0;
10029 +out:
10030 +       vxdprintk(VXD_CBIT(net, 0),
10031 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
10032 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
10033 +       return ret;
10034 +}
10035 +
10036 +static inline
10037 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
10038 +{
10039 +       /* FIXME: needs full range checks */
10040 +       return v6_addr_match(nxa, &addr->ip, mask);
10041 +}
10042 +
10043 +static inline
10044 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
10045 +{
10046 +       struct nx_addr_v6 *ptr;
10047 +
10048 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
10049 +               if (v6_nx_addr_match(ptr, nxa, mask))
10050 +                       return 1;
10051 +       return 0;
10052 +}
10053 +
10054 +
10055 +/*
10056 + *     Check if a given address matches for a socket
10057 + *
10058 + *     nxi:            the socket's nx_info if any
10059 + *     addr:           to be verified address
10060 + */
10061 +static inline
10062 +int v6_sock_addr_match (
10063 +       struct nx_info *nxi,
10064 +       struct inet_sock *inet,
10065 +       struct in6_addr *addr)
10066 +{
10067 +       struct sock *sk = &inet->sk;
10068 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
10069 +
10070 +       if (!ipv6_addr_any(addr) &&
10071 +               ipv6_addr_equal(saddr, addr))
10072 +               return 1;
10073 +       if (ipv6_addr_any(saddr))
10074 +               return v6_addr_in_nx_info(nxi, addr, -1);
10075 +       return 0;
10076 +}
10077 +
10078 +/*
10079 + *     check if address is covered by socket
10080 + *
10081 + *     sk:     the socket to check against
10082 + *     addr:   the address in question (must be != 0)
10083 + */
10084 +
10085 +static inline
10086 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
10087 +{
10088 +       struct nx_info *nxi = sk->sk_nx_info;
10089 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
10090 +
10091 +       vxdprintk(VXD_CBIT(net, 5),
10092 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
10093 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
10094 +               (sk->sk_socket?sk->sk_socket->flags:0));
10095 +
10096 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
10097 +               return v6_addr_match(nxa, saddr, -1);
10098 +       } else if (nxi) {               /* match against nx_info */
10099 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
10100 +       } else {                        /* unrestricted any socket */
10101 +               return 1;
10102 +       }
10103 +}
10104 +
10105 +
10106 +/* inet related checks and helpers */
10107 +
10108 +
10109 +struct in_ifaddr;
10110 +struct net_device;
10111 +struct sock;
10112 +
10113 +
10114 +#include <linux/netdevice.h>
10115 +#include <linux/inetdevice.h>
10116 +#include <net/inet_timewait_sock.h>
10117 +
10118 +
10119 +int dev_in_nx_info(struct net_device *, struct nx_info *);
10120 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
10121 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
10122 +
10123 +
10124 +
10125 +static inline
10126 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
10127 +{
10128 +       if (!nxi)
10129 +               return 1;
10130 +       if (!ifa)
10131 +               return 0;
10132 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
10133 +}
10134 +
10135 +static inline
10136 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
10137 +{
10138 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
10139 +               nxi, nxi ? nxi->nx_id : 0, ifa,
10140 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
10141 +
10142 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
10143 +               return 1;
10144 +       if (v6_ifa_in_nx_info(ifa, nxi))
10145 +               return 1;
10146 +       return 0;
10147 +}
10148 +
10149 +
10150 +struct nx_v6_sock_addr {
10151 +       struct in6_addr saddr;  /* Address used for validation */
10152 +       struct in6_addr baddr;  /* Address used for socket bind */
10153 +};
10154 +
10155 +static inline
10156 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
10157 +       struct nx_v6_sock_addr *nsa)
10158 +{
10159 +       // struct sock *sk = &inet->sk;
10160 +       // struct nx_info *nxi = sk->sk_nx_info;
10161 +       struct in6_addr saddr = addr->sin6_addr;
10162 +       struct in6_addr baddr = saddr;
10163 +
10164 +       nsa->saddr = saddr;
10165 +       nsa->baddr = baddr;
10166 +       return 0;
10167 +}
10168 +
10169 +static inline
10170 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
10171 +{
10172 +       // struct sock *sk = &inet->sk;
10173 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
10174 +
10175 +       // *saddr = nsa->baddr;
10176 +       // inet->inet_saddr = nsa->baddr;
10177 +}
10178 +
10179 +static inline
10180 +int nx_info_has_v6(struct nx_info *nxi)
10181 +{
10182 +       if (!nxi)
10183 +               return 1;
10184 +       if (NX_IPV6(nxi))
10185 +               return 1;
10186 +       return 0;
10187 +}
10188 +
10189 +#else /* CONFIG_IPV6 */
10190 +
10191 +static inline
10192 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
10193 +{
10194 +       return 1;
10195 +}
10196 +
10197 +
10198 +static inline
10199 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
10200 +{
10201 +       return 1;
10202 +}
10203 +
10204 +static inline
10205 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
10206 +{
10207 +       return 1;
10208 +}
10209 +
10210 +static inline
10211 +int nx_info_has_v6(struct nx_info *nxi)
10212 +{
10213 +       return 0;
10214 +}
10215 +
10216 +#endif /* CONFIG_IPV6 */
10217 +
10218 +#define current_nx_info_has_v6() \
10219 +       nx_info_has_v6(current_nx_info())
10220 +
10221 +#else
10222 +#warning duplicate inclusion
10223 +#endif
10224 diff -NurpP --minimal linux-3.1.6/include/linux/vs_limit.h linux-3.1.6-vs2.3.2.5/include/linux/vs_limit.h
10225 --- linux-3.1.6/include/linux/vs_limit.h        1970-01-01 01:00:00.000000000 +0100
10226 +++ linux-3.1.6-vs2.3.2.5/include/linux/vs_limit.h      2011-10-24 18:53:33.000000000 +0200
10227 @@ -0,0 +1,140 @@
10228 +#ifndef _VS_LIMIT_H
10229 +#define _VS_LIMIT_H
10230 +
10231 +#include "vserver/limit.h"
10232 +#include "vserver/base.h"
10233 +#include "vserver/context.h"
10234 +#include "vserver/debug.h"
10235 +#include "vserver/context.h"
10236 +#include "vserver/limit_int.h"
10237 +
10238 +
10239 +#define vx_acc_cres(v, d, p, r) \
10240 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
10241 +
10242 +#define vx_acc_cres_cond(x, d, p, r) \
10243 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
10244 +       r, d, p, __FILE__, __LINE__)
10245 +
10246 +
10247 +#define vx_add_cres(v, a, p, r) \
10248 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
10249 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
10250 +
10251 +#define vx_add_cres_cond(x, a, p, r) \
10252 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
10253 +       r, a, p, __FILE__, __LINE__)
10254 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
10255 +
10256 +
10257 +/* process and file limits */
10258 +
10259 +#define vx_nproc_inc(p) \
10260 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
10261 +
10262 +#define vx_nproc_dec(p) \
10263 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
10264 +
10265 +#define vx_files_inc(f) \
10266 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
10267 +
10268 +#define vx_files_dec(f) \
10269 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
10270 +
10271 +#define vx_locks_inc(l) \
10272 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
10273 +
10274 +#define vx_locks_dec(l) \
10275 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
10276 +
10277 +#define vx_openfd_inc(f) \
10278 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
10279 +
10280 +#define vx_openfd_dec(f) \
10281 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
10282 +
10283 +
10284 +#define vx_cres_avail(v, n, r) \
10285 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
10286 +
10287 +
10288 +#define vx_nproc_avail(n) \
10289 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
10290 +
10291 +#define vx_files_avail(n) \
10292 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
10293 +
10294 +#define vx_locks_avail(n) \
10295 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
10296 +
10297 +#define vx_openfd_avail(n) \
10298 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
10299 +
10300 +
10301 +/* dentry limits */
10302 +
10303 +#define vx_dentry_inc(d) do {                                          \
10304 +       if ((d)->d_count == 1)                                          \
10305 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
10306 +       } while (0)
10307 +
10308 +#define vx_dentry_dec(d) do {                                          \
10309 +       if ((d)->d_count == 0)                                          \
10310 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
10311 +       } while (0)
10312 +
10313 +#define vx_dentry_avail(n) \
10314 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
10315 +
10316 +
10317 +/* socket limits */
10318 +
10319 +#define vx_sock_inc(s) \
10320 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
10321 +
10322 +#define vx_sock_dec(s) \
10323 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
10324 +
10325 +#define vx_sock_avail(n) \
10326 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
10327 +
10328 +
10329 +/* ipc resource limits */
10330 +
10331 +#define vx_ipcmsg_add(v, u, a) \
10332 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
10333 +
10334 +#define vx_ipcmsg_sub(v, u, a) \
10335 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
10336 +
10337 +#define vx_ipcmsg_avail(v, a) \
10338 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
10339 +
10340 +
10341 +#define vx_ipcshm_add(v, k, a) \
10342 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
10343 +
10344 +#define vx_ipcshm_sub(v, k, a) \
10345 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
10346 +
10347 +#define vx_ipcshm_avail(v, a) \
10348 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
10349 +
10350 +
10351 +#define vx_semary_inc(a) \
10352 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
10353 +
10354 +#define vx_semary_dec(a) \
10355 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
10356 +
10357 +
10358 +#define vx_nsems_add(a,n) \
10359 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
10360 +
10361 +#define vx_nsems_sub(a,n) \
10362 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
10363 +
10364 +
10365 +#else
10366 +#warning duplicate inclusion
10367 +#endif
10368 diff -NurpP --minimal linux-3.1.6/include/linux/vs_network.h linux-3.1.6-vs2.3.2.5/include/linux/vs_network.h
10369 --- linux-3.1.6/include/linux/vs_network.h      1970-01-01 01:00:00.000000000 +0100
10370 +++ linux-3.1.6-vs2.3.2.5/include/linux/vs_network.h    2011-10-24 18:53:33.000000000 +0200
10371 @@ -0,0 +1,169 @@
10372 +#ifndef _NX_VS_NETWORK_H
10373 +#define _NX_VS_NETWORK_H
10374 +
10375 +#include "vserver/context.h"
10376 +#include "vserver/network.h"
10377 +#include "vserver/base.h"
10378 +#include "vserver/check.h"
10379 +#include "vserver/debug.h"
10380 +
10381 +#include <linux/sched.h>
10382 +
10383 +
10384 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
10385 +
10386 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
10387 +       const char *_file, int _line)
10388 +{
10389 +       if (!nxi)
10390 +               return NULL;
10391 +
10392 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
10393 +               nxi, nxi ? nxi->nx_id : 0,
10394 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10395 +               _file, _line);
10396 +
10397 +       atomic_inc(&nxi->nx_usecnt);
10398 +       return nxi;
10399 +}
10400 +
10401 +
10402 +extern void free_nx_info(struct nx_info *);
10403 +
10404 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
10405 +
10406 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
10407 +{
10408 +       if (!nxi)
10409 +               return;
10410 +
10411 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
10412 +               nxi, nxi ? nxi->nx_id : 0,
10413 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10414 +               _file, _line);
10415 +
10416 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
10417 +               free_nx_info(nxi);
10418 +}
10419 +
10420 +
10421 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
10422 +
10423 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
10424 +               const char *_file, int _line)
10425 +{
10426 +       if (nxi) {
10427 +               vxlprintk(VXD_CBIT(nid, 3),
10428 +                       "init_nx_info(%p[#%d.%d])",
10429 +                       nxi, nxi ? nxi->nx_id : 0,
10430 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10431 +                       _file, _line);
10432 +
10433 +               atomic_inc(&nxi->nx_usecnt);
10434 +       }
10435 +       *nxp = nxi;
10436 +}
10437 +
10438 +
10439 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
10440 +
10441 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
10442 +       const char *_file, int _line)
10443 +{
10444 +       struct nx_info *nxo;
10445 +
10446 +       if (!nxi)
10447 +               return;
10448 +
10449 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
10450 +               nxi, nxi ? nxi->nx_id : 0,
10451 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10452 +               _file, _line);
10453 +
10454 +       atomic_inc(&nxi->nx_usecnt);
10455 +       nxo = xchg(nxp, nxi);
10456 +       BUG_ON(nxo);
10457 +}
10458 +
10459 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
10460 +
10461 +static inline void __clr_nx_info(struct nx_info **nxp,
10462 +       const char *_file, int _line)
10463 +{
10464 +       struct nx_info *nxo;
10465 +
10466 +       nxo = xchg(nxp, NULL);
10467 +       if (!nxo)
10468 +               return;
10469 +
10470 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
10471 +               nxo, nxo ? nxo->nx_id : 0,
10472 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
10473 +               _file, _line);
10474 +
10475 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
10476 +               free_nx_info(nxo);
10477 +}
10478 +
10479 +
10480 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
10481 +
10482 +static inline void __claim_nx_info(struct nx_info *nxi,
10483 +       struct task_struct *task, const char *_file, int _line)
10484 +{
10485 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
10486 +               nxi, nxi ? nxi->nx_id : 0,
10487 +               nxi?atomic_read(&nxi->nx_usecnt):0,
10488 +               nxi?atomic_read(&nxi->nx_tasks):0,
10489 +               task, _file, _line);
10490 +
10491 +       atomic_inc(&nxi->nx_tasks);
10492 +}
10493 +
10494 +
10495 +extern void unhash_nx_info(struct nx_info *);
10496 +
10497 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
10498 +
10499 +static inline void __release_nx_info(struct nx_info *nxi,
10500 +       struct task_struct *task, const char *_file, int _line)
10501 +{
10502 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
10503 +               nxi, nxi ? nxi->nx_id : 0,
10504 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
10505 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
10506 +               task, _file, _line);
10507 +
10508 +       might_sleep();
10509 +
10510 +       if (atomic_dec_and_test(&nxi->nx_tasks))
10511 +               unhash_nx_info(nxi);
10512 +}
10513 +
10514 +
10515 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
10516 +
10517 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
10518 +       const char *_file, int _line)
10519 +{
10520 +       struct nx_info *nxi;
10521 +
10522 +       task_lock(p);
10523 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
10524 +               p, _file, _line);
10525 +       nxi = __get_nx_info(p->nx_info, _file, _line);
10526 +       task_unlock(p);
10527 +       return nxi;
10528 +}
10529 +
10530 +
10531 +static inline void exit_nx_info(struct task_struct *p)
10532 +{
10533 +       if (p->nx_info)
10534 +               release_nx_info(p->nx_info, p);
10535 +}
10536 +
10537 +
10538 +#else
10539 +#warning duplicate inclusion
10540 +#endif
10541 diff -NurpP --minimal linux-3.1.6/include/linux/vs_pid.h linux-3.1.6-vs2.3.2.5/include/linux/vs_pid.h
10542 --- linux-3.1.6/include/linux/vs_pid.h  1970-01-01 01:00:00.000000000 +0100
10543 +++ linux-3.1.6-vs2.3.2.5/include/linux/vs_pid.h        2011-10-24 18:53:33.000000000 +0200
10544 @@ -0,0 +1,50 @@
10545 +#ifndef _VS_PID_H
10546 +#define _VS_PID_H
10547 +
10548 +#include "vserver/base.h"
10549 +#include "vserver/check.h"
10550 +#include "vserver/context.h"
10551 +#include "vserver/debug.h"
10552 +#include "vserver/pid.h"
10553 +#include <linux/pid_namespace.h>
10554 +
10555 +
10556 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
10557 +
10558 +static inline
10559 +int vx_proc_task_visible(struct task_struct *task)
10560 +{
10561 +       if ((task->pid == 1) &&
10562 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
10563 +               /* show a blend through init */
10564 +               goto visible;
10565 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
10566 +               goto visible;
10567 +       return 0;
10568 +visible:
10569 +       return 1;
10570 +}
10571 +
10572 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
10573 +
10574 +
10575 +static inline
10576 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
10577 +{
10578 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
10579 +
10580 +       if (task && !vx_proc_task_visible(task)) {
10581 +               vxdprintk(VXD_CBIT(misc, 6),
10582 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
10583 +                       task, task->xid, task->pid,
10584 +                       current, current->xid, current->pid);
10585 +               put_task_struct(task);
10586 +               task = NULL;
10587 +       }
10588 +       return task;
10589 +}
10590 +
10591 +
10592 +#else
10593 +#warning duplicate inclusion
10594 +#endif
10595 diff -NurpP --minimal linux-3.1.6/include/linux/vs_sched.h linux-3.1.6-vs2.3.2.5/include/linux/vs_sched.h
10596 --- linux-3.1.6/include/linux/vs_sched.h        1970-01-01 01:00:00.000000000 +0100
10597 +++ linux-3.1.6-vs2.3.2.5/include/linux/vs_sched.h      2011-10-24 18:53:33.000000000 +0200
10598 @@ -0,0 +1,40 @@
10599 +#ifndef _VS_SCHED_H
10600 +#define _VS_SCHED_H
10601 +
10602 +#include "vserver/base.h"
10603 +#include "vserver/context.h"
10604 +#include "vserver/sched.h"
10605 +
10606 +
10607 +#define MAX_PRIO_BIAS           20
10608 +#define MIN_PRIO_BIAS          -20
10609 +
10610 +static inline
10611 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
10612 +{
10613 +       struct vx_info *vxi = p->vx_info;
10614 +
10615 +       if (vxi)
10616 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
10617 +       return prio;
10618 +}
10619 +
10620 +static inline void vx_account_user(struct vx_info *vxi,
10621 +       cputime_t cputime, int nice)
10622 +{
10623 +       if (!vxi)
10624 +               return;
10625 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
10626 +}
10627 +
10628 +static inline void vx_account_system(struct vx_info *vxi,
10629 +       cputime_t cputime, int idle)
10630 +{
10631 +       if (!vxi)
10632 +               return;
10633 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
10634 +}
10635 +
10636 +#else
10637 +#warning duplicate inclusion
10638 +#endif
10639 diff -NurpP --minimal linux-3.1.6/include/linux/vs_socket.h linux-3.1.6-vs2.3.2.5/include/linux/vs_socket.h
10640 --- linux-3.1.6/include/linux/vs_socket.h       1970-01-01 01:00:00.000000000 +0100
10641 +++ linux-3.1.6-vs2.3.2.5/include/linux/vs_socket.h     2011-10-24 18:53:33.000000000 +0200
10642 @@ -0,0 +1,67 @@
10643 +#ifndef _VS_SOCKET_H
10644 +#define _VS_SOCKET_H
10645 +
10646 +#include "vserver/debug.h"
10647 +#include "vserver/base.h"
10648 +#include "vserver/cacct.h"
10649 +#include "vserver/context.h"
10650 +#include "vserver/tag.h"
10651 +
10652 +
10653 +/* socket accounting */
10654 +
10655 +#include <linux/socket.h>
10656 +
10657 +static inline int vx_sock_type(int family)
10658 +{
10659 +       switch (family) {
10660 +       case PF_UNSPEC:
10661 +               return VXA_SOCK_UNSPEC;
10662 +       case PF_UNIX:
10663 +               return VXA_SOCK_UNIX;
10664 +       case PF_INET:
10665 +               return VXA_SOCK_INET;
10666 +       case PF_INET6:
10667 +               return VXA_SOCK_INET6;
10668 +       case PF_PACKET:
10669 +               return VXA_SOCK_PACKET;
10670 +       default:
10671 +               return VXA_SOCK_OTHER;
10672 +       }
10673 +}
10674 +
10675 +#define vx_acc_sock(v, f, p, s) \
10676 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
10677 +
10678 +static inline void __vx_acc_sock(struct vx_info *vxi,
10679 +       int family, int pos, int size, char *file, int line)
10680 +{
10681 +       if (vxi) {
10682 +               int type = vx_sock_type(family);
10683 +
10684 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
10685 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
10686 +       }
10687 +}
10688 +
10689 +#define vx_sock_recv(sk, s) \
10690 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
10691 +#define vx_sock_send(sk, s) \
10692 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
10693 +#define vx_sock_fail(sk, s) \
10694 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
10695 +
10696 +
10697 +#define sock_vx_init(s) do {           \
10698 +       (s)->sk_xid = 0;                \
10699 +       (s)->sk_vx_info = NULL;         \
10700 +       } while (0)
10701 +
10702 +#define sock_nx_init(s) do {           \
10703 +       (s)->sk_nid = 0;                \
10704 +       (s)->sk_nx_info = NULL;         \
10705 +       } while (0)
10706 +
10707 +#else
10708 +#warning duplicate inclusion
10709 +#endif
10710 diff -NurpP --minimal linux-3.1.6/include/linux/vs_tag.h linux-3.1.6-vs2.3.2.5/include/linux/vs_tag.h
10711 --- linux-3.1.6/include/linux/vs_tag.h  1970-01-01 01:00:00.000000000 +0100
10712 +++ linux-3.1.6-vs2.3.2.5/include/linux/vs_tag.h        2011-10-24 18:53:33.000000000 +0200
10713 @@ -0,0 +1,47 @@
10714 +#ifndef _VS_TAG_H
10715 +#define _VS_TAG_H
10716 +
10717 +#include <linux/vserver/tag.h>
10718 +
10719 +/* check conditions */
10720 +
10721 +#define DX_ADMIN       0x0001
10722 +#define DX_WATCH       0x0002
10723 +#define DX_HOSTID      0x0008
10724 +
10725 +#define DX_IDENT       0x0010
10726 +
10727 +#define DX_ARG_MASK    0x0010
10728 +
10729 +
10730 +#define dx_task_tag(t) ((t)->tag)
10731 +
10732 +#define dx_current_tag() dx_task_tag(current)
10733 +
10734 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
10735 +
10736 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
10737 +
10738 +
10739 +/*
10740 + * check current context for ADMIN/WATCH and
10741 + * optionally against supplied argument
10742 + */
10743 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
10744 +{
10745 +       if (mode & DX_ARG_MASK) {
10746 +               if ((mode & DX_IDENT) && (id == cid))
10747 +                       return 1;
10748 +       }
10749 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
10750 +               ((mode & DX_WATCH) && (cid == 1)) ||
10751 +               ((mode & DX_HOSTID) && (id == 0)));
10752 +}
10753 +
10754 +struct inode;
10755 +int dx_permission(const struct inode *inode, int mask);
10756 +
10757 +
10758 +#else
10759 +#warning duplicate inclusion
10760 +#endif
10761 diff -NurpP --minimal linux-3.1.6/include/linux/vs_time.h linux-3.1.6-vs2.3.2.5/include/linux/vs_time.h
10762 --- linux-3.1.6/include/linux/vs_time.h 1970-01-01 01:00:00.000000000 +0100
10763 +++ linux-3.1.6-vs2.3.2.5/include/linux/vs_time.h       2011-10-24 18:53:33.000000000 +0200
10764 @@ -0,0 +1,19 @@
10765 +#ifndef _VS_TIME_H
10766 +#define _VS_TIME_H
10767 +
10768 +
10769 +/* time faking stuff */
10770 +
10771 +#ifdef CONFIG_VSERVER_VTIME
10772 +
10773 +extern void vx_adjust_timespec(struct timespec *ts);
10774 +extern int vx_settimeofday(const struct timespec *ts);
10775 +
10776 +#else
10777 +#define        vx_adjust_timespec(t)   do { } while (0)
10778 +#define        vx_settimeofday(t)      do_settimeofday(t)
10779 +#endif
10780 +
10781 +#else
10782 +#warning duplicate inclusion
10783 +#endif
10784 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/Kbuild linux-3.1.6-vs2.3.2.5/include/linux/vserver/Kbuild
10785 --- linux-3.1.6/include/linux/vserver/Kbuild    1970-01-01 01:00:00.000000000 +0100
10786 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/Kbuild  2011-10-24 18:53:33.000000000 +0200
10787 @@ -0,0 +1,8 @@
10788 +
10789 +header-y += context_cmd.h network_cmd.h space_cmd.h \
10790 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
10791 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
10792 +       debug_cmd.h device_cmd.h
10793 +
10794 +header-y += switch.h network.h monitor.h inode.h device.h
10795 +
10796 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/base.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/base.h
10797 --- linux-3.1.6/include/linux/vserver/base.h    1970-01-01 01:00:00.000000000 +0100
10798 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/base.h  2011-10-24 18:53:33.000000000 +0200
10799 @@ -0,0 +1,178 @@
10800 +#ifndef _VX_BASE_H
10801 +#define _VX_BASE_H
10802 +
10803 +
10804 +/* context state changes */
10805 +
10806 +enum {
10807 +       VSC_STARTUP = 1,
10808 +       VSC_SHUTDOWN,
10809 +
10810 +       VSC_NETUP,
10811 +       VSC_NETDOWN,
10812 +};
10813 +
10814 +
10815 +
10816 +#define vx_task_xid(t) ((t)->xid)
10817 +
10818 +#define vx_current_xid() vx_task_xid(current)
10819 +
10820 +#define current_vx_info() (current->vx_info)
10821 +
10822 +
10823 +#define nx_task_nid(t) ((t)->nid)
10824 +
10825 +#define nx_current_nid() nx_task_nid(current)
10826 +
10827 +#define current_nx_info() (current->nx_info)
10828 +
10829 +
10830 +/* generic flag merging */
10831 +
10832 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10833 +
10834 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10835 +
10836 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10837 +
10838 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10839 +
10840 +
10841 +/* context flags */
10842 +
10843 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10844 +
10845 +#define vx_current_flags()     __vx_flags(current_vx_info())
10846 +
10847 +#define vx_info_flags(v, m, f) \
10848 +       vs_check_flags(__vx_flags(v), m, f)
10849 +
10850 +#define task_vx_flags(t, m, f) \
10851 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10852 +
10853 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10854 +
10855 +
10856 +/* context caps */
10857 +
10858 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10859 +
10860 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
10861 +
10862 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10863 +
10864 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
10865 +
10866 +
10867 +
10868 +/* network flags */
10869 +
10870 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10871 +
10872 +#define nx_current_flags()     __nx_flags(current_nx_info())
10873 +
10874 +#define nx_info_flags(n, m, f) \
10875 +       vs_check_flags(__nx_flags(n), m, f)
10876 +
10877 +#define task_nx_flags(t, m, f) \
10878 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10879 +
10880 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10881 +
10882 +
10883 +/* network caps */
10884 +
10885 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10886 +
10887 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
10888 +
10889 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10890 +
10891 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
10892 +
10893 +
10894 +/* context mask capabilities */
10895 +
10896 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10897 +
10898 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10899 +
10900 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
10901 +
10902 +
10903 +/* context bcap mask */
10904 +
10905 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10906 +
10907 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
10908 +
10909 +
10910 +/* mask given bcaps */
10911 +
10912 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10913 +
10914 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
10915 +
10916 +
10917 +/* masked cap_bset */
10918 +
10919 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10920 +
10921 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
10922 +
10923 +#if 0
10924 +#define vx_info_mbcap(v, b) \
10925 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10926 +       vx_info_bcaps(v, b) : (b))
10927 +
10928 +#define task_vx_mbcap(t, b) \
10929 +       vx_info_mbcap((t)->vx_info, (t)->b)
10930 +
10931 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10932 +#endif
10933 +
10934 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10935 +
10936 +#define vx_capable(b, c) (capable(b) || \
10937 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10938 +
10939 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
10940 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10941 +
10942 +#define nx_capable(b, c) (capable(b) || \
10943 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10944 +
10945 +#define vx_task_initpid(t, n) \
10946 +       ((t)->vx_info && \
10947 +       ((t)->vx_info->vx_initpid == (n)))
10948 +
10949 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
10950 +
10951 +
10952 +/* context unshare mask */
10953 +
10954 +#define __vx_umask(v)          ((v)->vx_umask)
10955 +
10956 +#define vx_current_umask()     __vx_umask(current_vx_info())
10957 +
10958 +#define vx_can_unshare(b, f) (capable(b) || \
10959 +       (cap_raised(current_cap(), b) && \
10960 +       !((f) & ~vx_current_umask())))
10961 +
10962 +
10963 +#define __vx_wmask(v)          ((v)->vx_wmask)
10964 +
10965 +#define vx_current_wmask()     __vx_wmask(current_vx_info())
10966 +
10967 +
10968 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10969 +
10970 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10971 +
10972 +
10973 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10974 +
10975 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10976 +
10977 +#endif
10978 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/cacct.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/cacct.h
10979 --- linux-3.1.6/include/linux/vserver/cacct.h   1970-01-01 01:00:00.000000000 +0100
10980 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/cacct.h 2011-10-24 18:53:33.000000000 +0200
10981 @@ -0,0 +1,15 @@
10982 +#ifndef _VX_CACCT_H
10983 +#define _VX_CACCT_H
10984 +
10985 +
10986 +enum sock_acc_field {
10987 +       VXA_SOCK_UNSPEC = 0,
10988 +       VXA_SOCK_UNIX,
10989 +       VXA_SOCK_INET,
10990 +       VXA_SOCK_INET6,
10991 +       VXA_SOCK_PACKET,
10992 +       VXA_SOCK_OTHER,
10993 +       VXA_SOCK_SIZE   /* array size */
10994 +};
10995 +
10996 +#endif /* _VX_CACCT_H */
10997 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/cacct_cmd.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/cacct_cmd.h
10998 --- linux-3.1.6/include/linux/vserver/cacct_cmd.h       1970-01-01 01:00:00.000000000 +0100
10999 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/cacct_cmd.h     2011-10-24 18:53:33.000000000 +0200
11000 @@ -0,0 +1,23 @@
11001 +#ifndef _VX_CACCT_CMD_H
11002 +#define _VX_CACCT_CMD_H
11003 +
11004 +
11005 +/* virtual host info name commands */
11006 +
11007 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
11008 +
11009 +struct vcmd_sock_stat_v0 {
11010 +       uint32_t field;
11011 +       uint32_t count[3];
11012 +       uint64_t total[3];
11013 +};
11014 +
11015 +
11016 +#ifdef __KERNEL__
11017 +
11018 +#include <linux/compiler.h>
11019 +
11020 +extern int vc_sock_stat(struct vx_info *, void __user *);
11021 +
11022 +#endif /* __KERNEL__ */
11023 +#endif /* _VX_CACCT_CMD_H */
11024 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/cacct_def.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/cacct_def.h
11025 --- linux-3.1.6/include/linux/vserver/cacct_def.h       1970-01-01 01:00:00.000000000 +0100
11026 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/cacct_def.h     2011-10-24 18:53:33.000000000 +0200
11027 @@ -0,0 +1,43 @@
11028 +#ifndef _VX_CACCT_DEF_H
11029 +#define _VX_CACCT_DEF_H
11030 +
11031 +#include <asm/atomic.h>
11032 +#include <linux/vserver/cacct.h>
11033 +
11034 +
11035 +struct _vx_sock_acc {
11036 +       atomic_long_t count;
11037 +       atomic_long_t total;
11038 +};
11039 +
11040 +/* context sub struct */
11041 +
11042 +struct _vx_cacct {
11043 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
11044 +       atomic_t slab[8];
11045 +       atomic_t page[6][8];
11046 +};
11047 +
11048 +#ifdef CONFIG_VSERVER_DEBUG
11049 +
11050 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
11051 +{
11052 +       int i, j;
11053 +
11054 +       printk("\t_vx_cacct:");
11055 +       for (i = 0; i < 6; i++) {
11056 +               struct _vx_sock_acc *ptr = cacct->sock[i];
11057 +
11058 +               printk("\t [%d] =", i);
11059 +               for (j = 0; j < 3; j++) {
11060 +                       printk(" [%d] = %8lu, %8lu", j,
11061 +                               atomic_long_read(&ptr[j].count),
11062 +                               atomic_long_read(&ptr[j].total));
11063 +               }
11064 +               printk("\n");
11065 +       }
11066 +}
11067 +
11068 +#endif
11069 +
11070 +#endif /* _VX_CACCT_DEF_H */
11071 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/cacct_int.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/cacct_int.h
11072 --- linux-3.1.6/include/linux/vserver/cacct_int.h       1970-01-01 01:00:00.000000000 +0100
11073 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/cacct_int.h     2011-10-24 18:53:33.000000000 +0200
11074 @@ -0,0 +1,21 @@
11075 +#ifndef _VX_CACCT_INT_H
11076 +#define _VX_CACCT_INT_H
11077 +
11078 +
11079 +#ifdef __KERNEL__
11080 +
11081 +static inline
11082 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
11083 +{
11084 +       return atomic_long_read(&cacct->sock[type][pos].count);
11085 +}
11086 +
11087 +
11088 +static inline
11089 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
11090 +{
11091 +       return atomic_long_read(&cacct->sock[type][pos].total);
11092 +}
11093 +
11094 +#endif /* __KERNEL__ */
11095 +#endif /* _VX_CACCT_INT_H */
11096 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/check.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/check.h
11097 --- linux-3.1.6/include/linux/vserver/check.h   1970-01-01 01:00:00.000000000 +0100
11098 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/check.h 2011-10-24 18:53:33.000000000 +0200
11099 @@ -0,0 +1,89 @@
11100 +#ifndef _VS_CHECK_H
11101 +#define _VS_CHECK_H
11102 +
11103 +
11104 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
11105 +
11106 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
11107 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
11108 +#else
11109 +#define MIN_D_CONTEXT  65536
11110 +#endif
11111 +
11112 +/* check conditions */
11113 +
11114 +#define VS_ADMIN       0x0001
11115 +#define VS_WATCH       0x0002
11116 +#define VS_HIDE                0x0004
11117 +#define VS_HOSTID      0x0008
11118 +
11119 +#define VS_IDENT       0x0010
11120 +#define VS_EQUIV       0x0020
11121 +#define VS_PARENT      0x0040
11122 +#define VS_CHILD       0x0080
11123 +
11124 +#define VS_ARG_MASK    0x00F0
11125 +
11126 +#define VS_DYNAMIC     0x0100
11127 +#define VS_STATIC      0x0200
11128 +
11129 +#define VS_ATR_MASK    0x0F00
11130 +
11131 +#ifdef CONFIG_VSERVER_PRIVACY
11132 +#define VS_ADMIN_P     (0)
11133 +#define VS_WATCH_P     (0)
11134 +#else
11135 +#define VS_ADMIN_P     VS_ADMIN
11136 +#define VS_WATCH_P     VS_WATCH
11137 +#endif
11138 +
11139 +#define VS_HARDIRQ     0x1000
11140 +#define VS_SOFTIRQ     0x2000
11141 +#define VS_IRQ         0x4000
11142 +
11143 +#define VS_IRQ_MASK    0xF000
11144 +
11145 +#include <linux/hardirq.h>
11146 +
11147 +/*
11148 + * check current context for ADMIN/WATCH and
11149 + * optionally against supplied argument
11150 + */
11151 +static inline int __vs_check(int cid, int id, unsigned int mode)
11152 +{
11153 +       if (mode & VS_ARG_MASK) {
11154 +               if ((mode & VS_IDENT) && (id == cid))
11155 +                       return 1;
11156 +       }
11157 +       if (mode & VS_ATR_MASK) {
11158 +               if ((mode & VS_DYNAMIC) &&
11159 +                       (id >= MIN_D_CONTEXT) &&
11160 +                       (id <= MAX_S_CONTEXT))
11161 +                       return 1;
11162 +               if ((mode & VS_STATIC) &&
11163 +                       (id > 1) && (id < MIN_D_CONTEXT))
11164 +                       return 1;
11165 +       }
11166 +       if (mode & VS_IRQ_MASK) {
11167 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
11168 +                       return 1;
11169 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
11170 +                       return 1;
11171 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
11172 +                       return 1;
11173 +       }
11174 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
11175 +               ((mode & VS_WATCH) && (cid == 1)) ||
11176 +               ((mode & VS_HOSTID) && (id == 0)));
11177 +}
11178 +
11179 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
11180 +
11181 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
11182 +
11183 +
11184 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
11185 +
11186 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
11187 +
11188 +#endif
11189 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/context.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/context.h
11190 --- linux-3.1.6/include/linux/vserver/context.h 1970-01-01 01:00:00.000000000 +0100
11191 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/context.h       2011-11-18 00:40:25.000000000 +0100
11192 @@ -0,0 +1,188 @@
11193 +#ifndef _VX_CONTEXT_H
11194 +#define _VX_CONTEXT_H
11195 +
11196 +#include <linux/types.h>
11197 +#include <linux/capability.h>
11198 +
11199 +
11200 +/* context flags */
11201 +
11202 +#define VXF_INFO_SCHED         0x00000002
11203 +#define VXF_INFO_NPROC         0x00000004
11204 +#define VXF_INFO_PRIVATE       0x00000008
11205 +
11206 +#define VXF_INFO_INIT          0x00000010
11207 +#define VXF_INFO_HIDE          0x00000020
11208 +#define VXF_INFO_ULIMIT                0x00000040
11209 +#define VXF_INFO_NSPACE                0x00000080
11210 +
11211 +#define VXF_SCHED_HARD         0x00000100
11212 +#define VXF_SCHED_PRIO         0x00000200
11213 +#define VXF_SCHED_PAUSE                0x00000400
11214 +
11215 +#define VXF_VIRT_MEM           0x00010000
11216 +#define VXF_VIRT_UPTIME                0x00020000
11217 +#define VXF_VIRT_CPU           0x00040000
11218 +#define VXF_VIRT_LOAD          0x00080000
11219 +#define VXF_VIRT_TIME          0x00100000
11220 +
11221 +#define VXF_HIDE_MOUNT         0x01000000
11222 +/* was VXF_HIDE_NETIF          0x02000000 */
11223 +#define VXF_HIDE_VINFO         0x04000000
11224 +
11225 +#define VXF_STATE_SETUP                (1ULL << 32)
11226 +#define VXF_STATE_INIT         (1ULL << 33)
11227 +#define VXF_STATE_ADMIN                (1ULL << 34)
11228 +
11229 +#define VXF_SC_HELPER          (1ULL << 36)
11230 +#define VXF_REBOOT_KILL                (1ULL << 37)
11231 +#define VXF_PERSISTENT         (1ULL << 38)
11232 +
11233 +#define VXF_FORK_RSS           (1ULL << 48)
11234 +#define VXF_PROLIFIC           (1ULL << 49)
11235 +
11236 +#define VXF_IGNEG_NICE         (1ULL << 52)
11237 +
11238 +#define VXF_ONE_TIME           (0x0007ULL << 32)
11239 +
11240 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
11241 +
11242 +
11243 +/* context migration */
11244 +
11245 +#define VXM_SET_INIT           0x00000001
11246 +#define VXM_SET_REAPER         0x00000002
11247 +
11248 +/* context caps */
11249 +
11250 +#define VXC_SET_UTSNAME                0x00000001
11251 +#define VXC_SET_RLIMIT         0x00000002
11252 +#define VXC_FS_SECURITY                0x00000004
11253 +#define VXC_FS_TRUSTED         0x00000008
11254 +#define VXC_TIOCSTI            0x00000010
11255 +
11256 +/* was VXC_RAW_ICMP            0x00000100 */
11257 +#define VXC_SYSLOG             0x00001000
11258 +#define VXC_OOM_ADJUST         0x00002000
11259 +#define VXC_AUDIT_CONTROL      0x00004000
11260 +
11261 +#define VXC_SECURE_MOUNT       0x00010000
11262 +#define VXC_SECURE_REMOUNT     0x00020000
11263 +#define VXC_BINARY_MOUNT       0x00040000
11264 +
11265 +#define VXC_QUOTA_CTL          0x00100000
11266 +#define VXC_ADMIN_MAPPER       0x00200000
11267 +#define VXC_ADMIN_CLOOP                0x00400000
11268 +
11269 +#define VXC_KTHREAD            0x01000000
11270 +#define VXC_NAMESPACE          0x02000000
11271 +
11272 +
11273 +#ifdef __KERNEL__
11274 +
11275 +#include <linux/list.h>
11276 +#include <linux/spinlock.h>
11277 +#include <linux/rcupdate.h>
11278 +
11279 +#include "limit_def.h"
11280 +#include "sched_def.h"
11281 +#include "cvirt_def.h"
11282 +#include "cacct_def.h"
11283 +#include "device_def.h"
11284 +
11285 +#define VX_SPACES      2
11286 +
11287 +struct _vx_info_pc {
11288 +       struct _vx_sched_pc sched_pc;
11289 +       struct _vx_cvirt_pc cvirt_pc;
11290 +};
11291 +
11292 +struct _vx_space {
11293 +       unsigned long vx_nsmask;                /* assignment mask */
11294 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
11295 +       struct fs_struct *vx_fs;                /* private namespace fs */
11296 +       const struct cred *vx_cred;             /* task credentials */
11297 +};
11298 +
11299 +struct vx_info {
11300 +       struct hlist_node vx_hlist;             /* linked list of contexts */
11301 +       xid_t vx_id;                            /* context id */
11302 +       atomic_t vx_usecnt;                     /* usage count */
11303 +       atomic_t vx_tasks;                      /* tasks count */
11304 +       struct vx_info *vx_parent;              /* parent context */
11305 +       int vx_state;                           /* context state */
11306 +
11307 +       struct _vx_space space[VX_SPACES];      /* namespace store */
11308 +
11309 +       uint64_t vx_flags;                      /* context flags */
11310 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
11311 +       uint64_t vx_umask;                      /* unshare mask (guest) */
11312 +       uint64_t vx_wmask;                      /* warn mask (guest) */
11313 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
11314 +
11315 +       struct task_struct *vx_reaper;          /* guest reaper process */
11316 +       pid_t vx_initpid;                       /* PID of guest init */
11317 +       int64_t vx_badness_bias;                /* OOM points bias */
11318 +
11319 +       struct _vx_limit limit;                 /* vserver limits */
11320 +       struct _vx_sched sched;                 /* vserver scheduler */
11321 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
11322 +       struct _vx_cacct cacct;                 /* context accounting */
11323 +
11324 +       struct _vx_device dmap;                 /* default device map targets */
11325 +
11326 +#ifndef CONFIG_SMP
11327 +       struct _vx_info_pc info_pc;             /* per cpu data */
11328 +#else
11329 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
11330 +#endif
11331 +
11332 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
11333 +       int reboot_cmd;                         /* last sys_reboot() cmd */
11334 +       int exit_code;                          /* last process exit code */
11335 +
11336 +       char vx_name[65];                       /* vserver name */
11337 +};
11338 +
11339 +#ifndef CONFIG_SMP
11340 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
11341 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
11342 +#else
11343 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
11344 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
11345 +#endif
11346 +
11347 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
11348 +
11349 +
11350 +struct vx_info_save {
11351 +       struct vx_info *vxi;
11352 +       xid_t xid;
11353 +};
11354 +
11355 +
11356 +/* status flags */
11357 +
11358 +#define VXS_HASHED     0x0001
11359 +#define VXS_PAUSED     0x0010
11360 +#define VXS_SHUTDOWN   0x0100
11361 +#define VXS_HELPER     0x1000
11362 +#define VXS_RELEASED   0x8000
11363 +
11364 +
11365 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
11366 +extern void release_vx_info(struct vx_info *, struct task_struct *);
11367 +
11368 +extern struct vx_info *lookup_vx_info(int);
11369 +extern struct vx_info *lookup_or_create_vx_info(int);
11370 +
11371 +extern int get_xid_list(int, unsigned int *, int);
11372 +extern int xid_is_hashed(xid_t);
11373 +
11374 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
11375 +
11376 +extern long vs_state_change(struct vx_info *, unsigned int);
11377 +
11378 +
11379 +#endif /* __KERNEL__ */
11380 +#endif /* _VX_CONTEXT_H */
11381 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/context_cmd.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/context_cmd.h
11382 --- linux-3.1.6/include/linux/vserver/context_cmd.h     1970-01-01 01:00:00.000000000 +0100
11383 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/context_cmd.h   2011-10-24 18:53:33.000000000 +0200
11384 @@ -0,0 +1,162 @@
11385 +#ifndef _VX_CONTEXT_CMD_H
11386 +#define _VX_CONTEXT_CMD_H
11387 +
11388 +
11389 +/* vinfo commands */
11390 +
11391 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
11392 +
11393 +#ifdef __KERNEL__
11394 +extern int vc_task_xid(uint32_t);
11395 +
11396 +#endif /* __KERNEL__ */
11397 +
11398 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
11399 +
11400 +struct vcmd_vx_info_v0 {
11401 +       uint32_t xid;
11402 +       uint32_t initpid;
11403 +       /* more to come */
11404 +};
11405 +
11406 +#ifdef __KERNEL__
11407 +extern int vc_vx_info(struct vx_info *, void __user *);
11408 +
11409 +#endif /* __KERNEL__ */
11410 +
11411 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
11412 +
11413 +struct vcmd_ctx_stat_v0 {
11414 +       uint32_t usecnt;
11415 +       uint32_t tasks;
11416 +       /* more to come */
11417 +};
11418 +
11419 +#ifdef __KERNEL__
11420 +extern int vc_ctx_stat(struct vx_info *, void __user *);
11421 +
11422 +#endif /* __KERNEL__ */
11423 +
11424 +/* context commands */
11425 +
11426 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
11427 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
11428 +
11429 +struct vcmd_ctx_create {
11430 +       uint64_t flagword;
11431 +};
11432 +
11433 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
11434 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
11435 +
11436 +struct vcmd_ctx_migrate {
11437 +       uint64_t flagword;
11438 +};
11439 +
11440 +#ifdef __KERNEL__
11441 +extern int vc_ctx_create(uint32_t, void __user *);
11442 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
11443 +
11444 +#endif /* __KERNEL__ */
11445 +
11446 +
11447 +/* flag commands */
11448 +
11449 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
11450 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
11451 +
11452 +struct vcmd_ctx_flags_v0 {
11453 +       uint64_t flagword;
11454 +       uint64_t mask;
11455 +};
11456 +
11457 +#ifdef __KERNEL__
11458 +extern int vc_get_cflags(struct vx_info *, void __user *);
11459 +extern int vc_set_cflags(struct vx_info *, void __user *);
11460 +
11461 +#endif /* __KERNEL__ */
11462 +
11463 +
11464 +/* context caps commands */
11465 +
11466 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
11467 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
11468 +
11469 +struct vcmd_ctx_caps_v1 {
11470 +       uint64_t ccaps;
11471 +       uint64_t cmask;
11472 +};
11473 +
11474 +#ifdef __KERNEL__
11475 +extern int vc_get_ccaps(struct vx_info *, void __user *);
11476 +extern int vc_set_ccaps(struct vx_info *, void __user *);
11477 +
11478 +#endif /* __KERNEL__ */
11479 +
11480 +
11481 +/* bcaps commands */
11482 +
11483 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
11484 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
11485 +
11486 +struct vcmd_bcaps {
11487 +       uint64_t bcaps;
11488 +       uint64_t bmask;
11489 +};
11490 +
11491 +#ifdef __KERNEL__
11492 +extern int vc_get_bcaps(struct vx_info *, void __user *);
11493 +extern int vc_set_bcaps(struct vx_info *, void __user *);
11494 +
11495 +#endif /* __KERNEL__ */
11496 +
11497 +
11498 +/* umask commands */
11499 +
11500 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
11501 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
11502 +
11503 +struct vcmd_umask {
11504 +       uint64_t umask;
11505 +       uint64_t mask;
11506 +};
11507 +
11508 +#ifdef __KERNEL__
11509 +extern int vc_get_umask(struct vx_info *, void __user *);
11510 +extern int vc_set_umask(struct vx_info *, void __user *);
11511 +
11512 +#endif /* __KERNEL__ */
11513 +
11514 +
11515 +/* wmask commands */
11516 +
11517 +#define VCMD_get_wmask         VC_CMD(FLAGS, 15, 0)
11518 +#define VCMD_set_wmask         VC_CMD(FLAGS, 16, 0)
11519 +
11520 +struct vcmd_wmask {
11521 +       uint64_t wmask;
11522 +       uint64_t mask;
11523 +};
11524 +
11525 +#ifdef __KERNEL__
11526 +extern int vc_get_wmask(struct vx_info *, void __user *);
11527 +extern int vc_set_wmask(struct vx_info *, void __user *);
11528 +
11529 +#endif /* __KERNEL__ */
11530 +
11531 +
11532 +/* OOM badness */
11533 +
11534 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
11535 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
11536 +
11537 +struct vcmd_badness_v0 {
11538 +       int64_t bias;
11539 +};
11540 +
11541 +#ifdef __KERNEL__
11542 +extern int vc_get_badness(struct vx_info *, void __user *);
11543 +extern int vc_set_badness(struct vx_info *, void __user *);
11544 +
11545 +#endif /* __KERNEL__ */
11546 +#endif /* _VX_CONTEXT_CMD_H */
11547 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/cvirt.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/cvirt.h
11548 --- linux-3.1.6/include/linux/vserver/cvirt.h   1970-01-01 01:00:00.000000000 +0100
11549 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/cvirt.h 2011-10-24 18:53:33.000000000 +0200
11550 @@ -0,0 +1,20 @@
11551 +#ifndef _VX_CVIRT_H
11552 +#define _VX_CVIRT_H
11553 +
11554 +
11555 +#ifdef __KERNEL__
11556 +
11557 +struct timespec;
11558 +
11559 +void vx_vsi_uptime(struct timespec *, struct timespec *);
11560 +
11561 +
11562 +struct vx_info;
11563 +
11564 +void vx_update_load(struct vx_info *);
11565 +
11566 +
11567 +int vx_do_syslog(int, char __user *, int);
11568 +
11569 +#endif /* __KERNEL__ */
11570 +#endif /* _VX_CVIRT_H */
11571 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/cvirt_cmd.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/cvirt_cmd.h
11572 --- linux-3.1.6/include/linux/vserver/cvirt_cmd.h       1970-01-01 01:00:00.000000000 +0100
11573 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/cvirt_cmd.h     2011-10-24 18:53:33.000000000 +0200
11574 @@ -0,0 +1,53 @@
11575 +#ifndef _VX_CVIRT_CMD_H
11576 +#define _VX_CVIRT_CMD_H
11577 +
11578 +
11579 +/* virtual host info name commands */
11580 +
11581 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
11582 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
11583 +
11584 +struct vcmd_vhi_name_v0 {
11585 +       uint32_t field;
11586 +       char name[65];
11587 +};
11588 +
11589 +
11590 +enum vhi_name_field {
11591 +       VHIN_CONTEXT = 0,
11592 +       VHIN_SYSNAME,
11593 +       VHIN_NODENAME,
11594 +       VHIN_RELEASE,
11595 +       VHIN_VERSION,
11596 +       VHIN_MACHINE,
11597 +       VHIN_DOMAINNAME,
11598 +};
11599 +
11600 +
11601 +#ifdef __KERNEL__
11602 +
11603 +#include <linux/compiler.h>
11604 +
11605 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
11606 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
11607 +
11608 +#endif /* __KERNEL__ */
11609 +
11610 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
11611 +
11612 +struct vcmd_virt_stat_v0 {
11613 +       uint64_t offset;
11614 +       uint64_t uptime;
11615 +       uint32_t nr_threads;
11616 +       uint32_t nr_running;
11617 +       uint32_t nr_uninterruptible;
11618 +       uint32_t nr_onhold;
11619 +       uint32_t nr_forks;
11620 +       uint32_t load[3];
11621 +};
11622 +
11623 +#ifdef __KERNEL__
11624 +extern int vc_virt_stat(struct vx_info *, void __user *);
11625 +
11626 +#endif /* __KERNEL__ */
11627 +#endif /* _VX_CVIRT_CMD_H */
11628 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/cvirt_def.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/cvirt_def.h
11629 --- linux-3.1.6/include/linux/vserver/cvirt_def.h       1970-01-01 01:00:00.000000000 +0100
11630 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/cvirt_def.h     2011-10-24 18:53:33.000000000 +0200
11631 @@ -0,0 +1,80 @@
11632 +#ifndef _VX_CVIRT_DEF_H
11633 +#define _VX_CVIRT_DEF_H
11634 +
11635 +#include <linux/jiffies.h>
11636 +#include <linux/spinlock.h>
11637 +#include <linux/wait.h>
11638 +#include <linux/time.h>
11639 +#include <asm/atomic.h>
11640 +
11641 +
11642 +struct _vx_usage_stat {
11643 +       uint64_t user;
11644 +       uint64_t nice;
11645 +       uint64_t system;
11646 +       uint64_t softirq;
11647 +       uint64_t irq;
11648 +       uint64_t idle;
11649 +       uint64_t iowait;
11650 +};
11651 +
11652 +struct _vx_syslog {
11653 +       wait_queue_head_t log_wait;
11654 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
11655 +
11656 +       unsigned long log_start;        /* next char to be read by syslog() */
11657 +       unsigned long con_start;        /* next char to be sent to consoles */
11658 +       unsigned long log_end;  /* most-recently-written-char + 1 */
11659 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
11660 +
11661 +       char log_buf[1024];
11662 +};
11663 +
11664 +
11665 +/* context sub struct */
11666 +
11667 +struct _vx_cvirt {
11668 +       atomic_t nr_threads;            /* number of current threads */
11669 +       atomic_t nr_running;            /* number of running threads */
11670 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
11671 +
11672 +       atomic_t nr_onhold;             /* processes on hold */
11673 +       uint32_t onhold_last;           /* jiffies when put on hold */
11674 +
11675 +       struct timespec bias_ts;        /* time offset to the host */
11676 +       struct timespec bias_idle;
11677 +       struct timespec bias_uptime;    /* context creation point */
11678 +       uint64_t bias_clock;            /* offset in clock_t */
11679 +
11680 +       spinlock_t load_lock;           /* lock for the load averages */
11681 +       atomic_t load_updates;          /* nr of load updates done so far */
11682 +       uint32_t load_last;             /* last time load was calculated */
11683 +       uint32_t load[3];               /* load averages 1,5,15 */
11684 +
11685 +       atomic_t total_forks;           /* number of forks so far */
11686 +
11687 +       struct _vx_syslog syslog;
11688 +};
11689 +
11690 +struct _vx_cvirt_pc {
11691 +       struct _vx_usage_stat cpustat;
11692 +};
11693 +
11694 +
11695 +#ifdef CONFIG_VSERVER_DEBUG
11696 +
11697 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
11698 +{
11699 +       printk("\t_vx_cvirt:\n");
11700 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
11701 +               atomic_read(&cvirt->nr_threads),
11702 +               atomic_read(&cvirt->nr_running),
11703 +               atomic_read(&cvirt->nr_uninterruptible),
11704 +               atomic_read(&cvirt->nr_onhold));
11705 +       /* add rest here */
11706 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
11707 +}
11708 +
11709 +#endif
11710 +
11711 +#endif /* _VX_CVIRT_DEF_H */
11712 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/debug.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/debug.h
11713 --- linux-3.1.6/include/linux/vserver/debug.h   1970-01-01 01:00:00.000000000 +0100
11714 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/debug.h 2011-11-18 12:56:11.000000000 +0100
11715 @@ -0,0 +1,145 @@
11716 +#ifndef _VX_DEBUG_H
11717 +#define _VX_DEBUG_H
11718 +
11719 +
11720 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
11721 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
11722 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
11723 +
11724 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
11725 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
11726 +#define VXF_DEV                "%p[%lu,%d:%d]"
11727 +
11728 +#if    defined(CONFIG_QUOTES_UTF8)
11729 +#define        VS_Q_LQM        "\xc2\xbb"
11730 +#define        VS_Q_RQM        "\xc2\xab"
11731 +#elif  defined(CONFIG_QUOTES_ASCII)
11732 +#define        VS_Q_LQM        "\x27"
11733 +#define        VS_Q_RQM        "\x27"
11734 +#else
11735 +#define        VS_Q_LQM        "\xbb"
11736 +#define        VS_Q_RQM        "\xab"
11737 +#endif
11738 +
11739 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
11740 +
11741 +
11742 +#define vxd_path(p)                                            \
11743 +       ({ static char _buffer[PATH_MAX];                       \
11744 +          d_path(p, _buffer, sizeof(_buffer)); })
11745 +
11746 +#define vxd_cond_path(n)                                       \
11747 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
11748 +
11749 +
11750 +#ifdef CONFIG_VSERVER_DEBUG
11751 +
11752 +extern unsigned int vs_debug_switch;
11753 +extern unsigned int vs_debug_xid;
11754 +extern unsigned int vs_debug_nid;
11755 +extern unsigned int vs_debug_tag;
11756 +extern unsigned int vs_debug_net;
11757 +extern unsigned int vs_debug_limit;
11758 +extern unsigned int vs_debug_cres;
11759 +extern unsigned int vs_debug_dlim;
11760 +extern unsigned int vs_debug_quota;
11761 +extern unsigned int vs_debug_cvirt;
11762 +extern unsigned int vs_debug_space;
11763 +extern unsigned int vs_debug_perm;
11764 +extern unsigned int vs_debug_misc;
11765 +
11766 +
11767 +#define VX_LOGLEVEL    "vxD: "
11768 +#define VX_PROC_FMT    "%p: "
11769 +#define VX_PROCESS     current
11770 +
11771 +#define vxdprintk(c, f, x...)                                  \
11772 +       do {                                                    \
11773 +               if (c)                                          \
11774 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
11775 +                               VX_PROCESS , ##x);              \
11776 +       } while (0)
11777 +
11778 +#define vxlprintk(c, f, x...)                                  \
11779 +       do {                                                    \
11780 +               if (c)                                          \
11781 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
11782 +       } while (0)
11783 +
11784 +#define vxfprintk(c, f, x...)                                  \
11785 +       do {                                                    \
11786 +               if (c)                                          \
11787 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
11788 +       } while (0)
11789 +
11790 +
11791 +struct vx_info;
11792 +
11793 +void dump_vx_info(struct vx_info *, int);
11794 +void dump_vx_info_inactive(int);
11795 +
11796 +#else  /* CONFIG_VSERVER_DEBUG */
11797 +
11798 +#define vs_debug_switch        0
11799 +#define vs_debug_xid   0
11800 +#define vs_debug_nid   0
11801 +#define vs_debug_tag   0
11802 +#define vs_debug_net   0
11803 +#define vs_debug_limit 0
11804 +#define vs_debug_cres  0
11805 +#define vs_debug_dlim  0
11806 +#define vs_debug_quota 0
11807 +#define vs_debug_cvirt 0
11808 +#define vs_debug_space 0
11809 +#define vs_debug_perm  0
11810 +#define vs_debug_misc  0
11811 +
11812 +#define vxdprintk(x...) do { } while (0)
11813 +#define vxlprintk(x...) do { } while (0)
11814 +#define vxfprintk(x...) do { } while (0)
11815 +
11816 +#endif /* CONFIG_VSERVER_DEBUG */
11817 +
11818 +
11819 +#ifdef CONFIG_VSERVER_WARN
11820 +
11821 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
11822 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
11823 +#define VX_WARN_XID    "[xid #%u] "
11824 +#define VX_WARN_NID    "[nid #%u] "
11825 +#define VX_WARN_TAG    "[tag #%u] "
11826 +
11827 +#define vxwprintk(c, f, x...)                                  \
11828 +       do {                                                    \
11829 +               if (c)                                          \
11830 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
11831 +       } while (0)
11832 +
11833 +#else  /* CONFIG_VSERVER_WARN */
11834 +
11835 +#define vxwprintk(x...) do { } while (0)
11836 +
11837 +#endif /* CONFIG_VSERVER_WARN */
11838 +
11839 +#define vxwprintk_task(c, f, x...)                             \
11840 +       vxwprintk(c, VX_WARN_TASK f,                            \
11841 +               current->comm, current->pid,                    \
11842 +               current->xid, current->nid, current->tag, ##x)
11843 +#define vxwprintk_xid(c, f, x...)                              \
11844 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
11845 +#define vxwprintk_nid(c, f, x...)                              \
11846 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
11847 +#define vxwprintk_tag(c, f, x...)                              \
11848 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
11849 +
11850 +#ifdef CONFIG_VSERVER_DEBUG
11851 +#define vxd_assert_lock(l)     assert_spin_locked(l)
11852 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
11853 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
11854 +#else
11855 +#define vxd_assert_lock(l)     do { } while (0)
11856 +#define vxd_assert(c, f, x...) do { } while (0)
11857 +#endif
11858 +
11859 +
11860 +#endif /* _VX_DEBUG_H */
11861 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/debug_cmd.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/debug_cmd.h
11862 --- linux-3.1.6/include/linux/vserver/debug_cmd.h       1970-01-01 01:00:00.000000000 +0100
11863 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/debug_cmd.h     2011-10-24 18:53:33.000000000 +0200
11864 @@ -0,0 +1,58 @@
11865 +#ifndef _VX_DEBUG_CMD_H
11866 +#define _VX_DEBUG_CMD_H
11867 +
11868 +
11869 +/* debug commands */
11870 +
11871 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
11872 +
11873 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
11874 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
11875 +
11876 +struct  vcmd_read_history_v0 {
11877 +       uint32_t index;
11878 +       uint32_t count;
11879 +       char __user *data;
11880 +};
11881 +
11882 +struct  vcmd_read_monitor_v0 {
11883 +       uint32_t index;
11884 +       uint32_t count;
11885 +       char __user *data;
11886 +};
11887 +
11888 +
11889 +#ifdef __KERNEL__
11890 +
11891 +#ifdef CONFIG_COMPAT
11892 +
11893 +#include <asm/compat.h>
11894 +
11895 +struct vcmd_read_history_v0_x32 {
11896 +       uint32_t index;
11897 +       uint32_t count;
11898 +       compat_uptr_t data_ptr;
11899 +};
11900 +
11901 +struct vcmd_read_monitor_v0_x32 {
11902 +       uint32_t index;
11903 +       uint32_t count;
11904 +       compat_uptr_t data_ptr;
11905 +};
11906 +
11907 +#endif  /* CONFIG_COMPAT */
11908 +
11909 +extern int vc_dump_history(uint32_t);
11910 +
11911 +extern int vc_read_history(uint32_t, void __user *);
11912 +extern int vc_read_monitor(uint32_t, void __user *);
11913 +
11914 +#ifdef CONFIG_COMPAT
11915 +
11916 +extern int vc_read_history_x32(uint32_t, void __user *);
11917 +extern int vc_read_monitor_x32(uint32_t, void __user *);
11918 +
11919 +#endif  /* CONFIG_COMPAT */
11920 +
11921 +#endif /* __KERNEL__ */
11922 +#endif /* _VX_DEBUG_CMD_H */
11923 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/device.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/device.h
11924 --- linux-3.1.6/include/linux/vserver/device.h  1970-01-01 01:00:00.000000000 +0100
11925 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/device.h        2011-10-24 18:53:33.000000000 +0200
11926 @@ -0,0 +1,15 @@
11927 +#ifndef _VX_DEVICE_H
11928 +#define _VX_DEVICE_H
11929 +
11930 +
11931 +#define DATTR_CREATE   0x00000001
11932 +#define DATTR_OPEN     0x00000002
11933 +
11934 +#define DATTR_REMAP    0x00000010
11935 +
11936 +#define DATTR_MASK     0x00000013
11937 +
11938 +
11939 +#else  /* _VX_DEVICE_H */
11940 +#warning duplicate inclusion
11941 +#endif /* _VX_DEVICE_H */
11942 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/device_cmd.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/device_cmd.h
11943 --- linux-3.1.6/include/linux/vserver/device_cmd.h      1970-01-01 01:00:00.000000000 +0100
11944 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/device_cmd.h    2011-10-24 18:53:33.000000000 +0200
11945 @@ -0,0 +1,44 @@
11946 +#ifndef _VX_DEVICE_CMD_H
11947 +#define _VX_DEVICE_CMD_H
11948 +
11949 +
11950 +/*  device vserver commands */
11951 +
11952 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
11953 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
11954 +
11955 +struct vcmd_set_mapping_v0 {
11956 +       const char __user *device;
11957 +       const char __user *target;
11958 +       uint32_t flags;
11959 +};
11960 +
11961 +
11962 +#ifdef __KERNEL__
11963 +
11964 +#ifdef CONFIG_COMPAT
11965 +
11966 +#include <asm/compat.h>
11967 +
11968 +struct vcmd_set_mapping_v0_x32 {
11969 +       compat_uptr_t device_ptr;
11970 +       compat_uptr_t target_ptr;
11971 +       uint32_t flags;
11972 +};
11973 +
11974 +#endif /* CONFIG_COMPAT */
11975 +
11976 +#include <linux/compiler.h>
11977 +
11978 +extern int vc_set_mapping(struct vx_info *, void __user *);
11979 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11980 +
11981 +#ifdef CONFIG_COMPAT
11982 +
11983 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11984 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11985 +
11986 +#endif /* CONFIG_COMPAT */
11987 +
11988 +#endif /* __KERNEL__ */
11989 +#endif /* _VX_DEVICE_CMD_H */
11990 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/device_def.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/device_def.h
11991 --- linux-3.1.6/include/linux/vserver/device_def.h      1970-01-01 01:00:00.000000000 +0100
11992 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/device_def.h    2011-10-24 18:53:33.000000000 +0200
11993 @@ -0,0 +1,17 @@
11994 +#ifndef _VX_DEVICE_DEF_H
11995 +#define _VX_DEVICE_DEF_H
11996 +
11997 +#include <linux/types.h>
11998 +
11999 +struct vx_dmap_target {
12000 +       dev_t target;
12001 +       uint32_t flags;
12002 +};
12003 +
12004 +struct _vx_device {
12005 +#ifdef CONFIG_VSERVER_DEVICE
12006 +       struct vx_dmap_target targets[2];
12007 +#endif
12008 +};
12009 +
12010 +#endif /* _VX_DEVICE_DEF_H */
12011 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/dlimit.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/dlimit.h
12012 --- linux-3.1.6/include/linux/vserver/dlimit.h  1970-01-01 01:00:00.000000000 +0100
12013 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/dlimit.h        2011-10-24 18:53:33.000000000 +0200
12014 @@ -0,0 +1,54 @@
12015 +#ifndef _VX_DLIMIT_H
12016 +#define _VX_DLIMIT_H
12017 +
12018 +#include "switch.h"
12019 +
12020 +
12021 +#ifdef __KERNEL__
12022 +
12023 +/*      keep in sync with CDLIM_INFINITY       */
12024 +
12025 +#define DLIM_INFINITY          (~0ULL)
12026 +
12027 +#include <linux/spinlock.h>
12028 +#include <linux/rcupdate.h>
12029 +
12030 +struct super_block;
12031 +
12032 +struct dl_info {
12033 +       struct hlist_node dl_hlist;             /* linked list of contexts */
12034 +       struct rcu_head dl_rcu;                 /* the rcu head */
12035 +       tag_t dl_tag;                           /* context tag */
12036 +       atomic_t dl_usecnt;                     /* usage count */
12037 +       atomic_t dl_refcnt;                     /* reference count */
12038 +
12039 +       struct super_block *dl_sb;              /* associated superblock */
12040 +
12041 +       spinlock_t dl_lock;                     /* protect the values */
12042 +
12043 +       unsigned long long dl_space_used;       /* used space in bytes */
12044 +       unsigned long long dl_space_total;      /* maximum space in bytes */
12045 +       unsigned long dl_inodes_used;           /* used inodes */
12046 +       unsigned long dl_inodes_total;          /* maximum inodes */
12047 +
12048 +       unsigned int dl_nrlmult;                /* non root limit mult */
12049 +};
12050 +
12051 +struct rcu_head;
12052 +
12053 +extern void rcu_free_dl_info(struct rcu_head *);
12054 +extern void unhash_dl_info(struct dl_info *);
12055 +
12056 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
12057 +
12058 +
12059 +struct kstatfs;
12060 +
12061 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
12062 +
12063 +typedef uint64_t dlsize_t;
12064 +
12065 +#endif /* __KERNEL__ */
12066 +#else  /* _VX_DLIMIT_H */
12067 +#warning duplicate inclusion
12068 +#endif /* _VX_DLIMIT_H */
12069 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/dlimit_cmd.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/dlimit_cmd.h
12070 --- linux-3.1.6/include/linux/vserver/dlimit_cmd.h      1970-01-01 01:00:00.000000000 +0100
12071 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/dlimit_cmd.h    2011-10-24 18:53:33.000000000 +0200
12072 @@ -0,0 +1,109 @@
12073 +#ifndef _VX_DLIMIT_CMD_H
12074 +#define _VX_DLIMIT_CMD_H
12075 +
12076 +
12077 +/*  dlimit vserver commands */
12078 +
12079 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
12080 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
12081 +
12082 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
12083 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
12084 +
12085 +struct vcmd_ctx_dlimit_base_v0 {
12086 +       const char __user *name;
12087 +       uint32_t flags;
12088 +};
12089 +
12090 +struct vcmd_ctx_dlimit_v0 {
12091 +       const char __user *name;
12092 +       uint32_t space_used;                    /* used space in kbytes */
12093 +       uint32_t space_total;                   /* maximum space in kbytes */
12094 +       uint32_t inodes_used;                   /* used inodes */
12095 +       uint32_t inodes_total;                  /* maximum inodes */
12096 +       uint32_t reserved;                      /* reserved for root in % */
12097 +       uint32_t flags;
12098 +};
12099 +
12100 +#define CDLIM_UNSET            ((uint32_t)0UL)
12101 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
12102 +#define CDLIM_KEEP             ((uint32_t)~1UL)
12103 +
12104 +#define DLIME_UNIT     0
12105 +#define DLIME_KILO     1
12106 +#define DLIME_MEGA     2
12107 +#define DLIME_GIGA     3
12108 +
12109 +#define DLIMF_SHIFT    0x10
12110 +
12111 +#define DLIMS_USED     0
12112 +#define DLIMS_TOTAL    2
12113 +
12114 +static inline
12115 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
12116 +{
12117 +       int exp = (flags & DLIMF_SHIFT) ?
12118 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
12119 +       return ((uint64_t)val) << (10 * exp);
12120 +}
12121 +
12122 +static inline
12123 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
12124 +{
12125 +       int exp = 0;
12126 +
12127 +       if (*flags & DLIMF_SHIFT) {
12128 +               while (val > (1LL << 32) && (exp < 3)) {
12129 +                       val >>= 10;
12130 +                       exp++;
12131 +               }
12132 +               *flags &= ~(DLIME_GIGA << shift);
12133 +               *flags |= exp << shift;
12134 +       } else
12135 +               val >>= 10;
12136 +       return val;
12137 +}
12138 +
12139 +#ifdef __KERNEL__
12140 +
12141 +#ifdef CONFIG_COMPAT
12142 +
12143 +#include <asm/compat.h>
12144 +
12145 +struct vcmd_ctx_dlimit_base_v0_x32 {
12146 +       compat_uptr_t name_ptr;
12147 +       uint32_t flags;
12148 +};
12149 +
12150 +struct vcmd_ctx_dlimit_v0_x32 {
12151 +       compat_uptr_t name_ptr;
12152 +       uint32_t space_used;                    /* used space in kbytes */
12153 +       uint32_t space_total;                   /* maximum space in kbytes */
12154 +       uint32_t inodes_used;                   /* used inodes */
12155 +       uint32_t inodes_total;                  /* maximum inodes */
12156 +       uint32_t reserved;                      /* reserved for root in % */
12157 +       uint32_t flags;
12158 +};
12159 +
12160 +#endif /* CONFIG_COMPAT */
12161 +
12162 +#include <linux/compiler.h>
12163 +
12164 +extern int vc_add_dlimit(uint32_t, void __user *);
12165 +extern int vc_rem_dlimit(uint32_t, void __user *);
12166 +
12167 +extern int vc_set_dlimit(uint32_t, void __user *);
12168 +extern int vc_get_dlimit(uint32_t, void __user *);
12169 +
12170 +#ifdef CONFIG_COMPAT
12171 +
12172 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
12173 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
12174 +
12175 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
12176 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
12177 +
12178 +#endif /* CONFIG_COMPAT */
12179 +
12180 +#endif /* __KERNEL__ */
12181 +#endif /* _VX_DLIMIT_CMD_H */
12182 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/global.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/global.h
12183 --- linux-3.1.6/include/linux/vserver/global.h  1970-01-01 01:00:00.000000000 +0100
12184 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/global.h        2011-10-24 18:53:33.000000000 +0200
12185 @@ -0,0 +1,19 @@
12186 +#ifndef _VX_GLOBAL_H
12187 +#define _VX_GLOBAL_H
12188 +
12189 +
12190 +extern atomic_t vx_global_ctotal;
12191 +extern atomic_t vx_global_cactive;
12192 +
12193 +extern atomic_t nx_global_ctotal;
12194 +extern atomic_t nx_global_cactive;
12195 +
12196 +extern atomic_t vs_global_nsproxy;
12197 +extern atomic_t vs_global_fs;
12198 +extern atomic_t vs_global_mnt_ns;
12199 +extern atomic_t vs_global_uts_ns;
12200 +extern atomic_t vs_global_user_ns;
12201 +extern atomic_t vs_global_pid_ns;
12202 +
12203 +
12204 +#endif /* _VX_GLOBAL_H */
12205 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/history.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/history.h
12206 --- linux-3.1.6/include/linux/vserver/history.h 1970-01-01 01:00:00.000000000 +0100
12207 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/history.h       2011-10-24 18:53:33.000000000 +0200
12208 @@ -0,0 +1,197 @@
12209 +#ifndef _VX_HISTORY_H
12210 +#define _VX_HISTORY_H
12211 +
12212 +
12213 +enum {
12214 +       VXH_UNUSED = 0,
12215 +       VXH_THROW_OOPS = 1,
12216 +
12217 +       VXH_GET_VX_INFO,
12218 +       VXH_PUT_VX_INFO,
12219 +       VXH_INIT_VX_INFO,
12220 +       VXH_SET_VX_INFO,
12221 +       VXH_CLR_VX_INFO,
12222 +       VXH_CLAIM_VX_INFO,
12223 +       VXH_RELEASE_VX_INFO,
12224 +       VXH_ALLOC_VX_INFO,
12225 +       VXH_DEALLOC_VX_INFO,
12226 +       VXH_HASH_VX_INFO,
12227 +       VXH_UNHASH_VX_INFO,
12228 +       VXH_LOC_VX_INFO,
12229 +       VXH_LOOKUP_VX_INFO,
12230 +       VXH_CREATE_VX_INFO,
12231 +};
12232 +
12233 +struct _vxhe_vxi {
12234 +       struct vx_info *ptr;
12235 +       unsigned xid;
12236 +       unsigned usecnt;
12237 +       unsigned tasks;
12238 +};
12239 +
12240 +struct _vxhe_set_clr {
12241 +       void *data;
12242 +};
12243 +
12244 +struct _vxhe_loc_lookup {
12245 +       unsigned arg;
12246 +};
12247 +
12248 +struct _vx_hist_entry {
12249 +       void *loc;
12250 +       unsigned short seq;
12251 +       unsigned short type;
12252 +       struct _vxhe_vxi vxi;
12253 +       union {
12254 +               struct _vxhe_set_clr sc;
12255 +               struct _vxhe_loc_lookup ll;
12256 +       };
12257 +};
12258 +
12259 +#ifdef CONFIG_VSERVER_HISTORY
12260 +
12261 +extern unsigned volatile int vxh_active;
12262 +
12263 +struct _vx_hist_entry *vxh_advance(void *loc);
12264 +
12265 +
12266 +static inline
12267 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
12268 +{
12269 +       entry->vxi.ptr = vxi;
12270 +       if (vxi) {
12271 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
12272 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
12273 +               entry->vxi.xid = vxi->vx_id;
12274 +       }
12275 +}
12276 +
12277 +
12278 +#define        __HERE__ current_text_addr()
12279 +
12280 +#define __VXH_BODY(__type, __data, __here)     \
12281 +       struct _vx_hist_entry *entry;           \
12282 +                                               \
12283 +       preempt_disable();                      \
12284 +       entry = vxh_advance(__here);            \
12285 +       __data;                                 \
12286 +       entry->type = __type;                   \
12287 +       preempt_enable();
12288 +
12289 +
12290 +       /* pass vxi only */
12291 +
12292 +#define __VXH_SMPL                             \
12293 +       __vxh_copy_vxi(entry, vxi)
12294 +
12295 +static inline
12296 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
12297 +{
12298 +       __VXH_BODY(__type, __VXH_SMPL, __here)
12299 +}
12300 +
12301 +       /* pass vxi and data (void *) */
12302 +
12303 +#define __VXH_DATA                             \
12304 +       __vxh_copy_vxi(entry, vxi);             \
12305 +       entry->sc.data = data
12306 +
12307 +static inline
12308 +void   __vxh_data(struct vx_info *vxi, void *data,
12309 +                       int __type, void *__here)
12310 +{
12311 +       __VXH_BODY(__type, __VXH_DATA, __here)
12312 +}
12313 +
12314 +       /* pass vxi and arg (long) */
12315 +
12316 +#define __VXH_LONG                             \
12317 +       __vxh_copy_vxi(entry, vxi);             \
12318 +       entry->ll.arg = arg
12319 +
12320 +static inline
12321 +void   __vxh_long(struct vx_info *vxi, long arg,
12322 +                       int __type, void *__here)
12323 +{
12324 +       __VXH_BODY(__type, __VXH_LONG, __here)
12325 +}
12326 +
12327 +
12328 +static inline
12329 +void   __vxh_throw_oops(void *__here)
12330 +{
12331 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
12332 +       /* prevent further acquisition */
12333 +       vxh_active = 0;
12334 +}
12335 +
12336 +
12337 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
12338 +
12339 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
12340 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
12341 +
12342 +#define __vxh_init_vx_info(v, d, h) \
12343 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
12344 +#define __vxh_set_vx_info(v, d, h) \
12345 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
12346 +#define __vxh_clr_vx_info(v, d, h) \
12347 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
12348 +
12349 +#define __vxh_claim_vx_info(v, d, h) \
12350 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
12351 +#define __vxh_release_vx_info(v, d, h) \
12352 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
12353 +
12354 +#define vxh_alloc_vx_info(v) \
12355 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
12356 +#define vxh_dealloc_vx_info(v) \
12357 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
12358 +
12359 +#define vxh_hash_vx_info(v) \
12360 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
12361 +#define vxh_unhash_vx_info(v) \
12362 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
12363 +
12364 +#define vxh_loc_vx_info(v, l) \
12365 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
12366 +#define vxh_lookup_vx_info(v, l) \
12367 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
12368 +#define vxh_create_vx_info(v, l) \
12369 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
12370 +
12371 +extern void vxh_dump_history(void);
12372 +
12373 +
12374 +#else  /* CONFIG_VSERVER_HISTORY */
12375 +
12376 +#define        __HERE__        0
12377 +
12378 +#define vxh_throw_oops()               do { } while (0)
12379 +
12380 +#define __vxh_get_vx_info(v, h)                do { } while (0)
12381 +#define __vxh_put_vx_info(v, h)                do { } while (0)
12382 +
12383 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
12384 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
12385 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
12386 +
12387 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
12388 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
12389 +
12390 +#define vxh_alloc_vx_info(v)           do { } while (0)
12391 +#define vxh_dealloc_vx_info(v)         do { } while (0)
12392 +
12393 +#define vxh_hash_vx_info(v)            do { } while (0)
12394 +#define vxh_unhash_vx_info(v)          do { } while (0)
12395 +
12396 +#define vxh_loc_vx_info(v, l)          do { } while (0)
12397 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
12398 +#define vxh_create_vx_info(v, l)       do { } while (0)
12399 +
12400 +#define vxh_dump_history()             do { } while (0)
12401 +
12402 +
12403 +#endif /* CONFIG_VSERVER_HISTORY */
12404 +
12405 +#endif /* _VX_HISTORY_H */
12406 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/inode.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/inode.h
12407 --- linux-3.1.6/include/linux/vserver/inode.h   1970-01-01 01:00:00.000000000 +0100
12408 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/inode.h 2011-10-24 18:53:33.000000000 +0200
12409 @@ -0,0 +1,39 @@
12410 +#ifndef _VX_INODE_H
12411 +#define _VX_INODE_H
12412 +
12413 +
12414 +#define IATTR_TAG      0x01000000
12415 +
12416 +#define IATTR_ADMIN    0x00000001
12417 +#define IATTR_WATCH    0x00000002
12418 +#define IATTR_HIDE     0x00000004
12419 +#define IATTR_FLAGS    0x00000007
12420 +
12421 +#define IATTR_BARRIER  0x00010000
12422 +#define IATTR_IXUNLINK 0x00020000
12423 +#define IATTR_IMMUTABLE 0x00040000
12424 +#define IATTR_COW      0x00080000
12425 +
12426 +#ifdef __KERNEL__
12427 +
12428 +
12429 +#ifdef CONFIG_VSERVER_PROC_SECURE
12430 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
12431 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
12432 +#else
12433 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
12434 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
12435 +#endif
12436 +
12437 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
12438 +
12439 +#endif /* __KERNEL__ */
12440 +
12441 +/* inode ioctls */
12442 +
12443 +#define FIOC_GETXFLG   _IOR('x', 5, long)
12444 +#define FIOC_SETXFLG   _IOW('x', 6, long)
12445 +
12446 +#else  /* _VX_INODE_H */
12447 +#warning duplicate inclusion
12448 +#endif /* _VX_INODE_H */
12449 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/inode_cmd.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/inode_cmd.h
12450 --- linux-3.1.6/include/linux/vserver/inode_cmd.h       1970-01-01 01:00:00.000000000 +0100
12451 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/inode_cmd.h     2011-10-24 18:53:33.000000000 +0200
12452 @@ -0,0 +1,59 @@
12453 +#ifndef _VX_INODE_CMD_H
12454 +#define _VX_INODE_CMD_H
12455 +
12456 +
12457 +/*  inode vserver commands */
12458 +
12459 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
12460 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
12461 +
12462 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
12463 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
12464 +
12465 +struct vcmd_ctx_iattr_v1 {
12466 +       const char __user *name;
12467 +       uint32_t tag;
12468 +       uint32_t flags;
12469 +       uint32_t mask;
12470 +};
12471 +
12472 +struct vcmd_ctx_fiattr_v0 {
12473 +       uint32_t tag;
12474 +       uint32_t flags;
12475 +       uint32_t mask;
12476 +};
12477 +
12478 +
12479 +#ifdef __KERNEL__
12480 +
12481 +
12482 +#ifdef CONFIG_COMPAT
12483 +
12484 +#include <asm/compat.h>
12485 +
12486 +struct vcmd_ctx_iattr_v1_x32 {
12487 +       compat_uptr_t name_ptr;
12488 +       uint32_t tag;
12489 +       uint32_t flags;
12490 +       uint32_t mask;
12491 +};
12492 +
12493 +#endif /* CONFIG_COMPAT */
12494 +
12495 +#include <linux/compiler.h>
12496 +
12497 +extern int vc_get_iattr(void __user *);
12498 +extern int vc_set_iattr(void __user *);
12499 +
12500 +extern int vc_fget_iattr(uint32_t, void __user *);
12501 +extern int vc_fset_iattr(uint32_t, void __user *);
12502 +
12503 +#ifdef CONFIG_COMPAT
12504 +
12505 +extern int vc_get_iattr_x32(void __user *);
12506 +extern int vc_set_iattr_x32(void __user *);
12507 +
12508 +#endif /* CONFIG_COMPAT */
12509 +
12510 +#endif /* __KERNEL__ */
12511 +#endif /* _VX_INODE_CMD_H */
12512 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/limit.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/limit.h
12513 --- linux-3.1.6/include/linux/vserver/limit.h   1970-01-01 01:00:00.000000000 +0100
12514 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/limit.h 2011-10-24 18:53:33.000000000 +0200
12515 @@ -0,0 +1,71 @@
12516 +#ifndef _VX_LIMIT_H
12517 +#define _VX_LIMIT_H
12518 +
12519 +#define VLIMIT_NSOCK   16
12520 +#define VLIMIT_OPENFD  17
12521 +#define VLIMIT_ANON    18
12522 +#define VLIMIT_SHMEM   19
12523 +#define VLIMIT_SEMARY  20
12524 +#define VLIMIT_NSEMS   21
12525 +#define VLIMIT_DENTRY  22
12526 +#define VLIMIT_MAPPED  23
12527 +
12528 +
12529 +#ifdef __KERNEL__
12530 +
12531 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
12532 +
12533 +/*     keep in sync with CRLIM_INFINITY */
12534 +
12535 +#define        VLIM_INFINITY   (~0ULL)
12536 +
12537 +#include <asm/atomic.h>
12538 +#include <asm/resource.h>
12539 +
12540 +#ifndef RLIM_INFINITY
12541 +#warning RLIM_INFINITY is undefined
12542 +#endif
12543 +
12544 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
12545 +
12546 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
12547 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
12548 +
12549 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
12550 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
12551 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
12552 +
12553 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
12554 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
12555 +
12556 +typedef atomic_long_t rlim_atomic_t;
12557 +typedef unsigned long rlim_t;
12558 +
12559 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
12560 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
12561 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
12562 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
12563 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
12564 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
12565 +
12566 +
12567 +#if    (RLIM_INFINITY == VLIM_INFINITY)
12568 +#define        VX_VLIM(r) ((long long)(long)(r))
12569 +#define        VX_RLIM(v) ((rlim_t)(v))
12570 +#else
12571 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
12572 +               ? VLIM_INFINITY : (long long)(r))
12573 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
12574 +               ? RLIM_INFINITY : (rlim_t)(v))
12575 +#endif
12576 +
12577 +struct sysinfo;
12578 +
12579 +void vx_vsi_meminfo(struct sysinfo *);
12580 +void vx_vsi_swapinfo(struct sysinfo *);
12581 +long vx_vsi_cached(struct sysinfo *);
12582 +
12583 +#define NUM_LIMITS     24
12584 +
12585 +#endif /* __KERNEL__ */
12586 +#endif /* _VX_LIMIT_H */
12587 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/limit_cmd.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/limit_cmd.h
12588 --- linux-3.1.6/include/linux/vserver/limit_cmd.h       1970-01-01 01:00:00.000000000 +0100
12589 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/limit_cmd.h     2011-10-24 18:53:33.000000000 +0200
12590 @@ -0,0 +1,71 @@
12591 +#ifndef _VX_LIMIT_CMD_H
12592 +#define _VX_LIMIT_CMD_H
12593 +
12594 +
12595 +/*  rlimit vserver commands */
12596 +
12597 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
12598 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
12599 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
12600 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
12601 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
12602 +
12603 +struct vcmd_ctx_rlimit_v0 {
12604 +       uint32_t id;
12605 +       uint64_t minimum;
12606 +       uint64_t softlimit;
12607 +       uint64_t maximum;
12608 +};
12609 +
12610 +struct vcmd_ctx_rlimit_mask_v0 {
12611 +       uint32_t minimum;
12612 +       uint32_t softlimit;
12613 +       uint32_t maximum;
12614 +};
12615 +
12616 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
12617 +
12618 +struct vcmd_rlimit_stat_v0 {
12619 +       uint32_t id;
12620 +       uint32_t hits;
12621 +       uint64_t value;
12622 +       uint64_t minimum;
12623 +       uint64_t maximum;
12624 +};
12625 +
12626 +#define CRLIM_UNSET            (0ULL)
12627 +#define CRLIM_INFINITY         (~0ULL)
12628 +#define CRLIM_KEEP             (~1ULL)
12629 +
12630 +#ifdef __KERNEL__
12631 +
12632 +#ifdef CONFIG_IA32_EMULATION
12633 +
12634 +struct vcmd_ctx_rlimit_v0_x32 {
12635 +       uint32_t id;
12636 +       uint64_t minimum;
12637 +       uint64_t softlimit;
12638 +       uint64_t maximum;
12639 +} __attribute__ ((packed));
12640 +
12641 +#endif /* CONFIG_IA32_EMULATION */
12642 +
12643 +#include <linux/compiler.h>
12644 +
12645 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
12646 +extern int vc_get_rlimit(struct vx_info *, void __user *);
12647 +extern int vc_set_rlimit(struct vx_info *, void __user *);
12648 +extern int vc_reset_hits(struct vx_info *, void __user *);
12649 +extern int vc_reset_minmax(struct vx_info *, void __user *);
12650 +
12651 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
12652 +
12653 +#ifdef CONFIG_IA32_EMULATION
12654 +
12655 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
12656 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
12657 +
12658 +#endif /* CONFIG_IA32_EMULATION */
12659 +
12660 +#endif /* __KERNEL__ */
12661 +#endif /* _VX_LIMIT_CMD_H */
12662 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/limit_def.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/limit_def.h
12663 --- linux-3.1.6/include/linux/vserver/limit_def.h       1970-01-01 01:00:00.000000000 +0100
12664 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/limit_def.h     2011-10-24 18:53:33.000000000 +0200
12665 @@ -0,0 +1,47 @@
12666 +#ifndef _VX_LIMIT_DEF_H
12667 +#define _VX_LIMIT_DEF_H
12668 +
12669 +#include <asm/atomic.h>
12670 +#include <asm/resource.h>
12671 +
12672 +#include "limit.h"
12673 +
12674 +
12675 +struct _vx_res_limit {
12676 +       rlim_t soft;            /* Context soft limit */
12677 +       rlim_t hard;            /* Context hard limit */
12678 +
12679 +       rlim_atomic_t rcur;     /* Current value */
12680 +       rlim_t rmin;            /* Context minimum */
12681 +       rlim_t rmax;            /* Context maximum */
12682 +
12683 +       atomic_t lhit;          /* Limit hits */
12684 +};
12685 +
12686 +/* context sub struct */
12687 +
12688 +struct _vx_limit {
12689 +       struct _vx_res_limit res[NUM_LIMITS];
12690 +};
12691 +
12692 +#ifdef CONFIG_VSERVER_DEBUG
12693 +
12694 +static inline void __dump_vx_limit(struct _vx_limit *limit)
12695 +{
12696 +       int i;
12697 +
12698 +       printk("\t_vx_limit:");
12699 +       for (i = 0; i < NUM_LIMITS; i++) {
12700 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
12701 +                       i, (unsigned long)__rlim_get(limit, i),
12702 +                       (unsigned long)__rlim_rmin(limit, i),
12703 +                       (unsigned long)__rlim_rmax(limit, i),
12704 +                       (long)__rlim_soft(limit, i),
12705 +                       (long)__rlim_hard(limit, i),
12706 +                       atomic_read(&__rlim_lhit(limit, i)));
12707 +       }
12708 +}
12709 +
12710 +#endif
12711 +
12712 +#endif /* _VX_LIMIT_DEF_H */
12713 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/limit_int.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/limit_int.h
12714 --- linux-3.1.6/include/linux/vserver/limit_int.h       1970-01-01 01:00:00.000000000 +0100
12715 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/limit_int.h     2011-10-24 18:53:33.000000000 +0200
12716 @@ -0,0 +1,198 @@
12717 +#ifndef _VX_LIMIT_INT_H
12718 +#define _VX_LIMIT_INT_H
12719 +
12720 +#include "context.h"
12721 +
12722 +#ifdef __KERNEL__
12723 +
12724 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
12725 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
12726 +
12727 +extern const char *vlimit_name[NUM_LIMITS];
12728 +
12729 +static inline void __vx_acc_cres(struct vx_info *vxi,
12730 +       int res, int dir, void *_data, char *_file, int _line)
12731 +{
12732 +       if (VXD_RCRES_COND(res))
12733 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
12734 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12735 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12736 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
12737 +       if (!vxi)
12738 +               return;
12739 +
12740 +       if (dir > 0)
12741 +               __rlim_inc(&vxi->limit, res);
12742 +       else
12743 +               __rlim_dec(&vxi->limit, res);
12744 +}
12745 +
12746 +static inline void __vx_add_cres(struct vx_info *vxi,
12747 +       int res, int amount, void *_data, char *_file, int _line)
12748 +{
12749 +       if (VXD_RCRES_COND(res))
12750 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
12751 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12752 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12753 +                       amount, _data, _file, _line);
12754 +       if (amount == 0)
12755 +               return;
12756 +       if (!vxi)
12757 +               return;
12758 +       __rlim_add(&vxi->limit, res, amount);
12759 +}
12760 +
12761 +static inline
12762 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
12763 +{
12764 +       int cond = (value > __rlim_rmax(limit, res));
12765 +
12766 +       if (cond)
12767 +               __rlim_rmax(limit, res) = value;
12768 +       return cond;
12769 +}
12770 +
12771 +static inline
12772 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
12773 +{
12774 +       int cond = (value < __rlim_rmin(limit, res));
12775 +
12776 +       if (cond)
12777 +               __rlim_rmin(limit, res) = value;
12778 +       return cond;
12779 +}
12780 +
12781 +static inline
12782 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
12783 +{
12784 +       if (!__vx_cres_adjust_max(limit, res, value))
12785 +               __vx_cres_adjust_min(limit, res, value);
12786 +}
12787 +
12788 +
12789 +/*     return values:
12790 +        +1 ... no limit hit
12791 +        -1 ... over soft limit
12792 +         0 ... over hard limit         */
12793 +
12794 +static inline int __vx_cres_avail(struct vx_info *vxi,
12795 +       int res, int num, char *_file, int _line)
12796 +{
12797 +       struct _vx_limit *limit;
12798 +       rlim_t value;
12799 +
12800 +       if (VXD_RLIMIT_COND(res))
12801 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
12802 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12803 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
12804 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
12805 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12806 +                       num, _file, _line);
12807 +       if (!vxi)
12808 +               return 1;
12809 +
12810 +       limit = &vxi->limit;
12811 +       value = __rlim_get(limit, res);
12812 +
12813 +       if (!__vx_cres_adjust_max(limit, res, value))
12814 +               __vx_cres_adjust_min(limit, res, value);
12815 +
12816 +       if (num == 0)
12817 +               return 1;
12818 +
12819 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
12820 +               return -1;
12821 +       if (value + num <= __rlim_soft(limit, res))
12822 +               return -1;
12823 +
12824 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
12825 +               return 1;
12826 +       if (value + num <= __rlim_hard(limit, res))
12827 +               return 1;
12828 +
12829 +       __rlim_hit(limit, res);
12830 +       return 0;
12831 +}
12832 +
12833 +
12834 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
12835 +
12836 +static inline
12837 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
12838 +{
12839 +       rlim_t value, sum = 0;
12840 +       int res;
12841 +
12842 +       while ((res = *array++)) {
12843 +               value = __rlim_get(limit, res);
12844 +               __vx_cres_fixup(limit, res, value);
12845 +               sum += value;
12846 +       }
12847 +       return sum;
12848 +}
12849 +
12850 +static inline
12851 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
12852 +{
12853 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
12854 +       int res = *array;
12855 +
12856 +       if (value == __rlim_get(limit, res))
12857 +               return value;
12858 +
12859 +       __rlim_set(limit, res, value);
12860 +       /* now adjust min/max */
12861 +       if (!__vx_cres_adjust_max(limit, res, value))
12862 +               __vx_cres_adjust_min(limit, res, value);
12863 +
12864 +       return value;
12865 +}
12866 +
12867 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
12868 +       const int *array, int num, char *_file, int _line)
12869 +{
12870 +       struct _vx_limit *limit;
12871 +       rlim_t value = 0;
12872 +       int res;
12873 +
12874 +       if (num == 0)
12875 +               return 1;
12876 +       if (!vxi)
12877 +               return 1;
12878 +
12879 +       limit = &vxi->limit;
12880 +       res = *array;
12881 +       value = __vx_cres_array_sum(limit, array + 1);
12882 +
12883 +       __rlim_set(limit, res, value);
12884 +       __vx_cres_fixup(limit, res, value);
12885 +
12886 +       return __vx_cres_avail(vxi, res, num, _file, _line);
12887 +}
12888 +
12889 +
12890 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
12891 +{
12892 +       rlim_t value;
12893 +       int res;
12894 +
12895 +       /* complex resources first */
12896 +       if ((id < 0) || (id == RLIMIT_RSS))
12897 +               __vx_cres_array_fixup(limit, VLA_RSS);
12898 +
12899 +       for (res = 0; res < NUM_LIMITS; res++) {
12900 +               if ((id > 0) && (res != id))
12901 +                       continue;
12902 +
12903 +               value = __rlim_get(limit, res);
12904 +               __vx_cres_fixup(limit, res, value);
12905 +
12906 +               /* not supposed to happen, maybe warn? */
12907 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
12908 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
12909 +       }
12910 +}
12911 +
12912 +
12913 +#endif /* __KERNEL__ */
12914 +#endif /* _VX_LIMIT_INT_H */
12915 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/monitor.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/monitor.h
12916 --- linux-3.1.6/include/linux/vserver/monitor.h 1970-01-01 01:00:00.000000000 +0100
12917 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/monitor.h       2011-10-24 18:53:33.000000000 +0200
12918 @@ -0,0 +1,96 @@
12919 +#ifndef _VX_MONITOR_H
12920 +#define _VX_MONITOR_H
12921 +
12922 +#include <linux/types.h>
12923 +
12924 +enum {
12925 +       VXM_UNUSED = 0,
12926 +
12927 +       VXM_SYNC = 0x10,
12928 +
12929 +       VXM_UPDATE = 0x20,
12930 +       VXM_UPDATE_1,
12931 +       VXM_UPDATE_2,
12932 +
12933 +       VXM_RQINFO_1 = 0x24,
12934 +       VXM_RQINFO_2,
12935 +
12936 +       VXM_ACTIVATE = 0x40,
12937 +       VXM_DEACTIVATE,
12938 +       VXM_IDLE,
12939 +
12940 +       VXM_HOLD = 0x44,
12941 +       VXM_UNHOLD,
12942 +
12943 +       VXM_MIGRATE = 0x48,
12944 +       VXM_RESCHED,
12945 +
12946 +       /* all other bits are flags */
12947 +       VXM_SCHED = 0x80,
12948 +};
12949 +
12950 +struct _vxm_update_1 {
12951 +       uint32_t tokens_max;
12952 +       uint32_t fill_rate;
12953 +       uint32_t interval;
12954 +};
12955 +
12956 +struct _vxm_update_2 {
12957 +       uint32_t tokens_min;
12958 +       uint32_t fill_rate;
12959 +       uint32_t interval;
12960 +};
12961 +
12962 +struct _vxm_rqinfo_1 {
12963 +       uint16_t running;
12964 +       uint16_t onhold;
12965 +       uint16_t iowait;
12966 +       uint16_t uintr;
12967 +       uint32_t idle_tokens;
12968 +};
12969 +
12970 +struct _vxm_rqinfo_2 {
12971 +       uint32_t norm_time;
12972 +       uint32_t idle_time;
12973 +       uint32_t idle_skip;
12974 +};
12975 +
12976 +struct _vxm_sched {
12977 +       uint32_t tokens;
12978 +       uint32_t norm_time;
12979 +       uint32_t idle_time;
12980 +};
12981 +
12982 +struct _vxm_task {
12983 +       uint16_t pid;
12984 +       uint16_t state;
12985 +};
12986 +
12987 +struct _vxm_event {
12988 +       uint32_t jif;
12989 +       union {
12990 +               uint32_t seq;
12991 +               uint32_t sec;
12992 +       };
12993 +       union {
12994 +               uint32_t tokens;
12995 +               uint32_t nsec;
12996 +               struct _vxm_task tsk;
12997 +       };
12998 +};
12999 +
13000 +struct _vx_mon_entry {
13001 +       uint16_t type;
13002 +       uint16_t xid;
13003 +       union {
13004 +               struct _vxm_event ev;
13005 +               struct _vxm_sched sd;
13006 +               struct _vxm_update_1 u1;
13007 +               struct _vxm_update_2 u2;
13008 +               struct _vxm_rqinfo_1 q1;
13009 +               struct _vxm_rqinfo_2 q2;
13010 +       };
13011 +};
13012 +
13013 +
13014 +#endif /* _VX_MONITOR_H */
13015 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/network.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/network.h
13016 --- linux-3.1.6/include/linux/vserver/network.h 1970-01-01 01:00:00.000000000 +0100
13017 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/network.h       2011-10-24 18:53:33.000000000 +0200
13018 @@ -0,0 +1,148 @@
13019 +#ifndef _VX_NETWORK_H
13020 +#define _VX_NETWORK_H
13021 +
13022 +#include <linux/types.h>
13023 +
13024 +
13025 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
13026 +
13027 +
13028 +/* network flags */
13029 +
13030 +#define NXF_INFO_PRIVATE       0x00000008
13031 +
13032 +#define NXF_SINGLE_IP          0x00000100
13033 +#define NXF_LBACK_REMAP                0x00000200
13034 +#define NXF_LBACK_ALLOW                0x00000400
13035 +
13036 +#define NXF_HIDE_NETIF         0x02000000
13037 +#define NXF_HIDE_LBACK         0x04000000
13038 +
13039 +#define NXF_STATE_SETUP                (1ULL << 32)
13040 +#define NXF_STATE_ADMIN                (1ULL << 34)
13041 +
13042 +#define NXF_SC_HELPER          (1ULL << 36)
13043 +#define NXF_PERSISTENT         (1ULL << 38)
13044 +
13045 +#define NXF_ONE_TIME           (0x0005ULL << 32)
13046 +
13047 +
13048 +#define        NXF_INIT_SET            (__nxf_init_set())
13049 +
13050 +static inline uint64_t __nxf_init_set(void) {
13051 +       return    NXF_STATE_ADMIN
13052 +#ifdef CONFIG_VSERVER_AUTO_LBACK
13053 +               | NXF_LBACK_REMAP
13054 +               | NXF_HIDE_LBACK
13055 +#endif
13056 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
13057 +               | NXF_SINGLE_IP
13058 +#endif
13059 +               | NXF_HIDE_NETIF;
13060 +}
13061 +
13062 +
13063 +/* network caps */
13064 +
13065 +#define NXC_TUN_CREATE         0x00000001
13066 +
13067 +#define NXC_RAW_ICMP           0x00000100
13068 +
13069 +#define NXC_MULTICAST          0x00001000
13070 +
13071 +
13072 +/* address types */
13073 +
13074 +#define NXA_TYPE_IPV4          0x0001
13075 +#define NXA_TYPE_IPV6          0x0002
13076 +
13077 +#define NXA_TYPE_NONE          0x0000
13078 +#define NXA_TYPE_ANY           0x00FF
13079 +
13080 +#define NXA_TYPE_ADDR          0x0010
13081 +#define NXA_TYPE_MASK          0x0020
13082 +#define NXA_TYPE_RANGE         0x0040
13083 +
13084 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
13085 +
13086 +#define NXA_MOD_BCAST          0x0100
13087 +#define NXA_MOD_LBACK          0x0200
13088 +
13089 +#define NXA_LOOPBACK           0x1000
13090 +
13091 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
13092 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
13093 +
13094 +#ifdef __KERNEL__
13095 +
13096 +#include <linux/list.h>
13097 +#include <linux/spinlock.h>
13098 +#include <linux/rcupdate.h>
13099 +#include <linux/in.h>
13100 +#include <linux/in6.h>
13101 +#include <asm/atomic.h>
13102 +
13103 +struct nx_addr_v4 {
13104 +       struct nx_addr_v4 *next;
13105 +       struct in_addr ip[2];
13106 +       struct in_addr mask;
13107 +       uint16_t type;
13108 +       uint16_t flags;
13109 +};
13110 +
13111 +struct nx_addr_v6 {
13112 +       struct nx_addr_v6 *next;
13113 +       struct in6_addr ip;
13114 +       struct in6_addr mask;
13115 +       uint32_t prefix;
13116 +       uint16_t type;
13117 +       uint16_t flags;
13118 +};
13119 +
13120 +struct nx_info {
13121 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
13122 +       nid_t nx_id;                    /* vnet id */
13123 +       atomic_t nx_usecnt;             /* usage count */
13124 +       atomic_t nx_tasks;              /* tasks count */
13125 +       int nx_state;                   /* context state */
13126 +
13127 +       uint64_t nx_flags;              /* network flag word */
13128 +       uint64_t nx_ncaps;              /* network capabilities */
13129 +
13130 +       struct in_addr v4_lback;        /* Loopback address */
13131 +       struct in_addr v4_bcast;        /* Broadcast address */
13132 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
13133 +#ifdef CONFIG_IPV6
13134 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
13135 +#endif
13136 +       char nx_name[65];               /* network context name */
13137 +};
13138 +
13139 +
13140 +/* status flags */
13141 +
13142 +#define NXS_HASHED      0x0001
13143 +#define NXS_SHUTDOWN    0x0100
13144 +#define NXS_RELEASED    0x8000
13145 +
13146 +extern struct nx_info *lookup_nx_info(int);
13147 +
13148 +extern int get_nid_list(int, unsigned int *, int);
13149 +extern int nid_is_hashed(nid_t);
13150 +
13151 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
13152 +
13153 +extern long vs_net_change(struct nx_info *, unsigned int);
13154 +
13155 +struct sock;
13156 +
13157 +
13158 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
13159 +#ifdef  CONFIG_IPV6
13160 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
13161 +#else
13162 +#define NX_IPV6(n)     (0)
13163 +#endif
13164 +
13165 +#endif /* __KERNEL__ */
13166 +#endif /* _VX_NETWORK_H */
13167 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/network_cmd.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/network_cmd.h
13168 --- linux-3.1.6/include/linux/vserver/network_cmd.h     1970-01-01 01:00:00.000000000 +0100
13169 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/network_cmd.h   2011-10-24 18:53:33.000000000 +0200
13170 @@ -0,0 +1,164 @@
13171 +#ifndef _VX_NETWORK_CMD_H
13172 +#define _VX_NETWORK_CMD_H
13173 +
13174 +
13175 +/* vinfo commands */
13176 +
13177 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
13178 +
13179 +#ifdef __KERNEL__
13180 +extern int vc_task_nid(uint32_t);
13181 +
13182 +#endif /* __KERNEL__ */
13183 +
13184 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
13185 +
13186 +struct vcmd_nx_info_v0 {
13187 +       uint32_t nid;
13188 +       /* more to come */
13189 +};
13190 +
13191 +#ifdef __KERNEL__
13192 +extern int vc_nx_info(struct nx_info *, void __user *);
13193 +
13194 +#endif /* __KERNEL__ */
13195 +
13196 +#include <linux/in.h>
13197 +#include <linux/in6.h>
13198 +
13199 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
13200 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
13201 +
13202 +struct  vcmd_net_create {
13203 +       uint64_t flagword;
13204 +};
13205 +
13206 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
13207 +
13208 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
13209 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
13210 +
13211 +struct vcmd_net_addr_v0 {
13212 +       uint16_t type;
13213 +       uint16_t count;
13214 +       struct in_addr ip[4];
13215 +       struct in_addr mask[4];
13216 +};
13217 +
13218 +#define VCMD_net_add_ipv4_v1   VC_CMD(NETALT, 1, 1)
13219 +#define VCMD_net_rem_ipv4_v1   VC_CMD(NETALT, 2, 1)
13220 +
13221 +struct vcmd_net_addr_ipv4_v1 {
13222 +       uint16_t type;
13223 +       uint16_t flags;
13224 +       struct in_addr ip;
13225 +       struct in_addr mask;
13226 +};
13227 +
13228 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 2)
13229 +#define VCMD_net_rem_ipv4      VC_CMD(NETALT, 2, 2)
13230 +
13231 +struct vcmd_net_addr_ipv4_v2 {
13232 +       uint16_t type;
13233 +       uint16_t flags;
13234 +       struct in_addr ip;
13235 +       struct in_addr ip2;
13236 +       struct in_addr mask;
13237 +};
13238 +
13239 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
13240 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
13241 +
13242 +struct vcmd_net_addr_ipv6_v1 {
13243 +       uint16_t type;
13244 +       uint16_t flags;
13245 +       uint32_t prefix;
13246 +       struct in6_addr ip;
13247 +       struct in6_addr mask;
13248 +};
13249 +
13250 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
13251 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
13252 +
13253 +struct vcmd_match_ipv4_v0 {
13254 +       uint16_t type;
13255 +       uint16_t flags;
13256 +       uint16_t parent;
13257 +       uint16_t prefix;
13258 +       struct in_addr ip;
13259 +       struct in_addr ip2;
13260 +       struct in_addr mask;
13261 +};
13262 +
13263 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
13264 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
13265 +
13266 +struct vcmd_match_ipv6_v0 {
13267 +       uint16_t type;
13268 +       uint16_t flags;
13269 +       uint16_t parent;
13270 +       uint16_t prefix;
13271 +       struct in6_addr ip;
13272 +       struct in6_addr ip2;
13273 +       struct in6_addr mask;
13274 +};
13275 +
13276 +
13277 +#ifdef __KERNEL__
13278 +extern int vc_net_create(uint32_t, void __user *);
13279 +extern int vc_net_migrate(struct nx_info *, void __user *);
13280 +
13281 +extern int vc_net_add(struct nx_info *, void __user *);
13282 +extern int vc_net_remove(struct nx_info *, void __user *);
13283 +
13284 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
13285 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
13286 +
13287 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
13288 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
13289 +
13290 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
13291 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
13292 +
13293 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
13294 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
13295 +
13296 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
13297 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
13298 +
13299 +#endif /* __KERNEL__ */
13300 +
13301 +
13302 +/* flag commands */
13303 +
13304 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
13305 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
13306 +
13307 +struct vcmd_net_flags_v0 {
13308 +       uint64_t flagword;
13309 +       uint64_t mask;
13310 +};
13311 +
13312 +#ifdef __KERNEL__
13313 +extern int vc_get_nflags(struct nx_info *, void __user *);
13314 +extern int vc_set_nflags(struct nx_info *, void __user *);
13315 +
13316 +#endif /* __KERNEL__ */
13317 +
13318 +
13319 +/* network caps commands */
13320 +
13321 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
13322 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
13323 +
13324 +struct vcmd_net_caps_v0 {
13325 +       uint64_t ncaps;
13326 +       uint64_t cmask;
13327 +};
13328 +
13329 +#ifdef __KERNEL__
13330 +extern int vc_get_ncaps(struct nx_info *, void __user *);
13331 +extern int vc_set_ncaps(struct nx_info *, void __user *);
13332 +
13333 +#endif /* __KERNEL__ */
13334 +#endif /* _VX_CONTEXT_CMD_H */
13335 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/percpu.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/percpu.h
13336 --- linux-3.1.6/include/linux/vserver/percpu.h  1970-01-01 01:00:00.000000000 +0100
13337 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/percpu.h        2011-10-24 18:53:33.000000000 +0200
13338 @@ -0,0 +1,14 @@
13339 +#ifndef _VX_PERCPU_H
13340 +#define _VX_PERCPU_H
13341 +
13342 +#include "cvirt_def.h"
13343 +#include "sched_def.h"
13344 +
13345 +struct _vx_percpu {
13346 +       struct _vx_cvirt_pc cvirt;
13347 +       struct _vx_sched_pc sched;
13348 +};
13349 +
13350 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
13351 +
13352 +#endif /* _VX_PERCPU_H */
13353 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/pid.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/pid.h
13354 --- linux-3.1.6/include/linux/vserver/pid.h     1970-01-01 01:00:00.000000000 +0100
13355 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/pid.h   2011-10-24 18:53:33.000000000 +0200
13356 @@ -0,0 +1,51 @@
13357 +#ifndef _VSERVER_PID_H
13358 +#define _VSERVER_PID_H
13359 +
13360 +/* pid faking stuff */
13361 +
13362 +#define vx_info_map_pid(v, p) \
13363 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
13364 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
13365 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
13366 +#define vx_map_tgid(p) vx_map_pid(p)
13367 +
13368 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
13369 +       const char *func, const char *file, int line)
13370 +{
13371 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13372 +               vxfprintk(VXD_CBIT(cvirt, 2),
13373 +                       "vx_map_tgid: %p/%llx: %d -> %d",
13374 +                       vxi, (long long)vxi->vx_flags, pid,
13375 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
13376 +                       func, file, line);
13377 +               if (pid == 0)
13378 +                       return 0;
13379 +               if (pid == vxi->vx_initpid)
13380 +                       return 1;
13381 +       }
13382 +       return pid;
13383 +}
13384 +
13385 +#define vx_info_rmap_pid(v, p) \
13386 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
13387 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
13388 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
13389 +
13390 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
13391 +       const char *func, const char *file, int line)
13392 +{
13393 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
13394 +               vxfprintk(VXD_CBIT(cvirt, 2),
13395 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
13396 +                       vxi, (long long)vxi->vx_flags, pid,
13397 +                       (pid == 1) ? vxi->vx_initpid : pid,
13398 +                       func, file, line);
13399 +               if ((pid == 1) && vxi->vx_initpid)
13400 +                       return vxi->vx_initpid;
13401 +               if (pid == vxi->vx_initpid)
13402 +                       return ~0U;
13403 +       }
13404 +       return pid;
13405 +}
13406 +
13407 +#endif
13408 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/sched.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/sched.h
13409 --- linux-3.1.6/include/linux/vserver/sched.h   1970-01-01 01:00:00.000000000 +0100
13410 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/sched.h 2011-10-24 18:53:33.000000000 +0200
13411 @@ -0,0 +1,23 @@
13412 +#ifndef _VX_SCHED_H
13413 +#define _VX_SCHED_H
13414 +
13415 +
13416 +#ifdef __KERNEL__
13417 +
13418 +struct timespec;
13419 +
13420 +void vx_vsi_uptime(struct timespec *, struct timespec *);
13421 +
13422 +
13423 +struct vx_info;
13424 +
13425 +void vx_update_load(struct vx_info *);
13426 +
13427 +
13428 +void vx_update_sched_param(struct _vx_sched *sched,
13429 +       struct _vx_sched_pc *sched_pc);
13430 +
13431 +#endif /* __KERNEL__ */
13432 +#else  /* _VX_SCHED_H */
13433 +#warning duplicate inclusion
13434 +#endif /* _VX_SCHED_H */
13435 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/sched_cmd.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/sched_cmd.h
13436 --- linux-3.1.6/include/linux/vserver/sched_cmd.h       1970-01-01 01:00:00.000000000 +0100
13437 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/sched_cmd.h     2011-10-24 18:53:33.000000000 +0200
13438 @@ -0,0 +1,21 @@
13439 +#ifndef _VX_SCHED_CMD_H
13440 +#define _VX_SCHED_CMD_H
13441 +
13442 +
13443 +struct vcmd_prio_bias {
13444 +       int32_t cpu_id;
13445 +       int32_t prio_bias;
13446 +};
13447 +
13448 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
13449 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
13450 +
13451 +#ifdef __KERNEL__
13452 +
13453 +#include <linux/compiler.h>
13454 +
13455 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
13456 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
13457 +
13458 +#endif /* __KERNEL__ */
13459 +#endif /* _VX_SCHED_CMD_H */
13460 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/sched_def.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/sched_def.h
13461 --- linux-3.1.6/include/linux/vserver/sched_def.h       1970-01-01 01:00:00.000000000 +0100
13462 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/sched_def.h     2011-10-24 18:53:33.000000000 +0200
13463 @@ -0,0 +1,38 @@
13464 +#ifndef _VX_SCHED_DEF_H
13465 +#define _VX_SCHED_DEF_H
13466 +
13467 +#include <linux/spinlock.h>
13468 +#include <linux/jiffies.h>
13469 +#include <linux/cpumask.h>
13470 +#include <asm/atomic.h>
13471 +#include <asm/param.h>
13472 +
13473 +
13474 +/* context sub struct */
13475 +
13476 +struct _vx_sched {
13477 +       int prio_bias;                  /* bias offset for priority */
13478 +
13479 +       cpumask_t update;               /* CPUs which should update */
13480 +};
13481 +
13482 +struct _vx_sched_pc {
13483 +       int prio_bias;                  /* bias offset for priority */
13484 +
13485 +       uint64_t user_ticks;            /* token tick events */
13486 +       uint64_t sys_ticks;             /* token tick events */
13487 +       uint64_t hold_ticks;            /* token ticks paused */
13488 +};
13489 +
13490 +
13491 +#ifdef CONFIG_VSERVER_DEBUG
13492 +
13493 +static inline void __dump_vx_sched(struct _vx_sched *sched)
13494 +{
13495 +       printk("\t_vx_sched:\n");
13496 +       printk("\t priority = %4d\n", sched->prio_bias);
13497 +}
13498 +
13499 +#endif
13500 +
13501 +#endif /* _VX_SCHED_DEF_H */
13502 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/signal.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/signal.h
13503 --- linux-3.1.6/include/linux/vserver/signal.h  1970-01-01 01:00:00.000000000 +0100
13504 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/signal.h        2011-10-24 18:53:33.000000000 +0200
13505 @@ -0,0 +1,14 @@
13506 +#ifndef _VX_SIGNAL_H
13507 +#define _VX_SIGNAL_H
13508 +
13509 +
13510 +#ifdef __KERNEL__
13511 +
13512 +struct vx_info;
13513 +
13514 +int vx_info_kill(struct vx_info *, int, int);
13515 +
13516 +#endif /* __KERNEL__ */
13517 +#else  /* _VX_SIGNAL_H */
13518 +#warning duplicate inclusion
13519 +#endif /* _VX_SIGNAL_H */
13520 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/signal_cmd.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/signal_cmd.h
13521 --- linux-3.1.6/include/linux/vserver/signal_cmd.h      1970-01-01 01:00:00.000000000 +0100
13522 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/signal_cmd.h    2011-10-24 18:53:33.000000000 +0200
13523 @@ -0,0 +1,43 @@
13524 +#ifndef _VX_SIGNAL_CMD_H
13525 +#define _VX_SIGNAL_CMD_H
13526 +
13527 +
13528 +/*  signalling vserver commands */
13529 +
13530 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
13531 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
13532 +
13533 +struct vcmd_ctx_kill_v0 {
13534 +       int32_t pid;
13535 +       int32_t sig;
13536 +};
13537 +
13538 +struct vcmd_wait_exit_v0 {
13539 +       int32_t reboot_cmd;
13540 +       int32_t exit_code;
13541 +};
13542 +
13543 +#ifdef __KERNEL__
13544 +
13545 +extern int vc_ctx_kill(struct vx_info *, void __user *);
13546 +extern int vc_wait_exit(struct vx_info *, void __user *);
13547 +
13548 +#endif /* __KERNEL__ */
13549 +
13550 +/*  process alteration commands */
13551 +
13552 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
13553 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
13554 +
13555 +struct vcmd_pflags_v0 {
13556 +       uint32_t flagword;
13557 +       uint32_t mask;
13558 +};
13559 +
13560 +#ifdef __KERNEL__
13561 +
13562 +extern int vc_get_pflags(uint32_t pid, void __user *);
13563 +extern int vc_set_pflags(uint32_t pid, void __user *);
13564 +
13565 +#endif /* __KERNEL__ */
13566 +#endif /* _VX_SIGNAL_CMD_H */
13567 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/space.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/space.h
13568 --- linux-3.1.6/include/linux/vserver/space.h   1970-01-01 01:00:00.000000000 +0100
13569 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/space.h 2011-10-24 18:53:33.000000000 +0200
13570 @@ -0,0 +1,12 @@
13571 +#ifndef _VX_SPACE_H
13572 +#define _VX_SPACE_H
13573 +
13574 +#include <linux/types.h>
13575 +
13576 +struct vx_info;
13577 +
13578 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
13579 +
13580 +#else  /* _VX_SPACE_H */
13581 +#warning duplicate inclusion
13582 +#endif /* _VX_SPACE_H */
13583 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/space_cmd.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/space_cmd.h
13584 --- linux-3.1.6/include/linux/vserver/space_cmd.h       1970-01-01 01:00:00.000000000 +0100
13585 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/space_cmd.h     2011-10-24 18:53:33.000000000 +0200
13586 @@ -0,0 +1,38 @@
13587 +#ifndef _VX_SPACE_CMD_H
13588 +#define _VX_SPACE_CMD_H
13589 +
13590 +
13591 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
13592 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
13593 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
13594 +
13595 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
13596 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
13597 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
13598 +
13599 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
13600 +
13601 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
13602 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
13603 +
13604 +
13605 +struct vcmd_space_mask_v1 {
13606 +       uint64_t mask;
13607 +};
13608 +
13609 +struct vcmd_space_mask_v2 {
13610 +       uint64_t mask;
13611 +       uint32_t index;
13612 +};
13613 +
13614 +
13615 +#ifdef __KERNEL__
13616 +
13617 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
13618 +extern int vc_set_space_v1(struct vx_info *, void __user *);
13619 +extern int vc_enter_space(struct vx_info *, void __user *);
13620 +extern int vc_set_space(struct vx_info *, void __user *);
13621 +extern int vc_get_space_mask(void __user *, int);
13622 +
13623 +#endif /* __KERNEL__ */
13624 +#endif /* _VX_SPACE_CMD_H */
13625 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/switch.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/switch.h
13626 --- linux-3.1.6/include/linux/vserver/switch.h  1970-01-01 01:00:00.000000000 +0100
13627 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/switch.h        2011-10-24 18:53:33.000000000 +0200
13628 @@ -0,0 +1,98 @@
13629 +#ifndef _VX_SWITCH_H
13630 +#define _VX_SWITCH_H
13631 +
13632 +#include <linux/types.h>
13633 +
13634 +
13635 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
13636 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
13637 +#define VC_VERSION(c)          ((c) & 0xFFF)
13638 +
13639 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
13640 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13641 +
13642 +/*
13643 +
13644 +  Syscall Matrix V2.8
13645 +
13646 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13647 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
13648 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
13649 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13650 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13651 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13652 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13653 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13654 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13655 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13656 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13657 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13658 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13659 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13660 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13661 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13662 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13663 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13664 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13665 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13666 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13667 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13668 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13669 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13670 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13671 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13672 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13673 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13674 +
13675 +*/
13676 +
13677 +#define VC_CAT_VERSION         0
13678 +
13679 +#define VC_CAT_VSETUP          1
13680 +#define VC_CAT_VHOST           2
13681 +
13682 +#define VC_CAT_DEVICE          6
13683 +
13684 +#define VC_CAT_VPROC           9
13685 +#define VC_CAT_PROCALT         10
13686 +#define VC_CAT_PROCMIG         11
13687 +#define VC_CAT_PROCTRL         12
13688 +
13689 +#define VC_CAT_SCHED           14
13690 +#define VC_CAT_MEMCTRL         20
13691 +
13692 +#define VC_CAT_VNET            25
13693 +#define VC_CAT_NETALT          26
13694 +#define VC_CAT_NETMIG          27
13695 +#define VC_CAT_NETCTRL         28
13696 +
13697 +#define VC_CAT_TAGMIG          35
13698 +#define VC_CAT_DLIMIT          36
13699 +#define VC_CAT_INODE           38
13700 +
13701 +#define VC_CAT_VSTAT           40
13702 +#define VC_CAT_VINFO           46
13703 +#define VC_CAT_EVENT           48
13704 +
13705 +#define VC_CAT_FLAGS           52
13706 +#define VC_CAT_VSPACE          54
13707 +#define VC_CAT_DEBUG           56
13708 +#define VC_CAT_RLIMIT          60
13709 +
13710 +#define VC_CAT_SYSTEST         61
13711 +#define VC_CAT_COMPAT          63
13712 +
13713 +/*  query version */
13714 +
13715 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13716 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13717 +
13718 +
13719 +#ifdef __KERNEL__
13720 +
13721 +#include <linux/errno.h>
13722 +
13723 +#endif /* __KERNEL__ */
13724 +
13725 +#endif /* _VX_SWITCH_H */
13726 +
13727 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/tag.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/tag.h
13728 --- linux-3.1.6/include/linux/vserver/tag.h     1970-01-01 01:00:00.000000000 +0100
13729 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/tag.h   2011-10-24 18:53:33.000000000 +0200
13730 @@ -0,0 +1,143 @@
13731 +#ifndef _DX_TAG_H
13732 +#define _DX_TAG_H
13733 +
13734 +#include <linux/types.h>
13735 +
13736 +
13737 +#define DX_TAG(in)     (IS_TAGGED(in))
13738 +
13739 +
13740 +#ifdef CONFIG_TAG_NFSD
13741 +#define DX_TAG_NFSD    1
13742 +#else
13743 +#define DX_TAG_NFSD    0
13744 +#endif
13745 +
13746 +
13747 +#ifdef CONFIG_TAGGING_NONE
13748 +
13749 +#define MAX_UID                0xFFFFFFFF
13750 +#define MAX_GID                0xFFFFFFFF
13751 +
13752 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
13753 +
13754 +#define TAGINO_UID(cond, uid, tag)     (uid)
13755 +#define TAGINO_GID(cond, gid, tag)     (gid)
13756 +
13757 +#endif
13758 +
13759 +
13760 +#ifdef CONFIG_TAGGING_GID16
13761 +
13762 +#define MAX_UID                0xFFFFFFFF
13763 +#define MAX_GID                0x0000FFFF
13764 +
13765 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13766 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
13767 +
13768 +#define TAGINO_UID(cond, uid, tag)     (uid)
13769 +#define TAGINO_GID(cond, gid, tag)     \
13770 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
13771 +
13772 +#endif
13773 +
13774 +
13775 +#ifdef CONFIG_TAGGING_ID24
13776 +
13777 +#define MAX_UID                0x00FFFFFF
13778 +#define MAX_GID                0x00FFFFFF
13779 +
13780 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13781 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
13782 +
13783 +#define TAGINO_UID(cond, uid, tag)     \
13784 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
13785 +#define TAGINO_GID(cond, gid, tag)     \
13786 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
13787 +
13788 +#endif
13789 +
13790 +
13791 +#ifdef CONFIG_TAGGING_UID16
13792 +
13793 +#define MAX_UID                0x0000FFFF
13794 +#define MAX_GID                0xFFFFFFFF
13795 +
13796 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13797 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
13798 +
13799 +#define TAGINO_UID(cond, uid, tag)     \
13800 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
13801 +#define TAGINO_GID(cond, gid, tag)     (gid)
13802 +
13803 +#endif
13804 +
13805 +
13806 +#ifdef CONFIG_TAGGING_INTERN
13807 +
13808 +#define MAX_UID                0xFFFFFFFF
13809 +#define MAX_GID                0xFFFFFFFF
13810 +
13811 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13812 +       ((cond) ? (tag) : 0)
13813 +
13814 +#define TAGINO_UID(cond, uid, tag)     (uid)
13815 +#define TAGINO_GID(cond, gid, tag)     (gid)
13816 +
13817 +#endif
13818 +
13819 +
13820 +#ifndef CONFIG_TAGGING_NONE
13821 +#define dx_current_fstag(sb)   \
13822 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
13823 +#else
13824 +#define dx_current_fstag(sb)   (0)
13825 +#endif
13826 +
13827 +#ifndef CONFIG_TAGGING_INTERN
13828 +#define TAGINO_TAG(cond, tag)  (0)
13829 +#else
13830 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
13831 +#endif
13832 +
13833 +#define INOTAG_UID(cond, uid, gid)     \
13834 +       ((cond) ? ((uid) & MAX_UID) : (uid))
13835 +#define INOTAG_GID(cond, uid, gid)     \
13836 +       ((cond) ? ((gid) & MAX_GID) : (gid))
13837 +
13838 +
13839 +static inline uid_t dx_map_uid(uid_t uid)
13840 +{
13841 +       if ((uid > MAX_UID) && (uid != -1))
13842 +               uid = -2;
13843 +       return (uid & MAX_UID);
13844 +}
13845 +
13846 +static inline gid_t dx_map_gid(gid_t gid)
13847 +{
13848 +       if ((gid > MAX_GID) && (gid != -1))
13849 +               gid = -2;
13850 +       return (gid & MAX_GID);
13851 +}
13852 +
13853 +struct peer_tag {
13854 +       int32_t xid;
13855 +       int32_t nid;
13856 +};
13857 +
13858 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
13859 +
13860 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
13861 +                unsigned long *flags);
13862 +
13863 +#ifdef CONFIG_PROPAGATE
13864 +
13865 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
13866 +
13867 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
13868 +
13869 +#else
13870 +#define dx_propagate_tag(n, i) do { } while (0)
13871 +#endif
13872 +
13873 +#endif /* _DX_TAG_H */
13874 diff -NurpP --minimal linux-3.1.6/include/linux/vserver/tag_cmd.h linux-3.1.6-vs2.3.2.5/include/linux/vserver/tag_cmd.h
13875 --- linux-3.1.6/include/linux/vserver/tag_cmd.h 1970-01-01 01:00:00.000000000 +0100
13876 +++ linux-3.1.6-vs2.3.2.5/include/linux/vserver/tag_cmd.h       2011-10-24 18:53:33.000000000 +0200
13877 @@ -0,0 +1,22 @@
13878 +#ifndef _VX_TAG_CMD_H
13879 +#define _VX_TAG_CMD_H
13880 +
13881 +
13882 +/* vinfo commands */
13883 +
13884 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13885 +
13886 +#ifdef __KERNEL__
13887 +extern int vc_task_tag(uint32_t);
13888 +
13889 +#endif /* __KERNEL__ */
13890 +
13891 +/* context commands */
13892 +
13893 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13894 +
13895 +#ifdef __KERNEL__
13896 +extern int vc_tag_migrate(uint32_t);
13897 +
13898 +#endif /* __KERNEL__ */
13899 +#endif /* _VX_TAG_CMD_H */
13900 diff -NurpP --minimal linux-3.1.6/include/net/addrconf.h linux-3.1.6-vs2.3.2.5/include/net/addrconf.h
13901 --- linux-3.1.6/include/net/addrconf.h  2011-07-22 11:18:11.000000000 +0200
13902 +++ linux-3.1.6-vs2.3.2.5/include/net/addrconf.h        2011-10-24 18:53:33.000000000 +0200
13903 @@ -80,7 +80,8 @@ extern int                    ipv6_dev_get_saddr(struct n
13904                                                struct net_device *dev,
13905                                                const struct in6_addr *daddr,
13906                                                unsigned int srcprefs,
13907 -                                              struct in6_addr *saddr);
13908 +                                              struct in6_addr *saddr,
13909 +                                              struct nx_info *nxi);
13910  extern int                     ipv6_get_lladdr(struct net_device *dev,
13911                                                 struct in6_addr *addr,
13912                                                 unsigned char banned_flags);
13913 diff -NurpP --minimal linux-3.1.6/include/net/af_unix.h linux-3.1.6-vs2.3.2.5/include/net/af_unix.h
13914 --- linux-3.1.6/include/net/af_unix.h   2011-07-22 11:18:11.000000000 +0200
13915 +++ linux-3.1.6-vs2.3.2.5/include/net/af_unix.h 2011-10-24 18:53:33.000000000 +0200
13916 @@ -4,6 +4,7 @@
13917  #include <linux/socket.h>
13918  #include <linux/un.h>
13919  #include <linux/mutex.h>
13920 +#include <linux/vs_base.h>
13921  #include <net/sock.h>
13922  
13923  extern void unix_inflight(struct file *fp);
13924 diff -NurpP --minimal linux-3.1.6/include/net/inet_timewait_sock.h linux-3.1.6-vs2.3.2.5/include/net/inet_timewait_sock.h
13925 --- linux-3.1.6/include/net/inet_timewait_sock.h        2011-10-24 18:45:32.000000000 +0200
13926 +++ linux-3.1.6-vs2.3.2.5/include/net/inet_timewait_sock.h      2011-10-24 18:53:33.000000000 +0200
13927 @@ -113,6 +113,10 @@ struct inet_timewait_sock {
13928  #define tw_net                 __tw_common.skc_net
13929  #define tw_daddr               __tw_common.skc_daddr
13930  #define tw_rcv_saddr           __tw_common.skc_rcv_saddr
13931 +#define tw_xid                 __tw_common.skc_xid
13932 +#define tw_vx_info             __tw_common.skc_vx_info
13933 +#define tw_nid                 __tw_common.skc_nid
13934 +#define tw_nx_info             __tw_common.skc_nx_info
13935         int                     tw_timeout;
13936         volatile unsigned char  tw_substate;
13937         unsigned char           tw_rcv_wscale;
13938 diff -NurpP --minimal linux-3.1.6/include/net/ip6_route.h linux-3.1.6-vs2.3.2.5/include/net/ip6_route.h
13939 --- linux-3.1.6/include/net/ip6_route.h 2011-07-22 11:18:11.000000000 +0200
13940 +++ linux-3.1.6-vs2.3.2.5/include/net/ip6_route.h       2011-10-24 18:53:33.000000000 +0200
13941 @@ -86,7 +86,8 @@ extern int                    ip6_route_get_saddr(struct 
13942                                                     struct rt6_info *rt,
13943                                                     const struct in6_addr *daddr,
13944                                                     unsigned int prefs,
13945 -                                                   struct in6_addr *saddr);
13946 +                                                   struct in6_addr *saddr,
13947 +                                                   struct nx_info *nxi);
13948  
13949  extern struct rt6_info         *rt6_lookup(struct net *net,
13950                                             const struct in6_addr *daddr,
13951 diff -NurpP --minimal linux-3.1.6/include/net/route.h linux-3.1.6-vs2.3.2.5/include/net/route.h
13952 --- linux-3.1.6/include/net/route.h     2011-07-22 11:18:11.000000000 +0200
13953 +++ linux-3.1.6-vs2.3.2.5/include/net/route.h   2011-10-24 18:53:33.000000000 +0200
13954 @@ -202,6 +202,9 @@ static inline void ip_rt_put(struct rtab
13955                 dst_release(&rt->dst);
13956  }
13957  
13958 +#include <linux/vs_base.h>
13959 +#include <linux/vs_inet.h>
13960 +
13961  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
13962  
13963  extern const __u8 ip_tos2prio[16];
13964 @@ -253,6 +256,9 @@ static inline void ip_route_connect_init
13965                            protocol, flow_flags, dst, src, dport, sport);
13966  }
13967  
13968 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
13969 +       struct flowi4 *);
13970 +
13971  static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
13972                                               __be32 dst, __be32 src, u32 tos,
13973                                               int oif, u8 protocol,
13974 @@ -261,11 +267,25 @@ static inline struct rtable *ip_route_co
13975  {
13976         struct net *net = sock_net(sk);
13977         struct rtable *rt;
13978 +       struct nx_info *nx_info = current_nx_info();
13979  
13980         ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
13981                               sport, dport, sk, can_sleep);
13982  
13983 -       if (!dst || !src) {
13984 +       if (sk)
13985 +               nx_info = sk->sk_nx_info;
13986 +
13987 +       vxdprintk(VXD_CBIT(net, 4),
13988 +               "ip_route_connect(%p) %p,%p;%lx",
13989 +               sk, nx_info, sk->sk_socket,
13990 +               (sk->sk_socket?sk->sk_socket->flags:0));
13991 +
13992 +       rt = ip_v4_find_src(net, nx_info, fl4);
13993 +       if (IS_ERR(rt))
13994 +               return rt;
13995 +       ip_rt_put(rt);
13996 +
13997 +       if (!fl4->daddr || !fl4->saddr) {
13998                 rt = __ip_route_output_key(net, fl4);
13999                 if (IS_ERR(rt))
14000                         return rt;
14001 diff -NurpP --minimal linux-3.1.6/include/net/sock.h linux-3.1.6-vs2.3.2.5/include/net/sock.h
14002 --- linux-3.1.6/include/net/sock.h      2011-10-24 18:45:32.000000000 +0200
14003 +++ linux-3.1.6-vs2.3.2.5/include/net/sock.h    2011-10-24 18:53:33.000000000 +0200
14004 @@ -150,6 +150,10 @@ struct sock_common {
14005  #ifdef CONFIG_NET_NS
14006         struct net              *skc_net;
14007  #endif
14008 +       xid_t                   skc_xid;
14009 +       struct vx_info          *skc_vx_info;
14010 +       nid_t                   skc_nid;
14011 +       struct nx_info          *skc_nx_info;
14012         /*
14013          * fields between dontcopy_begin/dontcopy_end
14014          * are not copied in sock_copy()
14015 @@ -257,6 +261,10 @@ struct sock {
14016  #define sk_bind_node           __sk_common.skc_bind_node
14017  #define sk_prot                        __sk_common.skc_prot
14018  #define sk_net                 __sk_common.skc_net
14019 +#define sk_xid                 __sk_common.skc_xid
14020 +#define sk_vx_info             __sk_common.skc_vx_info
14021 +#define sk_nid                 __sk_common.skc_nid
14022 +#define sk_nx_info             __sk_common.skc_nx_info
14023         socket_lock_t           sk_lock;
14024         struct sk_buff_head     sk_receive_queue;
14025         /*
14026 diff -NurpP --minimal linux-3.1.6/init/Kconfig linux-3.1.6-vs2.3.2.5/init/Kconfig
14027 --- linux-3.1.6/init/Kconfig    2011-10-24 18:45:33.000000000 +0200
14028 +++ linux-3.1.6-vs2.3.2.5/init/Kconfig  2011-10-24 18:53:33.000000000 +0200
14029 @@ -574,6 +574,7 @@ config HAVE_UNSTABLE_SCHED_CLOCK
14030  menuconfig CGROUPS
14031         boolean "Control Group support"
14032         depends on EVENTFD
14033 +       default y
14034         help
14035           This option adds support for grouping sets of processes together, for
14036           use with process control subsystems such as Cpusets, CFS, memory
14037 @@ -790,6 +791,7 @@ config IPC_NS
14038  config USER_NS
14039         bool "User namespace (EXPERIMENTAL)"
14040         depends on EXPERIMENTAL
14041 +       depends on VSERVER_DISABLED
14042         default y
14043         help
14044           This allows containers, i.e. vservers, to use user namespaces
14045 diff -NurpP --minimal linux-3.1.6/init/main.c linux-3.1.6-vs2.3.2.5/init/main.c
14046 --- linux-3.1.6/init/main.c     2011-10-24 18:45:33.000000000 +0200
14047 +++ linux-3.1.6-vs2.3.2.5/init/main.c   2011-10-24 18:53:33.000000000 +0200
14048 @@ -68,6 +68,7 @@
14049  #include <linux/shmem_fs.h>
14050  #include <linux/slab.h>
14051  #include <linux/perf_event.h>
14052 +#include <linux/vserver/percpu.h>
14053  
14054  #include <asm/io.h>
14055  #include <asm/bugs.h>
14056 diff -NurpP --minimal linux-3.1.6/ipc/mqueue.c linux-3.1.6-vs2.3.2.5/ipc/mqueue.c
14057 --- linux-3.1.6/ipc/mqueue.c    2011-10-24 18:45:33.000000000 +0200
14058 +++ linux-3.1.6-vs2.3.2.5/ipc/mqueue.c  2011-10-24 18:53:33.000000000 +0200
14059 @@ -33,6 +33,8 @@
14060  #include <linux/pid.h>
14061  #include <linux/ipc_namespace.h>
14062  #include <linux/slab.h>
14063 +#include <linux/vs_context.h>
14064 +#include <linux/vs_limit.h>
14065  
14066  #include <net/sock.h>
14067  #include "util.h"
14068 @@ -66,6 +68,7 @@ struct mqueue_inode_info {
14069         struct sigevent notify;
14070         struct pid* notify_owner;
14071         struct user_struct *user;       /* user who created, for accounting */
14072 +       struct vx_info *vxi;
14073         struct sock *notify_sock;
14074         struct sk_buff *notify_cookie;
14075  
14076 @@ -128,6 +131,7 @@ static struct inode *mqueue_get_inode(st
14077         if (S_ISREG(mode)) {
14078                 struct mqueue_inode_info *info;
14079                 struct task_struct *p = current;
14080 +               struct vx_info *vxi = p->vx_info;
14081                 unsigned long mq_bytes, mq_msg_tblsz;
14082  
14083                 inode->i_fop = &mqueue_file_operations;
14084 @@ -141,6 +145,7 @@ static struct inode *mqueue_get_inode(st
14085                 info->notify_owner = NULL;
14086                 info->qsize = 0;
14087                 info->user = NULL;      /* set when all is ok */
14088 +               info->vxi = NULL;
14089                 memset(&info->attr, 0, sizeof(info->attr));
14090                 info->attr.mq_maxmsg = ipc_ns->mq_msg_max;
14091                 info->attr.mq_msgsize = ipc_ns->mq_msgsize_max;
14092 @@ -158,17 +163,20 @@ static struct inode *mqueue_get_inode(st
14093  
14094                 spin_lock(&mq_lock);
14095                 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
14096 -                   u->mq_bytes + mq_bytes > task_rlimit(p, RLIMIT_MSGQUEUE)) {
14097 +                   u->mq_bytes + mq_bytes > task_rlimit(p, RLIMIT_MSGQUEUE) ||
14098 +                   !vx_ipcmsg_avail(vxi, mq_bytes)) {
14099                         spin_unlock(&mq_lock);
14100                         /* mqueue_evict_inode() releases info->messages */
14101                         ret = -EMFILE;
14102                         goto out_inode;
14103                 }
14104                 u->mq_bytes += mq_bytes;
14105 +               vx_ipcmsg_add(vxi, u, mq_bytes);
14106                 spin_unlock(&mq_lock);
14107  
14108                 /* all is ok */
14109                 info->user = get_uid(u);
14110 +               info->vxi = get_vx_info(vxi);
14111         } else if (S_ISDIR(mode)) {
14112                 inc_nlink(inode);
14113                 /* Some things misbehave if size == 0 on a directory */
14114 @@ -278,8 +286,11 @@ static void mqueue_evict_inode(struct in
14115             + info->attr.mq_msgsize);
14116         user = info->user;
14117         if (user) {
14118 +               struct vx_info *vxi = info->vxi;
14119 +
14120                 spin_lock(&mq_lock);
14121                 user->mq_bytes -= mq_bytes;
14122 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
14123                 /*
14124                  * get_ns_from_inode() ensures that the
14125                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
14126 @@ -289,6 +300,7 @@ static void mqueue_evict_inode(struct in
14127                 if (ipc_ns)
14128                         ipc_ns->mq_queues_count--;
14129                 spin_unlock(&mq_lock);
14130 +               put_vx_info(vxi);
14131                 free_uid(user);
14132         }
14133         if (ipc_ns)
14134 diff -NurpP --minimal linux-3.1.6/ipc/msg.c linux-3.1.6-vs2.3.2.5/ipc/msg.c
14135 --- linux-3.1.6/ipc/msg.c       2011-05-22 16:17:59.000000000 +0200
14136 +++ linux-3.1.6-vs2.3.2.5/ipc/msg.c     2011-10-24 18:53:33.000000000 +0200
14137 @@ -37,6 +37,7 @@
14138  #include <linux/rwsem.h>
14139  #include <linux/nsproxy.h>
14140  #include <linux/ipc_namespace.h>
14141 +#include <linux/vs_base.h>
14142  
14143  #include <asm/current.h>
14144  #include <asm/uaccess.h>
14145 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
14146  
14147         msq->q_perm.mode = msgflg & S_IRWXUGO;
14148         msq->q_perm.key = key;
14149 +       msq->q_perm.xid = vx_current_xid();
14150  
14151         msq->q_perm.security = NULL;
14152         retval = security_msg_queue_alloc(msq);
14153 diff -NurpP --minimal linux-3.1.6/ipc/namespace.c linux-3.1.6-vs2.3.2.5/ipc/namespace.c
14154 --- linux-3.1.6/ipc/namespace.c 2011-07-22 11:18:12.000000000 +0200
14155 +++ linux-3.1.6-vs2.3.2.5/ipc/namespace.c       2011-10-24 18:53:33.000000000 +0200
14156 @@ -13,11 +13,12 @@
14157  #include <linux/mount.h>
14158  #include <linux/user_namespace.h>
14159  #include <linux/proc_fs.h>
14160 +#include <linux/vs_base.h>
14161 +#include <linux/vserver/global.h>
14162  
14163  #include "util.h"
14164  
14165 -static struct ipc_namespace *create_ipc_ns(struct task_struct *tsk,
14166 -                                          struct ipc_namespace *old_ns)
14167 +static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns)
14168  {
14169         struct ipc_namespace *ns;
14170         int err;
14171 @@ -46,19 +47,18 @@ static struct ipc_namespace *create_ipc_
14172         ipcns_notify(IPCNS_CREATED);
14173         register_ipcns_notifier(ns);
14174  
14175 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user)->user_ns);
14176 +       ns->user_ns = get_user_ns(user_ns);
14177  
14178         return ns;
14179  }
14180  
14181  struct ipc_namespace *copy_ipcs(unsigned long flags,
14182 -                               struct task_struct *tsk)
14183 +                               struct ipc_namespace *old_ns,
14184 +                               struct user_namespace *user_ns)
14185  {
14186 -       struct ipc_namespace *ns = tsk->nsproxy->ipc_ns;
14187 -
14188         if (!(flags & CLONE_NEWIPC))
14189 -               return get_ipc_ns(ns);
14190 -       return create_ipc_ns(tsk, ns);
14191 +               return get_ipc_ns(old_ns);
14192 +       return create_ipc_ns(user_ns);
14193  }
14194  
14195  /*
14196 diff -NurpP --minimal linux-3.1.6/ipc/sem.c linux-3.1.6-vs2.3.2.5/ipc/sem.c
14197 --- linux-3.1.6/ipc/sem.c       2011-10-24 18:45:33.000000000 +0200
14198 +++ linux-3.1.6-vs2.3.2.5/ipc/sem.c     2011-10-24 18:53:33.000000000 +0200
14199 @@ -86,6 +86,8 @@
14200  #include <linux/rwsem.h>
14201  #include <linux/nsproxy.h>
14202  #include <linux/ipc_namespace.h>
14203 +#include <linux/vs_base.h>
14204 +#include <linux/vs_limit.h>
14205  
14206  #include <asm/uaccess.h>
14207  #include "util.h"
14208 @@ -260,6 +262,7 @@ static int newary(struct ipc_namespace *
14209  
14210         sma->sem_perm.mode = (semflg & S_IRWXUGO);
14211         sma->sem_perm.key = key;
14212 +       sma->sem_perm.xid = vx_current_xid();
14213  
14214         sma->sem_perm.security = NULL;
14215         retval = security_sem_alloc(sma);
14216 @@ -275,6 +278,9 @@ static int newary(struct ipc_namespace *
14217                 return id;
14218         }
14219         ns->used_sems += nsems;
14220 +       /* FIXME: obsoleted? */
14221 +       vx_semary_inc(sma);
14222 +       vx_nsems_add(sma, nsems);
14223  
14224         sma->sem_base = (struct sem *) &sma[1];
14225  
14226 @@ -724,6 +730,9 @@ static void freeary(struct ipc_namespace
14227  
14228         wake_up_sem_queue_do(&tasks);
14229         ns->used_sems -= sma->sem_nsems;
14230 +       /* FIXME: obsoleted? */
14231 +       vx_nsems_sub(sma, sma->sem_nsems);
14232 +       vx_semary_dec(sma);
14233         security_sem_free(sma);
14234         ipc_rcu_putref(sma);
14235  }
14236 diff -NurpP --minimal linux-3.1.6/ipc/shm.c linux-3.1.6-vs2.3.2.5/ipc/shm.c
14237 --- linux-3.1.6/ipc/shm.c       2011-10-24 18:45:33.000000000 +0200
14238 +++ linux-3.1.6-vs2.3.2.5/ipc/shm.c     2011-10-24 18:53:33.000000000 +0200
14239 @@ -39,6 +39,8 @@
14240  #include <linux/nsproxy.h>
14241  #include <linux/mount.h>
14242  #include <linux/ipc_namespace.h>
14243 +#include <linux/vs_context.h>
14244 +#include <linux/vs_limit.h>
14245  
14246  #include <asm/uaccess.h>
14247  
14248 @@ -187,7 +189,12 @@ static void shm_open(struct vm_area_stru
14249   */
14250  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
14251  {
14252 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14253 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
14254 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14255 +
14256 +       vx_ipcshm_sub(vxi, shp, numpages);
14257 +       ns->shm_tot -= numpages;
14258 +
14259         shm_rmid(ns, shp);
14260         shm_unlock(shp);
14261         if (!is_file_hugepages(shp->shm_file))
14262 @@ -197,6 +204,7 @@ static void shm_destroy(struct ipc_names
14263                                                 shp->mlock_user);
14264         fput (shp->shm_file);
14265         security_shm_free(shp);
14266 +       put_vx_info(vxi);
14267         ipc_rcu_putref(shp);
14268  }
14269  
14270 @@ -462,11 +470,15 @@ static int newseg(struct ipc_namespace *
14271         if (ns->shm_tot + numpages > ns->shm_ctlall)
14272                 return -ENOSPC;
14273  
14274 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
14275 +               return -ENOSPC;
14276 +
14277         shp = ipc_rcu_alloc(sizeof(*shp));
14278         if (!shp)
14279                 return -ENOMEM;
14280  
14281         shp->shm_perm.key = key;
14282 +       shp->shm_perm.xid = vx_current_xid();
14283         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
14284         shp->mlock_user = NULL;
14285  
14286 @@ -521,6 +533,7 @@ static int newseg(struct ipc_namespace *
14287         ns->shm_tot += numpages;
14288         error = shp->shm_perm.id;
14289         shm_unlock(shp);
14290 +       vx_ipcshm_add(current_vx_info(), key, numpages);
14291         return error;
14292  
14293  no_id:
14294 diff -NurpP --minimal linux-3.1.6/kernel/Makefile linux-3.1.6-vs2.3.2.5/kernel/Makefile
14295 --- linux-3.1.6/kernel/Makefile 2011-10-24 18:45:33.000000000 +0200
14296 +++ linux-3.1.6-vs2.3.2.5/kernel/Makefile       2011-10-24 18:53:33.000000000 +0200
14297 @@ -24,6 +24,7 @@ CFLAGS_REMOVE_sched_clock.o = -pg
14298  CFLAGS_REMOVE_irq_work.o = -pg
14299  endif
14300  
14301 +obj-y += vserver/
14302  obj-$(CONFIG_FREEZER) += freezer.o
14303  obj-$(CONFIG_PROFILING) += profile.o
14304  obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
14305 diff -NurpP --minimal linux-3.1.6/kernel/capability.c linux-3.1.6-vs2.3.2.5/kernel/capability.c
14306 --- linux-3.1.6/kernel/capability.c     2011-07-22 11:18:12.000000000 +0200
14307 +++ linux-3.1.6-vs2.3.2.5/kernel/capability.c   2011-11-18 00:38:57.000000000 +0100
14308 @@ -15,6 +15,7 @@
14309  #include <linux/syscalls.h>
14310  #include <linux/pid_namespace.h>
14311  #include <linux/user_namespace.h>
14312 +#include <linux/vs_context.h>
14313  #include <asm/uaccess.h>
14314  
14315  /*
14316 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
14317         return 0;
14318  }
14319  
14320 +
14321  /*
14322   * The only thing that can change the capabilities of the current
14323   * process is the current process. As such, we can't be in this code
14324 @@ -340,6 +342,8 @@ bool has_capability_noaudit(struct task_
14325         return (ret == 0);
14326  }
14327  
14328 +#include <linux/vserver/base.h>
14329 +
14330  /**
14331   * capable - Determine if the current task has a superior capability in effect
14332   * @cap: The capability to be tested for
14333 diff -NurpP --minimal linux-3.1.6/kernel/compat.c linux-3.1.6-vs2.3.2.5/kernel/compat.c
14334 --- linux-3.1.6/kernel/compat.c 2011-10-24 18:45:33.000000000 +0200
14335 +++ linux-3.1.6-vs2.3.2.5/kernel/compat.c       2011-10-24 18:53:33.000000000 +0200
14336 @@ -972,7 +972,7 @@ asmlinkage long compat_sys_stime(compat_
14337         if (err)
14338                 return err;
14339  
14340 -       do_settimeofday(&tv);
14341 +       vx_settimeofday(&tv);
14342         return 0;
14343  }
14344  
14345 diff -NurpP --minimal linux-3.1.6/kernel/cred.c linux-3.1.6-vs2.3.2.5/kernel/cred.c
14346 --- linux-3.1.6/kernel/cred.c   2011-10-24 18:45:33.000000000 +0200
14347 +++ linux-3.1.6-vs2.3.2.5/kernel/cred.c 2011-10-24 18:53:33.000000000 +0200
14348 @@ -61,31 +61,6 @@ struct cred init_cred = {
14349  #endif
14350  };
14351  
14352 -static inline void set_cred_subscribers(struct cred *cred, int n)
14353 -{
14354 -#ifdef CONFIG_DEBUG_CREDENTIALS
14355 -       atomic_set(&cred->subscribers, n);
14356 -#endif
14357 -}
14358 -
14359 -static inline int read_cred_subscribers(const struct cred *cred)
14360 -{
14361 -#ifdef CONFIG_DEBUG_CREDENTIALS
14362 -       return atomic_read(&cred->subscribers);
14363 -#else
14364 -       return 0;
14365 -#endif
14366 -}
14367 -
14368 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
14369 -{
14370 -#ifdef CONFIG_DEBUG_CREDENTIALS
14371 -       struct cred *cred = (struct cred *) _cred;
14372 -
14373 -       atomic_add(n, &cred->subscribers);
14374 -#endif
14375 -}
14376 -
14377  /*
14378   * Dispose of the shared task group credentials
14379   */
14380 @@ -281,21 +256,16 @@ error:
14381   *
14382   * Call commit_creds() or abort_creds() to clean up.
14383   */
14384 -struct cred *prepare_creds(void)
14385 +struct cred *__prepare_creds(const struct cred *old)
14386  {
14387 -       struct task_struct *task = current;
14388 -       const struct cred *old;
14389         struct cred *new;
14390  
14391 -       validate_process_creds();
14392 -
14393         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
14394         if (!new)
14395                 return NULL;
14396  
14397         kdebug("prepare_creds() alloc %p", new);
14398  
14399 -       old = task->cred;
14400         memcpy(new, old, sizeof(struct cred));
14401  
14402         atomic_set(&new->usage, 1);
14403 @@ -322,6 +292,13 @@ error:
14404         abort_creds(new);
14405         return NULL;
14406  }
14407 +
14408 +struct cred *prepare_creds(void)
14409 +{
14410 +       validate_process_creds();
14411 +
14412 +       return __prepare_creds(current->cred);
14413 +}
14414  EXPORT_SYMBOL(prepare_creds);
14415  
14416  /*
14417 diff -NurpP --minimal linux-3.1.6/kernel/exit.c linux-3.1.6-vs2.3.2.5/kernel/exit.c
14418 --- linux-3.1.6/kernel/exit.c   2011-10-24 18:45:33.000000000 +0200
14419 +++ linux-3.1.6-vs2.3.2.5/kernel/exit.c 2011-10-24 18:53:33.000000000 +0200
14420 @@ -48,6 +48,10 @@
14421  #include <linux/fs_struct.h>
14422  #include <linux/init_task.h>
14423  #include <linux/perf_event.h>
14424 +#include <linux/vs_limit.h>
14425 +#include <linux/vs_context.h>
14426 +#include <linux/vs_network.h>
14427 +#include <linux/vs_pid.h>
14428  #include <trace/events/sched.h>
14429  #include <linux/hw_breakpoint.h>
14430  #include <linux/oom.h>
14431 @@ -480,9 +484,11 @@ static void close_files(struct files_str
14432                                         filp_close(file, files);
14433                                         cond_resched();
14434                                 }
14435 +                               vx_openfd_dec(i);
14436                         }
14437                         i++;
14438                         set >>= 1;
14439 +                       cond_resched();
14440                 }
14441         }
14442  }
14443 @@ -1038,11 +1044,16 @@ NORET_TYPE void do_exit(long code)
14444  
14445         validate_creds_for_do_exit(tsk);
14446  
14447 +       /* needs to stay after exit_notify() */
14448 +       exit_vx_info(tsk, code);
14449 +       exit_nx_info(tsk);
14450 +
14451         preempt_disable();
14452         exit_rcu();
14453         /* causes final put_task_struct in finish_task_switch(). */
14454         tsk->state = TASK_DEAD;
14455         schedule();
14456 +       printk("bad task: %p [%lx]\n", current, current->state);
14457         BUG();
14458         /* Avoid "noreturn function does return".  */
14459         for (;;)
14460 diff -NurpP --minimal linux-3.1.6/kernel/fork.c linux-3.1.6-vs2.3.2.5/kernel/fork.c
14461 --- linux-3.1.6/kernel/fork.c   2011-10-24 18:45:33.000000000 +0200
14462 +++ linux-3.1.6-vs2.3.2.5/kernel/fork.c 2011-12-07 04:19:36.000000000 +0100
14463 @@ -66,6 +66,9 @@
14464  #include <linux/user-return-notifier.h>
14465  #include <linux/oom.h>
14466  #include <linux/khugepaged.h>
14467 +#include <linux/vs_context.h>
14468 +#include <linux/vs_network.h>
14469 +#include <linux/vs_limit.h>
14470  
14471  #include <asm/pgtable.h>
14472  #include <asm/pgalloc.h>
14473 @@ -166,6 +169,8 @@ void free_task(struct task_struct *tsk)
14474         account_kernel_stack(tsk->stack, -1);
14475         free_thread_info(tsk->stack);
14476         rt_mutex_debug_task_free(tsk);
14477 +       clr_vx_info(&tsk->vx_info);
14478 +       clr_nx_info(&tsk->nx_info);
14479         ftrace_graph_exit_task(tsk);
14480         free_task_struct(tsk);
14481  }
14482 @@ -506,6 +511,7 @@ static struct mm_struct *mm_init(struct 
14483         if (likely(!mm_alloc_pgd(mm))) {
14484                 mm->def_flags = 0;
14485                 mmu_notifier_mm_init(mm);
14486 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
14487                 return mm;
14488         }
14489  
14490 @@ -543,6 +549,7 @@ void __mmdrop(struct mm_struct *mm)
14491  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
14492         VM_BUG_ON(mm->pmd_huge_pte);
14493  #endif
14494 +       clr_vx_info(&mm->mm_vx_info);
14495         free_mm(mm);
14496  }
14497  EXPORT_SYMBOL_GPL(__mmdrop);
14498 @@ -730,6 +737,7 @@ struct mm_struct *dup_mm(struct task_str
14499                 goto fail_nomem;
14500  
14501         memcpy(mm, oldmm, sizeof(*mm));
14502 +       mm->mm_vx_info = NULL;
14503         mm_init_cpumask(mm);
14504  
14505         /* Initializing for Swap token stuff */
14506 @@ -773,6 +781,7 @@ fail_nocontext:
14507          * If init_new_context() failed, we cannot use mmput() to free the mm
14508          * because it calls destroy_context()
14509          */
14510 +       clr_vx_info(&mm->mm_vx_info);
14511         mm_free_pgd(mm);
14512         free_mm(mm);
14513         return NULL;
14514 @@ -1058,6 +1067,8 @@ static struct task_struct *copy_process(
14515         int retval;
14516         struct task_struct *p;
14517         int cgroup_callbacks_done = 0;
14518 +       struct vx_info *vxi;
14519 +       struct nx_info *nxi;
14520  
14521         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
14522                 return ERR_PTR(-EINVAL);
14523 @@ -1104,7 +1115,12 @@ static struct task_struct *copy_process(
14524         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
14525         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
14526  #endif
14527 +       init_vx_info(&p->vx_info, current_vx_info());
14528 +       init_nx_info(&p->nx_info, current_nx_info());
14529 +
14530         retval = -EAGAIN;
14531 +       if (!vx_nproc_avail(1))
14532 +               goto bad_fork_free;
14533         if (atomic_read(&p->real_cred->user->processes) >=
14534                         task_rlimit(p, RLIMIT_NPROC)) {
14535                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
14536 @@ -1374,6 +1390,18 @@ static struct task_struct *copy_process(
14537  
14538         total_forks++;
14539         spin_unlock(&current->sighand->siglock);
14540 +
14541 +       /* p is copy of current */
14542 +       vxi = p->vx_info;
14543 +       if (vxi) {
14544 +               claim_vx_info(vxi, p);
14545 +               atomic_inc(&vxi->cvirt.nr_threads);
14546 +               atomic_inc(&vxi->cvirt.total_forks);
14547 +               vx_nproc_inc(p);
14548 +       }
14549 +       nxi = p->nx_info;
14550 +       if (nxi)
14551 +               claim_nx_info(nxi, p);
14552         write_unlock_irq(&tasklist_lock);
14553         proc_fork_connector(p);
14554         cgroup_post_fork(p);
14555 diff -NurpP --minimal linux-3.1.6/kernel/kthread.c linux-3.1.6-vs2.3.2.5/kernel/kthread.c
14556 --- linux-3.1.6/kernel/kthread.c        2011-07-22 11:18:12.000000000 +0200
14557 +++ linux-3.1.6-vs2.3.2.5/kernel/kthread.c      2011-10-24 18:53:33.000000000 +0200
14558 @@ -16,6 +16,7 @@
14559  #include <linux/mutex.h>
14560  #include <linux/slab.h>
14561  #include <linux/freezer.h>
14562 +#include <linux/vs_pid.h>
14563  #include <trace/events/sched.h>
14564  
14565  static DEFINE_SPINLOCK(kthread_create_lock);
14566 diff -NurpP --minimal linux-3.1.6/kernel/nsproxy.c linux-3.1.6-vs2.3.2.5/kernel/nsproxy.c
14567 --- linux-3.1.6/kernel/nsproxy.c        2011-10-24 18:45:33.000000000 +0200
14568 +++ linux-3.1.6-vs2.3.2.5/kernel/nsproxy.c      2011-10-24 18:53:33.000000000 +0200
14569 @@ -20,6 +20,8 @@
14570  #include <linux/mnt_namespace.h>
14571  #include <linux/utsname.h>
14572  #include <linux/pid_namespace.h>
14573 +#include <linux/vserver/global.h>
14574 +#include <linux/vserver/debug.h>
14575  #include <net/net_namespace.h>
14576  #include <linux/ipc_namespace.h>
14577  #include <linux/proc_fs.h>
14578 @@ -46,8 +48,11 @@ static inline struct nsproxy *create_nsp
14579         struct nsproxy *nsproxy;
14580  
14581         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
14582 -       if (nsproxy)
14583 +       if (nsproxy) {
14584                 atomic_set(&nsproxy->count, 1);
14585 +               atomic_inc(&vs_global_nsproxy);
14586 +       }
14587 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
14588         return nsproxy;
14589  }
14590  
14591 @@ -56,8 +61,11 @@ static inline struct nsproxy *create_nsp
14592   * Return the newly created nsproxy.  Do not attach this to the task,
14593   * leave it to the caller to do proper locking and attach it to task.
14594   */
14595 -static struct nsproxy *create_new_namespaces(unsigned long flags,
14596 -                       struct task_struct *tsk, struct fs_struct *new_fs)
14597 +static struct nsproxy *unshare_namespaces(unsigned long flags,
14598 +                       struct nsproxy *orig,
14599 +                       struct fs_struct *new_fs,
14600 +                       struct user_namespace *new_user,
14601 +                       struct pid_namespace *new_pid)
14602  {
14603         struct nsproxy *new_nsp;
14604         int err;
14605 @@ -66,31 +74,31 @@ static struct nsproxy *create_new_namesp
14606         if (!new_nsp)
14607                 return ERR_PTR(-ENOMEM);
14608  
14609 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
14610 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
14611         if (IS_ERR(new_nsp->mnt_ns)) {
14612                 err = PTR_ERR(new_nsp->mnt_ns);
14613                 goto out_ns;
14614         }
14615  
14616 -       new_nsp->uts_ns = copy_utsname(flags, tsk);
14617 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns, new_user);
14618         if (IS_ERR(new_nsp->uts_ns)) {
14619                 err = PTR_ERR(new_nsp->uts_ns);
14620                 goto out_uts;
14621         }
14622  
14623 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk);
14624 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns, new_user);
14625         if (IS_ERR(new_nsp->ipc_ns)) {
14626                 err = PTR_ERR(new_nsp->ipc_ns);
14627                 goto out_ipc;
14628         }
14629  
14630 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
14631 +       new_nsp->pid_ns = copy_pid_ns(flags, new_pid);
14632         if (IS_ERR(new_nsp->pid_ns)) {
14633                 err = PTR_ERR(new_nsp->pid_ns);
14634                 goto out_pid;
14635         }
14636  
14637 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
14638 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
14639         if (IS_ERR(new_nsp->net_ns)) {
14640                 err = PTR_ERR(new_nsp->net_ns);
14641                 goto out_net;
14642 @@ -115,6 +123,40 @@ out_ns:
14643         return ERR_PTR(err);
14644  }
14645  
14646 +static struct nsproxy *create_new_namespaces(unsigned long flags,
14647 +                       struct task_struct *tsk, struct fs_struct *new_fs)
14648 +{
14649 +       return unshare_namespaces(flags, tsk->nsproxy,
14650 +               new_fs, task_cred_xxx(tsk, user)->user_ns,
14651 +               task_active_pid_ns(tsk));
14652 +}
14653 +
14654 +/*
14655 + * copies the nsproxy, setting refcount to 1, and grabbing a
14656 + * reference to all contained namespaces.
14657 + */
14658 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
14659 +{
14660 +       struct nsproxy *ns = create_nsproxy();
14661 +
14662 +       if (ns) {
14663 +               memcpy(ns, orig, sizeof(struct nsproxy));
14664 +               atomic_set(&ns->count, 1);
14665 +
14666 +               if (ns->mnt_ns)
14667 +                       get_mnt_ns(ns->mnt_ns);
14668 +               if (ns->uts_ns)
14669 +                       get_uts_ns(ns->uts_ns);
14670 +               if (ns->ipc_ns)
14671 +                       get_ipc_ns(ns->ipc_ns);
14672 +               if (ns->pid_ns)
14673 +                       get_pid_ns(ns->pid_ns);
14674 +               if (ns->net_ns)
14675 +                       get_net(ns->net_ns);
14676 +       }
14677 +       return ns;
14678 +}
14679 +
14680  /*
14681   * called from clone.  This now handles copy for nsproxy and all
14682   * namespaces therein.
14683 @@ -122,9 +164,12 @@ out_ns:
14684  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
14685  {
14686         struct nsproxy *old_ns = tsk->nsproxy;
14687 -       struct nsproxy *new_ns;
14688 +       struct nsproxy *new_ns = NULL;
14689         int err = 0;
14690  
14691 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
14692 +               flags, tsk, old_ns);
14693 +
14694         if (!old_ns)
14695                 return 0;
14696  
14697 @@ -134,7 +179,7 @@ int copy_namespaces(unsigned long flags,
14698                                 CLONE_NEWPID | CLONE_NEWNET)))
14699                 return 0;
14700  
14701 -       if (!capable(CAP_SYS_ADMIN)) {
14702 +       if (!vx_can_unshare(CAP_SYS_ADMIN, flags)) {
14703                 err = -EPERM;
14704                 goto out;
14705         }
14706 @@ -161,6 +206,9 @@ int copy_namespaces(unsigned long flags,
14707  
14708  out:
14709         put_nsproxy(old_ns);
14710 +       vxdprintk(VXD_CBIT(space, 3),
14711 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
14712 +               flags, tsk, old_ns, err, new_ns);
14713         return err;
14714  }
14715  
14716 @@ -174,7 +222,9 @@ void free_nsproxy(struct nsproxy *ns)
14717                 put_ipc_ns(ns->ipc_ns);
14718         if (ns->pid_ns)
14719                 put_pid_ns(ns->pid_ns);
14720 -       put_net(ns->net_ns);
14721 +       if (ns->net_ns)
14722 +               put_net(ns->net_ns);
14723 +       atomic_dec(&vs_global_nsproxy);
14724         kmem_cache_free(nsproxy_cachep, ns);
14725  }
14726  
14727 @@ -187,11 +237,15 @@ int unshare_nsproxy_namespaces(unsigned 
14728  {
14729         int err = 0;
14730  
14731 +       vxdprintk(VXD_CBIT(space, 4),
14732 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
14733 +               unshare_flags, current->nsproxy);
14734 +
14735         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
14736                                CLONE_NEWNET)))
14737                 return 0;
14738  
14739 -       if (!capable(CAP_SYS_ADMIN))
14740 +       if (!vx_can_unshare(CAP_SYS_ADMIN, unshare_flags))
14741                 return -EPERM;
14742  
14743         *new_nsp = create_new_namespaces(unshare_flags, current,
14744 diff -NurpP --minimal linux-3.1.6/kernel/pid.c linux-3.1.6-vs2.3.2.5/kernel/pid.c
14745 --- linux-3.1.6/kernel/pid.c    2011-10-24 18:45:33.000000000 +0200
14746 +++ linux-3.1.6-vs2.3.2.5/kernel/pid.c  2011-10-24 18:53:33.000000000 +0200
14747 @@ -36,6 +36,7 @@
14748  #include <linux/pid_namespace.h>
14749  #include <linux/init_task.h>
14750  #include <linux/syscalls.h>
14751 +#include <linux/vs_pid.h>
14752  
14753  #define pid_hashfn(nr, ns)     \
14754         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
14755 @@ -342,7 +343,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
14756  
14757  struct pid *find_vpid(int nr)
14758  {
14759 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
14760 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
14761  }
14762  EXPORT_SYMBOL_GPL(find_vpid);
14763  
14764 @@ -402,6 +403,9 @@ void transfer_pid(struct task_struct *ol
14765  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
14766  {
14767         struct task_struct *result = NULL;
14768 +
14769 +       if (type == PIDTYPE_REALPID)
14770 +               type = PIDTYPE_PID;
14771         if (pid) {
14772                 struct hlist_node *first;
14773                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
14774 @@ -419,7 +423,7 @@ EXPORT_SYMBOL(pid_task);
14775  struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
14776  {
14777         rcu_lockdep_assert(rcu_read_lock_held());
14778 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
14779 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
14780  }
14781  
14782  struct task_struct *find_task_by_vpid(pid_t vnr)
14783 @@ -463,7 +467,7 @@ struct pid *find_get_pid(pid_t nr)
14784  }
14785  EXPORT_SYMBOL_GPL(find_get_pid);
14786  
14787 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14788 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
14789  {
14790         struct upid *upid;
14791         pid_t nr = 0;
14792 @@ -476,6 +480,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
14793         return nr;
14794  }
14795  
14796 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14797 +{
14798 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
14799 +}
14800 +
14801  pid_t pid_vnr(struct pid *pid)
14802  {
14803         return pid_nr_ns(pid, current->nsproxy->pid_ns);
14804 diff -NurpP --minimal linux-3.1.6/kernel/pid_namespace.c linux-3.1.6-vs2.3.2.5/kernel/pid_namespace.c
14805 --- linux-3.1.6/kernel/pid_namespace.c  2011-05-22 16:17:59.000000000 +0200
14806 +++ linux-3.1.6-vs2.3.2.5/kernel/pid_namespace.c        2011-10-24 18:53:33.000000000 +0200
14807 @@ -15,6 +15,7 @@
14808  #include <linux/acct.h>
14809  #include <linux/slab.h>
14810  #include <linux/proc_fs.h>
14811 +#include <linux/vserver/global.h>
14812  
14813  #define BITS_PER_PAGE          (PAGE_SIZE*8)
14814  
14815 @@ -88,6 +89,7 @@ static struct pid_namespace *create_pid_
14816                 goto out_free_map;
14817  
14818         kref_init(&ns->kref);
14819 +       atomic_inc(&vs_global_pid_ns);
14820         ns->level = level;
14821         ns->parent = get_pid_ns(parent_pid_ns);
14822  
14823 @@ -119,6 +121,7 @@ static void destroy_pid_namespace(struct
14824  
14825         for (i = 0; i < PIDMAP_ENTRIES; i++)
14826                 kfree(ns->pidmap[i].page);
14827 +       atomic_dec(&vs_global_pid_ns);
14828         kmem_cache_free(pid_ns_cachep, ns);
14829  }
14830  
14831 diff -NurpP --minimal linux-3.1.6/kernel/posix-timers.c linux-3.1.6-vs2.3.2.5/kernel/posix-timers.c
14832 --- linux-3.1.6/kernel/posix-timers.c   2011-07-22 11:18:12.000000000 +0200
14833 +++ linux-3.1.6-vs2.3.2.5/kernel/posix-timers.c 2011-10-24 18:53:33.000000000 +0200
14834 @@ -47,6 +47,7 @@
14835  #include <linux/wait.h>
14836  #include <linux/workqueue.h>
14837  #include <linux/module.h>
14838 +#include <linux/vs_context.h>
14839  
14840  /*
14841   * Management arrays for POSIX timers.  Timers are kept in slab memory
14842 @@ -340,6 +341,7 @@ int posix_timer_event(struct k_itimer *t
14843  {
14844         struct task_struct *task;
14845         int shared, ret = -1;
14846 +
14847         /*
14848          * FIXME: if ->sigq is queued we can race with
14849          * dequeue_signal()->do_schedule_next_timer().
14850 @@ -356,10 +358,18 @@ int posix_timer_event(struct k_itimer *t
14851         rcu_read_lock();
14852         task = pid_task(timr->it_pid, PIDTYPE_PID);
14853         if (task) {
14854 +               struct vx_info_save vxis;
14855 +               struct vx_info *vxi;
14856 +
14857 +               vxi = get_vx_info(task->vx_info);
14858 +               enter_vx_info(vxi, &vxis);
14859                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
14860                 ret = send_sigqueue(timr->sigq, task, shared);
14861 +               leave_vx_info(&vxis);
14862 +               put_vx_info(vxi);
14863         }
14864         rcu_read_unlock();
14865 +
14866         /* If we failed to send the signal the timer stops. */
14867         return ret > 0;
14868  }
14869 diff -NurpP --minimal linux-3.1.6/kernel/printk.c linux-3.1.6-vs2.3.2.5/kernel/printk.c
14870 --- linux-3.1.6/kernel/printk.c 2011-10-24 18:45:33.000000000 +0200
14871 +++ linux-3.1.6-vs2.3.2.5/kernel/printk.c       2011-10-24 18:53:33.000000000 +0200
14872 @@ -41,6 +41,7 @@
14873  #include <linux/cpu.h>
14874  #include <linux/notifier.h>
14875  #include <linux/rculist.h>
14876 +#include <linux/vs_cvirt.h>
14877  
14878  #include <asm/uaccess.h>
14879  
14880 @@ -314,7 +315,7 @@ static int check_syslog_permissions(int 
14881                 return 0;
14882  
14883         if (syslog_action_restricted(type)) {
14884 -               if (capable(CAP_SYSLOG))
14885 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
14886                         return 0;
14887                 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
14888                 if (capable(CAP_SYS_ADMIN)) {
14889 @@ -344,12 +345,9 @@ int do_syslog(int type, char __user *buf
14890         if (error)
14891                 return error;
14892  
14893 -       switch (type) {
14894 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
14895 -               break;
14896 -       case SYSLOG_ACTION_OPEN:        /* Open log */
14897 -               break;
14898 -       case SYSLOG_ACTION_READ:        /* Read from log */
14899 +       if ((type == SYSLOG_ACTION_READ) ||
14900 +           (type == SYSLOG_ACTION_READ_ALL) ||
14901 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
14902                 error = -EINVAL;
14903                 if (!buf || len < 0)
14904                         goto out;
14905 @@ -360,6 +358,16 @@ int do_syslog(int type, char __user *buf
14906                         error = -EFAULT;
14907                         goto out;
14908                 }
14909 +       }
14910 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
14911 +               return vx_do_syslog(type, buf, len);
14912 +
14913 +       switch (type) {
14914 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
14915 +               break;
14916 +       case SYSLOG_ACTION_OPEN:        /* Open log */
14917 +               break;
14918 +       case SYSLOG_ACTION_READ:        /* Read from log */
14919                 error = wait_event_interruptible(log_wait,
14920                                                         (log_start - log_end));
14921                 if (error)
14922 @@ -386,16 +394,6 @@ int do_syslog(int type, char __user *buf
14923                 /* FALL THRU */
14924         /* Read last kernel messages */
14925         case SYSLOG_ACTION_READ_ALL:
14926 -               error = -EINVAL;
14927 -               if (!buf || len < 0)
14928 -                       goto out;
14929 -               error = 0;
14930 -               if (!len)
14931 -                       goto out;
14932 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
14933 -                       error = -EFAULT;
14934 -                       goto out;
14935 -               }
14936                 count = len;
14937                 if (count > log_buf_len)
14938                         count = log_buf_len;
14939 diff -NurpP --minimal linux-3.1.6/kernel/ptrace.c linux-3.1.6-vs2.3.2.5/kernel/ptrace.c
14940 --- linux-3.1.6/kernel/ptrace.c 2011-10-24 18:45:33.000000000 +0200
14941 +++ linux-3.1.6-vs2.3.2.5/kernel/ptrace.c       2011-10-24 18:53:33.000000000 +0200
14942 @@ -22,6 +22,7 @@
14943  #include <linux/syscalls.h>
14944  #include <linux/uaccess.h>
14945  #include <linux/regset.h>
14946 +#include <linux/vs_context.h>
14947  #include <linux/hw_breakpoint.h>
14948  #include <linux/cn_proc.h>
14949  
14950 @@ -198,6 +199,11 @@ ok:
14951                 dumpable = get_dumpable(task->mm);
14952         if (!dumpable && !task_ns_capable(task, CAP_SYS_PTRACE))
14953                 return -EPERM;
14954 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
14955 +               return -EPERM;
14956 +       if (!vx_check(task->xid, VS_IDENT) &&
14957 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
14958 +               return -EACCES;
14959  
14960         return security_ptrace_access_check(task, mode);
14961  }
14962 diff -NurpP --minimal linux-3.1.6/kernel/sched.c linux-3.1.6-vs2.3.2.5/kernel/sched.c
14963 --- linux-3.1.6/kernel/sched.c  2011-10-24 18:45:33.000000000 +0200
14964 +++ linux-3.1.6-vs2.3.2.5/kernel/sched.c        2011-10-24 18:53:33.000000000 +0200
14965 @@ -71,6 +71,8 @@
14966  #include <linux/ctype.h>
14967  #include <linux/ftrace.h>
14968  #include <linux/slab.h>
14969 +#include <linux/vs_sched.h>
14970 +#include <linux/vs_cvirt.h>
14971  
14972  #include <asm/tlb.h>
14973  #include <asm/irq_regs.h>
14974 @@ -3473,9 +3475,17 @@ static void calc_global_nohz(unsigned lo
14975   */
14976  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
14977  {
14978 -       loads[0] = (avenrun[0] + offset) << shift;
14979 -       loads[1] = (avenrun[1] + offset) << shift;
14980 -       loads[2] = (avenrun[2] + offset) << shift;
14981 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
14982 +               struct vx_info *vxi = current_vx_info();
14983 +
14984 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
14985 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
14986 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
14987 +       } else {
14988 +               loads[0] = (avenrun[0] + offset) << shift;
14989 +               loads[1] = (avenrun[1] + offset) << shift;
14990 +               loads[2] = (avenrun[2] + offset) << shift;
14991 +       }
14992  }
14993  
14994  /*
14995 @@ -3734,16 +3744,19 @@ void account_user_time(struct task_struc
14996                        cputime_t cputime_scaled)
14997  {
14998         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
14999 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15000         cputime64_t tmp;
15001 +       int nice = (TASK_NICE(p) > 0);
15002  
15003         /* Add user time to process. */
15004         p->utime = cputime_add(p->utime, cputime);
15005         p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
15006 +       vx_account_user(vxi, cputime, nice);
15007         account_group_user_time(p, cputime);
15008  
15009         /* Add user time to cpustat. */
15010         tmp = cputime_to_cputime64(cputime);
15011 -       if (TASK_NICE(p) > 0)
15012 +       if (nice)
15013                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
15014         else
15015                 cpustat->user = cputime64_add(cpustat->user, tmp);
15016 @@ -3795,10 +3808,12 @@ void __account_system_time(struct task_s
15017                         cputime_t cputime_scaled, cputime64_t *target_cputime64)
15018  {
15019         cputime64_t tmp = cputime_to_cputime64(cputime);
15020 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15021  
15022         /* Add system time to process. */
15023         p->stime = cputime_add(p->stime, cputime);
15024         p->stimescaled = cputime_add(p->stimescaled, cputime_scaled);
15025 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
15026         account_group_system_time(p, cputime);
15027  
15028         /* Add system time to cpustat. */
15029 @@ -4984,7 +4999,7 @@ SYSCALL_DEFINE1(nice, int, increment)
15030                 nice = 19;
15031  
15032         if (increment < 0 && !can_nice(current, nice))
15033 -               return -EPERM;
15034 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
15035  
15036         retval = security_task_setnice(current, nice);
15037         if (retval)
15038 diff -NurpP --minimal linux-3.1.6/kernel/sched_fair.c linux-3.1.6-vs2.3.2.5/kernel/sched_fair.c
15039 --- linux-3.1.6/kernel/sched_fair.c     2011-10-24 18:45:33.000000000 +0200
15040 +++ linux-3.1.6-vs2.3.2.5/kernel/sched_fair.c   2011-10-24 18:53:33.000000000 +0200
15041 @@ -979,6 +979,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
15042                 __enqueue_entity(cfs_rq, se);
15043         se->on_rq = 1;
15044  
15045 +       if (entity_is_task(se))
15046 +               vx_activate_task(task_of(se));
15047         if (cfs_rq->nr_running == 1)
15048                 list_add_leaf_cfs_rq(cfs_rq);
15049  }
15050 @@ -1055,6 +1057,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
15051         if (se != cfs_rq->curr)
15052                 __dequeue_entity(cfs_rq, se);
15053         se->on_rq = 0;
15054 +       if (entity_is_task(se))
15055 +               vx_deactivate_task(task_of(se));
15056         update_cfs_load(cfs_rq, 0);
15057         account_entity_dequeue(cfs_rq, se);
15058  
15059 diff -NurpP --minimal linux-3.1.6/kernel/signal.c linux-3.1.6-vs2.3.2.5/kernel/signal.c
15060 --- linux-3.1.6/kernel/signal.c 2011-10-24 18:45:33.000000000 +0200
15061 +++ linux-3.1.6-vs2.3.2.5/kernel/signal.c       2011-10-24 18:53:33.000000000 +0200
15062 @@ -28,6 +28,8 @@
15063  #include <linux/freezer.h>
15064  #include <linux/pid_namespace.h>
15065  #include <linux/nsproxy.h>
15066 +#include <linux/vs_context.h>
15067 +#include <linux/vs_pid.h>
15068  #define CREATE_TRACE_POINTS
15069  #include <trace/events/signal.h>
15070  
15071 @@ -789,9 +791,18 @@ static int check_kill_permission(int sig
15072         struct pid *sid;
15073         int error;
15074  
15075 +       vxdprintk(VXD_CBIT(misc, 7),
15076 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
15077 +               sig, info, t, vx_task_xid(t), t->pid);
15078 +
15079         if (!valid_signal(sig))
15080                 return -EINVAL;
15081  
15082 +/*     FIXME: needed? if so, why?
15083 +       if ((info != SEND_SIG_NOINFO) &&
15084 +               (is_si_special(info) || !si_fromuser(info)))
15085 +               goto skip;      */
15086 +
15087         if (!si_fromuser(info))
15088                 return 0;
15089  
15090 @@ -815,6 +826,20 @@ static int check_kill_permission(int sig
15091                 }
15092         }
15093  
15094 +       error = -EPERM;
15095 +       if (t->pid == 1 && current->xid)
15096 +               return error;
15097 +
15098 +       error = -ESRCH;
15099 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
15100 +                 loops, maybe ENOENT or EACCES? */
15101 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
15102 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
15103 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
15104 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
15105 +               return error;
15106 +       }
15107 +/* skip: */
15108         return security_task_kill(t, info, sig, 0);
15109  }
15110  
15111 @@ -1319,7 +1344,7 @@ int kill_pid_info(int sig, struct siginf
15112         rcu_read_lock();
15113  retry:
15114         p = pid_task(pid, PIDTYPE_PID);
15115 -       if (p) {
15116 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
15117                 error = group_send_sig_info(sig, info, p);
15118                 if (unlikely(error == -ESRCH))
15119                         /*
15120 @@ -1358,7 +1383,7 @@ int kill_pid_info_as_uid(int sig, struct
15121  
15122         rcu_read_lock();
15123         p = pid_task(pid, PIDTYPE_PID);
15124 -       if (!p) {
15125 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
15126                 ret = -ESRCH;
15127                 goto out_unlock;
15128         }
15129 @@ -1413,8 +1438,10 @@ static int kill_something_info(int sig, 
15130                 struct task_struct * p;
15131  
15132                 for_each_process(p) {
15133 -                       if (task_pid_vnr(p) > 1 &&
15134 -                                       !same_thread_group(p, current)) {
15135 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
15136 +                               task_pid_vnr(p) > 1 &&
15137 +                               !same_thread_group(p, current) &&
15138 +                               !vx_current_initpid(p->pid)) {
15139                                 int err = group_send_sig_info(sig, info, p);
15140                                 ++count;
15141                                 if (err != -EPERM)
15142 @@ -2249,6 +2276,11 @@ relock:
15143                                 !sig_kernel_only(signr))
15144                         continue;
15145  
15146 +               /* virtual init is protected against user signals */
15147 +               if ((info->si_code == SI_USER) &&
15148 +                       vx_current_initpid(current->pid))
15149 +                       continue;
15150 +
15151                 if (sig_kernel_stop(signr)) {
15152                         /*
15153                          * The default action is to stop all threads in
15154 diff -NurpP --minimal linux-3.1.6/kernel/softirq.c linux-3.1.6-vs2.3.2.5/kernel/softirq.c
15155 --- linux-3.1.6/kernel/softirq.c        2011-07-22 11:18:12.000000000 +0200
15156 +++ linux-3.1.6-vs2.3.2.5/kernel/softirq.c      2011-10-24 18:53:33.000000000 +0200
15157 @@ -24,6 +24,7 @@
15158  #include <linux/ftrace.h>
15159  #include <linux/smp.h>
15160  #include <linux/tick.h>
15161 +#include <linux/vs_context.h>
15162  
15163  #define CREATE_TRACE_POINTS
15164  #include <trace/events/irq.h>
15165 diff -NurpP --minimal linux-3.1.6/kernel/sys.c linux-3.1.6-vs2.3.2.5/kernel/sys.c
15166 --- linux-3.1.6/kernel/sys.c    2011-10-24 18:45:33.000000000 +0200
15167 +++ linux-3.1.6-vs2.3.2.5/kernel/sys.c  2011-10-24 18:53:33.000000000 +0200
15168 @@ -44,6 +44,7 @@
15169  #include <linux/syscalls.h>
15170  #include <linux/kprobes.h>
15171  #include <linux/user_namespace.h>
15172 +#include <linux/vs_pid.h>
15173  
15174  #include <linux/kmsg_dump.h>
15175  /* Move somewhere else to avoid recompiling? */
15176 @@ -154,7 +155,10 @@ static int set_one_prio(struct task_stru
15177                 goto out;
15178         }
15179         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
15180 -               error = -EACCES;
15181 +               if (vx_flags(VXF_IGNEG_NICE, 0))
15182 +                       error = 0;
15183 +               else
15184 +                       error = -EACCES;
15185                 goto out;
15186         }
15187         no_nice = security_task_setnice(p, niceval);
15188 @@ -204,6 +208,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
15189                         else
15190                                 pgrp = task_pgrp(current);
15191                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15192 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15193 +                                       continue;
15194                                 error = set_one_prio(p, niceval, error);
15195                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
15196                         break;
15197 @@ -267,6 +273,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
15198                         else
15199                                 pgrp = task_pgrp(current);
15200                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15201 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15202 +                                       continue;
15203                                 niceval = 20 - task_nice(p);
15204                                 if (niceval > retval)
15205                                         retval = niceval;
15206 @@ -417,6 +425,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
15207  
15208  static DEFINE_MUTEX(reboot_mutex);
15209  
15210 +long vs_reboot(unsigned int, void __user *);
15211 +
15212  /*
15213   * Reboot system call: for obvious reasons only root may call it,
15214   * and even root needs to set up some magic numbers in the registers
15215 @@ -449,6 +459,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
15216         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
15217                 cmd = LINUX_REBOOT_CMD_HALT;
15218  
15219 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15220 +               return vs_reboot(cmd, arg);
15221 +
15222         mutex_lock(&reboot_mutex);
15223         switch (cmd) {
15224         case LINUX_REBOOT_CMD_RESTART:
15225 @@ -1272,7 +1285,8 @@ SYSCALL_DEFINE2(sethostname, char __user
15226         int errno;
15227         char tmp[__NEW_UTS_LEN];
15228  
15229 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
15230 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
15231 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15232                 return -EPERM;
15233  
15234         if (len < 0 || len > __NEW_UTS_LEN)
15235 @@ -1322,7 +1336,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
15236         int errno;
15237         char tmp[__NEW_UTS_LEN];
15238  
15239 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
15240 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
15241 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15242                 return -EPERM;
15243         if (len < 0 || len > __NEW_UTS_LEN)
15244                 return -EINVAL;
15245 @@ -1440,7 +1455,7 @@ int do_prlimit(struct task_struct *tsk, 
15246                 /* Keep the capable check against init_user_ns until
15247                    cgroups can contain all limits */
15248                 if (new_rlim->rlim_max > rlim->rlim_max &&
15249 -                               !capable(CAP_SYS_RESOURCE))
15250 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15251                         retval = -EPERM;
15252                 if (!retval)
15253                         retval = security_task_setrlimit(tsk->group_leader,
15254 @@ -1494,7 +1509,8 @@ static int check_prlimit_permission(stru
15255              cred->gid == tcred->sgid &&
15256              cred->gid == tcred->gid))
15257                 return 0;
15258 -       if (ns_capable(tcred->user->user_ns, CAP_SYS_RESOURCE))
15259 +       if (vx_ns_capable(tcred->user->user_ns,
15260 +               CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15261                 return 0;
15262  
15263         return -EPERM;
15264 diff -NurpP --minimal linux-3.1.6/kernel/sysctl.c linux-3.1.6-vs2.3.2.5/kernel/sysctl.c
15265 --- linux-3.1.6/kernel/sysctl.c 2011-10-24 18:45:33.000000000 +0200
15266 +++ linux-3.1.6-vs2.3.2.5/kernel/sysctl.c       2011-10-24 18:53:33.000000000 +0200
15267 @@ -75,6 +75,7 @@
15268  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
15269  #include <linux/lockdep.h>
15270  #endif
15271 +extern char vshelper_path[];
15272  #ifdef CONFIG_CHR_DEV_SG
15273  #include <scsi/sg.h>
15274  #endif
15275 @@ -568,6 +569,13 @@ static struct ctl_table kern_table[] = {
15276                 .proc_handler   = proc_dostring,
15277         },
15278  #endif
15279 +       {
15280 +               .procname       = "vshelper",
15281 +               .data           = &vshelper_path,
15282 +               .maxlen         = 256,
15283 +               .mode           = 0644,
15284 +               .proc_handler   = &proc_dostring,
15285 +       },
15286  #ifdef CONFIG_CHR_DEV_SG
15287         {
15288                 .procname       = "sg-big-buff",
15289 diff -NurpP --minimal linux-3.1.6/kernel/sysctl_binary.c linux-3.1.6-vs2.3.2.5/kernel/sysctl_binary.c
15290 --- linux-3.1.6/kernel/sysctl_binary.c  2011-10-24 18:45:33.000000000 +0200
15291 +++ linux-3.1.6-vs2.3.2.5/kernel/sysctl_binary.c        2011-10-24 18:53:33.000000000 +0200
15292 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
15293  
15294         { CTL_INT,      KERN_PANIC,                     "panic" },
15295         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
15296 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
15297  
15298         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
15299         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
15300 diff -NurpP --minimal linux-3.1.6/kernel/time/timekeeping.c linux-3.1.6-vs2.3.2.5/kernel/time/timekeeping.c
15301 --- linux-3.1.6/kernel/time/timekeeping.c       2011-12-23 16:04:07.000000000 +0100
15302 +++ linux-3.1.6-vs2.3.2.5/kernel/time/timekeeping.c     2011-12-15 01:07:58.000000000 +0100
15303 @@ -233,6 +233,7 @@ void getnstimeofday(struct timespec *ts)
15304         } while (read_seqretry(&xtime_lock, seq));
15305  
15306         timespec_add_ns(ts, nsecs);
15307 +       vx_adjust_timespec(ts);
15308  }
15309  
15310  EXPORT_SYMBOL(getnstimeofday);
15311 diff -NurpP --minimal linux-3.1.6/kernel/time.c linux-3.1.6-vs2.3.2.5/kernel/time.c
15312 --- linux-3.1.6/kernel/time.c   2011-12-23 16:04:07.000000000 +0100
15313 +++ linux-3.1.6-vs2.3.2.5/kernel/time.c 2011-11-15 17:08:44.000000000 +0100
15314 @@ -92,7 +92,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
15315         if (err)
15316                 return err;
15317  
15318 -       do_settimeofday(&tv);
15319 +       vx_settimeofday(&tv);
15320         return 0;
15321  }
15322  
15323 @@ -177,7 +177,7 @@ int do_sys_settimeofday(const struct tim
15324                 /* SMP safe, again the code in arch/foo/time.c should
15325                  * globally block out interrupts when it runs.
15326                  */
15327 -               return do_settimeofday(tv);
15328 +               return vx_settimeofday(tv);
15329         }
15330         return 0;
15331  }
15332 diff -NurpP --minimal linux-3.1.6/kernel/timer.c linux-3.1.6-vs2.3.2.5/kernel/timer.c
15333 --- linux-3.1.6/kernel/timer.c  2011-07-22 11:18:12.000000000 +0200
15334 +++ linux-3.1.6-vs2.3.2.5/kernel/timer.c        2011-10-24 18:53:33.000000000 +0200
15335 @@ -40,6 +40,10 @@
15336  #include <linux/irq_work.h>
15337  #include <linux/sched.h>
15338  #include <linux/slab.h>
15339 +#include <linux/vs_base.h>
15340 +#include <linux/vs_cvirt.h>
15341 +#include <linux/vs_pid.h>
15342 +#include <linux/vserver/sched.h>
15343  
15344  #include <asm/uaccess.h>
15345  #include <asm/unistd.h>
15346 @@ -1336,12 +1340,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
15347  
15348  #endif
15349  
15350 -#ifndef __alpha__
15351 -
15352 -/*
15353 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
15354 - * should be moved into arch/i386 instead?
15355 - */
15356  
15357  /**
15358   * sys_getpid - return the thread group id of the current process
15359 @@ -1370,10 +1368,23 @@ SYSCALL_DEFINE0(getppid)
15360         rcu_read_lock();
15361         pid = task_tgid_vnr(current->real_parent);
15362         rcu_read_unlock();
15363 +       return vx_map_pid(pid);
15364 +}
15365  
15366 -       return pid;
15367 +#ifdef __alpha__
15368 +
15369 +/*
15370 + * The Alpha uses getxpid, getxuid, and getxgid instead.
15371 + */
15372 +
15373 +asmlinkage long do_getxpid(long *ppid)
15374 +{
15375 +       *ppid = sys_getppid();
15376 +       return sys_getpid();
15377  }
15378  
15379 +#else /* _alpha_ */
15380 +
15381  SYSCALL_DEFINE0(getuid)
15382  {
15383         /* Only we change this so SMP safe */
15384 diff -NurpP --minimal linux-3.1.6/kernel/user_namespace.c linux-3.1.6-vs2.3.2.5/kernel/user_namespace.c
15385 --- linux-3.1.6/kernel/user_namespace.c 2011-03-15 18:07:42.000000000 +0100
15386 +++ linux-3.1.6-vs2.3.2.5/kernel/user_namespace.c       2011-10-24 18:53:33.000000000 +0200
15387 @@ -11,6 +11,7 @@
15388  #include <linux/user_namespace.h>
15389  #include <linux/highuid.h>
15390  #include <linux/cred.h>
15391 +#include <linux/vserver/global.h>
15392  
15393  static struct kmem_cache *user_ns_cachep __read_mostly;
15394  
15395 @@ -33,6 +34,7 @@ int create_user_ns(struct cred *new)
15396                 return -ENOMEM;
15397  
15398         kref_init(&ns->kref);
15399 +       atomic_inc(&vs_global_user_ns);
15400  
15401         for (n = 0; n < UIDHASH_SZ; ++n)
15402                 INIT_HLIST_HEAD(ns->uidhash_table + n);
15403 @@ -81,6 +83,8 @@ void free_user_ns(struct kref *kref)
15404         struct user_namespace *ns =
15405                 container_of(kref, struct user_namespace, kref);
15406  
15407 +       /* FIXME: maybe move into destroyer? */
15408 +       atomic_dec(&vs_global_user_ns);
15409         INIT_WORK(&ns->destroyer, free_user_ns_work);
15410         schedule_work(&ns->destroyer);
15411  }
15412 diff -NurpP --minimal linux-3.1.6/kernel/utsname.c linux-3.1.6-vs2.3.2.5/kernel/utsname.c
15413 --- linux-3.1.6/kernel/utsname.c        2011-07-22 11:18:12.000000000 +0200
15414 +++ linux-3.1.6-vs2.3.2.5/kernel/utsname.c      2011-10-24 18:53:33.000000000 +0200
15415 @@ -16,14 +16,17 @@
15416  #include <linux/slab.h>
15417  #include <linux/user_namespace.h>
15418  #include <linux/proc_fs.h>
15419 +#include <linux/vserver/global.h>
15420  
15421  static struct uts_namespace *create_uts_ns(void)
15422  {
15423         struct uts_namespace *uts_ns;
15424  
15425         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
15426 -       if (uts_ns)
15427 +       if (uts_ns) {
15428                 kref_init(&uts_ns->kref);
15429 +               atomic_inc(&vs_global_uts_ns);
15430 +       }
15431         return uts_ns;
15432  }
15433  
15434 @@ -32,8 +35,8 @@ static struct uts_namespace *create_uts_
15435   * @old_ns: namespace to clone
15436   * Return NULL on error (failure to kmalloc), new ns otherwise
15437   */
15438 -static struct uts_namespace *clone_uts_ns(struct task_struct *tsk,
15439 -                                         struct uts_namespace *old_ns)
15440 +static struct uts_namespace *clone_uts_ns(struct uts_namespace *old_ns,
15441 +                                         struct user_namespace *old_user)
15442  {
15443         struct uts_namespace *ns;
15444  
15445 @@ -43,7 +46,7 @@ static struct uts_namespace *clone_uts_n
15446  
15447         down_read(&uts_sem);
15448         memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
15449 -       ns->user_ns = get_user_ns(task_cred_xxx(tsk, user)->user_ns);
15450 +       ns->user_ns = get_user_ns(old_user);
15451         up_read(&uts_sem);
15452         return ns;
15453  }
15454 @@ -55,9 +58,9 @@ static struct uts_namespace *clone_uts_n
15455   * versa.
15456   */
15457  struct uts_namespace *copy_utsname(unsigned long flags,
15458 -                                  struct task_struct *tsk)
15459 +                                  struct uts_namespace *old_ns,
15460 +                                  struct user_namespace *user_ns)
15461  {
15462 -       struct uts_namespace *old_ns = tsk->nsproxy->uts_ns;
15463         struct uts_namespace *new_ns;
15464  
15465         BUG_ON(!old_ns);
15466 @@ -66,7 +69,7 @@ struct uts_namespace *copy_utsname(unsig
15467         if (!(flags & CLONE_NEWUTS))
15468                 return old_ns;
15469  
15470 -       new_ns = clone_uts_ns(tsk, old_ns);
15471 +       new_ns = clone_uts_ns(old_ns, user_ns);
15472  
15473         put_uts_ns(old_ns);
15474         return new_ns;
15475 @@ -78,6 +81,7 @@ void free_uts_ns(struct kref *kref)
15476  
15477         ns = container_of(kref, struct uts_namespace, kref);
15478         put_user_ns(ns->user_ns);
15479 +       atomic_dec(&vs_global_uts_ns);
15480         kfree(ns);
15481  }
15482  
15483 diff -NurpP --minimal linux-3.1.6/kernel/vserver/Kconfig linux-3.1.6-vs2.3.2.5/kernel/vserver/Kconfig
15484 --- linux-3.1.6/kernel/vserver/Kconfig  1970-01-01 01:00:00.000000000 +0100
15485 +++ linux-3.1.6-vs2.3.2.5/kernel/vserver/Kconfig        2011-12-07 05:08:42.000000000 +0100
15486 @@ -0,0 +1,224 @@
15487 +#
15488 +# Linux VServer configuration
15489 +#
15490 +
15491 +menu "Linux VServer"
15492 +
15493 +config VSERVER_AUTO_LBACK
15494 +       bool    "Automatically Assign Loopback IP"
15495 +       default y
15496 +       help
15497 +         Automatically assign a guest specific loopback
15498 +         IP and add it to the kernel network stack on
15499 +         startup.
15500 +
15501 +config VSERVER_AUTO_SINGLE
15502 +       bool    "Automatic Single IP Special Casing"
15503 +       depends on EXPERIMENTAL
15504 +       default y
15505 +       help
15506 +         This allows network contexts with a single IP to
15507 +         automatically remap 0.0.0.0 bindings to that IP,
15508 +         avoiding further network checks and improving
15509 +         performance.
15510 +
15511 +         (note: such guests do not allow to change the ip
15512 +          on the fly and do not show loopback addresses)
15513 +
15514 +config VSERVER_COWBL
15515 +       bool    "Enable COW Immutable Link Breaking"
15516 +       default y
15517 +       help
15518 +         This enables the COW (Copy-On-Write) link break code.
15519 +         It allows you to treat unified files like normal files
15520 +         when writing to them (which will implicitely break the
15521 +         link and create a copy of the unified file)
15522 +
15523 +config VSERVER_VTIME
15524 +       bool    "Enable Virtualized Guest Time"
15525 +       depends on EXPERIMENTAL
15526 +       default n
15527 +       help
15528 +         This enables per guest time offsets to allow for
15529 +         adjusting the system clock individually per guest.
15530 +         this adds some overhead to the time functions and
15531 +         therefore should not be enabled without good reason.
15532 +
15533 +config VSERVER_DEVICE
15534 +       bool    "Enable Guest Device Mapping"
15535 +       depends on EXPERIMENTAL
15536 +       default n
15537 +       help
15538 +         This enables generic device remapping.
15539 +
15540 +config VSERVER_PROC_SECURE
15541 +       bool    "Enable Proc Security"
15542 +       depends on PROC_FS
15543 +       default y
15544 +       help
15545 +         This configures ProcFS security to initially hide
15546 +         non-process entries for all contexts except the main and
15547 +         spectator context (i.e. for all guests), which is a secure
15548 +         default.
15549 +
15550 +         (note: on 1.2x the entries were visible by default)
15551 +
15552 +choice
15553 +       prompt  "Persistent Inode Tagging"
15554 +       default TAGGING_ID24
15555 +       help
15556 +         This adds persistent context information to filesystems
15557 +         mounted with the tagxid option. Tagging is a requirement
15558 +         for per-context disk limits and per-context quota.
15559 +
15560 +
15561 +config TAGGING_NONE
15562 +       bool    "Disabled"
15563 +       help
15564 +         do not store per-context information in inodes.
15565 +
15566 +config TAGGING_UID16
15567 +       bool    "UID16/GID32"
15568 +       help
15569 +         reduces UID to 16 bit, but leaves GID at 32 bit.
15570 +
15571 +config TAGGING_GID16
15572 +       bool    "UID32/GID16"
15573 +       help
15574 +         reduces GID to 16 bit, but leaves UID at 32 bit.
15575 +
15576 +config TAGGING_ID24
15577 +       bool    "UID24/GID24"
15578 +       help
15579 +         uses the upper 8bit from UID and GID for XID tagging
15580 +         which leaves 24bit for UID/GID each, which should be
15581 +         more than sufficient for normal use.
15582 +
15583 +config TAGGING_INTERN
15584 +       bool    "UID32/GID32"
15585 +       help
15586 +         this uses otherwise reserved inode fields in the on
15587 +         disk representation, which limits the use to a few
15588 +         filesystems (currently ext2 and ext3)
15589 +
15590 +endchoice
15591 +
15592 +config TAG_NFSD
15593 +       bool    "Tag NFSD User Auth and Files"
15594 +       default n
15595 +       help
15596 +         Enable this if you do want the in-kernel NFS
15597 +         Server to use the tagging specified above.
15598 +         (will require patched clients too)
15599 +
15600 +config VSERVER_PRIVACY
15601 +       bool    "Honor Privacy Aspects of Guests"
15602 +       default n
15603 +       help
15604 +         When enabled, most context checks will disallow
15605 +         access to structures assigned to a specific context,
15606 +         like ptys or loop devices.
15607 +
15608 +config VSERVER_CONTEXTS
15609 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
15610 +       range 1 65533
15611 +       default "768"   if 64BIT
15612 +       default "256"
15613 +       help
15614 +         This setting will optimize certain data structures
15615 +         and memory allocations according to the expected
15616 +         maximum.
15617 +
15618 +         note: this is not a strict upper limit.
15619 +
15620 +config VSERVER_WARN
15621 +       bool    "VServer Warnings"
15622 +       default y
15623 +       help
15624 +         This enables various runtime warnings, which will
15625 +         notify about potential manipulation attempts or
15626 +         resource shortage. It is generally considered to
15627 +         be a good idea to have that enabled.
15628 +
15629 +config VSERVER_WARN_DEVPTS
15630 +       bool    "VServer DevPTS Warnings"
15631 +       depends on VSERVER_WARN
15632 +       default y
15633 +       help
15634 +         This enables DevPTS related warnings, issued when a
15635 +         process inside a context tries to lookup or access
15636 +         a dynamic pts from the host or a different context.
15637 +
15638 +config VSERVER_DEBUG
15639 +       bool    "VServer Debugging Code"
15640 +       default n
15641 +       help
15642 +         Set this to yes if you want to be able to activate
15643 +         debugging output at runtime. It adds a very small
15644 +         overhead to all vserver related functions and
15645 +         increases the kernel size by about 20k.
15646 +
15647 +config VSERVER_HISTORY
15648 +       bool    "VServer History Tracing"
15649 +       depends on VSERVER_DEBUG
15650 +       default n
15651 +       help
15652 +         Set this to yes if you want to record the history of
15653 +         linux-vserver activities, so they can be replayed in
15654 +         the event of a kernel panic or oops.
15655 +
15656 +config VSERVER_HISTORY_SIZE
15657 +       int     "Per-CPU History Size (32-65536)"
15658 +       depends on VSERVER_HISTORY
15659 +       range 32 65536
15660 +       default 64
15661 +       help
15662 +         This allows you to specify the number of entries in
15663 +         the per-CPU history buffer.
15664 +
15665 +choice
15666 +       prompt  "Quotes used in debug and warn messages"
15667 +       default QUOTES_ISO8859
15668 +
15669 +config QUOTES_ISO8859
15670 +       bool    "Extended ASCII (ISO 8859) angle quotes"
15671 +       help
15672 +         This uses the extended ASCII characters \xbb
15673 +         and \xab for quoting file and process names.
15674 +
15675 +config QUOTES_UTF8
15676 +       bool    "UTF-8 angle quotes"
15677 +       help
15678 +         This uses the the UTF-8 sequences for angle
15679 +         quotes to quote file and process names.
15680 +
15681 +config QUOTES_ASCII
15682 +       bool    "ASCII single quotes"
15683 +       help
15684 +         This uses the ASCII single quote character
15685 +         (\x27) to quote file and process names.
15686 +
15687 +endchoice
15688 +
15689 +endmenu
15690 +
15691 +
15692 +config VSERVER
15693 +       bool
15694 +       default y
15695 +       select NAMESPACES
15696 +       select UTS_NS
15697 +       select IPC_NS
15698 +#      select USER_NS
15699 +       select SYSVIPC
15700 +
15701 +config VSERVER_SECURITY
15702 +       bool
15703 +       depends on SECURITY
15704 +       default y
15705 +       select SECURITY_CAPABILITIES
15706 +
15707 +config VSERVER_DISABLED
15708 +       bool
15709 +       default n
15710 +
15711 diff -NurpP --minimal linux-3.1.6/kernel/vserver/Makefile linux-3.1.6-vs2.3.2.5/kernel/vserver/Makefile
15712 --- linux-3.1.6/kernel/vserver/Makefile 1970-01-01 01:00:00.000000000 +0100
15713 +++ linux-3.1.6-vs2.3.2.5/kernel/vserver/Makefile       2011-10-24 18:53:33.000000000 +0200
15714 @@ -0,0 +1,18 @@
15715 +#
15716 +# Makefile for the Linux vserver routines.
15717 +#
15718 +
15719 +
15720 +obj-y          += vserver.o
15721 +
15722 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
15723 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
15724 +                  dlimit.o tag.o
15725 +
15726 +vserver-$(CONFIG_INET) += inet.o
15727 +vserver-$(CONFIG_PROC_FS) += proc.o
15728 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
15729 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
15730 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
15731 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
15732 +
15733 diff -NurpP --minimal linux-3.1.6/kernel/vserver/cacct.c linux-3.1.6-vs2.3.2.5/kernel/vserver/cacct.c
15734 --- linux-3.1.6/kernel/vserver/cacct.c  1970-01-01 01:00:00.000000000 +0100
15735 +++ linux-3.1.6-vs2.3.2.5/kernel/vserver/cacct.c        2011-10-24 18:53:33.000000000 +0200
15736 @@ -0,0 +1,42 @@
15737 +/*
15738 + *  linux/kernel/vserver/cacct.c
15739 + *
15740 + *  Virtual Server: Context Accounting
15741 + *
15742 + *  Copyright (C) 2006-2007 Herbert Pötzl
15743 + *
15744 + *  V0.01  added accounting stats
15745 + *
15746 + */
15747 +
15748 +#include <linux/types.h>
15749 +#include <linux/vs_context.h>
15750 +#include <linux/vserver/cacct_cmd.h>
15751 +#include <linux/vserver/cacct_int.h>
15752 +
15753 +#include <asm/errno.h>
15754 +#include <asm/uaccess.h>
15755 +
15756 +
15757 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
15758 +{
15759 +       struct vcmd_sock_stat_v0 vc_data;
15760 +       int j, field;
15761 +
15762 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15763 +               return -EFAULT;
15764 +
15765 +       field = vc_data.field;
15766 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
15767 +               return -EINVAL;
15768 +
15769 +       for (j = 0; j < 3; j++) {
15770 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
15771 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
15772 +       }
15773 +
15774 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15775 +               return -EFAULT;
15776 +       return 0;
15777 +}
15778 +
15779 diff -NurpP --minimal linux-3.1.6/kernel/vserver/cacct_init.h linux-3.1.6-vs2.3.2.5/kernel/vserver/cacct_init.h
15780 --- linux-3.1.6/kernel/vserver/cacct_init.h     1970-01-01 01:00:00.000000000 +0100
15781 +++ linux-3.1.6-vs2.3.2.5/kernel/vserver/cacct_init.h   2011-10-24 18:53:33.000000000 +0200
15782 @@ -0,0 +1,25 @@
15783 +
15784 +
15785 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
15786 +{
15787 +       int i, j;
15788 +
15789 +
15790 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15791 +               for (j = 0; j < 3; j++) {
15792 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
15793 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
15794 +               }
15795 +       }
15796 +       for (i = 0; i < 8; i++)
15797 +               atomic_set(&cacct->slab[i], 0);
15798 +       for (i = 0; i < 5; i++)
15799 +               for (j = 0; j < 4; j++)
15800 +                       atomic_set(&cacct->page[i][j], 0);
15801 +}
15802 +
15803 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
15804 +{
15805 +       return;
15806 +}
15807 +
15808 diff -NurpP --minimal linux-3.1.6/kernel/vserver/cacct_proc.h linux-3.1.6-vs2.3.2.5/kernel/vserver/cacct_proc.h
15809 --- linux-3.1.6/kernel/vserver/cacct_proc.h     1970-01-01 01:00:00.000000000 +0100
15810 +++ linux-3.1.6-vs2.3.2.5/kernel/vserver/cacct_proc.h   2011-10-24 18:53:33.000000000 +0200
15811 @@ -0,0 +1,53 @@
15812 +#ifndef _VX_CACCT_PROC_H
15813 +#define _VX_CACCT_PROC_H
15814 +
15815 +#include <linux/vserver/cacct_int.h>
15816 +
15817 +
15818 +#define VX_SOCKA_TOP   \
15819 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
15820 +
15821 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
15822 +{
15823 +       int i, j, length = 0;
15824 +       static char *type[VXA_SOCK_SIZE] = {
15825 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
15826 +       };
15827 +
15828 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
15829 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15830 +               length += sprintf(buffer + length, "%s:", type[i]);
15831 +               for (j = 0; j < 3; j++) {
15832 +                       length += sprintf(buffer + length,
15833 +                               "\t%10lu/%-10lu",
15834 +                               vx_sock_count(cacct, i, j),
15835 +                               vx_sock_total(cacct, i, j));
15836 +               }
15837 +               buffer[length++] = '\n';
15838 +       }
15839 +
15840 +       length += sprintf(buffer + length, "\n");
15841 +       length += sprintf(buffer + length,
15842 +               "slab:\t %8u %8u %8u %8u\n",
15843 +               atomic_read(&cacct->slab[1]),
15844 +               atomic_read(&cacct->slab[4]),
15845 +               atomic_read(&cacct->slab[0]),
15846 +               atomic_read(&cacct->slab[2]));
15847 +
15848 +       length += sprintf(buffer + length, "\n");
15849 +       for (i = 0; i < 5; i++) {
15850 +               length += sprintf(buffer + length,
15851 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
15852 +                       atomic_read(&cacct->page[i][0]),
15853 +                       atomic_read(&cacct->page[i][1]),
15854 +                       atomic_read(&cacct->page[i][2]),
15855 +                       atomic_read(&cacct->page[i][3]),
15856 +                       atomic_read(&cacct->page[i][4]),
15857 +                       atomic_read(&cacct->page[i][5]),
15858 +                       atomic_read(&cacct->page[i][6]),
15859 +                       atomic_read(&cacct->page[i][7]));
15860 +       }
15861 +       return length;
15862 +}
15863 +
15864 +#endif /* _VX_CACCT_PROC_H */
15865 diff -NurpP --minimal linux-3.1.6/kernel/vserver/context.c linux-3.1.6-vs2.3.2.5/kernel/vserver/context.c
15866 --- linux-3.1.6/kernel/vserver/context.c        1970-01-01 01:00:00.000000000 +0100
15867 +++ linux-3.1.6-vs2.3.2.5/kernel/vserver/context.c      2011-10-24 18:53:33.000000000 +0200
15868 @@ -0,0 +1,1107 @@
15869 +/*
15870 + *  linux/kernel/vserver/context.c
15871 + *
15872 + *  Virtual Server: Context Support
15873 + *
15874 + *  Copyright (C) 2003-2011  Herbert Pötzl
15875 + *
15876 + *  V0.01  context helper
15877 + *  V0.02  vx_ctx_kill syscall command
15878 + *  V0.03  replaced context_info calls
15879 + *  V0.04  redesign of struct (de)alloc
15880 + *  V0.05  rlimit basic implementation
15881 + *  V0.06  task_xid and info commands
15882 + *  V0.07  context flags and caps
15883 + *  V0.08  switch to RCU based hash
15884 + *  V0.09  revert to non RCU for now
15885 + *  V0.10  and back to working RCU hash
15886 + *  V0.11  and back to locking again
15887 + *  V0.12  referenced context store
15888 + *  V0.13  separate per cpu data
15889 + *  V0.14  changed vcmds to vxi arg
15890 + *  V0.15  added context stat
15891 + *  V0.16  have __create claim() the vxi
15892 + *  V0.17  removed older and legacy stuff
15893 + *  V0.18  added user credentials
15894 + *  V0.19  added warn mask
15895 + *
15896 + */
15897 +
15898 +#include <linux/slab.h>
15899 +#include <linux/types.h>
15900 +#include <linux/security.h>
15901 +#include <linux/pid_namespace.h>
15902 +#include <linux/capability.h>
15903 +
15904 +#include <linux/vserver/context.h>
15905 +#include <linux/vserver/network.h>
15906 +#include <linux/vserver/debug.h>
15907 +#include <linux/vserver/limit.h>
15908 +#include <linux/vserver/limit_int.h>
15909 +#include <linux/vserver/space.h>
15910 +#include <linux/init_task.h>
15911 +#include <linux/fs_struct.h>
15912 +#include <linux/cred.h>
15913 +
15914 +#include <linux/vs_context.h>
15915 +#include <linux/vs_limit.h>
15916 +#include <linux/vs_pid.h>
15917 +#include <linux/vserver/context_cmd.h>
15918 +
15919 +#include "cvirt_init.h"
15920 +#include "cacct_init.h"
15921 +#include "limit_init.h"
15922 +#include "sched_init.h"
15923 +
15924 +
15925 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
15926 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
15927 +
15928 +
15929 +/*     now inactive context structures */
15930 +
15931 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
15932 +
15933 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
15934 +
15935 +
15936 +/*     __alloc_vx_info()
15937 +
15938 +       * allocate an initialized vx_info struct
15939 +       * doesn't make it visible (hash)                        */
15940 +
15941 +static struct vx_info *__alloc_vx_info(xid_t xid)
15942 +{
15943 +       struct vx_info *new = NULL;
15944 +       int cpu, index;
15945 +
15946 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
15947 +
15948 +       /* would this benefit from a slab cache? */
15949 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
15950 +       if (!new)
15951 +               return 0;
15952 +
15953 +       memset(new, 0, sizeof(struct vx_info));
15954 +#ifdef CONFIG_SMP
15955 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
15956 +       if (!new->ptr_pc)
15957 +               goto error;
15958 +#endif
15959 +       new->vx_id = xid;
15960 +       INIT_HLIST_NODE(&new->vx_hlist);
15961 +       atomic_set(&new->vx_usecnt, 0);
15962 +       atomic_set(&new->vx_tasks, 0);
15963 +       new->vx_parent = NULL;
15964 +       new->vx_state = 0;
15965 +       init_waitqueue_head(&new->vx_wait);
15966 +
15967 +       /* prepare reaper */
15968 +       get_task_struct(init_pid_ns.child_reaper);
15969 +       new->vx_reaper = init_pid_ns.child_reaper;
15970 +       new->vx_badness_bias = 0;
15971 +
15972 +       /* rest of init goes here */
15973 +       vx_info_init_limit(&new->limit);
15974 +       vx_info_init_sched(&new->sched);
15975 +       vx_info_init_cvirt(&new->cvirt);
15976 +       vx_info_init_cacct(&new->cacct);
15977 +
15978 +       /* per cpu data structures */
15979 +       for_each_possible_cpu(cpu) {
15980 +               vx_info_init_sched_pc(
15981 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
15982 +               vx_info_init_cvirt_pc(
15983 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
15984 +       }
15985 +
15986 +       new->vx_flags = VXF_INIT_SET;
15987 +       new->vx_bcaps = CAP_FULL_SET;   // maybe ~CAP_SETPCAP
15988 +       new->vx_ccaps = 0;
15989 +       new->vx_umask = 0;
15990 +       new->vx_wmask = 0;
15991 +
15992 +       new->reboot_cmd = 0;
15993 +       new->exit_code = 0;
15994 +
15995 +       // preconfig spaces
15996 +       for (index = 0; index < VX_SPACES; index++) {
15997 +               struct _vx_space *space = &new->space[index];
15998 +
15999 +               // filesystem
16000 +               spin_lock(&init_fs.lock);
16001 +               init_fs.users++;
16002 +               spin_unlock(&init_fs.lock);
16003 +               space->vx_fs = &init_fs;
16004 +
16005 +               /* FIXME: do we want defaults? */
16006 +               // space->vx_real_cred = 0;
16007 +               // space->vx_cred = 0;
16008 +       }
16009 +
16010 +
16011 +       vxdprintk(VXD_CBIT(xid, 0),
16012 +               "alloc_vx_info(%d) = %p", xid, new);
16013 +       vxh_alloc_vx_info(new);
16014 +       atomic_inc(&vx_global_ctotal);
16015 +       return new;
16016 +#ifdef CONFIG_SMP
16017 +error:
16018 +       kfree(new);
16019 +       return 0;
16020 +#endif
16021 +}
16022 +
16023 +/*     __dealloc_vx_info()
16024 +
16025 +       * final disposal of vx_info                             */
16026 +
16027 +static void __dealloc_vx_info(struct vx_info *vxi)
16028 +{
16029 +#ifdef CONFIG_VSERVER_WARN
16030 +       struct vx_info_save vxis;
16031 +       int cpu;
16032 +#endif
16033 +       vxdprintk(VXD_CBIT(xid, 0),
16034 +               "dealloc_vx_info(%p)", vxi);
16035 +       vxh_dealloc_vx_info(vxi);
16036 +
16037 +#ifdef CONFIG_VSERVER_WARN
16038 +       enter_vx_info(vxi, &vxis);
16039 +       vx_info_exit_limit(&vxi->limit);
16040 +       vx_info_exit_sched(&vxi->sched);
16041 +       vx_info_exit_cvirt(&vxi->cvirt);
16042 +       vx_info_exit_cacct(&vxi->cacct);
16043 +
16044 +       for_each_possible_cpu(cpu) {
16045 +               vx_info_exit_sched_pc(
16046 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
16047 +               vx_info_exit_cvirt_pc(
16048 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
16049 +       }
16050 +       leave_vx_info(&vxis);
16051 +#endif
16052 +
16053 +       vxi->vx_id = -1;
16054 +       vxi->vx_state |= VXS_RELEASED;
16055 +
16056 +#ifdef CONFIG_SMP
16057 +       free_percpu(vxi->ptr_pc);
16058 +#endif
16059 +       kfree(vxi);
16060 +       atomic_dec(&vx_global_ctotal);
16061 +}
16062 +
16063 +static void __shutdown_vx_info(struct vx_info *vxi)
16064 +{
16065 +       struct nsproxy *nsproxy;
16066 +       struct fs_struct *fs;
16067 +       struct cred *cred;
16068 +       int index, kill;
16069 +
16070 +       might_sleep();
16071 +
16072 +       vxi->vx_state |= VXS_SHUTDOWN;
16073 +       vs_state_change(vxi, VSC_SHUTDOWN);
16074 +
16075 +       for (index = 0; index < VX_SPACES; index++) {
16076 +               struct _vx_space *space = &vxi->space[index];
16077 +
16078 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
16079 +               if (nsproxy)
16080 +                       put_nsproxy(nsproxy);
16081 +
16082 +               fs = xchg(&space->vx_fs, NULL);
16083 +               spin_lock(&fs->lock);
16084 +               kill = !--fs->users;
16085 +               spin_unlock(&fs->lock);
16086 +               if (kill)
16087 +                       free_fs_struct(fs);
16088 +
16089 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
16090 +               if (cred)
16091 +                       abort_creds(cred);
16092 +       }
16093 +}
16094 +
16095 +/* exported stuff */
16096 +
16097 +void free_vx_info(struct vx_info *vxi)
16098 +{
16099 +       unsigned long flags;
16100 +       unsigned index;
16101 +
16102 +       /* check for reference counts first */
16103 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
16104 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16105 +
16106 +       /* context must not be hashed */
16107 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16108 +
16109 +       /* context shutdown is mandatory */
16110 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
16111 +
16112 +       /* spaces check */
16113 +       for (index = 0; index < VX_SPACES; index++) {
16114 +               struct _vx_space *space = &vxi->space[index];
16115 +
16116 +               BUG_ON(space->vx_nsproxy);
16117 +               BUG_ON(space->vx_fs);
16118 +               // BUG_ON(space->vx_real_cred);
16119 +               // BUG_ON(space->vx_cred);
16120 +       }
16121 +
16122 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16123 +       hlist_del(&vxi->vx_hlist);
16124 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16125 +
16126 +       __dealloc_vx_info(vxi);
16127 +}
16128 +
16129 +
16130 +/*     hash table for vx_info hash */
16131 +
16132 +#define VX_HASH_SIZE   13
16133 +
16134 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
16135 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
16136 +
16137 +static DEFINE_SPINLOCK(vx_info_hash_lock);
16138 +
16139 +
16140 +static inline unsigned int __hashval(xid_t xid)
16141 +{
16142 +       return (xid % VX_HASH_SIZE);
16143 +}
16144 +
16145 +
16146 +
16147 +/*     __hash_vx_info()
16148 +
16149 +       * add the vxi to the global hash table
16150 +       * requires the hash_lock to be held                     */
16151 +
16152 +static inline void __hash_vx_info(struct vx_info *vxi)
16153 +{
16154 +       struct hlist_head *head;
16155 +
16156 +       vxd_assert_lock(&vx_info_hash_lock);
16157 +       vxdprintk(VXD_CBIT(xid, 4),
16158 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
16159 +       vxh_hash_vx_info(vxi);
16160 +
16161 +       /* context must not be hashed */
16162 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16163 +
16164 +       vxi->vx_state |= VXS_HASHED;
16165 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
16166 +       hlist_add_head(&vxi->vx_hlist, head);
16167 +       atomic_inc(&vx_global_cactive);
16168 +}
16169 +
16170 +/*     __unhash_vx_info()
16171 +
16172 +       * remove the vxi from the global hash table
16173 +       * requires the hash_lock to be held                     */
16174 +
16175 +static inline void __unhash_vx_info(struct vx_info *vxi)
16176 +{
16177 +       unsigned long flags;
16178 +
16179 +       vxd_assert_lock(&vx_info_hash_lock);
16180 +       vxdprintk(VXD_CBIT(xid, 4),
16181 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
16182 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
16183 +       vxh_unhash_vx_info(vxi);
16184 +
16185 +       /* context must be hashed */
16186 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
16187 +       /* but without tasks */
16188 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16189 +
16190 +       vxi->vx_state &= ~VXS_HASHED;
16191 +       hlist_del_init(&vxi->vx_hlist);
16192 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16193 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
16194 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16195 +       atomic_dec(&vx_global_cactive);
16196 +}
16197 +
16198 +
16199 +/*     __lookup_vx_info()
16200 +
16201 +       * requires the hash_lock to be held
16202 +       * doesn't increment the vx_refcnt                       */
16203 +
16204 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
16205 +{
16206 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
16207 +       struct hlist_node *pos;
16208 +       struct vx_info *vxi;
16209 +
16210 +       vxd_assert_lock(&vx_info_hash_lock);
16211 +       hlist_for_each(pos, head) {
16212 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16213 +
16214 +               if (vxi->vx_id == xid)
16215 +                       goto found;
16216 +       }
16217 +       vxi = NULL;
16218 +found:
16219 +       vxdprintk(VXD_CBIT(xid, 0),
16220 +               "__lookup_vx_info(#%u): %p[#%u]",
16221 +               xid, vxi, vxi ? vxi->vx_id : 0);
16222 +       vxh_lookup_vx_info(vxi, xid);
16223 +       return vxi;
16224 +}
16225 +
16226 +
16227 +/*     __create_vx_info()
16228 +
16229 +       * create the requested context
16230 +       * get(), claim() and hash it                            */
16231 +
16232 +static struct vx_info *__create_vx_info(int id)
16233 +{
16234 +       struct vx_info *new, *vxi = NULL;
16235 +
16236 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
16237 +
16238 +       if (!(new = __alloc_vx_info(id)))
16239 +               return ERR_PTR(-ENOMEM);
16240 +
16241 +       /* required to make dynamic xids unique */
16242 +       spin_lock(&vx_info_hash_lock);
16243 +
16244 +       /* static context requested */
16245 +       if ((vxi = __lookup_vx_info(id))) {
16246 +               vxdprintk(VXD_CBIT(xid, 0),
16247 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
16248 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16249 +                       vxi = ERR_PTR(-EBUSY);
16250 +               else
16251 +                       vxi = ERR_PTR(-EEXIST);
16252 +               goto out_unlock;
16253 +       }
16254 +       /* new context */
16255 +       vxdprintk(VXD_CBIT(xid, 0),
16256 +               "create_vx_info(%d) = %p (new)", id, new);
16257 +       claim_vx_info(new, NULL);
16258 +       __hash_vx_info(get_vx_info(new));
16259 +       vxi = new, new = NULL;
16260 +
16261 +out_unlock:
16262 +       spin_unlock(&vx_info_hash_lock);
16263 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
16264 +       if (new)
16265 +               __dealloc_vx_info(new);
16266 +       return vxi;
16267 +}
16268 +
16269 +
16270 +/*     exported stuff                                          */
16271 +
16272 +
16273 +void unhash_vx_info(struct vx_info *vxi)
16274 +{
16275 +       spin_lock(&vx_info_hash_lock);
16276 +       __unhash_vx_info(vxi);
16277 +       spin_unlock(&vx_info_hash_lock);
16278 +       __shutdown_vx_info(vxi);
16279 +       __wakeup_vx_info(vxi);
16280 +}
16281 +
16282 +
16283 +/*     lookup_vx_info()
16284 +
16285 +       * search for a vx_info and get() it
16286 +       * negative id means current                             */
16287 +
16288 +struct vx_info *lookup_vx_info(int id)
16289 +{
16290 +       struct vx_info *vxi = NULL;
16291 +
16292 +       if (id < 0) {
16293 +               vxi = get_vx_info(current_vx_info());
16294 +       } else if (id > 1) {
16295 +               spin_lock(&vx_info_hash_lock);
16296 +               vxi = get_vx_info(__lookup_vx_info(id));
16297 +               spin_unlock(&vx_info_hash_lock);
16298 +       }
16299 +       return vxi;
16300 +}
16301 +
16302 +/*     xid_is_hashed()
16303 +
16304 +       * verify that xid is still hashed                       */
16305 +
16306 +int xid_is_hashed(xid_t xid)
16307 +{
16308 +       int hashed;
16309 +
16310 +       spin_lock(&vx_info_hash_lock);
16311 +       hashed = (__lookup_vx_info(xid) != NULL);
16312 +       spin_unlock(&vx_info_hash_lock);
16313 +       return hashed;
16314 +}
16315 +
16316 +#ifdef CONFIG_PROC_FS
16317 +
16318 +/*     get_xid_list()
16319 +
16320 +       * get a subset of hashed xids for proc
16321 +       * assumes size is at least one                          */
16322 +
16323 +int get_xid_list(int index, unsigned int *xids, int size)
16324 +{
16325 +       int hindex, nr_xids = 0;
16326 +
16327 +       /* only show current and children */
16328 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
16329 +               if (index > 0)
16330 +                       return 0;
16331 +               xids[nr_xids] = vx_current_xid();
16332 +               return 1;
16333 +       }
16334 +
16335 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
16336 +               struct hlist_head *head = &vx_info_hash[hindex];
16337 +               struct hlist_node *pos;
16338 +
16339 +               spin_lock(&vx_info_hash_lock);
16340 +               hlist_for_each(pos, head) {
16341 +                       struct vx_info *vxi;
16342 +
16343 +                       if (--index > 0)
16344 +                               continue;
16345 +
16346 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16347 +                       xids[nr_xids] = vxi->vx_id;
16348 +                       if (++nr_xids >= size) {
16349 +                               spin_unlock(&vx_info_hash_lock);
16350 +                               goto out;
16351 +                       }
16352 +               }
16353 +               /* keep the lock time short */
16354 +               spin_unlock(&vx_info_hash_lock);
16355 +       }
16356 +out:
16357 +       return nr_xids;
16358 +}
16359 +#endif
16360 +
16361 +#ifdef CONFIG_VSERVER_DEBUG
16362 +
16363 +void   dump_vx_info_inactive(int level)
16364 +{
16365 +       struct hlist_node *entry, *next;
16366 +
16367 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
16368 +               struct vx_info *vxi =
16369 +                       list_entry(entry, struct vx_info, vx_hlist);
16370 +
16371 +               dump_vx_info(vxi, level);
16372 +       }
16373 +}
16374 +
16375 +#endif
16376 +
16377 +#if 0
16378 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16379 +{
16380 +       struct user_struct *new_user, *old_user;
16381 +
16382 +       if (!p || !vxi)
16383 +               BUG();
16384 +
16385 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16386 +               return -EACCES;
16387 +
16388 +       new_user = alloc_uid(vxi->vx_id, p->uid);
16389 +       if (!new_user)
16390 +               return -ENOMEM;
16391 +
16392 +       old_user = p->user;
16393 +       if (new_user != old_user) {
16394 +               atomic_inc(&new_user->processes);
16395 +               atomic_dec(&old_user->processes);
16396 +               p->user = new_user;
16397 +       }
16398 +       free_uid(old_user);
16399 +       return 0;
16400 +}
16401 +#endif
16402 +
16403 +#if 0
16404 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16405 +{
16406 +       // p->cap_effective &= vxi->vx_cap_bset;
16407 +       p->cap_effective =
16408 +               cap_intersect(p->cap_effective, vxi->cap_bset);
16409 +       // p->cap_inheritable &= vxi->vx_cap_bset;
16410 +       p->cap_inheritable =
16411 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
16412 +       // p->cap_permitted &= vxi->vx_cap_bset;
16413 +       p->cap_permitted =
16414 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
16415 +}
16416 +#endif
16417 +
16418 +
16419 +#include <linux/file.h>
16420 +#include <linux/fdtable.h>
16421 +
16422 +static int vx_openfd_task(struct task_struct *tsk)
16423 +{
16424 +       struct files_struct *files = tsk->files;
16425 +       struct fdtable *fdt;
16426 +       const unsigned long *bptr;
16427 +       int count, total;
16428 +
16429 +       /* no rcu_read_lock() because of spin_lock() */
16430 +       spin_lock(&files->file_lock);
16431 +       fdt = files_fdtable(files);
16432 +       bptr = fdt->open_fds->fds_bits;
16433 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
16434 +       for (total = 0; count > 0; count--) {
16435 +               if (*bptr)
16436 +                       total += hweight_long(*bptr);
16437 +               bptr++;
16438 +       }
16439 +       spin_unlock(&files->file_lock);
16440 +       return total;
16441 +}
16442 +
16443 +
16444 +/*     for *space compatibility */
16445 +
16446 +asmlinkage long sys_unshare(unsigned long);
16447 +
16448 +/*
16449 + *     migrate task to new context
16450 + *     gets vxi, puts old_vxi on change
16451 + *     optionally unshares namespaces (hack)
16452 + */
16453 +
16454 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
16455 +{
16456 +       struct vx_info *old_vxi;
16457 +       int ret = 0;
16458 +
16459 +       if (!p || !vxi)
16460 +               BUG();
16461 +
16462 +       vxdprintk(VXD_CBIT(xid, 5),
16463 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
16464 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
16465 +
16466 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
16467 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16468 +               return -EACCES;
16469 +
16470 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
16471 +               return -EFAULT;
16472 +
16473 +       old_vxi = task_get_vx_info(p);
16474 +       if (old_vxi == vxi)
16475 +               goto out;
16476 +
16477 +//     if (!(ret = vx_migrate_user(p, vxi))) {
16478 +       {
16479 +               int openfd;
16480 +
16481 +               task_lock(p);
16482 +               openfd = vx_openfd_task(p);
16483 +
16484 +               if (old_vxi) {
16485 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
16486 +                       atomic_dec(&old_vxi->cvirt.nr_running);
16487 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
16488 +                       /* FIXME: what about the struct files here? */
16489 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
16490 +                       /* account for the executable */
16491 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
16492 +               }
16493 +               atomic_inc(&vxi->cvirt.nr_threads);
16494 +               atomic_inc(&vxi->cvirt.nr_running);
16495 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
16496 +               /* FIXME: what about the struct files here? */
16497 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
16498 +               /* account for the executable */
16499 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
16500 +
16501 +               if (old_vxi) {
16502 +                       release_vx_info(old_vxi, p);
16503 +                       clr_vx_info(&p->vx_info);
16504 +               }
16505 +               claim_vx_info(vxi, p);
16506 +               set_vx_info(&p->vx_info, vxi);
16507 +               p->xid = vxi->vx_id;
16508 +
16509 +               vxdprintk(VXD_CBIT(xid, 5),
16510 +                       "moved task %p into vxi:%p[#%d]",
16511 +                       p, vxi, vxi->vx_id);
16512 +
16513 +               // vx_mask_cap_bset(vxi, p);
16514 +               task_unlock(p);
16515 +
16516 +               /* hack for *spaces to provide compatibility */
16517 +               if (unshare) {
16518 +                       struct nsproxy *old_nsp, *new_nsp;
16519 +
16520 +                       ret = unshare_nsproxy_namespaces(
16521 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
16522 +                               &new_nsp, NULL);
16523 +                       if (ret)
16524 +                               goto out;
16525 +
16526 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
16527 +                       vx_set_space(vxi,
16528 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
16529 +                       put_nsproxy(old_nsp);
16530 +               }
16531 +       }
16532 +out:
16533 +       put_vx_info(old_vxi);
16534 +       return ret;
16535 +}
16536 +
16537 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
16538 +{
16539 +       struct task_struct *old_reaper;
16540 +
16541 +       if (!vxi)
16542 +               return -EINVAL;
16543 +
16544 +       vxdprintk(VXD_CBIT(xid, 6),
16545 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
16546 +               vxi, vxi->vx_id, p, p->xid, p->pid);
16547 +
16548 +       old_reaper = vxi->vx_reaper;
16549 +       if (old_reaper == p)
16550 +               return 0;
16551 +
16552 +       /* set new child reaper */
16553 +       get_task_struct(p);
16554 +       vxi->vx_reaper = p;
16555 +       put_task_struct(old_reaper);
16556 +       return 0;
16557 +}
16558 +
16559 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
16560 +{
16561 +       if (!vxi)
16562 +               return -EINVAL;
16563 +
16564 +       vxdprintk(VXD_CBIT(xid, 6),
16565 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
16566 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16567 +
16568 +       vxi->vx_flags &= ~VXF_STATE_INIT;
16569 +       // vxi->vx_initpid = p->tgid;
16570 +       vxi->vx_initpid = p->pid;
16571 +       return 0;
16572 +}
16573 +
16574 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
16575 +{
16576 +       vxdprintk(VXD_CBIT(xid, 6),
16577 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
16578 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16579 +
16580 +       vxi->exit_code = code;
16581 +       vxi->vx_initpid = 0;
16582 +}
16583 +
16584 +
16585 +void vx_set_persistent(struct vx_info *vxi)
16586 +{
16587 +       vxdprintk(VXD_CBIT(xid, 6),
16588 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
16589 +
16590 +       get_vx_info(vxi);
16591 +       claim_vx_info(vxi, NULL);
16592 +}
16593 +
16594 +void vx_clear_persistent(struct vx_info *vxi)
16595 +{
16596 +       vxdprintk(VXD_CBIT(xid, 6),
16597 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
16598 +
16599 +       release_vx_info(vxi, NULL);
16600 +       put_vx_info(vxi);
16601 +}
16602 +
16603 +void vx_update_persistent(struct vx_info *vxi)
16604 +{
16605 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
16606 +               vx_set_persistent(vxi);
16607 +       else
16608 +               vx_clear_persistent(vxi);
16609 +}
16610 +
16611 +
16612 +/*     task must be current or locked          */
16613 +
16614 +void   exit_vx_info(struct task_struct *p, int code)
16615 +{
16616 +       struct vx_info *vxi = p->vx_info;
16617 +
16618 +       if (vxi) {
16619 +               atomic_dec(&vxi->cvirt.nr_threads);
16620 +               vx_nproc_dec(p);
16621 +
16622 +               vxi->exit_code = code;
16623 +               release_vx_info(vxi, p);
16624 +       }
16625 +}
16626 +
16627 +void   exit_vx_info_early(struct task_struct *p, int code)
16628 +{
16629 +       struct vx_info *vxi = p->vx_info;
16630 +
16631 +       if (vxi) {
16632 +               if (vxi->vx_initpid == p->pid)
16633 +                       vx_exit_init(vxi, p, code);
16634 +               if (vxi->vx_reaper == p)
16635 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
16636 +       }
16637 +}
16638 +
16639 +
16640 +/* vserver syscall commands below here */
16641 +
16642 +/* taks xid and vx_info functions */
16643 +
16644 +#include <asm/uaccess.h>
16645 +
16646 +
16647 +int vc_task_xid(uint32_t id)
16648 +{
16649 +       xid_t xid;
16650 +
16651 +       if (id) {
16652 +               struct task_struct *tsk;
16653 +
16654 +               rcu_read_lock();
16655 +               tsk = find_task_by_real_pid(id);
16656 +               xid = (tsk) ? tsk->xid : -ESRCH;
16657 +               rcu_read_unlock();
16658 +       } else
16659 +               xid = vx_current_xid();
16660 +       return xid;
16661 +}
16662 +
16663 +
16664 +int vc_vx_info(struct vx_info *vxi, void __user *data)
16665 +{
16666 +       struct vcmd_vx_info_v0 vc_data;
16667 +
16668 +       vc_data.xid = vxi->vx_id;
16669 +       vc_data.initpid = vxi->vx_initpid;
16670 +
16671 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16672 +               return -EFAULT;
16673 +       return 0;
16674 +}
16675 +
16676 +
16677 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
16678 +{
16679 +       struct vcmd_ctx_stat_v0 vc_data;
16680 +
16681 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
16682 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
16683 +
16684 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16685 +               return -EFAULT;
16686 +       return 0;
16687 +}
16688 +
16689 +
16690 +/* context functions */
16691 +
16692 +int vc_ctx_create(uint32_t xid, void __user *data)
16693 +{
16694 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
16695 +       struct vx_info *new_vxi;
16696 +       int ret;
16697 +
16698 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16699 +               return -EFAULT;
16700 +
16701 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
16702 +               return -EINVAL;
16703 +
16704 +       new_vxi = __create_vx_info(xid);
16705 +       if (IS_ERR(new_vxi))
16706 +               return PTR_ERR(new_vxi);
16707 +
16708 +       /* initial flags */
16709 +       new_vxi->vx_flags = vc_data.flagword;
16710 +
16711 +       ret = -ENOEXEC;
16712 +       if (vs_state_change(new_vxi, VSC_STARTUP))
16713 +               goto out;
16714 +
16715 +       ret = vx_migrate_task(current, new_vxi, (!data));
16716 +       if (ret)
16717 +               goto out;
16718 +
16719 +       /* return context id on success */
16720 +       ret = new_vxi->vx_id;
16721 +
16722 +       /* get a reference for persistent contexts */
16723 +       if ((vc_data.flagword & VXF_PERSISTENT))
16724 +               vx_set_persistent(new_vxi);
16725 +out:
16726 +       release_vx_info(new_vxi, NULL);
16727 +       put_vx_info(new_vxi);
16728 +       return ret;
16729 +}
16730 +
16731 +
16732 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
16733 +{
16734 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
16735 +       int ret;
16736 +
16737 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16738 +               return -EFAULT;
16739 +
16740 +       ret = vx_migrate_task(current, vxi, 0);
16741 +       if (ret)
16742 +               return ret;
16743 +       if (vc_data.flagword & VXM_SET_INIT)
16744 +               ret = vx_set_init(vxi, current);
16745 +       if (ret)
16746 +               return ret;
16747 +       if (vc_data.flagword & VXM_SET_REAPER)
16748 +               ret = vx_set_reaper(vxi, current);
16749 +       return ret;
16750 +}
16751 +
16752 +
16753 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
16754 +{
16755 +       struct vcmd_ctx_flags_v0 vc_data;
16756 +
16757 +       vc_data.flagword = vxi->vx_flags;
16758 +
16759 +       /* special STATE flag handling */
16760 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
16761 +
16762 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16763 +               return -EFAULT;
16764 +       return 0;
16765 +}
16766 +
16767 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
16768 +{
16769 +       struct vcmd_ctx_flags_v0 vc_data;
16770 +       uint64_t mask, trigger;
16771 +
16772 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16773 +               return -EFAULT;
16774 +
16775 +       /* special STATE flag handling */
16776 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
16777 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
16778 +
16779 +       if (vxi == current_vx_info()) {
16780 +               /* if (trigger & VXF_STATE_SETUP)
16781 +                       vx_mask_cap_bset(vxi, current); */
16782 +               if (trigger & VXF_STATE_INIT) {
16783 +                       int ret;
16784 +
16785 +                       ret = vx_set_init(vxi, current);
16786 +                       if (ret)
16787 +                               return ret;
16788 +                       ret = vx_set_reaper(vxi, current);
16789 +                       if (ret)
16790 +                               return ret;
16791 +               }
16792 +       }
16793 +
16794 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
16795 +               vc_data.flagword, mask);
16796 +       if (trigger & VXF_PERSISTENT)
16797 +               vx_update_persistent(vxi);
16798 +
16799 +       return 0;
16800 +}
16801 +
16802 +
16803 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
16804 +{
16805 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
16806 +
16807 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
16808 +       return v;
16809 +}
16810 +
16811 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
16812 +{
16813 +       kernel_cap_t c = __cap_empty_set;
16814 +
16815 +       c.cap[0] = v & 0xFFFFFFFF;
16816 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
16817 +
16818 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
16819 +       return c;
16820 +}
16821 +
16822 +
16823 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
16824 +{
16825 +       if (bcaps)
16826 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
16827 +       if (ccaps)
16828 +               *ccaps = vxi->vx_ccaps;
16829 +
16830 +       return 0;
16831 +}
16832 +
16833 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
16834 +{
16835 +       struct vcmd_ctx_caps_v1 vc_data;
16836 +       int ret;
16837 +
16838 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
16839 +       if (ret)
16840 +               return ret;
16841 +       vc_data.cmask = ~0ULL;
16842 +
16843 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16844 +               return -EFAULT;
16845 +       return 0;
16846 +}
16847 +
16848 +static int do_set_caps(struct vx_info *vxi,
16849 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
16850 +{
16851 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
16852 +
16853 +#if 0
16854 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
16855 +               bcaps, bmask, ccaps, cmask);
16856 +#endif
16857 +       vxi->vx_bcaps = cap_t_from_caps(
16858 +               vs_mask_flags(bcold, bcaps, bmask));
16859 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
16860 +
16861 +       return 0;
16862 +}
16863 +
16864 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
16865 +{
16866 +       struct vcmd_ctx_caps_v1 vc_data;
16867 +
16868 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16869 +               return -EFAULT;
16870 +
16871 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
16872 +}
16873 +
16874 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
16875 +{
16876 +       struct vcmd_bcaps vc_data;
16877 +       int ret;
16878 +
16879 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
16880 +       if (ret)
16881 +               return ret;
16882 +       vc_data.bmask = ~0ULL;
16883 +
16884 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16885 +               return -EFAULT;
16886 +       return 0;
16887 +}
16888 +
16889 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
16890 +{
16891 +       struct vcmd_bcaps vc_data;
16892 +
16893 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16894 +               return -EFAULT;
16895 +
16896 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
16897 +}
16898 +
16899 +
16900 +int vc_get_umask(struct vx_info *vxi, void __user *data)
16901 +{
16902 +       struct vcmd_umask vc_data;
16903 +
16904 +       vc_data.umask = vxi->vx_umask;
16905 +       vc_data.mask = ~0ULL;
16906 +
16907 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16908 +               return -EFAULT;
16909 +       return 0;
16910 +}
16911 +
16912 +int vc_set_umask(struct vx_info *vxi, void __user *data)
16913 +{
16914 +       struct vcmd_umask vc_data;
16915 +
16916 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16917 +               return -EFAULT;
16918 +
16919 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
16920 +               vc_data.umask, vc_data.mask);
16921 +       return 0;
16922 +}
16923 +
16924 +
16925 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
16926 +{
16927 +       struct vcmd_wmask vc_data;
16928 +
16929 +       vc_data.wmask = vxi->vx_wmask;
16930 +       vc_data.mask = ~0ULL;
16931 +
16932 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16933 +               return -EFAULT;
16934 +       return 0;
16935 +}
16936 +
16937 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
16938 +{
16939 +       struct vcmd_wmask vc_data;
16940 +
16941 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16942 +               return -EFAULT;
16943 +
16944 +       vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
16945 +               vc_data.wmask, vc_data.mask);
16946 +       return 0;
16947 +}
16948 +
16949 +
16950 +int vc_get_badness(struct vx_info *vxi, void __user *data)
16951 +{
16952 +       struct vcmd_badness_v0 vc_data;
16953 +
16954 +       vc_data.bias = vxi->vx_badness_bias;
16955 +
16956 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16957 +               return -EFAULT;
16958 +       return 0;
16959 +}
16960 +
16961 +int vc_set_badness(struct vx_info *vxi, void __user *data)
16962 +{
16963 +       struct vcmd_badness_v0 vc_data;
16964 +
16965 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16966 +               return -EFAULT;
16967 +
16968 +       vxi->vx_badness_bias = vc_data.bias;
16969 +       return 0;
16970 +}
16971 +
16972 +#include <linux/module.h>
16973 +
16974 +EXPORT_SYMBOL_GPL(free_vx_info);
16975 +
16976 diff -NurpP --minimal linux-3.1.6/kernel/vserver/cvirt.c linux-3.1.6-vs2.3.2.5/kernel/vserver/cvirt.c
16977 --- linux-3.1.6/kernel/vserver/cvirt.c  1970-01-01 01:00:00.000000000 +0100
16978 +++ linux-3.1.6-vs2.3.2.5/kernel/vserver/cvirt.c        2011-10-24 18:53:33.000000000 +0200
16979 @@ -0,0 +1,303 @@
16980 +/*
16981 + *  linux/kernel/vserver/cvirt.c
16982 + *
16983 + *  Virtual Server: Context Virtualization
16984 + *
16985 + *  Copyright (C) 2004-2007  Herbert Pötzl
16986 + *
16987 + *  V0.01  broken out from limit.c
16988 + *  V0.02  added utsname stuff
16989 + *  V0.03  changed vcmds to vxi arg
16990 + *
16991 + */
16992 +
16993 +#include <linux/types.h>
16994 +#include <linux/utsname.h>
16995 +#include <linux/vs_cvirt.h>
16996 +#include <linux/vserver/switch.h>
16997 +#include <linux/vserver/cvirt_cmd.h>
16998 +
16999 +#include <asm/uaccess.h>
17000 +
17001 +
17002 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
17003 +{
17004 +       struct vx_info *vxi = current_vx_info();
17005 +
17006 +       set_normalized_timespec(uptime,
17007 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
17008 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
17009 +       if (!idle)
17010 +               return;
17011 +       set_normalized_timespec(idle,
17012 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
17013 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
17014 +       return;
17015 +}
17016 +
17017 +uint64_t vx_idle_jiffies(void)
17018 +{
17019 +       return init_task.utime + init_task.stime;
17020 +}
17021 +
17022 +
17023 +
17024 +static inline uint32_t __update_loadavg(uint32_t load,
17025 +       int wsize, int delta, int n)
17026 +{
17027 +       unsigned long long calc, prev;
17028 +
17029 +       /* just set it to n */
17030 +       if (unlikely(delta >= wsize))
17031 +               return (n << FSHIFT);
17032 +
17033 +       calc = delta * n;
17034 +       calc <<= FSHIFT;
17035 +       prev = (wsize - delta);
17036 +       prev *= load;
17037 +       calc += prev;
17038 +       do_div(calc, wsize);
17039 +       return calc;
17040 +}
17041 +
17042 +
17043 +void vx_update_load(struct vx_info *vxi)
17044 +{
17045 +       uint32_t now, last, delta;
17046 +       unsigned int nr_running, nr_uninterruptible;
17047 +       unsigned int total;
17048 +       unsigned long flags;
17049 +
17050 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
17051 +
17052 +       now = jiffies;
17053 +       last = vxi->cvirt.load_last;
17054 +       delta = now - last;
17055 +
17056 +       if (delta < 5*HZ)
17057 +               goto out;
17058 +
17059 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
17060 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
17061 +       total = nr_running + nr_uninterruptible;
17062 +
17063 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
17064 +               60*HZ, delta, total);
17065 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
17066 +               5*60*HZ, delta, total);
17067 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
17068 +               15*60*HZ, delta, total);
17069 +
17070 +       vxi->cvirt.load_last = now;
17071 +out:
17072 +       atomic_inc(&vxi->cvirt.load_updates);
17073 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
17074 +}
17075 +
17076 +
17077 +/*
17078 + * Commands to do_syslog:
17079 + *
17080 + *      0 -- Close the log.  Currently a NOP.
17081 + *      1 -- Open the log. Currently a NOP.
17082 + *      2 -- Read from the log.
17083 + *      3 -- Read all messages remaining in the ring buffer.
17084 + *      4 -- Read and clear all messages remaining in the ring buffer
17085 + *      5 -- Clear ring buffer.
17086 + *      6 -- Disable printk's to console
17087 + *      7 -- Enable printk's to console
17088 + *      8 -- Set level of messages printed to console
17089 + *      9 -- Return number of unread characters in the log buffer
17090 + *     10 -- Return size of the log buffer
17091 + */
17092 +int vx_do_syslog(int type, char __user *buf, int len)
17093 +{
17094 +       int error = 0;
17095 +       int do_clear = 0;
17096 +       struct vx_info *vxi = current_vx_info();
17097 +       struct _vx_syslog *log;
17098 +
17099 +       if (!vxi)
17100 +               return -EINVAL;
17101 +       log = &vxi->cvirt.syslog;
17102 +
17103 +       switch (type) {
17104 +       case 0:         /* Close log */
17105 +       case 1:         /* Open log */
17106 +               break;
17107 +       case 2:         /* Read from log */
17108 +               error = wait_event_interruptible(log->log_wait,
17109 +                       (log->log_start - log->log_end));
17110 +               if (error)
17111 +                       break;
17112 +               spin_lock_irq(&log->logbuf_lock);
17113 +               spin_unlock_irq(&log->logbuf_lock);
17114 +               break;
17115 +       case 4:         /* Read/clear last kernel messages */
17116 +               do_clear = 1;
17117 +               /* fall through */
17118 +       case 3:         /* Read last kernel messages */
17119 +               return 0;
17120 +
17121 +       case 5:         /* Clear ring buffer */
17122 +               return 0;
17123 +
17124 +       case 6:         /* Disable logging to console */
17125 +       case 7:         /* Enable logging to console */
17126 +       case 8:         /* Set level of messages printed to console */
17127 +               break;
17128 +
17129 +       case 9:         /* Number of chars in the log buffer */
17130 +               return 0;
17131 +       case 10:        /* Size of the log buffer */
17132 +               return 0;
17133 +       default:
17134 +               error = -EINVAL;
17135 +               break;
17136 +       }
17137 +       return error;
17138 +}
17139 +
17140 +
17141 +/* virtual host info names */
17142 +
17143 +static char *vx_vhi_name(struct vx_info *vxi, int id)
17144 +{
17145 +       struct nsproxy *nsproxy;
17146 +       struct uts_namespace *uts;
17147 +
17148 +       if (id == VHIN_CONTEXT)
17149 +               return vxi->vx_name;
17150 +
17151 +       nsproxy = vxi->space[0].vx_nsproxy;
17152 +       if (!nsproxy)
17153 +               return NULL;
17154 +
17155 +       uts = nsproxy->uts_ns;
17156 +       if (!uts)
17157 +               return NULL;
17158 +
17159 +       switch (id) {
17160 +       case VHIN_SYSNAME:
17161 +               return uts->name.sysname;
17162 +       case VHIN_NODENAME:
17163 +               return uts->name.nodename;
17164 +       case VHIN_RELEASE:
17165 +               return uts->name.release;
17166 +       case VHIN_VERSION:
17167 +               return uts->name.version;
17168 +       case VHIN_MACHINE:
17169 +               return uts->name.machine;
17170 +       case VHIN_DOMAINNAME:
17171 +               return uts->name.domainname;
17172 +       default:
17173 +               return NULL;
17174 +       }
17175 +       return NULL;
17176 +}
17177 +
17178 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
17179 +{
17180 +       struct vcmd_vhi_name_v0 vc_data;
17181 +       char *name;
17182 +
17183 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17184 +               return -EFAULT;
17185 +
17186 +       name = vx_vhi_name(vxi, vc_data.field);
17187 +       if (!name)
17188 +               return -EINVAL;
17189 +
17190 +       memcpy(name, vc_data.name, 65);
17191 +       return 0;
17192 +}
17193 +
17194 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
17195 +{
17196 +       struct vcmd_vhi_name_v0 vc_data;
17197 +       char *name;
17198 +
17199 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17200 +               return -EFAULT;
17201 +
17202 +       name = vx_vhi_name(vxi, vc_data.field);
17203 +       if (!name)
17204 +               return -EINVAL;
17205 +
17206 +       memcpy(vc_data.name, name, 65);
17207 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17208 +               return -EFAULT;
17209 +       return 0;
17210 +}
17211 +
17212 +
17213 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
17214 +{
17215 +       struct vcmd_virt_stat_v0 vc_data;
17216 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
17217 +       struct timespec uptime;
17218 +
17219 +       do_posix_clock_monotonic_gettime(&uptime);
17220 +       set_normalized_timespec(&uptime,
17221 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
17222 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
17223 +
17224 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
17225 +       vc_data.uptime = timespec_to_ns(&uptime);
17226 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
17227 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
17228 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
17229 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
17230 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
17231 +       vc_data.load[0] = cvirt->load[0];
17232 +       vc_data.load[1] = cvirt->load[1];
17233 +       vc_data.load[2] = cvirt->load[2];
17234 +
17235 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17236 +               return -EFAULT;
17237 +       return 0;
17238 +}
17239 +
17240 +
17241 +#ifdef CONFIG_VSERVER_VTIME
17242 +
17243 +/* virtualized time base */
17244 +
17245 +void vx_adjust_timespec(struct timespec *ts)
17246 +{
17247 +       struct vx_info *vxi;
17248 +
17249 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17250 +               return;
17251 +
17252 +       vxi = current_vx_info();
17253 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
17254 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
17255 +
17256 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
17257 +               ts->tv_sec++;
17258 +               ts->tv_nsec -= NSEC_PER_SEC;
17259 +       } else if (ts->tv_nsec < 0) {
17260 +               ts->tv_sec--;
17261 +               ts->tv_nsec += NSEC_PER_SEC;
17262 +       }
17263 +}
17264 +
17265 +int vx_settimeofday(const struct timespec *ts)
17266 +{
17267 +       struct timespec ats, delta;
17268 +       struct vx_info *vxi;
17269 +
17270 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17271 +               return do_settimeofday(ts);
17272 +
17273 +       getnstimeofday(&ats);
17274 +       delta = timespec_sub(*ts, ats);
17275 +
17276 +       vxi = current_vx_info();
17277 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
17278 +       return 0;
17279 +}
17280 +
17281 +#endif
17282 +
17283 diff -NurpP --minimal linux-3.1.6/kernel/vserver/cvirt_init.h linux-3.1.6-vs2.3.2.5/kernel/vserver/cvirt_init.h
17284 --- linux-3.1.6/kernel/vserver/cvirt_init.h     1970-01-01 01:00:00.000000000 +0100
17285 +++ linux-3.1.6-vs2.3.2.5/kernel/vserver/cvirt_init.h   2011-10-24 18:53:33.000000000 +0200
17286 @@ -0,0 +1,70 @@
17287 +
17288 +
17289 +extern uint64_t vx_idle_jiffies(void);
17290 +
17291 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
17292 +{
17293 +       uint64_t idle_jiffies = vx_idle_jiffies();
17294 +       uint64_t nsuptime;
17295 +
17296 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
17297 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
17298 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
17299 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
17300 +       cvirt->bias_ts.tv_sec = 0;
17301 +       cvirt->bias_ts.tv_nsec = 0;
17302 +
17303 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
17304 +       atomic_set(&cvirt->nr_threads, 0);
17305 +       atomic_set(&cvirt->nr_running, 0);
17306 +       atomic_set(&cvirt->nr_uninterruptible, 0);
17307 +       atomic_set(&cvirt->nr_onhold, 0);
17308 +
17309 +       spin_lock_init(&cvirt->load_lock);
17310 +       cvirt->load_last = jiffies;
17311 +       atomic_set(&cvirt->load_updates, 0);
17312 +       cvirt->load[0] = 0;
17313 +       cvirt->load[1] = 0;
17314 +       cvirt->load[2] = 0;
17315 +       atomic_set(&cvirt->total_forks, 0);
17316 +
17317 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
17318 +       init_waitqueue_head(&cvirt->syslog.log_wait);
17319 +       cvirt->syslog.log_start = 0;
17320 +       cvirt->syslog.log_end = 0;
17321 +       cvirt->syslog.con_start = 0;
17322 +       cvirt->syslog.logged_chars = 0;
17323 +}
17324 +
17325 +static inline
17326 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17327 +{
17328 +       // cvirt_pc->cpustat = { 0 };
17329 +}
17330 +
17331 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
17332 +{
17333 +#ifdef CONFIG_VSERVER_WARN
17334 +       int value;
17335 +#endif
17336 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
17337 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
17338 +               cvirt, value);
17339 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
17340 +               "!!! cvirt: %p[nr_running] = %d on exit.",
17341 +               cvirt, value);
17342 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
17343 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
17344 +               cvirt, value);
17345 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
17346 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
17347 +               cvirt, value);
17348 +       return;
17349 +}
17350 +
17351 +static inline
17352 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17353 +{
17354 +       return;
17355 +}
17356 +
17357 diff -NurpP --minimal linux-3.1.6/kernel/vserver/cvirt_proc.h linux-3.1.6-vs2.3.2.5/kernel/vserver/cvirt_proc.h
17358 --- linux-3.1.6/kernel/vserver/cvirt_proc.h     1970-01-01 01:00:00.000000000 +0100
17359 +++ linux-3.1.6-vs2.3.2.5/kernel/vserver/cvirt_proc.h   2011-10-24 18:53:33.000000000 +0200
17360 @@ -0,0 +1,135 @@
17361 +#ifndef _VX_CVIRT_PROC_H
17362 +#define _VX_CVIRT_PROC_H
17363 +
17364 +#include <linux/nsproxy.h>
17365 +#include <linux/mnt_namespace.h>
17366 +#include <linux/ipc_namespace.h>
17367 +#include <linux/utsname.h>
17368 +#include <linux/ipc.h>
17369 +
17370 +
17371 +static inline
17372 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17373 +{
17374 +       struct mnt_namespace *ns;
17375 +       struct uts_namespace *uts;
17376 +       struct ipc_namespace *ipc;
17377 +       struct path path;
17378 +       char *pstr, *root;
17379 +       int length = 0;
17380 +
17381 +       if (!nsproxy)
17382 +               goto out;
17383 +
17384 +       length += sprintf(buffer + length,
17385 +               "NSProxy:\t%p [%p,%p,%p]\n",
17386 +               nsproxy, nsproxy->mnt_ns,
17387 +               nsproxy->uts_ns, nsproxy->ipc_ns);
17388 +
17389 +       ns = nsproxy->mnt_ns;
17390 +       if (!ns)
17391 +               goto skip_ns;
17392 +
17393 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
17394 +       if (!pstr)
17395 +               goto skip_ns;
17396 +
17397 +       path.mnt = ns->root;
17398 +       path.dentry = ns->root->mnt_root;
17399 +       root = d_path(&path, pstr, PATH_MAX - 2);
17400 +       length += sprintf(buffer + length,
17401 +               "Namespace:\t%p [#%u]\n"
17402 +               "RootPath:\t%s\n",
17403 +               ns, atomic_read(&ns->count),
17404 +               root);
17405 +       kfree(pstr);
17406 +skip_ns:
17407 +
17408 +       uts = nsproxy->uts_ns;
17409 +       if (!uts)
17410 +               goto skip_uts;
17411 +
17412 +       length += sprintf(buffer + length,
17413 +               "SysName:\t%.*s\n"
17414 +               "NodeName:\t%.*s\n"
17415 +               "Release:\t%.*s\n"
17416 +               "Version:\t%.*s\n"
17417 +               "Machine:\t%.*s\n"
17418 +               "DomainName:\t%.*s\n",
17419 +               __NEW_UTS_LEN, uts->name.sysname,
17420 +               __NEW_UTS_LEN, uts->name.nodename,
17421 +               __NEW_UTS_LEN, uts->name.release,
17422 +               __NEW_UTS_LEN, uts->name.version,
17423 +               __NEW_UTS_LEN, uts->name.machine,
17424 +               __NEW_UTS_LEN, uts->name.domainname);
17425 +skip_uts:
17426 +
17427 +       ipc = nsproxy->ipc_ns;
17428 +       if (!ipc)
17429 +               goto skip_ipc;
17430 +
17431 +       length += sprintf(buffer + length,
17432 +               "SEMS:\t\t%d %d %d %d  %d\n"
17433 +               "MSG:\t\t%d %d %d\n"
17434 +               "SHM:\t\t%lu %lu  %d %d\n",
17435 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
17436 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
17437 +               ipc->used_sems,
17438 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17439 +               (unsigned long)ipc->shm_ctlmax,
17440 +               (unsigned long)ipc->shm_ctlall,
17441 +               ipc->shm_ctlmni, ipc->shm_tot);
17442 +skip_ipc:
17443 +out:
17444 +       return length;
17445 +}
17446 +
17447 +
17448 +#include <linux/sched.h>
17449 +
17450 +#define LOAD_INT(x) ((x) >> FSHIFT)
17451 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
17452 +
17453 +static inline
17454 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
17455 +{
17456 +       int length = 0;
17457 +       int a, b, c;
17458 +
17459 +       length += sprintf(buffer + length,
17460 +               "BiasUptime:\t%lu.%02lu\n",
17461 +               (unsigned long)cvirt->bias_uptime.tv_sec,
17462 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
17463 +
17464 +       a = cvirt->load[0] + (FIXED_1 / 200);
17465 +       b = cvirt->load[1] + (FIXED_1 / 200);
17466 +       c = cvirt->load[2] + (FIXED_1 / 200);
17467 +       length += sprintf(buffer + length,
17468 +               "nr_threads:\t%d\n"
17469 +               "nr_running:\t%d\n"
17470 +               "nr_unintr:\t%d\n"
17471 +               "nr_onhold:\t%d\n"
17472 +               "load_updates:\t%d\n"
17473 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
17474 +               "total_forks:\t%d\n",
17475 +               atomic_read(&cvirt->nr_threads),
17476 +               atomic_read(&cvirt->nr_running),
17477 +               atomic_read(&cvirt->nr_uninterruptible),
17478 +               atomic_read(&cvirt->nr_onhold),
17479 +               atomic_read(&cvirt->load_updates),
17480 +               LOAD_INT(a), LOAD_FRAC(a),
17481 +               LOAD_INT(b), LOAD_FRAC(b),
17482 +               LOAD_INT(c), LOAD_FRAC(c),
17483 +               atomic_read(&cvirt->total_forks));
17484 +       return length;
17485 +}
17486 +
17487 +static inline
17488 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
17489 +       char *buffer, int cpu)
17490 +{
17491 +       int length = 0;
17492 +       return length;
17493 +}
17494 +
17495 +#endif /* _VX_CVIRT_PROC_H */
17496 diff -NurpP --minimal linux-3.1.6/kernel/vserver/debug.c linux-3.1.6-vs2.3.2.5/kernel/vserver/debug.c
17497 --- linux-3.1.6/kernel/vserver/debug.c  1970-01-01 01:00:00.000000000 +0100
17498 +++ linux-3.1.6-vs2.3.2.5/kernel/vserver/debug.c        2011-10-24 18:53:33.000000000 +0200
17499 @@ -0,0 +1,32 @@
17500 +/*
17501 + *  kernel/vserver/debug.c
17502 + *
17503 + *  Copyright (C) 2005-2007 Herbert Pötzl
17504 + *
17505 + *  V0.01  vx_info dump support
17506 + *
17507 + */
17508 +
17509 +#include <linux/module.h>
17510 +
17511 +#include <linux/vserver/context.h>
17512 +
17513 +
17514 +void   dump_vx_info(struct vx_info *vxi, int level)
17515 +{
17516 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
17517 +               atomic_read(&vxi->vx_usecnt),
17518 +               atomic_read(&vxi->vx_tasks),
17519 +               vxi->vx_state);
17520 +       if (level > 0) {
17521 +               __dump_vx_limit(&vxi->limit);
17522 +               __dump_vx_sched(&vxi->sched);
17523 +               __dump_vx_cvirt(&vxi->cvirt);
17524 +               __dump_vx_cacct(&vxi->cacct);
17525 +       }
17526 +       printk("---\n");
17527 +}
17528 +
17529 +
17530 +EXPORT_SYMBOL_GPL(dump_vx_info);
17531 +
17532 diff -NurpP --minimal linux-3.1.6/kernel/vserver/device.c linux-3.1.6-vs2.3.2.5/kernel/vserver/device.c
17533 --- linux-3.1.6/kernel/vserver/device.c 1970-01-01 01:00:00.000000000 +0100
17534 +++ linux-3.1.6-vs2.3.2.5/kernel/vserver/device.c       2011-10-24 18:53:33.000000000 +0200
17535 @@ -0,0 +1,443 @@
17536 +/*
17537 + *  linux/kernel/vserver/device.c
17538 + *
17539 + *  Linux-VServer: Device Support
17540 + *
17541 + *  Copyright (C) 2006  Herbert Pötzl
17542 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
17543 + *
17544 + *  V0.01  device mapping basics
17545 + *  V0.02  added defaults
17546 + *
17547 + */
17548 +
17549 +#include <linux/slab.h>
17550 +#include <linux/rcupdate.h>
17551 +#include <linux/fs.h>
17552 +#include <linux/namei.h>
17553 +#include <linux/hash.h>
17554 +
17555 +#include <asm/errno.h>
17556 +#include <asm/uaccess.h>
17557 +#include <linux/vserver/base.h>
17558 +#include <linux/vserver/debug.h>
17559 +#include <linux/vserver/context.h>
17560 +#include <linux/vserver/device.h>
17561 +#include <linux/vserver/device_cmd.h>
17562 +
17563 +
17564 +#define DMAP_HASH_BITS 4
17565 +
17566 +
17567 +struct vs_mapping {
17568 +       union {
17569 +               struct hlist_node hlist;
17570 +               struct list_head list;
17571 +       } u;
17572 +#define dm_hlist       u.hlist
17573 +#define dm_list                u.list
17574 +       xid_t xid;
17575 +       dev_t device;
17576 +       struct vx_dmap_target target;
17577 +};
17578 +
17579 +
17580 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
17581 +
17582 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
17583 +
17584 +static struct vx_dmap_target dmap_defaults[2] = {
17585 +       { .flags = DATTR_OPEN },
17586 +       { .flags = DATTR_OPEN },
17587 +};
17588 +
17589 +
17590 +struct kmem_cache *dmap_cachep __read_mostly;
17591 +
17592 +int __init dmap_cache_init(void)
17593 +{
17594 +       dmap_cachep = kmem_cache_create("dmap_cache",
17595 +               sizeof(struct vs_mapping), 0,
17596 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
17597 +       return 0;
17598 +}
17599 +
17600 +__initcall(dmap_cache_init);
17601 +
17602 +
17603 +static inline unsigned int __hashval(dev_t dev, int bits)
17604 +{
17605 +       return hash_long((unsigned long)dev, bits);
17606 +}
17607 +
17608 +
17609 +/*     __hash_mapping()
17610 + *     add the mapping to the hash table
17611 + */
17612 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
17613 +{
17614 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17615 +       struct hlist_head *head, *hash = dmap_main_hash;
17616 +       int device = vdm->device;
17617 +
17618 +       spin_lock(hash_lock);
17619 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
17620 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
17621 +
17622 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
17623 +       hlist_add_head(&vdm->dm_hlist, head);
17624 +       spin_unlock(hash_lock);
17625 +}
17626 +
17627 +
17628 +static inline int __mode_to_default(umode_t mode)
17629 +{
17630 +       switch (mode) {
17631 +       case S_IFBLK:
17632 +               return 0;
17633 +       case S_IFCHR:
17634 +               return 1;
17635 +       default:
17636 +               BUG();
17637 +       }
17638 +}
17639 +
17640 +
17641 +/*     __set_default()
17642 + *     set a default
17643 + */
17644 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
17645 +       struct vx_dmap_target *vdmt)
17646 +{
17647 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17648 +       spin_lock(hash_lock);
17649 +
17650 +       if (vxi)
17651 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
17652 +       else
17653 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
17654 +
17655 +
17656 +       spin_unlock(hash_lock);
17657 +
17658 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
17659 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
17660 +}
17661 +
17662 +
17663 +/*     __remove_default()
17664 + *     remove a default
17665 + */
17666 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
17667 +{
17668 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17669 +       spin_lock(hash_lock);
17670 +
17671 +       if (vxi)
17672 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
17673 +       else    /* remove == reset */
17674 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
17675 +
17676 +       spin_unlock(hash_lock);
17677 +       return 0;
17678 +}
17679 +
17680 +
17681 +/*     __find_mapping()
17682 + *     find a mapping in the hash table
17683 + *
17684 + *     caller must hold hash_lock
17685 + */
17686 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
17687 +       struct vs_mapping **local, struct vs_mapping **global)
17688 +{
17689 +       struct hlist_head *hash = dmap_main_hash;
17690 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
17691 +       struct hlist_node *pos;
17692 +       struct vs_mapping *vdm;
17693 +
17694 +       *local = NULL;
17695 +       if (global)
17696 +               *global = NULL;
17697 +
17698 +       hlist_for_each(pos, head) {
17699 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
17700 +
17701 +               if ((vdm->device == device) &&
17702 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
17703 +                       if (vdm->xid == xid) {
17704 +                               *local = vdm;
17705 +                               return 1;
17706 +                       } else if (global && vdm->xid == 0)
17707 +                               *global = vdm;
17708 +               }
17709 +       }
17710 +
17711 +       if (global && *global)
17712 +               return 0;
17713 +       else
17714 +               return -ENOENT;
17715 +}
17716 +
17717 +
17718 +/*     __lookup_mapping()
17719 + *     find a mapping and store the result in target and flags
17720 + */
17721 +static inline int __lookup_mapping(struct vx_info *vxi,
17722 +       dev_t device, dev_t *target, int *flags, umode_t mode)
17723 +{
17724 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17725 +       struct vs_mapping *vdm, *global;
17726 +       struct vx_dmap_target *vdmt;
17727 +       int ret = 0;
17728 +       xid_t xid = vxi->vx_id;
17729 +       int index;
17730 +
17731 +       spin_lock(hash_lock);
17732 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
17733 +               ret = 1;
17734 +               vdmt = &vdm->target;
17735 +               goto found;
17736 +       }
17737 +
17738 +       index = __mode_to_default(mode);
17739 +       if (vxi && vxi->dmap.targets[index].flags) {
17740 +               ret = 2;
17741 +               vdmt = &vxi->dmap.targets[index];
17742 +       } else if (global) {
17743 +               ret = 3;
17744 +               vdmt = &global->target;
17745 +               goto found;
17746 +       } else {
17747 +               ret = 4;
17748 +               vdmt = &dmap_defaults[index];
17749 +       }
17750 +
17751 +found:
17752 +       if (target && (vdmt->flags & DATTR_REMAP))
17753 +               *target = vdmt->target;
17754 +       else if (target)
17755 +               *target = device;
17756 +       if (flags)
17757 +               *flags = vdmt->flags;
17758 +
17759 +       spin_unlock(hash_lock);
17760 +
17761 +       return ret;
17762 +}
17763 +
17764 +
17765 +/*     __remove_mapping()
17766 + *     remove a mapping from the hash table
17767 + */
17768 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
17769 +       umode_t mode)
17770 +{
17771 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17772 +       struct vs_mapping *vdm = NULL;
17773 +       int ret = 0;
17774 +
17775 +       spin_lock(hash_lock);
17776 +
17777 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
17778 +               NULL);
17779 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
17780 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
17781 +       if (ret < 0)
17782 +               goto out;
17783 +       hlist_del(&vdm->dm_hlist);
17784 +
17785 +out:
17786 +       spin_unlock(hash_lock);
17787 +       if (vdm)
17788 +               kmem_cache_free(dmap_cachep, vdm);
17789 +       return ret;
17790 +}
17791 +
17792 +
17793 +
17794 +int vs_map_device(struct vx_info *vxi,
17795 +       dev_t device, dev_t *target, umode_t mode)
17796 +{
17797 +       int ret, flags = DATTR_MASK;
17798 +
17799 +       if (!vxi) {
17800 +               if (target)
17801 +                       *target = device;
17802 +               goto out;
17803 +       }
17804 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
17805 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
17806 +               device, target ? *target : 0, flags, mode, ret);
17807 +out:
17808 +       return (flags & DATTR_MASK);
17809 +}
17810 +
17811 +
17812 +
17813 +static int do_set_mapping(struct vx_info *vxi,
17814 +       dev_t device, dev_t target, int flags, umode_t mode)
17815 +{
17816 +       if (device) {
17817 +               struct vs_mapping *new;
17818 +
17819 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
17820 +               if (!new)
17821 +                       return -ENOMEM;
17822 +
17823 +               INIT_HLIST_NODE(&new->dm_hlist);
17824 +               new->device = device;
17825 +               new->target.target = target;
17826 +               new->target.flags = flags | mode;
17827 +               new->xid = (vxi ? vxi->vx_id : 0);
17828 +
17829 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
17830 +               __hash_mapping(vxi, new);
17831 +       } else {
17832 +               struct vx_dmap_target new = {
17833 +                       .target = target,
17834 +                       .flags = flags | mode,
17835 +               };
17836 +               __set_default(vxi, mode, &new);
17837 +       }
17838 +       return 0;
17839 +}
17840 +
17841 +
17842 +static int do_unset_mapping(struct vx_info *vxi,
17843 +       dev_t device, dev_t target, int flags, umode_t mode)
17844 +{
17845 +       int ret = -EINVAL;
17846 +
17847 +       if (device) {
17848 +               ret = __remove_mapping(vxi, device, mode);
17849 +               if (ret < 0)
17850 +                       goto out;
17851 +       } else {
17852 +               ret = __remove_default(vxi, mode);
17853 +               if (ret < 0)
17854 +                       goto out;
17855 +       }
17856 +
17857 +out:
17858 +       return ret;
17859 +}
17860 +
17861 +
17862 +static inline int __user_device(const char __user *name, dev_t *dev,
17863 +       umode_t *mode)
17864 +{
17865 +       struct nameidata nd;
17866 +       int ret;
17867 +
17868 +       if (!name) {
17869 +               *dev = 0;
17870 +               return 0;
17871 +       }
17872 +       ret = user_lpath(name, &nd.path);
17873 +       if (ret)
17874 +               return ret;
17875 +       if (nd.path.dentry->d_inode) {
17876 +               *dev = nd.path.dentry->d_inode->i_rdev;
17877 +               *mode = nd.path.dentry->d_inode->i_mode;
17878 +       }
17879 +       path_put(&nd.path);
17880 +       return 0;
17881 +}
17882 +
17883 +static inline int __mapping_mode(dev_t device, dev_t target,
17884 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
17885 +{
17886 +       if (device)
17887 +               *mode = device_mode & S_IFMT;
17888 +       else if (target)
17889 +               *mode = target_mode & S_IFMT;
17890 +       else
17891 +               return -EINVAL;
17892 +
17893 +       /* if both given, device and target mode have to match */
17894 +       if (device && target &&
17895 +               ((device_mode ^ target_mode) & S_IFMT))
17896 +               return -EINVAL;
17897 +       return 0;
17898 +}
17899 +
17900 +
17901 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
17902 +       const char __user *target_path, int flags, int set)
17903 +{
17904 +       dev_t device = ~0, target = ~0;
17905 +       umode_t device_mode = 0, target_mode = 0, mode;
17906 +       int ret;
17907 +
17908 +       ret = __user_device(device_path, &device, &device_mode);
17909 +       if (ret)
17910 +               return ret;
17911 +       ret = __user_device(target_path, &target, &target_mode);
17912 +       if (ret)
17913 +               return ret;
17914 +
17915 +       ret = __mapping_mode(device, target,
17916 +               device_mode, target_mode, &mode);
17917 +       if (ret)
17918 +               return ret;
17919 +
17920 +       if (set)
17921 +               return do_set_mapping(vxi, device, target,
17922 +                       flags, mode);
17923 +       else
17924 +               return do_unset_mapping(vxi, device, target,
17925 +                       flags, mode);
17926 +}
17927 +
17928 +
17929 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
17930 +{
17931 +       struct vcmd_set_mapping_v0 vc_data;
17932 +
17933 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17934 +               return -EFAULT;
17935 +
17936 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17937 +               vc_data.flags, 1);
17938 +}
17939 +
17940 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
17941 +{
17942 +       struct vcmd_set_mapping_v0 vc_data;
17943 +
17944 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17945 +               return -EFAULT;
17946 +
17947 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17948 +               vc_data.flags, 0);
17949 +}
17950 +
17951 +
17952 +#ifdef CONFIG_COMPAT
17953 +
17954 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
17955 +{
17956 +       struct vcmd_set_mapping_v0_x32 vc_data;
17957 +
17958 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17959 +               return -EFAULT;
17960 +
17961 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17962 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
17963 +}
17964 +
17965 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
17966 +{
17967 +       struct vcmd_set_mapping_v0_x32 vc_data;
17968 +
17969 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17970 +               return -EFAULT;
17971 +
17972 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17973 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
17974 +}
17975 +
17976 +#endif /* CONFIG_COMPAT */
17977 +
17978 +
17979 diff -NurpP --minimal linux-3.1.6/kernel/vserver/dlimit.c linux-3.1.6-vs2.3.2.5/kernel/vserver/dlimit.c
17980 --- linux-3.1.6/kernel/vserver/dlimit.c 1970-01-01 01:00:00.000000000 +0100
17981 +++ linux-3.1.6-vs2.3.2.5/kernel/vserver/dlimit.c       2011-10-24 18:53:33.000000000 +0200
17982 @@ -0,0 +1,531 @@
17983 +/*
17984 + *  linux/kernel/vserver/dlimit.c
17985 + *
17986 + *  Virtual Server: Context Disk Limits
17987 + *
17988 + *  Copyright (C) 2004-2009  Herbert Pötzl
17989 + *
17990 + *  V0.01  initial version
17991 + *  V0.02  compat32 splitup
17992 + *  V0.03  extended interface
17993 + *
17994 + */
17995 +
17996 +#include <linux/statfs.h>
17997 +#include <linux/sched.h>
17998 +#include <linux/namei.h>
17999 +#include <linux/vs_tag.h>
18000 +#include <linux/vs_dlimit.h>
18001 +#include <linux/vserver/dlimit_cmd.h>
18002 +#include <linux/slab.h>
18003 +// #include <linux/gfp.h>
18004 +
18005 +#include <asm/uaccess.h>
18006 +
18007 +/*     __alloc_dl_info()
18008 +
18009 +       * allocate an initialized dl_info struct
18010 +       * doesn't make it visible (hash)                        */
18011 +
18012 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
18013 +{
18014 +       struct dl_info *new = NULL;
18015 +
18016 +       vxdprintk(VXD_CBIT(dlim, 5),
18017 +               "alloc_dl_info(%p,%d)*", sb, tag);
18018 +
18019 +       /* would this benefit from a slab cache? */
18020 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
18021 +       if (!new)
18022 +               return 0;
18023 +
18024 +       memset(new, 0, sizeof(struct dl_info));
18025 +       new->dl_tag = tag;
18026 +       new->dl_sb = sb;
18027 +       // INIT_RCU_HEAD(&new->dl_rcu);
18028 +       INIT_HLIST_NODE(&new->dl_hlist);
18029 +       spin_lock_init(&new->dl_lock);
18030 +       atomic_set(&new->dl_refcnt, 0);
18031 +       atomic_set(&new->dl_usecnt, 0);
18032 +
18033 +       /* rest of init goes here */
18034 +
18035 +       vxdprintk(VXD_CBIT(dlim, 4),
18036 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
18037 +       return new;
18038 +}
18039 +
18040 +/*     __dealloc_dl_info()
18041 +
18042 +       * final disposal of dl_info                             */
18043 +
18044 +static void __dealloc_dl_info(struct dl_info *dli)
18045 +{
18046 +       vxdprintk(VXD_CBIT(dlim, 4),
18047 +               "dealloc_dl_info(%p)", dli);
18048 +
18049 +       dli->dl_hlist.next = LIST_POISON1;
18050 +       dli->dl_tag = -1;
18051 +       dli->dl_sb = 0;
18052 +
18053 +       BUG_ON(atomic_read(&dli->dl_usecnt));
18054 +       BUG_ON(atomic_read(&dli->dl_refcnt));
18055 +
18056 +       kfree(dli);
18057 +}
18058 +
18059 +
18060 +/*     hash table for dl_info hash */
18061 +
18062 +#define DL_HASH_SIZE   13
18063 +
18064 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
18065 +
18066 +static DEFINE_SPINLOCK(dl_info_hash_lock);
18067 +
18068 +
18069 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
18070 +{
18071 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
18072 +}
18073 +
18074 +
18075 +
18076 +/*     __hash_dl_info()
18077 +
18078 +       * add the dli to the global hash table
18079 +       * requires the hash_lock to be held                     */
18080 +
18081 +static inline void __hash_dl_info(struct dl_info *dli)
18082 +{
18083 +       struct hlist_head *head;
18084 +
18085 +       vxdprintk(VXD_CBIT(dlim, 6),
18086 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
18087 +       get_dl_info(dli);
18088 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
18089 +       hlist_add_head_rcu(&dli->dl_hlist, head);
18090 +}
18091 +
18092 +/*     __unhash_dl_info()
18093 +
18094 +       * remove the dli from the global hash table
18095 +       * requires the hash_lock to be held                     */
18096 +
18097 +static inline void __unhash_dl_info(struct dl_info *dli)
18098 +{
18099 +       vxdprintk(VXD_CBIT(dlim, 6),
18100 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
18101 +       hlist_del_rcu(&dli->dl_hlist);
18102 +       put_dl_info(dli);
18103 +}
18104 +
18105 +
18106 +/*     __lookup_dl_info()
18107 +
18108 +       * requires the rcu_read_lock()
18109 +       * doesn't increment the dl_refcnt                       */
18110 +
18111 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
18112 +{
18113 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
18114 +       struct hlist_node *pos;
18115 +       struct dl_info *dli;
18116 +
18117 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
18118 +
18119 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
18120 +                       return dli;
18121 +               }
18122 +       }
18123 +       return NULL;
18124 +}
18125 +
18126 +
18127 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
18128 +{
18129 +       struct dl_info *dli;
18130 +
18131 +       rcu_read_lock();
18132 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
18133 +       vxdprintk(VXD_CBIT(dlim, 7),
18134 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
18135 +       rcu_read_unlock();
18136 +       return dli;
18137 +}
18138 +
18139 +void rcu_free_dl_info(struct rcu_head *head)
18140 +{
18141 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
18142 +       int usecnt, refcnt;
18143 +
18144 +       BUG_ON(!dli || !head);
18145 +
18146 +       usecnt = atomic_read(&dli->dl_usecnt);
18147 +       BUG_ON(usecnt < 0);
18148 +
18149 +       refcnt = atomic_read(&dli->dl_refcnt);
18150 +       BUG_ON(refcnt < 0);
18151 +
18152 +       vxdprintk(VXD_CBIT(dlim, 3),
18153 +               "rcu_free_dl_info(%p)", dli);
18154 +       if (!usecnt)
18155 +               __dealloc_dl_info(dli);
18156 +       else
18157 +               printk("!!! rcu didn't free\n");
18158 +}
18159 +
18160 +
18161 +
18162 +
18163 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
18164 +       uint32_t flags, int add)
18165 +{
18166 +       struct path path;
18167 +       int ret;
18168 +
18169 +       ret = user_lpath(name, &path);
18170 +       if (!ret) {
18171 +               struct super_block *sb;
18172 +               struct dl_info *dli;
18173 +
18174 +               ret = -EINVAL;
18175 +               if (!path.dentry->d_inode)
18176 +                       goto out_release;
18177 +               if (!(sb = path.dentry->d_inode->i_sb))
18178 +                       goto out_release;
18179 +
18180 +               if (add) {
18181 +                       dli = __alloc_dl_info(sb, id);
18182 +                       spin_lock(&dl_info_hash_lock);
18183 +
18184 +                       ret = -EEXIST;
18185 +                       if (__lookup_dl_info(sb, id))
18186 +                               goto out_unlock;
18187 +                       __hash_dl_info(dli);
18188 +                       dli = NULL;
18189 +               } else {
18190 +                       spin_lock(&dl_info_hash_lock);
18191 +                       dli = __lookup_dl_info(sb, id);
18192 +
18193 +                       ret = -ESRCH;
18194 +                       if (!dli)
18195 +                               goto out_unlock;
18196 +                       __unhash_dl_info(dli);
18197 +               }
18198 +               ret = 0;
18199 +       out_unlock:
18200 +               spin_unlock(&dl_info_hash_lock);
18201 +               if (add && dli)
18202 +                       __dealloc_dl_info(dli);
18203 +       out_release:
18204 +               path_put(&path);
18205 +       }
18206 +       return ret;
18207 +}
18208 +
18209 +int vc_add_dlimit(uint32_t id, void __user *data)
18210 +{
18211 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18212 +
18213 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18214 +               return -EFAULT;
18215 +
18216 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
18217 +}
18218 +
18219 +int vc_rem_dlimit(uint32_t id, void __user *data)
18220 +{
18221 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18222 +
18223 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18224 +               return -EFAULT;
18225 +
18226 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
18227 +}
18228 +
18229 +#ifdef CONFIG_COMPAT
18230 +
18231 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
18232 +{
18233 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18234 +
18235 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18236 +               return -EFAULT;
18237 +
18238 +       return do_addrem_dlimit(id,
18239 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
18240 +}
18241 +
18242 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
18243 +{
18244 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18245 +
18246 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18247 +               return -EFAULT;
18248 +
18249 +       return do_addrem_dlimit(id,
18250 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
18251 +}
18252 +
18253 +#endif /* CONFIG_COMPAT */
18254 +
18255 +
18256 +static inline
18257 +int do_set_dlimit(uint32_t id, const char __user *name,
18258 +       uint32_t space_used, uint32_t space_total,
18259 +       uint32_t inodes_used, uint32_t inodes_total,
18260 +       uint32_t reserved, uint32_t flags)
18261 +{
18262 +       struct path path;
18263 +       int ret;
18264 +
18265 +       ret = user_lpath(name, &path);
18266 +       if (!ret) {
18267 +               struct super_block *sb;
18268 +               struct dl_info *dli;
18269 +
18270 +               ret = -EINVAL;
18271 +               if (!path.dentry->d_inode)
18272 +                       goto out_release;
18273 +               if (!(sb = path.dentry->d_inode->i_sb))
18274 +                       goto out_release;
18275 +
18276 +               /* sanity checks */
18277 +               if ((reserved != CDLIM_KEEP &&
18278 +                       reserved > 100) ||
18279 +                       (inodes_used != CDLIM_KEEP &&
18280 +                       inodes_used > inodes_total) ||
18281 +                       (space_used != CDLIM_KEEP &&
18282 +                       space_used > space_total))
18283 +                       goto out_release;
18284 +
18285 +               ret = -ESRCH;
18286 +               dli = locate_dl_info(sb, id);
18287 +               if (!dli)
18288 +                       goto out_release;
18289 +
18290 +               spin_lock(&dli->dl_lock);
18291 +
18292 +               if (inodes_used != CDLIM_KEEP)
18293 +                       dli->dl_inodes_used = inodes_used;
18294 +               if (inodes_total != CDLIM_KEEP)
18295 +                       dli->dl_inodes_total = inodes_total;
18296 +               if (space_used != CDLIM_KEEP)
18297 +                       dli->dl_space_used = dlimit_space_32to64(
18298 +                               space_used, flags, DLIMS_USED);
18299 +
18300 +               if (space_total == CDLIM_INFINITY)
18301 +                       dli->dl_space_total = DLIM_INFINITY;
18302 +               else if (space_total != CDLIM_KEEP)
18303 +                       dli->dl_space_total = dlimit_space_32to64(
18304 +                               space_total, flags, DLIMS_TOTAL);
18305 +
18306 +               if (reserved != CDLIM_KEEP)
18307 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
18308 +
18309 +               spin_unlock(&dli->dl_lock);
18310 +
18311 +               put_dl_info(dli);
18312 +               ret = 0;
18313 +
18314 +       out_release:
18315 +               path_put(&path);
18316 +       }
18317 +       return ret;
18318 +}
18319 +
18320 +int vc_set_dlimit(uint32_t id, void __user *data)
18321 +{
18322 +       struct vcmd_ctx_dlimit_v0 vc_data;
18323 +
18324 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18325 +               return -EFAULT;
18326 +
18327 +       return do_set_dlimit(id, vc_data.name,
18328 +               vc_data.space_used, vc_data.space_total,
18329 +               vc_data.inodes_used, vc_data.inodes_total,
18330 +               vc_data.reserved, vc_data.flags);
18331 +}
18332 +
18333 +#ifdef CONFIG_COMPAT
18334 +
18335 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
18336 +{
18337 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18338 +
18339 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18340 +               return -EFAULT;
18341 +
18342 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
18343 +               vc_data.space_used, vc_data.space_total,
18344 +               vc_data.inodes_used, vc_data.inodes_total,
18345 +               vc_data.reserved, vc_data.flags);
18346 +}
18347 +
18348 +#endif /* CONFIG_COMPAT */
18349 +
18350 +
18351 +static inline
18352 +int do_get_dlimit(uint32_t id, const char __user *name,
18353 +       uint32_t *space_used, uint32_t *space_total,
18354 +       uint32_t *inodes_used, uint32_t *inodes_total,
18355 +       uint32_t *reserved, uint32_t *flags)
18356 +{
18357 +       struct path path;
18358 +       int ret;
18359 +
18360 +       ret = user_lpath(name, &path);
18361 +       if (!ret) {
18362 +               struct super_block *sb;
18363 +               struct dl_info *dli;
18364 +
18365 +               ret = -EINVAL;
18366 +               if (!path.dentry->d_inode)
18367 +                       goto out_release;
18368 +               if (!(sb = path.dentry->d_inode->i_sb))
18369 +                       goto out_release;
18370 +
18371 +               ret = -ESRCH;
18372 +               dli = locate_dl_info(sb, id);
18373 +               if (!dli)
18374 +                       goto out_release;
18375 +
18376 +               spin_lock(&dli->dl_lock);
18377 +               *inodes_used = dli->dl_inodes_used;
18378 +               *inodes_total = dli->dl_inodes_total;
18379 +
18380 +               *space_used = dlimit_space_64to32(
18381 +                       dli->dl_space_used, flags, DLIMS_USED);
18382 +
18383 +               if (dli->dl_space_total == DLIM_INFINITY)
18384 +                       *space_total = CDLIM_INFINITY;
18385 +               else
18386 +                       *space_total = dlimit_space_64to32(
18387 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
18388 +
18389 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18390 +               spin_unlock(&dli->dl_lock);
18391 +
18392 +               put_dl_info(dli);
18393 +               ret = -EFAULT;
18394 +
18395 +               ret = 0;
18396 +       out_release:
18397 +               path_put(&path);
18398 +       }
18399 +       return ret;
18400 +}
18401 +
18402 +
18403 +int vc_get_dlimit(uint32_t id, void __user *data)
18404 +{
18405 +       struct vcmd_ctx_dlimit_v0 vc_data;
18406 +       int ret;
18407 +
18408 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18409 +               return -EFAULT;
18410 +
18411 +       ret = do_get_dlimit(id, vc_data.name,
18412 +               &vc_data.space_used, &vc_data.space_total,
18413 +               &vc_data.inodes_used, &vc_data.inodes_total,
18414 +               &vc_data.reserved, &vc_data.flags);
18415 +       if (ret)
18416 +               return ret;
18417 +
18418 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18419 +               return -EFAULT;
18420 +       return 0;
18421 +}
18422 +
18423 +#ifdef CONFIG_COMPAT
18424 +
18425 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18426 +{
18427 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18428 +       int ret;
18429 +
18430 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18431 +               return -EFAULT;
18432 +
18433 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18434 +               &vc_data.space_used, &vc_data.space_total,
18435 +               &vc_data.inodes_used, &vc_data.inodes_total,
18436 +               &vc_data.reserved, &vc_data.flags);
18437 +       if (ret)
18438 +               return ret;
18439 +
18440 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18441 +               return -EFAULT;
18442 +       return 0;
18443 +}
18444 +
18445 +#endif /* CONFIG_COMPAT */
18446 +
18447 +
18448 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
18449 +{
18450 +       struct dl_info *dli;
18451 +       __u64 blimit, bfree, bavail;
18452 +       __u32 ifree;
18453 +
18454 +       dli = locate_dl_info(sb, dx_current_tag());
18455 +       if (!dli)
18456 +               return;
18457 +
18458 +       spin_lock(&dli->dl_lock);
18459 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
18460 +               goto no_ilim;
18461 +
18462 +       /* reduce max inodes available to limit */
18463 +       if (buf->f_files > dli->dl_inodes_total)
18464 +               buf->f_files = dli->dl_inodes_total;
18465 +
18466 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
18467 +       /* reduce free inodes to min */
18468 +       if (ifree < buf->f_ffree)
18469 +               buf->f_ffree = ifree;
18470 +
18471 +no_ilim:
18472 +       if (dli->dl_space_total == DLIM_INFINITY)
18473 +               goto no_blim;
18474 +
18475 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
18476 +
18477 +       if (dli->dl_space_total < dli->dl_space_used)
18478 +               bfree = 0;
18479 +       else
18480 +               bfree = (dli->dl_space_total - dli->dl_space_used)
18481 +                       >> sb->s_blocksize_bits;
18482 +
18483 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
18484 +       if (bavail < dli->dl_space_used)
18485 +               bavail = 0;
18486 +       else
18487 +               bavail = (bavail - dli->dl_space_used)
18488 +                       >> sb->s_blocksize_bits;
18489 +
18490 +       /* reduce max space available to limit */
18491 +       if (buf->f_blocks > blimit)
18492 +               buf->f_blocks = blimit;
18493 +
18494 +       /* reduce free space to min */
18495 +       if (bfree < buf->f_bfree)
18496 +               buf->f_bfree = bfree;
18497 +
18498 +       /* reduce avail space to min */
18499 +       if (bavail < buf->f_bavail)
18500 +               buf->f_bavail = bavail;
18501 +
18502 +no_blim:
18503 +       spin_unlock(&dli->dl_lock);
18504 +       put_dl_info(dli);
18505 +
18506 +       return;
18507 +}
18508 +
18509 +#include <linux/module.h>
18510 +
18511 +EXPORT_SYMBOL_GPL(locate_dl_info);
18512 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
18513 +
18514 diff -NurpP --minimal linux-3.1.6/kernel/vserver/helper.c linux-3.1.6-vs2.3.2.5/kernel/vserver/helper.c
18515 --- linux-3.1.6/kernel/vserver/helper.c 1970-01-01 01:00:00.000000000 +0100
18516 +++ linux-3.1.6-vs2.3.2.5/kernel/vserver/helper.c       2011-10-24 18:53:33.000000000 +0200
18517 @@ -0,0 +1,223 @@
18518 +/*
18519 + *  linux/kernel/vserver/helper.c
18520 + *
18521 + *  Virtual Context Support
18522 + *
18523 + *  Copyright (C) 2004-2007  Herbert Pötzl
18524 + *
18525 + *  V0.01  basic helper
18526 + *
18527 + */
18528 +
18529 +#include <linux/kmod.h>
18530 +#include <linux/reboot.h>
18531 +#include <linux/vs_context.h>
18532 +#include <linux/vs_network.h>
18533 +#include <linux/vserver/signal.h>
18534 +
18535 +
18536 +char vshelper_path[255] = "/sbin/vshelper";
18537 +
18538 +
18539 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
18540 +{
18541 +       int ret;
18542 +
18543 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
18544 +               printk( KERN_WARNING
18545 +                       "%s: (%s %s) returned %s with %d\n",
18546 +                       name, argv[1], argv[2],
18547 +                       sync ? "sync" : "async", ret);
18548 +       }
18549 +       vxdprintk(VXD_CBIT(switch, 4),
18550 +               "%s: (%s %s) returned %s with %d",
18551 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
18552 +       return ret;
18553 +}
18554 +
18555 +/*
18556 + *      vshelper path is set via /proc/sys
18557 + *      invoked by vserver sys_reboot(), with
18558 + *      the following arguments
18559 + *
18560 + *      argv [0] = vshelper_path;
18561 + *      argv [1] = action: "restart", "halt", "poweroff", ...
18562 + *      argv [2] = context identifier
18563 + *
18564 + *      envp [*] = type-specific parameters
18565 + */
18566 +
18567 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
18568 +{
18569 +       char id_buf[8], cmd_buf[16];
18570 +       char uid_buf[16], pid_buf[16];
18571 +       int ret;
18572 +
18573 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18574 +       char *envp[] = {"HOME=/", "TERM=linux",
18575 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
18576 +                       uid_buf, pid_buf, cmd_buf, 0};
18577 +
18578 +       if (vx_info_state(vxi, VXS_HELPER))
18579 +               return -EAGAIN;
18580 +       vxi->vx_state |= VXS_HELPER;
18581 +
18582 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
18583 +
18584 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
18585 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current_uid());
18586 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
18587 +
18588 +       switch (cmd) {
18589 +       case LINUX_REBOOT_CMD_RESTART:
18590 +               argv[1] = "restart";
18591 +               break;
18592 +
18593 +       case LINUX_REBOOT_CMD_HALT:
18594 +               argv[1] = "halt";
18595 +               break;
18596 +
18597 +       case LINUX_REBOOT_CMD_POWER_OFF:
18598 +               argv[1] = "poweroff";
18599 +               break;
18600 +
18601 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
18602 +               argv[1] = "swsusp";
18603 +               break;
18604 +
18605 +       case LINUX_REBOOT_CMD_OOM:
18606 +               argv[1] = "oom";
18607 +               break;
18608 +
18609 +       default:
18610 +               vxi->vx_state &= ~VXS_HELPER;
18611 +               return 0;
18612 +       }
18613 +
18614 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
18615 +       vxi->vx_state &= ~VXS_HELPER;
18616 +       __wakeup_vx_info(vxi);
18617 +       return (ret) ? -EPERM : 0;
18618 +}
18619 +
18620 +
18621 +long vs_reboot(unsigned int cmd, void __user *arg)
18622 +{
18623 +       struct vx_info *vxi = current_vx_info();
18624 +       long ret = 0;
18625 +
18626 +       vxdprintk(VXD_CBIT(misc, 5),
18627 +               "vs_reboot(%p[#%d],%u)",
18628 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18629 +
18630 +       ret = vs_reboot_helper(vxi, cmd, arg);
18631 +       if (ret)
18632 +               return ret;
18633 +
18634 +       vxi->reboot_cmd = cmd;
18635 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18636 +               switch (cmd) {
18637 +               case LINUX_REBOOT_CMD_RESTART:
18638 +               case LINUX_REBOOT_CMD_HALT:
18639 +               case LINUX_REBOOT_CMD_POWER_OFF:
18640 +                       vx_info_kill(vxi, 0, SIGKILL);
18641 +                       vx_info_kill(vxi, 1, SIGKILL);
18642 +               default:
18643 +                       break;
18644 +               }
18645 +       }
18646 +       return 0;
18647 +}
18648 +
18649 +long vs_oom_action(unsigned int cmd)
18650 +{
18651 +       struct vx_info *vxi = current_vx_info();
18652 +       long ret = 0;
18653 +
18654 +       vxdprintk(VXD_CBIT(misc, 5),
18655 +               "vs_oom_action(%p[#%d],%u)",
18656 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18657 +
18658 +       ret = vs_reboot_helper(vxi, cmd, NULL);
18659 +       if (ret)
18660 +               return ret;
18661 +
18662 +       vxi->reboot_cmd = cmd;
18663 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18664 +               vx_info_kill(vxi, 0, SIGKILL);
18665 +               vx_info_kill(vxi, 1, SIGKILL);
18666 +       }
18667 +       return 0;
18668 +}
18669 +
18670 +/*
18671 + *      argv [0] = vshelper_path;
18672 + *      argv [1] = action: "startup", "shutdown"
18673 + *      argv [2] = context identifier
18674 + *
18675 + *      envp [*] = type-specific parameters
18676 + */
18677 +
18678 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
18679 +{
18680 +       char id_buf[8], cmd_buf[16];
18681 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18682 +       char *envp[] = {"HOME=/", "TERM=linux",
18683 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18684 +
18685 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
18686 +               return 0;
18687 +
18688 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
18689 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
18690 +
18691 +       switch (cmd) {
18692 +       case VSC_STARTUP:
18693 +               argv[1] = "startup";
18694 +               break;
18695 +       case VSC_SHUTDOWN:
18696 +               argv[1] = "shutdown";
18697 +               break;
18698 +       default:
18699 +               return 0;
18700 +       }
18701 +
18702 +       return do_vshelper(vshelper_path, argv, envp, 1);
18703 +}
18704 +
18705 +
18706 +/*
18707 + *      argv [0] = vshelper_path;
18708 + *      argv [1] = action: "netup", "netdown"
18709 + *      argv [2] = context identifier
18710 + *
18711 + *      envp [*] = type-specific parameters
18712 + */
18713 +
18714 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
18715 +{
18716 +       char id_buf[8], cmd_buf[16];
18717 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18718 +       char *envp[] = {"HOME=/", "TERM=linux",
18719 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18720 +
18721 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
18722 +               return 0;
18723 +
18724 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
18725 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
18726 +
18727 +       switch (cmd) {
18728 +       case VSC_NETUP:
18729 +               argv[1] = "netup";
18730 +               break;
18731 +       case VSC_NETDOWN:
18732 +               argv[1] = "netdown";
18733 +               break;
18734 +       default:
18735 +               return 0;
18736 +       }
18737 +
18738 +       return do_vshelper(vshelper_path, argv, envp, 1);
18739 +}
18740 +
18741 diff -NurpP --minimal linux-3.1.6/kernel/vserver/history.c linux-3.1.6-vs2.3.2.5/kernel/vserver/history.c
18742 --- linux-3.1.6/kernel/vserver/history.c        1970-01-01 01:00:00.000000000 +0100
18743 +++ linux-3.1.6-vs2.3.2.5/kernel/vserver/history.c      2011-10-24 18:53:33.000000000 +0200
18744 @@ -0,0 +1,258 @@
18745 +/*
18746 + *  kernel/vserver/history.c
18747 + *
18748 + *  Virtual Context History Backtrace
18749 + *
18750 + *  Copyright (C) 2004-2007  Herbert Pötzl
18751 + *
18752 + *  V0.01  basic structure
18753 + *  V0.02  hash/unhash and trace
18754 + *  V0.03  preemption fixes
18755 + *
18756 + */
18757 +
18758 +#include <linux/module.h>
18759 +#include <asm/uaccess.h>
18760 +
18761 +#include <linux/vserver/context.h>
18762 +#include <linux/vserver/debug.h>
18763 +#include <linux/vserver/debug_cmd.h>
18764 +#include <linux/vserver/history.h>
18765 +
18766 +
18767 +#ifdef CONFIG_VSERVER_HISTORY
18768 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
18769 +#else
18770 +#define VXH_SIZE       64
18771 +#endif
18772 +
18773 +struct _vx_history {
18774 +       unsigned int counter;
18775 +
18776 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
18777 +};
18778 +
18779 +
18780 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
18781 +
18782 +unsigned volatile int vxh_active = 1;
18783 +
18784 +static atomic_t sequence = ATOMIC_INIT(0);
18785 +
18786 +
18787 +/*     vxh_advance()
18788 +
18789 +       * requires disabled preemption                          */
18790 +
18791 +struct _vx_hist_entry *vxh_advance(void *loc)
18792 +{
18793 +       unsigned int cpu = smp_processor_id();
18794 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18795 +       struct _vx_hist_entry *entry;
18796 +       unsigned int index;
18797 +
18798 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
18799 +       entry = &hist->entry[index];
18800 +
18801 +       entry->seq = atomic_inc_return(&sequence);
18802 +       entry->loc = loc;
18803 +       return entry;
18804 +}
18805 +
18806 +EXPORT_SYMBOL_GPL(vxh_advance);
18807 +
18808 +
18809 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
18810 +
18811 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
18812 +
18813 +
18814 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
18815 +
18816 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
18817 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
18818 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
18819 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
18820 +
18821 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
18822 +{
18823 +       switch (e->type) {
18824 +       case VXH_THROW_OOPS:
18825 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
18826 +               break;
18827 +
18828 +       case VXH_GET_VX_INFO:
18829 +       case VXH_PUT_VX_INFO:
18830 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18831 +                       VXH_LOC_ARGS(e),
18832 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
18833 +                       VXH_VXI_ARGS(e));
18834 +               break;
18835 +
18836 +       case VXH_INIT_VX_INFO:
18837 +       case VXH_SET_VX_INFO:
18838 +       case VXH_CLR_VX_INFO:
18839 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18840 +                       VXH_LOC_ARGS(e),
18841 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
18842 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
18843 +                       VXH_VXI_ARGS(e), e->sc.data);
18844 +               break;
18845 +
18846 +       case VXH_CLAIM_VX_INFO:
18847 +       case VXH_RELEASE_VX_INFO:
18848 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18849 +                       VXH_LOC_ARGS(e),
18850 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
18851 +                       VXH_VXI_ARGS(e), e->sc.data);
18852 +               break;
18853 +
18854 +       case VXH_ALLOC_VX_INFO:
18855 +       case VXH_DEALLOC_VX_INFO:
18856 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18857 +                       VXH_LOC_ARGS(e),
18858 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
18859 +                       VXH_VXI_ARGS(e));
18860 +               break;
18861 +
18862 +       case VXH_HASH_VX_INFO:
18863 +       case VXH_UNHASH_VX_INFO:
18864 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
18865 +                       VXH_LOC_ARGS(e),
18866 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
18867 +                       VXH_VXI_ARGS(e));
18868 +               break;
18869 +
18870 +       case VXH_LOC_VX_INFO:
18871 +       case VXH_LOOKUP_VX_INFO:
18872 +       case VXH_CREATE_VX_INFO:
18873 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
18874 +                       VXH_LOC_ARGS(e),
18875 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
18876 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
18877 +                       e->ll.arg, VXH_VXI_ARGS(e));
18878 +               break;
18879 +       }
18880 +}
18881 +
18882 +static void __vxh_dump_history(void)
18883 +{
18884 +       unsigned int i, cpu;
18885 +
18886 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
18887 +               atomic_read(&sequence), NR_CPUS);
18888 +
18889 +       for (i = 0; i < VXH_SIZE; i++) {
18890 +               for_each_online_cpu(cpu) {
18891 +                       struct _vx_history *hist =
18892 +                               &per_cpu(vx_history_buffer, cpu);
18893 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
18894 +                       struct _vx_hist_entry *entry = &hist->entry[index];
18895 +
18896 +                       vxh_dump_entry(entry, cpu);
18897 +               }
18898 +       }
18899 +}
18900 +
18901 +void   vxh_dump_history(void)
18902 +{
18903 +       vxh_active = 0;
18904 +#ifdef CONFIG_SMP
18905 +       local_irq_enable();
18906 +       smp_send_stop();
18907 +       local_irq_disable();
18908 +#endif
18909 +       __vxh_dump_history();
18910 +}
18911 +
18912 +
18913 +/* vserver syscall commands below here */
18914 +
18915 +
18916 +int vc_dump_history(uint32_t id)
18917 +{
18918 +       vxh_active = 0;
18919 +       __vxh_dump_history();
18920 +       vxh_active = 1;
18921 +
18922 +       return 0;
18923 +}
18924 +
18925 +
18926 +int do_read_history(struct __user _vx_hist_entry *data,
18927 +       int cpu, uint32_t *index, uint32_t *count)
18928 +{
18929 +       int pos, ret = 0;
18930 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18931 +       int end = hist->counter;
18932 +       int start = end - VXH_SIZE + 2;
18933 +       int idx = *index;
18934 +
18935 +       /* special case: get current pos */
18936 +       if (!*count) {
18937 +               *index = end;
18938 +               return 0;
18939 +       }
18940 +
18941 +       /* have we lost some data? */
18942 +       if (idx < start)
18943 +               idx = start;
18944 +
18945 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
18946 +               struct _vx_hist_entry *entry =
18947 +                       &hist->entry[idx % VXH_SIZE];
18948 +
18949 +               /* send entry to userspace */
18950 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
18951 +               if (ret)
18952 +                       break;
18953 +       }
18954 +       /* save new index and count */
18955 +       *index = idx;
18956 +       *count = pos;
18957 +       return ret ? ret : (*index < end);
18958 +}
18959 +
18960 +int vc_read_history(uint32_t id, void __user *data)
18961 +{
18962 +       struct vcmd_read_history_v0 vc_data;
18963 +       int ret;
18964 +
18965 +       if (id >= NR_CPUS)
18966 +               return -EINVAL;
18967 +
18968 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18969 +               return -EFAULT;
18970 +
18971 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
18972 +               id, &vc_data.index, &vc_data.count);
18973 +
18974 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18975 +               return -EFAULT;
18976 +       return ret;
18977 +}
18978 +
18979 +#ifdef CONFIG_COMPAT
18980 +
18981 +int vc_read_history_x32(uint32_t id, void __user *data)
18982 +{
18983 +       struct vcmd_read_history_v0_x32 vc_data;
18984 +       int ret;
18985 +
18986 +       if (id >= NR_CPUS)
18987 +               return -EINVAL;
18988 +
18989 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18990 +               return -EFAULT;
18991 +
18992 +       ret = do_read_history((struct __user _vx_hist_entry *)
18993 +               compat_ptr(vc_data.data_ptr),
18994 +               id, &vc_data.index, &vc_data.count);
18995 +
18996 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18997 +               return -EFAULT;
18998 +       return ret;
18999 +}
19000 +
19001 +#endif /* CONFIG_COMPAT */
19002 +
19003 diff -NurpP --minimal linux-3.1.6/kernel/vserver/inet.c linux-3.1.6-vs2.3.2.5/kernel/vserver/inet.c
19004 --- linux-3.1.6/kernel/vserver/inet.c   1970-01-01 01:00:00.000000000 +0100
19005 +++ linux-3.1.6-vs2.3.2.5/kernel/vserver/inet.c 2011-10-24 18:53:33.000000000 +0200
19006 @@ -0,0 +1,225 @@
19007 +
19008 +#include <linux/in.h>
19009 +#include <linux/inetdevice.h>
19010 +#include <linux/vs_inet.h>
19011 +#include <linux/vs_inet6.h>
19012 +#include <linux/vserver/debug.h>
19013 +#include <net/route.h>
19014 +#include <net/addrconf.h>
19015 +
19016 +
19017 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19018 +{
19019 +       int ret = 0;
19020 +
19021 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19022 +               ret = 1;
19023 +       else {
19024 +               struct nx_addr_v4 *ptr;
19025 +
19026 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
19027 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19028 +                               ret = 1;
19029 +                               break;
19030 +                       }
19031 +               }
19032 +       }
19033 +
19034 +       vxdprintk(VXD_CBIT(net, 2),
19035 +               "nx_v4_addr_conflict(%p,%p): %d",
19036 +               nxi1, nxi2, ret);
19037 +
19038 +       return ret;
19039 +}
19040 +
19041 +
19042 +#ifdef CONFIG_IPV6
19043 +
19044 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19045 +{
19046 +       int ret = 0;
19047 +
19048 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19049 +               ret = 1;
19050 +       else {
19051 +               struct nx_addr_v6 *ptr;
19052 +
19053 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
19054 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19055 +                               ret = 1;
19056 +                               break;
19057 +                       }
19058 +               }
19059 +       }
19060 +
19061 +       vxdprintk(VXD_CBIT(net, 2),
19062 +               "nx_v6_addr_conflict(%p,%p): %d",
19063 +               nxi1, nxi2, ret);
19064 +
19065 +       return ret;
19066 +}
19067 +
19068 +#endif
19069 +
19070 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19071 +{
19072 +       struct in_device *in_dev;
19073 +       struct in_ifaddr **ifap;
19074 +       struct in_ifaddr *ifa;
19075 +       int ret = 0;
19076 +
19077 +       if (!dev)
19078 +               goto out;
19079 +       in_dev = in_dev_get(dev);
19080 +       if (!in_dev)
19081 +               goto out;
19082 +
19083 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
19084 +               ifap = &ifa->ifa_next) {
19085 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
19086 +                       ret = 1;
19087 +                       break;
19088 +               }
19089 +       }
19090 +       in_dev_put(in_dev);
19091 +out:
19092 +       return ret;
19093 +}
19094 +
19095 +
19096 +#ifdef CONFIG_IPV6
19097 +
19098 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19099 +{
19100 +       struct inet6_dev *in_dev;
19101 +       struct inet6_ifaddr *ifa;
19102 +       int ret = 0;
19103 +
19104 +       if (!dev)
19105 +               goto out;
19106 +       in_dev = in6_dev_get(dev);
19107 +       if (!in_dev)
19108 +               goto out;
19109 +
19110 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
19111 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
19112 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
19113 +                       ret = 1;
19114 +                       break;
19115 +               }
19116 +       }
19117 +       in6_dev_put(in_dev);
19118 +out:
19119 +       return ret;
19120 +}
19121 +
19122 +#endif
19123 +
19124 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19125 +{
19126 +       int ret = 1;
19127 +
19128 +       if (!nxi)
19129 +               goto out;
19130 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
19131 +               goto out;
19132 +#ifdef CONFIG_IPV6
19133 +       ret = 2;
19134 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
19135 +               goto out;
19136 +#endif
19137 +       ret = 0;
19138 +out:
19139 +       vxdprintk(VXD_CBIT(net, 3),
19140 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
19141 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
19142 +       return ret;
19143 +}
19144 +
19145 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
19146 +       struct flowi4 *fl4)
19147 +{
19148 +       struct rtable *rt;
19149 +
19150 +       if (!nxi)
19151 +               return NULL;
19152 +
19153 +       /* FIXME: handle lback only case */
19154 +       if (!NX_IPV4(nxi))
19155 +               return ERR_PTR(-EPERM);
19156 +
19157 +       vxdprintk(VXD_CBIT(net, 4),
19158 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
19159 +               nxi, nxi ? nxi->nx_id : 0,
19160 +               NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
19161 +
19162 +       /* single IP is unconditional */
19163 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
19164 +               (fl4->saddr == INADDR_ANY))
19165 +               fl4->saddr = nxi->v4.ip[0].s_addr;
19166 +
19167 +       if (fl4->saddr == INADDR_ANY) {
19168 +               struct nx_addr_v4 *ptr;
19169 +               __be32 found = 0;
19170 +
19171 +               rt = __ip_route_output_key(net, fl4);
19172 +               if (!IS_ERR(rt)) {
19173 +                       found = fl4->saddr;
19174 +                       ip_rt_put(rt);
19175 +                       vxdprintk(VXD_CBIT(net, 4),
19176 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19177 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
19178 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
19179 +                               goto found;
19180 +               }
19181 +
19182 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
19183 +                       __be32 primary = ptr->ip[0].s_addr;
19184 +                       __be32 mask = ptr->mask.s_addr;
19185 +                       __be32 neta = primary & mask;
19186 +
19187 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
19188 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
19189 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
19190 +                               NIPQUAD(mask), NIPQUAD(neta));
19191 +                       if ((found & mask) != neta)
19192 +                               continue;
19193 +
19194 +                       fl4->saddr = primary;
19195 +                       rt = __ip_route_output_key(net, fl4);
19196 +                       vxdprintk(VXD_CBIT(net, 4),
19197 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19198 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
19199 +                       if (!IS_ERR(rt)) {
19200 +                               found = fl4->saddr;
19201 +                               ip_rt_put(rt);
19202 +                               if (found == primary)
19203 +                                       goto found;
19204 +                       }
19205 +               }
19206 +               /* still no source ip? */
19207 +               found = ipv4_is_loopback(fl4->daddr)
19208 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
19209 +       found:
19210 +               /* assign src ip to flow */
19211 +               fl4->saddr = found;
19212 +
19213 +       } else {
19214 +               if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
19215 +                       return ERR_PTR(-EPERM);
19216 +       }
19217 +
19218 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
19219 +               if (ipv4_is_loopback(fl4->daddr))
19220 +                       fl4->daddr = nxi->v4_lback.s_addr;
19221 +               if (ipv4_is_loopback(fl4->saddr))
19222 +                       fl4->saddr = nxi->v4_lback.s_addr;
19223 +       } else if (ipv4_is_loopback(fl4->daddr) &&
19224 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
19225 +               return ERR_PTR(-EPERM);
19226 +
19227 +       return NULL;
19228 +}
19229 +
19230 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
19231 +
19232 diff -NurpP --minimal linux-3.1.6/kernel/vserver/init.c linux-3.1.6-vs2.3.2.5/kernel/vserver/init.c
19233 --- linux-3.1.6/kernel/vserver/init.c   1970-01-01 01:00:00.000000000 +0100
19234 +++ linux-3.1.6-vs2.3.2.5/kernel/vserver/init.c 2011-10-24 18:53:33.000000000 +0200
19235 @@ -0,0 +1,45 @@
19236 +/*
19237 + *  linux/kernel/init.c
19238 + *
19239 + *  Virtual Server Init
19240 + *
19241 + *  Copyright (C) 2004-2007  Herbert Pötzl
19242 + *
19243 + *  V0.01  basic structure
19244 + *
19245 + */
19246 +
19247 +#include <linux/init.h>
19248 +
19249 +int    vserver_register_sysctl(void);
19250 +void   vserver_unregister_sysctl(void);
19251 +
19252 +
19253 +static int __init init_vserver(void)
19254 +{
19255 +       int ret = 0;
19256 +
19257 +#ifdef CONFIG_VSERVER_DEBUG
19258 +       vserver_register_sysctl();
19259 +#endif
19260 +       return ret;
19261 +}
19262 +
19263 +
19264 +static void __exit exit_vserver(void)
19265 +{
19266 +
19267 +#ifdef CONFIG_VSERVER_DEBUG
19268 +       vserver_unregister_sysctl();
19269 +#endif
19270 +       return;
19271 +}
19272 +
19273 +/* FIXME: GFP_ZONETYPES gone
19274 +long vx_slab[GFP_ZONETYPES]; */
19275 +long vx_area;
19276 +
19277 +
19278 +module_init(init_vserver);
19279 +module_exit(exit_vserver);
19280 +
19281 diff -NurpP --minimal linux-3.1.6/kernel/vserver/inode.c linux-3.1.6-vs2.3.2.5/kernel/vserver/inode.c
19282 --- linux-3.1.6/kernel/vserver/inode.c  1970-01-01 01:00:00.000000000 +0100
19283 +++ linux-3.1.6-vs2.3.2.5/kernel/vserver/inode.c        2011-12-06 23:58:02.000000000 +0100
19284 @@ -0,0 +1,437 @@
19285 +/*
19286 + *  linux/kernel/vserver/inode.c
19287 + *
19288 + *  Virtual Server: File System Support
19289 + *
19290 + *  Copyright (C) 2004-2007  Herbert Pötzl
19291 + *
19292 + *  V0.01  separated from vcontext V0.05
19293 + *  V0.02  moved to tag (instead of xid)
19294 + *
19295 + */
19296 +
19297 +#include <linux/tty.h>
19298 +#include <linux/proc_fs.h>
19299 +#include <linux/devpts_fs.h>
19300 +#include <linux/fs.h>
19301 +#include <linux/file.h>
19302 +#include <linux/mount.h>
19303 +#include <linux/parser.h>
19304 +#include <linux/namei.h>
19305 +#include <linux/vserver/inode.h>
19306 +#include <linux/vserver/inode_cmd.h>
19307 +#include <linux/vs_base.h>
19308 +#include <linux/vs_tag.h>
19309 +
19310 +#include <asm/uaccess.h>
19311 +
19312 +
19313 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19314 +{
19315 +       struct proc_dir_entry *entry;
19316 +
19317 +       if (!in || !in->i_sb)
19318 +               return -ESRCH;
19319 +
19320 +       *flags = IATTR_TAG
19321 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
19322 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
19323 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
19324 +               | (IS_COW(in) ? IATTR_COW : 0);
19325 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
19326 +
19327 +       if (S_ISDIR(in->i_mode))
19328 +               *mask |= IATTR_BARRIER;
19329 +
19330 +       if (IS_TAGGED(in)) {
19331 +               *tag = in->i_tag;
19332 +               *mask |= IATTR_TAG;
19333 +       }
19334 +
19335 +       switch (in->i_sb->s_magic) {
19336 +       case PROC_SUPER_MAGIC:
19337 +               entry = PROC_I(in)->pde;
19338 +
19339 +               /* check for specific inodes? */
19340 +               if (entry)
19341 +                       *mask |= IATTR_FLAGS;
19342 +               if (entry)
19343 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
19344 +               else
19345 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19346 +               break;
19347 +
19348 +       case DEVPTS_SUPER_MAGIC:
19349 +               *tag = in->i_tag;
19350 +               *mask |= IATTR_TAG;
19351 +               break;
19352 +
19353 +       default:
19354 +               break;
19355 +       }
19356 +       return 0;
19357 +}
19358 +
19359 +int vc_get_iattr(void __user *data)
19360 +{
19361 +       struct path path;
19362 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19363 +       int ret;
19364 +
19365 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19366 +               return -EFAULT;
19367 +
19368 +       ret = user_lpath(vc_data.name, &path);
19369 +       if (!ret) {
19370 +               ret = __vc_get_iattr(path.dentry->d_inode,
19371 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19372 +               path_put(&path);
19373 +       }
19374 +       if (ret)
19375 +               return ret;
19376 +
19377 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19378 +               ret = -EFAULT;
19379 +       return ret;
19380 +}
19381 +
19382 +#ifdef CONFIG_COMPAT
19383 +
19384 +int vc_get_iattr_x32(void __user *data)
19385 +{
19386 +       struct path path;
19387 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19388 +       int ret;
19389 +
19390 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19391 +               return -EFAULT;
19392 +
19393 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19394 +       if (!ret) {
19395 +               ret = __vc_get_iattr(path.dentry->d_inode,
19396 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19397 +               path_put(&path);
19398 +       }
19399 +       if (ret)
19400 +               return ret;
19401 +
19402 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19403 +               ret = -EFAULT;
19404 +       return ret;
19405 +}
19406 +
19407 +#endif /* CONFIG_COMPAT */
19408 +
19409 +
19410 +int vc_fget_iattr(uint32_t fd, void __user *data)
19411 +{
19412 +       struct file *filp;
19413 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19414 +       int ret;
19415 +
19416 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19417 +               return -EFAULT;
19418 +
19419 +       filp = fget(fd);
19420 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19421 +               return -EBADF;
19422 +
19423 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
19424 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
19425 +
19426 +       fput(filp);
19427 +
19428 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19429 +               ret = -EFAULT;
19430 +       return ret;
19431 +}
19432 +
19433 +
19434 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19435 +{
19436 +       struct inode *in = de->d_inode;
19437 +       int error = 0, is_proc = 0, has_tag = 0;
19438 +       struct iattr attr = { 0 };
19439 +
19440 +       if (!in || !in->i_sb)
19441 +               return -ESRCH;
19442 +
19443 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19444 +       if ((*mask & IATTR_FLAGS) && !is_proc)
19445 +               return -EINVAL;
19446 +
19447 +       has_tag = IS_TAGGED(in) ||
19448 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
19449 +       if ((*mask & IATTR_TAG) && !has_tag)
19450 +               return -EINVAL;
19451 +
19452 +       mutex_lock(&in->i_mutex);
19453 +       if (*mask & IATTR_TAG) {
19454 +               attr.ia_tag = *tag;
19455 +               attr.ia_valid |= ATTR_TAG;
19456 +       }
19457 +
19458 +       if (*mask & IATTR_FLAGS) {
19459 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
19460 +               unsigned int iflags = PROC_I(in)->vx_flags;
19461 +
19462 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
19463 +                       | (*flags & IATTR_FLAGS);
19464 +               PROC_I(in)->vx_flags = iflags;
19465 +               if (entry)
19466 +                       entry->vx_flags = iflags;
19467 +       }
19468 +
19469 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
19470 +               IATTR_BARRIER | IATTR_COW)) {
19471 +               int iflags = in->i_flags;
19472 +               int vflags = in->i_vflags;
19473 +
19474 +               if (*mask & IATTR_IMMUTABLE) {
19475 +                       if (*flags & IATTR_IMMUTABLE)
19476 +                               iflags |= S_IMMUTABLE;
19477 +                       else
19478 +                               iflags &= ~S_IMMUTABLE;
19479 +               }
19480 +               if (*mask & IATTR_IXUNLINK) {
19481 +                       if (*flags & IATTR_IXUNLINK)
19482 +                               iflags |= S_IXUNLINK;
19483 +                       else
19484 +                               iflags &= ~S_IXUNLINK;
19485 +               }
19486 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
19487 +                       if (*flags & IATTR_BARRIER)
19488 +                               vflags |= V_BARRIER;
19489 +                       else
19490 +                               vflags &= ~V_BARRIER;
19491 +               }
19492 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
19493 +                       if (*flags & IATTR_COW)
19494 +                               vflags |= V_COW;
19495 +                       else
19496 +                               vflags &= ~V_COW;
19497 +               }
19498 +               if (in->i_op && in->i_op->sync_flags) {
19499 +                       error = in->i_op->sync_flags(in, iflags, vflags);
19500 +                       if (error)
19501 +                               goto out;
19502 +               }
19503 +       }
19504 +
19505 +       if (attr.ia_valid) {
19506 +               if (in->i_op && in->i_op->setattr)
19507 +                       error = in->i_op->setattr(de, &attr);
19508 +               else {
19509 +                       error = inode_change_ok(in, &attr);
19510 +                       if (!error) {
19511 +                               setattr_copy(in, &attr);
19512 +                               mark_inode_dirty(in);
19513 +                       }
19514 +               }
19515 +       }
19516 +
19517 +out:
19518 +       mutex_unlock(&in->i_mutex);
19519 +       return error;
19520 +}
19521 +
19522 +int vc_set_iattr(void __user *data)
19523 +{
19524 +       struct path path;
19525 +       struct vcmd_ctx_iattr_v1 vc_data;
19526 +       int ret;
19527 +
19528 +       if (!capable(CAP_LINUX_IMMUTABLE))
19529 +               return -EPERM;
19530 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19531 +               return -EFAULT;
19532 +
19533 +       ret = user_lpath(vc_data.name, &path);
19534 +       if (!ret) {
19535 +               ret = __vc_set_iattr(path.dentry,
19536 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19537 +               path_put(&path);
19538 +       }
19539 +
19540 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19541 +               ret = -EFAULT;
19542 +       return ret;
19543 +}
19544 +
19545 +#ifdef CONFIG_COMPAT
19546 +
19547 +int vc_set_iattr_x32(void __user *data)
19548 +{
19549 +       struct path path;
19550 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
19551 +       int ret;
19552 +
19553 +       if (!capable(CAP_LINUX_IMMUTABLE))
19554 +               return -EPERM;
19555 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19556 +               return -EFAULT;
19557 +
19558 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19559 +       if (!ret) {
19560 +               ret = __vc_set_iattr(path.dentry,
19561 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19562 +               path_put(&path);
19563 +       }
19564 +
19565 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19566 +               ret = -EFAULT;
19567 +       return ret;
19568 +}
19569 +
19570 +#endif /* CONFIG_COMPAT */
19571 +
19572 +int vc_fset_iattr(uint32_t fd, void __user *data)
19573 +{
19574 +       struct file *filp;
19575 +       struct vcmd_ctx_fiattr_v0 vc_data;
19576 +       int ret;
19577 +
19578 +       if (!capable(CAP_LINUX_IMMUTABLE))
19579 +               return -EPERM;
19580 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19581 +               return -EFAULT;
19582 +
19583 +       filp = fget(fd);
19584 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19585 +               return -EBADF;
19586 +
19587 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
19588 +               &vc_data.flags, &vc_data.mask);
19589 +
19590 +       fput(filp);
19591 +
19592 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19593 +               return -EFAULT;
19594 +       return ret;
19595 +}
19596 +
19597 +
19598 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
19599 +
19600 +static match_table_t tokens = {
19601 +       {Opt_notagcheck, "notagcheck"},
19602 +#ifdef CONFIG_PROPAGATE
19603 +       {Opt_notag, "notag"},
19604 +       {Opt_tag, "tag"},
19605 +       {Opt_tagid, "tagid=%u"},
19606 +#endif
19607 +       {Opt_err, NULL}
19608 +};
19609 +
19610 +
19611 +static void __dx_parse_remove(char *string, char *opt)
19612 +{
19613 +       char *p = strstr(string, opt);
19614 +       char *q = p;
19615 +
19616 +       if (p) {
19617 +               while (*q != '\0' && *q != ',')
19618 +                       q++;
19619 +               while (*q)
19620 +                       *p++ = *q++;
19621 +               while (*p)
19622 +                       *p++ = '\0';
19623 +       }
19624 +}
19625 +
19626 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
19627 +                unsigned long *flags)
19628 +{
19629 +       int set = 0;
19630 +       substring_t args[MAX_OPT_ARGS];
19631 +       int token;
19632 +       char *s, *p, *opts;
19633 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
19634 +       int option = 0;
19635 +#endif
19636 +
19637 +       if (!string)
19638 +               return 0;
19639 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
19640 +       if (!s)
19641 +               return 0;
19642 +
19643 +       opts = s;
19644 +       while ((p = strsep(&opts, ",")) != NULL) {
19645 +               token = match_token(p, tokens, args);
19646 +
19647 +               switch (token) {
19648 +#ifdef CONFIG_PROPAGATE
19649 +               case Opt_tag:
19650 +                       if (tag)
19651 +                               *tag = 0;
19652 +                       if (remove)
19653 +                               __dx_parse_remove(s, "tag");
19654 +                       *mnt_flags |= MNT_TAGID;
19655 +                       set |= MNT_TAGID;
19656 +                       break;
19657 +               case Opt_notag:
19658 +                       if (remove)
19659 +                               __dx_parse_remove(s, "notag");
19660 +                       *mnt_flags |= MNT_NOTAG;
19661 +                       set |= MNT_NOTAG;
19662 +                       break;
19663 +               case Opt_tagid:
19664 +                       if (tag && !match_int(args, &option))
19665 +                               *tag = option;
19666 +                       if (remove)
19667 +                               __dx_parse_remove(s, "tagid");
19668 +                       *mnt_flags |= MNT_TAGID;
19669 +                       set |= MNT_TAGID;
19670 +                       break;
19671 +#endif /* CONFIG_PROPAGATE */
19672 +               case Opt_notagcheck:
19673 +                       if (remove)
19674 +                               __dx_parse_remove(s, "notagcheck");
19675 +                       *flags |= MS_NOTAGCHECK;
19676 +                       set |= MS_NOTAGCHECK;
19677 +                       break;
19678 +               }
19679 +               vxdprintk(VXD_CBIT(tag, 7),
19680 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
19681 +                       p, token, option);
19682 +       }
19683 +       if (set)
19684 +               strcpy(string, s);
19685 +       kfree(s);
19686 +       return set;
19687 +}
19688 +
19689 +#ifdef CONFIG_PROPAGATE
19690 +
19691 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
19692 +{
19693 +       tag_t new_tag = 0;
19694 +       struct vfsmount *mnt;
19695 +       int propagate;
19696 +
19697 +       if (!nd)
19698 +               return;
19699 +       mnt = nd->path.mnt;
19700 +       if (!mnt)
19701 +               return;
19702 +
19703 +       propagate = (mnt->mnt_flags & MNT_TAGID);
19704 +       if (propagate)
19705 +               new_tag = mnt->mnt_tag;
19706 +
19707 +       vxdprintk(VXD_CBIT(tag, 7),
19708 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
19709 +               inode, inode->i_ino, inode->i_tag,
19710 +               new_tag, (propagate) ? 1 : 0);
19711 +
19712 +       if (propagate)
19713 +               inode->i_tag = new_tag;
19714 +}
19715 +
19716 +#include <linux/module.h>
19717 +
19718 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
19719 +
19720 +#endif /* CONFIG_PROPAGATE */
19721 +
19722 diff -NurpP --minimal linux-3.1.6/kernel/vserver/limit.c linux-3.1.6-vs2.3.2.5/kernel/vserver/limit.c
19723 --- linux-3.1.6/kernel/vserver/limit.c  1970-01-01 01:00:00.000000000 +0100
19724 +++ linux-3.1.6-vs2.3.2.5/kernel/vserver/limit.c        2011-12-07 05:08:10.000000000 +0100
19725 @@ -0,0 +1,330 @@
19726 +/*
19727 + *  linux/kernel/vserver/limit.c
19728 + *
19729 + *  Virtual Server: Context Limits
19730 + *
19731 + *  Copyright (C) 2004-2010  Herbert Pötzl
19732 + *
19733 + *  V0.01  broken out from vcontext V0.05
19734 + *  V0.02  changed vcmds to vxi arg
19735 + *  V0.03  added memory cgroup support
19736 + *
19737 + */
19738 +
19739 +#include <linux/sched.h>
19740 +#include <linux/module.h>
19741 +#include <linux/memcontrol.h>
19742 +#include <linux/res_counter.h>
19743 +#include <linux/vs_limit.h>
19744 +#include <linux/vserver/limit.h>
19745 +#include <linux/vserver/limit_cmd.h>
19746 +
19747 +#include <asm/uaccess.h>
19748 +
19749 +
19750 +const char *vlimit_name[NUM_LIMITS] = {
19751 +       [RLIMIT_CPU]            = "CPU",
19752 +       [RLIMIT_NPROC]          = "NPROC",
19753 +       [RLIMIT_NOFILE]         = "NOFILE",
19754 +       [RLIMIT_LOCKS]          = "LOCKS",
19755 +       [RLIMIT_SIGPENDING]     = "SIGP",
19756 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
19757 +
19758 +       [VLIMIT_NSOCK]          = "NSOCK",
19759 +       [VLIMIT_OPENFD]         = "OPENFD",
19760 +       [VLIMIT_SHMEM]          = "SHMEM",
19761 +       [VLIMIT_DENTRY]         = "DENTRY",
19762 +};
19763 +
19764 +EXPORT_SYMBOL_GPL(vlimit_name);
19765 +
19766 +#define MASK_ENTRY(x)  (1 << (x))
19767 +
19768 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
19769 +               /* minimum */
19770 +       0
19771 +       ,       /* softlimit */
19772 +       0
19773 +       ,       /* maximum */
19774 +       MASK_ENTRY( RLIMIT_NPROC        ) |
19775 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
19776 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
19777 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
19778 +
19779 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
19780 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
19781 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
19782 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
19783 +       0
19784 +};
19785 +               /* accounting only */
19786 +uint32_t account_mask =
19787 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
19788 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
19789 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
19790 +       0;
19791 +
19792 +
19793 +static int is_valid_vlimit(int id)
19794 +{
19795 +       uint32_t mask = vlimit_mask.minimum |
19796 +               vlimit_mask.softlimit | vlimit_mask.maximum;
19797 +       return mask & (1 << id);
19798 +}
19799 +
19800 +static int is_accounted_vlimit(int id)
19801 +{
19802 +       if (is_valid_vlimit(id))
19803 +               return 1;
19804 +       return account_mask & (1 << id);
19805 +}
19806 +
19807 +
19808 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
19809 +{
19810 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
19811 +       return VX_VLIM(limit);
19812 +}
19813 +
19814 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
19815 +{
19816 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
19817 +       return VX_VLIM(limit);
19818 +}
19819 +
19820 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
19821 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
19822 +{
19823 +       if (!is_valid_vlimit(id))
19824 +               return -EINVAL;
19825 +
19826 +       if (minimum)
19827 +               *minimum = CRLIM_UNSET;
19828 +       if (softlimit)
19829 +               *softlimit = vc_get_soft(vxi, id);
19830 +       if (maximum)
19831 +               *maximum = vc_get_hard(vxi, id);
19832 +       return 0;
19833 +}
19834 +
19835 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
19836 +{
19837 +       struct vcmd_ctx_rlimit_v0 vc_data;
19838 +       int ret;
19839 +
19840 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19841 +               return -EFAULT;
19842 +
19843 +       ret = do_get_rlimit(vxi, vc_data.id,
19844 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19845 +       if (ret)
19846 +               return ret;
19847 +
19848 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19849 +               return -EFAULT;
19850 +       return 0;
19851 +}
19852 +
19853 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
19854 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
19855 +{
19856 +       if (!is_valid_vlimit(id))
19857 +               return -EINVAL;
19858 +
19859 +       if (maximum != CRLIM_KEEP)
19860 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
19861 +       if (softlimit != CRLIM_KEEP)
19862 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
19863 +
19864 +       /* clamp soft limit */
19865 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
19866 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
19867 +
19868 +       return 0;
19869 +}
19870 +
19871 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
19872 +{
19873 +       struct vcmd_ctx_rlimit_v0 vc_data;
19874 +
19875 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19876 +               return -EFAULT;
19877 +
19878 +       return do_set_rlimit(vxi, vc_data.id,
19879 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19880 +}
19881 +
19882 +#ifdef CONFIG_IA32_EMULATION
19883 +
19884 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
19885 +{
19886 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19887 +
19888 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19889 +               return -EFAULT;
19890 +
19891 +       return do_set_rlimit(vxi, vc_data.id,
19892 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19893 +}
19894 +
19895 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
19896 +{
19897 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19898 +       int ret;
19899 +
19900 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19901 +               return -EFAULT;
19902 +
19903 +       ret = do_get_rlimit(vxi, vc_data.id,
19904 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19905 +       if (ret)
19906 +               return ret;
19907 +
19908 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19909 +               return -EFAULT;
19910 +       return 0;
19911 +}
19912 +
19913 +#endif /* CONFIG_IA32_EMULATION */
19914 +
19915 +
19916 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
19917 +{
19918 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
19919 +               return -EFAULT;
19920 +       return 0;
19921 +}
19922 +
19923 +
19924 +static inline void vx_reset_hits(struct _vx_limit *limit)
19925 +{
19926 +       int lim;
19927 +
19928 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19929 +               atomic_set(&__rlim_lhit(limit, lim), 0);
19930 +       }
19931 +}
19932 +
19933 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
19934 +{
19935 +       vx_reset_hits(&vxi->limit);
19936 +       return 0;
19937 +}
19938 +
19939 +static inline void vx_reset_minmax(struct _vx_limit *limit)
19940 +{
19941 +       rlim_t value;
19942 +       int lim;
19943 +
19944 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19945 +               value = __rlim_get(limit, lim);
19946 +               __rlim_rmax(limit, lim) = value;
19947 +               __rlim_rmin(limit, lim) = value;
19948 +       }
19949 +}
19950 +
19951 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
19952 +{
19953 +       vx_reset_minmax(&vxi->limit);
19954 +       return 0;
19955 +}
19956 +
19957 +
19958 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
19959 +{
19960 +       struct vcmd_rlimit_stat_v0 vc_data;
19961 +       struct _vx_limit *limit = &vxi->limit;
19962 +       int id;
19963 +
19964 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19965 +               return -EFAULT;
19966 +
19967 +       id = vc_data.id;
19968 +       if (!is_accounted_vlimit(id))
19969 +               return -EINVAL;
19970 +
19971 +       vx_limit_fixup(limit, id);
19972 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
19973 +       vc_data.value = __rlim_get(limit, id);
19974 +       vc_data.minimum = __rlim_rmin(limit, id);
19975 +       vc_data.maximum = __rlim_rmax(limit, id);
19976 +
19977 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19978 +               return -EFAULT;
19979 +       return 0;
19980 +}
19981 +
19982 +
19983 +void vx_vsi_meminfo(struct sysinfo *val)
19984 +{
19985 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
19986 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
19987 +       u64 res_limit, res_usage;
19988 +
19989 +       if (!mcg)
19990 +               return;
19991 +
19992 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19993 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19994 +
19995 +       if (res_limit != RESOURCE_MAX)
19996 +               val->totalram = (res_limit >> PAGE_SHIFT);
19997 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
19998 +       val->bufferram = 0;
19999 +       val->totalhigh = 0;
20000 +       val->freehigh = 0;
20001 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
20002 +       return;
20003 +}
20004 +
20005 +void vx_vsi_swapinfo(struct sysinfo *val)
20006 +{
20007 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20008 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
20009 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20010 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
20011 +       s64 swap_limit, swap_usage;
20012 +
20013 +       if (!mcg)
20014 +               return;
20015 +
20016 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
20017 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
20018 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
20019 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
20020 +
20021 +       /* memory unlimited */
20022 +       if (res_limit == RESOURCE_MAX)
20023 +               return;
20024 +
20025 +       swap_limit = memsw_limit - res_limit;
20026 +       /* we have a swap limit? */
20027 +       if (memsw_limit != RESOURCE_MAX)
20028 +               val->totalswap = swap_limit >> PAGE_SHIFT;
20029 +
20030 +       /* calculate swap part */
20031 +       swap_usage = (memsw_usage > res_usage) ?
20032 +               memsw_usage - res_usage : 0;
20033 +
20034 +       /* total shown minus usage gives free swap */
20035 +       val->freeswap = (swap_usage < swap_limit) ?
20036 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
20037 +#else  /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20038 +       val->totalswap = 0;
20039 +       val->freeswap = 0;
20040 +#endif /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20041 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
20042 +       return;
20043 +}
20044 +
20045 +long vx_vsi_cached(struct sysinfo *val)
20046 +{
20047 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20048 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20049 +
20050 +       return mem_cgroup_stat_read_cache(mcg);
20051 +#else
20052 +       return 0;
20053 +#endif
20054 +}
20055 +
20056 diff -NurpP --minimal linux-3.1.6/kernel/vserver/limit_init.h linux-3.1.6-vs2.3.2.5/kernel/vserver/limit_init.h
20057 --- linux-3.1.6/kernel/vserver/limit_init.h     1970-01-01 01:00:00.000000000 +0100
20058 +++ linux-3.1.6-vs2.3.2.5/kernel/vserver/limit_init.h   2011-10-24 18:53:33.000000000 +0200
20059 @@ -0,0 +1,31 @@
20060 +
20061 +
20062 +static inline void vx_info_init_limit(struct _vx_limit *limit)
20063 +{
20064 +       int lim;
20065 +
20066 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20067 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
20068 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
20069 +               __rlim_set(limit, lim, 0);
20070 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20071 +               __rlim_rmin(limit, lim) = 0;
20072 +               __rlim_rmax(limit, lim) = 0;
20073 +       }
20074 +}
20075 +
20076 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
20077 +{
20078 +       rlim_t value;
20079 +       int lim;
20080 +
20081 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20082 +               if ((1 << lim) & VLIM_NOCHECK)
20083 +                       continue;
20084 +               value = __rlim_get(limit, lim);
20085 +               vxwprintk_xid(value,
20086 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
20087 +                       limit, vlimit_name[lim], lim, (long)value);
20088 +       }
20089 +}
20090 +
20091 diff -NurpP --minimal linux-3.1.6/kernel/vserver/limit_proc.h linux-3.1.6-vs2.3.2.5/kernel/vserver/limit_proc.h
20092 --- linux-3.1.6/kernel/vserver/limit_proc.h     1970-01-01 01:00:00.000000000 +0100
20093 +++ linux-3.1.6-vs2.3.2.5/kernel/vserver/limit_proc.h   2011-10-24 18:53:33.000000000 +0200
20094 @@ -0,0 +1,57 @@
20095 +#ifndef _VX_LIMIT_PROC_H
20096 +#define _VX_LIMIT_PROC_H
20097 +
20098 +#include <linux/vserver/limit_int.h>
20099 +
20100 +
20101 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
20102 +#define VX_LIMIT_TOP   \
20103 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
20104 +
20105 +#define VX_LIMIT_ARG(r)                                \
20106 +       (unsigned long)__rlim_get(limit, r),    \
20107 +       (unsigned long)__rlim_rmin(limit, r),   \
20108 +       (unsigned long)__rlim_rmax(limit, r),   \
20109 +       VX_VLIM(__rlim_soft(limit, r)),         \
20110 +       VX_VLIM(__rlim_hard(limit, r)),         \
20111 +       atomic_read(&__rlim_lhit(limit, r))
20112 +
20113 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
20114 +{
20115 +       vx_limit_fixup(limit, -1);
20116 +       return sprintf(buffer, VX_LIMIT_TOP
20117 +               "PROC"  VX_LIMIT_FMT
20118 +               "VM"    VX_LIMIT_FMT
20119 +               "VML"   VX_LIMIT_FMT
20120 +               "RSS"   VX_LIMIT_FMT
20121 +               "ANON"  VX_LIMIT_FMT
20122 +               "RMAP"  VX_LIMIT_FMT
20123 +               "FILES" VX_LIMIT_FMT
20124 +               "OFD"   VX_LIMIT_FMT
20125 +               "LOCKS" VX_LIMIT_FMT
20126 +               "SOCK"  VX_LIMIT_FMT
20127 +               "MSGQ"  VX_LIMIT_FMT
20128 +               "SHM"   VX_LIMIT_FMT
20129 +               "SEMA"  VX_LIMIT_FMT
20130 +               "SEMS"  VX_LIMIT_FMT
20131 +               "DENT"  VX_LIMIT_FMT,
20132 +               VX_LIMIT_ARG(RLIMIT_NPROC),
20133 +               VX_LIMIT_ARG(RLIMIT_AS),
20134 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
20135 +               VX_LIMIT_ARG(RLIMIT_RSS),
20136 +               VX_LIMIT_ARG(VLIMIT_ANON),
20137 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
20138 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
20139 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
20140 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
20141 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
20142 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
20143 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
20144 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
20145 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
20146 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
20147 +}
20148 +
20149 +#endif /* _VX_LIMIT_PROC_H */
20150 +
20151 +
20152 diff -NurpP --minimal linux-3.1.6/kernel/vserver/network.c linux-3.1.6-vs2.3.2.5/kernel/vserver/network.c
20153 --- linux-3.1.6/kernel/vserver/network.c        1970-01-01 01:00:00.000000000 +0100
20154 +++ linux-3.1.6-vs2.3.2.5/kernel/vserver/network.c      2011-10-24 18:53:33.000000000 +0200
20155 @@ -0,0 +1,912 @@
20156 +/*
20157 + *  linux/kernel/vserver/network.c
20158 + *
20159 + *  Virtual Server: Network Support
20160 + *
20161 + *  Copyright (C) 2003-2007  Herbert Pötzl
20162 + *
20163 + *  V0.01  broken out from vcontext V0.05
20164 + *  V0.02  cleaned up implementation
20165 + *  V0.03  added equiv nx commands
20166 + *  V0.04  switch to RCU based hash
20167 + *  V0.05  and back to locking again
20168 + *  V0.06  changed vcmds to nxi arg
20169 + *  V0.07  have __create claim() the nxi
20170 + *
20171 + */
20172 +
20173 +#include <linux/err.h>
20174 +#include <linux/slab.h>
20175 +#include <linux/rcupdate.h>
20176 +
20177 +#include <linux/vs_network.h>
20178 +#include <linux/vs_pid.h>
20179 +#include <linux/vserver/network_cmd.h>
20180 +
20181 +
20182 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
20183 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
20184 +
20185 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
20186 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
20187 +
20188 +
20189 +static int __init init_network(void)
20190 +{
20191 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
20192 +               sizeof(struct nx_addr_v4), 0,
20193 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20194 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
20195 +               sizeof(struct nx_addr_v6), 0,
20196 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20197 +       return 0;
20198 +}
20199 +
20200 +
20201 +/*     __alloc_nx_addr_v4()                                    */
20202 +
20203 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
20204 +{
20205 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
20206 +               nx_addr_v4_cachep, GFP_KERNEL);
20207 +
20208 +       if (!IS_ERR(nxa))
20209 +               memset(nxa, 0, sizeof(*nxa));
20210 +       return nxa;
20211 +}
20212 +
20213 +/*     __dealloc_nx_addr_v4()                                  */
20214 +
20215 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
20216 +{
20217 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
20218 +}
20219 +
20220 +/*     __dealloc_nx_addr_v4_all()                              */
20221 +
20222 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
20223 +{
20224 +       while (nxa) {
20225 +               struct nx_addr_v4 *next = nxa->next;
20226 +
20227 +               __dealloc_nx_addr_v4(nxa);
20228 +               nxa = next;
20229 +       }
20230 +}
20231 +
20232 +
20233 +#ifdef CONFIG_IPV6
20234 +
20235 +/*     __alloc_nx_addr_v6()                                    */
20236 +
20237 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
20238 +{
20239 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
20240 +               nx_addr_v6_cachep, GFP_KERNEL);
20241 +
20242 +       if (!IS_ERR(nxa))
20243 +               memset(nxa, 0, sizeof(*nxa));
20244 +       return nxa;
20245 +}
20246 +
20247 +/*     __dealloc_nx_addr_v6()                                  */
20248 +
20249 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
20250 +{
20251 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
20252 +}
20253 +
20254 +/*     __dealloc_nx_addr_v6_all()                              */
20255 +
20256 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
20257 +{
20258 +       while (nxa) {
20259 +               struct nx_addr_v6 *next = nxa->next;
20260 +
20261 +               __dealloc_nx_addr_v6(nxa);
20262 +               nxa = next;
20263 +       }
20264 +}
20265 +
20266 +#endif /* CONFIG_IPV6 */
20267 +
20268 +/*     __alloc_nx_info()
20269 +
20270 +       * allocate an initialized nx_info struct
20271 +       * doesn't make it visible (hash)                        */
20272 +
20273 +static struct nx_info *__alloc_nx_info(nid_t nid)
20274 +{
20275 +       struct nx_info *new = NULL;
20276 +
20277 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
20278 +
20279 +       /* would this benefit from a slab cache? */
20280 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
20281 +       if (!new)
20282 +               return 0;
20283 +
20284 +       memset(new, 0, sizeof(struct nx_info));
20285 +       new->nx_id = nid;
20286 +       INIT_HLIST_NODE(&new->nx_hlist);
20287 +       atomic_set(&new->nx_usecnt, 0);
20288 +       atomic_set(&new->nx_tasks, 0);
20289 +       new->nx_state = 0;
20290 +
20291 +       new->nx_flags = NXF_INIT_SET;
20292 +
20293 +       /* rest of init goes here */
20294 +
20295 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
20296 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
20297 +
20298 +       vxdprintk(VXD_CBIT(nid, 0),
20299 +               "alloc_nx_info(%d) = %p", nid, new);
20300 +       atomic_inc(&nx_global_ctotal);
20301 +       return new;
20302 +}
20303 +
20304 +/*     __dealloc_nx_info()
20305 +
20306 +       * final disposal of nx_info                             */
20307 +
20308 +static void __dealloc_nx_info(struct nx_info *nxi)
20309 +{
20310 +       vxdprintk(VXD_CBIT(nid, 0),
20311 +               "dealloc_nx_info(%p)", nxi);
20312 +
20313 +       nxi->nx_hlist.next = LIST_POISON1;
20314 +       nxi->nx_id = -1;
20315 +
20316 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20317 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20318 +
20319 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
20320 +
20321 +       nxi->nx_state |= NXS_RELEASED;
20322 +       kfree(nxi);
20323 +       atomic_dec(&nx_global_ctotal);
20324 +}
20325 +
20326 +static void __shutdown_nx_info(struct nx_info *nxi)
20327 +{
20328 +       nxi->nx_state |= NXS_SHUTDOWN;
20329 +       vs_net_change(nxi, VSC_NETDOWN);
20330 +}
20331 +
20332 +/*     exported stuff                                          */
20333 +
20334 +void free_nx_info(struct nx_info *nxi)
20335 +{
20336 +       /* context shutdown is mandatory */
20337 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
20338 +
20339 +       /* context must not be hashed */
20340 +       BUG_ON(nxi->nx_state & NXS_HASHED);
20341 +
20342 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20343 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20344 +
20345 +       __dealloc_nx_info(nxi);
20346 +}
20347 +
20348 +
20349 +void __nx_set_lback(struct nx_info *nxi)
20350 +{
20351 +       int nid = nxi->nx_id;
20352 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
20353 +
20354 +       nxi->v4_lback.s_addr = lback;
20355 +}
20356 +
20357 +extern int __nx_inet_add_lback(__be32 addr);
20358 +extern int __nx_inet_del_lback(__be32 addr);
20359 +
20360 +
20361 +/*     hash table for nx_info hash */
20362 +
20363 +#define NX_HASH_SIZE   13
20364 +
20365 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
20366 +
20367 +static DEFINE_SPINLOCK(nx_info_hash_lock);
20368 +
20369 +
20370 +static inline unsigned int __hashval(nid_t nid)
20371 +{
20372 +       return (nid % NX_HASH_SIZE);
20373 +}
20374 +
20375 +
20376 +
20377 +/*     __hash_nx_info()
20378 +
20379 +       * add the nxi to the global hash table
20380 +       * requires the hash_lock to be held                     */
20381 +
20382 +static inline void __hash_nx_info(struct nx_info *nxi)
20383 +{
20384 +       struct hlist_head *head;
20385 +
20386 +       vxd_assert_lock(&nx_info_hash_lock);
20387 +       vxdprintk(VXD_CBIT(nid, 4),
20388 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
20389 +
20390 +       /* context must not be hashed */
20391 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
20392 +
20393 +       nxi->nx_state |= NXS_HASHED;
20394 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
20395 +       hlist_add_head(&nxi->nx_hlist, head);
20396 +       atomic_inc(&nx_global_cactive);
20397 +}
20398 +
20399 +/*     __unhash_nx_info()
20400 +
20401 +       * remove the nxi from the global hash table
20402 +       * requires the hash_lock to be held                     */
20403 +
20404 +static inline void __unhash_nx_info(struct nx_info *nxi)
20405 +{
20406 +       vxd_assert_lock(&nx_info_hash_lock);
20407 +       vxdprintk(VXD_CBIT(nid, 4),
20408 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
20409 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
20410 +
20411 +       /* context must be hashed */
20412 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
20413 +       /* but without tasks */
20414 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20415 +
20416 +       nxi->nx_state &= ~NXS_HASHED;
20417 +       hlist_del(&nxi->nx_hlist);
20418 +       atomic_dec(&nx_global_cactive);
20419 +}
20420 +
20421 +
20422 +/*     __lookup_nx_info()
20423 +
20424 +       * requires the hash_lock to be held
20425 +       * doesn't increment the nx_refcnt                       */
20426 +
20427 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
20428 +{
20429 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
20430 +       struct hlist_node *pos;
20431 +       struct nx_info *nxi;
20432 +
20433 +       vxd_assert_lock(&nx_info_hash_lock);
20434 +       hlist_for_each(pos, head) {
20435 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20436 +
20437 +               if (nxi->nx_id == nid)
20438 +                       goto found;
20439 +       }
20440 +       nxi = NULL;
20441 +found:
20442 +       vxdprintk(VXD_CBIT(nid, 0),
20443 +               "__lookup_nx_info(#%u): %p[#%u]",
20444 +               nid, nxi, nxi ? nxi->nx_id : 0);
20445 +       return nxi;
20446 +}
20447 +
20448 +
20449 +/*     __create_nx_info()
20450 +
20451 +       * create the requested context
20452 +       * get(), claim() and hash it                            */
20453 +
20454 +static struct nx_info *__create_nx_info(int id)
20455 +{
20456 +       struct nx_info *new, *nxi = NULL;
20457 +
20458 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
20459 +
20460 +       if (!(new = __alloc_nx_info(id)))
20461 +               return ERR_PTR(-ENOMEM);
20462 +
20463 +       /* required to make dynamic xids unique */
20464 +       spin_lock(&nx_info_hash_lock);
20465 +
20466 +       /* static context requested */
20467 +       if ((nxi = __lookup_nx_info(id))) {
20468 +               vxdprintk(VXD_CBIT(nid, 0),
20469 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
20470 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20471 +                       nxi = ERR_PTR(-EBUSY);
20472 +               else
20473 +                       nxi = ERR_PTR(-EEXIST);
20474 +               goto out_unlock;
20475 +       }
20476 +       /* new context */
20477 +       vxdprintk(VXD_CBIT(nid, 0),
20478 +               "create_nx_info(%d) = %p (new)", id, new);
20479 +       claim_nx_info(new, NULL);
20480 +       __nx_set_lback(new);
20481 +       __hash_nx_info(get_nx_info(new));
20482 +       nxi = new, new = NULL;
20483 +
20484 +out_unlock:
20485 +       spin_unlock(&nx_info_hash_lock);
20486 +       if (new)
20487 +               __dealloc_nx_info(new);
20488 +       return nxi;
20489 +}
20490 +
20491 +
20492 +
20493 +/*     exported stuff                                          */
20494 +
20495 +
20496 +void unhash_nx_info(struct nx_info *nxi)
20497 +{
20498 +       __shutdown_nx_info(nxi);
20499 +       spin_lock(&nx_info_hash_lock);
20500 +       __unhash_nx_info(nxi);
20501 +       spin_unlock(&nx_info_hash_lock);
20502 +}
20503 +
20504 +/*     lookup_nx_info()
20505 +
20506 +       * search for a nx_info and get() it
20507 +       * negative id means current                             */
20508 +
20509 +struct nx_info *lookup_nx_info(int id)
20510 +{
20511 +       struct nx_info *nxi = NULL;
20512 +
20513 +       if (id < 0) {
20514 +               nxi = get_nx_info(current_nx_info());
20515 +       } else if (id > 1) {
20516 +               spin_lock(&nx_info_hash_lock);
20517 +               nxi = get_nx_info(__lookup_nx_info(id));
20518 +               spin_unlock(&nx_info_hash_lock);
20519 +       }
20520 +       return nxi;
20521 +}
20522 +
20523 +/*     nid_is_hashed()
20524 +
20525 +       * verify that nid is still hashed                       */
20526 +
20527 +int nid_is_hashed(nid_t nid)
20528 +{
20529 +       int hashed;
20530 +
20531 +       spin_lock(&nx_info_hash_lock);
20532 +       hashed = (__lookup_nx_info(nid) != NULL);
20533 +       spin_unlock(&nx_info_hash_lock);
20534 +       return hashed;
20535 +}
20536 +
20537 +
20538 +#ifdef CONFIG_PROC_FS
20539 +
20540 +/*     get_nid_list()
20541 +
20542 +       * get a subset of hashed nids for proc
20543 +       * assumes size is at least one                          */
20544 +
20545 +int get_nid_list(int index, unsigned int *nids, int size)
20546 +{
20547 +       int hindex, nr_nids = 0;
20548 +
20549 +       /* only show current and children */
20550 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
20551 +               if (index > 0)
20552 +                       return 0;
20553 +               nids[nr_nids] = nx_current_nid();
20554 +               return 1;
20555 +       }
20556 +
20557 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
20558 +               struct hlist_head *head = &nx_info_hash[hindex];
20559 +               struct hlist_node *pos;
20560 +
20561 +               spin_lock(&nx_info_hash_lock);
20562 +               hlist_for_each(pos, head) {
20563 +                       struct nx_info *nxi;
20564 +
20565 +                       if (--index > 0)
20566 +                               continue;
20567 +
20568 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20569 +                       nids[nr_nids] = nxi->nx_id;
20570 +                       if (++nr_nids >= size) {
20571 +                               spin_unlock(&nx_info_hash_lock);
20572 +                               goto out;
20573 +                       }
20574 +               }
20575 +               /* keep the lock time short */
20576 +               spin_unlock(&nx_info_hash_lock);
20577 +       }
20578 +out:
20579 +       return nr_nids;
20580 +}
20581 +#endif
20582 +
20583 +
20584 +/*
20585 + *     migrate task to new network
20586 + *     gets nxi, puts old_nxi on change
20587 + */
20588 +
20589 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
20590 +{
20591 +       struct nx_info *old_nxi;
20592 +       int ret = 0;
20593 +
20594 +       if (!p || !nxi)
20595 +               BUG();
20596 +
20597 +       vxdprintk(VXD_CBIT(nid, 5),
20598 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
20599 +               p, nxi, nxi->nx_id,
20600 +               atomic_read(&nxi->nx_usecnt),
20601 +               atomic_read(&nxi->nx_tasks));
20602 +
20603 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
20604 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20605 +               return -EACCES;
20606 +
20607 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
20608 +               return -EFAULT;
20609 +
20610 +       /* maybe disallow this completely? */
20611 +       old_nxi = task_get_nx_info(p);
20612 +       if (old_nxi == nxi)
20613 +               goto out;
20614 +
20615 +       task_lock(p);
20616 +       if (old_nxi)
20617 +               clr_nx_info(&p->nx_info);
20618 +       claim_nx_info(nxi, p);
20619 +       set_nx_info(&p->nx_info, nxi);
20620 +       p->nid = nxi->nx_id;
20621 +       task_unlock(p);
20622 +
20623 +       vxdprintk(VXD_CBIT(nid, 5),
20624 +               "moved task %p into nxi:%p[#%d]",
20625 +               p, nxi, nxi->nx_id);
20626 +
20627 +       if (old_nxi)
20628 +               release_nx_info(old_nxi, p);
20629 +       ret = 0;
20630 +out:
20631 +       put_nx_info(old_nxi);
20632 +       return ret;
20633 +}
20634 +
20635 +
20636 +void nx_set_persistent(struct nx_info *nxi)
20637 +{
20638 +       vxdprintk(VXD_CBIT(nid, 6),
20639 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
20640 +
20641 +       get_nx_info(nxi);
20642 +       claim_nx_info(nxi, NULL);
20643 +}
20644 +
20645 +void nx_clear_persistent(struct nx_info *nxi)
20646 +{
20647 +       vxdprintk(VXD_CBIT(nid, 6),
20648 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
20649 +
20650 +       release_nx_info(nxi, NULL);
20651 +       put_nx_info(nxi);
20652 +}
20653 +
20654 +void nx_update_persistent(struct nx_info *nxi)
20655 +{
20656 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
20657 +               nx_set_persistent(nxi);
20658 +       else
20659 +               nx_clear_persistent(nxi);
20660 +}
20661 +
20662 +/* vserver syscall commands below here */
20663 +
20664 +/* taks nid and nx_info functions */
20665 +
20666 +#include <asm/uaccess.h>
20667 +
20668 +
20669 +int vc_task_nid(uint32_t id)
20670 +{
20671 +       nid_t nid;
20672 +
20673 +       if (id) {
20674 +               struct task_struct *tsk;
20675 +
20676 +               rcu_read_lock();
20677 +               tsk = find_task_by_real_pid(id);
20678 +               nid = (tsk) ? tsk->nid : -ESRCH;
20679 +               rcu_read_unlock();
20680 +       } else
20681 +               nid = nx_current_nid();
20682 +       return nid;
20683 +}
20684 +
20685 +
20686 +int vc_nx_info(struct nx_info *nxi, void __user *data)
20687 +{
20688 +       struct vcmd_nx_info_v0 vc_data;
20689 +
20690 +       vc_data.nid = nxi->nx_id;
20691 +
20692 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20693 +               return -EFAULT;
20694 +       return 0;
20695 +}
20696 +
20697 +
20698 +/* network functions */
20699 +
20700 +int vc_net_create(uint32_t nid, void __user *data)
20701 +{
20702 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
20703 +       struct nx_info *new_nxi;
20704 +       int ret;
20705 +
20706 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20707 +               return -EFAULT;
20708 +
20709 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
20710 +               return -EINVAL;
20711 +
20712 +       new_nxi = __create_nx_info(nid);
20713 +       if (IS_ERR(new_nxi))
20714 +               return PTR_ERR(new_nxi);
20715 +
20716 +       /* initial flags */
20717 +       new_nxi->nx_flags = vc_data.flagword;
20718 +
20719 +       ret = -ENOEXEC;
20720 +       if (vs_net_change(new_nxi, VSC_NETUP))
20721 +               goto out;
20722 +
20723 +       ret = nx_migrate_task(current, new_nxi);
20724 +       if (ret)
20725 +               goto out;
20726 +
20727 +       /* return context id on success */
20728 +       ret = new_nxi->nx_id;
20729 +
20730 +       /* get a reference for persistent contexts */
20731 +       if ((vc_data.flagword & NXF_PERSISTENT))
20732 +               nx_set_persistent(new_nxi);
20733 +out:
20734 +       release_nx_info(new_nxi, NULL);
20735 +       put_nx_info(new_nxi);
20736 +       return ret;
20737 +}
20738 +
20739 +
20740 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
20741 +{
20742 +       return nx_migrate_task(current, nxi);
20743 +}
20744 +
20745 +
20746 +
20747 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20748 +       uint16_t type, uint16_t flags)
20749 +{
20750 +       struct nx_addr_v4 *nxa = &nxi->v4;
20751 +
20752 +       if (NX_IPV4(nxi)) {
20753 +               /* locate last entry */
20754 +               for (; nxa->next; nxa = nxa->next);
20755 +               nxa->next = __alloc_nx_addr_v4();
20756 +               nxa = nxa->next;
20757 +
20758 +               if (IS_ERR(nxa))
20759 +                       return PTR_ERR(nxa);
20760 +       }
20761 +
20762 +       if (nxi->v4.next)
20763 +               /* remove single ip for ip list */
20764 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
20765 +
20766 +       nxa->ip[0].s_addr = ip;
20767 +       nxa->ip[1].s_addr = ip2;
20768 +       nxa->mask.s_addr = mask;
20769 +       nxa->type = type;
20770 +       nxa->flags = flags;
20771 +       return 0;
20772 +}
20773 +
20774 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20775 +       uint16_t type, uint16_t flags)
20776 +{
20777 +       struct nx_addr_v4 *nxa = &nxi->v4;
20778 +
20779 +       switch (type) {
20780 +/*     case NXA_TYPE_ADDR:
20781 +               break;          */
20782 +
20783 +       case NXA_TYPE_ANY:
20784 +               __dealloc_nx_addr_v4_all(xchg(&nxa->next, NULL));
20785 +               memset(nxa, 0, sizeof(*nxa));
20786 +               break;
20787 +
20788 +       default:
20789 +               return -EINVAL;
20790 +       }
20791 +       return 0;
20792 +}
20793 +
20794 +
20795 +int vc_net_add(struct nx_info *nxi, void __user *data)
20796 +{
20797 +       struct vcmd_net_addr_v0 vc_data;
20798 +       int index, ret = 0;
20799 +
20800 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20801 +               return -EFAULT;
20802 +
20803 +       switch (vc_data.type) {
20804 +       case NXA_TYPE_IPV4:
20805 +               if ((vc_data.count < 1) || (vc_data.count > 4))
20806 +                       return -EINVAL;
20807 +
20808 +               index = 0;
20809 +               while (index < vc_data.count) {
20810 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
20811 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
20812 +                       if (ret)
20813 +                               return ret;
20814 +                       index++;
20815 +               }
20816 +               ret = index;
20817 +               break;
20818 +
20819 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
20820 +               nxi->v4_bcast = vc_data.ip[0];
20821 +               ret = 1;
20822 +               break;
20823 +
20824 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
20825 +               nxi->v4_lback = vc_data.ip[0];
20826 +               ret = 1;
20827 +               break;
20828 +
20829 +       default:
20830 +               ret = -EINVAL;
20831 +               break;
20832 +       }
20833 +       return ret;
20834 +}
20835 +
20836 +int vc_net_remove(struct nx_info *nxi, void __user *data)
20837 +{
20838 +       struct vcmd_net_addr_v0 vc_data;
20839 +
20840 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20841 +               return -EFAULT;
20842 +
20843 +       switch (vc_data.type) {
20844 +       case NXA_TYPE_ANY:
20845 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
20846 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
20847 +               break;
20848 +
20849 +       default:
20850 +               return -EINVAL;
20851 +       }
20852 +       return 0;
20853 +}
20854 +
20855 +
20856 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
20857 +{
20858 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20859 +
20860 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20861 +               return -EFAULT;
20862 +
20863 +       switch (vc_data.type) {
20864 +       case NXA_TYPE_ADDR:
20865 +       case NXA_TYPE_MASK:
20866 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
20867 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20868 +
20869 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20870 +               nxi->v4_bcast = vc_data.ip;
20871 +               break;
20872 +
20873 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20874 +               nxi->v4_lback = vc_data.ip;
20875 +               break;
20876 +
20877 +       default:
20878 +               return -EINVAL;
20879 +       }
20880 +       return 0;
20881 +}
20882 +
20883 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
20884 +{
20885 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20886 +
20887 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20888 +               return -EFAULT;
20889 +
20890 +       switch (vc_data.type) {
20891 +       case NXA_TYPE_ADDR:
20892 +       case NXA_TYPE_MASK:
20893 +       case NXA_TYPE_RANGE:
20894 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20895 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20896 +
20897 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20898 +               nxi->v4_bcast = vc_data.ip;
20899 +               break;
20900 +
20901 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20902 +               nxi->v4_lback = vc_data.ip;
20903 +               break;
20904 +
20905 +       default:
20906 +               return -EINVAL;
20907 +       }
20908 +       return 0;
20909 +}
20910 +
20911 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
20912 +{
20913 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20914 +
20915 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20916 +               return -EFAULT;
20917 +
20918 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
20919 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20920 +}
20921 +
20922 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
20923 +{
20924 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20925 +
20926 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20927 +               return -EFAULT;
20928 +
20929 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20930 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20931 +}
20932 +
20933 +#ifdef CONFIG_IPV6
20934 +
20935 +int do_add_v6_addr(struct nx_info *nxi,
20936 +       struct in6_addr *ip, struct in6_addr *mask,
20937 +       uint32_t prefix, uint16_t type, uint16_t flags)
20938 +{
20939 +       struct nx_addr_v6 *nxa = &nxi->v6;
20940 +
20941 +       if (NX_IPV6(nxi)) {
20942 +               /* locate last entry */
20943 +               for (; nxa->next; nxa = nxa->next);
20944 +               nxa->next = __alloc_nx_addr_v6();
20945 +               nxa = nxa->next;
20946 +
20947 +               if (IS_ERR(nxa))
20948 +                       return PTR_ERR(nxa);
20949 +       }
20950 +
20951 +       nxa->ip = *ip;
20952 +       nxa->mask = *mask;
20953 +       nxa->prefix = prefix;
20954 +       nxa->type = type;
20955 +       nxa->flags = flags;
20956 +       return 0;
20957 +}
20958 +
20959 +
20960 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
20961 +{
20962 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20963 +
20964 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20965 +               return -EFAULT;
20966 +
20967 +       switch (vc_data.type) {
20968 +       case NXA_TYPE_ADDR:
20969 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20970 +               /* fallthrough */
20971 +       case NXA_TYPE_MASK:
20972 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20973 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20974 +       default:
20975 +               return -EINVAL;
20976 +       }
20977 +       return 0;
20978 +}
20979 +
20980 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
20981 +{
20982 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20983 +
20984 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20985 +               return -EFAULT;
20986 +
20987 +       switch (vc_data.type) {
20988 +       case NXA_TYPE_ANY:
20989 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
20990 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
20991 +               break;
20992 +
20993 +       default:
20994 +               return -EINVAL;
20995 +       }
20996 +       return 0;
20997 +}
20998 +
20999 +#endif /* CONFIG_IPV6 */
21000 +
21001 +
21002 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
21003 +{
21004 +       struct vcmd_net_flags_v0 vc_data;
21005 +
21006 +       vc_data.flagword = nxi->nx_flags;
21007 +
21008 +       /* special STATE flag handling */
21009 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
21010 +
21011 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21012 +               return -EFAULT;
21013 +       return 0;
21014 +}
21015 +
21016 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
21017 +{
21018 +       struct vcmd_net_flags_v0 vc_data;
21019 +       uint64_t mask, trigger;
21020 +
21021 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21022 +               return -EFAULT;
21023 +
21024 +       /* special STATE flag handling */
21025 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
21026 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
21027 +
21028 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
21029 +               vc_data.flagword, mask);
21030 +       if (trigger & NXF_PERSISTENT)
21031 +               nx_update_persistent(nxi);
21032 +
21033 +       return 0;
21034 +}
21035 +
21036 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
21037 +{
21038 +       struct vcmd_net_caps_v0 vc_data;
21039 +
21040 +       vc_data.ncaps = nxi->nx_ncaps;
21041 +       vc_data.cmask = ~0ULL;
21042 +
21043 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21044 +               return -EFAULT;
21045 +       return 0;
21046 +}
21047 +
21048 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
21049 +{
21050 +       struct vcmd_net_caps_v0 vc_data;
21051 +
21052 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21053 +               return -EFAULT;
21054 +
21055 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
21056 +               vc_data.ncaps, vc_data.cmask);
21057 +       return 0;
21058 +}
21059 +
21060 +
21061 +#include <linux/module.h>
21062 +
21063 +module_init(init_network);
21064 +
21065 +EXPORT_SYMBOL_GPL(free_nx_info);
21066 +EXPORT_SYMBOL_GPL(unhash_nx_info);
21067 +
21068 diff -NurpP --minimal linux-3.1.6/kernel/vserver/proc.c linux-3.1.6-vs2.3.2.5/kernel/vserver/proc.c
21069 --- linux-3.1.6/kernel/vserver/proc.c   1970-01-01 01:00:00.000000000 +0100
21070 +++ linux-3.1.6-vs2.3.2.5/kernel/vserver/proc.c 2011-10-24 18:53:33.000000000 +0200
21071 @@ -0,0 +1,1103 @@
21072 +/*
21073 + *  linux/kernel/vserver/proc.c
21074 + *
21075 + *  Virtual Context Support
21076 + *
21077 + *  Copyright (C) 2003-2011  Herbert Pötzl
21078 + *
21079 + *  V0.01  basic structure
21080 + *  V0.02  adaptation vs1.3.0
21081 + *  V0.03  proc permissions
21082 + *  V0.04  locking/generic
21083 + *  V0.05  next generation procfs
21084 + *  V0.06  inode validation
21085 + *  V0.07  generic rewrite vid
21086 + *  V0.08  remove inode type
21087 + *  V0.09  added u/wmask info
21088 + *
21089 + */
21090 +
21091 +#include <linux/proc_fs.h>
21092 +#include <linux/fs_struct.h>
21093 +#include <linux/mount.h>
21094 +#include <asm/unistd.h>
21095 +
21096 +#include <linux/vs_context.h>
21097 +#include <linux/vs_network.h>
21098 +#include <linux/vs_cvirt.h>
21099 +
21100 +#include <linux/in.h>
21101 +#include <linux/inetdevice.h>
21102 +#include <linux/vs_inet.h>
21103 +#include <linux/vs_inet6.h>
21104 +
21105 +#include <linux/vserver/global.h>
21106 +
21107 +#include "cvirt_proc.h"
21108 +#include "cacct_proc.h"
21109 +#include "limit_proc.h"
21110 +#include "sched_proc.h"
21111 +#include "vci_config.h"
21112 +
21113 +
21114 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
21115 +{
21116 +       unsigned __capi;
21117 +
21118 +       CAP_FOR_EACH_U32(__capi) {
21119 +               buffer += sprintf(buffer, "%08x",
21120 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
21121 +       }
21122 +       return buffer;
21123 +}
21124 +
21125 +
21126 +static struct proc_dir_entry *proc_virtual;
21127 +
21128 +static struct proc_dir_entry *proc_virtnet;
21129 +
21130 +
21131 +/* first the actual feeds */
21132 +
21133 +
21134 +static int proc_vci(char *buffer)
21135 +{
21136 +       return sprintf(buffer,
21137 +               "VCIVersion:\t%04x:%04x\n"
21138 +               "VCISyscall:\t%d\n"
21139 +               "VCIKernel:\t%08x\n",
21140 +               VCI_VERSION >> 16,
21141 +               VCI_VERSION & 0xFFFF,
21142 +               __NR_vserver,
21143 +               vci_kernel_config());
21144 +}
21145 +
21146 +static int proc_virtual_info(char *buffer)
21147 +{
21148 +       return proc_vci(buffer);
21149 +}
21150 +
21151 +static int proc_virtual_status(char *buffer)
21152 +{
21153 +       return sprintf(buffer,
21154 +               "#CTotal:\t%d\n"
21155 +               "#CActive:\t%d\n"
21156 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
21157 +               "#InitTask:\t%d\t%d %d\n",
21158 +               atomic_read(&vx_global_ctotal),
21159 +               atomic_read(&vx_global_cactive),
21160 +               atomic_read(&vs_global_nsproxy),
21161 +               atomic_read(&vs_global_fs),
21162 +               atomic_read(&vs_global_mnt_ns),
21163 +               atomic_read(&vs_global_uts_ns),
21164 +               atomic_read(&nr_ipc_ns),
21165 +               atomic_read(&vs_global_user_ns),
21166 +               atomic_read(&vs_global_pid_ns),
21167 +               atomic_read(&init_task.usage),
21168 +               atomic_read(&init_task.nsproxy->count),
21169 +               init_task.fs->users);
21170 +}
21171 +
21172 +
21173 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
21174 +{
21175 +       int length;
21176 +
21177 +       length = sprintf(buffer,
21178 +               "ID:\t%d\n"
21179 +               "Info:\t%p\n"
21180 +               "Init:\t%d\n"
21181 +               "OOM:\t%lld\n",
21182 +               vxi->vx_id,
21183 +               vxi,
21184 +               vxi->vx_initpid,
21185 +               vxi->vx_badness_bias);
21186 +       return length;
21187 +}
21188 +
21189 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
21190 +{
21191 +       char *orig = buffer;
21192 +
21193 +       buffer += sprintf(buffer,
21194 +               "UseCnt:\t%d\n"
21195 +               "Tasks:\t%d\n"
21196 +               "Flags:\t%016llx\n",
21197 +               atomic_read(&vxi->vx_usecnt),
21198 +               atomic_read(&vxi->vx_tasks),
21199 +               (unsigned long long)vxi->vx_flags);
21200 +
21201 +       buffer += sprintf(buffer, "BCaps:\t");
21202 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21203 +       buffer += sprintf(buffer, "\n");
21204 +
21205 +       buffer += sprintf(buffer,
21206 +               "CCaps:\t%016llx\n"
21207 +               "Umask:\t%16llx\n"
21208 +               "Wmask:\t%16llx\n"
21209 +               "Spaces:\t%08lx %08lx\n",
21210 +               (unsigned long long)vxi->vx_ccaps,
21211 +               (unsigned long long)vxi->vx_umask,
21212 +               (unsigned long long)vxi->vx_wmask,
21213 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
21214 +       return buffer - orig;
21215 +}
21216 +
21217 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
21218 +{
21219 +       return vx_info_proc_limit(&vxi->limit, buffer);
21220 +}
21221 +
21222 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
21223 +{
21224 +       int cpu, length;
21225 +
21226 +       length = vx_info_proc_sched(&vxi->sched, buffer);
21227 +       for_each_online_cpu(cpu) {
21228 +               length += vx_info_proc_sched_pc(
21229 +                       &vx_per_cpu(vxi, sched_pc, cpu),
21230 +                       buffer + length, cpu);
21231 +       }
21232 +       return length;
21233 +}
21234 +
21235 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
21236 +{
21237 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
21238 +}
21239 +
21240 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
21241 +{
21242 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
21243 +}
21244 +
21245 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
21246 +{
21247 +       int cpu, length;
21248 +
21249 +       vx_update_load(vxi);
21250 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
21251 +       for_each_online_cpu(cpu) {
21252 +               length += vx_info_proc_cvirt_pc(
21253 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
21254 +                       buffer + length, cpu);
21255 +       }
21256 +       return length;
21257 +}
21258 +
21259 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
21260 +{
21261 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
21262 +}
21263 +
21264 +
21265 +static int proc_virtnet_info(char *buffer)
21266 +{
21267 +       return proc_vci(buffer);
21268 +}
21269 +
21270 +static int proc_virtnet_status(char *buffer)
21271 +{
21272 +       return sprintf(buffer,
21273 +               "#CTotal:\t%d\n"
21274 +               "#CActive:\t%d\n",
21275 +               atomic_read(&nx_global_ctotal),
21276 +               atomic_read(&nx_global_cactive));
21277 +}
21278 +
21279 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
21280 +{
21281 +       struct nx_addr_v4 *v4a;
21282 +#ifdef CONFIG_IPV6
21283 +       struct nx_addr_v6 *v6a;
21284 +#endif
21285 +       int length, i;
21286 +
21287 +       length = sprintf(buffer,
21288 +               "ID:\t%d\n"
21289 +               "Info:\t%p\n"
21290 +               "Bcast:\t" NIPQUAD_FMT "\n"
21291 +               "Lback:\t" NIPQUAD_FMT "\n",
21292 +               nxi->nx_id,
21293 +               nxi,
21294 +               NIPQUAD(nxi->v4_bcast.s_addr),
21295 +               NIPQUAD(nxi->v4_lback.s_addr));
21296 +
21297 +       if (!NX_IPV4(nxi))
21298 +               goto skip_v4;
21299 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21300 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
21301 +                       i, NXAV4(v4a));
21302 +skip_v4:
21303 +#ifdef CONFIG_IPV6
21304 +       if (!NX_IPV6(nxi))
21305 +               goto skip_v6;
21306 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21307 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
21308 +                       i, NXAV6(v6a));
21309 +skip_v6:
21310 +#endif
21311 +       return length;
21312 +}
21313 +
21314 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
21315 +{
21316 +       int length;
21317 +
21318 +       length = sprintf(buffer,
21319 +               "UseCnt:\t%d\n"
21320 +               "Tasks:\t%d\n"
21321 +               "Flags:\t%016llx\n"
21322 +               "NCaps:\t%016llx\n",
21323 +               atomic_read(&nxi->nx_usecnt),
21324 +               atomic_read(&nxi->nx_tasks),
21325 +               (unsigned long long)nxi->nx_flags,
21326 +               (unsigned long long)nxi->nx_ncaps);
21327 +       return length;
21328 +}
21329 +
21330 +
21331 +
21332 +/* here the inode helpers */
21333 +
21334 +struct vs_entry {
21335 +       int len;
21336 +       char *name;
21337 +       mode_t mode;
21338 +       struct inode_operations *iop;
21339 +       struct file_operations *fop;
21340 +       union proc_op op;
21341 +};
21342 +
21343 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
21344 +{
21345 +       struct inode *inode = new_inode(sb);
21346 +
21347 +       if (!inode)
21348 +               goto out;
21349 +
21350 +       inode->i_mode = p->mode;
21351 +       if (p->iop)
21352 +               inode->i_op = p->iop;
21353 +       if (p->fop)
21354 +               inode->i_fop = p->fop;
21355 +
21356 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
21357 +       inode->i_flags |= S_IMMUTABLE;
21358 +
21359 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
21360 +
21361 +       inode->i_uid = 0;
21362 +       inode->i_gid = 0;
21363 +       inode->i_tag = 0;
21364 +out:
21365 +       return inode;
21366 +}
21367 +
21368 +static struct dentry *vs_proc_instantiate(struct inode *dir,
21369 +       struct dentry *dentry, int id, void *ptr)
21370 +{
21371 +       struct vs_entry *p = ptr;
21372 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
21373 +       struct dentry *error = ERR_PTR(-EINVAL);
21374 +
21375 +       if (!inode)
21376 +               goto out;
21377 +
21378 +       PROC_I(inode)->op = p->op;
21379 +       PROC_I(inode)->fd = id;
21380 +       d_add(dentry, inode);
21381 +       error = NULL;
21382 +out:
21383 +       return error;
21384 +}
21385 +
21386 +/* Lookups */
21387 +
21388 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
21389 +
21390 +/*
21391 + * Fill a directory entry.
21392 + *
21393 + * If possible create the dcache entry and derive our inode number and
21394 + * file type from dcache entry.
21395 + *
21396 + * Since all of the proc inode numbers are dynamically generated, the inode
21397 + * numbers do not exist until the inode is cache.  This means creating the
21398 + * the dcache entry in readdir is necessary to keep the inode numbers
21399 + * reported by readdir in sync with the inode numbers reported
21400 + * by stat.
21401 + */
21402 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
21403 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
21404 +{
21405 +       struct dentry *child, *dir = filp->f_dentry;
21406 +       struct inode *inode;
21407 +       struct qstr qname;
21408 +       ino_t ino = 0;
21409 +       unsigned type = DT_UNKNOWN;
21410 +
21411 +       qname.name = name;
21412 +       qname.len  = len;
21413 +       qname.hash = full_name_hash(name, len);
21414 +
21415 +       child = d_lookup(dir, &qname);
21416 +       if (!child) {
21417 +               struct dentry *new;
21418 +               new = d_alloc(dir, &qname);
21419 +               if (new) {
21420 +                       child = instantiate(dir->d_inode, new, id, ptr);
21421 +                       if (child)
21422 +                               dput(new);
21423 +                       else
21424 +                               child = new;
21425 +               }
21426 +       }
21427 +       if (!child || IS_ERR(child) || !child->d_inode)
21428 +               goto end_instantiate;
21429 +       inode = child->d_inode;
21430 +       if (inode) {
21431 +               ino = inode->i_ino;
21432 +               type = inode->i_mode >> 12;
21433 +       }
21434 +       dput(child);
21435 +end_instantiate:
21436 +       if (!ino)
21437 +               ino = find_inode_number(dir, &qname);
21438 +       if (!ino)
21439 +               ino = 1;
21440 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
21441 +}
21442 +
21443 +
21444 +
21445 +/* get and revalidate vx_info/xid */
21446 +
21447 +static inline
21448 +struct vx_info *get_proc_vx_info(struct inode *inode)
21449 +{
21450 +       return lookup_vx_info(PROC_I(inode)->fd);
21451 +}
21452 +
21453 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
21454 +{
21455 +       struct inode *inode = dentry->d_inode;
21456 +       xid_t xid = PROC_I(inode)->fd;
21457 +
21458 +       if (!xid || xid_is_hashed(xid))
21459 +               return 1;
21460 +       d_drop(dentry);
21461 +       return 0;
21462 +}
21463 +
21464 +
21465 +/* get and revalidate nx_info/nid */
21466 +
21467 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
21468 +{
21469 +       struct inode *inode = dentry->d_inode;
21470 +       nid_t nid = PROC_I(inode)->fd;
21471 +
21472 +       if (!nid || nid_is_hashed(nid))
21473 +               return 1;
21474 +       d_drop(dentry);
21475 +       return 0;
21476 +}
21477 +
21478 +
21479 +
21480 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
21481 +
21482 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
21483 +                         size_t count, loff_t *ppos)
21484 +{
21485 +       struct inode *inode = file->f_dentry->d_inode;
21486 +       unsigned long page;
21487 +       ssize_t length = 0;
21488 +
21489 +       if (count > PROC_BLOCK_SIZE)
21490 +               count = PROC_BLOCK_SIZE;
21491 +
21492 +       /* fade that out as soon as stable */
21493 +       WARN_ON(PROC_I(inode)->fd);
21494 +
21495 +       if (!(page = __get_free_page(GFP_KERNEL)))
21496 +               return -ENOMEM;
21497 +
21498 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
21499 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
21500 +
21501 +       if (length >= 0)
21502 +               length = simple_read_from_buffer(buf, count, ppos,
21503 +                       (char *)page, length);
21504 +
21505 +       free_page(page);
21506 +       return length;
21507 +}
21508 +
21509 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
21510 +                         size_t count, loff_t *ppos)
21511 +{
21512 +       struct inode *inode = file->f_dentry->d_inode;
21513 +       struct vx_info *vxi = NULL;
21514 +       xid_t xid = PROC_I(inode)->fd;
21515 +       unsigned long page;
21516 +       ssize_t length = 0;
21517 +
21518 +       if (count > PROC_BLOCK_SIZE)
21519 +               count = PROC_BLOCK_SIZE;
21520 +
21521 +       /* fade that out as soon as stable */
21522 +       WARN_ON(!xid);
21523 +       vxi = lookup_vx_info(xid);
21524 +       if (!vxi)
21525 +               goto out;
21526 +
21527 +       length = -ENOMEM;
21528 +       if (!(page = __get_free_page(GFP_KERNEL)))
21529 +               goto out_put;
21530 +
21531 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
21532 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
21533 +
21534 +       if (length >= 0)
21535 +               length = simple_read_from_buffer(buf, count, ppos,
21536 +                       (char *)page, length);
21537 +
21538 +       free_page(page);
21539 +out_put:
21540 +       put_vx_info(vxi);
21541 +out:
21542 +       return length;
21543 +}
21544 +
21545 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
21546 +                         size_t count, loff_t *ppos)
21547 +{
21548 +       struct inode *inode = file->f_dentry->d_inode;
21549 +       struct nx_info *nxi = NULL;
21550 +       nid_t nid = PROC_I(inode)->fd;
21551 +       unsigned long page;
21552 +       ssize_t length = 0;
21553 +
21554 +       if (count > PROC_BLOCK_SIZE)
21555 +               count = PROC_BLOCK_SIZE;
21556 +
21557 +       /* fade that out as soon as stable */
21558 +       WARN_ON(!nid);
21559 +       nxi = lookup_nx_info(nid);
21560 +       if (!nxi)
21561 +               goto out;
21562 +
21563 +       length = -ENOMEM;
21564 +       if (!(page = __get_free_page(GFP_KERNEL)))
21565 +               goto out_put;
21566 +
21567 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
21568 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
21569 +
21570 +       if (length >= 0)
21571 +               length = simple_read_from_buffer(buf, count, ppos,
21572 +                       (char *)page, length);
21573 +
21574 +       free_page(page);
21575 +out_put:
21576 +       put_nx_info(nxi);
21577 +out:
21578 +       return length;
21579 +}
21580 +
21581 +
21582 +
21583 +/* here comes the lower level */
21584 +
21585 +
21586 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
21587 +       .len  = sizeof(NAME) - 1,       \
21588 +       .name = (NAME),                 \
21589 +       .mode = MODE,                   \
21590 +       .iop  = IOP,                    \
21591 +       .fop  = FOP,                    \
21592 +       .op   = OP,                     \
21593 +}
21594 +
21595 +
21596 +#define DIR(NAME, MODE, OTYPE)                         \
21597 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
21598 +               &proc_ ## OTYPE ## _inode_operations,   \
21599 +               &proc_ ## OTYPE ## _file_operations, { } )
21600 +
21601 +#define INF(NAME, MODE, OTYPE)                         \
21602 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21603 +               &proc_vs_info_file_operations,          \
21604 +               { .proc_vs_read = &proc_##OTYPE } )
21605 +
21606 +#define VINF(NAME, MODE, OTYPE)                                \
21607 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21608 +               &proc_vx_info_file_operations,          \
21609 +               { .proc_vxi_read = &proc_##OTYPE } )
21610 +
21611 +#define NINF(NAME, MODE, OTYPE)                                \
21612 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21613 +               &proc_nx_info_file_operations,          \
21614 +               { .proc_nxi_read = &proc_##OTYPE } )
21615 +
21616 +
21617 +static struct file_operations proc_vs_info_file_operations = {
21618 +       .read =         proc_vs_info_read,
21619 +};
21620 +
21621 +static struct file_operations proc_vx_info_file_operations = {
21622 +       .read =         proc_vx_info_read,
21623 +};
21624 +
21625 +static struct dentry_operations proc_xid_dentry_operations = {
21626 +       .d_revalidate = proc_xid_revalidate,
21627 +};
21628 +
21629 +static struct vs_entry vx_base_stuff[] = {
21630 +       VINF("info",    S_IRUGO, vxi_info),
21631 +       VINF("status",  S_IRUGO, vxi_status),
21632 +       VINF("limit",   S_IRUGO, vxi_limit),
21633 +       VINF("sched",   S_IRUGO, vxi_sched),
21634 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
21635 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
21636 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
21637 +       VINF("cacct",   S_IRUGO, vxi_cacct),
21638 +       {}
21639 +};
21640 +
21641 +
21642 +
21643 +
21644 +static struct dentry *proc_xid_instantiate(struct inode *dir,
21645 +       struct dentry *dentry, int id, void *ptr)
21646 +{
21647 +       dentry->d_op = &proc_xid_dentry_operations;
21648 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21649 +}
21650 +
21651 +static struct dentry *proc_xid_lookup(struct inode *dir,
21652 +       struct dentry *dentry, struct nameidata *nd)
21653 +{
21654 +       struct vs_entry *p = vx_base_stuff;
21655 +       struct dentry *error = ERR_PTR(-ENOENT);
21656 +
21657 +       for (; p->name; p++) {
21658 +               if (p->len != dentry->d_name.len)
21659 +                       continue;
21660 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21661 +                       break;
21662 +       }
21663 +       if (!p->name)
21664 +               goto out;
21665 +
21666 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21667 +out:
21668 +       return error;
21669 +}
21670 +
21671 +static int proc_xid_readdir(struct file *filp,
21672 +       void *dirent, filldir_t filldir)
21673 +{
21674 +       struct dentry *dentry = filp->f_dentry;
21675 +       struct inode *inode = dentry->d_inode;
21676 +       struct vs_entry *p = vx_base_stuff;
21677 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
21678 +       int pos, index;
21679 +       u64 ino;
21680 +
21681 +       pos = filp->f_pos;
21682 +       switch (pos) {
21683 +       case 0:
21684 +               ino = inode->i_ino;
21685 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21686 +                       goto out;
21687 +               pos++;
21688 +               /* fall through */
21689 +       case 1:
21690 +               ino = parent_ino(dentry);
21691 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21692 +                       goto out;
21693 +               pos++;
21694 +               /* fall through */
21695 +       default:
21696 +               index = pos - 2;
21697 +               if (index >= size)
21698 +                       goto out;
21699 +               for (p += index; p->name; p++) {
21700 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21701 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21702 +                               goto out;
21703 +                       pos++;
21704 +               }
21705 +       }
21706 +out:
21707 +       filp->f_pos = pos;
21708 +       return 1;
21709 +}
21710 +
21711 +
21712 +
21713 +static struct file_operations proc_nx_info_file_operations = {
21714 +       .read =         proc_nx_info_read,
21715 +};
21716 +
21717 +static struct dentry_operations proc_nid_dentry_operations = {
21718 +       .d_revalidate = proc_nid_revalidate,
21719 +};
21720 +
21721 +static struct vs_entry nx_base_stuff[] = {
21722 +       NINF("info",    S_IRUGO, nxi_info),
21723 +       NINF("status",  S_IRUGO, nxi_status),
21724 +       {}
21725 +};
21726 +
21727 +
21728 +static struct dentry *proc_nid_instantiate(struct inode *dir,
21729 +       struct dentry *dentry, int id, void *ptr)
21730 +{
21731 +       dentry->d_op = &proc_nid_dentry_operations;
21732 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21733 +}
21734 +
21735 +static struct dentry *proc_nid_lookup(struct inode *dir,
21736 +       struct dentry *dentry, struct nameidata *nd)
21737 +{
21738 +       struct vs_entry *p = nx_base_stuff;
21739 +       struct dentry *error = ERR_PTR(-ENOENT);
21740 +
21741 +       for (; p->name; p++) {
21742 +               if (p->len != dentry->d_name.len)
21743 +                       continue;
21744 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21745 +                       break;
21746 +       }
21747 +       if (!p->name)
21748 +               goto out;
21749 +
21750 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21751 +out:
21752 +       return error;
21753 +}
21754 +
21755 +static int proc_nid_readdir(struct file *filp,
21756 +       void *dirent, filldir_t filldir)
21757 +{
21758 +       struct dentry *dentry = filp->f_dentry;
21759 +       struct inode *inode = dentry->d_inode;
21760 +       struct vs_entry *p = nx_base_stuff;
21761 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
21762 +       int pos, index;
21763 +       u64 ino;
21764 +
21765 +       pos = filp->f_pos;
21766 +       switch (pos) {
21767 +       case 0:
21768 +               ino = inode->i_ino;
21769 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21770 +                       goto out;
21771 +               pos++;
21772 +               /* fall through */
21773 +       case 1:
21774 +               ino = parent_ino(dentry);
21775 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21776 +                       goto out;
21777 +               pos++;
21778 +               /* fall through */
21779 +       default:
21780 +               index = pos - 2;
21781 +               if (index >= size)
21782 +                       goto out;
21783 +               for (p += index; p->name; p++) {
21784 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21785 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21786 +                               goto out;
21787 +                       pos++;
21788 +               }
21789 +       }
21790 +out:
21791 +       filp->f_pos = pos;
21792 +       return 1;
21793 +}
21794 +
21795 +
21796 +#define MAX_MULBY10    ((~0U - 9) / 10)
21797 +
21798 +static inline int atovid(const char *str, int len)
21799 +{
21800 +       int vid, c;
21801 +
21802 +       vid = 0;
21803 +       while (len-- > 0) {
21804 +               c = *str - '0';
21805 +               str++;
21806 +               if (c > 9)
21807 +                       return -1;
21808 +               if (vid >= MAX_MULBY10)
21809 +                       return -1;
21810 +               vid *= 10;
21811 +               vid += c;
21812 +               if (!vid)
21813 +                       return -1;
21814 +       }
21815 +       return vid;
21816 +}
21817 +
21818 +/* now the upper level (virtual) */
21819 +
21820 +
21821 +static struct file_operations proc_xid_file_operations = {
21822 +       .read =         generic_read_dir,
21823 +       .readdir =      proc_xid_readdir,
21824 +};
21825 +
21826 +static struct inode_operations proc_xid_inode_operations = {
21827 +       .lookup =       proc_xid_lookup,
21828 +};
21829 +
21830 +static struct vs_entry vx_virtual_stuff[] = {
21831 +       INF("info",     S_IRUGO, virtual_info),
21832 +       INF("status",   S_IRUGO, virtual_status),
21833 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
21834 +};
21835 +
21836 +
21837 +static struct dentry *proc_virtual_lookup(struct inode *dir,
21838 +       struct dentry *dentry, struct nameidata *nd)
21839 +{
21840 +       struct vs_entry *p = vx_virtual_stuff;
21841 +       struct dentry *error = ERR_PTR(-ENOENT);
21842 +       int id = 0;
21843 +
21844 +       for (; p->name; p++) {
21845 +               if (p->len != dentry->d_name.len)
21846 +                       continue;
21847 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21848 +                       break;
21849 +       }
21850 +       if (p->name)
21851 +               goto instantiate;
21852 +
21853 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21854 +       if ((id < 0) || !xid_is_hashed(id))
21855 +               goto out;
21856 +
21857 +instantiate:
21858 +       error = proc_xid_instantiate(dir, dentry, id, p);
21859 +out:
21860 +       return error;
21861 +}
21862 +
21863 +static struct file_operations proc_nid_file_operations = {
21864 +       .read =         generic_read_dir,
21865 +       .readdir =      proc_nid_readdir,
21866 +};
21867 +
21868 +static struct inode_operations proc_nid_inode_operations = {
21869 +       .lookup =       proc_nid_lookup,
21870 +};
21871 +
21872 +static struct vs_entry nx_virtnet_stuff[] = {
21873 +       INF("info",     S_IRUGO, virtnet_info),
21874 +       INF("status",   S_IRUGO, virtnet_status),
21875 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
21876 +};
21877 +
21878 +
21879 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
21880 +       struct dentry *dentry, struct nameidata *nd)
21881 +{
21882 +       struct vs_entry *p = nx_virtnet_stuff;
21883 +       struct dentry *error = ERR_PTR(-ENOENT);
21884 +       int id = 0;
21885 +
21886 +       for (; p->name; p++) {
21887 +               if (p->len != dentry->d_name.len)
21888 +                       continue;
21889 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21890 +                       break;
21891 +       }
21892 +       if (p->name)
21893 +               goto instantiate;
21894 +
21895 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21896 +       if ((id < 0) || !nid_is_hashed(id))
21897 +               goto out;
21898 +
21899 +instantiate:
21900 +       error = proc_nid_instantiate(dir, dentry, id, p);
21901 +out:
21902 +       return error;
21903 +}
21904 +
21905 +
21906 +#define PROC_MAXVIDS 32
21907 +
21908 +int proc_virtual_readdir(struct file *filp,
21909 +       void *dirent, filldir_t filldir)
21910 +{
21911 +       struct dentry *dentry = filp->f_dentry;
21912 +       struct inode *inode = dentry->d_inode;
21913 +       struct vs_entry *p = vx_virtual_stuff;
21914 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
21915 +       int pos, index;
21916 +       unsigned int xid_array[PROC_MAXVIDS];
21917 +       char buf[PROC_NUMBUF];
21918 +       unsigned int nr_xids, i;
21919 +       u64 ino;
21920 +
21921 +       pos = filp->f_pos;
21922 +       switch (pos) {
21923 +       case 0:
21924 +               ino = inode->i_ino;
21925 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21926 +                       goto out;
21927 +               pos++;
21928 +               /* fall through */
21929 +       case 1:
21930 +               ino = parent_ino(dentry);
21931 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21932 +                       goto out;
21933 +               pos++;
21934 +               /* fall through */
21935 +       default:
21936 +               index = pos - 2;
21937 +               if (index >= size)
21938 +                       goto entries;
21939 +               for (p += index; p->name; p++) {
21940 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21941 +                               vs_proc_instantiate, 0, p))
21942 +                               goto out;
21943 +                       pos++;
21944 +               }
21945 +       entries:
21946 +               index = pos - size;
21947 +               p = &vx_virtual_stuff[size - 1];
21948 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
21949 +               for (i = 0; i < nr_xids; i++) {
21950 +                       int n, xid = xid_array[i];
21951 +                       unsigned int j = PROC_NUMBUF;
21952 +
21953 +                       n = xid;
21954 +                       do
21955 +                               buf[--j] = '0' + (n % 10);
21956 +                       while (n /= 10);
21957 +
21958 +                       if (proc_fill_cache(filp, dirent, filldir,
21959 +                               buf + j, PROC_NUMBUF - j,
21960 +                               vs_proc_instantiate, xid, p))
21961 +                               goto out;
21962 +                       pos++;
21963 +               }
21964 +       }
21965 +out:
21966 +       filp->f_pos = pos;
21967 +       return 0;
21968 +}
21969 +
21970 +static int proc_virtual_getattr(struct vfsmount *mnt,
21971 +       struct dentry *dentry, struct kstat *stat)
21972 +{
21973 +       struct inode *inode = dentry->d_inode;
21974 +
21975 +       generic_fillattr(inode, stat);
21976 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
21977 +       return 0;
21978 +}
21979 +
21980 +static struct file_operations proc_virtual_dir_operations = {
21981 +       .read =         generic_read_dir,
21982 +       .readdir =      proc_virtual_readdir,
21983 +};
21984 +
21985 +static struct inode_operations proc_virtual_dir_inode_operations = {
21986 +       .getattr =      proc_virtual_getattr,
21987 +       .lookup =       proc_virtual_lookup,
21988 +};
21989 +
21990 +
21991 +
21992 +
21993 +
21994 +int proc_virtnet_readdir(struct file *filp,
21995 +       void *dirent, filldir_t filldir)
21996 +{
21997 +       struct dentry *dentry = filp->f_dentry;
21998 +       struct inode *inode = dentry->d_inode;
21999 +       struct vs_entry *p = nx_virtnet_stuff;
22000 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
22001 +       int pos, index;
22002 +       unsigned int nid_array[PROC_MAXVIDS];
22003 +       char buf[PROC_NUMBUF];
22004 +       unsigned int nr_nids, i;
22005 +       u64 ino;
22006 +
22007 +       pos = filp->f_pos;
22008 +       switch (pos) {
22009 +       case 0:
22010 +               ino = inode->i_ino;
22011 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22012 +                       goto out;
22013 +               pos++;
22014 +               /* fall through */
22015 +       case 1:
22016 +               ino = parent_ino(dentry);
22017 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22018 +                       goto out;
22019 +               pos++;
22020 +               /* fall through */
22021 +       default:
22022 +               index = pos - 2;
22023 +               if (index >= size)
22024 +                       goto entries;
22025 +               for (p += index; p->name; p++) {
22026 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22027 +                               vs_proc_instantiate, 0, p))
22028 +                               goto out;
22029 +                       pos++;
22030 +               }
22031 +       entries:
22032 +               index = pos - size;
22033 +               p = &nx_virtnet_stuff[size - 1];
22034 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
22035 +               for (i = 0; i < nr_nids; i++) {
22036 +                       int n, nid = nid_array[i];
22037 +                       unsigned int j = PROC_NUMBUF;
22038 +
22039 +                       n = nid;
22040 +                       do
22041 +                               buf[--j] = '0' + (n % 10);
22042 +                       while (n /= 10);
22043 +
22044 +                       if (proc_fill_cache(filp, dirent, filldir,
22045 +                               buf + j, PROC_NUMBUF - j,
22046 +                               vs_proc_instantiate, nid, p))
22047 +                               goto out;
22048 +                       pos++;
22049 +               }
22050 +       }
22051 +out:
22052 +       filp->f_pos = pos;
22053 +       return 0;
22054 +}
22055 +
22056 +static int proc_virtnet_getattr(struct vfsmount *mnt,
22057 +       struct dentry *dentry, struct kstat *stat)
22058 +{
22059 +       struct inode *inode = dentry->d_inode;
22060 +
22061 +       generic_fillattr(inode, stat);
22062 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
22063 +       return 0;
22064 +}
22065 +
22066 +static struct file_operations proc_virtnet_dir_operations = {
22067 +       .read =         generic_read_dir,
22068 +       .readdir =      proc_virtnet_readdir,
22069 +};
22070 +
22071 +static struct inode_operations proc_virtnet_dir_inode_operations = {
22072 +       .getattr =      proc_virtnet_getattr,
22073 +       .lookup =       proc_virtnet_lookup,
22074 +};
22075 +
22076 +
22077 +
22078 +void proc_vx_init(void)
22079 +{
22080 +       struct proc_dir_entry *ent;
22081 +
22082 +       ent = proc_mkdir("virtual", 0);
22083 +       if (ent) {
22084 +               ent->proc_fops = &proc_virtual_dir_operations;
22085 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
22086 +       }
22087 +       proc_virtual = ent;
22088 +
22089 +       ent = proc_mkdir("virtnet", 0);
22090 +       if (ent) {
22091 +               ent->proc_fops = &proc_virtnet_dir_operations;
22092 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
22093 +       }
22094 +       proc_virtnet = ent;
22095 +}
22096 +
22097 +
22098 +
22099 +
22100 +/* per pid info */
22101 +
22102 +
22103 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
22104 +{
22105 +       struct vx_info *vxi;
22106 +       char *orig = buffer;
22107 +
22108 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
22109 +
22110 +       vxi = task_get_vx_info(p);
22111 +       if (!vxi)
22112 +               goto out;
22113 +
22114 +       buffer += sprintf(buffer, "BCaps:\t");
22115 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
22116 +       buffer += sprintf(buffer, "\n");
22117 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
22118 +               (unsigned long long)vxi->vx_ccaps);
22119 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
22120 +               (unsigned long long)vxi->vx_flags);
22121 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
22122 +
22123 +       put_vx_info(vxi);
22124 +out:
22125 +       return buffer - orig;
22126 +}
22127 +
22128 +
22129 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
22130 +{
22131 +       struct nx_info *nxi;
22132 +       struct nx_addr_v4 *v4a;
22133 +#ifdef CONFIG_IPV6
22134 +       struct nx_addr_v6 *v6a;
22135 +#endif
22136 +       char *orig = buffer;
22137 +       int i;
22138 +
22139 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
22140 +
22141 +       nxi = task_get_nx_info(p);
22142 +       if (!nxi)
22143 +               goto out;
22144 +
22145 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
22146 +               (unsigned long long)nxi->nx_ncaps);
22147 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
22148 +               (unsigned long long)nxi->nx_flags);
22149 +
22150 +       buffer += sprintf(buffer,
22151 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
22152 +               NIPQUAD(nxi->v4_bcast.s_addr));
22153 +       buffer += sprintf (buffer,
22154 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
22155 +               NIPQUAD(nxi->v4_lback.s_addr));
22156 +       if (!NX_IPV4(nxi))
22157 +               goto skip_v4;
22158 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22159 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
22160 +                       i, NXAV4(v4a));
22161 +skip_v4:
22162 +#ifdef CONFIG_IPV6
22163 +       if (!NX_IPV6(nxi))
22164 +               goto skip_v6;
22165 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22166 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
22167 +                       i, NXAV6(v6a));
22168 +skip_v6:
22169 +#endif
22170 +       put_nx_info(nxi);
22171 +out:
22172 +       return buffer - orig;
22173 +}
22174 +
22175 diff -NurpP --minimal linux-3.1.6/kernel/vserver/sched.c linux-3.1.6-vs2.3.2.5/kernel/vserver/sched.c
22176 --- linux-3.1.6/kernel/vserver/sched.c  1970-01-01 01:00:00.000000000 +0100
22177 +++ linux-3.1.6-vs2.3.2.5/kernel/vserver/sched.c        2011-10-24 18:53:33.000000000 +0200
22178 @@ -0,0 +1,82 @@
22179 +/*
22180 + *  linux/kernel/vserver/sched.c
22181 + *
22182 + *  Virtual Server: Scheduler Support
22183 + *
22184 + *  Copyright (C) 2004-2010  Herbert Pötzl
22185 + *
22186 + *  V0.01  adapted Sam Vilains version to 2.6.3
22187 + *  V0.02  removed legacy interface
22188 + *  V0.03  changed vcmds to vxi arg
22189 + *  V0.04  removed older and legacy interfaces
22190 + *  V0.05  removed scheduler code/commands
22191 + *
22192 + */
22193 +
22194 +#include <linux/vs_context.h>
22195 +#include <linux/vs_sched.h>
22196 +#include <linux/vserver/sched_cmd.h>
22197 +
22198 +#include <asm/uaccess.h>
22199 +
22200 +
22201 +void vx_update_sched_param(struct _vx_sched *sched,
22202 +       struct _vx_sched_pc *sched_pc)
22203 +{
22204 +       sched_pc->prio_bias = sched->prio_bias;
22205 +}
22206 +
22207 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
22208 +{
22209 +       int cpu;
22210 +
22211 +       if (data->prio_bias > MAX_PRIO_BIAS)
22212 +               data->prio_bias = MAX_PRIO_BIAS;
22213 +       if (data->prio_bias < MIN_PRIO_BIAS)
22214 +               data->prio_bias = MIN_PRIO_BIAS;
22215 +
22216 +       if (data->cpu_id != ~0) {
22217 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
22218 +               cpus_and(vxi->sched.update, cpu_online_map,
22219 +                       vxi->sched.update);
22220 +       } else
22221 +               vxi->sched.update = cpu_online_map;
22222 +
22223 +       for_each_cpu_mask(cpu, vxi->sched.update)
22224 +               vx_update_sched_param(&vxi->sched,
22225 +                       &vx_per_cpu(vxi, sched_pc, cpu));
22226 +       return 0;
22227 +}
22228 +
22229 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
22230 +{
22231 +       struct vcmd_prio_bias vc_data;
22232 +
22233 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22234 +               return -EFAULT;
22235 +
22236 +       return do_set_prio_bias(vxi, &vc_data);
22237 +}
22238 +
22239 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
22240 +{
22241 +       struct vcmd_prio_bias vc_data;
22242 +       struct _vx_sched_pc *pcd;
22243 +       int cpu;
22244 +
22245 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22246 +               return -EFAULT;
22247 +
22248 +       cpu = vc_data.cpu_id;
22249 +
22250 +       if (!cpu_possible(cpu))
22251 +               return -EINVAL;
22252 +
22253 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
22254 +       vc_data.prio_bias = pcd->prio_bias;
22255 +
22256 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22257 +               return -EFAULT;
22258 +       return 0;
22259 +}
22260 +
22261 diff -NurpP --minimal linux-3.1.6/kernel/vserver/sched_init.h linux-3.1.6-vs2.3.2.5/kernel/vserver/sched_init.h
22262 --- linux-3.1.6/kernel/vserver/sched_init.h     1970-01-01 01:00:00.000000000 +0100
22263 +++ linux-3.1.6-vs2.3.2.5/kernel/vserver/sched_init.h   2011-10-24 18:53:33.000000000 +0200
22264 @@ -0,0 +1,27 @@
22265 +
22266 +static inline void vx_info_init_sched(struct _vx_sched *sched)
22267 +{
22268 +       /* scheduling; hard code starting values as constants */
22269 +       sched->prio_bias = 0;
22270 +}
22271 +
22272 +static inline
22273 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22274 +{
22275 +       sched_pc->prio_bias = 0;
22276 +
22277 +       sched_pc->user_ticks = 0;
22278 +       sched_pc->sys_ticks = 0;
22279 +       sched_pc->hold_ticks = 0;
22280 +}
22281 +
22282 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
22283 +{
22284 +       return;
22285 +}
22286 +
22287 +static inline
22288 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22289 +{
22290 +       return;
22291 +}
22292 diff -NurpP --minimal linux-3.1.6/kernel/vserver/sched_proc.h linux-3.1.6-vs2.3.2.5/kernel/vserver/sched_proc.h
22293 --- linux-3.1.6/kernel/vserver/sched_proc.h     1970-01-01 01:00:00.000000000 +0100
22294 +++ linux-3.1.6-vs2.3.2.5/kernel/vserver/sched_proc.h   2011-10-24 18:53:33.000000000 +0200
22295 @@ -0,0 +1,32 @@
22296 +#ifndef _VX_SCHED_PROC_H
22297 +#define _VX_SCHED_PROC_H
22298 +
22299 +
22300 +static inline
22301 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
22302 +{
22303 +       int length = 0;
22304 +
22305 +       length += sprintf(buffer,
22306 +               "PrioBias:\t%8d\n",
22307 +               sched->prio_bias);
22308 +       return length;
22309 +}
22310 +
22311 +static inline
22312 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
22313 +       char *buffer, int cpu)
22314 +{
22315 +       int length = 0;
22316 +
22317 +       length += sprintf(buffer + length,
22318 +               "cpu %d: %lld %lld %lld", cpu,
22319 +               (unsigned long long)sched_pc->user_ticks,
22320 +               (unsigned long long)sched_pc->sys_ticks,
22321 +               (unsigned long long)sched_pc->hold_ticks);
22322 +       length += sprintf(buffer + length,
22323 +               " %d\n", sched_pc->prio_bias);
22324 +       return length;
22325 +}
22326 +
22327 +#endif /* _VX_SCHED_PROC_H */
22328 diff -NurpP --minimal linux-3.1.6/kernel/vserver/signal.c linux-3.1.6-vs2.3.2.5/kernel/vserver/signal.c
22329 --- linux-3.1.6/kernel/vserver/signal.c 1970-01-01 01:00:00.000000000 +0100
22330 +++ linux-3.1.6-vs2.3.2.5/kernel/vserver/signal.c       2011-10-24 18:53:33.000000000 +0200
22331 @@ -0,0 +1,134 @@
22332 +/*
22333 + *  linux/kernel/vserver/signal.c
22334 + *
22335 + *  Virtual Server: Signal Support
22336 + *
22337 + *  Copyright (C) 2003-2007  Herbert Pötzl
22338 + *
22339 + *  V0.01  broken out from vcontext V0.05
22340 + *  V0.02  changed vcmds to vxi arg
22341 + *  V0.03  adjusted siginfo for kill
22342 + *
22343 + */
22344 +
22345 +#include <asm/uaccess.h>
22346 +
22347 +#include <linux/vs_context.h>
22348 +#include <linux/vs_pid.h>
22349 +#include <linux/vserver/signal_cmd.h>
22350 +
22351 +
22352 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
22353 +{
22354 +       int retval, count = 0;
22355 +       struct task_struct *p;
22356 +       struct siginfo *sip = SEND_SIG_PRIV;
22357 +
22358 +       retval = -ESRCH;
22359 +       vxdprintk(VXD_CBIT(misc, 4),
22360 +               "vx_info_kill(%p[#%d],%d,%d)*",
22361 +               vxi, vxi->vx_id, pid, sig);
22362 +       read_lock(&tasklist_lock);
22363 +       switch (pid) {
22364 +       case  0:
22365 +       case -1:
22366 +               for_each_process(p) {
22367 +                       int err = 0;
22368 +
22369 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
22370 +                               (pid && vxi->vx_initpid == p->pid))
22371 +                               continue;
22372 +
22373 +                       err = group_send_sig_info(sig, sip, p);
22374 +                       ++count;
22375 +                       if (err != -EPERM)
22376 +                               retval = err;
22377 +               }
22378 +               break;
22379 +
22380 +       case 1:
22381 +               if (vxi->vx_initpid) {
22382 +                       pid = vxi->vx_initpid;
22383 +                       /* for now, only SIGINT to private init ... */
22384 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22385 +                               /* ... as long as there are tasks left */
22386 +                               (atomic_read(&vxi->vx_tasks) > 1))
22387 +                               sig = SIGINT;
22388 +               }
22389 +               /* fallthrough */
22390 +       default:
22391 +               rcu_read_lock();
22392 +               p = find_task_by_real_pid(pid);
22393 +               rcu_read_unlock();
22394 +               if (p) {
22395 +                       if (vx_task_xid(p) == vxi->vx_id)
22396 +                               retval = group_send_sig_info(sig, sip, p);
22397 +               }
22398 +               break;
22399 +       }
22400 +       read_unlock(&tasklist_lock);
22401 +       vxdprintk(VXD_CBIT(misc, 4),
22402 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
22403 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
22404 +       return retval;
22405 +}
22406 +
22407 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
22408 +{
22409 +       struct vcmd_ctx_kill_v0 vc_data;
22410 +
22411 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22412 +               return -EFAULT;
22413 +
22414 +       /* special check to allow guest shutdown */
22415 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22416 +               /* forbid killall pid=0 when init is present */
22417 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
22418 +               (vc_data.pid > 1)))
22419 +               return -EACCES;
22420 +
22421 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
22422 +}
22423 +
22424 +
22425 +static int __wait_exit(struct vx_info *vxi)
22426 +{
22427 +       DECLARE_WAITQUEUE(wait, current);
22428 +       int ret = 0;
22429 +
22430 +       add_wait_queue(&vxi->vx_wait, &wait);
22431 +       set_current_state(TASK_INTERRUPTIBLE);
22432 +
22433 +wait:
22434 +       if (vx_info_state(vxi,
22435 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
22436 +               goto out;
22437 +       if (signal_pending(current)) {
22438 +               ret = -ERESTARTSYS;
22439 +               goto out;
22440 +       }
22441 +       schedule();
22442 +       goto wait;
22443 +
22444 +out:
22445 +       set_current_state(TASK_RUNNING);
22446 +       remove_wait_queue(&vxi->vx_wait, &wait);
22447 +       return ret;
22448 +}
22449 +
22450 +
22451 +
22452 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
22453 +{
22454 +       struct vcmd_wait_exit_v0 vc_data;
22455 +       int ret;
22456 +
22457 +       ret = __wait_exit(vxi);
22458 +       vc_data.reboot_cmd = vxi->reboot_cmd;
22459 +       vc_data.exit_code = vxi->exit_code;
22460 +
22461 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22462 +               ret = -EFAULT;
22463 +       return ret;
22464 +}
22465 +
22466 diff -NurpP --minimal linux-3.1.6/kernel/vserver/space.c linux-3.1.6-vs2.3.2.5/kernel/vserver/space.c
22467 --- linux-3.1.6/kernel/vserver/space.c  1970-01-01 01:00:00.000000000 +0100
22468 +++ linux-3.1.6-vs2.3.2.5/kernel/vserver/space.c        2011-10-24 18:53:33.000000000 +0200
22469 @@ -0,0 +1,435 @@
22470 +/*
22471 + *  linux/kernel/vserver/space.c
22472 + *
22473 + *  Virtual Server: Context Space Support
22474 + *
22475 + *  Copyright (C) 2003-2010  Herbert Pötzl
22476 + *
22477 + *  V0.01  broken out from context.c 0.07
22478 + *  V0.02  added task locking for namespace
22479 + *  V0.03  broken out vx_enter_namespace
22480 + *  V0.04  added *space support and commands
22481 + *  V0.05  added credential support
22482 + *
22483 + */
22484 +
22485 +#include <linux/utsname.h>
22486 +#include <linux/nsproxy.h>
22487 +#include <linux/err.h>
22488 +#include <linux/fs_struct.h>
22489 +#include <linux/cred.h>
22490 +#include <asm/uaccess.h>
22491 +
22492 +#include <linux/vs_context.h>
22493 +#include <linux/vserver/space.h>
22494 +#include <linux/vserver/space_cmd.h>
22495 +
22496 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
22497 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
22498 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
22499 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
22500 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
22501 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
22502 +
22503 +
22504 +/* namespace functions */
22505 +
22506 +#include <linux/mnt_namespace.h>
22507 +#include <linux/user_namespace.h>
22508 +#include <linux/pid_namespace.h>
22509 +#include <linux/ipc_namespace.h>
22510 +#include <net/net_namespace.h>
22511 +
22512 +
22513 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
22514 +       .mask = CLONE_FS |
22515 +               CLONE_NEWNS |
22516 +#ifdef CONFIG_UTS_NS
22517 +               CLONE_NEWUTS |
22518 +#endif
22519 +#ifdef CONFIG_IPC_NS
22520 +               CLONE_NEWIPC |
22521 +#endif
22522 +#ifdef CONFIG_USER_NS
22523 +               CLONE_NEWUSER |
22524 +#endif
22525 +               0
22526 +};
22527 +
22528 +static const struct vcmd_space_mask_v1 space_mask = {
22529 +       .mask = CLONE_FS |
22530 +               CLONE_NEWNS |
22531 +#ifdef CONFIG_UTS_NS
22532 +               CLONE_NEWUTS |
22533 +#endif
22534 +#ifdef CONFIG_IPC_NS
22535 +               CLONE_NEWIPC |
22536 +#endif
22537 +#ifdef CONFIG_USER_NS
22538 +               CLONE_NEWUSER |
22539 +#endif
22540 +#ifdef CONFIG_PID_NS
22541 +               CLONE_NEWPID |
22542 +#endif
22543 +#ifdef CONFIG_NET_NS
22544 +               CLONE_NEWNET |
22545 +#endif
22546 +               0
22547 +};
22548 +
22549 +static const struct vcmd_space_mask_v1 default_space_mask = {
22550 +       .mask = CLONE_FS |
22551 +               CLONE_NEWNS |
22552 +#ifdef CONFIG_UTS_NS
22553 +               CLONE_NEWUTS |
22554 +#endif
22555 +#ifdef CONFIG_IPC_NS
22556 +               CLONE_NEWIPC |
22557 +#endif
22558 +#ifdef CONFIG_USER_NS
22559 +               CLONE_NEWUSER |
22560 +#endif
22561 +#ifdef CONFIG_PID_NS
22562 +//             CLONE_NEWPID |
22563 +#endif
22564 +               0
22565 +};
22566 +
22567 +/*
22568 + *     build a new nsproxy mix
22569 + *      assumes that both proxies are 'const'
22570 + *     does not touch nsproxy refcounts
22571 + *     will hold a reference on the result.
22572 + */
22573 +
22574 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
22575 +       struct nsproxy *new_nsproxy, unsigned long mask)
22576 +{
22577 +       struct mnt_namespace *old_ns;
22578 +       struct uts_namespace *old_uts;
22579 +       struct ipc_namespace *old_ipc;
22580 +#ifdef CONFIG_PID_NS
22581 +       struct pid_namespace *old_pid;
22582 +#endif
22583 +#ifdef CONFIG_NET_NS
22584 +       struct net *old_net;
22585 +#endif
22586 +       struct nsproxy *nsproxy;
22587 +
22588 +       nsproxy = copy_nsproxy(old_nsproxy);
22589 +       if (!nsproxy)
22590 +               goto out;
22591 +
22592 +       if (mask & CLONE_NEWNS) {
22593 +               old_ns = nsproxy->mnt_ns;
22594 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
22595 +               if (nsproxy->mnt_ns)
22596 +                       get_mnt_ns(nsproxy->mnt_ns);
22597 +       } else
22598 +               old_ns = NULL;
22599 +
22600 +       if (mask & CLONE_NEWUTS) {
22601 +               old_uts = nsproxy->uts_ns;
22602 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
22603 +               if (nsproxy->uts_ns)
22604 +                       get_uts_ns(nsproxy->uts_ns);
22605 +       } else
22606 +               old_uts = NULL;
22607 +
22608 +       if (mask & CLONE_NEWIPC) {
22609 +               old_ipc = nsproxy->ipc_ns;
22610 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
22611 +               if (nsproxy->ipc_ns)
22612 +                       get_ipc_ns(nsproxy->ipc_ns);
22613 +       } else
22614 +               old_ipc = NULL;
22615 +
22616 +#ifdef CONFIG_PID_NS
22617 +       if (mask & CLONE_NEWPID) {
22618 +               old_pid = nsproxy->pid_ns;
22619 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
22620 +               if (nsproxy->pid_ns)
22621 +                       get_pid_ns(nsproxy->pid_ns);
22622 +       } else
22623 +               old_pid = NULL;
22624 +#endif
22625 +#ifdef CONFIG_NET_NS
22626 +       if (mask & CLONE_NEWNET) {
22627 +               old_net = nsproxy->net_ns;
22628 +               nsproxy->net_ns = new_nsproxy->net_ns;
22629 +               if (nsproxy->net_ns)
22630 +                       get_net(nsproxy->net_ns);
22631 +       } else
22632 +               old_net = NULL;
22633 +#endif
22634 +       if (old_ns)
22635 +               put_mnt_ns(old_ns);
22636 +       if (old_uts)
22637 +               put_uts_ns(old_uts);
22638 +       if (old_ipc)
22639 +               put_ipc_ns(old_ipc);
22640 +#ifdef CONFIG_PID_NS
22641 +       if (old_pid)
22642 +               put_pid_ns(old_pid);
22643 +#endif
22644 +#ifdef CONFIG_NET_NS
22645 +       if (old_net)
22646 +               put_net(old_net);
22647 +#endif
22648 +out:
22649 +       return nsproxy;
22650 +}
22651 +
22652 +
22653 +/*
22654 + *     merge two nsproxy structs into a new one.
22655 + *     will hold a reference on the result.
22656 + */
22657 +
22658 +static inline
22659 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
22660 +       struct nsproxy *proxy, unsigned long mask)
22661 +{
22662 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
22663 +
22664 +       if (!proxy)
22665 +               return NULL;
22666 +
22667 +       if (mask) {
22668 +               /* vs_mix_nsproxy returns with reference */
22669 +               return vs_mix_nsproxy(old ? old : &null_proxy,
22670 +                       proxy, mask);
22671 +       }
22672 +       get_nsproxy(proxy);
22673 +       return proxy;
22674 +}
22675 +
22676 +
22677 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22678 +{
22679 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
22680 +       struct fs_struct *fs_cur, *fs = NULL;
22681 +       struct _vx_space *space;
22682 +       int ret, kill = 0;
22683 +
22684 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
22685 +               vxi, vxi->vx_id, mask, index);
22686 +
22687 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
22688 +               return -EACCES;
22689 +
22690 +       if (index >= VX_SPACES)
22691 +               return -EINVAL;
22692 +
22693 +       space = &vxi->space[index];
22694 +
22695 +       if (!mask)
22696 +               mask = space->vx_nsmask;
22697 +
22698 +       if ((mask & space->vx_nsmask) != mask)
22699 +               return -EINVAL;
22700 +
22701 +       if (mask & CLONE_FS) {
22702 +               fs = copy_fs_struct(space->vx_fs);
22703 +               if (!fs)
22704 +                       return -ENOMEM;
22705 +       }
22706 +       proxy = space->vx_nsproxy;
22707 +
22708 +       vxdprintk(VXD_CBIT(space, 9),
22709 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
22710 +               vxi, vxi->vx_id, mask, index, proxy, fs);
22711 +
22712 +       task_lock(current);
22713 +       fs_cur = current->fs;
22714 +
22715 +       if (mask & CLONE_FS) {
22716 +               spin_lock(&fs_cur->lock);
22717 +               current->fs = fs;
22718 +               kill = !--fs_cur->users;
22719 +               spin_unlock(&fs_cur->lock);
22720 +       }
22721 +
22722 +       proxy_cur = current->nsproxy;
22723 +       get_nsproxy(proxy_cur);
22724 +       task_unlock(current);
22725 +
22726 +       if (kill)
22727 +               free_fs_struct(fs_cur);
22728 +
22729 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
22730 +       if (IS_ERR(proxy_new)) {
22731 +               ret = PTR_ERR(proxy_new);
22732 +               goto out_put;
22733 +       }
22734 +
22735 +       proxy_new = xchg(&current->nsproxy, proxy_new);
22736 +
22737 +       if (mask & CLONE_NEWUSER) {
22738 +               struct cred *cred;
22739 +
22740 +               vxdprintk(VXD_CBIT(space, 10),
22741 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
22742 +                       vxi, vxi->vx_id, space->vx_cred,
22743 +                       current->real_cred, current->cred);
22744 +
22745 +               if (space->vx_cred) {
22746 +                       cred = __prepare_creds(space->vx_cred);
22747 +                       if (cred)
22748 +                               commit_creds(cred);
22749 +               }
22750 +       }
22751 +
22752 +       ret = 0;
22753 +
22754 +       if (proxy_new)
22755 +               put_nsproxy(proxy_new);
22756 +out_put:
22757 +       if (proxy_cur)
22758 +               put_nsproxy(proxy_cur);
22759 +       return ret;
22760 +}
22761 +
22762 +
22763 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22764 +{
22765 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
22766 +       struct fs_struct *fs_vxi, *fs;
22767 +       struct _vx_space *space;
22768 +       int ret, kill = 0;
22769 +
22770 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
22771 +               vxi, vxi->vx_id, mask, index);
22772 +
22773 +       if ((mask & space_mask.mask) != mask)
22774 +               return -EINVAL;
22775 +
22776 +       if (index >= VX_SPACES)
22777 +               return -EINVAL;
22778 +
22779 +       space = &vxi->space[index];
22780 +
22781 +       proxy_vxi = space->vx_nsproxy;
22782 +       fs_vxi = space->vx_fs;
22783 +
22784 +       if (mask & CLONE_FS) {
22785 +               fs = copy_fs_struct(current->fs);
22786 +               if (!fs)
22787 +                       return -ENOMEM;
22788 +       }
22789 +
22790 +       task_lock(current);
22791 +
22792 +       if (mask & CLONE_FS) {
22793 +               spin_lock(&fs_vxi->lock);
22794 +               space->vx_fs = fs;
22795 +               kill = !--fs_vxi->users;
22796 +               spin_unlock(&fs_vxi->lock);
22797 +       }
22798 +
22799 +       proxy_cur = current->nsproxy;
22800 +       get_nsproxy(proxy_cur);
22801 +       task_unlock(current);
22802 +
22803 +       if (kill)
22804 +               free_fs_struct(fs_vxi);
22805 +
22806 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
22807 +       if (IS_ERR(proxy_new)) {
22808 +               ret = PTR_ERR(proxy_new);
22809 +               goto out_put;
22810 +       }
22811 +
22812 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
22813 +       space->vx_nsmask |= mask;
22814 +
22815 +       if (mask & CLONE_NEWUSER) {
22816 +               struct cred *cred;
22817 +
22818 +               vxdprintk(VXD_CBIT(space, 10),
22819 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
22820 +                       vxi, vxi->vx_id, space->vx_cred,
22821 +                       current->real_cred, current->cred);
22822 +
22823 +               cred = prepare_creds();
22824 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
22825 +               if (cred)
22826 +                       abort_creds(cred);
22827 +       }
22828 +
22829 +       ret = 0;
22830 +
22831 +       if (proxy_new)
22832 +               put_nsproxy(proxy_new);
22833 +out_put:
22834 +       if (proxy_cur)
22835 +               put_nsproxy(proxy_cur);
22836 +       return ret;
22837 +}
22838 +
22839 +
22840 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
22841 +{
22842 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22843 +
22844 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22845 +               return -EFAULT;
22846 +
22847 +       return vx_enter_space(vxi, vc_data.mask, 0);
22848 +}
22849 +
22850 +int vc_enter_space(struct vx_info *vxi, void __user *data)
22851 +{
22852 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22853 +
22854 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22855 +               return -EFAULT;
22856 +
22857 +       if (vc_data.index >= VX_SPACES)
22858 +               return -EINVAL;
22859 +
22860 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
22861 +}
22862 +
22863 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
22864 +{
22865 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22866 +
22867 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22868 +               return -EFAULT;
22869 +
22870 +       return vx_set_space(vxi, vc_data.mask, 0);
22871 +}
22872 +
22873 +int vc_set_space(struct vx_info *vxi, void __user *data)
22874 +{
22875 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22876 +
22877 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22878 +               return -EFAULT;
22879 +
22880 +       if (vc_data.index >= VX_SPACES)
22881 +               return -EINVAL;
22882 +
22883 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
22884 +}
22885 +
22886 +int vc_get_space_mask(void __user *data, int type)
22887 +{
22888 +       const struct vcmd_space_mask_v1 *mask;
22889 +
22890 +       if (type == 0)
22891 +               mask = &space_mask_v0;
22892 +       else if (type == 1)
22893 +               mask = &space_mask;
22894 +       else
22895 +               mask = &default_space_mask;
22896 +
22897 +       vxdprintk(VXD_CBIT(space, 10),
22898 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
22899 +
22900 +       if (copy_to_user(data, mask, sizeof(*mask)))
22901 +               return -EFAULT;
22902 +       return 0;
22903 +}
22904 +
22905 diff -NurpP --minimal linux-3.1.6/kernel/vserver/switch.c linux-3.1.6-vs2.3.2.5/kernel/vserver/switch.c
22906 --- linux-3.1.6/kernel/vserver/switch.c 1970-01-01 01:00:00.000000000 +0100
22907 +++ linux-3.1.6-vs2.3.2.5/kernel/vserver/switch.c       2011-10-24 18:53:33.000000000 +0200
22908 @@ -0,0 +1,556 @@
22909 +/*
22910 + *  linux/kernel/vserver/switch.c
22911 + *
22912 + *  Virtual Server: Syscall Switch
22913 + *
22914 + *  Copyright (C) 2003-2011  Herbert Pötzl
22915 + *
22916 + *  V0.01  syscall switch
22917 + *  V0.02  added signal to context
22918 + *  V0.03  added rlimit functions
22919 + *  V0.04  added iattr, task/xid functions
22920 + *  V0.05  added debug/history stuff
22921 + *  V0.06  added compat32 layer
22922 + *  V0.07  vcmd args and perms
22923 + *  V0.08  added status commands
22924 + *  V0.09  added tag commands
22925 + *  V0.10  added oom bias
22926 + *  V0.11  added device commands
22927 + *  V0.12  added warn mask
22928 + *
22929 + */
22930 +
22931 +#include <linux/vs_context.h>
22932 +#include <linux/vs_network.h>
22933 +#include <linux/vserver/switch.h>
22934 +
22935 +#include "vci_config.h"
22936 +
22937 +
22938 +static inline
22939 +int vc_get_version(uint32_t id)
22940 +{
22941 +       return VCI_VERSION;
22942 +}
22943 +
22944 +static inline
22945 +int vc_get_vci(uint32_t id)
22946 +{
22947 +       return vci_kernel_config();
22948 +}
22949 +
22950 +#include <linux/vserver/context_cmd.h>
22951 +#include <linux/vserver/cvirt_cmd.h>
22952 +#include <linux/vserver/cacct_cmd.h>
22953 +#include <linux/vserver/limit_cmd.h>
22954 +#include <linux/vserver/network_cmd.h>
22955 +#include <linux/vserver/sched_cmd.h>
22956 +#include <linux/vserver/debug_cmd.h>
22957 +#include <linux/vserver/inode_cmd.h>
22958 +#include <linux/vserver/dlimit_cmd.h>
22959 +#include <linux/vserver/signal_cmd.h>
22960 +#include <linux/vserver/space_cmd.h>
22961 +#include <linux/vserver/tag_cmd.h>
22962 +#include <linux/vserver/device_cmd.h>
22963 +
22964 +#include <linux/vserver/inode.h>
22965 +#include <linux/vserver/dlimit.h>
22966 +
22967 +
22968 +#ifdef CONFIG_COMPAT
22969 +#define __COMPAT(name, id, data, compat)       \
22970 +       (compat) ? name ## _x32(id, data) : name(id, data)
22971 +#define __COMPAT_NO_ID(name, data, compat)     \
22972 +       (compat) ? name ## _x32(data) : name(data)
22973 +#else
22974 +#define __COMPAT(name, id, data, compat)       \
22975 +       name(id, data)
22976 +#define __COMPAT_NO_ID(name, data, compat)     \
22977 +       name(data)
22978 +#endif
22979 +
22980 +
22981 +static inline
22982 +long do_vcmd(uint32_t cmd, uint32_t id,
22983 +       struct vx_info *vxi, struct nx_info *nxi,
22984 +       void __user *data, int compat)
22985 +{
22986 +       switch (cmd) {
22987 +
22988 +       case VCMD_get_version:
22989 +               return vc_get_version(id);
22990 +       case VCMD_get_vci:
22991 +               return vc_get_vci(id);
22992 +
22993 +       case VCMD_task_xid:
22994 +               return vc_task_xid(id);
22995 +       case VCMD_vx_info:
22996 +               return vc_vx_info(vxi, data);
22997 +
22998 +       case VCMD_task_nid:
22999 +               return vc_task_nid(id);
23000 +       case VCMD_nx_info:
23001 +               return vc_nx_info(nxi, data);
23002 +
23003 +       case VCMD_task_tag:
23004 +               return vc_task_tag(id);
23005 +
23006 +       case VCMD_set_space_v1:
23007 +               return vc_set_space_v1(vxi, data);
23008 +       /* this is version 2 */
23009 +       case VCMD_set_space:
23010 +               return vc_set_space(vxi, data);
23011 +
23012 +       case VCMD_get_space_mask_v0:
23013 +               return vc_get_space_mask(data, 0);
23014 +       /* this is version 1 */
23015 +       case VCMD_get_space_mask:
23016 +               return vc_get_space_mask(data, 1);
23017 +
23018 +       case VCMD_get_space_default:
23019 +               return vc_get_space_mask(data, -1);
23020 +
23021 +       case VCMD_set_umask:
23022 +               return vc_set_umask(vxi, data);
23023 +
23024 +       case VCMD_get_umask:
23025 +               return vc_get_umask(vxi, data);
23026 +
23027 +       case VCMD_set_wmask:
23028 +               return vc_set_wmask(vxi, data);
23029 +
23030 +       case VCMD_get_wmask:
23031 +               return vc_get_wmask(vxi, data);
23032 +#ifdef CONFIG_IA32_EMULATION
23033 +       case VCMD_get_rlimit:
23034 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
23035 +       case VCMD_set_rlimit:
23036 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
23037 +#else
23038 +       case VCMD_get_rlimit:
23039 +               return vc_get_rlimit(vxi, data);
23040 +       case VCMD_set_rlimit:
23041 +               return vc_set_rlimit(vxi, data);
23042 +#endif
23043 +       case VCMD_get_rlimit_mask:
23044 +               return vc_get_rlimit_mask(id, data);
23045 +       case VCMD_reset_hits:
23046 +               return vc_reset_hits(vxi, data);
23047 +       case VCMD_reset_minmax:
23048 +               return vc_reset_minmax(vxi, data);
23049 +
23050 +       case VCMD_get_vhi_name:
23051 +               return vc_get_vhi_name(vxi, data);
23052 +       case VCMD_set_vhi_name:
23053 +               return vc_set_vhi_name(vxi, data);
23054 +
23055 +       case VCMD_ctx_stat:
23056 +               return vc_ctx_stat(vxi, data);
23057 +       case VCMD_virt_stat:
23058 +               return vc_virt_stat(vxi, data);
23059 +       case VCMD_sock_stat:
23060 +               return vc_sock_stat(vxi, data);
23061 +       case VCMD_rlimit_stat:
23062 +               return vc_rlimit_stat(vxi, data);
23063 +
23064 +       case VCMD_set_cflags:
23065 +               return vc_set_cflags(vxi, data);
23066 +       case VCMD_get_cflags:
23067 +               return vc_get_cflags(vxi, data);
23068 +
23069 +       /* this is version 1 */
23070 +       case VCMD_set_ccaps:
23071 +               return vc_set_ccaps(vxi, data);
23072 +       /* this is version 1 */
23073 +       case VCMD_get_ccaps:
23074 +               return vc_get_ccaps(vxi, data);
23075 +       case VCMD_set_bcaps:
23076 +               return vc_set_bcaps(vxi, data);
23077 +       case VCMD_get_bcaps:
23078 +               return vc_get_bcaps(vxi, data);
23079 +
23080 +       case VCMD_set_badness:
23081 +               return vc_set_badness(vxi, data);
23082 +       case VCMD_get_badness:
23083 +               return vc_get_badness(vxi, data);
23084 +
23085 +       case VCMD_set_nflags:
23086 +               return vc_set_nflags(nxi, data);
23087 +       case VCMD_get_nflags:
23088 +               return vc_get_nflags(nxi, data);
23089 +
23090 +       case VCMD_set_ncaps:
23091 +               return vc_set_ncaps(nxi, data);
23092 +       case VCMD_get_ncaps:
23093 +               return vc_get_ncaps(nxi, data);
23094 +
23095 +       case VCMD_set_prio_bias:
23096 +               return vc_set_prio_bias(vxi, data);
23097 +       case VCMD_get_prio_bias:
23098 +               return vc_get_prio_bias(vxi, data);
23099 +       case VCMD_add_dlimit:
23100 +               return __COMPAT(vc_add_dlimit, id, data, compat);
23101 +       case VCMD_rem_dlimit:
23102 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
23103 +       case VCMD_set_dlimit:
23104 +               return __COMPAT(vc_set_dlimit, id, data, compat);
23105 +       case VCMD_get_dlimit:
23106 +               return __COMPAT(vc_get_dlimit, id, data, compat);
23107 +
23108 +       case VCMD_ctx_kill:
23109 +               return vc_ctx_kill(vxi, data);
23110 +
23111 +       case VCMD_wait_exit:
23112 +               return vc_wait_exit(vxi, data);
23113 +
23114 +       case VCMD_get_iattr:
23115 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
23116 +       case VCMD_set_iattr:
23117 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
23118 +
23119 +       case VCMD_fget_iattr:
23120 +               return vc_fget_iattr(id, data);
23121 +       case VCMD_fset_iattr:
23122 +               return vc_fset_iattr(id, data);
23123 +
23124 +       case VCMD_enter_space_v0:
23125 +               return vc_enter_space_v1(vxi, NULL);
23126 +       case VCMD_enter_space_v1:
23127 +               return vc_enter_space_v1(vxi, data);
23128 +       /* this is version 2 */
23129 +       case VCMD_enter_space:
23130 +               return vc_enter_space(vxi, data);
23131 +
23132 +       case VCMD_ctx_create_v0:
23133 +               return vc_ctx_create(id, NULL);
23134 +       case VCMD_ctx_create:
23135 +               return vc_ctx_create(id, data);
23136 +       case VCMD_ctx_migrate_v0:
23137 +               return vc_ctx_migrate(vxi, NULL);
23138 +       case VCMD_ctx_migrate:
23139 +               return vc_ctx_migrate(vxi, data);
23140 +
23141 +       case VCMD_net_create_v0:
23142 +               return vc_net_create(id, NULL);
23143 +       case VCMD_net_create:
23144 +               return vc_net_create(id, data);
23145 +       case VCMD_net_migrate:
23146 +               return vc_net_migrate(nxi, data);
23147 +
23148 +       case VCMD_tag_migrate:
23149 +               return vc_tag_migrate(id);
23150 +
23151 +       case VCMD_net_add:
23152 +               return vc_net_add(nxi, data);
23153 +       case VCMD_net_remove:
23154 +               return vc_net_remove(nxi, data);
23155 +
23156 +       case VCMD_net_add_ipv4_v1:
23157 +               return vc_net_add_ipv4_v1(nxi, data);
23158 +       /* this is version 2 */
23159 +       case VCMD_net_add_ipv4:
23160 +               return vc_net_add_ipv4(nxi, data);
23161 +
23162 +       case VCMD_net_rem_ipv4_v1:
23163 +               return vc_net_rem_ipv4_v1(nxi, data);
23164 +       /* this is version 2 */
23165 +       case VCMD_net_rem_ipv4:
23166 +               return vc_net_rem_ipv4(nxi, data);
23167 +#ifdef CONFIG_IPV6
23168 +       case VCMD_net_add_ipv6:
23169 +               return vc_net_add_ipv6(nxi, data);
23170 +       case VCMD_net_remove_ipv6:
23171 +               return vc_net_remove_ipv6(nxi, data);
23172 +#endif
23173 +/*     case VCMD_add_match_ipv4:
23174 +               return vc_add_match_ipv4(nxi, data);
23175 +       case VCMD_get_match_ipv4:
23176 +               return vc_get_match_ipv4(nxi, data);
23177 +#ifdef CONFIG_IPV6
23178 +       case VCMD_add_match_ipv6:
23179 +               return vc_add_match_ipv6(nxi, data);
23180 +       case VCMD_get_match_ipv6:
23181 +               return vc_get_match_ipv6(nxi, data);
23182 +#endif */
23183 +
23184 +#ifdef CONFIG_VSERVER_DEVICE
23185 +       case VCMD_set_mapping:
23186 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
23187 +       case VCMD_unset_mapping:
23188 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
23189 +#endif
23190 +#ifdef CONFIG_VSERVER_HISTORY
23191 +       case VCMD_dump_history:
23192 +               return vc_dump_history(id);
23193 +       case VCMD_read_history:
23194 +               return __COMPAT(vc_read_history, id, data, compat);
23195 +#endif
23196 +       default:
23197 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
23198 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
23199 +       }
23200 +       return -ENOSYS;
23201 +}
23202 +
23203 +
23204 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
23205 +       case VCMD_ ## vcmd: perm = _perm;               \
23206 +               args = _args; flags = _flags; break
23207 +
23208 +
23209 +#define VCA_NONE       0x00
23210 +#define VCA_VXI                0x01
23211 +#define VCA_NXI                0x02
23212 +
23213 +#define VCF_NONE       0x00
23214 +#define VCF_INFO       0x01
23215 +#define VCF_ADMIN      0x02
23216 +#define VCF_ARES       0x06    /* includes admin */
23217 +#define VCF_SETUP      0x08
23218 +
23219 +#define VCF_ZIDOK      0x10    /* zero id okay */
23220 +
23221 +
23222 +static inline
23223 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
23224 +{
23225 +       long ret;
23226 +       int permit = -1, state = 0;
23227 +       int perm = -1, args = 0, flags = 0;
23228 +       struct vx_info *vxi = NULL;
23229 +       struct nx_info *nxi = NULL;
23230 +
23231 +       switch (cmd) {
23232 +       /* unpriviledged commands */
23233 +       __VCMD(get_version,      0, VCA_NONE,   0);
23234 +       __VCMD(get_vci,          0, VCA_NONE,   0);
23235 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
23236 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
23237 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
23238 +       __VCMD(get_space_default,0, VCA_NONE,   0);
23239 +
23240 +       /* info commands */
23241 +       __VCMD(task_xid,         2, VCA_NONE,   0);
23242 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
23243 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
23244 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
23245 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
23246 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
23247 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
23248 +       __VCMD(get_umask,        3, VCA_VXI,    VCF_INFO);
23249 +       __VCMD(get_wmask,        3, VCA_VXI,    VCF_INFO);
23250 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
23251 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
23252 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
23253 +
23254 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
23255 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
23256 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
23257 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
23258 +
23259 +       __VCMD(task_nid,         2, VCA_NONE,   0);
23260 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
23261 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
23262 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
23263 +
23264 +       __VCMD(task_tag,         2, VCA_NONE,   0);
23265 +
23266 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
23267 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
23268 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
23269 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
23270 +
23271 +       /* lower admin commands */
23272 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
23273 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
23274 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
23275 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
23276 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
23277 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
23278 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
23279 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
23280 +
23281 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
23282 +       __VCMD(net_create,       5, VCA_NONE,   0);
23283 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
23284 +
23285 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
23286 +
23287 +       /* higher admin commands */
23288 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
23289 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23290 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23291 +
23292 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23293 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23294 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23295 +       __VCMD(set_umask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23296 +       __VCMD(set_wmask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23297 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23298 +
23299 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23300 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23301 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23302 +
23303 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23304 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23305 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23306 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23307 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23308 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23309 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23310 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23311 +#ifdef CONFIG_IPV6
23312 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23313 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23314 +#endif
23315 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
23316 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
23317 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
23318 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
23319 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
23320 +
23321 +#ifdef CONFIG_VSERVER_DEVICE
23322 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23323 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23324 +#endif
23325 +       /* debug level admin commands */
23326 +#ifdef CONFIG_VSERVER_HISTORY
23327 +       __VCMD(dump_history,     9, VCA_NONE,   0);
23328 +       __VCMD(read_history,     9, VCA_NONE,   0);
23329 +#endif
23330 +
23331 +       default:
23332 +               perm = -1;
23333 +       }
23334 +
23335 +       vxdprintk(VXD_CBIT(switch, 0),
23336 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
23337 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23338 +               VC_VERSION(cmd), id, data, compat,
23339 +               perm, args, flags);
23340 +
23341 +       ret = -ENOSYS;
23342 +       if (perm < 0)
23343 +               goto out;
23344 +
23345 +       state = 1;
23346 +       if (!capable(CAP_CONTEXT))
23347 +               goto out;
23348 +
23349 +       state = 2;
23350 +       /* moved here from the individual commands */
23351 +       ret = -EPERM;
23352 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
23353 +               goto out;
23354 +
23355 +       state = 3;
23356 +       /* vcmd involves resource management  */
23357 +       ret = -EPERM;
23358 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
23359 +               goto out;
23360 +
23361 +       state = 4;
23362 +       /* various legacy exceptions */
23363 +       switch (cmd) {
23364 +       /* will go away when spectator is a cap */
23365 +       case VCMD_ctx_migrate_v0:
23366 +       case VCMD_ctx_migrate:
23367 +               if (id == 1) {
23368 +                       current->xid = 1;
23369 +                       ret = 1;
23370 +                       goto out;
23371 +               }
23372 +               break;
23373 +
23374 +       /* will go away when spectator is a cap */
23375 +       case VCMD_net_migrate:
23376 +               if (id == 1) {
23377 +                       current->nid = 1;
23378 +                       ret = 1;
23379 +                       goto out;
23380 +               }
23381 +               break;
23382 +       }
23383 +
23384 +       /* vcmds are fine by default */
23385 +       permit = 1;
23386 +
23387 +       /* admin type vcmds require admin ... */
23388 +       if (flags & VCF_ADMIN)
23389 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
23390 +
23391 +       /* ... but setup type vcmds override that */
23392 +       if (!permit && (flags & VCF_SETUP))
23393 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
23394 +
23395 +       state = 5;
23396 +       ret = -EPERM;
23397 +       if (!permit)
23398 +               goto out;
23399 +
23400 +       state = 6;
23401 +       if (!id && (flags & VCF_ZIDOK))
23402 +               goto skip_id;
23403 +
23404 +       ret = -ESRCH;
23405 +       if (args & VCA_VXI) {
23406 +               vxi = lookup_vx_info(id);
23407 +               if (!vxi)
23408 +                       goto out;
23409 +
23410 +               if ((flags & VCF_ADMIN) &&
23411 +                       /* special case kill for shutdown */
23412 +                       (cmd != VCMD_ctx_kill) &&
23413 +                       /* can context be administrated? */
23414 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
23415 +                       ret = -EACCES;
23416 +                       goto out_vxi;
23417 +               }
23418 +       }
23419 +       state = 7;
23420 +       if (args & VCA_NXI) {
23421 +               nxi = lookup_nx_info(id);
23422 +               if (!nxi)
23423 +                       goto out_vxi;
23424 +
23425 +               if ((flags & VCF_ADMIN) &&
23426 +                       /* can context be administrated? */
23427 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
23428 +                       ret = -EACCES;
23429 +                       goto out_nxi;
23430 +               }
23431 +       }
23432 +skip_id:
23433 +       state = 8;
23434 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
23435 +
23436 +out_nxi:
23437 +       if ((args & VCA_NXI) && nxi)
23438 +               put_nx_info(nxi);
23439 +out_vxi:
23440 +       if ((args & VCA_VXI) && vxi)
23441 +               put_vx_info(vxi);
23442 +out:
23443 +       vxdprintk(VXD_CBIT(switch, 1),
23444 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
23445 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23446 +               VC_VERSION(cmd), ret, ret, state, permit);
23447 +       return ret;
23448 +}
23449 +
23450 +asmlinkage long
23451 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
23452 +{
23453 +       return do_vserver(cmd, id, data, 0);
23454 +}
23455 +
23456 +#ifdef CONFIG_COMPAT
23457 +
23458 +asmlinkage long
23459 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
23460 +{
23461 +       return do_vserver(cmd, id, data, 1);
23462 +}
23463 +
23464 +#endif /* CONFIG_COMPAT */
23465 diff -NurpP --minimal linux-3.1.6/kernel/vserver/sysctl.c linux-3.1.6-vs2.3.2.5/kernel/vserver/sysctl.c
23466 --- linux-3.1.6/kernel/vserver/sysctl.c 1970-01-01 01:00:00.000000000 +0100
23467 +++ linux-3.1.6-vs2.3.2.5/kernel/vserver/sysctl.c       2011-11-18 00:40:25.000000000 +0100
23468 @@ -0,0 +1,247 @@
23469 +/*
23470 + *  kernel/vserver/sysctl.c
23471 + *
23472 + *  Virtual Context Support
23473 + *
23474 + *  Copyright (C) 2004-2007  Herbert Pötzl
23475 + *
23476 + *  V0.01  basic structure
23477 + *
23478 + */
23479 +
23480 +#include <linux/module.h>
23481 +#include <linux/ctype.h>
23482 +#include <linux/sysctl.h>
23483 +#include <linux/parser.h>
23484 +#include <asm/uaccess.h>
23485 +
23486 +enum {
23487 +       CTL_DEBUG_ERROR         = 0,
23488 +       CTL_DEBUG_SWITCH        = 1,
23489 +       CTL_DEBUG_XID,
23490 +       CTL_DEBUG_NID,
23491 +       CTL_DEBUG_TAG,
23492 +       CTL_DEBUG_NET,
23493 +       CTL_DEBUG_LIMIT,
23494 +       CTL_DEBUG_CRES,
23495 +       CTL_DEBUG_DLIM,
23496 +       CTL_DEBUG_QUOTA,
23497 +       CTL_DEBUG_CVIRT,
23498 +       CTL_DEBUG_SPACE,
23499 +       CTL_DEBUG_PERM,
23500 +       CTL_DEBUG_MISC,
23501 +};
23502 +
23503 +
23504 +unsigned int vs_debug_switch   = 0;
23505 +unsigned int vs_debug_xid      = 0;
23506 +unsigned int vs_debug_nid      = 0;
23507 +unsigned int vs_debug_tag      = 0;
23508 +unsigned int vs_debug_net      = 0;
23509 +unsigned int vs_debug_limit    = 0;
23510 +unsigned int vs_debug_cres     = 0;
23511 +unsigned int vs_debug_dlim     = 0;
23512 +unsigned int vs_debug_quota    = 0;
23513 +unsigned int vs_debug_cvirt    = 0;
23514 +unsigned int vs_debug_space    = 0;
23515 +unsigned int vs_debug_perm     = 0;
23516 +unsigned int vs_debug_misc     = 0;
23517 +
23518 +
23519 +static struct ctl_table_header *vserver_table_header;
23520 +static ctl_table vserver_root_table[];
23521 +
23522 +
23523 +void vserver_register_sysctl(void)
23524 +{
23525 +       if (!vserver_table_header) {
23526 +               vserver_table_header = register_sysctl_table(vserver_root_table);
23527 +       }
23528 +
23529 +}
23530 +
23531 +void vserver_unregister_sysctl(void)
23532 +{
23533 +       if (vserver_table_header) {
23534 +               unregister_sysctl_table(vserver_table_header);
23535 +               vserver_table_header = NULL;
23536 +       }
23537 +}
23538 +
23539 +
23540 +static int proc_dodebug(ctl_table *table, int write,
23541 +       void __user *buffer, size_t *lenp, loff_t *ppos)
23542 +{
23543 +       char            tmpbuf[20], *p, c;
23544 +       unsigned int    value;
23545 +       size_t          left, len;
23546 +
23547 +       if ((*ppos && !write) || !*lenp) {
23548 +               *lenp = 0;
23549 +               return 0;
23550 +       }
23551 +
23552 +       left = *lenp;
23553 +
23554 +       if (write) {
23555 +               if (!access_ok(VERIFY_READ, buffer, left))
23556 +                       return -EFAULT;
23557 +               p = (char *)buffer;
23558 +               while (left && __get_user(c, p) >= 0 && isspace(c))
23559 +                       left--, p++;
23560 +               if (!left)
23561 +                       goto done;
23562 +
23563 +               if (left > sizeof(tmpbuf) - 1)
23564 +                       return -EINVAL;
23565 +               if (copy_from_user(tmpbuf, p, left))
23566 +                       return -EFAULT;
23567 +               tmpbuf[left] = '\0';
23568 +
23569 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
23570 +                       value = 10 * value + (*p - '0');
23571 +               if (*p && !isspace(*p))
23572 +                       return -EINVAL;
23573 +               while (left && isspace(*p))
23574 +                       left--, p++;
23575 +               *(unsigned int *)table->data = value;
23576 +       } else {
23577 +               if (!access_ok(VERIFY_WRITE, buffer, left))
23578 +                       return -EFAULT;
23579 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
23580 +               if (len > left)
23581 +                       len = left;
23582 +               if (__copy_to_user(buffer, tmpbuf, len))
23583 +                       return -EFAULT;
23584 +               if ((left -= len) > 0) {
23585 +                       if (put_user('\n', (char *)buffer + len))
23586 +                               return -EFAULT;
23587 +                       left--;
23588 +               }
23589 +       }
23590 +
23591 +done:
23592 +       *lenp -= left;
23593 +       *ppos += *lenp;
23594 +       return 0;
23595 +}
23596 +
23597 +static int zero;
23598 +
23599 +#define        CTL_ENTRY(ctl, name)                            \
23600 +       {                                               \
23601 +               .procname       = #name,                \
23602 +               .data           = &vs_ ## name,         \
23603 +               .maxlen         = sizeof(int),          \
23604 +               .mode           = 0644,                 \
23605 +               .proc_handler   = &proc_dodebug,        \
23606 +               .extra1         = &zero,                \
23607 +               .extra2         = &zero,                \
23608 +       }
23609 +
23610 +static ctl_table vserver_debug_table[] = {
23611 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
23612 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
23613 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
23614 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
23615 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
23616 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
23617 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
23618 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
23619 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
23620 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
23621 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
23622 +       CTL_ENTRY(CTL_DEBUG_PERM,       debug_perm),
23623 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
23624 +       { 0 }
23625 +};
23626 +
23627 +static ctl_table vserver_root_table[] = {
23628 +       {
23629 +               .procname       = "vserver",
23630 +               .mode           = 0555,
23631 +               .child          = vserver_debug_table
23632 +       },
23633 +       { 0 }
23634 +};
23635 +
23636 +
23637 +static match_table_t tokens = {
23638 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
23639 +       { CTL_DEBUG_XID,        "xid=%x"        },
23640 +       { CTL_DEBUG_NID,        "nid=%x"        },
23641 +       { CTL_DEBUG_TAG,        "tag=%x"        },
23642 +       { CTL_DEBUG_NET,        "net=%x"        },
23643 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
23644 +       { CTL_DEBUG_CRES,       "cres=%x"       },
23645 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
23646 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
23647 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
23648 +       { CTL_DEBUG_SPACE,      "space=%x"      },
23649 +       { CTL_DEBUG_PERM,       "perm=%x"       },
23650 +       { CTL_DEBUG_MISC,       "misc=%x"       },
23651 +       { CTL_DEBUG_ERROR,      NULL            }
23652 +};
23653 +
23654 +#define        HANDLE_CASE(id, name, val)                              \
23655 +       case CTL_DEBUG_ ## id:                                  \
23656 +               vs_debug_ ## name = val;                        \
23657 +               printk("vs_debug_" #name "=0x%x\n", val);       \
23658 +               break
23659 +
23660 +
23661 +static int __init vs_debug_setup(char *str)
23662 +{
23663 +       char *p;
23664 +       int token;
23665 +
23666 +       printk("vs_debug_setup(%s)\n", str);
23667 +       while ((p = strsep(&str, ",")) != NULL) {
23668 +               substring_t args[MAX_OPT_ARGS];
23669 +               unsigned int value;
23670 +
23671 +               if (!*p)
23672 +                       continue;
23673 +
23674 +               token = match_token(p, tokens, args);
23675 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
23676 +
23677 +               switch (token) {
23678 +               HANDLE_CASE(SWITCH, switch, value);
23679 +               HANDLE_CASE(XID,    xid,    value);
23680 +               HANDLE_CASE(NID,    nid,    value);
23681 +               HANDLE_CASE(TAG,    tag,    value);
23682 +               HANDLE_CASE(NET,    net,    value);
23683 +               HANDLE_CASE(LIMIT,  limit,  value);
23684 +               HANDLE_CASE(CRES,   cres,   value);
23685 +               HANDLE_CASE(DLIM,   dlim,   value);
23686 +               HANDLE_CASE(QUOTA,  quota,  value);
23687 +               HANDLE_CASE(CVIRT,  cvirt,  value);
23688 +               HANDLE_CASE(SPACE,  space,  value);
23689 +               HANDLE_CASE(PERM,   perm,   value);
23690 +               HANDLE_CASE(MISC,   misc,   value);
23691 +               default:
23692 +                       return -EINVAL;
23693 +                       break;
23694 +               }
23695 +       }
23696 +       return 1;
23697 +}
23698 +
23699 +__setup("vsdebug=", vs_debug_setup);
23700 +
23701 +
23702 +
23703 +EXPORT_SYMBOL_GPL(vs_debug_switch);
23704 +EXPORT_SYMBOL_GPL(vs_debug_xid);
23705 +EXPORT_SYMBOL_GPL(vs_debug_nid);
23706 +EXPORT_SYMBOL_GPL(vs_debug_net);
23707 +EXPORT_SYMBOL_GPL(vs_debug_limit);
23708 +EXPORT_SYMBOL_GPL(vs_debug_cres);
23709 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
23710 +EXPORT_SYMBOL_GPL(vs_debug_quota);
23711 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
23712 +EXPORT_SYMBOL_GPL(vs_debug_space);
23713 +EXPORT_SYMBOL_GPL(vs_debug_perm);
23714 +EXPORT_SYMBOL_GPL(vs_debug_misc);
23715 +
23716 diff -NurpP --minimal linux-3.1.6/kernel/vserver/tag.c linux-3.1.6-vs2.3.2.5/kernel/vserver/tag.c
23717 --- linux-3.1.6/kernel/vserver/tag.c    1970-01-01 01:00:00.000000000 +0100
23718 +++ linux-3.1.6-vs2.3.2.5/kernel/vserver/tag.c  2011-10-24 18:53:33.000000000 +0200
23719 @@ -0,0 +1,63 @@
23720 +/*
23721 + *  linux/kernel/vserver/tag.c
23722 + *
23723 + *  Virtual Server: Shallow Tag Space
23724 + *
23725 + *  Copyright (C) 2007  Herbert Pötzl
23726 + *
23727 + *  V0.01  basic implementation
23728 + *
23729 + */
23730 +
23731 +#include <linux/sched.h>
23732 +#include <linux/vserver/debug.h>
23733 +#include <linux/vs_pid.h>
23734 +#include <linux/vs_tag.h>
23735 +
23736 +#include <linux/vserver/tag_cmd.h>
23737 +
23738 +
23739 +int dx_migrate_task(struct task_struct *p, tag_t tag)
23740 +{
23741 +       if (!p)
23742 +               BUG();
23743 +
23744 +       vxdprintk(VXD_CBIT(tag, 5),
23745 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
23746 +
23747 +       task_lock(p);
23748 +       p->tag = tag;
23749 +       task_unlock(p);
23750 +
23751 +       vxdprintk(VXD_CBIT(tag, 5),
23752 +               "moved task %p into [#%d]", p, tag);
23753 +       return 0;
23754 +}
23755 +
23756 +/* vserver syscall commands below here */
23757 +
23758 +/* taks xid and vx_info functions */
23759 +
23760 +
23761 +int vc_task_tag(uint32_t id)
23762 +{
23763 +       tag_t tag;
23764 +
23765 +       if (id) {
23766 +               struct task_struct *tsk;
23767 +               rcu_read_lock();
23768 +               tsk = find_task_by_real_pid(id);
23769 +               tag = (tsk) ? tsk->tag : -ESRCH;
23770 +               rcu_read_unlock();
23771 +       } else
23772 +               tag = dx_current_tag();
23773 +       return tag;
23774 +}
23775 +
23776 +
23777 +int vc_tag_migrate(uint32_t tag)
23778 +{
23779 +       return dx_migrate_task(current, tag & 0xFFFF);
23780 +}
23781 +
23782 +
23783 diff -NurpP --minimal linux-3.1.6/kernel/vserver/vci_config.h linux-3.1.6-vs2.3.2.5/kernel/vserver/vci_config.h
23784 --- linux-3.1.6/kernel/vserver/vci_config.h     1970-01-01 01:00:00.000000000 +0100
23785 +++ linux-3.1.6-vs2.3.2.5/kernel/vserver/vci_config.h   2011-10-24 18:53:33.000000000 +0200
23786 @@ -0,0 +1,76 @@
23787 +
23788 +/*  interface version */
23789 +
23790 +#define VCI_VERSION            0x00020308
23791 +
23792 +
23793 +enum {
23794 +       VCI_KCBIT_NO_DYNAMIC = 0,
23795 +
23796 +       VCI_KCBIT_PROC_SECURE = 4,
23797 +       /* VCI_KCBIT_HARDCPU = 5, */
23798 +       /* VCI_KCBIT_IDLELIMIT = 6, */
23799 +       /* VCI_KCBIT_IDLETIME = 7, */
23800 +
23801 +       VCI_KCBIT_COWBL = 8,
23802 +       VCI_KCBIT_FULLCOWBL = 9,
23803 +       VCI_KCBIT_SPACES = 10,
23804 +       VCI_KCBIT_NETV2 = 11,
23805 +       VCI_KCBIT_MEMCG = 12,
23806 +
23807 +       VCI_KCBIT_DEBUG = 16,
23808 +       VCI_KCBIT_HISTORY = 20,
23809 +       VCI_KCBIT_TAGGED = 24,
23810 +       VCI_KCBIT_PPTAG = 28,
23811 +
23812 +       VCI_KCBIT_MORE = 31,
23813 +};
23814 +
23815 +
23816 +static inline uint32_t vci_kernel_config(void)
23817 +{
23818 +       return
23819 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
23820 +
23821 +       /* configured features */
23822 +#ifdef CONFIG_VSERVER_PROC_SECURE
23823 +       (1 << VCI_KCBIT_PROC_SECURE) |
23824 +#endif
23825 +#ifdef CONFIG_VSERVER_COWBL
23826 +       (1 << VCI_KCBIT_COWBL) |
23827 +       (1 << VCI_KCBIT_FULLCOWBL) |
23828 +#endif
23829 +       (1 << VCI_KCBIT_SPACES) |
23830 +       (1 << VCI_KCBIT_NETV2) |
23831 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
23832 +       (1 << VCI_KCBIT_MEMCG) |
23833 +#endif
23834 +
23835 +       /* debug options */
23836 +#ifdef CONFIG_VSERVER_DEBUG
23837 +       (1 << VCI_KCBIT_DEBUG) |
23838 +#endif
23839 +#ifdef CONFIG_VSERVER_HISTORY
23840 +       (1 << VCI_KCBIT_HISTORY) |
23841 +#endif
23842 +
23843 +       /* inode context tagging */
23844 +#if    defined(CONFIG_TAGGING_NONE)
23845 +       (0 << VCI_KCBIT_TAGGED) |
23846 +#elif  defined(CONFIG_TAGGING_UID16)
23847 +       (1 << VCI_KCBIT_TAGGED) |
23848 +#elif  defined(CONFIG_TAGGING_GID16)
23849 +       (2 << VCI_KCBIT_TAGGED) |
23850 +#elif  defined(CONFIG_TAGGING_ID24)
23851 +       (3 << VCI_KCBIT_TAGGED) |
23852 +#elif  defined(CONFIG_TAGGING_INTERN)
23853 +       (4 << VCI_KCBIT_TAGGED) |
23854 +#elif  defined(CONFIG_TAGGING_RUNTIME)
23855 +       (5 << VCI_KCBIT_TAGGED) |
23856 +#else
23857 +       (7 << VCI_KCBIT_TAGGED) |
23858 +#endif
23859 +       (1 << VCI_KCBIT_PPTAG) |
23860 +       0;
23861 +}
23862 +
23863 diff -NurpP --minimal linux-3.1.6/mm/memcontrol.c linux-3.1.6-vs2.3.2.5/mm/memcontrol.c
23864 --- linux-3.1.6/mm/memcontrol.c 2011-10-24 18:45:33.000000000 +0200
23865 +++ linux-3.1.6-vs2.3.2.5/mm/memcontrol.c       2011-10-24 18:53:33.000000000 +0200
23866 @@ -760,6 +760,31 @@ struct mem_cgroup *mem_cgroup_from_task(
23867                                 struct mem_cgroup, css);
23868  }
23869  
23870 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
23871 +{
23872 +       return res_counter_read_u64(&mem->res, member);
23873 +}
23874 +
23875 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
23876 +{
23877 +       return res_counter_read_u64(&mem->memsw, member);
23878 +}
23879 +
23880 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
23881 +{
23882 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
23883 +}
23884 +
23885 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
23886 +{
23887 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
23888 +}
23889 +
23890 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
23891 +{
23892 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
23893 +}
23894 +
23895  struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
23896  {
23897         struct mem_cgroup *mem = NULL;
23898 diff -NurpP --minimal linux-3.1.6/mm/oom_kill.c linux-3.1.6-vs2.3.2.5/mm/oom_kill.c
23899 --- linux-3.1.6/mm/oom_kill.c   2011-10-24 18:45:33.000000000 +0200
23900 +++ linux-3.1.6-vs2.3.2.5/mm/oom_kill.c 2011-12-07 04:20:11.000000000 +0100
23901 @@ -32,6 +32,8 @@
23902  #include <linux/mempolicy.h>
23903  #include <linux/security.h>
23904  #include <linux/ptrace.h>
23905 +#include <linux/reboot.h>
23906 +#include <linux/vs_context.h>
23907  
23908  int sysctl_panic_on_oom;
23909  int sysctl_oom_kill_allocating_task;
23910 @@ -134,11 +136,18 @@ struct task_struct *find_lock_task_mm(st
23911  static bool oom_unkillable_task(struct task_struct *p,
23912                 const struct mem_cgroup *mem, const nodemask_t *nodemask)
23913  {
23914 -       if (is_global_init(p))
23915 +       unsigned xid = vx_current_xid();
23916 +
23917 +       /* skip the init task, global and per guest */
23918 +       if (task_is_init(p))
23919                 return true;
23920         if (p->flags & PF_KTHREAD)
23921                 return true;
23922  
23923 +       /* skip other guest and host processes if oom in guest */
23924 +       if (xid && vx_task_xid(p) != xid)
23925 +               return true;
23926 +
23927         /* When mem_cgroup_out_of_memory() and p is not member of the group */
23928         if (mem && !task_in_mem_cgroup(p, mem))
23929                 return true;
23930 @@ -428,8 +437,8 @@ static int oom_kill_task(struct task_str
23931         /* mm cannot be safely dereferenced after task_unlock(p) */
23932         mm = p->mm;
23933  
23934 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23935 -               task_pid_nr(p), p->comm, K(p->mm->total_vm),
23936 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23937 +               task_pid_nr(p), p->xid, p->comm, K(p->mm->total_vm),
23938                 K(get_mm_counter(p->mm, MM_ANONPAGES)),
23939                 K(get_mm_counter(p->mm, MM_FILEPAGES)));
23940         task_unlock(p);
23941 @@ -483,8 +492,8 @@ static int oom_kill_process(struct task_
23942         }
23943  
23944         task_lock(p);
23945 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
23946 -               message, task_pid_nr(p), p->comm, points);
23947 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
23948 +               message, task_pid_nr(p), p->xid, p->comm, points);
23949         task_unlock(p);
23950  
23951         /*
23952 @@ -585,6 +594,8 @@ int unregister_oom_notifier(struct notif
23953  }
23954  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
23955  
23956 +long vs_oom_action(unsigned int);
23957 +
23958  /*
23959   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
23960   * if a parallel OOM killing is already taking place that includes a zone in
23961 @@ -743,7 +754,12 @@ retry:
23962         if (!p) {
23963                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
23964                 read_unlock(&tasklist_lock);
23965 -               panic("Out of memory and no killable processes...\n");
23966 +
23967 +               /* avoid panic for guest OOM */
23968 +               if (current->xid)
23969 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
23970 +               else
23971 +                       panic("Out of memory and no killable processes...\n");
23972         }
23973  
23974         if (oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
23975 diff -NurpP --minimal linux-3.1.6/mm/page_alloc.c linux-3.1.6-vs2.3.2.5/mm/page_alloc.c
23976 --- linux-3.1.6/mm/page_alloc.c 2011-12-23 16:04:07.000000000 +0100
23977 +++ linux-3.1.6-vs2.3.2.5/mm/page_alloc.c       2011-12-23 16:11:57.000000000 +0100
23978 @@ -57,6 +57,8 @@
23979  #include <linux/ftrace_event.h>
23980  #include <linux/memcontrol.h>
23981  #include <linux/prefetch.h>
23982 +#include <linux/vs_base.h>
23983 +#include <linux/vs_limit.h>
23984  
23985  #include <asm/tlbflush.h>
23986  #include <asm/div64.h>
23987 @@ -2484,6 +2486,9 @@ void si_meminfo(struct sysinfo *val)
23988         val->totalhigh = totalhigh_pages;
23989         val->freehigh = nr_free_highpages();
23990         val->mem_unit = PAGE_SIZE;
23991 +
23992 +       if (vx_flags(VXF_VIRT_MEM, 0))
23993 +               vx_vsi_meminfo(val);
23994  }
23995  
23996  EXPORT_SYMBOL(si_meminfo);
23997 @@ -2504,6 +2509,9 @@ void si_meminfo_node(struct sysinfo *val
23998         val->freehigh = 0;
23999  #endif
24000         val->mem_unit = PAGE_SIZE;
24001 +
24002 +       if (vx_flags(VXF_VIRT_MEM, 0))
24003 +               vx_vsi_meminfo(val);
24004  }
24005  #endif
24006  
24007 diff -NurpP --minimal linux-3.1.6/mm/pgtable-generic.c linux-3.1.6-vs2.3.2.5/mm/pgtable-generic.c
24008 --- linux-3.1.6/mm/pgtable-generic.c    2011-03-15 18:07:42.000000000 +0100
24009 +++ linux-3.1.6-vs2.3.2.5/mm/pgtable-generic.c  2011-10-24 18:53:33.000000000 +0200
24010 @@ -6,6 +6,8 @@
24011   *  Copyright (C) 2010  Linus Torvalds
24012   */
24013  
24014 +#include <linux/mm.h>
24015 +
24016  #include <linux/pagemap.h>
24017  #include <asm/tlb.h>
24018  #include <asm-generic/pgtable.h>
24019 diff -NurpP --minimal linux-3.1.6/mm/shmem.c linux-3.1.6-vs2.3.2.5/mm/shmem.c
24020 --- linux-3.1.6/mm/shmem.c      2011-10-24 18:45:33.000000000 +0200
24021 +++ linux-3.1.6-vs2.3.2.5/mm/shmem.c    2011-10-24 18:53:33.000000000 +0200
24022 @@ -1429,7 +1429,7 @@ static int shmem_statfs(struct dentry *d
24023  {
24024         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
24025  
24026 -       buf->f_type = TMPFS_MAGIC;
24027 +       buf->f_type = TMPFS_SUPER_MAGIC;
24028         buf->f_bsize = PAGE_CACHE_SIZE;
24029         buf->f_namelen = NAME_MAX;
24030         if (sbinfo->max_blocks) {
24031 @@ -2186,7 +2186,7 @@ int shmem_fill_super(struct super_block 
24032         sb->s_maxbytes = MAX_LFS_FILESIZE;
24033         sb->s_blocksize = PAGE_CACHE_SIZE;
24034         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
24035 -       sb->s_magic = TMPFS_MAGIC;
24036 +       sb->s_magic = TMPFS_SUPER_MAGIC;
24037         sb->s_op = &shmem_ops;
24038         sb->s_time_gran = 1;
24039  #ifdef CONFIG_TMPFS_XATTR
24040 diff -NurpP --minimal linux-3.1.6/mm/slab.c linux-3.1.6-vs2.3.2.5/mm/slab.c
24041 --- linux-3.1.6/mm/slab.c       2011-12-23 16:04:07.000000000 +0100
24042 +++ linux-3.1.6-vs2.3.2.5/mm/slab.c     2011-12-15 01:07:58.000000000 +0100
24043 @@ -411,6 +411,8 @@ static void kmem_list3_init(struct kmem_
24044  #define STATS_INC_FREEMISS(x)  do { } while (0)
24045  #endif
24046  
24047 +#include "slab_vs.h"
24048 +
24049  #if DEBUG
24050  
24051  /*
24052 @@ -3402,6 +3404,7 @@ retry:
24053  
24054         obj = slab_get_obj(cachep, slabp, nodeid);
24055         check_slabp(cachep, slabp);
24056 +       vx_slab_alloc(cachep, flags);
24057         l3->free_objects--;
24058         /* move slabp to correct slabp list: */
24059         list_del(&slabp->list);
24060 @@ -3479,6 +3482,7 @@ __cache_alloc_node(struct kmem_cache *ca
24061         /* ___cache_alloc_node can fall back to other nodes */
24062         ptr = ____cache_alloc_node(cachep, flags, nodeid);
24063    out:
24064 +       vx_slab_alloc(cachep, flags);
24065         local_irq_restore(save_flags);
24066         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
24067         kmemleak_alloc_recursive(ptr, obj_size(cachep), 1, cachep->flags,
24068 @@ -3666,6 +3670,7 @@ static inline void __cache_free(struct k
24069         check_irq_off();
24070         kmemleak_free_recursive(objp, cachep->flags);
24071         objp = cache_free_debugcheck(cachep, objp, caller);
24072 +       vx_slab_free(cachep);
24073  
24074         kmemcheck_slab_free(cachep, objp, obj_size(cachep));
24075  
24076 diff -NurpP --minimal linux-3.1.6/mm/slab_vs.h linux-3.1.6-vs2.3.2.5/mm/slab_vs.h
24077 --- linux-3.1.6/mm/slab_vs.h    1970-01-01 01:00:00.000000000 +0100
24078 +++ linux-3.1.6-vs2.3.2.5/mm/slab_vs.h  2011-10-24 18:53:33.000000000 +0200
24079 @@ -0,0 +1,29 @@
24080 +
24081 +#include <linux/vserver/context.h>
24082 +
24083 +#include <linux/vs_context.h>
24084 +
24085 +static inline
24086 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
24087 +{
24088 +       int what = gfp_zone(cachep->gfpflags);
24089 +       struct vx_info *vxi = current_vx_info();
24090 +
24091 +       if (!vxi)
24092 +               return;
24093 +
24094 +       atomic_add(cachep->buffer_size, &vxi->cacct.slab[what]);
24095 +}
24096 +
24097 +static inline
24098 +void vx_slab_free(struct kmem_cache *cachep)
24099 +{
24100 +       int what = gfp_zone(cachep->gfpflags);
24101 +       struct vx_info *vxi = current_vx_info();
24102 +
24103 +       if (!vxi)
24104 +               return;
24105 +
24106 +       atomic_sub(cachep->buffer_size, &vxi->cacct.slab[what]);
24107 +}
24108 +
24109 diff -NurpP --minimal linux-3.1.6/mm/swapfile.c linux-3.1.6-vs2.3.2.5/mm/swapfile.c
24110 --- linux-3.1.6/mm/swapfile.c   2011-10-24 18:45:33.000000000 +0200
24111 +++ linux-3.1.6-vs2.3.2.5/mm/swapfile.c 2011-12-07 04:20:21.000000000 +0100
24112 @@ -37,6 +37,7 @@
24113  #include <asm/tlbflush.h>
24114  #include <linux/swapops.h>
24115  #include <linux/page_cgroup.h>
24116 +#include <linux/vs_base.h>
24117  
24118  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
24119                                  unsigned char);
24120 @@ -1754,6 +1755,16 @@ static int swap_show(struct seq_file *sw
24121  
24122         if (si == SEQ_START_TOKEN) {
24123                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
24124 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
24125 +                       struct sysinfo si;
24126 +
24127 +                       vx_vsi_swapinfo(&si);
24128 +                       if (si.totalswap < (1 << 10))
24129 +                               return 0;
24130 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
24131 +                               "hdv0", "partition", si.totalswap >> 10,
24132 +                               (si.totalswap - si.freeswap) >> 10, -1);
24133 +               }
24134                 return 0;
24135         }
24136  
24137 @@ -2177,6 +2188,8 @@ void si_swapinfo(struct sysinfo *val)
24138         val->freeswap = nr_swap_pages + nr_to_be_unused;
24139         val->totalswap = total_swap_pages + nr_to_be_unused;
24140         spin_unlock(&swap_lock);
24141 +       if (vx_flags(VXF_VIRT_MEM, 0))
24142 +               vx_vsi_swapinfo(val);
24143  }
24144  
24145  /*
24146 diff -NurpP --minimal linux-3.1.6/net/bridge/br_multicast.c linux-3.1.6-vs2.3.2.5/net/bridge/br_multicast.c
24147 --- linux-3.1.6/net/bridge/br_multicast.c       2011-12-23 16:04:07.000000000 +0100
24148 +++ linux-3.1.6-vs2.3.2.5/net/bridge/br_multicast.c     2011-12-15 01:07:58.000000000 +0100
24149 @@ -447,7 +447,7 @@ static struct sk_buff *br_ip6_multicast_
24150         ip6h->hop_limit = 1;
24151         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
24152         ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
24153 -                          &ip6h->saddr);
24154 +                          &ip6h->saddr, NULL);
24155         ipv6_eth_mc_map(&ip6h->daddr, eth->h_dest);
24156  
24157         hopopt = (u8 *)(ip6h + 1);
24158 diff -NurpP --minimal linux-3.1.6/net/core/dev.c linux-3.1.6-vs2.3.2.5/net/core/dev.c
24159 --- linux-3.1.6/net/core/dev.c  2011-12-23 16:04:07.000000000 +0100
24160 +++ linux-3.1.6-vs2.3.2.5/net/core/dev.c        2011-11-15 17:08:44.000000000 +0100
24161 @@ -127,6 +127,7 @@
24162  #include <linux/in.h>
24163  #include <linux/jhash.h>
24164  #include <linux/random.h>
24165 +#include <linux/vs_inet.h>
24166  #include <trace/events/napi.h>
24167  #include <trace/events/net.h>
24168  #include <trace/events/skb.h>
24169 @@ -619,7 +620,8 @@ struct net_device *__dev_get_by_name(str
24170         struct hlist_head *head = dev_name_hash(net, name);
24171  
24172         hlist_for_each_entry(dev, p, head, name_hlist)
24173 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24174 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24175 +                   nx_dev_visible(current_nx_info(), dev))
24176                         return dev;
24177  
24178         return NULL;
24179 @@ -645,7 +647,8 @@ struct net_device *dev_get_by_name_rcu(s
24180         struct hlist_head *head = dev_name_hash(net, name);
24181  
24182         hlist_for_each_entry_rcu(dev, p, head, name_hlist)
24183 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24184 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24185 +                   nx_dev_visible(current_nx_info(), dev))
24186                         return dev;
24187  
24188         return NULL;
24189 @@ -696,7 +699,8 @@ struct net_device *__dev_get_by_index(st
24190         struct hlist_head *head = dev_index_hash(net, ifindex);
24191  
24192         hlist_for_each_entry(dev, p, head, index_hlist)
24193 -               if (dev->ifindex == ifindex)
24194 +               if ((dev->ifindex == ifindex) &&
24195 +                   nx_dev_visible(current_nx_info(), dev))
24196                         return dev;
24197  
24198         return NULL;
24199 @@ -714,7 +718,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
24200   *     about locking. The caller must hold RCU lock.
24201   */
24202  
24203 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24204 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
24205  {
24206         struct hlist_node *p;
24207         struct net_device *dev;
24208 @@ -726,6 +730,16 @@ struct net_device *dev_get_by_index_rcu(
24209  
24210         return NULL;
24211  }
24212 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
24213 +
24214 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24215 +{
24216 +       struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
24217 +
24218 +       if (nx_dev_visible(current_nx_info(), dev))
24219 +               return dev;
24220 +       return NULL;
24221 +}
24222  EXPORT_SYMBOL(dev_get_by_index_rcu);
24223  
24224  
24225 @@ -774,7 +788,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
24226  
24227         for_each_netdev_rcu(net, dev)
24228                 if (dev->type == type &&
24229 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
24230 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
24231 +                   nx_dev_visible(current_nx_info(), dev))
24232                         return dev;
24233  
24234         return NULL;
24235 @@ -786,9 +801,11 @@ struct net_device *__dev_getfirstbyhwtyp
24236         struct net_device *dev;
24237  
24238         ASSERT_RTNL();
24239 -       for_each_netdev(net, dev)
24240 -               if (dev->type == type)
24241 +       for_each_netdev(net, dev) {
24242 +               if ((dev->type == type) &&
24243 +                   nx_dev_visible(current_nx_info(), dev))
24244                         return dev;
24245 +       }
24246  
24247         return NULL;
24248  }
24249 @@ -906,6 +923,8 @@ static int __dev_alloc_name(struct net *
24250                                 continue;
24251                         if (i < 0 || i >= max_netdevices)
24252                                 continue;
24253 +                       if (!nx_dev_visible(current_nx_info(), d))
24254 +                               continue;
24255  
24256                         /*  avoid cases where sscanf is not exact inverse of printf */
24257                         snprintf(buf, IFNAMSIZ, name, i);
24258 @@ -3955,6 +3974,8 @@ static int dev_ifconf(struct net *net, c
24259  
24260         total = 0;
24261         for_each_netdev(net, dev) {
24262 +               if (!nx_dev_visible(current_nx_info(), dev))
24263 +                       continue;
24264                 for (i = 0; i < NPROTO; i++) {
24265                         if (gifconf_list[i]) {
24266                                 int done;
24267 @@ -4029,6 +4050,10 @@ static void dev_seq_printf_stats(struct 
24268         struct rtnl_link_stats64 temp;
24269         const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
24270  
24271 +       /* device visible inside network context? */
24272 +       if (!nx_dev_visible(current_nx_info(), dev))
24273 +               return;
24274 +
24275         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
24276                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
24277                    dev->name, stats->rx_bytes, stats->rx_packets,
24278 diff -NurpP --minimal linux-3.1.6/net/core/rtnetlink.c linux-3.1.6-vs2.3.2.5/net/core/rtnetlink.c
24279 --- linux-3.1.6/net/core/rtnetlink.c    2011-10-24 18:45:34.000000000 +0200
24280 +++ linux-3.1.6-vs2.3.2.5/net/core/rtnetlink.c  2011-10-24 18:53:33.000000000 +0200
24281 @@ -1040,6 +1040,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
24282                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
24283                         if (idx < s_idx)
24284                                 goto cont;
24285 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
24286 +                               continue;
24287                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
24288                                              NETLINK_CB(cb->skb).pid,
24289                                              cb->nlh->nlmsg_seq, 0,
24290 @@ -1881,6 +1883,9 @@ void rtmsg_ifinfo(int type, struct net_d
24291         int err = -ENOBUFS;
24292         size_t if_info_size;
24293  
24294 +       if (!nx_dev_visible(current_nx_info(), dev))
24295 +               return;
24296 +
24297         skb = nlmsg_new((if_info_size = if_nlmsg_size(dev)), GFP_KERNEL);
24298         if (skb == NULL)
24299                 goto errout;
24300 diff -NurpP --minimal linux-3.1.6/net/core/sock.c linux-3.1.6-vs2.3.2.5/net/core/sock.c
24301 --- linux-3.1.6/net/core/sock.c 2011-12-23 16:04:07.000000000 +0100
24302 +++ linux-3.1.6-vs2.3.2.5/net/core/sock.c       2011-11-15 17:08:44.000000000 +0100
24303 @@ -127,6 +127,10 @@
24304  #include <net/cls_cgroup.h>
24305  
24306  #include <linux/filter.h>
24307 +#include <linux/vs_socket.h>
24308 +#include <linux/vs_limit.h>
24309 +#include <linux/vs_context.h>
24310 +#include <linux/vs_network.h>
24311  
24312  #include <trace/events/sock.h>
24313  
24314 @@ -1073,6 +1077,8 @@ static struct sock *sk_prot_alloc(struct
24315                         goto out_free_sec;
24316                 sk_tx_queue_clear(sk);
24317         }
24318 +               sock_vx_init(sk);
24319 +               sock_nx_init(sk);
24320  
24321         return sk;
24322  
24323 @@ -1172,6 +1178,11 @@ static void __sk_free(struct sock *sk)
24324                 put_cred(sk->sk_peer_cred);
24325         put_pid(sk->sk_peer_pid);
24326         put_net(sock_net(sk));
24327 +       vx_sock_dec(sk);
24328 +       clr_vx_info(&sk->sk_vx_info);
24329 +       sk->sk_xid = -1;
24330 +       clr_nx_info(&sk->sk_nx_info);
24331 +       sk->sk_nid = -1;
24332         sk_prot_free(sk->sk_prot_creator, sk);
24333  }
24334  
24335 @@ -1219,6 +1230,8 @@ struct sock *sk_clone(const struct sock 
24336  
24337                 /* SANITY */
24338                 get_net(sock_net(newsk));
24339 +               sock_vx_init(newsk);
24340 +               sock_nx_init(newsk);
24341                 sk_node_init(&newsk->sk_node);
24342                 sock_lock_init(newsk);
24343                 bh_lock_sock(newsk);
24344 @@ -1275,6 +1288,12 @@ struct sock *sk_clone(const struct sock 
24345                 smp_wmb();
24346                 atomic_set(&newsk->sk_refcnt, 2);
24347  
24348 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
24349 +               newsk->sk_xid = sk->sk_xid;
24350 +               vx_sock_inc(newsk);
24351 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
24352 +               newsk->sk_nid = sk->sk_nid;
24353 +
24354                 /*
24355                  * Increment the counter in the same struct proto as the master
24356                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
24357 @@ -2023,6 +2042,12 @@ void sock_init_data(struct socket *sock,
24358  
24359         sk->sk_stamp = ktime_set(-1L, 0);
24360  
24361 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
24362 +       sk->sk_xid = vx_current_xid();
24363 +       vx_sock_inc(sk);
24364 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
24365 +       sk->sk_nid = nx_current_nid();
24366 +
24367         /*
24368          * Before updating sk_refcnt, we must commit prior changes to memory
24369          * (Documentation/RCU/rculist_nulls.txt for details)
24370 diff -NurpP --minimal linux-3.1.6/net/ipv4/af_inet.c linux-3.1.6-vs2.3.2.5/net/ipv4/af_inet.c
24371 --- linux-3.1.6/net/ipv4/af_inet.c      2011-10-24 18:45:34.000000000 +0200
24372 +++ linux-3.1.6-vs2.3.2.5/net/ipv4/af_inet.c    2011-10-24 18:53:33.000000000 +0200
24373 @@ -117,6 +117,7 @@
24374  #ifdef CONFIG_IP_MROUTE
24375  #include <linux/mroute.h>
24376  #endif
24377 +#include <linux/vs_limit.h>
24378  
24379  
24380  /* The inetsw table contains everything that inet_create needs to
24381 @@ -326,9 +327,13 @@ lookup_protocol:
24382         }
24383  
24384         err = -EPERM;
24385 +       if ((protocol == IPPROTO_ICMP) &&
24386 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24387 +               goto override;
24388 +
24389         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
24390                 goto out_rcu_unlock;
24391 -
24392 +override:
24393         err = -EAFNOSUPPORT;
24394         if (!inet_netns_ok(net, protocol))
24395                 goto out_rcu_unlock;
24396 @@ -452,6 +457,7 @@ int inet_bind(struct socket *sock, struc
24397         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
24398         struct sock *sk = sock->sk;
24399         struct inet_sock *inet = inet_sk(sk);
24400 +       struct nx_v4_sock_addr nsa;
24401         unsigned short snum;
24402         int chk_addr_ret;
24403         int err;
24404 @@ -475,7 +481,11 @@ int inet_bind(struct socket *sock, struc
24405                         goto out;
24406         }
24407  
24408 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24409 +       err = v4_map_sock_addr(inet, addr, &nsa);
24410 +       if (err)
24411 +               goto out;
24412 +
24413 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24414  
24415         /* Not specified by any standard per-se, however it breaks too
24416          * many applications when removed.  It is unfortunate since
24417 @@ -487,7 +497,7 @@ int inet_bind(struct socket *sock, struc
24418         err = -EADDRNOTAVAIL;
24419         if (!sysctl_ip_nonlocal_bind &&
24420             !(inet->freebind || inet->transparent) &&
24421 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
24422 +           nsa.saddr != htonl(INADDR_ANY) &&
24423             chk_addr_ret != RTN_LOCAL &&
24424             chk_addr_ret != RTN_MULTICAST &&
24425             chk_addr_ret != RTN_BROADCAST)
24426 @@ -512,7 +522,7 @@ int inet_bind(struct socket *sock, struc
24427         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
24428                 goto out_release_sock;
24429  
24430 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24431 +       v4_set_sock_addr(inet, &nsa);
24432         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24433                 inet->inet_saddr = 0;  /* Use device */
24434  
24435 @@ -715,11 +725,13 @@ int inet_getname(struct socket *sock, st
24436                      peer == 1))
24437                         return -ENOTCONN;
24438                 sin->sin_port = inet->inet_dport;
24439 -               sin->sin_addr.s_addr = inet->inet_daddr;
24440 +               sin->sin_addr.s_addr =
24441 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
24442         } else {
24443                 __be32 addr = inet->inet_rcv_saddr;
24444                 if (!addr)
24445                         addr = inet->inet_saddr;
24446 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
24447                 sin->sin_port = inet->inet_sport;
24448                 sin->sin_addr.s_addr = addr;
24449         }
24450 diff -NurpP --minimal linux-3.1.6/net/ipv4/arp.c linux-3.1.6-vs2.3.2.5/net/ipv4/arp.c
24451 --- linux-3.1.6/net/ipv4/arp.c  2011-10-24 18:45:34.000000000 +0200
24452 +++ linux-3.1.6-vs2.3.2.5/net/ipv4/arp.c        2011-10-24 18:53:33.000000000 +0200
24453 @@ -1332,6 +1332,7 @@ static void arp_format_neigh_entry(struc
24454         struct net_device *dev = n->dev;
24455         int hatype = dev->type;
24456  
24457 +       /* FIXME: check for network context */
24458         read_lock(&n->lock);
24459         /* Convert hardware address to XX:XX:XX:XX ... form. */
24460  #if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
24461 @@ -1363,6 +1364,7 @@ static void arp_format_pneigh_entry(stru
24462         int hatype = dev ? dev->type : 0;
24463         char tbuf[16];
24464  
24465 +       /* FIXME: check for network context */
24466         sprintf(tbuf, "%pI4", n->key);
24467         seq_printf(seq, "%-16s 0x%-10x0x%-10x%s     *        %s\n",
24468                    tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
24469 diff -NurpP --minimal linux-3.1.6/net/ipv4/devinet.c linux-3.1.6-vs2.3.2.5/net/ipv4/devinet.c
24470 --- linux-3.1.6/net/ipv4/devinet.c      2011-10-24 18:45:34.000000000 +0200
24471 +++ linux-3.1.6-vs2.3.2.5/net/ipv4/devinet.c    2011-10-24 18:53:33.000000000 +0200
24472 @@ -518,6 +518,7 @@ struct in_device *inetdev_by_index(struc
24473  }
24474  EXPORT_SYMBOL(inetdev_by_index);
24475  
24476 +
24477  /* Called only from RTNL semaphored context. No locks. */
24478  
24479  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
24480 @@ -759,6 +760,8 @@ int devinet_ioctl(struct net *net, unsig
24481  
24482         in_dev = __in_dev_get_rtnl(dev);
24483         if (in_dev) {
24484 +               struct nx_info *nxi = current_nx_info();
24485 +
24486                 if (tryaddrmatch) {
24487                         /* Matthias Andree */
24488                         /* compare label and address (4.4BSD style) */
24489 @@ -767,6 +770,8 @@ int devinet_ioctl(struct net *net, unsig
24490                            This is checked above. */
24491                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24492                              ifap = &ifa->ifa_next) {
24493 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24494 +                                       continue;
24495                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
24496                                     sin_orig.sin_addr.s_addr ==
24497                                                         ifa->ifa_local) {
24498 @@ -779,9 +784,12 @@ int devinet_ioctl(struct net *net, unsig
24499                    comparing just the label */
24500                 if (!ifa) {
24501                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24502 -                            ifap = &ifa->ifa_next)
24503 +                            ifap = &ifa->ifa_next) {
24504 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24505 +                                       continue;
24506                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
24507                                         break;
24508 +                       }
24509                 }
24510         }
24511  
24512 @@ -934,6 +942,8 @@ static int inet_gifconf(struct net_devic
24513                 goto out;
24514  
24515         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
24516 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
24517 +                       continue;
24518                 if (!buf) {
24519                         done += sizeof(ifr);
24520                         continue;
24521 @@ -1294,6 +1304,7 @@ static int inet_dump_ifaddr(struct sk_bu
24522         struct net_device *dev;
24523         struct in_device *in_dev;
24524         struct in_ifaddr *ifa;
24525 +       struct sock *sk = skb->sk;
24526         struct hlist_head *head;
24527         struct hlist_node *node;
24528  
24529 @@ -1316,6 +1327,8 @@ static int inet_dump_ifaddr(struct sk_bu
24530  
24531                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
24532                              ifa = ifa->ifa_next, ip_idx++) {
24533 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
24534 +                               continue;
24535                                 if (ip_idx < s_ip_idx)
24536                                         continue;
24537                                 if (inet_fill_ifaddr(skb, ifa,
24538 diff -NurpP --minimal linux-3.1.6/net/ipv4/fib_trie.c linux-3.1.6-vs2.3.2.5/net/ipv4/fib_trie.c
24539 --- linux-3.1.6/net/ipv4/fib_trie.c     2011-10-24 18:45:34.000000000 +0200
24540 +++ linux-3.1.6-vs2.3.2.5/net/ipv4/fib_trie.c   2011-10-24 18:53:33.000000000 +0200
24541 @@ -2554,6 +2554,7 @@ static int fib_route_seq_show(struct seq
24542                             || fa->fa_type == RTN_MULTICAST)
24543                                 continue;
24544  
24545 +                       /* FIXME: check for network context? */
24546                         if (fi)
24547                                 seq_printf(seq,
24548                                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
24549 diff -NurpP --minimal linux-3.1.6/net/ipv4/inet_connection_sock.c linux-3.1.6-vs2.3.2.5/net/ipv4/inet_connection_sock.c
24550 --- linux-3.1.6/net/ipv4/inet_connection_sock.c 2011-07-22 11:18:13.000000000 +0200
24551 +++ linux-3.1.6-vs2.3.2.5/net/ipv4/inet_connection_sock.c       2011-10-24 18:53:33.000000000 +0200
24552 @@ -52,6 +52,37 @@ void inet_get_local_port_range(int *low,
24553  }
24554  EXPORT_SYMBOL(inet_get_local_port_range);
24555  
24556 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24557 +{
24558 +       __be32  sk1_rcv_saddr = sk_rcv_saddr(sk1),
24559 +               sk2_rcv_saddr = sk_rcv_saddr(sk2);
24560 +
24561 +       if (inet_v6_ipv6only(sk2))
24562 +               return 0;
24563 +
24564 +       if (sk1_rcv_saddr &&
24565 +           sk2_rcv_saddr &&
24566 +           sk1_rcv_saddr == sk2_rcv_saddr)
24567 +               return 1;
24568 +
24569 +       if (sk1_rcv_saddr &&
24570 +           !sk2_rcv_saddr &&
24571 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
24572 +               return 1;
24573 +
24574 +       if (sk2_rcv_saddr &&
24575 +           !sk1_rcv_saddr &&
24576 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
24577 +               return 1;
24578 +
24579 +       if (!sk1_rcv_saddr &&
24580 +           !sk2_rcv_saddr &&
24581 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
24582 +               return 1;
24583 +
24584 +       return 0;
24585 +}
24586 +
24587  int inet_csk_bind_conflict(const struct sock *sk,
24588                            const struct inet_bind_bucket *tb)
24589  {
24590 @@ -74,9 +105,7 @@ int inet_csk_bind_conflict(const struct 
24591                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
24592                         if (!reuse || !sk2->sk_reuse ||
24593                             sk2->sk_state == TCP_LISTEN) {
24594 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24595 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24596 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
24597 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
24598                                         break;
24599                         }
24600                 }
24601 diff -NurpP --minimal linux-3.1.6/net/ipv4/inet_diag.c linux-3.1.6-vs2.3.2.5/net/ipv4/inet_diag.c
24602 --- linux-3.1.6/net/ipv4/inet_diag.c    2011-10-24 18:45:34.000000000 +0200
24603 +++ linux-3.1.6-vs2.3.2.5/net/ipv4/inet_diag.c  2011-10-24 18:53:33.000000000 +0200
24604 @@ -33,6 +33,8 @@
24605  #include <linux/stddef.h>
24606  
24607  #include <linux/inet_diag.h>
24608 +#include <linux/vs_network.h>
24609 +#include <linux/vs_inet.h>
24610  
24611  static const struct inet_diag_handler **inet_diag_table;
24612  
24613 @@ -119,8 +121,10 @@ static int inet_csk_diag_fill(struct soc
24614  
24615         r->id.idiag_sport = inet->inet_sport;
24616         r->id.idiag_dport = inet->inet_dport;
24617 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
24618 -       r->id.idiag_dst[0] = inet->inet_daddr;
24619 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
24620 +               inet->inet_rcv_saddr);
24621 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
24622 +               inet->inet_daddr);
24623  
24624  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
24625         if (r->idiag_family == AF_INET6) {
24626 @@ -205,8 +209,8 @@ static int inet_twsk_diag_fill(struct in
24627         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
24628         r->id.idiag_sport     = tw->tw_sport;
24629         r->id.idiag_dport     = tw->tw_dport;
24630 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
24631 -       r->id.idiag_dst[0]    = tw->tw_daddr;
24632 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
24633 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
24634         r->idiag_state        = tw->tw_substate;
24635         r->idiag_timer        = 3;
24636         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
24637 @@ -263,6 +267,7 @@ static int inet_diag_get_exact(struct sk
24638         err = -EINVAL;
24639  
24640         if (req->idiag_family == AF_INET) {
24641 +               /* TODO: lback */
24642                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
24643                                  req->id.idiag_dport, req->id.idiag_src[0],
24644                                  req->id.idiag_sport, req->id.idiag_if);
24645 @@ -505,6 +510,7 @@ static int inet_csk_diag_dump(struct soc
24646                 } else
24647  #endif
24648                 {
24649 +                       /* TODO: lback */
24650                         entry.saddr = &inet->inet_rcv_saddr;
24651                         entry.daddr = &inet->inet_daddr;
24652                 }
24653 @@ -543,6 +549,7 @@ static int inet_twsk_diag_dump(struct in
24654                 } else
24655  #endif
24656                 {
24657 +                       /* TODO: lback */
24658                         entry.saddr = &tw->tw_rcv_saddr;
24659                         entry.daddr = &tw->tw_daddr;
24660                 }
24661 @@ -589,8 +596,8 @@ static int inet_diag_fill_req(struct sk_
24662  
24663         r->id.idiag_sport = inet->inet_sport;
24664         r->id.idiag_dport = ireq->rmt_port;
24665 -       r->id.idiag_src[0] = ireq->loc_addr;
24666 -       r->id.idiag_dst[0] = ireq->rmt_addr;
24667 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
24668 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
24669         r->idiag_expires = jiffies_to_msecs(tmo);
24670         r->idiag_rqueue = 0;
24671         r->idiag_wqueue = 0;
24672 @@ -661,6 +668,7 @@ static int inet_diag_dump_reqs(struct sk
24673                                 continue;
24674  
24675                         if (bc) {
24676 +                               /* TODO: lback */
24677                                 entry.saddr =
24678  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
24679                                         (entry.family == AF_INET6) ?
24680 @@ -731,6 +739,8 @@ static int inet_diag_dump(struct sk_buff
24681                         sk_nulls_for_each(sk, node, &ilb->head) {
24682                                 struct inet_sock *inet = inet_sk(sk);
24683  
24684 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24685 +                                       continue;
24686                                 if (num < s_num) {
24687                                         num++;
24688                                         continue;
24689 @@ -797,6 +807,8 @@ skip_listen_ht:
24690                 sk_nulls_for_each(sk, node, &head->chain) {
24691                         struct inet_sock *inet = inet_sk(sk);
24692  
24693 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24694 +                               continue;
24695                         if (num < s_num)
24696                                 goto next_normal;
24697                         if (!(r->idiag_states & (1 << sk->sk_state)))
24698 @@ -821,6 +833,8 @@ next_normal:
24699                         inet_twsk_for_each(tw, node,
24700                                     &head->twchain) {
24701  
24702 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24703 +                                       continue;
24704                                 if (num < s_num)
24705                                         goto next_dying;
24706                                 if (r->id.idiag_sport != tw->tw_sport &&
24707 diff -NurpP --minimal linux-3.1.6/net/ipv4/inet_hashtables.c linux-3.1.6-vs2.3.2.5/net/ipv4/inet_hashtables.c
24708 --- linux-3.1.6/net/ipv4/inet_hashtables.c      2011-10-24 18:45:34.000000000 +0200
24709 +++ linux-3.1.6-vs2.3.2.5/net/ipv4/inet_hashtables.c    2011-10-24 18:53:33.000000000 +0200
24710 @@ -22,6 +22,7 @@
24711  #include <net/inet_connection_sock.h>
24712  #include <net/inet_hashtables.h>
24713  #include <net/secure_seq.h>
24714 +#include <net/route.h>
24715  #include <net/ip.h>
24716  
24717  /*
24718 @@ -156,6 +157,11 @@ static inline int compute_score(struct s
24719                         if (rcv_saddr != daddr)
24720                                 return -1;
24721                         score += 2;
24722 +               } else {
24723 +                       /* block non nx_info ips */
24724 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24725 +                               daddr, NXA_MASK_BIND))
24726 +                               return -1;
24727                 }
24728                 if (sk->sk_bound_dev_if) {
24729                         if (sk->sk_bound_dev_if != dif)
24730 @@ -173,7 +179,6 @@ static inline int compute_score(struct s
24731   * wildcarded during the search since they can never be otherwise.
24732   */
24733  
24734 -
24735  struct sock *__inet_lookup_listener(struct net *net,
24736                                     struct inet_hashinfo *hashinfo,
24737                                     const __be32 daddr, const unsigned short hnum,
24738 @@ -196,6 +201,7 @@ begin:
24739                         hiscore = score;
24740                 }
24741         }
24742 +
24743         /*
24744          * if the nulls value we got at the end of this lookup is
24745          * not the expected one, we must restart lookup.
24746 diff -NurpP --minimal linux-3.1.6/net/ipv4/netfilter/nf_nat_helper.c linux-3.1.6-vs2.3.2.5/net/ipv4/netfilter/nf_nat_helper.c
24747 --- linux-3.1.6/net/ipv4/netfilter/nf_nat_helper.c      2011-07-22 11:18:13.000000000 +0200
24748 +++ linux-3.1.6-vs2.3.2.5/net/ipv4/netfilter/nf_nat_helper.c    2011-10-24 18:53:33.000000000 +0200
24749 @@ -20,6 +20,7 @@
24750  #include <net/route.h>
24751  
24752  #include <linux/netfilter_ipv4.h>
24753 +#include <net/route.h>
24754  #include <net/netfilter/nf_conntrack.h>
24755  #include <net/netfilter/nf_conntrack_helper.h>
24756  #include <net/netfilter/nf_conntrack_ecache.h>
24757 diff -NurpP --minimal linux-3.1.6/net/ipv4/netfilter.c linux-3.1.6-vs2.3.2.5/net/ipv4/netfilter.c
24758 --- linux-3.1.6/net/ipv4/netfilter.c    2011-10-24 18:45:34.000000000 +0200
24759 +++ linux-3.1.6-vs2.3.2.5/net/ipv4/netfilter.c  2011-10-24 18:53:33.000000000 +0200
24760 @@ -5,7 +5,7 @@
24761  #include <linux/ip.h>
24762  #include <linux/skbuff.h>
24763  #include <linux/gfp.h>
24764 -#include <net/route.h>
24765 +// #include <net/route.h>
24766  #include <net/xfrm.h>
24767  #include <net/ip.h>
24768  #include <net/netfilter/nf_queue.h>
24769 diff -NurpP --minimal linux-3.1.6/net/ipv4/raw.c linux-3.1.6-vs2.3.2.5/net/ipv4/raw.c
24770 --- linux-3.1.6/net/ipv4/raw.c  2011-10-24 18:45:34.000000000 +0200
24771 +++ linux-3.1.6-vs2.3.2.5/net/ipv4/raw.c        2011-10-24 18:53:33.000000000 +0200
24772 @@ -117,7 +117,7 @@ static struct sock *__raw_v4_lookup(stru
24773  
24774                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
24775                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
24776 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
24777 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
24778                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
24779                         goto found; /* gotcha */
24780         }
24781 @@ -385,6 +385,12 @@ static int raw_send_hdrinc(struct sock *
24782                 icmp_out_count(net, ((struct icmphdr *)
24783                         skb_transport_header(skb))->type);
24784  
24785 +       err = -EPERM;
24786 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
24787 +               sk->sk_nx_info &&
24788 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
24789 +               goto error_free;
24790 +
24791         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
24792                       rt->dst.dev, dst_output);
24793         if (err > 0)
24794 @@ -572,6 +578,16 @@ static int raw_sendmsg(struct kiocb *ioc
24795                         goto done;
24796         }
24797  
24798 +       if (sk->sk_nx_info) {
24799 +               rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
24800 +               if (IS_ERR(rt)) {
24801 +                       err = PTR_ERR(rt);
24802 +                       rt = NULL;
24803 +                       goto done;
24804 +               }
24805 +               ip_rt_put(rt);
24806 +       }
24807 +
24808         security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
24809         rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
24810         if (IS_ERR(rt)) {
24811 @@ -648,17 +664,19 @@ static int raw_bind(struct sock *sk, str
24812  {
24813         struct inet_sock *inet = inet_sk(sk);
24814         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
24815 +       struct nx_v4_sock_addr nsa = { 0 };
24816         int ret = -EINVAL;
24817         int chk_addr_ret;
24818  
24819         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
24820                 goto out;
24821 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24822 +       v4_map_sock_addr(inet, addr, &nsa);
24823 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24824         ret = -EADDRNOTAVAIL;
24825 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
24826 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
24827             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
24828                 goto out;
24829 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24830 +       v4_set_sock_addr(inet, &nsa);
24831         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24832                 inet->inet_saddr = 0;  /* Use device */
24833         sk_dst_reset(sk);
24834 @@ -710,7 +728,8 @@ static int raw_recvmsg(struct kiocb *ioc
24835         /* Copy the address. */
24836         if (sin) {
24837                 sin->sin_family = AF_INET;
24838 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24839 +               sin->sin_addr.s_addr =
24840 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
24841                 sin->sin_port = 0;
24842                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
24843         }
24844 @@ -906,7 +925,8 @@ static struct sock *raw_get_first(struct
24845                 struct hlist_node *node;
24846  
24847                 sk_for_each(sk, node, &state->h->ht[state->bucket])
24848 -                       if (sock_net(sk) == seq_file_net(seq))
24849 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
24850 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24851                                 goto found;
24852         }
24853         sk = NULL;
24854 @@ -922,7 +942,8 @@ static struct sock *raw_get_next(struct 
24855                 sk = sk_next(sk);
24856  try_again:
24857                 ;
24858 -       } while (sk && sock_net(sk) != seq_file_net(seq));
24859 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
24860 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24861  
24862         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
24863                 sk = sk_head(&state->h->ht[state->bucket]);
24864 diff -NurpP --minimal linux-3.1.6/net/ipv4/route.c linux-3.1.6-vs2.3.2.5/net/ipv4/route.c
24865 --- linux-3.1.6/net/ipv4/route.c        2011-12-23 16:04:07.000000000 +0100
24866 +++ linux-3.1.6-vs2.3.2.5/net/ipv4/route.c      2011-12-15 01:07:58.000000000 +0100
24867 @@ -2609,7 +2609,7 @@ static struct rtable *ip_route_output_sl
24868  
24869  
24870         if (fl4->flowi4_oif) {
24871 -               dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
24872 +               dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
24873                 rth = ERR_PTR(-ENODEV);
24874                 if (dev_out == NULL)
24875                         goto out;
24876 diff -NurpP --minimal linux-3.1.6/net/ipv4/tcp.c linux-3.1.6-vs2.3.2.5/net/ipv4/tcp.c
24877 --- linux-3.1.6/net/ipv4/tcp.c  2011-07-22 11:18:13.000000000 +0200
24878 +++ linux-3.1.6-vs2.3.2.5/net/ipv4/tcp.c        2011-10-24 18:53:33.000000000 +0200
24879 @@ -266,6 +266,7 @@
24880  #include <linux/crypto.h>
24881  #include <linux/time.h>
24882  #include <linux/slab.h>
24883 +#include <linux/in.h>
24884  
24885  #include <net/icmp.h>
24886  #include <net/tcp.h>
24887 diff -NurpP --minimal linux-3.1.6/net/ipv4/tcp_ipv4.c linux-3.1.6-vs2.3.2.5/net/ipv4/tcp_ipv4.c
24888 --- linux-3.1.6/net/ipv4/tcp_ipv4.c     2011-10-24 18:45:34.000000000 +0200
24889 +++ linux-3.1.6-vs2.3.2.5/net/ipv4/tcp_ipv4.c   2011-10-24 18:53:33.000000000 +0200
24890 @@ -2018,6 +2018,12 @@ static void *listening_get_next(struct s
24891                 req = req->dl_next;
24892                 while (1) {
24893                         while (req) {
24894 +                               vxdprintk(VXD_CBIT(net, 6),
24895 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
24896 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
24897 +                               if (req->sk &&
24898 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
24899 +                                       continue;
24900                                 if (req->rsk_ops->family == st->family) {
24901                                         cur = req;
24902                                         goto out;
24903 @@ -2042,6 +2048,10 @@ get_req:
24904         }
24905  get_sk:
24906         sk_nulls_for_each_from(sk, node) {
24907 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
24908 +                       sk, sk->sk_nid, nx_current_nid());
24909 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24910 +                       continue;
24911                 if (!net_eq(sock_net(sk), net))
24912                         continue;
24913                 if (sk->sk_family == st->family) {
24914 @@ -2118,6 +2128,11 @@ static void *established_get_first(struc
24915  
24916                 spin_lock_bh(lock);
24917                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
24918 +                       vxdprintk(VXD_CBIT(net, 6),
24919 +                               "sk,egf: %p [#%d] (from %d)",
24920 +                               sk, sk->sk_nid, nx_current_nid());
24921 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24922 +                               continue;
24923                         if (sk->sk_family != st->family ||
24924                             !net_eq(sock_net(sk), net)) {
24925                                 continue;
24926 @@ -2128,6 +2143,11 @@ static void *established_get_first(struc
24927                 st->state = TCP_SEQ_STATE_TIME_WAIT;
24928                 inet_twsk_for_each(tw, node,
24929                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
24930 +                       vxdprintk(VXD_CBIT(net, 6),
24931 +                               "tw: %p [#%d] (from %d)",
24932 +                               tw, tw->tw_nid, nx_current_nid());
24933 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24934 +                               continue;
24935                         if (tw->tw_family != st->family ||
24936                             !net_eq(twsk_net(tw), net)) {
24937                                 continue;
24938 @@ -2157,7 +2177,9 @@ static void *established_get_next(struct
24939                 tw = cur;
24940                 tw = tw_next(tw);
24941  get_tw:
24942 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
24943 +               while (tw && (tw->tw_family != st->family ||
24944 +                       !net_eq(twsk_net(tw), net) ||
24945 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
24946                         tw = tw_next(tw);
24947                 }
24948                 if (tw) {
24949 @@ -2181,6 +2203,11 @@ get_tw:
24950                 sk = sk_nulls_next(sk);
24951  
24952         sk_nulls_for_each_from(sk, node) {
24953 +               vxdprintk(VXD_CBIT(net, 6),
24954 +                       "sk,egn: %p [#%d] (from %d)",
24955 +                       sk, sk->sk_nid, nx_current_nid());
24956 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24957 +                       continue;
24958                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
24959                         goto found;
24960         }
24961 @@ -2390,9 +2417,9 @@ static void get_openreq4(struct sock *sk
24962         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
24963                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %pK%n",
24964                 i,
24965 -               ireq->loc_addr,
24966 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
24967                 ntohs(inet_sk(sk)->inet_sport),
24968 -               ireq->rmt_addr,
24969 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
24970                 ntohs(ireq->rmt_port),
24971                 TCP_SYN_RECV,
24972                 0, 0, /* could print option size, but that is af dependent. */
24973 @@ -2414,8 +2441,8 @@ static void get_tcp4_sock(struct sock *s
24974         struct tcp_sock *tp = tcp_sk(sk);
24975         const struct inet_connection_sock *icsk = inet_csk(sk);
24976         struct inet_sock *inet = inet_sk(sk);
24977 -       __be32 dest = inet->inet_daddr;
24978 -       __be32 src = inet->inet_rcv_saddr;
24979 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24980 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24981         __u16 destp = ntohs(inet->inet_dport);
24982         __u16 srcp = ntohs(inet->inet_sport);
24983         int rx_queue;
24984 @@ -2472,8 +2499,8 @@ static void get_timewait4_sock(struct in
24985         if (ttd < 0)
24986                 ttd = 0;
24987  
24988 -       dest  = tw->tw_daddr;
24989 -       src   = tw->tw_rcv_saddr;
24990 +       dest  = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
24991 +       src   = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
24992         destp = ntohs(tw->tw_dport);
24993         srcp  = ntohs(tw->tw_sport);
24994  
24995 diff -NurpP --minimal linux-3.1.6/net/ipv4/tcp_minisocks.c linux-3.1.6-vs2.3.2.5/net/ipv4/tcp_minisocks.c
24996 --- linux-3.1.6/net/ipv4/tcp_minisocks.c        2011-10-24 18:45:34.000000000 +0200
24997 +++ linux-3.1.6-vs2.3.2.5/net/ipv4/tcp_minisocks.c      2011-10-24 18:53:33.000000000 +0200
24998 @@ -23,6 +23,9 @@
24999  #include <linux/slab.h>
25000  #include <linux/sysctl.h>
25001  #include <linux/workqueue.h>
25002 +#include <linux/vs_limit.h>
25003 +#include <linux/vs_socket.h>
25004 +#include <linux/vs_context.h>
25005  #include <net/tcp.h>
25006  #include <net/inet_common.h>
25007  #include <net/xfrm.h>
25008 @@ -336,6 +339,11 @@ void tcp_time_wait(struct sock *sk, int 
25009                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
25010                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
25011  
25012 +               tw->tw_xid              = sk->sk_xid;
25013 +               tw->tw_vx_info          = NULL;
25014 +               tw->tw_nid              = sk->sk_nid;
25015 +               tw->tw_nx_info          = NULL;
25016 +
25017  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
25018                 if (tw->tw_family == PF_INET6) {
25019                         struct ipv6_pinfo *np = inet6_sk(sk);
25020 diff -NurpP --minimal linux-3.1.6/net/ipv4/udp.c linux-3.1.6-vs2.3.2.5/net/ipv4/udp.c
25021 --- linux-3.1.6/net/ipv4/udp.c  2011-10-24 18:45:34.000000000 +0200
25022 +++ linux-3.1.6-vs2.3.2.5/net/ipv4/udp.c        2011-10-24 18:53:33.000000000 +0200
25023 @@ -297,14 +297,7 @@ fail:
25024  }
25025  EXPORT_SYMBOL(udp_lib_get_port);
25026  
25027 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25028 -{
25029 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
25030 -
25031 -       return  (!ipv6_only_sock(sk2)  &&
25032 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
25033 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
25034 -}
25035 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
25036  
25037  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
25038                                        unsigned int port)
25039 @@ -339,6 +332,11 @@ static inline int compute_score(struct s
25040                         if (inet->inet_rcv_saddr != daddr)
25041                                 return -1;
25042                         score += 2;
25043 +               } else {
25044 +                       /* block non nx_info ips */
25045 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
25046 +                               daddr, NXA_MASK_BIND))
25047 +                               return -1;
25048                 }
25049                 if (inet->inet_daddr) {
25050                         if (inet->inet_daddr != saddr)
25051 @@ -442,6 +440,7 @@ exact_match:
25052         return result;
25053  }
25054  
25055 +
25056  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
25057   * harder than this. -DaveM
25058   */
25059 @@ -487,6 +486,11 @@ begin:
25060         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
25061                 score = compute_score(sk, net, saddr, hnum, sport,
25062                                       daddr, dport, dif);
25063 +               /* FIXME: disabled?
25064 +               if (score == 9) {
25065 +                       result = sk;
25066 +                       break;
25067 +               } else */
25068                 if (score > badness) {
25069                         result = sk;
25070                         badness = score;
25071 @@ -500,6 +504,7 @@ begin:
25072         if (get_nulls_value(node) != slot)
25073                 goto begin;
25074  
25075 +
25076         if (result) {
25077                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
25078                         result = NULL;
25079 @@ -509,6 +514,7 @@ begin:
25080                         goto begin;
25081                 }
25082         }
25083 +
25084         rcu_read_unlock();
25085         return result;
25086  }
25087 @@ -551,8 +557,7 @@ static inline struct sock *udp_v4_mcast_
25088                     udp_sk(s)->udp_port_hash != hnum ||
25089                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
25090                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
25091 -                   (inet->inet_rcv_saddr &&
25092 -                    inet->inet_rcv_saddr != loc_addr) ||
25093 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
25094                     ipv6_only_sock(s) ||
25095                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
25096                         continue;
25097 @@ -930,6 +935,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
25098                                    inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
25099                                    faddr, saddr, dport, inet->inet_sport);
25100  
25101 +               if (sk->sk_nx_info) {
25102 +                       rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
25103 +                       if (IS_ERR(rt)) {
25104 +                               err = PTR_ERR(rt);
25105 +                               rt = NULL;
25106 +                               goto out;
25107 +                       }
25108 +                       ip_rt_put(rt);
25109 +               }
25110 +
25111                 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
25112                 rt = ip_route_output_flow(net, fl4, sk);
25113                 if (IS_ERR(rt)) {
25114 @@ -1227,7 +1242,8 @@ try_again:
25115         if (sin) {
25116                 sin->sin_family = AF_INET;
25117                 sin->sin_port = udp_hdr(skb)->source;
25118 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25119 +               sin->sin_addr.s_addr = nx_map_sock_lback(
25120 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
25121                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
25122         }
25123         if (inet->cmsg_flags)
25124 @@ -1972,6 +1988,8 @@ static struct sock *udp_get_first(struct
25125                 sk_nulls_for_each(sk, node, &hslot->head) {
25126                         if (!net_eq(sock_net(sk), net))
25127                                 continue;
25128 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25129 +                               continue;
25130                         if (sk->sk_family == state->family)
25131                                 goto found;
25132                 }
25133 @@ -1989,7 +2007,9 @@ static struct sock *udp_get_next(struct 
25134  
25135         do {
25136                 sk = sk_nulls_next(sk);
25137 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
25138 +       } while (sk && (!net_eq(sock_net(sk), net) ||
25139 +               sk->sk_family != state->family ||
25140 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25141  
25142         if (!sk) {
25143                 if (state->bucket <= state->udp_table->mask)
25144 diff -NurpP --minimal linux-3.1.6/net/ipv6/Kconfig linux-3.1.6-vs2.3.2.5/net/ipv6/Kconfig
25145 --- linux-3.1.6/net/ipv6/Kconfig        2010-08-02 16:52:59.000000000 +0200
25146 +++ linux-3.1.6-vs2.3.2.5/net/ipv6/Kconfig      2011-10-24 18:53:33.000000000 +0200
25147 @@ -4,8 +4,8 @@
25148  
25149  #   IPv6 as module will cause a CRASH if you try to unload it
25150  menuconfig IPV6
25151 -       tristate "The IPv6 protocol"
25152 -       default m
25153 +       bool "The IPv6 protocol"
25154 +       default n
25155         ---help---
25156           This is complemental support for the IP version 6.
25157           You will still be able to do traditional IPv4 networking as well.
25158 diff -NurpP --minimal linux-3.1.6/net/ipv6/addrconf.c linux-3.1.6-vs2.3.2.5/net/ipv6/addrconf.c
25159 --- linux-3.1.6/net/ipv6/addrconf.c     2011-10-24 18:45:34.000000000 +0200
25160 +++ linux-3.1.6-vs2.3.2.5/net/ipv6/addrconf.c   2011-10-24 18:53:33.000000000 +0200
25161 @@ -87,6 +87,8 @@
25162  
25163  #include <linux/proc_fs.h>
25164  #include <linux/seq_file.h>
25165 +#include <linux/vs_network.h>
25166 +#include <linux/vs_inet6.h>
25167  
25168  /* Set to 3 to get tracing... */
25169  #define ACONF_DEBUG 2
25170 @@ -1108,7 +1110,7 @@ out:
25171  
25172  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
25173                        const struct in6_addr *daddr, unsigned int prefs,
25174 -                      struct in6_addr *saddr)
25175 +                      struct in6_addr *saddr, struct nx_info *nxi)
25176  {
25177         struct ipv6_saddr_score scores[2],
25178                                 *score = &scores[0], *hiscore = &scores[1];
25179 @@ -1180,6 +1182,8 @@ int ipv6_dev_get_saddr(struct net *net, 
25180                                                dev->name);
25181                                 continue;
25182                         }
25183 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
25184 +                               continue;
25185  
25186                         score->rule = -1;
25187                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
25188 @@ -3087,7 +3091,10 @@ static void if6_seq_stop(struct seq_file
25189  static int if6_seq_show(struct seq_file *seq, void *v)
25190  {
25191         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
25192 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25193 +
25194 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
25195 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
25196 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25197                    &ifp->addr,
25198                    ifp->idev->dev->ifindex,
25199                    ifp->prefix_len,
25200 @@ -3593,6 +3600,11 @@ static int in6_dump_addrs(struct inet6_d
25201         struct ifacaddr6 *ifaca;
25202         int err = 1;
25203         int ip_idx = *p_ip_idx;
25204 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25205 +
25206 +       /* disable ipv6 on non v6 guests */
25207 +       if (nxi && !nx_info_has_v6(nxi))
25208 +               return skb->len;
25209  
25210         read_lock_bh(&idev->lock);
25211         switch (type) {
25212 @@ -3603,6 +3615,8 @@ static int in6_dump_addrs(struct inet6_d
25213                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
25214                         if (++ip_idx < s_ip_idx)
25215                                 continue;
25216 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
25217 +                                       continue;
25218                         err = inet6_fill_ifaddr(skb, ifa,
25219                                                 NETLINK_CB(cb->skb).pid,
25220                                                 cb->nlh->nlmsg_seq,
25221 @@ -3619,6 +3633,8 @@ static int in6_dump_addrs(struct inet6_d
25222                      ifmca = ifmca->next, ip_idx++) {
25223                         if (ip_idx < s_ip_idx)
25224                                 continue;
25225 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
25226 +                                       continue;
25227                         err = inet6_fill_ifmcaddr(skb, ifmca,
25228                                                   NETLINK_CB(cb->skb).pid,
25229                                                   cb->nlh->nlmsg_seq,
25230 @@ -3634,6 +3650,8 @@ static int in6_dump_addrs(struct inet6_d
25231                      ifaca = ifaca->aca_next, ip_idx++) {
25232                         if (ip_idx < s_ip_idx)
25233                                 continue;
25234 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
25235 +                                       continue;
25236                         err = inet6_fill_ifacaddr(skb, ifaca,
25237                                                   NETLINK_CB(cb->skb).pid,
25238                                                   cb->nlh->nlmsg_seq,
25239 @@ -4019,6 +4037,11 @@ static int inet6_dump_ifinfo(struct sk_b
25240         struct inet6_dev *idev;
25241         struct hlist_head *head;
25242         struct hlist_node *node;
25243 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25244 +
25245 +       /* FIXME: maybe disable ipv6 on non v6 guests?
25246 +       if (skb->sk && skb->sk->sk_vx_info)
25247 +               return skb->len; */
25248  
25249         s_h = cb->args[0];
25250         s_idx = cb->args[1];
25251 @@ -4030,6 +4053,8 @@ static int inet6_dump_ifinfo(struct sk_b
25252                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
25253                         if (idx < s_idx)
25254                                 goto cont;
25255 +                       if (!v6_dev_in_nx_info(dev, nxi))
25256 +                               goto cont;
25257                         idev = __in6_dev_get(dev);
25258                         if (!idev)
25259                                 goto cont;
25260 diff -NurpP --minimal linux-3.1.6/net/ipv6/af_inet6.c linux-3.1.6-vs2.3.2.5/net/ipv6/af_inet6.c
25261 --- linux-3.1.6/net/ipv6/af_inet6.c     2011-10-24 18:45:34.000000000 +0200
25262 +++ linux-3.1.6-vs2.3.2.5/net/ipv6/af_inet6.c   2011-10-24 18:53:33.000000000 +0200
25263 @@ -42,6 +42,8 @@
25264  #include <linux/netdevice.h>
25265  #include <linux/icmpv6.h>
25266  #include <linux/netfilter_ipv6.h>
25267 +#include <linux/vs_inet.h>
25268 +#include <linux/vs_inet6.h>
25269  
25270  #include <net/ip.h>
25271  #include <net/ipv6.h>
25272 @@ -160,9 +162,12 @@ lookup_protocol:
25273         }
25274  
25275         err = -EPERM;
25276 +       if ((protocol == IPPROTO_ICMPV6) &&
25277 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
25278 +               goto override;
25279         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
25280                 goto out_rcu_unlock;
25281 -
25282 +override:
25283         sock->ops = answer->ops;
25284         answer_prot = answer->prot;
25285         answer_no_check = answer->no_check;
25286 @@ -261,6 +266,7 @@ int inet6_bind(struct socket *sock, stru
25287         struct inet_sock *inet = inet_sk(sk);
25288         struct ipv6_pinfo *np = inet6_sk(sk);
25289         struct net *net = sock_net(sk);
25290 +       struct nx_v6_sock_addr nsa;
25291         __be32 v4addr = 0;
25292         unsigned short snum;
25293         int addr_type = 0;
25294 @@ -276,6 +282,10 @@ int inet6_bind(struct socket *sock, stru
25295         if (addr->sin6_family != AF_INET6)
25296                 return -EAFNOSUPPORT;
25297  
25298 +       err = v6_map_sock_addr(inet, addr, &nsa);
25299 +       if (err)
25300 +               return err;
25301 +
25302         addr_type = ipv6_addr_type(&addr->sin6_addr);
25303         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
25304                 return -EINVAL;
25305 @@ -307,6 +317,7 @@ int inet6_bind(struct socket *sock, stru
25306                 /* Reproduce AF_INET checks to make the bindings consistent */
25307                 v4addr = addr->sin6_addr.s6_addr32[3];
25308                 chk_addr_ret = inet_addr_type(net, v4addr);
25309 +
25310                 if (!sysctl_ip_nonlocal_bind &&
25311                     !(inet->freebind || inet->transparent) &&
25312                     v4addr != htonl(INADDR_ANY) &&
25313 @@ -316,6 +327,10 @@ int inet6_bind(struct socket *sock, stru
25314                         err = -EADDRNOTAVAIL;
25315                         goto out;
25316                 }
25317 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
25318 +                       err = -EADDRNOTAVAIL;
25319 +                       goto out;
25320 +               }
25321         } else {
25322                 if (addr_type != IPV6_ADDR_ANY) {
25323                         struct net_device *dev = NULL;
25324 @@ -342,6 +357,11 @@ int inet6_bind(struct socket *sock, stru
25325                                 }
25326                         }
25327  
25328 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25329 +                               err = -EADDRNOTAVAIL;
25330 +                               goto out;
25331 +                       }
25332 +
25333                         /* ipv4 addr of the socket is invalid.  Only the
25334                          * unspecified and mapped address have a v4 equivalent.
25335                          */
25336 @@ -358,6 +378,9 @@ int inet6_bind(struct socket *sock, stru
25337                 }
25338         }
25339  
25340 +       /* what's that for? */
25341 +       v6_set_sock_addr(inet, &nsa);
25342 +
25343         inet->inet_rcv_saddr = v4addr;
25344         inet->inet_saddr = v4addr;
25345  
25346 @@ -459,9 +482,11 @@ int inet6_getname(struct socket *sock, s
25347                         return -ENOTCONN;
25348                 sin->sin6_port = inet->inet_dport;
25349                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
25350 +               /* FIXME: remap lback? */
25351                 if (np->sndflow)
25352                         sin->sin6_flowinfo = np->flow_label;
25353         } else {
25354 +               /* FIXME: remap lback? */
25355                 if (ipv6_addr_any(&np->rcv_saddr))
25356                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
25357                 else
25358 diff -NurpP --minimal linux-3.1.6/net/ipv6/datagram.c linux-3.1.6-vs2.3.2.5/net/ipv6/datagram.c
25359 --- linux-3.1.6/net/ipv6/datagram.c     2011-10-24 18:45:34.000000000 +0200
25360 +++ linux-3.1.6-vs2.3.2.5/net/ipv6/datagram.c   2011-10-24 18:53:33.000000000 +0200
25361 @@ -646,7 +646,7 @@ int datagram_send_ctl(struct net *net, s
25362  
25363                         rcu_read_lock();
25364                         if (fl6->flowi6_oif) {
25365 -                               dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
25366 +                               dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
25367                                 if (!dev) {
25368                                         rcu_read_unlock();
25369                                         return -ENODEV;
25370 diff -NurpP --minimal linux-3.1.6/net/ipv6/fib6_rules.c linux-3.1.6-vs2.3.2.5/net/ipv6/fib6_rules.c
25371 --- linux-3.1.6/net/ipv6/fib6_rules.c   2011-05-22 16:18:00.000000000 +0200
25372 +++ linux-3.1.6-vs2.3.2.5/net/ipv6/fib6_rules.c 2011-10-24 18:53:33.000000000 +0200
25373 @@ -90,7 +90,7 @@ static int fib6_rule_action(struct fib_r
25374                                                ip6_dst_idev(&rt->dst)->dev,
25375                                                &flp6->daddr,
25376                                                rt6_flags2srcprefs(flags),
25377 -                                              &saddr))
25378 +                                              &saddr, NULL))
25379                                 goto again;
25380                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
25381                                                r->src.plen))
25382 diff -NurpP --minimal linux-3.1.6/net/ipv6/inet6_hashtables.c linux-3.1.6-vs2.3.2.5/net/ipv6/inet6_hashtables.c
25383 --- linux-3.1.6/net/ipv6/inet6_hashtables.c     2011-10-24 18:45:34.000000000 +0200
25384 +++ linux-3.1.6-vs2.3.2.5/net/ipv6/inet6_hashtables.c   2011-10-24 18:53:33.000000000 +0200
25385 @@ -16,6 +16,7 @@
25386  
25387  #include <linux/module.h>
25388  #include <linux/random.h>
25389 +#include <linux/vs_inet6.h>
25390  
25391  #include <net/inet_connection_sock.h>
25392  #include <net/inet_hashtables.h>
25393 @@ -83,7 +84,6 @@ struct sock *__inet6_lookup_established(
25394         unsigned int slot = hash & hashinfo->ehash_mask;
25395         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
25396  
25397 -
25398         rcu_read_lock();
25399  begin:
25400         sk_nulls_for_each_rcu(sk, node, &head->chain) {
25401 @@ -95,7 +95,7 @@ begin:
25402                                 sock_put(sk);
25403                                 goto begin;
25404                         }
25405 -               goto out;
25406 +                       goto out;
25407                 }
25408         }
25409         if (get_nulls_value(node) != slot)
25410 @@ -141,6 +141,9 @@ static inline int compute_score(struct s
25411                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25412                                 return -1;
25413                         score++;
25414 +               } else {
25415 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25416 +                               return -1;
25417                 }
25418                 if (sk->sk_bound_dev_if) {
25419                         if (sk->sk_bound_dev_if != dif)
25420 diff -NurpP --minimal linux-3.1.6/net/ipv6/ip6_output.c linux-3.1.6-vs2.3.2.5/net/ipv6/ip6_output.c
25421 --- linux-3.1.6/net/ipv6/ip6_output.c   2011-10-24 18:45:34.000000000 +0200
25422 +++ linux-3.1.6-vs2.3.2.5/net/ipv6/ip6_output.c 2011-10-24 18:53:33.000000000 +0200
25423 @@ -966,7 +966,8 @@ static int ip6_dst_lookup_tail(struct so
25424                 struct rt6_info *rt = (struct rt6_info *) *dst;
25425                 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
25426                                           sk ? inet6_sk(sk)->srcprefs : 0,
25427 -                                         &fl6->saddr);
25428 +                                         &fl6->saddr,
25429 +                                         sk ? sk->sk_nx_info : NULL);
25430                 if (err)
25431                         goto out_err_release;
25432         }
25433 diff -NurpP --minimal linux-3.1.6/net/ipv6/ndisc.c linux-3.1.6-vs2.3.2.5/net/ipv6/ndisc.c
25434 --- linux-3.1.6/net/ipv6/ndisc.c        2011-10-24 18:45:34.000000000 +0200
25435 +++ linux-3.1.6-vs2.3.2.5/net/ipv6/ndisc.c      2011-10-24 18:53:33.000000000 +0200
25436 @@ -591,7 +591,7 @@ static void ndisc_send_na(struct net_dev
25437         } else {
25438                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
25439                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
25440 -                                      &tmpaddr))
25441 +                                      &tmpaddr, NULL))
25442                         return;
25443                 src_addr = &tmpaddr;
25444         }
25445 diff -NurpP --minimal linux-3.1.6/net/ipv6/raw.c linux-3.1.6-vs2.3.2.5/net/ipv6/raw.c
25446 --- linux-3.1.6/net/ipv6/raw.c  2011-10-24 18:45:34.000000000 +0200
25447 +++ linux-3.1.6-vs2.3.2.5/net/ipv6/raw.c        2011-10-24 18:53:33.000000000 +0200
25448 @@ -30,6 +30,7 @@
25449  #include <linux/icmpv6.h>
25450  #include <linux/netfilter.h>
25451  #include <linux/netfilter_ipv6.h>
25452 +#include <linux/vs_inet6.h>
25453  #include <linux/skbuff.h>
25454  #include <linux/compat.h>
25455  #include <asm/uaccess.h>
25456 @@ -284,6 +285,13 @@ static int rawv6_bind(struct sock *sk, s
25457                                 goto out_unlock;
25458                 }
25459  
25460 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25461 +                       err = -EADDRNOTAVAIL;
25462 +                       if (dev)
25463 +                               dev_put(dev);
25464 +                       goto out;
25465 +               }
25466 +
25467                 /* ipv4 addr of the socket is invalid.  Only the
25468                  * unspecified and mapped address have a v4 equivalent.
25469                  */
25470 diff -NurpP --minimal linux-3.1.6/net/ipv6/route.c linux-3.1.6-vs2.3.2.5/net/ipv6/route.c
25471 --- linux-3.1.6/net/ipv6/route.c        2011-12-23 16:04:07.000000000 +0100
25472 +++ linux-3.1.6-vs2.3.2.5/net/ipv6/route.c      2011-11-15 17:08:44.000000000 +0100
25473 @@ -54,6 +54,7 @@
25474  #include <net/xfrm.h>
25475  #include <net/netevent.h>
25476  #include <net/netlink.h>
25477 +#include <linux/vs_inet6.h>
25478  
25479  #include <asm/uaccess.h>
25480  
25481 @@ -2085,15 +2086,17 @@ int ip6_route_get_saddr(struct net *net,
25482                         struct rt6_info *rt,
25483                         const struct in6_addr *daddr,
25484                         unsigned int prefs,
25485 -                       struct in6_addr *saddr)
25486 +                       struct in6_addr *saddr,
25487 +                       struct nx_info *nxi)
25488  {
25489         struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
25490         int err = 0;
25491 -       if (rt->rt6i_prefsrc.plen)
25492 +       if (rt->rt6i_prefsrc.plen && (!nxi ||
25493 +           v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
25494                 ipv6_addr_copy(saddr, &rt->rt6i_prefsrc.addr);
25495         else
25496                 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
25497 -                                        daddr, prefs, saddr);
25498 +                                        daddr, prefs, saddr, nxi);
25499         return err;
25500  }
25501  
25502 @@ -2423,7 +2426,8 @@ static int rt6_fill_node(struct net *net
25503                         NLA_PUT_U32(skb, RTA_IIF, iif);
25504         } else if (dst) {
25505                 struct in6_addr saddr_buf;
25506 -               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0)
25507 +               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
25508 +                                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
25509                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
25510         }
25511  
25512 @@ -2626,6 +2630,7 @@ static int rt6_info_route(struct rt6_inf
25513         struct seq_file *m = p_arg;
25514         struct neighbour *n;
25515  
25516 +       /* FIXME: check for network context? */
25517         seq_printf(m, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
25518  
25519  #ifdef CONFIG_IPV6_SUBTREES
25520 diff -NurpP --minimal linux-3.1.6/net/ipv6/tcp_ipv6.c linux-3.1.6-vs2.3.2.5/net/ipv6/tcp_ipv6.c
25521 --- linux-3.1.6/net/ipv6/tcp_ipv6.c     2011-10-24 18:45:34.000000000 +0200
25522 +++ linux-3.1.6-vs2.3.2.5/net/ipv6/tcp_ipv6.c   2011-10-24 18:53:33.000000000 +0200
25523 @@ -70,6 +70,7 @@
25524  
25525  #include <linux/crypto.h>
25526  #include <linux/scatterlist.h>
25527 +#include <linux/vs_inet6.h>
25528  
25529  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
25530  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
25531 @@ -162,8 +163,15 @@ static int tcp_v6_connect(struct sock *s
25532          *      connect() to INADDR_ANY means loopback (BSD'ism).
25533          */
25534  
25535 -       if(ipv6_addr_any(&usin->sin6_addr))
25536 -               usin->sin6_addr.s6_addr[15] = 0x1;
25537 +       if(ipv6_addr_any(&usin->sin6_addr)) {
25538 +               struct nx_info *nxi =  sk->sk_nx_info;
25539 +
25540 +               if (nxi && nx_info_has_v6(nxi))
25541 +                       /* FIXME: remap lback? */
25542 +                       usin->sin6_addr = nxi->v6.ip;
25543 +               else
25544 +                       usin->sin6_addr.s6_addr[15] = 0x1;
25545 +       }
25546  
25547         addr_type = ipv6_addr_type(&usin->sin6_addr);
25548  
25549 diff -NurpP --minimal linux-3.1.6/net/ipv6/udp.c linux-3.1.6-vs2.3.2.5/net/ipv6/udp.c
25550 --- linux-3.1.6/net/ipv6/udp.c  2011-10-24 18:45:34.000000000 +0200
25551 +++ linux-3.1.6-vs2.3.2.5/net/ipv6/udp.c        2011-10-24 18:53:33.000000000 +0200
25552 @@ -45,41 +45,67 @@
25553  #include <net/tcp_states.h>
25554  #include <net/ip6_checksum.h>
25555  #include <net/xfrm.h>
25556 +#include <linux/vs_inet6.h>
25557  
25558  #include <linux/proc_fs.h>
25559  #include <linux/seq_file.h>
25560  #include "udp_impl.h"
25561  
25562 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
25563 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25564  {
25565 -       const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
25566 +       const struct in6_addr *sk1_rcv_saddr6 = &inet6_sk(sk1)->rcv_saddr;
25567         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
25568 -       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk);
25569 +       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1);
25570         __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
25571 -       int sk_ipv6only = ipv6_only_sock(sk);
25572 +       int sk1_ipv6only = ipv6_only_sock(sk1);
25573         int sk2_ipv6only = inet_v6_ipv6only(sk2);
25574 -       int addr_type = ipv6_addr_type(sk_rcv_saddr6);
25575 +       int addr_type = ipv6_addr_type(sk1_rcv_saddr6);
25576         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
25577  
25578         /* if both are mapped, treat as IPv4 */
25579 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
25580 -               return (!sk2_ipv6only &&
25581 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
25582 +               if (!sk2_ipv6only &&
25583                         (!sk1_rcv_saddr || !sk2_rcv_saddr ||
25584 -                         sk1_rcv_saddr == sk2_rcv_saddr));
25585 +                         sk1_rcv_saddr == sk2_rcv_saddr))
25586 +                       goto vs_v4;
25587 +               else
25588 +                       return 0;
25589 +       }
25590  
25591         if (addr_type2 == IPV6_ADDR_ANY &&
25592             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
25593 -               return 1;
25594 +               goto vs;
25595  
25596         if (addr_type == IPV6_ADDR_ANY &&
25597 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25598 -               return 1;
25599 +           !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25600 +               goto vs;
25601  
25602         if (sk2_rcv_saddr6 &&
25603 -           ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
25604 -               return 1;
25605 +           ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
25606 +               goto vs;
25607  
25608         return 0;
25609 +
25610 +vs_v4:
25611 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
25612 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25613 +       if (!sk2_rcv_saddr)
25614 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
25615 +       if (!sk1_rcv_saddr)
25616 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
25617 +       return 1;
25618 +vs:
25619 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
25620 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25621 +       else if (addr_type2 == IPV6_ADDR_ANY)
25622 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
25623 +       else if (addr_type == IPV6_ADDR_ANY) {
25624 +               if (addr_type2 == IPV6_ADDR_MAPPED)
25625 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25626 +               else
25627 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
25628 +       }
25629 +       return 1;
25630  }
25631  
25632  static unsigned int udp6_portaddr_hash(struct net *net,
25633 @@ -143,6 +169,10 @@ static inline int compute_score(struct s
25634                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25635                                 return -1;
25636                         score++;
25637 +               } else {
25638 +                       /* block non nx_info ips */
25639 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25640 +                               return -1;
25641                 }
25642                 if (!ipv6_addr_any(&np->daddr)) {
25643                         if (!ipv6_addr_equal(&np->daddr, saddr))
25644 diff -NurpP --minimal linux-3.1.6/net/ipv6/xfrm6_policy.c linux-3.1.6-vs2.3.2.5/net/ipv6/xfrm6_policy.c
25645 --- linux-3.1.6/net/ipv6/xfrm6_policy.c 2011-07-22 11:18:13.000000000 +0200
25646 +++ linux-3.1.6-vs2.3.2.5/net/ipv6/xfrm6_policy.c       2011-10-24 18:53:33.000000000 +0200
25647 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
25648         dev = ip6_dst_idev(dst)->dev;
25649         ipv6_dev_get_saddr(dev_net(dev), dev,
25650                            (struct in6_addr *)&daddr->a6, 0,
25651 -                          (struct in6_addr *)&saddr->a6);
25652 +                          (struct in6_addr *)&saddr->a6, NULL);
25653         dst_release(dst);
25654         return 0;
25655  }
25656 diff -NurpP --minimal linux-3.1.6/net/netfilter/ipvs/ip_vs_xmit.c linux-3.1.6-vs2.3.2.5/net/netfilter/ipvs/ip_vs_xmit.c
25657 --- linux-3.1.6/net/netfilter/ipvs/ip_vs_xmit.c 2011-07-22 11:18:13.000000000 +0200
25658 +++ linux-3.1.6-vs2.3.2.5/net/netfilter/ipvs/ip_vs_xmit.c       2011-10-24 18:53:33.000000000 +0200
25659 @@ -226,7 +226,7 @@ __ip_vs_route_output_v6(struct net *net,
25660                 return dst;
25661         if (ipv6_addr_any(&fl6.saddr) &&
25662             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
25663 -                              &fl6.daddr, 0, &fl6.saddr) < 0)
25664 +                              &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
25665                 goto out_err;
25666         if (do_xfrm) {
25667                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
25668 diff -NurpP --minimal linux-3.1.6/net/netlink/af_netlink.c linux-3.1.6-vs2.3.2.5/net/netlink/af_netlink.c
25669 --- linux-3.1.6/net/netlink/af_netlink.c        2011-10-24 18:45:34.000000000 +0200
25670 +++ linux-3.1.6-vs2.3.2.5/net/netlink/af_netlink.c      2011-10-24 18:53:33.000000000 +0200
25671 @@ -55,6 +55,9 @@
25672  #include <linux/types.h>
25673  #include <linux/audit.h>
25674  #include <linux/mutex.h>
25675 +#include <linux/vs_context.h>
25676 +#include <linux/vs_network.h>
25677 +#include <linux/vs_limit.h>
25678  
25679  #include <net/net_namespace.h>
25680  #include <net/sock.h>
25681 @@ -1913,6 +1916,8 @@ static struct sock *netlink_seq_socket_i
25682                         sk_for_each(s, node, &hash->table[j]) {
25683                                 if (sock_net(s) != seq_file_net(seq))
25684                                         continue;
25685 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25686 +                                       continue;
25687                                 if (off == pos) {
25688                                         iter->link = i;
25689                                         iter->hash_idx = j;
25690 @@ -1947,7 +1952,8 @@ static void *netlink_seq_next(struct seq
25691         s = v;
25692         do {
25693                 s = sk_next(s);
25694 -       } while (s && sock_net(s) != seq_file_net(seq));
25695 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
25696 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
25697         if (s)
25698                 return s;
25699  
25700 @@ -1959,7 +1965,8 @@ static void *netlink_seq_next(struct seq
25701  
25702                 for (; j <= hash->mask; j++) {
25703                         s = sk_head(&hash->table[j]);
25704 -                       while (s && sock_net(s) != seq_file_net(seq))
25705 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
25706 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
25707                                 s = sk_next(s);
25708                         if (s) {
25709                                 iter->link = i;
25710 diff -NurpP --minimal linux-3.1.6/net/socket.c linux-3.1.6-vs2.3.2.5/net/socket.c
25711 --- linux-3.1.6/net/socket.c    2011-10-24 18:45:34.000000000 +0200
25712 +++ linux-3.1.6-vs2.3.2.5/net/socket.c  2011-10-24 18:53:33.000000000 +0200
25713 @@ -98,6 +98,10 @@
25714  
25715  #include <net/sock.h>
25716  #include <linux/netfilter.h>
25717 +#include <linux/vs_base.h>
25718 +#include <linux/vs_socket.h>
25719 +#include <linux/vs_inet.h>
25720 +#include <linux/vs_inet6.h>
25721  
25722  #include <linux/if_tun.h>
25723  #include <linux/ipv6_route.h>
25724 @@ -546,6 +550,7 @@ static inline int __sock_sendmsg_nosec(s
25725                                        struct msghdr *msg, size_t size)
25726  {
25727         struct sock_iocb *si = kiocb_to_siocb(iocb);
25728 +       size_t len;
25729  
25730         sock_update_classid(sock->sk);
25731  
25732 @@ -554,7 +559,22 @@ static inline int __sock_sendmsg_nosec(s
25733         si->msg = msg;
25734         si->size = size;
25735  
25736 -       return sock->ops->sendmsg(iocb, sock, msg, size);
25737 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
25738 +       if (sock->sk) {
25739 +               if (len == size)
25740 +                       vx_sock_send(sock->sk, size);
25741 +               else
25742 +                       vx_sock_fail(sock->sk, size);
25743 +       }
25744 +       vxdprintk(VXD_CBIT(net, 7),
25745 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
25746 +               sock, sock->sk,
25747 +               (sock->sk)?sock->sk->sk_nx_info:0,
25748 +               (sock->sk)?sock->sk->sk_vx_info:0,
25749 +               (sock->sk)?sock->sk->sk_xid:0,
25750 +               (sock->sk)?sock->sk->sk_nid:0,
25751 +               (unsigned int)size, len);
25752 +       return len;
25753  }
25754  
25755  static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
25756 @@ -694,6 +714,7 @@ static inline int __sock_recvmsg_nosec(s
25757                                        struct msghdr *msg, size_t size, int flags)
25758  {
25759         struct sock_iocb *si = kiocb_to_siocb(iocb);
25760 +       int len;
25761  
25762         sock_update_classid(sock->sk);
25763  
25764 @@ -703,7 +724,18 @@ static inline int __sock_recvmsg_nosec(s
25765         si->size = size;
25766         si->flags = flags;
25767  
25768 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
25769 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
25770 +       if ((len >= 0) && sock->sk)
25771 +               vx_sock_recv(sock->sk, len);
25772 +       vxdprintk(VXD_CBIT(net, 7),
25773 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
25774 +               sock, sock->sk,
25775 +               (sock->sk)?sock->sk->sk_nx_info:0,
25776 +               (sock->sk)?sock->sk->sk_vx_info:0,
25777 +               (sock->sk)?sock->sk->sk_xid:0,
25778 +               (sock->sk)?sock->sk->sk_nid:0,
25779 +               (unsigned int)size, len);
25780 +       return len;
25781  }
25782  
25783  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
25784 @@ -1188,6 +1220,13 @@ int __sock_create(struct net *net, int f
25785         if (type < 0 || type >= SOCK_MAX)
25786                 return -EINVAL;
25787  
25788 +       if (!nx_check(0, VS_ADMIN)) {
25789 +               if (family == PF_INET && !current_nx_info_has_v4())
25790 +                       return -EAFNOSUPPORT;
25791 +               if (family == PF_INET6 && !current_nx_info_has_v6())
25792 +                       return -EAFNOSUPPORT;
25793 +       }
25794 +
25795         /* Compatibility.
25796  
25797            This uglymoron is moved from INET layer to here to avoid
25798 @@ -1323,6 +1362,7 @@ SYSCALL_DEFINE3(socket, int, family, int
25799         if (retval < 0)
25800                 goto out;
25801  
25802 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
25803         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
25804         if (retval < 0)
25805                 goto out_release;
25806 @@ -1364,10 +1404,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
25807         err = sock_create(family, type, protocol, &sock1);
25808         if (err < 0)
25809                 goto out;
25810 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
25811  
25812         err = sock_create(family, type, protocol, &sock2);
25813         if (err < 0)
25814                 goto out_release_1;
25815 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
25816  
25817         err = sock1->ops->socketpair(sock1, sock2);
25818         if (err < 0)
25819 diff -NurpP --minimal linux-3.1.6/net/sunrpc/auth.c linux-3.1.6-vs2.3.2.5/net/sunrpc/auth.c
25820 --- linux-3.1.6/net/sunrpc/auth.c       2011-10-24 18:45:34.000000000 +0200
25821 +++ linux-3.1.6-vs2.3.2.5/net/sunrpc/auth.c     2011-10-24 18:53:33.000000000 +0200
25822 @@ -14,6 +14,7 @@
25823  #include <linux/hash.h>
25824  #include <linux/sunrpc/clnt.h>
25825  #include <linux/spinlock.h>
25826 +#include <linux/vs_tag.h>
25827  
25828  #ifdef RPC_DEBUG
25829  # define RPCDBG_FACILITY       RPCDBG_AUTH
25830 @@ -427,6 +428,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
25831         memset(&acred, 0, sizeof(acred));
25832         acred.uid = cred->fsuid;
25833         acred.gid = cred->fsgid;
25834 +       acred.tag = dx_current_tag();
25835         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
25836  
25837         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
25838 @@ -467,6 +469,7 @@ rpcauth_bind_root_cred(struct rpc_task *
25839         struct auth_cred acred = {
25840                 .uid = 0,
25841                 .gid = 0,
25842 +               .tag = dx_current_tag(),
25843         };
25844  
25845         dprintk("RPC: %5u looking up %s cred\n",
25846 diff -NurpP --minimal linux-3.1.6/net/sunrpc/auth_unix.c linux-3.1.6-vs2.3.2.5/net/sunrpc/auth_unix.c
25847 --- linux-3.1.6/net/sunrpc/auth_unix.c  2011-12-23 16:04:07.000000000 +0100
25848 +++ linux-3.1.6-vs2.3.2.5/net/sunrpc/auth_unix.c        2011-11-15 17:08:44.000000000 +0100
25849 @@ -12,12 +12,14 @@
25850  #include <linux/module.h>
25851  #include <linux/sunrpc/clnt.h>
25852  #include <linux/sunrpc/auth.h>
25853 +#include <linux/vs_tag.h>
25854  
25855  #define NFS_NGROUPS    16
25856  
25857  struct unx_cred {
25858         struct rpc_cred         uc_base;
25859         gid_t                   uc_gid;
25860 +       tag_t                   uc_tag;
25861         gid_t                   uc_gids[NFS_NGROUPS];
25862  };
25863  #define uc_uid                 uc_base.cr_uid
25864 @@ -78,6 +80,7 @@ unx_create_cred(struct rpc_auth *auth, s
25865                 groups = NFS_NGROUPS;
25866  
25867         cred->uc_gid = acred->gid;
25868 +       cred->uc_tag = acred->tag;
25869         for (i = 0; i < groups; i++)
25870                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
25871         if (i < NFS_NGROUPS)
25872 @@ -119,7 +122,9 @@ unx_match(struct auth_cred *acred, struc
25873         unsigned int i;
25874  
25875  
25876 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
25877 +       if (cred->uc_uid != acred->uid ||
25878 +               cred->uc_gid != acred->gid ||
25879 +               cred->uc_tag != acred->tag)
25880                 return 0;
25881  
25882         if (acred->group_info != NULL)
25883 @@ -145,7 +150,7 @@ unx_marshal(struct rpc_task *task, __be3
25884         struct rpc_clnt *clnt = task->tk_client;
25885         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
25886         __be32          *base, *hold;
25887 -       int             i;
25888 +       int             i, tag;
25889  
25890         *p++ = htonl(RPC_AUTH_UNIX);
25891         base = p++;
25892 @@ -155,9 +160,12 @@ unx_marshal(struct rpc_task *task, __be3
25893          * Copy the UTS nodename captured when the client was created.
25894          */
25895         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
25896 +       tag = task->tk_client->cl_tag;
25897  
25898 -       *p++ = htonl((u32) cred->uc_uid);
25899 -       *p++ = htonl((u32) cred->uc_gid);
25900 +       *p++ = htonl((u32) TAGINO_UID(tag,
25901 +               cred->uc_uid, cred->uc_tag));
25902 +       *p++ = htonl((u32) TAGINO_GID(tag,
25903 +               cred->uc_gid, cred->uc_tag));
25904         hold = p++;
25905         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
25906                 *p++ = htonl((u32) cred->uc_gids[i]);
25907 diff -NurpP --minimal linux-3.1.6/net/sunrpc/clnt.c linux-3.1.6-vs2.3.2.5/net/sunrpc/clnt.c
25908 --- linux-3.1.6/net/sunrpc/clnt.c       2011-10-24 18:45:34.000000000 +0200
25909 +++ linux-3.1.6-vs2.3.2.5/net/sunrpc/clnt.c     2011-10-24 18:53:33.000000000 +0200
25910 @@ -31,6 +31,7 @@
25911  #include <linux/in.h>
25912  #include <linux/in6.h>
25913  #include <linux/un.h>
25914 +#include <linux/vs_cvirt.h>
25915  
25916  #include <linux/sunrpc/clnt.h>
25917  #include <linux/sunrpc/rpc_pipe_fs.h>
25918 @@ -361,6 +362,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
25919         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
25920                 clnt->cl_chatty = 1;
25921  
25922 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
25923 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
25924 +               clnt->cl_tag = 1; */
25925         return clnt;
25926  }
25927  EXPORT_SYMBOL_GPL(rpc_create);
25928 diff -NurpP --minimal linux-3.1.6/net/unix/af_unix.c linux-3.1.6-vs2.3.2.5/net/unix/af_unix.c
25929 --- linux-3.1.6/net/unix/af_unix.c      2011-10-24 18:45:34.000000000 +0200
25930 +++ linux-3.1.6-vs2.3.2.5/net/unix/af_unix.c    2011-10-24 18:53:33.000000000 +0200
25931 @@ -114,6 +114,8 @@
25932  #include <linux/mount.h>
25933  #include <net/checksum.h>
25934  #include <linux/security.h>
25935 +#include <linux/vs_context.h>
25936 +#include <linux/vs_limit.h>
25937  
25938  static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
25939  static DEFINE_SPINLOCK(unix_table_lock);
25940 @@ -258,6 +260,8 @@ static struct sock *__unix_find_socket_b
25941                 if (!net_eq(sock_net(s), net))
25942                         continue;
25943  
25944 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25945 +                       continue;
25946                 if (u->addr->len == len &&
25947                     !memcmp(u->addr->name, sunname, len))
25948                         goto found;
25949 @@ -2204,6 +2208,8 @@ static struct sock *unix_seq_idx(struct 
25950         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
25951                 if (sock_net(s) != seq_file_net(seq))
25952                         continue;
25953 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25954 +                       continue;
25955                 if (off == pos)
25956                         return s;
25957                 ++off;
25958 @@ -2228,7 +2234,8 @@ static void *unix_seq_next(struct seq_fi
25959                 sk = first_unix_socket(&iter->i);
25960         else
25961                 sk = next_unix_socket(&iter->i, sk);
25962 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
25963 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
25964 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
25965                 sk = next_unix_socket(&iter->i, sk);
25966         return sk;
25967  }
25968 diff -NurpP --minimal linux-3.1.6/scripts/checksyscalls.sh linux-3.1.6-vs2.3.2.5/scripts/checksyscalls.sh
25969 --- linux-3.1.6/scripts/checksyscalls.sh        2011-03-15 18:07:46.000000000 +0100
25970 +++ linux-3.1.6-vs2.3.2.5/scripts/checksyscalls.sh      2011-10-24 18:53:33.000000000 +0200
25971 @@ -193,7 +193,6 @@ cat << EOF
25972  #define __IGNORE_afs_syscall
25973  #define __IGNORE_getpmsg
25974  #define __IGNORE_putpmsg
25975 -#define __IGNORE_vserver
25976  EOF
25977  }
25978  
25979 diff -NurpP --minimal linux-3.1.6/security/commoncap.c linux-3.1.6-vs2.3.2.5/security/commoncap.c
25980 --- linux-3.1.6/security/commoncap.c    2011-07-22 11:18:14.000000000 +0200
25981 +++ linux-3.1.6-vs2.3.2.5/security/commoncap.c  2011-10-24 18:53:33.000000000 +0200
25982 @@ -62,6 +62,7 @@ int cap_netlink_recv(struct sk_buff *skb
25983                 return -EPERM;
25984         return 0;
25985  }
25986 +
25987  EXPORT_SYMBOL(cap_netlink_recv);
25988  
25989  /**
25990 @@ -83,14 +84,20 @@ EXPORT_SYMBOL(cap_netlink_recv);
25991  int cap_capable(struct task_struct *tsk, const struct cred *cred,
25992                 struct user_namespace *targ_ns, int cap, int audit)
25993  {
25994 +       struct vx_info *vxi = tsk->vx_info;
25995 +
25996         for (;;) {
25997                 /* The creator of the user namespace has all caps. */
25998                 if (targ_ns != &init_user_ns && targ_ns->creator == cred->user)
25999                         return 0;
26000  
26001                 /* Do we have the necessary capabilities? */
26002 -               if (targ_ns == cred->user->user_ns)
26003 -                       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
26004 +               if (targ_ns == cred->user->user_ns) {
26005 +                       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
26006 +                           cap_raised(cred->cap_effective, cap))
26007 +                               return 0;
26008 +                       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
26009 +               }
26010  
26011                 /* Have we tried all of the parent namespaces? */
26012                 if (targ_ns == &init_user_ns)
26013 @@ -611,7 +618,7 @@ int cap_inode_setxattr(struct dentry *de
26014  
26015         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26016                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26017 -           !capable(CAP_SYS_ADMIN))
26018 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26019                 return -EPERM;
26020         return 0;
26021  }
26022 @@ -637,7 +644,7 @@ int cap_inode_removexattr(struct dentry 
26023  
26024         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26025                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26026 -           !capable(CAP_SYS_ADMIN))
26027 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26028                 return -EPERM;
26029         return 0;
26030  }
26031 diff -NurpP --minimal linux-3.1.6/security/selinux/hooks.c linux-3.1.6-vs2.3.2.5/security/selinux/hooks.c
26032 --- linux-3.1.6/security/selinux/hooks.c        2011-10-24 18:45:35.000000000 +0200
26033 +++ linux-3.1.6-vs2.3.2.5/security/selinux/hooks.c      2011-10-24 18:53:33.000000000 +0200
26034 @@ -67,7 +67,6 @@
26035  #include <linux/dccp.h>
26036  #include <linux/quota.h>
26037  #include <linux/un.h>          /* for Unix socket types */
26038 -#include <net/af_unix.h>       /* for Unix socket types */
26039  #include <linux/parser.h>
26040  #include <linux/nfs_mount.h>
26041  #include <net/ipv6.h>
This page took 2.291645 seconds and 4 git commands to generate.