]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- updated for 2.6.32.58
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-2.6.32.56/Documentation/scheduler/sched-cfs-hard-limits.txt linux-2.6.32.56-vs2.3.0.36.29.9/Documentation/scheduler/sched-cfs-hard-limits.txt
2 --- linux-2.6.32.56/Documentation/scheduler/sched-cfs-hard-limits.txt   1970-01-01 01:00:00.000000000 +0100
3 +++ linux-2.6.32.56-vs2.3.0.36.29.9/Documentation/scheduler/sched-cfs-hard-limits.txt   2011-06-10 13:03:02.000000000 +0200
4 @@ -0,0 +1,48 @@
5 +CPU HARD LIMITS FOR CFS GROUPS
6 +==============================
7 +
8 +1. Overview
9 +2. Interface
10 +3. Examples
11 +
12 +1. Overview
13 +-----------
14 +
15 +CFS is a proportional share scheduler which tries to divide the CPU time
16 +proportionately between tasks or groups of tasks (task group/cgroup) depending
17 +on the priority/weight of the task or shares assigned to groups of tasks.
18 +In CFS, a task/task group can get more than its share of CPU if there are
19 +enough idle CPU cycles available in the system, due to the work conserving
20 +nature of the scheduler. However in certain scenarios (like pay-per-use),
21 +it is desirable not to provide extra time to a group even in the presence
22 +of idle CPU cycles. This is where hard limiting can be of use.
23 +
24 +Hard limits for task groups can be set by specifying how much CPU runtime a
25 +group can consume within a given period. If the group consumes more CPU time
26 +than the runtime in a given period, it gets throttled. None of the tasks of
27 +the throttled group gets to run until the runtime of the group gets refreshed
28 +at the beginning of the next period.
29 +
30 +2. Interface
31 +------------
32 +
33 +Hard limit feature adds 2 cgroup files for CFS group scheduler:
34 +
35 +cfs_runtime_us: Hard limit for the group in microseconds.
36 +
37 +cfs_period_us: Time period in microseconds within which hard limits is
38 +enforced.
39 +
40 +A group gets created with default values for runtime (infinite runtime which
41 +means hard limits disabled) and period (0.5s). Each group can set its own
42 +values for runtime and period independent of other groups in the system.
43 +
44 +3. Examples
45 +-----------
46 +
47 +# mount -t cgroup -ocpu none /cgroups/
48 +# cd /cgroups
49 +# mkdir 1
50 +# cd 1/
51 +# echo 250000 > cfs_runtime_us /* set a 250ms runtime or limit */
52 +# echo 500000 > cfs_period_us /* set a 500ms period */
53 diff -NurpP --minimal linux-2.6.32.56/Documentation/vserver/debug.txt linux-2.6.32.56-vs2.3.0.36.29.9/Documentation/vserver/debug.txt
54 --- linux-2.6.32.56/Documentation/vserver/debug.txt     1970-01-01 01:00:00.000000000 +0100
55 +++ linux-2.6.32.56-vs2.3.0.36.29.9/Documentation/vserver/debug.txt     2011-06-10 13:03:02.000000000 +0200
56 @@ -0,0 +1,154 @@
57 +
58 +debug_cvirt:
59 +
60 + 2   4 "vx_map_tgid: %p/%llx: %d -> %d"
61 +       "vx_rmap_tgid: %p/%llx: %d -> %d"
62 +
63 +debug_dlim:
64 +
65 + 0   1 "ALLOC (%p,#%d)%c inode (%d)"
66 +       "FREE  (%p,#%d)%c inode"
67 + 1   2 "ALLOC (%p,#%d)%c %lld bytes (%d)"
68 +       "FREE  (%p,#%d)%c %lld bytes"
69 + 2   4 "ADJUST: %lld,%lld on %ld,%ld [mult=%d]"
70 + 3   8 "ext3_has_free_blocks(%p): %lu<%lu+1, %c, %u!=%u r=%d"
71 +       "ext3_has_free_blocks(%p): free=%lu, root=%lu"
72 +       "rcu_free_dl_info(%p)"
73 + 4  10 "alloc_dl_info(%p,%d) = %p"
74 +       "dealloc_dl_info(%p)"
75 +       "get_dl_info(%p[#%d.%d])"
76 +       "put_dl_info(%p[#%d.%d])"
77 + 5  20 "alloc_dl_info(%p,%d)*"
78 + 6  40 "__hash_dl_info: %p[#%d]"
79 +       "__unhash_dl_info: %p[#%d]"
80 + 7  80 "locate_dl_info(%p,#%d) = %p"
81 +
82 +debug_misc:
83 +
84 + 0   1 "destroy_dqhash: %p [#0x%08x] c=%d"
85 +       "new_dqhash: %p [#0x%08x]"
86 +       "vroot[%d]_clr_dev: dev=%p[%lu,%d:%d]"
87 +       "vroot[%d]_get_real_bdev: dev=%p[%lu,%d:%d]"
88 +       "vroot[%d]_set_dev: dev=%p[%lu,%d:%d]"
89 +       "vroot_get_real_bdev not set"
90 + 1   2 "cow_break_link(»%s«)"
91 +       "temp copy »%s«"
92 + 2   4 "dentry_open(new): %p"
93 +       "dentry_open(old): %p"
94 +       "lookup_create(new): %p"
95 +       "old path »%s«"
96 +       "path_lookup(old): %d"
97 +       "vfs_create(new): %d"
98 +       "vfs_rename: %d"
99 +       "vfs_sendfile: %d"
100 + 3   8 "fput(new_file=%p[#%d])"
101 +       "fput(old_file=%p[#%d])"
102 + 4  10 "vx_info_kill(%p[#%d],%d,%d) = %d"
103 +       "vx_info_kill(%p[#%d],%d,%d)*"
104 + 5  20 "vs_reboot(%p[#%d],%d)"
105 + 6  40 "dropping task %p[#%u,%u] for %p[#%u,%u]"
106 +
107 +debug_net:
108 +
109 + 2   4 "nx_addr_conflict(%p,%p) %d.%d,%d.%d"
110 + 3   8 "inet_bind(%p) %d.%d.%d.%d, %d.%d.%d.%d, %d.%d.%d.%d"
111 +       "inet_bind(%p)* %p,%p;%lx %d.%d.%d.%d"
112 + 4  10 "ip_route_connect(%p) %p,%p;%lx"
113 + 5  20 "__addr_in_socket(%p,%d.%d.%d.%d) %p:%d.%d.%d.%d %p;%lx"
114 + 6  40 "sk,egf: %p [#%d] (from %d)"
115 +       "sk,egn: %p [#%d] (from %d)"
116 +       "sk,req: %p [#%d] (from %d)"
117 +       "sk: %p [#%d] (from %d)"
118 +       "tw: %p [#%d] (from %d)"
119 + 7  80 "__sock_recvmsg: %p[%p,%p,%p;%d]:%d/%d"
120 +       "__sock_sendmsg: %p[%p,%p,%p;%d]:%d/%d"
121 +
122 +debug_nid:
123 +
124 + 0   1 "__lookup_nx_info(#%u): %p[#%u]"
125 +       "alloc_nx_info(%d) = %p"
126 +       "create_nx_info(%d) (dynamic rejected)"
127 +       "create_nx_info(%d) = %p (already there)"
128 +       "create_nx_info(%d) = %p (new)"
129 +       "dealloc_nx_info(%p)"
130 + 1   2 "alloc_nx_info(%d)*"
131 +       "create_nx_info(%d)*"
132 + 2   4 "get_nx_info(%p[#%d.%d])"
133 +       "put_nx_info(%p[#%d.%d])"
134 + 3   8 "claim_nx_info(%p[#%d.%d.%d]) %p"
135 +       "clr_nx_info(%p[#%d.%d])"
136 +       "init_nx_info(%p[#%d.%d])"
137 +       "release_nx_info(%p[#%d.%d.%d]) %p"
138 +       "set_nx_info(%p[#%d.%d])"
139 + 4  10 "__hash_nx_info: %p[#%d]"
140 +       "__nx_dynamic_id: [#%d]"
141 +       "__unhash_nx_info: %p[#%d.%d.%d]"
142 + 5  20 "moved task %p into nxi:%p[#%d]"
143 +       "nx_migrate_task(%p,%p[#%d.%d.%d])"
144 +       "task_get_nx_info(%p)"
145 + 6  40 "nx_clear_persistent(%p[#%d])"
146 +
147 +debug_quota:
148 +
149 + 0   1 "quota_sync_dqh(%p,%d) discard inode %p"
150 + 1   2 "quota_sync_dqh(%p,%d)"
151 +       "sync_dquots(%p,%d)"
152 +       "sync_dquots_dqh(%p,%d)"
153 + 3   8 "do_quotactl(%p,%d,cmd=%d,id=%d,%p)"
154 +
155 +debug_switch:
156 +
157 + 0   1 "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]"
158 + 1   2 "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]"
159 + 4  10 "%s: (%s %s) returned %s with %d"
160 +
161 +debug_tag:
162 +
163 + 7  80 "dx_parse_tag(»%s«): %d:#%d"
164 +       "dx_propagate_tag(%p[#%lu.%d]): %d,%d"
165 +
166 +debug_xid:
167 +
168 + 0   1 "__lookup_vx_info(#%u): %p[#%u]"
169 +       "alloc_vx_info(%d) = %p"
170 +       "alloc_vx_info(%d)*"
171 +       "create_vx_info(%d) (dynamic rejected)"
172 +       "create_vx_info(%d) = %p (already there)"
173 +       "create_vx_info(%d) = %p (new)"
174 +       "dealloc_vx_info(%p)"
175 +       "loc_vx_info(%d) = %p (found)"
176 +       "loc_vx_info(%d) = %p (new)"
177 +       "loc_vx_info(%d) = %p (not available)"
178 + 1   2 "create_vx_info(%d)*"
179 +       "loc_vx_info(%d)*"
180 + 2   4 "get_vx_info(%p[#%d.%d])"
181 +       "put_vx_info(%p[#%d.%d])"
182 + 3   8 "claim_vx_info(%p[#%d.%d.%d]) %p"
183 +       "clr_vx_info(%p[#%d.%d])"
184 +       "init_vx_info(%p[#%d.%d])"
185 +       "release_vx_info(%p[#%d.%d.%d]) %p"
186 +       "set_vx_info(%p[#%d.%d])"
187 + 4  10 "__hash_vx_info: %p[#%d]"
188 +       "__unhash_vx_info: %p[#%d.%d.%d]"
189 +       "__vx_dynamic_id: [#%d]"
190 + 5  20 "enter_vx_info(%p[#%d],%p) %p[#%d,%p]"
191 +       "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]"
192 +       "moved task %p into vxi:%p[#%d]"
193 +       "task_get_vx_info(%p)"
194 +       "vx_migrate_task(%p,%p[#%d.%d])"
195 + 6  40 "vx_clear_persistent(%p[#%d])"
196 +       "vx_exit_init(%p[#%d],%p[#%d,%d,%d])"
197 +       "vx_set_init(%p[#%d],%p[#%d,%d,%d])"
198 +       "vx_set_persistent(%p[#%d])"
199 +       "vx_set_reaper(%p[#%d],%p[#%d,%d])"
200 + 7  80 "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]"
201 +
202 +
203 +debug_limit:
204 +
205 + n 2^n "vx_acc_cres[%5d,%s,%2d]: %5d%s"
206 +       "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
207 +
208 + m 2^m "vx_acc_page[%5d,%s,%2d]: %5d%s"
209 +       "vx_acc_pages[%5d,%s,%2d]: %5d += %5d"
210 +       "vx_pages_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
211 diff -NurpP --minimal linux-2.6.32.56/arch/alpha/Kconfig linux-2.6.32.56-vs2.3.0.36.29.9/arch/alpha/Kconfig
212 --- linux-2.6.32.56/arch/alpha/Kconfig  2009-12-03 20:01:49.000000000 +0100
213 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/alpha/Kconfig  2011-06-10 13:03:02.000000000 +0200
214 @@ -674,6 +674,8 @@ config DUMMY_CONSOLE
215         depends on VGA_HOSE
216         default y
217  
218 +source "kernel/vserver/Kconfig"
219 +
220  source "security/Kconfig"
221  
222  source "crypto/Kconfig"
223 diff -NurpP --minimal linux-2.6.32.56/arch/alpha/kernel/entry.S linux-2.6.32.56-vs2.3.0.36.29.9/arch/alpha/kernel/entry.S
224 --- linux-2.6.32.56/arch/alpha/kernel/entry.S   2009-06-11 17:11:46.000000000 +0200
225 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/alpha/kernel/entry.S   2011-06-10 13:03:02.000000000 +0200
226 @@ -874,24 +874,15 @@ sys_getxgid:
227         .globl  sys_getxpid
228         .ent    sys_getxpid
229  sys_getxpid:
230 +       lda     $sp, -16($sp)
231 +       stq     $26, 0($sp)
232         .prologue 0
233 -       ldq     $2, TI_TASK($8)
234  
235 -       /* See linux/kernel/timer.c sys_getppid for discussion
236 -          about this loop.  */
237 -       ldq     $3, TASK_GROUP_LEADER($2)
238 -       ldq     $4, TASK_REAL_PARENT($3)
239 -       ldl     $0, TASK_TGID($2)
240 -1:     ldl     $1, TASK_TGID($4)
241 -#ifdef CONFIG_SMP
242 -       mov     $4, $5
243 -       mb
244 -       ldq     $3, TASK_GROUP_LEADER($2)
245 -       ldq     $4, TASK_REAL_PARENT($3)
246 -       cmpeq   $4, $5, $5
247 -       beq     $5, 1b
248 -#endif
249 -       stq     $1, 80($sp)
250 +       lda     $16, 96($sp)
251 +       jsr     $26, do_getxpid
252 +       ldq     $26, 0($sp)
253 +
254 +       lda     $sp, 16($sp)
255         ret
256  .end sys_getxpid
257  
258 diff -NurpP --minimal linux-2.6.32.56/arch/alpha/kernel/osf_sys.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/alpha/kernel/osf_sys.c
259 --- linux-2.6.32.56/arch/alpha/kernel/osf_sys.c 2012-02-09 10:22:13.000000000 +0100
260 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/alpha/kernel/osf_sys.c 2011-11-17 12:18:26.000000000 +0100
261 @@ -865,7 +865,7 @@ SYSCALL_DEFINE2(osf_gettimeofday, struct
262  {
263         if (tv) {
264                 struct timeval ktv;
265 -               do_gettimeofday(&ktv);
266 +               vx_gettimeofday(&ktv);
267                 if (put_tv32(tv, &ktv))
268                         return -EFAULT;
269         }
270 diff -NurpP --minimal linux-2.6.32.56/arch/alpha/kernel/ptrace.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/alpha/kernel/ptrace.c
271 --- linux-2.6.32.56/arch/alpha/kernel/ptrace.c  2009-09-10 15:25:14.000000000 +0200
272 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/alpha/kernel/ptrace.c  2011-06-10 13:03:02.000000000 +0200
273 @@ -14,6 +14,7 @@
274  #include <linux/slab.h>
275  #include <linux/security.h>
276  #include <linux/signal.h>
277 +#include <linux/vs_base.h>
278  
279  #include <asm/uaccess.h>
280  #include <asm/pgtable.h>
281 diff -NurpP --minimal linux-2.6.32.56/arch/alpha/kernel/systbls.S linux-2.6.32.56-vs2.3.0.36.29.9/arch/alpha/kernel/systbls.S
282 --- linux-2.6.32.56/arch/alpha/kernel/systbls.S 2009-03-24 14:18:08.000000000 +0100
283 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/alpha/kernel/systbls.S 2011-06-10 13:03:02.000000000 +0200
284 @@ -446,7 +446,7 @@ sys_call_table:
285         .quad sys_stat64                        /* 425 */
286         .quad sys_lstat64
287         .quad sys_fstat64
288 -       .quad sys_ni_syscall                    /* sys_vserver */
289 +       .quad sys_vserver                       /* sys_vserver */
290         .quad sys_ni_syscall                    /* sys_mbind */
291         .quad sys_ni_syscall                    /* sys_get_mempolicy */
292         .quad sys_ni_syscall                    /* sys_set_mempolicy */
293 diff -NurpP --minimal linux-2.6.32.56/arch/alpha/kernel/traps.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/alpha/kernel/traps.c
294 --- linux-2.6.32.56/arch/alpha/kernel/traps.c   2009-06-11 17:11:46.000000000 +0200
295 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/alpha/kernel/traps.c   2011-06-10 13:03:02.000000000 +0200
296 @@ -183,7 +183,8 @@ die_if_kernel(char * str, struct pt_regs
297  #ifdef CONFIG_SMP
298         printk("CPU %d ", hard_smp_processor_id());
299  #endif
300 -       printk("%s(%d): %s %ld\n", current->comm, task_pid_nr(current), str, err);
301 +       printk("%s(%d[#%u]): %s %ld\n", current->comm,
302 +               task_pid_nr(current), current->xid, str, err);
303         dik_show_regs(regs, r9_15);
304         add_taint(TAINT_DIE);
305         dik_show_trace((unsigned long *)(regs+1));
306 diff -NurpP --minimal linux-2.6.32.56/arch/alpha/mm/fault.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/alpha/mm/fault.c
307 --- linux-2.6.32.56/arch/alpha/mm/fault.c       2009-09-10 15:25:14.000000000 +0200
308 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/alpha/mm/fault.c       2011-06-10 13:03:02.000000000 +0200
309 @@ -193,8 +193,8 @@ do_page_fault(unsigned long address, uns
310                 down_read(&mm->mmap_sem);
311                 goto survive;
312         }
313 -       printk(KERN_ALERT "VM: killing process %s(%d)\n",
314 -              current->comm, task_pid_nr(current));
315 +       printk(KERN_ALERT "VM: killing process %s(%d:#%u)\n",
316 +              current->comm, task_pid_nr(current), current->xid);
317         if (!user_mode(regs))
318                 goto no_context;
319         do_group_exit(SIGKILL);
320 diff -NurpP --minimal linux-2.6.32.56/arch/arm/Kconfig linux-2.6.32.56-vs2.3.0.36.29.9/arch/arm/Kconfig
321 --- linux-2.6.32.56/arch/arm/Kconfig    2012-02-09 10:22:13.000000000 +0100
322 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/arm/Kconfig    2012-01-10 09:18:12.000000000 +0100
323 @@ -1536,6 +1536,8 @@ source "fs/Kconfig"
324  
325  source "arch/arm/Kconfig.debug"
326  
327 +source "kernel/vserver/Kconfig"
328 +
329  source "security/Kconfig"
330  
331  source "crypto/Kconfig"
332 diff -NurpP --minimal linux-2.6.32.56/arch/arm/include/asm/tlb.h linux-2.6.32.56-vs2.3.0.36.29.9/arch/arm/include/asm/tlb.h
333 --- linux-2.6.32.56/arch/arm/include/asm/tlb.h  2009-09-10 15:25:15.000000000 +0200
334 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/arm/include/asm/tlb.h  2011-06-10 13:03:02.000000000 +0200
335 @@ -27,6 +27,7 @@
336  
337  #else /* !CONFIG_MMU */
338  
339 +#include <linux/vs_memory.h>
340  #include <asm/pgalloc.h>
341  
342  /*
343 diff -NurpP --minimal linux-2.6.32.56/arch/arm/kernel/calls.S linux-2.6.32.56-vs2.3.0.36.29.9/arch/arm/kernel/calls.S
344 --- linux-2.6.32.56/arch/arm/kernel/calls.S     2012-02-09 10:22:13.000000000 +0100
345 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/arm/kernel/calls.S     2011-06-10 13:03:02.000000000 +0200
346 @@ -322,7 +322,7 @@
347  /* 310 */      CALL(sys_request_key)
348                 CALL(sys_keyctl)
349                 CALL(ABI(sys_semtimedop, sys_oabi_semtimedop))
350 -/* vserver */  CALL(sys_ni_syscall)
351 +               CALL(sys_vserver)
352                 CALL(sys_ioprio_set)
353  /* 315 */      CALL(sys_ioprio_get)
354                 CALL(sys_inotify_init)
355 diff -NurpP --minimal linux-2.6.32.56/arch/arm/kernel/process.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/arm/kernel/process.c
356 --- linux-2.6.32.56/arch/arm/kernel/process.c   2012-02-09 10:22:13.000000000 +0100
357 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/arm/kernel/process.c   2012-01-10 09:18:12.000000000 +0100
358 @@ -272,7 +272,8 @@ void __show_regs(struct pt_regs *regs)
359  void show_regs(struct pt_regs * regs)
360  {
361         printk("\n");
362 -       printk("Pid: %d, comm: %20s\n", task_pid_nr(current), current->comm);
363 +       printk("Pid: %d[#%u], comm: %20s\n",
364 +               task_pid_nr(current), current->xid, current->comm);
365         __show_regs(regs);
366         __backtrace();
367  }
368 diff -NurpP --minimal linux-2.6.32.56/arch/arm/kernel/traps.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/arm/kernel/traps.c
369 --- linux-2.6.32.56/arch/arm/kernel/traps.c     2009-12-03 20:01:50.000000000 +0100
370 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/arm/kernel/traps.c     2011-06-10 13:03:02.000000000 +0200
371 @@ -234,8 +234,8 @@ static void __die(const char *str, int e
372         sysfs_printk_last_file();
373         print_modules();
374         __show_regs(regs);
375 -       printk(KERN_EMERG "Process %.*s (pid: %d, stack limit = 0x%p)\n",
376 -               TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), thread + 1);
377 +       printk(KERN_EMERG "Process %.*s (pid: %d:#%u, stack limit = 0x%p)\n",
378 +               TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), tsk->xid, thread + 1);
379  
380         if (!user_mode(regs) || in_interrupt()) {
381                 dump_mem(KERN_EMERG, "Stack: ", regs->ARM_sp,
382 diff -NurpP --minimal linux-2.6.32.56/arch/avr32/mm/fault.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/avr32/mm/fault.c
383 --- linux-2.6.32.56/arch/avr32/mm/fault.c       2009-09-10 15:25:20.000000000 +0200
384 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/avr32/mm/fault.c       2011-06-10 13:03:02.000000000 +0200
385 @@ -216,7 +216,8 @@ out_of_memory:
386                 down_read(&mm->mmap_sem);
387                 goto survive;
388         }
389 -       printk("VM: Killing process %s\n", tsk->comm);
390 +       printk("VM: Killing process %s(%d:#%u)\n",
391 +               tsk->comm, task_pid_nr(tsk), tsk->xid);
392         if (user_mode(regs))
393                 do_group_exit(SIGKILL);
394         goto no_context;
395 diff -NurpP --minimal linux-2.6.32.56/arch/cris/Kconfig linux-2.6.32.56-vs2.3.0.36.29.9/arch/cris/Kconfig
396 --- linux-2.6.32.56/arch/cris/Kconfig   2009-06-11 17:11:56.000000000 +0200
397 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/cris/Kconfig   2011-06-10 13:03:02.000000000 +0200
398 @@ -685,6 +685,8 @@ source "drivers/staging/Kconfig"
399  
400  source "arch/cris/Kconfig.debug"
401  
402 +source "kernel/vserver/Kconfig"
403 +
404  source "security/Kconfig"
405  
406  source "crypto/Kconfig"
407 diff -NurpP --minimal linux-2.6.32.56/arch/cris/mm/fault.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/cris/mm/fault.c
408 --- linux-2.6.32.56/arch/cris/mm/fault.c        2009-12-03 20:01:56.000000000 +0100
409 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/cris/mm/fault.c        2011-06-10 13:03:02.000000000 +0200
410 @@ -245,7 +245,8 @@ do_page_fault(unsigned long address, str
411  
412   out_of_memory:
413         up_read(&mm->mmap_sem);
414 -       printk("VM: killing process %s\n", tsk->comm);
415 +       printk("VM: killing process %s(%d:#%u)\n",
416 +               tsk->comm, task_pid_nr(tsk), tsk->xid);
417         if (user_mode(regs))
418                 do_exit(SIGKILL);
419         goto no_context;
420 diff -NurpP --minimal linux-2.6.32.56/arch/frv/kernel/kernel_thread.S linux-2.6.32.56-vs2.3.0.36.29.9/arch/frv/kernel/kernel_thread.S
421 --- linux-2.6.32.56/arch/frv/kernel/kernel_thread.S     2008-12-25 00:26:37.000000000 +0100
422 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/frv/kernel/kernel_thread.S     2011-06-10 13:03:02.000000000 +0200
423 @@ -37,7 +37,7 @@ kernel_thread:
424  
425         # start by forking the current process, but with shared VM
426         setlos.p        #__NR_clone,gr7         ; syscall number
427 -       ori             gr10,#CLONE_VM,gr8      ; first syscall arg     [clone_flags]
428 +       ori             gr10,#CLONE_KT,gr8      ; first syscall arg     [clone_flags]
429         sethi.p         #0xe4e4,gr9             ; second syscall arg    [newsp]
430         setlo           #0xe4e4,gr9
431         setlos.p        #0,gr10                 ; third syscall arg     [parent_tidptr]
432 diff -NurpP --minimal linux-2.6.32.56/arch/frv/mm/fault.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/frv/mm/fault.c
433 --- linux-2.6.32.56/arch/frv/mm/fault.c 2009-09-10 15:25:22.000000000 +0200
434 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/frv/mm/fault.c 2011-06-10 13:03:02.000000000 +0200
435 @@ -257,7 +257,8 @@ asmlinkage void do_page_fault(int datamm
436   */
437   out_of_memory:
438         up_read(&mm->mmap_sem);
439 -       printk("VM: killing process %s\n", current->comm);
440 +       printk("VM: killing process %s(%d:#%u)\n",
441 +               current->comm, task_pid_nr(current), current->xid);
442         if (user_mode(__frame))
443                 do_group_exit(SIGKILL);
444         goto no_context;
445 diff -NurpP --minimal linux-2.6.32.56/arch/h8300/Kconfig linux-2.6.32.56-vs2.3.0.36.29.9/arch/h8300/Kconfig
446 --- linux-2.6.32.56/arch/h8300/Kconfig  2009-03-24 14:18:24.000000000 +0100
447 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/h8300/Kconfig  2011-06-10 13:03:02.000000000 +0200
448 @@ -226,6 +226,8 @@ source "fs/Kconfig"
449  
450  source "arch/h8300/Kconfig.debug"
451  
452 +source "kernel/vserver/Kconfig"
453 +
454  source "security/Kconfig"
455  
456  source "crypto/Kconfig"
457 diff -NurpP --minimal linux-2.6.32.56/arch/ia64/Kconfig linux-2.6.32.56-vs2.3.0.36.29.9/arch/ia64/Kconfig
458 --- linux-2.6.32.56/arch/ia64/Kconfig   2009-12-03 20:01:56.000000000 +0100
459 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/ia64/Kconfig   2011-06-10 13:03:02.000000000 +0200
460 @@ -685,6 +685,8 @@ source "fs/Kconfig"
461  
462  source "arch/ia64/Kconfig.debug"
463  
464 +source "kernel/vserver/Kconfig"
465 +
466  source "security/Kconfig"
467  
468  source "crypto/Kconfig"
469 diff -NurpP --minimal linux-2.6.32.56/arch/ia64/ia32/ia32_entry.S linux-2.6.32.56-vs2.3.0.36.29.9/arch/ia64/ia32/ia32_entry.S
470 --- linux-2.6.32.56/arch/ia64/ia32/ia32_entry.S 2009-06-11 17:11:57.000000000 +0200
471 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/ia64/ia32/ia32_entry.S 2011-06-10 13:03:02.000000000 +0200
472 @@ -451,7 +451,7 @@ ia32_syscall_table:
473         data8 sys_tgkill        /* 270 */
474         data8 compat_sys_utimes
475         data8 sys32_fadvise64_64
476 -       data8 sys_ni_syscall
477 +       data8 sys32_vserver
478         data8 sys_ni_syscall
479         data8 sys_ni_syscall    /* 275 */
480         data8 sys_ni_syscall
481 diff -NurpP --minimal linux-2.6.32.56/arch/ia64/include/asm/tlb.h linux-2.6.32.56-vs2.3.0.36.29.9/arch/ia64/include/asm/tlb.h
482 --- linux-2.6.32.56/arch/ia64/include/asm/tlb.h 2009-09-10 15:25:22.000000000 +0200
483 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/ia64/include/asm/tlb.h 2011-06-10 13:03:02.000000000 +0200
484 @@ -40,6 +40,7 @@
485  #include <linux/mm.h>
486  #include <linux/pagemap.h>
487  #include <linux/swap.h>
488 +#include <linux/vs_memory.h>
489  
490  #include <asm/pgalloc.h>
491  #include <asm/processor.h>
492 diff -NurpP --minimal linux-2.6.32.56/arch/ia64/kernel/entry.S linux-2.6.32.56-vs2.3.0.36.29.9/arch/ia64/kernel/entry.S
493 --- linux-2.6.32.56/arch/ia64/kernel/entry.S    2009-09-10 15:25:22.000000000 +0200
494 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/ia64/kernel/entry.S    2011-06-10 13:03:02.000000000 +0200
495 @@ -1753,7 +1753,7 @@ sys_call_table:
496         data8 sys_mq_notify
497         data8 sys_mq_getsetattr
498         data8 sys_kexec_load
499 -       data8 sys_ni_syscall                    // reserved for vserver
500 +       data8 sys_vserver
501         data8 sys_waitid                        // 1270
502         data8 sys_add_key
503         data8 sys_request_key
504 diff -NurpP --minimal linux-2.6.32.56/arch/ia64/kernel/perfmon.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/ia64/kernel/perfmon.c
505 --- linux-2.6.32.56/arch/ia64/kernel/perfmon.c  2009-09-10 15:25:22.000000000 +0200
506 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/ia64/kernel/perfmon.c  2011-06-10 13:03:02.000000000 +0200
507 @@ -41,6 +41,7 @@
508  #include <linux/rcupdate.h>
509  #include <linux/completion.h>
510  #include <linux/tracehook.h>
511 +#include <linux/vs_memory.h>
512  
513  #include <asm/errno.h>
514  #include <asm/intrinsics.h>
515 @@ -2372,7 +2373,7 @@ pfm_smpl_buffer_alloc(struct task_struct
516          */
517         insert_vm_struct(mm, vma);
518  
519 -       mm->total_vm  += size >> PAGE_SHIFT;
520 +       vx_vmpages_add(mm, size >> PAGE_SHIFT);
521         vm_stat_account(vma->vm_mm, vma->vm_flags, vma->vm_file,
522                                                         vma_pages(vma));
523         up_write(&task->mm->mmap_sem);
524 diff -NurpP --minimal linux-2.6.32.56/arch/ia64/kernel/process.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/ia64/kernel/process.c
525 --- linux-2.6.32.56/arch/ia64/kernel/process.c  2009-12-03 20:01:56.000000000 +0100
526 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/ia64/kernel/process.c  2011-06-10 13:03:02.000000000 +0200
527 @@ -110,8 +110,8 @@ show_regs (struct pt_regs *regs)
528         unsigned long ip = regs->cr_iip + ia64_psr(regs)->ri;
529  
530         print_modules();
531 -       printk("\nPid: %d, CPU %d, comm: %20s\n", task_pid_nr(current),
532 -                       smp_processor_id(), current->comm);
533 +       printk("\nPid: %d[#%u], CPU %d, comm: %20s\n", task_pid_nr(current),
534 +                       current->xid, smp_processor_id(), current->comm);
535         printk("psr : %016lx ifs : %016lx ip  : [<%016lx>]    %s (%s)\n",
536                regs->cr_ipsr, regs->cr_ifs, ip, print_tainted(),
537                init_utsname()->release);
538 diff -NurpP --minimal linux-2.6.32.56/arch/ia64/kernel/ptrace.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/ia64/kernel/ptrace.c
539 --- linux-2.6.32.56/arch/ia64/kernel/ptrace.c   2009-09-10 15:25:22.000000000 +0200
540 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/ia64/kernel/ptrace.c   2011-06-10 13:03:02.000000000 +0200
541 @@ -22,6 +22,7 @@
542  #include <linux/regset.h>
543  #include <linux/elf.h>
544  #include <linux/tracehook.h>
545 +#include <linux/vs_base.h>
546  
547  #include <asm/pgtable.h>
548  #include <asm/processor.h>
549 diff -NurpP --minimal linux-2.6.32.56/arch/ia64/kernel/traps.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/ia64/kernel/traps.c
550 --- linux-2.6.32.56/arch/ia64/kernel/traps.c    2008-12-25 00:26:37.000000000 +0100
551 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/ia64/kernel/traps.c    2011-06-10 13:03:02.000000000 +0200
552 @@ -60,8 +60,9 @@ die (const char *str, struct pt_regs *re
553         put_cpu();
554  
555         if (++die.lock_owner_depth < 3) {
556 -               printk("%s[%d]: %s %ld [%d]\n",
557 -               current->comm, task_pid_nr(current), str, err, ++die_counter);
558 +               printk("%s[%d[#%u]]: %s %ld [%d]\n",
559 +                       current->comm, task_pid_nr(current), current->xid,
560 +                       str, err, ++die_counter);
561                 if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV)
562                     != NOTIFY_STOP)
563                         show_regs(regs);
564 @@ -324,8 +325,9 @@ handle_fpu_swa (int fp_fault, struct pt_
565                         if ((last.count & 15) < 5 && (ia64_fetchadd(1, &last.count, acq) & 15) < 5) {
566                                 last.time = current_jiffies + 5 * HZ;
567                                 printk(KERN_WARNING
568 -                                       "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
569 -                                       current->comm, task_pid_nr(current), regs->cr_iip + ia64_psr(regs)->ri, isr);
570 +                                       "%s(%d[#%u]): floating-point assist fault at ip %016lx, isr %016lx\n",
571 +                                       current->comm, task_pid_nr(current), current->xid,
572 +                                       regs->cr_iip + ia64_psr(regs)->ri, isr);
573                         }
574                 }
575         }
576 diff -NurpP --minimal linux-2.6.32.56/arch/ia64/mm/fault.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/ia64/mm/fault.c
577 --- linux-2.6.32.56/arch/ia64/mm/fault.c        2009-09-10 15:25:23.000000000 +0200
578 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/ia64/mm/fault.c        2011-06-10 13:03:02.000000000 +0200
579 @@ -10,6 +10,7 @@
580  #include <linux/interrupt.h>
581  #include <linux/kprobes.h>
582  #include <linux/kdebug.h>
583 +#include <linux/vs_memory.h>
584  
585  #include <asm/pgtable.h>
586  #include <asm/processor.h>
587 @@ -281,7 +282,8 @@ ia64_do_page_fault (unsigned long addres
588                 down_read(&mm->mmap_sem);
589                 goto survive;
590         }
591 -       printk(KERN_CRIT "VM: killing process %s\n", current->comm);
592 +       printk(KERN_CRIT "VM: killing process %s(%d:#%u)\n",
593 +               current->comm, task_pid_nr(current), current->xid);
594         if (user_mode(regs))
595                 do_group_exit(SIGKILL);
596         goto no_context;
597 diff -NurpP --minimal linux-2.6.32.56/arch/m32r/kernel/traps.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/m32r/kernel/traps.c
598 --- linux-2.6.32.56/arch/m32r/kernel/traps.c    2009-12-03 20:01:57.000000000 +0100
599 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/m32r/kernel/traps.c    2011-06-10 13:03:02.000000000 +0200
600 @@ -196,8 +196,9 @@ static void show_registers(struct pt_reg
601         } else {
602                 printk("SPI: %08lx\n", sp);
603         }
604 -       printk("Process %s (pid: %d, process nr: %d, stackpage=%08lx)",
605 -               current->comm, task_pid_nr(current), 0xffff & i, 4096+(unsigned long)current);
606 +       printk("Process %s (pid: %d[#%u], process nr: %d, stackpage=%08lx)",
607 +               current->comm, task_pid_nr(current), current->xid,
608 +               0xffff & i, 4096+(unsigned long)current);
609  
610         /*
611          * When in-kernel, we also print out the stack and code at the
612 diff -NurpP --minimal linux-2.6.32.56/arch/m32r/mm/fault.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/m32r/mm/fault.c
613 --- linux-2.6.32.56/arch/m32r/mm/fault.c        2009-09-10 15:25:23.000000000 +0200
614 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/m32r/mm/fault.c        2011-06-10 13:03:02.000000000 +0200
615 @@ -276,7 +276,8 @@ out_of_memory:
616                 down_read(&mm->mmap_sem);
617                 goto survive;
618         }
619 -       printk("VM: killing process %s\n", tsk->comm);
620 +       printk("VM: killing process %s(%d:#%u)\n",
621 +               tsk->comm, task_pid_nr(tsk), tsk->xid);
622         if (error_code & ACE_USERMODE)
623                 do_group_exit(SIGKILL);
624         goto no_context;
625 diff -NurpP --minimal linux-2.6.32.56/arch/m68k/Kconfig linux-2.6.32.56-vs2.3.0.36.29.9/arch/m68k/Kconfig
626 --- linux-2.6.32.56/arch/m68k/Kconfig   2009-12-03 20:01:57.000000000 +0100
627 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/m68k/Kconfig   2011-06-10 13:03:02.000000000 +0200
628 @@ -622,6 +622,8 @@ source "fs/Kconfig"
629  
630  source "arch/m68k/Kconfig.debug"
631  
632 +source "kernel/vserver/Kconfig"
633 +
634  source "security/Kconfig"
635  
636  source "crypto/Kconfig"
637 diff -NurpP --minimal linux-2.6.32.56/arch/m68k/kernel/ptrace.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/m68k/kernel/ptrace.c
638 --- linux-2.6.32.56/arch/m68k/kernel/ptrace.c   2008-12-25 00:26:37.000000000 +0100
639 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/m68k/kernel/ptrace.c   2011-06-10 13:03:02.000000000 +0200
640 @@ -18,6 +18,7 @@
641  #include <linux/ptrace.h>
642  #include <linux/user.h>
643  #include <linux/signal.h>
644 +#include <linux/vs_base.h>
645  
646  #include <asm/uaccess.h>
647  #include <asm/page.h>
648 @@ -269,6 +270,8 @@ long arch_ptrace(struct task_struct *chi
649                 ret = ptrace_request(child, request, addr, data);
650                 break;
651         }
652 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
653 +               goto out_tsk;
654  
655         return ret;
656  out_eio:
657 diff -NurpP --minimal linux-2.6.32.56/arch/m68k/kernel/traps.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/m68k/kernel/traps.c
658 --- linux-2.6.32.56/arch/m68k/kernel/traps.c    2009-09-10 15:25:23.000000000 +0200
659 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/m68k/kernel/traps.c    2011-06-10 13:03:02.000000000 +0200
660 @@ -906,8 +906,8 @@ void show_registers(struct pt_regs *regs
661         printk("d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
662                regs->d4, regs->d5, regs->a0, regs->a1);
663  
664 -       printk("Process %s (pid: %d, task=%p)\n",
665 -               current->comm, task_pid_nr(current), current);
666 +       printk("Process %s (pid: %d[#%u], task=%p)\n",
667 +               current->comm, task_pid_nr(current), current->xid, current);
668         addr = (unsigned long)&fp->un;
669         printk("Frame format=%X ", regs->format);
670         switch (regs->format) {
671 diff -NurpP --minimal linux-2.6.32.56/arch/m68k/mm/fault.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/m68k/mm/fault.c
672 --- linux-2.6.32.56/arch/m68k/mm/fault.c        2009-09-10 15:25:23.000000000 +0200
673 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/m68k/mm/fault.c        2011-06-10 13:03:02.000000000 +0200
674 @@ -186,7 +186,8 @@ out_of_memory:
675                 goto survive;
676         }
677  
678 -       printk("VM: killing process %s\n", current->comm);
679 +       printk("VM: killing process %s(%d:#%u)\n",
680 +               current->comm, task_pid_nr(current), current->xid);
681         if (user_mode(regs))
682                 do_group_exit(SIGKILL);
683  
684 diff -NurpP --minimal linux-2.6.32.56/arch/m68knommu/Kconfig linux-2.6.32.56-vs2.3.0.36.29.9/arch/m68knommu/Kconfig
685 --- linux-2.6.32.56/arch/m68knommu/Kconfig      2009-12-03 20:01:57.000000000 +0100
686 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/m68knommu/Kconfig      2011-06-10 13:03:02.000000000 +0200
687 @@ -727,6 +727,8 @@ source "fs/Kconfig"
688  
689  source "arch/m68knommu/Kconfig.debug"
690  
691 +source "kernel/vserver/Kconfig"
692 +
693  source "security/Kconfig"
694  
695  source "crypto/Kconfig"
696 diff -NurpP --minimal linux-2.6.32.56/arch/m68knommu/kernel/traps.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/m68knommu/kernel/traps.c
697 --- linux-2.6.32.56/arch/m68knommu/kernel/traps.c       2009-09-10 15:25:23.000000000 +0200
698 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/m68knommu/kernel/traps.c       2011-06-10 13:03:02.000000000 +0200
699 @@ -78,8 +78,9 @@ void die_if_kernel(char *str, struct pt_
700         printk(KERN_EMERG "d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
701                fp->d4, fp->d5, fp->a0, fp->a1);
702  
703 -       printk(KERN_EMERG "Process %s (pid: %d, stackpage=%08lx)\n",
704 -               current->comm, current->pid, PAGE_SIZE+(unsigned long)current);
705 +       printk(KERN_EMERG "Process %s (pid: %d[#%u], stackpage=%08lx)\n",
706 +               current->comm, task_pid_nr(current), current->xid,
707 +               PAGE_SIZE+(unsigned long)current);
708         show_stack(NULL, (unsigned long *)(fp + 1));
709         add_taint(TAINT_DIE);
710         do_exit(SIGSEGV);
711 diff -NurpP --minimal linux-2.6.32.56/arch/microblaze/mm/fault.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/microblaze/mm/fault.c
712 --- linux-2.6.32.56/arch/microblaze/mm/fault.c  2009-09-10 15:25:24.000000000 +0200
713 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/microblaze/mm/fault.c  2011-06-10 13:03:02.000000000 +0200
714 @@ -279,7 +279,8 @@ out_of_memory:
715                 goto survive;
716         }
717         up_read(&mm->mmap_sem);
718 -       printk(KERN_WARNING "VM: killing process %s\n", current->comm);
719 +       printk(KERN_WARNING "VM: killing process %s(%d:#%u)\n",
720 +               current->comm, task_pid_nr(current), current->xid);
721         if (user_mode(regs))
722                 do_exit(SIGKILL);
723         bad_page_fault(regs, address, SIGKILL);
724 diff -NurpP --minimal linux-2.6.32.56/arch/mips/Kconfig linux-2.6.32.56-vs2.3.0.36.29.9/arch/mips/Kconfig
725 --- linux-2.6.32.56/arch/mips/Kconfig   2009-12-03 20:01:58.000000000 +0100
726 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/mips/Kconfig   2011-06-10 13:03:02.000000000 +0200
727 @@ -2188,6 +2188,8 @@ source "fs/Kconfig"
728  
729  source "arch/mips/Kconfig.debug"
730  
731 +source "kernel/vserver/Kconfig"
732 +
733  source "security/Kconfig"
734  
735  source "crypto/Kconfig"
736 diff -NurpP --minimal linux-2.6.32.56/arch/mips/kernel/ptrace.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/mips/kernel/ptrace.c
737 --- linux-2.6.32.56/arch/mips/kernel/ptrace.c   2008-12-25 00:26:37.000000000 +0100
738 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/mips/kernel/ptrace.c   2011-06-10 13:03:02.000000000 +0200
739 @@ -25,6 +25,7 @@
740  #include <linux/security.h>
741  #include <linux/audit.h>
742  #include <linux/seccomp.h>
743 +#include <linux/vs_base.h>
744  
745  #include <asm/byteorder.h>
746  #include <asm/cpu.h>
747 @@ -259,6 +260,9 @@ long arch_ptrace(struct task_struct *chi
748  {
749         int ret;
750  
751 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
752 +               goto out;
753 +
754         switch (request) {
755         /* when I and D space are separate, these will need to be fixed. */
756         case PTRACE_PEEKTEXT: /* read word at location addr. */
757 diff -NurpP --minimal linux-2.6.32.56/arch/mips/kernel/scall32-o32.S linux-2.6.32.56-vs2.3.0.36.29.9/arch/mips/kernel/scall32-o32.S
758 --- linux-2.6.32.56/arch/mips/kernel/scall32-o32.S      2009-12-03 20:01:59.000000000 +0100
759 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/mips/kernel/scall32-o32.S      2011-06-10 13:03:02.000000000 +0200
760 @@ -525,7 +525,7 @@ einval:     li      v0, -ENOSYS
761         sys     sys_mq_timedreceive     5
762         sys     sys_mq_notify           2       /* 4275 */
763         sys     sys_mq_getsetattr       3
764 -       sys     sys_ni_syscall          0       /* sys_vserver */
765 +       sys     sys_vserver             3
766         sys     sys_waitid              5
767         sys     sys_ni_syscall          0       /* available, was setaltroot */
768         sys     sys_add_key             5       /* 4280 */
769 diff -NurpP --minimal linux-2.6.32.56/arch/mips/kernel/scall64-64.S linux-2.6.32.56-vs2.3.0.36.29.9/arch/mips/kernel/scall64-64.S
770 --- linux-2.6.32.56/arch/mips/kernel/scall64-64.S       2009-12-03 20:01:59.000000000 +0100
771 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/mips/kernel/scall64-64.S       2011-06-10 13:03:02.000000000 +0200
772 @@ -362,7 +362,7 @@ sys_call_table:
773         PTR     sys_mq_timedreceive
774         PTR     sys_mq_notify
775         PTR     sys_mq_getsetattr               /* 5235 */
776 -       PTR     sys_ni_syscall                  /* sys_vserver */
777 +       PTR     sys_vserver
778         PTR     sys_waitid
779         PTR     sys_ni_syscall                  /* available, was setaltroot */
780         PTR     sys_add_key
781 diff -NurpP --minimal linux-2.6.32.56/arch/mips/kernel/scall64-n32.S linux-2.6.32.56-vs2.3.0.36.29.9/arch/mips/kernel/scall64-n32.S
782 --- linux-2.6.32.56/arch/mips/kernel/scall64-n32.S      2009-12-03 20:01:59.000000000 +0100
783 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/mips/kernel/scall64-n32.S      2011-06-10 13:03:02.000000000 +0200
784 @@ -360,7 +360,7 @@ EXPORT(sysn32_call_table)
785         PTR     compat_sys_mq_timedreceive
786         PTR     compat_sys_mq_notify
787         PTR     compat_sys_mq_getsetattr
788 -       PTR     sys_ni_syscall                  /* 6240, sys_vserver */
789 +       PTR     sys32_vserver                   /* 6240 */
790         PTR     compat_sys_waitid
791         PTR     sys_ni_syscall                  /* available, was setaltroot */
792         PTR     sys_add_key
793 diff -NurpP --minimal linux-2.6.32.56/arch/mips/kernel/scall64-o32.S linux-2.6.32.56-vs2.3.0.36.29.9/arch/mips/kernel/scall64-o32.S
794 --- linux-2.6.32.56/arch/mips/kernel/scall64-o32.S      2009-12-03 20:01:59.000000000 +0100
795 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/mips/kernel/scall64-o32.S      2011-06-10 13:03:02.000000000 +0200
796 @@ -480,7 +480,7 @@ sys_call_table:
797         PTR     compat_sys_mq_timedreceive
798         PTR     compat_sys_mq_notify            /* 4275 */
799         PTR     compat_sys_mq_getsetattr
800 -       PTR     sys_ni_syscall                  /* sys_vserver */
801 +       PTR     sys32_vserver
802         PTR     sys_32_waitid
803         PTR     sys_ni_syscall                  /* available, was setaltroot */
804         PTR     sys_add_key                     /* 4280 */
805 diff -NurpP --minimal linux-2.6.32.56/arch/mips/kernel/traps.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/mips/kernel/traps.c
806 --- linux-2.6.32.56/arch/mips/kernel/traps.c    2009-12-03 20:01:59.000000000 +0100
807 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/mips/kernel/traps.c    2011-06-10 13:03:02.000000000 +0200
808 @@ -335,9 +335,10 @@ void show_registers(const struct pt_regs
809  
810         __show_regs(regs);
811         print_modules();
812 -       printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
813 -              current->comm, current->pid, current_thread_info(), current,
814 -             field, current_thread_info()->tp_value);
815 +       printk("Process %s (pid: %d:#%u, threadinfo=%p, task=%p, tls=%0*lx)\n",
816 +               current->comm, task_pid_nr(current), current->xid,
817 +               current_thread_info(), current,
818 +               field, current_thread_info()->tp_value);
819         if (cpu_has_userlocal) {
820                 unsigned long tls;
821  
822 diff -NurpP --minimal linux-2.6.32.56/arch/mn10300/mm/fault.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/mn10300/mm/fault.c
823 --- linux-2.6.32.56/arch/mn10300/mm/fault.c     2009-09-10 15:25:39.000000000 +0200
824 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/mn10300/mm/fault.c     2011-06-10 13:03:02.000000000 +0200
825 @@ -339,7 +339,8 @@ no_context:
826  out_of_memory:
827         up_read(&mm->mmap_sem);
828         monitor_signal(regs);
829 -       printk(KERN_ALERT "VM: killing process %s\n", tsk->comm);
830 +       printk(KERN_ALERT "VM: killing process %s(%d:#%u)\n",
831 +               tsk->comm, task_pid_nr(tsk), tsk->xid);
832         if ((fault_code & MMUFCR_xFC_ACCESS) == MMUFCR_xFC_ACCESS_USR)
833                 do_exit(SIGKILL);
834         goto no_context;
835 diff -NurpP --minimal linux-2.6.32.56/arch/parisc/Kconfig linux-2.6.32.56-vs2.3.0.36.29.9/arch/parisc/Kconfig
836 --- linux-2.6.32.56/arch/parisc/Kconfig 2009-12-03 20:02:00.000000000 +0100
837 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/parisc/Kconfig 2011-06-10 13:03:02.000000000 +0200
838 @@ -294,6 +294,8 @@ source "fs/Kconfig"
839  
840  source "arch/parisc/Kconfig.debug"
841  
842 +source "kernel/vserver/Kconfig"
843 +
844  source "security/Kconfig"
845  
846  source "crypto/Kconfig"
847 diff -NurpP --minimal linux-2.6.32.56/arch/parisc/kernel/syscall_table.S linux-2.6.32.56-vs2.3.0.36.29.9/arch/parisc/kernel/syscall_table.S
848 --- linux-2.6.32.56/arch/parisc/kernel/syscall_table.S  2009-12-03 20:02:00.000000000 +0100
849 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/parisc/kernel/syscall_table.S  2011-06-10 13:03:02.000000000 +0200
850 @@ -361,7 +361,7 @@
851         ENTRY_COMP(mbind)               /* 260 */
852         ENTRY_COMP(get_mempolicy)
853         ENTRY_COMP(set_mempolicy)
854 -       ENTRY_SAME(ni_syscall)  /* 263: reserved for vserver */
855 +       ENTRY_DIFF(vserver)
856         ENTRY_SAME(add_key)
857         ENTRY_SAME(request_key)         /* 265 */
858         ENTRY_SAME(keyctl)
859 diff -NurpP --minimal linux-2.6.32.56/arch/parisc/kernel/traps.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/parisc/kernel/traps.c
860 --- linux-2.6.32.56/arch/parisc/kernel/traps.c  2009-09-10 15:25:40.000000000 +0200
861 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/parisc/kernel/traps.c  2011-06-10 13:03:02.000000000 +0200
862 @@ -236,8 +236,9 @@ void die_if_kernel(char *str, struct pt_
863                 if (err == 0)
864                         return; /* STFU */
865  
866 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
867 -                       current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
868 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld) at " RFMT "\n",
869 +                       current->comm, task_pid_nr(current), current->xid,
870 +                       str, err, regs->iaoq[0]);
871  #ifdef PRINT_USER_FAULTS
872                 /* XXX for debugging only */
873                 show_regs(regs);
874 @@ -270,8 +271,8 @@ void die_if_kernel(char *str, struct pt_
875                 pdc_console_restart();
876         
877         if (err)
878 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
879 -                       current->comm, task_pid_nr(current), str, err);
880 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld)\n",
881 +                       current->comm, task_pid_nr(current), current->xid, str, err);
882  
883         /* Wot's wrong wif bein' racy? */
884         if (current->thread.flags & PARISC_KERNEL_DEATH) {
885 diff -NurpP --minimal linux-2.6.32.56/arch/parisc/mm/fault.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/parisc/mm/fault.c
886 --- linux-2.6.32.56/arch/parisc/mm/fault.c      2009-09-10 15:25:40.000000000 +0200
887 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/parisc/mm/fault.c      2011-06-10 13:03:02.000000000 +0200
888 @@ -237,8 +237,9 @@ bad_area:
889  
890  #ifdef PRINT_USER_FAULTS
891                 printk(KERN_DEBUG "\n");
892 -               printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n",
893 -                   task_pid_nr(tsk), tsk->comm, code, address);
894 +               printk(KERN_DEBUG "do_page_fault() pid=%d:#%u "
895 +                   "command='%s' type=%lu address=0x%08lx\n",
896 +                   task_pid_nr(tsk), tsk->xid, tsk->comm, code, address);
897                 if (vma) {
898                         printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n",
899                                         vma->vm_start, vma->vm_end);
900 @@ -264,7 +265,8 @@ no_context:
901  
902    out_of_memory:
903         up_read(&mm->mmap_sem);
904 -       printk(KERN_CRIT "VM: killing process %s\n", current->comm);
905 +       printk(KERN_CRIT "VM: killing process %s(%d:#%u)\n",
906 +               current->comm, current->pid, current->xid);
907         if (user_mode(regs))
908                 do_group_exit(SIGKILL);
909         goto no_context;
910 diff -NurpP --minimal linux-2.6.32.56/arch/powerpc/Kconfig linux-2.6.32.56-vs2.3.0.36.29.9/arch/powerpc/Kconfig
911 --- linux-2.6.32.56/arch/powerpc/Kconfig        2009-12-03 20:02:00.000000000 +0100
912 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/powerpc/Kconfig        2011-06-10 13:03:02.000000000 +0200
913 @@ -943,6 +943,8 @@ source "lib/Kconfig"
914  
915  source "arch/powerpc/Kconfig.debug"
916  
917 +source "kernel/vserver/Kconfig"
918 +
919  source "security/Kconfig"
920  
921  config KEYS_COMPAT
922 diff -NurpP --minimal linux-2.6.32.56/arch/powerpc/include/asm/unistd.h linux-2.6.32.56-vs2.3.0.36.29.9/arch/powerpc/include/asm/unistd.h
923 --- linux-2.6.32.56/arch/powerpc/include/asm/unistd.h   2009-12-03 20:02:01.000000000 +0100
924 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/powerpc/include/asm/unistd.h   2011-06-10 13:03:02.000000000 +0200
925 @@ -275,7 +275,7 @@
926  #endif
927  #define __NR_rtas              255
928  #define __NR_sys_debug_setcontext 256
929 -/* Number 257 is reserved for vserver */
930 +#define __NR_vserver           257
931  #define __NR_migrate_pages     258
932  #define __NR_mbind             259
933  #define __NR_get_mempolicy     260
934 diff -NurpP --minimal linux-2.6.32.56/arch/powerpc/kernel/process.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/powerpc/kernel/process.c
935 --- linux-2.6.32.56/arch/powerpc/kernel/process.c       2012-02-09 10:22:15.000000000 +0100
936 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/powerpc/kernel/process.c       2011-06-10 13:03:02.000000000 +0200
937 @@ -519,8 +519,9 @@ void show_regs(struct pt_regs * regs)
938  #else
939                 printk("DAR: "REG", DSISR: "REG"\n", regs->dar, regs->dsisr);
940  #endif
941 -       printk("TASK = %p[%d] '%s' THREAD: %p",
942 -              current, task_pid_nr(current), current->comm, task_thread_info(current));
943 +       printk("TASK = %p[%d,#%u] '%s' THREAD: %p",
944 +              current, task_pid_nr(current), current->xid,
945 +              current->comm, task_thread_info(current));
946  
947  #ifdef CONFIG_SMP
948         printk(" CPU: %d", raw_smp_processor_id());
949 diff -NurpP --minimal linux-2.6.32.56/arch/powerpc/kernel/traps.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/powerpc/kernel/traps.c
950 --- linux-2.6.32.56/arch/powerpc/kernel/traps.c 2009-09-10 15:25:41.000000000 +0200
951 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/powerpc/kernel/traps.c 2011-06-10 13:03:02.000000000 +0200
952 @@ -931,8 +931,9 @@ void nonrecoverable_exception(struct pt_
953  
954  void trace_syscall(struct pt_regs *regs)
955  {
956 -       printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
957 -              current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
958 +       printk("Task: %p(%d[#%u]), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
959 +              current, task_pid_nr(current), current->xid,
960 +              regs->nip, regs->link, regs->gpr[0],
961                regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
962  }
963  
964 diff -NurpP --minimal linux-2.6.32.56/arch/powerpc/kernel/vdso.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/powerpc/kernel/vdso.c
965 --- linux-2.6.32.56/arch/powerpc/kernel/vdso.c  2009-12-03 20:02:02.000000000 +0100
966 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/powerpc/kernel/vdso.c  2011-06-10 13:03:02.000000000 +0200
967 @@ -23,6 +23,7 @@
968  #include <linux/security.h>
969  #include <linux/bootmem.h>
970  #include <linux/lmb.h>
971 +#include <linux/vs_memory.h>
972  
973  #include <asm/pgtable.h>
974  #include <asm/system.h>
975 diff -NurpP --minimal linux-2.6.32.56/arch/powerpc/mm/fault.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/powerpc/mm/fault.c
976 --- linux-2.6.32.56/arch/powerpc/mm/fault.c     2009-12-03 20:02:02.000000000 +0100
977 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/powerpc/mm/fault.c     2011-06-10 13:03:02.000000000 +0200
978 @@ -358,7 +358,8 @@ out_of_memory:
979                 down_read(&mm->mmap_sem);
980                 goto survive;
981         }
982 -       printk("VM: killing process %s\n", current->comm);
983 +       printk("VM: killing process %s(%d:#%u)\n",
984 +               current->comm, current->pid, current->xid);
985         if (user_mode(regs))
986                 do_group_exit(SIGKILL);
987         return SIGKILL;
988 diff -NurpP --minimal linux-2.6.32.56/arch/s390/Kconfig linux-2.6.32.56-vs2.3.0.36.29.9/arch/s390/Kconfig
989 --- linux-2.6.32.56/arch/s390/Kconfig   2009-12-03 20:02:03.000000000 +0100
990 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/s390/Kconfig   2011-06-10 13:03:02.000000000 +0200
991 @@ -616,6 +616,8 @@ source "fs/Kconfig"
992  
993  source "arch/s390/Kconfig.debug"
994  
995 +source "kernel/vserver/Kconfig"
996 +
997  source "security/Kconfig"
998  
999  source "crypto/Kconfig"
1000 diff -NurpP --minimal linux-2.6.32.56/arch/s390/include/asm/tlb.h linux-2.6.32.56-vs2.3.0.36.29.9/arch/s390/include/asm/tlb.h
1001 --- linux-2.6.32.56/arch/s390/include/asm/tlb.h 2009-09-10 15:25:43.000000000 +0200
1002 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/s390/include/asm/tlb.h 2011-06-10 13:03:02.000000000 +0200
1003 @@ -23,6 +23,8 @@
1004  
1005  #include <linux/mm.h>
1006  #include <linux/swap.h>
1007 +#include <linux/vs_memory.h>
1008 +
1009  #include <asm/processor.h>
1010  #include <asm/pgalloc.h>
1011  #include <asm/smp.h>
1012 diff -NurpP --minimal linux-2.6.32.56/arch/s390/include/asm/unistd.h linux-2.6.32.56-vs2.3.0.36.29.9/arch/s390/include/asm/unistd.h
1013 --- linux-2.6.32.56/arch/s390/include/asm/unistd.h      2009-12-03 20:02:03.000000000 +0100
1014 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/s390/include/asm/unistd.h      2011-06-10 13:03:02.000000000 +0200
1015 @@ -202,7 +202,7 @@
1016  #define __NR_clock_gettime     (__NR_timer_create+6)
1017  #define __NR_clock_getres      (__NR_timer_create+7)
1018  #define __NR_clock_nanosleep   (__NR_timer_create+8)
1019 -/* Number 263 is reserved for vserver */
1020 +#define __NR_vserver           263
1021  #define __NR_statfs64          265
1022  #define __NR_fstatfs64         266
1023  #define __NR_remap_file_pages  267
1024 diff -NurpP --minimal linux-2.6.32.56/arch/s390/kernel/ptrace.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/s390/kernel/ptrace.c
1025 --- linux-2.6.32.56/arch/s390/kernel/ptrace.c   2012-02-09 10:22:15.000000000 +0100
1026 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/s390/kernel/ptrace.c   2011-06-10 13:03:02.000000000 +0200
1027 @@ -36,6 +36,7 @@
1028  #include <linux/regset.h>
1029  #include <linux/tracehook.h>
1030  #include <linux/seccomp.h>
1031 +#include <linux/vs_base.h>
1032  #include <linux/compat.h>
1033  #include <trace/syscall.h>
1034  #include <asm/segment.h>
1035 diff -NurpP --minimal linux-2.6.32.56/arch/s390/kernel/syscalls.S linux-2.6.32.56-vs2.3.0.36.29.9/arch/s390/kernel/syscalls.S
1036 --- linux-2.6.32.56/arch/s390/kernel/syscalls.S 2009-12-03 20:02:03.000000000 +0100
1037 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/s390/kernel/syscalls.S 2011-06-10 13:03:02.000000000 +0200
1038 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
1039  SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper)       /* 260 */
1040  SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
1041  SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
1042 -NI_SYSCALL                                                     /* reserved for vserver */
1043 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
1044  SYSCALL(sys_s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
1045  SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
1046  SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
1047 diff -NurpP --minimal linux-2.6.32.56/arch/s390/lib/uaccess_pt.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/s390/lib/uaccess_pt.c
1048 --- linux-2.6.32.56/arch/s390/lib/uaccess_pt.c  2009-09-10 15:25:43.000000000 +0200
1049 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/s390/lib/uaccess_pt.c  2011-06-10 13:03:02.000000000 +0200
1050 @@ -90,7 +90,8 @@ out_of_memory:
1051                 down_read(&mm->mmap_sem);
1052                 goto survive;
1053         }
1054 -       printk("VM: killing process %s\n", current->comm);
1055 +       printk("VM: killing process %s(%d:#%u)\n",
1056 +               current->comm, task_pid_nr(current), current->xid);
1057         return ret;
1058  
1059  out_sigbus:
1060 diff -NurpP --minimal linux-2.6.32.56/arch/sh/Kconfig linux-2.6.32.56-vs2.3.0.36.29.9/arch/sh/Kconfig
1061 --- linux-2.6.32.56/arch/sh/Kconfig     2009-12-03 20:02:03.000000000 +0100
1062 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/sh/Kconfig     2011-06-10 13:03:02.000000000 +0200
1063 @@ -853,6 +853,8 @@ source "fs/Kconfig"
1064  
1065  source "arch/sh/Kconfig.debug"
1066  
1067 +source "kernel/vserver/Kconfig"
1068 +
1069  source "security/Kconfig"
1070  
1071  source "crypto/Kconfig"
1072 diff -NurpP --minimal linux-2.6.32.56/arch/sh/kernel/irq.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/sh/kernel/irq.c
1073 --- linux-2.6.32.56/arch/sh/kernel/irq.c        2009-12-03 20:02:10.000000000 +0100
1074 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/sh/kernel/irq.c        2011-06-10 13:03:02.000000000 +0200
1075 @@ -12,6 +12,7 @@
1076  #include <linux/kernel_stat.h>
1077  #include <linux/seq_file.h>
1078  #include <linux/ftrace.h>
1079 +// #include <linux/vs_context.h>
1080  #include <asm/processor.h>
1081  #include <asm/machvec.h>
1082  #include <asm/uaccess.h>
1083 diff -NurpP --minimal linux-2.6.32.56/arch/sh/kernel/vsyscall/vsyscall.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/sh/kernel/vsyscall/vsyscall.c
1084 --- linux-2.6.32.56/arch/sh/kernel/vsyscall/vsyscall.c  2009-03-24 14:18:42.000000000 +0100
1085 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/sh/kernel/vsyscall/vsyscall.c  2011-06-10 13:03:02.000000000 +0200
1086 @@ -19,6 +19,7 @@
1087  #include <linux/elf.h>
1088  #include <linux/sched.h>
1089  #include <linux/err.h>
1090 +#include <linux/vs_memory.h>
1091  
1092  /*
1093   * Should the kernel map a VDSO page into processes and pass its
1094 diff -NurpP --minimal linux-2.6.32.56/arch/sh/mm/fault_32.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/sh/mm/fault_32.c
1095 --- linux-2.6.32.56/arch/sh/mm/fault_32.c       2009-12-03 20:02:14.000000000 +0100
1096 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/sh/mm/fault_32.c       2011-06-10 13:03:02.000000000 +0200
1097 @@ -292,7 +292,8 @@ out_of_memory:
1098                 down_read(&mm->mmap_sem);
1099                 goto survive;
1100         }
1101 -       printk("VM: killing process %s\n", tsk->comm);
1102 +       printk("VM: killing process %s(%d:#%u)\n",
1103 +               tsk->comm, task_pid_nr(tsk), tsk->xid);
1104         if (user_mode(regs))
1105                 do_group_exit(SIGKILL);
1106         goto no_context;
1107 diff -NurpP --minimal linux-2.6.32.56/arch/sh/mm/tlbflush_64.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/sh/mm/tlbflush_64.c
1108 --- linux-2.6.32.56/arch/sh/mm/tlbflush_64.c    2009-12-03 20:02:14.000000000 +0100
1109 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/sh/mm/tlbflush_64.c    2011-06-10 13:03:02.000000000 +0200
1110 @@ -306,7 +306,8 @@ out_of_memory:
1111                 down_read(&mm->mmap_sem);
1112                 goto survive;
1113         }
1114 -       printk("VM: killing process %s\n", tsk->comm);
1115 +       printk("VM: killing process %s(%d:#%u)\n",
1116 +               tsk->comm, task_pid_nr(tsk), tsk->xid);
1117         if (user_mode(regs))
1118                 do_group_exit(SIGKILL);
1119         goto no_context;
1120 diff -NurpP --minimal linux-2.6.32.56/arch/sparc/Kconfig linux-2.6.32.56-vs2.3.0.36.29.9/arch/sparc/Kconfig
1121 --- linux-2.6.32.56/arch/sparc/Kconfig  2009-12-03 20:02:14.000000000 +0100
1122 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/sparc/Kconfig  2011-06-10 13:03:02.000000000 +0200
1123 @@ -550,6 +550,8 @@ source "fs/Kconfig"
1124  
1125  source "arch/sparc/Kconfig.debug"
1126  
1127 +source "kernel/vserver/Kconfig"
1128 +
1129  source "security/Kconfig"
1130  
1131  source "crypto/Kconfig"
1132 diff -NurpP --minimal linux-2.6.32.56/arch/sparc/include/asm/tlb_64.h linux-2.6.32.56-vs2.3.0.36.29.9/arch/sparc/include/asm/tlb_64.h
1133 --- linux-2.6.32.56/arch/sparc/include/asm/tlb_64.h     2009-09-10 15:25:45.000000000 +0200
1134 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/sparc/include/asm/tlb_64.h     2011-06-10 13:03:02.000000000 +0200
1135 @@ -3,6 +3,7 @@
1136  
1137  #include <linux/swap.h>
1138  #include <linux/pagemap.h>
1139 +#include <linux/vs_memory.h>
1140  #include <asm/pgalloc.h>
1141  #include <asm/tlbflush.h>
1142  #include <asm/mmu_context.h>
1143 diff -NurpP --minimal linux-2.6.32.56/arch/sparc/include/asm/unistd.h linux-2.6.32.56-vs2.3.0.36.29.9/arch/sparc/include/asm/unistd.h
1144 --- linux-2.6.32.56/arch/sparc/include/asm/unistd.h     2009-12-03 20:02:15.000000000 +0100
1145 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/sparc/include/asm/unistd.h     2011-06-10 13:03:02.000000000 +0200
1146 @@ -335,7 +335,7 @@
1147  #define __NR_timer_getoverrun  264
1148  #define __NR_timer_delete      265
1149  #define __NR_timer_create      266
1150 -/* #define __NR_vserver                267 Reserved for VSERVER */
1151 +#define __NR_vserver           267
1152  #define __NR_io_setup          268
1153  #define __NR_io_destroy                269
1154  #define __NR_io_submit         270
1155 diff -NurpP --minimal linux-2.6.32.56/arch/sparc/kernel/systbls_32.S linux-2.6.32.56-vs2.3.0.36.29.9/arch/sparc/kernel/systbls_32.S
1156 --- linux-2.6.32.56/arch/sparc/kernel/systbls_32.S      2012-02-09 10:22:16.000000000 +0100
1157 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/sparc/kernel/systbls_32.S      2011-06-10 13:03:02.000000000 +0200
1158 @@ -70,7 +70,7 @@ sys_call_table:
1159  /*250*/        .long sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
1160  /*255*/        .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
1161  /*260*/        .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
1162 -/*265*/        .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
1163 +/*265*/        .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
1164  /*270*/        .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
1165  /*275*/        .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
1166  /*280*/        .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
1167 diff -NurpP --minimal linux-2.6.32.56/arch/sparc/kernel/systbls_64.S linux-2.6.32.56-vs2.3.0.36.29.9/arch/sparc/kernel/systbls_64.S
1168 --- linux-2.6.32.56/arch/sparc/kernel/systbls_64.S      2012-02-09 10:22:16.000000000 +0100
1169 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/sparc/kernel/systbls_64.S      2011-06-10 13:03:02.000000000 +0200
1170 @@ -71,7 +71,7 @@ sys_call_table32:
1171  /*250*/        .word sys32_mremap, sys32_sysctl, sys32_getsid, sys_fdatasync, sys32_nfsservctl
1172         .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
1173  /*260*/        .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
1174 -       .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
1175 +       .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
1176  /*270*/        .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
1177         .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
1178  /*280*/        .word sys32_tee, sys_add_key, sys_request_key, sys_keyctl, compat_sys_openat
1179 @@ -146,7 +146,7 @@ sys_call_table:
1180  /*250*/        .word sys_64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
1181         .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
1182  /*260*/        .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
1183 -       .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
1184 +       .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
1185  /*270*/        .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
1186         .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
1187  /*280*/        .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
1188 diff -NurpP --minimal linux-2.6.32.56/arch/um/Kconfig.rest linux-2.6.32.56-vs2.3.0.36.29.9/arch/um/Kconfig.rest
1189 --- linux-2.6.32.56/arch/um/Kconfig.rest        2009-06-11 17:12:19.000000000 +0200
1190 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/um/Kconfig.rest        2011-06-10 13:03:02.000000000 +0200
1191 @@ -18,6 +18,8 @@ source "drivers/connector/Kconfig"
1192  
1193  source "fs/Kconfig"
1194  
1195 +source "kernel/vserver/Kconfig"
1196 +
1197  source "security/Kconfig"
1198  
1199  source "crypto/Kconfig"
1200 diff -NurpP --minimal linux-2.6.32.56/arch/um/include/asm/tlb.h linux-2.6.32.56-vs2.3.0.36.29.9/arch/um/include/asm/tlb.h
1201 --- linux-2.6.32.56/arch/um/include/asm/tlb.h   2009-09-10 15:25:46.000000000 +0200
1202 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/um/include/asm/tlb.h   2011-06-10 13:03:02.000000000 +0200
1203 @@ -3,6 +3,7 @@
1204  
1205  #include <linux/pagemap.h>
1206  #include <linux/swap.h>
1207 +#include <linux/vs_memory.h>
1208  #include <asm/percpu.h>
1209  #include <asm/pgalloc.h>
1210  #include <asm/tlbflush.h>
1211 diff -NurpP --minimal linux-2.6.32.56/arch/x86/Kconfig linux-2.6.32.56-vs2.3.0.36.29.9/arch/x86/Kconfig
1212 --- linux-2.6.32.56/arch/x86/Kconfig    2012-02-09 10:22:16.000000000 +0100
1213 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/x86/Kconfig    2011-06-10 13:03:02.000000000 +0200
1214 @@ -2100,6 +2100,8 @@ source "fs/Kconfig"
1215  
1216  source "arch/x86/Kconfig.debug"
1217  
1218 +source "kernel/vserver/Kconfig"
1219 +
1220  source "security/Kconfig"
1221  
1222  source "crypto/Kconfig"
1223 diff -NurpP --minimal linux-2.6.32.56/arch/x86/ia32/ia32entry.S linux-2.6.32.56-vs2.3.0.36.29.9/arch/x86/ia32/ia32entry.S
1224 --- linux-2.6.32.56/arch/x86/ia32/ia32entry.S   2012-02-09 10:22:16.000000000 +0100
1225 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/x86/ia32/ia32entry.S   2011-06-10 13:03:02.000000000 +0200
1226 @@ -783,7 +783,7 @@ ia32_sys_call_table:
1227         .quad sys_tgkill                /* 270 */
1228         .quad compat_sys_utimes
1229         .quad sys32_fadvise64_64
1230 -       .quad quiet_ni_syscall  /* sys_vserver */
1231 +       .quad sys32_vserver
1232         .quad sys_mbind
1233         .quad compat_sys_get_mempolicy  /* 275 */
1234         .quad sys_set_mempolicy
1235 diff -NurpP --minimal linux-2.6.32.56/arch/x86/include/asm/unistd_64.h linux-2.6.32.56-vs2.3.0.36.29.9/arch/x86/include/asm/unistd_64.h
1236 --- linux-2.6.32.56/arch/x86/include/asm/unistd_64.h    2009-12-03 20:02:16.000000000 +0100
1237 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/x86/include/asm/unistd_64.h    2011-06-10 13:03:02.000000000 +0200
1238 @@ -535,7 +535,7 @@ __SYSCALL(__NR_tgkill, sys_tgkill)
1239  #define __NR_utimes                            235
1240  __SYSCALL(__NR_utimes, sys_utimes)
1241  #define __NR_vserver                           236
1242 -__SYSCALL(__NR_vserver, sys_ni_syscall)
1243 +__SYSCALL(__NR_vserver, sys_vserver)
1244  #define __NR_mbind                             237
1245  __SYSCALL(__NR_mbind, sys_mbind)
1246  #define __NR_set_mempolicy                     238
1247 diff -NurpP --minimal linux-2.6.32.56/arch/x86/kernel/syscall_table_32.S linux-2.6.32.56-vs2.3.0.36.29.9/arch/x86/kernel/syscall_table_32.S
1248 --- linux-2.6.32.56/arch/x86/kernel/syscall_table_32.S  2012-02-09 10:22:18.000000000 +0100
1249 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/x86/kernel/syscall_table_32.S  2011-06-10 13:03:02.000000000 +0200
1250 @@ -272,7 +272,7 @@ ENTRY(sys_call_table)
1251         .long sys_tgkill        /* 270 */
1252         .long sys_utimes
1253         .long sys_fadvise64_64
1254 -       .long sys_ni_syscall    /* sys_vserver */
1255 +       .long sys_vserver
1256         .long sys_mbind
1257         .long sys_get_mempolicy
1258         .long sys_set_mempolicy
1259 diff -NurpP --minimal linux-2.6.32.56/arch/xtensa/mm/fault.c linux-2.6.32.56-vs2.3.0.36.29.9/arch/xtensa/mm/fault.c
1260 --- linux-2.6.32.56/arch/xtensa/mm/fault.c      2009-09-10 15:25:48.000000000 +0200
1261 +++ linux-2.6.32.56-vs2.3.0.36.29.9/arch/xtensa/mm/fault.c      2011-06-10 13:03:02.000000000 +0200
1262 @@ -151,7 +151,8 @@ out_of_memory:
1263                 down_read(&mm->mmap_sem);
1264                 goto survive;
1265         }
1266 -       printk("VM: killing process %s\n", current->comm);
1267 +       printk("VM: killing process %s(%d:#%u)\n",
1268 +               current->comm, task_pid_nr(current), current->xid);
1269         if (user_mode(regs))
1270                 do_group_exit(SIGKILL);
1271         bad_page_fault(regs, address, SIGKILL);
1272 diff -NurpP --minimal linux-2.6.32.56/drivers/block/Kconfig linux-2.6.32.56-vs2.3.0.36.29.9/drivers/block/Kconfig
1273 --- linux-2.6.32.56/drivers/block/Kconfig       2009-09-10 15:25:49.000000000 +0200
1274 +++ linux-2.6.32.56-vs2.3.0.36.29.9/drivers/block/Kconfig       2011-06-10 13:03:02.000000000 +0200
1275 @@ -271,6 +271,13 @@ config BLK_DEV_CRYPTOLOOP
1276           instead, which can be configured to be on-disk compatible with the
1277           cryptoloop device.
1278  
1279 +config BLK_DEV_VROOT
1280 +       tristate "Virtual Root device support"
1281 +       depends on QUOTACTL
1282 +       ---help---
1283 +         Saying Y here will allow you to use quota/fs ioctls on a shared
1284 +         partition within a virtual server without compromising security.
1285 +
1286  config BLK_DEV_NBD
1287         tristate "Network block device support"
1288         depends on NET
1289 diff -NurpP --minimal linux-2.6.32.56/drivers/block/Makefile linux-2.6.32.56-vs2.3.0.36.29.9/drivers/block/Makefile
1290 --- linux-2.6.32.56/drivers/block/Makefile      2009-09-10 15:25:49.000000000 +0200
1291 +++ linux-2.6.32.56-vs2.3.0.36.29.9/drivers/block/Makefile      2011-06-10 13:03:02.000000000 +0200
1292 @@ -34,6 +34,7 @@ obj-$(CONFIG_VIODASD)         += viodasd.o
1293  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
1294  obj-$(CONFIG_BLK_DEV_UB)       += ub.o
1295  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
1296 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
1297  
1298  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
1299  
1300 diff -NurpP --minimal linux-2.6.32.56/drivers/block/loop.c linux-2.6.32.56-vs2.3.0.36.29.9/drivers/block/loop.c
1301 --- linux-2.6.32.56/drivers/block/loop.c        2012-02-09 10:22:19.000000000 +0100
1302 +++ linux-2.6.32.56-vs2.3.0.36.29.9/drivers/block/loop.c        2011-08-08 22:40:36.000000000 +0200
1303 @@ -74,6 +74,7 @@
1304  #include <linux/gfp.h>
1305  #include <linux/kthread.h>
1306  #include <linux/splice.h>
1307 +#include <linux/vs_context.h>
1308  
1309  #include <asm/uaccess.h>
1310  
1311 @@ -814,6 +815,7 @@ static int loop_set_fd(struct loop_devic
1312         lo->lo_blocksize = lo_blocksize;
1313         lo->lo_device = bdev;
1314         lo->lo_flags = lo_flags;
1315 +       lo->lo_xid = vx_current_xid();
1316         lo->lo_backing_file = file;
1317         lo->transfer = transfer_none;
1318         lo->ioctl = NULL;
1319 @@ -939,6 +941,7 @@ static int loop_clr_fd(struct loop_devic
1320         lo->lo_encrypt_key_size = 0;
1321         lo->lo_flags = 0;
1322         lo->lo_thread = NULL;
1323 +       lo->lo_xid = 0;
1324         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
1325         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
1326         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
1327 @@ -973,7 +976,7 @@ loop_set_status(struct loop_device *lo, 
1328  
1329         if (lo->lo_encrypt_key_size &&
1330             lo->lo_key_owner != uid &&
1331 -           !capable(CAP_SYS_ADMIN))
1332 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
1333                 return -EPERM;
1334         if (lo->lo_state != Lo_bound)
1335                 return -ENXIO;
1336 @@ -1057,7 +1060,8 @@ loop_get_status(struct loop_device *lo, 
1337         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
1338         info->lo_encrypt_type =
1339                 lo->lo_encryption ? lo->lo_encryption->number : 0;
1340 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
1341 +       if (lo->lo_encrypt_key_size &&
1342 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
1343                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
1344                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
1345                        lo->lo_encrypt_key_size);
1346 @@ -1401,6 +1405,9 @@ static int lo_open(struct block_device *
1347  {
1348         struct loop_device *lo = bdev->bd_disk->private_data;
1349  
1350 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P))
1351 +               return -EACCES;
1352 +
1353         mutex_lock(&lo->lo_ctl_mutex);
1354         lo->lo_refcnt++;
1355         mutex_unlock(&lo->lo_ctl_mutex);
1356 diff -NurpP --minimal linux-2.6.32.56/drivers/block/vroot.c linux-2.6.32.56-vs2.3.0.36.29.9/drivers/block/vroot.c
1357 --- linux-2.6.32.56/drivers/block/vroot.c       1970-01-01 01:00:00.000000000 +0100
1358 +++ linux-2.6.32.56-vs2.3.0.36.29.9/drivers/block/vroot.c       2011-06-10 13:03:02.000000000 +0200
1359 @@ -0,0 +1,281 @@
1360 +/*
1361 + *  linux/drivers/block/vroot.c
1362 + *
1363 + *  written by Herbert Pötzl, 9/11/2002
1364 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
1365 + *
1366 + *  based on the loop.c code by Theodore Ts'o.
1367 + *
1368 + * Copyright (C) 2002-2007 by Herbert Pötzl.
1369 + * Redistribution of this file is permitted under the
1370 + * GNU General Public License.
1371 + *
1372 + */
1373 +
1374 +#include <linux/module.h>
1375 +#include <linux/moduleparam.h>
1376 +#include <linux/file.h>
1377 +#include <linux/major.h>
1378 +#include <linux/blkdev.h>
1379 +
1380 +#include <linux/vroot.h>
1381 +#include <linux/vs_context.h>
1382 +
1383 +
1384 +static int max_vroot = 8;
1385 +
1386 +static struct vroot_device *vroot_dev;
1387 +static struct gendisk **disks;
1388 +
1389 +
1390 +static int vroot_set_dev(
1391 +       struct vroot_device *vr,
1392 +       struct block_device *bdev,
1393 +       unsigned int arg)
1394 +{
1395 +       struct block_device *real_bdev;
1396 +       struct file *file;
1397 +       struct inode *inode;
1398 +       int error;
1399 +
1400 +       error = -EBUSY;
1401 +       if (vr->vr_state != Vr_unbound)
1402 +               goto out;
1403 +
1404 +       error = -EBADF;
1405 +       file = fget(arg);
1406 +       if (!file)
1407 +               goto out;
1408 +
1409 +       error = -EINVAL;
1410 +       inode = file->f_dentry->d_inode;
1411 +
1412 +
1413 +       if (S_ISBLK(inode->i_mode)) {
1414 +               real_bdev = inode->i_bdev;
1415 +               vr->vr_device = real_bdev;
1416 +               __iget(real_bdev->bd_inode);
1417 +       } else
1418 +               goto out_fput;
1419 +
1420 +       vxdprintk(VXD_CBIT(misc, 0),
1421 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
1422 +               vr->vr_number, VXD_DEV(real_bdev));
1423 +
1424 +       vr->vr_state = Vr_bound;
1425 +       error = 0;
1426 +
1427 + out_fput:
1428 +       fput(file);
1429 + out:
1430 +       return error;
1431 +}
1432 +
1433 +static int vroot_clr_dev(
1434 +       struct vroot_device *vr,
1435 +       struct block_device *bdev)
1436 +{
1437 +       struct block_device *real_bdev;
1438 +
1439 +       if (vr->vr_state != Vr_bound)
1440 +               return -ENXIO;
1441 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
1442 +               return -EBUSY;
1443 +
1444 +       real_bdev = vr->vr_device;
1445 +
1446 +       vxdprintk(VXD_CBIT(misc, 0),
1447 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
1448 +               vr->vr_number, VXD_DEV(real_bdev));
1449 +
1450 +       bdput(real_bdev);
1451 +       vr->vr_state = Vr_unbound;
1452 +       vr->vr_device = NULL;
1453 +       return 0;
1454 +}
1455 +
1456 +
1457 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
1458 +       unsigned int cmd, unsigned long arg)
1459 +{
1460 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1461 +       int err;
1462 +
1463 +       down(&vr->vr_ctl_mutex);
1464 +       switch (cmd) {
1465 +       case VROOT_SET_DEV:
1466 +               err = vroot_set_dev(vr, bdev, arg);
1467 +               break;
1468 +       case VROOT_CLR_DEV:
1469 +               err = vroot_clr_dev(vr, bdev);
1470 +               break;
1471 +       default:
1472 +               err = -EINVAL;
1473 +               break;
1474 +       }
1475 +       up(&vr->vr_ctl_mutex);
1476 +       return err;
1477 +}
1478 +
1479 +static int vr_open(struct block_device *bdev, fmode_t mode)
1480 +{
1481 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1482 +
1483 +       down(&vr->vr_ctl_mutex);
1484 +       vr->vr_refcnt++;
1485 +       up(&vr->vr_ctl_mutex);
1486 +       return 0;
1487 +}
1488 +
1489 +static int vr_release(struct gendisk *disk, fmode_t mode)
1490 +{
1491 +       struct vroot_device *vr = disk->private_data;
1492 +
1493 +       down(&vr->vr_ctl_mutex);
1494 +       --vr->vr_refcnt;
1495 +       up(&vr->vr_ctl_mutex);
1496 +       return 0;
1497 +}
1498 +
1499 +static struct block_device_operations vr_fops = {
1500 +       .owner =        THIS_MODULE,
1501 +       .open =         vr_open,
1502 +       .release =      vr_release,
1503 +       .ioctl =        vr_ioctl,
1504 +};
1505 +
1506 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
1507 +{
1508 +       struct inode *inode = bdev->bd_inode;
1509 +       struct vroot_device *vr;
1510 +       struct block_device *real_bdev;
1511 +       int minor = iminor(inode);
1512 +
1513 +       vr = &vroot_dev[minor];
1514 +       real_bdev = vr->vr_device;
1515 +
1516 +       vxdprintk(VXD_CBIT(misc, 0),
1517 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1518 +               vr->vr_number, VXD_DEV(real_bdev));
1519 +
1520 +       if (vr->vr_state != Vr_bound)
1521 +               return ERR_PTR(-ENXIO);
1522 +
1523 +       __iget(real_bdev->bd_inode);
1524 +       return real_bdev;
1525 +}
1526 +
1527 +/*
1528 + * And now the modules code and kernel interface.
1529 + */
1530 +
1531 +module_param(max_vroot, int, 0);
1532 +
1533 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1534 +MODULE_LICENSE("GPL");
1535 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1536 +
1537 +MODULE_AUTHOR ("Herbert Pötzl");
1538 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1539 +
1540 +
1541 +int __init vroot_init(void)
1542 +{
1543 +       int err, i;
1544 +
1545 +       if (max_vroot < 1 || max_vroot > 256) {
1546 +               max_vroot = MAX_VROOT_DEFAULT;
1547 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1548 +                       "(must be between 1 and 256), "
1549 +                       "using default (%d)\n", max_vroot);
1550 +       }
1551 +
1552 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1553 +               return -EIO;
1554 +
1555 +       err = -ENOMEM;
1556 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1557 +       if (!vroot_dev)
1558 +               goto out_mem1;
1559 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1560 +
1561 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1562 +       if (!disks)
1563 +               goto out_mem2;
1564 +
1565 +       for (i = 0; i < max_vroot; i++) {
1566 +               disks[i] = alloc_disk(1);
1567 +               if (!disks[i])
1568 +                       goto out_mem3;
1569 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1570 +               if (!disks[i]->queue)
1571 +                       goto out_mem3;
1572 +       }
1573 +
1574 +       for (i = 0; i < max_vroot; i++) {
1575 +               struct vroot_device *vr = &vroot_dev[i];
1576 +               struct gendisk *disk = disks[i];
1577 +
1578 +               memset(vr, 0, sizeof(*vr));
1579 +               init_MUTEX(&vr->vr_ctl_mutex);
1580 +               vr->vr_number = i;
1581 +               disk->major = VROOT_MAJOR;
1582 +               disk->first_minor = i;
1583 +               disk->fops = &vr_fops;
1584 +               sprintf(disk->disk_name, "vroot%d", i);
1585 +               disk->private_data = vr;
1586 +       }
1587 +
1588 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1589 +       if (err)
1590 +               goto out_mem3;
1591 +
1592 +       for (i = 0; i < max_vroot; i++)
1593 +               add_disk(disks[i]);
1594 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1595 +       return 0;
1596 +
1597 +out_mem3:
1598 +       while (i--)
1599 +               put_disk(disks[i]);
1600 +       kfree(disks);
1601 +out_mem2:
1602 +       kfree(vroot_dev);
1603 +out_mem1:
1604 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1605 +       printk(KERN_ERR "vroot: ran out of memory\n");
1606 +       return err;
1607 +}
1608 +
1609 +void vroot_exit(void)
1610 +{
1611 +       int i;
1612 +
1613 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1614 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1615 +
1616 +       for (i = 0; i < max_vroot; i++) {
1617 +               del_gendisk(disks[i]);
1618 +               put_disk(disks[i]);
1619 +       }
1620 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1621 +
1622 +       kfree(disks);
1623 +       kfree(vroot_dev);
1624 +}
1625 +
1626 +module_init(vroot_init);
1627 +module_exit(vroot_exit);
1628 +
1629 +#ifndef MODULE
1630 +
1631 +static int __init max_vroot_setup(char *str)
1632 +{
1633 +       max_vroot = simple_strtol(str, NULL, 0);
1634 +       return 1;
1635 +}
1636 +
1637 +__setup("max_vroot=", max_vroot_setup);
1638 +
1639 +#endif
1640 +
1641 diff -NurpP --minimal linux-2.6.32.56/drivers/char/sysrq.c linux-2.6.32.56-vs2.3.0.36.29.9/drivers/char/sysrq.c
1642 --- linux-2.6.32.56/drivers/char/sysrq.c        2009-12-03 20:02:20.000000000 +0100
1643 +++ linux-2.6.32.56-vs2.3.0.36.29.9/drivers/char/sysrq.c        2011-06-10 13:03:02.000000000 +0200
1644 @@ -38,6 +38,7 @@
1645  #include <linux/workqueue.h>
1646  #include <linux/hrtimer.h>
1647  #include <linux/oom.h>
1648 +#include <linux/vserver/debug.h>
1649  
1650  #include <asm/ptrace.h>
1651  #include <asm/irq_regs.h>
1652 @@ -391,6 +392,21 @@ static struct sysrq_key_op sysrq_unrt_op
1653         .enable_mask    = SYSRQ_ENABLE_RTNICE,
1654  };
1655  
1656 +
1657 +#ifdef CONFIG_VSERVER_DEBUG
1658 +static void sysrq_handle_vxinfo(int key, struct tty_struct *tty)
1659 +{
1660 +       dump_vx_info_inactive((key == 'x')?0:1);
1661 +}
1662 +
1663 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1664 +       .handler        = sysrq_handle_vxinfo,
1665 +       .help_msg       = "conteXt",
1666 +       .action_msg     = "Show Context Info",
1667 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
1668 +};
1669 +#endif
1670 +
1671  /* Key Operations table and lock */
1672  static DEFINE_SPINLOCK(sysrq_key_table_lock);
1673  
1674 @@ -445,7 +461,11 @@ static struct sysrq_key_op *sysrq_key_ta
1675         NULL,                           /* v */
1676         &sysrq_showstate_blocked_op,    /* w */
1677         /* x: May be registered on ppc/powerpc for xmon */
1678 +#ifdef CONFIG_VSERVER_DEBUG
1679 +       &sysrq_showvxinfo_op,           /* x */
1680 +#else
1681         NULL,                           /* x */
1682 +#endif
1683         /* y: May be registered on sparc64 for global register dump */
1684         NULL,                           /* y */
1685         &sysrq_ftrace_dump_op,          /* z */
1686 @@ -460,6 +480,8 @@ static int sysrq_key_table_key2index(int
1687                 retval = key - '0';
1688         else if ((key >= 'a') && (key <= 'z'))
1689                 retval = key + 10 - 'a';
1690 +       else if ((key >= 'A') && (key <= 'Z'))
1691 +               retval = key + 10 - 'A';
1692         else
1693                 retval = -1;
1694         return retval;
1695 diff -NurpP --minimal linux-2.6.32.56/drivers/char/tty_io.c linux-2.6.32.56-vs2.3.0.36.29.9/drivers/char/tty_io.c
1696 --- linux-2.6.32.56/drivers/char/tty_io.c       2012-02-09 10:22:19.000000000 +0100
1697 +++ linux-2.6.32.56-vs2.3.0.36.29.9/drivers/char/tty_io.c       2012-01-10 09:18:12.000000000 +0100
1698 @@ -107,6 +107,7 @@
1699  
1700  #include <linux/kmod.h>
1701  #include <linux/nsproxy.h>
1702 +#include <linux/vs_pid.h>
1703  
1704  #undef TTY_DEBUG_HANGUP
1705  
1706 @@ -1971,7 +1972,8 @@ static int tiocsti(struct tty_struct *tt
1707         char ch, mbz = 0;
1708         struct tty_ldisc *ld;
1709  
1710 -       if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
1711 +       if (((current->signal->tty != tty) &&
1712 +               !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
1713                 return -EPERM;
1714         if (get_user(ch, p))
1715                 return -EFAULT;
1716 @@ -2259,6 +2261,7 @@ static int tiocspgrp(struct tty_struct *
1717                 return -ENOTTY;
1718         if (get_user(pgrp_nr, p))
1719                 return -EFAULT;
1720 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
1721         if (pgrp_nr < 0)
1722                 return -EINVAL;
1723         rcu_read_lock();
1724 diff -NurpP --minimal linux-2.6.32.56/drivers/infiniband/hw/ipath/ipath_user_pages.c linux-2.6.32.56-vs2.3.0.36.29.9/drivers/infiniband/hw/ipath/ipath_user_pages.c
1725 --- linux-2.6.32.56/drivers/infiniband/hw/ipath/ipath_user_pages.c      2009-12-03 20:02:23.000000000 +0100
1726 +++ linux-2.6.32.56-vs2.3.0.36.29.9/drivers/infiniband/hw/ipath/ipath_user_pages.c      2011-06-10 13:03:02.000000000 +0200
1727 @@ -34,6 +34,7 @@
1728  #include <linux/mm.h>
1729  #include <linux/device.h>
1730  #include <linux/sched.h>
1731 +#include <linux/vs_memory.h>
1732  
1733  #include "ipath_kernel.h"
1734  
1735 @@ -62,7 +63,8 @@ static int __get_user_pages(unsigned lon
1736         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur >>
1737                 PAGE_SHIFT;
1738  
1739 -       if (num_pages > lock_limit) {
1740 +       if (num_pages > lock_limit ||
1741 +               !vx_vmlocked_avail(current->mm, num_pages)) {
1742                 ret = -ENOMEM;
1743                 goto bail;
1744         }
1745 @@ -79,7 +81,7 @@ static int __get_user_pages(unsigned lon
1746                         goto bail_release;
1747         }
1748  
1749 -       current->mm->locked_vm += num_pages;
1750 +       vx_vmlocked_add(current->mm, num_pages);
1751  
1752         ret = 0;
1753         goto bail;
1754 @@ -178,7 +180,7 @@ void ipath_release_user_pages(struct pag
1755  
1756         __ipath_release_user_pages(p, num_pages, 1);
1757  
1758 -       current->mm->locked_vm -= num_pages;
1759 +       vx_vmlocked_sub(current->mm, num_pages);
1760  
1761         up_write(&current->mm->mmap_sem);
1762  }
1763 @@ -195,7 +197,7 @@ static void user_pages_account(struct wo
1764                 container_of(_work, struct ipath_user_pages_work, work);
1765  
1766         down_write(&work->mm->mmap_sem);
1767 -       work->mm->locked_vm -= work->num_pages;
1768 +       vx_vmlocked_sub(work->mm, work->num_pages);
1769         up_write(&work->mm->mmap_sem);
1770         mmput(work->mm);
1771         kfree(work);
1772 diff -NurpP --minimal linux-2.6.32.56/drivers/md/dm-ioctl.c linux-2.6.32.56-vs2.3.0.36.29.9/drivers/md/dm-ioctl.c
1773 --- linux-2.6.32.56/drivers/md/dm-ioctl.c       2012-02-09 10:22:20.000000000 +0100
1774 +++ linux-2.6.32.56-vs2.3.0.36.29.9/drivers/md/dm-ioctl.c       2011-06-10 13:03:02.000000000 +0200
1775 @@ -16,6 +16,7 @@
1776  #include <linux/dm-ioctl.h>
1777  #include <linux/hdreg.h>
1778  #include <linux/compat.h>
1779 +#include <linux/vs_context.h>
1780  
1781  #include <asm/uaccess.h>
1782  
1783 @@ -106,7 +107,8 @@ static struct hash_cell *__get_name_cell
1784         unsigned int h = hash_str(str);
1785  
1786         list_for_each_entry (hc, _name_buckets + h, name_list)
1787 -               if (!strcmp(hc->name, str)) {
1788 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1789 +                       !strcmp(hc->name, str)) {
1790                         dm_get(hc->md);
1791                         return hc;
1792                 }
1793 @@ -120,7 +122,8 @@ static struct hash_cell *__get_uuid_cell
1794         unsigned int h = hash_str(str);
1795  
1796         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1797 -               if (!strcmp(hc->uuid, str)) {
1798 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1799 +                       !strcmp(hc->uuid, str)) {
1800                         dm_get(hc->md);
1801                         return hc;
1802                 }
1803 @@ -369,6 +372,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl 
1804  
1805  static int remove_all(struct dm_ioctl *param, size_t param_size)
1806  {
1807 +       if (!vx_check(0, VS_ADMIN))
1808 +               return -EPERM;
1809 +
1810         dm_hash_remove_all(1);
1811         param->data_size = 0;
1812         return 0;
1813 @@ -416,6 +422,8 @@ static int list_devices(struct dm_ioctl 
1814          */
1815         for (i = 0; i < NUM_BUCKETS; i++) {
1816                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1817 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1818 +                               continue;
1819                         needed += sizeof(struct dm_name_list);
1820                         needed += strlen(hc->name) + 1;
1821                         needed += ALIGN_MASK;
1822 @@ -439,6 +447,8 @@ static int list_devices(struct dm_ioctl 
1823          */
1824         for (i = 0; i < NUM_BUCKETS; i++) {
1825                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1826 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1827 +                               continue;
1828                         if (old_nl)
1829                                 old_nl->next = (uint32_t) ((void *) nl -
1830                                                            (void *) old_nl);
1831 @@ -629,10 +639,11 @@ static struct hash_cell *__find_device_h
1832         if (!md)
1833                 goto out;
1834  
1835 -       mdptr = dm_get_mdptr(md);
1836 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1837 +               mdptr = dm_get_mdptr(md);
1838 +
1839         if (!mdptr)
1840                 dm_put(md);
1841 -
1842  out:
1843         return mdptr;
1844  }
1845 @@ -1462,8 +1473,8 @@ static int ctl_ioctl(uint command, struc
1846         ioctl_fn fn = NULL;
1847         size_t param_size;
1848  
1849 -       /* only root can play with this */
1850 -       if (!capable(CAP_SYS_ADMIN))
1851 +       /* only root and certain contexts can play with this */
1852 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1853                 return -EACCES;
1854  
1855         if (_IOC_TYPE(command) != DM_IOCTL)
1856 diff -NurpP --minimal linux-2.6.32.56/drivers/md/dm.c linux-2.6.32.56-vs2.3.0.36.29.9/drivers/md/dm.c
1857 --- linux-2.6.32.56/drivers/md/dm.c     2012-02-09 10:22:20.000000000 +0100
1858 +++ linux-2.6.32.56-vs2.3.0.36.29.9/drivers/md/dm.c     2011-11-17 12:18:26.000000000 +0100
1859 @@ -19,6 +19,7 @@
1860  #include <linux/slab.h>
1861  #include <linux/idr.h>
1862  #include <linux/hdreg.h>
1863 +#include <linux/vs_base.h>
1864  
1865  #include <trace/events/block.h>
1866  
1867 @@ -121,6 +122,7 @@ struct mapped_device {
1868         rwlock_t map_lock;
1869         atomic_t holders;
1870         atomic_t open_count;
1871 +       xid_t xid;
1872  
1873         unsigned long flags;
1874  
1875 @@ -331,6 +333,7 @@ static void __exit dm_exit(void)
1876  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1877  {
1878         struct mapped_device *md;
1879 +       int ret = -ENXIO;
1880  
1881         spin_lock(&_minor_lock);
1882  
1883 @@ -339,18 +342,19 @@ static int dm_blk_open(struct block_devi
1884                 goto out;
1885  
1886         if (test_bit(DMF_FREEING, &md->flags) ||
1887 -           test_bit(DMF_DELETING, &md->flags)) {
1888 -               md = NULL;
1889 +           test_bit(DMF_DELETING, &md->flags))
1890 +               goto out;
1891 +
1892 +       ret = -EACCES;
1893 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1894                 goto out;
1895 -       }
1896  
1897         dm_get(md);
1898         atomic_inc(&md->open_count);
1899 -
1900 +       ret = 0;
1901  out:
1902         spin_unlock(&_minor_lock);
1903 -
1904 -       return md ? 0 : -ENXIO;
1905 +       return ret;
1906  }
1907  
1908  static int dm_blk_close(struct gendisk *disk, fmode_t mode)
1909 @@ -561,6 +565,14 @@ int dm_set_geometry(struct mapped_device
1910         return 0;
1911  }
1912  
1913 +/*
1914 + * Get the xid associated with a dm device
1915 + */
1916 +xid_t dm_get_xid(struct mapped_device *md)
1917 +{
1918 +       return md->xid;
1919 +}
1920 +
1921  /*-----------------------------------------------------------------
1922   * CRUD START:
1923   *   A more elegant soln is in the works that uses the queue
1924 @@ -1781,6 +1793,7 @@ static struct mapped_device *alloc_dev(i
1925         INIT_LIST_HEAD(&md->uevent_list);
1926         spin_lock_init(&md->uevent_lock);
1927  
1928 +       md->xid = vx_current_xid();
1929         md->queue = blk_init_queue(dm_request_fn, NULL);
1930         if (!md->queue)
1931                 goto bad_queue;
1932 diff -NurpP --minimal linux-2.6.32.56/drivers/md/dm.h linux-2.6.32.56-vs2.3.0.36.29.9/drivers/md/dm.h
1933 --- linux-2.6.32.56/drivers/md/dm.h     2009-09-10 15:25:55.000000000 +0200
1934 +++ linux-2.6.32.56-vs2.3.0.36.29.9/drivers/md/dm.h     2011-06-10 13:03:02.000000000 +0200
1935 @@ -41,6 +41,8 @@ struct dm_dev_internal {
1936  struct dm_table;
1937  struct dm_md_mempools;
1938  
1939 +xid_t dm_get_xid(struct mapped_device *md);
1940 +
1941  /*-----------------------------------------------------------------
1942   * Internal table functions.
1943   *---------------------------------------------------------------*/
1944 diff -NurpP --minimal linux-2.6.32.56/drivers/net/tun.c linux-2.6.32.56-vs2.3.0.36.29.9/drivers/net/tun.c
1945 --- linux-2.6.32.56/drivers/net/tun.c   2012-02-09 10:22:25.000000000 +0100
1946 +++ linux-2.6.32.56-vs2.3.0.36.29.9/drivers/net/tun.c   2011-06-10 13:03:02.000000000 +0200
1947 @@ -61,6 +61,7 @@
1948  #include <linux/crc32.h>
1949  #include <linux/nsproxy.h>
1950  #include <linux/virtio_net.h>
1951 +#include <linux/vs_network.h>
1952  #include <net/net_namespace.h>
1953  #include <net/netns/generic.h>
1954  #include <net/rtnetlink.h>
1955 @@ -102,6 +103,7 @@ struct tun_struct {
1956         unsigned int            flags;
1957         uid_t                   owner;
1958         gid_t                   group;
1959 +       nid_t                   nid;
1960  
1961         struct net_device       *dev;
1962         struct fasync_struct    *fasync;
1963 @@ -816,6 +818,7 @@ static void tun_setup(struct net_device 
1964  
1965         tun->owner = -1;
1966         tun->group = -1;
1967 +       tun->nid = current->nid;
1968  
1969         dev->ethtool_ops = &tun_ethtool_ops;
1970         dev->destructor = tun_free_netdev;
1971 @@ -932,7 +935,7 @@ static int tun_set_iff(struct net *net, 
1972  
1973                 if (((tun->owner != -1 && cred->euid != tun->owner) ||
1974                      (tun->group != -1 && !in_egroup_p(tun->group))) &&
1975 -                   !capable(CAP_NET_ADMIN))
1976 +               !cap_raised(current_cap(), CAP_NET_ADMIN))
1977                         return -EPERM;
1978                 err = security_tun_dev_attach(tun->socket.sk);
1979                 if (err < 0)
1980 @@ -946,7 +949,7 @@ static int tun_set_iff(struct net *net, 
1981                 char *name;
1982                 unsigned long flags = 0;
1983  
1984 -               if (!capable(CAP_NET_ADMIN))
1985 +               if (!nx_capable(CAP_NET_ADMIN, NXC_TUN_CREATE))
1986                         return -EPERM;
1987                 err = security_tun_dev_create();
1988                 if (err < 0)
1989 @@ -1014,6 +1017,9 @@ static int tun_set_iff(struct net *net, 
1990  
1991                 sk->sk_destruct = tun_sock_destruct;
1992  
1993 +               if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
1994 +                       return -EPERM;
1995 +
1996                 err = tun_attach(tun, file);
1997                 if (err < 0)
1998                         goto failed;
1999 @@ -1203,6 +1209,16 @@ static long tun_chr_ioctl(struct file *f
2000                 DBG(KERN_INFO "%s: group set to %d\n", tun->dev->name, tun->group);
2001                 break;
2002  
2003 +       case TUNSETNID:
2004 +               if (!capable(CAP_CONTEXT))
2005 +                       return -EPERM;
2006 +
2007 +               /* Set nid owner of the device */
2008 +               tun->nid = (nid_t) arg;
2009 +
2010 +               DBG(KERN_INFO "%s: nid owner set to %u\n", tun->dev->name, tun->nid);
2011 +               break;
2012 +
2013         case TUNSETLINK:
2014                 /* Only allow setting the type when the interface is down */
2015                 if (tun->dev->flags & IFF_UP) {
2016 diff -NurpP --minimal linux-2.6.32.56/fs/attr.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/attr.c
2017 --- linux-2.6.32.56/fs/attr.c   2009-12-03 20:02:51.000000000 +0100
2018 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/attr.c   2011-06-10 13:03:02.000000000 +0200
2019 @@ -14,6 +14,9 @@
2020  #include <linux/fcntl.h>
2021  #include <linux/quotaops.h>
2022  #include <linux/security.h>
2023 +#include <linux/proc_fs.h>
2024 +#include <linux/devpts_fs.h>
2025 +#include <linux/vs_tag.h>
2026  
2027  /* Taken over from the old code... */
2028  
2029 @@ -55,6 +58,10 @@ int inode_change_ok(const struct inode *
2030                 if (!is_owner_or_cap(inode))
2031                         goto error;
2032         }
2033 +
2034 +       if (dx_permission(inode, MAY_WRITE))
2035 +               goto error;
2036 +
2037  fine:
2038         retval = 0;
2039  error:
2040 @@ -120,6 +127,8 @@ int inode_setattr(struct inode * inode, 
2041                 inode->i_uid = attr->ia_uid;
2042         if (ia_valid & ATTR_GID)
2043                 inode->i_gid = attr->ia_gid;
2044 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2045 +               inode->i_tag = attr->ia_tag;
2046         if (ia_valid & ATTR_ATIME)
2047                 inode->i_atime = timespec_trunc(attr->ia_atime,
2048                                                 inode->i_sb->s_time_gran);
2049 @@ -214,7 +223,8 @@ int notify_change(struct dentry * dentry
2050                 error = inode_change_ok(inode, attr);
2051                 if (!error) {
2052                         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
2053 -                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid))
2054 +                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
2055 +                           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag))
2056                                 error = vfs_dq_transfer(inode, attr) ?
2057                                         -EDQUOT : 0;
2058                         if (!error)
2059 diff -NurpP --minimal linux-2.6.32.56/fs/binfmt_aout.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/binfmt_aout.c
2060 --- linux-2.6.32.56/fs/binfmt_aout.c    2012-02-09 10:22:29.000000000 +0100
2061 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/binfmt_aout.c    2011-06-10 13:03:02.000000000 +0200
2062 @@ -24,6 +24,7 @@
2063  #include <linux/binfmts.h>
2064  #include <linux/personality.h>
2065  #include <linux/init.h>
2066 +#include <linux/vs_memory.h>
2067  
2068  #include <asm/system.h>
2069  #include <asm/uaccess.h>
2070 diff -NurpP --minimal linux-2.6.32.56/fs/binfmt_elf.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/binfmt_elf.c
2071 --- linux-2.6.32.56/fs/binfmt_elf.c     2012-02-09 10:22:29.000000000 +0100
2072 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/binfmt_elf.c     2011-06-10 13:03:02.000000000 +0200
2073 @@ -31,6 +31,7 @@
2074  #include <linux/random.h>
2075  #include <linux/elf.h>
2076  #include <linux/utsname.h>
2077 +#include <linux/vs_memory.h>
2078  #include <asm/uaccess.h>
2079  #include <asm/param.h>
2080  #include <asm/page.h>
2081 diff -NurpP --minimal linux-2.6.32.56/fs/binfmt_flat.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/binfmt_flat.c
2082 --- linux-2.6.32.56/fs/binfmt_flat.c    2012-02-09 10:22:29.000000000 +0100
2083 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/binfmt_flat.c    2011-06-10 13:03:02.000000000 +0200
2084 @@ -35,6 +35,7 @@
2085  #include <linux/init.h>
2086  #include <linux/flat.h>
2087  #include <linux/syscalls.h>
2088 +#include <linux/vs_memory.h>
2089  
2090  #include <asm/byteorder.h>
2091  #include <asm/system.h>
2092 diff -NurpP --minimal linux-2.6.32.56/fs/binfmt_som.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/binfmt_som.c
2093 --- linux-2.6.32.56/fs/binfmt_som.c     2012-02-09 10:22:29.000000000 +0100
2094 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/binfmt_som.c     2011-06-10 13:03:02.000000000 +0200
2095 @@ -28,6 +28,7 @@
2096  #include <linux/shm.h>
2097  #include <linux/personality.h>
2098  #include <linux/init.h>
2099 +#include <linux/vs_memory.h>
2100  
2101  #include <asm/uaccess.h>
2102  #include <asm/pgtable.h>
2103 diff -NurpP --minimal linux-2.6.32.56/fs/block_dev.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/block_dev.c
2104 --- linux-2.6.32.56/fs/block_dev.c      2012-02-09 10:22:29.000000000 +0100
2105 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/block_dev.c      2011-11-17 12:18:26.000000000 +0100
2106 @@ -26,6 +26,7 @@
2107  #include <linux/namei.h>
2108  #include <linux/log2.h>
2109  #include <linux/kmemleak.h>
2110 +#include <linux/vs_device.h>
2111  #include <asm/uaccess.h>
2112  #include "internal.h"
2113  
2114 @@ -557,6 +558,7 @@ struct block_device *bdget(dev_t dev)
2115                 bdev->bd_invalidated = 0;
2116                 inode->i_mode = S_IFBLK;
2117                 inode->i_rdev = dev;
2118 +               inode->i_mdev = dev;
2119                 inode->i_bdev = bdev;
2120                 inode->i_data.a_ops = &def_blk_aops;
2121                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
2122 @@ -603,6 +605,11 @@ EXPORT_SYMBOL(bdput);
2123  static struct block_device *bd_acquire(struct inode *inode)
2124  {
2125         struct block_device *bdev;
2126 +       dev_t mdev;
2127 +
2128 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
2129 +               return NULL;
2130 +       inode->i_mdev = mdev;
2131  
2132         spin_lock(&bdev_lock);
2133         bdev = inode->i_bdev;
2134 @@ -613,7 +620,7 @@ static struct block_device *bd_acquire(s
2135         }
2136         spin_unlock(&bdev_lock);
2137  
2138 -       bdev = bdget(inode->i_rdev);
2139 +       bdev = bdget(mdev);
2140         if (bdev) {
2141                 spin_lock(&bdev_lock);
2142                 if (!inode->i_bdev) {
2143 diff -NurpP --minimal linux-2.6.32.56/fs/btrfs/ctree.h linux-2.6.32.56-vs2.3.0.36.29.9/fs/btrfs/ctree.h
2144 --- linux-2.6.32.56/fs/btrfs/ctree.h    2012-02-09 10:22:29.000000000 +0100
2145 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/btrfs/ctree.h    2011-06-10 13:03:02.000000000 +0200
2146 @@ -547,11 +547,14 @@ struct btrfs_inode_item {
2147         /* modification sequence number for NFS */
2148         __le64 sequence;
2149  
2150 +       __le16 tag;
2151         /*
2152          * a little future expansion, for more than this we can
2153          * just grow the inode item and version it
2154          */
2155 -       __le64 reserved[4];
2156 +       __le16 reserved16;
2157 +       __le32 reserved32;
2158 +       __le64 reserved[3];
2159         struct btrfs_timespec atime;
2160         struct btrfs_timespec ctime;
2161         struct btrfs_timespec mtime;
2162 @@ -1162,6 +1165,8 @@ struct btrfs_root {
2163  #define BTRFS_MOUNT_NOSSD              (1 << 9)
2164  #define BTRFS_MOUNT_DISCARD            (1 << 10)
2165  
2166 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
2167 +
2168  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
2169  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
2170  #define btrfs_test_opt(root, opt)      ((root)->fs_info->mount_opt & \
2171 @@ -1181,6 +1186,10 @@ struct btrfs_root {
2172  #define BTRFS_INODE_NOATIME            (1 << 9)
2173  #define BTRFS_INODE_DIRSYNC            (1 << 10)
2174  
2175 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
2176 +#define BTRFS_INODE_BARRIER            (1 << 25)
2177 +#define BTRFS_INODE_COW                        (1 << 26)
2178 +
2179  
2180  #define BTRFS_INODE_ROOT_ITEM_INIT     (1 << 31)
2181  
2182 @@ -1385,6 +1394,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
2183  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
2184  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
2185  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
2186 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
2187  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
2188  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
2189  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
2190 @@ -2360,6 +2370,7 @@ extern const struct dentry_operations bt
2191  long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
2192  void btrfs_update_iflags(struct inode *inode);
2193  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
2194 +int btrfs_sync_flags(struct inode *inode, int, int);
2195  
2196  /* file.c */
2197  int btrfs_sync_file(struct file *file, struct dentry *dentry, int datasync);
2198 diff -NurpP --minimal linux-2.6.32.56/fs/btrfs/disk-io.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/btrfs/disk-io.c
2199 --- linux-2.6.32.56/fs/btrfs/disk-io.c  2012-02-09 10:22:29.000000000 +0100
2200 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/btrfs/disk-io.c  2011-06-10 13:03:02.000000000 +0200
2201 @@ -1728,6 +1728,9 @@ struct btrfs_root *open_ctree(struct sup
2202                 goto fail_iput;
2203         }
2204  
2205 +       if (btrfs_test_opt(tree_root, TAGGED))
2206 +               sb->s_flags |= MS_TAGGED;
2207 +
2208         features = btrfs_super_incompat_flags(disk_super) &
2209                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
2210         if (features) {
2211 diff -NurpP --minimal linux-2.6.32.56/fs/btrfs/inode.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/btrfs/inode.c
2212 --- linux-2.6.32.56/fs/btrfs/inode.c    2012-02-09 10:22:29.000000000 +0100
2213 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/btrfs/inode.c    2011-06-10 13:03:02.000000000 +0200
2214 @@ -36,6 +36,8 @@
2215  #include <linux/xattr.h>
2216  #include <linux/posix_acl.h>
2217  #include <linux/falloc.h>
2218 +#include <linux/vs_tag.h>
2219 +
2220  #include "compat.h"
2221  #include "ctree.h"
2222  #include "disk-io.h"
2223 @@ -2263,6 +2265,8 @@ static void btrfs_read_locked_inode(stru
2224         int maybe_acls;
2225         u64 alloc_group_block;
2226         u32 rdev;
2227 +       uid_t uid;
2228 +       gid_t gid;
2229         int ret;
2230  
2231         path = btrfs_alloc_path();
2232 @@ -2279,8 +2283,13 @@ static void btrfs_read_locked_inode(stru
2233  
2234         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
2235         inode->i_nlink = btrfs_inode_nlink(leaf, inode_item);
2236 -       inode->i_uid = btrfs_inode_uid(leaf, inode_item);
2237 -       inode->i_gid = btrfs_inode_gid(leaf, inode_item);
2238 +
2239 +       uid = btrfs_inode_uid(leaf, inode_item);
2240 +       gid = btrfs_inode_gid(leaf, inode_item);
2241 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2242 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2243 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2244 +               btrfs_inode_tag(leaf, inode_item));
2245         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
2246  
2247         tspec = btrfs_inode_atime(inode_item);
2248 @@ -2362,8 +2371,15 @@ static void fill_inode_item(struct btrfs
2249                             struct btrfs_inode_item *item,
2250                             struct inode *inode)
2251  {
2252 -       btrfs_set_inode_uid(leaf, item, inode->i_uid);
2253 -       btrfs_set_inode_gid(leaf, item, inode->i_gid);
2254 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2255 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2256 +
2257 +       btrfs_set_inode_uid(leaf, item, uid);
2258 +       btrfs_set_inode_gid(leaf, item, gid);
2259 +#ifdef CONFIG_TAGGING_INTERN
2260 +       btrfs_set_inode_tag(leaf, item, inode->i_tag);
2261 +#endif
2262 +
2263         btrfs_set_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size);
2264         btrfs_set_inode_mode(leaf, item, inode->i_mode);
2265         btrfs_set_inode_nlink(leaf, item, inode->i_nlink);
2266 @@ -4153,6 +4169,7 @@ static struct inode *btrfs_new_inode(str
2267         } else
2268                 inode->i_gid = current_fsgid();
2269  
2270 +       inode->i_tag = dx_current_fstag(root->fs_info->sb);
2271         inode->i_mode = mode;
2272         inode->i_ino = objectid;
2273         inode_set_bytes(inode, 0);
2274 @@ -5954,6 +5971,7 @@ static const struct inode_operations btr
2275         .listxattr      = btrfs_listxattr,
2276         .removexattr    = btrfs_removexattr,
2277         .permission     = btrfs_permission,
2278 +       .sync_flags     = btrfs_sync_flags,
2279  };
2280  static const struct inode_operations btrfs_dir_ro_inode_operations = {
2281         .lookup         = btrfs_lookup,
2282 @@ -6029,6 +6047,7 @@ static const struct inode_operations btr
2283         .permission     = btrfs_permission,
2284         .fallocate      = btrfs_fallocate,
2285         .fiemap         = btrfs_fiemap,
2286 +       .sync_flags     = btrfs_sync_flags,
2287  };
2288  static const struct inode_operations btrfs_special_inode_operations = {
2289         .getattr        = btrfs_getattr,
2290 diff -NurpP --minimal linux-2.6.32.56/fs/btrfs/ioctl.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/btrfs/ioctl.c
2291 --- linux-2.6.32.56/fs/btrfs/ioctl.c    2012-02-09 10:22:29.000000000 +0100
2292 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/btrfs/ioctl.c    2011-06-10 13:03:02.000000000 +0200
2293 @@ -67,10 +67,13 @@ static unsigned int btrfs_flags_to_ioctl
2294  {
2295         unsigned int iflags = 0;
2296  
2297 -       if (flags & BTRFS_INODE_SYNC)
2298 -               iflags |= FS_SYNC_FL;
2299         if (flags & BTRFS_INODE_IMMUTABLE)
2300                 iflags |= FS_IMMUTABLE_FL;
2301 +       if (flags & BTRFS_INODE_IXUNLINK)
2302 +               iflags |= FS_IXUNLINK_FL;
2303 +
2304 +       if (flags & BTRFS_INODE_SYNC)
2305 +               iflags |= FS_SYNC_FL;
2306         if (flags & BTRFS_INODE_APPEND)
2307                 iflags |= FS_APPEND_FL;
2308         if (flags & BTRFS_INODE_NODUMP)
2309 @@ -80,28 +83,78 @@ static unsigned int btrfs_flags_to_ioctl
2310         if (flags & BTRFS_INODE_DIRSYNC)
2311                 iflags |= FS_DIRSYNC_FL;
2312  
2313 +       if (flags & BTRFS_INODE_BARRIER)
2314 +               iflags |= FS_BARRIER_FL;
2315 +       if (flags & BTRFS_INODE_COW)
2316 +               iflags |= FS_COW_FL;
2317         return iflags;
2318  }
2319  
2320  /*
2321 - * Update inode->i_flags based on the btrfs internal flags.
2322 + * Update inode->i_(v)flags based on the btrfs internal flags.
2323   */
2324  void btrfs_update_iflags(struct inode *inode)
2325  {
2326         struct btrfs_inode *ip = BTRFS_I(inode);
2327  
2328 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2329 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2330 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2331  
2332 -       if (ip->flags & BTRFS_INODE_SYNC)
2333 -               inode->i_flags |= S_SYNC;
2334         if (ip->flags & BTRFS_INODE_IMMUTABLE)
2335                 inode->i_flags |= S_IMMUTABLE;
2336 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
2337 +               inode->i_flags |= S_IXUNLINK;
2338 +
2339 +       if (ip->flags & BTRFS_INODE_SYNC)
2340 +               inode->i_flags |= S_SYNC;
2341         if (ip->flags & BTRFS_INODE_APPEND)
2342                 inode->i_flags |= S_APPEND;
2343         if (ip->flags & BTRFS_INODE_NOATIME)
2344                 inode->i_flags |= S_NOATIME;
2345         if (ip->flags & BTRFS_INODE_DIRSYNC)
2346                 inode->i_flags |= S_DIRSYNC;
2347 +
2348 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2349 +
2350 +       if (ip->flags & BTRFS_INODE_BARRIER)
2351 +               inode->i_vflags |= V_BARRIER;
2352 +       if (ip->flags & BTRFS_INODE_COW)
2353 +               inode->i_vflags |= V_COW;
2354 +}
2355 +
2356 +/*
2357 + * Update btrfs internal flags from inode->i_(v)flags.
2358 + */
2359 +void btrfs_update_flags(struct inode *inode)
2360 +{
2361 +       struct btrfs_inode *ip = BTRFS_I(inode);
2362 +
2363 +       unsigned int flags = inode->i_flags;
2364 +       unsigned int vflags = inode->i_vflags;
2365 +
2366 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
2367 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
2368 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
2369 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
2370 +
2371 +       if (flags & S_IMMUTABLE)
2372 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
2373 +       if (flags & S_IXUNLINK)
2374 +               ip->flags |= BTRFS_INODE_IXUNLINK;
2375 +
2376 +       if (flags & S_SYNC)
2377 +               ip->flags |= BTRFS_INODE_SYNC;
2378 +       if (flags & S_APPEND)
2379 +               ip->flags |= BTRFS_INODE_APPEND;
2380 +       if (flags & S_NOATIME)
2381 +               ip->flags |= BTRFS_INODE_NOATIME;
2382 +       if (flags & S_DIRSYNC)
2383 +               ip->flags |= BTRFS_INODE_DIRSYNC;
2384 +
2385 +       if (vflags & V_BARRIER)
2386 +               ip->flags |= BTRFS_INODE_BARRIER;
2387 +       if (vflags & V_COW)
2388 +               ip->flags |= BTRFS_INODE_COW;
2389  }
2390  
2391  /*
2392 @@ -119,7 +172,7 @@ void btrfs_inherit_iflags(struct inode *
2393         flags = BTRFS_I(dir)->flags;
2394  
2395         if (S_ISREG(inode->i_mode))
2396 -               flags &= ~BTRFS_INODE_DIRSYNC;
2397 +               flags &= ~(BTRFS_INODE_DIRSYNC | BTRFS_INODE_BARRIER);
2398         else if (!S_ISDIR(inode->i_mode))
2399                 flags &= (BTRFS_INODE_NODUMP | BTRFS_INODE_NOATIME);
2400  
2401 @@ -127,6 +180,30 @@ void btrfs_inherit_iflags(struct inode *
2402         btrfs_update_iflags(inode);
2403  }
2404  
2405 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
2406 +{
2407 +       struct btrfs_inode *ip = BTRFS_I(inode);
2408 +       struct btrfs_root *root = ip->root;
2409 +       struct btrfs_trans_handle *trans;
2410 +       int ret;
2411 +
2412 +       trans = btrfs_join_transaction(root, 1);
2413 +       BUG_ON(!trans);
2414 +
2415 +       inode->i_flags = flags;
2416 +       inode->i_vflags = vflags;
2417 +       btrfs_update_flags(inode);
2418 +
2419 +       ret = btrfs_update_inode(trans, root, inode);
2420 +       BUG_ON(ret);
2421 +
2422 +       btrfs_update_iflags(inode);
2423 +       inode->i_ctime = CURRENT_TIME;
2424 +       btrfs_end_transaction(trans, root);
2425 +
2426 +       return 0;
2427 +}
2428 +
2429  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
2430  {
2431         struct btrfs_inode *ip = BTRFS_I(file->f_path.dentry->d_inode);
2432 @@ -149,6 +226,7 @@ static int btrfs_ioctl_setflags(struct f
2433         if (copy_from_user(&flags, arg, sizeof(flags)))
2434                 return -EFAULT;
2435  
2436 +       /* maybe add FS_IXUNLINK_FL ? */
2437         if (flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | \
2438                       FS_NOATIME_FL | FS_NODUMP_FL | \
2439                       FS_SYNC_FL | FS_DIRSYNC_FL))
2440 @@ -161,7 +239,8 @@ static int btrfs_ioctl_setflags(struct f
2441  
2442         flags = btrfs_mask_flags(inode->i_mode, flags);
2443         oldflags = btrfs_flags_to_ioctl(ip->flags);
2444 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
2445 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
2446 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
2447                 if (!capable(CAP_LINUX_IMMUTABLE)) {
2448                         ret = -EPERM;
2449                         goto out_unlock;
2450 @@ -172,14 +251,19 @@ static int btrfs_ioctl_setflags(struct f
2451         if (ret)
2452                 goto out_unlock;
2453  
2454 -       if (flags & FS_SYNC_FL)
2455 -               ip->flags |= BTRFS_INODE_SYNC;
2456 -       else
2457 -               ip->flags &= ~BTRFS_INODE_SYNC;
2458         if (flags & FS_IMMUTABLE_FL)
2459                 ip->flags |= BTRFS_INODE_IMMUTABLE;
2460         else
2461                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
2462 +       if (flags & FS_IXUNLINK_FL)
2463 +               ip->flags |= BTRFS_INODE_IXUNLINK;
2464 +       else
2465 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
2466 +
2467 +       if (flags & FS_SYNC_FL)
2468 +               ip->flags |= BTRFS_INODE_SYNC;
2469 +       else
2470 +               ip->flags &= ~BTRFS_INODE_SYNC;
2471         if (flags & FS_APPEND_FL)
2472                 ip->flags |= BTRFS_INODE_APPEND;
2473         else
2474 diff -NurpP --minimal linux-2.6.32.56/fs/btrfs/super.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/btrfs/super.c
2475 --- linux-2.6.32.56/fs/btrfs/super.c    2012-02-09 10:22:29.000000000 +0100
2476 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/btrfs/super.c    2011-06-10 13:03:02.000000000 +0200
2477 @@ -67,7 +67,7 @@ enum {
2478         Opt_max_extent, Opt_max_inline, Opt_alloc_start, Opt_nobarrier,
2479         Opt_ssd, Opt_nossd, Opt_ssd_spread, Opt_thread_pool, Opt_noacl,
2480         Opt_compress, Opt_notreelog, Opt_ratio, Opt_flushoncommit,
2481 -       Opt_discard, Opt_err,
2482 +       Opt_tag, Opt_notag, Opt_tagid, Opt_discard, Opt_err,
2483  };
2484  
2485  static match_table_t tokens = {
2486 @@ -90,6 +90,9 @@ static match_table_t tokens = {
2487         {Opt_flushoncommit, "flushoncommit"},
2488         {Opt_ratio, "metadata_ratio=%d"},
2489         {Opt_discard, "discard"},
2490 +       {Opt_tag, "tag"},
2491 +       {Opt_notag, "notag"},
2492 +       {Opt_tagid, "tagid=%u"},
2493         {Opt_err, NULL},
2494  };
2495  
2496 @@ -264,6 +267,22 @@ int btrfs_parse_options(struct btrfs_roo
2497                 case Opt_discard:
2498                         btrfs_set_opt(info->mount_opt, DISCARD);
2499                         break;
2500 +#ifndef CONFIG_TAGGING_NONE
2501 +               case Opt_tag:
2502 +                       printk(KERN_INFO "btrfs: use tagging\n");
2503 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2504 +                       break;
2505 +               case Opt_notag:
2506 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
2507 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
2508 +                       break;
2509 +#endif
2510 +#ifdef CONFIG_PROPAGATE
2511 +               case Opt_tagid:
2512 +                       /* use args[0] */
2513 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2514 +                       break;
2515 +#endif
2516                 case Opt_err:
2517                         printk(KERN_INFO "btrfs: unrecognized mount option "
2518                                "'%s'\n", p);
2519 @@ -585,6 +604,12 @@ static int btrfs_remount(struct super_bl
2520         if (ret)
2521                 return -EINVAL;
2522  
2523 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
2524 +               printk("btrfs: %s: tagging not permitted on remount.\n",
2525 +                       sb->s_id);
2526 +               return -EINVAL;
2527 +       }
2528 +
2529         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
2530                 return 0;
2531  
2532 diff -NurpP --minimal linux-2.6.32.56/fs/char_dev.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/char_dev.c
2533 --- linux-2.6.32.56/fs/char_dev.c       2012-02-09 10:22:29.000000000 +0100
2534 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/char_dev.c       2011-06-10 13:03:02.000000000 +0200
2535 @@ -20,6 +20,8 @@
2536  #include <linux/cdev.h>
2537  #include <linux/mutex.h>
2538  #include <linux/backing-dev.h>
2539 +#include <linux/vs_context.h>
2540 +#include <linux/vs_device.h>
2541  
2542  #include "internal.h"
2543  
2544 @@ -370,14 +372,21 @@ static int chrdev_open(struct inode *ino
2545         struct cdev *p;
2546         struct cdev *new = NULL;
2547         int ret = 0;
2548 +       dev_t mdev;
2549 +
2550 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2551 +               return -EPERM;
2552 +       inode->i_mdev = mdev;
2553  
2554         spin_lock(&cdev_lock);
2555         p = inode->i_cdev;
2556         if (!p) {
2557                 struct kobject *kobj;
2558                 int idx;
2559 +
2560                 spin_unlock(&cdev_lock);
2561 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2562 +
2563 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
2564                 if (!kobj)
2565                         return -ENXIO;
2566                 new = container_of(kobj, struct cdev, kobj);
2567 diff -NurpP --minimal linux-2.6.32.56/fs/dcache.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/dcache.c
2568 --- linux-2.6.32.56/fs/dcache.c 2012-02-09 10:22:30.000000000 +0100
2569 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/dcache.c 2011-06-10 13:03:02.000000000 +0200
2570 @@ -33,6 +33,7 @@
2571  #include <linux/bootmem.h>
2572  #include <linux/fs_struct.h>
2573  #include <linux/hardirq.h>
2574 +#include <linux/vs_limit.h>
2575  #include "internal.h"
2576  
2577  int sysctl_vfs_cache_pressure __read_mostly = 100;
2578 @@ -230,6 +231,8 @@ repeat:
2579                 return;
2580         }
2581  
2582 +       vx_dentry_dec(dentry);
2583 +
2584         /*
2585          * AV: ->d_delete() is _NOT_ allowed to block now.
2586          */
2587 @@ -321,6 +324,7 @@ static inline struct dentry * __dget_loc
2588  {
2589         atomic_inc(&dentry->d_count);
2590         dentry_lru_del_init(dentry);
2591 +       vx_dentry_inc(dentry);
2592         return dentry;
2593  }
2594  
2595 @@ -919,6 +923,9 @@ struct dentry *d_alloc(struct dentry * p
2596         struct dentry *dentry;
2597         char *dname;
2598  
2599 +       if (!vx_dentry_avail(1))
2600 +               return NULL;
2601 +
2602         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2603         if (!dentry)
2604                 return NULL;
2605 @@ -964,6 +971,7 @@ struct dentry *d_alloc(struct dentry * p
2606         if (parent)
2607                 list_add(&dentry->d_u.d_child, &parent->d_subdirs);
2608         dentry_stat.nr_dentry++;
2609 +       vx_dentry_inc(dentry);
2610         spin_unlock(&dcache_lock);
2611  
2612         return dentry;
2613 @@ -1410,6 +1418,7 @@ struct dentry * __d_lookup(struct dentry
2614                 }
2615  
2616                 atomic_inc(&dentry->d_count);
2617 +               vx_dentry_inc(dentry);
2618                 found = dentry;
2619                 spin_unlock(&dentry->d_lock);
2620                 break;
2621 diff -NurpP --minimal linux-2.6.32.56/fs/devpts/inode.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/devpts/inode.c
2622 --- linux-2.6.32.56/fs/devpts/inode.c   2012-02-09 10:22:30.000000000 +0100
2623 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/devpts/inode.c   2011-06-10 13:03:02.000000000 +0200
2624 @@ -24,6 +24,7 @@
2625  #include <linux/parser.h>
2626  #include <linux/fsnotify.h>
2627  #include <linux/seq_file.h>
2628 +#include <linux/vs_base.h>
2629  
2630  #define DEVPTS_DEFAULT_MODE 0600
2631  /*
2632 @@ -35,6 +36,20 @@
2633  #define DEVPTS_DEFAULT_PTMX_MODE 0000
2634  #define PTMX_MINOR     2
2635  
2636 +static int devpts_permission(struct inode *inode, int mask)
2637 +{
2638 +       int ret = -EACCES;
2639 +
2640 +       /* devpts is xid tagged */
2641 +       if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
2642 +               ret = generic_permission(inode, mask, NULL);
2643 +       return ret;
2644 +}
2645 +
2646 +static struct inode_operations devpts_file_inode_operations = {
2647 +       .permission     = devpts_permission,
2648 +};
2649 +
2650  extern int pty_limit;                  /* Config limit on Unix98 ptys */
2651  static DEFINE_MUTEX(allocated_ptys_lock);
2652  
2653 @@ -262,6 +277,25 @@ static int devpts_show_options(struct se
2654         return 0;
2655  }
2656  
2657 +static int devpts_filter(struct dentry *de)
2658 +{
2659 +       /* devpts is xid tagged */
2660 +       return vx_check((xid_t)de->d_inode->i_tag, VS_WATCH_P | VS_IDENT);
2661 +}
2662 +
2663 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2664 +{
2665 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2666 +}
2667 +
2668 +static struct file_operations devpts_dir_operations = {
2669 +       .open           = dcache_dir_open,
2670 +       .release        = dcache_dir_close,
2671 +       .llseek         = dcache_dir_lseek,
2672 +       .read           = generic_read_dir,
2673 +       .readdir        = devpts_readdir,
2674 +};
2675 +
2676  static const struct super_operations devpts_sops = {
2677         .statfs         = simple_statfs,
2678         .remount_fs     = devpts_remount,
2679 @@ -301,12 +335,15 @@ devpts_fill_super(struct super_block *s,
2680         inode = new_inode(s);
2681         if (!inode)
2682                 goto free_fsi;
2683 +
2684         inode->i_ino = 1;
2685         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2686         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2687         inode->i_op = &simple_dir_inode_operations;
2688 -       inode->i_fop = &simple_dir_operations;
2689 +       inode->i_fop = &devpts_dir_operations;
2690         inode->i_nlink = 2;
2691 +       /* devpts is xid tagged */
2692 +       inode->i_tag = (tag_t)vx_current_xid();
2693  
2694         s->s_root = d_alloc_root(inode);
2695         if (s->s_root)
2696 @@ -497,6 +534,9 @@ int devpts_pty_new(struct inode *ptmx_in
2697         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2698         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2699         init_special_inode(inode, S_IFCHR|opts->mode, device);
2700 +       /* devpts is xid tagged */
2701 +       inode->i_tag = (tag_t)vx_current_xid();
2702 +       inode->i_op = &devpts_file_inode_operations;
2703         inode->i_private = tty;
2704         tty->driver_data = inode;
2705  
2706 diff -NurpP --minimal linux-2.6.32.56/fs/exec.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/exec.c
2707 --- linux-2.6.32.56/fs/exec.c   2012-02-09 10:22:30.000000000 +0100
2708 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/exec.c   2011-08-08 22:40:36.000000000 +0200
2709 @@ -273,7 +273,9 @@ static int __bprm_mm_init(struct linux_b
2710         if (err)
2711                 goto err;
2712  
2713 -       mm->stack_vm = mm->total_vm = 1;
2714 +       mm->total_vm = 0;
2715 +       vx_vmpages_inc(mm);
2716 +       mm->stack_vm = 1;
2717         up_write(&mm->mmap_sem);
2718         bprm->p = vma->vm_end - sizeof(void *);
2719         return 0;
2720 @@ -1534,7 +1536,7 @@ static int format_corename(char *corenam
2721                         /* UNIX time of coredump */
2722                         case 't': {
2723                                 struct timeval tv;
2724 -                               do_gettimeofday(&tv);
2725 +                               vx_gettimeofday(&tv);
2726                                 rc = snprintf(out_ptr, out_end - out_ptr,
2727                                               "%lu", tv.tv_sec);
2728                                 if (rc > out_end - out_ptr)
2729 diff -NurpP --minimal linux-2.6.32.56/fs/ext2/balloc.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext2/balloc.c
2730 --- linux-2.6.32.56/fs/ext2/balloc.c    2009-06-11 17:13:03.000000000 +0200
2731 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext2/balloc.c    2011-06-10 13:03:02.000000000 +0200
2732 @@ -701,7 +701,6 @@ ext2_try_to_allocate(struct super_block 
2733                         start = 0;
2734                 end = EXT2_BLOCKS_PER_GROUP(sb);
2735         }
2736 -
2737         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2738  
2739  repeat:
2740 diff -NurpP --minimal linux-2.6.32.56/fs/ext2/ext2.h linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext2/ext2.h
2741 --- linux-2.6.32.56/fs/ext2/ext2.h      2009-09-10 15:26:21.000000000 +0200
2742 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext2/ext2.h      2011-06-10 13:03:02.000000000 +0200
2743 @@ -131,6 +131,7 @@ extern int ext2_fiemap(struct inode *ino
2744  int __ext2_write_begin(struct file *file, struct address_space *mapping,
2745                 loff_t pos, unsigned len, unsigned flags,
2746                 struct page **pagep, void **fsdata);
2747 +extern int ext2_sync_flags(struct inode *, int, int);
2748  
2749  /* ioctl.c */
2750  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2751 diff -NurpP --minimal linux-2.6.32.56/fs/ext2/file.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext2/file.c
2752 --- linux-2.6.32.56/fs/ext2/file.c      2009-12-03 20:02:51.000000000 +0100
2753 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext2/file.c      2011-06-10 13:03:02.000000000 +0200
2754 @@ -87,4 +87,5 @@ const struct inode_operations ext2_file_
2755         .setattr        = ext2_setattr,
2756         .check_acl      = ext2_check_acl,
2757         .fiemap         = ext2_fiemap,
2758 +       .sync_flags     = ext2_sync_flags,
2759  };
2760 diff -NurpP --minimal linux-2.6.32.56/fs/ext2/ialloc.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext2/ialloc.c
2761 --- linux-2.6.32.56/fs/ext2/ialloc.c    2009-06-11 17:13:03.000000000 +0200
2762 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext2/ialloc.c    2011-06-10 13:03:02.000000000 +0200
2763 @@ -17,6 +17,7 @@
2764  #include <linux/backing-dev.h>
2765  #include <linux/buffer_head.h>
2766  #include <linux/random.h>
2767 +#include <linux/vs_tag.h>
2768  #include "ext2.h"
2769  #include "xattr.h"
2770  #include "acl.h"
2771 @@ -560,6 +561,7 @@ got:
2772         } else
2773                 inode->i_gid = current_fsgid();
2774         inode->i_mode = mode;
2775 +       inode->i_tag = dx_current_fstag(sb);
2776  
2777         inode->i_ino = ino;
2778         inode->i_blocks = 0;
2779 diff -NurpP --minimal linux-2.6.32.56/fs/ext2/inode.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext2/inode.c
2780 --- linux-2.6.32.56/fs/ext2/inode.c     2009-12-03 20:02:51.000000000 +0100
2781 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext2/inode.c     2011-06-10 18:47:35.000000000 +0200
2782 @@ -33,6 +33,7 @@
2783  #include <linux/mpage.h>
2784  #include <linux/fiemap.h>
2785  #include <linux/namei.h>
2786 +#include <linux/vs_tag.h>
2787  #include "ext2.h"
2788  #include "acl.h"
2789  #include "xip.h"
2790 @@ -1040,7 +1041,7 @@ void ext2_truncate(struct inode *inode)
2791                 return;
2792         if (ext2_inode_is_fast_symlink(inode))
2793                 return;
2794 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2795 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2796                 return;
2797  
2798         blocksize = inode->i_sb->s_blocksize;
2799 @@ -1178,36 +1179,61 @@ void ext2_set_inode_flags(struct inode *
2800  {
2801         unsigned int flags = EXT2_I(inode)->i_flags;
2802  
2803 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2804 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2805 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2806 +
2807 +
2808 +       if (flags & EXT2_IMMUTABLE_FL)
2809 +               inode->i_flags |= S_IMMUTABLE;
2810 +       if (flags & EXT2_IXUNLINK_FL)
2811 +               inode->i_flags |= S_IXUNLINK;
2812 +
2813         if (flags & EXT2_SYNC_FL)
2814                 inode->i_flags |= S_SYNC;
2815         if (flags & EXT2_APPEND_FL)
2816                 inode->i_flags |= S_APPEND;
2817 -       if (flags & EXT2_IMMUTABLE_FL)
2818 -               inode->i_flags |= S_IMMUTABLE;
2819         if (flags & EXT2_NOATIME_FL)
2820                 inode->i_flags |= S_NOATIME;
2821         if (flags & EXT2_DIRSYNC_FL)
2822                 inode->i_flags |= S_DIRSYNC;
2823 +
2824 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2825 +
2826 +       if (flags & EXT2_BARRIER_FL)
2827 +               inode->i_vflags |= V_BARRIER;
2828 +       if (flags & EXT2_COW_FL)
2829 +               inode->i_vflags |= V_COW;
2830  }
2831  
2832  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2833  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2834  {
2835         unsigned int flags = ei->vfs_inode.i_flags;
2836 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2837 +
2838 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2839 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2840 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2841 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2842 +
2843 +       if (flags & S_IMMUTABLE)
2844 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2845 +       if (flags & S_IXUNLINK)
2846 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2847  
2848 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2849 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2850         if (flags & S_SYNC)
2851                 ei->i_flags |= EXT2_SYNC_FL;
2852         if (flags & S_APPEND)
2853                 ei->i_flags |= EXT2_APPEND_FL;
2854 -       if (flags & S_IMMUTABLE)
2855 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2856         if (flags & S_NOATIME)
2857                 ei->i_flags |= EXT2_NOATIME_FL;
2858         if (flags & S_DIRSYNC)
2859                 ei->i_flags |= EXT2_DIRSYNC_FL;
2860 +
2861 +       if (vflags & V_BARRIER)
2862 +               ei->i_flags |= EXT2_BARRIER_FL;
2863 +       if (vflags & V_COW)
2864 +               ei->i_flags |= EXT2_COW_FL;
2865  }
2866  
2867  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2868 @@ -1217,6 +1243,8 @@ struct inode *ext2_iget (struct super_bl
2869         struct ext2_inode *raw_inode;
2870         struct inode *inode;
2871         long ret = -EIO;
2872 +       uid_t uid;
2873 +       gid_t gid;
2874         int n;
2875  
2876         inode = iget_locked(sb, ino);
2877 @@ -1235,12 +1263,17 @@ struct inode *ext2_iget (struct super_bl
2878         }
2879  
2880         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2881 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2882 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2883 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2884 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2885         if (!(test_opt (inode->i_sb, NO_UID32))) {
2886 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2887 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2888 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2889 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2890         }
2891 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2892 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2893 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2894 +               le16_to_cpu(raw_inode->i_raw_tag));
2895 +
2896         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
2897         inode->i_size = le32_to_cpu(raw_inode->i_size);
2898         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2899 @@ -1338,8 +1371,8 @@ int ext2_write_inode(struct inode *inode
2900         struct ext2_inode_info *ei = EXT2_I(inode);
2901         struct super_block *sb = inode->i_sb;
2902         ino_t ino = inode->i_ino;
2903 -       uid_t uid = inode->i_uid;
2904 -       gid_t gid = inode->i_gid;
2905 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2906 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2907         struct buffer_head * bh;
2908         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2909         int n;
2910 @@ -1375,6 +1408,9 @@ int ext2_write_inode(struct inode *inode
2911                 raw_inode->i_uid_high = 0;
2912                 raw_inode->i_gid_high = 0;
2913         }
2914 +#ifdef CONFIG_TAGGING_INTERN
2915 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2916 +#endif
2917         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2918         raw_inode->i_size = cpu_to_le32(inode->i_size);
2919         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2920 @@ -1456,7 +1492,8 @@ int ext2_setattr(struct dentry *dentry, 
2921         if (error)
2922                 return error;
2923         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
2924 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
2925 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
2926 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
2927                 error = vfs_dq_transfer(inode, iattr) ? -EDQUOT : 0;
2928                 if (error)
2929                         return error;
2930 diff -NurpP --minimal linux-2.6.32.56/fs/ext2/ioctl.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext2/ioctl.c
2931 --- linux-2.6.32.56/fs/ext2/ioctl.c     2009-09-10 15:26:21.000000000 +0200
2932 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext2/ioctl.c     2011-06-10 18:47:17.000000000 +0200
2933 @@ -17,6 +17,16 @@
2934  #include <asm/uaccess.h>
2935  
2936  
2937 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2938 +{
2939 +       inode->i_flags = flags;
2940 +       inode->i_vflags = vflags;
2941 +       ext2_get_inode_flags(EXT2_I(inode));
2942 +       inode->i_ctime = CURRENT_TIME_SEC;
2943 +       mark_inode_dirty(inode);
2944 +       return 0;
2945 +}
2946 +
2947  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2948  {
2949         struct inode *inode = filp->f_dentry->d_inode;
2950 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2951  
2952                 flags = ext2_mask_flags(inode->i_mode, flags);
2953  
2954 +               if (IS_BARRIER(inode)) {
2955 +                       vxwprintk_task(1, "messing with the barrier.");
2956 +                       return -EACCES;
2957 +               }
2958 +
2959                 mutex_lock(&inode->i_mutex);
2960                 /* Is it quota file? Do not allow user to mess with it */
2961                 if (IS_NOQUOTA(inode)) {
2962 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2963                  *
2964                  * This test looks nicer. Thanks to Pauline Middelink
2965                  */
2966 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2967 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2968 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2969 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2970                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2971                                 mutex_unlock(&inode->i_mutex);
2972                                 ret = -EPERM;
2973 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2974                         }
2975                 }
2976  
2977 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
2978 +               flags &= EXT2_FL_USER_MODIFIABLE;
2979                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2980                 ei->i_flags = flags;
2981                 mutex_unlock(&inode->i_mutex);
2982 diff -NurpP --minimal linux-2.6.32.56/fs/ext2/namei.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext2/namei.c
2983 --- linux-2.6.32.56/fs/ext2/namei.c     2012-02-09 10:22:30.000000000 +0100
2984 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext2/namei.c     2011-06-10 13:03:02.000000000 +0200
2985 @@ -31,6 +31,7 @@
2986   */
2987  
2988  #include <linux/pagemap.h>
2989 +#include <linux/vs_tag.h>
2990  #include "ext2.h"
2991  #include "xattr.h"
2992  #include "acl.h"
2993 @@ -74,6 +75,7 @@ static struct dentry *ext2_lookup(struct
2994                                 return ERR_PTR(-EIO);
2995                         } else {
2996                                 return ERR_CAST(inode);
2997 +               dx_propagate_tag(nd, inode);
2998                         }
2999                 }
3000         }
3001 @@ -396,6 +398,7 @@ const struct inode_operations ext2_dir_i
3002  #endif
3003         .setattr        = ext2_setattr,
3004         .check_acl      = ext2_check_acl,
3005 +       .sync_flags     = ext2_sync_flags,
3006  };
3007  
3008  const struct inode_operations ext2_special_inode_operations = {
3009 diff -NurpP --minimal linux-2.6.32.56/fs/ext2/super.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext2/super.c
3010 --- linux-2.6.32.56/fs/ext2/super.c     2009-09-10 15:26:21.000000000 +0200
3011 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext2/super.c     2011-06-10 13:03:02.000000000 +0200
3012 @@ -382,7 +382,8 @@ enum {
3013         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
3014         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
3015         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
3016 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
3017 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
3018 +       Opt_tag, Opt_notag, Opt_tagid
3019  };
3020  
3021  static const match_table_t tokens = {
3022 @@ -410,6 +411,9 @@ static const match_table_t tokens = {
3023         {Opt_acl, "acl"},
3024         {Opt_noacl, "noacl"},
3025         {Opt_xip, "xip"},
3026 +       {Opt_tag, "tag"},
3027 +       {Opt_notag, "notag"},
3028 +       {Opt_tagid, "tagid=%u"},
3029         {Opt_grpquota, "grpquota"},
3030         {Opt_ignore, "noquota"},
3031         {Opt_quota, "quota"},
3032 @@ -480,6 +484,20 @@ static int parse_options (char * options
3033                 case Opt_nouid32:
3034                         set_opt (sbi->s_mount_opt, NO_UID32);
3035                         break;
3036 +#ifndef CONFIG_TAGGING_NONE
3037 +               case Opt_tag:
3038 +                       set_opt (sbi->s_mount_opt, TAGGED);
3039 +                       break;
3040 +               case Opt_notag:
3041 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3042 +                       break;
3043 +#endif
3044 +#ifdef CONFIG_PROPAGATE
3045 +               case Opt_tagid:
3046 +                       /* use args[0] */
3047 +                       set_opt (sbi->s_mount_opt, TAGGED);
3048 +                       break;
3049 +#endif
3050                 case Opt_nocheck:
3051                         clear_opt (sbi->s_mount_opt, CHECK);
3052                         break;
3053 @@ -829,6 +847,8 @@ static int ext2_fill_super(struct super_
3054         if (!parse_options ((char *) data, sbi))
3055                 goto failed_mount;
3056  
3057 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
3058 +               sb->s_flags |= MS_TAGGED;
3059         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3060                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
3061                  MS_POSIXACL : 0);
3062 @@ -1175,6 +1195,14 @@ static int ext2_remount (struct super_bl
3063                 goto restore_opts;
3064         }
3065  
3066 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
3067 +               !(sb->s_flags & MS_TAGGED)) {
3068 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
3069 +                      sb->s_id);
3070 +               err = -EINVAL;
3071 +               goto restore_opts;
3072 +       }
3073 +
3074         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3075                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3076  
3077 diff -NurpP --minimal linux-2.6.32.56/fs/ext3/file.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext3/file.c
3078 --- linux-2.6.32.56/fs/ext3/file.c      2009-12-03 20:02:51.000000000 +0100
3079 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext3/file.c      2011-06-10 13:03:02.000000000 +0200
3080 @@ -80,5 +80,6 @@ const struct inode_operations ext3_file_
3081  #endif
3082         .check_acl      = ext3_check_acl,
3083         .fiemap         = ext3_fiemap,
3084 +       .sync_flags     = ext3_sync_flags,
3085  };
3086  
3087 diff -NurpP --minimal linux-2.6.32.56/fs/ext3/ialloc.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext3/ialloc.c
3088 --- linux-2.6.32.56/fs/ext3/ialloc.c    2009-09-10 15:26:21.000000000 +0200
3089 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext3/ialloc.c    2011-06-10 13:03:02.000000000 +0200
3090 @@ -23,6 +23,7 @@
3091  #include <linux/buffer_head.h>
3092  #include <linux/random.h>
3093  #include <linux/bitops.h>
3094 +#include <linux/vs_tag.h>
3095  
3096  #include <asm/byteorder.h>
3097  
3098 @@ -548,6 +549,7 @@ got:
3099         } else
3100                 inode->i_gid = current_fsgid();
3101         inode->i_mode = mode;
3102 +       inode->i_tag = dx_current_fstag(sb);
3103  
3104         inode->i_ino = ino;
3105         /* This is the optimal IO size (for stat), not the fs block size */
3106 diff -NurpP --minimal linux-2.6.32.56/fs/ext3/inode.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext3/inode.c
3107 --- linux-2.6.32.56/fs/ext3/inode.c     2012-02-09 10:22:30.000000000 +0100
3108 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext3/inode.c     2011-06-10 13:03:02.000000000 +0200
3109 @@ -38,6 +38,7 @@
3110  #include <linux/bio.h>
3111  #include <linux/fiemap.h>
3112  #include <linux/namei.h>
3113 +#include <linux/vs_tag.h>
3114  #include "xattr.h"
3115  #include "acl.h"
3116  
3117 @@ -2343,7 +2344,7 @@ static void ext3_free_branches(handle_t 
3118  
3119  int ext3_can_truncate(struct inode *inode)
3120  {
3121 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3122 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3123                 return 0;
3124         if (S_ISREG(inode->i_mode))
3125                 return 1;
3126 @@ -2728,36 +2729,60 @@ void ext3_set_inode_flags(struct inode *
3127  {
3128         unsigned int flags = EXT3_I(inode)->i_flags;
3129  
3130 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3131 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3132 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3133 +
3134 +       if (flags & EXT3_IMMUTABLE_FL)
3135 +               inode->i_flags |= S_IMMUTABLE;
3136 +       if (flags & EXT3_IXUNLINK_FL)
3137 +               inode->i_flags |= S_IXUNLINK;
3138 +
3139         if (flags & EXT3_SYNC_FL)
3140                 inode->i_flags |= S_SYNC;
3141         if (flags & EXT3_APPEND_FL)
3142                 inode->i_flags |= S_APPEND;
3143 -       if (flags & EXT3_IMMUTABLE_FL)
3144 -               inode->i_flags |= S_IMMUTABLE;
3145         if (flags & EXT3_NOATIME_FL)
3146                 inode->i_flags |= S_NOATIME;
3147         if (flags & EXT3_DIRSYNC_FL)
3148                 inode->i_flags |= S_DIRSYNC;
3149 +
3150 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3151 +
3152 +       if (flags & EXT3_BARRIER_FL)
3153 +               inode->i_vflags |= V_BARRIER;
3154 +       if (flags & EXT3_COW_FL)
3155 +               inode->i_vflags |= V_COW;
3156  }
3157  
3158  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
3159  void ext3_get_inode_flags(struct ext3_inode_info *ei)
3160  {
3161         unsigned int flags = ei->vfs_inode.i_flags;
3162 +       unsigned int vflags = ei->vfs_inode.i_vflags;
3163 +
3164 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
3165 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
3166 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
3167 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
3168 +
3169 +       if (flags & S_IMMUTABLE)
3170 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
3171 +       if (flags & S_IXUNLINK)
3172 +               ei->i_flags |= EXT3_IXUNLINK_FL;
3173  
3174 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
3175 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
3176         if (flags & S_SYNC)
3177                 ei->i_flags |= EXT3_SYNC_FL;
3178         if (flags & S_APPEND)
3179                 ei->i_flags |= EXT3_APPEND_FL;
3180 -       if (flags & S_IMMUTABLE)
3181 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
3182         if (flags & S_NOATIME)
3183                 ei->i_flags |= EXT3_NOATIME_FL;
3184         if (flags & S_DIRSYNC)
3185                 ei->i_flags |= EXT3_DIRSYNC_FL;
3186 +
3187 +       if (vflags & V_BARRIER)
3188 +               ei->i_flags |= EXT3_BARRIER_FL;
3189 +       if (vflags & V_COW)
3190 +               ei->i_flags |= EXT3_COW_FL;
3191  }
3192  
3193  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
3194 @@ -2771,6 +2796,8 @@ struct inode *ext3_iget(struct super_blo
3195         transaction_t *transaction;
3196         long ret;
3197         int block;
3198 +       uid_t uid;
3199 +       gid_t gid;
3200  
3201         inode = iget_locked(sb, ino);
3202         if (!inode)
3203 @@ -2787,12 +2814,17 @@ struct inode *ext3_iget(struct super_blo
3204         bh = iloc.bh;
3205         raw_inode = ext3_raw_inode(&iloc);
3206         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3207 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3208 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3209 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3210 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3211         if(!(test_opt (inode->i_sb, NO_UID32))) {
3212 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3213 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3214 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3215 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3216         }
3217 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3218 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3219 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3220 +               le16_to_cpu(raw_inode->i_raw_tag));
3221 +
3222         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3223         inode->i_size = le32_to_cpu(raw_inode->i_size);
3224         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
3225 @@ -2947,6 +2979,8 @@ static int ext3_do_update_inode(handle_t
3226         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
3227         struct ext3_inode_info *ei = EXT3_I(inode);
3228         struct buffer_head *bh = iloc->bh;
3229 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3230 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3231         int err = 0, rc, block;
3232  
3233  again:
3234 @@ -2961,29 +2995,32 @@ again:
3235         ext3_get_inode_flags(ei);
3236         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3237         if(!(test_opt(inode->i_sb, NO_UID32))) {
3238 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3239 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3240 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3241 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3242  /*
3243   * Fix up interoperability with old kernels. Otherwise, old inodes get
3244   * re-used with the upper 16 bits of the uid/gid intact
3245   */
3246                 if(!ei->i_dtime) {
3247                         raw_inode->i_uid_high =
3248 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3249 +                               cpu_to_le16(high_16_bits(uid));
3250                         raw_inode->i_gid_high =
3251 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3252 +                               cpu_to_le16(high_16_bits(gid));
3253                 } else {
3254                         raw_inode->i_uid_high = 0;
3255                         raw_inode->i_gid_high = 0;
3256                 }
3257         } else {
3258                 raw_inode->i_uid_low =
3259 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3260 +                       cpu_to_le16(fs_high2lowuid(uid));
3261                 raw_inode->i_gid_low =
3262 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3263 +                       cpu_to_le16(fs_high2lowgid(gid));
3264                 raw_inode->i_uid_high = 0;
3265                 raw_inode->i_gid_high = 0;
3266         }
3267 +#ifdef CONFIG_TAGGING_INTERN
3268 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3269 +#endif
3270         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3271         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
3272         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
3273 @@ -3141,7 +3178,8 @@ int ext3_setattr(struct dentry *dentry, 
3274                 return error;
3275  
3276         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3277 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3278 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3279 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3280                 handle_t *handle;
3281  
3282                 /* (user+group)*(old+new) structure, inode write (sb,
3283 @@ -3163,6 +3201,8 @@ int ext3_setattr(struct dentry *dentry, 
3284                         inode->i_uid = attr->ia_uid;
3285                 if (attr->ia_valid & ATTR_GID)
3286                         inode->i_gid = attr->ia_gid;
3287 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3288 +                       inode->i_tag = attr->ia_tag;
3289                 error = ext3_mark_inode_dirty(handle, inode);
3290                 ext3_journal_stop(handle);
3291         }
3292 diff -NurpP --minimal linux-2.6.32.56/fs/ext3/ioctl.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext3/ioctl.c
3293 --- linux-2.6.32.56/fs/ext3/ioctl.c     2009-06-11 17:13:03.000000000 +0200
3294 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext3/ioctl.c     2011-06-10 13:03:02.000000000 +0200
3295 @@ -8,6 +8,7 @@
3296   */
3297  
3298  #include <linux/fs.h>
3299 +#include <linux/mount.h>
3300  #include <linux/jbd.h>
3301  #include <linux/capability.h>
3302  #include <linux/ext3_fs.h>
3303 @@ -17,6 +18,34 @@
3304  #include <linux/compat.h>
3305  #include <asm/uaccess.h>
3306  
3307 +
3308 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
3309 +{
3310 +       handle_t *handle = NULL;
3311 +       struct ext3_iloc iloc;
3312 +       int err;
3313 +
3314 +       handle = ext3_journal_start(inode, 1);
3315 +       if (IS_ERR(handle))
3316 +               return PTR_ERR(handle);
3317 +
3318 +       if (IS_SYNC(inode))
3319 +               handle->h_sync = 1;
3320 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
3321 +       if (err)
3322 +               goto flags_err;
3323 +
3324 +       inode->i_flags = flags;
3325 +       inode->i_vflags = vflags;
3326 +       ext3_get_inode_flags(EXT3_I(inode));
3327 +       inode->i_ctime = CURRENT_TIME_SEC;
3328 +
3329 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
3330 +flags_err:
3331 +       ext3_journal_stop(handle);
3332 +       return err;
3333 +}
3334 +
3335  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3336  {
3337         struct inode *inode = filp->f_dentry->d_inode;
3338 @@ -50,6 +79,11 @@ long ext3_ioctl(struct file *filp, unsig
3339  
3340                 flags = ext3_mask_flags(inode->i_mode, flags);
3341  
3342 +               if (IS_BARRIER(inode)) {
3343 +                       vxwprintk_task(1, "messing with the barrier.");
3344 +                       return -EACCES;
3345 +               }
3346 +
3347                 mutex_lock(&inode->i_mutex);
3348  
3349                 /* Is it quota file? Do not allow user to mess with it */
3350 @@ -68,7 +102,9 @@ long ext3_ioctl(struct file *filp, unsig
3351                  *
3352                  * This test looks nicer. Thanks to Pauline Middelink
3353                  */
3354 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
3355 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
3356 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
3357 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
3358                         if (!capable(CAP_LINUX_IMMUTABLE))
3359                                 goto flags_out;
3360                 }
3361 @@ -93,7 +129,7 @@ long ext3_ioctl(struct file *filp, unsig
3362                 if (err)
3363                         goto flags_err;
3364  
3365 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
3366 +               flags &= EXT3_FL_USER_MODIFIABLE;
3367                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
3368                 ei->i_flags = flags;
3369  
3370 diff -NurpP --minimal linux-2.6.32.56/fs/ext3/namei.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext3/namei.c
3371 --- linux-2.6.32.56/fs/ext3/namei.c     2012-02-09 10:22:30.000000000 +0100
3372 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext3/namei.c     2011-08-08 22:40:36.000000000 +0200
3373 @@ -36,6 +36,7 @@
3374  #include <linux/quotaops.h>
3375  #include <linux/buffer_head.h>
3376  #include <linux/bio.h>
3377 +#include <linux/vs_tag.h>
3378  
3379  #include "namei.h"
3380  #include "xattr.h"
3381 @@ -912,6 +913,7 @@ restart:
3382                                 if (bh)
3383                                         ll_rw_block(READ_META, 1, &bh);
3384                         }
3385 +               dx_propagate_tag(nd, inode);
3386                 }
3387                 if ((bh = bh_use[ra_ptr++]) == NULL)
3388                         goto next;
3389 @@ -2455,6 +2457,7 @@ const struct inode_operations ext3_dir_i
3390         .removexattr    = generic_removexattr,
3391  #endif
3392         .check_acl      = ext3_check_acl,
3393 +       .sync_flags     = ext3_sync_flags,
3394  };
3395  
3396  const struct inode_operations ext3_special_inode_operations = {
3397 diff -NurpP --minimal linux-2.6.32.56/fs/ext3/super.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext3/super.c
3398 --- linux-2.6.32.56/fs/ext3/super.c     2012-02-09 10:22:30.000000000 +0100
3399 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext3/super.c     2011-06-10 13:03:02.000000000 +0200
3400 @@ -789,7 +789,7 @@ enum {
3401         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
3402         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
3403         Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
3404 -       Opt_grpquota
3405 +       Opt_grpquota, Opt_tag, Opt_notag, Opt_tagid
3406  };
3407  
3408  static const match_table_t tokens = {
3409 @@ -842,6 +842,9 @@ static const match_table_t tokens = {
3410         {Opt_usrquota, "usrquota"},
3411         {Opt_barrier, "barrier=%u"},
3412         {Opt_resize, "resize"},
3413 +       {Opt_tag, "tag"},
3414 +       {Opt_notag, "notag"},
3415 +       {Opt_tagid, "tagid=%u"},
3416         {Opt_err, NULL},
3417  };
3418  
3419 @@ -934,6 +937,20 @@ static int parse_options (char *options,
3420                 case Opt_nouid32:
3421                         set_opt (sbi->s_mount_opt, NO_UID32);
3422                         break;
3423 +#ifndef CONFIG_TAGGING_NONE
3424 +               case Opt_tag:
3425 +                       set_opt (sbi->s_mount_opt, TAGGED);
3426 +                       break;
3427 +               case Opt_notag:
3428 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3429 +                       break;
3430 +#endif
3431 +#ifdef CONFIG_PROPAGATE
3432 +               case Opt_tagid:
3433 +                       /* use args[0] */
3434 +                       set_opt (sbi->s_mount_opt, TAGGED);
3435 +                       break;
3436 +#endif
3437                 case Opt_nocheck:
3438                         clear_opt (sbi->s_mount_opt, CHECK);
3439                         break;
3440 @@ -1665,6 +1682,9 @@ static int ext3_fill_super (struct super
3441                             NULL, 0))
3442                 goto failed_mount;
3443  
3444 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
3445 +               sb->s_flags |= MS_TAGGED;
3446 +
3447         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3448                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3449  
3450 @@ -2534,6 +2554,14 @@ static int ext3_remount (struct super_bl
3451         if (sbi->s_mount_opt & EXT3_MOUNT_ABORT)
3452                 ext3_abort(sb, __func__, "Abort forced by user");
3453  
3454 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
3455 +               !(sb->s_flags & MS_TAGGED)) {
3456 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
3457 +                       sb->s_id);
3458 +               err = -EINVAL;
3459 +               goto restore_opts;
3460 +       }
3461 +
3462         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3463                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3464  
3465 diff -NurpP --minimal linux-2.6.32.56/fs/ext4/ext4.h linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext4/ext4.h
3466 --- linux-2.6.32.56/fs/ext4/ext4.h      2012-02-09 10:22:30.000000000 +0100
3467 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext4/ext4.h      2011-11-17 12:18:26.000000000 +0100
3468 @@ -289,8 +289,12 @@ struct flex_groups {
3469  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
3470  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
3471  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
3472 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
3473  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
3474  
3475 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
3476 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
3477 +
3478  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
3479  #define EXT4_FL_USER_MODIFIABLE                0x004B80FF /* User modifiable flags */
3480  
3481 @@ -551,7 +555,8 @@ struct ext4_inode {
3482                         __le16  l_i_file_acl_high;
3483                         __le16  l_i_uid_high;   /* these 2 fields */
3484                         __le16  l_i_gid_high;   /* were reserved2[0] */
3485 -                       __u32   l_i_reserved2;
3486 +                       __le16  l_i_tag;        /* Context Tag */
3487 +                       __u16   l_i_reserved2;
3488                 } linux2;
3489                 struct {
3490                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
3491 @@ -665,6 +670,7 @@ do {                                                                               \
3492  #define i_gid_low      i_gid
3493  #define i_uid_high     osd2.linux2.l_i_uid_high
3494  #define i_gid_high     osd2.linux2.l_i_gid_high
3495 +#define i_raw_tag      osd2.linux2.l_i_tag
3496  #define i_reserved2    osd2.linux2.l_i_reserved2
3497  
3498  #elif defined(__GNU__)
3499 @@ -839,6 +845,7 @@ struct ext4_inode_info {
3500  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
3501  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
3502  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
3503 +#define EXT4_MOUNT_TAGGED              0x400000 /* Enable Context Tags */
3504  #define EXT4_MOUNT_JOURNAL_CHECKSUM    0x800000 /* Journal checksums */
3505  #define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT        0x1000000 /* Journal Async Commit */
3506  #define EXT4_MOUNT_I_VERSION            0x2000000 /* i_version support */
3507 @@ -1864,6 +1871,7 @@ extern int ext4_get_blocks(handle_t *han
3508                            struct buffer_head *bh, int flags);
3509  extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
3510                         __u64 start, __u64 len);
3511 +extern int ext4_sync_flags(struct inode *, int, int);
3512  /* move_extent.c */
3513  extern int ext4_move_extents(struct file *o_filp, struct file *d_filp,
3514                              __u64 start_orig, __u64 start_donor,
3515 diff -NurpP --minimal linux-2.6.32.56/fs/ext4/file.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext4/file.c
3516 --- linux-2.6.32.56/fs/ext4/file.c      2012-02-09 10:22:30.000000000 +0100
3517 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext4/file.c      2011-06-10 13:03:02.000000000 +0200
3518 @@ -161,5 +161,6 @@ const struct inode_operations ext4_file_
3519         .check_acl      = ext4_check_acl,
3520         .fallocate      = ext4_fallocate,
3521         .fiemap         = ext4_fiemap,
3522 +       .sync_flags     = ext4_sync_flags,
3523  };
3524  
3525 diff -NurpP --minimal linux-2.6.32.56/fs/ext4/ialloc.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext4/ialloc.c
3526 --- linux-2.6.32.56/fs/ext4/ialloc.c    2012-02-09 10:22:30.000000000 +0100
3527 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext4/ialloc.c    2011-06-10 13:03:02.000000000 +0200
3528 @@ -22,6 +22,7 @@
3529  #include <linux/random.h>
3530  #include <linux/bitops.h>
3531  #include <linux/blkdev.h>
3532 +#include <linux/vs_tag.h>
3533  #include <asm/byteorder.h>
3534  
3535  #include "ext4.h"
3536 @@ -988,6 +989,7 @@ got:
3537         } else
3538                 inode->i_gid = current_fsgid();
3539         inode->i_mode = mode;
3540 +       inode->i_tag = dx_current_fstag(sb);
3541  
3542         inode->i_ino = ino + group * EXT4_INODES_PER_GROUP(sb);
3543         /* This is the optimal IO size (for stat), not the fs block size */
3544 diff -NurpP --minimal linux-2.6.32.56/fs/ext4/inode.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext4/inode.c
3545 --- linux-2.6.32.56/fs/ext4/inode.c     2012-02-09 10:22:30.000000000 +0100
3546 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext4/inode.c     2012-01-10 09:18:12.000000000 +0100
3547 @@ -38,6 +38,7 @@
3548  #include <linux/uio.h>
3549  #include <linux/bio.h>
3550  #include <linux/workqueue.h>
3551 +#include <linux/vs_tag.h>
3552  
3553  #include "ext4_jbd2.h"
3554  #include "xattr.h"
3555 @@ -4446,7 +4447,7 @@ static void ext4_free_branches(handle_t 
3556  
3557  int ext4_can_truncate(struct inode *inode)
3558  {
3559 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3560 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3561                 return 0;
3562         if (S_ISREG(inode->i_mode))
3563                 return 1;
3564 @@ -4799,41 +4800,64 @@ void ext4_set_inode_flags(struct inode *
3565  {
3566         unsigned int flags = EXT4_I(inode)->i_flags;
3567  
3568 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3569 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3570 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3571 +
3572 +       if (flags & EXT4_IMMUTABLE_FL)
3573 +               inode->i_flags |= S_IMMUTABLE;
3574 +       if (flags & EXT4_IXUNLINK_FL)
3575 +               inode->i_flags |= S_IXUNLINK;
3576 +
3577         if (flags & EXT4_SYNC_FL)
3578                 inode->i_flags |= S_SYNC;
3579         if (flags & EXT4_APPEND_FL)
3580                 inode->i_flags |= S_APPEND;
3581 -       if (flags & EXT4_IMMUTABLE_FL)
3582 -               inode->i_flags |= S_IMMUTABLE;
3583         if (flags & EXT4_NOATIME_FL)
3584                 inode->i_flags |= S_NOATIME;
3585         if (flags & EXT4_DIRSYNC_FL)
3586                 inode->i_flags |= S_DIRSYNC;
3587 +
3588 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3589 +
3590 +       if (flags & EXT4_BARRIER_FL)
3591 +               inode->i_vflags |= V_BARRIER;
3592 +       if (flags & EXT4_COW_FL)
3593 +               inode->i_vflags |= V_COW;
3594  }
3595  
3596  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3597  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3598  {
3599 -       unsigned int vfs_fl;
3600 +       unsigned int vfs_fl, vflags;
3601         unsigned long old_fl, new_fl;
3602  
3603         do {
3604                 vfs_fl = ei->vfs_inode.i_flags;
3605 +               vflags = ei->vfs_inode.i_vflags;
3606                 old_fl = ei->i_flags;
3607 -               new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3608 -                               EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
3609 -                               EXT4_DIRSYNC_FL);
3610 +               new_fl = old_fl & ~(EXT4_SYNC_FL | EXT4_APPEND_FL |
3611 +                               EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL |
3612 +                               EXT4_NOATIME_FL | EXT4_DIRSYNC_FL |
3613 +                               EXT4_BARRIER_FL | EXT4_COW_FL);
3614 +
3615 +               if (vfs_fl & S_IMMUTABLE)
3616 +                       new_fl |= EXT4_IMMUTABLE_FL;
3617 +               if (vfs_fl & S_IXUNLINK)
3618 +                       new_fl |= EXT4_IXUNLINK_FL;
3619 +
3620                 if (vfs_fl & S_SYNC)
3621                         new_fl |= EXT4_SYNC_FL;
3622                 if (vfs_fl & S_APPEND)
3623                         new_fl |= EXT4_APPEND_FL;
3624 -               if (vfs_fl & S_IMMUTABLE)
3625 -                       new_fl |= EXT4_IMMUTABLE_FL;
3626                 if (vfs_fl & S_NOATIME)
3627                         new_fl |= EXT4_NOATIME_FL;
3628                 if (vfs_fl & S_DIRSYNC)
3629                         new_fl |= EXT4_DIRSYNC_FL;
3630 +
3631 +               if (vflags & V_BARRIER)
3632 +                       new_fl |= EXT4_BARRIER_FL;
3633 +               if (vflags & V_COW)
3634 +                       new_fl |= EXT4_COW_FL;
3635         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3636  }
3637  
3638 @@ -4869,6 +4893,8 @@ struct inode *ext4_iget(struct super_blo
3639         journal_t *journal = EXT4_SB(sb)->s_journal;
3640         long ret;
3641         int block;
3642 +       uid_t uid;
3643 +       gid_t gid;
3644  
3645         inode = iget_locked(sb, ino);
3646         if (!inode)
3647 @@ -4884,12 +4910,16 @@ struct inode *ext4_iget(struct super_blo
3648                 goto bad_inode;
3649         raw_inode = ext4_raw_inode(&iloc);
3650         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3651 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3652 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3653 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3654 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3655         if (!(test_opt(inode->i_sb, NO_UID32))) {
3656 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3657 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3658 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3659 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3660         }
3661 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3662 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3663 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3664 +               le16_to_cpu(raw_inode->i_raw_tag));
3665         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3666  
3667         ei->i_state_flags = 0;
3668 @@ -5111,6 +5141,8 @@ static int ext4_do_update_inode(handle_t
3669         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
3670         struct ext4_inode_info *ei = EXT4_I(inode);
3671         struct buffer_head *bh = iloc->bh;
3672 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3673 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3674         int err = 0, rc, block;
3675  
3676         /* For fields not not tracking in the in-memory inode,
3677 @@ -5121,29 +5153,32 @@ static int ext4_do_update_inode(handle_t
3678         ext4_get_inode_flags(ei);
3679         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3680         if (!(test_opt(inode->i_sb, NO_UID32))) {
3681 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3682 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3683 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3684 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3685  /*
3686   * Fix up interoperability with old kernels. Otherwise, old inodes get
3687   * re-used with the upper 16 bits of the uid/gid intact
3688   */
3689                 if (!ei->i_dtime) {
3690                         raw_inode->i_uid_high =
3691 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3692 +                               cpu_to_le16(high_16_bits(uid));
3693                         raw_inode->i_gid_high =
3694 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3695 +                               cpu_to_le16(high_16_bits(gid));
3696                 } else {
3697                         raw_inode->i_uid_high = 0;
3698                         raw_inode->i_gid_high = 0;
3699                 }
3700         } else {
3701                 raw_inode->i_uid_low =
3702 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3703 +                       cpu_to_le16(fs_high2lowuid(uid));
3704                 raw_inode->i_gid_low =
3705 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3706 +                       cpu_to_le16(fs_high2lowgid(gid));
3707                 raw_inode->i_uid_high = 0;
3708                 raw_inode->i_gid_high = 0;
3709         }
3710 +#ifdef CONFIG_TAGGING_INTERN
3711 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3712 +#endif
3713         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3714  
3715         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3716 @@ -5329,7 +5364,8 @@ int ext4_setattr(struct dentry *dentry, 
3717                 return error;
3718  
3719         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3720 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3721 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3722 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3723                 handle_t *handle;
3724  
3725                 /* (user+group)*(old+new) structure, inode write (sb,
3726 @@ -5351,6 +5387,8 @@ int ext4_setattr(struct dentry *dentry, 
3727                         inode->i_uid = attr->ia_uid;
3728                 if (attr->ia_valid & ATTR_GID)
3729                         inode->i_gid = attr->ia_gid;
3730 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3731 +                       inode->i_tag = attr->ia_tag;
3732                 error = ext4_mark_inode_dirty(handle, inode);
3733                 ext4_journal_stop(handle);
3734         }
3735 diff -NurpP --minimal linux-2.6.32.56/fs/ext4/ioctl.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext4/ioctl.c
3736 --- linux-2.6.32.56/fs/ext4/ioctl.c     2012-02-09 10:22:30.000000000 +0100
3737 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext4/ioctl.c     2011-06-10 13:03:02.000000000 +0200
3738 @@ -14,10 +14,39 @@
3739  #include <linux/compat.h>
3740  #include <linux/mount.h>
3741  #include <linux/file.h>
3742 +#include <linux/vs_tag.h>
3743  #include <asm/uaccess.h>
3744  #include "ext4_jbd2.h"
3745  #include "ext4.h"
3746  
3747 +
3748 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3749 +{
3750 +       handle_t *handle = NULL;
3751 +       struct ext4_iloc iloc;
3752 +       int err;
3753 +
3754 +       handle = ext4_journal_start(inode, 1);
3755 +       if (IS_ERR(handle))
3756 +               return PTR_ERR(handle);
3757 +
3758 +       if (IS_SYNC(inode))
3759 +               ext4_handle_sync(handle);
3760 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3761 +       if (err)
3762 +               goto flags_err;
3763 +
3764 +       inode->i_flags = flags;
3765 +       inode->i_vflags = vflags;
3766 +       ext4_get_inode_flags(EXT4_I(inode));
3767 +       inode->i_ctime = ext4_current_time(inode);
3768 +
3769 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3770 +flags_err:
3771 +       ext4_journal_stop(handle);
3772 +       return err;
3773 +}
3774 +
3775  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3776  {
3777         struct inode *inode = filp->f_dentry->d_inode;
3778 @@ -50,6 +79,11 @@ long ext4_ioctl(struct file *filp, unsig
3779  
3780                 flags = ext4_mask_flags(inode->i_mode, flags);
3781  
3782 +               if (IS_BARRIER(inode)) {
3783 +                       vxwprintk_task(1, "messing with the barrier.");
3784 +                       return -EACCES;
3785 +               }
3786 +
3787                 err = -EPERM;
3788                 mutex_lock(&inode->i_mutex);
3789                 /* Is it quota file? Do not allow user to mess with it */
3790 @@ -67,7 +101,9 @@ long ext4_ioctl(struct file *filp, unsig
3791                  *
3792                  * This test looks nicer. Thanks to Pauline Middelink
3793                  */
3794 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3795 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3796 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3797 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3798                         if (!capable(CAP_LINUX_IMMUTABLE))
3799                                 goto flags_out;
3800                 }
3801 diff -NurpP --minimal linux-2.6.32.56/fs/ext4/namei.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext4/namei.c
3802 --- linux-2.6.32.56/fs/ext4/namei.c     2012-02-09 10:22:30.000000000 +0100
3803 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext4/namei.c     2011-06-10 13:03:02.000000000 +0200
3804 @@ -34,6 +34,7 @@
3805  #include <linux/quotaops.h>
3806  #include <linux/buffer_head.h>
3807  #include <linux/bio.h>
3808 +#include <linux/vs_tag.h>
3809  #include "ext4.h"
3810  #include "ext4_jbd2.h"
3811  
3812 @@ -941,6 +942,7 @@ restart:
3813                                 if (bh)
3814                                         ll_rw_block(READ_META, 1, &bh);
3815                         }
3816 +               dx_propagate_tag(nd, inode);
3817                 }
3818                 if ((bh = bh_use[ra_ptr++]) == NULL)
3819                         goto next;
3820 @@ -2543,6 +2545,7 @@ const struct inode_operations ext4_dir_i
3821  #endif
3822         .check_acl      = ext4_check_acl,
3823         .fiemap         = ext4_fiemap,
3824 +       .sync_flags     = ext4_sync_flags,
3825  };
3826  
3827  const struct inode_operations ext4_special_inode_operations = {
3828 diff -NurpP --minimal linux-2.6.32.56/fs/ext4/super.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext4/super.c
3829 --- linux-2.6.32.56/fs/ext4/super.c     2012-02-09 10:22:30.000000000 +0100
3830 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/ext4/super.c     2012-02-09 10:33:19.000000000 +0100
3831 @@ -1100,6 +1100,7 @@ enum {
3832         Opt_block_validity, Opt_noblock_validity,
3833         Opt_inode_readahead_blks, Opt_journal_ioprio,
3834         Opt_discard, Opt_nodiscard,
3835 +       Opt_tag, Opt_notag, Opt_tagid
3836  };
3837  
3838  static const match_table_t tokens = {
3839 @@ -1167,6 +1168,9 @@ static const match_table_t tokens = {
3840         {Opt_noauto_da_alloc, "noauto_da_alloc"},
3841         {Opt_discard, "discard"},
3842         {Opt_nodiscard, "nodiscard"},
3843 +       {Opt_tag, "tag"},
3844 +       {Opt_notag, "notag"},
3845 +       {Opt_tagid, "tagid=%u"},
3846         {Opt_err, NULL},
3847  };
3848  
3849 @@ -1269,6 +1273,20 @@ static int parse_options(char *options, 
3850                 case Opt_nouid32:
3851                         set_opt(sbi->s_mount_opt, NO_UID32);
3852                         break;
3853 +#ifndef CONFIG_TAGGING_NONE
3854 +               case Opt_tag:
3855 +                       set_opt (sbi->s_mount_opt, TAGGED);
3856 +                       break;
3857 +               case Opt_notag:
3858 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3859 +                       break;
3860 +#endif
3861 +#ifdef CONFIG_PROPAGATE
3862 +               case Opt_tagid:
3863 +                       /* use args[0] */
3864 +                       set_opt (sbi->s_mount_opt, TAGGED);
3865 +                       break;
3866 +#endif
3867                 case Opt_debug:
3868                         set_opt(sbi->s_mount_opt, DEBUG);
3869                         break;
3870 @@ -2470,6 +2488,9 @@ static int ext4_fill_super(struct super_
3871                            &journal_ioprio, NULL, 0))
3872                 goto failed_mount;
3873  
3874 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3875 +               sb->s_flags |= MS_TAGGED;
3876 +
3877         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3878                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3879  
3880 @@ -3521,6 +3542,14 @@ static int ext4_remount(struct super_blo
3881         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3882                 ext4_abort(sb, __func__, "Abort forced by user");
3883  
3884 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3885 +               !(sb->s_flags & MS_TAGGED)) {
3886 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3887 +                       sb->s_id);
3888 +               err = -EINVAL;
3889 +               goto restore_opts;
3890 +       }
3891 +
3892         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3893                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3894  
3895 diff -NurpP --minimal linux-2.6.32.56/fs/fcntl.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/fcntl.c
3896 --- linux-2.6.32.56/fs/fcntl.c  2012-02-09 10:22:30.000000000 +0100
3897 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/fcntl.c  2011-06-10 13:03:02.000000000 +0200
3898 @@ -19,6 +19,7 @@
3899  #include <linux/signal.h>
3900  #include <linux/rcupdate.h>
3901  #include <linux/pid_namespace.h>
3902 +#include <linux/vs_limit.h>
3903  
3904  #include <asm/poll.h>
3905  #include <asm/siginfo.h>
3906 @@ -102,6 +103,8 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldf
3907  
3908         if (tofree)
3909                 filp_close(tofree, files);
3910 +       else
3911 +               vx_openfd_inc(newfd);   /* fd was unused */
3912  
3913         return newfd;
3914  
3915 @@ -426,6 +429,8 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd,
3916         filp = fget(fd);
3917         if (!filp)
3918                 goto out;
3919 +       if (!vx_files_avail(1))
3920 +               goto out;
3921  
3922         err = security_file_fcntl(filp, cmd, arg);
3923         if (err) {
3924 diff -NurpP --minimal linux-2.6.32.56/fs/file.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/file.c
3925 --- linux-2.6.32.56/fs/file.c   2009-12-03 20:02:51.000000000 +0100
3926 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/file.c   2011-06-10 13:03:02.000000000 +0200
3927 @@ -20,6 +20,7 @@
3928  #include <linux/spinlock.h>
3929  #include <linux/rcupdate.h>
3930  #include <linux/workqueue.h>
3931 +#include <linux/vs_limit.h>
3932  
3933  struct fdtable_defer {
3934         spinlock_t lock;
3935 @@ -368,6 +369,8 @@ struct files_struct *dup_fd(struct files
3936                 struct file *f = *old_fds++;
3937                 if (f) {
3938                         get_file(f);
3939 +                       /* TODO: sum it first for check and performance */
3940 +                       vx_openfd_inc(open_files - i);
3941                 } else {
3942                         /*
3943                          * The fd may be claimed in the fd bitmap but not yet
3944 @@ -476,6 +479,7 @@ repeat:
3945         else
3946                 FD_CLR(fd, fdt->close_on_exec);
3947         error = fd;
3948 +       vx_openfd_inc(fd);
3949  #if 1
3950         /* Sanity check */
3951         if (rcu_dereference(fdt->fd[fd]) != NULL) {
3952 diff -NurpP --minimal linux-2.6.32.56/fs/file_table.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/file_table.c
3953 --- linux-2.6.32.56/fs/file_table.c     2012-02-09 10:22:30.000000000 +0100
3954 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/file_table.c     2011-06-10 13:03:02.000000000 +0200
3955 @@ -22,6 +22,8 @@
3956  #include <linux/fsnotify.h>
3957  #include <linux/sysctl.h>
3958  #include <linux/percpu_counter.h>
3959 +#include <linux/vs_limit.h>
3960 +#include <linux/vs_context.h>
3961  
3962  #include <asm/atomic.h>
3963  
3964 @@ -131,6 +133,8 @@ struct file *get_empty_filp(void)
3965         spin_lock_init(&f->f_lock);
3966         eventpoll_init_file(f);
3967         /* f->f_version: 0 */
3968 +       f->f_xid = vx_current_xid();
3969 +       vx_files_inc(f);
3970         return f;
3971  
3972  over:
3973 @@ -285,6 +289,8 @@ void __fput(struct file *file)
3974                 cdev_put(inode->i_cdev);
3975         fops_put(file->f_op);
3976         put_pid(file->f_owner.pid);
3977 +       vx_files_dec(file);
3978 +       file->f_xid = 0;
3979         file_kill(file);
3980         if (file->f_mode & FMODE_WRITE)
3981                 drop_file_write_access(file);
3982 @@ -352,6 +358,8 @@ void put_filp(struct file *file)
3983  {
3984         if (atomic_long_dec_and_test(&file->f_count)) {
3985                 security_file_free(file);
3986 +               vx_files_dec(file);
3987 +               file->f_xid = 0;
3988                 file_kill(file);
3989                 file_free(file);
3990         }
3991 diff -NurpP --minimal linux-2.6.32.56/fs/fs_struct.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/fs_struct.c
3992 --- linux-2.6.32.56/fs/fs_struct.c      2009-06-11 17:13:04.000000000 +0200
3993 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/fs_struct.c      2011-06-10 13:03:02.000000000 +0200
3994 @@ -4,6 +4,7 @@
3995  #include <linux/path.h>
3996  #include <linux/slab.h>
3997  #include <linux/fs_struct.h>
3998 +#include <linux/vserver/global.h>
3999  
4000  /*
4001   * Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values.
4002 @@ -77,6 +78,7 @@ void free_fs_struct(struct fs_struct *fs
4003  {
4004         path_put(&fs->root);
4005         path_put(&fs->pwd);
4006 +       atomic_dec(&vs_global_fs);
4007         kmem_cache_free(fs_cachep, fs);
4008  }
4009  
4010 @@ -112,6 +114,7 @@ struct fs_struct *copy_fs_struct(struct 
4011                 fs->pwd = old->pwd;
4012                 path_get(&old->pwd);
4013                 read_unlock(&old->lock);
4014 +               atomic_inc(&vs_global_fs);
4015         }
4016         return fs;
4017  }
4018 diff -NurpP --minimal linux-2.6.32.56/fs/gfs2/file.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/gfs2/file.c
4019 --- linux-2.6.32.56/fs/gfs2/file.c      2012-02-09 10:22:30.000000000 +0100
4020 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/gfs2/file.c      2011-06-10 13:03:02.000000000 +0200
4021 @@ -132,6 +132,9 @@ static const u32 fsflags_to_gfs2[32] = {
4022         [7] = GFS2_DIF_NOATIME,
4023         [12] = GFS2_DIF_EXHASH,
4024         [14] = GFS2_DIF_INHERIT_JDATA,
4025 +       [27] = GFS2_DIF_IXUNLINK,
4026 +       [26] = GFS2_DIF_BARRIER,
4027 +       [29] = GFS2_DIF_COW,
4028  };
4029  
4030  static const u32 gfs2_to_fsflags[32] = {
4031 @@ -141,6 +144,9 @@ static const u32 gfs2_to_fsflags[32] = {
4032         [gfs2fl_NoAtime] = FS_NOATIME_FL,
4033         [gfs2fl_ExHash] = FS_INDEX_FL,
4034         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
4035 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
4036 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
4037 +       [gfs2fl_Cow] = FS_COW_FL,
4038  };
4039  
4040  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
4041 @@ -171,10 +177,16 @@ void gfs2_set_inode_flags(struct inode *
4042  {
4043         struct gfs2_inode *ip = GFS2_I(inode);
4044         unsigned int flags = inode->i_flags;
4045 +       unsigned int vflags = inode->i_vflags;
4046 +
4047 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4048 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4049  
4050 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
4051         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
4052                 flags |= S_IMMUTABLE;
4053 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
4054 +               flags |= S_IXUNLINK;
4055 +
4056         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
4057                 flags |= S_APPEND;
4058         if (ip->i_diskflags & GFS2_DIF_NOATIME)
4059 @@ -182,6 +194,43 @@ void gfs2_set_inode_flags(struct inode *
4060         if (ip->i_diskflags & GFS2_DIF_SYNC)
4061                 flags |= S_SYNC;
4062         inode->i_flags = flags;
4063 +
4064 +       vflags &= ~(V_BARRIER | V_COW);
4065 +
4066 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
4067 +               vflags |= V_BARRIER;
4068 +       if (ip->i_diskflags & GFS2_DIF_COW)
4069 +               vflags |= V_COW;
4070 +       inode->i_vflags = vflags;
4071 +}
4072 +
4073 +void gfs2_get_inode_flags(struct inode *inode)
4074 +{
4075 +       struct gfs2_inode *ip = GFS2_I(inode);
4076 +       unsigned int flags = inode->i_flags;
4077 +       unsigned int vflags = inode->i_vflags;
4078 +
4079 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
4080 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
4081 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
4082 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
4083 +
4084 +       if (flags & S_IMMUTABLE)
4085 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
4086 +       if (flags & S_IXUNLINK)
4087 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
4088 +
4089 +       if (flags & S_APPEND)
4090 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
4091 +       if (flags & S_NOATIME)
4092 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
4093 +       if (flags & S_SYNC)
4094 +               ip->i_diskflags |= GFS2_DIF_SYNC;
4095 +
4096 +       if (vflags & V_BARRIER)
4097 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
4098 +       if (vflags & V_COW)
4099 +               ip->i_diskflags |= GFS2_DIF_COW;
4100  }
4101  
4102  /* Flags that can be set by user space */
4103 @@ -293,6 +342,37 @@ static int gfs2_set_flags(struct file *f
4104         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
4105  }
4106  
4107 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
4108 +{
4109 +       struct gfs2_inode *ip = GFS2_I(inode);
4110 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
4111 +       struct buffer_head *bh;
4112 +       struct gfs2_holder gh;
4113 +       int error;
4114 +
4115 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
4116 +       if (error)
4117 +               return error;
4118 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
4119 +       if (error)
4120 +               goto out;
4121 +       error = gfs2_meta_inode_buffer(ip, &bh);
4122 +       if (error)
4123 +               goto out_trans_end;
4124 +       gfs2_trans_add_bh(ip->i_gl, bh, 1);
4125 +       inode->i_flags = flags;
4126 +       inode->i_vflags = vflags;
4127 +       gfs2_get_inode_flags(inode);
4128 +       gfs2_dinode_out(ip, bh->b_data);
4129 +       brelse(bh);
4130 +       gfs2_set_aops(inode);
4131 +out_trans_end:
4132 +       gfs2_trans_end(sdp);
4133 +out:
4134 +       gfs2_glock_dq_uninit(&gh);
4135 +       return error;
4136 +}
4137 +
4138  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4139  {
4140         switch(cmd) {
4141 diff -NurpP --minimal linux-2.6.32.56/fs/gfs2/inode.h linux-2.6.32.56-vs2.3.0.36.29.9/fs/gfs2/inode.h
4142 --- linux-2.6.32.56/fs/gfs2/inode.h     2009-09-10 15:26:22.000000000 +0200
4143 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/gfs2/inode.h     2011-06-10 13:03:02.000000000 +0200
4144 @@ -109,6 +109,7 @@ extern const struct file_operations gfs2
4145  extern const struct file_operations gfs2_dir_fops_nolock;
4146  
4147  extern void gfs2_set_inode_flags(struct inode *inode);
4148 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
4149   
4150  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
4151  extern const struct file_operations gfs2_file_fops;
4152 diff -NurpP --minimal linux-2.6.32.56/fs/gfs2/ops_inode.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/gfs2/ops_inode.c
4153 --- linux-2.6.32.56/fs/gfs2/ops_inode.c 2009-12-03 20:02:52.000000000 +0100
4154 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/gfs2/ops_inode.c 2011-06-10 13:03:02.000000000 +0200
4155 @@ -1400,6 +1400,7 @@ const struct inode_operations gfs2_file_
4156         .listxattr = gfs2_listxattr,
4157         .removexattr = gfs2_removexattr,
4158         .fiemap = gfs2_fiemap,
4159 +       .sync_flags = gfs2_sync_flags,
4160  };
4161  
4162  const struct inode_operations gfs2_dir_iops = {
4163 @@ -1420,6 +1421,7 @@ const struct inode_operations gfs2_dir_i
4164         .listxattr = gfs2_listxattr,
4165         .removexattr = gfs2_removexattr,
4166         .fiemap = gfs2_fiemap,
4167 +       .sync_flags = gfs2_sync_flags,
4168  };
4169  
4170  const struct inode_operations gfs2_symlink_iops = {
4171 diff -NurpP --minimal linux-2.6.32.56/fs/hfsplus/ioctl.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/hfsplus/ioctl.c
4172 --- linux-2.6.32.56/fs/hfsplus/ioctl.c  2008-12-25 00:26:37.000000000 +0100
4173 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/hfsplus/ioctl.c  2011-06-10 13:03:02.000000000 +0200
4174 @@ -17,6 +17,7 @@
4175  #include <linux/mount.h>
4176  #include <linux/sched.h>
4177  #include <linux/xattr.h>
4178 +#include <linux/mount.h>
4179  #include <asm/uaccess.h>
4180  #include "hfsplus_fs.h"
4181  
4182 diff -NurpP --minimal linux-2.6.32.56/fs/inode.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/inode.c
4183 --- linux-2.6.32.56/fs/inode.c  2012-02-09 10:22:30.000000000 +0100
4184 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/inode.c  2011-08-08 22:40:36.000000000 +0200
4185 @@ -133,6 +133,9 @@ int inode_init_always(struct super_block
4186         struct address_space *const mapping = &inode->i_data;
4187  
4188         inode->i_sb = sb;
4189 +
4190 +       /* essential because of inode slab reuse */
4191 +       inode->i_tag = 0;
4192         inode->i_blkbits = sb->s_blocksize_bits;
4193         inode->i_flags = 0;
4194         atomic_set(&inode->i_count, 1);
4195 @@ -153,6 +156,7 @@ int inode_init_always(struct super_block
4196         inode->i_bdev = NULL;
4197         inode->i_cdev = NULL;
4198         inode->i_rdev = 0;
4199 +       inode->i_mdev = 0;
4200         inode->dirtied_when = 0;
4201  
4202         if (security_inode_alloc(inode))
4203 @@ -315,6 +319,8 @@ void __iget(struct inode *inode)
4204         inodes_stat.nr_unused--;
4205  }
4206  
4207 +EXPORT_SYMBOL_GPL(__iget);
4208 +
4209  /**
4210   * clear_inode - clear an inode
4211   * @inode: inode to clear
4212 @@ -1619,9 +1625,11 @@ void init_special_inode(struct inode *in
4213         if (S_ISCHR(mode)) {
4214                 inode->i_fop = &def_chr_fops;
4215                 inode->i_rdev = rdev;
4216 +               inode->i_mdev = rdev;
4217         } else if (S_ISBLK(mode)) {
4218                 inode->i_fop = &def_blk_fops;
4219                 inode->i_rdev = rdev;
4220 +               inode->i_mdev = rdev;
4221         } else if (S_ISFIFO(mode))
4222                 inode->i_fop = &def_fifo_fops;
4223         else if (S_ISSOCK(mode))
4224 diff -NurpP --minimal linux-2.6.32.56/fs/ioctl.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/ioctl.c
4225 --- linux-2.6.32.56/fs/ioctl.c  2009-12-03 20:02:52.000000000 +0100
4226 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/ioctl.c  2011-06-10 13:03:02.000000000 +0200
4227 @@ -16,6 +16,9 @@
4228  #include <linux/writeback.h>
4229  #include <linux/buffer_head.h>
4230  #include <linux/falloc.h>
4231 +#include <linux/proc_fs.h>
4232 +#include <linux/vserver/inode.h>
4233 +#include <linux/vs_tag.h>
4234  
4235  #include <asm/ioctls.h>
4236  
4237 diff -NurpP --minimal linux-2.6.32.56/fs/ioprio.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/ioprio.c
4238 --- linux-2.6.32.56/fs/ioprio.c 2009-03-24 14:22:26.000000000 +0100
4239 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/ioprio.c 2011-06-10 13:03:02.000000000 +0200
4240 @@ -26,6 +26,7 @@
4241  #include <linux/syscalls.h>
4242  #include <linux/security.h>
4243  #include <linux/pid_namespace.h>
4244 +#include <linux/vs_base.h>
4245  
4246  int set_task_ioprio(struct task_struct *task, int ioprio)
4247  {
4248 @@ -123,6 +124,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which, 
4249                         else
4250                                 pgrp = find_vpid(who);
4251                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
4252 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4253 +                                       continue;
4254                                 ret = set_task_ioprio(p, ioprio);
4255                                 if (ret)
4256                                         break;
4257 @@ -212,6 +215,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which, 
4258                         else
4259                                 pgrp = find_vpid(who);
4260                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
4261 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4262 +                                       continue;
4263                                 tmpio = get_task_ioprio(p);
4264                                 if (tmpio < 0)
4265                                         continue;
4266 diff -NurpP --minimal linux-2.6.32.56/fs/jfs/acl.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/jfs/acl.c
4267 --- linux-2.6.32.56/fs/jfs/acl.c        2009-12-03 20:02:52.000000000 +0100
4268 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/jfs/acl.c        2011-06-10 13:03:02.000000000 +0200
4269 @@ -216,7 +216,8 @@ int jfs_setattr(struct dentry *dentry, s
4270                 return rc;
4271  
4272         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
4273 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
4274 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
4275 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
4276                 if (vfs_dq_transfer(inode, iattr))
4277                         return -EDQUOT;
4278         }
4279 diff -NurpP --minimal linux-2.6.32.56/fs/jfs/file.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/jfs/file.c
4280 --- linux-2.6.32.56/fs/jfs/file.c       2009-12-03 20:02:52.000000000 +0100
4281 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/jfs/file.c       2011-06-10 13:03:02.000000000 +0200
4282 @@ -98,6 +98,7 @@ const struct inode_operations jfs_file_i
4283         .setattr        = jfs_setattr,
4284         .check_acl      = jfs_check_acl,
4285  #endif
4286 +       .sync_flags     = jfs_sync_flags,
4287  };
4288  
4289  const struct file_operations jfs_file_operations = {
4290 diff -NurpP --minimal linux-2.6.32.56/fs/jfs/ioctl.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/jfs/ioctl.c
4291 --- linux-2.6.32.56/fs/jfs/ioctl.c      2008-12-25 00:26:37.000000000 +0100
4292 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/jfs/ioctl.c      2011-06-10 13:03:02.000000000 +0200
4293 @@ -11,6 +11,7 @@
4294  #include <linux/mount.h>
4295  #include <linux/time.h>
4296  #include <linux/sched.h>
4297 +#include <linux/mount.h>
4298  #include <asm/current.h>
4299  #include <asm/uaccess.h>
4300  
4301 @@ -52,6 +53,16 @@ static long jfs_map_ext2(unsigned long f
4302  }
4303  
4304  
4305 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
4306 +{
4307 +       inode->i_flags = flags;
4308 +       inode->i_vflags = vflags;
4309 +       jfs_get_inode_flags(JFS_IP(inode));
4310 +       inode->i_ctime = CURRENT_TIME_SEC;
4311 +       mark_inode_dirty(inode);
4312 +       return 0;
4313 +}
4314 +
4315  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4316  {
4317         struct inode *inode = filp->f_dentry->d_inode;
4318 @@ -85,6 +96,11 @@ long jfs_ioctl(struct file *filp, unsign
4319                 if (!S_ISDIR(inode->i_mode))
4320                         flags &= ~JFS_DIRSYNC_FL;
4321  
4322 +               if (IS_BARRIER(inode)) {
4323 +                       vxwprintk_task(1, "messing with the barrier.");
4324 +                       return -EACCES;
4325 +               }
4326 +
4327                 /* Is it quota file? Do not allow user to mess with it */
4328                 if (IS_NOQUOTA(inode)) {
4329                         err = -EPERM;
4330 @@ -102,8 +118,8 @@ long jfs_ioctl(struct file *filp, unsign
4331                  * the relevant capability.
4332                  */
4333                 if ((oldflags & JFS_IMMUTABLE_FL) ||
4334 -                       ((flags ^ oldflags) &
4335 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
4336 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
4337 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
4338                         if (!capable(CAP_LINUX_IMMUTABLE)) {
4339                                 mutex_unlock(&inode->i_mutex);
4340                                 err = -EPERM;
4341 @@ -111,7 +127,7 @@ long jfs_ioctl(struct file *filp, unsign
4342                         }
4343                 }
4344  
4345 -               flags = flags & JFS_FL_USER_MODIFIABLE;
4346 +               flags &= JFS_FL_USER_MODIFIABLE;
4347                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
4348                 jfs_inode->mode2 = flags;
4349  
4350 diff -NurpP --minimal linux-2.6.32.56/fs/jfs/jfs_dinode.h linux-2.6.32.56-vs2.3.0.36.29.9/fs/jfs/jfs_dinode.h
4351 --- linux-2.6.32.56/fs/jfs/jfs_dinode.h 2008-12-25 00:26:37.000000000 +0100
4352 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/jfs/jfs_dinode.h 2011-06-10 13:03:02.000000000 +0200
4353 @@ -161,9 +161,13 @@ struct dinode {
4354  
4355  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
4356  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
4357 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
4358  
4359 -#define JFS_FL_USER_VISIBLE    0x03F80000
4360 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
4361 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
4362 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
4363 +
4364 +#define JFS_FL_USER_VISIBLE    0x07F80000
4365 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
4366  #define JFS_FL_INHERIT         0x03C80000
4367  
4368  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
4369 diff -NurpP --minimal linux-2.6.32.56/fs/jfs/jfs_filsys.h linux-2.6.32.56-vs2.3.0.36.29.9/fs/jfs/jfs_filsys.h
4370 --- linux-2.6.32.56/fs/jfs/jfs_filsys.h 2008-12-25 00:26:37.000000000 +0100
4371 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/jfs/jfs_filsys.h 2011-06-10 13:03:02.000000000 +0200
4372 @@ -263,6 +263,7 @@
4373  #define JFS_NAME_MAX   255
4374  #define JFS_PATH_MAX   BPSIZE
4375  
4376 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
4377  
4378  /*
4379   *     file system state (superblock state)
4380 diff -NurpP --minimal linux-2.6.32.56/fs/jfs/jfs_imap.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/jfs/jfs_imap.c
4381 --- linux-2.6.32.56/fs/jfs/jfs_imap.c   2009-09-10 15:26:22.000000000 +0200
4382 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/jfs/jfs_imap.c   2011-06-10 13:03:02.000000000 +0200
4383 @@ -45,6 +45,7 @@
4384  #include <linux/buffer_head.h>
4385  #include <linux/pagemap.h>
4386  #include <linux/quotaops.h>
4387 +#include <linux/vs_tag.h>
4388  
4389  #include "jfs_incore.h"
4390  #include "jfs_inode.h"
4391 @@ -3059,6 +3060,8 @@ static int copy_from_dinode(struct dinod
4392  {
4393         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
4394         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
4395 +       uid_t uid;
4396 +       gid_t gid;
4397  
4398         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
4399         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
4400 @@ -3079,14 +3082,18 @@ static int copy_from_dinode(struct dinod
4401         }
4402         ip->i_nlink = le32_to_cpu(dip->di_nlink);
4403  
4404 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
4405 +       uid = le32_to_cpu(dip->di_uid);
4406 +       gid = le32_to_cpu(dip->di_gid);
4407 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
4408 +
4409 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
4410         if (sbi->uid == -1)
4411                 ip->i_uid = jfs_ip->saved_uid;
4412         else {
4413                 ip->i_uid = sbi->uid;
4414         }
4415  
4416 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
4417 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
4418         if (sbi->gid == -1)
4419                 ip->i_gid = jfs_ip->saved_gid;
4420         else {
4421 @@ -3151,14 +3158,12 @@ static void copy_to_dinode(struct dinode
4422         dip->di_size = cpu_to_le64(ip->i_size);
4423         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
4424         dip->di_nlink = cpu_to_le32(ip->i_nlink);
4425 -       if (sbi->uid == -1)
4426 -               dip->di_uid = cpu_to_le32(ip->i_uid);
4427 -       else
4428 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
4429 -       if (sbi->gid == -1)
4430 -               dip->di_gid = cpu_to_le32(ip->i_gid);
4431 -       else
4432 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
4433 +
4434 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
4435 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
4436 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
4437 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
4438 +
4439         jfs_get_inode_flags(jfs_ip);
4440         /*
4441          * mode2 is only needed for storing the higher order bits.
4442 diff -NurpP --minimal linux-2.6.32.56/fs/jfs/jfs_inode.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/jfs/jfs_inode.c
4443 --- linux-2.6.32.56/fs/jfs/jfs_inode.c  2009-06-11 17:13:05.000000000 +0200
4444 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/jfs/jfs_inode.c  2011-06-10 13:03:02.000000000 +0200
4445 @@ -18,6 +18,7 @@
4446  
4447  #include <linux/fs.h>
4448  #include <linux/quotaops.h>
4449 +#include <linux/vs_tag.h>
4450  #include "jfs_incore.h"
4451  #include "jfs_inode.h"
4452  #include "jfs_filsys.h"
4453 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
4454  {
4455         unsigned int flags = JFS_IP(inode)->mode2;
4456  
4457 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
4458 -               S_NOATIME | S_DIRSYNC | S_SYNC);
4459 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4460 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4461  
4462         if (flags & JFS_IMMUTABLE_FL)
4463                 inode->i_flags |= S_IMMUTABLE;
4464 +       if (flags & JFS_IXUNLINK_FL)
4465 +               inode->i_flags |= S_IXUNLINK;
4466 +
4467 +       if (flags & JFS_SYNC_FL)
4468 +               inode->i_flags |= S_SYNC;
4469         if (flags & JFS_APPEND_FL)
4470                 inode->i_flags |= S_APPEND;
4471         if (flags & JFS_NOATIME_FL)
4472                 inode->i_flags |= S_NOATIME;
4473         if (flags & JFS_DIRSYNC_FL)
4474                 inode->i_flags |= S_DIRSYNC;
4475 -       if (flags & JFS_SYNC_FL)
4476 -               inode->i_flags |= S_SYNC;
4477 +
4478 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
4479 +
4480 +       if (flags & JFS_BARRIER_FL)
4481 +               inode->i_vflags |= V_BARRIER;
4482 +       if (flags & JFS_COW_FL)
4483 +               inode->i_vflags |= V_COW;
4484  }
4485  
4486  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
4487  {
4488         unsigned int flags = jfs_ip->vfs_inode.i_flags;
4489 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
4490 +
4491 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
4492 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
4493 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
4494 +                          JFS_BARRIER_FL | JFS_COW_FL);
4495  
4496 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
4497 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
4498         if (flags & S_IMMUTABLE)
4499                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
4500 +       if (flags & S_IXUNLINK)
4501 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
4502 +
4503         if (flags & S_APPEND)
4504                 jfs_ip->mode2 |= JFS_APPEND_FL;
4505         if (flags & S_NOATIME)
4506 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
4507                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
4508         if (flags & S_SYNC)
4509                 jfs_ip->mode2 |= JFS_SYNC_FL;
4510 +
4511 +       if (vflags & V_BARRIER)
4512 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
4513 +       if (vflags & V_COW)
4514 +               jfs_ip->mode2 |= JFS_COW_FL;
4515  }
4516  
4517  /*
4518 @@ -105,6 +128,7 @@ struct inode *ialloc(struct inode *paren
4519                         mode |= S_ISGID;
4520         } else
4521                 inode->i_gid = current_fsgid();
4522 +       inode->i_tag = dx_current_fstag(sb);
4523  
4524         /*
4525          * New inodes need to save sane values on disk when
4526 diff -NurpP --minimal linux-2.6.32.56/fs/jfs/jfs_inode.h linux-2.6.32.56-vs2.3.0.36.29.9/fs/jfs/jfs_inode.h
4527 --- linux-2.6.32.56/fs/jfs/jfs_inode.h  2009-06-11 17:13:05.000000000 +0200
4528 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/jfs/jfs_inode.h  2011-06-10 13:03:02.000000000 +0200
4529 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
4530  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
4531         int fh_len, int fh_type);
4532  extern void jfs_set_inode_flags(struct inode *);
4533 +extern int jfs_sync_flags(struct inode *, int, int);
4534  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
4535  
4536  extern const struct address_space_operations jfs_aops;
4537 diff -NurpP --minimal linux-2.6.32.56/fs/jfs/namei.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/jfs/namei.c
4538 --- linux-2.6.32.56/fs/jfs/namei.c      2009-12-03 20:02:52.000000000 +0100
4539 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/jfs/namei.c      2011-06-10 13:03:02.000000000 +0200
4540 @@ -21,6 +21,7 @@
4541  #include <linux/ctype.h>
4542  #include <linux/quotaops.h>
4543  #include <linux/exportfs.h>
4544 +#include <linux/vs_tag.h>
4545  #include "jfs_incore.h"
4546  #include "jfs_superblock.h"
4547  #include "jfs_inode.h"
4548 @@ -1476,6 +1477,7 @@ static struct dentry *jfs_lookup(struct 
4549                 return ERR_CAST(ip);
4550         }
4551  
4552 +       dx_propagate_tag(nd, ip);
4553         dentry = d_splice_alias(ip, dentry);
4554  
4555         if (dentry && (JFS_SBI(dip->i_sb)->mntflag & JFS_OS2))
4556 @@ -1545,6 +1547,7 @@ const struct inode_operations jfs_dir_in
4557         .setattr        = jfs_setattr,
4558         .check_acl      = jfs_check_acl,
4559  #endif
4560 +       .sync_flags     = jfs_sync_flags,
4561  };
4562  
4563  const struct file_operations jfs_dir_operations = {
4564 diff -NurpP --minimal linux-2.6.32.56/fs/jfs/super.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/jfs/super.c
4565 --- linux-2.6.32.56/fs/jfs/super.c      2009-12-03 20:02:52.000000000 +0100
4566 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/jfs/super.c      2011-06-10 13:03:02.000000000 +0200
4567 @@ -192,7 +192,8 @@ static void jfs_put_super(struct super_b
4568  enum {
4569         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4570         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4571 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
4572 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4573 +       Opt_tag, Opt_notag, Opt_tagid
4574  };
4575  
4576  static const match_table_t tokens = {
4577 @@ -202,6 +203,10 @@ static const match_table_t tokens = {
4578         {Opt_resize, "resize=%u"},
4579         {Opt_resize_nosize, "resize"},
4580         {Opt_errors, "errors=%s"},
4581 +       {Opt_tag, "tag"},
4582 +       {Opt_notag, "notag"},
4583 +       {Opt_tagid, "tagid=%u"},
4584 +       {Opt_tag, "tagxid"},
4585         {Opt_ignore, "noquota"},
4586         {Opt_ignore, "quota"},
4587         {Opt_usrquota, "usrquota"},
4588 @@ -336,6 +341,20 @@ static int parse_options(char *options, 
4589                         }
4590                         break;
4591                 }
4592 +#ifndef CONFIG_TAGGING_NONE
4593 +               case Opt_tag:
4594 +                       *flag |= JFS_TAGGED;
4595 +                       break;
4596 +               case Opt_notag:
4597 +                       *flag &= JFS_TAGGED;
4598 +                       break;
4599 +#endif
4600 +#ifdef CONFIG_PROPAGATE
4601 +               case Opt_tagid:
4602 +                       /* use args[0] */
4603 +                       *flag |= JFS_TAGGED;
4604 +                       break;
4605 +#endif
4606                 default:
4607                         printk("jfs: Unrecognized mount option \"%s\" "
4608                                         " or missing value\n", p);
4609 @@ -366,6 +385,12 @@ static int jfs_remount(struct super_bloc
4610         if (!parse_options(data, sb, &newLVSize, &flag)) {
4611                 return -EINVAL;
4612         }
4613 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4614 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4615 +                       sb->s_id);
4616 +               return -EINVAL;
4617 +       }
4618 +
4619         lock_kernel();
4620         if (newLVSize) {
4621                 if (sb->s_flags & MS_RDONLY) {
4622 @@ -449,6 +474,9 @@ static int jfs_fill_super(struct super_b
4623  #ifdef CONFIG_JFS_POSIX_ACL
4624         sb->s_flags |= MS_POSIXACL;
4625  #endif
4626 +       /* map mount option tagxid */
4627 +       if (sbi->flag & JFS_TAGGED)
4628 +               sb->s_flags |= MS_TAGGED;
4629  
4630         if (newLVSize) {
4631                 printk(KERN_ERR "resize option for remount only\n");
4632 diff -NurpP --minimal linux-2.6.32.56/fs/libfs.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/libfs.c
4633 --- linux-2.6.32.56/fs/libfs.c  2012-02-09 10:22:30.000000000 +0100
4634 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/libfs.c  2011-06-10 13:03:02.000000000 +0200
4635 @@ -127,7 +127,8 @@ static inline unsigned char dt_type(stru
4636   * both impossible due to the lock on directory.
4637   */
4638  
4639 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4640 +static inline int do_dcache_readdir_filter(struct file *filp,
4641 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4642  {
4643         struct dentry *dentry = filp->f_path.dentry;
4644         struct dentry *cursor = filp->private_data;
4645 @@ -160,6 +161,8 @@ int dcache_readdir(struct file * filp, v
4646                                 next = list_entry(p, struct dentry, d_u.d_child);
4647                                 if (d_unhashed(next) || !next->d_inode)
4648                                         continue;
4649 +                               if (filter && !filter(next))
4650 +                                       continue;
4651  
4652                                 spin_unlock(&dcache_lock);
4653                                 if (filldir(dirent, next->d_name.name, 
4654 @@ -178,6 +181,18 @@ int dcache_readdir(struct file * filp, v
4655         return 0;
4656  }
4657  
4658 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4659 +{
4660 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4661 +}
4662 +
4663 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4664 +       int (*filter)(struct dentry *))
4665 +{
4666 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4667 +}
4668 +
4669 +
4670  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4671  {
4672         return -EISDIR;
4673 @@ -842,6 +857,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4674  EXPORT_SYMBOL(dcache_dir_lseek);
4675  EXPORT_SYMBOL(dcache_dir_open);
4676  EXPORT_SYMBOL(dcache_readdir);
4677 +EXPORT_SYMBOL(dcache_readdir_filter);
4678  EXPORT_SYMBOL(generic_read_dir);
4679  EXPORT_SYMBOL(get_sb_pseudo);
4680  EXPORT_SYMBOL(simple_write_begin);
4681 diff -NurpP --minimal linux-2.6.32.56/fs/locks.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/locks.c
4682 --- linux-2.6.32.56/fs/locks.c  2009-12-03 20:02:52.000000000 +0100
4683 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/locks.c  2011-06-10 13:03:02.000000000 +0200
4684 @@ -127,6 +127,8 @@
4685  #include <linux/time.h>
4686  #include <linux/rcupdate.h>
4687  #include <linux/pid_namespace.h>
4688 +#include <linux/vs_base.h>
4689 +#include <linux/vs_limit.h>
4690  
4691  #include <asm/uaccess.h>
4692  
4693 @@ -148,6 +150,8 @@ static struct kmem_cache *filelock_cache
4694  /* Allocate an empty lock structure. */
4695  static struct file_lock *locks_alloc_lock(void)
4696  {
4697 +       if (!vx_locks_avail(1))
4698 +               return NULL;
4699         return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
4700  }
4701  
4702 @@ -174,6 +178,7 @@ static void locks_free_lock(struct file_
4703         BUG_ON(!list_empty(&fl->fl_block));
4704         BUG_ON(!list_empty(&fl->fl_link));
4705  
4706 +       vx_locks_dec(fl);
4707         locks_release_private(fl);
4708         kmem_cache_free(filelock_cache, fl);
4709  }
4710 @@ -194,6 +199,7 @@ void locks_init_lock(struct file_lock *f
4711         fl->fl_start = fl->fl_end = 0;
4712         fl->fl_ops = NULL;
4713         fl->fl_lmops = NULL;
4714 +       fl->fl_xid = -1;
4715  }
4716  
4717  EXPORT_SYMBOL(locks_init_lock);
4718 @@ -248,6 +254,7 @@ void locks_copy_lock(struct file_lock *n
4719         new->fl_file = fl->fl_file;
4720         new->fl_ops = fl->fl_ops;
4721         new->fl_lmops = fl->fl_lmops;
4722 +       new->fl_xid = fl->fl_xid;
4723  
4724         locks_copy_private(new, fl);
4725  }
4726 @@ -286,6 +293,11 @@ static int flock_make_lock(struct file *
4727         fl->fl_flags = FL_FLOCK;
4728         fl->fl_type = type;
4729         fl->fl_end = OFFSET_MAX;
4730 +
4731 +       vxd_assert(filp->f_xid == vx_current_xid(),
4732 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4733 +       fl->fl_xid = filp->f_xid;
4734 +       vx_locks_inc(fl);
4735         
4736         *lock = fl;
4737         return 0;
4738 @@ -451,6 +463,7 @@ static int lease_init(struct file *filp,
4739  
4740         fl->fl_owner = current->files;
4741         fl->fl_pid = current->tgid;
4742 +       fl->fl_xid = vx_current_xid();
4743  
4744         fl->fl_file = filp;
4745         fl->fl_flags = FL_LEASE;
4746 @@ -470,6 +483,11 @@ static struct file_lock *lease_alloc(str
4747         if (fl == NULL)
4748                 return ERR_PTR(error);
4749  
4750 +       fl->fl_xid = vx_current_xid();
4751 +       if (filp)
4752 +               vxd_assert(filp->f_xid == fl->fl_xid,
4753 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4754 +       vx_locks_inc(fl);
4755         error = lease_init(filp, type, fl);
4756         if (error) {
4757                 locks_free_lock(fl);
4758 @@ -770,6 +788,7 @@ static int flock_lock_file(struct file *
4759         if (found)
4760                 cond_resched();
4761  
4762 +       new_fl->fl_xid = -1;
4763  find_conflict:
4764         for_each_lock(inode, before) {
4765                 struct file_lock *fl = *before;
4766 @@ -790,6 +809,7 @@ find_conflict:
4767                 goto out;
4768         locks_copy_lock(new_fl, request);
4769         locks_insert_lock(before, new_fl);
4770 +       vx_locks_inc(new_fl);
4771         new_fl = NULL;
4772         error = 0;
4773  
4774 @@ -800,7 +820,8 @@ out:
4775         return error;
4776  }
4777  
4778 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4779 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4780 +       struct file_lock *conflock, xid_t xid)
4781  {
4782         struct file_lock *fl;
4783         struct file_lock *new_fl = NULL;
4784 @@ -810,6 +831,8 @@ static int __posix_lock_file(struct inod
4785         struct file_lock **before;
4786         int error, added = 0;
4787  
4788 +       vxd_assert(xid == vx_current_xid(),
4789 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4790         /*
4791          * We may need two file_lock structures for this operation,
4792          * so we get them in advance to avoid races.
4793 @@ -820,7 +843,11 @@ static int __posix_lock_file(struct inod
4794             (request->fl_type != F_UNLCK ||
4795              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4796                 new_fl = locks_alloc_lock();
4797 +               new_fl->fl_xid = xid;
4798 +               vx_locks_inc(new_fl);
4799                 new_fl2 = locks_alloc_lock();
4800 +               new_fl2->fl_xid = xid;
4801 +               vx_locks_inc(new_fl2);
4802         }
4803  
4804         lock_kernel();
4805 @@ -1019,7 +1046,8 @@ static int __posix_lock_file(struct inod
4806  int posix_lock_file(struct file *filp, struct file_lock *fl,
4807                         struct file_lock *conflock)
4808  {
4809 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
4810 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
4811 +               fl, conflock, filp->f_xid);
4812  }
4813  EXPORT_SYMBOL(posix_lock_file);
4814  
4815 @@ -1109,7 +1137,7 @@ int locks_mandatory_area(int read_write,
4816         fl.fl_end = offset + count - 1;
4817  
4818         for (;;) {
4819 -               error = __posix_lock_file(inode, &fl, NULL);
4820 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4821                 if (error != FILE_LOCK_DEFERRED)
4822                         break;
4823                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4824 @@ -1424,6 +1452,7 @@ int generic_setlease(struct file *filp, 
4825  
4826         locks_copy_lock(new_fl, lease);
4827         locks_insert_lock(before, new_fl);
4828 +       vx_locks_inc(new_fl);
4829  
4830         *flp = new_fl;
4831         return 0;
4832 @@ -1779,6 +1808,11 @@ int fcntl_setlk(unsigned int fd, struct 
4833         if (file_lock == NULL)
4834                 return -ENOLCK;
4835  
4836 +       vxd_assert(filp->f_xid == vx_current_xid(),
4837 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4838 +       file_lock->fl_xid = filp->f_xid;
4839 +       vx_locks_inc(file_lock);
4840 +
4841         /*
4842          * This might block, so we do it before checking the inode.
4843          */
4844 @@ -1897,6 +1931,11 @@ int fcntl_setlk64(unsigned int fd, struc
4845         if (file_lock == NULL)
4846                 return -ENOLCK;
4847  
4848 +       vxd_assert(filp->f_xid == vx_current_xid(),
4849 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4850 +       file_lock->fl_xid = filp->f_xid;
4851 +       vx_locks_inc(file_lock);
4852 +
4853         /*
4854          * This might block, so we do it before checking the inode.
4855          */
4856 @@ -2162,8 +2201,11 @@ static int locks_show(struct seq_file *f
4857  
4858         lock_get_status(f, fl, (long)f->private, "");
4859  
4860 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4861 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4862 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4863 +                       continue;
4864                 lock_get_status(f, bfl, (long)f->private, " ->");
4865 +       }
4866  
4867         f->private++;
4868         return 0;
4869 diff -NurpP --minimal linux-2.6.32.56/fs/namei.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/namei.c
4870 --- linux-2.6.32.56/fs/namei.c  2012-02-09 10:22:30.000000000 +0100
4871 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/namei.c  2011-06-10 18:44:08.000000000 +0200
4872 @@ -33,6 +33,14 @@
4873  #include <linux/fcntl.h>
4874  #include <linux/device_cgroup.h>
4875  #include <linux/fs_struct.h>
4876 +#include <linux/proc_fs.h>
4877 +#include <linux/vserver/inode.h>
4878 +#include <linux/vs_base.h>
4879 +#include <linux/vs_tag.h>
4880 +#include <linux/vs_cowbl.h>
4881 +#include <linux/vs_device.h>
4882 +#include <linux/vs_context.h>
4883 +#include <linux/pid_namespace.h>
4884  #include <asm/uaccess.h>
4885  
4886  #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
4887 @@ -169,6 +177,77 @@ void putname(const char *name)
4888  EXPORT_SYMBOL(putname);
4889  #endif
4890  
4891 +static inline int dx_barrier(const struct inode *inode)
4892 +{
4893 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4894 +               vxwprintk_task(1, "did hit the barrier.");
4895 +               return 1;
4896 +       }
4897 +       return 0;
4898 +}
4899 +
4900 +static int __dx_permission(const struct inode *inode, int mask)
4901 +{
4902 +       if (dx_barrier(inode))
4903 +               return -EACCES;
4904 +
4905 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4906 +               /* devpts is xid tagged */
4907 +               if (S_ISDIR(inode->i_mode) ||
4908 +                   vx_check((xid_t)inode->i_tag, VS_IDENT | VS_WATCH_P))
4909 +                       return 0;
4910 +       }
4911 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4912 +               struct proc_dir_entry *de = PDE(inode);
4913 +
4914 +               if (de && !vx_hide_check(0, de->vx_flags))
4915 +                       goto out;
4916 +
4917 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4918 +                       struct pid *pid;
4919 +                       struct task_struct *tsk;
4920 +
4921 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4922 +                           vx_flags(VXF_STATE_SETUP, 0))
4923 +                               return 0;
4924 +
4925 +                       pid = PROC_I(inode)->pid;
4926 +                       if (!pid)
4927 +                               goto out;
4928 +
4929 +                       tsk = pid_task(pid, PIDTYPE_PID);
4930 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4931 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4932 +                       if (tsk && vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P))
4933 +                               return 0;
4934 +               }
4935 +               else {
4936 +                       /* FIXME: Should we block some entries here? */
4937 +                       return 0;
4938 +               }
4939 +       }
4940 +       else {
4941 +               if (dx_notagcheck(inode->i_sb) ||
4942 +                   dx_check(inode->i_tag, DX_HOSTID | DX_ADMIN | DX_WATCH |
4943 +                            DX_IDENT))
4944 +                       return 0;
4945 +       }
4946 +
4947 +out:
4948 +       return -EACCES;
4949 +}
4950 +
4951 +int dx_permission(const struct inode *inode, int mask)
4952 +{
4953 +       int ret = __dx_permission(inode, mask);
4954 +       if (unlikely(ret)) {
4955 +               vxwprintk_task(1, "denied %x access to %s:%p[#%d,%lu]",
4956 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
4957 +                       inode->i_ino);
4958 +       }
4959 +       return ret;
4960 +}
4961 +
4962  /*
4963   * This does basic POSIX ACL permission checking
4964   */
4965 @@ -269,10 +348,14 @@ int inode_permission(struct inode *inode
4966                 /*
4967                  * Nobody gets write access to an immutable file.
4968                  */
4969 -               if (IS_IMMUTABLE(inode))
4970 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4971                         return -EACCES;
4972         }
4973  
4974 +       retval = dx_permission(inode, mask);
4975 +       if (retval)
4976 +               return retval;
4977 +
4978         if (inode->i_op->permission)
4979                 retval = inode->i_op->permission(inode, mask);
4980         else
4981 @@ -448,6 +531,9 @@ static int exec_permission_lite(struct i
4982  {
4983         int ret;
4984  
4985 +       if (dx_barrier(inode))
4986 +               return -EACCES;
4987 +
4988         if (inode->i_op->permission) {
4989                 ret = inode->i_op->permission(inode, MAY_EXEC);
4990                 if (!ret)
4991 @@ -763,7 +849,8 @@ static __always_inline void follow_dotdo
4992  
4993                 if (nd->path.dentry == nd->root.dentry &&
4994                     nd->path.mnt == nd->root.mnt) {
4995 -                       break;
4996 +                       /* for sane '/' avoid follow_mount() */
4997 +                       return;
4998                 }
4999                 spin_lock(&dcache_lock);
5000                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
5001 @@ -799,16 +886,30 @@ static int do_lookup(struct nameidata *n
5002  {
5003         struct vfsmount *mnt = nd->path.mnt;
5004         struct dentry *dentry = __d_lookup(nd->path.dentry, name);
5005 +       struct inode *inode;
5006  
5007         if (!dentry)
5008                 goto need_lookup;
5009         if (dentry->d_op && dentry->d_op->d_revalidate)
5010                 goto need_revalidate;
5011 +       inode = dentry->d_inode;
5012 +       if (!inode)
5013 +               goto done;
5014 +
5015 +       if (__dx_permission(inode, MAY_ACCESS))
5016 +               goto hidden;
5017 +
5018  done:
5019         path->mnt = mnt;
5020         path->dentry = dentry;
5021         __follow_mount(path);
5022         return 0;
5023 +hidden:
5024 +       vxwprintk_task(1, "did lookup hidden %s:%p[#%d,%lu] »%s/%.*s«.",
5025 +               inode->i_sb->s_id, inode, inode->i_tag, inode->i_ino,
5026 +               vxd_path(&nd->path), name->len, name->name);
5027 +       dput(dentry);
5028 +       return -ENOENT;
5029  
5030  need_lookup:
5031         dentry = real_lookup(nd->path.dentry, name, nd);
5032 @@ -1400,7 +1501,7 @@ static int may_delete(struct inode *dir,
5033         if (IS_APPEND(dir))
5034                 return -EPERM;
5035         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
5036 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
5037 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
5038                 return -EPERM;
5039         if (isdir) {
5040                 if (!S_ISDIR(victim->d_inode->i_mode))
5041 @@ -1540,6 +1641,14 @@ int may_open(struct path *path, int acc_
5042                 break;
5043         }
5044  
5045 +#ifdef CONFIG_VSERVER_COWBL
5046 +       if (IS_COW(inode) && (flag & FMODE_WRITE)) {
5047 +               if (IS_COW_LINK(inode))
5048 +                       return -EMLINK;
5049 +               inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
5050 +               mark_inode_dirty(inode);
5051 +       }
5052 +#endif
5053         error = inode_permission(inode, acc_mode);
5054         if (error)
5055                 return error;
5056 @@ -1688,7 +1797,11 @@ struct file *do_filp_open(int dfd, const
5057         int count = 0;
5058         int will_write;
5059         int flag = open_to_namei_flags(open_flag);
5060 -
5061 +#ifdef CONFIG_VSERVER_COWBL
5062 +       int rflag = flag;
5063 +       int rmode = mode;
5064 +restart:
5065 +#endif
5066         if (!acc_mode)
5067                 acc_mode = MAY_OPEN | ACC_MODE(flag);
5068  
5069 @@ -1836,6 +1949,25 @@ ok:
5070                         goto exit;
5071         }
5072         error = may_open(&nd.path, acc_mode, flag);
5073 +#ifdef CONFIG_VSERVER_COWBL
5074 +       if (error == -EMLINK) {
5075 +               struct dentry *dentry;
5076 +               dentry = cow_break_link(pathname);
5077 +               if (IS_ERR(dentry)) {
5078 +                       error = PTR_ERR(dentry);
5079 +                       goto exit_cow;
5080 +               }
5081 +               dput(dentry);
5082 +               if (will_write)
5083 +                       mnt_drop_write(nd.path.mnt);
5084 +               release_open_intent(&nd);
5085 +               path_put(&nd.path);
5086 +               flag = rflag;
5087 +               mode = rmode;
5088 +               goto restart;
5089 +       }
5090 +exit_cow:
5091 +#endif
5092         if (error) {
5093                 if (will_write)
5094                         mnt_drop_write(nd.path.mnt);
5095 @@ -1998,9 +2130,17 @@ int vfs_mknod(struct inode *dir, struct 
5096         if (error)
5097                 return error;
5098  
5099 -       if ((S_ISCHR(mode) || S_ISBLK(mode)) && !capable(CAP_MKNOD))
5100 +       if (!(S_ISCHR(mode) || S_ISBLK(mode)))
5101 +               goto okay;
5102 +
5103 +       if (!capable(CAP_MKNOD))
5104                 return -EPERM;
5105  
5106 +       if (S_ISCHR(mode) && !vs_chrdev_perm(dev, DATTR_CREATE))
5107 +               return -EPERM;
5108 +       if (S_ISBLK(mode) && !vs_blkdev_perm(dev, DATTR_CREATE))
5109 +               return -EPERM;
5110 +okay:
5111         if (!dir->i_op->mknod)
5112                 return -EPERM;
5113  
5114 @@ -2467,7 +2607,7 @@ int vfs_link(struct dentry *old_dentry, 
5115         /*
5116          * A link to an append-only or immutable file cannot be created.
5117          */
5118 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
5119 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
5120                 return -EPERM;
5121         if (!dir->i_op->link)
5122                 return -EPERM;
5123 @@ -2840,6 +2980,219 @@ int vfs_follow_link(struct nameidata *nd
5124         return __vfs_follow_link(nd, link);
5125  }
5126  
5127 +
5128 +#ifdef CONFIG_VSERVER_COWBL
5129 +
5130 +#include <linux/file.h>
5131 +
5132 +static inline
5133 +long do_cow_splice(struct file *in, struct file *out, size_t len)
5134 +{
5135 +       loff_t ppos = 0;
5136 +
5137 +       return do_splice_direct(in, &ppos, out, len, 0);
5138 +}
5139 +
5140 +struct dentry *cow_break_link(const char *pathname)
5141 +{
5142 +       int ret, mode, pathlen, redo = 0;
5143 +       struct nameidata old_nd, dir_nd;
5144 +       struct path old_path, new_path;
5145 +       struct dentry *dir, *res = NULL;
5146 +       struct file *old_file;
5147 +       struct file *new_file;
5148 +       char *to, *path, pad='\251';
5149 +       loff_t size;
5150 +
5151 +       vxdprintk(VXD_CBIT(misc, 1), "cow_break_link(»%s«)", pathname);
5152 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
5153 +       ret = -ENOMEM;
5154 +       if (!path)
5155 +               goto out;
5156 +
5157 +       /* old_nd will have refs to dentry and mnt */
5158 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5159 +       vxdprintk(VXD_CBIT(misc, 2), "path_lookup(old): %d", ret);
5160 +       if (ret < 0)
5161 +               goto out_free_path;
5162 +
5163 +       old_path = old_nd.path;
5164 +       mode = old_path.dentry->d_inode->i_mode;
5165 +
5166 +       to = d_path(&old_path, path, PATH_MAX-2);
5167 +       pathlen = strlen(to);
5168 +       vxdprintk(VXD_CBIT(misc, 2), "old path »%s« [»%.*s«:%d]", to,
5169 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5170 +               old_path.dentry->d_name.len);
5171 +
5172 +       to[pathlen + 1] = 0;
5173 +retry:
5174 +       to[pathlen] = pad--;
5175 +       ret = -EMLINK;
5176 +       if (pad <= '\240')
5177 +               goto out_rel_old;
5178 +
5179 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy »%s«", to);
5180 +       /* dir_nd will have refs to dentry and mnt */
5181 +       ret = path_lookup(to,
5182 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
5183 +       vxdprintk(VXD_CBIT(misc, 2),
5184 +               "path_lookup(new): %d", ret);
5185 +       if (ret < 0)
5186 +               goto retry;
5187 +
5188 +       /* this puppy downs the inode mutex */
5189 +       new_path.dentry = lookup_create(&dir_nd, 0);
5190 +       if (!new_path.dentry || IS_ERR(new_path.dentry)) {
5191 +               vxdprintk(VXD_CBIT(misc, 2),
5192 +                       "lookup_create(new): %p", new_path.dentry);
5193 +               mutex_unlock(&dir_nd.path.dentry->d_inode->i_mutex);
5194 +               path_put(&dir_nd.path);
5195 +               goto retry;
5196 +       }
5197 +       vxdprintk(VXD_CBIT(misc, 2),
5198 +               "lookup_create(new): %p [»%.*s«:%d]", new_path.dentry,
5199 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5200 +               new_path.dentry->d_name.len);
5201 +       dir = dir_nd.path.dentry;
5202 +
5203 +       ret = vfs_create(dir_nd.path.dentry->d_inode, new_path.dentry, mode, &dir_nd);
5204 +       vxdprintk(VXD_CBIT(misc, 2),
5205 +               "vfs_create(new): %d", ret);
5206 +       if (ret == -EEXIST) {
5207 +               mutex_unlock(&dir->d_inode->i_mutex);
5208 +               dput(new_path.dentry);
5209 +               path_put(&dir_nd.path);
5210 +               goto retry;
5211 +       }
5212 +       else if (ret < 0)
5213 +               goto out_unlock_new;
5214 +
5215 +       /* drop out early, ret passes ENOENT */
5216 +       ret = -ENOENT;
5217 +       if ((redo = d_unhashed(old_path.dentry)))
5218 +               goto out_unlock_new;
5219 +
5220 +       new_path.mnt = dir_nd.path.mnt;
5221 +       dget(old_path.dentry);
5222 +       mntget(old_path.mnt);
5223 +       /* this one cleans up the dentry/mnt in case of failure */
5224 +       old_file = dentry_open(old_path.dentry, old_path.mnt,
5225 +               O_RDONLY, current_cred());
5226 +       vxdprintk(VXD_CBIT(misc, 2),
5227 +               "dentry_open(old): %p", old_file);
5228 +       if (!old_file || IS_ERR(old_file)) {
5229 +               res = IS_ERR(old_file) ? (void *) old_file : res;
5230 +               goto out_unlock_new;
5231 +       }
5232 +
5233 +       dget(new_path.dentry);
5234 +       mntget(new_path.mnt);
5235 +       /* this one cleans up the dentry/mnt in case of failure */
5236 +       new_file = dentry_open(new_path.dentry, new_path.mnt,
5237 +               O_WRONLY, current_cred());
5238 +       vxdprintk(VXD_CBIT(misc, 2),
5239 +               "dentry_open(new): %p", new_file);
5240 +
5241 +       ret = IS_ERR(new_file) ? PTR_ERR(new_file) : -ENOENT;
5242 +       if (!new_file || IS_ERR(new_file))
5243 +               goto out_fput_old;
5244 +
5245 +       size = i_size_read(old_file->f_dentry->d_inode);
5246 +       ret = do_cow_splice(old_file, new_file, size);
5247 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
5248 +       if (ret < 0) {
5249 +               goto out_fput_both;
5250 +       } else if (ret < size) {
5251 +               ret = -ENOSPC;
5252 +               goto out_fput_both;
5253 +       } else {
5254 +               struct inode *old_inode = old_path.dentry->d_inode;
5255 +               struct inode *new_inode = new_path.dentry->d_inode;
5256 +               struct iattr attr = {
5257 +                       .ia_uid = old_inode->i_uid,
5258 +                       .ia_gid = old_inode->i_gid,
5259 +                       .ia_valid = ATTR_UID | ATTR_GID
5260 +                       };
5261 +
5262 +               ret = inode_setattr(new_inode, &attr);
5263 +               if (ret)
5264 +                       goto out_fput_both;
5265 +       }
5266 +
5267 +       mutex_lock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5268 +
5269 +       /* drop out late */
5270 +       ret = -ENOENT;
5271 +       if ((redo = d_unhashed(old_path.dentry)))
5272 +               goto out_unlock;
5273 +
5274 +       vxdprintk(VXD_CBIT(misc, 2),
5275 +               "vfs_rename: [»%*s«:%d] -> [»%*s«:%d]",
5276 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5277 +               new_path.dentry->d_name.len,
5278 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5279 +               old_path.dentry->d_name.len);
5280 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_path.dentry,
5281 +               old_nd.path.dentry->d_parent->d_inode, old_path.dentry);
5282 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
5283 +       res = new_path.dentry;
5284 +
5285 +out_unlock:
5286 +       mutex_unlock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5287 +
5288 +out_fput_both:
5289 +       vxdprintk(VXD_CBIT(misc, 3),
5290 +               "fput(new_file=%p[#%ld])", new_file,
5291 +               atomic_long_read(&new_file->f_count));
5292 +       fput(new_file);
5293 +
5294 +out_fput_old:
5295 +       vxdprintk(VXD_CBIT(misc, 3),
5296 +               "fput(old_file=%p[#%ld])", old_file,
5297 +               atomic_long_read(&old_file->f_count));
5298 +       fput(old_file);
5299 +
5300 +out_unlock_new:
5301 +       mutex_unlock(&dir->d_inode->i_mutex);
5302 +       if (!ret)
5303 +               goto out_redo;
5304 +
5305 +       /* error path cleanup */
5306 +       vfs_unlink(dir->d_inode, new_path.dentry);
5307 +       dput(new_path.dentry);
5308 +
5309 +out_redo:
5310 +       if (!redo)
5311 +               goto out_rel_both;
5312 +       /* lookup dentry once again */
5313 +       path_put(&old_nd.path);
5314 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5315 +       if (ret)
5316 +               goto out_rel_both;
5317 +
5318 +       new_path.dentry = old_nd.path.dentry;
5319 +       vxdprintk(VXD_CBIT(misc, 2),
5320 +               "path_lookup(redo): %p [»%.*s«:%d]", new_path.dentry,
5321 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5322 +               new_path.dentry->d_name.len);
5323 +       dget(new_path.dentry);
5324 +       res = new_path.dentry;
5325 +
5326 +out_rel_both:
5327 +       path_put(&dir_nd.path);
5328 +out_rel_old:
5329 +       path_put(&old_nd.path);
5330 +out_free_path:
5331 +       kfree(path);
5332 +out:
5333 +       if (ret)
5334 +               res = ERR_PTR(ret);
5335 +       return res;
5336 +}
5337 +
5338 +#endif
5339 +
5340  /* get the link contents into pagecache */
5341  static char *page_getlink(struct dentry * dentry, struct page **ppage)
5342  {
5343 diff -NurpP --minimal linux-2.6.32.56/fs/namespace.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/namespace.c
5344 --- linux-2.6.32.56/fs/namespace.c      2012-02-09 10:22:30.000000000 +0100
5345 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/namespace.c      2011-06-10 13:03:02.000000000 +0200
5346 @@ -29,6 +29,11 @@
5347  #include <linux/log2.h>
5348  #include <linux/idr.h>
5349  #include <linux/fs_struct.h>
5350 +#include <linux/vs_base.h>
5351 +#include <linux/vs_context.h>
5352 +#include <linux/vs_tag.h>
5353 +#include <linux/vserver/space.h>
5354 +#include <linux/vserver/global.h>
5355  #include <asm/uaccess.h>
5356  #include <asm/unistd.h>
5357  #include "pnode.h"
5358 @@ -567,6 +572,7 @@ static struct vfsmount *clone_mnt(struct
5359                 mnt->mnt_root = dget(root);
5360                 mnt->mnt_mountpoint = mnt->mnt_root;
5361                 mnt->mnt_parent = mnt;
5362 +               mnt->mnt_tag = old->mnt_tag;
5363  
5364                 if (flag & CL_SLAVE) {
5365                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
5366 @@ -661,6 +667,31 @@ static inline void mangle(struct seq_fil
5367         seq_escape(m, s, " \t\n\\");
5368  }
5369  
5370 +static int mnt_is_reachable(struct vfsmount *mnt)
5371 +{
5372 +       struct path root;
5373 +       struct dentry *point;
5374 +       int ret;
5375 +
5376 +       if (mnt == mnt->mnt_ns->root)
5377 +               return 1;
5378 +
5379 +       spin_lock(&vfsmount_lock);
5380 +       root = current->fs->root;
5381 +       point = root.dentry;
5382 +
5383 +       while ((mnt != mnt->mnt_parent) && (mnt != root.mnt)) {
5384 +               point = mnt->mnt_mountpoint;
5385 +               mnt = mnt->mnt_parent;
5386 +       }
5387 +
5388 +       ret = (mnt == root.mnt) && is_subdir(point, root.dentry);
5389 +
5390 +       spin_unlock(&vfsmount_lock);
5391 +
5392 +       return ret;
5393 +}
5394 +
5395  /*
5396   * Simple .show_options callback for filesystems which don't want to
5397   * implement more complex mount option showing.
5398 @@ -748,6 +779,8 @@ static int show_sb_opts(struct seq_file 
5399                 { MS_SYNCHRONOUS, ",sync" },
5400                 { MS_DIRSYNC, ",dirsync" },
5401                 { MS_MANDLOCK, ",mand" },
5402 +               { MS_TAGGED, ",tag" },
5403 +               { MS_NOTAGCHECK, ",notagcheck" },
5404                 { 0, NULL }
5405         };
5406         const struct proc_fs_info *fs_infop;
5407 @@ -795,10 +828,20 @@ static int show_vfsmnt(struct seq_file *
5408         int err = 0;
5409         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5410  
5411 -       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5412 -       seq_putc(m, ' ');
5413 -       seq_path(m, &mnt_path, " \t\n\\");
5414 -       seq_putc(m, ' ');
5415 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5416 +               return SEQ_SKIP;
5417 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5418 +               return SEQ_SKIP;
5419 +
5420 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5421 +               mnt == current->fs->root.mnt) {
5422 +               seq_puts(m, "/dev/root / ");
5423 +       } else {
5424 +               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5425 +               seq_putc(m, ' ');
5426 +               seq_path(m, &mnt_path, " \t\n\\");
5427 +               seq_putc(m, ' ');
5428 +       }
5429         show_type(m, mnt->mnt_sb);
5430         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
5431         err = show_sb_opts(m, mnt->mnt_sb);
5432 @@ -828,6 +871,11 @@ static int show_mountinfo(struct seq_fil
5433         struct path root = p->root;
5434         int err = 0;
5435  
5436 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5437 +               return SEQ_SKIP;
5438 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5439 +               return SEQ_SKIP;
5440 +
5441         seq_printf(m, "%i %i %u:%u ", mnt->mnt_id, mnt->mnt_parent->mnt_id,
5442                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
5443         seq_dentry(m, mnt->mnt_root, " \t\n\\");
5444 @@ -886,17 +934,27 @@ static int show_vfsstat(struct seq_file 
5445         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5446         int err = 0;
5447  
5448 -       /* device */
5449 -       if (mnt->mnt_devname) {
5450 -               seq_puts(m, "device ");
5451 -               mangle(m, mnt->mnt_devname);
5452 -       } else
5453 -               seq_puts(m, "no device");
5454 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5455 +               return SEQ_SKIP;
5456 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5457 +               return SEQ_SKIP;
5458  
5459 -       /* mount point */
5460 -       seq_puts(m, " mounted on ");
5461 -       seq_path(m, &mnt_path, " \t\n\\");
5462 -       seq_putc(m, ' ');
5463 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5464 +               mnt == current->fs->root.mnt) {
5465 +               seq_puts(m, "device /dev/root mounted on / ");
5466 +       } else {
5467 +               /* device */
5468 +               if (mnt->mnt_devname) {
5469 +                       seq_puts(m, "device ");
5470 +                       mangle(m, mnt->mnt_devname);
5471 +               } else
5472 +                       seq_puts(m, "no device");
5473 +
5474 +               /* mount point */
5475 +               seq_puts(m, " mounted on ");
5476 +               seq_path(m, &mnt_path, " \t\n\\");
5477 +               seq_putc(m, ' ');
5478 +       }
5479  
5480         /* file system type */
5481         seq_puts(m, "with fstype ");
5482 @@ -1137,7 +1195,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
5483                 goto dput_and_out;
5484  
5485         retval = -EPERM;
5486 -       if (!capable(CAP_SYS_ADMIN))
5487 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5488                 goto dput_and_out;
5489  
5490         retval = do_umount(path.mnt, flags);
5491 @@ -1163,7 +1221,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
5492  
5493  static int mount_is_safe(struct path *path)
5494  {
5495 -       if (capable(CAP_SYS_ADMIN))
5496 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5497                 return 0;
5498         return -EPERM;
5499  #ifdef notyet
5500 @@ -1427,7 +1485,7 @@ static int do_change_type(struct path *p
5501         int type = flag & ~MS_REC;
5502         int err = 0;
5503  
5504 -       if (!capable(CAP_SYS_ADMIN))
5505 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_NAMESPACE))
5506                 return -EPERM;
5507  
5508         if (path->dentry != path->mnt->mnt_root)
5509 @@ -1454,11 +1512,13 @@ static int do_change_type(struct path *p
5510   * do loopback mount.
5511   */
5512  static int do_loopback(struct path *path, char *old_name,
5513 -                               int recurse)
5514 +       tag_t tag, unsigned long flags, int mnt_flags)
5515  {
5516         struct path old_path;
5517         struct vfsmount *mnt = NULL;
5518         int err = mount_is_safe(path);
5519 +       int recurse = flags & MS_REC;
5520 +
5521         if (err)
5522                 return err;
5523         if (!old_name || !*old_name)
5524 @@ -1492,6 +1552,7 @@ static int do_loopback(struct path *path
5525                 spin_unlock(&vfsmount_lock);
5526                 release_mounts(&umount_list);
5527         }
5528 +       mnt->mnt_flags = mnt_flags;
5529  
5530  out:
5531         up_write(&namespace_sem);
5532 @@ -1522,12 +1583,12 @@ static int change_mount_flags(struct vfs
5533   * on it - tough luck.
5534   */
5535  static int do_remount(struct path *path, int flags, int mnt_flags,
5536 -                     void *data)
5537 +       void *data, xid_t xid)
5538  {
5539         int err;
5540         struct super_block *sb = path->mnt->mnt_sb;
5541  
5542 -       if (!capable(CAP_SYS_ADMIN))
5543 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
5544                 return -EPERM;
5545  
5546         if (!check_mnt(path->mnt))
5547 @@ -1569,7 +1630,7 @@ static int do_move_mount(struct path *pa
5548         struct path old_path, parent_path;
5549         struct vfsmount *p;
5550         int err = 0;
5551 -       if (!capable(CAP_SYS_ADMIN))
5552 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5553                 return -EPERM;
5554         if (!old_name || !*old_name)
5555                 return -EINVAL;
5556 @@ -1651,7 +1712,7 @@ static int do_new_mount(struct path *pat
5557                 return -EINVAL;
5558  
5559         /* we need capabilities... */
5560 -       if (!capable(CAP_SYS_ADMIN))
5561 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5562                 return -EPERM;
5563  
5564         lock_kernel();
5565 @@ -1915,6 +1976,7 @@ long do_mount(char *dev_name, char *dir_
5566         struct path path;
5567         int retval = 0;
5568         int mnt_flags = 0;
5569 +       tag_t tag = 0;
5570  
5571         /* Discard magic */
5572         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5573 @@ -1932,6 +1994,12 @@ long do_mount(char *dev_name, char *dir_
5574         if (!(flags & MS_NOATIME))
5575                 mnt_flags |= MNT_RELATIME;
5576  
5577 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5578 +               /* FIXME: bind and re-mounts get the tag flag? */
5579 +               if (flags & (MS_BIND|MS_REMOUNT))
5580 +                       flags |= MS_TAGID;
5581 +       }
5582 +
5583         /* Separate the per-mountpoint flags */
5584         if (flags & MS_NOSUID)
5585                 mnt_flags |= MNT_NOSUID;
5586 @@ -1948,6 +2016,8 @@ long do_mount(char *dev_name, char *dir_
5587         if (flags & MS_RDONLY)
5588                 mnt_flags |= MNT_READONLY;
5589  
5590 +       if (!capable(CAP_SYS_ADMIN))
5591 +               mnt_flags |= MNT_NODEV;
5592         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE |
5593                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
5594                    MS_STRICTATIME);
5595 @@ -1964,9 +2034,9 @@ long do_mount(char *dev_name, char *dir_
5596  
5597         if (flags & MS_REMOUNT)
5598                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5599 -                                   data_page);
5600 +                                   data_page, tag);
5601         else if (flags & MS_BIND)
5602 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5603 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5604         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5605                 retval = do_change_type(&path, flags);
5606         else if (flags & MS_MOVE)
5607 @@ -2045,6 +2115,7 @@ static struct mnt_namespace *dup_mnt_ns(
5608                 q = next_mnt(q, new_ns->root);
5609         }
5610         up_write(&namespace_sem);
5611 +       atomic_inc(&vs_global_mnt_ns);
5612  
5613         if (rootmnt)
5614                 mntput(rootmnt);
5615 @@ -2189,9 +2260,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5616         down_write(&namespace_sem);
5617         mutex_lock(&old.dentry->d_inode->i_mutex);
5618         error = -EINVAL;
5619 -       if (IS_MNT_SHARED(old.mnt) ||
5620 +       if ((IS_MNT_SHARED(old.mnt) ||
5621                 IS_MNT_SHARED(new.mnt->mnt_parent) ||
5622 -               IS_MNT_SHARED(root.mnt->mnt_parent))
5623 +               IS_MNT_SHARED(root.mnt->mnt_parent)) &&
5624 +               !vx_flags(VXF_STATE_SETUP, 0))
5625                 goto out2;
5626         if (!check_mnt(root.mnt))
5627                 goto out2;
5628 @@ -2327,6 +2399,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5629         spin_unlock(&vfsmount_lock);
5630         up_write(&namespace_sem);
5631         release_mounts(&umount_list);
5632 +       atomic_dec(&vs_global_mnt_ns);
5633         kfree(ns);
5634  }
5635  EXPORT_SYMBOL(put_mnt_ns);
5636 diff -NurpP --minimal linux-2.6.32.56/fs/nfs/client.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/nfs/client.c
5637 --- linux-2.6.32.56/fs/nfs/client.c     2012-02-09 10:22:30.000000000 +0100
5638 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/nfs/client.c     2011-06-10 13:03:02.000000000 +0200
5639 @@ -738,6 +738,9 @@ static int nfs_init_server_rpcclient(str
5640         if (server->flags & NFS_MOUNT_SOFT)
5641                 server->client->cl_softrtry = 1;
5642  
5643 +       server->client->cl_tag = 0;
5644 +       if (server->flags & NFS_MOUNT_TAGGED)
5645 +               server->client->cl_tag = 1;
5646         return 0;
5647  }
5648  
5649 @@ -909,6 +912,10 @@ static void nfs_server_set_fsinfo(struct
5650                 server->acdirmin = server->acdirmax = 0;
5651         }
5652  
5653 +       /* FIXME: needs fsinfo
5654 +       if (server->flags & NFS_MOUNT_TAGGED)
5655 +               sb->s_flags |= MS_TAGGED;       */
5656 +
5657         server->maxfilesize = fsinfo->maxfilesize;
5658  
5659         /* We're airborne Set socket buffersize */
5660 diff -NurpP --minimal linux-2.6.32.56/fs/nfs/dir.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/nfs/dir.c
5661 --- linux-2.6.32.56/fs/nfs/dir.c        2012-02-09 10:22:30.000000000 +0100
5662 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/nfs/dir.c        2011-06-10 13:03:02.000000000 +0200
5663 @@ -33,6 +33,7 @@
5664  #include <linux/namei.h>
5665  #include <linux/mount.h>
5666  #include <linux/sched.h>
5667 +#include <linux/vs_tag.h>
5668  
5669  #include "nfs4_fs.h"
5670  #include "delegation.h"
5671 @@ -951,6 +952,7 @@ static struct dentry *nfs_lookup(struct 
5672         if (IS_ERR(res))
5673                 goto out_unblock_sillyrename;
5674  
5675 +       dx_propagate_tag(nd, inode);
5676  no_entry:
5677         res = d_materialise_unique(dentry, inode);
5678         if (res != NULL) {
5679 diff -NurpP --minimal linux-2.6.32.56/fs/nfs/inode.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/nfs/inode.c
5680 --- linux-2.6.32.56/fs/nfs/inode.c      2012-02-09 10:22:30.000000000 +0100
5681 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/nfs/inode.c      2011-09-30 02:12:21.000000000 +0200
5682 @@ -36,6 +36,7 @@
5683  #include <linux/vfs.h>
5684  #include <linux/inet.h>
5685  #include <linux/nfs_xdr.h>
5686 +#include <linux/vs_tag.h>
5687  
5688  #include <asm/system.h>
5689  #include <asm/uaccess.h>
5690 @@ -279,6 +280,8 @@ nfs_fhget(struct super_block *sb, struct
5691         if (inode->i_state & I_NEW) {
5692                 struct nfs_inode *nfsi = NFS_I(inode);
5693                 unsigned long now = jiffies;
5694 +               uid_t uid;
5695 +               gid_t gid;
5696  
5697                 /* We set i_ino for the few things that still rely on it,
5698                  * such as stat(2) */
5699 @@ -327,8 +330,8 @@ nfs_fhget(struct super_block *sb, struct
5700                 nfsi->change_attr = 0;
5701                 inode->i_size = 0;
5702                 inode->i_nlink = 0;
5703 -               inode->i_uid = -2;
5704 -               inode->i_gid = -2;
5705 +               uid = -2;
5706 +               gid = -2;
5707                 inode->i_blocks = 0;
5708                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5709  
5710 @@ -365,17 +368,25 @@ nfs_fhget(struct super_block *sb, struct
5711                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5712                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5713                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5714 -                       inode->i_uid = fattr->uid;
5715 -               else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5716 -                       nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5717 -                               | NFS_INO_INVALID_ACCESS
5718 -                               | NFS_INO_INVALID_ACL;
5719 +                       uid = fattr->uid;
5720 +               else {
5721 +                       uid = TAGINO_UID(DX_TAG(inode),
5722 +                               inode->i_uid, inode->i_tag);
5723 +                       if (nfs_server_capable(inode, NFS_CAP_OWNER))
5724 +                               nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5725 +                                       | NFS_INO_INVALID_ACCESS
5726 +                                       | NFS_INO_INVALID_ACL;
5727 +               }
5728                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5729 -                       inode->i_gid = fattr->gid;
5730 -               else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5731 -                       nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5732 -                               | NFS_INO_INVALID_ACCESS
5733 -                               | NFS_INO_INVALID_ACL;
5734 +                       gid = fattr->gid;
5735 +               else {
5736 +                       gid = TAGINO_GID(DX_TAG(inode),
5737 +                               inode->i_gid, inode->i_tag);
5738 +                       if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5739 +                               nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5740 +                                       | NFS_INO_INVALID_ACCESS
5741 +                                       | NFS_INO_INVALID_ACL;
5742 +               }
5743                 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
5744                         inode->i_blocks = fattr->du.nfs2.blocks;
5745                 if (fattr->valid & NFS_ATTR_FATTR_SPACE_USED) {
5746 @@ -384,6 +395,11 @@ nfs_fhget(struct super_block *sb, struct
5747                          */
5748                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5749                 }
5750 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5751 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5752 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
5753 +                               /* maybe fattr->xid someday */
5754 +
5755                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5756                 nfsi->attrtimeo_timestamp = now;
5757                 nfsi->access_cache = RB_ROOT;
5758 @@ -393,11 +409,11 @@ nfs_fhget(struct super_block *sb, struct
5759                 unlock_new_inode(inode);
5760         } else
5761                 nfs_refresh_inode(inode, fattr);
5762 +
5763         dprintk("NFS: nfs_fhget(%s/%Ld ct=%d)\n",
5764                 inode->i_sb->s_id,
5765                 (long long)NFS_FILEID(inode),
5766                 atomic_read(&inode->i_count));
5767 -
5768  out:
5769         return inode;
5770  
5771 @@ -496,6 +512,8 @@ void nfs_setattr_update_inode(struct ino
5772                         inode->i_uid = attr->ia_uid;
5773                 if ((attr->ia_valid & ATTR_GID) != 0)
5774                         inode->i_gid = attr->ia_gid;
5775 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5776 +                       inode->i_tag = attr->ia_tag;
5777                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5778                 spin_unlock(&inode->i_lock);
5779         }
5780 @@ -914,6 +932,9 @@ static int nfs_check_inode_attributes(st
5781         struct nfs_inode *nfsi = NFS_I(inode);
5782         loff_t cur_size, new_isize;
5783         unsigned long invalid = 0;
5784 +       uid_t uid;
5785 +       gid_t gid;
5786 +       tag_t tag;
5787  
5788  
5789         /* Has the inode gone and changed behind our back? */
5790 @@ -937,13 +958,18 @@ static int nfs_check_inode_attributes(st
5791                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5792         }
5793  
5794 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5795 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5796 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5797 +
5798         /* Have any file permissions changed? */
5799         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5800                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5801 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && inode->i_uid != fattr->uid)
5802 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && uid != fattr->uid)
5803                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5804 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && inode->i_gid != fattr->gid)
5805 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && gid != fattr->gid)
5806                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5807 +               /* maybe check for tag too? */
5808  
5809         /* Has the link count changed? */
5810         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5811 @@ -1158,6 +1184,9 @@ static int nfs_update_inode(struct inode
5812         unsigned long invalid = 0;
5813         unsigned long now = jiffies;
5814         unsigned long save_cache_validity;
5815 +       uid_t uid;
5816 +       gid_t gid;
5817 +       tag_t tag;
5818  
5819         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
5820                         __func__, inode->i_sb->s_id, inode->i_ino,
5821 @@ -1260,6 +1289,9 @@ static int nfs_update_inode(struct inode
5822                                 | NFS_INO_REVAL_PAGECACHE
5823                                 | NFS_INO_REVAL_FORCED);
5824  
5825 +       uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5826 +       gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5827 +       tag = inode->i_tag;
5828  
5829         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5830                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5831 @@ -1279,9 +1311,9 @@ static int nfs_update_inode(struct inode
5832                                 | NFS_INO_REVAL_FORCED);
5833  
5834         if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
5835 -               if (inode->i_uid != fattr->uid) {
5836 +               if (uid != fattr->uid) {
5837                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5838 -                       inode->i_uid = fattr->uid;
5839 +                       uid = fattr->uid;
5840                 }
5841         } else if (server->caps & NFS_CAP_OWNER)
5842                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5843 @@ -1290,9 +1322,9 @@ static int nfs_update_inode(struct inode
5844                                 | NFS_INO_REVAL_FORCED);
5845  
5846         if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
5847 -               if (inode->i_gid != fattr->gid) {
5848 +               if (gid != fattr->gid) {
5849                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5850 -                       inode->i_gid = fattr->gid;
5851 +                       gid = fattr->gid;
5852                 }
5853         } else if (server->caps & NFS_CAP_OWNER_GROUP)
5854                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5855 @@ -1300,6 +1332,10 @@ static int nfs_update_inode(struct inode
5856                                 | NFS_INO_INVALID_ACL
5857                                 | NFS_INO_REVAL_FORCED);
5858  
5859 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5860 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5861 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, tag);
5862 +
5863         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5864                 if (inode->i_nlink != fattr->nlink) {
5865                         invalid |= NFS_INO_INVALID_ATTR;
5866 diff -NurpP --minimal linux-2.6.32.56/fs/nfs/nfs3xdr.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/nfs/nfs3xdr.c
5867 --- linux-2.6.32.56/fs/nfs/nfs3xdr.c    2009-12-03 20:02:52.000000000 +0100
5868 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/nfs/nfs3xdr.c    2011-06-10 13:03:02.000000000 +0200
5869 @@ -21,6 +21,7 @@
5870  #include <linux/nfs3.h>
5871  #include <linux/nfs_fs.h>
5872  #include <linux/nfsacl.h>
5873 +#include <linux/vs_tag.h>
5874  #include "internal.h"
5875  
5876  #define NFSDBG_FACILITY                NFSDBG_XDR
5877 @@ -176,7 +177,7 @@ xdr_decode_fattr(__be32 *p, struct nfs_f
5878  }
5879  
5880  static inline __be32 *
5881 -xdr_encode_sattr(__be32 *p, struct iattr *attr)
5882 +xdr_encode_sattr(__be32 *p, struct iattr *attr, int tag)
5883  {
5884         if (attr->ia_valid & ATTR_MODE) {
5885                 *p++ = xdr_one;
5886 @@ -184,15 +185,17 @@ xdr_encode_sattr(__be32 *p, struct iattr
5887         } else {
5888                 *p++ = xdr_zero;
5889         }
5890 -       if (attr->ia_valid & ATTR_UID) {
5891 +       if (attr->ia_valid & ATTR_UID ||
5892 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5893                 *p++ = xdr_one;
5894 -               *p++ = htonl(attr->ia_uid);
5895 +               *p++ = htonl(TAGINO_UID(tag, attr->ia_uid, attr->ia_tag));
5896         } else {
5897                 *p++ = xdr_zero;
5898         }
5899 -       if (attr->ia_valid & ATTR_GID) {
5900 +       if (attr->ia_valid & ATTR_GID ||
5901 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5902                 *p++ = xdr_one;
5903 -               *p++ = htonl(attr->ia_gid);
5904 +               *p++ = htonl(TAGINO_GID(tag, attr->ia_gid, attr->ia_tag));
5905         } else {
5906                 *p++ = xdr_zero;
5907         }
5908 @@ -279,7 +282,8 @@ static int
5909  nfs3_xdr_sattrargs(struct rpc_rqst *req, __be32 *p, struct nfs3_sattrargs *args)
5910  {
5911         p = xdr_encode_fhandle(p, args->fh);
5912 -       p = xdr_encode_sattr(p, args->sattr);
5913 +       p = xdr_encode_sattr(p, args->sattr,
5914 +               req->rq_task->tk_client->cl_tag);
5915         *p++ = htonl(args->guard);
5916         if (args->guard)
5917                 p = xdr_encode_time3(p, &args->guardtime);
5918 @@ -384,7 +388,8 @@ nfs3_xdr_createargs(struct rpc_rqst *req
5919                 *p++ = args->verifier[0];
5920                 *p++ = args->verifier[1];
5921         } else
5922 -               p = xdr_encode_sattr(p, args->sattr);
5923 +               p = xdr_encode_sattr(p, args->sattr,
5924 +                       req->rq_task->tk_client->cl_tag);
5925  
5926         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5927         return 0;
5928 @@ -398,7 +403,8 @@ nfs3_xdr_mkdirargs(struct rpc_rqst *req,
5929  {
5930         p = xdr_encode_fhandle(p, args->fh);
5931         p = xdr_encode_array(p, args->name, args->len);
5932 -       p = xdr_encode_sattr(p, args->sattr);
5933 +       p = xdr_encode_sattr(p, args->sattr,
5934 +               req->rq_task->tk_client->cl_tag);
5935         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5936         return 0;
5937  }
5938 @@ -411,7 +417,8 @@ nfs3_xdr_symlinkargs(struct rpc_rqst *re
5939  {
5940         p = xdr_encode_fhandle(p, args->fromfh);
5941         p = xdr_encode_array(p, args->fromname, args->fromlen);
5942 -       p = xdr_encode_sattr(p, args->sattr);
5943 +       p = xdr_encode_sattr(p, args->sattr,
5944 +               req->rq_task->tk_client->cl_tag);
5945         *p++ = htonl(args->pathlen);
5946         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5947  
5948 @@ -429,7 +436,8 @@ nfs3_xdr_mknodargs(struct rpc_rqst *req,
5949         p = xdr_encode_fhandle(p, args->fh);
5950         p = xdr_encode_array(p, args->name, args->len);
5951         *p++ = htonl(args->type);
5952 -       p = xdr_encode_sattr(p, args->sattr);
5953 +       p = xdr_encode_sattr(p, args->sattr,
5954 +               req->rq_task->tk_client->cl_tag);
5955         if (args->type == NF3CHR || args->type == NF3BLK) {
5956                 *p++ = htonl(MAJOR(args->rdev));
5957                 *p++ = htonl(MINOR(args->rdev));
5958 diff -NurpP --minimal linux-2.6.32.56/fs/nfs/nfsroot.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/nfs/nfsroot.c
5959 --- linux-2.6.32.56/fs/nfs/nfsroot.c    2009-09-10 15:26:23.000000000 +0200
5960 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/nfs/nfsroot.c    2011-06-10 13:03:02.000000000 +0200
5961 @@ -122,12 +122,12 @@ static int mount_port __initdata = 0;             /
5962  enum {
5963         /* Options that take integer arguments */
5964         Opt_port, Opt_rsize, Opt_wsize, Opt_timeo, Opt_retrans, Opt_acregmin,
5965 -       Opt_acregmax, Opt_acdirmin, Opt_acdirmax,
5966 +       Opt_acregmax, Opt_acdirmin, Opt_acdirmax, Opt_tagid,
5967         /* Options that take no arguments */
5968         Opt_soft, Opt_hard, Opt_intr,
5969         Opt_nointr, Opt_posix, Opt_noposix, Opt_cto, Opt_nocto, Opt_ac, 
5970         Opt_noac, Opt_lock, Opt_nolock, Opt_v2, Opt_v3, Opt_udp, Opt_tcp,
5971 -       Opt_acl, Opt_noacl,
5972 +       Opt_acl, Opt_noacl, Opt_tag, Opt_notag,
5973         /* Error token */
5974         Opt_err
5975  };
5976 @@ -164,6 +164,9 @@ static const match_table_t tokens __init
5977         {Opt_tcp, "tcp"},
5978         {Opt_acl, "acl"},
5979         {Opt_noacl, "noacl"},
5980 +       {Opt_tag, "tag"},
5981 +       {Opt_notag, "notag"},
5982 +       {Opt_tagid, "tagid=%u"},
5983         {Opt_err, NULL}
5984         
5985  };
5986 @@ -275,6 +278,20 @@ static int __init root_nfs_parse(char *n
5987                         case Opt_noacl:
5988                                 nfs_data.flags |= NFS_MOUNT_NOACL;
5989                                 break;
5990 +#ifndef CONFIG_TAGGING_NONE
5991 +                       case Opt_tag:
5992 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
5993 +                               break;
5994 +                       case Opt_notag:
5995 +                               nfs_data.flags &= ~NFS_MOUNT_TAGGED;
5996 +                               break;
5997 +#endif
5998 +#ifdef CONFIG_PROPAGATE
5999 +                       case Opt_tagid:
6000 +                               /* use args[0] */
6001 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
6002 +                               break;
6003 +#endif
6004                         default:
6005                                 printk(KERN_WARNING "Root-NFS: unknown "
6006                                         "option: %s\n", p);
6007 diff -NurpP --minimal linux-2.6.32.56/fs/nfs/super.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/nfs/super.c
6008 --- linux-2.6.32.56/fs/nfs/super.c      2012-02-09 10:22:30.000000000 +0100
6009 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/nfs/super.c      2011-06-10 13:03:02.000000000 +0200
6010 @@ -53,6 +53,7 @@
6011  #include <linux/nfs_xdr.h>
6012  #include <linux/magic.h>
6013  #include <linux/parser.h>
6014 +#include <linux/vs_tag.h>
6015  
6016  #include <asm/system.h>
6017  #include <asm/uaccess.h>
6018 @@ -570,6 +571,7 @@ static void nfs_show_mount_options(struc
6019                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
6020                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
6021                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
6022 +               { NFS_MOUNT_TAGGED, ",tag", "" },
6023                 { 0, NULL, NULL }
6024         };
6025         const struct proc_nfs_info *nfs_infop;
6026 diff -NurpP --minimal linux-2.6.32.56/fs/nfsd/auth.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/nfsd/auth.c
6027 --- linux-2.6.32.56/fs/nfsd/auth.c      2009-12-03 20:02:52.000000000 +0100
6028 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/nfsd/auth.c      2011-06-10 13:03:02.000000000 +0200
6029 @@ -10,6 +10,7 @@
6030  #include <linux/sunrpc/svcauth.h>
6031  #include <linux/nfsd/nfsd.h>
6032  #include <linux/nfsd/export.h>
6033 +#include <linux/vs_tag.h>
6034  #include "auth.h"
6035  
6036  int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp)
6037 @@ -44,6 +45,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
6038  
6039         new->fsuid = rqstp->rq_cred.cr_uid;
6040         new->fsgid = rqstp->rq_cred.cr_gid;
6041 +       /* FIXME: this desperately needs a tag :)
6042 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
6043 +                       */
6044  
6045         rqgi = rqstp->rq_cred.cr_group_info;
6046  
6047 diff -NurpP --minimal linux-2.6.32.56/fs/nfsd/nfs3xdr.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/nfsd/nfs3xdr.c
6048 --- linux-2.6.32.56/fs/nfsd/nfs3xdr.c   2012-02-09 10:22:30.000000000 +0100
6049 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/nfsd/nfs3xdr.c   2011-06-10 13:03:02.000000000 +0200
6050 @@ -21,6 +21,7 @@
6051  #include <linux/sunrpc/svc.h>
6052  #include <linux/nfsd/nfsd.h>
6053  #include <linux/nfsd/xdr3.h>
6054 +#include <linux/vs_tag.h>
6055  #include "auth.h"
6056  
6057  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6058 @@ -108,6 +109,8 @@ static __be32 *
6059  decode_sattr3(__be32 *p, struct iattr *iap)
6060  {
6061         u32     tmp;
6062 +       uid_t   uid = 0;
6063 +       gid_t   gid = 0;
6064  
6065         iap->ia_valid = 0;
6066  
6067 @@ -117,12 +120,15 @@ decode_sattr3(__be32 *p, struct iattr *i
6068         }
6069         if (*p++) {
6070                 iap->ia_valid |= ATTR_UID;
6071 -               iap->ia_uid = ntohl(*p++);
6072 +               uid = ntohl(*p++);
6073         }
6074         if (*p++) {
6075                 iap->ia_valid |= ATTR_GID;
6076 -               iap->ia_gid = ntohl(*p++);
6077 +               gid = ntohl(*p++);
6078         }
6079 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6080 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6081 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6082         if (*p++) {
6083                 u64     newsize;
6084  
6085 @@ -178,8 +184,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
6086         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
6087         *p++ = htonl((u32) stat->mode);
6088         *p++ = htonl((u32) stat->nlink);
6089 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6090 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6091 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6092 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6093 +               stat->uid, stat->tag)));
6094 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6095 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6096 +               stat->gid, stat->tag)));
6097         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
6098                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
6099         } else {
6100 diff -NurpP --minimal linux-2.6.32.56/fs/nfsd/nfs4xdr.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/nfsd/nfs4xdr.c
6101 --- linux-2.6.32.56/fs/nfsd/nfs4xdr.c   2012-02-09 10:22:30.000000000 +0100
6102 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/nfsd/nfs4xdr.c   2011-06-10 13:03:02.000000000 +0200
6103 @@ -57,6 +57,7 @@
6104  #include <linux/nfs4_acl.h>
6105  #include <linux/sunrpc/gss_api.h>
6106  #include <linux/sunrpc/svcauth_gss.h>
6107 +#include <linux/vs_tag.h>
6108  
6109  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6110  
6111 @@ -2047,14 +2048,18 @@ out_acl:
6112                 WRITE32(stat.nlink);
6113         }
6114         if (bmval1 & FATTR4_WORD1_OWNER) {
6115 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
6116 +               status = nfsd4_encode_user(rqstp,
6117 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
6118 +                       stat.uid, stat.tag), &p, &buflen);
6119                 if (status == nfserr_resource)
6120                         goto out_resource;
6121                 if (status)
6122                         goto out;
6123         }
6124         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
6125 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
6126 +               status = nfsd4_encode_group(rqstp,
6127 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
6128 +                       stat.gid, stat.tag), &p, &buflen);
6129                 if (status == nfserr_resource)
6130                         goto out_resource;
6131                 if (status)
6132 diff -NurpP --minimal linux-2.6.32.56/fs/nfsd/nfsxdr.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/nfsd/nfsxdr.c
6133 --- linux-2.6.32.56/fs/nfsd/nfsxdr.c    2008-12-25 00:26:37.000000000 +0100
6134 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/nfsd/nfsxdr.c    2011-06-10 13:03:02.000000000 +0200
6135 @@ -15,6 +15,7 @@
6136  #include <linux/nfsd/nfsd.h>
6137  #include <linux/nfsd/xdr.h>
6138  #include <linux/mm.h>
6139 +#include <linux/vs_tag.h>
6140  #include "auth.h"
6141  
6142  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6143 @@ -98,6 +99,8 @@ static __be32 *
6144  decode_sattr(__be32 *p, struct iattr *iap)
6145  {
6146         u32     tmp, tmp1;
6147 +       uid_t   uid = 0;
6148 +       gid_t   gid = 0;
6149  
6150         iap->ia_valid = 0;
6151  
6152 @@ -111,12 +114,15 @@ decode_sattr(__be32 *p, struct iattr *ia
6153         }
6154         if ((tmp = ntohl(*p++)) != (u32)-1) {
6155                 iap->ia_valid |= ATTR_UID;
6156 -               iap->ia_uid = tmp;
6157 +               uid = tmp;
6158         }
6159         if ((tmp = ntohl(*p++)) != (u32)-1) {
6160                 iap->ia_valid |= ATTR_GID;
6161 -               iap->ia_gid = tmp;
6162 +               gid = tmp;
6163         }
6164 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6165 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6166 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6167         if ((tmp = ntohl(*p++)) != (u32)-1) {
6168                 iap->ia_valid |= ATTR_SIZE;
6169                 iap->ia_size = tmp;
6170 @@ -161,8 +167,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
6171         *p++ = htonl(nfs_ftypes[type >> 12]);
6172         *p++ = htonl((u32) stat->mode);
6173         *p++ = htonl((u32) stat->nlink);
6174 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6175 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6176 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6177 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
6178 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6179 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
6180  
6181         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
6182                 *p++ = htonl(NFS_MAXPATHLEN);
6183 diff -NurpP --minimal linux-2.6.32.56/fs/ocfs2/dlm/dlmfs.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/ocfs2/dlm/dlmfs.c
6184 --- linux-2.6.32.56/fs/ocfs2/dlm/dlmfs.c        2012-02-09 10:22:30.000000000 +0100
6185 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/ocfs2/dlm/dlmfs.c        2011-06-10 13:03:02.000000000 +0200
6186 @@ -43,6 +43,7 @@
6187  #include <linux/init.h>
6188  #include <linux/string.h>
6189  #include <linux/backing-dev.h>
6190 +#include <linux/vs_tag.h>
6191  
6192  #include <asm/uaccess.h>
6193  
6194 @@ -342,6 +343,7 @@ static struct inode *dlmfs_get_root_inod
6195                 inode->i_mode = mode;
6196                 inode->i_uid = current_fsuid();
6197                 inode->i_gid = current_fsgid();
6198 +               inode->i_tag = dx_current_fstag(sb);
6199                 inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
6200                 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
6201                 inc_nlink(inode);
6202 @@ -367,6 +369,7 @@ static struct inode *dlmfs_get_inode(str
6203         inode->i_mode = mode;
6204         inode->i_uid = current_fsuid();
6205         inode->i_gid = current_fsgid();
6206 +       inode->i_tag = dx_current_fstag(sb);
6207         inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
6208         inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
6209  
6210 diff -NurpP --minimal linux-2.6.32.56/fs/ocfs2/dlmglue.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/ocfs2/dlmglue.c
6211 --- linux-2.6.32.56/fs/ocfs2/dlmglue.c  2009-12-03 20:02:53.000000000 +0100
6212 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/ocfs2/dlmglue.c  2011-06-10 13:03:02.000000000 +0200
6213 @@ -1991,6 +1991,7 @@ static void __ocfs2_stuff_meta_lvb(struc
6214         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
6215         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
6216         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
6217 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
6218         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
6219         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
6220         lvb->lvb_iatime_packed  =
6221 @@ -2045,6 +2046,7 @@ static void ocfs2_refresh_inode_from_lvb
6222  
6223         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
6224         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
6225 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
6226         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
6227         inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
6228         ocfs2_unpack_timespec(&inode->i_atime,
6229 diff -NurpP --minimal linux-2.6.32.56/fs/ocfs2/dlmglue.h linux-2.6.32.56-vs2.3.0.36.29.9/fs/ocfs2/dlmglue.h
6230 --- linux-2.6.32.56/fs/ocfs2/dlmglue.h  2009-12-03 20:02:53.000000000 +0100
6231 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/ocfs2/dlmglue.h  2011-06-10 13:03:02.000000000 +0200
6232 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
6233         __be16       lvb_inlink;
6234         __be32       lvb_iattr;
6235         __be32       lvb_igeneration;
6236 -       __be32       lvb_reserved2;
6237 +       __be16       lvb_itag;
6238 +       __be16       lvb_reserved2;
6239  };
6240  
6241  #define OCFS2_QINFO_LVB_VERSION 1
6242 diff -NurpP --minimal linux-2.6.32.56/fs/ocfs2/file.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/ocfs2/file.c
6243 --- linux-2.6.32.56/fs/ocfs2/file.c     2009-12-03 20:02:53.000000000 +0100
6244 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/ocfs2/file.c     2011-06-10 13:03:02.000000000 +0200
6245 @@ -960,13 +960,15 @@ int ocfs2_setattr(struct dentry *dentry,
6246                 mlog(0, "uid change: %d\n", attr->ia_uid);
6247         if (attr->ia_valid & ATTR_GID)
6248                 mlog(0, "gid change: %d\n", attr->ia_gid);
6249 +       if (attr->ia_valid & ATTR_TAG)
6250 +               mlog(0, "tag change: %d\n", attr->ia_tag);
6251         if (attr->ia_valid & ATTR_SIZE)
6252                 mlog(0, "size change...\n");
6253         if (attr->ia_valid & (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME))
6254                 mlog(0, "time change...\n");
6255  
6256  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
6257 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
6258 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
6259         if (!(attr->ia_valid & OCFS2_VALID_ATTRS)) {
6260                 mlog(0, "can't handle attrs: 0x%x\n", attr->ia_valid);
6261                 return 0;
6262 diff -NurpP --minimal linux-2.6.32.56/fs/ocfs2/inode.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/ocfs2/inode.c
6263 --- linux-2.6.32.56/fs/ocfs2/inode.c    2012-02-09 10:22:30.000000000 +0100
6264 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/ocfs2/inode.c    2011-06-10 13:03:02.000000000 +0200
6265 @@ -29,6 +29,7 @@
6266  #include <linux/highmem.h>
6267  #include <linux/pagemap.h>
6268  #include <linux/quotaops.h>
6269 +#include <linux/vs_tag.h>
6270  
6271  #include <asm/byteorder.h>
6272  
6273 @@ -79,11 +80,13 @@ void ocfs2_set_inode_flags(struct inode 
6274  {
6275         unsigned int flags = OCFS2_I(inode)->ip_attr;
6276  
6277 -       inode->i_flags &= ~(S_IMMUTABLE |
6278 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
6279                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
6280  
6281         if (flags & OCFS2_IMMUTABLE_FL)
6282                 inode->i_flags |= S_IMMUTABLE;
6283 +       if (flags & OCFS2_IXUNLINK_FL)
6284 +               inode->i_flags |= S_IXUNLINK;
6285  
6286         if (flags & OCFS2_SYNC_FL)
6287                 inode->i_flags |= S_SYNC;
6288 @@ -93,25 +96,44 @@ void ocfs2_set_inode_flags(struct inode 
6289                 inode->i_flags |= S_NOATIME;
6290         if (flags & OCFS2_DIRSYNC_FL)
6291                 inode->i_flags |= S_DIRSYNC;
6292 +
6293 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
6294 +
6295 +       if (flags & OCFS2_BARRIER_FL)
6296 +               inode->i_vflags |= V_BARRIER;
6297 +       if (flags & OCFS2_COW_FL)
6298 +               inode->i_vflags |= V_COW;
6299  }
6300  
6301  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
6302  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
6303  {
6304         unsigned int flags = oi->vfs_inode.i_flags;
6305 +       unsigned int vflags = oi->vfs_inode.i_vflags;
6306 +
6307 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
6308 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
6309 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
6310 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
6311 +
6312 +       if (flags & S_IMMUTABLE)
6313 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6314 +       if (flags & S_IXUNLINK)
6315 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
6316  
6317 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
6318 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
6319         if (flags & S_SYNC)
6320                 oi->ip_attr |= OCFS2_SYNC_FL;
6321         if (flags & S_APPEND)
6322                 oi->ip_attr |= OCFS2_APPEND_FL;
6323 -       if (flags & S_IMMUTABLE)
6324 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6325         if (flags & S_NOATIME)
6326                 oi->ip_attr |= OCFS2_NOATIME_FL;
6327         if (flags & S_DIRSYNC)
6328                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
6329 +
6330 +       if (vflags & V_BARRIER)
6331 +               oi->ip_attr |= OCFS2_BARRIER_FL;
6332 +       if (vflags & V_COW)
6333 +               oi->ip_attr |= OCFS2_COW_FL;
6334  }
6335  
6336  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
6337 @@ -246,6 +268,8 @@ void ocfs2_populate_inode(struct inode *
6338         struct super_block *sb;
6339         struct ocfs2_super *osb;
6340         int use_plocks = 1;
6341 +       uid_t uid;
6342 +       gid_t gid;
6343  
6344         mlog_entry("(0x%p, size:%llu)\n", inode,
6345                    (unsigned long long)le64_to_cpu(fe->i_size));
6346 @@ -277,8 +301,12 @@ void ocfs2_populate_inode(struct inode *
6347         inode->i_generation = le32_to_cpu(fe->i_generation);
6348         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
6349         inode->i_mode = le16_to_cpu(fe->i_mode);
6350 -       inode->i_uid = le32_to_cpu(fe->i_uid);
6351 -       inode->i_gid = le32_to_cpu(fe->i_gid);
6352 +       uid = le32_to_cpu(fe->i_uid);
6353 +       gid = le32_to_cpu(fe->i_gid);
6354 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6355 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6356 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
6357 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
6358  
6359         /* Fast symlinks will have i_size but no allocated clusters. */
6360         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
6361 diff -NurpP --minimal linux-2.6.32.56/fs/ocfs2/inode.h linux-2.6.32.56-vs2.3.0.36.29.9/fs/ocfs2/inode.h
6362 --- linux-2.6.32.56/fs/ocfs2/inode.h    2009-12-03 20:02:53.000000000 +0100
6363 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/ocfs2/inode.h    2011-06-10 13:03:02.000000000 +0200
6364 @@ -150,6 +150,7 @@ struct buffer_head *ocfs2_bread(struct i
6365  
6366  void ocfs2_set_inode_flags(struct inode *inode);
6367  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
6368 +int ocfs2_sync_flags(struct inode *inode, int, int);
6369  
6370  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
6371  {
6372 diff -NurpP --minimal linux-2.6.32.56/fs/ocfs2/ioctl.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/ocfs2/ioctl.c
6373 --- linux-2.6.32.56/fs/ocfs2/ioctl.c    2009-12-03 20:02:53.000000000 +0100
6374 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/ocfs2/ioctl.c    2011-06-10 13:03:02.000000000 +0200
6375 @@ -42,7 +42,41 @@ static int ocfs2_get_inode_attr(struct i
6376         return status;
6377  }
6378  
6379 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6380 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
6381 +{
6382 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
6383 +       struct buffer_head *bh = NULL;
6384 +       handle_t *handle = NULL;
6385 +       int status;
6386 +
6387 +       status = ocfs2_inode_lock(inode, &bh, 1);
6388 +       if (status < 0) {
6389 +               mlog_errno(status);
6390 +               return status;
6391 +       }
6392 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6393 +       if (IS_ERR(handle)) {
6394 +               status = PTR_ERR(handle);
6395 +               mlog_errno(status);
6396 +               goto bail_unlock;
6397 +       }
6398 +
6399 +       inode->i_flags = flags;
6400 +       inode->i_vflags = vflags;
6401 +       ocfs2_get_inode_flags(OCFS2_I(inode));
6402 +
6403 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
6404 +       if (status < 0)
6405 +               mlog_errno(status);
6406 +
6407 +       ocfs2_commit_trans(osb, handle);
6408 +bail_unlock:
6409 +       ocfs2_inode_unlock(inode, 1);
6410 +       brelse(bh);
6411 +       return status;
6412 +}
6413 +
6414 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6415                                 unsigned mask)
6416  {
6417         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
6418 @@ -67,6 +101,11 @@ static int ocfs2_set_inode_attr(struct i
6419         if (!S_ISDIR(inode->i_mode))
6420                 flags &= ~OCFS2_DIRSYNC_FL;
6421  
6422 +       if (IS_BARRIER(inode)) {
6423 +               vxwprintk_task(1, "messing with the barrier.");
6424 +               goto bail_unlock;
6425 +       }
6426 +
6427         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6428         if (IS_ERR(handle)) {
6429                 status = PTR_ERR(handle);
6430 @@ -108,6 +147,7 @@ bail:
6431         return status;
6432  }
6433  
6434 +
6435  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
6436  {
6437         struct inode *inode = filp->f_path.dentry->d_inode;
6438 diff -NurpP --minimal linux-2.6.32.56/fs/ocfs2/namei.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/ocfs2/namei.c
6439 --- linux-2.6.32.56/fs/ocfs2/namei.c    2009-12-03 20:02:53.000000000 +0100
6440 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/ocfs2/namei.c    2011-06-10 13:03:02.000000000 +0200
6441 @@ -41,6 +41,7 @@
6442  #include <linux/slab.h>
6443  #include <linux/highmem.h>
6444  #include <linux/quotaops.h>
6445 +#include <linux/vs_tag.h>
6446  
6447  #define MLOG_MASK_PREFIX ML_NAMEI
6448  #include <cluster/masklog.h>
6449 @@ -481,6 +482,7 @@ static int ocfs2_mknod_locked(struct ocf
6450         u64 fe_blkno = 0;
6451         u16 suballoc_bit;
6452         u16 feat;
6453 +       tag_t tag;
6454  
6455         *new_fe_bh = NULL;
6456  
6457 @@ -524,8 +526,11 @@ static int ocfs2_mknod_locked(struct ocf
6458         fe->i_blkno = cpu_to_le64(fe_blkno);
6459         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
6460         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
6461 -       fe->i_uid = cpu_to_le32(inode->i_uid);
6462 -       fe->i_gid = cpu_to_le32(inode->i_gid);
6463 +
6464 +       tag = dx_current_fstag(osb->sb);
6465 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
6466 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
6467 +       inode->i_tag = tag;
6468         fe->i_mode = cpu_to_le16(inode->i_mode);
6469         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
6470                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
6471 diff -NurpP --minimal linux-2.6.32.56/fs/ocfs2/ocfs2.h linux-2.6.32.56-vs2.3.0.36.29.9/fs/ocfs2/ocfs2.h
6472 --- linux-2.6.32.56/fs/ocfs2/ocfs2.h    2009-12-03 20:02:53.000000000 +0100
6473 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/ocfs2/ocfs2.h    2011-06-10 13:03:02.000000000 +0200
6474 @@ -248,6 +248,7 @@ enum ocfs2_mount_options
6475         OCFS2_MOUNT_POSIX_ACL = 1 << 8, /* POSIX access control lists */
6476         OCFS2_MOUNT_USRQUOTA = 1 << 9, /* We support user quotas */
6477         OCFS2_MOUNT_GRPQUOTA = 1 << 10, /* We support group quotas */
6478 +       OCFS2_MOUNT_TAGGED = 1 << 11, /* use tagging */
6479  };
6480  
6481  #define OCFS2_OSB_SOFT_RO                      0x0001
6482 diff -NurpP --minimal linux-2.6.32.56/fs/ocfs2/ocfs2_fs.h linux-2.6.32.56-vs2.3.0.36.29.9/fs/ocfs2/ocfs2_fs.h
6483 --- linux-2.6.32.56/fs/ocfs2/ocfs2_fs.h 2009-12-03 20:02:53.000000000 +0100
6484 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/ocfs2/ocfs2_fs.h 2011-06-10 13:03:02.000000000 +0200
6485 @@ -231,18 +231,23 @@
6486  #define OCFS2_HAS_REFCOUNT_FL   (0x0010)
6487  
6488  /* Inode attributes, keep in sync with EXT2 */
6489 -#define OCFS2_SECRM_FL         (0x00000001)    /* Secure deletion */
6490 -#define OCFS2_UNRM_FL          (0x00000002)    /* Undelete */
6491 -#define OCFS2_COMPR_FL         (0x00000004)    /* Compress file */
6492 -#define OCFS2_SYNC_FL          (0x00000008)    /* Synchronous updates */
6493 -#define OCFS2_IMMUTABLE_FL     (0x00000010)    /* Immutable file */
6494 -#define OCFS2_APPEND_FL                (0x00000020)    /* writes to file may only append */
6495 -#define OCFS2_NODUMP_FL                (0x00000040)    /* do not dump file */
6496 -#define OCFS2_NOATIME_FL       (0x00000080)    /* do not update atime */
6497 -#define OCFS2_DIRSYNC_FL       (0x00010000)    /* dirsync behaviour (directories only) */
6498 +#define OCFS2_SECRM_FL         FS_SECRM_FL     /* Secure deletion */
6499 +#define OCFS2_UNRM_FL          FS_UNRM_FL      /* Undelete */
6500 +#define OCFS2_COMPR_FL         FS_COMPR_FL     /* Compress file */
6501 +#define OCFS2_SYNC_FL          FS_SYNC_FL      /* Synchronous updates */
6502 +#define OCFS2_IMMUTABLE_FL     FS_IMMUTABLE_FL /* Immutable file */
6503 +#define OCFS2_APPEND_FL                FS_APPEND_FL    /* writes to file may only append */
6504 +#define OCFS2_NODUMP_FL                FS_NODUMP_FL    /* do not dump file */
6505 +#define OCFS2_NOATIME_FL       FS_NOATIME_FL   /* do not update atime */
6506  
6507 -#define OCFS2_FL_VISIBLE       (0x000100FF)    /* User visible flags */
6508 -#define OCFS2_FL_MODIFIABLE    (0x000100FF)    /* User modifiable flags */
6509 +#define OCFS2_DIRSYNC_FL       FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
6510 +#define OCFS2_IXUNLINK_FL      FS_IXUNLINK_FL  /* Immutable invert on unlink */
6511 +
6512 +#define OCFS2_BARRIER_FL       FS_BARRIER_FL   /* Barrier for chroot() */
6513 +#define OCFS2_COW_FL           FS_COW_FL       /* Copy on Write marker */
6514 +
6515 +#define OCFS2_FL_VISIBLE       (0x010300FF)    /* User visible flags */
6516 +#define OCFS2_FL_MODIFIABLE    (0x010300FF)    /* User modifiable flags */
6517  
6518  /*
6519   * Extent record flags (e_node.leaf.flags)
6520 diff -NurpP --minimal linux-2.6.32.56/fs/ocfs2/super.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/ocfs2/super.c
6521 --- linux-2.6.32.56/fs/ocfs2/super.c    2012-02-09 10:22:30.000000000 +0100
6522 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/ocfs2/super.c    2011-06-10 13:03:02.000000000 +0200
6523 @@ -173,6 +173,7 @@ enum {
6524         Opt_noacl,
6525         Opt_usrquota,
6526         Opt_grpquota,
6527 +       Opt_tag, Opt_notag, Opt_tagid,
6528         Opt_err,
6529  };
6530  
6531 @@ -199,6 +200,9 @@ static const match_table_t tokens = {
6532         {Opt_noacl, "noacl"},
6533         {Opt_usrquota, "usrquota"},
6534         {Opt_grpquota, "grpquota"},
6535 +       {Opt_tag, "tag"},
6536 +       {Opt_notag, "notag"},
6537 +       {Opt_tagid, "tagid=%u"},
6538         {Opt_err, NULL}
6539  };
6540  
6541 @@ -605,6 +609,13 @@ static int ocfs2_remount(struct super_bl
6542                 goto out;
6543         }
6544  
6545 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
6546 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
6547 +               ret = -EINVAL;
6548 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
6549 +               goto out;
6550 +       }
6551 +
6552         if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
6553             (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
6554                 ret = -EINVAL;
6555 @@ -1152,6 +1163,9 @@ static int ocfs2_fill_super(struct super
6556  
6557         ocfs2_complete_mount_recovery(osb);
6558  
6559 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
6560 +               sb->s_flags |= MS_TAGGED;
6561 +
6562         if (ocfs2_mount_local(osb))
6563                 snprintf(nodestr, sizeof(nodestr), "local");
6564         else
6565 @@ -1430,6 +1444,20 @@ static int ocfs2_parse_options(struct su
6566                         printk(KERN_INFO "ocfs2 (no)acl options not supported\n");
6567                         break;
6568  #endif
6569 +#ifndef CONFIG_TAGGING_NONE
6570 +               case Opt_tag:
6571 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6572 +                       break;
6573 +               case Opt_notag:
6574 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
6575 +                       break;
6576 +#endif
6577 +#ifdef CONFIG_PROPAGATE
6578 +               case Opt_tagid:
6579 +                       /* use args[0] */
6580 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6581 +                       break;
6582 +#endif
6583                 default:
6584                         mlog(ML_ERROR,
6585                              "Unrecognized mount option \"%s\" "
6586 diff -NurpP --minimal linux-2.6.32.56/fs/open.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/open.c
6587 --- linux-2.6.32.56/fs/open.c   2009-12-03 20:02:53.000000000 +0100
6588 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/open.c   2011-06-10 13:03:02.000000000 +0200
6589 @@ -30,22 +30,30 @@
6590  #include <linux/audit.h>
6591  #include <linux/falloc.h>
6592  #include <linux/fs_struct.h>
6593 +#include <linux/vs_base.h>
6594 +#include <linux/vs_limit.h>
6595 +#include <linux/vs_tag.h>
6596 +#include <linux/vs_cowbl.h>
6597  
6598  int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)
6599  {
6600         int retval = -ENODEV;
6601  
6602         if (dentry) {
6603 +               struct super_block *sb = dentry->d_sb;
6604 +
6605                 retval = -ENOSYS;
6606 -               if (dentry->d_sb->s_op->statfs) {
6607 +               if (sb->s_op->statfs) {
6608                         memset(buf, 0, sizeof(*buf));
6609                         retval = security_sb_statfs(dentry);
6610                         if (retval)
6611                                 return retval;
6612 -                       retval = dentry->d_sb->s_op->statfs(dentry, buf);
6613 +                       retval = sb->s_op->statfs(dentry, buf);
6614                         if (retval == 0 && buf->f_frsize == 0)
6615                                 buf->f_frsize = buf->f_bsize;
6616                 }
6617 +               if (!vx_check(0, VS_ADMIN|VS_WATCH))
6618 +                       vx_vsi_statfs(sb, buf);
6619         }
6620         return retval;
6621  }
6622 @@ -640,6 +648,10 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6623         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
6624         if (error)
6625                 goto out;
6626 +
6627 +       error = cow_check_and_break(&path);
6628 +       if (error)
6629 +               goto dput_and_out;
6630         inode = path.dentry->d_inode;
6631  
6632         error = mnt_want_write(path.mnt);
6633 @@ -673,11 +685,11 @@ static int chown_common(struct dentry * 
6634         newattrs.ia_valid =  ATTR_CTIME;
6635         if (user != (uid_t) -1) {
6636                 newattrs.ia_valid |= ATTR_UID;
6637 -               newattrs.ia_uid = user;
6638 +               newattrs.ia_uid = dx_map_uid(user);
6639         }
6640         if (group != (gid_t) -1) {
6641                 newattrs.ia_valid |= ATTR_GID;
6642 -               newattrs.ia_gid = group;
6643 +               newattrs.ia_gid = dx_map_gid(group);
6644         }
6645         if (!S_ISDIR(inode->i_mode))
6646                 newattrs.ia_valid |=
6647 @@ -700,7 +712,11 @@ SYSCALL_DEFINE3(chown, const char __user
6648         error = mnt_want_write(path.mnt);
6649         if (error)
6650                 goto out_release;
6651 -       error = chown_common(path.dentry, user, group);
6652 +#ifdef CONFIG_VSERVER_COWBL
6653 +       error = cow_check_and_break(&path);
6654 +       if (!error)
6655 +#endif
6656 +               error = chown_common(path.dentry, user, group);
6657         mnt_drop_write(path.mnt);
6658  out_release:
6659         path_put(&path);
6660 @@ -725,7 +741,11 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
6661         error = mnt_want_write(path.mnt);
6662         if (error)
6663                 goto out_release;
6664 -       error = chown_common(path.dentry, user, group);
6665 +#ifdef CONFIG_VSERVER_COWBL
6666 +       error = cow_check_and_break(&path);
6667 +       if (!error)
6668 +#endif
6669 +               error = chown_common(path.dentry, user, group);
6670         mnt_drop_write(path.mnt);
6671  out_release:
6672         path_put(&path);
6673 @@ -744,7 +764,11 @@ SYSCALL_DEFINE3(lchown, const char __use
6674         error = mnt_want_write(path.mnt);
6675         if (error)
6676                 goto out_release;
6677 -       error = chown_common(path.dentry, user, group);
6678 +#ifdef CONFIG_VSERVER_COWBL
6679 +       error = cow_check_and_break(&path);
6680 +       if (!error)
6681 +#endif
6682 +               error = chown_common(path.dentry, user, group);
6683         mnt_drop_write(path.mnt);
6684  out_release:
6685         path_put(&path);
6686 @@ -990,6 +1014,7 @@ static void __put_unused_fd(struct files
6687         __FD_CLR(fd, fdt->open_fds);
6688         if (fd < files->next_fd)
6689                 files->next_fd = fd;
6690 +       vx_openfd_dec(fd);
6691  }
6692  
6693  void put_unused_fd(unsigned int fd)
6694 diff -NurpP --minimal linux-2.6.32.56/fs/proc/array.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/proc/array.c
6695 --- linux-2.6.32.56/fs/proc/array.c     2012-02-09 10:22:30.000000000 +0100
6696 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/proc/array.c     2011-06-10 18:44:08.000000000 +0200
6697 @@ -82,6 +82,8 @@
6698  #include <linux/pid_namespace.h>
6699  #include <linux/ptrace.h>
6700  #include <linux/tracehook.h>
6701 +#include <linux/vs_context.h>
6702 +#include <linux/vs_network.h>
6703  
6704  #include <asm/pgtable.h>
6705  #include <asm/processor.h>
6706 @@ -166,6 +168,9 @@ static inline void task_state(struct seq
6707         rcu_read_lock();
6708         ppid = pid_alive(p) ?
6709                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6710 +       if (unlikely(vx_current_initpid(p->pid)))
6711 +               ppid = 0;
6712 +
6713         tpid = 0;
6714         if (pid_alive(p)) {
6715                 struct task_struct *tracer = tracehook_tracer_task(p);
6716 @@ -281,7 +286,7 @@ static inline void task_sig(struct seq_f
6717  }
6718  
6719  static void render_cap_t(struct seq_file *m, const char *header,
6720 -                       kernel_cap_t *a)
6721 +                       struct vx_info *vxi, kernel_cap_t *a)
6722  {
6723         unsigned __capi;
6724  
6725 @@ -306,10 +311,11 @@ static inline void task_cap(struct seq_f
6726         cap_bset        = cred->cap_bset;
6727         rcu_read_unlock();
6728  
6729 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6730 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6731 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6732 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6733 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6734 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6735 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6736 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6737 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6738  }
6739  
6740  static inline void task_context_switch_counts(struct seq_file *m,
6741 @@ -321,6 +327,43 @@ static inline void task_context_switch_c
6742                         p->nivcsw);
6743  }
6744  
6745 +
6746 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6747 +                       struct pid *pid, struct task_struct *task)
6748 +{
6749 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6750 +                       "Count:\t%u\n"
6751 +                       "uts:\t%p(%c)\n"
6752 +                       "ipc:\t%p(%c)\n"
6753 +                       "mnt:\t%p(%c)\n"
6754 +                       "pid:\t%p(%c)\n"
6755 +                       "net:\t%p(%c)\n",
6756 +                       task->nsproxy,
6757 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6758 +                       atomic_read(&task->nsproxy->count),
6759 +                       task->nsproxy->uts_ns,
6760 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6761 +                       task->nsproxy->ipc_ns,
6762 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6763 +                       task->nsproxy->mnt_ns,
6764 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6765 +                       task->nsproxy->pid_ns,
6766 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6767 +                       task->nsproxy->net_ns,
6768 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6769 +       return 0;
6770 +}
6771 +
6772 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6773 +{
6774 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6775 +               return;
6776 +
6777 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6778 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6779 +}
6780 +
6781 +
6782  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6783                         struct pid *pid, struct task_struct *task)
6784  {
6785 @@ -336,6 +379,7 @@ int proc_pid_status(struct seq_file *m, 
6786         task_sig(m, task);
6787         task_cap(m, task);
6788         cpuset_task_status_allowed(m, task);
6789 +       task_vs_id(m, task);
6790         task_context_switch_counts(m, task);
6791         return 0;
6792  }
6793 @@ -446,6 +490,17 @@ static int do_task_stat(struct seq_file 
6794         /* convert nsec -> ticks */
6795         start_time = nsec_to_clock_t(start_time);
6796  
6797 +       /* fixup start time for virt uptime */
6798 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6799 +               unsigned long long bias =
6800 +                       current->vx_info->cvirt.bias_clock;
6801 +
6802 +               if (start_time > bias)
6803 +                       start_time -= bias;
6804 +               else
6805 +                       start_time = 0;
6806 +       }
6807 +
6808         seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \
6809  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
6810  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
6811 diff -NurpP --minimal linux-2.6.32.56/fs/proc/base.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/proc/base.c
6812 --- linux-2.6.32.56/fs/proc/base.c      2012-02-09 10:22:30.000000000 +0100
6813 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/proc/base.c      2011-11-17 12:18:26.000000000 +0100
6814 @@ -81,6 +81,8 @@
6815  #include <linux/elf.h>
6816  #include <linux/pid_namespace.h>
6817  #include <linux/fs_struct.h>
6818 +#include <linux/vs_context.h>
6819 +#include <linux/vs_network.h>
6820  #include "internal.h"
6821  
6822  /* NOTE:
6823 @@ -1075,12 +1077,17 @@ static ssize_t oom_adjust_write(struct f
6824                 return -ESRCH;
6825         }
6826  
6827 -       if (oom_adjust < task->signal->oom_adj && !capable(CAP_SYS_RESOURCE)) {
6828 +       if (oom_adjust < task->signal->oom_adj &&
6829 +               !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6830                 unlock_task_sighand(task, &flags);
6831                 put_task_struct(task);
6832                 return -EACCES;
6833         }
6834  
6835 +       /* prevent guest processes from circumventing the oom killer */
6836 +       if (vx_current_xid() && (oom_adjust == OOM_DISABLE))
6837 +               oom_adjust = OOM_ADJUST_MIN;
6838 +
6839         task->signal->oom_adj = oom_adjust;
6840  
6841         unlock_task_sighand(task, &flags);
6842 @@ -1120,7 +1127,7 @@ static ssize_t proc_loginuid_write(struc
6843         ssize_t length;
6844         uid_t loginuid;
6845  
6846 -       if (!capable(CAP_AUDIT_CONTROL))
6847 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
6848                 return -EPERM;
6849  
6850         if (current != pid_task(proc_pid(inode), PIDTYPE_PID))
6851 @@ -1486,6 +1493,8 @@ static struct inode *proc_pid_make_inode
6852                 inode->i_gid = cred->egid;
6853                 rcu_read_unlock();
6854         }
6855 +       /* procfs is xid tagged */
6856 +       inode->i_tag = (tag_t)vx_task_xid(task);
6857         security_task_to_inode(task, inode);
6858  
6859  out:
6860 @@ -2036,6 +2045,13 @@ static struct dentry *proc_pident_lookup
6861         if (!task)
6862                 goto out_no_task;
6863  
6864 +       /* TODO: maybe we can come up with a generic approach? */
6865 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6866 +               (dentry->d_name.len == 5) &&
6867 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6868 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6869 +               goto out;
6870 +
6871         /*
6872          * Yes, it does not scale. And it should not. Don't add
6873          * new entries into /proc/<tgid>/ without very good reasons.
6874 @@ -2441,7 +2457,7 @@ out_iput:
6875  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
6876  {
6877         struct dentry *error;
6878 -       struct task_struct *task = get_proc_task(dir);
6879 +       struct task_struct *task = get_proc_task_real(dir);
6880         const struct pid_entry *p, *last;
6881  
6882         error = ERR_PTR(-ENOENT);
6883 @@ -2538,6 +2554,9 @@ static int proc_pid_personality(struct s
6884  static const struct file_operations proc_task_operations;
6885  static const struct inode_operations proc_task_inode_operations;
6886  
6887 +extern int proc_pid_vx_info(struct task_struct *, char *);
6888 +extern int proc_pid_nx_info(struct task_struct *, char *);
6889 +
6890  static const struct pid_entry tgid_base_stuff[] = {
6891         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6892         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6893 @@ -2596,6 +2615,8 @@ static const struct pid_entry tgid_base_
6894  #ifdef CONFIG_CGROUPS
6895         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6896  #endif
6897 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6898 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6899         INF("oom_score",  S_IRUGO, proc_oom_score),
6900         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
6901  #ifdef CONFIG_AUDITSYSCALL
6902 @@ -2611,6 +2632,7 @@ static const struct pid_entry tgid_base_
6903  #ifdef CONFIG_TASK_IO_ACCOUNTING
6904         INF("io",       S_IRUSR, proc_tgid_io_accounting),
6905  #endif
6906 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6907  };
6908  
6909  static int proc_tgid_base_readdir(struct file * filp,
6910 @@ -2802,7 +2824,7 @@ retry:
6911         iter.task = NULL;
6912         pid = find_ge_pid(iter.tgid, ns);
6913         if (pid) {
6914 -               iter.tgid = pid_nr_ns(pid, ns);
6915 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6916                 iter.task = pid_task(pid, PIDTYPE_PID);
6917                 /* What we to know is if the pid we have find is the
6918                  * pid of a thread_group_leader.  Testing for task
6919 @@ -2832,7 +2854,7 @@ static int proc_pid_fill_cache(struct fi
6920         struct tgid_iter iter)
6921  {
6922         char name[PROC_NUMBUF];
6923 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6924 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6925         return proc_fill_cache(filp, dirent, filldir, name, len,
6926                                 proc_pid_instantiate, iter.task, NULL);
6927  }
6928 @@ -2849,7 +2871,7 @@ int proc_pid_readdir(struct file * filp,
6929                 goto out_no_task;
6930         nr = filp->f_pos - FIRST_PROCESS_ENTRY;
6931  
6932 -       reaper = get_proc_task(filp->f_path.dentry->d_inode);
6933 +       reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
6934         if (!reaper)
6935                 goto out_no_task;
6936  
6937 @@ -2866,6 +2888,8 @@ int proc_pid_readdir(struct file * filp,
6938              iter.task;
6939              iter.tgid += 1, iter = next_tgid(ns, iter)) {
6940                 filp->f_pos = iter.tgid + TGID_OFFSET;
6941 +               if (!vx_proc_task_visible(iter.task))
6942 +                       continue;
6943                 if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
6944                         put_task_struct(iter.task);
6945                         goto out;
6946 @@ -3012,6 +3036,8 @@ static struct dentry *proc_task_lookup(s
6947         tid = name_to_int(dentry);
6948         if (tid == ~0U)
6949                 goto out;
6950 +       if (vx_current_initpid(tid))
6951 +               goto out;
6952  
6953         ns = dentry->d_sb->s_fs_info;
6954         rcu_read_lock();
6955 diff -NurpP --minimal linux-2.6.32.56/fs/proc/generic.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/proc/generic.c
6956 --- linux-2.6.32.56/fs/proc/generic.c   2009-06-11 17:13:07.000000000 +0200
6957 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/proc/generic.c   2011-06-10 13:03:02.000000000 +0200
6958 @@ -20,6 +20,7 @@
6959  #include <linux/bitops.h>
6960  #include <linux/spinlock.h>
6961  #include <linux/completion.h>
6962 +#include <linux/vserver/inode.h>
6963  #include <asm/uaccess.h>
6964  
6965  #include "internal.h"
6966 @@ -425,6 +426,8 @@ struct dentry *proc_lookup_de(struct pro
6967         for (de = de->subdir; de ; de = de->next) {
6968                 if (de->namelen != dentry->d_name.len)
6969                         continue;
6970 +                       if (!vx_hide_check(0, de->vx_flags))
6971 +                               continue;
6972                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6973                         unsigned int ino;
6974  
6975 @@ -433,6 +436,8 @@ struct dentry *proc_lookup_de(struct pro
6976                         spin_unlock(&proc_subdir_lock);
6977                         error = -EINVAL;
6978                         inode = proc_get_inode(dir->i_sb, ino, de);
6979 +                               /* generic proc entries belong to the host */
6980 +                               inode->i_tag = 0;
6981                         goto out_unlock;
6982                 }
6983         }
6984 @@ -510,6 +515,8 @@ int proc_readdir_de(struct proc_dir_entr
6985  
6986                                 /* filldir passes info to user space */
6987                                 de_get(de);
6988 +                               if (!vx_hide_check(0, de->vx_flags))
6989 +                                       goto skip;
6990                                 spin_unlock(&proc_subdir_lock);
6991                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6992                                             de->low_ino, de->mode >> 12) < 0) {
6993 @@ -517,6 +524,7 @@ int proc_readdir_de(struct proc_dir_entr
6994                                         goto out;
6995                                 }
6996                                 spin_lock(&proc_subdir_lock);
6997 +                       skip:
6998                                 filp->f_pos++;
6999                                 next = de->next;
7000                                 de_put(de);
7001 @@ -631,6 +639,7 @@ static struct proc_dir_entry *__proc_cre
7002         ent->nlink = nlink;
7003         atomic_set(&ent->count, 1);
7004         ent->pde_users = 0;
7005 +       ent->vx_flags = IATTR_PROC_DEFAULT;
7006         spin_lock_init(&ent->pde_unload_lock);
7007         ent->pde_unload_completion = NULL;
7008         INIT_LIST_HEAD(&ent->pde_openers);
7009 @@ -654,7 +663,8 @@ struct proc_dir_entry *proc_symlink(cons
7010                                 kfree(ent->data);
7011                                 kfree(ent);
7012                                 ent = NULL;
7013 -                       }
7014 +                       } else
7015 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
7016                 } else {
7017                         kfree(ent);
7018                         ent = NULL;
7019 diff -NurpP --minimal linux-2.6.32.56/fs/proc/inode.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/proc/inode.c
7020 --- linux-2.6.32.56/fs/proc/inode.c     2009-06-11 17:13:07.000000000 +0200
7021 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/proc/inode.c     2011-06-10 13:03:02.000000000 +0200
7022 @@ -459,6 +459,8 @@ struct inode *proc_get_inode(struct supe
7023                         inode->i_uid = de->uid;
7024                         inode->i_gid = de->gid;
7025                 }
7026 +               if (de->vx_flags)
7027 +                       PROC_I(inode)->vx_flags = de->vx_flags;
7028                 if (de->size)
7029                         inode->i_size = de->size;
7030                 if (de->nlink)
7031 diff -NurpP --minimal linux-2.6.32.56/fs/proc/internal.h linux-2.6.32.56-vs2.3.0.36.29.9/fs/proc/internal.h
7032 --- linux-2.6.32.56/fs/proc/internal.h  2009-09-10 15:26:23.000000000 +0200
7033 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/proc/internal.h  2011-06-10 13:03:02.000000000 +0200
7034 @@ -10,6 +10,7 @@
7035   */
7036  
7037  #include <linux/proc_fs.h>
7038 +#include <linux/vs_pid.h>
7039  
7040  extern struct proc_dir_entry proc_root;
7041  #ifdef CONFIG_PROC_SYSCTL
7042 @@ -51,6 +52,9 @@ extern int proc_pid_status(struct seq_fi
7043                                 struct pid *pid, struct task_struct *task);
7044  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
7045                                 struct pid *pid, struct task_struct *task);
7046 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
7047 +                               struct pid *pid, struct task_struct *task);
7048 +
7049  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
7050  
7051  extern const struct file_operations proc_maps_operations;
7052 @@ -70,11 +74,16 @@ static inline struct pid *proc_pid(struc
7053         return PROC_I(inode)->pid;
7054  }
7055  
7056 -static inline struct task_struct *get_proc_task(struct inode *inode)
7057 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
7058  {
7059         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
7060  }
7061  
7062 +static inline struct task_struct *get_proc_task(struct inode *inode)
7063 +{
7064 +       return vx_get_proc_task(inode, proc_pid(inode));
7065 +}
7066 +
7067  static inline int proc_fd(struct inode *inode)
7068  {
7069         return PROC_I(inode)->fd;
7070 diff -NurpP --minimal linux-2.6.32.56/fs/proc/loadavg.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/proc/loadavg.c
7071 --- linux-2.6.32.56/fs/proc/loadavg.c   2009-09-10 15:26:23.000000000 +0200
7072 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/proc/loadavg.c   2011-06-10 13:03:02.000000000 +0200
7073 @@ -12,15 +12,27 @@
7074  
7075  static int loadavg_proc_show(struct seq_file *m, void *v)
7076  {
7077 +       unsigned long running;
7078 +       unsigned int threads;
7079         unsigned long avnrun[3];
7080  
7081         get_avenrun(avnrun, FIXED_1/200, 0);
7082  
7083 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
7084 +               struct vx_info *vxi = current_vx_info();
7085 +
7086 +               running = atomic_read(&vxi->cvirt.nr_running);
7087 +               threads = atomic_read(&vxi->cvirt.nr_threads);
7088 +       } else {
7089 +               running = nr_running();
7090 +               threads = nr_threads;
7091 +       }
7092 +
7093         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
7094                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
7095                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
7096                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
7097 -               nr_running(), nr_threads,
7098 +               running, threads,
7099                 task_active_pid_ns(current)->last_pid);
7100         return 0;
7101  }
7102 diff -NurpP --minimal linux-2.6.32.56/fs/proc/meminfo.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/proc/meminfo.c
7103 --- linux-2.6.32.56/fs/proc/meminfo.c   2009-12-03 20:02:53.000000000 +0100
7104 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/proc/meminfo.c   2011-06-10 13:03:02.000000000 +0200
7105 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
7106         allowed = ((totalram_pages - hugetlb_total_pages())
7107                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
7108  
7109 -       cached = global_page_state(NR_FILE_PAGES) -
7110 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
7111 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
7112                         total_swapcache_pages - i.bufferram;
7113         if (cached < 0)
7114                 cached = 0;
7115 diff -NurpP --minimal linux-2.6.32.56/fs/proc/root.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/proc/root.c
7116 --- linux-2.6.32.56/fs/proc/root.c      2009-06-11 17:13:07.000000000 +0200
7117 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/proc/root.c      2011-06-10 13:03:02.000000000 +0200
7118 @@ -18,9 +18,14 @@
7119  #include <linux/bitops.h>
7120  #include <linux/mount.h>
7121  #include <linux/pid_namespace.h>
7122 +#include <linux/vserver/inode.h>
7123  
7124  #include "internal.h"
7125  
7126 +struct proc_dir_entry *proc_virtual;
7127 +
7128 +extern void proc_vx_init(void);
7129 +
7130  static int proc_test_super(struct super_block *sb, void *data)
7131  {
7132         return sb->s_fs_info == data;
7133 @@ -136,6 +141,7 @@ void __init proc_root_init(void)
7134  #endif
7135         proc_mkdir("bus", NULL);
7136         proc_sys_init();
7137 +       proc_vx_init();
7138  }
7139  
7140  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
7141 @@ -203,6 +209,7 @@ struct proc_dir_entry proc_root = {
7142         .proc_iops      = &proc_root_inode_operations, 
7143         .proc_fops      = &proc_root_operations,
7144         .parent         = &proc_root,
7145 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
7146  };
7147  
7148  int pid_ns_prepare_proc(struct pid_namespace *ns)
7149 diff -NurpP --minimal linux-2.6.32.56/fs/proc/uptime.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/proc/uptime.c
7150 --- linux-2.6.32.56/fs/proc/uptime.c    2012-02-09 10:22:30.000000000 +0100
7151 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/proc/uptime.c    2012-02-09 10:58:46.000000000 +0100
7152 @@ -5,6 +5,7 @@
7153  #include <linux/seq_file.h>
7154  #include <linux/time.h>
7155  #include <linux/kernel_stat.h>
7156 +#include <linux/vserver/cvirt.h>
7157  #include <asm/cputime.h>
7158  
7159  static int uptime_proc_show(struct seq_file *m, void *v)
7160 @@ -25,6 +26,10 @@ static int uptime_proc_show(struct seq_f
7161         nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
7162         idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
7163         idle.tv_nsec = rem;
7164 +
7165 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
7166 +               vx_vsi_uptime(&uptime, &idle);
7167 +
7168         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
7169                         (unsigned long) uptime.tv_sec,
7170                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
7171 diff -NurpP --minimal linux-2.6.32.56/fs/quota/quota.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/quota/quota.c
7172 --- linux-2.6.32.56/fs/quota/quota.c    2009-09-10 15:26:24.000000000 +0200
7173 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/quota/quota.c    2011-06-10 13:03:02.000000000 +0200
7174 @@ -18,6 +18,7 @@
7175  #include <linux/capability.h>
7176  #include <linux/quotaops.h>
7177  #include <linux/types.h>
7178 +#include <linux/vs_context.h>
7179  
7180  /* Check validity of generic quotactl commands */
7181  static int generic_quotactl_valid(struct super_block *sb, int type, int cmd,
7182 @@ -83,11 +84,11 @@ static int generic_quotactl_valid(struct
7183         if (cmd == Q_GETQUOTA) {
7184                 if (((type == USRQUOTA && current_euid() != id) ||
7185                      (type == GRPQUOTA && !in_egroup_p(id))) &&
7186 -                   !capable(CAP_SYS_ADMIN))
7187 +                   !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7188                         return -EPERM;
7189         }
7190         else if (cmd != Q_GETFMT && cmd != Q_SYNC && cmd != Q_GETINFO)
7191 -               if (!capable(CAP_SYS_ADMIN))
7192 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7193                         return -EPERM;
7194  
7195         return 0;
7196 @@ -135,10 +136,10 @@ static int xqm_quotactl_valid(struct sup
7197         if (cmd == Q_XGETQUOTA) {
7198                 if (((type == XQM_USRQUOTA && current_euid() != id) ||
7199                      (type == XQM_GRPQUOTA && !in_egroup_p(id))) &&
7200 -                    !capable(CAP_SYS_ADMIN))
7201 +                    !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7202                         return -EPERM;
7203         } else if (cmd != Q_XGETQSTAT && cmd != Q_XQUOTASYNC) {
7204 -               if (!capable(CAP_SYS_ADMIN))
7205 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7206                         return -EPERM;
7207         }
7208  
7209 @@ -351,6 +352,46 @@ static int do_quotactl(struct super_bloc
7210         return 0;
7211  }
7212  
7213 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7214 +
7215 +#include <linux/vroot.h>
7216 +#include <linux/major.h>
7217 +#include <linux/module.h>
7218 +#include <linux/kallsyms.h>
7219 +#include <linux/vserver/debug.h>
7220 +
7221 +static vroot_grb_func *vroot_get_real_bdev = NULL;
7222 +
7223 +static spinlock_t vroot_grb_lock = SPIN_LOCK_UNLOCKED;
7224 +
7225 +int register_vroot_grb(vroot_grb_func *func) {
7226 +       int ret = -EBUSY;
7227 +
7228 +       spin_lock(&vroot_grb_lock);
7229 +       if (!vroot_get_real_bdev) {
7230 +               vroot_get_real_bdev = func;
7231 +               ret = 0;
7232 +       }
7233 +       spin_unlock(&vroot_grb_lock);
7234 +       return ret;
7235 +}
7236 +EXPORT_SYMBOL(register_vroot_grb);
7237 +
7238 +int unregister_vroot_grb(vroot_grb_func *func) {
7239 +       int ret = -EINVAL;
7240 +
7241 +       spin_lock(&vroot_grb_lock);
7242 +       if (vroot_get_real_bdev) {
7243 +               vroot_get_real_bdev = NULL;
7244 +               ret = 0;
7245 +       }
7246 +       spin_unlock(&vroot_grb_lock);
7247 +       return ret;
7248 +}
7249 +EXPORT_SYMBOL(unregister_vroot_grb);
7250 +
7251 +#endif
7252 +
7253  /*
7254   * look up a superblock on which quota ops will be performed
7255   * - use the name of a block device to find the superblock thereon
7256 @@ -368,6 +409,22 @@ static struct super_block *quotactl_bloc
7257         putname(tmp);
7258         if (IS_ERR(bdev))
7259                 return ERR_CAST(bdev);
7260 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7261 +       if (bdev && bdev->bd_inode &&
7262 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
7263 +               struct block_device *bdnew = (void *)-EINVAL;
7264 +
7265 +               if (vroot_get_real_bdev)
7266 +                       bdnew = vroot_get_real_bdev(bdev);
7267 +               else
7268 +                       vxdprintk(VXD_CBIT(misc, 0),
7269 +                                       "vroot_get_real_bdev not set");
7270 +               bdput(bdev);
7271 +               if (IS_ERR(bdnew))
7272 +                       return ERR_PTR(PTR_ERR(bdnew));
7273 +               bdev = bdnew;
7274 +       }
7275 +#endif
7276         sb = get_super(bdev);
7277         bdput(bdev);
7278         if (!sb)
7279 diff -NurpP --minimal linux-2.6.32.56/fs/reiserfs/file.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/reiserfs/file.c
7280 --- linux-2.6.32.56/fs/reiserfs/file.c  2009-06-11 17:13:08.000000000 +0200
7281 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/reiserfs/file.c  2011-06-10 13:03:02.000000000 +0200
7282 @@ -307,4 +307,5 @@ const struct inode_operations reiserfs_f
7283         .listxattr = reiserfs_listxattr,
7284         .removexattr = reiserfs_removexattr,
7285         .permission = reiserfs_permission,
7286 +       .sync_flags = reiserfs_sync_flags,
7287  };
7288 diff -NurpP --minimal linux-2.6.32.56/fs/reiserfs/inode.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/reiserfs/inode.c
7289 --- linux-2.6.32.56/fs/reiserfs/inode.c 2012-02-09 10:22:30.000000000 +0100
7290 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/reiserfs/inode.c 2011-06-10 13:03:02.000000000 +0200
7291 @@ -18,6 +18,7 @@
7292  #include <linux/writeback.h>
7293  #include <linux/quotaops.h>
7294  #include <linux/swap.h>
7295 +#include <linux/vs_tag.h>
7296  
7297  int reiserfs_commit_write(struct file *f, struct page *page,
7298                           unsigned from, unsigned to);
7299 @@ -1117,6 +1118,8 @@ static void init_inode(struct inode *ino
7300         struct buffer_head *bh;
7301         struct item_head *ih;
7302         __u32 rdev;
7303 +       uid_t uid;
7304 +       gid_t gid;
7305         //int version = ITEM_VERSION_1;
7306  
7307         bh = PATH_PLAST_BUFFER(path);
7308 @@ -1138,12 +1141,13 @@ static void init_inode(struct inode *ino
7309                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
7310                 unsigned long blocks;
7311  
7312 +               uid = sd_v1_uid(sd);
7313 +               gid = sd_v1_gid(sd);
7314 +
7315                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
7316                 set_inode_sd_version(inode, STAT_DATA_V1);
7317                 inode->i_mode = sd_v1_mode(sd);
7318                 inode->i_nlink = sd_v1_nlink(sd);
7319 -               inode->i_uid = sd_v1_uid(sd);
7320 -               inode->i_gid = sd_v1_gid(sd);
7321                 inode->i_size = sd_v1_size(sd);
7322                 inode->i_atime.tv_sec = sd_v1_atime(sd);
7323                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
7324 @@ -1185,11 +1189,12 @@ static void init_inode(struct inode *ino
7325                 // (directories and symlinks)
7326                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
7327  
7328 +               uid    = sd_v2_uid(sd);
7329 +               gid    = sd_v2_gid(sd);
7330 +
7331                 inode->i_mode = sd_v2_mode(sd);
7332                 inode->i_nlink = sd_v2_nlink(sd);
7333 -               inode->i_uid = sd_v2_uid(sd);
7334                 inode->i_size = sd_v2_size(sd);
7335 -               inode->i_gid = sd_v2_gid(sd);
7336                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
7337                 inode->i_atime.tv_sec = sd_v2_atime(sd);
7338                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
7339 @@ -1219,6 +1224,10 @@ static void init_inode(struct inode *ino
7340                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
7341         }
7342  
7343 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7344 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7345 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
7346 +
7347         pathrelse(path);
7348         if (S_ISREG(inode->i_mode)) {
7349                 inode->i_op = &reiserfs_file_inode_operations;
7350 @@ -1241,13 +1250,15 @@ static void init_inode(struct inode *ino
7351  static void inode2sd(void *sd, struct inode *inode, loff_t size)
7352  {
7353         struct stat_data *sd_v2 = (struct stat_data *)sd;
7354 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
7355 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
7356         __u16 flags;
7357  
7358 +       set_sd_v2_uid(sd_v2, uid);
7359 +       set_sd_v2_gid(sd_v2, gid);
7360         set_sd_v2_mode(sd_v2, inode->i_mode);
7361         set_sd_v2_nlink(sd_v2, inode->i_nlink);
7362 -       set_sd_v2_uid(sd_v2, inode->i_uid);
7363         set_sd_v2_size(sd_v2, size);
7364 -       set_sd_v2_gid(sd_v2, inode->i_gid);
7365         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
7366         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
7367         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
7368 @@ -2839,14 +2850,19 @@ int reiserfs_commit_write(struct file *f
7369  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
7370  {
7371         if (reiserfs_attrs(inode->i_sb)) {
7372 -               if (sd_attrs & REISERFS_SYNC_FL)
7373 -                       inode->i_flags |= S_SYNC;
7374 -               else
7375 -                       inode->i_flags &= ~S_SYNC;
7376                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
7377                         inode->i_flags |= S_IMMUTABLE;
7378                 else
7379                         inode->i_flags &= ~S_IMMUTABLE;
7380 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
7381 +                       inode->i_flags |= S_IXUNLINK;
7382 +               else
7383 +                       inode->i_flags &= ~S_IXUNLINK;
7384 +
7385 +               if (sd_attrs & REISERFS_SYNC_FL)
7386 +                       inode->i_flags |= S_SYNC;
7387 +               else
7388 +                       inode->i_flags &= ~S_SYNC;
7389                 if (sd_attrs & REISERFS_APPEND_FL)
7390                         inode->i_flags |= S_APPEND;
7391                 else
7392 @@ -2859,6 +2875,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
7393                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
7394                 else
7395                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
7396 +
7397 +               if (sd_attrs & REISERFS_BARRIER_FL)
7398 +                       inode->i_vflags |= V_BARRIER;
7399 +               else
7400 +                       inode->i_vflags &= ~V_BARRIER;
7401 +               if (sd_attrs & REISERFS_COW_FL)
7402 +                       inode->i_vflags |= V_COW;
7403 +               else
7404 +                       inode->i_vflags &= ~V_COW;
7405         }
7406  }
7407  
7408 @@ -2869,6 +2894,11 @@ void i_attrs_to_sd_attrs(struct inode *i
7409                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
7410                 else
7411                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
7412 +               if (inode->i_flags & S_IXUNLINK)
7413 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
7414 +               else
7415 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
7416 +
7417                 if (inode->i_flags & S_SYNC)
7418                         *sd_attrs |= REISERFS_SYNC_FL;
7419                 else
7420 @@ -2881,6 +2911,15 @@ void i_attrs_to_sd_attrs(struct inode *i
7421                         *sd_attrs |= REISERFS_NOTAIL_FL;
7422                 else
7423                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
7424 +
7425 +               if (inode->i_vflags & V_BARRIER)
7426 +                       *sd_attrs |= REISERFS_BARRIER_FL;
7427 +               else
7428 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
7429 +               if (inode->i_vflags & V_COW)
7430 +                       *sd_attrs |= REISERFS_COW_FL;
7431 +               else
7432 +                       *sd_attrs &= ~REISERFS_COW_FL;
7433         }
7434  }
7435  
7436 @@ -3101,9 +3140,11 @@ int reiserfs_setattr(struct dentry *dent
7437         }
7438  
7439         error = inode_change_ok(inode, attr);
7440 +
7441         if (!error) {
7442                 if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
7443 -                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
7444 +                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
7445 +                   (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
7446                         error = reiserfs_chown_xattrs(inode, attr);
7447  
7448                         if (!error) {
7449 @@ -3133,6 +3174,9 @@ int reiserfs_setattr(struct dentry *dent
7450                                         inode->i_uid = attr->ia_uid;
7451                                 if (attr->ia_valid & ATTR_GID)
7452                                         inode->i_gid = attr->ia_gid;
7453 +                               if ((attr->ia_valid & ATTR_TAG) &&
7454 +                                       IS_TAGGED(inode))
7455 +                                       inode->i_tag = attr->ia_tag;
7456                                 mark_inode_dirty(inode);
7457                                 error =
7458                                     journal_end(&th, inode->i_sb, jbegin_count);
7459 diff -NurpP --minimal linux-2.6.32.56/fs/reiserfs/ioctl.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/reiserfs/ioctl.c
7460 --- linux-2.6.32.56/fs/reiserfs/ioctl.c 2009-06-11 17:13:08.000000000 +0200
7461 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/reiserfs/ioctl.c 2011-06-10 13:03:02.000000000 +0200
7462 @@ -7,11 +7,27 @@
7463  #include <linux/mount.h>
7464  #include <linux/reiserfs_fs.h>
7465  #include <linux/time.h>
7466 +#include <linux/mount.h>
7467  #include <asm/uaccess.h>
7468  #include <linux/pagemap.h>
7469  #include <linux/smp_lock.h>
7470  #include <linux/compat.h>
7471  
7472 +
7473 +int reiserfs_sync_flags(struct inode *inode, int flags, int vflags)
7474 +{
7475 +       __u16 sd_attrs = 0;
7476 +
7477 +       inode->i_flags = flags;
7478 +       inode->i_vflags = vflags;
7479 +
7480 +       i_attrs_to_sd_attrs(inode, &sd_attrs);
7481 +       REISERFS_I(inode)->i_attrs = sd_attrs;
7482 +       inode->i_ctime = CURRENT_TIME_SEC;
7483 +       mark_inode_dirty(inode);
7484 +       return 0;
7485 +}
7486 +
7487  /*
7488  ** reiserfs_ioctl - handler for ioctl for inode
7489  ** supported commands:
7490 @@ -23,7 +39,7 @@
7491  int reiserfs_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
7492                    unsigned long arg)
7493  {
7494 -       unsigned int flags;
7495 +       unsigned int flags, oldflags;
7496         int err = 0;
7497  
7498         switch (cmd) {
7499 @@ -43,6 +59,7 @@ int reiserfs_ioctl(struct inode *inode, 
7500  
7501                 flags = REISERFS_I(inode)->i_attrs;
7502                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
7503 +               flags &= REISERFS_FL_USER_VISIBLE;
7504                 return put_user(flags, (int __user *)arg);
7505         case REISERFS_IOC_SETFLAGS:{
7506                         if (!reiserfs_attrs(inode->i_sb))
7507 @@ -60,6 +77,10 @@ int reiserfs_ioctl(struct inode *inode, 
7508                                 err = -EFAULT;
7509                                 goto setflags_out;
7510                         }
7511 +                       if (IS_BARRIER(inode)) {
7512 +                               vxwprintk_task(1, "messing with the barrier.");
7513 +                               return -EACCES;
7514 +                       }
7515                         /*
7516                          * Is it quota file? Do not allow user to mess with it
7517                          */
7518 @@ -84,6 +105,10 @@ int reiserfs_ioctl(struct inode *inode, 
7519                                         goto setflags_out;
7520                                 }
7521                         }
7522 +
7523 +                       oldflags = REISERFS_I(inode)->i_attrs;
7524 +                       flags &= REISERFS_FL_USER_MODIFIABLE;
7525 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
7526                         sd_attrs_to_i_attrs(flags, inode);
7527                         REISERFS_I(inode)->i_attrs = flags;
7528                         inode->i_ctime = CURRENT_TIME_SEC;
7529 diff -NurpP --minimal linux-2.6.32.56/fs/reiserfs/namei.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/reiserfs/namei.c
7530 --- linux-2.6.32.56/fs/reiserfs/namei.c 2009-06-11 17:13:08.000000000 +0200
7531 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/reiserfs/namei.c 2011-06-10 13:03:02.000000000 +0200
7532 @@ -17,6 +17,7 @@
7533  #include <linux/reiserfs_acl.h>
7534  #include <linux/reiserfs_xattr.h>
7535  #include <linux/quotaops.h>
7536 +#include <linux/vs_tag.h>
7537  
7538  #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; }
7539  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
7540 @@ -354,6 +355,7 @@ static struct dentry *reiserfs_lookup(st
7541         if (retval == IO_ERROR) {
7542                 return ERR_PTR(-EIO);
7543         }
7544 +               dx_propagate_tag(nd, inode);
7545  
7546         return d_splice_alias(inode, dentry);
7547  }
7548 @@ -570,6 +572,7 @@ static int new_inode_init(struct inode *
7549         } else {
7550                 inode->i_gid = current_fsgid();
7551         }
7552 +       inode->i_tag = dx_current_fstag(inode->i_sb);
7553         vfs_dq_init(inode);
7554         return 0;
7555  }
7556 @@ -1515,6 +1518,7 @@ const struct inode_operations reiserfs_d
7557         .listxattr = reiserfs_listxattr,
7558         .removexattr = reiserfs_removexattr,
7559         .permission = reiserfs_permission,
7560 +       .sync_flags = reiserfs_sync_flags,
7561  };
7562  
7563  /*
7564 diff -NurpP --minimal linux-2.6.32.56/fs/reiserfs/super.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/reiserfs/super.c
7565 --- linux-2.6.32.56/fs/reiserfs/super.c 2012-02-09 10:22:30.000000000 +0100
7566 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/reiserfs/super.c 2012-02-09 10:33:19.000000000 +0100
7567 @@ -888,6 +888,14 @@ static int reiserfs_parse_options(struct
7568                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
7569                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
7570  #endif
7571 +#ifndef CONFIG_TAGGING_NONE
7572 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
7573 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
7574 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
7575 +#endif
7576 +#ifdef CONFIG_PROPAGATE
7577 +               {"tag",.arg_required = 'T',.values = NULL},
7578 +#endif
7579  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
7580                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
7581                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
7582 @@ -1195,6 +1203,14 @@ static int reiserfs_remount(struct super
7583         handle_quota_files(s, qf_names, &qfmt);
7584  #endif
7585  
7586 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
7587 +               !(s->s_flags & MS_TAGGED)) {
7588 +               reiserfs_warning(s, "super-vs01",
7589 +                       "reiserfs: tagging not permitted on remount.");
7590 +               err = -EINVAL;
7591 +               goto out_err;
7592 +       }
7593 +
7594         handle_attrs(s);
7595  
7596         /* Add options that are safe here */
7597 @@ -1657,6 +1673,10 @@ static int reiserfs_fill_super(struct su
7598                 goto error;
7599         }
7600  
7601 +       /* map mount option tagxid */
7602 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
7603 +               s->s_flags |= MS_TAGGED;
7604 +
7605         rs = SB_DISK_SUPER_BLOCK(s);
7606         /* Let's do basic sanity check to verify that underlying device is not
7607            smaller than the filesystem. If the check fails then abort and scream,
7608 diff -NurpP --minimal linux-2.6.32.56/fs/reiserfs/xattr.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/reiserfs/xattr.c
7609 --- linux-2.6.32.56/fs/reiserfs/xattr.c 2012-02-09 10:22:30.000000000 +0100
7610 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/reiserfs/xattr.c 2011-06-10 13:03:02.000000000 +0200
7611 @@ -39,6 +39,7 @@
7612  #include <linux/namei.h>
7613  #include <linux/errno.h>
7614  #include <linux/fs.h>
7615 +#include <linux/mount.h>
7616  #include <linux/file.h>
7617  #include <linux/pagemap.h>
7618  #include <linux/xattr.h>
7619 diff -NurpP --minimal linux-2.6.32.56/fs/stat.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/stat.c
7620 --- linux-2.6.32.56/fs/stat.c   2012-02-09 10:22:30.000000000 +0100
7621 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/stat.c   2011-06-10 13:03:02.000000000 +0200
7622 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
7623         stat->nlink = inode->i_nlink;
7624         stat->uid = inode->i_uid;
7625         stat->gid = inode->i_gid;
7626 +       stat->tag = inode->i_tag;
7627         stat->rdev = inode->i_rdev;
7628         stat->atime = inode->i_atime;
7629         stat->mtime = inode->i_mtime;
7630 diff -NurpP --minimal linux-2.6.32.56/fs/super.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/super.c
7631 --- linux-2.6.32.56/fs/super.c  2012-02-09 10:22:30.000000000 +0100
7632 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/super.c  2011-06-10 13:03:02.000000000 +0200
7633 @@ -37,6 +37,9 @@
7634  #include <linux/kobject.h>
7635  #include <linux/mutex.h>
7636  #include <linux/file.h>
7637 +#include <linux/devpts_fs.h>
7638 +#include <linux/proc_fs.h>
7639 +#include <linux/vs_context.h>
7640  #include <asm/uaccess.h>
7641  #include "internal.h"
7642  
7643 @@ -914,12 +917,18 @@ struct vfsmount *
7644  vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
7645  {
7646         struct vfsmount *mnt;
7647 +       struct super_block *sb;
7648         char *secdata = NULL;
7649         int error;
7650  
7651         if (!type)
7652                 return ERR_PTR(-ENODEV);
7653  
7654 +       error = -EPERM;
7655 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
7656 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
7657 +               goto out;
7658 +
7659         error = -ENOMEM;
7660         mnt = alloc_vfsmnt(name);
7661         if (!mnt)
7662 @@ -938,9 +947,17 @@ vfs_kern_mount(struct file_system_type *
7663         error = type->get_sb(type, flags, name, data, mnt);
7664         if (error < 0)
7665                 goto out_free_secdata;
7666 -       BUG_ON(!mnt->mnt_sb);
7667  
7668 -       error = security_sb_kern_mount(mnt->mnt_sb, flags, secdata);
7669 +       sb = mnt->mnt_sb;
7670 +       BUG_ON(!sb);
7671 +
7672 +       error = -EPERM;
7673 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) && !sb->s_bdev &&
7674 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
7675 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
7676 +               goto out_sb;
7677 +
7678 +       error = security_sb_kern_mount(sb, flags, secdata);
7679         if (error)
7680                 goto out_sb;
7681  
7682 diff -NurpP --minimal linux-2.6.32.56/fs/sysfs/mount.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/sysfs/mount.c
7683 --- linux-2.6.32.56/fs/sysfs/mount.c    2009-06-11 17:13:08.000000000 +0200
7684 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/sysfs/mount.c    2011-06-10 13:03:02.000000000 +0200
7685 @@ -47,7 +47,7 @@ static int sysfs_fill_super(struct super
7686  
7687         sb->s_blocksize = PAGE_CACHE_SIZE;
7688         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
7689 -       sb->s_magic = SYSFS_MAGIC;
7690 +       sb->s_magic = SYSFS_SUPER_MAGIC;
7691         sb->s_op = &sysfs_ops;
7692         sb->s_time_gran = 1;
7693         sysfs_sb = sb;
7694 diff -NurpP --minimal linux-2.6.32.56/fs/utimes.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/utimes.c
7695 --- linux-2.6.32.56/fs/utimes.c 2009-03-24 14:22:37.000000000 +0100
7696 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/utimes.c 2011-06-10 13:03:02.000000000 +0200
7697 @@ -8,6 +8,8 @@
7698  #include <linux/stat.h>
7699  #include <linux/utime.h>
7700  #include <linux/syscalls.h>
7701 +#include <linux/mount.h>
7702 +#include <linux/vs_cowbl.h>
7703  #include <asm/uaccess.h>
7704  #include <asm/unistd.h>
7705  
7706 diff -NurpP --minimal linux-2.6.32.56/fs/xattr.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/xattr.c
7707 --- linux-2.6.32.56/fs/xattr.c  2009-12-03 20:02:53.000000000 +0100
7708 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/xattr.c  2011-06-10 13:03:02.000000000 +0200
7709 @@ -18,6 +18,7 @@
7710  #include <linux/module.h>
7711  #include <linux/fsnotify.h>
7712  #include <linux/audit.h>
7713 +#include <linux/mount.h>
7714  #include <asm/uaccess.h>
7715  
7716  
7717 @@ -49,7 +50,7 @@ xattr_permission(struct inode *inode, co
7718          * The trusted.* namespace can only be accessed by a privileged user.
7719          */
7720         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN))
7721 -               return (capable(CAP_SYS_ADMIN) ? 0 : -EPERM);
7722 +               return (vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED) ? 0 : -EPERM);
7723  
7724         /* In user.* namespace, only regular files and directories can have
7725          * extended attributes. For sticky directories, only the owner and
7726 diff -NurpP --minimal linux-2.6.32.56/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/xfs/linux-2.6/xfs_ioctl.c
7727 --- linux-2.6.32.56/fs/xfs/linux-2.6/xfs_ioctl.c        2012-02-09 10:22:30.000000000 +0100
7728 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/xfs/linux-2.6/xfs_ioctl.c        2011-06-10 13:03:02.000000000 +0200
7729 @@ -34,7 +34,6 @@
7730  #include "xfs_dir2_sf.h"
7731  #include "xfs_dinode.h"
7732  #include "xfs_inode.h"
7733 -#include "xfs_ioctl.h"
7734  #include "xfs_btree.h"
7735  #include "xfs_ialloc.h"
7736  #include "xfs_rtalloc.h"
7737 @@ -746,6 +745,10 @@ xfs_merge_ioc_xflags(
7738                 xflags |= XFS_XFLAG_IMMUTABLE;
7739         else
7740                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7741 +       if (flags & FS_IXUNLINK_FL)
7742 +               xflags |= XFS_XFLAG_IXUNLINK;
7743 +       else
7744 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7745         if (flags & FS_APPEND_FL)
7746                 xflags |= XFS_XFLAG_APPEND;
7747         else
7748 @@ -774,6 +777,8 @@ xfs_di2lxflags(
7749  
7750         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7751                 flags |= FS_IMMUTABLE_FL;
7752 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7753 +               flags |= FS_IXUNLINK_FL;
7754         if (di_flags & XFS_DIFLAG_APPEND)
7755                 flags |= FS_APPEND_FL;
7756         if (di_flags & XFS_DIFLAG_SYNC)
7757 @@ -834,6 +839,8 @@ xfs_set_diflags(
7758         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7759         if (xflags & XFS_XFLAG_IMMUTABLE)
7760                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7761 +       if (xflags & XFS_XFLAG_IXUNLINK)
7762 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7763         if (xflags & XFS_XFLAG_APPEND)
7764                 di_flags |= XFS_DIFLAG_APPEND;
7765         if (xflags & XFS_XFLAG_SYNC)
7766 @@ -876,6 +883,10 @@ xfs_diflags_to_linux(
7767                 inode->i_flags |= S_IMMUTABLE;
7768         else
7769                 inode->i_flags &= ~S_IMMUTABLE;
7770 +       if (xflags & XFS_XFLAG_IXUNLINK)
7771 +               inode->i_flags |= S_IXUNLINK;
7772 +       else
7773 +               inode->i_flags &= ~S_IXUNLINK;
7774         if (xflags & XFS_XFLAG_APPEND)
7775                 inode->i_flags |= S_APPEND;
7776         else
7777 @@ -1352,10 +1363,18 @@ xfs_file_ioctl(
7778         case XFS_IOC_FSGETXATTRA:
7779                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7780         case XFS_IOC_FSSETXATTR:
7781 +               if (IS_BARRIER(inode)) {
7782 +                       vxwprintk_task(1, "messing with the barrier.");
7783 +                       return -XFS_ERROR(EACCES);
7784 +               }
7785                 return xfs_ioc_fssetxattr(ip, filp, arg);
7786         case XFS_IOC_GETXFLAGS:
7787                 return xfs_ioc_getxflags(ip, arg);
7788         case XFS_IOC_SETXFLAGS:
7789 +               if (IS_BARRIER(inode)) {
7790 +                       vxwprintk_task(1, "messing with the barrier.");
7791 +                       return -XFS_ERROR(EACCES);
7792 +               }
7793                 return xfs_ioc_setxflags(ip, filp, arg);
7794  
7795         case XFS_IOC_FSSETDM: {
7796 diff -NurpP --minimal linux-2.6.32.56/fs/xfs/linux-2.6/xfs_ioctl.h linux-2.6.32.56-vs2.3.0.36.29.9/fs/xfs/linux-2.6/xfs_ioctl.h
7797 --- linux-2.6.32.56/fs/xfs/linux-2.6/xfs_ioctl.h        2009-03-24 14:22:37.000000000 +0100
7798 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/xfs/linux-2.6/xfs_ioctl.h        2011-06-10 13:03:02.000000000 +0200
7799 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7800         void __user             *uhandle,
7801         u32                     hlen);
7802  
7803 +extern int
7804 +xfs_sync_flags(
7805 +       struct inode            *inode,
7806 +       int                     flags,
7807 +       int                     vflags);
7808 +
7809  extern long
7810  xfs_file_ioctl(
7811         struct file             *filp,
7812 diff -NurpP --minimal linux-2.6.32.56/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/xfs/linux-2.6/xfs_iops.c
7813 --- linux-2.6.32.56/fs/xfs/linux-2.6/xfs_iops.c 2012-02-09 10:22:30.000000000 +0100
7814 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/xfs/linux-2.6/xfs_iops.c 2011-06-10 13:03:02.000000000 +0200
7815 @@ -36,6 +36,7 @@
7816  #include "xfs_attr_sf.h"
7817  #include "xfs_dinode.h"
7818  #include "xfs_inode.h"
7819 +#include "xfs_ioctl.h"
7820  #include "xfs_bmap.h"
7821  #include "xfs_btree.h"
7822  #include "xfs_ialloc.h"
7823 @@ -55,6 +56,7 @@
7824  #include <linux/security.h>
7825  #include <linux/falloc.h>
7826  #include <linux/fiemap.h>
7827 +#include <linux/vs_tag.h>
7828  
7829  /*
7830   * Bring the timestamps in the XFS inode uptodate.
7831 @@ -495,6 +497,7 @@ xfs_vn_getattr(
7832         stat->nlink = ip->i_d.di_nlink;
7833         stat->uid = ip->i_d.di_uid;
7834         stat->gid = ip->i_d.di_gid;
7835 +       stat->tag = ip->i_d.di_tag;
7836         stat->ino = ip->i_ino;
7837         stat->atime = inode->i_atime;
7838         stat->mtime = inode->i_mtime;
7839 @@ -686,6 +689,7 @@ static const struct inode_operations xfs
7840         .listxattr              = xfs_vn_listxattr,
7841         .fallocate              = xfs_vn_fallocate,
7842         .fiemap                 = xfs_vn_fiemap,
7843 +       .sync_flags             = xfs_sync_flags,
7844  };
7845  
7846  static const struct inode_operations xfs_dir_inode_operations = {
7847 @@ -711,6 +715,7 @@ static const struct inode_operations xfs
7848         .getxattr               = generic_getxattr,
7849         .removexattr            = generic_removexattr,
7850         .listxattr              = xfs_vn_listxattr,
7851 +       .sync_flags             = xfs_sync_flags,
7852  };
7853  
7854  static const struct inode_operations xfs_dir_ci_inode_operations = {
7855 @@ -760,6 +765,10 @@ xfs_diflags_to_iflags(
7856                 inode->i_flags |= S_IMMUTABLE;
7857         else
7858                 inode->i_flags &= ~S_IMMUTABLE;
7859 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7860 +               inode->i_flags |= S_IXUNLINK;
7861 +       else
7862 +               inode->i_flags &= ~S_IXUNLINK;
7863         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7864                 inode->i_flags |= S_APPEND;
7865         else
7866 @@ -772,6 +781,15 @@ xfs_diflags_to_iflags(
7867                 inode->i_flags |= S_NOATIME;
7868         else
7869                 inode->i_flags &= ~S_NOATIME;
7870 +
7871 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7872 +               inode->i_vflags |= V_BARRIER;
7873 +       else
7874 +               inode->i_vflags &= ~V_BARRIER;
7875 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7876 +               inode->i_vflags |= V_COW;
7877 +       else
7878 +               inode->i_vflags &= ~V_COW;
7879  }
7880  
7881  /*
7882 @@ -800,6 +818,7 @@ xfs_setup_inode(
7883         inode->i_nlink  = ip->i_d.di_nlink;
7884         inode->i_uid    = ip->i_d.di_uid;
7885         inode->i_gid    = ip->i_d.di_gid;
7886 +       inode->i_tag    = ip->i_d.di_tag;
7887  
7888         switch (inode->i_mode & S_IFMT) {
7889         case S_IFBLK:
7890 diff -NurpP --minimal linux-2.6.32.56/fs/xfs/linux-2.6/xfs_linux.h linux-2.6.32.56-vs2.3.0.36.29.9/fs/xfs/linux-2.6/xfs_linux.h
7891 --- linux-2.6.32.56/fs/xfs/linux-2.6/xfs_linux.h        2009-09-10 15:26:24.000000000 +0200
7892 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/xfs/linux-2.6/xfs_linux.h        2011-06-10 13:03:02.000000000 +0200
7893 @@ -119,6 +119,7 @@
7894  
7895  #define current_cpu()          (raw_smp_processor_id())
7896  #define current_pid()          (current->pid)
7897 +#define current_fstag(cred,vp) (dx_current_fstag((vp)->i_sb))
7898  #define current_test_flags(f)  (current->flags & (f))
7899  #define current_set_flags_nested(sp, f)                \
7900                 (*(sp) = current->flags, current->flags |= (f))
7901 diff -NurpP --minimal linux-2.6.32.56/fs/xfs/linux-2.6/xfs_super.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/xfs/linux-2.6/xfs_super.c
7902 --- linux-2.6.32.56/fs/xfs/linux-2.6/xfs_super.c        2012-02-09 10:22:30.000000000 +0100
7903 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/xfs/linux-2.6/xfs_super.c        2011-06-10 13:03:02.000000000 +0200
7904 @@ -117,6 +117,9 @@ mempool_t *xfs_ioend_pool;
7905  #define MNTOPT_DMAPI   "dmapi"         /* DMI enabled (DMAPI / XDSM) */
7906  #define MNTOPT_XDSM    "xdsm"          /* DMI enabled (DMAPI / XDSM) */
7907  #define MNTOPT_DMI     "dmi"           /* DMI enabled (DMAPI / XDSM) */
7908 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
7909 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
7910 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
7911  
7912  /*
7913   * Table driven mount option parser.
7914 @@ -125,10 +128,14 @@ mempool_t *xfs_ioend_pool;
7915   * in the future, too.
7916   */
7917  enum {
7918 +       Opt_tag, Opt_notag,
7919         Opt_barrier, Opt_nobarrier, Opt_err
7920  };
7921  
7922  static const match_table_t tokens = {
7923 +       {Opt_tag, "tagxid"},
7924 +       {Opt_tag, "tag"},
7925 +       {Opt_notag, "notag"},
7926         {Opt_barrier, "barrier"},
7927         {Opt_nobarrier, "nobarrier"},
7928         {Opt_err, NULL}
7929 @@ -382,6 +389,19 @@ xfs_parseargs(
7930                 } else if (!strcmp(this_char, "irixsgid")) {
7931                         cmn_err(CE_WARN,
7932         "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
7933 +#ifndef CONFIG_TAGGING_NONE
7934 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7935 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7936 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7937 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
7938 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7939 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7940 +#endif
7941 +#ifdef CONFIG_PROPAGATE
7942 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7943 +                       /* use value */
7944 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7945 +#endif
7946                 } else {
7947                         cmn_err(CE_WARN,
7948                                 "XFS: unknown mount option [%s].", this_char);
7949 @@ -1295,6 +1315,16 @@ xfs_fs_remount(
7950                 case Opt_nobarrier:
7951                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
7952                         break;
7953 +               case Opt_tag:
7954 +                       if (!(sb->s_flags & MS_TAGGED)) {
7955 +                               printk(KERN_INFO
7956 +                                       "XFS: %s: tagging not permitted on remount.\n",
7957 +                                       sb->s_id);
7958 +                               return -EINVAL;
7959 +                       }
7960 +                       break;
7961 +               case Opt_notag:
7962 +                       break;
7963                 default:
7964                         /*
7965                          * Logically we would return an error here to prevent
7966 @@ -1530,6 +1560,9 @@ xfs_fs_fill_super(
7967  
7968         XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, mtpt, mp->m_fsname);
7969  
7970 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
7971 +               sb->s_flags |= MS_TAGGED;
7972 +
7973         sb->s_magic = XFS_SB_MAGIC;
7974         sb->s_blocksize = mp->m_sb.sb_blocksize;
7975         sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
7976 diff -NurpP --minimal linux-2.6.32.56/fs/xfs/xfs_dinode.h linux-2.6.32.56-vs2.3.0.36.29.9/fs/xfs/xfs_dinode.h
7977 --- linux-2.6.32.56/fs/xfs/xfs_dinode.h 2009-06-11 17:13:09.000000000 +0200
7978 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/xfs/xfs_dinode.h 2011-06-10 13:03:02.000000000 +0200
7979 @@ -50,7 +50,9 @@ typedef struct xfs_dinode {
7980         __be32          di_gid;         /* owner's group id */
7981         __be32          di_nlink;       /* number of links to file */
7982         __be16          di_projid;      /* owner's project id */
7983 -       __u8            di_pad[8];      /* unused, zeroed space */
7984 +       __be16          di_tag;         /* context tagging */
7985 +       __be16          di_vflags;      /* vserver specific flags */
7986 +       __u8            di_pad[4];      /* unused, zeroed space */
7987         __be16          di_flushiter;   /* incremented on flush */
7988         xfs_timestamp_t di_atime;       /* time last accessed */
7989         xfs_timestamp_t di_mtime;       /* time last modified */
7990 @@ -183,6 +185,8 @@ static inline void xfs_dinode_put_rdev(s
7991  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
7992  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
7993  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
7994 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
7995 +
7996  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
7997  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
7998  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
7999 @@ -198,6 +202,7 @@ static inline void xfs_dinode_put_rdev(s
8000  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
8001  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
8002  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
8003 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
8004  
8005  #ifdef CONFIG_XFS_RT
8006  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
8007 @@ -210,6 +215,10 @@ static inline void xfs_dinode_put_rdev(s
8008          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
8009          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
8010          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
8011 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
8012 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
8013 +        XFS_DIFLAG_IXUNLINK)
8014 +
8015 +#define XFS_DIVFLAG_BARRIER    0x01
8016 +#define XFS_DIVFLAG_COW                0x02
8017  
8018  #endif /* __XFS_DINODE_H__ */
8019 diff -NurpP --minimal linux-2.6.32.56/fs/xfs/xfs_fs.h linux-2.6.32.56-vs2.3.0.36.29.9/fs/xfs/xfs_fs.h
8020 --- linux-2.6.32.56/fs/xfs/xfs_fs.h     2009-12-03 20:02:53.000000000 +0100
8021 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/xfs/xfs_fs.h     2011-06-10 13:03:02.000000000 +0200
8022 @@ -67,6 +67,9 @@ struct fsxattr {
8023  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
8024  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
8025  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
8026 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
8027 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
8028 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
8029  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
8030  
8031  /*
8032 @@ -292,7 +295,8 @@ typedef struct xfs_bstat {
8033         __s32           bs_extents;     /* number of extents            */
8034         __u32           bs_gen;         /* generation count             */
8035         __u16           bs_projid;      /* project id                   */
8036 -       unsigned char   bs_pad[14];     /* pad space, unused            */
8037 +       __u16           bs_tag;         /* context tagging              */
8038 +       unsigned char   bs_pad[12];     /* pad space, unused            */
8039         __u32           bs_dmevmask;    /* DMIG event mask              */
8040         __u16           bs_dmstate;     /* DMIG state info              */
8041         __u16           bs_aextents;    /* attribute number of extents  */
8042 diff -NurpP --minimal linux-2.6.32.56/fs/xfs/xfs_ialloc.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/xfs/xfs_ialloc.c
8043 --- linux-2.6.32.56/fs/xfs/xfs_ialloc.c 2012-02-09 10:22:31.000000000 +0100
8044 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/xfs/xfs_ialloc.c 2011-06-10 13:03:02.000000000 +0200
8045 @@ -41,7 +41,6 @@
8046  #include "xfs_error.h"
8047  #include "xfs_bmap.h"
8048  
8049 -
8050  /*
8051   * Allocation group level functions.
8052   */
8053 diff -NurpP --minimal linux-2.6.32.56/fs/xfs/xfs_inode.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/xfs/xfs_inode.c
8054 --- linux-2.6.32.56/fs/xfs/xfs_inode.c  2012-02-09 10:22:31.000000000 +0100
8055 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/xfs/xfs_inode.c  2011-06-10 13:03:02.000000000 +0200
8056 @@ -249,6 +249,7 @@ xfs_inotobp(
8057         return 0;
8058  }
8059  
8060 +#include <linux/vs_tag.h>
8061  
8062  /*
8063   * This routine is called to map an inode to the buffer containing
8064 @@ -654,15 +655,25 @@ xfs_iformat_btree(
8065  STATIC void
8066  xfs_dinode_from_disk(
8067         xfs_icdinode_t          *to,
8068 -       xfs_dinode_t            *from)
8069 +       xfs_dinode_t            *from,
8070 +       int tagged)
8071  {
8072 +       uint32_t uid, gid, tag;
8073 +
8074         to->di_magic = be16_to_cpu(from->di_magic);
8075         to->di_mode = be16_to_cpu(from->di_mode);
8076         to->di_version = from ->di_version;
8077         to->di_format = from->di_format;
8078         to->di_onlink = be16_to_cpu(from->di_onlink);
8079 -       to->di_uid = be32_to_cpu(from->di_uid);
8080 -       to->di_gid = be32_to_cpu(from->di_gid);
8081 +
8082 +       uid = be32_to_cpu(from->di_uid);
8083 +       gid = be32_to_cpu(from->di_gid);
8084 +       tag = be16_to_cpu(from->di_tag);
8085 +
8086 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
8087 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
8088 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
8089 +
8090         to->di_nlink = be32_to_cpu(from->di_nlink);
8091         to->di_projid = be16_to_cpu(from->di_projid);
8092         memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
8093 @@ -683,21 +694,26 @@ xfs_dinode_from_disk(
8094         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
8095         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
8096         to->di_flags    = be16_to_cpu(from->di_flags);
8097 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
8098         to->di_gen      = be32_to_cpu(from->di_gen);
8099  }
8100  
8101  void
8102  xfs_dinode_to_disk(
8103         xfs_dinode_t            *to,
8104 -       xfs_icdinode_t          *from)
8105 +       xfs_icdinode_t          *from,
8106 +       int tagged)
8107  {
8108         to->di_magic = cpu_to_be16(from->di_magic);
8109         to->di_mode = cpu_to_be16(from->di_mode);
8110         to->di_version = from ->di_version;
8111         to->di_format = from->di_format;
8112         to->di_onlink = cpu_to_be16(from->di_onlink);
8113 -       to->di_uid = cpu_to_be32(from->di_uid);
8114 -       to->di_gid = cpu_to_be32(from->di_gid);
8115 +
8116 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
8117 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
8118 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
8119 +
8120         to->di_nlink = cpu_to_be32(from->di_nlink);
8121         to->di_projid = cpu_to_be16(from->di_projid);
8122         memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
8123 @@ -718,12 +734,14 @@ xfs_dinode_to_disk(
8124         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
8125         to->di_dmstate = cpu_to_be16(from->di_dmstate);
8126         to->di_flags = cpu_to_be16(from->di_flags);
8127 +       to->di_vflags = cpu_to_be16(from->di_vflags);
8128         to->di_gen = cpu_to_be32(from->di_gen);
8129  }
8130  
8131  STATIC uint
8132  _xfs_dic2xflags(
8133 -       __uint16_t              di_flags)
8134 +       __uint16_t              di_flags,
8135 +       __uint16_t              di_vflags)
8136  {
8137         uint                    flags = 0;
8138  
8139 @@ -734,6 +752,8 @@ _xfs_dic2xflags(
8140                         flags |= XFS_XFLAG_PREALLOC;
8141                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
8142                         flags |= XFS_XFLAG_IMMUTABLE;
8143 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
8144 +                       flags |= XFS_XFLAG_IXUNLINK;
8145                 if (di_flags & XFS_DIFLAG_APPEND)
8146                         flags |= XFS_XFLAG_APPEND;
8147                 if (di_flags & XFS_DIFLAG_SYNC)
8148 @@ -758,6 +778,10 @@ _xfs_dic2xflags(
8149                         flags |= XFS_XFLAG_FILESTREAM;
8150         }
8151  
8152 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
8153 +               flags |= FS_BARRIER_FL;
8154 +       if (di_vflags & XFS_DIVFLAG_COW)
8155 +               flags |= FS_COW_FL;
8156         return flags;
8157  }
8158  
8159 @@ -767,7 +791,7 @@ xfs_ip2xflags(
8160  {
8161         xfs_icdinode_t          *dic = &ip->i_d;
8162  
8163 -       return _xfs_dic2xflags(dic->di_flags) |
8164 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
8165                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
8166  }
8167  
8168 @@ -775,7 +799,8 @@ uint
8169  xfs_dic2xflags(
8170         xfs_dinode_t            *dip)
8171  {
8172 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
8173 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
8174 +                               be16_to_cpu(dip->di_vflags)) |
8175                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
8176  }
8177  
8178 @@ -808,7 +833,6 @@ xfs_iread(
8179         if (error)
8180                 return error;
8181         dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);
8182 -
8183         /*
8184          * If we got something that isn't an inode it means someone
8185          * (nfs or dmi) has a stale handle.
8186 @@ -833,7 +857,8 @@ xfs_iread(
8187          * Otherwise, just get the truly permanent information.
8188          */
8189         if (dip->di_mode) {
8190 -               xfs_dinode_from_disk(&ip->i_d, dip);
8191 +               xfs_dinode_from_disk(&ip->i_d, dip,
8192 +                       mp->m_flags & XFS_MOUNT_TAGGED);
8193                 error = xfs_iformat(ip, dip);
8194                 if (error)  {
8195  #ifdef DEBUG
8196 @@ -1033,6 +1058,7 @@ xfs_ialloc(
8197         ASSERT(ip->i_d.di_nlink == nlink);
8198         ip->i_d.di_uid = current_fsuid();
8199         ip->i_d.di_gid = current_fsgid();
8200 +       ip->i_d.di_tag = current_fstag(cr, &ip->i_vnode);
8201         ip->i_d.di_projid = prid;
8202         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
8203  
8204 @@ -1093,6 +1119,7 @@ xfs_ialloc(
8205         ip->i_d.di_dmevmask = 0;
8206         ip->i_d.di_dmstate = 0;
8207         ip->i_d.di_flags = 0;
8208 +       ip->i_d.di_vflags = 0;
8209         flags = XFS_ILOG_CORE;
8210         switch (mode & S_IFMT) {
8211         case S_IFIFO:
8212 @@ -2169,6 +2196,7 @@ xfs_ifree(
8213         }
8214         ip->i_d.di_mode = 0;            /* mark incore inode as free */
8215         ip->i_d.di_flags = 0;
8216 +       ip->i_d.di_vflags = 0;
8217         ip->i_d.di_dmevmask = 0;
8218         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
8219         ip->i_df.if_ext_max =
8220 @@ -3149,7 +3177,8 @@ xfs_iflush_int(
8221          * because if the inode is dirty at all the core must
8222          * be.
8223          */
8224 -       xfs_dinode_to_disk(dip, &ip->i_d);
8225 +       xfs_dinode_to_disk(dip, &ip->i_d,
8226 +               mp->m_flags & XFS_MOUNT_TAGGED);
8227  
8228         /* Wrap, we never let the log put out DI_MAX_FLUSH */
8229         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
8230 diff -NurpP --minimal linux-2.6.32.56/fs/xfs/xfs_inode.h linux-2.6.32.56-vs2.3.0.36.29.9/fs/xfs/xfs_inode.h
8231 --- linux-2.6.32.56/fs/xfs/xfs_inode.h  2012-02-09 10:22:31.000000000 +0100
8232 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/xfs/xfs_inode.h  2011-06-10 13:03:02.000000000 +0200
8233 @@ -135,7 +135,9 @@ typedef struct xfs_icdinode {
8234         __uint32_t      di_gid;         /* owner's group id */
8235         __uint32_t      di_nlink;       /* number of links to file */
8236         __uint16_t      di_projid;      /* owner's project id */
8237 -       __uint8_t       di_pad[8];      /* unused, zeroed space */
8238 +       __uint16_t      di_tag;         /* context tagging */
8239 +       __uint16_t      di_vflags;      /* vserver specific flags */
8240 +       __uint8_t       di_pad[4];      /* unused, zeroed space */
8241         __uint16_t      di_flushiter;   /* incremented on flush */
8242         xfs_ictimestamp_t di_atime;     /* time last accessed */
8243         xfs_ictimestamp_t di_mtime;     /* time last modified */
8244 @@ -569,7 +571,7 @@ int         xfs_itobp(struct xfs_mount *, struc
8245  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
8246                           struct xfs_inode *, uint);
8247  void           xfs_dinode_to_disk(struct xfs_dinode *,
8248 -                                  struct xfs_icdinode *);
8249 +                                  struct xfs_icdinode *, int);
8250  void           xfs_idestroy_fork(struct xfs_inode *, int);
8251  void           xfs_idata_realloc(struct xfs_inode *, int, int);
8252  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
8253 diff -NurpP --minimal linux-2.6.32.56/fs/xfs/xfs_itable.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/xfs/xfs_itable.c
8254 --- linux-2.6.32.56/fs/xfs/xfs_itable.c 2012-02-09 10:22:31.000000000 +0100
8255 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/xfs/xfs_itable.c 2011-06-10 13:03:02.000000000 +0200
8256 @@ -100,6 +100,7 @@ xfs_bulkstat_one_int(
8257         buf->bs_mode = dic->di_mode;
8258         buf->bs_uid = dic->di_uid;
8259         buf->bs_gid = dic->di_gid;
8260 +       buf->bs_tag = dic->di_tag;
8261         buf->bs_size = dic->di_size;
8262  
8263         /*
8264 diff -NurpP --minimal linux-2.6.32.56/fs/xfs/xfs_log_recover.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/xfs/xfs_log_recover.c
8265 --- linux-2.6.32.56/fs/xfs/xfs_log_recover.c    2012-02-09 10:22:31.000000000 +0100
8266 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/xfs/xfs_log_recover.c    2011-06-10 13:03:02.000000000 +0200
8267 @@ -2467,7 +2467,8 @@ xlog_recover_do_inode_trans(
8268         }
8269  
8270         /* The core is in in-core format */
8271 -       xfs_dinode_to_disk(dip, (xfs_icdinode_t *)item->ri_buf[1].i_addr);
8272 +       xfs_dinode_to_disk(dip, (xfs_icdinode_t *)item->ri_buf[1].i_addr,
8273 +               mp->m_flags & XFS_MOUNT_TAGGED);
8274  
8275         /* the rest is in on-disk format */
8276         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
8277 diff -NurpP --minimal linux-2.6.32.56/fs/xfs/xfs_mount.h linux-2.6.32.56-vs2.3.0.36.29.9/fs/xfs/xfs_mount.h
8278 --- linux-2.6.32.56/fs/xfs/xfs_mount.h  2012-02-09 10:22:31.000000000 +0100
8279 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/xfs/xfs_mount.h  2011-06-10 13:03:02.000000000 +0200
8280 @@ -285,6 +285,7 @@ typedef struct xfs_mount {
8281                                                    allocator */
8282  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
8283  
8284 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
8285  
8286  /*
8287   * Default minimum read and write sizes.
8288 diff -NurpP --minimal linux-2.6.32.56/fs/xfs/xfs_vnodeops.c linux-2.6.32.56-vs2.3.0.36.29.9/fs/xfs/xfs_vnodeops.c
8289 --- linux-2.6.32.56/fs/xfs/xfs_vnodeops.c       2012-02-09 10:22:31.000000000 +0100
8290 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/xfs/xfs_vnodeops.c       2011-06-10 13:03:02.000000000 +0200
8291 @@ -54,6 +54,80 @@
8292  #include "xfs_filestream.h"
8293  #include "xfs_vnodeops.h"
8294  
8295 +
8296 +STATIC void
8297 +xfs_get_inode_flags(
8298 +       xfs_inode_t     *ip)
8299 +{
8300 +       struct inode    *inode = VFS_I(ip);
8301 +       unsigned int    flags = inode->i_flags;
8302 +       unsigned int    vflags = inode->i_vflags;
8303 +
8304 +       if (flags & S_IMMUTABLE)
8305 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
8306 +       else
8307 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
8308 +       if (flags & S_IXUNLINK)
8309 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
8310 +       else
8311 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
8312 +
8313 +       if (vflags & V_BARRIER)
8314 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
8315 +       else
8316 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
8317 +       if (vflags & V_COW)
8318 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
8319 +       else
8320 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
8321 +}
8322 +
8323 +int
8324 +xfs_sync_flags(
8325 +       struct inode            *inode,
8326 +       int                     flags,
8327 +       int                     vflags)
8328 +{
8329 +       struct xfs_inode        *ip = XFS_I(inode);
8330 +       struct xfs_mount        *mp = ip->i_mount;
8331 +       struct xfs_trans        *tp;
8332 +       unsigned int            lock_flags = 0;
8333 +       int                     code;
8334 +
8335 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
8336 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
8337 +       if (code)
8338 +               goto error_out;
8339 +
8340 +       lock_flags = XFS_ILOCK_EXCL;
8341 +       xfs_ilock(ip, lock_flags);
8342 +
8343 +       xfs_trans_ijoin(tp, ip, lock_flags);
8344 +       xfs_trans_ihold(tp, ip);
8345 +
8346 +       inode->i_flags = flags;
8347 +       inode->i_vflags = vflags;
8348 +       xfs_get_inode_flags(ip);
8349 +
8350 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
8351 +       xfs_ichgtime(ip, XFS_ICHGTIME_CHG);
8352 +
8353 +       XFS_STATS_INC(xs_ig_attrchg);
8354 +
8355 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
8356 +               xfs_trans_set_sync(tp);
8357 +       code = xfs_trans_commit(tp, 0);
8358 +       xfs_iunlock(ip, lock_flags);
8359 +       return code;
8360 +
8361 +error_out:
8362 +       xfs_trans_cancel(tp, 0);
8363 +       if (lock_flags)
8364 +               xfs_iunlock(ip, lock_flags);
8365 +       return code;
8366 +}
8367 +
8368 +
8369  int
8370  xfs_setattr(
8371         struct xfs_inode        *ip,
8372 @@ -69,6 +143,7 @@ xfs_setattr(
8373         uint                    commit_flags=0;
8374         uid_t                   uid=0, iuid=0;
8375         gid_t                   gid=0, igid=0;
8376 +       tag_t                   tag=0, itag=0;
8377         struct xfs_dquot        *udqp, *gdqp, *olddquot1, *olddquot2;
8378         int                     need_iolock = 1;
8379  
8380 @@ -161,7 +236,7 @@ xfs_setattr(
8381         /*
8382          * Change file ownership.  Must be the owner or privileged.
8383          */
8384 -       if (mask & (ATTR_UID|ATTR_GID)) {
8385 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8386                 /*
8387                  * These IDs could have changed since we last looked at them.
8388                  * But, we're assured that if the ownership did change
8389 @@ -170,8 +245,10 @@ xfs_setattr(
8390                  */
8391                 iuid = ip->i_d.di_uid;
8392                 igid = ip->i_d.di_gid;
8393 +               itag = ip->i_d.di_tag;
8394                 gid = (mask & ATTR_GID) ? iattr->ia_gid : igid;
8395                 uid = (mask & ATTR_UID) ? iattr->ia_uid : iuid;
8396 +               tag = (mask & ATTR_TAG) ? iattr->ia_tag : itag;
8397  
8398                 /*
8399                  * Do a quota reservation only if uid/gid is actually
8400 @@ -179,7 +256,8 @@ xfs_setattr(
8401                  */
8402                 if (XFS_IS_QUOTA_RUNNING(mp) &&
8403                     ((XFS_IS_UQUOTA_ON(mp) && iuid != uid) ||
8404 -                    (XFS_IS_GQUOTA_ON(mp) && igid != gid))) {
8405 +                    (XFS_IS_GQUOTA_ON(mp) && igid != gid) ||
8406 +                    (XFS_IS_GQUOTA_ON(mp) && itag != tag))) {
8407                         ASSERT(tp);
8408                         code = xfs_qm_vop_chown_reserve(tp, ip, udqp, gdqp,
8409                                                 capable(CAP_FOWNER) ?
8410 @@ -340,7 +418,7 @@ xfs_setattr(
8411         /*
8412          * Change file ownership.  Must be the owner or privileged.
8413          */
8414 -       if (mask & (ATTR_UID|ATTR_GID)) {
8415 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8416                 /*
8417                  * CAP_FSETID overrides the following restrictions:
8418                  *
8419 @@ -356,6 +434,10 @@ xfs_setattr(
8420                  * Change the ownerships and register quota modifications
8421                  * in the transaction.
8422                  */
8423 +               if (itag != tag) {
8424 +                       ip->i_d.di_tag = tag;
8425 +                       inode->i_tag = tag;
8426 +               }
8427                 if (iuid != uid) {
8428                         if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_UQUOTA_ON(mp)) {
8429                                 ASSERT(mask & ATTR_UID);
8430 diff -NurpP --minimal linux-2.6.32.56/fs/xfs/xfs_vnodeops.h linux-2.6.32.56-vs2.3.0.36.29.9/fs/xfs/xfs_vnodeops.h
8431 --- linux-2.6.32.56/fs/xfs/xfs_vnodeops.h       2012-02-09 10:22:31.000000000 +0100
8432 +++ linux-2.6.32.56-vs2.3.0.36.29.9/fs/xfs/xfs_vnodeops.h       2011-06-10 13:03:02.000000000 +0200
8433 @@ -14,6 +14,7 @@ struct xfs_inode;
8434  struct xfs_iomap;
8435  
8436  
8437 +int xfs_sync_xflags(struct xfs_inode *ip);
8438  int xfs_setattr(struct xfs_inode *ip, struct iattr *vap, int flags);
8439  #define        XFS_ATTR_DMI            0x01    /* invocation from a DMI function */
8440  #define        XFS_ATTR_NONBLOCK       0x02    /* return EAGAIN if operation would block */
8441 diff -NurpP --minimal linux-2.6.32.56/include/asm-generic/tlb.h linux-2.6.32.56-vs2.3.0.36.29.9/include/asm-generic/tlb.h
8442 --- linux-2.6.32.56/include/asm-generic/tlb.h   2009-09-10 15:26:24.000000000 +0200
8443 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/asm-generic/tlb.h   2011-06-10 13:03:02.000000000 +0200
8444 @@ -14,6 +14,7 @@
8445  #define _ASM_GENERIC__TLB_H
8446  
8447  #include <linux/swap.h>
8448 +#include <linux/vs_memory.h>
8449  #include <asm/pgalloc.h>
8450  #include <asm/tlbflush.h>
8451  
8452 diff -NurpP --minimal linux-2.6.32.56/include/linux/Kbuild linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/Kbuild
8453 --- linux-2.6.32.56/include/linux/Kbuild        2009-12-03 20:02:54.000000000 +0100
8454 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/Kbuild        2011-06-10 13:03:02.000000000 +0200
8455 @@ -382,5 +382,8 @@ unifdef-y += xattr.h
8456  unifdef-y += xfrm.h
8457  
8458  objhdr-y += version.h
8459 +
8460 +header-y += vserver/
8461  header-y += wimax.h
8462  header-y += wimax/
8463 +
8464 diff -NurpP --minimal linux-2.6.32.56/include/linux/capability.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/capability.h
8465 --- linux-2.6.32.56/include/linux/capability.h  2009-12-03 20:02:54.000000000 +0100
8466 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/capability.h  2011-06-10 13:03:02.000000000 +0200
8467 @@ -285,6 +285,7 @@ struct cpu_vfs_cap_data {
8468     arbitrary SCSI commands */
8469  /* Allow setting encryption key on loopback filesystem */
8470  /* Allow setting zone reclaim policy */
8471 +/* Allow the selection of a security context */
8472  
8473  #define CAP_SYS_ADMIN        21
8474  
8475 @@ -357,7 +358,13 @@ struct cpu_vfs_cap_data {
8476  
8477  #define CAP_MAC_ADMIN        33
8478  
8479 -#define CAP_LAST_CAP         CAP_MAC_ADMIN
8480 +/* Allow context manipulations */
8481 +/* Allow changing context info on files */
8482 +
8483 +#define CAP_CONTEXT         34
8484 +
8485 +
8486 +#define CAP_LAST_CAP         CAP_CONTEXT
8487  
8488  #define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
8489  
8490 diff -NurpP --minimal linux-2.6.32.56/include/linux/devpts_fs.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/devpts_fs.h
8491 --- linux-2.6.32.56/include/linux/devpts_fs.h   2008-12-25 00:26:37.000000000 +0100
8492 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/devpts_fs.h   2011-06-10 13:03:02.000000000 +0200
8493 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
8494  
8495  #endif
8496  
8497 -
8498  #endif /* _LINUX_DEVPTS_FS_H */
8499 diff -NurpP --minimal linux-2.6.32.56/include/linux/ext2_fs.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/ext2_fs.h
8500 --- linux-2.6.32.56/include/linux/ext2_fs.h     2012-02-09 10:22:31.000000000 +0100
8501 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/ext2_fs.h     2011-11-17 12:18:26.000000000 +0100
8502 @@ -189,8 +189,12 @@ struct ext2_group_desc
8503  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
8504  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
8505  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
8506 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
8507  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
8508  
8509 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
8510 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
8511 +
8512  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
8513  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
8514  
8515 @@ -274,7 +278,8 @@ struct ext2_inode {
8516                         __u16   i_pad1;
8517                         __le16  l_i_uid_high;   /* these 2 fields    */
8518                         __le16  l_i_gid_high;   /* were reserved2[0] */
8519 -                       __u32   l_i_reserved2;
8520 +                       __le16  l_i_tag;        /* Context Tag */
8521 +                       __u16   l_i_reserved2;
8522                 } linux2;
8523                 struct {
8524                         __u8    h_i_frag;       /* Fragment number */
8525 @@ -303,6 +308,7 @@ struct ext2_inode {
8526  #define i_gid_low      i_gid
8527  #define i_uid_high     osd2.linux2.l_i_uid_high
8528  #define i_gid_high     osd2.linux2.l_i_gid_high
8529 +#define i_raw_tag      osd2.linux2.l_i_tag
8530  #define i_reserved2    osd2.linux2.l_i_reserved2
8531  #endif
8532  
8533 @@ -347,6 +353,7 @@ struct ext2_inode {
8534  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
8535  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
8536  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
8537 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
8538  
8539  
8540  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
8541 diff -NurpP --minimal linux-2.6.32.56/include/linux/ext3_fs.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/ext3_fs.h
8542 --- linux-2.6.32.56/include/linux/ext3_fs.h     2012-02-09 10:22:31.000000000 +0100
8543 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/ext3_fs.h     2011-11-17 12:18:26.000000000 +0100
8544 @@ -173,10 +173,14 @@ struct ext3_group_desc
8545  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
8546  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
8547  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
8548 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
8549  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
8550  
8551 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
8552 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
8553 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
8554 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
8555 +
8556 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
8557 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
8558  
8559  /* Flags that should be inherited by new inodes from their parent. */
8560  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
8561 @@ -320,7 +324,8 @@ struct ext3_inode {
8562                         __u16   i_pad1;
8563                         __le16  l_i_uid_high;   /* these 2 fields    */
8564                         __le16  l_i_gid_high;   /* were reserved2[0] */
8565 -                       __u32   l_i_reserved2;
8566 +                       __le16  l_i_tag;        /* Context Tag */
8567 +                       __u16   l_i_reserved2;
8568                 } linux2;
8569                 struct {
8570                         __u8    h_i_frag;       /* Fragment number */
8571 @@ -351,6 +356,7 @@ struct ext3_inode {
8572  #define i_gid_low      i_gid
8573  #define i_uid_high     osd2.linux2.l_i_uid_high
8574  #define i_gid_high     osd2.linux2.l_i_gid_high
8575 +#define i_raw_tag      osd2.linux2.l_i_tag
8576  #define i_reserved2    osd2.linux2.l_i_reserved2
8577  
8578  #elif defined(__GNU__)
8579 @@ -414,6 +420,7 @@ struct ext3_inode {
8580  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
8581  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
8582                                                   * error in ordered mode */
8583 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
8584  
8585  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
8586  #ifndef _LINUX_EXT2_FS_H
8587 @@ -892,6 +899,7 @@ extern void ext3_get_inode_flags(struct 
8588  extern void ext3_set_aops(struct inode *inode);
8589  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
8590                        u64 start, u64 len);
8591 +extern int ext3_sync_flags(struct inode *, int, int);
8592  
8593  /* ioctl.c */
8594  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
8595 diff -NurpP --minimal linux-2.6.32.56/include/linux/fs.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/fs.h
8596 --- linux-2.6.32.56/include/linux/fs.h  2012-02-09 10:22:31.000000000 +0100
8597 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/fs.h  2011-08-08 22:40:36.000000000 +0200
8598 @@ -208,6 +208,9 @@ struct inodes_stat_t {
8599  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
8600  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
8601  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
8602 +#define MS_TAGGED      (1<<25) /* use generic inode tagging */
8603 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
8604 +#define MS_NOTAGCHECK  (1<<27) /* don't check tags */
8605  #define MS_ACTIVE      (1<<30)
8606  #define MS_NOUSER      (1<<31)
8607  
8608 @@ -234,6 +237,14 @@ struct inodes_stat_t {
8609  #define S_NOCMTIME     128     /* Do not update file c/mtime */
8610  #define S_SWAPFILE     256     /* Do not truncate: swapon got its bmaps */
8611  #define S_PRIVATE      512     /* Inode is fs-internal */
8612 +#define S_IXUNLINK     1024    /* Immutable Invert on unlink */
8613 +
8614 +/* Linux-VServer related Inode flags */
8615 +
8616 +#define V_VALID                1
8617 +#define V_XATTR                2
8618 +#define V_BARRIER      4       /* Barrier for chroot() */
8619 +#define V_COW          8       /* Copy on Write */
8620  
8621  /*
8622   * Note that nosuid etc flags are inode-specific: setting some file-system
8623 @@ -256,12 +267,15 @@ struct inodes_stat_t {
8624  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
8625                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
8626  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
8627 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8628 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
8629 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8630 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
8631 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
8632  
8633  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
8634  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
8635  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
8636 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
8637 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
8638  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
8639  
8640  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
8641 @@ -269,6 +283,16 @@ struct inodes_stat_t {
8642  #define IS_SWAPFILE(inode)     ((inode)->i_flags & S_SWAPFILE)
8643  #define IS_PRIVATE(inode)      ((inode)->i_flags & S_PRIVATE)
8644  
8645 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
8646 +
8647 +#ifdef CONFIG_VSERVER_COWBL
8648 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
8649 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
8650 +#else
8651 +#  define IS_COW(inode)                (0)
8652 +#  define IS_COW_LINK(inode)   (0)
8653 +#endif
8654 +
8655  /* the read-only stuff doesn't really belong here, but any other place is
8656     probably as bad and I don't want to create yet another include file. */
8657  
8658 @@ -350,11 +374,14 @@ struct inodes_stat_t {
8659  #define FS_TOPDIR_FL                   0x00020000 /* Top of directory hierarchies*/
8660  #define FS_EXTENT_FL                   0x00080000 /* Extents */
8661  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
8662 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
8663  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
8664  
8665 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
8666 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
8667 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
8668 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
8669  
8670 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
8671 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
8672  
8673  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
8674  #define SYNC_FILE_RANGE_WRITE          2
8675 @@ -436,6 +463,7 @@ typedef void (dio_iodone_t)(struct kiocb
8676  #define ATTR_KILL_PRIV (1 << 14)
8677  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
8678  #define ATTR_TIMES_SET (1 << 16)
8679 +#define ATTR_TAG       (1 << 17)
8680  
8681  /*
8682   * This is the Inode Attributes structure, used for notify_change().  It
8683 @@ -451,6 +479,7 @@ struct iattr {
8684         umode_t         ia_mode;
8685         uid_t           ia_uid;
8686         gid_t           ia_gid;
8687 +       tag_t           ia_tag;
8688         loff_t          ia_size;
8689         struct timespec ia_atime;
8690         struct timespec ia_mtime;
8691 @@ -464,6 +493,9 @@ struct iattr {
8692         struct file     *ia_file;
8693  };
8694  
8695 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
8696 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
8697 +
8698  /*
8699   * Includes for diskquotas.
8700   */
8701 @@ -730,7 +762,9 @@ struct inode {
8702         unsigned int            i_nlink;
8703         uid_t                   i_uid;
8704         gid_t                   i_gid;
8705 +       tag_t                   i_tag;
8706         dev_t                   i_rdev;
8707 +       dev_t                   i_mdev;
8708         u64                     i_version;
8709         loff_t                  i_size;
8710  #ifdef __NEED_I_SIZE_ORDERED
8711 @@ -777,7 +811,8 @@ struct inode {
8712         unsigned long           i_state;
8713         unsigned long           dirtied_when;   /* jiffies of first dirtying */
8714  
8715 -       unsigned int            i_flags;
8716 +       unsigned short          i_flags;
8717 +       unsigned short          i_vflags;
8718  
8719         atomic_t                i_writecount;
8720  #ifdef CONFIG_SECURITY
8721 @@ -865,12 +900,12 @@ static inline void i_size_write(struct i
8722  
8723  static inline unsigned iminor(const struct inode *inode)
8724  {
8725 -       return MINOR(inode->i_rdev);
8726 +       return MINOR(inode->i_mdev);
8727  }
8728  
8729  static inline unsigned imajor(const struct inode *inode)
8730  {
8731 -       return MAJOR(inode->i_rdev);
8732 +       return MAJOR(inode->i_mdev);
8733  }
8734  
8735  extern struct block_device *I_BDEV(struct inode *inode);
8736 @@ -929,6 +964,7 @@ struct file {
8737         loff_t                  f_pos;
8738         struct fown_struct      f_owner;
8739         const struct cred       *f_cred;
8740 +       xid_t                   f_xid;
8741         struct file_ra_state    f_ra;
8742  
8743         u64                     f_version;
8744 @@ -1070,6 +1106,7 @@ struct file_lock {
8745         struct file *fl_file;
8746         loff_t fl_start;
8747         loff_t fl_end;
8748 +       xid_t fl_xid;
8749  
8750         struct fasync_struct *  fl_fasync; /* for lease break notifications */
8751         unsigned long fl_break_time;    /* for nonblocking lease breaks */
8752 @@ -1537,6 +1574,7 @@ struct inode_operations {
8753         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
8754         ssize_t (*listxattr) (struct dentry *, char *, size_t);
8755         int (*removexattr) (struct dentry *, const char *);
8756 +       int (*sync_flags) (struct inode *, int, int);
8757         void (*truncate_range)(struct inode *, loff_t, loff_t);
8758         long (*fallocate)(struct inode *inode, int mode, loff_t offset,
8759                           loff_t len);
8760 @@ -1557,6 +1595,7 @@ extern ssize_t vfs_readv(struct file *, 
8761                 unsigned long, loff_t *);
8762  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
8763                 unsigned long, loff_t *);
8764 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
8765  
8766  struct super_operations {
8767         struct inode *(*alloc_inode)(struct super_block *sb);
8768 @@ -2356,6 +2395,7 @@ extern int dcache_dir_open(struct inode 
8769  extern int dcache_dir_close(struct inode *, struct file *);
8770  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
8771  extern int dcache_readdir(struct file *, void *, filldir_t);
8772 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
8773  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
8774  extern int simple_statfs(struct dentry *, struct kstatfs *);
8775  extern int simple_link(struct dentry *, struct inode *, struct dentry *);
8776 diff -NurpP --minimal linux-2.6.32.56/include/linux/gfs2_ondisk.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/gfs2_ondisk.h
8777 --- linux-2.6.32.56/include/linux/gfs2_ondisk.h 2009-12-03 20:02:55.000000000 +0100
8778 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/gfs2_ondisk.h 2011-06-10 13:03:02.000000000 +0200
8779 @@ -235,6 +235,9 @@ enum {
8780         gfs2fl_NoAtime          = 7,
8781         gfs2fl_Sync             = 8,
8782         gfs2fl_System           = 9,
8783 +       gfs2fl_IXUnlink         = 16,
8784 +       gfs2fl_Barrier          = 17,
8785 +       gfs2fl_Cow              = 18,
8786         gfs2fl_TruncInProg      = 29,
8787         gfs2fl_InheritDirectio  = 30,
8788         gfs2fl_InheritJdata     = 31,
8789 @@ -251,6 +254,9 @@ enum {
8790  #define GFS2_DIF_NOATIME               0x00000080
8791  #define GFS2_DIF_SYNC                  0x00000100
8792  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
8793 +#define GFS2_DIF_IXUNLINK              0x00010000
8794 +#define GFS2_DIF_BARRIER               0x00020000
8795 +#define GFS2_DIF_COW                   0x00040000
8796  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
8797  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000
8798  #define GFS2_DIF_INHERIT_JDATA         0x80000000
8799 diff -NurpP --minimal linux-2.6.32.56/include/linux/if_tun.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/if_tun.h
8800 --- linux-2.6.32.56/include/linux/if_tun.h      2009-12-03 20:02:55.000000000 +0100
8801 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/if_tun.h      2011-06-10 13:03:02.000000000 +0200
8802 @@ -48,6 +48,7 @@
8803  #define TUNGETIFF      _IOR('T', 210, unsigned int)
8804  #define TUNGETSNDBUF   _IOR('T', 211, int)
8805  #define TUNSETSNDBUF   _IOW('T', 212, int)
8806 +#define TUNSETNID     _IOW('T', 215, int)
8807  
8808  /* TUNSETIFF ifr flags */
8809  #define IFF_TUN                0x0001
8810 diff -NurpP --minimal linux-2.6.32.56/include/linux/init_task.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/init_task.h
8811 --- linux-2.6.32.56/include/linux/init_task.h   2009-12-03 20:02:55.000000000 +0100
8812 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/init_task.h   2011-06-10 13:03:02.000000000 +0200
8813 @@ -184,6 +184,10 @@ extern struct cred init_cred;
8814         INIT_FTRACE_GRAPH                                               \
8815         INIT_TRACE_RECURSION                                            \
8816         INIT_TASK_RCU_PREEMPT(tsk)                                      \
8817 +       .xid            = 0,                                            \
8818 +       .vx_info        = NULL,                                         \
8819 +       .nid            = 0,                                            \
8820 +       .nx_info        = NULL,                                         \
8821  }
8822  
8823  
8824 diff -NurpP --minimal linux-2.6.32.56/include/linux/ipc.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/ipc.h
8825 --- linux-2.6.32.56/include/linux/ipc.h 2009-12-03 20:02:55.000000000 +0100
8826 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/ipc.h 2011-06-10 13:03:02.000000000 +0200
8827 @@ -91,6 +91,7 @@ struct kern_ipc_perm
8828         key_t           key;
8829         uid_t           uid;
8830         gid_t           gid;
8831 +       xid_t           xid;
8832         uid_t           cuid;
8833         gid_t           cgid;
8834         mode_t          mode; 
8835 diff -NurpP --minimal linux-2.6.32.56/include/linux/loop.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/loop.h
8836 --- linux-2.6.32.56/include/linux/loop.h        2009-09-10 15:26:25.000000000 +0200
8837 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/loop.h        2011-06-10 13:03:02.000000000 +0200
8838 @@ -45,6 +45,7 @@ struct loop_device {
8839         struct loop_func_table *lo_encryption;
8840         __u32           lo_init[2];
8841         uid_t           lo_key_owner;   /* Who set the key */
8842 +       xid_t           lo_xid;
8843         int             (*ioctl)(struct loop_device *, int cmd, 
8844                                  unsigned long arg); 
8845  
8846 diff -NurpP --minimal linux-2.6.32.56/include/linux/magic.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/magic.h
8847 --- linux-2.6.32.56/include/linux/magic.h       2009-12-03 20:02:55.000000000 +0100
8848 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/magic.h       2011-06-10 13:03:02.000000000 +0200
8849 @@ -3,7 +3,7 @@
8850  
8851  #define ADFS_SUPER_MAGIC       0xadf5
8852  #define AFFS_SUPER_MAGIC       0xadff
8853 -#define AFS_SUPER_MAGIC                0x5346414F
8854 +#define AFS_SUPER_MAGIC                0x5346414F
8855  #define AUTOFS_SUPER_MAGIC     0x0187
8856  #define CODA_SUPER_MAGIC       0x73757245
8857  #define CRAMFS_MAGIC           0x28cd3d45      /* some random number */
8858 @@ -38,6 +38,7 @@
8859  #define NFS_SUPER_MAGIC                0x6969
8860  #define OPENPROM_SUPER_MAGIC   0x9fa1
8861  #define PROC_SUPER_MAGIC       0x9fa0
8862 +#define DEVPTS_SUPER_MAGIC     0x1cd1
8863  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
8864  
8865  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
8866 diff -NurpP --minimal linux-2.6.32.56/include/linux/major.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/major.h
8867 --- linux-2.6.32.56/include/linux/major.h       2009-09-10 15:26:25.000000000 +0200
8868 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/major.h       2011-06-10 13:03:02.000000000 +0200
8869 @@ -15,6 +15,7 @@
8870  #define HD_MAJOR               IDE0_MAJOR
8871  #define PTY_SLAVE_MAJOR                3
8872  #define TTY_MAJOR              4
8873 +#define VROOT_MAJOR            4
8874  #define TTYAUX_MAJOR           5
8875  #define LP_MAJOR               6
8876  #define VCS_MAJOR              7
8877 diff -NurpP --minimal linux-2.6.32.56/include/linux/memcontrol.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/memcontrol.h
8878 --- linux-2.6.32.56/include/linux/memcontrol.h  2009-12-03 20:02:55.000000000 +0100
8879 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/memcontrol.h  2011-06-10 13:03:02.000000000 +0200
8880 @@ -70,6 +70,13 @@ int task_in_mem_cgroup(struct task_struc
8881  
8882  extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
8883  
8884 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
8885 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
8886 +
8887 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
8888 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
8889 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
8890 +
8891  static inline
8892  int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
8893  {
8894 diff -NurpP --minimal linux-2.6.32.56/include/linux/mm_types.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/mm_types.h
8895 --- linux-2.6.32.56/include/linux/mm_types.h    2012-02-09 10:22:31.000000000 +0100
8896 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/mm_types.h    2011-06-10 13:03:02.000000000 +0200
8897 @@ -246,6 +246,7 @@ struct mm_struct {
8898  
8899         /* Architecture-specific MM context */
8900         mm_context_t context;
8901 +       struct vx_info *mm_vx_info;
8902  
8903         /* Swap token stuff */
8904         /*
8905 diff -NurpP --minimal linux-2.6.32.56/include/linux/mount.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/mount.h
8906 --- linux-2.6.32.56/include/linux/mount.h       2009-09-10 15:26:25.000000000 +0200
8907 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/mount.h       2011-06-10 13:03:02.000000000 +0200
8908 @@ -36,6 +36,9 @@ struct mnt_namespace;
8909  #define MNT_UNBINDABLE 0x2000  /* if the vfsmount is a unbindable mount */
8910  #define MNT_PNODE_MASK 0x3000  /* propagation flag mask */
8911  
8912 +#define MNT_TAGID      0x10000
8913 +#define MNT_NOTAG      0x20000
8914 +
8915  struct vfsmount {
8916         struct list_head mnt_hash;
8917         struct vfsmount *mnt_parent;    /* fs we are mounted on */
8918 @@ -70,6 +73,7 @@ struct vfsmount {
8919  #else
8920         int mnt_writers;
8921  #endif
8922 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
8923  };
8924  
8925  static inline int *get_mnt_writers_ptr(struct vfsmount *mnt)
8926 diff -NurpP --minimal linux-2.6.32.56/include/linux/net.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/net.h
8927 --- linux-2.6.32.56/include/linux/net.h 2009-12-03 20:02:55.000000000 +0100
8928 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/net.h 2011-06-10 13:03:02.000000000 +0200
8929 @@ -69,6 +69,7 @@ struct net;
8930  #define SOCK_NOSPACE           2
8931  #define SOCK_PASSCRED          3
8932  #define SOCK_PASSSEC           4
8933 +#define SOCK_USER_SOCKET       5
8934  
8935  #ifndef ARCH_HAS_SOCKET_TYPES
8936  /**
8937 diff -NurpP --minimal linux-2.6.32.56/include/linux/nfs_mount.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/nfs_mount.h
8938 --- linux-2.6.32.56/include/linux/nfs_mount.h   2009-03-24 14:22:43.000000000 +0100
8939 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/nfs_mount.h   2011-06-10 13:03:02.000000000 +0200
8940 @@ -63,7 +63,8 @@ struct nfs_mount_data {
8941  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
8942  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
8943  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
8944 -#define NFS_MOUNT_FLAGMASK     0xFFFF
8945 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
8946 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
8947  
8948  /* The following are for internal use only */
8949  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
8950 diff -NurpP --minimal linux-2.6.32.56/include/linux/nsproxy.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/nsproxy.h
8951 --- linux-2.6.32.56/include/linux/nsproxy.h     2009-06-11 17:13:17.000000000 +0200
8952 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/nsproxy.h     2011-06-10 13:03:02.000000000 +0200
8953 @@ -3,6 +3,7 @@
8954  
8955  #include <linux/spinlock.h>
8956  #include <linux/sched.h>
8957 +#include <linux/vserver/debug.h>
8958  
8959  struct mnt_namespace;
8960  struct uts_namespace;
8961 @@ -63,22 +64,33 @@ static inline struct nsproxy *task_nspro
8962  }
8963  
8964  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
8965 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
8966  void exit_task_namespaces(struct task_struct *tsk);
8967  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
8968  void free_nsproxy(struct nsproxy *ns);
8969  int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
8970         struct fs_struct *);
8971  
8972 -static inline void put_nsproxy(struct nsproxy *ns)
8973 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
8974 +
8975 +static inline void __get_nsproxy(struct nsproxy *ns,
8976 +       const char *_file, int _line)
8977  {
8978 -       if (atomic_dec_and_test(&ns->count)) {
8979 -               free_nsproxy(ns);
8980 -       }
8981 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
8982 +               ns, atomic_read(&ns->count), _file, _line);
8983 +       atomic_inc(&ns->count);
8984  }
8985  
8986 -static inline void get_nsproxy(struct nsproxy *ns)
8987 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
8988 +
8989 +static inline void __put_nsproxy(struct nsproxy *ns,
8990 +       const char *_file, int _line)
8991  {
8992 -       atomic_inc(&ns->count);
8993 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
8994 +               ns, atomic_read(&ns->count), _file, _line);
8995 +       if (atomic_dec_and_test(&ns->count)) {
8996 +               free_nsproxy(ns);
8997 +       }
8998  }
8999  
9000  #ifdef CONFIG_CGROUP_NS
9001 diff -NurpP --minimal linux-2.6.32.56/include/linux/pid.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/pid.h
9002 --- linux-2.6.32.56/include/linux/pid.h 2012-02-09 10:22:31.000000000 +0100
9003 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/pid.h 2011-06-10 13:03:02.000000000 +0200
9004 @@ -8,7 +8,8 @@ enum pid_type
9005         PIDTYPE_PID,
9006         PIDTYPE_PGID,
9007         PIDTYPE_SID,
9008 -       PIDTYPE_MAX
9009 +       PIDTYPE_MAX,
9010 +       PIDTYPE_REALPID
9011  };
9012  
9013  /*
9014 @@ -160,6 +161,7 @@ static inline pid_t pid_nr(struct pid *p
9015  }
9016  
9017  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
9018 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
9019  pid_t pid_vnr(struct pid *pid);
9020  
9021  #define do_each_pid_task(pid, type, task)                              \
9022 diff -NurpP --minimal linux-2.6.32.56/include/linux/proc_fs.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/proc_fs.h
9023 --- linux-2.6.32.56/include/linux/proc_fs.h     2009-12-03 20:02:56.000000000 +0100
9024 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/proc_fs.h     2011-06-10 13:03:02.000000000 +0200
9025 @@ -56,6 +56,7 @@ struct proc_dir_entry {
9026         nlink_t nlink;
9027         uid_t uid;
9028         gid_t gid;
9029 +       int vx_flags;
9030         loff_t size;
9031         const struct inode_operations *proc_iops;
9032         /*
9033 @@ -250,12 +251,18 @@ kclist_add(struct kcore_list *new, void 
9034  extern void kclist_add(struct kcore_list *, void *, size_t, int type);
9035  #endif
9036  
9037 +struct vx_info;
9038 +struct nx_info;
9039 +
9040  union proc_op {
9041         int (*proc_get_link)(struct inode *, struct path *);
9042         int (*proc_read)(struct task_struct *task, char *page);
9043         int (*proc_show)(struct seq_file *m,
9044                 struct pid_namespace *ns, struct pid *pid,
9045                 struct task_struct *task);
9046 +       int (*proc_vs_read)(char *page);
9047 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
9048 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
9049  };
9050  
9051  struct ctl_table_header;
9052 @@ -263,6 +270,7 @@ struct ctl_table;
9053  
9054  struct proc_inode {
9055         struct pid *pid;
9056 +       int vx_flags;
9057         int fd;
9058         union proc_op op;
9059         struct proc_dir_entry *pde;
9060 diff -NurpP --minimal linux-2.6.32.56/include/linux/quotaops.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/quotaops.h
9061 --- linux-2.6.32.56/include/linux/quotaops.h    2012-02-09 10:22:31.000000000 +0100
9062 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/quotaops.h    2011-06-10 13:03:02.000000000 +0200
9063 @@ -8,6 +8,7 @@
9064  #define _LINUX_QUOTAOPS_
9065  
9066  #include <linux/fs.h>
9067 +#include <linux/vs_dlimit.h>
9068  
9069  static inline struct quota_info *sb_dqopt(struct super_block *sb)
9070  {
9071 @@ -157,10 +158,14 @@ static inline void vfs_dq_init(struct in
9072   * a transaction (deadlocks possible otherwise) */
9073  static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
9074  {
9075 +       if (dl_alloc_space(inode, nr))
9076 +               return 1;
9077         if (sb_any_quota_active(inode->i_sb)) {
9078                 /* Used space is updated in alloc_space() */
9079 -               if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA)
9080 +               if (inode->i_sb->dq_op->alloc_space(inode, nr, 1) == NO_QUOTA) {
9081 +                       dl_free_space(inode, nr);
9082                         return 1;
9083 +               }
9084         }
9085         else
9086                 inode_add_bytes(inode, nr);
9087 @@ -177,10 +182,14 @@ static inline int vfs_dq_prealloc_space(
9088  
9089  static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
9090  {
9091 +       if (dl_alloc_space(inode, nr))
9092 +               return 1;
9093         if (sb_any_quota_active(inode->i_sb)) {
9094                 /* Used space is updated in alloc_space() */
9095 -               if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA)
9096 +               if (inode->i_sb->dq_op->alloc_space(inode, nr, 0) == NO_QUOTA) {
9097 +                       dl_free_space(inode, nr);
9098                         return 1;
9099 +               }
9100         }
9101         else
9102                 inode_add_bytes(inode, nr);
9103 @@ -197,10 +206,14 @@ static inline int vfs_dq_alloc_space(str
9104  
9105  static inline int vfs_dq_reserve_space(struct inode *inode, qsize_t nr)
9106  {
9107 +       if (dl_reserve_space(inode, nr))
9108 +               return 1;
9109         if (sb_any_quota_active(inode->i_sb)) {
9110                 /* Used space is updated in alloc_space() */
9111 -               if (inode->i_sb->dq_op->reserve_space(inode, nr, 0) == NO_QUOTA)
9112 +               if (inode->i_sb->dq_op->reserve_space(inode, nr, 0) == NO_QUOTA) {
9113 +                       dl_release_space(inode, nr);
9114                         return 1;
9115 +               }
9116         }
9117         else
9118                 inode_add_rsv_space(inode, nr);
9119 @@ -209,10 +222,14 @@ static inline int vfs_dq_reserve_space(s
9120  
9121  static inline int vfs_dq_alloc_inode(struct inode *inode)
9122  {
9123 +       if (dl_alloc_inode(inode))
9124 +               return 1;
9125         if (sb_any_quota_active(inode->i_sb)) {
9126                 vfs_dq_init(inode);
9127 -               if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA)
9128 +               if (inode->i_sb->dq_op->alloc_inode(inode, 1) == NO_QUOTA) {
9129 +                       dl_free_inode(inode);
9130                         return 1;
9131 +               }
9132         }
9133         return 0;
9134  }
9135 @@ -222,9 +239,13 @@ static inline int vfs_dq_alloc_inode(str
9136   */
9137  static inline int vfs_dq_claim_space(struct inode *inode, qsize_t nr)
9138  {
9139 +       if (dl_claim_space(inode, nr))
9140 +               return 1;
9141         if (sb_any_quota_active(inode->i_sb)) {
9142 -               if (inode->i_sb->dq_op->claim_space(inode, nr) == NO_QUOTA)
9143 +               if (inode->i_sb->dq_op->claim_space(inode, nr) == NO_QUOTA) {
9144 +                       dl_release_space(inode, nr);
9145                         return 1;
9146 +               }
9147         } else
9148                 inode_claim_rsv_space(inode, nr);
9149  
9150 @@ -242,6 +263,7 @@ void vfs_dq_release_reservation_space(st
9151                 inode->i_sb->dq_op->release_rsv(inode, nr);
9152         else
9153                 inode_sub_rsv_space(inode, nr);
9154 +       dl_release_space(inode, nr);
9155  }
9156  
9157  static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
9158 @@ -250,6 +272,7 @@ static inline void vfs_dq_free_space_nod
9159                 inode->i_sb->dq_op->free_space(inode, nr);
9160         else
9161                 inode_sub_bytes(inode, nr);
9162 +       dl_free_space(inode, nr);
9163  }
9164  
9165  static inline void vfs_dq_free_space(struct inode *inode, qsize_t nr)
9166 @@ -262,6 +285,7 @@ static inline void vfs_dq_free_inode(str
9167  {
9168         if (sb_any_quota_active(inode->i_sb))
9169                 inode->i_sb->dq_op->free_inode(inode, 1);
9170 +       dl_free_inode(inode);
9171  }
9172  
9173  /* Cannot be called inside a transaction */
9174 @@ -365,6 +389,8 @@ static inline int vfs_dq_transfer(struct
9175  
9176  static inline int vfs_dq_prealloc_space_nodirty(struct inode *inode, qsize_t nr)
9177  {
9178 +       if (dl_alloc_space(inode, nr))
9179 +               return 1;
9180         inode_add_bytes(inode, nr);
9181         return 0;
9182  }
9183 @@ -378,6 +404,8 @@ static inline int vfs_dq_prealloc_space(
9184  
9185  static inline int vfs_dq_alloc_space_nodirty(struct inode *inode, qsize_t nr)
9186  {
9187 +       if (dl_alloc_space(inode, nr))
9188 +               return 1;
9189         inode_add_bytes(inode, nr);
9190         return 0;
9191  }
9192 @@ -391,22 +419,28 @@ static inline int vfs_dq_alloc_space(str
9193  
9194  static inline int vfs_dq_reserve_space(struct inode *inode, qsize_t nr)
9195  {
9196 +       if (dl_reserve_space(inode, nr))
9197 +               return 1;
9198         return 0;
9199  }
9200  
9201  static inline int vfs_dq_claim_space(struct inode *inode, qsize_t nr)
9202  {
9203 +       if (dl_claim_space(inode, nr))
9204 +               return 1;
9205         return vfs_dq_alloc_space(inode, nr);
9206  }
9207  
9208  static inline
9209  int vfs_dq_release_reservation_space(struct inode *inode, qsize_t nr)
9210  {
9211 +       dl_release_space(inode, nr);
9212         return 0;
9213  }
9214  
9215  static inline void vfs_dq_free_space_nodirty(struct inode *inode, qsize_t nr)
9216  {
9217 +       dl_free_space(inode, nr);
9218         inode_sub_bytes(inode, nr);
9219  }
9220  
9221 diff -NurpP --minimal linux-2.6.32.56/include/linux/reboot.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/reboot.h
9222 --- linux-2.6.32.56/include/linux/reboot.h      2008-12-25 00:26:37.000000000 +0100
9223 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/reboot.h      2011-06-10 13:03:02.000000000 +0200
9224 @@ -33,6 +33,7 @@
9225  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
9226  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
9227  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
9228 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
9229  
9230  
9231  #ifdef __KERNEL__
9232 diff -NurpP --minimal linux-2.6.32.56/include/linux/reiserfs_fs.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/reiserfs_fs.h
9233 --- linux-2.6.32.56/include/linux/reiserfs_fs.h 2009-09-10 15:26:26.000000000 +0200
9234 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/reiserfs_fs.h 2011-06-10 13:03:02.000000000 +0200
9235 @@ -899,6 +899,11 @@ struct stat_data_v1 {
9236  #define REISERFS_COMPR_FL     FS_COMPR_FL
9237  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
9238  
9239 +/* unfortunately reiserfs sdattr is only 16 bit */
9240 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
9241 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
9242 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
9243 +
9244  /* persistent flags that file inherits from the parent directory */
9245  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
9246                                 REISERFS_SYNC_FL |      \
9247 @@ -908,6 +913,9 @@ struct stat_data_v1 {
9248                                 REISERFS_COMPR_FL |     \
9249                                 REISERFS_NOTAIL_FL )
9250  
9251 +#define REISERFS_FL_USER_VISIBLE       0x80FF
9252 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
9253 +
9254  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
9255     address blocks) */
9256  struct stat_data {
9257 @@ -1989,6 +1997,7 @@ static inline void reiserfs_update_sd(st
9258  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
9259  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
9260  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
9261 +int reiserfs_sync_flags(struct inode *inode, int, int);
9262  
9263  /* namei.c */
9264  void set_de_name_and_namelen(struct reiserfs_dir_entry *de);
9265 diff -NurpP --minimal linux-2.6.32.56/include/linux/reiserfs_fs_sb.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/reiserfs_fs_sb.h
9266 --- linux-2.6.32.56/include/linux/reiserfs_fs_sb.h      2009-09-10 15:26:26.000000000 +0200
9267 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/reiserfs_fs_sb.h      2011-06-10 13:03:02.000000000 +0200
9268 @@ -456,6 +456,7 @@ enum reiserfs_mount_options {
9269         REISERFS_EXPOSE_PRIVROOT,
9270         REISERFS_BARRIER_NONE,
9271         REISERFS_BARRIER_FLUSH,
9272 +       REISERFS_TAGGED,
9273  
9274         /* Actions on error */
9275         REISERFS_ERROR_PANIC,
9276 diff -NurpP --minimal linux-2.6.32.56/include/linux/sched.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/sched.h
9277 --- linux-2.6.32.56/include/linux/sched.h       2012-02-09 10:22:31.000000000 +0100
9278 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/sched.h       2011-06-10 13:03:02.000000000 +0200
9279 @@ -389,25 +389,28 @@ extern void arch_unmap_area_topdown(stru
9280   * The mm counters are not protected by its page_table_lock,
9281   * so must be incremented atomically.
9282   */
9283 -#define set_mm_counter(mm, member, value) atomic_long_set(&(mm)->_##member, value)
9284 -#define get_mm_counter(mm, member) ((unsigned long)atomic_long_read(&(mm)->_##member))
9285 -#define add_mm_counter(mm, member, value) atomic_long_add(value, &(mm)->_##member)
9286 -#define inc_mm_counter(mm, member) atomic_long_inc(&(mm)->_##member)
9287 -#define dec_mm_counter(mm, member) atomic_long_dec(&(mm)->_##member)
9288 +#define __set_mm_counter(mm, member, value) \
9289 +       atomic_long_set(&(mm)->_##member, value)
9290 +#define get_mm_counter(mm, member) \
9291 +       ((unsigned long)atomic_long_read(&(mm)->_##member))
9292  
9293  #else  /* !USE_SPLIT_PTLOCKS */
9294  /*
9295   * The mm counters are protected by its page_table_lock,
9296   * so can be incremented directly.
9297   */
9298 -#define set_mm_counter(mm, member, value) (mm)->_##member = (value)
9299 +#define __set_mm_counter(mm, member, value) (mm)->_##member = (value)
9300  #define get_mm_counter(mm, member) ((mm)->_##member)
9301 -#define add_mm_counter(mm, member, value) (mm)->_##member += (value)
9302 -#define inc_mm_counter(mm, member) (mm)->_##member++
9303 -#define dec_mm_counter(mm, member) (mm)->_##member--
9304  
9305  #endif /* !USE_SPLIT_PTLOCKS */
9306  
9307 +#define set_mm_counter(mm, member, value) \
9308 +       vx_ ## member ## pages_sub((mm), (get_mm_counter(mm, member) - value))
9309 +#define add_mm_counter(mm, member, value) \
9310 +       vx_ ## member ## pages_add((mm), (value))
9311 +#define inc_mm_counter(mm, member) vx_ ## member ## pages_inc((mm))
9312 +#define dec_mm_counter(mm, member) vx_ ## member ## pages_dec((mm))
9313 +
9314  #define get_mm_rss(mm)                                 \
9315         (get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss))
9316  #define update_hiwater_rss(mm) do {                    \
9317 @@ -1185,6 +1188,12 @@ struct sched_entity {
9318         u64                     nr_wakeups_affine_attempts;
9319         u64                     nr_wakeups_passive;
9320         u64                     nr_wakeups_idle;
9321 +#ifdef CONFIG_CFS_HARD_LIMITS
9322 +       u64                     throttle_start;
9323 +       u64                     throttle_max;
9324 +       u64                     throttle_count;
9325 +       u64                     throttle_sum;
9326 +#endif
9327  #endif
9328  
9329  #ifdef CONFIG_FAIR_GROUP_SCHED
9330 @@ -1395,6 +1404,14 @@ struct task_struct {
9331  #endif
9332         seccomp_t seccomp;
9333  
9334 +/* vserver context data */
9335 +       struct vx_info *vx_info;
9336 +       struct nx_info *nx_info;
9337 +
9338 +       xid_t xid;
9339 +       nid_t nid;
9340 +       tag_t tag;
9341 +
9342  /* Thread group tracking */
9343         u32 parent_exec_id;
9344         u32 self_exec_id;
9345 @@ -1619,6 +1636,11 @@ struct pid_namespace;
9346  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
9347                         struct pid_namespace *ns);
9348  
9349 +#include <linux/vserver/base.h>
9350 +#include <linux/vserver/context.h>
9351 +#include <linux/vserver/debug.h>
9352 +#include <linux/vserver/pid.h>
9353 +
9354  static inline pid_t task_pid_nr(struct task_struct *tsk)
9355  {
9356         return tsk->pid;
9357 @@ -1632,7 +1654,8 @@ static inline pid_t task_pid_nr_ns(struc
9358  
9359  static inline pid_t task_pid_vnr(struct task_struct *tsk)
9360  {
9361 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
9362 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
9363 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
9364  }
9365  
9366  
9367 @@ -1645,7 +1668,7 @@ pid_t task_tgid_nr_ns(struct task_struct
9368  
9369  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
9370  {
9371 -       return pid_vnr(task_tgid(tsk));
9372 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
9373  }
9374  
9375  
9376 diff -NurpP --minimal linux-2.6.32.56/include/linux/shmem_fs.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/shmem_fs.h
9377 --- linux-2.6.32.56/include/linux/shmem_fs.h    2009-12-03 20:02:56.000000000 +0100
9378 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/shmem_fs.h    2011-06-10 13:03:02.000000000 +0200
9379 @@ -8,6 +8,9 @@
9380  
9381  #define SHMEM_NR_DIRECT 16
9382  
9383 +#define TMPFS_SUPER_MAGIC      0x01021994
9384 +
9385 +
9386  struct shmem_inode_info {
9387         spinlock_t              lock;
9388         unsigned long           flags;
9389 diff -NurpP --minimal linux-2.6.32.56/include/linux/stat.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/stat.h
9390 --- linux-2.6.32.56/include/linux/stat.h        2008-12-25 00:26:37.000000000 +0100
9391 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/stat.h        2011-06-10 13:03:02.000000000 +0200
9392 @@ -66,6 +66,7 @@ struct kstat {
9393         unsigned int    nlink;
9394         uid_t           uid;
9395         gid_t           gid;
9396 +       tag_t           tag;
9397         dev_t           rdev;
9398         loff_t          size;
9399         struct timespec  atime;
9400 diff -NurpP --minimal linux-2.6.32.56/include/linux/sunrpc/auth.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/sunrpc/auth.h
9401 --- linux-2.6.32.56/include/linux/sunrpc/auth.h 2009-12-03 20:02:56.000000000 +0100
9402 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/sunrpc/auth.h 2011-06-10 13:03:02.000000000 +0200
9403 @@ -25,6 +25,7 @@
9404  struct auth_cred {
9405         uid_t   uid;
9406         gid_t   gid;
9407 +       tag_t   tag;
9408         struct group_info *group_info;
9409         unsigned char machine_cred : 1;
9410  };
9411 diff -NurpP --minimal linux-2.6.32.56/include/linux/sunrpc/clnt.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/sunrpc/clnt.h
9412 --- linux-2.6.32.56/include/linux/sunrpc/clnt.h 2009-12-03 20:02:56.000000000 +0100
9413 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/sunrpc/clnt.h 2011-06-10 13:03:02.000000000 +0200
9414 @@ -49,7 +49,8 @@ struct rpc_clnt {
9415         unsigned int            cl_softrtry : 1,/* soft timeouts */
9416                                 cl_discrtry : 1,/* disconnect before retry */
9417                                 cl_autobind : 1,/* use getport() */
9418 -                               cl_chatty   : 1;/* be verbose */
9419 +                               cl_chatty   : 1,/* be verbose */
9420 +                               cl_tag      : 1;/* context tagging */
9421  
9422         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
9423         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
9424 diff -NurpP --minimal linux-2.6.32.56/include/linux/syscalls.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/syscalls.h
9425 --- linux-2.6.32.56/include/linux/syscalls.h    2012-02-09 10:22:32.000000000 +0100
9426 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/syscalls.h    2011-06-10 13:03:02.000000000 +0200
9427 @@ -548,6 +548,8 @@ asmlinkage long sys_symlink(const char _
9428  asmlinkage long sys_unlink(const char __user *pathname);
9429  asmlinkage long sys_rename(const char __user *oldname,
9430                                 const char __user *newname);
9431 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
9432 +                               umode_t mode);
9433  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
9434  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
9435  
9436 diff -NurpP --minimal linux-2.6.32.56/include/linux/sysctl.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/sysctl.h
9437 --- linux-2.6.32.56/include/linux/sysctl.h      2012-02-09 10:22:32.000000000 +0100
9438 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/sysctl.h      2011-06-10 13:03:02.000000000 +0200
9439 @@ -69,6 +69,7 @@ enum
9440         CTL_ABI=9,              /* Binary emulation */
9441         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
9442         CTL_ARLAN=254,          /* arlan wireless driver */
9443 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
9444         CTL_S390DBF=5677,       /* s390 debug */
9445         CTL_SUNRPC=7249,        /* sunrpc debug */
9446         CTL_PM=9899,            /* frv power management */
9447 @@ -103,6 +104,7 @@ enum
9448  
9449         KERN_PANIC=15,          /* int: panic timeout */
9450         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
9451 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
9452  
9453         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
9454         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
9455 diff -NurpP --minimal linux-2.6.32.56/include/linux/sysfs.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/sysfs.h
9456 --- linux-2.6.32.56/include/linux/sysfs.h       2008-12-25 00:26:37.000000000 +0100
9457 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/sysfs.h       2011-06-10 13:03:02.000000000 +0200
9458 @@ -17,6 +17,8 @@
9459  #include <linux/list.h>
9460  #include <asm/atomic.h>
9461  
9462 +#define SYSFS_SUPER_MAGIC      0x62656572
9463 +
9464  struct kobject;
9465  struct module;
9466  
9467 diff -NurpP --minimal linux-2.6.32.56/include/linux/time.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/time.h
9468 --- linux-2.6.32.56/include/linux/time.h        2012-02-09 10:22:32.000000000 +0100
9469 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/time.h        2011-06-10 13:03:02.000000000 +0200
9470 @@ -238,6 +238,9 @@ static __always_inline void timespec_add
9471         a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
9472         a->tv_nsec = ns;
9473  }
9474 +
9475 +#include <linux/vs_time.h>
9476 +
9477  #endif /* __KERNEL__ */
9478  
9479  #define NFDBITS                        __NFDBITS
9480 diff -NurpP --minimal linux-2.6.32.56/include/linux/types.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/types.h
9481 --- linux-2.6.32.56/include/linux/types.h       2009-09-10 15:26:26.000000000 +0200
9482 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/types.h       2011-06-10 13:03:02.000000000 +0200
9483 @@ -37,6 +37,9 @@ typedef __kernel_uid32_t      uid_t;
9484  typedef __kernel_gid32_t       gid_t;
9485  typedef __kernel_uid16_t        uid16_t;
9486  typedef __kernel_gid16_t        gid16_t;
9487 +typedef unsigned int           xid_t;
9488 +typedef unsigned int           nid_t;
9489 +typedef unsigned int           tag_t;
9490  
9491  typedef unsigned long          uintptr_t;
9492  
9493 diff -NurpP --minimal linux-2.6.32.56/include/linux/vroot.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vroot.h
9494 --- linux-2.6.32.56/include/linux/vroot.h       1970-01-01 01:00:00.000000000 +0100
9495 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vroot.h       2011-06-10 13:03:02.000000000 +0200
9496 @@ -0,0 +1,51 @@
9497 +
9498 +/*
9499 + * include/linux/vroot.h
9500 + *
9501 + * written by Herbert Pötzl, 9/11/2002
9502 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
9503 + *
9504 + * Copyright (C) 2002-2007 by Herbert Pötzl.
9505 + * Redistribution of this file is permitted under the
9506 + * GNU General Public License.
9507 + */
9508 +
9509 +#ifndef _LINUX_VROOT_H
9510 +#define _LINUX_VROOT_H
9511 +
9512 +
9513 +#ifdef __KERNEL__
9514 +
9515 +/* Possible states of device */
9516 +enum {
9517 +       Vr_unbound,
9518 +       Vr_bound,
9519 +};
9520 +
9521 +struct vroot_device {
9522 +       int             vr_number;
9523 +       int             vr_refcnt;
9524 +
9525 +       struct semaphore        vr_ctl_mutex;
9526 +       struct block_device    *vr_device;
9527 +       int                     vr_state;
9528 +};
9529 +
9530 +
9531 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
9532 +
9533 +extern int register_vroot_grb(vroot_grb_func *);
9534 +extern int unregister_vroot_grb(vroot_grb_func *);
9535 +
9536 +#endif /* __KERNEL__ */
9537 +
9538 +#define MAX_VROOT_DEFAULT      8
9539 +
9540 +/*
9541 + * IOCTL commands --- we will commandeer 0x56 ('V')
9542 + */
9543 +
9544 +#define VROOT_SET_DEV          0x5600
9545 +#define VROOT_CLR_DEV          0x5601
9546 +
9547 +#endif /* _LINUX_VROOT_H */
9548 diff -NurpP --minimal linux-2.6.32.56/include/linux/vs_base.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vs_base.h
9549 --- linux-2.6.32.56/include/linux/vs_base.h     1970-01-01 01:00:00.000000000 +0100
9550 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vs_base.h     2011-06-10 13:03:02.000000000 +0200
9551 @@ -0,0 +1,10 @@
9552 +#ifndef _VS_BASE_H
9553 +#define _VS_BASE_H
9554 +
9555 +#include "vserver/base.h"
9556 +#include "vserver/check.h"
9557 +#include "vserver/debug.h"
9558 +
9559 +#else
9560 +#warning duplicate inclusion
9561 +#endif
9562 diff -NurpP --minimal linux-2.6.32.56/include/linux/vs_context.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vs_context.h
9563 --- linux-2.6.32.56/include/linux/vs_context.h  1970-01-01 01:00:00.000000000 +0100
9564 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vs_context.h  2011-06-10 13:03:02.000000000 +0200
9565 @@ -0,0 +1,242 @@
9566 +#ifndef _VS_CONTEXT_H
9567 +#define _VS_CONTEXT_H
9568 +
9569 +#include "vserver/base.h"
9570 +#include "vserver/check.h"
9571 +#include "vserver/context.h"
9572 +#include "vserver/history.h"
9573 +#include "vserver/debug.h"
9574 +
9575 +#include <linux/sched.h>
9576 +
9577 +
9578 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
9579 +
9580 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
9581 +       const char *_file, int _line, void *_here)
9582 +{
9583 +       if (!vxi)
9584 +               return NULL;
9585 +
9586 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
9587 +               vxi, vxi ? vxi->vx_id : 0,
9588 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9589 +               _file, _line);
9590 +       __vxh_get_vx_info(vxi, _here);
9591 +
9592 +       atomic_inc(&vxi->vx_usecnt);
9593 +       return vxi;
9594 +}
9595 +
9596 +
9597 +extern void free_vx_info(struct vx_info *);
9598 +
9599 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
9600 +
9601 +static inline void __put_vx_info(struct vx_info *vxi,
9602 +       const char *_file, int _line, void *_here)
9603 +{
9604 +       if (!vxi)
9605 +               return;
9606 +
9607 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
9608 +               vxi, vxi ? vxi->vx_id : 0,
9609 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9610 +               _file, _line);
9611 +       __vxh_put_vx_info(vxi, _here);
9612 +
9613 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
9614 +               free_vx_info(vxi);
9615 +}
9616 +
9617 +
9618 +#define init_vx_info(p, i) \
9619 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9620 +
9621 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9622 +       const char *_file, int _line, void *_here)
9623 +{
9624 +       if (vxi) {
9625 +               vxlprintk(VXD_CBIT(xid, 3),
9626 +                       "init_vx_info(%p[#%d.%d])",
9627 +                       vxi, vxi ? vxi->vx_id : 0,
9628 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9629 +                       _file, _line);
9630 +               __vxh_init_vx_info(vxi, vxp, _here);
9631 +
9632 +               atomic_inc(&vxi->vx_usecnt);
9633 +       }
9634 +       *vxp = vxi;
9635 +}
9636 +
9637 +
9638 +#define set_vx_info(p, i) \
9639 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9640 +
9641 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9642 +       const char *_file, int _line, void *_here)
9643 +{
9644 +       struct vx_info *vxo;
9645 +
9646 +       if (!vxi)
9647 +               return;
9648 +
9649 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
9650 +               vxi, vxi ? vxi->vx_id : 0,
9651 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9652 +               _file, _line);
9653 +       __vxh_set_vx_info(vxi, vxp, _here);
9654 +
9655 +       atomic_inc(&vxi->vx_usecnt);
9656 +       vxo = xchg(vxp, vxi);
9657 +       BUG_ON(vxo);
9658 +}
9659 +
9660 +
9661 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
9662 +
9663 +static inline void __clr_vx_info(struct vx_info **vxp,
9664 +       const char *_file, int _line, void *_here)
9665 +{
9666 +       struct vx_info *vxo;
9667 +
9668 +       vxo = xchg(vxp, NULL);
9669 +       if (!vxo)
9670 +               return;
9671 +
9672 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
9673 +               vxo, vxo ? vxo->vx_id : 0,
9674 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
9675 +               _file, _line);
9676 +       __vxh_clr_vx_info(vxo, vxp, _here);
9677 +
9678 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
9679 +               free_vx_info(vxo);
9680 +}
9681 +
9682 +
9683 +#define claim_vx_info(v, p) \
9684 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9685 +
9686 +static inline void __claim_vx_info(struct vx_info *vxi,
9687 +       struct task_struct *task,
9688 +       const char *_file, int _line, void *_here)
9689 +{
9690 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
9691 +               vxi, vxi ? vxi->vx_id : 0,
9692 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9693 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9694 +               task, _file, _line);
9695 +       __vxh_claim_vx_info(vxi, task, _here);
9696 +
9697 +       atomic_inc(&vxi->vx_tasks);
9698 +}
9699 +
9700 +
9701 +extern void unhash_vx_info(struct vx_info *);
9702 +
9703 +#define release_vx_info(v, p) \
9704 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9705 +
9706 +static inline void __release_vx_info(struct vx_info *vxi,
9707 +       struct task_struct *task,
9708 +       const char *_file, int _line, void *_here)
9709 +{
9710 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
9711 +               vxi, vxi ? vxi->vx_id : 0,
9712 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9713 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9714 +               task, _file, _line);
9715 +       __vxh_release_vx_info(vxi, task, _here);
9716 +
9717 +       might_sleep();
9718 +
9719 +       if (atomic_dec_and_test(&vxi->vx_tasks))
9720 +               unhash_vx_info(vxi);
9721 +}
9722 +
9723 +
9724 +#define task_get_vx_info(p) \
9725 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
9726 +
9727 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
9728 +       const char *_file, int _line, void *_here)
9729 +{
9730 +       struct vx_info *vxi;
9731 +
9732 +       task_lock(p);
9733 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
9734 +               p, _file, _line);
9735 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
9736 +       task_unlock(p);
9737 +       return vxi;
9738 +}
9739 +
9740 +
9741 +static inline void __wakeup_vx_info(struct vx_info *vxi)
9742 +{
9743 +       if (waitqueue_active(&vxi->vx_wait))
9744 +               wake_up_interruptible(&vxi->vx_wait);
9745 +}
9746 +
9747 +
9748 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
9749 +
9750 +static inline void __enter_vx_info(struct vx_info *vxi,
9751 +       struct vx_info_save *vxis, const char *_file, int _line)
9752 +{
9753 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
9754 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
9755 +               current->xid, current->vx_info, _file, _line);
9756 +       vxis->vxi = xchg(&current->vx_info, vxi);
9757 +       vxis->xid = current->xid;
9758 +       current->xid = vxi ? vxi->vx_id : 0;
9759 +}
9760 +
9761 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
9762 +
9763 +static inline void __leave_vx_info(struct vx_info_save *vxis,
9764 +       const char *_file, int _line)
9765 +{
9766 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
9767 +               vxis, vxis->xid, vxis->vxi, current,
9768 +               current->xid, current->vx_info, _file, _line);
9769 +       (void)xchg(&current->vx_info, vxis->vxi);
9770 +       current->xid = vxis->xid;
9771 +}
9772 +
9773 +
9774 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
9775 +{
9776 +       vxis->vxi = xchg(&current->vx_info, NULL);
9777 +       vxis->xid = xchg(&current->xid, (xid_t)0);
9778 +}
9779 +
9780 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
9781 +{
9782 +       (void)xchg(&current->xid, vxis->xid);
9783 +       (void)xchg(&current->vx_info, vxis->vxi);
9784 +}
9785 +
9786 +#define task_is_init(p) \
9787 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
9788 +
9789 +static inline int __task_is_init(struct task_struct *p,
9790 +       const char *_file, int _line, void *_here)
9791 +{
9792 +       int is_init = is_global_init(p);
9793 +
9794 +       task_lock(p);
9795 +       if (p->vx_info)
9796 +               is_init = p->vx_info->vx_initpid == p->pid;
9797 +       task_unlock(p);
9798 +       return is_init;
9799 +}
9800 +
9801 +extern void exit_vx_info(struct task_struct *, int);
9802 +extern void exit_vx_info_early(struct task_struct *, int);
9803 +
9804 +
9805 +#else
9806 +#warning duplicate inclusion
9807 +#endif
9808 diff -NurpP --minimal linux-2.6.32.56/include/linux/vs_cowbl.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vs_cowbl.h
9809 --- linux-2.6.32.56/include/linux/vs_cowbl.h    1970-01-01 01:00:00.000000000 +0100
9810 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vs_cowbl.h    2011-06-10 13:03:02.000000000 +0200
9811 @@ -0,0 +1,47 @@
9812 +#ifndef _VS_COWBL_H
9813 +#define _VS_COWBL_H
9814 +
9815 +#include <linux/fs.h>
9816 +#include <linux/dcache.h>
9817 +#include <linux/namei.h>
9818 +
9819 +extern struct dentry *cow_break_link(const char *pathname);
9820 +
9821 +static inline int cow_check_and_break(struct path *path)
9822 +{
9823 +       struct inode *inode = path->dentry->d_inode;
9824 +       int error = 0;
9825 +
9826 +       /* do we need this check? */
9827 +       if (IS_RDONLY(inode))
9828 +               return -EROFS;
9829 +
9830 +       if (IS_COW(inode)) {
9831 +               if (IS_COW_LINK(inode)) {
9832 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
9833 +                       char *pp, *buf;
9834 +
9835 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
9836 +                       if (!buf) {
9837 +                               return -ENOMEM;
9838 +                       }
9839 +                       pp = d_path(path, buf, PATH_MAX);
9840 +                       new_dentry = cow_break_link(pp);
9841 +                       kfree(buf);
9842 +                       if (!IS_ERR(new_dentry)) {
9843 +                               path->dentry = new_dentry;
9844 +                               dput(old_dentry);
9845 +                       } else
9846 +                               error = PTR_ERR(new_dentry);
9847 +               } else {
9848 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
9849 +                       inode->i_ctime = CURRENT_TIME;
9850 +                       mark_inode_dirty(inode);
9851 +               }
9852 +       }
9853 +       return error;
9854 +}
9855 +
9856 +#else
9857 +#warning duplicate inclusion
9858 +#endif
9859 diff -NurpP --minimal linux-2.6.32.56/include/linux/vs_cvirt.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vs_cvirt.h
9860 --- linux-2.6.32.56/include/linux/vs_cvirt.h    1970-01-01 01:00:00.000000000 +0100
9861 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vs_cvirt.h    2011-06-10 13:03:02.000000000 +0200
9862 @@ -0,0 +1,50 @@
9863 +#ifndef _VS_CVIRT_H
9864 +#define _VS_CVIRT_H
9865 +
9866 +#include "vserver/cvirt.h"
9867 +#include "vserver/context.h"
9868 +#include "vserver/base.h"
9869 +#include "vserver/check.h"
9870 +#include "vserver/debug.h"
9871 +
9872 +
9873 +static inline void vx_activate_task(struct task_struct *p)
9874 +{
9875 +       struct vx_info *vxi;
9876 +
9877 +       if ((vxi = p->vx_info)) {
9878 +               vx_update_load(vxi);
9879 +               atomic_inc(&vxi->cvirt.nr_running);
9880 +       }
9881 +}
9882 +
9883 +static inline void vx_deactivate_task(struct task_struct *p)
9884 +{
9885 +       struct vx_info *vxi;
9886 +
9887 +       if ((vxi = p->vx_info)) {
9888 +               vx_update_load(vxi);
9889 +               atomic_dec(&vxi->cvirt.nr_running);
9890 +       }
9891 +}
9892 +
9893 +static inline void vx_uninterruptible_inc(struct task_struct *p)
9894 +{
9895 +       struct vx_info *vxi;
9896 +
9897 +       if ((vxi = p->vx_info))
9898 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
9899 +}
9900 +
9901 +static inline void vx_uninterruptible_dec(struct task_struct *p)
9902 +{
9903 +       struct vx_info *vxi;
9904 +
9905 +       if ((vxi = p->vx_info))
9906 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
9907 +}
9908 +
9909 +
9910 +#else
9911 +#warning duplicate inclusion
9912 +#endif
9913 diff -NurpP --minimal linux-2.6.32.56/include/linux/vs_device.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vs_device.h
9914 --- linux-2.6.32.56/include/linux/vs_device.h   1970-01-01 01:00:00.000000000 +0100
9915 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vs_device.h   2011-06-10 13:03:02.000000000 +0200
9916 @@ -0,0 +1,45 @@
9917 +#ifndef _VS_DEVICE_H
9918 +#define _VS_DEVICE_H
9919 +
9920 +#include "vserver/base.h"
9921 +#include "vserver/device.h"
9922 +#include "vserver/debug.h"
9923 +
9924 +
9925 +#ifdef CONFIG_VSERVER_DEVICE
9926 +
9927 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
9928 +
9929 +#define vs_device_perm(v, d, m, p) \
9930 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
9931 +
9932 +#else
9933 +
9934 +static inline
9935 +int vs_map_device(struct vx_info *vxi,
9936 +       dev_t device, dev_t *target, umode_t mode)
9937 +{
9938 +       if (target)
9939 +               *target = device;
9940 +       return ~0;
9941 +}
9942 +
9943 +#define vs_device_perm(v, d, m, p) ((p) == (p))
9944 +
9945 +#endif
9946 +
9947 +
9948 +#define vs_map_chrdev(d, t, p) \
9949 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
9950 +#define vs_map_blkdev(d, t, p) \
9951 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
9952 +
9953 +#define vs_chrdev_perm(d, p) \
9954 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
9955 +#define vs_blkdev_perm(d, p) \
9956 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
9957 +
9958 +
9959 +#else
9960 +#warning duplicate inclusion
9961 +#endif
9962 diff -NurpP --minimal linux-2.6.32.56/include/linux/vs_dlimit.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vs_dlimit.h
9963 --- linux-2.6.32.56/include/linux/vs_dlimit.h   1970-01-01 01:00:00.000000000 +0100
9964 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vs_dlimit.h   2011-06-10 13:03:02.000000000 +0200
9965 @@ -0,0 +1,215 @@
9966 +#ifndef _VS_DLIMIT_H
9967 +#define _VS_DLIMIT_H
9968 +
9969 +#include <linux/fs.h>
9970 +
9971 +#include "vserver/dlimit.h"
9972 +#include "vserver/base.h"
9973 +#include "vserver/debug.h"
9974 +
9975 +
9976 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
9977 +
9978 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
9979 +       const char *_file, int _line)
9980 +{
9981 +       if (!dli)
9982 +               return NULL;
9983 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
9984 +               dli, dli ? dli->dl_tag : 0,
9985 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9986 +               _file, _line);
9987 +       atomic_inc(&dli->dl_usecnt);
9988 +       return dli;
9989 +}
9990 +
9991 +
9992 +#define free_dl_info(i) \
9993 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
9994 +
9995 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
9996 +
9997 +static inline void __put_dl_info(struct dl_info *dli,
9998 +       const char *_file, int _line)
9999 +{
10000 +       if (!dli)
10001 +               return;
10002 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
10003 +               dli, dli ? dli->dl_tag : 0,
10004 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
10005 +               _file, _line);
10006 +       if (atomic_dec_and_test(&dli->dl_usecnt))
10007 +               free_dl_info(dli);
10008 +}
10009 +
10010 +
10011 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
10012 +
10013 +static inline int __dl_alloc_space(struct super_block *sb,
10014 +       tag_t tag, dlsize_t nr, const char *file, int line)
10015 +{
10016 +       struct dl_info *dli = NULL;
10017 +       int ret = 0;
10018 +
10019 +       if (nr == 0)
10020 +               goto out;
10021 +       dli = locate_dl_info(sb, tag);
10022 +       if (!dli)
10023 +               goto out;
10024 +
10025 +       spin_lock(&dli->dl_lock);
10026 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
10027 +       if (!ret)
10028 +               dli->dl_space_used += nr;
10029 +       spin_unlock(&dli->dl_lock);
10030 +       put_dl_info(dli);
10031 +out:
10032 +       vxlprintk(VXD_CBIT(dlim, 1),
10033 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
10034 +               sb, tag, __dlimit_char(dli), (long long)nr,
10035 +               ret, file, line);
10036 +       return ret;
10037 +}
10038 +
10039 +static inline void __dl_free_space(struct super_block *sb,
10040 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
10041 +{
10042 +       struct dl_info *dli = NULL;
10043 +
10044 +       if (nr == 0)
10045 +               goto out;
10046 +       dli = locate_dl_info(sb, tag);
10047 +       if (!dli)
10048 +               goto out;
10049 +
10050 +       spin_lock(&dli->dl_lock);
10051 +       if (dli->dl_space_used > nr)
10052 +               dli->dl_space_used -= nr;
10053 +       else
10054 +               dli->dl_space_used = 0;
10055 +       spin_unlock(&dli->dl_lock);
10056 +       put_dl_info(dli);
10057 +out:
10058 +       vxlprintk(VXD_CBIT(dlim, 1),
10059 +               "FREE  (%p,#%d)%c %lld bytes",
10060 +               sb, tag, __dlimit_char(dli), (long long)nr,
10061 +               _file, _line);
10062 +}
10063 +
10064 +static inline int __dl_alloc_inode(struct super_block *sb,
10065 +       tag_t tag, const char *_file, int _line)
10066 +{
10067 +       struct dl_info *dli;
10068 +       int ret = 0;
10069 +
10070 +       dli = locate_dl_info(sb, tag);
10071 +       if (!dli)
10072 +               goto out;
10073 +
10074 +       spin_lock(&dli->dl_lock);
10075 +       dli->dl_inodes_used++;
10076 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
10077 +       spin_unlock(&dli->dl_lock);
10078 +       put_dl_info(dli);
10079 +out:
10080 +       vxlprintk(VXD_CBIT(dlim, 0),
10081 +               "ALLOC (%p,#%d)%c inode (%d)",
10082 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
10083 +       return ret;
10084 +}
10085 +
10086 +static inline void __dl_free_inode(struct super_block *sb,
10087 +       tag_t tag, const char *_file, int _line)
10088 +{
10089 +       struct dl_info *dli;
10090 +
10091 +       dli = locate_dl_info(sb, tag);
10092 +       if (!dli)
10093 +               goto out;
10094 +
10095 +       spin_lock(&dli->dl_lock);
10096 +       if (dli->dl_inodes_used > 1)
10097 +               dli->dl_inodes_used--;
10098 +       else
10099 +               dli->dl_inodes_used = 0;
10100 +       spin_unlock(&dli->dl_lock);
10101 +       put_dl_info(dli);
10102 +out:
10103 +       vxlprintk(VXD_CBIT(dlim, 0),
10104 +               "FREE  (%p,#%d)%c inode",
10105 +               sb, tag, __dlimit_char(dli), _file, _line);
10106 +}
10107 +
10108 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
10109 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
10110 +       const char *_file, int _line)
10111 +{
10112 +       struct dl_info *dli;
10113 +       uint64_t broot, bfree;
10114 +
10115 +       dli = locate_dl_info(sb, tag);
10116 +       if (!dli)
10117 +               return;
10118 +
10119 +       spin_lock(&dli->dl_lock);
10120 +       broot = (dli->dl_space_total -
10121 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
10122 +               >> sb->s_blocksize_bits;
10123 +       bfree = (dli->dl_space_total - dli->dl_space_used)
10124 +                       >> sb->s_blocksize_bits;
10125 +       spin_unlock(&dli->dl_lock);
10126 +
10127 +       vxlprintk(VXD_CBIT(dlim, 2),
10128 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
10129 +               (long long)bfree, (long long)broot,
10130 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
10131 +               _file, _line);
10132 +       if (free_blocks) {
10133 +               if (*free_blocks > bfree)
10134 +                       *free_blocks = bfree;
10135 +       }
10136 +       if (root_blocks) {
10137 +               if (*root_blocks > broot)
10138 +                       *root_blocks = broot;
10139 +       }
10140 +       put_dl_info(dli);
10141 +}
10142 +
10143 +#define dl_prealloc_space(in, bytes) \
10144 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10145 +               __FILE__, __LINE__ )
10146 +
10147 +#define dl_alloc_space(in, bytes) \
10148 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10149 +               __FILE__, __LINE__ )
10150 +
10151 +#define dl_reserve_space(in, bytes) \
10152 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10153 +               __FILE__, __LINE__ )
10154 +
10155 +#define dl_claim_space(in, bytes) (0)
10156 +
10157 +#define dl_release_space(in, bytes) \
10158 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10159 +               __FILE__, __LINE__ )
10160 +
10161 +#define dl_free_space(in, bytes) \
10162 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10163 +               __FILE__, __LINE__ )
10164 +
10165 +
10166 +
10167 +#define dl_alloc_inode(in) \
10168 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10169 +
10170 +#define dl_free_inode(in) \
10171 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10172 +
10173 +
10174 +#define dl_adjust_block(sb, tag, fb, rb) \
10175 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
10176 +
10177 +
10178 +#else
10179 +#warning duplicate inclusion
10180 +#endif
10181 diff -NurpP --minimal linux-2.6.32.56/include/linux/vs_inet.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vs_inet.h
10182 --- linux-2.6.32.56/include/linux/vs_inet.h     1970-01-01 01:00:00.000000000 +0100
10183 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vs_inet.h     2011-06-10 13:03:02.000000000 +0200
10184 @@ -0,0 +1,342 @@
10185 +#ifndef _VS_INET_H
10186 +#define _VS_INET_H
10187 +
10188 +#include "vserver/base.h"
10189 +#include "vserver/network.h"
10190 +#include "vserver/debug.h"
10191 +
10192 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
10193 +
10194 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
10195 +                       NIPQUAD((a)->mask), (a)->type
10196 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
10197 +
10198 +
10199 +static inline
10200 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
10201 +{
10202 +       __be32 ip = nxa->ip[0].s_addr;
10203 +       __be32 mask = nxa->mask.s_addr;
10204 +       __be32 bcast = ip | ~mask;
10205 +       int ret = 0;
10206 +
10207 +       switch (nxa->type & tmask) {
10208 +       case NXA_TYPE_MASK:
10209 +               ret = (ip == (addr & mask));
10210 +               break;
10211 +       case NXA_TYPE_ADDR:
10212 +               ret = 3;
10213 +               if (addr == ip)
10214 +                       break;
10215 +               /* fall through to broadcast */
10216 +       case NXA_MOD_BCAST:
10217 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
10218 +               break;
10219 +       case NXA_TYPE_RANGE:
10220 +               ret = ((nxa->ip[0].s_addr <= addr) &&
10221 +                       (nxa->ip[1].s_addr > addr));
10222 +               break;
10223 +       case NXA_TYPE_ANY:
10224 +               ret = 2;
10225 +               break;
10226 +       }
10227 +
10228 +       vxdprintk(VXD_CBIT(net, 0),
10229 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
10230 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
10231 +       return ret;
10232 +}
10233 +
10234 +static inline
10235 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
10236 +{
10237 +       struct nx_addr_v4 *nxa;
10238 +       int ret = 1;
10239 +
10240 +       if (!nxi)
10241 +               goto out;
10242 +
10243 +       ret = 2;
10244 +       /* allow 127.0.0.1 when remapping lback */
10245 +       if ((tmask & NXA_LOOPBACK) &&
10246 +               (addr == IPI_LOOPBACK) &&
10247 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
10248 +               goto out;
10249 +       ret = 3;
10250 +       /* check for lback address */
10251 +       if ((tmask & NXA_MOD_LBACK) &&
10252 +               (nxi->v4_lback.s_addr == addr))
10253 +               goto out;
10254 +       ret = 4;
10255 +       /* check for broadcast address */
10256 +       if ((tmask & NXA_MOD_BCAST) &&
10257 +               (nxi->v4_bcast.s_addr == addr))
10258 +               goto out;
10259 +       ret = 5;
10260 +       /* check for v4 addresses */
10261 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
10262 +               if (v4_addr_match(nxa, addr, tmask))
10263 +                       goto out;
10264 +       ret = 0;
10265 +out:
10266 +       vxdprintk(VXD_CBIT(net, 0),
10267 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
10268 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
10269 +       return ret;
10270 +}
10271 +
10272 +static inline
10273 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
10274 +{
10275 +       /* FIXME: needs full range checks */
10276 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
10277 +}
10278 +
10279 +static inline
10280 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
10281 +{
10282 +       struct nx_addr_v4 *ptr;
10283 +
10284 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
10285 +               if (v4_nx_addr_match(ptr, nxa, mask))
10286 +                       return 1;
10287 +       return 0;
10288 +}
10289 +
10290 +#include <net/inet_sock.h>
10291 +
10292 +/*
10293 + *     Check if a given address matches for a socket
10294 + *
10295 + *     nxi:            the socket's nx_info if any
10296 + *     addr:           to be verified address
10297 + */
10298 +static inline
10299 +int v4_sock_addr_match (
10300 +       struct nx_info *nxi,
10301 +       struct inet_sock *inet,
10302 +       __be32 addr)
10303 +{
10304 +       __be32 saddr = inet->rcv_saddr;
10305 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
10306 +
10307 +       if (addr && (saddr == addr || bcast == addr))
10308 +               return 1;
10309 +       if (!saddr)
10310 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
10311 +       return 0;
10312 +}
10313 +
10314 +
10315 +/* inet related checks and helpers */
10316 +
10317 +
10318 +struct in_ifaddr;
10319 +struct net_device;
10320 +struct sock;
10321 +
10322 +#ifdef CONFIG_INET
10323 +
10324 +#include <linux/netdevice.h>
10325 +#include <linux/inetdevice.h>
10326 +#include <net/inet_sock.h>
10327 +#include <net/inet_timewait_sock.h>
10328 +
10329 +
10330 +int dev_in_nx_info(struct net_device *, struct nx_info *);
10331 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
10332 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
10333 +
10334 +
10335 +/*
10336 + *     check if address is covered by socket
10337 + *
10338 + *     sk:     the socket to check against
10339 + *     addr:   the address in question (must be != 0)
10340 + */
10341 +
10342 +static inline
10343 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
10344 +{
10345 +       struct nx_info *nxi = sk->sk_nx_info;
10346 +       __be32 saddr = inet_rcv_saddr(sk);
10347 +
10348 +       vxdprintk(VXD_CBIT(net, 5),
10349 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
10350 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
10351 +               (sk->sk_socket?sk->sk_socket->flags:0));
10352 +
10353 +       if (saddr) {            /* direct address match */
10354 +               return v4_addr_match(nxa, saddr, -1);
10355 +       } else if (nxi) {       /* match against nx_info */
10356 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
10357 +       } else {                /* unrestricted any socket */
10358 +               return 1;
10359 +       }
10360 +}
10361 +
10362 +
10363 +
10364 +static inline
10365 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
10366 +{
10367 +       vxdprintk(VXD_CBIT(net, 1), "nx_dev_visible(%p[#%u],%p »%s«) %d",
10368 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
10369 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
10370 +
10371 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
10372 +               return 1;
10373 +       if (dev_in_nx_info(dev, nxi))
10374 +               return 1;
10375 +       return 0;
10376 +}
10377 +
10378 +
10379 +static inline
10380 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
10381 +{
10382 +       if (!nxi)
10383 +               return 1;
10384 +       if (!ifa)
10385 +               return 0;
10386 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
10387 +}
10388 +
10389 +static inline
10390 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
10391 +{
10392 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
10393 +               nxi, nxi ? nxi->nx_id : 0, ifa,
10394 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
10395 +
10396 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
10397 +               return 1;
10398 +       if (v4_ifa_in_nx_info(ifa, nxi))
10399 +               return 1;
10400 +       return 0;
10401 +}
10402 +
10403 +
10404 +struct nx_v4_sock_addr {
10405 +       __be32 saddr;   /* Address used for validation */
10406 +       __be32 baddr;   /* Address used for socket bind */
10407 +};
10408 +
10409 +static inline
10410 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
10411 +       struct nx_v4_sock_addr *nsa)
10412 +{
10413 +       struct sock *sk = &inet->sk;
10414 +       struct nx_info *nxi = sk->sk_nx_info;
10415 +       __be32 saddr = addr->sin_addr.s_addr;
10416 +       __be32 baddr = saddr;
10417 +
10418 +       vxdprintk(VXD_CBIT(net, 3),
10419 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
10420 +               sk, sk->sk_nx_info, sk->sk_socket,
10421 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
10422 +               NIPQUAD(saddr));
10423 +
10424 +       if (nxi) {
10425 +               if (saddr == INADDR_ANY) {
10426 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
10427 +                               baddr = nxi->v4.ip[0].s_addr;
10428 +               } else if (saddr == IPI_LOOPBACK) {
10429 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
10430 +                               baddr = nxi->v4_lback.s_addr;
10431 +               } else {        /* normal address bind */
10432 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
10433 +                               return -EADDRNOTAVAIL;
10434 +               }
10435 +       }
10436 +
10437 +       vxdprintk(VXD_CBIT(net, 3),
10438 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
10439 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
10440 +
10441 +       nsa->saddr = saddr;
10442 +       nsa->baddr = baddr;
10443 +       return 0;
10444 +}
10445 +
10446 +static inline
10447 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
10448 +{
10449 +       inet->saddr = nsa->baddr;
10450 +       inet->rcv_saddr = nsa->baddr;
10451 +}
10452 +
10453 +
10454 +/*
10455 + *      helper to simplify inet_lookup_listener
10456 + *
10457 + *      nxi:   the socket's nx_info if any
10458 + *      addr:  to be verified address
10459 + *      saddr: socket address
10460 + */
10461 +static inline int v4_inet_addr_match (
10462 +       struct nx_info *nxi,
10463 +       __be32 addr,
10464 +       __be32 saddr)
10465 +{
10466 +       if (addr && (saddr == addr))
10467 +               return 1;
10468 +       if (!saddr)
10469 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
10470 +       return 0;
10471 +}
10472 +
10473 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
10474 +{
10475 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
10476 +               (addr == nxi->v4_lback.s_addr))
10477 +               return IPI_LOOPBACK;
10478 +       return addr;
10479 +}
10480 +
10481 +static inline
10482 +int nx_info_has_v4(struct nx_info *nxi)
10483 +{
10484 +       if (!nxi)
10485 +               return 1;
10486 +       if (NX_IPV4(nxi))
10487 +               return 1;
10488 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
10489 +               return 1;
10490 +       return 0;
10491 +}
10492 +
10493 +#else /* CONFIG_INET */
10494 +
10495 +static inline
10496 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
10497 +{
10498 +       return 1;
10499 +}
10500 +
10501 +static inline
10502 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
10503 +{
10504 +       return 1;
10505 +}
10506 +
10507 +static inline
10508 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
10509 +{
10510 +       return 1;
10511 +}
10512 +
10513 +static inline
10514 +int nx_info_has_v4(struct nx_info *nxi)
10515 +{
10516 +       return 0;
10517 +}
10518 +
10519 +#endif /* CONFIG_INET */
10520 +
10521 +#define current_nx_info_has_v4() \
10522 +       nx_info_has_v4(current_nx_info())
10523 +
10524 +#else
10525 +// #warning duplicate inclusion
10526 +#endif
10527 diff -NurpP --minimal linux-2.6.32.56/include/linux/vs_inet6.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vs_inet6.h
10528 --- linux-2.6.32.56/include/linux/vs_inet6.h    1970-01-01 01:00:00.000000000 +0100
10529 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vs_inet6.h    2011-06-10 13:03:02.000000000 +0200
10530 @@ -0,0 +1,246 @@
10531 +#ifndef _VS_INET6_H
10532 +#define _VS_INET6_H
10533 +
10534 +#include "vserver/base.h"
10535 +#include "vserver/network.h"
10536 +#include "vserver/debug.h"
10537 +
10538 +#include <net/ipv6.h>
10539 +
10540 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
10541 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
10542 +
10543 +
10544 +#ifdef CONFIG_IPV6
10545 +
10546 +static inline
10547 +int v6_addr_match(struct nx_addr_v6 *nxa,
10548 +       const struct in6_addr *addr, uint16_t mask)
10549 +{
10550 +       int ret = 0;
10551 +
10552 +       switch (nxa->type & mask) {
10553 +       case NXA_TYPE_MASK:
10554 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
10555 +               break;
10556 +       case NXA_TYPE_ADDR:
10557 +               ret = ipv6_addr_equal(&nxa->ip, addr);
10558 +               break;
10559 +       case NXA_TYPE_ANY:
10560 +               ret = 1;
10561 +               break;
10562 +       }
10563 +       vxdprintk(VXD_CBIT(net, 0),
10564 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
10565 +               nxa, NXAV6(nxa), addr, mask, ret);
10566 +       return ret;
10567 +}
10568 +
10569 +static inline
10570 +int v6_addr_in_nx_info(struct nx_info *nxi,
10571 +       const struct in6_addr *addr, uint16_t mask)
10572 +{
10573 +       struct nx_addr_v6 *nxa;
10574 +       int ret = 1;
10575 +
10576 +       if (!nxi)
10577 +               goto out;
10578 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
10579 +               if (v6_addr_match(nxa, addr, mask))
10580 +                       goto out;
10581 +       ret = 0;
10582 +out:
10583 +       vxdprintk(VXD_CBIT(net, 0),
10584 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
10585 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
10586 +       return ret;
10587 +}
10588 +
10589 +static inline
10590 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
10591 +{
10592 +       /* FIXME: needs full range checks */
10593 +       return v6_addr_match(nxa, &addr->ip, mask);
10594 +}
10595 +
10596 +static inline
10597 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
10598 +{
10599 +       struct nx_addr_v6 *ptr;
10600 +
10601 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
10602 +               if (v6_nx_addr_match(ptr, nxa, mask))
10603 +                       return 1;
10604 +       return 0;
10605 +}
10606 +
10607 +
10608 +/*
10609 + *     Check if a given address matches for a socket
10610 + *
10611 + *     nxi:            the socket's nx_info if any
10612 + *     addr:           to be verified address
10613 + */
10614 +static inline
10615 +int v6_sock_addr_match (
10616 +       struct nx_info *nxi,
10617 +       struct inet_sock *inet,
10618 +       struct in6_addr *addr)
10619 +{
10620 +       struct sock *sk = &inet->sk;
10621 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
10622 +
10623 +       if (!ipv6_addr_any(addr) &&
10624 +               ipv6_addr_equal(saddr, addr))
10625 +               return 1;
10626 +       if (ipv6_addr_any(saddr))
10627 +               return v6_addr_in_nx_info(nxi, addr, -1);
10628 +       return 0;
10629 +}
10630 +
10631 +/*
10632 + *     check if address is covered by socket
10633 + *
10634 + *     sk:     the socket to check against
10635 + *     addr:   the address in question (must be != 0)
10636 + */
10637 +
10638 +static inline
10639 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
10640 +{
10641 +       struct nx_info *nxi = sk->sk_nx_info;
10642 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
10643 +
10644 +       vxdprintk(VXD_CBIT(net, 5),
10645 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
10646 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
10647 +               (sk->sk_socket?sk->sk_socket->flags:0));
10648 +
10649 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
10650 +               return v6_addr_match(nxa, saddr, -1);
10651 +       } else if (nxi) {               /* match against nx_info */
10652 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
10653 +       } else {                        /* unrestricted any socket */
10654 +               return 1;
10655 +       }
10656 +}
10657 +
10658 +
10659 +/* inet related checks and helpers */
10660 +
10661 +
10662 +struct in_ifaddr;
10663 +struct net_device;
10664 +struct sock;
10665 +
10666 +
10667 +#include <linux/netdevice.h>
10668 +#include <linux/inetdevice.h>
10669 +#include <net/inet_timewait_sock.h>
10670 +
10671 +
10672 +int dev_in_nx_info(struct net_device *, struct nx_info *);
10673 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
10674 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
10675 +
10676 +
10677 +
10678 +static inline
10679 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
10680 +{
10681 +       if (!nxi)
10682 +               return 1;
10683 +       if (!ifa)
10684 +               return 0;
10685 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
10686 +}
10687 +
10688 +static inline
10689 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
10690 +{
10691 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
10692 +               nxi, nxi ? nxi->nx_id : 0, ifa,
10693 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
10694 +
10695 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
10696 +               return 1;
10697 +       if (v6_ifa_in_nx_info(ifa, nxi))
10698 +               return 1;
10699 +       return 0;
10700 +}
10701 +
10702 +
10703 +struct nx_v6_sock_addr {
10704 +       struct in6_addr saddr;  /* Address used for validation */
10705 +       struct in6_addr baddr;  /* Address used for socket bind */
10706 +};
10707 +
10708 +static inline
10709 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
10710 +       struct nx_v6_sock_addr *nsa)
10711 +{
10712 +       // struct sock *sk = &inet->sk;
10713 +       // struct nx_info *nxi = sk->sk_nx_info;
10714 +       struct in6_addr saddr = addr->sin6_addr;
10715 +       struct in6_addr baddr = saddr;
10716 +
10717 +       nsa->saddr = saddr;
10718 +       nsa->baddr = baddr;
10719 +       return 0;
10720 +}
10721 +
10722 +static inline
10723 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
10724 +{
10725 +       // struct sock *sk = &inet->sk;
10726 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
10727 +
10728 +       // *saddr = nsa->baddr;
10729 +       // inet->saddr = nsa->baddr;
10730 +}
10731 +
10732 +static inline
10733 +int nx_info_has_v6(struct nx_info *nxi)
10734 +{
10735 +       if (!nxi)
10736 +               return 1;
10737 +       if (NX_IPV6(nxi))
10738 +               return 1;
10739 +       return 0;
10740 +}
10741 +
10742 +#else /* CONFIG_IPV6 */
10743 +
10744 +static inline
10745 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
10746 +{
10747 +       return 1;
10748 +}
10749 +
10750 +
10751 +static inline
10752 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
10753 +{
10754 +       return 1;
10755 +}
10756 +
10757 +static inline
10758 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
10759 +{
10760 +       return 1;
10761 +}
10762 +
10763 +static inline
10764 +int nx_info_has_v6(struct nx_info *nxi)
10765 +{
10766 +       return 0;
10767 +}
10768 +
10769 +#endif /* CONFIG_IPV6 */
10770 +
10771 +#define current_nx_info_has_v6() \
10772 +       nx_info_has_v6(current_nx_info())
10773 +
10774 +#else
10775 +#warning duplicate inclusion
10776 +#endif
10777 diff -NurpP --minimal linux-2.6.32.56/include/linux/vs_limit.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vs_limit.h
10778 --- linux-2.6.32.56/include/linux/vs_limit.h    1970-01-01 01:00:00.000000000 +0100
10779 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vs_limit.h    2011-06-10 13:03:02.000000000 +0200
10780 @@ -0,0 +1,140 @@
10781 +#ifndef _VS_LIMIT_H
10782 +#define _VS_LIMIT_H
10783 +
10784 +#include "vserver/limit.h"
10785 +#include "vserver/base.h"
10786 +#include "vserver/context.h"
10787 +#include "vserver/debug.h"
10788 +#include "vserver/context.h"
10789 +#include "vserver/limit_int.h"
10790 +
10791 +
10792 +#define vx_acc_cres(v, d, p, r) \
10793 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
10794 +
10795 +#define vx_acc_cres_cond(x, d, p, r) \
10796 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
10797 +       r, d, p, __FILE__, __LINE__)
10798 +
10799 +
10800 +#define vx_add_cres(v, a, p, r) \
10801 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
10802 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
10803 +
10804 +#define vx_add_cres_cond(x, a, p, r) \
10805 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
10806 +       r, a, p, __FILE__, __LINE__)
10807 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
10808 +
10809 +
10810 +/* process and file limits */
10811 +
10812 +#define vx_nproc_inc(p) \
10813 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
10814 +
10815 +#define vx_nproc_dec(p) \
10816 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
10817 +
10818 +#define vx_files_inc(f) \
10819 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
10820 +
10821 +#define vx_files_dec(f) \
10822 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
10823 +
10824 +#define vx_locks_inc(l) \
10825 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
10826 +
10827 +#define vx_locks_dec(l) \
10828 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
10829 +
10830 +#define vx_openfd_inc(f) \
10831 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
10832 +
10833 +#define vx_openfd_dec(f) \
10834 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
10835 +
10836 +
10837 +#define vx_cres_avail(v, n, r) \
10838 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
10839 +
10840 +
10841 +#define vx_nproc_avail(n) \
10842 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
10843 +
10844 +#define vx_files_avail(n) \
10845 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
10846 +
10847 +#define vx_locks_avail(n) \
10848 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
10849 +
10850 +#define vx_openfd_avail(n) \
10851 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
10852 +
10853 +
10854 +/* dentry limits */
10855 +
10856 +#define vx_dentry_inc(d) do {                                          \
10857 +       if (atomic_read(&d->d_count) == 1)                              \
10858 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
10859 +       } while (0)
10860 +
10861 +#define vx_dentry_dec(d) do {                                          \
10862 +       if (atomic_read(&d->d_count) == 0)                              \
10863 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
10864 +       } while (0)
10865 +
10866 +#define vx_dentry_avail(n) \
10867 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
10868 +
10869 +
10870 +/* socket limits */
10871 +
10872 +#define vx_sock_inc(s) \
10873 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
10874 +
10875 +#define vx_sock_dec(s) \
10876 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
10877 +
10878 +#define vx_sock_avail(n) \
10879 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
10880 +
10881 +
10882 +/* ipc resource limits */
10883 +
10884 +#define vx_ipcmsg_add(v, u, a) \
10885 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
10886 +
10887 +#define vx_ipcmsg_sub(v, u, a) \
10888 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
10889 +
10890 +#define vx_ipcmsg_avail(v, a) \
10891 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
10892 +
10893 +
10894 +#define vx_ipcshm_add(v, k, a) \
10895 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
10896 +
10897 +#define vx_ipcshm_sub(v, k, a) \
10898 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
10899 +
10900 +#define vx_ipcshm_avail(v, a) \
10901 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
10902 +
10903 +
10904 +#define vx_semary_inc(a) \
10905 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
10906 +
10907 +#define vx_semary_dec(a) \
10908 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
10909 +
10910 +
10911 +#define vx_nsems_add(a,n) \
10912 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
10913 +
10914 +#define vx_nsems_sub(a,n) \
10915 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
10916 +
10917 +
10918 +#else
10919 +#warning duplicate inclusion
10920 +#endif
10921 diff -NurpP --minimal linux-2.6.32.56/include/linux/vs_memory.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vs_memory.h
10922 --- linux-2.6.32.56/include/linux/vs_memory.h   1970-01-01 01:00:00.000000000 +0100
10923 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vs_memory.h   2011-06-10 13:03:02.000000000 +0200
10924 @@ -0,0 +1,159 @@
10925 +#ifndef _VS_MEMORY_H
10926 +#define _VS_MEMORY_H
10927 +
10928 +#include "vserver/limit.h"
10929 +#include "vserver/base.h"
10930 +#include "vserver/context.h"
10931 +#include "vserver/debug.h"
10932 +#include "vserver/context.h"
10933 +#include "vserver/limit_int.h"
10934 +
10935 +
10936 +#define __acc_add_long(a, v)   (*(v) += (a))
10937 +#define __acc_inc_long(v)      (++*(v))
10938 +#define __acc_dec_long(v)      (--*(v))
10939 +
10940 +#if    NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS
10941 +#define __acc_add_atomic(a, v) atomic_long_add(a, v)
10942 +#define __acc_inc_atomic(v)    atomic_long_inc(v)
10943 +#define __acc_dec_atomic(v)    atomic_long_dec(v)
10944 +#else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
10945 +#define __acc_add_atomic(a, v) __acc_add_long(a, v)
10946 +#define __acc_inc_atomic(v)    __acc_inc_long(v)
10947 +#define __acc_dec_atomic(v)    __acc_dec_long(v)
10948 +#endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
10949 +
10950 +
10951 +#define vx_acc_page(m, d, v, r) do {                                   \
10952 +       if ((d) > 0)                                                    \
10953 +               __acc_inc_long(&(m)->v);                                \
10954 +       else                                                            \
10955 +               __acc_dec_long(&(m)->v);                                \
10956 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
10957 +} while (0)
10958 +
10959 +#define vx_acc_page_atomic(m, d, v, r) do {                            \
10960 +       if ((d) > 0)                                                    \
10961 +               __acc_inc_atomic(&(m)->v);                              \
10962 +       else                                                            \
10963 +               __acc_dec_atomic(&(m)->v);                              \
10964 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
10965 +} while (0)
10966 +
10967 +
10968 +#define vx_acc_pages(m, p, v, r) do {                                  \
10969 +       unsigned long __p = (p);                                        \
10970 +       __acc_add_long(__p, &(m)->v);                                   \
10971 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
10972 +} while (0)
10973 +
10974 +#define vx_acc_pages_atomic(m, p, v, r) do {                           \
10975 +       unsigned long __p = (p);                                        \
10976 +       __acc_add_atomic(__p, &(m)->v);                                 \
10977 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
10978 +} while (0)
10979 +
10980 +
10981 +
10982 +#define vx_acc_vmpage(m, d) \
10983 +       vx_acc_page(m, d, total_vm,  RLIMIT_AS)
10984 +#define vx_acc_vmlpage(m, d) \
10985 +       vx_acc_page(m, d, locked_vm, RLIMIT_MEMLOCK)
10986 +#define vx_acc_file_rsspage(m, d) \
10987 +       vx_acc_page_atomic(m, d, _file_rss, VLIMIT_MAPPED)
10988 +#define vx_acc_anon_rsspage(m, d) \
10989 +       vx_acc_page_atomic(m, d, _anon_rss, VLIMIT_ANON)
10990 +
10991 +#define vx_acc_vmpages(m, p) \
10992 +       vx_acc_pages(m, p, total_vm,  RLIMIT_AS)
10993 +#define vx_acc_vmlpages(m, p) \
10994 +       vx_acc_pages(m, p, locked_vm, RLIMIT_MEMLOCK)
10995 +#define vx_acc_file_rsspages(m, p) \
10996 +       vx_acc_pages_atomic(m, p, _file_rss, VLIMIT_MAPPED)
10997 +#define vx_acc_anon_rsspages(m, p) \
10998 +       vx_acc_pages_atomic(m, p, _anon_rss, VLIMIT_ANON)
10999 +
11000 +#define vx_pages_add(s, r, p)  __vx_add_cres(s, r, p, 0, __FILE__, __LINE__)
11001 +#define vx_pages_sub(s, r, p)  vx_pages_add(s, r, -(p))
11002 +
11003 +#define vx_vmpages_inc(m)              vx_acc_vmpage(m, 1)
11004 +#define vx_vmpages_dec(m)              vx_acc_vmpage(m, -1)
11005 +#define vx_vmpages_add(m, p)           vx_acc_vmpages(m, p)
11006 +#define vx_vmpages_sub(m, p)           vx_acc_vmpages(m, -(p))
11007 +
11008 +#define vx_vmlocked_inc(m)             vx_acc_vmlpage(m, 1)
11009 +#define vx_vmlocked_dec(m)             vx_acc_vmlpage(m, -1)
11010 +#define vx_vmlocked_add(m, p)          vx_acc_vmlpages(m, p)
11011 +#define vx_vmlocked_sub(m, p)          vx_acc_vmlpages(m, -(p))
11012 +
11013 +#define vx_file_rsspages_inc(m)                vx_acc_file_rsspage(m, 1)
11014 +#define vx_file_rsspages_dec(m)                vx_acc_file_rsspage(m, -1)
11015 +#define vx_file_rsspages_add(m, p)     vx_acc_file_rsspages(m, p)
11016 +#define vx_file_rsspages_sub(m, p)     vx_acc_file_rsspages(m, -(p))
11017 +
11018 +#define vx_anon_rsspages_inc(m)                vx_acc_anon_rsspage(m, 1)
11019 +#define vx_anon_rsspages_dec(m)                vx_acc_anon_rsspage(m, -1)
11020 +#define vx_anon_rsspages_add(m, p)     vx_acc_anon_rsspages(m, p)
11021 +#define vx_anon_rsspages_sub(m, p)     vx_acc_anon_rsspages(m, -(p))
11022 +
11023 +
11024 +#define vx_pages_avail(m, p, r) \
11025 +       __vx_cres_avail((m)->mm_vx_info, r, p, __FILE__, __LINE__)
11026 +
11027 +#define vx_vmpages_avail(m, p) vx_pages_avail(m, p, RLIMIT_AS)
11028 +#define vx_vmlocked_avail(m, p)        vx_pages_avail(m, p, RLIMIT_MEMLOCK)
11029 +#define vx_anon_avail(m, p)    vx_pages_avail(m, p, VLIMIT_ANON)
11030 +#define vx_mapped_avail(m, p)  vx_pages_avail(m, p, VLIMIT_MAPPED)
11031 +
11032 +#define vx_rss_avail(m, p) \
11033 +       __vx_cres_array_avail((m)->mm_vx_info, VLA_RSS, p, __FILE__, __LINE__)
11034 +
11035 +
11036 +enum {
11037 +       VXPT_UNKNOWN = 0,
11038 +       VXPT_ANON,
11039 +       VXPT_NONE,
11040 +       VXPT_FILE,
11041 +       VXPT_SWAP,
11042 +       VXPT_WRITE
11043 +};
11044 +
11045 +#if 0
11046 +#define        vx_page_fault(mm, vma, type, ret)
11047 +#else
11048 +
11049 +static inline
11050 +void __vx_page_fault(struct mm_struct *mm,
11051 +       struct vm_area_struct *vma, int type, int ret)
11052 +{
11053 +       struct vx_info *vxi = mm->mm_vx_info;
11054 +       int what;
11055 +/*
11056 +       static char *page_type[6] =
11057 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
11058 +       static char *page_what[4] =
11059 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
11060 +*/
11061 +
11062 +       if (!vxi)
11063 +               return;
11064 +
11065 +       what = (ret & 0x3);
11066 +
11067 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
11068 +               type, what, ret, page_type[type], page_what[what]);
11069 +*/
11070 +       if (ret & VM_FAULT_WRITE)
11071 +               what |= 0x4;
11072 +       atomic_inc(&vxi->cacct.page[type][what]);
11073 +}
11074 +
11075 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
11076 +#endif
11077 +
11078 +
11079 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
11080 +
11081 +#else
11082 +#warning duplicate inclusion
11083 +#endif
11084 diff -NurpP --minimal linux-2.6.32.56/include/linux/vs_network.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vs_network.h
11085 --- linux-2.6.32.56/include/linux/vs_network.h  1970-01-01 01:00:00.000000000 +0100
11086 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vs_network.h  2011-06-10 13:03:02.000000000 +0200
11087 @@ -0,0 +1,169 @@
11088 +#ifndef _NX_VS_NETWORK_H
11089 +#define _NX_VS_NETWORK_H
11090 +
11091 +#include "vserver/context.h"
11092 +#include "vserver/network.h"
11093 +#include "vserver/base.h"
11094 +#include "vserver/check.h"
11095 +#include "vserver/debug.h"
11096 +
11097 +#include <linux/sched.h>
11098 +
11099 +
11100 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
11101 +
11102 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
11103 +       const char *_file, int _line)
11104 +{
11105 +       if (!nxi)
11106 +               return NULL;
11107 +
11108 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
11109 +               nxi, nxi ? nxi->nx_id : 0,
11110 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
11111 +               _file, _line);
11112 +
11113 +       atomic_inc(&nxi->nx_usecnt);
11114 +       return nxi;
11115 +}
11116 +
11117 +
11118 +extern void free_nx_info(struct nx_info *);
11119 +
11120 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
11121 +
11122 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
11123 +{
11124 +       if (!nxi)
11125 +               return;
11126 +
11127 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
11128 +               nxi, nxi ? nxi->nx_id : 0,
11129 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
11130 +               _file, _line);
11131 +
11132 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
11133 +               free_nx_info(nxi);
11134 +}
11135 +
11136 +
11137 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
11138 +
11139 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
11140 +               const char *_file, int _line)
11141 +{
11142 +       if (nxi) {
11143 +               vxlprintk(VXD_CBIT(nid, 3),
11144 +                       "init_nx_info(%p[#%d.%d])",
11145 +                       nxi, nxi ? nxi->nx_id : 0,
11146 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
11147 +                       _file, _line);
11148 +
11149 +               atomic_inc(&nxi->nx_usecnt);
11150 +       }
11151 +       *nxp = nxi;
11152 +}
11153 +
11154 +
11155 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
11156 +
11157 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
11158 +       const char *_file, int _line)
11159 +{
11160 +       struct nx_info *nxo;
11161 +
11162 +       if (!nxi)
11163 +               return;
11164 +
11165 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
11166 +               nxi, nxi ? nxi->nx_id : 0,
11167 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
11168 +               _file, _line);
11169 +
11170 +       atomic_inc(&nxi->nx_usecnt);
11171 +       nxo = xchg(nxp, nxi);
11172 +       BUG_ON(nxo);
11173 +}
11174 +
11175 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
11176 +
11177 +static inline void __clr_nx_info(struct nx_info **nxp,
11178 +       const char *_file, int _line)
11179 +{
11180 +       struct nx_info *nxo;
11181 +
11182 +       nxo = xchg(nxp, NULL);
11183 +       if (!nxo)
11184 +               return;
11185 +
11186 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
11187 +               nxo, nxo ? nxo->nx_id : 0,
11188 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
11189 +               _file, _line);
11190 +
11191 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
11192 +               free_nx_info(nxo);
11193 +}
11194 +
11195 +
11196 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
11197 +
11198 +static inline void __claim_nx_info(struct nx_info *nxi,
11199 +       struct task_struct *task, const char *_file, int _line)
11200 +{
11201 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
11202 +               nxi, nxi ? nxi->nx_id : 0,
11203 +               nxi?atomic_read(&nxi->nx_usecnt):0,
11204 +               nxi?atomic_read(&nxi->nx_tasks):0,
11205 +               task, _file, _line);
11206 +
11207 +       atomic_inc(&nxi->nx_tasks);
11208 +}
11209 +
11210 +
11211 +extern void unhash_nx_info(struct nx_info *);
11212 +
11213 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
11214 +
11215 +static inline void __release_nx_info(struct nx_info *nxi,
11216 +       struct task_struct *task, const char *_file, int _line)
11217 +{
11218 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
11219 +               nxi, nxi ? nxi->nx_id : 0,
11220 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
11221 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
11222 +               task, _file, _line);
11223 +
11224 +       might_sleep();
11225 +
11226 +       if (atomic_dec_and_test(&nxi->nx_tasks))
11227 +               unhash_nx_info(nxi);
11228 +}
11229 +
11230 +
11231 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
11232 +
11233 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
11234 +       const char *_file, int _line)
11235 +{
11236 +       struct nx_info *nxi;
11237 +
11238 +       task_lock(p);
11239 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
11240 +               p, _file, _line);
11241 +       nxi = __get_nx_info(p->nx_info, _file, _line);
11242 +       task_unlock(p);
11243 +       return nxi;
11244 +}
11245 +
11246 +
11247 +static inline void exit_nx_info(struct task_struct *p)
11248 +{
11249 +       if (p->nx_info)
11250 +               release_nx_info(p->nx_info, p);
11251 +}
11252 +
11253 +
11254 +#else
11255 +#warning duplicate inclusion
11256 +#endif
11257 diff -NurpP --minimal linux-2.6.32.56/include/linux/vs_pid.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vs_pid.h
11258 --- linux-2.6.32.56/include/linux/vs_pid.h      1970-01-01 01:00:00.000000000 +0100
11259 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vs_pid.h      2011-06-10 14:04:27.000000000 +0200
11260 @@ -0,0 +1,50 @@
11261 +#ifndef _VS_PID_H
11262 +#define _VS_PID_H
11263 +
11264 +#include "vserver/base.h"
11265 +#include "vserver/check.h"
11266 +#include "vserver/context.h"
11267 +#include "vserver/debug.h"
11268 +#include "vserver/pid.h"
11269 +#include <linux/pid_namespace.h>
11270 +
11271 +
11272 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
11273 +
11274 +static inline
11275 +int vx_proc_task_visible(struct task_struct *task)
11276 +{
11277 +       if ((task->pid == 1) &&
11278 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
11279 +               /* show a blend through init */
11280 +               goto visible;
11281 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
11282 +               goto visible;
11283 +       return 0;
11284 +visible:
11285 +       return 1;
11286 +}
11287 +
11288 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
11289 +
11290 +
11291 +static inline
11292 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
11293 +{
11294 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
11295 +
11296 +       if (task && !vx_proc_task_visible(task)) {
11297 +               vxdprintk(VXD_CBIT(misc, 6),
11298 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
11299 +                       task, task->xid, task->pid,
11300 +                       current, current->xid, current->pid);
11301 +               put_task_struct(task);
11302 +               task = NULL;
11303 +       }
11304 +       return task;
11305 +}
11306 +
11307 +
11308 +#else
11309 +#warning duplicate inclusion
11310 +#endif
11311 diff -NurpP --minimal linux-2.6.32.56/include/linux/vs_sched.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vs_sched.h
11312 --- linux-2.6.32.56/include/linux/vs_sched.h    1970-01-01 01:00:00.000000000 +0100
11313 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vs_sched.h    2011-06-10 13:03:02.000000000 +0200
11314 @@ -0,0 +1,110 @@
11315 +#ifndef _VS_SCHED_H
11316 +#define _VS_SCHED_H
11317 +
11318 +#include "vserver/base.h"
11319 +#include "vserver/context.h"
11320 +#include "vserver/sched.h"
11321 +
11322 +
11323 +#define VAVAVOOM_RATIO          50
11324 +
11325 +#define MAX_PRIO_BIAS           20
11326 +#define MIN_PRIO_BIAS          -20
11327 +
11328 +
11329 +#ifdef CONFIG_VSERVER_HARDCPU
11330 +
11331 +/*
11332 + * effective_prio - return the priority that is based on the static
11333 + * priority but is modified by bonuses/penalties.
11334 + *
11335 + * We scale the actual sleep average [0 .... MAX_SLEEP_AVG]
11336 + * into a -4 ... 0 ... +4 bonus/penalty range.
11337 + *
11338 + * Additionally, we scale another amount based on the number of
11339 + * CPU tokens currently held by the context, if the process is
11340 + * part of a context (and the appropriate SCHED flag is set).
11341 + * This ranges from -5 ... 0 ... +15, quadratically.
11342 + *
11343 + * So, the total bonus is -9 .. 0 .. +19
11344 + * We use ~50% of the full 0...39 priority range so that:
11345 + *
11346 + * 1) nice +19 interactive tasks do not preempt nice 0 CPU hogs.
11347 + * 2) nice -20 CPU hogs do not get preempted by nice 0 tasks.
11348 + *    unless that context is far exceeding its CPU allocation.
11349 + *
11350 + * Both properties are important to certain workloads.
11351 + */
11352 +static inline
11353 +int vx_effective_vavavoom(struct _vx_sched_pc *sched_pc, int max_prio)
11354 +{
11355 +       int vavavoom, max;
11356 +
11357 +       /* lots of tokens = lots of vavavoom
11358 +        *      no tokens = no vavavoom      */
11359 +       if ((vavavoom = sched_pc->tokens) >= 0) {
11360 +               max = sched_pc->tokens_max;
11361 +               vavavoom = max - vavavoom;
11362 +               max = max * max;
11363 +               vavavoom = max_prio * VAVAVOOM_RATIO / 100
11364 +                       * (vavavoom*vavavoom - (max >> 2)) / max;
11365 +               return vavavoom;
11366 +       }
11367 +       return 0;
11368 +}
11369 +
11370 +
11371 +static inline
11372 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
11373 +{
11374 +       struct vx_info *vxi = p->vx_info;
11375 +       struct _vx_sched_pc *sched_pc;
11376 +
11377 +       if (!vxi)
11378 +               return prio;
11379 +
11380 +       sched_pc = &vx_cpu(vxi, sched_pc);
11381 +       if (vx_info_flags(vxi, VXF_SCHED_PRIO, 0)) {
11382 +               int vavavoom = vx_effective_vavavoom(sched_pc, max_user);
11383 +
11384 +               sched_pc->vavavoom = vavavoom;
11385 +               prio += vavavoom;
11386 +       }
11387 +       prio += sched_pc->prio_bias;
11388 +       return prio;
11389 +}
11390 +
11391 +#else /* !CONFIG_VSERVER_HARDCPU */
11392 +
11393 +static inline
11394 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
11395 +{
11396 +       struct vx_info *vxi = p->vx_info;
11397 +
11398 +       if (vxi)
11399 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
11400 +       return prio;
11401 +}
11402 +
11403 +#endif /* CONFIG_VSERVER_HARDCPU */
11404 +
11405 +
11406 +static inline void vx_account_user(struct vx_info *vxi,
11407 +       cputime_t cputime, int nice)
11408 +{
11409 +       if (!vxi)
11410 +               return;
11411 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
11412 +}
11413 +
11414 +static inline void vx_account_system(struct vx_info *vxi,
11415 +       cputime_t cputime, int idle)
11416 +{
11417 +       if (!vxi)
11418 +               return;
11419 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
11420 +}
11421 +
11422 +#else
11423 +#warning duplicate inclusion
11424 +#endif
11425 diff -NurpP --minimal linux-2.6.32.56/include/linux/vs_socket.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vs_socket.h
11426 --- linux-2.6.32.56/include/linux/vs_socket.h   1970-01-01 01:00:00.000000000 +0100
11427 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vs_socket.h   2011-06-10 13:03:02.000000000 +0200
11428 @@ -0,0 +1,67 @@
11429 +#ifndef _VS_SOCKET_H
11430 +#define _VS_SOCKET_H
11431 +
11432 +#include "vserver/debug.h"
11433 +#include "vserver/base.h"
11434 +#include "vserver/cacct.h"
11435 +#include "vserver/context.h"
11436 +#include "vserver/tag.h"
11437 +
11438 +
11439 +/* socket accounting */
11440 +
11441 +#include <linux/socket.h>
11442 +
11443 +static inline int vx_sock_type(int family)
11444 +{
11445 +       switch (family) {
11446 +       case PF_UNSPEC:
11447 +               return VXA_SOCK_UNSPEC;
11448 +       case PF_UNIX:
11449 +               return VXA_SOCK_UNIX;
11450 +       case PF_INET:
11451 +               return VXA_SOCK_INET;
11452 +       case PF_INET6:
11453 +               return VXA_SOCK_INET6;
11454 +       case PF_PACKET:
11455 +               return VXA_SOCK_PACKET;
11456 +       default:
11457 +               return VXA_SOCK_OTHER;
11458 +       }
11459 +}
11460 +
11461 +#define vx_acc_sock(v, f, p, s) \
11462 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
11463 +
11464 +static inline void __vx_acc_sock(struct vx_info *vxi,
11465 +       int family, int pos, int size, char *file, int line)
11466 +{
11467 +       if (vxi) {
11468 +               int type = vx_sock_type(family);
11469 +
11470 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
11471 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
11472 +       }
11473 +}
11474 +
11475 +#define vx_sock_recv(sk, s) \
11476 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
11477 +#define vx_sock_send(sk, s) \
11478 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
11479 +#define vx_sock_fail(sk, s) \
11480 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
11481 +
11482 +
11483 +#define sock_vx_init(s) do {           \
11484 +       (s)->sk_xid = 0;                \
11485 +       (s)->sk_vx_info = NULL;         \
11486 +       } while (0)
11487 +
11488 +#define sock_nx_init(s) do {           \
11489 +       (s)->sk_nid = 0;                \
11490 +       (s)->sk_nx_info = NULL;         \
11491 +       } while (0)
11492 +
11493 +#else
11494 +#warning duplicate inclusion
11495 +#endif
11496 diff -NurpP --minimal linux-2.6.32.56/include/linux/vs_tag.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vs_tag.h
11497 --- linux-2.6.32.56/include/linux/vs_tag.h      1970-01-01 01:00:00.000000000 +0100
11498 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vs_tag.h      2011-06-10 13:03:02.000000000 +0200
11499 @@ -0,0 +1,47 @@
11500 +#ifndef _VS_TAG_H
11501 +#define _VS_TAG_H
11502 +
11503 +#include <linux/vserver/tag.h>
11504 +
11505 +/* check conditions */
11506 +
11507 +#define DX_ADMIN       0x0001
11508 +#define DX_WATCH       0x0002
11509 +#define DX_HOSTID      0x0008
11510 +
11511 +#define DX_IDENT       0x0010
11512 +
11513 +#define DX_ARG_MASK    0x0010
11514 +
11515 +
11516 +#define dx_task_tag(t) ((t)->tag)
11517 +
11518 +#define dx_current_tag() dx_task_tag(current)
11519 +
11520 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
11521 +
11522 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
11523 +
11524 +
11525 +/*
11526 + * check current context for ADMIN/WATCH and
11527 + * optionally against supplied argument
11528 + */
11529 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
11530 +{
11531 +       if (mode & DX_ARG_MASK) {
11532 +               if ((mode & DX_IDENT) && (id == cid))
11533 +                       return 1;
11534 +       }
11535 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
11536 +               ((mode & DX_WATCH) && (cid == 1)) ||
11537 +               ((mode & DX_HOSTID) && (id == 0)));
11538 +}
11539 +
11540 +struct inode;
11541 +int dx_permission(const struct inode *inode, int mask);
11542 +
11543 +
11544 +#else
11545 +#warning duplicate inclusion
11546 +#endif
11547 diff -NurpP --minimal linux-2.6.32.56/include/linux/vs_time.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vs_time.h
11548 --- linux-2.6.32.56/include/linux/vs_time.h     1970-01-01 01:00:00.000000000 +0100
11549 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vs_time.h     2011-06-10 13:03:02.000000000 +0200
11550 @@ -0,0 +1,19 @@
11551 +#ifndef _VS_TIME_H
11552 +#define _VS_TIME_H
11553 +
11554 +
11555 +/* time faking stuff */
11556 +
11557 +#ifdef CONFIG_VSERVER_VTIME
11558 +
11559 +extern void vx_gettimeofday(struct timeval *tv);
11560 +extern int vx_settimeofday(struct timespec *ts);
11561 +
11562 +#else
11563 +#define        vx_gettimeofday(t)      do_gettimeofday(t)
11564 +#define        vx_settimeofday(t)      do_settimeofday(t)
11565 +#endif
11566 +
11567 +#else
11568 +#warning duplicate inclusion
11569 +#endif
11570 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/Kbuild linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/Kbuild
11571 --- linux-2.6.32.56/include/linux/vserver/Kbuild        1970-01-01 01:00:00.000000000 +0100
11572 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/Kbuild        2011-06-10 13:03:02.000000000 +0200
11573 @@ -0,0 +1,8 @@
11574 +
11575 +unifdef-y += context_cmd.h network_cmd.h space_cmd.h \
11576 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
11577 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
11578 +       debug_cmd.h device_cmd.h
11579 +
11580 +unifdef-y += switch.h network.h monitor.h inode.h device.h
11581 +
11582 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/base.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/base.h
11583 --- linux-2.6.32.56/include/linux/vserver/base.h        1970-01-01 01:00:00.000000000 +0100
11584 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/base.h        2011-06-10 13:03:02.000000000 +0200
11585 @@ -0,0 +1,170 @@
11586 +#ifndef _VX_BASE_H
11587 +#define _VX_BASE_H
11588 +
11589 +
11590 +/* context state changes */
11591 +
11592 +enum {
11593 +       VSC_STARTUP = 1,
11594 +       VSC_SHUTDOWN,
11595 +
11596 +       VSC_NETUP,
11597 +       VSC_NETDOWN,
11598 +};
11599 +
11600 +
11601 +
11602 +#define vx_task_xid(t) ((t)->xid)
11603 +
11604 +#define vx_current_xid() vx_task_xid(current)
11605 +
11606 +#define current_vx_info() (current->vx_info)
11607 +
11608 +
11609 +#define nx_task_nid(t) ((t)->nid)
11610 +
11611 +#define nx_current_nid() nx_task_nid(current)
11612 +
11613 +#define current_nx_info() (current->nx_info)
11614 +
11615 +
11616 +/* generic flag merging */
11617 +
11618 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
11619 +
11620 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
11621 +
11622 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
11623 +
11624 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
11625 +
11626 +
11627 +/* context flags */
11628 +
11629 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
11630 +
11631 +#define vx_current_flags()     __vx_flags(current_vx_info())
11632 +
11633 +#define vx_info_flags(v, m, f) \
11634 +       vs_check_flags(__vx_flags(v), m, f)
11635 +
11636 +#define task_vx_flags(t, m, f) \
11637 +       ((t) && vx_info_flags((t)->vx_info, m, f))
11638 +
11639 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
11640 +
11641 +
11642 +/* context caps */
11643 +
11644 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
11645 +
11646 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
11647 +
11648 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
11649 +
11650 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
11651 +
11652 +
11653 +
11654 +/* network flags */
11655 +
11656 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
11657 +
11658 +#define nx_current_flags()     __nx_flags(current_nx_info())
11659 +
11660 +#define nx_info_flags(n, m, f) \
11661 +       vs_check_flags(__nx_flags(n), m, f)
11662 +
11663 +#define task_nx_flags(t, m, f) \
11664 +       ((t) && nx_info_flags((t)->nx_info, m, f))
11665 +
11666 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
11667 +
11668 +
11669 +/* network caps */
11670 +
11671 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
11672 +
11673 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
11674 +
11675 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
11676 +
11677 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
11678 +
11679 +
11680 +/* context mask capabilities */
11681 +
11682 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
11683 +
11684 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
11685 +
11686 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
11687 +
11688 +
11689 +/* context bcap mask */
11690 +
11691 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
11692 +
11693 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
11694 +
11695 +
11696 +/* mask given bcaps */
11697 +
11698 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
11699 +
11700 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
11701 +
11702 +
11703 +/* masked cap_bset */
11704 +
11705 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
11706 +
11707 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
11708 +
11709 +#if 0
11710 +#define vx_info_mbcap(v, b) \
11711 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
11712 +       vx_info_bcaps(v, b) : (b))
11713 +
11714 +#define task_vx_mbcap(t, b) \
11715 +       vx_info_mbcap((t)->vx_info, (t)->b)
11716 +
11717 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
11718 +#endif
11719 +
11720 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
11721 +
11722 +#define vx_capable(b, c) (capable(b) || \
11723 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
11724 +
11725 +#define nx_capable(b, c) (capable(b) || \
11726 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
11727 +
11728 +#define vx_task_initpid(t, n) \
11729 +       ((t)->vx_info && \
11730 +       ((t)->vx_info->vx_initpid == (n)))
11731 +
11732 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
11733 +
11734 +
11735 +/* context unshare mask */
11736 +
11737 +#define __vx_umask(v)          ((v)->vx_umask)
11738 +
11739 +#define vx_current_umask()     __vx_umask(current_vx_info())
11740 +
11741 +#define vx_can_unshare(b, f) (capable(b) || \
11742 +       (cap_raised(current_cap(), b) && \
11743 +       !((f) & ~vx_current_umask())))
11744 +
11745 +
11746 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
11747 +
11748 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
11749 +
11750 +
11751 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
11752 +
11753 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
11754 +
11755 +#endif
11756 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/cacct.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/cacct.h
11757 --- linux-2.6.32.56/include/linux/vserver/cacct.h       1970-01-01 01:00:00.000000000 +0100
11758 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/cacct.h       2011-06-10 13:03:02.000000000 +0200
11759 @@ -0,0 +1,15 @@
11760 +#ifndef _VX_CACCT_H
11761 +#define _VX_CACCT_H
11762 +
11763 +
11764 +enum sock_acc_field {
11765 +       VXA_SOCK_UNSPEC = 0,
11766 +       VXA_SOCK_UNIX,
11767 +       VXA_SOCK_INET,
11768 +       VXA_SOCK_INET6,
11769 +       VXA_SOCK_PACKET,
11770 +       VXA_SOCK_OTHER,
11771 +       VXA_SOCK_SIZE   /* array size */
11772 +};
11773 +
11774 +#endif /* _VX_CACCT_H */
11775 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/cacct_cmd.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/cacct_cmd.h
11776 --- linux-2.6.32.56/include/linux/vserver/cacct_cmd.h   1970-01-01 01:00:00.000000000 +0100
11777 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/cacct_cmd.h   2011-06-10 13:03:02.000000000 +0200
11778 @@ -0,0 +1,23 @@
11779 +#ifndef _VX_CACCT_CMD_H
11780 +#define _VX_CACCT_CMD_H
11781 +
11782 +
11783 +/* virtual host info name commands */
11784 +
11785 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
11786 +
11787 +struct vcmd_sock_stat_v0 {
11788 +       uint32_t field;
11789 +       uint32_t count[3];
11790 +       uint64_t total[3];
11791 +};
11792 +
11793 +
11794 +#ifdef __KERNEL__
11795 +
11796 +#include <linux/compiler.h>
11797 +
11798 +extern int vc_sock_stat(struct vx_info *, void __user *);
11799 +
11800 +#endif /* __KERNEL__ */
11801 +#endif /* _VX_CACCT_CMD_H */
11802 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/cacct_def.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/cacct_def.h
11803 --- linux-2.6.32.56/include/linux/vserver/cacct_def.h   1970-01-01 01:00:00.000000000 +0100
11804 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/cacct_def.h   2011-06-10 13:03:02.000000000 +0200
11805 @@ -0,0 +1,43 @@
11806 +#ifndef _VX_CACCT_DEF_H
11807 +#define _VX_CACCT_DEF_H
11808 +
11809 +#include <asm/atomic.h>
11810 +#include <linux/vserver/cacct.h>
11811 +
11812 +
11813 +struct _vx_sock_acc {
11814 +       atomic_long_t count;
11815 +       atomic_long_t total;
11816 +};
11817 +
11818 +/* context sub struct */
11819 +
11820 +struct _vx_cacct {
11821 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
11822 +       atomic_t slab[8];
11823 +       atomic_t page[6][8];
11824 +};
11825 +
11826 +#ifdef CONFIG_VSERVER_DEBUG
11827 +
11828 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
11829 +{
11830 +       int i, j;
11831 +
11832 +       printk("\t_vx_cacct:");
11833 +       for (i = 0; i < 6; i++) {
11834 +               struct _vx_sock_acc *ptr = cacct->sock[i];
11835 +
11836 +               printk("\t [%d] =", i);
11837 +               for (j = 0; j < 3; j++) {
11838 +                       printk(" [%d] = %8lu, %8lu", j,
11839 +                               atomic_long_read(&ptr[j].count),
11840 +                               atomic_long_read(&ptr[j].total));
11841 +               }
11842 +               printk("\n");
11843 +       }
11844 +}
11845 +
11846 +#endif
11847 +
11848 +#endif /* _VX_CACCT_DEF_H */
11849 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/cacct_int.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/cacct_int.h
11850 --- linux-2.6.32.56/include/linux/vserver/cacct_int.h   1970-01-01 01:00:00.000000000 +0100
11851 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/cacct_int.h   2011-06-10 13:03:02.000000000 +0200
11852 @@ -0,0 +1,21 @@
11853 +#ifndef _VX_CACCT_INT_H
11854 +#define _VX_CACCT_INT_H
11855 +
11856 +
11857 +#ifdef __KERNEL__
11858 +
11859 +static inline
11860 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
11861 +{
11862 +       return atomic_long_read(&cacct->sock[type][pos].count);
11863 +}
11864 +
11865 +
11866 +static inline
11867 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
11868 +{
11869 +       return atomic_long_read(&cacct->sock[type][pos].total);
11870 +}
11871 +
11872 +#endif /* __KERNEL__ */
11873 +#endif /* _VX_CACCT_INT_H */
11874 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/check.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/check.h
11875 --- linux-2.6.32.56/include/linux/vserver/check.h       1970-01-01 01:00:00.000000000 +0100
11876 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/check.h       2011-06-10 13:03:02.000000000 +0200
11877 @@ -0,0 +1,89 @@
11878 +#ifndef _VS_CHECK_H
11879 +#define _VS_CHECK_H
11880 +
11881 +
11882 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
11883 +
11884 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
11885 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
11886 +#else
11887 +#define MIN_D_CONTEXT  65536
11888 +#endif
11889 +
11890 +/* check conditions */
11891 +
11892 +#define VS_ADMIN       0x0001
11893 +#define VS_WATCH       0x0002
11894 +#define VS_HIDE                0x0004
11895 +#define VS_HOSTID      0x0008
11896 +
11897 +#define VS_IDENT       0x0010
11898 +#define VS_EQUIV       0x0020
11899 +#define VS_PARENT      0x0040
11900 +#define VS_CHILD       0x0080
11901 +
11902 +#define VS_ARG_MASK    0x00F0
11903 +
11904 +#define VS_DYNAMIC     0x0100
11905 +#define VS_STATIC      0x0200
11906 +
11907 +#define VS_ATR_MASK    0x0F00
11908 +
11909 +#ifdef CONFIG_VSERVER_PRIVACY
11910 +#define VS_ADMIN_P     (0)
11911 +#define VS_WATCH_P     (0)
11912 +#else
11913 +#define VS_ADMIN_P     VS_ADMIN
11914 +#define VS_WATCH_P     VS_WATCH
11915 +#endif
11916 +
11917 +#define VS_HARDIRQ     0x1000
11918 +#define VS_SOFTIRQ     0x2000
11919 +#define VS_IRQ         0x4000
11920 +
11921 +#define VS_IRQ_MASK    0xF000
11922 +
11923 +#include <linux/hardirq.h>
11924 +
11925 +/*
11926 + * check current context for ADMIN/WATCH and
11927 + * optionally against supplied argument
11928 + */
11929 +static inline int __vs_check(int cid, int id, unsigned int mode)
11930 +{
11931 +       if (mode & VS_ARG_MASK) {
11932 +               if ((mode & VS_IDENT) && (id == cid))
11933 +                       return 1;
11934 +       }
11935 +       if (mode & VS_ATR_MASK) {
11936 +               if ((mode & VS_DYNAMIC) &&
11937 +                       (id >= MIN_D_CONTEXT) &&
11938 +                       (id <= MAX_S_CONTEXT))
11939 +                       return 1;
11940 +               if ((mode & VS_STATIC) &&
11941 +                       (id > 1) && (id < MIN_D_CONTEXT))
11942 +                       return 1;
11943 +       }
11944 +       if (mode & VS_IRQ_MASK) {
11945 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
11946 +                       return 1;
11947 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
11948 +                       return 1;
11949 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
11950 +                       return 1;
11951 +       }
11952 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
11953 +               ((mode & VS_WATCH) && (cid == 1)) ||
11954 +               ((mode & VS_HOSTID) && (id == 0)));
11955 +}
11956 +
11957 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
11958 +
11959 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
11960 +
11961 +
11962 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
11963 +
11964 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
11965 +
11966 +#endif
11967 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/context.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/context.h
11968 --- linux-2.6.32.56/include/linux/vserver/context.h     1970-01-01 01:00:00.000000000 +0100
11969 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/context.h     2011-06-10 13:03:02.000000000 +0200
11970 @@ -0,0 +1,184 @@
11971 +#ifndef _VX_CONTEXT_H
11972 +#define _VX_CONTEXT_H
11973 +
11974 +#include <linux/types.h>
11975 +#include <linux/capability.h>
11976 +
11977 +
11978 +/* context flags */
11979 +
11980 +#define VXF_INFO_SCHED         0x00000002
11981 +#define VXF_INFO_NPROC         0x00000004
11982 +#define VXF_INFO_PRIVATE       0x00000008
11983 +
11984 +#define VXF_INFO_INIT          0x00000010
11985 +#define VXF_INFO_HIDE          0x00000020
11986 +#define VXF_INFO_ULIMIT                0x00000040
11987 +#define VXF_INFO_NSPACE                0x00000080
11988 +
11989 +#define VXF_SCHED_HARD         0x00000100
11990 +#define VXF_SCHED_PRIO         0x00000200
11991 +#define VXF_SCHED_PAUSE                0x00000400
11992 +
11993 +#define VXF_VIRT_MEM           0x00010000
11994 +#define VXF_VIRT_UPTIME                0x00020000
11995 +#define VXF_VIRT_CPU           0x00040000
11996 +#define VXF_VIRT_LOAD          0x00080000
11997 +#define VXF_VIRT_TIME          0x00100000
11998 +
11999 +#define VXF_HIDE_MOUNT         0x01000000
12000 +/* was VXF_HIDE_NETIF          0x02000000 */
12001 +#define VXF_HIDE_VINFO         0x04000000
12002 +
12003 +#define VXF_STATE_SETUP                (1ULL << 32)
12004 +#define VXF_STATE_INIT         (1ULL << 33)
12005 +#define VXF_STATE_ADMIN                (1ULL << 34)
12006 +
12007 +#define VXF_SC_HELPER          (1ULL << 36)
12008 +#define VXF_REBOOT_KILL                (1ULL << 37)
12009 +#define VXF_PERSISTENT         (1ULL << 38)
12010 +
12011 +#define VXF_FORK_RSS           (1ULL << 48)
12012 +#define VXF_PROLIFIC           (1ULL << 49)
12013 +
12014 +#define VXF_IGNEG_NICE         (1ULL << 52)
12015 +
12016 +#define VXF_ONE_TIME           (0x0007ULL << 32)
12017 +
12018 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
12019 +
12020 +
12021 +/* context migration */
12022 +
12023 +#define VXM_SET_INIT           0x00000001
12024 +#define VXM_SET_REAPER         0x00000002
12025 +
12026 +/* context caps */
12027 +
12028 +#define VXC_CAP_MASK           0x00000000
12029 +
12030 +#define VXC_SET_UTSNAME                0x00000001
12031 +#define VXC_SET_RLIMIT         0x00000002
12032 +#define VXC_FS_SECURITY                0x00000004
12033 +#define VXC_FS_TRUSTED         0x00000008
12034 +#define VXC_TIOCSTI            0x00000010
12035 +
12036 +/* was VXC_RAW_ICMP            0x00000100 */
12037 +#define VXC_SYSLOG             0x00001000
12038 +#define VXC_OOM_ADJUST         0x00002000
12039 +#define VXC_AUDIT_CONTROL      0x00004000
12040 +
12041 +#define VXC_SECURE_MOUNT       0x00010000
12042 +#define VXC_SECURE_REMOUNT     0x00020000
12043 +#define VXC_BINARY_MOUNT       0x00040000
12044 +
12045 +#define VXC_QUOTA_CTL          0x00100000
12046 +#define VXC_ADMIN_MAPPER       0x00200000
12047 +#define VXC_ADMIN_CLOOP                0x00400000
12048 +
12049 +#define VXC_KTHREAD            0x01000000
12050 +#define VXC_NAMESPACE          0x02000000
12051 +
12052 +
12053 +#ifdef __KERNEL__
12054 +
12055 +#include <linux/list.h>
12056 +#include <linux/spinlock.h>
12057 +#include <linux/rcupdate.h>
12058 +
12059 +#include "limit_def.h"
12060 +#include "sched_def.h"
12061 +#include "cvirt_def.h"
12062 +#include "cacct_def.h"
12063 +#include "device_def.h"
12064 +
12065 +#define VX_SPACES      2
12066 +
12067 +struct _vx_info_pc {
12068 +       struct _vx_sched_pc sched_pc;
12069 +       struct _vx_cvirt_pc cvirt_pc;
12070 +};
12071 +
12072 +struct vx_info {
12073 +       struct hlist_node vx_hlist;             /* linked list of contexts */
12074 +       xid_t vx_id;                            /* context id */
12075 +       atomic_t vx_usecnt;                     /* usage count */
12076 +       atomic_t vx_tasks;                      /* tasks count */
12077 +       struct vx_info *vx_parent;              /* parent context */
12078 +       int vx_state;                           /* context state */
12079 +
12080 +       unsigned long vx_nsmask[VX_SPACES];     /* assignment mask */
12081 +       struct nsproxy *vx_nsproxy[VX_SPACES];  /* private namespaces */
12082 +       struct fs_struct *vx_fs[VX_SPACES];     /* private namespace fs */
12083 +
12084 +       uint64_t vx_flags;                      /* context flags */
12085 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
12086 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
12087 +       unsigned long vx_umask;                 /* unshare mask (guest) */
12088 +
12089 +       struct task_struct *vx_reaper;          /* guest reaper process */
12090 +       pid_t vx_initpid;                       /* PID of guest init */
12091 +       int64_t vx_badness_bias;                /* OOM points bias */
12092 +
12093 +       struct _vx_limit limit;                 /* vserver limits */
12094 +       struct _vx_sched sched;                 /* vserver scheduler */
12095 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
12096 +       struct _vx_cacct cacct;                 /* context accounting */
12097 +
12098 +       struct _vx_device dmap;                 /* default device map targets */
12099 +
12100 +#ifndef CONFIG_SMP
12101 +       struct _vx_info_pc info_pc;             /* per cpu data */
12102 +#else
12103 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
12104 +#endif
12105 +
12106 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
12107 +       int reboot_cmd;                         /* last sys_reboot() cmd */
12108 +       int exit_code;                          /* last process exit code */
12109 +
12110 +       char vx_name[65];                       /* vserver name */
12111 +};
12112 +
12113 +#ifndef CONFIG_SMP
12114 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
12115 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
12116 +#else
12117 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
12118 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
12119 +#endif
12120 +
12121 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
12122 +
12123 +
12124 +struct vx_info_save {
12125 +       struct vx_info *vxi;
12126 +       xid_t xid;
12127 +};
12128 +
12129 +
12130 +/* status flags */
12131 +
12132 +#define VXS_HASHED     0x0001
12133 +#define VXS_PAUSED     0x0010
12134 +#define VXS_SHUTDOWN   0x0100
12135 +#define VXS_HELPER     0x1000
12136 +#define VXS_RELEASED   0x8000
12137 +
12138 +
12139 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
12140 +extern void release_vx_info(struct vx_info *, struct task_struct *);
12141 +
12142 +extern struct vx_info *lookup_vx_info(int);
12143 +extern struct vx_info *lookup_or_create_vx_info(int);
12144 +
12145 +extern int get_xid_list(int, unsigned int *, int);
12146 +extern int xid_is_hashed(xid_t);
12147 +
12148 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
12149 +
12150 +extern long vs_state_change(struct vx_info *, unsigned int);
12151 +
12152 +
12153 +#endif /* __KERNEL__ */
12154 +#endif /* _VX_CONTEXT_H */
12155 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/context_cmd.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/context_cmd.h
12156 --- linux-2.6.32.56/include/linux/vserver/context_cmd.h 1970-01-01 01:00:00.000000000 +0100
12157 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/context_cmd.h 2011-06-10 13:03:02.000000000 +0200
12158 @@ -0,0 +1,145 @@
12159 +#ifndef _VX_CONTEXT_CMD_H
12160 +#define _VX_CONTEXT_CMD_H
12161 +
12162 +
12163 +/* vinfo commands */
12164 +
12165 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
12166 +
12167 +#ifdef __KERNEL__
12168 +extern int vc_task_xid(uint32_t);
12169 +
12170 +#endif /* __KERNEL__ */
12171 +
12172 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
12173 +
12174 +struct vcmd_vx_info_v0 {
12175 +       uint32_t xid;
12176 +       uint32_t initpid;
12177 +       /* more to come */
12178 +};
12179 +
12180 +#ifdef __KERNEL__
12181 +extern int vc_vx_info(struct vx_info *, void __user *);
12182 +
12183 +#endif /* __KERNEL__ */
12184 +
12185 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
12186 +
12187 +struct vcmd_ctx_stat_v0 {
12188 +       uint32_t usecnt;
12189 +       uint32_t tasks;
12190 +       /* more to come */
12191 +};
12192 +
12193 +#ifdef __KERNEL__
12194 +extern int vc_ctx_stat(struct vx_info *, void __user *);
12195 +
12196 +#endif /* __KERNEL__ */
12197 +
12198 +/* context commands */
12199 +
12200 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
12201 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
12202 +
12203 +struct vcmd_ctx_create {
12204 +       uint64_t flagword;
12205 +};
12206 +
12207 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
12208 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
12209 +
12210 +struct vcmd_ctx_migrate {
12211 +       uint64_t flagword;
12212 +};
12213 +
12214 +#ifdef __KERNEL__
12215 +extern int vc_ctx_create(uint32_t, void __user *);
12216 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
12217 +
12218 +#endif /* __KERNEL__ */
12219 +
12220 +
12221 +/* flag commands */
12222 +
12223 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
12224 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
12225 +
12226 +struct vcmd_ctx_flags_v0 {
12227 +       uint64_t flagword;
12228 +       uint64_t mask;
12229 +};
12230 +
12231 +#ifdef __KERNEL__
12232 +extern int vc_get_cflags(struct vx_info *, void __user *);
12233 +extern int vc_set_cflags(struct vx_info *, void __user *);
12234 +
12235 +#endif /* __KERNEL__ */
12236 +
12237 +
12238 +/* context caps commands */
12239 +
12240 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
12241 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
12242 +
12243 +struct vcmd_ctx_caps_v1 {
12244 +       uint64_t ccaps;
12245 +       uint64_t cmask;
12246 +};
12247 +
12248 +#ifdef __KERNEL__
12249 +extern int vc_get_ccaps(struct vx_info *, void __user *);
12250 +extern int vc_set_ccaps(struct vx_info *, void __user *);
12251 +
12252 +#endif /* __KERNEL__ */
12253 +
12254 +
12255 +/* bcaps commands */
12256 +
12257 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
12258 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
12259 +
12260 +struct vcmd_bcaps {
12261 +       uint64_t bcaps;
12262 +       uint64_t bmask;
12263 +};
12264 +
12265 +#ifdef __KERNEL__
12266 +extern int vc_get_bcaps(struct vx_info *, void __user *);
12267 +extern int vc_set_bcaps(struct vx_info *, void __user *);
12268 +
12269 +#endif /* __KERNEL__ */
12270 +
12271 +
12272 +/* umask commands */
12273 +
12274 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
12275 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
12276 +
12277 +struct vcmd_umask {
12278 +       uint64_t umask;
12279 +       uint64_t mask;
12280 +};
12281 +
12282 +#ifdef __KERNEL__
12283 +extern int vc_get_umask(struct vx_info *, void __user *);
12284 +extern int vc_set_umask(struct vx_info *, void __user *);
12285 +
12286 +#endif /* __KERNEL__ */
12287 +
12288 +
12289 +/* OOM badness */
12290 +
12291 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
12292 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
12293 +
12294 +struct vcmd_badness_v0 {
12295 +       int64_t bias;
12296 +};
12297 +
12298 +#ifdef __KERNEL__
12299 +extern int vc_get_badness(struct vx_info *, void __user *);
12300 +extern int vc_set_badness(struct vx_info *, void __user *);
12301 +
12302 +#endif /* __KERNEL__ */
12303 +#endif /* _VX_CONTEXT_CMD_H */
12304 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/cvirt.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/cvirt.h
12305 --- linux-2.6.32.56/include/linux/vserver/cvirt.h       1970-01-01 01:00:00.000000000 +0100
12306 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/cvirt.h       2011-06-10 13:03:02.000000000 +0200
12307 @@ -0,0 +1,20 @@
12308 +#ifndef _VX_CVIRT_H
12309 +#define _VX_CVIRT_H
12310 +
12311 +
12312 +#ifdef __KERNEL__
12313 +
12314 +struct timespec;
12315 +
12316 +void vx_vsi_uptime(struct timespec *, struct timespec *);
12317 +
12318 +
12319 +struct vx_info;
12320 +
12321 +void vx_update_load(struct vx_info *);
12322 +
12323 +
12324 +int vx_do_syslog(int, char __user *, int);
12325 +
12326 +#endif /* __KERNEL__ */
12327 +#endif /* _VX_CVIRT_H */
12328 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/cvirt_cmd.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/cvirt_cmd.h
12329 --- linux-2.6.32.56/include/linux/vserver/cvirt_cmd.h   1970-01-01 01:00:00.000000000 +0100
12330 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/cvirt_cmd.h   2011-06-10 13:03:02.000000000 +0200
12331 @@ -0,0 +1,53 @@
12332 +#ifndef _VX_CVIRT_CMD_H
12333 +#define _VX_CVIRT_CMD_H
12334 +
12335 +
12336 +/* virtual host info name commands */
12337 +
12338 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
12339 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
12340 +
12341 +struct vcmd_vhi_name_v0 {
12342 +       uint32_t field;
12343 +       char name[65];
12344 +};
12345 +
12346 +
12347 +enum vhi_name_field {
12348 +       VHIN_CONTEXT = 0,
12349 +       VHIN_SYSNAME,
12350 +       VHIN_NODENAME,
12351 +       VHIN_RELEASE,
12352 +       VHIN_VERSION,
12353 +       VHIN_MACHINE,
12354 +       VHIN_DOMAINNAME,
12355 +};
12356 +
12357 +
12358 +#ifdef __KERNEL__
12359 +
12360 +#include <linux/compiler.h>
12361 +
12362 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
12363 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
12364 +
12365 +#endif /* __KERNEL__ */
12366 +
12367 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
12368 +
12369 +struct vcmd_virt_stat_v0 {
12370 +       uint64_t offset;
12371 +       uint64_t uptime;
12372 +       uint32_t nr_threads;
12373 +       uint32_t nr_running;
12374 +       uint32_t nr_uninterruptible;
12375 +       uint32_t nr_onhold;
12376 +       uint32_t nr_forks;
12377 +       uint32_t load[3];
12378 +};
12379 +
12380 +#ifdef __KERNEL__
12381 +extern int vc_virt_stat(struct vx_info *, void __user *);
12382 +
12383 +#endif /* __KERNEL__ */
12384 +#endif /* _VX_CVIRT_CMD_H */
12385 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/cvirt_def.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/cvirt_def.h
12386 --- linux-2.6.32.56/include/linux/vserver/cvirt_def.h   1970-01-01 01:00:00.000000000 +0100
12387 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/cvirt_def.h   2011-06-10 13:03:02.000000000 +0200
12388 @@ -0,0 +1,80 @@
12389 +#ifndef _VX_CVIRT_DEF_H
12390 +#define _VX_CVIRT_DEF_H
12391 +
12392 +#include <linux/jiffies.h>
12393 +#include <linux/spinlock.h>
12394 +#include <linux/wait.h>
12395 +#include <linux/time.h>
12396 +#include <asm/atomic.h>
12397 +
12398 +
12399 +struct _vx_usage_stat {
12400 +       uint64_t user;
12401 +       uint64_t nice;
12402 +       uint64_t system;
12403 +       uint64_t softirq;
12404 +       uint64_t irq;
12405 +       uint64_t idle;
12406 +       uint64_t iowait;
12407 +};
12408 +
12409 +struct _vx_syslog {
12410 +       wait_queue_head_t log_wait;
12411 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
12412 +
12413 +       unsigned long log_start;        /* next char to be read by syslog() */
12414 +       unsigned long con_start;        /* next char to be sent to consoles */
12415 +       unsigned long log_end;  /* most-recently-written-char + 1 */
12416 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
12417 +
12418 +       char log_buf[1024];
12419 +};
12420 +
12421 +
12422 +/* context sub struct */
12423 +
12424 +struct _vx_cvirt {
12425 +       atomic_t nr_threads;            /* number of current threads */
12426 +       atomic_t nr_running;            /* number of running threads */
12427 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
12428 +
12429 +       atomic_t nr_onhold;             /* processes on hold */
12430 +       uint32_t onhold_last;           /* jiffies when put on hold */
12431 +
12432 +       struct timeval bias_tv;         /* time offset to the host */
12433 +       struct timespec bias_idle;
12434 +       struct timespec bias_uptime;    /* context creation point */
12435 +       uint64_t bias_clock;            /* offset in clock_t */
12436 +
12437 +       spinlock_t load_lock;           /* lock for the load averages */
12438 +       atomic_t load_updates;          /* nr of load updates done so far */
12439 +       uint32_t load_last;             /* last time load was calculated */
12440 +       uint32_t load[3];               /* load averages 1,5,15 */
12441 +
12442 +       atomic_t total_forks;           /* number of forks so far */
12443 +
12444 +       struct _vx_syslog syslog;
12445 +};
12446 +
12447 +struct _vx_cvirt_pc {
12448 +       struct _vx_usage_stat cpustat;
12449 +};
12450 +
12451 +
12452 +#ifdef CONFIG_VSERVER_DEBUG
12453 +
12454 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
12455 +{
12456 +       printk("\t_vx_cvirt:\n");
12457 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
12458 +               atomic_read(&cvirt->nr_threads),
12459 +               atomic_read(&cvirt->nr_running),
12460 +               atomic_read(&cvirt->nr_uninterruptible),
12461 +               atomic_read(&cvirt->nr_onhold));
12462 +       /* add rest here */
12463 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
12464 +}
12465 +
12466 +#endif
12467 +
12468 +#endif /* _VX_CVIRT_DEF_H */
12469 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/debug.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/debug.h
12470 --- linux-2.6.32.56/include/linux/vserver/debug.h       1970-01-01 01:00:00.000000000 +0100
12471 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/debug.h       2011-06-10 13:03:02.000000000 +0200
12472 @@ -0,0 +1,127 @@
12473 +#ifndef _VX_DEBUG_H
12474 +#define _VX_DEBUG_H
12475 +
12476 +
12477 +#define VXD_CBIT(n, m) (vx_debug_ ## n & (1 << (m)))
12478 +#define VXD_CMIN(n, m) (vx_debug_ ## n > (m))
12479 +#define VXD_MASK(n, m) (vx_debug_ ## n & (m))
12480 +
12481 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
12482 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
12483 +#define VXF_DEV                "%p[%lu,%d:%d]"
12484 +
12485 +
12486 +#define vxd_path(p)                                            \
12487 +       ({ static char _buffer[PATH_MAX];                       \
12488 +          d_path(p, _buffer, sizeof(_buffer)); })
12489 +
12490 +#define vxd_cond_path(n)                                       \
12491 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
12492 +
12493 +
12494 +#ifdef CONFIG_VSERVER_DEBUG
12495 +
12496 +extern unsigned int vx_debug_switch;
12497 +extern unsigned int vx_debug_xid;
12498 +extern unsigned int vx_debug_nid;
12499 +extern unsigned int vx_debug_tag;
12500 +extern unsigned int vx_debug_net;
12501 +extern unsigned int vx_debug_limit;
12502 +extern unsigned int vx_debug_cres;
12503 +extern unsigned int vx_debug_dlim;
12504 +extern unsigned int vx_debug_quota;
12505 +extern unsigned int vx_debug_cvirt;
12506 +extern unsigned int vx_debug_space;
12507 +extern unsigned int vx_debug_misc;
12508 +
12509 +
12510 +#define VX_LOGLEVEL    "vxD: "
12511 +#define VX_PROC_FMT    "%p: "
12512 +#define VX_PROCESS     current
12513 +
12514 +#define vxdprintk(c, f, x...)                                  \
12515 +       do {                                                    \
12516 +               if (c)                                          \
12517 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
12518 +                               VX_PROCESS , ##x);              \
12519 +       } while (0)
12520 +
12521 +#define vxlprintk(c, f, x...)                                  \
12522 +       do {                                                    \
12523 +               if (c)                                          \
12524 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
12525 +       } while (0)
12526 +
12527 +#define vxfprintk(c, f, x...)                                  \
12528 +       do {                                                    \
12529 +               if (c)                                          \
12530 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
12531 +       } while (0)
12532 +
12533 +
12534 +struct vx_info;
12535 +
12536 +void dump_vx_info(struct vx_info *, int);
12537 +void dump_vx_info_inactive(int);
12538 +
12539 +#else  /* CONFIG_VSERVER_DEBUG */
12540 +
12541 +#define vx_debug_switch 0
12542 +#define vx_debug_xid   0
12543 +#define vx_debug_nid   0
12544 +#define vx_debug_tag   0
12545 +#define vx_debug_net   0
12546 +#define vx_debug_limit 0
12547 +#define vx_debug_cres  0
12548 +#define vx_debug_dlim  0
12549 +#define vx_debug_cvirt 0
12550 +
12551 +#define vxdprintk(x...) do { } while (0)
12552 +#define vxlprintk(x...) do { } while (0)
12553 +#define vxfprintk(x...) do { } while (0)
12554 +
12555 +#endif /* CONFIG_VSERVER_DEBUG */
12556 +
12557 +
12558 +#ifdef CONFIG_VSERVER_WARN
12559 +
12560 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
12561 +#define VX_WARN_TASK   "[»%s«,%u:#%u|%u|%u] "
12562 +#define VX_WARN_XID    "[xid #%u] "
12563 +#define VX_WARN_NID    "[nid #%u] "
12564 +#define VX_WARN_TAG    "[tag #%u] "
12565 +
12566 +#define vxwprintk(c, f, x...)                                  \
12567 +       do {                                                    \
12568 +               if (c)                                          \
12569 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
12570 +       } while (0)
12571 +
12572 +#else  /* CONFIG_VSERVER_WARN */
12573 +
12574 +#define vxwprintk(x...) do { } while (0)
12575 +
12576 +#endif /* CONFIG_VSERVER_WARN */
12577 +
12578 +#define vxwprintk_task(c, f, x...)                             \
12579 +       vxwprintk(c, VX_WARN_TASK f,                            \
12580 +               current->comm, current->pid,                    \
12581 +               current->xid, current->nid, current->tag, ##x)
12582 +#define vxwprintk_xid(c, f, x...)                              \
12583 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
12584 +#define vxwprintk_nid(c, f, x...)                              \
12585 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
12586 +#define vxwprintk_tag(c, f, x...)                              \
12587 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
12588 +
12589 +#ifdef CONFIG_VSERVER_DEBUG
12590 +#define vxd_assert_lock(l)     assert_spin_locked(l)
12591 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
12592 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
12593 +#else
12594 +#define vxd_assert_lock(l)     do { } while (0)
12595 +#define vxd_assert(c, f, x...) do { } while (0)
12596 +#endif
12597 +
12598 +
12599 +#endif /* _VX_DEBUG_H */
12600 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/debug_cmd.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/debug_cmd.h
12601 --- linux-2.6.32.56/include/linux/vserver/debug_cmd.h   1970-01-01 01:00:00.000000000 +0100
12602 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/debug_cmd.h   2011-06-10 13:03:02.000000000 +0200
12603 @@ -0,0 +1,58 @@
12604 +#ifndef _VX_DEBUG_CMD_H
12605 +#define _VX_DEBUG_CMD_H
12606 +
12607 +
12608 +/* debug commands */
12609 +
12610 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
12611 +
12612 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
12613 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
12614 +
12615 +struct  vcmd_read_history_v0 {
12616 +       uint32_t index;
12617 +       uint32_t count;
12618 +       char __user *data;
12619 +};
12620 +
12621 +struct  vcmd_read_monitor_v0 {
12622 +       uint32_t index;
12623 +       uint32_t count;
12624 +       char __user *data;
12625 +};
12626 +
12627 +
12628 +#ifdef __KERNEL__
12629 +
12630 +#ifdef CONFIG_COMPAT
12631 +
12632 +#include <asm/compat.h>
12633 +
12634 +struct vcmd_read_history_v0_x32 {
12635 +       uint32_t index;
12636 +       uint32_t count;
12637 +       compat_uptr_t data_ptr;
12638 +};
12639 +
12640 +struct vcmd_read_monitor_v0_x32 {
12641 +       uint32_t index;
12642 +       uint32_t count;
12643 +       compat_uptr_t data_ptr;
12644 +};
12645 +
12646 +#endif  /* CONFIG_COMPAT */
12647 +
12648 +extern int vc_dump_history(uint32_t);
12649 +
12650 +extern int vc_read_history(uint32_t, void __user *);
12651 +extern int vc_read_monitor(uint32_t, void __user *);
12652 +
12653 +#ifdef CONFIG_COMPAT
12654 +
12655 +extern int vc_read_history_x32(uint32_t, void __user *);
12656 +extern int vc_read_monitor_x32(uint32_t, void __user *);
12657 +
12658 +#endif  /* CONFIG_COMPAT */
12659 +
12660 +#endif /* __KERNEL__ */
12661 +#endif /* _VX_DEBUG_CMD_H */
12662 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/device.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/device.h
12663 --- linux-2.6.32.56/include/linux/vserver/device.h      1970-01-01 01:00:00.000000000 +0100
12664 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/device.h      2011-06-10 13:03:02.000000000 +0200
12665 @@ -0,0 +1,15 @@
12666 +#ifndef _VX_DEVICE_H
12667 +#define _VX_DEVICE_H
12668 +
12669 +
12670 +#define DATTR_CREATE   0x00000001
12671 +#define DATTR_OPEN     0x00000002
12672 +
12673 +#define DATTR_REMAP    0x00000010
12674 +
12675 +#define DATTR_MASK     0x00000013
12676 +
12677 +
12678 +#else  /* _VX_DEVICE_H */
12679 +#warning duplicate inclusion
12680 +#endif /* _VX_DEVICE_H */
12681 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/device_cmd.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/device_cmd.h
12682 --- linux-2.6.32.56/include/linux/vserver/device_cmd.h  1970-01-01 01:00:00.000000000 +0100
12683 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/device_cmd.h  2011-06-10 13:03:02.000000000 +0200
12684 @@ -0,0 +1,44 @@
12685 +#ifndef _VX_DEVICE_CMD_H
12686 +#define _VX_DEVICE_CMD_H
12687 +
12688 +
12689 +/*  device vserver commands */
12690 +
12691 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
12692 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
12693 +
12694 +struct vcmd_set_mapping_v0 {
12695 +       const char __user *device;
12696 +       const char __user *target;
12697 +       uint32_t flags;
12698 +};
12699 +
12700 +
12701 +#ifdef __KERNEL__
12702 +
12703 +#ifdef CONFIG_COMPAT
12704 +
12705 +#include <asm/compat.h>
12706 +
12707 +struct vcmd_set_mapping_v0_x32 {
12708 +       compat_uptr_t device_ptr;
12709 +       compat_uptr_t target_ptr;
12710 +       uint32_t flags;
12711 +};
12712 +
12713 +#endif /* CONFIG_COMPAT */
12714 +
12715 +#include <linux/compiler.h>
12716 +
12717 +extern int vc_set_mapping(struct vx_info *, void __user *);
12718 +extern int vc_unset_mapping(struct vx_info *, void __user *);
12719 +
12720 +#ifdef CONFIG_COMPAT
12721 +
12722 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
12723 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
12724 +
12725 +#endif /* CONFIG_COMPAT */
12726 +
12727 +#endif /* __KERNEL__ */
12728 +#endif /* _VX_DEVICE_CMD_H */
12729 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/device_def.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/device_def.h
12730 --- linux-2.6.32.56/include/linux/vserver/device_def.h  1970-01-01 01:00:00.000000000 +0100
12731 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/device_def.h  2011-06-10 13:03:02.000000000 +0200
12732 @@ -0,0 +1,17 @@
12733 +#ifndef _VX_DEVICE_DEF_H
12734 +#define _VX_DEVICE_DEF_H
12735 +
12736 +#include <linux/types.h>
12737 +
12738 +struct vx_dmap_target {
12739 +       dev_t target;
12740 +       uint32_t flags;
12741 +};
12742 +
12743 +struct _vx_device {
12744 +#ifdef CONFIG_VSERVER_DEVICE
12745 +       struct vx_dmap_target targets[2];
12746 +#endif
12747 +};
12748 +
12749 +#endif /* _VX_DEVICE_DEF_H */
12750 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/dlimit.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/dlimit.h
12751 --- linux-2.6.32.56/include/linux/vserver/dlimit.h      1970-01-01 01:00:00.000000000 +0100
12752 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/dlimit.h      2011-06-10 13:03:02.000000000 +0200
12753 @@ -0,0 +1,54 @@
12754 +#ifndef _VX_DLIMIT_H
12755 +#define _VX_DLIMIT_H
12756 +
12757 +#include "switch.h"
12758 +
12759 +
12760 +#ifdef __KERNEL__
12761 +
12762 +/*      keep in sync with CDLIM_INFINITY       */
12763 +
12764 +#define DLIM_INFINITY          (~0ULL)
12765 +
12766 +#include <linux/spinlock.h>
12767 +#include <linux/rcupdate.h>
12768 +
12769 +struct super_block;
12770 +
12771 +struct dl_info {
12772 +       struct hlist_node dl_hlist;             /* linked list of contexts */
12773 +       struct rcu_head dl_rcu;                 /* the rcu head */
12774 +       tag_t dl_tag;                           /* context tag */
12775 +       atomic_t dl_usecnt;                     /* usage count */
12776 +       atomic_t dl_refcnt;                     /* reference count */
12777 +
12778 +       struct super_block *dl_sb;              /* associated superblock */
12779 +
12780 +       spinlock_t dl_lock;                     /* protect the values */
12781 +
12782 +       unsigned long long dl_space_used;       /* used space in bytes */
12783 +       unsigned long long dl_space_total;      /* maximum space in bytes */
12784 +       unsigned long dl_inodes_used;           /* used inodes */
12785 +       unsigned long dl_inodes_total;          /* maximum inodes */
12786 +
12787 +       unsigned int dl_nrlmult;                /* non root limit mult */
12788 +};
12789 +
12790 +struct rcu_head;
12791 +
12792 +extern void rcu_free_dl_info(struct rcu_head *);
12793 +extern void unhash_dl_info(struct dl_info *);
12794 +
12795 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
12796 +
12797 +
12798 +struct kstatfs;
12799 +
12800 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
12801 +
12802 +typedef uint64_t dlsize_t;
12803 +
12804 +#endif /* __KERNEL__ */
12805 +#else  /* _VX_DLIMIT_H */
12806 +#warning duplicate inclusion
12807 +#endif /* _VX_DLIMIT_H */
12808 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/dlimit_cmd.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/dlimit_cmd.h
12809 --- linux-2.6.32.56/include/linux/vserver/dlimit_cmd.h  1970-01-01 01:00:00.000000000 +0100
12810 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/dlimit_cmd.h  2011-06-10 13:03:02.000000000 +0200
12811 @@ -0,0 +1,109 @@
12812 +#ifndef _VX_DLIMIT_CMD_H
12813 +#define _VX_DLIMIT_CMD_H
12814 +
12815 +
12816 +/*  dlimit vserver commands */
12817 +
12818 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
12819 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
12820 +
12821 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
12822 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
12823 +
12824 +struct vcmd_ctx_dlimit_base_v0 {
12825 +       const char __user *name;
12826 +       uint32_t flags;
12827 +};
12828 +
12829 +struct vcmd_ctx_dlimit_v0 {
12830 +       const char __user *name;
12831 +       uint32_t space_used;                    /* used space in kbytes */
12832 +       uint32_t space_total;                   /* maximum space in kbytes */
12833 +       uint32_t inodes_used;                   /* used inodes */
12834 +       uint32_t inodes_total;                  /* maximum inodes */
12835 +       uint32_t reserved;                      /* reserved for root in % */
12836 +       uint32_t flags;
12837 +};
12838 +
12839 +#define CDLIM_UNSET            ((uint32_t)0UL)
12840 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
12841 +#define CDLIM_KEEP             ((uint32_t)~1UL)
12842 +
12843 +#define DLIME_UNIT     0
12844 +#define DLIME_KILO     1
12845 +#define DLIME_MEGA     2
12846 +#define DLIME_GIGA     3
12847 +
12848 +#define DLIMF_SHIFT    0x10
12849 +
12850 +#define DLIMS_USED     0
12851 +#define DLIMS_TOTAL    2
12852 +
12853 +static inline
12854 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
12855 +{
12856 +       int exp = (flags & DLIMF_SHIFT) ?
12857 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
12858 +       return ((uint64_t)val) << (10 * exp);
12859 +}
12860 +
12861 +static inline
12862 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
12863 +{
12864 +       int exp = 0;
12865 +
12866 +       if (*flags & DLIMF_SHIFT) {
12867 +               while (val > (1LL << 32) && (exp < 3)) {
12868 +                       val >>= 10;
12869 +                       exp++;
12870 +               }
12871 +               *flags &= ~(DLIME_GIGA << shift);
12872 +               *flags |= exp << shift;
12873 +       } else
12874 +               val >>= 10;
12875 +       return val;
12876 +}
12877 +
12878 +#ifdef __KERNEL__
12879 +
12880 +#ifdef CONFIG_COMPAT
12881 +
12882 +#include <asm/compat.h>
12883 +
12884 +struct vcmd_ctx_dlimit_base_v0_x32 {
12885 +       compat_uptr_t name_ptr;
12886 +       uint32_t flags;
12887 +};
12888 +
12889 +struct vcmd_ctx_dlimit_v0_x32 {
12890 +       compat_uptr_t name_ptr;
12891 +       uint32_t space_used;                    /* used space in kbytes */
12892 +       uint32_t space_total;                   /* maximum space in kbytes */
12893 +       uint32_t inodes_used;                   /* used inodes */
12894 +       uint32_t inodes_total;                  /* maximum inodes */
12895 +       uint32_t reserved;                      /* reserved for root in % */
12896 +       uint32_t flags;
12897 +};
12898 +
12899 +#endif /* CONFIG_COMPAT */
12900 +
12901 +#include <linux/compiler.h>
12902 +
12903 +extern int vc_add_dlimit(uint32_t, void __user *);
12904 +extern int vc_rem_dlimit(uint32_t, void __user *);
12905 +
12906 +extern int vc_set_dlimit(uint32_t, void __user *);
12907 +extern int vc_get_dlimit(uint32_t, void __user *);
12908 +
12909 +#ifdef CONFIG_COMPAT
12910 +
12911 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
12912 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
12913 +
12914 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
12915 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
12916 +
12917 +#endif /* CONFIG_COMPAT */
12918 +
12919 +#endif /* __KERNEL__ */
12920 +#endif /* _VX_DLIMIT_CMD_H */
12921 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/global.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/global.h
12922 --- linux-2.6.32.56/include/linux/vserver/global.h      1970-01-01 01:00:00.000000000 +0100
12923 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/global.h      2011-06-10 13:03:02.000000000 +0200
12924 @@ -0,0 +1,19 @@
12925 +#ifndef _VX_GLOBAL_H
12926 +#define _VX_GLOBAL_H
12927 +
12928 +
12929 +extern atomic_t vx_global_ctotal;
12930 +extern atomic_t vx_global_cactive;
12931 +
12932 +extern atomic_t nx_global_ctotal;
12933 +extern atomic_t nx_global_cactive;
12934 +
12935 +extern atomic_t vs_global_nsproxy;
12936 +extern atomic_t vs_global_fs;
12937 +extern atomic_t vs_global_mnt_ns;
12938 +extern atomic_t vs_global_uts_ns;
12939 +extern atomic_t vs_global_user_ns;
12940 +extern atomic_t vs_global_pid_ns;
12941 +
12942 +
12943 +#endif /* _VX_GLOBAL_H */
12944 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/history.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/history.h
12945 --- linux-2.6.32.56/include/linux/vserver/history.h     1970-01-01 01:00:00.000000000 +0100
12946 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/history.h     2011-06-10 13:03:02.000000000 +0200
12947 @@ -0,0 +1,197 @@
12948 +#ifndef _VX_HISTORY_H
12949 +#define _VX_HISTORY_H
12950 +
12951 +
12952 +enum {
12953 +       VXH_UNUSED = 0,
12954 +       VXH_THROW_OOPS = 1,
12955 +
12956 +       VXH_GET_VX_INFO,
12957 +       VXH_PUT_VX_INFO,
12958 +       VXH_INIT_VX_INFO,
12959 +       VXH_SET_VX_INFO,
12960 +       VXH_CLR_VX_INFO,
12961 +       VXH_CLAIM_VX_INFO,
12962 +       VXH_RELEASE_VX_INFO,
12963 +       VXH_ALLOC_VX_INFO,
12964 +       VXH_DEALLOC_VX_INFO,
12965 +       VXH_HASH_VX_INFO,
12966 +       VXH_UNHASH_VX_INFO,
12967 +       VXH_LOC_VX_INFO,
12968 +       VXH_LOOKUP_VX_INFO,
12969 +       VXH_CREATE_VX_INFO,
12970 +};
12971 +
12972 +struct _vxhe_vxi {
12973 +       struct vx_info *ptr;
12974 +       unsigned xid;
12975 +       unsigned usecnt;
12976 +       unsigned tasks;
12977 +};
12978 +
12979 +struct _vxhe_set_clr {
12980 +       void *data;
12981 +};
12982 +
12983 +struct _vxhe_loc_lookup {
12984 +       unsigned arg;
12985 +};
12986 +
12987 +struct _vx_hist_entry {
12988 +       void *loc;
12989 +       unsigned short seq;
12990 +       unsigned short type;
12991 +       struct _vxhe_vxi vxi;
12992 +       union {
12993 +               struct _vxhe_set_clr sc;
12994 +               struct _vxhe_loc_lookup ll;
12995 +       };
12996 +};
12997 +
12998 +#ifdef CONFIG_VSERVER_HISTORY
12999 +
13000 +extern unsigned volatile int vxh_active;
13001 +
13002 +struct _vx_hist_entry *vxh_advance(void *loc);
13003 +
13004 +
13005 +static inline
13006 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
13007 +{
13008 +       entry->vxi.ptr = vxi;
13009 +       if (vxi) {
13010 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
13011 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
13012 +               entry->vxi.xid = vxi->vx_id;
13013 +       }
13014 +}
13015 +
13016 +
13017 +#define        __HERE__ current_text_addr()
13018 +
13019 +#define __VXH_BODY(__type, __data, __here)     \
13020 +       struct _vx_hist_entry *entry;           \
13021 +                                               \
13022 +       preempt_disable();                      \
13023 +       entry = vxh_advance(__here);            \
13024 +       __data;                                 \
13025 +       entry->type = __type;                   \
13026 +       preempt_enable();
13027 +
13028 +
13029 +       /* pass vxi only */
13030 +
13031 +#define __VXH_SMPL                             \
13032 +       __vxh_copy_vxi(entry, vxi)
13033 +
13034 +static inline
13035 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
13036 +{
13037 +       __VXH_BODY(__type, __VXH_SMPL, __here)
13038 +}
13039 +
13040 +       /* pass vxi and data (void *) */
13041 +
13042 +#define __VXH_DATA                             \
13043 +       __vxh_copy_vxi(entry, vxi);             \
13044 +       entry->sc.data = data
13045 +
13046 +static inline
13047 +void   __vxh_data(struct vx_info *vxi, void *data,
13048 +                       int __type, void *__here)
13049 +{
13050 +       __VXH_BODY(__type, __VXH_DATA, __here)
13051 +}
13052 +
13053 +       /* pass vxi and arg (long) */
13054 +
13055 +#define __VXH_LONG                             \
13056 +       __vxh_copy_vxi(entry, vxi);             \
13057 +       entry->ll.arg = arg
13058 +
13059 +static inline
13060 +void   __vxh_long(struct vx_info *vxi, long arg,
13061 +                       int __type, void *__here)
13062 +{
13063 +       __VXH_BODY(__type, __VXH_LONG, __here)
13064 +}
13065 +
13066 +
13067 +static inline
13068 +void   __vxh_throw_oops(void *__here)
13069 +{
13070 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
13071 +       /* prevent further acquisition */
13072 +       vxh_active = 0;
13073 +}
13074 +
13075 +
13076 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
13077 +
13078 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
13079 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
13080 +
13081 +#define __vxh_init_vx_info(v, d, h) \
13082 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
13083 +#define __vxh_set_vx_info(v, d, h) \
13084 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
13085 +#define __vxh_clr_vx_info(v, d, h) \
13086 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
13087 +
13088 +#define __vxh_claim_vx_info(v, d, h) \
13089 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
13090 +#define __vxh_release_vx_info(v, d, h) \
13091 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
13092 +
13093 +#define vxh_alloc_vx_info(v) \
13094 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
13095 +#define vxh_dealloc_vx_info(v) \
13096 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
13097 +
13098 +#define vxh_hash_vx_info(v) \
13099 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
13100 +#define vxh_unhash_vx_info(v) \
13101 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
13102 +
13103 +#define vxh_loc_vx_info(v, l) \
13104 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
13105 +#define vxh_lookup_vx_info(v, l) \
13106 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
13107 +#define vxh_create_vx_info(v, l) \
13108 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
13109 +
13110 +extern void vxh_dump_history(void);
13111 +
13112 +
13113 +#else  /* CONFIG_VSERVER_HISTORY */
13114 +
13115 +#define        __HERE__        0
13116 +
13117 +#define vxh_throw_oops()               do { } while (0)
13118 +
13119 +#define __vxh_get_vx_info(v, h)                do { } while (0)
13120 +#define __vxh_put_vx_info(v, h)                do { } while (0)
13121 +
13122 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
13123 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
13124 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
13125 +
13126 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
13127 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
13128 +
13129 +#define vxh_alloc_vx_info(v)           do { } while (0)
13130 +#define vxh_dealloc_vx_info(v)         do { } while (0)
13131 +
13132 +#define vxh_hash_vx_info(v)            do { } while (0)
13133 +#define vxh_unhash_vx_info(v)          do { } while (0)
13134 +
13135 +#define vxh_loc_vx_info(v, l)          do { } while (0)
13136 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
13137 +#define vxh_create_vx_info(v, l)       do { } while (0)
13138 +
13139 +#define vxh_dump_history()             do { } while (0)
13140 +
13141 +
13142 +#endif /* CONFIG_VSERVER_HISTORY */
13143 +
13144 +#endif /* _VX_HISTORY_H */
13145 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/inode.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/inode.h
13146 --- linux-2.6.32.56/include/linux/vserver/inode.h       1970-01-01 01:00:00.000000000 +0100
13147 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/inode.h       2011-06-10 13:03:02.000000000 +0200
13148 @@ -0,0 +1,39 @@
13149 +#ifndef _VX_INODE_H
13150 +#define _VX_INODE_H
13151 +
13152 +
13153 +#define IATTR_TAG      0x01000000
13154 +
13155 +#define IATTR_ADMIN    0x00000001
13156 +#define IATTR_WATCH    0x00000002
13157 +#define IATTR_HIDE     0x00000004
13158 +#define IATTR_FLAGS    0x00000007
13159 +
13160 +#define IATTR_BARRIER  0x00010000
13161 +#define IATTR_IXUNLINK 0x00020000
13162 +#define IATTR_IMMUTABLE 0x00040000
13163 +#define IATTR_COW      0x00080000
13164 +
13165 +#ifdef __KERNEL__
13166 +
13167 +
13168 +#ifdef CONFIG_VSERVER_PROC_SECURE
13169 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
13170 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
13171 +#else
13172 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
13173 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
13174 +#endif
13175 +
13176 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
13177 +
13178 +#endif /* __KERNEL__ */
13179 +
13180 +/* inode ioctls */
13181 +
13182 +#define FIOC_GETXFLG   _IOR('x', 5, long)
13183 +#define FIOC_SETXFLG   _IOW('x', 6, long)
13184 +
13185 +#else  /* _VX_INODE_H */
13186 +#warning duplicate inclusion
13187 +#endif /* _VX_INODE_H */
13188 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/inode_cmd.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/inode_cmd.h
13189 --- linux-2.6.32.56/include/linux/vserver/inode_cmd.h   1970-01-01 01:00:00.000000000 +0100
13190 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/inode_cmd.h   2011-06-10 13:03:02.000000000 +0200
13191 @@ -0,0 +1,59 @@
13192 +#ifndef _VX_INODE_CMD_H
13193 +#define _VX_INODE_CMD_H
13194 +
13195 +
13196 +/*  inode vserver commands */
13197 +
13198 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
13199 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
13200 +
13201 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
13202 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
13203 +
13204 +struct vcmd_ctx_iattr_v1 {
13205 +       const char __user *name;
13206 +       uint32_t tag;
13207 +       uint32_t flags;
13208 +       uint32_t mask;
13209 +};
13210 +
13211 +struct vcmd_ctx_fiattr_v0 {
13212 +       uint32_t tag;
13213 +       uint32_t flags;
13214 +       uint32_t mask;
13215 +};
13216 +
13217 +
13218 +#ifdef __KERNEL__
13219 +
13220 +
13221 +#ifdef CONFIG_COMPAT
13222 +
13223 +#include <asm/compat.h>
13224 +
13225 +struct vcmd_ctx_iattr_v1_x32 {
13226 +       compat_uptr_t name_ptr;
13227 +       uint32_t tag;
13228 +       uint32_t flags;
13229 +       uint32_t mask;
13230 +};
13231 +
13232 +#endif /* CONFIG_COMPAT */
13233 +
13234 +#include <linux/compiler.h>
13235 +
13236 +extern int vc_get_iattr(void __user *);
13237 +extern int vc_set_iattr(void __user *);
13238 +
13239 +extern int vc_fget_iattr(uint32_t, void __user *);
13240 +extern int vc_fset_iattr(uint32_t, void __user *);
13241 +
13242 +#ifdef CONFIG_COMPAT
13243 +
13244 +extern int vc_get_iattr_x32(void __user *);
13245 +extern int vc_set_iattr_x32(void __user *);
13246 +
13247 +#endif /* CONFIG_COMPAT */
13248 +
13249 +#endif /* __KERNEL__ */
13250 +#endif /* _VX_INODE_CMD_H */
13251 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/limit.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/limit.h
13252 --- linux-2.6.32.56/include/linux/vserver/limit.h       1970-01-01 01:00:00.000000000 +0100
13253 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/limit.h       2011-06-10 13:03:02.000000000 +0200
13254 @@ -0,0 +1,71 @@
13255 +#ifndef _VX_LIMIT_H
13256 +#define _VX_LIMIT_H
13257 +
13258 +#define VLIMIT_NSOCK   16
13259 +#define VLIMIT_OPENFD  17
13260 +#define VLIMIT_ANON    18
13261 +#define VLIMIT_SHMEM   19
13262 +#define VLIMIT_SEMARY  20
13263 +#define VLIMIT_NSEMS   21
13264 +#define VLIMIT_DENTRY  22
13265 +#define VLIMIT_MAPPED  23
13266 +
13267 +
13268 +#ifdef __KERNEL__
13269 +
13270 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
13271 +
13272 +/*     keep in sync with CRLIM_INFINITY */
13273 +
13274 +#define        VLIM_INFINITY   (~0ULL)
13275 +
13276 +#include <asm/atomic.h>
13277 +#include <asm/resource.h>
13278 +
13279 +#ifndef RLIM_INFINITY
13280 +#warning RLIM_INFINITY is undefined
13281 +#endif
13282 +
13283 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
13284 +
13285 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
13286 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
13287 +
13288 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
13289 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
13290 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
13291 +
13292 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
13293 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
13294 +
13295 +typedef atomic_long_t rlim_atomic_t;
13296 +typedef unsigned long rlim_t;
13297 +
13298 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
13299 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
13300 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
13301 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
13302 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
13303 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
13304 +
13305 +
13306 +#if    (RLIM_INFINITY == VLIM_INFINITY)
13307 +#define        VX_VLIM(r) ((long long)(long)(r))
13308 +#define        VX_RLIM(v) ((rlim_t)(v))
13309 +#else
13310 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
13311 +               ? VLIM_INFINITY : (long long)(r))
13312 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
13313 +               ? RLIM_INFINITY : (rlim_t)(v))
13314 +#endif
13315 +
13316 +struct sysinfo;
13317 +
13318 +void vx_vsi_meminfo(struct sysinfo *);
13319 +void vx_vsi_swapinfo(struct sysinfo *);
13320 +long vx_vsi_cached(struct sysinfo *);
13321 +
13322 +#define NUM_LIMITS     24
13323 +
13324 +#endif /* __KERNEL__ */
13325 +#endif /* _VX_LIMIT_H */
13326 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/limit_cmd.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/limit_cmd.h
13327 --- linux-2.6.32.56/include/linux/vserver/limit_cmd.h   1970-01-01 01:00:00.000000000 +0100
13328 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/limit_cmd.h   2011-06-10 13:03:02.000000000 +0200
13329 @@ -0,0 +1,71 @@
13330 +#ifndef _VX_LIMIT_CMD_H
13331 +#define _VX_LIMIT_CMD_H
13332 +
13333 +
13334 +/*  rlimit vserver commands */
13335 +
13336 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
13337 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
13338 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
13339 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
13340 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
13341 +
13342 +struct vcmd_ctx_rlimit_v0 {
13343 +       uint32_t id;
13344 +       uint64_t minimum;
13345 +       uint64_t softlimit;
13346 +       uint64_t maximum;
13347 +};
13348 +
13349 +struct vcmd_ctx_rlimit_mask_v0 {
13350 +       uint32_t minimum;
13351 +       uint32_t softlimit;
13352 +       uint32_t maximum;
13353 +};
13354 +
13355 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
13356 +
13357 +struct vcmd_rlimit_stat_v0 {
13358 +       uint32_t id;
13359 +       uint32_t hits;
13360 +       uint64_t value;
13361 +       uint64_t minimum;
13362 +       uint64_t maximum;
13363 +};
13364 +
13365 +#define CRLIM_UNSET            (0ULL)
13366 +#define CRLIM_INFINITY         (~0ULL)
13367 +#define CRLIM_KEEP             (~1ULL)
13368 +
13369 +#ifdef __KERNEL__
13370 +
13371 +#ifdef CONFIG_IA32_EMULATION
13372 +
13373 +struct vcmd_ctx_rlimit_v0_x32 {
13374 +       uint32_t id;
13375 +       uint64_t minimum;
13376 +       uint64_t softlimit;
13377 +       uint64_t maximum;
13378 +} __attribute__ ((packed));
13379 +
13380 +#endif /* CONFIG_IA32_EMULATION */
13381 +
13382 +#include <linux/compiler.h>
13383 +
13384 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
13385 +extern int vc_get_rlimit(struct vx_info *, void __user *);
13386 +extern int vc_set_rlimit(struct vx_info *, void __user *);
13387 +extern int vc_reset_hits(struct vx_info *, void __user *);
13388 +extern int vc_reset_minmax(struct vx_info *, void __user *);
13389 +
13390 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
13391 +
13392 +#ifdef CONFIG_IA32_EMULATION
13393 +
13394 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
13395 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
13396 +
13397 +#endif /* CONFIG_IA32_EMULATION */
13398 +
13399 +#endif /* __KERNEL__ */
13400 +#endif /* _VX_LIMIT_CMD_H */
13401 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/limit_def.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/limit_def.h
13402 --- linux-2.6.32.56/include/linux/vserver/limit_def.h   1970-01-01 01:00:00.000000000 +0100
13403 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/limit_def.h   2011-06-10 13:03:02.000000000 +0200
13404 @@ -0,0 +1,47 @@
13405 +#ifndef _VX_LIMIT_DEF_H
13406 +#define _VX_LIMIT_DEF_H
13407 +
13408 +#include <asm/atomic.h>
13409 +#include <asm/resource.h>
13410 +
13411 +#include "limit.h"
13412 +
13413 +
13414 +struct _vx_res_limit {
13415 +       rlim_t soft;            /* Context soft limit */
13416 +       rlim_t hard;            /* Context hard limit */
13417 +
13418 +       rlim_atomic_t rcur;     /* Current value */
13419 +       rlim_t rmin;            /* Context minimum */
13420 +       rlim_t rmax;            /* Context maximum */
13421 +
13422 +       atomic_t lhit;          /* Limit hits */
13423 +};
13424 +
13425 +/* context sub struct */
13426 +
13427 +struct _vx_limit {
13428 +       struct _vx_res_limit res[NUM_LIMITS];
13429 +};
13430 +
13431 +#ifdef CONFIG_VSERVER_DEBUG
13432 +
13433 +static inline void __dump_vx_limit(struct _vx_limit *limit)
13434 +{
13435 +       int i;
13436 +
13437 +       printk("\t_vx_limit:");
13438 +       for (i = 0; i < NUM_LIMITS; i++) {
13439 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
13440 +                       i, (unsigned long)__rlim_get(limit, i),
13441 +                       (unsigned long)__rlim_rmin(limit, i),
13442 +                       (unsigned long)__rlim_rmax(limit, i),
13443 +                       (long)__rlim_soft(limit, i),
13444 +                       (long)__rlim_hard(limit, i),
13445 +                       atomic_read(&__rlim_lhit(limit, i)));
13446 +       }
13447 +}
13448 +
13449 +#endif
13450 +
13451 +#endif /* _VX_LIMIT_DEF_H */
13452 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/limit_int.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/limit_int.h
13453 --- linux-2.6.32.56/include/linux/vserver/limit_int.h   1970-01-01 01:00:00.000000000 +0100
13454 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/limit_int.h   2011-06-10 13:03:02.000000000 +0200
13455 @@ -0,0 +1,198 @@
13456 +#ifndef _VX_LIMIT_INT_H
13457 +#define _VX_LIMIT_INT_H
13458 +
13459 +#include "context.h"
13460 +
13461 +#ifdef __KERNEL__
13462 +
13463 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
13464 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
13465 +
13466 +extern const char *vlimit_name[NUM_LIMITS];
13467 +
13468 +static inline void __vx_acc_cres(struct vx_info *vxi,
13469 +       int res, int dir, void *_data, char *_file, int _line)
13470 +{
13471 +       if (VXD_RCRES_COND(res))
13472 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
13473 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
13474 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
13475 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
13476 +       if (!vxi)
13477 +               return;
13478 +
13479 +       if (dir > 0)
13480 +               __rlim_inc(&vxi->limit, res);
13481 +       else
13482 +               __rlim_dec(&vxi->limit, res);
13483 +}
13484 +
13485 +static inline void __vx_add_cres(struct vx_info *vxi,
13486 +       int res, int amount, void *_data, char *_file, int _line)
13487 +{
13488 +       if (VXD_RCRES_COND(res))
13489 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
13490 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
13491 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
13492 +                       amount, _data, _file, _line);
13493 +       if (amount == 0)
13494 +               return;
13495 +       if (!vxi)
13496 +               return;
13497 +       __rlim_add(&vxi->limit, res, amount);
13498 +}
13499 +
13500 +static inline
13501 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
13502 +{
13503 +       int cond = (value > __rlim_rmax(limit, res));
13504 +
13505 +       if (cond)
13506 +               __rlim_rmax(limit, res) = value;
13507 +       return cond;
13508 +}
13509 +
13510 +static inline
13511 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
13512 +{
13513 +       int cond = (value < __rlim_rmin(limit, res));
13514 +
13515 +       if (cond)
13516 +               __rlim_rmin(limit, res) = value;
13517 +       return cond;
13518 +}
13519 +
13520 +static inline
13521 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
13522 +{
13523 +       if (!__vx_cres_adjust_max(limit, res, value))
13524 +               __vx_cres_adjust_min(limit, res, value);
13525 +}
13526 +
13527 +
13528 +/*     return values:
13529 +        +1 ... no limit hit
13530 +        -1 ... over soft limit
13531 +         0 ... over hard limit         */
13532 +
13533 +static inline int __vx_cres_avail(struct vx_info *vxi,
13534 +       int res, int num, char *_file, int _line)
13535 +{
13536 +       struct _vx_limit *limit;
13537 +       rlim_t value;
13538 +
13539 +       if (VXD_RLIMIT_COND(res))
13540 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
13541 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
13542 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
13543 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
13544 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
13545 +                       num, _file, _line);
13546 +       if (!vxi)
13547 +               return 1;
13548 +
13549 +       limit = &vxi->limit;
13550 +       value = __rlim_get(limit, res);
13551 +
13552 +       if (!__vx_cres_adjust_max(limit, res, value))
13553 +               __vx_cres_adjust_min(limit, res, value);
13554 +
13555 +       if (num == 0)
13556 +               return 1;
13557 +
13558 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
13559 +               return -1;
13560 +       if (value + num <= __rlim_soft(limit, res))
13561 +               return -1;
13562 +
13563 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
13564 +               return 1;
13565 +       if (value + num <= __rlim_hard(limit, res))
13566 +               return 1;
13567 +
13568 +       __rlim_hit(limit, res);
13569 +       return 0;
13570 +}
13571 +
13572 +
13573 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
13574 +
13575 +static inline
13576 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
13577 +{
13578 +       rlim_t value, sum = 0;
13579 +       int res;
13580 +
13581 +       while ((res = *array++)) {
13582 +               value = __rlim_get(limit, res);
13583 +               __vx_cres_fixup(limit, res, value);
13584 +               sum += value;
13585 +       }
13586 +       return sum;
13587 +}
13588 +
13589 +static inline
13590 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
13591 +{
13592 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
13593 +       int res = *array;
13594 +
13595 +       if (value == __rlim_get(limit, res))
13596 +               return value;
13597 +
13598 +       __rlim_set(limit, res, value);
13599 +       /* now adjust min/max */
13600 +       if (!__vx_cres_adjust_max(limit, res, value))
13601 +               __vx_cres_adjust_min(limit, res, value);
13602 +
13603 +       return value;
13604 +}
13605 +
13606 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
13607 +       const int *array, int num, char *_file, int _line)
13608 +{
13609 +       struct _vx_limit *limit;
13610 +       rlim_t value = 0;
13611 +       int res;
13612 +
13613 +       if (num == 0)
13614 +               return 1;
13615 +       if (!vxi)
13616 +               return 1;
13617 +
13618 +       limit = &vxi->limit;
13619 +       res = *array;
13620 +       value = __vx_cres_array_sum(limit, array + 1);
13621 +
13622 +       __rlim_set(limit, res, value);
13623 +       __vx_cres_fixup(limit, res, value);
13624 +
13625 +       return __vx_cres_avail(vxi, res, num, _file, _line);
13626 +}
13627 +
13628 +
13629 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
13630 +{
13631 +       rlim_t value;
13632 +       int res;
13633 +
13634 +       /* complex resources first */
13635 +       if ((id < 0) || (id == RLIMIT_RSS))
13636 +               __vx_cres_array_fixup(limit, VLA_RSS);
13637 +
13638 +       for (res = 0; res < NUM_LIMITS; res++) {
13639 +               if ((id > 0) && (res != id))
13640 +                       continue;
13641 +
13642 +               value = __rlim_get(limit, res);
13643 +               __vx_cres_fixup(limit, res, value);
13644 +
13645 +               /* not supposed to happen, maybe warn? */
13646 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
13647 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
13648 +       }
13649 +}
13650 +
13651 +
13652 +#endif /* __KERNEL__ */
13653 +#endif /* _VX_LIMIT_INT_H */
13654 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/monitor.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/monitor.h
13655 --- linux-2.6.32.56/include/linux/vserver/monitor.h     1970-01-01 01:00:00.000000000 +0100
13656 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/monitor.h     2011-06-10 13:03:02.000000000 +0200
13657 @@ -0,0 +1,96 @@
13658 +#ifndef _VX_MONITOR_H
13659 +#define _VX_MONITOR_H
13660 +
13661 +#include <linux/types.h>
13662 +
13663 +enum {
13664 +       VXM_UNUSED = 0,
13665 +
13666 +       VXM_SYNC = 0x10,
13667 +
13668 +       VXM_UPDATE = 0x20,
13669 +       VXM_UPDATE_1,
13670 +       VXM_UPDATE_2,
13671 +
13672 +       VXM_RQINFO_1 = 0x24,
13673 +       VXM_RQINFO_2,
13674 +
13675 +       VXM_ACTIVATE = 0x40,
13676 +       VXM_DEACTIVATE,
13677 +       VXM_IDLE,
13678 +
13679 +       VXM_HOLD = 0x44,
13680 +       VXM_UNHOLD,
13681 +
13682 +       VXM_MIGRATE = 0x48,
13683 +       VXM_RESCHED,
13684 +
13685 +       /* all other bits are flags */
13686 +       VXM_SCHED = 0x80,
13687 +};
13688 +
13689 +struct _vxm_update_1 {
13690 +       uint32_t tokens_max;
13691 +       uint32_t fill_rate;
13692 +       uint32_t interval;
13693 +};
13694 +
13695 +struct _vxm_update_2 {
13696 +       uint32_t tokens_min;
13697 +       uint32_t fill_rate;
13698 +       uint32_t interval;
13699 +};
13700 +
13701 +struct _vxm_rqinfo_1 {
13702 +       uint16_t running;
13703 +       uint16_t onhold;
13704 +       uint16_t iowait;
13705 +       uint16_t uintr;
13706 +       uint32_t idle_tokens;
13707 +};
13708 +
13709 +struct _vxm_rqinfo_2 {
13710 +       uint32_t norm_time;
13711 +       uint32_t idle_time;
13712 +       uint32_t idle_skip;
13713 +};
13714 +
13715 +struct _vxm_sched {
13716 +       uint32_t tokens;
13717 +       uint32_t norm_time;
13718 +       uint32_t idle_time;
13719 +};
13720 +
13721 +struct _vxm_task {
13722 +       uint16_t pid;
13723 +       uint16_t state;
13724 +};
13725 +
13726 +struct _vxm_event {
13727 +       uint32_t jif;
13728 +       union {
13729 +               uint32_t seq;
13730 +               uint32_t sec;
13731 +       };
13732 +       union {
13733 +               uint32_t tokens;
13734 +               uint32_t nsec;
13735 +               struct _vxm_task tsk;
13736 +       };
13737 +};
13738 +
13739 +struct _vx_mon_entry {
13740 +       uint16_t type;
13741 +       uint16_t xid;
13742 +       union {
13743 +               struct _vxm_event ev;
13744 +               struct _vxm_sched sd;
13745 +               struct _vxm_update_1 u1;
13746 +               struct _vxm_update_2 u2;
13747 +               struct _vxm_rqinfo_1 q1;
13748 +               struct _vxm_rqinfo_2 q2;
13749 +       };
13750 +};
13751 +
13752 +
13753 +#endif /* _VX_MONITOR_H */
13754 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/network.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/network.h
13755 --- linux-2.6.32.56/include/linux/vserver/network.h     1970-01-01 01:00:00.000000000 +0100
13756 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/network.h     2011-06-10 13:03:02.000000000 +0200
13757 @@ -0,0 +1,146 @@
13758 +#ifndef _VX_NETWORK_H
13759 +#define _VX_NETWORK_H
13760 +
13761 +#include <linux/types.h>
13762 +
13763 +
13764 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
13765 +
13766 +
13767 +/* network flags */
13768 +
13769 +#define NXF_INFO_PRIVATE       0x00000008
13770 +
13771 +#define NXF_SINGLE_IP          0x00000100
13772 +#define NXF_LBACK_REMAP                0x00000200
13773 +#define NXF_LBACK_ALLOW                0x00000400
13774 +
13775 +#define NXF_HIDE_NETIF         0x02000000
13776 +#define NXF_HIDE_LBACK         0x04000000
13777 +
13778 +#define NXF_STATE_SETUP                (1ULL << 32)
13779 +#define NXF_STATE_ADMIN                (1ULL << 34)
13780 +
13781 +#define NXF_SC_HELPER          (1ULL << 36)
13782 +#define NXF_PERSISTENT         (1ULL << 38)
13783 +
13784 +#define NXF_ONE_TIME           (0x0005ULL << 32)
13785 +
13786 +
13787 +#define        NXF_INIT_SET            (__nxf_init_set())
13788 +
13789 +static inline uint64_t __nxf_init_set(void) {
13790 +       return    NXF_STATE_ADMIN
13791 +#ifdef CONFIG_VSERVER_AUTO_LBACK
13792 +               | NXF_LBACK_REMAP
13793 +               | NXF_HIDE_LBACK
13794 +#endif
13795 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
13796 +               | NXF_SINGLE_IP
13797 +#endif
13798 +               | NXF_HIDE_NETIF;
13799 +}
13800 +
13801 +
13802 +/* network caps */
13803 +
13804 +#define NXC_TUN_CREATE         0x00000001
13805 +
13806 +#define NXC_RAW_ICMP           0x00000100
13807 +
13808 +
13809 +/* address types */
13810 +
13811 +#define NXA_TYPE_IPV4          0x0001
13812 +#define NXA_TYPE_IPV6          0x0002
13813 +
13814 +#define NXA_TYPE_NONE          0x0000
13815 +#define NXA_TYPE_ANY           0x00FF
13816 +
13817 +#define NXA_TYPE_ADDR          0x0010
13818 +#define NXA_TYPE_MASK          0x0020
13819 +#define NXA_TYPE_RANGE         0x0040
13820 +
13821 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
13822 +
13823 +#define NXA_MOD_BCAST          0x0100
13824 +#define NXA_MOD_LBACK          0x0200
13825 +
13826 +#define NXA_LOOPBACK           0x1000
13827 +
13828 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
13829 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
13830 +
13831 +#ifdef __KERNEL__
13832 +
13833 +#include <linux/list.h>
13834 +#include <linux/spinlock.h>
13835 +#include <linux/rcupdate.h>
13836 +#include <linux/in.h>
13837 +#include <linux/in6.h>
13838 +#include <asm/atomic.h>
13839 +
13840 +struct nx_addr_v4 {
13841 +       struct nx_addr_v4 *next;
13842 +       struct in_addr ip[2];
13843 +       struct in_addr mask;
13844 +       uint16_t type;
13845 +       uint16_t flags;
13846 +};
13847 +
13848 +struct nx_addr_v6 {
13849 +       struct nx_addr_v6 *next;
13850 +       struct in6_addr ip;
13851 +       struct in6_addr mask;
13852 +       uint32_t prefix;
13853 +       uint16_t type;
13854 +       uint16_t flags;
13855 +};
13856 +
13857 +struct nx_info {
13858 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
13859 +       nid_t nx_id;                    /* vnet id */
13860 +       atomic_t nx_usecnt;             /* usage count */
13861 +       atomic_t nx_tasks;              /* tasks count */
13862 +       int nx_state;                   /* context state */
13863 +
13864 +       uint64_t nx_flags;              /* network flag word */
13865 +       uint64_t nx_ncaps;              /* network capabilities */
13866 +
13867 +       struct in_addr v4_lback;        /* Loopback address */
13868 +       struct in_addr v4_bcast;        /* Broadcast address */
13869 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
13870 +#ifdef CONFIG_IPV6
13871 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
13872 +#endif
13873 +       char nx_name[65];               /* network context name */
13874 +};
13875 +
13876 +
13877 +/* status flags */
13878 +
13879 +#define NXS_HASHED      0x0001
13880 +#define NXS_SHUTDOWN    0x0100
13881 +#define NXS_RELEASED    0x8000
13882 +
13883 +extern struct nx_info *lookup_nx_info(int);
13884 +
13885 +extern int get_nid_list(int, unsigned int *, int);
13886 +extern int nid_is_hashed(nid_t);
13887 +
13888 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
13889 +
13890 +extern long vs_net_change(struct nx_info *, unsigned int);
13891 +
13892 +struct sock;
13893 +
13894 +
13895 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
13896 +#ifdef  CONFIG_IPV6
13897 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
13898 +#else
13899 +#define NX_IPV6(n)     (0)
13900 +#endif
13901 +
13902 +#endif /* __KERNEL__ */
13903 +#endif /* _VX_NETWORK_H */
13904 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/network_cmd.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/network_cmd.h
13905 --- linux-2.6.32.56/include/linux/vserver/network_cmd.h 1970-01-01 01:00:00.000000000 +0100
13906 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/network_cmd.h 2011-06-10 13:03:02.000000000 +0200
13907 @@ -0,0 +1,150 @@
13908 +#ifndef _VX_NETWORK_CMD_H
13909 +#define _VX_NETWORK_CMD_H
13910 +
13911 +
13912 +/* vinfo commands */
13913 +
13914 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
13915 +
13916 +#ifdef __KERNEL__
13917 +extern int vc_task_nid(uint32_t);
13918 +
13919 +#endif /* __KERNEL__ */
13920 +
13921 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
13922 +
13923 +struct vcmd_nx_info_v0 {
13924 +       uint32_t nid;
13925 +       /* more to come */
13926 +};
13927 +
13928 +#ifdef __KERNEL__
13929 +extern int vc_nx_info(struct nx_info *, void __user *);
13930 +
13931 +#endif /* __KERNEL__ */
13932 +
13933 +#include <linux/in.h>
13934 +#include <linux/in6.h>
13935 +
13936 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
13937 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
13938 +
13939 +struct  vcmd_net_create {
13940 +       uint64_t flagword;
13941 +};
13942 +
13943 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
13944 +
13945 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
13946 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
13947 +
13948 +struct vcmd_net_addr_v0 {
13949 +       uint16_t type;
13950 +       uint16_t count;
13951 +       struct in_addr ip[4];
13952 +       struct in_addr mask[4];
13953 +};
13954 +
13955 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 1)
13956 +#define VCMD_net_remove_ipv4   VC_CMD(NETALT, 2, 1)
13957 +
13958 +struct vcmd_net_addr_ipv4_v1 {
13959 +       uint16_t type;
13960 +       uint16_t flags;
13961 +       struct in_addr ip;
13962 +       struct in_addr mask;
13963 +};
13964 +
13965 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
13966 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
13967 +
13968 +struct vcmd_net_addr_ipv6_v1 {
13969 +       uint16_t type;
13970 +       uint16_t flags;
13971 +       uint32_t prefix;
13972 +       struct in6_addr ip;
13973 +       struct in6_addr mask;
13974 +};
13975 +
13976 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
13977 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
13978 +
13979 +struct vcmd_match_ipv4_v0 {
13980 +       uint16_t type;
13981 +       uint16_t flags;
13982 +       uint16_t parent;
13983 +       uint16_t prefix;
13984 +       struct in_addr ip;
13985 +       struct in_addr ip2;
13986 +       struct in_addr mask;
13987 +};
13988 +
13989 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
13990 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
13991 +
13992 +struct vcmd_match_ipv6_v0 {
13993 +       uint16_t type;
13994 +       uint16_t flags;
13995 +       uint16_t parent;
13996 +       uint16_t prefix;
13997 +       struct in6_addr ip;
13998 +       struct in6_addr ip2;
13999 +       struct in6_addr mask;
14000 +};
14001 +
14002 +
14003 +#ifdef __KERNEL__
14004 +extern int vc_net_create(uint32_t, void __user *);
14005 +extern int vc_net_migrate(struct nx_info *, void __user *);
14006 +
14007 +extern int vc_net_add(struct nx_info *, void __user *);
14008 +extern int vc_net_remove(struct nx_info *, void __user *);
14009 +
14010 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
14011 +extern int vc_net_remove_ipv4(struct nx_info *, void __user *);
14012 +
14013 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
14014 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
14015 +
14016 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
14017 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
14018 +
14019 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
14020 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
14021 +
14022 +#endif /* __KERNEL__ */
14023 +
14024 +
14025 +/* flag commands */
14026 +
14027 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
14028 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
14029 +
14030 +struct vcmd_net_flags_v0 {
14031 +       uint64_t flagword;
14032 +       uint64_t mask;
14033 +};
14034 +
14035 +#ifdef __KERNEL__
14036 +extern int vc_get_nflags(struct nx_info *, void __user *);
14037 +extern int vc_set_nflags(struct nx_info *, void __user *);
14038 +
14039 +#endif /* __KERNEL__ */
14040 +
14041 +
14042 +/* network caps commands */
14043 +
14044 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
14045 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
14046 +
14047 +struct vcmd_net_caps_v0 {
14048 +       uint64_t ncaps;
14049 +       uint64_t cmask;
14050 +};
14051 +
14052 +#ifdef __KERNEL__
14053 +extern int vc_get_ncaps(struct nx_info *, void __user *);
14054 +extern int vc_set_ncaps(struct nx_info *, void __user *);
14055 +
14056 +#endif /* __KERNEL__ */
14057 +#endif /* _VX_CONTEXT_CMD_H */
14058 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/percpu.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/percpu.h
14059 --- linux-2.6.32.56/include/linux/vserver/percpu.h      1970-01-01 01:00:00.000000000 +0100
14060 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/percpu.h      2011-06-10 13:03:02.000000000 +0200
14061 @@ -0,0 +1,14 @@
14062 +#ifndef _VX_PERCPU_H
14063 +#define _VX_PERCPU_H
14064 +
14065 +#include "cvirt_def.h"
14066 +#include "sched_def.h"
14067 +
14068 +struct _vx_percpu {
14069 +       struct _vx_cvirt_pc cvirt;
14070 +       struct _vx_sched_pc sched;
14071 +};
14072 +
14073 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
14074 +
14075 +#endif /* _VX_PERCPU_H */
14076 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/pid.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/pid.h
14077 --- linux-2.6.32.56/include/linux/vserver/pid.h 1970-01-01 01:00:00.000000000 +0100
14078 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/pid.h 2011-06-10 13:03:02.000000000 +0200
14079 @@ -0,0 +1,51 @@
14080 +#ifndef _VSERVER_PID_H
14081 +#define _VSERVER_PID_H
14082 +
14083 +/* pid faking stuff */
14084 +
14085 +#define vx_info_map_pid(v, p) \
14086 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
14087 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
14088 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
14089 +#define vx_map_tgid(p) vx_map_pid(p)
14090 +
14091 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
14092 +       const char *func, const char *file, int line)
14093 +{
14094 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
14095 +               vxfprintk(VXD_CBIT(cvirt, 2),
14096 +                       "vx_map_tgid: %p/%llx: %d -> %d",
14097 +                       vxi, (long long)vxi->vx_flags, pid,
14098 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
14099 +                       func, file, line);
14100 +               if (pid == 0)
14101 +                       return 0;
14102 +               if (pid == vxi->vx_initpid)
14103 +                       return 1;
14104 +       }
14105 +       return pid;
14106 +}
14107 +
14108 +#define vx_info_rmap_pid(v, p) \
14109 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
14110 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
14111 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
14112 +
14113 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
14114 +       const char *func, const char *file, int line)
14115 +{
14116 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
14117 +               vxfprintk(VXD_CBIT(cvirt, 2),
14118 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
14119 +                       vxi, (long long)vxi->vx_flags, pid,
14120 +                       (pid == 1) ? vxi->vx_initpid : pid,
14121 +                       func, file, line);
14122 +               if ((pid == 1) && vxi->vx_initpid)
14123 +                       return vxi->vx_initpid;
14124 +               if (pid == vxi->vx_initpid)
14125 +                       return ~0U;
14126 +       }
14127 +       return pid;
14128 +}
14129 +
14130 +#endif
14131 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/sched.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/sched.h
14132 --- linux-2.6.32.56/include/linux/vserver/sched.h       1970-01-01 01:00:00.000000000 +0100
14133 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/sched.h       2011-06-10 13:03:02.000000000 +0200
14134 @@ -0,0 +1,26 @@
14135 +#ifndef _VX_SCHED_H
14136 +#define _VX_SCHED_H
14137 +
14138 +
14139 +#ifdef __KERNEL__
14140 +
14141 +struct timespec;
14142 +
14143 +void vx_vsi_uptime(struct timespec *, struct timespec *);
14144 +
14145 +
14146 +struct vx_info;
14147 +
14148 +void vx_update_load(struct vx_info *);
14149 +
14150 +
14151 +int vx_tokens_recalc(struct _vx_sched_pc *,
14152 +       unsigned long *, unsigned long *, int [2]);
14153 +
14154 +void vx_update_sched_param(struct _vx_sched *sched,
14155 +       struct _vx_sched_pc *sched_pc);
14156 +
14157 +#endif /* __KERNEL__ */
14158 +#else  /* _VX_SCHED_H */
14159 +#warning duplicate inclusion
14160 +#endif /* _VX_SCHED_H */
14161 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/sched_cmd.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/sched_cmd.h
14162 --- linux-2.6.32.56/include/linux/vserver/sched_cmd.h   1970-01-01 01:00:00.000000000 +0100
14163 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/sched_cmd.h   2011-06-10 13:03:02.000000000 +0200
14164 @@ -0,0 +1,108 @@
14165 +#ifndef _VX_SCHED_CMD_H
14166 +#define _VX_SCHED_CMD_H
14167 +
14168 +
14169 +/*  sched vserver commands */
14170 +
14171 +#define VCMD_set_sched_v2      VC_CMD(SCHED, 1, 2)
14172 +#define VCMD_set_sched_v3      VC_CMD(SCHED, 1, 3)
14173 +#define VCMD_set_sched_v4      VC_CMD(SCHED, 1, 4)
14174 +
14175 +struct vcmd_set_sched_v2 {
14176 +       int32_t fill_rate;
14177 +       int32_t interval;
14178 +       int32_t tokens;
14179 +       int32_t tokens_min;
14180 +       int32_t tokens_max;
14181 +       uint64_t cpu_mask;
14182 +};
14183 +
14184 +struct vcmd_set_sched_v3 {
14185 +       uint32_t set_mask;
14186 +       int32_t fill_rate;
14187 +       int32_t interval;
14188 +       int32_t tokens;
14189 +       int32_t tokens_min;
14190 +       int32_t tokens_max;
14191 +       int32_t priority_bias;
14192 +};
14193 +
14194 +struct vcmd_set_sched_v4 {
14195 +       uint32_t set_mask;
14196 +       int32_t fill_rate;
14197 +       int32_t interval;
14198 +       int32_t tokens;
14199 +       int32_t tokens_min;
14200 +       int32_t tokens_max;
14201 +       int32_t prio_bias;
14202 +       int32_t cpu_id;
14203 +       int32_t bucket_id;
14204 +};
14205 +
14206 +#define VCMD_set_sched         VC_CMD(SCHED, 1, 5)
14207 +#define VCMD_get_sched         VC_CMD(SCHED, 2, 5)
14208 +
14209 +struct vcmd_sched_v5 {
14210 +       uint32_t mask;
14211 +       int32_t cpu_id;
14212 +       int32_t bucket_id;
14213 +       int32_t fill_rate[2];
14214 +       int32_t interval[2];
14215 +       int32_t tokens;
14216 +       int32_t tokens_min;
14217 +       int32_t tokens_max;
14218 +       int32_t prio_bias;
14219 +};
14220 +
14221 +#define VXSM_FILL_RATE         0x0001
14222 +#define VXSM_INTERVAL          0x0002
14223 +#define VXSM_FILL_RATE2                0x0004
14224 +#define VXSM_INTERVAL2         0x0008
14225 +#define VXSM_TOKENS            0x0010
14226 +#define VXSM_TOKENS_MIN                0x0020
14227 +#define VXSM_TOKENS_MAX                0x0040
14228 +#define VXSM_PRIO_BIAS         0x0100
14229 +
14230 +#define VXSM_IDLE_TIME         0x0200
14231 +#define VXSM_FORCE             0x0400
14232 +
14233 +#define        VXSM_V3_MASK            0x0173
14234 +#define        VXSM_SET_MASK           0x01FF
14235 +
14236 +#define VXSM_CPU_ID            0x1000
14237 +#define VXSM_BUCKET_ID         0x2000
14238 +
14239 +#define VXSM_MSEC              0x4000
14240 +
14241 +#define SCHED_KEEP             (-2)    /* only for v2 */
14242 +
14243 +#ifdef __KERNEL__
14244 +
14245 +#include <linux/compiler.h>
14246 +
14247 +extern int vc_set_sched_v2(struct vx_info *, void __user *);
14248 +extern int vc_set_sched_v3(struct vx_info *, void __user *);
14249 +extern int vc_set_sched_v4(struct vx_info *, void __user *);
14250 +extern int vc_set_sched(struct vx_info *, void __user *);
14251 +extern int vc_get_sched(struct vx_info *, void __user *);
14252 +
14253 +#endif /* __KERNEL__ */
14254 +
14255 +#define VCMD_sched_info                VC_CMD(SCHED, 3, 0)
14256 +
14257 +struct vcmd_sched_info {
14258 +       int32_t cpu_id;
14259 +       int32_t bucket_id;
14260 +       uint64_t user_msec;
14261 +       uint64_t sys_msec;
14262 +       uint64_t hold_msec;
14263 +       uint32_t token_usec;
14264 +       int32_t vavavoom;
14265 +};
14266 +
14267 +#ifdef __KERNEL__
14268 +
14269 +extern int vc_sched_info(struct vx_info *, void __user *);
14270 +
14271 +#endif /* __KERNEL__ */
14272 +#endif /* _VX_SCHED_CMD_H */
14273 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/sched_def.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/sched_def.h
14274 --- linux-2.6.32.56/include/linux/vserver/sched_def.h   1970-01-01 01:00:00.000000000 +0100
14275 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/sched_def.h   2011-06-10 13:03:02.000000000 +0200
14276 @@ -0,0 +1,68 @@
14277 +#ifndef _VX_SCHED_DEF_H
14278 +#define _VX_SCHED_DEF_H
14279 +
14280 +#include <linux/spinlock.h>
14281 +#include <linux/jiffies.h>
14282 +#include <linux/cpumask.h>
14283 +#include <asm/atomic.h>
14284 +#include <asm/param.h>
14285 +
14286 +
14287 +/* context sub struct */
14288 +
14289 +struct _vx_sched {
14290 +       spinlock_t tokens_lock;         /* lock for token bucket */
14291 +
14292 +       int tokens;                     /* number of CPU tokens */
14293 +       int fill_rate[2];               /* Fill rate: add X tokens... */
14294 +       int interval[2];                /* Divisor:   per Y jiffies   */
14295 +       int tokens_min;                 /* Limit:     minimum for unhold */
14296 +       int tokens_max;                 /* Limit:     no more than N tokens */
14297 +
14298 +       int prio_bias;                  /* bias offset for priority */
14299 +
14300 +       unsigned update_mask;           /* which features should be updated */
14301 +       cpumask_t update;               /* CPUs which should update */
14302 +};
14303 +
14304 +struct _vx_sched_pc {
14305 +       int tokens;                     /* number of CPU tokens */
14306 +       int flags;                      /* bucket flags */
14307 +
14308 +       int fill_rate[2];               /* Fill rate: add X tokens... */
14309 +       int interval[2];                /* Divisor:   per Y jiffies   */
14310 +       int tokens_min;                 /* Limit:     minimum for unhold */
14311 +       int tokens_max;                 /* Limit:     no more than N tokens */
14312 +
14313 +       int prio_bias;                  /* bias offset for priority */
14314 +       int vavavoom;                   /* last calculated vavavoom */
14315 +
14316 +       unsigned long norm_time;        /* last time accounted */
14317 +       unsigned long idle_time;        /* non linear time for fair sched */
14318 +       unsigned long token_time;       /* token time for accounting */
14319 +       unsigned long onhold;           /* jiffies when put on hold */
14320 +
14321 +       uint64_t user_ticks;            /* token tick events */
14322 +       uint64_t sys_ticks;             /* token tick events */
14323 +       uint64_t hold_ticks;            /* token ticks paused */
14324 +};
14325 +
14326 +
14327 +#define VXSF_ONHOLD    0x0001
14328 +#define VXSF_IDLE_TIME 0x0100
14329 +
14330 +#ifdef CONFIG_VSERVER_DEBUG
14331 +
14332 +static inline void __dump_vx_sched(struct _vx_sched *sched)
14333 +{
14334 +       printk("\t_vx_sched:\n");
14335 +       printk("\t tokens: %4d/%4d, %4d/%4d, %4d, %4d\n",
14336 +               sched->fill_rate[0], sched->interval[0],
14337 +               sched->fill_rate[1], sched->interval[1],
14338 +               sched->tokens_min, sched->tokens_max);
14339 +       printk("\t priority = %4d\n", sched->prio_bias);
14340 +}
14341 +
14342 +#endif
14343 +
14344 +#endif /* _VX_SCHED_DEF_H */
14345 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/signal.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/signal.h
14346 --- linux-2.6.32.56/include/linux/vserver/signal.h      1970-01-01 01:00:00.000000000 +0100
14347 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/signal.h      2011-06-10 13:03:02.000000000 +0200
14348 @@ -0,0 +1,14 @@
14349 +#ifndef _VX_SIGNAL_H
14350 +#define _VX_SIGNAL_H
14351 +
14352 +
14353 +#ifdef __KERNEL__
14354 +
14355 +struct vx_info;
14356 +
14357 +int vx_info_kill(struct vx_info *, int, int);
14358 +
14359 +#endif /* __KERNEL__ */
14360 +#else  /* _VX_SIGNAL_H */
14361 +#warning duplicate inclusion
14362 +#endif /* _VX_SIGNAL_H */
14363 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/signal_cmd.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/signal_cmd.h
14364 --- linux-2.6.32.56/include/linux/vserver/signal_cmd.h  1970-01-01 01:00:00.000000000 +0100
14365 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/signal_cmd.h  2011-06-10 13:03:02.000000000 +0200
14366 @@ -0,0 +1,43 @@
14367 +#ifndef _VX_SIGNAL_CMD_H
14368 +#define _VX_SIGNAL_CMD_H
14369 +
14370 +
14371 +/*  signalling vserver commands */
14372 +
14373 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
14374 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
14375 +
14376 +struct vcmd_ctx_kill_v0 {
14377 +       int32_t pid;
14378 +       int32_t sig;
14379 +};
14380 +
14381 +struct vcmd_wait_exit_v0 {
14382 +       int32_t reboot_cmd;
14383 +       int32_t exit_code;
14384 +};
14385 +
14386 +#ifdef __KERNEL__
14387 +
14388 +extern int vc_ctx_kill(struct vx_info *, void __user *);
14389 +extern int vc_wait_exit(struct vx_info *, void __user *);
14390 +
14391 +#endif /* __KERNEL__ */
14392 +
14393 +/*  process alteration commands */
14394 +
14395 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
14396 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
14397 +
14398 +struct vcmd_pflags_v0 {
14399 +       uint32_t flagword;
14400 +       uint32_t mask;
14401 +};
14402 +
14403 +#ifdef __KERNEL__
14404 +
14405 +extern int vc_get_pflags(uint32_t pid, void __user *);
14406 +extern int vc_set_pflags(uint32_t pid, void __user *);
14407 +
14408 +#endif /* __KERNEL__ */
14409 +#endif /* _VX_SIGNAL_CMD_H */
14410 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/space.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/space.h
14411 --- linux-2.6.32.56/include/linux/vserver/space.h       1970-01-01 01:00:00.000000000 +0100
14412 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/space.h       2011-06-10 13:03:02.000000000 +0200
14413 @@ -0,0 +1,12 @@
14414 +#ifndef _VX_SPACE_H
14415 +#define _VX_SPACE_H
14416 +
14417 +#include <linux/types.h>
14418 +
14419 +struct vx_info;
14420 +
14421 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
14422 +
14423 +#else  /* _VX_SPACE_H */
14424 +#warning duplicate inclusion
14425 +#endif /* _VX_SPACE_H */
14426 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/space_cmd.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/space_cmd.h
14427 --- linux-2.6.32.56/include/linux/vserver/space_cmd.h   1970-01-01 01:00:00.000000000 +0100
14428 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/space_cmd.h   2011-06-10 13:03:02.000000000 +0200
14429 @@ -0,0 +1,38 @@
14430 +#ifndef _VX_SPACE_CMD_H
14431 +#define _VX_SPACE_CMD_H
14432 +
14433 +
14434 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
14435 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
14436 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
14437 +
14438 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
14439 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
14440 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
14441 +
14442 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
14443 +
14444 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
14445 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
14446 +
14447 +
14448 +struct vcmd_space_mask_v1 {
14449 +       uint64_t mask;
14450 +};
14451 +
14452 +struct vcmd_space_mask_v2 {
14453 +       uint64_t mask;
14454 +       uint32_t index;
14455 +};
14456 +
14457 +
14458 +#ifdef __KERNEL__
14459 +
14460 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
14461 +extern int vc_set_space_v1(struct vx_info *, void __user *);
14462 +extern int vc_enter_space(struct vx_info *, void __user *);
14463 +extern int vc_set_space(struct vx_info *, void __user *);
14464 +extern int vc_get_space_mask(void __user *, int);
14465 +
14466 +#endif /* __KERNEL__ */
14467 +#endif /* _VX_SPACE_CMD_H */
14468 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/switch.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/switch.h
14469 --- linux-2.6.32.56/include/linux/vserver/switch.h      1970-01-01 01:00:00.000000000 +0100
14470 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/switch.h      2011-06-10 13:03:02.000000000 +0200
14471 @@ -0,0 +1,98 @@
14472 +#ifndef _VX_SWITCH_H
14473 +#define _VX_SWITCH_H
14474 +
14475 +#include <linux/types.h>
14476 +
14477 +
14478 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
14479 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
14480 +#define VC_VERSION(c)          ((c) & 0xFFF)
14481 +
14482 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
14483 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
14484 +
14485 +/*
14486 +
14487 +  Syscall Matrix V2.8
14488 +
14489 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
14490 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
14491 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
14492 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14493 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
14494 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
14495 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14496 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
14497 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
14498 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14499 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
14500 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
14501 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14502 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
14503 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
14504 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14505 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
14506 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
14507 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14508 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
14509 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
14510 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
14511 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
14512 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
14513 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14514 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
14515 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
14516 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
14517 +
14518 +*/
14519 +
14520 +#define VC_CAT_VERSION         0
14521 +
14522 +#define VC_CAT_VSETUP          1
14523 +#define VC_CAT_VHOST           2
14524 +
14525 +#define VC_CAT_DEVICE          6
14526 +
14527 +#define VC_CAT_VPROC           9
14528 +#define VC_CAT_PROCALT         10
14529 +#define VC_CAT_PROCMIG         11
14530 +#define VC_CAT_PROCTRL         12
14531 +
14532 +#define VC_CAT_SCHED           14
14533 +#define VC_CAT_MEMCTRL         20
14534 +
14535 +#define VC_CAT_VNET            25
14536 +#define VC_CAT_NETALT          26
14537 +#define VC_CAT_NETMIG          27
14538 +#define VC_CAT_NETCTRL         28
14539 +
14540 +#define VC_CAT_TAGMIG          35
14541 +#define VC_CAT_DLIMIT          36
14542 +#define VC_CAT_INODE           38
14543 +
14544 +#define VC_CAT_VSTAT           40
14545 +#define VC_CAT_VINFO           46
14546 +#define VC_CAT_EVENT           48
14547 +
14548 +#define VC_CAT_FLAGS           52
14549 +#define VC_CAT_VSPACE          54
14550 +#define VC_CAT_DEBUG           56
14551 +#define VC_CAT_RLIMIT          60
14552 +
14553 +#define VC_CAT_SYSTEST         61
14554 +#define VC_CAT_COMPAT          63
14555 +
14556 +/*  query version */
14557 +
14558 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
14559 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
14560 +
14561 +
14562 +#ifdef __KERNEL__
14563 +
14564 +#include <linux/errno.h>
14565 +
14566 +#endif /* __KERNEL__ */
14567 +
14568 +#endif /* _VX_SWITCH_H */
14569 +
14570 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/tag.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/tag.h
14571 --- linux-2.6.32.56/include/linux/vserver/tag.h 1970-01-01 01:00:00.000000000 +0100
14572 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/tag.h 2011-06-10 13:03:02.000000000 +0200
14573 @@ -0,0 +1,143 @@
14574 +#ifndef _DX_TAG_H
14575 +#define _DX_TAG_H
14576 +
14577 +#include <linux/types.h>
14578 +
14579 +
14580 +#define DX_TAG(in)     (IS_TAGGED(in))
14581 +
14582 +
14583 +#ifdef CONFIG_TAG_NFSD
14584 +#define DX_TAG_NFSD    1
14585 +#else
14586 +#define DX_TAG_NFSD    0
14587 +#endif
14588 +
14589 +
14590 +#ifdef CONFIG_TAGGING_NONE
14591 +
14592 +#define MAX_UID                0xFFFFFFFF
14593 +#define MAX_GID                0xFFFFFFFF
14594 +
14595 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
14596 +
14597 +#define TAGINO_UID(cond, uid, tag)     (uid)
14598 +#define TAGINO_GID(cond, gid, tag)     (gid)
14599 +
14600 +#endif
14601 +
14602 +
14603 +#ifdef CONFIG_TAGGING_GID16
14604 +
14605 +#define MAX_UID                0xFFFFFFFF
14606 +#define MAX_GID                0x0000FFFF
14607 +
14608 +#define INOTAG_TAG(cond, uid, gid, tag)        \
14609 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
14610 +
14611 +#define TAGINO_UID(cond, uid, tag)     (uid)
14612 +#define TAGINO_GID(cond, gid, tag)     \
14613 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
14614 +
14615 +#endif
14616 +
14617 +
14618 +#ifdef CONFIG_TAGGING_ID24
14619 +
14620 +#define MAX_UID                0x00FFFFFF
14621 +#define MAX_GID                0x00FFFFFF
14622 +
14623 +#define INOTAG_TAG(cond, uid, gid, tag)        \
14624 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
14625 +
14626 +#define TAGINO_UID(cond, uid, tag)     \
14627 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
14628 +#define TAGINO_GID(cond, gid, tag)     \
14629 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
14630 +
14631 +#endif
14632 +
14633 +
14634 +#ifdef CONFIG_TAGGING_UID16
14635 +
14636 +#define MAX_UID                0x0000FFFF
14637 +#define MAX_GID                0xFFFFFFFF
14638 +
14639 +#define INOTAG_TAG(cond, uid, gid, tag)        \
14640 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
14641 +
14642 +#define TAGINO_UID(cond, uid, tag)     \
14643 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
14644 +#define TAGINO_GID(cond, gid, tag)     (gid)
14645 +
14646 +#endif
14647 +
14648 +
14649 +#ifdef CONFIG_TAGGING_INTERN
14650 +
14651 +#define MAX_UID                0xFFFFFFFF
14652 +#define MAX_GID                0xFFFFFFFF
14653 +
14654 +#define INOTAG_TAG(cond, uid, gid, tag)        \
14655 +       ((cond) ? (tag) : 0)
14656 +
14657 +#define TAGINO_UID(cond, uid, tag)     (uid)
14658 +#define TAGINO_GID(cond, gid, tag)     (gid)
14659 +
14660 +#endif
14661 +
14662 +
14663 +#ifndef CONFIG_TAGGING_NONE
14664 +#define dx_current_fstag(sb)   \
14665 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
14666 +#else
14667 +#define dx_current_fstag(sb)   (0)
14668 +#endif
14669 +
14670 +#ifndef CONFIG_TAGGING_INTERN
14671 +#define TAGINO_TAG(cond, tag)  (0)
14672 +#else
14673 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
14674 +#endif
14675 +
14676 +#define INOTAG_UID(cond, uid, gid)     \
14677 +       ((cond) ? ((uid) & MAX_UID) : (uid))
14678 +#define INOTAG_GID(cond, uid, gid)     \
14679 +       ((cond) ? ((gid) & MAX_GID) : (gid))
14680 +
14681 +
14682 +static inline uid_t dx_map_uid(uid_t uid)
14683 +{
14684 +       if ((uid > MAX_UID) && (uid != -1))
14685 +               uid = -2;
14686 +       return (uid & MAX_UID);
14687 +}
14688 +
14689 +static inline gid_t dx_map_gid(gid_t gid)
14690 +{
14691 +       if ((gid > MAX_GID) && (gid != -1))
14692 +               gid = -2;
14693 +       return (gid & MAX_GID);
14694 +}
14695 +
14696 +struct peer_tag {
14697 +       int32_t xid;
14698 +       int32_t nid;
14699 +};
14700 +
14701 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
14702 +
14703 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
14704 +                unsigned long *flags);
14705 +
14706 +#ifdef CONFIG_PROPAGATE
14707 +
14708 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
14709 +
14710 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
14711 +
14712 +#else
14713 +#define dx_propagate_tag(n, i) do { } while (0)
14714 +#endif
14715 +
14716 +#endif /* _DX_TAG_H */
14717 diff -NurpP --minimal linux-2.6.32.56/include/linux/vserver/tag_cmd.h linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/tag_cmd.h
14718 --- linux-2.6.32.56/include/linux/vserver/tag_cmd.h     1970-01-01 01:00:00.000000000 +0100
14719 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/linux/vserver/tag_cmd.h     2011-06-10 13:03:02.000000000 +0200
14720 @@ -0,0 +1,22 @@
14721 +#ifndef _VX_TAG_CMD_H
14722 +#define _VX_TAG_CMD_H
14723 +
14724 +
14725 +/* vinfo commands */
14726 +
14727 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
14728 +
14729 +#ifdef __KERNEL__
14730 +extern int vc_task_tag(uint32_t);
14731 +
14732 +#endif /* __KERNEL__ */
14733 +
14734 +/* context commands */
14735 +
14736 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
14737 +
14738 +#ifdef __KERNEL__
14739 +extern int vc_tag_migrate(uint32_t);
14740 +
14741 +#endif /* __KERNEL__ */
14742 +#endif /* _VX_TAG_CMD_H */
14743 diff -NurpP --minimal linux-2.6.32.56/include/net/addrconf.h linux-2.6.32.56-vs2.3.0.36.29.9/include/net/addrconf.h
14744 --- linux-2.6.32.56/include/net/addrconf.h      2009-12-03 20:02:57.000000000 +0100
14745 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/net/addrconf.h      2011-06-10 13:03:02.000000000 +0200
14746 @@ -84,7 +84,8 @@ extern int                    ipv6_dev_get_saddr(struct n
14747                                                struct net_device *dev,
14748                                                const struct in6_addr *daddr,
14749                                                unsigned int srcprefs,
14750 -                                              struct in6_addr *saddr);
14751 +                                              struct in6_addr *saddr,
14752 +                                              struct nx_info *nxi);
14753  extern int                     ipv6_get_lladdr(struct net_device *dev,
14754                                                 struct in6_addr *addr,
14755                                                 unsigned char banned_flags);
14756 diff -NurpP --minimal linux-2.6.32.56/include/net/af_unix.h linux-2.6.32.56-vs2.3.0.36.29.9/include/net/af_unix.h
14757 --- linux-2.6.32.56/include/net/af_unix.h       2012-02-09 10:22:32.000000000 +0100
14758 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/net/af_unix.h       2011-06-10 13:03:02.000000000 +0200
14759 @@ -4,6 +4,7 @@
14760  #include <linux/socket.h>
14761  #include <linux/un.h>
14762  #include <linux/mutex.h>
14763 +#include <linux/vs_base.h>
14764  #include <net/sock.h>
14765  
14766  extern void unix_inflight(struct file *fp);
14767 diff -NurpP --minimal linux-2.6.32.56/include/net/inet_timewait_sock.h linux-2.6.32.56-vs2.3.0.36.29.9/include/net/inet_timewait_sock.h
14768 --- linux-2.6.32.56/include/net/inet_timewait_sock.h    2009-12-03 20:02:57.000000000 +0100
14769 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/net/inet_timewait_sock.h    2011-06-10 13:03:02.000000000 +0200
14770 @@ -117,6 +117,10 @@ struct inet_timewait_sock {
14771  #define tw_hash                        __tw_common.skc_hash
14772  #define tw_prot                        __tw_common.skc_prot
14773  #define tw_net                 __tw_common.skc_net
14774 +#define tw_xid                 __tw_common.skc_xid
14775 +#define tw_vx_info             __tw_common.skc_vx_info
14776 +#define tw_nid                 __tw_common.skc_nid
14777 +#define tw_nx_info             __tw_common.skc_nx_info
14778         int                     tw_timeout;
14779         volatile unsigned char  tw_substate;
14780         /* 3 bits hole, try to pack */
14781 diff -NurpP --minimal linux-2.6.32.56/include/net/route.h linux-2.6.32.56-vs2.3.0.36.29.9/include/net/route.h
14782 --- linux-2.6.32.56/include/net/route.h 2009-09-10 15:26:27.000000000 +0200
14783 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/net/route.h 2011-06-10 13:03:02.000000000 +0200
14784 @@ -135,6 +135,9 @@ static inline void ip_rt_put(struct rtab
14785                 dst_release(&rt->u.dst);
14786  }
14787  
14788 +#include <linux/vs_base.h>
14789 +#include <linux/vs_inet.h>
14790 +
14791  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
14792  
14793  extern const __u8 ip_tos2prio[16];
14794 @@ -144,6 +147,9 @@ static inline char rt_tos2priority(u8 to
14795         return ip_tos2prio[IPTOS_TOS(tos)>>1];
14796  }
14797  
14798 +extern int ip_v4_find_src(struct net *net, struct nx_info *,
14799 +       struct rtable **, struct flowi *);
14800 +
14801  static inline int ip_route_connect(struct rtable **rp, __be32 dst,
14802                                    __be32 src, u32 tos, int oif, u8 protocol,
14803                                    __be16 sport, __be16 dport, struct sock *sk,
14804 @@ -161,11 +167,24 @@ static inline int ip_route_connect(struc
14805  
14806         int err;
14807         struct net *net = sock_net(sk);
14808 +       struct nx_info *nx_info = current_nx_info();
14809  
14810         if (inet_sk(sk)->transparent)
14811                 fl.flags |= FLOWI_FLAG_ANYSRC;
14812  
14813 -       if (!dst || !src) {
14814 +       if (sk)
14815 +               nx_info = sk->sk_nx_info;
14816 +
14817 +       vxdprintk(VXD_CBIT(net, 4),
14818 +               "ip_route_connect(%p) %p,%p;%lx",
14819 +               sk, nx_info, sk->sk_socket,
14820 +               (sk->sk_socket?sk->sk_socket->flags:0));
14821 +
14822 +       err = ip_v4_find_src(net, nx_info, rp, &fl);
14823 +       if (err)
14824 +               return err;
14825 +
14826 +       if (!fl.fl4_dst || !fl.fl4_src) {
14827                 err = __ip_route_output_key(net, rp, &fl);
14828                 if (err)
14829                         return err;
14830 diff -NurpP --minimal linux-2.6.32.56/include/net/sock.h linux-2.6.32.56-vs2.3.0.36.29.9/include/net/sock.h
14831 --- linux-2.6.32.56/include/net/sock.h  2009-12-03 20:02:57.000000000 +0100
14832 +++ linux-2.6.32.56-vs2.3.0.36.29.9/include/net/sock.h  2011-06-10 13:03:02.000000000 +0200
14833 @@ -139,6 +139,10 @@ struct sock_common {
14834  #ifdef CONFIG_NET_NS
14835         struct net              *skc_net;
14836  #endif
14837 +       xid_t                   skc_xid;
14838 +       struct vx_info          *skc_vx_info;
14839 +       nid_t                   skc_nid;
14840 +       struct nx_info          *skc_nx_info;
14841  };
14842  
14843  /**
14844 @@ -225,6 +229,10 @@ struct sock {
14845  #define sk_bind_node           __sk_common.skc_bind_node
14846  #define sk_prot                        __sk_common.skc_prot
14847  #define sk_net                 __sk_common.skc_net
14848 +#define sk_xid                 __sk_common.skc_xid
14849 +#define sk_vx_info             __sk_common.skc_vx_info
14850 +#define sk_nid                 __sk_common.skc_nid
14851 +#define sk_nx_info             __sk_common.skc_nx_info
14852         kmemcheck_bitfield_begin(flags);
14853         unsigned int            sk_shutdown  : 2,
14854                                 sk_no_check  : 2,
14855 diff -NurpP --minimal linux-2.6.32.56/init/Kconfig linux-2.6.32.56-vs2.3.0.36.29.9/init/Kconfig
14856 --- linux-2.6.32.56/init/Kconfig        2012-02-09 10:22:35.000000000 +0100
14857 +++ linux-2.6.32.56-vs2.3.0.36.29.9/init/Kconfig        2011-06-10 13:03:02.000000000 +0200
14858 @@ -426,6 +426,19 @@ config LOG_BUF_SHIFT
14859  config HAVE_UNSTABLE_SCHED_CLOCK
14860         bool
14861  
14862 +config CFS_HARD_LIMITS
14863 +       bool "Hard Limits for CFS Group Scheduler"
14864 +       depends on EXPERIMENTAL
14865 +       depends on FAIR_GROUP_SCHED && CGROUP_SCHED
14866 +       default n
14867 +       help
14868 +         This option enables hard limiting of CPU time obtained by
14869 +         a fair task group. Use this if you want to throttle a group of tasks
14870 +         based on its CPU usage. For more details refer to
14871 +         Documentation/scheduler/sched-cfs-hard-limits.txt
14872 +
14873 +         Say N if unsure.
14874 +
14875  menuconfig CGROUPS
14876         boolean "Control Group support"
14877         help
14878 diff -NurpP --minimal linux-2.6.32.56/init/main.c linux-2.6.32.56-vs2.3.0.36.29.9/init/main.c
14879 --- linux-2.6.32.56/init/main.c 2012-02-09 10:22:35.000000000 +0100
14880 +++ linux-2.6.32.56-vs2.3.0.36.29.9/init/main.c 2011-06-10 13:03:02.000000000 +0200
14881 @@ -70,6 +70,7 @@
14882  #include <linux/sfi.h>
14883  #include <linux/shmem_fs.h>
14884  #include <trace/boot.h>
14885 +#include <linux/vserver/percpu.h>
14886  
14887  #include <asm/io.h>
14888  #include <asm/bugs.h>
14889 diff -NurpP --minimal linux-2.6.32.56/ipc/mqueue.c linux-2.6.32.56-vs2.3.0.36.29.9/ipc/mqueue.c
14890 --- linux-2.6.32.56/ipc/mqueue.c        2012-02-09 10:22:35.000000000 +0100
14891 +++ linux-2.6.32.56-vs2.3.0.36.29.9/ipc/mqueue.c        2011-06-10 13:03:02.000000000 +0200
14892 @@ -33,6 +33,8 @@
14893  #include <linux/pid.h>
14894  #include <linux/ipc_namespace.h>
14895  #include <linux/ima.h>
14896 +#include <linux/vs_context.h>
14897 +#include <linux/vs_limit.h>
14898  
14899  #include <net/sock.h>
14900  #include "util.h"
14901 @@ -66,6 +68,7 @@ struct mqueue_inode_info {
14902         struct sigevent notify;
14903         struct pid* notify_owner;
14904         struct user_struct *user;       /* user who created, for accounting */
14905 +       struct vx_info *vxi;
14906         struct sock *notify_sock;
14907         struct sk_buff *notify_cookie;
14908  
14909 @@ -125,6 +128,7 @@ static struct inode *mqueue_get_inode(st
14910                 if (S_ISREG(mode)) {
14911                         struct mqueue_inode_info *info;
14912                         struct task_struct *p = current;
14913 +                       struct vx_info *vxi = p->vx_info;
14914                         unsigned long mq_bytes, mq_msg_tblsz;
14915  
14916                         inode->i_fop = &mqueue_file_operations;
14917 @@ -139,6 +143,7 @@ static struct inode *mqueue_get_inode(st
14918                         info->notify_owner = NULL;
14919                         info->qsize = 0;
14920                         info->user = NULL;      /* set when all is ok */
14921 +                       info->vxi = NULL;
14922                         memset(&info->attr, 0, sizeof(info->attr));
14923                         info->attr.mq_maxmsg = ipc_ns->mq_msg_max;
14924                         info->attr.mq_msgsize = ipc_ns->mq_msgsize_max;
14925 @@ -153,22 +158,26 @@ static struct inode *mqueue_get_inode(st
14926                         spin_lock(&mq_lock);
14927                         if (u->mq_bytes + mq_bytes < u->mq_bytes ||
14928                             u->mq_bytes + mq_bytes >
14929 -                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur) {
14930 +                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur ||
14931 +                           !vx_ipcmsg_avail(vxi, mq_bytes)) {
14932                                 spin_unlock(&mq_lock);
14933                                 goto out_inode;
14934                         }
14935                         u->mq_bytes += mq_bytes;
14936 +                       vx_ipcmsg_add(vxi, u, mq_bytes);
14937                         spin_unlock(&mq_lock);
14938  
14939                         info->messages = kmalloc(mq_msg_tblsz, GFP_KERNEL);
14940                         if (!info->messages) {
14941                                 spin_lock(&mq_lock);
14942                                 u->mq_bytes -= mq_bytes;
14943 +                               vx_ipcmsg_sub(vxi, u, mq_bytes);
14944                                 spin_unlock(&mq_lock);
14945                                 goto out_inode;
14946                         }
14947                         /* all is ok */
14948                         info->user = get_uid(u);
14949 +                       info->vxi = get_vx_info(vxi);
14950                 } else if (S_ISDIR(mode)) {
14951                         inc_nlink(inode);
14952                         /* Some things misbehave if size == 0 on a directory */
14953 @@ -269,8 +278,11 @@ static void mqueue_delete_inode(struct i
14954                    (info->attr.mq_maxmsg * info->attr.mq_msgsize));
14955         user = info->user;
14956         if (user) {
14957 +               struct vx_info *vxi = info->vxi;
14958 +
14959                 spin_lock(&mq_lock);
14960                 user->mq_bytes -= mq_bytes;
14961 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
14962                 /*
14963                  * get_ns_from_inode() ensures that the
14964                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
14965 @@ -280,6 +292,7 @@ static void mqueue_delete_inode(struct i
14966                 if (ipc_ns)
14967                         ipc_ns->mq_queues_count--;
14968                 spin_unlock(&mq_lock);
14969 +               put_vx_info(vxi);
14970                 free_uid(user);
14971         }
14972         if (ipc_ns)
14973 diff -NurpP --minimal linux-2.6.32.56/ipc/msg.c linux-2.6.32.56-vs2.3.0.36.29.9/ipc/msg.c
14974 --- linux-2.6.32.56/ipc/msg.c   2012-02-09 10:22:35.000000000 +0100
14975 +++ linux-2.6.32.56-vs2.3.0.36.29.9/ipc/msg.c   2011-06-10 13:03:02.000000000 +0200
14976 @@ -38,6 +38,7 @@
14977  #include <linux/rwsem.h>
14978  #include <linux/nsproxy.h>
14979  #include <linux/ipc_namespace.h>
14980 +#include <linux/vs_base.h>
14981  
14982  #include <asm/current.h>
14983  #include <asm/uaccess.h>
14984 @@ -191,6 +192,7 @@ static int newque(struct ipc_namespace *
14985  
14986         msq->q_perm.mode = msgflg & S_IRWXUGO;
14987         msq->q_perm.key = key;
14988 +       msq->q_perm.xid = vx_current_xid();
14989  
14990         msq->q_perm.security = NULL;
14991         retval = security_msg_queue_alloc(msq);
14992 diff -NurpP --minimal linux-2.6.32.56/ipc/namespace.c linux-2.6.32.56-vs2.3.0.36.29.9/ipc/namespace.c
14993 --- linux-2.6.32.56/ipc/namespace.c     2009-09-10 15:26:27.000000000 +0200
14994 +++ linux-2.6.32.56-vs2.3.0.36.29.9/ipc/namespace.c     2011-06-10 13:03:02.000000000 +0200
14995 @@ -11,6 +11,8 @@
14996  #include <linux/slab.h>
14997  #include <linux/fs.h>
14998  #include <linux/mount.h>
14999 +#include <linux/vs_base.h>
15000 +#include <linux/vserver/global.h>
15001  
15002  #include "util.h"
15003  
15004 diff -NurpP --minimal linux-2.6.32.56/ipc/sem.c linux-2.6.32.56-vs2.3.0.36.29.9/ipc/sem.c
15005 --- linux-2.6.32.56/ipc/sem.c   2012-02-09 10:22:35.000000000 +0100
15006 +++ linux-2.6.32.56-vs2.3.0.36.29.9/ipc/sem.c   2011-06-10 13:03:02.000000000 +0200
15007 @@ -83,6 +83,8 @@
15008  #include <linux/rwsem.h>
15009  #include <linux/nsproxy.h>
15010  #include <linux/ipc_namespace.h>
15011 +#include <linux/vs_base.h>
15012 +#include <linux/vs_limit.h>
15013  
15014  #include <asm/uaccess.h>
15015  #include "util.h"
15016 @@ -256,6 +258,7 @@ static int newary(struct ipc_namespace *
15017  
15018         sma->sem_perm.mode = (semflg & S_IRWXUGO);
15019         sma->sem_perm.key = key;
15020 +       sma->sem_perm.xid = vx_current_xid();
15021  
15022         sma->sem_perm.security = NULL;
15023         retval = security_sem_alloc(sma);
15024 @@ -271,6 +274,9 @@ static int newary(struct ipc_namespace *
15025                 return id;
15026         }
15027         ns->used_sems += nsems;
15028 +       /* FIXME: obsoleted? */
15029 +       vx_semary_inc(sma);
15030 +       vx_nsems_add(sma, nsems);
15031  
15032         sma->sem_base = (struct sem *) &sma[1];
15033         INIT_LIST_HEAD(&sma->sem_pending);
15034 @@ -547,6 +553,9 @@ static void freeary(struct ipc_namespace
15035         sem_unlock(sma);
15036  
15037         ns->used_sems -= sma->sem_nsems;
15038 +       /* FIXME: obsoleted? */
15039 +       vx_nsems_sub(sma, sma->sem_nsems);
15040 +       vx_semary_dec(sma);
15041         security_sem_free(sma);
15042         ipc_rcu_putref(sma);
15043  }
15044 diff -NurpP --minimal linux-2.6.32.56/ipc/shm.c linux-2.6.32.56-vs2.3.0.36.29.9/ipc/shm.c
15045 --- linux-2.6.32.56/ipc/shm.c   2012-02-09 10:22:35.000000000 +0100
15046 +++ linux-2.6.32.56-vs2.3.0.36.29.9/ipc/shm.c   2011-06-10 13:03:02.000000000 +0200
15047 @@ -40,6 +40,8 @@
15048  #include <linux/mount.h>
15049  #include <linux/ipc_namespace.h>
15050  #include <linux/ima.h>
15051 +#include <linux/vs_context.h>
15052 +#include <linux/vs_limit.h>
15053  
15054  #include <asm/uaccess.h>
15055  
15056 @@ -170,7 +172,12 @@ static void shm_open(struct vm_area_stru
15057   */
15058  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
15059  {
15060 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
15061 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
15062 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
15063 +
15064 +       vx_ipcshm_sub(vxi, shp, numpages);
15065 +       ns->shm_tot -= numpages;
15066 +
15067         shm_rmid(ns, shp);
15068         shm_unlock(shp);
15069         if (!is_file_hugepages(shp->shm_file))
15070 @@ -180,6 +187,7 @@ static void shm_destroy(struct ipc_names
15071                                                 shp->mlock_user);
15072         fput (shp->shm_file);
15073         security_shm_free(shp);
15074 +       put_vx_info(vxi);
15075         ipc_rcu_putref(shp);
15076  }
15077  
15078 @@ -350,11 +358,15 @@ static int newseg(struct ipc_namespace *
15079         if (ns->shm_tot + numpages > ns->shm_ctlall)
15080                 return -ENOSPC;
15081  
15082 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
15083 +               return -ENOSPC;
15084 +
15085         shp = ipc_rcu_alloc(sizeof(*shp));
15086         if (!shp)
15087                 return -ENOMEM;
15088  
15089         shp->shm_perm.key = key;
15090 +       shp->shm_perm.xid = vx_current_xid();
15091         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
15092         shp->mlock_user = NULL;
15093  
15094 @@ -408,6 +420,7 @@ static int newseg(struct ipc_namespace *
15095         ns->shm_tot += numpages;
15096         error = shp->shm_perm.id;
15097         shm_unlock(shp);
15098 +       vx_ipcshm_add(current_vx_info(), key, numpages);
15099         return error;
15100  
15101  no_id:
15102 diff -NurpP --minimal linux-2.6.32.56/kernel/Makefile linux-2.6.32.56-vs2.3.0.36.29.9/kernel/Makefile
15103 --- linux-2.6.32.56/kernel/Makefile     2009-12-03 20:02:57.000000000 +0100
15104 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/Makefile     2011-06-10 13:03:02.000000000 +0200
15105 @@ -23,6 +23,7 @@ CFLAGS_REMOVE_cgroup-debug.o = -pg
15106  CFLAGS_REMOVE_sched_clock.o = -pg
15107  endif
15108  
15109 +obj-y += vserver/
15110  obj-$(CONFIG_FREEZER) += freezer.o
15111  obj-$(CONFIG_PROFILING) += profile.o
15112  obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
15113 diff -NurpP --minimal linux-2.6.32.56/kernel/capability.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/capability.c
15114 --- linux-2.6.32.56/kernel/capability.c 2012-02-09 10:22:35.000000000 +0100
15115 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/capability.c 2011-06-10 13:03:02.000000000 +0200
15116 @@ -14,6 +14,7 @@
15117  #include <linux/security.h>
15118  #include <linux/syscalls.h>
15119  #include <linux/pid_namespace.h>
15120 +#include <linux/vs_context.h>
15121  #include <asm/uaccess.h>
15122  
15123  /*
15124 @@ -121,6 +122,7 @@ static int cap_validate_magic(cap_user_h
15125         return 0;
15126  }
15127  
15128 +
15129  /*
15130   * The only thing that can change the capabilities of the current
15131   * process is the current process. As such, we can't be in this code
15132 @@ -288,6 +290,8 @@ error:
15133         return ret;
15134  }
15135  
15136 +#include <linux/vserver/base.h>
15137 +
15138  /**
15139   * capable - Determine if the current task has a superior capability in effect
15140   * @cap: The capability to be tested for
15141 @@ -300,6 +304,9 @@ error:
15142   */
15143  int capable(int cap)
15144  {
15145 +       /* here for now so we don't require task locking */
15146 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
15147 +               return 0;
15148         if (unlikely(!cap_valid(cap))) {
15149                 printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
15150                 BUG();
15151 diff -NurpP --minimal linux-2.6.32.56/kernel/compat.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/compat.c
15152 --- linux-2.6.32.56/kernel/compat.c     2012-02-09 10:22:36.000000000 +0100
15153 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/compat.c     2011-06-10 13:03:02.000000000 +0200
15154 @@ -900,7 +900,7 @@ asmlinkage long compat_sys_time(compat_t
15155         compat_time_t i;
15156         struct timeval tv;
15157  
15158 -       do_gettimeofday(&tv);
15159 +       vx_gettimeofday(&tv);
15160         i = tv.tv_sec;
15161  
15162         if (tloc) {
15163 @@ -925,7 +925,7 @@ asmlinkage long compat_sys_stime(compat_
15164         if (err)
15165                 return err;
15166  
15167 -       do_settimeofday(&tv);
15168 +       vx_settimeofday(&tv);
15169         return 0;
15170  }
15171  
15172 diff -NurpP --minimal linux-2.6.32.56/kernel/exit.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/exit.c
15173 --- linux-2.6.32.56/kernel/exit.c       2012-02-09 10:22:36.000000000 +0100
15174 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/exit.c       2011-06-10 13:03:02.000000000 +0200
15175 @@ -48,6 +48,10 @@
15176  #include <linux/fs_struct.h>
15177  #include <linux/init_task.h>
15178  #include <linux/perf_event.h>
15179 +#include <linux/vs_limit.h>
15180 +#include <linux/vs_context.h>
15181 +#include <linux/vs_network.h>
15182 +#include <linux/vs_pid.h>
15183  #include <trace/events/sched.h>
15184  
15185  #include <asm/uaccess.h>
15186 @@ -495,9 +499,11 @@ static void close_files(struct files_str
15187                                         filp_close(file, files);
15188                                         cond_resched();
15189                                 }
15190 +                               vx_openfd_dec(i);
15191                         }
15192                         i++;
15193                         set >>= 1;
15194 +                       cond_resched();
15195                 }
15196         }
15197  }
15198 @@ -1027,11 +1033,16 @@ NORET_TYPE void do_exit(long code)
15199  
15200         validate_creds_for_do_exit(tsk);
15201  
15202 +       /* needs to stay after exit_notify() */
15203 +       exit_vx_info(tsk, code);
15204 +       exit_nx_info(tsk);
15205 +
15206         preempt_disable();
15207         exit_rcu();
15208         /* causes final put_task_struct in finish_task_switch(). */
15209         tsk->state = TASK_DEAD;
15210         schedule();
15211 +       printk("bad task: %p [%lx]\n", current, current->state);
15212         BUG();
15213         /* Avoid "noreturn function does return".  */
15214         for (;;)
15215 diff -NurpP --minimal linux-2.6.32.56/kernel/fork.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/fork.c
15216 --- linux-2.6.32.56/kernel/fork.c       2012-02-09 10:22:36.000000000 +0100
15217 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/fork.c       2011-06-10 13:03:02.000000000 +0200
15218 @@ -64,6 +64,10 @@
15219  #include <linux/magic.h>
15220  #include <linux/perf_event.h>
15221  #include <linux/posix-timers.h>
15222 +#include <linux/vs_context.h>
15223 +#include <linux/vs_network.h>
15224 +#include <linux/vs_limit.h>
15225 +#include <linux/vs_memory.h>
15226  
15227  #include <asm/pgtable.h>
15228  #include <asm/pgalloc.h>
15229 @@ -151,6 +155,8 @@ void free_task(struct task_struct *tsk)
15230         account_kernel_stack(tsk->stack, -1);
15231         free_thread_info(tsk->stack);
15232         rt_mutex_debug_task_free(tsk);
15233 +       clr_vx_info(&tsk->vx_info);
15234 +       clr_nx_info(&tsk->nx_info);
15235         ftrace_graph_exit_task(tsk);
15236         free_task_struct(tsk);
15237  }
15238 @@ -296,6 +302,8 @@ static int dup_mmap(struct mm_struct *mm
15239         mm->free_area_cache = oldmm->mmap_base;
15240         mm->cached_hole_size = ~0UL;
15241         mm->map_count = 0;
15242 +       __set_mm_counter(mm, file_rss, 0);
15243 +       __set_mm_counter(mm, anon_rss, 0);
15244         cpumask_clear(mm_cpumask(mm));
15245         mm->mm_rb = RB_ROOT;
15246         rb_link = &mm->mm_rb.rb_node;
15247 @@ -311,7 +319,7 @@ static int dup_mmap(struct mm_struct *mm
15248  
15249                 if (mpnt->vm_flags & VM_DONTCOPY) {
15250                         long pages = vma_pages(mpnt);
15251 -                       mm->total_vm -= pages;
15252 +                       vx_vmpages_sub(mm, pages);
15253                         vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
15254                                                                 -pages);
15255                         continue;
15256 @@ -455,8 +463,8 @@ static struct mm_struct * mm_init(struct
15257                 (current->mm->flags & MMF_INIT_MASK) : default_dump_filter;
15258         mm->core_state = NULL;
15259         mm->nr_ptes = 0;
15260 -       set_mm_counter(mm, file_rss, 0);
15261 -       set_mm_counter(mm, anon_rss, 0);
15262 +       __set_mm_counter(mm, file_rss, 0);
15263 +       __set_mm_counter(mm, anon_rss, 0);
15264         spin_lock_init(&mm->page_table_lock);
15265         mm->free_area_cache = TASK_UNMAPPED_BASE;
15266         mm->cached_hole_size = ~0UL;
15267 @@ -466,6 +474,7 @@ static struct mm_struct * mm_init(struct
15268         if (likely(!mm_alloc_pgd(mm))) {
15269                 mm->def_flags = 0;
15270                 mmu_notifier_mm_init(mm);
15271 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
15272                 return mm;
15273         }
15274  
15275 @@ -499,6 +508,7 @@ void __mmdrop(struct mm_struct *mm)
15276         mm_free_pgd(mm);
15277         destroy_context(mm);
15278         mmu_notifier_mm_destroy(mm);
15279 +       clr_vx_info(&mm->mm_vx_info);
15280         free_mm(mm);
15281  }
15282  EXPORT_SYMBOL_GPL(__mmdrop);
15283 @@ -634,6 +644,7 @@ struct mm_struct *dup_mm(struct task_str
15284                 goto fail_nomem;
15285  
15286         memcpy(mm, oldmm, sizeof(*mm));
15287 +       mm->mm_vx_info = NULL;
15288  
15289         /* Initializing for Swap token stuff */
15290         mm->token_priority = 0;
15291 @@ -672,6 +683,7 @@ fail_nocontext:
15292          * If init_new_context() failed, we cannot use mmput() to free the mm
15293          * because it calls destroy_context()
15294          */
15295 +       clr_vx_info(&mm->mm_vx_info);
15296         mm_free_pgd(mm);
15297         free_mm(mm);
15298         return NULL;
15299 @@ -986,6 +998,8 @@ static struct task_struct *copy_process(
15300         int retval;
15301         struct task_struct *p;
15302         int cgroup_callbacks_done = 0;
15303 +       struct vx_info *vxi;
15304 +       struct nx_info *nxi;
15305  
15306         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
15307                 return ERR_PTR(-EINVAL);
15308 @@ -1032,12 +1046,28 @@ static struct task_struct *copy_process(
15309         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
15310         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
15311  #endif
15312 +       init_vx_info(&p->vx_info, current_vx_info());
15313 +       init_nx_info(&p->nx_info, current_nx_info());
15314 +
15315 +       /* check vserver memory */
15316 +       if (p->mm && !(clone_flags & CLONE_VM)) {
15317 +               if (vx_vmpages_avail(p->mm, p->mm->total_vm))
15318 +                       vx_pages_add(p->vx_info, RLIMIT_AS, p->mm->total_vm);
15319 +               else
15320 +                       goto bad_fork_free;
15321 +       }
15322 +       if (p->mm && vx_flags(VXF_FORK_RSS, 0)) {
15323 +               if (!vx_rss_avail(p->mm, get_mm_counter(p->mm, file_rss)))
15324 +                       goto bad_fork_cleanup_vm;
15325 +       }
15326         retval = -EAGAIN;
15327 +       if (!vx_nproc_avail(1))
15328 +               goto bad_fork_cleanup_vm;
15329         if (atomic_read(&p->real_cred->user->processes) >=
15330                         p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
15331                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
15332                     p->real_cred->user != INIT_USER)
15333 -                       goto bad_fork_free;
15334 +                       goto bad_fork_cleanup_vm;
15335         }
15336  
15337         retval = copy_creds(p, clone_flags);
15338 @@ -1289,6 +1319,18 @@ static struct task_struct *copy_process(
15339  
15340         total_forks++;
15341         spin_unlock(&current->sighand->siglock);
15342 +
15343 +       /* p is copy of current */
15344 +       vxi = p->vx_info;
15345 +       if (vxi) {
15346 +               claim_vx_info(vxi, p);
15347 +               atomic_inc(&vxi->cvirt.nr_threads);
15348 +               atomic_inc(&vxi->cvirt.total_forks);
15349 +               vx_nproc_inc(p);
15350 +       }
15351 +       nxi = p->nx_info;
15352 +       if (nxi)
15353 +               claim_nx_info(nxi, p);
15354         write_unlock_irq(&tasklist_lock);
15355         proc_fork_connector(p);
15356         cgroup_post_fork(p);
15357 @@ -1330,6 +1372,9 @@ bad_fork_cleanup_cgroup:
15358  bad_fork_cleanup_count:
15359         atomic_dec(&p->cred->user->processes);
15360         exit_creds(p);
15361 +bad_fork_cleanup_vm:
15362 +       if (p->mm && !(clone_flags & CLONE_VM))
15363 +               vx_pages_sub(p->vx_info, RLIMIT_AS, p->mm->total_vm);
15364  bad_fork_free:
15365         free_task(p);
15366  fork_out:
15367 diff -NurpP --minimal linux-2.6.32.56/kernel/kthread.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/kthread.c
15368 --- linux-2.6.32.56/kernel/kthread.c    2012-02-09 10:22:36.000000000 +0100
15369 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/kthread.c    2011-06-10 13:03:02.000000000 +0200
15370 @@ -14,6 +14,7 @@
15371  #include <linux/file.h>
15372  #include <linux/module.h>
15373  #include <linux/mutex.h>
15374 +#include <linux/vs_pid.h>
15375  #include <trace/events/sched.h>
15376  
15377  static DEFINE_SPINLOCK(kthread_create_lock);
15378 diff -NurpP --minimal linux-2.6.32.56/kernel/nsproxy.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/nsproxy.c
15379 --- linux-2.6.32.56/kernel/nsproxy.c    2009-09-10 15:26:28.000000000 +0200
15380 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/nsproxy.c    2011-06-10 13:03:02.000000000 +0200
15381 @@ -19,6 +19,8 @@
15382  #include <linux/mnt_namespace.h>
15383  #include <linux/utsname.h>
15384  #include <linux/pid_namespace.h>
15385 +#include <linux/vserver/global.h>
15386 +#include <linux/vserver/debug.h>
15387  #include <net/net_namespace.h>
15388  #include <linux/ipc_namespace.h>
15389  
15390 @@ -31,8 +33,11 @@ static inline struct nsproxy *create_nsp
15391         struct nsproxy *nsproxy;
15392  
15393         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
15394 -       if (nsproxy)
15395 +       if (nsproxy) {
15396                 atomic_set(&nsproxy->count, 1);
15397 +               atomic_inc(&vs_global_nsproxy);
15398 +       }
15399 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
15400         return nsproxy;
15401  }
15402  
15403 @@ -41,41 +46,52 @@ static inline struct nsproxy *create_nsp
15404   * Return the newly created nsproxy.  Do not attach this to the task,
15405   * leave it to the caller to do proper locking and attach it to task.
15406   */
15407 -static struct nsproxy *create_new_namespaces(unsigned long flags,
15408 -                       struct task_struct *tsk, struct fs_struct *new_fs)
15409 +static struct nsproxy *unshare_namespaces(unsigned long flags,
15410 +                       struct nsproxy *orig, struct fs_struct *new_fs)
15411  {
15412         struct nsproxy *new_nsp;
15413         int err;
15414  
15415 +       vxdprintk(VXD_CBIT(space, 4),
15416 +               "unshare_namespaces(0x%08lx,%p,%p)",
15417 +               flags, orig, new_fs);
15418 +
15419         new_nsp = create_nsproxy();
15420         if (!new_nsp)
15421                 return ERR_PTR(-ENOMEM);
15422  
15423 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
15424 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
15425         if (IS_ERR(new_nsp->mnt_ns)) {
15426                 err = PTR_ERR(new_nsp->mnt_ns);
15427                 goto out_ns;
15428         }
15429  
15430 -       new_nsp->uts_ns = copy_utsname(flags, tsk->nsproxy->uts_ns);
15431 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns);
15432         if (IS_ERR(new_nsp->uts_ns)) {
15433                 err = PTR_ERR(new_nsp->uts_ns);
15434                 goto out_uts;
15435         }
15436  
15437 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk->nsproxy->ipc_ns);
15438 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns);
15439         if (IS_ERR(new_nsp->ipc_ns)) {
15440                 err = PTR_ERR(new_nsp->ipc_ns);
15441                 goto out_ipc;
15442         }
15443  
15444 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
15445 +       new_nsp->pid_ns = copy_pid_ns(flags, orig->pid_ns);
15446         if (IS_ERR(new_nsp->pid_ns)) {
15447                 err = PTR_ERR(new_nsp->pid_ns);
15448                 goto out_pid;
15449         }
15450  
15451 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
15452 +       /* disabled now?
15453 +       new_nsp->user_ns = copy_user_ns(flags, orig->user_ns);
15454 +       if (IS_ERR(new_nsp->user_ns)) {
15455 +               err = PTR_ERR(new_nsp->user_ns);
15456 +               goto out_user;
15457 +       } */
15458 +
15459 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
15460         if (IS_ERR(new_nsp->net_ns)) {
15461                 err = PTR_ERR(new_nsp->net_ns);
15462                 goto out_net;
15463 @@ -100,6 +116,38 @@ out_ns:
15464         return ERR_PTR(err);
15465  }
15466  
15467 +static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
15468 +                       struct fs_struct *new_fs)
15469 +{
15470 +       return unshare_namespaces(flags, tsk->nsproxy, new_fs);
15471 +}
15472 +
15473 +/*
15474 + * copies the nsproxy, setting refcount to 1, and grabbing a
15475 + * reference to all contained namespaces.
15476 + */
15477 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
15478 +{
15479 +       struct nsproxy *ns = create_nsproxy();
15480 +
15481 +       if (ns) {
15482 +               memcpy(ns, orig, sizeof(struct nsproxy));
15483 +               atomic_set(&ns->count, 1);
15484 +
15485 +               if (ns->mnt_ns)
15486 +                       get_mnt_ns(ns->mnt_ns);
15487 +               if (ns->uts_ns)
15488 +                       get_uts_ns(ns->uts_ns);
15489 +               if (ns->ipc_ns)
15490 +                       get_ipc_ns(ns->ipc_ns);
15491 +               if (ns->pid_ns)
15492 +                       get_pid_ns(ns->pid_ns);
15493 +               if (ns->net_ns)
15494 +                       get_net(ns->net_ns);
15495 +       }
15496 +       return ns;
15497 +}
15498 +
15499  /*
15500   * called from clone.  This now handles copy for nsproxy and all
15501   * namespaces therein.
15502 @@ -107,9 +155,12 @@ out_ns:
15503  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
15504  {
15505         struct nsproxy *old_ns = tsk->nsproxy;
15506 -       struct nsproxy *new_ns;
15507 +       struct nsproxy *new_ns = NULL;
15508         int err = 0;
15509  
15510 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
15511 +               flags, tsk, old_ns);
15512 +
15513         if (!old_ns)
15514                 return 0;
15515  
15516 @@ -119,7 +170,7 @@ int copy_namespaces(unsigned long flags,
15517                                 CLONE_NEWPID | CLONE_NEWNET)))
15518                 return 0;
15519  
15520 -       if (!capable(CAP_SYS_ADMIN)) {
15521 +       if (!vx_can_unshare(CAP_SYS_ADMIN, flags)) {
15522                 err = -EPERM;
15523                 goto out;
15524         }
15525 @@ -146,6 +197,9 @@ int copy_namespaces(unsigned long flags,
15526  
15527  out:
15528         put_nsproxy(old_ns);
15529 +       vxdprintk(VXD_CBIT(space, 3),
15530 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
15531 +               flags, tsk, old_ns, err, new_ns);
15532         return err;
15533  }
15534  
15535 @@ -159,7 +213,9 @@ void free_nsproxy(struct nsproxy *ns)
15536                 put_ipc_ns(ns->ipc_ns);
15537         if (ns->pid_ns)
15538                 put_pid_ns(ns->pid_ns);
15539 -       put_net(ns->net_ns);
15540 +       if (ns->net_ns)
15541 +               put_net(ns->net_ns);
15542 +       atomic_dec(&vs_global_nsproxy);
15543         kmem_cache_free(nsproxy_cachep, ns);
15544  }
15545  
15546 @@ -172,11 +228,15 @@ int unshare_nsproxy_namespaces(unsigned 
15547  {
15548         int err = 0;
15549  
15550 +       vxdprintk(VXD_CBIT(space, 4),
15551 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
15552 +               unshare_flags, current->nsproxy);
15553 +
15554         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
15555                                CLONE_NEWNET)))
15556                 return 0;
15557  
15558 -       if (!capable(CAP_SYS_ADMIN))
15559 +       if (!vx_can_unshare(CAP_SYS_ADMIN, unshare_flags))
15560                 return -EPERM;
15561  
15562         *new_nsp = create_new_namespaces(unshare_flags, current,
15563 diff -NurpP --minimal linux-2.6.32.56/kernel/pid.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/pid.c
15564 --- linux-2.6.32.56/kernel/pid.c        2012-02-09 10:22:36.000000000 +0100
15565 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/pid.c        2011-06-10 13:03:02.000000000 +0200
15566 @@ -36,6 +36,7 @@
15567  #include <linux/pid_namespace.h>
15568  #include <linux/init_task.h>
15569  #include <linux/syscalls.h>
15570 +#include <linux/vs_pid.h>
15571  
15572  #define pid_hashfn(nr, ns)     \
15573         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
15574 @@ -308,7 +309,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
15575  
15576  struct pid *find_vpid(int nr)
15577  {
15578 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
15579 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
15580  }
15581  EXPORT_SYMBOL_GPL(find_vpid);
15582  
15583 @@ -368,6 +369,9 @@ void transfer_pid(struct task_struct *ol
15584  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
15585  {
15586         struct task_struct *result = NULL;
15587 +
15588 +       if (type == PIDTYPE_REALPID)
15589 +               type = PIDTYPE_PID;
15590         if (pid) {
15591                 struct hlist_node *first;
15592                 first = rcu_dereference(pid->tasks[type].first);
15593 @@ -383,7 +387,7 @@ EXPORT_SYMBOL(pid_task);
15594   */
15595  struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
15596  {
15597 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
15598 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
15599  }
15600  
15601  struct task_struct *find_task_by_vpid(pid_t vnr)
15602 @@ -425,7 +429,7 @@ struct pid *find_get_pid(pid_t nr)
15603  }
15604  EXPORT_SYMBOL_GPL(find_get_pid);
15605  
15606 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15607 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
15608  {
15609         struct upid *upid;
15610         pid_t nr = 0;
15611 @@ -438,6 +442,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
15612         return nr;
15613  }
15614  
15615 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15616 +{
15617 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
15618 +}
15619 +
15620  pid_t pid_vnr(struct pid *pid)
15621  {
15622         return pid_nr_ns(pid, current->nsproxy->pid_ns);
15623 diff -NurpP --minimal linux-2.6.32.56/kernel/pid_namespace.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/pid_namespace.c
15624 --- linux-2.6.32.56/kernel/pid_namespace.c      2009-12-03 20:02:58.000000000 +0100
15625 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/pid_namespace.c      2011-06-10 13:03:02.000000000 +0200
15626 @@ -13,6 +13,7 @@
15627  #include <linux/syscalls.h>
15628  #include <linux/err.h>
15629  #include <linux/acct.h>
15630 +#include <linux/vserver/global.h>
15631  
15632  #define BITS_PER_PAGE          (PAGE_SIZE*8)
15633  
15634 @@ -86,6 +87,7 @@ static struct pid_namespace *create_pid_
15635                 goto out_free_map;
15636  
15637         kref_init(&ns->kref);
15638 +       atomic_inc(&vs_global_pid_ns);
15639         ns->level = level;
15640         ns->parent = get_pid_ns(parent_pid_ns);
15641  
15642 @@ -111,6 +113,7 @@ static void destroy_pid_namespace(struct
15643  
15644         for (i = 0; i < PIDMAP_ENTRIES; i++)
15645                 kfree(ns->pidmap[i].page);
15646 +       atomic_dec(&vs_global_pid_ns);
15647         kmem_cache_free(pid_ns_cachep, ns);
15648  }
15649  
15650 diff -NurpP --minimal linux-2.6.32.56/kernel/posix-timers.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/posix-timers.c
15651 --- linux-2.6.32.56/kernel/posix-timers.c       2012-02-09 10:22:36.000000000 +0100
15652 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/posix-timers.c       2011-06-10 13:03:02.000000000 +0200
15653 @@ -46,6 +46,7 @@
15654  #include <linux/wait.h>
15655  #include <linux/workqueue.h>
15656  #include <linux/module.h>
15657 +#include <linux/vs_context.h>
15658  
15659  /*
15660   * Management arrays for POSIX timers.  Timers are kept in slab memory
15661 @@ -363,6 +364,7 @@ int posix_timer_event(struct k_itimer *t
15662  {
15663         struct task_struct *task;
15664         int shared, ret = -1;
15665 +
15666         /*
15667          * FIXME: if ->sigq is queued we can race with
15668          * dequeue_signal()->do_schedule_next_timer().
15669 @@ -379,10 +381,18 @@ int posix_timer_event(struct k_itimer *t
15670         rcu_read_lock();
15671         task = pid_task(timr->it_pid, PIDTYPE_PID);
15672         if (task) {
15673 +               struct vx_info_save vxis;
15674 +               struct vx_info *vxi;
15675 +
15676 +               vxi = get_vx_info(task->vx_info);
15677 +               enter_vx_info(vxi, &vxis);
15678                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
15679                 ret = send_sigqueue(timr->sigq, task, shared);
15680 +               leave_vx_info(&vxis);
15681 +               put_vx_info(vxi);
15682         }
15683         rcu_read_unlock();
15684 +
15685         /* If we failed to send the signal the timer stops. */
15686         return ret > 0;
15687  }
15688 diff -NurpP --minimal linux-2.6.32.56/kernel/printk.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/printk.c
15689 --- linux-2.6.32.56/kernel/printk.c     2012-02-09 10:22:36.000000000 +0100
15690 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/printk.c     2011-06-10 13:03:02.000000000 +0200
15691 @@ -33,6 +33,7 @@
15692  #include <linux/bootmem.h>
15693  #include <linux/syscalls.h>
15694  #include <linux/kexec.h>
15695 +#include <linux/vs_cvirt.h>
15696  
15697  #include <asm/uaccess.h>
15698  
15699 @@ -276,18 +277,13 @@ int do_syslog(int type, char __user *buf
15700         unsigned i, j, limit, count;
15701         int do_clear = 0;
15702         char c;
15703 -       int error = 0;
15704 +       int error;
15705  
15706         error = security_syslog(type);
15707         if (error)
15708                 return error;
15709  
15710 -       switch (type) {
15711 -       case 0:         /* Close log */
15712 -               break;
15713 -       case 1:         /* Open log */
15714 -               break;
15715 -       case 2:         /* Read from log */
15716 +       if ((type >= 2) && (type <= 4)) {
15717                 error = -EINVAL;
15718                 if (!buf || len < 0)
15719                         goto out;
15720 @@ -298,6 +294,16 @@ int do_syslog(int type, char __user *buf
15721                         error = -EFAULT;
15722                         goto out;
15723                 }
15724 +       }
15725 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15726 +               return vx_do_syslog(type, buf, len);
15727 +
15728 +       switch (type) {
15729 +       case 0:         /* Close log */
15730 +               break;
15731 +       case 1:         /* Open log */
15732 +               break;
15733 +       case 2:         /* Read from log */
15734                 error = wait_event_interruptible(log_wait,
15735                                                         (log_start - log_end));
15736                 if (error)
15737 @@ -322,16 +328,6 @@ int do_syslog(int type, char __user *buf
15738                 do_clear = 1;
15739                 /* FALL THRU */
15740         case 3:         /* Read last kernel messages */
15741 -               error = -EINVAL;
15742 -               if (!buf || len < 0)
15743 -                       goto out;
15744 -               error = 0;
15745 -               if (!len)
15746 -                       goto out;
15747 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
15748 -                       error = -EFAULT;
15749 -                       goto out;
15750 -               }
15751                 count = len;
15752                 if (count > log_buf_len)
15753                         count = log_buf_len;
15754 diff -NurpP --minimal linux-2.6.32.56/kernel/ptrace.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/ptrace.c
15755 --- linux-2.6.32.56/kernel/ptrace.c     2012-02-09 10:22:36.000000000 +0100
15756 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/ptrace.c     2011-06-10 14:03:28.000000000 +0200
15757 @@ -22,6 +22,7 @@
15758  #include <linux/pid_namespace.h>
15759  #include <linux/syscalls.h>
15760  #include <linux/uaccess.h>
15761 +#include <linux/vs_context.h>
15762  
15763  
15764  /*
15765 @@ -151,6 +152,11 @@ int __ptrace_may_access(struct task_stru
15766                 dumpable = get_dumpable(task->mm);
15767         if (!dumpable && !capable(CAP_SYS_PTRACE))
15768                 return -EPERM;
15769 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_IDENT))
15770 +               return -EPERM;
15771 +       if (!vx_check(task->xid, VS_IDENT) &&
15772 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
15773 +               return -EACCES;
15774  
15775         return security_ptrace_access_check(task, mode);
15776  }
15777 diff -NurpP --minimal linux-2.6.32.56/kernel/sched.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/sched.c
15778 --- linux-2.6.32.56/kernel/sched.c      2012-02-09 10:22:36.000000000 +0100
15779 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/sched.c      2011-06-10 13:15:21.000000000 +0200
15780 @@ -71,6 +71,8 @@
15781  #include <linux/debugfs.h>
15782  #include <linux/ctype.h>
15783  #include <linux/ftrace.h>
15784 +#include <linux/vs_sched.h>
15785 +#include <linux/vs_cvirt.h>
15786  
15787  #include <asm/tlb.h>
15788  #include <asm/irq_regs.h>
15789 @@ -237,6 +239,15 @@ static DEFINE_MUTEX(sched_domains_mutex)
15790  
15791  #include <linux/cgroup.h>
15792  
15793 +#if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_CFS_HARD_LIMITS)
15794 +struct cfs_bandwidth {
15795 +       spinlock_t              cfs_runtime_lock;
15796 +       ktime_t                 cfs_period;
15797 +       u64                     cfs_runtime;
15798 +       struct hrtimer          cfs_period_timer;
15799 +};
15800 +#endif
15801 +
15802  struct cfs_rq;
15803  
15804  static LIST_HEAD(task_groups);
15805 @@ -251,6 +262,9 @@ struct task_group {
15806         /* runqueue "owned" by this group on each cpu */
15807         struct cfs_rq **cfs_rq;
15808         unsigned long shares;
15809 +#ifdef CONFIG_CFS_HARD_LIMITS
15810 +       struct cfs_bandwidth cfs_bandwidth;
15811 +#endif
15812  #endif
15813  
15814  #ifdef CONFIG_RT_GROUP_SCHED
15815 @@ -404,6 +418,19 @@ struct cfs_rq {
15816         unsigned long rq_weight;
15817  #endif
15818  #endif
15819 +#ifdef CONFIG_CFS_HARD_LIMITS
15820 +       /* set when the group is throttled  on this cpu */
15821 +       int cfs_throttled;
15822 +
15823 +       /* runtime currently consumed by the group on this rq */
15824 +       u64 cfs_time;
15825 +
15826 +       /* runtime available to the group on this rq */
15827 +       u64 cfs_runtime;
15828 +
15829 +       /* Protects the cfs runtime related fields of this cfs_rq */
15830 +       spinlock_t cfs_runtime_lock;
15831 +#endif
15832  };
15833  
15834  /* Real-Time classes' related field in a runqueue: */
15835 @@ -1586,6 +1613,7 @@ static void update_group_shares_cpu(stru
15836         }
15837  }
15838  
15839 +static inline int cfs_rq_throttled(struct cfs_rq *cfs_rq);
15840  /*
15841   * Re-compute the task group their per cpu shares over the given domain.
15842   * This needs to be done in a bottom-up fashion because the rq weight of a
15843 @@ -1614,8 +1642,10 @@ static int tg_shares_up(struct task_grou
15844                  * If there are currently no tasks on the cpu pretend there
15845                  * is one of average load so that when a new task gets to
15846                  * run here it will not get delayed by group starvation.
15847 +                * Also if the group is throttled on this cpu, pretend that
15848 +                * it has no tasks.
15849                  */
15850 -               if (!weight)
15851 +               if (!weight || cfs_rq_throttled(tg->cfs_rq[i]))
15852                         weight = NICE_0_LOAD;
15853  
15854                 sum_weight += weight;
15855 @@ -1792,6 +1822,175 @@ static void cfs_rq_set_shares(struct cfs
15856  static void calc_load_account_active(struct rq *this_rq);
15857  static void update_sysctl(void);
15858  
15859 +
15860 +#if defined(CONFIG_RT_GROUP_SCHED) || defined(CONFIG_FAIR_GROUP_SCHED)
15861 +
15862 +#ifdef CONFIG_SMP
15863 +static inline const struct cpumask *sched_bw_period_mask(void)
15864 +{
15865 +       return cpu_rq(smp_processor_id())->rd->span;
15866 +}
15867 +#else /* !CONFIG_SMP */
15868 +static inline const struct cpumask *sched_bw_period_mask(void)
15869 +{
15870 +       return cpu_online_mask;
15871 +}
15872 +#endif /* CONFIG_SMP */
15873 +
15874 +#else
15875 +static inline const struct cpumask *sched_bw_period_mask(void)
15876 +{
15877 +       return cpu_online_mask;
15878 +}
15879 +
15880 +#endif
15881 +
15882 +#ifdef CONFIG_FAIR_GROUP_SCHED
15883 +#ifdef CONFIG_CFS_HARD_LIMITS
15884 +
15885 +/*
15886 + * Runtime allowed for a cfs group before it is hard limited.
15887 + * default: Infinite which means no hard limiting.
15888 + */
15889 +u64 sched_cfs_runtime = RUNTIME_INF;
15890 +
15891 +/*
15892 + * period over which we hard limit the cfs group's bandwidth.
15893 + * default: 0.5s
15894 + */
15895 +u64 sched_cfs_period = 500000;
15896 +
15897 +static inline u64 global_cfs_period(void)
15898 +{
15899 +       return sched_cfs_period * NSEC_PER_USEC;
15900 +}
15901 +
15902 +static inline u64 global_cfs_runtime(void)
15903 +{
15904 +       return RUNTIME_INF;
15905 +}
15906 +
15907 +void do_sched_cfs_period_timer(struct cfs_bandwidth *cfs_b);
15908 +
15909 +static inline void cfs_rq_runtime_lock(struct cfs_rq *cfs_rq)
15910 +{
15911 +       spin_lock(&cfs_rq->cfs_runtime_lock);
15912 +}
15913 +
15914 +static inline void cfs_rq_runtime_unlock(struct cfs_rq *cfs_rq)
15915 +{
15916 +       spin_unlock(&cfs_rq->cfs_runtime_lock);
15917 +}
15918 +
15919 +/*
15920 + * Refresh the runtimes of the throttled groups.
15921 + * But nothing much to do now, will populate this in later patches.
15922 + */
15923 +static enum hrtimer_restart sched_cfs_period_timer(struct hrtimer *timer)
15924 +{
15925 +       struct cfs_bandwidth *cfs_b =
15926 +               container_of(timer, struct cfs_bandwidth, cfs_period_timer);
15927 +
15928 +       do_sched_cfs_period_timer(cfs_b);
15929 +       hrtimer_add_expires_ns(timer, ktime_to_ns(cfs_b->cfs_period));
15930 +       return HRTIMER_RESTART;
15931 +}
15932 +
15933 +/*
15934 + * TODO: Check if this kind of timer setup is sufficient for cfs or
15935 + * should we do what rt is doing.
15936 + */
15937 +static void start_cfs_bandwidth(struct task_group *tg)
15938 +{
15939 +       struct cfs_bandwidth *cfs_b = &tg->cfs_bandwidth;
15940 +
15941 +       /*
15942 +        * Timer isn't setup for groups with infinite runtime
15943 +        */
15944 +       if (cfs_b->cfs_runtime == RUNTIME_INF)
15945 +               return;
15946 +
15947 +       if (hrtimer_active(&cfs_b->cfs_period_timer))
15948 +               return;
15949 +
15950 +       hrtimer_start_range_ns(&cfs_b->cfs_period_timer, cfs_b->cfs_period,
15951 +                       0, HRTIMER_MODE_REL);
15952 +}
15953 +
15954 +static void init_cfs_bandwidth(struct task_group *tg)
15955 +{
15956 +       struct cfs_bandwidth *cfs_b = &tg->cfs_bandwidth;
15957 +
15958 +       cfs_b->cfs_period = ns_to_ktime(global_cfs_period());
15959 +       cfs_b->cfs_runtime = global_cfs_runtime();
15960 +
15961 +       spin_lock_init(&cfs_b->cfs_runtime_lock);
15962 +
15963 +       hrtimer_init(&cfs_b->cfs_period_timer,
15964 +                       CLOCK_MONOTONIC, HRTIMER_MODE_REL);
15965 +       cfs_b->cfs_period_timer.function = &sched_cfs_period_timer;
15966 +}
15967 +
15968 +static inline void destroy_cfs_bandwidth(struct task_group *tg)
15969 +{
15970 +       hrtimer_cancel(&tg->cfs_bandwidth.cfs_period_timer);
15971 +}
15972 +
15973 +static void init_cfs_hard_limits(struct cfs_rq *cfs_rq, struct task_group *tg)
15974 +{
15975 +       cfs_rq->cfs_time = 0;
15976 +       cfs_rq->cfs_throttled = 0;
15977 +       cfs_rq->cfs_runtime = tg->cfs_bandwidth.cfs_runtime;
15978 +       spin_lock_init(&cfs_rq->cfs_runtime_lock);
15979 +}
15980 +
15981 +#else /* !CONFIG_CFS_HARD_LIMITS */
15982 +
15983 +static void init_cfs_bandwidth(struct task_group *tg)
15984 +{
15985 +       return;
15986 +}
15987 +
15988 +static inline void destroy_cfs_bandwidth(struct task_group *tg)
15989 +{
15990 +       return;
15991 +}
15992 +
15993 +static void init_cfs_hard_limits(struct cfs_rq *cfs_rq, struct task_group *tg)
15994 +{
15995 +       return;
15996 +}
15997 +
15998 +static inline void cfs_rq_runtime_lock(struct cfs_rq *cfs_rq)
15999 +{
16000 +       return;
16001 +}
16002 +
16003 +static inline void cfs_rq_runtime_unlock(struct cfs_rq *cfs_rq)
16004 +{
16005 +       return;
16006 +}
16007 +
16008 +#endif /* CONFIG_CFS_HARD_LIMITS */
16009 +#else /* !CONFIG_FAIR_GROUP_SCHED */
16010 +
16011 +static inline void cfs_rq_runtime_lock(struct cfs_rq *cfs_rq)
16012 +{
16013 +       return;
16014 +}
16015 +
16016 +static inline void cfs_rq_runtime_unlock(struct cfs_rq *cfs_rq)
16017 +{
16018 +       return;
16019 +}
16020 +
16021 +static inline int cfs_rq_throttled(struct cfs_rq *cfs_rq)
16022 +{
16023 +       return 0;
16024 +}
16025 +
16026 +#endif /* CONFIG_FAIR_GROUP_SCHED */
16027 +
16028  static inline void __set_task_cpu(struct task_struct *p, unsigned int cpu)
16029  {
16030         set_task_rq(p, cpu);
16031 @@ -3129,9 +3328,17 @@ EXPORT_SYMBOL(avenrun);
16032   */
16033  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
16034  {
16035 -       loads[0] = (avenrun[0] + offset) << shift;
16036 -       loads[1] = (avenrun[1] + offset) << shift;
16037 -       loads[2] = (avenrun[2] + offset) << shift;
16038 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
16039 +               struct vx_info *vxi = current_vx_info();
16040 +
16041 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
16042 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
16043 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
16044 +       } else {
16045 +               loads[0] = (avenrun[0] + offset) << shift;
16046 +               loads[1] = (avenrun[1] + offset) << shift;
16047 +               loads[2] = (avenrun[2] + offset) << shift;
16048 +       }
16049  }
16050  
16051  static unsigned long
16052 @@ -5245,16 +5452,19 @@ void account_user_time(struct task_struc
16053                        cputime_t cputime_scaled)
16054  {
16055         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
16056 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
16057         cputime64_t tmp;
16058 +       int nice = (TASK_NICE(p) > 0);
16059  
16060         /* Add user time to process. */
16061         p->utime = cputime_add(p->utime, cputime);
16062         p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
16063 +       vx_account_user(vxi, cputime, nice);
16064         account_group_user_time(p, cputime);
16065  
16066         /* Add user time to cpustat. */
16067         tmp = cputime_to_cputime64(cputime);
16068 -       if (TASK_NICE(p) > 0)
16069 +       if (nice)
16070                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
16071         else
16072                 cpustat->user = cputime64_add(cpustat->user, tmp);
16073 @@ -5300,6 +5510,7 @@ void account_system_time(struct task_str
16074                          cputime_t cputime, cputime_t cputime_scaled)
16075  {
16076         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
16077 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
16078         cputime64_t tmp;
16079  
16080         if ((p->flags & PF_VCPU) && (irq_count() - hardirq_offset == 0)) {
16081 @@ -5310,6 +5521,7 @@ void account_system_time(struct task_str
16082         /* Add system time to process. */
16083         p->stime = cputime_add(p->stime, cputime);
16084         p->stimescaled = cputime_add(p->stimescaled, cputime_scaled);
16085 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
16086         account_group_system_time(p, cputime);
16087  
16088         /* Add system time to cpustat. */
16089 @@ -6393,7 +6605,7 @@ SYSCALL_DEFINE1(nice, int, increment)
16090                 nice = 19;
16091  
16092         if (increment < 0 && !can_nice(current, nice))
16093 -               return -EPERM;
16094 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
16095  
16096         retval = security_task_setnice(current, nice);
16097         if (retval)
16098 @@ -9470,6 +9682,32 @@ static int update_sched_domains(struct n
16099  }
16100  #endif
16101  
16102 +#ifdef CONFIG_SMP
16103 +static void disable_runtime(struct rq *rq)
16104 +{
16105 +       unsigned long flags;
16106 +
16107 +       spin_lock_irqsave(&rq->lock, flags);
16108 +#if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_CFS_HARD_LIMITS)
16109 +       disable_runtime_cfs(rq);
16110 +#endif
16111 +       disable_runtime_rt(rq);
16112 +       spin_unlock_irqrestore(&rq->lock, flags);
16113 +}
16114 +
16115 +static void enable_runtime(struct rq *rq)
16116 +{
16117 +       unsigned long flags;
16118 +
16119 +       spin_lock_irqsave(&rq->lock, flags);
16120 +#if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_CFS_HARD_LIMITS)
16121 +       enable_runtime_cfs(rq);
16122 +#endif
16123 +       enable_runtime_rt(rq);
16124 +       spin_unlock_irqrestore(&rq->lock, flags);
16125 +}
16126 +#endif
16127 +
16128  static int update_runtime(struct notifier_block *nfb,
16129                                 unsigned long action, void *hcpu)
16130  {
16131 @@ -9602,6 +9840,7 @@ static void init_tg_cfs_entry(struct tas
16132         struct rq *rq = cpu_rq(cpu);
16133         tg->cfs_rq[cpu] = cfs_rq;
16134         init_cfs_rq(cfs_rq, rq);
16135 +       init_cfs_hard_limits(cfs_rq, tg);
16136         cfs_rq->tg = tg;
16137         if (add)
16138                 list_add(&cfs_rq->leaf_cfs_rq_list, &rq->leaf_cfs_rq_list);
16139 @@ -9710,6 +9949,10 @@ void __init sched_init(void)
16140                         global_rt_period(), global_rt_runtime());
16141  #endif /* CONFIG_RT_GROUP_SCHED */
16142  
16143 +#ifdef CONFIG_FAIR_GROUP_SCHED
16144 +       init_cfs_bandwidth(&init_task_group);
16145 +#endif
16146 +
16147  #ifdef CONFIG_CGROUP_SCHED
16148         list_add(&init_task_group.list, &task_groups);
16149         INIT_LIST_HEAD(&init_task_group.children);
16150 @@ -9731,6 +9974,7 @@ void __init sched_init(void)
16151                 init_cfs_rq(&rq->cfs, rq);
16152                 init_rt_rq(&rq->rt, rq);
16153  #ifdef CONFIG_FAIR_GROUP_SCHED
16154 +               init_cfs_hard_limits(&rq->cfs, &init_task_group);
16155                 init_task_group.shares = init_task_group_load;
16156                 INIT_LIST_HEAD(&rq->leaf_cfs_rq_list);
16157  #ifdef CONFIG_CGROUP_SCHED
16158 @@ -9992,6 +10236,7 @@ static void free_fair_sched_group(struct
16159  {
16160         int i;
16161  
16162 +       destroy_cfs_bandwidth(tg);
16163         for_each_possible_cpu(i) {
16164                 if (tg->cfs_rq)
16165                         kfree(tg->cfs_rq[i]);
16166 @@ -10018,6 +10263,7 @@ int alloc_fair_sched_group(struct task_g
16167         if (!tg->se)
16168                 goto err;
16169  
16170 +       init_cfs_bandwidth(tg);
16171         tg->shares = NICE_0_LOAD;
16172  
16173         for_each_possible_cpu(i) {
16174 @@ -10734,6 +10980,100 @@ static u64 cpu_shares_read_u64(struct cg
16175  
16176         return (u64) tg->shares;
16177  }
16178 +
16179 +#ifdef CONFIG_CFS_HARD_LIMITS
16180 +
16181 +static int tg_set_cfs_bandwidth(struct task_group *tg,
16182 +               u64 cfs_period, u64 cfs_runtime)
16183 +{
16184 +       int i;
16185 +
16186 +       spin_lock_irq(&tg->cfs_bandwidth.cfs_runtime_lock);
16187 +       tg->cfs_bandwidth.cfs_period = ns_to_ktime(cfs_period);
16188 +       tg->cfs_bandwidth.cfs_runtime = cfs_runtime;
16189 +
16190 +       for_each_possible_cpu(i) {
16191 +               struct cfs_rq *cfs_rq = tg->cfs_rq[i];
16192 +
16193 +               cfs_rq_runtime_lock(cfs_rq);
16194 +               cfs_rq->cfs_runtime = cfs_runtime;
16195 +               cfs_rq_runtime_unlock(cfs_rq);
16196 +       }
16197 +
16198 +       start_cfs_bandwidth(tg);
16199 +       spin_unlock_irq(&tg->cfs_bandwidth.cfs_runtime_lock);
16200 +       return 0;
16201 +}
16202 +
16203 +int tg_set_cfs_runtime(struct task_group *tg, long cfs_runtime_us)
16204 +{
16205 +       u64 cfs_runtime, cfs_period;
16206 +
16207 +       cfs_period = ktime_to_ns(tg->cfs_bandwidth.cfs_period);
16208 +       cfs_runtime = (u64)cfs_runtime_us * NSEC_PER_USEC;
16209 +       if (cfs_runtime_us < 0)
16210 +               cfs_runtime = RUNTIME_INF;
16211 +
16212 +       return tg_set_cfs_bandwidth(tg, cfs_period, cfs_runtime);
16213 +}
16214 +
16215 +long tg_get_cfs_runtime(struct task_group *tg)
16216 +{
16217 +       u64 cfs_runtime_us;
16218 +
16219 +       if (tg->cfs_bandwidth.cfs_runtime == RUNTIME_INF)
16220 +               return -1;
16221 +
16222 +       cfs_runtime_us = tg->cfs_bandwidth.cfs_runtime;
16223 +       do_div(cfs_runtime_us, NSEC_PER_USEC);
16224 +       return cfs_runtime_us;
16225 +}
16226 +
16227 +int tg_set_cfs_period(struct task_group *tg, long cfs_period_us)
16228 +{
16229 +       u64 cfs_runtime, cfs_period;
16230 +
16231 +       cfs_period = (u64)cfs_period_us * NSEC_PER_USEC;
16232 +       cfs_runtime = tg->cfs_bandwidth.cfs_runtime;
16233 +
16234 +       if (cfs_period == 0)
16235 +               return -EINVAL;
16236 +
16237 +       return tg_set_cfs_bandwidth(tg, cfs_period, cfs_runtime);
16238 +}
16239 +
16240 +long tg_get_cfs_period(struct task_group *tg)
16241 +{
16242 +       u64 cfs_period_us;
16243 +
16244 +       cfs_period_us = ktime_to_ns(tg->cfs_bandwidth.cfs_period);
16245 +       do_div(cfs_period_us, NSEC_PER_USEC);
16246 +       return cfs_period_us;
16247 +}
16248 +
16249 +static s64 cpu_cfs_runtime_read_s64(struct cgroup *cgrp, struct cftype *cft)
16250 +{
16251 +       return tg_get_cfs_runtime(cgroup_tg(cgrp));
16252 +}
16253 +
16254 +static int cpu_cfs_runtime_write_s64(struct cgroup *cgrp, struct cftype *cftype,
16255 +                               s64 cfs_runtime_us)
16256 +{
16257 +       return tg_set_cfs_runtime(cgroup_tg(cgrp), cfs_runtime_us);
16258 +}
16259 +
16260 +static u64 cpu_cfs_period_read_u64(struct cgroup *cgrp, struct cftype *cft)
16261 +{
16262 +       return tg_get_cfs_period(cgroup_tg(cgrp));
16263 +}
16264 +
16265 +static int cpu_cfs_period_write_u64(struct cgroup *cgrp, struct cftype *cftype,
16266 +                               u64 cfs_period_us)
16267 +{
16268 +       return tg_set_cfs_period(cgroup_tg(cgrp), cfs_period_us);
16269 +}
16270 +
16271 +#endif /* CONFIG_CFS_HARD_LIMITS */
16272  #endif /* CONFIG_FAIR_GROUP_SCHED */
16273  
16274  #ifdef CONFIG_RT_GROUP_SCHED
16275 @@ -10767,6 +11107,18 @@ static struct cftype cpu_files[] = {
16276                 .read_u64 = cpu_shares_read_u64,
16277                 .write_u64 = cpu_shares_write_u64,
16278         },
16279 +#ifdef CONFIG_CFS_HARD_LIMITS
16280 +       {
16281 +               .name = "cfs_runtime_us",
16282 +               .read_s64 = cpu_cfs_runtime_read_s64,
16283 +               .write_s64 = cpu_cfs_runtime_write_s64,
16284 +       },
16285 +       {
16286 +               .name = "cfs_period_us",
16287 +               .read_u64 = cpu_cfs_period_read_u64,
16288 +               .write_u64 = cpu_cfs_period_write_u64,
16289 +       },
16290 +#endif /* CONFIG_CFS_HARD_LIMITS */
16291  #endif
16292  #ifdef CONFIG_RT_GROUP_SCHED
16293         {
16294 diff -NurpP --minimal linux-2.6.32.56/kernel/sched_debug.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/sched_debug.c
16295 --- linux-2.6.32.56/kernel/sched_debug.c        2012-02-09 10:22:36.000000000 +0100
16296 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/sched_debug.c        2011-06-10 13:03:02.000000000 +0200
16297 @@ -80,6 +80,11 @@ static void print_cfs_group_stats(struct
16298         PN(se->wait_max);
16299         PN(se->wait_sum);
16300         P(se->wait_count);
16301 +#ifdef CONFIG_CFS_HARD_LIMITS
16302 +       PN(se->throttle_max);
16303 +       PN(se->throttle_sum);
16304 +       P(se->throttle_count);
16305 +#endif
16306  #endif
16307         P(se->load.weight);
16308  #undef PN
16309 @@ -209,6 +214,16 @@ void print_cfs_rq(struct seq_file *m, in
16310  #ifdef CONFIG_SMP
16311         SEQ_printf(m, "  .%-30s: %lu\n", "shares", cfs_rq->shares);
16312  #endif
16313 +#ifdef CONFIG_CFS_HARD_LIMITS
16314 +       spin_lock_irqsave(&rq->lock, flags);
16315 +       SEQ_printf(m, "  .%-30s: %d\n", "cfs_throttled",
16316 +                       cfs_rq->cfs_throttled);
16317 +       SEQ_printf(m, "  .%-30s: %Ld.%06ld\n", "cfs_time",
16318 +                       SPLIT_NS(cfs_rq->cfs_time));
16319 +       SEQ_printf(m, "  .%-30s: %Ld.%06ld\n", "cfs_runtime",
16320 +                       SPLIT_NS(cfs_rq->cfs_runtime));
16321 +       spin_unlock_irqrestore(&rq->lock, flags);
16322 +#endif /* CONFIG_CFS_HARD_LIMITS */
16323         print_cfs_group_stats(m, cpu, cfs_rq->tg);
16324  #endif
16325  }
16326 @@ -309,7 +324,7 @@ static int sched_debug_show(struct seq_f
16327         u64 now = ktime_to_ns(ktime_get());
16328         int cpu;
16329  
16330 -       SEQ_printf(m, "Sched Debug Version: v0.09, %s %.*s\n",
16331 +       SEQ_printf(m, "Sched Debug Version: v0.10, %s %.*s\n",
16332                 init_utsname()->release,
16333                 (int)strcspn(init_utsname()->version, " "),
16334                 init_utsname()->version);
16335 diff -NurpP --minimal linux-2.6.32.56/kernel/sched_fair.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/sched_fair.c
16336 --- linux-2.6.32.56/kernel/sched_fair.c 2012-02-09 10:22:36.000000000 +0100
16337 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/sched_fair.c 2011-06-10 13:08:20.000000000 +0200
16338 @@ -192,7 +192,308 @@ find_matching_se(struct sched_entity **s
16339         }
16340  }
16341  
16342 -#else  /* !CONFIG_FAIR_GROUP_SCHED */
16343 +#ifdef CONFIG_CFS_HARD_LIMITS
16344 +
16345 +static inline void update_stats_throttle_start(struct cfs_rq *cfs_rq,
16346 +                       struct sched_entity *se)
16347 +{
16348 +       schedstat_set(se->throttle_start, rq_of(cfs_rq)->clock);
16349 +}
16350 +
16351 +static inline void update_stats_throttle_end(struct cfs_rq *cfs_rq,
16352 +                       struct sched_entity *se)
16353 +{
16354 +       schedstat_set(se->throttle_max, max(se->throttle_max,
16355 +                       rq_of(cfs_rq)->clock - se->throttle_start));
16356 +       schedstat_set(se->throttle_count, se->throttle_count + 1);
16357 +       schedstat_set(se->throttle_sum, se->throttle_sum +
16358 +                       rq_of(cfs_rq)->clock - se->throttle_start);
16359 +       schedstat_set(se->throttle_start, 0);
16360 +}
16361 +
16362 +static inline
16363 +struct cfs_rq *sched_cfs_period_cfs_rq(struct cfs_bandwidth *cfs_b, int cpu)
16364 +{
16365 +       return container_of(cfs_b, struct task_group,
16366 +                       cfs_bandwidth)->cfs_rq[cpu];
16367 +}
16368 +
16369 +static inline int cfs_rq_throttled(struct cfs_rq *cfs_rq)
16370 +{
16371 +       return cfs_rq->cfs_throttled;
16372 +}
16373 +
16374 +#ifdef CONFIG_SMP
16375 +/*
16376 + * Ensure this RQ takes back all the runtime it lend to its neighbours.
16377 + */
16378 +static void disable_runtime_cfs(struct rq *rq)
16379 +{
16380 +       struct root_domain *rd = rq->rd;
16381 +       struct cfs_rq *cfs_rq;
16382 +
16383 +       if (unlikely(!scheduler_running))
16384 +               return;
16385 +
16386 +       for_each_leaf_cfs_rq(rq, cfs_rq) {
16387 +               struct cfs_bandwidth *cfs_b = &cfs_rq->tg->cfs_bandwidth;
16388 +               s64 want;
16389 +               int i;
16390 +
16391 +               spin_lock(&cfs_b->cfs_runtime_lock);
16392 +               spin_lock(&cfs_rq->cfs_runtime_lock);
16393 +
16394 +               /*
16395 +                * Either we're all are infinity and nobody needs to borrow,
16396 +                * or we're already disabled and this have nothing to do, or
16397 +                * we have exactly the right amount of runtime to take out.
16398 +                */
16399 +                if (cfs_rq->cfs_runtime == RUNTIME_INF ||
16400 +                               cfs_rq->cfs_runtime == cfs_b->cfs_runtime)
16401 +                       goto balanced;
16402 +               spin_unlock(&cfs_rq->cfs_runtime_lock);
16403 +
16404 +               /*
16405 +                * Calculate the difference between what we started out with
16406 +                * and what we current have, that's the amount of runtime
16407 +                * we lend and now have to reclaim.
16408 +                */
16409 +                want = cfs_b->cfs_runtime - cfs_rq->cfs_runtime;
16410 +
16411 +               /*
16412 +                * Greedy reclaim, take back as much as possible.
16413 +                */
16414 +               for_each_cpu(i, rd->span) {
16415 +                       struct cfs_rq *iter = sched_cfs_period_cfs_rq(cfs_b, i);
16416 +                       s64 diff;
16417 +
16418 +                       /*
16419 +                        * Can't reclaim from ourselves or disabled runqueues.
16420 +                        */
16421 +                       if (iter == cfs_rq || iter->cfs_runtime == RUNTIME_INF)
16422 +                               continue;
16423 +
16424 +                       spin_lock(&iter->cfs_runtime_lock);
16425 +                       if (want > 0) {
16426 +                               diff = min_t(s64, iter->cfs_runtime, want);
16427 +                               iter->cfs_runtime -= diff;
16428 +                               want -= diff;
16429 +                       } else {
16430 +                               iter->cfs_runtime -= want;
16431 +                               want -= want;
16432 +                       }
16433 +
16434 +                       spin_unlock(&iter->cfs_runtime_lock);
16435 +                       if (!want)
16436 +                               break;
16437 +               }
16438 +
16439 +               spin_lock(&cfs_rq->cfs_runtime_lock);
16440 +               /*
16441 +                * We cannot be left wanting - that would mean some
16442 +                * runtime leaked out of the system.
16443 +                */
16444 +               BUG_ON(want);
16445 +balanced:
16446 +               /*
16447 +                * Disable all the borrow logic by pretending we have infinite
16448 +                * runtime - in which case borrowing doesn't make sense.
16449 +                */
16450 +                cfs_rq->cfs_runtime = RUNTIME_INF;
16451 +                spin_unlock(&cfs_rq->cfs_runtime_lock);
16452 +                spin_unlock(&cfs_b->cfs_runtime_lock);
16453 +       }
16454 +}
16455 +
16456 +static void enable_runtime_cfs(struct rq *rq)
16457 +{
16458 +       struct cfs_rq *cfs_rq;
16459 +
16460 +       if (unlikely(!scheduler_running))
16461 +               return;
16462 +
16463 +       /*
16464 +        * Reset each runqueue's bandwidth settings
16465 +        */
16466 +       for_each_leaf_cfs_rq(rq, cfs_rq) {
16467 +               struct cfs_bandwidth *cfs_b = &cfs_rq->tg->cfs_bandwidth;
16468 +
16469 +               spin_lock(&cfs_b->cfs_runtime_lock);
16470 +               spin_lock(&cfs_rq->cfs_runtime_lock);
16471 +               cfs_rq->cfs_runtime = cfs_b->cfs_runtime;
16472 +               cfs_rq->cfs_time = 0;
16473 +               cfs_rq->cfs_throttled = 0;
16474 +               spin_unlock(&cfs_rq->cfs_runtime_lock);
16475 +               spin_unlock(&cfs_b->cfs_runtime_lock);
16476 +       }
16477 +}
16478 +
16479 +/*
16480 + * Ran out of runtime, check if we can borrow some from others
16481 + * instead of getting throttled right away.
16482 + */
16483 +static void do_cfs_balance_runtime(struct cfs_rq *cfs_rq)
16484 +{
16485 +       struct cfs_bandwidth *cfs_b = &cfs_rq->tg->cfs_bandwidth;
16486 +       const struct cpumask *span = sched_bw_period_mask();
16487 +       int i, weight;
16488 +       u64 cfs_period;
16489 +
16490 +       weight = cpumask_weight(span);
16491 +       spin_lock(&cfs_b->cfs_runtime_lock);
16492 +       cfs_period = ktime_to_ns(cfs_b->cfs_period);
16493 +
16494 +       for_each_cpu(i, span) {
16495 +               struct cfs_rq *borrow_cfs_rq =
16496 +                               sched_cfs_period_cfs_rq(cfs_b, i);
16497 +               s64 diff;
16498 +
16499 +               if (borrow_cfs_rq == cfs_rq)
16500 +                       continue;
16501 +
16502 +               cfs_rq_runtime_lock(borrow_cfs_rq);
16503 +               if (borrow_cfs_rq->cfs_runtime == RUNTIME_INF) {
16504 +                       cfs_rq_runtime_unlock(borrow_cfs_rq);
16505 +                       continue;
16506 +               }
16507 +
16508 +               diff = borrow_cfs_rq->cfs_runtime - borrow_cfs_rq->cfs_time;
16509 +               if (diff > 0) {
16510 +                       diff = div_u64((u64)diff, weight);
16511 +                       if (cfs_rq->cfs_runtime + diff > cfs_period)
16512 +                               diff = cfs_period - cfs_rq->cfs_runtime;
16513 +                       borrow_cfs_rq->cfs_runtime -= diff;
16514 +                       cfs_rq->cfs_runtime += diff;
16515 +                       if (cfs_rq->cfs_runtime == cfs_period) {
16516 +                               cfs_rq_runtime_unlock(borrow_cfs_rq);
16517 +                               break;
16518 +                       }
16519 +               }
16520 +               cfs_rq_runtime_unlock(borrow_cfs_rq);
16521 +       }
16522 +       spin_unlock(&cfs_b->cfs_runtime_lock);
16523 +}
16524 +
16525 +/*
16526 + * Called with rq->runtime_lock held.
16527 + */
16528 +static void cfs_balance_runtime(struct cfs_rq *cfs_rq)
16529 +{
16530 +       cfs_rq_runtime_unlock(cfs_rq);
16531 +       do_cfs_balance_runtime(cfs_rq);
16532 +       cfs_rq_runtime_lock(cfs_rq);
16533 +}
16534 +
16535 +#else /* !CONFIG_SMP */
16536 +
16537 +static void cfs_balance_runtime(struct cfs_rq *cfs_rq)
16538 +{
16539 +       return;
16540 +}
16541 +#endif /* CONFIG_SMP */
16542 +
16543 +/*
16544 + * Check if group entity exceeded its runtime. If so, mark the cfs_rq as
16545 + * throttled mark the current task for reschedling.
16546 + */
16547 +static void sched_cfs_runtime_exceeded(struct sched_entity *se,
16548 +       struct task_struct *tsk_curr, unsigned long delta_exec)
16549 +{
16550 +       struct cfs_rq *cfs_rq;
16551 +
16552 +       cfs_rq = group_cfs_rq(se);
16553 +
16554 +       if (cfs_rq->cfs_runtime == RUNTIME_INF)
16555 +               return;
16556 +
16557 +       cfs_rq->cfs_time += delta_exec;
16558 +
16559 +       if (cfs_rq_throttled(cfs_rq))
16560 +               return;
16561 +
16562 +       if (cfs_rq->cfs_time > cfs_rq->cfs_runtime)
16563 +               cfs_balance_runtime(cfs_rq);
16564 +
16565 +       if (cfs_rq->cfs_time > cfs_rq->cfs_runtime) {
16566 +               cfs_rq->cfs_throttled = 1;
16567 +               update_stats_throttle_start(cfs_rq, se);
16568 +               resched_task(tsk_curr);
16569 +       }
16570 +}
16571 +
16572 +static inline void update_curr_group(struct sched_entity *curr,
16573 +               unsigned long delta_exec, struct task_struct *tsk_curr)
16574 +{
16575 +       sched_cfs_runtime_exceeded(curr, tsk_curr, delta_exec);
16576 +}
16577 +
16578 +static void enqueue_entity_locked(struct cfs_rq *cfs_rq,
16579 +               struct sched_entity *se, int flags);
16580 +
16581 +static void enqueue_throttled_entity(struct rq *rq, struct sched_entity *se)
16582 +{
16583 +       for_each_sched_entity(se) {
16584 +               struct cfs_rq *gcfs_rq = group_cfs_rq(se);
16585 +
16586 +               if (se->on_rq || cfs_rq_throttled(gcfs_rq) ||
16587 +                               !gcfs_rq->nr_running)
16588 +                       break;
16589 +               enqueue_entity_locked(cfs_rq_of(se), se, 0);
16590 +       }
16591 +}
16592 +
16593 +/*
16594 + * Refresh runtimes of all cfs_rqs in this group, i,e.,
16595 + * refresh runtimes of the representative cfs_rq of this
16596 + * tg on all cpus. Enqueue any throttled entity back.
16597 + */
16598 +void do_sched_cfs_period_timer(struct cfs_bandwidth *cfs_b)
16599 +{
16600 +       int i;
16601 +       const struct cpumask *span = sched_bw_period_mask();
16602 +       unsigned long flags;
16603 +
16604 +       for_each_cpu(i, span) {
16605 +               struct rq *rq = cpu_rq(i);
16606 +               struct cfs_rq *cfs_rq = sched_cfs_period_cfs_rq(cfs_b, i);
16607 +               struct sched_entity *se = cfs_rq->tg->se[i];
16608 +
16609 +               spin_lock_irqsave(&rq->lock, flags);
16610 +               cfs_rq_runtime_lock(cfs_rq);
16611 +               cfs_rq->cfs_time = 0;
16612 +               if (cfs_rq_throttled(cfs_rq)) {
16613 +                       update_rq_clock(rq);
16614 +                       update_stats_throttle_end(cfs_rq, se);
16615 +                       cfs_rq->cfs_throttled = 0;
16616 +                       enqueue_throttled_entity(rq, se);
16617 +               }
16618 +               cfs_rq_runtime_unlock(cfs_rq);
16619 +               spin_unlock_irqrestore(&rq->lock, flags);
16620 +       }
16621 +}
16622 +
16623 +#else
16624 +
16625 +static inline void update_curr_group(struct sched_entity *curr,
16626 +               unsigned long delta_exec, struct task_struct *tsk_curr)
16627 +{
16628 +       return;
16629 +}
16630 +
16631 +static inline int cfs_rq_throttled(struct cfs_rq *cfs_rq)
16632 +{
16633 +       return 0;
16634 +}
16635 +
16636 +#endif /* CONFIG_CFS_HARD_LIMITS */
16637 +
16638 +#else  /* CONFIG_FAIR_GROUP_SCHED */
16639 +
16640 +static inline void update_curr_group(struct sched_entity *curr,
16641 +               unsigned long delta_exec, struct task_struct *tsk_curr)
16642 +{
16643 +       return;
16644 +}
16645  
16646  static inline struct task_struct *task_of(struct sched_entity *se)
16647  {
16648 @@ -254,7 +555,6 @@ find_matching_se(struct sched_entity **s
16649  
16650  #endif /* CONFIG_FAIR_GROUP_SCHED */
16651  
16652 -
16653  /**************************************************************
16654   * Scheduling class tree data structure manipulation methods:
16655   */
16656 @@ -493,14 +793,25 @@ __update_curr(struct cfs_rq *cfs_rq, str
16657         update_min_vruntime(cfs_rq);
16658  }
16659  
16660 -static void update_curr(struct cfs_rq *cfs_rq)
16661 +static void update_curr_task(struct sched_entity *curr,
16662 +               unsigned long delta_exec)
16663 +{
16664 +       struct task_struct *curtask = task_of(curr);
16665 +
16666 +       trace_sched_stat_runtime(curtask, delta_exec, curr->vruntime);
16667 +       cpuacct_charge(curtask, delta_exec);
16668 +       account_group_exec_runtime(curtask, delta_exec);
16669 +}
16670 +
16671 +static int update_curr_common(struct cfs_rq *cfs_rq, unsigned long *delta)
16672  {
16673         struct sched_entity *curr = cfs_rq->curr;
16674 -       u64 now = rq_of(cfs_rq)->clock_task;
16675 +       struct rq *rq = rq_of(cfs_rq);
16676 +       u64 now = rq->clock_task;
16677         unsigned long delta_exec;
16678  
16679         if (unlikely(!curr))
16680 -               return;
16681 +               return 1;
16682  
16683         /*
16684          * Get the amount of time the current task was running
16685 @@ -509,17 +820,29 @@ static void update_curr(struct cfs_rq *c
16686          */
16687         delta_exec = (unsigned long)(now - curr->exec_start);
16688         if (!delta_exec)
16689 -               return;
16690 +               return 1;
16691  
16692         __update_curr(cfs_rq, curr, delta_exec);
16693         curr->exec_start = now;
16694 +       *delta = delta_exec;
16695 +       return 0;
16696 +}
16697  
16698 -       if (entity_is_task(curr)) {
16699 -               struct task_struct *curtask = task_of(curr);
16700 +static void update_curr(struct cfs_rq *cfs_rq)
16701 +{
16702 +       struct sched_entity *curr = cfs_rq->curr;
16703 +       struct rq *rq = rq_of(cfs_rq);
16704 +       unsigned long delta_exec;
16705  
16706 -               trace_sched_stat_runtime(curtask, delta_exec, curr->vruntime);
16707 -               cpuacct_charge(curtask, delta_exec);
16708 -               account_group_exec_runtime(curtask, delta_exec);
16709 +       if (update_curr_common(cfs_rq, &delta_exec))
16710 +               return ;
16711 +
16712 +       if (entity_is_task(curr))
16713 +               update_curr_task(curr, delta_exec);
16714 +       else {
16715 +               cfs_rq_runtime_lock(group_cfs_rq(curr));
16716 +               update_curr_group(curr, delta_exec, rq->curr);
16717 +               cfs_rq_runtime_unlock(group_cfs_rq(curr));
16718         }
16719  }
16720  
16721 @@ -748,6 +1071,25 @@ place_entity(struct cfs_rq *cfs_rq, stru
16722  #define ENQUEUE_MIGRATE 2
16723  
16724  static void
16725 +enqueue_entity_common(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
16726 +{
16727 +       account_entity_enqueue(cfs_rq, se);
16728 +
16729 +       if (flags & ENQUEUE_WAKEUP) {
16730 +               place_entity(cfs_rq, se, 0);
16731 +               enqueue_sleeper(cfs_rq, se);
16732 +       }
16733 +
16734 +       update_stats_enqueue(cfs_rq, se);
16735 +       check_spread(cfs_rq, se);
16736 +       if (se != cfs_rq->curr)
16737 +               __enqueue_entity(cfs_rq, se);
16738 +
16739 +       if (entity_is_task(se))
16740 +               vx_activate_task(task_of(se));
16741 +}
16742 +
16743 +static void
16744  enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
16745  {
16746         /*
16747 @@ -761,17 +1103,17 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
16748          * Update run-time statistics of the 'current'.
16749          */
16750         update_curr(cfs_rq);
16751 -       account_entity_enqueue(cfs_rq, se);
16752 -
16753 -       if (flags & ENQUEUE_WAKEUP) {
16754 -               place_entity(cfs_rq, se, 0);
16755 -               enqueue_sleeper(cfs_rq, se);
16756 -       }
16757 +       enqueue_entity_common(cfs_rq, se, flags);
16758 +}
16759  
16760 -       update_stats_enqueue(cfs_rq, se);
16761 -       check_spread(cfs_rq, se);
16762 -       if (se != cfs_rq->curr)
16763 -               __enqueue_entity(cfs_rq, se);
16764 +static void enqueue_entity_locked(struct cfs_rq *cfs_rq,
16765 +               struct sched_entity *se, int flags)
16766 +{
16767 +       /*
16768 +        * Update run-time statistics of the 'current'.
16769 +        */
16770 +       // update_curr_locked(cfs_rq);
16771 +       enqueue_entity_common(cfs_rq, se, flags);
16772  }
16773  
16774  static void __clear_buddies(struct cfs_rq *cfs_rq, struct sched_entity *se)
16775 @@ -815,6 +1157,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
16776  
16777         if (se != cfs_rq->curr)
16778                 __dequeue_entity(cfs_rq, se);
16779 +       if (entity_is_task(se))
16780 +               vx_deactivate_task(task_of(se));
16781         account_entity_dequeue(cfs_rq, se);
16782         update_min_vruntime(cfs_rq);
16783  
16784 @@ -919,6 +1263,32 @@ static struct sched_entity *pick_next_en
16785         return se;
16786  }
16787  
16788 +/*
16789 + * Called from put_prev_entity()
16790 + * If a group entity (@se) is found to be throttled, it will not be put back
16791 + * on @cfs_rq, which is equivalent to dequeing it.
16792 + */
16793 +static int dequeue_throttled_entity(struct cfs_rq *cfs_rq,
16794 +               struct sched_entity *se)
16795 +{
16796 +       struct cfs_rq *gcfs_rq = group_cfs_rq(se);
16797 +
16798 +       if (entity_is_task(se))
16799 +               return 0;
16800 +
16801 +       cfs_rq_runtime_lock(gcfs_rq);
16802 +       if (!cfs_rq_throttled(gcfs_rq) && gcfs_rq->nr_running) {
16803 +               cfs_rq_runtime_unlock(gcfs_rq);
16804 +               return 0;
16805 +       }
16806 +
16807 +       __clear_buddies(cfs_rq, se);
16808 +       account_entity_dequeue(cfs_rq, se);
16809 +       cfs_rq->curr = NULL;
16810 +       cfs_rq_runtime_unlock(gcfs_rq);
16811 +       return 1;
16812 +}
16813 +
16814  static void put_prev_entity(struct cfs_rq *cfs_rq, struct sched_entity *prev)
16815  {
16816         /*
16817 @@ -930,6 +1300,8 @@ static void put_prev_entity(struct cfs_r
16818  
16819         check_spread(cfs_rq, prev);
16820         if (prev->on_rq) {
16821 +               if (dequeue_throttled_entity(cfs_rq, prev))
16822 +                       return;
16823                 update_stats_wait_start(cfs_rq, prev);
16824                 /* Put 'current' back into the tree. */
16825                 __enqueue_entity(cfs_rq, prev);
16826 @@ -1026,10 +1398,28 @@ static inline void hrtick_update(struct 
16827  }
16828  #endif
16829  
16830 +static int enqueue_group_entity(struct cfs_rq *cfs_rq, struct sched_entity *se,
16831 +                int flags)
16832 +{
16833 +       struct cfs_rq *gcfs_rq = group_cfs_rq(se);
16834 +       int ret = 0;
16835 +
16836 +       cfs_rq_runtime_lock(gcfs_rq);
16837 +       if (cfs_rq_throttled(gcfs_rq)) {
16838 +               ret = 1;
16839 +               goto out;
16840 +       }
16841 +       enqueue_entity_locked(cfs_rq, se, flags);
16842 +out:
16843 +       cfs_rq_runtime_unlock(gcfs_rq);
16844 +       return ret;
16845 +}
16846 +
16847  /*
16848   * The enqueue_task method is called before nr_running is
16849   * increased. Here we update the fair scheduling stats and
16850   * then put the task into the rbtree:
16851 + * Don't enqueue a throttled entity further into the hierarchy.
16852   */
16853  static void
16854  enqueue_task_fair(struct rq *rq, struct task_struct *p, int wakeup, bool head)
16855 @@ -1046,11 +1436,15 @@ enqueue_task_fair(struct rq *rq, struct 
16856         for_each_sched_entity(se) {
16857                 if (se->on_rq)
16858                         break;
16859 +
16860                 cfs_rq = cfs_rq_of(se);
16861 -               enqueue_entity(cfs_rq, se, flags);
16862 +               if (entity_is_task(se))
16863 +                       enqueue_entity(cfs_rq, se, flags);
16864 +               else
16865 +                       if (enqueue_group_entity(cfs_rq, se, flags))
16866 +                               break;
16867                 flags = ENQUEUE_WAKEUP;
16868         }
16869 -
16870         hrtick_update(rq);
16871  }
16872  
16873 @@ -1070,6 +1464,17 @@ static void dequeue_task_fair(struct rq 
16874                 /* Don't dequeue parent if it has other entities besides us */
16875                 if (cfs_rq->load.weight)
16876                         break;
16877 +
16878 +               /*
16879 +                * If this cfs_rq is throttled, then it is already
16880 +                * dequeued.
16881 +                */
16882 +               cfs_rq_runtime_lock(cfs_rq);
16883 +               if (cfs_rq_throttled(cfs_rq)) {
16884 +                       cfs_rq_runtime_unlock(cfs_rq);
16885 +                       break;
16886 +               }
16887 +               cfs_rq_runtime_unlock(cfs_rq);
16888                 sleep = 1;
16889         }
16890  
16891 @@ -1896,9 +2301,10 @@ load_balance_fair(struct rq *this_rq, in
16892                 u64 rem_load, moved_load;
16893  
16894                 /*
16895 -                * empty group
16896 +                * empty group or throttled group
16897                  */
16898 -               if (!busiest_cfs_rq->task_weight)
16899 +               if (!busiest_cfs_rq->task_weight ||
16900 +                               cfs_rq_throttled(busiest_cfs_rq))
16901                         continue;
16902  
16903                 rem_load = (u64)rem_load_move * busiest_weight;
16904 @@ -1947,6 +2353,12 @@ move_one_task_fair(struct rq *this_rq, i
16905  
16906         for_each_leaf_cfs_rq(busiest, busy_cfs_rq) {
16907                 /*
16908 +                * Don't move task from a throttled cfs_rq
16909 +                */
16910 +               if (cfs_rq_throttled(busy_cfs_rq))
16911 +                       continue;
16912 +
16913 +               /*
16914                  * pass busy_cfs_rq argument into
16915                  * load_balance_[start|next]_fair iterators
16916                  */
16917 diff -NurpP --minimal linux-2.6.32.56/kernel/sched_rt.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/sched_rt.c
16918 --- linux-2.6.32.56/kernel/sched_rt.c   2012-02-09 10:22:36.000000000 +0100
16919 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/sched_rt.c   2011-06-10 13:03:02.000000000 +0200
16920 @@ -235,18 +235,6 @@ static int rt_se_boosted(struct sched_rt
16921         return p->prio != p->normal_prio;
16922  }
16923  
16924 -#ifdef CONFIG_SMP
16925 -static inline const struct cpumask *sched_rt_period_mask(void)
16926 -{
16927 -       return cpu_rq(smp_processor_id())->rd->span;
16928 -}
16929 -#else
16930 -static inline const struct cpumask *sched_rt_period_mask(void)
16931 -{
16932 -       return cpu_online_mask;
16933 -}
16934 -#endif
16935 -
16936  static inline
16937  struct rt_rq *sched_rt_period_rt_rq(struct rt_bandwidth *rt_b, int cpu)
16938  {
16939 @@ -296,11 +284,6 @@ static inline int rt_rq_throttled(struct
16940         return rt_rq->rt_throttled;
16941  }
16942  
16943 -static inline const struct cpumask *sched_rt_period_mask(void)
16944 -{
16945 -       return cpu_online_mask;
16946 -}
16947 -
16948  static inline
16949  struct rt_rq *sched_rt_period_rt_rq(struct rt_bandwidth *rt_b, int cpu)
16950  {
16951 @@ -373,7 +356,7 @@ next:
16952  /*
16953   * Ensure this RQ takes back all the runtime it lend to its neighbours.
16954   */
16955 -static void __disable_runtime(struct rq *rq)
16956 +static void disable_runtime_rt(struct rq *rq)
16957  {
16958         struct root_domain *rd = rq->rd;
16959         struct rt_rq *rt_rq;
16960 @@ -450,16 +433,7 @@ balanced:
16961         }
16962  }
16963  
16964 -static void disable_runtime(struct rq *rq)
16965 -{
16966 -       unsigned long flags;
16967 -
16968 -       spin_lock_irqsave(&rq->lock, flags);
16969 -       __disable_runtime(rq);
16970 -       spin_unlock_irqrestore(&rq->lock, flags);
16971 -}
16972 -
16973 -static void __enable_runtime(struct rq *rq)
16974 +static void enable_runtime_rt(struct rq *rq)
16975  {
16976         struct rt_rq *rt_rq;
16977  
16978 @@ -482,15 +456,6 @@ static void __enable_runtime(struct rq *
16979         }
16980  }
16981  
16982 -static void enable_runtime(struct rq *rq)
16983 -{
16984 -       unsigned long flags;
16985 -
16986 -       spin_lock_irqsave(&rq->lock, flags);
16987 -       __enable_runtime(rq);
16988 -       spin_unlock_irqrestore(&rq->lock, flags);
16989 -}
16990 -
16991  static int balance_runtime(struct rt_rq *rt_rq)
16992  {
16993         int more = 0;
16994 @@ -518,7 +483,7 @@ static int do_sched_rt_period_timer(stru
16995         if (!rt_bandwidth_enabled() || rt_b->rt_runtime == RUNTIME_INF)
16996                 return 1;
16997  
16998 -       span = sched_rt_period_mask();
16999 +       span = sched_bw_period_mask();
17000         for_each_cpu(i, span) {
17001                 int enqueue = 0;
17002                 struct rt_rq *rt_rq = sched_rt_period_rt_rq(rt_b, i);
17003 @@ -1571,7 +1536,7 @@ static void rq_online_rt(struct rq *rq)
17004         if (rq->rt.overloaded)
17005                 rt_set_overload(rq);
17006  
17007 -       __enable_runtime(rq);
17008 +       enable_runtime_rt(rq);
17009  
17010         cpupri_set(&rq->rd->cpupri, rq->cpu, rq->rt.highest_prio.curr);
17011  }
17012 @@ -1582,7 +1547,7 @@ static void rq_offline_rt(struct rq *rq)
17013         if (rq->rt.overloaded)
17014                 rt_clear_overload(rq);
17015  
17016 -       __disable_runtime(rq);
17017 +       disable_runtime_rt(rq);
17018  
17019         cpupri_set(&rq->rd->cpupri, rq->cpu, CPUPRI_INVALID);
17020  }
17021 diff -NurpP --minimal linux-2.6.32.56/kernel/signal.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/signal.c
17022 --- linux-2.6.32.56/kernel/signal.c     2012-02-09 10:22:36.000000000 +0100
17023 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/signal.c     2011-06-10 13:03:02.000000000 +0200
17024 @@ -27,6 +27,8 @@
17025  #include <linux/freezer.h>
17026  #include <linux/pid_namespace.h>
17027  #include <linux/nsproxy.h>
17028 +#include <linux/vs_context.h>
17029 +#include <linux/vs_pid.h>
17030  #include <trace/events/sched.h>
17031  
17032  #include <asm/param.h>
17033 @@ -598,6 +600,14 @@ static int check_kill_permission(int sig
17034         if (!valid_signal(sig))
17035                 return -EINVAL;
17036  
17037 +       if ((info != SEND_SIG_NOINFO) &&
17038 +               (is_si_special(info) || !SI_FROMUSER(info)))
17039 +               goto skip;
17040 +
17041 +       vxdprintk(VXD_CBIT(misc, 7),
17042 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
17043 +               sig, info, t, vx_task_xid(t), t->pid);
17044 +
17045         if (info != SEND_SIG_NOINFO && (is_si_special(info) || SI_FROMKERNEL(info)))
17046                 return 0;
17047  
17048 @@ -627,6 +637,20 @@ static int check_kill_permission(int sig
17049                 }
17050         }
17051  
17052 +       error = -EPERM;
17053 +       if (t->pid == 1 && current->xid)
17054 +               return error;
17055 +
17056 +       error = -ESRCH;
17057 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
17058 +                 loops, maybe ENOENT or EACCES? */
17059 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
17060 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
17061 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
17062 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
17063 +               return error;
17064 +       }
17065 +skip:
17066         return security_task_kill(t, info, sig, 0);
17067  }
17068  
17069 @@ -1115,7 +1139,7 @@ int kill_pid_info(int sig, struct siginf
17070         rcu_read_lock();
17071  retry:
17072         p = pid_task(pid, PIDTYPE_PID);
17073 -       if (p) {
17074 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
17075                 error = group_send_sig_info(sig, info, p);
17076                 if (unlikely(error == -ESRCH))
17077                         /*
17078 @@ -1154,7 +1178,7 @@ int kill_pid_info_as_uid(int sig, struct
17079  
17080         read_lock(&tasklist_lock);
17081         p = pid_task(pid, PIDTYPE_PID);
17082 -       if (!p) {
17083 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
17084                 ret = -ESRCH;
17085                 goto out_unlock;
17086         }
17087 @@ -1208,8 +1232,10 @@ static int kill_something_info(int sig, 
17088                 struct task_struct * p;
17089  
17090                 for_each_process(p) {
17091 -                       if (task_pid_vnr(p) > 1 &&
17092 -                                       !same_thread_group(p, current)) {
17093 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
17094 +                               task_pid_vnr(p) > 1 &&
17095 +                               !same_thread_group(p, current) &&
17096 +                               !vx_current_initpid(p->pid)) {
17097                                 int err = group_send_sig_info(sig, info, p);
17098                                 ++count;
17099                                 if (err != -EPERM)
17100 @@ -1874,6 +1900,11 @@ relock:
17101                                 !sig_kernel_only(signr))
17102                         continue;
17103  
17104 +               /* virtual init is protected against user signals */
17105 +               if ((info->si_code == SI_USER) &&
17106 +                       vx_current_initpid(current->pid))
17107 +                       continue;
17108 +
17109                 if (sig_kernel_stop(signr)) {
17110                         /*
17111                          * The default action is to stop all threads in
17112 diff -NurpP --minimal linux-2.6.32.56/kernel/softirq.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/softirq.c
17113 --- linux-2.6.32.56/kernel/softirq.c    2012-02-09 10:22:36.000000000 +0100
17114 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/softirq.c    2011-06-10 13:03:02.000000000 +0200
17115 @@ -24,6 +24,7 @@
17116  #include <linux/ftrace.h>
17117  #include <linux/smp.h>
17118  #include <linux/tick.h>
17119 +#include <linux/vs_context.h>
17120  
17121  #define CREATE_TRACE_POINTS
17122  #include <trace/events/irq.h>
17123 diff -NurpP --minimal linux-2.6.32.56/kernel/sys.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/sys.c
17124 --- linux-2.6.32.56/kernel/sys.c        2012-02-09 10:22:36.000000000 +0100
17125 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/sys.c        2011-06-10 13:03:02.000000000 +0200
17126 @@ -41,6 +41,7 @@
17127  #include <linux/syscalls.h>
17128  #include <linux/kprobes.h>
17129  #include <linux/user_namespace.h>
17130 +#include <linux/vs_pid.h>
17131  
17132  #include <asm/uaccess.h>
17133  #include <asm/io.h>
17134 @@ -130,7 +131,10 @@ static int set_one_prio(struct task_stru
17135                 goto out;
17136         }
17137         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
17138 -               error = -EACCES;
17139 +               if (vx_flags(VXF_IGNEG_NICE, 0))
17140 +                       error = 0;
17141 +               else
17142 +                       error = -EACCES;
17143                 goto out;
17144         }
17145         no_nice = security_task_setnice(p, niceval);
17146 @@ -179,6 +183,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
17147                         else
17148                                 pgrp = task_pgrp(current);
17149                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
17150 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
17151 +                                       continue;
17152                                 error = set_one_prio(p, niceval, error);
17153                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
17154                         break;
17155 @@ -240,6 +246,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
17156                         else
17157                                 pgrp = task_pgrp(current);
17158                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
17159 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
17160 +                                       continue;
17161                                 niceval = 20 - task_nice(p);
17162                                 if (niceval > retval)
17163                                         retval = niceval;
17164 @@ -349,6 +357,9 @@ void kernel_power_off(void)
17165         machine_power_off();
17166  }
17167  EXPORT_SYMBOL_GPL(kernel_power_off);
17168 +
17169 +long vs_reboot(unsigned int, void __user *);
17170 +
17171  /*
17172   * Reboot system call: for obvious reasons only root may call it,
17173   * and even root needs to set up some magic numbers in the registers
17174 @@ -381,6 +392,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
17175         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
17176                 cmd = LINUX_REBOOT_CMD_HALT;
17177  
17178 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
17179 +               return vs_reboot(cmd, arg);
17180 +
17181         lock_kernel();
17182         switch (cmd) {
17183         case LINUX_REBOOT_CMD_RESTART:
17184 @@ -1129,7 +1143,7 @@ SYSCALL_DEFINE2(sethostname, char __user
17185         int errno;
17186         char tmp[__NEW_UTS_LEN];
17187  
17188 -       if (!capable(CAP_SYS_ADMIN))
17189 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
17190                 return -EPERM;
17191         if (len < 0 || len > __NEW_UTS_LEN)
17192                 return -EINVAL;
17193 @@ -1178,7 +1192,7 @@ SYSCALL_DEFINE2(setdomainname, char __us
17194         int errno;
17195         char tmp[__NEW_UTS_LEN];
17196  
17197 -       if (!capable(CAP_SYS_ADMIN))
17198 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
17199                 return -EPERM;
17200         if (len < 0 || len > __NEW_UTS_LEN)
17201                 return -EINVAL;
17202 @@ -1247,7 +1261,7 @@ SYSCALL_DEFINE2(setrlimit, unsigned int,
17203                 return -EINVAL;
17204         old_rlim = current->signal->rlim + resource;
17205         if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
17206 -           !capable(CAP_SYS_RESOURCE))
17207 +           !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
17208                 return -EPERM;
17209         if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > sysctl_nr_open)
17210                 return -EPERM;
17211 diff -NurpP --minimal linux-2.6.32.56/kernel/sysctl.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/sysctl.c
17212 --- linux-2.6.32.56/kernel/sysctl.c     2012-02-09 10:22:36.000000000 +0100
17213 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/sysctl.c     2011-06-10 13:03:02.000000000 +0200
17214 @@ -124,6 +124,7 @@ static int ngroups_max = NGROUPS_MAX;
17215  extern char modprobe_path[];
17216  extern int modules_disabled;
17217  #endif
17218 +extern char vshelper_path[];
17219  #ifdef CONFIG_CHR_DEV_SG
17220  extern int sg_big_buff;
17221  #endif
17222 @@ -593,6 +594,15 @@ static struct ctl_table kern_table[] = {
17223                 .strategy       = &sysctl_string,
17224         },
17225  #endif
17226 +       {
17227 +               .ctl_name       = KERN_VSHELPER,
17228 +               .procname       = "vshelper",
17229 +               .data           = &vshelper_path,
17230 +               .maxlen         = 256,
17231 +               .mode           = 0644,
17232 +               .proc_handler   = &proc_dostring,
17233 +               .strategy       = &sysctl_string,
17234 +       },
17235  #ifdef CONFIG_CHR_DEV_SG
17236         {
17237                 .ctl_name       = KERN_SG_BIG_BUFF,
17238 diff -NurpP --minimal linux-2.6.32.56/kernel/sysctl_check.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/sysctl_check.c
17239 --- linux-2.6.32.56/kernel/sysctl_check.c       2012-02-09 10:22:36.000000000 +0100
17240 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/sysctl_check.c       2011-06-10 13:03:02.000000000 +0200
17241 @@ -39,6 +39,7 @@ static const struct trans_ctl_table tran
17242  
17243         { KERN_PANIC,                   "panic" },
17244         { KERN_REALROOTDEV,             "real-root-dev" },
17245 +       { KERN_VSHELPER,                "vshelper", },
17246  
17247         { KERN_SPARC_REBOOT,            "reboot-cmd" },
17248         { KERN_CTLALTDEL,               "ctrl-alt-del" },
17249 @@ -1218,6 +1219,22 @@ static const struct trans_ctl_table tran
17250         {}
17251  };
17252  
17253 +static struct trans_ctl_table trans_vserver_table[] = {
17254 +       { 1,    "debug_switch" },
17255 +       { 2,    "debug_xid" },
17256 +       { 3,    "debug_nid" },
17257 +       { 4,    "debug_tag" },
17258 +       { 5,    "debug_net" },
17259 +       { 6,    "debug_limit" },
17260 +       { 7,    "debug_cres" },
17261 +       { 8,    "debug_dlim" },
17262 +       { 9,    "debug_quota" },
17263 +       { 10,   "debug_cvirt" },
17264 +       { 11,   "debug_space" },
17265 +       { 12,   "debug_misc" },
17266 +       {}
17267 +};
17268 +
17269  static const struct trans_ctl_table trans_root_table[] = {
17270         { CTL_KERN,     "kernel",       trans_kern_table },
17271         { CTL_VM,       "vm",           trans_vm_table },
17272 @@ -1234,6 +1251,7 @@ static const struct trans_ctl_table tran
17273         { CTL_SUNRPC,   "sunrpc",       trans_sunrpc_table },
17274         { CTL_PM,       "pm",           trans_pm_table },
17275         { CTL_FRV,      "frv",          trans_frv_table },
17276 +       { CTL_VSERVER,  "vserver",      trans_vserver_table },
17277         {}
17278  };
17279  
17280 diff -NurpP --minimal linux-2.6.32.56/kernel/time.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/time.c
17281 --- linux-2.6.32.56/kernel/time.c       2012-02-09 10:22:36.000000000 +0100
17282 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/time.c       2011-11-17 12:18:26.000000000 +0100
17283 @@ -63,6 +63,7 @@ EXPORT_SYMBOL(sys_tz);
17284  SYSCALL_DEFINE1(time, time_t __user *, tloc)
17285  {
17286         time_t i = get_seconds();
17287 +/*     FIXME: do_gettimeofday(&tv) -> vx_gettimeofday(&tv) */
17288  
17289         if (tloc) {
17290                 if (put_user(i,tloc))
17291 @@ -93,7 +94,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
17292         if (err)
17293                 return err;
17294  
17295 -       do_settimeofday(&tv);
17296 +       vx_settimeofday(&tv);
17297         return 0;
17298  }
17299  
17300 @@ -104,7 +105,7 @@ SYSCALL_DEFINE2(gettimeofday, struct tim
17301  {
17302         if (likely(tv != NULL)) {
17303                 struct timeval ktv;
17304 -               do_gettimeofday(&ktv);
17305 +               vx_gettimeofday(&ktv);
17306                 if (copy_to_user(tv, &ktv, sizeof(ktv)))
17307                         return -EFAULT;
17308         }
17309 @@ -179,7 +180,7 @@ int do_sys_settimeofday(struct timespec 
17310                 /* SMP safe, again the code in arch/foo/time.c should
17311                  * globally block out interrupts when it runs.
17312                  */
17313 -               return do_settimeofday(tv);
17314 +               return vx_settimeofday(tv);
17315         }
17316         return 0;
17317  }
17318 @@ -311,7 +312,7 @@ void getnstimeofday(struct timespec *tv)
17319  {
17320         struct timeval x;
17321  
17322 -       do_gettimeofday(&x);
17323 +       vx_gettimeofday(&x);
17324         tv->tv_sec = x.tv_sec;
17325         tv->tv_nsec = x.tv_usec * NSEC_PER_USEC;
17326  }
17327 diff -NurpP --minimal linux-2.6.32.56/kernel/timer.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/timer.c
17328 --- linux-2.6.32.56/kernel/timer.c      2012-02-09 10:22:36.000000000 +0100
17329 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/timer.c      2011-06-10 13:03:02.000000000 +0200
17330 @@ -39,6 +39,10 @@
17331  #include <linux/kallsyms.h>
17332  #include <linux/perf_event.h>
17333  #include <linux/sched.h>
17334 +#include <linux/vs_base.h>
17335 +#include <linux/vs_cvirt.h>
17336 +#include <linux/vs_pid.h>
17337 +#include <linux/vserver/sched.h>
17338  
17339  #include <asm/uaccess.h>
17340  #include <asm/unistd.h>
17341 @@ -1261,12 +1265,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
17342  
17343  #endif
17344  
17345 -#ifndef __alpha__
17346 -
17347 -/*
17348 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
17349 - * should be moved into arch/i386 instead?
17350 - */
17351  
17352  /**
17353   * sys_getpid - return the thread group id of the current process
17354 @@ -1295,10 +1293,23 @@ SYSCALL_DEFINE0(getppid)
17355         rcu_read_lock();
17356         pid = task_tgid_vnr(current->real_parent);
17357         rcu_read_unlock();
17358 +       return vx_map_pid(pid);
17359 +}
17360  
17361 -       return pid;
17362 +#ifdef __alpha__
17363 +
17364 +/*
17365 + * The Alpha uses getxpid, getxuid, and getxgid instead.
17366 + */
17367 +
17368 +asmlinkage long do_getxpid(long *ppid)
17369 +{
17370 +       *ppid = sys_getppid();
17371 +       return sys_getpid();
17372  }
17373  
17374 +#else /* _alpha_ */
17375 +
17376  SYSCALL_DEFINE0(getuid)
17377  {
17378         /* Only we change this so SMP safe */
17379 diff -NurpP --minimal linux-2.6.32.56/kernel/user_namespace.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/user_namespace.c
17380 --- linux-2.6.32.56/kernel/user_namespace.c     2009-03-24 14:22:45.000000000 +0100
17381 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/user_namespace.c     2011-06-10 13:03:02.000000000 +0200
17382 @@ -10,6 +10,7 @@
17383  #include <linux/slab.h>
17384  #include <linux/user_namespace.h>
17385  #include <linux/cred.h>
17386 +#include <linux/vserver/global.h>
17387  
17388  /*
17389   * Create a new user namespace, deriving the creator from the user in the
17390 @@ -30,6 +31,7 @@ int create_user_ns(struct cred *new)
17391                 return -ENOMEM;
17392  
17393         kref_init(&ns->kref);
17394 +       atomic_inc(&vs_global_user_ns);
17395  
17396         for (n = 0; n < UIDHASH_SZ; ++n)
17397                 INIT_HLIST_HEAD(ns->uidhash_table + n);
17398 @@ -78,6 +80,8 @@ void free_user_ns(struct kref *kref)
17399         struct user_namespace *ns =
17400                 container_of(kref, struct user_namespace, kref);
17401  
17402 +       /* FIXME: maybe move into destroyer? */
17403 +       atomic_dec(&vs_global_user_ns);
17404         INIT_WORK(&ns->destroyer, free_user_ns_work);
17405         schedule_work(&ns->destroyer);
17406  }
17407 diff -NurpP --minimal linux-2.6.32.56/kernel/utsname.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/utsname.c
17408 --- linux-2.6.32.56/kernel/utsname.c    2009-09-10 15:26:28.000000000 +0200
17409 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/utsname.c    2011-06-10 13:03:02.000000000 +0200
17410 @@ -14,14 +14,17 @@
17411  #include <linux/utsname.h>
17412  #include <linux/err.h>
17413  #include <linux/slab.h>
17414 +#include <linux/vserver/global.h>
17415  
17416  static struct uts_namespace *create_uts_ns(void)
17417  {
17418         struct uts_namespace *uts_ns;
17419  
17420         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
17421 -       if (uts_ns)
17422 +       if (uts_ns) {
17423                 kref_init(&uts_ns->kref);
17424 +               atomic_inc(&vs_global_uts_ns);
17425 +       }
17426         return uts_ns;
17427  }
17428  
17429 @@ -71,5 +74,6 @@ void free_uts_ns(struct kref *kref)
17430         struct uts_namespace *ns;
17431  
17432         ns = container_of(kref, struct uts_namespace, kref);
17433 +       atomic_dec(&vs_global_uts_ns);
17434         kfree(ns);
17435  }
17436 diff -NurpP --minimal linux-2.6.32.56/kernel/vserver/Kconfig linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/Kconfig
17437 --- linux-2.6.32.56/kernel/vserver/Kconfig      1970-01-01 01:00:00.000000000 +0100
17438 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/Kconfig      2011-06-10 13:03:02.000000000 +0200
17439 @@ -0,0 +1,251 @@
17440 +#
17441 +# Linux VServer configuration
17442 +#
17443 +
17444 +menu "Linux VServer"
17445 +
17446 +config VSERVER_AUTO_LBACK
17447 +       bool    "Automatically Assign Loopback IP"
17448 +       default y
17449 +       help
17450 +         Automatically assign a guest specific loopback
17451 +         IP and add it to the kernel network stack on
17452 +         startup.
17453 +
17454 +config VSERVER_AUTO_SINGLE
17455 +       bool    "Automatic Single IP Special Casing"
17456 +       depends on EXPERIMENTAL
17457 +       default y
17458 +       help
17459 +         This allows network contexts with a single IP to
17460 +         automatically remap 0.0.0.0 bindings to that IP,
17461 +         avoiding further network checks and improving
17462 +         performance.
17463 +
17464 +         (note: such guests do not allow to change the ip
17465 +          on the fly and do not show loopback addresses)
17466 +
17467 +config VSERVER_COWBL
17468 +       bool    "Enable COW Immutable Link Breaking"
17469 +       default y
17470 +       help
17471 +         This enables the COW (Copy-On-Write) link break code.
17472 +         It allows you to treat unified files like normal files
17473 +         when writing to them (which will implicitely break the
17474 +         link and create a copy of the unified file)
17475 +
17476 +config VSERVER_VTIME
17477 +       bool    "Enable Virtualized Guest Time"
17478 +       depends on EXPERIMENTAL
17479 +       default n
17480 +       help
17481 +         This enables per guest time offsets to allow for
17482 +         adjusting the system clock individually per guest.
17483 +         this adds some overhead to the time functions and
17484 +         therefore should not be enabled without good reason.
17485 +
17486 +config VSERVER_DEVICE
17487 +       bool    "Enable Guest Device Mapping"
17488 +       depends on EXPERIMENTAL
17489 +       default n
17490 +       help
17491 +         This enables generic device remapping.
17492 +
17493 +config VSERVER_PROC_SECURE
17494 +       bool    "Enable Proc Security"
17495 +       depends on PROC_FS
17496 +       default y
17497 +       help
17498 +         This configures ProcFS security to initially hide
17499 +         non-process entries for all contexts except the main and
17500 +         spectator context (i.e. for all guests), which is a secure
17501 +         default.
17502 +
17503 +         (note: on 1.2x the entries were visible by default)
17504 +
17505 +config VSERVER_HARDCPU
17506 +       bool    "Enable Hard CPU Limits"
17507 +       default y
17508 +       help
17509 +         Activate the Hard CPU Limits
17510 +
17511 +         This will compile in code that allows the Token Bucket
17512 +         Scheduler to put processes on hold when a context's
17513 +         tokens are depleted (provided that its per-context
17514 +         sched_hard flag is set).
17515 +
17516 +         Processes belonging to that context will not be able
17517 +         to consume CPU resources again until a per-context
17518 +         configured minimum of tokens has been reached.
17519 +
17520 +config VSERVER_IDLETIME
17521 +       bool    "Avoid idle CPUs by skipping Time"
17522 +       depends on VSERVER_HARDCPU
17523 +       default y
17524 +       help
17525 +         This option allows the scheduler to artificially
17526 +         advance time (per cpu) when otherwise the idle
17527 +         task would be scheduled, thus keeping the cpu
17528 +         busy and sharing the available resources among
17529 +         certain contexts.
17530 +
17531 +config VSERVER_IDLELIMIT
17532 +       bool    "Limit the IDLE task"
17533 +       depends on VSERVER_HARDCPU
17534 +       default n
17535 +       help
17536 +         Limit the idle slices, so the the next context
17537 +         will be scheduled as soon as possible.
17538 +
17539 +         This might improve interactivity and latency, but
17540 +         will also marginally increase scheduling overhead.
17541 +
17542 +choice
17543 +       prompt  "Persistent Inode Tagging"
17544 +       default TAGGING_ID24
17545 +       help
17546 +         This adds persistent context information to filesystems
17547 +         mounted with the tagxid option. Tagging is a requirement
17548 +         for per-context disk limits and per-context quota.
17549 +
17550 +
17551 +config TAGGING_NONE
17552 +       bool    "Disabled"
17553 +       help
17554 +         do not store per-context information in inodes.
17555 +
17556 +config TAGGING_UID16
17557 +       bool    "UID16/GID32"
17558 +       help
17559 +         reduces UID to 16 bit, but leaves GID at 32 bit.
17560 +
17561 +config TAGGING_GID16
17562 +       bool    "UID32/GID16"
17563 +       help
17564 +         reduces GID to 16 bit, but leaves UID at 32 bit.
17565 +
17566 +config TAGGING_ID24
17567 +       bool    "UID24/GID24"
17568 +       help
17569 +         uses the upper 8bit from UID and GID for XID tagging
17570 +         which leaves 24bit for UID/GID each, which should be
17571 +         more than sufficient for normal use.
17572 +
17573 +config TAGGING_INTERN
17574 +       bool    "UID32/GID32"
17575 +       help
17576 +         this uses otherwise reserved inode fields in the on
17577 +         disk representation, which limits the use to a few
17578 +         filesystems (currently ext2 and ext3)
17579 +
17580 +endchoice
17581 +
17582 +config TAG_NFSD
17583 +       bool    "Tag NFSD User Auth and Files"
17584 +       default n
17585 +       help
17586 +         Enable this if you do want the in-kernel NFS
17587 +         Server to use the tagging specified above.
17588 +         (will require patched clients too)
17589 +
17590 +config VSERVER_PRIVACY
17591 +       bool    "Honor Privacy Aspects of Guests"
17592 +       default n
17593 +       help
17594 +         When enabled, most context checks will disallow
17595 +         access to structures assigned to a specific context,
17596 +         like ptys or loop devices.
17597 +
17598 +config VSERVER_CONTEXTS
17599 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
17600 +       range 1 65533
17601 +       default "768"   if 64BIT
17602 +       default "256"
17603 +       help
17604 +         This setting will optimize certain data structures
17605 +         and memory allocations according to the expected
17606 +         maximum.
17607 +
17608 +         note: this is not a strict upper limit.
17609 +
17610 +config VSERVER_WARN
17611 +       bool    "VServer Warnings"
17612 +       default y
17613 +       help
17614 +         This enables various runtime warnings, which will
17615 +         notify about potential manipulation attempts or
17616 +         resource shortage. It is generally considered to
17617 +         be a good idea to have that enabled.
17618 +
17619 +config VSERVER_DEBUG
17620 +       bool    "VServer Debugging Code"
17621 +       default n
17622 +       help
17623 +         Set this to yes if you want to be able to activate
17624 +         debugging output at runtime. It adds a very small
17625 +         overhead to all vserver related functions and
17626 +         increases the kernel size by about 20k.
17627 +
17628 +config VSERVER_HISTORY
17629 +       bool    "VServer History Tracing"
17630 +       depends on VSERVER_DEBUG
17631 +       default n
17632 +       help
17633 +         Set this to yes if you want to record the history of
17634 +         linux-vserver activities, so they can be replayed in
17635 +         the event of a kernel panic or oops.
17636 +
17637 +config VSERVER_HISTORY_SIZE
17638 +       int     "Per-CPU History Size (32-65536)"
17639 +       depends on VSERVER_HISTORY
17640 +       range 32 65536
17641 +       default 64
17642 +       help
17643 +         This allows you to specify the number of entries in
17644 +         the per-CPU history buffer.
17645 +
17646 +config VSERVER_MONITOR
17647 +       bool    "VServer Scheduling Monitor"
17648 +       depends on VSERVER_DISABLED
17649 +       default n
17650 +       help
17651 +         Set this to yes if you want to record the scheduling
17652 +         decisions, so that they can be relayed to userspace
17653 +         for detailed analysis.
17654 +
17655 +config VSERVER_MONITOR_SIZE
17656 +       int     "Per-CPU Monitor Queue Size (32-65536)"
17657 +       depends on VSERVER_MONITOR
17658 +       range 32 65536
17659 +       default 1024
17660 +       help
17661 +         This allows you to specify the number of entries in
17662 +         the per-CPU scheduling monitor buffer.
17663 +
17664 +config VSERVER_MONITOR_SYNC
17665 +       int     "Per-CPU Monitor Sync Interval (0-65536)"
17666 +       depends on VSERVER_MONITOR
17667 +       range 0 65536
17668 +       default 256
17669 +       help
17670 +         This allows you to specify the interval in ticks
17671 +         when a time sync entry is inserted.
17672 +
17673 +endmenu
17674 +
17675 +
17676 +config VSERVER
17677 +       bool
17678 +       default y
17679 +       select NAMESPACES
17680 +       select UTS_NS
17681 +       select IPC_NS
17682 +       select USER_NS
17683 +       select SYSVIPC
17684 +
17685 +config VSERVER_SECURITY
17686 +       bool
17687 +       depends on SECURITY
17688 +       default y
17689 +       select SECURITY_CAPABILITIES
17690 +
17691 diff -NurpP --minimal linux-2.6.32.56/kernel/vserver/Makefile linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/Makefile
17692 --- linux-2.6.32.56/kernel/vserver/Makefile     1970-01-01 01:00:00.000000000 +0100
17693 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/Makefile     2011-06-10 13:03:02.000000000 +0200
17694 @@ -0,0 +1,18 @@
17695 +#
17696 +# Makefile for the Linux vserver routines.
17697 +#
17698 +
17699 +
17700 +obj-y          += vserver.o
17701 +
17702 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
17703 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
17704 +                  dlimit.o tag.o
17705 +
17706 +vserver-$(CONFIG_INET) += inet.o
17707 +vserver-$(CONFIG_PROC_FS) += proc.o
17708 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
17709 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
17710 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
17711 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
17712 +
17713 diff -NurpP --minimal linux-2.6.32.56/kernel/vserver/cacct.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/cacct.c
17714 --- linux-2.6.32.56/kernel/vserver/cacct.c      1970-01-01 01:00:00.000000000 +0100
17715 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/cacct.c      2011-06-10 13:03:02.000000000 +0200
17716 @@ -0,0 +1,42 @@
17717 +/*
17718 + *  linux/kernel/vserver/cacct.c
17719 + *
17720 + *  Virtual Server: Context Accounting
17721 + *
17722 + *  Copyright (C) 2006-2007 Herbert Pötzl
17723 + *
17724 + *  V0.01  added accounting stats
17725 + *
17726 + */
17727 +
17728 +#include <linux/types.h>
17729 +#include <linux/vs_context.h>
17730 +#include <linux/vserver/cacct_cmd.h>
17731 +#include <linux/vserver/cacct_int.h>
17732 +
17733 +#include <asm/errno.h>
17734 +#include <asm/uaccess.h>
17735 +
17736 +
17737 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
17738 +{
17739 +       struct vcmd_sock_stat_v0 vc_data;
17740 +       int j, field;
17741 +
17742 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17743 +               return -EFAULT;
17744 +
17745 +       field = vc_data.field;
17746 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
17747 +               return -EINVAL;
17748 +
17749 +       for (j = 0; j < 3; j++) {
17750 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
17751 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
17752 +       }
17753 +
17754 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17755 +               return -EFAULT;
17756 +       return 0;
17757 +}
17758 +
17759 diff -NurpP --minimal linux-2.6.32.56/kernel/vserver/cacct_init.h linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/cacct_init.h
17760 --- linux-2.6.32.56/kernel/vserver/cacct_init.h 1970-01-01 01:00:00.000000000 +0100
17761 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/cacct_init.h 2011-06-10 13:03:02.000000000 +0200
17762 @@ -0,0 +1,25 @@
17763 +
17764 +
17765 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
17766 +{
17767 +       int i, j;
17768 +
17769 +
17770 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
17771 +               for (j = 0; j < 3; j++) {
17772 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
17773 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
17774 +               }
17775 +       }
17776 +       for (i = 0; i < 8; i++)
17777 +               atomic_set(&cacct->slab[i], 0);
17778 +       for (i = 0; i < 5; i++)
17779 +               for (j = 0; j < 4; j++)
17780 +                       atomic_set(&cacct->page[i][j], 0);
17781 +}
17782 +
17783 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
17784 +{
17785 +       return;
17786 +}
17787 +
17788 diff -NurpP --minimal linux-2.6.32.56/kernel/vserver/cacct_proc.h linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/cacct_proc.h
17789 --- linux-2.6.32.56/kernel/vserver/cacct_proc.h 1970-01-01 01:00:00.000000000 +0100
17790 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/cacct_proc.h 2011-06-10 13:03:02.000000000 +0200
17791 @@ -0,0 +1,53 @@
17792 +#ifndef _VX_CACCT_PROC_H
17793 +#define _VX_CACCT_PROC_H
17794 +
17795 +#include <linux/vserver/cacct_int.h>
17796 +
17797 +
17798 +#define VX_SOCKA_TOP   \
17799 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
17800 +
17801 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
17802 +{
17803 +       int i, j, length = 0;
17804 +       static char *type[VXA_SOCK_SIZE] = {
17805 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
17806 +       };
17807 +
17808 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
17809 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
17810 +               length += sprintf(buffer + length, "%s:", type[i]);
17811 +               for (j = 0; j < 3; j++) {
17812 +                       length += sprintf(buffer + length,
17813 +                               "\t%10lu/%-10lu",
17814 +                               vx_sock_count(cacct, i, j),
17815 +                               vx_sock_total(cacct, i, j));
17816 +               }
17817 +               buffer[length++] = '\n';
17818 +       }
17819 +
17820 +       length += sprintf(buffer + length, "\n");
17821 +       length += sprintf(buffer + length,
17822 +               "slab:\t %8u %8u %8u %8u\n",
17823 +               atomic_read(&cacct->slab[1]),
17824 +               atomic_read(&cacct->slab[4]),
17825 +               atomic_read(&cacct->slab[0]),
17826 +               atomic_read(&cacct->slab[2]));
17827 +
17828 +       length += sprintf(buffer + length, "\n");
17829 +       for (i = 0; i < 5; i++) {
17830 +               length += sprintf(buffer + length,
17831 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
17832 +                       atomic_read(&cacct->page[i][0]),
17833 +                       atomic_read(&cacct->page[i][1]),
17834 +                       atomic_read(&cacct->page[i][2]),
17835 +                       atomic_read(&cacct->page[i][3]),
17836 +                       atomic_read(&cacct->page[i][4]),
17837 +                       atomic_read(&cacct->page[i][5]),
17838 +                       atomic_read(&cacct->page[i][6]),
17839 +                       atomic_read(&cacct->page[i][7]));
17840 +       }
17841 +       return length;
17842 +}
17843 +
17844 +#endif /* _VX_CACCT_PROC_H */
17845 diff -NurpP --minimal linux-2.6.32.56/kernel/vserver/context.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/context.c
17846 --- linux-2.6.32.56/kernel/vserver/context.c    1970-01-01 01:00:00.000000000 +0100
17847 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/context.c    2011-06-10 14:02:35.000000000 +0200
17848 @@ -0,0 +1,1058 @@
17849 +/*
17850 + *  linux/kernel/vserver/context.c
17851 + *
17852 + *  Virtual Server: Context Support
17853 + *
17854 + *  Copyright (C) 2003-2007  Herbert Pötzl
17855 + *
17856 + *  V0.01  context helper
17857 + *  V0.02  vx_ctx_kill syscall command
17858 + *  V0.03  replaced context_info calls
17859 + *  V0.04  redesign of struct (de)alloc
17860 + *  V0.05  rlimit basic implementation
17861 + *  V0.06  task_xid and info commands
17862 + *  V0.07  context flags and caps
17863 + *  V0.08  switch to RCU based hash
17864 + *  V0.09  revert to non RCU for now
17865 + *  V0.10  and back to working RCU hash
17866 + *  V0.11  and back to locking again
17867 + *  V0.12  referenced context store
17868 + *  V0.13  separate per cpu data
17869 + *  V0.14  changed vcmds to vxi arg
17870 + *  V0.15  added context stat
17871 + *  V0.16  have __create claim() the vxi
17872 + *  V0.17  removed older and legacy stuff
17873 + *
17874 + */
17875 +
17876 +#include <linux/slab.h>
17877 +#include <linux/types.h>
17878 +#include <linux/security.h>
17879 +#include <linux/pid_namespace.h>
17880 +
17881 +#include <linux/vserver/context.h>
17882 +#include <linux/vserver/network.h>
17883 +#include <linux/vserver/debug.h>
17884 +#include <linux/vserver/limit.h>
17885 +#include <linux/vserver/limit_int.h>
17886 +#include <linux/vserver/space.h>
17887 +#include <linux/init_task.h>
17888 +#include <linux/fs_struct.h>
17889 +
17890 +#include <linux/vs_context.h>
17891 +#include <linux/vs_limit.h>
17892 +#include <linux/vs_pid.h>
17893 +#include <linux/vserver/context_cmd.h>
17894 +
17895 +#include "cvirt_init.h"
17896 +#include "cacct_init.h"
17897 +#include "limit_init.h"
17898 +#include "sched_init.h"
17899 +
17900 +
17901 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
17902 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
17903 +
17904 +
17905 +/*     now inactive context structures */
17906 +
17907 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
17908 +
17909 +static spinlock_t vx_info_inactive_lock = SPIN_LOCK_UNLOCKED;
17910 +
17911 +
17912 +/*     __alloc_vx_info()
17913 +
17914 +       * allocate an initialized vx_info struct
17915 +       * doesn't make it visible (hash)                        */
17916 +
17917 +static struct vx_info *__alloc_vx_info(xid_t xid)
17918 +{
17919 +       struct vx_info *new = NULL;
17920 +       int cpu, index;
17921 +
17922 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
17923 +
17924 +       /* would this benefit from a slab cache? */
17925 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
17926 +       if (!new)
17927 +               return 0;
17928 +
17929 +       memset(new, 0, sizeof(struct vx_info));
17930 +#ifdef CONFIG_SMP
17931 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
17932 +       if (!new->ptr_pc)
17933 +               goto error;
17934 +#endif
17935 +       new->vx_id = xid;
17936 +       INIT_HLIST_NODE(&new->vx_hlist);
17937 +       atomic_set(&new->vx_usecnt, 0);
17938 +       atomic_set(&new->vx_tasks, 0);
17939 +       new->vx_parent = NULL;
17940 +       new->vx_state = 0;
17941 +       init_waitqueue_head(&new->vx_wait);
17942 +
17943 +       /* prepare reaper */
17944 +       get_task_struct(init_pid_ns.child_reaper);
17945 +       new->vx_reaper = init_pid_ns.child_reaper;
17946 +       new->vx_badness_bias = 0;
17947 +
17948 +       /* rest of init goes here */
17949 +       vx_info_init_limit(&new->limit);
17950 +       vx_info_init_sched(&new->sched);
17951 +       vx_info_init_cvirt(&new->cvirt);
17952 +       vx_info_init_cacct(&new->cacct);
17953 +
17954 +       /* per cpu data structures */
17955 +       for_each_possible_cpu(cpu) {
17956 +               vx_info_init_sched_pc(
17957 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
17958 +               vx_info_init_cvirt_pc(
17959 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
17960 +       }
17961 +
17962 +       new->vx_flags = VXF_INIT_SET;
17963 +       cap_set_init_eff(new->vx_bcaps);
17964 +       new->vx_ccaps = 0;
17965 +       new->vx_umask = 0;
17966 +
17967 +       new->reboot_cmd = 0;
17968 +       new->exit_code = 0;
17969 +
17970 +       // preconfig fs entries
17971 +       for (index = 0; index < VX_SPACES; index++) {
17972 +               write_lock(&init_fs.lock);
17973 +               init_fs.users++;
17974 +               write_unlock(&init_fs.lock);
17975 +               new->vx_fs[index] = &init_fs;
17976 +       }
17977 +
17978 +       vxdprintk(VXD_CBIT(xid, 0),
17979 +               "alloc_vx_info(%d) = %p", xid, new);
17980 +       vxh_alloc_vx_info(new);
17981 +       atomic_inc(&vx_global_ctotal);
17982 +       return new;
17983 +#ifdef CONFIG_SMP
17984 +error:
17985 +       kfree(new);
17986 +       return 0;
17987 +#endif
17988 +}
17989 +
17990 +/*     __dealloc_vx_info()
17991 +
17992 +       * final disposal of vx_info                             */
17993 +
17994 +static void __dealloc_vx_info(struct vx_info *vxi)
17995 +{
17996 +#ifdef CONFIG_VSERVER_WARN
17997 +       struct vx_info_save vxis;
17998 +       int cpu;
17999 +#endif
18000 +       vxdprintk(VXD_CBIT(xid, 0),
18001 +               "dealloc_vx_info(%p)", vxi);
18002 +       vxh_dealloc_vx_info(vxi);
18003 +
18004 +#ifdef CONFIG_VSERVER_WARN
18005 +       enter_vx_info(vxi, &vxis);
18006 +       vx_info_exit_limit(&vxi->limit);
18007 +       vx_info_exit_sched(&vxi->sched);
18008 +       vx_info_exit_cvirt(&vxi->cvirt);
18009 +       vx_info_exit_cacct(&vxi->cacct);
18010 +
18011 +       for_each_possible_cpu(cpu) {
18012 +               vx_info_exit_sched_pc(
18013 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
18014 +               vx_info_exit_cvirt_pc(
18015 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
18016 +       }
18017 +       leave_vx_info(&vxis);
18018 +#endif
18019 +
18020 +       vxi->vx_id = -1;
18021 +       vxi->vx_state |= VXS_RELEASED;
18022 +
18023 +#ifdef CONFIG_SMP
18024 +       free_percpu(vxi->ptr_pc);
18025 +#endif
18026 +       kfree(vxi);
18027 +       atomic_dec(&vx_global_ctotal);
18028 +}
18029 +
18030 +static void __shutdown_vx_info(struct vx_info *vxi)
18031 +{
18032 +       struct nsproxy *nsproxy;
18033 +       struct fs_struct *fs;
18034 +       int index, kill;
18035 +
18036 +       might_sleep();
18037 +
18038 +       vxi->vx_state |= VXS_SHUTDOWN;
18039 +       vs_state_change(vxi, VSC_SHUTDOWN);
18040 +
18041 +       for (index = 0; index < VX_SPACES; index++) {
18042 +               nsproxy = xchg(&vxi->vx_nsproxy[index], NULL);
18043 +               if (nsproxy)
18044 +                       put_nsproxy(nsproxy);
18045 +
18046 +               fs = xchg(&vxi->vx_fs[index], NULL);
18047 +               write_lock(&fs->lock);
18048 +               kill = !--fs->users;
18049 +               write_unlock(&fs->lock);
18050 +               if (kill)
18051 +                       free_fs_struct(fs);
18052 +       }
18053 +}
18054 +
18055 +/* exported stuff */
18056 +
18057 +void free_vx_info(struct vx_info *vxi)
18058 +{
18059 +       unsigned long flags;
18060 +       unsigned index;
18061 +
18062 +       /* check for reference counts first */
18063 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
18064 +       BUG_ON(atomic_read(&vxi->vx_tasks));
18065 +
18066 +       /* context must not be hashed */
18067 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
18068 +
18069 +       /* context shutdown is mandatory */
18070 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
18071 +
18072 +       /* nsproxy and fs check */
18073 +       for (index = 0; index < VX_SPACES; index++) {
18074 +               BUG_ON(vxi->vx_nsproxy[index]);
18075 +               BUG_ON(vxi->vx_fs[index]);
18076 +       }
18077 +
18078 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
18079 +       hlist_del(&vxi->vx_hlist);
18080 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
18081 +
18082 +       __dealloc_vx_info(vxi);
18083 +}
18084 +
18085 +
18086 +/*     hash table for vx_info hash */
18087 +
18088 +#define VX_HASH_SIZE   13
18089 +
18090 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
18091 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
18092 +
18093 +static spinlock_t vx_info_hash_lock = SPIN_LOCK_UNLOCKED;
18094 +
18095 +
18096 +static inline unsigned int __hashval(xid_t xid)
18097 +{
18098 +       return (xid % VX_HASH_SIZE);
18099 +}
18100 +
18101 +
18102 +
18103 +/*     __hash_vx_info()
18104 +
18105 +       * add the vxi to the global hash table
18106 +       * requires the hash_lock to be held                     */
18107 +
18108 +static inline void __hash_vx_info(struct vx_info *vxi)
18109 +{
18110 +       struct hlist_head *head;
18111 +
18112 +       vxd_assert_lock(&vx_info_hash_lock);
18113 +       vxdprintk(VXD_CBIT(xid, 4),
18114 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
18115 +       vxh_hash_vx_info(vxi);
18116 +
18117 +       /* context must not be hashed */
18118 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
18119 +
18120 +       vxi->vx_state |= VXS_HASHED;
18121 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
18122 +       hlist_add_head(&vxi->vx_hlist, head);
18123 +       atomic_inc(&vx_global_cactive);
18124 +}
18125 +
18126 +/*     __unhash_vx_info()
18127 +
18128 +       * remove the vxi from the global hash table
18129 +       * requires the hash_lock to be held                     */
18130 +
18131 +static inline void __unhash_vx_info(struct vx_info *vxi)
18132 +{
18133 +       unsigned long flags;
18134 +
18135 +       vxd_assert_lock(&vx_info_hash_lock);
18136 +       vxdprintk(VXD_CBIT(xid, 4),
18137 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
18138 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
18139 +       vxh_unhash_vx_info(vxi);
18140 +
18141 +       /* context must be hashed */
18142 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
18143 +       /* but without tasks */
18144 +       BUG_ON(atomic_read(&vxi->vx_tasks));
18145 +
18146 +       vxi->vx_state &= ~VXS_HASHED;
18147 +       hlist_del_init(&vxi->vx_hlist);
18148 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
18149 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
18150 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
18151 +       atomic_dec(&vx_global_cactive);
18152 +}
18153 +
18154 +
18155 +/*     __lookup_vx_info()
18156 +
18157 +       * requires the hash_lock to be held
18158 +       * doesn't increment the vx_refcnt                       */
18159 +
18160 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
18161 +{
18162 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
18163 +       struct hlist_node *pos;
18164 +       struct vx_info *vxi;
18165 +
18166 +       vxd_assert_lock(&vx_info_hash_lock);
18167 +       hlist_for_each(pos, head) {
18168 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
18169 +
18170 +               if (vxi->vx_id == xid)
18171 +                       goto found;
18172 +       }
18173 +       vxi = NULL;
18174 +found:
18175 +       vxdprintk(VXD_CBIT(xid, 0),
18176 +               "__lookup_vx_info(#%u): %p[#%u]",
18177 +               xid, vxi, vxi ? vxi->vx_id : 0);
18178 +       vxh_lookup_vx_info(vxi, xid);
18179 +       return vxi;
18180 +}
18181 +
18182 +
18183 +/*     __create_vx_info()
18184 +
18185 +       * create the requested context
18186 +       * get(), claim() and hash it                            */
18187 +
18188 +static struct vx_info *__create_vx_info(int id)
18189 +{
18190 +       struct vx_info *new, *vxi = NULL;
18191 +
18192 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
18193 +
18194 +       if (!(new = __alloc_vx_info(id)))
18195 +               return ERR_PTR(-ENOMEM);
18196 +
18197 +       /* required to make dynamic xids unique */
18198 +       spin_lock(&vx_info_hash_lock);
18199 +
18200 +       /* static context requested */
18201 +       if ((vxi = __lookup_vx_info(id))) {
18202 +               vxdprintk(VXD_CBIT(xid, 0),
18203 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
18204 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
18205 +                       vxi = ERR_PTR(-EBUSY);
18206 +               else
18207 +                       vxi = ERR_PTR(-EEXIST);
18208 +               goto out_unlock;
18209 +       }
18210 +       /* new context */
18211 +       vxdprintk(VXD_CBIT(xid, 0),
18212 +               "create_vx_info(%d) = %p (new)", id, new);
18213 +       claim_vx_info(new, NULL);
18214 +       __hash_vx_info(get_vx_info(new));
18215 +       vxi = new, new = NULL;
18216 +
18217 +out_unlock:
18218 +       spin_unlock(&vx_info_hash_lock);
18219 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
18220 +       if (new)
18221 +               __dealloc_vx_info(new);
18222 +       return vxi;
18223 +}
18224 +
18225 +
18226 +/*     exported stuff                                          */
18227 +
18228 +
18229 +void unhash_vx_info(struct vx_info *vxi)
18230 +{
18231 +       spin_lock(&vx_info_hash_lock);
18232 +       __unhash_vx_info(vxi);
18233 +       spin_unlock(&vx_info_hash_lock);
18234 +       __shutdown_vx_info(vxi);
18235 +       __wakeup_vx_info(vxi);
18236 +}
18237 +
18238 +
18239 +/*     lookup_vx_info()
18240 +
18241 +       * search for a vx_info and get() it
18242 +       * negative id means current                             */
18243 +
18244 +struct vx_info *lookup_vx_info(int id)
18245 +{
18246 +       struct vx_info *vxi = NULL;
18247 +
18248 +       if (id < 0) {
18249 +               vxi = get_vx_info(current_vx_info());
18250 +       } else if (id > 1) {
18251 +               spin_lock(&vx_info_hash_lock);
18252 +               vxi = get_vx_info(__lookup_vx_info(id));
18253 +               spin_unlock(&vx_info_hash_lock);
18254 +       }
18255 +       return vxi;
18256 +}
18257 +
18258 +/*     xid_is_hashed()
18259 +
18260 +       * verify that xid is still hashed                       */
18261 +
18262 +int xid_is_hashed(xid_t xid)
18263 +{
18264 +       int hashed;
18265 +
18266 +       spin_lock(&vx_info_hash_lock);
18267 +       hashed = (__lookup_vx_info(xid) != NULL);
18268 +       spin_unlock(&vx_info_hash_lock);
18269 +       return hashed;
18270 +}
18271 +
18272 +#ifdef CONFIG_PROC_FS
18273 +
18274 +/*     get_xid_list()
18275 +
18276 +       * get a subset of hashed xids for proc
18277 +       * assumes size is at least one                          */
18278 +
18279 +int get_xid_list(int index, unsigned int *xids, int size)
18280 +{
18281 +       int hindex, nr_xids = 0;
18282 +
18283 +       /* only show current and children */
18284 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
18285 +               if (index > 0)
18286 +                       return 0;
18287 +               xids[nr_xids] = vx_current_xid();
18288 +               return 1;
18289 +       }
18290 +
18291 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
18292 +               struct hlist_head *head = &vx_info_hash[hindex];
18293 +               struct hlist_node *pos;
18294 +
18295 +               spin_lock(&vx_info_hash_lock);
18296 +               hlist_for_each(pos, head) {
18297 +                       struct vx_info *vxi;
18298 +
18299 +                       if (--index > 0)
18300 +                               continue;
18301 +
18302 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
18303 +                       xids[nr_xids] = vxi->vx_id;
18304 +                       if (++nr_xids >= size) {
18305 +                               spin_unlock(&vx_info_hash_lock);
18306 +                               goto out;
18307 +                       }
18308 +               }
18309 +               /* keep the lock time short */
18310 +               spin_unlock(&vx_info_hash_lock);
18311 +       }
18312 +out:
18313 +       return nr_xids;
18314 +}
18315 +#endif
18316 +
18317 +#ifdef CONFIG_VSERVER_DEBUG
18318 +
18319 +void   dump_vx_info_inactive(int level)
18320 +{
18321 +       struct hlist_node *entry, *next;
18322 +
18323 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
18324 +               struct vx_info *vxi =
18325 +                       list_entry(entry, struct vx_info, vx_hlist);
18326 +
18327 +               dump_vx_info(vxi, level);
18328 +       }
18329 +}
18330 +
18331 +#endif
18332 +
18333 +#if 0
18334 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
18335 +{
18336 +       struct user_struct *new_user, *old_user;
18337 +
18338 +       if (!p || !vxi)
18339 +               BUG();
18340 +
18341 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
18342 +               return -EACCES;
18343 +
18344 +       new_user = alloc_uid(vxi->vx_id, p->uid);
18345 +       if (!new_user)
18346 +               return -ENOMEM;
18347 +
18348 +       old_user = p->user;
18349 +       if (new_user != old_user) {
18350 +               atomic_inc(&new_user->processes);
18351 +               atomic_dec(&old_user->processes);
18352 +               p->user = new_user;
18353 +       }
18354 +       free_uid(old_user);
18355 +       return 0;
18356 +}
18357 +#endif
18358 +
18359 +#if 0
18360 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
18361 +{
18362 +       // p->cap_effective &= vxi->vx_cap_bset;
18363 +       p->cap_effective =
18364 +               cap_intersect(p->cap_effective, vxi->cap_bset);
18365 +       // p->cap_inheritable &= vxi->vx_cap_bset;
18366 +       p->cap_inheritable =
18367 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
18368 +       // p->cap_permitted &= vxi->vx_cap_bset;
18369 +       p->cap_permitted =
18370 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
18371 +}
18372 +#endif
18373 +
18374 +
18375 +#include <linux/file.h>
18376 +#include <linux/fdtable.h>
18377 +
18378 +static int vx_openfd_task(struct task_struct *tsk)
18379 +{
18380 +       struct files_struct *files = tsk->files;
18381 +       struct fdtable *fdt;
18382 +       const unsigned long *bptr;
18383 +       int count, total;
18384 +
18385 +       /* no rcu_read_lock() because of spin_lock() */
18386 +       spin_lock(&files->file_lock);
18387 +       fdt = files_fdtable(files);
18388 +       bptr = fdt->open_fds->fds_bits;
18389 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
18390 +       for (total = 0; count > 0; count--) {
18391 +               if (*bptr)
18392 +                       total += hweight_long(*bptr);
18393 +               bptr++;
18394 +       }
18395 +       spin_unlock(&files->file_lock);
18396 +       return total;
18397 +}
18398 +
18399 +
18400 +/*     for *space compatibility */
18401 +
18402 +asmlinkage long sys_unshare(unsigned long);
18403 +
18404 +/*
18405 + *     migrate task to new context
18406 + *     gets vxi, puts old_vxi on change
18407 + *     optionally unshares namespaces (hack)
18408 + */
18409 +
18410 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
18411 +{
18412 +       struct vx_info *old_vxi;
18413 +       int ret = 0;
18414 +
18415 +       if (!p || !vxi)
18416 +               BUG();
18417 +
18418 +       vxdprintk(VXD_CBIT(xid, 5),
18419 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
18420 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
18421 +
18422 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
18423 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
18424 +               return -EACCES;
18425 +
18426 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
18427 +               return -EFAULT;
18428 +
18429 +       old_vxi = task_get_vx_info(p);
18430 +       if (old_vxi == vxi)
18431 +               goto out;
18432 +
18433 +//     if (!(ret = vx_migrate_user(p, vxi))) {
18434 +       {
18435 +               int openfd;
18436 +
18437 +               task_lock(p);
18438 +               openfd = vx_openfd_task(p);
18439 +
18440 +               if (old_vxi) {
18441 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
18442 +                       atomic_dec(&old_vxi->cvirt.nr_running);
18443 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
18444 +                       /* FIXME: what about the struct files here? */
18445 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
18446 +                       /* account for the executable */
18447 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
18448 +               }
18449 +               atomic_inc(&vxi->cvirt.nr_threads);
18450 +               atomic_inc(&vxi->cvirt.nr_running);
18451 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
18452 +               /* FIXME: what about the struct files here? */
18453 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
18454 +               /* account for the executable */
18455 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
18456 +
18457 +               if (old_vxi) {
18458 +                       release_vx_info(old_vxi, p);
18459 +                       clr_vx_info(&p->vx_info);
18460 +               }
18461 +               claim_vx_info(vxi, p);
18462 +               set_vx_info(&p->vx_info, vxi);
18463 +               p->xid = vxi->vx_id;
18464 +
18465 +               vxdprintk(VXD_CBIT(xid, 5),
18466 +                       "moved task %p into vxi:%p[#%d]",
18467 +                       p, vxi, vxi->vx_id);
18468 +
18469 +               // vx_mask_cap_bset(vxi, p);
18470 +               task_unlock(p);
18471 +
18472 +               /* hack for *spaces to provide compatibility */
18473 +               if (unshare) {
18474 +                       struct nsproxy *old_nsp, *new_nsp;
18475 +
18476 +                       ret = unshare_nsproxy_namespaces(
18477 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
18478 +                               &new_nsp, NULL);
18479 +                       if (ret)
18480 +                               goto out;
18481 +
18482 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
18483 +                       vx_set_space(vxi,
18484 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
18485 +                       put_nsproxy(old_nsp);
18486 +               }
18487 +       }
18488 +out:
18489 +       put_vx_info(old_vxi);
18490 +       return ret;
18491 +}
18492 +
18493 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
18494 +{
18495 +       struct task_struct *old_reaper;
18496 +
18497 +       if (!vxi)
18498 +               return -EINVAL;
18499 +
18500 +       vxdprintk(VXD_CBIT(xid, 6),
18501 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
18502 +               vxi, vxi->vx_id, p, p->xid, p->pid);
18503 +
18504 +       old_reaper = vxi->vx_reaper;
18505 +       if (old_reaper == p)
18506 +               return 0;
18507 +
18508 +       /* set new child reaper */
18509 +       get_task_struct(p);
18510 +       vxi->vx_reaper = p;
18511 +       put_task_struct(old_reaper);
18512 +       return 0;
18513 +}
18514 +
18515 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
18516 +{
18517 +       if (!vxi)
18518 +               return -EINVAL;
18519 +
18520 +       vxdprintk(VXD_CBIT(xid, 6),
18521 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
18522 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
18523 +
18524 +       vxi->vx_flags &= ~VXF_STATE_INIT;
18525 +       // vxi->vx_initpid = p->tgid;
18526 +       vxi->vx_initpid = p->pid;
18527 +       return 0;
18528 +}
18529 +
18530 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
18531 +{
18532 +       vxdprintk(VXD_CBIT(xid, 6),
18533 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
18534 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
18535 +
18536 +       vxi->exit_code = code;
18537 +       vxi->vx_initpid = 0;
18538 +}
18539 +
18540 +
18541 +void vx_set_persistent(struct vx_info *vxi)
18542 +{
18543 +       vxdprintk(VXD_CBIT(xid, 6),
18544 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
18545 +
18546 +       get_vx_info(vxi);
18547 +       claim_vx_info(vxi, NULL);
18548 +}
18549 +
18550 +void vx_clear_persistent(struct vx_info *vxi)
18551 +{
18552 +       vxdprintk(VXD_CBIT(xid, 6),
18553 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
18554 +
18555 +       release_vx_info(vxi, NULL);
18556 +       put_vx_info(vxi);
18557 +}
18558 +
18559 +void vx_update_persistent(struct vx_info *vxi)
18560 +{
18561 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
18562 +               vx_set_persistent(vxi);
18563 +       else
18564 +               vx_clear_persistent(vxi);
18565 +}
18566 +
18567 +
18568 +/*     task must be current or locked          */
18569 +
18570 +void   exit_vx_info(struct task_struct *p, int code)
18571 +{
18572 +       struct vx_info *vxi = p->vx_info;
18573 +
18574 +       if (vxi) {
18575 +               atomic_dec(&vxi->cvirt.nr_threads);
18576 +               vx_nproc_dec(p);
18577 +
18578 +               vxi->exit_code = code;
18579 +               release_vx_info(vxi, p);
18580 +       }
18581 +}
18582 +
18583 +void   exit_vx_info_early(struct task_struct *p, int code)
18584 +{
18585 +       struct vx_info *vxi = p->vx_info;
18586 +
18587 +       if (vxi) {
18588 +               if (vxi->vx_initpid == p->pid)
18589 +                       vx_exit_init(vxi, p, code);
18590 +               if (vxi->vx_reaper == p)
18591 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
18592 +       }
18593 +}
18594 +
18595 +
18596 +/* vserver syscall commands below here */
18597 +
18598 +/* taks xid and vx_info functions */
18599 +
18600 +#include <asm/uaccess.h>
18601 +
18602 +
18603 +int vc_task_xid(uint32_t id)
18604 +{
18605 +       xid_t xid;
18606 +
18607 +       if (id) {
18608 +               struct task_struct *tsk;
18609 +
18610 +               read_lock(&tasklist_lock);
18611 +               tsk = find_task_by_real_pid(id);
18612 +               xid = (tsk) ? tsk->xid : -ESRCH;
18613 +               read_unlock(&tasklist_lock);
18614 +       } else
18615 +               xid = vx_current_xid();
18616 +       return xid;
18617 +}
18618 +
18619 +
18620 +int vc_vx_info(struct vx_info *vxi, void __user *data)
18621 +{
18622 +       struct vcmd_vx_info_v0 vc_data;
18623 +
18624 +       vc_data.xid = vxi->vx_id;
18625 +       vc_data.initpid = vxi->vx_initpid;
18626 +
18627 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18628 +               return -EFAULT;
18629 +       return 0;
18630 +}
18631 +
18632 +
18633 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
18634 +{
18635 +       struct vcmd_ctx_stat_v0 vc_data;
18636 +
18637 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
18638 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
18639 +
18640 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18641 +               return -EFAULT;
18642 +       return 0;
18643 +}
18644 +
18645 +
18646 +/* context functions */
18647 +
18648 +int vc_ctx_create(uint32_t xid, void __user *data)
18649 +{
18650 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
18651 +       struct vx_info *new_vxi;
18652 +       int ret;
18653 +
18654 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
18655 +               return -EFAULT;
18656 +
18657 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
18658 +               return -EINVAL;
18659 +
18660 +       new_vxi = __create_vx_info(xid);
18661 +       if (IS_ERR(new_vxi))
18662 +               return PTR_ERR(new_vxi);
18663 +
18664 +       /* initial flags */
18665 +       new_vxi->vx_flags = vc_data.flagword;
18666 +
18667 +       ret = -ENOEXEC;
18668 +       if (vs_state_change(new_vxi, VSC_STARTUP))
18669 +               goto out;
18670 +
18671 +       ret = vx_migrate_task(current, new_vxi, (!data));
18672 +       if (ret)
18673 +               goto out;
18674 +
18675 +       /* return context id on success */
18676 +       ret = new_vxi->vx_id;
18677 +
18678 +       /* get a reference for persistent contexts */
18679 +       if ((vc_data.flagword & VXF_PERSISTENT))
18680 +               vx_set_persistent(new_vxi);
18681 +out:
18682 +       release_vx_info(new_vxi, NULL);
18683 +       put_vx_info(new_vxi);
18684 +       return ret;
18685 +}
18686 +
18687 +
18688 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
18689 +{
18690 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
18691 +       int ret;
18692 +
18693 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
18694 +               return -EFAULT;
18695 +
18696 +       ret = vx_migrate_task(current, vxi, 0);
18697 +       if (ret)
18698 +               return ret;
18699 +       if (vc_data.flagword & VXM_SET_INIT)
18700 +               ret = vx_set_init(vxi, current);
18701 +       if (ret)
18702 +               return ret;
18703 +       if (vc_data.flagword & VXM_SET_REAPER)
18704 +               ret = vx_set_reaper(vxi, current);
18705 +       return ret;
18706 +}
18707 +
18708 +
18709 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
18710 +{
18711 +       struct vcmd_ctx_flags_v0 vc_data;
18712 +
18713 +       vc_data.flagword = vxi->vx_flags;
18714 +
18715 +       /* special STATE flag handling */
18716 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
18717 +
18718 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18719 +               return -EFAULT;
18720 +       return 0;
18721 +}
18722 +
18723 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
18724 +{
18725 +       struct vcmd_ctx_flags_v0 vc_data;
18726 +       uint64_t mask, trigger;
18727 +
18728 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18729 +               return -EFAULT;
18730 +
18731 +       /* special STATE flag handling */
18732 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
18733 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
18734 +
18735 +       if (vxi == current_vx_info()) {
18736 +               /* if (trigger & VXF_STATE_SETUP)
18737 +                       vx_mask_cap_bset(vxi, current); */
18738 +               if (trigger & VXF_STATE_INIT) {
18739 +                       int ret;
18740 +
18741 +                       ret = vx_set_init(vxi, current);
18742 +                       if (ret)
18743 +                               return ret;
18744 +                       ret = vx_set_reaper(vxi, current);
18745 +                       if (ret)
18746 +                               return ret;
18747 +               }
18748 +       }
18749 +
18750 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
18751 +               vc_data.flagword, mask);
18752 +       if (trigger & VXF_PERSISTENT)
18753 +               vx_update_persistent(vxi);
18754 +
18755 +       return 0;
18756 +}
18757 +
18758 +
18759 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
18760 +{
18761 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
18762 +
18763 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
18764 +       return v;
18765 +}
18766 +
18767 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
18768 +{
18769 +       kernel_cap_t c = __cap_empty_set;
18770 +
18771 +       c.cap[0] = v & 0xFFFFFFFF;
18772 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
18773 +
18774 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
18775 +       return c;
18776 +}
18777 +
18778 +
18779 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
18780 +{
18781 +       if (bcaps)
18782 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
18783 +       if (ccaps)
18784 +               *ccaps = vxi->vx_ccaps;
18785 +
18786 +       return 0;
18787 +}
18788 +
18789 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
18790 +{
18791 +       struct vcmd_ctx_caps_v1 vc_data;
18792 +       int ret;
18793 +
18794 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
18795 +       if (ret)
18796 +               return ret;
18797 +       vc_data.cmask = ~0ULL;
18798 +
18799 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18800 +               return -EFAULT;
18801 +       return 0;
18802 +}
18803 +
18804 +static int do_set_caps(struct vx_info *vxi,
18805 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
18806 +{
18807 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
18808 +
18809 +#if 0
18810 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
18811 +               bcaps, bmask, ccaps, cmask);
18812 +#endif
18813 +       vxi->vx_bcaps = cap_t_from_caps(
18814 +               vs_mask_flags(bcold, bcaps, bmask));
18815 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
18816 +
18817 +       return 0;
18818 +}
18819 +
18820 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
18821 +{
18822 +       struct vcmd_ctx_caps_v1 vc_data;
18823 +
18824 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18825 +               return -EFAULT;
18826 +
18827 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
18828 +}
18829 +
18830 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
18831 +{
18832 +       struct vcmd_bcaps vc_data;
18833 +       int ret;
18834 +
18835 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
18836 +       if (ret)
18837 +               return ret;
18838 +       vc_data.bmask = ~0ULL;
18839 +
18840 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18841 +               return -EFAULT;
18842 +       return 0;
18843 +}
18844 +
18845 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
18846 +{
18847 +       struct vcmd_bcaps vc_data;
18848 +
18849 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18850 +               return -EFAULT;
18851 +
18852 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
18853 +}
18854 +
18855 +
18856 +int vc_get_umask(struct vx_info *vxi, void __user *data)
18857 +{
18858 +       struct vcmd_umask vc_data;
18859 +
18860 +       vc_data.umask = vxi->vx_umask;
18861 +       vc_data.mask = ~0ULL;
18862 +
18863 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18864 +               return -EFAULT;
18865 +       return 0;
18866 +}
18867 +
18868 +int vc_set_umask(struct vx_info *vxi, void __user *data)
18869 +{
18870 +       struct vcmd_umask vc_data;
18871 +
18872 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18873 +               return -EFAULT;
18874 +
18875 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
18876 +               vc_data.umask, vc_data.mask);
18877 +       return 0;
18878 +}
18879 +
18880 +
18881 +int vc_get_badness(struct vx_info *vxi, void __user *data)
18882 +{
18883 +       struct vcmd_badness_v0 vc_data;
18884 +
18885 +       vc_data.bias = vxi->vx_badness_bias;
18886 +
18887 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18888 +               return -EFAULT;
18889 +       return 0;
18890 +}
18891 +
18892 +int vc_set_badness(struct vx_info *vxi, void __user *data)
18893 +{
18894 +       struct vcmd_badness_v0 vc_data;
18895 +
18896 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18897 +               return -EFAULT;
18898 +
18899 +       vxi->vx_badness_bias = vc_data.bias;
18900 +       return 0;
18901 +}
18902 +
18903 +#include <linux/module.h>
18904 +
18905 +EXPORT_SYMBOL_GPL(free_vx_info);
18906 +
18907 diff -NurpP --minimal linux-2.6.32.56/kernel/vserver/cvirt.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/cvirt.c
18908 --- linux-2.6.32.56/kernel/vserver/cvirt.c      1970-01-01 01:00:00.000000000 +0100
18909 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/cvirt.c      2011-06-10 13:03:02.000000000 +0200
18910 @@ -0,0 +1,304 @@
18911 +/*
18912 + *  linux/kernel/vserver/cvirt.c
18913 + *
18914 + *  Virtual Server: Context Virtualization
18915 + *
18916 + *  Copyright (C) 2004-2007  Herbert Pötzl
18917 + *
18918 + *  V0.01  broken out from limit.c
18919 + *  V0.02  added utsname stuff
18920 + *  V0.03  changed vcmds to vxi arg
18921 + *
18922 + */
18923 +
18924 +#include <linux/types.h>
18925 +#include <linux/utsname.h>
18926 +#include <linux/vs_cvirt.h>
18927 +#include <linux/vserver/switch.h>
18928 +#include <linux/vserver/cvirt_cmd.h>
18929 +
18930 +#include <asm/uaccess.h>
18931 +
18932 +
18933 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
18934 +{
18935 +       struct vx_info *vxi = current_vx_info();
18936 +
18937 +       set_normalized_timespec(uptime,
18938 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
18939 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
18940 +       if (!idle)
18941 +               return;
18942 +       set_normalized_timespec(idle,
18943 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
18944 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
18945 +       return;
18946 +}
18947 +
18948 +uint64_t vx_idle_jiffies(void)
18949 +{
18950 +       return init_task.utime + init_task.stime;
18951 +}
18952 +
18953 +
18954 +
18955 +static inline uint32_t __update_loadavg(uint32_t load,
18956 +       int wsize, int delta, int n)
18957 +{
18958 +       unsigned long long calc, prev;
18959 +
18960 +       /* just set it to n */
18961 +       if (unlikely(delta >= wsize))
18962 +               return (n << FSHIFT);
18963 +
18964 +       calc = delta * n;
18965 +       calc <<= FSHIFT;
18966 +       prev = (wsize - delta);
18967 +       prev *= load;
18968 +       calc += prev;
18969 +       do_div(calc, wsize);
18970 +       return calc;
18971 +}
18972 +
18973 +
18974 +void vx_update_load(struct vx_info *vxi)
18975 +{
18976 +       uint32_t now, last, delta;
18977 +       unsigned int nr_running, nr_uninterruptible;
18978 +       unsigned int total;
18979 +       unsigned long flags;
18980 +
18981 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
18982 +
18983 +       now = jiffies;
18984 +       last = vxi->cvirt.load_last;
18985 +       delta = now - last;
18986 +
18987 +       if (delta < 5*HZ)
18988 +               goto out;
18989 +
18990 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
18991 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
18992 +       total = nr_running + nr_uninterruptible;
18993 +
18994 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
18995 +               60*HZ, delta, total);
18996 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
18997 +               5*60*HZ, delta, total);
18998 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
18999 +               15*60*HZ, delta, total);
19000 +
19001 +       vxi->cvirt.load_last = now;
19002 +out:
19003 +       atomic_inc(&vxi->cvirt.load_updates);
19004 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
19005 +}
19006 +
19007 +
19008 +/*
19009 + * Commands to do_syslog:
19010 + *
19011 + *      0 -- Close the log.  Currently a NOP.
19012 + *      1 -- Open the log. Currently a NOP.
19013 + *      2 -- Read from the log.
19014 + *      3 -- Read all messages remaining in the ring buffer.
19015 + *      4 -- Read and clear all messages remaining in the ring buffer
19016 + *      5 -- Clear ring buffer.
19017 + *      6 -- Disable printk's to console
19018 + *      7 -- Enable printk's to console
19019 + *      8 -- Set level of messages printed to console
19020 + *      9 -- Return number of unread characters in the log buffer
19021 + *     10 -- Return size of the log buffer
19022 + */
19023 +int vx_do_syslog(int type, char __user *buf, int len)
19024 +{
19025 +       int error = 0;
19026 +       int do_clear = 0;
19027 +       struct vx_info *vxi = current_vx_info();
19028 +       struct _vx_syslog *log;
19029 +
19030 +       if (!vxi)
19031 +               return -EINVAL;
19032 +       log = &vxi->cvirt.syslog;
19033 +
19034 +       switch (type) {
19035 +       case 0:         /* Close log */
19036 +       case 1:         /* Open log */
19037 +               break;
19038 +       case 2:         /* Read from log */
19039 +               error = wait_event_interruptible(log->log_wait,
19040 +                       (log->log_start - log->log_end));
19041 +               if (error)
19042 +                       break;
19043 +               spin_lock_irq(&log->logbuf_lock);
19044 +               spin_unlock_irq(&log->logbuf_lock);
19045 +               break;
19046 +       case 4:         /* Read/clear last kernel messages */
19047 +               do_clear = 1;
19048 +               /* fall through */
19049 +       case 3:         /* Read last kernel messages */
19050 +               return 0;
19051 +
19052 +       case 5:         /* Clear ring buffer */
19053 +               return 0;
19054 +
19055 +       case 6:         /* Disable logging to console */
19056 +       case 7:         /* Enable logging to console */
19057 +       case 8:         /* Set level of messages printed to console */
19058 +               break;
19059 +
19060 +       case 9:         /* Number of chars in the log buffer */
19061 +               return 0;
19062 +       case 10:        /* Size of the log buffer */
19063 +               return 0;
19064 +       default:
19065 +               error = -EINVAL;
19066 +               break;
19067 +       }
19068 +       return error;
19069 +}
19070 +
19071 +
19072 +/* virtual host info names */
19073 +
19074 +static char *vx_vhi_name(struct vx_info *vxi, int id)
19075 +{
19076 +       struct nsproxy *nsproxy;
19077 +       struct uts_namespace *uts;
19078 +
19079 +       if (id == VHIN_CONTEXT)
19080 +               return vxi->vx_name;
19081 +
19082 +       nsproxy = vxi->vx_nsproxy[0];
19083 +       if (!nsproxy)
19084 +               return NULL;
19085 +
19086 +       uts = nsproxy->uts_ns;
19087 +       if (!uts)
19088 +               return NULL;
19089 +
19090 +       switch (id) {
19091 +       case VHIN_SYSNAME:
19092 +               return uts->name.sysname;
19093 +       case VHIN_NODENAME:
19094 +               return uts->name.nodename;
19095 +       case VHIN_RELEASE:
19096 +               return uts->name.release;
19097 +       case VHIN_VERSION:
19098 +               return uts->name.version;
19099 +       case VHIN_MACHINE:
19100 +               return uts->name.machine;
19101 +       case VHIN_DOMAINNAME:
19102 +               return uts->name.domainname;
19103 +       default:
19104 +               return NULL;
19105 +       }
19106 +       return NULL;
19107 +}
19108 +
19109 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
19110 +{
19111 +       struct vcmd_vhi_name_v0 vc_data;
19112 +       char *name;
19113 +
19114 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19115 +               return -EFAULT;
19116 +
19117 +       name = vx_vhi_name(vxi, vc_data.field);
19118 +       if (!name)
19119 +               return -EINVAL;
19120 +
19121 +       memcpy(name, vc_data.name, 65);
19122 +       return 0;
19123 +}
19124 +
19125 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
19126 +{
19127 +       struct vcmd_vhi_name_v0 vc_data;
19128 +       char *name;
19129 +
19130 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19131 +               return -EFAULT;
19132 +
19133 +       name = vx_vhi_name(vxi, vc_data.field);
19134 +       if (!name)
19135 +               return -EINVAL;
19136 +
19137 +       memcpy(vc_data.name, name, 65);
19138 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19139 +               return -EFAULT;
19140 +       return 0;
19141 +}
19142 +
19143 +
19144 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
19145 +{
19146 +       struct vcmd_virt_stat_v0 vc_data;
19147 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
19148 +       struct timespec uptime;
19149 +
19150 +       do_posix_clock_monotonic_gettime(&uptime);
19151 +       set_normalized_timespec(&uptime,
19152 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
19153 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
19154 +
19155 +       vc_data.offset = timeval_to_ns(&cvirt->bias_tv);
19156 +       vc_data.uptime = timespec_to_ns(&uptime);
19157 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
19158 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
19159 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
19160 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
19161 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
19162 +       vc_data.load[0] = cvirt->load[0];
19163 +       vc_data.load[1] = cvirt->load[1];
19164 +       vc_data.load[2] = cvirt->load[2];
19165 +
19166 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19167 +               return -EFAULT;
19168 +       return 0;
19169 +}
19170 +
19171 +
19172 +#ifdef CONFIG_VSERVER_VTIME
19173 +
19174 +/* virtualized time base */
19175 +
19176 +void vx_gettimeofday(struct timeval *tv)
19177 +{
19178 +       struct vx_info *vxi;
19179 +
19180 +       do_gettimeofday(tv);
19181 +       if (!vx_flags(VXF_VIRT_TIME, 0))
19182 +               return;
19183 +
19184 +       vxi = current_vx_info();
19185 +       tv->tv_sec += vxi->cvirt.bias_tv.tv_sec;
19186 +       tv->tv_usec += vxi->cvirt.bias_tv.tv_usec;
19187 +
19188 +       if (tv->tv_usec >= USEC_PER_SEC) {
19189 +               tv->tv_sec++;
19190 +               tv->tv_usec -= USEC_PER_SEC;
19191 +       } else if (tv->tv_usec < 0) {
19192 +               tv->tv_sec--;
19193 +               tv->tv_usec += USEC_PER_SEC;
19194 +       }
19195 +}
19196 +
19197 +int vx_settimeofday(struct timespec *ts)
19198 +{
19199 +       struct timeval tv;
19200 +       struct vx_info *vxi;
19201 +
19202 +       if (!vx_flags(VXF_VIRT_TIME, 0))
19203 +               return do_settimeofday(ts);
19204 +
19205 +       do_gettimeofday(&tv);
19206 +       vxi = current_vx_info();
19207 +       vxi->cvirt.bias_tv.tv_sec = ts->tv_sec - tv.tv_sec;
19208 +       vxi->cvirt.bias_tv.tv_usec =
19209 +               (ts->tv_nsec/NSEC_PER_USEC) - tv.tv_usec;
19210 +       return 0;
19211 +}
19212 +
19213 +#endif
19214 +
19215 diff -NurpP --minimal linux-2.6.32.56/kernel/vserver/cvirt_init.h linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/cvirt_init.h
19216 --- linux-2.6.32.56/kernel/vserver/cvirt_init.h 1970-01-01 01:00:00.000000000 +0100
19217 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/cvirt_init.h 2011-06-10 13:03:02.000000000 +0200
19218 @@ -0,0 +1,69 @@
19219 +
19220 +
19221 +extern uint64_t vx_idle_jiffies(void);
19222 +
19223 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
19224 +{
19225 +       uint64_t idle_jiffies = vx_idle_jiffies();
19226 +       uint64_t nsuptime;
19227 +
19228 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
19229 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
19230 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
19231 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
19232 +       cvirt->bias_tv.tv_sec = 0;
19233 +       cvirt->bias_tv.tv_usec = 0;
19234 +
19235 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
19236 +       atomic_set(&cvirt->nr_threads, 0);
19237 +       atomic_set(&cvirt->nr_running, 0);
19238 +       atomic_set(&cvirt->nr_uninterruptible, 0);
19239 +       atomic_set(&cvirt->nr_onhold, 0);
19240 +
19241 +       spin_lock_init(&cvirt->load_lock);
19242 +       cvirt->load_last = jiffies;
19243 +       atomic_set(&cvirt->load_updates, 0);
19244 +       cvirt->load[0] = 0;
19245 +       cvirt->load[1] = 0;
19246 +       cvirt->load[2] = 0;
19247 +       atomic_set(&cvirt->total_forks, 0);
19248 +
19249 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
19250 +       init_waitqueue_head(&cvirt->syslog.log_wait);
19251 +       cvirt->syslog.log_start = 0;
19252 +       cvirt->syslog.log_end = 0;
19253 +       cvirt->syslog.con_start = 0;
19254 +       cvirt->syslog.logged_chars = 0;
19255 +}
19256 +
19257 +static inline
19258 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
19259 +{
19260 +       // cvirt_pc->cpustat = { 0 };
19261 +}
19262 +
19263 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
19264 +{
19265 +       int value;
19266 +
19267 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
19268 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
19269 +               cvirt, value);
19270 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
19271 +               "!!! cvirt: %p[nr_running] = %d on exit.",
19272 +               cvirt, value);
19273 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
19274 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
19275 +               cvirt, value);
19276 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
19277 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
19278 +               cvirt, value);
19279 +       return;
19280 +}
19281 +
19282 +static inline
19283 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
19284 +{
19285 +       return;
19286 +}
19287 +
19288 diff -NurpP --minimal linux-2.6.32.56/kernel/vserver/cvirt_proc.h linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/cvirt_proc.h
19289 --- linux-2.6.32.56/kernel/vserver/cvirt_proc.h 1970-01-01 01:00:00.000000000 +0100
19290 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/cvirt_proc.h 2011-06-10 13:03:02.000000000 +0200
19291 @@ -0,0 +1,135 @@
19292 +#ifndef _VX_CVIRT_PROC_H
19293 +#define _VX_CVIRT_PROC_H
19294 +
19295 +#include <linux/nsproxy.h>
19296 +#include <linux/mnt_namespace.h>
19297 +#include <linux/ipc_namespace.h>
19298 +#include <linux/utsname.h>
19299 +#include <linux/ipc.h>
19300 +
19301 +
19302 +static inline
19303 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
19304 +{
19305 +       struct mnt_namespace *ns;
19306 +       struct uts_namespace *uts;
19307 +       struct ipc_namespace *ipc;
19308 +       struct path path;
19309 +       char *pstr, *root;
19310 +       int length = 0;
19311 +
19312 +       if (!nsproxy)
19313 +               goto out;
19314 +
19315 +       length += sprintf(buffer + length,
19316 +               "NSProxy:\t%p [%p,%p,%p]\n",
19317 +               nsproxy, nsproxy->mnt_ns,
19318 +               nsproxy->uts_ns, nsproxy->ipc_ns);
19319 +
19320 +       ns = nsproxy->mnt_ns;
19321 +       if (!ns)
19322 +               goto skip_ns;
19323 +
19324 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
19325 +       if (!pstr)
19326 +               goto skip_ns;
19327 +
19328 +       path.mnt = ns->root;
19329 +       path.dentry = ns->root->mnt_root;
19330 +       root = d_path(&path, pstr, PATH_MAX - 2);
19331 +       length += sprintf(buffer + length,
19332 +               "Namespace:\t%p [#%u]\n"
19333 +               "RootPath:\t%s\n",
19334 +               ns, atomic_read(&ns->count),
19335 +               root);
19336 +       kfree(pstr);
19337 +skip_ns:
19338 +
19339 +       uts = nsproxy->uts_ns;
19340 +       if (!uts)
19341 +               goto skip_uts;
19342 +
19343 +       length += sprintf(buffer + length,
19344 +               "SysName:\t%.*s\n"
19345 +               "NodeName:\t%.*s\n"
19346 +               "Release:\t%.*s\n"
19347 +               "Version:\t%.*s\n"
19348 +               "Machine:\t%.*s\n"
19349 +               "DomainName:\t%.*s\n",
19350 +               __NEW_UTS_LEN, uts->name.sysname,
19351 +               __NEW_UTS_LEN, uts->name.nodename,
19352 +               __NEW_UTS_LEN, uts->name.release,
19353 +               __NEW_UTS_LEN, uts->name.version,
19354 +               __NEW_UTS_LEN, uts->name.machine,
19355 +               __NEW_UTS_LEN, uts->name.domainname);
19356 +skip_uts:
19357 +
19358 +       ipc = nsproxy->ipc_ns;
19359 +       if (!ipc)
19360 +               goto skip_ipc;
19361 +
19362 +       length += sprintf(buffer + length,
19363 +               "SEMS:\t\t%d %d %d %d  %d\n"
19364 +               "MSG:\t\t%d %d %d\n"
19365 +               "SHM:\t\t%lu %lu  %d %d\n",
19366 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
19367 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
19368 +               ipc->used_sems,
19369 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
19370 +               (unsigned long)ipc->shm_ctlmax,
19371 +               (unsigned long)ipc->shm_ctlall,
19372 +               ipc->shm_ctlmni, ipc->shm_tot);
19373 +skip_ipc:
19374 +out:
19375 +       return length;
19376 +}
19377 +
19378 +
19379 +#include <linux/sched.h>
19380 +
19381 +#define LOAD_INT(x) ((x) >> FSHIFT)
19382 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
19383 +
19384 +static inline
19385 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
19386 +{
19387 +       int length = 0;
19388 +       int a, b, c;
19389 +
19390 +       length += sprintf(buffer + length,
19391 +               "BiasUptime:\t%lu.%02lu\n",
19392 +               (unsigned long)cvirt->bias_uptime.tv_sec,
19393 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
19394 +
19395 +       a = cvirt->load[0] + (FIXED_1 / 200);
19396 +       b = cvirt->load[1] + (FIXED_1 / 200);
19397 +       c = cvirt->load[2] + (FIXED_1 / 200);
19398 +       length += sprintf(buffer + length,
19399 +               "nr_threads:\t%d\n"
19400 +               "nr_running:\t%d\n"
19401 +               "nr_unintr:\t%d\n"
19402 +               "nr_onhold:\t%d\n"
19403 +               "load_updates:\t%d\n"
19404 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
19405 +               "total_forks:\t%d\n",
19406 +               atomic_read(&cvirt->nr_threads),
19407 +               atomic_read(&cvirt->nr_running),
19408 +               atomic_read(&cvirt->nr_uninterruptible),
19409 +               atomic_read(&cvirt->nr_onhold),
19410 +               atomic_read(&cvirt->load_updates),
19411 +               LOAD_INT(a), LOAD_FRAC(a),
19412 +               LOAD_INT(b), LOAD_FRAC(b),
19413 +               LOAD_INT(c), LOAD_FRAC(c),
19414 +               atomic_read(&cvirt->total_forks));
19415 +       return length;
19416 +}
19417 +
19418 +static inline
19419 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
19420 +       char *buffer, int cpu)
19421 +{
19422 +       int length = 0;
19423 +       return length;
19424 +}
19425 +
19426 +#endif /* _VX_CVIRT_PROC_H */
19427 diff -NurpP --minimal linux-2.6.32.56/kernel/vserver/debug.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/debug.c
19428 --- linux-2.6.32.56/kernel/vserver/debug.c      1970-01-01 01:00:00.000000000 +0100
19429 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/debug.c      2011-06-10 13:03:02.000000000 +0200
19430 @@ -0,0 +1,32 @@
19431 +/*
19432 + *  kernel/vserver/debug.c
19433 + *
19434 + *  Copyright (C) 2005-2007 Herbert Pötzl
19435 + *
19436 + *  V0.01  vx_info dump support
19437 + *
19438 + */
19439 +
19440 +#include <linux/module.h>
19441 +
19442 +#include <linux/vserver/context.h>
19443 +
19444 +
19445 +void   dump_vx_info(struct vx_info *vxi, int level)
19446 +{
19447 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
19448 +               atomic_read(&vxi->vx_usecnt),
19449 +               atomic_read(&vxi->vx_tasks),
19450 +               vxi->vx_state);
19451 +       if (level > 0) {
19452 +               __dump_vx_limit(&vxi->limit);
19453 +               __dump_vx_sched(&vxi->sched);
19454 +               __dump_vx_cvirt(&vxi->cvirt);
19455 +               __dump_vx_cacct(&vxi->cacct);
19456 +       }
19457 +       printk("---\n");
19458 +}
19459 +
19460 +
19461 +EXPORT_SYMBOL_GPL(dump_vx_info);
19462 +
19463 diff -NurpP --minimal linux-2.6.32.56/kernel/vserver/device.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/device.c
19464 --- linux-2.6.32.56/kernel/vserver/device.c     1970-01-01 01:00:00.000000000 +0100
19465 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/device.c     2011-06-10 13:03:02.000000000 +0200
19466 @@ -0,0 +1,443 @@
19467 +/*
19468 + *  linux/kernel/vserver/device.c
19469 + *
19470 + *  Linux-VServer: Device Support
19471 + *
19472 + *  Copyright (C) 2006  Herbert Pötzl
19473 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
19474 + *
19475 + *  V0.01  device mapping basics
19476 + *  V0.02  added defaults
19477 + *
19478 + */
19479 +
19480 +#include <linux/slab.h>
19481 +#include <linux/rcupdate.h>
19482 +#include <linux/fs.h>
19483 +#include <linux/namei.h>
19484 +#include <linux/hash.h>
19485 +
19486 +#include <asm/errno.h>
19487 +#include <asm/uaccess.h>
19488 +#include <linux/vserver/base.h>
19489 +#include <linux/vserver/debug.h>
19490 +#include <linux/vserver/context.h>
19491 +#include <linux/vserver/device.h>
19492 +#include <linux/vserver/device_cmd.h>
19493 +
19494 +
19495 +#define DMAP_HASH_BITS 4
19496 +
19497 +
19498 +struct vs_mapping {
19499 +       union {
19500 +               struct hlist_node hlist;
19501 +               struct list_head list;
19502 +       } u;
19503 +#define dm_hlist       u.hlist
19504 +#define dm_list                u.list
19505 +       xid_t xid;
19506 +       dev_t device;
19507 +       struct vx_dmap_target target;
19508 +};
19509 +
19510 +
19511 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
19512 +
19513 +static spinlock_t dmap_main_hash_lock = SPIN_LOCK_UNLOCKED;
19514 +
19515 +static struct vx_dmap_target dmap_defaults[2] = {
19516 +       { .flags = DATTR_OPEN },
19517 +       { .flags = DATTR_OPEN },
19518 +};
19519 +
19520 +
19521 +struct kmem_cache *dmap_cachep __read_mostly;
19522 +
19523 +int __init dmap_cache_init(void)
19524 +{
19525 +       dmap_cachep = kmem_cache_create("dmap_cache",
19526 +               sizeof(struct vs_mapping), 0,
19527 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19528 +       return 0;
19529 +}
19530 +
19531 +__initcall(dmap_cache_init);
19532 +
19533 +
19534 +static inline unsigned int __hashval(dev_t dev, int bits)
19535 +{
19536 +       return hash_long((unsigned long)dev, bits);
19537 +}
19538 +
19539 +
19540 +/*     __hash_mapping()
19541 + *     add the mapping to the hash table
19542 + */
19543 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
19544 +{
19545 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19546 +       struct hlist_head *head, *hash = dmap_main_hash;
19547 +       int device = vdm->device;
19548 +
19549 +       spin_lock(hash_lock);
19550 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
19551 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
19552 +
19553 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
19554 +       hlist_add_head(&vdm->dm_hlist, head);
19555 +       spin_unlock(hash_lock);
19556 +}
19557 +
19558 +
19559 +static inline int __mode_to_default(umode_t mode)
19560 +{
19561 +       switch (mode) {
19562 +       case S_IFBLK:
19563 +               return 0;
19564 +       case S_IFCHR:
19565 +               return 1;
19566 +       default:
19567 +               BUG();
19568 +       }
19569 +}
19570 +
19571 +
19572 +/*     __set_default()
19573 + *     set a default
19574 + */
19575 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
19576 +       struct vx_dmap_target *vdmt)
19577 +{
19578 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19579 +       spin_lock(hash_lock);
19580 +
19581 +       if (vxi)
19582 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
19583 +       else
19584 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
19585 +
19586 +
19587 +       spin_unlock(hash_lock);
19588 +
19589 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
19590 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
19591 +}
19592 +
19593 +
19594 +/*     __remove_default()
19595 + *     remove a default
19596 + */
19597 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
19598 +{
19599 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19600 +       spin_lock(hash_lock);
19601 +
19602 +       if (vxi)
19603 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
19604 +       else    /* remove == reset */
19605 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
19606 +
19607 +       spin_unlock(hash_lock);
19608 +       return 0;
19609 +}
19610 +
19611 +
19612 +/*     __find_mapping()
19613 + *     find a mapping in the hash table
19614 + *
19615 + *     caller must hold hash_lock
19616 + */
19617 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
19618 +       struct vs_mapping **local, struct vs_mapping **global)
19619 +{
19620 +       struct hlist_head *hash = dmap_main_hash;
19621 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
19622 +       struct hlist_node *pos;
19623 +       struct vs_mapping *vdm;
19624 +
19625 +       *local = NULL;
19626 +       if (global)
19627 +               *global = NULL;
19628 +
19629 +       hlist_for_each(pos, head) {
19630 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
19631 +
19632 +               if ((vdm->device == device) &&
19633 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
19634 +                       if (vdm->xid == xid) {
19635 +                               *local = vdm;
19636 +                               return 1;
19637 +                       } else if (global && vdm->xid == 0)
19638 +                               *global = vdm;
19639 +               }
19640 +       }
19641 +
19642 +       if (global && *global)
19643 +               return 0;
19644 +       else
19645 +               return -ENOENT;
19646 +}
19647 +
19648 +
19649 +/*     __lookup_mapping()
19650 + *     find a mapping and store the result in target and flags
19651 + */
19652 +static inline int __lookup_mapping(struct vx_info *vxi,
19653 +       dev_t device, dev_t *target, int *flags, umode_t mode)
19654 +{
19655 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19656 +       struct vs_mapping *vdm, *global;
19657 +       struct vx_dmap_target *vdmt;
19658 +       int ret = 0;
19659 +       xid_t xid = vxi->vx_id;
19660 +       int index;
19661 +
19662 +       spin_lock(hash_lock);
19663 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
19664 +               ret = 1;
19665 +               vdmt = &vdm->target;
19666 +               goto found;
19667 +       }
19668 +
19669 +       index = __mode_to_default(mode);
19670 +       if (vxi && vxi->dmap.targets[index].flags) {
19671 +               ret = 2;
19672 +               vdmt = &vxi->dmap.targets[index];
19673 +       } else if (global) {
19674 +               ret = 3;
19675 +               vdmt = &global->target;
19676 +               goto found;
19677 +       } else {
19678 +               ret = 4;
19679 +               vdmt = &dmap_defaults[index];
19680 +       }
19681 +
19682 +found:
19683 +       if (target && (vdmt->flags & DATTR_REMAP))
19684 +               *target = vdmt->target;
19685 +       else if (target)
19686 +               *target = device;
19687 +       if (flags)
19688 +               *flags = vdmt->flags;
19689 +
19690 +       spin_unlock(hash_lock);
19691 +
19692 +       return ret;
19693 +}
19694 +
19695 +
19696 +/*     __remove_mapping()
19697 + *     remove a mapping from the hash table
19698 + */
19699 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
19700 +       umode_t mode)
19701 +{
19702 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19703 +       struct vs_mapping *vdm = NULL;
19704 +       int ret = 0;
19705 +
19706 +       spin_lock(hash_lock);
19707 +
19708 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
19709 +               NULL);
19710 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
19711 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
19712 +       if (ret < 0)
19713 +               goto out;
19714 +       hlist_del(&vdm->dm_hlist);
19715 +
19716 +out:
19717 +       spin_unlock(hash_lock);
19718 +       if (vdm)
19719 +               kmem_cache_free(dmap_cachep, vdm);
19720 +       return ret;
19721 +}
19722 +
19723 +
19724 +
19725 +int vs_map_device(struct vx_info *vxi,
19726 +       dev_t device, dev_t *target, umode_t mode)
19727 +{
19728 +       int ret, flags = DATTR_MASK;
19729 +
19730 +       if (!vxi) {
19731 +               if (target)
19732 +                       *target = device;
19733 +               goto out;
19734 +       }
19735 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
19736 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
19737 +               device, target ? *target : 0, flags, mode, ret);
19738 +out:
19739 +       return (flags & DATTR_MASK);
19740 +}
19741 +
19742 +
19743 +
19744 +static int do_set_mapping(struct vx_info *vxi,
19745 +       dev_t device, dev_t target, int flags, umode_t mode)
19746 +{
19747 +       if (device) {
19748 +               struct vs_mapping *new;
19749 +
19750 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
19751 +               if (!new)
19752 +                       return -ENOMEM;
19753 +
19754 +               INIT_HLIST_NODE(&new->dm_hlist);
19755 +               new->device = device;
19756 +               new->target.target = target;
19757 +               new->target.flags = flags | mode;
19758 +               new->xid = (vxi ? vxi->vx_id : 0);
19759 +
19760 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
19761 +               __hash_mapping(vxi, new);
19762 +       } else {
19763 +               struct vx_dmap_target new = {
19764 +                       .target = target,
19765 +                       .flags = flags | mode,
19766 +               };
19767 +               __set_default(vxi, mode, &new);
19768 +       }
19769 +       return 0;
19770 +}
19771 +
19772 +
19773 +static int do_unset_mapping(struct vx_info *vxi,
19774 +       dev_t device, dev_t target, int flags, umode_t mode)
19775 +{
19776 +       int ret = -EINVAL;
19777 +
19778 +       if (device) {
19779 +               ret = __remove_mapping(vxi, device, mode);
19780 +               if (ret < 0)
19781 +                       goto out;
19782 +       } else {
19783 +               ret = __remove_default(vxi, mode);
19784 +               if (ret < 0)
19785 +                       goto out;
19786 +       }
19787 +
19788 +out:
19789 +       return ret;
19790 +}
19791 +
19792 +
19793 +static inline int __user_device(const char __user *name, dev_t *dev,
19794 +       umode_t *mode)
19795 +{
19796 +       struct nameidata nd;
19797 +       int ret;
19798 +
19799 +       if (!name) {
19800 +               *dev = 0;
19801 +               return 0;
19802 +       }
19803 +       ret = user_lpath(name, &nd.path);
19804 +       if (ret)
19805 +               return ret;
19806 +       if (nd.path.dentry->d_inode) {
19807 +               *dev = nd.path.dentry->d_inode->i_rdev;
19808 +               *mode = nd.path.dentry->d_inode->i_mode;
19809 +       }
19810 +       path_put(&nd.path);
19811 +       return 0;
19812 +}
19813 +
19814 +static inline int __mapping_mode(dev_t device, dev_t target,
19815 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
19816 +{
19817 +       if (device)
19818 +               *mode = device_mode & S_IFMT;
19819 +       else if (target)
19820 +               *mode = target_mode & S_IFMT;
19821 +       else
19822 +               return -EINVAL;
19823 +
19824 +       /* if both given, device and target mode have to match */
19825 +       if (device && target &&
19826 +               ((device_mode ^ target_mode) & S_IFMT))
19827 +               return -EINVAL;
19828 +       return 0;
19829 +}
19830 +
19831 +
19832 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
19833 +       const char __user *target_path, int flags, int set)
19834 +{
19835 +       dev_t device = ~0, target = ~0;
19836 +       umode_t device_mode = 0, target_mode = 0, mode;
19837 +       int ret;
19838 +
19839 +       ret = __user_device(device_path, &device, &device_mode);
19840 +       if (ret)
19841 +               return ret;
19842 +       ret = __user_device(target_path, &target, &target_mode);
19843 +       if (ret)
19844 +               return ret;
19845 +
19846 +       ret = __mapping_mode(device, target,
19847 +               device_mode, target_mode, &mode);
19848 +       if (ret)
19849 +               return ret;
19850 +
19851 +       if (set)
19852 +               return do_set_mapping(vxi, device, target,
19853 +                       flags, mode);
19854 +       else
19855 +               return do_unset_mapping(vxi, device, target,
19856 +                       flags, mode);
19857 +}
19858 +
19859 +
19860 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
19861 +{
19862 +       struct vcmd_set_mapping_v0 vc_data;
19863 +
19864 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19865 +               return -EFAULT;
19866 +
19867 +       return do_mapping(vxi, vc_data.device, vc_data.target,
19868 +               vc_data.flags, 1);
19869 +}
19870 +
19871 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
19872 +{
19873 +       struct vcmd_set_mapping_v0 vc_data;
19874 +
19875 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19876 +               return -EFAULT;
19877 +
19878 +       return do_mapping(vxi, vc_data.device, vc_data.target,
19879 +               vc_data.flags, 0);
19880 +}
19881 +
19882 +
19883 +#ifdef CONFIG_COMPAT
19884 +
19885 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
19886 +{
19887 +       struct vcmd_set_mapping_v0_x32 vc_data;
19888 +
19889 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19890 +               return -EFAULT;
19891 +
19892 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
19893 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
19894 +}
19895 +
19896 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
19897 +{
19898 +       struct vcmd_set_mapping_v0_x32 vc_data;
19899 +
19900 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19901 +               return -EFAULT;
19902 +
19903 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
19904 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
19905 +}
19906 +
19907 +#endif /* CONFIG_COMPAT */
19908 +
19909 +
19910 diff -NurpP --minimal linux-2.6.32.56/kernel/vserver/dlimit.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/dlimit.c
19911 --- linux-2.6.32.56/kernel/vserver/dlimit.c     1970-01-01 01:00:00.000000000 +0100
19912 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/dlimit.c     2011-06-10 13:03:02.000000000 +0200
19913 @@ -0,0 +1,529 @@
19914 +/*
19915 + *  linux/kernel/vserver/dlimit.c
19916 + *
19917 + *  Virtual Server: Context Disk Limits
19918 + *
19919 + *  Copyright (C) 2004-2009  Herbert Pötzl
19920 + *
19921 + *  V0.01  initial version
19922 + *  V0.02  compat32 splitup
19923 + *  V0.03  extended interface
19924 + *
19925 + */
19926 +
19927 +#include <linux/statfs.h>
19928 +#include <linux/sched.h>
19929 +#include <linux/namei.h>
19930 +#include <linux/vs_tag.h>
19931 +#include <linux/vs_dlimit.h>
19932 +#include <linux/vserver/dlimit_cmd.h>
19933 +
19934 +#include <asm/uaccess.h>
19935 +
19936 +/*     __alloc_dl_info()
19937 +
19938 +       * allocate an initialized dl_info struct
19939 +       * doesn't make it visible (hash)                        */
19940 +
19941 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
19942 +{
19943 +       struct dl_info *new = NULL;
19944 +
19945 +       vxdprintk(VXD_CBIT(dlim, 5),
19946 +               "alloc_dl_info(%p,%d)*", sb, tag);
19947 +
19948 +       /* would this benefit from a slab cache? */
19949 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
19950 +       if (!new)
19951 +               return 0;
19952 +
19953 +       memset(new, 0, sizeof(struct dl_info));
19954 +       new->dl_tag = tag;
19955 +       new->dl_sb = sb;
19956 +       INIT_RCU_HEAD(&new->dl_rcu);
19957 +       INIT_HLIST_NODE(&new->dl_hlist);
19958 +       spin_lock_init(&new->dl_lock);
19959 +       atomic_set(&new->dl_refcnt, 0);
19960 +       atomic_set(&new->dl_usecnt, 0);
19961 +
19962 +       /* rest of init goes here */
19963 +
19964 +       vxdprintk(VXD_CBIT(dlim, 4),
19965 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
19966 +       return new;
19967 +}
19968 +
19969 +/*     __dealloc_dl_info()
19970 +
19971 +       * final disposal of dl_info                             */
19972 +
19973 +static void __dealloc_dl_info(struct dl_info *dli)
19974 +{
19975 +       vxdprintk(VXD_CBIT(dlim, 4),
19976 +               "dealloc_dl_info(%p)", dli);
19977 +
19978 +       dli->dl_hlist.next = LIST_POISON1;
19979 +       dli->dl_tag = -1;
19980 +       dli->dl_sb = 0;
19981 +
19982 +       BUG_ON(atomic_read(&dli->dl_usecnt));
19983 +       BUG_ON(atomic_read(&dli->dl_refcnt));
19984 +
19985 +       kfree(dli);
19986 +}
19987 +
19988 +
19989 +/*     hash table for dl_info hash */
19990 +
19991 +#define DL_HASH_SIZE   13
19992 +
19993 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
19994 +
19995 +static spinlock_t dl_info_hash_lock = SPIN_LOCK_UNLOCKED;
19996 +
19997 +
19998 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
19999 +{
20000 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
20001 +}
20002 +
20003 +
20004 +
20005 +/*     __hash_dl_info()
20006 +
20007 +       * add the dli to the global hash table
20008 +       * requires the hash_lock to be held                     */
20009 +
20010 +static inline void __hash_dl_info(struct dl_info *dli)
20011 +{
20012 +       struct hlist_head *head;
20013 +
20014 +       vxdprintk(VXD_CBIT(dlim, 6),
20015 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
20016 +       get_dl_info(dli);
20017 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
20018 +       hlist_add_head_rcu(&dli->dl_hlist, head);
20019 +}
20020 +
20021 +/*     __unhash_dl_info()
20022 +
20023 +       * remove the dli from the global hash table
20024 +       * requires the hash_lock to be held                     */
20025 +
20026 +static inline void __unhash_dl_info(struct dl_info *dli)
20027 +{
20028 +       vxdprintk(VXD_CBIT(dlim, 6),
20029 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
20030 +       hlist_del_rcu(&dli->dl_hlist);
20031 +       put_dl_info(dli);
20032 +}
20033 +
20034 +
20035 +/*     __lookup_dl_info()
20036 +
20037 +       * requires the rcu_read_lock()
20038 +       * doesn't increment the dl_refcnt                       */
20039 +
20040 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
20041 +{
20042 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
20043 +       struct hlist_node *pos;
20044 +       struct dl_info *dli;
20045 +
20046 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
20047 +
20048 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
20049 +                       return dli;
20050 +               }
20051 +       }
20052 +       return NULL;
20053 +}
20054 +
20055 +
20056 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
20057 +{
20058 +       struct dl_info *dli;
20059 +
20060 +       rcu_read_lock();
20061 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
20062 +       vxdprintk(VXD_CBIT(dlim, 7),
20063 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
20064 +       rcu_read_unlock();
20065 +       return dli;
20066 +}
20067 +
20068 +void rcu_free_dl_info(struct rcu_head *head)
20069 +{
20070 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
20071 +       int usecnt, refcnt;
20072 +
20073 +       BUG_ON(!dli || !head);
20074 +
20075 +       usecnt = atomic_read(&dli->dl_usecnt);
20076 +       BUG_ON(usecnt < 0);
20077 +
20078 +       refcnt = atomic_read(&dli->dl_refcnt);
20079 +       BUG_ON(refcnt < 0);
20080 +
20081 +       vxdprintk(VXD_CBIT(dlim, 3),
20082 +               "rcu_free_dl_info(%p)", dli);
20083 +       if (!usecnt)
20084 +               __dealloc_dl_info(dli);
20085 +       else
20086 +               printk("!!! rcu didn't free\n");
20087 +}
20088 +
20089 +
20090 +
20091 +
20092 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
20093 +       uint32_t flags, int add)
20094 +{
20095 +       struct path path;
20096 +       int ret;
20097 +
20098 +       ret = user_lpath(name, &path);
20099 +       if (!ret) {
20100 +               struct super_block *sb;
20101 +               struct dl_info *dli;
20102 +
20103 +               ret = -EINVAL;
20104 +               if (!path.dentry->d_inode)
20105 +                       goto out_release;
20106 +               if (!(sb = path.dentry->d_inode->i_sb))
20107 +                       goto out_release;
20108 +
20109 +               if (add) {
20110 +                       dli = __alloc_dl_info(sb, id);
20111 +                       spin_lock(&dl_info_hash_lock);
20112 +
20113 +                       ret = -EEXIST;
20114 +                       if (__lookup_dl_info(sb, id))
20115 +                               goto out_unlock;
20116 +                       __hash_dl_info(dli);
20117 +                       dli = NULL;
20118 +               } else {
20119 +                       spin_lock(&dl_info_hash_lock);
20120 +                       dli = __lookup_dl_info(sb, id);
20121 +
20122 +                       ret = -ESRCH;
20123 +                       if (!dli)
20124 +                               goto out_unlock;
20125 +                       __unhash_dl_info(dli);
20126 +               }
20127 +               ret = 0;
20128 +       out_unlock:
20129 +               spin_unlock(&dl_info_hash_lock);
20130 +               if (add && dli)
20131 +                       __dealloc_dl_info(dli);
20132 +       out_release:
20133 +               path_put(&path);
20134 +       }
20135 +       return ret;
20136 +}
20137 +
20138 +int vc_add_dlimit(uint32_t id, void __user *data)
20139 +{
20140 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
20141 +
20142 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20143 +               return -EFAULT;
20144 +
20145 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
20146 +}
20147 +
20148 +int vc_rem_dlimit(uint32_t id, void __user *data)
20149 +{
20150 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
20151 +
20152 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20153 +               return -EFAULT;
20154 +
20155 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
20156 +}
20157 +
20158 +#ifdef CONFIG_COMPAT
20159 +
20160 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
20161 +{
20162 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
20163 +
20164 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20165 +               return -EFAULT;
20166 +
20167 +       return do_addrem_dlimit(id,
20168 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
20169 +}
20170 +
20171 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
20172 +{
20173 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
20174 +
20175 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20176 +               return -EFAULT;
20177 +
20178 +       return do_addrem_dlimit(id,
20179 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
20180 +}
20181 +
20182 +#endif /* CONFIG_COMPAT */
20183 +
20184 +
20185 +static inline
20186 +int do_set_dlimit(uint32_t id, const char __user *name,
20187 +       uint32_t space_used, uint32_t space_total,
20188 +       uint32_t inodes_used, uint32_t inodes_total,
20189 +       uint32_t reserved, uint32_t flags)
20190 +{
20191 +       struct path path;
20192 +       int ret;
20193 +
20194 +       ret = user_lpath(name, &path);
20195 +       if (!ret) {
20196 +               struct super_block *sb;
20197 +               struct dl_info *dli;
20198 +
20199 +               ret = -EINVAL;
20200 +               if (!path.dentry->d_inode)
20201 +                       goto out_release;
20202 +               if (!(sb = path.dentry->d_inode->i_sb))
20203 +                       goto out_release;
20204 +
20205 +               /* sanity checks */
20206 +               if ((reserved != CDLIM_KEEP &&
20207 +                       reserved > 100) ||
20208 +                       (inodes_used != CDLIM_KEEP &&
20209 +                       inodes_used > inodes_total) ||
20210 +                       (space_used != CDLIM_KEEP &&
20211 +                       space_used > space_total))
20212 +                       goto out_release;
20213 +
20214 +               ret = -ESRCH;
20215 +               dli = locate_dl_info(sb, id);
20216 +               if (!dli)
20217 +                       goto out_release;
20218 +
20219 +               spin_lock(&dli->dl_lock);
20220 +
20221 +               if (inodes_used != CDLIM_KEEP)
20222 +                       dli->dl_inodes_used = inodes_used;
20223 +               if (inodes_total != CDLIM_KEEP)
20224 +                       dli->dl_inodes_total = inodes_total;
20225 +               if (space_used != CDLIM_KEEP)
20226 +                       dli->dl_space_used = dlimit_space_32to64(
20227 +                               space_used, flags, DLIMS_USED);
20228 +
20229 +               if (space_total == CDLIM_INFINITY)
20230 +                       dli->dl_space_total = DLIM_INFINITY;
20231 +               else if (space_total != CDLIM_KEEP)
20232 +                       dli->dl_space_total = dlimit_space_32to64(
20233 +                               space_total, flags, DLIMS_TOTAL);
20234 +
20235 +               if (reserved != CDLIM_KEEP)
20236 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
20237 +
20238 +               spin_unlock(&dli->dl_lock);
20239 +
20240 +               put_dl_info(dli);
20241 +               ret = 0;
20242 +
20243 +       out_release:
20244 +               path_put(&path);
20245 +       }
20246 +       return ret;
20247 +}
20248 +
20249 +int vc_set_dlimit(uint32_t id, void __user *data)
20250 +{
20251 +       struct vcmd_ctx_dlimit_v0 vc_data;
20252 +
20253 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20254 +               return -EFAULT;
20255 +
20256 +       return do_set_dlimit(id, vc_data.name,
20257 +               vc_data.space_used, vc_data.space_total,
20258 +               vc_data.inodes_used, vc_data.inodes_total,
20259 +               vc_data.reserved, vc_data.flags);
20260 +}
20261 +
20262 +#ifdef CONFIG_COMPAT
20263 +
20264 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
20265 +{
20266 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
20267 +
20268 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20269 +               return -EFAULT;
20270 +
20271 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
20272 +               vc_data.space_used, vc_data.space_total,
20273 +               vc_data.inodes_used, vc_data.inodes_total,
20274 +               vc_data.reserved, vc_data.flags);
20275 +}
20276 +
20277 +#endif /* CONFIG_COMPAT */
20278 +
20279 +
20280 +static inline
20281 +int do_get_dlimit(uint32_t id, const char __user *name,
20282 +       uint32_t *space_used, uint32_t *space_total,
20283 +       uint32_t *inodes_used, uint32_t *inodes_total,
20284 +       uint32_t *reserved, uint32_t *flags)
20285 +{
20286 +       struct path path;
20287 +       int ret;
20288 +
20289 +       ret = user_lpath(name, &path);
20290 +       if (!ret) {
20291 +               struct super_block *sb;
20292 +               struct dl_info *dli;
20293 +
20294 +               ret = -EINVAL;
20295 +               if (!path.dentry->d_inode)
20296 +                       goto out_release;
20297 +               if (!(sb = path.dentry->d_inode->i_sb))
20298 +                       goto out_release;
20299 +
20300 +               ret = -ESRCH;
20301 +               dli = locate_dl_info(sb, id);
20302 +               if (!dli)
20303 +                       goto out_release;
20304 +
20305 +               spin_lock(&dli->dl_lock);
20306 +               *inodes_used = dli->dl_inodes_used;
20307 +               *inodes_total = dli->dl_inodes_total;
20308 +
20309 +               *space_used = dlimit_space_64to32(
20310 +                       dli->dl_space_used, flags, DLIMS_USED);
20311 +
20312 +               if (dli->dl_space_total == DLIM_INFINITY)
20313 +                       *space_total = CDLIM_INFINITY;
20314 +               else
20315 +                       *space_total = dlimit_space_64to32(
20316 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
20317 +
20318 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
20319 +               spin_unlock(&dli->dl_lock);
20320 +
20321 +               put_dl_info(dli);
20322 +               ret = -EFAULT;
20323 +
20324 +               ret = 0;
20325 +       out_release:
20326 +               path_put(&path);
20327 +       }
20328 +       return ret;
20329 +}
20330 +
20331 +
20332 +int vc_get_dlimit(uint32_t id, void __user *data)
20333 +{
20334 +       struct vcmd_ctx_dlimit_v0 vc_data;
20335 +       int ret;
20336 +
20337 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20338 +               return -EFAULT;
20339 +
20340 +       ret = do_get_dlimit(id, vc_data.name,
20341 +               &vc_data.space_used, &vc_data.space_total,
20342 +               &vc_data.inodes_used, &vc_data.inodes_total,
20343 +               &vc_data.reserved, &vc_data.flags);
20344 +       if (ret)
20345 +               return ret;
20346 +
20347 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20348 +               return -EFAULT;
20349 +       return 0;
20350 +}
20351 +
20352 +#ifdef CONFIG_COMPAT
20353 +
20354 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
20355 +{
20356 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
20357 +       int ret;
20358 +
20359 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20360 +               return -EFAULT;
20361 +
20362 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
20363 +               &vc_data.space_used, &vc_data.space_total,
20364 +               &vc_data.inodes_used, &vc_data.inodes_total,
20365 +               &vc_data.reserved, &vc_data.flags);
20366 +       if (ret)
20367 +               return ret;
20368 +
20369 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20370 +               return -EFAULT;
20371 +       return 0;
20372 +}
20373 +
20374 +#endif /* CONFIG_COMPAT */
20375 +
20376 +
20377 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
20378 +{
20379 +       struct dl_info *dli;
20380 +       __u64 blimit, bfree, bavail;
20381 +       __u32 ifree;
20382 +
20383 +       dli = locate_dl_info(sb, dx_current_tag());
20384 +       if (!dli)
20385 +               return;
20386 +
20387 +       spin_lock(&dli->dl_lock);
20388 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
20389 +               goto no_ilim;
20390 +
20391 +       /* reduce max inodes available to limit */
20392 +       if (buf->f_files > dli->dl_inodes_total)
20393 +               buf->f_files = dli->dl_inodes_total;
20394 +
20395 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
20396 +       /* reduce free inodes to min */
20397 +       if (ifree < buf->f_ffree)
20398 +               buf->f_ffree = ifree;
20399 +
20400 +no_ilim:
20401 +       if (dli->dl_space_total == DLIM_INFINITY)
20402 +               goto no_blim;
20403 +
20404 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
20405 +
20406 +       if (dli->dl_space_total < dli->dl_space_used)
20407 +               bfree = 0;
20408 +       else
20409 +               bfree = (dli->dl_space_total - dli->dl_space_used)
20410 +                       >> sb->s_blocksize_bits;
20411 +
20412 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
20413 +       if (bavail < dli->dl_space_used)
20414 +               bavail = 0;
20415 +       else
20416 +               bavail = (bavail - dli->dl_space_used)
20417 +                       >> sb->s_blocksize_bits;
20418 +
20419 +       /* reduce max space available to limit */
20420 +       if (buf->f_blocks > blimit)
20421 +               buf->f_blocks = blimit;
20422 +
20423 +       /* reduce free space to min */
20424 +       if (bfree < buf->f_bfree)
20425 +               buf->f_bfree = bfree;
20426 +
20427 +       /* reduce avail space to min */
20428 +       if (bavail < buf->f_bavail)
20429 +               buf->f_bavail = bavail;
20430 +
20431 +no_blim:
20432 +       spin_unlock(&dli->dl_lock);
20433 +       put_dl_info(dli);
20434 +
20435 +       return;
20436 +}
20437 +
20438 +#include <linux/module.h>
20439 +
20440 +EXPORT_SYMBOL_GPL(locate_dl_info);
20441 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
20442 +
20443 diff -NurpP --minimal linux-2.6.32.56/kernel/vserver/helper.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/helper.c
20444 --- linux-2.6.32.56/kernel/vserver/helper.c     1970-01-01 01:00:00.000000000 +0100
20445 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/helper.c     2011-06-10 13:03:02.000000000 +0200
20446 @@ -0,0 +1,223 @@
20447 +/*
20448 + *  linux/kernel/vserver/helper.c
20449 + *
20450 + *  Virtual Context Support
20451 + *
20452 + *  Copyright (C) 2004-2007  Herbert Pötzl
20453 + *
20454 + *  V0.01  basic helper
20455 + *
20456 + */
20457 +
20458 +#include <linux/kmod.h>
20459 +#include <linux/reboot.h>
20460 +#include <linux/vs_context.h>
20461 +#include <linux/vs_network.h>
20462 +#include <linux/vserver/signal.h>
20463 +
20464 +
20465 +char vshelper_path[255] = "/sbin/vshelper";
20466 +
20467 +
20468 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
20469 +{
20470 +       int ret;
20471 +
20472 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
20473 +               printk( KERN_WARNING
20474 +                       "%s: (%s %s) returned %s with %d\n",
20475 +                       name, argv[1], argv[2],
20476 +                       sync ? "sync" : "async", ret);
20477 +       }
20478 +       vxdprintk(VXD_CBIT(switch, 4),
20479 +               "%s: (%s %s) returned %s with %d",
20480 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
20481 +       return ret;
20482 +}
20483 +
20484 +/*
20485 + *      vshelper path is set via /proc/sys
20486 + *      invoked by vserver sys_reboot(), with
20487 + *      the following arguments
20488 + *
20489 + *      argv [0] = vshelper_path;
20490 + *      argv [1] = action: "restart", "halt", "poweroff", ...
20491 + *      argv [2] = context identifier
20492 + *
20493 + *      envp [*] = type-specific parameters
20494 + */
20495 +
20496 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
20497 +{
20498 +       char id_buf[8], cmd_buf[16];
20499 +       char uid_buf[16], pid_buf[16];
20500 +       int ret;
20501 +
20502 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20503 +       char *envp[] = {"HOME=/", "TERM=linux",
20504 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
20505 +                       uid_buf, pid_buf, cmd_buf, 0};
20506 +
20507 +       if (vx_info_state(vxi, VXS_HELPER))
20508 +               return -EAGAIN;
20509 +       vxi->vx_state |= VXS_HELPER;
20510 +
20511 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
20512 +
20513 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20514 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current_uid());
20515 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
20516 +
20517 +       switch (cmd) {
20518 +       case LINUX_REBOOT_CMD_RESTART:
20519 +               argv[1] = "restart";
20520 +               break;
20521 +
20522 +       case LINUX_REBOOT_CMD_HALT:
20523 +               argv[1] = "halt";
20524 +               break;
20525 +
20526 +       case LINUX_REBOOT_CMD_POWER_OFF:
20527 +               argv[1] = "poweroff";
20528 +               break;
20529 +
20530 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
20531 +               argv[1] = "swsusp";
20532 +               break;
20533 +
20534 +       case LINUX_REBOOT_CMD_OOM:
20535 +               argv[1] = "oom";
20536 +               break;
20537 +
20538 +       default:
20539 +               vxi->vx_state &= ~VXS_HELPER;
20540 +               return 0;
20541 +       }
20542 +
20543 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
20544 +       vxi->vx_state &= ~VXS_HELPER;
20545 +       __wakeup_vx_info(vxi);
20546 +       return (ret) ? -EPERM : 0;
20547 +}
20548 +
20549 +
20550 +long vs_reboot(unsigned int cmd, void __user *arg)
20551 +{
20552 +       struct vx_info *vxi = current_vx_info();
20553 +       long ret = 0;
20554 +
20555 +       vxdprintk(VXD_CBIT(misc, 5),
20556 +               "vs_reboot(%p[#%d],%u)",
20557 +               vxi, vxi ? vxi->vx_id : 0, cmd);
20558 +
20559 +       ret = vs_reboot_helper(vxi, cmd, arg);
20560 +       if (ret)
20561 +               return ret;
20562 +
20563 +       vxi->reboot_cmd = cmd;
20564 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
20565 +               switch (cmd) {
20566 +               case LINUX_REBOOT_CMD_RESTART:
20567 +               case LINUX_REBOOT_CMD_HALT:
20568 +               case LINUX_REBOOT_CMD_POWER_OFF:
20569 +                       vx_info_kill(vxi, 0, SIGKILL);
20570 +                       vx_info_kill(vxi, 1, SIGKILL);
20571 +               default:
20572 +                       break;
20573 +               }
20574 +       }
20575 +       return 0;
20576 +}
20577 +
20578 +long vs_oom_action(unsigned int cmd)
20579 +{
20580 +       struct vx_info *vxi = current_vx_info();
20581 +       long ret = 0;
20582 +
20583 +       vxdprintk(VXD_CBIT(misc, 5),
20584 +               "vs_oom_action(%p[#%d],%u)",
20585 +               vxi, vxi ? vxi->vx_id : 0, cmd);
20586 +
20587 +       ret = vs_reboot_helper(vxi, cmd, NULL);
20588 +       if (ret)
20589 +               return ret;
20590 +
20591 +       vxi->reboot_cmd = cmd;
20592 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
20593 +               vx_info_kill(vxi, 0, SIGKILL);
20594 +               vx_info_kill(vxi, 1, SIGKILL);
20595 +       }
20596 +       return 0;
20597 +}
20598 +
20599 +/*
20600 + *      argv [0] = vshelper_path;
20601 + *      argv [1] = action: "startup", "shutdown"
20602 + *      argv [2] = context identifier
20603 + *
20604 + *      envp [*] = type-specific parameters
20605 + */
20606 +
20607 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
20608 +{
20609 +       char id_buf[8], cmd_buf[16];
20610 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20611 +       char *envp[] = {"HOME=/", "TERM=linux",
20612 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
20613 +
20614 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
20615 +               return 0;
20616 +
20617 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
20618 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20619 +
20620 +       switch (cmd) {
20621 +       case VSC_STARTUP:
20622 +               argv[1] = "startup";
20623 +               break;
20624 +       case VSC_SHUTDOWN:
20625 +               argv[1] = "shutdown";
20626 +               break;
20627 +       default:
20628 +               return 0;
20629 +       }
20630 +
20631 +       return do_vshelper(vshelper_path, argv, envp, 1);
20632 +}
20633 +
20634 +
20635 +/*
20636 + *      argv [0] = vshelper_path;
20637 + *      argv [1] = action: "netup", "netdown"
20638 + *      argv [2] = context identifier
20639 + *
20640 + *      envp [*] = type-specific parameters
20641 + */
20642 +
20643 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
20644 +{
20645 +       char id_buf[8], cmd_buf[16];
20646 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
20647 +       char *envp[] = {"HOME=/", "TERM=linux",
20648 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
20649 +
20650 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
20651 +               return 0;
20652 +
20653 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
20654 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
20655 +
20656 +       switch (cmd) {
20657 +       case VSC_NETUP:
20658 +               argv[1] = "netup";
20659 +               break;
20660 +       case VSC_NETDOWN:
20661 +               argv[1] = "netdown";
20662 +               break;
20663 +       default:
20664 +               return 0;
20665 +       }
20666 +
20667 +       return do_vshelper(vshelper_path, argv, envp, 1);
20668 +}
20669 +
20670 diff -NurpP --minimal linux-2.6.32.56/kernel/vserver/history.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/history.c
20671 --- linux-2.6.32.56/kernel/vserver/history.c    1970-01-01 01:00:00.000000000 +0100
20672 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/history.c    2011-06-10 13:03:02.000000000 +0200
20673 @@ -0,0 +1,258 @@
20674 +/*
20675 + *  kernel/vserver/history.c
20676 + *
20677 + *  Virtual Context History Backtrace
20678 + *
20679 + *  Copyright (C) 2004-2007  Herbert Pötzl
20680 + *
20681 + *  V0.01  basic structure
20682 + *  V0.02  hash/unhash and trace
20683 + *  V0.03  preemption fixes
20684 + *
20685 + */
20686 +
20687 +#include <linux/module.h>
20688 +#include <asm/uaccess.h>
20689 +
20690 +#include <linux/vserver/context.h>
20691 +#include <linux/vserver/debug.h>
20692 +#include <linux/vserver/debug_cmd.h>
20693 +#include <linux/vserver/history.h>
20694 +
20695 +
20696 +#ifdef CONFIG_VSERVER_HISTORY
20697 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
20698 +#else
20699 +#define VXH_SIZE       64
20700 +#endif
20701 +
20702 +struct _vx_history {
20703 +       unsigned int counter;
20704 +
20705 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
20706 +};
20707 +
20708 +
20709 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
20710 +
20711 +unsigned volatile int vxh_active = 1;
20712 +
20713 +static atomic_t sequence = ATOMIC_INIT(0);
20714 +
20715 +
20716 +/*     vxh_advance()
20717 +
20718 +       * requires disabled preemption                          */
20719 +
20720 +struct _vx_hist_entry *vxh_advance(void *loc)
20721 +{
20722 +       unsigned int cpu = smp_processor_id();
20723 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
20724 +       struct _vx_hist_entry *entry;
20725 +       unsigned int index;
20726 +
20727 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
20728 +       entry = &hist->entry[index];
20729 +
20730 +       entry->seq = atomic_inc_return(&sequence);
20731 +       entry->loc = loc;
20732 +       return entry;
20733 +}
20734 +
20735 +EXPORT_SYMBOL_GPL(vxh_advance);
20736 +
20737 +
20738 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
20739 +
20740 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
20741 +
20742 +
20743 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
20744 +
20745 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
20746 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
20747 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
20748 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
20749 +
20750 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
20751 +{
20752 +       switch (e->type) {
20753 +       case VXH_THROW_OOPS:
20754 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
20755 +               break;
20756 +
20757 +       case VXH_GET_VX_INFO:
20758 +       case VXH_PUT_VX_INFO:
20759 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
20760 +                       VXH_LOC_ARGS(e),
20761 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
20762 +                       VXH_VXI_ARGS(e));
20763 +               break;
20764 +
20765 +       case VXH_INIT_VX_INFO:
20766 +       case VXH_SET_VX_INFO:
20767 +       case VXH_CLR_VX_INFO:
20768 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
20769 +                       VXH_LOC_ARGS(e),
20770 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
20771 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
20772 +                       VXH_VXI_ARGS(e), e->sc.data);
20773 +               break;
20774 +
20775 +       case VXH_CLAIM_VX_INFO:
20776 +       case VXH_RELEASE_VX_INFO:
20777 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
20778 +                       VXH_LOC_ARGS(e),
20779 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
20780 +                       VXH_VXI_ARGS(e), e->sc.data);
20781 +               break;
20782 +
20783 +       case VXH_ALLOC_VX_INFO:
20784 +       case VXH_DEALLOC_VX_INFO:
20785 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
20786 +                       VXH_LOC_ARGS(e),
20787 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
20788 +                       VXH_VXI_ARGS(e));
20789 +               break;
20790 +
20791 +       case VXH_HASH_VX_INFO:
20792 +       case VXH_UNHASH_VX_INFO:
20793 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
20794 +                       VXH_LOC_ARGS(e),
20795 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
20796 +                       VXH_VXI_ARGS(e));
20797 +               break;
20798 +
20799 +       case VXH_LOC_VX_INFO:
20800 +       case VXH_LOOKUP_VX_INFO:
20801 +       case VXH_CREATE_VX_INFO:
20802 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
20803 +                       VXH_LOC_ARGS(e),
20804 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
20805 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
20806 +                       e->ll.arg, VXH_VXI_ARGS(e));
20807 +               break;
20808 +       }
20809 +}
20810 +
20811 +static void __vxh_dump_history(void)
20812 +{
20813 +       unsigned int i, cpu;
20814 +
20815 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
20816 +               atomic_read(&sequence), NR_CPUS);
20817 +
20818 +       for (i = 0; i < VXH_SIZE; i++) {
20819 +               for_each_online_cpu(cpu) {
20820 +                       struct _vx_history *hist =
20821 +                               &per_cpu(vx_history_buffer, cpu);
20822 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
20823 +                       struct _vx_hist_entry *entry = &hist->entry[index];
20824 +
20825 +                       vxh_dump_entry(entry, cpu);
20826 +               }
20827 +       }
20828 +}
20829 +
20830 +void   vxh_dump_history(void)
20831 +{
20832 +       vxh_active = 0;
20833 +#ifdef CONFIG_SMP
20834 +       local_irq_enable();
20835 +       smp_send_stop();
20836 +       local_irq_disable();
20837 +#endif
20838 +       __vxh_dump_history();
20839 +}
20840 +
20841 +
20842 +/* vserver syscall commands below here */
20843 +
20844 +
20845 +int vc_dump_history(uint32_t id)
20846 +{
20847 +       vxh_active = 0;
20848 +       __vxh_dump_history();
20849 +       vxh_active = 1;
20850 +
20851 +       return 0;
20852 +}
20853 +
20854 +
20855 +int do_read_history(struct __user _vx_hist_entry *data,
20856 +       int cpu, uint32_t *index, uint32_t *count)
20857 +{
20858 +       int pos, ret = 0;
20859 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
20860 +       int end = hist->counter;
20861 +       int start = end - VXH_SIZE + 2;
20862 +       int idx = *index;
20863 +
20864 +       /* special case: get current pos */
20865 +       if (!*count) {
20866 +               *index = end;
20867 +               return 0;
20868 +       }
20869 +
20870 +       /* have we lost some data? */
20871 +       if (idx < start)
20872 +               idx = start;
20873 +
20874 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
20875 +               struct _vx_hist_entry *entry =
20876 +                       &hist->entry[idx % VXH_SIZE];
20877 +
20878 +               /* send entry to userspace */
20879 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
20880 +               if (ret)
20881 +                       break;
20882 +       }
20883 +       /* save new index and count */
20884 +       *index = idx;
20885 +       *count = pos;
20886 +       return ret ? ret : (*index < end);
20887 +}
20888 +
20889 +int vc_read_history(uint32_t id, void __user *data)
20890 +{
20891 +       struct vcmd_read_history_v0 vc_data;
20892 +       int ret;
20893 +
20894 +       if (id >= NR_CPUS)
20895 +               return -EINVAL;
20896 +
20897 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20898 +               return -EFAULT;
20899 +
20900 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
20901 +               id, &vc_data.index, &vc_data.count);
20902 +
20903 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20904 +               return -EFAULT;
20905 +       return ret;
20906 +}
20907 +
20908 +#ifdef CONFIG_COMPAT
20909 +
20910 +int vc_read_history_x32(uint32_t id, void __user *data)
20911 +{
20912 +       struct vcmd_read_history_v0_x32 vc_data;
20913 +       int ret;
20914 +
20915 +       if (id >= NR_CPUS)
20916 +               return -EINVAL;
20917 +
20918 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20919 +               return -EFAULT;
20920 +
20921 +       ret = do_read_history((struct __user _vx_hist_entry *)
20922 +               compat_ptr(vc_data.data_ptr),
20923 +               id, &vc_data.index, &vc_data.count);
20924 +
20925 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20926 +               return -EFAULT;
20927 +       return ret;
20928 +}
20929 +
20930 +#endif /* CONFIG_COMPAT */
20931 +
20932 diff -NurpP --minimal linux-2.6.32.56/kernel/vserver/inet.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/inet.c
20933 --- linux-2.6.32.56/kernel/vserver/inet.c       1970-01-01 01:00:00.000000000 +0100
20934 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/inet.c       2011-06-10 13:03:02.000000000 +0200
20935 @@ -0,0 +1,225 @@
20936 +
20937 +#include <linux/in.h>
20938 +#include <linux/inetdevice.h>
20939 +#include <linux/vs_inet.h>
20940 +#include <linux/vs_inet6.h>
20941 +#include <linux/vserver/debug.h>
20942 +#include <net/route.h>
20943 +#include <net/addrconf.h>
20944 +
20945 +
20946 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
20947 +{
20948 +       int ret = 0;
20949 +
20950 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
20951 +               ret = 1;
20952 +       else {
20953 +               struct nx_addr_v4 *ptr;
20954 +
20955 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
20956 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
20957 +                               ret = 1;
20958 +                               break;
20959 +                       }
20960 +               }
20961 +       }
20962 +
20963 +       vxdprintk(VXD_CBIT(net, 2),
20964 +               "nx_v4_addr_conflict(%p,%p): %d",
20965 +               nxi1, nxi2, ret);
20966 +
20967 +       return ret;
20968 +}
20969 +
20970 +
20971 +#ifdef CONFIG_IPV6
20972 +
20973 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
20974 +{
20975 +       int ret = 0;
20976 +
20977 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
20978 +               ret = 1;
20979 +       else {
20980 +               struct nx_addr_v6 *ptr;
20981 +
20982 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
20983 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
20984 +                               ret = 1;
20985 +                               break;
20986 +                       }
20987 +               }
20988 +       }
20989 +
20990 +       vxdprintk(VXD_CBIT(net, 2),
20991 +               "nx_v6_addr_conflict(%p,%p): %d",
20992 +               nxi1, nxi2, ret);
20993 +
20994 +       return ret;
20995 +}
20996 +
20997 +#endif
20998 +
20999 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
21000 +{
21001 +       struct in_device *in_dev;
21002 +       struct in_ifaddr **ifap;
21003 +       struct in_ifaddr *ifa;
21004 +       int ret = 0;
21005 +
21006 +       if (!dev)
21007 +               goto out;
21008 +       in_dev = in_dev_get(dev);
21009 +       if (!in_dev)
21010 +               goto out;
21011 +
21012 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
21013 +               ifap = &ifa->ifa_next) {
21014 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
21015 +                       ret = 1;
21016 +                       break;
21017 +               }
21018 +       }
21019 +       in_dev_put(in_dev);
21020 +out:
21021 +       return ret;
21022 +}
21023 +
21024 +
21025 +#ifdef CONFIG_IPV6
21026 +
21027 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
21028 +{
21029 +       struct inet6_dev *in_dev;
21030 +       struct inet6_ifaddr **ifap;
21031 +       struct inet6_ifaddr *ifa;
21032 +       int ret = 0;
21033 +
21034 +       if (!dev)
21035 +               goto out;
21036 +       in_dev = in6_dev_get(dev);
21037 +       if (!in_dev)
21038 +               goto out;
21039 +
21040 +       for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
21041 +               ifap = &ifa->if_next) {
21042 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
21043 +                       ret = 1;
21044 +                       break;
21045 +               }
21046 +       }
21047 +       in6_dev_put(in_dev);
21048 +out:
21049 +       return ret;
21050 +}
21051 +
21052 +#endif
21053 +
21054 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
21055 +{
21056 +       int ret = 1;
21057 +
21058 +       if (!nxi)
21059 +               goto out;
21060 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
21061 +               goto out;
21062 +#ifdef CONFIG_IPV6
21063 +       ret = 2;
21064 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
21065 +               goto out;
21066 +#endif
21067 +       ret = 0;
21068 +out:
21069 +       vxdprintk(VXD_CBIT(net, 3),
21070 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
21071 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
21072 +       return ret;
21073 +}
21074 +
21075 +int ip_v4_find_src(struct net *net, struct nx_info *nxi,
21076 +       struct rtable **rp, struct flowi *fl)
21077 +{
21078 +       if (!nxi)
21079 +               return 0;
21080 +
21081 +       /* FIXME: handle lback only case */
21082 +       if (!NX_IPV4(nxi))
21083 +               return -EPERM;
21084 +
21085 +       vxdprintk(VXD_CBIT(net, 4),
21086 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
21087 +               nxi, nxi ? nxi->nx_id : 0,
21088 +               NIPQUAD(fl->fl4_src), NIPQUAD(fl->fl4_dst));
21089 +
21090 +       /* single IP is unconditional */
21091 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
21092 +               (fl->fl4_src == INADDR_ANY))
21093 +               fl->fl4_src = nxi->v4.ip[0].s_addr;
21094 +
21095 +       if (fl->fl4_src == INADDR_ANY) {
21096 +               struct nx_addr_v4 *ptr;
21097 +               __be32 found = 0;
21098 +               int err;
21099 +
21100 +               err = __ip_route_output_key(net, rp, fl);
21101 +               if (!err) {
21102 +                       found = (*rp)->rt_src;
21103 +                       ip_rt_put(*rp);
21104 +                       vxdprintk(VXD_CBIT(net, 4),
21105 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
21106 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(found));
21107 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
21108 +                               goto found;
21109 +               }
21110 +
21111 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
21112 +                       __be32 primary = ptr->ip[0].s_addr;
21113 +                       __be32 mask = ptr->mask.s_addr;
21114 +                       __be32 neta = primary & mask;
21115 +
21116 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
21117 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
21118 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
21119 +                               NIPQUAD(mask), NIPQUAD(neta));
21120 +                       if ((found & mask) != neta)
21121 +                               continue;
21122 +
21123 +                       fl->fl4_src = primary;
21124 +                       err = __ip_route_output_key(net, rp, fl);
21125 +                       vxdprintk(VXD_CBIT(net, 4),
21126 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
21127 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(primary));
21128 +                       if (!err) {
21129 +                               found = (*rp)->rt_src;
21130 +                               ip_rt_put(*rp);
21131 +                               if (found == primary)
21132 +                                       goto found;
21133 +                       }
21134 +               }
21135 +               /* still no source ip? */
21136 +               found = ipv4_is_loopback(fl->fl4_dst)
21137 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
21138 +       found:
21139 +               /* assign src ip to flow */
21140 +               fl->fl4_src = found;
21141 +
21142 +       } else {
21143 +               if (!v4_addr_in_nx_info(nxi, fl->fl4_src, NXA_MASK_BIND))
21144 +                       return -EPERM;
21145 +       }
21146 +
21147 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
21148 +               if (ipv4_is_loopback(fl->fl4_dst))
21149 +                       fl->fl4_dst = nxi->v4_lback.s_addr;
21150 +               if (ipv4_is_loopback(fl->fl4_src))
21151 +                       fl->fl4_src = nxi->v4_lback.s_addr;
21152 +       } else if (ipv4_is_loopback(fl->fl4_dst) &&
21153 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
21154 +               return -EPERM;
21155 +
21156 +       return 0;
21157 +}
21158 +
21159 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
21160 +
21161 diff -NurpP --minimal linux-2.6.32.56/kernel/vserver/init.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/init.c
21162 --- linux-2.6.32.56/kernel/vserver/init.c       1970-01-01 01:00:00.000000000 +0100
21163 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/init.c       2011-06-10 13:03:02.000000000 +0200
21164 @@ -0,0 +1,45 @@
21165 +/*
21166 + *  linux/kernel/init.c
21167 + *
21168 + *  Virtual Server Init
21169 + *
21170 + *  Copyright (C) 2004-2007  Herbert Pötzl
21171 + *
21172 + *  V0.01  basic structure
21173 + *
21174 + */
21175 +
21176 +#include <linux/init.h>
21177 +
21178 +int    vserver_register_sysctl(void);
21179 +void   vserver_unregister_sysctl(void);
21180 +
21181 +
21182 +static int __init init_vserver(void)
21183 +{
21184 +       int ret = 0;
21185 +
21186 +#ifdef CONFIG_VSERVER_DEBUG
21187 +       vserver_register_sysctl();
21188 +#endif
21189 +       return ret;
21190 +}
21191 +
21192 +
21193 +static void __exit exit_vserver(void)
21194 +{
21195 +
21196 +#ifdef CONFIG_VSERVER_DEBUG
21197 +       vserver_unregister_sysctl();
21198 +#endif
21199 +       return;
21200 +}
21201 +
21202 +/* FIXME: GFP_ZONETYPES gone
21203 +long vx_slab[GFP_ZONETYPES]; */
21204 +long vx_area;
21205 +
21206 +
21207 +module_init(init_vserver);
21208 +module_exit(exit_vserver);
21209 +
21210 diff -NurpP --minimal linux-2.6.32.56/kernel/vserver/inode.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/inode.c
21211 --- linux-2.6.32.56/kernel/vserver/inode.c      1970-01-01 01:00:00.000000000 +0100
21212 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/inode.c      2011-06-10 18:58:46.000000000 +0200
21213 @@ -0,0 +1,433 @@
21214 +/*
21215 + *  linux/kernel/vserver/inode.c
21216 + *
21217 + *  Virtual Server: File System Support
21218 + *
21219 + *  Copyright (C) 2004-2007  Herbert Pötzl
21220 + *
21221 + *  V0.01  separated from vcontext V0.05
21222 + *  V0.02  moved to tag (instead of xid)
21223 + *
21224 + */
21225 +
21226 +#include <linux/tty.h>
21227 +#include <linux/proc_fs.h>
21228 +#include <linux/devpts_fs.h>
21229 +#include <linux/fs.h>
21230 +#include <linux/file.h>
21231 +#include <linux/mount.h>
21232 +#include <linux/parser.h>
21233 +#include <linux/namei.h>
21234 +#include <linux/vserver/inode.h>
21235 +#include <linux/vserver/inode_cmd.h>
21236 +#include <linux/vs_base.h>
21237 +#include <linux/vs_tag.h>
21238 +
21239 +#include <asm/uaccess.h>
21240 +
21241 +
21242 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
21243 +{
21244 +       struct proc_dir_entry *entry;
21245 +
21246 +       if (!in || !in->i_sb)
21247 +               return -ESRCH;
21248 +
21249 +       *flags = IATTR_TAG
21250 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
21251 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
21252 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
21253 +               | (IS_COW(in) ? IATTR_COW : 0);
21254 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
21255 +
21256 +       if (S_ISDIR(in->i_mode))
21257 +               *mask |= IATTR_BARRIER;
21258 +
21259 +       if (IS_TAGGED(in)) {
21260 +               *tag = in->i_tag;
21261 +               *mask |= IATTR_TAG;
21262 +       }
21263 +
21264 +       switch (in->i_sb->s_magic) {
21265 +       case PROC_SUPER_MAGIC:
21266 +               entry = PROC_I(in)->pde;
21267 +
21268 +               /* check for specific inodes? */
21269 +               if (entry)
21270 +                       *mask |= IATTR_FLAGS;
21271 +               if (entry)
21272 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
21273 +               else
21274 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
21275 +               break;
21276 +
21277 +       case DEVPTS_SUPER_MAGIC:
21278 +               *tag = in->i_tag;
21279 +               *mask |= IATTR_TAG;
21280 +               break;
21281 +
21282 +       default:
21283 +               break;
21284 +       }
21285 +       return 0;
21286 +}
21287 +
21288 +int vc_get_iattr(void __user *data)
21289 +{
21290 +       struct path path;
21291 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
21292 +       int ret;
21293 +
21294 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21295 +               return -EFAULT;
21296 +
21297 +       ret = user_lpath(vc_data.name, &path);
21298 +       if (!ret) {
21299 +               ret = __vc_get_iattr(path.dentry->d_inode,
21300 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21301 +               path_put(&path);
21302 +       }
21303 +       if (ret)
21304 +               return ret;
21305 +
21306 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21307 +               ret = -EFAULT;
21308 +       return ret;
21309 +}
21310 +
21311 +#ifdef CONFIG_COMPAT
21312 +
21313 +int vc_get_iattr_x32(void __user *data)
21314 +{
21315 +       struct path path;
21316 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
21317 +       int ret;
21318 +
21319 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21320 +               return -EFAULT;
21321 +
21322 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
21323 +       if (!ret) {
21324 +               ret = __vc_get_iattr(path.dentry->d_inode,
21325 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21326 +               path_put(&path);
21327 +       }
21328 +       if (ret)
21329 +               return ret;
21330 +
21331 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21332 +               ret = -EFAULT;
21333 +       return ret;
21334 +}
21335 +
21336 +#endif /* CONFIG_COMPAT */
21337 +
21338 +
21339 +int vc_fget_iattr(uint32_t fd, void __user *data)
21340 +{
21341 +       struct file *filp;
21342 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
21343 +       int ret;
21344 +
21345 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21346 +               return -EFAULT;
21347 +
21348 +       filp = fget(fd);
21349 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
21350 +               return -EBADF;
21351 +
21352 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
21353 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
21354 +
21355 +       fput(filp);
21356 +
21357 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21358 +               ret = -EFAULT;
21359 +       return ret;
21360 +}
21361 +
21362 +
21363 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
21364 +{
21365 +       struct inode *in = de->d_inode;
21366 +       int error = 0, is_proc = 0, has_tag = 0;
21367 +       struct iattr attr = { 0 };
21368 +
21369 +       if (!in || !in->i_sb)
21370 +               return -ESRCH;
21371 +
21372 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
21373 +       if ((*mask & IATTR_FLAGS) && !is_proc)
21374 +               return -EINVAL;
21375 +
21376 +       has_tag = IS_TAGGED(in) ||
21377 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
21378 +       if ((*mask & IATTR_TAG) && !has_tag)
21379 +               return -EINVAL;
21380 +
21381 +       mutex_lock(&in->i_mutex);
21382 +       if (*mask & IATTR_TAG) {
21383 +               attr.ia_tag = *tag;
21384 +               attr.ia_valid |= ATTR_TAG;
21385 +       }
21386 +
21387 +       if (*mask & IATTR_FLAGS) {
21388 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
21389 +               unsigned int iflags = PROC_I(in)->vx_flags;
21390 +
21391 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
21392 +                       | (*flags & IATTR_FLAGS);
21393 +               PROC_I(in)->vx_flags = iflags;
21394 +               if (entry)
21395 +                       entry->vx_flags = iflags;
21396 +       }
21397 +
21398 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
21399 +               IATTR_BARRIER | IATTR_COW)) {
21400 +               int iflags = in->i_flags;
21401 +               int vflags = in->i_vflags;
21402 +
21403 +               if (*mask & IATTR_IMMUTABLE) {
21404 +                       if (*flags & IATTR_IMMUTABLE)
21405 +                               iflags |= S_IMMUTABLE;
21406 +                       else
21407 +                               iflags &= ~S_IMMUTABLE;
21408 +               }
21409 +               if (*mask & IATTR_IXUNLINK) {
21410 +                       if (*flags & IATTR_IXUNLINK)
21411 +                               iflags |= S_IXUNLINK;
21412 +                       else
21413 +                               iflags &= ~S_IXUNLINK;
21414 +               }
21415 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
21416 +                       if (*flags & IATTR_BARRIER)
21417 +                               vflags |= V_BARRIER;
21418 +                       else
21419 +                               vflags &= ~V_BARRIER;
21420 +               }
21421 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
21422 +                       if (*flags & IATTR_COW)
21423 +                               vflags |= V_COW;
21424 +                       else
21425 +                               vflags &= ~V_COW;
21426 +               }
21427 +               if (in->i_op && in->i_op->sync_flags) {
21428 +                       error = in->i_op->sync_flags(in, iflags, vflags);
21429 +                       if (error)
21430 +                               goto out;
21431 +               }
21432 +       }
21433 +
21434 +       if (attr.ia_valid) {
21435 +               if (in->i_op && in->i_op->setattr)
21436 +                       error = in->i_op->setattr(de, &attr);
21437 +               else {
21438 +                       error = inode_change_ok(in, &attr);
21439 +                       if (!error)
21440 +                               error = inode_setattr(in, &attr);
21441 +               }
21442 +       }
21443 +
21444 +out:
21445 +       mutex_unlock(&in->i_mutex);
21446 +       return error;
21447 +}
21448 +
21449 +int vc_set_iattr(void __user *data)
21450 +{
21451 +       struct path path;
21452 +       struct vcmd_ctx_iattr_v1 vc_data;
21453 +       int ret;
21454 +
21455 +       if (!capable(CAP_LINUX_IMMUTABLE))
21456 +               return -EPERM;
21457 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21458 +               return -EFAULT;
21459 +
21460 +       ret = user_lpath(vc_data.name, &path);
21461 +       if (!ret) {
21462 +               ret = __vc_set_iattr(path.dentry,
21463 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21464 +               path_put(&path);
21465 +       }
21466 +
21467 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21468 +               ret = -EFAULT;
21469 +       return ret;
21470 +}
21471 +
21472 +#ifdef CONFIG_COMPAT
21473 +
21474 +int vc_set_iattr_x32(void __user *data)
21475 +{
21476 +       struct path path;
21477 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
21478 +       int ret;
21479 +
21480 +       if (!capable(CAP_LINUX_IMMUTABLE))
21481 +               return -EPERM;
21482 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21483 +               return -EFAULT;
21484 +
21485 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
21486 +       if (!ret) {
21487 +               ret = __vc_set_iattr(path.dentry,
21488 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
21489 +               path_put(&path);
21490 +       }
21491 +
21492 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21493 +               ret = -EFAULT;
21494 +       return ret;
21495 +}
21496 +
21497 +#endif /* CONFIG_COMPAT */
21498 +
21499 +int vc_fset_iattr(uint32_t fd, void __user *data)
21500 +{
21501 +       struct file *filp;
21502 +       struct vcmd_ctx_fiattr_v0 vc_data;
21503 +       int ret;
21504 +
21505 +       if (!capable(CAP_LINUX_IMMUTABLE))
21506 +               return -EPERM;
21507 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21508 +               return -EFAULT;
21509 +
21510 +       filp = fget(fd);
21511 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
21512 +               return -EBADF;
21513 +
21514 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
21515 +               &vc_data.flags, &vc_data.mask);
21516 +
21517 +       fput(filp);
21518 +
21519 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21520 +               return -EFAULT;
21521 +       return ret;
21522 +}
21523 +
21524 +
21525 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
21526 +
21527 +static match_table_t tokens = {
21528 +       {Opt_notagcheck, "notagcheck"},
21529 +#ifdef CONFIG_PROPAGATE
21530 +       {Opt_notag, "notag"},
21531 +       {Opt_tag, "tag"},
21532 +       {Opt_tagid, "tagid=%u"},
21533 +#endif
21534 +       {Opt_err, NULL}
21535 +};
21536 +
21537 +
21538 +static void __dx_parse_remove(char *string, char *opt)
21539 +{
21540 +       char *p = strstr(string, opt);
21541 +       char *q = p;
21542 +
21543 +       if (p) {
21544 +               while (*q != '\0' && *q != ',')
21545 +                       q++;
21546 +               while (*q)
21547 +                       *p++ = *q++;
21548 +               while (*p)
21549 +                       *p++ = '\0';
21550 +       }
21551 +}
21552 +
21553 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
21554 +                unsigned long *flags)
21555 +{
21556 +       int set = 0;
21557 +       substring_t args[MAX_OPT_ARGS];
21558 +       int token, option = 0;
21559 +       char *s, *p, *opts;
21560 +
21561 +       if (!string)
21562 +               return 0;
21563 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
21564 +       if (!s)
21565 +               return 0;
21566 +
21567 +       opts = s;
21568 +       while ((p = strsep(&opts, ",")) != NULL) {
21569 +               token = match_token(p, tokens, args);
21570 +
21571 +               vxdprintk(VXD_CBIT(tag, 7),
21572 +                       "dx_parse_tag(»%s«): %d:#%d",
21573 +                       p, token, option);
21574 +
21575 +               switch (token) {
21576 +#ifdef CONFIG_PROPAGATE
21577 +               case Opt_tag:
21578 +                       if (tag)
21579 +                               *tag = 0;
21580 +                       if (remove)
21581 +                               __dx_parse_remove(s, "tag");
21582 +                       *mnt_flags |= MNT_TAGID;
21583 +                       set |= MNT_TAGID;
21584 +                       break;
21585 +               case Opt_notag:
21586 +                       if (remove)
21587 +                               __dx_parse_remove(s, "notag");
21588 +                       *mnt_flags |= MNT_NOTAG;
21589 +                       set |= MNT_NOTAG;
21590 +                       break;
21591 +               case Opt_tagid:
21592 +                       if (tag && !match_int(args, &option))
21593 +                               *tag = option;
21594 +                       if (remove)
21595 +                               __dx_parse_remove(s, "tagid");
21596 +                       *mnt_flags |= MNT_TAGID;
21597 +                       set |= MNT_TAGID;
21598 +                       break;
21599 +#endif
21600 +               case Opt_notagcheck:
21601 +                       if (remove)
21602 +                               __dx_parse_remove(s, "notagcheck");
21603 +                       *flags |= MS_NOTAGCHECK;
21604 +                       set |= MS_NOTAGCHECK;
21605 +                       break;
21606 +               }
21607 +       }
21608 +       if (set)
21609 +               strcpy(string, s);
21610 +       kfree(s);
21611 +       return set;
21612 +}
21613 +
21614 +#ifdef CONFIG_PROPAGATE
21615 +
21616 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
21617 +{
21618 +       tag_t new_tag = 0;
21619 +       struct vfsmount *mnt;
21620 +       int propagate;
21621 +
21622 +       if (!nd)
21623 +               return;
21624 +       mnt = nd->path.mnt;
21625 +       if (!mnt)
21626 +               return;
21627 +
21628 +       propagate = (mnt->mnt_flags & MNT_TAGID);
21629 +       if (propagate)
21630 +               new_tag = mnt->mnt_tag;
21631 +
21632 +       vxdprintk(VXD_CBIT(tag, 7),
21633 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
21634 +               inode, inode->i_ino, inode->i_tag,
21635 +               new_tag, (propagate) ? 1 : 0);
21636 +
21637 +       if (propagate)
21638 +               inode->i_tag = new_tag;
21639 +}
21640 +
21641 +#include <linux/module.h>
21642 +
21643 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
21644 +
21645 +#endif /* CONFIG_PROPAGATE */
21646 +
21647 diff -NurpP --minimal linux-2.6.32.56/kernel/vserver/limit.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/limit.c
21648 --- linux-2.6.32.56/kernel/vserver/limit.c      1970-01-01 01:00:00.000000000 +0100
21649 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/limit.c      2011-06-10 13:03:02.000000000 +0200
21650 @@ -0,0 +1,392 @@
21651 +/*
21652 + *  linux/kernel/vserver/limit.c
21653 + *
21654 + *  Virtual Server: Context Limits
21655 + *
21656 + *  Copyright (C) 2004-2010  Herbert Pötzl
21657 + *
21658 + *  V0.01  broken out from vcontext V0.05
21659 + *  V0.02  changed vcmds to vxi arg
21660 + *  V0.03  added memory cgroup support
21661 + *
21662 + */
21663 +
21664 +#include <linux/sched.h>
21665 +#include <linux/module.h>
21666 +#include <linux/memcontrol.h>
21667 +#include <linux/res_counter.h>
21668 +#include <linux/vs_limit.h>
21669 +#include <linux/vserver/limit.h>
21670 +#include <linux/vserver/limit_cmd.h>
21671 +
21672 +#include <asm/uaccess.h>
21673 +
21674 +
21675 +const char *vlimit_name[NUM_LIMITS] = {
21676 +       [RLIMIT_CPU]            = "CPU",
21677 +       [RLIMIT_RSS]            = "RSS",
21678 +       [RLIMIT_NPROC]          = "NPROC",
21679 +       [RLIMIT_NOFILE]         = "NOFILE",
21680 +       [RLIMIT_MEMLOCK]        = "VML",
21681 +       [RLIMIT_AS]             = "VM",
21682 +       [RLIMIT_LOCKS]          = "LOCKS",
21683 +       [RLIMIT_SIGPENDING]     = "SIGP",
21684 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
21685 +
21686 +       [VLIMIT_NSOCK]          = "NSOCK",
21687 +       [VLIMIT_OPENFD]         = "OPENFD",
21688 +       [VLIMIT_ANON]           = "ANON",
21689 +       [VLIMIT_SHMEM]          = "SHMEM",
21690 +       [VLIMIT_DENTRY]         = "DENTRY",
21691 +};
21692 +
21693 +EXPORT_SYMBOL_GPL(vlimit_name);
21694 +
21695 +#define MASK_ENTRY(x)  (1 << (x))
21696 +
21697 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
21698 +               /* minimum */
21699 +       0
21700 +       ,       /* softlimit */
21701 +       MASK_ENTRY( RLIMIT_RSS          ) |
21702 +       MASK_ENTRY( VLIMIT_ANON         ) |
21703 +       0
21704 +       ,       /* maximum */
21705 +       MASK_ENTRY( RLIMIT_RSS          ) |
21706 +       MASK_ENTRY( RLIMIT_NPROC        ) |
21707 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
21708 +       MASK_ENTRY( RLIMIT_MEMLOCK      ) |
21709 +       MASK_ENTRY( RLIMIT_AS           ) |
21710 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
21711 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
21712 +
21713 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
21714 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
21715 +       MASK_ENTRY( VLIMIT_ANON         ) |
21716 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
21717 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
21718 +       0
21719 +};
21720 +               /* accounting only */
21721 +uint32_t account_mask =
21722 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
21723 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
21724 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
21725 +       0;
21726 +
21727 +
21728 +static int is_valid_vlimit(int id)
21729 +{
21730 +       uint32_t mask = vlimit_mask.minimum |
21731 +               vlimit_mask.softlimit | vlimit_mask.maximum;
21732 +       return mask & (1 << id);
21733 +}
21734 +
21735 +static int is_accounted_vlimit(int id)
21736 +{
21737 +       if (is_valid_vlimit(id))
21738 +               return 1;
21739 +       return account_mask & (1 << id);
21740 +}
21741 +
21742 +
21743 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
21744 +{
21745 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
21746 +       return VX_VLIM(limit);
21747 +}
21748 +
21749 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
21750 +{
21751 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
21752 +       return VX_VLIM(limit);
21753 +}
21754 +
21755 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
21756 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
21757 +{
21758 +       if (!is_valid_vlimit(id))
21759 +               return -EINVAL;
21760 +
21761 +       if (minimum)
21762 +               *minimum = CRLIM_UNSET;
21763 +       if (softlimit)
21764 +               *softlimit = vc_get_soft(vxi, id);
21765 +       if (maximum)
21766 +               *maximum = vc_get_hard(vxi, id);
21767 +       return 0;
21768 +}
21769 +
21770 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
21771 +{
21772 +       struct vcmd_ctx_rlimit_v0 vc_data;
21773 +       int ret;
21774 +
21775 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21776 +               return -EFAULT;
21777 +
21778 +       ret = do_get_rlimit(vxi, vc_data.id,
21779 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
21780 +       if (ret)
21781 +               return ret;
21782 +
21783 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21784 +               return -EFAULT;
21785 +       return 0;
21786 +}
21787 +
21788 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
21789 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
21790 +{
21791 +       if (!is_valid_vlimit(id))
21792 +               return -EINVAL;
21793 +
21794 +       if (maximum != CRLIM_KEEP)
21795 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
21796 +       if (softlimit != CRLIM_KEEP)
21797 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
21798 +
21799 +       /* clamp soft limit */
21800 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
21801 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
21802 +
21803 +       return 0;
21804 +}
21805 +
21806 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
21807 +{
21808 +       struct vcmd_ctx_rlimit_v0 vc_data;
21809 +
21810 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21811 +               return -EFAULT;
21812 +
21813 +       return do_set_rlimit(vxi, vc_data.id,
21814 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
21815 +}
21816 +
21817 +#ifdef CONFIG_IA32_EMULATION
21818 +
21819 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
21820 +{
21821 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
21822 +
21823 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21824 +               return -EFAULT;
21825 +
21826 +       return do_set_rlimit(vxi, vc_data.id,
21827 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
21828 +}
21829 +
21830 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
21831 +{
21832 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
21833 +       int ret;
21834 +
21835 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21836 +               return -EFAULT;
21837 +
21838 +       ret = do_get_rlimit(vxi, vc_data.id,
21839 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
21840 +       if (ret)
21841 +               return ret;
21842 +
21843 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21844 +               return -EFAULT;
21845 +       return 0;
21846 +}
21847 +
21848 +#endif /* CONFIG_IA32_EMULATION */
21849 +
21850 +
21851 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
21852 +{
21853 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
21854 +               return -EFAULT;
21855 +       return 0;
21856 +}
21857 +
21858 +
21859 +static inline void vx_reset_hits(struct _vx_limit *limit)
21860 +{
21861 +       int lim;
21862 +
21863 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21864 +               atomic_set(&__rlim_lhit(limit, lim), 0);
21865 +       }
21866 +}
21867 +
21868 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
21869 +{
21870 +       vx_reset_hits(&vxi->limit);
21871 +       return 0;
21872 +}
21873 +
21874 +static inline void vx_reset_minmax(struct _vx_limit *limit)
21875 +{
21876 +       rlim_t value;
21877 +       int lim;
21878 +
21879 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21880 +               value = __rlim_get(limit, lim);
21881 +               __rlim_rmax(limit, lim) = value;
21882 +               __rlim_rmin(limit, lim) = value;
21883 +       }
21884 +}
21885 +
21886 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
21887 +{
21888 +       vx_reset_minmax(&vxi->limit);
21889 +       return 0;
21890 +}
21891 +
21892 +
21893 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
21894 +{
21895 +       struct vcmd_rlimit_stat_v0 vc_data;
21896 +       struct _vx_limit *limit = &vxi->limit;
21897 +       int id;
21898 +
21899 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21900 +               return -EFAULT;
21901 +
21902 +       id = vc_data.id;
21903 +       if (!is_accounted_vlimit(id))
21904 +               return -EINVAL;
21905 +
21906 +       vx_limit_fixup(limit, id);
21907 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
21908 +       vc_data.value = __rlim_get(limit, id);
21909 +       vc_data.minimum = __rlim_rmin(limit, id);
21910 +       vc_data.maximum = __rlim_rmax(limit, id);
21911 +
21912 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21913 +               return -EFAULT;
21914 +       return 0;
21915 +}
21916 +
21917 +
21918 +void vx_vsi_meminfo(struct sysinfo *val)
21919 +{
21920 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
21921 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
21922 +       u64 res_limit, res_usage;
21923 +
21924 +       if (!mcg)
21925 +               return;
21926 +
21927 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
21928 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
21929 +
21930 +       if (res_limit != RESOURCE_MAX)
21931 +               val->totalram = (res_limit >> PAGE_SHIFT);
21932 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
21933 +       val->bufferram = 0;
21934 +#else  /* !CONFIG_CGROUP_MEM_RES_CTLR */
21935 +       struct vx_info *vxi = current_vx_info();
21936 +       unsigned long totalram, freeram;
21937 +       rlim_t v;
21938 +
21939 +       /* we blindly accept the max */
21940 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21941 +       totalram = (v != RLIM_INFINITY) ? v : val->totalram;
21942 +
21943 +       /* total minus used equals free */
21944 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21945 +       freeram = (v < totalram) ? totalram - v : 0;
21946 +
21947 +       val->totalram = totalram;
21948 +       val->freeram = freeram;
21949 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
21950 +       val->totalhigh = 0;
21951 +       val->freehigh = 0;
21952 +       return;
21953 +}
21954 +
21955 +void vx_vsi_swapinfo(struct sysinfo *val)
21956 +{
21957 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
21958 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
21959 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
21960 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
21961 +       s64 swap_limit, swap_usage;
21962 +
21963 +       if (!mcg)
21964 +               return;
21965 +
21966 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
21967 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
21968 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
21969 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
21970 +
21971 +       if (res_limit == RESOURCE_MAX)
21972 +               return;
21973 +
21974 +       swap_limit = memsw_limit - res_limit;
21975 +       if (memsw_limit != RESOURCE_MAX)
21976 +               val->totalswap = swap_limit >> PAGE_SHIFT;
21977 +
21978 +       swap_usage = memsw_usage - res_usage;
21979 +       val->freeswap = (swap_usage < swap_limit) ?
21980 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
21981 +#else  /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
21982 +       val->totalswap = 0;
21983 +       val->freeswap = 0;
21984 +#endif /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
21985 +#else  /* !CONFIG_CGROUP_MEM_RES_CTLR */
21986 +       struct vx_info *vxi = current_vx_info();
21987 +       unsigned long totalswap, freeswap;
21988 +       rlim_t v, w;
21989 +
21990 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21991 +       if (v == RLIM_INFINITY) {
21992 +               val->freeswap = val->totalswap;
21993 +               return;
21994 +       }
21995 +
21996 +       /* we blindly accept the max */
21997 +       w = __rlim_hard(&vxi->limit, RLIMIT_RSS);
21998 +       totalswap = (w != RLIM_INFINITY) ? (w - v) : val->totalswap;
21999 +
22000 +       /* currently 'used' swap */
22001 +       w = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
22002 +       w -= (w > v) ? v : w;
22003 +
22004 +       /* total minus used equals free */
22005 +       freeswap = (w < totalswap) ? totalswap - w : 0;
22006 +
22007 +       val->totalswap = totalswap;
22008 +       val->freeswap = freeswap;
22009 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
22010 +       return;
22011 +}
22012 +
22013 +long vx_vsi_cached(struct sysinfo *val)
22014 +{
22015 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
22016 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
22017 +
22018 +       return mem_cgroup_stat_read_cache(mcg);
22019 +#else
22020 +       return 0;
22021 +#endif
22022 +}
22023 +
22024 +
22025 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
22026 +{
22027 +       struct vx_info *vxi = mm->mm_vx_info;
22028 +       unsigned long points;
22029 +       rlim_t v, w;
22030 +
22031 +       if (!vxi)
22032 +               return 0;
22033 +
22034 +       points = vxi->vx_badness_bias;
22035 +
22036 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
22037 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
22038 +       points += (v > w) ? (v - w) : 0;
22039 +
22040 +       return points;
22041 +}
22042 +
22043 diff -NurpP --minimal linux-2.6.32.56/kernel/vserver/limit_init.h linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/limit_init.h
22044 --- linux-2.6.32.56/kernel/vserver/limit_init.h 1970-01-01 01:00:00.000000000 +0100
22045 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/limit_init.h 2011-06-10 13:03:02.000000000 +0200
22046 @@ -0,0 +1,31 @@
22047 +
22048 +
22049 +static inline void vx_info_init_limit(struct _vx_limit *limit)
22050 +{
22051 +       int lim;
22052 +
22053 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
22054 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
22055 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
22056 +               __rlim_set(limit, lim, 0);
22057 +               atomic_set(&__rlim_lhit(limit, lim), 0);
22058 +               __rlim_rmin(limit, lim) = 0;
22059 +               __rlim_rmax(limit, lim) = 0;
22060 +       }
22061 +}
22062 +
22063 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
22064 +{
22065 +       rlim_t value;
22066 +       int lim;
22067 +
22068 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
22069 +               if ((1 << lim) & VLIM_NOCHECK)
22070 +                       continue;
22071 +               value = __rlim_get(limit, lim);
22072 +               vxwprintk_xid(value,
22073 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
22074 +                       limit, vlimit_name[lim], lim, (long)value);
22075 +       }
22076 +}
22077 +
22078 diff -NurpP --minimal linux-2.6.32.56/kernel/vserver/limit_proc.h linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/limit_proc.h
22079 --- linux-2.6.32.56/kernel/vserver/limit_proc.h 1970-01-01 01:00:00.000000000 +0100
22080 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/limit_proc.h 2011-06-10 13:03:02.000000000 +0200
22081 @@ -0,0 +1,57 @@
22082 +#ifndef _VX_LIMIT_PROC_H
22083 +#define _VX_LIMIT_PROC_H
22084 +
22085 +#include <linux/vserver/limit_int.h>
22086 +
22087 +
22088 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
22089 +#define VX_LIMIT_TOP   \
22090 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
22091 +
22092 +#define VX_LIMIT_ARG(r)                                \
22093 +       (unsigned long)__rlim_get(limit, r),    \
22094 +       (unsigned long)__rlim_rmin(limit, r),   \
22095 +       (unsigned long)__rlim_rmax(limit, r),   \
22096 +       VX_VLIM(__rlim_soft(limit, r)),         \
22097 +       VX_VLIM(__rlim_hard(limit, r)),         \
22098 +       atomic_read(&__rlim_lhit(limit, r))
22099 +
22100 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
22101 +{
22102 +       vx_limit_fixup(limit, -1);
22103 +       return sprintf(buffer, VX_LIMIT_TOP
22104 +               "PROC"  VX_LIMIT_FMT
22105 +               "VM"    VX_LIMIT_FMT
22106 +               "VML"   VX_LIMIT_FMT
22107 +               "RSS"   VX_LIMIT_FMT
22108 +               "ANON"  VX_LIMIT_FMT
22109 +               "RMAP"  VX_LIMIT_FMT
22110 +               "FILES" VX_LIMIT_FMT
22111 +               "OFD"   VX_LIMIT_FMT
22112 +               "LOCKS" VX_LIMIT_FMT
22113 +               "SOCK"  VX_LIMIT_FMT
22114 +               "MSGQ"  VX_LIMIT_FMT
22115 +               "SHM"   VX_LIMIT_FMT
22116 +               "SEMA"  VX_LIMIT_FMT
22117 +               "SEMS"  VX_LIMIT_FMT
22118 +               "DENT"  VX_LIMIT_FMT,
22119 +               VX_LIMIT_ARG(RLIMIT_NPROC),
22120 +               VX_LIMIT_ARG(RLIMIT_AS),
22121 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
22122 +               VX_LIMIT_ARG(RLIMIT_RSS),
22123 +               VX_LIMIT_ARG(VLIMIT_ANON),
22124 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
22125 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
22126 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
22127 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
22128 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
22129 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
22130 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
22131 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
22132 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
22133 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
22134 +}
22135 +
22136 +#endif /* _VX_LIMIT_PROC_H */
22137 +
22138 +
22139 diff -NurpP --minimal linux-2.6.32.56/kernel/vserver/monitor.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/monitor.c
22140 --- linux-2.6.32.56/kernel/vserver/monitor.c    1970-01-01 01:00:00.000000000 +0100
22141 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/monitor.c    2011-06-10 13:03:02.000000000 +0200
22142 @@ -0,0 +1,138 @@
22143 +/*
22144 + *  kernel/vserver/monitor.c
22145 + *
22146 + *  Virtual Context Scheduler Monitor
22147 + *
22148 + *  Copyright (C) 2006-2007 Herbert Pötzl
22149 + *
22150 + *  V0.01  basic design
22151 + *
22152 + */
22153 +
22154 +#include <linux/module.h>
22155 +#include <linux/jiffies.h>
22156 +#include <asm/uaccess.h>
22157 +#include <asm/atomic.h>
22158 +
22159 +#include <linux/vserver/monitor.h>
22160 +#include <linux/vserver/debug_cmd.h>
22161 +
22162 +
22163 +#ifdef CONFIG_VSERVER_MONITOR
22164 +#define VXM_SIZE       CONFIG_VSERVER_MONITOR_SIZE
22165 +#else
22166 +#define VXM_SIZE       64
22167 +#endif
22168 +
22169 +struct _vx_monitor {
22170 +       unsigned int counter;
22171 +
22172 +       struct _vx_mon_entry entry[VXM_SIZE+1];
22173 +};
22174 +
22175 +
22176 +DEFINE_PER_CPU(struct _vx_monitor, vx_monitor_buffer);
22177 +
22178 +unsigned volatile int vxm_active = 1;
22179 +
22180 +static atomic_t sequence = ATOMIC_INIT(0);
22181 +
22182 +
22183 +/*     vxm_advance()
22184 +
22185 +       * requires disabled preemption                          */
22186 +
22187 +struct _vx_mon_entry *vxm_advance(int cpu)
22188 +{
22189 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
22190 +       struct _vx_mon_entry *entry;
22191 +       unsigned int index;
22192 +
22193 +       index = vxm_active ? (mon->counter++ % VXM_SIZE) : VXM_SIZE;
22194 +       entry = &mon->entry[index];
22195 +
22196 +       entry->ev.seq = atomic_inc_return(&sequence);
22197 +       entry->ev.jif = jiffies;
22198 +       return entry;
22199 +}
22200 +
22201 +EXPORT_SYMBOL_GPL(vxm_advance);
22202 +
22203 +
22204 +int do_read_monitor(struct __user _vx_mon_entry *data,
22205 +       int cpu, uint32_t *index, uint32_t *count)
22206 +{
22207 +       int pos, ret = 0;
22208 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
22209 +       int end = mon->counter;
22210 +       int start = end - VXM_SIZE + 2;
22211 +       int idx = *index;
22212 +
22213 +       /* special case: get current pos */
22214 +       if (!*count) {
22215 +               *index = end;
22216 +               return 0;
22217 +       }
22218 +
22219 +       /* have we lost some data? */
22220 +       if (idx < start)
22221 +               idx = start;
22222 +
22223 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
22224 +               struct _vx_mon_entry *entry =
22225 +                       &mon->entry[idx % VXM_SIZE];
22226 +
22227 +               /* send entry to userspace */
22228 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
22229 +               if (ret)
22230 +                       break;
22231 +       }
22232 +       /* save new index and count */
22233 +       *index = idx;
22234 +       *count = pos;
22235 +       return ret ? ret : (*index < end);
22236 +}
22237 +
22238 +int vc_read_monitor(uint32_t id, void __user *data)
22239 +{
22240 +       struct vcmd_read_monitor_v0 vc_data;
22241 +       int ret;
22242 +
22243 +       if (id >= NR_CPUS)
22244 +               return -EINVAL;
22245 +
22246 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22247 +               return -EFAULT;
22248 +
22249 +       ret = do_read_monitor((struct __user _vx_mon_entry *)vc_data.data,
22250 +               id, &vc_data.index, &vc_data.count);
22251 +
22252 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22253 +               return -EFAULT;
22254 +       return ret;
22255 +}
22256 +
22257 +#ifdef CONFIG_COMPAT
22258 +
22259 +int vc_read_monitor_x32(uint32_t id, void __user *data)
22260 +{
22261 +       struct vcmd_read_monitor_v0_x32 vc_data;
22262 +       int ret;
22263 +
22264 +       if (id >= NR_CPUS)
22265 +               return -EINVAL;
22266 +
22267 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22268 +               return -EFAULT;
22269 +
22270 +       ret = do_read_monitor((struct __user _vx_mon_entry *)
22271 +               compat_ptr(vc_data.data_ptr),
22272 +               id, &vc_data.index, &vc_data.count);
22273 +
22274 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22275 +               return -EFAULT;
22276 +       return ret;
22277 +}
22278 +
22279 +#endif /* CONFIG_COMPAT */
22280 +
22281 diff -NurpP --minimal linux-2.6.32.56/kernel/vserver/network.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/network.c
22282 --- linux-2.6.32.56/kernel/vserver/network.c    1970-01-01 01:00:00.000000000 +0100
22283 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/network.c    2011-06-10 13:03:02.000000000 +0200
22284 @@ -0,0 +1,864 @@
22285 +/*
22286 + *  linux/kernel/vserver/network.c
22287 + *
22288 + *  Virtual Server: Network Support
22289 + *
22290 + *  Copyright (C) 2003-2007  Herbert Pötzl
22291 + *
22292 + *  V0.01  broken out from vcontext V0.05
22293 + *  V0.02  cleaned up implementation
22294 + *  V0.03  added equiv nx commands
22295 + *  V0.04  switch to RCU based hash
22296 + *  V0.05  and back to locking again
22297 + *  V0.06  changed vcmds to nxi arg
22298 + *  V0.07  have __create claim() the nxi
22299 + *
22300 + */
22301 +
22302 +#include <linux/err.h>
22303 +#include <linux/slab.h>
22304 +#include <linux/rcupdate.h>
22305 +
22306 +#include <linux/vs_network.h>
22307 +#include <linux/vs_pid.h>
22308 +#include <linux/vserver/network_cmd.h>
22309 +
22310 +
22311 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
22312 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
22313 +
22314 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
22315 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
22316 +
22317 +
22318 +static int __init init_network(void)
22319 +{
22320 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
22321 +               sizeof(struct nx_addr_v4), 0,
22322 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
22323 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
22324 +               sizeof(struct nx_addr_v6), 0,
22325 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
22326 +       return 0;
22327 +}
22328 +
22329 +
22330 +/*     __alloc_nx_addr_v4()                                    */
22331 +
22332 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
22333 +{
22334 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
22335 +               nx_addr_v4_cachep, GFP_KERNEL);
22336 +
22337 +       if (!IS_ERR(nxa))
22338 +               memset(nxa, 0, sizeof(*nxa));
22339 +       return nxa;
22340 +}
22341 +
22342 +/*     __dealloc_nx_addr_v4()                                  */
22343 +
22344 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
22345 +{
22346 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
22347 +}
22348 +
22349 +/*     __dealloc_nx_addr_v4_all()                              */
22350 +
22351 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
22352 +{
22353 +       while (nxa) {
22354 +               struct nx_addr_v4 *next = nxa->next;
22355 +
22356 +               __dealloc_nx_addr_v4(nxa);
22357 +               nxa = next;
22358 +       }
22359 +}
22360 +
22361 +
22362 +#ifdef CONFIG_IPV6
22363 +
22364 +/*     __alloc_nx_addr_v6()                                    */
22365 +
22366 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
22367 +{
22368 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
22369 +               nx_addr_v6_cachep, GFP_KERNEL);
22370 +
22371 +       if (!IS_ERR(nxa))
22372 +               memset(nxa, 0, sizeof(*nxa));
22373 +       return nxa;
22374 +}
22375 +
22376 +/*     __dealloc_nx_addr_v6()                                  */
22377 +
22378 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
22379 +{
22380 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
22381 +}
22382 +
22383 +/*     __dealloc_nx_addr_v6_all()                              */
22384 +
22385 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
22386 +{
22387 +       while (nxa) {
22388 +               struct nx_addr_v6 *next = nxa->next;
22389 +
22390 +               __dealloc_nx_addr_v6(nxa);
22391 +               nxa = next;
22392 +       }
22393 +}
22394 +
22395 +#endif /* CONFIG_IPV6 */
22396 +
22397 +/*     __alloc_nx_info()
22398 +
22399 +       * allocate an initialized nx_info struct
22400 +       * doesn't make it visible (hash)                        */
22401 +
22402 +static struct nx_info *__alloc_nx_info(nid_t nid)
22403 +{
22404 +       struct nx_info *new = NULL;
22405 +
22406 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
22407 +
22408 +       /* would this benefit from a slab cache? */
22409 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
22410 +       if (!new)
22411 +               return 0;
22412 +
22413 +       memset(new, 0, sizeof(struct nx_info));
22414 +       new->nx_id = nid;
22415 +       INIT_HLIST_NODE(&new->nx_hlist);
22416 +       atomic_set(&new->nx_usecnt, 0);
22417 +       atomic_set(&new->nx_tasks, 0);
22418 +       new->nx_state = 0;
22419 +
22420 +       new->nx_flags = NXF_INIT_SET;
22421 +
22422 +       /* rest of init goes here */
22423 +
22424 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
22425 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
22426 +
22427 +       vxdprintk(VXD_CBIT(nid, 0),
22428 +               "alloc_nx_info(%d) = %p", nid, new);
22429 +       atomic_inc(&nx_global_ctotal);
22430 +       return new;
22431 +}
22432 +
22433 +/*     __dealloc_nx_info()
22434 +
22435 +       * final disposal of nx_info                             */
22436 +
22437 +static void __dealloc_nx_info(struct nx_info *nxi)
22438 +{
22439 +       vxdprintk(VXD_CBIT(nid, 0),
22440 +               "dealloc_nx_info(%p)", nxi);
22441 +
22442 +       nxi->nx_hlist.next = LIST_POISON1;
22443 +       nxi->nx_id = -1;
22444 +
22445 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
22446 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22447 +
22448 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
22449 +
22450 +       nxi->nx_state |= NXS_RELEASED;
22451 +       kfree(nxi);
22452 +       atomic_dec(&nx_global_ctotal);
22453 +}
22454 +
22455 +static void __shutdown_nx_info(struct nx_info *nxi)
22456 +{
22457 +       nxi->nx_state |= NXS_SHUTDOWN;
22458 +       vs_net_change(nxi, VSC_NETDOWN);
22459 +}
22460 +
22461 +/*     exported stuff                                          */
22462 +
22463 +void free_nx_info(struct nx_info *nxi)
22464 +{
22465 +       /* context shutdown is mandatory */
22466 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
22467 +
22468 +       /* context must not be hashed */
22469 +       BUG_ON(nxi->nx_state & NXS_HASHED);
22470 +
22471 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
22472 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22473 +
22474 +       __dealloc_nx_info(nxi);
22475 +}
22476 +
22477 +
22478 +void __nx_set_lback(struct nx_info *nxi)
22479 +{
22480 +       int nid = nxi->nx_id;
22481 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
22482 +
22483 +       nxi->v4_lback.s_addr = lback;
22484 +}
22485 +
22486 +extern int __nx_inet_add_lback(__be32 addr);
22487 +extern int __nx_inet_del_lback(__be32 addr);
22488 +
22489 +
22490 +/*     hash table for nx_info hash */
22491 +
22492 +#define NX_HASH_SIZE   13
22493 +
22494 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
22495 +
22496 +static spinlock_t nx_info_hash_lock = SPIN_LOCK_UNLOCKED;
22497 +
22498 +
22499 +static inline unsigned int __hashval(nid_t nid)
22500 +{
22501 +       return (nid % NX_HASH_SIZE);
22502 +}
22503 +
22504 +
22505 +
22506 +/*     __hash_nx_info()
22507 +
22508 +       * add the nxi to the global hash table
22509 +       * requires the hash_lock to be held                     */
22510 +
22511 +static inline void __hash_nx_info(struct nx_info *nxi)
22512 +{
22513 +       struct hlist_head *head;
22514 +
22515 +       vxd_assert_lock(&nx_info_hash_lock);
22516 +       vxdprintk(VXD_CBIT(nid, 4),
22517 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
22518 +
22519 +       /* context must not be hashed */
22520 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
22521 +
22522 +       nxi->nx_state |= NXS_HASHED;
22523 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
22524 +       hlist_add_head(&nxi->nx_hlist, head);
22525 +       atomic_inc(&nx_global_cactive);
22526 +}
22527 +
22528 +/*     __unhash_nx_info()
22529 +
22530 +       * remove the nxi from the global hash table
22531 +       * requires the hash_lock to be held                     */
22532 +
22533 +static inline void __unhash_nx_info(struct nx_info *nxi)
22534 +{
22535 +       vxd_assert_lock(&nx_info_hash_lock);
22536 +       vxdprintk(VXD_CBIT(nid, 4),
22537 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
22538 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
22539 +
22540 +       /* context must be hashed */
22541 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
22542 +       /* but without tasks */
22543 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22544 +
22545 +       nxi->nx_state &= ~NXS_HASHED;
22546 +       hlist_del(&nxi->nx_hlist);
22547 +       atomic_dec(&nx_global_cactive);
22548 +}
22549 +
22550 +
22551 +/*     __lookup_nx_info()
22552 +
22553 +       * requires the hash_lock to be held
22554 +       * doesn't increment the nx_refcnt                       */
22555 +
22556 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
22557 +{
22558 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
22559 +       struct hlist_node *pos;
22560 +       struct nx_info *nxi;
22561 +
22562 +       vxd_assert_lock(&nx_info_hash_lock);
22563 +       hlist_for_each(pos, head) {
22564 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
22565 +
22566 +               if (nxi->nx_id == nid)
22567 +                       goto found;
22568 +       }
22569 +       nxi = NULL;
22570 +found:
22571 +       vxdprintk(VXD_CBIT(nid, 0),
22572 +               "__lookup_nx_info(#%u): %p[#%u]",
22573 +               nid, nxi, nxi ? nxi->nx_id : 0);
22574 +       return nxi;
22575 +}
22576 +
22577 +
22578 +/*     __create_nx_info()
22579 +
22580 +       * create the requested context
22581 +       * get(), claim() and hash it                            */
22582 +
22583 +static struct nx_info *__create_nx_info(int id)
22584 +{
22585 +       struct nx_info *new, *nxi = NULL;
22586 +
22587 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
22588 +
22589 +       if (!(new = __alloc_nx_info(id)))
22590 +               return ERR_PTR(-ENOMEM);
22591 +
22592 +       /* required to make dynamic xids unique */
22593 +       spin_lock(&nx_info_hash_lock);
22594 +
22595 +       /* static context requested */
22596 +       if ((nxi = __lookup_nx_info(id))) {
22597 +               vxdprintk(VXD_CBIT(nid, 0),
22598 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
22599 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22600 +                       nxi = ERR_PTR(-EBUSY);
22601 +               else
22602 +                       nxi = ERR_PTR(-EEXIST);
22603 +               goto out_unlock;
22604 +       }
22605 +       /* new context */
22606 +       vxdprintk(VXD_CBIT(nid, 0),
22607 +               "create_nx_info(%d) = %p (new)", id, new);
22608 +       claim_nx_info(new, NULL);
22609 +       __nx_set_lback(new);
22610 +       __hash_nx_info(get_nx_info(new));
22611 +       nxi = new, new = NULL;
22612 +
22613 +out_unlock:
22614 +       spin_unlock(&nx_info_hash_lock);
22615 +       if (new)
22616 +               __dealloc_nx_info(new);
22617 +       return nxi;
22618 +}
22619 +
22620 +
22621 +
22622 +/*     exported stuff                                          */
22623 +
22624 +
22625 +void unhash_nx_info(struct nx_info *nxi)
22626 +{
22627 +       __shutdown_nx_info(nxi);
22628 +       spin_lock(&nx_info_hash_lock);
22629 +       __unhash_nx_info(nxi);
22630 +       spin_unlock(&nx_info_hash_lock);
22631 +}
22632 +
22633 +/*     lookup_nx_info()
22634 +
22635 +       * search for a nx_info and get() it
22636 +       * negative id means current                             */
22637 +
22638 +struct nx_info *lookup_nx_info(int id)
22639 +{
22640 +       struct nx_info *nxi = NULL;
22641 +
22642 +       if (id < 0) {
22643 +               nxi = get_nx_info(current_nx_info());
22644 +       } else if (id > 1) {
22645 +               spin_lock(&nx_info_hash_lock);
22646 +               nxi = get_nx_info(__lookup_nx_info(id));
22647 +               spin_unlock(&nx_info_hash_lock);
22648 +       }
22649 +       return nxi;
22650 +}
22651 +
22652 +/*     nid_is_hashed()
22653 +
22654 +       * verify that nid is still hashed                       */
22655 +
22656 +int nid_is_hashed(nid_t nid)
22657 +{
22658 +       int hashed;
22659 +
22660 +       spin_lock(&nx_info_hash_lock);
22661 +       hashed = (__lookup_nx_info(nid) != NULL);
22662 +       spin_unlock(&nx_info_hash_lock);
22663 +       return hashed;
22664 +}
22665 +
22666 +
22667 +#ifdef CONFIG_PROC_FS
22668 +
22669 +/*     get_nid_list()
22670 +
22671 +       * get a subset of hashed nids for proc
22672 +       * assumes size is at least one                          */
22673 +
22674 +int get_nid_list(int index, unsigned int *nids, int size)
22675 +{
22676 +       int hindex, nr_nids = 0;
22677 +
22678 +       /* only show current and children */
22679 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
22680 +               if (index > 0)
22681 +                       return 0;
22682 +               nids[nr_nids] = nx_current_nid();
22683 +               return 1;
22684 +       }
22685 +
22686 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
22687 +               struct hlist_head *head = &nx_info_hash[hindex];
22688 +               struct hlist_node *pos;
22689 +
22690 +               spin_lock(&nx_info_hash_lock);
22691 +               hlist_for_each(pos, head) {
22692 +                       struct nx_info *nxi;
22693 +
22694 +                       if (--index > 0)
22695 +                               continue;
22696 +
22697 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
22698 +                       nids[nr_nids] = nxi->nx_id;
22699 +                       if (++nr_nids >= size) {
22700 +                               spin_unlock(&nx_info_hash_lock);
22701 +                               goto out;
22702 +                       }
22703 +               }
22704 +               /* keep the lock time short */
22705 +               spin_unlock(&nx_info_hash_lock);
22706 +       }
22707 +out:
22708 +       return nr_nids;
22709 +}
22710 +#endif
22711 +
22712 +
22713 +/*
22714 + *     migrate task to new network
22715 + *     gets nxi, puts old_nxi on change
22716 + */
22717 +
22718 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
22719 +{
22720 +       struct nx_info *old_nxi;
22721 +       int ret = 0;
22722 +
22723 +       if (!p || !nxi)
22724 +               BUG();
22725 +
22726 +       vxdprintk(VXD_CBIT(nid, 5),
22727 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
22728 +               p, nxi, nxi->nx_id,
22729 +               atomic_read(&nxi->nx_usecnt),
22730 +               atomic_read(&nxi->nx_tasks));
22731 +
22732 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
22733 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22734 +               return -EACCES;
22735 +
22736 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
22737 +               return -EFAULT;
22738 +
22739 +       /* maybe disallow this completely? */
22740 +       old_nxi = task_get_nx_info(p);
22741 +       if (old_nxi == nxi)
22742 +               goto out;
22743 +
22744 +       task_lock(p);
22745 +       if (old_nxi)
22746 +               clr_nx_info(&p->nx_info);
22747 +       claim_nx_info(nxi, p);
22748 +       set_nx_info(&p->nx_info, nxi);
22749 +       p->nid = nxi->nx_id;
22750 +       task_unlock(p);
22751 +
22752 +       vxdprintk(VXD_CBIT(nid, 5),
22753 +               "moved task %p into nxi:%p[#%d]",
22754 +               p, nxi, nxi->nx_id);
22755 +
22756 +       if (old_nxi)
22757 +               release_nx_info(old_nxi, p);
22758 +       ret = 0;
22759 +out:
22760 +       put_nx_info(old_nxi);
22761 +       return ret;
22762 +}
22763 +
22764 +
22765 +void nx_set_persistent(struct nx_info *nxi)
22766 +{
22767 +       vxdprintk(VXD_CBIT(nid, 6),
22768 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
22769 +
22770 +       get_nx_info(nxi);
22771 +       claim_nx_info(nxi, NULL);
22772 +}
22773 +
22774 +void nx_clear_persistent(struct nx_info *nxi)
22775 +{
22776 +       vxdprintk(VXD_CBIT(nid, 6),
22777 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
22778 +
22779 +       release_nx_info(nxi, NULL);
22780 +       put_nx_info(nxi);
22781 +}
22782 +
22783 +void nx_update_persistent(struct nx_info *nxi)
22784 +{
22785 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
22786 +               nx_set_persistent(nxi);
22787 +       else
22788 +               nx_clear_persistent(nxi);
22789 +}
22790 +
22791 +/* vserver syscall commands below here */
22792 +
22793 +/* taks nid and nx_info functions */
22794 +
22795 +#include <asm/uaccess.h>
22796 +
22797 +
22798 +int vc_task_nid(uint32_t id)
22799 +{
22800 +       nid_t nid;
22801 +
22802 +       if (id) {
22803 +               struct task_struct *tsk;
22804 +
22805 +               read_lock(&tasklist_lock);
22806 +               tsk = find_task_by_real_pid(id);
22807 +               nid = (tsk) ? tsk->nid : -ESRCH;
22808 +               read_unlock(&tasklist_lock);
22809 +       } else
22810 +               nid = nx_current_nid();
22811 +       return nid;
22812 +}
22813 +
22814 +
22815 +int vc_nx_info(struct nx_info *nxi, void __user *data)
22816 +{
22817 +       struct vcmd_nx_info_v0 vc_data;
22818 +
22819 +       vc_data.nid = nxi->nx_id;
22820 +
22821 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22822 +               return -EFAULT;
22823 +       return 0;
22824 +}
22825 +
22826 +
22827 +/* network functions */
22828 +
22829 +int vc_net_create(uint32_t nid, void __user *data)
22830 +{
22831 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
22832 +       struct nx_info *new_nxi;
22833 +       int ret;
22834 +
22835 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22836 +               return -EFAULT;
22837 +
22838 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
22839 +               return -EINVAL;
22840 +
22841 +       new_nxi = __create_nx_info(nid);
22842 +       if (IS_ERR(new_nxi))
22843 +               return PTR_ERR(new_nxi);
22844 +
22845 +       /* initial flags */
22846 +       new_nxi->nx_flags = vc_data.flagword;
22847 +
22848 +       ret = -ENOEXEC;
22849 +       if (vs_net_change(new_nxi, VSC_NETUP))
22850 +               goto out;
22851 +
22852 +       ret = nx_migrate_task(current, new_nxi);
22853 +       if (ret)
22854 +               goto out;
22855 +
22856 +       /* return context id on success */
22857 +       ret = new_nxi->nx_id;
22858 +
22859 +       /* get a reference for persistent contexts */
22860 +       if ((vc_data.flagword & NXF_PERSISTENT))
22861 +               nx_set_persistent(new_nxi);
22862 +out:
22863 +       release_nx_info(new_nxi, NULL);
22864 +       put_nx_info(new_nxi);
22865 +       return ret;
22866 +}
22867 +
22868 +
22869 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
22870 +{
22871 +       return nx_migrate_task(current, nxi);
22872 +}
22873 +
22874 +
22875 +
22876 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
22877 +       uint16_t type, uint16_t flags)
22878 +{
22879 +       struct nx_addr_v4 *nxa = &nxi->v4;
22880 +
22881 +       if (NX_IPV4(nxi)) {
22882 +               /* locate last entry */
22883 +               for (; nxa->next; nxa = nxa->next);
22884 +               nxa->next = __alloc_nx_addr_v4();
22885 +               nxa = nxa->next;
22886 +
22887 +               if (IS_ERR(nxa))
22888 +                       return PTR_ERR(nxa);
22889 +       }
22890 +
22891 +       if (nxi->v4.next)
22892 +               /* remove single ip for ip list */
22893 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
22894 +
22895 +       nxa->ip[0].s_addr = ip;
22896 +       nxa->ip[1].s_addr = ip2;
22897 +       nxa->mask.s_addr = mask;
22898 +       nxa->type = type;
22899 +       nxa->flags = flags;
22900 +       return 0;
22901 +}
22902 +
22903 +
22904 +int vc_net_add(struct nx_info *nxi, void __user *data)
22905 +{
22906 +       struct vcmd_net_addr_v0 vc_data;
22907 +       int index, ret = 0;
22908 +
22909 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22910 +               return -EFAULT;
22911 +
22912 +       switch (vc_data.type) {
22913 +       case NXA_TYPE_IPV4:
22914 +               if ((vc_data.count < 1) || (vc_data.count > 4))
22915 +                       return -EINVAL;
22916 +
22917 +               index = 0;
22918 +               while (index < vc_data.count) {
22919 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
22920 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
22921 +                       if (ret)
22922 +                               return ret;
22923 +                       index++;
22924 +               }
22925 +               ret = index;
22926 +               break;
22927 +
22928 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
22929 +               nxi->v4_bcast = vc_data.ip[0];
22930 +               ret = 1;
22931 +               break;
22932 +
22933 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
22934 +               nxi->v4_lback = vc_data.ip[0];
22935 +               ret = 1;
22936 +               break;
22937 +
22938 +       default:
22939 +               ret = -EINVAL;
22940 +               break;
22941 +       }
22942 +       return ret;
22943 +}
22944 +
22945 +int vc_net_remove(struct nx_info *nxi, void __user *data)
22946 +{
22947 +       struct vcmd_net_addr_v0 vc_data;
22948 +
22949 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22950 +               return -EFAULT;
22951 +
22952 +       switch (vc_data.type) {
22953 +       case NXA_TYPE_ANY:
22954 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
22955 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
22956 +               break;
22957 +
22958 +       default:
22959 +               return -EINVAL;
22960 +       }
22961 +       return 0;
22962 +}
22963 +
22964 +
22965 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
22966 +{
22967 +       struct vcmd_net_addr_ipv4_v1 vc_data;
22968 +
22969 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22970 +               return -EFAULT;
22971 +
22972 +       switch (vc_data.type) {
22973 +       case NXA_TYPE_ADDR:
22974 +       case NXA_TYPE_RANGE:
22975 +       case NXA_TYPE_MASK:
22976 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
22977 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
22978 +
22979 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
22980 +               nxi->v4_bcast = vc_data.ip;
22981 +               break;
22982 +
22983 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
22984 +               nxi->v4_lback = vc_data.ip;
22985 +               break;
22986 +
22987 +       default:
22988 +               return -EINVAL;
22989 +       }
22990 +       return 0;
22991 +}
22992 +
22993 +int vc_net_remove_ipv4(struct nx_info *nxi, void __user *data)
22994 +{
22995 +       struct vcmd_net_addr_ipv4_v1 vc_data;
22996 +
22997 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22998 +               return -EFAULT;
22999 +
23000 +       switch (vc_data.type) {
23001 +/*     case NXA_TYPE_ADDR:
23002 +               break;          */
23003 +
23004 +       case NXA_TYPE_ANY:
23005 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
23006 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
23007 +               break;
23008 +
23009 +       default:
23010 +               return -EINVAL;
23011 +       }
23012 +       return 0;
23013 +}
23014 +
23015 +
23016 +#ifdef CONFIG_IPV6
23017 +
23018 +int do_add_v6_addr(struct nx_info *nxi,
23019 +       struct in6_addr *ip, struct in6_addr *mask,
23020 +       uint32_t prefix, uint16_t type, uint16_t flags)
23021 +{
23022 +       struct nx_addr_v6 *nxa = &nxi->v6;
23023 +
23024 +       if (NX_IPV6(nxi)) {
23025 +               /* locate last entry */
23026 +               for (; nxa->next; nxa = nxa->next);
23027 +               nxa->next = __alloc_nx_addr_v6();
23028 +               nxa = nxa->next;
23029 +
23030 +               if (IS_ERR(nxa))
23031 +                       return PTR_ERR(nxa);
23032 +       }
23033 +
23034 +       nxa->ip = *ip;
23035 +       nxa->mask = *mask;
23036 +       nxa->prefix = prefix;
23037 +       nxa->type = type;
23038 +       nxa->flags = flags;
23039 +       return 0;
23040 +}
23041 +
23042 +
23043 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
23044 +{
23045 +       struct vcmd_net_addr_ipv6_v1 vc_data;
23046 +
23047 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23048 +               return -EFAULT;
23049 +
23050 +       switch (vc_data.type) {
23051 +       case NXA_TYPE_ADDR:
23052 +       case NXA_TYPE_MASK:
23053 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
23054 +                       vc_data.prefix, vc_data.type, vc_data.flags);
23055 +       default:
23056 +               return -EINVAL;
23057 +       }
23058 +       return 0;
23059 +}
23060 +
23061 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
23062 +{
23063 +       struct vcmd_net_addr_ipv6_v1 vc_data;
23064 +
23065 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23066 +               return -EFAULT;
23067 +
23068 +       switch (vc_data.type) {
23069 +       case NXA_TYPE_ANY:
23070 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
23071 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
23072 +               break;
23073 +
23074 +       default:
23075 +               return -EINVAL;
23076 +       }
23077 +       return 0;
23078 +}
23079 +
23080 +#endif /* CONFIG_IPV6 */
23081 +
23082 +
23083 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
23084 +{
23085 +       struct vcmd_net_flags_v0 vc_data;
23086 +
23087 +       vc_data.flagword = nxi->nx_flags;
23088 +
23089 +       /* special STATE flag handling */
23090 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
23091 +
23092 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23093 +               return -EFAULT;
23094 +       return 0;
23095 +}
23096 +
23097 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
23098 +{
23099 +       struct vcmd_net_flags_v0 vc_data;
23100 +       uint64_t mask, trigger;
23101 +
23102 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23103 +               return -EFAULT;
23104 +
23105 +       /* special STATE flag handling */
23106 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
23107 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
23108 +
23109 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
23110 +               vc_data.flagword, mask);
23111 +       if (trigger & NXF_PERSISTENT)
23112 +               nx_update_persistent(nxi);
23113 +
23114 +       return 0;
23115 +}
23116 +
23117 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
23118 +{
23119 +       struct vcmd_net_caps_v0 vc_data;
23120 +
23121 +       vc_data.ncaps = nxi->nx_ncaps;
23122 +       vc_data.cmask = ~0ULL;
23123 +
23124 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23125 +               return -EFAULT;
23126 +       return 0;
23127 +}
23128 +
23129 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
23130 +{
23131 +       struct vcmd_net_caps_v0 vc_data;
23132 +
23133 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23134 +               return -EFAULT;
23135 +
23136 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
23137 +               vc_data.ncaps, vc_data.cmask);
23138 +       return 0;
23139 +}
23140 +
23141 +
23142 +#include <linux/module.h>
23143 +
23144 +module_init(init_network);
23145 +
23146 +EXPORT_SYMBOL_GPL(free_nx_info);
23147 +EXPORT_SYMBOL_GPL(unhash_nx_info);
23148 +
23149 diff -NurpP --minimal linux-2.6.32.56/kernel/vserver/proc.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/proc.c
23150 --- linux-2.6.32.56/kernel/vserver/proc.c       1970-01-01 01:00:00.000000000 +0100
23151 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/proc.c       2011-06-10 13:03:02.000000000 +0200
23152 @@ -0,0 +1,1098 @@
23153 +/*
23154 + *  linux/kernel/vserver/proc.c
23155 + *
23156 + *  Virtual Context Support
23157 + *
23158 + *  Copyright (C) 2003-2007  Herbert Pötzl
23159 + *
23160 + *  V0.01  basic structure
23161 + *  V0.02  adaptation vs1.3.0
23162 + *  V0.03  proc permissions
23163 + *  V0.04  locking/generic
23164 + *  V0.05  next generation procfs
23165 + *  V0.06  inode validation
23166 + *  V0.07  generic rewrite vid
23167 + *  V0.08  remove inode type
23168 + *
23169 + */
23170 +
23171 +#include <linux/proc_fs.h>
23172 +#include <linux/fs_struct.h>
23173 +#include <linux/mount.h>
23174 +#include <asm/unistd.h>
23175 +
23176 +#include <linux/vs_context.h>
23177 +#include <linux/vs_network.h>
23178 +#include <linux/vs_cvirt.h>
23179 +
23180 +#include <linux/in.h>
23181 +#include <linux/inetdevice.h>
23182 +#include <linux/vs_inet.h>
23183 +#include <linux/vs_inet6.h>
23184 +
23185 +#include <linux/vserver/global.h>
23186 +
23187 +#include "cvirt_proc.h"
23188 +#include "cacct_proc.h"
23189 +#include "limit_proc.h"
23190 +#include "sched_proc.h"
23191 +#include "vci_config.h"
23192 +
23193 +
23194 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
23195 +{
23196 +       unsigned __capi;
23197 +
23198 +       CAP_FOR_EACH_U32(__capi) {
23199 +               buffer += sprintf(buffer, "%08x",
23200 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
23201 +       }
23202 +       return buffer;
23203 +}
23204 +
23205 +
23206 +static struct proc_dir_entry *proc_virtual;
23207 +
23208 +static struct proc_dir_entry *proc_virtnet;
23209 +
23210 +
23211 +/* first the actual feeds */
23212 +
23213 +
23214 +static int proc_vci(char *buffer)
23215 +{
23216 +       return sprintf(buffer,
23217 +               "VCIVersion:\t%04x:%04x\n"
23218 +               "VCISyscall:\t%d\n"
23219 +               "VCIKernel:\t%08x\n",
23220 +               VCI_VERSION >> 16,
23221 +               VCI_VERSION & 0xFFFF,
23222 +               __NR_vserver,
23223 +               vci_kernel_config());
23224 +}
23225 +
23226 +static int proc_virtual_info(char *buffer)
23227 +{
23228 +       return proc_vci(buffer);
23229 +}
23230 +
23231 +static int proc_virtual_status(char *buffer)
23232 +{
23233 +       return sprintf(buffer,
23234 +               "#CTotal:\t%d\n"
23235 +               "#CActive:\t%d\n"
23236 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
23237 +               "#InitTask:\t%d\t%d %d\n",
23238 +               atomic_read(&vx_global_ctotal),
23239 +               atomic_read(&vx_global_cactive),
23240 +               atomic_read(&vs_global_nsproxy),
23241 +               atomic_read(&vs_global_fs),
23242 +               atomic_read(&vs_global_mnt_ns),
23243 +               atomic_read(&vs_global_uts_ns),
23244 +               atomic_read(&nr_ipc_ns),
23245 +               atomic_read(&vs_global_user_ns),
23246 +               atomic_read(&vs_global_pid_ns),
23247 +               atomic_read(&init_task.usage),
23248 +               atomic_read(&init_task.nsproxy->count),
23249 +               init_task.fs->users);
23250 +}
23251 +
23252 +
23253 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
23254 +{
23255 +       int length;
23256 +
23257 +       length = sprintf(buffer,
23258 +               "ID:\t%d\n"
23259 +               "Info:\t%p\n"
23260 +               "Init:\t%d\n"
23261 +               "OOM:\t%lld\n",
23262 +               vxi->vx_id,
23263 +               vxi,
23264 +               vxi->vx_initpid,
23265 +               vxi->vx_badness_bias);
23266 +       return length;
23267 +}
23268 +
23269 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
23270 +{
23271 +       char *orig = buffer;
23272 +
23273 +       buffer += sprintf(buffer,
23274 +               "UseCnt:\t%d\n"
23275 +               "Tasks:\t%d\n"
23276 +               "Flags:\t%016llx\n",
23277 +               atomic_read(&vxi->vx_usecnt),
23278 +               atomic_read(&vxi->vx_tasks),
23279 +               (unsigned long long)vxi->vx_flags);
23280 +
23281 +       buffer += sprintf(buffer, "BCaps:\t");
23282 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
23283 +       buffer += sprintf(buffer, "\n");
23284 +
23285 +       buffer += sprintf(buffer,
23286 +               "CCaps:\t%016llx\n"
23287 +               "Spaces:\t%08lx %08lx\n",
23288 +               (unsigned long long)vxi->vx_ccaps,
23289 +               vxi->vx_nsmask[0], vxi->vx_nsmask[1]);
23290 +       return buffer - orig;
23291 +}
23292 +
23293 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
23294 +{
23295 +       return vx_info_proc_limit(&vxi->limit, buffer);
23296 +}
23297 +
23298 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
23299 +{
23300 +       int cpu, length;
23301 +
23302 +       length = vx_info_proc_sched(&vxi->sched, buffer);
23303 +       for_each_online_cpu(cpu) {
23304 +               length += vx_info_proc_sched_pc(
23305 +                       &vx_per_cpu(vxi, sched_pc, cpu),
23306 +                       buffer + length, cpu);
23307 +       }
23308 +       return length;
23309 +}
23310 +
23311 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
23312 +{
23313 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[0], buffer);
23314 +}
23315 +
23316 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
23317 +{
23318 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[1], buffer);
23319 +}
23320 +
23321 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
23322 +{
23323 +       int cpu, length;
23324 +
23325 +       vx_update_load(vxi);
23326 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
23327 +       for_each_online_cpu(cpu) {
23328 +               length += vx_info_proc_cvirt_pc(
23329 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
23330 +                       buffer + length, cpu);
23331 +       }
23332 +       return length;
23333 +}
23334 +
23335 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
23336 +{
23337 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
23338 +}
23339 +
23340 +
23341 +static int proc_virtnet_info(char *buffer)
23342 +{
23343 +       return proc_vci(buffer);
23344 +}
23345 +
23346 +static int proc_virtnet_status(char *buffer)
23347 +{
23348 +       return sprintf(buffer,
23349 +               "#CTotal:\t%d\n"
23350 +               "#CActive:\t%d\n",
23351 +               atomic_read(&nx_global_ctotal),
23352 +               atomic_read(&nx_global_cactive));
23353 +}
23354 +
23355 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
23356 +{
23357 +       struct nx_addr_v4 *v4a;
23358 +#ifdef CONFIG_IPV6
23359 +       struct nx_addr_v6 *v6a;
23360 +#endif
23361 +       int length, i;
23362 +
23363 +       length = sprintf(buffer,
23364 +               "ID:\t%d\n"
23365 +               "Info:\t%p\n"
23366 +               "Bcast:\t" NIPQUAD_FMT "\n"
23367 +               "Lback:\t" NIPQUAD_FMT "\n",
23368 +               nxi->nx_id,
23369 +               nxi,
23370 +               NIPQUAD(nxi->v4_bcast.s_addr),
23371 +               NIPQUAD(nxi->v4_lback.s_addr));
23372 +
23373 +       if (!NX_IPV4(nxi))
23374 +               goto skip_v4;
23375 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
23376 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
23377 +                       i, NXAV4(v4a));
23378 +skip_v4:
23379 +#ifdef CONFIG_IPV6
23380 +       if (!NX_IPV6(nxi))
23381 +               goto skip_v6;
23382 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
23383 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
23384 +                       i, NXAV6(v6a));
23385 +skip_v6:
23386 +#endif
23387 +       return length;
23388 +}
23389 +
23390 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
23391 +{
23392 +       int length;
23393 +
23394 +       length = sprintf(buffer,
23395 +               "UseCnt:\t%d\n"
23396 +               "Tasks:\t%d\n"
23397 +               "Flags:\t%016llx\n"
23398 +               "NCaps:\t%016llx\n",
23399 +               atomic_read(&nxi->nx_usecnt),
23400 +               atomic_read(&nxi->nx_tasks),
23401 +               (unsigned long long)nxi->nx_flags,
23402 +               (unsigned long long)nxi->nx_ncaps);
23403 +       return length;
23404 +}
23405 +
23406 +
23407 +
23408 +/* here the inode helpers */
23409 +
23410 +struct vs_entry {
23411 +       int len;
23412 +       char *name;
23413 +       mode_t mode;
23414 +       struct inode_operations *iop;
23415 +       struct file_operations *fop;
23416 +       union proc_op op;
23417 +};
23418 +
23419 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
23420 +{
23421 +       struct inode *inode = new_inode(sb);
23422 +
23423 +       if (!inode)
23424 +               goto out;
23425 +
23426 +       inode->i_mode = p->mode;
23427 +       if (p->iop)
23428 +               inode->i_op = p->iop;
23429 +       if (p->fop)
23430 +               inode->i_fop = p->fop;
23431 +
23432 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
23433 +       inode->i_flags |= S_IMMUTABLE;
23434 +
23435 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
23436 +
23437 +       inode->i_uid = 0;
23438 +       inode->i_gid = 0;
23439 +       inode->i_tag = 0;
23440 +out:
23441 +       return inode;
23442 +}
23443 +
23444 +static struct dentry *vs_proc_instantiate(struct inode *dir,
23445 +       struct dentry *dentry, int id, void *ptr)
23446 +{
23447 +       struct vs_entry *p = ptr;
23448 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
23449 +       struct dentry *error = ERR_PTR(-EINVAL);
23450 +
23451 +       if (!inode)
23452 +               goto out;
23453 +
23454 +       PROC_I(inode)->op = p->op;
23455 +       PROC_I(inode)->fd = id;
23456 +       d_add(dentry, inode);
23457 +       error = NULL;
23458 +out:
23459 +       return error;
23460 +}
23461 +
23462 +/* Lookups */
23463 +
23464 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
23465 +
23466 +/*
23467 + * Fill a directory entry.
23468 + *
23469 + * If possible create the dcache entry and derive our inode number and
23470 + * file type from dcache entry.
23471 + *
23472 + * Since all of the proc inode numbers are dynamically generated, the inode
23473 + * numbers do not exist until the inode is cache.  This means creating the
23474 + * the dcache entry in readdir is necessary to keep the inode numbers
23475 + * reported by readdir in sync with the inode numbers reported
23476 + * by stat.
23477 + */
23478 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
23479 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
23480 +{
23481 +       struct dentry *child, *dir = filp->f_dentry;
23482 +       struct inode *inode;
23483 +       struct qstr qname;
23484 +       ino_t ino = 0;
23485 +       unsigned type = DT_UNKNOWN;
23486 +
23487 +       qname.name = name;
23488 +       qname.len  = len;
23489 +       qname.hash = full_name_hash(name, len);
23490 +
23491 +       child = d_lookup(dir, &qname);
23492 +       if (!child) {
23493 +               struct dentry *new;
23494 +               new = d_alloc(dir, &qname);
23495 +               if (new) {
23496 +                       child = instantiate(dir->d_inode, new, id, ptr);
23497 +                       if (child)
23498 +                               dput(new);
23499 +                       else
23500 +                               child = new;
23501 +               }
23502 +       }
23503 +       if (!child || IS_ERR(child) || !child->d_inode)
23504 +               goto end_instantiate;
23505 +       inode = child->d_inode;
23506 +       if (inode) {
23507 +               ino = inode->i_ino;
23508 +               type = inode->i_mode >> 12;
23509 +       }
23510 +       dput(child);
23511 +end_instantiate:
23512 +       if (!ino)
23513 +               ino = find_inode_number(dir, &qname);
23514 +       if (!ino)
23515 +               ino = 1;
23516 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
23517 +}
23518 +
23519 +
23520 +
23521 +/* get and revalidate vx_info/xid */
23522 +
23523 +static inline
23524 +struct vx_info *get_proc_vx_info(struct inode *inode)
23525 +{
23526 +       return lookup_vx_info(PROC_I(inode)->fd);
23527 +}
23528 +
23529 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
23530 +{
23531 +       struct inode *inode = dentry->d_inode;
23532 +       xid_t xid = PROC_I(inode)->fd;
23533 +
23534 +       if (!xid || xid_is_hashed(xid))
23535 +               return 1;
23536 +       d_drop(dentry);
23537 +       return 0;
23538 +}
23539 +
23540 +
23541 +/* get and revalidate nx_info/nid */
23542 +
23543 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
23544 +{
23545 +       struct inode *inode = dentry->d_inode;
23546 +       nid_t nid = PROC_I(inode)->fd;
23547 +
23548 +       if (!nid || nid_is_hashed(nid))
23549 +               return 1;
23550 +       d_drop(dentry);
23551 +       return 0;
23552 +}
23553 +
23554 +
23555 +
23556 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
23557 +
23558 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
23559 +                         size_t count, loff_t *ppos)
23560 +{
23561 +       struct inode *inode = file->f_dentry->d_inode;
23562 +       unsigned long page;
23563 +       ssize_t length = 0;
23564 +
23565 +       if (count > PROC_BLOCK_SIZE)
23566 +               count = PROC_BLOCK_SIZE;
23567 +
23568 +       /* fade that out as soon as stable */
23569 +       WARN_ON(PROC_I(inode)->fd);
23570 +
23571 +       if (!(page = __get_free_page(GFP_KERNEL)))
23572 +               return -ENOMEM;
23573 +
23574 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
23575 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
23576 +
23577 +       if (length >= 0)
23578 +               length = simple_read_from_buffer(buf, count, ppos,
23579 +                       (char *)page, length);
23580 +
23581 +       free_page(page);
23582 +       return length;
23583 +}
23584 +
23585 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
23586 +                         size_t count, loff_t *ppos)
23587 +{
23588 +       struct inode *inode = file->f_dentry->d_inode;
23589 +       struct vx_info *vxi = NULL;
23590 +       xid_t xid = PROC_I(inode)->fd;
23591 +       unsigned long page;
23592 +       ssize_t length = 0;
23593 +
23594 +       if (count > PROC_BLOCK_SIZE)
23595 +               count = PROC_BLOCK_SIZE;
23596 +
23597 +       /* fade that out as soon as stable */
23598 +       WARN_ON(!xid);
23599 +       vxi = lookup_vx_info(xid);
23600 +       if (!vxi)
23601 +               goto out;
23602 +
23603 +       length = -ENOMEM;
23604 +       if (!(page = __get_free_page(GFP_KERNEL)))
23605 +               goto out_put;
23606 +
23607 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
23608 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
23609 +
23610 +       if (length >= 0)
23611 +               length = simple_read_from_buffer(buf, count, ppos,
23612 +                       (char *)page, length);
23613 +
23614 +       free_page(page);
23615 +out_put:
23616 +       put_vx_info(vxi);
23617 +out:
23618 +       return length;
23619 +}
23620 +
23621 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
23622 +                         size_t count, loff_t *ppos)
23623 +{
23624 +       struct inode *inode = file->f_dentry->d_inode;
23625 +       struct nx_info *nxi = NULL;
23626 +       nid_t nid = PROC_I(inode)->fd;
23627 +       unsigned long page;
23628 +       ssize_t length = 0;
23629 +
23630 +       if (count > PROC_BLOCK_SIZE)
23631 +               count = PROC_BLOCK_SIZE;
23632 +
23633 +       /* fade that out as soon as stable */
23634 +       WARN_ON(!nid);
23635 +       nxi = lookup_nx_info(nid);
23636 +       if (!nxi)
23637 +               goto out;
23638 +
23639 +       length = -ENOMEM;
23640 +       if (!(page = __get_free_page(GFP_KERNEL)))
23641 +               goto out_put;
23642 +
23643 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
23644 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
23645 +
23646 +       if (length >= 0)
23647 +               length = simple_read_from_buffer(buf, count, ppos,
23648 +                       (char *)page, length);
23649 +
23650 +       free_page(page);
23651 +out_put:
23652 +       put_nx_info(nxi);
23653 +out:
23654 +       return length;
23655 +}
23656 +
23657 +
23658 +
23659 +/* here comes the lower level */
23660 +
23661 +
23662 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
23663 +       .len  = sizeof(NAME) - 1,       \
23664 +       .name = (NAME),                 \
23665 +       .mode = MODE,                   \
23666 +       .iop  = IOP,                    \
23667 +       .fop  = FOP,                    \
23668 +       .op   = OP,                     \
23669 +}
23670 +
23671 +
23672 +#define DIR(NAME, MODE, OTYPE)                         \
23673 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
23674 +               &proc_ ## OTYPE ## _inode_operations,   \
23675 +               &proc_ ## OTYPE ## _file_operations, { } )
23676 +
23677 +#define INF(NAME, MODE, OTYPE)                         \
23678 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23679 +               &proc_vs_info_file_operations,          \
23680 +               { .proc_vs_read = &proc_##OTYPE } )
23681 +
23682 +#define VINF(NAME, MODE, OTYPE)                                \
23683 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23684 +               &proc_vx_info_file_operations,          \
23685 +               { .proc_vxi_read = &proc_##OTYPE } )
23686 +
23687 +#define NINF(NAME, MODE, OTYPE)                                \
23688 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23689 +               &proc_nx_info_file_operations,          \
23690 +               { .proc_nxi_read = &proc_##OTYPE } )
23691 +
23692 +
23693 +static struct file_operations proc_vs_info_file_operations = {
23694 +       .read =         proc_vs_info_read,
23695 +};
23696 +
23697 +static struct file_operations proc_vx_info_file_operations = {
23698 +       .read =         proc_vx_info_read,
23699 +};
23700 +
23701 +static struct dentry_operations proc_xid_dentry_operations = {
23702 +       .d_revalidate = proc_xid_revalidate,
23703 +};
23704 +
23705 +static struct vs_entry vx_base_stuff[] = {
23706 +       VINF("info",    S_IRUGO, vxi_info),
23707 +       VINF("status",  S_IRUGO, vxi_status),
23708 +       VINF("limit",   S_IRUGO, vxi_limit),
23709 +       VINF("sched",   S_IRUGO, vxi_sched),
23710 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
23711 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
23712 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
23713 +       VINF("cacct",   S_IRUGO, vxi_cacct),
23714 +       {}
23715 +};
23716 +
23717 +
23718 +
23719 +
23720 +static struct dentry *proc_xid_instantiate(struct inode *dir,
23721 +       struct dentry *dentry, int id, void *ptr)
23722 +{
23723 +       dentry->d_op = &proc_xid_dentry_operations;
23724 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23725 +}
23726 +
23727 +static struct dentry *proc_xid_lookup(struct inode *dir,
23728 +       struct dentry *dentry, struct nameidata *nd)
23729 +{
23730 +       struct vs_entry *p = vx_base_stuff;
23731 +       struct dentry *error = ERR_PTR(-ENOENT);
23732 +
23733 +       for (; p->name; p++) {
23734 +               if (p->len != dentry->d_name.len)
23735 +                       continue;
23736 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23737 +                       break;
23738 +       }
23739 +       if (!p->name)
23740 +               goto out;
23741 +
23742 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23743 +out:
23744 +       return error;
23745 +}
23746 +
23747 +static int proc_xid_readdir(struct file *filp,
23748 +       void *dirent, filldir_t filldir)
23749 +{
23750 +       struct dentry *dentry = filp->f_dentry;
23751 +       struct inode *inode = dentry->d_inode;
23752 +       struct vs_entry *p = vx_base_stuff;
23753 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
23754 +       int pos, index;
23755 +       u64 ino;
23756 +
23757 +       pos = filp->f_pos;
23758 +       switch (pos) {
23759 +       case 0:
23760 +               ino = inode->i_ino;
23761 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23762 +                       goto out;
23763 +               pos++;
23764 +               /* fall through */
23765 +       case 1:
23766 +               ino = parent_ino(dentry);
23767 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23768 +                       goto out;
23769 +               pos++;
23770 +               /* fall through */
23771 +       default:
23772 +               index = pos - 2;
23773 +               if (index >= size)
23774 +                       goto out;
23775 +               for (p += index; p->name; p++) {
23776 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23777 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23778 +                               goto out;
23779 +                       pos++;
23780 +               }
23781 +       }
23782 +out:
23783 +       filp->f_pos = pos;
23784 +       return 1;
23785 +}
23786 +
23787 +
23788 +
23789 +static struct file_operations proc_nx_info_file_operations = {
23790 +       .read =         proc_nx_info_read,
23791 +};
23792 +
23793 +static struct dentry_operations proc_nid_dentry_operations = {
23794 +       .d_revalidate = proc_nid_revalidate,
23795 +};
23796 +
23797 +static struct vs_entry nx_base_stuff[] = {
23798 +       NINF("info",    S_IRUGO, nxi_info),
23799 +       NINF("status",  S_IRUGO, nxi_status),
23800 +       {}
23801 +};
23802 +
23803 +
23804 +static struct dentry *proc_nid_instantiate(struct inode *dir,
23805 +       struct dentry *dentry, int id, void *ptr)
23806 +{
23807 +       dentry->d_op = &proc_nid_dentry_operations;
23808 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23809 +}
23810 +
23811 +static struct dentry *proc_nid_lookup(struct inode *dir,
23812 +       struct dentry *dentry, struct nameidata *nd)
23813 +{
23814 +       struct vs_entry *p = nx_base_stuff;
23815 +       struct dentry *error = ERR_PTR(-ENOENT);
23816 +
23817 +       for (; p->name; p++) {
23818 +               if (p->len != dentry->d_name.len)
23819 +                       continue;
23820 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23821 +                       break;
23822 +       }
23823 +       if (!p->name)
23824 +               goto out;
23825 +
23826 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23827 +out:
23828 +       return error;
23829 +}
23830 +
23831 +static int proc_nid_readdir(struct file *filp,
23832 +       void *dirent, filldir_t filldir)
23833 +{
23834 +       struct dentry *dentry = filp->f_dentry;
23835 +       struct inode *inode = dentry->d_inode;
23836 +       struct vs_entry *p = nx_base_stuff;
23837 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
23838 +       int pos, index;
23839 +       u64 ino;
23840 +
23841 +       pos = filp->f_pos;
23842 +       switch (pos) {
23843 +       case 0:
23844 +               ino = inode->i_ino;
23845 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23846 +                       goto out;
23847 +               pos++;
23848 +               /* fall through */
23849 +       case 1:
23850 +               ino = parent_ino(dentry);
23851 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23852 +                       goto out;
23853 +               pos++;
23854 +               /* fall through */
23855 +       default:
23856 +               index = pos - 2;
23857 +               if (index >= size)
23858 +                       goto out;
23859 +               for (p += index; p->name; p++) {
23860 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23861 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23862 +                               goto out;
23863 +                       pos++;
23864 +               }
23865 +       }
23866 +out:
23867 +       filp->f_pos = pos;
23868 +       return 1;
23869 +}
23870 +
23871 +
23872 +#define MAX_MULBY10    ((~0U - 9) / 10)
23873 +
23874 +static inline int atovid(const char *str, int len)
23875 +{
23876 +       int vid, c;
23877 +
23878 +       vid = 0;
23879 +       while (len-- > 0) {
23880 +               c = *str - '0';
23881 +               str++;
23882 +               if (c > 9)
23883 +                       return -1;
23884 +               if (vid >= MAX_MULBY10)
23885 +                       return -1;
23886 +               vid *= 10;
23887 +               vid += c;
23888 +               if (!vid)
23889 +                       return -1;
23890 +       }
23891 +       return vid;
23892 +}
23893 +
23894 +/* now the upper level (virtual) */
23895 +
23896 +
23897 +static struct file_operations proc_xid_file_operations = {
23898 +       .read =         generic_read_dir,
23899 +       .readdir =      proc_xid_readdir,
23900 +};
23901 +
23902 +static struct inode_operations proc_xid_inode_operations = {
23903 +       .lookup =       proc_xid_lookup,
23904 +};
23905 +
23906 +static struct vs_entry vx_virtual_stuff[] = {
23907 +       INF("info",     S_IRUGO, virtual_info),
23908 +       INF("status",   S_IRUGO, virtual_status),
23909 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
23910 +};
23911 +
23912 +
23913 +static struct dentry *proc_virtual_lookup(struct inode *dir,
23914 +       struct dentry *dentry, struct nameidata *nd)
23915 +{
23916 +       struct vs_entry *p = vx_virtual_stuff;
23917 +       struct dentry *error = ERR_PTR(-ENOENT);
23918 +       int id = 0;
23919 +
23920 +       for (; p->name; p++) {
23921 +               if (p->len != dentry->d_name.len)
23922 +                       continue;
23923 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23924 +                       break;
23925 +       }
23926 +       if (p->name)
23927 +               goto instantiate;
23928 +
23929 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
23930 +       if ((id < 0) || !xid_is_hashed(id))
23931 +               goto out;
23932 +
23933 +instantiate:
23934 +       error = proc_xid_instantiate(dir, dentry, id, p);
23935 +out:
23936 +       return error;
23937 +}
23938 +
23939 +static struct file_operations proc_nid_file_operations = {
23940 +       .read =         generic_read_dir,
23941 +       .readdir =      proc_nid_readdir,
23942 +};
23943 +
23944 +static struct inode_operations proc_nid_inode_operations = {
23945 +       .lookup =       proc_nid_lookup,
23946 +};
23947 +
23948 +static struct vs_entry nx_virtnet_stuff[] = {
23949 +       INF("info",     S_IRUGO, virtnet_info),
23950 +       INF("status",   S_IRUGO, virtnet_status),
23951 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
23952 +};
23953 +
23954 +
23955 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
23956 +       struct dentry *dentry, struct nameidata *nd)
23957 +{
23958 +       struct vs_entry *p = nx_virtnet_stuff;
23959 +       struct dentry *error = ERR_PTR(-ENOENT);
23960 +       int id = 0;
23961 +
23962 +       for (; p->name; p++) {
23963 +               if (p->len != dentry->d_name.len)
23964 +                       continue;
23965 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23966 +                       break;
23967 +       }
23968 +       if (p->name)
23969 +               goto instantiate;
23970 +
23971 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
23972 +       if ((id < 0) || !nid_is_hashed(id))
23973 +               goto out;
23974 +
23975 +instantiate:
23976 +       error = proc_nid_instantiate(dir, dentry, id, p);
23977 +out:
23978 +       return error;
23979 +}
23980 +
23981 +
23982 +#define PROC_MAXVIDS 32
23983 +
23984 +int proc_virtual_readdir(struct file *filp,
23985 +       void *dirent, filldir_t filldir)
23986 +{
23987 +       struct dentry *dentry = filp->f_dentry;
23988 +       struct inode *inode = dentry->d_inode;
23989 +       struct vs_entry *p = vx_virtual_stuff;
23990 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
23991 +       int pos, index;
23992 +       unsigned int xid_array[PROC_MAXVIDS];
23993 +       char buf[PROC_NUMBUF];
23994 +       unsigned int nr_xids, i;
23995 +       u64 ino;
23996 +
23997 +       pos = filp->f_pos;
23998 +       switch (pos) {
23999 +       case 0:
24000 +               ino = inode->i_ino;
24001 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
24002 +                       goto out;
24003 +               pos++;
24004 +               /* fall through */
24005 +       case 1:
24006 +               ino = parent_ino(dentry);
24007 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
24008 +                       goto out;
24009 +               pos++;
24010 +               /* fall through */
24011 +       default:
24012 +               index = pos - 2;
24013 +               if (index >= size)
24014 +                       goto entries;
24015 +               for (p += index; p->name; p++) {
24016 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
24017 +                               vs_proc_instantiate, 0, p))
24018 +                               goto out;
24019 +                       pos++;
24020 +               }
24021 +       entries:
24022 +               index = pos - size;
24023 +               p = &vx_virtual_stuff[size - 1];
24024 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
24025 +               for (i = 0; i < nr_xids; i++) {
24026 +                       int n, xid = xid_array[i];
24027 +                       unsigned int j = PROC_NUMBUF;
24028 +
24029 +                       n = xid;
24030 +                       do
24031 +                               buf[--j] = '0' + (n % 10);
24032 +                       while (n /= 10);
24033 +
24034 +                       if (proc_fill_cache(filp, dirent, filldir,
24035 +                               buf + j, PROC_NUMBUF - j,
24036 +                               vs_proc_instantiate, xid, p))
24037 +                               goto out;
24038 +                       pos++;
24039 +               }
24040 +       }
24041 +out:
24042 +       filp->f_pos = pos;
24043 +       return 0;
24044 +}
24045 +
24046 +static int proc_virtual_getattr(struct vfsmount *mnt,
24047 +       struct dentry *dentry, struct kstat *stat)
24048 +{
24049 +       struct inode *inode = dentry->d_inode;
24050 +
24051 +       generic_fillattr(inode, stat);
24052 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
24053 +       return 0;
24054 +}
24055 +
24056 +static struct file_operations proc_virtual_dir_operations = {
24057 +       .read =         generic_read_dir,
24058 +       .readdir =      proc_virtual_readdir,
24059 +};
24060 +
24061 +static struct inode_operations proc_virtual_dir_inode_operations = {
24062 +       .getattr =      proc_virtual_getattr,
24063 +       .lookup =       proc_virtual_lookup,
24064 +};
24065 +
24066 +
24067 +
24068 +
24069 +
24070 +int proc_virtnet_readdir(struct file *filp,
24071 +       void *dirent, filldir_t filldir)
24072 +{
24073 +       struct dentry *dentry = filp->f_dentry;
24074 +       struct inode *inode = dentry->d_inode;
24075 +       struct vs_entry *p = nx_virtnet_stuff;
24076 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
24077 +       int pos, index;
24078 +       unsigned int nid_array[PROC_MAXVIDS];
24079 +       char buf[PROC_NUMBUF];
24080 +       unsigned int nr_nids, i;
24081 +       u64 ino;
24082 +
24083 +       pos = filp->f_pos;
24084 +       switch (pos) {
24085 +       case 0:
24086 +               ino = inode->i_ino;
24087 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
24088 +                       goto out;
24089 +               pos++;
24090 +               /* fall through */
24091 +       case 1:
24092 +               ino = parent_ino(dentry);
24093 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
24094 +                       goto out;
24095 +               pos++;
24096 +               /* fall through */
24097 +       default:
24098 +               index = pos - 2;
24099 +               if (index >= size)
24100 +                       goto entries;
24101 +               for (p += index; p->name; p++) {
24102 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
24103 +                               vs_proc_instantiate, 0, p))
24104 +                               goto out;
24105 +                       pos++;
24106 +               }
24107 +       entries:
24108 +               index = pos - size;
24109 +               p = &nx_virtnet_stuff[size - 1];
24110 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
24111 +               for (i = 0; i < nr_nids; i++) {
24112 +                       int n, nid = nid_array[i];
24113 +                       unsigned int j = PROC_NUMBUF;
24114 +
24115 +                       n = nid;
24116 +                       do
24117 +                               buf[--j] = '0' + (n % 10);
24118 +                       while (n /= 10);
24119 +
24120 +                       if (proc_fill_cache(filp, dirent, filldir,
24121 +                               buf + j, PROC_NUMBUF - j,
24122 +                               vs_proc_instantiate, nid, p))
24123 +                               goto out;
24124 +                       pos++;
24125 +               }
24126 +       }
24127 +out:
24128 +       filp->f_pos = pos;
24129 +       return 0;
24130 +}
24131 +
24132 +static int proc_virtnet_getattr(struct vfsmount *mnt,
24133 +       struct dentry *dentry, struct kstat *stat)
24134 +{
24135 +       struct inode *inode = dentry->d_inode;
24136 +
24137 +       generic_fillattr(inode, stat);
24138 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
24139 +       return 0;
24140 +}
24141 +
24142 +static struct file_operations proc_virtnet_dir_operations = {
24143 +       .read =         generic_read_dir,
24144 +       .readdir =      proc_virtnet_readdir,
24145 +};
24146 +
24147 +static struct inode_operations proc_virtnet_dir_inode_operations = {
24148 +       .getattr =      proc_virtnet_getattr,
24149 +       .lookup =       proc_virtnet_lookup,
24150 +};
24151 +
24152 +
24153 +
24154 +void proc_vx_init(void)
24155 +{
24156 +       struct proc_dir_entry *ent;
24157 +
24158 +       ent = proc_mkdir("virtual", 0);
24159 +       if (ent) {
24160 +               ent->proc_fops = &proc_virtual_dir_operations;
24161 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
24162 +       }
24163 +       proc_virtual = ent;
24164 +
24165 +       ent = proc_mkdir("virtnet", 0);
24166 +       if (ent) {
24167 +               ent->proc_fops = &proc_virtnet_dir_operations;
24168 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
24169 +       }
24170 +       proc_virtnet = ent;
24171 +}
24172 +
24173 +
24174 +
24175 +
24176 +/* per pid info */
24177 +
24178 +
24179 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
24180 +{
24181 +       struct vx_info *vxi;
24182 +       char *orig = buffer;
24183 +
24184 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
24185 +
24186 +       vxi = task_get_vx_info(p);
24187 +       if (!vxi)
24188 +               goto out;
24189 +
24190 +       buffer += sprintf(buffer, "BCaps:\t");
24191 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
24192 +       buffer += sprintf(buffer, "\n");
24193 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
24194 +               (unsigned long long)vxi->vx_ccaps);
24195 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
24196 +               (unsigned long long)vxi->vx_flags);
24197 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
24198 +
24199 +       put_vx_info(vxi);
24200 +out:
24201 +       return buffer - orig;
24202 +}
24203 +
24204 +
24205 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
24206 +{
24207 +       struct nx_info *nxi;
24208 +       struct nx_addr_v4 *v4a;
24209 +#ifdef CONFIG_IPV6
24210 +       struct nx_addr_v6 *v6a;
24211 +#endif
24212 +       char *orig = buffer;
24213 +       int i;
24214 +
24215 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
24216 +
24217 +       nxi = task_get_nx_info(p);
24218 +       if (!nxi)
24219 +               goto out;
24220 +
24221 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
24222 +               (unsigned long long)nxi->nx_ncaps);
24223 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
24224 +               (unsigned long long)nxi->nx_flags);
24225 +
24226 +       buffer += sprintf(buffer,
24227 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
24228 +               NIPQUAD(nxi->v4_bcast.s_addr));
24229 +       buffer += sprintf (buffer,
24230 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
24231 +               NIPQUAD(nxi->v4_lback.s_addr));
24232 +       if (!NX_IPV4(nxi))
24233 +               goto skip_v4;
24234 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
24235 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
24236 +                       i, NXAV4(v4a));
24237 +skip_v4:
24238 +#ifdef CONFIG_IPV6
24239 +       if (!NX_IPV6(nxi))
24240 +               goto skip_v6;
24241 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
24242 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
24243 +                       i, NXAV6(v6a));
24244 +skip_v6:
24245 +#endif
24246 +       put_nx_info(nxi);
24247 +out:
24248 +       return buffer - orig;
24249 +}
24250 +
24251 diff -NurpP --minimal linux-2.6.32.56/kernel/vserver/sched.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/sched.c
24252 --- linux-2.6.32.56/kernel/vserver/sched.c      1970-01-01 01:00:00.000000000 +0100
24253 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/sched.c      2011-06-10 13:03:02.000000000 +0200
24254 @@ -0,0 +1,414 @@
24255 +/*
24256 + *  linux/kernel/vserver/sched.c
24257 + *
24258 + *  Virtual Server: Scheduler Support
24259 + *
24260 + *  Copyright (C) 2004-2007  Herbert Pötzl
24261 + *
24262 + *  V0.01  adapted Sam Vilains version to 2.6.3
24263 + *  V0.02  removed legacy interface
24264 + *  V0.03  changed vcmds to vxi arg
24265 + *  V0.04  removed older and legacy interfaces
24266 + *
24267 + */
24268 +
24269 +#include <linux/vs_context.h>
24270 +#include <linux/vs_sched.h>
24271 +#include <linux/vserver/sched_cmd.h>
24272 +
24273 +#include <asm/uaccess.h>
24274 +
24275 +
24276 +#define vxd_check_range(val, min, max) do {            \
24277 +       vxlprintk((val < min) || (val > max),           \
24278 +               "check_range(%ld,%ld,%ld)",             \
24279 +               (long)val, (long)min, (long)max,        \
24280 +               __FILE__, __LINE__);                    \
24281 +       } while (0)
24282 +
24283 +
24284 +void vx_update_sched_param(struct _vx_sched *sched,
24285 +       struct _vx_sched_pc *sched_pc)
24286 +{
24287 +       unsigned int set_mask = sched->update_mask;
24288 +
24289 +       if (set_mask & VXSM_FILL_RATE)
24290 +               sched_pc->fill_rate[0] = sched->fill_rate[0];
24291 +       if (set_mask & VXSM_INTERVAL)
24292 +               sched_pc->interval[0] = sched->interval[0];
24293 +       if (set_mask & VXSM_FILL_RATE2)
24294 +               sched_pc->fill_rate[1] = sched->fill_rate[1];
24295 +       if (set_mask & VXSM_INTERVAL2)
24296 +               sched_pc->interval[1] = sched->interval[1];
24297 +       if (set_mask & VXSM_TOKENS)
24298 +               sched_pc->tokens = sched->tokens;
24299 +       if (set_mask & VXSM_TOKENS_MIN)
24300 +               sched_pc->tokens_min = sched->tokens_min;
24301 +       if (set_mask & VXSM_TOKENS_MAX)
24302 +               sched_pc->tokens_max = sched->tokens_max;
24303 +       if (set_mask & VXSM_PRIO_BIAS)
24304 +               sched_pc->prio_bias = sched->prio_bias;
24305 +
24306 +       if (set_mask & VXSM_IDLE_TIME)
24307 +               sched_pc->flags |= VXSF_IDLE_TIME;
24308 +       else
24309 +               sched_pc->flags &= ~VXSF_IDLE_TIME;
24310 +
24311 +       /* reset time */
24312 +       sched_pc->norm_time = jiffies;
24313 +}
24314 +
24315 +
24316 +/*
24317 + * recalculate the context's scheduling tokens
24318 + *
24319 + * ret > 0 : number of tokens available
24320 + * ret < 0 : on hold, check delta_min[]
24321 + *          -1 only jiffies
24322 + *          -2 also idle time
24323 + *
24324 + */
24325 +int vx_tokens_recalc(struct _vx_sched_pc *sched_pc,
24326 +       unsigned long *norm_time, unsigned long *idle_time, int delta_min[2])
24327 +{
24328 +       long delta;
24329 +       long tokens = 0;
24330 +       int flags = sched_pc->flags;
24331 +
24332 +       /* how much time did pass? */
24333 +       delta = *norm_time - sched_pc->norm_time;
24334 +       // printk("@ %ld, %ld, %ld\n", *norm_time, sched_pc->norm_time, jiffies);
24335 +       vxd_check_range(delta, 0, INT_MAX);
24336 +
24337 +       if (delta >= sched_pc->interval[0]) {
24338 +               long tokens, integral;
24339 +
24340 +               /* calc integral token part */
24341 +               tokens = delta / sched_pc->interval[0];
24342 +               integral = tokens * sched_pc->interval[0];
24343 +               tokens *= sched_pc->fill_rate[0];
24344 +#ifdef CONFIG_VSERVER_HARDCPU
24345 +               delta_min[0] = delta - integral;
24346 +               vxd_check_range(delta_min[0], 0, sched_pc->interval[0]);
24347 +#endif
24348 +               /* advance time */
24349 +               sched_pc->norm_time += delta;
24350 +
24351 +               /* add tokens */
24352 +               sched_pc->tokens += tokens;
24353 +               sched_pc->token_time += tokens;
24354 +       } else
24355 +               delta_min[0] = delta;
24356 +
24357 +#ifdef CONFIG_VSERVER_IDLETIME
24358 +       if (!(flags & VXSF_IDLE_TIME))
24359 +               goto skip_idle;
24360 +
24361 +       /* how much was the idle skip? */
24362 +       delta = *idle_time - sched_pc->idle_time;
24363 +       vxd_check_range(delta, 0, INT_MAX);
24364 +
24365 +       if (delta >= sched_pc->interval[1]) {
24366 +               long tokens, integral;
24367 +
24368 +               /* calc fair share token part */
24369 +               tokens = delta / sched_pc->interval[1];
24370 +               integral = tokens * sched_pc->interval[1];
24371 +               tokens *= sched_pc->fill_rate[1];
24372 +               delta_min[1] = delta - integral;
24373 +               vxd_check_range(delta_min[1], 0, sched_pc->interval[1]);
24374 +
24375 +               /* advance idle time */
24376 +               sched_pc->idle_time += integral;
24377 +
24378 +               /* add tokens */
24379 +               sched_pc->tokens += tokens;
24380 +               sched_pc->token_time += tokens;
24381 +       } else
24382 +               delta_min[1] = delta;
24383 +skip_idle:
24384 +#endif
24385 +
24386 +       /* clip at maximum */
24387 +       if (sched_pc->tokens > sched_pc->tokens_max)
24388 +               sched_pc->tokens = sched_pc->tokens_max;
24389 +       tokens = sched_pc->tokens;
24390 +
24391 +       if ((flags & VXSF_ONHOLD)) {
24392 +               /* can we unhold? */
24393 +               if (tokens >= sched_pc->tokens_min) {
24394 +                       flags &= ~VXSF_ONHOLD;
24395 +                       sched_pc->hold_ticks +=
24396 +                               *norm_time - sched_pc->onhold;
24397 +               } else
24398 +                       goto on_hold;
24399 +       } else {
24400 +               /* put on hold? */
24401 +               if (tokens <= 0) {
24402 +                       flags |= VXSF_ONHOLD;
24403 +                       sched_pc->onhold = *norm_time;
24404 +                       goto on_hold;
24405 +               }
24406 +       }
24407 +       sched_pc->flags = flags;
24408 +       return tokens;
24409 +
24410 +on_hold:
24411 +       tokens = sched_pc->tokens_min - tokens;
24412 +       sched_pc->flags = flags;
24413 +       // BUG_ON(tokens < 0); probably doesn't hold anymore
24414 +
24415 +#ifdef CONFIG_VSERVER_HARDCPU
24416 +       /* next interval? */
24417 +       if (!sched_pc->fill_rate[0])
24418 +               delta_min[0] = HZ;
24419 +       else if (tokens > sched_pc->fill_rate[0])
24420 +               delta_min[0] += sched_pc->interval[0] *
24421 +                       tokens / sched_pc->fill_rate[0];
24422 +       else
24423 +               delta_min[0] = sched_pc->interval[0] - delta_min[0];
24424 +       vxd_check_range(delta_min[0], 0, INT_MAX);
24425 +
24426 +#ifdef CONFIG_VSERVER_IDLETIME
24427 +       if (!(flags & VXSF_IDLE_TIME))
24428 +               return -1;
24429 +
24430 +       /* next interval? */
24431 +       if (!sched_pc->fill_rate[1])
24432 +               delta_min[1] = HZ;
24433 +       else if (tokens > sched_pc->fill_rate[1])
24434 +               delta_min[1] += sched_pc->interval[1] *
24435 +                       tokens / sched_pc->fill_rate[1];
24436 +       else
24437 +               delta_min[1] = sched_pc->interval[1] - delta_min[1];
24438 +       vxd_check_range(delta_min[1], 0, INT_MAX);
24439 +
24440 +       return -2;
24441 +#else
24442 +       return -1;
24443 +#endif /* CONFIG_VSERVER_IDLETIME */
24444 +#else
24445 +       return 0;
24446 +#endif /* CONFIG_VSERVER_HARDCPU */
24447 +}
24448 +
24449 +static inline unsigned long msec_to_ticks(unsigned long msec)
24450 +{
24451 +       return msecs_to_jiffies(msec);
24452 +}
24453 +
24454 +static inline unsigned long ticks_to_msec(unsigned long ticks)
24455 +{
24456 +       return jiffies_to_msecs(ticks);
24457 +}
24458 +
24459 +static inline unsigned long ticks_to_usec(unsigned long ticks)
24460 +{
24461 +       return jiffies_to_usecs(ticks);
24462 +}
24463 +
24464 +
24465 +static int do_set_sched(struct vx_info *vxi, struct vcmd_sched_v5 *data)
24466 +{
24467 +       unsigned int set_mask = data->mask;
24468 +       unsigned int update_mask;
24469 +       int i, cpu;
24470 +
24471 +       /* Sanity check data values */
24472 +       if (data->tokens_max <= 0)
24473 +               data->tokens_max = HZ;
24474 +       if (data->tokens_min < 0)
24475 +               data->tokens_min = HZ / 3;
24476 +       if (data->tokens_min >= data->tokens_max)
24477 +               data->tokens_min = data->tokens_max;
24478 +
24479 +       if (data->prio_bias > MAX_PRIO_BIAS)
24480 +               data->prio_bias = MAX_PRIO_BIAS;
24481 +       if (data->prio_bias < MIN_PRIO_BIAS)
24482 +               data->prio_bias = MIN_PRIO_BIAS;
24483 +
24484 +       spin_lock(&vxi->sched.tokens_lock);
24485 +
24486 +       /* sync up on delayed updates */
24487 +       for_each_cpu_mask(cpu, vxi->sched.update)
24488 +               vx_update_sched_param(&vxi->sched,
24489 +                       &vx_per_cpu(vxi, sched_pc, cpu));
24490 +
24491 +       if (set_mask & VXSM_FILL_RATE)
24492 +               vxi->sched.fill_rate[0] = data->fill_rate[0];
24493 +       if (set_mask & VXSM_FILL_RATE2)
24494 +               vxi->sched.fill_rate[1] = data->fill_rate[1];
24495 +       if (set_mask & VXSM_INTERVAL)
24496 +               vxi->sched.interval[0] = (set_mask & VXSM_MSEC) ?
24497 +                       msec_to_ticks(data->interval[0]) : data->interval[0];
24498 +       if (set_mask & VXSM_INTERVAL2)
24499 +               vxi->sched.interval[1] = (set_mask & VXSM_MSEC) ?
24500 +                       msec_to_ticks(data->interval[1]) : data->interval[1];
24501 +       if (set_mask & VXSM_TOKENS)
24502 +               vxi->sched.tokens = data->tokens;
24503 +       if (set_mask & VXSM_TOKENS_MIN)
24504 +               vxi->sched.tokens_min = data->tokens_min;
24505 +       if (set_mask & VXSM_TOKENS_MAX)
24506 +               vxi->sched.tokens_max = data->tokens_max;
24507 +       if (set_mask & VXSM_PRIO_BIAS)
24508 +               vxi->sched.prio_bias = data->prio_bias;
24509 +
24510 +       /* Sanity check rate/interval */
24511 +       for (i = 0; i < 2; i++) {
24512 +               if (data->fill_rate[i] < 0)
24513 +                       data->fill_rate[i] = 0;
24514 +               if (data->interval[i] <= 0)
24515 +                       data->interval[i] = HZ;
24516 +       }
24517 +
24518 +       update_mask = vxi->sched.update_mask & VXSM_SET_MASK;
24519 +       update_mask |= (set_mask & (VXSM_SET_MASK | VXSM_IDLE_TIME));
24520 +       vxi->sched.update_mask = update_mask;
24521 +
24522 +#ifdef CONFIG_SMP
24523 +       rmb();
24524 +       if (set_mask & VXSM_CPU_ID) {
24525 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
24526 +               cpus_and(vxi->sched.update, cpu_online_map,
24527 +                       vxi->sched.update);
24528 +       } else
24529 +               vxi->sched.update = cpu_online_map;
24530 +
24531 +       /* forced reload? */
24532 +       if (set_mask & VXSM_FORCE) {
24533 +               for_each_cpu_mask(cpu, vxi->sched.update)
24534 +                       vx_update_sched_param(&vxi->sched,
24535 +                               &vx_per_cpu(vxi, sched_pc, cpu));
24536 +               vxi->sched.update = CPU_MASK_NONE;
24537 +       }
24538 +#else
24539 +       /* on UP we update immediately */
24540 +       vx_update_sched_param(&vxi->sched,
24541 +               &vx_per_cpu(vxi, sched_pc, 0));
24542 +#endif
24543 +
24544 +       spin_unlock(&vxi->sched.tokens_lock);
24545 +       return 0;
24546 +}
24547 +
24548 +
24549 +#define COPY_IDS(C) C(cpu_id); C(bucket_id)
24550 +#define COPY_PRI(C) C(prio_bias)
24551 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
24552 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);   \
24553 +                   C(fill_rate[1]); C(interval[1]);
24554 +
24555 +#define COPY_VALUE(name) vc_data.name = data->name
24556 +
24557 +static int do_set_sched_v4(struct vx_info *vxi, struct vcmd_set_sched_v4 *data)
24558 +{
24559 +       struct vcmd_sched_v5 vc_data;
24560 +
24561 +       vc_data.mask = data->set_mask;
24562 +       COPY_IDS(COPY_VALUE);
24563 +       COPY_PRI(COPY_VALUE);
24564 +       COPY_TOK(COPY_VALUE);
24565 +       vc_data.fill_rate[0] = vc_data.fill_rate[1] = data->fill_rate;
24566 +       vc_data.interval[0] = vc_data.interval[1] = data->interval;
24567 +       return do_set_sched(vxi, &vc_data);
24568 +}
24569 +
24570 +int vc_set_sched_v4(struct vx_info *vxi, void __user *data)
24571 +{
24572 +       struct vcmd_set_sched_v4 vc_data;
24573 +
24574 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24575 +               return -EFAULT;
24576 +
24577 +       return do_set_sched_v4(vxi, &vc_data);
24578 +}
24579 +
24580 +       /* latest interface is v5 */
24581 +
24582 +int vc_set_sched(struct vx_info *vxi, void __user *data)
24583 +{
24584 +       struct vcmd_sched_v5 vc_data;
24585 +
24586 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24587 +               return -EFAULT;
24588 +
24589 +       return do_set_sched(vxi, &vc_data);
24590 +}
24591 +
24592 +
24593 +#define COPY_PRI(C) C(prio_bias)
24594 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
24595 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);    \
24596 +                   C(fill_rate[1]); C(interval[1]);
24597 +
24598 +#define COPY_VALUE(name) vc_data.name = data->name
24599 +
24600 +
24601 +int vc_get_sched(struct vx_info *vxi, void __user *data)
24602 +{
24603 +       struct vcmd_sched_v5 vc_data;
24604 +
24605 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24606 +               return -EFAULT;
24607 +
24608 +       if (vc_data.mask & VXSM_CPU_ID) {
24609 +               int cpu = vc_data.cpu_id;
24610 +               struct _vx_sched_pc *data;
24611 +
24612 +               if (!cpu_possible(cpu))
24613 +                       return -EINVAL;
24614 +
24615 +               data = &vx_per_cpu(vxi, sched_pc, cpu);
24616 +               COPY_TOK(COPY_VALUE);
24617 +               COPY_PRI(COPY_VALUE);
24618 +               COPY_FRI(COPY_VALUE);
24619 +
24620 +               if (data->flags & VXSF_IDLE_TIME)
24621 +                       vc_data.mask |= VXSM_IDLE_TIME;
24622 +       } else {
24623 +               struct _vx_sched *data = &vxi->sched;
24624 +
24625 +               COPY_TOK(COPY_VALUE);
24626 +               COPY_PRI(COPY_VALUE);
24627 +               COPY_FRI(COPY_VALUE);
24628 +       }
24629 +
24630 +       if (vc_data.mask & VXSM_MSEC) {
24631 +               vc_data.interval[0] = ticks_to_msec(vc_data.interval[0]);
24632 +               vc_data.interval[1] = ticks_to_msec(vc_data.interval[1]);
24633 +       }
24634 +
24635 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24636 +               return -EFAULT;
24637 +       return 0;
24638 +}
24639 +
24640 +
24641 +int vc_sched_info(struct vx_info *vxi, void __user *data)
24642 +{
24643 +       struct vcmd_sched_info vc_data;
24644 +       int cpu;
24645 +
24646 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24647 +               return -EFAULT;
24648 +
24649 +       cpu = vc_data.cpu_id;
24650 +       if (!cpu_possible(cpu))
24651 +               return -EINVAL;
24652 +
24653 +       if (vxi) {
24654 +               struct _vx_sched_pc *sched_pc =
24655 +                       &vx_per_cpu(vxi, sched_pc, cpu);
24656 +
24657 +               vc_data.user_msec = ticks_to_msec(sched_pc->user_ticks);
24658 +               vc_data.sys_msec = ticks_to_msec(sched_pc->sys_ticks);
24659 +               vc_data.hold_msec = ticks_to_msec(sched_pc->hold_ticks);
24660 +               vc_data.vavavoom = sched_pc->vavavoom;
24661 +       }
24662 +       vc_data.token_usec = ticks_to_usec(1);
24663 +
24664 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24665 +               return -EFAULT;
24666 +       return 0;
24667 +}
24668 +
24669 diff -NurpP --minimal linux-2.6.32.56/kernel/vserver/sched_init.h linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/sched_init.h
24670 --- linux-2.6.32.56/kernel/vserver/sched_init.h 1970-01-01 01:00:00.000000000 +0100
24671 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/sched_init.h 2011-06-10 13:03:02.000000000 +0200
24672 @@ -0,0 +1,50 @@
24673 +
24674 +static inline void vx_info_init_sched(struct _vx_sched *sched)
24675 +{
24676 +       static struct lock_class_key tokens_lock_key;
24677 +
24678 +       /* scheduling; hard code starting values as constants */
24679 +       sched->fill_rate[0]     = 1;
24680 +       sched->interval[0]      = 4;
24681 +       sched->fill_rate[1]     = 1;
24682 +       sched->interval[1]      = 8;
24683 +       sched->tokens           = HZ >> 2;
24684 +       sched->tokens_min       = HZ >> 4;
24685 +       sched->tokens_max       = HZ >> 1;
24686 +       sched->tokens_lock      = SPIN_LOCK_UNLOCKED;
24687 +       sched->prio_bias        = 0;
24688 +
24689 +       lockdep_set_class(&sched->tokens_lock, &tokens_lock_key);
24690 +}
24691 +
24692 +static inline
24693 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24694 +{
24695 +       sched_pc->fill_rate[0]  = 1;
24696 +       sched_pc->interval[0]   = 4;
24697 +       sched_pc->fill_rate[1]  = 1;
24698 +       sched_pc->interval[1]   = 8;
24699 +       sched_pc->tokens        = HZ >> 2;
24700 +       sched_pc->tokens_min    = HZ >> 4;
24701 +       sched_pc->tokens_max    = HZ >> 1;
24702 +       sched_pc->prio_bias     = 0;
24703 +       sched_pc->vavavoom      = 0;
24704 +       sched_pc->token_time    = 0;
24705 +       sched_pc->idle_time     = 0;
24706 +       sched_pc->norm_time     = jiffies;
24707 +
24708 +       sched_pc->user_ticks = 0;
24709 +       sched_pc->sys_ticks = 0;
24710 +       sched_pc->hold_ticks = 0;
24711 +}
24712 +
24713 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
24714 +{
24715 +       return;
24716 +}
24717 +
24718 +static inline
24719 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24720 +{
24721 +       return;
24722 +}
24723 diff -NurpP --minimal linux-2.6.32.56/kernel/vserver/sched_proc.h linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/sched_proc.h
24724 --- linux-2.6.32.56/kernel/vserver/sched_proc.h 1970-01-01 01:00:00.000000000 +0100
24725 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/sched_proc.h 2011-06-10 13:03:02.000000000 +0200
24726 @@ -0,0 +1,57 @@
24727 +#ifndef _VX_SCHED_PROC_H
24728 +#define _VX_SCHED_PROC_H
24729 +
24730 +
24731 +static inline
24732 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
24733 +{
24734 +       int length = 0;
24735 +
24736 +       length += sprintf(buffer,
24737 +               "FillRate:\t%8d,%d\n"
24738 +               "Interval:\t%8d,%d\n"
24739 +               "TokensMin:\t%8d\n"
24740 +               "TokensMax:\t%8d\n"
24741 +               "PrioBias:\t%8d\n",
24742 +               sched->fill_rate[0],
24743 +               sched->fill_rate[1],
24744 +               sched->interval[0],
24745 +               sched->interval[1],
24746 +               sched->tokens_min,
24747 +               sched->tokens_max,
24748 +               sched->prio_bias);
24749 +       return length;
24750 +}
24751 +
24752 +static inline
24753 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
24754 +       char *buffer, int cpu)
24755 +{
24756 +       int length = 0;
24757 +
24758 +       length += sprintf(buffer + length,
24759 +               "cpu %d: %lld %lld %lld %ld %ld", cpu,
24760 +               (unsigned long long)sched_pc->user_ticks,
24761 +               (unsigned long long)sched_pc->sys_ticks,
24762 +               (unsigned long long)sched_pc->hold_ticks,
24763 +               sched_pc->token_time,
24764 +               sched_pc->idle_time);
24765 +       length += sprintf(buffer + length,
24766 +               " %c%c %d %d %d %d/%d %d/%d",
24767 +               (sched_pc->flags & VXSF_ONHOLD) ? 'H' : 'R',
24768 +               (sched_pc->flags & VXSF_IDLE_TIME) ? 'I' : '-',
24769 +               sched_pc->tokens,
24770 +               sched_pc->tokens_min,
24771 +               sched_pc->tokens_max,
24772 +               sched_pc->fill_rate[0],
24773 +               sched_pc->interval[0],
24774 +               sched_pc->fill_rate[1],
24775 +               sched_pc->interval[1]);
24776 +       length += sprintf(buffer + length,
24777 +               " %d %d\n",
24778 +               sched_pc->prio_bias,
24779 +               sched_pc->vavavoom);
24780 +       return length;
24781 +}
24782 +
24783 +#endif /* _VX_SCHED_PROC_H */
24784 diff -NurpP --minimal linux-2.6.32.56/kernel/vserver/signal.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/signal.c
24785 --- linux-2.6.32.56/kernel/vserver/signal.c     1970-01-01 01:00:00.000000000 +0100
24786 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/signal.c     2011-06-10 13:03:02.000000000 +0200
24787 @@ -0,0 +1,132 @@
24788 +/*
24789 + *  linux/kernel/vserver/signal.c
24790 + *
24791 + *  Virtual Server: Signal Support
24792 + *
24793 + *  Copyright (C) 2003-2007  Herbert Pötzl
24794 + *
24795 + *  V0.01  broken out from vcontext V0.05
24796 + *  V0.02  changed vcmds to vxi arg
24797 + *  V0.03  adjusted siginfo for kill
24798 + *
24799 + */
24800 +
24801 +#include <asm/uaccess.h>
24802 +
24803 +#include <linux/vs_context.h>
24804 +#include <linux/vs_pid.h>
24805 +#include <linux/vserver/signal_cmd.h>
24806 +
24807 +
24808 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
24809 +{
24810 +       int retval, count = 0;
24811 +       struct task_struct *p;
24812 +       struct siginfo *sip = SEND_SIG_PRIV;
24813 +
24814 +       retval = -ESRCH;
24815 +       vxdprintk(VXD_CBIT(misc, 4),
24816 +               "vx_info_kill(%p[#%d],%d,%d)*",
24817 +               vxi, vxi->vx_id, pid, sig);
24818 +       read_lock(&tasklist_lock);
24819 +       switch (pid) {
24820 +       case  0:
24821 +       case -1:
24822 +               for_each_process(p) {
24823 +                       int err = 0;
24824 +
24825 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
24826 +                               (pid && vxi->vx_initpid == p->pid))
24827 +                               continue;
24828 +
24829 +                       err = group_send_sig_info(sig, sip, p);
24830 +                       ++count;
24831 +                       if (err != -EPERM)
24832 +                               retval = err;
24833 +               }
24834 +               break;
24835 +
24836 +       case 1:
24837 +               if (vxi->vx_initpid) {
24838 +                       pid = vxi->vx_initpid;
24839 +                       /* for now, only SIGINT to private init ... */
24840 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24841 +                               /* ... as long as there are tasks left */
24842 +                               (atomic_read(&vxi->vx_tasks) > 1))
24843 +                               sig = SIGINT;
24844 +               }
24845 +               /* fallthrough */
24846 +       default:
24847 +               p = find_task_by_real_pid(pid);
24848 +               if (p) {
24849 +                       if (vx_task_xid(p) == vxi->vx_id)
24850 +                               retval = group_send_sig_info(sig, sip, p);
24851 +               }
24852 +               break;
24853 +       }
24854 +       read_unlock(&tasklist_lock);
24855 +       vxdprintk(VXD_CBIT(misc, 4),
24856 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
24857 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
24858 +       return retval;
24859 +}
24860 +
24861 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
24862 +{
24863 +       struct vcmd_ctx_kill_v0 vc_data;
24864 +
24865 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24866 +               return -EFAULT;
24867 +
24868 +       /* special check to allow guest shutdown */
24869 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24870 +               /* forbid killall pid=0 when init is present */
24871 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
24872 +               (vc_data.pid > 1)))
24873 +               return -EACCES;
24874 +
24875 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
24876 +}
24877 +
24878 +
24879 +static int __wait_exit(struct vx_info *vxi)
24880 +{
24881 +       DECLARE_WAITQUEUE(wait, current);
24882 +       int ret = 0;
24883 +
24884 +       add_wait_queue(&vxi->vx_wait, &wait);
24885 +       set_current_state(TASK_INTERRUPTIBLE);
24886 +
24887 +wait:
24888 +       if (vx_info_state(vxi,
24889 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
24890 +               goto out;
24891 +       if (signal_pending(current)) {
24892 +               ret = -ERESTARTSYS;
24893 +               goto out;
24894 +       }
24895 +       schedule();
24896 +       goto wait;
24897 +
24898 +out:
24899 +       set_current_state(TASK_RUNNING);
24900 +       remove_wait_queue(&vxi->vx_wait, &wait);
24901 +       return ret;
24902 +}
24903 +
24904 +
24905 +
24906 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
24907 +{
24908 +       struct vcmd_wait_exit_v0 vc_data;
24909 +       int ret;
24910 +
24911 +       ret = __wait_exit(vxi);
24912 +       vc_data.reboot_cmd = vxi->reboot_cmd;
24913 +       vc_data.exit_code = vxi->exit_code;
24914 +
24915 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24916 +               ret = -EFAULT;
24917 +       return ret;
24918 +}
24919 +
24920 diff -NurpP --minimal linux-2.6.32.56/kernel/vserver/space.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/space.c
24921 --- linux-2.6.32.56/kernel/vserver/space.c      1970-01-01 01:00:00.000000000 +0100
24922 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/space.c      2011-06-10 13:03:02.000000000 +0200
24923 @@ -0,0 +1,375 @@
24924 +/*
24925 + *  linux/kernel/vserver/space.c
24926 + *
24927 + *  Virtual Server: Context Space Support
24928 + *
24929 + *  Copyright (C) 2003-2007  Herbert Pötzl
24930 + *
24931 + *  V0.01  broken out from context.c 0.07
24932 + *  V0.02  added task locking for namespace
24933 + *  V0.03  broken out vx_enter_namespace
24934 + *  V0.04  added *space support and commands
24935 + *
24936 + */
24937 +
24938 +#include <linux/utsname.h>
24939 +#include <linux/nsproxy.h>
24940 +#include <linux/err.h>
24941 +#include <linux/fs_struct.h>
24942 +#include <asm/uaccess.h>
24943 +
24944 +#include <linux/vs_context.h>
24945 +#include <linux/vserver/space.h>
24946 +#include <linux/vserver/space_cmd.h>
24947 +
24948 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
24949 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
24950 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
24951 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
24952 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
24953 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
24954 +
24955 +
24956 +/* namespace functions */
24957 +
24958 +#include <linux/mnt_namespace.h>
24959 +#include <linux/user_namespace.h>
24960 +#include <linux/pid_namespace.h>
24961 +#include <linux/ipc_namespace.h>
24962 +#include <net/net_namespace.h>
24963 +
24964 +
24965 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
24966 +       .mask = CLONE_FS |
24967 +               CLONE_NEWNS |
24968 +               CLONE_NEWUTS |
24969 +               CLONE_NEWIPC |
24970 +               CLONE_NEWUSER |
24971 +               0
24972 +};
24973 +
24974 +static const struct vcmd_space_mask_v1 space_mask = {
24975 +       .mask = CLONE_FS |
24976 +               CLONE_NEWNS |
24977 +               CLONE_NEWUTS |
24978 +               CLONE_NEWIPC |
24979 +               CLONE_NEWUSER |
24980 +#ifdef CONFIG_PID_NS
24981 +               CLONE_NEWPID |
24982 +#endif
24983 +#ifdef CONFIG_NET_NS
24984 +               CLONE_NEWNET |
24985 +#endif
24986 +               0
24987 +};
24988 +
24989 +static const struct vcmd_space_mask_v1 default_space_mask = {
24990 +       .mask = CLONE_FS |
24991 +               CLONE_NEWNS |
24992 +               CLONE_NEWUTS |
24993 +               CLONE_NEWIPC |
24994 +               CLONE_NEWUSER |
24995 +#ifdef CONFIG_PID_NS
24996 +//             CLONE_NEWPID |
24997 +#endif
24998 +               0
24999 +};
25000 +
25001 +/*
25002 + *     build a new nsproxy mix
25003 + *      assumes that both proxies are 'const'
25004 + *     does not touch nsproxy refcounts
25005 + *     will hold a reference on the result.
25006 + */
25007 +
25008 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
25009 +       struct nsproxy *new_nsproxy, unsigned long mask)
25010 +{
25011 +       struct mnt_namespace *old_ns;
25012 +       struct uts_namespace *old_uts;
25013 +       struct ipc_namespace *old_ipc;
25014 +#ifdef CONFIG_PID_NS
25015 +       struct pid_namespace *old_pid;
25016 +#endif
25017 +#ifdef CONFIG_NET_NS
25018 +       struct net *old_net;
25019 +#endif
25020 +       struct nsproxy *nsproxy;
25021 +
25022 +       nsproxy = copy_nsproxy(old_nsproxy);
25023 +       if (!nsproxy)
25024 +               goto out;
25025 +
25026 +       if (mask & CLONE_NEWNS) {
25027 +               old_ns = nsproxy->mnt_ns;
25028 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
25029 +               if (nsproxy->mnt_ns)
25030 +                       get_mnt_ns(nsproxy->mnt_ns);
25031 +       } else
25032 +               old_ns = NULL;
25033 +
25034 +       if (mask & CLONE_NEWUTS) {
25035 +               old_uts = nsproxy->uts_ns;
25036 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
25037 +               if (nsproxy->uts_ns)
25038 +                       get_uts_ns(nsproxy->uts_ns);
25039 +       } else
25040 +               old_uts = NULL;
25041 +
25042 +       if (mask & CLONE_NEWIPC) {
25043 +               old_ipc = nsproxy->ipc_ns;
25044 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
25045 +               if (nsproxy->ipc_ns)
25046 +                       get_ipc_ns(nsproxy->ipc_ns);
25047 +       } else
25048 +               old_ipc = NULL;
25049 +
25050 +#ifdef CONFIG_PID_NS
25051 +       if (mask & CLONE_NEWPID) {
25052 +               old_pid = nsproxy->pid_ns;
25053 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
25054 +               if (nsproxy->pid_ns)
25055 +                       get_pid_ns(nsproxy->pid_ns);
25056 +       } else
25057 +               old_pid = NULL;
25058 +#endif
25059 +#ifdef CONFIG_NET_NS
25060 +       if (mask & CLONE_NEWNET) {
25061 +               old_net = nsproxy->net_ns;
25062 +               nsproxy->net_ns = new_nsproxy->net_ns;
25063 +               if (nsproxy->net_ns)
25064 +                       get_net(nsproxy->net_ns);
25065 +       } else
25066 +               old_net = NULL;
25067 +#endif
25068 +       if (old_ns)
25069 +               put_mnt_ns(old_ns);
25070 +       if (old_uts)
25071 +               put_uts_ns(old_uts);
25072 +       if (old_ipc)
25073 +               put_ipc_ns(old_ipc);
25074 +#ifdef CONFIG_PID_NS
25075 +       if (old_pid)
25076 +               put_pid_ns(old_pid);
25077 +#endif
25078 +#ifdef CONFIG_NET_NS
25079 +       if (old_net)
25080 +               put_net(old_net);
25081 +#endif
25082 +out:
25083 +       return nsproxy;
25084 +}
25085 +
25086 +
25087 +/*
25088 + *     merge two nsproxy structs into a new one.
25089 + *     will hold a reference on the result.
25090 + */
25091 +
25092 +static inline
25093 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
25094 +       struct nsproxy *proxy, unsigned long mask)
25095 +{
25096 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
25097 +
25098 +       if (!proxy)
25099 +               return NULL;
25100 +
25101 +       if (mask) {
25102 +               /* vs_mix_nsproxy returns with reference */
25103 +               return vs_mix_nsproxy(old ? old : &null_proxy,
25104 +                       proxy, mask);
25105 +       }
25106 +       get_nsproxy(proxy);
25107 +       return proxy;
25108 +}
25109 +
25110 +
25111 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
25112 +{
25113 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
25114 +       struct fs_struct *fs_cur, *fs = NULL;
25115 +       int ret, kill = 0;
25116 +
25117 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
25118 +               vxi, vxi->vx_id, mask, index);
25119 +
25120 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
25121 +               return -EACCES;
25122 +
25123 +       if (!mask)
25124 +               mask = vxi->vx_nsmask[index];
25125 +
25126 +       if ((mask & vxi->vx_nsmask[index]) != mask)
25127 +               return -EINVAL;
25128 +
25129 +       if (mask & CLONE_FS) {
25130 +               fs = copy_fs_struct(vxi->vx_fs[index]);
25131 +               if (!fs)
25132 +                       return -ENOMEM;
25133 +       }
25134 +       proxy = vxi->vx_nsproxy[index];
25135 +
25136 +       vxdprintk(VXD_CBIT(space, 9),
25137 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
25138 +               vxi, vxi->vx_id, mask, index, proxy, fs);
25139 +
25140 +       task_lock(current);
25141 +       fs_cur = current->fs;
25142 +
25143 +       if (mask & CLONE_FS) {
25144 +               write_lock(&fs_cur->lock);
25145 +               current->fs = fs;
25146 +               kill = !--fs_cur->users;
25147 +               write_unlock(&fs_cur->lock);
25148 +       }
25149 +
25150 +       proxy_cur = current->nsproxy;
25151 +       get_nsproxy(proxy_cur);
25152 +       task_unlock(current);
25153 +
25154 +       if (kill)
25155 +               free_fs_struct(fs_cur);
25156 +
25157 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
25158 +       if (IS_ERR(proxy_new)) {
25159 +               ret = PTR_ERR(proxy_new);
25160 +               goto out_put;
25161 +       }
25162 +
25163 +       proxy_new = xchg(&current->nsproxy, proxy_new);
25164 +       ret = 0;
25165 +
25166 +       if (proxy_new)
25167 +               put_nsproxy(proxy_new);
25168 +out_put:
25169 +       if (proxy_cur)
25170 +               put_nsproxy(proxy_cur);
25171 +       return ret;
25172 +}
25173 +
25174 +
25175 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
25176 +{
25177 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
25178 +       struct fs_struct *fs_vxi, *fs;
25179 +       int ret, kill = 0;
25180 +
25181 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
25182 +               vxi, vxi->vx_id, mask, index);
25183 +#if 0
25184 +       if (!mask)
25185 +               mask = default_space_mask.mask;
25186 +#endif
25187 +       if ((mask & space_mask.mask) != mask)
25188 +               return -EINVAL;
25189 +
25190 +       proxy_vxi = vxi->vx_nsproxy[index];
25191 +       fs_vxi = vxi->vx_fs[index];
25192 +
25193 +       if (mask & CLONE_FS) {
25194 +               fs = copy_fs_struct(current->fs);
25195 +               if (!fs)
25196 +                       return -ENOMEM;
25197 +       }
25198 +
25199 +       task_lock(current);
25200 +
25201 +       if (mask & CLONE_FS) {
25202 +               write_lock(&fs_vxi->lock);
25203 +               vxi->vx_fs[index] = fs;
25204 +               kill = !--fs_vxi->users;
25205 +               write_unlock(&fs_vxi->lock);
25206 +       }
25207 +
25208 +       proxy_cur = current->nsproxy;
25209 +       get_nsproxy(proxy_cur);
25210 +       task_unlock(current);
25211 +
25212 +       if (kill)
25213 +               free_fs_struct(fs_vxi);
25214 +
25215 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
25216 +       if (IS_ERR(proxy_new)) {
25217 +               ret = PTR_ERR(proxy_new);
25218 +               goto out_put;
25219 +       }
25220 +
25221 +       proxy_new = xchg(&vxi->vx_nsproxy[index], proxy_new);
25222 +       vxi->vx_nsmask[index] |= mask;
25223 +       ret = 0;
25224 +
25225 +       if (proxy_new)
25226 +               put_nsproxy(proxy_new);
25227 +out_put:
25228 +       if (proxy_cur)
25229 +               put_nsproxy(proxy_cur);
25230 +       return ret;
25231 +}
25232 +
25233 +
25234 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
25235 +{
25236 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
25237 +
25238 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
25239 +               return -EFAULT;
25240 +
25241 +       return vx_enter_space(vxi, vc_data.mask, 0);
25242 +}
25243 +
25244 +int vc_enter_space(struct vx_info *vxi, void __user *data)
25245 +{
25246 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
25247 +
25248 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
25249 +               return -EFAULT;
25250 +
25251 +       if (vc_data.index >= VX_SPACES)
25252 +               return -EINVAL;
25253 +
25254 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
25255 +}
25256 +
25257 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
25258 +{
25259 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
25260 +
25261 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
25262 +               return -EFAULT;
25263 +
25264 +       return vx_set_space(vxi, vc_data.mask, 0);
25265 +}
25266 +
25267 +int vc_set_space(struct vx_info *vxi, void __user *data)
25268 +{
25269 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
25270 +
25271 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
25272 +               return -EFAULT;
25273 +
25274 +       if (vc_data.index >= VX_SPACES)
25275 +               return -EINVAL;
25276 +
25277 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
25278 +}
25279 +
25280 +int vc_get_space_mask(void __user *data, int type)
25281 +{
25282 +       const struct vcmd_space_mask_v1 *mask;
25283 +
25284 +       if (type == 0)
25285 +               mask = &space_mask_v0;
25286 +       else if (type == 1)
25287 +               mask = &space_mask;
25288 +       else
25289 +               mask = &default_space_mask;
25290 +
25291 +       vxdprintk(VXD_CBIT(space, 10),
25292 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
25293 +
25294 +       if (copy_to_user(data, mask, sizeof(*mask)))
25295 +               return -EFAULT;
25296 +       return 0;
25297 +}
25298 +
25299 diff -NurpP --minimal linux-2.6.32.56/kernel/vserver/switch.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/switch.c
25300 --- linux-2.6.32.56/kernel/vserver/switch.c     1970-01-01 01:00:00.000000000 +0100
25301 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/switch.c     2011-06-10 13:03:02.000000000 +0200
25302 @@ -0,0 +1,546 @@
25303 +/*
25304 + *  linux/kernel/vserver/switch.c
25305 + *
25306 + *  Virtual Server: Syscall Switch
25307 + *
25308 + *  Copyright (C) 2003-2007  Herbert Pötzl
25309 + *
25310 + *  V0.01  syscall switch
25311 + *  V0.02  added signal to context
25312 + *  V0.03  added rlimit functions
25313 + *  V0.04  added iattr, task/xid functions
25314 + *  V0.05  added debug/history stuff
25315 + *  V0.06  added compat32 layer
25316 + *  V0.07  vcmd args and perms
25317 + *  V0.08  added status commands
25318 + *  V0.09  added tag commands
25319 + *  V0.10  added oom bias
25320 + *  V0.11  added device commands
25321 + *
25322 + */
25323 +
25324 +#include <linux/vs_context.h>
25325 +#include <linux/vs_network.h>
25326 +#include <linux/vserver/switch.h>
25327 +
25328 +#include "vci_config.h"
25329 +
25330 +
25331 +static inline
25332 +int vc_get_version(uint32_t id)
25333 +{
25334 +       return VCI_VERSION;
25335 +}
25336 +
25337 +static inline
25338 +int vc_get_vci(uint32_t id)
25339 +{
25340 +       return vci_kernel_config();
25341 +}
25342 +
25343 +#include <linux/vserver/context_cmd.h>
25344 +#include <linux/vserver/cvirt_cmd.h>
25345 +#include <linux/vserver/cacct_cmd.h>
25346 +#include <linux/vserver/limit_cmd.h>
25347 +#include <linux/vserver/network_cmd.h>
25348 +#include <linux/vserver/sched_cmd.h>
25349 +#include <linux/vserver/debug_cmd.h>
25350 +#include <linux/vserver/inode_cmd.h>
25351 +#include <linux/vserver/dlimit_cmd.h>
25352 +#include <linux/vserver/signal_cmd.h>
25353 +#include <linux/vserver/space_cmd.h>
25354 +#include <linux/vserver/tag_cmd.h>
25355 +#include <linux/vserver/device_cmd.h>
25356 +
25357 +#include <linux/vserver/inode.h>
25358 +#include <linux/vserver/dlimit.h>
25359 +
25360 +
25361 +#ifdef CONFIG_COMPAT
25362 +#define __COMPAT(name, id, data, compat)       \
25363 +       (compat) ? name ## _x32(id, data) : name(id, data)
25364 +#define __COMPAT_NO_ID(name, data, compat)     \
25365 +       (compat) ? name ## _x32(data) : name(data)
25366 +#else
25367 +#define __COMPAT(name, id, data, compat)       \
25368 +       name(id, data)
25369 +#define __COMPAT_NO_ID(name, data, compat)     \
25370 +       name(data)
25371 +#endif
25372 +
25373 +
25374 +static inline
25375 +long do_vcmd(uint32_t cmd, uint32_t id,
25376 +       struct vx_info *vxi, struct nx_info *nxi,
25377 +       void __user *data, int compat)
25378 +{
25379 +       switch (cmd) {
25380 +
25381 +       case VCMD_get_version:
25382 +               return vc_get_version(id);
25383 +       case VCMD_get_vci:
25384 +               return vc_get_vci(id);
25385 +
25386 +       case VCMD_task_xid:
25387 +               return vc_task_xid(id);
25388 +       case VCMD_vx_info:
25389 +               return vc_vx_info(vxi, data);
25390 +
25391 +       case VCMD_task_nid:
25392 +               return vc_task_nid(id);
25393 +       case VCMD_nx_info:
25394 +               return vc_nx_info(nxi, data);
25395 +
25396 +       case VCMD_task_tag:
25397 +               return vc_task_tag(id);
25398 +
25399 +       case VCMD_set_space_v1:
25400 +               return vc_set_space_v1(vxi, data);
25401 +       /* this is version 2 */
25402 +       case VCMD_set_space:
25403 +               return vc_set_space(vxi, data);
25404 +
25405 +       case VCMD_get_space_mask_v0:
25406 +               return vc_get_space_mask(data, 0);
25407 +       /* this is version 1 */
25408 +       case VCMD_get_space_mask:
25409 +               return vc_get_space_mask(data, 1);
25410 +
25411 +       case VCMD_get_space_default:
25412 +               return vc_get_space_mask(data, -1);
25413 +
25414 +#ifdef CONFIG_IA32_EMULATION
25415 +       case VCMD_get_rlimit:
25416 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
25417 +       case VCMD_set_rlimit:
25418 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
25419 +#else
25420 +       case VCMD_get_rlimit:
25421 +               return vc_get_rlimit(vxi, data);
25422 +       case VCMD_set_rlimit:
25423 +               return vc_set_rlimit(vxi, data);
25424 +#endif
25425 +       case VCMD_get_rlimit_mask:
25426 +               return vc_get_rlimit_mask(id, data);
25427 +       case VCMD_reset_hits:
25428 +               return vc_reset_hits(vxi, data);
25429 +       case VCMD_reset_minmax:
25430 +               return vc_reset_minmax(vxi, data);
25431 +
25432 +       case VCMD_get_vhi_name:
25433 +               return vc_get_vhi_name(vxi, data);
25434 +       case VCMD_set_vhi_name:
25435 +               return vc_set_vhi_name(vxi, data);
25436 +
25437 +       case VCMD_ctx_stat:
25438 +               return vc_ctx_stat(vxi, data);
25439 +       case VCMD_virt_stat:
25440 +               return vc_virt_stat(vxi, data);
25441 +       case VCMD_sock_stat:
25442 +               return vc_sock_stat(vxi, data);
25443 +       case VCMD_rlimit_stat:
25444 +               return vc_rlimit_stat(vxi, data);
25445 +
25446 +       case VCMD_set_cflags:
25447 +               return vc_set_cflags(vxi, data);
25448 +       case VCMD_get_cflags:
25449 +               return vc_get_cflags(vxi, data);
25450 +
25451 +       /* this is version 1 */
25452 +       case VCMD_set_ccaps:
25453 +               return vc_set_ccaps(vxi, data);
25454 +       /* this is version 1 */
25455 +       case VCMD_get_ccaps:
25456 +               return vc_get_ccaps(vxi, data);
25457 +       case VCMD_set_bcaps:
25458 +               return vc_set_bcaps(vxi, data);
25459 +       case VCMD_get_bcaps:
25460 +               return vc_get_bcaps(vxi, data);
25461 +
25462 +       case VCMD_set_badness:
25463 +               return vc_set_badness(vxi, data);
25464 +       case VCMD_get_badness:
25465 +               return vc_get_badness(vxi, data);
25466 +
25467 +       case VCMD_set_nflags:
25468 +               return vc_set_nflags(nxi, data);
25469 +       case VCMD_get_nflags:
25470 +               return vc_get_nflags(nxi, data);
25471 +
25472 +       case VCMD_set_ncaps:
25473 +               return vc_set_ncaps(nxi, data);
25474 +       case VCMD_get_ncaps:
25475 +               return vc_get_ncaps(nxi, data);
25476 +
25477 +       case VCMD_set_sched_v4:
25478 +               return vc_set_sched_v4(vxi, data);
25479 +       /* this is version 5 */
25480 +       case VCMD_set_sched:
25481 +               return vc_set_sched(vxi, data);
25482 +       case VCMD_get_sched:
25483 +               return vc_get_sched(vxi, data);
25484 +       case VCMD_sched_info:
25485 +               return vc_sched_info(vxi, data);
25486 +
25487 +       case VCMD_add_dlimit:
25488 +               return __COMPAT(vc_add_dlimit, id, data, compat);
25489 +       case VCMD_rem_dlimit:
25490 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
25491 +       case VCMD_set_dlimit:
25492 +               return __COMPAT(vc_set_dlimit, id, data, compat);
25493 +       case VCMD_get_dlimit:
25494 +               return __COMPAT(vc_get_dlimit, id, data, compat);
25495 +
25496 +       case VCMD_ctx_kill:
25497 +               return vc_ctx_kill(vxi, data);
25498 +
25499 +       case VCMD_wait_exit:
25500 +               return vc_wait_exit(vxi, data);
25501 +
25502 +       case VCMD_get_iattr:
25503 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
25504 +       case VCMD_set_iattr:
25505 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
25506 +
25507 +       case VCMD_fget_iattr:
25508 +               return vc_fget_iattr(id, data);
25509 +       case VCMD_fset_iattr:
25510 +               return vc_fset_iattr(id, data);
25511 +
25512 +       case VCMD_enter_space_v0:
25513 +               return vc_enter_space_v1(vxi, NULL);
25514 +       case VCMD_enter_space_v1:
25515 +               return vc_enter_space_v1(vxi, data);
25516 +       /* this is version 2 */
25517 +       case VCMD_enter_space:
25518 +               return vc_enter_space(vxi, data);
25519 +
25520 +       case VCMD_ctx_create_v0:
25521 +               return vc_ctx_create(id, NULL);
25522 +       case VCMD_ctx_create:
25523 +               return vc_ctx_create(id, data);
25524 +       case VCMD_ctx_migrate_v0:
25525 +               return vc_ctx_migrate(vxi, NULL);
25526 +       case VCMD_ctx_migrate:
25527 +               return vc_ctx_migrate(vxi, data);
25528 +
25529 +       case VCMD_net_create_v0:
25530 +               return vc_net_create(id, NULL);
25531 +       case VCMD_net_create:
25532 +               return vc_net_create(id, data);
25533 +       case VCMD_net_migrate:
25534 +               return vc_net_migrate(nxi, data);
25535 +
25536 +       case VCMD_tag_migrate:
25537 +               return vc_tag_migrate(id);
25538 +
25539 +       case VCMD_net_add:
25540 +               return vc_net_add(nxi, data);
25541 +       case VCMD_net_remove:
25542 +               return vc_net_remove(nxi, data);
25543 +
25544 +       case VCMD_net_add_ipv4:
25545 +               return vc_net_add_ipv4(nxi, data);
25546 +       case VCMD_net_remove_ipv4:
25547 +               return vc_net_remove_ipv4(nxi, data);
25548 +#ifdef CONFIG_IPV6
25549 +       case VCMD_net_add_ipv6:
25550 +               return vc_net_add_ipv6(nxi, data);
25551 +       case VCMD_net_remove_ipv6:
25552 +               return vc_net_remove_ipv6(nxi, data);
25553 +#endif
25554 +/*     case VCMD_add_match_ipv4:
25555 +               return vc_add_match_ipv4(nxi, data);
25556 +       case VCMD_get_match_ipv4:
25557 +               return vc_get_match_ipv4(nxi, data);
25558 +#ifdef CONFIG_IPV6
25559 +       case VCMD_add_match_ipv6:
25560 +               return vc_add_match_ipv6(nxi, data);
25561 +       case VCMD_get_match_ipv6:
25562 +               return vc_get_match_ipv6(nxi, data);
25563 +#endif */
25564 +
25565 +#ifdef CONFIG_VSERVER_DEVICE
25566 +       case VCMD_set_mapping:
25567 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
25568 +       case VCMD_unset_mapping:
25569 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
25570 +#endif
25571 +#ifdef CONFIG_VSERVER_HISTORY
25572 +       case VCMD_dump_history:
25573 +               return vc_dump_history(id);
25574 +       case VCMD_read_history:
25575 +               return __COMPAT(vc_read_history, id, data, compat);
25576 +#endif
25577 +#ifdef CONFIG_VSERVER_MONITOR
25578 +       case VCMD_read_monitor:
25579 +               return __COMPAT(vc_read_monitor, id, data, compat);
25580 +#endif
25581 +       default:
25582 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
25583 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
25584 +       }
25585 +       return -ENOSYS;
25586 +}
25587 +
25588 +
25589 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
25590 +       case VCMD_ ## vcmd: perm = _perm;               \
25591 +               args = _args; flags = _flags; break
25592 +
25593 +
25594 +#define VCA_NONE       0x00
25595 +#define VCA_VXI                0x01
25596 +#define VCA_NXI                0x02
25597 +
25598 +#define VCF_NONE       0x00
25599 +#define VCF_INFO       0x01
25600 +#define VCF_ADMIN      0x02
25601 +#define VCF_ARES       0x06    /* includes admin */
25602 +#define VCF_SETUP      0x08
25603 +
25604 +#define VCF_ZIDOK      0x10    /* zero id okay */
25605 +
25606 +
25607 +static inline
25608 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
25609 +{
25610 +       long ret;
25611 +       int permit = -1, state = 0;
25612 +       int perm = -1, args = 0, flags = 0;
25613 +       struct vx_info *vxi = NULL;
25614 +       struct nx_info *nxi = NULL;
25615 +
25616 +       switch (cmd) {
25617 +       /* unpriviledged commands */
25618 +       __VCMD(get_version,      0, VCA_NONE,   0);
25619 +       __VCMD(get_vci,          0, VCA_NONE,   0);
25620 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
25621 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
25622 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
25623 +       __VCMD(get_space_default,0, VCA_NONE,   0);
25624 +
25625 +       /* info commands */
25626 +       __VCMD(task_xid,         2, VCA_NONE,   0);
25627 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
25628 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
25629 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
25630 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
25631 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
25632 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
25633 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
25634 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
25635 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
25636 +
25637 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
25638 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
25639 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
25640 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
25641 +
25642 +       __VCMD(task_nid,         2, VCA_NONE,   0);
25643 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
25644 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
25645 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
25646 +
25647 +       __VCMD(task_tag,         2, VCA_NONE,   0);
25648 +
25649 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
25650 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
25651 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
25652 +       __VCMD(get_sched,        3, VCA_VXI,    VCF_INFO);
25653 +       __VCMD(sched_info,       3, VCA_VXI,    VCF_INFO | VCF_ZIDOK);
25654 +
25655 +       /* lower admin commands */
25656 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
25657 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
25658 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
25659 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
25660 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
25661 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
25662 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
25663 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
25664 +
25665 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
25666 +       __VCMD(net_create,       5, VCA_NONE,   0);
25667 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
25668 +
25669 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
25670 +
25671 +       /* higher admin commands */
25672 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
25673 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25674 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25675 +
25676 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25677 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25678 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25679 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25680 +
25681 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25682 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25683 +       __VCMD(set_sched,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25684 +       __VCMD(set_sched_v4,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25685 +
25686 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25687 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25688 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25689 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25690 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25691 +       __VCMD(net_remove_ipv4,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25692 +#ifdef CONFIG_IPV6
25693 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25694 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25695 +#endif
25696 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
25697 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
25698 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
25699 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
25700 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
25701 +
25702 +#ifdef CONFIG_VSERVER_DEVICE
25703 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
25704 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
25705 +#endif
25706 +       /* debug level admin commands */
25707 +#ifdef CONFIG_VSERVER_HISTORY
25708 +       __VCMD(dump_history,     9, VCA_NONE,   0);
25709 +       __VCMD(read_history,     9, VCA_NONE,   0);
25710 +#endif
25711 +#ifdef CONFIG_VSERVER_MONITOR
25712 +       __VCMD(read_monitor,     9, VCA_NONE,   0);
25713 +#endif
25714 +
25715 +       default:
25716 +               perm = -1;
25717 +       }
25718 +
25719 +       vxdprintk(VXD_CBIT(switch, 0),
25720 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
25721 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25722 +               VC_VERSION(cmd), id, data, compat,
25723 +               perm, args, flags);
25724 +
25725 +       ret = -ENOSYS;
25726 +       if (perm < 0)
25727 +               goto out;
25728 +
25729 +       state = 1;
25730 +       if (!capable(CAP_CONTEXT))
25731 +               goto out;
25732 +
25733 +       state = 2;
25734 +       /* moved here from the individual commands */
25735 +       ret = -EPERM;
25736 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
25737 +               goto out;
25738 +
25739 +       state = 3;
25740 +       /* vcmd involves resource management  */
25741 +       ret = -EPERM;
25742 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
25743 +               goto out;
25744 +
25745 +       state = 4;
25746 +       /* various legacy exceptions */
25747 +       switch (cmd) {
25748 +       /* will go away when spectator is a cap */
25749 +       case VCMD_ctx_migrate_v0:
25750 +       case VCMD_ctx_migrate:
25751 +               if (id == 1) {
25752 +                       current->xid = 1;
25753 +                       ret = 1;
25754 +                       goto out;
25755 +               }
25756 +               break;
25757 +
25758 +       /* will go away when spectator is a cap */
25759 +       case VCMD_net_migrate:
25760 +               if (id == 1) {
25761 +                       current->nid = 1;
25762 +                       ret = 1;
25763 +                       goto out;
25764 +               }
25765 +               break;
25766 +       }
25767 +
25768 +       /* vcmds are fine by default */
25769 +       permit = 1;
25770 +
25771 +       /* admin type vcmds require admin ... */
25772 +       if (flags & VCF_ADMIN)
25773 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
25774 +
25775 +       /* ... but setup type vcmds override that */
25776 +       if (!permit && (flags & VCF_SETUP))
25777 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
25778 +
25779 +       state = 5;
25780 +       ret = -EPERM;
25781 +       if (!permit)
25782 +               goto out;
25783 +
25784 +       state = 6;
25785 +       if (!id && (flags & VCF_ZIDOK))
25786 +               goto skip_id;
25787 +
25788 +       ret = -ESRCH;
25789 +       if (args & VCA_VXI) {
25790 +               vxi = lookup_vx_info(id);
25791 +               if (!vxi)
25792 +                       goto out;
25793 +
25794 +               if ((flags & VCF_ADMIN) &&
25795 +                       /* special case kill for shutdown */
25796 +                       (cmd != VCMD_ctx_kill) &&
25797 +                       /* can context be administrated? */
25798 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
25799 +                       ret = -EACCES;
25800 +                       goto out_vxi;
25801 +               }
25802 +       }
25803 +       state = 7;
25804 +       if (args & VCA_NXI) {
25805 +               nxi = lookup_nx_info(id);
25806 +               if (!nxi)
25807 +                       goto out_vxi;
25808 +
25809 +               if ((flags & VCF_ADMIN) &&
25810 +                       /* can context be administrated? */
25811 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
25812 +                       ret = -EACCES;
25813 +                       goto out_nxi;
25814 +               }
25815 +       }
25816 +skip_id:
25817 +       state = 8;
25818 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
25819 +
25820 +out_nxi:
25821 +       if ((args & VCA_NXI) && nxi)
25822 +               put_nx_info(nxi);
25823 +out_vxi:
25824 +       if ((args & VCA_VXI) && vxi)
25825 +               put_vx_info(vxi);
25826 +out:
25827 +       vxdprintk(VXD_CBIT(switch, 1),
25828 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
25829 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25830 +               VC_VERSION(cmd), ret, ret, state, permit);
25831 +       return ret;
25832 +}
25833 +
25834 +asmlinkage long
25835 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
25836 +{
25837 +       return do_vserver(cmd, id, data, 0);
25838 +}
25839 +
25840 +#ifdef CONFIG_COMPAT
25841 +
25842 +asmlinkage long
25843 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
25844 +{
25845 +       return do_vserver(cmd, id, data, 1);
25846 +}
25847 +
25848 +#endif /* CONFIG_COMPAT */
25849 diff -NurpP --minimal linux-2.6.32.56/kernel/vserver/sysctl.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/sysctl.c
25850 --- linux-2.6.32.56/kernel/vserver/sysctl.c     1970-01-01 01:00:00.000000000 +0100
25851 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/sysctl.c     2011-06-10 13:03:02.000000000 +0200
25852 @@ -0,0 +1,245 @@
25853 +/*
25854 + *  kernel/vserver/sysctl.c
25855 + *
25856 + *  Virtual Context Support
25857 + *
25858 + *  Copyright (C) 2004-2007  Herbert Pötzl
25859 + *
25860 + *  V0.01  basic structure
25861 + *
25862 + */
25863 +
25864 +#include <linux/module.h>
25865 +#include <linux/ctype.h>
25866 +#include <linux/sysctl.h>
25867 +#include <linux/parser.h>
25868 +#include <asm/uaccess.h>
25869 +
25870 +
25871 +enum {
25872 +       CTL_DEBUG_ERROR         = 0,
25873 +       CTL_DEBUG_SWITCH        = 1,
25874 +       CTL_DEBUG_XID,
25875 +       CTL_DEBUG_NID,
25876 +       CTL_DEBUG_TAG,
25877 +       CTL_DEBUG_NET,
25878 +       CTL_DEBUG_LIMIT,
25879 +       CTL_DEBUG_CRES,
25880 +       CTL_DEBUG_DLIM,
25881 +       CTL_DEBUG_QUOTA,
25882 +       CTL_DEBUG_CVIRT,
25883 +       CTL_DEBUG_SPACE,
25884 +       CTL_DEBUG_MISC,
25885 +};
25886 +
25887 +
25888 +unsigned int vx_debug_switch   = 0;
25889 +unsigned int vx_debug_xid      = 0;
25890 +unsigned int vx_debug_nid      = 0;
25891 +unsigned int vx_debug_tag      = 0;
25892 +unsigned int vx_debug_net      = 0;
25893 +unsigned int vx_debug_limit    = 0;
25894 +unsigned int vx_debug_cres     = 0;
25895 +unsigned int vx_debug_dlim     = 0;
25896 +unsigned int vx_debug_quota    = 0;
25897 +unsigned int vx_debug_cvirt    = 0;
25898 +unsigned int vx_debug_space    = 0;
25899 +unsigned int vx_debug_misc     = 0;
25900 +
25901 +
25902 +static struct ctl_table_header *vserver_table_header;
25903 +static ctl_table vserver_root_table[];
25904 +
25905 +
25906 +void vserver_register_sysctl(void)
25907 +{
25908 +       if (!vserver_table_header) {
25909 +               vserver_table_header = register_sysctl_table(vserver_root_table);
25910 +       }
25911 +
25912 +}
25913 +
25914 +void vserver_unregister_sysctl(void)
25915 +{
25916 +       if (vserver_table_header) {
25917 +               unregister_sysctl_table(vserver_table_header);
25918 +               vserver_table_header = NULL;
25919 +       }
25920 +}
25921 +
25922 +
25923 +static int proc_dodebug(ctl_table *table, int write,
25924 +       void __user *buffer, size_t *lenp, loff_t *ppos)
25925 +{
25926 +       char            tmpbuf[20], *p, c;
25927 +       unsigned int    value;
25928 +       size_t          left, len;
25929 +
25930 +       if ((*ppos && !write) || !*lenp) {
25931 +               *lenp = 0;
25932 +               return 0;
25933 +       }
25934 +
25935 +       left = *lenp;
25936 +
25937 +       if (write) {
25938 +               if (!access_ok(VERIFY_READ, buffer, left))
25939 +                       return -EFAULT;
25940 +               p = (char *)buffer;
25941 +               while (left && __get_user(c, p) >= 0 && isspace(c))
25942 +                       left--, p++;
25943 +               if (!left)
25944 +                       goto done;
25945 +
25946 +               if (left > sizeof(tmpbuf) - 1)
25947 +                       return -EINVAL;
25948 +               if (copy_from_user(tmpbuf, p, left))
25949 +                       return -EFAULT;
25950 +               tmpbuf[left] = '\0';
25951 +
25952 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
25953 +                       value = 10 * value + (*p - '0');
25954 +               if (*p && !isspace(*p))
25955 +                       return -EINVAL;
25956 +               while (left && isspace(*p))
25957 +                       left--, p++;
25958 +               *(unsigned int *)table->data = value;
25959 +       } else {
25960 +               if (!access_ok(VERIFY_WRITE, buffer, left))
25961 +                       return -EFAULT;
25962 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
25963 +               if (len > left)
25964 +                       len = left;
25965 +               if (__copy_to_user(buffer, tmpbuf, len))
25966 +                       return -EFAULT;
25967 +               if ((left -= len) > 0) {
25968 +                       if (put_user('\n', (char *)buffer + len))
25969 +                               return -EFAULT;
25970 +                       left--;
25971 +               }
25972 +       }
25973 +
25974 +done:
25975 +       *lenp -= left;
25976 +       *ppos += *lenp;
25977 +       return 0;
25978 +}
25979 +
25980 +static int zero;
25981 +
25982 +#define        CTL_ENTRY(ctl, name)                            \
25983 +       {                                               \
25984 +               .ctl_name       = ctl,                  \
25985 +               .procname       = #name,                \
25986 +               .data           = &vx_ ## name,         \
25987 +               .maxlen         = sizeof(int),          \
25988 +               .mode           = 0644,                 \
25989 +               .proc_handler   = &proc_dodebug,        \
25990 +               .strategy       = &sysctl_intvec,       \
25991 +               .extra1         = &zero,                \
25992 +               .extra2         = &zero,                \
25993 +       }
25994 +
25995 +static ctl_table vserver_debug_table[] = {
25996 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
25997 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
25998 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
25999 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
26000 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
26001 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
26002 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
26003 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
26004 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
26005 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
26006 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
26007 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
26008 +       { .ctl_name = 0 }
26009 +};
26010 +
26011 +static ctl_table vserver_root_table[] = {
26012 +       {
26013 +               .ctl_name       = CTL_VSERVER,
26014 +               .procname       = "vserver",
26015 +               .mode           = 0555,
26016 +               .child          = vserver_debug_table
26017 +       },
26018 +       { .ctl_name = 0 }
26019 +};
26020 +
26021 +
26022 +static match_table_t tokens = {
26023 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
26024 +       { CTL_DEBUG_XID,        "xid=%x"        },
26025 +       { CTL_DEBUG_NID,        "nid=%x"        },
26026 +       { CTL_DEBUG_TAG,        "tag=%x"        },
26027 +       { CTL_DEBUG_NET,        "net=%x"        },
26028 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
26029 +       { CTL_DEBUG_CRES,       "cres=%x"       },
26030 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
26031 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
26032 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
26033 +       { CTL_DEBUG_SPACE,      "space=%x"      },
26034 +       { CTL_DEBUG_MISC,       "misc=%x"       },
26035 +       { CTL_DEBUG_ERROR,      NULL            }
26036 +};
26037 +
26038 +#define        HANDLE_CASE(id, name, val)                              \
26039 +       case CTL_DEBUG_ ## id:                                  \
26040 +               vx_debug_ ## name = val;                        \
26041 +               printk("vs_debug_" #name "=0x%x\n", val);       \
26042 +               break
26043 +
26044 +
26045 +static int __init vs_debug_setup(char *str)
26046 +{
26047 +       char *p;
26048 +       int token;
26049 +
26050 +       printk("vs_debug_setup(%s)\n", str);
26051 +       while ((p = strsep(&str, ",")) != NULL) {
26052 +               substring_t args[MAX_OPT_ARGS];
26053 +               unsigned int value;
26054 +
26055 +               if (!*p)
26056 +                       continue;
26057 +
26058 +               token = match_token(p, tokens, args);
26059 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
26060 +
26061 +               switch (token) {
26062 +               HANDLE_CASE(SWITCH, switch, value);
26063 +               HANDLE_CASE(XID,    xid,    value);
26064 +               HANDLE_CASE(NID,    nid,    value);
26065 +               HANDLE_CASE(TAG,    tag,    value);
26066 +               HANDLE_CASE(NET,    net,    value);
26067 +               HANDLE_CASE(LIMIT,  limit,  value);
26068 +               HANDLE_CASE(CRES,   cres,   value);
26069 +               HANDLE_CASE(DLIM,   dlim,   value);
26070 +               HANDLE_CASE(QUOTA,  quota,  value);
26071 +               HANDLE_CASE(CVIRT,  cvirt,  value);
26072 +               HANDLE_CASE(SPACE,  space,  value);
26073 +               HANDLE_CASE(MISC,   misc,   value);
26074 +               default:
26075 +                       return -EINVAL;
26076 +                       break;
26077 +               }
26078 +       }
26079 +       return 1;
26080 +}
26081 +
26082 +__setup("vsdebug=", vs_debug_setup);
26083 +
26084 +
26085 +
26086 +EXPORT_SYMBOL_GPL(vx_debug_switch);
26087 +EXPORT_SYMBOL_GPL(vx_debug_xid);
26088 +EXPORT_SYMBOL_GPL(vx_debug_nid);
26089 +EXPORT_SYMBOL_GPL(vx_debug_net);
26090 +EXPORT_SYMBOL_GPL(vx_debug_limit);
26091 +EXPORT_SYMBOL_GPL(vx_debug_cres);
26092 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
26093 +EXPORT_SYMBOL_GPL(vx_debug_quota);
26094 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
26095 +EXPORT_SYMBOL_GPL(vx_debug_space);
26096 +EXPORT_SYMBOL_GPL(vx_debug_misc);
26097 +
26098 diff -NurpP --minimal linux-2.6.32.56/kernel/vserver/tag.c linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/tag.c
26099 --- linux-2.6.32.56/kernel/vserver/tag.c        1970-01-01 01:00:00.000000000 +0100
26100 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/tag.c        2011-06-10 13:03:02.000000000 +0200
26101 @@ -0,0 +1,63 @@
26102 +/*
26103 + *  linux/kernel/vserver/tag.c
26104 + *
26105 + *  Virtual Server: Shallow Tag Space
26106 + *
26107 + *  Copyright (C) 2007  Herbert Pötzl
26108 + *
26109 + *  V0.01  basic implementation
26110 + *
26111 + */
26112 +
26113 +#include <linux/sched.h>
26114 +#include <linux/vserver/debug.h>
26115 +#include <linux/vs_pid.h>
26116 +#include <linux/vs_tag.h>
26117 +
26118 +#include <linux/vserver/tag_cmd.h>
26119 +
26120 +
26121 +int dx_migrate_task(struct task_struct *p, tag_t tag)
26122 +{
26123 +       if (!p)
26124 +               BUG();
26125 +
26126 +       vxdprintk(VXD_CBIT(tag, 5),
26127 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
26128 +
26129 +       task_lock(p);
26130 +       p->tag = tag;
26131 +       task_unlock(p);
26132 +
26133 +       vxdprintk(VXD_CBIT(tag, 5),
26134 +               "moved task %p into [#%d]", p, tag);
26135 +       return 0;
26136 +}
26137 +
26138 +/* vserver syscall commands below here */
26139 +
26140 +/* taks xid and vx_info functions */
26141 +
26142 +
26143 +int vc_task_tag(uint32_t id)
26144 +{
26145 +       tag_t tag;
26146 +
26147 +       if (id) {
26148 +               struct task_struct *tsk;
26149 +               read_lock(&tasklist_lock);
26150 +               tsk = find_task_by_real_pid(id);
26151 +               tag = (tsk) ? tsk->tag : -ESRCH;
26152 +               read_unlock(&tasklist_lock);
26153 +       } else
26154 +               tag = dx_current_tag();
26155 +       return tag;
26156 +}
26157 +
26158 +
26159 +int vc_tag_migrate(uint32_t tag)
26160 +{
26161 +       return dx_migrate_task(current, tag & 0xFFFF);
26162 +}
26163 +
26164 +
26165 diff -NurpP --minimal linux-2.6.32.56/kernel/vserver/vci_config.h linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/vci_config.h
26166 --- linux-2.6.32.56/kernel/vserver/vci_config.h 1970-01-01 01:00:00.000000000 +0100
26167 +++ linux-2.6.32.56-vs2.3.0.36.29.9/kernel/vserver/vci_config.h 2011-06-10 13:03:02.000000000 +0200
26168 @@ -0,0 +1,81 @@
26169 +
26170 +/*  interface version */
26171 +
26172 +#define VCI_VERSION            0x00020305
26173 +
26174 +
26175 +enum {
26176 +       VCI_KCBIT_NO_DYNAMIC = 0,
26177 +
26178 +       VCI_KCBIT_PROC_SECURE = 4,
26179 +       VCI_KCBIT_HARDCPU = 5,
26180 +       VCI_KCBIT_IDLELIMIT = 6,
26181 +       VCI_KCBIT_IDLETIME = 7,
26182 +
26183 +       VCI_KCBIT_COWBL = 8,
26184 +       VCI_KCBIT_FULLCOWBL = 9,
26185 +       VCI_KCBIT_SPACES = 10,
26186 +       VCI_KCBIT_NETV2 = 11,
26187 +
26188 +       VCI_KCBIT_DEBUG = 16,
26189 +       VCI_KCBIT_HISTORY = 20,
26190 +       VCI_KCBIT_TAGGED = 24,
26191 +       VCI_KCBIT_PPTAG = 28,
26192 +
26193 +       VCI_KCBIT_MORE = 31,
26194 +};
26195 +
26196 +
26197 +static inline uint32_t vci_kernel_config(void)
26198 +{
26199 +       return
26200 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
26201 +
26202 +       /* configured features */
26203 +#ifdef CONFIG_VSERVER_PROC_SECURE
26204 +       (1 << VCI_KCBIT_PROC_SECURE) |
26205 +#endif
26206 +#ifdef CONFIG_VSERVER_HARDCPU
26207 +       (1 << VCI_KCBIT_HARDCPU) |
26208 +#endif
26209 +#ifdef CONFIG_VSERVER_IDLELIMIT
26210 +       (1 << VCI_KCBIT_IDLELIMIT) |
26211 +#endif
26212 +#ifdef CONFIG_VSERVER_IDLETIME
26213 +       (1 << VCI_KCBIT_IDLETIME) |
26214 +#endif
26215 +#ifdef CONFIG_VSERVER_COWBL
26216 +       (1 << VCI_KCBIT_COWBL) |
26217 +       (1 << VCI_KCBIT_FULLCOWBL) |
26218 +#endif
26219 +       (1 << VCI_KCBIT_SPACES) |
26220 +       (1 << VCI_KCBIT_NETV2) |
26221 +
26222 +       /* debug options */
26223 +#ifdef CONFIG_VSERVER_DEBUG
26224 +       (1 << VCI_KCBIT_DEBUG) |
26225 +#endif
26226 +#ifdef CONFIG_VSERVER_HISTORY
26227 +       (1 << VCI_KCBIT_HISTORY) |
26228 +#endif
26229 +
26230 +       /* inode context tagging */
26231 +#if    defined(CONFIG_TAGGING_NONE)
26232 +       (0 << VCI_KCBIT_TAGGED) |
26233 +#elif  defined(CONFIG_TAGGING_UID16)
26234 +       (1 << VCI_KCBIT_TAGGED) |
26235 +#elif  defined(CONFIG_TAGGING_GID16)
26236 +       (2 << VCI_KCBIT_TAGGED) |
26237 +#elif  defined(CONFIG_TAGGING_ID24)
26238 +       (3 << VCI_KCBIT_TAGGED) |
26239 +#elif  defined(CONFIG_TAGGING_INTERN)
26240 +       (4 << VCI_KCBIT_TAGGED) |
26241 +#elif  defined(CONFIG_TAGGING_RUNTIME)
26242 +       (5 << VCI_KCBIT_TAGGED) |
26243 +#else
26244 +       (7 << VCI_KCBIT_TAGGED) |
26245 +#endif
26246 +       (1 << VCI_KCBIT_PPTAG) |
26247 +       0;
26248 +}
26249 +
26250 diff -NurpP --minimal linux-2.6.32.56/mm/allocpercpu.c linux-2.6.32.56-vs2.3.0.36.29.9/mm/allocpercpu.c
26251 --- linux-2.6.32.56/mm/allocpercpu.c    2009-12-03 20:02:58.000000000 +0100
26252 +++ linux-2.6.32.56-vs2.3.0.36.29.9/mm/allocpercpu.c    2011-06-10 13:03:02.000000000 +0200
26253 @@ -160,12 +160,14 @@ EXPORT_SYMBOL(__per_cpu_offset);
26254  
26255  void __init setup_per_cpu_areas(void)
26256  {
26257 -       unsigned long size, i;
26258 +       unsigned long size, vspc, i;
26259         char *ptr;
26260         unsigned long nr_possible_cpus = num_possible_cpus();
26261  
26262 +       vspc = PERCPU_PERCTX * CONFIG_VSERVER_CONTEXTS;
26263 +
26264         /* Copy section for each CPU (we discard the original) */
26265 -       size = ALIGN(PERCPU_ENOUGH_ROOM, PAGE_SIZE);
26266 +       size = ALIGN(PERCPU_ENOUGH_ROOM + vspc, PAGE_SIZE);
26267         ptr = alloc_bootmem_pages(size * nr_possible_cpus);
26268  
26269         for_each_possible_cpu(i) {
26270 diff -NurpP --minimal linux-2.6.32.56/mm/filemap_xip.c linux-2.6.32.56-vs2.3.0.36.29.9/mm/filemap_xip.c
26271 --- linux-2.6.32.56/mm/filemap_xip.c    2009-12-03 20:02:58.000000000 +0100
26272 +++ linux-2.6.32.56-vs2.3.0.36.29.9/mm/filemap_xip.c    2011-06-10 13:03:02.000000000 +0200
26273 @@ -17,6 +17,7 @@
26274  #include <linux/sched.h>
26275  #include <linux/seqlock.h>
26276  #include <linux/mutex.h>
26277 +#include <linux/vs_memory.h>
26278  #include <asm/tlbflush.h>
26279  #include <asm/io.h>
26280  
26281 diff -NurpP --minimal linux-2.6.32.56/mm/fremap.c linux-2.6.32.56-vs2.3.0.36.29.9/mm/fremap.c
26282 --- linux-2.6.32.56/mm/fremap.c 2009-03-24 14:22:45.000000000 +0100
26283 +++ linux-2.6.32.56-vs2.3.0.36.29.9/mm/fremap.c 2011-06-10 13:03:02.000000000 +0200
26284 @@ -16,6 +16,7 @@
26285  #include <linux/module.h>
26286  #include <linux/syscalls.h>
26287  #include <linux/mmu_notifier.h>
26288 +#include <linux/vs_memory.h>
26289  
26290  #include <asm/mmu_context.h>
26291  #include <asm/cacheflush.h>
26292 diff -NurpP --minimal linux-2.6.32.56/mm/hugetlb.c linux-2.6.32.56-vs2.3.0.36.29.9/mm/hugetlb.c
26293 --- linux-2.6.32.56/mm/hugetlb.c        2012-02-09 10:22:36.000000000 +0100
26294 +++ linux-2.6.32.56-vs2.3.0.36.29.9/mm/hugetlb.c        2011-08-08 22:40:36.000000000 +0200
26295 @@ -24,6 +24,7 @@
26296  #include <asm/io.h>
26297  
26298  #include <linux/hugetlb.h>
26299 +#include <linux/vs_memory.h>
26300  #include "internal.h"
26301  
26302  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
26303 diff -NurpP --minimal linux-2.6.32.56/mm/memcontrol.c linux-2.6.32.56-vs2.3.0.36.29.9/mm/memcontrol.c
26304 --- linux-2.6.32.56/mm/memcontrol.c     2012-02-09 10:22:36.000000000 +0100
26305 +++ linux-2.6.32.56-vs2.3.0.36.29.9/mm/memcontrol.c     2011-06-10 13:03:02.000000000 +0200
26306 @@ -549,6 +549,31 @@ struct mem_cgroup *mem_cgroup_from_task(
26307                                 struct mem_cgroup, css);
26308  }
26309  
26310 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
26311 +{
26312 +       return res_counter_read_u64(&mem->res, member);
26313 +}
26314 +
26315 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
26316 +{
26317 +       return res_counter_read_u64(&mem->memsw, member);
26318 +}
26319 +
26320 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
26321 +{
26322 +       return mem_cgroup_read_stat(&mem->stat, MEM_CGROUP_STAT_CACHE);
26323 +}
26324 +
26325 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
26326 +{
26327 +       return mem_cgroup_read_stat(&mem->stat, MEM_CGROUP_STAT_RSS);
26328 +}
26329 +
26330 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
26331 +{
26332 +       return mem_cgroup_read_stat(&mem->stat, MEM_CGROUP_STAT_MAPPED_FILE);
26333 +}
26334 +
26335  static struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
26336  {
26337         struct mem_cgroup *mem = NULL;
26338 diff -NurpP --minimal linux-2.6.32.56/mm/memory.c linux-2.6.32.56-vs2.3.0.36.29.9/mm/memory.c
26339 --- linux-2.6.32.56/mm/memory.c 2012-02-09 10:22:36.000000000 +0100
26340 +++ linux-2.6.32.56-vs2.3.0.36.29.9/mm/memory.c 2011-08-08 22:40:36.000000000 +0200
26341 @@ -56,6 +56,7 @@
26342  #include <linux/kallsyms.h>
26343  #include <linux/swapops.h>
26344  #include <linux/elf.h>
26345 +// #include <linux/vs_memory.h>
26346  
26347  #include <asm/io.h>
26348  #include <asm/pgalloc.h>
26349 @@ -647,6 +648,9 @@ static int copy_pte_range(struct mm_stru
26350         int progress = 0;
26351         int rss[2];
26352  
26353 +       if (!vx_rss_avail(dst_mm, ((end - addr)/PAGE_SIZE + 1)))
26354 +               return -ENOMEM;
26355 +
26356  again:
26357         rss[1] = rss[0] = 0;
26358         dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr, &dst_ptl);
26359 @@ -2680,6 +2684,9 @@ static int do_anonymous_page(struct mm_s
26360  
26361         pte_unmap(page_table);
26362  
26363 +       if (!vx_rss_avail(mm, 1))
26364 +               goto oom;
26365 +
26366         /* Check if we need to add a guard page to the stack */
26367         if (check_stack_guard_page(vma, address) < 0)
26368                 return VM_FAULT_SIGBUS;
26369 @@ -2986,6 +2993,7 @@ static inline int handle_pte_fault(struc
26370  {
26371         pte_t entry;
26372         spinlock_t *ptl;
26373 +       int ret = 0, type = VXPT_UNKNOWN;
26374  
26375         entry = *pte;
26376         if (!pte_present(entry)) {
26377 @@ -3010,9 +3018,12 @@ static inline int handle_pte_fault(struc
26378         if (unlikely(!pte_same(*pte, entry)))
26379                 goto unlock;
26380         if (flags & FAULT_FLAG_WRITE) {
26381 -               if (!pte_write(entry))
26382 -                       return do_wp_page(mm, vma, address,
26383 +               if (!pte_write(entry)) {
26384 +                       ret = do_wp_page(mm, vma, address,
26385                                         pte, pmd, ptl, entry);
26386 +                       type = VXPT_WRITE;
26387 +                       goto out;
26388 +               }
26389                 entry = pte_mkdirty(entry);
26390         }
26391         entry = pte_mkyoung(entry);
26392 @@ -3030,7 +3041,10 @@ static inline int handle_pte_fault(struc
26393         }
26394  unlock:
26395         pte_unmap_unlock(pte, ptl);
26396 -       return 0;
26397 +       ret = 0;
26398 +out:
26399 +       vx_page_fault(mm, vma, type, ret);
26400 +       return ret;
26401  }
26402  
26403  /*
26404 diff -NurpP --minimal linux-2.6.32.56/mm/mlock.c linux-2.6.32.56-vs2.3.0.36.29.9/mm/mlock.c
26405 --- linux-2.6.32.56/mm/mlock.c  2012-02-09 10:22:36.000000000 +0100
26406 +++ linux-2.6.32.56-vs2.3.0.36.29.9/mm/mlock.c  2011-06-10 13:03:02.000000000 +0200
26407 @@ -18,6 +18,7 @@
26408  #include <linux/rmap.h>
26409  #include <linux/mmzone.h>
26410  #include <linux/hugetlb.h>
26411 +#include <linux/vs_memory.h>
26412  
26413  #include "internal.h"
26414  
26415 @@ -414,7 +415,7 @@ success:
26416         nr_pages = (end - start) >> PAGE_SHIFT;
26417         if (!lock)
26418                 nr_pages = -nr_pages;
26419 -       mm->locked_vm += nr_pages;
26420 +       vx_vmlocked_add(mm, nr_pages);
26421  
26422         /*
26423          * vm_flags is protected by the mmap_sem held in write mode.
26424 @@ -487,7 +488,7 @@ static int do_mlock(unsigned long start,
26425  
26426  SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
26427  {
26428 -       unsigned long locked;
26429 +       unsigned long locked, grow;
26430         unsigned long lock_limit;
26431         int error = -ENOMEM;
26432  
26433 @@ -500,8 +501,10 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
26434         len = PAGE_ALIGN(len + (start & ~PAGE_MASK));
26435         start &= PAGE_MASK;
26436  
26437 -       locked = len >> PAGE_SHIFT;
26438 -       locked += current->mm->locked_vm;
26439 +       grow = len >> PAGE_SHIFT;
26440 +       if (!vx_vmlocked_avail(current->mm, grow))
26441 +               goto out;
26442 +       locked = current->mm->locked_vm + grow;
26443  
26444         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
26445         lock_limit >>= PAGE_SHIFT;
26446 @@ -509,6 +512,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
26447         /* check against resource limits */
26448         if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
26449                 error = do_mlock(start, len, 1);
26450 +out:
26451         up_write(&current->mm->mmap_sem);
26452         return error;
26453  }
26454 @@ -570,6 +574,8 @@ SYSCALL_DEFINE1(mlockall, int, flags)
26455         lock_limit >>= PAGE_SHIFT;
26456  
26457         ret = -ENOMEM;
26458 +       if (!vx_vmlocked_avail(current->mm, current->mm->total_vm))
26459 +               goto out;
26460         if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
26461             capable(CAP_IPC_LOCK))
26462                 ret = do_mlockall(flags);
26463 @@ -644,8 +650,10 @@ int account_locked_memory(struct mm_stru
26464         if (lim < vm)
26465                 goto out;
26466  
26467 -       mm->total_vm  += pgsz;
26468 -       mm->locked_vm += pgsz;
26469 +       // mm->total_vm  += pgsz;
26470 +       vx_vmpages_add(mm, pgsz);
26471 +       // mm->locked_vm += pgsz;
26472 +       vx_vmlocked_add(mm, pgsz);
26473  
26474         error = 0;
26475   out:
26476 @@ -659,8 +667,10 @@ void refund_locked_memory(struct mm_stru
26477  
26478         down_write(&mm->mmap_sem);
26479  
26480 -       mm->total_vm  -= pgsz;
26481 -       mm->locked_vm -= pgsz;
26482 +       // mm->total_vm  -= pgsz;
26483 +       vx_vmpages_sub(mm, pgsz);
26484 +       // mm->locked_vm -= pgsz;
26485 +       vx_vmlocked_sub(mm, pgsz);
26486  
26487         up_write(&mm->mmap_sem);
26488  }
26489 diff -NurpP --minimal linux-2.6.32.56/mm/mmap.c linux-2.6.32.56-vs2.3.0.36.29.9/mm/mmap.c
26490 --- linux-2.6.32.56/mm/mmap.c   2012-02-09 10:22:36.000000000 +0100
26491 +++ linux-2.6.32.56-vs2.3.0.36.29.9/mm/mmap.c   2011-11-17 12:18:26.000000000 +0100
26492 @@ -1224,7 +1224,8 @@ munmap_back:
26493  out:
26494         perf_event_mmap(vma);
26495  
26496 -       mm->total_vm += len >> PAGE_SHIFT;
26497 +       // mm->total_vm += len >> PAGE_SHIFT;
26498 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26499         vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
26500         if (vm_flags & VM_LOCKED) {
26501                 /*
26502 @@ -1233,7 +1234,8 @@ out:
26503                 long nr_pages = mlock_vma_pages_range(vma, addr, addr + len);
26504                 if (nr_pages < 0)
26505                         return nr_pages;        /* vma gone! */
26506 -               mm->locked_vm += (len >> PAGE_SHIFT) - nr_pages;
26507 +               // mm->locked_vm += (len >> PAGE_SHIFT) - nr_pages;
26508 +               vx_vmlocked_add(mm, (len >> PAGE_SHIFT) - nr_pages);
26509         } else if ((flags & MAP_POPULATE) && !(flags & MAP_NONBLOCK))
26510                 make_pages_present(addr, addr + len);
26511         return addr;
26512 @@ -1588,9 +1590,9 @@ static int acct_stack_growth(struct vm_a
26513                 return -ENOMEM;
26514  
26515         /* Ok, everything looks good - let it rip */
26516 -       mm->total_vm += grow;
26517 +       vx_vmpages_add(mm, grow);
26518         if (vma->vm_flags & VM_LOCKED)
26519 -               mm->locked_vm += grow;
26520 +               vx_vmlocked_add(mm, grow);
26521         vm_stat_account(mm, vma->vm_flags, vma->vm_file, grow);
26522         return 0;
26523  }
26524 @@ -1768,7 +1770,8 @@ static void remove_vma_list(struct mm_st
26525         do {
26526                 long nrpages = vma_pages(vma);
26527  
26528 -               mm->total_vm -= nrpages;
26529 +               // mm->total_vm -= nrpages;
26530 +               vx_vmpages_sub(mm, nrpages);
26531                 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
26532                 vma = remove_vma(vma);
26533         } while (vma);
26534 @@ -1943,7 +1946,8 @@ int do_munmap(struct mm_struct *mm, unsi
26535                 struct vm_area_struct *tmp = vma;
26536                 while (tmp && tmp->vm_start < end) {
26537                         if (tmp->vm_flags & VM_LOCKED) {
26538 -                               mm->locked_vm -= vma_pages(tmp);
26539 +                               // mm->locked_vm -= vma_pages(tmp);
26540 +                               vx_vmlocked_sub(mm, vma_pages(tmp));
26541                                 munlock_vma_pages_all(tmp);
26542                         }
26543                         tmp = tmp->vm_next;
26544 @@ -2026,6 +2030,8 @@ unsigned long do_brk(unsigned long addr,
26545                 lock_limit >>= PAGE_SHIFT;
26546                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
26547                         return -EAGAIN;
26548 +               if (!vx_vmlocked_avail(mm, len >> PAGE_SHIFT))
26549 +                       return -ENOMEM;
26550         }
26551  
26552         /*
26553 @@ -2052,7 +2058,8 @@ unsigned long do_brk(unsigned long addr,
26554         if (mm->map_count > sysctl_max_map_count)
26555                 return -ENOMEM;
26556  
26557 -       if (security_vm_enough_memory(len >> PAGE_SHIFT))
26558 +       if (security_vm_enough_memory(len >> PAGE_SHIFT) ||
26559 +               !vx_vmpages_avail(mm, len >> PAGE_SHIFT))
26560                 return -ENOMEM;
26561  
26562         /* Can we just expand an old private anonymous mapping? */
26563 @@ -2078,10 +2085,13 @@ unsigned long do_brk(unsigned long addr,
26564         vma->vm_page_prot = vm_get_page_prot(flags);
26565         vma_link(mm, vma, prev, rb_link, rb_parent);
26566  out:
26567 -       mm->total_vm += len >> PAGE_SHIFT;
26568 +       // mm->total_vm += len >> PAGE_SHIFT;
26569 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26570 +
26571         if (flags & VM_LOCKED) {
26572                 if (!mlock_vma_pages_range(vma, addr, addr + len))
26573 -                       mm->locked_vm += (len >> PAGE_SHIFT);
26574 +                       // mm->locked_vm += (len >> PAGE_SHIFT);
26575 +                       vx_vmlocked_add(mm, len >> PAGE_SHIFT);
26576         }
26577         return addr;
26578  }
26579 @@ -2125,6 +2135,11 @@ void exit_mmap(struct mm_struct *mm)
26580         free_pgtables(tlb, vma, FIRST_USER_ADDRESS, 0);
26581         tlb_finish_mmu(tlb, 0, end);
26582  
26583 +       set_mm_counter(mm, file_rss, 0);
26584 +       set_mm_counter(mm, anon_rss, 0);
26585 +       vx_vmpages_sub(mm, mm->total_vm);
26586 +       vx_vmlocked_sub(mm, mm->locked_vm);
26587 +
26588         /*
26589          * Walk the list again, actually closing and freeing it,
26590          * with preemption enabled, without holding any MM locks.
26591 @@ -2164,7 +2179,8 @@ int insert_vm_struct(struct mm_struct * 
26592         if (__vma && __vma->vm_start < vma->vm_end)
26593                 return -ENOMEM;
26594         if ((vma->vm_flags & VM_ACCOUNT) &&
26595 -            security_vm_enough_memory_mm(mm, vma_pages(vma)))
26596 +               (security_vm_enough_memory_mm(mm, vma_pages(vma)) ||
26597 +               !vx_vmpages_avail(mm, vma_pages(vma))))
26598                 return -ENOMEM;
26599         vma_link(mm, vma, prev, rb_link, rb_parent);
26600         return 0;
26601 @@ -2240,6 +2256,8 @@ int may_expand_vm(struct mm_struct *mm, 
26602  
26603         if (cur + npages > lim)
26604                 return 0;
26605 +       if (!vx_vmpages_avail(mm, npages))
26606 +               return 0;
26607         return 1;
26608  }
26609  
26610 @@ -2321,7 +2339,7 @@ int install_special_mapping(struct mm_st
26611         if (ret)
26612                 goto out;
26613  
26614 -       mm->total_vm += len >> PAGE_SHIFT;
26615 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26616  
26617         perf_event_mmap(vma);
26618  
26619 diff -NurpP --minimal linux-2.6.32.56/mm/mremap.c linux-2.6.32.56-vs2.3.0.36.29.9/mm/mremap.c
26620 --- linux-2.6.32.56/mm/mremap.c 2012-02-09 10:22:36.000000000 +0100
26621 +++ linux-2.6.32.56-vs2.3.0.36.29.9/mm/mremap.c 2011-06-10 13:03:02.000000000 +0200
26622 @@ -20,6 +20,7 @@
26623  #include <linux/security.h>
26624  #include <linux/syscalls.h>
26625  #include <linux/mmu_notifier.h>
26626 +#include <linux/vs_memory.h>
26627  
26628  #include <asm/uaccess.h>
26629  #include <asm/cacheflush.h>
26630 @@ -232,7 +233,7 @@ static unsigned long move_vma(struct vm_
26631          * If this were a serious issue, we'd add a flag to do_munmap().
26632          */
26633         hiwater_vm = mm->hiwater_vm;
26634 -       mm->total_vm += new_len >> PAGE_SHIFT;
26635 +       vx_vmpages_add(mm, new_len >> PAGE_SHIFT);
26636         vm_stat_account(mm, vma->vm_flags, vma->vm_file, new_len>>PAGE_SHIFT);
26637  
26638         if (do_munmap(mm, old_addr, old_len) < 0) {
26639 @@ -250,7 +251,7 @@ static unsigned long move_vma(struct vm_
26640         }
26641  
26642         if (vm_flags & VM_LOCKED) {
26643 -               mm->locked_vm += new_len >> PAGE_SHIFT;
26644 +               vx_vmlocked_add(mm, new_len >> PAGE_SHIFT);
26645                 if (new_len > old_len)
26646                         mlock_vma_pages_range(new_vma, new_addr + old_len,
26647                                                        new_addr + new_len);
26648 @@ -468,10 +469,12 @@ unsigned long do_mremap(unsigned long ad
26649                         vma_adjust(vma, vma->vm_start,
26650                                 addr + new_len, vma->vm_pgoff, NULL);
26651  
26652 -                       mm->total_vm += pages;
26653 +                       // mm->total_vm += pages;
26654 +                       vx_vmpages_add(mm, pages);
26655                         vm_stat_account(mm, vma->vm_flags, vma->vm_file, pages);
26656                         if (vma->vm_flags & VM_LOCKED) {
26657 -                               mm->locked_vm += pages;
26658 +                               // mm->locked_vm += pages;
26659 +                               vx_vmlocked_add(mm, pages);
26660                                 mlock_vma_pages_range(vma, addr + old_len,
26661                                                    addr + new_len);
26662                         }
26663 diff -NurpP --minimal linux-2.6.32.56/mm/nommu.c linux-2.6.32.56-vs2.3.0.36.29.9/mm/nommu.c
26664 --- linux-2.6.32.56/mm/nommu.c  2012-02-09 10:22:36.000000000 +0100
26665 +++ linux-2.6.32.56-vs2.3.0.36.29.9/mm/nommu.c  2011-06-10 13:03:02.000000000 +0200
26666 @@ -1349,7 +1349,7 @@ unsigned long do_mmap_pgoff(struct file 
26667         /* okay... we have a mapping; now we have to register it */
26668         result = vma->vm_start;
26669  
26670 -       current->mm->total_vm += len >> PAGE_SHIFT;
26671 +       vx_vmpages_add(current->mm, len >> PAGE_SHIFT);
26672  
26673  share:
26674         add_vma_to_mm(current->mm, vma);
26675 @@ -1609,7 +1609,7 @@ void exit_mmap(struct mm_struct *mm)
26676  
26677         kenter("");
26678  
26679 -       mm->total_vm = 0;
26680 +       vx_vmpages_sub(mm, mm->total_vm);
26681  
26682         while ((vma = mm->mmap)) {
26683                 mm->mmap = vma->vm_next;
26684 diff -NurpP --minimal linux-2.6.32.56/mm/oom_kill.c linux-2.6.32.56-vs2.3.0.36.29.9/mm/oom_kill.c
26685 --- linux-2.6.32.56/mm/oom_kill.c       2012-02-09 10:22:36.000000000 +0100
26686 +++ linux-2.6.32.56-vs2.3.0.36.29.9/mm/oom_kill.c       2011-06-10 13:03:02.000000000 +0200
26687 @@ -27,6 +27,9 @@
26688  #include <linux/notifier.h>
26689  #include <linux/memcontrol.h>
26690  #include <linux/security.h>
26691 +#include <linux/reboot.h>
26692 +#include <linux/vs_memory.h>
26693 +#include <linux/vs_context.h>
26694  
26695  int sysctl_panic_on_oom;
26696  int sysctl_oom_kill_allocating_task;
26697 @@ -186,9 +189,21 @@ unsigned long badness(struct task_struct
26698                         points >>= -(oom_adj);
26699         }
26700  
26701 +       /*
26702 +        * add points for context badness and
26703 +        * reduce badness for processes belonging to
26704 +        * a different context
26705 +        */
26706 +
26707 +       points += vx_badness(p, mm);
26708 +
26709 +       if ((vx_current_xid() > 1) &&
26710 +               vx_current_xid() != vx_task_xid(p))
26711 +               points /= 16;
26712 +
26713  #ifdef DEBUG
26714 -       printk(KERN_DEBUG "OOMkill: task %d (%s) got %lu points\n",
26715 -       p->pid, p->comm, points);
26716 +       printk(KERN_DEBUG "OOMkill: task %d:#%u (%s) got %d points\n",
26717 +               task_pid_nr(p), p->xid, p->comm, points);
26718  #endif
26719         return points;
26720  }
26721 @@ -230,6 +245,7 @@ static struct task_struct *select_bad_pr
26722         struct task_struct *p;
26723         struct task_struct *chosen = NULL;
26724         struct timespec uptime;
26725 +       unsigned xid = vx_current_xid();
26726         *ppoints = 0;
26727  
26728         do_posix_clock_monotonic_gettime(&uptime);
26729 @@ -242,11 +258,14 @@ static struct task_struct *select_bad_pr
26730                  */
26731                 if (!p->mm)
26732                         continue;
26733 -               /* skip the init task */
26734 -               if (is_global_init(p))
26735 +               /* skip the init task, global and per guest */
26736 +               if (task_is_init(p))
26737                         continue;
26738                 if (mem && !task_in_mem_cgroup(p, mem))
26739                         continue;
26740 +               /* skip other guest and host processes if oom in guest */
26741 +               if (xid && vx_task_xid(p) != xid)
26742 +                       continue;
26743  
26744                 /*
26745                  * This task already has access to memory reserves and is
26746 @@ -357,8 +376,8 @@ static void __oom_kill_task(struct task_
26747         }
26748  
26749         if (verbose)
26750 -               printk(KERN_ERR "Killed process %d (%s)\n",
26751 -                               task_pid_nr(p), p->comm);
26752 +               printk(KERN_ERR "Killed process %s(%d:#%u)\n",
26753 +                       p->comm, task_pid_nr(p), p->xid);
26754  
26755         /*
26756          * We give our sacrificial lamb high priority and access to
26757 @@ -419,8 +438,8 @@ static int oom_kill_process(struct task_
26758                 return 0;
26759         }
26760  
26761 -       printk(KERN_ERR "%s: kill process %d (%s) score %li or a child\n",
26762 -                                       message, task_pid_nr(p), p->comm, points);
26763 +       printk(KERN_ERR "%s: kill process %s(%d:#%u) score %li or a child\n",
26764 +               message, p->comm, task_pid_nr(p), p->xid, points);
26765  
26766         /* Try to kill a child first */
26767         list_for_each_entry(c, &p->children, sibling) {
26768 @@ -521,6 +540,8 @@ void clear_zonelist_oom(struct zonelist 
26769         spin_unlock(&zone_scan_lock);
26770  }
26771  
26772 +long vs_oom_action(unsigned int);
26773 +
26774  /*
26775   * Must be called with tasklist_lock held for read.
26776   */
26777 @@ -546,7 +567,11 @@ retry:
26778         /* Found nothing?!?! Either we hang forever, or we panic. */
26779         if (!p) {
26780                 read_unlock(&tasklist_lock);
26781 -               panic("Out of memory and no killable processes...\n");
26782 +               /* avoid panic for guest OOM */
26783 +               if (current->xid)
26784 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
26785 +               else
26786 +                       panic("Out of memory and no killable processes...\n");
26787         }
26788  
26789         if (oom_kill_process(p, gfp_mask, order, points, NULL,
26790 diff -NurpP --minimal linux-2.6.32.56/mm/page_alloc.c linux-2.6.32.56-vs2.3.0.36.29.9/mm/page_alloc.c
26791 --- linux-2.6.32.56/mm/page_alloc.c     2012-02-09 10:22:36.000000000 +0100
26792 +++ linux-2.6.32.56-vs2.3.0.36.29.9/mm/page_alloc.c     2011-08-08 22:40:36.000000000 +0200
26793 @@ -48,6 +48,8 @@
26794  #include <linux/page_cgroup.h>
26795  #include <linux/debugobjects.h>
26796  #include <linux/kmemleak.h>
26797 +#include <linux/vs_base.h>
26798 +#include <linux/vs_limit.h>
26799  #include <trace/events/kmem.h>
26800  
26801  #include <asm/tlbflush.h>
26802 @@ -2144,6 +2146,9 @@ void si_meminfo(struct sysinfo *val)
26803         val->totalhigh = totalhigh_pages;
26804         val->freehigh = nr_free_highpages();
26805         val->mem_unit = PAGE_SIZE;
26806 +
26807 +       if (vx_flags(VXF_VIRT_MEM, 0))
26808 +               vx_vsi_meminfo(val);
26809  }
26810  
26811  EXPORT_SYMBOL(si_meminfo);
26812 @@ -2164,6 +2169,9 @@ void si_meminfo_node(struct sysinfo *val
26813         val->freehigh = 0;
26814  #endif
26815         val->mem_unit = PAGE_SIZE;
26816 +
26817 +       if (vx_flags(VXF_VIRT_MEM, 0))
26818 +               vx_vsi_meminfo(val);
26819  }
26820  #endif
26821  
26822 diff -NurpP --minimal linux-2.6.32.56/mm/rmap.c linux-2.6.32.56-vs2.3.0.36.29.9/mm/rmap.c
26823 --- linux-2.6.32.56/mm/rmap.c   2009-12-03 20:02:58.000000000 +0100
26824 +++ linux-2.6.32.56-vs2.3.0.36.29.9/mm/rmap.c   2011-06-10 13:03:02.000000000 +0200
26825 @@ -55,6 +55,7 @@
26826  #include <linux/memcontrol.h>
26827  #include <linux/mmu_notifier.h>
26828  #include <linux/migrate.h>
26829 +#include <linux/vs_memory.h>
26830  
26831  #include <asm/tlbflush.h>
26832  
26833 diff -NurpP --minimal linux-2.6.32.56/mm/shmem.c linux-2.6.32.56-vs2.3.0.36.29.9/mm/shmem.c
26834 --- linux-2.6.32.56/mm/shmem.c  2012-02-09 10:22:36.000000000 +0100
26835 +++ linux-2.6.32.56-vs2.3.0.36.29.9/mm/shmem.c  2011-06-10 13:03:02.000000000 +0200
26836 @@ -1781,7 +1781,7 @@ static int shmem_statfs(struct dentry *d
26837  {
26838         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
26839  
26840 -       buf->f_type = TMPFS_MAGIC;
26841 +       buf->f_type = TMPFS_SUPER_MAGIC;
26842         buf->f_bsize = PAGE_CACHE_SIZE;
26843         buf->f_namelen = NAME_MAX;
26844         spin_lock(&sbinfo->stat_lock);
26845 @@ -2346,7 +2346,7 @@ int shmem_fill_super(struct super_block 
26846         sb->s_maxbytes = SHMEM_MAX_BYTES;
26847         sb->s_blocksize = PAGE_CACHE_SIZE;
26848         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
26849 -       sb->s_magic = TMPFS_MAGIC;
26850 +       sb->s_magic = TMPFS_SUPER_MAGIC;
26851         sb->s_op = &shmem_ops;
26852         sb->s_time_gran = 1;
26853  #ifdef CONFIG_TMPFS_POSIX_ACL
26854 diff -NurpP --minimal linux-2.6.32.56/mm/slab.c linux-2.6.32.56-vs2.3.0.36.29.9/mm/slab.c
26855 --- linux-2.6.32.56/mm/slab.c   2012-02-09 10:22:36.000000000 +0100
26856 +++ linux-2.6.32.56-vs2.3.0.36.29.9/mm/slab.c   2011-06-10 13:03:02.000000000 +0200
26857 @@ -431,6 +431,8 @@ static void kmem_list3_init(struct kmem_
26858  #define STATS_INC_FREEMISS(x)  do { } while (0)
26859  #endif
26860  
26861 +#include "slab_vs.h"
26862 +
26863  #if DEBUG
26864  
26865  /*
26866 @@ -3251,6 +3253,7 @@ retry:
26867  
26868         obj = slab_get_obj(cachep, slabp, nodeid);
26869         check_slabp(cachep, slabp);
26870 +       vx_slab_alloc(cachep, flags);
26871         l3->free_objects--;
26872         /* move slabp to correct slabp list: */
26873         list_del(&slabp->list);
26874 @@ -3327,6 +3330,7 @@ __cache_alloc_node(struct kmem_cache *ca
26875         /* ___cache_alloc_node can fall back to other nodes */
26876         ptr = ____cache_alloc_node(cachep, flags, nodeid);
26877    out:
26878 +       vx_slab_alloc(cachep, flags);
26879         local_irq_restore(save_flags);
26880         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
26881         kmemleak_alloc_recursive(ptr, obj_size(cachep), 1, cachep->flags,
26882 @@ -3513,6 +3517,7 @@ static inline void __cache_free(struct k
26883         check_irq_off();
26884         kmemleak_free_recursive(objp, cachep->flags);
26885         objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
26886 +       vx_slab_free(cachep);
26887  
26888         kmemcheck_slab_free(cachep, objp, obj_size(cachep));
26889  
26890 diff -NurpP --minimal linux-2.6.32.56/mm/slab_vs.h linux-2.6.32.56-vs2.3.0.36.29.9/mm/slab_vs.h
26891 --- linux-2.6.32.56/mm/slab_vs.h        1970-01-01 01:00:00.000000000 +0100
26892 +++ linux-2.6.32.56-vs2.3.0.36.29.9/mm/slab_vs.h        2011-06-10 13:03:02.000000000 +0200
26893 @@ -0,0 +1,29 @@
26894 +
26895 +#include <linux/vserver/context.h>
26896 +
26897 +#include <linux/vs_context.h>
26898 +
26899 +static inline
26900 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
26901 +{
26902 +       int what = gfp_zone(cachep->gfpflags);
26903 +       struct vx_info *vxi = current_vx_info();
26904 +
26905 +       if (!vxi)
26906 +               return;
26907 +
26908 +       atomic_add(cachep->buffer_size, &vxi->cacct.slab[what]);
26909 +}
26910 +
26911 +static inline
26912 +void vx_slab_free(struct kmem_cache *cachep)
26913 +{
26914 +       int what = gfp_zone(cachep->gfpflags);
26915 +       struct vx_info *vxi = current_vx_info();
26916 +
26917 +       if (!vxi)
26918 +               return;
26919 +
26920 +       atomic_sub(cachep->buffer_size, &vxi->cacct.slab[what]);
26921 +}
26922 +
26923 diff -NurpP --minimal linux-2.6.32.56/mm/swapfile.c linux-2.6.32.56-vs2.3.0.36.29.9/mm/swapfile.c
26924 --- linux-2.6.32.56/mm/swapfile.c       2012-02-09 10:22:36.000000000 +0100
26925 +++ linux-2.6.32.56-vs2.3.0.36.29.9/mm/swapfile.c       2011-06-10 13:03:02.000000000 +0200
26926 @@ -34,6 +34,8 @@
26927  #include <asm/tlbflush.h>
26928  #include <linux/swapops.h>
26929  #include <linux/page_cgroup.h>
26930 +#include <linux/vs_base.h>
26931 +#include <linux/vs_memory.h>
26932  
26933  static DEFINE_SPINLOCK(swap_lock);
26934  static unsigned int nr_swapfiles;
26935 @@ -1682,6 +1684,8 @@ static void *swap_next(struct seq_file *
26936         if (v == SEQ_START_TOKEN)
26937                 ptr = swap_info;
26938         else {
26939 +               if (vx_flags(VXF_VIRT_MEM, 0))
26940 +                       return NULL;
26941                 ptr = v;
26942                 ptr++;
26943         }
26944 @@ -1709,6 +1713,16 @@ static int swap_show(struct seq_file *sw
26945  
26946         if (ptr == SEQ_START_TOKEN) {
26947                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
26948 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
26949 +                       struct sysinfo si;
26950 +
26951 +                       vx_vsi_swapinfo(&si);
26952 +                       if (si.totalswap < (1 << 10))
26953 +                               return 0;
26954 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
26955 +                               "hdv0", "partition", si.totalswap >> 10,
26956 +                               (si.totalswap - si.freeswap) >> 10, -1);
26957 +               }
26958                 return 0;
26959         }
26960  
26961 @@ -2066,6 +2080,8 @@ void si_swapinfo(struct sysinfo *val)
26962         val->freeswap = nr_swap_pages + nr_to_be_unused;
26963         val->totalswap = total_swap_pages + nr_to_be_unused;
26964         spin_unlock(&swap_lock);
26965 +       if (vx_flags(VXF_VIRT_MEM, 0))
26966 +               vx_vsi_swapinfo(val);
26967  }
26968  
26969  /*
26970 diff -NurpP --minimal linux-2.6.32.56/net/core/dev.c linux-2.6.32.56-vs2.3.0.36.29.9/net/core/dev.c
26971 --- linux-2.6.32.56/net/core/dev.c      2012-02-09 10:22:37.000000000 +0100
26972 +++ linux-2.6.32.56-vs2.3.0.36.29.9/net/core/dev.c      2012-01-10 09:18:12.000000000 +0100
26973 @@ -126,6 +126,7 @@
26974  #include <linux/in.h>
26975  #include <linux/jhash.h>
26976  #include <linux/random.h>
26977 +#include <linux/vs_inet.h>
26978  #include <trace/events/napi.h>
26979  
26980  #include "net-sysfs.h"
26981 @@ -591,7 +592,8 @@ struct net_device *__dev_get_by_name(str
26982         hlist_for_each(p, dev_name_hash(net, name)) {
26983                 struct net_device *dev
26984                         = hlist_entry(p, struct net_device, name_hlist);
26985 -               if (!strncmp(dev->name, name, IFNAMSIZ))
26986 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
26987 +                   nx_dev_visible(current_nx_info(), dev))
26988                         return dev;
26989         }
26990         return NULL;
26991 @@ -642,7 +644,8 @@ struct net_device *__dev_get_by_index(st
26992         hlist_for_each(p, dev_index_hash(net, ifindex)) {
26993                 struct net_device *dev
26994                         = hlist_entry(p, struct net_device, index_hlist);
26995 -               if (dev->ifindex == ifindex)
26996 +               if ((dev->ifindex == ifindex) &&
26997 +                   nx_dev_visible(current_nx_info(), dev))
26998                         return dev;
26999         }
27000         return NULL;
27001 @@ -695,10 +698,12 @@ struct net_device *dev_getbyhwaddr(struc
27002  
27003         ASSERT_RTNL();
27004  
27005 -       for_each_netdev(net, dev)
27006 +       for_each_netdev(net, dev) {
27007                 if (dev->type == type &&
27008 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
27009 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
27010 +                   nx_dev_visible(current_nx_info(), dev))
27011                         return dev;
27012 +       }
27013  
27014         return NULL;
27015  }
27016 @@ -709,9 +714,11 @@ struct net_device *__dev_getfirstbyhwtyp
27017         struct net_device *dev;
27018  
27019         ASSERT_RTNL();
27020 -       for_each_netdev(net, dev)
27021 -               if (dev->type == type)
27022 +       for_each_netdev(net, dev) {
27023 +               if ((dev->type == type) &&
27024 +                   nx_dev_visible(current_nx_info(), dev))
27025                         return dev;
27026 +       }
27027  
27028         return NULL;
27029  }
27030 @@ -830,6 +837,8 @@ static int __dev_alloc_name(struct net *
27031                                 continue;
27032                         if (i < 0 || i >= max_netdevices)
27033                                 continue;
27034 +                       if (!nx_dev_visible(current_nx_info(), d))
27035 +                               continue;
27036  
27037                         /*  avoid cases where sscanf is not exact inverse of printf */
27038                         snprintf(buf, IFNAMSIZ, name, i);
27039 @@ -3003,6 +3012,8 @@ static int dev_ifconf(struct net *net, c
27040  
27041         total = 0;
27042         for_each_netdev(net, dev) {
27043 +               if (!nx_dev_visible(current_nx_info(), dev))
27044 +                       continue;
27045                 for (i = 0; i < NPROTO; i++) {
27046                         if (gifconf_list[i]) {
27047                                 int done;
27048 @@ -3071,6 +3082,9 @@ static void dev_seq_printf_stats(struct 
27049  {
27050         const struct net_device_stats *stats = dev_get_stats(dev);
27051  
27052 +       if (!nx_dev_visible(current_nx_info(), dev))
27053 +               return;
27054 +
27055         seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
27056                    "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
27057                    dev->name, stats->rx_bytes, stats->rx_packets,
27058 @@ -5336,7 +5350,6 @@ int dev_change_net_namespace(struct net_
27059         if (dev->dev.parent)
27060                 goto out;
27061  #endif
27062 -
27063         /* Ensure the device has been registrered */
27064         err = -EINVAL;
27065         if (dev->reg_state != NETREG_REGISTERED)
27066 diff -NurpP --minimal linux-2.6.32.56/net/core/rtnetlink.c linux-2.6.32.56-vs2.3.0.36.29.9/net/core/rtnetlink.c
27067 --- linux-2.6.32.56/net/core/rtnetlink.c        2012-02-09 10:22:37.000000000 +0100
27068 +++ linux-2.6.32.56-vs2.3.0.36.29.9/net/core/rtnetlink.c        2011-06-10 13:03:02.000000000 +0200
27069 @@ -688,6 +688,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
27070  
27071         idx = 0;
27072         for_each_netdev(net, dev) {
27073 +               if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
27074 +                       continue;
27075                 if (idx < s_idx)
27076                         goto cont;
27077                 if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
27078 @@ -1222,6 +1224,9 @@ void rtmsg_ifinfo(int type, struct net_d
27079         struct sk_buff *skb;
27080         int err = -ENOBUFS;
27081  
27082 +       if (!nx_dev_visible(current_nx_info(), dev))
27083 +               return;
27084 +
27085         skb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL);
27086         if (skb == NULL)
27087                 goto errout;
27088 diff -NurpP --minimal linux-2.6.32.56/net/core/sock.c linux-2.6.32.56-vs2.3.0.36.29.9/net/core/sock.c
27089 --- linux-2.6.32.56/net/core/sock.c     2012-02-09 10:22:37.000000000 +0100
27090 +++ linux-2.6.32.56-vs2.3.0.36.29.9/net/core/sock.c     2011-06-10 13:03:02.000000000 +0200
27091 @@ -125,6 +125,10 @@
27092  #include <linux/ipsec.h>
27093  
27094  #include <linux/filter.h>
27095 +#include <linux/vs_socket.h>
27096 +#include <linux/vs_limit.h>
27097 +#include <linux/vs_context.h>
27098 +#include <linux/vs_network.h>
27099  
27100  #ifdef CONFIG_INET
27101  #include <net/tcp.h>
27102 @@ -984,6 +988,8 @@ static struct sock *sk_prot_alloc(struct
27103                 if (!try_module_get(prot->owner))
27104                         goto out_free_sec;
27105         }
27106 +               sock_vx_init(sk);
27107 +               sock_nx_init(sk);
27108  
27109         return sk;
27110  
27111 @@ -1063,6 +1069,11 @@ static void __sk_free(struct sock *sk)
27112                        __func__, atomic_read(&sk->sk_omem_alloc));
27113  
27114         put_net(sock_net(sk));
27115 +       vx_sock_dec(sk);
27116 +       clr_vx_info(&sk->sk_vx_info);
27117 +       sk->sk_xid = -1;
27118 +       clr_nx_info(&sk->sk_nx_info);
27119 +       sk->sk_nid = -1;
27120         sk_prot_free(sk->sk_prot_creator, sk);
27121  }
27122  
27123 @@ -1110,6 +1121,8 @@ struct sock *sk_clone(const struct sock 
27124  
27125                 /* SANITY */
27126                 get_net(sock_net(newsk));
27127 +               sock_vx_init(newsk);
27128 +               sock_nx_init(newsk);
27129                 sk_node_init(&newsk->sk_node);
27130                 sock_lock_init(newsk);
27131                 bh_lock_sock(newsk);
27132 @@ -1164,6 +1177,12 @@ struct sock *sk_clone(const struct sock 
27133                 smp_wmb();
27134                 atomic_set(&newsk->sk_refcnt, 2);
27135  
27136 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
27137 +               newsk->sk_xid = sk->sk_xid;
27138 +               vx_sock_inc(newsk);
27139 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
27140 +               newsk->sk_nid = sk->sk_nid;
27141 +
27142                 /*
27143                  * Increment the counter in the same struct proto as the master
27144                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
27145 @@ -1886,6 +1905,12 @@ void sock_init_data(struct socket *sock,
27146  
27147         sk->sk_stamp = ktime_set(-1L, 0);
27148  
27149 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
27150 +       sk->sk_xid = vx_current_xid();
27151 +       vx_sock_inc(sk);
27152 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
27153 +       sk->sk_nid = nx_current_nid();
27154 +
27155         /*
27156          * Before updating sk_refcnt, we must commit prior changes to memory
27157          * (Documentation/RCU/rculist_nulls.txt for details)
27158 diff -NurpP --minimal linux-2.6.32.56/net/ipv4/af_inet.c linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv4/af_inet.c
27159 --- linux-2.6.32.56/net/ipv4/af_inet.c  2012-02-09 10:22:37.000000000 +0100
27160 +++ linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv4/af_inet.c  2011-08-08 22:42:21.000000000 +0200
27161 @@ -115,6 +115,7 @@
27162  #ifdef CONFIG_IP_MROUTE
27163  #include <linux/mroute.h>
27164  #endif
27165 +#include <linux/vs_limit.h>
27166  
27167  
27168  /* The inetsw table contains everything that inet_create needs to
27169 @@ -325,9 +326,12 @@ lookup_protocol:
27170         }
27171  
27172         err = -EPERM;
27173 +       if ((protocol == IPPROTO_ICMP) &&
27174 +               nx_capable(answer->capability, NXC_RAW_ICMP))
27175 +               goto override;
27176         if (answer->capability > 0 && !capable(answer->capability))
27177                 goto out_rcu_unlock;
27178 -
27179 +override:
27180         err = -EAFNOSUPPORT;
27181         if (!inet_netns_ok(net, protocol))
27182                 goto out_rcu_unlock;
27183 @@ -447,6 +451,7 @@ int inet_bind(struct socket *sock, struc
27184         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
27185         struct sock *sk = sock->sk;
27186         struct inet_sock *inet = inet_sk(sk);
27187 +       struct nx_v4_sock_addr nsa;
27188         unsigned short snum;
27189         int chk_addr_ret;
27190         int err;
27191 @@ -463,7 +468,11 @@ int inet_bind(struct socket *sock, struc
27192         if (addr->sin_family != AF_INET)
27193                 goto out;
27194  
27195 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
27196 +       err = v4_map_sock_addr(inet, addr, &nsa);
27197 +       if (err)
27198 +               goto out;
27199 +
27200 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
27201  
27202         /* Not specified by any standard per-se, however it breaks too
27203          * many applications when removed.  It is unfortunate since
27204 @@ -475,7 +484,7 @@ int inet_bind(struct socket *sock, struc
27205         err = -EADDRNOTAVAIL;
27206         if (!sysctl_ip_nonlocal_bind &&
27207             !(inet->freebind || inet->transparent) &&
27208 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
27209 +           nsa.saddr != htonl(INADDR_ANY) &&
27210             chk_addr_ret != RTN_LOCAL &&
27211             chk_addr_ret != RTN_MULTICAST &&
27212             chk_addr_ret != RTN_BROADCAST)
27213 @@ -500,7 +509,7 @@ int inet_bind(struct socket *sock, struc
27214         if (sk->sk_state != TCP_CLOSE || inet->num)
27215                 goto out_release_sock;
27216  
27217 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
27218 +       v4_set_sock_addr(inet, &nsa);
27219         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
27220                 inet->saddr = 0;  /* Use device */
27221  
27222 @@ -697,11 +706,13 @@ int inet_getname(struct socket *sock, st
27223                      peer == 1))
27224                         return -ENOTCONN;
27225                 sin->sin_port = inet->dport;
27226 -               sin->sin_addr.s_addr = inet->daddr;
27227 +               sin->sin_addr.s_addr =
27228 +                       nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
27229         } else {
27230                 __be32 addr = inet->rcv_saddr;
27231                 if (!addr)
27232                         addr = inet->saddr;
27233 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
27234                 sin->sin_port = inet->sport;
27235                 sin->sin_addr.s_addr = addr;
27236         }
27237 diff -NurpP --minimal linux-2.6.32.56/net/ipv4/devinet.c linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv4/devinet.c
27238 --- linux-2.6.32.56/net/ipv4/devinet.c  2012-02-09 10:22:37.000000000 +0100
27239 +++ linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv4/devinet.c  2011-06-10 13:03:02.000000000 +0200
27240 @@ -413,6 +413,7 @@ struct in_device *inetdev_by_index(struc
27241         return in_dev;
27242  }
27243  
27244 +
27245  /* Called only from RTNL semaphored context. No locks. */
27246  
27247  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
27248 @@ -653,6 +654,8 @@ int devinet_ioctl(struct net *net, unsig
27249                 *colon = ':';
27250  
27251         if ((in_dev = __in_dev_get_rtnl(dev)) != NULL) {
27252 +               struct nx_info *nxi = current_nx_info();
27253 +
27254                 if (tryaddrmatch) {
27255                         /* Matthias Andree */
27256                         /* compare label and address (4.4BSD style) */
27257 @@ -661,6 +664,8 @@ int devinet_ioctl(struct net *net, unsig
27258                            This is checked above. */
27259                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
27260                              ifap = &ifa->ifa_next) {
27261 +                               if (!nx_v4_ifa_visible(nxi, ifa))
27262 +                                       continue;
27263                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
27264                                     sin_orig.sin_addr.s_addr ==
27265                                                         ifa->ifa_address) {
27266 @@ -673,9 +678,12 @@ int devinet_ioctl(struct net *net, unsig
27267                    comparing just the label */
27268                 if (!ifa) {
27269                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
27270 -                            ifap = &ifa->ifa_next)
27271 +                            ifap = &ifa->ifa_next) {
27272 +                               if (!nx_v4_ifa_visible(nxi, ifa))
27273 +                                       continue;
27274                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
27275                                         break;
27276 +                       }
27277                 }
27278         }
27279  
27280 @@ -826,6 +834,8 @@ static int inet_gifconf(struct net_devic
27281                 goto out;
27282  
27283         for (; ifa; ifa = ifa->ifa_next) {
27284 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
27285 +                       continue;
27286                 if (!buf) {
27287                         done += sizeof(ifr);
27288                         continue;
27289 @@ -1185,6 +1195,7 @@ static int inet_dump_ifaddr(struct sk_bu
27290         struct net_device *dev;
27291         struct in_device *in_dev;
27292         struct in_ifaddr *ifa;
27293 +       struct sock *sk = skb->sk;
27294         int s_ip_idx, s_idx = cb->args[0];
27295  
27296         s_ip_idx = ip_idx = cb->args[1];
27297 @@ -1199,6 +1210,8 @@ static int inet_dump_ifaddr(struct sk_bu
27298  
27299                 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
27300                      ifa = ifa->ifa_next, ip_idx++) {
27301 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
27302 +                               continue;
27303                         if (ip_idx < s_ip_idx)
27304                                 continue;
27305                         if (inet_fill_ifaddr(skb, ifa, NETLINK_CB(cb->skb).pid,
27306 diff -NurpP --minimal linux-2.6.32.56/net/ipv4/fib_hash.c linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv4/fib_hash.c
27307 --- linux-2.6.32.56/net/ipv4/fib_hash.c 2009-09-10 15:26:29.000000000 +0200
27308 +++ linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv4/fib_hash.c 2011-06-10 13:03:02.000000000 +0200
27309 @@ -1021,7 +1021,7 @@ static int fib_seq_show(struct seq_file 
27310         prefix  = f->fn_key;
27311         mask    = FZ_MASK(iter->zone);
27312         flags   = fib_flag_trans(fa->fa_type, mask, fi);
27313 -       if (fi)
27314 +       if (fi && nx_dev_visible(current_nx_info(), fi->fib_dev))
27315                 seq_printf(seq,
27316                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u%n",
27317                          fi->fib_dev ? fi->fib_dev->name : "*", prefix,
27318 diff -NurpP --minimal linux-2.6.32.56/net/ipv4/inet_connection_sock.c linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv4/inet_connection_sock.c
27319 --- linux-2.6.32.56/net/ipv4/inet_connection_sock.c     2009-12-03 20:02:59.000000000 +0100
27320 +++ linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv4/inet_connection_sock.c     2011-06-10 13:03:02.000000000 +0200
27321 @@ -49,10 +49,40 @@ void inet_get_local_port_range(int *low,
27322  }
27323  EXPORT_SYMBOL(inet_get_local_port_range);
27324  
27325 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
27326 +{
27327 +       __be32  sk1_rcv_saddr = inet_rcv_saddr(sk1),
27328 +               sk2_rcv_saddr = inet_rcv_saddr(sk2);
27329 +
27330 +       if (inet_v6_ipv6only(sk2))
27331 +               return 0;
27332 +
27333 +       if (sk1_rcv_saddr &&
27334 +           sk2_rcv_saddr &&
27335 +           sk1_rcv_saddr == sk2_rcv_saddr)
27336 +               return 1;
27337 +
27338 +       if (sk1_rcv_saddr &&
27339 +           !sk2_rcv_saddr &&
27340 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
27341 +               return 1;
27342 +
27343 +       if (sk2_rcv_saddr &&
27344 +           !sk1_rcv_saddr &&
27345 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
27346 +               return 1;
27347 +
27348 +       if (!sk1_rcv_saddr &&
27349 +           !sk2_rcv_saddr &&
27350 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
27351 +               return 1;
27352 +
27353 +       return 0;
27354 +}
27355 +
27356  int inet_csk_bind_conflict(const struct sock *sk,
27357                            const struct inet_bind_bucket *tb)
27358  {
27359 -       const __be32 sk_rcv_saddr = inet_rcv_saddr(sk);
27360         struct sock *sk2;
27361         struct hlist_node *node;
27362         int reuse = sk->sk_reuse;
27363 @@ -72,9 +102,7 @@ int inet_csk_bind_conflict(const struct 
27364                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
27365                         if (!reuse || !sk2->sk_reuse ||
27366                             sk2->sk_state == TCP_LISTEN) {
27367 -                               const __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
27368 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr ||
27369 -                                   sk2_rcv_saddr == sk_rcv_saddr)
27370 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
27371                                         break;
27372                         }
27373                 }
27374 diff -NurpP --minimal linux-2.6.32.56/net/ipv4/inet_diag.c linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv4/inet_diag.c
27375 --- linux-2.6.32.56/net/ipv4/inet_diag.c        2012-02-09 10:22:37.000000000 +0100
27376 +++ linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv4/inet_diag.c        2011-08-08 22:40:36.000000000 +0200
27377 @@ -32,6 +32,8 @@
27378  #include <linux/stddef.h>
27379  
27380  #include <linux/inet_diag.h>
27381 +#include <linux/vs_network.h>
27382 +#include <linux/vs_inet.h>
27383  
27384  static const struct inet_diag_handler **inet_diag_table;
27385  
27386 @@ -118,8 +120,8 @@ static int inet_csk_diag_fill(struct soc
27387  
27388         r->id.idiag_sport = inet->sport;
27389         r->id.idiag_dport = inet->dport;
27390 -       r->id.idiag_src[0] = inet->rcv_saddr;
27391 -       r->id.idiag_dst[0] = inet->daddr;
27392 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, inet->rcv_saddr);
27393 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
27394  
27395  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
27396         if (r->idiag_family == AF_INET6) {
27397 @@ -204,8 +206,8 @@ static int inet_twsk_diag_fill(struct in
27398         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
27399         r->id.idiag_sport     = tw->tw_sport;
27400         r->id.idiag_dport     = tw->tw_dport;
27401 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
27402 -       r->id.idiag_dst[0]    = tw->tw_daddr;
27403 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
27404 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
27405         r->idiag_state        = tw->tw_substate;
27406         r->idiag_timer        = 3;
27407         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
27408 @@ -262,6 +264,7 @@ static int inet_diag_get_exact(struct sk
27409         err = -EINVAL;
27410  
27411         if (req->idiag_family == AF_INET) {
27412 +               /* TODO: lback */
27413                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
27414                                  req->id.idiag_dport, req->id.idiag_src[0],
27415                                  req->id.idiag_sport, req->id.idiag_if);
27416 @@ -504,6 +507,7 @@ static int inet_csk_diag_dump(struct soc
27417                 } else
27418  #endif
27419                 {
27420 +                       /* TODO: lback */
27421                         entry.saddr = &inet->rcv_saddr;
27422                         entry.daddr = &inet->daddr;
27423                 }
27424 @@ -542,6 +546,7 @@ static int inet_twsk_diag_dump(struct in
27425                 } else
27426  #endif
27427                 {
27428 +                       /* TODO: lback */
27429                         entry.saddr = &tw->tw_rcv_saddr;
27430                         entry.daddr = &tw->tw_daddr;
27431                 }
27432 @@ -588,8 +593,8 @@ static int inet_diag_fill_req(struct sk_
27433  
27434         r->id.idiag_sport = inet->sport;
27435         r->id.idiag_dport = ireq->rmt_port;
27436 -       r->id.idiag_src[0] = ireq->loc_addr;
27437 -       r->id.idiag_dst[0] = ireq->rmt_addr;
27438 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
27439 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
27440         r->idiag_expires = jiffies_to_msecs(tmo);
27441         r->idiag_rqueue = 0;
27442         r->idiag_wqueue = 0;
27443 @@ -660,6 +665,7 @@ static int inet_diag_dump_reqs(struct sk
27444                                 continue;
27445  
27446                         if (bc) {
27447 +                               /* TODO: lback */
27448                                 entry.saddr =
27449  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
27450                                         (entry.family == AF_INET6) ?
27451 @@ -730,6 +736,8 @@ static int inet_diag_dump(struct sk_buff
27452                         sk_nulls_for_each(sk, node, &ilb->head) {
27453                                 struct inet_sock *inet = inet_sk(sk);
27454  
27455 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27456 +                                       continue;
27457                                 if (num < s_num) {
27458                                         num++;
27459                                         continue;
27460 @@ -796,6 +804,8 @@ skip_listen_ht:
27461                 sk_nulls_for_each(sk, node, &head->chain) {
27462                         struct inet_sock *inet = inet_sk(sk);
27463  
27464 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27465 +                               continue;
27466                         if (num < s_num)
27467                                 goto next_normal;
27468                         if (!(r->idiag_states & (1 << sk->sk_state)))
27469 @@ -820,6 +830,8 @@ next_normal:
27470                         inet_twsk_for_each(tw, node,
27471                                     &head->twchain) {
27472  
27473 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
27474 +                                       continue;
27475                                 if (num < s_num)
27476                                         goto next_dying;
27477                                 if (r->id.idiag_sport != tw->tw_sport &&
27478 diff -NurpP --minimal linux-2.6.32.56/net/ipv4/inet_hashtables.c linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv4/inet_hashtables.c
27479 --- linux-2.6.32.56/net/ipv4/inet_hashtables.c  2012-02-09 10:22:37.000000000 +0100
27480 +++ linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv4/inet_hashtables.c  2011-11-17 12:19:00.000000000 +0100
27481 @@ -22,6 +22,7 @@
27482  #include <net/inet_connection_sock.h>
27483  #include <net/inet_hashtables.h>
27484  #include <net/secure_seq.h>
27485 +#include <net/route.h>
27486  #include <net/ip.h>
27487  
27488  /*
27489 @@ -135,6 +136,11 @@ static inline int compute_score(struct s
27490                         if (rcv_saddr != daddr)
27491                                 return -1;
27492                         score += 2;
27493 +               } else {
27494 +                       /* block non nx_info ips */
27495 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
27496 +                               daddr, NXA_MASK_BIND))
27497 +                               return -1;
27498                 }
27499                 if (sk->sk_bound_dev_if) {
27500                         if (sk->sk_bound_dev_if != dif)
27501 @@ -152,7 +158,6 @@ static inline int compute_score(struct s
27502   * wildcarded during the search since they can never be otherwise.
27503   */
27504  
27505 -
27506  struct sock *__inet_lookup_listener(struct net *net,
27507                                     struct inet_hashinfo *hashinfo,
27508                                     const __be32 daddr, const unsigned short hnum,
27509 @@ -175,6 +180,7 @@ begin:
27510                         hiscore = score;
27511                 }
27512         }
27513 +
27514         /*
27515          * if the nulls value we got at the end of this lookup is
27516          * not the expected one, we must restart lookup.
27517 diff -NurpP --minimal linux-2.6.32.56/net/ipv4/netfilter/nf_nat_helper.c linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv4/netfilter/nf_nat_helper.c
27518 --- linux-2.6.32.56/net/ipv4/netfilter/nf_nat_helper.c  2009-12-03 20:02:59.000000000 +0100
27519 +++ linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv4/netfilter/nf_nat_helper.c  2011-06-10 13:03:02.000000000 +0200
27520 @@ -19,6 +19,7 @@
27521  #include <net/route.h>
27522  
27523  #include <linux/netfilter_ipv4.h>
27524 +#include <net/route.h>
27525  #include <net/netfilter/nf_conntrack.h>
27526  #include <net/netfilter/nf_conntrack_helper.h>
27527  #include <net/netfilter/nf_conntrack_ecache.h>
27528 diff -NurpP --minimal linux-2.6.32.56/net/ipv4/netfilter.c linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv4/netfilter.c
27529 --- linux-2.6.32.56/net/ipv4/netfilter.c        2009-09-10 15:26:29.000000000 +0200
27530 +++ linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv4/netfilter.c        2011-06-10 13:03:02.000000000 +0200
27531 @@ -4,7 +4,7 @@
27532  #include <linux/netfilter_ipv4.h>
27533  #include <linux/ip.h>
27534  #include <linux/skbuff.h>
27535 -#include <net/route.h>
27536 +// #include <net/route.h>
27537  #include <net/xfrm.h>
27538  #include <net/ip.h>
27539  #include <net/netfilter/nf_queue.h>
27540 diff -NurpP --minimal linux-2.6.32.56/net/ipv4/raw.c linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv4/raw.c
27541 --- linux-2.6.32.56/net/ipv4/raw.c      2009-12-03 20:02:59.000000000 +0100
27542 +++ linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv4/raw.c      2011-06-10 13:03:02.000000000 +0200
27543 @@ -117,7 +117,7 @@ static struct sock *__raw_v4_lookup(stru
27544  
27545                 if (net_eq(sock_net(sk), net) && inet->num == num       &&
27546                     !(inet->daddr && inet->daddr != raddr)              &&
27547 -                   !(inet->rcv_saddr && inet->rcv_saddr != laddr)      &&
27548 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
27549                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
27550                         goto found; /* gotcha */
27551         }
27552 @@ -383,6 +383,12 @@ static int raw_send_hdrinc(struct sock *
27553                 icmp_out_count(net, ((struct icmphdr *)
27554                         skb_transport_header(skb))->type);
27555  
27556 +       err = -EPERM;
27557 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
27558 +               sk->sk_nx_info &&
27559 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
27560 +               goto error_free;
27561 +
27562         err = NF_HOOK(PF_INET, NF_INET_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
27563                       dst_output);
27564         if (err > 0)
27565 @@ -563,6 +569,13 @@ static int raw_sendmsg(struct kiocb *ioc
27566                 }
27567  
27568                 security_sk_classify_flow(sk, &fl);
27569 +               if (sk->sk_nx_info) {
27570 +                       err = ip_v4_find_src(sock_net(sk),
27571 +                               sk->sk_nx_info, &rt, &fl);
27572 +
27573 +                       if (err)
27574 +                               goto done;
27575 +               }
27576                 err = ip_route_output_flow(sock_net(sk), &rt, &fl, sk, 1);
27577         }
27578         if (err)
27579 @@ -635,17 +648,19 @@ static int raw_bind(struct sock *sk, str
27580  {
27581         struct inet_sock *inet = inet_sk(sk);
27582         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
27583 +       struct nx_v4_sock_addr nsa = { 0 };
27584         int ret = -EINVAL;
27585         int chk_addr_ret;
27586  
27587         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
27588                 goto out;
27589 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
27590 +       v4_map_sock_addr(inet, addr, &nsa);
27591 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
27592         ret = -EADDRNOTAVAIL;
27593 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
27594 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
27595             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
27596                 goto out;
27597 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
27598 +       v4_set_sock_addr(inet, &nsa);
27599         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
27600                 inet->saddr = 0;  /* Use device */
27601         sk_dst_reset(sk);
27602 @@ -697,7 +712,8 @@ static int raw_recvmsg(struct kiocb *ioc
27603         /* Copy the address. */
27604         if (sin) {
27605                 sin->sin_family = AF_INET;
27606 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
27607 +               sin->sin_addr.s_addr =
27608 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
27609                 sin->sin_port = 0;
27610                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
27611         }
27612 @@ -875,7 +891,8 @@ static struct sock *raw_get_first(struct
27613                 struct hlist_node *node;
27614  
27615                 sk_for_each(sk, node, &state->h->ht[state->bucket])
27616 -                       if (sock_net(sk) == seq_file_net(seq))
27617 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
27618 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27619                                 goto found;
27620         }
27621         sk = NULL;
27622 @@ -891,7 +908,8 @@ static struct sock *raw_get_next(struct 
27623                 sk = sk_next(sk);
27624  try_again:
27625                 ;
27626 -       } while (sk && sock_net(sk) != seq_file_net(seq));
27627 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
27628 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
27629  
27630         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
27631                 sk = sk_head(&state->h->ht[state->bucket]);
27632 @@ -950,7 +968,10 @@ static void raw_sock_seq_show(struct seq
27633  
27634         seq_printf(seq, "%4d: %08X:%04X %08X:%04X"
27635                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n",
27636 -               i, src, srcp, dest, destp, sp->sk_state,
27637 +               i,
27638 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27639 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27640 +               sp->sk_state,
27641                 sk_wmem_alloc_get(sp),
27642                 sk_rmem_alloc_get(sp),
27643                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
27644 diff -NurpP --minimal linux-2.6.32.56/net/ipv4/tcp.c linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv4/tcp.c
27645 --- linux-2.6.32.56/net/ipv4/tcp.c      2012-02-09 10:22:37.000000000 +0100
27646 +++ linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv4/tcp.c      2011-06-10 13:03:02.000000000 +0200
27647 @@ -264,6 +264,7 @@
27648  #include <linux/cache.h>
27649  #include <linux/err.h>
27650  #include <linux/crypto.h>
27651 +#include <linux/in.h>
27652  
27653  #include <net/icmp.h>
27654  #include <net/tcp.h>
27655 diff -NurpP --minimal linux-2.6.32.56/net/ipv4/tcp_ipv4.c linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv4/tcp_ipv4.c
27656 --- linux-2.6.32.56/net/ipv4/tcp_ipv4.c 2012-02-09 10:22:37.000000000 +0100
27657 +++ linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv4/tcp_ipv4.c 2011-11-17 12:18:26.000000000 +0100
27658 @@ -1926,6 +1926,12 @@ static void *listening_get_next(struct s
27659                 req = req->dl_next;
27660                 while (1) {
27661                         while (req) {
27662 +                               vxdprintk(VXD_CBIT(net, 6),
27663 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
27664 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
27665 +                               if (req->sk &&
27666 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
27667 +                                       continue;
27668                                 if (req->rsk_ops->family == st->family) {
27669                                         cur = req;
27670                                         goto out;
27671 @@ -1950,6 +1956,10 @@ get_req:
27672         }
27673  get_sk:
27674         sk_nulls_for_each_from(sk, node) {
27675 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
27676 +                       sk, sk->sk_nid, nx_current_nid());
27677 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27678 +                       continue;
27679                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net)) {
27680                         cur = sk;
27681                         goto out;
27682 @@ -2013,6 +2023,11 @@ static void *established_get_first(struc
27683  
27684                 spin_lock_bh(lock);
27685                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
27686 +                       vxdprintk(VXD_CBIT(net, 6),
27687 +                               "sk,egf: %p [#%d] (from %d)",
27688 +                               sk, sk->sk_nid, nx_current_nid());
27689 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27690 +                               continue;
27691                         if (sk->sk_family != st->family ||
27692                             !net_eq(sock_net(sk), net)) {
27693                                 continue;
27694 @@ -2023,6 +2038,11 @@ static void *established_get_first(struc
27695                 st->state = TCP_SEQ_STATE_TIME_WAIT;
27696                 inet_twsk_for_each(tw, node,
27697                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
27698 +                       vxdprintk(VXD_CBIT(net, 6),
27699 +                               "tw: %p [#%d] (from %d)",
27700 +                               tw, tw->tw_nid, nx_current_nid());
27701 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
27702 +                               continue;
27703                         if (tw->tw_family != st->family ||
27704                             !net_eq(twsk_net(tw), net)) {
27705                                 continue;
27706 @@ -2051,7 +2071,9 @@ static void *established_get_next(struct
27707                 tw = cur;
27708                 tw = tw_next(tw);
27709  get_tw:
27710 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
27711 +               while (tw && (tw->tw_family != st->family ||
27712 +                       !net_eq(twsk_net(tw), net) ||
27713 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
27714                         tw = tw_next(tw);
27715                 }
27716                 if (tw) {
27717 @@ -2074,6 +2096,11 @@ get_tw:
27718                 sk = sk_nulls_next(sk);
27719  
27720         sk_nulls_for_each_from(sk, node) {
27721 +               vxdprintk(VXD_CBIT(net, 6),
27722 +                       "sk,egn: %p [#%d] (from %d)",
27723 +                       sk, sk->sk_nid, nx_current_nid());
27724 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27725 +                       continue;
27726                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
27727                         goto found;
27728         }
27729 @@ -2225,9 +2252,9 @@ static void get_openreq4(struct sock *sk
27730         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
27731                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p%n",
27732                 i,
27733 -               ireq->loc_addr,
27734 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
27735                 ntohs(inet_sk(sk)->sport),
27736 -               ireq->rmt_addr,
27737 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
27738                 ntohs(ireq->rmt_port),
27739                 TCP_SYN_RECV,
27740                 0, 0, /* could print option size, but that is af dependent. */
27741 @@ -2270,7 +2297,10 @@ static void get_tcp4_sock(struct sock *s
27742  
27743         seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
27744                         "%08X %5d %8d %lu %d %p %lu %lu %u %u %d%n",
27745 -               i, src, srcp, dest, destp, sk->sk_state,
27746 +               i,
27747 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27748 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27749 +               sk->sk_state,
27750                 tp->write_seq - tp->snd_una,
27751                 sk->sk_state == TCP_LISTEN ? sk->sk_ack_backlog :
27752                                              (tp->rcv_nxt - tp->copied_seq),
27753 @@ -2306,7 +2336,10 @@ static void get_timewait4_sock(struct in
27754  
27755         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
27756                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
27757 -               i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
27758 +               i,
27759 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27760 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27761 +               tw->tw_substate, 0, 0,
27762                 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
27763                 atomic_read(&tw->tw_refcnt), tw, len);
27764  }
27765 diff -NurpP --minimal linux-2.6.32.56/net/ipv4/tcp_minisocks.c linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv4/tcp_minisocks.c
27766 --- linux-2.6.32.56/net/ipv4/tcp_minisocks.c    2009-12-03 20:03:00.000000000 +0100
27767 +++ linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv4/tcp_minisocks.c    2011-06-10 13:03:02.000000000 +0200
27768 @@ -26,6 +26,10 @@
27769  #include <net/inet_common.h>
27770  #include <net/xfrm.h>
27771  
27772 +#include <linux/vs_limit.h>
27773 +#include <linux/vs_socket.h>
27774 +#include <linux/vs_context.h>
27775 +
27776  #ifdef CONFIG_SYSCTL
27777  #define SYNC_INIT 0 /* let the user enable it */
27778  #else
27779 @@ -294,6 +298,11 @@ void tcp_time_wait(struct sock *sk, int 
27780                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
27781                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
27782  
27783 +               tw->tw_xid              = sk->sk_xid;
27784 +               tw->tw_vx_info          = NULL;
27785 +               tw->tw_nid              = sk->sk_nid;
27786 +               tw->tw_nx_info          = NULL;
27787 +
27788  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
27789                 if (tw->tw_family == PF_INET6) {
27790                         struct ipv6_pinfo *np = inet6_sk(sk);
27791 diff -NurpP --minimal linux-2.6.32.56/net/ipv4/udp.c linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv4/udp.c
27792 --- linux-2.6.32.56/net/ipv4/udp.c      2012-02-09 10:22:37.000000000 +0100
27793 +++ linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv4/udp.c      2011-08-08 22:40:36.000000000 +0200
27794 @@ -224,14 +224,7 @@ fail:
27795  }
27796  EXPORT_SYMBOL(udp_lib_get_port);
27797  
27798 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
27799 -{
27800 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
27801 -
27802 -       return  (!ipv6_only_sock(sk2)  &&
27803 -                (!inet1->rcv_saddr || !inet2->rcv_saddr ||
27804 -                  inet1->rcv_saddr == inet2->rcv_saddr));
27805 -}
27806 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
27807  
27808  int udp_v4_get_port(struct sock *sk, unsigned short snum)
27809  {
27810 @@ -253,6 +246,11 @@ static inline int compute_score(struct s
27811                         if (inet->rcv_saddr != daddr)
27812                                 return -1;
27813                         score += 2;
27814 +               } else {
27815 +                       /* block non nx_info ips */
27816 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
27817 +                               daddr, NXA_MASK_BIND))
27818 +                               return -1;
27819                 }
27820                 if (inet->daddr) {
27821                         if (inet->daddr != saddr)
27822 @@ -273,6 +271,7 @@ static inline int compute_score(struct s
27823         return score;
27824  }
27825  
27826 +
27827  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
27828   * harder than this. -DaveM
27829   */
27830 @@ -294,6 +293,11 @@ begin:
27831         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
27832                 score = compute_score(sk, net, saddr, hnum, sport,
27833                                       daddr, dport, dif);
27834 +               /* FIXME: disabled?
27835 +               if (score == 9) {
27836 +                       result = sk;
27837 +                       break;
27838 +               } else */
27839                 if (score > badness) {
27840                         result = sk;
27841                         badness = score;
27842 @@ -307,6 +311,7 @@ begin:
27843         if (get_nulls_value(node) != hash)
27844                 goto begin;
27845  
27846 +
27847         if (result) {
27848                 if (unlikely(!atomic_inc_not_zero(&result->sk_refcnt)))
27849                         result = NULL;
27850 @@ -316,6 +321,7 @@ begin:
27851                         goto begin;
27852                 }
27853         }
27854 +
27855         rcu_read_unlock();
27856         return result;
27857  }
27858 @@ -358,7 +364,7 @@ static inline struct sock *udp_v4_mcast_
27859                     s->sk_hash != hnum                                  ||
27860                     (inet->daddr && inet->daddr != rmt_addr)            ||
27861                     (inet->dport != rmt_port && inet->dport)            ||
27862 -                   (inet->rcv_saddr && inet->rcv_saddr != loc_addr)    ||
27863 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
27864                     ipv6_only_sock(s)                                   ||
27865                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
27866                         continue;
27867 @@ -707,8 +713,13 @@ int udp_sendmsg(struct kiocb *iocb, stru
27868                                                { .sport = inet->sport,
27869                                                  .dport = dport } } };
27870                 struct net *net = sock_net(sk);
27871 +               struct nx_info *nxi = sk->sk_nx_info;
27872  
27873                 security_sk_classify_flow(sk, &fl);
27874 +               err = ip_v4_find_src(net, nxi, &rt, &fl);
27875 +               if (err)
27876 +                       goto out;
27877 +
27878                 err = ip_route_output_flow(net, &rt, &fl, sk, 1);
27879                 if (err) {
27880                         if (err == -ENETUNREACH)
27881 @@ -988,7 +999,8 @@ try_again:
27882         if (sin) {
27883                 sin->sin_family = AF_INET;
27884                 sin->sin_port = udp_hdr(skb)->source;
27885 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
27886 +               sin->sin_addr.s_addr = nx_map_sock_lback(
27887 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
27888                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
27889         }
27890         if (inet->cmsg_flags)
27891 @@ -1630,6 +1642,8 @@ static struct sock *udp_get_first(struct
27892                 sk_nulls_for_each(sk, node, &hslot->head) {
27893                         if (!net_eq(sock_net(sk), net))
27894                                 continue;
27895 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27896 +                               continue;
27897                         if (sk->sk_family == state->family)
27898                                 goto found;
27899                 }
27900 @@ -1647,7 +1661,9 @@ static struct sock *udp_get_next(struct 
27901  
27902         do {
27903                 sk = sk_nulls_next(sk);
27904 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
27905 +       } while (sk && (!net_eq(sock_net(sk), net) ||
27906 +               sk->sk_family != state->family ||
27907 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
27908  
27909         if (!sk) {
27910                 if (state->bucket < UDP_HTABLE_SIZE)
27911 @@ -1754,7 +1770,10 @@ static void udp4_format_sock(struct sock
27912  
27913         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
27914                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d%n",
27915 -               bucket, src, srcp, dest, destp, sp->sk_state,
27916 +               bucket,
27917 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27918 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27919 +               sp->sk_state,
27920                 sk_wmem_alloc_get(sp),
27921                 sk_rmem_alloc_get(sp),
27922                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
27923 diff -NurpP --minimal linux-2.6.32.56/net/ipv6/Kconfig linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv6/Kconfig
27924 --- linux-2.6.32.56/net/ipv6/Kconfig    2009-09-10 15:26:30.000000000 +0200
27925 +++ linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv6/Kconfig    2011-06-10 13:03:02.000000000 +0200
27926 @@ -4,8 +4,8 @@
27927  
27928  #   IPv6 as module will cause a CRASH if you try to unload it
27929  menuconfig IPV6
27930 -       tristate "The IPv6 protocol"
27931 -       default m
27932 +       bool "The IPv6 protocol"
27933 +       default n
27934         ---help---
27935           This is complemental support for the IP version 6.
27936           You will still be able to do traditional IPv4 networking as well.
27937 diff -NurpP --minimal linux-2.6.32.56/net/ipv6/addrconf.c linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv6/addrconf.c
27938 --- linux-2.6.32.56/net/ipv6/addrconf.c 2012-02-09 10:22:37.000000000 +0100
27939 +++ linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv6/addrconf.c 2011-06-10 13:03:02.000000000 +0200
27940 @@ -86,6 +86,8 @@
27941  
27942  #include <linux/proc_fs.h>
27943  #include <linux/seq_file.h>
27944 +#include <linux/vs_network.h>
27945 +#include <linux/vs_inet6.h>
27946  
27947  /* Set to 3 to get tracing... */
27948  #define ACONF_DEBUG 2
27949 @@ -1119,7 +1121,7 @@ out:
27950  
27951  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
27952                        const struct in6_addr *daddr, unsigned int prefs,
27953 -                      struct in6_addr *saddr)
27954 +                      struct in6_addr *saddr, struct nx_info *nxi)
27955  {
27956         struct ipv6_saddr_score scores[2],
27957                                 *score = &scores[0], *hiscore = &scores[1];
27958 @@ -1192,6 +1194,8 @@ int ipv6_dev_get_saddr(struct net *net, 
27959                                                dev->name);
27960                                 continue;
27961                         }
27962 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
27963 +                               continue;
27964  
27965                         score->rule = -1;
27966                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
27967 @@ -3000,7 +3004,10 @@ static void if6_seq_stop(struct seq_file
27968  static int if6_seq_show(struct seq_file *seq, void *v)
27969  {
27970         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
27971 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
27972 +
27973 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
27974 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
27975 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
27976                    &ifp->addr,
27977                    ifp->idev->dev->ifindex,
27978                    ifp->prefix_len,
27979 @@ -3497,6 +3504,12 @@ static int inet6_dump_addr(struct sk_buf
27980         struct ifmcaddr6 *ifmca;
27981         struct ifacaddr6 *ifaca;
27982         struct net *net = sock_net(skb->sk);
27983 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
27984 +
27985 +       /* disable ipv6 on non v6 guests */
27986 +       if (nxi && !nx_info_has_v6(nxi))
27987 +               return skb->len;
27988 +
27989  
27990         s_idx = cb->args[0];
27991         s_ip_idx = ip_idx = cb->args[1];
27992 @@ -3518,6 +3531,8 @@ static int inet6_dump_addr(struct sk_buf
27993                              ifa = ifa->if_next, ip_idx++) {
27994                                 if (ip_idx < s_ip_idx)
27995                                         continue;
27996 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
27997 +                                       continue;
27998                                 err = inet6_fill_ifaddr(skb, ifa,
27999                                                         NETLINK_CB(cb->skb).pid,
28000                                                         cb->nlh->nlmsg_seq,
28001 @@ -3531,6 +3546,8 @@ static int inet6_dump_addr(struct sk_buf
28002                              ifmca = ifmca->next, ip_idx++) {
28003                                 if (ip_idx < s_ip_idx)
28004                                         continue;
28005 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
28006 +                                       continue;
28007                                 err = inet6_fill_ifmcaddr(skb, ifmca,
28008                                                           NETLINK_CB(cb->skb).pid,
28009                                                           cb->nlh->nlmsg_seq,
28010 @@ -3544,6 +3561,8 @@ static int inet6_dump_addr(struct sk_buf
28011                              ifaca = ifaca->aca_next, ip_idx++) {
28012                                 if (ip_idx < s_ip_idx)
28013                                         continue;
28014 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
28015 +                                       continue;
28016                                 err = inet6_fill_ifacaddr(skb, ifaca,
28017                                                           NETLINK_CB(cb->skb).pid,
28018                                                           cb->nlh->nlmsg_seq,
28019 @@ -3830,12 +3849,19 @@ static int inet6_dump_ifinfo(struct sk_b
28020         int s_idx = cb->args[0];
28021         struct net_device *dev;
28022         struct inet6_dev *idev;
28023 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
28024 +
28025 +       /* FIXME: maybe disable ipv6 on non v6 guests?
28026 +       if (skb->sk && skb->sk->sk_vx_info)
28027 +               return skb->len; */
28028  
28029         read_lock(&dev_base_lock);
28030         idx = 0;
28031         for_each_netdev(net, dev) {
28032                 if (idx < s_idx)
28033                         goto cont;
28034 +               if (!v6_dev_in_nx_info(dev, nxi))
28035 +                       goto cont;
28036                 if ((idev = in6_dev_get(dev)) == NULL)
28037                         goto cont;
28038                 err = inet6_fill_ifinfo(skb, idev, NETLINK_CB(cb->skb).pid,
28039 diff -NurpP --minimal linux-2.6.32.56/net/ipv6/af_inet6.c linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv6/af_inet6.c
28040 --- linux-2.6.32.56/net/ipv6/af_inet6.c 2009-12-03 20:03:00.000000000 +0100
28041 +++ linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv6/af_inet6.c 2011-06-10 13:03:02.000000000 +0200
28042 @@ -41,6 +41,8 @@
28043  #include <linux/netdevice.h>
28044  #include <linux/icmpv6.h>
28045  #include <linux/netfilter_ipv6.h>
28046 +#include <linux/vs_inet.h>
28047 +#include <linux/vs_inet6.h>
28048  
28049  #include <net/ip.h>
28050  #include <net/ipv6.h>
28051 @@ -158,9 +160,12 @@ lookup_protocol:
28052         }
28053  
28054         err = -EPERM;
28055 +       if ((protocol == IPPROTO_ICMPV6) &&
28056 +               nx_capable(answer->capability, NXC_RAW_ICMP))
28057 +               goto override;
28058         if (answer->capability > 0 && !capable(answer->capability))
28059                 goto out_rcu_unlock;
28060 -
28061 +override:
28062         sock->ops = answer->ops;
28063         answer_prot = answer->prot;
28064         answer_no_check = answer->no_check;
28065 @@ -259,6 +264,7 @@ int inet6_bind(struct socket *sock, stru
28066         struct inet_sock *inet = inet_sk(sk);
28067         struct ipv6_pinfo *np = inet6_sk(sk);
28068         struct net *net = sock_net(sk);
28069 +       struct nx_v6_sock_addr nsa;
28070         __be32 v4addr = 0;
28071         unsigned short snum;
28072         int addr_type = 0;
28073 @@ -270,6 +276,11 @@ int inet6_bind(struct socket *sock, stru
28074  
28075         if (addr_len < SIN6_LEN_RFC2133)
28076                 return -EINVAL;
28077 +
28078 +       err = v6_map_sock_addr(inet, addr, &nsa);
28079 +       if (err)
28080 +               return err;
28081 +
28082         addr_type = ipv6_addr_type(&addr->sin6_addr);
28083         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
28084                 return -EINVAL;
28085 @@ -301,6 +312,7 @@ int inet6_bind(struct socket *sock, stru
28086                 /* Reproduce AF_INET checks to make the bindings consitant */
28087                 v4addr = addr->sin6_addr.s6_addr32[3];
28088                 chk_addr_ret = inet_addr_type(net, v4addr);
28089 +
28090                 if (!sysctl_ip_nonlocal_bind &&
28091                     !(inet->freebind || inet->transparent) &&
28092                     v4addr != htonl(INADDR_ANY) &&
28093 @@ -310,6 +322,10 @@ int inet6_bind(struct socket *sock, stru
28094                         err = -EADDRNOTAVAIL;
28095                         goto out;
28096                 }
28097 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
28098 +                       err = -EADDRNOTAVAIL;
28099 +                       goto out;
28100 +               }
28101         } else {
28102                 if (addr_type != IPV6_ADDR_ANY) {
28103                         struct net_device *dev = NULL;
28104 @@ -335,6 +351,11 @@ int inet6_bind(struct socket *sock, stru
28105                                 }
28106                         }
28107  
28108 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
28109 +                               err = -EADDRNOTAVAIL;
28110 +                               goto out;
28111 +                       }
28112 +
28113                         /* ipv4 addr of the socket is invalid.  Only the
28114                          * unspecified and mapped address have a v4 equivalent.
28115                          */
28116 @@ -353,6 +374,8 @@ int inet6_bind(struct socket *sock, stru
28117                 }
28118         }
28119  
28120 +       v6_set_sock_addr(inet, &nsa);
28121 +
28122         inet->rcv_saddr = v4addr;
28123         inet->saddr = v4addr;
28124  
28125 @@ -448,9 +471,11 @@ int inet6_getname(struct socket *sock, s
28126                         return -ENOTCONN;
28127                 sin->sin6_port = inet->dport;
28128                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
28129 +               /* FIXME: remap lback? */
28130                 if (np->sndflow)
28131                         sin->sin6_flowinfo = np->flow_label;
28132         } else {
28133 +               /* FIXME: remap lback? */
28134                 if (ipv6_addr_any(&np->rcv_saddr))
28135                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
28136                 else
28137 diff -NurpP --minimal linux-2.6.32.56/net/ipv6/fib6_rules.c linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv6/fib6_rules.c
28138 --- linux-2.6.32.56/net/ipv6/fib6_rules.c       2009-09-10 15:26:30.000000000 +0200
28139 +++ linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv6/fib6_rules.c       2011-06-10 13:03:02.000000000 +0200
28140 @@ -96,7 +96,7 @@ static int fib6_rule_action(struct fib_r
28141                         if (ipv6_dev_get_saddr(net,
28142                                                ip6_dst_idev(&rt->u.dst)->dev,
28143                                                &flp->fl6_dst, srcprefs,
28144 -                                              &saddr))
28145 +                                              &saddr, NULL))
28146                                 goto again;
28147                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
28148                                                r->src.plen))
28149 diff -NurpP --minimal linux-2.6.32.56/net/ipv6/inet6_hashtables.c linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv6/inet6_hashtables.c
28150 --- linux-2.6.32.56/net/ipv6/inet6_hashtables.c 2012-02-09 10:22:37.000000000 +0100
28151 +++ linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv6/inet6_hashtables.c 2011-11-17 12:18:26.000000000 +0100
28152 @@ -16,6 +16,7 @@
28153  
28154  #include <linux/module.h>
28155  #include <linux/random.h>
28156 +#include <linux/vs_inet6.h>
28157  
28158  #include <net/inet_connection_sock.h>
28159  #include <net/inet_hashtables.h>
28160 @@ -77,7 +78,6 @@ struct sock *__inet6_lookup_established(
28161         unsigned int slot = hash & (hashinfo->ehash_size - 1);
28162         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
28163  
28164 -
28165         rcu_read_lock();
28166  begin:
28167         sk_nulls_for_each_rcu(sk, node, &head->chain) {
28168 @@ -89,7 +89,7 @@ begin:
28169                                 sock_put(sk);
28170                                 goto begin;
28171                         }
28172 -               goto out;
28173 +                       goto out;
28174                 }
28175         }
28176         if (get_nulls_value(node) != slot)
28177 @@ -135,6 +135,9 @@ static int inline compute_score(struct s
28178                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
28179                                 return -1;
28180                         score++;
28181 +               } else {
28182 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
28183 +                               return -1;
28184                 }
28185                 if (sk->sk_bound_dev_if) {
28186                         if (sk->sk_bound_dev_if != dif)
28187 diff -NurpP --minimal linux-2.6.32.56/net/ipv6/ip6_output.c linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv6/ip6_output.c
28188 --- linux-2.6.32.56/net/ipv6/ip6_output.c       2012-02-09 10:22:37.000000000 +0100
28189 +++ linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv6/ip6_output.c       2011-11-17 12:18:26.000000000 +0100
28190 @@ -942,7 +942,7 @@ static int ip6_dst_lookup_tail(struct so
28191                 err = ipv6_dev_get_saddr(net, ip6_dst_idev(*dst)->dev,
28192                                          &fl->fl6_dst,
28193                                          sk ? inet6_sk(sk)->srcprefs : 0,
28194 -                                        &fl->fl6_src);
28195 +                                        &fl->fl6_src, sk->sk_nx_info);
28196                 if (err)
28197                         goto out_err_release;
28198         }
28199 diff -NurpP --minimal linux-2.6.32.56/net/ipv6/ndisc.c linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv6/ndisc.c
28200 --- linux-2.6.32.56/net/ipv6/ndisc.c    2009-12-03 20:03:00.000000000 +0100
28201 +++ linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv6/ndisc.c    2011-06-10 13:03:02.000000000 +0200
28202 @@ -589,7 +589,7 @@ static void ndisc_send_na(struct net_dev
28203         } else {
28204                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
28205                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
28206 -                                      &tmpaddr))
28207 +                                      &tmpaddr, NULL /* FIXME: ? */ ))
28208                         return;
28209                 src_addr = &tmpaddr;
28210         }
28211 diff -NurpP --minimal linux-2.6.32.56/net/ipv6/raw.c linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv6/raw.c
28212 --- linux-2.6.32.56/net/ipv6/raw.c      2009-12-03 20:03:00.000000000 +0100
28213 +++ linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv6/raw.c      2011-06-10 13:03:02.000000000 +0200
28214 @@ -29,6 +29,7 @@
28215  #include <linux/icmpv6.h>
28216  #include <linux/netfilter.h>
28217  #include <linux/netfilter_ipv6.h>
28218 +#include <linux/vs_inet6.h>
28219  #include <linux/skbuff.h>
28220  #include <asm/uaccess.h>
28221  #include <asm/ioctls.h>
28222 @@ -281,6 +282,13 @@ static int rawv6_bind(struct sock *sk, s
28223                         }
28224                 }
28225  
28226 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
28227 +                       err = -EADDRNOTAVAIL;
28228 +                       if (dev)
28229 +                               dev_put(dev);
28230 +                       goto out;
28231 +               }
28232 +
28233                 /* ipv4 addr of the socket is invalid.  Only the
28234                  * unspecified and mapped address have a v4 equivalent.
28235                  */
28236 diff -NurpP --minimal linux-2.6.32.56/net/ipv6/route.c linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv6/route.c
28237 --- linux-2.6.32.56/net/ipv6/route.c    2012-02-09 10:22:37.000000000 +0100
28238 +++ linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv6/route.c    2011-06-10 13:03:02.000000000 +0200
28239 @@ -2277,7 +2277,8 @@ static int rt6_fill_node(struct net *net
28240                 struct inet6_dev *idev = ip6_dst_idev(&rt->u.dst);
28241                 struct in6_addr saddr_buf;
28242                 if (ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
28243 -                                      dst, 0, &saddr_buf) == 0)
28244 +                       dst, 0, &saddr_buf,
28245 +                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
28246                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
28247         }
28248  
28249 diff -NurpP --minimal linux-2.6.32.56/net/ipv6/tcp_ipv6.c linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv6/tcp_ipv6.c
28250 --- linux-2.6.32.56/net/ipv6/tcp_ipv6.c 2012-02-09 10:22:37.000000000 +0100
28251 +++ linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv6/tcp_ipv6.c 2011-11-17 12:18:26.000000000 +0100
28252 @@ -69,6 +69,7 @@
28253  
28254  #include <linux/crypto.h>
28255  #include <linux/scatterlist.h>
28256 +#include <linux/vs_inet6.h>
28257  
28258  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
28259  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
28260 @@ -157,8 +158,15 @@ static int tcp_v6_connect(struct sock *s
28261          *      connect() to INADDR_ANY means loopback (BSD'ism).
28262          */
28263  
28264 -       if(ipv6_addr_any(&usin->sin6_addr))
28265 -               usin->sin6_addr.s6_addr[15] = 0x1;
28266 +       if(ipv6_addr_any(&usin->sin6_addr)) {
28267 +               struct nx_info *nxi =  sk->sk_nx_info;
28268 +
28269 +               if (nxi && nx_info_has_v6(nxi))
28270 +                       /* FIXME: remap lback? */
28271 +                       usin->sin6_addr = nxi->v6.ip;
28272 +               else
28273 +                       usin->sin6_addr.s6_addr[15] = 0x1;
28274 +       }
28275  
28276         addr_type = ipv6_addr_type(&usin->sin6_addr);
28277  
28278 diff -NurpP --minimal linux-2.6.32.56/net/ipv6/udp.c linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv6/udp.c
28279 --- linux-2.6.32.56/net/ipv6/udp.c      2012-02-09 10:22:38.000000000 +0100
28280 +++ linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv6/udp.c      2012-01-10 09:18:12.000000000 +0100
28281 @@ -47,6 +47,7 @@
28282  
28283  #include <linux/proc_fs.h>
28284  #include <linux/seq_file.h>
28285 +#include <linux/vs_inet6.h>
28286  #include "udp_impl.h"
28287  
28288  int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
28289 @@ -61,24 +62,49 @@ int ipv6_rcv_saddr_equal(const struct so
28290         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
28291  
28292         /* if both are mapped, treat as IPv4 */
28293 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
28294 -               return (!sk2_ipv6only &&
28295 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
28296 +               if (!sk2_ipv6only &&
28297                         (!sk_rcv_saddr || !sk2_rcv_saddr ||
28298 -                         sk_rcv_saddr == sk2_rcv_saddr));
28299 +                         sk_rcv_saddr == sk2_rcv_saddr))
28300 +                       goto vs_v4;
28301 +               else
28302 +                       return 0;
28303 +       }
28304  
28305         if (addr_type2 == IPV6_ADDR_ANY &&
28306             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
28307 -               return 1;
28308 +               goto vs;
28309  
28310         if (addr_type == IPV6_ADDR_ANY &&
28311             !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
28312 -               return 1;
28313 +               goto vs;
28314  
28315         if (sk2_rcv_saddr6 &&
28316             ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
28317 -               return 1;
28318 +               goto vs;
28319  
28320         return 0;
28321 +
28322 +vs_v4:
28323 +       if (!sk_rcv_saddr && !sk2_rcv_saddr)
28324 +               return nx_v4_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info);
28325 +       if (!sk2_rcv_saddr)
28326 +               return v4_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr, -1);
28327 +       if (!sk_rcv_saddr)
28328 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr, -1);
28329 +       return 1;
28330 +vs:
28331 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
28332 +               return nx_v6_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info);
28333 +       else if (addr_type2 == IPV6_ADDR_ANY)
28334 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr6, -1);
28335 +       else if (addr_type == IPV6_ADDR_ANY) {
28336 +               if (addr_type2 == IPV6_ADDR_MAPPED)
28337 +                       return nx_v4_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info);
28338 +               else
28339 +                       return v6_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr6, -1);
28340 +       }
28341 +       return 1;
28342  }
28343  
28344  int udp_v6_get_port(struct sock *sk, unsigned short snum)
28345 @@ -109,6 +135,10 @@ static inline int compute_score(struct s
28346                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
28347                                 return -1;
28348                         score++;
28349 +               } else {
28350 +                       /* block non nx_info ips */
28351 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
28352 +                               return -1;
28353                 }
28354                 if (!ipv6_addr_any(&np->daddr)) {
28355                         if (!ipv6_addr_equal(&np->daddr, saddr))
28356 diff -NurpP --minimal linux-2.6.32.56/net/ipv6/xfrm6_policy.c linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv6/xfrm6_policy.c
28357 --- linux-2.6.32.56/net/ipv6/xfrm6_policy.c     2009-12-03 20:03:00.000000000 +0100
28358 +++ linux-2.6.32.56-vs2.3.0.36.29.9/net/ipv6/xfrm6_policy.c     2011-06-10 13:03:02.000000000 +0200
28359 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
28360         dev = ip6_dst_idev(dst)->dev;
28361         ipv6_dev_get_saddr(dev_net(dev), dev,
28362                            (struct in6_addr *)&daddr->a6, 0,
28363 -                          (struct in6_addr *)&saddr->a6);
28364 +                          (struct in6_addr *)&saddr->a6, NULL);
28365         dst_release(dst);
28366         return 0;
28367  }
28368 diff -NurpP --minimal linux-2.6.32.56/net/netlink/af_netlink.c linux-2.6.32.56-vs2.3.0.36.29.9/net/netlink/af_netlink.c
28369 --- linux-2.6.32.56/net/netlink/af_netlink.c    2012-02-09 10:22:38.000000000 +0100
28370 +++ linux-2.6.32.56-vs2.3.0.36.29.9/net/netlink/af_netlink.c    2011-06-10 13:03:02.000000000 +0200
28371 @@ -55,6 +55,9 @@
28372  #include <linux/types.h>
28373  #include <linux/audit.h>
28374  #include <linux/mutex.h>
28375 +#include <linux/vs_context.h>
28376 +#include <linux/vs_network.h>
28377 +#include <linux/vs_limit.h>
28378  
28379  #include <net/net_namespace.h>
28380  #include <net/sock.h>
28381 @@ -1885,6 +1888,8 @@ static struct sock *netlink_seq_socket_i
28382                         sk_for_each(s, node, &hash->table[j]) {
28383                                 if (sock_net(s) != seq_file_net(seq))
28384                                         continue;
28385 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
28386 +                                       continue;
28387                                 if (off == pos) {
28388                                         iter->link = i;
28389                                         iter->hash_idx = j;
28390 @@ -1919,7 +1924,8 @@ static void *netlink_seq_next(struct seq
28391         s = v;
28392         do {
28393                 s = sk_next(s);
28394 -       } while (s && sock_net(s) != seq_file_net(seq));
28395 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
28396 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
28397         if (s)
28398                 return s;
28399  
28400 @@ -1931,7 +1937,8 @@ static void *netlink_seq_next(struct seq
28401  
28402                 for (; j <= hash->mask; j++) {
28403                         s = sk_head(&hash->table[j]);
28404 -                       while (s && sock_net(s) != seq_file_net(seq))
28405 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
28406 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
28407                                 s = sk_next(s);
28408                         if (s) {
28409                                 iter->link = i;
28410 diff -NurpP --minimal linux-2.6.32.56/net/sctp/ipv6.c linux-2.6.32.56-vs2.3.0.36.29.9/net/sctp/ipv6.c
28411 --- linux-2.6.32.56/net/sctp/ipv6.c     2009-12-03 20:03:01.000000000 +0100
28412 +++ linux-2.6.32.56-vs2.3.0.36.29.9/net/sctp/ipv6.c     2011-06-10 13:03:02.000000000 +0200
28413 @@ -316,7 +316,8 @@ static void sctp_v6_get_saddr(struct sct
28414                                    dst ? ip6_dst_idev(dst)->dev : NULL,
28415                                    &daddr->v6.sin6_addr,
28416                                    inet6_sk(&sk->inet.sk)->srcprefs,
28417 -                                  &saddr->v6.sin6_addr);
28418 +                                  &saddr->v6.sin6_addr,
28419 +                                  asoc->base.sk->sk_nx_info);
28420                 SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: %pI6\n",
28421                                   &saddr->v6.sin6_addr);
28422                 return;
28423 diff -NurpP --minimal linux-2.6.32.56/net/socket.c linux-2.6.32.56-vs2.3.0.36.29.9/net/socket.c
28424 --- linux-2.6.32.56/net/socket.c        2012-02-09 10:22:38.000000000 +0100
28425 +++ linux-2.6.32.56-vs2.3.0.36.29.9/net/socket.c        2011-06-10 13:03:02.000000000 +0200
28426 @@ -96,6 +96,10 @@
28427  
28428  #include <net/sock.h>
28429  #include <linux/netfilter.h>
28430 +#include <linux/vs_base.h>
28431 +#include <linux/vs_socket.h>
28432 +#include <linux/vs_inet.h>
28433 +#include <linux/vs_inet6.h>
28434  
28435  static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
28436  static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
28437 @@ -559,7 +563,7 @@ static inline int __sock_sendmsg(struct 
28438                                  struct msghdr *msg, size_t size)
28439  {
28440         struct sock_iocb *si = kiocb_to_siocb(iocb);
28441 -       int err;
28442 +       int err, len;
28443  
28444         si->sock = sock;
28445         si->scm = NULL;
28446 @@ -570,7 +574,22 @@ static inline int __sock_sendmsg(struct 
28447         if (err)
28448                 return err;
28449  
28450 -       return sock->ops->sendmsg(iocb, sock, msg, size);
28451 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
28452 +       if (sock->sk) {
28453 +               if (len == size)
28454 +                       vx_sock_send(sock->sk, size);
28455 +               else
28456 +                       vx_sock_fail(sock->sk, size);
28457 +       }
28458 +       vxdprintk(VXD_CBIT(net, 7),
28459 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
28460 +               sock, sock->sk,
28461 +               (sock->sk)?sock->sk->sk_nx_info:0,
28462 +               (sock->sk)?sock->sk->sk_vx_info:0,
28463 +               (sock->sk)?sock->sk->sk_xid:0,
28464 +               (sock->sk)?sock->sk->sk_nid:0,
28465 +               (unsigned int)size, len);
28466 +       return len;
28467  }
28468  
28469  int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
28470 @@ -671,7 +690,7 @@ EXPORT_SYMBOL_GPL(__sock_recv_timestamp)
28471  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
28472                                  struct msghdr *msg, size_t size, int flags)
28473  {
28474 -       int err;
28475 +       int err, len;
28476         struct sock_iocb *si = kiocb_to_siocb(iocb);
28477  
28478         si->sock = sock;
28479 @@ -684,7 +703,18 @@ static inline int __sock_recvmsg(struct 
28480         if (err)
28481                 return err;
28482  
28483 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
28484 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
28485 +       if ((len >= 0) && sock->sk)
28486 +               vx_sock_recv(sock->sk, len);
28487 +       vxdprintk(VXD_CBIT(net, 7),
28488 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
28489 +               sock, sock->sk,
28490 +               (sock->sk)?sock->sk->sk_nx_info:0,
28491 +               (sock->sk)?sock->sk->sk_vx_info:0,
28492 +               (sock->sk)?sock->sk->sk_xid:0,
28493 +               (sock->sk)?sock->sk->sk_nid:0,
28494 +               (unsigned int)size, len);
28495 +       return len;
28496  }
28497  
28498  int sock_recvmsg(struct socket *sock, struct msghdr *msg,
28499 @@ -1155,6 +1185,13 @@ static int __sock_create(struct net *net
28500         if (type < 0 || type >= SOCK_MAX)
28501                 return -EINVAL;
28502  
28503 +       if (!nx_check(0, VS_ADMIN)) {
28504 +               if (family == PF_INET && !current_nx_info_has_v4())
28505 +                       return -EAFNOSUPPORT;
28506 +               if (family == PF_INET6 && !current_nx_info_has_v6())
28507 +                       return -EAFNOSUPPORT;
28508 +       }
28509 +
28510         /* Compatibility.
28511  
28512            This uglymoron is moved from INET layer to here to avoid
28513 @@ -1287,6 +1324,7 @@ SYSCALL_DEFINE3(socket, int, family, int
28514         if (retval < 0)
28515                 goto out;
28516  
28517 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
28518         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
28519         if (retval < 0)
28520                 goto out_release;
28521 @@ -1328,10 +1366,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
28522         err = sock_create(family, type, protocol, &sock1);
28523         if (err < 0)
28524                 goto out;
28525 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
28526  
28527         err = sock_create(family, type, protocol, &sock2);
28528         if (err < 0)
28529                 goto out_release_1;
28530 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
28531  
28532         err = sock1->ops->socketpair(sock1, sock2);
28533         if (err < 0)
28534 diff -NurpP --minimal linux-2.6.32.56/net/sunrpc/auth.c linux-2.6.32.56-vs2.3.0.36.29.9/net/sunrpc/auth.c
28535 --- linux-2.6.32.56/net/sunrpc/auth.c   2009-12-03 20:03:01.000000000 +0100
28536 +++ linux-2.6.32.56-vs2.3.0.36.29.9/net/sunrpc/auth.c   2011-06-10 13:03:02.000000000 +0200
28537 @@ -14,6 +14,7 @@
28538  #include <linux/hash.h>
28539  #include <linux/sunrpc/clnt.h>
28540  #include <linux/spinlock.h>
28541 +#include <linux/vs_tag.h>
28542  
28543  #ifdef RPC_DEBUG
28544  # define RPCDBG_FACILITY       RPCDBG_AUTH
28545 @@ -360,6 +361,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
28546         memset(&acred, 0, sizeof(acred));
28547         acred.uid = cred->fsuid;
28548         acred.gid = cred->fsgid;
28549 +       acred.tag = dx_current_tag();
28550         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
28551  
28552         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
28553 @@ -400,6 +402,7 @@ rpcauth_bind_root_cred(struct rpc_task *
28554         struct auth_cred acred = {
28555                 .uid = 0,
28556                 .gid = 0,
28557 +               .tag = dx_current_tag(),
28558         };
28559         struct rpc_cred *ret;
28560  
28561 diff -NurpP --minimal linux-2.6.32.56/net/sunrpc/auth_unix.c linux-2.6.32.56-vs2.3.0.36.29.9/net/sunrpc/auth_unix.c
28562 --- linux-2.6.32.56/net/sunrpc/auth_unix.c      2012-02-09 10:22:38.000000000 +0100
28563 +++ linux-2.6.32.56-vs2.3.0.36.29.9/net/sunrpc/auth_unix.c      2012-01-10 09:18:12.000000000 +0100
28564 @@ -11,12 +11,14 @@
28565  #include <linux/module.h>
28566  #include <linux/sunrpc/clnt.h>
28567  #include <linux/sunrpc/auth.h>
28568 +#include <linux/vs_tag.h>
28569  
28570  #define NFS_NGROUPS    16
28571  
28572  struct unx_cred {
28573         struct rpc_cred         uc_base;
28574         gid_t                   uc_gid;
28575 +       tag_t                   uc_tag;
28576         gid_t                   uc_gids[NFS_NGROUPS];
28577  };
28578  #define uc_uid                 uc_base.cr_uid
28579 @@ -78,6 +80,7 @@ unx_create_cred(struct rpc_auth *auth, s
28580                 groups = NFS_NGROUPS;
28581  
28582         cred->uc_gid = acred->gid;
28583 +       cred->uc_tag = acred->tag;
28584         for (i = 0; i < groups; i++)
28585                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
28586         if (i < NFS_NGROUPS)
28587 @@ -119,7 +122,9 @@ unx_match(struct auth_cred *acred, struc
28588         unsigned int i;
28589  
28590  
28591 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
28592 +       if (cred->uc_uid != acred->uid ||
28593 +               cred->uc_gid != acred->gid ||
28594 +               cred->uc_tag != acred->tag)
28595                 return 0;
28596  
28597         if (acred->group_info != NULL)
28598 @@ -145,7 +150,7 @@ unx_marshal(struct rpc_task *task, __be3
28599         struct rpc_clnt *clnt = task->tk_client;
28600         struct unx_cred *cred = container_of(task->tk_msg.rpc_cred, struct unx_cred, uc_base);
28601         __be32          *base, *hold;
28602 -       int             i;
28603 +       int             i, tag;
28604  
28605         *p++ = htonl(RPC_AUTH_UNIX);
28606         base = p++;
28607 @@ -155,9 +160,12 @@ unx_marshal(struct rpc_task *task, __be3
28608          * Copy the UTS nodename captured when the client was created.
28609          */
28610         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
28611 +       tag = task->tk_client->cl_tag;
28612  
28613 -       *p++ = htonl((u32) cred->uc_uid);
28614 -       *p++ = htonl((u32) cred->uc_gid);
28615 +       *p++ = htonl((u32) TAGINO_UID(tag,
28616 +               cred->uc_uid, cred->uc_tag));
28617 +       *p++ = htonl((u32) TAGINO_GID(tag,
28618 +               cred->uc_gid, cred->uc_tag));
28619         hold = p++;
28620         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
28621                 *p++ = htonl((u32) cred->uc_gids[i]);
28622 diff -NurpP --minimal linux-2.6.32.56/net/sunrpc/clnt.c linux-2.6.32.56-vs2.3.0.36.29.9/net/sunrpc/clnt.c
28623 --- linux-2.6.32.56/net/sunrpc/clnt.c   2012-02-09 10:22:38.000000000 +0100
28624 +++ linux-2.6.32.56-vs2.3.0.36.29.9/net/sunrpc/clnt.c   2011-11-17 12:18:26.000000000 +0100
28625 @@ -33,6 +33,7 @@
28626  #include <linux/utsname.h>
28627  #include <linux/workqueue.h>
28628  #include <linux/in6.h>
28629 +#include <linux/vs_cvirt.h>
28630  
28631  #include <linux/sunrpc/clnt.h>
28632  #include <linux/sunrpc/rpc_pipe_fs.h>
28633 @@ -358,6 +359,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
28634         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
28635                 clnt->cl_chatty = 1;
28636  
28637 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
28638 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
28639 +               clnt->cl_tag = 1; */
28640         return clnt;
28641  }
28642  EXPORT_SYMBOL_GPL(rpc_create);
28643 diff -NurpP --minimal linux-2.6.32.56/net/unix/af_unix.c linux-2.6.32.56-vs2.3.0.36.29.9/net/unix/af_unix.c
28644 --- linux-2.6.32.56/net/unix/af_unix.c  2012-02-09 10:22:38.000000000 +0100
28645 +++ linux-2.6.32.56-vs2.3.0.36.29.9/net/unix/af_unix.c  2011-06-10 13:03:02.000000000 +0200
28646 @@ -114,6 +114,8 @@
28647  #include <linux/mount.h>
28648  #include <net/checksum.h>
28649  #include <linux/security.h>
28650 +#include <linux/vs_context.h>
28651 +#include <linux/vs_limit.h>
28652  
28653  static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
28654  static DEFINE_SPINLOCK(unix_table_lock);
28655 @@ -258,6 +260,8 @@ static struct sock *__unix_find_socket_b
28656                 if (!net_eq(sock_net(s), net))
28657                         continue;
28658  
28659 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
28660 +                       continue;
28661                 if (u->addr->len == len &&
28662                     !memcmp(u->addr->name, sunname, len))
28663                         goto found;
28664 @@ -2164,6 +2168,8 @@ static struct sock *unix_seq_idx(struct 
28665         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
28666                 if (sock_net(s) != seq_file_net(seq))
28667                         continue;
28668 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
28669 +                       continue;
28670                 if (off == pos)
28671                         return s;
28672                 ++off;
28673 @@ -2188,7 +2194,8 @@ static void *unix_seq_next(struct seq_fi
28674                 sk = first_unix_socket(&iter->i);
28675         else
28676                 sk = next_unix_socket(&iter->i, sk);
28677 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
28678 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
28679 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
28680                 sk = next_unix_socket(&iter->i, sk);
28681         return sk;
28682  }
28683 diff -NurpP --minimal linux-2.6.32.56/scripts/checksyscalls.sh linux-2.6.32.56-vs2.3.0.36.29.9/scripts/checksyscalls.sh
28684 --- linux-2.6.32.56/scripts/checksyscalls.sh    2009-09-10 15:26:31.000000000 +0200
28685 +++ linux-2.6.32.56-vs2.3.0.36.29.9/scripts/checksyscalls.sh    2011-06-10 13:03:02.000000000 +0200
28686 @@ -194,7 +194,6 @@ cat << EOF
28687  #define __IGNORE_afs_syscall
28688  #define __IGNORE_getpmsg
28689  #define __IGNORE_putpmsg
28690 -#define __IGNORE_vserver
28691  EOF
28692  }
28693  
28694 diff -NurpP --minimal linux-2.6.32.56/security/commoncap.c linux-2.6.32.56-vs2.3.0.36.29.9/security/commoncap.c
28695 --- linux-2.6.32.56/security/commoncap.c        2009-12-03 20:03:02.000000000 +0100
28696 +++ linux-2.6.32.56-vs2.3.0.36.29.9/security/commoncap.c        2011-06-10 13:03:02.000000000 +0200
28697 @@ -27,6 +27,7 @@
28698  #include <linux/sched.h>
28699  #include <linux/prctl.h>
28700  #include <linux/securebits.h>
28701 +#include <linux/vs_context.h>
28702  
28703  /*
28704   * If a non-root user executes a setuid-root binary in
28705 @@ -52,7 +53,7 @@ static void warn_setuid_and_fcaps_mixed(
28706  
28707  int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
28708  {
28709 -       NETLINK_CB(skb).eff_cap = current_cap();
28710 +       NETLINK_CB(skb).eff_cap = vx_mbcaps(current_cap());
28711         return 0;
28712  }
28713  
28714 @@ -62,6 +63,7 @@ int cap_netlink_recv(struct sk_buff *skb
28715                 return -EPERM;
28716         return 0;
28717  }
28718 +
28719  EXPORT_SYMBOL(cap_netlink_recv);
28720  
28721  /**
28722 @@ -82,7 +84,22 @@ EXPORT_SYMBOL(cap_netlink_recv);
28723  int cap_capable(struct task_struct *tsk, const struct cred *cred, int cap,
28724                 int audit)
28725  {
28726 -       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
28727 +       struct vx_info *vxi = tsk->vx_info;
28728 +
28729 +#if 0
28730 +       printk("cap_capable() VXF_STATE_SETUP = %llx, raised = %x, eff = %08x:%08x\n",
28731 +               vx_info_flags(vxi, VXF_STATE_SETUP, 0),
28732 +               cap_raised(tsk->cap_effective, cap),
28733 +               tsk->cap_effective.cap[1], tsk->cap_effective.cap[0]);
28734 +#endif
28735 +
28736 +       /* special case SETUP */
28737 +       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
28738 +               /* FIXME: maybe use cred instead? */
28739 +               cap_raised(tsk->cred->cap_effective, cap))
28740 +               return 0;
28741 +
28742 +       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
28743  }
28744  
28745  /**
28746 @@ -618,7 +635,7 @@ int cap_inode_setxattr(struct dentry *de
28747  
28748         if (!strncmp(name, XATTR_SECURITY_PREFIX,
28749                      sizeof(XATTR_SECURITY_PREFIX) - 1)  &&
28750 -           !capable(CAP_SYS_ADMIN))
28751 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
28752                 return -EPERM;
28753         return 0;
28754  }
28755 @@ -644,7 +661,7 @@ int cap_inode_removexattr(struct dentry 
28756  
28757         if (!strncmp(name, XATTR_SECURITY_PREFIX,
28758                      sizeof(XATTR_SECURITY_PREFIX) - 1)  &&
28759 -           !capable(CAP_SYS_ADMIN))
28760 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
28761                 return -EPERM;
28762         return 0;
28763  }
28764 @@ -962,7 +979,8 @@ error:
28765   */
28766  int cap_syslog(int type)
28767  {
28768 -       if ((type != 3 && type != 10) && !capable(CAP_SYS_ADMIN))
28769 +       if ((type != 3 && type != 10) &&
28770 +               !vx_capable(CAP_SYS_ADMIN, VXC_SYSLOG))
28771                 return -EPERM;
28772         return 0;
28773  }
28774 diff -NurpP --minimal linux-2.6.32.56/security/selinux/hooks.c linux-2.6.32.56-vs2.3.0.36.29.9/security/selinux/hooks.c
28775 --- linux-2.6.32.56/security/selinux/hooks.c    2012-02-09 10:22:38.000000000 +0100
28776 +++ linux-2.6.32.56-vs2.3.0.36.29.9/security/selinux/hooks.c    2011-06-10 13:03:02.000000000 +0200
28777 @@ -64,7 +64,6 @@
28778  #include <linux/dccp.h>
28779  #include <linux/quota.h>
28780  #include <linux/un.h>          /* for Unix socket types */
28781 -#include <net/af_unix.h>       /* for Unix socket types */
28782  #include <linux/parser.h>
28783  #include <linux/nfs_mount.h>
28784  #include <net/ipv6.h>
28785 diff -NurpP --minimal linux-2.6.32.56/security/selinux/include/av_perm_to_string.h linux-2.6.32.56-vs2.3.0.36.29.9/security/selinux/include/av_perm_to_string.h
28786 --- linux-2.6.32.56/security/selinux/include/av_perm_to_string.h        2009-12-03 20:03:02.000000000 +0100
28787 +++ linux-2.6.32.56-vs2.3.0.36.29.9/security/selinux/include/av_perm_to_string.h        2011-06-10 13:03:02.000000000 +0200
28788 @@ -142,6 +142,7 @@
28789     S_(SECCLASS_CAPABILITY, CAPABILITY__SETFCAP, "setfcap")
28790     S_(SECCLASS_CAPABILITY2, CAPABILITY2__MAC_OVERRIDE, "mac_override")
28791     S_(SECCLASS_CAPABILITY2, CAPABILITY2__MAC_ADMIN, "mac_admin")
28792 +   S_(SECCLASS_CAPABILITY2, CAPABILITY2__CONTEXT, "context")
28793     S_(SECCLASS_NETLINK_ROUTE_SOCKET, NETLINK_ROUTE_SOCKET__NLMSG_READ, "nlmsg_read")
28794     S_(SECCLASS_NETLINK_ROUTE_SOCKET, NETLINK_ROUTE_SOCKET__NLMSG_WRITE, "nlmsg_write")
28795     S_(SECCLASS_NETLINK_FIREWALL_SOCKET, NETLINK_FIREWALL_SOCKET__NLMSG_READ, "nlmsg_read")
28796 diff -NurpP --minimal linux-2.6.32.56/security/selinux/include/av_permissions.h linux-2.6.32.56-vs2.3.0.36.29.9/security/selinux/include/av_permissions.h
28797 --- linux-2.6.32.56/security/selinux/include/av_permissions.h   2009-12-03 20:03:02.000000000 +0100
28798 +++ linux-2.6.32.56-vs2.3.0.36.29.9/security/selinux/include/av_permissions.h   2011-06-10 13:03:02.000000000 +0200
28799 @@ -565,6 +565,7 @@
28800  #define CAPABILITY__SETFCAP                       0x80000000UL
28801  #define CAPABILITY2__MAC_OVERRIDE                 0x00000001UL
28802  #define CAPABILITY2__MAC_ADMIN                    0x00000002UL
28803 +#define CAPABILITY2__CONTEXT                      0x00000004UL
28804  #define NETLINK_ROUTE_SOCKET__IOCTL               0x00000001UL
28805  #define NETLINK_ROUTE_SOCKET__READ                0x00000002UL
28806  #define NETLINK_ROUTE_SOCKET__WRITE               0x00000004UL
This page took 2.268452 seconds and 4 git commands to generate.