]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- patch-2.6.36-vs2.3.0.36.36.diff
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-2.6.36/arch/alpha/Kconfig linux-2.6.36-vs2.3.0.36.36/arch/alpha/Kconfig
2 --- linux-2.6.36/arch/alpha/Kconfig     2010-10-21 13:06:45.000000000 +0200
3 +++ linux-2.6.36-vs2.3.0.36.36/arch/alpha/Kconfig       2010-10-21 13:09:36.000000000 +0200
4 @@ -677,6 +677,8 @@ config DUMMY_CONSOLE
5         depends on VGA_HOSE
6         default y
7  
8 +source "kernel/vserver/Kconfig"
9 +
10  source "security/Kconfig"
11  
12  source "crypto/Kconfig"
13 diff -NurpP --minimal linux-2.6.36/arch/alpha/kernel/entry.S linux-2.6.36-vs2.3.0.36.36/arch/alpha/kernel/entry.S
14 --- linux-2.6.36/arch/alpha/kernel/entry.S      2010-10-21 13:06:45.000000000 +0200
15 +++ linux-2.6.36-vs2.3.0.36.36/arch/alpha/kernel/entry.S        2010-10-21 13:09:36.000000000 +0200
16 @@ -860,24 +860,15 @@ sys_getxgid:
17         .globl  sys_getxpid
18         .ent    sys_getxpid
19  sys_getxpid:
20 +       lda     $sp, -16($sp)
21 +       stq     $26, 0($sp)
22         .prologue 0
23 -       ldq     $2, TI_TASK($8)
24  
25 -       /* See linux/kernel/timer.c sys_getppid for discussion
26 -          about this loop.  */
27 -       ldq     $3, TASK_GROUP_LEADER($2)
28 -       ldq     $4, TASK_REAL_PARENT($3)
29 -       ldl     $0, TASK_TGID($2)
30 -1:     ldl     $1, TASK_TGID($4)
31 -#ifdef CONFIG_SMP
32 -       mov     $4, $5
33 -       mb
34 -       ldq     $3, TASK_GROUP_LEADER($2)
35 -       ldq     $4, TASK_REAL_PARENT($3)
36 -       cmpeq   $4, $5, $5
37 -       beq     $5, 1b
38 -#endif
39 -       stq     $1, 80($sp)
40 +       lda     $16, 96($sp)
41 +       jsr     $26, do_getxpid
42 +       ldq     $26, 0($sp)
43 +
44 +       lda     $sp, 16($sp)
45         ret
46  .end sys_getxpid
47  
48 diff -NurpP --minimal linux-2.6.36/arch/alpha/kernel/ptrace.c linux-2.6.36-vs2.3.0.36.36/arch/alpha/kernel/ptrace.c
49 --- linux-2.6.36/arch/alpha/kernel/ptrace.c     2010-07-07 18:30:51.000000000 +0200
50 +++ linux-2.6.36-vs2.3.0.36.36/arch/alpha/kernel/ptrace.c       2010-10-21 13:09:36.000000000 +0200
51 @@ -13,6 +13,7 @@
52  #include <linux/user.h>
53  #include <linux/security.h>
54  #include <linux/signal.h>
55 +#include <linux/vs_base.h>
56  
57  #include <asm/uaccess.h>
58  #include <asm/pgtable.h>
59 diff -NurpP --minimal linux-2.6.36/arch/alpha/kernel/systbls.S linux-2.6.36-vs2.3.0.36.36/arch/alpha/kernel/systbls.S
60 --- linux-2.6.36/arch/alpha/kernel/systbls.S    2010-10-21 13:06:46.000000000 +0200
61 +++ linux-2.6.36-vs2.3.0.36.36/arch/alpha/kernel/systbls.S      2010-10-21 13:09:36.000000000 +0200
62 @@ -446,7 +446,7 @@ sys_call_table:
63         .quad sys_stat64                        /* 425 */
64         .quad sys_lstat64
65         .quad sys_fstat64
66 -       .quad sys_ni_syscall                    /* sys_vserver */
67 +       .quad sys_vserver                       /* sys_vserver */
68         .quad sys_ni_syscall                    /* sys_mbind */
69         .quad sys_ni_syscall                    /* sys_get_mempolicy */
70         .quad sys_ni_syscall                    /* sys_set_mempolicy */
71 diff -NurpP --minimal linux-2.6.36/arch/alpha/kernel/traps.c linux-2.6.36-vs2.3.0.36.36/arch/alpha/kernel/traps.c
72 --- linux-2.6.36/arch/alpha/kernel/traps.c      2010-10-21 13:06:46.000000000 +0200
73 +++ linux-2.6.36-vs2.3.0.36.36/arch/alpha/kernel/traps.c        2010-10-21 13:09:36.000000000 +0200
74 @@ -183,7 +183,8 @@ die_if_kernel(char * str, struct pt_regs
75  #ifdef CONFIG_SMP
76         printk("CPU %d ", hard_smp_processor_id());
77  #endif
78 -       printk("%s(%d): %s %ld\n", current->comm, task_pid_nr(current), str, err);
79 +       printk("%s(%d[#%u]): %s %ld\n", current->comm,
80 +               task_pid_nr(current), current->xid, str, err);
81         dik_show_regs(regs, r9_15);
82         add_taint(TAINT_DIE);
83         dik_show_trace((unsigned long *)(regs+1));
84 diff -NurpP --minimal linux-2.6.36/arch/arm/include/asm/tlb.h linux-2.6.36-vs2.3.0.36.36/arch/arm/include/asm/tlb.h
85 --- linux-2.6.36/arch/arm/include/asm/tlb.h     2009-09-10 15:25:15.000000000 +0200
86 +++ linux-2.6.36-vs2.3.0.36.36/arch/arm/include/asm/tlb.h       2010-10-21 13:09:36.000000000 +0200
87 @@ -27,6 +27,7 @@
88  
89  #else /* !CONFIG_MMU */
90  
91 +#include <linux/vs_memory.h>
92  #include <asm/pgalloc.h>
93  
94  /*
95 diff -NurpP --minimal linux-2.6.36/arch/arm/Kconfig linux-2.6.36-vs2.3.0.36.36/arch/arm/Kconfig
96 --- linux-2.6.36/arch/arm/Kconfig       2010-10-21 13:06:46.000000000 +0200
97 +++ linux-2.6.36-vs2.3.0.36.36/arch/arm/Kconfig 2010-10-21 13:09:36.000000000 +0200
98 @@ -1803,6 +1803,8 @@ source "fs/Kconfig"
99  
100  source "arch/arm/Kconfig.debug"
101  
102 +source "kernel/vserver/Kconfig"
103 +
104  source "security/Kconfig"
105  
106  source "crypto/Kconfig"
107 diff -NurpP --minimal linux-2.6.36/arch/arm/kernel/calls.S linux-2.6.36-vs2.3.0.36.36/arch/arm/kernel/calls.S
108 --- linux-2.6.36/arch/arm/kernel/calls.S        2010-10-21 13:06:46.000000000 +0200
109 +++ linux-2.6.36-vs2.3.0.36.36/arch/arm/kernel/calls.S  2010-10-21 13:09:36.000000000 +0200
110 @@ -322,7 +322,7 @@
111  /* 310 */      CALL(sys_request_key)
112                 CALL(sys_keyctl)
113                 CALL(ABI(sys_semtimedop, sys_oabi_semtimedop))
114 -/* vserver */  CALL(sys_ni_syscall)
115 +               CALL(sys_vserver)
116                 CALL(sys_ioprio_set)
117  /* 315 */      CALL(sys_ioprio_get)
118                 CALL(sys_inotify_init)
119 diff -NurpP --minimal linux-2.6.36/arch/arm/kernel/process.c linux-2.6.36-vs2.3.0.36.36/arch/arm/kernel/process.c
120 --- linux-2.6.36/arch/arm/kernel/process.c      2010-10-21 13:06:46.000000000 +0200
121 +++ linux-2.6.36-vs2.3.0.36.36/arch/arm/kernel/process.c        2010-10-21 13:09:36.000000000 +0200
122 @@ -295,7 +295,8 @@ void __show_regs(struct pt_regs *regs)
123  void show_regs(struct pt_regs * regs)
124  {
125         printk("\n");
126 -       printk("Pid: %d, comm: %20s\n", task_pid_nr(current), current->comm);
127 +       printk("Pid: %d[#%u], comm: %20s\n",
128 +               task_pid_nr(current), current->xid, current->comm);
129         __show_regs(regs);
130         __backtrace();
131  }
132 diff -NurpP --minimal linux-2.6.36/arch/arm/kernel/traps.c linux-2.6.36-vs2.3.0.36.36/arch/arm/kernel/traps.c
133 --- linux-2.6.36/arch/arm/kernel/traps.c        2010-10-21 13:06:46.000000000 +0200
134 +++ linux-2.6.36-vs2.3.0.36.36/arch/arm/kernel/traps.c  2010-10-21 13:09:36.000000000 +0200
135 @@ -244,8 +244,8 @@ static int __die(const char *str, int er
136  
137         print_modules();
138         __show_regs(regs);
139 -       printk(KERN_EMERG "Process %.*s (pid: %d, stack limit = 0x%p)\n",
140 -               TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), thread + 1);
141 +       printk(KERN_EMERG "Process %.*s (pid: %d:#%u, stack limit = 0x%p)\n",
142 +               TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), tsk->xid, thread + 1);
143  
144         if (!user_mode(regs) || in_interrupt()) {
145                 dump_mem(KERN_EMERG, "Stack: ", regs->ARM_sp,
146 diff -NurpP --minimal linux-2.6.36/arch/cris/Kconfig linux-2.6.36-vs2.3.0.36.36/arch/cris/Kconfig
147 --- linux-2.6.36/arch/cris/Kconfig      2010-10-21 13:06:51.000000000 +0200
148 +++ linux-2.6.36-vs2.3.0.36.36/arch/cris/Kconfig        2010-10-21 13:09:36.000000000 +0200
149 @@ -694,6 +694,8 @@ source "drivers/staging/Kconfig"
150  
151  source "arch/cris/Kconfig.debug"
152  
153 +source "kernel/vserver/Kconfig"
154 +
155  source "security/Kconfig"
156  
157  source "crypto/Kconfig"
158 diff -NurpP --minimal linux-2.6.36/arch/frv/kernel/kernel_thread.S linux-2.6.36-vs2.3.0.36.36/arch/frv/kernel/kernel_thread.S
159 --- linux-2.6.36/arch/frv/kernel/kernel_thread.S        2008-12-25 00:26:37.000000000 +0100
160 +++ linux-2.6.36-vs2.3.0.36.36/arch/frv/kernel/kernel_thread.S  2010-10-21 13:09:36.000000000 +0200
161 @@ -37,7 +37,7 @@ kernel_thread:
162  
163         # start by forking the current process, but with shared VM
164         setlos.p        #__NR_clone,gr7         ; syscall number
165 -       ori             gr10,#CLONE_VM,gr8      ; first syscall arg     [clone_flags]
166 +       ori             gr10,#CLONE_KT,gr8      ; first syscall arg     [clone_flags]
167         sethi.p         #0xe4e4,gr9             ; second syscall arg    [newsp]
168         setlo           #0xe4e4,gr9
169         setlos.p        #0,gr10                 ; third syscall arg     [parent_tidptr]
170 diff -NurpP --minimal linux-2.6.36/arch/h8300/Kconfig linux-2.6.36-vs2.3.0.36.36/arch/h8300/Kconfig
171 --- linux-2.6.36/arch/h8300/Kconfig     2010-10-21 13:06:51.000000000 +0200
172 +++ linux-2.6.36-vs2.3.0.36.36/arch/h8300/Kconfig       2010-10-21 13:09:36.000000000 +0200
173 @@ -226,6 +226,8 @@ source "fs/Kconfig"
174  
175  source "arch/h8300/Kconfig.debug"
176  
177 +source "kernel/vserver/Kconfig"
178 +
179  source "security/Kconfig"
180  
181  source "crypto/Kconfig"
182 diff -NurpP --minimal linux-2.6.36/arch/ia64/include/asm/tlb.h linux-2.6.36-vs2.3.0.36.36/arch/ia64/include/asm/tlb.h
183 --- linux-2.6.36/arch/ia64/include/asm/tlb.h    2010-02-25 11:51:26.000000000 +0100
184 +++ linux-2.6.36-vs2.3.0.36.36/arch/ia64/include/asm/tlb.h      2010-10-21 13:09:36.000000000 +0200
185 @@ -40,6 +40,7 @@
186  #include <linux/mm.h>
187  #include <linux/pagemap.h>
188  #include <linux/swap.h>
189 +#include <linux/vs_memory.h>
190  
191  #include <asm/pgalloc.h>
192  #include <asm/processor.h>
193 diff -NurpP --minimal linux-2.6.36/arch/ia64/Kconfig linux-2.6.36-vs2.3.0.36.36/arch/ia64/Kconfig
194 --- linux-2.6.36/arch/ia64/Kconfig      2010-10-21 13:06:52.000000000 +0200
195 +++ linux-2.6.36-vs2.3.0.36.36/arch/ia64/Kconfig        2010-10-21 13:09:36.000000000 +0200
196 @@ -671,6 +671,8 @@ source "fs/Kconfig"
197  
198  source "arch/ia64/Kconfig.debug"
199  
200 +source "kernel/vserver/Kconfig"
201 +
202  source "security/Kconfig"
203  
204  source "crypto/Kconfig"
205 diff -NurpP --minimal linux-2.6.36/arch/ia64/kernel/entry.S linux-2.6.36-vs2.3.0.36.36/arch/ia64/kernel/entry.S
206 --- linux-2.6.36/arch/ia64/kernel/entry.S       2010-10-21 13:06:52.000000000 +0200
207 +++ linux-2.6.36-vs2.3.0.36.36/arch/ia64/kernel/entry.S 2010-10-21 13:09:36.000000000 +0200
208 @@ -1714,7 +1714,7 @@ sys_call_table:
209         data8 sys_mq_notify
210         data8 sys_mq_getsetattr
211         data8 sys_kexec_load
212 -       data8 sys_ni_syscall                    // reserved for vserver
213 +       data8 sys_vserver
214         data8 sys_waitid                        // 1270
215         data8 sys_add_key
216         data8 sys_request_key
217 diff -NurpP --minimal linux-2.6.36/arch/ia64/kernel/perfmon.c linux-2.6.36-vs2.3.0.36.36/arch/ia64/kernel/perfmon.c
218 --- linux-2.6.36/arch/ia64/kernel/perfmon.c     2010-10-21 13:06:52.000000000 +0200
219 +++ linux-2.6.36-vs2.3.0.36.36/arch/ia64/kernel/perfmon.c       2010-10-21 13:09:36.000000000 +0200
220 @@ -42,6 +42,7 @@
221  #include <linux/completion.h>
222  #include <linux/tracehook.h>
223  #include <linux/slab.h>
224 +#include <linux/vs_memory.h>
225  
226  #include <asm/errno.h>
227  #include <asm/intrinsics.h>
228 diff -NurpP --minimal linux-2.6.36/arch/ia64/kernel/process.c linux-2.6.36-vs2.3.0.36.36/arch/ia64/kernel/process.c
229 --- linux-2.6.36/arch/ia64/kernel/process.c     2010-10-21 13:06:52.000000000 +0200
230 +++ linux-2.6.36-vs2.3.0.36.36/arch/ia64/kernel/process.c       2010-10-21 13:09:36.000000000 +0200
231 @@ -113,8 +113,8 @@ show_regs (struct pt_regs *regs)
232         unsigned long ip = regs->cr_iip + ia64_psr(regs)->ri;
233  
234         print_modules();
235 -       printk("\nPid: %d, CPU %d, comm: %20s\n", task_pid_nr(current),
236 -                       smp_processor_id(), current->comm);
237 +       printk("\nPid: %d[#%u], CPU %d, comm: %20s\n", task_pid_nr(current),
238 +                       current->xid, smp_processor_id(), current->comm);
239         printk("psr : %016lx ifs : %016lx ip  : [<%016lx>]    %s (%s)\n",
240                regs->cr_ipsr, regs->cr_ifs, ip, print_tainted(),
241                init_utsname()->release);
242 diff -NurpP --minimal linux-2.6.36/arch/ia64/kernel/ptrace.c linux-2.6.36-vs2.3.0.36.36/arch/ia64/kernel/ptrace.c
243 --- linux-2.6.36/arch/ia64/kernel/ptrace.c      2010-08-02 16:52:04.000000000 +0200
244 +++ linux-2.6.36-vs2.3.0.36.36/arch/ia64/kernel/ptrace.c        2010-10-21 13:09:36.000000000 +0200
245 @@ -21,6 +21,7 @@
246  #include <linux/regset.h>
247  #include <linux/elf.h>
248  #include <linux/tracehook.h>
249 +#include <linux/vs_base.h>
250  
251  #include <asm/pgtable.h>
252  #include <asm/processor.h>
253 diff -NurpP --minimal linux-2.6.36/arch/ia64/kernel/traps.c linux-2.6.36-vs2.3.0.36.36/arch/ia64/kernel/traps.c
254 --- linux-2.6.36/arch/ia64/kernel/traps.c       2010-07-07 18:31:01.000000000 +0200
255 +++ linux-2.6.36-vs2.3.0.36.36/arch/ia64/kernel/traps.c 2010-10-21 13:09:36.000000000 +0200
256 @@ -59,8 +59,9 @@ die (const char *str, struct pt_regs *re
257         put_cpu();
258  
259         if (++die.lock_owner_depth < 3) {
260 -               printk("%s[%d]: %s %ld [%d]\n",
261 -               current->comm, task_pid_nr(current), str, err, ++die_counter);
262 +               printk("%s[%d[#%u]]: %s %ld [%d]\n",
263 +                       current->comm, task_pid_nr(current), current->xid,
264 +                       str, err, ++die_counter);
265                 if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV)
266                     != NOTIFY_STOP)
267                         show_regs(regs);
268 @@ -323,8 +324,9 @@ handle_fpu_swa (int fp_fault, struct pt_
269                         if ((last.count & 15) < 5 && (ia64_fetchadd(1, &last.count, acq) & 15) < 5) {
270                                 last.time = current_jiffies + 5 * HZ;
271                                 printk(KERN_WARNING
272 -                                       "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
273 -                                       current->comm, task_pid_nr(current), regs->cr_iip + ia64_psr(regs)->ri, isr);
274 +                                       "%s(%d[#%u]): floating-point assist fault at ip %016lx, isr %016lx\n",
275 +                                       current->comm, task_pid_nr(current), current->xid,
276 +                                       regs->cr_iip + ia64_psr(regs)->ri, isr);
277                         }
278                 }
279         }
280 diff -NurpP --minimal linux-2.6.36/arch/ia64/mm/fault.c linux-2.6.36-vs2.3.0.36.36/arch/ia64/mm/fault.c
281 --- linux-2.6.36/arch/ia64/mm/fault.c   2010-08-02 16:52:04.000000000 +0200
282 +++ linux-2.6.36-vs2.3.0.36.36/arch/ia64/mm/fault.c     2010-10-21 13:09:36.000000000 +0200
283 @@ -10,6 +10,7 @@
284  #include <linux/interrupt.h>
285  #include <linux/kprobes.h>
286  #include <linux/kdebug.h>
287 +#include <linux/vs_memory.h>
288  
289  #include <asm/pgtable.h>
290  #include <asm/processor.h>
291 diff -NurpP --minimal linux-2.6.36/arch/m32r/kernel/traps.c linux-2.6.36-vs2.3.0.36.36/arch/m32r/kernel/traps.c
292 --- linux-2.6.36/arch/m32r/kernel/traps.c       2009-12-03 20:01:57.000000000 +0100
293 +++ linux-2.6.36-vs2.3.0.36.36/arch/m32r/kernel/traps.c 2010-10-21 13:09:36.000000000 +0200
294 @@ -196,8 +196,9 @@ static void show_registers(struct pt_reg
295         } else {
296                 printk("SPI: %08lx\n", sp);
297         }
298 -       printk("Process %s (pid: %d, process nr: %d, stackpage=%08lx)",
299 -               current->comm, task_pid_nr(current), 0xffff & i, 4096+(unsigned long)current);
300 +       printk("Process %s (pid: %d[#%u], process nr: %d, stackpage=%08lx)",
301 +               current->comm, task_pid_nr(current), current->xid,
302 +               0xffff & i, 4096+(unsigned long)current);
303  
304         /*
305          * When in-kernel, we also print out the stack and code at the
306 diff -NurpP --minimal linux-2.6.36/arch/m68k/Kconfig linux-2.6.36-vs2.3.0.36.36/arch/m68k/Kconfig
307 --- linux-2.6.36/arch/m68k/Kconfig      2010-10-21 13:06:52.000000000 +0200
308 +++ linux-2.6.36-vs2.3.0.36.36/arch/m68k/Kconfig        2010-10-21 13:09:36.000000000 +0200
309 @@ -616,6 +616,8 @@ source "fs/Kconfig"
310  
311  source "arch/m68k/Kconfig.debug"
312  
313 +source "kernel/vserver/Kconfig"
314 +
315  source "security/Kconfig"
316  
317  source "crypto/Kconfig"
318 diff -NurpP --minimal linux-2.6.36/arch/m68k/kernel/ptrace.c linux-2.6.36-vs2.3.0.36.36/arch/m68k/kernel/ptrace.c
319 --- linux-2.6.36/arch/m68k/kernel/ptrace.c      2010-07-07 18:31:02.000000000 +0200
320 +++ linux-2.6.36-vs2.3.0.36.36/arch/m68k/kernel/ptrace.c        2010-10-21 13:09:36.000000000 +0200
321 @@ -18,6 +18,7 @@
322  #include <linux/ptrace.h>
323  #include <linux/user.h>
324  #include <linux/signal.h>
325 +#include <linux/vs_base.h>
326  
327  #include <asm/uaccess.h>
328  #include <asm/page.h>
329 @@ -254,6 +255,8 @@ long arch_ptrace(struct task_struct *chi
330                 ret = ptrace_request(child, request, addr, data);
331                 break;
332         }
333 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
334 +               goto out_tsk;
335  
336         return ret;
337  out_eio:
338 diff -NurpP --minimal linux-2.6.36/arch/m68k/kernel/traps.c linux-2.6.36-vs2.3.0.36.36/arch/m68k/kernel/traps.c
339 --- linux-2.6.36/arch/m68k/kernel/traps.c       2010-08-02 16:52:04.000000000 +0200
340 +++ linux-2.6.36-vs2.3.0.36.36/arch/m68k/kernel/traps.c 2010-10-21 13:09:36.000000000 +0200
341 @@ -906,8 +906,8 @@ void show_registers(struct pt_regs *regs
342         printk("d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
343                regs->d4, regs->d5, regs->a0, regs->a1);
344  
345 -       printk("Process %s (pid: %d, task=%p)\n",
346 -               current->comm, task_pid_nr(current), current);
347 +       printk("Process %s (pid: %d[#%u], task=%p)\n",
348 +               current->comm, task_pid_nr(current), current->xid, current);
349         addr = (unsigned long)&fp->un;
350         printk("Frame format=%X ", regs->format);
351         switch (regs->format) {
352 diff -NurpP --minimal linux-2.6.36/arch/m68knommu/Kconfig linux-2.6.36-vs2.3.0.36.36/arch/m68knommu/Kconfig
353 --- linux-2.6.36/arch/m68knommu/Kconfig 2010-10-21 13:06:53.000000000 +0200
354 +++ linux-2.6.36-vs2.3.0.36.36/arch/m68knommu/Kconfig   2010-10-21 13:09:36.000000000 +0200
355 @@ -730,6 +730,8 @@ source "fs/Kconfig"
356  
357  source "arch/m68knommu/Kconfig.debug"
358  
359 +source "kernel/vserver/Kconfig"
360 +
361  source "security/Kconfig"
362  
363  source "crypto/Kconfig"
364 diff -NurpP --minimal linux-2.6.36/arch/m68knommu/kernel/traps.c linux-2.6.36-vs2.3.0.36.36/arch/m68knommu/kernel/traps.c
365 --- linux-2.6.36/arch/m68knommu/kernel/traps.c  2009-09-10 15:25:23.000000000 +0200
366 +++ linux-2.6.36-vs2.3.0.36.36/arch/m68knommu/kernel/traps.c    2010-10-21 13:09:36.000000000 +0200
367 @@ -78,8 +78,9 @@ void die_if_kernel(char *str, struct pt_
368         printk(KERN_EMERG "d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
369                fp->d4, fp->d5, fp->a0, fp->a1);
370  
371 -       printk(KERN_EMERG "Process %s (pid: %d, stackpage=%08lx)\n",
372 -               current->comm, current->pid, PAGE_SIZE+(unsigned long)current);
373 +       printk(KERN_EMERG "Process %s (pid: %d[#%u], stackpage=%08lx)\n",
374 +               current->comm, task_pid_nr(current), current->xid,
375 +               PAGE_SIZE+(unsigned long)current);
376         show_stack(NULL, (unsigned long *)(fp + 1));
377         add_taint(TAINT_DIE);
378         do_exit(SIGSEGV);
379 diff -NurpP --minimal linux-2.6.36/arch/mips/Kconfig linux-2.6.36-vs2.3.0.36.36/arch/mips/Kconfig
380 --- linux-2.6.36/arch/mips/Kconfig      2010-10-21 13:06:53.000000000 +0200
381 +++ linux-2.6.36-vs2.3.0.36.36/arch/mips/Kconfig        2010-10-21 13:09:36.000000000 +0200
382 @@ -2298,6 +2298,8 @@ source "fs/Kconfig"
383  
384  source "arch/mips/Kconfig.debug"
385  
386 +source "kernel/vserver/Kconfig"
387 +
388  source "security/Kconfig"
389  
390  source "crypto/Kconfig"
391 diff -NurpP --minimal linux-2.6.36/arch/mips/kernel/ptrace.c linux-2.6.36-vs2.3.0.36.36/arch/mips/kernel/ptrace.c
392 --- linux-2.6.36/arch/mips/kernel/ptrace.c      2010-10-21 13:06:54.000000000 +0200
393 +++ linux-2.6.36-vs2.3.0.36.36/arch/mips/kernel/ptrace.c        2010-10-21 13:09:36.000000000 +0200
394 @@ -25,6 +25,7 @@
395  #include <linux/security.h>
396  #include <linux/audit.h>
397  #include <linux/seccomp.h>
398 +#include <linux/vs_base.h>
399  
400  #include <asm/byteorder.h>
401  #include <asm/cpu.h>
402 @@ -259,6 +260,9 @@ long arch_ptrace(struct task_struct *chi
403  {
404         int ret;
405  
406 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
407 +               goto out;
408 +
409         switch (request) {
410         /* when I and D space are separate, these will need to be fixed. */
411         case PTRACE_PEEKTEXT: /* read word at location addr. */
412 diff -NurpP --minimal linux-2.6.36/arch/mips/kernel/scall32-o32.S linux-2.6.36-vs2.3.0.36.36/arch/mips/kernel/scall32-o32.S
413 --- linux-2.6.36/arch/mips/kernel/scall32-o32.S 2010-10-21 13:06:54.000000000 +0200
414 +++ linux-2.6.36-vs2.3.0.36.36/arch/mips/kernel/scall32-o32.S   2010-10-21 13:09:36.000000000 +0200
415 @@ -524,7 +524,7 @@ einval:     li      v0, -ENOSYS
416         sys     sys_mq_timedreceive     5
417         sys     sys_mq_notify           2       /* 4275 */
418         sys     sys_mq_getsetattr       3
419 -       sys     sys_ni_syscall          0       /* sys_vserver */
420 +       sys     sys_vserver             3
421         sys     sys_waitid              5
422         sys     sys_ni_syscall          0       /* available, was setaltroot */
423         sys     sys_add_key             5       /* 4280 */
424 diff -NurpP --minimal linux-2.6.36/arch/mips/kernel/scall64-64.S linux-2.6.36-vs2.3.0.36.36/arch/mips/kernel/scall64-64.S
425 --- linux-2.6.36/arch/mips/kernel/scall64-64.S  2010-10-21 13:06:54.000000000 +0200
426 +++ linux-2.6.36-vs2.3.0.36.36/arch/mips/kernel/scall64-64.S    2010-10-21 13:09:36.000000000 +0200
427 @@ -363,7 +363,7 @@ sys_call_table:
428         PTR     sys_mq_timedreceive
429         PTR     sys_mq_notify
430         PTR     sys_mq_getsetattr               /* 5235 */
431 -       PTR     sys_ni_syscall                  /* sys_vserver */
432 +       PTR     sys_vserver
433         PTR     sys_waitid
434         PTR     sys_ni_syscall                  /* available, was setaltroot */
435         PTR     sys_add_key
436 diff -NurpP --minimal linux-2.6.36/arch/mips/kernel/scall64-n32.S linux-2.6.36-vs2.3.0.36.36/arch/mips/kernel/scall64-n32.S
437 --- linux-2.6.36/arch/mips/kernel/scall64-n32.S 2010-10-21 13:06:54.000000000 +0200
438 +++ linux-2.6.36-vs2.3.0.36.36/arch/mips/kernel/scall64-n32.S   2010-10-21 13:09:36.000000000 +0200
439 @@ -362,7 +362,7 @@ EXPORT(sysn32_call_table)
440         PTR     compat_sys_mq_timedreceive
441         PTR     compat_sys_mq_notify
442         PTR     compat_sys_mq_getsetattr
443 -       PTR     sys_ni_syscall                  /* 6240, sys_vserver */
444 +       PTR     sys32_vserver                   /* 6240 */
445         PTR     compat_sys_waitid
446         PTR     sys_ni_syscall                  /* available, was setaltroot */
447         PTR     sys_add_key
448 diff -NurpP --minimal linux-2.6.36/arch/mips/kernel/scall64-o32.S linux-2.6.36-vs2.3.0.36.36/arch/mips/kernel/scall64-o32.S
449 --- linux-2.6.36/arch/mips/kernel/scall64-o32.S 2010-10-21 13:06:54.000000000 +0200
450 +++ linux-2.6.36-vs2.3.0.36.36/arch/mips/kernel/scall64-o32.S   2010-10-21 13:09:36.000000000 +0200
451 @@ -481,7 +481,7 @@ sys_call_table:
452         PTR     compat_sys_mq_timedreceive
453         PTR     compat_sys_mq_notify            /* 4275 */
454         PTR     compat_sys_mq_getsetattr
455 -       PTR     sys_ni_syscall                  /* sys_vserver */
456 +       PTR     sys32_vserver
457         PTR     sys_32_waitid
458         PTR     sys_ni_syscall                  /* available, was setaltroot */
459         PTR     sys_add_key                     /* 4280 */
460 diff -NurpP --minimal linux-2.6.36/arch/mips/kernel/traps.c linux-2.6.36-vs2.3.0.36.36/arch/mips/kernel/traps.c
461 --- linux-2.6.36/arch/mips/kernel/traps.c       2010-10-21 13:06:54.000000000 +0200
462 +++ linux-2.6.36-vs2.3.0.36.36/arch/mips/kernel/traps.c 2010-10-21 13:09:36.000000000 +0200
463 @@ -341,9 +341,10 @@ void show_registers(struct pt_regs *regs
464  
465         __show_regs(regs);
466         print_modules();
467 -       printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
468 -              current->comm, current->pid, current_thread_info(), current,
469 -             field, current_thread_info()->tp_value);
470 +       printk("Process %s (pid: %d:#%u, threadinfo=%p, task=%p, tls=%0*lx)\n",
471 +               current->comm, task_pid_nr(current), current->xid,
472 +               current_thread_info(), current,
473 +               field, current_thread_info()->tp_value);
474         if (cpu_has_userlocal) {
475                 unsigned long tls;
476  
477 diff -NurpP --minimal linux-2.6.36/arch/parisc/Kconfig linux-2.6.36-vs2.3.0.36.36/arch/parisc/Kconfig
478 --- linux-2.6.36/arch/parisc/Kconfig    2010-10-21 13:06:55.000000000 +0200
479 +++ linux-2.6.36-vs2.3.0.36.36/arch/parisc/Kconfig      2010-10-21 13:09:36.000000000 +0200
480 @@ -295,6 +295,8 @@ source "fs/Kconfig"
481  
482  source "arch/parisc/Kconfig.debug"
483  
484 +source "kernel/vserver/Kconfig"
485 +
486  source "security/Kconfig"
487  
488  source "crypto/Kconfig"
489 diff -NurpP --minimal linux-2.6.36/arch/parisc/kernel/syscall_table.S linux-2.6.36-vs2.3.0.36.36/arch/parisc/kernel/syscall_table.S
490 --- linux-2.6.36/arch/parisc/kernel/syscall_table.S     2010-07-07 18:31:04.000000000 +0200
491 +++ linux-2.6.36-vs2.3.0.36.36/arch/parisc/kernel/syscall_table.S       2010-10-21 13:09:36.000000000 +0200
492 @@ -361,7 +361,7 @@
493         ENTRY_COMP(mbind)               /* 260 */
494         ENTRY_COMP(get_mempolicy)
495         ENTRY_COMP(set_mempolicy)
496 -       ENTRY_SAME(ni_syscall)  /* 263: reserved for vserver */
497 +       ENTRY_DIFF(vserver)
498         ENTRY_SAME(add_key)
499         ENTRY_SAME(request_key)         /* 265 */
500         ENTRY_SAME(keyctl)
501 diff -NurpP --minimal linux-2.6.36/arch/parisc/kernel/traps.c linux-2.6.36-vs2.3.0.36.36/arch/parisc/kernel/traps.c
502 --- linux-2.6.36/arch/parisc/kernel/traps.c     2009-09-10 15:25:40.000000000 +0200
503 +++ linux-2.6.36-vs2.3.0.36.36/arch/parisc/kernel/traps.c       2010-10-21 13:09:36.000000000 +0200
504 @@ -236,8 +236,9 @@ void die_if_kernel(char *str, struct pt_
505                 if (err == 0)
506                         return; /* STFU */
507  
508 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
509 -                       current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
510 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld) at " RFMT "\n",
511 +                       current->comm, task_pid_nr(current), current->xid,
512 +                       str, err, regs->iaoq[0]);
513  #ifdef PRINT_USER_FAULTS
514                 /* XXX for debugging only */
515                 show_regs(regs);
516 @@ -270,8 +271,8 @@ void die_if_kernel(char *str, struct pt_
517                 pdc_console_restart();
518         
519         if (err)
520 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
521 -                       current->comm, task_pid_nr(current), str, err);
522 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld)\n",
523 +                       current->comm, task_pid_nr(current), current->xid, str, err);
524  
525         /* Wot's wrong wif bein' racy? */
526         if (current->thread.flags & PARISC_KERNEL_DEATH) {
527 diff -NurpP --minimal linux-2.6.36/arch/parisc/mm/fault.c linux-2.6.36-vs2.3.0.36.36/arch/parisc/mm/fault.c
528 --- linux-2.6.36/arch/parisc/mm/fault.c 2010-08-02 16:52:06.000000000 +0200
529 +++ linux-2.6.36-vs2.3.0.36.36/arch/parisc/mm/fault.c   2010-10-21 13:09:36.000000000 +0200
530 @@ -237,8 +237,9 @@ bad_area:
531  
532  #ifdef PRINT_USER_FAULTS
533                 printk(KERN_DEBUG "\n");
534 -               printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n",
535 -                   task_pid_nr(tsk), tsk->comm, code, address);
536 +               printk(KERN_DEBUG "do_page_fault() pid=%d:#%u "
537 +                   "command='%s' type=%lu address=0x%08lx\n",
538 +                   task_pid_nr(tsk), tsk->xid, tsk->comm, code, address);
539                 if (vma) {
540                         printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n",
541                                         vma->vm_start, vma->vm_end);
542 diff -NurpP --minimal linux-2.6.36/arch/powerpc/include/asm/unistd.h linux-2.6.36-vs2.3.0.36.36/arch/powerpc/include/asm/unistd.h
543 --- linux-2.6.36/arch/powerpc/include/asm/unistd.h      2010-10-21 13:06:56.000000000 +0200
544 +++ linux-2.6.36-vs2.3.0.36.36/arch/powerpc/include/asm/unistd.h        2010-10-21 13:09:36.000000000 +0200
545 @@ -275,7 +275,7 @@
546  #endif
547  #define __NR_rtas              255
548  #define __NR_sys_debug_setcontext 256
549 -/* Number 257 is reserved for vserver */
550 +#define __NR_vserver           257
551  #define __NR_migrate_pages     258
552  #define __NR_mbind             259
553  #define __NR_get_mempolicy     260
554 diff -NurpP --minimal linux-2.6.36/arch/powerpc/Kconfig linux-2.6.36-vs2.3.0.36.36/arch/powerpc/Kconfig
555 --- linux-2.6.36/arch/powerpc/Kconfig   2010-10-21 13:06:55.000000000 +0200
556 +++ linux-2.6.36-vs2.3.0.36.36/arch/powerpc/Kconfig     2010-10-21 13:09:36.000000000 +0200
557 @@ -974,6 +974,8 @@ source "lib/Kconfig"
558  
559  source "arch/powerpc/Kconfig.debug"
560  
561 +source "kernel/vserver/Kconfig"
562 +
563  source "security/Kconfig"
564  
565  config KEYS_COMPAT
566 diff -NurpP --minimal linux-2.6.36/arch/powerpc/kernel/process.c linux-2.6.36-vs2.3.0.36.36/arch/powerpc/kernel/process.c
567 --- linux-2.6.36/arch/powerpc/kernel/process.c  2010-10-21 13:06:56.000000000 +0200
568 +++ linux-2.6.36-vs2.3.0.36.36/arch/powerpc/kernel/process.c    2010-10-21 13:09:36.000000000 +0200
569 @@ -634,8 +634,9 @@ void show_regs(struct pt_regs * regs)
570  #else
571                 printk("DAR: "REG", DSISR: "REG"\n", regs->dar, regs->dsisr);
572  #endif
573 -       printk("TASK = %p[%d] '%s' THREAD: %p",
574 -              current, task_pid_nr(current), current->comm, task_thread_info(current));
575 +       printk("TASK = %p[%d,#%u] '%s' THREAD: %p",
576 +              current, task_pid_nr(current), current->xid,
577 +              current->comm, task_thread_info(current));
578  
579  #ifdef CONFIG_SMP
580         printk(" CPU: %d", raw_smp_processor_id());
581 diff -NurpP --minimal linux-2.6.36/arch/powerpc/kernel/traps.c linux-2.6.36-vs2.3.0.36.36/arch/powerpc/kernel/traps.c
582 --- linux-2.6.36/arch/powerpc/kernel/traps.c    2010-10-21 13:06:57.000000000 +0200
583 +++ linux-2.6.36-vs2.3.0.36.36/arch/powerpc/kernel/traps.c      2010-10-21 13:09:36.000000000 +0200
584 @@ -1048,8 +1048,9 @@ void nonrecoverable_exception(struct pt_
585  
586  void trace_syscall(struct pt_regs *regs)
587  {
588 -       printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
589 -              current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
590 +       printk("Task: %p(%d[#%u]), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
591 +              current, task_pid_nr(current), current->xid,
592 +              regs->nip, regs->link, regs->gpr[0],
593                regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
594  }
595  
596 diff -NurpP --minimal linux-2.6.36/arch/powerpc/kernel/vdso.c linux-2.6.36-vs2.3.0.36.36/arch/powerpc/kernel/vdso.c
597 --- linux-2.6.36/arch/powerpc/kernel/vdso.c     2010-08-02 16:52:07.000000000 +0200
598 +++ linux-2.6.36-vs2.3.0.36.36/arch/powerpc/kernel/vdso.c       2010-10-21 13:09:36.000000000 +0200
599 @@ -23,6 +23,7 @@
600  #include <linux/security.h>
601  #include <linux/bootmem.h>
602  #include <linux/memblock.h>
603 +#include <linux/vs_memory.h>
604  
605  #include <asm/pgtable.h>
606  #include <asm/system.h>
607 diff -NurpP --minimal linux-2.6.36/arch/s390/include/asm/tlb.h linux-2.6.36-vs2.3.0.36.36/arch/s390/include/asm/tlb.h
608 --- linux-2.6.36/arch/s390/include/asm/tlb.h    2010-10-21 13:06:58.000000000 +0200
609 +++ linux-2.6.36-vs2.3.0.36.36/arch/s390/include/asm/tlb.h      2010-10-21 13:09:36.000000000 +0200
610 @@ -23,6 +23,8 @@
611  
612  #include <linux/mm.h>
613  #include <linux/swap.h>
614 +#include <linux/vs_memory.h>
615 +
616  #include <asm/processor.h>
617  #include <asm/pgalloc.h>
618  #include <asm/smp.h>
619 diff -NurpP --minimal linux-2.6.36/arch/s390/include/asm/unistd.h linux-2.6.36-vs2.3.0.36.36/arch/s390/include/asm/unistd.h
620 --- linux-2.6.36/arch/s390/include/asm/unistd.h 2010-10-21 13:06:58.000000000 +0200
621 +++ linux-2.6.36-vs2.3.0.36.36/arch/s390/include/asm/unistd.h   2010-10-21 13:09:36.000000000 +0200
622 @@ -202,7 +202,7 @@
623  #define __NR_clock_gettime     (__NR_timer_create+6)
624  #define __NR_clock_getres      (__NR_timer_create+7)
625  #define __NR_clock_nanosleep   (__NR_timer_create+8)
626 -/* Number 263 is reserved for vserver */
627 +#define __NR_vserver           263
628  #define __NR_statfs64          265
629  #define __NR_fstatfs64         266
630  #define __NR_remap_file_pages  267
631 diff -NurpP --minimal linux-2.6.36/arch/s390/Kconfig linux-2.6.36-vs2.3.0.36.36/arch/s390/Kconfig
632 --- linux-2.6.36/arch/s390/Kconfig      2010-10-21 13:06:57.000000000 +0200
633 +++ linux-2.6.36-vs2.3.0.36.36/arch/s390/Kconfig        2010-10-21 13:09:36.000000000 +0200
634 @@ -620,6 +620,8 @@ source "fs/Kconfig"
635  
636  source "arch/s390/Kconfig.debug"
637  
638 +source "kernel/vserver/Kconfig"
639 +
640  source "security/Kconfig"
641  
642  source "crypto/Kconfig"
643 diff -NurpP --minimal linux-2.6.36/arch/s390/kernel/ptrace.c linux-2.6.36-vs2.3.0.36.36/arch/s390/kernel/ptrace.c
644 --- linux-2.6.36/arch/s390/kernel/ptrace.c      2010-08-02 16:52:09.000000000 +0200
645 +++ linux-2.6.36-vs2.3.0.36.36/arch/s390/kernel/ptrace.c        2010-10-21 13:09:36.000000000 +0200
646 @@ -36,6 +36,7 @@
647  #include <linux/regset.h>
648  #include <linux/tracehook.h>
649  #include <linux/seccomp.h>
650 +#include <linux/vs_base.h>
651  #include <trace/syscall.h>
652  #include <asm/compat.h>
653  #include <asm/segment.h>
654 diff -NurpP --minimal linux-2.6.36/arch/s390/kernel/syscalls.S linux-2.6.36-vs2.3.0.36.36/arch/s390/kernel/syscalls.S
655 --- linux-2.6.36/arch/s390/kernel/syscalls.S    2010-10-21 13:06:58.000000000 +0200
656 +++ linux-2.6.36-vs2.3.0.36.36/arch/s390/kernel/syscalls.S      2010-10-21 13:09:36.000000000 +0200
657 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
658  SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper)       /* 260 */
659  SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
660  SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
661 -NI_SYSCALL                                                     /* reserved for vserver */
662 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
663  SYSCALL(sys_s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
664  SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
665  SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
666 diff -NurpP --minimal linux-2.6.36/arch/sh/Kconfig linux-2.6.36-vs2.3.0.36.36/arch/sh/Kconfig
667 --- linux-2.6.36/arch/sh/Kconfig        2010-10-21 13:06:58.000000000 +0200
668 +++ linux-2.6.36-vs2.3.0.36.36/arch/sh/Kconfig  2010-10-21 13:09:36.000000000 +0200
669 @@ -878,6 +878,8 @@ source "fs/Kconfig"
670  
671  source "arch/sh/Kconfig.debug"
672  
673 +source "kernel/vserver/Kconfig"
674 +
675  source "security/Kconfig"
676  
677  source "crypto/Kconfig"
678 diff -NurpP --minimal linux-2.6.36/arch/sh/kernel/irq.c linux-2.6.36-vs2.3.0.36.36/arch/sh/kernel/irq.c
679 --- linux-2.6.36/arch/sh/kernel/irq.c   2010-08-02 16:52:10.000000000 +0200
680 +++ linux-2.6.36-vs2.3.0.36.36/arch/sh/kernel/irq.c     2010-10-21 13:09:36.000000000 +0200
681 @@ -13,6 +13,7 @@
682  #include <linux/seq_file.h>
683  #include <linux/ftrace.h>
684  #include <linux/delay.h>
685 +// #include <linux/vs_context.h>
686  #include <asm/processor.h>
687  #include <asm/machvec.h>
688  #include <asm/uaccess.h>
689 diff -NurpP --minimal linux-2.6.36/arch/sh/kernel/vsyscall/vsyscall.c linux-2.6.36-vs2.3.0.36.36/arch/sh/kernel/vsyscall/vsyscall.c
690 --- linux-2.6.36/arch/sh/kernel/vsyscall/vsyscall.c     2010-07-07 18:31:10.000000000 +0200
691 +++ linux-2.6.36-vs2.3.0.36.36/arch/sh/kernel/vsyscall/vsyscall.c       2010-10-21 13:09:36.000000000 +0200
692 @@ -18,6 +18,7 @@
693  #include <linux/elf.h>
694  #include <linux/sched.h>
695  #include <linux/err.h>
696 +#include <linux/vs_memory.h>
697  
698  /*
699   * Should the kernel map a VDSO page into processes and pass its
700 diff -NurpP --minimal linux-2.6.36/arch/sparc/include/asm/tlb_64.h linux-2.6.36-vs2.3.0.36.36/arch/sparc/include/asm/tlb_64.h
701 --- linux-2.6.36/arch/sparc/include/asm/tlb_64.h        2009-09-10 15:25:45.000000000 +0200
702 +++ linux-2.6.36-vs2.3.0.36.36/arch/sparc/include/asm/tlb_64.h  2010-10-21 13:09:36.000000000 +0200
703 @@ -3,6 +3,7 @@
704  
705  #include <linux/swap.h>
706  #include <linux/pagemap.h>
707 +#include <linux/vs_memory.h>
708  #include <asm/pgalloc.h>
709  #include <asm/tlbflush.h>
710  #include <asm/mmu_context.h>
711 diff -NurpP --minimal linux-2.6.36/arch/sparc/include/asm/unistd.h linux-2.6.36-vs2.3.0.36.36/arch/sparc/include/asm/unistd.h
712 --- linux-2.6.36/arch/sparc/include/asm/unistd.h        2010-10-21 13:06:58.000000000 +0200
713 +++ linux-2.6.36-vs2.3.0.36.36/arch/sparc/include/asm/unistd.h  2010-10-21 13:09:36.000000000 +0200
714 @@ -335,7 +335,7 @@
715  #define __NR_timer_getoverrun  264
716  #define __NR_timer_delete      265
717  #define __NR_timer_create      266
718 -/* #define __NR_vserver                267 Reserved for VSERVER */
719 +#define __NR_vserver           267
720  #define __NR_io_setup          268
721  #define __NR_io_destroy                269
722  #define __NR_io_submit         270
723 diff -NurpP --minimal linux-2.6.36/arch/sparc/Kconfig linux-2.6.36-vs2.3.0.36.36/arch/sparc/Kconfig
724 --- linux-2.6.36/arch/sparc/Kconfig     2010-10-21 13:06:58.000000000 +0200
725 +++ linux-2.6.36-vs2.3.0.36.36/arch/sparc/Kconfig       2010-10-21 13:09:36.000000000 +0200
726 @@ -565,6 +565,8 @@ source "fs/Kconfig"
727  
728  source "arch/sparc/Kconfig.debug"
729  
730 +source "kernel/vserver/Kconfig"
731 +
732  source "security/Kconfig"
733  
734  source "crypto/Kconfig"
735 diff -NurpP --minimal linux-2.6.36/arch/sparc/kernel/systbls_32.S linux-2.6.36-vs2.3.0.36.36/arch/sparc/kernel/systbls_32.S
736 --- linux-2.6.36/arch/sparc/kernel/systbls_32.S 2010-10-21 13:06:59.000000000 +0200
737 +++ linux-2.6.36-vs2.3.0.36.36/arch/sparc/kernel/systbls_32.S   2010-10-21 13:09:36.000000000 +0200
738 @@ -70,7 +70,7 @@ sys_call_table:
739  /*250*/        .long sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
740  /*255*/        .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
741  /*260*/        .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
742 -/*265*/        .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
743 +/*265*/        .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
744  /*270*/        .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
745  /*275*/        .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
746  /*280*/        .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
747 diff -NurpP --minimal linux-2.6.36/arch/sparc/kernel/systbls_64.S linux-2.6.36-vs2.3.0.36.36/arch/sparc/kernel/systbls_64.S
748 --- linux-2.6.36/arch/sparc/kernel/systbls_64.S 2010-10-21 13:06:59.000000000 +0200
749 +++ linux-2.6.36-vs2.3.0.36.36/arch/sparc/kernel/systbls_64.S   2010-10-21 13:09:36.000000000 +0200
750 @@ -71,7 +71,7 @@ sys_call_table32:
751  /*250*/        .word sys_mremap, compat_sys_sysctl, sys32_getsid, sys_fdatasync, sys32_nfsservctl
752         .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
753  /*260*/        .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
754 -       .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
755 +       .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
756  /*270*/        .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
757         .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
758  /*280*/        .word sys32_tee, sys_add_key, sys_request_key, sys_keyctl, compat_sys_openat
759 @@ -147,7 +147,7 @@ sys_call_table:
760  /*250*/        .word sys_64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
761         .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
762  /*260*/        .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
763 -       .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
764 +       .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
765  /*270*/        .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
766         .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
767  /*280*/        .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
768 diff -NurpP --minimal linux-2.6.36/arch/um/include/asm/tlb.h linux-2.6.36-vs2.3.0.36.36/arch/um/include/asm/tlb.h
769 --- linux-2.6.36/arch/um/include/asm/tlb.h      2009-09-10 15:25:46.000000000 +0200
770 +++ linux-2.6.36-vs2.3.0.36.36/arch/um/include/asm/tlb.h        2010-10-21 13:09:36.000000000 +0200
771 @@ -3,6 +3,7 @@
772  
773  #include <linux/pagemap.h>
774  #include <linux/swap.h>
775 +#include <linux/vs_memory.h>
776  #include <asm/percpu.h>
777  #include <asm/pgalloc.h>
778  #include <asm/tlbflush.h>
779 diff -NurpP --minimal linux-2.6.36/arch/um/include/shared/kern_constants.h linux-2.6.36-vs2.3.0.36.36/arch/um/include/shared/kern_constants.h
780 --- linux-2.6.36/arch/um/include/shared/kern_constants.h        1970-01-01 01:00:00.000000000 +0100
781 +++ linux-2.6.36-vs2.3.0.36.36/arch/um/include/shared/kern_constants.h  2010-10-21 13:09:36.000000000 +0200
782 @@ -0,0 +1 @@
783 +#include "../../../../include/generated/asm-offsets.h"
784 diff -NurpP --minimal linux-2.6.36/arch/um/include/shared/user_constants.h linux-2.6.36-vs2.3.0.36.36/arch/um/include/shared/user_constants.h
785 --- linux-2.6.36/arch/um/include/shared/user_constants.h        1970-01-01 01:00:00.000000000 +0100
786 +++ linux-2.6.36-vs2.3.0.36.36/arch/um/include/shared/user_constants.h  2010-10-21 13:09:36.000000000 +0200
787 @@ -0,0 +1,40 @@
788 +/*
789 + * DO NOT MODIFY.
790 + *
791 + * This file was generated by arch/um/Makefile
792 + *
793 + */
794 +
795 +#define HOST_SC_CR2 176 /* offsetof(struct sigcontext, cr2)    # */
796 +#define HOST_SC_ERR 152 /* offsetof(struct sigcontext, err)    # */
797 +#define HOST_SC_TRAPNO 160 /* offsetof(struct sigcontext, trapno)      # */
798 +#define HOST_FP_SIZE 64 /* sizeof(struct _fpstate) / sizeof(unsigned long)     # */
799 +#define HOST_RBX 5 /* RBX      # */
800 +#define HOST_RCX 11 /* RCX     # */
801 +#define HOST_RDI 14 /* RDI     # */
802 +#define HOST_RSI 13 /* RSI     # */
803 +#define HOST_RDX 12 /* RDX     # */
804 +#define HOST_RBP 4 /* RBP      # */
805 +#define HOST_RAX 10 /* RAX     # */
806 +#define HOST_R8 9 /* R8        # */
807 +#define HOST_R9 8 /* R9        # */
808 +#define HOST_R10 7 /* R10      # */
809 +#define HOST_R11 6 /* R11      # */
810 +#define HOST_R12 3 /* R12      # */
811 +#define HOST_R13 2 /* R13      # */
812 +#define HOST_R14 1 /* R14      # */
813 +#define HOST_R15 0 /* R15      # */
814 +#define HOST_ORIG_RAX 15 /* ORIG_RAX   # */
815 +#define HOST_CS 17 /* CS       # */
816 +#define HOST_SS 20 /* SS       # */
817 +#define HOST_EFLAGS 18 /* EFLAGS       # */
818 +#define HOST_IP 16 /* RIP      # */
819 +#define HOST_SP 19 /* RSP      # */
820 +#define UM_FRAME_SIZE 216 /* sizeof(struct user_regs_struct)   # */
821 +#define UM_POLLIN 1 /* POLLIN  # */
822 +#define UM_POLLPRI 2 /* POLLPRI        # */
823 +#define UM_POLLOUT 4 /* POLLOUT        # */
824 +#define UM_PROT_READ 1 /* PROT_READ    # */
825 +#define UM_PROT_WRITE 2 /* PROT_WRITE  # */
826 +#define UM_PROT_EXEC 4 /* PROT_EXEC    # */
827 +
828 diff -NurpP --minimal linux-2.6.36/arch/um/Kconfig.rest linux-2.6.36-vs2.3.0.36.36/arch/um/Kconfig.rest
829 --- linux-2.6.36/arch/um/Kconfig.rest   2009-06-11 17:12:19.000000000 +0200
830 +++ linux-2.6.36-vs2.3.0.36.36/arch/um/Kconfig.rest     2010-10-21 13:09:36.000000000 +0200
831 @@ -18,6 +18,8 @@ source "drivers/connector/Kconfig"
832  
833  source "fs/Kconfig"
834  
835 +source "kernel/vserver/Kconfig"
836 +
837  source "security/Kconfig"
838  
839  source "crypto/Kconfig"
840 diff -NurpP --minimal linux-2.6.36/arch/x86/ia32/ia32entry.S linux-2.6.36-vs2.3.0.36.36/arch/x86/ia32/ia32entry.S
841 --- linux-2.6.36/arch/x86/ia32/ia32entry.S      2010-10-21 13:06:59.000000000 +0200
842 +++ linux-2.6.36-vs2.3.0.36.36/arch/x86/ia32/ia32entry.S        2010-10-21 13:09:36.000000000 +0200
843 @@ -783,7 +783,7 @@ ia32_sys_call_table:
844         .quad sys_tgkill                /* 270 */
845         .quad compat_sys_utimes
846         .quad sys32_fadvise64_64
847 -       .quad quiet_ni_syscall  /* sys_vserver */
848 +       .quad sys32_vserver
849         .quad sys_mbind
850         .quad compat_sys_get_mempolicy  /* 275 */
851         .quad sys_set_mempolicy
852 diff -NurpP --minimal linux-2.6.36/arch/x86/include/asm/unistd_64.h linux-2.6.36-vs2.3.0.36.36/arch/x86/include/asm/unistd_64.h
853 --- linux-2.6.36/arch/x86/include/asm/unistd_64.h       2010-10-21 13:06:59.000000000 +0200
854 +++ linux-2.6.36-vs2.3.0.36.36/arch/x86/include/asm/unistd_64.h 2010-10-21 13:09:36.000000000 +0200
855 @@ -535,7 +535,7 @@ __SYSCALL(__NR_tgkill, sys_tgkill)
856  #define __NR_utimes                            235
857  __SYSCALL(__NR_utimes, sys_utimes)
858  #define __NR_vserver                           236
859 -__SYSCALL(__NR_vserver, sys_ni_syscall)
860 +__SYSCALL(__NR_vserver, sys_vserver)
861  #define __NR_mbind                             237
862  __SYSCALL(__NR_mbind, sys_mbind)
863  #define __NR_set_mempolicy                     238
864 diff -NurpP --minimal linux-2.6.36/arch/x86/Kconfig linux-2.6.36-vs2.3.0.36.36/arch/x86/Kconfig
865 --- linux-2.6.36/arch/x86/Kconfig       2010-10-21 13:06:59.000000000 +0200
866 +++ linux-2.6.36-vs2.3.0.36.36/arch/x86/Kconfig 2010-10-21 13:09:36.000000000 +0200
867 @@ -2135,6 +2135,8 @@ source "fs/Kconfig"
868  
869  source "arch/x86/Kconfig.debug"
870  
871 +source "kernel/vserver/Kconfig"
872 +
873  source "security/Kconfig"
874  
875  source "crypto/Kconfig"
876 diff -NurpP --minimal linux-2.6.36/arch/x86/kernel/syscall_table_32.S linux-2.6.36-vs2.3.0.36.36/arch/x86/kernel/syscall_table_32.S
877 --- linux-2.6.36/arch/x86/kernel/syscall_table_32.S     2010-10-21 13:07:00.000000000 +0200
878 +++ linux-2.6.36-vs2.3.0.36.36/arch/x86/kernel/syscall_table_32.S       2010-10-21 13:09:36.000000000 +0200
879 @@ -272,7 +272,7 @@ ENTRY(sys_call_table)
880         .long sys_tgkill        /* 270 */
881         .long sys_utimes
882         .long sys_fadvise64_64
883 -       .long sys_ni_syscall    /* sys_vserver */
884 +       .long sys_vserver
885         .long sys_mbind
886         .long sys_get_mempolicy
887         .long sys_set_mempolicy
888 diff -NurpP --minimal linux-2.6.36/Documentation/vserver/debug.txt linux-2.6.36-vs2.3.0.36.36/Documentation/vserver/debug.txt
889 --- linux-2.6.36/Documentation/vserver/debug.txt        1970-01-01 01:00:00.000000000 +0100
890 +++ linux-2.6.36-vs2.3.0.36.36/Documentation/vserver/debug.txt  2010-10-21 13:09:36.000000000 +0200
891 @@ -0,0 +1,154 @@
892 +
893 +debug_cvirt:
894 +
895 + 2   4 "vx_map_tgid: %p/%llx: %d -> %d"
896 +       "vx_rmap_tgid: %p/%llx: %d -> %d"
897 +
898 +debug_dlim:
899 +
900 + 0   1 "ALLOC (%p,#%d)%c inode (%d)"
901 +       "FREE  (%p,#%d)%c inode"
902 + 1   2 "ALLOC (%p,#%d)%c %lld bytes (%d)"
903 +       "FREE  (%p,#%d)%c %lld bytes"
904 + 2   4 "ADJUST: %lld,%lld on %ld,%ld [mult=%d]"
905 + 3   8 "ext3_has_free_blocks(%p): %lu<%lu+1, %c, %u!=%u r=%d"
906 +       "ext3_has_free_blocks(%p): free=%lu, root=%lu"
907 +       "rcu_free_dl_info(%p)"
908 + 4  10 "alloc_dl_info(%p,%d) = %p"
909 +       "dealloc_dl_info(%p)"
910 +       "get_dl_info(%p[#%d.%d])"
911 +       "put_dl_info(%p[#%d.%d])"
912 + 5  20 "alloc_dl_info(%p,%d)*"
913 + 6  40 "__hash_dl_info: %p[#%d]"
914 +       "__unhash_dl_info: %p[#%d]"
915 + 7  80 "locate_dl_info(%p,#%d) = %p"
916 +
917 +debug_misc:
918 +
919 + 0   1 "destroy_dqhash: %p [#0x%08x] c=%d"
920 +       "new_dqhash: %p [#0x%08x]"
921 +       "vroot[%d]_clr_dev: dev=%p[%lu,%d:%d]"
922 +       "vroot[%d]_get_real_bdev: dev=%p[%lu,%d:%d]"
923 +       "vroot[%d]_set_dev: dev=%p[%lu,%d:%d]"
924 +       "vroot_get_real_bdev not set"
925 + 1   2 "cow_break_link(»%s«)"
926 +       "temp copy Â»%s«"
927 + 2   4 "dentry_open(new): %p"
928 +       "dentry_open(old): %p"
929 +       "lookup_create(new): %p"
930 +       "old path Â»%s«"
931 +       "path_lookup(old): %d"
932 +       "vfs_create(new): %d"
933 +       "vfs_rename: %d"
934 +       "vfs_sendfile: %d"
935 + 3   8 "fput(new_file=%p[#%d])"
936 +       "fput(old_file=%p[#%d])"
937 + 4  10 "vx_info_kill(%p[#%d],%d,%d) = %d"
938 +       "vx_info_kill(%p[#%d],%d,%d)*"
939 + 5  20 "vs_reboot(%p[#%d],%d)"
940 + 6  40 "dropping task %p[#%u,%u] for %p[#%u,%u]"
941 +
942 +debug_net:
943 +
944 + 2   4 "nx_addr_conflict(%p,%p) %d.%d,%d.%d"
945 + 3   8 "inet_bind(%p) %d.%d.%d.%d, %d.%d.%d.%d, %d.%d.%d.%d"
946 +       "inet_bind(%p)* %p,%p;%lx %d.%d.%d.%d"
947 + 4  10 "ip_route_connect(%p) %p,%p;%lx"
948 + 5  20 "__addr_in_socket(%p,%d.%d.%d.%d) %p:%d.%d.%d.%d %p;%lx"
949 + 6  40 "sk,egf: %p [#%d] (from %d)"
950 +       "sk,egn: %p [#%d] (from %d)"
951 +       "sk,req: %p [#%d] (from %d)"
952 +       "sk: %p [#%d] (from %d)"
953 +       "tw: %p [#%d] (from %d)"
954 + 7  80 "__sock_recvmsg: %p[%p,%p,%p;%d]:%d/%d"
955 +       "__sock_sendmsg: %p[%p,%p,%p;%d]:%d/%d"
956 +
957 +debug_nid:
958 +
959 + 0   1 "__lookup_nx_info(#%u): %p[#%u]"
960 +       "alloc_nx_info(%d) = %p"
961 +       "create_nx_info(%d) (dynamic rejected)"
962 +       "create_nx_info(%d) = %p (already there)"
963 +       "create_nx_info(%d) = %p (new)"
964 +       "dealloc_nx_info(%p)"
965 + 1   2 "alloc_nx_info(%d)*"
966 +       "create_nx_info(%d)*"
967 + 2   4 "get_nx_info(%p[#%d.%d])"
968 +       "put_nx_info(%p[#%d.%d])"
969 + 3   8 "claim_nx_info(%p[#%d.%d.%d]) %p"
970 +       "clr_nx_info(%p[#%d.%d])"
971 +       "init_nx_info(%p[#%d.%d])"
972 +       "release_nx_info(%p[#%d.%d.%d]) %p"
973 +       "set_nx_info(%p[#%d.%d])"
974 + 4  10 "__hash_nx_info: %p[#%d]"
975 +       "__nx_dynamic_id: [#%d]"
976 +       "__unhash_nx_info: %p[#%d.%d.%d]"
977 + 5  20 "moved task %p into nxi:%p[#%d]"
978 +       "nx_migrate_task(%p,%p[#%d.%d.%d])"
979 +       "task_get_nx_info(%p)"
980 + 6  40 "nx_clear_persistent(%p[#%d])"
981 +
982 +debug_quota:
983 +
984 + 0   1 "quota_sync_dqh(%p,%d) discard inode %p"
985 + 1   2 "quota_sync_dqh(%p,%d)"
986 +       "sync_dquots(%p,%d)"
987 +       "sync_dquots_dqh(%p,%d)"
988 + 3   8 "do_quotactl(%p,%d,cmd=%d,id=%d,%p)"
989 +
990 +debug_switch:
991 +
992 + 0   1 "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]"
993 + 1   2 "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]"
994 + 4  10 "%s: (%s %s) returned %s with %d"
995 +
996 +debug_tag:
997 +
998 + 7  80 "dx_parse_tag(»%s«): %d:#%d"
999 +       "dx_propagate_tag(%p[#%lu.%d]): %d,%d"
1000 +
1001 +debug_xid:
1002 +
1003 + 0   1 "__lookup_vx_info(#%u): %p[#%u]"
1004 +       "alloc_vx_info(%d) = %p"
1005 +       "alloc_vx_info(%d)*"
1006 +       "create_vx_info(%d) (dynamic rejected)"
1007 +       "create_vx_info(%d) = %p (already there)"
1008 +       "create_vx_info(%d) = %p (new)"
1009 +       "dealloc_vx_info(%p)"
1010 +       "loc_vx_info(%d) = %p (found)"
1011 +       "loc_vx_info(%d) = %p (new)"
1012 +       "loc_vx_info(%d) = %p (not available)"
1013 + 1   2 "create_vx_info(%d)*"
1014 +       "loc_vx_info(%d)*"
1015 + 2   4 "get_vx_info(%p[#%d.%d])"
1016 +       "put_vx_info(%p[#%d.%d])"
1017 + 3   8 "claim_vx_info(%p[#%d.%d.%d]) %p"
1018 +       "clr_vx_info(%p[#%d.%d])"
1019 +       "init_vx_info(%p[#%d.%d])"
1020 +       "release_vx_info(%p[#%d.%d.%d]) %p"
1021 +       "set_vx_info(%p[#%d.%d])"
1022 + 4  10 "__hash_vx_info: %p[#%d]"
1023 +       "__unhash_vx_info: %p[#%d.%d.%d]"
1024 +       "__vx_dynamic_id: [#%d]"
1025 + 5  20 "enter_vx_info(%p[#%d],%p) %p[#%d,%p]"
1026 +       "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]"
1027 +       "moved task %p into vxi:%p[#%d]"
1028 +       "task_get_vx_info(%p)"
1029 +       "vx_migrate_task(%p,%p[#%d.%d])"
1030 + 6  40 "vx_clear_persistent(%p[#%d])"
1031 +       "vx_exit_init(%p[#%d],%p[#%d,%d,%d])"
1032 +       "vx_set_init(%p[#%d],%p[#%d,%d,%d])"
1033 +       "vx_set_persistent(%p[#%d])"
1034 +       "vx_set_reaper(%p[#%d],%p[#%d,%d])"
1035 + 7  80 "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]"
1036 +
1037 +
1038 +debug_limit:
1039 +
1040 + n 2^n "vx_acc_cres[%5d,%s,%2d]: %5d%s"
1041 +       "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
1042 +
1043 + m 2^m "vx_acc_page[%5d,%s,%2d]: %5d%s"
1044 +       "vx_acc_pages[%5d,%s,%2d]: %5d += %5d"
1045 +       "vx_pages_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
1046 diff -NurpP --minimal linux-2.6.36/drivers/block/Kconfig linux-2.6.36-vs2.3.0.36.36/drivers/block/Kconfig
1047 --- linux-2.6.36/drivers/block/Kconfig  2010-08-02 16:52:14.000000000 +0200
1048 +++ linux-2.6.36-vs2.3.0.36.36/drivers/block/Kconfig    2010-10-21 13:09:36.000000000 +0200
1049 @@ -273,6 +273,13 @@ config BLK_DEV_CRYPTOLOOP
1050  
1051  source "drivers/block/drbd/Kconfig"
1052  
1053 +config BLK_DEV_VROOT
1054 +       tristate "Virtual Root device support"
1055 +       depends on QUOTACTL
1056 +       ---help---
1057 +         Saying Y here will allow you to use quota/fs ioctls on a shared
1058 +         partition within a virtual server without compromising security.
1059 +
1060  config BLK_DEV_NBD
1061         tristate "Network block device support"
1062         depends on NET
1063 diff -NurpP --minimal linux-2.6.36/drivers/block/loop.c linux-2.6.36-vs2.3.0.36.36/drivers/block/loop.c
1064 --- linux-2.6.36/drivers/block/loop.c   2010-10-21 13:07:02.000000000 +0200
1065 +++ linux-2.6.36-vs2.3.0.36.36/drivers/block/loop.c     2010-10-21 13:11:25.000000000 +0200
1066 @@ -74,6 +74,7 @@
1067  #include <linux/highmem.h>
1068  #include <linux/kthread.h>
1069  #include <linux/splice.h>
1070 +#include <linux/vs_context.h>
1071  
1072  #include <asm/uaccess.h>
1073  
1074 @@ -814,6 +815,7 @@ static int loop_set_fd(struct loop_devic
1075         lo->lo_blocksize = lo_blocksize;
1076         lo->lo_device = bdev;
1077         lo->lo_flags = lo_flags;
1078 +       lo->lo_xid = vx_current_xid();
1079         lo->lo_backing_file = file;
1080         lo->transfer = transfer_none;
1081         lo->ioctl = NULL;
1082 @@ -942,6 +944,7 @@ static int loop_clr_fd(struct loop_devic
1083         lo->lo_encrypt_key_size = 0;
1084         lo->lo_flags = 0;
1085         lo->lo_thread = NULL;
1086 +       lo->lo_xid = 0;
1087         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
1088         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
1089         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
1090 @@ -979,7 +982,7 @@ loop_set_status(struct loop_device *lo, 
1091  
1092         if (lo->lo_encrypt_key_size &&
1093             lo->lo_key_owner != uid &&
1094 -           !capable(CAP_SYS_ADMIN))
1095 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
1096                 return -EPERM;
1097         if (lo->lo_state != Lo_bound)
1098                 return -ENXIO;
1099 @@ -1063,7 +1066,8 @@ loop_get_status(struct loop_device *lo, 
1100         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
1101         info->lo_encrypt_type =
1102                 lo->lo_encryption ? lo->lo_encryption->number : 0;
1103 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
1104 +       if (lo->lo_encrypt_key_size &&
1105 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
1106                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
1107                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
1108                        lo->lo_encrypt_key_size);
1109 @@ -1409,6 +1413,9 @@ static int lo_open(struct block_device *
1110  {
1111         struct loop_device *lo = bdev->bd_disk->private_data;
1112  
1113 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P))
1114 +               return -EACCES;
1115 +
1116         lock_kernel();
1117         mutex_lock(&lo->lo_ctl_mutex);
1118         lo->lo_refcnt++;
1119 diff -NurpP --minimal linux-2.6.36/drivers/block/Makefile linux-2.6.36-vs2.3.0.36.36/drivers/block/Makefile
1120 --- linux-2.6.36/drivers/block/Makefile 2010-02-25 11:51:36.000000000 +0100
1121 +++ linux-2.6.36-vs2.3.0.36.36/drivers/block/Makefile   2010-10-21 13:09:36.000000000 +0200
1122 @@ -34,6 +34,7 @@ obj-$(CONFIG_VIODASD)         += viodasd.o
1123  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
1124  obj-$(CONFIG_BLK_DEV_UB)       += ub.o
1125  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
1126 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
1127  
1128  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
1129  obj-$(CONFIG_BLK_DEV_DRBD)     += drbd/
1130 diff -NurpP --minimal linux-2.6.36/drivers/block/vroot.c linux-2.6.36-vs2.3.0.36.36/drivers/block/vroot.c
1131 --- linux-2.6.36/drivers/block/vroot.c  1970-01-01 01:00:00.000000000 +0100
1132 +++ linux-2.6.36-vs2.3.0.36.36/drivers/block/vroot.c    2010-10-21 13:09:36.000000000 +0200
1133 @@ -0,0 +1,282 @@
1134 +/*
1135 + *  linux/drivers/block/vroot.c
1136 + *
1137 + *  written by Herbert Pötzl, 9/11/2002
1138 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
1139 + *
1140 + *  based on the loop.c code by Theodore Ts'o.
1141 + *
1142 + * Copyright (C) 2002-2007 by Herbert Pötzl.
1143 + * Redistribution of this file is permitted under the
1144 + * GNU General Public License.
1145 + *
1146 + */
1147 +
1148 +#include <linux/module.h>
1149 +#include <linux/moduleparam.h>
1150 +#include <linux/file.h>
1151 +#include <linux/major.h>
1152 +#include <linux/blkdev.h>
1153 +#include <linux/slab.h>
1154 +
1155 +#include <linux/vroot.h>
1156 +#include <linux/vs_context.h>
1157 +
1158 +
1159 +static int max_vroot = 8;
1160 +
1161 +static struct vroot_device *vroot_dev;
1162 +static struct gendisk **disks;
1163 +
1164 +
1165 +static int vroot_set_dev(
1166 +       struct vroot_device *vr,
1167 +       struct block_device *bdev,
1168 +       unsigned int arg)
1169 +{
1170 +       struct block_device *real_bdev;
1171 +       struct file *file;
1172 +       struct inode *inode;
1173 +       int error;
1174 +
1175 +       error = -EBUSY;
1176 +       if (vr->vr_state != Vr_unbound)
1177 +               goto out;
1178 +
1179 +       error = -EBADF;
1180 +       file = fget(arg);
1181 +       if (!file)
1182 +               goto out;
1183 +
1184 +       error = -EINVAL;
1185 +       inode = file->f_dentry->d_inode;
1186 +
1187 +
1188 +       if (S_ISBLK(inode->i_mode)) {
1189 +               real_bdev = inode->i_bdev;
1190 +               vr->vr_device = real_bdev;
1191 +               __iget(real_bdev->bd_inode);
1192 +       } else
1193 +               goto out_fput;
1194 +
1195 +       vxdprintk(VXD_CBIT(misc, 0),
1196 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
1197 +               vr->vr_number, VXD_DEV(real_bdev));
1198 +
1199 +       vr->vr_state = Vr_bound;
1200 +       error = 0;
1201 +
1202 + out_fput:
1203 +       fput(file);
1204 + out:
1205 +       return error;
1206 +}
1207 +
1208 +static int vroot_clr_dev(
1209 +       struct vroot_device *vr,
1210 +       struct block_device *bdev)
1211 +{
1212 +       struct block_device *real_bdev;
1213 +
1214 +       if (vr->vr_state != Vr_bound)
1215 +               return -ENXIO;
1216 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
1217 +               return -EBUSY;
1218 +
1219 +       real_bdev = vr->vr_device;
1220 +
1221 +       vxdprintk(VXD_CBIT(misc, 0),
1222 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
1223 +               vr->vr_number, VXD_DEV(real_bdev));
1224 +
1225 +       bdput(real_bdev);
1226 +       vr->vr_state = Vr_unbound;
1227 +       vr->vr_device = NULL;
1228 +       return 0;
1229 +}
1230 +
1231 +
1232 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
1233 +       unsigned int cmd, unsigned long arg)
1234 +{
1235 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1236 +       int err;
1237 +
1238 +       down(&vr->vr_ctl_mutex);
1239 +       switch (cmd) {
1240 +       case VROOT_SET_DEV:
1241 +               err = vroot_set_dev(vr, bdev, arg);
1242 +               break;
1243 +       case VROOT_CLR_DEV:
1244 +               err = vroot_clr_dev(vr, bdev);
1245 +               break;
1246 +       default:
1247 +               err = -EINVAL;
1248 +               break;
1249 +       }
1250 +       up(&vr->vr_ctl_mutex);
1251 +       return err;
1252 +}
1253 +
1254 +static int vr_open(struct block_device *bdev, fmode_t mode)
1255 +{
1256 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1257 +
1258 +       down(&vr->vr_ctl_mutex);
1259 +       vr->vr_refcnt++;
1260 +       up(&vr->vr_ctl_mutex);
1261 +       return 0;
1262 +}
1263 +
1264 +static int vr_release(struct gendisk *disk, fmode_t mode)
1265 +{
1266 +       struct vroot_device *vr = disk->private_data;
1267 +
1268 +       down(&vr->vr_ctl_mutex);
1269 +       --vr->vr_refcnt;
1270 +       up(&vr->vr_ctl_mutex);
1271 +       return 0;
1272 +}
1273 +
1274 +static struct block_device_operations vr_fops = {
1275 +       .owner =        THIS_MODULE,
1276 +       .open =         vr_open,
1277 +       .release =      vr_release,
1278 +       .ioctl =        vr_ioctl,
1279 +};
1280 +
1281 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
1282 +{
1283 +       struct inode *inode = bdev->bd_inode;
1284 +       struct vroot_device *vr;
1285 +       struct block_device *real_bdev;
1286 +       int minor = iminor(inode);
1287 +
1288 +       vr = &vroot_dev[minor];
1289 +       real_bdev = vr->vr_device;
1290 +
1291 +       vxdprintk(VXD_CBIT(misc, 0),
1292 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1293 +               vr->vr_number, VXD_DEV(real_bdev));
1294 +
1295 +       if (vr->vr_state != Vr_bound)
1296 +               return ERR_PTR(-ENXIO);
1297 +
1298 +       __iget(real_bdev->bd_inode);
1299 +       return real_bdev;
1300 +}
1301 +
1302 +/*
1303 + * And now the modules code and kernel interface.
1304 + */
1305 +
1306 +module_param(max_vroot, int, 0);
1307 +
1308 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1309 +MODULE_LICENSE("GPL");
1310 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1311 +
1312 +MODULE_AUTHOR ("Herbert Pötzl");
1313 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1314 +
1315 +
1316 +int __init vroot_init(void)
1317 +{
1318 +       int err, i;
1319 +
1320 +       if (max_vroot < 1 || max_vroot > 256) {
1321 +               max_vroot = MAX_VROOT_DEFAULT;
1322 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1323 +                       "(must be between 1 and 256), "
1324 +                       "using default (%d)\n", max_vroot);
1325 +       }
1326 +
1327 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1328 +               return -EIO;
1329 +
1330 +       err = -ENOMEM;
1331 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1332 +       if (!vroot_dev)
1333 +               goto out_mem1;
1334 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1335 +
1336 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1337 +       if (!disks)
1338 +               goto out_mem2;
1339 +
1340 +       for (i = 0; i < max_vroot; i++) {
1341 +               disks[i] = alloc_disk(1);
1342 +               if (!disks[i])
1343 +                       goto out_mem3;
1344 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1345 +               if (!disks[i]->queue)
1346 +                       goto out_mem3;
1347 +       }
1348 +
1349 +       for (i = 0; i < max_vroot; i++) {
1350 +               struct vroot_device *vr = &vroot_dev[i];
1351 +               struct gendisk *disk = disks[i];
1352 +
1353 +               memset(vr, 0, sizeof(*vr));
1354 +               init_MUTEX(&vr->vr_ctl_mutex);
1355 +               vr->vr_number = i;
1356 +               disk->major = VROOT_MAJOR;
1357 +               disk->first_minor = i;
1358 +               disk->fops = &vr_fops;
1359 +               sprintf(disk->disk_name, "vroot%d", i);
1360 +               disk->private_data = vr;
1361 +       }
1362 +
1363 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1364 +       if (err)
1365 +               goto out_mem3;
1366 +
1367 +       for (i = 0; i < max_vroot; i++)
1368 +               add_disk(disks[i]);
1369 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1370 +       return 0;
1371 +
1372 +out_mem3:
1373 +       while (i--)
1374 +               put_disk(disks[i]);
1375 +       kfree(disks);
1376 +out_mem2:
1377 +       kfree(vroot_dev);
1378 +out_mem1:
1379 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1380 +       printk(KERN_ERR "vroot: ran out of memory\n");
1381 +       return err;
1382 +}
1383 +
1384 +void vroot_exit(void)
1385 +{
1386 +       int i;
1387 +
1388 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1389 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1390 +
1391 +       for (i = 0; i < max_vroot; i++) {
1392 +               del_gendisk(disks[i]);
1393 +               put_disk(disks[i]);
1394 +       }
1395 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1396 +
1397 +       kfree(disks);
1398 +       kfree(vroot_dev);
1399 +}
1400 +
1401 +module_init(vroot_init);
1402 +module_exit(vroot_exit);
1403 +
1404 +#ifndef MODULE
1405 +
1406 +static int __init max_vroot_setup(char *str)
1407 +{
1408 +       max_vroot = simple_strtol(str, NULL, 0);
1409 +       return 1;
1410 +}
1411 +
1412 +__setup("max_vroot=", max_vroot_setup);
1413 +
1414 +#endif
1415 +
1416 diff -NurpP --minimal linux-2.6.36/drivers/char/sysrq.c linux-2.6.36-vs2.3.0.36.36/drivers/char/sysrq.c
1417 --- linux-2.6.36/drivers/char/sysrq.c   2010-10-21 13:07:02.000000000 +0200
1418 +++ linux-2.6.36-vs2.3.0.36.36/drivers/char/sysrq.c     2010-10-21 13:09:36.000000000 +0200
1419 @@ -41,6 +41,7 @@
1420  #include <linux/oom.h>
1421  #include <linux/slab.h>
1422  #include <linux/input.h>
1423 +#include <linux/vserver/debug.h>
1424  
1425  #include <asm/ptrace.h>
1426  #include <asm/irq_regs.h>
1427 @@ -395,6 +396,21 @@ static struct sysrq_key_op sysrq_unrt_op
1428         .enable_mask    = SYSRQ_ENABLE_RTNICE,
1429  };
1430  
1431 +
1432 +#ifdef CONFIG_VSERVER_DEBUG
1433 +static void sysrq_handle_vxinfo(int key, struct tty_struct *tty)
1434 +{
1435 +       dump_vx_info_inactive((key == 'x')?0:1);
1436 +}
1437 +
1438 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1439 +       .handler        = sysrq_handle_vxinfo,
1440 +       .help_msg       = "conteXt",
1441 +       .action_msg     = "Show Context Info",
1442 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
1443 +};
1444 +#endif
1445 +
1446  /* Key Operations table and lock */
1447  static DEFINE_SPINLOCK(sysrq_key_table_lock);
1448  
1449 @@ -449,7 +465,11 @@ static struct sysrq_key_op *sysrq_key_ta
1450         NULL,                           /* v */
1451         &sysrq_showstate_blocked_op,    /* w */
1452         /* x: May be registered on ppc/powerpc for xmon */
1453 +#ifdef CONFIG_VSERVER_DEBUG
1454 +       &sysrq_showvxinfo_op,           /* x */
1455 +#else
1456         NULL,                           /* x */
1457 +#endif
1458         /* y: May be registered on sparc64 for global register dump */
1459         NULL,                           /* y */
1460         &sysrq_ftrace_dump_op,          /* z */
1461 @@ -464,6 +484,8 @@ static int sysrq_key_table_key2index(int
1462                 retval = key - '0';
1463         else if ((key >= 'a') && (key <= 'z'))
1464                 retval = key + 10 - 'a';
1465 +       else if ((key >= 'A') && (key <= 'Z'))
1466 +               retval = key + 10 - 'A';
1467         else
1468                 retval = -1;
1469         return retval;
1470 diff -NurpP --minimal linux-2.6.36/drivers/char/tty_io.c linux-2.6.36-vs2.3.0.36.36/drivers/char/tty_io.c
1471 --- linux-2.6.36/drivers/char/tty_io.c  2010-10-21 13:07:02.000000000 +0200
1472 +++ linux-2.6.36-vs2.3.0.36.36/drivers/char/tty_io.c    2010-10-21 13:09:36.000000000 +0200
1473 @@ -106,6 +106,7 @@
1474  
1475  #include <linux/kmod.h>
1476  #include <linux/nsproxy.h>
1477 +#include <linux/vs_pid.h>
1478  
1479  #undef TTY_DEBUG_HANGUP
1480  
1481 @@ -2038,7 +2039,8 @@ static int tiocsti(struct tty_struct *tt
1482         char ch, mbz = 0;
1483         struct tty_ldisc *ld;
1484  
1485 -       if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
1486 +       if (((current->signal->tty != tty) &&
1487 +               !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
1488                 return -EPERM;
1489         if (get_user(ch, p))
1490                 return -EFAULT;
1491 @@ -2326,6 +2328,7 @@ static int tiocspgrp(struct tty_struct *
1492                 return -ENOTTY;
1493         if (get_user(pgrp_nr, p))
1494                 return -EFAULT;
1495 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
1496         if (pgrp_nr < 0)
1497                 return -EINVAL;
1498         rcu_read_lock();
1499 diff -NurpP --minimal linux-2.6.36/drivers/gpu/drm/radeon/r100_reg_safe.h linux-2.6.36-vs2.3.0.36.36/drivers/gpu/drm/radeon/r100_reg_safe.h
1500 --- linux-2.6.36/drivers/gpu/drm/radeon/r100_reg_safe.h 1970-01-01 01:00:00.000000000 +0100
1501 +++ linux-2.6.36-vs2.3.0.36.36/drivers/gpu/drm/radeon/r100_reg_safe.h   2010-10-21 13:09:36.000000000 +0200
1502 @@ -0,0 +1,28 @@
1503 +static const unsigned r100_reg_safe_bm[102] = {
1504 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1505 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1506 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1507 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1508 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1509 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1510 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1511 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1512 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1513 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1514 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1515 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1516 +       0xFFFFFFCF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1517 +       0xFFFFFF9F, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1518 +       0x38E7FE1F, 0xFFC3FF8E, 0x7FF8FFFF, 0xFFFF803C,
1519 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1520 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFEFFFF, 0xFFFFFFFF,
1521 +       0x00000000, 0xFFFFFFFD, 0xFFFFFFFF, 0xFFFFFFFF,
1522 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1523 +       0xFFFFFFFF, 0xFFFCFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1524 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1525 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1526 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1527 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1528 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1529 +       0xFFFFFFFF, 0xFFFFFFEF,
1530 +};
1531 diff -NurpP --minimal linux-2.6.36/drivers/gpu/drm/radeon/r200_reg_safe.h linux-2.6.36-vs2.3.0.36.36/drivers/gpu/drm/radeon/r200_reg_safe.h
1532 --- linux-2.6.36/drivers/gpu/drm/radeon/r200_reg_safe.h 1970-01-01 01:00:00.000000000 +0100
1533 +++ linux-2.6.36-vs2.3.0.36.36/drivers/gpu/drm/radeon/r200_reg_safe.h   2010-10-21 13:09:36.000000000 +0200
1534 @@ -0,0 +1,28 @@
1535 +static const unsigned r200_reg_safe_bm[102] = {
1536 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1537 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1538 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1539 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1540 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1541 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1542 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1543 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1544 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1545 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1546 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1547 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1548 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1549 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1550 +       0xFFE7FE1F, 0xF003FFFF, 0x7EFFFFFF, 0xFFFF803C,
1551 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1552 +       0xFFFFFFFF, 0xFFFFEFCE, 0xFFFEFFFF, 0xFFFFFFFE,
1553 +       0x020E0FF0, 0xFFCC83FD, 0xFFFFFFFF, 0xFFFFFFFF,
1554 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1555 +       0xFFFBFFFF, 0xEFFCFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1556 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1557 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1558 +       0xDFDFDFDF, 0x3FFDDFDF, 0xFFFFFFFF, 0xFFFFFF7F,
1559 +       0xFFFFFFFF, 0x00FFFFFF, 0x00000000, 0x00000000,
1560 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1561 +       0xFFFFFE3F, 0xFFFFFFEF,
1562 +};
1563 diff -NurpP --minimal linux-2.6.36/drivers/gpu/drm/radeon/r300_reg_safe.h linux-2.6.36-vs2.3.0.36.36/drivers/gpu/drm/radeon/r300_reg_safe.h
1564 --- linux-2.6.36/drivers/gpu/drm/radeon/r300_reg_safe.h 1970-01-01 01:00:00.000000000 +0100
1565 +++ linux-2.6.36-vs2.3.0.36.36/drivers/gpu/drm/radeon/r300_reg_safe.h   2010-10-21 13:09:36.000000000 +0200
1566 @@ -0,0 +1,42 @@
1567 +static const unsigned r300_reg_safe_bm[159] = {
1568 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1569 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1570 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1571 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1572 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1573 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1574 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1575 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1576 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1577 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1578 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1579 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1580 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1581 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1582 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF03F,
1583 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1584 +       0xFFFFFFFF, 0xFFFFEFCE, 0xF00EBFFF, 0x007C0000,
1585 +       0xF0000078, 0xFF000009, 0xFFFFFFFF, 0xFFFFFFFF,
1586 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1587 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1588 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1589 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1590 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1591 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1592 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1593 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1594 +       0xFFFFF7FF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1595 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1596 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1597 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1598 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1599 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1600 +       0xFFFFFC78, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF,
1601 +       0x38FF8F50, 0xFFF88082, 0xF000000C, 0xFAE009FF,
1602 +       0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
1603 +       0x00000000, 0x0000C100, 0x00000000, 0x00000000,
1604 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1605 +       0x00000000, 0xFFFF0000, 0xFFFFFFFF, 0xFF80FFFF,
1606 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1607 +       0x0003FC01, 0xFFFFFCF8, 0xFF800B19,
1608 +};
1609 diff -NurpP --minimal linux-2.6.36/drivers/gpu/drm/radeon/r420_reg_safe.h linux-2.6.36-vs2.3.0.36.36/drivers/gpu/drm/radeon/r420_reg_safe.h
1610 --- linux-2.6.36/drivers/gpu/drm/radeon/r420_reg_safe.h 1970-01-01 01:00:00.000000000 +0100
1611 +++ linux-2.6.36-vs2.3.0.36.36/drivers/gpu/drm/radeon/r420_reg_safe.h   2010-10-21 13:09:36.000000000 +0200
1612 @@ -0,0 +1,42 @@
1613 +static const unsigned r420_reg_safe_bm[159] = {
1614 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1615 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1616 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1617 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1618 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1619 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1620 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1621 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1622 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1623 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1624 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1625 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1626 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1627 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1628 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF03F,
1629 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1630 +       0xFFFFFFFF, 0xFFFFEFCE, 0xF00EBFFF, 0x007C0000,
1631 +       0xF0000078, 0xFF000009, 0xFFFFFFFF, 0xFFFFFFFF,
1632 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1633 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1634 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1635 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1636 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1637 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1638 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1639 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1640 +       0xFFFFF7FF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1641 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1642 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1643 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1644 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1645 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1646 +       0xFFFFFC78, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF,
1647 +       0x38FF8F50, 0xFFF88082, 0xF000000C, 0xFAE009FF,
1648 +       0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
1649 +       0x00000000, 0x00000100, 0x00000000, 0x00000000,
1650 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1651 +       0x00000000, 0x00000000, 0x00000000, 0xFF800000,
1652 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1653 +       0x0003FC01, 0xFFFFFCF8, 0xFF800B19,
1654 +};
1655 diff -NurpP --minimal linux-2.6.36/drivers/gpu/drm/radeon/rn50_reg_safe.h linux-2.6.36-vs2.3.0.36.36/drivers/gpu/drm/radeon/rn50_reg_safe.h
1656 --- linux-2.6.36/drivers/gpu/drm/radeon/rn50_reg_safe.h 1970-01-01 01:00:00.000000000 +0100
1657 +++ linux-2.6.36-vs2.3.0.36.36/drivers/gpu/drm/radeon/rn50_reg_safe.h   2010-10-21 13:09:36.000000000 +0200
1658 @@ -0,0 +1,28 @@
1659 +static const unsigned rn50_reg_safe_bm[102] = {
1660 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1661 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1662 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1663 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1664 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1665 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1666 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1667 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1668 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1669 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1670 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1671 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1672 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1673 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1674 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1675 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1676 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1677 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1678 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1679 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1680 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1681 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1682 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1683 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1684 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1685 +       0xFFFFFFFF, 0xFFFFFFFF,
1686 +};
1687 diff -NurpP --minimal linux-2.6.36/drivers/gpu/drm/radeon/rs600_reg_safe.h linux-2.6.36-vs2.3.0.36.36/drivers/gpu/drm/radeon/rs600_reg_safe.h
1688 --- linux-2.6.36/drivers/gpu/drm/radeon/rs600_reg_safe.h        1970-01-01 01:00:00.000000000 +0100
1689 +++ linux-2.6.36-vs2.3.0.36.36/drivers/gpu/drm/radeon/rs600_reg_safe.h  2010-10-21 13:09:36.000000000 +0200
1690 @@ -0,0 +1,57 @@
1691 +static const unsigned rs600_reg_safe_bm[219] = {
1692 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1693 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1694 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1695 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1696 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1697 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1698 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1699 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1700 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1701 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1702 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1703 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1704 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1705 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1706 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF03F,
1707 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1708 +       0xFFFFFFFF, 0xFFFFEFCE, 0xF00EBFFF, 0x007C0000,
1709 +       0xF0000078, 0xFF000009, 0xFFFFFFFF, 0xFFFFFFFF,
1710 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1711 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1712 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1713 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1714 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1715 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1716 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1717 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1718 +       0xFFFFF7FF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1719 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1720 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1721 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1722 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1723 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1724 +       0xFFFFFC78, 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFF,
1725 +       0x38FF8F50, 0xFFF88082, 0xF000000C, 0xFAE009FF,
1726 +       0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
1727 +       0x00000000, 0x00000100, 0x00000000, 0x00000000,
1728 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1729 +       0x00000000, 0x00000000, 0x00000000, 0xFF800000,
1730 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1731 +       0x0003FC01, 0xFFFFFCF8, 0xFF800B19, 0xFFFFFFFF,
1732 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1733 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1734 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1735 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1736 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1737 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1738 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1739 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1740 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1741 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1742 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1743 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1744 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1745 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1746 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1747 +};
1748 diff -NurpP --minimal linux-2.6.36/drivers/gpu/drm/radeon/rv515_reg_safe.h linux-2.6.36-vs2.3.0.36.36/drivers/gpu/drm/radeon/rv515_reg_safe.h
1749 --- linux-2.6.36/drivers/gpu/drm/radeon/rv515_reg_safe.h        1970-01-01 01:00:00.000000000 +0100
1750 +++ linux-2.6.36-vs2.3.0.36.36/drivers/gpu/drm/radeon/rv515_reg_safe.h  2010-10-21 13:09:36.000000000 +0200
1751 @@ -0,0 +1,57 @@
1752 +static const unsigned rv515_reg_safe_bm[219] = {
1753 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1754 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1755 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1756 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1757 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1758 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1759 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1760 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1761 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1762 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1763 +       0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
1764 +       0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
1765 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1766 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1767 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF03F,
1768 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1769 +       0xFFFFFFFF, 0xFFFFEFCE, 0xF00EBFFF, 0x007C0000,
1770 +       0xF0000038, 0xFF000009, 0xFFFFFFFF, 0xFFFFFFFF,
1771 +       0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0xFFFFFFFF,
1772 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1773 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1774 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1775 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1776 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1777 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1778 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1779 +       0xFFFFF7FF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1780 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1781 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1782 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1783 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1784 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1785 +       0x1FFFF878, 0xFFFFE000, 0xFFFFFE1E, 0xFFFFFFFF,
1786 +       0x388F8F50, 0xFFF88082, 0xFF0000FC, 0xFAE009FF,
1787 +       0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
1788 +       0xFFFF8CFC, 0xFFFFC1FF, 0xFFFFFFFF, 0xFFFFFFFF,
1789 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1790 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFF80FFFF,
1791 +       0x00000000, 0x00000000, 0x00000000, 0x00000000,
1792 +       0x0003FC01, 0x3FFFFCF8, 0xFF800B19, 0xFFDFFFFF,
1793 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1794 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1795 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1796 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1797 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1798 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1799 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1800 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1801 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1802 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1803 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1804 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1805 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1806 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1807 +       0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
1808 +};
1809 diff -NurpP --minimal linux-2.6.36/drivers/infiniband/core/addr.c linux-2.6.36-vs2.3.0.36.36/drivers/infiniband/core/addr.c
1810 --- linux-2.6.36/drivers/infiniband/core/addr.c 2010-10-21 13:07:05.000000000 +0200
1811 +++ linux-2.6.36-vs2.3.0.36.36/drivers/infiniband/core/addr.c   2010-10-21 13:09:36.000000000 +0200
1812 @@ -252,7 +252,7 @@ static int addr6_resolve(struct sockaddr
1813  
1814         if (ipv6_addr_any(&fl.fl6_src)) {
1815                 ret = ipv6_dev_get_saddr(&init_net, ip6_dst_idev(dst)->dev,
1816 -                                        &fl.fl6_dst, 0, &fl.fl6_src);
1817 +                                        &fl.fl6_dst, 0, &fl.fl6_src, NULL);
1818                 if (ret)
1819                         goto put;
1820  
1821 diff -NurpP --minimal linux-2.6.36/drivers/infiniband/hw/ipath/ipath_user_pages.c linux-2.6.36-vs2.3.0.36.36/drivers/infiniband/hw/ipath/ipath_user_pages.c
1822 --- linux-2.6.36/drivers/infiniband/hw/ipath/ipath_user_pages.c 2010-07-07 18:31:19.000000000 +0200
1823 +++ linux-2.6.36-vs2.3.0.36.36/drivers/infiniband/hw/ipath/ipath_user_pages.c   2010-10-21 13:09:36.000000000 +0200
1824 @@ -35,6 +35,7 @@
1825  #include <linux/device.h>
1826  #include <linux/slab.h>
1827  #include <linux/sched.h>
1828 +#include <linux/vs_memory.h>
1829  
1830  #include "ipath_kernel.h"
1831  
1832 diff -NurpP --minimal linux-2.6.36/drivers/md/dm.c linux-2.6.36-vs2.3.0.36.36/drivers/md/dm.c
1833 --- linux-2.6.36/drivers/md/dm.c        2010-10-21 13:07:07.000000000 +0200
1834 +++ linux-2.6.36-vs2.3.0.36.36/drivers/md/dm.c  2010-10-21 15:19:30.000000000 +0200
1835 @@ -21,6 +21,7 @@
1836  #include <linux/idr.h>
1837  #include <linux/hdreg.h>
1838  #include <linux/delay.h>
1839 +#include <linux/vs_base.h>
1840  
1841  #include <trace/events/block.h>
1842  
1843 @@ -121,6 +122,7 @@ struct mapped_device {
1844         rwlock_t map_lock;
1845         atomic_t holders;
1846         atomic_t open_count;
1847 +       xid_t xid;
1848  
1849         unsigned long flags;
1850  
1851 @@ -343,6 +345,7 @@ int dm_deleting_md(struct mapped_device 
1852  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1853  {
1854         struct mapped_device *md;
1855 +       int ret = -ENXIO;
1856  
1857         lock_kernel();
1858         spin_lock(&_minor_lock);
1859 @@ -352,19 +355,20 @@ static int dm_blk_open(struct block_devi
1860                 goto out;
1861  
1862         if (test_bit(DMF_FREEING, &md->flags) ||
1863 -           dm_deleting_md(md)) {
1864 -               md = NULL;
1865 +           dm_deleting_md(md))
1866 +               goto out;
1867 +
1868 +       ret = -EACCES;
1869 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1870                 goto out;
1871 -       }
1872  
1873         dm_get(md);
1874         atomic_inc(&md->open_count);
1875 -
1876 +       ret = 0;
1877  out:
1878         spin_unlock(&_minor_lock);
1879         unlock_kernel();
1880 -
1881 -       return md ? 0 : -ENXIO;
1882 +       return ret;
1883  }
1884  
1885  static int dm_blk_close(struct gendisk *disk, fmode_t mode)
1886 @@ -586,6 +590,14 @@ int dm_set_geometry(struct mapped_device
1887         return 0;
1888  }
1889  
1890 +/*
1891 + * Get the xid associated with a dm device
1892 + */
1893 +xid_t dm_get_xid(struct mapped_device *md)
1894 +{
1895 +       return md->xid;
1896 +}
1897 +
1898  /*-----------------------------------------------------------------
1899   * CRUD START:
1900   *   A more elegant soln is in the works that uses the queue
1901 @@ -1981,6 +1993,7 @@ static struct mapped_device *alloc_dev(i
1902         INIT_LIST_HEAD(&md->uevent_list);
1903         spin_lock_init(&md->uevent_lock);
1904  
1905 +       md->xid = vx_current_xid();
1906         md->queue = blk_alloc_queue(GFP_KERNEL);
1907         if (!md->queue)
1908                 goto bad_queue;
1909 diff -NurpP --minimal linux-2.6.36/drivers/md/dm.h linux-2.6.36-vs2.3.0.36.36/drivers/md/dm.h
1910 --- linux-2.6.36/drivers/md/dm.h        2010-10-21 13:07:07.000000000 +0200
1911 +++ linux-2.6.36-vs2.3.0.36.36/drivers/md/dm.h  2010-10-21 13:09:36.000000000 +0200
1912 @@ -41,6 +41,8 @@ struct dm_dev_internal {
1913  struct dm_table;
1914  struct dm_md_mempools;
1915  
1916 +xid_t dm_get_xid(struct mapped_device *md);
1917 +
1918  /*-----------------------------------------------------------------
1919   * Internal table functions.
1920   *---------------------------------------------------------------*/
1921 diff -NurpP --minimal linux-2.6.36/drivers/md/dm-ioctl.c linux-2.6.36-vs2.3.0.36.36/drivers/md/dm-ioctl.c
1922 --- linux-2.6.36/drivers/md/dm-ioctl.c  2010-10-21 13:07:07.000000000 +0200
1923 +++ linux-2.6.36-vs2.3.0.36.36/drivers/md/dm-ioctl.c    2010-10-21 13:09:36.000000000 +0200
1924 @@ -16,6 +16,7 @@
1925  #include <linux/dm-ioctl.h>
1926  #include <linux/hdreg.h>
1927  #include <linux/compat.h>
1928 +#include <linux/vs_context.h>
1929  
1930  #include <asm/uaccess.h>
1931  
1932 @@ -106,7 +107,8 @@ static struct hash_cell *__get_name_cell
1933         unsigned int h = hash_str(str);
1934  
1935         list_for_each_entry (hc, _name_buckets + h, name_list)
1936 -               if (!strcmp(hc->name, str)) {
1937 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1938 +                       !strcmp(hc->name, str)) {
1939                         dm_get(hc->md);
1940                         return hc;
1941                 }
1942 @@ -120,7 +122,8 @@ static struct hash_cell *__get_uuid_cell
1943         unsigned int h = hash_str(str);
1944  
1945         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1946 -               if (!strcmp(hc->uuid, str)) {
1947 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1948 +                       !strcmp(hc->uuid, str)) {
1949                         dm_get(hc->md);
1950                         return hc;
1951                 }
1952 @@ -377,6 +380,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl 
1953  
1954  static int remove_all(struct dm_ioctl *param, size_t param_size)
1955  {
1956 +       if (!vx_check(0, VS_ADMIN))
1957 +               return -EPERM;
1958 +
1959         dm_hash_remove_all(1);
1960         param->data_size = 0;
1961         return 0;
1962 @@ -424,6 +430,8 @@ static int list_devices(struct dm_ioctl 
1963          */
1964         for (i = 0; i < NUM_BUCKETS; i++) {
1965                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1966 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1967 +                               continue;
1968                         needed += sizeof(struct dm_name_list);
1969                         needed += strlen(hc->name) + 1;
1970                         needed += ALIGN_MASK;
1971 @@ -447,6 +455,8 @@ static int list_devices(struct dm_ioctl 
1972          */
1973         for (i = 0; i < NUM_BUCKETS; i++) {
1974                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1975 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1976 +                               continue;
1977                         if (old_nl)
1978                                 old_nl->next = (uint32_t) ((void *) nl -
1979                                                            (void *) old_nl);
1980 @@ -681,10 +691,11 @@ static struct hash_cell *__find_device_h
1981         if (!md)
1982                 goto out;
1983  
1984 -       mdptr = dm_get_mdptr(md);
1985 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1986 +               mdptr = dm_get_mdptr(md);
1987 +
1988         if (!mdptr)
1989                 dm_put(md);
1990 -
1991  out:
1992         return mdptr;
1993  }
1994 @@ -1513,8 +1524,8 @@ static int ctl_ioctl(uint command, struc
1995         ioctl_fn fn = NULL;
1996         size_t param_size;
1997  
1998 -       /* only root can play with this */
1999 -       if (!capable(CAP_SYS_ADMIN))
2000 +       /* only root and certain contexts can play with this */
2001 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
2002                 return -EACCES;
2003  
2004         if (_IOC_TYPE(command) != DM_IOCTL)
2005 diff -NurpP --minimal linux-2.6.36/drivers/net/tun.c linux-2.6.36-vs2.3.0.36.36/drivers/net/tun.c
2006 --- linux-2.6.36/drivers/net/tun.c      2010-10-21 13:07:15.000000000 +0200
2007 +++ linux-2.6.36-vs2.3.0.36.36/drivers/net/tun.c        2010-10-21 13:09:36.000000000 +0200
2008 @@ -62,6 +62,7 @@
2009  #include <linux/nsproxy.h>
2010  #include <linux/virtio_net.h>
2011  #include <linux/rcupdate.h>
2012 +#include <linux/vs_network.h>
2013  #include <net/net_namespace.h>
2014  #include <net/netns/generic.h>
2015  #include <net/rtnetlink.h>
2016 @@ -103,6 +104,7 @@ struct tun_struct {
2017         unsigned int            flags;
2018         uid_t                   owner;
2019         gid_t                   group;
2020 +       nid_t                   nid;
2021  
2022         struct net_device       *dev;
2023         struct fasync_struct    *fasync;
2024 @@ -853,6 +855,7 @@ static void tun_setup(struct net_device 
2025  
2026         tun->owner = -1;
2027         tun->group = -1;
2028 +       tun->nid = current->nid;
2029  
2030         dev->ethtool_ops = &tun_ethtool_ops;
2031         dev->destructor = tun_free_netdev;
2032 @@ -1003,7 +1006,7 @@ static int tun_set_iff(struct net *net, 
2033  
2034                 if (((tun->owner != -1 && cred->euid != tun->owner) ||
2035                      (tun->group != -1 && !in_egroup_p(tun->group))) &&
2036 -                   !capable(CAP_NET_ADMIN))
2037 +               !cap_raised(current_cap(), CAP_NET_ADMIN))
2038                         return -EPERM;
2039                 err = security_tun_dev_attach(tun->socket.sk);
2040                 if (err < 0)
2041 @@ -1017,7 +1020,7 @@ static int tun_set_iff(struct net *net, 
2042                 char *name;
2043                 unsigned long flags = 0;
2044  
2045 -               if (!capable(CAP_NET_ADMIN))
2046 +               if (!nx_capable(CAP_NET_ADMIN, NXC_TUN_CREATE))
2047                         return -EPERM;
2048                 err = security_tun_dev_create();
2049                 if (err < 0)
2050 @@ -1087,6 +1090,9 @@ static int tun_set_iff(struct net *net, 
2051  
2052                 sk->sk_destruct = tun_sock_destruct;
2053  
2054 +               if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
2055 +                       return -EPERM;
2056 +
2057                 err = tun_attach(tun, file);
2058                 if (err < 0)
2059                         goto failed;
2060 @@ -1278,6 +1284,16 @@ static long __tun_chr_ioctl(struct file 
2061                 DBG(KERN_INFO "%s: group set to %d\n", tun->dev->name, tun->group);
2062                 break;
2063  
2064 +       case TUNSETNID:
2065 +               if (!capable(CAP_CONTEXT))
2066 +                       return -EPERM;
2067 +
2068 +               /* Set nid owner of the device */
2069 +               tun->nid = (nid_t) arg;
2070 +
2071 +               DBG(KERN_INFO "%s: nid owner set to %u\n", tun->dev->name, tun->nid);
2072 +               break;
2073 +
2074         case TUNSETLINK:
2075                 /* Only allow setting the type when the interface is down */
2076                 if (tun->dev->flags & IFF_UP) {
2077 diff -NurpP --minimal linux-2.6.36/fs/attr.c linux-2.6.36-vs2.3.0.36.36/fs/attr.c
2078 --- linux-2.6.36/fs/attr.c      2010-10-21 13:07:47.000000000 +0200
2079 +++ linux-2.6.36-vs2.3.0.36.36/fs/attr.c        2010-10-21 14:04:40.000000000 +0200
2080 @@ -13,6 +13,9 @@
2081  #include <linux/fsnotify.h>
2082  #include <linux/fcntl.h>
2083  #include <linux/security.h>
2084 +#include <linux/proc_fs.h>
2085 +#include <linux/devpts_fs.h>
2086 +#include <linux/vs_tag.h>
2087  
2088  /**
2089   * inode_change_ok - check if attribute changes to an inode are allowed
2090 @@ -73,6 +76,10 @@ int inode_change_ok(const struct inode *
2091                         return -EPERM;
2092         }
2093  
2094 +       /* check for inode tag permission */
2095 +       if (dx_permission(inode, MAY_WRITE))
2096 +               return -EACCES;
2097 +
2098         return 0;
2099  }
2100  EXPORT_SYMBOL(inode_change_ok);
2101 @@ -143,6 +150,8 @@ void setattr_copy(struct inode *inode, c
2102                 inode->i_uid = attr->ia_uid;
2103         if (ia_valid & ATTR_GID)
2104                 inode->i_gid = attr->ia_gid;
2105 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2106 +               inode->i_tag = attr->ia_tag;
2107         if (ia_valid & ATTR_ATIME)
2108                 inode->i_atime = timespec_trunc(attr->ia_atime,
2109                                                 inode->i_sb->s_time_gran);
2110 @@ -170,7 +179,8 @@ int notify_change(struct dentry * dentry
2111         struct timespec now;
2112         unsigned int ia_valid = attr->ia_valid;
2113  
2114 -       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
2115 +       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
2116 +               ATTR_TAG | ATTR_TIMES_SET)) {
2117                 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
2118                         return -EPERM;
2119         }
2120 diff -NurpP --minimal linux-2.6.36/fs/binfmt_aout.c linux-2.6.36-vs2.3.0.36.36/fs/binfmt_aout.c
2121 --- linux-2.6.36/fs/binfmt_aout.c       2010-10-21 13:07:47.000000000 +0200
2122 +++ linux-2.6.36-vs2.3.0.36.36/fs/binfmt_aout.c 2010-10-21 13:09:36.000000000 +0200
2123 @@ -25,6 +25,7 @@
2124  #include <linux/init.h>
2125  #include <linux/coredump.h>
2126  #include <linux/slab.h>
2127 +#include <linux/vs_memory.h>
2128  
2129  #include <asm/system.h>
2130  #include <asm/uaccess.h>
2131 diff -NurpP --minimal linux-2.6.36/fs/binfmt_elf.c linux-2.6.36-vs2.3.0.36.36/fs/binfmt_elf.c
2132 --- linux-2.6.36/fs/binfmt_elf.c        2010-07-07 18:31:50.000000000 +0200
2133 +++ linux-2.6.36-vs2.3.0.36.36/fs/binfmt_elf.c  2010-10-21 13:09:36.000000000 +0200
2134 @@ -32,6 +32,7 @@
2135  #include <linux/elf.h>
2136  #include <linux/utsname.h>
2137  #include <linux/coredump.h>
2138 +#include <linux/vs_memory.h>
2139  #include <asm/uaccess.h>
2140  #include <asm/param.h>
2141  #include <asm/page.h>
2142 diff -NurpP --minimal linux-2.6.36/fs/binfmt_flat.c linux-2.6.36-vs2.3.0.36.36/fs/binfmt_flat.c
2143 --- linux-2.6.36/fs/binfmt_flat.c       2010-08-02 16:52:47.000000000 +0200
2144 +++ linux-2.6.36-vs2.3.0.36.36/fs/binfmt_flat.c 2010-10-21 13:09:36.000000000 +0200
2145 @@ -35,6 +35,7 @@
2146  #include <linux/init.h>
2147  #include <linux/flat.h>
2148  #include <linux/syscalls.h>
2149 +#include <linux/vs_memory.h>
2150  
2151  #include <asm/byteorder.h>
2152  #include <asm/system.h>
2153 diff -NurpP --minimal linux-2.6.36/fs/binfmt_som.c linux-2.6.36-vs2.3.0.36.36/fs/binfmt_som.c
2154 --- linux-2.6.36/fs/binfmt_som.c        2010-02-25 11:52:04.000000000 +0100
2155 +++ linux-2.6.36-vs2.3.0.36.36/fs/binfmt_som.c  2010-10-21 13:09:36.000000000 +0200
2156 @@ -28,6 +28,7 @@
2157  #include <linux/shm.h>
2158  #include <linux/personality.h>
2159  #include <linux/init.h>
2160 +#include <linux/vs_memory.h>
2161  
2162  #include <asm/uaccess.h>
2163  #include <asm/pgtable.h>
2164 diff -NurpP --minimal linux-2.6.36/fs/block_dev.c linux-2.6.36-vs2.3.0.36.36/fs/block_dev.c
2165 --- linux-2.6.36/fs/block_dev.c 2010-10-21 13:07:47.000000000 +0200
2166 +++ linux-2.6.36-vs2.3.0.36.36/fs/block_dev.c   2010-10-21 13:09:36.000000000 +0200
2167 @@ -26,6 +26,7 @@
2168  #include <linux/namei.h>
2169  #include <linux/log2.h>
2170  #include <linux/kmemleak.h>
2171 +#include <linux/vs_device.h>
2172  #include <asm/uaccess.h>
2173  #include "internal.h"
2174  
2175 @@ -530,6 +531,7 @@ struct block_device *bdget(dev_t dev)
2176                 bdev->bd_invalidated = 0;
2177                 inode->i_mode = S_IFBLK;
2178                 inode->i_rdev = dev;
2179 +               inode->i_mdev = dev;
2180                 inode->i_bdev = bdev;
2181                 inode->i_data.a_ops = &def_blk_aops;
2182                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
2183 @@ -576,6 +578,11 @@ EXPORT_SYMBOL(bdput);
2184  static struct block_device *bd_acquire(struct inode *inode)
2185  {
2186         struct block_device *bdev;
2187 +       dev_t mdev;
2188 +
2189 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
2190 +               return NULL;
2191 +       inode->i_mdev = mdev;
2192  
2193         spin_lock(&bdev_lock);
2194         bdev = inode->i_bdev;
2195 @@ -586,7 +593,7 @@ static struct block_device *bd_acquire(s
2196         }
2197         spin_unlock(&bdev_lock);
2198  
2199 -       bdev = bdget(inode->i_rdev);
2200 +       bdev = bdget(mdev);
2201         if (bdev) {
2202                 spin_lock(&bdev_lock);
2203                 if (!inode->i_bdev) {
2204 diff -NurpP --minimal linux-2.6.36/fs/btrfs/ctree.h linux-2.6.36-vs2.3.0.36.36/fs/btrfs/ctree.h
2205 --- linux-2.6.36/fs/btrfs/ctree.h       2010-10-21 13:07:48.000000000 +0200
2206 +++ linux-2.6.36-vs2.3.0.36.36/fs/btrfs/ctree.h 2010-10-21 13:09:36.000000000 +0200
2207 @@ -551,11 +551,14 @@ struct btrfs_inode_item {
2208         /* modification sequence number for NFS */
2209         __le64 sequence;
2210  
2211 +       __le16 tag;
2212         /*
2213          * a little future expansion, for more than this we can
2214          * just grow the inode item and version it
2215          */
2216 -       __le64 reserved[4];
2217 +       __le16 reserved16;
2218 +       __le32 reserved32;
2219 +       __le64 reserved[3];
2220         struct btrfs_timespec atime;
2221         struct btrfs_timespec ctime;
2222         struct btrfs_timespec mtime;
2223 @@ -1193,6 +1196,8 @@ struct btrfs_root {
2224  #define BTRFS_MOUNT_DISCARD            (1 << 10)
2225  #define BTRFS_MOUNT_FORCE_COMPRESS      (1 << 11)
2226  
2227 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
2228 +
2229  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
2230  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
2231  #define btrfs_test_opt(root, opt)      ((root)->fs_info->mount_opt & \
2232 @@ -1413,6 +1418,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
2233  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
2234  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
2235  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
2236 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
2237  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
2238  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
2239  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
2240 @@ -1474,6 +1480,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct 
2241  
2242  BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
2243  
2244 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
2245 +#define BTRFS_INODE_BARRIER            (1 << 25)
2246 +#define BTRFS_INODE_COW                        (1 << 26)
2247 +
2248  
2249  BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
2250  
2251 @@ -2432,6 +2442,7 @@ extern const struct dentry_operations bt
2252  long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
2253  void btrfs_update_iflags(struct inode *inode);
2254  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
2255 +int btrfs_sync_flags(struct inode *inode, int, int);
2256  
2257  /* file.c */
2258  int btrfs_sync_file(struct file *file, int datasync);
2259 diff -NurpP --minimal linux-2.6.36/fs/btrfs/disk-io.c linux-2.6.36-vs2.3.0.36.36/fs/btrfs/disk-io.c
2260 --- linux-2.6.36/fs/btrfs/disk-io.c     2010-10-21 13:07:48.000000000 +0200
2261 +++ linux-2.6.36-vs2.3.0.36.36/fs/btrfs/disk-io.c       2010-10-21 13:09:36.000000000 +0200
2262 @@ -1707,6 +1707,9 @@ struct btrfs_root *open_ctree(struct sup
2263                 goto fail_iput;
2264         }
2265  
2266 +       if (btrfs_test_opt(tree_root, TAGGED))
2267 +               sb->s_flags |= MS_TAGGED;
2268 +
2269         features = btrfs_super_incompat_flags(disk_super) &
2270                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
2271         if (features) {
2272 diff -NurpP --minimal linux-2.6.36/fs/btrfs/inode.c linux-2.6.36-vs2.3.0.36.36/fs/btrfs/inode.c
2273 --- linux-2.6.36/fs/btrfs/inode.c       2010-10-21 13:07:48.000000000 +0200
2274 +++ linux-2.6.36-vs2.3.0.36.36/fs/btrfs/inode.c 2010-10-21 13:09:36.000000000 +0200
2275 @@ -37,6 +37,8 @@
2276  #include <linux/posix_acl.h>
2277  #include <linux/falloc.h>
2278  #include <linux/slab.h>
2279 +#include <linux/vs_tag.h>
2280 +
2281  #include "compat.h"
2282  #include "ctree.h"
2283  #include "disk-io.h"
2284 @@ -2415,6 +2417,8 @@ static void btrfs_read_locked_inode(stru
2285         int maybe_acls;
2286         u64 alloc_group_block;
2287         u32 rdev;
2288 +       uid_t uid;
2289 +       gid_t gid;
2290         int ret;
2291  
2292         path = btrfs_alloc_path();
2293 @@ -2431,8 +2435,13 @@ static void btrfs_read_locked_inode(stru
2294  
2295         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
2296         inode->i_nlink = btrfs_inode_nlink(leaf, inode_item);
2297 -       inode->i_uid = btrfs_inode_uid(leaf, inode_item);
2298 -       inode->i_gid = btrfs_inode_gid(leaf, inode_item);
2299 +
2300 +       uid = btrfs_inode_uid(leaf, inode_item);
2301 +       gid = btrfs_inode_gid(leaf, inode_item);
2302 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2303 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2304 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2305 +               btrfs_inode_tag(leaf, inode_item));
2306         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
2307  
2308         tspec = btrfs_inode_atime(inode_item);
2309 @@ -2514,8 +2523,15 @@ static void fill_inode_item(struct btrfs
2310                             struct btrfs_inode_item *item,
2311                             struct inode *inode)
2312  {
2313 -       btrfs_set_inode_uid(leaf, item, inode->i_uid);
2314 -       btrfs_set_inode_gid(leaf, item, inode->i_gid);
2315 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2316 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2317 +
2318 +       btrfs_set_inode_uid(leaf, item, uid);
2319 +       btrfs_set_inode_gid(leaf, item, gid);
2320 +#ifdef CONFIG_TAGGING_INTERN
2321 +       btrfs_set_inode_tag(leaf, item, inode->i_tag);
2322 +#endif
2323 +
2324         btrfs_set_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size);
2325         btrfs_set_inode_mode(leaf, item, inode->i_mode);
2326         btrfs_set_inode_nlink(leaf, item, inode->i_nlink);
2327 @@ -6946,6 +6962,7 @@ static const struct inode_operations btr
2328         .listxattr      = btrfs_listxattr,
2329         .removexattr    = btrfs_removexattr,
2330         .permission     = btrfs_permission,
2331 +       .sync_flags     = btrfs_sync_flags,
2332  };
2333  static const struct inode_operations btrfs_dir_ro_inode_operations = {
2334         .lookup         = btrfs_lookup,
2335 @@ -7021,6 +7038,7 @@ static const struct inode_operations btr
2336         .permission     = btrfs_permission,
2337         .fallocate      = btrfs_fallocate,
2338         .fiemap         = btrfs_fiemap,
2339 +       .sync_flags     = btrfs_sync_flags,
2340  };
2341  static const struct inode_operations btrfs_special_inode_operations = {
2342         .getattr        = btrfs_getattr,
2343 diff -NurpP --minimal linux-2.6.36/fs/btrfs/ioctl.c linux-2.6.36-vs2.3.0.36.36/fs/btrfs/ioctl.c
2344 --- linux-2.6.36/fs/btrfs/ioctl.c       2010-08-02 16:52:47.000000000 +0200
2345 +++ linux-2.6.36-vs2.3.0.36.36/fs/btrfs/ioctl.c 2010-10-21 13:09:36.000000000 +0200
2346 @@ -68,10 +68,13 @@ static unsigned int btrfs_flags_to_ioctl
2347  {
2348         unsigned int iflags = 0;
2349  
2350 -       if (flags & BTRFS_INODE_SYNC)
2351 -               iflags |= FS_SYNC_FL;
2352         if (flags & BTRFS_INODE_IMMUTABLE)
2353                 iflags |= FS_IMMUTABLE_FL;
2354 +       if (flags & BTRFS_INODE_IXUNLINK)
2355 +               iflags |= FS_IXUNLINK_FL;
2356 +
2357 +       if (flags & BTRFS_INODE_SYNC)
2358 +               iflags |= FS_SYNC_FL;
2359         if (flags & BTRFS_INODE_APPEND)
2360                 iflags |= FS_APPEND_FL;
2361         if (flags & BTRFS_INODE_NODUMP)
2362 @@ -81,28 +84,78 @@ static unsigned int btrfs_flags_to_ioctl
2363         if (flags & BTRFS_INODE_DIRSYNC)
2364                 iflags |= FS_DIRSYNC_FL;
2365  
2366 +       if (flags & BTRFS_INODE_BARRIER)
2367 +               iflags |= FS_BARRIER_FL;
2368 +       if (flags & BTRFS_INODE_COW)
2369 +               iflags |= FS_COW_FL;
2370         return iflags;
2371  }
2372  
2373  /*
2374 - * Update inode->i_flags based on the btrfs internal flags.
2375 + * Update inode->i_(v)flags based on the btrfs internal flags.
2376   */
2377  void btrfs_update_iflags(struct inode *inode)
2378  {
2379         struct btrfs_inode *ip = BTRFS_I(inode);
2380  
2381 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2382 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2383 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2384  
2385 -       if (ip->flags & BTRFS_INODE_SYNC)
2386 -               inode->i_flags |= S_SYNC;
2387         if (ip->flags & BTRFS_INODE_IMMUTABLE)
2388                 inode->i_flags |= S_IMMUTABLE;
2389 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
2390 +               inode->i_flags |= S_IXUNLINK;
2391 +
2392 +       if (ip->flags & BTRFS_INODE_SYNC)
2393 +               inode->i_flags |= S_SYNC;
2394         if (ip->flags & BTRFS_INODE_APPEND)
2395                 inode->i_flags |= S_APPEND;
2396         if (ip->flags & BTRFS_INODE_NOATIME)
2397                 inode->i_flags |= S_NOATIME;
2398         if (ip->flags & BTRFS_INODE_DIRSYNC)
2399                 inode->i_flags |= S_DIRSYNC;
2400 +
2401 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2402 +
2403 +       if (ip->flags & BTRFS_INODE_BARRIER)
2404 +               inode->i_vflags |= V_BARRIER;
2405 +       if (ip->flags & BTRFS_INODE_COW)
2406 +               inode->i_vflags |= V_COW;
2407 +}
2408 +
2409 +/*
2410 + * Update btrfs internal flags from inode->i_(v)flags.
2411 + */
2412 +void btrfs_update_flags(struct inode *inode)
2413 +{
2414 +       struct btrfs_inode *ip = BTRFS_I(inode);
2415 +
2416 +       unsigned int flags = inode->i_flags;
2417 +       unsigned int vflags = inode->i_vflags;
2418 +
2419 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
2420 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
2421 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
2422 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
2423 +
2424 +       if (flags & S_IMMUTABLE)
2425 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
2426 +       if (flags & S_IXUNLINK)
2427 +               ip->flags |= BTRFS_INODE_IXUNLINK;
2428 +
2429 +       if (flags & S_SYNC)
2430 +               ip->flags |= BTRFS_INODE_SYNC;
2431 +       if (flags & S_APPEND)
2432 +               ip->flags |= BTRFS_INODE_APPEND;
2433 +       if (flags & S_NOATIME)
2434 +               ip->flags |= BTRFS_INODE_NOATIME;
2435 +       if (flags & S_DIRSYNC)
2436 +               ip->flags |= BTRFS_INODE_DIRSYNC;
2437 +
2438 +       if (vflags & V_BARRIER)
2439 +               ip->flags |= BTRFS_INODE_BARRIER;
2440 +       if (vflags & V_COW)
2441 +               ip->flags |= BTRFS_INODE_COW;
2442  }
2443  
2444  /*
2445 @@ -120,7 +173,7 @@ void btrfs_inherit_iflags(struct inode *
2446         flags = BTRFS_I(dir)->flags;
2447  
2448         if (S_ISREG(inode->i_mode))
2449 -               flags &= ~BTRFS_INODE_DIRSYNC;
2450 +               flags &= ~(BTRFS_INODE_DIRSYNC | BTRFS_INODE_BARRIER);
2451         else if (!S_ISDIR(inode->i_mode))
2452                 flags &= (BTRFS_INODE_NODUMP | BTRFS_INODE_NOATIME);
2453  
2454 @@ -128,6 +181,30 @@ void btrfs_inherit_iflags(struct inode *
2455         btrfs_update_iflags(inode);
2456  }
2457  
2458 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
2459 +{
2460 +       struct btrfs_inode *ip = BTRFS_I(inode);
2461 +       struct btrfs_root *root = ip->root;
2462 +       struct btrfs_trans_handle *trans;
2463 +       int ret;
2464 +
2465 +       trans = btrfs_join_transaction(root, 1);
2466 +       BUG_ON(!trans);
2467 +
2468 +       inode->i_flags = flags;
2469 +       inode->i_vflags = vflags;
2470 +       btrfs_update_flags(inode);
2471 +
2472 +       ret = btrfs_update_inode(trans, root, inode);
2473 +       BUG_ON(ret);
2474 +
2475 +       btrfs_update_iflags(inode);
2476 +       inode->i_ctime = CURRENT_TIME;
2477 +       btrfs_end_transaction(trans, root);
2478 +
2479 +       return 0;
2480 +}
2481 +
2482  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
2483  {
2484         struct btrfs_inode *ip = BTRFS_I(file->f_path.dentry->d_inode);
2485 @@ -150,6 +227,7 @@ static int btrfs_ioctl_setflags(struct f
2486         if (copy_from_user(&flags, arg, sizeof(flags)))
2487                 return -EFAULT;
2488  
2489 +       /* maybe add FS_IXUNLINK_FL ? */
2490         if (flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL | \
2491                       FS_NOATIME_FL | FS_NODUMP_FL | \
2492                       FS_SYNC_FL | FS_DIRSYNC_FL))
2493 @@ -162,7 +240,8 @@ static int btrfs_ioctl_setflags(struct f
2494  
2495         flags = btrfs_mask_flags(inode->i_mode, flags);
2496         oldflags = btrfs_flags_to_ioctl(ip->flags);
2497 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
2498 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
2499 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
2500                 if (!capable(CAP_LINUX_IMMUTABLE)) {
2501                         ret = -EPERM;
2502                         goto out_unlock;
2503 @@ -173,14 +252,19 @@ static int btrfs_ioctl_setflags(struct f
2504         if (ret)
2505                 goto out_unlock;
2506  
2507 -       if (flags & FS_SYNC_FL)
2508 -               ip->flags |= BTRFS_INODE_SYNC;
2509 -       else
2510 -               ip->flags &= ~BTRFS_INODE_SYNC;
2511         if (flags & FS_IMMUTABLE_FL)
2512                 ip->flags |= BTRFS_INODE_IMMUTABLE;
2513         else
2514                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
2515 +       if (flags & FS_IXUNLINK_FL)
2516 +               ip->flags |= BTRFS_INODE_IXUNLINK;
2517 +       else
2518 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
2519 +
2520 +       if (flags & FS_SYNC_FL)
2521 +               ip->flags |= BTRFS_INODE_SYNC;
2522 +       else
2523 +               ip->flags &= ~BTRFS_INODE_SYNC;
2524         if (flags & FS_APPEND_FL)
2525                 ip->flags |= BTRFS_INODE_APPEND;
2526         else
2527 diff -NurpP --minimal linux-2.6.36/fs/btrfs/super.c linux-2.6.36-vs2.3.0.36.36/fs/btrfs/super.c
2528 --- linux-2.6.36/fs/btrfs/super.c       2010-10-21 13:07:48.000000000 +0200
2529 +++ linux-2.6.36-vs2.3.0.36.36/fs/btrfs/super.c 2010-10-21 13:09:36.000000000 +0200
2530 @@ -68,7 +68,7 @@ enum {
2531         Opt_nodatacow, Opt_max_inline, Opt_alloc_start, Opt_nobarrier, Opt_ssd,
2532         Opt_nossd, Opt_ssd_spread, Opt_thread_pool, Opt_noacl, Opt_compress,
2533         Opt_compress_force, Opt_notreelog, Opt_ratio, Opt_flushoncommit,
2534 -       Opt_discard, Opt_err,
2535 +       Opt_tag, Opt_notag, Opt_tagid, Opt_discard, Opt_err,
2536  };
2537  
2538  static match_table_t tokens = {
2539 @@ -92,6 +92,9 @@ static match_table_t tokens = {
2540         {Opt_flushoncommit, "flushoncommit"},
2541         {Opt_ratio, "metadata_ratio=%d"},
2542         {Opt_discard, "discard"},
2543 +       {Opt_tag, "tag"},
2544 +       {Opt_notag, "notag"},
2545 +       {Opt_tagid, "tagid=%u"},
2546         {Opt_err, NULL},
2547  };
2548  
2549 @@ -235,6 +238,22 @@ int btrfs_parse_options(struct btrfs_roo
2550                 case Opt_discard:
2551                         btrfs_set_opt(info->mount_opt, DISCARD);
2552                         break;
2553 +#ifndef CONFIG_TAGGING_NONE
2554 +               case Opt_tag:
2555 +                       printk(KERN_INFO "btrfs: use tagging\n");
2556 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2557 +                       break;
2558 +               case Opt_notag:
2559 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
2560 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
2561 +                       break;
2562 +#endif
2563 +#ifdef CONFIG_PROPAGATE
2564 +               case Opt_tagid:
2565 +                       /* use args[0] */
2566 +                       btrfs_set_opt(info->mount_opt, TAGGED);
2567 +                       break;
2568 +#endif
2569                 case Opt_err:
2570                         printk(KERN_INFO "btrfs: unrecognized mount option "
2571                                "'%s'\n", p);
2572 @@ -681,6 +700,12 @@ static int btrfs_remount(struct super_bl
2573         if (ret)
2574                 return -EINVAL;
2575  
2576 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
2577 +               printk("btrfs: %s: tagging not permitted on remount.\n",
2578 +                       sb->s_id);
2579 +               return -EINVAL;
2580 +       }
2581 +
2582         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
2583                 return 0;
2584  
2585 diff -NurpP --minimal linux-2.6.36/fs/char_dev.c linux-2.6.36-vs2.3.0.36.36/fs/char_dev.c
2586 --- linux-2.6.36/fs/char_dev.c  2010-10-21 13:07:48.000000000 +0200
2587 +++ linux-2.6.36-vs2.3.0.36.36/fs/char_dev.c    2010-10-21 13:09:36.000000000 +0200
2588 @@ -21,6 +21,8 @@
2589  #include <linux/mutex.h>
2590  #include <linux/backing-dev.h>
2591  #include <linux/tty.h>
2592 +#include <linux/vs_context.h>
2593 +#include <linux/vs_device.h>
2594  
2595  #include "internal.h"
2596  
2597 @@ -371,14 +373,21 @@ static int chrdev_open(struct inode *ino
2598         struct cdev *p;
2599         struct cdev *new = NULL;
2600         int ret = 0;
2601 +       dev_t mdev;
2602 +
2603 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2604 +               return -EPERM;
2605 +       inode->i_mdev = mdev;
2606  
2607         spin_lock(&cdev_lock);
2608         p = inode->i_cdev;
2609         if (!p) {
2610                 struct kobject *kobj;
2611                 int idx;
2612 +
2613                 spin_unlock(&cdev_lock);
2614 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2615 +
2616 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
2617                 if (!kobj)
2618                         return -ENXIO;
2619                 new = container_of(kobj, struct cdev, kobj);
2620 diff -NurpP --minimal linux-2.6.36/fs/dcache.c linux-2.6.36-vs2.3.0.36.36/fs/dcache.c
2621 --- linux-2.6.36/fs/dcache.c    2010-10-21 13:07:48.000000000 +0200
2622 +++ linux-2.6.36-vs2.3.0.36.36/fs/dcache.c      2010-10-21 13:09:36.000000000 +0200
2623 @@ -33,6 +33,7 @@
2624  #include <linux/bootmem.h>
2625  #include <linux/fs_struct.h>
2626  #include <linux/hardirq.h>
2627 +#include <linux/vs_limit.h>
2628  #include "internal.h"
2629  
2630  int sysctl_vfs_cache_pressure __read_mostly = 100;
2631 @@ -230,6 +231,8 @@ repeat:
2632                 return;
2633         }
2634  
2635 +       vx_dentry_dec(dentry);
2636 +
2637         /*
2638          * AV: ->d_delete() is _NOT_ allowed to block now.
2639          */
2640 @@ -323,6 +326,7 @@ static inline struct dentry * __dget_loc
2641  {
2642         atomic_inc(&dentry->d_count);
2643         dentry_lru_del_init(dentry);
2644 +       vx_dentry_inc(dentry);
2645         return dentry;
2646  }
2647  
2648 @@ -928,6 +932,9 @@ struct dentry *d_alloc(struct dentry * p
2649         struct dentry *dentry;
2650         char *dname;
2651  
2652 +       if (!vx_dentry_avail(1))
2653 +               return NULL;
2654 +
2655         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2656         if (!dentry)
2657                 return NULL;
2658 @@ -973,6 +980,7 @@ struct dentry *d_alloc(struct dentry * p
2659         if (parent)
2660                 list_add(&dentry->d_u.d_child, &parent->d_subdirs);
2661         dentry_stat.nr_dentry++;
2662 +       vx_dentry_inc(dentry);
2663         spin_unlock(&dcache_lock);
2664  
2665         return dentry;
2666 @@ -1432,6 +1440,7 @@ struct dentry * __d_lookup(struct dentry
2667                 }
2668  
2669                 atomic_inc(&dentry->d_count);
2670 +               vx_dentry_inc(dentry);
2671                 found = dentry;
2672                 spin_unlock(&dentry->d_lock);
2673                 break;
2674 diff -NurpP --minimal linux-2.6.36/fs/devpts/inode.c linux-2.6.36-vs2.3.0.36.36/fs/devpts/inode.c
2675 --- linux-2.6.36/fs/devpts/inode.c      2010-08-02 16:52:48.000000000 +0200
2676 +++ linux-2.6.36-vs2.3.0.36.36/fs/devpts/inode.c        2010-10-21 22:25:15.000000000 +0200
2677 @@ -25,6 +25,7 @@
2678  #include <linux/parser.h>
2679  #include <linux/fsnotify.h>
2680  #include <linux/seq_file.h>
2681 +#include <linux/vs_base.h>
2682  
2683  #define DEVPTS_DEFAULT_MODE 0600
2684  /*
2685 @@ -36,6 +37,20 @@
2686  #define DEVPTS_DEFAULT_PTMX_MODE 0000
2687  #define PTMX_MINOR     2
2688  
2689 +static int devpts_permission(struct inode *inode, int mask)
2690 +{
2691 +       int ret = -EACCES;
2692 +
2693 +       /* devpts is xid tagged */
2694 +       if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
2695 +               ret = generic_permission(inode, mask, NULL);
2696 +       return ret;
2697 +}
2698 +
2699 +static struct inode_operations devpts_file_inode_operations = {
2700 +       .permission     = devpts_permission,
2701 +};
2702 +
2703  extern int pty_limit;                  /* Config limit on Unix98 ptys */
2704  static DEFINE_MUTEX(allocated_ptys_lock);
2705  
2706 @@ -263,6 +278,25 @@ static int devpts_show_options(struct se
2707         return 0;
2708  }
2709  
2710 +static int devpts_filter(struct dentry *de)
2711 +{
2712 +       /* devpts is xid tagged */
2713 +       return vx_check((xid_t)de->d_inode->i_tag, VS_WATCH_P | VS_IDENT);
2714 +}
2715 +
2716 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2717 +{
2718 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2719 +}
2720 +
2721 +static struct file_operations devpts_dir_operations = {
2722 +       .open           = dcache_dir_open,
2723 +       .release        = dcache_dir_close,
2724 +       .llseek         = dcache_dir_lseek,
2725 +       .read           = generic_read_dir,
2726 +       .readdir        = devpts_readdir,
2727 +};
2728 +
2729  static const struct super_operations devpts_sops = {
2730         .statfs         = simple_statfs,
2731         .remount_fs     = devpts_remount,
2732 @@ -302,12 +336,15 @@ devpts_fill_super(struct super_block *s,
2733         inode = new_inode(s);
2734         if (!inode)
2735                 goto free_fsi;
2736 +
2737         inode->i_ino = 1;
2738         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2739         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2740         inode->i_op = &simple_dir_inode_operations;
2741 -       inode->i_fop = &simple_dir_operations;
2742 +       inode->i_fop = &devpts_dir_operations;
2743         inode->i_nlink = 2;
2744 +       /* devpts is xid tagged */
2745 +       inode->i_tag = (tag_t)vx_current_xid();
2746  
2747         s->s_root = d_alloc_root(inode);
2748         if (s->s_root)
2749 @@ -495,6 +532,9 @@ int devpts_pty_new(struct inode *ptmx_in
2750         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2751         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2752         init_special_inode(inode, S_IFCHR|opts->mode, device);
2753 +       /* devpts is xid tagged */
2754 +       inode->i_tag = (tag_t)vx_current_xid();
2755 +       inode->i_op = &devpts_file_inode_operations;
2756         inode->i_private = tty;
2757         tty->driver_data = inode;
2758  
2759 diff -NurpP --minimal linux-2.6.36/fs/ext2/balloc.c linux-2.6.36-vs2.3.0.36.36/fs/ext2/balloc.c
2760 --- linux-2.6.36/fs/ext2/balloc.c       2010-10-21 13:07:48.000000000 +0200
2761 +++ linux-2.6.36-vs2.3.0.36.36/fs/ext2/balloc.c 2010-10-21 13:09:36.000000000 +0200
2762 @@ -702,7 +702,6 @@ ext2_try_to_allocate(struct super_block 
2763                         start = 0;
2764                 end = EXT2_BLOCKS_PER_GROUP(sb);
2765         }
2766 -
2767         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2768  
2769  repeat:
2770 diff -NurpP --minimal linux-2.6.36/fs/ext2/ext2.h linux-2.6.36-vs2.3.0.36.36/fs/ext2/ext2.h
2771 --- linux-2.6.36/fs/ext2/ext2.h 2010-10-21 13:07:48.000000000 +0200
2772 +++ linux-2.6.36-vs2.3.0.36.36/fs/ext2/ext2.h   2010-10-21 14:10:55.000000000 +0200
2773 @@ -127,6 +127,7 @@ extern void ext2_set_inode_flags(struct 
2774  extern void ext2_get_inode_flags(struct ext2_inode_info *);
2775  extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2776                        u64 start, u64 len);
2777 +extern int ext2_sync_flags(struct inode *, int, int);
2778  
2779  /* ioctl.c */
2780  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2781 diff -NurpP --minimal linux-2.6.36/fs/ext2/file.c linux-2.6.36-vs2.3.0.36.36/fs/ext2/file.c
2782 --- linux-2.6.36/fs/ext2/file.c 2010-08-02 16:52:48.000000000 +0200
2783 +++ linux-2.6.36-vs2.3.0.36.36/fs/ext2/file.c   2010-10-21 13:09:36.000000000 +0200
2784 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
2785         .setattr        = ext2_setattr,
2786         .check_acl      = ext2_check_acl,
2787         .fiemap         = ext2_fiemap,
2788 +       .sync_flags     = ext2_sync_flags,
2789  };
2790 diff -NurpP --minimal linux-2.6.36/fs/ext2/ialloc.c linux-2.6.36-vs2.3.0.36.36/fs/ext2/ialloc.c
2791 --- linux-2.6.36/fs/ext2/ialloc.c       2010-10-21 13:07:48.000000000 +0200
2792 +++ linux-2.6.36-vs2.3.0.36.36/fs/ext2/ialloc.c 2010-10-21 13:09:36.000000000 +0200
2793 @@ -17,6 +17,7 @@
2794  #include <linux/backing-dev.h>
2795  #include <linux/buffer_head.h>
2796  #include <linux/random.h>
2797 +#include <linux/vs_tag.h>
2798  #include "ext2.h"
2799  #include "xattr.h"
2800  #include "acl.h"
2801 @@ -548,6 +549,7 @@ got:
2802                 inode->i_mode = mode;
2803                 inode->i_uid = current_fsuid();
2804                 inode->i_gid = dir->i_gid;
2805 +               inode->i_tag = dx_current_fstag(sb);
2806         } else
2807                 inode_init_owner(inode, dir, mode);
2808  
2809 diff -NurpP --minimal linux-2.6.36/fs/ext2/inode.c linux-2.6.36-vs2.3.0.36.36/fs/ext2/inode.c
2810 --- linux-2.6.36/fs/ext2/inode.c        2010-10-21 13:07:48.000000000 +0200
2811 +++ linux-2.6.36-vs2.3.0.36.36/fs/ext2/inode.c  2010-10-21 13:09:36.000000000 +0200
2812 @@ -32,6 +32,7 @@
2813  #include <linux/mpage.h>
2814  #include <linux/fiemap.h>
2815  #include <linux/namei.h>
2816 +#include <linux/vs_tag.h>
2817  #include "ext2.h"
2818  #include "acl.h"
2819  #include "xip.h"
2820 @@ -1169,7 +1170,7 @@ static void ext2_truncate_blocks(struct 
2821                 return;
2822         if (ext2_inode_is_fast_symlink(inode))
2823                 return;
2824 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2825 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2826                 return;
2827         __ext2_truncate_blocks(inode, offset);
2828  }
2829 @@ -1258,36 +1259,61 @@ void ext2_set_inode_flags(struct inode *
2830  {
2831         unsigned int flags = EXT2_I(inode)->i_flags;
2832  
2833 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2834 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2835 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2836 +
2837 +
2838 +       if (flags & EXT2_IMMUTABLE_FL)
2839 +               inode->i_flags |= S_IMMUTABLE;
2840 +       if (flags & EXT2_IXUNLINK_FL)
2841 +               inode->i_flags |= S_IXUNLINK;
2842 +
2843         if (flags & EXT2_SYNC_FL)
2844                 inode->i_flags |= S_SYNC;
2845         if (flags & EXT2_APPEND_FL)
2846                 inode->i_flags |= S_APPEND;
2847 -       if (flags & EXT2_IMMUTABLE_FL)
2848 -               inode->i_flags |= S_IMMUTABLE;
2849         if (flags & EXT2_NOATIME_FL)
2850                 inode->i_flags |= S_NOATIME;
2851         if (flags & EXT2_DIRSYNC_FL)
2852                 inode->i_flags |= S_DIRSYNC;
2853 +
2854 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2855 +
2856 +       if (flags & EXT2_BARRIER_FL)
2857 +               inode->i_vflags |= V_BARRIER;
2858 +       if (flags & EXT2_COW_FL)
2859 +               inode->i_vflags |= V_COW;
2860  }
2861  
2862  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2863  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2864  {
2865         unsigned int flags = ei->vfs_inode.i_flags;
2866 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2867 +
2868 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2869 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2870 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2871 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2872 +
2873 +       if (flags & S_IMMUTABLE)
2874 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2875 +       if (flags & S_IXUNLINK)
2876 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2877  
2878 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2879 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2880         if (flags & S_SYNC)
2881                 ei->i_flags |= EXT2_SYNC_FL;
2882         if (flags & S_APPEND)
2883                 ei->i_flags |= EXT2_APPEND_FL;
2884 -       if (flags & S_IMMUTABLE)
2885 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2886         if (flags & S_NOATIME)
2887                 ei->i_flags |= EXT2_NOATIME_FL;
2888         if (flags & S_DIRSYNC)
2889                 ei->i_flags |= EXT2_DIRSYNC_FL;
2890 +
2891 +       if (vflags & V_BARRIER)
2892 +               ei->i_flags |= EXT2_BARRIER_FL;
2893 +       if (vflags & V_COW)
2894 +               ei->i_flags |= EXT2_COW_FL;
2895  }
2896  
2897  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2898 @@ -1297,6 +1323,8 @@ struct inode *ext2_iget (struct super_bl
2899         struct ext2_inode *raw_inode;
2900         struct inode *inode;
2901         long ret = -EIO;
2902 +       uid_t uid;
2903 +       gid_t gid;
2904         int n;
2905  
2906         inode = iget_locked(sb, ino);
2907 @@ -1315,12 +1343,17 @@ struct inode *ext2_iget (struct super_bl
2908         }
2909  
2910         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2911 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2912 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2913 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2914 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2915         if (!(test_opt (inode->i_sb, NO_UID32))) {
2916 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2917 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2918 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2919 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2920         }
2921 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2922 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2923 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2924 +               le16_to_cpu(raw_inode->i_raw_tag));
2925 +
2926         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
2927         inode->i_size = le32_to_cpu(raw_inode->i_size);
2928         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2929 @@ -1418,8 +1451,8 @@ static int __ext2_write_inode(struct ino
2930         struct ext2_inode_info *ei = EXT2_I(inode);
2931         struct super_block *sb = inode->i_sb;
2932         ino_t ino = inode->i_ino;
2933 -       uid_t uid = inode->i_uid;
2934 -       gid_t gid = inode->i_gid;
2935 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2936 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2937         struct buffer_head * bh;
2938         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2939         int n;
2940 @@ -1455,6 +1488,9 @@ static int __ext2_write_inode(struct ino
2941                 raw_inode->i_uid_high = 0;
2942                 raw_inode->i_gid_high = 0;
2943         }
2944 +#ifdef CONFIG_TAGGING_INTERN
2945 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2946 +#endif
2947         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2948         raw_inode->i_size = cpu_to_le32(inode->i_size);
2949         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2950 @@ -1544,7 +1580,8 @@ int ext2_setattr(struct dentry *dentry, 
2951         if (is_quota_modification(inode, iattr))
2952                 dquot_initialize(inode);
2953         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
2954 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
2955 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
2956 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
2957                 error = dquot_transfer(inode, iattr);
2958                 if (error)
2959                         return error;
2960 diff -NurpP --minimal linux-2.6.36/fs/ext2/ioctl.c linux-2.6.36-vs2.3.0.36.36/fs/ext2/ioctl.c
2961 --- linux-2.6.36/fs/ext2/ioctl.c        2009-09-10 15:26:21.000000000 +0200
2962 +++ linux-2.6.36-vs2.3.0.36.36/fs/ext2/ioctl.c  2010-10-21 13:09:36.000000000 +0200
2963 @@ -17,6 +17,16 @@
2964  #include <asm/uaccess.h>
2965  
2966  
2967 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2968 +{
2969 +       inode->i_flags = flags;
2970 +       inode->i_vflags = vflags;
2971 +       ext2_get_inode_flags(EXT2_I(inode));
2972 +       inode->i_ctime = CURRENT_TIME_SEC;
2973 +       mark_inode_dirty(inode);
2974 +       return 0;
2975 +}
2976 +
2977  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2978  {
2979         struct inode *inode = filp->f_dentry->d_inode;
2980 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2981  
2982                 flags = ext2_mask_flags(inode->i_mode, flags);
2983  
2984 +               if (IS_BARRIER(inode)) {
2985 +                       vxwprintk_task(1, "messing with the barrier.");
2986 +                       return -EACCES;
2987 +               }
2988 +
2989                 mutex_lock(&inode->i_mutex);
2990                 /* Is it quota file? Do not allow user to mess with it */
2991                 if (IS_NOQUOTA(inode)) {
2992 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2993                  *
2994                  * This test looks nicer. Thanks to Pauline Middelink
2995                  */
2996 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2997 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2998 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2999 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
3000                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3001                                 mutex_unlock(&inode->i_mutex);
3002                                 ret = -EPERM;
3003 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
3004                         }
3005                 }
3006  
3007 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
3008 +               flags &= EXT2_FL_USER_MODIFIABLE;
3009                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
3010                 ei->i_flags = flags;
3011                 mutex_unlock(&inode->i_mutex);
3012 diff -NurpP --minimal linux-2.6.36/fs/ext2/namei.c linux-2.6.36-vs2.3.0.36.36/fs/ext2/namei.c
3013 --- linux-2.6.36/fs/ext2/namei.c        2010-07-07 18:31:51.000000000 +0200
3014 +++ linux-2.6.36-vs2.3.0.36.36/fs/ext2/namei.c  2010-10-21 13:09:36.000000000 +0200
3015 @@ -32,6 +32,7 @@
3016  
3017  #include <linux/pagemap.h>
3018  #include <linux/quotaops.h>
3019 +#include <linux/vs_tag.h>
3020  #include "ext2.h"
3021  #include "xattr.h"
3022  #include "acl.h"
3023 @@ -75,6 +76,7 @@ static struct dentry *ext2_lookup(struct
3024                                 return ERR_PTR(-EIO);
3025                         } else {
3026                                 return ERR_CAST(inode);
3027 +               dx_propagate_tag(nd, inode);
3028                         }
3029                 }
3030         }
3031 @@ -418,6 +420,7 @@ const struct inode_operations ext2_dir_i
3032  #endif
3033         .setattr        = ext2_setattr,
3034         .check_acl      = ext2_check_acl,
3035 +       .sync_flags     = ext2_sync_flags,
3036  };
3037  
3038  const struct inode_operations ext2_special_inode_operations = {
3039 diff -NurpP --minimal linux-2.6.36/fs/ext2/super.c linux-2.6.36-vs2.3.0.36.36/fs/ext2/super.c
3040 --- linux-2.6.36/fs/ext2/super.c        2010-10-21 13:07:48.000000000 +0200
3041 +++ linux-2.6.36-vs2.3.0.36.36/fs/ext2/super.c  2010-10-21 13:09:36.000000000 +0200
3042 @@ -378,7 +378,8 @@ enum {
3043         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
3044         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
3045         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
3046 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
3047 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
3048 +       Opt_tag, Opt_notag, Opt_tagid
3049  };
3050  
3051  static const match_table_t tokens = {
3052 @@ -406,6 +407,9 @@ static const match_table_t tokens = {
3053         {Opt_acl, "acl"},
3054         {Opt_noacl, "noacl"},
3055         {Opt_xip, "xip"},
3056 +       {Opt_tag, "tag"},
3057 +       {Opt_notag, "notag"},
3058 +       {Opt_tagid, "tagid=%u"},
3059         {Opt_grpquota, "grpquota"},
3060         {Opt_ignore, "noquota"},
3061         {Opt_quota, "quota"},
3062 @@ -476,6 +480,20 @@ static int parse_options(char *options, 
3063                 case Opt_nouid32:
3064                         set_opt (sbi->s_mount_opt, NO_UID32);
3065                         break;
3066 +#ifndef CONFIG_TAGGING_NONE
3067 +               case Opt_tag:
3068 +                       set_opt (sbi->s_mount_opt, TAGGED);
3069 +                       break;
3070 +               case Opt_notag:
3071 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3072 +                       break;
3073 +#endif
3074 +#ifdef CONFIG_PROPAGATE
3075 +               case Opt_tagid:
3076 +                       /* use args[0] */
3077 +                       set_opt (sbi->s_mount_opt, TAGGED);
3078 +                       break;
3079 +#endif
3080                 case Opt_nocheck:
3081                         clear_opt (sbi->s_mount_opt, CHECK);
3082                         break;
3083 @@ -833,6 +851,8 @@ static int ext2_fill_super(struct super_
3084         if (!parse_options((char *) data, sb))
3085                 goto failed_mount;
3086  
3087 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
3088 +               sb->s_flags |= MS_TAGGED;
3089         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3090                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
3091                  MS_POSIXACL : 0);
3092 @@ -1205,6 +1225,14 @@ static int ext2_remount (struct super_bl
3093                 goto restore_opts;
3094         }
3095  
3096 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
3097 +               !(sb->s_flags & MS_TAGGED)) {
3098 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
3099 +                      sb->s_id);
3100 +               err = -EINVAL;
3101 +               goto restore_opts;
3102 +       }
3103 +
3104         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3105                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3106  
3107 diff -NurpP --minimal linux-2.6.36/fs/ext3/file.c linux-2.6.36-vs2.3.0.36.36/fs/ext3/file.c
3108 --- linux-2.6.36/fs/ext3/file.c 2010-07-07 18:31:51.000000000 +0200
3109 +++ linux-2.6.36-vs2.3.0.36.36/fs/ext3/file.c   2010-10-21 13:09:36.000000000 +0200
3110 @@ -81,5 +81,6 @@ const struct inode_operations ext3_file_
3111  #endif
3112         .check_acl      = ext3_check_acl,
3113         .fiemap         = ext3_fiemap,
3114 +       .sync_flags     = ext3_sync_flags,
3115  };
3116  
3117 diff -NurpP --minimal linux-2.6.36/fs/ext3/ialloc.c linux-2.6.36-vs2.3.0.36.36/fs/ext3/ialloc.c
3118 --- linux-2.6.36/fs/ext3/ialloc.c       2010-10-21 13:07:48.000000000 +0200
3119 +++ linux-2.6.36-vs2.3.0.36.36/fs/ext3/ialloc.c 2010-10-21 13:09:36.000000000 +0200
3120 @@ -23,6 +23,7 @@
3121  #include <linux/buffer_head.h>
3122  #include <linux/random.h>
3123  #include <linux/bitops.h>
3124 +#include <linux/vs_tag.h>
3125  
3126  #include <asm/byteorder.h>
3127  
3128 @@ -531,6 +532,7 @@ got:
3129                 inode->i_mode = mode;
3130                 inode->i_uid = current_fsuid();
3131                 inode->i_gid = dir->i_gid;
3132 +               inode->i_tag = dx_current_fstag(sb);
3133         } else
3134                 inode_init_owner(inode, dir, mode);
3135  
3136 diff -NurpP --minimal linux-2.6.36/fs/ext3/inode.c linux-2.6.36-vs2.3.0.36.36/fs/ext3/inode.c
3137 --- linux-2.6.36/fs/ext3/inode.c        2010-10-21 13:07:48.000000000 +0200
3138 +++ linux-2.6.36-vs2.3.0.36.36/fs/ext3/inode.c  2010-10-21 13:09:36.000000000 +0200
3139 @@ -38,6 +38,7 @@
3140  #include <linux/bio.h>
3141  #include <linux/fiemap.h>
3142  #include <linux/namei.h>
3143 +#include <linux/vs_tag.h>
3144  #include "xattr.h"
3145  #include "acl.h"
3146  
3147 @@ -2387,7 +2388,7 @@ static void ext3_free_branches(handle_t 
3148  
3149  int ext3_can_truncate(struct inode *inode)
3150  {
3151 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3152 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3153                 return 0;
3154         if (S_ISREG(inode->i_mode))
3155                 return 1;
3156 @@ -2772,36 +2773,60 @@ void ext3_set_inode_flags(struct inode *
3157  {
3158         unsigned int flags = EXT3_I(inode)->i_flags;
3159  
3160 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3161 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3162 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3163 +
3164 +       if (flags & EXT3_IMMUTABLE_FL)
3165 +               inode->i_flags |= S_IMMUTABLE;
3166 +       if (flags & EXT3_IXUNLINK_FL)
3167 +               inode->i_flags |= S_IXUNLINK;
3168 +
3169         if (flags & EXT3_SYNC_FL)
3170                 inode->i_flags |= S_SYNC;
3171         if (flags & EXT3_APPEND_FL)
3172                 inode->i_flags |= S_APPEND;
3173 -       if (flags & EXT3_IMMUTABLE_FL)
3174 -               inode->i_flags |= S_IMMUTABLE;
3175         if (flags & EXT3_NOATIME_FL)
3176                 inode->i_flags |= S_NOATIME;
3177         if (flags & EXT3_DIRSYNC_FL)
3178                 inode->i_flags |= S_DIRSYNC;
3179 +
3180 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3181 +
3182 +       if (flags & EXT3_BARRIER_FL)
3183 +               inode->i_vflags |= V_BARRIER;
3184 +       if (flags & EXT3_COW_FL)
3185 +               inode->i_vflags |= V_COW;
3186  }
3187  
3188  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
3189  void ext3_get_inode_flags(struct ext3_inode_info *ei)
3190  {
3191         unsigned int flags = ei->vfs_inode.i_flags;
3192 +       unsigned int vflags = ei->vfs_inode.i_vflags;
3193 +
3194 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
3195 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
3196 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
3197 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
3198 +
3199 +       if (flags & S_IMMUTABLE)
3200 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
3201 +       if (flags & S_IXUNLINK)
3202 +               ei->i_flags |= EXT3_IXUNLINK_FL;
3203  
3204 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
3205 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
3206         if (flags & S_SYNC)
3207                 ei->i_flags |= EXT3_SYNC_FL;
3208         if (flags & S_APPEND)
3209                 ei->i_flags |= EXT3_APPEND_FL;
3210 -       if (flags & S_IMMUTABLE)
3211 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
3212         if (flags & S_NOATIME)
3213                 ei->i_flags |= EXT3_NOATIME_FL;
3214         if (flags & S_DIRSYNC)
3215                 ei->i_flags |= EXT3_DIRSYNC_FL;
3216 +
3217 +       if (vflags & V_BARRIER)
3218 +               ei->i_flags |= EXT3_BARRIER_FL;
3219 +       if (vflags & V_COW)
3220 +               ei->i_flags |= EXT3_COW_FL;
3221  }
3222  
3223  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
3224 @@ -2815,6 +2840,8 @@ struct inode *ext3_iget(struct super_blo
3225         transaction_t *transaction;
3226         long ret;
3227         int block;
3228 +       uid_t uid;
3229 +       gid_t gid;
3230  
3231         inode = iget_locked(sb, ino);
3232         if (!inode)
3233 @@ -2831,12 +2858,17 @@ struct inode *ext3_iget(struct super_blo
3234         bh = iloc.bh;
3235         raw_inode = ext3_raw_inode(&iloc);
3236         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3237 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3238 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3239 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3240 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3241         if(!(test_opt (inode->i_sb, NO_UID32))) {
3242 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3243 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3244 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3245 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3246         }
3247 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3248 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3249 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3250 +               le16_to_cpu(raw_inode->i_raw_tag));
3251 +
3252         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3253         inode->i_size = le32_to_cpu(raw_inode->i_size);
3254         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
3255 @@ -2991,6 +3023,8 @@ static int ext3_do_update_inode(handle_t
3256         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
3257         struct ext3_inode_info *ei = EXT3_I(inode);
3258         struct buffer_head *bh = iloc->bh;
3259 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3260 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3261         int err = 0, rc, block;
3262  
3263  again:
3264 @@ -3005,29 +3039,32 @@ again:
3265         ext3_get_inode_flags(ei);
3266         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3267         if(!(test_opt(inode->i_sb, NO_UID32))) {
3268 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3269 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3270 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3271 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3272  /*
3273   * Fix up interoperability with old kernels. Otherwise, old inodes get
3274   * re-used with the upper 16 bits of the uid/gid intact
3275   */
3276                 if(!ei->i_dtime) {
3277                         raw_inode->i_uid_high =
3278 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3279 +                               cpu_to_le16(high_16_bits(uid));
3280                         raw_inode->i_gid_high =
3281 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3282 +                               cpu_to_le16(high_16_bits(gid));
3283                 } else {
3284                         raw_inode->i_uid_high = 0;
3285                         raw_inode->i_gid_high = 0;
3286                 }
3287         } else {
3288                 raw_inode->i_uid_low =
3289 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3290 +                       cpu_to_le16(fs_high2lowuid(uid));
3291                 raw_inode->i_gid_low =
3292 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3293 +                       cpu_to_le16(fs_high2lowgid(gid));
3294                 raw_inode->i_uid_high = 0;
3295                 raw_inode->i_gid_high = 0;
3296         }
3297 +#ifdef CONFIG_TAGGING_INTERN
3298 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3299 +#endif
3300         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3301         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
3302         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
3303 @@ -3187,7 +3224,8 @@ int ext3_setattr(struct dentry *dentry, 
3304         if (is_quota_modification(inode, attr))
3305                 dquot_initialize(inode);
3306         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3307 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3308 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3309 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3310                 handle_t *handle;
3311  
3312                 /* (user+group)*(old+new) structure, inode write (sb,
3313 @@ -3209,6 +3247,8 @@ int ext3_setattr(struct dentry *dentry, 
3314                         inode->i_uid = attr->ia_uid;
3315                 if (attr->ia_valid & ATTR_GID)
3316                         inode->i_gid = attr->ia_gid;
3317 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3318 +                       inode->i_tag = attr->ia_tag;
3319                 error = ext3_mark_inode_dirty(handle, inode);
3320                 ext3_journal_stop(handle);
3321         }
3322 diff -NurpP --minimal linux-2.6.36/fs/ext3/ioctl.c linux-2.6.36-vs2.3.0.36.36/fs/ext3/ioctl.c
3323 --- linux-2.6.36/fs/ext3/ioctl.c        2009-06-11 17:13:03.000000000 +0200
3324 +++ linux-2.6.36-vs2.3.0.36.36/fs/ext3/ioctl.c  2010-10-21 13:09:36.000000000 +0200
3325 @@ -8,6 +8,7 @@
3326   */
3327  
3328  #include <linux/fs.h>
3329 +#include <linux/mount.h>
3330  #include <linux/jbd.h>
3331  #include <linux/capability.h>
3332  #include <linux/ext3_fs.h>
3333 @@ -17,6 +18,34 @@
3334  #include <linux/compat.h>
3335  #include <asm/uaccess.h>
3336  
3337 +
3338 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
3339 +{
3340 +       handle_t *handle = NULL;
3341 +       struct ext3_iloc iloc;
3342 +       int err;
3343 +
3344 +       handle = ext3_journal_start(inode, 1);
3345 +       if (IS_ERR(handle))
3346 +               return PTR_ERR(handle);
3347 +
3348 +       if (IS_SYNC(inode))
3349 +               handle->h_sync = 1;
3350 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
3351 +       if (err)
3352 +               goto flags_err;
3353 +
3354 +       inode->i_flags = flags;
3355 +       inode->i_vflags = vflags;
3356 +       ext3_get_inode_flags(EXT3_I(inode));
3357 +       inode->i_ctime = CURRENT_TIME_SEC;
3358 +
3359 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
3360 +flags_err:
3361 +       ext3_journal_stop(handle);
3362 +       return err;
3363 +}
3364 +
3365  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3366  {
3367         struct inode *inode = filp->f_dentry->d_inode;
3368 @@ -50,6 +79,11 @@ long ext3_ioctl(struct file *filp, unsig
3369  
3370                 flags = ext3_mask_flags(inode->i_mode, flags);
3371  
3372 +               if (IS_BARRIER(inode)) {
3373 +                       vxwprintk_task(1, "messing with the barrier.");
3374 +                       return -EACCES;
3375 +               }
3376 +
3377                 mutex_lock(&inode->i_mutex);
3378  
3379                 /* Is it quota file? Do not allow user to mess with it */
3380 @@ -68,7 +102,9 @@ long ext3_ioctl(struct file *filp, unsig
3381                  *
3382                  * This test looks nicer. Thanks to Pauline Middelink
3383                  */
3384 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
3385 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
3386 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
3387 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
3388                         if (!capable(CAP_LINUX_IMMUTABLE))
3389                                 goto flags_out;
3390                 }
3391 @@ -93,7 +129,7 @@ long ext3_ioctl(struct file *filp, unsig
3392                 if (err)
3393                         goto flags_err;
3394  
3395 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
3396 +               flags &= EXT3_FL_USER_MODIFIABLE;
3397                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
3398                 ei->i_flags = flags;
3399  
3400 diff -NurpP --minimal linux-2.6.36/fs/ext3/namei.c linux-2.6.36-vs2.3.0.36.36/fs/ext3/namei.c
3401 --- linux-2.6.36/fs/ext3/namei.c        2010-10-21 13:07:48.000000000 +0200
3402 +++ linux-2.6.36-vs2.3.0.36.36/fs/ext3/namei.c  2010-10-21 13:09:36.000000000 +0200
3403 @@ -36,6 +36,7 @@
3404  #include <linux/quotaops.h>
3405  #include <linux/buffer_head.h>
3406  #include <linux/bio.h>
3407 +#include <linux/vs_tag.h>
3408  
3409  #include "namei.h"
3410  #include "xattr.h"
3411 @@ -912,6 +913,7 @@ restart:
3412                                 if (bh)
3413                                         ll_rw_block(READ_META, 1, &bh);
3414                         }
3415 +               dx_propagate_tag(nd, inode);
3416                 }
3417                 if ((bh = bh_use[ra_ptr++]) == NULL)
3418                         goto next;
3419 @@ -2465,6 +2467,7 @@ const struct inode_operations ext3_dir_i
3420         .removexattr    = generic_removexattr,
3421  #endif
3422         .check_acl      = ext3_check_acl,
3423 +       .sync_flags     = ext3_sync_flags,
3424  };
3425  
3426  const struct inode_operations ext3_special_inode_operations = {
3427 diff -NurpP --minimal linux-2.6.36/fs/ext3/super.c linux-2.6.36-vs2.3.0.36.36/fs/ext3/super.c
3428 --- linux-2.6.36/fs/ext3/super.c        2010-10-21 13:07:48.000000000 +0200
3429 +++ linux-2.6.36-vs2.3.0.36.36/fs/ext3/super.c  2010-10-21 13:09:36.000000000 +0200
3430 @@ -802,7 +802,8 @@ enum {
3431         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
3432         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
3433         Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
3434 -       Opt_resize, Opt_usrquota, Opt_grpquota
3435 +       Opt_resize, Opt_usrquota, Opt_grpquota,
3436 +       Opt_tag, Opt_notag, Opt_tagid
3437  };
3438  
3439  static const match_table_t tokens = {
3440 @@ -859,6 +860,9 @@ static const match_table_t tokens = {
3441         {Opt_barrier, "barrier"},
3442         {Opt_nobarrier, "nobarrier"},
3443         {Opt_resize, "resize"},
3444 +       {Opt_tag, "tag"},
3445 +       {Opt_notag, "notag"},
3446 +       {Opt_tagid, "tagid=%u"},
3447         {Opt_err, NULL},
3448  };
3449  
3450 @@ -1011,6 +1015,20 @@ static int parse_options (char *options,
3451                 case Opt_nouid32:
3452                         set_opt (sbi->s_mount_opt, NO_UID32);
3453                         break;
3454 +#ifndef CONFIG_TAGGING_NONE
3455 +               case Opt_tag:
3456 +                       set_opt (sbi->s_mount_opt, TAGGED);
3457 +                       break;
3458 +               case Opt_notag:
3459 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3460 +                       break;
3461 +#endif
3462 +#ifdef CONFIG_PROPAGATE
3463 +               case Opt_tagid:
3464 +                       /* use args[0] */
3465 +                       set_opt (sbi->s_mount_opt, TAGGED);
3466 +                       break;
3467 +#endif
3468                 case Opt_nocheck:
3469                         clear_opt (sbi->s_mount_opt, CHECK);
3470                         break;
3471 @@ -1699,6 +1717,9 @@ static int ext3_fill_super (struct super
3472                             NULL, 0))
3473                 goto failed_mount;
3474  
3475 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
3476 +               sb->s_flags |= MS_TAGGED;
3477 +
3478         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3479                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3480  
3481 @@ -2564,6 +2585,14 @@ static int ext3_remount (struct super_bl
3482         if (test_opt(sb, ABORT))
3483                 ext3_abort(sb, __func__, "Abort forced by user");
3484  
3485 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
3486 +               !(sb->s_flags & MS_TAGGED)) {
3487 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
3488 +                       sb->s_id);
3489 +               err = -EINVAL;
3490 +               goto restore_opts;
3491 +       }
3492 +
3493         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3494                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3495  
3496 diff -NurpP --minimal linux-2.6.36/fs/ext4/ext4.h linux-2.6.36-vs2.3.0.36.36/fs/ext4/ext4.h
3497 --- linux-2.6.36/fs/ext4/ext4.h 2010-10-21 13:07:48.000000000 +0200
3498 +++ linux-2.6.36-vs2.3.0.36.36/fs/ext4/ext4.h   2010-10-21 13:09:36.000000000 +0200
3499 @@ -323,8 +323,12 @@ struct flex_groups {
3500  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
3501  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
3502  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
3503 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
3504  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
3505  
3506 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
3507 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
3508 +
3509  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
3510  #define EXT4_FL_USER_MODIFIABLE                0x004B80FF /* User modifiable flags */
3511  
3512 @@ -593,7 +597,8 @@ struct ext4_inode {
3513                         __le16  l_i_file_acl_high;
3514                         __le16  l_i_uid_high;   /* these 2 fields */
3515                         __le16  l_i_gid_high;   /* were reserved2[0] */
3516 -                       __u32   l_i_reserved2;
3517 +                       __le16  l_i_tag;        /* Context Tag */
3518 +                       __u16   l_i_reserved2;
3519                 } linux2;
3520                 struct {
3521                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
3522 @@ -707,6 +712,7 @@ do {                                                                               \
3523  #define i_gid_low      i_gid
3524  #define i_uid_high     osd2.linux2.l_i_uid_high
3525  #define i_gid_high     osd2.linux2.l_i_gid_high
3526 +#define i_raw_tag      osd2.linux2.l_i_tag
3527  #define i_reserved2    osd2.linux2.l_i_reserved2
3528  
3529  #elif defined(__GNU__)
3530 @@ -885,6 +891,7 @@ struct ext4_inode_info {
3531  #define EXT4_MOUNT_JOURNAL_CHECKSUM    0x800000 /* Journal checksums */
3532  #define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT        0x1000000 /* Journal Async Commit */
3533  #define EXT4_MOUNT_I_VERSION            0x2000000 /* i_version support */
3534 +#define EXT4_MOUNT_TAGGED              0x4000000 /* Enable Context Tags */
3535  #define EXT4_MOUNT_DELALLOC            0x8000000 /* Delalloc support */
3536  #define EXT4_MOUNT_DATA_ERR_ABORT      0x10000000 /* Abort on file data write */
3537  #define EXT4_MOUNT_BLOCK_VALIDITY      0x20000000 /* Block validity checking */
3538 @@ -1997,6 +2004,7 @@ extern int ext4_map_blocks(handle_t *han
3539                            struct ext4_map_blocks *map, int flags);
3540  extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
3541                         __u64 start, __u64 len);
3542 +extern int ext4_sync_flags(struct inode *, int, int);
3543  /* move_extent.c */
3544  extern int ext4_move_extents(struct file *o_filp, struct file *d_filp,
3545                              __u64 start_orig, __u64 start_donor,
3546 diff -NurpP --minimal linux-2.6.36/fs/ext4/file.c linux-2.6.36-vs2.3.0.36.36/fs/ext4/file.c
3547 --- linux-2.6.36/fs/ext4/file.c 2010-10-21 13:07:48.000000000 +0200
3548 +++ linux-2.6.36-vs2.3.0.36.36/fs/ext4/file.c   2010-10-21 13:09:36.000000000 +0200
3549 @@ -161,5 +161,6 @@ const struct inode_operations ext4_file_
3550         .check_acl      = ext4_check_acl,
3551         .fallocate      = ext4_fallocate,
3552         .fiemap         = ext4_fiemap,
3553 +       .sync_flags     = ext4_sync_flags,
3554  };
3555  
3556 diff -NurpP --minimal linux-2.6.36/fs/ext4/ialloc.c linux-2.6.36-vs2.3.0.36.36/fs/ext4/ialloc.c
3557 --- linux-2.6.36/fs/ext4/ialloc.c       2010-10-21 13:07:48.000000000 +0200
3558 +++ linux-2.6.36-vs2.3.0.36.36/fs/ext4/ialloc.c 2010-10-21 13:09:36.000000000 +0200
3559 @@ -22,6 +22,7 @@
3560  #include <linux/random.h>
3561  #include <linux/bitops.h>
3562  #include <linux/blkdev.h>
3563 +#include <linux/vs_tag.h>
3564  #include <asm/byteorder.h>
3565  
3566  #include "ext4.h"
3567 @@ -976,6 +977,7 @@ got:
3568                 inode->i_mode = mode;
3569                 inode->i_uid = current_fsuid();
3570                 inode->i_gid = dir->i_gid;
3571 +               inode->i_tag = dx_current_fstag(sb);
3572         } else
3573                 inode_init_owner(inode, dir, mode);
3574  
3575 diff -NurpP --minimal linux-2.6.36/fs/ext4/inode.c linux-2.6.36-vs2.3.0.36.36/fs/ext4/inode.c
3576 --- linux-2.6.36/fs/ext4/inode.c        2010-10-21 13:07:48.000000000 +0200
3577 +++ linux-2.6.36-vs2.3.0.36.36/fs/ext4/inode.c  2010-10-21 13:09:36.000000000 +0200
3578 @@ -40,6 +40,7 @@
3579  #include <linux/workqueue.h>
3580  #include <linux/kernel.h>
3581  #include <linux/slab.h>
3582 +#include <linux/vs_tag.h>
3583  
3584  #include "ext4_jbd2.h"
3585  #include "xattr.h"
3586 @@ -4596,7 +4597,7 @@ static void ext4_free_branches(handle_t 
3587  
3588  int ext4_can_truncate(struct inode *inode)
3589  {
3590 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3591 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3592                 return 0;
3593         if (S_ISREG(inode->i_mode))
3594                 return 1;
3595 @@ -4947,41 +4948,64 @@ void ext4_set_inode_flags(struct inode *
3596  {
3597         unsigned int flags = EXT4_I(inode)->i_flags;
3598  
3599 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3600 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3601 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3602 +
3603 +       if (flags & EXT4_IMMUTABLE_FL)
3604 +               inode->i_flags |= S_IMMUTABLE;
3605 +       if (flags & EXT4_IXUNLINK_FL)
3606 +               inode->i_flags |= S_IXUNLINK;
3607 +
3608         if (flags & EXT4_SYNC_FL)
3609                 inode->i_flags |= S_SYNC;
3610         if (flags & EXT4_APPEND_FL)
3611                 inode->i_flags |= S_APPEND;
3612 -       if (flags & EXT4_IMMUTABLE_FL)
3613 -               inode->i_flags |= S_IMMUTABLE;
3614         if (flags & EXT4_NOATIME_FL)
3615                 inode->i_flags |= S_NOATIME;
3616         if (flags & EXT4_DIRSYNC_FL)
3617                 inode->i_flags |= S_DIRSYNC;
3618 +
3619 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3620 +
3621 +       if (flags & EXT4_BARRIER_FL)
3622 +               inode->i_vflags |= V_BARRIER;
3623 +       if (flags & EXT4_COW_FL)
3624 +               inode->i_vflags |= V_COW;
3625  }
3626  
3627  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3628  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3629  {
3630 -       unsigned int vfs_fl;
3631 +       unsigned int vfs_fl, vfs_vf;
3632         unsigned long old_fl, new_fl;
3633  
3634         do {
3635                 vfs_fl = ei->vfs_inode.i_flags;
3636 +               vfs_vf = ei->vfs_inode.i_vflags;
3637                 old_fl = ei->i_flags;
3638                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3639                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
3640 -                               EXT4_DIRSYNC_FL);
3641 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
3642 +                               EXT4_COW_FL);
3643 +
3644 +               if (vfs_fl & S_IMMUTABLE)
3645 +                       new_fl |= EXT4_IMMUTABLE_FL;
3646 +               if (vfs_fl & S_IXUNLINK)
3647 +                       new_fl |= EXT4_IXUNLINK_FL;
3648 +
3649                 if (vfs_fl & S_SYNC)
3650                         new_fl |= EXT4_SYNC_FL;
3651                 if (vfs_fl & S_APPEND)
3652                         new_fl |= EXT4_APPEND_FL;
3653 -               if (vfs_fl & S_IMMUTABLE)
3654 -                       new_fl |= EXT4_IMMUTABLE_FL;
3655                 if (vfs_fl & S_NOATIME)
3656                         new_fl |= EXT4_NOATIME_FL;
3657                 if (vfs_fl & S_DIRSYNC)
3658                         new_fl |= EXT4_DIRSYNC_FL;
3659 +
3660 +               if (vfs_vf & V_BARRIER)
3661 +                       new_fl |= EXT4_BARRIER_FL;
3662 +               if (vfs_vf & V_COW)
3663 +                       new_fl |= EXT4_COW_FL;
3664         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3665  }
3666  
3667 @@ -5017,6 +5041,8 @@ struct inode *ext4_iget(struct super_blo
3668         journal_t *journal = EXT4_SB(sb)->s_journal;
3669         long ret;
3670         int block;
3671 +       uid_t uid;
3672 +       gid_t gid;
3673  
3674         inode = iget_locked(sb, ino);
3675         if (!inode)
3676 @@ -5032,12 +5058,16 @@ struct inode *ext4_iget(struct super_blo
3677                 goto bad_inode;
3678         raw_inode = ext4_raw_inode(&iloc);
3679         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3680 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3681 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3682 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3683 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3684         if (!(test_opt(inode->i_sb, NO_UID32))) {
3685 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3686 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3687 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3688 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3689         }
3690 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3691 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3692 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3693 +               le16_to_cpu(raw_inode->i_raw_tag));
3694         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3695  
3696         ei->i_state_flags = 0;
3697 @@ -5256,6 +5286,8 @@ static int ext4_do_update_inode(handle_t
3698         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
3699         struct ext4_inode_info *ei = EXT4_I(inode);
3700         struct buffer_head *bh = iloc->bh;
3701 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3702 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3703         int err = 0, rc, block;
3704  
3705         /* For fields not not tracking in the in-memory inode,
3706 @@ -5266,29 +5298,32 @@ static int ext4_do_update_inode(handle_t
3707         ext4_get_inode_flags(ei);
3708         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3709         if (!(test_opt(inode->i_sb, NO_UID32))) {
3710 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3711 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3712 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3713 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3714  /*
3715   * Fix up interoperability with old kernels. Otherwise, old inodes get
3716   * re-used with the upper 16 bits of the uid/gid intact
3717   */
3718                 if (!ei->i_dtime) {
3719                         raw_inode->i_uid_high =
3720 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3721 +                               cpu_to_le16(high_16_bits(uid));
3722                         raw_inode->i_gid_high =
3723 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3724 +                               cpu_to_le16(high_16_bits(gid));
3725                 } else {
3726                         raw_inode->i_uid_high = 0;
3727                         raw_inode->i_gid_high = 0;
3728                 }
3729         } else {
3730                 raw_inode->i_uid_low =
3731 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3732 +                       cpu_to_le16(fs_high2lowuid(uid));
3733                 raw_inode->i_gid_low =
3734 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3735 +                       cpu_to_le16(fs_high2lowgid(gid));
3736                 raw_inode->i_uid_high = 0;
3737                 raw_inode->i_gid_high = 0;
3738         }
3739 +#ifdef CONFIG_TAGGING_INTERN
3740 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3741 +#endif
3742         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3743  
3744         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3745 @@ -5473,7 +5508,8 @@ int ext4_setattr(struct dentry *dentry, 
3746         if (is_quota_modification(inode, attr))
3747                 dquot_initialize(inode);
3748         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3749 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3750 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3751 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3752                 handle_t *handle;
3753  
3754                 /* (user+group)*(old+new) structure, inode write (sb,
3755 @@ -5495,6 +5531,8 @@ int ext4_setattr(struct dentry *dentry, 
3756                         inode->i_uid = attr->ia_uid;
3757                 if (attr->ia_valid & ATTR_GID)
3758                         inode->i_gid = attr->ia_gid;
3759 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3760 +                       inode->i_tag = attr->ia_tag;
3761                 error = ext4_mark_inode_dirty(handle, inode);
3762                 ext4_journal_stop(handle);
3763         }
3764 diff -NurpP --minimal linux-2.6.36/fs/ext4/ioctl.c linux-2.6.36-vs2.3.0.36.36/fs/ext4/ioctl.c
3765 --- linux-2.6.36/fs/ext4/ioctl.c        2010-08-02 16:52:48.000000000 +0200
3766 +++ linux-2.6.36-vs2.3.0.36.36/fs/ext4/ioctl.c  2010-10-21 13:09:36.000000000 +0200
3767 @@ -14,10 +14,39 @@
3768  #include <linux/compat.h>
3769  #include <linux/mount.h>
3770  #include <linux/file.h>
3771 +#include <linux/vs_tag.h>
3772  #include <asm/uaccess.h>
3773  #include "ext4_jbd2.h"
3774  #include "ext4.h"
3775  
3776 +
3777 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3778 +{
3779 +       handle_t *handle = NULL;
3780 +       struct ext4_iloc iloc;
3781 +       int err;
3782 +
3783 +       handle = ext4_journal_start(inode, 1);
3784 +       if (IS_ERR(handle))
3785 +               return PTR_ERR(handle);
3786 +
3787 +       if (IS_SYNC(inode))
3788 +               ext4_handle_sync(handle);
3789 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3790 +       if (err)
3791 +               goto flags_err;
3792 +
3793 +       inode->i_flags = flags;
3794 +       inode->i_vflags = vflags;
3795 +       ext4_get_inode_flags(EXT4_I(inode));
3796 +       inode->i_ctime = ext4_current_time(inode);
3797 +
3798 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3799 +flags_err:
3800 +       ext4_journal_stop(handle);
3801 +       return err;
3802 +}
3803 +
3804  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3805  {
3806         struct inode *inode = filp->f_dentry->d_inode;
3807 @@ -50,6 +79,11 @@ long ext4_ioctl(struct file *filp, unsig
3808  
3809                 flags = ext4_mask_flags(inode->i_mode, flags);
3810  
3811 +               if (IS_BARRIER(inode)) {
3812 +                       vxwprintk_task(1, "messing with the barrier.");
3813 +                       return -EACCES;
3814 +               }
3815 +
3816                 err = -EPERM;
3817                 mutex_lock(&inode->i_mutex);
3818                 /* Is it quota file? Do not allow user to mess with it */
3819 @@ -67,7 +101,9 @@ long ext4_ioctl(struct file *filp, unsig
3820                  *
3821                  * This test looks nicer. Thanks to Pauline Middelink
3822                  */
3823 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3824 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3825 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3826 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3827                         if (!capable(CAP_LINUX_IMMUTABLE))
3828                                 goto flags_out;
3829                 }
3830 diff -NurpP --minimal linux-2.6.36/fs/ext4/namei.c linux-2.6.36-vs2.3.0.36.36/fs/ext4/namei.c
3831 --- linux-2.6.36/fs/ext4/namei.c        2010-10-21 13:07:48.000000000 +0200
3832 +++ linux-2.6.36-vs2.3.0.36.36/fs/ext4/namei.c  2010-10-21 13:09:36.000000000 +0200
3833 @@ -34,6 +34,7 @@
3834  #include <linux/quotaops.h>
3835  #include <linux/buffer_head.h>
3836  #include <linux/bio.h>
3837 +#include <linux/vs_tag.h>
3838  #include "ext4.h"
3839  #include "ext4_jbd2.h"
3840  
3841 @@ -912,6 +913,7 @@ restart:
3842                                 if (bh)
3843                                         ll_rw_block(READ_META, 1, &bh);
3844                         }
3845 +               dx_propagate_tag(nd, inode);
3846                 }
3847                 if ((bh = bh_use[ra_ptr++]) == NULL)
3848                         goto next;
3849 @@ -2522,6 +2524,7 @@ const struct inode_operations ext4_dir_i
3850  #endif
3851         .check_acl      = ext4_check_acl,
3852         .fiemap         = ext4_fiemap,
3853 +       .sync_flags     = ext4_sync_flags,
3854  };
3855  
3856  const struct inode_operations ext4_special_inode_operations = {
3857 diff -NurpP --minimal linux-2.6.36/fs/ext4/super.c linux-2.6.36-vs2.3.0.36.36/fs/ext4/super.c
3858 --- linux-2.6.36/fs/ext4/super.c        2010-10-21 13:07:48.000000000 +0200
3859 +++ linux-2.6.36-vs2.3.0.36.36/fs/ext4/super.c  2010-10-21 13:09:36.000000000 +0200
3860 @@ -1219,6 +1219,7 @@ enum {
3861         Opt_inode_readahead_blks, Opt_journal_ioprio,
3862         Opt_dioread_nolock, Opt_dioread_lock,
3863         Opt_discard, Opt_nodiscard,
3864 +       Opt_tag, Opt_notag, Opt_tagid
3865  };
3866  
3867  static const match_table_t tokens = {
3868 @@ -1289,6 +1290,9 @@ static const match_table_t tokens = {
3869         {Opt_dioread_lock, "dioread_lock"},
3870         {Opt_discard, "discard"},
3871         {Opt_nodiscard, "nodiscard"},
3872 +       {Opt_tag, "tag"},
3873 +       {Opt_notag, "notag"},
3874 +       {Opt_tagid, "tagid=%u"},
3875         {Opt_err, NULL},
3876  };
3877  
3878 @@ -1457,6 +1461,20 @@ static int parse_options(char *options, 
3879                 case Opt_nouid32:
3880                         set_opt(sbi->s_mount_opt, NO_UID32);
3881                         break;
3882 +#ifndef CONFIG_TAGGING_NONE
3883 +               case Opt_tag:
3884 +                       set_opt (sbi->s_mount_opt, TAGGED);
3885 +                       break;
3886 +               case Opt_notag:
3887 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3888 +                       break;
3889 +#endif
3890 +#ifdef CONFIG_PROPAGATE
3891 +               case Opt_tagid:
3892 +                       /* use args[0] */
3893 +                       set_opt (sbi->s_mount_opt, TAGGED);
3894 +                       break;
3895 +#endif
3896                 case Opt_debug:
3897                         set_opt(sbi->s_mount_opt, DEBUG);
3898                         break;
3899 @@ -2691,6 +2709,9 @@ static int ext4_fill_super(struct super_
3900                            &journal_ioprio, NULL, 0))
3901                 goto failed_mount;
3902  
3903 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3904 +               sb->s_flags |= MS_TAGGED;
3905 +
3906         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3907                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3908  
3909 @@ -3753,6 +3774,14 @@ static int ext4_remount(struct super_blo
3910         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3911                 ext4_abort(sb, "Abort forced by user");
3912  
3913 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3914 +               !(sb->s_flags & MS_TAGGED)) {
3915 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3916 +                       sb->s_id);
3917 +               err = -EINVAL;
3918 +               goto restore_opts;
3919 +       }
3920 +
3921         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3922                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3923  
3924 diff -NurpP --minimal linux-2.6.36/fs/fcntl.c linux-2.6.36-vs2.3.0.36.36/fs/fcntl.c
3925 --- linux-2.6.36/fs/fcntl.c     2010-10-21 13:07:48.000000000 +0200
3926 +++ linux-2.6.36-vs2.3.0.36.36/fs/fcntl.c       2010-10-21 13:09:36.000000000 +0200
3927 @@ -20,6 +20,7 @@
3928  #include <linux/signal.h>
3929  #include <linux/rcupdate.h>
3930  #include <linux/pid_namespace.h>
3931 +#include <linux/vs_limit.h>
3932  
3933  #include <asm/poll.h>
3934  #include <asm/siginfo.h>
3935 @@ -103,6 +104,8 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldf
3936  
3937         if (tofree)
3938                 filp_close(tofree, files);
3939 +       else
3940 +               vx_openfd_inc(newfd);   /* fd was unused */
3941  
3942         return newfd;
3943  
3944 @@ -434,6 +437,8 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd,
3945         filp = fget(fd);
3946         if (!filp)
3947                 goto out;
3948 +       if (!vx_files_avail(1))
3949 +               goto out;
3950  
3951         err = security_file_fcntl(filp, cmd, arg);
3952         if (err) {
3953 diff -NurpP --minimal linux-2.6.36/fs/file.c linux-2.6.36-vs2.3.0.36.36/fs/file.c
3954 --- linux-2.6.36/fs/file.c      2010-10-21 13:07:48.000000000 +0200
3955 +++ linux-2.6.36-vs2.3.0.36.36/fs/file.c        2010-10-21 13:09:36.000000000 +0200
3956 @@ -20,6 +20,7 @@
3957  #include <linux/spinlock.h>
3958  #include <linux/rcupdate.h>
3959  #include <linux/workqueue.h>
3960 +#include <linux/vs_limit.h>
3961  
3962  struct fdtable_defer {
3963         spinlock_t lock;
3964 @@ -355,6 +356,8 @@ struct files_struct *dup_fd(struct files
3965                 struct file *f = *old_fds++;
3966                 if (f) {
3967                         get_file(f);
3968 +                       /* TODO: sum it first for check and performance */
3969 +                       vx_openfd_inc(open_files - i);
3970                 } else {
3971                         /*
3972                          * The fd may be claimed in the fd bitmap but not yet
3973 @@ -462,6 +465,7 @@ repeat:
3974         else
3975                 FD_CLR(fd, fdt->close_on_exec);
3976         error = fd;
3977 +       vx_openfd_inc(fd);
3978  #if 1
3979         /* Sanity check */
3980         if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
3981 diff -NurpP --minimal linux-2.6.36/fs/file_table.c linux-2.6.36-vs2.3.0.36.36/fs/file_table.c
3982 --- linux-2.6.36/fs/file_table.c        2010-10-21 13:07:48.000000000 +0200
3983 +++ linux-2.6.36-vs2.3.0.36.36/fs/file_table.c  2010-10-21 14:10:28.000000000 +0200
3984 @@ -24,6 +24,8 @@
3985  #include <linux/percpu_counter.h>
3986  #include <linux/percpu.h>
3987  #include <linux/ima.h>
3988 +#include <linux/vs_limit.h>
3989 +#include <linux/vs_context.h>
3990  
3991  #include <asm/atomic.h>
3992  
3993 @@ -135,6 +137,8 @@ struct file *get_empty_filp(void)
3994         spin_lock_init(&f->f_lock);
3995         eventpoll_init_file(f);
3996         /* f->f_version: 0 */
3997 +       f->f_xid = vx_current_xid();
3998 +       vx_files_inc(f);
3999         return f;
4000  
4001  over:
4002 @@ -251,6 +255,8 @@ static void __fput(struct file *file)
4003                 cdev_put(inode->i_cdev);
4004         fops_put(file->f_op);
4005         put_pid(file->f_owner.pid);
4006 +       vx_files_dec(file);
4007 +       file->f_xid = 0;
4008         file_sb_list_del(file);
4009         if (file->f_mode & FMODE_WRITE)
4010                 drop_file_write_access(file);
4011 @@ -334,6 +340,8 @@ void put_filp(struct file *file)
4012  {
4013         if (atomic_long_dec_and_test(&file->f_count)) {
4014                 security_file_free(file);
4015 +               vx_files_dec(file);
4016 +               file->f_xid = 0;
4017                 file_sb_list_del(file);
4018                 file_free(file);
4019         }
4020 diff -NurpP --minimal linux-2.6.36/fs/fs_struct.c linux-2.6.36-vs2.3.0.36.36/fs/fs_struct.c
4021 --- linux-2.6.36/fs/fs_struct.c 2010-10-21 13:07:48.000000000 +0200
4022 +++ linux-2.6.36-vs2.3.0.36.36/fs/fs_struct.c   2010-10-21 13:56:13.000000000 +0200
4023 @@ -4,6 +4,7 @@
4024  #include <linux/path.h>
4025  #include <linux/slab.h>
4026  #include <linux/fs_struct.h>
4027 +#include <linux/vserver/global.h>
4028  
4029  /*
4030   * Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values.
4031 @@ -77,6 +78,7 @@ void free_fs_struct(struct fs_struct *fs
4032  {
4033         path_put(&fs->root);
4034         path_put(&fs->pwd);
4035 +       atomic_dec(&vs_global_fs);
4036         kmem_cache_free(fs_cachep, fs);
4037  }
4038  
4039 @@ -107,6 +109,7 @@ struct fs_struct *copy_fs_struct(struct 
4040                 spin_lock_init(&fs->lock);
4041                 fs->umask = old->umask;
4042                 get_fs_root_and_pwd(old, &fs->root, &fs->pwd);
4043 +               atomic_inc(&vs_global_fs);
4044         }
4045         return fs;
4046  }
4047 diff -NurpP --minimal linux-2.6.36/fs/gfs2/file.c linux-2.6.36-vs2.3.0.36.36/fs/gfs2/file.c
4048 --- linux-2.6.36/fs/gfs2/file.c 2010-10-21 13:07:49.000000000 +0200
4049 +++ linux-2.6.36-vs2.3.0.36.36/fs/gfs2/file.c   2010-10-21 13:09:36.000000000 +0200
4050 @@ -132,6 +132,9 @@ static const u32 fsflags_to_gfs2[32] = {
4051         [7] = GFS2_DIF_NOATIME,
4052         [12] = GFS2_DIF_EXHASH,
4053         [14] = GFS2_DIF_INHERIT_JDATA,
4054 +       [27] = GFS2_DIF_IXUNLINK,
4055 +       [26] = GFS2_DIF_BARRIER,
4056 +       [29] = GFS2_DIF_COW,
4057  };
4058  
4059  static const u32 gfs2_to_fsflags[32] = {
4060 @@ -141,6 +144,9 @@ static const u32 gfs2_to_fsflags[32] = {
4061         [gfs2fl_NoAtime] = FS_NOATIME_FL,
4062         [gfs2fl_ExHash] = FS_INDEX_FL,
4063         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
4064 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
4065 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
4066 +       [gfs2fl_Cow] = FS_COW_FL,
4067  };
4068  
4069  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
4070 @@ -171,10 +177,16 @@ void gfs2_set_inode_flags(struct inode *
4071  {
4072         struct gfs2_inode *ip = GFS2_I(inode);
4073         unsigned int flags = inode->i_flags;
4074 +       unsigned int vflags = inode->i_vflags;
4075 +
4076 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4077 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4078  
4079 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
4080         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
4081                 flags |= S_IMMUTABLE;
4082 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
4083 +               flags |= S_IXUNLINK;
4084 +
4085         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
4086                 flags |= S_APPEND;
4087         if (ip->i_diskflags & GFS2_DIF_NOATIME)
4088 @@ -182,6 +194,43 @@ void gfs2_set_inode_flags(struct inode *
4089         if (ip->i_diskflags & GFS2_DIF_SYNC)
4090                 flags |= S_SYNC;
4091         inode->i_flags = flags;
4092 +
4093 +       vflags &= ~(V_BARRIER | V_COW);
4094 +
4095 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
4096 +               vflags |= V_BARRIER;
4097 +       if (ip->i_diskflags & GFS2_DIF_COW)
4098 +               vflags |= V_COW;
4099 +       inode->i_vflags = vflags;
4100 +}
4101 +
4102 +void gfs2_get_inode_flags(struct inode *inode)
4103 +{
4104 +       struct gfs2_inode *ip = GFS2_I(inode);
4105 +       unsigned int flags = inode->i_flags;
4106 +       unsigned int vflags = inode->i_vflags;
4107 +
4108 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
4109 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
4110 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
4111 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
4112 +
4113 +       if (flags & S_IMMUTABLE)
4114 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
4115 +       if (flags & S_IXUNLINK)
4116 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
4117 +
4118 +       if (flags & S_APPEND)
4119 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
4120 +       if (flags & S_NOATIME)
4121 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
4122 +       if (flags & S_SYNC)
4123 +               ip->i_diskflags |= GFS2_DIF_SYNC;
4124 +
4125 +       if (vflags & V_BARRIER)
4126 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
4127 +       if (vflags & V_COW)
4128 +               ip->i_diskflags |= GFS2_DIF_COW;
4129  }
4130  
4131  /* Flags that can be set by user space */
4132 @@ -293,6 +342,37 @@ static int gfs2_set_flags(struct file *f
4133         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
4134  }
4135  
4136 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
4137 +{
4138 +       struct gfs2_inode *ip = GFS2_I(inode);
4139 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
4140 +       struct buffer_head *bh;
4141 +       struct gfs2_holder gh;
4142 +       int error;
4143 +
4144 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
4145 +       if (error)
4146 +               return error;
4147 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
4148 +       if (error)
4149 +               goto out;
4150 +       error = gfs2_meta_inode_buffer(ip, &bh);
4151 +       if (error)
4152 +               goto out_trans_end;
4153 +       gfs2_trans_add_bh(ip->i_gl, bh, 1);
4154 +       inode->i_flags = flags;
4155 +       inode->i_vflags = vflags;
4156 +       gfs2_get_inode_flags(inode);
4157 +       gfs2_dinode_out(ip, bh->b_data);
4158 +       brelse(bh);
4159 +       gfs2_set_aops(inode);
4160 +out_trans_end:
4161 +       gfs2_trans_end(sdp);
4162 +out:
4163 +       gfs2_glock_dq_uninit(&gh);
4164 +       return error;
4165 +}
4166 +
4167  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4168  {
4169         switch(cmd) {
4170 diff -NurpP --minimal linux-2.6.36/fs/gfs2/inode.h linux-2.6.36-vs2.3.0.36.36/fs/gfs2/inode.h
4171 --- linux-2.6.36/fs/gfs2/inode.h        2010-08-02 16:52:49.000000000 +0200
4172 +++ linux-2.6.36-vs2.3.0.36.36/fs/gfs2/inode.h  2010-10-21 13:09:36.000000000 +0200
4173 @@ -109,6 +109,7 @@ extern const struct file_operations gfs2
4174  extern const struct file_operations gfs2_dir_fops_nolock;
4175  
4176  extern void gfs2_set_inode_flags(struct inode *inode);
4177 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
4178   
4179  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
4180  extern const struct file_operations gfs2_file_fops;
4181 diff -NurpP --minimal linux-2.6.36/fs/gfs2/ops_inode.c linux-2.6.36-vs2.3.0.36.36/fs/gfs2/ops_inode.c
4182 --- linux-2.6.36/fs/gfs2/ops_inode.c    2010-10-21 13:07:49.000000000 +0200
4183 +++ linux-2.6.36-vs2.3.0.36.36/fs/gfs2/ops_inode.c      2010-10-21 13:09:36.000000000 +0200
4184 @@ -1352,6 +1352,7 @@ const struct inode_operations gfs2_file_
4185         .listxattr = gfs2_listxattr,
4186         .removexattr = gfs2_removexattr,
4187         .fiemap = gfs2_fiemap,
4188 +       .sync_flags = gfs2_sync_flags,
4189  };
4190  
4191  const struct inode_operations gfs2_dir_iops = {
4192 @@ -1372,6 +1373,7 @@ const struct inode_operations gfs2_dir_i
4193         .listxattr = gfs2_listxattr,
4194         .removexattr = gfs2_removexattr,
4195         .fiemap = gfs2_fiemap,
4196 +       .sync_flags = gfs2_sync_flags,
4197  };
4198  
4199  const struct inode_operations gfs2_symlink_iops = {
4200 diff -NurpP --minimal linux-2.6.36/fs/hfsplus/ioctl.c linux-2.6.36-vs2.3.0.36.36/fs/hfsplus/ioctl.c
4201 --- linux-2.6.36/fs/hfsplus/ioctl.c     2010-08-02 16:52:49.000000000 +0200
4202 +++ linux-2.6.36-vs2.3.0.36.36/fs/hfsplus/ioctl.c       2010-10-21 13:09:36.000000000 +0200
4203 @@ -18,6 +18,7 @@
4204  #include <linux/sched.h>
4205  #include <linux/xattr.h>
4206  #include <linux/smp_lock.h>
4207 +// #include <linux/mount.h>
4208  #include <asm/uaccess.h>
4209  #include "hfsplus_fs.h"
4210  
4211 diff -NurpP --minimal linux-2.6.36/fs/inode.c linux-2.6.36-vs2.3.0.36.36/fs/inode.c
4212 --- linux-2.6.36/fs/inode.c     2010-10-21 13:07:49.000000000 +0200
4213 +++ linux-2.6.36-vs2.3.0.36.36/fs/inode.c       2010-10-21 13:09:36.000000000 +0200
4214 @@ -24,6 +24,7 @@
4215  #include <linux/mount.h>
4216  #include <linux/async.h>
4217  #include <linux/posix_acl.h>
4218 +#include <linux/vs_tag.h>
4219  
4220  /*
4221   * This is needed for the following functions:
4222 @@ -130,6 +131,9 @@ int inode_init_always(struct super_block
4223         struct address_space *const mapping = &inode->i_data;
4224  
4225         inode->i_sb = sb;
4226 +
4227 +       /* essential because of inode slab reuse */
4228 +       inode->i_tag = 0;
4229         inode->i_blkbits = sb->s_blocksize_bits;
4230         inode->i_flags = 0;
4231         atomic_set(&inode->i_count, 1);
4232 @@ -150,6 +154,7 @@ int inode_init_always(struct super_block
4233         inode->i_bdev = NULL;
4234         inode->i_cdev = NULL;
4235         inode->i_rdev = 0;
4236 +       inode->i_mdev = 0;
4237         inode->dirtied_when = 0;
4238  
4239         if (security_inode_alloc(inode))
4240 @@ -393,6 +398,8 @@ static int invalidate_list(struct list_h
4241         return busy;
4242  }
4243  
4244 +EXPORT_SYMBOL_GPL(__iget);
4245 +
4246  /**
4247   *     invalidate_inodes       - discard the inodes on a device
4248   *     @sb: superblock
4249 @@ -1528,9 +1535,11 @@ void init_special_inode(struct inode *in
4250         if (S_ISCHR(mode)) {
4251                 inode->i_fop = &def_chr_fops;
4252                 inode->i_rdev = rdev;
4253 +               inode->i_mdev = rdev;
4254         } else if (S_ISBLK(mode)) {
4255                 inode->i_fop = &def_blk_fops;
4256                 inode->i_rdev = rdev;
4257 +               inode->i_mdev = rdev;
4258         } else if (S_ISFIFO(mode))
4259                 inode->i_fop = &def_fifo_fops;
4260         else if (S_ISSOCK(mode))
4261 @@ -1559,5 +1568,6 @@ void inode_init_owner(struct inode *inod
4262         } else
4263                 inode->i_gid = current_fsgid();
4264         inode->i_mode = mode;
4265 +       inode->i_tag = dx_current_fstag(inode->i_sb);
4266  }
4267  EXPORT_SYMBOL(inode_init_owner);
4268 diff -NurpP --minimal linux-2.6.36/fs/ioctl.c linux-2.6.36-vs2.3.0.36.36/fs/ioctl.c
4269 --- linux-2.6.36/fs/ioctl.c     2010-10-21 13:07:49.000000000 +0200
4270 +++ linux-2.6.36-vs2.3.0.36.36/fs/ioctl.c       2010-10-21 13:09:36.000000000 +0200
4271 @@ -16,6 +16,9 @@
4272  #include <linux/writeback.h>
4273  #include <linux/buffer_head.h>
4274  #include <linux/falloc.h>
4275 +#include <linux/proc_fs.h>
4276 +#include <linux/vserver/inode.h>
4277 +#include <linux/vs_tag.h>
4278  
4279  #include <asm/ioctls.h>
4280  
4281 diff -NurpP --minimal linux-2.6.36/fs/ioprio.c linux-2.6.36-vs2.3.0.36.36/fs/ioprio.c
4282 --- linux-2.6.36/fs/ioprio.c    2010-07-07 18:31:52.000000000 +0200
4283 +++ linux-2.6.36-vs2.3.0.36.36/fs/ioprio.c      2010-10-21 13:09:36.000000000 +0200
4284 @@ -27,6 +27,7 @@
4285  #include <linux/syscalls.h>
4286  #include <linux/security.h>
4287  #include <linux/pid_namespace.h>
4288 +#include <linux/vs_base.h>
4289  
4290  int set_task_ioprio(struct task_struct *task, int ioprio)
4291  {
4292 @@ -124,6 +125,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which, 
4293                         else
4294                                 pgrp = find_vpid(who);
4295                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
4296 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4297 +                                       continue;
4298                                 ret = set_task_ioprio(p, ioprio);
4299                                 if (ret)
4300                                         break;
4301 @@ -213,6 +216,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which, 
4302                         else
4303                                 pgrp = find_vpid(who);
4304                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
4305 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
4306 +                                       continue;
4307                                 tmpio = get_task_ioprio(p);
4308                                 if (tmpio < 0)
4309                                         continue;
4310 diff -NurpP --minimal linux-2.6.36/fs/jfs/file.c linux-2.6.36-vs2.3.0.36.36/fs/jfs/file.c
4311 --- linux-2.6.36/fs/jfs/file.c  2010-10-21 13:07:50.000000000 +0200
4312 +++ linux-2.6.36-vs2.3.0.36.36/fs/jfs/file.c    2010-10-21 13:09:36.000000000 +0200
4313 @@ -102,7 +102,8 @@ int jfs_setattr(struct dentry *dentry, s
4314         if (is_quota_modification(inode, iattr))
4315                 dquot_initialize(inode);
4316         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
4317 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
4318 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
4319 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
4320                 rc = dquot_transfer(inode, iattr);
4321                 if (rc)
4322                         return rc;
4323 @@ -133,6 +134,7 @@ const struct inode_operations jfs_file_i
4324  #ifdef CONFIG_JFS_POSIX_ACL
4325         .check_acl      = jfs_check_acl,
4326  #endif
4327 +       .sync_flags     = jfs_sync_flags,
4328  };
4329  
4330  const struct file_operations jfs_file_operations = {
4331 diff -NurpP --minimal linux-2.6.36/fs/jfs/ioctl.c linux-2.6.36-vs2.3.0.36.36/fs/jfs/ioctl.c
4332 --- linux-2.6.36/fs/jfs/ioctl.c 2008-12-25 00:26:37.000000000 +0100
4333 +++ linux-2.6.36-vs2.3.0.36.36/fs/jfs/ioctl.c   2010-10-21 13:09:36.000000000 +0200
4334 @@ -11,6 +11,7 @@
4335  #include <linux/mount.h>
4336  #include <linux/time.h>
4337  #include <linux/sched.h>
4338 +#include <linux/mount.h>
4339  #include <asm/current.h>
4340  #include <asm/uaccess.h>
4341  
4342 @@ -52,6 +53,16 @@ static long jfs_map_ext2(unsigned long f
4343  }
4344  
4345  
4346 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
4347 +{
4348 +       inode->i_flags = flags;
4349 +       inode->i_vflags = vflags;
4350 +       jfs_get_inode_flags(JFS_IP(inode));
4351 +       inode->i_ctime = CURRENT_TIME_SEC;
4352 +       mark_inode_dirty(inode);
4353 +       return 0;
4354 +}
4355 +
4356  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4357  {
4358         struct inode *inode = filp->f_dentry->d_inode;
4359 @@ -85,6 +96,11 @@ long jfs_ioctl(struct file *filp, unsign
4360                 if (!S_ISDIR(inode->i_mode))
4361                         flags &= ~JFS_DIRSYNC_FL;
4362  
4363 +               if (IS_BARRIER(inode)) {
4364 +                       vxwprintk_task(1, "messing with the barrier.");
4365 +                       return -EACCES;
4366 +               }
4367 +
4368                 /* Is it quota file? Do not allow user to mess with it */
4369                 if (IS_NOQUOTA(inode)) {
4370                         err = -EPERM;
4371 @@ -102,8 +118,8 @@ long jfs_ioctl(struct file *filp, unsign
4372                  * the relevant capability.
4373                  */
4374                 if ((oldflags & JFS_IMMUTABLE_FL) ||
4375 -                       ((flags ^ oldflags) &
4376 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
4377 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
4378 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
4379                         if (!capable(CAP_LINUX_IMMUTABLE)) {
4380                                 mutex_unlock(&inode->i_mutex);
4381                                 err = -EPERM;
4382 @@ -111,7 +127,7 @@ long jfs_ioctl(struct file *filp, unsign
4383                         }
4384                 }
4385  
4386 -               flags = flags & JFS_FL_USER_MODIFIABLE;
4387 +               flags &= JFS_FL_USER_MODIFIABLE;
4388                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
4389                 jfs_inode->mode2 = flags;
4390  
4391 diff -NurpP --minimal linux-2.6.36/fs/jfs/jfs_dinode.h linux-2.6.36-vs2.3.0.36.36/fs/jfs/jfs_dinode.h
4392 --- linux-2.6.36/fs/jfs/jfs_dinode.h    2008-12-25 00:26:37.000000000 +0100
4393 +++ linux-2.6.36-vs2.3.0.36.36/fs/jfs/jfs_dinode.h      2010-10-21 13:09:36.000000000 +0200
4394 @@ -161,9 +161,13 @@ struct dinode {
4395  
4396  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
4397  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
4398 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
4399  
4400 -#define JFS_FL_USER_VISIBLE    0x03F80000
4401 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
4402 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
4403 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
4404 +
4405 +#define JFS_FL_USER_VISIBLE    0x07F80000
4406 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
4407  #define JFS_FL_INHERIT         0x03C80000
4408  
4409  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
4410 diff -NurpP --minimal linux-2.6.36/fs/jfs/jfs_filsys.h linux-2.6.36-vs2.3.0.36.36/fs/jfs/jfs_filsys.h
4411 --- linux-2.6.36/fs/jfs/jfs_filsys.h    2008-12-25 00:26:37.000000000 +0100
4412 +++ linux-2.6.36-vs2.3.0.36.36/fs/jfs/jfs_filsys.h      2010-10-21 13:09:36.000000000 +0200
4413 @@ -263,6 +263,7 @@
4414  #define JFS_NAME_MAX   255
4415  #define JFS_PATH_MAX   BPSIZE
4416  
4417 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
4418  
4419  /*
4420   *     file system state (superblock state)
4421 diff -NurpP --minimal linux-2.6.36/fs/jfs/jfs_imap.c linux-2.6.36-vs2.3.0.36.36/fs/jfs/jfs_imap.c
4422 --- linux-2.6.36/fs/jfs/jfs_imap.c      2010-07-07 18:31:52.000000000 +0200
4423 +++ linux-2.6.36-vs2.3.0.36.36/fs/jfs/jfs_imap.c        2010-10-21 13:09:36.000000000 +0200
4424 @@ -46,6 +46,7 @@
4425  #include <linux/pagemap.h>
4426  #include <linux/quotaops.h>
4427  #include <linux/slab.h>
4428 +#include <linux/vs_tag.h>
4429  
4430  #include "jfs_incore.h"
4431  #include "jfs_inode.h"
4432 @@ -3060,6 +3061,8 @@ static int copy_from_dinode(struct dinod
4433  {
4434         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
4435         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
4436 +       uid_t uid;
4437 +       gid_t gid;
4438  
4439         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
4440         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
4441 @@ -3080,14 +3083,18 @@ static int copy_from_dinode(struct dinod
4442         }
4443         ip->i_nlink = le32_to_cpu(dip->di_nlink);
4444  
4445 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
4446 +       uid = le32_to_cpu(dip->di_uid);
4447 +       gid = le32_to_cpu(dip->di_gid);
4448 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
4449 +
4450 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
4451         if (sbi->uid == -1)
4452                 ip->i_uid = jfs_ip->saved_uid;
4453         else {
4454                 ip->i_uid = sbi->uid;
4455         }
4456  
4457 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
4458 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
4459         if (sbi->gid == -1)
4460                 ip->i_gid = jfs_ip->saved_gid;
4461         else {
4462 @@ -3152,14 +3159,12 @@ static void copy_to_dinode(struct dinode
4463         dip->di_size = cpu_to_le64(ip->i_size);
4464         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
4465         dip->di_nlink = cpu_to_le32(ip->i_nlink);
4466 -       if (sbi->uid == -1)
4467 -               dip->di_uid = cpu_to_le32(ip->i_uid);
4468 -       else
4469 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
4470 -       if (sbi->gid == -1)
4471 -               dip->di_gid = cpu_to_le32(ip->i_gid);
4472 -       else
4473 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
4474 +
4475 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
4476 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
4477 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
4478 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
4479 +
4480         jfs_get_inode_flags(jfs_ip);
4481         /*
4482          * mode2 is only needed for storing the higher order bits.
4483 diff -NurpP --minimal linux-2.6.36/fs/jfs/jfs_inode.c linux-2.6.36-vs2.3.0.36.36/fs/jfs/jfs_inode.c
4484 --- linux-2.6.36/fs/jfs/jfs_inode.c     2010-08-02 16:52:49.000000000 +0200
4485 +++ linux-2.6.36-vs2.3.0.36.36/fs/jfs/jfs_inode.c       2010-10-21 13:09:36.000000000 +0200
4486 @@ -18,6 +18,7 @@
4487  
4488  #include <linux/fs.h>
4489  #include <linux/quotaops.h>
4490 +#include <linux/vs_tag.h>
4491  #include "jfs_incore.h"
4492  #include "jfs_inode.h"
4493  #include "jfs_filsys.h"
4494 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
4495  {
4496         unsigned int flags = JFS_IP(inode)->mode2;
4497  
4498 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
4499 -               S_NOATIME | S_DIRSYNC | S_SYNC);
4500 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4501 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4502  
4503         if (flags & JFS_IMMUTABLE_FL)
4504                 inode->i_flags |= S_IMMUTABLE;
4505 +       if (flags & JFS_IXUNLINK_FL)
4506 +               inode->i_flags |= S_IXUNLINK;
4507 +
4508 +       if (flags & JFS_SYNC_FL)
4509 +               inode->i_flags |= S_SYNC;
4510         if (flags & JFS_APPEND_FL)
4511                 inode->i_flags |= S_APPEND;
4512         if (flags & JFS_NOATIME_FL)
4513                 inode->i_flags |= S_NOATIME;
4514         if (flags & JFS_DIRSYNC_FL)
4515                 inode->i_flags |= S_DIRSYNC;
4516 -       if (flags & JFS_SYNC_FL)
4517 -               inode->i_flags |= S_SYNC;
4518 +
4519 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
4520 +
4521 +       if (flags & JFS_BARRIER_FL)
4522 +               inode->i_vflags |= V_BARRIER;
4523 +       if (flags & JFS_COW_FL)
4524 +               inode->i_vflags |= V_COW;
4525  }
4526  
4527  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
4528  {
4529         unsigned int flags = jfs_ip->vfs_inode.i_flags;
4530 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
4531 +
4532 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
4533 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
4534 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
4535 +                          JFS_BARRIER_FL | JFS_COW_FL);
4536  
4537 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
4538 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
4539         if (flags & S_IMMUTABLE)
4540                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
4541 +       if (flags & S_IXUNLINK)
4542 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
4543 +
4544         if (flags & S_APPEND)
4545                 jfs_ip->mode2 |= JFS_APPEND_FL;
4546         if (flags & S_NOATIME)
4547 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
4548                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
4549         if (flags & S_SYNC)
4550                 jfs_ip->mode2 |= JFS_SYNC_FL;
4551 +
4552 +       if (vflags & V_BARRIER)
4553 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
4554 +       if (vflags & V_COW)
4555 +               jfs_ip->mode2 |= JFS_COW_FL;
4556  }
4557  
4558  /*
4559 diff -NurpP --minimal linux-2.6.36/fs/jfs/jfs_inode.h linux-2.6.36-vs2.3.0.36.36/fs/jfs/jfs_inode.h
4560 --- linux-2.6.36/fs/jfs/jfs_inode.h     2010-10-21 13:07:50.000000000 +0200
4561 +++ linux-2.6.36-vs2.3.0.36.36/fs/jfs/jfs_inode.h       2010-10-21 13:09:36.000000000 +0200
4562 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
4563  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
4564         int fh_len, int fh_type);
4565  extern void jfs_set_inode_flags(struct inode *);
4566 +extern int jfs_sync_flags(struct inode *, int, int);
4567  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
4568  extern int jfs_setattr(struct dentry *, struct iattr *);
4569  
4570 diff -NurpP --minimal linux-2.6.36/fs/jfs/namei.c linux-2.6.36-vs2.3.0.36.36/fs/jfs/namei.c
4571 --- linux-2.6.36/fs/jfs/namei.c 2010-07-07 18:31:52.000000000 +0200
4572 +++ linux-2.6.36-vs2.3.0.36.36/fs/jfs/namei.c   2010-10-21 13:09:36.000000000 +0200
4573 @@ -21,6 +21,7 @@
4574  #include <linux/ctype.h>
4575  #include <linux/quotaops.h>
4576  #include <linux/exportfs.h>
4577 +#include <linux/vs_tag.h>
4578  #include "jfs_incore.h"
4579  #include "jfs_superblock.h"
4580  #include "jfs_inode.h"
4581 @@ -1491,6 +1492,7 @@ static struct dentry *jfs_lookup(struct 
4582                 return ERR_CAST(ip);
4583         }
4584  
4585 +       dx_propagate_tag(nd, ip);
4586         dentry = d_splice_alias(ip, dentry);
4587  
4588         if (dentry && (JFS_SBI(dip->i_sb)->mntflag & JFS_OS2))
4589 @@ -1560,6 +1562,7 @@ const struct inode_operations jfs_dir_in
4590  #ifdef CONFIG_JFS_POSIX_ACL
4591         .check_acl      = jfs_check_acl,
4592  #endif
4593 +       .sync_flags     = jfs_sync_flags,
4594  };
4595  
4596  const struct file_operations jfs_dir_operations = {
4597 diff -NurpP --minimal linux-2.6.36/fs/jfs/super.c linux-2.6.36-vs2.3.0.36.36/fs/jfs/super.c
4598 --- linux-2.6.36/fs/jfs/super.c 2010-10-21 13:07:50.000000000 +0200
4599 +++ linux-2.6.36-vs2.3.0.36.36/fs/jfs/super.c   2010-10-21 13:09:36.000000000 +0200
4600 @@ -195,7 +195,8 @@ static void jfs_put_super(struct super_b
4601  enum {
4602         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4603         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4604 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
4605 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4606 +       Opt_tag, Opt_notag, Opt_tagid
4607  };
4608  
4609  static const match_table_t tokens = {
4610 @@ -205,6 +206,10 @@ static const match_table_t tokens = {
4611         {Opt_resize, "resize=%u"},
4612         {Opt_resize_nosize, "resize"},
4613         {Opt_errors, "errors=%s"},
4614 +       {Opt_tag, "tag"},
4615 +       {Opt_notag, "notag"},
4616 +       {Opt_tagid, "tagid=%u"},
4617 +       {Opt_tag, "tagxid"},
4618         {Opt_ignore, "noquota"},
4619         {Opt_ignore, "quota"},
4620         {Opt_usrquota, "usrquota"},
4621 @@ -339,6 +344,20 @@ static int parse_options(char *options, 
4622                         }
4623                         break;
4624                 }
4625 +#ifndef CONFIG_TAGGING_NONE
4626 +               case Opt_tag:
4627 +                       *flag |= JFS_TAGGED;
4628 +                       break;
4629 +               case Opt_notag:
4630 +                       *flag &= JFS_TAGGED;
4631 +                       break;
4632 +#endif
4633 +#ifdef CONFIG_PROPAGATE
4634 +               case Opt_tagid:
4635 +                       /* use args[0] */
4636 +                       *flag |= JFS_TAGGED;
4637 +                       break;
4638 +#endif
4639                 default:
4640                         printk("jfs: Unrecognized mount option \"%s\" "
4641                                         " or missing value\n", p);
4642 @@ -369,6 +388,12 @@ static int jfs_remount(struct super_bloc
4643         if (!parse_options(data, sb, &newLVSize, &flag)) {
4644                 return -EINVAL;
4645         }
4646 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4647 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4648 +                       sb->s_id);
4649 +               return -EINVAL;
4650 +       }
4651 +
4652         lock_kernel();
4653         if (newLVSize) {
4654                 if (sb->s_flags & MS_RDONLY) {
4655 @@ -460,6 +485,9 @@ static int jfs_fill_super(struct super_b
4656  #ifdef CONFIG_JFS_POSIX_ACL
4657         sb->s_flags |= MS_POSIXACL;
4658  #endif
4659 +       /* map mount option tagxid */
4660 +       if (sbi->flag & JFS_TAGGED)
4661 +               sb->s_flags |= MS_TAGGED;
4662  
4663         if (newLVSize) {
4664                 printk(KERN_ERR "resize option for remount only\n");
4665 diff -NurpP --minimal linux-2.6.36/fs/libfs.c linux-2.6.36-vs2.3.0.36.36/fs/libfs.c
4666 --- linux-2.6.36/fs/libfs.c     2010-10-21 13:07:50.000000000 +0200
4667 +++ linux-2.6.36-vs2.3.0.36.36/fs/libfs.c       2010-10-21 13:09:36.000000000 +0200
4668 @@ -124,7 +124,8 @@ static inline unsigned char dt_type(stru
4669   * both impossible due to the lock on directory.
4670   */
4671  
4672 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4673 +static inline int do_dcache_readdir_filter(struct file *filp,
4674 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4675  {
4676         struct dentry *dentry = filp->f_path.dentry;
4677         struct dentry *cursor = filp->private_data;
4678 @@ -157,6 +158,8 @@ int dcache_readdir(struct file * filp, v
4679                                 next = list_entry(p, struct dentry, d_u.d_child);
4680                                 if (d_unhashed(next) || !next->d_inode)
4681                                         continue;
4682 +                               if (filter && !filter(next))
4683 +                                       continue;
4684  
4685                                 spin_unlock(&dcache_lock);
4686                                 if (filldir(dirent, next->d_name.name, 
4687 @@ -175,6 +178,18 @@ int dcache_readdir(struct file * filp, v
4688         return 0;
4689  }
4690  
4691 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4692 +{
4693 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4694 +}
4695 +
4696 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4697 +       int (*filter)(struct dentry *))
4698 +{
4699 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4700 +}
4701 +
4702 +
4703  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4704  {
4705         return -EISDIR;
4706 @@ -925,6 +940,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4707  EXPORT_SYMBOL(dcache_dir_lseek);
4708  EXPORT_SYMBOL(dcache_dir_open);
4709  EXPORT_SYMBOL(dcache_readdir);
4710 +EXPORT_SYMBOL(dcache_readdir_filter);
4711  EXPORT_SYMBOL(generic_read_dir);
4712  EXPORT_SYMBOL(get_sb_pseudo);
4713  EXPORT_SYMBOL(simple_write_begin);
4714 diff -NurpP --minimal linux-2.6.36/fs/locks.c linux-2.6.36-vs2.3.0.36.36/fs/locks.c
4715 --- linux-2.6.36/fs/locks.c     2010-07-07 18:31:52.000000000 +0200
4716 +++ linux-2.6.36-vs2.3.0.36.36/fs/locks.c       2010-10-21 13:09:36.000000000 +0200
4717 @@ -127,6 +127,8 @@
4718  #include <linux/time.h>
4719  #include <linux/rcupdate.h>
4720  #include <linux/pid_namespace.h>
4721 +#include <linux/vs_base.h>
4722 +#include <linux/vs_limit.h>
4723  
4724  #include <asm/uaccess.h>
4725  
4726 @@ -148,6 +150,8 @@ static struct kmem_cache *filelock_cache
4727  /* Allocate an empty lock structure. */
4728  static struct file_lock *locks_alloc_lock(void)
4729  {
4730 +       if (!vx_locks_avail(1))
4731 +               return NULL;
4732         return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
4733  }
4734  
4735 @@ -174,6 +178,7 @@ static void locks_free_lock(struct file_
4736         BUG_ON(!list_empty(&fl->fl_block));
4737         BUG_ON(!list_empty(&fl->fl_link));
4738  
4739 +       vx_locks_dec(fl);
4740         locks_release_private(fl);
4741         kmem_cache_free(filelock_cache, fl);
4742  }
4743 @@ -194,6 +199,7 @@ void locks_init_lock(struct file_lock *f
4744         fl->fl_start = fl->fl_end = 0;
4745         fl->fl_ops = NULL;
4746         fl->fl_lmops = NULL;
4747 +       fl->fl_xid = -1;
4748  }
4749  
4750  EXPORT_SYMBOL(locks_init_lock);
4751 @@ -248,6 +254,7 @@ void locks_copy_lock(struct file_lock *n
4752         new->fl_file = fl->fl_file;
4753         new->fl_ops = fl->fl_ops;
4754         new->fl_lmops = fl->fl_lmops;
4755 +       new->fl_xid = fl->fl_xid;
4756  
4757         locks_copy_private(new, fl);
4758  }
4759 @@ -286,6 +293,11 @@ static int flock_make_lock(struct file *
4760         fl->fl_flags = FL_FLOCK;
4761         fl->fl_type = type;
4762         fl->fl_end = OFFSET_MAX;
4763 +
4764 +       vxd_assert(filp->f_xid == vx_current_xid(),
4765 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4766 +       fl->fl_xid = filp->f_xid;
4767 +       vx_locks_inc(fl);
4768         
4769         *lock = fl;
4770         return 0;
4771 @@ -451,6 +463,7 @@ static int lease_init(struct file *filp,
4772  
4773         fl->fl_owner = current->files;
4774         fl->fl_pid = current->tgid;
4775 +       fl->fl_xid = vx_current_xid();
4776  
4777         fl->fl_file = filp;
4778         fl->fl_flags = FL_LEASE;
4779 @@ -470,6 +483,11 @@ static struct file_lock *lease_alloc(str
4780         if (fl == NULL)
4781                 return ERR_PTR(error);
4782  
4783 +       fl->fl_xid = vx_current_xid();
4784 +       if (filp)
4785 +               vxd_assert(filp->f_xid == fl->fl_xid,
4786 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4787 +       vx_locks_inc(fl);
4788         error = lease_init(filp, type, fl);
4789         if (error) {
4790                 locks_free_lock(fl);
4791 @@ -770,6 +788,7 @@ static int flock_lock_file(struct file *
4792         if (found)
4793                 cond_resched();
4794  
4795 +       new_fl->fl_xid = -1;
4796  find_conflict:
4797         for_each_lock(inode, before) {
4798                 struct file_lock *fl = *before;
4799 @@ -790,6 +809,7 @@ find_conflict:
4800                 goto out;
4801         locks_copy_lock(new_fl, request);
4802         locks_insert_lock(before, new_fl);
4803 +       vx_locks_inc(new_fl);
4804         new_fl = NULL;
4805         error = 0;
4806  
4807 @@ -800,7 +820,8 @@ out:
4808         return error;
4809  }
4810  
4811 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4812 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4813 +       struct file_lock *conflock, xid_t xid)
4814  {
4815         struct file_lock *fl;
4816         struct file_lock *new_fl = NULL;
4817 @@ -810,6 +831,8 @@ static int __posix_lock_file(struct inod
4818         struct file_lock **before;
4819         int error, added = 0;
4820  
4821 +       vxd_assert(xid == vx_current_xid(),
4822 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4823         /*
4824          * We may need two file_lock structures for this operation,
4825          * so we get them in advance to avoid races.
4826 @@ -820,7 +843,11 @@ static int __posix_lock_file(struct inod
4827             (request->fl_type != F_UNLCK ||
4828              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4829                 new_fl = locks_alloc_lock();
4830 +               new_fl->fl_xid = xid;
4831 +               vx_locks_inc(new_fl);
4832                 new_fl2 = locks_alloc_lock();
4833 +               new_fl2->fl_xid = xid;
4834 +               vx_locks_inc(new_fl2);
4835         }
4836  
4837         lock_kernel();
4838 @@ -1019,7 +1046,8 @@ static int __posix_lock_file(struct inod
4839  int posix_lock_file(struct file *filp, struct file_lock *fl,
4840                         struct file_lock *conflock)
4841  {
4842 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
4843 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
4844 +               fl, conflock, filp->f_xid);
4845  }
4846  EXPORT_SYMBOL(posix_lock_file);
4847  
4848 @@ -1109,7 +1137,7 @@ int locks_mandatory_area(int read_write,
4849         fl.fl_end = offset + count - 1;
4850  
4851         for (;;) {
4852 -               error = __posix_lock_file(inode, &fl, NULL);
4853 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4854                 if (error != FILE_LOCK_DEFERRED)
4855                         break;
4856                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4857 @@ -1425,6 +1453,7 @@ int generic_setlease(struct file *filp, 
4858  
4859         locks_copy_lock(new_fl, lease);
4860         locks_insert_lock(before, new_fl);
4861 +       vx_locks_inc(new_fl);
4862  
4863         *flp = new_fl;
4864         return 0;
4865 @@ -1780,6 +1809,11 @@ int fcntl_setlk(unsigned int fd, struct 
4866         if (file_lock == NULL)
4867                 return -ENOLCK;
4868  
4869 +       vxd_assert(filp->f_xid == vx_current_xid(),
4870 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4871 +       file_lock->fl_xid = filp->f_xid;
4872 +       vx_locks_inc(file_lock);
4873 +
4874         /*
4875          * This might block, so we do it before checking the inode.
4876          */
4877 @@ -1898,6 +1932,11 @@ int fcntl_setlk64(unsigned int fd, struc
4878         if (file_lock == NULL)
4879                 return -ENOLCK;
4880  
4881 +       vxd_assert(filp->f_xid == vx_current_xid(),
4882 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4883 +       file_lock->fl_xid = filp->f_xid;
4884 +       vx_locks_inc(file_lock);
4885 +
4886         /*
4887          * This might block, so we do it before checking the inode.
4888          */
4889 @@ -2163,8 +2202,11 @@ static int locks_show(struct seq_file *f
4890  
4891         lock_get_status(f, fl, (long)f->private, "");
4892  
4893 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4894 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4895 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4896 +                       continue;
4897                 lock_get_status(f, bfl, (long)f->private, " ->");
4898 +       }
4899  
4900         f->private++;
4901         return 0;
4902 diff -NurpP --minimal linux-2.6.36/fs/namei.c linux-2.6.36-vs2.3.0.36.36/fs/namei.c
4903 --- linux-2.6.36/fs/namei.c     2010-10-21 13:07:50.000000000 +0200
4904 +++ linux-2.6.36-vs2.3.0.36.36/fs/namei.c       2010-10-21 22:09:46.000000000 +0200
4905 @@ -32,6 +32,14 @@
4906  #include <linux/fcntl.h>
4907  #include <linux/device_cgroup.h>
4908  #include <linux/fs_struct.h>
4909 +#include <linux/proc_fs.h>
4910 +#include <linux/vserver/inode.h>
4911 +#include <linux/vs_base.h>
4912 +#include <linux/vs_tag.h>
4913 +#include <linux/vs_cowbl.h>
4914 +#include <linux/vs_device.h>
4915 +#include <linux/vs_context.h>
4916 +#include <linux/pid_namespace.h>
4917  #include <asm/uaccess.h>
4918  
4919  #include "internal.h"
4920 @@ -166,6 +174,84 @@ void putname(const char *name)
4921  EXPORT_SYMBOL(putname);
4922  #endif
4923  
4924 +static inline int dx_barrier(const struct inode *inode)
4925 +{
4926 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4927 +               vxwprintk_task(1, "did hit the barrier.");
4928 +               return 1;
4929 +       }
4930 +       return 0;
4931 +}
4932 +
4933 +static int __dx_permission(const struct inode *inode, int mask)
4934 +{
4935 +       if (dx_barrier(inode))
4936 +               return -EACCES;
4937 +
4938 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4939 +               /* devpts is xid tagged */
4940 +               if (S_ISDIR(inode->i_mode) ||
4941 +                   vx_check((xid_t)inode->i_tag, VS_IDENT | VS_WATCH_P))
4942 +                       return 0;
4943 +
4944 +               /* just say we didn't find anything */
4945 +               return -ENOENT;
4946 +       }
4947 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4948 +               struct proc_dir_entry *de = PDE(inode);
4949 +
4950 +               if (de && !vx_hide_check(0, de->vx_flags))
4951 +                       goto out;
4952 +
4953 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4954 +                       struct pid *pid;
4955 +                       struct task_struct *tsk;
4956 +
4957 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4958 +                           vx_flags(VXF_STATE_SETUP, 0))
4959 +                               return 0;
4960 +
4961 +                       pid = PROC_I(inode)->pid;
4962 +                       if (!pid)
4963 +                               goto out;
4964 +
4965 +                       tsk = pid_task(pid, PIDTYPE_PID);
4966 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4967 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4968 +                       if (tsk && vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P))
4969 +                               return 0;
4970 +               }
4971 +               else {
4972 +                       /* FIXME: Should we block some entries here? */
4973 +                       return 0;
4974 +               }
4975 +       }
4976 +       else {
4977 +               if (dx_notagcheck(inode->i_sb) ||
4978 +                   dx_check(inode->i_tag, DX_HOSTID | DX_ADMIN | DX_WATCH |
4979 +                            DX_IDENT))
4980 +                       return 0;
4981 +       }
4982 +
4983 +out:
4984 +       return -EACCES;
4985 +}
4986 +
4987 +int dx_permission(const struct inode *inode, int mask)
4988 +{
4989 +       int ret = __dx_permission(inode, mask);
4990 +       if (unlikely(ret)) {
4991 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
4992 +               if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4993 +#endif
4994 +                   vxwprintk_task(1,
4995 +                       "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4996 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
4997 +                       inode->i_ino);
4998 +       }
4999 +       return ret;
5000 +}
5001 +
5002  /*
5003   * This does basic POSIX ACL permission checking
5004   */
5005 @@ -266,10 +352,14 @@ int inode_permission(struct inode *inode
5006                 /*
5007                  * Nobody gets write access to an immutable file.
5008                  */
5009 -               if (IS_IMMUTABLE(inode))
5010 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
5011                         return -EACCES;
5012         }
5013  
5014 +       retval = dx_permission(inode, mask);
5015 +       if (retval)
5016 +               return retval;
5017 +
5018         if (inode->i_op->permission)
5019                 retval = inode->i_op->permission(inode, mask);
5020         else
5021 @@ -463,6 +553,9 @@ static int exec_permission(struct inode 
5022  {
5023         int ret;
5024  
5025 +       if (dx_barrier(inode))
5026 +               return -EACCES;
5027 +
5028         if (inode->i_op->permission) {
5029                 ret = inode->i_op->permission(inode, MAY_EXEC);
5030                 if (!ret)
5031 @@ -672,7 +765,8 @@ static __always_inline void follow_dotdo
5032  
5033                 if (nd->path.dentry == nd->root.dentry &&
5034                     nd->path.mnt == nd->root.mnt) {
5035 -                       break;
5036 +                       /* for sane '/' avoid follow_mount() */
5037 +                       return;
5038                 }
5039                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
5040                         /* rare case of legitimate dget_parent()... */
5041 @@ -725,7 +819,7 @@ static int do_lookup(struct nameidata *n
5042  {
5043         struct vfsmount *mnt = nd->path.mnt;
5044         struct dentry *dentry, *parent;
5045 -       struct inode *dir;
5046 +       struct inode *dir, *inode;
5047         /*
5048          * See if the low-level filesystem might want
5049          * to use its own hash..
5050 @@ -747,12 +841,31 @@ static int do_lookup(struct nameidata *n
5051  found:
5052         if (dentry->d_op && dentry->d_op->d_revalidate)
5053                 goto need_revalidate;
5054 +
5055 +       inode = dentry->d_inode;
5056 +       if (!inode)
5057 +               goto done;
5058 +
5059 +       if (__dx_permission(inode, MAY_ACCESS))
5060 +               goto hidden;
5061  done:
5062         path->mnt = mnt;
5063         path->dentry = dentry;
5064         __follow_mount(path);
5065         return 0;
5066  
5067 +hidden:
5068 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
5069 +       if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
5070 +#endif
5071 +           vxwprintk_task(1,
5072 +               "did lookup hidden %s:%p[#%d,%lu] " VS_Q("%s/%.*s") ".",
5073 +               inode->i_sb->s_id, inode, inode->i_tag, inode->i_ino,
5074 +               vxd_path(&nd->path), name->len, name->name);
5075 +
5076 +       dput(dentry);
5077 +       return -ENOENT;
5078 +
5079  need_lookup:
5080         parent = nd->path.dentry;
5081         dir = parent->d_inode;
5082 @@ -1307,7 +1420,7 @@ static int may_delete(struct inode *dir,
5083         if (IS_APPEND(dir))
5084                 return -EPERM;
5085         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
5086 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
5087 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
5088                 return -EPERM;
5089         if (isdir) {
5090                 if (!S_ISDIR(victim->d_inode->i_mode))
5091 @@ -1430,6 +1543,14 @@ int may_open(struct path *path, int acc_
5092                 break;
5093         }
5094  
5095 +#ifdef CONFIG_VSERVER_COWBL
5096 +       if (IS_COW(inode) && (flag & FMODE_WRITE)) {
5097 +               if (IS_COW_LINK(inode))
5098 +                       return -EMLINK;
5099 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
5100 +               mark_inode_dirty(inode);
5101 +       }
5102 +#endif
5103         error = inode_permission(inode, acc_mode);
5104         if (error)
5105                 return error;
5106 @@ -1538,7 +1659,8 @@ static int open_will_truncate(int flag, 
5107  }
5108  
5109  static struct file *finish_open(struct nameidata *nd,
5110 -                               int open_flag, int acc_mode)
5111 +                               int open_flag, int acc_mode,
5112 +                               const char *pathname)
5113  {
5114         struct file *filp;
5115         int will_truncate;
5116 @@ -1551,6 +1673,23 @@ static struct file *finish_open(struct n
5117                         goto exit;
5118         }
5119         error = may_open(&nd->path, acc_mode, open_flag);
5120 +#ifdef CONFIG_VSERVER_COWBL
5121 +       if (error == -EMLINK) {
5122 +               struct dentry *dentry;
5123 +               dentry = cow_break_link(pathname);
5124 +               if (IS_ERR(dentry)) {
5125 +                       error = PTR_ERR(dentry);
5126 +                       goto exit_cow;
5127 +               }
5128 +               dput(dentry);
5129 +               if (will_truncate)
5130 +                       mnt_drop_write(nd->path.mnt);
5131 +               release_open_intent(nd);
5132 +               path_put(&nd->path);
5133 +               return ERR_PTR(-EMLINK);
5134 +       }
5135 +exit_cow:
5136 +#endif
5137         if (error) {
5138                 if (will_truncate)
5139                         mnt_drop_write(nd->path.mnt);
5140 @@ -1719,7 +1858,7 @@ static struct file *do_last(struct namei
5141         if (S_ISDIR(path->dentry->d_inode->i_mode))
5142                 goto exit;
5143  ok:
5144 -       filp = finish_open(nd, open_flag, acc_mode);
5145 +       filp = finish_open(nd, open_flag, acc_mode, pathname);
5146         return filp;
5147  
5148  exit_mutex_unlock:
5149 @@ -1748,7 +1887,11 @@ struct file *do_filp_open(int dfd, const
5150         int count = 0;
5151         int flag = open_to_namei_flags(open_flag);
5152         int force_reval = 0;
5153 -
5154 +#ifdef CONFIG_VSERVER_COWBL
5155 +       int rflag = flag;
5156 +       int rmode = mode;
5157 +restart:
5158 +#endif
5159         if (!(open_flag & O_CREAT))
5160                 mode = 0;
5161  
5162 @@ -1814,6 +1957,13 @@ reval:
5163         if (!(open_flag & O_NOFOLLOW))
5164                 nd.flags |= LOOKUP_FOLLOW;
5165         filp = do_last(&nd, &path, open_flag, acc_mode, mode, pathname);
5166 +#ifdef CONFIG_VSERVER_COWBL
5167 +       if (unlikely(IS_ERR(filp) && PTR_ERR(filp) == -EMLINK)) {
5168 +               flag = rflag;
5169 +               mode = rmode;
5170 +               goto restart;
5171 +       }
5172 +#endif
5173         while (unlikely(!filp)) { /* trailing symlink */
5174                 struct path holder;
5175                 struct inode *inode = path.dentry->d_inode;
5176 @@ -1852,6 +2002,13 @@ reval:
5177                 holder = path;
5178                 nd.flags &= ~LOOKUP_PARENT;
5179                 filp = do_last(&nd, &path, open_flag, acc_mode, mode, pathname);
5180 +#ifdef CONFIG_VSERVER_COWBL
5181 +               if (unlikely(IS_ERR(filp) && PTR_ERR(filp) == -EMLINK)) {
5182 +                       flag = rflag;
5183 +                       mode = rmode;
5184 +                       goto restart;
5185 +               }
5186 +#endif
5187                 if (inode->i_op->put_link)
5188                         inode->i_op->put_link(holder.dentry, &nd, cookie);
5189                 path_put(&holder);
5190 @@ -1952,9 +2109,17 @@ int vfs_mknod(struct inode *dir, struct 
5191         if (error)
5192                 return error;
5193  
5194 -       if ((S_ISCHR(mode) || S_ISBLK(mode)) && !capable(CAP_MKNOD))
5195 +       if (!(S_ISCHR(mode) || S_ISBLK(mode)))
5196 +               goto okay;
5197 +
5198 +       if (!capable(CAP_MKNOD))
5199                 return -EPERM;
5200  
5201 +       if (S_ISCHR(mode) && !vs_chrdev_perm(dev, DATTR_CREATE))
5202 +               return -EPERM;
5203 +       if (S_ISBLK(mode) && !vs_blkdev_perm(dev, DATTR_CREATE))
5204 +               return -EPERM;
5205 +okay:
5206         if (!dir->i_op->mknod)
5207                 return -EPERM;
5208  
5209 @@ -2419,7 +2584,7 @@ int vfs_link(struct dentry *old_dentry, 
5210         /*
5211          * A link to an append-only or immutable file cannot be created.
5212          */
5213 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
5214 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
5215                 return -EPERM;
5216         if (!dir->i_op->link)
5217                 return -EPERM;
5218 @@ -2791,6 +2956,222 @@ int vfs_follow_link(struct nameidata *nd
5219         return __vfs_follow_link(nd, link);
5220  }
5221  
5222 +
5223 +#ifdef CONFIG_VSERVER_COWBL
5224 +
5225 +#include <linux/file.h>
5226 +
5227 +static inline
5228 +long do_cow_splice(struct file *in, struct file *out, size_t len)
5229 +{
5230 +       loff_t ppos = 0;
5231 +
5232 +       return do_splice_direct(in, &ppos, out, len, 0);
5233 +}
5234 +
5235 +struct dentry *cow_break_link(const char *pathname)
5236 +{
5237 +       int ret, mode, pathlen, redo = 0;
5238 +       struct nameidata old_nd, dir_nd;
5239 +       struct path old_path, new_path;
5240 +       struct dentry *dir, *res = NULL;
5241 +       struct file *old_file;
5242 +       struct file *new_file;
5243 +       char *to, *path, pad='\251';
5244 +       loff_t size;
5245 +
5246 +       vxdprintk(VXD_CBIT(misc, 1),
5247 +               "cow_break_link(" VS_Q("%s") ")", pathname);
5248 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
5249 +       ret = -ENOMEM;
5250 +       if (!path)
5251 +               goto out;
5252 +
5253 +       /* old_nd will have refs to dentry and mnt */
5254 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5255 +       vxdprintk(VXD_CBIT(misc, 2), "path_lookup(old): %d", ret);
5256 +       if (ret < 0)
5257 +               goto out_free_path;
5258 +
5259 +       old_path = old_nd.path;
5260 +       mode = old_path.dentry->d_inode->i_mode;
5261 +
5262 +       to = d_path(&old_path, path, PATH_MAX-2);
5263 +       pathlen = strlen(to);
5264 +       vxdprintk(VXD_CBIT(misc, 2),
5265 +               "old path " VS_Q("%s") " [" VS_Q("%.*s") ":%d]", to,
5266 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5267 +               old_path.dentry->d_name.len);
5268 +
5269 +       to[pathlen + 1] = 0;
5270 +retry:
5271 +       to[pathlen] = pad--;
5272 +       ret = -EMLINK;
5273 +       if (pad <= '\240')
5274 +               goto out_rel_old;
5275 +
5276 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
5277 +       /* dir_nd will have refs to dentry and mnt */
5278 +       ret = path_lookup(to,
5279 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
5280 +       vxdprintk(VXD_CBIT(misc, 2),
5281 +               "path_lookup(new): %d", ret);
5282 +       if (ret < 0)
5283 +               goto retry;
5284 +
5285 +       /* this puppy downs the inode mutex */
5286 +       new_path.dentry = lookup_create(&dir_nd, 0);
5287 +       if (!new_path.dentry || IS_ERR(new_path.dentry)) {
5288 +               vxdprintk(VXD_CBIT(misc, 2),
5289 +                       "lookup_create(new): %p", new_path.dentry);
5290 +               mutex_unlock(&dir_nd.path.dentry->d_inode->i_mutex);
5291 +               path_put(&dir_nd.path);
5292 +               goto retry;
5293 +       }
5294 +       vxdprintk(VXD_CBIT(misc, 2),
5295 +               "lookup_create(new): %p [" VS_Q("%.*s") ":%d]",
5296 +               new_path.dentry,
5297 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5298 +               new_path.dentry->d_name.len);
5299 +       dir = dir_nd.path.dentry;
5300 +
5301 +       ret = vfs_create(dir_nd.path.dentry->d_inode, new_path.dentry, mode, &dir_nd);
5302 +       vxdprintk(VXD_CBIT(misc, 2),
5303 +               "vfs_create(new): %d", ret);
5304 +       if (ret == -EEXIST) {
5305 +               mutex_unlock(&dir->d_inode->i_mutex);
5306 +               dput(new_path.dentry);
5307 +               path_put(&dir_nd.path);
5308 +               goto retry;
5309 +       }
5310 +       else if (ret < 0)
5311 +               goto out_unlock_new;
5312 +
5313 +       /* drop out early, ret passes ENOENT */
5314 +       ret = -ENOENT;
5315 +       if ((redo = d_unhashed(old_path.dentry)))
5316 +               goto out_unlock_new;
5317 +
5318 +       new_path.mnt = dir_nd.path.mnt;
5319 +       dget(old_path.dentry);
5320 +       mntget(old_path.mnt);
5321 +       /* this one cleans up the dentry/mnt in case of failure */
5322 +       old_file = dentry_open(old_path.dentry, old_path.mnt,
5323 +               O_RDONLY, current_cred());
5324 +       vxdprintk(VXD_CBIT(misc, 2),
5325 +               "dentry_open(old): %p", old_file);
5326 +       if (!old_file || IS_ERR(old_file)) {
5327 +               res = IS_ERR(old_file) ? (void *) old_file : res;
5328 +               goto out_unlock_new;
5329 +       }
5330 +
5331 +       dget(new_path.dentry);
5332 +       mntget(new_path.mnt);
5333 +       /* this one cleans up the dentry/mnt in case of failure */
5334 +       new_file = dentry_open(new_path.dentry, new_path.mnt,
5335 +               O_WRONLY, current_cred());
5336 +       vxdprintk(VXD_CBIT(misc, 2),
5337 +               "dentry_open(new): %p", new_file);
5338 +
5339 +       ret = IS_ERR(new_file) ? PTR_ERR(new_file) : -ENOENT;
5340 +       if (!new_file || IS_ERR(new_file))
5341 +               goto out_fput_old;
5342 +
5343 +       size = i_size_read(old_file->f_dentry->d_inode);
5344 +       ret = do_cow_splice(old_file, new_file, size);
5345 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
5346 +       if (ret < 0) {
5347 +               goto out_fput_both;
5348 +       } else if (ret < size) {
5349 +               ret = -ENOSPC;
5350 +               goto out_fput_both;
5351 +       } else {
5352 +               struct inode *old_inode = old_path.dentry->d_inode;
5353 +               struct inode *new_inode = new_path.dentry->d_inode;
5354 +               struct iattr attr = {
5355 +                       .ia_uid = old_inode->i_uid,
5356 +                       .ia_gid = old_inode->i_gid,
5357 +                       .ia_valid = ATTR_UID | ATTR_GID
5358 +                       };
5359 +
5360 +               setattr_copy(new_inode, &attr);
5361 +               mark_inode_dirty(new_inode);
5362 +       }
5363 +
5364 +       mutex_lock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5365 +
5366 +       /* drop out late */
5367 +       ret = -ENOENT;
5368 +       if ((redo = d_unhashed(old_path.dentry)))
5369 +               goto out_unlock;
5370 +
5371 +       vxdprintk(VXD_CBIT(misc, 2),
5372 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
5373 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5374 +               new_path.dentry->d_name.len,
5375 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5376 +               old_path.dentry->d_name.len);
5377 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_path.dentry,
5378 +               old_nd.path.dentry->d_parent->d_inode, old_path.dentry);
5379 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
5380 +       res = new_path.dentry;
5381 +
5382 +out_unlock:
5383 +       mutex_unlock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5384 +
5385 +out_fput_both:
5386 +       vxdprintk(VXD_CBIT(misc, 3),
5387 +               "fput(new_file=%p[#%ld])", new_file,
5388 +               atomic_long_read(&new_file->f_count));
5389 +       fput(new_file);
5390 +
5391 +out_fput_old:
5392 +       vxdprintk(VXD_CBIT(misc, 3),
5393 +               "fput(old_file=%p[#%ld])", old_file,
5394 +               atomic_long_read(&old_file->f_count));
5395 +       fput(old_file);
5396 +
5397 +out_unlock_new:
5398 +       mutex_unlock(&dir->d_inode->i_mutex);
5399 +       if (!ret)
5400 +               goto out_redo;
5401 +
5402 +       /* error path cleanup */
5403 +       vfs_unlink(dir->d_inode, new_path.dentry);
5404 +       dput(new_path.dentry);
5405 +
5406 +out_redo:
5407 +       if (!redo)
5408 +               goto out_rel_both;
5409 +       /* lookup dentry once again */
5410 +       path_put(&old_nd.path);
5411 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5412 +       if (ret)
5413 +               goto out_rel_both;
5414 +
5415 +       new_path.dentry = old_nd.path.dentry;
5416 +       vxdprintk(VXD_CBIT(misc, 2),
5417 +               "path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
5418 +               new_path.dentry,
5419 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5420 +               new_path.dentry->d_name.len);
5421 +       dget(new_path.dentry);
5422 +       res = new_path.dentry;
5423 +
5424 +out_rel_both:
5425 +       path_put(&dir_nd.path);
5426 +out_rel_old:
5427 +       path_put(&old_nd.path);
5428 +out_free_path:
5429 +       kfree(path);
5430 +out:
5431 +       if (ret)
5432 +               res = ERR_PTR(ret);
5433 +       return res;
5434 +}
5435 +
5436 +#endif
5437 +
5438  /* get the link contents into pagecache */
5439  static char *page_getlink(struct dentry * dentry, struct page **ppage)
5440  {
5441 diff -NurpP --minimal linux-2.6.36/fs/namespace.c linux-2.6.36-vs2.3.0.36.36/fs/namespace.c
5442 --- linux-2.6.36/fs/namespace.c 2010-10-21 13:07:50.000000000 +0200
5443 +++ linux-2.6.36-vs2.3.0.36.36/fs/namespace.c   2010-10-21 15:11:02.000000000 +0200
5444 @@ -32,6 +32,11 @@
5445  #include <linux/idr.h>
5446  #include <linux/fs_struct.h>
5447  #include <linux/fsnotify.h>
5448 +#include <linux/vs_base.h>
5449 +#include <linux/vs_context.h>
5450 +#include <linux/vs_tag.h>
5451 +#include <linux/vserver/space.h>
5452 +#include <linux/vserver/global.h>
5453  #include <asm/uaccess.h>
5454  #include <asm/unistd.h>
5455  #include "pnode.h"
5456 @@ -601,6 +606,7 @@ static struct vfsmount *clone_mnt(struct
5457                 mnt->mnt_root = dget(root);
5458                 mnt->mnt_mountpoint = mnt->mnt_root;
5459                 mnt->mnt_parent = mnt;
5460 +               mnt->mnt_tag = old->mnt_tag;
5461  
5462                 if (flag & CL_SLAVE) {
5463                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
5464 @@ -699,6 +705,31 @@ static inline void mangle(struct seq_fil
5465         seq_escape(m, s, " \t\n\\");
5466  }
5467  
5468 +static int mnt_is_reachable(struct vfsmount *mnt)
5469 +{
5470 +       struct path root;
5471 +       struct dentry *point;
5472 +       int ret;
5473 +
5474 +       if (mnt == mnt->mnt_ns->root)
5475 +               return 1;
5476 +
5477 +       br_read_lock(vfsmount_lock);
5478 +       root = current->fs->root;
5479 +       point = root.dentry;
5480 +
5481 +       while ((mnt != mnt->mnt_parent) && (mnt != root.mnt)) {
5482 +               point = mnt->mnt_mountpoint;
5483 +               mnt = mnt->mnt_parent;
5484 +       }
5485 +
5486 +       ret = (mnt == root.mnt) && is_subdir(point, root.dentry);
5487 +
5488 +       br_read_unlock(vfsmount_lock);
5489 +
5490 +       return ret;
5491 +}
5492 +
5493  /*
5494   * Simple .show_options callback for filesystems which don't want to
5495   * implement more complex mount option showing.
5496 @@ -801,6 +832,8 @@ static int show_sb_opts(struct seq_file 
5497                 { MS_SYNCHRONOUS, ",sync" },
5498                 { MS_DIRSYNC, ",dirsync" },
5499                 { MS_MANDLOCK, ",mand" },
5500 +               { MS_TAGGED, ",tag" },
5501 +               { MS_NOTAGCHECK, ",notagcheck" },
5502                 { 0, NULL }
5503         };
5504         const struct proc_fs_info *fs_infop;
5505 @@ -847,10 +880,20 @@ static int show_vfsmnt(struct seq_file *
5506         int err = 0;
5507         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5508  
5509 -       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5510 -       seq_putc(m, ' ');
5511 -       seq_path(m, &mnt_path, " \t\n\\");
5512 -       seq_putc(m, ' ');
5513 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5514 +               return SEQ_SKIP;
5515 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5516 +               return SEQ_SKIP;
5517 +
5518 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5519 +               mnt == current->fs->root.mnt) {
5520 +               seq_puts(m, "/dev/root / ");
5521 +       } else {
5522 +               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5523 +               seq_putc(m, ' ');
5524 +               seq_path(m, &mnt_path, " \t\n\\");
5525 +               seq_putc(m, ' ');
5526 +       }
5527         show_type(m, mnt->mnt_sb);
5528         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
5529         err = show_sb_opts(m, mnt->mnt_sb);
5530 @@ -880,6 +923,11 @@ static int show_mountinfo(struct seq_fil
5531         struct path root = p->root;
5532         int err = 0;
5533  
5534 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5535 +               return SEQ_SKIP;
5536 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5537 +               return SEQ_SKIP;
5538 +
5539         seq_printf(m, "%i %i %u:%u ", mnt->mnt_id, mnt->mnt_parent->mnt_id,
5540                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
5541         seq_dentry(m, mnt->mnt_root, " \t\n\\");
5542 @@ -938,17 +986,27 @@ static int show_vfsstat(struct seq_file 
5543         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5544         int err = 0;
5545  
5546 -       /* device */
5547 -       if (mnt->mnt_devname) {
5548 -               seq_puts(m, "device ");
5549 -               mangle(m, mnt->mnt_devname);
5550 -       } else
5551 -               seq_puts(m, "no device");
5552 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5553 +               return SEQ_SKIP;
5554 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5555 +               return SEQ_SKIP;
5556  
5557 -       /* mount point */
5558 -       seq_puts(m, " mounted on ");
5559 -       seq_path(m, &mnt_path, " \t\n\\");
5560 -       seq_putc(m, ' ');
5561 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5562 +               mnt == current->fs->root.mnt) {
5563 +               seq_puts(m, "device /dev/root mounted on / ");
5564 +       } else {
5565 +               /* device */
5566 +               if (mnt->mnt_devname) {
5567 +                       seq_puts(m, "device ");
5568 +                       mangle(m, mnt->mnt_devname);
5569 +               } else
5570 +                       seq_puts(m, "no device");
5571 +
5572 +               /* mount point */
5573 +               seq_puts(m, " mounted on ");
5574 +               seq_path(m, &mnt_path, " \t\n\\");
5575 +               seq_putc(m, ' ');
5576 +       }
5577  
5578         /* file system type */
5579         seq_puts(m, "with fstype ");
5580 @@ -1194,7 +1252,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
5581                 goto dput_and_out;
5582  
5583         retval = -EPERM;
5584 -       if (!capable(CAP_SYS_ADMIN))
5585 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5586                 goto dput_and_out;
5587  
5588         retval = do_umount(path.mnt, flags);
5589 @@ -1220,7 +1278,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
5590  
5591  static int mount_is_safe(struct path *path)
5592  {
5593 -       if (capable(CAP_SYS_ADMIN))
5594 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5595                 return 0;
5596         return -EPERM;
5597  #ifdef notyet
5598 @@ -1510,7 +1568,7 @@ static int do_change_type(struct path *p
5599         int type;
5600         int err = 0;
5601  
5602 -       if (!capable(CAP_SYS_ADMIN))
5603 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_NAMESPACE))
5604                 return -EPERM;
5605  
5606         if (path->dentry != path->mnt->mnt_root)
5607 @@ -1541,11 +1599,13 @@ static int do_change_type(struct path *p
5608   * do loopback mount.
5609   */
5610  static int do_loopback(struct path *path, char *old_name,
5611 -                               int recurse)
5612 +       tag_t tag, unsigned long flags, int mnt_flags)
5613  {
5614         struct path old_path;
5615         struct vfsmount *mnt = NULL;
5616         int err = mount_is_safe(path);
5617 +       int recurse = flags & MS_REC;
5618 +
5619         if (err)
5620                 return err;
5621         if (!old_name || !*old_name)
5622 @@ -1580,6 +1640,7 @@ static int do_loopback(struct path *path
5623                 br_write_unlock(vfsmount_lock);
5624                 release_mounts(&umount_list);
5625         }
5626 +       mnt->mnt_flags = mnt_flags;
5627  
5628  out:
5629         up_write(&namespace_sem);
5630 @@ -1610,12 +1671,12 @@ static int change_mount_flags(struct vfs
5631   * on it - tough luck.
5632   */
5633  static int do_remount(struct path *path, int flags, int mnt_flags,
5634 -                     void *data)
5635 +       void *data, xid_t xid)
5636  {
5637         int err;
5638         struct super_block *sb = path->mnt->mnt_sb;
5639  
5640 -       if (!capable(CAP_SYS_ADMIN))
5641 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
5642                 return -EPERM;
5643  
5644         if (!check_mnt(path->mnt))
5645 @@ -1659,7 +1720,7 @@ static int do_move_mount(struct path *pa
5646         struct path old_path, parent_path;
5647         struct vfsmount *p;
5648         int err = 0;
5649 -       if (!capable(CAP_SYS_ADMIN))
5650 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5651                 return -EPERM;
5652         if (!old_name || !*old_name)
5653                 return -EINVAL;
5654 @@ -1741,7 +1802,7 @@ static int do_new_mount(struct path *pat
5655                 return -EINVAL;
5656  
5657         /* we need capabilities... */
5658 -       if (!capable(CAP_SYS_ADMIN))
5659 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5660                 return -EPERM;
5661  
5662         lock_kernel();
5663 @@ -2009,6 +2070,7 @@ long do_mount(char *dev_name, char *dir_
5664         struct path path;
5665         int retval = 0;
5666         int mnt_flags = 0;
5667 +       tag_t tag = 0;
5668  
5669         /* Discard magic */
5670         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5671 @@ -2036,6 +2098,12 @@ long do_mount(char *dev_name, char *dir_
5672         if (!(flags & MS_NOATIME))
5673                 mnt_flags |= MNT_RELATIME;
5674  
5675 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5676 +               /* FIXME: bind and re-mounts get the tag flag? */
5677 +               if (flags & (MS_BIND|MS_REMOUNT))
5678 +                       flags |= MS_TAGID;
5679 +       }
5680 +
5681         /* Separate the per-mountpoint flags */
5682         if (flags & MS_NOSUID)
5683                 mnt_flags |= MNT_NOSUID;
5684 @@ -2052,15 +2120,17 @@ long do_mount(char *dev_name, char *dir_
5685         if (flags & MS_RDONLY)
5686                 mnt_flags |= MNT_READONLY;
5687  
5688 +       if (!capable(CAP_SYS_ADMIN))
5689 +               mnt_flags |= MNT_NODEV;
5690         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
5691                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
5692                    MS_STRICTATIME);
5693  
5694         if (flags & MS_REMOUNT)
5695                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5696 -                                   data_page);
5697 +                                   data_page, tag);
5698         else if (flags & MS_BIND)
5699 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5700 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5701         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5702                 retval = do_change_type(&path, flags);
5703         else if (flags & MS_MOVE)
5704 @@ -2139,6 +2209,7 @@ static struct mnt_namespace *dup_mnt_ns(
5705                 q = next_mnt(q, new_ns->root);
5706         }
5707         up_write(&namespace_sem);
5708 +       atomic_inc(&vs_global_mnt_ns);
5709  
5710         if (rootmnt)
5711                 mntput(rootmnt);
5712 @@ -2280,9 +2351,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5713         down_write(&namespace_sem);
5714         mutex_lock(&old.dentry->d_inode->i_mutex);
5715         error = -EINVAL;
5716 -       if (IS_MNT_SHARED(old.mnt) ||
5717 +       if ((IS_MNT_SHARED(old.mnt) ||
5718                 IS_MNT_SHARED(new.mnt->mnt_parent) ||
5719 -               IS_MNT_SHARED(root.mnt->mnt_parent))
5720 +               IS_MNT_SHARED(root.mnt->mnt_parent)) &&
5721 +               !vx_flags(VXF_STATE_SETUP, 0))
5722                 goto out2;
5723         if (!check_mnt(root.mnt))
5724                 goto out2;
5725 @@ -2415,6 +2487,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5726         br_write_unlock(vfsmount_lock);
5727         up_write(&namespace_sem);
5728         release_mounts(&umount_list);
5729 +       atomic_dec(&vs_global_mnt_ns);
5730         kfree(ns);
5731  }
5732  EXPORT_SYMBOL(put_mnt_ns);
5733 diff -NurpP --minimal linux-2.6.36/fs/nfs/client.c linux-2.6.36-vs2.3.0.36.36/fs/nfs/client.c
5734 --- linux-2.6.36/fs/nfs/client.c        2010-10-21 13:07:50.000000000 +0200
5735 +++ linux-2.6.36-vs2.3.0.36.36/fs/nfs/client.c  2010-10-21 13:09:36.000000000 +0200
5736 @@ -740,6 +740,9 @@ static int nfs_init_server_rpcclient(str
5737         if (server->flags & NFS_MOUNT_SOFT)
5738                 server->client->cl_softrtry = 1;
5739  
5740 +       server->client->cl_tag = 0;
5741 +       if (server->flags & NFS_MOUNT_TAGGED)
5742 +               server->client->cl_tag = 1;
5743         return 0;
5744  }
5745  
5746 @@ -911,6 +914,10 @@ static void nfs_server_set_fsinfo(struct
5747                 server->acdirmin = server->acdirmax = 0;
5748         }
5749  
5750 +       /* FIXME: needs fsinfo
5751 +       if (server->flags & NFS_MOUNT_TAGGED)
5752 +               sb->s_flags |= MS_TAGGED;       */
5753 +
5754         server->maxfilesize = fsinfo->maxfilesize;
5755  
5756         /* We're airborne Set socket buffersize */
5757 diff -NurpP --minimal linux-2.6.36/fs/nfs/dir.c linux-2.6.36-vs2.3.0.36.36/fs/nfs/dir.c
5758 --- linux-2.6.36/fs/nfs/dir.c   2010-10-21 13:07:50.000000000 +0200
5759 +++ linux-2.6.36-vs2.3.0.36.36/fs/nfs/dir.c     2010-10-21 13:09:36.000000000 +0200
5760 @@ -33,6 +33,7 @@
5761  #include <linux/namei.h>
5762  #include <linux/mount.h>
5763  #include <linux/sched.h>
5764 +#include <linux/vs_tag.h>
5765  
5766  #include "nfs4_fs.h"
5767  #include "delegation.h"
5768 @@ -986,6 +987,7 @@ static struct dentry *nfs_lookup(struct 
5769         if (IS_ERR(res))
5770                 goto out_unblock_sillyrename;
5771  
5772 +       dx_propagate_tag(nd, inode);
5773  no_entry:
5774         res = d_materialise_unique(dentry, inode);
5775         if (res != NULL) {
5776 diff -NurpP --minimal linux-2.6.36/fs/nfs/inode.c linux-2.6.36-vs2.3.0.36.36/fs/nfs/inode.c
5777 --- linux-2.6.36/fs/nfs/inode.c 2010-10-21 13:07:50.000000000 +0200
5778 +++ linux-2.6.36-vs2.3.0.36.36/fs/nfs/inode.c   2010-10-21 13:09:36.000000000 +0200
5779 @@ -37,6 +37,7 @@
5780  #include <linux/inet.h>
5781  #include <linux/nfs_xdr.h>
5782  #include <linux/slab.h>
5783 +#include <linux/vs_tag.h>
5784  
5785  #include <asm/system.h>
5786  #include <asm/uaccess.h>
5787 @@ -267,6 +268,8 @@ nfs_fhget(struct super_block *sb, struct
5788         if (inode->i_state & I_NEW) {
5789                 struct nfs_inode *nfsi = NFS_I(inode);
5790                 unsigned long now = jiffies;
5791 +               uid_t uid;
5792 +               gid_t gid;
5793  
5794                 /* We set i_ino for the few things that still rely on it,
5795                  * such as stat(2) */
5796 @@ -315,8 +318,8 @@ nfs_fhget(struct super_block *sb, struct
5797                 nfsi->change_attr = 0;
5798                 inode->i_size = 0;
5799                 inode->i_nlink = 0;
5800 -               inode->i_uid = -2;
5801 -               inode->i_gid = -2;
5802 +               uid = -2;
5803 +               gid = -2;
5804                 inode->i_blocks = 0;
5805                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5806  
5807 @@ -353,13 +356,13 @@ nfs_fhget(struct super_block *sb, struct
5808                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5809                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5810                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5811 -                       inode->i_uid = fattr->uid;
5812 +                       uid = fattr->uid;
5813                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5814                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5815                                 | NFS_INO_INVALID_ACCESS
5816                                 | NFS_INO_INVALID_ACL;
5817                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5818 -                       inode->i_gid = fattr->gid;
5819 +                       gid = fattr->gid;
5820                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5821                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5822                                 | NFS_INO_INVALID_ACCESS
5823 @@ -372,6 +375,11 @@ nfs_fhget(struct super_block *sb, struct
5824                          */
5825                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5826                 }
5827 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5828 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5829 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
5830 +                               /* maybe fattr->xid someday */
5831 +
5832                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5833                 nfsi->attrtimeo_timestamp = now;
5834                 nfsi->access_cache = RB_ROOT;
5835 @@ -488,6 +496,8 @@ void nfs_setattr_update_inode(struct ino
5836                         inode->i_uid = attr->ia_uid;
5837                 if ((attr->ia_valid & ATTR_GID) != 0)
5838                         inode->i_gid = attr->ia_gid;
5839 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5840 +                       inode->i_tag = attr->ia_tag;
5841                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5842                 spin_unlock(&inode->i_lock);
5843         }
5844 @@ -923,6 +933,9 @@ static int nfs_check_inode_attributes(st
5845         struct nfs_inode *nfsi = NFS_I(inode);
5846         loff_t cur_size, new_isize;
5847         unsigned long invalid = 0;
5848 +       uid_t uid;
5849 +       gid_t gid;
5850 +       tag_t tag;
5851  
5852  
5853         /* Has the inode gone and changed behind our back? */
5854 @@ -946,13 +959,18 @@ static int nfs_check_inode_attributes(st
5855                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5856         }
5857  
5858 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5859 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5860 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5861 +
5862         /* Have any file permissions changed? */
5863         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5864                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5865 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && inode->i_uid != fattr->uid)
5866 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && uid != fattr->uid)
5867                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5868 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && inode->i_gid != fattr->gid)
5869 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && gid != fattr->gid)
5870                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5871 +               /* maybe check for tag too? */
5872  
5873         /* Has the link count changed? */
5874         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5875 @@ -1187,6 +1205,9 @@ static int nfs_update_inode(struct inode
5876         unsigned long invalid = 0;
5877         unsigned long now = jiffies;
5878         unsigned long save_cache_validity;
5879 +       uid_t uid;
5880 +       gid_t gid;
5881 +       tag_t tag;
5882  
5883         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
5884                         __func__, inode->i_sb->s_id, inode->i_ino,
5885 @@ -1289,6 +1310,9 @@ static int nfs_update_inode(struct inode
5886                                 | NFS_INO_REVAL_PAGECACHE
5887                                 | NFS_INO_REVAL_FORCED);
5888  
5889 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5890 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5891 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5892  
5893         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5894                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5895 @@ -1310,9 +1334,9 @@ static int nfs_update_inode(struct inode
5896                                 | NFS_INO_REVAL_FORCED);
5897  
5898         if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
5899 -               if (inode->i_uid != fattr->uid) {
5900 +               if (uid != fattr->uid) {
5901                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5902 -                       inode->i_uid = fattr->uid;
5903 +                       uid = fattr->uid;
5904                 }
5905         } else if (server->caps & NFS_CAP_OWNER)
5906                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5907 @@ -1321,9 +1345,9 @@ static int nfs_update_inode(struct inode
5908                                 | NFS_INO_REVAL_FORCED);
5909  
5910         if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
5911 -               if (inode->i_gid != fattr->gid) {
5912 +               if (gid != fattr->gid) {
5913                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5914 -                       inode->i_gid = fattr->gid;
5915 +                       gid = fattr->gid;
5916                 }
5917         } else if (server->caps & NFS_CAP_OWNER_GROUP)
5918                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5919 @@ -1331,6 +1355,10 @@ static int nfs_update_inode(struct inode
5920                                 | NFS_INO_INVALID_ACL
5921                                 | NFS_INO_REVAL_FORCED);
5922  
5923 +       inode->i_uid = uid;
5924 +       inode->i_gid = gid;
5925 +       inode->i_tag = tag;
5926 +
5927         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5928                 if (inode->i_nlink != fattr->nlink) {
5929                         invalid |= NFS_INO_INVALID_ATTR;
5930 diff -NurpP --minimal linux-2.6.36/fs/nfs/nfs3xdr.c linux-2.6.36-vs2.3.0.36.36/fs/nfs/nfs3xdr.c
5931 --- linux-2.6.36/fs/nfs/nfs3xdr.c       2010-10-21 13:07:50.000000000 +0200
5932 +++ linux-2.6.36-vs2.3.0.36.36/fs/nfs/nfs3xdr.c 2010-10-21 13:09:36.000000000 +0200
5933 @@ -20,6 +20,7 @@
5934  #include <linux/nfs3.h>
5935  #include <linux/nfs_fs.h>
5936  #include <linux/nfsacl.h>
5937 +#include <linux/vs_tag.h>
5938  #include "internal.h"
5939  
5940  #define NFSDBG_FACILITY                NFSDBG_XDR
5941 @@ -175,7 +176,7 @@ xdr_decode_fattr(__be32 *p, struct nfs_f
5942  }
5943  
5944  static inline __be32 *
5945 -xdr_encode_sattr(__be32 *p, struct iattr *attr)
5946 +xdr_encode_sattr(__be32 *p, struct iattr *attr, int tag)
5947  {
5948         if (attr->ia_valid & ATTR_MODE) {
5949                 *p++ = xdr_one;
5950 @@ -183,15 +184,17 @@ xdr_encode_sattr(__be32 *p, struct iattr
5951         } else {
5952                 *p++ = xdr_zero;
5953         }
5954 -       if (attr->ia_valid & ATTR_UID) {
5955 +       if (attr->ia_valid & ATTR_UID ||
5956 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5957                 *p++ = xdr_one;
5958 -               *p++ = htonl(attr->ia_uid);
5959 +               *p++ = htonl(TAGINO_UID(tag, attr->ia_uid, attr->ia_tag));
5960         } else {
5961                 *p++ = xdr_zero;
5962         }
5963 -       if (attr->ia_valid & ATTR_GID) {
5964 +       if (attr->ia_valid & ATTR_GID ||
5965 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5966                 *p++ = xdr_one;
5967 -               *p++ = htonl(attr->ia_gid);
5968 +               *p++ = htonl(TAGINO_GID(tag, attr->ia_gid, attr->ia_tag));
5969         } else {
5970                 *p++ = xdr_zero;
5971         }
5972 @@ -278,7 +281,8 @@ static int
5973  nfs3_xdr_sattrargs(struct rpc_rqst *req, __be32 *p, struct nfs3_sattrargs *args)
5974  {
5975         p = xdr_encode_fhandle(p, args->fh);
5976 -       p = xdr_encode_sattr(p, args->sattr);
5977 +       p = xdr_encode_sattr(p, args->sattr,
5978 +               req->rq_task->tk_client->cl_tag);
5979         *p++ = htonl(args->guard);
5980         if (args->guard)
5981                 p = xdr_encode_time3(p, &args->guardtime);
5982 @@ -383,7 +387,8 @@ nfs3_xdr_createargs(struct rpc_rqst *req
5983                 *p++ = args->verifier[0];
5984                 *p++ = args->verifier[1];
5985         } else
5986 -               p = xdr_encode_sattr(p, args->sattr);
5987 +               p = xdr_encode_sattr(p, args->sattr,
5988 +                       req->rq_task->tk_client->cl_tag);
5989  
5990         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5991         return 0;
5992 @@ -397,7 +402,8 @@ nfs3_xdr_mkdirargs(struct rpc_rqst *req,
5993  {
5994         p = xdr_encode_fhandle(p, args->fh);
5995         p = xdr_encode_array(p, args->name, args->len);
5996 -       p = xdr_encode_sattr(p, args->sattr);
5997 +       p = xdr_encode_sattr(p, args->sattr,
5998 +               req->rq_task->tk_client->cl_tag);
5999         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
6000         return 0;
6001  }
6002 @@ -410,7 +416,8 @@ nfs3_xdr_symlinkargs(struct rpc_rqst *re
6003  {
6004         p = xdr_encode_fhandle(p, args->fromfh);
6005         p = xdr_encode_array(p, args->fromname, args->fromlen);
6006 -       p = xdr_encode_sattr(p, args->sattr);
6007 +       p = xdr_encode_sattr(p, args->sattr,
6008 +               req->rq_task->tk_client->cl_tag);
6009         *p++ = htonl(args->pathlen);
6010         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
6011  
6012 @@ -428,7 +435,8 @@ nfs3_xdr_mknodargs(struct rpc_rqst *req,
6013         p = xdr_encode_fhandle(p, args->fh);
6014         p = xdr_encode_array(p, args->name, args->len);
6015         *p++ = htonl(args->type);
6016 -       p = xdr_encode_sattr(p, args->sattr);
6017 +       p = xdr_encode_sattr(p, args->sattr,
6018 +               req->rq_task->tk_client->cl_tag);
6019         if (args->type == NF3CHR || args->type == NF3BLK) {
6020                 *p++ = htonl(MAJOR(args->rdev));
6021                 *p++ = htonl(MINOR(args->rdev));
6022 diff -NurpP --minimal linux-2.6.36/fs/nfs/nfsroot.c linux-2.6.36-vs2.3.0.36.36/fs/nfs/nfsroot.c
6023 --- linux-2.6.36/fs/nfs/nfsroot.c       2010-08-02 16:52:50.000000000 +0200
6024 +++ linux-2.6.36-vs2.3.0.36.36/fs/nfs/nfsroot.c 2010-10-21 13:09:36.000000000 +0200
6025 @@ -122,12 +122,12 @@ static int mount_port __initdata = 0;             /
6026  enum {
6027         /* Options that take integer arguments */
6028         Opt_port, Opt_rsize, Opt_wsize, Opt_timeo, Opt_retrans, Opt_acregmin,
6029 -       Opt_acregmax, Opt_acdirmin, Opt_acdirmax,
6030 +       Opt_acregmax, Opt_acdirmin, Opt_acdirmax, Opt_tagid,
6031         /* Options that take no arguments */
6032         Opt_soft, Opt_hard, Opt_intr,
6033         Opt_nointr, Opt_posix, Opt_noposix, Opt_cto, Opt_nocto, Opt_ac, 
6034         Opt_noac, Opt_lock, Opt_nolock, Opt_v2, Opt_v3, Opt_udp, Opt_tcp,
6035 -       Opt_acl, Opt_noacl,
6036 +       Opt_acl, Opt_noacl, Opt_tag, Opt_notag,
6037         /* Error token */
6038         Opt_err
6039  };
6040 @@ -164,6 +164,9 @@ static const match_table_t tokens __init
6041         {Opt_tcp, "tcp"},
6042         {Opt_acl, "acl"},
6043         {Opt_noacl, "noacl"},
6044 +       {Opt_tag, "tag"},
6045 +       {Opt_notag, "notag"},
6046 +       {Opt_tagid, "tagid=%u"},
6047         {Opt_err, NULL}
6048         
6049  };
6050 @@ -275,6 +278,20 @@ static int __init root_nfs_parse(char *n
6051                         case Opt_noacl:
6052                                 nfs_data.flags |= NFS_MOUNT_NOACL;
6053                                 break;
6054 +#ifndef CONFIG_TAGGING_NONE
6055 +                       case Opt_tag:
6056 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
6057 +                               break;
6058 +                       case Opt_notag:
6059 +                               nfs_data.flags &= ~NFS_MOUNT_TAGGED;
6060 +                               break;
6061 +#endif
6062 +#ifdef CONFIG_PROPAGATE
6063 +                       case Opt_tagid:
6064 +                               /* use args[0] */
6065 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
6066 +                               break;
6067 +#endif
6068                         default:
6069                                 printk(KERN_WARNING "Root-NFS: unknown "
6070                                         "option: %s\n", p);
6071 diff -NurpP --minimal linux-2.6.36/fs/nfs/super.c linux-2.6.36-vs2.3.0.36.36/fs/nfs/super.c
6072 --- linux-2.6.36/fs/nfs/super.c 2010-10-21 13:07:50.000000000 +0200
6073 +++ linux-2.6.36-vs2.3.0.36.36/fs/nfs/super.c   2010-10-21 13:09:36.000000000 +0200
6074 @@ -54,6 +54,7 @@
6075  #include <linux/nfs_xdr.h>
6076  #include <linux/magic.h>
6077  #include <linux/parser.h>
6078 +#include <linux/vs_tag.h>
6079  
6080  #include <asm/system.h>
6081  #include <asm/uaccess.h>
6082 @@ -617,6 +618,7 @@ static void nfs_show_mount_options(struc
6083                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
6084                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
6085                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
6086 +               { NFS_MOUNT_TAGGED, ",tag", "" },
6087                 { 0, NULL, NULL }
6088         };
6089         const struct proc_nfs_info *nfs_infop;
6090 diff -NurpP --minimal linux-2.6.36/fs/nfsd/auth.c linux-2.6.36-vs2.3.0.36.36/fs/nfsd/auth.c
6091 --- linux-2.6.36/fs/nfsd/auth.c 2010-02-25 11:52:05.000000000 +0100
6092 +++ linux-2.6.36-vs2.3.0.36.36/fs/nfsd/auth.c   2010-10-21 13:09:36.000000000 +0200
6093 @@ -1,6 +1,7 @@
6094  /* Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> */
6095  
6096  #include <linux/sched.h>
6097 +#include <linux/vs_tag.h>
6098  #include "nfsd.h"
6099  #include "auth.h"
6100  
6101 @@ -36,6 +37,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
6102  
6103         new->fsuid = rqstp->rq_cred.cr_uid;
6104         new->fsgid = rqstp->rq_cred.cr_gid;
6105 +       /* FIXME: this desperately needs a tag :)
6106 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
6107 +                       */
6108  
6109         rqgi = rqstp->rq_cred.cr_group_info;
6110  
6111 diff -NurpP --minimal linux-2.6.36/fs/nfsd/nfs3xdr.c linux-2.6.36-vs2.3.0.36.36/fs/nfsd/nfs3xdr.c
6112 --- linux-2.6.36/fs/nfsd/nfs3xdr.c      2010-02-25 11:52:05.000000000 +0100
6113 +++ linux-2.6.36-vs2.3.0.36.36/fs/nfsd/nfs3xdr.c        2010-10-21 13:09:36.000000000 +0200
6114 @@ -7,6 +7,7 @@
6115   */
6116  
6117  #include <linux/namei.h>
6118 +#include <linux/vs_tag.h>
6119  #include "xdr3.h"
6120  #include "auth.h"
6121  
6122 @@ -95,6 +96,8 @@ static __be32 *
6123  decode_sattr3(__be32 *p, struct iattr *iap)
6124  {
6125         u32     tmp;
6126 +       uid_t   uid = 0;
6127 +       gid_t   gid = 0;
6128  
6129         iap->ia_valid = 0;
6130  
6131 @@ -104,12 +107,15 @@ decode_sattr3(__be32 *p, struct iattr *i
6132         }
6133         if (*p++) {
6134                 iap->ia_valid |= ATTR_UID;
6135 -               iap->ia_uid = ntohl(*p++);
6136 +               uid = ntohl(*p++);
6137         }
6138         if (*p++) {
6139                 iap->ia_valid |= ATTR_GID;
6140 -               iap->ia_gid = ntohl(*p++);
6141 +               gid = ntohl(*p++);
6142         }
6143 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6144 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6145 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6146         if (*p++) {
6147                 u64     newsize;
6148  
6149 @@ -165,8 +171,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
6150         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
6151         *p++ = htonl((u32) stat->mode);
6152         *p++ = htonl((u32) stat->nlink);
6153 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6154 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6155 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6156 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6157 +               stat->uid, stat->tag)));
6158 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6159 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6160 +               stat->gid, stat->tag)));
6161         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
6162                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
6163         } else {
6164 diff -NurpP --minimal linux-2.6.36/fs/nfsd/nfs4xdr.c linux-2.6.36-vs2.3.0.36.36/fs/nfsd/nfs4xdr.c
6165 --- linux-2.6.36/fs/nfsd/nfs4xdr.c      2010-10-21 13:07:50.000000000 +0200
6166 +++ linux-2.6.36-vs2.3.0.36.36/fs/nfsd/nfs4xdr.c        2010-10-21 13:09:36.000000000 +0200
6167 @@ -47,6 +47,7 @@
6168  #include <linux/nfsd_idmap.h>
6169  #include <linux/nfs4_acl.h>
6170  #include <linux/sunrpc/svcauth_gss.h>
6171 +#include <linux/vs_tag.h>
6172  
6173  #include "xdr4.h"
6174  #include "vfs.h"
6175 @@ -2057,14 +2058,18 @@ out_acl:
6176                 WRITE32(stat.nlink);
6177         }
6178         if (bmval1 & FATTR4_WORD1_OWNER) {
6179 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
6180 +               status = nfsd4_encode_user(rqstp,
6181 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
6182 +                       stat.uid, stat.tag), &p, &buflen);
6183                 if (status == nfserr_resource)
6184                         goto out_resource;
6185                 if (status)
6186                         goto out;
6187         }
6188         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
6189 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
6190 +               status = nfsd4_encode_group(rqstp,
6191 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
6192 +                       stat.gid, stat.tag), &p, &buflen);
6193                 if (status == nfserr_resource)
6194                         goto out_resource;
6195                 if (status)
6196 diff -NurpP --minimal linux-2.6.36/fs/nfsd/nfsxdr.c linux-2.6.36-vs2.3.0.36.36/fs/nfsd/nfsxdr.c
6197 --- linux-2.6.36/fs/nfsd/nfsxdr.c       2010-02-25 11:52:05.000000000 +0100
6198 +++ linux-2.6.36-vs2.3.0.36.36/fs/nfsd/nfsxdr.c 2010-10-21 13:09:36.000000000 +0200
6199 @@ -6,6 +6,7 @@
6200  
6201  #include "xdr.h"
6202  #include "auth.h"
6203 +#include <linux/vs_tag.h>
6204  
6205  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6206  
6207 @@ -88,6 +89,8 @@ static __be32 *
6208  decode_sattr(__be32 *p, struct iattr *iap)
6209  {
6210         u32     tmp, tmp1;
6211 +       uid_t   uid = 0;
6212 +       gid_t   gid = 0;
6213  
6214         iap->ia_valid = 0;
6215  
6216 @@ -101,12 +104,15 @@ decode_sattr(__be32 *p, struct iattr *ia
6217         }
6218         if ((tmp = ntohl(*p++)) != (u32)-1) {
6219                 iap->ia_valid |= ATTR_UID;
6220 -               iap->ia_uid = tmp;
6221 +               uid = tmp;
6222         }
6223         if ((tmp = ntohl(*p++)) != (u32)-1) {
6224                 iap->ia_valid |= ATTR_GID;
6225 -               iap->ia_gid = tmp;
6226 +               gid = tmp;
6227         }
6228 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6229 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6230 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6231         if ((tmp = ntohl(*p++)) != (u32)-1) {
6232                 iap->ia_valid |= ATTR_SIZE;
6233                 iap->ia_size = tmp;
6234 @@ -151,8 +157,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
6235         *p++ = htonl(nfs_ftypes[type >> 12]);
6236         *p++ = htonl((u32) stat->mode);
6237         *p++ = htonl((u32) stat->nlink);
6238 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6239 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6240 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6241 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
6242 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6243 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
6244  
6245         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
6246                 *p++ = htonl(NFS_MAXPATHLEN);
6247 diff -NurpP --minimal linux-2.6.36/fs/ocfs2/dlmglue.c linux-2.6.36-vs2.3.0.36.36/fs/ocfs2/dlmglue.c
6248 --- linux-2.6.36/fs/ocfs2/dlmglue.c     2010-10-21 13:07:50.000000000 +0200
6249 +++ linux-2.6.36-vs2.3.0.36.36/fs/ocfs2/dlmglue.c       2010-10-21 13:09:36.000000000 +0200
6250 @@ -2114,6 +2114,7 @@ static void __ocfs2_stuff_meta_lvb(struc
6251         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
6252         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
6253         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
6254 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
6255         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
6256         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
6257         lvb->lvb_iatime_packed  =
6258 @@ -2168,6 +2169,7 @@ static void ocfs2_refresh_inode_from_lvb
6259  
6260         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
6261         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
6262 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
6263         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
6264         inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
6265         ocfs2_unpack_timespec(&inode->i_atime,
6266 diff -NurpP --minimal linux-2.6.36/fs/ocfs2/dlmglue.h linux-2.6.36-vs2.3.0.36.36/fs/ocfs2/dlmglue.h
6267 --- linux-2.6.36/fs/ocfs2/dlmglue.h     2010-10-21 13:07:50.000000000 +0200
6268 +++ linux-2.6.36-vs2.3.0.36.36/fs/ocfs2/dlmglue.h       2010-10-21 13:09:36.000000000 +0200
6269 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
6270         __be16       lvb_inlink;
6271         __be32       lvb_iattr;
6272         __be32       lvb_igeneration;
6273 -       __be32       lvb_reserved2;
6274 +       __be16       lvb_itag;
6275 +       __be16       lvb_reserved2;
6276  };
6277  
6278  #define OCFS2_QINFO_LVB_VERSION 1
6279 diff -NurpP --minimal linux-2.6.36/fs/ocfs2/file.c linux-2.6.36-vs2.3.0.36.36/fs/ocfs2/file.c
6280 --- linux-2.6.36/fs/ocfs2/file.c        2010-10-21 13:07:50.000000000 +0200
6281 +++ linux-2.6.36-vs2.3.0.36.36/fs/ocfs2/file.c  2010-10-21 13:09:36.000000000 +0200
6282 @@ -1138,13 +1138,15 @@ int ocfs2_setattr(struct dentry *dentry,
6283                 mlog(0, "uid change: %d\n", attr->ia_uid);
6284         if (attr->ia_valid & ATTR_GID)
6285                 mlog(0, "gid change: %d\n", attr->ia_gid);
6286 +       if (attr->ia_valid & ATTR_TAG)
6287 +               mlog(0, "tag change: %d\n", attr->ia_tag);
6288         if (attr->ia_valid & ATTR_SIZE)
6289                 mlog(0, "size change...\n");
6290         if (attr->ia_valid & (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME))
6291                 mlog(0, "time change...\n");
6292  
6293  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
6294 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
6295 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
6296         if (!(attr->ia_valid & OCFS2_VALID_ATTRS)) {
6297                 mlog(0, "can't handle attrs: 0x%x\n", attr->ia_valid);
6298                 return 0;
6299 diff -NurpP --minimal linux-2.6.36/fs/ocfs2/inode.c linux-2.6.36-vs2.3.0.36.36/fs/ocfs2/inode.c
6300 --- linux-2.6.36/fs/ocfs2/inode.c       2010-10-21 13:07:50.000000000 +0200
6301 +++ linux-2.6.36-vs2.3.0.36.36/fs/ocfs2/inode.c 2010-10-21 13:09:36.000000000 +0200
6302 @@ -28,6 +28,7 @@
6303  #include <linux/highmem.h>
6304  #include <linux/pagemap.h>
6305  #include <linux/quotaops.h>
6306 +#include <linux/vs_tag.h>
6307  
6308  #include <asm/byteorder.h>
6309  
6310 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode 
6311  {
6312         unsigned int flags = OCFS2_I(inode)->ip_attr;
6313  
6314 -       inode->i_flags &= ~(S_IMMUTABLE |
6315 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
6316                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
6317  
6318         if (flags & OCFS2_IMMUTABLE_FL)
6319                 inode->i_flags |= S_IMMUTABLE;
6320 +       if (flags & OCFS2_IXUNLINK_FL)
6321 +               inode->i_flags |= S_IXUNLINK;
6322  
6323         if (flags & OCFS2_SYNC_FL)
6324                 inode->i_flags |= S_SYNC;
6325 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode 
6326                 inode->i_flags |= S_NOATIME;
6327         if (flags & OCFS2_DIRSYNC_FL)
6328                 inode->i_flags |= S_DIRSYNC;
6329 +
6330 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
6331 +
6332 +       if (flags & OCFS2_BARRIER_FL)
6333 +               inode->i_vflags |= V_BARRIER;
6334 +       if (flags & OCFS2_COW_FL)
6335 +               inode->i_vflags |= V_COW;
6336  }
6337  
6338  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
6339  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
6340  {
6341         unsigned int flags = oi->vfs_inode.i_flags;
6342 +       unsigned int vflags = oi->vfs_inode.i_vflags;
6343 +
6344 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
6345 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
6346 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
6347 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
6348 +
6349 +       if (flags & S_IMMUTABLE)
6350 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6351 +       if (flags & S_IXUNLINK)
6352 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
6353  
6354 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
6355 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
6356         if (flags & S_SYNC)
6357                 oi->ip_attr |= OCFS2_SYNC_FL;
6358         if (flags & S_APPEND)
6359                 oi->ip_attr |= OCFS2_APPEND_FL;
6360 -       if (flags & S_IMMUTABLE)
6361 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6362         if (flags & S_NOATIME)
6363                 oi->ip_attr |= OCFS2_NOATIME_FL;
6364         if (flags & S_DIRSYNC)
6365                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
6366 +
6367 +       if (vflags & V_BARRIER)
6368 +               oi->ip_attr |= OCFS2_BARRIER_FL;
6369 +       if (vflags & V_COW)
6370 +               oi->ip_attr |= OCFS2_COW_FL;
6371  }
6372  
6373  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
6374 @@ -245,6 +267,8 @@ void ocfs2_populate_inode(struct inode *
6375         struct super_block *sb;
6376         struct ocfs2_super *osb;
6377         int use_plocks = 1;
6378 +       uid_t uid;
6379 +       gid_t gid;
6380  
6381         mlog_entry("(0x%p, size:%llu)\n", inode,
6382                    (unsigned long long)le64_to_cpu(fe->i_size));
6383 @@ -276,8 +300,12 @@ void ocfs2_populate_inode(struct inode *
6384         inode->i_generation = le32_to_cpu(fe->i_generation);
6385         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
6386         inode->i_mode = le16_to_cpu(fe->i_mode);
6387 -       inode->i_uid = le32_to_cpu(fe->i_uid);
6388 -       inode->i_gid = le32_to_cpu(fe->i_gid);
6389 +       uid = le32_to_cpu(fe->i_uid);
6390 +       gid = le32_to_cpu(fe->i_gid);
6391 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6392 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6393 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
6394 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
6395  
6396         /* Fast symlinks will have i_size but no allocated clusters. */
6397         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
6398 diff -NurpP --minimal linux-2.6.36/fs/ocfs2/inode.h linux-2.6.36-vs2.3.0.36.36/fs/ocfs2/inode.h
6399 --- linux-2.6.36/fs/ocfs2/inode.h       2010-10-21 13:07:50.000000000 +0200
6400 +++ linux-2.6.36-vs2.3.0.36.36/fs/ocfs2/inode.h 2010-10-21 13:09:36.000000000 +0200
6401 @@ -153,6 +153,7 @@ struct buffer_head *ocfs2_bread(struct i
6402  
6403  void ocfs2_set_inode_flags(struct inode *inode);
6404  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
6405 +int ocfs2_sync_flags(struct inode *inode, int, int);
6406  
6407  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
6408  {
6409 diff -NurpP --minimal linux-2.6.36/fs/ocfs2/ioctl.c linux-2.6.36-vs2.3.0.36.36/fs/ocfs2/ioctl.c
6410 --- linux-2.6.36/fs/ocfs2/ioctl.c       2010-02-25 11:52:06.000000000 +0100
6411 +++ linux-2.6.36-vs2.3.0.36.36/fs/ocfs2/ioctl.c 2010-10-21 13:09:36.000000000 +0200
6412 @@ -43,7 +43,41 @@ static int ocfs2_get_inode_attr(struct i
6413         return status;
6414  }
6415  
6416 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6417 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
6418 +{
6419 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
6420 +       struct buffer_head *bh = NULL;
6421 +       handle_t *handle = NULL;
6422 +       int status;
6423 +
6424 +       status = ocfs2_inode_lock(inode, &bh, 1);
6425 +       if (status < 0) {
6426 +               mlog_errno(status);
6427 +               return status;
6428 +       }
6429 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6430 +       if (IS_ERR(handle)) {
6431 +               status = PTR_ERR(handle);
6432 +               mlog_errno(status);
6433 +               goto bail_unlock;
6434 +       }
6435 +
6436 +       inode->i_flags = flags;
6437 +       inode->i_vflags = vflags;
6438 +       ocfs2_get_inode_flags(OCFS2_I(inode));
6439 +
6440 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
6441 +       if (status < 0)
6442 +               mlog_errno(status);
6443 +
6444 +       ocfs2_commit_trans(osb, handle);
6445 +bail_unlock:
6446 +       ocfs2_inode_unlock(inode, 1);
6447 +       brelse(bh);
6448 +       return status;
6449 +}
6450 +
6451 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6452                                 unsigned mask)
6453  {
6454         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
6455 @@ -68,6 +102,11 @@ static int ocfs2_set_inode_attr(struct i
6456         if (!S_ISDIR(inode->i_mode))
6457                 flags &= ~OCFS2_DIRSYNC_FL;
6458  
6459 +       if (IS_BARRIER(inode)) {
6460 +               vxwprintk_task(1, "messing with the barrier.");
6461 +               goto bail_unlock;
6462 +       }
6463 +
6464         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6465         if (IS_ERR(handle)) {
6466                 status = PTR_ERR(handle);
6467 @@ -109,6 +148,7 @@ bail:
6468         return status;
6469  }
6470  
6471 +
6472  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
6473  {
6474         struct inode *inode = filp->f_path.dentry->d_inode;
6475 diff -NurpP --minimal linux-2.6.36/fs/ocfs2/namei.c linux-2.6.36-vs2.3.0.36.36/fs/ocfs2/namei.c
6476 --- linux-2.6.36/fs/ocfs2/namei.c       2010-10-21 13:07:50.000000000 +0200
6477 +++ linux-2.6.36-vs2.3.0.36.36/fs/ocfs2/namei.c 2010-10-21 13:09:36.000000000 +0200
6478 @@ -41,6 +41,7 @@
6479  #include <linux/slab.h>
6480  #include <linux/highmem.h>
6481  #include <linux/quotaops.h>
6482 +#include <linux/vs_tag.h>
6483  
6484  #define MLOG_MASK_PREFIX ML_NAMEI
6485  #include <cluster/masklog.h>
6486 @@ -486,6 +487,7 @@ static int __ocfs2_mknod_locked(struct i
6487         struct ocfs2_dinode *fe = NULL;
6488         struct ocfs2_extent_list *fel;
6489         u16 feat;
6490 +       tag_t tag;
6491  
6492         *new_fe_bh = NULL;
6493  
6494 @@ -523,8 +525,11 @@ static int __ocfs2_mknod_locked(struct i
6495         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
6496         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
6497         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
6498 -       fe->i_uid = cpu_to_le32(inode->i_uid);
6499 -       fe->i_gid = cpu_to_le32(inode->i_gid);
6500 +
6501 +       tag = dx_current_fstag(osb->sb);
6502 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
6503 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
6504 +       inode->i_tag = tag;
6505         fe->i_mode = cpu_to_le16(inode->i_mode);
6506         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
6507                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
6508 diff -NurpP --minimal linux-2.6.36/fs/ocfs2/ocfs2_fs.h linux-2.6.36-vs2.3.0.36.36/fs/ocfs2/ocfs2_fs.h
6509 --- linux-2.6.36/fs/ocfs2/ocfs2_fs.h    2010-10-21 13:07:51.000000000 +0200
6510 +++ linux-2.6.36-vs2.3.0.36.36/fs/ocfs2/ocfs2_fs.h      2010-10-21 14:00:41.000000000 +0200
6511 @@ -258,6 +258,11 @@
6512  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
6513  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
6514  
6515 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
6516 +
6517 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
6518 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
6519 +
6520  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
6521  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
6522  
6523 diff -NurpP --minimal linux-2.6.36/fs/ocfs2/ocfs2.h linux-2.6.36-vs2.3.0.36.36/fs/ocfs2/ocfs2.h
6524 --- linux-2.6.36/fs/ocfs2/ocfs2.h       2010-08-02 16:52:51.000000000 +0200
6525 +++ linux-2.6.36-vs2.3.0.36.36/fs/ocfs2/ocfs2.h 2010-10-21 13:09:36.000000000 +0200
6526 @@ -256,6 +256,7 @@ enum ocfs2_mount_options
6527                                                    control lists */
6528         OCFS2_MOUNT_USRQUOTA = 1 << 10, /* We support user quotas */
6529         OCFS2_MOUNT_GRPQUOTA = 1 << 11, /* We support group quotas */
6530 +       OCFS2_MOUNT_TAGGED = 1 << 12, /* use tagging */
6531  };
6532  
6533  #define OCFS2_OSB_SOFT_RO                      0x0001
6534 diff -NurpP --minimal linux-2.6.36/fs/ocfs2/super.c linux-2.6.36-vs2.3.0.36.36/fs/ocfs2/super.c
6535 --- linux-2.6.36/fs/ocfs2/super.c       2010-10-21 13:07:51.000000000 +0200
6536 +++ linux-2.6.36-vs2.3.0.36.36/fs/ocfs2/super.c 2010-10-21 13:09:36.000000000 +0200
6537 @@ -179,6 +179,7 @@ enum {
6538         Opt_grpquota,
6539         Opt_resv_level,
6540         Opt_dir_resv_level,
6541 +       Opt_tag, Opt_notag, Opt_tagid,
6542         Opt_err,
6543  };
6544  
6545 @@ -207,6 +208,9 @@ static const match_table_t tokens = {
6546         {Opt_grpquota, "grpquota"},
6547         {Opt_resv_level, "resv_level=%u"},
6548         {Opt_dir_resv_level, "dir_resv_level=%u"},
6549 +       {Opt_tag, "tag"},
6550 +       {Opt_notag, "notag"},
6551 +       {Opt_tagid, "tagid=%u"},
6552         {Opt_err, NULL}
6553  };
6554  
6555 @@ -617,6 +621,13 @@ static int ocfs2_remount(struct super_bl
6556                 goto out;
6557         }
6558  
6559 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
6560 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
6561 +               ret = -EINVAL;
6562 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
6563 +               goto out;
6564 +       }
6565 +
6566         if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
6567             (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
6568                 ret = -EINVAL;
6569 @@ -1153,6 +1164,9 @@ static int ocfs2_fill_super(struct super
6570  
6571         ocfs2_complete_mount_recovery(osb);
6572  
6573 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
6574 +               sb->s_flags |= MS_TAGGED;
6575 +
6576         if (ocfs2_mount_local(osb))
6577                 snprintf(nodestr, sizeof(nodestr), "local");
6578         else
6579 @@ -1468,6 +1482,20 @@ static int ocfs2_parse_options(struct su
6580                             option < OCFS2_MAX_RESV_LEVEL)
6581                                 mopt->dir_resv_level = option;
6582                         break;
6583 +#ifndef CONFIG_TAGGING_NONE
6584 +               case Opt_tag:
6585 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6586 +                       break;
6587 +               case Opt_notag:
6588 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
6589 +                       break;
6590 +#endif
6591 +#ifdef CONFIG_PROPAGATE
6592 +               case Opt_tagid:
6593 +                       /* use args[0] */
6594 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6595 +                       break;
6596 +#endif
6597                 default:
6598                         mlog(ML_ERROR,
6599                              "Unrecognized mount option \"%s\" "
6600 diff -NurpP --minimal linux-2.6.36/fs/open.c linux-2.6.36-vs2.3.0.36.36/fs/open.c
6601 --- linux-2.6.36/fs/open.c      2010-10-21 13:07:51.000000000 +0200
6602 +++ linux-2.6.36-vs2.3.0.36.36/fs/open.c        2010-10-21 13:55:41.000000000 +0200
6603 @@ -30,6 +30,11 @@
6604  #include <linux/fs_struct.h>
6605  #include <linux/ima.h>
6606  #include <linux/dnotify.h>
6607 +#include <linux/vs_base.h>
6608 +#include <linux/vs_limit.h>
6609 +#include <linux/vs_tag.h>
6610 +#include <linux/vs_cowbl.h>
6611 +#include <linux/vserver/dlimit.h>
6612  
6613  #include "internal.h"
6614  
6615 @@ -481,6 +486,12 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6616         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
6617         if (error)
6618                 goto out;
6619 +
6620 +#ifdef CONFIG_VSERVER_COWBL
6621 +       error = cow_check_and_break(&path);
6622 +       if (error)
6623 +               goto dput_and_out;
6624 +#endif
6625         inode = path.dentry->d_inode;
6626  
6627         error = mnt_want_write(path.mnt);
6628 @@ -518,11 +529,11 @@ static int chown_common(struct path *pat
6629         newattrs.ia_valid =  ATTR_CTIME;
6630         if (user != (uid_t) -1) {
6631                 newattrs.ia_valid |= ATTR_UID;
6632 -               newattrs.ia_uid = user;
6633 +               newattrs.ia_uid = dx_map_uid(user);
6634         }
6635         if (group != (gid_t) -1) {
6636                 newattrs.ia_valid |= ATTR_GID;
6637 -               newattrs.ia_gid = group;
6638 +               newattrs.ia_gid = dx_map_gid(group);
6639         }
6640         if (!S_ISDIR(inode->i_mode))
6641                 newattrs.ia_valid |=
6642 @@ -547,6 +558,10 @@ SYSCALL_DEFINE3(chown, const char __user
6643         error = mnt_want_write(path.mnt);
6644         if (error)
6645                 goto out_release;
6646 +#ifdef CONFIG_VSERVER_COWBL
6647 +       error = cow_check_and_break(&path);
6648 +       if (!error)
6649 +#endif
6650         error = chown_common(&path, user, group);
6651         mnt_drop_write(path.mnt);
6652  out_release:
6653 @@ -572,6 +587,10 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
6654         error = mnt_want_write(path.mnt);
6655         if (error)
6656                 goto out_release;
6657 +#ifdef CONFIG_VSERVER_COWBL
6658 +       error = cow_check_and_break(&path);
6659 +       if (!error)
6660 +#endif
6661         error = chown_common(&path, user, group);
6662         mnt_drop_write(path.mnt);
6663  out_release:
6664 @@ -591,6 +610,10 @@ SYSCALL_DEFINE3(lchown, const char __use
6665         error = mnt_want_write(path.mnt);
6666         if (error)
6667                 goto out_release;
6668 +#ifdef CONFIG_VSERVER_COWBL
6669 +       error = cow_check_and_break(&path);
6670 +       if (!error)
6671 +#endif
6672         error = chown_common(&path, user, group);
6673         mnt_drop_write(path.mnt);
6674  out_release:
6675 @@ -837,6 +860,7 @@ static void __put_unused_fd(struct files
6676         __FD_CLR(fd, fdt->open_fds);
6677         if (fd < files->next_fd)
6678                 files->next_fd = fd;
6679 +       vx_openfd_dec(fd);
6680  }
6681  
6682  void put_unused_fd(unsigned int fd)
6683 diff -NurpP --minimal linux-2.6.36/fs/proc/array.c linux-2.6.36-vs2.3.0.36.36/fs/proc/array.c
6684 --- linux-2.6.36/fs/proc/array.c        2010-08-02 16:52:51.000000000 +0200
6685 +++ linux-2.6.36-vs2.3.0.36.36/fs/proc/array.c  2010-10-21 13:09:36.000000000 +0200
6686 @@ -81,6 +81,8 @@
6687  #include <linux/pid_namespace.h>
6688  #include <linux/ptrace.h>
6689  #include <linux/tracehook.h>
6690 +#include <linux/vs_context.h>
6691 +#include <linux/vs_network.h>
6692  
6693  #include <asm/pgtable.h>
6694  #include <asm/processor.h>
6695 @@ -170,6 +172,9 @@ static inline void task_state(struct seq
6696         rcu_read_lock();
6697         ppid = pid_alive(p) ?
6698                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6699 +       if (unlikely(vx_current_initpid(p->pid)))
6700 +               ppid = 0;
6701 +
6702         tpid = 0;
6703         if (pid_alive(p)) {
6704                 struct task_struct *tracer = tracehook_tracer_task(p);
6705 @@ -287,7 +292,7 @@ static inline void task_sig(struct seq_f
6706  }
6707  
6708  static void render_cap_t(struct seq_file *m, const char *header,
6709 -                       kernel_cap_t *a)
6710 +                       struct vx_info *vxi, kernel_cap_t *a)
6711  {
6712         unsigned __capi;
6713  
6714 @@ -312,10 +317,11 @@ static inline void task_cap(struct seq_f
6715         cap_bset        = cred->cap_bset;
6716         rcu_read_unlock();
6717  
6718 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6719 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6720 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6721 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6722 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6723 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6724 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6725 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6726 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6727  }
6728  
6729  static inline void task_context_switch_counts(struct seq_file *m,
6730 @@ -337,6 +343,42 @@ static void task_cpus_allowed(struct seq
6731         seq_printf(m, "\n");
6732  }
6733  
6734 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6735 +                       struct pid *pid, struct task_struct *task)
6736 +{
6737 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6738 +                       "Count:\t%u\n"
6739 +                       "uts:\t%p(%c)\n"
6740 +                       "ipc:\t%p(%c)\n"
6741 +                       "mnt:\t%p(%c)\n"
6742 +                       "pid:\t%p(%c)\n"
6743 +                       "net:\t%p(%c)\n",
6744 +                       task->nsproxy,
6745 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6746 +                       atomic_read(&task->nsproxy->count),
6747 +                       task->nsproxy->uts_ns,
6748 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6749 +                       task->nsproxy->ipc_ns,
6750 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6751 +                       task->nsproxy->mnt_ns,
6752 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6753 +                       task->nsproxy->pid_ns,
6754 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6755 +                       task->nsproxy->net_ns,
6756 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6757 +       return 0;
6758 +}
6759 +
6760 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6761 +{
6762 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6763 +               return;
6764 +
6765 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6766 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6767 +}
6768 +
6769 +
6770  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6771                         struct pid *pid, struct task_struct *task)
6772  {
6773 @@ -353,6 +395,7 @@ int proc_pid_status(struct seq_file *m, 
6774         task_cap(m, task);
6775         task_cpus_allowed(m, task);
6776         cpuset_task_status_allowed(m, task);
6777 +       task_vs_id(m, task);
6778  #if defined(CONFIG_S390)
6779         task_show_regs(m, task);
6780  #endif
6781 @@ -465,6 +508,17 @@ static int do_task_stat(struct seq_file 
6782         /* convert nsec -> ticks */
6783         start_time = nsec_to_clock_t(start_time);
6784  
6785 +       /* fixup start time for virt uptime */
6786 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6787 +               unsigned long long bias =
6788 +                       current->vx_info->cvirt.bias_clock;
6789 +
6790 +               if (start_time > bias)
6791 +                       start_time -= bias;
6792 +               else
6793 +                       start_time = 0;
6794 +       }
6795 +
6796         seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \
6797  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
6798  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
6799 diff -NurpP --minimal linux-2.6.36/fs/proc/base.c linux-2.6.36-vs2.3.0.36.36/fs/proc/base.c
6800 --- linux-2.6.36/fs/proc/base.c 2010-10-21 13:07:51.000000000 +0200
6801 +++ linux-2.6.36-vs2.3.0.36.36/fs/proc/base.c   2010-10-21 13:58:32.000000000 +0200
6802 @@ -83,6 +83,8 @@
6803  #include <linux/pid_namespace.h>
6804  #include <linux/fs_struct.h>
6805  #include <linux/slab.h>
6806 +#include <linux/vs_context.h>
6807 +#include <linux/vs_network.h>
6808  #include "internal.h"
6809  
6810  /* NOTE:
6811 @@ -1041,12 +1043,17 @@ static ssize_t oom_adjust_write(struct f
6812                 return -ESRCH;
6813         }
6814  
6815 -       if (oom_adjust < task->signal->oom_adj && !capable(CAP_SYS_RESOURCE)) {
6816 +       if (oom_adjust < task->signal->oom_adj &&
6817 +               !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6818                 unlock_task_sighand(task, &flags);
6819                 put_task_struct(task);
6820                 return -EACCES;
6821         }
6822  
6823 +       /* prevent guest processes from circumventing the oom killer */
6824 +       if (vx_current_xid() && (oom_adjust == OOM_DISABLE))
6825 +               oom_adjust = OOM_ADJUST_MIN;
6826 +
6827         /*
6828          * Warn that /proc/pid/oom_adj is deprecated, see
6829          * Documentation/feature-removal-schedule.txt.
6830 @@ -1179,7 +1186,7 @@ static ssize_t proc_loginuid_write(struc
6831         ssize_t length;
6832         uid_t loginuid;
6833  
6834 -       if (!capable(CAP_AUDIT_CONTROL))
6835 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
6836                 return -EPERM;
6837  
6838         rcu_read_lock();
6839 @@ -1617,6 +1624,8 @@ static struct inode *proc_pid_make_inode
6840                 inode->i_gid = cred->egid;
6841                 rcu_read_unlock();
6842         }
6843 +       /* procfs is xid tagged */
6844 +       inode->i_tag = (tag_t)vx_task_xid(task);
6845         security_task_to_inode(task, inode);
6846  
6847  out:
6848 @@ -2167,6 +2176,13 @@ static struct dentry *proc_pident_lookup
6849         if (!task)
6850                 goto out_no_task;
6851  
6852 +       /* TODO: maybe we can come up with a generic approach? */
6853 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6854 +               (dentry->d_name.len == 5) &&
6855 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6856 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6857 +               goto out;
6858 +
6859         /*
6860          * Yes, it does not scale. And it should not. Don't add
6861          * new entries into /proc/<tgid>/ without very good reasons.
6862 @@ -2574,7 +2590,7 @@ out_iput:
6863  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
6864  {
6865         struct dentry *error;
6866 -       struct task_struct *task = get_proc_task(dir);
6867 +       struct task_struct *task = get_proc_task_real(dir);
6868         const struct pid_entry *p, *last;
6869  
6870         error = ERR_PTR(-ENOENT);
6871 @@ -2664,6 +2680,9 @@ static int proc_pid_personality(struct s
6872  static const struct file_operations proc_task_operations;
6873  static const struct inode_operations proc_task_inode_operations;
6874  
6875 +extern int proc_pid_vx_info(struct task_struct *, char *);
6876 +extern int proc_pid_nx_info(struct task_struct *, char *);
6877 +
6878  static const struct pid_entry tgid_base_stuff[] = {
6879         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6880         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6881 @@ -2723,6 +2742,8 @@ static const struct pid_entry tgid_base_
6882  #ifdef CONFIG_CGROUPS
6883         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6884  #endif
6885 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6886 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6887         INF("oom_score",  S_IRUGO, proc_oom_score),
6888         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
6889         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6890 @@ -2739,6 +2760,7 @@ static const struct pid_entry tgid_base_
6891  #ifdef CONFIG_TASK_IO_ACCOUNTING
6892         INF("io",       S_IRUGO, proc_tgid_io_accounting),
6893  #endif
6894 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6895  };
6896  
6897  static int proc_tgid_base_readdir(struct file * filp,
6898 @@ -2930,7 +2952,7 @@ retry:
6899         iter.task = NULL;
6900         pid = find_ge_pid(iter.tgid, ns);
6901         if (pid) {
6902 -               iter.tgid = pid_nr_ns(pid, ns);
6903 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6904                 iter.task = pid_task(pid, PIDTYPE_PID);
6905                 /* What we to know is if the pid we have find is the
6906                  * pid of a thread_group_leader.  Testing for task
6907 @@ -2960,7 +2982,7 @@ static int proc_pid_fill_cache(struct fi
6908         struct tgid_iter iter)
6909  {
6910         char name[PROC_NUMBUF];
6911 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6912 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6913         return proc_fill_cache(filp, dirent, filldir, name, len,
6914                                 proc_pid_instantiate, iter.task, NULL);
6915  }
6916 @@ -2969,7 +2991,7 @@ static int proc_pid_fill_cache(struct fi
6917  int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
6918  {
6919         unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
6920 -       struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode);
6921 +       struct task_struct *reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
6922         struct tgid_iter iter;
6923         struct pid_namespace *ns;
6924  
6925 @@ -2989,6 +3011,8 @@ int proc_pid_readdir(struct file * filp,
6926              iter.task;
6927              iter.tgid += 1, iter = next_tgid(ns, iter)) {
6928                 filp->f_pos = iter.tgid + TGID_OFFSET;
6929 +               if (!vx_proc_task_visible(iter.task))
6930 +                       continue;
6931                 if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
6932                         put_task_struct(iter.task);
6933                         goto out;
6934 @@ -3137,6 +3161,8 @@ static struct dentry *proc_task_lookup(s
6935         tid = name_to_int(dentry);
6936         if (tid == ~0U)
6937                 goto out;
6938 +       if (vx_current_initpid(tid))
6939 +               goto out;
6940  
6941         ns = dentry->d_sb->s_fs_info;
6942         rcu_read_lock();
6943 diff -NurpP --minimal linux-2.6.36/fs/proc/generic.c linux-2.6.36-vs2.3.0.36.36/fs/proc/generic.c
6944 --- linux-2.6.36/fs/proc/generic.c      2010-10-21 13:07:51.000000000 +0200
6945 +++ linux-2.6.36-vs2.3.0.36.36/fs/proc/generic.c        2010-10-21 21:43:28.000000000 +0200
6946 @@ -22,6 +22,7 @@
6947  #include <linux/bitops.h>
6948  #include <linux/spinlock.h>
6949  #include <linux/completion.h>
6950 +#include <linux/vserver/inode.h>
6951  #include <asm/uaccess.h>
6952  
6953  #include "internal.h"
6954 @@ -424,6 +425,8 @@ struct dentry *proc_lookup_de(struct pro
6955         for (de = de->subdir; de ; de = de->next) {
6956                 if (de->namelen != dentry->d_name.len)
6957                         continue;
6958 +               if (!vx_hide_check(0, de->vx_flags))
6959 +                       continue;
6960                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6961                         unsigned int ino;
6962  
6963 @@ -432,6 +435,8 @@ struct dentry *proc_lookup_de(struct pro
6964                         spin_unlock(&proc_subdir_lock);
6965                         error = -EINVAL;
6966                         inode = proc_get_inode(dir->i_sb, ino, de);
6967 +                       /* generic proc entries belong to the host */
6968 +                       inode->i_tag = 0;
6969                         goto out_unlock;
6970                 }
6971         }
6972 @@ -509,6 +514,8 @@ int proc_readdir_de(struct proc_dir_entr
6973  
6974                                 /* filldir passes info to user space */
6975                                 pde_get(de);
6976 +                               if (!vx_hide_check(0, de->vx_flags))
6977 +                                       goto skip;
6978                                 spin_unlock(&proc_subdir_lock);
6979                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6980                                             de->low_ino, de->mode >> 12) < 0) {
6981 @@ -516,6 +523,7 @@ int proc_readdir_de(struct proc_dir_entr
6982                                         goto out;
6983                                 }
6984                                 spin_lock(&proc_subdir_lock);
6985 +                       skip:
6986                                 filp->f_pos++;
6987                                 next = de->next;
6988                                 pde_put(de);
6989 @@ -630,6 +638,7 @@ static struct proc_dir_entry *__proc_cre
6990         ent->nlink = nlink;
6991         atomic_set(&ent->count, 1);
6992         ent->pde_users = 0;
6993 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6994         spin_lock_init(&ent->pde_unload_lock);
6995         ent->pde_unload_completion = NULL;
6996         INIT_LIST_HEAD(&ent->pde_openers);
6997 @@ -653,7 +662,8 @@ struct proc_dir_entry *proc_symlink(cons
6998                                 kfree(ent->data);
6999                                 kfree(ent);
7000                                 ent = NULL;
7001 -                       }
7002 +                       } else
7003 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
7004                 } else {
7005                         kfree(ent);
7006                         ent = NULL;
7007 diff -NurpP --minimal linux-2.6.36/fs/proc/inode.c linux-2.6.36-vs2.3.0.36.36/fs/proc/inode.c
7008 --- linux-2.6.36/fs/proc/inode.c        2010-10-21 13:07:51.000000000 +0200
7009 +++ linux-2.6.36-vs2.3.0.36.36/fs/proc/inode.c  2010-10-21 13:09:36.000000000 +0200
7010 @@ -428,6 +428,8 @@ struct inode *proc_get_inode(struct supe
7011                         inode->i_uid = de->uid;
7012                         inode->i_gid = de->gid;
7013                 }
7014 +               if (de->vx_flags)
7015 +                       PROC_I(inode)->vx_flags = de->vx_flags;
7016                 if (de->size)
7017                         inode->i_size = de->size;
7018                 if (de->nlink)
7019 diff -NurpP --minimal linux-2.6.36/fs/proc/internal.h linux-2.6.36-vs2.3.0.36.36/fs/proc/internal.h
7020 --- linux-2.6.36/fs/proc/internal.h     2010-02-25 11:52:06.000000000 +0100
7021 +++ linux-2.6.36-vs2.3.0.36.36/fs/proc/internal.h       2010-10-21 13:09:36.000000000 +0200
7022 @@ -10,6 +10,7 @@
7023   */
7024  
7025  #include <linux/proc_fs.h>
7026 +#include <linux/vs_pid.h>
7027  
7028  extern struct proc_dir_entry proc_root;
7029  #ifdef CONFIG_PROC_SYSCTL
7030 @@ -51,6 +52,9 @@ extern int proc_pid_status(struct seq_fi
7031                                 struct pid *pid, struct task_struct *task);
7032  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
7033                                 struct pid *pid, struct task_struct *task);
7034 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
7035 +                               struct pid *pid, struct task_struct *task);
7036 +
7037  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
7038  
7039  extern const struct file_operations proc_maps_operations;
7040 @@ -68,11 +72,16 @@ static inline struct pid *proc_pid(struc
7041         return PROC_I(inode)->pid;
7042  }
7043  
7044 -static inline struct task_struct *get_proc_task(struct inode *inode)
7045 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
7046  {
7047         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
7048  }
7049  
7050 +static inline struct task_struct *get_proc_task(struct inode *inode)
7051 +{
7052 +       return vx_get_proc_task(inode, proc_pid(inode));
7053 +}
7054 +
7055  static inline int proc_fd(struct inode *inode)
7056  {
7057         return PROC_I(inode)->fd;
7058 diff -NurpP --minimal linux-2.6.36/fs/proc/loadavg.c linux-2.6.36-vs2.3.0.36.36/fs/proc/loadavg.c
7059 --- linux-2.6.36/fs/proc/loadavg.c      2009-09-10 15:26:23.000000000 +0200
7060 +++ linux-2.6.36-vs2.3.0.36.36/fs/proc/loadavg.c        2010-10-21 13:09:36.000000000 +0200
7061 @@ -12,15 +12,27 @@
7062  
7063  static int loadavg_proc_show(struct seq_file *m, void *v)
7064  {
7065 +       unsigned long running;
7066 +       unsigned int threads;
7067         unsigned long avnrun[3];
7068  
7069         get_avenrun(avnrun, FIXED_1/200, 0);
7070  
7071 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
7072 +               struct vx_info *vxi = current_vx_info();
7073 +
7074 +               running = atomic_read(&vxi->cvirt.nr_running);
7075 +               threads = atomic_read(&vxi->cvirt.nr_threads);
7076 +       } else {
7077 +               running = nr_running();
7078 +               threads = nr_threads;
7079 +       }
7080 +
7081         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
7082                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
7083                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
7084                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
7085 -               nr_running(), nr_threads,
7086 +               running, threads,
7087                 task_active_pid_ns(current)->last_pid);
7088         return 0;
7089  }
7090 diff -NurpP --minimal linux-2.6.36/fs/proc/meminfo.c linux-2.6.36-vs2.3.0.36.36/fs/proc/meminfo.c
7091 --- linux-2.6.36/fs/proc/meminfo.c      2009-12-03 20:02:53.000000000 +0100
7092 +++ linux-2.6.36-vs2.3.0.36.36/fs/proc/meminfo.c        2010-10-21 13:09:36.000000000 +0200
7093 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
7094         allowed = ((totalram_pages - hugetlb_total_pages())
7095                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
7096  
7097 -       cached = global_page_state(NR_FILE_PAGES) -
7098 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
7099 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
7100                         total_swapcache_pages - i.bufferram;
7101         if (cached < 0)
7102                 cached = 0;
7103 diff -NurpP --minimal linux-2.6.36/fs/proc/root.c linux-2.6.36-vs2.3.0.36.36/fs/proc/root.c
7104 --- linux-2.6.36/fs/proc/root.c 2010-08-02 16:52:51.000000000 +0200
7105 +++ linux-2.6.36-vs2.3.0.36.36/fs/proc/root.c   2010-10-21 13:09:36.000000000 +0200
7106 @@ -18,9 +18,14 @@
7107  #include <linux/bitops.h>
7108  #include <linux/mount.h>
7109  #include <linux/pid_namespace.h>
7110 +#include <linux/vserver/inode.h>
7111  
7112  #include "internal.h"
7113  
7114 +struct proc_dir_entry *proc_virtual;
7115 +
7116 +extern void proc_vx_init(void);
7117 +
7118  static int proc_test_super(struct super_block *sb, void *data)
7119  {
7120         return sb->s_fs_info == data;
7121 @@ -135,6 +140,7 @@ void __init proc_root_init(void)
7122  #endif
7123         proc_mkdir("bus", NULL);
7124         proc_sys_init();
7125 +       proc_vx_init();
7126  }
7127  
7128  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
7129 @@ -202,6 +208,7 @@ struct proc_dir_entry proc_root = {
7130         .proc_iops      = &proc_root_inode_operations, 
7131         .proc_fops      = &proc_root_operations,
7132         .parent         = &proc_root,
7133 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
7134  };
7135  
7136  int pid_ns_prepare_proc(struct pid_namespace *ns)
7137 diff -NurpP --minimal linux-2.6.36/fs/proc/uptime.c linux-2.6.36-vs2.3.0.36.36/fs/proc/uptime.c
7138 --- linux-2.6.36/fs/proc/uptime.c       2009-12-03 20:02:53.000000000 +0100
7139 +++ linux-2.6.36-vs2.3.0.36.36/fs/proc/uptime.c 2010-10-21 13:09:36.000000000 +0200
7140 @@ -4,22 +4,22 @@
7141  #include <linux/sched.h>
7142  #include <linux/seq_file.h>
7143  #include <linux/time.h>
7144 -#include <linux/kernel_stat.h>
7145 +#include <linux/vserver/cvirt.h>
7146  #include <asm/cputime.h>
7147  
7148  static int uptime_proc_show(struct seq_file *m, void *v)
7149  {
7150         struct timespec uptime;
7151         struct timespec idle;
7152 -       int i;
7153 -       cputime_t idletime = cputime_zero;
7154 -
7155 -       for_each_possible_cpu(i)
7156 -               idletime = cputime64_add(idletime, kstat_cpu(i).cpustat.idle);
7157 +       cputime_t idletime = cputime_add(init_task.utime, init_task.stime);
7158  
7159         do_posix_clock_monotonic_gettime(&uptime);
7160         monotonic_to_bootbased(&uptime);
7161         cputime_to_timespec(idletime, &idle);
7162 +
7163 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
7164 +               vx_vsi_uptime(&uptime, &idle);
7165 +
7166         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
7167                         (unsigned long) uptime.tv_sec,
7168                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
7169 diff -NurpP --minimal linux-2.6.36/fs/quota/dquot.c linux-2.6.36-vs2.3.0.36.36/fs/quota/dquot.c
7170 --- linux-2.6.36/fs/quota/dquot.c       2010-10-21 13:07:51.000000000 +0200
7171 +++ linux-2.6.36-vs2.3.0.36.36/fs/quota/dquot.c 2010-10-21 13:09:36.000000000 +0200
7172 @@ -1538,6 +1538,9 @@ int __dquot_alloc_space(struct inode *in
7173         int reserve = flags & DQUOT_SPACE_RESERVE;
7174         int nofail = flags & DQUOT_SPACE_NOFAIL;
7175  
7176 +       if ((ret = dl_alloc_space(inode, number)))
7177 +               return ret;
7178 +
7179         /*
7180          * First test before acquiring mutex - solves deadlocks when we
7181          * re-enter the quota code and are already holding the mutex
7182 @@ -1592,6 +1595,9 @@ int dquot_alloc_inode(const struct inode
7183         int cnt, ret = 0;
7184         char warntype[MAXQUOTAS];
7185  
7186 +       if ((ret = dl_alloc_inode(inode)))
7187 +               return ret;
7188 +
7189         /* First test before acquiring mutex - solves deadlocks when we
7190           * re-enter the quota code and are already holding the mutex */
7191         if (!dquot_active(inode))
7192 @@ -1662,6 +1668,8 @@ void __dquot_free_space(struct inode *in
7193         char warntype[MAXQUOTAS];
7194         int reserve = flags & DQUOT_SPACE_RESERVE;
7195  
7196 +       dl_free_space(inode, number);
7197 +
7198         /* First test before acquiring mutex - solves deadlocks when we
7199           * re-enter the quota code and are already holding the mutex */
7200         if (!dquot_active(inode)) {
7201 @@ -1700,6 +1708,8 @@ void dquot_free_inode(const struct inode
7202         unsigned int cnt;
7203         char warntype[MAXQUOTAS];
7204  
7205 +       dl_free_inode(inode);
7206 +
7207         /* First test before acquiring mutex - solves deadlocks when we
7208           * re-enter the quota code and are already holding the mutex */
7209         if (!dquot_active(inode))
7210 diff -NurpP --minimal linux-2.6.36/fs/quota/quota.c linux-2.6.36-vs2.3.0.36.36/fs/quota/quota.c
7211 --- linux-2.6.36/fs/quota/quota.c       2010-08-02 16:52:51.000000000 +0200
7212 +++ linux-2.6.36-vs2.3.0.36.36/fs/quota/quota.c 2010-10-21 13:09:36.000000000 +0200
7213 @@ -8,6 +8,7 @@
7214  #include <linux/fs.h>
7215  #include <linux/namei.h>
7216  #include <linux/slab.h>
7217 +#include <linux/vs_context.h>
7218  #include <asm/current.h>
7219  #include <asm/uaccess.h>
7220  #include <linux/kernel.h>
7221 @@ -38,7 +39,7 @@ static int check_quotactl_permission(str
7222                         break;
7223                 /*FALLTHROUGH*/
7224         default:
7225 -               if (!capable(CAP_SYS_ADMIN))
7226 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7227                         return -EPERM;
7228         }
7229  
7230 @@ -296,6 +297,46 @@ static int do_quotactl(struct super_bloc
7231         }
7232  }
7233  
7234 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7235 +
7236 +#include <linux/vroot.h>
7237 +#include <linux/major.h>
7238 +#include <linux/module.h>
7239 +#include <linux/kallsyms.h>
7240 +#include <linux/vserver/debug.h>
7241 +
7242 +static vroot_grb_func *vroot_get_real_bdev = NULL;
7243 +
7244 +static spinlock_t vroot_grb_lock = SPIN_LOCK_UNLOCKED;
7245 +
7246 +int register_vroot_grb(vroot_grb_func *func) {
7247 +       int ret = -EBUSY;
7248 +
7249 +       spin_lock(&vroot_grb_lock);
7250 +       if (!vroot_get_real_bdev) {
7251 +               vroot_get_real_bdev = func;
7252 +               ret = 0;
7253 +       }
7254 +       spin_unlock(&vroot_grb_lock);
7255 +       return ret;
7256 +}
7257 +EXPORT_SYMBOL(register_vroot_grb);
7258 +
7259 +int unregister_vroot_grb(vroot_grb_func *func) {
7260 +       int ret = -EINVAL;
7261 +
7262 +       spin_lock(&vroot_grb_lock);
7263 +       if (vroot_get_real_bdev) {
7264 +               vroot_get_real_bdev = NULL;
7265 +               ret = 0;
7266 +       }
7267 +       spin_unlock(&vroot_grb_lock);
7268 +       return ret;
7269 +}
7270 +EXPORT_SYMBOL(unregister_vroot_grb);
7271 +
7272 +#endif
7273 +
7274  /*
7275   * look up a superblock on which quota ops will be performed
7276   * - use the name of a block device to find the superblock thereon
7277 @@ -313,6 +354,22 @@ static struct super_block *quotactl_bloc
7278         putname(tmp);
7279         if (IS_ERR(bdev))
7280                 return ERR_CAST(bdev);
7281 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7282 +       if (bdev && bdev->bd_inode &&
7283 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
7284 +               struct block_device *bdnew = (void *)-EINVAL;
7285 +
7286 +               if (vroot_get_real_bdev)
7287 +                       bdnew = vroot_get_real_bdev(bdev);
7288 +               else
7289 +                       vxdprintk(VXD_CBIT(misc, 0),
7290 +                                       "vroot_get_real_bdev not set");
7291 +               bdput(bdev);
7292 +               if (IS_ERR(bdnew))
7293 +                       return ERR_PTR(PTR_ERR(bdnew));
7294 +               bdev = bdnew;
7295 +       }
7296 +#endif
7297         sb = get_super(bdev);
7298         bdput(bdev);
7299         if (!sb)
7300 diff -NurpP --minimal linux-2.6.36/fs/reiserfs/file.c linux-2.6.36-vs2.3.0.36.36/fs/reiserfs/file.c
7301 --- linux-2.6.36/fs/reiserfs/file.c     2010-10-21 13:07:51.000000000 +0200
7302 +++ linux-2.6.36-vs2.3.0.36.36/fs/reiserfs/file.c       2010-10-21 13:09:36.000000000 +0200
7303 @@ -313,4 +313,5 @@ const struct inode_operations reiserfs_f
7304         .listxattr = reiserfs_listxattr,
7305         .removexattr = reiserfs_removexattr,
7306         .permission = reiserfs_permission,
7307 +       .sync_flags = reiserfs_sync_flags,
7308  };
7309 diff -NurpP --minimal linux-2.6.36/fs/reiserfs/inode.c linux-2.6.36-vs2.3.0.36.36/fs/reiserfs/inode.c
7310 --- linux-2.6.36/fs/reiserfs/inode.c    2010-10-21 13:07:51.000000000 +0200
7311 +++ linux-2.6.36-vs2.3.0.36.36/fs/reiserfs/inode.c      2010-10-21 13:59:16.000000000 +0200
7312 @@ -19,6 +19,7 @@
7313  #include <linux/writeback.h>
7314  #include <linux/quotaops.h>
7315  #include <linux/swap.h>
7316 +#include <linux/vs_tag.h>
7317  
7318  int reiserfs_commit_write(struct file *f, struct page *page,
7319                           unsigned from, unsigned to);
7320 @@ -1133,6 +1134,8 @@ static void init_inode(struct inode *ino
7321         struct buffer_head *bh;
7322         struct item_head *ih;
7323         __u32 rdev;
7324 +       uid_t uid;
7325 +       gid_t gid;
7326         //int version = ITEM_VERSION_1;
7327  
7328         bh = PATH_PLAST_BUFFER(path);
7329 @@ -1153,12 +1156,13 @@ static void init_inode(struct inode *ino
7330                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
7331                 unsigned long blocks;
7332  
7333 +               uid = sd_v1_uid(sd);
7334 +               gid = sd_v1_gid(sd);
7335 +
7336                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
7337                 set_inode_sd_version(inode, STAT_DATA_V1);
7338                 inode->i_mode = sd_v1_mode(sd);
7339                 inode->i_nlink = sd_v1_nlink(sd);
7340 -               inode->i_uid = sd_v1_uid(sd);
7341 -               inode->i_gid = sd_v1_gid(sd);
7342                 inode->i_size = sd_v1_size(sd);
7343                 inode->i_atime.tv_sec = sd_v1_atime(sd);
7344                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
7345 @@ -1200,11 +1204,12 @@ static void init_inode(struct inode *ino
7346                 // (directories and symlinks)
7347                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
7348  
7349 +               uid    = sd_v2_uid(sd);
7350 +               gid    = sd_v2_gid(sd);
7351 +
7352                 inode->i_mode = sd_v2_mode(sd);
7353                 inode->i_nlink = sd_v2_nlink(sd);
7354 -               inode->i_uid = sd_v2_uid(sd);
7355                 inode->i_size = sd_v2_size(sd);
7356 -               inode->i_gid = sd_v2_gid(sd);
7357                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
7358                 inode->i_atime.tv_sec = sd_v2_atime(sd);
7359                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
7360 @@ -1234,6 +1239,10 @@ static void init_inode(struct inode *ino
7361                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
7362         }
7363  
7364 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7365 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7366 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
7367 +
7368         pathrelse(path);
7369         if (S_ISREG(inode->i_mode)) {
7370                 inode->i_op = &reiserfs_file_inode_operations;
7371 @@ -1256,13 +1265,15 @@ static void init_inode(struct inode *ino
7372  static void inode2sd(void *sd, struct inode *inode, loff_t size)
7373  {
7374         struct stat_data *sd_v2 = (struct stat_data *)sd;
7375 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
7376 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
7377         __u16 flags;
7378  
7379 +       set_sd_v2_uid(sd_v2, uid);
7380 +       set_sd_v2_gid(sd_v2, gid);
7381         set_sd_v2_mode(sd_v2, inode->i_mode);
7382         set_sd_v2_nlink(sd_v2, inode->i_nlink);
7383 -       set_sd_v2_uid(sd_v2, inode->i_uid);
7384         set_sd_v2_size(sd_v2, size);
7385 -       set_sd_v2_gid(sd_v2, inode->i_gid);
7386         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
7387         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
7388         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
7389 @@ -2861,14 +2872,19 @@ int reiserfs_commit_write(struct file *f
7390  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
7391  {
7392         if (reiserfs_attrs(inode->i_sb)) {
7393 -               if (sd_attrs & REISERFS_SYNC_FL)
7394 -                       inode->i_flags |= S_SYNC;
7395 -               else
7396 -                       inode->i_flags &= ~S_SYNC;
7397                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
7398                         inode->i_flags |= S_IMMUTABLE;
7399                 else
7400                         inode->i_flags &= ~S_IMMUTABLE;
7401 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
7402 +                       inode->i_flags |= S_IXUNLINK;
7403 +               else
7404 +                       inode->i_flags &= ~S_IXUNLINK;
7405 +
7406 +               if (sd_attrs & REISERFS_SYNC_FL)
7407 +                       inode->i_flags |= S_SYNC;
7408 +               else
7409 +                       inode->i_flags &= ~S_SYNC;
7410                 if (sd_attrs & REISERFS_APPEND_FL)
7411                         inode->i_flags |= S_APPEND;
7412                 else
7413 @@ -2881,6 +2897,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
7414                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
7415                 else
7416                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
7417 +
7418 +               if (sd_attrs & REISERFS_BARRIER_FL)
7419 +                       inode->i_vflags |= V_BARRIER;
7420 +               else
7421 +                       inode->i_vflags &= ~V_BARRIER;
7422 +               if (sd_attrs & REISERFS_COW_FL)
7423 +                       inode->i_vflags |= V_COW;
7424 +               else
7425 +                       inode->i_vflags &= ~V_COW;
7426         }
7427  }
7428  
7429 @@ -2891,6 +2916,11 @@ void i_attrs_to_sd_attrs(struct inode *i
7430                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
7431                 else
7432                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
7433 +               if (inode->i_flags & S_IXUNLINK)
7434 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
7435 +               else
7436 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
7437 +
7438                 if (inode->i_flags & S_SYNC)
7439                         *sd_attrs |= REISERFS_SYNC_FL;
7440                 else
7441 @@ -2903,6 +2933,15 @@ void i_attrs_to_sd_attrs(struct inode *i
7442                         *sd_attrs |= REISERFS_NOTAIL_FL;
7443                 else
7444                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
7445 +
7446 +               if (inode->i_vflags & V_BARRIER)
7447 +                       *sd_attrs |= REISERFS_BARRIER_FL;
7448 +               else
7449 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
7450 +               if (inode->i_vflags & V_COW)
7451 +                       *sd_attrs |= REISERFS_COW_FL;
7452 +               else
7453 +                       *sd_attrs &= ~REISERFS_COW_FL;
7454         }
7455  }
7456  
7457 @@ -3146,7 +3185,8 @@ int reiserfs_setattr(struct dentry *dent
7458         }
7459  
7460         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
7461 -           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
7462 +           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
7463 +           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
7464                 struct reiserfs_transaction_handle th;
7465                 int jbegin_count =
7466                     2 *
7467 @@ -3175,6 +3215,9 @@ int reiserfs_setattr(struct dentry *dent
7468                         inode->i_uid = attr->ia_uid;
7469                 if (attr->ia_valid & ATTR_GID)
7470                         inode->i_gid = attr->ia_gid;
7471 +                               if ((attr->ia_valid & ATTR_TAG) &&
7472 +                                       IS_TAGGED(inode))
7473 +                                       inode->i_tag = attr->ia_tag;
7474                 mark_inode_dirty(inode);
7475                 error = journal_end(&th, inode->i_sb, jbegin_count);
7476                 if (error)
7477 diff -NurpP --minimal linux-2.6.36/fs/reiserfs/ioctl.c linux-2.6.36-vs2.3.0.36.36/fs/reiserfs/ioctl.c
7478 --- linux-2.6.36/fs/reiserfs/ioctl.c    2010-10-21 13:07:51.000000000 +0200
7479 +++ linux-2.6.36-vs2.3.0.36.36/fs/reiserfs/ioctl.c      2010-10-21 13:09:36.000000000 +0200
7480 @@ -7,11 +7,27 @@
7481  #include <linux/mount.h>
7482  #include <linux/reiserfs_fs.h>
7483  #include <linux/time.h>
7484 +#include <linux/mount.h>
7485  #include <asm/uaccess.h>
7486  #include <linux/pagemap.h>
7487  #include <linux/smp_lock.h>
7488  #include <linux/compat.h>
7489  
7490 +
7491 +int reiserfs_sync_flags(struct inode *inode, int flags, int vflags)
7492 +{
7493 +       __u16 sd_attrs = 0;
7494 +
7495 +       inode->i_flags = flags;
7496 +       inode->i_vflags = vflags;
7497 +
7498 +       i_attrs_to_sd_attrs(inode, &sd_attrs);
7499 +       REISERFS_I(inode)->i_attrs = sd_attrs;
7500 +       inode->i_ctime = CURRENT_TIME_SEC;
7501 +       mark_inode_dirty(inode);
7502 +       return 0;
7503 +}
7504 +
7505  /*
7506   * reiserfs_ioctl - handler for ioctl for inode
7507   * supported commands:
7508 @@ -23,7 +39,7 @@
7509  long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
7510  {
7511         struct inode *inode = filp->f_path.dentry->d_inode;
7512 -       unsigned int flags;
7513 +       unsigned int flags, oldflags;
7514         int err = 0;
7515  
7516         reiserfs_write_lock(inode->i_sb);
7517 @@ -48,6 +64,7 @@ long reiserfs_ioctl(struct file *filp, u
7518  
7519                 flags = REISERFS_I(inode)->i_attrs;
7520                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
7521 +               flags &= REISERFS_FL_USER_VISIBLE;
7522                 err = put_user(flags, (int __user *)arg);
7523                 break;
7524         case REISERFS_IOC_SETFLAGS:{
7525 @@ -68,6 +85,10 @@ long reiserfs_ioctl(struct file *filp, u
7526                                 err = -EFAULT;
7527                                 goto setflags_out;
7528                         }
7529 +                       if (IS_BARRIER(inode)) {
7530 +                               vxwprintk_task(1, "messing with the barrier.");
7531 +                               return -EACCES;
7532 +                       }
7533                         /*
7534                          * Is it quota file? Do not allow user to mess with it
7535                          */
7536 @@ -92,6 +113,10 @@ long reiserfs_ioctl(struct file *filp, u
7537                                         goto setflags_out;
7538                                 }
7539                         }
7540 +
7541 +                       oldflags = REISERFS_I(inode)->i_attrs;
7542 +                       flags &= REISERFS_FL_USER_MODIFIABLE;
7543 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
7544                         sd_attrs_to_i_attrs(flags, inode);
7545                         REISERFS_I(inode)->i_attrs = flags;
7546                         inode->i_ctime = CURRENT_TIME_SEC;
7547 diff -NurpP --minimal linux-2.6.36/fs/reiserfs/namei.c linux-2.6.36-vs2.3.0.36.36/fs/reiserfs/namei.c
7548 --- linux-2.6.36/fs/reiserfs/namei.c    2010-08-02 16:52:52.000000000 +0200
7549 +++ linux-2.6.36-vs2.3.0.36.36/fs/reiserfs/namei.c      2010-10-21 13:09:36.000000000 +0200
7550 @@ -18,6 +18,7 @@
7551  #include <linux/reiserfs_acl.h>
7552  #include <linux/reiserfs_xattr.h>
7553  #include <linux/quotaops.h>
7554 +#include <linux/vs_tag.h>
7555  
7556  #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; }
7557  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
7558 @@ -362,6 +363,7 @@ static struct dentry *reiserfs_lookup(st
7559         if (retval == IO_ERROR) {
7560                 return ERR_PTR(-EIO);
7561         }
7562 +               dx_propagate_tag(nd, inode);
7563  
7564         return d_splice_alias(inode, dentry);
7565  }
7566 @@ -1532,6 +1534,7 @@ const struct inode_operations reiserfs_d
7567         .listxattr = reiserfs_listxattr,
7568         .removexattr = reiserfs_removexattr,
7569         .permission = reiserfs_permission,
7570 +       .sync_flags = reiserfs_sync_flags,
7571  };
7572  
7573  /*
7574 diff -NurpP --minimal linux-2.6.36/fs/reiserfs/super.c linux-2.6.36-vs2.3.0.36.36/fs/reiserfs/super.c
7575 --- linux-2.6.36/fs/reiserfs/super.c    2010-10-21 13:07:51.000000000 +0200
7576 +++ linux-2.6.36-vs2.3.0.36.36/fs/reiserfs/super.c      2010-10-21 13:09:36.000000000 +0200
7577 @@ -893,6 +893,14 @@ static int reiserfs_parse_options(struct
7578                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
7579                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
7580  #endif
7581 +#ifndef CONFIG_TAGGING_NONE
7582 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
7583 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
7584 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
7585 +#endif
7586 +#ifdef CONFIG_PROPAGATE
7587 +               {"tag",.arg_required = 'T',.values = NULL},
7588 +#endif
7589  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
7590                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
7591                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
7592 @@ -1202,6 +1210,14 @@ static int reiserfs_remount(struct super
7593         handle_quota_files(s, qf_names, &qfmt);
7594  #endif
7595  
7596 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
7597 +               !(s->s_flags & MS_TAGGED)) {
7598 +               reiserfs_warning(s, "super-vs01",
7599 +                       "reiserfs: tagging not permitted on remount.");
7600 +               err = -EINVAL;
7601 +               goto out_err;
7602 +       }
7603 +
7604         handle_attrs(s);
7605  
7606         /* Add options that are safe here */
7607 @@ -1684,6 +1700,10 @@ static int reiserfs_fill_super(struct su
7608                 goto error;
7609         }
7610  
7611 +       /* map mount option tagxid */
7612 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
7613 +               s->s_flags |= MS_TAGGED;
7614 +
7615         rs = SB_DISK_SUPER_BLOCK(s);
7616         /* Let's do basic sanity check to verify that underlying device is not
7617            smaller than the filesystem. If the check fails then abort and scream,
7618 diff -NurpP --minimal linux-2.6.36/fs/reiserfs/xattr.c linux-2.6.36-vs2.3.0.36.36/fs/reiserfs/xattr.c
7619 --- linux-2.6.36/fs/reiserfs/xattr.c    2010-08-02 16:52:52.000000000 +0200
7620 +++ linux-2.6.36-vs2.3.0.36.36/fs/reiserfs/xattr.c      2010-10-21 13:09:36.000000000 +0200
7621 @@ -40,6 +40,7 @@
7622  #include <linux/errno.h>
7623  #include <linux/gfp.h>
7624  #include <linux/fs.h>
7625 +#include <linux/mount.h>
7626  #include <linux/file.h>
7627  #include <linux/pagemap.h>
7628  #include <linux/xattr.h>
7629 diff -NurpP --minimal linux-2.6.36/fs/stat.c linux-2.6.36-vs2.3.0.36.36/fs/stat.c
7630 --- linux-2.6.36/fs/stat.c      2010-10-21 13:07:51.000000000 +0200
7631 +++ linux-2.6.36-vs2.3.0.36.36/fs/stat.c        2010-10-21 13:09:36.000000000 +0200
7632 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
7633         stat->nlink = inode->i_nlink;
7634         stat->uid = inode->i_uid;
7635         stat->gid = inode->i_gid;
7636 +       stat->tag = inode->i_tag;
7637         stat->rdev = inode->i_rdev;
7638         stat->atime = inode->i_atime;
7639         stat->mtime = inode->i_mtime;
7640 diff -NurpP --minimal linux-2.6.36/fs/statfs.c linux-2.6.36-vs2.3.0.36.36/fs/statfs.c
7641 --- linux-2.6.36/fs/statfs.c    2010-10-21 13:07:51.000000000 +0200
7642 +++ linux-2.6.36-vs2.3.0.36.36/fs/statfs.c      2010-10-21 14:07:35.000000000 +0200
7643 @@ -7,6 +7,8 @@
7644  #include <linux/statfs.h>
7645  #include <linux/security.h>
7646  #include <linux/uaccess.h>
7647 +#include <linux/vs_base.h>
7648 +#include <linux/vs_dlimit.h>
7649  
7650  static int flags_by_mnt(int mnt_flags)
7651  {
7652 @@ -59,6 +61,8 @@ int statfs_by_dentry(struct dentry *dent
7653         retval = dentry->d_sb->s_op->statfs(dentry, buf);
7654         if (retval == 0 && buf->f_frsize == 0)
7655                 buf->f_frsize = buf->f_bsize;
7656 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
7657 +               vx_vsi_statfs(dentry->d_sb, buf);
7658         return retval;
7659  }
7660  
7661 diff -NurpP --minimal linux-2.6.36/fs/super.c linux-2.6.36-vs2.3.0.36.36/fs/super.c
7662 --- linux-2.6.36/fs/super.c     2010-10-21 13:07:51.000000000 +0200
7663 +++ linux-2.6.36-vs2.3.0.36.36/fs/super.c       2010-10-21 13:09:36.000000000 +0200
7664 @@ -30,6 +30,9 @@
7665  #include <linux/idr.h>
7666  #include <linux/mutex.h>
7667  #include <linux/backing-dev.h>
7668 +#include <linux/devpts_fs.h>
7669 +#include <linux/proc_fs.h>
7670 +#include <linux/vs_context.h>
7671  #include "internal.h"
7672  
7673  
7674 @@ -918,12 +921,18 @@ struct vfsmount *
7675  vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
7676  {
7677         struct vfsmount *mnt;
7678 +       struct super_block *sb;
7679         char *secdata = NULL;
7680         int error;
7681  
7682         if (!type)
7683                 return ERR_PTR(-ENODEV);
7684  
7685 +       error = -EPERM;
7686 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
7687 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
7688 +               goto out;
7689 +
7690         error = -ENOMEM;
7691         mnt = alloc_vfsmnt(name);
7692         if (!mnt)
7693 @@ -945,11 +954,19 @@ vfs_kern_mount(struct file_system_type *
7694         error = type->get_sb(type, flags, name, data, mnt);
7695         if (error < 0)
7696                 goto out_free_secdata;
7697 -       BUG_ON(!mnt->mnt_sb);
7698 -       WARN_ON(!mnt->mnt_sb->s_bdi);
7699 +
7700 +       sb = mnt->mnt_sb;
7701 +       BUG_ON(!sb);
7702 +       WARN_ON(!sb->s_bdi);
7703         mnt->mnt_sb->s_flags |= MS_BORN;
7704  
7705 -       error = security_sb_kern_mount(mnt->mnt_sb, flags, secdata);
7706 +       error = -EPERM;
7707 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) && !sb->s_bdev &&
7708 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
7709 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
7710 +               goto out_sb;
7711 +
7712 +       error = security_sb_kern_mount(sb, flags, secdata);
7713         if (error)
7714                 goto out_sb;
7715  
7716 diff -NurpP --minimal linux-2.6.36/fs/sysfs/mount.c linux-2.6.36-vs2.3.0.36.36/fs/sysfs/mount.c
7717 --- linux-2.6.36/fs/sysfs/mount.c       2010-10-21 13:07:51.000000000 +0200
7718 +++ linux-2.6.36-vs2.3.0.36.36/fs/sysfs/mount.c 2010-10-21 13:09:36.000000000 +0200
7719 @@ -47,7 +47,7 @@ static int sysfs_fill_super(struct super
7720  
7721         sb->s_blocksize = PAGE_CACHE_SIZE;
7722         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
7723 -       sb->s_magic = SYSFS_MAGIC;
7724 +       sb->s_magic = SYSFS_SUPER_MAGIC;
7725         sb->s_op = &sysfs_ops;
7726         sb->s_time_gran = 1;
7727  
7728 diff -NurpP --minimal linux-2.6.36/fs/utimes.c linux-2.6.36-vs2.3.0.36.36/fs/utimes.c
7729 --- linux-2.6.36/fs/utimes.c    2010-10-21 13:07:51.000000000 +0200
7730 +++ linux-2.6.36-vs2.3.0.36.36/fs/utimes.c      2010-10-21 13:09:36.000000000 +0200
7731 @@ -8,6 +8,8 @@
7732  #include <linux/stat.h>
7733  #include <linux/utime.h>
7734  #include <linux/syscalls.h>
7735 +#include <linux/mount.h>
7736 +#include <linux/vs_cowbl.h>
7737  #include <asm/uaccess.h>
7738  #include <asm/unistd.h>
7739  
7740 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
7741  {
7742         int error;
7743         struct iattr newattrs;
7744 -       struct inode *inode = path->dentry->d_inode;
7745 +       struct inode *inode;
7746  
7747         error = mnt_want_write(path->mnt);
7748         if (error)
7749                 goto out;
7750  
7751 +       error = cow_check_and_break(path);
7752 +       if (error)
7753 +               goto mnt_drop_write_and_out;
7754 +
7755 +       inode = path->dentry->d_inode;
7756 +
7757         if (times && times[0].tv_nsec == UTIME_NOW &&
7758                      times[1].tv_nsec == UTIME_NOW)
7759                 times = NULL;
7760 diff -NurpP --minimal linux-2.6.36/fs/xattr.c linux-2.6.36-vs2.3.0.36.36/fs/xattr.c
7761 --- linux-2.6.36/fs/xattr.c     2010-08-02 16:52:52.000000000 +0200
7762 +++ linux-2.6.36-vs2.3.0.36.36/fs/xattr.c       2010-10-21 13:09:36.000000000 +0200
7763 @@ -18,6 +18,7 @@
7764  #include <linux/module.h>
7765  #include <linux/fsnotify.h>
7766  #include <linux/audit.h>
7767 +#include <linux/mount.h>
7768  #include <asm/uaccess.h>
7769  
7770  
7771 @@ -49,7 +50,7 @@ xattr_permission(struct inode *inode, co
7772          * The trusted.* namespace can only be accessed by a privileged user.
7773          */
7774         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN))
7775 -               return (capable(CAP_SYS_ADMIN) ? 0 : -EPERM);
7776 +               return (vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED) ? 0 : -EPERM);
7777  
7778         /* In user.* namespace, only regular files and directories can have
7779          * extended attributes. For sticky directories, only the owner and
7780 diff -NurpP --minimal linux-2.6.36/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.36-vs2.3.0.36.36/fs/xfs/linux-2.6/xfs_ioctl.c
7781 --- linux-2.6.36/fs/xfs/linux-2.6/xfs_ioctl.c   2010-10-21 13:07:51.000000000 +0200
7782 +++ linux-2.6.36-vs2.3.0.36.36/fs/xfs/linux-2.6/xfs_ioctl.c     2010-10-21 14:02:37.000000000 +0200
7783 @@ -28,7 +28,7 @@
7784  #include "xfs_bmap_btree.h"
7785  #include "xfs_dinode.h"
7786  #include "xfs_inode.h"
7787 -#include "xfs_ioctl.h"
7788 +// #include "xfs_ioctl.h"
7789  #include "xfs_rtalloc.h"
7790  #include "xfs_itable.h"
7791  #include "xfs_error.h"
7792 @@ -738,6 +738,10 @@ xfs_merge_ioc_xflags(
7793                 xflags |= XFS_XFLAG_IMMUTABLE;
7794         else
7795                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7796 +       if (flags & FS_IXUNLINK_FL)
7797 +               xflags |= XFS_XFLAG_IXUNLINK;
7798 +       else
7799 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7800         if (flags & FS_APPEND_FL)
7801                 xflags |= XFS_XFLAG_APPEND;
7802         else
7803 @@ -766,6 +770,8 @@ xfs_di2lxflags(
7804  
7805         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7806                 flags |= FS_IMMUTABLE_FL;
7807 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7808 +               flags |= FS_IXUNLINK_FL;
7809         if (di_flags & XFS_DIFLAG_APPEND)
7810                 flags |= FS_APPEND_FL;
7811         if (di_flags & XFS_DIFLAG_SYNC)
7812 @@ -826,6 +832,8 @@ xfs_set_diflags(
7813         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7814         if (xflags & XFS_XFLAG_IMMUTABLE)
7815                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7816 +       if (xflags & XFS_XFLAG_IXUNLINK)
7817 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7818         if (xflags & XFS_XFLAG_APPEND)
7819                 di_flags |= XFS_DIFLAG_APPEND;
7820         if (xflags & XFS_XFLAG_SYNC)
7821 @@ -868,6 +876,10 @@ xfs_diflags_to_linux(
7822                 inode->i_flags |= S_IMMUTABLE;
7823         else
7824                 inode->i_flags &= ~S_IMMUTABLE;
7825 +       if (xflags & XFS_XFLAG_IXUNLINK)
7826 +               inode->i_flags |= S_IXUNLINK;
7827 +       else
7828 +               inode->i_flags &= ~S_IXUNLINK;
7829         if (xflags & XFS_XFLAG_APPEND)
7830                 inode->i_flags |= S_APPEND;
7831         else
7832 @@ -1341,10 +1353,18 @@ xfs_file_ioctl(
7833         case XFS_IOC_FSGETXATTRA:
7834                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7835         case XFS_IOC_FSSETXATTR:
7836 +               if (IS_BARRIER(inode)) {
7837 +                       vxwprintk_task(1, "messing with the barrier.");
7838 +                       return -XFS_ERROR(EACCES);
7839 +               }
7840                 return xfs_ioc_fssetxattr(ip, filp, arg);
7841         case XFS_IOC_GETXFLAGS:
7842                 return xfs_ioc_getxflags(ip, arg);
7843         case XFS_IOC_SETXFLAGS:
7844 +               if (IS_BARRIER(inode)) {
7845 +                       vxwprintk_task(1, "messing with the barrier.");
7846 +                       return -XFS_ERROR(EACCES);
7847 +               }
7848                 return xfs_ioc_setxflags(ip, filp, arg);
7849  
7850         case XFS_IOC_FSSETDM: {
7851 diff -NurpP --minimal linux-2.6.36/fs/xfs/linux-2.6/xfs_ioctl.h linux-2.6.36-vs2.3.0.36.36/fs/xfs/linux-2.6/xfs_ioctl.h
7852 --- linux-2.6.36/fs/xfs/linux-2.6/xfs_ioctl.h   2010-07-07 18:31:54.000000000 +0200
7853 +++ linux-2.6.36-vs2.3.0.36.36/fs/xfs/linux-2.6/xfs_ioctl.h     2010-10-21 13:09:36.000000000 +0200
7854 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7855         void __user             *uhandle,
7856         u32                     hlen);
7857  
7858 +extern int
7859 +xfs_sync_flags(
7860 +       struct inode            *inode,
7861 +       int                     flags,
7862 +       int                     vflags);
7863 +
7864  extern long
7865  xfs_file_ioctl(
7866         struct file             *filp,
7867 diff -NurpP --minimal linux-2.6.36/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.36-vs2.3.0.36.36/fs/xfs/linux-2.6/xfs_iops.c
7868 --- linux-2.6.36/fs/xfs/linux-2.6/xfs_iops.c    2010-10-21 13:07:51.000000000 +0200
7869 +++ linux-2.6.36-vs2.3.0.36.36/fs/xfs/linux-2.6/xfs_iops.c      2010-10-21 13:09:36.000000000 +0200
7870 @@ -30,6 +30,7 @@
7871  #include "xfs_bmap_btree.h"
7872  #include "xfs_dinode.h"
7873  #include "xfs_inode.h"
7874 +#include "xfs_ioctl.h"
7875  #include "xfs_bmap.h"
7876  #include "xfs_rtalloc.h"
7877  #include "xfs_error.h"
7878 @@ -49,6 +50,7 @@
7879  #include <linux/falloc.h>
7880  #include <linux/fiemap.h>
7881  #include <linux/slab.h>
7882 +#include <linux/vs_tag.h>
7883  
7884  /*
7885   * Bring the timestamps in the XFS inode uptodate.
7886 @@ -499,6 +501,7 @@ xfs_vn_getattr(
7887         stat->nlink = ip->i_d.di_nlink;
7888         stat->uid = ip->i_d.di_uid;
7889         stat->gid = ip->i_d.di_gid;
7890 +       stat->tag = ip->i_d.di_tag;
7891         stat->ino = ip->i_ino;
7892         stat->atime = inode->i_atime;
7893         stat->mtime = inode->i_mtime;
7894 @@ -687,6 +690,7 @@ static const struct inode_operations xfs
7895         .listxattr              = xfs_vn_listxattr,
7896         .fallocate              = xfs_vn_fallocate,
7897         .fiemap                 = xfs_vn_fiemap,
7898 +       .sync_flags             = xfs_sync_flags,
7899  };
7900  
7901  static const struct inode_operations xfs_dir_inode_operations = {
7902 @@ -712,6 +716,7 @@ static const struct inode_operations xfs
7903         .getxattr               = generic_getxattr,
7904         .removexattr            = generic_removexattr,
7905         .listxattr              = xfs_vn_listxattr,
7906 +       .sync_flags             = xfs_sync_flags,
7907  };
7908  
7909  static const struct inode_operations xfs_dir_ci_inode_operations = {
7910 @@ -761,6 +766,10 @@ xfs_diflags_to_iflags(
7911                 inode->i_flags |= S_IMMUTABLE;
7912         else
7913                 inode->i_flags &= ~S_IMMUTABLE;
7914 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7915 +               inode->i_flags |= S_IXUNLINK;
7916 +       else
7917 +               inode->i_flags &= ~S_IXUNLINK;
7918         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7919                 inode->i_flags |= S_APPEND;
7920         else
7921 @@ -773,6 +782,15 @@ xfs_diflags_to_iflags(
7922                 inode->i_flags |= S_NOATIME;
7923         else
7924                 inode->i_flags &= ~S_NOATIME;
7925 +
7926 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7927 +               inode->i_vflags |= V_BARRIER;
7928 +       else
7929 +               inode->i_vflags &= ~V_BARRIER;
7930 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7931 +               inode->i_vflags |= V_COW;
7932 +       else
7933 +               inode->i_vflags &= ~V_COW;
7934  }
7935  
7936  /*
7937 @@ -801,6 +819,7 @@ xfs_setup_inode(
7938         inode->i_nlink  = ip->i_d.di_nlink;
7939         inode->i_uid    = ip->i_d.di_uid;
7940         inode->i_gid    = ip->i_d.di_gid;
7941 +       inode->i_tag    = ip->i_d.di_tag;
7942  
7943         switch (inode->i_mode & S_IFMT) {
7944         case S_IFBLK:
7945 diff -NurpP --minimal linux-2.6.36/fs/xfs/linux-2.6/xfs_linux.h linux-2.6.36-vs2.3.0.36.36/fs/xfs/linux-2.6/xfs_linux.h
7946 --- linux-2.6.36/fs/xfs/linux-2.6/xfs_linux.h   2010-10-21 13:07:51.000000000 +0200
7947 +++ linux-2.6.36-vs2.3.0.36.36/fs/xfs/linux-2.6/xfs_linux.h     2010-10-21 13:09:36.000000000 +0200
7948 @@ -116,6 +116,7 @@
7949  
7950  #define current_cpu()          (raw_smp_processor_id())
7951  #define current_pid()          (current->pid)
7952 +#define current_fstag(cred,vp) (dx_current_fstag((vp)->i_sb))
7953  #define current_test_flags(f)  (current->flags & (f))
7954  #define current_set_flags_nested(sp, f)                \
7955                 (*(sp) = current->flags, current->flags |= (f))
7956 diff -NurpP --minimal linux-2.6.36/fs/xfs/linux-2.6/xfs_super.c linux-2.6.36-vs2.3.0.36.36/fs/xfs/linux-2.6/xfs_super.c
7957 --- linux-2.6.36/fs/xfs/linux-2.6/xfs_super.c   2010-10-21 13:07:51.000000000 +0200
7958 +++ linux-2.6.36-vs2.3.0.36.36/fs/xfs/linux-2.6/xfs_super.c     2010-10-21 13:09:36.000000000 +0200
7959 @@ -113,6 +113,9 @@ mempool_t *xfs_ioend_pool;
7960  #define MNTOPT_QUOTANOENF  "qnoenforce"        /* same as uqnoenforce */
7961  #define MNTOPT_DELAYLOG   "delaylog"   /* Delayed loging enabled */
7962  #define MNTOPT_NODELAYLOG "nodelaylog" /* Delayed loging disabled */
7963 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
7964 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
7965 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
7966  
7967  /*
7968   * Table driven mount option parser.
7969 @@ -121,10 +124,14 @@ mempool_t *xfs_ioend_pool;
7970   * in the future, too.
7971   */
7972  enum {
7973 +       Opt_tag, Opt_notag,
7974         Opt_barrier, Opt_nobarrier, Opt_err
7975  };
7976  
7977  static const match_table_t tokens = {
7978 +       {Opt_tag, "tagxid"},
7979 +       {Opt_tag, "tag"},
7980 +       {Opt_notag, "notag"},
7981         {Opt_barrier, "barrier"},
7982         {Opt_nobarrier, "nobarrier"},
7983         {Opt_err, NULL}
7984 @@ -371,6 +378,19 @@ xfs_parseargs(
7985                 } else if (!strcmp(this_char, "irixsgid")) {
7986                         cmn_err(CE_WARN,
7987         "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
7988 +#ifndef CONFIG_TAGGING_NONE
7989 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7990 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7991 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7992 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
7993 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7994 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7995 +#endif
7996 +#ifdef CONFIG_PROPAGATE
7997 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7998 +                       /* use value */
7999 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
8000 +#endif
8001                 } else {
8002                         cmn_err(CE_WARN,
8003                                 "XFS: unknown mount option [%s].", this_char);
8004 @@ -1320,6 +1340,16 @@ xfs_fs_remount(
8005                 case Opt_nobarrier:
8006                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
8007                         break;
8008 +               case Opt_tag:
8009 +                       if (!(sb->s_flags & MS_TAGGED)) {
8010 +                               printk(KERN_INFO
8011 +                                       "XFS: %s: tagging not permitted on remount.\n",
8012 +                                       sb->s_id);
8013 +                               return -EINVAL;
8014 +                       }
8015 +                       break;
8016 +               case Opt_notag:
8017 +                       break;
8018                 default:
8019                         /*
8020                          * Logically we would return an error here to prevent
8021 @@ -1547,6 +1577,9 @@ xfs_fs_fill_super(
8022         if (error)
8023                 goto out_filestream_unmount;
8024  
8025 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
8026 +               sb->s_flags |= MS_TAGGED;
8027 +
8028         sb->s_magic = XFS_SB_MAGIC;
8029         sb->s_blocksize = mp->m_sb.sb_blocksize;
8030         sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
8031 diff -NurpP --minimal linux-2.6.36/fs/xfs/xfs_dinode.h linux-2.6.36-vs2.3.0.36.36/fs/xfs/xfs_dinode.h
8032 --- linux-2.6.36/fs/xfs/xfs_dinode.h    2009-06-11 17:13:09.000000000 +0200
8033 +++ linux-2.6.36-vs2.3.0.36.36/fs/xfs/xfs_dinode.h      2010-10-21 13:09:36.000000000 +0200
8034 @@ -50,7 +50,9 @@ typedef struct xfs_dinode {
8035         __be32          di_gid;         /* owner's group id */
8036         __be32          di_nlink;       /* number of links to file */
8037         __be16          di_projid;      /* owner's project id */
8038 -       __u8            di_pad[8];      /* unused, zeroed space */
8039 +       __be16          di_tag;         /* context tagging */
8040 +       __be16          di_vflags;      /* vserver specific flags */
8041 +       __u8            di_pad[4];      /* unused, zeroed space */
8042         __be16          di_flushiter;   /* incremented on flush */
8043         xfs_timestamp_t di_atime;       /* time last accessed */
8044         xfs_timestamp_t di_mtime;       /* time last modified */
8045 @@ -183,6 +185,8 @@ static inline void xfs_dinode_put_rdev(s
8046  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
8047  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
8048  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
8049 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
8050 +
8051  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
8052  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
8053  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
8054 @@ -198,6 +202,7 @@ static inline void xfs_dinode_put_rdev(s
8055  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
8056  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
8057  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
8058 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
8059  
8060  #ifdef CONFIG_XFS_RT
8061  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
8062 @@ -210,6 +215,10 @@ static inline void xfs_dinode_put_rdev(s
8063          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
8064          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
8065          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
8066 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
8067 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
8068 +        XFS_DIFLAG_IXUNLINK)
8069 +
8070 +#define XFS_DIVFLAG_BARRIER    0x01
8071 +#define XFS_DIVFLAG_COW                0x02
8072  
8073  #endif /* __XFS_DINODE_H__ */
8074 diff -NurpP --minimal linux-2.6.36/fs/xfs/xfs_fs.h linux-2.6.36-vs2.3.0.36.36/fs/xfs/xfs_fs.h
8075 --- linux-2.6.36/fs/xfs/xfs_fs.h        2010-10-21 13:07:52.000000000 +0200
8076 +++ linux-2.6.36-vs2.3.0.36.36/fs/xfs/xfs_fs.h  2010-10-21 13:09:36.000000000 +0200
8077 @@ -67,6 +67,9 @@ struct fsxattr {
8078  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
8079  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
8080  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
8081 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
8082 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
8083 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
8084  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
8085  
8086  /*
8087 @@ -295,7 +298,8 @@ typedef struct xfs_bstat {
8088         __u32           bs_gen;         /* generation count             */
8089         __u16           bs_projid;      /* project id                   */
8090         __u16           bs_forkoff;     /* inode fork offset in bytes   */
8091 -       unsigned char   bs_pad[12];     /* pad space, unused            */
8092 +       __u16           bs_tag;         /* context tagging              */
8093 +       unsigned char   bs_pad[10];     /* pad space, unused            */
8094         __u32           bs_dmevmask;    /* DMIG event mask              */
8095         __u16           bs_dmstate;     /* DMIG state info              */
8096         __u16           bs_aextents;    /* attribute number of extents  */
8097 diff -NurpP --minimal linux-2.6.36/fs/xfs/xfs_ialloc.c linux-2.6.36-vs2.3.0.36.36/fs/xfs/xfs_ialloc.c
8098 --- linux-2.6.36/fs/xfs/xfs_ialloc.c    2010-10-21 13:07:52.000000000 +0200
8099 +++ linux-2.6.36-vs2.3.0.36.36/fs/xfs/xfs_ialloc.c      2010-10-21 13:09:36.000000000 +0200
8100 @@ -37,7 +37,6 @@
8101  #include "xfs_error.h"
8102  #include "xfs_bmap.h"
8103  
8104 -
8105  /*
8106   * Allocation group level functions.
8107   */
8108 diff -NurpP --minimal linux-2.6.36/fs/xfs/xfs_inode.c linux-2.6.36-vs2.3.0.36.36/fs/xfs/xfs_inode.c
8109 --- linux-2.6.36/fs/xfs/xfs_inode.c     2010-10-21 13:07:52.000000000 +0200
8110 +++ linux-2.6.36-vs2.3.0.36.36/fs/xfs/xfs_inode.c       2010-10-21 13:09:36.000000000 +0200
8111 @@ -245,6 +245,7 @@ xfs_inotobp(
8112         return 0;
8113  }
8114  
8115 +#include <linux/vs_tag.h>
8116  
8117  /*
8118   * This routine is called to map an inode to the buffer containing
8119 @@ -650,15 +651,25 @@ xfs_iformat_btree(
8120  STATIC void
8121  xfs_dinode_from_disk(
8122         xfs_icdinode_t          *to,
8123 -       xfs_dinode_t            *from)
8124 +       xfs_dinode_t            *from,
8125 +       int tagged)
8126  {
8127 +       uint32_t uid, gid, tag;
8128 +
8129         to->di_magic = be16_to_cpu(from->di_magic);
8130         to->di_mode = be16_to_cpu(from->di_mode);
8131         to->di_version = from ->di_version;
8132         to->di_format = from->di_format;
8133         to->di_onlink = be16_to_cpu(from->di_onlink);
8134 -       to->di_uid = be32_to_cpu(from->di_uid);
8135 -       to->di_gid = be32_to_cpu(from->di_gid);
8136 +
8137 +       uid = be32_to_cpu(from->di_uid);
8138 +       gid = be32_to_cpu(from->di_gid);
8139 +       tag = be16_to_cpu(from->di_tag);
8140 +
8141 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
8142 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
8143 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
8144 +
8145         to->di_nlink = be32_to_cpu(from->di_nlink);
8146         to->di_projid = be16_to_cpu(from->di_projid);
8147         memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
8148 @@ -679,21 +690,26 @@ xfs_dinode_from_disk(
8149         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
8150         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
8151         to->di_flags    = be16_to_cpu(from->di_flags);
8152 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
8153         to->di_gen      = be32_to_cpu(from->di_gen);
8154  }
8155  
8156  void
8157  xfs_dinode_to_disk(
8158         xfs_dinode_t            *to,
8159 -       xfs_icdinode_t          *from)
8160 +       xfs_icdinode_t          *from,
8161 +       int tagged)
8162  {
8163         to->di_magic = cpu_to_be16(from->di_magic);
8164         to->di_mode = cpu_to_be16(from->di_mode);
8165         to->di_version = from ->di_version;
8166         to->di_format = from->di_format;
8167         to->di_onlink = cpu_to_be16(from->di_onlink);
8168 -       to->di_uid = cpu_to_be32(from->di_uid);
8169 -       to->di_gid = cpu_to_be32(from->di_gid);
8170 +
8171 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
8172 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
8173 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
8174 +
8175         to->di_nlink = cpu_to_be32(from->di_nlink);
8176         to->di_projid = cpu_to_be16(from->di_projid);
8177         memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
8178 @@ -714,12 +730,14 @@ xfs_dinode_to_disk(
8179         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
8180         to->di_dmstate = cpu_to_be16(from->di_dmstate);
8181         to->di_flags = cpu_to_be16(from->di_flags);
8182 +       to->di_vflags = cpu_to_be16(from->di_vflags);
8183         to->di_gen = cpu_to_be32(from->di_gen);
8184  }
8185  
8186  STATIC uint
8187  _xfs_dic2xflags(
8188 -       __uint16_t              di_flags)
8189 +       __uint16_t              di_flags,
8190 +       __uint16_t              di_vflags)
8191  {
8192         uint                    flags = 0;
8193  
8194 @@ -730,6 +748,8 @@ _xfs_dic2xflags(
8195                         flags |= XFS_XFLAG_PREALLOC;
8196                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
8197                         flags |= XFS_XFLAG_IMMUTABLE;
8198 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
8199 +                       flags |= XFS_XFLAG_IXUNLINK;
8200                 if (di_flags & XFS_DIFLAG_APPEND)
8201                         flags |= XFS_XFLAG_APPEND;
8202                 if (di_flags & XFS_DIFLAG_SYNC)
8203 @@ -754,6 +774,10 @@ _xfs_dic2xflags(
8204                         flags |= XFS_XFLAG_FILESTREAM;
8205         }
8206  
8207 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
8208 +               flags |= FS_BARRIER_FL;
8209 +       if (di_vflags & XFS_DIVFLAG_COW)
8210 +               flags |= FS_COW_FL;
8211         return flags;
8212  }
8213  
8214 @@ -763,7 +787,7 @@ xfs_ip2xflags(
8215  {
8216         xfs_icdinode_t          *dic = &ip->i_d;
8217  
8218 -       return _xfs_dic2xflags(dic->di_flags) |
8219 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
8220                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
8221  }
8222  
8223 @@ -771,7 +795,8 @@ uint
8224  xfs_dic2xflags(
8225         xfs_dinode_t            *dip)
8226  {
8227 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
8228 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
8229 +                               be16_to_cpu(dip->di_vflags)) |
8230                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
8231  }
8232  
8233 @@ -804,7 +829,6 @@ xfs_iread(
8234         if (error)
8235                 return error;
8236         dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);
8237 -
8238         /*
8239          * If we got something that isn't an inode it means someone
8240          * (nfs or dmi) has a stale handle.
8241 @@ -829,7 +853,8 @@ xfs_iread(
8242          * Otherwise, just get the truly permanent information.
8243          */
8244         if (dip->di_mode) {
8245 -               xfs_dinode_from_disk(&ip->i_d, dip);
8246 +               xfs_dinode_from_disk(&ip->i_d, dip,
8247 +                       mp->m_flags & XFS_MOUNT_TAGGED);
8248                 error = xfs_iformat(ip, dip);
8249                 if (error)  {
8250  #ifdef DEBUG
8251 @@ -1027,6 +1052,7 @@ xfs_ialloc(
8252         ASSERT(ip->i_d.di_nlink == nlink);
8253         ip->i_d.di_uid = current_fsuid();
8254         ip->i_d.di_gid = current_fsgid();
8255 +       ip->i_d.di_tag = current_fstag(cr, &ip->i_vnode);
8256         ip->i_d.di_projid = prid;
8257         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
8258  
8259 @@ -1087,6 +1113,7 @@ xfs_ialloc(
8260         ip->i_d.di_dmevmask = 0;
8261         ip->i_d.di_dmstate = 0;
8262         ip->i_d.di_flags = 0;
8263 +       ip->i_d.di_vflags = 0;
8264         flags = XFS_ILOG_CORE;
8265         switch (mode & S_IFMT) {
8266         case S_IFIFO:
8267 @@ -2105,6 +2132,7 @@ xfs_ifree(
8268         }
8269         ip->i_d.di_mode = 0;            /* mark incore inode as free */
8270         ip->i_d.di_flags = 0;
8271 +       ip->i_d.di_vflags = 0;
8272         ip->i_d.di_dmevmask = 0;
8273         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
8274         ip->i_df.if_ext_max =
8275 @@ -2975,7 +3003,8 @@ xfs_iflush_int(
8276          * because if the inode is dirty at all the core must
8277          * be.
8278          */
8279 -       xfs_dinode_to_disk(dip, &ip->i_d);
8280 +       xfs_dinode_to_disk(dip, &ip->i_d,
8281 +               mp->m_flags & XFS_MOUNT_TAGGED);
8282  
8283         /* Wrap, we never let the log put out DI_MAX_FLUSH */
8284         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
8285 diff -NurpP --minimal linux-2.6.36/fs/xfs/xfs_inode.h linux-2.6.36-vs2.3.0.36.36/fs/xfs/xfs_inode.h
8286 --- linux-2.6.36/fs/xfs/xfs_inode.h     2010-10-21 13:07:52.000000000 +0200
8287 +++ linux-2.6.36-vs2.3.0.36.36/fs/xfs/xfs_inode.h       2010-10-21 13:09:36.000000000 +0200
8288 @@ -135,7 +135,9 @@ typedef struct xfs_icdinode {
8289         __uint32_t      di_gid;         /* owner's group id */
8290         __uint32_t      di_nlink;       /* number of links to file */
8291         __uint16_t      di_projid;      /* owner's project id */
8292 -       __uint8_t       di_pad[8];      /* unused, zeroed space */
8293 +       __uint16_t      di_tag;         /* context tagging */
8294 +       __uint16_t      di_vflags;      /* vserver specific flags */
8295 +       __uint8_t       di_pad[4];      /* unused, zeroed space */
8296         __uint16_t      di_flushiter;   /* incremented on flush */
8297         xfs_ictimestamp_t di_atime;     /* time last accessed */
8298         xfs_ictimestamp_t di_mtime;     /* time last modified */
8299 @@ -509,7 +511,7 @@ int         xfs_itobp(struct xfs_mount *, struc
8300  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
8301                           struct xfs_inode *, uint);
8302  void           xfs_dinode_to_disk(struct xfs_dinode *,
8303 -                                  struct xfs_icdinode *);
8304 +                                  struct xfs_icdinode *, int);
8305  void           xfs_idestroy_fork(struct xfs_inode *, int);
8306  void           xfs_idata_realloc(struct xfs_inode *, int, int);
8307  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
8308 diff -NurpP --minimal linux-2.6.36/fs/xfs/xfs_itable.c linux-2.6.36-vs2.3.0.36.36/fs/xfs/xfs_itable.c
8309 --- linux-2.6.36/fs/xfs/xfs_itable.c    2010-10-21 13:07:52.000000000 +0200
8310 +++ linux-2.6.36-vs2.3.0.36.36/fs/xfs/xfs_itable.c      2010-10-21 13:09:36.000000000 +0200
8311 @@ -97,6 +97,7 @@ xfs_bulkstat_one_int(
8312         buf->bs_mode = dic->di_mode;
8313         buf->bs_uid = dic->di_uid;
8314         buf->bs_gid = dic->di_gid;
8315 +       buf->bs_tag = dic->di_tag;
8316         buf->bs_size = dic->di_size;
8317  
8318         /*
8319 diff -NurpP --minimal linux-2.6.36/fs/xfs/xfs_log_recover.c linux-2.6.36-vs2.3.0.36.36/fs/xfs/xfs_log_recover.c
8320 --- linux-2.6.36/fs/xfs/xfs_log_recover.c       2010-10-21 13:07:52.000000000 +0200
8321 +++ linux-2.6.36-vs2.3.0.36.36/fs/xfs/xfs_log_recover.c 2010-10-21 14:02:02.000000000 +0200
8322 @@ -2450,7 +2450,8 @@ xlog_recover_do_inode_trans(
8323         }
8324  
8325         /* The core is in in-core format */
8326 -       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr);
8327 +       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr,
8328 +               mp->m_flags & XFS_MOUNT_TAGGED);
8329  
8330         /* the rest is in on-disk format */
8331         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
8332 diff -NurpP --minimal linux-2.6.36/fs/xfs/xfs_mount.h linux-2.6.36-vs2.3.0.36.36/fs/xfs/xfs_mount.h
8333 --- linux-2.6.36/fs/xfs/xfs_mount.h     2010-10-21 13:07:52.000000000 +0200
8334 +++ linux-2.6.36-vs2.3.0.36.36/fs/xfs/xfs_mount.h       2010-10-21 13:09:36.000000000 +0200
8335 @@ -238,6 +238,7 @@ typedef struct xfs_mount {
8336                                                    allocator */
8337  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
8338  
8339 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
8340  
8341  /*
8342   * Default minimum read and write sizes.
8343 diff -NurpP --minimal linux-2.6.36/fs/xfs/xfs_vnodeops.c linux-2.6.36-vs2.3.0.36.36/fs/xfs/xfs_vnodeops.c
8344 --- linux-2.6.36/fs/xfs/xfs_vnodeops.c  2010-10-21 13:07:52.000000000 +0200
8345 +++ linux-2.6.36-vs2.3.0.36.36/fs/xfs/xfs_vnodeops.c    2010-10-21 15:17:26.000000000 +0200
8346 @@ -50,6 +50,78 @@
8347  #include "xfs_vnodeops.h"
8348  #include "xfs_trace.h"
8349  
8350 +
8351 +STATIC void
8352 +xfs_get_inode_flags(
8353 +       xfs_inode_t     *ip)
8354 +{
8355 +       struct inode    *inode = VFS_I(ip);
8356 +       unsigned int    flags = inode->i_flags;
8357 +       unsigned int    vflags = inode->i_vflags;
8358 +
8359 +       if (flags & S_IMMUTABLE)
8360 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
8361 +       else
8362 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
8363 +       if (flags & S_IXUNLINK)
8364 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
8365 +       else
8366 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
8367 +
8368 +       if (vflags & V_BARRIER)
8369 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
8370 +       else
8371 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
8372 +       if (vflags & V_COW)
8373 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
8374 +       else
8375 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
8376 +}
8377 +
8378 +int
8379 +xfs_sync_flags(
8380 +       struct inode            *inode,
8381 +       int                     flags,
8382 +       int                     vflags)
8383 +{
8384 +       struct xfs_inode        *ip = XFS_I(inode);
8385 +       struct xfs_mount        *mp = ip->i_mount;
8386 +       struct xfs_trans        *tp;
8387 +       unsigned int            lock_flags = 0;
8388 +       int                     code;
8389 +
8390 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
8391 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
8392 +       if (code)
8393 +               goto error_out;
8394 +
8395 +       xfs_ilock(ip, XFS_ILOCK_EXCL);
8396 +
8397 +       xfs_trans_ijoin(tp, ip);
8398 +
8399 +       inode->i_flags = flags;
8400 +       inode->i_vflags = vflags;
8401 +       xfs_get_inode_flags(ip);
8402 +
8403 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
8404 +       xfs_ichgtime(ip, XFS_ICHGTIME_CHG);
8405 +
8406 +       XFS_STATS_INC(xs_ig_attrchg);
8407 +
8408 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
8409 +               xfs_trans_set_sync(tp);
8410 +       code = xfs_trans_commit(tp, 0);
8411 +       xfs_iunlock(ip, XFS_ILOCK_EXCL);
8412 +       return code;
8413 +
8414 +error_out:
8415 +       xfs_trans_cancel(tp, 0);
8416 +       if (lock_flags)
8417 +               xfs_iunlock(ip, XFS_ILOCK_EXCL);
8418 +       return code;
8419 +}
8420 +
8421 +
8422  int
8423  xfs_setattr(
8424         struct xfs_inode        *ip,
8425 @@ -65,6 +137,7 @@ xfs_setattr(
8426         uint                    commit_flags=0;
8427         uid_t                   uid=0, iuid=0;
8428         gid_t                   gid=0, igid=0;
8429 +       tag_t                   tag=0, itag=0;
8430         struct xfs_dquot        *udqp, *gdqp, *olddquot1, *olddquot2;
8431         int                     need_iolock = 1;
8432  
8433 @@ -147,7 +220,7 @@ xfs_setattr(
8434         /*
8435          * Change file ownership.  Must be the owner or privileged.
8436          */
8437 -       if (mask & (ATTR_UID|ATTR_GID)) {
8438 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8439                 /*
8440                  * These IDs could have changed since we last looked at them.
8441                  * But, we're assured that if the ownership did change
8442 @@ -156,8 +229,10 @@ xfs_setattr(
8443                  */
8444                 iuid = ip->i_d.di_uid;
8445                 igid = ip->i_d.di_gid;
8446 +               itag = ip->i_d.di_tag;
8447                 gid = (mask & ATTR_GID) ? iattr->ia_gid : igid;
8448                 uid = (mask & ATTR_UID) ? iattr->ia_uid : iuid;
8449 +               tag = (mask & ATTR_TAG) ? iattr->ia_tag : itag;
8450  
8451                 /*
8452                  * Do a quota reservation only if uid/gid is actually
8453 @@ -165,7 +240,8 @@ xfs_setattr(
8454                  */
8455                 if (XFS_IS_QUOTA_RUNNING(mp) &&
8456                     ((XFS_IS_UQUOTA_ON(mp) && iuid != uid) ||
8457 -                    (XFS_IS_GQUOTA_ON(mp) && igid != gid))) {
8458 +                    (XFS_IS_GQUOTA_ON(mp) && igid != gid) ||
8459 +                    (XFS_IS_GQUOTA_ON(mp) && itag != tag))) {
8460                         ASSERT(tp);
8461                         code = xfs_qm_vop_chown_reserve(tp, ip, udqp, gdqp,
8462                                                 capable(CAP_FOWNER) ?
8463 @@ -326,7 +402,7 @@ xfs_setattr(
8464         /*
8465          * Change file ownership.  Must be the owner or privileged.
8466          */
8467 -       if (mask & (ATTR_UID|ATTR_GID)) {
8468 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8469                 /*
8470                  * CAP_FSETID overrides the following restrictions:
8471                  *
8472 @@ -342,6 +418,10 @@ xfs_setattr(
8473                  * Change the ownerships and register quota modifications
8474                  * in the transaction.
8475                  */
8476 +               if (itag != tag) {
8477 +                       ip->i_d.di_tag = tag;
8478 +                       inode->i_tag = tag;
8479 +               }
8480                 if (iuid != uid) {
8481                         if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_UQUOTA_ON(mp)) {
8482                                 ASSERT(mask & ATTR_UID);
8483 diff -NurpP --minimal linux-2.6.36/fs/xfs/xfs_vnodeops.h linux-2.6.36-vs2.3.0.36.36/fs/xfs/xfs_vnodeops.h
8484 --- linux-2.6.36/fs/xfs/xfs_vnodeops.h  2010-07-07 18:31:54.000000000 +0200
8485 +++ linux-2.6.36-vs2.3.0.36.36/fs/xfs/xfs_vnodeops.h    2010-10-21 13:09:36.000000000 +0200
8486 @@ -14,6 +14,7 @@ struct xfs_inode;
8487  struct xfs_iomap;
8488  
8489  
8490 +int xfs_sync_xflags(struct xfs_inode *ip);
8491  int xfs_setattr(struct xfs_inode *ip, struct iattr *vap, int flags);
8492  #define        XFS_ATTR_DMI            0x01    /* invocation from a DMI function */
8493  #define        XFS_ATTR_NONBLOCK       0x02    /* return EAGAIN if operation would block */
8494 diff -NurpP --minimal linux-2.6.36/include/asm-generic/tlb.h linux-2.6.36-vs2.3.0.36.36/include/asm-generic/tlb.h
8495 --- linux-2.6.36/include/asm-generic/tlb.h      2009-09-10 15:26:24.000000000 +0200
8496 +++ linux-2.6.36-vs2.3.0.36.36/include/asm-generic/tlb.h        2010-10-21 13:09:36.000000000 +0200
8497 @@ -14,6 +14,7 @@
8498  #define _ASM_GENERIC__TLB_H
8499  
8500  #include <linux/swap.h>
8501 +#include <linux/vs_memory.h>
8502  #include <asm/pgalloc.h>
8503  #include <asm/tlbflush.h>
8504  
8505 diff -NurpP --minimal linux-2.6.36/include/linux/capability.h linux-2.6.36-vs2.3.0.36.36/include/linux/capability.h
8506 --- linux-2.6.36/include/linux/capability.h     2010-10-21 13:07:52.000000000 +0200
8507 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/capability.h       2010-10-21 13:09:36.000000000 +0200
8508 @@ -280,6 +280,7 @@ struct cpu_vfs_cap_data {
8509     arbitrary SCSI commands */
8510  /* Allow setting encryption key on loopback filesystem */
8511  /* Allow setting zone reclaim policy */
8512 +/* Allow the selection of a security context */
8513  
8514  #define CAP_SYS_ADMIN        21
8515  
8516 @@ -352,7 +353,13 @@ struct cpu_vfs_cap_data {
8517  
8518  #define CAP_MAC_ADMIN        33
8519  
8520 -#define CAP_LAST_CAP         CAP_MAC_ADMIN
8521 +/* Allow context manipulations */
8522 +/* Allow changing context info on files */
8523 +
8524 +#define CAP_CONTEXT         34
8525 +
8526 +
8527 +#define CAP_LAST_CAP         CAP_CONTEXT
8528  
8529  #define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
8530  
8531 diff -NurpP --minimal linux-2.6.36/include/linux/devpts_fs.h linux-2.6.36-vs2.3.0.36.36/include/linux/devpts_fs.h
8532 --- linux-2.6.36/include/linux/devpts_fs.h      2008-12-25 00:26:37.000000000 +0100
8533 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/devpts_fs.h        2010-10-21 13:09:36.000000000 +0200
8534 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
8535  
8536  #endif
8537  
8538 -
8539  #endif /* _LINUX_DEVPTS_FS_H */
8540 diff -NurpP --minimal linux-2.6.36/include/linux/ext2_fs.h linux-2.6.36-vs2.3.0.36.36/include/linux/ext2_fs.h
8541 --- linux-2.6.36/include/linux/ext2_fs.h        2010-02-25 11:52:07.000000000 +0100
8542 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/ext2_fs.h  2010-10-21 13:09:36.000000000 +0200
8543 @@ -189,8 +189,12 @@ struct ext2_group_desc
8544  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
8545  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
8546  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
8547 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
8548  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
8549  
8550 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
8551 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
8552 +
8553  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
8554  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
8555  
8556 @@ -274,7 +278,8 @@ struct ext2_inode {
8557                         __u16   i_pad1;
8558                         __le16  l_i_uid_high;   /* these 2 fields    */
8559                         __le16  l_i_gid_high;   /* were reserved2[0] */
8560 -                       __u32   l_i_reserved2;
8561 +                       __le16  l_i_tag;        /* Context Tag */
8562 +                       __u16   l_i_reserved2;
8563                 } linux2;
8564                 struct {
8565                         __u8    h_i_frag;       /* Fragment number */
8566 @@ -303,6 +308,7 @@ struct ext2_inode {
8567  #define i_gid_low      i_gid
8568  #define i_uid_high     osd2.linux2.l_i_uid_high
8569  #define i_gid_high     osd2.linux2.l_i_gid_high
8570 +#define i_raw_tag      osd2.linux2.l_i_tag
8571  #define i_reserved2    osd2.linux2.l_i_reserved2
8572  #endif
8573  
8574 @@ -347,6 +353,7 @@ struct ext2_inode {
8575  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
8576  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
8577  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
8578 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
8579  
8580  
8581  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
8582 diff -NurpP --minimal linux-2.6.36/include/linux/ext3_fs.h linux-2.6.36-vs2.3.0.36.36/include/linux/ext3_fs.h
8583 --- linux-2.6.36/include/linux/ext3_fs.h        2010-10-21 13:07:53.000000000 +0200
8584 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/ext3_fs.h  2010-10-21 13:09:36.000000000 +0200
8585 @@ -173,10 +173,14 @@ struct ext3_group_desc
8586  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
8587  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
8588  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
8589 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
8590  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
8591  
8592 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
8593 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
8594 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
8595 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
8596 +
8597 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
8598 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
8599  
8600  /* Flags that should be inherited by new inodes from their parent. */
8601  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
8602 @@ -312,7 +316,8 @@ struct ext3_inode {
8603                         __u16   i_pad1;
8604                         __le16  l_i_uid_high;   /* these 2 fields    */
8605                         __le16  l_i_gid_high;   /* were reserved2[0] */
8606 -                       __u32   l_i_reserved2;
8607 +                       __le16  l_i_tag;        /* Context Tag */
8608 +                       __u16   l_i_reserved2;
8609                 } linux2;
8610                 struct {
8611                         __u8    h_i_frag;       /* Fragment number */
8612 @@ -343,6 +348,7 @@ struct ext3_inode {
8613  #define i_gid_low      i_gid
8614  #define i_uid_high     osd2.linux2.l_i_uid_high
8615  #define i_gid_high     osd2.linux2.l_i_gid_high
8616 +#define i_raw_tag      osd2.linux2.l_i_tag
8617  #define i_reserved2    osd2.linux2.l_i_reserved2
8618  
8619  #elif defined(__GNU__)
8620 @@ -405,6 +411,7 @@ struct ext3_inode {
8621  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
8622  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
8623                                                   * error in ordered mode */
8624 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
8625  
8626  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
8627  #ifndef _LINUX_EXT2_FS_H
8628 @@ -908,6 +915,7 @@ extern void ext3_get_inode_flags(struct 
8629  extern void ext3_set_aops(struct inode *inode);
8630  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
8631                        u64 start, u64 len);
8632 +extern int ext3_sync_flags(struct inode *, int, int);
8633  
8634  /* ioctl.c */
8635  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
8636 diff -NurpP --minimal linux-2.6.36/include/linux/fs.h linux-2.6.36-vs2.3.0.36.36/include/linux/fs.h
8637 --- linux-2.6.36/include/linux/fs.h     2010-10-21 13:07:53.000000000 +0200
8638 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/fs.h       2010-10-21 13:09:36.000000000 +0200
8639 @@ -208,6 +208,9 @@ struct inodes_stat_t {
8640  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
8641  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
8642  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
8643 +#define MS_TAGGED      (1<<25) /* use generic inode tagging */
8644 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
8645 +#define MS_NOTAGCHECK  (1<<27) /* don't check tags */
8646  #define MS_BORN                (1<<29)
8647  #define MS_ACTIVE      (1<<30)
8648  #define MS_NOUSER      (1<<31)
8649 @@ -235,6 +238,14 @@ struct inodes_stat_t {
8650  #define S_NOCMTIME     128     /* Do not update file c/mtime */
8651  #define S_SWAPFILE     256     /* Do not truncate: swapon got its bmaps */
8652  #define S_PRIVATE      512     /* Inode is fs-internal */
8653 +#define S_IXUNLINK     1024    /* Immutable Invert on unlink */
8654 +
8655 +/* Linux-VServer related Inode flags */
8656 +
8657 +#define V_VALID                1
8658 +#define V_XATTR                2
8659 +#define V_BARRIER      4       /* Barrier for chroot() */
8660 +#define V_COW          8       /* Copy on Write */
8661  
8662  /*
8663   * Note that nosuid etc flags are inode-specific: setting some file-system
8664 @@ -257,12 +268,15 @@ struct inodes_stat_t {
8665  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
8666                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
8667  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
8668 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8669 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
8670 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8671 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
8672 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
8673  
8674  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
8675  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
8676  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
8677 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
8678 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
8679  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
8680  
8681  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
8682 @@ -270,6 +284,16 @@ struct inodes_stat_t {
8683  #define IS_SWAPFILE(inode)     ((inode)->i_flags & S_SWAPFILE)
8684  #define IS_PRIVATE(inode)      ((inode)->i_flags & S_PRIVATE)
8685  
8686 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
8687 +
8688 +#ifdef CONFIG_VSERVER_COWBL
8689 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
8690 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
8691 +#else
8692 +#  define IS_COW(inode)                (0)
8693 +#  define IS_COW_LINK(inode)   (0)
8694 +#endif
8695 +
8696  /* the read-only stuff doesn't really belong here, but any other place is
8697     probably as bad and I don't want to create yet another include file. */
8698  
8699 @@ -353,11 +377,14 @@ struct inodes_stat_t {
8700  #define FS_TOPDIR_FL                   0x00020000 /* Top of directory hierarchies*/
8701  #define FS_EXTENT_FL                   0x00080000 /* Extents */
8702  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
8703 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
8704  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
8705  
8706 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
8707 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
8708 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
8709 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
8710  
8711 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
8712 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
8713  
8714  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
8715  #define SYNC_FILE_RANGE_WRITE          2
8716 @@ -437,6 +464,7 @@ typedef void (dio_iodone_t)(struct kiocb
8717  #define ATTR_KILL_PRIV (1 << 14)
8718  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
8719  #define ATTR_TIMES_SET (1 << 16)
8720 +#define ATTR_TAG       (1 << 17)
8721  
8722  /*
8723   * This is the Inode Attributes structure, used for notify_change().  It
8724 @@ -452,6 +480,7 @@ struct iattr {
8725         umode_t         ia_mode;
8726         uid_t           ia_uid;
8727         gid_t           ia_gid;
8728 +       tag_t           ia_tag;
8729         loff_t          ia_size;
8730         struct timespec ia_atime;
8731         struct timespec ia_mtime;
8732 @@ -465,6 +494,9 @@ struct iattr {
8733         struct file     *ia_file;
8734  };
8735  
8736 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
8737 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
8738 +
8739  /*
8740   * Includes for diskquotas.
8741   */
8742 @@ -732,7 +764,9 @@ struct inode {
8743         unsigned int            i_nlink;
8744         uid_t                   i_uid;
8745         gid_t                   i_gid;
8746 +       tag_t                   i_tag;
8747         dev_t                   i_rdev;
8748 +       dev_t                   i_mdev;
8749         unsigned int            i_blkbits;
8750         u64                     i_version;
8751         loff_t                  i_size;
8752 @@ -774,7 +808,8 @@ struct inode {
8753         unsigned long           i_state;
8754         unsigned long           dirtied_when;   /* jiffies of first dirtying */
8755  
8756 -       unsigned int            i_flags;
8757 +       unsigned short          i_flags;
8758 +       unsigned short          i_vflags;
8759  
8760         atomic_t                i_writecount;
8761  #ifdef CONFIG_SECURITY
8762 @@ -862,12 +897,12 @@ static inline void i_size_write(struct i
8763  
8764  static inline unsigned iminor(const struct inode *inode)
8765  {
8766 -       return MINOR(inode->i_rdev);
8767 +       return MINOR(inode->i_mdev);
8768  }
8769  
8770  static inline unsigned imajor(const struct inode *inode)
8771  {
8772 -       return MAJOR(inode->i_rdev);
8773 +       return MAJOR(inode->i_mdev);
8774  }
8775  
8776  extern struct block_device *I_BDEV(struct inode *inode);
8777 @@ -929,6 +964,7 @@ struct file {
8778         loff_t                  f_pos;
8779         struct fown_struct      f_owner;
8780         const struct cred       *f_cred;
8781 +       xid_t                   f_xid;
8782         struct file_ra_state    f_ra;
8783  
8784         u64                     f_version;
8785 @@ -1068,6 +1104,7 @@ struct file_lock {
8786         struct file *fl_file;
8787         loff_t fl_start;
8788         loff_t fl_end;
8789 +       xid_t fl_xid;
8790  
8791         struct fasync_struct *  fl_fasync; /* for lease break notifications */
8792         unsigned long fl_break_time;    /* for nonblocking lease breaks */
8793 @@ -1536,6 +1573,7 @@ struct inode_operations {
8794         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
8795         ssize_t (*listxattr) (struct dentry *, char *, size_t);
8796         int (*removexattr) (struct dentry *, const char *);
8797 +       int (*sync_flags) (struct inode *, int, int);
8798         void (*truncate_range)(struct inode *, loff_t, loff_t);
8799         long (*fallocate)(struct inode *inode, int mode, loff_t offset,
8800                           loff_t len);
8801 @@ -1556,6 +1594,7 @@ extern ssize_t vfs_readv(struct file *, 
8802                 unsigned long, loff_t *);
8803  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
8804                 unsigned long, loff_t *);
8805 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
8806  
8807  struct super_operations {
8808         struct inode *(*alloc_inode)(struct super_block *sb);
8809 @@ -2344,6 +2383,7 @@ extern int dcache_dir_open(struct inode 
8810  extern int dcache_dir_close(struct inode *, struct file *);
8811  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
8812  extern int dcache_readdir(struct file *, void *, filldir_t);
8813 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
8814  extern int simple_setattr(struct dentry *, struct iattr *);
8815  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
8816  extern int simple_statfs(struct dentry *, struct kstatfs *);
8817 diff -NurpP --minimal linux-2.6.36/include/linux/gfs2_ondisk.h linux-2.6.36-vs2.3.0.36.36/include/linux/gfs2_ondisk.h
8818 --- linux-2.6.36/include/linux/gfs2_ondisk.h    2010-07-07 18:31:55.000000000 +0200
8819 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/gfs2_ondisk.h      2010-10-21 13:09:36.000000000 +0200
8820 @@ -211,6 +211,9 @@ enum {
8821         gfs2fl_NoAtime          = 7,
8822         gfs2fl_Sync             = 8,
8823         gfs2fl_System           = 9,
8824 +       gfs2fl_IXUnlink         = 16,
8825 +       gfs2fl_Barrier          = 17,
8826 +       gfs2fl_Cow              = 18,
8827         gfs2fl_TruncInProg      = 29,
8828         gfs2fl_InheritDirectio  = 30,
8829         gfs2fl_InheritJdata     = 31,
8830 @@ -227,6 +230,9 @@ enum {
8831  #define GFS2_DIF_NOATIME               0x00000080
8832  #define GFS2_DIF_SYNC                  0x00000100
8833  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
8834 +#define GFS2_DIF_IXUNLINK              0x00010000
8835 +#define GFS2_DIF_BARRIER               0x00020000
8836 +#define GFS2_DIF_COW                   0x00040000
8837  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
8838  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000
8839  #define GFS2_DIF_INHERIT_JDATA         0x80000000
8840 diff -NurpP --minimal linux-2.6.36/include/linux/if_tun.h linux-2.6.36-vs2.3.0.36.36/include/linux/if_tun.h
8841 --- linux-2.6.36/include/linux/if_tun.h 2010-08-02 16:52:54.000000000 +0200
8842 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/if_tun.h   2010-10-21 13:09:36.000000000 +0200
8843 @@ -53,6 +53,7 @@
8844  #define TUNDETACHFILTER _IOW('T', 214, struct sock_fprog)
8845  #define TUNGETVNETHDRSZ _IOR('T', 215, int)
8846  #define TUNSETVNETHDRSZ _IOW('T', 216, int)
8847 +#define TUNSETNID     _IOW('T', 217, int)
8848  
8849  /* TUNSETIFF ifr flags */
8850  #define IFF_TUN                0x0001
8851 diff -NurpP --minimal linux-2.6.36/include/linux/init_task.h linux-2.6.36-vs2.3.0.36.36/include/linux/init_task.h
8852 --- linux-2.6.36/include/linux/init_task.h      2010-08-02 16:52:54.000000000 +0200
8853 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/init_task.h        2010-10-21 13:09:36.000000000 +0200
8854 @@ -172,6 +172,10 @@ extern struct cred init_cred;
8855         INIT_FTRACE_GRAPH                                               \
8856         INIT_TRACE_RECURSION                                            \
8857         INIT_TASK_RCU_PREEMPT(tsk)                                      \
8858 +       .xid            = 0,                                            \
8859 +       .vx_info        = NULL,                                         \
8860 +       .nid            = 0,                                            \
8861 +       .nx_info        = NULL,                                         \
8862  }
8863  
8864  
8865 diff -NurpP --minimal linux-2.6.36/include/linux/ipc.h linux-2.6.36-vs2.3.0.36.36/include/linux/ipc.h
8866 --- linux-2.6.36/include/linux/ipc.h    2009-12-03 20:02:55.000000000 +0100
8867 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/ipc.h      2010-10-21 13:09:36.000000000 +0200
8868 @@ -91,6 +91,7 @@ struct kern_ipc_perm
8869         key_t           key;
8870         uid_t           uid;
8871         gid_t           gid;
8872 +       xid_t           xid;
8873         uid_t           cuid;
8874         gid_t           cgid;
8875         mode_t          mode; 
8876 diff -NurpP --minimal linux-2.6.36/include/linux/Kbuild linux-2.6.36-vs2.3.0.36.36/include/linux/Kbuild
8877 --- linux-2.6.36/include/linux/Kbuild   2010-10-21 13:07:52.000000000 +0200
8878 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/Kbuild     2010-10-21 14:12:01.000000000 +0200
8879 @@ -15,6 +15,7 @@ header-y += netfilter_bridge/
8880  header-y += netfilter_ipv4/
8881  header-y += netfilter_ipv6/
8882  header-y += usb/
8883 +header-y += vserver/
8884  header-y += wimax/
8885  
8886  objhdr-y += version.h
8887 diff -NurpP --minimal linux-2.6.36/include/linux/loop.h linux-2.6.36-vs2.3.0.36.36/include/linux/loop.h
8888 --- linux-2.6.36/include/linux/loop.h   2009-09-10 15:26:25.000000000 +0200
8889 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/loop.h     2010-10-21 13:09:36.000000000 +0200
8890 @@ -45,6 +45,7 @@ struct loop_device {
8891         struct loop_func_table *lo_encryption;
8892         __u32           lo_init[2];
8893         uid_t           lo_key_owner;   /* Who set the key */
8894 +       xid_t           lo_xid;
8895         int             (*ioctl)(struct loop_device *, int cmd, 
8896                                  unsigned long arg); 
8897  
8898 diff -NurpP --minimal linux-2.6.36/include/linux/magic.h linux-2.6.36-vs2.3.0.36.36/include/linux/magic.h
8899 --- linux-2.6.36/include/linux/magic.h  2010-07-07 18:31:55.000000000 +0200
8900 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/magic.h    2010-10-21 13:09:36.000000000 +0200
8901 @@ -3,7 +3,7 @@
8902  
8903  #define ADFS_SUPER_MAGIC       0xadf5
8904  #define AFFS_SUPER_MAGIC       0xadff
8905 -#define AFS_SUPER_MAGIC                0x5346414F
8906 +#define AFS_SUPER_MAGIC                0x5346414F
8907  #define AUTOFS_SUPER_MAGIC     0x0187
8908  #define CODA_SUPER_MAGIC       0x73757245
8909  #define CRAMFS_MAGIC           0x28cd3d45      /* some random number */
8910 @@ -38,6 +38,7 @@
8911  #define NFS_SUPER_MAGIC                0x6969
8912  #define OPENPROM_SUPER_MAGIC   0x9fa1
8913  #define PROC_SUPER_MAGIC       0x9fa0
8914 +#define DEVPTS_SUPER_MAGIC     0x1cd1
8915  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
8916  
8917  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
8918 diff -NurpP --minimal linux-2.6.36/include/linux/major.h linux-2.6.36-vs2.3.0.36.36/include/linux/major.h
8919 --- linux-2.6.36/include/linux/major.h  2009-09-10 15:26:25.000000000 +0200
8920 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/major.h    2010-10-21 13:09:36.000000000 +0200
8921 @@ -15,6 +15,7 @@
8922  #define HD_MAJOR               IDE0_MAJOR
8923  #define PTY_SLAVE_MAJOR                3
8924  #define TTY_MAJOR              4
8925 +#define VROOT_MAJOR            4
8926  #define TTYAUX_MAJOR           5
8927  #define LP_MAJOR               6
8928  #define VCS_MAJOR              7
8929 diff -NurpP --minimal linux-2.6.36/include/linux/memcontrol.h linux-2.6.36-vs2.3.0.36.36/include/linux/memcontrol.h
8930 --- linux-2.6.36/include/linux/memcontrol.h     2010-10-21 13:07:53.000000000 +0200
8931 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/memcontrol.h       2010-10-21 13:09:36.000000000 +0200
8932 @@ -77,6 +77,13 @@ int task_in_mem_cgroup(struct task_struc
8933  extern struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page);
8934  extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
8935  
8936 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
8937 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
8938 +
8939 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
8940 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
8941 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
8942 +
8943  static inline
8944  int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
8945  {
8946 diff -NurpP --minimal linux-2.6.36/include/linux/mm_types.h linux-2.6.36-vs2.3.0.36.36/include/linux/mm_types.h
8947 --- linux-2.6.36/include/linux/mm_types.h       2010-10-21 13:07:53.000000000 +0200
8948 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/mm_types.h 2010-10-21 13:09:36.000000000 +0200
8949 @@ -269,6 +269,7 @@ struct mm_struct {
8950  
8951         /* Architecture-specific MM context */
8952         mm_context_t context;
8953 +       struct vx_info *mm_vx_info;
8954  
8955         /* Swap token stuff */
8956         /*
8957 diff -NurpP --minimal linux-2.6.36/include/linux/mount.h linux-2.6.36-vs2.3.0.36.36/include/linux/mount.h
8958 --- linux-2.6.36/include/linux/mount.h  2010-10-21 13:07:53.000000000 +0200
8959 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/mount.h    2010-10-21 13:09:36.000000000 +0200
8960 @@ -46,6 +46,9 @@ struct mnt_namespace;
8961  
8962  #define MNT_INTERNAL   0x4000
8963  
8964 +#define MNT_TAGID      0x10000
8965 +#define MNT_NOTAG      0x20000
8966 +
8967  struct vfsmount {
8968         struct list_head mnt_hash;
8969         struct vfsmount *mnt_parent;    /* fs we are mounted on */
8970 @@ -84,6 +87,7 @@ struct vfsmount {
8971  #else
8972         int mnt_writers;
8973  #endif
8974 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
8975  };
8976  
8977  static inline int *get_mnt_writers_ptr(struct vfsmount *mnt)
8978 diff -NurpP --minimal linux-2.6.36/include/linux/net.h linux-2.6.36-vs2.3.0.36.36/include/linux/net.h
8979 --- linux-2.6.36/include/linux/net.h    2010-08-02 16:52:55.000000000 +0200
8980 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/net.h      2010-10-21 13:09:36.000000000 +0200
8981 @@ -71,6 +71,7 @@ struct net;
8982  #define SOCK_NOSPACE           2
8983  #define SOCK_PASSCRED          3
8984  #define SOCK_PASSSEC           4
8985 +#define SOCK_USER_SOCKET       5
8986  
8987  #ifndef ARCH_HAS_SOCKET_TYPES
8988  /**
8989 diff -NurpP --minimal linux-2.6.36/include/linux/nfs_mount.h linux-2.6.36-vs2.3.0.36.36/include/linux/nfs_mount.h
8990 --- linux-2.6.36/include/linux/nfs_mount.h      2010-10-21 13:07:54.000000000 +0200
8991 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/nfs_mount.h        2010-10-21 13:09:36.000000000 +0200
8992 @@ -63,7 +63,8 @@ struct nfs_mount_data {
8993  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
8994  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
8995  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
8996 -#define NFS_MOUNT_FLAGMASK     0xFFFF
8997 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
8998 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
8999  
9000  /* The following are for internal use only */
9001  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
9002 diff -NurpP --minimal linux-2.6.36/include/linux/nsproxy.h linux-2.6.36-vs2.3.0.36.36/include/linux/nsproxy.h
9003 --- linux-2.6.36/include/linux/nsproxy.h        2009-06-11 17:13:17.000000000 +0200
9004 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/nsproxy.h  2010-10-21 13:09:36.000000000 +0200
9005 @@ -3,6 +3,7 @@
9006  
9007  #include <linux/spinlock.h>
9008  #include <linux/sched.h>
9009 +#include <linux/vserver/debug.h>
9010  
9011  struct mnt_namespace;
9012  struct uts_namespace;
9013 @@ -63,22 +64,33 @@ static inline struct nsproxy *task_nspro
9014  }
9015  
9016  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
9017 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
9018  void exit_task_namespaces(struct task_struct *tsk);
9019  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
9020  void free_nsproxy(struct nsproxy *ns);
9021  int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
9022         struct fs_struct *);
9023  
9024 -static inline void put_nsproxy(struct nsproxy *ns)
9025 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
9026 +
9027 +static inline void __get_nsproxy(struct nsproxy *ns,
9028 +       const char *_file, int _line)
9029  {
9030 -       if (atomic_dec_and_test(&ns->count)) {
9031 -               free_nsproxy(ns);
9032 -       }
9033 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
9034 +               ns, atomic_read(&ns->count), _file, _line);
9035 +       atomic_inc(&ns->count);
9036  }
9037  
9038 -static inline void get_nsproxy(struct nsproxy *ns)
9039 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
9040 +
9041 +static inline void __put_nsproxy(struct nsproxy *ns,
9042 +       const char *_file, int _line)
9043  {
9044 -       atomic_inc(&ns->count);
9045 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
9046 +               ns, atomic_read(&ns->count), _file, _line);
9047 +       if (atomic_dec_and_test(&ns->count)) {
9048 +               free_nsproxy(ns);
9049 +       }
9050  }
9051  
9052  #ifdef CONFIG_CGROUP_NS
9053 diff -NurpP --minimal linux-2.6.36/include/linux/pid.h linux-2.6.36-vs2.3.0.36.36/include/linux/pid.h
9054 --- linux-2.6.36/include/linux/pid.h    2009-03-24 14:22:43.000000000 +0100
9055 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/pid.h      2010-10-21 13:09:36.000000000 +0200
9056 @@ -8,7 +8,8 @@ enum pid_type
9057         PIDTYPE_PID,
9058         PIDTYPE_PGID,
9059         PIDTYPE_SID,
9060 -       PIDTYPE_MAX
9061 +       PIDTYPE_MAX,
9062 +       PIDTYPE_REALPID
9063  };
9064  
9065  /*
9066 @@ -160,6 +161,7 @@ static inline pid_t pid_nr(struct pid *p
9067  }
9068  
9069  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
9070 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
9071  pid_t pid_vnr(struct pid *pid);
9072  
9073  #define do_each_pid_task(pid, type, task)                              \
9074 diff -NurpP --minimal linux-2.6.36/include/linux/proc_fs.h linux-2.6.36-vs2.3.0.36.36/include/linux/proc_fs.h
9075 --- linux-2.6.36/include/linux/proc_fs.h        2009-12-03 20:02:56.000000000 +0100
9076 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/proc_fs.h  2010-10-21 13:09:36.000000000 +0200
9077 @@ -56,6 +56,7 @@ struct proc_dir_entry {
9078         nlink_t nlink;
9079         uid_t uid;
9080         gid_t gid;
9081 +       int vx_flags;
9082         loff_t size;
9083         const struct inode_operations *proc_iops;
9084         /*
9085 @@ -250,12 +251,18 @@ kclist_add(struct kcore_list *new, void 
9086  extern void kclist_add(struct kcore_list *, void *, size_t, int type);
9087  #endif
9088  
9089 +struct vx_info;
9090 +struct nx_info;
9091 +
9092  union proc_op {
9093         int (*proc_get_link)(struct inode *, struct path *);
9094         int (*proc_read)(struct task_struct *task, char *page);
9095         int (*proc_show)(struct seq_file *m,
9096                 struct pid_namespace *ns, struct pid *pid,
9097                 struct task_struct *task);
9098 +       int (*proc_vs_read)(char *page);
9099 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
9100 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
9101  };
9102  
9103  struct ctl_table_header;
9104 @@ -263,6 +270,7 @@ struct ctl_table;
9105  
9106  struct proc_inode {
9107         struct pid *pid;
9108 +       int vx_flags;
9109         int fd;
9110         union proc_op op;
9111         struct proc_dir_entry *pde;
9112 diff -NurpP --minimal linux-2.6.36/include/linux/quotaops.h linux-2.6.36-vs2.3.0.36.36/include/linux/quotaops.h
9113 --- linux-2.6.36/include/linux/quotaops.h       2010-10-21 13:07:54.000000000 +0200
9114 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/quotaops.h 2010-10-21 13:09:36.000000000 +0200
9115 @@ -8,6 +8,7 @@
9116  #define _LINUX_QUOTAOPS_
9117  
9118  #include <linux/fs.h>
9119 +#include <linux/vs_dlimit.h>
9120  
9121  #define DQUOT_SPACE_WARN       0x1
9122  #define DQUOT_SPACE_RESERVE    0x2
9123 @@ -205,11 +206,12 @@ static inline void dquot_drop(struct ino
9124  
9125  static inline int dquot_alloc_inode(const struct inode *inode)
9126  {
9127 -       return 0;
9128 +       return dl_alloc_inode(inode);
9129  }
9130  
9131  static inline void dquot_free_inode(const struct inode *inode)
9132  {
9133 +       dl_free_inode(inode);
9134  }
9135  
9136  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
9137 @@ -220,6 +222,10 @@ static inline int dquot_transfer(struct 
9138  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
9139                 int flags)
9140  {
9141 +       int ret = 0;
9142 +
9143 +       if ((ret = dl_alloc_space(inode, number)))
9144 +               return ret;
9145         if (!(flags & DQUOT_SPACE_RESERVE))
9146                 inode_add_bytes(inode, number);
9147         return 0;
9148 @@ -230,6 +236,7 @@ static inline void __dquot_free_space(st
9149  {
9150         if (!(flags & DQUOT_SPACE_RESERVE))
9151                 inode_sub_bytes(inode, number);
9152 +       dl_free_space(inode, number);
9153  }
9154  
9155  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
9156 diff -NurpP --minimal linux-2.6.36/include/linux/reboot.h linux-2.6.36-vs2.3.0.36.36/include/linux/reboot.h
9157 --- linux-2.6.36/include/linux/reboot.h 2010-07-07 18:31:56.000000000 +0200
9158 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/reboot.h   2010-10-21 13:09:36.000000000 +0200
9159 @@ -33,6 +33,7 @@
9160  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
9161  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
9162  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
9163 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
9164  
9165  
9166  #ifdef __KERNEL__
9167 diff -NurpP --minimal linux-2.6.36/include/linux/reiserfs_fs.h linux-2.6.36-vs2.3.0.36.36/include/linux/reiserfs_fs.h
9168 --- linux-2.6.36/include/linux/reiserfs_fs.h    2010-10-21 13:07:54.000000000 +0200
9169 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/reiserfs_fs.h      2010-10-21 13:09:36.000000000 +0200
9170 @@ -977,6 +977,11 @@ struct stat_data_v1 {
9171  #define REISERFS_COMPR_FL     FS_COMPR_FL
9172  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
9173  
9174 +/* unfortunately reiserfs sdattr is only 16 bit */
9175 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
9176 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
9177 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
9178 +
9179  /* persistent flags that file inherits from the parent directory */
9180  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
9181                                 REISERFS_SYNC_FL |      \
9182 @@ -986,6 +991,9 @@ struct stat_data_v1 {
9183                                 REISERFS_COMPR_FL |     \
9184                                 REISERFS_NOTAIL_FL )
9185  
9186 +#define REISERFS_FL_USER_VISIBLE       0x80FF
9187 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
9188 +
9189  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
9190     address blocks) */
9191  struct stat_data {
9192 @@ -2071,6 +2079,7 @@ static inline void reiserfs_update_sd(st
9193  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
9194  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
9195  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
9196 +int reiserfs_sync_flags(struct inode *inode, int, int);
9197  
9198  /* namei.c */
9199  void set_de_name_and_namelen(struct reiserfs_dir_entry *de);
9200 diff -NurpP --minimal linux-2.6.36/include/linux/reiserfs_fs_sb.h linux-2.6.36-vs2.3.0.36.36/include/linux/reiserfs_fs_sb.h
9201 --- linux-2.6.36/include/linux/reiserfs_fs_sb.h 2010-02-25 11:52:07.000000000 +0100
9202 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/reiserfs_fs_sb.h   2010-10-21 13:09:36.000000000 +0200
9203 @@ -476,6 +476,7 @@ enum reiserfs_mount_options {
9204         REISERFS_EXPOSE_PRIVROOT,
9205         REISERFS_BARRIER_NONE,
9206         REISERFS_BARRIER_FLUSH,
9207 +       REISERFS_TAGGED,
9208  
9209         /* Actions on error */
9210         REISERFS_ERROR_PANIC,
9211 diff -NurpP --minimal linux-2.6.36/include/linux/sched.h linux-2.6.36-vs2.3.0.36.36/include/linux/sched.h
9212 --- linux-2.6.36/include/linux/sched.h  2010-10-21 13:07:54.000000000 +0200
9213 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/sched.h    2010-10-21 13:09:36.000000000 +0200
9214 @@ -1339,6 +1339,14 @@ struct task_struct {
9215  #endif
9216         seccomp_t seccomp;
9217  
9218 +/* vserver context data */
9219 +       struct vx_info *vx_info;
9220 +       struct nx_info *nx_info;
9221 +
9222 +       xid_t xid;
9223 +       nid_t nid;
9224 +       tag_t tag;
9225 +
9226  /* Thread group tracking */
9227         u32 parent_exec_id;
9228         u32 self_exec_id;
9229 @@ -1573,6 +1581,11 @@ struct pid_namespace;
9230  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
9231                         struct pid_namespace *ns);
9232  
9233 +#include <linux/vserver/base.h>
9234 +#include <linux/vserver/context.h>
9235 +#include <linux/vserver/debug.h>
9236 +#include <linux/vserver/pid.h>
9237 +
9238  static inline pid_t task_pid_nr(struct task_struct *tsk)
9239  {
9240         return tsk->pid;
9241 @@ -1586,7 +1599,8 @@ static inline pid_t task_pid_nr_ns(struc
9242  
9243  static inline pid_t task_pid_vnr(struct task_struct *tsk)
9244  {
9245 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
9246 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
9247 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
9248  }
9249  
9250  
9251 @@ -1599,7 +1613,7 @@ pid_t task_tgid_nr_ns(struct task_struct
9252  
9253  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
9254  {
9255 -       return pid_vnr(task_tgid(tsk));
9256 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
9257  }
9258  
9259  
9260 diff -NurpP --minimal linux-2.6.36/include/linux/shmem_fs.h linux-2.6.36-vs2.3.0.36.36/include/linux/shmem_fs.h
9261 --- linux-2.6.36/include/linux/shmem_fs.h       2010-10-21 13:07:55.000000000 +0200
9262 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/shmem_fs.h 2010-10-21 13:09:36.000000000 +0200
9263 @@ -9,6 +9,9 @@
9264  
9265  #define SHMEM_NR_DIRECT 16
9266  
9267 +#define TMPFS_SUPER_MAGIC      0x01021994
9268 +
9269 +
9270  struct shmem_inode_info {
9271         spinlock_t              lock;
9272         unsigned long           flags;
9273 diff -NurpP --minimal linux-2.6.36/include/linux/stat.h linux-2.6.36-vs2.3.0.36.36/include/linux/stat.h
9274 --- linux-2.6.36/include/linux/stat.h   2008-12-25 00:26:37.000000000 +0100
9275 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/stat.h     2010-10-21 13:09:36.000000000 +0200
9276 @@ -66,6 +66,7 @@ struct kstat {
9277         unsigned int    nlink;
9278         uid_t           uid;
9279         gid_t           gid;
9280 +       tag_t           tag;
9281         dev_t           rdev;
9282         loff_t          size;
9283         struct timespec  atime;
9284 diff -NurpP --minimal linux-2.6.36/include/linux/sunrpc/auth.h linux-2.6.36-vs2.3.0.36.36/include/linux/sunrpc/auth.h
9285 --- linux-2.6.36/include/linux/sunrpc/auth.h    2010-10-21 13:07:55.000000000 +0200
9286 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/sunrpc/auth.h      2010-10-21 13:09:36.000000000 +0200
9287 @@ -25,6 +25,7 @@
9288  struct auth_cred {
9289         uid_t   uid;
9290         gid_t   gid;
9291 +       tag_t   tag;
9292         struct group_info *group_info;
9293         unsigned char machine_cred : 1;
9294  };
9295 diff -NurpP --minimal linux-2.6.36/include/linux/sunrpc/clnt.h linux-2.6.36-vs2.3.0.36.36/include/linux/sunrpc/clnt.h
9296 --- linux-2.6.36/include/linux/sunrpc/clnt.h    2010-10-21 13:07:55.000000000 +0200
9297 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/sunrpc/clnt.h      2010-10-21 13:09:36.000000000 +0200
9298 @@ -49,7 +49,8 @@ struct rpc_clnt {
9299         unsigned int            cl_softrtry : 1,/* soft timeouts */
9300                                 cl_discrtry : 1,/* disconnect before retry */
9301                                 cl_autobind : 1,/* use getport() */
9302 -                               cl_chatty   : 1;/* be verbose */
9303 +                               cl_chatty   : 1,/* be verbose */
9304 +                               cl_tag      : 1;/* context tagging */
9305  
9306         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
9307         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
9308 diff -NurpP --minimal linux-2.6.36/include/linux/syscalls.h linux-2.6.36-vs2.3.0.36.36/include/linux/syscalls.h
9309 --- linux-2.6.36/include/linux/syscalls.h       2010-10-21 13:07:55.000000000 +0200
9310 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/syscalls.h 2010-10-21 13:09:36.000000000 +0200
9311 @@ -478,6 +478,8 @@ asmlinkage long sys_symlink(const char _
9312  asmlinkage long sys_unlink(const char __user *pathname);
9313  asmlinkage long sys_rename(const char __user *oldname,
9314                                 const char __user *newname);
9315 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
9316 +                               umode_t mode);
9317  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
9318  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
9319  
9320 diff -NurpP --minimal linux-2.6.36/include/linux/sysctl.h linux-2.6.36-vs2.3.0.36.36/include/linux/sysctl.h
9321 --- linux-2.6.36/include/linux/sysctl.h 2010-08-02 16:52:56.000000000 +0200
9322 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/sysctl.h   2010-10-21 13:09:36.000000000 +0200
9323 @@ -60,6 +60,7 @@ enum
9324         CTL_ABI=9,              /* Binary emulation */
9325         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
9326         CTL_ARLAN=254,          /* arlan wireless driver */
9327 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
9328         CTL_S390DBF=5677,       /* s390 debug */
9329         CTL_SUNRPC=7249,        /* sunrpc debug */
9330         CTL_PM=9899,            /* frv power management */
9331 @@ -94,6 +95,7 @@ enum
9332  
9333         KERN_PANIC=15,          /* int: panic timeout */
9334         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
9335 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
9336  
9337         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
9338         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
9339 diff -NurpP --minimal linux-2.6.36/include/linux/sysfs.h linux-2.6.36-vs2.3.0.36.36/include/linux/sysfs.h
9340 --- linux-2.6.36/include/linux/sysfs.h  2010-10-21 13:07:55.000000000 +0200
9341 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/sysfs.h    2010-10-21 13:09:36.000000000 +0200
9342 @@ -19,6 +19,8 @@
9343  #include <linux/kobject_ns.h>
9344  #include <asm/atomic.h>
9345  
9346 +#define SYSFS_SUPER_MAGIC      0x62656572
9347 +
9348  struct kobject;
9349  struct module;
9350  enum kobj_ns_type;
9351 diff -NurpP --minimal linux-2.6.36/include/linux/time.h linux-2.6.36-vs2.3.0.36.36/include/linux/time.h
9352 --- linux-2.6.36/include/linux/time.h   2010-10-21 13:07:55.000000000 +0200
9353 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/time.h     2010-10-21 13:09:36.000000000 +0200
9354 @@ -252,6 +252,9 @@ static __always_inline void timespec_add
9355         a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
9356         a->tv_nsec = ns;
9357  }
9358 +
9359 +#include <linux/vs_time.h>
9360 +
9361  #endif /* __KERNEL__ */
9362  
9363  #define NFDBITS                        __NFDBITS
9364 diff -NurpP --minimal linux-2.6.36/include/linux/types.h linux-2.6.36-vs2.3.0.36.36/include/linux/types.h
9365 --- linux-2.6.36/include/linux/types.h  2010-10-21 13:07:55.000000000 +0200
9366 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/types.h    2010-10-21 13:09:36.000000000 +0200
9367 @@ -40,6 +40,9 @@ typedef __kernel_uid32_t      uid_t;
9368  typedef __kernel_gid32_t       gid_t;
9369  typedef __kernel_uid16_t        uid16_t;
9370  typedef __kernel_gid16_t        gid16_t;
9371 +typedef unsigned int           xid_t;
9372 +typedef unsigned int           nid_t;
9373 +typedef unsigned int           tag_t;
9374  
9375  typedef unsigned long          uintptr_t;
9376  
9377 diff -NurpP --minimal linux-2.6.36/include/linux/vroot.h linux-2.6.36-vs2.3.0.36.36/include/linux/vroot.h
9378 --- linux-2.6.36/include/linux/vroot.h  1970-01-01 01:00:00.000000000 +0100
9379 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vroot.h    2010-10-21 13:09:36.000000000 +0200
9380 @@ -0,0 +1,51 @@
9381 +
9382 +/*
9383 + * include/linux/vroot.h
9384 + *
9385 + * written by Herbert Pötzl, 9/11/2002
9386 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
9387 + *
9388 + * Copyright (C) 2002-2007 by Herbert Pötzl.
9389 + * Redistribution of this file is permitted under the
9390 + * GNU General Public License.
9391 + */
9392 +
9393 +#ifndef _LINUX_VROOT_H
9394 +#define _LINUX_VROOT_H
9395 +
9396 +
9397 +#ifdef __KERNEL__
9398 +
9399 +/* Possible states of device */
9400 +enum {
9401 +       Vr_unbound,
9402 +       Vr_bound,
9403 +};
9404 +
9405 +struct vroot_device {
9406 +       int             vr_number;
9407 +       int             vr_refcnt;
9408 +
9409 +       struct semaphore        vr_ctl_mutex;
9410 +       struct block_device    *vr_device;
9411 +       int                     vr_state;
9412 +};
9413 +
9414 +
9415 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
9416 +
9417 +extern int register_vroot_grb(vroot_grb_func *);
9418 +extern int unregister_vroot_grb(vroot_grb_func *);
9419 +
9420 +#endif /* __KERNEL__ */
9421 +
9422 +#define MAX_VROOT_DEFAULT      8
9423 +
9424 +/*
9425 + * IOCTL commands --- we will commandeer 0x56 ('V')
9426 + */
9427 +
9428 +#define VROOT_SET_DEV          0x5600
9429 +#define VROOT_CLR_DEV          0x5601
9430 +
9431 +#endif /* _LINUX_VROOT_H */
9432 diff -NurpP --minimal linux-2.6.36/include/linux/vs_base.h linux-2.6.36-vs2.3.0.36.36/include/linux/vs_base.h
9433 --- linux-2.6.36/include/linux/vs_base.h        1970-01-01 01:00:00.000000000 +0100
9434 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vs_base.h  2010-10-21 13:09:36.000000000 +0200
9435 @@ -0,0 +1,10 @@
9436 +#ifndef _VS_BASE_H
9437 +#define _VS_BASE_H
9438 +
9439 +#include "vserver/base.h"
9440 +#include "vserver/check.h"
9441 +#include "vserver/debug.h"
9442 +
9443 +#else
9444 +#warning duplicate inclusion
9445 +#endif
9446 diff -NurpP --minimal linux-2.6.36/include/linux/vs_context.h linux-2.6.36-vs2.3.0.36.36/include/linux/vs_context.h
9447 --- linux-2.6.36/include/linux/vs_context.h     1970-01-01 01:00:00.000000000 +0100
9448 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vs_context.h       2010-10-21 13:09:36.000000000 +0200
9449 @@ -0,0 +1,242 @@
9450 +#ifndef _VS_CONTEXT_H
9451 +#define _VS_CONTEXT_H
9452 +
9453 +#include "vserver/base.h"
9454 +#include "vserver/check.h"
9455 +#include "vserver/context.h"
9456 +#include "vserver/history.h"
9457 +#include "vserver/debug.h"
9458 +
9459 +#include <linux/sched.h>
9460 +
9461 +
9462 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
9463 +
9464 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
9465 +       const char *_file, int _line, void *_here)
9466 +{
9467 +       if (!vxi)
9468 +               return NULL;
9469 +
9470 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
9471 +               vxi, vxi ? vxi->vx_id : 0,
9472 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9473 +               _file, _line);
9474 +       __vxh_get_vx_info(vxi, _here);
9475 +
9476 +       atomic_inc(&vxi->vx_usecnt);
9477 +       return vxi;
9478 +}
9479 +
9480 +
9481 +extern void free_vx_info(struct vx_info *);
9482 +
9483 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
9484 +
9485 +static inline void __put_vx_info(struct vx_info *vxi,
9486 +       const char *_file, int _line, void *_here)
9487 +{
9488 +       if (!vxi)
9489 +               return;
9490 +
9491 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
9492 +               vxi, vxi ? vxi->vx_id : 0,
9493 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9494 +               _file, _line);
9495 +       __vxh_put_vx_info(vxi, _here);
9496 +
9497 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
9498 +               free_vx_info(vxi);
9499 +}
9500 +
9501 +
9502 +#define init_vx_info(p, i) \
9503 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9504 +
9505 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9506 +       const char *_file, int _line, void *_here)
9507 +{
9508 +       if (vxi) {
9509 +               vxlprintk(VXD_CBIT(xid, 3),
9510 +                       "init_vx_info(%p[#%d.%d])",
9511 +                       vxi, vxi ? vxi->vx_id : 0,
9512 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9513 +                       _file, _line);
9514 +               __vxh_init_vx_info(vxi, vxp, _here);
9515 +
9516 +               atomic_inc(&vxi->vx_usecnt);
9517 +       }
9518 +       *vxp = vxi;
9519 +}
9520 +
9521 +
9522 +#define set_vx_info(p, i) \
9523 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9524 +
9525 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9526 +       const char *_file, int _line, void *_here)
9527 +{
9528 +       struct vx_info *vxo;
9529 +
9530 +       if (!vxi)
9531 +               return;
9532 +
9533 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
9534 +               vxi, vxi ? vxi->vx_id : 0,
9535 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9536 +               _file, _line);
9537 +       __vxh_set_vx_info(vxi, vxp, _here);
9538 +
9539 +       atomic_inc(&vxi->vx_usecnt);
9540 +       vxo = xchg(vxp, vxi);
9541 +       BUG_ON(vxo);
9542 +}
9543 +
9544 +
9545 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
9546 +
9547 +static inline void __clr_vx_info(struct vx_info **vxp,
9548 +       const char *_file, int _line, void *_here)
9549 +{
9550 +       struct vx_info *vxo;
9551 +
9552 +       vxo = xchg(vxp, NULL);
9553 +       if (!vxo)
9554 +               return;
9555 +
9556 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
9557 +               vxo, vxo ? vxo->vx_id : 0,
9558 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
9559 +               _file, _line);
9560 +       __vxh_clr_vx_info(vxo, vxp, _here);
9561 +
9562 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
9563 +               free_vx_info(vxo);
9564 +}
9565 +
9566 +
9567 +#define claim_vx_info(v, p) \
9568 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9569 +
9570 +static inline void __claim_vx_info(struct vx_info *vxi,
9571 +       struct task_struct *task,
9572 +       const char *_file, int _line, void *_here)
9573 +{
9574 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
9575 +               vxi, vxi ? vxi->vx_id : 0,
9576 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9577 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9578 +               task, _file, _line);
9579 +       __vxh_claim_vx_info(vxi, task, _here);
9580 +
9581 +       atomic_inc(&vxi->vx_tasks);
9582 +}
9583 +
9584 +
9585 +extern void unhash_vx_info(struct vx_info *);
9586 +
9587 +#define release_vx_info(v, p) \
9588 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9589 +
9590 +static inline void __release_vx_info(struct vx_info *vxi,
9591 +       struct task_struct *task,
9592 +       const char *_file, int _line, void *_here)
9593 +{
9594 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
9595 +               vxi, vxi ? vxi->vx_id : 0,
9596 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9597 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9598 +               task, _file, _line);
9599 +       __vxh_release_vx_info(vxi, task, _here);
9600 +
9601 +       might_sleep();
9602 +
9603 +       if (atomic_dec_and_test(&vxi->vx_tasks))
9604 +               unhash_vx_info(vxi);
9605 +}
9606 +
9607 +
9608 +#define task_get_vx_info(p) \
9609 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
9610 +
9611 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
9612 +       const char *_file, int _line, void *_here)
9613 +{
9614 +       struct vx_info *vxi;
9615 +
9616 +       task_lock(p);
9617 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
9618 +               p, _file, _line);
9619 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
9620 +       task_unlock(p);
9621 +       return vxi;
9622 +}
9623 +
9624 +
9625 +static inline void __wakeup_vx_info(struct vx_info *vxi)
9626 +{
9627 +       if (waitqueue_active(&vxi->vx_wait))
9628 +               wake_up_interruptible(&vxi->vx_wait);
9629 +}
9630 +
9631 +
9632 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
9633 +
9634 +static inline void __enter_vx_info(struct vx_info *vxi,
9635 +       struct vx_info_save *vxis, const char *_file, int _line)
9636 +{
9637 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
9638 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
9639 +               current->xid, current->vx_info, _file, _line);
9640 +       vxis->vxi = xchg(&current->vx_info, vxi);
9641 +       vxis->xid = current->xid;
9642 +       current->xid = vxi ? vxi->vx_id : 0;
9643 +}
9644 +
9645 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
9646 +
9647 +static inline void __leave_vx_info(struct vx_info_save *vxis,
9648 +       const char *_file, int _line)
9649 +{
9650 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
9651 +               vxis, vxis->xid, vxis->vxi, current,
9652 +               current->xid, current->vx_info, _file, _line);
9653 +       (void)xchg(&current->vx_info, vxis->vxi);
9654 +       current->xid = vxis->xid;
9655 +}
9656 +
9657 +
9658 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
9659 +{
9660 +       vxis->vxi = xchg(&current->vx_info, NULL);
9661 +       vxis->xid = xchg(&current->xid, (xid_t)0);
9662 +}
9663 +
9664 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
9665 +{
9666 +       (void)xchg(&current->xid, vxis->xid);
9667 +       (void)xchg(&current->vx_info, vxis->vxi);
9668 +}
9669 +
9670 +#define task_is_init(p) \
9671 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
9672 +
9673 +static inline int __task_is_init(struct task_struct *p,
9674 +       const char *_file, int _line, void *_here)
9675 +{
9676 +       int is_init = is_global_init(p);
9677 +
9678 +       task_lock(p);
9679 +       if (p->vx_info)
9680 +               is_init = p->vx_info->vx_initpid == p->pid;
9681 +       task_unlock(p);
9682 +       return is_init;
9683 +}
9684 +
9685 +extern void exit_vx_info(struct task_struct *, int);
9686 +extern void exit_vx_info_early(struct task_struct *, int);
9687 +
9688 +
9689 +#else
9690 +#warning duplicate inclusion
9691 +#endif
9692 diff -NurpP --minimal linux-2.6.36/include/linux/vs_cowbl.h linux-2.6.36-vs2.3.0.36.36/include/linux/vs_cowbl.h
9693 --- linux-2.6.36/include/linux/vs_cowbl.h       1970-01-01 01:00:00.000000000 +0100
9694 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vs_cowbl.h 2010-10-21 13:09:36.000000000 +0200
9695 @@ -0,0 +1,48 @@
9696 +#ifndef _VS_COWBL_H
9697 +#define _VS_COWBL_H
9698 +
9699 +#include <linux/fs.h>
9700 +#include <linux/dcache.h>
9701 +#include <linux/namei.h>
9702 +#include <linux/slab.h>
9703 +
9704 +extern struct dentry *cow_break_link(const char *pathname);
9705 +
9706 +static inline int cow_check_and_break(struct path *path)
9707 +{
9708 +       struct inode *inode = path->dentry->d_inode;
9709 +       int error = 0;
9710 +
9711 +       /* do we need this check? */
9712 +       if (IS_RDONLY(inode))
9713 +               return -EROFS;
9714 +
9715 +       if (IS_COW(inode)) {
9716 +               if (IS_COW_LINK(inode)) {
9717 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
9718 +                       char *pp, *buf;
9719 +
9720 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
9721 +                       if (!buf) {
9722 +                               return -ENOMEM;
9723 +                       }
9724 +                       pp = d_path(path, buf, PATH_MAX);
9725 +                       new_dentry = cow_break_link(pp);
9726 +                       kfree(buf);
9727 +                       if (!IS_ERR(new_dentry)) {
9728 +                               path->dentry = new_dentry;
9729 +                               dput(old_dentry);
9730 +                       } else
9731 +                               error = PTR_ERR(new_dentry);
9732 +               } else {
9733 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
9734 +                       inode->i_ctime = CURRENT_TIME;
9735 +                       mark_inode_dirty(inode);
9736 +               }
9737 +       }
9738 +       return error;
9739 +}
9740 +
9741 +#else
9742 +#warning duplicate inclusion
9743 +#endif
9744 diff -NurpP --minimal linux-2.6.36/include/linux/vs_cvirt.h linux-2.6.36-vs2.3.0.36.36/include/linux/vs_cvirt.h
9745 --- linux-2.6.36/include/linux/vs_cvirt.h       1970-01-01 01:00:00.000000000 +0100
9746 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vs_cvirt.h 2010-10-21 13:09:36.000000000 +0200
9747 @@ -0,0 +1,50 @@
9748 +#ifndef _VS_CVIRT_H
9749 +#define _VS_CVIRT_H
9750 +
9751 +#include "vserver/cvirt.h"
9752 +#include "vserver/context.h"
9753 +#include "vserver/base.h"
9754 +#include "vserver/check.h"
9755 +#include "vserver/debug.h"
9756 +
9757 +
9758 +static inline void vx_activate_task(struct task_struct *p)
9759 +{
9760 +       struct vx_info *vxi;
9761 +
9762 +       if ((vxi = p->vx_info)) {
9763 +               vx_update_load(vxi);
9764 +               atomic_inc(&vxi->cvirt.nr_running);
9765 +       }
9766 +}
9767 +
9768 +static inline void vx_deactivate_task(struct task_struct *p)
9769 +{
9770 +       struct vx_info *vxi;
9771 +
9772 +       if ((vxi = p->vx_info)) {
9773 +               vx_update_load(vxi);
9774 +               atomic_dec(&vxi->cvirt.nr_running);
9775 +       }
9776 +}
9777 +
9778 +static inline void vx_uninterruptible_inc(struct task_struct *p)
9779 +{
9780 +       struct vx_info *vxi;
9781 +
9782 +       if ((vxi = p->vx_info))
9783 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
9784 +}
9785 +
9786 +static inline void vx_uninterruptible_dec(struct task_struct *p)
9787 +{
9788 +       struct vx_info *vxi;
9789 +
9790 +       if ((vxi = p->vx_info))
9791 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
9792 +}
9793 +
9794 +
9795 +#else
9796 +#warning duplicate inclusion
9797 +#endif
9798 diff -NurpP --minimal linux-2.6.36/include/linux/vs_device.h linux-2.6.36-vs2.3.0.36.36/include/linux/vs_device.h
9799 --- linux-2.6.36/include/linux/vs_device.h      1970-01-01 01:00:00.000000000 +0100
9800 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vs_device.h        2010-10-21 13:09:36.000000000 +0200
9801 @@ -0,0 +1,45 @@
9802 +#ifndef _VS_DEVICE_H
9803 +#define _VS_DEVICE_H
9804 +
9805 +#include "vserver/base.h"
9806 +#include "vserver/device.h"
9807 +#include "vserver/debug.h"
9808 +
9809 +
9810 +#ifdef CONFIG_VSERVER_DEVICE
9811 +
9812 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
9813 +
9814 +#define vs_device_perm(v, d, m, p) \
9815 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
9816 +
9817 +#else
9818 +
9819 +static inline
9820 +int vs_map_device(struct vx_info *vxi,
9821 +       dev_t device, dev_t *target, umode_t mode)
9822 +{
9823 +       if (target)
9824 +               *target = device;
9825 +       return ~0;
9826 +}
9827 +
9828 +#define vs_device_perm(v, d, m, p) ((p) == (p))
9829 +
9830 +#endif
9831 +
9832 +
9833 +#define vs_map_chrdev(d, t, p) \
9834 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
9835 +#define vs_map_blkdev(d, t, p) \
9836 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
9837 +
9838 +#define vs_chrdev_perm(d, p) \
9839 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
9840 +#define vs_blkdev_perm(d, p) \
9841 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
9842 +
9843 +
9844 +#else
9845 +#warning duplicate inclusion
9846 +#endif
9847 diff -NurpP --minimal linux-2.6.36/include/linux/vs_dlimit.h linux-2.6.36-vs2.3.0.36.36/include/linux/vs_dlimit.h
9848 --- linux-2.6.36/include/linux/vs_dlimit.h      1970-01-01 01:00:00.000000000 +0100
9849 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vs_dlimit.h        2010-10-21 13:09:36.000000000 +0200
9850 @@ -0,0 +1,215 @@
9851 +#ifndef _VS_DLIMIT_H
9852 +#define _VS_DLIMIT_H
9853 +
9854 +#include <linux/fs.h>
9855 +
9856 +#include "vserver/dlimit.h"
9857 +#include "vserver/base.h"
9858 +#include "vserver/debug.h"
9859 +
9860 +
9861 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
9862 +
9863 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
9864 +       const char *_file, int _line)
9865 +{
9866 +       if (!dli)
9867 +               return NULL;
9868 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
9869 +               dli, dli ? dli->dl_tag : 0,
9870 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9871 +               _file, _line);
9872 +       atomic_inc(&dli->dl_usecnt);
9873 +       return dli;
9874 +}
9875 +
9876 +
9877 +#define free_dl_info(i) \
9878 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
9879 +
9880 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
9881 +
9882 +static inline void __put_dl_info(struct dl_info *dli,
9883 +       const char *_file, int _line)
9884 +{
9885 +       if (!dli)
9886 +               return;
9887 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
9888 +               dli, dli ? dli->dl_tag : 0,
9889 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9890 +               _file, _line);
9891 +       if (atomic_dec_and_test(&dli->dl_usecnt))
9892 +               free_dl_info(dli);
9893 +}
9894 +
9895 +
9896 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
9897 +
9898 +static inline int __dl_alloc_space(struct super_block *sb,
9899 +       tag_t tag, dlsize_t nr, const char *file, int line)
9900 +{
9901 +       struct dl_info *dli = NULL;
9902 +       int ret = 0;
9903 +
9904 +       if (nr == 0)
9905 +               goto out;
9906 +       dli = locate_dl_info(sb, tag);
9907 +       if (!dli)
9908 +               goto out;
9909 +
9910 +       spin_lock(&dli->dl_lock);
9911 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
9912 +       if (!ret)
9913 +               dli->dl_space_used += nr;
9914 +       spin_unlock(&dli->dl_lock);
9915 +       put_dl_info(dli);
9916 +out:
9917 +       vxlprintk(VXD_CBIT(dlim, 1),
9918 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
9919 +               sb, tag, __dlimit_char(dli), (long long)nr,
9920 +               ret, file, line);
9921 +       return ret ? -ENOSPC : 0;
9922 +}
9923 +
9924 +static inline void __dl_free_space(struct super_block *sb,
9925 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
9926 +{
9927 +       struct dl_info *dli = NULL;
9928 +
9929 +       if (nr == 0)
9930 +               goto out;
9931 +       dli = locate_dl_info(sb, tag);
9932 +       if (!dli)
9933 +               goto out;
9934 +
9935 +       spin_lock(&dli->dl_lock);
9936 +       if (dli->dl_space_used > nr)
9937 +               dli->dl_space_used -= nr;
9938 +       else
9939 +               dli->dl_space_used = 0;
9940 +       spin_unlock(&dli->dl_lock);
9941 +       put_dl_info(dli);
9942 +out:
9943 +       vxlprintk(VXD_CBIT(dlim, 1),
9944 +               "FREE  (%p,#%d)%c %lld bytes",
9945 +               sb, tag, __dlimit_char(dli), (long long)nr,
9946 +               _file, _line);
9947 +}
9948 +
9949 +static inline int __dl_alloc_inode(struct super_block *sb,
9950 +       tag_t tag, const char *_file, int _line)
9951 +{
9952 +       struct dl_info *dli;
9953 +       int ret = 0;
9954 +
9955 +       dli = locate_dl_info(sb, tag);
9956 +       if (!dli)
9957 +               goto out;
9958 +
9959 +       spin_lock(&dli->dl_lock);
9960 +       dli->dl_inodes_used++;
9961 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
9962 +       spin_unlock(&dli->dl_lock);
9963 +       put_dl_info(dli);
9964 +out:
9965 +       vxlprintk(VXD_CBIT(dlim, 0),
9966 +               "ALLOC (%p,#%d)%c inode (%d)",
9967 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
9968 +       return ret ? -ENOSPC : 0;
9969 +}
9970 +
9971 +static inline void __dl_free_inode(struct super_block *sb,
9972 +       tag_t tag, const char *_file, int _line)
9973 +{
9974 +       struct dl_info *dli;
9975 +
9976 +       dli = locate_dl_info(sb, tag);
9977 +       if (!dli)
9978 +               goto out;
9979 +
9980 +       spin_lock(&dli->dl_lock);
9981 +       if (dli->dl_inodes_used > 1)
9982 +               dli->dl_inodes_used--;
9983 +       else
9984 +               dli->dl_inodes_used = 0;
9985 +       spin_unlock(&dli->dl_lock);
9986 +       put_dl_info(dli);
9987 +out:
9988 +       vxlprintk(VXD_CBIT(dlim, 0),
9989 +               "FREE  (%p,#%d)%c inode",
9990 +               sb, tag, __dlimit_char(dli), _file, _line);
9991 +}
9992 +
9993 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
9994 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
9995 +       const char *_file, int _line)
9996 +{
9997 +       struct dl_info *dli;
9998 +       uint64_t broot, bfree;
9999 +
10000 +       dli = locate_dl_info(sb, tag);
10001 +       if (!dli)
10002 +               return;
10003 +
10004 +       spin_lock(&dli->dl_lock);
10005 +       broot = (dli->dl_space_total -
10006 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
10007 +               >> sb->s_blocksize_bits;
10008 +       bfree = (dli->dl_space_total - dli->dl_space_used)
10009 +                       >> sb->s_blocksize_bits;
10010 +       spin_unlock(&dli->dl_lock);
10011 +
10012 +       vxlprintk(VXD_CBIT(dlim, 2),
10013 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
10014 +               (long long)bfree, (long long)broot,
10015 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
10016 +               _file, _line);
10017 +       if (free_blocks) {
10018 +               if (*free_blocks > bfree)
10019 +                       *free_blocks = bfree;
10020 +       }
10021 +       if (root_blocks) {
10022 +               if (*root_blocks > broot)
10023 +                       *root_blocks = broot;
10024 +       }
10025 +       put_dl_info(dli);
10026 +}
10027 +
10028 +#define dl_prealloc_space(in, bytes) \
10029 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10030 +               __FILE__, __LINE__ )
10031 +
10032 +#define dl_alloc_space(in, bytes) \
10033 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10034 +               __FILE__, __LINE__ )
10035 +
10036 +#define dl_reserve_space(in, bytes) \
10037 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10038 +               __FILE__, __LINE__ )
10039 +
10040 +#define dl_claim_space(in, bytes) (0)
10041 +
10042 +#define dl_release_space(in, bytes) \
10043 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10044 +               __FILE__, __LINE__ )
10045 +
10046 +#define dl_free_space(in, bytes) \
10047 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10048 +               __FILE__, __LINE__ )
10049 +
10050 +
10051 +
10052 +#define dl_alloc_inode(in) \
10053 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10054 +
10055 +#define dl_free_inode(in) \
10056 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10057 +
10058 +
10059 +#define dl_adjust_block(sb, tag, fb, rb) \
10060 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
10061 +
10062 +
10063 +#else
10064 +#warning duplicate inclusion
10065 +#endif
10066 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/base.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/base.h
10067 --- linux-2.6.36/include/linux/vserver/base.h   1970-01-01 01:00:00.000000000 +0100
10068 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/base.h     2010-10-21 13:09:36.000000000 +0200
10069 @@ -0,0 +1,170 @@
10070 +#ifndef _VX_BASE_H
10071 +#define _VX_BASE_H
10072 +
10073 +
10074 +/* context state changes */
10075 +
10076 +enum {
10077 +       VSC_STARTUP = 1,
10078 +       VSC_SHUTDOWN,
10079 +
10080 +       VSC_NETUP,
10081 +       VSC_NETDOWN,
10082 +};
10083 +
10084 +
10085 +
10086 +#define vx_task_xid(t) ((t)->xid)
10087 +
10088 +#define vx_current_xid() vx_task_xid(current)
10089 +
10090 +#define current_vx_info() (current->vx_info)
10091 +
10092 +
10093 +#define nx_task_nid(t) ((t)->nid)
10094 +
10095 +#define nx_current_nid() nx_task_nid(current)
10096 +
10097 +#define current_nx_info() (current->nx_info)
10098 +
10099 +
10100 +/* generic flag merging */
10101 +
10102 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10103 +
10104 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10105 +
10106 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10107 +
10108 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10109 +
10110 +
10111 +/* context flags */
10112 +
10113 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10114 +
10115 +#define vx_current_flags()     __vx_flags(current_vx_info())
10116 +
10117 +#define vx_info_flags(v, m, f) \
10118 +       vs_check_flags(__vx_flags(v), m, f)
10119 +
10120 +#define task_vx_flags(t, m, f) \
10121 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10122 +
10123 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10124 +
10125 +
10126 +/* context caps */
10127 +
10128 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10129 +
10130 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
10131 +
10132 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10133 +
10134 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
10135 +
10136 +
10137 +
10138 +/* network flags */
10139 +
10140 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10141 +
10142 +#define nx_current_flags()     __nx_flags(current_nx_info())
10143 +
10144 +#define nx_info_flags(n, m, f) \
10145 +       vs_check_flags(__nx_flags(n), m, f)
10146 +
10147 +#define task_nx_flags(t, m, f) \
10148 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10149 +
10150 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10151 +
10152 +
10153 +/* network caps */
10154 +
10155 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10156 +
10157 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
10158 +
10159 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10160 +
10161 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
10162 +
10163 +
10164 +/* context mask capabilities */
10165 +
10166 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10167 +
10168 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10169 +
10170 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
10171 +
10172 +
10173 +/* context bcap mask */
10174 +
10175 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10176 +
10177 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
10178 +
10179 +
10180 +/* mask given bcaps */
10181 +
10182 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10183 +
10184 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
10185 +
10186 +
10187 +/* masked cap_bset */
10188 +
10189 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10190 +
10191 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
10192 +
10193 +#if 0
10194 +#define vx_info_mbcap(v, b) \
10195 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10196 +       vx_info_bcaps(v, b) : (b))
10197 +
10198 +#define task_vx_mbcap(t, b) \
10199 +       vx_info_mbcap((t)->vx_info, (t)->b)
10200 +
10201 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10202 +#endif
10203 +
10204 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10205 +
10206 +#define vx_capable(b, c) (capable(b) || \
10207 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10208 +
10209 +#define nx_capable(b, c) (capable(b) || \
10210 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10211 +
10212 +#define vx_task_initpid(t, n) \
10213 +       ((t)->vx_info && \
10214 +       ((t)->vx_info->vx_initpid == (n)))
10215 +
10216 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
10217 +
10218 +
10219 +/* context unshare mask */
10220 +
10221 +#define __vx_umask(v)          ((v)->vx_umask)
10222 +
10223 +#define vx_current_umask()     __vx_umask(current_vx_info())
10224 +
10225 +#define vx_can_unshare(b, f) (capable(b) || \
10226 +       (cap_raised(current_cap(), b) && \
10227 +       !((f) & ~vx_current_umask())))
10228 +
10229 +
10230 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10231 +
10232 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10233 +
10234 +
10235 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10236 +
10237 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10238 +
10239 +#endif
10240 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/cacct_cmd.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/cacct_cmd.h
10241 --- linux-2.6.36/include/linux/vserver/cacct_cmd.h      1970-01-01 01:00:00.000000000 +0100
10242 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/cacct_cmd.h        2010-10-21 13:09:36.000000000 +0200
10243 @@ -0,0 +1,23 @@
10244 +#ifndef _VX_CACCT_CMD_H
10245 +#define _VX_CACCT_CMD_H
10246 +
10247 +
10248 +/* virtual host info name commands */
10249 +
10250 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
10251 +
10252 +struct vcmd_sock_stat_v0 {
10253 +       uint32_t field;
10254 +       uint32_t count[3];
10255 +       uint64_t total[3];
10256 +};
10257 +
10258 +
10259 +#ifdef __KERNEL__
10260 +
10261 +#include <linux/compiler.h>
10262 +
10263 +extern int vc_sock_stat(struct vx_info *, void __user *);
10264 +
10265 +#endif /* __KERNEL__ */
10266 +#endif /* _VX_CACCT_CMD_H */
10267 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/cacct_def.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/cacct_def.h
10268 --- linux-2.6.36/include/linux/vserver/cacct_def.h      1970-01-01 01:00:00.000000000 +0100
10269 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/cacct_def.h        2010-10-21 13:09:36.000000000 +0200
10270 @@ -0,0 +1,43 @@
10271 +#ifndef _VX_CACCT_DEF_H
10272 +#define _VX_CACCT_DEF_H
10273 +
10274 +#include <asm/atomic.h>
10275 +#include <linux/vserver/cacct.h>
10276 +
10277 +
10278 +struct _vx_sock_acc {
10279 +       atomic_long_t count;
10280 +       atomic_long_t total;
10281 +};
10282 +
10283 +/* context sub struct */
10284 +
10285 +struct _vx_cacct {
10286 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10287 +       atomic_t slab[8];
10288 +       atomic_t page[6][8];
10289 +};
10290 +
10291 +#ifdef CONFIG_VSERVER_DEBUG
10292 +
10293 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10294 +{
10295 +       int i, j;
10296 +
10297 +       printk("\t_vx_cacct:");
10298 +       for (i = 0; i < 6; i++) {
10299 +               struct _vx_sock_acc *ptr = cacct->sock[i];
10300 +
10301 +               printk("\t [%d] =", i);
10302 +               for (j = 0; j < 3; j++) {
10303 +                       printk(" [%d] = %8lu, %8lu", j,
10304 +                               atomic_long_read(&ptr[j].count),
10305 +                               atomic_long_read(&ptr[j].total));
10306 +               }
10307 +               printk("\n");
10308 +       }
10309 +}
10310 +
10311 +#endif
10312 +
10313 +#endif /* _VX_CACCT_DEF_H */
10314 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/cacct.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/cacct.h
10315 --- linux-2.6.36/include/linux/vserver/cacct.h  1970-01-01 01:00:00.000000000 +0100
10316 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/cacct.h    2010-10-21 13:09:36.000000000 +0200
10317 @@ -0,0 +1,15 @@
10318 +#ifndef _VX_CACCT_H
10319 +#define _VX_CACCT_H
10320 +
10321 +
10322 +enum sock_acc_field {
10323 +       VXA_SOCK_UNSPEC = 0,
10324 +       VXA_SOCK_UNIX,
10325 +       VXA_SOCK_INET,
10326 +       VXA_SOCK_INET6,
10327 +       VXA_SOCK_PACKET,
10328 +       VXA_SOCK_OTHER,
10329 +       VXA_SOCK_SIZE   /* array size */
10330 +};
10331 +
10332 +#endif /* _VX_CACCT_H */
10333 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/cacct_int.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/cacct_int.h
10334 --- linux-2.6.36/include/linux/vserver/cacct_int.h      1970-01-01 01:00:00.000000000 +0100
10335 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/cacct_int.h        2010-10-21 13:09:36.000000000 +0200
10336 @@ -0,0 +1,21 @@
10337 +#ifndef _VX_CACCT_INT_H
10338 +#define _VX_CACCT_INT_H
10339 +
10340 +
10341 +#ifdef __KERNEL__
10342 +
10343 +static inline
10344 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10345 +{
10346 +       return atomic_long_read(&cacct->sock[type][pos].count);
10347 +}
10348 +
10349 +
10350 +static inline
10351 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10352 +{
10353 +       return atomic_long_read(&cacct->sock[type][pos].total);
10354 +}
10355 +
10356 +#endif /* __KERNEL__ */
10357 +#endif /* _VX_CACCT_INT_H */
10358 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/check.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/check.h
10359 --- linux-2.6.36/include/linux/vserver/check.h  1970-01-01 01:00:00.000000000 +0100
10360 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/check.h    2010-10-21 13:09:36.000000000 +0200
10361 @@ -0,0 +1,89 @@
10362 +#ifndef _VS_CHECK_H
10363 +#define _VS_CHECK_H
10364 +
10365 +
10366 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
10367 +
10368 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10369 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
10370 +#else
10371 +#define MIN_D_CONTEXT  65536
10372 +#endif
10373 +
10374 +/* check conditions */
10375 +
10376 +#define VS_ADMIN       0x0001
10377 +#define VS_WATCH       0x0002
10378 +#define VS_HIDE                0x0004
10379 +#define VS_HOSTID      0x0008
10380 +
10381 +#define VS_IDENT       0x0010
10382 +#define VS_EQUIV       0x0020
10383 +#define VS_PARENT      0x0040
10384 +#define VS_CHILD       0x0080
10385 +
10386 +#define VS_ARG_MASK    0x00F0
10387 +
10388 +#define VS_DYNAMIC     0x0100
10389 +#define VS_STATIC      0x0200
10390 +
10391 +#define VS_ATR_MASK    0x0F00
10392 +
10393 +#ifdef CONFIG_VSERVER_PRIVACY
10394 +#define VS_ADMIN_P     (0)
10395 +#define VS_WATCH_P     (0)
10396 +#else
10397 +#define VS_ADMIN_P     VS_ADMIN
10398 +#define VS_WATCH_P     VS_WATCH
10399 +#endif
10400 +
10401 +#define VS_HARDIRQ     0x1000
10402 +#define VS_SOFTIRQ     0x2000
10403 +#define VS_IRQ         0x4000
10404 +
10405 +#define VS_IRQ_MASK    0xF000
10406 +
10407 +#include <linux/hardirq.h>
10408 +
10409 +/*
10410 + * check current context for ADMIN/WATCH and
10411 + * optionally against supplied argument
10412 + */
10413 +static inline int __vs_check(int cid, int id, unsigned int mode)
10414 +{
10415 +       if (mode & VS_ARG_MASK) {
10416 +               if ((mode & VS_IDENT) && (id == cid))
10417 +                       return 1;
10418 +       }
10419 +       if (mode & VS_ATR_MASK) {
10420 +               if ((mode & VS_DYNAMIC) &&
10421 +                       (id >= MIN_D_CONTEXT) &&
10422 +                       (id <= MAX_S_CONTEXT))
10423 +                       return 1;
10424 +               if ((mode & VS_STATIC) &&
10425 +                       (id > 1) && (id < MIN_D_CONTEXT))
10426 +                       return 1;
10427 +       }
10428 +       if (mode & VS_IRQ_MASK) {
10429 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
10430 +                       return 1;
10431 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
10432 +                       return 1;
10433 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
10434 +                       return 1;
10435 +       }
10436 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
10437 +               ((mode & VS_WATCH) && (cid == 1)) ||
10438 +               ((mode & VS_HOSTID) && (id == 0)));
10439 +}
10440 +
10441 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
10442 +
10443 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
10444 +
10445 +
10446 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
10447 +
10448 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
10449 +
10450 +#endif
10451 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/context_cmd.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/context_cmd.h
10452 --- linux-2.6.36/include/linux/vserver/context_cmd.h    1970-01-01 01:00:00.000000000 +0100
10453 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/context_cmd.h      2010-10-21 13:09:36.000000000 +0200
10454 @@ -0,0 +1,145 @@
10455 +#ifndef _VX_CONTEXT_CMD_H
10456 +#define _VX_CONTEXT_CMD_H
10457 +
10458 +
10459 +/* vinfo commands */
10460 +
10461 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
10462 +
10463 +#ifdef __KERNEL__
10464 +extern int vc_task_xid(uint32_t);
10465 +
10466 +#endif /* __KERNEL__ */
10467 +
10468 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
10469 +
10470 +struct vcmd_vx_info_v0 {
10471 +       uint32_t xid;
10472 +       uint32_t initpid;
10473 +       /* more to come */
10474 +};
10475 +
10476 +#ifdef __KERNEL__
10477 +extern int vc_vx_info(struct vx_info *, void __user *);
10478 +
10479 +#endif /* __KERNEL__ */
10480 +
10481 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
10482 +
10483 +struct vcmd_ctx_stat_v0 {
10484 +       uint32_t usecnt;
10485 +       uint32_t tasks;
10486 +       /* more to come */
10487 +};
10488 +
10489 +#ifdef __KERNEL__
10490 +extern int vc_ctx_stat(struct vx_info *, void __user *);
10491 +
10492 +#endif /* __KERNEL__ */
10493 +
10494 +/* context commands */
10495 +
10496 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
10497 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
10498 +
10499 +struct vcmd_ctx_create {
10500 +       uint64_t flagword;
10501 +};
10502 +
10503 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
10504 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
10505 +
10506 +struct vcmd_ctx_migrate {
10507 +       uint64_t flagword;
10508 +};
10509 +
10510 +#ifdef __KERNEL__
10511 +extern int vc_ctx_create(uint32_t, void __user *);
10512 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
10513 +
10514 +#endif /* __KERNEL__ */
10515 +
10516 +
10517 +/* flag commands */
10518 +
10519 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
10520 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
10521 +
10522 +struct vcmd_ctx_flags_v0 {
10523 +       uint64_t flagword;
10524 +       uint64_t mask;
10525 +};
10526 +
10527 +#ifdef __KERNEL__
10528 +extern int vc_get_cflags(struct vx_info *, void __user *);
10529 +extern int vc_set_cflags(struct vx_info *, void __user *);
10530 +
10531 +#endif /* __KERNEL__ */
10532 +
10533 +
10534 +/* context caps commands */
10535 +
10536 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
10537 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
10538 +
10539 +struct vcmd_ctx_caps_v1 {
10540 +       uint64_t ccaps;
10541 +       uint64_t cmask;
10542 +};
10543 +
10544 +#ifdef __KERNEL__
10545 +extern int vc_get_ccaps(struct vx_info *, void __user *);
10546 +extern int vc_set_ccaps(struct vx_info *, void __user *);
10547 +
10548 +#endif /* __KERNEL__ */
10549 +
10550 +
10551 +/* bcaps commands */
10552 +
10553 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
10554 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
10555 +
10556 +struct vcmd_bcaps {
10557 +       uint64_t bcaps;
10558 +       uint64_t bmask;
10559 +};
10560 +
10561 +#ifdef __KERNEL__
10562 +extern int vc_get_bcaps(struct vx_info *, void __user *);
10563 +extern int vc_set_bcaps(struct vx_info *, void __user *);
10564 +
10565 +#endif /* __KERNEL__ */
10566 +
10567 +
10568 +/* umask commands */
10569 +
10570 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
10571 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
10572 +
10573 +struct vcmd_umask {
10574 +       uint64_t umask;
10575 +       uint64_t mask;
10576 +};
10577 +
10578 +#ifdef __KERNEL__
10579 +extern int vc_get_umask(struct vx_info *, void __user *);
10580 +extern int vc_set_umask(struct vx_info *, void __user *);
10581 +
10582 +#endif /* __KERNEL__ */
10583 +
10584 +
10585 +/* OOM badness */
10586 +
10587 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
10588 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
10589 +
10590 +struct vcmd_badness_v0 {
10591 +       int64_t bias;
10592 +};
10593 +
10594 +#ifdef __KERNEL__
10595 +extern int vc_get_badness(struct vx_info *, void __user *);
10596 +extern int vc_set_badness(struct vx_info *, void __user *);
10597 +
10598 +#endif /* __KERNEL__ */
10599 +#endif /* _VX_CONTEXT_CMD_H */
10600 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/context.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/context.h
10601 --- linux-2.6.36/include/linux/vserver/context.h        1970-01-01 01:00:00.000000000 +0100
10602 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/context.h  2010-10-21 13:09:36.000000000 +0200
10603 @@ -0,0 +1,184 @@
10604 +#ifndef _VX_CONTEXT_H
10605 +#define _VX_CONTEXT_H
10606 +
10607 +#include <linux/types.h>
10608 +#include <linux/capability.h>
10609 +
10610 +
10611 +/* context flags */
10612 +
10613 +#define VXF_INFO_SCHED         0x00000002
10614 +#define VXF_INFO_NPROC         0x00000004
10615 +#define VXF_INFO_PRIVATE       0x00000008
10616 +
10617 +#define VXF_INFO_INIT          0x00000010
10618 +#define VXF_INFO_HIDE          0x00000020
10619 +#define VXF_INFO_ULIMIT                0x00000040
10620 +#define VXF_INFO_NSPACE                0x00000080
10621 +
10622 +#define VXF_SCHED_HARD         0x00000100
10623 +#define VXF_SCHED_PRIO         0x00000200
10624 +#define VXF_SCHED_PAUSE                0x00000400
10625 +
10626 +#define VXF_VIRT_MEM           0x00010000
10627 +#define VXF_VIRT_UPTIME                0x00020000
10628 +#define VXF_VIRT_CPU           0x00040000
10629 +#define VXF_VIRT_LOAD          0x00080000
10630 +#define VXF_VIRT_TIME          0x00100000
10631 +
10632 +#define VXF_HIDE_MOUNT         0x01000000
10633 +/* was VXF_HIDE_NETIF          0x02000000 */
10634 +#define VXF_HIDE_VINFO         0x04000000
10635 +
10636 +#define VXF_STATE_SETUP                (1ULL << 32)
10637 +#define VXF_STATE_INIT         (1ULL << 33)
10638 +#define VXF_STATE_ADMIN                (1ULL << 34)
10639 +
10640 +#define VXF_SC_HELPER          (1ULL << 36)
10641 +#define VXF_REBOOT_KILL                (1ULL << 37)
10642 +#define VXF_PERSISTENT         (1ULL << 38)
10643 +
10644 +#define VXF_FORK_RSS           (1ULL << 48)
10645 +#define VXF_PROLIFIC           (1ULL << 49)
10646 +
10647 +#define VXF_IGNEG_NICE         (1ULL << 52)
10648 +
10649 +#define VXF_ONE_TIME           (0x0007ULL << 32)
10650 +
10651 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
10652 +
10653 +
10654 +/* context migration */
10655 +
10656 +#define VXM_SET_INIT           0x00000001
10657 +#define VXM_SET_REAPER         0x00000002
10658 +
10659 +/* context caps */
10660 +
10661 +#define VXC_CAP_MASK           0x00000000
10662 +
10663 +#define VXC_SET_UTSNAME                0x00000001
10664 +#define VXC_SET_RLIMIT         0x00000002
10665 +#define VXC_FS_SECURITY                0x00000004
10666 +#define VXC_FS_TRUSTED         0x00000008
10667 +#define VXC_TIOCSTI            0x00000010
10668 +
10669 +/* was VXC_RAW_ICMP            0x00000100 */
10670 +#define VXC_SYSLOG             0x00001000
10671 +#define VXC_OOM_ADJUST         0x00002000
10672 +#define VXC_AUDIT_CONTROL      0x00004000
10673 +
10674 +#define VXC_SECURE_MOUNT       0x00010000
10675 +#define VXC_SECURE_REMOUNT     0x00020000
10676 +#define VXC_BINARY_MOUNT       0x00040000
10677 +
10678 +#define VXC_QUOTA_CTL          0x00100000
10679 +#define VXC_ADMIN_MAPPER       0x00200000
10680 +#define VXC_ADMIN_CLOOP                0x00400000
10681 +
10682 +#define VXC_KTHREAD            0x01000000
10683 +#define VXC_NAMESPACE          0x02000000
10684 +
10685 +
10686 +#ifdef __KERNEL__
10687 +
10688 +#include <linux/list.h>
10689 +#include <linux/spinlock.h>
10690 +#include <linux/rcupdate.h>
10691 +
10692 +#include "limit_def.h"
10693 +#include "sched_def.h"
10694 +#include "cvirt_def.h"
10695 +#include "cacct_def.h"
10696 +#include "device_def.h"
10697 +
10698 +#define VX_SPACES      2
10699 +
10700 +struct _vx_info_pc {
10701 +       struct _vx_sched_pc sched_pc;
10702 +       struct _vx_cvirt_pc cvirt_pc;
10703 +};
10704 +
10705 +struct vx_info {
10706 +       struct hlist_node vx_hlist;             /* linked list of contexts */
10707 +       xid_t vx_id;                            /* context id */
10708 +       atomic_t vx_usecnt;                     /* usage count */
10709 +       atomic_t vx_tasks;                      /* tasks count */
10710 +       struct vx_info *vx_parent;              /* parent context */
10711 +       int vx_state;                           /* context state */
10712 +
10713 +       unsigned long vx_nsmask[VX_SPACES];     /* assignment mask */
10714 +       struct nsproxy *vx_nsproxy[VX_SPACES];  /* private namespaces */
10715 +       struct fs_struct *vx_fs[VX_SPACES];     /* private namespace fs */
10716 +
10717 +       uint64_t vx_flags;                      /* context flags */
10718 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
10719 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
10720 +       unsigned long vx_umask;                 /* unshare mask (guest) */
10721 +
10722 +       struct task_struct *vx_reaper;          /* guest reaper process */
10723 +       pid_t vx_initpid;                       /* PID of guest init */
10724 +       int64_t vx_badness_bias;                /* OOM points bias */
10725 +
10726 +       struct _vx_limit limit;                 /* vserver limits */
10727 +       struct _vx_sched sched;                 /* vserver scheduler */
10728 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
10729 +       struct _vx_cacct cacct;                 /* context accounting */
10730 +
10731 +       struct _vx_device dmap;                 /* default device map targets */
10732 +
10733 +#ifndef CONFIG_SMP
10734 +       struct _vx_info_pc info_pc;             /* per cpu data */
10735 +#else
10736 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
10737 +#endif
10738 +
10739 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
10740 +       int reboot_cmd;                         /* last sys_reboot() cmd */
10741 +       int exit_code;                          /* last process exit code */
10742 +
10743 +       char vx_name[65];                       /* vserver name */
10744 +};
10745 +
10746 +#ifndef CONFIG_SMP
10747 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
10748 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
10749 +#else
10750 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
10751 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
10752 +#endif
10753 +
10754 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
10755 +
10756 +
10757 +struct vx_info_save {
10758 +       struct vx_info *vxi;
10759 +       xid_t xid;
10760 +};
10761 +
10762 +
10763 +/* status flags */
10764 +
10765 +#define VXS_HASHED     0x0001
10766 +#define VXS_PAUSED     0x0010
10767 +#define VXS_SHUTDOWN   0x0100
10768 +#define VXS_HELPER     0x1000
10769 +#define VXS_RELEASED   0x8000
10770 +
10771 +
10772 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
10773 +extern void release_vx_info(struct vx_info *, struct task_struct *);
10774 +
10775 +extern struct vx_info *lookup_vx_info(int);
10776 +extern struct vx_info *lookup_or_create_vx_info(int);
10777 +
10778 +extern int get_xid_list(int, unsigned int *, int);
10779 +extern int xid_is_hashed(xid_t);
10780 +
10781 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
10782 +
10783 +extern long vs_state_change(struct vx_info *, unsigned int);
10784 +
10785 +
10786 +#endif /* __KERNEL__ */
10787 +#endif /* _VX_CONTEXT_H */
10788 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/cvirt_cmd.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/cvirt_cmd.h
10789 --- linux-2.6.36/include/linux/vserver/cvirt_cmd.h      1970-01-01 01:00:00.000000000 +0100
10790 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/cvirt_cmd.h        2010-10-21 13:09:36.000000000 +0200
10791 @@ -0,0 +1,53 @@
10792 +#ifndef _VX_CVIRT_CMD_H
10793 +#define _VX_CVIRT_CMD_H
10794 +
10795 +
10796 +/* virtual host info name commands */
10797 +
10798 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
10799 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
10800 +
10801 +struct vcmd_vhi_name_v0 {
10802 +       uint32_t field;
10803 +       char name[65];
10804 +};
10805 +
10806 +
10807 +enum vhi_name_field {
10808 +       VHIN_CONTEXT = 0,
10809 +       VHIN_SYSNAME,
10810 +       VHIN_NODENAME,
10811 +       VHIN_RELEASE,
10812 +       VHIN_VERSION,
10813 +       VHIN_MACHINE,
10814 +       VHIN_DOMAINNAME,
10815 +};
10816 +
10817 +
10818 +#ifdef __KERNEL__
10819 +
10820 +#include <linux/compiler.h>
10821 +
10822 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
10823 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
10824 +
10825 +#endif /* __KERNEL__ */
10826 +
10827 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
10828 +
10829 +struct vcmd_virt_stat_v0 {
10830 +       uint64_t offset;
10831 +       uint64_t uptime;
10832 +       uint32_t nr_threads;
10833 +       uint32_t nr_running;
10834 +       uint32_t nr_uninterruptible;
10835 +       uint32_t nr_onhold;
10836 +       uint32_t nr_forks;
10837 +       uint32_t load[3];
10838 +};
10839 +
10840 +#ifdef __KERNEL__
10841 +extern int vc_virt_stat(struct vx_info *, void __user *);
10842 +
10843 +#endif /* __KERNEL__ */
10844 +#endif /* _VX_CVIRT_CMD_H */
10845 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/cvirt_def.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/cvirt_def.h
10846 --- linux-2.6.36/include/linux/vserver/cvirt_def.h      1970-01-01 01:00:00.000000000 +0100
10847 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/cvirt_def.h        2010-10-21 14:26:47.000000000 +0200
10848 @@ -0,0 +1,80 @@
10849 +#ifndef _VX_CVIRT_DEF_H
10850 +#define _VX_CVIRT_DEF_H
10851 +
10852 +#include <linux/jiffies.h>
10853 +#include <linux/spinlock.h>
10854 +#include <linux/wait.h>
10855 +#include <linux/time.h>
10856 +#include <asm/atomic.h>
10857 +
10858 +
10859 +struct _vx_usage_stat {
10860 +       uint64_t user;
10861 +       uint64_t nice;
10862 +       uint64_t system;
10863 +       uint64_t softirq;
10864 +       uint64_t irq;
10865 +       uint64_t idle;
10866 +       uint64_t iowait;
10867 +};
10868 +
10869 +struct _vx_syslog {
10870 +       wait_queue_head_t log_wait;
10871 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
10872 +
10873 +       unsigned long log_start;        /* next char to be read by syslog() */
10874 +       unsigned long con_start;        /* next char to be sent to consoles */
10875 +       unsigned long log_end;  /* most-recently-written-char + 1 */
10876 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
10877 +
10878 +       char log_buf[1024];
10879 +};
10880 +
10881 +
10882 +/* context sub struct */
10883 +
10884 +struct _vx_cvirt {
10885 +       atomic_t nr_threads;            /* number of current threads */
10886 +       atomic_t nr_running;            /* number of running threads */
10887 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
10888 +
10889 +       atomic_t nr_onhold;             /* processes on hold */
10890 +       uint32_t onhold_last;           /* jiffies when put on hold */
10891 +
10892 +       struct timespec bias_ts;        /* time offset to the host */
10893 +       struct timespec bias_idle;
10894 +       struct timespec bias_uptime;    /* context creation point */
10895 +       uint64_t bias_clock;            /* offset in clock_t */
10896 +
10897 +       spinlock_t load_lock;           /* lock for the load averages */
10898 +       atomic_t load_updates;          /* nr of load updates done so far */
10899 +       uint32_t load_last;             /* last time load was calculated */
10900 +       uint32_t load[3];               /* load averages 1,5,15 */
10901 +
10902 +       atomic_t total_forks;           /* number of forks so far */
10903 +
10904 +       struct _vx_syslog syslog;
10905 +};
10906 +
10907 +struct _vx_cvirt_pc {
10908 +       struct _vx_usage_stat cpustat;
10909 +};
10910 +
10911 +
10912 +#ifdef CONFIG_VSERVER_DEBUG
10913 +
10914 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
10915 +{
10916 +       printk("\t_vx_cvirt:\n");
10917 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
10918 +               atomic_read(&cvirt->nr_threads),
10919 +               atomic_read(&cvirt->nr_running),
10920 +               atomic_read(&cvirt->nr_uninterruptible),
10921 +               atomic_read(&cvirt->nr_onhold));
10922 +       /* add rest here */
10923 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
10924 +}
10925 +
10926 +#endif
10927 +
10928 +#endif /* _VX_CVIRT_DEF_H */
10929 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/cvirt.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/cvirt.h
10930 --- linux-2.6.36/include/linux/vserver/cvirt.h  1970-01-01 01:00:00.000000000 +0100
10931 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/cvirt.h    2010-10-21 13:09:36.000000000 +0200
10932 @@ -0,0 +1,20 @@
10933 +#ifndef _VX_CVIRT_H
10934 +#define _VX_CVIRT_H
10935 +
10936 +
10937 +#ifdef __KERNEL__
10938 +
10939 +struct timespec;
10940 +
10941 +void vx_vsi_uptime(struct timespec *, struct timespec *);
10942 +
10943 +
10944 +struct vx_info;
10945 +
10946 +void vx_update_load(struct vx_info *);
10947 +
10948 +
10949 +int vx_do_syslog(int, char __user *, int);
10950 +
10951 +#endif /* __KERNEL__ */
10952 +#endif /* _VX_CVIRT_H */
10953 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/debug_cmd.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/debug_cmd.h
10954 --- linux-2.6.36/include/linux/vserver/debug_cmd.h      1970-01-01 01:00:00.000000000 +0100
10955 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/debug_cmd.h        2010-10-21 13:09:36.000000000 +0200
10956 @@ -0,0 +1,58 @@
10957 +#ifndef _VX_DEBUG_CMD_H
10958 +#define _VX_DEBUG_CMD_H
10959 +
10960 +
10961 +/* debug commands */
10962 +
10963 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
10964 +
10965 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
10966 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
10967 +
10968 +struct  vcmd_read_history_v0 {
10969 +       uint32_t index;
10970 +       uint32_t count;
10971 +       char __user *data;
10972 +};
10973 +
10974 +struct  vcmd_read_monitor_v0 {
10975 +       uint32_t index;
10976 +       uint32_t count;
10977 +       char __user *data;
10978 +};
10979 +
10980 +
10981 +#ifdef __KERNEL__
10982 +
10983 +#ifdef CONFIG_COMPAT
10984 +
10985 +#include <asm/compat.h>
10986 +
10987 +struct vcmd_read_history_v0_x32 {
10988 +       uint32_t index;
10989 +       uint32_t count;
10990 +       compat_uptr_t data_ptr;
10991 +};
10992 +
10993 +struct vcmd_read_monitor_v0_x32 {
10994 +       uint32_t index;
10995 +       uint32_t count;
10996 +       compat_uptr_t data_ptr;
10997 +};
10998 +
10999 +#endif  /* CONFIG_COMPAT */
11000 +
11001 +extern int vc_dump_history(uint32_t);
11002 +
11003 +extern int vc_read_history(uint32_t, void __user *);
11004 +extern int vc_read_monitor(uint32_t, void __user *);
11005 +
11006 +#ifdef CONFIG_COMPAT
11007 +
11008 +extern int vc_read_history_x32(uint32_t, void __user *);
11009 +extern int vc_read_monitor_x32(uint32_t, void __user *);
11010 +
11011 +#endif  /* CONFIG_COMPAT */
11012 +
11013 +#endif /* __KERNEL__ */
11014 +#endif /* _VX_DEBUG_CMD_H */
11015 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/debug.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/debug.h
11016 --- linux-2.6.36/include/linux/vserver/debug.h  1970-01-01 01:00:00.000000000 +0100
11017 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/debug.h    2010-10-21 18:35:25.000000000 +0200
11018 @@ -0,0 +1,140 @@
11019 +#ifndef _VX_DEBUG_H
11020 +#define _VX_DEBUG_H
11021 +
11022 +
11023 +#define VXD_CBIT(n, m) (vx_debug_ ## n & (1 << (m)))
11024 +#define VXD_CMIN(n, m) (vx_debug_ ## n > (m))
11025 +#define VXD_MASK(n, m) (vx_debug_ ## n & (m))
11026 +
11027 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
11028 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
11029 +#define VXF_DEV                "%p[%lu,%d:%d]"
11030 +
11031 +#if    defined(CONFIG_QUOTES_UTF8)
11032 +#define        VS_Q_LQM        "\xc2\xbb"
11033 +#define        VS_Q_RQM        "\xc2\xab"
11034 +#elif  defined(CONFIG_QUOTES_ASCII)
11035 +#define        VS_Q_LQM        "\x27"
11036 +#define        VS_Q_RQM        "\x27"
11037 +#else
11038 +#define        VS_Q_LQM        "\xbb"
11039 +#define        VS_Q_RQM        "\xab"
11040 +#endif
11041 +
11042 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
11043 +
11044 +
11045 +#define vxd_path(p)                                            \
11046 +       ({ static char _buffer[PATH_MAX];                       \
11047 +          d_path(p, _buffer, sizeof(_buffer)); })
11048 +
11049 +#define vxd_cond_path(n)                                       \
11050 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
11051 +
11052 +
11053 +#ifdef CONFIG_VSERVER_DEBUG
11054 +
11055 +extern unsigned int vx_debug_switch;
11056 +extern unsigned int vx_debug_xid;
11057 +extern unsigned int vx_debug_nid;
11058 +extern unsigned int vx_debug_tag;
11059 +extern unsigned int vx_debug_net;
11060 +extern unsigned int vx_debug_limit;
11061 +extern unsigned int vx_debug_cres;
11062 +extern unsigned int vx_debug_dlim;
11063 +extern unsigned int vx_debug_quota;
11064 +extern unsigned int vx_debug_cvirt;
11065 +extern unsigned int vx_debug_space;
11066 +extern unsigned int vx_debug_misc;
11067 +
11068 +
11069 +#define VX_LOGLEVEL    "vxD: "
11070 +#define VX_PROC_FMT    "%p: "
11071 +#define VX_PROCESS     current
11072 +
11073 +#define vxdprintk(c, f, x...)                                  \
11074 +       do {                                                    \
11075 +               if (c)                                          \
11076 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
11077 +                               VX_PROCESS , ##x);              \
11078 +       } while (0)
11079 +
11080 +#define vxlprintk(c, f, x...)                                  \
11081 +       do {                                                    \
11082 +               if (c)                                          \
11083 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
11084 +       } while (0)
11085 +
11086 +#define vxfprintk(c, f, x...)                                  \
11087 +       do {                                                    \
11088 +               if (c)                                          \
11089 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
11090 +       } while (0)
11091 +
11092 +
11093 +struct vx_info;
11094 +
11095 +void dump_vx_info(struct vx_info *, int);
11096 +void dump_vx_info_inactive(int);
11097 +
11098 +#else  /* CONFIG_VSERVER_DEBUG */
11099 +
11100 +#define vx_debug_switch 0
11101 +#define vx_debug_xid   0
11102 +#define vx_debug_nid   0
11103 +#define vx_debug_tag   0
11104 +#define vx_debug_net   0
11105 +#define vx_debug_limit 0
11106 +#define vx_debug_cres  0
11107 +#define vx_debug_dlim  0
11108 +#define vx_debug_cvirt 0
11109 +
11110 +#define vxdprintk(x...) do { } while (0)
11111 +#define vxlprintk(x...) do { } while (0)
11112 +#define vxfprintk(x...) do { } while (0)
11113 +
11114 +#endif /* CONFIG_VSERVER_DEBUG */
11115 +
11116 +
11117 +#ifdef CONFIG_VSERVER_WARN
11118 +
11119 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
11120 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
11121 +#define VX_WARN_XID    "[xid #%u] "
11122 +#define VX_WARN_NID    "[nid #%u] "
11123 +#define VX_WARN_TAG    "[tag #%u] "
11124 +
11125 +#define vxwprintk(c, f, x...)                                  \
11126 +       do {                                                    \
11127 +               if (c)                                          \
11128 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
11129 +       } while (0)
11130 +
11131 +#else  /* CONFIG_VSERVER_WARN */
11132 +
11133 +#define vxwprintk(x...) do { } while (0)
11134 +
11135 +#endif /* CONFIG_VSERVER_WARN */
11136 +
11137 +#define vxwprintk_task(c, f, x...)                             \
11138 +       vxwprintk(c, VX_WARN_TASK f,                            \
11139 +               current->comm, current->pid,                    \
11140 +               current->xid, current->nid, current->tag, ##x)
11141 +#define vxwprintk_xid(c, f, x...)                              \
11142 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
11143 +#define vxwprintk_nid(c, f, x...)                              \
11144 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
11145 +#define vxwprintk_tag(c, f, x...)                              \
11146 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
11147 +
11148 +#ifdef CONFIG_VSERVER_DEBUG
11149 +#define vxd_assert_lock(l)     assert_spin_locked(l)
11150 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
11151 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
11152 +#else
11153 +#define vxd_assert_lock(l)     do { } while (0)
11154 +#define vxd_assert(c, f, x...) do { } while (0)
11155 +#endif
11156 +
11157 +
11158 +#endif /* _VX_DEBUG_H */
11159 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/device_cmd.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/device_cmd.h
11160 --- linux-2.6.36/include/linux/vserver/device_cmd.h     1970-01-01 01:00:00.000000000 +0100
11161 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/device_cmd.h       2010-10-21 13:09:36.000000000 +0200
11162 @@ -0,0 +1,44 @@
11163 +#ifndef _VX_DEVICE_CMD_H
11164 +#define _VX_DEVICE_CMD_H
11165 +
11166 +
11167 +/*  device vserver commands */
11168 +
11169 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
11170 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
11171 +
11172 +struct vcmd_set_mapping_v0 {
11173 +       const char __user *device;
11174 +       const char __user *target;
11175 +       uint32_t flags;
11176 +};
11177 +
11178 +
11179 +#ifdef __KERNEL__
11180 +
11181 +#ifdef CONFIG_COMPAT
11182 +
11183 +#include <asm/compat.h>
11184 +
11185 +struct vcmd_set_mapping_v0_x32 {
11186 +       compat_uptr_t device_ptr;
11187 +       compat_uptr_t target_ptr;
11188 +       uint32_t flags;
11189 +};
11190 +
11191 +#endif /* CONFIG_COMPAT */
11192 +
11193 +#include <linux/compiler.h>
11194 +
11195 +extern int vc_set_mapping(struct vx_info *, void __user *);
11196 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11197 +
11198 +#ifdef CONFIG_COMPAT
11199 +
11200 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11201 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11202 +
11203 +#endif /* CONFIG_COMPAT */
11204 +
11205 +#endif /* __KERNEL__ */
11206 +#endif /* _VX_DEVICE_CMD_H */
11207 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/device_def.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/device_def.h
11208 --- linux-2.6.36/include/linux/vserver/device_def.h     1970-01-01 01:00:00.000000000 +0100
11209 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/device_def.h       2010-10-21 13:09:36.000000000 +0200
11210 @@ -0,0 +1,17 @@
11211 +#ifndef _VX_DEVICE_DEF_H
11212 +#define _VX_DEVICE_DEF_H
11213 +
11214 +#include <linux/types.h>
11215 +
11216 +struct vx_dmap_target {
11217 +       dev_t target;
11218 +       uint32_t flags;
11219 +};
11220 +
11221 +struct _vx_device {
11222 +#ifdef CONFIG_VSERVER_DEVICE
11223 +       struct vx_dmap_target targets[2];
11224 +#endif
11225 +};
11226 +
11227 +#endif /* _VX_DEVICE_DEF_H */
11228 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/device.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/device.h
11229 --- linux-2.6.36/include/linux/vserver/device.h 1970-01-01 01:00:00.000000000 +0100
11230 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/device.h   2010-10-21 13:09:36.000000000 +0200
11231 @@ -0,0 +1,15 @@
11232 +#ifndef _VX_DEVICE_H
11233 +#define _VX_DEVICE_H
11234 +
11235 +
11236 +#define DATTR_CREATE   0x00000001
11237 +#define DATTR_OPEN     0x00000002
11238 +
11239 +#define DATTR_REMAP    0x00000010
11240 +
11241 +#define DATTR_MASK     0x00000013
11242 +
11243 +
11244 +#else  /* _VX_DEVICE_H */
11245 +#warning duplicate inclusion
11246 +#endif /* _VX_DEVICE_H */
11247 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/dlimit_cmd.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/dlimit_cmd.h
11248 --- linux-2.6.36/include/linux/vserver/dlimit_cmd.h     1970-01-01 01:00:00.000000000 +0100
11249 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/dlimit_cmd.h       2010-10-21 13:09:36.000000000 +0200
11250 @@ -0,0 +1,109 @@
11251 +#ifndef _VX_DLIMIT_CMD_H
11252 +#define _VX_DLIMIT_CMD_H
11253 +
11254 +
11255 +/*  dlimit vserver commands */
11256 +
11257 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
11258 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
11259 +
11260 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
11261 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
11262 +
11263 +struct vcmd_ctx_dlimit_base_v0 {
11264 +       const char __user *name;
11265 +       uint32_t flags;
11266 +};
11267 +
11268 +struct vcmd_ctx_dlimit_v0 {
11269 +       const char __user *name;
11270 +       uint32_t space_used;                    /* used space in kbytes */
11271 +       uint32_t space_total;                   /* maximum space in kbytes */
11272 +       uint32_t inodes_used;                   /* used inodes */
11273 +       uint32_t inodes_total;                  /* maximum inodes */
11274 +       uint32_t reserved;                      /* reserved for root in % */
11275 +       uint32_t flags;
11276 +};
11277 +
11278 +#define CDLIM_UNSET            ((uint32_t)0UL)
11279 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
11280 +#define CDLIM_KEEP             ((uint32_t)~1UL)
11281 +
11282 +#define DLIME_UNIT     0
11283 +#define DLIME_KILO     1
11284 +#define DLIME_MEGA     2
11285 +#define DLIME_GIGA     3
11286 +
11287 +#define DLIMF_SHIFT    0x10
11288 +
11289 +#define DLIMS_USED     0
11290 +#define DLIMS_TOTAL    2
11291 +
11292 +static inline
11293 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
11294 +{
11295 +       int exp = (flags & DLIMF_SHIFT) ?
11296 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
11297 +       return ((uint64_t)val) << (10 * exp);
11298 +}
11299 +
11300 +static inline
11301 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
11302 +{
11303 +       int exp = 0;
11304 +
11305 +       if (*flags & DLIMF_SHIFT) {
11306 +               while (val > (1LL << 32) && (exp < 3)) {
11307 +                       val >>= 10;
11308 +                       exp++;
11309 +               }
11310 +               *flags &= ~(DLIME_GIGA << shift);
11311 +               *flags |= exp << shift;
11312 +       } else
11313 +               val >>= 10;
11314 +       return val;
11315 +}
11316 +
11317 +#ifdef __KERNEL__
11318 +
11319 +#ifdef CONFIG_COMPAT
11320 +
11321 +#include <asm/compat.h>
11322 +
11323 +struct vcmd_ctx_dlimit_base_v0_x32 {
11324 +       compat_uptr_t name_ptr;
11325 +       uint32_t flags;
11326 +};
11327 +
11328 +struct vcmd_ctx_dlimit_v0_x32 {
11329 +       compat_uptr_t name_ptr;
11330 +       uint32_t space_used;                    /* used space in kbytes */
11331 +       uint32_t space_total;                   /* maximum space in kbytes */
11332 +       uint32_t inodes_used;                   /* used inodes */
11333 +       uint32_t inodes_total;                  /* maximum inodes */
11334 +       uint32_t reserved;                      /* reserved for root in % */
11335 +       uint32_t flags;
11336 +};
11337 +
11338 +#endif /* CONFIG_COMPAT */
11339 +
11340 +#include <linux/compiler.h>
11341 +
11342 +extern int vc_add_dlimit(uint32_t, void __user *);
11343 +extern int vc_rem_dlimit(uint32_t, void __user *);
11344 +
11345 +extern int vc_set_dlimit(uint32_t, void __user *);
11346 +extern int vc_get_dlimit(uint32_t, void __user *);
11347 +
11348 +#ifdef CONFIG_COMPAT
11349 +
11350 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
11351 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
11352 +
11353 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
11354 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
11355 +
11356 +#endif /* CONFIG_COMPAT */
11357 +
11358 +#endif /* __KERNEL__ */
11359 +#endif /* _VX_DLIMIT_CMD_H */
11360 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/dlimit.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/dlimit.h
11361 --- linux-2.6.36/include/linux/vserver/dlimit.h 1970-01-01 01:00:00.000000000 +0100
11362 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/dlimit.h   2010-10-21 13:09:36.000000000 +0200
11363 @@ -0,0 +1,54 @@
11364 +#ifndef _VX_DLIMIT_H
11365 +#define _VX_DLIMIT_H
11366 +
11367 +#include "switch.h"
11368 +
11369 +
11370 +#ifdef __KERNEL__
11371 +
11372 +/*      keep in sync with CDLIM_INFINITY       */
11373 +
11374 +#define DLIM_INFINITY          (~0ULL)
11375 +
11376 +#include <linux/spinlock.h>
11377 +#include <linux/rcupdate.h>
11378 +
11379 +struct super_block;
11380 +
11381 +struct dl_info {
11382 +       struct hlist_node dl_hlist;             /* linked list of contexts */
11383 +       struct rcu_head dl_rcu;                 /* the rcu head */
11384 +       tag_t dl_tag;                           /* context tag */
11385 +       atomic_t dl_usecnt;                     /* usage count */
11386 +       atomic_t dl_refcnt;                     /* reference count */
11387 +
11388 +       struct super_block *dl_sb;              /* associated superblock */
11389 +
11390 +       spinlock_t dl_lock;                     /* protect the values */
11391 +
11392 +       unsigned long long dl_space_used;       /* used space in bytes */
11393 +       unsigned long long dl_space_total;      /* maximum space in bytes */
11394 +       unsigned long dl_inodes_used;           /* used inodes */
11395 +       unsigned long dl_inodes_total;          /* maximum inodes */
11396 +
11397 +       unsigned int dl_nrlmult;                /* non root limit mult */
11398 +};
11399 +
11400 +struct rcu_head;
11401 +
11402 +extern void rcu_free_dl_info(struct rcu_head *);
11403 +extern void unhash_dl_info(struct dl_info *);
11404 +
11405 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
11406 +
11407 +
11408 +struct kstatfs;
11409 +
11410 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11411 +
11412 +typedef uint64_t dlsize_t;
11413 +
11414 +#endif /* __KERNEL__ */
11415 +#else  /* _VX_DLIMIT_H */
11416 +#warning duplicate inclusion
11417 +#endif /* _VX_DLIMIT_H */
11418 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/global.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/global.h
11419 --- linux-2.6.36/include/linux/vserver/global.h 1970-01-01 01:00:00.000000000 +0100
11420 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/global.h   2010-10-21 13:09:36.000000000 +0200
11421 @@ -0,0 +1,19 @@
11422 +#ifndef _VX_GLOBAL_H
11423 +#define _VX_GLOBAL_H
11424 +
11425 +
11426 +extern atomic_t vx_global_ctotal;
11427 +extern atomic_t vx_global_cactive;
11428 +
11429 +extern atomic_t nx_global_ctotal;
11430 +extern atomic_t nx_global_cactive;
11431 +
11432 +extern atomic_t vs_global_nsproxy;
11433 +extern atomic_t vs_global_fs;
11434 +extern atomic_t vs_global_mnt_ns;
11435 +extern atomic_t vs_global_uts_ns;
11436 +extern atomic_t vs_global_user_ns;
11437 +extern atomic_t vs_global_pid_ns;
11438 +
11439 +
11440 +#endif /* _VX_GLOBAL_H */
11441 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/history.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/history.h
11442 --- linux-2.6.36/include/linux/vserver/history.h        1970-01-01 01:00:00.000000000 +0100
11443 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/history.h  2010-10-21 13:09:36.000000000 +0200
11444 @@ -0,0 +1,197 @@
11445 +#ifndef _VX_HISTORY_H
11446 +#define _VX_HISTORY_H
11447 +
11448 +
11449 +enum {
11450 +       VXH_UNUSED = 0,
11451 +       VXH_THROW_OOPS = 1,
11452 +
11453 +       VXH_GET_VX_INFO,
11454 +       VXH_PUT_VX_INFO,
11455 +       VXH_INIT_VX_INFO,
11456 +       VXH_SET_VX_INFO,
11457 +       VXH_CLR_VX_INFO,
11458 +       VXH_CLAIM_VX_INFO,
11459 +       VXH_RELEASE_VX_INFO,
11460 +       VXH_ALLOC_VX_INFO,
11461 +       VXH_DEALLOC_VX_INFO,
11462 +       VXH_HASH_VX_INFO,
11463 +       VXH_UNHASH_VX_INFO,
11464 +       VXH_LOC_VX_INFO,
11465 +       VXH_LOOKUP_VX_INFO,
11466 +       VXH_CREATE_VX_INFO,
11467 +};
11468 +
11469 +struct _vxhe_vxi {
11470 +       struct vx_info *ptr;
11471 +       unsigned xid;
11472 +       unsigned usecnt;
11473 +       unsigned tasks;
11474 +};
11475 +
11476 +struct _vxhe_set_clr {
11477 +       void *data;
11478 +};
11479 +
11480 +struct _vxhe_loc_lookup {
11481 +       unsigned arg;
11482 +};
11483 +
11484 +struct _vx_hist_entry {
11485 +       void *loc;
11486 +       unsigned short seq;
11487 +       unsigned short type;
11488 +       struct _vxhe_vxi vxi;
11489 +       union {
11490 +               struct _vxhe_set_clr sc;
11491 +               struct _vxhe_loc_lookup ll;
11492 +       };
11493 +};
11494 +
11495 +#ifdef CONFIG_VSERVER_HISTORY
11496 +
11497 +extern unsigned volatile int vxh_active;
11498 +
11499 +struct _vx_hist_entry *vxh_advance(void *loc);
11500 +
11501 +
11502 +static inline
11503 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
11504 +{
11505 +       entry->vxi.ptr = vxi;
11506 +       if (vxi) {
11507 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
11508 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
11509 +               entry->vxi.xid = vxi->vx_id;
11510 +       }
11511 +}
11512 +
11513 +
11514 +#define        __HERE__ current_text_addr()
11515 +
11516 +#define __VXH_BODY(__type, __data, __here)     \
11517 +       struct _vx_hist_entry *entry;           \
11518 +                                               \
11519 +       preempt_disable();                      \
11520 +       entry = vxh_advance(__here);            \
11521 +       __data;                                 \
11522 +       entry->type = __type;                   \
11523 +       preempt_enable();
11524 +
11525 +
11526 +       /* pass vxi only */
11527 +
11528 +#define __VXH_SMPL                             \
11529 +       __vxh_copy_vxi(entry, vxi)
11530 +
11531 +static inline
11532 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
11533 +{
11534 +       __VXH_BODY(__type, __VXH_SMPL, __here)
11535 +}
11536 +
11537 +       /* pass vxi and data (void *) */
11538 +
11539 +#define __VXH_DATA                             \
11540 +       __vxh_copy_vxi(entry, vxi);             \
11541 +       entry->sc.data = data
11542 +
11543 +static inline
11544 +void   __vxh_data(struct vx_info *vxi, void *data,
11545 +                       int __type, void *__here)
11546 +{
11547 +       __VXH_BODY(__type, __VXH_DATA, __here)
11548 +}
11549 +
11550 +       /* pass vxi and arg (long) */
11551 +
11552 +#define __VXH_LONG                             \
11553 +       __vxh_copy_vxi(entry, vxi);             \
11554 +       entry->ll.arg = arg
11555 +
11556 +static inline
11557 +void   __vxh_long(struct vx_info *vxi, long arg,
11558 +                       int __type, void *__here)
11559 +{
11560 +       __VXH_BODY(__type, __VXH_LONG, __here)
11561 +}
11562 +
11563 +
11564 +static inline
11565 +void   __vxh_throw_oops(void *__here)
11566 +{
11567 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
11568 +       /* prevent further acquisition */
11569 +       vxh_active = 0;
11570 +}
11571 +
11572 +
11573 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
11574 +
11575 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
11576 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
11577 +
11578 +#define __vxh_init_vx_info(v, d, h) \
11579 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
11580 +#define __vxh_set_vx_info(v, d, h) \
11581 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
11582 +#define __vxh_clr_vx_info(v, d, h) \
11583 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
11584 +
11585 +#define __vxh_claim_vx_info(v, d, h) \
11586 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
11587 +#define __vxh_release_vx_info(v, d, h) \
11588 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
11589 +
11590 +#define vxh_alloc_vx_info(v) \
11591 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
11592 +#define vxh_dealloc_vx_info(v) \
11593 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
11594 +
11595 +#define vxh_hash_vx_info(v) \
11596 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
11597 +#define vxh_unhash_vx_info(v) \
11598 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
11599 +
11600 +#define vxh_loc_vx_info(v, l) \
11601 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
11602 +#define vxh_lookup_vx_info(v, l) \
11603 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
11604 +#define vxh_create_vx_info(v, l) \
11605 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
11606 +
11607 +extern void vxh_dump_history(void);
11608 +
11609 +
11610 +#else  /* CONFIG_VSERVER_HISTORY */
11611 +
11612 +#define        __HERE__        0
11613 +
11614 +#define vxh_throw_oops()               do { } while (0)
11615 +
11616 +#define __vxh_get_vx_info(v, h)                do { } while (0)
11617 +#define __vxh_put_vx_info(v, h)                do { } while (0)
11618 +
11619 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
11620 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
11621 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
11622 +
11623 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
11624 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
11625 +
11626 +#define vxh_alloc_vx_info(v)           do { } while (0)
11627 +#define vxh_dealloc_vx_info(v)         do { } while (0)
11628 +
11629 +#define vxh_hash_vx_info(v)            do { } while (0)
11630 +#define vxh_unhash_vx_info(v)          do { } while (0)
11631 +
11632 +#define vxh_loc_vx_info(v, l)          do { } while (0)
11633 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
11634 +#define vxh_create_vx_info(v, l)       do { } while (0)
11635 +
11636 +#define vxh_dump_history()             do { } while (0)
11637 +
11638 +
11639 +#endif /* CONFIG_VSERVER_HISTORY */
11640 +
11641 +#endif /* _VX_HISTORY_H */
11642 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/inode_cmd.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/inode_cmd.h
11643 --- linux-2.6.36/include/linux/vserver/inode_cmd.h      1970-01-01 01:00:00.000000000 +0100
11644 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/inode_cmd.h        2010-10-21 13:09:36.000000000 +0200
11645 @@ -0,0 +1,59 @@
11646 +#ifndef _VX_INODE_CMD_H
11647 +#define _VX_INODE_CMD_H
11648 +
11649 +
11650 +/*  inode vserver commands */
11651 +
11652 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
11653 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
11654 +
11655 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
11656 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
11657 +
11658 +struct vcmd_ctx_iattr_v1 {
11659 +       const char __user *name;
11660 +       uint32_t tag;
11661 +       uint32_t flags;
11662 +       uint32_t mask;
11663 +};
11664 +
11665 +struct vcmd_ctx_fiattr_v0 {
11666 +       uint32_t tag;
11667 +       uint32_t flags;
11668 +       uint32_t mask;
11669 +};
11670 +
11671 +
11672 +#ifdef __KERNEL__
11673 +
11674 +
11675 +#ifdef CONFIG_COMPAT
11676 +
11677 +#include <asm/compat.h>
11678 +
11679 +struct vcmd_ctx_iattr_v1_x32 {
11680 +       compat_uptr_t name_ptr;
11681 +       uint32_t tag;
11682 +       uint32_t flags;
11683 +       uint32_t mask;
11684 +};
11685 +
11686 +#endif /* CONFIG_COMPAT */
11687 +
11688 +#include <linux/compiler.h>
11689 +
11690 +extern int vc_get_iattr(void __user *);
11691 +extern int vc_set_iattr(void __user *);
11692 +
11693 +extern int vc_fget_iattr(uint32_t, void __user *);
11694 +extern int vc_fset_iattr(uint32_t, void __user *);
11695 +
11696 +#ifdef CONFIG_COMPAT
11697 +
11698 +extern int vc_get_iattr_x32(void __user *);
11699 +extern int vc_set_iattr_x32(void __user *);
11700 +
11701 +#endif /* CONFIG_COMPAT */
11702 +
11703 +#endif /* __KERNEL__ */
11704 +#endif /* _VX_INODE_CMD_H */
11705 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/inode.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/inode.h
11706 --- linux-2.6.36/include/linux/vserver/inode.h  1970-01-01 01:00:00.000000000 +0100
11707 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/inode.h    2010-10-21 13:09:36.000000000 +0200
11708 @@ -0,0 +1,39 @@
11709 +#ifndef _VX_INODE_H
11710 +#define _VX_INODE_H
11711 +
11712 +
11713 +#define IATTR_TAG      0x01000000
11714 +
11715 +#define IATTR_ADMIN    0x00000001
11716 +#define IATTR_WATCH    0x00000002
11717 +#define IATTR_HIDE     0x00000004
11718 +#define IATTR_FLAGS    0x00000007
11719 +
11720 +#define IATTR_BARRIER  0x00010000
11721 +#define IATTR_IXUNLINK 0x00020000
11722 +#define IATTR_IMMUTABLE 0x00040000
11723 +#define IATTR_COW      0x00080000
11724 +
11725 +#ifdef __KERNEL__
11726 +
11727 +
11728 +#ifdef CONFIG_VSERVER_PROC_SECURE
11729 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
11730 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11731 +#else
11732 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
11733 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11734 +#endif
11735 +
11736 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
11737 +
11738 +#endif /* __KERNEL__ */
11739 +
11740 +/* inode ioctls */
11741 +
11742 +#define FIOC_GETXFLG   _IOR('x', 5, long)
11743 +#define FIOC_SETXFLG   _IOW('x', 6, long)
11744 +
11745 +#else  /* _VX_INODE_H */
11746 +#warning duplicate inclusion
11747 +#endif /* _VX_INODE_H */
11748 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/Kbuild linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/Kbuild
11749 --- linux-2.6.36/include/linux/vserver/Kbuild   1970-01-01 01:00:00.000000000 +0100
11750 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/Kbuild     2010-10-21 13:09:36.000000000 +0200
11751 @@ -0,0 +1,8 @@
11752 +
11753 +unifdef-y += context_cmd.h network_cmd.h space_cmd.h \
11754 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
11755 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
11756 +       debug_cmd.h device_cmd.h
11757 +
11758 +unifdef-y += switch.h network.h monitor.h inode.h device.h
11759 +
11760 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/limit_cmd.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/limit_cmd.h
11761 --- linux-2.6.36/include/linux/vserver/limit_cmd.h      1970-01-01 01:00:00.000000000 +0100
11762 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/limit_cmd.h        2010-10-21 13:09:36.000000000 +0200
11763 @@ -0,0 +1,71 @@
11764 +#ifndef _VX_LIMIT_CMD_H
11765 +#define _VX_LIMIT_CMD_H
11766 +
11767 +
11768 +/*  rlimit vserver commands */
11769 +
11770 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
11771 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
11772 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
11773 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
11774 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
11775 +
11776 +struct vcmd_ctx_rlimit_v0 {
11777 +       uint32_t id;
11778 +       uint64_t minimum;
11779 +       uint64_t softlimit;
11780 +       uint64_t maximum;
11781 +};
11782 +
11783 +struct vcmd_ctx_rlimit_mask_v0 {
11784 +       uint32_t minimum;
11785 +       uint32_t softlimit;
11786 +       uint32_t maximum;
11787 +};
11788 +
11789 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
11790 +
11791 +struct vcmd_rlimit_stat_v0 {
11792 +       uint32_t id;
11793 +       uint32_t hits;
11794 +       uint64_t value;
11795 +       uint64_t minimum;
11796 +       uint64_t maximum;
11797 +};
11798 +
11799 +#define CRLIM_UNSET            (0ULL)
11800 +#define CRLIM_INFINITY         (~0ULL)
11801 +#define CRLIM_KEEP             (~1ULL)
11802 +
11803 +#ifdef __KERNEL__
11804 +
11805 +#ifdef CONFIG_IA32_EMULATION
11806 +
11807 +struct vcmd_ctx_rlimit_v0_x32 {
11808 +       uint32_t id;
11809 +       uint64_t minimum;
11810 +       uint64_t softlimit;
11811 +       uint64_t maximum;
11812 +} __attribute__ ((packed));
11813 +
11814 +#endif /* CONFIG_IA32_EMULATION */
11815 +
11816 +#include <linux/compiler.h>
11817 +
11818 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
11819 +extern int vc_get_rlimit(struct vx_info *, void __user *);
11820 +extern int vc_set_rlimit(struct vx_info *, void __user *);
11821 +extern int vc_reset_hits(struct vx_info *, void __user *);
11822 +extern int vc_reset_minmax(struct vx_info *, void __user *);
11823 +
11824 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
11825 +
11826 +#ifdef CONFIG_IA32_EMULATION
11827 +
11828 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
11829 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
11830 +
11831 +#endif /* CONFIG_IA32_EMULATION */
11832 +
11833 +#endif /* __KERNEL__ */
11834 +#endif /* _VX_LIMIT_CMD_H */
11835 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/limit_def.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/limit_def.h
11836 --- linux-2.6.36/include/linux/vserver/limit_def.h      1970-01-01 01:00:00.000000000 +0100
11837 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/limit_def.h        2010-10-21 13:09:36.000000000 +0200
11838 @@ -0,0 +1,47 @@
11839 +#ifndef _VX_LIMIT_DEF_H
11840 +#define _VX_LIMIT_DEF_H
11841 +
11842 +#include <asm/atomic.h>
11843 +#include <asm/resource.h>
11844 +
11845 +#include "limit.h"
11846 +
11847 +
11848 +struct _vx_res_limit {
11849 +       rlim_t soft;            /* Context soft limit */
11850 +       rlim_t hard;            /* Context hard limit */
11851 +
11852 +       rlim_atomic_t rcur;     /* Current value */
11853 +       rlim_t rmin;            /* Context minimum */
11854 +       rlim_t rmax;            /* Context maximum */
11855 +
11856 +       atomic_t lhit;          /* Limit hits */
11857 +};
11858 +
11859 +/* context sub struct */
11860 +
11861 +struct _vx_limit {
11862 +       struct _vx_res_limit res[NUM_LIMITS];
11863 +};
11864 +
11865 +#ifdef CONFIG_VSERVER_DEBUG
11866 +
11867 +static inline void __dump_vx_limit(struct _vx_limit *limit)
11868 +{
11869 +       int i;
11870 +
11871 +       printk("\t_vx_limit:");
11872 +       for (i = 0; i < NUM_LIMITS; i++) {
11873 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
11874 +                       i, (unsigned long)__rlim_get(limit, i),
11875 +                       (unsigned long)__rlim_rmin(limit, i),
11876 +                       (unsigned long)__rlim_rmax(limit, i),
11877 +                       (long)__rlim_soft(limit, i),
11878 +                       (long)__rlim_hard(limit, i),
11879 +                       atomic_read(&__rlim_lhit(limit, i)));
11880 +       }
11881 +}
11882 +
11883 +#endif
11884 +
11885 +#endif /* _VX_LIMIT_DEF_H */
11886 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/limit.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/limit.h
11887 --- linux-2.6.36/include/linux/vserver/limit.h  1970-01-01 01:00:00.000000000 +0100
11888 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/limit.h    2010-10-21 13:09:36.000000000 +0200
11889 @@ -0,0 +1,71 @@
11890 +#ifndef _VX_LIMIT_H
11891 +#define _VX_LIMIT_H
11892 +
11893 +#define VLIMIT_NSOCK   16
11894 +#define VLIMIT_OPENFD  17
11895 +#define VLIMIT_ANON    18
11896 +#define VLIMIT_SHMEM   19
11897 +#define VLIMIT_SEMARY  20
11898 +#define VLIMIT_NSEMS   21
11899 +#define VLIMIT_DENTRY  22
11900 +#define VLIMIT_MAPPED  23
11901 +
11902 +
11903 +#ifdef __KERNEL__
11904 +
11905 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
11906 +
11907 +/*     keep in sync with CRLIM_INFINITY */
11908 +
11909 +#define        VLIM_INFINITY   (~0ULL)
11910 +
11911 +#include <asm/atomic.h>
11912 +#include <asm/resource.h>
11913 +
11914 +#ifndef RLIM_INFINITY
11915 +#warning RLIM_INFINITY is undefined
11916 +#endif
11917 +
11918 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
11919 +
11920 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
11921 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
11922 +
11923 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
11924 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
11925 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
11926 +
11927 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
11928 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
11929 +
11930 +typedef atomic_long_t rlim_atomic_t;
11931 +typedef unsigned long rlim_t;
11932 +
11933 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
11934 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
11935 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
11936 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
11937 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
11938 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
11939 +
11940 +
11941 +#if    (RLIM_INFINITY == VLIM_INFINITY)
11942 +#define        VX_VLIM(r) ((long long)(long)(r))
11943 +#define        VX_RLIM(v) ((rlim_t)(v))
11944 +#else
11945 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
11946 +               ? VLIM_INFINITY : (long long)(r))
11947 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
11948 +               ? RLIM_INFINITY : (rlim_t)(v))
11949 +#endif
11950 +
11951 +struct sysinfo;
11952 +
11953 +void vx_vsi_meminfo(struct sysinfo *);
11954 +void vx_vsi_swapinfo(struct sysinfo *);
11955 +long vx_vsi_cached(struct sysinfo *);
11956 +
11957 +#define NUM_LIMITS     24
11958 +
11959 +#endif /* __KERNEL__ */
11960 +#endif /* _VX_LIMIT_H */
11961 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/limit_int.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/limit_int.h
11962 --- linux-2.6.36/include/linux/vserver/limit_int.h      1970-01-01 01:00:00.000000000 +0100
11963 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/limit_int.h        2010-10-21 13:09:36.000000000 +0200
11964 @@ -0,0 +1,198 @@
11965 +#ifndef _VX_LIMIT_INT_H
11966 +#define _VX_LIMIT_INT_H
11967 +
11968 +#include "context.h"
11969 +
11970 +#ifdef __KERNEL__
11971 +
11972 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
11973 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
11974 +
11975 +extern const char *vlimit_name[NUM_LIMITS];
11976 +
11977 +static inline void __vx_acc_cres(struct vx_info *vxi,
11978 +       int res, int dir, void *_data, char *_file, int _line)
11979 +{
11980 +       if (VXD_RCRES_COND(res))
11981 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
11982 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11983 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11984 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
11985 +       if (!vxi)
11986 +               return;
11987 +
11988 +       if (dir > 0)
11989 +               __rlim_inc(&vxi->limit, res);
11990 +       else
11991 +               __rlim_dec(&vxi->limit, res);
11992 +}
11993 +
11994 +static inline void __vx_add_cres(struct vx_info *vxi,
11995 +       int res, int amount, void *_data, char *_file, int _line)
11996 +{
11997 +       if (VXD_RCRES_COND(res))
11998 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
11999 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12000 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12001 +                       amount, _data, _file, _line);
12002 +       if (amount == 0)
12003 +               return;
12004 +       if (!vxi)
12005 +               return;
12006 +       __rlim_add(&vxi->limit, res, amount);
12007 +}
12008 +
12009 +static inline
12010 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
12011 +{
12012 +       int cond = (value > __rlim_rmax(limit, res));
12013 +
12014 +       if (cond)
12015 +               __rlim_rmax(limit, res) = value;
12016 +       return cond;
12017 +}
12018 +
12019 +static inline
12020 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
12021 +{
12022 +       int cond = (value < __rlim_rmin(limit, res));
12023 +
12024 +       if (cond)
12025 +               __rlim_rmin(limit, res) = value;
12026 +       return cond;
12027 +}
12028 +
12029 +static inline
12030 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
12031 +{
12032 +       if (!__vx_cres_adjust_max(limit, res, value))
12033 +               __vx_cres_adjust_min(limit, res, value);
12034 +}
12035 +
12036 +
12037 +/*     return values:
12038 +        +1 ... no limit hit
12039 +        -1 ... over soft limit
12040 +         0 ... over hard limit         */
12041 +
12042 +static inline int __vx_cres_avail(struct vx_info *vxi,
12043 +       int res, int num, char *_file, int _line)
12044 +{
12045 +       struct _vx_limit *limit;
12046 +       rlim_t value;
12047 +
12048 +       if (VXD_RLIMIT_COND(res))
12049 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
12050 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12051 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
12052 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
12053 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12054 +                       num, _file, _line);
12055 +       if (!vxi)
12056 +               return 1;
12057 +
12058 +       limit = &vxi->limit;
12059 +       value = __rlim_get(limit, res);
12060 +
12061 +       if (!__vx_cres_adjust_max(limit, res, value))
12062 +               __vx_cres_adjust_min(limit, res, value);
12063 +
12064 +       if (num == 0)
12065 +               return 1;
12066 +
12067 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
12068 +               return -1;
12069 +       if (value + num <= __rlim_soft(limit, res))
12070 +               return -1;
12071 +
12072 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
12073 +               return 1;
12074 +       if (value + num <= __rlim_hard(limit, res))
12075 +               return 1;
12076 +
12077 +       __rlim_hit(limit, res);
12078 +       return 0;
12079 +}
12080 +
12081 +
12082 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
12083 +
12084 +static inline
12085 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
12086 +{
12087 +       rlim_t value, sum = 0;
12088 +       int res;
12089 +
12090 +       while ((res = *array++)) {
12091 +               value = __rlim_get(limit, res);
12092 +               __vx_cres_fixup(limit, res, value);
12093 +               sum += value;
12094 +       }
12095 +       return sum;
12096 +}
12097 +
12098 +static inline
12099 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
12100 +{
12101 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
12102 +       int res = *array;
12103 +
12104 +       if (value == __rlim_get(limit, res))
12105 +               return value;
12106 +
12107 +       __rlim_set(limit, res, value);
12108 +       /* now adjust min/max */
12109 +       if (!__vx_cres_adjust_max(limit, res, value))
12110 +               __vx_cres_adjust_min(limit, res, value);
12111 +
12112 +       return value;
12113 +}
12114 +
12115 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
12116 +       const int *array, int num, char *_file, int _line)
12117 +{
12118 +       struct _vx_limit *limit;
12119 +       rlim_t value = 0;
12120 +       int res;
12121 +
12122 +       if (num == 0)
12123 +               return 1;
12124 +       if (!vxi)
12125 +               return 1;
12126 +
12127 +       limit = &vxi->limit;
12128 +       res = *array;
12129 +       value = __vx_cres_array_sum(limit, array + 1);
12130 +
12131 +       __rlim_set(limit, res, value);
12132 +       __vx_cres_fixup(limit, res, value);
12133 +
12134 +       return __vx_cres_avail(vxi, res, num, _file, _line);
12135 +}
12136 +
12137 +
12138 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
12139 +{
12140 +       rlim_t value;
12141 +       int res;
12142 +
12143 +       /* complex resources first */
12144 +       if ((id < 0) || (id == RLIMIT_RSS))
12145 +               __vx_cres_array_fixup(limit, VLA_RSS);
12146 +
12147 +       for (res = 0; res < NUM_LIMITS; res++) {
12148 +               if ((id > 0) && (res != id))
12149 +                       continue;
12150 +
12151 +               value = __rlim_get(limit, res);
12152 +               __vx_cres_fixup(limit, res, value);
12153 +
12154 +               /* not supposed to happen, maybe warn? */
12155 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
12156 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
12157 +       }
12158 +}
12159 +
12160 +
12161 +#endif /* __KERNEL__ */
12162 +#endif /* _VX_LIMIT_INT_H */
12163 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/monitor.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/monitor.h
12164 --- linux-2.6.36/include/linux/vserver/monitor.h        1970-01-01 01:00:00.000000000 +0100
12165 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/monitor.h  2010-10-21 13:09:36.000000000 +0200
12166 @@ -0,0 +1,96 @@
12167 +#ifndef _VX_MONITOR_H
12168 +#define _VX_MONITOR_H
12169 +
12170 +#include <linux/types.h>
12171 +
12172 +enum {
12173 +       VXM_UNUSED = 0,
12174 +
12175 +       VXM_SYNC = 0x10,
12176 +
12177 +       VXM_UPDATE = 0x20,
12178 +       VXM_UPDATE_1,
12179 +       VXM_UPDATE_2,
12180 +
12181 +       VXM_RQINFO_1 = 0x24,
12182 +       VXM_RQINFO_2,
12183 +
12184 +       VXM_ACTIVATE = 0x40,
12185 +       VXM_DEACTIVATE,
12186 +       VXM_IDLE,
12187 +
12188 +       VXM_HOLD = 0x44,
12189 +       VXM_UNHOLD,
12190 +
12191 +       VXM_MIGRATE = 0x48,
12192 +       VXM_RESCHED,
12193 +
12194 +       /* all other bits are flags */
12195 +       VXM_SCHED = 0x80,
12196 +};
12197 +
12198 +struct _vxm_update_1 {
12199 +       uint32_t tokens_max;
12200 +       uint32_t fill_rate;
12201 +       uint32_t interval;
12202 +};
12203 +
12204 +struct _vxm_update_2 {
12205 +       uint32_t tokens_min;
12206 +       uint32_t fill_rate;
12207 +       uint32_t interval;
12208 +};
12209 +
12210 +struct _vxm_rqinfo_1 {
12211 +       uint16_t running;
12212 +       uint16_t onhold;
12213 +       uint16_t iowait;
12214 +       uint16_t uintr;
12215 +       uint32_t idle_tokens;
12216 +};
12217 +
12218 +struct _vxm_rqinfo_2 {
12219 +       uint32_t norm_time;
12220 +       uint32_t idle_time;
12221 +       uint32_t idle_skip;
12222 +};
12223 +
12224 +struct _vxm_sched {
12225 +       uint32_t tokens;
12226 +       uint32_t norm_time;
12227 +       uint32_t idle_time;
12228 +};
12229 +
12230 +struct _vxm_task {
12231 +       uint16_t pid;
12232 +       uint16_t state;
12233 +};
12234 +
12235 +struct _vxm_event {
12236 +       uint32_t jif;
12237 +       union {
12238 +               uint32_t seq;
12239 +               uint32_t sec;
12240 +       };
12241 +       union {
12242 +               uint32_t tokens;
12243 +               uint32_t nsec;
12244 +               struct _vxm_task tsk;
12245 +       };
12246 +};
12247 +
12248 +struct _vx_mon_entry {
12249 +       uint16_t type;
12250 +       uint16_t xid;
12251 +       union {
12252 +               struct _vxm_event ev;
12253 +               struct _vxm_sched sd;
12254 +               struct _vxm_update_1 u1;
12255 +               struct _vxm_update_2 u2;
12256 +               struct _vxm_rqinfo_1 q1;
12257 +               struct _vxm_rqinfo_2 q2;
12258 +       };
12259 +};
12260 +
12261 +
12262 +#endif /* _VX_MONITOR_H */
12263 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/network_cmd.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/network_cmd.h
12264 --- linux-2.6.36/include/linux/vserver/network_cmd.h    1970-01-01 01:00:00.000000000 +0100
12265 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/network_cmd.h      2010-10-21 13:09:36.000000000 +0200
12266 @@ -0,0 +1,150 @@
12267 +#ifndef _VX_NETWORK_CMD_H
12268 +#define _VX_NETWORK_CMD_H
12269 +
12270 +
12271 +/* vinfo commands */
12272 +
12273 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
12274 +
12275 +#ifdef __KERNEL__
12276 +extern int vc_task_nid(uint32_t);
12277 +
12278 +#endif /* __KERNEL__ */
12279 +
12280 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
12281 +
12282 +struct vcmd_nx_info_v0 {
12283 +       uint32_t nid;
12284 +       /* more to come */
12285 +};
12286 +
12287 +#ifdef __KERNEL__
12288 +extern int vc_nx_info(struct nx_info *, void __user *);
12289 +
12290 +#endif /* __KERNEL__ */
12291 +
12292 +#include <linux/in.h>
12293 +#include <linux/in6.h>
12294 +
12295 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
12296 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
12297 +
12298 +struct  vcmd_net_create {
12299 +       uint64_t flagword;
12300 +};
12301 +
12302 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
12303 +
12304 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
12305 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
12306 +
12307 +struct vcmd_net_addr_v0 {
12308 +       uint16_t type;
12309 +       uint16_t count;
12310 +       struct in_addr ip[4];
12311 +       struct in_addr mask[4];
12312 +};
12313 +
12314 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 1)
12315 +#define VCMD_net_remove_ipv4   VC_CMD(NETALT, 2, 1)
12316 +
12317 +struct vcmd_net_addr_ipv4_v1 {
12318 +       uint16_t type;
12319 +       uint16_t flags;
12320 +       struct in_addr ip;
12321 +       struct in_addr mask;
12322 +};
12323 +
12324 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
12325 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
12326 +
12327 +struct vcmd_net_addr_ipv6_v1 {
12328 +       uint16_t type;
12329 +       uint16_t flags;
12330 +       uint32_t prefix;
12331 +       struct in6_addr ip;
12332 +       struct in6_addr mask;
12333 +};
12334 +
12335 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
12336 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
12337 +
12338 +struct vcmd_match_ipv4_v0 {
12339 +       uint16_t type;
12340 +       uint16_t flags;
12341 +       uint16_t parent;
12342 +       uint16_t prefix;
12343 +       struct in_addr ip;
12344 +       struct in_addr ip2;
12345 +       struct in_addr mask;
12346 +};
12347 +
12348 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
12349 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
12350 +
12351 +struct vcmd_match_ipv6_v0 {
12352 +       uint16_t type;
12353 +       uint16_t flags;
12354 +       uint16_t parent;
12355 +       uint16_t prefix;
12356 +       struct in6_addr ip;
12357 +       struct in6_addr ip2;
12358 +       struct in6_addr mask;
12359 +};
12360 +
12361 +
12362 +#ifdef __KERNEL__
12363 +extern int vc_net_create(uint32_t, void __user *);
12364 +extern int vc_net_migrate(struct nx_info *, void __user *);
12365 +
12366 +extern int vc_net_add(struct nx_info *, void __user *);
12367 +extern int vc_net_remove(struct nx_info *, void __user *);
12368 +
12369 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
12370 +extern int vc_net_remove_ipv4(struct nx_info *, void __user *);
12371 +
12372 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
12373 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
12374 +
12375 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
12376 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
12377 +
12378 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
12379 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
12380 +
12381 +#endif /* __KERNEL__ */
12382 +
12383 +
12384 +/* flag commands */
12385 +
12386 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
12387 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
12388 +
12389 +struct vcmd_net_flags_v0 {
12390 +       uint64_t flagword;
12391 +       uint64_t mask;
12392 +};
12393 +
12394 +#ifdef __KERNEL__
12395 +extern int vc_get_nflags(struct nx_info *, void __user *);
12396 +extern int vc_set_nflags(struct nx_info *, void __user *);
12397 +
12398 +#endif /* __KERNEL__ */
12399 +
12400 +
12401 +/* network caps commands */
12402 +
12403 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
12404 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
12405 +
12406 +struct vcmd_net_caps_v0 {
12407 +       uint64_t ncaps;
12408 +       uint64_t cmask;
12409 +};
12410 +
12411 +#ifdef __KERNEL__
12412 +extern int vc_get_ncaps(struct nx_info *, void __user *);
12413 +extern int vc_set_ncaps(struct nx_info *, void __user *);
12414 +
12415 +#endif /* __KERNEL__ */
12416 +#endif /* _VX_CONTEXT_CMD_H */
12417 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/network.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/network.h
12418 --- linux-2.6.36/include/linux/vserver/network.h        1970-01-01 01:00:00.000000000 +0100
12419 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/network.h  2010-10-21 13:09:36.000000000 +0200
12420 @@ -0,0 +1,146 @@
12421 +#ifndef _VX_NETWORK_H
12422 +#define _VX_NETWORK_H
12423 +
12424 +#include <linux/types.h>
12425 +
12426 +
12427 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
12428 +
12429 +
12430 +/* network flags */
12431 +
12432 +#define NXF_INFO_PRIVATE       0x00000008
12433 +
12434 +#define NXF_SINGLE_IP          0x00000100
12435 +#define NXF_LBACK_REMAP                0x00000200
12436 +#define NXF_LBACK_ALLOW                0x00000400
12437 +
12438 +#define NXF_HIDE_NETIF         0x02000000
12439 +#define NXF_HIDE_LBACK         0x04000000
12440 +
12441 +#define NXF_STATE_SETUP                (1ULL << 32)
12442 +#define NXF_STATE_ADMIN                (1ULL << 34)
12443 +
12444 +#define NXF_SC_HELPER          (1ULL << 36)
12445 +#define NXF_PERSISTENT         (1ULL << 38)
12446 +
12447 +#define NXF_ONE_TIME           (0x0005ULL << 32)
12448 +
12449 +
12450 +#define        NXF_INIT_SET            (__nxf_init_set())
12451 +
12452 +static inline uint64_t __nxf_init_set(void) {
12453 +       return    NXF_STATE_ADMIN
12454 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12455 +               | NXF_LBACK_REMAP
12456 +               | NXF_HIDE_LBACK
12457 +#endif
12458 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12459 +               | NXF_SINGLE_IP
12460 +#endif
12461 +               | NXF_HIDE_NETIF;
12462 +}
12463 +
12464 +
12465 +/* network caps */
12466 +
12467 +#define NXC_TUN_CREATE         0x00000001
12468 +
12469 +#define NXC_RAW_ICMP           0x00000100
12470 +
12471 +
12472 +/* address types */
12473 +
12474 +#define NXA_TYPE_IPV4          0x0001
12475 +#define NXA_TYPE_IPV6          0x0002
12476 +
12477 +#define NXA_TYPE_NONE          0x0000
12478 +#define NXA_TYPE_ANY           0x00FF
12479 +
12480 +#define NXA_TYPE_ADDR          0x0010
12481 +#define NXA_TYPE_MASK          0x0020
12482 +#define NXA_TYPE_RANGE         0x0040
12483 +
12484 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12485 +
12486 +#define NXA_MOD_BCAST          0x0100
12487 +#define NXA_MOD_LBACK          0x0200
12488 +
12489 +#define NXA_LOOPBACK           0x1000
12490 +
12491 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12492 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
12493 +
12494 +#ifdef __KERNEL__
12495 +
12496 +#include <linux/list.h>
12497 +#include <linux/spinlock.h>
12498 +#include <linux/rcupdate.h>
12499 +#include <linux/in.h>
12500 +#include <linux/in6.h>
12501 +#include <asm/atomic.h>
12502 +
12503 +struct nx_addr_v4 {
12504 +       struct nx_addr_v4 *next;
12505 +       struct in_addr ip[2];
12506 +       struct in_addr mask;
12507 +       uint16_t type;
12508 +       uint16_t flags;
12509 +};
12510 +
12511 +struct nx_addr_v6 {
12512 +       struct nx_addr_v6 *next;
12513 +       struct in6_addr ip;
12514 +       struct in6_addr mask;
12515 +       uint32_t prefix;
12516 +       uint16_t type;
12517 +       uint16_t flags;
12518 +};
12519 +
12520 +struct nx_info {
12521 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
12522 +       nid_t nx_id;                    /* vnet id */
12523 +       atomic_t nx_usecnt;             /* usage count */
12524 +       atomic_t nx_tasks;              /* tasks count */
12525 +       int nx_state;                   /* context state */
12526 +
12527 +       uint64_t nx_flags;              /* network flag word */
12528 +       uint64_t nx_ncaps;              /* network capabilities */
12529 +
12530 +       struct in_addr v4_lback;        /* Loopback address */
12531 +       struct in_addr v4_bcast;        /* Broadcast address */
12532 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
12533 +#ifdef CONFIG_IPV6
12534 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
12535 +#endif
12536 +       char nx_name[65];               /* network context name */
12537 +};
12538 +
12539 +
12540 +/* status flags */
12541 +
12542 +#define NXS_HASHED      0x0001
12543 +#define NXS_SHUTDOWN    0x0100
12544 +#define NXS_RELEASED    0x8000
12545 +
12546 +extern struct nx_info *lookup_nx_info(int);
12547 +
12548 +extern int get_nid_list(int, unsigned int *, int);
12549 +extern int nid_is_hashed(nid_t);
12550 +
12551 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
12552 +
12553 +extern long vs_net_change(struct nx_info *, unsigned int);
12554 +
12555 +struct sock;
12556 +
12557 +
12558 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
12559 +#ifdef  CONFIG_IPV6
12560 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
12561 +#else
12562 +#define NX_IPV6(n)     (0)
12563 +#endif
12564 +
12565 +#endif /* __KERNEL__ */
12566 +#endif /* _VX_NETWORK_H */
12567 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/percpu.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/percpu.h
12568 --- linux-2.6.36/include/linux/vserver/percpu.h 1970-01-01 01:00:00.000000000 +0100
12569 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/percpu.h   2010-10-21 13:09:36.000000000 +0200
12570 @@ -0,0 +1,14 @@
12571 +#ifndef _VX_PERCPU_H
12572 +#define _VX_PERCPU_H
12573 +
12574 +#include "cvirt_def.h"
12575 +#include "sched_def.h"
12576 +
12577 +struct _vx_percpu {
12578 +       struct _vx_cvirt_pc cvirt;
12579 +       struct _vx_sched_pc sched;
12580 +};
12581 +
12582 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
12583 +
12584 +#endif /* _VX_PERCPU_H */
12585 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/pid.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/pid.h
12586 --- linux-2.6.36/include/linux/vserver/pid.h    1970-01-01 01:00:00.000000000 +0100
12587 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/pid.h      2010-10-21 13:09:36.000000000 +0200
12588 @@ -0,0 +1,51 @@
12589 +#ifndef _VSERVER_PID_H
12590 +#define _VSERVER_PID_H
12591 +
12592 +/* pid faking stuff */
12593 +
12594 +#define vx_info_map_pid(v, p) \
12595 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
12596 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
12597 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
12598 +#define vx_map_tgid(p) vx_map_pid(p)
12599 +
12600 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
12601 +       const char *func, const char *file, int line)
12602 +{
12603 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12604 +               vxfprintk(VXD_CBIT(cvirt, 2),
12605 +                       "vx_map_tgid: %p/%llx: %d -> %d",
12606 +                       vxi, (long long)vxi->vx_flags, pid,
12607 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
12608 +                       func, file, line);
12609 +               if (pid == 0)
12610 +                       return 0;
12611 +               if (pid == vxi->vx_initpid)
12612 +                       return 1;
12613 +       }
12614 +       return pid;
12615 +}
12616 +
12617 +#define vx_info_rmap_pid(v, p) \
12618 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
12619 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
12620 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
12621 +
12622 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
12623 +       const char *func, const char *file, int line)
12624 +{
12625 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12626 +               vxfprintk(VXD_CBIT(cvirt, 2),
12627 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
12628 +                       vxi, (long long)vxi->vx_flags, pid,
12629 +                       (pid == 1) ? vxi->vx_initpid : pid,
12630 +                       func, file, line);
12631 +               if ((pid == 1) && vxi->vx_initpid)
12632 +                       return vxi->vx_initpid;
12633 +               if (pid == vxi->vx_initpid)
12634 +                       return ~0U;
12635 +       }
12636 +       return pid;
12637 +}
12638 +
12639 +#endif
12640 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/sched_cmd.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/sched_cmd.h
12641 --- linux-2.6.36/include/linux/vserver/sched_cmd.h      1970-01-01 01:00:00.000000000 +0100
12642 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/sched_cmd.h        2010-10-21 13:09:36.000000000 +0200
12643 @@ -0,0 +1,108 @@
12644 +#ifndef _VX_SCHED_CMD_H
12645 +#define _VX_SCHED_CMD_H
12646 +
12647 +
12648 +/*  sched vserver commands */
12649 +
12650 +#define VCMD_set_sched_v2      VC_CMD(SCHED, 1, 2)
12651 +#define VCMD_set_sched_v3      VC_CMD(SCHED, 1, 3)
12652 +#define VCMD_set_sched_v4      VC_CMD(SCHED, 1, 4)
12653 +
12654 +struct vcmd_set_sched_v2 {
12655 +       int32_t fill_rate;
12656 +       int32_t interval;
12657 +       int32_t tokens;
12658 +       int32_t tokens_min;
12659 +       int32_t tokens_max;
12660 +       uint64_t cpu_mask;
12661 +};
12662 +
12663 +struct vcmd_set_sched_v3 {
12664 +       uint32_t set_mask;
12665 +       int32_t fill_rate;
12666 +       int32_t interval;
12667 +       int32_t tokens;
12668 +       int32_t tokens_min;
12669 +       int32_t tokens_max;
12670 +       int32_t priority_bias;
12671 +};
12672 +
12673 +struct vcmd_set_sched_v4 {
12674 +       uint32_t set_mask;
12675 +       int32_t fill_rate;
12676 +       int32_t interval;
12677 +       int32_t tokens;
12678 +       int32_t tokens_min;
12679 +       int32_t tokens_max;
12680 +       int32_t prio_bias;
12681 +       int32_t cpu_id;
12682 +       int32_t bucket_id;
12683 +};
12684 +
12685 +#define VCMD_set_sched         VC_CMD(SCHED, 1, 5)
12686 +#define VCMD_get_sched         VC_CMD(SCHED, 2, 5)
12687 +
12688 +struct vcmd_sched_v5 {
12689 +       uint32_t mask;
12690 +       int32_t cpu_id;
12691 +       int32_t bucket_id;
12692 +       int32_t fill_rate[2];
12693 +       int32_t interval[2];
12694 +       int32_t tokens;
12695 +       int32_t tokens_min;
12696 +       int32_t tokens_max;
12697 +       int32_t prio_bias;
12698 +};
12699 +
12700 +#define VXSM_FILL_RATE         0x0001
12701 +#define VXSM_INTERVAL          0x0002
12702 +#define VXSM_FILL_RATE2                0x0004
12703 +#define VXSM_INTERVAL2         0x0008
12704 +#define VXSM_TOKENS            0x0010
12705 +#define VXSM_TOKENS_MIN                0x0020
12706 +#define VXSM_TOKENS_MAX                0x0040
12707 +#define VXSM_PRIO_BIAS         0x0100
12708 +
12709 +#define VXSM_IDLE_TIME         0x0200
12710 +#define VXSM_FORCE             0x0400
12711 +
12712 +#define        VXSM_V3_MASK            0x0173
12713 +#define        VXSM_SET_MASK           0x01FF
12714 +
12715 +#define VXSM_CPU_ID            0x1000
12716 +#define VXSM_BUCKET_ID         0x2000
12717 +
12718 +#define VXSM_MSEC              0x4000
12719 +
12720 +#define SCHED_KEEP             (-2)    /* only for v2 */
12721 +
12722 +#ifdef __KERNEL__
12723 +
12724 +#include <linux/compiler.h>
12725 +
12726 +extern int vc_set_sched_v2(struct vx_info *, void __user *);
12727 +extern int vc_set_sched_v3(struct vx_info *, void __user *);
12728 +extern int vc_set_sched_v4(struct vx_info *, void __user *);
12729 +extern int vc_set_sched(struct vx_info *, void __user *);
12730 +extern int vc_get_sched(struct vx_info *, void __user *);
12731 +
12732 +#endif /* __KERNEL__ */
12733 +
12734 +#define VCMD_sched_info                VC_CMD(SCHED, 3, 0)
12735 +
12736 +struct vcmd_sched_info {
12737 +       int32_t cpu_id;
12738 +       int32_t bucket_id;
12739 +       uint64_t user_msec;
12740 +       uint64_t sys_msec;
12741 +       uint64_t hold_msec;
12742 +       uint32_t token_usec;
12743 +       int32_t vavavoom;
12744 +};
12745 +
12746 +#ifdef __KERNEL__
12747 +
12748 +extern int vc_sched_info(struct vx_info *, void __user *);
12749 +
12750 +#endif /* __KERNEL__ */
12751 +#endif /* _VX_SCHED_CMD_H */
12752 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/sched_def.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/sched_def.h
12753 --- linux-2.6.36/include/linux/vserver/sched_def.h      1970-01-01 01:00:00.000000000 +0100
12754 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/sched_def.h        2010-10-21 13:09:36.000000000 +0200
12755 @@ -0,0 +1,68 @@
12756 +#ifndef _VX_SCHED_DEF_H
12757 +#define _VX_SCHED_DEF_H
12758 +
12759 +#include <linux/spinlock.h>
12760 +#include <linux/jiffies.h>
12761 +#include <linux/cpumask.h>
12762 +#include <asm/atomic.h>
12763 +#include <asm/param.h>
12764 +
12765 +
12766 +/* context sub struct */
12767 +
12768 +struct _vx_sched {
12769 +       spinlock_t tokens_lock;         /* lock for token bucket */
12770 +
12771 +       int tokens;                     /* number of CPU tokens */
12772 +       int fill_rate[2];               /* Fill rate: add X tokens... */
12773 +       int interval[2];                /* Divisor:   per Y jiffies   */
12774 +       int tokens_min;                 /* Limit:     minimum for unhold */
12775 +       int tokens_max;                 /* Limit:     no more than N tokens */
12776 +
12777 +       int prio_bias;                  /* bias offset for priority */
12778 +
12779 +       unsigned update_mask;           /* which features should be updated */
12780 +       cpumask_t update;               /* CPUs which should update */
12781 +};
12782 +
12783 +struct _vx_sched_pc {
12784 +       int tokens;                     /* number of CPU tokens */
12785 +       int flags;                      /* bucket flags */
12786 +
12787 +       int fill_rate[2];               /* Fill rate: add X tokens... */
12788 +       int interval[2];                /* Divisor:   per Y jiffies   */
12789 +       int tokens_min;                 /* Limit:     minimum for unhold */
12790 +       int tokens_max;                 /* Limit:     no more than N tokens */
12791 +
12792 +       int prio_bias;                  /* bias offset for priority */
12793 +       int vavavoom;                   /* last calculated vavavoom */
12794 +
12795 +       unsigned long norm_time;        /* last time accounted */
12796 +       unsigned long idle_time;        /* non linear time for fair sched */
12797 +       unsigned long token_time;       /* token time for accounting */
12798 +       unsigned long onhold;           /* jiffies when put on hold */
12799 +
12800 +       uint64_t user_ticks;            /* token tick events */
12801 +       uint64_t sys_ticks;             /* token tick events */
12802 +       uint64_t hold_ticks;            /* token ticks paused */
12803 +};
12804 +
12805 +
12806 +#define VXSF_ONHOLD    0x0001
12807 +#define VXSF_IDLE_TIME 0x0100
12808 +
12809 +#ifdef CONFIG_VSERVER_DEBUG
12810 +
12811 +static inline void __dump_vx_sched(struct _vx_sched *sched)
12812 +{
12813 +       printk("\t_vx_sched:\n");
12814 +       printk("\t tokens: %4d/%4d, %4d/%4d, %4d, %4d\n",
12815 +               sched->fill_rate[0], sched->interval[0],
12816 +               sched->fill_rate[1], sched->interval[1],
12817 +               sched->tokens_min, sched->tokens_max);
12818 +       printk("\t priority = %4d\n", sched->prio_bias);
12819 +}
12820 +
12821 +#endif
12822 +
12823 +#endif /* _VX_SCHED_DEF_H */
12824 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/sched.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/sched.h
12825 --- linux-2.6.36/include/linux/vserver/sched.h  1970-01-01 01:00:00.000000000 +0100
12826 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/sched.h    2010-10-21 13:09:36.000000000 +0200
12827 @@ -0,0 +1,26 @@
12828 +#ifndef _VX_SCHED_H
12829 +#define _VX_SCHED_H
12830 +
12831 +
12832 +#ifdef __KERNEL__
12833 +
12834 +struct timespec;
12835 +
12836 +void vx_vsi_uptime(struct timespec *, struct timespec *);
12837 +
12838 +
12839 +struct vx_info;
12840 +
12841 +void vx_update_load(struct vx_info *);
12842 +
12843 +
12844 +int vx_tokens_recalc(struct _vx_sched_pc *,
12845 +       unsigned long *, unsigned long *, int [2]);
12846 +
12847 +void vx_update_sched_param(struct _vx_sched *sched,
12848 +       struct _vx_sched_pc *sched_pc);
12849 +
12850 +#endif /* __KERNEL__ */
12851 +#else  /* _VX_SCHED_H */
12852 +#warning duplicate inclusion
12853 +#endif /* _VX_SCHED_H */
12854 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/signal_cmd.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/signal_cmd.h
12855 --- linux-2.6.36/include/linux/vserver/signal_cmd.h     1970-01-01 01:00:00.000000000 +0100
12856 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/signal_cmd.h       2010-10-21 13:09:36.000000000 +0200
12857 @@ -0,0 +1,43 @@
12858 +#ifndef _VX_SIGNAL_CMD_H
12859 +#define _VX_SIGNAL_CMD_H
12860 +
12861 +
12862 +/*  signalling vserver commands */
12863 +
12864 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
12865 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
12866 +
12867 +struct vcmd_ctx_kill_v0 {
12868 +       int32_t pid;
12869 +       int32_t sig;
12870 +};
12871 +
12872 +struct vcmd_wait_exit_v0 {
12873 +       int32_t reboot_cmd;
12874 +       int32_t exit_code;
12875 +};
12876 +
12877 +#ifdef __KERNEL__
12878 +
12879 +extern int vc_ctx_kill(struct vx_info *, void __user *);
12880 +extern int vc_wait_exit(struct vx_info *, void __user *);
12881 +
12882 +#endif /* __KERNEL__ */
12883 +
12884 +/*  process alteration commands */
12885 +
12886 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
12887 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
12888 +
12889 +struct vcmd_pflags_v0 {
12890 +       uint32_t flagword;
12891 +       uint32_t mask;
12892 +};
12893 +
12894 +#ifdef __KERNEL__
12895 +
12896 +extern int vc_get_pflags(uint32_t pid, void __user *);
12897 +extern int vc_set_pflags(uint32_t pid, void __user *);
12898 +
12899 +#endif /* __KERNEL__ */
12900 +#endif /* _VX_SIGNAL_CMD_H */
12901 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/signal.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/signal.h
12902 --- linux-2.6.36/include/linux/vserver/signal.h 1970-01-01 01:00:00.000000000 +0100
12903 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/signal.h   2010-10-21 13:09:36.000000000 +0200
12904 @@ -0,0 +1,14 @@
12905 +#ifndef _VX_SIGNAL_H
12906 +#define _VX_SIGNAL_H
12907 +
12908 +
12909 +#ifdef __KERNEL__
12910 +
12911 +struct vx_info;
12912 +
12913 +int vx_info_kill(struct vx_info *, int, int);
12914 +
12915 +#endif /* __KERNEL__ */
12916 +#else  /* _VX_SIGNAL_H */
12917 +#warning duplicate inclusion
12918 +#endif /* _VX_SIGNAL_H */
12919 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/space_cmd.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/space_cmd.h
12920 --- linux-2.6.36/include/linux/vserver/space_cmd.h      1970-01-01 01:00:00.000000000 +0100
12921 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/space_cmd.h        2010-10-21 13:09:36.000000000 +0200
12922 @@ -0,0 +1,38 @@
12923 +#ifndef _VX_SPACE_CMD_H
12924 +#define _VX_SPACE_CMD_H
12925 +
12926 +
12927 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
12928 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
12929 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
12930 +
12931 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
12932 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
12933 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
12934 +
12935 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
12936 +
12937 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
12938 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
12939 +
12940 +
12941 +struct vcmd_space_mask_v1 {
12942 +       uint64_t mask;
12943 +};
12944 +
12945 +struct vcmd_space_mask_v2 {
12946 +       uint64_t mask;
12947 +       uint32_t index;
12948 +};
12949 +
12950 +
12951 +#ifdef __KERNEL__
12952 +
12953 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
12954 +extern int vc_set_space_v1(struct vx_info *, void __user *);
12955 +extern int vc_enter_space(struct vx_info *, void __user *);
12956 +extern int vc_set_space(struct vx_info *, void __user *);
12957 +extern int vc_get_space_mask(void __user *, int);
12958 +
12959 +#endif /* __KERNEL__ */
12960 +#endif /* _VX_SPACE_CMD_H */
12961 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/space.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/space.h
12962 --- linux-2.6.36/include/linux/vserver/space.h  1970-01-01 01:00:00.000000000 +0100
12963 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/space.h    2010-10-21 13:09:36.000000000 +0200
12964 @@ -0,0 +1,12 @@
12965 +#ifndef _VX_SPACE_H
12966 +#define _VX_SPACE_H
12967 +
12968 +#include <linux/types.h>
12969 +
12970 +struct vx_info;
12971 +
12972 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
12973 +
12974 +#else  /* _VX_SPACE_H */
12975 +#warning duplicate inclusion
12976 +#endif /* _VX_SPACE_H */
12977 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/switch.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/switch.h
12978 --- linux-2.6.36/include/linux/vserver/switch.h 1970-01-01 01:00:00.000000000 +0100
12979 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/switch.h   2010-10-21 13:09:36.000000000 +0200
12980 @@ -0,0 +1,98 @@
12981 +#ifndef _VX_SWITCH_H
12982 +#define _VX_SWITCH_H
12983 +
12984 +#include <linux/types.h>
12985 +
12986 +
12987 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
12988 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
12989 +#define VC_VERSION(c)          ((c) & 0xFFF)
12990 +
12991 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
12992 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
12993 +
12994 +/*
12995 +
12996 +  Syscall Matrix V2.8
12997 +
12998 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
12999 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
13000 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
13001 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13002 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13003 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13004 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13005 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13006 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13007 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13008 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13009 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13010 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13011 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13012 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13013 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13014 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13015 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13016 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13017 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13018 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13019 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13020 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13021 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13022 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13023 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13024 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13025 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13026 +
13027 +*/
13028 +
13029 +#define VC_CAT_VERSION         0
13030 +
13031 +#define VC_CAT_VSETUP          1
13032 +#define VC_CAT_VHOST           2
13033 +
13034 +#define VC_CAT_DEVICE          6
13035 +
13036 +#define VC_CAT_VPROC           9
13037 +#define VC_CAT_PROCALT         10
13038 +#define VC_CAT_PROCMIG         11
13039 +#define VC_CAT_PROCTRL         12
13040 +
13041 +#define VC_CAT_SCHED           14
13042 +#define VC_CAT_MEMCTRL         20
13043 +
13044 +#define VC_CAT_VNET            25
13045 +#define VC_CAT_NETALT          26
13046 +#define VC_CAT_NETMIG          27
13047 +#define VC_CAT_NETCTRL         28
13048 +
13049 +#define VC_CAT_TAGMIG          35
13050 +#define VC_CAT_DLIMIT          36
13051 +#define VC_CAT_INODE           38
13052 +
13053 +#define VC_CAT_VSTAT           40
13054 +#define VC_CAT_VINFO           46
13055 +#define VC_CAT_EVENT           48
13056 +
13057 +#define VC_CAT_FLAGS           52
13058 +#define VC_CAT_VSPACE          54
13059 +#define VC_CAT_DEBUG           56
13060 +#define VC_CAT_RLIMIT          60
13061 +
13062 +#define VC_CAT_SYSTEST         61
13063 +#define VC_CAT_COMPAT          63
13064 +
13065 +/*  query version */
13066 +
13067 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13068 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13069 +
13070 +
13071 +#ifdef __KERNEL__
13072 +
13073 +#include <linux/errno.h>
13074 +
13075 +#endif /* __KERNEL__ */
13076 +
13077 +#endif /* _VX_SWITCH_H */
13078 +
13079 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/tag_cmd.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/tag_cmd.h
13080 --- linux-2.6.36/include/linux/vserver/tag_cmd.h        1970-01-01 01:00:00.000000000 +0100
13081 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/tag_cmd.h  2010-10-21 13:09:36.000000000 +0200
13082 @@ -0,0 +1,22 @@
13083 +#ifndef _VX_TAG_CMD_H
13084 +#define _VX_TAG_CMD_H
13085 +
13086 +
13087 +/* vinfo commands */
13088 +
13089 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13090 +
13091 +#ifdef __KERNEL__
13092 +extern int vc_task_tag(uint32_t);
13093 +
13094 +#endif /* __KERNEL__ */
13095 +
13096 +/* context commands */
13097 +
13098 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13099 +
13100 +#ifdef __KERNEL__
13101 +extern int vc_tag_migrate(uint32_t);
13102 +
13103 +#endif /* __KERNEL__ */
13104 +#endif /* _VX_TAG_CMD_H */
13105 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/tag.h linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/tag.h
13106 --- linux-2.6.36/include/linux/vserver/tag.h    1970-01-01 01:00:00.000000000 +0100
13107 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vserver/tag.h      2010-10-21 13:09:36.000000000 +0200
13108 @@ -0,0 +1,143 @@
13109 +#ifndef _DX_TAG_H
13110 +#define _DX_TAG_H
13111 +
13112 +#include <linux/types.h>
13113 +
13114 +
13115 +#define DX_TAG(in)     (IS_TAGGED(in))
13116 +
13117 +
13118 +#ifdef CONFIG_TAG_NFSD
13119 +#define DX_TAG_NFSD    1
13120 +#else
13121 +#define DX_TAG_NFSD    0
13122 +#endif
13123 +
13124 +
13125 +#ifdef CONFIG_TAGGING_NONE
13126 +
13127 +#define MAX_UID                0xFFFFFFFF
13128 +#define MAX_GID                0xFFFFFFFF
13129 +
13130 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
13131 +
13132 +#define TAGINO_UID(cond, uid, tag)     (uid)
13133 +#define TAGINO_GID(cond, gid, tag)     (gid)
13134 +
13135 +#endif
13136 +
13137 +
13138 +#ifdef CONFIG_TAGGING_GID16
13139 +
13140 +#define MAX_UID                0xFFFFFFFF
13141 +#define MAX_GID                0x0000FFFF
13142 +
13143 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13144 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
13145 +
13146 +#define TAGINO_UID(cond, uid, tag)     (uid)
13147 +#define TAGINO_GID(cond, gid, tag)     \
13148 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
13149 +
13150 +#endif
13151 +
13152 +
13153 +#ifdef CONFIG_TAGGING_ID24
13154 +
13155 +#define MAX_UID                0x00FFFFFF
13156 +#define MAX_GID                0x00FFFFFF
13157 +
13158 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13159 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
13160 +
13161 +#define TAGINO_UID(cond, uid, tag)     \
13162 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
13163 +#define TAGINO_GID(cond, gid, tag)     \
13164 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
13165 +
13166 +#endif
13167 +
13168 +
13169 +#ifdef CONFIG_TAGGING_UID16
13170 +
13171 +#define MAX_UID                0x0000FFFF
13172 +#define MAX_GID                0xFFFFFFFF
13173 +
13174 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13175 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
13176 +
13177 +#define TAGINO_UID(cond, uid, tag)     \
13178 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
13179 +#define TAGINO_GID(cond, gid, tag)     (gid)
13180 +
13181 +#endif
13182 +
13183 +
13184 +#ifdef CONFIG_TAGGING_INTERN
13185 +
13186 +#define MAX_UID                0xFFFFFFFF
13187 +#define MAX_GID                0xFFFFFFFF
13188 +
13189 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13190 +       ((cond) ? (tag) : 0)
13191 +
13192 +#define TAGINO_UID(cond, uid, tag)     (uid)
13193 +#define TAGINO_GID(cond, gid, tag)     (gid)
13194 +
13195 +#endif
13196 +
13197 +
13198 +#ifndef CONFIG_TAGGING_NONE
13199 +#define dx_current_fstag(sb)   \
13200 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
13201 +#else
13202 +#define dx_current_fstag(sb)   (0)
13203 +#endif
13204 +
13205 +#ifndef CONFIG_TAGGING_INTERN
13206 +#define TAGINO_TAG(cond, tag)  (0)
13207 +#else
13208 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
13209 +#endif
13210 +
13211 +#define INOTAG_UID(cond, uid, gid)     \
13212 +       ((cond) ? ((uid) & MAX_UID) : (uid))
13213 +#define INOTAG_GID(cond, uid, gid)     \
13214 +       ((cond) ? ((gid) & MAX_GID) : (gid))
13215 +
13216 +
13217 +static inline uid_t dx_map_uid(uid_t uid)
13218 +{
13219 +       if ((uid > MAX_UID) && (uid != -1))
13220 +               uid = -2;
13221 +       return (uid & MAX_UID);
13222 +}
13223 +
13224 +static inline gid_t dx_map_gid(gid_t gid)
13225 +{
13226 +       if ((gid > MAX_GID) && (gid != -1))
13227 +               gid = -2;
13228 +       return (gid & MAX_GID);
13229 +}
13230 +
13231 +struct peer_tag {
13232 +       int32_t xid;
13233 +       int32_t nid;
13234 +};
13235 +
13236 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
13237 +
13238 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
13239 +                unsigned long *flags);
13240 +
13241 +#ifdef CONFIG_PROPAGATE
13242 +
13243 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
13244 +
13245 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
13246 +
13247 +#else
13248 +#define dx_propagate_tag(n, i) do { } while (0)
13249 +#endif
13250 +
13251 +#endif /* _DX_TAG_H */
13252 diff -NurpP --minimal linux-2.6.36/include/linux/vs_inet6.h linux-2.6.36-vs2.3.0.36.36/include/linux/vs_inet6.h
13253 --- linux-2.6.36/include/linux/vs_inet6.h       1970-01-01 01:00:00.000000000 +0100
13254 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vs_inet6.h 2010-10-21 13:09:36.000000000 +0200
13255 @@ -0,0 +1,246 @@
13256 +#ifndef _VS_INET6_H
13257 +#define _VS_INET6_H
13258 +
13259 +#include "vserver/base.h"
13260 +#include "vserver/network.h"
13261 +#include "vserver/debug.h"
13262 +
13263 +#include <net/ipv6.h>
13264 +
13265 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
13266 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
13267 +
13268 +
13269 +#ifdef CONFIG_IPV6
13270 +
13271 +static inline
13272 +int v6_addr_match(struct nx_addr_v6 *nxa,
13273 +       const struct in6_addr *addr, uint16_t mask)
13274 +{
13275 +       int ret = 0;
13276 +
13277 +       switch (nxa->type & mask) {
13278 +       case NXA_TYPE_MASK:
13279 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
13280 +               break;
13281 +       case NXA_TYPE_ADDR:
13282 +               ret = ipv6_addr_equal(&nxa->ip, addr);
13283 +               break;
13284 +       case NXA_TYPE_ANY:
13285 +               ret = 1;
13286 +               break;
13287 +       }
13288 +       vxdprintk(VXD_CBIT(net, 0),
13289 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
13290 +               nxa, NXAV6(nxa), addr, mask, ret);
13291 +       return ret;
13292 +}
13293 +
13294 +static inline
13295 +int v6_addr_in_nx_info(struct nx_info *nxi,
13296 +       const struct in6_addr *addr, uint16_t mask)
13297 +{
13298 +       struct nx_addr_v6 *nxa;
13299 +       int ret = 1;
13300 +
13301 +       if (!nxi)
13302 +               goto out;
13303 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
13304 +               if (v6_addr_match(nxa, addr, mask))
13305 +                       goto out;
13306 +       ret = 0;
13307 +out:
13308 +       vxdprintk(VXD_CBIT(net, 0),
13309 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
13310 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
13311 +       return ret;
13312 +}
13313 +
13314 +static inline
13315 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
13316 +{
13317 +       /* FIXME: needs full range checks */
13318 +       return v6_addr_match(nxa, &addr->ip, mask);
13319 +}
13320 +
13321 +static inline
13322 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
13323 +{
13324 +       struct nx_addr_v6 *ptr;
13325 +
13326 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
13327 +               if (v6_nx_addr_match(ptr, nxa, mask))
13328 +                       return 1;
13329 +       return 0;
13330 +}
13331 +
13332 +
13333 +/*
13334 + *     Check if a given address matches for a socket
13335 + *
13336 + *     nxi:            the socket's nx_info if any
13337 + *     addr:           to be verified address
13338 + */
13339 +static inline
13340 +int v6_sock_addr_match (
13341 +       struct nx_info *nxi,
13342 +       struct inet_sock *inet,
13343 +       struct in6_addr *addr)
13344 +{
13345 +       struct sock *sk = &inet->sk;
13346 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13347 +
13348 +       if (!ipv6_addr_any(addr) &&
13349 +               ipv6_addr_equal(saddr, addr))
13350 +               return 1;
13351 +       if (ipv6_addr_any(saddr))
13352 +               return v6_addr_in_nx_info(nxi, addr, -1);
13353 +       return 0;
13354 +}
13355 +
13356 +/*
13357 + *     check if address is covered by socket
13358 + *
13359 + *     sk:     the socket to check against
13360 + *     addr:   the address in question (must be != 0)
13361 + */
13362 +
13363 +static inline
13364 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
13365 +{
13366 +       struct nx_info *nxi = sk->sk_nx_info;
13367 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13368 +
13369 +       vxdprintk(VXD_CBIT(net, 5),
13370 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
13371 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
13372 +               (sk->sk_socket?sk->sk_socket->flags:0));
13373 +
13374 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
13375 +               return v6_addr_match(nxa, saddr, -1);
13376 +       } else if (nxi) {               /* match against nx_info */
13377 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
13378 +       } else {                        /* unrestricted any socket */
13379 +               return 1;
13380 +       }
13381 +}
13382 +
13383 +
13384 +/* inet related checks and helpers */
13385 +
13386 +
13387 +struct in_ifaddr;
13388 +struct net_device;
13389 +struct sock;
13390 +
13391 +
13392 +#include <linux/netdevice.h>
13393 +#include <linux/inetdevice.h>
13394 +#include <net/inet_timewait_sock.h>
13395 +
13396 +
13397 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13398 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
13399 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
13400 +
13401 +
13402 +
13403 +static inline
13404 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
13405 +{
13406 +       if (!nxi)
13407 +               return 1;
13408 +       if (!ifa)
13409 +               return 0;
13410 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
13411 +}
13412 +
13413 +static inline
13414 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
13415 +{
13416 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
13417 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13418 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
13419 +
13420 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13421 +               return 1;
13422 +       if (v6_ifa_in_nx_info(ifa, nxi))
13423 +               return 1;
13424 +       return 0;
13425 +}
13426 +
13427 +
13428 +struct nx_v6_sock_addr {
13429 +       struct in6_addr saddr;  /* Address used for validation */
13430 +       struct in6_addr baddr;  /* Address used for socket bind */
13431 +};
13432 +
13433 +static inline
13434 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
13435 +       struct nx_v6_sock_addr *nsa)
13436 +{
13437 +       // struct sock *sk = &inet->sk;
13438 +       // struct nx_info *nxi = sk->sk_nx_info;
13439 +       struct in6_addr saddr = addr->sin6_addr;
13440 +       struct in6_addr baddr = saddr;
13441 +
13442 +       nsa->saddr = saddr;
13443 +       nsa->baddr = baddr;
13444 +       return 0;
13445 +}
13446 +
13447 +static inline
13448 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
13449 +{
13450 +       // struct sock *sk = &inet->sk;
13451 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
13452 +
13453 +       // *saddr = nsa->baddr;
13454 +       // inet->inet_saddr = nsa->baddr;
13455 +}
13456 +
13457 +static inline
13458 +int nx_info_has_v6(struct nx_info *nxi)
13459 +{
13460 +       if (!nxi)
13461 +               return 1;
13462 +       if (NX_IPV6(nxi))
13463 +               return 1;
13464 +       return 0;
13465 +}
13466 +
13467 +#else /* CONFIG_IPV6 */
13468 +
13469 +static inline
13470 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
13471 +{
13472 +       return 1;
13473 +}
13474 +
13475 +
13476 +static inline
13477 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13478 +{
13479 +       return 1;
13480 +}
13481 +
13482 +static inline
13483 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13484 +{
13485 +       return 1;
13486 +}
13487 +
13488 +static inline
13489 +int nx_info_has_v6(struct nx_info *nxi)
13490 +{
13491 +       return 0;
13492 +}
13493 +
13494 +#endif /* CONFIG_IPV6 */
13495 +
13496 +#define current_nx_info_has_v6() \
13497 +       nx_info_has_v6(current_nx_info())
13498 +
13499 +#else
13500 +#warning duplicate inclusion
13501 +#endif
13502 diff -NurpP --minimal linux-2.6.36/include/linux/vs_inet.h linux-2.6.36-vs2.3.0.36.36/include/linux/vs_inet.h
13503 --- linux-2.6.36/include/linux/vs_inet.h        1970-01-01 01:00:00.000000000 +0100
13504 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vs_inet.h  2010-10-21 17:41:35.000000000 +0200
13505 @@ -0,0 +1,351 @@
13506 +#ifndef _VS_INET_H
13507 +#define _VS_INET_H
13508 +
13509 +#include "vserver/base.h"
13510 +#include "vserver/network.h"
13511 +#include "vserver/debug.h"
13512 +
13513 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
13514 +
13515 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
13516 +                       NIPQUAD((a)->mask), (a)->type
13517 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
13518 +
13519 +#define NIPQUAD(addr) \
13520 +       ((unsigned char *)&addr)[0], \
13521 +       ((unsigned char *)&addr)[1], \
13522 +       ((unsigned char *)&addr)[2], \
13523 +       ((unsigned char *)&addr)[3]
13524 +
13525 +#define NIPQUAD_FMT "%u.%u.%u.%u"
13526 +
13527 +
13528 +static inline
13529 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
13530 +{
13531 +       __be32 ip = nxa->ip[0].s_addr;
13532 +       __be32 mask = nxa->mask.s_addr;
13533 +       __be32 bcast = ip | ~mask;
13534 +       int ret = 0;
13535 +
13536 +       switch (nxa->type & tmask) {
13537 +       case NXA_TYPE_MASK:
13538 +               ret = (ip == (addr & mask));
13539 +               break;
13540 +       case NXA_TYPE_ADDR:
13541 +               ret = 3;
13542 +               if (addr == ip)
13543 +                       break;
13544 +               /* fall through to broadcast */
13545 +       case NXA_MOD_BCAST:
13546 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
13547 +               break;
13548 +       case NXA_TYPE_RANGE:
13549 +               ret = ((nxa->ip[0].s_addr <= addr) &&
13550 +                       (nxa->ip[1].s_addr > addr));
13551 +               break;
13552 +       case NXA_TYPE_ANY:
13553 +               ret = 2;
13554 +               break;
13555 +       }
13556 +
13557 +       vxdprintk(VXD_CBIT(net, 0),
13558 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
13559 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
13560 +       return ret;
13561 +}
13562 +
13563 +static inline
13564 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
13565 +{
13566 +       struct nx_addr_v4 *nxa;
13567 +       int ret = 1;
13568 +
13569 +       if (!nxi)
13570 +               goto out;
13571 +
13572 +       ret = 2;
13573 +       /* allow 127.0.0.1 when remapping lback */
13574 +       if ((tmask & NXA_LOOPBACK) &&
13575 +               (addr == IPI_LOOPBACK) &&
13576 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13577 +               goto out;
13578 +       ret = 3;
13579 +       /* check for lback address */
13580 +       if ((tmask & NXA_MOD_LBACK) &&
13581 +               (nxi->v4_lback.s_addr == addr))
13582 +               goto out;
13583 +       ret = 4;
13584 +       /* check for broadcast address */
13585 +       if ((tmask & NXA_MOD_BCAST) &&
13586 +               (nxi->v4_bcast.s_addr == addr))
13587 +               goto out;
13588 +       ret = 5;
13589 +       /* check for v4 addresses */
13590 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
13591 +               if (v4_addr_match(nxa, addr, tmask))
13592 +                       goto out;
13593 +       ret = 0;
13594 +out:
13595 +       vxdprintk(VXD_CBIT(net, 0),
13596 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
13597 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
13598 +       return ret;
13599 +}
13600 +
13601 +static inline
13602 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
13603 +{
13604 +       /* FIXME: needs full range checks */
13605 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
13606 +}
13607 +
13608 +static inline
13609 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
13610 +{
13611 +       struct nx_addr_v4 *ptr;
13612 +
13613 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
13614 +               if (v4_nx_addr_match(ptr, nxa, mask))
13615 +                       return 1;
13616 +       return 0;
13617 +}
13618 +
13619 +#include <net/inet_sock.h>
13620 +
13621 +/*
13622 + *     Check if a given address matches for a socket
13623 + *
13624 + *     nxi:            the socket's nx_info if any
13625 + *     addr:           to be verified address
13626 + */
13627 +static inline
13628 +int v4_sock_addr_match (
13629 +       struct nx_info *nxi,
13630 +       struct inet_sock *inet,
13631 +       __be32 addr)
13632 +{
13633 +       __be32 saddr = inet->inet_rcv_saddr;
13634 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
13635 +
13636 +       if (addr && (saddr == addr || bcast == addr))
13637 +               return 1;
13638 +       if (!saddr)
13639 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
13640 +       return 0;
13641 +}
13642 +
13643 +
13644 +/* inet related checks and helpers */
13645 +
13646 +
13647 +struct in_ifaddr;
13648 +struct net_device;
13649 +struct sock;
13650 +
13651 +#ifdef CONFIG_INET
13652 +
13653 +#include <linux/netdevice.h>
13654 +#include <linux/inetdevice.h>
13655 +#include <net/inet_sock.h>
13656 +#include <net/inet_timewait_sock.h>
13657 +
13658 +
13659 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13660 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
13661 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
13662 +
13663 +
13664 +/*
13665 + *     check if address is covered by socket
13666 + *
13667 + *     sk:     the socket to check against
13668 + *     addr:   the address in question (must be != 0)
13669 + */
13670 +
13671 +static inline
13672 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
13673 +{
13674 +       struct nx_info *nxi = sk->sk_nx_info;
13675 +       __be32 saddr = inet_rcv_saddr(sk);
13676 +
13677 +       vxdprintk(VXD_CBIT(net, 5),
13678 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
13679 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
13680 +               (sk->sk_socket?sk->sk_socket->flags:0));
13681 +
13682 +       if (saddr) {            /* direct address match */
13683 +               return v4_addr_match(nxa, saddr, -1);
13684 +       } else if (nxi) {       /* match against nx_info */
13685 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
13686 +       } else {                /* unrestricted any socket */
13687 +               return 1;
13688 +       }
13689 +}
13690 +
13691 +
13692 +
13693 +static inline
13694 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
13695 +{
13696 +       vxdprintk(VXD_CBIT(net, 1),
13697 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
13698 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
13699 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
13700 +
13701 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13702 +               return 1;
13703 +       if (dev_in_nx_info(dev, nxi))
13704 +               return 1;
13705 +       return 0;
13706 +}
13707 +
13708 +
13709 +static inline
13710 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
13711 +{
13712 +       if (!nxi)
13713 +               return 1;
13714 +       if (!ifa)
13715 +               return 0;
13716 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
13717 +}
13718 +
13719 +static inline
13720 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
13721 +{
13722 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
13723 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13724 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
13725 +
13726 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13727 +               return 1;
13728 +       if (v4_ifa_in_nx_info(ifa, nxi))
13729 +               return 1;
13730 +       return 0;
13731 +}
13732 +
13733 +
13734 +struct nx_v4_sock_addr {
13735 +       __be32 saddr;   /* Address used for validation */
13736 +       __be32 baddr;   /* Address used for socket bind */
13737 +};
13738 +
13739 +static inline
13740 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
13741 +       struct nx_v4_sock_addr *nsa)
13742 +{
13743 +       struct sock *sk = &inet->sk;
13744 +       struct nx_info *nxi = sk->sk_nx_info;
13745 +       __be32 saddr = addr->sin_addr.s_addr;
13746 +       __be32 baddr = saddr;
13747 +
13748 +       vxdprintk(VXD_CBIT(net, 3),
13749 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
13750 +               sk, sk->sk_nx_info, sk->sk_socket,
13751 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
13752 +               NIPQUAD(saddr));
13753 +
13754 +       if (nxi) {
13755 +               if (saddr == INADDR_ANY) {
13756 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
13757 +                               baddr = nxi->v4.ip[0].s_addr;
13758 +               } else if (saddr == IPI_LOOPBACK) {
13759 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13760 +                               baddr = nxi->v4_lback.s_addr;
13761 +               } else {        /* normal address bind */
13762 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
13763 +                               return -EADDRNOTAVAIL;
13764 +               }
13765 +       }
13766 +
13767 +       vxdprintk(VXD_CBIT(net, 3),
13768 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
13769 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
13770 +
13771 +       nsa->saddr = saddr;
13772 +       nsa->baddr = baddr;
13773 +       return 0;
13774 +}
13775 +
13776 +static inline
13777 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
13778 +{
13779 +       inet->inet_saddr = nsa->baddr;
13780 +       inet->inet_rcv_saddr = nsa->baddr;
13781 +}
13782 +
13783 +
13784 +/*
13785 + *      helper to simplify inet_lookup_listener
13786 + *
13787 + *      nxi:   the socket's nx_info if any
13788 + *      addr:  to be verified address
13789 + *      saddr: socket address
13790 + */
13791 +static inline int v4_inet_addr_match (
13792 +       struct nx_info *nxi,
13793 +       __be32 addr,
13794 +       __be32 saddr)
13795 +{
13796 +       if (addr && (saddr == addr))
13797 +               return 1;
13798 +       if (!saddr)
13799 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
13800 +       return 0;
13801 +}
13802 +
13803 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
13804 +{
13805 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
13806 +               (addr == nxi->v4_lback.s_addr))
13807 +               return IPI_LOOPBACK;
13808 +       return addr;
13809 +}
13810 +
13811 +static inline
13812 +int nx_info_has_v4(struct nx_info *nxi)
13813 +{
13814 +       if (!nxi)
13815 +               return 1;
13816 +       if (NX_IPV4(nxi))
13817 +               return 1;
13818 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13819 +               return 1;
13820 +       return 0;
13821 +}
13822 +
13823 +#else /* CONFIG_INET */
13824 +
13825 +static inline
13826 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
13827 +{
13828 +       return 1;
13829 +}
13830 +
13831 +static inline
13832 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13833 +{
13834 +       return 1;
13835 +}
13836 +
13837 +static inline
13838 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13839 +{
13840 +       return 1;
13841 +}
13842 +
13843 +static inline
13844 +int nx_info_has_v4(struct nx_info *nxi)
13845 +{
13846 +       return 0;
13847 +}
13848 +
13849 +#endif /* CONFIG_INET */
13850 +
13851 +#define current_nx_info_has_v4() \
13852 +       nx_info_has_v4(current_nx_info())
13853 +
13854 +#else
13855 +// #warning duplicate inclusion
13856 +#endif
13857 diff -NurpP --minimal linux-2.6.36/include/linux/vs_limit.h linux-2.6.36-vs2.3.0.36.36/include/linux/vs_limit.h
13858 --- linux-2.6.36/include/linux/vs_limit.h       1970-01-01 01:00:00.000000000 +0100
13859 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vs_limit.h 2010-10-21 13:09:36.000000000 +0200
13860 @@ -0,0 +1,140 @@
13861 +#ifndef _VS_LIMIT_H
13862 +#define _VS_LIMIT_H
13863 +
13864 +#include "vserver/limit.h"
13865 +#include "vserver/base.h"
13866 +#include "vserver/context.h"
13867 +#include "vserver/debug.h"
13868 +#include "vserver/context.h"
13869 +#include "vserver/limit_int.h"
13870 +
13871 +
13872 +#define vx_acc_cres(v, d, p, r) \
13873 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
13874 +
13875 +#define vx_acc_cres_cond(x, d, p, r) \
13876 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
13877 +       r, d, p, __FILE__, __LINE__)
13878 +
13879 +
13880 +#define vx_add_cres(v, a, p, r) \
13881 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
13882 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
13883 +
13884 +#define vx_add_cres_cond(x, a, p, r) \
13885 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
13886 +       r, a, p, __FILE__, __LINE__)
13887 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
13888 +
13889 +
13890 +/* process and file limits */
13891 +
13892 +#define vx_nproc_inc(p) \
13893 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
13894 +
13895 +#define vx_nproc_dec(p) \
13896 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
13897 +
13898 +#define vx_files_inc(f) \
13899 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
13900 +
13901 +#define vx_files_dec(f) \
13902 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
13903 +
13904 +#define vx_locks_inc(l) \
13905 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
13906 +
13907 +#define vx_locks_dec(l) \
13908 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
13909 +
13910 +#define vx_openfd_inc(f) \
13911 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
13912 +
13913 +#define vx_openfd_dec(f) \
13914 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
13915 +
13916 +
13917 +#define vx_cres_avail(v, n, r) \
13918 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
13919 +
13920 +
13921 +#define vx_nproc_avail(n) \
13922 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
13923 +
13924 +#define vx_files_avail(n) \
13925 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
13926 +
13927 +#define vx_locks_avail(n) \
13928 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
13929 +
13930 +#define vx_openfd_avail(n) \
13931 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
13932 +
13933 +
13934 +/* dentry limits */
13935 +
13936 +#define vx_dentry_inc(d) do {                                          \
13937 +       if (atomic_read(&d->d_count) == 1)                              \
13938 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
13939 +       } while (0)
13940 +
13941 +#define vx_dentry_dec(d) do {                                          \
13942 +       if (atomic_read(&d->d_count) == 0)                              \
13943 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
13944 +       } while (0)
13945 +
13946 +#define vx_dentry_avail(n) \
13947 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
13948 +
13949 +
13950 +/* socket limits */
13951 +
13952 +#define vx_sock_inc(s) \
13953 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
13954 +
13955 +#define vx_sock_dec(s) \
13956 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
13957 +
13958 +#define vx_sock_avail(n) \
13959 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
13960 +
13961 +
13962 +/* ipc resource limits */
13963 +
13964 +#define vx_ipcmsg_add(v, u, a) \
13965 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
13966 +
13967 +#define vx_ipcmsg_sub(v, u, a) \
13968 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
13969 +
13970 +#define vx_ipcmsg_avail(v, a) \
13971 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
13972 +
13973 +
13974 +#define vx_ipcshm_add(v, k, a) \
13975 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
13976 +
13977 +#define vx_ipcshm_sub(v, k, a) \
13978 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
13979 +
13980 +#define vx_ipcshm_avail(v, a) \
13981 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
13982 +
13983 +
13984 +#define vx_semary_inc(a) \
13985 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
13986 +
13987 +#define vx_semary_dec(a) \
13988 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
13989 +
13990 +
13991 +#define vx_nsems_add(a,n) \
13992 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
13993 +
13994 +#define vx_nsems_sub(a,n) \
13995 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
13996 +
13997 +
13998 +#else
13999 +#warning duplicate inclusion
14000 +#endif
14001 diff -NurpP --minimal linux-2.6.36/include/linux/vs_memory.h linux-2.6.36-vs2.3.0.36.36/include/linux/vs_memory.h
14002 --- linux-2.6.36/include/linux/vs_memory.h      1970-01-01 01:00:00.000000000 +0100
14003 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vs_memory.h        2010-10-21 13:09:36.000000000 +0200
14004 @@ -0,0 +1,58 @@
14005 +#ifndef _VS_MEMORY_H
14006 +#define _VS_MEMORY_H
14007 +
14008 +#include "vserver/limit.h"
14009 +#include "vserver/base.h"
14010 +#include "vserver/context.h"
14011 +#include "vserver/debug.h"
14012 +#include "vserver/context.h"
14013 +#include "vserver/limit_int.h"
14014 +
14015 +enum {
14016 +       VXPT_UNKNOWN = 0,
14017 +       VXPT_ANON,
14018 +       VXPT_NONE,
14019 +       VXPT_FILE,
14020 +       VXPT_SWAP,
14021 +       VXPT_WRITE
14022 +};
14023 +
14024 +#if 0
14025 +#define        vx_page_fault(mm, vma, type, ret)
14026 +#else
14027 +
14028 +static inline
14029 +void __vx_page_fault(struct mm_struct *mm,
14030 +       struct vm_area_struct *vma, int type, int ret)
14031 +{
14032 +       struct vx_info *vxi = mm->mm_vx_info;
14033 +       int what;
14034 +/*
14035 +       static char *page_type[6] =
14036 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
14037 +       static char *page_what[4] =
14038 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
14039 +*/
14040 +
14041 +       if (!vxi)
14042 +               return;
14043 +
14044 +       what = (ret & 0x3);
14045 +
14046 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
14047 +               type, what, ret, page_type[type], page_what[what]);
14048 +*/
14049 +       if (ret & VM_FAULT_WRITE)
14050 +               what |= 0x4;
14051 +       atomic_inc(&vxi->cacct.page[type][what]);
14052 +}
14053 +
14054 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
14055 +#endif
14056 +
14057 +
14058 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
14059 +
14060 +#else
14061 +#warning duplicate inclusion
14062 +#endif
14063 diff -NurpP --minimal linux-2.6.36/include/linux/vs_network.h linux-2.6.36-vs2.3.0.36.36/include/linux/vs_network.h
14064 --- linux-2.6.36/include/linux/vs_network.h     1970-01-01 01:00:00.000000000 +0100
14065 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vs_network.h       2010-10-21 13:09:36.000000000 +0200
14066 @@ -0,0 +1,169 @@
14067 +#ifndef _NX_VS_NETWORK_H
14068 +#define _NX_VS_NETWORK_H
14069 +
14070 +#include "vserver/context.h"
14071 +#include "vserver/network.h"
14072 +#include "vserver/base.h"
14073 +#include "vserver/check.h"
14074 +#include "vserver/debug.h"
14075 +
14076 +#include <linux/sched.h>
14077 +
14078 +
14079 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
14080 +
14081 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
14082 +       const char *_file, int _line)
14083 +{
14084 +       if (!nxi)
14085 +               return NULL;
14086 +
14087 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
14088 +               nxi, nxi ? nxi->nx_id : 0,
14089 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14090 +               _file, _line);
14091 +
14092 +       atomic_inc(&nxi->nx_usecnt);
14093 +       return nxi;
14094 +}
14095 +
14096 +
14097 +extern void free_nx_info(struct nx_info *);
14098 +
14099 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
14100 +
14101 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
14102 +{
14103 +       if (!nxi)
14104 +               return;
14105 +
14106 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
14107 +               nxi, nxi ? nxi->nx_id : 0,
14108 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14109 +               _file, _line);
14110 +
14111 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
14112 +               free_nx_info(nxi);
14113 +}
14114 +
14115 +
14116 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
14117 +
14118 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14119 +               const char *_file, int _line)
14120 +{
14121 +       if (nxi) {
14122 +               vxlprintk(VXD_CBIT(nid, 3),
14123 +                       "init_nx_info(%p[#%d.%d])",
14124 +                       nxi, nxi ? nxi->nx_id : 0,
14125 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14126 +                       _file, _line);
14127 +
14128 +               atomic_inc(&nxi->nx_usecnt);
14129 +       }
14130 +       *nxp = nxi;
14131 +}
14132 +
14133 +
14134 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
14135 +
14136 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14137 +       const char *_file, int _line)
14138 +{
14139 +       struct nx_info *nxo;
14140 +
14141 +       if (!nxi)
14142 +               return;
14143 +
14144 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
14145 +               nxi, nxi ? nxi->nx_id : 0,
14146 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14147 +               _file, _line);
14148 +
14149 +       atomic_inc(&nxi->nx_usecnt);
14150 +       nxo = xchg(nxp, nxi);
14151 +       BUG_ON(nxo);
14152 +}
14153 +
14154 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
14155 +
14156 +static inline void __clr_nx_info(struct nx_info **nxp,
14157 +       const char *_file, int _line)
14158 +{
14159 +       struct nx_info *nxo;
14160 +
14161 +       nxo = xchg(nxp, NULL);
14162 +       if (!nxo)
14163 +               return;
14164 +
14165 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
14166 +               nxo, nxo ? nxo->nx_id : 0,
14167 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
14168 +               _file, _line);
14169 +
14170 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
14171 +               free_nx_info(nxo);
14172 +}
14173 +
14174 +
14175 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
14176 +
14177 +static inline void __claim_nx_info(struct nx_info *nxi,
14178 +       struct task_struct *task, const char *_file, int _line)
14179 +{
14180 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
14181 +               nxi, nxi ? nxi->nx_id : 0,
14182 +               nxi?atomic_read(&nxi->nx_usecnt):0,
14183 +               nxi?atomic_read(&nxi->nx_tasks):0,
14184 +               task, _file, _line);
14185 +
14186 +       atomic_inc(&nxi->nx_tasks);
14187 +}
14188 +
14189 +
14190 +extern void unhash_nx_info(struct nx_info *);
14191 +
14192 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
14193 +
14194 +static inline void __release_nx_info(struct nx_info *nxi,
14195 +       struct task_struct *task, const char *_file, int _line)
14196 +{
14197 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
14198 +               nxi, nxi ? nxi->nx_id : 0,
14199 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14200 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
14201 +               task, _file, _line);
14202 +
14203 +       might_sleep();
14204 +
14205 +       if (atomic_dec_and_test(&nxi->nx_tasks))
14206 +               unhash_nx_info(nxi);
14207 +}
14208 +
14209 +
14210 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
14211 +
14212 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
14213 +       const char *_file, int _line)
14214 +{
14215 +       struct nx_info *nxi;
14216 +
14217 +       task_lock(p);
14218 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
14219 +               p, _file, _line);
14220 +       nxi = __get_nx_info(p->nx_info, _file, _line);
14221 +       task_unlock(p);
14222 +       return nxi;
14223 +}
14224 +
14225 +
14226 +static inline void exit_nx_info(struct task_struct *p)
14227 +{
14228 +       if (p->nx_info)
14229 +               release_nx_info(p->nx_info, p);
14230 +}
14231 +
14232 +
14233 +#else
14234 +#warning duplicate inclusion
14235 +#endif
14236 diff -NurpP --minimal linux-2.6.36/include/linux/vs_pid.h linux-2.6.36-vs2.3.0.36.36/include/linux/vs_pid.h
14237 --- linux-2.6.36/include/linux/vs_pid.h 1970-01-01 01:00:00.000000000 +0100
14238 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vs_pid.h   2010-10-21 13:09:36.000000000 +0200
14239 @@ -0,0 +1,95 @@
14240 +#ifndef _VS_PID_H
14241 +#define _VS_PID_H
14242 +
14243 +#include "vserver/base.h"
14244 +#include "vserver/check.h"
14245 +#include "vserver/context.h"
14246 +#include "vserver/debug.h"
14247 +#include "vserver/pid.h"
14248 +#include <linux/pid_namespace.h>
14249 +
14250 +
14251 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
14252 +
14253 +static inline
14254 +int vx_proc_task_visible(struct task_struct *task)
14255 +{
14256 +       if ((task->pid == 1) &&
14257 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
14258 +               /* show a blend through init */
14259 +               goto visible;
14260 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
14261 +               goto visible;
14262 +       return 0;
14263 +visible:
14264 +       return 1;
14265 +}
14266 +
14267 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
14268 +
14269 +#if 0
14270 +
14271 +static inline
14272 +struct task_struct *vx_find_proc_task_by_pid(int pid)
14273 +{
14274 +       struct task_struct *task = find_task_by_real_pid(pid);
14275 +
14276 +       if (task && !vx_proc_task_visible(task)) {
14277 +               vxdprintk(VXD_CBIT(misc, 6),
14278 +                       "dropping task (find) %p[#%u,%u] for %p[#%u,%u]",
14279 +                       task, task->xid, task->pid,
14280 +                       current, current->xid, current->pid);
14281 +               task = NULL;
14282 +       }
14283 +       return task;
14284 +}
14285 +
14286 +#endif
14287 +
14288 +static inline
14289 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
14290 +{
14291 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
14292 +
14293 +       if (task && !vx_proc_task_visible(task)) {
14294 +               vxdprintk(VXD_CBIT(misc, 6),
14295 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
14296 +                       task, task->xid, task->pid,
14297 +                       current, current->xid, current->pid);
14298 +               put_task_struct(task);
14299 +               task = NULL;
14300 +       }
14301 +       return task;
14302 +}
14303 +
14304 +#if 0
14305 +
14306 +static inline
14307 +struct task_struct *vx_child_reaper(struct task_struct *p)
14308 +{
14309 +       struct vx_info *vxi = p->vx_info;
14310 +       struct task_struct *reaper = child_reaper(p);
14311 +
14312 +       if (!vxi)
14313 +               goto out;
14314 +
14315 +       BUG_ON(!p->vx_info->vx_reaper);
14316 +
14317 +       /* child reaper for the guest reaper */
14318 +       if (vxi->vx_reaper == p)
14319 +               goto out;
14320 +
14321 +       reaper = vxi->vx_reaper;
14322 +out:
14323 +       vxdprintk(VXD_CBIT(xid, 7),
14324 +               "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]",
14325 +               p, p->xid, p->pid, reaper, reaper->xid, reaper->pid);
14326 +       return reaper;
14327 +}
14328 +
14329 +#endif
14330 +
14331 +
14332 +#else
14333 +#warning duplicate inclusion
14334 +#endif
14335 diff -NurpP --minimal linux-2.6.36/include/linux/vs_sched.h linux-2.6.36-vs2.3.0.36.36/include/linux/vs_sched.h
14336 --- linux-2.6.36/include/linux/vs_sched.h       1970-01-01 01:00:00.000000000 +0100
14337 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vs_sched.h 2010-10-21 13:09:36.000000000 +0200
14338 @@ -0,0 +1,110 @@
14339 +#ifndef _VS_SCHED_H
14340 +#define _VS_SCHED_H
14341 +
14342 +#include "vserver/base.h"
14343 +#include "vserver/context.h"
14344 +#include "vserver/sched.h"
14345 +
14346 +
14347 +#define VAVAVOOM_RATIO          50
14348 +
14349 +#define MAX_PRIO_BIAS           20
14350 +#define MIN_PRIO_BIAS          -20
14351 +
14352 +
14353 +#ifdef CONFIG_VSERVER_HARDCPU
14354 +
14355 +/*
14356 + * effective_prio - return the priority that is based on the static
14357 + * priority but is modified by bonuses/penalties.
14358 + *
14359 + * We scale the actual sleep average [0 .... MAX_SLEEP_AVG]
14360 + * into a -4 ... 0 ... +4 bonus/penalty range.
14361 + *
14362 + * Additionally, we scale another amount based on the number of
14363 + * CPU tokens currently held by the context, if the process is
14364 + * part of a context (and the appropriate SCHED flag is set).
14365 + * This ranges from -5 ... 0 ... +15, quadratically.
14366 + *
14367 + * So, the total bonus is -9 .. 0 .. +19
14368 + * We use ~50% of the full 0...39 priority range so that:
14369 + *
14370 + * 1) nice +19 interactive tasks do not preempt nice 0 CPU hogs.
14371 + * 2) nice -20 CPU hogs do not get preempted by nice 0 tasks.
14372 + *    unless that context is far exceeding its CPU allocation.
14373 + *
14374 + * Both properties are important to certain workloads.
14375 + */
14376 +static inline
14377 +int vx_effective_vavavoom(struct _vx_sched_pc *sched_pc, int max_prio)
14378 +{
14379 +       int vavavoom, max;
14380 +
14381 +       /* lots of tokens = lots of vavavoom
14382 +        *      no tokens = no vavavoom      */
14383 +       if ((vavavoom = sched_pc->tokens) >= 0) {
14384 +               max = sched_pc->tokens_max;
14385 +               vavavoom = max - vavavoom;
14386 +               max = max * max;
14387 +               vavavoom = max_prio * VAVAVOOM_RATIO / 100
14388 +                       * (vavavoom*vavavoom - (max >> 2)) / max;
14389 +               return vavavoom;
14390 +       }
14391 +       return 0;
14392 +}
14393 +
14394 +
14395 +static inline
14396 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14397 +{
14398 +       struct vx_info *vxi = p->vx_info;
14399 +       struct _vx_sched_pc *sched_pc;
14400 +
14401 +       if (!vxi)
14402 +               return prio;
14403 +
14404 +       sched_pc = &vx_cpu(vxi, sched_pc);
14405 +       if (vx_info_flags(vxi, VXF_SCHED_PRIO, 0)) {
14406 +               int vavavoom = vx_effective_vavavoom(sched_pc, max_user);
14407 +
14408 +               sched_pc->vavavoom = vavavoom;
14409 +               prio += vavavoom;
14410 +       }
14411 +       prio += sched_pc->prio_bias;
14412 +       return prio;
14413 +}
14414 +
14415 +#else /* !CONFIG_VSERVER_HARDCPU */
14416 +
14417 +static inline
14418 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14419 +{
14420 +       struct vx_info *vxi = p->vx_info;
14421 +
14422 +       if (vxi)
14423 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
14424 +       return prio;
14425 +}
14426 +
14427 +#endif /* CONFIG_VSERVER_HARDCPU */
14428 +
14429 +
14430 +static inline void vx_account_user(struct vx_info *vxi,
14431 +       cputime_t cputime, int nice)
14432 +{
14433 +       if (!vxi)
14434 +               return;
14435 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
14436 +}
14437 +
14438 +static inline void vx_account_system(struct vx_info *vxi,
14439 +       cputime_t cputime, int idle)
14440 +{
14441 +       if (!vxi)
14442 +               return;
14443 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
14444 +}
14445 +
14446 +#else
14447 +#warning duplicate inclusion
14448 +#endif
14449 diff -NurpP --minimal linux-2.6.36/include/linux/vs_socket.h linux-2.6.36-vs2.3.0.36.36/include/linux/vs_socket.h
14450 --- linux-2.6.36/include/linux/vs_socket.h      1970-01-01 01:00:00.000000000 +0100
14451 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vs_socket.h        2010-10-21 13:09:36.000000000 +0200
14452 @@ -0,0 +1,67 @@
14453 +#ifndef _VS_SOCKET_H
14454 +#define _VS_SOCKET_H
14455 +
14456 +#include "vserver/debug.h"
14457 +#include "vserver/base.h"
14458 +#include "vserver/cacct.h"
14459 +#include "vserver/context.h"
14460 +#include "vserver/tag.h"
14461 +
14462 +
14463 +/* socket accounting */
14464 +
14465 +#include <linux/socket.h>
14466 +
14467 +static inline int vx_sock_type(int family)
14468 +{
14469 +       switch (family) {
14470 +       case PF_UNSPEC:
14471 +               return VXA_SOCK_UNSPEC;
14472 +       case PF_UNIX:
14473 +               return VXA_SOCK_UNIX;
14474 +       case PF_INET:
14475 +               return VXA_SOCK_INET;
14476 +       case PF_INET6:
14477 +               return VXA_SOCK_INET6;
14478 +       case PF_PACKET:
14479 +               return VXA_SOCK_PACKET;
14480 +       default:
14481 +               return VXA_SOCK_OTHER;
14482 +       }
14483 +}
14484 +
14485 +#define vx_acc_sock(v, f, p, s) \
14486 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
14487 +
14488 +static inline void __vx_acc_sock(struct vx_info *vxi,
14489 +       int family, int pos, int size, char *file, int line)
14490 +{
14491 +       if (vxi) {
14492 +               int type = vx_sock_type(family);
14493 +
14494 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
14495 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
14496 +       }
14497 +}
14498 +
14499 +#define vx_sock_recv(sk, s) \
14500 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
14501 +#define vx_sock_send(sk, s) \
14502 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
14503 +#define vx_sock_fail(sk, s) \
14504 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
14505 +
14506 +
14507 +#define sock_vx_init(s) do {           \
14508 +       (s)->sk_xid = 0;                \
14509 +       (s)->sk_vx_info = NULL;         \
14510 +       } while (0)
14511 +
14512 +#define sock_nx_init(s) do {           \
14513 +       (s)->sk_nid = 0;                \
14514 +       (s)->sk_nx_info = NULL;         \
14515 +       } while (0)
14516 +
14517 +#else
14518 +#warning duplicate inclusion
14519 +#endif
14520 diff -NurpP --minimal linux-2.6.36/include/linux/vs_tag.h linux-2.6.36-vs2.3.0.36.36/include/linux/vs_tag.h
14521 --- linux-2.6.36/include/linux/vs_tag.h 1970-01-01 01:00:00.000000000 +0100
14522 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vs_tag.h   2010-10-21 13:09:36.000000000 +0200
14523 @@ -0,0 +1,47 @@
14524 +#ifndef _VS_TAG_H
14525 +#define _VS_TAG_H
14526 +
14527 +#include <linux/vserver/tag.h>
14528 +
14529 +/* check conditions */
14530 +
14531 +#define DX_ADMIN       0x0001
14532 +#define DX_WATCH       0x0002
14533 +#define DX_HOSTID      0x0008
14534 +
14535 +#define DX_IDENT       0x0010
14536 +
14537 +#define DX_ARG_MASK    0x0010
14538 +
14539 +
14540 +#define dx_task_tag(t) ((t)->tag)
14541 +
14542 +#define dx_current_tag() dx_task_tag(current)
14543 +
14544 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
14545 +
14546 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
14547 +
14548 +
14549 +/*
14550 + * check current context for ADMIN/WATCH and
14551 + * optionally against supplied argument
14552 + */
14553 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
14554 +{
14555 +       if (mode & DX_ARG_MASK) {
14556 +               if ((mode & DX_IDENT) && (id == cid))
14557 +                       return 1;
14558 +       }
14559 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
14560 +               ((mode & DX_WATCH) && (cid == 1)) ||
14561 +               ((mode & DX_HOSTID) && (id == 0)));
14562 +}
14563 +
14564 +struct inode;
14565 +int dx_permission(const struct inode *inode, int mask);
14566 +
14567 +
14568 +#else
14569 +#warning duplicate inclusion
14570 +#endif
14571 diff -NurpP --minimal linux-2.6.36/include/linux/vs_time.h linux-2.6.36-vs2.3.0.36.36/include/linux/vs_time.h
14572 --- linux-2.6.36/include/linux/vs_time.h        1970-01-01 01:00:00.000000000 +0100
14573 +++ linux-2.6.36-vs2.3.0.36.36/include/linux/vs_time.h  2010-10-21 14:25:37.000000000 +0200
14574 @@ -0,0 +1,19 @@
14575 +#ifndef _VS_TIME_H
14576 +#define _VS_TIME_H
14577 +
14578 +
14579 +/* time faking stuff */
14580 +
14581 +#ifdef CONFIG_VSERVER_VTIME
14582 +
14583 +extern void vx_adjust_timespec(struct timespec *ts);
14584 +extern int vx_settimeofday(struct timespec *ts);
14585 +
14586 +#else
14587 +#define        vx_adjust_timespec(t)   do { } while (0)
14588 +#define        vx_settimeofday(t)      do_settimeofday(t)
14589 +#endif
14590 +
14591 +#else
14592 +#warning duplicate inclusion
14593 +#endif
14594 diff -NurpP --minimal linux-2.6.36/include/net/addrconf.h linux-2.6.36-vs2.3.0.36.36/include/net/addrconf.h
14595 --- linux-2.6.36/include/net/addrconf.h 2010-10-21 13:07:56.000000000 +0200
14596 +++ linux-2.6.36-vs2.3.0.36.36/include/net/addrconf.h   2010-10-21 13:09:36.000000000 +0200
14597 @@ -84,7 +84,8 @@ extern int                    ipv6_dev_get_saddr(struct n
14598                                                struct net_device *dev,
14599                                                const struct in6_addr *daddr,
14600                                                unsigned int srcprefs,
14601 -                                              struct in6_addr *saddr);
14602 +                                              struct in6_addr *saddr,
14603 +                                              struct nx_info *nxi);
14604  extern int                     ipv6_get_lladdr(struct net_device *dev,
14605                                                 struct in6_addr *addr,
14606                                                 unsigned char banned_flags);
14607 diff -NurpP --minimal linux-2.6.36/include/net/af_unix.h linux-2.6.36-vs2.3.0.36.36/include/net/af_unix.h
14608 --- linux-2.6.36/include/net/af_unix.h  2010-10-21 13:07:56.000000000 +0200
14609 +++ linux-2.6.36-vs2.3.0.36.36/include/net/af_unix.h    2010-10-21 13:09:36.000000000 +0200
14610 @@ -4,6 +4,7 @@
14611  #include <linux/socket.h>
14612  #include <linux/un.h>
14613  #include <linux/mutex.h>
14614 +#include <linux/vs_base.h>
14615  #include <net/sock.h>
14616  
14617  extern void unix_inflight(struct file *fp);
14618 diff -NurpP --minimal linux-2.6.36/include/net/inet_timewait_sock.h linux-2.6.36-vs2.3.0.36.36/include/net/inet_timewait_sock.h
14619 --- linux-2.6.36/include/net/inet_timewait_sock.h       2010-08-02 16:52:56.000000000 +0200
14620 +++ linux-2.6.36-vs2.3.0.36.36/include/net/inet_timewait_sock.h 2010-10-21 13:09:36.000000000 +0200
14621 @@ -117,6 +117,10 @@ struct inet_timewait_sock {
14622  #define tw_hash                        __tw_common.skc_hash
14623  #define tw_prot                        __tw_common.skc_prot
14624  #define tw_net                 __tw_common.skc_net
14625 +#define tw_xid                 __tw_common.skc_xid
14626 +#define tw_vx_info             __tw_common.skc_vx_info
14627 +#define tw_nid                 __tw_common.skc_nid
14628 +#define tw_nx_info             __tw_common.skc_nx_info
14629         int                     tw_timeout;
14630         volatile unsigned char  tw_substate;
14631         /* 3 bits hole, try to pack */
14632 diff -NurpP --minimal linux-2.6.36/include/net/route.h linux-2.6.36-vs2.3.0.36.36/include/net/route.h
14633 --- linux-2.6.36/include/net/route.h    2010-10-21 13:07:56.000000000 +0200
14634 +++ linux-2.6.36-vs2.3.0.36.36/include/net/route.h      2010-10-21 13:09:36.000000000 +0200
14635 @@ -145,6 +145,9 @@ static inline void ip_rt_put(struct rtab
14636                 dst_release(&rt->dst);
14637  }
14638  
14639 +#include <linux/vs_base.h>
14640 +#include <linux/vs_inet.h>
14641 +
14642  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
14643  
14644  extern const __u8 ip_tos2prio[16];
14645 @@ -154,6 +157,9 @@ static inline char rt_tos2priority(u8 to
14646         return ip_tos2prio[IPTOS_TOS(tos)>>1];
14647  }
14648  
14649 +extern int ip_v4_find_src(struct net *net, struct nx_info *,
14650 +       struct rtable **, struct flowi *);
14651 +
14652  static inline int ip_route_connect(struct rtable **rp, __be32 dst,
14653                                    __be32 src, u32 tos, int oif, u8 protocol,
14654                                    __be16 sport, __be16 dport, struct sock *sk,
14655 @@ -171,11 +177,24 @@ static inline int ip_route_connect(struc
14656  
14657         int err;
14658         struct net *net = sock_net(sk);
14659 +       struct nx_info *nx_info = current_nx_info();
14660  
14661         if (inet_sk(sk)->transparent)
14662                 fl.flags |= FLOWI_FLAG_ANYSRC;
14663  
14664 -       if (!dst || !src) {
14665 +       if (sk)
14666 +               nx_info = sk->sk_nx_info;
14667 +
14668 +       vxdprintk(VXD_CBIT(net, 4),
14669 +               "ip_route_connect(%p) %p,%p;%lx",
14670 +               sk, nx_info, sk->sk_socket,
14671 +               (sk->sk_socket?sk->sk_socket->flags:0));
14672 +
14673 +       err = ip_v4_find_src(net, nx_info, rp, &fl);
14674 +       if (err)
14675 +               return err;
14676 +
14677 +       if (!fl.fl4_dst || !fl.fl4_src) {
14678                 err = __ip_route_output_key(net, rp, &fl);
14679                 if (err)
14680                         return err;
14681 diff -NurpP --minimal linux-2.6.36/include/net/sock.h linux-2.6.36-vs2.3.0.36.36/include/net/sock.h
14682 --- linux-2.6.36/include/net/sock.h     2010-10-21 13:07:56.000000000 +0200
14683 +++ linux-2.6.36-vs2.3.0.36.36/include/net/sock.h       2010-10-21 13:09:36.000000000 +0200
14684 @@ -150,6 +150,10 @@ struct sock_common {
14685  #ifdef CONFIG_NET_NS
14686         struct net              *skc_net;
14687  #endif
14688 +       xid_t                   skc_xid;
14689 +       struct vx_info          *skc_vx_info;
14690 +       nid_t                   skc_nid;
14691 +       struct nx_info          *skc_nx_info;
14692  };
14693  
14694  /**
14695 @@ -241,6 +245,10 @@ struct sock {
14696  #define sk_bind_node           __sk_common.skc_bind_node
14697  #define sk_prot                        __sk_common.skc_prot
14698  #define sk_net                 __sk_common.skc_net
14699 +#define sk_xid                 __sk_common.skc_xid
14700 +#define sk_vx_info             __sk_common.skc_vx_info
14701 +#define sk_nid                 __sk_common.skc_nid
14702 +#define sk_nx_info             __sk_common.skc_nx_info
14703         kmemcheck_bitfield_begin(flags);
14704         unsigned int            sk_shutdown  : 2,
14705                                 sk_no_check  : 2,
14706 diff -NurpP --minimal linux-2.6.36/init/Kconfig linux-2.6.36-vs2.3.0.36.36/init/Kconfig
14707 --- linux-2.6.36/init/Kconfig   2010-10-21 13:07:56.000000000 +0200
14708 +++ linux-2.6.36-vs2.3.0.36.36/init/Kconfig     2010-10-21 13:09:36.000000000 +0200
14709 @@ -476,6 +476,7 @@ config HAVE_UNSTABLE_SCHED_CLOCK
14710  menuconfig CGROUPS
14711         boolean "Control Group support"
14712         depends on EVENTFD
14713 +       default y
14714         help
14715           This option adds support for grouping sets of processes together, for
14716           use with process control subsystems such as Cpusets, CFS, memory
14717 @@ -503,6 +504,7 @@ config CGROUP_DEBUG
14718  config CGROUP_NS
14719         bool "Namespace cgroup subsystem"
14720         depends on CGROUPS
14721 +       default n
14722         help
14723           Provides a simple namespace cgroup subsystem to
14724           provide hierarchical naming of sets of namespaces,
14725 diff -NurpP --minimal linux-2.6.36/init/main.c linux-2.6.36-vs2.3.0.36.36/init/main.c
14726 --- linux-2.6.36/init/main.c    2010-10-21 13:07:56.000000000 +0200
14727 +++ linux-2.6.36-vs2.3.0.36.36/init/main.c      2010-10-21 13:10:12.000000000 +0200
14728 @@ -68,6 +68,7 @@
14729  #include <linux/sfi.h>
14730  #include <linux/shmem_fs.h>
14731  #include <linux/slab.h>
14732 +#include <linux/vserver/percpu.h>
14733  
14734  #include <asm/io.h>
14735  #include <asm/bugs.h>
14736 diff -NurpP --minimal linux-2.6.36/ipc/mqueue.c linux-2.6.36-vs2.3.0.36.36/ipc/mqueue.c
14737 --- linux-2.6.36/ipc/mqueue.c   2010-10-21 13:07:56.000000000 +0200
14738 +++ linux-2.6.36-vs2.3.0.36.36/ipc/mqueue.c     2010-10-21 13:28:42.000000000 +0200
14739 @@ -33,6 +33,8 @@
14740  #include <linux/pid.h>
14741  #include <linux/ipc_namespace.h>
14742  #include <linux/slab.h>
14743 +#include <linux/vs_context.h>
14744 +#include <linux/vs_limit.h>
14745  
14746  #include <net/sock.h>
14747  #include "util.h"
14748 @@ -66,6 +68,7 @@ struct mqueue_inode_info {
14749         struct sigevent notify;
14750         struct pid* notify_owner;
14751         struct user_struct *user;       /* user who created, for accounting */
14752 +       struct vx_info *vxi;
14753         struct sock *notify_sock;
14754         struct sk_buff *notify_cookie;
14755  
14756 @@ -125,6 +128,7 @@ static struct inode *mqueue_get_inode(st
14757                 if (S_ISREG(mode)) {
14758                         struct mqueue_inode_info *info;
14759                         struct task_struct *p = current;
14760 +                       struct vx_info *vxi = p->vx_info;
14761                         unsigned long mq_bytes, mq_msg_tblsz;
14762  
14763                         inode->i_fop = &mqueue_file_operations;
14764 @@ -138,6 +142,7 @@ static struct inode *mqueue_get_inode(st
14765                         info->notify_owner = NULL;
14766                         info->qsize = 0;
14767                         info->user = NULL;      /* set when all is ok */
14768 +                       info->vxi = NULL;
14769                         memset(&info->attr, 0, sizeof(info->attr));
14770                         info->attr.mq_maxmsg = ipc_ns->mq_msg_max;
14771                         info->attr.mq_msgsize = ipc_ns->mq_msgsize_max;
14772 @@ -156,16 +161,19 @@ static struct inode *mqueue_get_inode(st
14773                         spin_lock(&mq_lock);
14774                         if (u->mq_bytes + mq_bytes < u->mq_bytes ||
14775                             u->mq_bytes + mq_bytes >
14776 -                           task_rlimit(p, RLIMIT_MSGQUEUE)) {
14777 +                           task_rlimit(p, RLIMIT_MSGQUEUE) ||
14778 +                           !vx_ipcmsg_avail(vxi, mq_bytes)) {
14779                                 spin_unlock(&mq_lock);
14780                                 /* mqueue_evict_inode() releases info->messages */
14781                                 goto out_inode;
14782                         }
14783                         u->mq_bytes += mq_bytes;
14784 +                       vx_ipcmsg_add(vxi, u, mq_bytes);
14785                         spin_unlock(&mq_lock);
14786  
14787                         /* all is ok */
14788                         info->user = get_uid(u);
14789 +                       info->vxi = get_vx_info(vxi);
14790                 } else if (S_ISDIR(mode)) {
14791                         inc_nlink(inode);
14792                         /* Some things misbehave if size == 0 on a directory */
14793 @@ -267,8 +275,11 @@ static void mqueue_evict_inode(struct in
14794             + info->attr.mq_msgsize);
14795         user = info->user;
14796         if (user) {
14797 +               struct vx_info *vxi = info->vxi;
14798 +
14799                 spin_lock(&mq_lock);
14800                 user->mq_bytes -= mq_bytes;
14801 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
14802                 /*
14803                  * get_ns_from_inode() ensures that the
14804                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
14805 @@ -278,6 +289,7 @@ static void mqueue_evict_inode(struct in
14806                 if (ipc_ns)
14807                         ipc_ns->mq_queues_count--;
14808                 spin_unlock(&mq_lock);
14809 +               put_vx_info(vxi);
14810                 free_uid(user);
14811         }
14812         if (ipc_ns)
14813 diff -NurpP --minimal linux-2.6.36/ipc/msg.c linux-2.6.36-vs2.3.0.36.36/ipc/msg.c
14814 --- linux-2.6.36/ipc/msg.c      2010-08-02 16:52:57.000000000 +0200
14815 +++ linux-2.6.36-vs2.3.0.36.36/ipc/msg.c        2010-10-21 13:09:36.000000000 +0200
14816 @@ -37,6 +37,7 @@
14817  #include <linux/rwsem.h>
14818  #include <linux/nsproxy.h>
14819  #include <linux/ipc_namespace.h>
14820 +#include <linux/vs_base.h>
14821  
14822  #include <asm/current.h>
14823  #include <asm/uaccess.h>
14824 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
14825  
14826         msq->q_perm.mode = msgflg & S_IRWXUGO;
14827         msq->q_perm.key = key;
14828 +       msq->q_perm.xid = vx_current_xid();
14829  
14830         msq->q_perm.security = NULL;
14831         retval = security_msg_queue_alloc(msq);
14832 diff -NurpP --minimal linux-2.6.36/ipc/namespace.c linux-2.6.36-vs2.3.0.36.36/ipc/namespace.c
14833 --- linux-2.6.36/ipc/namespace.c        2009-09-10 15:26:27.000000000 +0200
14834 +++ linux-2.6.36-vs2.3.0.36.36/ipc/namespace.c  2010-10-21 13:09:36.000000000 +0200
14835 @@ -11,6 +11,8 @@
14836  #include <linux/slab.h>
14837  #include <linux/fs.h>
14838  #include <linux/mount.h>
14839 +#include <linux/vs_base.h>
14840 +#include <linux/vserver/global.h>
14841  
14842  #include "util.h"
14843  
14844 diff -NurpP --minimal linux-2.6.36/ipc/sem.c linux-2.6.36-vs2.3.0.36.36/ipc/sem.c
14845 --- linux-2.6.36/ipc/sem.c      2010-10-21 13:07:56.000000000 +0200
14846 +++ linux-2.6.36-vs2.3.0.36.36/ipc/sem.c        2010-10-21 13:09:36.000000000 +0200
14847 @@ -86,6 +86,8 @@
14848  #include <linux/rwsem.h>
14849  #include <linux/nsproxy.h>
14850  #include <linux/ipc_namespace.h>
14851 +#include <linux/vs_base.h>
14852 +#include <linux/vs_limit.h>
14853  
14854  #include <asm/uaccess.h>
14855  #include "util.h"
14856 @@ -260,6 +262,7 @@ static int newary(struct ipc_namespace *
14857  
14858         sma->sem_perm.mode = (semflg & S_IRWXUGO);
14859         sma->sem_perm.key = key;
14860 +       sma->sem_perm.xid = vx_current_xid();
14861  
14862         sma->sem_perm.security = NULL;
14863         retval = security_sem_alloc(sma);
14864 @@ -275,6 +278,9 @@ static int newary(struct ipc_namespace *
14865                 return id;
14866         }
14867         ns->used_sems += nsems;
14868 +       /* FIXME: obsoleted? */
14869 +       vx_semary_inc(sma);
14870 +       vx_nsems_add(sma, nsems);
14871  
14872         sma->sem_base = (struct sem *) &sma[1];
14873  
14874 @@ -730,6 +736,9 @@ static void freeary(struct ipc_namespace
14875  
14876         wake_up_sem_queue_do(&tasks);
14877         ns->used_sems -= sma->sem_nsems;
14878 +       /* FIXME: obsoleted? */
14879 +       vx_nsems_sub(sma, sma->sem_nsems);
14880 +       vx_semary_dec(sma);
14881         security_sem_free(sma);
14882         ipc_rcu_putref(sma);
14883  }
14884 diff -NurpP --minimal linux-2.6.36/ipc/shm.c linux-2.6.36-vs2.3.0.36.36/ipc/shm.c
14885 --- linux-2.6.36/ipc/shm.c      2010-08-02 16:52:57.000000000 +0200
14886 +++ linux-2.6.36-vs2.3.0.36.36/ipc/shm.c        2010-10-21 13:09:36.000000000 +0200
14887 @@ -39,6 +39,8 @@
14888  #include <linux/nsproxy.h>
14889  #include <linux/mount.h>
14890  #include <linux/ipc_namespace.h>
14891 +#include <linux/vs_context.h>
14892 +#include <linux/vs_limit.h>
14893  
14894  #include <asm/uaccess.h>
14895  
14896 @@ -169,7 +171,12 @@ static void shm_open(struct vm_area_stru
14897   */
14898  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
14899  {
14900 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14901 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
14902 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14903 +
14904 +       vx_ipcshm_sub(vxi, shp, numpages);
14905 +       ns->shm_tot -= numpages;
14906 +
14907         shm_rmid(ns, shp);
14908         shm_unlock(shp);
14909         if (!is_file_hugepages(shp->shm_file))
14910 @@ -179,6 +186,7 @@ static void shm_destroy(struct ipc_names
14911                                                 shp->mlock_user);
14912         fput (shp->shm_file);
14913         security_shm_free(shp);
14914 +       put_vx_info(vxi);
14915         ipc_rcu_putref(shp);
14916  }
14917  
14918 @@ -349,11 +357,15 @@ static int newseg(struct ipc_namespace *
14919         if (ns->shm_tot + numpages > ns->shm_ctlall)
14920                 return -ENOSPC;
14921  
14922 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
14923 +               return -ENOSPC;
14924 +
14925         shp = ipc_rcu_alloc(sizeof(*shp));
14926         if (!shp)
14927                 return -ENOMEM;
14928  
14929         shp->shm_perm.key = key;
14930 +       shp->shm_perm.xid = vx_current_xid();
14931         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
14932         shp->mlock_user = NULL;
14933  
14934 @@ -407,6 +419,7 @@ static int newseg(struct ipc_namespace *
14935         ns->shm_tot += numpages;
14936         error = shp->shm_perm.id;
14937         shm_unlock(shp);
14938 +       vx_ipcshm_add(current_vx_info(), key, numpages);
14939         return error;
14940  
14941  no_id:
14942 diff -NurpP --minimal linux-2.6.36/kernel/capability.c linux-2.6.36-vs2.3.0.36.36/kernel/capability.c
14943 --- linux-2.6.36/kernel/capability.c    2010-08-02 16:52:57.000000000 +0200
14944 +++ linux-2.6.36-vs2.3.0.36.36/kernel/capability.c      2010-10-21 13:09:36.000000000 +0200
14945 @@ -14,6 +14,7 @@
14946  #include <linux/security.h>
14947  #include <linux/syscalls.h>
14948  #include <linux/pid_namespace.h>
14949 +#include <linux/vs_context.h>
14950  #include <asm/uaccess.h>
14951  
14952  /*
14953 @@ -119,6 +120,7 @@ static int cap_validate_magic(cap_user_h
14954         return 0;
14955  }
14956  
14957 +
14958  /*
14959   * The only thing that can change the capabilities of the current
14960   * process is the current process. As such, we can't be in this code
14961 @@ -289,6 +291,8 @@ error:
14962         return ret;
14963  }
14964  
14965 +#include <linux/vserver/base.h>
14966 +
14967  /**
14968   * capable - Determine if the current task has a superior capability in effect
14969   * @cap: The capability to be tested for
14970 @@ -301,6 +305,9 @@ error:
14971   */
14972  int capable(int cap)
14973  {
14974 +       /* here for now so we don't require task locking */
14975 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
14976 +               return 0;
14977         if (unlikely(!cap_valid(cap))) {
14978                 printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
14979                 BUG();
14980 diff -NurpP --minimal linux-2.6.36/kernel/compat.c linux-2.6.36-vs2.3.0.36.36/kernel/compat.c
14981 --- linux-2.6.36/kernel/compat.c        2010-10-21 13:07:56.000000000 +0200
14982 +++ linux-2.6.36-vs2.3.0.36.36/kernel/compat.c  2010-10-21 14:22:43.000000000 +0200
14983 @@ -914,7 +914,7 @@ asmlinkage long compat_sys_stime(compat_
14984         if (err)
14985                 return err;
14986  
14987 -       do_settimeofday(&tv);
14988 +       vx_settimeofday(&tv);
14989         return 0;
14990  }
14991  
14992 diff -NurpP --minimal linux-2.6.36/kernel/exit.c linux-2.6.36-vs2.3.0.36.36/kernel/exit.c
14993 --- linux-2.6.36/kernel/exit.c  2010-10-21 13:07:56.000000000 +0200
14994 +++ linux-2.6.36-vs2.3.0.36.36/kernel/exit.c    2010-10-21 13:09:36.000000000 +0200
14995 @@ -48,6 +48,10 @@
14996  #include <linux/fs_struct.h>
14997  #include <linux/init_task.h>
14998  #include <linux/perf_event.h>
14999 +#include <linux/vs_limit.h>
15000 +#include <linux/vs_context.h>
15001 +#include <linux/vs_network.h>
15002 +#include <linux/vs_pid.h>
15003  #include <trace/events/sched.h>
15004  #include <linux/hw_breakpoint.h>
15005  
15006 @@ -487,9 +491,11 @@ static void close_files(struct files_str
15007                                         filp_close(file, files);
15008                                         cond_resched();
15009                                 }
15010 +                               vx_openfd_dec(i);
15011                         }
15012                         i++;
15013                         set >>= 1;
15014 +                       cond_resched();
15015                 }
15016         }
15017  }
15018 @@ -1023,11 +1029,16 @@ NORET_TYPE void do_exit(long code)
15019  
15020         validate_creds_for_do_exit(tsk);
15021  
15022 +       /* needs to stay after exit_notify() */
15023 +       exit_vx_info(tsk, code);
15024 +       exit_nx_info(tsk);
15025 +
15026         preempt_disable();
15027         exit_rcu();
15028         /* causes final put_task_struct in finish_task_switch(). */
15029         tsk->state = TASK_DEAD;
15030         schedule();
15031 +       printk("bad task: %p [%lx]\n", current, current->state);
15032         BUG();
15033         /* Avoid "noreturn function does return".  */
15034         for (;;)
15035 diff -NurpP --minimal linux-2.6.36/kernel/fork.c linux-2.6.36-vs2.3.0.36.36/kernel/fork.c
15036 --- linux-2.6.36/kernel/fork.c  2010-10-21 13:07:56.000000000 +0200
15037 +++ linux-2.6.36-vs2.3.0.36.36/kernel/fork.c    2010-10-21 13:09:36.000000000 +0200
15038 @@ -65,6 +65,10 @@
15039  #include <linux/perf_event.h>
15040  #include <linux/posix-timers.h>
15041  #include <linux/user-return-notifier.h>
15042 +#include <linux/vs_context.h>
15043 +#include <linux/vs_network.h>
15044 +#include <linux/vs_limit.h>
15045 +#include <linux/vs_memory.h>
15046  
15047  #include <asm/pgtable.h>
15048  #include <asm/pgalloc.h>
15049 @@ -160,6 +164,8 @@ void free_task(struct task_struct *tsk)
15050         account_kernel_stack(tsk->stack, -1);
15051         free_thread_info(tsk->stack);
15052         rt_mutex_debug_task_free(tsk);
15053 +       clr_vx_info(&tsk->vx_info);
15054 +       clr_nx_info(&tsk->nx_info);
15055         ftrace_graph_exit_task(tsk);
15056         free_task_struct(tsk);
15057  }
15058 @@ -492,6 +498,7 @@ static struct mm_struct * mm_init(struct
15059         if (likely(!mm_alloc_pgd(mm))) {
15060                 mm->def_flags = 0;
15061                 mmu_notifier_mm_init(mm);
15062 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
15063                 return mm;
15064         }
15065  
15066 @@ -525,6 +532,7 @@ void __mmdrop(struct mm_struct *mm)
15067         mm_free_pgd(mm);
15068         destroy_context(mm);
15069         mmu_notifier_mm_destroy(mm);
15070 +       clr_vx_info(&mm->mm_vx_info);
15071         free_mm(mm);
15072  }
15073  EXPORT_SYMBOL_GPL(__mmdrop);
15074 @@ -660,6 +668,7 @@ struct mm_struct *dup_mm(struct task_str
15075                 goto fail_nomem;
15076  
15077         memcpy(mm, oldmm, sizeof(*mm));
15078 +       mm->mm_vx_info = NULL;
15079  
15080         /* Initializing for Swap token stuff */
15081         mm->token_priority = 0;
15082 @@ -698,6 +707,7 @@ fail_nocontext:
15083          * If init_new_context() failed, we cannot use mmput() to free the mm
15084          * because it calls destroy_context()
15085          */
15086 +       clr_vx_info(&mm->mm_vx_info);
15087         mm_free_pgd(mm);
15088         free_mm(mm);
15089         return NULL;
15090 @@ -973,6 +983,8 @@ static struct task_struct *copy_process(
15091         int retval;
15092         struct task_struct *p;
15093         int cgroup_callbacks_done = 0;
15094 +       struct vx_info *vxi;
15095 +       struct nx_info *nxi;
15096  
15097         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
15098                 return ERR_PTR(-EINVAL);
15099 @@ -1019,7 +1031,12 @@ static struct task_struct *copy_process(
15100         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
15101         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
15102  #endif
15103 +       init_vx_info(&p->vx_info, current_vx_info());
15104 +       init_nx_info(&p->nx_info, current_nx_info());
15105 +
15106         retval = -EAGAIN;
15107 +       if (!vx_nproc_avail(1))
15108 +               goto bad_fork_free;
15109         if (atomic_read(&p->real_cred->user->processes) >=
15110                         task_rlimit(p, RLIMIT_NPROC)) {
15111                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
15112 @@ -1284,6 +1301,18 @@ static struct task_struct *copy_process(
15113  
15114         total_forks++;
15115         spin_unlock(&current->sighand->siglock);
15116 +
15117 +       /* p is copy of current */
15118 +       vxi = p->vx_info;
15119 +       if (vxi) {
15120 +               claim_vx_info(vxi, p);
15121 +               atomic_inc(&vxi->cvirt.nr_threads);
15122 +               atomic_inc(&vxi->cvirt.total_forks);
15123 +               vx_nproc_inc(p);
15124 +       }
15125 +       nxi = p->nx_info;
15126 +       if (nxi)
15127 +               claim_nx_info(nxi, p);
15128         write_unlock_irq(&tasklist_lock);
15129         proc_fork_connector(p);
15130         cgroup_post_fork(p);
15131 diff -NurpP --minimal linux-2.6.36/kernel/kthread.c linux-2.6.36-vs2.3.0.36.36/kernel/kthread.c
15132 --- linux-2.6.36/kernel/kthread.c       2010-10-21 13:07:57.000000000 +0200
15133 +++ linux-2.6.36-vs2.3.0.36.36/kernel/kthread.c 2010-10-21 13:42:40.000000000 +0200
15134 @@ -16,6 +16,7 @@
15135  #include <linux/mutex.h>
15136  #include <linux/slab.h>
15137  #include <linux/freezer.h>
15138 +#include <linux/vs_pid.h>
15139  #include <trace/events/sched.h>
15140  
15141  static DEFINE_SPINLOCK(kthread_create_lock);
15142 diff -NurpP --minimal linux-2.6.36/kernel/Makefile linux-2.6.36-vs2.3.0.36.36/kernel/Makefile
15143 --- linux-2.6.36/kernel/Makefile        2010-10-21 13:07:56.000000000 +0200
15144 +++ linux-2.6.36-vs2.3.0.36.36/kernel/Makefile  2010-10-21 13:09:36.000000000 +0200
15145 @@ -25,6 +25,7 @@ CFLAGS_REMOVE_sched_clock.o = -pg
15146  CFLAGS_REMOVE_perf_event.o = -pg
15147  endif
15148  
15149 +obj-y += vserver/
15150  obj-$(CONFIG_FREEZER) += freezer.o
15151  obj-$(CONFIG_PROFILING) += profile.o
15152  obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
15153 diff -NurpP --minimal linux-2.6.36/kernel/nsproxy.c linux-2.6.36-vs2.3.0.36.36/kernel/nsproxy.c
15154 --- linux-2.6.36/kernel/nsproxy.c       2010-07-07 18:31:57.000000000 +0200
15155 +++ linux-2.6.36-vs2.3.0.36.36/kernel/nsproxy.c 2010-10-21 13:09:36.000000000 +0200
15156 @@ -20,6 +20,8 @@
15157  #include <linux/mnt_namespace.h>
15158  #include <linux/utsname.h>
15159  #include <linux/pid_namespace.h>
15160 +#include <linux/vserver/global.h>
15161 +#include <linux/vserver/debug.h>
15162  #include <net/net_namespace.h>
15163  #include <linux/ipc_namespace.h>
15164  
15165 @@ -43,8 +45,11 @@ static inline struct nsproxy *create_nsp
15166         struct nsproxy *nsproxy;
15167  
15168         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
15169 -       if (nsproxy)
15170 +       if (nsproxy) {
15171                 atomic_set(&nsproxy->count, 1);
15172 +               atomic_inc(&vs_global_nsproxy);
15173 +       }
15174 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
15175         return nsproxy;
15176  }
15177  
15178 @@ -53,41 +58,52 @@ static inline struct nsproxy *create_nsp
15179   * Return the newly created nsproxy.  Do not attach this to the task,
15180   * leave it to the caller to do proper locking and attach it to task.
15181   */
15182 -static struct nsproxy *create_new_namespaces(unsigned long flags,
15183 -                       struct task_struct *tsk, struct fs_struct *new_fs)
15184 +static struct nsproxy *unshare_namespaces(unsigned long flags,
15185 +                       struct nsproxy *orig, struct fs_struct *new_fs)
15186  {
15187         struct nsproxy *new_nsp;
15188         int err;
15189  
15190 +       vxdprintk(VXD_CBIT(space, 4),
15191 +               "unshare_namespaces(0x%08lx,%p,%p)",
15192 +               flags, orig, new_fs);
15193 +
15194         new_nsp = create_nsproxy();
15195         if (!new_nsp)
15196                 return ERR_PTR(-ENOMEM);
15197  
15198 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
15199 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
15200         if (IS_ERR(new_nsp->mnt_ns)) {
15201                 err = PTR_ERR(new_nsp->mnt_ns);
15202                 goto out_ns;
15203         }
15204  
15205 -       new_nsp->uts_ns = copy_utsname(flags, tsk->nsproxy->uts_ns);
15206 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns);
15207         if (IS_ERR(new_nsp->uts_ns)) {
15208                 err = PTR_ERR(new_nsp->uts_ns);
15209                 goto out_uts;
15210         }
15211  
15212 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk->nsproxy->ipc_ns);
15213 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns);
15214         if (IS_ERR(new_nsp->ipc_ns)) {
15215                 err = PTR_ERR(new_nsp->ipc_ns);
15216                 goto out_ipc;
15217         }
15218  
15219 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
15220 +       new_nsp->pid_ns = copy_pid_ns(flags, orig->pid_ns);
15221         if (IS_ERR(new_nsp->pid_ns)) {
15222                 err = PTR_ERR(new_nsp->pid_ns);
15223                 goto out_pid;
15224         }
15225  
15226 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
15227 +       /* disabled now?
15228 +       new_nsp->user_ns = copy_user_ns(flags, orig->user_ns);
15229 +       if (IS_ERR(new_nsp->user_ns)) {
15230 +               err = PTR_ERR(new_nsp->user_ns);
15231 +               goto out_user;
15232 +       } */
15233 +
15234 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
15235         if (IS_ERR(new_nsp->net_ns)) {
15236                 err = PTR_ERR(new_nsp->net_ns);
15237                 goto out_net;
15238 @@ -112,6 +128,38 @@ out_ns:
15239         return ERR_PTR(err);
15240  }
15241  
15242 +static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
15243 +                       struct fs_struct *new_fs)
15244 +{
15245 +       return unshare_namespaces(flags, tsk->nsproxy, new_fs);
15246 +}
15247 +
15248 +/*
15249 + * copies the nsproxy, setting refcount to 1, and grabbing a
15250 + * reference to all contained namespaces.
15251 + */
15252 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
15253 +{
15254 +       struct nsproxy *ns = create_nsproxy();
15255 +
15256 +       if (ns) {
15257 +               memcpy(ns, orig, sizeof(struct nsproxy));
15258 +               atomic_set(&ns->count, 1);
15259 +
15260 +               if (ns->mnt_ns)
15261 +                       get_mnt_ns(ns->mnt_ns);
15262 +               if (ns->uts_ns)
15263 +                       get_uts_ns(ns->uts_ns);
15264 +               if (ns->ipc_ns)
15265 +                       get_ipc_ns(ns->ipc_ns);
15266 +               if (ns->pid_ns)
15267 +                       get_pid_ns(ns->pid_ns);
15268 +               if (ns->net_ns)
15269 +                       get_net(ns->net_ns);
15270 +       }
15271 +       return ns;
15272 +}
15273 +
15274  /*
15275   * called from clone.  This now handles copy for nsproxy and all
15276   * namespaces therein.
15277 @@ -119,9 +167,12 @@ out_ns:
15278  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
15279  {
15280         struct nsproxy *old_ns = tsk->nsproxy;
15281 -       struct nsproxy *new_ns;
15282 +       struct nsproxy *new_ns = NULL;
15283         int err = 0;
15284  
15285 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
15286 +               flags, tsk, old_ns);
15287 +
15288         if (!old_ns)
15289                 return 0;
15290  
15291 @@ -131,7 +182,7 @@ int copy_namespaces(unsigned long flags,
15292                                 CLONE_NEWPID | CLONE_NEWNET)))
15293                 return 0;
15294  
15295 -       if (!capable(CAP_SYS_ADMIN)) {
15296 +       if (!vx_can_unshare(CAP_SYS_ADMIN, flags)) {
15297                 err = -EPERM;
15298                 goto out;
15299         }
15300 @@ -158,6 +209,9 @@ int copy_namespaces(unsigned long flags,
15301  
15302  out:
15303         put_nsproxy(old_ns);
15304 +       vxdprintk(VXD_CBIT(space, 3),
15305 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
15306 +               flags, tsk, old_ns, err, new_ns);
15307         return err;
15308  }
15309  
15310 @@ -171,7 +225,9 @@ void free_nsproxy(struct nsproxy *ns)
15311                 put_ipc_ns(ns->ipc_ns);
15312         if (ns->pid_ns)
15313                 put_pid_ns(ns->pid_ns);
15314 -       put_net(ns->net_ns);
15315 +       if (ns->net_ns)
15316 +               put_net(ns->net_ns);
15317 +       atomic_dec(&vs_global_nsproxy);
15318         kmem_cache_free(nsproxy_cachep, ns);
15319  }
15320  
15321 @@ -184,11 +240,15 @@ int unshare_nsproxy_namespaces(unsigned 
15322  {
15323         int err = 0;
15324  
15325 +       vxdprintk(VXD_CBIT(space, 4),
15326 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
15327 +               unshare_flags, current->nsproxy);
15328 +
15329         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
15330                                CLONE_NEWNET)))
15331                 return 0;
15332  
15333 -       if (!capable(CAP_SYS_ADMIN))
15334 +       if (!vx_can_unshare(CAP_SYS_ADMIN, unshare_flags))
15335                 return -EPERM;
15336  
15337         *new_nsp = create_new_namespaces(unshare_flags, current,
15338 diff -NurpP --minimal linux-2.6.36/kernel/pid.c linux-2.6.36-vs2.3.0.36.36/kernel/pid.c
15339 --- linux-2.6.36/kernel/pid.c   2010-10-21 13:07:57.000000000 +0200
15340 +++ linux-2.6.36-vs2.3.0.36.36/kernel/pid.c     2010-10-21 13:09:36.000000000 +0200
15341 @@ -36,6 +36,7 @@
15342  #include <linux/pid_namespace.h>
15343  #include <linux/init_task.h>
15344  #include <linux/syscalls.h>
15345 +#include <linux/vs_pid.h>
15346  
15347  #define pid_hashfn(nr, ns)     \
15348         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
15349 @@ -339,7 +340,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
15350  
15351  struct pid *find_vpid(int nr)
15352  {
15353 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
15354 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
15355  }
15356  EXPORT_SYMBOL_GPL(find_vpid);
15357  
15358 @@ -399,6 +400,9 @@ void transfer_pid(struct task_struct *ol
15359  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
15360  {
15361         struct task_struct *result = NULL;
15362 +
15363 +       if (type == PIDTYPE_REALPID)
15364 +               type = PIDTYPE_PID;
15365         if (pid) {
15366                 struct hlist_node *first;
15367                 first = rcu_dereference_check(pid->tasks[type].first,
15368 @@ -416,7 +420,7 @@ EXPORT_SYMBOL(pid_task);
15369   */
15370  struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
15371  {
15372 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
15373 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
15374  }
15375  
15376  struct task_struct *find_task_by_vpid(pid_t vnr)
15377 @@ -458,7 +462,7 @@ struct pid *find_get_pid(pid_t nr)
15378  }
15379  EXPORT_SYMBOL_GPL(find_get_pid);
15380  
15381 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15382 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
15383  {
15384         struct upid *upid;
15385         pid_t nr = 0;
15386 @@ -471,6 +475,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
15387         return nr;
15388  }
15389  
15390 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15391 +{
15392 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
15393 +}
15394 +
15395  pid_t pid_vnr(struct pid *pid)
15396  {
15397         return pid_nr_ns(pid, current->nsproxy->pid_ns);
15398 diff -NurpP --minimal linux-2.6.36/kernel/pid_namespace.c linux-2.6.36-vs2.3.0.36.36/kernel/pid_namespace.c
15399 --- linux-2.6.36/kernel/pid_namespace.c 2010-07-07 18:31:57.000000000 +0200
15400 +++ linux-2.6.36-vs2.3.0.36.36/kernel/pid_namespace.c   2010-10-21 13:09:36.000000000 +0200
15401 @@ -14,6 +14,7 @@
15402  #include <linux/err.h>
15403  #include <linux/acct.h>
15404  #include <linux/slab.h>
15405 +#include <linux/vserver/global.h>
15406  
15407  #define BITS_PER_PAGE          (PAGE_SIZE*8)
15408  
15409 @@ -87,6 +88,7 @@ static struct pid_namespace *create_pid_
15410                 goto out_free_map;
15411  
15412         kref_init(&ns->kref);
15413 +       atomic_inc(&vs_global_pid_ns);
15414         ns->level = level;
15415         ns->parent = get_pid_ns(parent_pid_ns);
15416  
15417 @@ -112,6 +114,7 @@ static void destroy_pid_namespace(struct
15418  
15419         for (i = 0; i < PIDMAP_ENTRIES; i++)
15420                 kfree(ns->pidmap[i].page);
15421 +       atomic_dec(&vs_global_pid_ns);
15422         kmem_cache_free(pid_ns_cachep, ns);
15423  }
15424  
15425 diff -NurpP --minimal linux-2.6.36/kernel/posix-timers.c linux-2.6.36-vs2.3.0.36.36/kernel/posix-timers.c
15426 --- linux-2.6.36/kernel/posix-timers.c  2010-10-21 13:07:57.000000000 +0200
15427 +++ linux-2.6.36-vs2.3.0.36.36/kernel/posix-timers.c    2010-10-21 13:09:36.000000000 +0200
15428 @@ -46,6 +46,7 @@
15429  #include <linux/wait.h>
15430  #include <linux/workqueue.h>
15431  #include <linux/module.h>
15432 +#include <linux/vs_context.h>
15433  
15434  /*
15435   * Management arrays for POSIX timers.  Timers are kept in slab memory
15436 @@ -363,6 +364,7 @@ int posix_timer_event(struct k_itimer *t
15437  {
15438         struct task_struct *task;
15439         int shared, ret = -1;
15440 +
15441         /*
15442          * FIXME: if ->sigq is queued we can race with
15443          * dequeue_signal()->do_schedule_next_timer().
15444 @@ -379,10 +381,18 @@ int posix_timer_event(struct k_itimer *t
15445         rcu_read_lock();
15446         task = pid_task(timr->it_pid, PIDTYPE_PID);
15447         if (task) {
15448 +               struct vx_info_save vxis;
15449 +               struct vx_info *vxi;
15450 +
15451 +               vxi = get_vx_info(task->vx_info);
15452 +               enter_vx_info(vxi, &vxis);
15453                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
15454                 ret = send_sigqueue(timr->sigq, task, shared);
15455 +               leave_vx_info(&vxis);
15456 +               put_vx_info(vxi);
15457         }
15458         rcu_read_unlock();
15459 +
15460         /* If we failed to send the signal the timer stops. */
15461         return ret > 0;
15462  }
15463 diff -NurpP --minimal linux-2.6.36/kernel/printk.c linux-2.6.36-vs2.3.0.36.36/kernel/printk.c
15464 --- linux-2.6.36/kernel/printk.c        2010-10-21 13:07:57.000000000 +0200
15465 +++ linux-2.6.36-vs2.3.0.36.36/kernel/printk.c  2010-10-21 13:43:06.000000000 +0200
15466 @@ -39,6 +39,7 @@
15467  #include <linux/syslog.h>
15468  #include <linux/cpu.h>
15469  #include <linux/notifier.h>
15470 +#include <linux/vs_cvirt.h>
15471  
15472  #include <asm/uaccess.h>
15473  
15474 @@ -266,18 +267,15 @@ int do_syslog(int type, char __user *buf
15475         unsigned i, j, limit, count;
15476         int do_clear = 0;
15477         char c;
15478 -       int error = 0;
15479 +       int error;
15480  
15481         error = security_syslog(type, from_file);
15482         if (error)
15483                 return error;
15484  
15485 -       switch (type) {
15486 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
15487 -               break;
15488 -       case SYSLOG_ACTION_OPEN:        /* Open log */
15489 -               break;
15490 -       case SYSLOG_ACTION_READ:        /* Read from log */
15491 +       if ((type == SYSLOG_ACTION_READ) ||
15492 +           (type == SYSLOG_ACTION_READ_ALL) ||
15493 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
15494                 error = -EINVAL;
15495                 if (!buf || len < 0)
15496                         goto out;
15497 @@ -288,6 +286,16 @@ int do_syslog(int type, char __user *buf
15498                         error = -EFAULT;
15499                         goto out;
15500                 }
15501 +       }
15502 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15503 +               return vx_do_syslog(type, buf, len);
15504 +
15505 +       switch (type) {
15506 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
15507 +               break;
15508 +       case SYSLOG_ACTION_OPEN:        /* Open log */
15509 +               break;
15510 +       case SYSLOG_ACTION_READ:        /* Read from log */
15511                 error = wait_event_interruptible(log_wait,
15512                                                         (log_start - log_end));
15513                 if (error)
15514 @@ -314,16 +322,6 @@ int do_syslog(int type, char __user *buf
15515                 /* FALL THRU */
15516         /* Read last kernel messages */
15517         case SYSLOG_ACTION_READ_ALL:
15518 -               error = -EINVAL;
15519 -               if (!buf || len < 0)
15520 -                       goto out;
15521 -               error = 0;
15522 -               if (!len)
15523 -                       goto out;
15524 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
15525 -                       error = -EFAULT;
15526 -                       goto out;
15527 -               }
15528                 count = len;
15529                 if (count > log_buf_len)
15530                         count = log_buf_len;
15531 diff -NurpP --minimal linux-2.6.36/kernel/ptrace.c linux-2.6.36-vs2.3.0.36.36/kernel/ptrace.c
15532 --- linux-2.6.36/kernel/ptrace.c        2010-10-21 13:07:57.000000000 +0200
15533 +++ linux-2.6.36-vs2.3.0.36.36/kernel/ptrace.c  2010-10-21 13:09:36.000000000 +0200
15534 @@ -22,6 +22,7 @@
15535  #include <linux/syscalls.h>
15536  #include <linux/uaccess.h>
15537  #include <linux/regset.h>
15538 +#include <linux/vs_context.h>
15539  
15540  
15541  /*
15542 @@ -150,6 +151,11 @@ int __ptrace_may_access(struct task_stru
15543                 dumpable = get_dumpable(task->mm);
15544         if (!dumpable && !capable(CAP_SYS_PTRACE))
15545                 return -EPERM;
15546 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_IDENT))
15547 +               return -EPERM;
15548 +       if (!vx_check(task->xid, VS_IDENT) &&
15549 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
15550 +               return -EACCES;
15551  
15552         return security_ptrace_access_check(task, mode);
15553  }
15554 @@ -709,6 +715,10 @@ SYSCALL_DEFINE4(ptrace, long, request, l
15555                 goto out;
15556         }
15557  
15558 +       ret = -EPERM;
15559 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
15560 +               goto out_put_task_struct;
15561 +
15562         if (request == PTRACE_ATTACH) {
15563                 ret = ptrace_attach(child);
15564                 /*
15565 diff -NurpP --minimal linux-2.6.36/kernel/sched.c linux-2.6.36-vs2.3.0.36.36/kernel/sched.c
15566 --- linux-2.6.36/kernel/sched.c 2010-10-21 13:07:57.000000000 +0200
15567 +++ linux-2.6.36-vs2.3.0.36.36/kernel/sched.c   2010-10-21 13:09:36.000000000 +0200
15568 @@ -72,6 +72,8 @@
15569  #include <linux/ctype.h>
15570  #include <linux/ftrace.h>
15571  #include <linux/slab.h>
15572 +#include <linux/vs_sched.h>
15573 +#include <linux/vs_cvirt.h>
15574  
15575  #include <asm/tlb.h>
15576  #include <asm/irq_regs.h>
15577 @@ -3024,9 +3026,17 @@ static inline long calc_load_fold_idle(v
15578   */
15579  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
15580  {
15581 -       loads[0] = (avenrun[0] + offset) << shift;
15582 -       loads[1] = (avenrun[1] + offset) << shift;
15583 -       loads[2] = (avenrun[2] + offset) << shift;
15584 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
15585 +               struct vx_info *vxi = current_vx_info();
15586 +
15587 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
15588 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
15589 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
15590 +       } else {
15591 +               loads[0] = (avenrun[0] + offset) << shift;
15592 +               loads[1] = (avenrun[1] + offset) << shift;
15593 +               loads[2] = (avenrun[2] + offset) << shift;
15594 +       }
15595  }
15596  
15597  static unsigned long
15598 @@ -3321,16 +3331,19 @@ void account_user_time(struct task_struc
15599                        cputime_t cputime_scaled)
15600  {
15601         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
15602 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15603         cputime64_t tmp;
15604 +       int nice = (TASK_NICE(p) > 0);
15605  
15606         /* Add user time to process. */
15607         p->utime = cputime_add(p->utime, cputime);
15608         p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
15609 +       vx_account_user(vxi, cputime, nice);
15610         account_group_user_time(p, cputime);
15611  
15612         /* Add user time to cpustat. */
15613         tmp = cputime_to_cputime64(cputime);
15614 -       if (TASK_NICE(p) > 0)
15615 +       if (nice)
15616                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
15617         else
15618                 cpustat->user = cputime64_add(cpustat->user, tmp);
15619 @@ -3381,6 +3394,7 @@ void account_system_time(struct task_str
15620                          cputime_t cputime, cputime_t cputime_scaled)
15621  {
15622         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
15623 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15624         cputime64_t tmp;
15625  
15626         if ((p->flags & PF_VCPU) && (irq_count() - hardirq_offset == 0)) {
15627 @@ -3391,6 +3405,7 @@ void account_system_time(struct task_str
15628         /* Add system time to process. */
15629         p->stime = cputime_add(p->stime, cputime);
15630         p->stimescaled = cputime_add(p->stimescaled, cputime_scaled);
15631 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
15632         account_group_system_time(p, cputime);
15633  
15634         /* Add system time to cpustat. */
15635 @@ -4477,7 +4492,7 @@ SYSCALL_DEFINE1(nice, int, increment)
15636                 nice = 19;
15637  
15638         if (increment < 0 && !can_nice(current, nice))
15639 -               return -EPERM;
15640 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
15641  
15642         retval = security_task_setnice(current, nice);
15643         if (retval)
15644 diff -NurpP --minimal linux-2.6.36/kernel/sched_fair.c linux-2.6.36-vs2.3.0.36.36/kernel/sched_fair.c
15645 --- linux-2.6.36/kernel/sched_fair.c    2010-10-21 13:07:57.000000000 +0200
15646 +++ linux-2.6.36-vs2.3.0.36.36/kernel/sched_fair.c      2010-10-21 13:09:36.000000000 +0200
15647 @@ -782,6 +782,9 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
15648         check_spread(cfs_rq, se);
15649         if (se != cfs_rq->curr)
15650                 __enqueue_entity(cfs_rq, se);
15651 +
15652 +       if (entity_is_task(se))
15653 +               vx_activate_task(task_of(se));
15654  }
15655  
15656  static void __clear_buddies(struct cfs_rq *cfs_rq, struct sched_entity *se)
15657 @@ -825,6 +828,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
15658  
15659         if (se != cfs_rq->curr)
15660                 __dequeue_entity(cfs_rq, se);
15661 +       if (entity_is_task(se))
15662 +               vx_deactivate_task(task_of(se));
15663         account_entity_dequeue(cfs_rq, se);
15664         update_min_vruntime(cfs_rq);
15665  
15666 diff -NurpP --minimal linux-2.6.36/kernel/signal.c linux-2.6.36-vs2.3.0.36.36/kernel/signal.c
15667 --- linux-2.6.36/kernel/signal.c        2010-10-21 13:07:57.000000000 +0200
15668 +++ linux-2.6.36-vs2.3.0.36.36/kernel/signal.c  2010-10-21 13:09:36.000000000 +0200
15669 @@ -28,6 +28,8 @@
15670  #include <linux/freezer.h>
15671  #include <linux/pid_namespace.h>
15672  #include <linux/nsproxy.h>
15673 +#include <linux/vs_context.h>
15674 +#include <linux/vs_pid.h>
15675  #define CREATE_TRACE_POINTS
15676  #include <trace/events/signal.h>
15677  
15678 @@ -646,9 +648,18 @@ static int check_kill_permission(int sig
15679         struct pid *sid;
15680         int error;
15681  
15682 +       vxdprintk(VXD_CBIT(misc, 7),
15683 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
15684 +               sig, info, t, vx_task_xid(t), t->pid);
15685 +
15686         if (!valid_signal(sig))
15687                 return -EINVAL;
15688  
15689 +/*     FIXME: needed? if so, why?
15690 +       if ((info != SEND_SIG_NOINFO) &&
15691 +               (is_si_special(info) || !si_fromuser(info)))
15692 +               goto skip;      */
15693 +
15694         if (!si_fromuser(info))
15695                 return 0;
15696  
15697 @@ -678,6 +689,20 @@ static int check_kill_permission(int sig
15698                 }
15699         }
15700  
15701 +       error = -EPERM;
15702 +       if (t->pid == 1 && current->xid)
15703 +               return error;
15704 +
15705 +       error = -ESRCH;
15706 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
15707 +                 loops, maybe ENOENT or EACCES? */
15708 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
15709 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
15710 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
15711 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
15712 +               return error;
15713 +       }
15714 +/* skip: */
15715         return security_task_kill(t, info, sig, 0);
15716  }
15717  
15718 @@ -1170,7 +1195,7 @@ int kill_pid_info(int sig, struct siginf
15719         rcu_read_lock();
15720  retry:
15721         p = pid_task(pid, PIDTYPE_PID);
15722 -       if (p) {
15723 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
15724                 error = group_send_sig_info(sig, info, p);
15725                 if (unlikely(error == -ESRCH))
15726                         /*
15727 @@ -1210,7 +1235,7 @@ int kill_pid_info_as_uid(int sig, struct
15728  
15729         rcu_read_lock();
15730         p = pid_task(pid, PIDTYPE_PID);
15731 -       if (!p) {
15732 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
15733                 ret = -ESRCH;
15734                 goto out_unlock;
15735         }
15736 @@ -1265,8 +1290,10 @@ static int kill_something_info(int sig, 
15737                 struct task_struct * p;
15738  
15739                 for_each_process(p) {
15740 -                       if (task_pid_vnr(p) > 1 &&
15741 -                                       !same_thread_group(p, current)) {
15742 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
15743 +                               task_pid_vnr(p) > 1 &&
15744 +                               !same_thread_group(p, current) &&
15745 +                               !vx_current_initpid(p->pid)) {
15746                                 int err = group_send_sig_info(sig, info, p);
15747                                 ++count;
15748                                 if (err != -EPERM)
15749 @@ -1933,6 +1960,11 @@ relock:
15750                                 !sig_kernel_only(signr))
15751                         continue;
15752  
15753 +               /* virtual init is protected against user signals */
15754 +               if ((info->si_code == SI_USER) &&
15755 +                       vx_current_initpid(current->pid))
15756 +                       continue;
15757 +
15758                 if (sig_kernel_stop(signr)) {
15759                         /*
15760                          * The default action is to stop all threads in
15761 diff -NurpP --minimal linux-2.6.36/kernel/softirq.c linux-2.6.36-vs2.3.0.36.36/kernel/softirq.c
15762 --- linux-2.6.36/kernel/softirq.c       2010-08-02 16:52:57.000000000 +0200
15763 +++ linux-2.6.36-vs2.3.0.36.36/kernel/softirq.c 2010-10-21 13:09:36.000000000 +0200
15764 @@ -24,6 +24,7 @@
15765  #include <linux/ftrace.h>
15766  #include <linux/smp.h>
15767  #include <linux/tick.h>
15768 +#include <linux/vs_context.h>
15769  
15770  #define CREATE_TRACE_POINTS
15771  #include <trace/events/irq.h>
15772 diff -NurpP --minimal linux-2.6.36/kernel/sys.c linux-2.6.36-vs2.3.0.36.36/kernel/sys.c
15773 --- linux-2.6.36/kernel/sys.c   2010-10-21 13:07:57.000000000 +0200
15774 +++ linux-2.6.36-vs2.3.0.36.36/kernel/sys.c     2010-10-21 13:45:48.000000000 +0200
15775 @@ -42,6 +42,7 @@
15776  #include <linux/syscalls.h>
15777  #include <linux/kprobes.h>
15778  #include <linux/user_namespace.h>
15779 +#include <linux/vs_pid.h>
15780  
15781  #include <asm/uaccess.h>
15782  #include <asm/io.h>
15783 @@ -131,7 +132,10 @@ static int set_one_prio(struct task_stru
15784                 goto out;
15785         }
15786         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
15787 -               error = -EACCES;
15788 +               if (vx_flags(VXF_IGNEG_NICE, 0))
15789 +                       error = 0;
15790 +               else
15791 +                       error = -EACCES;
15792                 goto out;
15793         }
15794         no_nice = security_task_setnice(p, niceval);
15795 @@ -181,6 +185,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
15796                         else
15797                                 pgrp = task_pgrp(current);
15798                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15799 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15800 +                                       continue;
15801                                 error = set_one_prio(p, niceval, error);
15802                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
15803                         break;
15804 @@ -244,6 +250,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
15805                         else
15806                                 pgrp = task_pgrp(current);
15807                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15808 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15809 +                                       continue;
15810                                 niceval = 20 - task_nice(p);
15811                                 if (niceval > retval)
15812                                         retval = niceval;
15813 @@ -357,6 +365,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
15814  
15815  static DEFINE_MUTEX(reboot_mutex);
15816  
15817 +long vs_reboot(unsigned int, void __user *);
15818 +
15819  /*
15820   * Reboot system call: for obvious reasons only root may call it,
15821   * and even root needs to set up some magic numbers in the registers
15822 @@ -389,6 +399,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
15823         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
15824                 cmd = LINUX_REBOOT_CMD_HALT;
15825  
15826 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15827 +               return vs_reboot(cmd, arg);
15828 +
15829         mutex_lock(&reboot_mutex);
15830         switch (cmd) {
15831         case LINUX_REBOOT_CMD_RESTART:
15832 @@ -1169,7 +1182,7 @@ SYSCALL_DEFINE2(sethostname, char __user
15833         int errno;
15834         char tmp[__NEW_UTS_LEN];
15835  
15836 -       if (!capable(CAP_SYS_ADMIN))
15837 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15838                 return -EPERM;
15839         if (len < 0 || len > __NEW_UTS_LEN)
15840                 return -EINVAL;
15841 @@ -1218,7 +1231,7 @@ SYSCALL_DEFINE2(setdomainname, char __us
15842         int errno;
15843         char tmp[__NEW_UTS_LEN];
15844  
15845 -       if (!capable(CAP_SYS_ADMIN))
15846 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15847                 return -EPERM;
15848         if (len < 0 || len > __NEW_UTS_LEN)
15849                 return -EINVAL;
15850 @@ -1334,7 +1347,7 @@ int do_prlimit(struct task_struct *tsk, 
15851         task_lock(tsk->group_leader);
15852         if (new_rlim) {
15853                 if (new_rlim->rlim_max > rlim->rlim_max &&
15854 -                               !capable(CAP_SYS_RESOURCE))
15855 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15856                         retval = -EPERM;
15857                 if (!retval)
15858                         retval = security_task_setrlimit(tsk->group_leader,
15859 @@ -1383,7 +1396,7 @@ static int check_prlimit_permission(stru
15860              cred->gid != tcred->egid ||
15861              cred->gid != tcred->sgid ||
15862              cred->gid != tcred->gid) &&
15863 -            !capable(CAP_SYS_RESOURCE)) {
15864 +            !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT)) {
15865                 return -EPERM;
15866         }
15867  
15868 diff -NurpP --minimal linux-2.6.36/kernel/sysctl_binary.c linux-2.6.36-vs2.3.0.36.36/kernel/sysctl_binary.c
15869 --- linux-2.6.36/kernel/sysctl_binary.c 2010-08-02 16:52:57.000000000 +0200
15870 +++ linux-2.6.36-vs2.3.0.36.36/kernel/sysctl_binary.c   2010-10-21 13:09:36.000000000 +0200
15871 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
15872  
15873         { CTL_INT,      KERN_PANIC,                     "panic" },
15874         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
15875 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
15876  
15877         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
15878         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
15879 diff -NurpP --minimal linux-2.6.36/kernel/sysctl.c linux-2.6.36-vs2.3.0.36.36/kernel/sysctl.c
15880 --- linux-2.6.36/kernel/sysctl.c        2010-10-21 13:07:57.000000000 +0200
15881 +++ linux-2.6.36-vs2.3.0.36.36/kernel/sysctl.c  2010-10-21 13:09:36.000000000 +0200
15882 @@ -73,6 +73,7 @@
15883  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
15884  #include <linux/lockdep.h>
15885  #endif
15886 +extern char vshelper_path[];
15887  #ifdef CONFIG_CHR_DEV_SG
15888  #include <scsi/sg.h>
15889  #endif
15890 @@ -573,6 +574,13 @@ static struct ctl_table kern_table[] = {
15891                 .proc_handler   = proc_dostring,
15892         },
15893  #endif
15894 +       {
15895 +               .procname       = "vshelper",
15896 +               .data           = &vshelper_path,
15897 +               .maxlen         = 256,
15898 +               .mode           = 0644,
15899 +               .proc_handler   = &proc_dostring,
15900 +       },
15901  #ifdef CONFIG_CHR_DEV_SG
15902         {
15903                 .procname       = "sg-big-buff",
15904 diff -NurpP --minimal linux-2.6.36/kernel/time/timekeeping.c linux-2.6.36-vs2.3.0.36.36/kernel/time/timekeeping.c
15905 --- linux-2.6.36/kernel/time/timekeeping.c      2010-10-21 13:07:57.000000000 +0200
15906 +++ linux-2.6.36-vs2.3.0.36.36/kernel/time/timekeeping.c        2010-10-21 14:17:59.000000000 +0200
15907 @@ -229,6 +229,7 @@ void getnstimeofday(struct timespec *ts)
15908         } while (read_seqretry(&xtime_lock, seq));
15909  
15910         timespec_add_ns(ts, nsecs);
15911 +       vx_adjust_timespec(ts);
15912  }
15913  
15914  EXPORT_SYMBOL(getnstimeofday);
15915 diff -NurpP --minimal linux-2.6.36/kernel/time.c linux-2.6.36-vs2.3.0.36.36/kernel/time.c
15916 --- linux-2.6.36/kernel/time.c  2010-10-21 13:07:57.000000000 +0200
15917 +++ linux-2.6.36-vs2.3.0.36.36/kernel/time.c    2010-10-21 14:22:43.000000000 +0200
15918 @@ -92,7 +92,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
15919         if (err)
15920                 return err;
15921  
15922 -       do_settimeofday(&tv);
15923 +       vx_settimeofday(&tv);
15924         return 0;
15925  }
15926  
15927 @@ -177,7 +177,7 @@ int do_sys_settimeofday(struct timespec 
15928                 /* SMP safe, again the code in arch/foo/time.c should
15929                  * globally block out interrupts when it runs.
15930                  */
15931 -               return do_settimeofday(tv);
15932 +               return vx_settimeofday(tv);
15933         }
15934         return 0;
15935  }
15936 diff -NurpP --minimal linux-2.6.36/kernel/timer.c linux-2.6.36-vs2.3.0.36.36/kernel/timer.c
15937 --- linux-2.6.36/kernel/timer.c 2010-10-21 13:07:57.000000000 +0200
15938 +++ linux-2.6.36-vs2.3.0.36.36/kernel/timer.c   2010-10-21 13:09:36.000000000 +0200
15939 @@ -40,6 +40,10 @@
15940  #include <linux/perf_event.h>
15941  #include <linux/sched.h>
15942  #include <linux/slab.h>
15943 +#include <linux/vs_base.h>
15944 +#include <linux/vs_cvirt.h>
15945 +#include <linux/vs_pid.h>
15946 +#include <linux/vserver/sched.h>
15947  
15948  #include <asm/uaccess.h>
15949  #include <asm/unistd.h>
15950 @@ -1332,12 +1336,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
15951  
15952  #endif
15953  
15954 -#ifndef __alpha__
15955 -
15956 -/*
15957 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
15958 - * should be moved into arch/i386 instead?
15959 - */
15960  
15961  /**
15962   * sys_getpid - return the thread group id of the current process
15963 @@ -1366,10 +1364,23 @@ SYSCALL_DEFINE0(getppid)
15964         rcu_read_lock();
15965         pid = task_tgid_vnr(current->real_parent);
15966         rcu_read_unlock();
15967 +       return vx_map_pid(pid);
15968 +}
15969  
15970 -       return pid;
15971 +#ifdef __alpha__
15972 +
15973 +/*
15974 + * The Alpha uses getxpid, getxuid, and getxgid instead.
15975 + */
15976 +
15977 +asmlinkage long do_getxpid(long *ppid)
15978 +{
15979 +       *ppid = sys_getppid();
15980 +       return sys_getpid();
15981  }
15982  
15983 +#else /* _alpha_ */
15984 +
15985  SYSCALL_DEFINE0(getuid)
15986  {
15987         /* Only we change this so SMP safe */
15988 diff -NurpP --minimal linux-2.6.36/kernel/user_namespace.c linux-2.6.36-vs2.3.0.36.36/kernel/user_namespace.c
15989 --- linux-2.6.36/kernel/user_namespace.c        2010-10-21 13:07:57.000000000 +0200
15990 +++ linux-2.6.36-vs2.3.0.36.36/kernel/user_namespace.c  2010-10-21 13:09:36.000000000 +0200
15991 @@ -11,6 +11,7 @@
15992  #include <linux/user_namespace.h>
15993  #include <linux/highuid.h>
15994  #include <linux/cred.h>
15995 +#include <linux/vserver/global.h>
15996  
15997  /*
15998   * Create a new user namespace, deriving the creator from the user in the
15999 @@ -31,6 +32,7 @@ int create_user_ns(struct cred *new)
16000                 return -ENOMEM;
16001  
16002         kref_init(&ns->kref);
16003 +       atomic_inc(&vs_global_user_ns);
16004  
16005         for (n = 0; n < UIDHASH_SZ; ++n)
16006                 INIT_HLIST_HEAD(ns->uidhash_table + n);
16007 @@ -79,6 +81,8 @@ void free_user_ns(struct kref *kref)
16008         struct user_namespace *ns =
16009                 container_of(kref, struct user_namespace, kref);
16010  
16011 +       /* FIXME: maybe move into destroyer? */
16012 +       atomic_dec(&vs_global_user_ns);
16013         INIT_WORK(&ns->destroyer, free_user_ns_work);
16014         schedule_work(&ns->destroyer);
16015  }
16016 diff -NurpP --minimal linux-2.6.36/kernel/utsname.c linux-2.6.36-vs2.3.0.36.36/kernel/utsname.c
16017 --- linux-2.6.36/kernel/utsname.c       2009-09-10 15:26:28.000000000 +0200
16018 +++ linux-2.6.36-vs2.3.0.36.36/kernel/utsname.c 2010-10-21 13:09:36.000000000 +0200
16019 @@ -14,14 +14,17 @@
16020  #include <linux/utsname.h>
16021  #include <linux/err.h>
16022  #include <linux/slab.h>
16023 +#include <linux/vserver/global.h>
16024  
16025  static struct uts_namespace *create_uts_ns(void)
16026  {
16027         struct uts_namespace *uts_ns;
16028  
16029         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
16030 -       if (uts_ns)
16031 +       if (uts_ns) {
16032                 kref_init(&uts_ns->kref);
16033 +               atomic_inc(&vs_global_uts_ns);
16034 +       }
16035         return uts_ns;
16036  }
16037  
16038 @@ -71,5 +74,6 @@ void free_uts_ns(struct kref *kref)
16039         struct uts_namespace *ns;
16040  
16041         ns = container_of(kref, struct uts_namespace, kref);
16042 +       atomic_dec(&vs_global_uts_ns);
16043         kfree(ns);
16044  }
16045 diff -NurpP --minimal linux-2.6.36/kernel/vserver/cacct.c linux-2.6.36-vs2.3.0.36.36/kernel/vserver/cacct.c
16046 --- linux-2.6.36/kernel/vserver/cacct.c 1970-01-01 01:00:00.000000000 +0100
16047 +++ linux-2.6.36-vs2.3.0.36.36/kernel/vserver/cacct.c   2010-10-21 13:09:36.000000000 +0200
16048 @@ -0,0 +1,42 @@
16049 +/*
16050 + *  linux/kernel/vserver/cacct.c
16051 + *
16052 + *  Virtual Server: Context Accounting
16053 + *
16054 + *  Copyright (C) 2006-2007 Herbert Pötzl
16055 + *
16056 + *  V0.01  added accounting stats
16057 + *
16058 + */
16059 +
16060 +#include <linux/types.h>
16061 +#include <linux/vs_context.h>
16062 +#include <linux/vserver/cacct_cmd.h>
16063 +#include <linux/vserver/cacct_int.h>
16064 +
16065 +#include <asm/errno.h>
16066 +#include <asm/uaccess.h>
16067 +
16068 +
16069 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
16070 +{
16071 +       struct vcmd_sock_stat_v0 vc_data;
16072 +       int j, field;
16073 +
16074 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16075 +               return -EFAULT;
16076 +
16077 +       field = vc_data.field;
16078 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
16079 +               return -EINVAL;
16080 +
16081 +       for (j = 0; j < 3; j++) {
16082 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
16083 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
16084 +       }
16085 +
16086 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16087 +               return -EFAULT;
16088 +       return 0;
16089 +}
16090 +
16091 diff -NurpP --minimal linux-2.6.36/kernel/vserver/cacct_init.h linux-2.6.36-vs2.3.0.36.36/kernel/vserver/cacct_init.h
16092 --- linux-2.6.36/kernel/vserver/cacct_init.h    1970-01-01 01:00:00.000000000 +0100
16093 +++ linux-2.6.36-vs2.3.0.36.36/kernel/vserver/cacct_init.h      2010-10-21 13:09:36.000000000 +0200
16094 @@ -0,0 +1,25 @@
16095 +
16096 +
16097 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
16098 +{
16099 +       int i, j;
16100 +
16101 +
16102 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
16103 +               for (j = 0; j < 3; j++) {
16104 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
16105 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
16106 +               }
16107 +       }
16108 +       for (i = 0; i < 8; i++)
16109 +               atomic_set(&cacct->slab[i], 0);
16110 +       for (i = 0; i < 5; i++)
16111 +               for (j = 0; j < 4; j++)
16112 +                       atomic_set(&cacct->page[i][j], 0);
16113 +}
16114 +
16115 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
16116 +{
16117 +       return;
16118 +}
16119 +
16120 diff -NurpP --minimal linux-2.6.36/kernel/vserver/cacct_proc.h linux-2.6.36-vs2.3.0.36.36/kernel/vserver/cacct_proc.h
16121 --- linux-2.6.36/kernel/vserver/cacct_proc.h    1970-01-01 01:00:00.000000000 +0100
16122 +++ linux-2.6.36-vs2.3.0.36.36/kernel/vserver/cacct_proc.h      2010-10-21 13:09:36.000000000 +0200
16123 @@ -0,0 +1,53 @@
16124 +#ifndef _VX_CACCT_PROC_H
16125 +#define _VX_CACCT_PROC_H
16126 +
16127 +#include <linux/vserver/cacct_int.h>
16128 +
16129 +
16130 +#define VX_SOCKA_TOP   \
16131 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
16132 +
16133 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
16134 +{
16135 +       int i, j, length = 0;
16136 +       static char *type[VXA_SOCK_SIZE] = {
16137 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
16138 +       };
16139 +
16140 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
16141 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
16142 +               length += sprintf(buffer + length, "%s:", type[i]);
16143 +               for (j = 0; j < 3; j++) {
16144 +                       length += sprintf(buffer + length,
16145 +                               "\t%10lu/%-10lu",
16146 +                               vx_sock_count(cacct, i, j),
16147 +                               vx_sock_total(cacct, i, j));
16148 +               }
16149 +               buffer[length++] = '\n';
16150 +       }
16151 +
16152 +       length += sprintf(buffer + length, "\n");
16153 +       length += sprintf(buffer + length,
16154 +               "slab:\t %8u %8u %8u %8u\n",
16155 +               atomic_read(&cacct->slab[1]),
16156 +               atomic_read(&cacct->slab[4]),
16157 +               atomic_read(&cacct->slab[0]),
16158 +               atomic_read(&cacct->slab[2]));
16159 +
16160 +       length += sprintf(buffer + length, "\n");
16161 +       for (i = 0; i < 5; i++) {
16162 +               length += sprintf(buffer + length,
16163 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
16164 +                       atomic_read(&cacct->page[i][0]),
16165 +                       atomic_read(&cacct->page[i][1]),
16166 +                       atomic_read(&cacct->page[i][2]),
16167 +                       atomic_read(&cacct->page[i][3]),
16168 +                       atomic_read(&cacct->page[i][4]),
16169 +                       atomic_read(&cacct->page[i][5]),
16170 +                       atomic_read(&cacct->page[i][6]),
16171 +                       atomic_read(&cacct->page[i][7]));
16172 +       }
16173 +       return length;
16174 +}
16175 +
16176 +#endif /* _VX_CACCT_PROC_H */
16177 diff -NurpP --minimal linux-2.6.36/kernel/vserver/context.c linux-2.6.36-vs2.3.0.36.36/kernel/vserver/context.c
16178 --- linux-2.6.36/kernel/vserver/context.c       1970-01-01 01:00:00.000000000 +0100
16179 +++ linux-2.6.36-vs2.3.0.36.36/kernel/vserver/context.c 2010-10-21 14:39:59.000000000 +0200
16180 @@ -0,0 +1,1058 @@
16181 +/*
16182 + *  linux/kernel/vserver/context.c
16183 + *
16184 + *  Virtual Server: Context Support
16185 + *
16186 + *  Copyright (C) 2003-2007  Herbert Pötzl
16187 + *
16188 + *  V0.01  context helper
16189 + *  V0.02  vx_ctx_kill syscall command
16190 + *  V0.03  replaced context_info calls
16191 + *  V0.04  redesign of struct (de)alloc
16192 + *  V0.05  rlimit basic implementation
16193 + *  V0.06  task_xid and info commands
16194 + *  V0.07  context flags and caps
16195 + *  V0.08  switch to RCU based hash
16196 + *  V0.09  revert to non RCU for now
16197 + *  V0.10  and back to working RCU hash
16198 + *  V0.11  and back to locking again
16199 + *  V0.12  referenced context store
16200 + *  V0.13  separate per cpu data
16201 + *  V0.14  changed vcmds to vxi arg
16202 + *  V0.15  added context stat
16203 + *  V0.16  have __create claim() the vxi
16204 + *  V0.17  removed older and legacy stuff
16205 + *
16206 + */
16207 +
16208 +#include <linux/slab.h>
16209 +#include <linux/types.h>
16210 +#include <linux/security.h>
16211 +#include <linux/pid_namespace.h>
16212 +
16213 +#include <linux/vserver/context.h>
16214 +#include <linux/vserver/network.h>
16215 +#include <linux/vserver/debug.h>
16216 +#include <linux/vserver/limit.h>
16217 +#include <linux/vserver/limit_int.h>
16218 +#include <linux/vserver/space.h>
16219 +#include <linux/init_task.h>
16220 +#include <linux/fs_struct.h>
16221 +
16222 +#include <linux/vs_context.h>
16223 +#include <linux/vs_limit.h>
16224 +#include <linux/vs_pid.h>
16225 +#include <linux/vserver/context_cmd.h>
16226 +
16227 +#include "cvirt_init.h"
16228 +#include "cacct_init.h"
16229 +#include "limit_init.h"
16230 +#include "sched_init.h"
16231 +
16232 +
16233 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
16234 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
16235 +
16236 +
16237 +/*     now inactive context structures */
16238 +
16239 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
16240 +
16241 +static spinlock_t vx_info_inactive_lock = SPIN_LOCK_UNLOCKED;
16242 +
16243 +
16244 +/*     __alloc_vx_info()
16245 +
16246 +       * allocate an initialized vx_info struct
16247 +       * doesn't make it visible (hash)                        */
16248 +
16249 +static struct vx_info *__alloc_vx_info(xid_t xid)
16250 +{
16251 +       struct vx_info *new = NULL;
16252 +       int cpu, index;
16253 +
16254 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
16255 +
16256 +       /* would this benefit from a slab cache? */
16257 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
16258 +       if (!new)
16259 +               return 0;
16260 +
16261 +       memset(new, 0, sizeof(struct vx_info));
16262 +#ifdef CONFIG_SMP
16263 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
16264 +       if (!new->ptr_pc)
16265 +               goto error;
16266 +#endif
16267 +       new->vx_id = xid;
16268 +       INIT_HLIST_NODE(&new->vx_hlist);
16269 +       atomic_set(&new->vx_usecnt, 0);
16270 +       atomic_set(&new->vx_tasks, 0);
16271 +       new->vx_parent = NULL;
16272 +       new->vx_state = 0;
16273 +       init_waitqueue_head(&new->vx_wait);
16274 +
16275 +       /* prepare reaper */
16276 +       get_task_struct(init_pid_ns.child_reaper);
16277 +       new->vx_reaper = init_pid_ns.child_reaper;
16278 +       new->vx_badness_bias = 0;
16279 +
16280 +       /* rest of init goes here */
16281 +       vx_info_init_limit(&new->limit);
16282 +       vx_info_init_sched(&new->sched);
16283 +       vx_info_init_cvirt(&new->cvirt);
16284 +       vx_info_init_cacct(&new->cacct);
16285 +
16286 +       /* per cpu data structures */
16287 +       for_each_possible_cpu(cpu) {
16288 +               vx_info_init_sched_pc(
16289 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
16290 +               vx_info_init_cvirt_pc(
16291 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
16292 +       }
16293 +
16294 +       new->vx_flags = VXF_INIT_SET;
16295 +       cap_set_init_eff(new->vx_bcaps);
16296 +       new->vx_ccaps = 0;
16297 +       new->vx_umask = 0;
16298 +
16299 +       new->reboot_cmd = 0;
16300 +       new->exit_code = 0;
16301 +
16302 +       // preconfig fs entries
16303 +       for (index = 0; index < VX_SPACES; index++) {
16304 +               spin_lock(&init_fs.lock);
16305 +               init_fs.users++;
16306 +               spin_unlock(&init_fs.lock);
16307 +               new->vx_fs[index] = &init_fs;
16308 +       }
16309 +
16310 +       vxdprintk(VXD_CBIT(xid, 0),
16311 +               "alloc_vx_info(%d) = %p", xid, new);
16312 +       vxh_alloc_vx_info(new);
16313 +       atomic_inc(&vx_global_ctotal);
16314 +       return new;
16315 +#ifdef CONFIG_SMP
16316 +error:
16317 +       kfree(new);
16318 +       return 0;
16319 +#endif
16320 +}
16321 +
16322 +/*     __dealloc_vx_info()
16323 +
16324 +       * final disposal of vx_info                             */
16325 +
16326 +static void __dealloc_vx_info(struct vx_info *vxi)
16327 +{
16328 +#ifdef CONFIG_VSERVER_WARN
16329 +       struct vx_info_save vxis;
16330 +       int cpu;
16331 +#endif
16332 +       vxdprintk(VXD_CBIT(xid, 0),
16333 +               "dealloc_vx_info(%p)", vxi);
16334 +       vxh_dealloc_vx_info(vxi);
16335 +
16336 +#ifdef CONFIG_VSERVER_WARN
16337 +       enter_vx_info(vxi, &vxis);
16338 +       vx_info_exit_limit(&vxi->limit);
16339 +       vx_info_exit_sched(&vxi->sched);
16340 +       vx_info_exit_cvirt(&vxi->cvirt);
16341 +       vx_info_exit_cacct(&vxi->cacct);
16342 +
16343 +       for_each_possible_cpu(cpu) {
16344 +               vx_info_exit_sched_pc(
16345 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
16346 +               vx_info_exit_cvirt_pc(
16347 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
16348 +       }
16349 +       leave_vx_info(&vxis);
16350 +#endif
16351 +
16352 +       vxi->vx_id = -1;
16353 +       vxi->vx_state |= VXS_RELEASED;
16354 +
16355 +#ifdef CONFIG_SMP
16356 +       free_percpu(vxi->ptr_pc);
16357 +#endif
16358 +       kfree(vxi);
16359 +       atomic_dec(&vx_global_ctotal);
16360 +}
16361 +
16362 +static void __shutdown_vx_info(struct vx_info *vxi)
16363 +{
16364 +       struct nsproxy *nsproxy;
16365 +       struct fs_struct *fs;
16366 +       int index, kill;
16367 +
16368 +       might_sleep();
16369 +
16370 +       vxi->vx_state |= VXS_SHUTDOWN;
16371 +       vs_state_change(vxi, VSC_SHUTDOWN);
16372 +
16373 +       for (index = 0; index < VX_SPACES; index++) {
16374 +               nsproxy = xchg(&vxi->vx_nsproxy[index], NULL);
16375 +               if (nsproxy)
16376 +                       put_nsproxy(nsproxy);
16377 +
16378 +               fs = xchg(&vxi->vx_fs[index], NULL);
16379 +               spin_lock(&fs->lock);
16380 +               kill = !--fs->users;
16381 +               spin_unlock(&fs->lock);
16382 +               if (kill)
16383 +                       free_fs_struct(fs);
16384 +       }
16385 +}
16386 +
16387 +/* exported stuff */
16388 +
16389 +void free_vx_info(struct vx_info *vxi)
16390 +{
16391 +       unsigned long flags;
16392 +       unsigned index;
16393 +
16394 +       /* check for reference counts first */
16395 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
16396 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16397 +
16398 +       /* context must not be hashed */
16399 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16400 +
16401 +       /* context shutdown is mandatory */
16402 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
16403 +
16404 +       /* nsproxy and fs check */
16405 +       for (index = 0; index < VX_SPACES; index++) {
16406 +               BUG_ON(vxi->vx_nsproxy[index]);
16407 +               BUG_ON(vxi->vx_fs[index]);
16408 +       }
16409 +
16410 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16411 +       hlist_del(&vxi->vx_hlist);
16412 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16413 +
16414 +       __dealloc_vx_info(vxi);
16415 +}
16416 +
16417 +
16418 +/*     hash table for vx_info hash */
16419 +
16420 +#define VX_HASH_SIZE   13
16421 +
16422 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
16423 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
16424 +
16425 +static spinlock_t vx_info_hash_lock = SPIN_LOCK_UNLOCKED;
16426 +
16427 +
16428 +static inline unsigned int __hashval(xid_t xid)
16429 +{
16430 +       return (xid % VX_HASH_SIZE);
16431 +}
16432 +
16433 +
16434 +
16435 +/*     __hash_vx_info()
16436 +
16437 +       * add the vxi to the global hash table
16438 +       * requires the hash_lock to be held                     */
16439 +
16440 +static inline void __hash_vx_info(struct vx_info *vxi)
16441 +{
16442 +       struct hlist_head *head;
16443 +
16444 +       vxd_assert_lock(&vx_info_hash_lock);
16445 +       vxdprintk(VXD_CBIT(xid, 4),
16446 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
16447 +       vxh_hash_vx_info(vxi);
16448 +
16449 +       /* context must not be hashed */
16450 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16451 +
16452 +       vxi->vx_state |= VXS_HASHED;
16453 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
16454 +       hlist_add_head(&vxi->vx_hlist, head);
16455 +       atomic_inc(&vx_global_cactive);
16456 +}
16457 +
16458 +/*     __unhash_vx_info()
16459 +
16460 +       * remove the vxi from the global hash table
16461 +       * requires the hash_lock to be held                     */
16462 +
16463 +static inline void __unhash_vx_info(struct vx_info *vxi)
16464 +{
16465 +       unsigned long flags;
16466 +
16467 +       vxd_assert_lock(&vx_info_hash_lock);
16468 +       vxdprintk(VXD_CBIT(xid, 4),
16469 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
16470 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
16471 +       vxh_unhash_vx_info(vxi);
16472 +
16473 +       /* context must be hashed */
16474 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
16475 +       /* but without tasks */
16476 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16477 +
16478 +       vxi->vx_state &= ~VXS_HASHED;
16479 +       hlist_del_init(&vxi->vx_hlist);
16480 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16481 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
16482 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16483 +       atomic_dec(&vx_global_cactive);
16484 +}
16485 +
16486 +
16487 +/*     __lookup_vx_info()
16488 +
16489 +       * requires the hash_lock to be held
16490 +       * doesn't increment the vx_refcnt                       */
16491 +
16492 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
16493 +{
16494 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
16495 +       struct hlist_node *pos;
16496 +       struct vx_info *vxi;
16497 +
16498 +       vxd_assert_lock(&vx_info_hash_lock);
16499 +       hlist_for_each(pos, head) {
16500 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16501 +
16502 +               if (vxi->vx_id == xid)
16503 +                       goto found;
16504 +       }
16505 +       vxi = NULL;
16506 +found:
16507 +       vxdprintk(VXD_CBIT(xid, 0),
16508 +               "__lookup_vx_info(#%u): %p[#%u]",
16509 +               xid, vxi, vxi ? vxi->vx_id : 0);
16510 +       vxh_lookup_vx_info(vxi, xid);
16511 +       return vxi;
16512 +}
16513 +
16514 +
16515 +/*     __create_vx_info()
16516 +
16517 +       * create the requested context
16518 +       * get(), claim() and hash it                            */
16519 +
16520 +static struct vx_info *__create_vx_info(int id)
16521 +{
16522 +       struct vx_info *new, *vxi = NULL;
16523 +
16524 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
16525 +
16526 +       if (!(new = __alloc_vx_info(id)))
16527 +               return ERR_PTR(-ENOMEM);
16528 +
16529 +       /* required to make dynamic xids unique */
16530 +       spin_lock(&vx_info_hash_lock);
16531 +
16532 +       /* static context requested */
16533 +       if ((vxi = __lookup_vx_info(id))) {
16534 +               vxdprintk(VXD_CBIT(xid, 0),
16535 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
16536 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16537 +                       vxi = ERR_PTR(-EBUSY);
16538 +               else
16539 +                       vxi = ERR_PTR(-EEXIST);
16540 +               goto out_unlock;
16541 +       }
16542 +       /* new context */
16543 +       vxdprintk(VXD_CBIT(xid, 0),
16544 +               "create_vx_info(%d) = %p (new)", id, new);
16545 +       claim_vx_info(new, NULL);
16546 +       __hash_vx_info(get_vx_info(new));
16547 +       vxi = new, new = NULL;
16548 +
16549 +out_unlock:
16550 +       spin_unlock(&vx_info_hash_lock);
16551 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
16552 +       if (new)
16553 +               __dealloc_vx_info(new);
16554 +       return vxi;
16555 +}
16556 +
16557 +
16558 +/*     exported stuff                                          */
16559 +
16560 +
16561 +void unhash_vx_info(struct vx_info *vxi)
16562 +{
16563 +       __shutdown_vx_info(vxi);
16564 +       spin_lock(&vx_info_hash_lock);
16565 +       __unhash_vx_info(vxi);
16566 +       spin_unlock(&vx_info_hash_lock);
16567 +       __wakeup_vx_info(vxi);
16568 +}
16569 +
16570 +
16571 +/*     lookup_vx_info()
16572 +
16573 +       * search for a vx_info and get() it
16574 +       * negative id means current                             */
16575 +
16576 +struct vx_info *lookup_vx_info(int id)
16577 +{
16578 +       struct vx_info *vxi = NULL;
16579 +
16580 +       if (id < 0) {
16581 +               vxi = get_vx_info(current_vx_info());
16582 +       } else if (id > 1) {
16583 +               spin_lock(&vx_info_hash_lock);
16584 +               vxi = get_vx_info(__lookup_vx_info(id));
16585 +               spin_unlock(&vx_info_hash_lock);
16586 +       }
16587 +       return vxi;
16588 +}
16589 +
16590 +/*     xid_is_hashed()
16591 +
16592 +       * verify that xid is still hashed                       */
16593 +
16594 +int xid_is_hashed(xid_t xid)
16595 +{
16596 +       int hashed;
16597 +
16598 +       spin_lock(&vx_info_hash_lock);
16599 +       hashed = (__lookup_vx_info(xid) != NULL);
16600 +       spin_unlock(&vx_info_hash_lock);
16601 +       return hashed;
16602 +}
16603 +
16604 +#ifdef CONFIG_PROC_FS
16605 +
16606 +/*     get_xid_list()
16607 +
16608 +       * get a subset of hashed xids for proc
16609 +       * assumes size is at least one                          */
16610 +
16611 +int get_xid_list(int index, unsigned int *xids, int size)
16612 +{
16613 +       int hindex, nr_xids = 0;
16614 +
16615 +       /* only show current and children */
16616 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
16617 +               if (index > 0)
16618 +                       return 0;
16619 +               xids[nr_xids] = vx_current_xid();
16620 +               return 1;
16621 +       }
16622 +
16623 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
16624 +               struct hlist_head *head = &vx_info_hash[hindex];
16625 +               struct hlist_node *pos;
16626 +
16627 +               spin_lock(&vx_info_hash_lock);
16628 +               hlist_for_each(pos, head) {
16629 +                       struct vx_info *vxi;
16630 +
16631 +                       if (--index > 0)
16632 +                               continue;
16633 +
16634 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16635 +                       xids[nr_xids] = vxi->vx_id;
16636 +                       if (++nr_xids >= size) {
16637 +                               spin_unlock(&vx_info_hash_lock);
16638 +                               goto out;
16639 +                       }
16640 +               }
16641 +               /* keep the lock time short */
16642 +               spin_unlock(&vx_info_hash_lock);
16643 +       }
16644 +out:
16645 +       return nr_xids;
16646 +}
16647 +#endif
16648 +
16649 +#ifdef CONFIG_VSERVER_DEBUG
16650 +
16651 +void   dump_vx_info_inactive(int level)
16652 +{
16653 +       struct hlist_node *entry, *next;
16654 +
16655 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
16656 +               struct vx_info *vxi =
16657 +                       list_entry(entry, struct vx_info, vx_hlist);
16658 +
16659 +               dump_vx_info(vxi, level);
16660 +       }
16661 +}
16662 +
16663 +#endif
16664 +
16665 +#if 0
16666 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16667 +{
16668 +       struct user_struct *new_user, *old_user;
16669 +
16670 +       if (!p || !vxi)
16671 +               BUG();
16672 +
16673 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16674 +               return -EACCES;
16675 +
16676 +       new_user = alloc_uid(vxi->vx_id, p->uid);
16677 +       if (!new_user)
16678 +               return -ENOMEM;
16679 +
16680 +       old_user = p->user;
16681 +       if (new_user != old_user) {
16682 +               atomic_inc(&new_user->processes);
16683 +               atomic_dec(&old_user->processes);
16684 +               p->user = new_user;
16685 +       }
16686 +       free_uid(old_user);
16687 +       return 0;
16688 +}
16689 +#endif
16690 +
16691 +#if 0
16692 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16693 +{
16694 +       // p->cap_effective &= vxi->vx_cap_bset;
16695 +       p->cap_effective =
16696 +               cap_intersect(p->cap_effective, vxi->cap_bset);
16697 +       // p->cap_inheritable &= vxi->vx_cap_bset;
16698 +       p->cap_inheritable =
16699 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
16700 +       // p->cap_permitted &= vxi->vx_cap_bset;
16701 +       p->cap_permitted =
16702 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
16703 +}
16704 +#endif
16705 +
16706 +
16707 +#include <linux/file.h>
16708 +#include <linux/fdtable.h>
16709 +
16710 +static int vx_openfd_task(struct task_struct *tsk)
16711 +{
16712 +       struct files_struct *files = tsk->files;
16713 +       struct fdtable *fdt;
16714 +       const unsigned long *bptr;
16715 +       int count, total;
16716 +
16717 +       /* no rcu_read_lock() because of spin_lock() */
16718 +       spin_lock(&files->file_lock);
16719 +       fdt = files_fdtable(files);
16720 +       bptr = fdt->open_fds->fds_bits;
16721 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
16722 +       for (total = 0; count > 0; count--) {
16723 +               if (*bptr)
16724 +                       total += hweight_long(*bptr);
16725 +               bptr++;
16726 +       }
16727 +       spin_unlock(&files->file_lock);
16728 +       return total;
16729 +}
16730 +
16731 +
16732 +/*     for *space compatibility */
16733 +
16734 +asmlinkage long sys_unshare(unsigned long);
16735 +
16736 +/*
16737 + *     migrate task to new context
16738 + *     gets vxi, puts old_vxi on change
16739 + *     optionally unshares namespaces (hack)
16740 + */
16741 +
16742 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
16743 +{
16744 +       struct vx_info *old_vxi;
16745 +       int ret = 0;
16746 +
16747 +       if (!p || !vxi)
16748 +               BUG();
16749 +
16750 +       vxdprintk(VXD_CBIT(xid, 5),
16751 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
16752 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
16753 +
16754 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
16755 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16756 +               return -EACCES;
16757 +
16758 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
16759 +               return -EFAULT;
16760 +
16761 +       old_vxi = task_get_vx_info(p);
16762 +       if (old_vxi == vxi)
16763 +               goto out;
16764 +
16765 +//     if (!(ret = vx_migrate_user(p, vxi))) {
16766 +       {
16767 +               int openfd;
16768 +
16769 +               task_lock(p);
16770 +               openfd = vx_openfd_task(p);
16771 +
16772 +               if (old_vxi) {
16773 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
16774 +                       atomic_dec(&old_vxi->cvirt.nr_running);
16775 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
16776 +                       /* FIXME: what about the struct files here? */
16777 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
16778 +                       /* account for the executable */
16779 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
16780 +               }
16781 +               atomic_inc(&vxi->cvirt.nr_threads);
16782 +               atomic_inc(&vxi->cvirt.nr_running);
16783 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
16784 +               /* FIXME: what about the struct files here? */
16785 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
16786 +               /* account for the executable */
16787 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
16788 +
16789 +               if (old_vxi) {
16790 +                       release_vx_info(old_vxi, p);
16791 +                       clr_vx_info(&p->vx_info);
16792 +               }
16793 +               claim_vx_info(vxi, p);
16794 +               set_vx_info(&p->vx_info, vxi);
16795 +               p->xid = vxi->vx_id;
16796 +
16797 +               vxdprintk(VXD_CBIT(xid, 5),
16798 +                       "moved task %p into vxi:%p[#%d]",
16799 +                       p, vxi, vxi->vx_id);
16800 +
16801 +               // vx_mask_cap_bset(vxi, p);
16802 +               task_unlock(p);
16803 +
16804 +               /* hack for *spaces to provide compatibility */
16805 +               if (unshare) {
16806 +                       struct nsproxy *old_nsp, *new_nsp;
16807 +
16808 +                       ret = unshare_nsproxy_namespaces(
16809 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
16810 +                               &new_nsp, NULL);
16811 +                       if (ret)
16812 +                               goto out;
16813 +
16814 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
16815 +                       vx_set_space(vxi,
16816 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
16817 +                       put_nsproxy(old_nsp);
16818 +               }
16819 +       }
16820 +out:
16821 +       put_vx_info(old_vxi);
16822 +       return ret;
16823 +}
16824 +
16825 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
16826 +{
16827 +       struct task_struct *old_reaper;
16828 +
16829 +       if (!vxi)
16830 +               return -EINVAL;
16831 +
16832 +       vxdprintk(VXD_CBIT(xid, 6),
16833 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
16834 +               vxi, vxi->vx_id, p, p->xid, p->pid);
16835 +
16836 +       old_reaper = vxi->vx_reaper;
16837 +       if (old_reaper == p)
16838 +               return 0;
16839 +
16840 +       /* set new child reaper */
16841 +       get_task_struct(p);
16842 +       vxi->vx_reaper = p;
16843 +       put_task_struct(old_reaper);
16844 +       return 0;
16845 +}
16846 +
16847 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
16848 +{
16849 +       if (!vxi)
16850 +               return -EINVAL;
16851 +
16852 +       vxdprintk(VXD_CBIT(xid, 6),
16853 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
16854 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16855 +
16856 +       vxi->vx_flags &= ~VXF_STATE_INIT;
16857 +       // vxi->vx_initpid = p->tgid;
16858 +       vxi->vx_initpid = p->pid;
16859 +       return 0;
16860 +}
16861 +
16862 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
16863 +{
16864 +       vxdprintk(VXD_CBIT(xid, 6),
16865 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
16866 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16867 +
16868 +       vxi->exit_code = code;
16869 +       vxi->vx_initpid = 0;
16870 +}
16871 +
16872 +
16873 +void vx_set_persistent(struct vx_info *vxi)
16874 +{
16875 +       vxdprintk(VXD_CBIT(xid, 6),
16876 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
16877 +
16878 +       get_vx_info(vxi);
16879 +       claim_vx_info(vxi, NULL);
16880 +}
16881 +
16882 +void vx_clear_persistent(struct vx_info *vxi)
16883 +{
16884 +       vxdprintk(VXD_CBIT(xid, 6),
16885 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
16886 +
16887 +       release_vx_info(vxi, NULL);
16888 +       put_vx_info(vxi);
16889 +}
16890 +
16891 +void vx_update_persistent(struct vx_info *vxi)
16892 +{
16893 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
16894 +               vx_set_persistent(vxi);
16895 +       else
16896 +               vx_clear_persistent(vxi);
16897 +}
16898 +
16899 +
16900 +/*     task must be current or locked          */
16901 +
16902 +void   exit_vx_info(struct task_struct *p, int code)
16903 +{
16904 +       struct vx_info *vxi = p->vx_info;
16905 +
16906 +       if (vxi) {
16907 +               atomic_dec(&vxi->cvirt.nr_threads);
16908 +               vx_nproc_dec(p);
16909 +
16910 +               vxi->exit_code = code;
16911 +               release_vx_info(vxi, p);
16912 +       }
16913 +}
16914 +
16915 +void   exit_vx_info_early(struct task_struct *p, int code)
16916 +{
16917 +       struct vx_info *vxi = p->vx_info;
16918 +
16919 +       if (vxi) {
16920 +               if (vxi->vx_initpid == p->pid)
16921 +                       vx_exit_init(vxi, p, code);
16922 +               if (vxi->vx_reaper == p)
16923 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
16924 +       }
16925 +}
16926 +
16927 +
16928 +/* vserver syscall commands below here */
16929 +
16930 +/* taks xid and vx_info functions */
16931 +
16932 +#include <asm/uaccess.h>
16933 +
16934 +
16935 +int vc_task_xid(uint32_t id)
16936 +{
16937 +       xid_t xid;
16938 +
16939 +       if (id) {
16940 +               struct task_struct *tsk;
16941 +
16942 +               read_lock(&tasklist_lock);
16943 +               tsk = find_task_by_real_pid(id);
16944 +               xid = (tsk) ? tsk->xid : -ESRCH;
16945 +               read_unlock(&tasklist_lock);
16946 +       } else
16947 +               xid = vx_current_xid();
16948 +       return xid;
16949 +}
16950 +
16951 +
16952 +int vc_vx_info(struct vx_info *vxi, void __user *data)
16953 +{
16954 +       struct vcmd_vx_info_v0 vc_data;
16955 +
16956 +       vc_data.xid = vxi->vx_id;
16957 +       vc_data.initpid = vxi->vx_initpid;
16958 +
16959 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16960 +               return -EFAULT;
16961 +       return 0;
16962 +}
16963 +
16964 +
16965 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
16966 +{
16967 +       struct vcmd_ctx_stat_v0 vc_data;
16968 +
16969 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
16970 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
16971 +
16972 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16973 +               return -EFAULT;
16974 +       return 0;
16975 +}
16976 +
16977 +
16978 +/* context functions */
16979 +
16980 +int vc_ctx_create(uint32_t xid, void __user *data)
16981 +{
16982 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
16983 +       struct vx_info *new_vxi;
16984 +       int ret;
16985 +
16986 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16987 +               return -EFAULT;
16988 +
16989 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
16990 +               return -EINVAL;
16991 +
16992 +       new_vxi = __create_vx_info(xid);
16993 +       if (IS_ERR(new_vxi))
16994 +               return PTR_ERR(new_vxi);
16995 +
16996 +       /* initial flags */
16997 +       new_vxi->vx_flags = vc_data.flagword;
16998 +
16999 +       ret = -ENOEXEC;
17000 +       if (vs_state_change(new_vxi, VSC_STARTUP))
17001 +               goto out;
17002 +
17003 +       ret = vx_migrate_task(current, new_vxi, (!data));
17004 +       if (ret)
17005 +               goto out;
17006 +
17007 +       /* return context id on success */
17008 +       ret = new_vxi->vx_id;
17009 +
17010 +       /* get a reference for persistent contexts */
17011 +       if ((vc_data.flagword & VXF_PERSISTENT))
17012 +               vx_set_persistent(new_vxi);
17013 +out:
17014 +       release_vx_info(new_vxi, NULL);
17015 +       put_vx_info(new_vxi);
17016 +       return ret;
17017 +}
17018 +
17019 +
17020 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
17021 +{
17022 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
17023 +       int ret;
17024 +
17025 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
17026 +               return -EFAULT;
17027 +
17028 +       ret = vx_migrate_task(current, vxi, 0);
17029 +       if (ret)
17030 +               return ret;
17031 +       if (vc_data.flagword & VXM_SET_INIT)
17032 +               ret = vx_set_init(vxi, current);
17033 +       if (ret)
17034 +               return ret;
17035 +       if (vc_data.flagword & VXM_SET_REAPER)
17036 +               ret = vx_set_reaper(vxi, current);
17037 +       return ret;
17038 +}
17039 +
17040 +
17041 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
17042 +{
17043 +       struct vcmd_ctx_flags_v0 vc_data;
17044 +
17045 +       vc_data.flagword = vxi->vx_flags;
17046 +
17047 +       /* special STATE flag handling */
17048 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
17049 +
17050 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17051 +               return -EFAULT;
17052 +       return 0;
17053 +}
17054 +
17055 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
17056 +{
17057 +       struct vcmd_ctx_flags_v0 vc_data;
17058 +       uint64_t mask, trigger;
17059 +
17060 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17061 +               return -EFAULT;
17062 +
17063 +       /* special STATE flag handling */
17064 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
17065 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
17066 +
17067 +       if (vxi == current_vx_info()) {
17068 +               /* if (trigger & VXF_STATE_SETUP)
17069 +                       vx_mask_cap_bset(vxi, current); */
17070 +               if (trigger & VXF_STATE_INIT) {
17071 +                       int ret;
17072 +
17073 +                       ret = vx_set_init(vxi, current);
17074 +                       if (ret)
17075 +                               return ret;
17076 +                       ret = vx_set_reaper(vxi, current);
17077 +                       if (ret)
17078 +                               return ret;
17079 +               }
17080 +       }
17081 +
17082 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
17083 +               vc_data.flagword, mask);
17084 +       if (trigger & VXF_PERSISTENT)
17085 +               vx_update_persistent(vxi);
17086 +
17087 +       return 0;
17088 +}
17089 +
17090 +
17091 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
17092 +{
17093 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
17094 +
17095 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
17096 +       return v;
17097 +}
17098 +
17099 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
17100 +{
17101 +       kernel_cap_t c = __cap_empty_set;
17102 +
17103 +       c.cap[0] = v & 0xFFFFFFFF;
17104 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
17105 +
17106 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
17107 +       return c;
17108 +}
17109 +
17110 +
17111 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
17112 +{
17113 +       if (bcaps)
17114 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
17115 +       if (ccaps)
17116 +               *ccaps = vxi->vx_ccaps;
17117 +
17118 +       return 0;
17119 +}
17120 +
17121 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
17122 +{
17123 +       struct vcmd_ctx_caps_v1 vc_data;
17124 +       int ret;
17125 +
17126 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
17127 +       if (ret)
17128 +               return ret;
17129 +       vc_data.cmask = ~0ULL;
17130 +
17131 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17132 +               return -EFAULT;
17133 +       return 0;
17134 +}
17135 +
17136 +static int do_set_caps(struct vx_info *vxi,
17137 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
17138 +{
17139 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
17140 +
17141 +#if 0
17142 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
17143 +               bcaps, bmask, ccaps, cmask);
17144 +#endif
17145 +       vxi->vx_bcaps = cap_t_from_caps(
17146 +               vs_mask_flags(bcold, bcaps, bmask));
17147 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
17148 +
17149 +       return 0;
17150 +}
17151 +
17152 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
17153 +{
17154 +       struct vcmd_ctx_caps_v1 vc_data;
17155 +
17156 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17157 +               return -EFAULT;
17158 +
17159 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
17160 +}
17161 +
17162 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
17163 +{
17164 +       struct vcmd_bcaps vc_data;
17165 +       int ret;
17166 +
17167 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
17168 +       if (ret)
17169 +               return ret;
17170 +       vc_data.bmask = ~0ULL;
17171 +
17172 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17173 +               return -EFAULT;
17174 +       return 0;
17175 +}
17176 +
17177 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
17178 +{
17179 +       struct vcmd_bcaps vc_data;
17180 +
17181 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17182 +               return -EFAULT;
17183 +
17184 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
17185 +}
17186 +
17187 +
17188 +int vc_get_umask(struct vx_info *vxi, void __user *data)
17189 +{
17190 +       struct vcmd_umask vc_data;
17191 +
17192 +       vc_data.umask = vxi->vx_umask;
17193 +       vc_data.mask = ~0ULL;
17194 +
17195 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17196 +               return -EFAULT;
17197 +       return 0;
17198 +}
17199 +
17200 +int vc_set_umask(struct vx_info *vxi, void __user *data)
17201 +{
17202 +       struct vcmd_umask vc_data;
17203 +
17204 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17205 +               return -EFAULT;
17206 +
17207 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
17208 +               vc_data.umask, vc_data.mask);
17209 +       return 0;
17210 +}
17211 +
17212 +
17213 +int vc_get_badness(struct vx_info *vxi, void __user *data)
17214 +{
17215 +       struct vcmd_badness_v0 vc_data;
17216 +
17217 +       vc_data.bias = vxi->vx_badness_bias;
17218 +
17219 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17220 +               return -EFAULT;
17221 +       return 0;
17222 +}
17223 +
17224 +int vc_set_badness(struct vx_info *vxi, void __user *data)
17225 +{
17226 +       struct vcmd_badness_v0 vc_data;
17227 +
17228 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17229 +               return -EFAULT;
17230 +
17231 +       vxi->vx_badness_bias = vc_data.bias;
17232 +       return 0;
17233 +}
17234 +
17235 +#include <linux/module.h>
17236 +
17237 +EXPORT_SYMBOL_GPL(free_vx_info);
17238 +
17239 diff -NurpP --minimal linux-2.6.36/kernel/vserver/cvirt.c linux-2.6.36-vs2.3.0.36.36/kernel/vserver/cvirt.c
17240 --- linux-2.6.36/kernel/vserver/cvirt.c 1970-01-01 01:00:00.000000000 +0100
17241 +++ linux-2.6.36-vs2.3.0.36.36/kernel/vserver/cvirt.c   2010-10-21 14:47:08.000000000 +0200
17242 @@ -0,0 +1,303 @@
17243 +/*
17244 + *  linux/kernel/vserver/cvirt.c
17245 + *
17246 + *  Virtual Server: Context Virtualization
17247 + *
17248 + *  Copyright (C) 2004-2007  Herbert Pötzl
17249 + *
17250 + *  V0.01  broken out from limit.c
17251 + *  V0.02  added utsname stuff
17252 + *  V0.03  changed vcmds to vxi arg
17253 + *
17254 + */
17255 +
17256 +#include <linux/types.h>
17257 +#include <linux/utsname.h>
17258 +#include <linux/vs_cvirt.h>
17259 +#include <linux/vserver/switch.h>
17260 +#include <linux/vserver/cvirt_cmd.h>
17261 +
17262 +#include <asm/uaccess.h>
17263 +
17264 +
17265 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
17266 +{
17267 +       struct vx_info *vxi = current_vx_info();
17268 +
17269 +       set_normalized_timespec(uptime,
17270 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
17271 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
17272 +       if (!idle)
17273 +               return;
17274 +       set_normalized_timespec(idle,
17275 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
17276 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
17277 +       return;
17278 +}
17279 +
17280 +uint64_t vx_idle_jiffies(void)
17281 +{
17282 +       return init_task.utime + init_task.stime;
17283 +}
17284 +
17285 +
17286 +
17287 +static inline uint32_t __update_loadavg(uint32_t load,
17288 +       int wsize, int delta, int n)
17289 +{
17290 +       unsigned long long calc, prev;
17291 +
17292 +       /* just set it to n */
17293 +       if (unlikely(delta >= wsize))
17294 +               return (n << FSHIFT);
17295 +
17296 +       calc = delta * n;
17297 +       calc <<= FSHIFT;
17298 +       prev = (wsize - delta);
17299 +       prev *= load;
17300 +       calc += prev;
17301 +       do_div(calc, wsize);
17302 +       return calc;
17303 +}
17304 +
17305 +
17306 +void vx_update_load(struct vx_info *vxi)
17307 +{
17308 +       uint32_t now, last, delta;
17309 +       unsigned int nr_running, nr_uninterruptible;
17310 +       unsigned int total;
17311 +       unsigned long flags;
17312 +
17313 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
17314 +
17315 +       now = jiffies;
17316 +       last = vxi->cvirt.load_last;
17317 +       delta = now - last;
17318 +
17319 +       if (delta < 5*HZ)
17320 +               goto out;
17321 +
17322 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
17323 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
17324 +       total = nr_running + nr_uninterruptible;
17325 +
17326 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
17327 +               60*HZ, delta, total);
17328 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
17329 +               5*60*HZ, delta, total);
17330 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
17331 +               15*60*HZ, delta, total);
17332 +
17333 +       vxi->cvirt.load_last = now;
17334 +out:
17335 +       atomic_inc(&vxi->cvirt.load_updates);
17336 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
17337 +}
17338 +
17339 +
17340 +/*
17341 + * Commands to do_syslog:
17342 + *
17343 + *      0 -- Close the log.  Currently a NOP.
17344 + *      1 -- Open the log. Currently a NOP.
17345 + *      2 -- Read from the log.
17346 + *      3 -- Read all messages remaining in the ring buffer.
17347 + *      4 -- Read and clear all messages remaining in the ring buffer
17348 + *      5 -- Clear ring buffer.
17349 + *      6 -- Disable printk's to console
17350 + *      7 -- Enable printk's to console
17351 + *      8 -- Set level of messages printed to console
17352 + *      9 -- Return number of unread characters in the log buffer
17353 + *     10 -- Return size of the log buffer
17354 + */
17355 +int vx_do_syslog(int type, char __user *buf, int len)
17356 +{
17357 +       int error = 0;
17358 +       int do_clear = 0;
17359 +       struct vx_info *vxi = current_vx_info();
17360 +       struct _vx_syslog *log;
17361 +
17362 +       if (!vxi)
17363 +               return -EINVAL;
17364 +       log = &vxi->cvirt.syslog;
17365 +
17366 +       switch (type) {
17367 +       case 0:         /* Close log */
17368 +       case 1:         /* Open log */
17369 +               break;
17370 +       case 2:         /* Read from log */
17371 +               error = wait_event_interruptible(log->log_wait,
17372 +                       (log->log_start - log->log_end));
17373 +               if (error)
17374 +                       break;
17375 +               spin_lock_irq(&log->logbuf_lock);
17376 +               spin_unlock_irq(&log->logbuf_lock);
17377 +               break;
17378 +       case 4:         /* Read/clear last kernel messages */
17379 +               do_clear = 1;
17380 +               /* fall through */
17381 +       case 3:         /* Read last kernel messages */
17382 +               return 0;
17383 +
17384 +       case 5:         /* Clear ring buffer */
17385 +               return 0;
17386 +
17387 +       case 6:         /* Disable logging to console */
17388 +       case 7:         /* Enable logging to console */
17389 +       case 8:         /* Set level of messages printed to console */
17390 +               break;
17391 +
17392 +       case 9:         /* Number of chars in the log buffer */
17393 +               return 0;
17394 +       case 10:        /* Size of the log buffer */
17395 +               return 0;
17396 +       default:
17397 +               error = -EINVAL;
17398 +               break;
17399 +       }
17400 +       return error;
17401 +}
17402 +
17403 +
17404 +/* virtual host info names */
17405 +
17406 +static char *vx_vhi_name(struct vx_info *vxi, int id)
17407 +{
17408 +       struct nsproxy *nsproxy;
17409 +       struct uts_namespace *uts;
17410 +
17411 +       if (id == VHIN_CONTEXT)
17412 +               return vxi->vx_name;
17413 +
17414 +       nsproxy = vxi->vx_nsproxy[0];
17415 +       if (!nsproxy)
17416 +               return NULL;
17417 +
17418 +       uts = nsproxy->uts_ns;
17419 +       if (!uts)
17420 +               return NULL;
17421 +
17422 +       switch (id) {
17423 +       case VHIN_SYSNAME:
17424 +               return uts->name.sysname;
17425 +       case VHIN_NODENAME:
17426 +               return uts->name.nodename;
17427 +       case VHIN_RELEASE:
17428 +               return uts->name.release;
17429 +       case VHIN_VERSION:
17430 +               return uts->name.version;
17431 +       case VHIN_MACHINE:
17432 +               return uts->name.machine;
17433 +       case VHIN_DOMAINNAME:
17434 +               return uts->name.domainname;
17435 +       default:
17436 +               return NULL;
17437 +       }
17438 +       return NULL;
17439 +}
17440 +
17441 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
17442 +{
17443 +       struct vcmd_vhi_name_v0 vc_data;
17444 +       char *name;
17445 +
17446 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17447 +               return -EFAULT;
17448 +
17449 +       name = vx_vhi_name(vxi, vc_data.field);
17450 +       if (!name)
17451 +               return -EINVAL;
17452 +
17453 +       memcpy(name, vc_data.name, 65);
17454 +       return 0;
17455 +}
17456 +
17457 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
17458 +{
17459 +       struct vcmd_vhi_name_v0 vc_data;
17460 +       char *name;
17461 +
17462 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17463 +               return -EFAULT;
17464 +
17465 +       name = vx_vhi_name(vxi, vc_data.field);
17466 +       if (!name)
17467 +               return -EINVAL;
17468 +
17469 +       memcpy(vc_data.name, name, 65);
17470 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17471 +               return -EFAULT;
17472 +       return 0;
17473 +}
17474 +
17475 +
17476 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
17477 +{
17478 +       struct vcmd_virt_stat_v0 vc_data;
17479 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
17480 +       struct timespec uptime;
17481 +
17482 +       do_posix_clock_monotonic_gettime(&uptime);
17483 +       set_normalized_timespec(&uptime,
17484 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
17485 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
17486 +
17487 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
17488 +       vc_data.uptime = timespec_to_ns(&uptime);
17489 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
17490 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
17491 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
17492 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
17493 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
17494 +       vc_data.load[0] = cvirt->load[0];
17495 +       vc_data.load[1] = cvirt->load[1];
17496 +       vc_data.load[2] = cvirt->load[2];
17497 +
17498 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17499 +               return -EFAULT;
17500 +       return 0;
17501 +}
17502 +
17503 +
17504 +#ifdef CONFIG_VSERVER_VTIME
17505 +
17506 +/* virtualized time base */
17507 +
17508 +void vx_adjust_timespec(struct timespec *ts)
17509 +{
17510 +       struct vx_info *vxi;
17511 +
17512 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17513 +               return;
17514 +
17515 +       vxi = current_vx_info();
17516 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
17517 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
17518 +
17519 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
17520 +               ts->tv_sec++;
17521 +               ts->tv_nsec -= NSEC_PER_SEC;
17522 +       } else if (ts->tv_nsec < 0) {
17523 +               ts->tv_sec--;
17524 +               ts->tv_nsec += NSEC_PER_SEC;
17525 +       }
17526 +}
17527 +
17528 +int vx_settimeofday(struct timespec *ts)
17529 +{
17530 +       struct timespec ats, delta;
17531 +       struct vx_info *vxi;
17532 +
17533 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17534 +               return do_settimeofday(ts);
17535 +
17536 +       getnstimeofday(&ats);
17537 +       delta = timespec_sub(ts, &ats);
17538 +
17539 +       vxi = current_vx_info();
17540 +       vxi->cvirt.bias_ts = timespec_add(&vxi->cvirt.bias_ts, &delta);
17541 +       return 0;
17542 +}
17543 +
17544 +#endif
17545 +
17546 diff -NurpP --minimal linux-2.6.36/kernel/vserver/cvirt_init.h linux-2.6.36-vs2.3.0.36.36/kernel/vserver/cvirt_init.h
17547 --- linux-2.6.36/kernel/vserver/cvirt_init.h    1970-01-01 01:00:00.000000000 +0100
17548 +++ linux-2.6.36-vs2.3.0.36.36/kernel/vserver/cvirt_init.h      2010-10-21 14:40:17.000000000 +0200
17549 @@ -0,0 +1,69 @@
17550 +
17551 +
17552 +extern uint64_t vx_idle_jiffies(void);
17553 +
17554 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
17555 +{
17556 +       uint64_t idle_jiffies = vx_idle_jiffies();
17557 +       uint64_t nsuptime;
17558 +
17559 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
17560 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
17561 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
17562 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
17563 +       cvirt->bias_ts.tv_sec = 0;
17564 +       cvirt->bias_ts.tv_nsec = 0;
17565 +
17566 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
17567 +       atomic_set(&cvirt->nr_threads, 0);
17568 +       atomic_set(&cvirt->nr_running, 0);
17569 +       atomic_set(&cvirt->nr_uninterruptible, 0);
17570 +       atomic_set(&cvirt->nr_onhold, 0);
17571 +
17572 +       spin_lock_init(&cvirt->load_lock);
17573 +       cvirt->load_last = jiffies;
17574 +       atomic_set(&cvirt->load_updates, 0);
17575 +       cvirt->load[0] = 0;
17576 +       cvirt->load[1] = 0;
17577 +       cvirt->load[2] = 0;
17578 +       atomic_set(&cvirt->total_forks, 0);
17579 +
17580 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
17581 +       init_waitqueue_head(&cvirt->syslog.log_wait);
17582 +       cvirt->syslog.log_start = 0;
17583 +       cvirt->syslog.log_end = 0;
17584 +       cvirt->syslog.con_start = 0;
17585 +       cvirt->syslog.logged_chars = 0;
17586 +}
17587 +
17588 +static inline
17589 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17590 +{
17591 +       // cvirt_pc->cpustat = { 0 };
17592 +}
17593 +
17594 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
17595 +{
17596 +       int value;
17597 +
17598 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
17599 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
17600 +               cvirt, value);
17601 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
17602 +               "!!! cvirt: %p[nr_running] = %d on exit.",
17603 +               cvirt, value);
17604 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
17605 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
17606 +               cvirt, value);
17607 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
17608 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
17609 +               cvirt, value);
17610 +       return;
17611 +}
17612 +
17613 +static inline
17614 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17615 +{
17616 +       return;
17617 +}
17618 +
17619 diff -NurpP --minimal linux-2.6.36/kernel/vserver/cvirt_proc.h linux-2.6.36-vs2.3.0.36.36/kernel/vserver/cvirt_proc.h
17620 --- linux-2.6.36/kernel/vserver/cvirt_proc.h    1970-01-01 01:00:00.000000000 +0100
17621 +++ linux-2.6.36-vs2.3.0.36.36/kernel/vserver/cvirt_proc.h      2010-10-21 13:09:36.000000000 +0200
17622 @@ -0,0 +1,135 @@
17623 +#ifndef _VX_CVIRT_PROC_H
17624 +#define _VX_CVIRT_PROC_H
17625 +
17626 +#include <linux/nsproxy.h>
17627 +#include <linux/mnt_namespace.h>
17628 +#include <linux/ipc_namespace.h>
17629 +#include <linux/utsname.h>
17630 +#include <linux/ipc.h>
17631 +
17632 +
17633 +static inline
17634 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17635 +{
17636 +       struct mnt_namespace *ns;
17637 +       struct uts_namespace *uts;
17638 +       struct ipc_namespace *ipc;
17639 +       struct path path;
17640 +       char *pstr, *root;
17641 +       int length = 0;
17642 +
17643 +       if (!nsproxy)
17644 +               goto out;
17645 +
17646 +       length += sprintf(buffer + length,
17647 +               "NSProxy:\t%p [%p,%p,%p]\n",
17648 +               nsproxy, nsproxy->mnt_ns,
17649 +               nsproxy->uts_ns, nsproxy->ipc_ns);
17650 +
17651 +       ns = nsproxy->mnt_ns;
17652 +       if (!ns)
17653 +               goto skip_ns;
17654 +
17655 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
17656 +       if (!pstr)
17657 +               goto skip_ns;
17658 +
17659 +       path.mnt = ns->root;
17660 +       path.dentry = ns->root->mnt_root;
17661 +       root = d_path(&path, pstr, PATH_MAX - 2);
17662 +       length += sprintf(buffer + length,
17663 +               "Namespace:\t%p [#%u]\n"
17664 +               "RootPath:\t%s\n",
17665 +               ns, atomic_read(&ns->count),
17666 +               root);
17667 +       kfree(pstr);
17668 +skip_ns:
17669 +
17670 +       uts = nsproxy->uts_ns;
17671 +       if (!uts)
17672 +               goto skip_uts;
17673 +
17674 +       length += sprintf(buffer + length,
17675 +               "SysName:\t%.*s\n"
17676 +               "NodeName:\t%.*s\n"
17677 +               "Release:\t%.*s\n"
17678 +               "Version:\t%.*s\n"
17679 +               "Machine:\t%.*s\n"
17680 +               "DomainName:\t%.*s\n",
17681 +               __NEW_UTS_LEN, uts->name.sysname,
17682 +               __NEW_UTS_LEN, uts->name.nodename,
17683 +               __NEW_UTS_LEN, uts->name.release,
17684 +               __NEW_UTS_LEN, uts->name.version,
17685 +               __NEW_UTS_LEN, uts->name.machine,
17686 +               __NEW_UTS_LEN, uts->name.domainname);
17687 +skip_uts:
17688 +
17689 +       ipc = nsproxy->ipc_ns;
17690 +       if (!ipc)
17691 +               goto skip_ipc;
17692 +
17693 +       length += sprintf(buffer + length,
17694 +               "SEMS:\t\t%d %d %d %d  %d\n"
17695 +               "MSG:\t\t%d %d %d\n"
17696 +               "SHM:\t\t%lu %lu  %d %d\n",
17697 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
17698 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
17699 +               ipc->used_sems,
17700 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17701 +               (unsigned long)ipc->shm_ctlmax,
17702 +               (unsigned long)ipc->shm_ctlall,
17703 +               ipc->shm_ctlmni, ipc->shm_tot);
17704 +skip_ipc:
17705 +out:
17706 +       return length;
17707 +}
17708 +
17709 +
17710 +#include <linux/sched.h>
17711 +
17712 +#define LOAD_INT(x) ((x) >> FSHIFT)
17713 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
17714 +
17715 +static inline
17716 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
17717 +{
17718 +       int length = 0;
17719 +       int a, b, c;
17720 +
17721 +       length += sprintf(buffer + length,
17722 +               "BiasUptime:\t%lu.%02lu\n",
17723 +               (unsigned long)cvirt->bias_uptime.tv_sec,
17724 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
17725 +
17726 +       a = cvirt->load[0] + (FIXED_1 / 200);
17727 +       b = cvirt->load[1] + (FIXED_1 / 200);
17728 +       c = cvirt->load[2] + (FIXED_1 / 200);
17729 +       length += sprintf(buffer + length,
17730 +               "nr_threads:\t%d\n"
17731 +               "nr_running:\t%d\n"
17732 +               "nr_unintr:\t%d\n"
17733 +               "nr_onhold:\t%d\n"
17734 +               "load_updates:\t%d\n"
17735 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
17736 +               "total_forks:\t%d\n",
17737 +               atomic_read(&cvirt->nr_threads),
17738 +               atomic_read(&cvirt->nr_running),
17739 +               atomic_read(&cvirt->nr_uninterruptible),
17740 +               atomic_read(&cvirt->nr_onhold),
17741 +               atomic_read(&cvirt->load_updates),
17742 +               LOAD_INT(a), LOAD_FRAC(a),
17743 +               LOAD_INT(b), LOAD_FRAC(b),
17744 +               LOAD_INT(c), LOAD_FRAC(c),
17745 +               atomic_read(&cvirt->total_forks));
17746 +       return length;
17747 +}
17748 +
17749 +static inline
17750 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
17751 +       char *buffer, int cpu)
17752 +{
17753 +       int length = 0;
17754 +       return length;
17755 +}
17756 +
17757 +#endif /* _VX_CVIRT_PROC_H */
17758 diff -NurpP --minimal linux-2.6.36/kernel/vserver/debug.c linux-2.6.36-vs2.3.0.36.36/kernel/vserver/debug.c
17759 --- linux-2.6.36/kernel/vserver/debug.c 1970-01-01 01:00:00.000000000 +0100
17760 +++ linux-2.6.36-vs2.3.0.36.36/kernel/vserver/debug.c   2010-10-21 13:09:36.000000000 +0200
17761 @@ -0,0 +1,32 @@
17762 +/*
17763 + *  kernel/vserver/debug.c
17764 + *
17765 + *  Copyright (C) 2005-2007 Herbert Pötzl
17766 + *
17767 + *  V0.01  vx_info dump support
17768 + *
17769 + */
17770 +
17771 +#include <linux/module.h>
17772 +
17773 +#include <linux/vserver/context.h>
17774 +
17775 +
17776 +void   dump_vx_info(struct vx_info *vxi, int level)
17777 +{
17778 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
17779 +               atomic_read(&vxi->vx_usecnt),
17780 +               atomic_read(&vxi->vx_tasks),
17781 +               vxi->vx_state);
17782 +       if (level > 0) {
17783 +               __dump_vx_limit(&vxi->limit);
17784 +               __dump_vx_sched(&vxi->sched);
17785 +               __dump_vx_cvirt(&vxi->cvirt);
17786 +               __dump_vx_cacct(&vxi->cacct);
17787 +       }
17788 +       printk("---\n");
17789 +}
17790 +
17791 +
17792 +EXPORT_SYMBOL_GPL(dump_vx_info);
17793 +
17794 diff -NurpP --minimal linux-2.6.36/kernel/vserver/device.c linux-2.6.36-vs2.3.0.36.36/kernel/vserver/device.c
17795 --- linux-2.6.36/kernel/vserver/device.c        1970-01-01 01:00:00.000000000 +0100
17796 +++ linux-2.6.36-vs2.3.0.36.36/kernel/vserver/device.c  2010-10-21 13:09:36.000000000 +0200
17797 @@ -0,0 +1,443 @@
17798 +/*
17799 + *  linux/kernel/vserver/device.c
17800 + *
17801 + *  Linux-VServer: Device Support
17802 + *
17803 + *  Copyright (C) 2006  Herbert Pötzl
17804 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
17805 + *
17806 + *  V0.01  device mapping basics
17807 + *  V0.02  added defaults
17808 + *
17809 + */
17810 +
17811 +#include <linux/slab.h>
17812 +#include <linux/rcupdate.h>
17813 +#include <linux/fs.h>
17814 +#include <linux/namei.h>
17815 +#include <linux/hash.h>
17816 +
17817 +#include <asm/errno.h>
17818 +#include <asm/uaccess.h>
17819 +#include <linux/vserver/base.h>
17820 +#include <linux/vserver/debug.h>
17821 +#include <linux/vserver/context.h>
17822 +#include <linux/vserver/device.h>
17823 +#include <linux/vserver/device_cmd.h>
17824 +
17825 +
17826 +#define DMAP_HASH_BITS 4
17827 +
17828 +
17829 +struct vs_mapping {
17830 +       union {
17831 +               struct hlist_node hlist;
17832 +               struct list_head list;
17833 +       } u;
17834 +#define dm_hlist       u.hlist
17835 +#define dm_list                u.list
17836 +       xid_t xid;
17837 +       dev_t device;
17838 +       struct vx_dmap_target target;
17839 +};
17840 +
17841 +
17842 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
17843 +
17844 +static spinlock_t dmap_main_hash_lock = SPIN_LOCK_UNLOCKED;
17845 +
17846 +static struct vx_dmap_target dmap_defaults[2] = {
17847 +       { .flags = DATTR_OPEN },
17848 +       { .flags = DATTR_OPEN },
17849 +};
17850 +
17851 +
17852 +struct kmem_cache *dmap_cachep __read_mostly;
17853 +
17854 +int __init dmap_cache_init(void)
17855 +{
17856 +       dmap_cachep = kmem_cache_create("dmap_cache",
17857 +               sizeof(struct vs_mapping), 0,
17858 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
17859 +       return 0;
17860 +}
17861 +
17862 +__initcall(dmap_cache_init);
17863 +
17864 +
17865 +static inline unsigned int __hashval(dev_t dev, int bits)
17866 +{
17867 +       return hash_long((unsigned long)dev, bits);
17868 +}
17869 +
17870 +
17871 +/*     __hash_mapping()
17872 + *     add the mapping to the hash table
17873 + */
17874 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
17875 +{
17876 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17877 +       struct hlist_head *head, *hash = dmap_main_hash;
17878 +       int device = vdm->device;
17879 +
17880 +       spin_lock(hash_lock);
17881 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
17882 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
17883 +
17884 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
17885 +       hlist_add_head(&vdm->dm_hlist, head);
17886 +       spin_unlock(hash_lock);
17887 +}
17888 +
17889 +
17890 +static inline int __mode_to_default(umode_t mode)
17891 +{
17892 +       switch (mode) {
17893 +       case S_IFBLK:
17894 +               return 0;
17895 +       case S_IFCHR:
17896 +               return 1;
17897 +       default:
17898 +               BUG();
17899 +       }
17900 +}
17901 +
17902 +
17903 +/*     __set_default()
17904 + *     set a default
17905 + */
17906 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
17907 +       struct vx_dmap_target *vdmt)
17908 +{
17909 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17910 +       spin_lock(hash_lock);
17911 +
17912 +       if (vxi)
17913 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
17914 +       else
17915 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
17916 +
17917 +
17918 +       spin_unlock(hash_lock);
17919 +
17920 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
17921 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
17922 +}
17923 +
17924 +
17925 +/*     __remove_default()
17926 + *     remove a default
17927 + */
17928 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
17929 +{
17930 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17931 +       spin_lock(hash_lock);
17932 +
17933 +       if (vxi)
17934 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
17935 +       else    /* remove == reset */
17936 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
17937 +
17938 +       spin_unlock(hash_lock);
17939 +       return 0;
17940 +}
17941 +
17942 +
17943 +/*     __find_mapping()
17944 + *     find a mapping in the hash table
17945 + *
17946 + *     caller must hold hash_lock
17947 + */
17948 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
17949 +       struct vs_mapping **local, struct vs_mapping **global)
17950 +{
17951 +       struct hlist_head *hash = dmap_main_hash;
17952 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
17953 +       struct hlist_node *pos;
17954 +       struct vs_mapping *vdm;
17955 +
17956 +       *local = NULL;
17957 +       if (global)
17958 +               *global = NULL;
17959 +
17960 +       hlist_for_each(pos, head) {
17961 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
17962 +
17963 +               if ((vdm->device == device) &&
17964 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
17965 +                       if (vdm->xid == xid) {
17966 +                               *local = vdm;
17967 +                               return 1;
17968 +                       } else if (global && vdm->xid == 0)
17969 +                               *global = vdm;
17970 +               }
17971 +       }
17972 +
17973 +       if (global && *global)
17974 +               return 0;
17975 +       else
17976 +               return -ENOENT;
17977 +}
17978 +
17979 +
17980 +/*     __lookup_mapping()
17981 + *     find a mapping and store the result in target and flags
17982 + */
17983 +static inline int __lookup_mapping(struct vx_info *vxi,
17984 +       dev_t device, dev_t *target, int *flags, umode_t mode)
17985 +{
17986 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17987 +       struct vs_mapping *vdm, *global;
17988 +       struct vx_dmap_target *vdmt;
17989 +       int ret = 0;
17990 +       xid_t xid = vxi->vx_id;
17991 +       int index;
17992 +
17993 +       spin_lock(hash_lock);
17994 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
17995 +               ret = 1;
17996 +               vdmt = &vdm->target;
17997 +               goto found;
17998 +       }
17999 +
18000 +       index = __mode_to_default(mode);
18001 +       if (vxi && vxi->dmap.targets[index].flags) {
18002 +               ret = 2;
18003 +               vdmt = &vxi->dmap.targets[index];
18004 +       } else if (global) {
18005 +               ret = 3;
18006 +               vdmt = &global->target;
18007 +               goto found;
18008 +       } else {
18009 +               ret = 4;
18010 +               vdmt = &dmap_defaults[index];
18011 +       }
18012 +
18013 +found:
18014 +       if (target && (vdmt->flags & DATTR_REMAP))
18015 +               *target = vdmt->target;
18016 +       else if (target)
18017 +               *target = device;
18018 +       if (flags)
18019 +               *flags = vdmt->flags;
18020 +
18021 +       spin_unlock(hash_lock);
18022 +
18023 +       return ret;
18024 +}
18025 +
18026 +
18027 +/*     __remove_mapping()
18028 + *     remove a mapping from the hash table
18029 + */
18030 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
18031 +       umode_t mode)
18032 +{
18033 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18034 +       struct vs_mapping *vdm = NULL;
18035 +       int ret = 0;
18036 +
18037 +       spin_lock(hash_lock);
18038 +
18039 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
18040 +               NULL);
18041 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
18042 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
18043 +       if (ret < 0)
18044 +               goto out;
18045 +       hlist_del(&vdm->dm_hlist);
18046 +
18047 +out:
18048 +       spin_unlock(hash_lock);
18049 +       if (vdm)
18050 +               kmem_cache_free(dmap_cachep, vdm);
18051 +       return ret;
18052 +}
18053 +
18054 +
18055 +
18056 +int vs_map_device(struct vx_info *vxi,
18057 +       dev_t device, dev_t *target, umode_t mode)
18058 +{
18059 +       int ret, flags = DATTR_MASK;
18060 +
18061 +       if (!vxi) {
18062 +               if (target)
18063 +                       *target = device;
18064 +               goto out;
18065 +       }
18066 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
18067 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
18068 +               device, target ? *target : 0, flags, mode, ret);
18069 +out:
18070 +       return (flags & DATTR_MASK);
18071 +}
18072 +
18073 +
18074 +
18075 +static int do_set_mapping(struct vx_info *vxi,
18076 +       dev_t device, dev_t target, int flags, umode_t mode)
18077 +{
18078 +       if (device) {
18079 +               struct vs_mapping *new;
18080 +
18081 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
18082 +               if (!new)
18083 +                       return -ENOMEM;
18084 +
18085 +               INIT_HLIST_NODE(&new->dm_hlist);
18086 +               new->device = device;
18087 +               new->target.target = target;
18088 +               new->target.flags = flags | mode;
18089 +               new->xid = (vxi ? vxi->vx_id : 0);
18090 +
18091 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
18092 +               __hash_mapping(vxi, new);
18093 +       } else {
18094 +               struct vx_dmap_target new = {
18095 +                       .target = target,
18096 +                       .flags = flags | mode,
18097 +               };
18098 +               __set_default(vxi, mode, &new);
18099 +       }
18100 +       return 0;
18101 +}
18102 +
18103 +
18104 +static int do_unset_mapping(struct vx_info *vxi,
18105 +       dev_t device, dev_t target, int flags, umode_t mode)
18106 +{
18107 +       int ret = -EINVAL;
18108 +
18109 +       if (device) {
18110 +               ret = __remove_mapping(vxi, device, mode);
18111 +               if (ret < 0)
18112 +                       goto out;
18113 +       } else {
18114 +               ret = __remove_default(vxi, mode);
18115 +               if (ret < 0)
18116 +                       goto out;
18117 +       }
18118 +
18119 +out:
18120 +       return ret;
18121 +}
18122 +
18123 +
18124 +static inline int __user_device(const char __user *name, dev_t *dev,
18125 +       umode_t *mode)
18126 +{
18127 +       struct nameidata nd;
18128 +       int ret;
18129 +
18130 +       if (!name) {
18131 +               *dev = 0;
18132 +               return 0;
18133 +       }
18134 +       ret = user_lpath(name, &nd.path);
18135 +       if (ret)
18136 +               return ret;
18137 +       if (nd.path.dentry->d_inode) {
18138 +               *dev = nd.path.dentry->d_inode->i_rdev;
18139 +               *mode = nd.path.dentry->d_inode->i_mode;
18140 +       }
18141 +       path_put(&nd.path);
18142 +       return 0;
18143 +}
18144 +
18145 +static inline int __mapping_mode(dev_t device, dev_t target,
18146 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
18147 +{
18148 +       if (device)
18149 +               *mode = device_mode & S_IFMT;
18150 +       else if (target)
18151 +               *mode = target_mode & S_IFMT;
18152 +       else
18153 +               return -EINVAL;
18154 +
18155 +       /* if both given, device and target mode have to match */
18156 +       if (device && target &&
18157 +               ((device_mode ^ target_mode) & S_IFMT))
18158 +               return -EINVAL;
18159 +       return 0;
18160 +}
18161 +
18162 +
18163 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
18164 +       const char __user *target_path, int flags, int set)
18165 +{
18166 +       dev_t device = ~0, target = ~0;
18167 +       umode_t device_mode = 0, target_mode = 0, mode;
18168 +       int ret;
18169 +
18170 +       ret = __user_device(device_path, &device, &device_mode);
18171 +       if (ret)
18172 +               return ret;
18173 +       ret = __user_device(target_path, &target, &target_mode);
18174 +       if (ret)
18175 +               return ret;
18176 +
18177 +       ret = __mapping_mode(device, target,
18178 +               device_mode, target_mode, &mode);
18179 +       if (ret)
18180 +               return ret;
18181 +
18182 +       if (set)
18183 +               return do_set_mapping(vxi, device, target,
18184 +                       flags, mode);
18185 +       else
18186 +               return do_unset_mapping(vxi, device, target,
18187 +                       flags, mode);
18188 +}
18189 +
18190 +
18191 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
18192 +{
18193 +       struct vcmd_set_mapping_v0 vc_data;
18194 +
18195 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18196 +               return -EFAULT;
18197 +
18198 +       return do_mapping(vxi, vc_data.device, vc_data.target,
18199 +               vc_data.flags, 1);
18200 +}
18201 +
18202 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
18203 +{
18204 +       struct vcmd_set_mapping_v0 vc_data;
18205 +
18206 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18207 +               return -EFAULT;
18208 +
18209 +       return do_mapping(vxi, vc_data.device, vc_data.target,
18210 +               vc_data.flags, 0);
18211 +}
18212 +
18213 +
18214 +#ifdef CONFIG_COMPAT
18215 +
18216 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
18217 +{
18218 +       struct vcmd_set_mapping_v0_x32 vc_data;
18219 +
18220 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18221 +               return -EFAULT;
18222 +
18223 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
18224 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
18225 +}
18226 +
18227 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
18228 +{
18229 +       struct vcmd_set_mapping_v0_x32 vc_data;
18230 +
18231 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18232 +               return -EFAULT;
18233 +
18234 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
18235 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
18236 +}
18237 +
18238 +#endif /* CONFIG_COMPAT */
18239 +
18240 +
18241 diff -NurpP --minimal linux-2.6.36/kernel/vserver/dlimit.c linux-2.6.36-vs2.3.0.36.36/kernel/vserver/dlimit.c
18242 --- linux-2.6.36/kernel/vserver/dlimit.c        1970-01-01 01:00:00.000000000 +0100
18243 +++ linux-2.6.36-vs2.3.0.36.36/kernel/vserver/dlimit.c  2010-10-21 13:09:36.000000000 +0200
18244 @@ -0,0 +1,531 @@
18245 +/*
18246 + *  linux/kernel/vserver/dlimit.c
18247 + *
18248 + *  Virtual Server: Context Disk Limits
18249 + *
18250 + *  Copyright (C) 2004-2009  Herbert Pötzl
18251 + *
18252 + *  V0.01  initial version
18253 + *  V0.02  compat32 splitup
18254 + *  V0.03  extended interface
18255 + *
18256 + */
18257 +
18258 +#include <linux/statfs.h>
18259 +#include <linux/sched.h>
18260 +#include <linux/namei.h>
18261 +#include <linux/vs_tag.h>
18262 +#include <linux/vs_dlimit.h>
18263 +#include <linux/vserver/dlimit_cmd.h>
18264 +#include <linux/slab.h>
18265 +// #include <linux/gfp.h>
18266 +
18267 +#include <asm/uaccess.h>
18268 +
18269 +/*     __alloc_dl_info()
18270 +
18271 +       * allocate an initialized dl_info struct
18272 +       * doesn't make it visible (hash)                        */
18273 +
18274 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
18275 +{
18276 +       struct dl_info *new = NULL;
18277 +
18278 +       vxdprintk(VXD_CBIT(dlim, 5),
18279 +               "alloc_dl_info(%p,%d)*", sb, tag);
18280 +
18281 +       /* would this benefit from a slab cache? */
18282 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
18283 +       if (!new)
18284 +               return 0;
18285 +
18286 +       memset(new, 0, sizeof(struct dl_info));
18287 +       new->dl_tag = tag;
18288 +       new->dl_sb = sb;
18289 +       INIT_RCU_HEAD(&new->dl_rcu);
18290 +       INIT_HLIST_NODE(&new->dl_hlist);
18291 +       spin_lock_init(&new->dl_lock);
18292 +       atomic_set(&new->dl_refcnt, 0);
18293 +       atomic_set(&new->dl_usecnt, 0);
18294 +
18295 +       /* rest of init goes here */
18296 +
18297 +       vxdprintk(VXD_CBIT(dlim, 4),
18298 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
18299 +       return new;
18300 +}
18301 +
18302 +/*     __dealloc_dl_info()
18303 +
18304 +       * final disposal of dl_info                             */
18305 +
18306 +static void __dealloc_dl_info(struct dl_info *dli)
18307 +{
18308 +       vxdprintk(VXD_CBIT(dlim, 4),
18309 +               "dealloc_dl_info(%p)", dli);
18310 +
18311 +       dli->dl_hlist.next = LIST_POISON1;
18312 +       dli->dl_tag = -1;
18313 +       dli->dl_sb = 0;
18314 +
18315 +       BUG_ON(atomic_read(&dli->dl_usecnt));
18316 +       BUG_ON(atomic_read(&dli->dl_refcnt));
18317 +
18318 +       kfree(dli);
18319 +}
18320 +
18321 +
18322 +/*     hash table for dl_info hash */
18323 +
18324 +#define DL_HASH_SIZE   13
18325 +
18326 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
18327 +
18328 +static spinlock_t dl_info_hash_lock = SPIN_LOCK_UNLOCKED;
18329 +
18330 +
18331 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
18332 +{
18333 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
18334 +}
18335 +
18336 +
18337 +
18338 +/*     __hash_dl_info()
18339 +
18340 +       * add the dli to the global hash table
18341 +       * requires the hash_lock to be held                     */
18342 +
18343 +static inline void __hash_dl_info(struct dl_info *dli)
18344 +{
18345 +       struct hlist_head *head;
18346 +
18347 +       vxdprintk(VXD_CBIT(dlim, 6),
18348 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
18349 +       get_dl_info(dli);
18350 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
18351 +       hlist_add_head_rcu(&dli->dl_hlist, head);
18352 +}
18353 +
18354 +/*     __unhash_dl_info()
18355 +
18356 +       * remove the dli from the global hash table
18357 +       * requires the hash_lock to be held                     */
18358 +
18359 +static inline void __unhash_dl_info(struct dl_info *dli)
18360 +{
18361 +       vxdprintk(VXD_CBIT(dlim, 6),
18362 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
18363 +       hlist_del_rcu(&dli->dl_hlist);
18364 +       put_dl_info(dli);
18365 +}
18366 +
18367 +
18368 +/*     __lookup_dl_info()
18369 +
18370 +       * requires the rcu_read_lock()
18371 +       * doesn't increment the dl_refcnt                       */
18372 +
18373 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
18374 +{
18375 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
18376 +       struct hlist_node *pos;
18377 +       struct dl_info *dli;
18378 +
18379 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
18380 +
18381 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
18382 +                       return dli;
18383 +               }
18384 +       }
18385 +       return NULL;
18386 +}
18387 +
18388 +
18389 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
18390 +{
18391 +       struct dl_info *dli;
18392 +
18393 +       rcu_read_lock();
18394 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
18395 +       vxdprintk(VXD_CBIT(dlim, 7),
18396 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
18397 +       rcu_read_unlock();
18398 +       return dli;
18399 +}
18400 +
18401 +void rcu_free_dl_info(struct rcu_head *head)
18402 +{
18403 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
18404 +       int usecnt, refcnt;
18405 +
18406 +       BUG_ON(!dli || !head);
18407 +
18408 +       usecnt = atomic_read(&dli->dl_usecnt);
18409 +       BUG_ON(usecnt < 0);
18410 +
18411 +       refcnt = atomic_read(&dli->dl_refcnt);
18412 +       BUG_ON(refcnt < 0);
18413 +
18414 +       vxdprintk(VXD_CBIT(dlim, 3),
18415 +               "rcu_free_dl_info(%p)", dli);
18416 +       if (!usecnt)
18417 +               __dealloc_dl_info(dli);
18418 +       else
18419 +               printk("!!! rcu didn't free\n");
18420 +}
18421 +
18422 +
18423 +
18424 +
18425 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
18426 +       uint32_t flags, int add)
18427 +{
18428 +       struct path path;
18429 +       int ret;
18430 +
18431 +       ret = user_lpath(name, &path);
18432 +       if (!ret) {
18433 +               struct super_block *sb;
18434 +               struct dl_info *dli;
18435 +
18436 +               ret = -EINVAL;
18437 +               if (!path.dentry->d_inode)
18438 +                       goto out_release;
18439 +               if (!(sb = path.dentry->d_inode->i_sb))
18440 +                       goto out_release;
18441 +
18442 +               if (add) {
18443 +                       dli = __alloc_dl_info(sb, id);
18444 +                       spin_lock(&dl_info_hash_lock);
18445 +
18446 +                       ret = -EEXIST;
18447 +                       if (__lookup_dl_info(sb, id))
18448 +                               goto out_unlock;
18449 +                       __hash_dl_info(dli);
18450 +                       dli = NULL;
18451 +               } else {
18452 +                       spin_lock(&dl_info_hash_lock);
18453 +                       dli = __lookup_dl_info(sb, id);
18454 +
18455 +                       ret = -ESRCH;
18456 +                       if (!dli)
18457 +                               goto out_unlock;
18458 +                       __unhash_dl_info(dli);
18459 +               }
18460 +               ret = 0;
18461 +       out_unlock:
18462 +               spin_unlock(&dl_info_hash_lock);
18463 +               if (add && dli)
18464 +                       __dealloc_dl_info(dli);
18465 +       out_release:
18466 +               path_put(&path);
18467 +       }
18468 +       return ret;
18469 +}
18470 +
18471 +int vc_add_dlimit(uint32_t id, void __user *data)
18472 +{
18473 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18474 +
18475 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18476 +               return -EFAULT;
18477 +
18478 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
18479 +}
18480 +
18481 +int vc_rem_dlimit(uint32_t id, void __user *data)
18482 +{
18483 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18484 +
18485 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18486 +               return -EFAULT;
18487 +
18488 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
18489 +}
18490 +
18491 +#ifdef CONFIG_COMPAT
18492 +
18493 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
18494 +{
18495 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18496 +
18497 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18498 +               return -EFAULT;
18499 +
18500 +       return do_addrem_dlimit(id,
18501 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
18502 +}
18503 +
18504 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
18505 +{
18506 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18507 +
18508 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18509 +               return -EFAULT;
18510 +
18511 +       return do_addrem_dlimit(id,
18512 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
18513 +}
18514 +
18515 +#endif /* CONFIG_COMPAT */
18516 +
18517 +
18518 +static inline
18519 +int do_set_dlimit(uint32_t id, const char __user *name,
18520 +       uint32_t space_used, uint32_t space_total,
18521 +       uint32_t inodes_used, uint32_t inodes_total,
18522 +       uint32_t reserved, uint32_t flags)
18523 +{
18524 +       struct path path;
18525 +       int ret;
18526 +
18527 +       ret = user_lpath(name, &path);
18528 +       if (!ret) {
18529 +               struct super_block *sb;
18530 +               struct dl_info *dli;
18531 +
18532 +               ret = -EINVAL;
18533 +               if (!path.dentry->d_inode)
18534 +                       goto out_release;
18535 +               if (!(sb = path.dentry->d_inode->i_sb))
18536 +                       goto out_release;
18537 +
18538 +               /* sanity checks */
18539 +               if ((reserved != CDLIM_KEEP &&
18540 +                       reserved > 100) ||
18541 +                       (inodes_used != CDLIM_KEEP &&
18542 +                       inodes_used > inodes_total) ||
18543 +                       (space_used != CDLIM_KEEP &&
18544 +                       space_used > space_total))
18545 +                       goto out_release;
18546 +
18547 +               ret = -ESRCH;
18548 +               dli = locate_dl_info(sb, id);
18549 +               if (!dli)
18550 +                       goto out_release;
18551 +
18552 +               spin_lock(&dli->dl_lock);
18553 +
18554 +               if (inodes_used != CDLIM_KEEP)
18555 +                       dli->dl_inodes_used = inodes_used;
18556 +               if (inodes_total != CDLIM_KEEP)
18557 +                       dli->dl_inodes_total = inodes_total;
18558 +               if (space_used != CDLIM_KEEP)
18559 +                       dli->dl_space_used = dlimit_space_32to64(
18560 +                               space_used, flags, DLIMS_USED);
18561 +
18562 +               if (space_total == CDLIM_INFINITY)
18563 +                       dli->dl_space_total = DLIM_INFINITY;
18564 +               else if (space_total != CDLIM_KEEP)
18565 +                       dli->dl_space_total = dlimit_space_32to64(
18566 +                               space_total, flags, DLIMS_TOTAL);
18567 +
18568 +               if (reserved != CDLIM_KEEP)
18569 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
18570 +
18571 +               spin_unlock(&dli->dl_lock);
18572 +
18573 +               put_dl_info(dli);
18574 +               ret = 0;
18575 +
18576 +       out_release:
18577 +               path_put(&path);
18578 +       }
18579 +       return ret;
18580 +}
18581 +
18582 +int vc_set_dlimit(uint32_t id, void __user *data)
18583 +{
18584 +       struct vcmd_ctx_dlimit_v0 vc_data;
18585 +
18586 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18587 +               return -EFAULT;
18588 +
18589 +       return do_set_dlimit(id, vc_data.name,
18590 +               vc_data.space_used, vc_data.space_total,
18591 +               vc_data.inodes_used, vc_data.inodes_total,
18592 +               vc_data.reserved, vc_data.flags);
18593 +}
18594 +
18595 +#ifdef CONFIG_COMPAT
18596 +
18597 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
18598 +{
18599 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18600 +
18601 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18602 +               return -EFAULT;
18603 +
18604 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
18605 +               vc_data.space_used, vc_data.space_total,
18606 +               vc_data.inodes_used, vc_data.inodes_total,
18607 +               vc_data.reserved, vc_data.flags);
18608 +}
18609 +
18610 +#endif /* CONFIG_COMPAT */
18611 +
18612 +
18613 +static inline
18614 +int do_get_dlimit(uint32_t id, const char __user *name,
18615 +       uint32_t *space_used, uint32_t *space_total,
18616 +       uint32_t *inodes_used, uint32_t *inodes_total,
18617 +       uint32_t *reserved, uint32_t *flags)
18618 +{
18619 +       struct path path;
18620 +       int ret;
18621 +
18622 +       ret = user_lpath(name, &path);
18623 +       if (!ret) {
18624 +               struct super_block *sb;
18625 +               struct dl_info *dli;
18626 +
18627 +               ret = -EINVAL;
18628 +               if (!path.dentry->d_inode)
18629 +                       goto out_release;
18630 +               if (!(sb = path.dentry->d_inode->i_sb))
18631 +                       goto out_release;
18632 +
18633 +               ret = -ESRCH;
18634 +               dli = locate_dl_info(sb, id);
18635 +               if (!dli)
18636 +                       goto out_release;
18637 +
18638 +               spin_lock(&dli->dl_lock);
18639 +               *inodes_used = dli->dl_inodes_used;
18640 +               *inodes_total = dli->dl_inodes_total;
18641 +
18642 +               *space_used = dlimit_space_64to32(
18643 +                       dli->dl_space_used, flags, DLIMS_USED);
18644 +
18645 +               if (dli->dl_space_total == DLIM_INFINITY)
18646 +                       *space_total = CDLIM_INFINITY;
18647 +               else
18648 +                       *space_total = dlimit_space_64to32(
18649 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
18650 +
18651 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18652 +               spin_unlock(&dli->dl_lock);
18653 +
18654 +               put_dl_info(dli);
18655 +               ret = -EFAULT;
18656 +
18657 +               ret = 0;
18658 +       out_release:
18659 +               path_put(&path);
18660 +       }
18661 +       return ret;
18662 +}
18663 +
18664 +
18665 +int vc_get_dlimit(uint32_t id, void __user *data)
18666 +{
18667 +       struct vcmd_ctx_dlimit_v0 vc_data;
18668 +       int ret;
18669 +
18670 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18671 +               return -EFAULT;
18672 +
18673 +       ret = do_get_dlimit(id, vc_data.name,
18674 +               &vc_data.space_used, &vc_data.space_total,
18675 +               &vc_data.inodes_used, &vc_data.inodes_total,
18676 +               &vc_data.reserved, &vc_data.flags);
18677 +       if (ret)
18678 +               return ret;
18679 +
18680 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18681 +               return -EFAULT;
18682 +       return 0;
18683 +}
18684 +
18685 +#ifdef CONFIG_COMPAT
18686 +
18687 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18688 +{
18689 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18690 +       int ret;
18691 +
18692 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18693 +               return -EFAULT;
18694 +
18695 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18696 +               &vc_data.space_used, &vc_data.space_total,
18697 +               &vc_data.inodes_used, &vc_data.inodes_total,
18698 +               &vc_data.reserved, &vc_data.flags);
18699 +       if (ret)
18700 +               return ret;
18701 +
18702 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18703 +               return -EFAULT;
18704 +       return 0;
18705 +}
18706 +
18707 +#endif /* CONFIG_COMPAT */
18708 +
18709 +
18710 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
18711 +{
18712 +       struct dl_info *dli;
18713 +       __u64 blimit, bfree, bavail;
18714 +       __u32 ifree;
18715 +
18716 +       dli = locate_dl_info(sb, dx_current_tag());
18717 +       if (!dli)
18718 +               return;
18719 +
18720 +       spin_lock(&dli->dl_lock);
18721 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
18722 +               goto no_ilim;
18723 +
18724 +       /* reduce max inodes available to limit */
18725 +       if (buf->f_files > dli->dl_inodes_total)
18726 +               buf->f_files = dli->dl_inodes_total;
18727 +
18728 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
18729 +       /* reduce free inodes to min */
18730 +       if (ifree < buf->f_ffree)
18731 +               buf->f_ffree = ifree;
18732 +
18733 +no_ilim:
18734 +       if (dli->dl_space_total == DLIM_INFINITY)
18735 +               goto no_blim;
18736 +
18737 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
18738 +
18739 +       if (dli->dl_space_total < dli->dl_space_used)
18740 +               bfree = 0;
18741 +       else
18742 +               bfree = (dli->dl_space_total - dli->dl_space_used)
18743 +                       >> sb->s_blocksize_bits;
18744 +
18745 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
18746 +       if (bavail < dli->dl_space_used)
18747 +               bavail = 0;
18748 +       else
18749 +               bavail = (bavail - dli->dl_space_used)
18750 +                       >> sb->s_blocksize_bits;
18751 +
18752 +       /* reduce max space available to limit */
18753 +       if (buf->f_blocks > blimit)
18754 +               buf->f_blocks = blimit;
18755 +
18756 +       /* reduce free space to min */
18757 +       if (bfree < buf->f_bfree)
18758 +               buf->f_bfree = bfree;
18759 +
18760 +       /* reduce avail space to min */
18761 +       if (bavail < buf->f_bavail)
18762 +               buf->f_bavail = bavail;
18763 +
18764 +no_blim:
18765 +       spin_unlock(&dli->dl_lock);
18766 +       put_dl_info(dli);
18767 +
18768 +       return;
18769 +}
18770 +
18771 +#include <linux/module.h>
18772 +
18773 +EXPORT_SYMBOL_GPL(locate_dl_info);
18774 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
18775 +
18776 diff -NurpP --minimal linux-2.6.36/kernel/vserver/helper.c linux-2.6.36-vs2.3.0.36.36/kernel/vserver/helper.c
18777 --- linux-2.6.36/kernel/vserver/helper.c        1970-01-01 01:00:00.000000000 +0100
18778 +++ linux-2.6.36-vs2.3.0.36.36/kernel/vserver/helper.c  2010-10-21 13:09:36.000000000 +0200
18779 @@ -0,0 +1,223 @@
18780 +/*
18781 + *  linux/kernel/vserver/helper.c
18782 + *
18783 + *  Virtual Context Support
18784 + *
18785 + *  Copyright (C) 2004-2007  Herbert Pötzl
18786 + *
18787 + *  V0.01  basic helper
18788 + *
18789 + */
18790 +
18791 +#include <linux/kmod.h>
18792 +#include <linux/reboot.h>
18793 +#include <linux/vs_context.h>
18794 +#include <linux/vs_network.h>
18795 +#include <linux/vserver/signal.h>
18796 +
18797 +
18798 +char vshelper_path[255] = "/sbin/vshelper";
18799 +
18800 +
18801 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
18802 +{
18803 +       int ret;
18804 +
18805 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
18806 +               printk( KERN_WARNING
18807 +                       "%s: (%s %s) returned %s with %d\n",
18808 +                       name, argv[1], argv[2],
18809 +                       sync ? "sync" : "async", ret);
18810 +       }
18811 +       vxdprintk(VXD_CBIT(switch, 4),
18812 +               "%s: (%s %s) returned %s with %d",
18813 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
18814 +       return ret;
18815 +}
18816 +
18817 +/*
18818 + *      vshelper path is set via /proc/sys
18819 + *      invoked by vserver sys_reboot(), with
18820 + *      the following arguments
18821 + *
18822 + *      argv [0] = vshelper_path;
18823 + *      argv [1] = action: "restart", "halt", "poweroff", ...
18824 + *      argv [2] = context identifier
18825 + *
18826 + *      envp [*] = type-specific parameters
18827 + */
18828 +
18829 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
18830 +{
18831 +       char id_buf[8], cmd_buf[16];
18832 +       char uid_buf[16], pid_buf[16];
18833 +       int ret;
18834 +
18835 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18836 +       char *envp[] = {"HOME=/", "TERM=linux",
18837 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
18838 +                       uid_buf, pid_buf, cmd_buf, 0};
18839 +
18840 +       if (vx_info_state(vxi, VXS_HELPER))
18841 +               return -EAGAIN;
18842 +       vxi->vx_state |= VXS_HELPER;
18843 +
18844 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
18845 +
18846 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
18847 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current_uid());
18848 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
18849 +
18850 +       switch (cmd) {
18851 +       case LINUX_REBOOT_CMD_RESTART:
18852 +               argv[1] = "restart";
18853 +               break;
18854 +
18855 +       case LINUX_REBOOT_CMD_HALT:
18856 +               argv[1] = "halt";
18857 +               break;
18858 +
18859 +       case LINUX_REBOOT_CMD_POWER_OFF:
18860 +               argv[1] = "poweroff";
18861 +               break;
18862 +
18863 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
18864 +               argv[1] = "swsusp";
18865 +               break;
18866 +
18867 +       case LINUX_REBOOT_CMD_OOM:
18868 +               argv[1] = "oom";
18869 +               break;
18870 +
18871 +       default:
18872 +               vxi->vx_state &= ~VXS_HELPER;
18873 +               return 0;
18874 +       }
18875 +
18876 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
18877 +       vxi->vx_state &= ~VXS_HELPER;
18878 +       __wakeup_vx_info(vxi);
18879 +       return (ret) ? -EPERM : 0;
18880 +}
18881 +
18882 +
18883 +long vs_reboot(unsigned int cmd, void __user *arg)
18884 +{
18885 +       struct vx_info *vxi = current_vx_info();
18886 +       long ret = 0;
18887 +
18888 +       vxdprintk(VXD_CBIT(misc, 5),
18889 +               "vs_reboot(%p[#%d],%u)",
18890 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18891 +
18892 +       ret = vs_reboot_helper(vxi, cmd, arg);
18893 +       if (ret)
18894 +               return ret;
18895 +
18896 +       vxi->reboot_cmd = cmd;
18897 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18898 +               switch (cmd) {
18899 +               case LINUX_REBOOT_CMD_RESTART:
18900 +               case LINUX_REBOOT_CMD_HALT:
18901 +               case LINUX_REBOOT_CMD_POWER_OFF:
18902 +                       vx_info_kill(vxi, 0, SIGKILL);
18903 +                       vx_info_kill(vxi, 1, SIGKILL);
18904 +               default:
18905 +                       break;
18906 +               }
18907 +       }
18908 +       return 0;
18909 +}
18910 +
18911 +long vs_oom_action(unsigned int cmd)
18912 +{
18913 +       struct vx_info *vxi = current_vx_info();
18914 +       long ret = 0;
18915 +
18916 +       vxdprintk(VXD_CBIT(misc, 5),
18917 +               "vs_oom_action(%p[#%d],%u)",
18918 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18919 +
18920 +       ret = vs_reboot_helper(vxi, cmd, NULL);
18921 +       if (ret)
18922 +               return ret;
18923 +
18924 +       vxi->reboot_cmd = cmd;
18925 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18926 +               vx_info_kill(vxi, 0, SIGKILL);
18927 +               vx_info_kill(vxi, 1, SIGKILL);
18928 +       }
18929 +       return 0;
18930 +}
18931 +
18932 +/*
18933 + *      argv [0] = vshelper_path;
18934 + *      argv [1] = action: "startup", "shutdown"
18935 + *      argv [2] = context identifier
18936 + *
18937 + *      envp [*] = type-specific parameters
18938 + */
18939 +
18940 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
18941 +{
18942 +       char id_buf[8], cmd_buf[16];
18943 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18944 +       char *envp[] = {"HOME=/", "TERM=linux",
18945 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18946 +
18947 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
18948 +               return 0;
18949 +
18950 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
18951 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
18952 +
18953 +       switch (cmd) {
18954 +       case VSC_STARTUP:
18955 +               argv[1] = "startup";
18956 +               break;
18957 +       case VSC_SHUTDOWN:
18958 +               argv[1] = "shutdown";
18959 +               break;
18960 +       default:
18961 +               return 0;
18962 +       }
18963 +
18964 +       return do_vshelper(vshelper_path, argv, envp, 1);
18965 +}
18966 +
18967 +
18968 +/*
18969 + *      argv [0] = vshelper_path;
18970 + *      argv [1] = action: "netup", "netdown"
18971 + *      argv [2] = context identifier
18972 + *
18973 + *      envp [*] = type-specific parameters
18974 + */
18975 +
18976 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
18977 +{
18978 +       char id_buf[8], cmd_buf[16];
18979 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18980 +       char *envp[] = {"HOME=/", "TERM=linux",
18981 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18982 +
18983 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
18984 +               return 0;
18985 +
18986 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
18987 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
18988 +
18989 +       switch (cmd) {
18990 +       case VSC_NETUP:
18991 +               argv[1] = "netup";
18992 +               break;
18993 +       case VSC_NETDOWN:
18994 +               argv[1] = "netdown";
18995 +               break;
18996 +       default:
18997 +               return 0;
18998 +       }
18999 +
19000 +       return do_vshelper(vshelper_path, argv, envp, 1);
19001 +}
19002 +
19003 diff -NurpP --minimal linux-2.6.36/kernel/vserver/history.c linux-2.6.36-vs2.3.0.36.36/kernel/vserver/history.c
19004 --- linux-2.6.36/kernel/vserver/history.c       1970-01-01 01:00:00.000000000 +0100
19005 +++ linux-2.6.36-vs2.3.0.36.36/kernel/vserver/history.c 2010-10-21 13:09:36.000000000 +0200
19006 @@ -0,0 +1,258 @@
19007 +/*
19008 + *  kernel/vserver/history.c
19009 + *
19010 + *  Virtual Context History Backtrace
19011 + *
19012 + *  Copyright (C) 2004-2007  Herbert Pötzl
19013 + *
19014 + *  V0.01  basic structure
19015 + *  V0.02  hash/unhash and trace
19016 + *  V0.03  preemption fixes
19017 + *
19018 + */
19019 +
19020 +#include <linux/module.h>
19021 +#include <asm/uaccess.h>
19022 +
19023 +#include <linux/vserver/context.h>
19024 +#include <linux/vserver/debug.h>
19025 +#include <linux/vserver/debug_cmd.h>
19026 +#include <linux/vserver/history.h>
19027 +
19028 +
19029 +#ifdef CONFIG_VSERVER_HISTORY
19030 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
19031 +#else
19032 +#define VXH_SIZE       64
19033 +#endif
19034 +
19035 +struct _vx_history {
19036 +       unsigned int counter;
19037 +
19038 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
19039 +};
19040 +
19041 +
19042 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
19043 +
19044 +unsigned volatile int vxh_active = 1;
19045 +
19046 +static atomic_t sequence = ATOMIC_INIT(0);
19047 +
19048 +
19049 +/*     vxh_advance()
19050 +
19051 +       * requires disabled preemption                          */
19052 +
19053 +struct _vx_hist_entry *vxh_advance(void *loc)
19054 +{
19055 +       unsigned int cpu = smp_processor_id();
19056 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
19057 +       struct _vx_hist_entry *entry;
19058 +       unsigned int index;
19059 +
19060 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
19061 +       entry = &hist->entry[index];
19062 +
19063 +       entry->seq = atomic_inc_return(&sequence);
19064 +       entry->loc = loc;
19065 +       return entry;
19066 +}
19067 +
19068 +EXPORT_SYMBOL_GPL(vxh_advance);
19069 +
19070 +
19071 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
19072 +
19073 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
19074 +
19075 +
19076 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
19077 +
19078 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
19079 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
19080 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
19081 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
19082 +
19083 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
19084 +{
19085 +       switch (e->type) {
19086 +       case VXH_THROW_OOPS:
19087 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
19088 +               break;
19089 +
19090 +       case VXH_GET_VX_INFO:
19091 +       case VXH_PUT_VX_INFO:
19092 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
19093 +                       VXH_LOC_ARGS(e),
19094 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
19095 +                       VXH_VXI_ARGS(e));
19096 +               break;
19097 +
19098 +       case VXH_INIT_VX_INFO:
19099 +       case VXH_SET_VX_INFO:
19100 +       case VXH_CLR_VX_INFO:
19101 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
19102 +                       VXH_LOC_ARGS(e),
19103 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
19104 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
19105 +                       VXH_VXI_ARGS(e), e->sc.data);
19106 +               break;
19107 +
19108 +       case VXH_CLAIM_VX_INFO:
19109 +       case VXH_RELEASE_VX_INFO:
19110 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
19111 +                       VXH_LOC_ARGS(e),
19112 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
19113 +                       VXH_VXI_ARGS(e), e->sc.data);
19114 +               break;
19115 +
19116 +       case VXH_ALLOC_VX_INFO:
19117 +       case VXH_DEALLOC_VX_INFO:
19118 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
19119 +                       VXH_LOC_ARGS(e),
19120 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
19121 +                       VXH_VXI_ARGS(e));
19122 +               break;
19123 +
19124 +       case VXH_HASH_VX_INFO:
19125 +       case VXH_UNHASH_VX_INFO:
19126 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
19127 +                       VXH_LOC_ARGS(e),
19128 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
19129 +                       VXH_VXI_ARGS(e));
19130 +               break;
19131 +
19132 +       case VXH_LOC_VX_INFO:
19133 +       case VXH_LOOKUP_VX_INFO:
19134 +       case VXH_CREATE_VX_INFO:
19135 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
19136 +                       VXH_LOC_ARGS(e),
19137 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
19138 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
19139 +                       e->ll.arg, VXH_VXI_ARGS(e));
19140 +               break;
19141 +       }
19142 +}
19143 +
19144 +static void __vxh_dump_history(void)
19145 +{
19146 +       unsigned int i, cpu;
19147 +
19148 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
19149 +               atomic_read(&sequence), NR_CPUS);
19150 +
19151 +       for (i = 0; i < VXH_SIZE; i++) {
19152 +               for_each_online_cpu(cpu) {
19153 +                       struct _vx_history *hist =
19154 +                               &per_cpu(vx_history_buffer, cpu);
19155 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
19156 +                       struct _vx_hist_entry *entry = &hist->entry[index];
19157 +
19158 +                       vxh_dump_entry(entry, cpu);
19159 +               }
19160 +       }
19161 +}
19162 +
19163 +void   vxh_dump_history(void)
19164 +{
19165 +       vxh_active = 0;
19166 +#ifdef CONFIG_SMP
19167 +       local_irq_enable();
19168 +       smp_send_stop();
19169 +       local_irq_disable();
19170 +#endif
19171 +       __vxh_dump_history();
19172 +}
19173 +
19174 +
19175 +/* vserver syscall commands below here */
19176 +
19177 +
19178 +int vc_dump_history(uint32_t id)
19179 +{
19180 +       vxh_active = 0;
19181 +       __vxh_dump_history();
19182 +       vxh_active = 1;
19183 +
19184 +       return 0;
19185 +}
19186 +
19187 +
19188 +int do_read_history(struct __user _vx_hist_entry *data,
19189 +       int cpu, uint32_t *index, uint32_t *count)
19190 +{
19191 +       int pos, ret = 0;
19192 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
19193 +       int end = hist->counter;
19194 +       int start = end - VXH_SIZE + 2;
19195 +       int idx = *index;
19196 +
19197 +       /* special case: get current pos */
19198 +       if (!*count) {
19199 +               *index = end;
19200 +               return 0;
19201 +       }
19202 +
19203 +       /* have we lost some data? */
19204 +       if (idx < start)
19205 +               idx = start;
19206 +
19207 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
19208 +               struct _vx_hist_entry *entry =
19209 +                       &hist->entry[idx % VXH_SIZE];
19210 +
19211 +               /* send entry to userspace */
19212 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
19213 +               if (ret)
19214 +                       break;
19215 +       }
19216 +       /* save new index and count */
19217 +       *index = idx;
19218 +       *count = pos;
19219 +       return ret ? ret : (*index < end);
19220 +}
19221 +
19222 +int vc_read_history(uint32_t id, void __user *data)
19223 +{
19224 +       struct vcmd_read_history_v0 vc_data;
19225 +       int ret;
19226 +
19227 +       if (id >= NR_CPUS)
19228 +               return -EINVAL;
19229 +
19230 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19231 +               return -EFAULT;
19232 +
19233 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
19234 +               id, &vc_data.index, &vc_data.count);
19235 +
19236 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19237 +               return -EFAULT;
19238 +       return ret;
19239 +}
19240 +
19241 +#ifdef CONFIG_COMPAT
19242 +
19243 +int vc_read_history_x32(uint32_t id, void __user *data)
19244 +{
19245 +       struct vcmd_read_history_v0_x32 vc_data;
19246 +       int ret;
19247 +
19248 +       if (id >= NR_CPUS)
19249 +               return -EINVAL;
19250 +
19251 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19252 +               return -EFAULT;
19253 +
19254 +       ret = do_read_history((struct __user _vx_hist_entry *)
19255 +               compat_ptr(vc_data.data_ptr),
19256 +               id, &vc_data.index, &vc_data.count);
19257 +
19258 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19259 +               return -EFAULT;
19260 +       return ret;
19261 +}
19262 +
19263 +#endif /* CONFIG_COMPAT */
19264 +
19265 diff -NurpP --minimal linux-2.6.36/kernel/vserver/inet.c linux-2.6.36-vs2.3.0.36.36/kernel/vserver/inet.c
19266 --- linux-2.6.36/kernel/vserver/inet.c  1970-01-01 01:00:00.000000000 +0100
19267 +++ linux-2.6.36-vs2.3.0.36.36/kernel/vserver/inet.c    2010-10-21 13:09:36.000000000 +0200
19268 @@ -0,0 +1,224 @@
19269 +
19270 +#include <linux/in.h>
19271 +#include <linux/inetdevice.h>
19272 +#include <linux/vs_inet.h>
19273 +#include <linux/vs_inet6.h>
19274 +#include <linux/vserver/debug.h>
19275 +#include <net/route.h>
19276 +#include <net/addrconf.h>
19277 +
19278 +
19279 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19280 +{
19281 +       int ret = 0;
19282 +
19283 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19284 +               ret = 1;
19285 +       else {
19286 +               struct nx_addr_v4 *ptr;
19287 +
19288 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
19289 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19290 +                               ret = 1;
19291 +                               break;
19292 +                       }
19293 +               }
19294 +       }
19295 +
19296 +       vxdprintk(VXD_CBIT(net, 2),
19297 +               "nx_v4_addr_conflict(%p,%p): %d",
19298 +               nxi1, nxi2, ret);
19299 +
19300 +       return ret;
19301 +}
19302 +
19303 +
19304 +#ifdef CONFIG_IPV6
19305 +
19306 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19307 +{
19308 +       int ret = 0;
19309 +
19310 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19311 +               ret = 1;
19312 +       else {
19313 +               struct nx_addr_v6 *ptr;
19314 +
19315 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
19316 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19317 +                               ret = 1;
19318 +                               break;
19319 +                       }
19320 +               }
19321 +       }
19322 +
19323 +       vxdprintk(VXD_CBIT(net, 2),
19324 +               "nx_v6_addr_conflict(%p,%p): %d",
19325 +               nxi1, nxi2, ret);
19326 +
19327 +       return ret;
19328 +}
19329 +
19330 +#endif
19331 +
19332 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19333 +{
19334 +       struct in_device *in_dev;
19335 +       struct in_ifaddr **ifap;
19336 +       struct in_ifaddr *ifa;
19337 +       int ret = 0;
19338 +
19339 +       if (!dev)
19340 +               goto out;
19341 +       in_dev = in_dev_get(dev);
19342 +       if (!in_dev)
19343 +               goto out;
19344 +
19345 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
19346 +               ifap = &ifa->ifa_next) {
19347 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
19348 +                       ret = 1;
19349 +                       break;
19350 +               }
19351 +       }
19352 +       in_dev_put(in_dev);
19353 +out:
19354 +       return ret;
19355 +}
19356 +
19357 +
19358 +#ifdef CONFIG_IPV6
19359 +
19360 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19361 +{
19362 +       struct inet6_dev *in_dev;
19363 +       struct inet6_ifaddr *ifa;
19364 +       int ret = 0;
19365 +
19366 +       if (!dev)
19367 +               goto out;
19368 +       in_dev = in6_dev_get(dev);
19369 +       if (!in_dev)
19370 +               goto out;
19371 +
19372 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
19373 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
19374 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
19375 +                       ret = 1;
19376 +                       break;
19377 +               }
19378 +       }
19379 +       in6_dev_put(in_dev);
19380 +out:
19381 +       return ret;
19382 +}
19383 +
19384 +#endif
19385 +
19386 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19387 +{
19388 +       int ret = 1;
19389 +
19390 +       if (!nxi)
19391 +               goto out;
19392 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
19393 +               goto out;
19394 +#ifdef CONFIG_IPV6
19395 +       ret = 2;
19396 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
19397 +               goto out;
19398 +#endif
19399 +       ret = 0;
19400 +out:
19401 +       vxdprintk(VXD_CBIT(net, 3),
19402 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
19403 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
19404 +       return ret;
19405 +}
19406 +
19407 +int ip_v4_find_src(struct net *net, struct nx_info *nxi,
19408 +       struct rtable **rp, struct flowi *fl)
19409 +{
19410 +       if (!nxi)
19411 +               return 0;
19412 +
19413 +       /* FIXME: handle lback only case */
19414 +       if (!NX_IPV4(nxi))
19415 +               return -EPERM;
19416 +
19417 +       vxdprintk(VXD_CBIT(net, 4),
19418 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
19419 +               nxi, nxi ? nxi->nx_id : 0,
19420 +               NIPQUAD(fl->fl4_src), NIPQUAD(fl->fl4_dst));
19421 +
19422 +       /* single IP is unconditional */
19423 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
19424 +               (fl->fl4_src == INADDR_ANY))
19425 +               fl->fl4_src = nxi->v4.ip[0].s_addr;
19426 +
19427 +       if (fl->fl4_src == INADDR_ANY) {
19428 +               struct nx_addr_v4 *ptr;
19429 +               __be32 found = 0;
19430 +               int err;
19431 +
19432 +               err = __ip_route_output_key(net, rp, fl);
19433 +               if (!err) {
19434 +                       found = (*rp)->rt_src;
19435 +                       ip_rt_put(*rp);
19436 +                       vxdprintk(VXD_CBIT(net, 4),
19437 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19438 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(found));
19439 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
19440 +                               goto found;
19441 +               }
19442 +
19443 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
19444 +                       __be32 primary = ptr->ip[0].s_addr;
19445 +                       __be32 mask = ptr->mask.s_addr;
19446 +                       __be32 neta = primary & mask;
19447 +
19448 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
19449 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
19450 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
19451 +                               NIPQUAD(mask), NIPQUAD(neta));
19452 +                       if ((found & mask) != neta)
19453 +                               continue;
19454 +
19455 +                       fl->fl4_src = primary;
19456 +                       err = __ip_route_output_key(net, rp, fl);
19457 +                       vxdprintk(VXD_CBIT(net, 4),
19458 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19459 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(primary));
19460 +                       if (!err) {
19461 +                               found = (*rp)->rt_src;
19462 +                               ip_rt_put(*rp);
19463 +                               if (found == primary)
19464 +                                       goto found;
19465 +                       }
19466 +               }
19467 +               /* still no source ip? */
19468 +               found = ipv4_is_loopback(fl->fl4_dst)
19469 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
19470 +       found:
19471 +               /* assign src ip to flow */
19472 +               fl->fl4_src = found;
19473 +
19474 +       } else {
19475 +               if (!v4_addr_in_nx_info(nxi, fl->fl4_src, NXA_MASK_BIND))
19476 +                       return -EPERM;
19477 +       }
19478 +
19479 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
19480 +               if (ipv4_is_loopback(fl->fl4_dst))
19481 +                       fl->fl4_dst = nxi->v4_lback.s_addr;
19482 +               if (ipv4_is_loopback(fl->fl4_src))
19483 +                       fl->fl4_src = nxi->v4_lback.s_addr;
19484 +       } else if (ipv4_is_loopback(fl->fl4_dst) &&
19485 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
19486 +               return -EPERM;
19487 +
19488 +       return 0;
19489 +}
19490 +
19491 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
19492 +
19493 diff -NurpP --minimal linux-2.6.36/kernel/vserver/init.c linux-2.6.36-vs2.3.0.36.36/kernel/vserver/init.c
19494 --- linux-2.6.36/kernel/vserver/init.c  1970-01-01 01:00:00.000000000 +0100
19495 +++ linux-2.6.36-vs2.3.0.36.36/kernel/vserver/init.c    2010-10-21 13:09:36.000000000 +0200
19496 @@ -0,0 +1,45 @@
19497 +/*
19498 + *  linux/kernel/init.c
19499 + *
19500 + *  Virtual Server Init
19501 + *
19502 + *  Copyright (C) 2004-2007  Herbert Pötzl
19503 + *
19504 + *  V0.01  basic structure
19505 + *
19506 + */
19507 +
19508 +#include <linux/init.h>
19509 +
19510 +int    vserver_register_sysctl(void);
19511 +void   vserver_unregister_sysctl(void);
19512 +
19513 +
19514 +static int __init init_vserver(void)
19515 +{
19516 +       int ret = 0;
19517 +
19518 +#ifdef CONFIG_VSERVER_DEBUG
19519 +       vserver_register_sysctl();
19520 +#endif
19521 +       return ret;
19522 +}
19523 +
19524 +
19525 +static void __exit exit_vserver(void)
19526 +{
19527 +
19528 +#ifdef CONFIG_VSERVER_DEBUG
19529 +       vserver_unregister_sysctl();
19530 +#endif
19531 +       return;
19532 +}
19533 +
19534 +/* FIXME: GFP_ZONETYPES gone
19535 +long vx_slab[GFP_ZONETYPES]; */
19536 +long vx_area;
19537 +
19538 +
19539 +module_init(init_vserver);
19540 +module_exit(exit_vserver);
19541 +
19542 diff -NurpP --minimal linux-2.6.36/kernel/vserver/inode.c linux-2.6.36-vs2.3.0.36.36/kernel/vserver/inode.c
19543 --- linux-2.6.36/kernel/vserver/inode.c 1970-01-01 01:00:00.000000000 +0100
19544 +++ linux-2.6.36-vs2.3.0.36.36/kernel/vserver/inode.c   2010-10-21 17:40:44.000000000 +0200
19545 @@ -0,0 +1,435 @@
19546 +/*
19547 + *  linux/kernel/vserver/inode.c
19548 + *
19549 + *  Virtual Server: File System Support
19550 + *
19551 + *  Copyright (C) 2004-2007  Herbert Pötzl
19552 + *
19553 + *  V0.01  separated from vcontext V0.05
19554 + *  V0.02  moved to tag (instead of xid)
19555 + *
19556 + */
19557 +
19558 +#include <linux/tty.h>
19559 +#include <linux/proc_fs.h>
19560 +#include <linux/devpts_fs.h>
19561 +#include <linux/fs.h>
19562 +#include <linux/file.h>
19563 +#include <linux/mount.h>
19564 +#include <linux/parser.h>
19565 +#include <linux/namei.h>
19566 +#include <linux/vserver/inode.h>
19567 +#include <linux/vserver/inode_cmd.h>
19568 +#include <linux/vs_base.h>
19569 +#include <linux/vs_tag.h>
19570 +
19571 +#include <asm/uaccess.h>
19572 +
19573 +
19574 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19575 +{
19576 +       struct proc_dir_entry *entry;
19577 +
19578 +       if (!in || !in->i_sb)
19579 +               return -ESRCH;
19580 +
19581 +       *flags = IATTR_TAG
19582 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
19583 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
19584 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
19585 +               | (IS_COW(in) ? IATTR_COW : 0);
19586 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
19587 +
19588 +       if (S_ISDIR(in->i_mode))
19589 +               *mask |= IATTR_BARRIER;
19590 +
19591 +       if (IS_TAGGED(in)) {
19592 +               *tag = in->i_tag;
19593 +               *mask |= IATTR_TAG;
19594 +       }
19595 +
19596 +       switch (in->i_sb->s_magic) {
19597 +       case PROC_SUPER_MAGIC:
19598 +               entry = PROC_I(in)->pde;
19599 +
19600 +               /* check for specific inodes? */
19601 +               if (entry)
19602 +                       *mask |= IATTR_FLAGS;
19603 +               if (entry)
19604 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
19605 +               else
19606 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19607 +               break;
19608 +
19609 +       case DEVPTS_SUPER_MAGIC:
19610 +               *tag = in->i_tag;
19611 +               *mask |= IATTR_TAG;
19612 +               break;
19613 +
19614 +       default:
19615 +               break;
19616 +       }
19617 +       return 0;
19618 +}
19619 +
19620 +int vc_get_iattr(void __user *data)
19621 +{
19622 +       struct path path;
19623 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19624 +       int ret;
19625 +
19626 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19627 +               return -EFAULT;
19628 +
19629 +       ret = user_lpath(vc_data.name, &path);
19630 +       if (!ret) {
19631 +               ret = __vc_get_iattr(path.dentry->d_inode,
19632 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19633 +               path_put(&path);
19634 +       }
19635 +       if (ret)
19636 +               return ret;
19637 +
19638 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19639 +               ret = -EFAULT;
19640 +       return ret;
19641 +}
19642 +
19643 +#ifdef CONFIG_COMPAT
19644 +
19645 +int vc_get_iattr_x32(void __user *data)
19646 +{
19647 +       struct path path;
19648 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19649 +       int ret;
19650 +
19651 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19652 +               return -EFAULT;
19653 +
19654 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19655 +       if (!ret) {
19656 +               ret = __vc_get_iattr(path.dentry->d_inode,
19657 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19658 +               path_put(&path);
19659 +       }
19660 +       if (ret)
19661 +               return ret;
19662 +
19663 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19664 +               ret = -EFAULT;
19665 +       return ret;
19666 +}
19667 +
19668 +#endif /* CONFIG_COMPAT */
19669 +
19670 +
19671 +int vc_fget_iattr(uint32_t fd, void __user *data)
19672 +{
19673 +       struct file *filp;
19674 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19675 +       int ret;
19676 +
19677 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19678 +               return -EFAULT;
19679 +
19680 +       filp = fget(fd);
19681 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19682 +               return -EBADF;
19683 +
19684 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
19685 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
19686 +
19687 +       fput(filp);
19688 +
19689 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19690 +               ret = -EFAULT;
19691 +       return ret;
19692 +}
19693 +
19694 +
19695 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19696 +{
19697 +       struct inode *in = de->d_inode;
19698 +       int error = 0, is_proc = 0, has_tag = 0;
19699 +       struct iattr attr = { 0 };
19700 +
19701 +       if (!in || !in->i_sb)
19702 +               return -ESRCH;
19703 +
19704 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19705 +       if ((*mask & IATTR_FLAGS) && !is_proc)
19706 +               return -EINVAL;
19707 +
19708 +       has_tag = IS_TAGGED(in) ||
19709 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
19710 +       if ((*mask & IATTR_TAG) && !has_tag)
19711 +               return -EINVAL;
19712 +
19713 +       mutex_lock(&in->i_mutex);
19714 +       if (*mask & IATTR_TAG) {
19715 +               attr.ia_tag = *tag;
19716 +               attr.ia_valid |= ATTR_TAG;
19717 +       }
19718 +
19719 +       if (*mask & IATTR_FLAGS) {
19720 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
19721 +               unsigned int iflags = PROC_I(in)->vx_flags;
19722 +
19723 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
19724 +                       | (*flags & IATTR_FLAGS);
19725 +               PROC_I(in)->vx_flags = iflags;
19726 +               if (entry)
19727 +                       entry->vx_flags = iflags;
19728 +       }
19729 +
19730 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
19731 +               IATTR_BARRIER | IATTR_COW)) {
19732 +               int iflags = in->i_flags;
19733 +               int vflags = in->i_vflags;
19734 +
19735 +               if (*mask & IATTR_IMMUTABLE) {
19736 +                       if (*flags & IATTR_IMMUTABLE)
19737 +                               iflags |= S_IMMUTABLE;
19738 +                       else
19739 +                               iflags &= ~S_IMMUTABLE;
19740 +               }
19741 +               if (*mask & IATTR_IXUNLINK) {
19742 +                       if (*flags & IATTR_IXUNLINK)
19743 +                               iflags |= S_IXUNLINK;
19744 +                       else
19745 +                               iflags &= ~S_IXUNLINK;
19746 +               }
19747 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
19748 +                       if (*flags & IATTR_BARRIER)
19749 +                               vflags |= V_BARRIER;
19750 +                       else
19751 +                               vflags &= ~V_BARRIER;
19752 +               }
19753 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
19754 +                       if (*flags & IATTR_COW)
19755 +                               vflags |= V_COW;
19756 +                       else
19757 +                               vflags &= ~V_COW;
19758 +               }
19759 +               if (in->i_op && in->i_op->sync_flags) {
19760 +                       error = in->i_op->sync_flags(in, iflags, vflags);
19761 +                       if (error)
19762 +                               goto out;
19763 +               }
19764 +       }
19765 +
19766 +       if (attr.ia_valid) {
19767 +               if (in->i_op && in->i_op->setattr)
19768 +                       error = in->i_op->setattr(de, &attr);
19769 +               else {
19770 +                       error = inode_change_ok(in, &attr);
19771 +                       if (!error) {
19772 +                               setattr_copy(in, &attr);
19773 +                               mark_inode_dirty(in);
19774 +                       }
19775 +               }
19776 +       }
19777 +
19778 +out:
19779 +       mutex_unlock(&in->i_mutex);
19780 +       return error;
19781 +}
19782 +
19783 +int vc_set_iattr(void __user *data)
19784 +{
19785 +       struct path path;
19786 +       struct vcmd_ctx_iattr_v1 vc_data;
19787 +       int ret;
19788 +
19789 +       if (!capable(CAP_LINUX_IMMUTABLE))
19790 +               return -EPERM;
19791 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19792 +               return -EFAULT;
19793 +
19794 +       ret = user_lpath(vc_data.name, &path);
19795 +       if (!ret) {
19796 +               ret = __vc_set_iattr(path.dentry,
19797 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19798 +               path_put(&path);
19799 +       }
19800 +
19801 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19802 +               ret = -EFAULT;
19803 +       return ret;
19804 +}
19805 +
19806 +#ifdef CONFIG_COMPAT
19807 +
19808 +int vc_set_iattr_x32(void __user *data)
19809 +{
19810 +       struct path path;
19811 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
19812 +       int ret;
19813 +
19814 +       if (!capable(CAP_LINUX_IMMUTABLE))
19815 +               return -EPERM;
19816 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19817 +               return -EFAULT;
19818 +
19819 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19820 +       if (!ret) {
19821 +               ret = __vc_set_iattr(path.dentry,
19822 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19823 +               path_put(&path);
19824 +       }
19825 +
19826 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19827 +               ret = -EFAULT;
19828 +       return ret;
19829 +}
19830 +
19831 +#endif /* CONFIG_COMPAT */
19832 +
19833 +int vc_fset_iattr(uint32_t fd, void __user *data)
19834 +{
19835 +       struct file *filp;
19836 +       struct vcmd_ctx_fiattr_v0 vc_data;
19837 +       int ret;
19838 +
19839 +       if (!capable(CAP_LINUX_IMMUTABLE))
19840 +               return -EPERM;
19841 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19842 +               return -EFAULT;
19843 +
19844 +       filp = fget(fd);
19845 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19846 +               return -EBADF;
19847 +
19848 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
19849 +               &vc_data.flags, &vc_data.mask);
19850 +
19851 +       fput(filp);
19852 +
19853 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19854 +               return -EFAULT;
19855 +       return ret;
19856 +}
19857 +
19858 +
19859 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
19860 +
19861 +static match_table_t tokens = {
19862 +       {Opt_notagcheck, "notagcheck"},
19863 +#ifdef CONFIG_PROPAGATE
19864 +       {Opt_notag, "notag"},
19865 +       {Opt_tag, "tag"},
19866 +       {Opt_tagid, "tagid=%u"},
19867 +#endif
19868 +       {Opt_err, NULL}
19869 +};
19870 +
19871 +
19872 +static void __dx_parse_remove(char *string, char *opt)
19873 +{
19874 +       char *p = strstr(string, opt);
19875 +       char *q = p;
19876 +
19877 +       if (p) {
19878 +               while (*q != '\0' && *q != ',')
19879 +                       q++;
19880 +               while (*q)
19881 +                       *p++ = *q++;
19882 +               while (*p)
19883 +                       *p++ = '\0';
19884 +       }
19885 +}
19886 +
19887 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
19888 +                unsigned long *flags)
19889 +{
19890 +       int set = 0;
19891 +       substring_t args[MAX_OPT_ARGS];
19892 +       int token, option = 0;
19893 +       char *s, *p, *opts;
19894 +
19895 +       if (!string)
19896 +               return 0;
19897 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
19898 +       if (!s)
19899 +               return 0;
19900 +
19901 +       opts = s;
19902 +       while ((p = strsep(&opts, ",")) != NULL) {
19903 +               token = match_token(p, tokens, args);
19904 +
19905 +               vxdprintk(VXD_CBIT(tag, 7),
19906 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
19907 +                       p, token, option);
19908 +
19909 +               switch (token) {
19910 +#ifdef CONFIG_PROPAGATE
19911 +               case Opt_tag:
19912 +                       if (tag)
19913 +                               *tag = 0;
19914 +                       if (remove)
19915 +                               __dx_parse_remove(s, "tag");
19916 +                       *mnt_flags |= MNT_TAGID;
19917 +                       set |= MNT_TAGID;
19918 +                       break;
19919 +               case Opt_notag:
19920 +                       if (remove)
19921 +                               __dx_parse_remove(s, "notag");
19922 +                       *mnt_flags |= MNT_NOTAG;
19923 +                       set |= MNT_NOTAG;
19924 +                       break;
19925 +               case Opt_tagid:
19926 +                       if (tag && !match_int(args, &option))
19927 +                               *tag = option;
19928 +                       if (remove)
19929 +                               __dx_parse_remove(s, "tagid");
19930 +                       *mnt_flags |= MNT_TAGID;
19931 +                       set |= MNT_TAGID;
19932 +                       break;
19933 +#endif
19934 +               case Opt_notagcheck:
19935 +                       if (remove)
19936 +                               __dx_parse_remove(s, "notagcheck");
19937 +                       *flags |= MS_NOTAGCHECK;
19938 +                       set |= MS_NOTAGCHECK;
19939 +                       break;
19940 +               }
19941 +       }
19942 +       if (set)
19943 +               strcpy(string, s);
19944 +       kfree(s);
19945 +       return set;
19946 +}
19947 +
19948 +#ifdef CONFIG_PROPAGATE
19949 +
19950 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
19951 +{
19952 +       tag_t new_tag = 0;
19953 +       struct vfsmount *mnt;
19954 +       int propagate;
19955 +
19956 +       if (!nd)
19957 +               return;
19958 +       mnt = nd->path.mnt;
19959 +       if (!mnt)
19960 +               return;
19961 +
19962 +       propagate = (mnt->mnt_flags & MNT_TAGID);
19963 +       if (propagate)
19964 +               new_tag = mnt->mnt_tag;
19965 +
19966 +       vxdprintk(VXD_CBIT(tag, 7),
19967 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
19968 +               inode, inode->i_ino, inode->i_tag,
19969 +               new_tag, (propagate) ? 1 : 0);
19970 +
19971 +       if (propagate)
19972 +               inode->i_tag = new_tag;
19973 +}
19974 +
19975 +#include <linux/module.h>
19976 +
19977 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
19978 +
19979 +#endif /* CONFIG_PROPAGATE */
19980 +
19981 diff -NurpP --minimal linux-2.6.36/kernel/vserver/Kconfig linux-2.6.36-vs2.3.0.36.36/kernel/vserver/Kconfig
19982 --- linux-2.6.36/kernel/vserver/Kconfig 1970-01-01 01:00:00.000000000 +0100
19983 +++ linux-2.6.36-vs2.3.0.36.36/kernel/vserver/Kconfig   2010-10-21 21:49:28.000000000 +0200
19984 @@ -0,0 +1,265 @@
19985 +#
19986 +# Linux VServer configuration
19987 +#
19988 +
19989 +menu "Linux VServer"
19990 +
19991 +config VSERVER_AUTO_LBACK
19992 +       bool    "Automatically Assign Loopback IP"
19993 +       default y
19994 +       help
19995 +         Automatically assign a guest specific loopback
19996 +         IP and add it to the kernel network stack on
19997 +         startup.
19998 +
19999 +config VSERVER_AUTO_SINGLE
20000 +       bool    "Automatic Single IP Special Casing"
20001 +       depends on EXPERIMENTAL
20002 +       default y
20003 +       help
20004 +         This allows network contexts with a single IP to
20005 +         automatically remap 0.0.0.0 bindings to that IP,
20006 +         avoiding further network checks and improving
20007 +         performance.
20008 +
20009 +         (note: such guests do not allow to change the ip
20010 +          on the fly and do not show loopback addresses)
20011 +
20012 +config VSERVER_COWBL
20013 +       bool    "Enable COW Immutable Link Breaking"
20014 +       default y
20015 +       help
20016 +         This enables the COW (Copy-On-Write) link break code.
20017 +         It allows you to treat unified files like normal files
20018 +         when writing to them (which will implicitely break the
20019 +         link and create a copy of the unified file)
20020 +
20021 +config VSERVER_VTIME
20022 +       bool    "Enable Virtualized Guest Time"
20023 +       depends on EXPERIMENTAL
20024 +       default n
20025 +       help
20026 +         This enables per guest time offsets to allow for
20027 +         adjusting the system clock individually per guest.
20028 +         this adds some overhead to the time functions and
20029 +         therefore should not be enabled without good reason.
20030 +
20031 +config VSERVER_DEVICE
20032 +       bool    "Enable Guest Device Mapping"
20033 +       depends on EXPERIMENTAL
20034 +       default n
20035 +       help
20036 +         This enables generic device remapping.
20037 +
20038 +config VSERVER_PROC_SECURE
20039 +       bool    "Enable Proc Security"
20040 +       depends on PROC_FS
20041 +       default y
20042 +       help
20043 +         This configures ProcFS security to initially hide
20044 +         non-process entries for all contexts except the main and
20045 +         spectator context (i.e. for all guests), which is a secure
20046 +         default.
20047 +
20048 +         (note: on 1.2x the entries were visible by default)
20049 +
20050 +config VSERVER_HARDCPU
20051 +       bool    "Enable Hard CPU Limits"
20052 +       default y
20053 +       help
20054 +         Activate the Hard CPU Limits
20055 +
20056 +         This will compile in code that allows the Token Bucket
20057 +         Scheduler to put processes on hold when a context's
20058 +         tokens are depleted (provided that its per-context
20059 +         sched_hard flag is set).
20060 +
20061 +         Processes belonging to that context will not be able
20062 +         to consume CPU resources again until a per-context
20063 +         configured minimum of tokens has been reached.
20064 +
20065 +config VSERVER_IDLETIME
20066 +       bool    "Avoid idle CPUs by skipping Time"
20067 +       depends on VSERVER_HARDCPU
20068 +       default y
20069 +       help
20070 +         This option allows the scheduler to artificially
20071 +         advance time (per cpu) when otherwise the idle
20072 +         task would be scheduled, thus keeping the cpu
20073 +         busy and sharing the available resources among
20074 +         certain contexts.
20075 +
20076 +config VSERVER_IDLELIMIT
20077 +       bool    "Limit the IDLE task"
20078 +       depends on VSERVER_HARDCPU
20079 +       default n
20080 +       help
20081 +         Limit the idle slices, so the the next context
20082 +         will be scheduled as soon as possible.
20083 +
20084 +         This might improve interactivity and latency, but
20085 +         will also marginally increase scheduling overhead.
20086 +
20087 +choice
20088 +       prompt  "Persistent Inode Tagging"
20089 +       default TAGGING_ID24
20090 +       help
20091 +         This adds persistent context information to filesystems
20092 +         mounted with the tagxid option. Tagging is a requirement
20093 +         for per-context disk limits and per-context quota.
20094 +
20095 +
20096 +config TAGGING_NONE
20097 +       bool    "Disabled"
20098 +       help
20099 +         do not store per-context information in inodes.
20100 +
20101 +config TAGGING_UID16
20102 +       bool    "UID16/GID32"
20103 +       help
20104 +         reduces UID to 16 bit, but leaves GID at 32 bit.
20105 +
20106 +config TAGGING_GID16
20107 +       bool    "UID32/GID16"
20108 +       help
20109 +         reduces GID to 16 bit, but leaves UID at 32 bit.
20110 +
20111 +config TAGGING_ID24
20112 +       bool    "UID24/GID24"
20113 +       help
20114 +         uses the upper 8bit from UID and GID for XID tagging
20115 +         which leaves 24bit for UID/GID each, which should be
20116 +         more than sufficient for normal use.
20117 +
20118 +config TAGGING_INTERN
20119 +       bool    "UID32/GID32"
20120 +       help
20121 +         this uses otherwise reserved inode fields in the on
20122 +         disk representation, which limits the use to a few
20123 +         filesystems (currently ext2 and ext3)
20124 +
20125 +endchoice
20126 +
20127 +config TAG_NFSD
20128 +       bool    "Tag NFSD User Auth and Files"
20129 +       default n
20130 +       help
20131 +         Enable this if you do want the in-kernel NFS
20132 +         Server to use the tagging specified above.
20133 +         (will require patched clients too)
20134 +
20135 +config VSERVER_PRIVACY
20136 +       bool    "Honor Privacy Aspects of Guests"
20137 +       default n
20138 +       help
20139 +         When enabled, most context checks will disallow
20140 +         access to structures assigned to a specific context,
20141 +         like ptys or loop devices.
20142 +
20143 +config VSERVER_CONTEXTS
20144 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
20145 +       range 1 65533
20146 +       default "768"   if 64BIT
20147 +       default "256"
20148 +       help
20149 +         This setting will optimize certain data structures
20150 +         and memory allocations according to the expected
20151 +         maximum.
20152 +
20153 +         note: this is not a strict upper limit.
20154 +
20155 +config VSERVER_WARN
20156 +       bool    "VServer Warnings"
20157 +       default y
20158 +       help
20159 +         This enables various runtime warnings, which will
20160 +         notify about potential manipulation attempts or
20161 +         resource shortage. It is generally considered to
20162 +         be a good idea to have that enabled.
20163 +
20164 +config VSERVER_WARN_DEVPTS
20165 +       bool    "VServer DevPTS Warnings"
20166 +       depends on VSERVER_WARN
20167 +       default y
20168 +       help
20169 +         This enables DevPTS related warnings, issued when a
20170 +         process inside a context tries to lookup or access
20171 +         a dynamic pts from the host or a different context.
20172 +
20173 +config VSERVER_DEBUG
20174 +       bool    "VServer Debugging Code"
20175 +       default n
20176 +       help
20177 +         Set this to yes if you want to be able to activate
20178 +         debugging output at runtime. It adds a very small
20179 +         overhead to all vserver related functions and
20180 +         increases the kernel size by about 20k.
20181 +
20182 +config VSERVER_HISTORY
20183 +       bool    "VServer History Tracing"
20184 +       depends on VSERVER_DEBUG
20185 +       default n
20186 +       help
20187 +         Set this to yes if you want to record the history of
20188 +         linux-vserver activities, so they can be replayed in
20189 +         the event of a kernel panic or oops.
20190 +
20191 +config VSERVER_HISTORY_SIZE
20192 +       int     "Per-CPU History Size (32-65536)"
20193 +       depends on VSERVER_HISTORY
20194 +       range 32 65536
20195 +       default 64
20196 +       help
20197 +         This allows you to specify the number of entries in
20198 +         the per-CPU history buffer.
20199 +
20200 +config VSERVER_LEGACY_MEM
20201 +       bool    "Legacy Memory Limits"
20202 +       default n
20203 +       help
20204 +         This provides fake memory limits to keep
20205 +         older tools happy in the face of memory
20206 +         cgroups
20207 +
20208 +choice
20209 +       prompt  "Quotes used in debug and warn messages"
20210 +       default QUOTES_ISO8859
20211 +
20212 +config QUOTES_ISO8859
20213 +       bool    "Extended ASCII (ISO 8859) angle quotes"
20214 +       help
20215 +         This uses the extended ASCII characters \xbb
20216 +         and \xab for quoting file and process names.
20217 +
20218 +config QUOTES_UTF8
20219 +       bool    "UTF-8 angle quotes"
20220 +       help
20221 +         This uses the the UTF-8 sequences for angle
20222 +         quotes to quote file and process names.
20223 +
20224 +config QUOTES_ASCII
20225 +       bool    "ASCII single quotes"
20226 +       help
20227 +         This uses the ASCII single quote character
20228 +         (\x27) to quote file and process names.
20229 +
20230 +endchoice
20231 +
20232 +endmenu
20233 +
20234 +
20235 +config VSERVER
20236 +       bool
20237 +       default y
20238 +       select NAMESPACES
20239 +       select UTS_NS
20240 +       select IPC_NS
20241 +       select USER_NS
20242 +       select SYSVIPC
20243 +
20244 +config VSERVER_SECURITY
20245 +       bool
20246 +       depends on SECURITY
20247 +       default y
20248 +       select SECURITY_CAPABILITIES
20249 +
20250 diff -NurpP --minimal linux-2.6.36/kernel/vserver/limit.c linux-2.6.36-vs2.3.0.36.36/kernel/vserver/limit.c
20251 --- linux-2.6.36/kernel/vserver/limit.c 1970-01-01 01:00:00.000000000 +0100
20252 +++ linux-2.6.36-vs2.3.0.36.36/kernel/vserver/limit.c   2010-10-21 13:09:36.000000000 +0200
20253 @@ -0,0 +1,354 @@
20254 +/*
20255 + *  linux/kernel/vserver/limit.c
20256 + *
20257 + *  Virtual Server: Context Limits
20258 + *
20259 + *  Copyright (C) 2004-2010  Herbert Pötzl
20260 + *
20261 + *  V0.01  broken out from vcontext V0.05
20262 + *  V0.02  changed vcmds to vxi arg
20263 + *  V0.03  added memory cgroup support
20264 + *
20265 + */
20266 +
20267 +#include <linux/sched.h>
20268 +#include <linux/module.h>
20269 +#include <linux/memcontrol.h>
20270 +#include <linux/res_counter.h>
20271 +#include <linux/vs_limit.h>
20272 +#include <linux/vserver/limit.h>
20273 +#include <linux/vserver/limit_cmd.h>
20274 +
20275 +#include <asm/uaccess.h>
20276 +
20277 +
20278 +const char *vlimit_name[NUM_LIMITS] = {
20279 +#ifdef CONFIG_VSERVER_LEGACY_MEM
20280 +       [RLIMIT_RSS]            = "RSS",
20281 +       [RLIMIT_AS]             = "VM",
20282 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
20283 +       [RLIMIT_CPU]            = "CPU",
20284 +       [RLIMIT_NPROC]          = "NPROC",
20285 +       [RLIMIT_NOFILE]         = "NOFILE",
20286 +       [RLIMIT_LOCKS]          = "LOCKS",
20287 +       [RLIMIT_SIGPENDING]     = "SIGP",
20288 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
20289 +
20290 +       [VLIMIT_NSOCK]          = "NSOCK",
20291 +       [VLIMIT_OPENFD]         = "OPENFD",
20292 +       [VLIMIT_SHMEM]          = "SHMEM",
20293 +       [VLIMIT_DENTRY]         = "DENTRY",
20294 +};
20295 +
20296 +EXPORT_SYMBOL_GPL(vlimit_name);
20297 +
20298 +#define MASK_ENTRY(x)  (1 << (x))
20299 +
20300 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
20301 +               /* minimum */
20302 +       0
20303 +       ,       /* softlimit */
20304 +#ifdef CONFIG_VSERVER_LEGACY_MEM
20305 +       MASK_ENTRY( RLIMIT_RSS          ) |
20306 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
20307 +       0
20308 +       ,       /* maximum */
20309 +#ifdef CONFIG_VSERVER_LEGACY_MEM
20310 +       MASK_ENTRY( RLIMIT_RSS          ) |
20311 +       MASK_ENTRY( RLIMIT_AS           ) |
20312 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
20313 +       MASK_ENTRY( RLIMIT_NPROC        ) |
20314 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
20315 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
20316 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
20317 +
20318 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
20319 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
20320 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
20321 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
20322 +       0
20323 +};
20324 +               /* accounting only */
20325 +uint32_t account_mask =
20326 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
20327 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
20328 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
20329 +       0;
20330 +
20331 +
20332 +static int is_valid_vlimit(int id)
20333 +{
20334 +       uint32_t mask = vlimit_mask.minimum |
20335 +               vlimit_mask.softlimit | vlimit_mask.maximum;
20336 +       return mask & (1 << id);
20337 +}
20338 +
20339 +static int is_accounted_vlimit(int id)
20340 +{
20341 +       if (is_valid_vlimit(id))
20342 +               return 1;
20343 +       return account_mask & (1 << id);
20344 +}
20345 +
20346 +
20347 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
20348 +{
20349 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
20350 +       return VX_VLIM(limit);
20351 +}
20352 +
20353 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
20354 +{
20355 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
20356 +       return VX_VLIM(limit);
20357 +}
20358 +
20359 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
20360 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
20361 +{
20362 +       if (!is_valid_vlimit(id))
20363 +               return -EINVAL;
20364 +
20365 +       if (minimum)
20366 +               *minimum = CRLIM_UNSET;
20367 +       if (softlimit)
20368 +               *softlimit = vc_get_soft(vxi, id);
20369 +       if (maximum)
20370 +               *maximum = vc_get_hard(vxi, id);
20371 +       return 0;
20372 +}
20373 +
20374 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
20375 +{
20376 +       struct vcmd_ctx_rlimit_v0 vc_data;
20377 +       int ret;
20378 +
20379 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20380 +               return -EFAULT;
20381 +
20382 +       ret = do_get_rlimit(vxi, vc_data.id,
20383 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
20384 +       if (ret)
20385 +               return ret;
20386 +
20387 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20388 +               return -EFAULT;
20389 +       return 0;
20390 +}
20391 +
20392 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
20393 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
20394 +{
20395 +       if (!is_valid_vlimit(id))
20396 +               return -EINVAL;
20397 +
20398 +       if (maximum != CRLIM_KEEP)
20399 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
20400 +       if (softlimit != CRLIM_KEEP)
20401 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
20402 +
20403 +       /* clamp soft limit */
20404 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
20405 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
20406 +
20407 +       return 0;
20408 +}
20409 +
20410 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
20411 +{
20412 +       struct vcmd_ctx_rlimit_v0 vc_data;
20413 +
20414 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20415 +               return -EFAULT;
20416 +
20417 +       return do_set_rlimit(vxi, vc_data.id,
20418 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
20419 +}
20420 +
20421 +#ifdef CONFIG_IA32_EMULATION
20422 +
20423 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
20424 +{
20425 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
20426 +
20427 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20428 +               return -EFAULT;
20429 +
20430 +       return do_set_rlimit(vxi, vc_data.id,
20431 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
20432 +}
20433 +
20434 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
20435 +{
20436 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
20437 +       int ret;
20438 +
20439 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20440 +               return -EFAULT;
20441 +
20442 +       ret = do_get_rlimit(vxi, vc_data.id,
20443 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
20444 +       if (ret)
20445 +               return ret;
20446 +
20447 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20448 +               return -EFAULT;
20449 +       return 0;
20450 +}
20451 +
20452 +#endif /* CONFIG_IA32_EMULATION */
20453 +
20454 +
20455 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
20456 +{
20457 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
20458 +               return -EFAULT;
20459 +       return 0;
20460 +}
20461 +
20462 +
20463 +static inline void vx_reset_hits(struct _vx_limit *limit)
20464 +{
20465 +       int lim;
20466 +
20467 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20468 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20469 +       }
20470 +}
20471 +
20472 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
20473 +{
20474 +       vx_reset_hits(&vxi->limit);
20475 +       return 0;
20476 +}
20477 +
20478 +static inline void vx_reset_minmax(struct _vx_limit *limit)
20479 +{
20480 +       rlim_t value;
20481 +       int lim;
20482 +
20483 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20484 +               value = __rlim_get(limit, lim);
20485 +               __rlim_rmax(limit, lim) = value;
20486 +               __rlim_rmin(limit, lim) = value;
20487 +       }
20488 +}
20489 +
20490 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
20491 +{
20492 +       vx_reset_minmax(&vxi->limit);
20493 +       return 0;
20494 +}
20495 +
20496 +
20497 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
20498 +{
20499 +       struct vcmd_rlimit_stat_v0 vc_data;
20500 +       struct _vx_limit *limit = &vxi->limit;
20501 +       int id;
20502 +
20503 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20504 +               return -EFAULT;
20505 +
20506 +       id = vc_data.id;
20507 +       if (!is_accounted_vlimit(id))
20508 +               return -EINVAL;
20509 +
20510 +       vx_limit_fixup(limit, id);
20511 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
20512 +       vc_data.value = __rlim_get(limit, id);
20513 +       vc_data.minimum = __rlim_rmin(limit, id);
20514 +       vc_data.maximum = __rlim_rmax(limit, id);
20515 +
20516 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20517 +               return -EFAULT;
20518 +       return 0;
20519 +}
20520 +
20521 +
20522 +void vx_vsi_meminfo(struct sysinfo *val)
20523 +{
20524 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20525 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20526 +       u64 res_limit, res_usage;
20527 +
20528 +       if (!mcg)
20529 +               return;
20530 +
20531 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
20532 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
20533 +
20534 +       if (res_limit != RESOURCE_MAX)
20535 +               val->totalram = (res_limit >> PAGE_SHIFT);
20536 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
20537 +       val->bufferram = 0;
20538 +       val->totalhigh = 0;
20539 +       val->freehigh = 0;
20540 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
20541 +       return;
20542 +}
20543 +
20544 +void vx_vsi_swapinfo(struct sysinfo *val)
20545 +{
20546 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20547 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
20548 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20549 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
20550 +       s64 swap_limit, swap_usage;
20551 +
20552 +       if (!mcg)
20553 +               return;
20554 +
20555 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
20556 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
20557 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
20558 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
20559 +
20560 +       if (res_limit == RESOURCE_MAX)
20561 +               return;
20562 +
20563 +       swap_limit = memsw_limit - res_limit;
20564 +       if (memsw_limit != RESOURCE_MAX)
20565 +               val->totalswap = swap_limit >> PAGE_SHIFT;
20566 +
20567 +       swap_usage = memsw_usage - res_usage;
20568 +       val->freeswap = (swap_usage < swap_limit) ?
20569 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
20570 +#else  /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20571 +       val->totalswap = 0;
20572 +       val->freeswap = 0;
20573 +#endif /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20574 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
20575 +       return;
20576 +}
20577 +
20578 +long vx_vsi_cached(struct sysinfo *val)
20579 +{
20580 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20581 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20582 +
20583 +       return mem_cgroup_stat_read_cache(mcg);
20584 +#else
20585 +       return 0;
20586 +#endif
20587 +}
20588 +
20589 +
20590 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
20591 +{
20592 +       struct vx_info *vxi = mm->mm_vx_info;
20593 +       unsigned long points;
20594 +       rlim_t v, w;
20595 +
20596 +       if (!vxi)
20597 +               return 0;
20598 +
20599 +       points = vxi->vx_badness_bias;
20600 +
20601 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
20602 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
20603 +       points += (v > w) ? (v - w) : 0;
20604 +
20605 +       return points;
20606 +}
20607 +
20608 diff -NurpP --minimal linux-2.6.36/kernel/vserver/limit_init.h linux-2.6.36-vs2.3.0.36.36/kernel/vserver/limit_init.h
20609 --- linux-2.6.36/kernel/vserver/limit_init.h    1970-01-01 01:00:00.000000000 +0100
20610 +++ linux-2.6.36-vs2.3.0.36.36/kernel/vserver/limit_init.h      2010-10-21 13:09:36.000000000 +0200
20611 @@ -0,0 +1,31 @@
20612 +
20613 +
20614 +static inline void vx_info_init_limit(struct _vx_limit *limit)
20615 +{
20616 +       int lim;
20617 +
20618 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20619 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
20620 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
20621 +               __rlim_set(limit, lim, 0);
20622 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20623 +               __rlim_rmin(limit, lim) = 0;
20624 +               __rlim_rmax(limit, lim) = 0;
20625 +       }
20626 +}
20627 +
20628 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
20629 +{
20630 +       rlim_t value;
20631 +       int lim;
20632 +
20633 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20634 +               if ((1 << lim) & VLIM_NOCHECK)
20635 +                       continue;
20636 +               value = __rlim_get(limit, lim);
20637 +               vxwprintk_xid(value,
20638 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
20639 +                       limit, vlimit_name[lim], lim, (long)value);
20640 +       }
20641 +}
20642 +
20643 diff -NurpP --minimal linux-2.6.36/kernel/vserver/limit_proc.h linux-2.6.36-vs2.3.0.36.36/kernel/vserver/limit_proc.h
20644 --- linux-2.6.36/kernel/vserver/limit_proc.h    1970-01-01 01:00:00.000000000 +0100
20645 +++ linux-2.6.36-vs2.3.0.36.36/kernel/vserver/limit_proc.h      2010-10-21 13:09:36.000000000 +0200
20646 @@ -0,0 +1,57 @@
20647 +#ifndef _VX_LIMIT_PROC_H
20648 +#define _VX_LIMIT_PROC_H
20649 +
20650 +#include <linux/vserver/limit_int.h>
20651 +
20652 +
20653 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
20654 +#define VX_LIMIT_TOP   \
20655 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
20656 +
20657 +#define VX_LIMIT_ARG(r)                                \
20658 +       (unsigned long)__rlim_get(limit, r),    \
20659 +       (unsigned long)__rlim_rmin(limit, r),   \
20660 +       (unsigned long)__rlim_rmax(limit, r),   \
20661 +       VX_VLIM(__rlim_soft(limit, r)),         \
20662 +       VX_VLIM(__rlim_hard(limit, r)),         \
20663 +       atomic_read(&__rlim_lhit(limit, r))
20664 +
20665 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
20666 +{
20667 +       vx_limit_fixup(limit, -1);
20668 +       return sprintf(buffer, VX_LIMIT_TOP
20669 +               "PROC"  VX_LIMIT_FMT
20670 +               "VM"    VX_LIMIT_FMT
20671 +               "VML"   VX_LIMIT_FMT
20672 +               "RSS"   VX_LIMIT_FMT
20673 +               "ANON"  VX_LIMIT_FMT
20674 +               "RMAP"  VX_LIMIT_FMT
20675 +               "FILES" VX_LIMIT_FMT
20676 +               "OFD"   VX_LIMIT_FMT
20677 +               "LOCKS" VX_LIMIT_FMT
20678 +               "SOCK"  VX_LIMIT_FMT
20679 +               "MSGQ"  VX_LIMIT_FMT
20680 +               "SHM"   VX_LIMIT_FMT
20681 +               "SEMA"  VX_LIMIT_FMT
20682 +               "SEMS"  VX_LIMIT_FMT
20683 +               "DENT"  VX_LIMIT_FMT,
20684 +               VX_LIMIT_ARG(RLIMIT_NPROC),
20685 +               VX_LIMIT_ARG(RLIMIT_AS),
20686 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
20687 +               VX_LIMIT_ARG(RLIMIT_RSS),
20688 +               VX_LIMIT_ARG(VLIMIT_ANON),
20689 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
20690 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
20691 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
20692 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
20693 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
20694 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
20695 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
20696 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
20697 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
20698 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
20699 +}
20700 +
20701 +#endif /* _VX_LIMIT_PROC_H */
20702 +
20703 +
20704 diff -NurpP --minimal linux-2.6.36/kernel/vserver/Makefile linux-2.6.36-vs2.3.0.36.36/kernel/vserver/Makefile
20705 --- linux-2.6.36/kernel/vserver/Makefile        1970-01-01 01:00:00.000000000 +0100
20706 +++ linux-2.6.36-vs2.3.0.36.36/kernel/vserver/Makefile  2010-10-21 13:09:36.000000000 +0200
20707 @@ -0,0 +1,18 @@
20708 +#
20709 +# Makefile for the Linux vserver routines.
20710 +#
20711 +
20712 +
20713 +obj-y          += vserver.o
20714 +
20715 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
20716 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
20717 +                  dlimit.o tag.o
20718 +
20719 +vserver-$(CONFIG_INET) += inet.o
20720 +vserver-$(CONFIG_PROC_FS) += proc.o
20721 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
20722 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
20723 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
20724 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
20725 +
20726 diff -NurpP --minimal linux-2.6.36/kernel/vserver/network.c linux-2.6.36-vs2.3.0.36.36/kernel/vserver/network.c
20727 --- linux-2.6.36/kernel/vserver/network.c       1970-01-01 01:00:00.000000000 +0100
20728 +++ linux-2.6.36-vs2.3.0.36.36/kernel/vserver/network.c 2010-10-21 13:09:36.000000000 +0200
20729 @@ -0,0 +1,864 @@
20730 +/*
20731 + *  linux/kernel/vserver/network.c
20732 + *
20733 + *  Virtual Server: Network Support
20734 + *
20735 + *  Copyright (C) 2003-2007  Herbert Pötzl
20736 + *
20737 + *  V0.01  broken out from vcontext V0.05
20738 + *  V0.02  cleaned up implementation
20739 + *  V0.03  added equiv nx commands
20740 + *  V0.04  switch to RCU based hash
20741 + *  V0.05  and back to locking again
20742 + *  V0.06  changed vcmds to nxi arg
20743 + *  V0.07  have __create claim() the nxi
20744 + *
20745 + */
20746 +
20747 +#include <linux/err.h>
20748 +#include <linux/slab.h>
20749 +#include <linux/rcupdate.h>
20750 +
20751 +#include <linux/vs_network.h>
20752 +#include <linux/vs_pid.h>
20753 +#include <linux/vserver/network_cmd.h>
20754 +
20755 +
20756 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
20757 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
20758 +
20759 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
20760 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
20761 +
20762 +
20763 +static int __init init_network(void)
20764 +{
20765 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
20766 +               sizeof(struct nx_addr_v4), 0,
20767 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20768 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
20769 +               sizeof(struct nx_addr_v6), 0,
20770 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20771 +       return 0;
20772 +}
20773 +
20774 +
20775 +/*     __alloc_nx_addr_v4()                                    */
20776 +
20777 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
20778 +{
20779 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
20780 +               nx_addr_v4_cachep, GFP_KERNEL);
20781 +
20782 +       if (!IS_ERR(nxa))
20783 +               memset(nxa, 0, sizeof(*nxa));
20784 +       return nxa;
20785 +}
20786 +
20787 +/*     __dealloc_nx_addr_v4()                                  */
20788 +
20789 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
20790 +{
20791 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
20792 +}
20793 +
20794 +/*     __dealloc_nx_addr_v4_all()                              */
20795 +
20796 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
20797 +{
20798 +       while (nxa) {
20799 +               struct nx_addr_v4 *next = nxa->next;
20800 +
20801 +               __dealloc_nx_addr_v4(nxa);
20802 +               nxa = next;
20803 +       }
20804 +}
20805 +
20806 +
20807 +#ifdef CONFIG_IPV6
20808 +
20809 +/*     __alloc_nx_addr_v6()                                    */
20810 +
20811 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
20812 +{
20813 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
20814 +               nx_addr_v6_cachep, GFP_KERNEL);
20815 +
20816 +       if (!IS_ERR(nxa))
20817 +               memset(nxa, 0, sizeof(*nxa));
20818 +       return nxa;
20819 +}
20820 +
20821 +/*     __dealloc_nx_addr_v6()                                  */
20822 +
20823 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
20824 +{
20825 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
20826 +}
20827 +
20828 +/*     __dealloc_nx_addr_v6_all()                              */
20829 +
20830 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
20831 +{
20832 +       while (nxa) {
20833 +               struct nx_addr_v6 *next = nxa->next;
20834 +
20835 +               __dealloc_nx_addr_v6(nxa);
20836 +               nxa = next;
20837 +       }
20838 +}
20839 +
20840 +#endif /* CONFIG_IPV6 */
20841 +
20842 +/*     __alloc_nx_info()
20843 +
20844 +       * allocate an initialized nx_info struct
20845 +       * doesn't make it visible (hash)                        */
20846 +
20847 +static struct nx_info *__alloc_nx_info(nid_t nid)
20848 +{
20849 +       struct nx_info *new = NULL;
20850 +
20851 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
20852 +
20853 +       /* would this benefit from a slab cache? */
20854 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
20855 +       if (!new)
20856 +               return 0;
20857 +
20858 +       memset(new, 0, sizeof(struct nx_info));
20859 +       new->nx_id = nid;
20860 +       INIT_HLIST_NODE(&new->nx_hlist);
20861 +       atomic_set(&new->nx_usecnt, 0);
20862 +       atomic_set(&new->nx_tasks, 0);
20863 +       new->nx_state = 0;
20864 +
20865 +       new->nx_flags = NXF_INIT_SET;
20866 +
20867 +       /* rest of init goes here */
20868 +
20869 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
20870 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
20871 +
20872 +       vxdprintk(VXD_CBIT(nid, 0),
20873 +               "alloc_nx_info(%d) = %p", nid, new);
20874 +       atomic_inc(&nx_global_ctotal);
20875 +       return new;
20876 +}
20877 +
20878 +/*     __dealloc_nx_info()
20879 +
20880 +       * final disposal of nx_info                             */
20881 +
20882 +static void __dealloc_nx_info(struct nx_info *nxi)
20883 +{
20884 +       vxdprintk(VXD_CBIT(nid, 0),
20885 +               "dealloc_nx_info(%p)", nxi);
20886 +
20887 +       nxi->nx_hlist.next = LIST_POISON1;
20888 +       nxi->nx_id = -1;
20889 +
20890 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20891 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20892 +
20893 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
20894 +
20895 +       nxi->nx_state |= NXS_RELEASED;
20896 +       kfree(nxi);
20897 +       atomic_dec(&nx_global_ctotal);
20898 +}
20899 +
20900 +static void __shutdown_nx_info(struct nx_info *nxi)
20901 +{
20902 +       nxi->nx_state |= NXS_SHUTDOWN;
20903 +       vs_net_change(nxi, VSC_NETDOWN);
20904 +}
20905 +
20906 +/*     exported stuff                                          */
20907 +
20908 +void free_nx_info(struct nx_info *nxi)
20909 +{
20910 +       /* context shutdown is mandatory */
20911 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
20912 +
20913 +       /* context must not be hashed */
20914 +       BUG_ON(nxi->nx_state & NXS_HASHED);
20915 +
20916 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20917 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20918 +
20919 +       __dealloc_nx_info(nxi);
20920 +}
20921 +
20922 +
20923 +void __nx_set_lback(struct nx_info *nxi)
20924 +{
20925 +       int nid = nxi->nx_id;
20926 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
20927 +
20928 +       nxi->v4_lback.s_addr = lback;
20929 +}
20930 +
20931 +extern int __nx_inet_add_lback(__be32 addr);
20932 +extern int __nx_inet_del_lback(__be32 addr);
20933 +
20934 +
20935 +/*     hash table for nx_info hash */
20936 +
20937 +#define NX_HASH_SIZE   13
20938 +
20939 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
20940 +
20941 +static spinlock_t nx_info_hash_lock = SPIN_LOCK_UNLOCKED;
20942 +
20943 +
20944 +static inline unsigned int __hashval(nid_t nid)
20945 +{
20946 +       return (nid % NX_HASH_SIZE);
20947 +}
20948 +
20949 +
20950 +
20951 +/*     __hash_nx_info()
20952 +
20953 +       * add the nxi to the global hash table
20954 +       * requires the hash_lock to be held                     */
20955 +
20956 +static inline void __hash_nx_info(struct nx_info *nxi)
20957 +{
20958 +       struct hlist_head *head;
20959 +
20960 +       vxd_assert_lock(&nx_info_hash_lock);
20961 +       vxdprintk(VXD_CBIT(nid, 4),
20962 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
20963 +
20964 +       /* context must not be hashed */
20965 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
20966 +
20967 +       nxi->nx_state |= NXS_HASHED;
20968 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
20969 +       hlist_add_head(&nxi->nx_hlist, head);
20970 +       atomic_inc(&nx_global_cactive);
20971 +}
20972 +
20973 +/*     __unhash_nx_info()
20974 +
20975 +       * remove the nxi from the global hash table
20976 +       * requires the hash_lock to be held                     */
20977 +
20978 +static inline void __unhash_nx_info(struct nx_info *nxi)
20979 +{
20980 +       vxd_assert_lock(&nx_info_hash_lock);
20981 +       vxdprintk(VXD_CBIT(nid, 4),
20982 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
20983 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
20984 +
20985 +       /* context must be hashed */
20986 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
20987 +       /* but without tasks */
20988 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20989 +
20990 +       nxi->nx_state &= ~NXS_HASHED;
20991 +       hlist_del(&nxi->nx_hlist);
20992 +       atomic_dec(&nx_global_cactive);
20993 +}
20994 +
20995 +
20996 +/*     __lookup_nx_info()
20997 +
20998 +       * requires the hash_lock to be held
20999 +       * doesn't increment the nx_refcnt                       */
21000 +
21001 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
21002 +{
21003 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
21004 +       struct hlist_node *pos;
21005 +       struct nx_info *nxi;
21006 +
21007 +       vxd_assert_lock(&nx_info_hash_lock);
21008 +       hlist_for_each(pos, head) {
21009 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
21010 +
21011 +               if (nxi->nx_id == nid)
21012 +                       goto found;
21013 +       }
21014 +       nxi = NULL;
21015 +found:
21016 +       vxdprintk(VXD_CBIT(nid, 0),
21017 +               "__lookup_nx_info(#%u): %p[#%u]",
21018 +               nid, nxi, nxi ? nxi->nx_id : 0);
21019 +       return nxi;
21020 +}
21021 +
21022 +
21023 +/*     __create_nx_info()
21024 +
21025 +       * create the requested context
21026 +       * get(), claim() and hash it                            */
21027 +
21028 +static struct nx_info *__create_nx_info(int id)
21029 +{
21030 +       struct nx_info *new, *nxi = NULL;
21031 +
21032 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
21033 +
21034 +       if (!(new = __alloc_nx_info(id)))
21035 +               return ERR_PTR(-ENOMEM);
21036 +
21037 +       /* required to make dynamic xids unique */
21038 +       spin_lock(&nx_info_hash_lock);
21039 +
21040 +       /* static context requested */
21041 +       if ((nxi = __lookup_nx_info(id))) {
21042 +               vxdprintk(VXD_CBIT(nid, 0),
21043 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
21044 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
21045 +                       nxi = ERR_PTR(-EBUSY);
21046 +               else
21047 +                       nxi = ERR_PTR(-EEXIST);
21048 +               goto out_unlock;
21049 +       }
21050 +       /* new context */
21051 +       vxdprintk(VXD_CBIT(nid, 0),
21052 +               "create_nx_info(%d) = %p (new)", id, new);
21053 +       claim_nx_info(new, NULL);
21054 +       __nx_set_lback(new);
21055 +       __hash_nx_info(get_nx_info(new));
21056 +       nxi = new, new = NULL;
21057 +
21058 +out_unlock:
21059 +       spin_unlock(&nx_info_hash_lock);
21060 +       if (new)
21061 +               __dealloc_nx_info(new);
21062 +       return nxi;
21063 +}
21064 +
21065 +
21066 +
21067 +/*     exported stuff                                          */
21068 +
21069 +
21070 +void unhash_nx_info(struct nx_info *nxi)
21071 +{
21072 +       __shutdown_nx_info(nxi);
21073 +       spin_lock(&nx_info_hash_lock);
21074 +       __unhash_nx_info(nxi);
21075 +       spin_unlock(&nx_info_hash_lock);
21076 +}
21077 +
21078 +/*     lookup_nx_info()
21079 +
21080 +       * search for a nx_info and get() it
21081 +       * negative id means current                             */
21082 +
21083 +struct nx_info *lookup_nx_info(int id)
21084 +{
21085 +       struct nx_info *nxi = NULL;
21086 +
21087 +       if (id < 0) {
21088 +               nxi = get_nx_info(current_nx_info());
21089 +       } else if (id > 1) {
21090 +               spin_lock(&nx_info_hash_lock);
21091 +               nxi = get_nx_info(__lookup_nx_info(id));
21092 +               spin_unlock(&nx_info_hash_lock);
21093 +       }
21094 +       return nxi;
21095 +}
21096 +
21097 +/*     nid_is_hashed()
21098 +
21099 +       * verify that nid is still hashed                       */
21100 +
21101 +int nid_is_hashed(nid_t nid)
21102 +{
21103 +       int hashed;
21104 +
21105 +       spin_lock(&nx_info_hash_lock);
21106 +       hashed = (__lookup_nx_info(nid) != NULL);
21107 +       spin_unlock(&nx_info_hash_lock);
21108 +       return hashed;
21109 +}
21110 +
21111 +
21112 +#ifdef CONFIG_PROC_FS
21113 +
21114 +/*     get_nid_list()
21115 +
21116 +       * get a subset of hashed nids for proc
21117 +       * assumes size is at least one                          */
21118 +
21119 +int get_nid_list(int index, unsigned int *nids, int size)
21120 +{
21121 +       int hindex, nr_nids = 0;
21122 +
21123 +       /* only show current and children */
21124 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
21125 +               if (index > 0)
21126 +                       return 0;
21127 +               nids[nr_nids] = nx_current_nid();
21128 +               return 1;
21129 +       }
21130 +
21131 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
21132 +               struct hlist_head *head = &nx_info_hash[hindex];
21133 +               struct hlist_node *pos;
21134 +
21135 +               spin_lock(&nx_info_hash_lock);
21136 +               hlist_for_each(pos, head) {
21137 +                       struct nx_info *nxi;
21138 +
21139 +                       if (--index > 0)
21140 +                               continue;
21141 +
21142 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
21143 +                       nids[nr_nids] = nxi->nx_id;
21144 +                       if (++nr_nids >= size) {
21145 +                               spin_unlock(&nx_info_hash_lock);
21146 +                               goto out;
21147 +                       }
21148 +               }
21149 +               /* keep the lock time short */
21150 +               spin_unlock(&nx_info_hash_lock);
21151 +       }
21152 +out:
21153 +       return nr_nids;
21154 +}
21155 +#endif
21156 +
21157 +
21158 +/*
21159 + *     migrate task to new network
21160 + *     gets nxi, puts old_nxi on change
21161 + */
21162 +
21163 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
21164 +{
21165 +       struct nx_info *old_nxi;
21166 +       int ret = 0;
21167 +
21168 +       if (!p || !nxi)
21169 +               BUG();
21170 +
21171 +       vxdprintk(VXD_CBIT(nid, 5),
21172 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
21173 +               p, nxi, nxi->nx_id,
21174 +               atomic_read(&nxi->nx_usecnt),
21175 +               atomic_read(&nxi->nx_tasks));
21176 +
21177 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
21178 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
21179 +               return -EACCES;
21180 +
21181 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
21182 +               return -EFAULT;
21183 +
21184 +       /* maybe disallow this completely? */
21185 +       old_nxi = task_get_nx_info(p);
21186 +       if (old_nxi == nxi)
21187 +               goto out;
21188 +
21189 +       task_lock(p);
21190 +       if (old_nxi)
21191 +               clr_nx_info(&p->nx_info);
21192 +       claim_nx_info(nxi, p);
21193 +       set_nx_info(&p->nx_info, nxi);
21194 +       p->nid = nxi->nx_id;
21195 +       task_unlock(p);
21196 +
21197 +       vxdprintk(VXD_CBIT(nid, 5),
21198 +               "moved task %p into nxi:%p[#%d]",
21199 +               p, nxi, nxi->nx_id);
21200 +
21201 +       if (old_nxi)
21202 +               release_nx_info(old_nxi, p);
21203 +       ret = 0;
21204 +out:
21205 +       put_nx_info(old_nxi);
21206 +       return ret;
21207 +}
21208 +
21209 +
21210 +void nx_set_persistent(struct nx_info *nxi)
21211 +{
21212 +       vxdprintk(VXD_CBIT(nid, 6),
21213 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
21214 +
21215 +       get_nx_info(nxi);
21216 +       claim_nx_info(nxi, NULL);
21217 +}
21218 +
21219 +void nx_clear_persistent(struct nx_info *nxi)
21220 +{
21221 +       vxdprintk(VXD_CBIT(nid, 6),
21222 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
21223 +
21224 +       release_nx_info(nxi, NULL);
21225 +       put_nx_info(nxi);
21226 +}
21227 +
21228 +void nx_update_persistent(struct nx_info *nxi)
21229 +{
21230 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
21231 +               nx_set_persistent(nxi);
21232 +       else
21233 +               nx_clear_persistent(nxi);
21234 +}
21235 +
21236 +/* vserver syscall commands below here */
21237 +
21238 +/* taks nid and nx_info functions */
21239 +
21240 +#include <asm/uaccess.h>
21241 +
21242 +
21243 +int vc_task_nid(uint32_t id)
21244 +{
21245 +       nid_t nid;
21246 +
21247 +       if (id) {
21248 +               struct task_struct *tsk;
21249 +
21250 +               read_lock(&tasklist_lock);
21251 +               tsk = find_task_by_real_pid(id);
21252 +               nid = (tsk) ? tsk->nid : -ESRCH;
21253 +               read_unlock(&tasklist_lock);
21254 +       } else
21255 +               nid = nx_current_nid();
21256 +       return nid;
21257 +}
21258 +
21259 +
21260 +int vc_nx_info(struct nx_info *nxi, void __user *data)
21261 +{
21262 +       struct vcmd_nx_info_v0 vc_data;
21263 +
21264 +       vc_data.nid = nxi->nx_id;
21265 +
21266 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21267 +               return -EFAULT;
21268 +       return 0;
21269 +}
21270 +
21271 +
21272 +/* network functions */
21273 +
21274 +int vc_net_create(uint32_t nid, void __user *data)
21275 +{
21276 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
21277 +       struct nx_info *new_nxi;
21278 +       int ret;
21279 +
21280 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21281 +               return -EFAULT;
21282 +
21283 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
21284 +               return -EINVAL;
21285 +
21286 +       new_nxi = __create_nx_info(nid);
21287 +       if (IS_ERR(new_nxi))
21288 +               return PTR_ERR(new_nxi);
21289 +
21290 +       /* initial flags */
21291 +       new_nxi->nx_flags = vc_data.flagword;
21292 +
21293 +       ret = -ENOEXEC;
21294 +       if (vs_net_change(new_nxi, VSC_NETUP))
21295 +               goto out;
21296 +
21297 +       ret = nx_migrate_task(current, new_nxi);
21298 +       if (ret)
21299 +               goto out;
21300 +
21301 +       /* return context id on success */
21302 +       ret = new_nxi->nx_id;
21303 +
21304 +       /* get a reference for persistent contexts */
21305 +       if ((vc_data.flagword & NXF_PERSISTENT))
21306 +               nx_set_persistent(new_nxi);
21307 +out:
21308 +       release_nx_info(new_nxi, NULL);
21309 +       put_nx_info(new_nxi);
21310 +       return ret;
21311 +}
21312 +
21313 +
21314 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
21315 +{
21316 +       return nx_migrate_task(current, nxi);
21317 +}
21318 +
21319 +
21320 +
21321 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
21322 +       uint16_t type, uint16_t flags)
21323 +{
21324 +       struct nx_addr_v4 *nxa = &nxi->v4;
21325 +
21326 +       if (NX_IPV4(nxi)) {
21327 +               /* locate last entry */
21328 +               for (; nxa->next; nxa = nxa->next);
21329 +               nxa->next = __alloc_nx_addr_v4();
21330 +               nxa = nxa->next;
21331 +
21332 +               if (IS_ERR(nxa))
21333 +                       return PTR_ERR(nxa);
21334 +       }
21335 +
21336 +       if (nxi->v4.next)
21337 +               /* remove single ip for ip list */
21338 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
21339 +
21340 +       nxa->ip[0].s_addr = ip;
21341 +       nxa->ip[1].s_addr = ip2;
21342 +       nxa->mask.s_addr = mask;
21343 +       nxa->type = type;
21344 +       nxa->flags = flags;
21345 +       return 0;
21346 +}
21347 +
21348 +
21349 +int vc_net_add(struct nx_info *nxi, void __user *data)
21350 +{
21351 +       struct vcmd_net_addr_v0 vc_data;
21352 +       int index, ret = 0;
21353 +
21354 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21355 +               return -EFAULT;
21356 +
21357 +       switch (vc_data.type) {
21358 +       case NXA_TYPE_IPV4:
21359 +               if ((vc_data.count < 1) || (vc_data.count > 4))
21360 +                       return -EINVAL;
21361 +
21362 +               index = 0;
21363 +               while (index < vc_data.count) {
21364 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
21365 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
21366 +                       if (ret)
21367 +                               return ret;
21368 +                       index++;
21369 +               }
21370 +               ret = index;
21371 +               break;
21372 +
21373 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
21374 +               nxi->v4_bcast = vc_data.ip[0];
21375 +               ret = 1;
21376 +               break;
21377 +
21378 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
21379 +               nxi->v4_lback = vc_data.ip[0];
21380 +               ret = 1;
21381 +               break;
21382 +
21383 +       default:
21384 +               ret = -EINVAL;
21385 +               break;
21386 +       }
21387 +       return ret;
21388 +}
21389 +
21390 +int vc_net_remove(struct nx_info *nxi, void __user *data)
21391 +{
21392 +       struct vcmd_net_addr_v0 vc_data;
21393 +
21394 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21395 +               return -EFAULT;
21396 +
21397 +       switch (vc_data.type) {
21398 +       case NXA_TYPE_ANY:
21399 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
21400 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
21401 +               break;
21402 +
21403 +       default:
21404 +               return -EINVAL;
21405 +       }
21406 +       return 0;
21407 +}
21408 +
21409 +
21410 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
21411 +{
21412 +       struct vcmd_net_addr_ipv4_v1 vc_data;
21413 +
21414 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21415 +               return -EFAULT;
21416 +
21417 +       switch (vc_data.type) {
21418 +       case NXA_TYPE_ADDR:
21419 +       case NXA_TYPE_RANGE:
21420 +       case NXA_TYPE_MASK:
21421 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
21422 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
21423 +
21424 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
21425 +               nxi->v4_bcast = vc_data.ip;
21426 +               break;
21427 +
21428 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
21429 +               nxi->v4_lback = vc_data.ip;
21430 +               break;
21431 +
21432 +       default:
21433 +               return -EINVAL;
21434 +       }
21435 +       return 0;
21436 +}
21437 +
21438 +int vc_net_remove_ipv4(struct nx_info *nxi, void __user *data)
21439 +{
21440 +       struct vcmd_net_addr_ipv4_v1 vc_data;
21441 +
21442 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21443 +               return -EFAULT;
21444 +
21445 +       switch (vc_data.type) {
21446 +/*     case NXA_TYPE_ADDR:
21447 +               break;          */
21448 +
21449 +       case NXA_TYPE_ANY:
21450 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
21451 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
21452 +               break;
21453 +
21454 +       default:
21455 +               return -EINVAL;
21456 +       }
21457 +       return 0;
21458 +}
21459 +
21460 +
21461 +#ifdef CONFIG_IPV6
21462 +
21463 +int do_add_v6_addr(struct nx_info *nxi,
21464 +       struct in6_addr *ip, struct in6_addr *mask,
21465 +       uint32_t prefix, uint16_t type, uint16_t flags)
21466 +{
21467 +       struct nx_addr_v6 *nxa = &nxi->v6;
21468 +
21469 +       if (NX_IPV6(nxi)) {
21470 +               /* locate last entry */
21471 +               for (; nxa->next; nxa = nxa->next);
21472 +               nxa->next = __alloc_nx_addr_v6();
21473 +               nxa = nxa->next;
21474 +
21475 +               if (IS_ERR(nxa))
21476 +                       return PTR_ERR(nxa);
21477 +       }
21478 +
21479 +       nxa->ip = *ip;
21480 +       nxa->mask = *mask;
21481 +       nxa->prefix = prefix;
21482 +       nxa->type = type;
21483 +       nxa->flags = flags;
21484 +       return 0;
21485 +}
21486 +
21487 +
21488 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
21489 +{
21490 +       struct vcmd_net_addr_ipv6_v1 vc_data;
21491 +
21492 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21493 +               return -EFAULT;
21494 +
21495 +       switch (vc_data.type) {
21496 +       case NXA_TYPE_ADDR:
21497 +       case NXA_TYPE_MASK:
21498 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
21499 +                       vc_data.prefix, vc_data.type, vc_data.flags);
21500 +       default:
21501 +               return -EINVAL;
21502 +       }
21503 +       return 0;
21504 +}
21505 +
21506 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
21507 +{
21508 +       struct vcmd_net_addr_ipv6_v1 vc_data;
21509 +
21510 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21511 +               return -EFAULT;
21512 +
21513 +       switch (vc_data.type) {
21514 +       case NXA_TYPE_ANY:
21515 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
21516 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
21517 +               break;
21518 +
21519 +       default:
21520 +               return -EINVAL;
21521 +       }
21522 +       return 0;
21523 +}
21524 +
21525 +#endif /* CONFIG_IPV6 */
21526 +
21527 +
21528 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
21529 +{
21530 +       struct vcmd_net_flags_v0 vc_data;
21531 +
21532 +       vc_data.flagword = nxi->nx_flags;
21533 +
21534 +       /* special STATE flag handling */
21535 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
21536 +
21537 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21538 +               return -EFAULT;
21539 +       return 0;
21540 +}
21541 +
21542 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
21543 +{
21544 +       struct vcmd_net_flags_v0 vc_data;
21545 +       uint64_t mask, trigger;
21546 +
21547 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21548 +               return -EFAULT;
21549 +
21550 +       /* special STATE flag handling */
21551 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
21552 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
21553 +
21554 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
21555 +               vc_data.flagword, mask);
21556 +       if (trigger & NXF_PERSISTENT)
21557 +               nx_update_persistent(nxi);
21558 +
21559 +       return 0;
21560 +}
21561 +
21562 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
21563 +{
21564 +       struct vcmd_net_caps_v0 vc_data;
21565 +
21566 +       vc_data.ncaps = nxi->nx_ncaps;
21567 +       vc_data.cmask = ~0ULL;
21568 +
21569 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21570 +               return -EFAULT;
21571 +       return 0;
21572 +}
21573 +
21574 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
21575 +{
21576 +       struct vcmd_net_caps_v0 vc_data;
21577 +
21578 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21579 +               return -EFAULT;
21580 +
21581 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
21582 +               vc_data.ncaps, vc_data.cmask);
21583 +       return 0;
21584 +}
21585 +
21586 +
21587 +#include <linux/module.h>
21588 +
21589 +module_init(init_network);
21590 +
21591 +EXPORT_SYMBOL_GPL(free_nx_info);
21592 +EXPORT_SYMBOL_GPL(unhash_nx_info);
21593 +
21594 diff -NurpP --minimal linux-2.6.36/kernel/vserver/proc.c linux-2.6.36-vs2.3.0.36.36/kernel/vserver/proc.c
21595 --- linux-2.6.36/kernel/vserver/proc.c  1970-01-01 01:00:00.000000000 +0100
21596 +++ linux-2.6.36-vs2.3.0.36.36/kernel/vserver/proc.c    2010-10-21 13:09:36.000000000 +0200
21597 @@ -0,0 +1,1098 @@
21598 +/*
21599 + *  linux/kernel/vserver/proc.c
21600 + *
21601 + *  Virtual Context Support
21602 + *
21603 + *  Copyright (C) 2003-2007  Herbert Pötzl
21604 + *
21605 + *  V0.01  basic structure
21606 + *  V0.02  adaptation vs1.3.0
21607 + *  V0.03  proc permissions
21608 + *  V0.04  locking/generic
21609 + *  V0.05  next generation procfs
21610 + *  V0.06  inode validation
21611 + *  V0.07  generic rewrite vid
21612 + *  V0.08  remove inode type
21613 + *
21614 + */
21615 +
21616 +#include <linux/proc_fs.h>
21617 +#include <linux/fs_struct.h>
21618 +#include <linux/mount.h>
21619 +#include <asm/unistd.h>
21620 +
21621 +#include <linux/vs_context.h>
21622 +#include <linux/vs_network.h>
21623 +#include <linux/vs_cvirt.h>
21624 +
21625 +#include <linux/in.h>
21626 +#include <linux/inetdevice.h>
21627 +#include <linux/vs_inet.h>
21628 +#include <linux/vs_inet6.h>
21629 +
21630 +#include <linux/vserver/global.h>
21631 +
21632 +#include "cvirt_proc.h"
21633 +#include "cacct_proc.h"
21634 +#include "limit_proc.h"
21635 +#include "sched_proc.h"
21636 +#include "vci_config.h"
21637 +
21638 +
21639 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
21640 +{
21641 +       unsigned __capi;
21642 +
21643 +       CAP_FOR_EACH_U32(__capi) {
21644 +               buffer += sprintf(buffer, "%08x",
21645 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
21646 +       }
21647 +       return buffer;
21648 +}
21649 +
21650 +
21651 +static struct proc_dir_entry *proc_virtual;
21652 +
21653 +static struct proc_dir_entry *proc_virtnet;
21654 +
21655 +
21656 +/* first the actual feeds */
21657 +
21658 +
21659 +static int proc_vci(char *buffer)
21660 +{
21661 +       return sprintf(buffer,
21662 +               "VCIVersion:\t%04x:%04x\n"
21663 +               "VCISyscall:\t%d\n"
21664 +               "VCIKernel:\t%08x\n",
21665 +               VCI_VERSION >> 16,
21666 +               VCI_VERSION & 0xFFFF,
21667 +               __NR_vserver,
21668 +               vci_kernel_config());
21669 +}
21670 +
21671 +static int proc_virtual_info(char *buffer)
21672 +{
21673 +       return proc_vci(buffer);
21674 +}
21675 +
21676 +static int proc_virtual_status(char *buffer)
21677 +{
21678 +       return sprintf(buffer,
21679 +               "#CTotal:\t%d\n"
21680 +               "#CActive:\t%d\n"
21681 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
21682 +               "#InitTask:\t%d\t%d %d\n",
21683 +               atomic_read(&vx_global_ctotal),
21684 +               atomic_read(&vx_global_cactive),
21685 +               atomic_read(&vs_global_nsproxy),
21686 +               atomic_read(&vs_global_fs),
21687 +               atomic_read(&vs_global_mnt_ns),
21688 +               atomic_read(&vs_global_uts_ns),
21689 +               atomic_read(&nr_ipc_ns),
21690 +               atomic_read(&vs_global_user_ns),
21691 +               atomic_read(&vs_global_pid_ns),
21692 +               atomic_read(&init_task.usage),
21693 +               atomic_read(&init_task.nsproxy->count),
21694 +               init_task.fs->users);
21695 +}
21696 +
21697 +
21698 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
21699 +{
21700 +       int length;
21701 +
21702 +       length = sprintf(buffer,
21703 +               "ID:\t%d\n"
21704 +               "Info:\t%p\n"
21705 +               "Init:\t%d\n"
21706 +               "OOM:\t%lld\n",
21707 +               vxi->vx_id,
21708 +               vxi,
21709 +               vxi->vx_initpid,
21710 +               vxi->vx_badness_bias);
21711 +       return length;
21712 +}
21713 +
21714 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
21715 +{
21716 +       char *orig = buffer;
21717 +
21718 +       buffer += sprintf(buffer,
21719 +               "UseCnt:\t%d\n"
21720 +               "Tasks:\t%d\n"
21721 +               "Flags:\t%016llx\n",
21722 +               atomic_read(&vxi->vx_usecnt),
21723 +               atomic_read(&vxi->vx_tasks),
21724 +               (unsigned long long)vxi->vx_flags);
21725 +
21726 +       buffer += sprintf(buffer, "BCaps:\t");
21727 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21728 +       buffer += sprintf(buffer, "\n");
21729 +
21730 +       buffer += sprintf(buffer,
21731 +               "CCaps:\t%016llx\n"
21732 +               "Spaces:\t%08lx %08lx\n",
21733 +               (unsigned long long)vxi->vx_ccaps,
21734 +               vxi->vx_nsmask[0], vxi->vx_nsmask[1]);
21735 +       return buffer - orig;
21736 +}
21737 +
21738 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
21739 +{
21740 +       return vx_info_proc_limit(&vxi->limit, buffer);
21741 +}
21742 +
21743 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
21744 +{
21745 +       int cpu, length;
21746 +
21747 +       length = vx_info_proc_sched(&vxi->sched, buffer);
21748 +       for_each_online_cpu(cpu) {
21749 +               length += vx_info_proc_sched_pc(
21750 +                       &vx_per_cpu(vxi, sched_pc, cpu),
21751 +                       buffer + length, cpu);
21752 +       }
21753 +       return length;
21754 +}
21755 +
21756 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
21757 +{
21758 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[0], buffer);
21759 +}
21760 +
21761 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
21762 +{
21763 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[1], buffer);
21764 +}
21765 +
21766 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
21767 +{
21768 +       int cpu, length;
21769 +
21770 +       vx_update_load(vxi);
21771 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
21772 +       for_each_online_cpu(cpu) {
21773 +               length += vx_info_proc_cvirt_pc(
21774 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
21775 +                       buffer + length, cpu);
21776 +       }
21777 +       return length;
21778 +}
21779 +
21780 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
21781 +{
21782 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
21783 +}
21784 +
21785 +
21786 +static int proc_virtnet_info(char *buffer)
21787 +{
21788 +       return proc_vci(buffer);
21789 +}
21790 +
21791 +static int proc_virtnet_status(char *buffer)
21792 +{
21793 +       return sprintf(buffer,
21794 +               "#CTotal:\t%d\n"
21795 +               "#CActive:\t%d\n",
21796 +               atomic_read(&nx_global_ctotal),
21797 +               atomic_read(&nx_global_cactive));
21798 +}
21799 +
21800 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
21801 +{
21802 +       struct nx_addr_v4 *v4a;
21803 +#ifdef CONFIG_IPV6
21804 +       struct nx_addr_v6 *v6a;
21805 +#endif
21806 +       int length, i;
21807 +
21808 +       length = sprintf(buffer,
21809 +               "ID:\t%d\n"
21810 +               "Info:\t%p\n"
21811 +               "Bcast:\t" NIPQUAD_FMT "\n"
21812 +               "Lback:\t" NIPQUAD_FMT "\n",
21813 +               nxi->nx_id,
21814 +               nxi,
21815 +               NIPQUAD(nxi->v4_bcast.s_addr),
21816 +               NIPQUAD(nxi->v4_lback.s_addr));
21817 +
21818 +       if (!NX_IPV4(nxi))
21819 +               goto skip_v4;
21820 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21821 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
21822 +                       i, NXAV4(v4a));
21823 +skip_v4:
21824 +#ifdef CONFIG_IPV6
21825 +       if (!NX_IPV6(nxi))
21826 +               goto skip_v6;
21827 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21828 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
21829 +                       i, NXAV6(v6a));
21830 +skip_v6:
21831 +#endif
21832 +       return length;
21833 +}
21834 +
21835 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
21836 +{
21837 +       int length;
21838 +
21839 +       length = sprintf(buffer,
21840 +               "UseCnt:\t%d\n"
21841 +               "Tasks:\t%d\n"
21842 +               "Flags:\t%016llx\n"
21843 +               "NCaps:\t%016llx\n",
21844 +               atomic_read(&nxi->nx_usecnt),
21845 +               atomic_read(&nxi->nx_tasks),
21846 +               (unsigned long long)nxi->nx_flags,
21847 +               (unsigned long long)nxi->nx_ncaps);
21848 +       return length;
21849 +}
21850 +
21851 +
21852 +
21853 +/* here the inode helpers */
21854 +
21855 +struct vs_entry {
21856 +       int len;
21857 +       char *name;
21858 +       mode_t mode;
21859 +       struct inode_operations *iop;
21860 +       struct file_operations *fop;
21861 +       union proc_op op;
21862 +};
21863 +
21864 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
21865 +{
21866 +       struct inode *inode = new_inode(sb);
21867 +
21868 +       if (!inode)
21869 +               goto out;
21870 +
21871 +       inode->i_mode = p->mode;
21872 +       if (p->iop)
21873 +               inode->i_op = p->iop;
21874 +       if (p->fop)
21875 +               inode->i_fop = p->fop;
21876 +
21877 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
21878 +       inode->i_flags |= S_IMMUTABLE;
21879 +
21880 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
21881 +
21882 +       inode->i_uid = 0;
21883 +       inode->i_gid = 0;
21884 +       inode->i_tag = 0;
21885 +out:
21886 +       return inode;
21887 +}
21888 +
21889 +static struct dentry *vs_proc_instantiate(struct inode *dir,
21890 +       struct dentry *dentry, int id, void *ptr)
21891 +{
21892 +       struct vs_entry *p = ptr;
21893 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
21894 +       struct dentry *error = ERR_PTR(-EINVAL);
21895 +
21896 +       if (!inode)
21897 +               goto out;
21898 +
21899 +       PROC_I(inode)->op = p->op;
21900 +       PROC_I(inode)->fd = id;
21901 +       d_add(dentry, inode);
21902 +       error = NULL;
21903 +out:
21904 +       return error;
21905 +}
21906 +
21907 +/* Lookups */
21908 +
21909 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
21910 +
21911 +/*
21912 + * Fill a directory entry.
21913 + *
21914 + * If possible create the dcache entry and derive our inode number and
21915 + * file type from dcache entry.
21916 + *
21917 + * Since all of the proc inode numbers are dynamically generated, the inode
21918 + * numbers do not exist until the inode is cache.  This means creating the
21919 + * the dcache entry in readdir is necessary to keep the inode numbers
21920 + * reported by readdir in sync with the inode numbers reported
21921 + * by stat.
21922 + */
21923 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
21924 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
21925 +{
21926 +       struct dentry *child, *dir = filp->f_dentry;
21927 +       struct inode *inode;
21928 +       struct qstr qname;
21929 +       ino_t ino = 0;
21930 +       unsigned type = DT_UNKNOWN;
21931 +
21932 +       qname.name = name;
21933 +       qname.len  = len;
21934 +       qname.hash = full_name_hash(name, len);
21935 +
21936 +       child = d_lookup(dir, &qname);
21937 +       if (!child) {
21938 +               struct dentry *new;
21939 +               new = d_alloc(dir, &qname);
21940 +               if (new) {
21941 +                       child = instantiate(dir->d_inode, new, id, ptr);
21942 +                       if (child)
21943 +                               dput(new);
21944 +                       else
21945 +                               child = new;
21946 +               }
21947 +       }
21948 +       if (!child || IS_ERR(child) || !child->d_inode)
21949 +               goto end_instantiate;
21950 +       inode = child->d_inode;
21951 +       if (inode) {
21952 +               ino = inode->i_ino;
21953 +               type = inode->i_mode >> 12;
21954 +       }
21955 +       dput(child);
21956 +end_instantiate:
21957 +       if (!ino)
21958 +               ino = find_inode_number(dir, &qname);
21959 +       if (!ino)
21960 +               ino = 1;
21961 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
21962 +}
21963 +
21964 +
21965 +
21966 +/* get and revalidate vx_info/xid */
21967 +
21968 +static inline
21969 +struct vx_info *get_proc_vx_info(struct inode *inode)
21970 +{
21971 +       return lookup_vx_info(PROC_I(inode)->fd);
21972 +}
21973 +
21974 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
21975 +{
21976 +       struct inode *inode = dentry->d_inode;
21977 +       xid_t xid = PROC_I(inode)->fd;
21978 +
21979 +       if (!xid || xid_is_hashed(xid))
21980 +               return 1;
21981 +       d_drop(dentry);
21982 +       return 0;
21983 +}
21984 +
21985 +
21986 +/* get and revalidate nx_info/nid */
21987 +
21988 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
21989 +{
21990 +       struct inode *inode = dentry->d_inode;
21991 +       nid_t nid = PROC_I(inode)->fd;
21992 +
21993 +       if (!nid || nid_is_hashed(nid))
21994 +               return 1;
21995 +       d_drop(dentry);
21996 +       return 0;
21997 +}
21998 +
21999 +
22000 +
22001 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
22002 +
22003 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
22004 +                         size_t count, loff_t *ppos)
22005 +{
22006 +       struct inode *inode = file->f_dentry->d_inode;
22007 +       unsigned long page;
22008 +       ssize_t length = 0;
22009 +
22010 +       if (count > PROC_BLOCK_SIZE)
22011 +               count = PROC_BLOCK_SIZE;
22012 +
22013 +       /* fade that out as soon as stable */
22014 +       WARN_ON(PROC_I(inode)->fd);
22015 +
22016 +       if (!(page = __get_free_page(GFP_KERNEL)))
22017 +               return -ENOMEM;
22018 +
22019 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
22020 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
22021 +
22022 +       if (length >= 0)
22023 +               length = simple_read_from_buffer(buf, count, ppos,
22024 +                       (char *)page, length);
22025 +
22026 +       free_page(page);
22027 +       return length;
22028 +}
22029 +
22030 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
22031 +                         size_t count, loff_t *ppos)
22032 +{
22033 +       struct inode *inode = file->f_dentry->d_inode;
22034 +       struct vx_info *vxi = NULL;
22035 +       xid_t xid = PROC_I(inode)->fd;
22036 +       unsigned long page;
22037 +       ssize_t length = 0;
22038 +
22039 +       if (count > PROC_BLOCK_SIZE)
22040 +               count = PROC_BLOCK_SIZE;
22041 +
22042 +       /* fade that out as soon as stable */
22043 +       WARN_ON(!xid);
22044 +       vxi = lookup_vx_info(xid);
22045 +       if (!vxi)
22046 +               goto out;
22047 +
22048 +       length = -ENOMEM;
22049 +       if (!(page = __get_free_page(GFP_KERNEL)))
22050 +               goto out_put;
22051 +
22052 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
22053 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
22054 +
22055 +       if (length >= 0)
22056 +               length = simple_read_from_buffer(buf, count, ppos,
22057 +                       (char *)page, length);
22058 +
22059 +       free_page(page);
22060 +out_put:
22061 +       put_vx_info(vxi);
22062 +out:
22063 +       return length;
22064 +}
22065 +
22066 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
22067 +                         size_t count, loff_t *ppos)
22068 +{
22069 +       struct inode *inode = file->f_dentry->d_inode;
22070 +       struct nx_info *nxi = NULL;
22071 +       nid_t nid = PROC_I(inode)->fd;
22072 +       unsigned long page;
22073 +       ssize_t length = 0;
22074 +
22075 +       if (count > PROC_BLOCK_SIZE)
22076 +               count = PROC_BLOCK_SIZE;
22077 +
22078 +       /* fade that out as soon as stable */
22079 +       WARN_ON(!nid);
22080 +       nxi = lookup_nx_info(nid);
22081 +       if (!nxi)
22082 +               goto out;
22083 +
22084 +       length = -ENOMEM;
22085 +       if (!(page = __get_free_page(GFP_KERNEL)))
22086 +               goto out_put;
22087 +
22088 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
22089 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
22090 +
22091 +       if (length >= 0)
22092 +               length = simple_read_from_buffer(buf, count, ppos,
22093 +                       (char *)page, length);
22094 +
22095 +       free_page(page);
22096 +out_put:
22097 +       put_nx_info(nxi);
22098 +out:
22099 +       return length;
22100 +}
22101 +
22102 +
22103 +
22104 +/* here comes the lower level */
22105 +
22106 +
22107 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
22108 +       .len  = sizeof(NAME) - 1,       \
22109 +       .name = (NAME),                 \
22110 +       .mode = MODE,                   \
22111 +       .iop  = IOP,                    \
22112 +       .fop  = FOP,                    \
22113 +       .op   = OP,                     \
22114 +}
22115 +
22116 +
22117 +#define DIR(NAME, MODE, OTYPE)                         \
22118 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
22119 +               &proc_ ## OTYPE ## _inode_operations,   \
22120 +               &proc_ ## OTYPE ## _file_operations, { } )
22121 +
22122 +#define INF(NAME, MODE, OTYPE)                         \
22123 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
22124 +               &proc_vs_info_file_operations,          \
22125 +               { .proc_vs_read = &proc_##OTYPE } )
22126 +
22127 +#define VINF(NAME, MODE, OTYPE)                                \
22128 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
22129 +               &proc_vx_info_file_operations,          \
22130 +               { .proc_vxi_read = &proc_##OTYPE } )
22131 +
22132 +#define NINF(NAME, MODE, OTYPE)                                \
22133 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
22134 +               &proc_nx_info_file_operations,          \
22135 +               { .proc_nxi_read = &proc_##OTYPE } )
22136 +
22137 +
22138 +static struct file_operations proc_vs_info_file_operations = {
22139 +       .read =         proc_vs_info_read,
22140 +};
22141 +
22142 +static struct file_operations proc_vx_info_file_operations = {
22143 +       .read =         proc_vx_info_read,
22144 +};
22145 +
22146 +static struct dentry_operations proc_xid_dentry_operations = {
22147 +       .d_revalidate = proc_xid_revalidate,
22148 +};
22149 +
22150 +static struct vs_entry vx_base_stuff[] = {
22151 +       VINF("info",    S_IRUGO, vxi_info),
22152 +       VINF("status",  S_IRUGO, vxi_status),
22153 +       VINF("limit",   S_IRUGO, vxi_limit),
22154 +       VINF("sched",   S_IRUGO, vxi_sched),
22155 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
22156 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
22157 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
22158 +       VINF("cacct",   S_IRUGO, vxi_cacct),
22159 +       {}
22160 +};
22161 +
22162 +
22163 +
22164 +
22165 +static struct dentry *proc_xid_instantiate(struct inode *dir,
22166 +       struct dentry *dentry, int id, void *ptr)
22167 +{
22168 +       dentry->d_op = &proc_xid_dentry_operations;
22169 +       return vs_proc_instantiate(dir, dentry, id, ptr);
22170 +}
22171 +
22172 +static struct dentry *proc_xid_lookup(struct inode *dir,
22173 +       struct dentry *dentry, struct nameidata *nd)
22174 +{
22175 +       struct vs_entry *p = vx_base_stuff;
22176 +       struct dentry *error = ERR_PTR(-ENOENT);
22177 +
22178 +       for (; p->name; p++) {
22179 +               if (p->len != dentry->d_name.len)
22180 +                       continue;
22181 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22182 +                       break;
22183 +       }
22184 +       if (!p->name)
22185 +               goto out;
22186 +
22187 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
22188 +out:
22189 +       return error;
22190 +}
22191 +
22192 +static int proc_xid_readdir(struct file *filp,
22193 +       void *dirent, filldir_t filldir)
22194 +{
22195 +       struct dentry *dentry = filp->f_dentry;
22196 +       struct inode *inode = dentry->d_inode;
22197 +       struct vs_entry *p = vx_base_stuff;
22198 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
22199 +       int pos, index;
22200 +       u64 ino;
22201 +
22202 +       pos = filp->f_pos;
22203 +       switch (pos) {
22204 +       case 0:
22205 +               ino = inode->i_ino;
22206 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22207 +                       goto out;
22208 +               pos++;
22209 +               /* fall through */
22210 +       case 1:
22211 +               ino = parent_ino(dentry);
22212 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22213 +                       goto out;
22214 +               pos++;
22215 +               /* fall through */
22216 +       default:
22217 +               index = pos - 2;
22218 +               if (index >= size)
22219 +                       goto out;
22220 +               for (p += index; p->name; p++) {
22221 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22222 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
22223 +                               goto out;
22224 +                       pos++;
22225 +               }
22226 +       }
22227 +out:
22228 +       filp->f_pos = pos;
22229 +       return 1;
22230 +}
22231 +
22232 +
22233 +
22234 +static struct file_operations proc_nx_info_file_operations = {
22235 +       .read =         proc_nx_info_read,
22236 +};
22237 +
22238 +static struct dentry_operations proc_nid_dentry_operations = {
22239 +       .d_revalidate = proc_nid_revalidate,
22240 +};
22241 +
22242 +static struct vs_entry nx_base_stuff[] = {
22243 +       NINF("info",    S_IRUGO, nxi_info),
22244 +       NINF("status",  S_IRUGO, nxi_status),
22245 +       {}
22246 +};
22247 +
22248 +
22249 +static struct dentry *proc_nid_instantiate(struct inode *dir,
22250 +       struct dentry *dentry, int id, void *ptr)
22251 +{
22252 +       dentry->d_op = &proc_nid_dentry_operations;
22253 +       return vs_proc_instantiate(dir, dentry, id, ptr);
22254 +}
22255 +
22256 +static struct dentry *proc_nid_lookup(struct inode *dir,
22257 +       struct dentry *dentry, struct nameidata *nd)
22258 +{
22259 +       struct vs_entry *p = nx_base_stuff;
22260 +       struct dentry *error = ERR_PTR(-ENOENT);
22261 +
22262 +       for (; p->name; p++) {
22263 +               if (p->len != dentry->d_name.len)
22264 +                       continue;
22265 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22266 +                       break;
22267 +       }
22268 +       if (!p->name)
22269 +               goto out;
22270 +
22271 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
22272 +out:
22273 +       return error;
22274 +}
22275 +
22276 +static int proc_nid_readdir(struct file *filp,
22277 +       void *dirent, filldir_t filldir)
22278 +{
22279 +       struct dentry *dentry = filp->f_dentry;
22280 +       struct inode *inode = dentry->d_inode;
22281 +       struct vs_entry *p = nx_base_stuff;
22282 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
22283 +       int pos, index;
22284 +       u64 ino;
22285 +
22286 +       pos = filp->f_pos;
22287 +       switch (pos) {
22288 +       case 0:
22289 +               ino = inode->i_ino;
22290 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22291 +                       goto out;
22292 +               pos++;
22293 +               /* fall through */
22294 +       case 1:
22295 +               ino = parent_ino(dentry);
22296 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22297 +                       goto out;
22298 +               pos++;
22299 +               /* fall through */
22300 +       default:
22301 +               index = pos - 2;
22302 +               if (index >= size)
22303 +                       goto out;
22304 +               for (p += index; p->name; p++) {
22305 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22306 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
22307 +                               goto out;
22308 +                       pos++;
22309 +               }
22310 +       }
22311 +out:
22312 +       filp->f_pos = pos;
22313 +       return 1;
22314 +}
22315 +
22316 +
22317 +#define MAX_MULBY10    ((~0U - 9) / 10)
22318 +
22319 +static inline int atovid(const char *str, int len)
22320 +{
22321 +       int vid, c;
22322 +
22323 +       vid = 0;
22324 +       while (len-- > 0) {
22325 +               c = *str - '0';
22326 +               str++;
22327 +               if (c > 9)
22328 +                       return -1;
22329 +               if (vid >= MAX_MULBY10)
22330 +                       return -1;
22331 +               vid *= 10;
22332 +               vid += c;
22333 +               if (!vid)
22334 +                       return -1;
22335 +       }
22336 +       return vid;
22337 +}
22338 +
22339 +/* now the upper level (virtual) */
22340 +
22341 +
22342 +static struct file_operations proc_xid_file_operations = {
22343 +       .read =         generic_read_dir,
22344 +       .readdir =      proc_xid_readdir,
22345 +};
22346 +
22347 +static struct inode_operations proc_xid_inode_operations = {
22348 +       .lookup =       proc_xid_lookup,
22349 +};
22350 +
22351 +static struct vs_entry vx_virtual_stuff[] = {
22352 +       INF("info",     S_IRUGO, virtual_info),
22353 +       INF("status",   S_IRUGO, virtual_status),
22354 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
22355 +};
22356 +
22357 +
22358 +static struct dentry *proc_virtual_lookup(struct inode *dir,
22359 +       struct dentry *dentry, struct nameidata *nd)
22360 +{
22361 +       struct vs_entry *p = vx_virtual_stuff;
22362 +       struct dentry *error = ERR_PTR(-ENOENT);
22363 +       int id = 0;
22364 +
22365 +       for (; p->name; p++) {
22366 +               if (p->len != dentry->d_name.len)
22367 +                       continue;
22368 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22369 +                       break;
22370 +       }
22371 +       if (p->name)
22372 +               goto instantiate;
22373 +
22374 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
22375 +       if ((id < 0) || !xid_is_hashed(id))
22376 +               goto out;
22377 +
22378 +instantiate:
22379 +       error = proc_xid_instantiate(dir, dentry, id, p);
22380 +out:
22381 +       return error;
22382 +}
22383 +
22384 +static struct file_operations proc_nid_file_operations = {
22385 +       .read =         generic_read_dir,
22386 +       .readdir =      proc_nid_readdir,
22387 +};
22388 +
22389 +static struct inode_operations proc_nid_inode_operations = {
22390 +       .lookup =       proc_nid_lookup,
22391 +};
22392 +
22393 +static struct vs_entry nx_virtnet_stuff[] = {
22394 +       INF("info",     S_IRUGO, virtnet_info),
22395 +       INF("status",   S_IRUGO, virtnet_status),
22396 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
22397 +};
22398 +
22399 +
22400 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
22401 +       struct dentry *dentry, struct nameidata *nd)
22402 +{
22403 +       struct vs_entry *p = nx_virtnet_stuff;
22404 +       struct dentry *error = ERR_PTR(-ENOENT);
22405 +       int id = 0;
22406 +
22407 +       for (; p->name; p++) {
22408 +               if (p->len != dentry->d_name.len)
22409 +                       continue;
22410 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22411 +                       break;
22412 +       }
22413 +       if (p->name)
22414 +               goto instantiate;
22415 +
22416 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
22417 +       if ((id < 0) || !nid_is_hashed(id))
22418 +               goto out;
22419 +
22420 +instantiate:
22421 +       error = proc_nid_instantiate(dir, dentry, id, p);
22422 +out:
22423 +       return error;
22424 +}
22425 +
22426 +
22427 +#define PROC_MAXVIDS 32
22428 +
22429 +int proc_virtual_readdir(struct file *filp,
22430 +       void *dirent, filldir_t filldir)
22431 +{
22432 +       struct dentry *dentry = filp->f_dentry;
22433 +       struct inode *inode = dentry->d_inode;
22434 +       struct vs_entry *p = vx_virtual_stuff;
22435 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
22436 +       int pos, index;
22437 +       unsigned int xid_array[PROC_MAXVIDS];
22438 +       char buf[PROC_NUMBUF];
22439 +       unsigned int nr_xids, i;
22440 +       u64 ino;
22441 +
22442 +       pos = filp->f_pos;
22443 +       switch (pos) {
22444 +       case 0:
22445 +               ino = inode->i_ino;
22446 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22447 +                       goto out;
22448 +               pos++;
22449 +               /* fall through */
22450 +       case 1:
22451 +               ino = parent_ino(dentry);
22452 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22453 +                       goto out;
22454 +               pos++;
22455 +               /* fall through */
22456 +       default:
22457 +               index = pos - 2;
22458 +               if (index >= size)
22459 +                       goto entries;
22460 +               for (p += index; p->name; p++) {
22461 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22462 +                               vs_proc_instantiate, 0, p))
22463 +                               goto out;
22464 +                       pos++;
22465 +               }
22466 +       entries:
22467 +               index = pos - size;
22468 +               p = &vx_virtual_stuff[size - 1];
22469 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
22470 +               for (i = 0; i < nr_xids; i++) {
22471 +                       int n, xid = xid_array[i];
22472 +                       unsigned int j = PROC_NUMBUF;
22473 +
22474 +                       n = xid;
22475 +                       do
22476 +                               buf[--j] = '0' + (n % 10);
22477 +                       while (n /= 10);
22478 +
22479 +                       if (proc_fill_cache(filp, dirent, filldir,
22480 +                               buf + j, PROC_NUMBUF - j,
22481 +                               vs_proc_instantiate, xid, p))
22482 +                               goto out;
22483 +                       pos++;
22484 +               }
22485 +       }
22486 +out:
22487 +       filp->f_pos = pos;
22488 +       return 0;
22489 +}
22490 +
22491 +static int proc_virtual_getattr(struct vfsmount *mnt,
22492 +       struct dentry *dentry, struct kstat *stat)
22493 +{
22494 +       struct inode *inode = dentry->d_inode;
22495 +
22496 +       generic_fillattr(inode, stat);
22497 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
22498 +       return 0;
22499 +}
22500 +
22501 +static struct file_operations proc_virtual_dir_operations = {
22502 +       .read =         generic_read_dir,
22503 +       .readdir =      proc_virtual_readdir,
22504 +};
22505 +
22506 +static struct inode_operations proc_virtual_dir_inode_operations = {
22507 +       .getattr =      proc_virtual_getattr,
22508 +       .lookup =       proc_virtual_lookup,
22509 +};
22510 +
22511 +
22512 +
22513 +
22514 +
22515 +int proc_virtnet_readdir(struct file *filp,
22516 +       void *dirent, filldir_t filldir)
22517 +{
22518 +       struct dentry *dentry = filp->f_dentry;
22519 +       struct inode *inode = dentry->d_inode;
22520 +       struct vs_entry *p = nx_virtnet_stuff;
22521 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
22522 +       int pos, index;
22523 +       unsigned int nid_array[PROC_MAXVIDS];
22524 +       char buf[PROC_NUMBUF];
22525 +       unsigned int nr_nids, i;
22526 +       u64 ino;
22527 +
22528 +       pos = filp->f_pos;
22529 +       switch (pos) {
22530 +       case 0:
22531 +               ino = inode->i_ino;
22532 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22533 +                       goto out;
22534 +               pos++;
22535 +               /* fall through */
22536 +       case 1:
22537 +               ino = parent_ino(dentry);
22538 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22539 +                       goto out;
22540 +               pos++;
22541 +               /* fall through */
22542 +       default:
22543 +               index = pos - 2;
22544 +               if (index >= size)
22545 +                       goto entries;
22546 +               for (p += index; p->name; p++) {
22547 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22548 +                               vs_proc_instantiate, 0, p))
22549 +                               goto out;
22550 +                       pos++;
22551 +               }
22552 +       entries:
22553 +               index = pos - size;
22554 +               p = &nx_virtnet_stuff[size - 1];
22555 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
22556 +               for (i = 0; i < nr_nids; i++) {
22557 +                       int n, nid = nid_array[i];
22558 +                       unsigned int j = PROC_NUMBUF;
22559 +
22560 +                       n = nid;
22561 +                       do
22562 +                               buf[--j] = '0' + (n % 10);
22563 +                       while (n /= 10);
22564 +
22565 +                       if (proc_fill_cache(filp, dirent, filldir,
22566 +                               buf + j, PROC_NUMBUF - j,
22567 +                               vs_proc_instantiate, nid, p))
22568 +                               goto out;
22569 +                       pos++;
22570 +               }
22571 +       }
22572 +out:
22573 +       filp->f_pos = pos;
22574 +       return 0;
22575 +}
22576 +
22577 +static int proc_virtnet_getattr(struct vfsmount *mnt,
22578 +       struct dentry *dentry, struct kstat *stat)
22579 +{
22580 +       struct inode *inode = dentry->d_inode;
22581 +
22582 +       generic_fillattr(inode, stat);
22583 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
22584 +       return 0;
22585 +}
22586 +
22587 +static struct file_operations proc_virtnet_dir_operations = {
22588 +       .read =         generic_read_dir,
22589 +       .readdir =      proc_virtnet_readdir,
22590 +};
22591 +
22592 +static struct inode_operations proc_virtnet_dir_inode_operations = {
22593 +       .getattr =      proc_virtnet_getattr,
22594 +       .lookup =       proc_virtnet_lookup,
22595 +};
22596 +
22597 +
22598 +
22599 +void proc_vx_init(void)
22600 +{
22601 +       struct proc_dir_entry *ent;
22602 +
22603 +       ent = proc_mkdir("virtual", 0);
22604 +       if (ent) {
22605 +               ent->proc_fops = &proc_virtual_dir_operations;
22606 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
22607 +       }
22608 +       proc_virtual = ent;
22609 +
22610 +       ent = proc_mkdir("virtnet", 0);
22611 +       if (ent) {
22612 +               ent->proc_fops = &proc_virtnet_dir_operations;
22613 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
22614 +       }
22615 +       proc_virtnet = ent;
22616 +}
22617 +
22618 +
22619 +
22620 +
22621 +/* per pid info */
22622 +
22623 +
22624 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
22625 +{
22626 +       struct vx_info *vxi;
22627 +       char *orig = buffer;
22628 +
22629 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
22630 +
22631 +       vxi = task_get_vx_info(p);
22632 +       if (!vxi)
22633 +               goto out;
22634 +
22635 +       buffer += sprintf(buffer, "BCaps:\t");
22636 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
22637 +       buffer += sprintf(buffer, "\n");
22638 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
22639 +               (unsigned long long)vxi->vx_ccaps);
22640 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
22641 +               (unsigned long long)vxi->vx_flags);
22642 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
22643 +
22644 +       put_vx_info(vxi);
22645 +out:
22646 +       return buffer - orig;
22647 +}
22648 +
22649 +
22650 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
22651 +{
22652 +       struct nx_info *nxi;
22653 +       struct nx_addr_v4 *v4a;
22654 +#ifdef CONFIG_IPV6
22655 +       struct nx_addr_v6 *v6a;
22656 +#endif
22657 +       char *orig = buffer;
22658 +       int i;
22659 +
22660 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
22661 +
22662 +       nxi = task_get_nx_info(p);
22663 +       if (!nxi)
22664 +               goto out;
22665 +
22666 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
22667 +               (unsigned long long)nxi->nx_ncaps);
22668 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
22669 +               (unsigned long long)nxi->nx_flags);
22670 +
22671 +       buffer += sprintf(buffer,
22672 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
22673 +               NIPQUAD(nxi->v4_bcast.s_addr));
22674 +       buffer += sprintf (buffer,
22675 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
22676 +               NIPQUAD(nxi->v4_lback.s_addr));
22677 +       if (!NX_IPV4(nxi))
22678 +               goto skip_v4;
22679 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22680 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
22681 +                       i, NXAV4(v4a));
22682 +skip_v4:
22683 +#ifdef CONFIG_IPV6
22684 +       if (!NX_IPV6(nxi))
22685 +               goto skip_v6;
22686 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22687 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
22688 +                       i, NXAV6(v6a));
22689 +skip_v6:
22690 +#endif
22691 +       put_nx_info(nxi);
22692 +out:
22693 +       return buffer - orig;
22694 +}
22695 +
22696 diff -NurpP --minimal linux-2.6.36/kernel/vserver/sched.c linux-2.6.36-vs2.3.0.36.36/kernel/vserver/sched.c
22697 --- linux-2.6.36/kernel/vserver/sched.c 1970-01-01 01:00:00.000000000 +0100
22698 +++ linux-2.6.36-vs2.3.0.36.36/kernel/vserver/sched.c   2010-10-21 13:09:36.000000000 +0200
22699 @@ -0,0 +1,414 @@
22700 +/*
22701 + *  linux/kernel/vserver/sched.c
22702 + *
22703 + *  Virtual Server: Scheduler Support
22704 + *
22705 + *  Copyright (C) 2004-2007  Herbert Pötzl
22706 + *
22707 + *  V0.01  adapted Sam Vilains version to 2.6.3
22708 + *  V0.02  removed legacy interface
22709 + *  V0.03  changed vcmds to vxi arg
22710 + *  V0.04  removed older and legacy interfaces
22711 + *
22712 + */
22713 +
22714 +#include <linux/vs_context.h>
22715 +#include <linux/vs_sched.h>
22716 +#include <linux/vserver/sched_cmd.h>
22717 +
22718 +#include <asm/uaccess.h>
22719 +
22720 +
22721 +#define vxd_check_range(val, min, max) do {            \
22722 +       vxlprintk((val < min) || (val > max),           \
22723 +               "check_range(%ld,%ld,%ld)",             \
22724 +               (long)val, (long)min, (long)max,        \
22725 +               __FILE__, __LINE__);                    \
22726 +       } while (0)
22727 +
22728 +
22729 +void vx_update_sched_param(struct _vx_sched *sched,
22730 +       struct _vx_sched_pc *sched_pc)
22731 +{
22732 +       unsigned int set_mask = sched->update_mask;
22733 +
22734 +       if (set_mask & VXSM_FILL_RATE)
22735 +               sched_pc->fill_rate[0] = sched->fill_rate[0];
22736 +       if (set_mask & VXSM_INTERVAL)
22737 +               sched_pc->interval[0] = sched->interval[0];
22738 +       if (set_mask & VXSM_FILL_RATE2)
22739 +               sched_pc->fill_rate[1] = sched->fill_rate[1];
22740 +       if (set_mask & VXSM_INTERVAL2)
22741 +               sched_pc->interval[1] = sched->interval[1];
22742 +       if (set_mask & VXSM_TOKENS)
22743 +               sched_pc->tokens = sched->tokens;
22744 +       if (set_mask & VXSM_TOKENS_MIN)
22745 +               sched_pc->tokens_min = sched->tokens_min;
22746 +       if (set_mask & VXSM_TOKENS_MAX)
22747 +               sched_pc->tokens_max = sched->tokens_max;
22748 +       if (set_mask & VXSM_PRIO_BIAS)
22749 +               sched_pc->prio_bias = sched->prio_bias;
22750 +
22751 +       if (set_mask & VXSM_IDLE_TIME)
22752 +               sched_pc->flags |= VXSF_IDLE_TIME;
22753 +       else
22754 +               sched_pc->flags &= ~VXSF_IDLE_TIME;
22755 +
22756 +       /* reset time */
22757 +       sched_pc->norm_time = jiffies;
22758 +}
22759 +
22760 +
22761 +/*
22762 + * recalculate the context's scheduling tokens
22763 + *
22764 + * ret > 0 : number of tokens available
22765 + * ret < 0 : on hold, check delta_min[]
22766 + *          -1 only jiffies
22767 + *          -2 also idle time
22768 + *
22769 + */
22770 +int vx_tokens_recalc(struct _vx_sched_pc *sched_pc,
22771 +       unsigned long *norm_time, unsigned long *idle_time, int delta_min[2])
22772 +{
22773 +       long delta;
22774 +       long tokens = 0;
22775 +       int flags = sched_pc->flags;
22776 +
22777 +       /* how much time did pass? */
22778 +       delta = *norm_time - sched_pc->norm_time;
22779 +       // printk("@ %ld, %ld, %ld\n", *norm_time, sched_pc->norm_time, jiffies);
22780 +       vxd_check_range(delta, 0, INT_MAX);
22781 +
22782 +       if (delta >= sched_pc->interval[0]) {
22783 +               long tokens, integral;
22784 +
22785 +               /* calc integral token part */
22786 +               tokens = delta / sched_pc->interval[0];
22787 +               integral = tokens * sched_pc->interval[0];
22788 +               tokens *= sched_pc->fill_rate[0];
22789 +#ifdef CONFIG_VSERVER_HARDCPU
22790 +               delta_min[0] = delta - integral;
22791 +               vxd_check_range(delta_min[0], 0, sched_pc->interval[0]);
22792 +#endif
22793 +               /* advance time */
22794 +               sched_pc->norm_time += delta;
22795 +
22796 +               /* add tokens */
22797 +               sched_pc->tokens += tokens;
22798 +               sched_pc->token_time += tokens;
22799 +       } else
22800 +               delta_min[0] = delta;
22801 +
22802 +#ifdef CONFIG_VSERVER_IDLETIME
22803 +       if (!(flags & VXSF_IDLE_TIME))
22804 +               goto skip_idle;
22805 +
22806 +       /* how much was the idle skip? */
22807 +       delta = *idle_time - sched_pc->idle_time;
22808 +       vxd_check_range(delta, 0, INT_MAX);
22809 +
22810 +       if (delta >= sched_pc->interval[1]) {
22811 +               long tokens, integral;
22812 +
22813 +               /* calc fair share token part */
22814 +               tokens = delta / sched_pc->interval[1];
22815 +               integral = tokens * sched_pc->interval[1];
22816 +               tokens *= sched_pc->fill_rate[1];
22817 +               delta_min[1] = delta - integral;
22818 +               vxd_check_range(delta_min[1], 0, sched_pc->interval[1]);
22819 +
22820 +               /* advance idle time */
22821 +               sched_pc->idle_time += integral;
22822 +
22823 +               /* add tokens */
22824 +               sched_pc->tokens += tokens;
22825 +               sched_pc->token_time += tokens;
22826 +       } else
22827 +               delta_min[1] = delta;
22828 +skip_idle:
22829 +#endif
22830 +
22831 +       /* clip at maximum */
22832 +       if (sched_pc->tokens > sched_pc->tokens_max)
22833 +               sched_pc->tokens = sched_pc->tokens_max;
22834 +       tokens = sched_pc->tokens;
22835 +
22836 +       if ((flags & VXSF_ONHOLD)) {
22837 +               /* can we unhold? */
22838 +               if (tokens >= sched_pc->tokens_min) {
22839 +                       flags &= ~VXSF_ONHOLD;
22840 +                       sched_pc->hold_ticks +=
22841 +                               *norm_time - sched_pc->onhold;
22842 +               } else
22843 +                       goto on_hold;
22844 +       } else {
22845 +               /* put on hold? */
22846 +               if (tokens <= 0) {
22847 +                       flags |= VXSF_ONHOLD;
22848 +                       sched_pc->onhold = *norm_time;
22849 +                       goto on_hold;
22850 +               }
22851 +       }
22852 +       sched_pc->flags = flags;
22853 +       return tokens;
22854 +
22855 +on_hold:
22856 +       tokens = sched_pc->tokens_min - tokens;
22857 +       sched_pc->flags = flags;
22858 +       // BUG_ON(tokens < 0); probably doesn't hold anymore
22859 +
22860 +#ifdef CONFIG_VSERVER_HARDCPU
22861 +       /* next interval? */
22862 +       if (!sched_pc->fill_rate[0])
22863 +               delta_min[0] = HZ;
22864 +       else if (tokens > sched_pc->fill_rate[0])
22865 +               delta_min[0] += sched_pc->interval[0] *
22866 +                       tokens / sched_pc->fill_rate[0];
22867 +       else
22868 +               delta_min[0] = sched_pc->interval[0] - delta_min[0];
22869 +       vxd_check_range(delta_min[0], 0, INT_MAX);
22870 +
22871 +#ifdef CONFIG_VSERVER_IDLETIME
22872 +       if (!(flags & VXSF_IDLE_TIME))
22873 +               return -1;
22874 +
22875 +       /* next interval? */
22876 +       if (!sched_pc->fill_rate[1])
22877 +               delta_min[1] = HZ;
22878 +       else if (tokens > sched_pc->fill_rate[1])
22879 +               delta_min[1] += sched_pc->interval[1] *
22880 +                       tokens / sched_pc->fill_rate[1];
22881 +       else
22882 +               delta_min[1] = sched_pc->interval[1] - delta_min[1];
22883 +       vxd_check_range(delta_min[1], 0, INT_MAX);
22884 +
22885 +       return -2;
22886 +#else
22887 +       return -1;
22888 +#endif /* CONFIG_VSERVER_IDLETIME */
22889 +#else
22890 +       return 0;
22891 +#endif /* CONFIG_VSERVER_HARDCPU */
22892 +}
22893 +
22894 +static inline unsigned long msec_to_ticks(unsigned long msec)
22895 +{
22896 +       return msecs_to_jiffies(msec);
22897 +}
22898 +
22899 +static inline unsigned long ticks_to_msec(unsigned long ticks)
22900 +{
22901 +       return jiffies_to_msecs(ticks);
22902 +}
22903 +
22904 +static inline unsigned long ticks_to_usec(unsigned long ticks)
22905 +{
22906 +       return jiffies_to_usecs(ticks);
22907 +}
22908 +
22909 +
22910 +static int do_set_sched(struct vx_info *vxi, struct vcmd_sched_v5 *data)
22911 +{
22912 +       unsigned int set_mask = data->mask;
22913 +       unsigned int update_mask;
22914 +       int i, cpu;
22915 +
22916 +       /* Sanity check data values */
22917 +       if (data->tokens_max <= 0)
22918 +               data->tokens_max = HZ;
22919 +       if (data->tokens_min < 0)
22920 +               data->tokens_min = HZ / 3;
22921 +       if (data->tokens_min >= data->tokens_max)
22922 +               data->tokens_min = data->tokens_max;
22923 +
22924 +       if (data->prio_bias > MAX_PRIO_BIAS)
22925 +               data->prio_bias = MAX_PRIO_BIAS;
22926 +       if (data->prio_bias < MIN_PRIO_BIAS)
22927 +               data->prio_bias = MIN_PRIO_BIAS;
22928 +
22929 +       spin_lock(&vxi->sched.tokens_lock);
22930 +
22931 +       /* sync up on delayed updates */
22932 +       for_each_cpu_mask(cpu, vxi->sched.update)
22933 +               vx_update_sched_param(&vxi->sched,
22934 +                       &vx_per_cpu(vxi, sched_pc, cpu));
22935 +
22936 +       if (set_mask & VXSM_FILL_RATE)
22937 +               vxi->sched.fill_rate[0] = data->fill_rate[0];
22938 +       if (set_mask & VXSM_FILL_RATE2)
22939 +               vxi->sched.fill_rate[1] = data->fill_rate[1];
22940 +       if (set_mask & VXSM_INTERVAL)
22941 +               vxi->sched.interval[0] = (set_mask & VXSM_MSEC) ?
22942 +                       msec_to_ticks(data->interval[0]) : data->interval[0];
22943 +       if (set_mask & VXSM_INTERVAL2)
22944 +               vxi->sched.interval[1] = (set_mask & VXSM_MSEC) ?
22945 +                       msec_to_ticks(data->interval[1]) : data->interval[1];
22946 +       if (set_mask & VXSM_TOKENS)
22947 +               vxi->sched.tokens = data->tokens;
22948 +       if (set_mask & VXSM_TOKENS_MIN)
22949 +               vxi->sched.tokens_min = data->tokens_min;
22950 +       if (set_mask & VXSM_TOKENS_MAX)
22951 +               vxi->sched.tokens_max = data->tokens_max;
22952 +       if (set_mask & VXSM_PRIO_BIAS)
22953 +               vxi->sched.prio_bias = data->prio_bias;
22954 +
22955 +       /* Sanity check rate/interval */
22956 +       for (i = 0; i < 2; i++) {
22957 +               if (data->fill_rate[i] < 0)
22958 +                       data->fill_rate[i] = 0;
22959 +               if (data->interval[i] <= 0)
22960 +                       data->interval[i] = HZ;
22961 +       }
22962 +
22963 +       update_mask = vxi->sched.update_mask & VXSM_SET_MASK;
22964 +       update_mask |= (set_mask & (VXSM_SET_MASK | VXSM_IDLE_TIME));
22965 +       vxi->sched.update_mask = update_mask;
22966 +
22967 +#ifdef CONFIG_SMP
22968 +       rmb();
22969 +       if (set_mask & VXSM_CPU_ID) {
22970 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
22971 +               cpus_and(vxi->sched.update, cpu_online_map,
22972 +                       vxi->sched.update);
22973 +       } else
22974 +               vxi->sched.update = cpu_online_map;
22975 +
22976 +       /* forced reload? */
22977 +       if (set_mask & VXSM_FORCE) {
22978 +               for_each_cpu_mask(cpu, vxi->sched.update)
22979 +                       vx_update_sched_param(&vxi->sched,
22980 +                               &vx_per_cpu(vxi, sched_pc, cpu));
22981 +               vxi->sched.update = CPU_MASK_NONE;
22982 +       }
22983 +#else
22984 +       /* on UP we update immediately */
22985 +       vx_update_sched_param(&vxi->sched,
22986 +               &vx_per_cpu(vxi, sched_pc, 0));
22987 +#endif
22988 +
22989 +       spin_unlock(&vxi->sched.tokens_lock);
22990 +       return 0;
22991 +}
22992 +
22993 +
22994 +#define COPY_IDS(C) C(cpu_id); C(bucket_id)
22995 +#define COPY_PRI(C) C(prio_bias)
22996 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
22997 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);   \
22998 +                   C(fill_rate[1]); C(interval[1]);
22999 +
23000 +#define COPY_VALUE(name) vc_data.name = data->name
23001 +
23002 +static int do_set_sched_v4(struct vx_info *vxi, struct vcmd_set_sched_v4 *data)
23003 +{
23004 +       struct vcmd_sched_v5 vc_data;
23005 +
23006 +       vc_data.mask = data->set_mask;
23007 +       COPY_IDS(COPY_VALUE);
23008 +       COPY_PRI(COPY_VALUE);
23009 +       COPY_TOK(COPY_VALUE);
23010 +       vc_data.fill_rate[0] = vc_data.fill_rate[1] = data->fill_rate;
23011 +       vc_data.interval[0] = vc_data.interval[1] = data->interval;
23012 +       return do_set_sched(vxi, &vc_data);
23013 +}
23014 +
23015 +int vc_set_sched_v4(struct vx_info *vxi, void __user *data)
23016 +{
23017 +       struct vcmd_set_sched_v4 vc_data;
23018 +
23019 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23020 +               return -EFAULT;
23021 +
23022 +       return do_set_sched_v4(vxi, &vc_data);
23023 +}
23024 +
23025 +       /* latest interface is v5 */
23026 +
23027 +int vc_set_sched(struct vx_info *vxi, void __user *data)
23028 +{
23029 +       struct vcmd_sched_v5 vc_data;
23030 +
23031 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23032 +               return -EFAULT;
23033 +
23034 +       return do_set_sched(vxi, &vc_data);
23035 +}
23036 +
23037 +
23038 +#define COPY_PRI(C) C(prio_bias)
23039 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
23040 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);    \
23041 +                   C(fill_rate[1]); C(interval[1]);
23042 +
23043 +#define COPY_VALUE(name) vc_data.name = data->name
23044 +
23045 +
23046 +int vc_get_sched(struct vx_info *vxi, void __user *data)
23047 +{
23048 +       struct vcmd_sched_v5 vc_data;
23049 +
23050 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23051 +               return -EFAULT;
23052 +
23053 +       if (vc_data.mask & VXSM_CPU_ID) {
23054 +               int cpu = vc_data.cpu_id;
23055 +               struct _vx_sched_pc *data;
23056 +
23057 +               if (!cpu_possible(cpu))
23058 +                       return -EINVAL;
23059 +
23060 +               data = &vx_per_cpu(vxi, sched_pc, cpu);
23061 +               COPY_TOK(COPY_VALUE);
23062 +               COPY_PRI(COPY_VALUE);
23063 +               COPY_FRI(COPY_VALUE);
23064 +
23065 +               if (data->flags & VXSF_IDLE_TIME)
23066 +                       vc_data.mask |= VXSM_IDLE_TIME;
23067 +       } else {
23068 +               struct _vx_sched *data = &vxi->sched;
23069 +
23070 +               COPY_TOK(COPY_VALUE);
23071 +               COPY_PRI(COPY_VALUE);
23072 +               COPY_FRI(COPY_VALUE);
23073 +       }
23074 +
23075 +       if (vc_data.mask & VXSM_MSEC) {
23076 +               vc_data.interval[0] = ticks_to_msec(vc_data.interval[0]);
23077 +               vc_data.interval[1] = ticks_to_msec(vc_data.interval[1]);
23078 +       }
23079 +
23080 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23081 +               return -EFAULT;
23082 +       return 0;
23083 +}
23084 +
23085 +
23086 +int vc_sched_info(struct vx_info *vxi, void __user *data)
23087 +{
23088 +       struct vcmd_sched_info vc_data;
23089 +       int cpu;
23090 +
23091 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23092 +               return -EFAULT;
23093 +
23094 +       cpu = vc_data.cpu_id;
23095 +       if (!cpu_possible(cpu))
23096 +               return -EINVAL;
23097 +
23098 +       if (vxi) {
23099 +               struct _vx_sched_pc *sched_pc =
23100 +                       &vx_per_cpu(vxi, sched_pc, cpu);
23101 +
23102 +               vc_data.user_msec = ticks_to_msec(sched_pc->user_ticks);
23103 +               vc_data.sys_msec = ticks_to_msec(sched_pc->sys_ticks);
23104 +               vc_data.hold_msec = ticks_to_msec(sched_pc->hold_ticks);
23105 +               vc_data.vavavoom = sched_pc->vavavoom;
23106 +       }
23107 +       vc_data.token_usec = ticks_to_usec(1);
23108 +
23109 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23110 +               return -EFAULT;
23111 +       return 0;
23112 +}
23113 +
23114 diff -NurpP --minimal linux-2.6.36/kernel/vserver/sched_init.h linux-2.6.36-vs2.3.0.36.36/kernel/vserver/sched_init.h
23115 --- linux-2.6.36/kernel/vserver/sched_init.h    1970-01-01 01:00:00.000000000 +0100
23116 +++ linux-2.6.36-vs2.3.0.36.36/kernel/vserver/sched_init.h      2010-10-21 13:09:36.000000000 +0200
23117 @@ -0,0 +1,50 @@
23118 +
23119 +static inline void vx_info_init_sched(struct _vx_sched *sched)
23120 +{
23121 +       static struct lock_class_key tokens_lock_key;
23122 +
23123 +       /* scheduling; hard code starting values as constants */
23124 +       sched->fill_rate[0]     = 1;
23125 +       sched->interval[0]      = 4;
23126 +       sched->fill_rate[1]     = 1;
23127 +       sched->interval[1]      = 8;
23128 +       sched->tokens           = HZ >> 2;
23129 +       sched->tokens_min       = HZ >> 4;
23130 +       sched->tokens_max       = HZ >> 1;
23131 +       sched->tokens_lock      = SPIN_LOCK_UNLOCKED;
23132 +       sched->prio_bias        = 0;
23133 +
23134 +       lockdep_set_class(&sched->tokens_lock, &tokens_lock_key);
23135 +}
23136 +
23137 +static inline
23138 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
23139 +{
23140 +       sched_pc->fill_rate[0]  = 1;
23141 +       sched_pc->interval[0]   = 4;
23142 +       sched_pc->fill_rate[1]  = 1;
23143 +       sched_pc->interval[1]   = 8;
23144 +       sched_pc->tokens        = HZ >> 2;
23145 +       sched_pc->tokens_min    = HZ >> 4;
23146 +       sched_pc->tokens_max    = HZ >> 1;
23147 +       sched_pc->prio_bias     = 0;
23148 +       sched_pc->vavavoom      = 0;
23149 +       sched_pc->token_time    = 0;
23150 +       sched_pc->idle_time     = 0;
23151 +       sched_pc->norm_time     = jiffies;
23152 +
23153 +       sched_pc->user_ticks = 0;
23154 +       sched_pc->sys_ticks = 0;
23155 +       sched_pc->hold_ticks = 0;
23156 +}
23157 +
23158 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
23159 +{
23160 +       return;
23161 +}
23162 +
23163 +static inline
23164 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
23165 +{
23166 +       return;
23167 +}
23168 diff -NurpP --minimal linux-2.6.36/kernel/vserver/sched_proc.h linux-2.6.36-vs2.3.0.36.36/kernel/vserver/sched_proc.h
23169 --- linux-2.6.36/kernel/vserver/sched_proc.h    1970-01-01 01:00:00.000000000 +0100
23170 +++ linux-2.6.36-vs2.3.0.36.36/kernel/vserver/sched_proc.h      2010-10-21 13:09:36.000000000 +0200
23171 @@ -0,0 +1,57 @@
23172 +#ifndef _VX_SCHED_PROC_H
23173 +#define _VX_SCHED_PROC_H
23174 +
23175 +
23176 +static inline
23177 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
23178 +{
23179 +       int length = 0;
23180 +
23181 +       length += sprintf(buffer,
23182 +               "FillRate:\t%8d,%d\n"
23183 +               "Interval:\t%8d,%d\n"
23184 +               "TokensMin:\t%8d\n"
23185 +               "TokensMax:\t%8d\n"
23186 +               "PrioBias:\t%8d\n",
23187 +               sched->fill_rate[0],
23188 +               sched->fill_rate[1],
23189 +               sched->interval[0],
23190 +               sched->interval[1],
23191 +               sched->tokens_min,
23192 +               sched->tokens_max,
23193 +               sched->prio_bias);
23194 +       return length;
23195 +}
23196 +
23197 +static inline
23198 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
23199 +       char *buffer, int cpu)
23200 +{
23201 +       int length = 0;
23202 +
23203 +       length += sprintf(buffer + length,
23204 +               "cpu %d: %lld %lld %lld %ld %ld", cpu,
23205 +               (unsigned long long)sched_pc->user_ticks,
23206 +               (unsigned long long)sched_pc->sys_ticks,
23207 +               (unsigned long long)sched_pc->hold_ticks,
23208 +               sched_pc->token_time,
23209 +               sched_pc->idle_time);
23210 +       length += sprintf(buffer + length,
23211 +               " %c%c %d %d %d %d/%d %d/%d",
23212 +               (sched_pc->flags & VXSF_ONHOLD) ? 'H' : 'R',
23213 +               (sched_pc->flags & VXSF_IDLE_TIME) ? 'I' : '-',
23214 +               sched_pc->tokens,
23215 +               sched_pc->tokens_min,
23216 +               sched_pc->tokens_max,
23217 +               sched_pc->fill_rate[0],
23218 +               sched_pc->interval[0],
23219 +               sched_pc->fill_rate[1],
23220 +               sched_pc->interval[1]);
23221 +       length += sprintf(buffer + length,
23222 +               " %d %d\n",
23223 +               sched_pc->prio_bias,
23224 +               sched_pc->vavavoom);
23225 +       return length;
23226 +}
23227 +
23228 +#endif /* _VX_SCHED_PROC_H */
23229 diff -NurpP --minimal linux-2.6.36/kernel/vserver/signal.c linux-2.6.36-vs2.3.0.36.36/kernel/vserver/signal.c
23230 --- linux-2.6.36/kernel/vserver/signal.c        1970-01-01 01:00:00.000000000 +0100
23231 +++ linux-2.6.36-vs2.3.0.36.36/kernel/vserver/signal.c  2010-10-21 13:09:36.000000000 +0200
23232 @@ -0,0 +1,132 @@
23233 +/*
23234 + *  linux/kernel/vserver/signal.c
23235 + *
23236 + *  Virtual Server: Signal Support
23237 + *
23238 + *  Copyright (C) 2003-2007  Herbert Pötzl
23239 + *
23240 + *  V0.01  broken out from vcontext V0.05
23241 + *  V0.02  changed vcmds to vxi arg
23242 + *  V0.03  adjusted siginfo for kill
23243 + *
23244 + */
23245 +
23246 +#include <asm/uaccess.h>
23247 +
23248 +#include <linux/vs_context.h>
23249 +#include <linux/vs_pid.h>
23250 +#include <linux/vserver/signal_cmd.h>
23251 +
23252 +
23253 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
23254 +{
23255 +       int retval, count = 0;
23256 +       struct task_struct *p;
23257 +       struct siginfo *sip = SEND_SIG_PRIV;
23258 +
23259 +       retval = -ESRCH;
23260 +       vxdprintk(VXD_CBIT(misc, 4),
23261 +               "vx_info_kill(%p[#%d],%d,%d)*",
23262 +               vxi, vxi->vx_id, pid, sig);
23263 +       read_lock(&tasklist_lock);
23264 +       switch (pid) {
23265 +       case  0:
23266 +       case -1:
23267 +               for_each_process(p) {
23268 +                       int err = 0;
23269 +
23270 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
23271 +                               (pid && vxi->vx_initpid == p->pid))
23272 +                               continue;
23273 +
23274 +                       err = group_send_sig_info(sig, sip, p);
23275 +                       ++count;
23276 +                       if (err != -EPERM)
23277 +                               retval = err;
23278 +               }
23279 +               break;
23280 +
23281 +       case 1:
23282 +               if (vxi->vx_initpid) {
23283 +                       pid = vxi->vx_initpid;
23284 +                       /* for now, only SIGINT to private init ... */
23285 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
23286 +                               /* ... as long as there are tasks left */
23287 +                               (atomic_read(&vxi->vx_tasks) > 1))
23288 +                               sig = SIGINT;
23289 +               }
23290 +               /* fallthrough */
23291 +       default:
23292 +               p = find_task_by_real_pid(pid);
23293 +               if (p) {
23294 +                       if (vx_task_xid(p) == vxi->vx_id)
23295 +                               retval = group_send_sig_info(sig, sip, p);
23296 +               }
23297 +               break;
23298 +       }
23299 +       read_unlock(&tasklist_lock);
23300 +       vxdprintk(VXD_CBIT(misc, 4),
23301 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
23302 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
23303 +       return retval;
23304 +}
23305 +
23306 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
23307 +{
23308 +       struct vcmd_ctx_kill_v0 vc_data;
23309 +
23310 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23311 +               return -EFAULT;
23312 +
23313 +       /* special check to allow guest shutdown */
23314 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
23315 +               /* forbid killall pid=0 when init is present */
23316 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
23317 +               (vc_data.pid > 1)))
23318 +               return -EACCES;
23319 +
23320 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
23321 +}
23322 +
23323 +
23324 +static int __wait_exit(struct vx_info *vxi)
23325 +{
23326 +       DECLARE_WAITQUEUE(wait, current);
23327 +       int ret = 0;
23328 +
23329 +       add_wait_queue(&vxi->vx_wait, &wait);
23330 +       set_current_state(TASK_INTERRUPTIBLE);
23331 +
23332 +wait:
23333 +       if (vx_info_state(vxi,
23334 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
23335 +               goto out;
23336 +       if (signal_pending(current)) {
23337 +               ret = -ERESTARTSYS;
23338 +               goto out;
23339 +       }
23340 +       schedule();
23341 +       goto wait;
23342 +
23343 +out:
23344 +       set_current_state(TASK_RUNNING);
23345 +       remove_wait_queue(&vxi->vx_wait, &wait);
23346 +       return ret;
23347 +}
23348 +
23349 +
23350 +
23351 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
23352 +{
23353 +       struct vcmd_wait_exit_v0 vc_data;
23354 +       int ret;
23355 +
23356 +       ret = __wait_exit(vxi);
23357 +       vc_data.reboot_cmd = vxi->reboot_cmd;
23358 +       vc_data.exit_code = vxi->exit_code;
23359 +
23360 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23361 +               ret = -EFAULT;
23362 +       return ret;
23363 +}
23364 +
23365 diff -NurpP --minimal linux-2.6.36/kernel/vserver/space.c linux-2.6.36-vs2.3.0.36.36/kernel/vserver/space.c
23366 --- linux-2.6.36/kernel/vserver/space.c 1970-01-01 01:00:00.000000000 +0100
23367 +++ linux-2.6.36-vs2.3.0.36.36/kernel/vserver/space.c   2010-10-21 14:41:06.000000000 +0200
23368 @@ -0,0 +1,375 @@
23369 +/*
23370 + *  linux/kernel/vserver/space.c
23371 + *
23372 + *  Virtual Server: Context Space Support
23373 + *
23374 + *  Copyright (C) 2003-2007  Herbert Pötzl
23375 + *
23376 + *  V0.01  broken out from context.c 0.07
23377 + *  V0.02  added task locking for namespace
23378 + *  V0.03  broken out vx_enter_namespace
23379 + *  V0.04  added *space support and commands
23380 + *
23381 + */
23382 +
23383 +#include <linux/utsname.h>
23384 +#include <linux/nsproxy.h>
23385 +#include <linux/err.h>
23386 +#include <linux/fs_struct.h>
23387 +#include <asm/uaccess.h>
23388 +
23389 +#include <linux/vs_context.h>
23390 +#include <linux/vserver/space.h>
23391 +#include <linux/vserver/space_cmd.h>
23392 +
23393 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
23394 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
23395 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
23396 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
23397 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
23398 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
23399 +
23400 +
23401 +/* namespace functions */
23402 +
23403 +#include <linux/mnt_namespace.h>
23404 +#include <linux/user_namespace.h>
23405 +#include <linux/pid_namespace.h>
23406 +#include <linux/ipc_namespace.h>
23407 +#include <net/net_namespace.h>
23408 +
23409 +
23410 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
23411 +       .mask = CLONE_FS |
23412 +               CLONE_NEWNS |
23413 +               CLONE_NEWUTS |
23414 +               CLONE_NEWIPC |
23415 +               CLONE_NEWUSER |
23416 +               0
23417 +};
23418 +
23419 +static const struct vcmd_space_mask_v1 space_mask = {
23420 +       .mask = CLONE_FS |
23421 +               CLONE_NEWNS |
23422 +               CLONE_NEWUTS |
23423 +               CLONE_NEWIPC |
23424 +               CLONE_NEWUSER |
23425 +#ifdef CONFIG_PID_NS
23426 +               CLONE_NEWPID |
23427 +#endif
23428 +#ifdef CONFIG_NET_NS
23429 +               CLONE_NEWNET |
23430 +#endif
23431 +               0
23432 +};
23433 +
23434 +static const struct vcmd_space_mask_v1 default_space_mask = {
23435 +       .mask = CLONE_FS |
23436 +               CLONE_NEWNS |
23437 +               CLONE_NEWUTS |
23438 +               CLONE_NEWIPC |
23439 +               CLONE_NEWUSER |
23440 +#ifdef CONFIG_PID_NS
23441 +//             CLONE_NEWPID |
23442 +#endif
23443 +               0
23444 +};
23445 +
23446 +/*
23447 + *     build a new nsproxy mix
23448 + *      assumes that both proxies are 'const'
23449 + *     does not touch nsproxy refcounts
23450 + *     will hold a reference on the result.
23451 + */
23452 +
23453 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
23454 +       struct nsproxy *new_nsproxy, unsigned long mask)
23455 +{
23456 +       struct mnt_namespace *old_ns;
23457 +       struct uts_namespace *old_uts;
23458 +       struct ipc_namespace *old_ipc;
23459 +#ifdef CONFIG_PID_NS
23460 +       struct pid_namespace *old_pid;
23461 +#endif
23462 +#ifdef CONFIG_NET_NS
23463 +       struct net *old_net;
23464 +#endif
23465 +       struct nsproxy *nsproxy;
23466 +
23467 +       nsproxy = copy_nsproxy(old_nsproxy);
23468 +       if (!nsproxy)
23469 +               goto out;
23470 +
23471 +       if (mask & CLONE_NEWNS) {
23472 +               old_ns = nsproxy->mnt_ns;
23473 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
23474 +               if (nsproxy->mnt_ns)
23475 +                       get_mnt_ns(nsproxy->mnt_ns);
23476 +       } else
23477 +               old_ns = NULL;
23478 +
23479 +       if (mask & CLONE_NEWUTS) {
23480 +               old_uts = nsproxy->uts_ns;
23481 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
23482 +               if (nsproxy->uts_ns)
23483 +                       get_uts_ns(nsproxy->uts_ns);
23484 +       } else
23485 +               old_uts = NULL;
23486 +
23487 +       if (mask & CLONE_NEWIPC) {
23488 +               old_ipc = nsproxy->ipc_ns;
23489 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
23490 +               if (nsproxy->ipc_ns)
23491 +                       get_ipc_ns(nsproxy->ipc_ns);
23492 +       } else
23493 +               old_ipc = NULL;
23494 +
23495 +#ifdef CONFIG_PID_NS
23496 +       if (mask & CLONE_NEWPID) {
23497 +               old_pid = nsproxy->pid_ns;
23498 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
23499 +               if (nsproxy->pid_ns)
23500 +                       get_pid_ns(nsproxy->pid_ns);
23501 +       } else
23502 +               old_pid = NULL;
23503 +#endif
23504 +#ifdef CONFIG_NET_NS
23505 +       if (mask & CLONE_NEWNET) {
23506 +               old_net = nsproxy->net_ns;
23507 +               nsproxy->net_ns = new_nsproxy->net_ns;
23508 +               if (nsproxy->net_ns)
23509 +                       get_net(nsproxy->net_ns);
23510 +       } else
23511 +               old_net = NULL;
23512 +#endif
23513 +       if (old_ns)
23514 +               put_mnt_ns(old_ns);
23515 +       if (old_uts)
23516 +               put_uts_ns(old_uts);
23517 +       if (old_ipc)
23518 +               put_ipc_ns(old_ipc);
23519 +#ifdef CONFIG_PID_NS
23520 +       if (old_pid)
23521 +               put_pid_ns(old_pid);
23522 +#endif
23523 +#ifdef CONFIG_NET_NS
23524 +       if (old_net)
23525 +               put_net(old_net);
23526 +#endif
23527 +out:
23528 +       return nsproxy;
23529 +}
23530 +
23531 +
23532 +/*
23533 + *     merge two nsproxy structs into a new one.
23534 + *     will hold a reference on the result.
23535 + */
23536 +
23537 +static inline
23538 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
23539 +       struct nsproxy *proxy, unsigned long mask)
23540 +{
23541 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
23542 +
23543 +       if (!proxy)
23544 +               return NULL;
23545 +
23546 +       if (mask) {
23547 +               /* vs_mix_nsproxy returns with reference */
23548 +               return vs_mix_nsproxy(old ? old : &null_proxy,
23549 +                       proxy, mask);
23550 +       }
23551 +       get_nsproxy(proxy);
23552 +       return proxy;
23553 +}
23554 +
23555 +
23556 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
23557 +{
23558 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
23559 +       struct fs_struct *fs_cur, *fs = NULL;
23560 +       int ret, kill = 0;
23561 +
23562 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
23563 +               vxi, vxi->vx_id, mask, index);
23564 +
23565 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
23566 +               return -EACCES;
23567 +
23568 +       if (!mask)
23569 +               mask = vxi->vx_nsmask[index];
23570 +
23571 +       if ((mask & vxi->vx_nsmask[index]) != mask)
23572 +               return -EINVAL;
23573 +
23574 +       if (mask & CLONE_FS) {
23575 +               fs = copy_fs_struct(vxi->vx_fs[index]);
23576 +               if (!fs)
23577 +                       return -ENOMEM;
23578 +       }
23579 +       proxy = vxi->vx_nsproxy[index];
23580 +
23581 +       vxdprintk(VXD_CBIT(space, 9),
23582 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
23583 +               vxi, vxi->vx_id, mask, index, proxy, fs);
23584 +
23585 +       task_lock(current);
23586 +       fs_cur = current->fs;
23587 +
23588 +       if (mask & CLONE_FS) {
23589 +               spin_lock(&fs_cur->lock);
23590 +               current->fs = fs;
23591 +               kill = !--fs_cur->users;
23592 +               spin_unlock(&fs_cur->lock);
23593 +       }
23594 +
23595 +       proxy_cur = current->nsproxy;
23596 +       get_nsproxy(proxy_cur);
23597 +       task_unlock(current);
23598 +
23599 +       if (kill)
23600 +               free_fs_struct(fs_cur);
23601 +
23602 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
23603 +       if (IS_ERR(proxy_new)) {
23604 +               ret = PTR_ERR(proxy_new);
23605 +               goto out_put;
23606 +       }
23607 +
23608 +       proxy_new = xchg(&current->nsproxy, proxy_new);
23609 +       ret = 0;
23610 +
23611 +       if (proxy_new)
23612 +               put_nsproxy(proxy_new);
23613 +out_put:
23614 +       if (proxy_cur)
23615 +               put_nsproxy(proxy_cur);
23616 +       return ret;
23617 +}
23618 +
23619 +
23620 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
23621 +{
23622 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
23623 +       struct fs_struct *fs_vxi, *fs;
23624 +       int ret, kill = 0;
23625 +
23626 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
23627 +               vxi, vxi->vx_id, mask, index);
23628 +#if 0
23629 +       if (!mask)
23630 +               mask = default_space_mask.mask;
23631 +#endif
23632 +       if ((mask & space_mask.mask) != mask)
23633 +               return -EINVAL;
23634 +
23635 +       proxy_vxi = vxi->vx_nsproxy[index];
23636 +       fs_vxi = vxi->vx_fs[index];
23637 +
23638 +       if (mask & CLONE_FS) {
23639 +               fs = copy_fs_struct(current->fs);
23640 +               if (!fs)
23641 +                       return -ENOMEM;
23642 +       }
23643 +
23644 +       task_lock(current);
23645 +
23646 +       if (mask & CLONE_FS) {
23647 +               spin_lock(&fs_vxi->lock);
23648 +               vxi->vx_fs[index] = fs;
23649 +               kill = !--fs_vxi->users;
23650 +               spin_unlock(&fs_vxi->lock);
23651 +       }
23652 +
23653 +       proxy_cur = current->nsproxy;
23654 +       get_nsproxy(proxy_cur);
23655 +       task_unlock(current);
23656 +
23657 +       if (kill)
23658 +               free_fs_struct(fs_vxi);
23659 +
23660 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
23661 +       if (IS_ERR(proxy_new)) {
23662 +               ret = PTR_ERR(proxy_new);
23663 +               goto out_put;
23664 +       }
23665 +
23666 +       proxy_new = xchg(&vxi->vx_nsproxy[index], proxy_new);
23667 +       vxi->vx_nsmask[index] |= mask;
23668 +       ret = 0;
23669 +
23670 +       if (proxy_new)
23671 +               put_nsproxy(proxy_new);
23672 +out_put:
23673 +       if (proxy_cur)
23674 +               put_nsproxy(proxy_cur);
23675 +       return ret;
23676 +}
23677 +
23678 +
23679 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
23680 +{
23681 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
23682 +
23683 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23684 +               return -EFAULT;
23685 +
23686 +       return vx_enter_space(vxi, vc_data.mask, 0);
23687 +}
23688 +
23689 +int vc_enter_space(struct vx_info *vxi, void __user *data)
23690 +{
23691 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
23692 +
23693 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23694 +               return -EFAULT;
23695 +
23696 +       if (vc_data.index >= VX_SPACES)
23697 +               return -EINVAL;
23698 +
23699 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
23700 +}
23701 +
23702 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
23703 +{
23704 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
23705 +
23706 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23707 +               return -EFAULT;
23708 +
23709 +       return vx_set_space(vxi, vc_data.mask, 0);
23710 +}
23711 +
23712 +int vc_set_space(struct vx_info *vxi, void __user *data)
23713 +{
23714 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
23715 +
23716 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23717 +               return -EFAULT;
23718 +
23719 +       if (vc_data.index >= VX_SPACES)
23720 +               return -EINVAL;
23721 +
23722 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
23723 +}
23724 +
23725 +int vc_get_space_mask(void __user *data, int type)
23726 +{
23727 +       const struct vcmd_space_mask_v1 *mask;
23728 +
23729 +       if (type == 0)
23730 +               mask = &space_mask_v0;
23731 +       else if (type == 1)
23732 +               mask = &space_mask;
23733 +       else
23734 +               mask = &default_space_mask;
23735 +
23736 +       vxdprintk(VXD_CBIT(space, 10),
23737 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
23738 +
23739 +       if (copy_to_user(data, mask, sizeof(*mask)))
23740 +               return -EFAULT;
23741 +       return 0;
23742 +}
23743 +
23744 diff -NurpP --minimal linux-2.6.36/kernel/vserver/switch.c linux-2.6.36-vs2.3.0.36.36/kernel/vserver/switch.c
23745 --- linux-2.6.36/kernel/vserver/switch.c        1970-01-01 01:00:00.000000000 +0100
23746 +++ linux-2.6.36-vs2.3.0.36.36/kernel/vserver/switch.c  2010-10-21 19:05:54.000000000 +0200
23747 @@ -0,0 +1,539 @@
23748 +/*
23749 + *  linux/kernel/vserver/switch.c
23750 + *
23751 + *  Virtual Server: Syscall Switch
23752 + *
23753 + *  Copyright (C) 2003-2007  Herbert Pötzl
23754 + *
23755 + *  V0.01  syscall switch
23756 + *  V0.02  added signal to context
23757 + *  V0.03  added rlimit functions
23758 + *  V0.04  added iattr, task/xid functions
23759 + *  V0.05  added debug/history stuff
23760 + *  V0.06  added compat32 layer
23761 + *  V0.07  vcmd args and perms
23762 + *  V0.08  added status commands
23763 + *  V0.09  added tag commands
23764 + *  V0.10  added oom bias
23765 + *  V0.11  added device commands
23766 + *
23767 + */
23768 +
23769 +#include <linux/vs_context.h>
23770 +#include <linux/vs_network.h>
23771 +#include <linux/vserver/switch.h>
23772 +
23773 +#include "vci_config.h"
23774 +
23775 +
23776 +static inline
23777 +int vc_get_version(uint32_t id)
23778 +{
23779 +       return VCI_VERSION;
23780 +}
23781 +
23782 +static inline
23783 +int vc_get_vci(uint32_t id)
23784 +{
23785 +       return vci_kernel_config();
23786 +}
23787 +
23788 +#include <linux/vserver/context_cmd.h>
23789 +#include <linux/vserver/cvirt_cmd.h>
23790 +#include <linux/vserver/cacct_cmd.h>
23791 +#include <linux/vserver/limit_cmd.h>
23792 +#include <linux/vserver/network_cmd.h>
23793 +#include <linux/vserver/sched_cmd.h>
23794 +#include <linux/vserver/debug_cmd.h>
23795 +#include <linux/vserver/inode_cmd.h>
23796 +#include <linux/vserver/dlimit_cmd.h>
23797 +#include <linux/vserver/signal_cmd.h>
23798 +#include <linux/vserver/space_cmd.h>
23799 +#include <linux/vserver/tag_cmd.h>
23800 +#include <linux/vserver/device_cmd.h>
23801 +
23802 +#include <linux/vserver/inode.h>
23803 +#include <linux/vserver/dlimit.h>
23804 +
23805 +
23806 +#ifdef CONFIG_COMPAT
23807 +#define __COMPAT(name, id, data, compat)       \
23808 +       (compat) ? name ## _x32(id, data) : name(id, data)
23809 +#define __COMPAT_NO_ID(name, data, compat)     \
23810 +       (compat) ? name ## _x32(data) : name(data)
23811 +#else
23812 +#define __COMPAT(name, id, data, compat)       \
23813 +       name(id, data)
23814 +#define __COMPAT_NO_ID(name, data, compat)     \
23815 +       name(data)
23816 +#endif
23817 +
23818 +
23819 +static inline
23820 +long do_vcmd(uint32_t cmd, uint32_t id,
23821 +       struct vx_info *vxi, struct nx_info *nxi,
23822 +       void __user *data, int compat)
23823 +{
23824 +       switch (cmd) {
23825 +
23826 +       case VCMD_get_version:
23827 +               return vc_get_version(id);
23828 +       case VCMD_get_vci:
23829 +               return vc_get_vci(id);
23830 +
23831 +       case VCMD_task_xid:
23832 +               return vc_task_xid(id);
23833 +       case VCMD_vx_info:
23834 +               return vc_vx_info(vxi, data);
23835 +
23836 +       case VCMD_task_nid:
23837 +               return vc_task_nid(id);
23838 +       case VCMD_nx_info:
23839 +               return vc_nx_info(nxi, data);
23840 +
23841 +       case VCMD_task_tag:
23842 +               return vc_task_tag(id);
23843 +
23844 +       case VCMD_set_space_v1:
23845 +               return vc_set_space_v1(vxi, data);
23846 +       /* this is version 2 */
23847 +       case VCMD_set_space:
23848 +               return vc_set_space(vxi, data);
23849 +
23850 +       case VCMD_get_space_mask_v0:
23851 +               return vc_get_space_mask(data, 0);
23852 +       /* this is version 1 */
23853 +       case VCMD_get_space_mask:
23854 +               return vc_get_space_mask(data, 1);
23855 +
23856 +       case VCMD_get_space_default:
23857 +               return vc_get_space_mask(data, -1);
23858 +
23859 +#ifdef CONFIG_IA32_EMULATION
23860 +       case VCMD_get_rlimit:
23861 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
23862 +       case VCMD_set_rlimit:
23863 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
23864 +#else
23865 +       case VCMD_get_rlimit:
23866 +               return vc_get_rlimit(vxi, data);
23867 +       case VCMD_set_rlimit:
23868 +               return vc_set_rlimit(vxi, data);
23869 +#endif
23870 +       case VCMD_get_rlimit_mask:
23871 +               return vc_get_rlimit_mask(id, data);
23872 +       case VCMD_reset_hits:
23873 +               return vc_reset_hits(vxi, data);
23874 +       case VCMD_reset_minmax:
23875 +               return vc_reset_minmax(vxi, data);
23876 +
23877 +       case VCMD_get_vhi_name:
23878 +               return vc_get_vhi_name(vxi, data);
23879 +       case VCMD_set_vhi_name:
23880 +               return vc_set_vhi_name(vxi, data);
23881 +
23882 +       case VCMD_ctx_stat:
23883 +               return vc_ctx_stat(vxi, data);
23884 +       case VCMD_virt_stat:
23885 +               return vc_virt_stat(vxi, data);
23886 +       case VCMD_sock_stat:
23887 +               return vc_sock_stat(vxi, data);
23888 +       case VCMD_rlimit_stat:
23889 +               return vc_rlimit_stat(vxi, data);
23890 +
23891 +       case VCMD_set_cflags:
23892 +               return vc_set_cflags(vxi, data);
23893 +       case VCMD_get_cflags:
23894 +               return vc_get_cflags(vxi, data);
23895 +
23896 +       /* this is version 1 */
23897 +       case VCMD_set_ccaps:
23898 +               return vc_set_ccaps(vxi, data);
23899 +       /* this is version 1 */
23900 +       case VCMD_get_ccaps:
23901 +               return vc_get_ccaps(vxi, data);
23902 +       case VCMD_set_bcaps:
23903 +               return vc_set_bcaps(vxi, data);
23904 +       case VCMD_get_bcaps:
23905 +               return vc_get_bcaps(vxi, data);
23906 +
23907 +       case VCMD_set_badness:
23908 +               return vc_set_badness(vxi, data);
23909 +       case VCMD_get_badness:
23910 +               return vc_get_badness(vxi, data);
23911 +
23912 +       case VCMD_set_nflags:
23913 +               return vc_set_nflags(nxi, data);
23914 +       case VCMD_get_nflags:
23915 +               return vc_get_nflags(nxi, data);
23916 +
23917 +       case VCMD_set_ncaps:
23918 +               return vc_set_ncaps(nxi, data);
23919 +       case VCMD_get_ncaps:
23920 +               return vc_get_ncaps(nxi, data);
23921 +
23922 +       case VCMD_set_sched_v4:
23923 +               return vc_set_sched_v4(vxi, data);
23924 +       /* this is version 5 */
23925 +       case VCMD_set_sched:
23926 +               return vc_set_sched(vxi, data);
23927 +       case VCMD_get_sched:
23928 +               return vc_get_sched(vxi, data);
23929 +       case VCMD_sched_info:
23930 +               return vc_sched_info(vxi, data);
23931 +
23932 +       case VCMD_add_dlimit:
23933 +               return __COMPAT(vc_add_dlimit, id, data, compat);
23934 +       case VCMD_rem_dlimit:
23935 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
23936 +       case VCMD_set_dlimit:
23937 +               return __COMPAT(vc_set_dlimit, id, data, compat);
23938 +       case VCMD_get_dlimit:
23939 +               return __COMPAT(vc_get_dlimit, id, data, compat);
23940 +
23941 +       case VCMD_ctx_kill:
23942 +               return vc_ctx_kill(vxi, data);
23943 +
23944 +       case VCMD_wait_exit:
23945 +               return vc_wait_exit(vxi, data);
23946 +
23947 +       case VCMD_get_iattr:
23948 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
23949 +       case VCMD_set_iattr:
23950 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
23951 +
23952 +       case VCMD_fget_iattr:
23953 +               return vc_fget_iattr(id, data);
23954 +       case VCMD_fset_iattr:
23955 +               return vc_fset_iattr(id, data);
23956 +
23957 +       case VCMD_enter_space_v0:
23958 +               return vc_enter_space_v1(vxi, NULL);
23959 +       case VCMD_enter_space_v1:
23960 +               return vc_enter_space_v1(vxi, data);
23961 +       /* this is version 2 */
23962 +       case VCMD_enter_space:
23963 +               return vc_enter_space(vxi, data);
23964 +
23965 +       case VCMD_ctx_create_v0:
23966 +               return vc_ctx_create(id, NULL);
23967 +       case VCMD_ctx_create:
23968 +               return vc_ctx_create(id, data);
23969 +       case VCMD_ctx_migrate_v0:
23970 +               return vc_ctx_migrate(vxi, NULL);
23971 +       case VCMD_ctx_migrate:
23972 +               return vc_ctx_migrate(vxi, data);
23973 +
23974 +       case VCMD_net_create_v0:
23975 +               return vc_net_create(id, NULL);
23976 +       case VCMD_net_create:
23977 +               return vc_net_create(id, data);
23978 +       case VCMD_net_migrate:
23979 +               return vc_net_migrate(nxi, data);
23980 +
23981 +       case VCMD_tag_migrate:
23982 +               return vc_tag_migrate(id);
23983 +
23984 +       case VCMD_net_add:
23985 +               return vc_net_add(nxi, data);
23986 +       case VCMD_net_remove:
23987 +               return vc_net_remove(nxi, data);
23988 +
23989 +       case VCMD_net_add_ipv4:
23990 +               return vc_net_add_ipv4(nxi, data);
23991 +       case VCMD_net_remove_ipv4:
23992 +               return vc_net_remove_ipv4(nxi, data);
23993 +#ifdef CONFIG_IPV6
23994 +       case VCMD_net_add_ipv6:
23995 +               return vc_net_add_ipv6(nxi, data);
23996 +       case VCMD_net_remove_ipv6:
23997 +               return vc_net_remove_ipv6(nxi, data);
23998 +#endif
23999 +/*     case VCMD_add_match_ipv4:
24000 +               return vc_add_match_ipv4(nxi, data);
24001 +       case VCMD_get_match_ipv4:
24002 +               return vc_get_match_ipv4(nxi, data);
24003 +#ifdef CONFIG_IPV6
24004 +       case VCMD_add_match_ipv6:
24005 +               return vc_add_match_ipv6(nxi, data);
24006 +       case VCMD_get_match_ipv6:
24007 +               return vc_get_match_ipv6(nxi, data);
24008 +#endif */
24009 +
24010 +#ifdef CONFIG_VSERVER_DEVICE
24011 +       case VCMD_set_mapping:
24012 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
24013 +       case VCMD_unset_mapping:
24014 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
24015 +#endif
24016 +#ifdef CONFIG_VSERVER_HISTORY
24017 +       case VCMD_dump_history:
24018 +               return vc_dump_history(id);
24019 +       case VCMD_read_history:
24020 +               return __COMPAT(vc_read_history, id, data, compat);
24021 +#endif
24022 +       default:
24023 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
24024 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
24025 +       }
24026 +       return -ENOSYS;
24027 +}
24028 +
24029 +
24030 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
24031 +       case VCMD_ ## vcmd: perm = _perm;               \
24032 +               args = _args; flags = _flags; break
24033 +
24034 +
24035 +#define VCA_NONE       0x00
24036 +#define VCA_VXI                0x01
24037 +#define VCA_NXI                0x02
24038 +
24039 +#define VCF_NONE       0x00
24040 +#define VCF_INFO       0x01
24041 +#define VCF_ADMIN      0x02
24042 +#define VCF_ARES       0x06    /* includes admin */
24043 +#define VCF_SETUP      0x08
24044 +
24045 +#define VCF_ZIDOK      0x10    /* zero id okay */
24046 +
24047 +
24048 +static inline
24049 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
24050 +{
24051 +       long ret;
24052 +       int permit = -1, state = 0;
24053 +       int perm = -1, args = 0, flags = 0;
24054 +       struct vx_info *vxi = NULL;
24055 +       struct nx_info *nxi = NULL;
24056 +
24057 +       switch (cmd) {
24058 +       /* unpriviledged commands */
24059 +       __VCMD(get_version,      0, VCA_NONE,   0);
24060 +       __VCMD(get_vci,          0, VCA_NONE,   0);
24061 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
24062 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
24063 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
24064 +       __VCMD(get_space_default,0, VCA_NONE,   0);
24065 +
24066 +       /* info commands */
24067 +       __VCMD(task_xid,         2, VCA_NONE,   0);
24068 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
24069 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
24070 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
24071 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
24072 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
24073 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
24074 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
24075 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
24076 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
24077 +
24078 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
24079 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
24080 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
24081 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
24082 +
24083 +       __VCMD(task_nid,         2, VCA_NONE,   0);
24084 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
24085 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
24086 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
24087 +
24088 +       __VCMD(task_tag,         2, VCA_NONE,   0);
24089 +
24090 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
24091 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
24092 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
24093 +       __VCMD(get_sched,        3, VCA_VXI,    VCF_INFO);
24094 +       __VCMD(sched_info,       3, VCA_VXI,    VCF_INFO | VCF_ZIDOK);
24095 +
24096 +       /* lower admin commands */
24097 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
24098 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
24099 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
24100 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
24101 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
24102 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
24103 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
24104 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
24105 +
24106 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
24107 +       __VCMD(net_create,       5, VCA_NONE,   0);
24108 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
24109 +
24110 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
24111 +
24112 +       /* higher admin commands */
24113 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
24114 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24115 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24116 +
24117 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24118 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24119 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24120 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24121 +
24122 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24123 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24124 +       __VCMD(set_sched,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24125 +       __VCMD(set_sched_v4,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24126 +
24127 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
24128 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
24129 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
24130 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
24131 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
24132 +       __VCMD(net_remove_ipv4,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
24133 +#ifdef CONFIG_IPV6
24134 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
24135 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
24136 +#endif
24137 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
24138 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
24139 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
24140 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
24141 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
24142 +
24143 +#ifdef CONFIG_VSERVER_DEVICE
24144 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
24145 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
24146 +#endif
24147 +       /* debug level admin commands */
24148 +#ifdef CONFIG_VSERVER_HISTORY
24149 +       __VCMD(dump_history,     9, VCA_NONE,   0);
24150 +       __VCMD(read_history,     9, VCA_NONE,   0);
24151 +#endif
24152 +
24153 +       default:
24154 +               perm = -1;
24155 +       }
24156 +
24157 +       vxdprintk(VXD_CBIT(switch, 0),
24158 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
24159 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
24160 +               VC_VERSION(cmd), id, data, compat,
24161 +               perm, args, flags);
24162 +
24163 +       ret = -ENOSYS;
24164 +       if (perm < 0)
24165 +               goto out;
24166 +
24167 +       state = 1;
24168 +       if (!capable(CAP_CONTEXT))
24169 +               goto out;
24170 +
24171 +       state = 2;
24172 +       /* moved here from the individual commands */
24173 +       ret = -EPERM;
24174 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
24175 +               goto out;
24176 +
24177 +       state = 3;
24178 +       /* vcmd involves resource management  */
24179 +       ret = -EPERM;
24180 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
24181 +               goto out;
24182 +
24183 +       state = 4;
24184 +       /* various legacy exceptions */
24185 +       switch (cmd) {
24186 +       /* will go away when spectator is a cap */
24187 +       case VCMD_ctx_migrate_v0:
24188 +       case VCMD_ctx_migrate:
24189 +               if (id == 1) {
24190 +                       current->xid = 1;
24191 +                       ret = 1;
24192 +                       goto out;
24193 +               }
24194 +               break;
24195 +
24196 +       /* will go away when spectator is a cap */
24197 +       case VCMD_net_migrate:
24198 +               if (id == 1) {
24199 +                       current->nid = 1;
24200 +                       ret = 1;
24201 +                       goto out;
24202 +               }
24203 +               break;
24204 +       }
24205 +
24206 +       /* vcmds are fine by default */
24207 +       permit = 1;
24208 +
24209 +       /* admin type vcmds require admin ... */
24210 +       if (flags & VCF_ADMIN)
24211 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
24212 +
24213 +       /* ... but setup type vcmds override that */
24214 +       if (!permit && (flags & VCF_SETUP))
24215 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
24216 +
24217 +       state = 5;
24218 +       ret = -EPERM;
24219 +       if (!permit)
24220 +               goto out;
24221 +
24222 +       state = 6;
24223 +       if (!id && (flags & VCF_ZIDOK))
24224 +               goto skip_id;
24225 +
24226 +       ret = -ESRCH;
24227 +       if (args & VCA_VXI) {
24228 +               vxi = lookup_vx_info(id);
24229 +               if (!vxi)
24230 +                       goto out;
24231 +
24232 +               if ((flags & VCF_ADMIN) &&
24233 +                       /* special case kill for shutdown */
24234 +                       (cmd != VCMD_ctx_kill) &&
24235 +                       /* can context be administrated? */
24236 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
24237 +                       ret = -EACCES;
24238 +                       goto out_vxi;
24239 +               }
24240 +       }
24241 +       state = 7;
24242 +       if (args & VCA_NXI) {
24243 +               nxi = lookup_nx_info(id);
24244 +               if (!nxi)
24245 +                       goto out_vxi;
24246 +
24247 +               if ((flags & VCF_ADMIN) &&
24248 +                       /* can context be administrated? */
24249 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
24250 +                       ret = -EACCES;
24251 +                       goto out_nxi;
24252 +               }
24253 +       }
24254 +skip_id:
24255 +       state = 8;
24256 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
24257 +
24258 +out_nxi:
24259 +       if ((args & VCA_NXI) && nxi)
24260 +               put_nx_info(nxi);
24261 +out_vxi:
24262 +       if ((args & VCA_VXI) && vxi)
24263 +               put_vx_info(vxi);
24264 +out:
24265 +       vxdprintk(VXD_CBIT(switch, 1),
24266 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
24267 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
24268 +               VC_VERSION(cmd), ret, ret, state, permit);
24269 +       return ret;
24270 +}
24271 +
24272 +asmlinkage long
24273 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
24274 +{
24275 +       return do_vserver(cmd, id, data, 0);
24276 +}
24277 +
24278 +#ifdef CONFIG_COMPAT
24279 +
24280 +asmlinkage long
24281 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
24282 +{
24283 +       return do_vserver(cmd, id, data, 1);
24284 +}
24285 +
24286 +#endif /* CONFIG_COMPAT */
24287 diff -NurpP --minimal linux-2.6.36/kernel/vserver/sysctl.c linux-2.6.36-vs2.3.0.36.36/kernel/vserver/sysctl.c
24288 --- linux-2.6.36/kernel/vserver/sysctl.c        1970-01-01 01:00:00.000000000 +0100
24289 +++ linux-2.6.36-vs2.3.0.36.36/kernel/vserver/sysctl.c  2010-10-21 13:09:36.000000000 +0200
24290 @@ -0,0 +1,241 @@
24291 +/*
24292 + *  kernel/vserver/sysctl.c
24293 + *
24294 + *  Virtual Context Support
24295 + *
24296 + *  Copyright (C) 2004-2007  Herbert Pötzl
24297 + *
24298 + *  V0.01  basic structure
24299 + *
24300 + */
24301 +
24302 +#include <linux/module.h>
24303 +#include <linux/ctype.h>
24304 +#include <linux/sysctl.h>
24305 +#include <linux/parser.h>
24306 +#include <asm/uaccess.h>
24307 +
24308 +enum {
24309 +       CTL_DEBUG_ERROR         = 0,
24310 +       CTL_DEBUG_SWITCH        = 1,
24311 +       CTL_DEBUG_XID,
24312 +       CTL_DEBUG_NID,
24313 +       CTL_DEBUG_TAG,
24314 +       CTL_DEBUG_NET,
24315 +       CTL_DEBUG_LIMIT,
24316 +       CTL_DEBUG_CRES,
24317 +       CTL_DEBUG_DLIM,
24318 +       CTL_DEBUG_QUOTA,
24319 +       CTL_DEBUG_CVIRT,
24320 +       CTL_DEBUG_SPACE,
24321 +       CTL_DEBUG_MISC,
24322 +};
24323 +
24324 +
24325 +unsigned int vx_debug_switch   = 0;
24326 +unsigned int vx_debug_xid      = 0;
24327 +unsigned int vx_debug_nid      = 0;
24328 +unsigned int vx_debug_tag      = 0;
24329 +unsigned int vx_debug_net      = 0;
24330 +unsigned int vx_debug_limit    = 0;
24331 +unsigned int vx_debug_cres     = 0;
24332 +unsigned int vx_debug_dlim     = 0;
24333 +unsigned int vx_debug_quota    = 0;
24334 +unsigned int vx_debug_cvirt    = 0;
24335 +unsigned int vx_debug_space    = 0;
24336 +unsigned int vx_debug_misc     = 0;
24337 +
24338 +
24339 +static struct ctl_table_header *vserver_table_header;
24340 +static ctl_table vserver_root_table[];
24341 +
24342 +
24343 +void vserver_register_sysctl(void)
24344 +{
24345 +       if (!vserver_table_header) {
24346 +               vserver_table_header = register_sysctl_table(vserver_root_table);
24347 +       }
24348 +
24349 +}
24350 +
24351 +void vserver_unregister_sysctl(void)
24352 +{
24353 +       if (vserver_table_header) {
24354 +               unregister_sysctl_table(vserver_table_header);
24355 +               vserver_table_header = NULL;
24356 +       }
24357 +}
24358 +
24359 +
24360 +static int proc_dodebug(ctl_table *table, int write,
24361 +       void __user *buffer, size_t *lenp, loff_t *ppos)
24362 +{
24363 +       char            tmpbuf[20], *p, c;
24364 +       unsigned int    value;
24365 +       size_t          left, len;
24366 +
24367 +       if ((*ppos && !write) || !*lenp) {
24368 +               *lenp = 0;
24369 +               return 0;
24370 +       }
24371 +
24372 +       left = *lenp;
24373 +
24374 +       if (write) {
24375 +               if (!access_ok(VERIFY_READ, buffer, left))
24376 +                       return -EFAULT;
24377 +               p = (char *)buffer;
24378 +               while (left && __get_user(c, p) >= 0 && isspace(c))
24379 +                       left--, p++;
24380 +               if (!left)
24381 +                       goto done;
24382 +
24383 +               if (left > sizeof(tmpbuf) - 1)
24384 +                       return -EINVAL;
24385 +               if (copy_from_user(tmpbuf, p, left))
24386 +                       return -EFAULT;
24387 +               tmpbuf[left] = '\0';
24388 +
24389 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
24390 +                       value = 10 * value + (*p - '0');
24391 +               if (*p && !isspace(*p))
24392 +                       return -EINVAL;
24393 +               while (left && isspace(*p))
24394 +                       left--, p++;
24395 +               *(unsigned int *)table->data = value;
24396 +       } else {
24397 +               if (!access_ok(VERIFY_WRITE, buffer, left))
24398 +                       return -EFAULT;
24399 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
24400 +               if (len > left)
24401 +                       len = left;
24402 +               if (__copy_to_user(buffer, tmpbuf, len))
24403 +                       return -EFAULT;
24404 +               if ((left -= len) > 0) {
24405 +                       if (put_user('\n', (char *)buffer + len))
24406 +                               return -EFAULT;
24407 +                       left--;
24408 +               }
24409 +       }
24410 +
24411 +done:
24412 +       *lenp -= left;
24413 +       *ppos += *lenp;
24414 +       return 0;
24415 +}
24416 +
24417 +static int zero;
24418 +
24419 +#define        CTL_ENTRY(ctl, name)                            \
24420 +       {                                               \
24421 +               .procname       = #name,                \
24422 +               .data           = &vx_ ## name,         \
24423 +               .maxlen         = sizeof(int),          \
24424 +               .mode           = 0644,                 \
24425 +               .proc_handler   = &proc_dodebug,        \
24426 +               .extra1         = &zero,                \
24427 +               .extra2         = &zero,                \
24428 +       }
24429 +
24430 +static ctl_table vserver_debug_table[] = {
24431 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
24432 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
24433 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
24434 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
24435 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
24436 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
24437 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
24438 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
24439 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
24440 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
24441 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
24442 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
24443 +       { 0 }
24444 +};
24445 +
24446 +static ctl_table vserver_root_table[] = {
24447 +       {
24448 +               .procname       = "vserver",
24449 +               .mode           = 0555,
24450 +               .child          = vserver_debug_table
24451 +       },
24452 +       { 0 }
24453 +};
24454 +
24455 +
24456 +static match_table_t tokens = {
24457 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
24458 +       { CTL_DEBUG_XID,        "xid=%x"        },
24459 +       { CTL_DEBUG_NID,        "nid=%x"        },
24460 +       { CTL_DEBUG_TAG,        "tag=%x"        },
24461 +       { CTL_DEBUG_NET,        "net=%x"        },
24462 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
24463 +       { CTL_DEBUG_CRES,       "cres=%x"       },
24464 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
24465 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
24466 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
24467 +       { CTL_DEBUG_SPACE,      "space=%x"      },
24468 +       { CTL_DEBUG_MISC,       "misc=%x"       },
24469 +       { CTL_DEBUG_ERROR,      NULL            }
24470 +};
24471 +
24472 +#define        HANDLE_CASE(id, name, val)                              \
24473 +       case CTL_DEBUG_ ## id:                                  \
24474 +               vx_debug_ ## name = val;                        \
24475 +               printk("vs_debug_" #name "=0x%x\n", val);       \
24476 +               break
24477 +
24478 +
24479 +static int __init vs_debug_setup(char *str)
24480 +{
24481 +       char *p;
24482 +       int token;
24483 +
24484 +       printk("vs_debug_setup(%s)\n", str);
24485 +       while ((p = strsep(&str, ",")) != NULL) {
24486 +               substring_t args[MAX_OPT_ARGS];
24487 +               unsigned int value;
24488 +
24489 +               if (!*p)
24490 +                       continue;
24491 +
24492 +               token = match_token(p, tokens, args);
24493 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
24494 +
24495 +               switch (token) {
24496 +               HANDLE_CASE(SWITCH, switch, value);
24497 +               HANDLE_CASE(XID,    xid,    value);
24498 +               HANDLE_CASE(NID,    nid,    value);
24499 +               HANDLE_CASE(TAG,    tag,    value);
24500 +               HANDLE_CASE(NET,    net,    value);
24501 +               HANDLE_CASE(LIMIT,  limit,  value);
24502 +               HANDLE_CASE(CRES,   cres,   value);
24503 +               HANDLE_CASE(DLIM,   dlim,   value);
24504 +               HANDLE_CASE(QUOTA,  quota,  value);
24505 +               HANDLE_CASE(CVIRT,  cvirt,  value);
24506 +               HANDLE_CASE(SPACE,  space,  value);
24507 +               HANDLE_CASE(MISC,   misc,   value);
24508 +               default:
24509 +                       return -EINVAL;
24510 +                       break;
24511 +               }
24512 +       }
24513 +       return 1;
24514 +}
24515 +
24516 +__setup("vsdebug=", vs_debug_setup);
24517 +
24518 +
24519 +
24520 +EXPORT_SYMBOL_GPL(vx_debug_switch);
24521 +EXPORT_SYMBOL_GPL(vx_debug_xid);
24522 +EXPORT_SYMBOL_GPL(vx_debug_nid);
24523 +EXPORT_SYMBOL_GPL(vx_debug_net);
24524 +EXPORT_SYMBOL_GPL(vx_debug_limit);
24525 +EXPORT_SYMBOL_GPL(vx_debug_cres);
24526 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
24527 +EXPORT_SYMBOL_GPL(vx_debug_quota);
24528 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
24529 +EXPORT_SYMBOL_GPL(vx_debug_space);
24530 +EXPORT_SYMBOL_GPL(vx_debug_misc);
24531 +
24532 diff -NurpP --minimal linux-2.6.36/kernel/vserver/tag.c linux-2.6.36-vs2.3.0.36.36/kernel/vserver/tag.c
24533 --- linux-2.6.36/kernel/vserver/tag.c   1970-01-01 01:00:00.000000000 +0100
24534 +++ linux-2.6.36-vs2.3.0.36.36/kernel/vserver/tag.c     2010-10-21 13:09:36.000000000 +0200
24535 @@ -0,0 +1,63 @@
24536 +/*
24537 + *  linux/kernel/vserver/tag.c
24538 + *
24539 + *  Virtual Server: Shallow Tag Space
24540 + *
24541 + *  Copyright (C) 2007  Herbert Pötzl
24542 + *
24543 + *  V0.01  basic implementation
24544 + *
24545 + */
24546 +
24547 +#include <linux/sched.h>
24548 +#include <linux/vserver/debug.h>
24549 +#include <linux/vs_pid.h>
24550 +#include <linux/vs_tag.h>
24551 +
24552 +#include <linux/vserver/tag_cmd.h>
24553 +
24554 +
24555 +int dx_migrate_task(struct task_struct *p, tag_t tag)
24556 +{
24557 +       if (!p)
24558 +               BUG();
24559 +
24560 +       vxdprintk(VXD_CBIT(tag, 5),
24561 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
24562 +
24563 +       task_lock(p);
24564 +       p->tag = tag;
24565 +       task_unlock(p);
24566 +
24567 +       vxdprintk(VXD_CBIT(tag, 5),
24568 +               "moved task %p into [#%d]", p, tag);
24569 +       return 0;
24570 +}
24571 +
24572 +/* vserver syscall commands below here */
24573 +
24574 +/* taks xid and vx_info functions */
24575 +
24576 +
24577 +int vc_task_tag(uint32_t id)
24578 +{
24579 +       tag_t tag;
24580 +
24581 +       if (id) {
24582 +               struct task_struct *tsk;
24583 +               read_lock(&tasklist_lock);
24584 +               tsk = find_task_by_real_pid(id);
24585 +               tag = (tsk) ? tsk->tag : -ESRCH;
24586 +               read_unlock(&tasklist_lock);
24587 +       } else
24588 +               tag = dx_current_tag();
24589 +       return tag;
24590 +}
24591 +
24592 +
24593 +int vc_tag_migrate(uint32_t tag)
24594 +{
24595 +       return dx_migrate_task(current, tag & 0xFFFF);
24596 +}
24597 +
24598 +
24599 diff -NurpP --minimal linux-2.6.36/kernel/vserver/vci_config.h linux-2.6.36-vs2.3.0.36.36/kernel/vserver/vci_config.h
24600 --- linux-2.6.36/kernel/vserver/vci_config.h    1970-01-01 01:00:00.000000000 +0100
24601 +++ linux-2.6.36-vs2.3.0.36.36/kernel/vserver/vci_config.h      2010-10-21 13:09:36.000000000 +0200
24602 @@ -0,0 +1,85 @@
24603 +
24604 +/*  interface version */
24605 +
24606 +#define VCI_VERSION            0x00020306
24607 +
24608 +
24609 +enum {
24610 +       VCI_KCBIT_NO_DYNAMIC = 0,
24611 +
24612 +       VCI_KCBIT_PROC_SECURE = 4,
24613 +       VCI_KCBIT_HARDCPU = 5,
24614 +       VCI_KCBIT_IDLELIMIT = 6,
24615 +       VCI_KCBIT_IDLETIME = 7,
24616 +
24617 +       VCI_KCBIT_COWBL = 8,
24618 +       VCI_KCBIT_FULLCOWBL = 9,
24619 +       VCI_KCBIT_SPACES = 10,
24620 +       VCI_KCBIT_NETV2 = 11,
24621 +       VCI_KCBIT_MEMCG = 12,
24622 +
24623 +       VCI_KCBIT_DEBUG = 16,
24624 +       VCI_KCBIT_HISTORY = 20,
24625 +       VCI_KCBIT_TAGGED = 24,
24626 +       VCI_KCBIT_PPTAG = 28,
24627 +
24628 +       VCI_KCBIT_MORE = 31,
24629 +};
24630 +
24631 +
24632 +static inline uint32_t vci_kernel_config(void)
24633 +{
24634 +       return
24635 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
24636 +
24637 +       /* configured features */
24638 +#ifdef CONFIG_VSERVER_PROC_SECURE
24639 +       (1 << VCI_KCBIT_PROC_SECURE) |
24640 +#endif
24641 +#ifdef CONFIG_VSERVER_HARDCPU
24642 +       (1 << VCI_KCBIT_HARDCPU) |
24643 +#endif
24644 +#ifdef CONFIG_VSERVER_IDLELIMIT
24645 +       (1 << VCI_KCBIT_IDLELIMIT) |
24646 +#endif
24647 +#ifdef CONFIG_VSERVER_IDLETIME
24648 +       (1 << VCI_KCBIT_IDLETIME) |
24649 +#endif
24650 +#ifdef CONFIG_VSERVER_COWBL
24651 +       (1 << VCI_KCBIT_COWBL) |
24652 +       (1 << VCI_KCBIT_FULLCOWBL) |
24653 +#endif
24654 +       (1 << VCI_KCBIT_SPACES) |
24655 +       (1 << VCI_KCBIT_NETV2) |
24656 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
24657 +       (1 << VCI_KCBIT_MEMCG) |
24658 +#endif
24659 +
24660 +       /* debug options */
24661 +#ifdef CONFIG_VSERVER_DEBUG
24662 +       (1 << VCI_KCBIT_DEBUG) |
24663 +#endif
24664 +#ifdef CONFIG_VSERVER_HISTORY
24665 +       (1 << VCI_KCBIT_HISTORY) |
24666 +#endif
24667 +
24668 +       /* inode context tagging */
24669 +#if    defined(CONFIG_TAGGING_NONE)
24670 +       (0 << VCI_KCBIT_TAGGED) |
24671 +#elif  defined(CONFIG_TAGGING_UID16)
24672 +       (1 << VCI_KCBIT_TAGGED) |
24673 +#elif  defined(CONFIG_TAGGING_GID16)
24674 +       (2 << VCI_KCBIT_TAGGED) |
24675 +#elif  defined(CONFIG_TAGGING_ID24)
24676 +       (3 << VCI_KCBIT_TAGGED) |
24677 +#elif  defined(CONFIG_TAGGING_INTERN)
24678 +       (4 << VCI_KCBIT_TAGGED) |
24679 +#elif  defined(CONFIG_TAGGING_RUNTIME)
24680 +       (5 << VCI_KCBIT_TAGGED) |
24681 +#else
24682 +       (7 << VCI_KCBIT_TAGGED) |
24683 +#endif
24684 +       (1 << VCI_KCBIT_PPTAG) |
24685 +       0;
24686 +}
24687 +
24688 diff -NurpP --minimal linux-2.6.36/mm/filemap_xip.c linux-2.6.36-vs2.3.0.36.36/mm/filemap_xip.c
24689 --- linux-2.6.36/mm/filemap_xip.c       2010-07-07 18:31:58.000000000 +0200
24690 +++ linux-2.6.36-vs2.3.0.36.36/mm/filemap_xip.c 2010-10-21 13:09:36.000000000 +0200
24691 @@ -18,6 +18,7 @@
24692  #include <linux/seqlock.h>
24693  #include <linux/mutex.h>
24694  #include <linux/gfp.h>
24695 +#include <linux/vs_memory.h>
24696  #include <asm/tlbflush.h>
24697  #include <asm/io.h>
24698  
24699 diff -NurpP --minimal linux-2.6.36/mm/fremap.c linux-2.6.36-vs2.3.0.36.36/mm/fremap.c
24700 --- linux-2.6.36/mm/fremap.c    2010-10-21 13:07:57.000000000 +0200
24701 +++ linux-2.6.36-vs2.3.0.36.36/mm/fremap.c      2010-10-21 13:09:36.000000000 +0200
24702 @@ -16,6 +16,7 @@
24703  #include <linux/module.h>
24704  #include <linux/syscalls.h>
24705  #include <linux/mmu_notifier.h>
24706 +#include <linux/vs_memory.h>
24707  
24708  #include <asm/mmu_context.h>
24709  #include <asm/cacheflush.h>
24710 diff -NurpP --minimal linux-2.6.36/mm/hugetlb.c linux-2.6.36-vs2.3.0.36.36/mm/hugetlb.c
24711 --- linux-2.6.36/mm/hugetlb.c   2010-10-21 13:07:57.000000000 +0200
24712 +++ linux-2.6.36-vs2.3.0.36.36/mm/hugetlb.c     2010-10-21 13:09:36.000000000 +0200
24713 @@ -28,6 +28,7 @@
24714  
24715  #include <linux/hugetlb.h>
24716  #include <linux/node.h>
24717 +#include <linux/vs_memory.h>
24718  #include "internal.h"
24719  
24720  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
24721 diff -NurpP --minimal linux-2.6.36/mm/memcontrol.c linux-2.6.36-vs2.3.0.36.36/mm/memcontrol.c
24722 --- linux-2.6.36/mm/memcontrol.c        2010-10-21 13:07:57.000000000 +0200
24723 +++ linux-2.6.36-vs2.3.0.36.36/mm/memcontrol.c  2010-10-21 13:09:36.000000000 +0200
24724 @@ -638,6 +638,31 @@ struct mem_cgroup *mem_cgroup_from_task(
24725                                 struct mem_cgroup, css);
24726  }
24727  
24728 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
24729 +{
24730 +       return res_counter_read_u64(&mem->res, member);
24731 +}
24732 +
24733 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
24734 +{
24735 +       return res_counter_read_u64(&mem->memsw, member);
24736 +}
24737 +
24738 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
24739 +{
24740 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
24741 +}
24742 +
24743 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
24744 +{
24745 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
24746 +}
24747 +
24748 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
24749 +{
24750 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
24751 +}
24752 +
24753  static struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
24754  {
24755         struct mem_cgroup *mem = NULL;
24756 diff -NurpP --minimal linux-2.6.36/mm/memory.c linux-2.6.36-vs2.3.0.36.36/mm/memory.c
24757 --- linux-2.6.36/mm/memory.c    2010-10-21 13:07:57.000000000 +0200
24758 +++ linux-2.6.36-vs2.3.0.36.36/mm/memory.c      2010-10-21 13:09:36.000000000 +0200
24759 @@ -3145,6 +3145,7 @@ static inline int handle_pte_fault(struc
24760  {
24761         pte_t entry;
24762         spinlock_t *ptl;
24763 +       int ret = 0, type = VXPT_UNKNOWN;
24764  
24765         entry = *pte;
24766         if (!pte_present(entry)) {
24767 @@ -3169,9 +3170,12 @@ static inline int handle_pte_fault(struc
24768         if (unlikely(!pte_same(*pte, entry)))
24769                 goto unlock;
24770         if (flags & FAULT_FLAG_WRITE) {
24771 -               if (!pte_write(entry))
24772 -                       return do_wp_page(mm, vma, address,
24773 +               if (!pte_write(entry)) {
24774 +                       ret = do_wp_page(mm, vma, address,
24775                                         pte, pmd, ptl, entry);
24776 +                       type = VXPT_WRITE;
24777 +                       goto out;
24778 +               }
24779                 entry = pte_mkdirty(entry);
24780         }
24781         entry = pte_mkyoung(entry);
24782 @@ -3189,7 +3193,10 @@ static inline int handle_pte_fault(struc
24783         }
24784  unlock:
24785         pte_unmap_unlock(pte, ptl);
24786 -       return 0;
24787 +       ret = 0;
24788 +out:
24789 +       vx_page_fault(mm, vma, type, ret);
24790 +       return ret;
24791  }
24792  
24793  /*
24794 diff -NurpP --minimal linux-2.6.36/mm/mremap.c linux-2.6.36-vs2.3.0.36.36/mm/mremap.c
24795 --- linux-2.6.36/mm/mremap.c    2010-07-07 18:31:58.000000000 +0200
24796 +++ linux-2.6.36-vs2.3.0.36.36/mm/mremap.c      2010-10-21 13:09:36.000000000 +0200
24797 @@ -19,6 +19,7 @@
24798  #include <linux/security.h>
24799  #include <linux/syscalls.h>
24800  #include <linux/mmu_notifier.h>
24801 +#include <linux/vs_memory.h>
24802  
24803  #include <asm/uaccess.h>
24804  #include <asm/cacheflush.h>
24805 diff -NurpP --minimal linux-2.6.36/mm/oom_kill.c linux-2.6.36-vs2.3.0.36.36/mm/oom_kill.c
24806 --- linux-2.6.36/mm/oom_kill.c  2010-10-21 13:07:57.000000000 +0200
24807 +++ linux-2.6.36-vs2.3.0.36.36/mm/oom_kill.c    2010-10-21 14:57:29.000000000 +0200
24808 @@ -31,6 +31,9 @@
24809  #include <linux/memcontrol.h>
24810  #include <linux/mempolicy.h>
24811  #include <linux/security.h>
24812 +#include <linux/reboot.h>
24813 +#include <linux/vs_memory.h>
24814 +#include <linux/vs_context.h>
24815  
24816  int sysctl_panic_on_oom;
24817  int sysctl_oom_kill_allocating_task;
24818 @@ -124,11 +127,18 @@ struct task_struct *find_lock_task_mm(st
24819  static bool oom_unkillable_task(struct task_struct *p,
24820                 const struct mem_cgroup *mem, const nodemask_t *nodemask)
24821  {
24822 -       if (is_global_init(p))
24823 +       unsigned xid = vx_current_xid();
24824 +
24825 +       /* skip the init task, global and per guest */
24826 +       if (task_is_init(p))
24827                 return true;
24828         if (p->flags & PF_KTHREAD)
24829                 return true;
24830  
24831 +       /* skip other guest and host processes if oom in guest */
24832 +       if (xid && vx_task_xid(p) != xid)
24833 +               return true;
24834 +
24835         /* When mem_cgroup_out_of_memory() and p is not member of the group */
24836         if (mem && !task_in_mem_cgroup(p, mem))
24837                 return true;
24838 @@ -209,6 +219,18 @@ unsigned int oom_badness(struct task_str
24839         points += p->signal->oom_score_adj;
24840  
24841         /*
24842 +        * add points for context badness and
24843 +        * reduce badness for processes belonging to
24844 +        * a different context
24845 +        */
24846 +
24847 +       points += vx_badness(p, p->mm);
24848 +
24849 +       if ((vx_current_xid() > 1) &&
24850 +               vx_current_xid() != vx_task_xid(p))
24851 +               points /= 16;
24852 +
24853 +       /*
24854          * Never return 0 for an eligible task that may be killed since it's
24855          * possible that no single user task uses more than 0.1% of memory and
24856          * no single admin tasks uses more than 3.0%.
24857 @@ -407,8 +429,8 @@ static int oom_kill_task(struct task_str
24858         if (!p)
24859                 return 1;
24860  
24861 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
24862 -               task_pid_nr(p), p->comm, K(p->mm->total_vm),
24863 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
24864 +               task_pid_nr(p), p->xid, p->comm, K(p->mm->total_vm),
24865                 K(get_mm_counter(p->mm, MM_ANONPAGES)),
24866                 K(get_mm_counter(p->mm, MM_FILEPAGES)));
24867         task_unlock(p);
24868 @@ -452,8 +474,8 @@ static int oom_kill_process(struct task_
24869         }
24870  
24871         task_lock(p);
24872 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
24873 -               message, task_pid_nr(p), p->comm, points);
24874 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
24875 +               message, task_pid_nr(p), p->xid, p->comm, points);
24876         task_unlock(p);
24877  
24878         /*
24879 @@ -542,6 +564,8 @@ int unregister_oom_notifier(struct notif
24880  }
24881  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
24882  
24883 +long vs_oom_action(unsigned int);
24884 +
24885  /*
24886   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
24887   * if a parallel OOM killing is already taking place that includes a zone in
24888 @@ -701,7 +725,12 @@ retry:
24889         if (!p) {
24890                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
24891                 read_unlock(&tasklist_lock);
24892 -               panic("Out of memory and no killable processes...\n");
24893 +
24894 +               /* avoid panic for guest OOM */
24895 +               if (current->xid)
24896 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
24897 +               else
24898 +                       panic("Out of memory and no killable processes...\n");
24899         }
24900  
24901         if (oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
24902 diff -NurpP --minimal linux-2.6.36/mm/page_alloc.c linux-2.6.36-vs2.3.0.36.36/mm/page_alloc.c
24903 --- linux-2.6.36/mm/page_alloc.c        2010-10-21 13:07:57.000000000 +0200
24904 +++ linux-2.6.36-vs2.3.0.36.36/mm/page_alloc.c  2010-10-21 13:09:36.000000000 +0200
24905 @@ -52,6 +52,8 @@
24906  #include <linux/compaction.h>
24907  #include <trace/events/kmem.h>
24908  #include <linux/ftrace_event.h>
24909 +#include <linux/vs_base.h>
24910 +#include <linux/vs_limit.h>
24911  
24912  #include <asm/tlbflush.h>
24913  #include <asm/div64.h>
24914 @@ -2329,6 +2331,9 @@ void si_meminfo(struct sysinfo *val)
24915         val->totalhigh = totalhigh_pages;
24916         val->freehigh = nr_free_highpages();
24917         val->mem_unit = PAGE_SIZE;
24918 +
24919 +       if (vx_flags(VXF_VIRT_MEM, 0))
24920 +               vx_vsi_meminfo(val);
24921  }
24922  
24923  EXPORT_SYMBOL(si_meminfo);
24924 @@ -2349,6 +2354,9 @@ void si_meminfo_node(struct sysinfo *val
24925         val->freehigh = 0;
24926  #endif
24927         val->mem_unit = PAGE_SIZE;
24928 +
24929 +       if (vx_flags(VXF_VIRT_MEM, 0))
24930 +               vx_vsi_meminfo(val);
24931  }
24932  #endif
24933  
24934 diff -NurpP --minimal linux-2.6.36/mm/rmap.c linux-2.6.36-vs2.3.0.36.36/mm/rmap.c
24935 --- linux-2.6.36/mm/rmap.c      2010-10-21 13:07:57.000000000 +0200
24936 +++ linux-2.6.36-vs2.3.0.36.36/mm/rmap.c        2010-10-21 13:19:11.000000000 +0200
24937 @@ -57,6 +57,7 @@
24938  #include <linux/mmu_notifier.h>
24939  #include <linux/migrate.h>
24940  #include <linux/hugetlb.h>
24941 +#include <linux/vs_memory.h>
24942  
24943  #include <asm/tlbflush.h>
24944  
24945 diff -NurpP --minimal linux-2.6.36/mm/shmem.c linux-2.6.36-vs2.3.0.36.36/mm/shmem.c
24946 --- linux-2.6.36/mm/shmem.c     2010-10-21 13:07:57.000000000 +0200
24947 +++ linux-2.6.36-vs2.3.0.36.36/mm/shmem.c       2010-10-21 13:09:36.000000000 +0200
24948 @@ -1815,7 +1815,7 @@ static int shmem_statfs(struct dentry *d
24949  {
24950         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
24951  
24952 -       buf->f_type = TMPFS_MAGIC;
24953 +       buf->f_type = TMPFS_SUPER_MAGIC;
24954         buf->f_bsize = PAGE_CACHE_SIZE;
24955         buf->f_namelen = NAME_MAX;
24956         if (sbinfo->max_blocks) {
24957 @@ -2377,7 +2377,7 @@ int shmem_fill_super(struct super_block 
24958         sb->s_maxbytes = SHMEM_MAX_BYTES;
24959         sb->s_blocksize = PAGE_CACHE_SIZE;
24960         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
24961 -       sb->s_magic = TMPFS_MAGIC;
24962 +       sb->s_magic = TMPFS_SUPER_MAGIC;
24963         sb->s_op = &shmem_ops;
24964         sb->s_time_gran = 1;
24965  #ifdef CONFIG_TMPFS_POSIX_ACL
24966 diff -NurpP --minimal linux-2.6.36/mm/slab.c linux-2.6.36-vs2.3.0.36.36/mm/slab.c
24967 --- linux-2.6.36/mm/slab.c      2010-10-21 13:07:57.000000000 +0200
24968 +++ linux-2.6.36-vs2.3.0.36.36/mm/slab.c        2010-10-21 13:09:36.000000000 +0200
24969 @@ -407,6 +407,8 @@ static void kmem_list3_init(struct kmem_
24970  #define STATS_INC_FREEMISS(x)  do { } while (0)
24971  #endif
24972  
24973 +#include "slab_vs.h"
24974 +
24975  #if DEBUG
24976  
24977  /*
24978 @@ -3346,6 +3348,7 @@ retry:
24979  
24980         obj = slab_get_obj(cachep, slabp, nodeid);
24981         check_slabp(cachep, slabp);
24982 +       vx_slab_alloc(cachep, flags);
24983         l3->free_objects--;
24984         /* move slabp to correct slabp list: */
24985         list_del(&slabp->list);
24986 @@ -3423,6 +3426,7 @@ __cache_alloc_node(struct kmem_cache *ca
24987         /* ___cache_alloc_node can fall back to other nodes */
24988         ptr = ____cache_alloc_node(cachep, flags, nodeid);
24989    out:
24990 +       vx_slab_alloc(cachep, flags);
24991         local_irq_restore(save_flags);
24992         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
24993         kmemleak_alloc_recursive(ptr, obj_size(cachep), 1, cachep->flags,
24994 @@ -3609,6 +3613,7 @@ static inline void __cache_free(struct k
24995         check_irq_off();
24996         kmemleak_free_recursive(objp, cachep->flags);
24997         objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
24998 +       vx_slab_free(cachep);
24999  
25000         kmemcheck_slab_free(cachep, objp, obj_size(cachep));
25001  
25002 diff -NurpP --minimal linux-2.6.36/mm/slab_vs.h linux-2.6.36-vs2.3.0.36.36/mm/slab_vs.h
25003 --- linux-2.6.36/mm/slab_vs.h   1970-01-01 01:00:00.000000000 +0100
25004 +++ linux-2.6.36-vs2.3.0.36.36/mm/slab_vs.h     2010-10-21 13:09:36.000000000 +0200
25005 @@ -0,0 +1,29 @@
25006 +
25007 +#include <linux/vserver/context.h>
25008 +
25009 +#include <linux/vs_context.h>
25010 +
25011 +static inline
25012 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
25013 +{
25014 +       int what = gfp_zone(cachep->gfpflags);
25015 +       struct vx_info *vxi = current_vx_info();
25016 +
25017 +       if (!vxi)
25018 +               return;
25019 +
25020 +       atomic_add(cachep->buffer_size, &vxi->cacct.slab[what]);
25021 +}
25022 +
25023 +static inline
25024 +void vx_slab_free(struct kmem_cache *cachep)
25025 +{
25026 +       int what = gfp_zone(cachep->gfpflags);
25027 +       struct vx_info *vxi = current_vx_info();
25028 +
25029 +       if (!vxi)
25030 +               return;
25031 +
25032 +       atomic_sub(cachep->buffer_size, &vxi->cacct.slab[what]);
25033 +}
25034 +
25035 diff -NurpP --minimal linux-2.6.36/mm/swapfile.c linux-2.6.36-vs2.3.0.36.36/mm/swapfile.c
25036 --- linux-2.6.36/mm/swapfile.c  2010-10-21 13:07:57.000000000 +0200
25037 +++ linux-2.6.36-vs2.3.0.36.36/mm/swapfile.c    2010-10-21 13:09:36.000000000 +0200
25038 @@ -35,6 +35,8 @@
25039  #include <asm/tlbflush.h>
25040  #include <linux/swapops.h>
25041  #include <linux/page_cgroup.h>
25042 +#include <linux/vs_base.h>
25043 +#include <linux/vs_memory.h>
25044  
25045  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
25046                                  unsigned char);
25047 @@ -1747,6 +1749,16 @@ static int swap_show(struct seq_file *sw
25048  
25049         if (si == SEQ_START_TOKEN) {
25050                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
25051 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
25052 +                       struct sysinfo si;
25053 +
25054 +                       vx_vsi_swapinfo(&si);
25055 +                       if (si.totalswap < (1 << 10))
25056 +                               return 0;
25057 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
25058 +                               "hdv0", "partition", si.totalswap >> 10,
25059 +                               (si.totalswap - si.freeswap) >> 10, -1);
25060 +               }
25061                 return 0;
25062         }
25063  
25064 @@ -2131,6 +2143,8 @@ void si_swapinfo(struct sysinfo *val)
25065         val->freeswap = nr_swap_pages + nr_to_be_unused;
25066         val->totalswap = total_swap_pages + nr_to_be_unused;
25067         spin_unlock(&swap_lock);
25068 +       if (vx_flags(VXF_VIRT_MEM, 0))
25069 +               vx_vsi_swapinfo(val);
25070  }
25071  
25072  /*
25073 diff -NurpP --minimal linux-2.6.36/net/core/dev.c linux-2.6.36-vs2.3.0.36.36/net/core/dev.c
25074 --- linux-2.6.36/net/core/dev.c 2010-10-21 13:07:58.000000000 +0200
25075 +++ linux-2.6.36-vs2.3.0.36.36/net/core/dev.c   2010-10-21 14:12:56.000000000 +0200
25076 @@ -127,6 +127,7 @@
25077  #include <linux/in.h>
25078  #include <linux/jhash.h>
25079  #include <linux/random.h>
25080 +#include <linux/vs_inet.h>
25081  #include <trace/events/napi.h>
25082  #include <linux/pci.h>
25083  
25084 @@ -607,7 +608,8 @@ struct net_device *__dev_get_by_name(str
25085         struct hlist_head *head = dev_name_hash(net, name);
25086  
25087         hlist_for_each_entry(dev, p, head, name_hlist)
25088 -               if (!strncmp(dev->name, name, IFNAMSIZ))
25089 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
25090 +                   nx_dev_visible(current_nx_info(), dev))
25091                         return dev;
25092  
25093         return NULL;
25094 @@ -633,7 +635,8 @@ struct net_device *dev_get_by_name_rcu(s
25095         struct hlist_head *head = dev_name_hash(net, name);
25096  
25097         hlist_for_each_entry_rcu(dev, p, head, name_hlist)
25098 -               if (!strncmp(dev->name, name, IFNAMSIZ))
25099 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
25100 +                   nx_dev_visible(current_nx_info(), dev))
25101                         return dev;
25102  
25103         return NULL;
25104 @@ -684,7 +687,8 @@ struct net_device *__dev_get_by_index(st
25105         struct hlist_head *head = dev_index_hash(net, ifindex);
25106  
25107         hlist_for_each_entry(dev, p, head, index_hlist)
25108 -               if (dev->ifindex == ifindex)
25109 +               if ((dev->ifindex == ifindex) &&
25110 +                   nx_dev_visible(current_nx_info(), dev))
25111                         return dev;
25112  
25113         return NULL;
25114 @@ -709,7 +713,8 @@ struct net_device *dev_get_by_index_rcu(
25115         struct hlist_head *head = dev_index_hash(net, ifindex);
25116  
25117         hlist_for_each_entry_rcu(dev, p, head, index_hlist)
25118 -               if (dev->ifindex == ifindex)
25119 +               if ((dev->ifindex == ifindex) &&
25120 +                   nx_dev_visible(current_nx_info(), dev))
25121                         return dev;
25122  
25123         return NULL;
25124 @@ -762,10 +767,12 @@ struct net_device *dev_getbyhwaddr(struc
25125  
25126         ASSERT_RTNL();
25127  
25128 -       for_each_netdev(net, dev)
25129 +       for_each_netdev(net, dev) {
25130                 if (dev->type == type &&
25131 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
25132 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
25133 +                   nx_dev_visible(current_nx_info(), dev))
25134                         return dev;
25135 +       }
25136  
25137         return NULL;
25138  }
25139 @@ -776,9 +783,11 @@ struct net_device *__dev_getfirstbyhwtyp
25140         struct net_device *dev;
25141  
25142         ASSERT_RTNL();
25143 -       for_each_netdev(net, dev)
25144 -               if (dev->type == type)
25145 +       for_each_netdev(net, dev) {
25146 +               if ((dev->type == type) &&
25147 +                   nx_dev_visible(current_nx_info(), dev))
25148                         return dev;
25149 +       }
25150  
25151         return NULL;
25152  }
25153 @@ -896,6 +905,8 @@ static int __dev_alloc_name(struct net *
25154                                 continue;
25155                         if (i < 0 || i >= max_netdevices)
25156                                 continue;
25157 +                       if (!nx_dev_visible(current_nx_info(), d))
25158 +                               continue;
25159  
25160                         /*  avoid cases where sscanf is not exact inverse of printf */
25161                         snprintf(buf, IFNAMSIZ, name, i);
25162 @@ -3658,6 +3669,8 @@ static int dev_ifconf(struct net *net, c
25163  
25164         total = 0;
25165         for_each_netdev(net, dev) {
25166 +               if (!nx_dev_visible(current_nx_info(), dev))
25167 +                       continue;
25168                 for (i = 0; i < NPROTO; i++) {
25169                         if (gifconf_list[i]) {
25170                                 int done;
25171 @@ -3729,6 +3742,10 @@ static void dev_seq_printf_stats(struct 
25172         struct rtnl_link_stats64 temp;
25173         const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
25174  
25175 +       /* device visible inside network context? */
25176 +       if (!nx_dev_visible(current_nx_info(), dev))
25177 +               return;
25178 +
25179         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
25180                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
25181                    dev->name, stats->rx_bytes, stats->rx_packets,
25182 diff -NurpP --minimal linux-2.6.36/net/core/rtnetlink.c linux-2.6.36-vs2.3.0.36.36/net/core/rtnetlink.c
25183 --- linux-2.6.36/net/core/rtnetlink.c   2010-10-21 13:07:58.000000000 +0200
25184 +++ linux-2.6.36-vs2.3.0.36.36/net/core/rtnetlink.c     2010-10-21 13:09:36.000000000 +0200
25185 @@ -927,6 +927,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
25186                 hlist_for_each_entry(dev, node, head, index_hlist) {
25187                         if (idx < s_idx)
25188                                 goto cont;
25189 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
25190 +                               continue;
25191                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
25192                                              NETLINK_CB(cb->skb).pid,
25193                                              cb->nlh->nlmsg_seq, 0,
25194 @@ -1643,6 +1645,9 @@ void rtmsg_ifinfo(int type, struct net_d
25195         struct sk_buff *skb;
25196         int err = -ENOBUFS;
25197  
25198 +       if (!nx_dev_visible(current_nx_info(), dev))
25199 +               return;
25200 +
25201         skb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL);
25202         if (skb == NULL)
25203                 goto errout;
25204 diff -NurpP --minimal linux-2.6.36/net/core/sock.c linux-2.6.36-vs2.3.0.36.36/net/core/sock.c
25205 --- linux-2.6.36/net/core/sock.c        2010-10-21 13:07:58.000000000 +0200
25206 +++ linux-2.6.36-vs2.3.0.36.36/net/core/sock.c  2010-10-21 13:09:36.000000000 +0200
25207 @@ -127,6 +127,10 @@
25208  #include <net/cls_cgroup.h>
25209  
25210  #include <linux/filter.h>
25211 +#include <linux/vs_socket.h>
25212 +#include <linux/vs_limit.h>
25213 +#include <linux/vs_context.h>
25214 +#include <linux/vs_network.h>
25215  
25216  #ifdef CONFIG_INET
25217  #include <net/tcp.h>
25218 @@ -1046,6 +1050,8 @@ static struct sock *sk_prot_alloc(struct
25219                         goto out_free_sec;
25220                 sk_tx_queue_clear(sk);
25221         }
25222 +               sock_vx_init(sk);
25223 +               sock_nx_init(sk);
25224  
25225         return sk;
25226  
25227 @@ -1142,6 +1148,11 @@ static void __sk_free(struct sock *sk)
25228                 put_cred(sk->sk_peer_cred);
25229         put_pid(sk->sk_peer_pid);
25230         put_net(sock_net(sk));
25231 +       vx_sock_dec(sk);
25232 +       clr_vx_info(&sk->sk_vx_info);
25233 +       sk->sk_xid = -1;
25234 +       clr_nx_info(&sk->sk_nx_info);
25235 +       sk->sk_nid = -1;
25236         sk_prot_free(sk->sk_prot_creator, sk);
25237  }
25238  
25239 @@ -1189,6 +1200,8 @@ struct sock *sk_clone(const struct sock 
25240  
25241                 /* SANITY */
25242                 get_net(sock_net(newsk));
25243 +               sock_vx_init(newsk);
25244 +               sock_nx_init(newsk);
25245                 sk_node_init(&newsk->sk_node);
25246                 sock_lock_init(newsk);
25247                 bh_lock_sock(newsk);
25248 @@ -1244,6 +1257,12 @@ struct sock *sk_clone(const struct sock 
25249                 smp_wmb();
25250                 atomic_set(&newsk->sk_refcnt, 2);
25251  
25252 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
25253 +               newsk->sk_xid = sk->sk_xid;
25254 +               vx_sock_inc(newsk);
25255 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
25256 +               newsk->sk_nid = sk->sk_nid;
25257 +
25258                 /*
25259                  * Increment the counter in the same struct proto as the master
25260                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
25261 @@ -1986,6 +2005,12 @@ void sock_init_data(struct socket *sock,
25262  
25263         sk->sk_stamp = ktime_set(-1L, 0);
25264  
25265 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
25266 +       sk->sk_xid = vx_current_xid();
25267 +       vx_sock_inc(sk);
25268 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
25269 +       sk->sk_nid = nx_current_nid();
25270 +
25271         /*
25272          * Before updating sk_refcnt, we must commit prior changes to memory
25273          * (Documentation/RCU/rculist_nulls.txt for details)
25274 diff -NurpP --minimal linux-2.6.36/net/ipv4/af_inet.c linux-2.6.36-vs2.3.0.36.36/net/ipv4/af_inet.c
25275 --- linux-2.6.36/net/ipv4/af_inet.c     2010-10-21 13:07:58.000000000 +0200
25276 +++ linux-2.6.36-vs2.3.0.36.36/net/ipv4/af_inet.c       2010-10-21 13:09:36.000000000 +0200
25277 @@ -116,6 +116,7 @@
25278  #ifdef CONFIG_IP_MROUTE
25279  #include <linux/mroute.h>
25280  #endif
25281 +#include <linux/vs_limit.h>
25282  
25283  
25284  /* The inetsw table contains everything that inet_create needs to
25285 @@ -327,9 +328,13 @@ lookup_protocol:
25286         }
25287  
25288         err = -EPERM;
25289 +       if ((protocol == IPPROTO_ICMP) &&
25290 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
25291 +               goto override;
25292 +
25293         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
25294                 goto out_rcu_unlock;
25295 -
25296 +override:
25297         err = -EAFNOSUPPORT;
25298         if (!inet_netns_ok(net, protocol))
25299                 goto out_rcu_unlock;
25300 @@ -453,6 +458,7 @@ int inet_bind(struct socket *sock, struc
25301         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
25302         struct sock *sk = sock->sk;
25303         struct inet_sock *inet = inet_sk(sk);
25304 +       struct nx_v4_sock_addr nsa;
25305         unsigned short snum;
25306         int chk_addr_ret;
25307         int err;
25308 @@ -466,7 +472,11 @@ int inet_bind(struct socket *sock, struc
25309         if (addr_len < sizeof(struct sockaddr_in))
25310                 goto out;
25311  
25312 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
25313 +       err = v4_map_sock_addr(inet, addr, &nsa);
25314 +       if (err)
25315 +               goto out;
25316 +
25317 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
25318  
25319         /* Not specified by any standard per-se, however it breaks too
25320          * many applications when removed.  It is unfortunate since
25321 @@ -478,7 +488,7 @@ int inet_bind(struct socket *sock, struc
25322         err = -EADDRNOTAVAIL;
25323         if (!sysctl_ip_nonlocal_bind &&
25324             !(inet->freebind || inet->transparent) &&
25325 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
25326 +           nsa.saddr != htonl(INADDR_ANY) &&
25327             chk_addr_ret != RTN_LOCAL &&
25328             chk_addr_ret != RTN_MULTICAST &&
25329             chk_addr_ret != RTN_BROADCAST)
25330 @@ -503,7 +513,7 @@ int inet_bind(struct socket *sock, struc
25331         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
25332                 goto out_release_sock;
25333  
25334 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
25335 +       v4_set_sock_addr(inet, &nsa);
25336         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
25337                 inet->inet_saddr = 0;  /* Use device */
25338  
25339 @@ -705,11 +715,13 @@ int inet_getname(struct socket *sock, st
25340                      peer == 1))
25341                         return -ENOTCONN;
25342                 sin->sin_port = inet->inet_dport;
25343 -               sin->sin_addr.s_addr = inet->inet_daddr;
25344 +               sin->sin_addr.s_addr =
25345 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
25346         } else {
25347                 __be32 addr = inet->inet_rcv_saddr;
25348                 if (!addr)
25349                         addr = inet->inet_saddr;
25350 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
25351                 sin->sin_port = inet->inet_sport;
25352                 sin->sin_addr.s_addr = addr;
25353         }
25354 diff -NurpP --minimal linux-2.6.36/net/ipv4/devinet.c linux-2.6.36-vs2.3.0.36.36/net/ipv4/devinet.c
25355 --- linux-2.6.36/net/ipv4/devinet.c     2010-10-21 13:07:58.000000000 +0200
25356 +++ linux-2.6.36-vs2.3.0.36.36/net/ipv4/devinet.c       2010-10-21 13:09:36.000000000 +0200
25357 @@ -417,6 +417,7 @@ struct in_device *inetdev_by_index(struc
25358  }
25359  EXPORT_SYMBOL(inetdev_by_index);
25360  
25361 +
25362  /* Called only from RTNL semaphored context. No locks. */
25363  
25364  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
25365 @@ -659,6 +660,8 @@ int devinet_ioctl(struct net *net, unsig
25366  
25367         in_dev = __in_dev_get_rtnl(dev);
25368         if (in_dev) {
25369 +               struct nx_info *nxi = current_nx_info();
25370 +
25371                 if (tryaddrmatch) {
25372                         /* Matthias Andree */
25373                         /* compare label and address (4.4BSD style) */
25374 @@ -667,6 +670,8 @@ int devinet_ioctl(struct net *net, unsig
25375                            This is checked above. */
25376                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
25377                              ifap = &ifa->ifa_next) {
25378 +                               if (!nx_v4_ifa_visible(nxi, ifa))
25379 +                                       continue;
25380                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
25381                                     sin_orig.sin_addr.s_addr ==
25382                                                         ifa->ifa_address) {
25383 @@ -679,9 +684,12 @@ int devinet_ioctl(struct net *net, unsig
25384                    comparing just the label */
25385                 if (!ifa) {
25386                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
25387 -                            ifap = &ifa->ifa_next)
25388 +                            ifap = &ifa->ifa_next) {
25389 +                               if (!nx_v4_ifa_visible(nxi, ifa))
25390 +                                       continue;
25391                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
25392                                         break;
25393 +                       }
25394                 }
25395         }
25396  
25397 @@ -833,6 +841,8 @@ static int inet_gifconf(struct net_devic
25398                 goto out;
25399  
25400         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
25401 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
25402 +                       continue;
25403                 if (!buf) {
25404                         done += sizeof(ifr);
25405                         continue;
25406 @@ -1182,6 +1192,7 @@ static int inet_dump_ifaddr(struct sk_bu
25407         struct net_device *dev;
25408         struct in_device *in_dev;
25409         struct in_ifaddr *ifa;
25410 +       struct sock *sk = skb->sk;
25411         struct hlist_head *head;
25412         struct hlist_node *node;
25413  
25414 @@ -1204,6 +1215,8 @@ static int inet_dump_ifaddr(struct sk_bu
25415  
25416                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
25417                              ifa = ifa->ifa_next, ip_idx++) {
25418 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
25419 +                               continue;
25420                                 if (ip_idx < s_ip_idx)
25421                                         continue;
25422                                 if (inet_fill_ifaddr(skb, ifa,
25423 diff -NurpP --minimal linux-2.6.36/net/ipv4/fib_hash.c linux-2.6.36-vs2.3.0.36.36/net/ipv4/fib_hash.c
25424 --- linux-2.6.36/net/ipv4/fib_hash.c    2010-07-07 18:31:59.000000000 +0200
25425 +++ linux-2.6.36-vs2.3.0.36.36/net/ipv4/fib_hash.c      2010-10-21 13:09:36.000000000 +0200
25426 @@ -1017,7 +1017,7 @@ static int fib_seq_show(struct seq_file 
25427         prefix  = f->fn_key;
25428         mask    = FZ_MASK(iter->zone);
25429         flags   = fib_flag_trans(fa->fa_type, mask, fi);
25430 -       if (fi)
25431 +       if (fi && nx_dev_visible(current_nx_info(), fi->fib_dev))
25432                 seq_printf(seq,
25433                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u%n",
25434                          fi->fib_dev ? fi->fib_dev->name : "*", prefix,
25435 diff -NurpP --minimal linux-2.6.36/net/ipv4/inet_connection_sock.c linux-2.6.36-vs2.3.0.36.36/net/ipv4/inet_connection_sock.c
25436 --- linux-2.6.36/net/ipv4/inet_connection_sock.c        2010-10-21 13:07:58.000000000 +0200
25437 +++ linux-2.6.36-vs2.3.0.36.36/net/ipv4/inet_connection_sock.c  2010-10-21 13:09:36.000000000 +0200
25438 @@ -52,10 +52,40 @@ void inet_get_local_port_range(int *low,
25439  }
25440  EXPORT_SYMBOL(inet_get_local_port_range);
25441  
25442 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25443 +{
25444 +       __be32  sk1_rcv_saddr = inet_rcv_saddr(sk1),
25445 +               sk2_rcv_saddr = inet_rcv_saddr(sk2);
25446 +
25447 +       if (inet_v6_ipv6only(sk2))
25448 +               return 0;
25449 +
25450 +       if (sk1_rcv_saddr &&
25451 +           sk2_rcv_saddr &&
25452 +           sk1_rcv_saddr == sk2_rcv_saddr)
25453 +               return 1;
25454 +
25455 +       if (sk1_rcv_saddr &&
25456 +           !sk2_rcv_saddr &&
25457 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
25458 +               return 1;
25459 +
25460 +       if (sk2_rcv_saddr &&
25461 +           !sk1_rcv_saddr &&
25462 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
25463 +               return 1;
25464 +
25465 +       if (!sk1_rcv_saddr &&
25466 +           !sk2_rcv_saddr &&
25467 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
25468 +               return 1;
25469 +
25470 +       return 0;
25471 +}
25472 +
25473  int inet_csk_bind_conflict(const struct sock *sk,
25474                            const struct inet_bind_bucket *tb)
25475  {
25476 -       const __be32 sk_rcv_saddr = inet_rcv_saddr(sk);
25477         struct sock *sk2;
25478         struct hlist_node *node;
25479         int reuse = sk->sk_reuse;
25480 @@ -75,9 +105,7 @@ int inet_csk_bind_conflict(const struct 
25481                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
25482                         if (!reuse || !sk2->sk_reuse ||
25483                             sk2->sk_state == TCP_LISTEN) {
25484 -                               const __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
25485 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr ||
25486 -                                   sk2_rcv_saddr == sk_rcv_saddr)
25487 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
25488                                         break;
25489                         }
25490                 }
25491 diff -NurpP --minimal linux-2.6.36/net/ipv4/inet_diag.c linux-2.6.36-vs2.3.0.36.36/net/ipv4/inet_diag.c
25492 --- linux-2.6.36/net/ipv4/inet_diag.c   2010-07-07 18:31:59.000000000 +0200
25493 +++ linux-2.6.36-vs2.3.0.36.36/net/ipv4/inet_diag.c     2010-10-21 13:09:36.000000000 +0200
25494 @@ -33,6 +33,8 @@
25495  #include <linux/stddef.h>
25496  
25497  #include <linux/inet_diag.h>
25498 +#include <linux/vs_network.h>
25499 +#include <linux/vs_inet.h>
25500  
25501  static const struct inet_diag_handler **inet_diag_table;
25502  
25503 @@ -119,8 +121,10 @@ static int inet_csk_diag_fill(struct soc
25504  
25505         r->id.idiag_sport = inet->inet_sport;
25506         r->id.idiag_dport = inet->inet_dport;
25507 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
25508 -       r->id.idiag_dst[0] = inet->inet_daddr;
25509 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
25510 +               inet->inet_rcv_saddr);
25511 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
25512 +               inet->inet_daddr);
25513  
25514  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
25515         if (r->idiag_family == AF_INET6) {
25516 @@ -205,8 +209,8 @@ static int inet_twsk_diag_fill(struct in
25517         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
25518         r->id.idiag_sport     = tw->tw_sport;
25519         r->id.idiag_dport     = tw->tw_dport;
25520 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
25521 -       r->id.idiag_dst[0]    = tw->tw_daddr;
25522 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
25523 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
25524         r->idiag_state        = tw->tw_substate;
25525         r->idiag_timer        = 3;
25526         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
25527 @@ -263,6 +267,7 @@ static int inet_diag_get_exact(struct sk
25528         err = -EINVAL;
25529  
25530         if (req->idiag_family == AF_INET) {
25531 +               /* TODO: lback */
25532                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
25533                                  req->id.idiag_dport, req->id.idiag_src[0],
25534                                  req->id.idiag_sport, req->id.idiag_if);
25535 @@ -505,6 +510,7 @@ static int inet_csk_diag_dump(struct soc
25536                 } else
25537  #endif
25538                 {
25539 +                       /* TODO: lback */
25540                         entry.saddr = &inet->inet_rcv_saddr;
25541                         entry.daddr = &inet->inet_daddr;
25542                 }
25543 @@ -541,6 +547,7 @@ static int inet_twsk_diag_dump(struct in
25544                 } else
25545  #endif
25546                 {
25547 +                       /* TODO: lback */
25548                         entry.saddr = &tw->tw_rcv_saddr;
25549                         entry.daddr = &tw->tw_daddr;
25550                 }
25551 @@ -587,8 +594,8 @@ static int inet_diag_fill_req(struct sk_
25552  
25553         r->id.idiag_sport = inet->inet_sport;
25554         r->id.idiag_dport = ireq->rmt_port;
25555 -       r->id.idiag_src[0] = ireq->loc_addr;
25556 -       r->id.idiag_dst[0] = ireq->rmt_addr;
25557 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
25558 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
25559         r->idiag_expires = jiffies_to_msecs(tmo);
25560         r->idiag_rqueue = 0;
25561         r->idiag_wqueue = 0;
25562 @@ -658,6 +665,7 @@ static int inet_diag_dump_reqs(struct sk
25563                                 continue;
25564  
25565                         if (bc) {
25566 +                               /* TODO: lback */
25567                                 entry.saddr =
25568  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
25569                                         (entry.family == AF_INET6) ?
25570 @@ -728,6 +736,8 @@ static int inet_diag_dump(struct sk_buff
25571                         sk_nulls_for_each(sk, node, &ilb->head) {
25572                                 struct inet_sock *inet = inet_sk(sk);
25573  
25574 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25575 +                                       continue;
25576                                 if (num < s_num) {
25577                                         num++;
25578                                         continue;
25579 @@ -794,6 +804,8 @@ skip_listen_ht:
25580                 sk_nulls_for_each(sk, node, &head->chain) {
25581                         struct inet_sock *inet = inet_sk(sk);
25582  
25583 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25584 +                               continue;
25585                         if (num < s_num)
25586                                 goto next_normal;
25587                         if (!(r->idiag_states & (1 << sk->sk_state)))
25588 @@ -818,6 +830,8 @@ next_normal:
25589                         inet_twsk_for_each(tw, node,
25590                                     &head->twchain) {
25591  
25592 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
25593 +                                       continue;
25594                                 if (num < s_num)
25595                                         goto next_dying;
25596                                 if (r->id.idiag_sport != tw->tw_sport &&
25597 diff -NurpP --minimal linux-2.6.36/net/ipv4/inet_hashtables.c linux-2.6.36-vs2.3.0.36.36/net/ipv4/inet_hashtables.c
25598 --- linux-2.6.36/net/ipv4/inet_hashtables.c     2010-10-21 13:07:58.000000000 +0200
25599 +++ linux-2.6.36-vs2.3.0.36.36/net/ipv4/inet_hashtables.c       2010-10-21 13:09:36.000000000 +0200
25600 @@ -21,6 +21,7 @@
25601  
25602  #include <net/inet_connection_sock.h>
25603  #include <net/inet_hashtables.h>
25604 +#include <net/route.h>
25605  #include <net/ip.h>
25606  
25607  /*
25608 @@ -132,6 +133,11 @@ static inline int compute_score(struct s
25609                         if (rcv_saddr != daddr)
25610                                 return -1;
25611                         score += 2;
25612 +               } else {
25613 +                       /* block non nx_info ips */
25614 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
25615 +                               daddr, NXA_MASK_BIND))
25616 +                               return -1;
25617                 }
25618                 if (sk->sk_bound_dev_if) {
25619                         if (sk->sk_bound_dev_if != dif)
25620 @@ -149,7 +155,6 @@ static inline int compute_score(struct s
25621   * wildcarded during the search since they can never be otherwise.
25622   */
25623  
25624 -
25625  struct sock *__inet_lookup_listener(struct net *net,
25626                                     struct inet_hashinfo *hashinfo,
25627                                     const __be32 daddr, const unsigned short hnum,
25628 @@ -172,6 +177,7 @@ begin:
25629                         hiscore = score;
25630                 }
25631         }
25632 +
25633         /*
25634          * if the nulls value we got at the end of this lookup is
25635          * not the expected one, we must restart lookup.
25636 diff -NurpP --minimal linux-2.6.36/net/ipv4/netfilter/nf_nat_helper.c linux-2.6.36-vs2.3.0.36.36/net/ipv4/netfilter/nf_nat_helper.c
25637 --- linux-2.6.36/net/ipv4/netfilter/nf_nat_helper.c     2010-07-07 18:31:59.000000000 +0200
25638 +++ linux-2.6.36-vs2.3.0.36.36/net/ipv4/netfilter/nf_nat_helper.c       2010-10-21 13:09:36.000000000 +0200
25639 @@ -20,6 +20,7 @@
25640  #include <net/route.h>
25641  
25642  #include <linux/netfilter_ipv4.h>
25643 +#include <net/route.h>
25644  #include <net/netfilter/nf_conntrack.h>
25645  #include <net/netfilter/nf_conntrack_helper.h>
25646  #include <net/netfilter/nf_conntrack_ecache.h>
25647 diff -NurpP --minimal linux-2.6.36/net/ipv4/netfilter.c linux-2.6.36-vs2.3.0.36.36/net/ipv4/netfilter.c
25648 --- linux-2.6.36/net/ipv4/netfilter.c   2010-10-21 13:07:58.000000000 +0200
25649 +++ linux-2.6.36-vs2.3.0.36.36/net/ipv4/netfilter.c     2010-10-21 13:09:36.000000000 +0200
25650 @@ -5,7 +5,7 @@
25651  #include <linux/ip.h>
25652  #include <linux/skbuff.h>
25653  #include <linux/gfp.h>
25654 -#include <net/route.h>
25655 +// #include <net/route.h>
25656  #include <net/xfrm.h>
25657  #include <net/ip.h>
25658  #include <net/netfilter/nf_queue.h>
25659 diff -NurpP --minimal linux-2.6.36/net/ipv4/raw.c linux-2.6.36-vs2.3.0.36.36/net/ipv4/raw.c
25660 --- linux-2.6.36/net/ipv4/raw.c 2010-10-21 13:07:58.000000000 +0200
25661 +++ linux-2.6.36-vs2.3.0.36.36/net/ipv4/raw.c   2010-10-21 13:09:36.000000000 +0200
25662 @@ -116,7 +116,7 @@ static struct sock *__raw_v4_lookup(stru
25663  
25664                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
25665                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
25666 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
25667 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
25668                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
25669                         goto found; /* gotcha */
25670         }
25671 @@ -383,6 +383,12 @@ static int raw_send_hdrinc(struct sock *
25672                 icmp_out_count(net, ((struct icmphdr *)
25673                         skb_transport_header(skb))->type);
25674  
25675 +       err = -EPERM;
25676 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
25677 +               sk->sk_nx_info &&
25678 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
25679 +               goto error_free;
25680 +
25681         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
25682                       rt->dst.dev, dst_output);
25683         if (err > 0)
25684 @@ -563,6 +569,13 @@ static int raw_sendmsg(struct kiocb *ioc
25685                 }
25686  
25687                 security_sk_classify_flow(sk, &fl);
25688 +               if (sk->sk_nx_info) {
25689 +                       err = ip_v4_find_src(sock_net(sk),
25690 +                               sk->sk_nx_info, &rt, &fl);
25691 +
25692 +                       if (err)
25693 +                               goto done;
25694 +               }
25695                 err = ip_route_output_flow(sock_net(sk), &rt, &fl, sk, 1);
25696         }
25697         if (err)
25698 @@ -635,17 +648,19 @@ static int raw_bind(struct sock *sk, str
25699  {
25700         struct inet_sock *inet = inet_sk(sk);
25701         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
25702 +       struct nx_v4_sock_addr nsa = { 0 };
25703         int ret = -EINVAL;
25704         int chk_addr_ret;
25705  
25706         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
25707                 goto out;
25708 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
25709 +       v4_map_sock_addr(inet, addr, &nsa);
25710 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
25711         ret = -EADDRNOTAVAIL;
25712 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
25713 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
25714             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
25715                 goto out;
25716 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
25717 +       v4_set_sock_addr(inet, &nsa);
25718         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
25719                 inet->inet_saddr = 0;  /* Use device */
25720         sk_dst_reset(sk);
25721 @@ -697,7 +712,8 @@ static int raw_recvmsg(struct kiocb *ioc
25722         /* Copy the address. */
25723         if (sin) {
25724                 sin->sin_family = AF_INET;
25725 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25726 +               sin->sin_addr.s_addr =
25727 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
25728                 sin->sin_port = 0;
25729                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
25730         }
25731 @@ -875,7 +891,8 @@ static struct sock *raw_get_first(struct
25732                 struct hlist_node *node;
25733  
25734                 sk_for_each(sk, node, &state->h->ht[state->bucket])
25735 -                       if (sock_net(sk) == seq_file_net(seq))
25736 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
25737 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25738                                 goto found;
25739         }
25740         sk = NULL;
25741 @@ -891,7 +908,8 @@ static struct sock *raw_get_next(struct 
25742                 sk = sk_next(sk);
25743  try_again:
25744                 ;
25745 -       } while (sk && sock_net(sk) != seq_file_net(seq));
25746 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
25747 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25748  
25749         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
25750                 sk = sk_head(&state->h->ht[state->bucket]);
25751 @@ -950,7 +968,10 @@ static void raw_sock_seq_show(struct seq
25752  
25753         seq_printf(seq, "%4d: %08X:%04X %08X:%04X"
25754                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n",
25755 -               i, src, srcp, dest, destp, sp->sk_state,
25756 +               i,
25757 +               nx_map_sock_lback(current_nx_info(), src), srcp,
25758 +               nx_map_sock_lback(current_nx_info(), dest), destp,
25759 +               sp->sk_state,
25760                 sk_wmem_alloc_get(sp),
25761                 sk_rmem_alloc_get(sp),
25762                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
25763 diff -NurpP --minimal linux-2.6.36/net/ipv4/tcp.c linux-2.6.36-vs2.3.0.36.36/net/ipv4/tcp.c
25764 --- linux-2.6.36/net/ipv4/tcp.c 2010-10-21 13:07:58.000000000 +0200
25765 +++ linux-2.6.36-vs2.3.0.36.36/net/ipv4/tcp.c   2010-10-21 13:09:36.000000000 +0200
25766 @@ -266,6 +266,7 @@
25767  #include <linux/crypto.h>
25768  #include <linux/time.h>
25769  #include <linux/slab.h>
25770 +#include <linux/in.h>
25771  
25772  #include <net/icmp.h>
25773  #include <net/tcp.h>
25774 diff -NurpP --minimal linux-2.6.36/net/ipv4/tcp_ipv4.c linux-2.6.36-vs2.3.0.36.36/net/ipv4/tcp_ipv4.c
25775 --- linux-2.6.36/net/ipv4/tcp_ipv4.c    2010-10-21 13:07:58.000000000 +0200
25776 +++ linux-2.6.36-vs2.3.0.36.36/net/ipv4/tcp_ipv4.c      2010-10-21 13:09:36.000000000 +0200
25777 @@ -2016,6 +2016,12 @@ static void *listening_get_next(struct s
25778                 req = req->dl_next;
25779                 while (1) {
25780                         while (req) {
25781 +                               vxdprintk(VXD_CBIT(net, 6),
25782 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
25783 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
25784 +                               if (req->sk &&
25785 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
25786 +                                       continue;
25787                                 if (req->rsk_ops->family == st->family) {
25788                                         cur = req;
25789                                         goto out;
25790 @@ -2041,6 +2047,10 @@ get_req:
25791         }
25792  get_sk:
25793         sk_nulls_for_each_from(sk, node) {
25794 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
25795 +                       sk, sk->sk_nid, nx_current_nid());
25796 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25797 +                       continue;
25798                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net)) {
25799                         cur = sk;
25800                         goto out;
25801 @@ -2115,6 +2125,11 @@ static void *established_get_first(struc
25802  
25803                 spin_lock_bh(lock);
25804                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
25805 +                       vxdprintk(VXD_CBIT(net, 6),
25806 +                               "sk,egf: %p [#%d] (from %d)",
25807 +                               sk, sk->sk_nid, nx_current_nid());
25808 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25809 +                               continue;
25810                         if (sk->sk_family != st->family ||
25811                             !net_eq(sock_net(sk), net)) {
25812                                 continue;
25813 @@ -2125,6 +2140,11 @@ static void *established_get_first(struc
25814                 st->state = TCP_SEQ_STATE_TIME_WAIT;
25815                 inet_twsk_for_each(tw, node,
25816                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
25817 +                       vxdprintk(VXD_CBIT(net, 6),
25818 +                               "tw: %p [#%d] (from %d)",
25819 +                               tw, tw->tw_nid, nx_current_nid());
25820 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
25821 +                               continue;
25822                         if (tw->tw_family != st->family ||
25823                             !net_eq(twsk_net(tw), net)) {
25824                                 continue;
25825 @@ -2154,7 +2174,9 @@ static void *established_get_next(struct
25826                 tw = cur;
25827                 tw = tw_next(tw);
25828  get_tw:
25829 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
25830 +               while (tw && (tw->tw_family != st->family ||
25831 +                       !net_eq(twsk_net(tw), net) ||
25832 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
25833                         tw = tw_next(tw);
25834                 }
25835                 if (tw) {
25836 @@ -2178,6 +2200,11 @@ get_tw:
25837                 sk = sk_nulls_next(sk);
25838  
25839         sk_nulls_for_each_from(sk, node) {
25840 +               vxdprintk(VXD_CBIT(net, 6),
25841 +                       "sk,egn: %p [#%d] (from %d)",
25842 +                       sk, sk->sk_nid, nx_current_nid());
25843 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25844 +                       continue;
25845                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
25846                         goto found;
25847         }
25848 @@ -2387,9 +2414,9 @@ static void get_openreq4(struct sock *sk
25849         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
25850                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p%n",
25851                 i,
25852 -               ireq->loc_addr,
25853 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
25854                 ntohs(inet_sk(sk)->inet_sport),
25855 -               ireq->rmt_addr,
25856 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
25857                 ntohs(ireq->rmt_port),
25858                 TCP_SYN_RECV,
25859                 0, 0, /* could print option size, but that is af dependent. */
25860 @@ -2441,7 +2468,10 @@ static void get_tcp4_sock(struct sock *s
25861  
25862         seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
25863                         "%08X %5d %8d %lu %d %p %lu %lu %u %u %d%n",
25864 -               i, src, srcp, dest, destp, sk->sk_state,
25865 +               i,
25866 +               nx_map_sock_lback(current_nx_info(), src), srcp,
25867 +               nx_map_sock_lback(current_nx_info(), dest), destp,
25868 +               sk->sk_state,
25869                 tp->write_seq - tp->snd_una,
25870                 rx_queue,
25871                 timer_active,
25872 @@ -2476,7 +2506,10 @@ static void get_timewait4_sock(struct in
25873  
25874         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
25875                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
25876 -               i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
25877 +               i,
25878 +               nx_map_sock_lback(current_nx_info(), src), srcp,
25879 +               nx_map_sock_lback(current_nx_info(), dest), destp,
25880 +               tw->tw_substate, 0, 0,
25881                 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
25882                 atomic_read(&tw->tw_refcnt), tw, len);
25883  }
25884 diff -NurpP --minimal linux-2.6.36/net/ipv4/tcp_minisocks.c linux-2.6.36-vs2.3.0.36.36/net/ipv4/tcp_minisocks.c
25885 --- linux-2.6.36/net/ipv4/tcp_minisocks.c       2010-10-21 13:07:58.000000000 +0200
25886 +++ linux-2.6.36-vs2.3.0.36.36/net/ipv4/tcp_minisocks.c 2010-10-21 13:09:36.000000000 +0200
25887 @@ -23,6 +23,9 @@
25888  #include <linux/slab.h>
25889  #include <linux/sysctl.h>
25890  #include <linux/workqueue.h>
25891 +#include <linux/vs_limit.h>
25892 +#include <linux/vs_socket.h>
25893 +#include <linux/vs_context.h>
25894  #include <net/tcp.h>
25895  #include <net/inet_common.h>
25896  #include <net/xfrm.h>
25897 @@ -290,6 +293,11 @@ void tcp_time_wait(struct sock *sk, int 
25898                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
25899                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
25900  
25901 +               tw->tw_xid              = sk->sk_xid;
25902 +               tw->tw_vx_info          = NULL;
25903 +               tw->tw_nid              = sk->sk_nid;
25904 +               tw->tw_nx_info          = NULL;
25905 +
25906  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
25907                 if (tw->tw_family == PF_INET6) {
25908                         struct ipv6_pinfo *np = inet6_sk(sk);
25909 diff -NurpP --minimal linux-2.6.36/net/ipv4/udp.c linux-2.6.36-vs2.3.0.36.36/net/ipv4/udp.c
25910 --- linux-2.6.36/net/ipv4/udp.c 2010-10-21 13:07:59.000000000 +0200
25911 +++ linux-2.6.36-vs2.3.0.36.36/net/ipv4/udp.c   2010-10-21 13:09:36.000000000 +0200
25912 @@ -296,14 +296,7 @@ fail:
25913  }
25914  EXPORT_SYMBOL(udp_lib_get_port);
25915  
25916 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25917 -{
25918 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
25919 -
25920 -       return  (!ipv6_only_sock(sk2)  &&
25921 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
25922 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
25923 -}
25924 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
25925  
25926  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
25927                                        unsigned int port)
25928 @@ -338,6 +331,11 @@ static inline int compute_score(struct s
25929                         if (inet->inet_rcv_saddr != daddr)
25930                                 return -1;
25931                         score += 2;
25932 +               } else {
25933 +                       /* block non nx_info ips */
25934 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
25935 +                               daddr, NXA_MASK_BIND))
25936 +                               return -1;
25937                 }
25938                 if (inet->inet_daddr) {
25939                         if (inet->inet_daddr != saddr)
25940 @@ -441,6 +439,7 @@ exact_match:
25941         return result;
25942  }
25943  
25944 +
25945  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
25946   * harder than this. -DaveM
25947   */
25948 @@ -486,6 +485,11 @@ begin:
25949         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
25950                 score = compute_score(sk, net, saddr, hnum, sport,
25951                                       daddr, dport, dif);
25952 +               /* FIXME: disabled?
25953 +               if (score == 9) {
25954 +                       result = sk;
25955 +                       break;
25956 +               } else */
25957                 if (score > badness) {
25958                         result = sk;
25959                         badness = score;
25960 @@ -499,6 +503,7 @@ begin:
25961         if (get_nulls_value(node) != slot)
25962                 goto begin;
25963  
25964 +
25965         if (result) {
25966                 if (unlikely(!atomic_inc_not_zero(&result->sk_refcnt)))
25967                         result = NULL;
25968 @@ -508,6 +513,7 @@ begin:
25969                         goto begin;
25970                 }
25971         }
25972 +
25973         rcu_read_unlock();
25974         return result;
25975  }
25976 @@ -550,8 +556,7 @@ static inline struct sock *udp_v4_mcast_
25977                     udp_sk(s)->udp_port_hash != hnum ||
25978                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
25979                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
25980 -                   (inet->inet_rcv_saddr &&
25981 -                    inet->inet_rcv_saddr != loc_addr) ||
25982 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
25983                     ipv6_only_sock(s) ||
25984                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
25985                         continue;
25986 @@ -900,8 +905,13 @@ int udp_sendmsg(struct kiocb *iocb, stru
25987                                                { .sport = inet->inet_sport,
25988                                                  .dport = dport } } };
25989                 struct net *net = sock_net(sk);
25990 +               struct nx_info *nxi = sk->sk_nx_info;
25991  
25992                 security_sk_classify_flow(sk, &fl);
25993 +               err = ip_v4_find_src(net, nxi, &rt, &fl);
25994 +               if (err)
25995 +                       goto out;
25996 +
25997                 err = ip_route_output_flow(net, &rt, &fl, sk, 1);
25998                 if (err) {
25999                         if (err == -ENETUNREACH)
26000 @@ -1183,7 +1193,8 @@ try_again:
26001         if (sin) {
26002                 sin->sin_family = AF_INET;
26003                 sin->sin_port = udp_hdr(skb)->source;
26004 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
26005 +               sin->sin_addr.s_addr = nx_map_sock_lback(
26006 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
26007                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
26008         }
26009         if (inet->cmsg_flags)
26010 @@ -1923,6 +1934,8 @@ static struct sock *udp_get_first(struct
26011                 sk_nulls_for_each(sk, node, &hslot->head) {
26012                         if (!net_eq(sock_net(sk), net))
26013                                 continue;
26014 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26015 +                               continue;
26016                         if (sk->sk_family == state->family)
26017                                 goto found;
26018                 }
26019 @@ -1940,7 +1953,9 @@ static struct sock *udp_get_next(struct 
26020  
26021         do {
26022                 sk = sk_nulls_next(sk);
26023 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
26024 +       } while (sk && (!net_eq(sock_net(sk), net) ||
26025 +               sk->sk_family != state->family ||
26026 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
26027  
26028         if (!sk) {
26029                 if (state->bucket <= state->udp_table->mask)
26030 @@ -2047,7 +2062,10 @@ static void udp4_format_sock(struct sock
26031  
26032         seq_printf(f, "%5d: %08X:%04X %08X:%04X"
26033                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d%n",
26034 -               bucket, src, srcp, dest, destp, sp->sk_state,
26035 +               bucket,
26036 +               nx_map_sock_lback(current_nx_info(), src), srcp,
26037 +               nx_map_sock_lback(current_nx_info(), dest), destp,
26038 +               sp->sk_state,
26039                 sk_wmem_alloc_get(sp),
26040                 sk_rmem_alloc_get(sp),
26041                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
26042 diff -NurpP --minimal linux-2.6.36/net/ipv6/addrconf.c linux-2.6.36-vs2.3.0.36.36/net/ipv6/addrconf.c
26043 --- linux-2.6.36/net/ipv6/addrconf.c    2010-10-21 13:07:59.000000000 +0200
26044 +++ linux-2.6.36-vs2.3.0.36.36/net/ipv6/addrconf.c      2010-10-21 13:09:36.000000000 +0200
26045 @@ -87,6 +87,8 @@
26046  
26047  #include <linux/proc_fs.h>
26048  #include <linux/seq_file.h>
26049 +#include <linux/vs_network.h>
26050 +#include <linux/vs_inet6.h>
26051  
26052  /* Set to 3 to get tracing... */
26053  #define ACONF_DEBUG 2
26054 @@ -1119,7 +1121,7 @@ out:
26055  
26056  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
26057                        const struct in6_addr *daddr, unsigned int prefs,
26058 -                      struct in6_addr *saddr)
26059 +                      struct in6_addr *saddr, struct nx_info *nxi)
26060  {
26061         struct ipv6_saddr_score scores[2],
26062                                 *score = &scores[0], *hiscore = &scores[1];
26063 @@ -1191,6 +1193,8 @@ int ipv6_dev_get_saddr(struct net *net, 
26064                                                dev->name);
26065                                 continue;
26066                         }
26067 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
26068 +                               continue;
26069  
26070                         score->rule = -1;
26071                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
26072 @@ -3077,7 +3081,10 @@ static void if6_seq_stop(struct seq_file
26073  static int if6_seq_show(struct seq_file *seq, void *v)
26074  {
26075         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
26076 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
26077 +
26078 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
26079 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
26080 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
26081                    &ifp->addr,
26082                    ifp->idev->dev->ifindex,
26083                    ifp->prefix_len,
26084 @@ -3585,6 +3592,11 @@ static int in6_dump_addrs(struct inet6_d
26085         struct ifacaddr6 *ifaca;
26086         int err = 1;
26087         int ip_idx = *p_ip_idx;
26088 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
26089 +
26090 +       /* disable ipv6 on non v6 guests */
26091 +       if (nxi && !nx_info_has_v6(nxi))
26092 +               return skb->len;
26093  
26094         read_lock_bh(&idev->lock);
26095         switch (type) {
26096 @@ -3595,6 +3607,8 @@ static int in6_dump_addrs(struct inet6_d
26097                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
26098                         if (++ip_idx < s_ip_idx)
26099                                 continue;
26100 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
26101 +                                       continue;
26102                         err = inet6_fill_ifaddr(skb, ifa,
26103                                                 NETLINK_CB(cb->skb).pid,
26104                                                 cb->nlh->nlmsg_seq,
26105 @@ -3611,6 +3625,8 @@ static int in6_dump_addrs(struct inet6_d
26106                      ifmca = ifmca->next, ip_idx++) {
26107                         if (ip_idx < s_ip_idx)
26108                                 continue;
26109 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
26110 +                                       continue;
26111                         err = inet6_fill_ifmcaddr(skb, ifmca,
26112                                                   NETLINK_CB(cb->skb).pid,
26113                                                   cb->nlh->nlmsg_seq,
26114 @@ -3626,6 +3642,8 @@ static int in6_dump_addrs(struct inet6_d
26115                      ifaca = ifaca->aca_next, ip_idx++) {
26116                         if (ip_idx < s_ip_idx)
26117                                 continue;
26118 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
26119 +                                       continue;
26120                         err = inet6_fill_ifacaddr(skb, ifaca,
26121                                                   NETLINK_CB(cb->skb).pid,
26122                                                   cb->nlh->nlmsg_seq,
26123 @@ -3973,6 +3991,11 @@ static int inet6_dump_ifinfo(struct sk_b
26124         struct inet6_dev *idev;
26125         struct hlist_head *head;
26126         struct hlist_node *node;
26127 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
26128 +
26129 +       /* FIXME: maybe disable ipv6 on non v6 guests?
26130 +       if (skb->sk && skb->sk->sk_vx_info)
26131 +               return skb->len; */
26132  
26133         s_h = cb->args[0];
26134         s_idx = cb->args[1];
26135 @@ -3984,6 +4007,8 @@ static int inet6_dump_ifinfo(struct sk_b
26136                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
26137                         if (idx < s_idx)
26138                                 goto cont;
26139 +                       if (!v6_dev_in_nx_info(dev, nxi))
26140 +                               goto cont;
26141                         idev = __in6_dev_get(dev);
26142                         if (!idev)
26143                                 goto cont;
26144 diff -NurpP --minimal linux-2.6.36/net/ipv6/af_inet6.c linux-2.6.36-vs2.3.0.36.36/net/ipv6/af_inet6.c
26145 --- linux-2.6.36/net/ipv6/af_inet6.c    2010-10-21 13:07:59.000000000 +0200
26146 +++ linux-2.6.36-vs2.3.0.36.36/net/ipv6/af_inet6.c      2010-10-21 13:09:36.000000000 +0200
26147 @@ -42,6 +42,8 @@
26148  #include <linux/netdevice.h>
26149  #include <linux/icmpv6.h>
26150  #include <linux/netfilter_ipv6.h>
26151 +#include <linux/vs_inet.h>
26152 +#include <linux/vs_inet6.h>
26153  
26154  #include <net/ip.h>
26155  #include <net/ipv6.h>
26156 @@ -160,9 +162,12 @@ lookup_protocol:
26157         }
26158  
26159         err = -EPERM;
26160 +       if ((protocol == IPPROTO_ICMPV6) &&
26161 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
26162 +               goto override;
26163         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
26164                 goto out_rcu_unlock;
26165 -
26166 +override:
26167         sock->ops = answer->ops;
26168         answer_prot = answer->prot;
26169         answer_no_check = answer->no_check;
26170 @@ -261,6 +266,7 @@ int inet6_bind(struct socket *sock, stru
26171         struct inet_sock *inet = inet_sk(sk);
26172         struct ipv6_pinfo *np = inet6_sk(sk);
26173         struct net *net = sock_net(sk);
26174 +       struct nx_v6_sock_addr nsa;
26175         __be32 v4addr = 0;
26176         unsigned short snum;
26177         int addr_type = 0;
26178 @@ -272,6 +278,11 @@ int inet6_bind(struct socket *sock, stru
26179  
26180         if (addr_len < SIN6_LEN_RFC2133)
26181                 return -EINVAL;
26182 +
26183 +       err = v6_map_sock_addr(inet, addr, &nsa);
26184 +       if (err)
26185 +               return err;
26186 +
26187         addr_type = ipv6_addr_type(&addr->sin6_addr);
26188         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
26189                 return -EINVAL;
26190 @@ -303,6 +314,7 @@ int inet6_bind(struct socket *sock, stru
26191                 /* Reproduce AF_INET checks to make the bindings consitant */
26192                 v4addr = addr->sin6_addr.s6_addr32[3];
26193                 chk_addr_ret = inet_addr_type(net, v4addr);
26194 +
26195                 if (!sysctl_ip_nonlocal_bind &&
26196                     !(inet->freebind || inet->transparent) &&
26197                     v4addr != htonl(INADDR_ANY) &&
26198 @@ -312,6 +324,10 @@ int inet6_bind(struct socket *sock, stru
26199                         err = -EADDRNOTAVAIL;
26200                         goto out;
26201                 }
26202 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
26203 +                       err = -EADDRNOTAVAIL;
26204 +                       goto out;
26205 +               }
26206         } else {
26207                 if (addr_type != IPV6_ADDR_ANY) {
26208                         struct net_device *dev = NULL;
26209 @@ -338,6 +354,11 @@ int inet6_bind(struct socket *sock, stru
26210                                 }
26211                         }
26212  
26213 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
26214 +                               err = -EADDRNOTAVAIL;
26215 +                               goto out;
26216 +                       }
26217 +
26218                         /* ipv4 addr of the socket is invalid.  Only the
26219                          * unspecified and mapped address have a v4 equivalent.
26220                          */
26221 @@ -353,6 +374,9 @@ int inet6_bind(struct socket *sock, stru
26222                 }
26223         }
26224  
26225 +       /* what's that for? */
26226 +       v6_set_sock_addr(inet, &nsa);
26227 +
26228         inet->inet_rcv_saddr = v4addr;
26229         inet->inet_saddr = v4addr;
26230  
26231 @@ -454,9 +478,11 @@ int inet6_getname(struct socket *sock, s
26232                         return -ENOTCONN;
26233                 sin->sin6_port = inet->inet_dport;
26234                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
26235 +               /* FIXME: remap lback? */
26236                 if (np->sndflow)
26237                         sin->sin6_flowinfo = np->flow_label;
26238         } else {
26239 +               /* FIXME: remap lback? */
26240                 if (ipv6_addr_any(&np->rcv_saddr))
26241                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
26242                 else
26243 diff -NurpP --minimal linux-2.6.36/net/ipv6/fib6_rules.c linux-2.6.36-vs2.3.0.36.36/net/ipv6/fib6_rules.c
26244 --- linux-2.6.36/net/ipv6/fib6_rules.c  2010-10-21 13:07:59.000000000 +0200
26245 +++ linux-2.6.36-vs2.3.0.36.36/net/ipv6/fib6_rules.c    2010-10-21 13:09:36.000000000 +0200
26246 @@ -89,7 +89,7 @@ static int fib6_rule_action(struct fib_r
26247                                                ip6_dst_idev(&rt->dst)->dev,
26248                                                &flp->fl6_dst,
26249                                                rt6_flags2srcprefs(flags),
26250 -                                              &saddr))
26251 +                                              &saddr, NULL))
26252                                 goto again;
26253                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
26254                                                r->src.plen))
26255 diff -NurpP --minimal linux-2.6.36/net/ipv6/inet6_hashtables.c linux-2.6.36-vs2.3.0.36.36/net/ipv6/inet6_hashtables.c
26256 --- linux-2.6.36/net/ipv6/inet6_hashtables.c    2010-02-25 11:52:10.000000000 +0100
26257 +++ linux-2.6.36-vs2.3.0.36.36/net/ipv6/inet6_hashtables.c      2010-10-21 13:09:36.000000000 +0200
26258 @@ -16,6 +16,7 @@
26259  
26260  #include <linux/module.h>
26261  #include <linux/random.h>
26262 +#include <linux/vs_inet6.h>
26263  
26264  #include <net/inet_connection_sock.h>
26265  #include <net/inet_hashtables.h>
26266 @@ -82,7 +83,6 @@ struct sock *__inet6_lookup_established(
26267         unsigned int slot = hash & hashinfo->ehash_mask;
26268         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
26269  
26270 -
26271         rcu_read_lock();
26272  begin:
26273         sk_nulls_for_each_rcu(sk, node, &head->chain) {
26274 @@ -94,7 +94,7 @@ begin:
26275                                 sock_put(sk);
26276                                 goto begin;
26277                         }
26278 -               goto out;
26279 +                       goto out;
26280                 }
26281         }
26282         if (get_nulls_value(node) != slot)
26283 @@ -140,6 +140,9 @@ static int inline compute_score(struct s
26284                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
26285                                 return -1;
26286                         score++;
26287 +               } else {
26288 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
26289 +                               return -1;
26290                 }
26291                 if (sk->sk_bound_dev_if) {
26292                         if (sk->sk_bound_dev_if != dif)
26293 diff -NurpP --minimal linux-2.6.36/net/ipv6/ip6_output.c linux-2.6.36-vs2.3.0.36.36/net/ipv6/ip6_output.c
26294 --- linux-2.6.36/net/ipv6/ip6_output.c  2010-10-21 13:07:59.000000000 +0200
26295 +++ linux-2.6.36-vs2.3.0.36.36/net/ipv6/ip6_output.c    2010-10-21 13:09:36.000000000 +0200
26296 @@ -938,7 +938,7 @@ static int ip6_dst_lookup_tail(struct so
26297                 err = ipv6_dev_get_saddr(net, ip6_dst_idev(*dst)->dev,
26298                                          &fl->fl6_dst,
26299                                          sk ? inet6_sk(sk)->srcprefs : 0,
26300 -                                        &fl->fl6_src);
26301 +                                        &fl->fl6_src, sk->sk_nx_info);
26302                 if (err)
26303                         goto out_err_release;
26304         }
26305 diff -NurpP --minimal linux-2.6.36/net/ipv6/Kconfig linux-2.6.36-vs2.3.0.36.36/net/ipv6/Kconfig
26306 --- linux-2.6.36/net/ipv6/Kconfig       2010-08-02 16:52:59.000000000 +0200
26307 +++ linux-2.6.36-vs2.3.0.36.36/net/ipv6/Kconfig 2010-10-21 13:09:36.000000000 +0200
26308 @@ -4,8 +4,8 @@
26309  
26310  #   IPv6 as module will cause a CRASH if you try to unload it
26311  menuconfig IPV6
26312 -       tristate "The IPv6 protocol"
26313 -       default m
26314 +       bool "The IPv6 protocol"
26315 +       default n
26316         ---help---
26317           This is complemental support for the IP version 6.
26318           You will still be able to do traditional IPv4 networking as well.
26319 diff -NurpP --minimal linux-2.6.36/net/ipv6/ndisc.c linux-2.6.36-vs2.3.0.36.36/net/ipv6/ndisc.c
26320 --- linux-2.6.36/net/ipv6/ndisc.c       2010-10-21 13:07:59.000000000 +0200
26321 +++ linux-2.6.36-vs2.3.0.36.36/net/ipv6/ndisc.c 2010-10-21 13:09:36.000000000 +0200
26322 @@ -591,7 +591,7 @@ static void ndisc_send_na(struct net_dev
26323         } else {
26324                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
26325                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
26326 -                                      &tmpaddr))
26327 +                                      &tmpaddr, NULL /* FIXME: ? */ ))
26328                         return;
26329                 src_addr = &tmpaddr;
26330         }
26331 diff -NurpP --minimal linux-2.6.36/net/ipv6/raw.c linux-2.6.36-vs2.3.0.36.36/net/ipv6/raw.c
26332 --- linux-2.6.36/net/ipv6/raw.c 2010-10-21 13:07:59.000000000 +0200
26333 +++ linux-2.6.36-vs2.3.0.36.36/net/ipv6/raw.c   2010-10-21 13:09:36.000000000 +0200
26334 @@ -30,6 +30,7 @@
26335  #include <linux/icmpv6.h>
26336  #include <linux/netfilter.h>
26337  #include <linux/netfilter_ipv6.h>
26338 +#include <linux/vs_inet6.h>
26339  #include <linux/skbuff.h>
26340  #include <asm/uaccess.h>
26341  #include <asm/ioctls.h>
26342 @@ -283,6 +284,13 @@ static int rawv6_bind(struct sock *sk, s
26343                                 goto out_unlock;
26344                 }
26345  
26346 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
26347 +                       err = -EADDRNOTAVAIL;
26348 +                       if (dev)
26349 +                               dev_put(dev);
26350 +                       goto out;
26351 +               }
26352 +
26353                 /* ipv4 addr of the socket is invalid.  Only the
26354                  * unspecified and mapped address have a v4 equivalent.
26355                  */
26356 diff -NurpP --minimal linux-2.6.36/net/ipv6/route.c linux-2.6.36-vs2.3.0.36.36/net/ipv6/route.c
26357 --- linux-2.6.36/net/ipv6/route.c       2010-10-21 13:07:59.000000000 +0200
26358 +++ linux-2.6.36-vs2.3.0.36.36/net/ipv6/route.c 2010-10-21 13:09:36.000000000 +0200
26359 @@ -2272,7 +2272,8 @@ static int rt6_fill_node(struct net *net
26360                 struct inet6_dev *idev = ip6_dst_idev(&rt->dst);
26361                 struct in6_addr saddr_buf;
26362                 if (ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
26363 -                                      dst, 0, &saddr_buf) == 0)
26364 +                       dst, 0, &saddr_buf,
26365 +                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
26366                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
26367         }
26368  
26369 diff -NurpP --minimal linux-2.6.36/net/ipv6/tcp_ipv6.c linux-2.6.36-vs2.3.0.36.36/net/ipv6/tcp_ipv6.c
26370 --- linux-2.6.36/net/ipv6/tcp_ipv6.c    2010-10-21 13:07:59.000000000 +0200
26371 +++ linux-2.6.36-vs2.3.0.36.36/net/ipv6/tcp_ipv6.c      2010-10-21 13:09:36.000000000 +0200
26372 @@ -69,6 +69,7 @@
26373  
26374  #include <linux/crypto.h>
26375  #include <linux/scatterlist.h>
26376 +#include <linux/vs_inet6.h>
26377  
26378  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
26379  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
26380 @@ -160,8 +161,15 @@ static int tcp_v6_connect(struct sock *s
26381          *      connect() to INADDR_ANY means loopback (BSD'ism).
26382          */
26383  
26384 -       if(ipv6_addr_any(&usin->sin6_addr))
26385 -               usin->sin6_addr.s6_addr[15] = 0x1;
26386 +       if(ipv6_addr_any(&usin->sin6_addr)) {
26387 +               struct nx_info *nxi =  sk->sk_nx_info;
26388 +
26389 +               if (nxi && nx_info_has_v6(nxi))
26390 +                       /* FIXME: remap lback? */
26391 +                       usin->sin6_addr = nxi->v6.ip;
26392 +               else
26393 +                       usin->sin6_addr.s6_addr[15] = 0x1;
26394 +       }
26395  
26396         addr_type = ipv6_addr_type(&usin->sin6_addr);
26397  
26398 diff -NurpP --minimal linux-2.6.36/net/ipv6/udp.c linux-2.6.36-vs2.3.0.36.36/net/ipv6/udp.c
26399 --- linux-2.6.36/net/ipv6/udp.c 2010-10-21 13:07:59.000000000 +0200
26400 +++ linux-2.6.36-vs2.3.0.36.36/net/ipv6/udp.c   2010-10-21 13:09:36.000000000 +0200
26401 @@ -48,13 +48,14 @@
26402  
26403  #include <linux/proc_fs.h>
26404  #include <linux/seq_file.h>
26405 +#include <linux/vs_inet6.h>
26406  #include "udp_impl.h"
26407  
26408  int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
26409  {
26410         const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
26411         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
26412 -       __be32 sk1_rcv_saddr = inet_sk(sk)->inet_rcv_saddr;
26413 +       __be32 sk_rcv_saddr = inet_sk(sk)->inet_rcv_saddr;
26414         __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
26415         int sk_ipv6only = ipv6_only_sock(sk);
26416         int sk2_ipv6only = inet_v6_ipv6only(sk2);
26417 @@ -62,24 +63,49 @@ int ipv6_rcv_saddr_equal(const struct so
26418         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
26419  
26420         /* if both are mapped, treat as IPv4 */
26421 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
26422 -               return (!sk2_ipv6only &&
26423 -                       (!sk1_rcv_saddr || !sk2_rcv_saddr ||
26424 -                         sk1_rcv_saddr == sk2_rcv_saddr));
26425 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
26426 +               if (!sk2_ipv6only &&
26427 +                       (!sk_rcv_saddr || !sk2_rcv_saddr ||
26428 +                         sk_rcv_saddr == sk2_rcv_saddr))
26429 +                       goto vs_v4;
26430 +               else
26431 +                       return 0;
26432 +       }
26433  
26434         if (addr_type2 == IPV6_ADDR_ANY &&
26435             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
26436 -               return 1;
26437 +               goto vs;
26438  
26439         if (addr_type == IPV6_ADDR_ANY &&
26440             !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
26441 -               return 1;
26442 +               goto vs;
26443  
26444         if (sk2_rcv_saddr6 &&
26445             ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
26446 -               return 1;
26447 +               goto vs;
26448  
26449         return 0;
26450 +
26451 +vs_v4:
26452 +       if (!sk_rcv_saddr && !sk2_rcv_saddr)
26453 +               return nx_v4_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info);
26454 +       if (!sk2_rcv_saddr)
26455 +               return v4_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr, -1);
26456 +       if (!sk_rcv_saddr)
26457 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr, -1);
26458 +       return 1;
26459 +vs:
26460 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
26461 +               return nx_v6_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info);
26462 +       else if (addr_type2 == IPV6_ADDR_ANY)
26463 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr6, -1);
26464 +       else if (addr_type == IPV6_ADDR_ANY) {
26465 +               if (addr_type2 == IPV6_ADDR_MAPPED)
26466 +                       return nx_v4_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info);
26467 +               else
26468 +                       return v6_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr6, -1);
26469 +       }
26470 +       return 1;
26471  }
26472  
26473  static unsigned int udp6_portaddr_hash(struct net *net,
26474 @@ -143,6 +169,10 @@ static inline int compute_score(struct s
26475                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
26476                                 return -1;
26477                         score++;
26478 +               } else {
26479 +                       /* block non nx_info ips */
26480 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
26481 +                               return -1;
26482                 }
26483                 if (!ipv6_addr_any(&np->daddr)) {
26484                         if (!ipv6_addr_equal(&np->daddr, saddr))
26485 diff -NurpP --minimal linux-2.6.36/net/ipv6/xfrm6_policy.c linux-2.6.36-vs2.3.0.36.36/net/ipv6/xfrm6_policy.c
26486 --- linux-2.6.36/net/ipv6/xfrm6_policy.c        2010-08-02 16:53:00.000000000 +0200
26487 +++ linux-2.6.36-vs2.3.0.36.36/net/ipv6/xfrm6_policy.c  2010-10-21 13:09:36.000000000 +0200
26488 @@ -62,7 +62,7 @@ static int xfrm6_get_saddr(struct net *n
26489         dev = ip6_dst_idev(dst)->dev;
26490         ipv6_dev_get_saddr(dev_net(dev), dev,
26491                            (struct in6_addr *)&daddr->a6, 0,
26492 -                          (struct in6_addr *)&saddr->a6);
26493 +                          (struct in6_addr *)&saddr->a6, NULL);
26494         dst_release(dst);
26495         return 0;
26496  }
26497 diff -NurpP --minimal linux-2.6.36/net/netlink/af_netlink.c linux-2.6.36-vs2.3.0.36.36/net/netlink/af_netlink.c
26498 --- linux-2.6.36/net/netlink/af_netlink.c       2010-10-21 13:08:01.000000000 +0200
26499 +++ linux-2.6.36-vs2.3.0.36.36/net/netlink/af_netlink.c 2010-10-21 13:09:36.000000000 +0200
26500 @@ -55,6 +55,9 @@
26501  #include <linux/types.h>
26502  #include <linux/audit.h>
26503  #include <linux/mutex.h>
26504 +#include <linux/vs_context.h>
26505 +#include <linux/vs_network.h>
26506 +#include <linux/vs_limit.h>
26507  
26508  #include <net/net_namespace.h>
26509  #include <net/sock.h>
26510 @@ -1928,6 +1931,8 @@ static struct sock *netlink_seq_socket_i
26511                         sk_for_each(s, node, &hash->table[j]) {
26512                                 if (sock_net(s) != seq_file_net(seq))
26513                                         continue;
26514 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26515 +                                       continue;
26516                                 if (off == pos) {
26517                                         iter->link = i;
26518                                         iter->hash_idx = j;
26519 @@ -1962,7 +1967,8 @@ static void *netlink_seq_next(struct seq
26520         s = v;
26521         do {
26522                 s = sk_next(s);
26523 -       } while (s && sock_net(s) != seq_file_net(seq));
26524 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
26525 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
26526         if (s)
26527                 return s;
26528  
26529 @@ -1974,7 +1980,8 @@ static void *netlink_seq_next(struct seq
26530  
26531                 for (; j <= hash->mask; j++) {
26532                         s = sk_head(&hash->table[j]);
26533 -                       while (s && sock_net(s) != seq_file_net(seq))
26534 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
26535 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
26536                                 s = sk_next(s);
26537                         if (s) {
26538                                 iter->link = i;
26539 diff -NurpP --minimal linux-2.6.36/net/sctp/ipv6.c linux-2.6.36-vs2.3.0.36.36/net/sctp/ipv6.c
26540 --- linux-2.6.36/net/sctp/ipv6.c        2010-08-02 16:53:01.000000000 +0200
26541 +++ linux-2.6.36-vs2.3.0.36.36/net/sctp/ipv6.c  2010-10-21 13:09:36.000000000 +0200
26542 @@ -304,7 +304,8 @@ static void sctp_v6_get_saddr(struct sct
26543                                    dst ? ip6_dst_idev(dst)->dev : NULL,
26544                                    &daddr->v6.sin6_addr,
26545                                    inet6_sk(&sk->inet.sk)->srcprefs,
26546 -                                  &saddr->v6.sin6_addr);
26547 +                                  &saddr->v6.sin6_addr,
26548 +                                  asoc->base.sk->sk_nx_info);
26549                 SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: %pI6\n",
26550                                   &saddr->v6.sin6_addr);
26551                 return;
26552 diff -NurpP --minimal linux-2.6.36/net/socket.c linux-2.6.36-vs2.3.0.36.36/net/socket.c
26553 --- linux-2.6.36/net/socket.c   2010-10-21 13:08:01.000000000 +0200
26554 +++ linux-2.6.36-vs2.3.0.36.36/net/socket.c     2010-10-21 13:09:36.000000000 +0200
26555 @@ -98,6 +98,10 @@
26556  
26557  #include <net/sock.h>
26558  #include <linux/netfilter.h>
26559 +#include <linux/vs_base.h>
26560 +#include <linux/vs_socket.h>
26561 +#include <linux/vs_inet.h>
26562 +#include <linux/vs_inet6.h>
26563  
26564  #include <linux/if_tun.h>
26565  #include <linux/ipv6_route.h>
26566 @@ -551,7 +555,7 @@ static inline int __sock_sendmsg(struct 
26567                                  struct msghdr *msg, size_t size)
26568  {
26569         struct sock_iocb *si = kiocb_to_siocb(iocb);
26570 -       int err;
26571 +       int err, len;
26572  
26573         sock_update_classid(sock->sk);
26574  
26575 @@ -564,7 +568,22 @@ static inline int __sock_sendmsg(struct 
26576         if (err)
26577                 return err;
26578  
26579 -       return sock->ops->sendmsg(iocb, sock, msg, size);
26580 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
26581 +       if (sock->sk) {
26582 +               if (len == size)
26583 +                       vx_sock_send(sock->sk, size);
26584 +               else
26585 +                       vx_sock_fail(sock->sk, size);
26586 +       }
26587 +       vxdprintk(VXD_CBIT(net, 7),
26588 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
26589 +               sock, sock->sk,
26590 +               (sock->sk)?sock->sk->sk_nx_info:0,
26591 +               (sock->sk)?sock->sk->sk_vx_info:0,
26592 +               (sock->sk)?sock->sk->sk_xid:0,
26593 +               (sock->sk)?sock->sk->sk_nid:0,
26594 +               (unsigned int)size, len);
26595 +       return len;
26596  }
26597  
26598  int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
26599 @@ -681,6 +700,7 @@ static inline int __sock_recvmsg_nosec(s
26600                                        struct msghdr *msg, size_t size, int flags)
26601  {
26602         struct sock_iocb *si = kiocb_to_siocb(iocb);
26603 +       int len;
26604  
26605         sock_update_classid(sock->sk);
26606  
26607 @@ -690,7 +710,18 @@ static inline int __sock_recvmsg_nosec(s
26608         si->size = size;
26609         si->flags = flags;
26610  
26611 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
26612 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
26613 +       if ((len >= 0) && sock->sk)
26614 +               vx_sock_recv(sock->sk, len);
26615 +       vxdprintk(VXD_CBIT(net, 7),
26616 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
26617 +               sock, sock->sk,
26618 +               (sock->sk)?sock->sk->sk_nx_info:0,
26619 +               (sock->sk)?sock->sk->sk_vx_info:0,
26620 +               (sock->sk)?sock->sk->sk_xid:0,
26621 +               (sock->sk)?sock->sk->sk_nid:0,
26622 +               (unsigned int)size, len);
26623 +       return len;
26624  }
26625  
26626  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
26627 @@ -1159,6 +1190,13 @@ static int __sock_create(struct net *net
26628         if (type < 0 || type >= SOCK_MAX)
26629                 return -EINVAL;
26630  
26631 +       if (!nx_check(0, VS_ADMIN)) {
26632 +               if (family == PF_INET && !current_nx_info_has_v4())
26633 +                       return -EAFNOSUPPORT;
26634 +               if (family == PF_INET6 && !current_nx_info_has_v6())
26635 +                       return -EAFNOSUPPORT;
26636 +       }
26637 +
26638         /* Compatibility.
26639  
26640            This uglymoron is moved from INET layer to here to avoid
26641 @@ -1293,6 +1331,7 @@ SYSCALL_DEFINE3(socket, int, family, int
26642         if (retval < 0)
26643                 goto out;
26644  
26645 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
26646         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
26647         if (retval < 0)
26648                 goto out_release;
26649 @@ -1334,10 +1373,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
26650         err = sock_create(family, type, protocol, &sock1);
26651         if (err < 0)
26652                 goto out;
26653 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
26654  
26655         err = sock_create(family, type, protocol, &sock2);
26656         if (err < 0)
26657                 goto out_release_1;
26658 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
26659  
26660         err = sock1->ops->socketpair(sock1, sock2);
26661         if (err < 0)
26662 diff -NurpP --minimal linux-2.6.36/net/sunrpc/auth.c linux-2.6.36-vs2.3.0.36.36/net/sunrpc/auth.c
26663 --- linux-2.6.36/net/sunrpc/auth.c      2010-10-21 13:08:01.000000000 +0200
26664 +++ linux-2.6.36-vs2.3.0.36.36/net/sunrpc/auth.c        2010-10-21 13:09:36.000000000 +0200
26665 @@ -14,6 +14,7 @@
26666  #include <linux/hash.h>
26667  #include <linux/sunrpc/clnt.h>
26668  #include <linux/spinlock.h>
26669 +#include <linux/vs_tag.h>
26670  
26671  #ifdef RPC_DEBUG
26672  # define RPCDBG_FACILITY       RPCDBG_AUTH
26673 @@ -425,6 +426,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
26674         memset(&acred, 0, sizeof(acred));
26675         acred.uid = cred->fsuid;
26676         acred.gid = cred->fsgid;
26677 +       acred.tag = dx_current_tag();
26678         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
26679  
26680         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
26681 @@ -465,6 +467,7 @@ rpcauth_bind_root_cred(struct rpc_task *
26682         struct auth_cred acred = {
26683                 .uid = 0,
26684                 .gid = 0,
26685 +               .tag = dx_current_tag(),
26686         };
26687  
26688         dprintk("RPC: %5u looking up %s cred\n",
26689 diff -NurpP --minimal linux-2.6.36/net/sunrpc/auth_unix.c linux-2.6.36-vs2.3.0.36.36/net/sunrpc/auth_unix.c
26690 --- linux-2.6.36/net/sunrpc/auth_unix.c 2010-10-21 13:08:01.000000000 +0200
26691 +++ linux-2.6.36-vs2.3.0.36.36/net/sunrpc/auth_unix.c   2010-10-21 13:09:36.000000000 +0200
26692 @@ -12,12 +12,14 @@
26693  #include <linux/module.h>
26694  #include <linux/sunrpc/clnt.h>
26695  #include <linux/sunrpc/auth.h>
26696 +#include <linux/vs_tag.h>
26697  
26698  #define NFS_NGROUPS    16
26699  
26700  struct unx_cred {
26701         struct rpc_cred         uc_base;
26702         gid_t                   uc_gid;
26703 +       tag_t                   uc_tag;
26704         gid_t                   uc_gids[NFS_NGROUPS];
26705  };
26706  #define uc_uid                 uc_base.cr_uid
26707 @@ -78,6 +80,7 @@ unx_create_cred(struct rpc_auth *auth, s
26708                 groups = NFS_NGROUPS;
26709  
26710         cred->uc_gid = acred->gid;
26711 +       cred->uc_tag = acred->tag;
26712         for (i = 0; i < groups; i++)
26713                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
26714         if (i < NFS_NGROUPS)
26715 @@ -119,7 +122,9 @@ unx_match(struct auth_cred *acred, struc
26716         unsigned int i;
26717  
26718  
26719 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
26720 +       if (cred->uc_uid != acred->uid ||
26721 +               cred->uc_gid != acred->gid ||
26722 +               cred->uc_tag != acred->tag)
26723                 return 0;
26724  
26725         if (acred->group_info != NULL)
26726 @@ -142,7 +147,7 @@ unx_marshal(struct rpc_task *task, __be3
26727         struct rpc_clnt *clnt = task->tk_client;
26728         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
26729         __be32          *base, *hold;
26730 -       int             i;
26731 +       int             i, tag;
26732  
26733         *p++ = htonl(RPC_AUTH_UNIX);
26734         base = p++;
26735 @@ -152,9 +157,12 @@ unx_marshal(struct rpc_task *task, __be3
26736          * Copy the UTS nodename captured when the client was created.
26737          */
26738         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
26739 +       tag = task->tk_client->cl_tag;
26740  
26741 -       *p++ = htonl((u32) cred->uc_uid);
26742 -       *p++ = htonl((u32) cred->uc_gid);
26743 +       *p++ = htonl((u32) TAGINO_UID(tag,
26744 +               cred->uc_uid, cred->uc_tag));
26745 +       *p++ = htonl((u32) TAGINO_GID(tag,
26746 +               cred->uc_gid, cred->uc_tag));
26747         hold = p++;
26748         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
26749                 *p++ = htonl((u32) cred->uc_gids[i]);
26750 diff -NurpP --minimal linux-2.6.36/net/sunrpc/clnt.c linux-2.6.36-vs2.3.0.36.36/net/sunrpc/clnt.c
26751 --- linux-2.6.36/net/sunrpc/clnt.c      2010-10-21 13:08:01.000000000 +0200
26752 +++ linux-2.6.36-vs2.3.0.36.36/net/sunrpc/clnt.c        2010-10-21 13:09:36.000000000 +0200
26753 @@ -33,6 +33,7 @@
26754  #include <linux/utsname.h>
26755  #include <linux/workqueue.h>
26756  #include <linux/in6.h>
26757 +#include <linux/vs_cvirt.h>
26758  
26759  #include <linux/sunrpc/clnt.h>
26760  #include <linux/sunrpc/rpc_pipe_fs.h>
26761 @@ -358,6 +359,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
26762         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
26763                 clnt->cl_chatty = 1;
26764  
26765 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
26766 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
26767 +               clnt->cl_tag = 1; */
26768         return clnt;
26769  }
26770  EXPORT_SYMBOL_GPL(rpc_create);
26771 diff -NurpP --minimal linux-2.6.36/net/unix/af_unix.c linux-2.6.36-vs2.3.0.36.36/net/unix/af_unix.c
26772 --- linux-2.6.36/net/unix/af_unix.c     2010-10-21 13:08:01.000000000 +0200
26773 +++ linux-2.6.36-vs2.3.0.36.36/net/unix/af_unix.c       2010-10-21 13:09:36.000000000 +0200
26774 @@ -114,6 +114,8 @@
26775  #include <linux/mount.h>
26776  #include <net/checksum.h>
26777  #include <linux/security.h>
26778 +#include <linux/vs_context.h>
26779 +#include <linux/vs_limit.h>
26780  
26781  static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
26782  static DEFINE_SPINLOCK(unix_table_lock);
26783 @@ -258,6 +260,8 @@ static struct sock *__unix_find_socket_b
26784                 if (!net_eq(sock_net(s), net))
26785                         continue;
26786  
26787 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26788 +                       continue;
26789                 if (u->addr->len == len &&
26790                     !memcmp(u->addr->name, sunname, len))
26791                         goto found;
26792 @@ -2148,6 +2152,8 @@ static struct sock *unix_seq_idx(struct 
26793         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
26794                 if (sock_net(s) != seq_file_net(seq))
26795                         continue;
26796 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26797 +                       continue;
26798                 if (off == pos)
26799                         return s;
26800                 ++off;
26801 @@ -2172,7 +2178,8 @@ static void *unix_seq_next(struct seq_fi
26802                 sk = first_unix_socket(&iter->i);
26803         else
26804                 sk = next_unix_socket(&iter->i, sk);
26805 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
26806 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
26807 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
26808                 sk = next_unix_socket(&iter->i, sk);
26809         return sk;
26810  }
26811 diff -NurpP --minimal linux-2.6.36/scripts/checksyscalls.sh linux-2.6.36-vs2.3.0.36.36/scripts/checksyscalls.sh
26812 --- linux-2.6.36/scripts/checksyscalls.sh       2010-10-21 13:08:01.000000000 +0200
26813 +++ linux-2.6.36-vs2.3.0.36.36/scripts/checksyscalls.sh 2010-10-21 13:09:36.000000000 +0200
26814 @@ -193,7 +193,6 @@ cat << EOF
26815  #define __IGNORE_afs_syscall
26816  #define __IGNORE_getpmsg
26817  #define __IGNORE_putpmsg
26818 -#define __IGNORE_vserver
26819  EOF
26820  }
26821  
26822 diff -NurpP --minimal linux-2.6.36/security/commoncap.c linux-2.6.36-vs2.3.0.36.36/security/commoncap.c
26823 --- linux-2.6.36/security/commoncap.c   2010-10-21 13:08:02.000000000 +0200
26824 +++ linux-2.6.36-vs2.3.0.36.36/security/commoncap.c     2010-10-21 13:09:36.000000000 +0200
26825 @@ -28,6 +28,7 @@
26826  #include <linux/prctl.h>
26827  #include <linux/securebits.h>
26828  #include <linux/syslog.h>
26829 +#include <linux/vs_context.h>
26830  
26831  /*
26832   * If a non-root user executes a setuid-root binary in
26833 @@ -53,7 +54,7 @@ static void warn_setuid_and_fcaps_mixed(
26834  
26835  int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
26836  {
26837 -       NETLINK_CB(skb).eff_cap = current_cap();
26838 +       NETLINK_CB(skb).eff_cap = vx_mbcaps(current_cap());
26839         return 0;
26840  }
26841  
26842 @@ -63,6 +64,7 @@ int cap_netlink_recv(struct sk_buff *skb
26843                 return -EPERM;
26844         return 0;
26845  }
26846 +
26847  EXPORT_SYMBOL(cap_netlink_recv);
26848  
26849  /**
26850 @@ -83,7 +85,22 @@ EXPORT_SYMBOL(cap_netlink_recv);
26851  int cap_capable(struct task_struct *tsk, const struct cred *cred, int cap,
26852                 int audit)
26853  {
26854 -       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
26855 +       struct vx_info *vxi = tsk->vx_info;
26856 +
26857 +#if 0
26858 +       printk("cap_capable() VXF_STATE_SETUP = %llx, raised = %x, eff = %08x:%08x\n",
26859 +               vx_info_flags(vxi, VXF_STATE_SETUP, 0),
26860 +               cap_raised(tsk->cap_effective, cap),
26861 +               tsk->cap_effective.cap[1], tsk->cap_effective.cap[0]);
26862 +#endif
26863 +
26864 +       /* special case SETUP */
26865 +       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
26866 +               /* FIXME: maybe use cred instead? */
26867 +               cap_raised(tsk->cred->cap_effective, cap))
26868 +               return 0;
26869 +
26870 +       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
26871  }
26872  
26873  /**
26874 @@ -571,7 +588,7 @@ int cap_inode_setxattr(struct dentry *de
26875  
26876         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26877                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26878 -           !capable(CAP_SYS_ADMIN))
26879 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26880                 return -EPERM;
26881         return 0;
26882  }
26883 @@ -597,7 +614,7 @@ int cap_inode_removexattr(struct dentry 
26884  
26885         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26886                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26887 -           !capable(CAP_SYS_ADMIN))
26888 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26889                 return -EPERM;
26890         return 0;
26891  }
26892 @@ -899,7 +916,8 @@ int cap_syslog(int type, bool from_file)
26893         if (type != SYSLOG_ACTION_OPEN && from_file)
26894                 return 0;
26895         if ((type != SYSLOG_ACTION_READ_ALL &&
26896 -            type != SYSLOG_ACTION_SIZE_BUFFER) && !capable(CAP_SYS_ADMIN))
26897 +            type != SYSLOG_ACTION_SIZE_BUFFER) &&
26898 +               !vx_capable(CAP_SYS_ADMIN, VXC_SYSLOG))
26899                 return -EPERM;
26900         return 0;
26901  }
26902 @@ -951,3 +969,4 @@ int cap_file_mmap(struct file *file, uns
26903         }
26904         return ret;
26905  }
26906 +
26907 diff -NurpP --minimal linux-2.6.36/security/selinux/hooks.c linux-2.6.36-vs2.3.0.36.36/security/selinux/hooks.c
26908 --- linux-2.6.36/security/selinux/hooks.c       2010-10-21 13:08:02.000000000 +0200
26909 +++ linux-2.6.36-vs2.3.0.36.36/security/selinux/hooks.c 2010-10-21 13:09:36.000000000 +0200
26910 @@ -64,7 +64,6 @@
26911  #include <linux/dccp.h>
26912  #include <linux/quota.h>
26913  #include <linux/un.h>          /* for Unix socket types */
26914 -#include <net/af_unix.h>       /* for Unix socket types */
26915  #include <linux/parser.h>
26916  #include <linux/nfs_mount.h>
26917  #include <net/ipv6.h>
This page took 2.25851 seconds and 4 git commands to generate.