]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- vserver for 2.6.36 + two delta patches
[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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/fs/devpts/inode.c        2010-10-21 13:09:36.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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/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.33/fs/namei.c       2010-10-21 14:45:53.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,77 @@ 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 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4945 +               struct proc_dir_entry *de = PDE(inode);
4946 +
4947 +               if (de && !vx_hide_check(0, de->vx_flags))
4948 +                       goto out;
4949 +
4950 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4951 +                       struct pid *pid;
4952 +                       struct task_struct *tsk;
4953 +
4954 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4955 +                           vx_flags(VXF_STATE_SETUP, 0))
4956 +                               return 0;
4957 +
4958 +                       pid = PROC_I(inode)->pid;
4959 +                       if (!pid)
4960 +                               goto out;
4961 +
4962 +                       tsk = pid_task(pid, PIDTYPE_PID);
4963 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4964 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4965 +                       if (tsk && vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P))
4966 +                               return 0;
4967 +               }
4968 +               else {
4969 +                       /* FIXME: Should we block some entries here? */
4970 +                       return 0;
4971 +               }
4972 +       }
4973 +       else {
4974 +               if (dx_notagcheck(inode->i_sb) ||
4975 +                   dx_check(inode->i_tag, DX_HOSTID | DX_ADMIN | DX_WATCH |
4976 +                            DX_IDENT))
4977 +                       return 0;
4978 +       }
4979 +
4980 +out:
4981 +       return -EACCES;
4982 +}
4983 +
4984 +int dx_permission(const struct inode *inode, int mask)
4985 +{
4986 +       int ret = __dx_permission(inode, mask);
4987 +       if (unlikely(ret)) {
4988 +               vxwprintk_task(1, "denied %x access to %s:%p[#%d,%lu]",
4989 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
4990 +                       inode->i_ino);
4991 +       }
4992 +       return ret;
4993 +}
4994 +
4995  /*
4996   * This does basic POSIX ACL permission checking
4997   */
4998 @@ -266,10 +345,14 @@ int inode_permission(struct inode *inode
4999                 /*
5000                  * Nobody gets write access to an immutable file.
5001                  */
5002 -               if (IS_IMMUTABLE(inode))
5003 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
5004                         return -EACCES;
5005         }
5006  
5007 +       retval = dx_permission(inode, mask);
5008 +       if (retval)
5009 +               return retval;
5010 +
5011         if (inode->i_op->permission)
5012                 retval = inode->i_op->permission(inode, mask);
5013         else
5014 @@ -463,6 +546,9 @@ static int exec_permission(struct inode 
5015  {
5016         int ret;
5017  
5018 +       if (dx_barrier(inode))
5019 +               return -EACCES;
5020 +
5021         if (inode->i_op->permission) {
5022                 ret = inode->i_op->permission(inode, MAY_EXEC);
5023                 if (!ret)
5024 @@ -672,7 +758,8 @@ static __always_inline void follow_dotdo
5025  
5026                 if (nd->path.dentry == nd->root.dentry &&
5027                     nd->path.mnt == nd->root.mnt) {
5028 -                       break;
5029 +                       /* for sane '/' avoid follow_mount() */
5030 +                       return;
5031                 }
5032                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
5033                         /* rare case of legitimate dget_parent()... */
5034 @@ -725,7 +812,7 @@ static int do_lookup(struct nameidata *n
5035  {
5036         struct vfsmount *mnt = nd->path.mnt;
5037         struct dentry *dentry, *parent;
5038 -       struct inode *dir;
5039 +       struct inode *dir, *inode;
5040         /*
5041          * See if the low-level filesystem might want
5042          * to use its own hash..
5043 @@ -747,12 +834,26 @@ static int do_lookup(struct nameidata *n
5044  found:
5045         if (dentry->d_op && dentry->d_op->d_revalidate)
5046                 goto need_revalidate;
5047 +
5048 +       inode = dentry->d_inode;
5049 +       if (!inode)
5050 +               goto done;
5051 +
5052 +       if (__dx_permission(inode, MAY_ACCESS))
5053 +               goto hidden;
5054  done:
5055         path->mnt = mnt;
5056         path->dentry = dentry;
5057         __follow_mount(path);
5058         return 0;
5059  
5060 +hidden:
5061 +       vxwprintk_task(1, "did lookup hidden %s:%p[#%d,%lu] »%s/%.*s«.",
5062 +               inode->i_sb->s_id, inode, inode->i_tag, inode->i_ino,
5063 +               vxd_path(&nd->path), name->len, name->name);
5064 +       dput(dentry);
5065 +       return -ENOENT;
5066 +
5067  need_lookup:
5068         parent = nd->path.dentry;
5069         dir = parent->d_inode;
5070 @@ -1307,7 +1408,7 @@ static int may_delete(struct inode *dir,
5071         if (IS_APPEND(dir))
5072                 return -EPERM;
5073         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
5074 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
5075 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
5076                 return -EPERM;
5077         if (isdir) {
5078                 if (!S_ISDIR(victim->d_inode->i_mode))
5079 @@ -1430,6 +1531,14 @@ int may_open(struct path *path, int acc_
5080                 break;
5081         }
5082  
5083 +#ifdef CONFIG_VSERVER_COWBL
5084 +       if (IS_COW(inode) && (flag & FMODE_WRITE)) {
5085 +               if (IS_COW_LINK(inode))
5086 +                       return -EMLINK;
5087 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
5088 +               mark_inode_dirty(inode);
5089 +       }
5090 +#endif
5091         error = inode_permission(inode, acc_mode);
5092         if (error)
5093                 return error;
5094 @@ -1538,7 +1647,8 @@ static int open_will_truncate(int flag, 
5095  }
5096  
5097  static struct file *finish_open(struct nameidata *nd,
5098 -                               int open_flag, int acc_mode)
5099 +                               int open_flag, int acc_mode,
5100 +                               const char *pathname)
5101  {
5102         struct file *filp;
5103         int will_truncate;
5104 @@ -1551,6 +1661,23 @@ static struct file *finish_open(struct n
5105                         goto exit;
5106         }
5107         error = may_open(&nd->path, acc_mode, open_flag);
5108 +#ifdef CONFIG_VSERVER_COWBL
5109 +       if (error == -EMLINK) {
5110 +               struct dentry *dentry;
5111 +               dentry = cow_break_link(pathname);
5112 +               if (IS_ERR(dentry)) {
5113 +                       error = PTR_ERR(dentry);
5114 +                       goto exit_cow;
5115 +               }
5116 +               dput(dentry);
5117 +               if (will_truncate)
5118 +                       mnt_drop_write(nd->path.mnt);
5119 +               release_open_intent(nd);
5120 +               path_put(&nd->path);
5121 +               return ERR_PTR(-EMLINK);
5122 +       }
5123 +exit_cow:
5124 +#endif
5125         if (error) {
5126                 if (will_truncate)
5127                         mnt_drop_write(nd->path.mnt);
5128 @@ -1719,7 +1846,7 @@ static struct file *do_last(struct namei
5129         if (S_ISDIR(path->dentry->d_inode->i_mode))
5130                 goto exit;
5131  ok:
5132 -       filp = finish_open(nd, open_flag, acc_mode);
5133 +       filp = finish_open(nd, open_flag, acc_mode, pathname);
5134         return filp;
5135  
5136  exit_mutex_unlock:
5137 @@ -1748,7 +1875,11 @@ struct file *do_filp_open(int dfd, const
5138         int count = 0;
5139         int flag = open_to_namei_flags(open_flag);
5140         int force_reval = 0;
5141 -
5142 +#ifdef CONFIG_VSERVER_COWBL
5143 +       int rflag = flag;
5144 +       int rmode = mode;
5145 +restart:
5146 +#endif
5147         if (!(open_flag & O_CREAT))
5148                 mode = 0;
5149  
5150 @@ -1814,6 +1945,13 @@ reval:
5151         if (!(open_flag & O_NOFOLLOW))
5152                 nd.flags |= LOOKUP_FOLLOW;
5153         filp = do_last(&nd, &path, open_flag, acc_mode, mode, pathname);
5154 +#ifdef CONFIG_VSERVER_COWBL
5155 +       if (unlikely(IS_ERR(filp) && PTR_ERR(filp) == -EMLINK)) {
5156 +               flag = rflag;
5157 +               mode = rmode;
5158 +               goto restart;
5159 +       }
5160 +#endif
5161         while (unlikely(!filp)) { /* trailing symlink */
5162                 struct path holder;
5163                 struct inode *inode = path.dentry->d_inode;
5164 @@ -1852,6 +1990,13 @@ reval:
5165                 holder = path;
5166                 nd.flags &= ~LOOKUP_PARENT;
5167                 filp = do_last(&nd, &path, open_flag, acc_mode, mode, pathname);
5168 +#ifdef CONFIG_VSERVER_COWBL
5169 +               if (unlikely(IS_ERR(filp) && PTR_ERR(filp) == -EMLINK)) {
5170 +                       flag = rflag;
5171 +                       mode = rmode;
5172 +                       goto restart;
5173 +               }
5174 +#endif
5175                 if (inode->i_op->put_link)
5176                         inode->i_op->put_link(holder.dentry, &nd, cookie);
5177                 path_put(&holder);
5178 @@ -1952,9 +2097,17 @@ int vfs_mknod(struct inode *dir, struct 
5179         if (error)
5180                 return error;
5181  
5182 -       if ((S_ISCHR(mode) || S_ISBLK(mode)) && !capable(CAP_MKNOD))
5183 +       if (!(S_ISCHR(mode) || S_ISBLK(mode)))
5184 +               goto okay;
5185 +
5186 +       if (!capable(CAP_MKNOD))
5187                 return -EPERM;
5188  
5189 +       if (S_ISCHR(mode) && !vs_chrdev_perm(dev, DATTR_CREATE))
5190 +               return -EPERM;
5191 +       if (S_ISBLK(mode) && !vs_blkdev_perm(dev, DATTR_CREATE))
5192 +               return -EPERM;
5193 +okay:
5194         if (!dir->i_op->mknod)
5195                 return -EPERM;
5196  
5197 @@ -2419,7 +2572,7 @@ int vfs_link(struct dentry *old_dentry, 
5198         /*
5199          * A link to an append-only or immutable file cannot be created.
5200          */
5201 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
5202 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
5203                 return -EPERM;
5204         if (!dir->i_op->link)
5205                 return -EPERM;
5206 @@ -2791,6 +2944,218 @@ int vfs_follow_link(struct nameidata *nd
5207         return __vfs_follow_link(nd, link);
5208  }
5209  
5210 +
5211 +#ifdef CONFIG_VSERVER_COWBL
5212 +
5213 +#include <linux/file.h>
5214 +
5215 +static inline
5216 +long do_cow_splice(struct file *in, struct file *out, size_t len)
5217 +{
5218 +       loff_t ppos = 0;
5219 +
5220 +       return do_splice_direct(in, &ppos, out, len, 0);
5221 +}
5222 +
5223 +struct dentry *cow_break_link(const char *pathname)
5224 +{
5225 +       int ret, mode, pathlen, redo = 0;
5226 +       struct nameidata old_nd, dir_nd;
5227 +       struct path old_path, new_path;
5228 +       struct dentry *dir, *res = NULL;
5229 +       struct file *old_file;
5230 +       struct file *new_file;
5231 +       char *to, *path, pad='\251';
5232 +       loff_t size;
5233 +
5234 +       vxdprintk(VXD_CBIT(misc, 1), "cow_break_link(»%s«)", pathname);
5235 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
5236 +       ret = -ENOMEM;
5237 +       if (!path)
5238 +               goto out;
5239 +
5240 +       /* old_nd will have refs to dentry and mnt */
5241 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5242 +       vxdprintk(VXD_CBIT(misc, 2), "path_lookup(old): %d", ret);
5243 +       if (ret < 0)
5244 +               goto out_free_path;
5245 +
5246 +       old_path = old_nd.path;
5247 +       mode = old_path.dentry->d_inode->i_mode;
5248 +
5249 +       to = d_path(&old_path, path, PATH_MAX-2);
5250 +       pathlen = strlen(to);
5251 +       vxdprintk(VXD_CBIT(misc, 2), "old path »%s« [»%.*s«:%d]", to,
5252 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5253 +               old_path.dentry->d_name.len);
5254 +
5255 +       to[pathlen + 1] = 0;
5256 +retry:
5257 +       to[pathlen] = pad--;
5258 +       ret = -EMLINK;
5259 +       if (pad <= '\240')
5260 +               goto out_rel_old;
5261 +
5262 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy »%s«", to);
5263 +       /* dir_nd will have refs to dentry and mnt */
5264 +       ret = path_lookup(to,
5265 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
5266 +       vxdprintk(VXD_CBIT(misc, 2),
5267 +               "path_lookup(new): %d", ret);
5268 +       if (ret < 0)
5269 +               goto retry;
5270 +
5271 +       /* this puppy downs the inode mutex */
5272 +       new_path.dentry = lookup_create(&dir_nd, 0);
5273 +       if (!new_path.dentry || IS_ERR(new_path.dentry)) {
5274 +               vxdprintk(VXD_CBIT(misc, 2),
5275 +                       "lookup_create(new): %p", new_path.dentry);
5276 +               mutex_unlock(&dir_nd.path.dentry->d_inode->i_mutex);
5277 +               path_put(&dir_nd.path);
5278 +               goto retry;
5279 +       }
5280 +       vxdprintk(VXD_CBIT(misc, 2),
5281 +               "lookup_create(new): %p [»%.*s«:%d]", new_path.dentry,
5282 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5283 +               new_path.dentry->d_name.len);
5284 +       dir = dir_nd.path.dentry;
5285 +
5286 +       ret = vfs_create(dir_nd.path.dentry->d_inode, new_path.dentry, mode, &dir_nd);
5287 +       vxdprintk(VXD_CBIT(misc, 2),
5288 +               "vfs_create(new): %d", ret);
5289 +       if (ret == -EEXIST) {
5290 +               mutex_unlock(&dir->d_inode->i_mutex);
5291 +               dput(new_path.dentry);
5292 +               path_put(&dir_nd.path);
5293 +               goto retry;
5294 +       }
5295 +       else if (ret < 0)
5296 +               goto out_unlock_new;
5297 +
5298 +       /* drop out early, ret passes ENOENT */
5299 +       ret = -ENOENT;
5300 +       if ((redo = d_unhashed(old_path.dentry)))
5301 +               goto out_unlock_new;
5302 +
5303 +       new_path.mnt = dir_nd.path.mnt;
5304 +       dget(old_path.dentry);
5305 +       mntget(old_path.mnt);
5306 +       /* this one cleans up the dentry/mnt in case of failure */
5307 +       old_file = dentry_open(old_path.dentry, old_path.mnt,
5308 +               O_RDONLY, current_cred());
5309 +       vxdprintk(VXD_CBIT(misc, 2),
5310 +               "dentry_open(old): %p", old_file);
5311 +       if (!old_file || IS_ERR(old_file)) {
5312 +               res = IS_ERR(old_file) ? (void *) old_file : res;
5313 +               goto out_unlock_new;
5314 +       }
5315 +
5316 +       dget(new_path.dentry);
5317 +       mntget(new_path.mnt);
5318 +       /* this one cleans up the dentry/mnt in case of failure */
5319 +       new_file = dentry_open(new_path.dentry, new_path.mnt,
5320 +               O_WRONLY, current_cred());
5321 +       vxdprintk(VXD_CBIT(misc, 2),
5322 +               "dentry_open(new): %p", new_file);
5323 +
5324 +       ret = IS_ERR(new_file) ? PTR_ERR(new_file) : -ENOENT;
5325 +       if (!new_file || IS_ERR(new_file))
5326 +               goto out_fput_old;
5327 +
5328 +       size = i_size_read(old_file->f_dentry->d_inode);
5329 +       ret = do_cow_splice(old_file, new_file, size);
5330 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
5331 +       if (ret < 0) {
5332 +               goto out_fput_both;
5333 +       } else if (ret < size) {
5334 +               ret = -ENOSPC;
5335 +               goto out_fput_both;
5336 +       } else {
5337 +               struct inode *old_inode = old_path.dentry->d_inode;
5338 +               struct inode *new_inode = new_path.dentry->d_inode;
5339 +               struct iattr attr = {
5340 +                       .ia_uid = old_inode->i_uid,
5341 +                       .ia_gid = old_inode->i_gid,
5342 +                       .ia_valid = ATTR_UID | ATTR_GID
5343 +                       };
5344 +
5345 +               setattr_copy(new_inode, &attr);
5346 +               mark_inode_dirty(new_inode);
5347 +       }
5348 +
5349 +       mutex_lock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5350 +
5351 +       /* drop out late */
5352 +       ret = -ENOENT;
5353 +       if ((redo = d_unhashed(old_path.dentry)))
5354 +               goto out_unlock;
5355 +
5356 +       vxdprintk(VXD_CBIT(misc, 2),
5357 +               "vfs_rename: [»%*s«:%d] -> [»%*s«:%d]",
5358 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5359 +               new_path.dentry->d_name.len,
5360 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5361 +               old_path.dentry->d_name.len);
5362 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_path.dentry,
5363 +               old_nd.path.dentry->d_parent->d_inode, old_path.dentry);
5364 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
5365 +       res = new_path.dentry;
5366 +
5367 +out_unlock:
5368 +       mutex_unlock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5369 +
5370 +out_fput_both:
5371 +       vxdprintk(VXD_CBIT(misc, 3),
5372 +               "fput(new_file=%p[#%ld])", new_file,
5373 +               atomic_long_read(&new_file->f_count));
5374 +       fput(new_file);
5375 +
5376 +out_fput_old:
5377 +       vxdprintk(VXD_CBIT(misc, 3),
5378 +               "fput(old_file=%p[#%ld])", old_file,
5379 +               atomic_long_read(&old_file->f_count));
5380 +       fput(old_file);
5381 +
5382 +out_unlock_new:
5383 +       mutex_unlock(&dir->d_inode->i_mutex);
5384 +       if (!ret)
5385 +               goto out_redo;
5386 +
5387 +       /* error path cleanup */
5388 +       vfs_unlink(dir->d_inode, new_path.dentry);
5389 +       dput(new_path.dentry);
5390 +
5391 +out_redo:
5392 +       if (!redo)
5393 +               goto out_rel_both;
5394 +       /* lookup dentry once again */
5395 +       path_put(&old_nd.path);
5396 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5397 +       if (ret)
5398 +               goto out_rel_both;
5399 +
5400 +       new_path.dentry = old_nd.path.dentry;
5401 +       vxdprintk(VXD_CBIT(misc, 2),
5402 +               "path_lookup(redo): %p [»%.*s«:%d]", new_path.dentry,
5403 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5404 +               new_path.dentry->d_name.len);
5405 +       dget(new_path.dentry);
5406 +       res = new_path.dentry;
5407 +
5408 +out_rel_both:
5409 +       path_put(&dir_nd.path);
5410 +out_rel_old:
5411 +       path_put(&old_nd.path);
5412 +out_free_path:
5413 +       kfree(path);
5414 +out:
5415 +       if (ret)
5416 +               res = ERR_PTR(ret);
5417 +       return res;
5418 +}
5419 +
5420 +#endif
5421 +
5422  /* get the link contents into pagecache */
5423  static char *page_getlink(struct dentry * dentry, struct page **ppage)
5424  {
5425 diff -NurpP --minimal linux-2.6.36/fs/namespace.c linux-2.6.36-vs2.3.0.36.33/fs/namespace.c
5426 --- linux-2.6.36/fs/namespace.c 2010-10-21 13:07:50.000000000 +0200
5427 +++ linux-2.6.36-vs2.3.0.36.33/fs/namespace.c   2010-10-21 15:11:02.000000000 +0200
5428 @@ -32,6 +32,11 @@
5429  #include <linux/idr.h>
5430  #include <linux/fs_struct.h>
5431  #include <linux/fsnotify.h>
5432 +#include <linux/vs_base.h>
5433 +#include <linux/vs_context.h>
5434 +#include <linux/vs_tag.h>
5435 +#include <linux/vserver/space.h>
5436 +#include <linux/vserver/global.h>
5437  #include <asm/uaccess.h>
5438  #include <asm/unistd.h>
5439  #include "pnode.h"
5440 @@ -601,6 +606,7 @@ static struct vfsmount *clone_mnt(struct
5441                 mnt->mnt_root = dget(root);
5442                 mnt->mnt_mountpoint = mnt->mnt_root;
5443                 mnt->mnt_parent = mnt;
5444 +               mnt->mnt_tag = old->mnt_tag;
5445  
5446                 if (flag & CL_SLAVE) {
5447                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
5448 @@ -699,6 +705,31 @@ static inline void mangle(struct seq_fil
5449         seq_escape(m, s, " \t\n\\");
5450  }
5451  
5452 +static int mnt_is_reachable(struct vfsmount *mnt)
5453 +{
5454 +       struct path root;
5455 +       struct dentry *point;
5456 +       int ret;
5457 +
5458 +       if (mnt == mnt->mnt_ns->root)
5459 +               return 1;
5460 +
5461 +       br_read_lock(vfsmount_lock);
5462 +       root = current->fs->root;
5463 +       point = root.dentry;
5464 +
5465 +       while ((mnt != mnt->mnt_parent) && (mnt != root.mnt)) {
5466 +               point = mnt->mnt_mountpoint;
5467 +               mnt = mnt->mnt_parent;
5468 +       }
5469 +
5470 +       ret = (mnt == root.mnt) && is_subdir(point, root.dentry);
5471 +
5472 +       br_read_unlock(vfsmount_lock);
5473 +
5474 +       return ret;
5475 +}
5476 +
5477  /*
5478   * Simple .show_options callback for filesystems which don't want to
5479   * implement more complex mount option showing.
5480 @@ -801,6 +832,8 @@ static int show_sb_opts(struct seq_file 
5481                 { MS_SYNCHRONOUS, ",sync" },
5482                 { MS_DIRSYNC, ",dirsync" },
5483                 { MS_MANDLOCK, ",mand" },
5484 +               { MS_TAGGED, ",tag" },
5485 +               { MS_NOTAGCHECK, ",notagcheck" },
5486                 { 0, NULL }
5487         };
5488         const struct proc_fs_info *fs_infop;
5489 @@ -847,10 +880,20 @@ static int show_vfsmnt(struct seq_file *
5490         int err = 0;
5491         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5492  
5493 -       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5494 -       seq_putc(m, ' ');
5495 -       seq_path(m, &mnt_path, " \t\n\\");
5496 -       seq_putc(m, ' ');
5497 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5498 +               return SEQ_SKIP;
5499 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5500 +               return SEQ_SKIP;
5501 +
5502 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5503 +               mnt == current->fs->root.mnt) {
5504 +               seq_puts(m, "/dev/root / ");
5505 +       } else {
5506 +               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5507 +               seq_putc(m, ' ');
5508 +               seq_path(m, &mnt_path, " \t\n\\");
5509 +               seq_putc(m, ' ');
5510 +       }
5511         show_type(m, mnt->mnt_sb);
5512         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
5513         err = show_sb_opts(m, mnt->mnt_sb);
5514 @@ -880,6 +923,11 @@ static int show_mountinfo(struct seq_fil
5515         struct path root = p->root;
5516         int err = 0;
5517  
5518 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5519 +               return SEQ_SKIP;
5520 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5521 +               return SEQ_SKIP;
5522 +
5523         seq_printf(m, "%i %i %u:%u ", mnt->mnt_id, mnt->mnt_parent->mnt_id,
5524                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
5525         seq_dentry(m, mnt->mnt_root, " \t\n\\");
5526 @@ -938,17 +986,27 @@ static int show_vfsstat(struct seq_file 
5527         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5528         int err = 0;
5529  
5530 -       /* device */
5531 -       if (mnt->mnt_devname) {
5532 -               seq_puts(m, "device ");
5533 -               mangle(m, mnt->mnt_devname);
5534 -       } else
5535 -               seq_puts(m, "no device");
5536 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5537 +               return SEQ_SKIP;
5538 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5539 +               return SEQ_SKIP;
5540  
5541 -       /* mount point */
5542 -       seq_puts(m, " mounted on ");
5543 -       seq_path(m, &mnt_path, " \t\n\\");
5544 -       seq_putc(m, ' ');
5545 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5546 +               mnt == current->fs->root.mnt) {
5547 +               seq_puts(m, "device /dev/root mounted on / ");
5548 +       } else {
5549 +               /* device */
5550 +               if (mnt->mnt_devname) {
5551 +                       seq_puts(m, "device ");
5552 +                       mangle(m, mnt->mnt_devname);
5553 +               } else
5554 +                       seq_puts(m, "no device");
5555 +
5556 +               /* mount point */
5557 +               seq_puts(m, " mounted on ");
5558 +               seq_path(m, &mnt_path, " \t\n\\");
5559 +               seq_putc(m, ' ');
5560 +       }
5561  
5562         /* file system type */
5563         seq_puts(m, "with fstype ");
5564 @@ -1194,7 +1252,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
5565                 goto dput_and_out;
5566  
5567         retval = -EPERM;
5568 -       if (!capable(CAP_SYS_ADMIN))
5569 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5570                 goto dput_and_out;
5571  
5572         retval = do_umount(path.mnt, flags);
5573 @@ -1220,7 +1278,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
5574  
5575  static int mount_is_safe(struct path *path)
5576  {
5577 -       if (capable(CAP_SYS_ADMIN))
5578 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5579                 return 0;
5580         return -EPERM;
5581  #ifdef notyet
5582 @@ -1510,7 +1568,7 @@ static int do_change_type(struct path *p
5583         int type;
5584         int err = 0;
5585  
5586 -       if (!capable(CAP_SYS_ADMIN))
5587 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_NAMESPACE))
5588                 return -EPERM;
5589  
5590         if (path->dentry != path->mnt->mnt_root)
5591 @@ -1541,11 +1599,13 @@ static int do_change_type(struct path *p
5592   * do loopback mount.
5593   */
5594  static int do_loopback(struct path *path, char *old_name,
5595 -                               int recurse)
5596 +       tag_t tag, unsigned long flags, int mnt_flags)
5597  {
5598         struct path old_path;
5599         struct vfsmount *mnt = NULL;
5600         int err = mount_is_safe(path);
5601 +       int recurse = flags & MS_REC;
5602 +
5603         if (err)
5604                 return err;
5605         if (!old_name || !*old_name)
5606 @@ -1580,6 +1640,7 @@ static int do_loopback(struct path *path
5607                 br_write_unlock(vfsmount_lock);
5608                 release_mounts(&umount_list);
5609         }
5610 +       mnt->mnt_flags = mnt_flags;
5611  
5612  out:
5613         up_write(&namespace_sem);
5614 @@ -1610,12 +1671,12 @@ static int change_mount_flags(struct vfs
5615   * on it - tough luck.
5616   */
5617  static int do_remount(struct path *path, int flags, int mnt_flags,
5618 -                     void *data)
5619 +       void *data, xid_t xid)
5620  {
5621         int err;
5622         struct super_block *sb = path->mnt->mnt_sb;
5623  
5624 -       if (!capable(CAP_SYS_ADMIN))
5625 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
5626                 return -EPERM;
5627  
5628         if (!check_mnt(path->mnt))
5629 @@ -1659,7 +1720,7 @@ static int do_move_mount(struct path *pa
5630         struct path old_path, parent_path;
5631         struct vfsmount *p;
5632         int err = 0;
5633 -       if (!capable(CAP_SYS_ADMIN))
5634 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5635                 return -EPERM;
5636         if (!old_name || !*old_name)
5637                 return -EINVAL;
5638 @@ -1741,7 +1802,7 @@ static int do_new_mount(struct path *pat
5639                 return -EINVAL;
5640  
5641         /* we need capabilities... */
5642 -       if (!capable(CAP_SYS_ADMIN))
5643 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5644                 return -EPERM;
5645  
5646         lock_kernel();
5647 @@ -2009,6 +2070,7 @@ long do_mount(char *dev_name, char *dir_
5648         struct path path;
5649         int retval = 0;
5650         int mnt_flags = 0;
5651 +       tag_t tag = 0;
5652  
5653         /* Discard magic */
5654         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5655 @@ -2036,6 +2098,12 @@ long do_mount(char *dev_name, char *dir_
5656         if (!(flags & MS_NOATIME))
5657                 mnt_flags |= MNT_RELATIME;
5658  
5659 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5660 +               /* FIXME: bind and re-mounts get the tag flag? */
5661 +               if (flags & (MS_BIND|MS_REMOUNT))
5662 +                       flags |= MS_TAGID;
5663 +       }
5664 +
5665         /* Separate the per-mountpoint flags */
5666         if (flags & MS_NOSUID)
5667                 mnt_flags |= MNT_NOSUID;
5668 @@ -2052,15 +2120,17 @@ long do_mount(char *dev_name, char *dir_
5669         if (flags & MS_RDONLY)
5670                 mnt_flags |= MNT_READONLY;
5671  
5672 +       if (!capable(CAP_SYS_ADMIN))
5673 +               mnt_flags |= MNT_NODEV;
5674         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
5675                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
5676                    MS_STRICTATIME);
5677  
5678         if (flags & MS_REMOUNT)
5679                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5680 -                                   data_page);
5681 +                                   data_page, tag);
5682         else if (flags & MS_BIND)
5683 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5684 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5685         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5686                 retval = do_change_type(&path, flags);
5687         else if (flags & MS_MOVE)
5688 @@ -2139,6 +2209,7 @@ static struct mnt_namespace *dup_mnt_ns(
5689                 q = next_mnt(q, new_ns->root);
5690         }
5691         up_write(&namespace_sem);
5692 +       atomic_inc(&vs_global_mnt_ns);
5693  
5694         if (rootmnt)
5695                 mntput(rootmnt);
5696 @@ -2280,9 +2351,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5697         down_write(&namespace_sem);
5698         mutex_lock(&old.dentry->d_inode->i_mutex);
5699         error = -EINVAL;
5700 -       if (IS_MNT_SHARED(old.mnt) ||
5701 +       if ((IS_MNT_SHARED(old.mnt) ||
5702                 IS_MNT_SHARED(new.mnt->mnt_parent) ||
5703 -               IS_MNT_SHARED(root.mnt->mnt_parent))
5704 +               IS_MNT_SHARED(root.mnt->mnt_parent)) &&
5705 +               !vx_flags(VXF_STATE_SETUP, 0))
5706                 goto out2;
5707         if (!check_mnt(root.mnt))
5708                 goto out2;
5709 @@ -2415,6 +2487,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5710         br_write_unlock(vfsmount_lock);
5711         up_write(&namespace_sem);
5712         release_mounts(&umount_list);
5713 +       atomic_dec(&vs_global_mnt_ns);
5714         kfree(ns);
5715  }
5716  EXPORT_SYMBOL(put_mnt_ns);
5717 diff -NurpP --minimal linux-2.6.36/fs/nfs/client.c linux-2.6.36-vs2.3.0.36.33/fs/nfs/client.c
5718 --- linux-2.6.36/fs/nfs/client.c        2010-10-21 13:07:50.000000000 +0200
5719 +++ linux-2.6.36-vs2.3.0.36.33/fs/nfs/client.c  2010-10-21 13:09:36.000000000 +0200
5720 @@ -740,6 +740,9 @@ static int nfs_init_server_rpcclient(str
5721         if (server->flags & NFS_MOUNT_SOFT)
5722                 server->client->cl_softrtry = 1;
5723  
5724 +       server->client->cl_tag = 0;
5725 +       if (server->flags & NFS_MOUNT_TAGGED)
5726 +               server->client->cl_tag = 1;
5727         return 0;
5728  }
5729  
5730 @@ -911,6 +914,10 @@ static void nfs_server_set_fsinfo(struct
5731                 server->acdirmin = server->acdirmax = 0;
5732         }
5733  
5734 +       /* FIXME: needs fsinfo
5735 +       if (server->flags & NFS_MOUNT_TAGGED)
5736 +               sb->s_flags |= MS_TAGGED;       */
5737 +
5738         server->maxfilesize = fsinfo->maxfilesize;
5739  
5740         /* We're airborne Set socket buffersize */
5741 diff -NurpP --minimal linux-2.6.36/fs/nfs/dir.c linux-2.6.36-vs2.3.0.36.33/fs/nfs/dir.c
5742 --- linux-2.6.36/fs/nfs/dir.c   2010-10-21 13:07:50.000000000 +0200
5743 +++ linux-2.6.36-vs2.3.0.36.33/fs/nfs/dir.c     2010-10-21 13:09:36.000000000 +0200
5744 @@ -33,6 +33,7 @@
5745  #include <linux/namei.h>
5746  #include <linux/mount.h>
5747  #include <linux/sched.h>
5748 +#include <linux/vs_tag.h>
5749  
5750  #include "nfs4_fs.h"
5751  #include "delegation.h"
5752 @@ -986,6 +987,7 @@ static struct dentry *nfs_lookup(struct 
5753         if (IS_ERR(res))
5754                 goto out_unblock_sillyrename;
5755  
5756 +       dx_propagate_tag(nd, inode);
5757  no_entry:
5758         res = d_materialise_unique(dentry, inode);
5759         if (res != NULL) {
5760 diff -NurpP --minimal linux-2.6.36/fs/nfs/inode.c linux-2.6.36-vs2.3.0.36.33/fs/nfs/inode.c
5761 --- linux-2.6.36/fs/nfs/inode.c 2010-10-21 13:07:50.000000000 +0200
5762 +++ linux-2.6.36-vs2.3.0.36.33/fs/nfs/inode.c   2010-10-21 13:09:36.000000000 +0200
5763 @@ -37,6 +37,7 @@
5764  #include <linux/inet.h>
5765  #include <linux/nfs_xdr.h>
5766  #include <linux/slab.h>
5767 +#include <linux/vs_tag.h>
5768  
5769  #include <asm/system.h>
5770  #include <asm/uaccess.h>
5771 @@ -267,6 +268,8 @@ nfs_fhget(struct super_block *sb, struct
5772         if (inode->i_state & I_NEW) {
5773                 struct nfs_inode *nfsi = NFS_I(inode);
5774                 unsigned long now = jiffies;
5775 +               uid_t uid;
5776 +               gid_t gid;
5777  
5778                 /* We set i_ino for the few things that still rely on it,
5779                  * such as stat(2) */
5780 @@ -315,8 +318,8 @@ nfs_fhget(struct super_block *sb, struct
5781                 nfsi->change_attr = 0;
5782                 inode->i_size = 0;
5783                 inode->i_nlink = 0;
5784 -               inode->i_uid = -2;
5785 -               inode->i_gid = -2;
5786 +               uid = -2;
5787 +               gid = -2;
5788                 inode->i_blocks = 0;
5789                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5790  
5791 @@ -353,13 +356,13 @@ nfs_fhget(struct super_block *sb, struct
5792                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5793                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5794                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5795 -                       inode->i_uid = fattr->uid;
5796 +                       uid = fattr->uid;
5797                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5798                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5799                                 | NFS_INO_INVALID_ACCESS
5800                                 | NFS_INO_INVALID_ACL;
5801                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5802 -                       inode->i_gid = fattr->gid;
5803 +                       gid = fattr->gid;
5804                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5805                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR
5806                                 | NFS_INO_INVALID_ACCESS
5807 @@ -372,6 +375,11 @@ nfs_fhget(struct super_block *sb, struct
5808                          */
5809                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5810                 }
5811 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5812 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5813 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
5814 +                               /* maybe fattr->xid someday */
5815 +
5816                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5817                 nfsi->attrtimeo_timestamp = now;
5818                 nfsi->access_cache = RB_ROOT;
5819 @@ -488,6 +496,8 @@ void nfs_setattr_update_inode(struct ino
5820                         inode->i_uid = attr->ia_uid;
5821                 if ((attr->ia_valid & ATTR_GID) != 0)
5822                         inode->i_gid = attr->ia_gid;
5823 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5824 +                       inode->i_tag = attr->ia_tag;
5825                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5826                 spin_unlock(&inode->i_lock);
5827         }
5828 @@ -923,6 +933,9 @@ static int nfs_check_inode_attributes(st
5829         struct nfs_inode *nfsi = NFS_I(inode);
5830         loff_t cur_size, new_isize;
5831         unsigned long invalid = 0;
5832 +       uid_t uid;
5833 +       gid_t gid;
5834 +       tag_t tag;
5835  
5836  
5837         /* Has the inode gone and changed behind our back? */
5838 @@ -946,13 +959,18 @@ static int nfs_check_inode_attributes(st
5839                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5840         }
5841  
5842 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5843 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5844 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5845 +
5846         /* Have any file permissions changed? */
5847         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5848                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5849 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && inode->i_uid != fattr->uid)
5850 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && uid != fattr->uid)
5851                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5852 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && inode->i_gid != fattr->gid)
5853 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && gid != fattr->gid)
5854                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5855 +               /* maybe check for tag too? */
5856  
5857         /* Has the link count changed? */
5858         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5859 @@ -1187,6 +1205,9 @@ static int nfs_update_inode(struct inode
5860         unsigned long invalid = 0;
5861         unsigned long now = jiffies;
5862         unsigned long save_cache_validity;
5863 +       uid_t uid;
5864 +       gid_t gid;
5865 +       tag_t tag;
5866  
5867         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
5868                         __func__, inode->i_sb->s_id, inode->i_ino,
5869 @@ -1289,6 +1310,9 @@ static int nfs_update_inode(struct inode
5870                                 | NFS_INO_REVAL_PAGECACHE
5871                                 | NFS_INO_REVAL_FORCED);
5872  
5873 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5874 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5875 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5876  
5877         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5878                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5879 @@ -1310,9 +1334,9 @@ static int nfs_update_inode(struct inode
5880                                 | NFS_INO_REVAL_FORCED);
5881  
5882         if (fattr->valid & NFS_ATTR_FATTR_OWNER) {
5883 -               if (inode->i_uid != fattr->uid) {
5884 +               if (uid != fattr->uid) {
5885                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5886 -                       inode->i_uid = fattr->uid;
5887 +                       uid = fattr->uid;
5888                 }
5889         } else if (server->caps & NFS_CAP_OWNER)
5890                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5891 @@ -1321,9 +1345,9 @@ static int nfs_update_inode(struct inode
5892                                 | NFS_INO_REVAL_FORCED);
5893  
5894         if (fattr->valid & NFS_ATTR_FATTR_GROUP) {
5895 -               if (inode->i_gid != fattr->gid) {
5896 +               if (gid != fattr->gid) {
5897                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5898 -                       inode->i_gid = fattr->gid;
5899 +                       gid = fattr->gid;
5900                 }
5901         } else if (server->caps & NFS_CAP_OWNER_GROUP)
5902                 invalid |= save_cache_validity & (NFS_INO_INVALID_ATTR
5903 @@ -1331,6 +1355,10 @@ static int nfs_update_inode(struct inode
5904                                 | NFS_INO_INVALID_ACL
5905                                 | NFS_INO_REVAL_FORCED);
5906  
5907 +       inode->i_uid = uid;
5908 +       inode->i_gid = gid;
5909 +       inode->i_tag = tag;
5910 +
5911         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5912                 if (inode->i_nlink != fattr->nlink) {
5913                         invalid |= NFS_INO_INVALID_ATTR;
5914 diff -NurpP --minimal linux-2.6.36/fs/nfs/nfs3xdr.c linux-2.6.36-vs2.3.0.36.33/fs/nfs/nfs3xdr.c
5915 --- linux-2.6.36/fs/nfs/nfs3xdr.c       2010-10-21 13:07:50.000000000 +0200
5916 +++ linux-2.6.36-vs2.3.0.36.33/fs/nfs/nfs3xdr.c 2010-10-21 13:09:36.000000000 +0200
5917 @@ -20,6 +20,7 @@
5918  #include <linux/nfs3.h>
5919  #include <linux/nfs_fs.h>
5920  #include <linux/nfsacl.h>
5921 +#include <linux/vs_tag.h>
5922  #include "internal.h"
5923  
5924  #define NFSDBG_FACILITY                NFSDBG_XDR
5925 @@ -175,7 +176,7 @@ xdr_decode_fattr(__be32 *p, struct nfs_f
5926  }
5927  
5928  static inline __be32 *
5929 -xdr_encode_sattr(__be32 *p, struct iattr *attr)
5930 +xdr_encode_sattr(__be32 *p, struct iattr *attr, int tag)
5931  {
5932         if (attr->ia_valid & ATTR_MODE) {
5933                 *p++ = xdr_one;
5934 @@ -183,15 +184,17 @@ xdr_encode_sattr(__be32 *p, struct iattr
5935         } else {
5936                 *p++ = xdr_zero;
5937         }
5938 -       if (attr->ia_valid & ATTR_UID) {
5939 +       if (attr->ia_valid & ATTR_UID ||
5940 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5941                 *p++ = xdr_one;
5942 -               *p++ = htonl(attr->ia_uid);
5943 +               *p++ = htonl(TAGINO_UID(tag, attr->ia_uid, attr->ia_tag));
5944         } else {
5945                 *p++ = xdr_zero;
5946         }
5947 -       if (attr->ia_valid & ATTR_GID) {
5948 +       if (attr->ia_valid & ATTR_GID ||
5949 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5950                 *p++ = xdr_one;
5951 -               *p++ = htonl(attr->ia_gid);
5952 +               *p++ = htonl(TAGINO_GID(tag, attr->ia_gid, attr->ia_tag));
5953         } else {
5954                 *p++ = xdr_zero;
5955         }
5956 @@ -278,7 +281,8 @@ static int
5957  nfs3_xdr_sattrargs(struct rpc_rqst *req, __be32 *p, struct nfs3_sattrargs *args)
5958  {
5959         p = xdr_encode_fhandle(p, args->fh);
5960 -       p = xdr_encode_sattr(p, args->sattr);
5961 +       p = xdr_encode_sattr(p, args->sattr,
5962 +               req->rq_task->tk_client->cl_tag);
5963         *p++ = htonl(args->guard);
5964         if (args->guard)
5965                 p = xdr_encode_time3(p, &args->guardtime);
5966 @@ -383,7 +387,8 @@ nfs3_xdr_createargs(struct rpc_rqst *req
5967                 *p++ = args->verifier[0];
5968                 *p++ = args->verifier[1];
5969         } else
5970 -               p = xdr_encode_sattr(p, args->sattr);
5971 +               p = xdr_encode_sattr(p, args->sattr,
5972 +                       req->rq_task->tk_client->cl_tag);
5973  
5974         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5975         return 0;
5976 @@ -397,7 +402,8 @@ nfs3_xdr_mkdirargs(struct rpc_rqst *req,
5977  {
5978         p = xdr_encode_fhandle(p, args->fh);
5979         p = xdr_encode_array(p, args->name, args->len);
5980 -       p = xdr_encode_sattr(p, args->sattr);
5981 +       p = xdr_encode_sattr(p, args->sattr,
5982 +               req->rq_task->tk_client->cl_tag);
5983         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5984         return 0;
5985  }
5986 @@ -410,7 +416,8 @@ nfs3_xdr_symlinkargs(struct rpc_rqst *re
5987  {
5988         p = xdr_encode_fhandle(p, args->fromfh);
5989         p = xdr_encode_array(p, args->fromname, args->fromlen);
5990 -       p = xdr_encode_sattr(p, args->sattr);
5991 +       p = xdr_encode_sattr(p, args->sattr,
5992 +               req->rq_task->tk_client->cl_tag);
5993         *p++ = htonl(args->pathlen);
5994         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5995  
5996 @@ -428,7 +435,8 @@ nfs3_xdr_mknodargs(struct rpc_rqst *req,
5997         p = xdr_encode_fhandle(p, args->fh);
5998         p = xdr_encode_array(p, args->name, args->len);
5999         *p++ = htonl(args->type);
6000 -       p = xdr_encode_sattr(p, args->sattr);
6001 +       p = xdr_encode_sattr(p, args->sattr,
6002 +               req->rq_task->tk_client->cl_tag);
6003         if (args->type == NF3CHR || args->type == NF3BLK) {
6004                 *p++ = htonl(MAJOR(args->rdev));
6005                 *p++ = htonl(MINOR(args->rdev));
6006 diff -NurpP --minimal linux-2.6.36/fs/nfs/nfsroot.c linux-2.6.36-vs2.3.0.36.33/fs/nfs/nfsroot.c
6007 --- linux-2.6.36/fs/nfs/nfsroot.c       2010-08-02 16:52:50.000000000 +0200
6008 +++ linux-2.6.36-vs2.3.0.36.33/fs/nfs/nfsroot.c 2010-10-21 13:09:36.000000000 +0200
6009 @@ -122,12 +122,12 @@ static int mount_port __initdata = 0;             /
6010  enum {
6011         /* Options that take integer arguments */
6012         Opt_port, Opt_rsize, Opt_wsize, Opt_timeo, Opt_retrans, Opt_acregmin,
6013 -       Opt_acregmax, Opt_acdirmin, Opt_acdirmax,
6014 +       Opt_acregmax, Opt_acdirmin, Opt_acdirmax, Opt_tagid,
6015         /* Options that take no arguments */
6016         Opt_soft, Opt_hard, Opt_intr,
6017         Opt_nointr, Opt_posix, Opt_noposix, Opt_cto, Opt_nocto, Opt_ac, 
6018         Opt_noac, Opt_lock, Opt_nolock, Opt_v2, Opt_v3, Opt_udp, Opt_tcp,
6019 -       Opt_acl, Opt_noacl,
6020 +       Opt_acl, Opt_noacl, Opt_tag, Opt_notag,
6021         /* Error token */
6022         Opt_err
6023  };
6024 @@ -164,6 +164,9 @@ static const match_table_t tokens __init
6025         {Opt_tcp, "tcp"},
6026         {Opt_acl, "acl"},
6027         {Opt_noacl, "noacl"},
6028 +       {Opt_tag, "tag"},
6029 +       {Opt_notag, "notag"},
6030 +       {Opt_tagid, "tagid=%u"},
6031         {Opt_err, NULL}
6032         
6033  };
6034 @@ -275,6 +278,20 @@ static int __init root_nfs_parse(char *n
6035                         case Opt_noacl:
6036                                 nfs_data.flags |= NFS_MOUNT_NOACL;
6037                                 break;
6038 +#ifndef CONFIG_TAGGING_NONE
6039 +                       case Opt_tag:
6040 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
6041 +                               break;
6042 +                       case Opt_notag:
6043 +                               nfs_data.flags &= ~NFS_MOUNT_TAGGED;
6044 +                               break;
6045 +#endif
6046 +#ifdef CONFIG_PROPAGATE
6047 +                       case Opt_tagid:
6048 +                               /* use args[0] */
6049 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
6050 +                               break;
6051 +#endif
6052                         default:
6053                                 printk(KERN_WARNING "Root-NFS: unknown "
6054                                         "option: %s\n", p);
6055 diff -NurpP --minimal linux-2.6.36/fs/nfs/super.c linux-2.6.36-vs2.3.0.36.33/fs/nfs/super.c
6056 --- linux-2.6.36/fs/nfs/super.c 2010-10-21 13:07:50.000000000 +0200
6057 +++ linux-2.6.36-vs2.3.0.36.33/fs/nfs/super.c   2010-10-21 13:09:36.000000000 +0200
6058 @@ -54,6 +54,7 @@
6059  #include <linux/nfs_xdr.h>
6060  #include <linux/magic.h>
6061  #include <linux/parser.h>
6062 +#include <linux/vs_tag.h>
6063  
6064  #include <asm/system.h>
6065  #include <asm/uaccess.h>
6066 @@ -617,6 +618,7 @@ static void nfs_show_mount_options(struc
6067                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
6068                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
6069                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
6070 +               { NFS_MOUNT_TAGGED, ",tag", "" },
6071                 { 0, NULL, NULL }
6072         };
6073         const struct proc_nfs_info *nfs_infop;
6074 diff -NurpP --minimal linux-2.6.36/fs/nfsd/auth.c linux-2.6.36-vs2.3.0.36.33/fs/nfsd/auth.c
6075 --- linux-2.6.36/fs/nfsd/auth.c 2010-02-25 11:52:05.000000000 +0100
6076 +++ linux-2.6.36-vs2.3.0.36.33/fs/nfsd/auth.c   2010-10-21 13:09:36.000000000 +0200
6077 @@ -1,6 +1,7 @@
6078  /* Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> */
6079  
6080  #include <linux/sched.h>
6081 +#include <linux/vs_tag.h>
6082  #include "nfsd.h"
6083  #include "auth.h"
6084  
6085 @@ -36,6 +37,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
6086  
6087         new->fsuid = rqstp->rq_cred.cr_uid;
6088         new->fsgid = rqstp->rq_cred.cr_gid;
6089 +       /* FIXME: this desperately needs a tag :)
6090 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
6091 +                       */
6092  
6093         rqgi = rqstp->rq_cred.cr_group_info;
6094  
6095 diff -NurpP --minimal linux-2.6.36/fs/nfsd/nfs3xdr.c linux-2.6.36-vs2.3.0.36.33/fs/nfsd/nfs3xdr.c
6096 --- linux-2.6.36/fs/nfsd/nfs3xdr.c      2010-02-25 11:52:05.000000000 +0100
6097 +++ linux-2.6.36-vs2.3.0.36.33/fs/nfsd/nfs3xdr.c        2010-10-21 13:09:36.000000000 +0200
6098 @@ -7,6 +7,7 @@
6099   */
6100  
6101  #include <linux/namei.h>
6102 +#include <linux/vs_tag.h>
6103  #include "xdr3.h"
6104  #include "auth.h"
6105  
6106 @@ -95,6 +96,8 @@ static __be32 *
6107  decode_sattr3(__be32 *p, struct iattr *iap)
6108  {
6109         u32     tmp;
6110 +       uid_t   uid = 0;
6111 +       gid_t   gid = 0;
6112  
6113         iap->ia_valid = 0;
6114  
6115 @@ -104,12 +107,15 @@ decode_sattr3(__be32 *p, struct iattr *i
6116         }
6117         if (*p++) {
6118                 iap->ia_valid |= ATTR_UID;
6119 -               iap->ia_uid = ntohl(*p++);
6120 +               uid = ntohl(*p++);
6121         }
6122         if (*p++) {
6123                 iap->ia_valid |= ATTR_GID;
6124 -               iap->ia_gid = ntohl(*p++);
6125 +               gid = ntohl(*p++);
6126         }
6127 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6128 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6129 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6130         if (*p++) {
6131                 u64     newsize;
6132  
6133 @@ -165,8 +171,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
6134         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
6135         *p++ = htonl((u32) stat->mode);
6136         *p++ = htonl((u32) stat->nlink);
6137 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6138 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6139 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6140 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6141 +               stat->uid, stat->tag)));
6142 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6143 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6144 +               stat->gid, stat->tag)));
6145         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
6146                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
6147         } else {
6148 diff -NurpP --minimal linux-2.6.36/fs/nfsd/nfs4xdr.c linux-2.6.36-vs2.3.0.36.33/fs/nfsd/nfs4xdr.c
6149 --- linux-2.6.36/fs/nfsd/nfs4xdr.c      2010-10-21 13:07:50.000000000 +0200
6150 +++ linux-2.6.36-vs2.3.0.36.33/fs/nfsd/nfs4xdr.c        2010-10-21 13:09:36.000000000 +0200
6151 @@ -47,6 +47,7 @@
6152  #include <linux/nfsd_idmap.h>
6153  #include <linux/nfs4_acl.h>
6154  #include <linux/sunrpc/svcauth_gss.h>
6155 +#include <linux/vs_tag.h>
6156  
6157  #include "xdr4.h"
6158  #include "vfs.h"
6159 @@ -2057,14 +2058,18 @@ out_acl:
6160                 WRITE32(stat.nlink);
6161         }
6162         if (bmval1 & FATTR4_WORD1_OWNER) {
6163 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
6164 +               status = nfsd4_encode_user(rqstp,
6165 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
6166 +                       stat.uid, stat.tag), &p, &buflen);
6167                 if (status == nfserr_resource)
6168                         goto out_resource;
6169                 if (status)
6170                         goto out;
6171         }
6172         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
6173 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
6174 +               status = nfsd4_encode_group(rqstp,
6175 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
6176 +                       stat.gid, stat.tag), &p, &buflen);
6177                 if (status == nfserr_resource)
6178                         goto out_resource;
6179                 if (status)
6180 diff -NurpP --minimal linux-2.6.36/fs/nfsd/nfsxdr.c linux-2.6.36-vs2.3.0.36.33/fs/nfsd/nfsxdr.c
6181 --- linux-2.6.36/fs/nfsd/nfsxdr.c       2010-02-25 11:52:05.000000000 +0100
6182 +++ linux-2.6.36-vs2.3.0.36.33/fs/nfsd/nfsxdr.c 2010-10-21 13:09:36.000000000 +0200
6183 @@ -6,6 +6,7 @@
6184  
6185  #include "xdr.h"
6186  #include "auth.h"
6187 +#include <linux/vs_tag.h>
6188  
6189  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6190  
6191 @@ -88,6 +89,8 @@ static __be32 *
6192  decode_sattr(__be32 *p, struct iattr *iap)
6193  {
6194         u32     tmp, tmp1;
6195 +       uid_t   uid = 0;
6196 +       gid_t   gid = 0;
6197  
6198         iap->ia_valid = 0;
6199  
6200 @@ -101,12 +104,15 @@ decode_sattr(__be32 *p, struct iattr *ia
6201         }
6202         if ((tmp = ntohl(*p++)) != (u32)-1) {
6203                 iap->ia_valid |= ATTR_UID;
6204 -               iap->ia_uid = tmp;
6205 +               uid = tmp;
6206         }
6207         if ((tmp = ntohl(*p++)) != (u32)-1) {
6208                 iap->ia_valid |= ATTR_GID;
6209 -               iap->ia_gid = tmp;
6210 +               gid = tmp;
6211         }
6212 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6213 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6214 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6215         if ((tmp = ntohl(*p++)) != (u32)-1) {
6216                 iap->ia_valid |= ATTR_SIZE;
6217                 iap->ia_size = tmp;
6218 @@ -151,8 +157,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
6219         *p++ = htonl(nfs_ftypes[type >> 12]);
6220         *p++ = htonl((u32) stat->mode);
6221         *p++ = htonl((u32) stat->nlink);
6222 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6223 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6224 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6225 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
6226 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6227 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
6228  
6229         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
6230                 *p++ = htonl(NFS_MAXPATHLEN);
6231 diff -NurpP --minimal linux-2.6.36/fs/ocfs2/dlmglue.c linux-2.6.36-vs2.3.0.36.33/fs/ocfs2/dlmglue.c
6232 --- linux-2.6.36/fs/ocfs2/dlmglue.c     2010-10-21 13:07:50.000000000 +0200
6233 +++ linux-2.6.36-vs2.3.0.36.33/fs/ocfs2/dlmglue.c       2010-10-21 13:09:36.000000000 +0200
6234 @@ -2114,6 +2114,7 @@ static void __ocfs2_stuff_meta_lvb(struc
6235         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
6236         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
6237         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
6238 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
6239         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
6240         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
6241         lvb->lvb_iatime_packed  =
6242 @@ -2168,6 +2169,7 @@ static void ocfs2_refresh_inode_from_lvb
6243  
6244         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
6245         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
6246 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
6247         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
6248         inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
6249         ocfs2_unpack_timespec(&inode->i_atime,
6250 diff -NurpP --minimal linux-2.6.36/fs/ocfs2/dlmglue.h linux-2.6.36-vs2.3.0.36.33/fs/ocfs2/dlmglue.h
6251 --- linux-2.6.36/fs/ocfs2/dlmglue.h     2010-10-21 13:07:50.000000000 +0200
6252 +++ linux-2.6.36-vs2.3.0.36.33/fs/ocfs2/dlmglue.h       2010-10-21 13:09:36.000000000 +0200
6253 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
6254         __be16       lvb_inlink;
6255         __be32       lvb_iattr;
6256         __be32       lvb_igeneration;
6257 -       __be32       lvb_reserved2;
6258 +       __be16       lvb_itag;
6259 +       __be16       lvb_reserved2;
6260  };
6261  
6262  #define OCFS2_QINFO_LVB_VERSION 1
6263 diff -NurpP --minimal linux-2.6.36/fs/ocfs2/file.c linux-2.6.36-vs2.3.0.36.33/fs/ocfs2/file.c
6264 --- linux-2.6.36/fs/ocfs2/file.c        2010-10-21 13:07:50.000000000 +0200
6265 +++ linux-2.6.36-vs2.3.0.36.33/fs/ocfs2/file.c  2010-10-21 13:09:36.000000000 +0200
6266 @@ -1138,13 +1138,15 @@ int ocfs2_setattr(struct dentry *dentry,
6267                 mlog(0, "uid change: %d\n", attr->ia_uid);
6268         if (attr->ia_valid & ATTR_GID)
6269                 mlog(0, "gid change: %d\n", attr->ia_gid);
6270 +       if (attr->ia_valid & ATTR_TAG)
6271 +               mlog(0, "tag change: %d\n", attr->ia_tag);
6272         if (attr->ia_valid & ATTR_SIZE)
6273                 mlog(0, "size change...\n");
6274         if (attr->ia_valid & (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME))
6275                 mlog(0, "time change...\n");
6276  
6277  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
6278 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
6279 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
6280         if (!(attr->ia_valid & OCFS2_VALID_ATTRS)) {
6281                 mlog(0, "can't handle attrs: 0x%x\n", attr->ia_valid);
6282                 return 0;
6283 diff -NurpP --minimal linux-2.6.36/fs/ocfs2/inode.c linux-2.6.36-vs2.3.0.36.33/fs/ocfs2/inode.c
6284 --- linux-2.6.36/fs/ocfs2/inode.c       2010-10-21 13:07:50.000000000 +0200
6285 +++ linux-2.6.36-vs2.3.0.36.33/fs/ocfs2/inode.c 2010-10-21 13:09:36.000000000 +0200
6286 @@ -28,6 +28,7 @@
6287  #include <linux/highmem.h>
6288  #include <linux/pagemap.h>
6289  #include <linux/quotaops.h>
6290 +#include <linux/vs_tag.h>
6291  
6292  #include <asm/byteorder.h>
6293  
6294 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode 
6295  {
6296         unsigned int flags = OCFS2_I(inode)->ip_attr;
6297  
6298 -       inode->i_flags &= ~(S_IMMUTABLE |
6299 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
6300                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
6301  
6302         if (flags & OCFS2_IMMUTABLE_FL)
6303                 inode->i_flags |= S_IMMUTABLE;
6304 +       if (flags & OCFS2_IXUNLINK_FL)
6305 +               inode->i_flags |= S_IXUNLINK;
6306  
6307         if (flags & OCFS2_SYNC_FL)
6308                 inode->i_flags |= S_SYNC;
6309 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode 
6310                 inode->i_flags |= S_NOATIME;
6311         if (flags & OCFS2_DIRSYNC_FL)
6312                 inode->i_flags |= S_DIRSYNC;
6313 +
6314 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
6315 +
6316 +       if (flags & OCFS2_BARRIER_FL)
6317 +               inode->i_vflags |= V_BARRIER;
6318 +       if (flags & OCFS2_COW_FL)
6319 +               inode->i_vflags |= V_COW;
6320  }
6321  
6322  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
6323  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
6324  {
6325         unsigned int flags = oi->vfs_inode.i_flags;
6326 +       unsigned int vflags = oi->vfs_inode.i_vflags;
6327 +
6328 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
6329 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
6330 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
6331 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
6332 +
6333 +       if (flags & S_IMMUTABLE)
6334 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6335 +       if (flags & S_IXUNLINK)
6336 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
6337  
6338 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
6339 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
6340         if (flags & S_SYNC)
6341                 oi->ip_attr |= OCFS2_SYNC_FL;
6342         if (flags & S_APPEND)
6343                 oi->ip_attr |= OCFS2_APPEND_FL;
6344 -       if (flags & S_IMMUTABLE)
6345 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6346         if (flags & S_NOATIME)
6347                 oi->ip_attr |= OCFS2_NOATIME_FL;
6348         if (flags & S_DIRSYNC)
6349                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
6350 +
6351 +       if (vflags & V_BARRIER)
6352 +               oi->ip_attr |= OCFS2_BARRIER_FL;
6353 +       if (vflags & V_COW)
6354 +               oi->ip_attr |= OCFS2_COW_FL;
6355  }
6356  
6357  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
6358 @@ -245,6 +267,8 @@ void ocfs2_populate_inode(struct inode *
6359         struct super_block *sb;
6360         struct ocfs2_super *osb;
6361         int use_plocks = 1;
6362 +       uid_t uid;
6363 +       gid_t gid;
6364  
6365         mlog_entry("(0x%p, size:%llu)\n", inode,
6366                    (unsigned long long)le64_to_cpu(fe->i_size));
6367 @@ -276,8 +300,12 @@ void ocfs2_populate_inode(struct inode *
6368         inode->i_generation = le32_to_cpu(fe->i_generation);
6369         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
6370         inode->i_mode = le16_to_cpu(fe->i_mode);
6371 -       inode->i_uid = le32_to_cpu(fe->i_uid);
6372 -       inode->i_gid = le32_to_cpu(fe->i_gid);
6373 +       uid = le32_to_cpu(fe->i_uid);
6374 +       gid = le32_to_cpu(fe->i_gid);
6375 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6376 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6377 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
6378 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
6379  
6380         /* Fast symlinks will have i_size but no allocated clusters. */
6381         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
6382 diff -NurpP --minimal linux-2.6.36/fs/ocfs2/inode.h linux-2.6.36-vs2.3.0.36.33/fs/ocfs2/inode.h
6383 --- linux-2.6.36/fs/ocfs2/inode.h       2010-10-21 13:07:50.000000000 +0200
6384 +++ linux-2.6.36-vs2.3.0.36.33/fs/ocfs2/inode.h 2010-10-21 13:09:36.000000000 +0200
6385 @@ -153,6 +153,7 @@ struct buffer_head *ocfs2_bread(struct i
6386  
6387  void ocfs2_set_inode_flags(struct inode *inode);
6388  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
6389 +int ocfs2_sync_flags(struct inode *inode, int, int);
6390  
6391  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
6392  {
6393 diff -NurpP --minimal linux-2.6.36/fs/ocfs2/ioctl.c linux-2.6.36-vs2.3.0.36.33/fs/ocfs2/ioctl.c
6394 --- linux-2.6.36/fs/ocfs2/ioctl.c       2010-02-25 11:52:06.000000000 +0100
6395 +++ linux-2.6.36-vs2.3.0.36.33/fs/ocfs2/ioctl.c 2010-10-21 13:09:36.000000000 +0200
6396 @@ -43,7 +43,41 @@ static int ocfs2_get_inode_attr(struct i
6397         return status;
6398  }
6399  
6400 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6401 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
6402 +{
6403 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
6404 +       struct buffer_head *bh = NULL;
6405 +       handle_t *handle = NULL;
6406 +       int status;
6407 +
6408 +       status = ocfs2_inode_lock(inode, &bh, 1);
6409 +       if (status < 0) {
6410 +               mlog_errno(status);
6411 +               return status;
6412 +       }
6413 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6414 +       if (IS_ERR(handle)) {
6415 +               status = PTR_ERR(handle);
6416 +               mlog_errno(status);
6417 +               goto bail_unlock;
6418 +       }
6419 +
6420 +       inode->i_flags = flags;
6421 +       inode->i_vflags = vflags;
6422 +       ocfs2_get_inode_flags(OCFS2_I(inode));
6423 +
6424 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
6425 +       if (status < 0)
6426 +               mlog_errno(status);
6427 +
6428 +       ocfs2_commit_trans(osb, handle);
6429 +bail_unlock:
6430 +       ocfs2_inode_unlock(inode, 1);
6431 +       brelse(bh);
6432 +       return status;
6433 +}
6434 +
6435 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6436                                 unsigned mask)
6437  {
6438         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
6439 @@ -68,6 +102,11 @@ static int ocfs2_set_inode_attr(struct i
6440         if (!S_ISDIR(inode->i_mode))
6441                 flags &= ~OCFS2_DIRSYNC_FL;
6442  
6443 +       if (IS_BARRIER(inode)) {
6444 +               vxwprintk_task(1, "messing with the barrier.");
6445 +               goto bail_unlock;
6446 +       }
6447 +
6448         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6449         if (IS_ERR(handle)) {
6450                 status = PTR_ERR(handle);
6451 @@ -109,6 +148,7 @@ bail:
6452         return status;
6453  }
6454  
6455 +
6456  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
6457  {
6458         struct inode *inode = filp->f_path.dentry->d_inode;
6459 diff -NurpP --minimal linux-2.6.36/fs/ocfs2/namei.c linux-2.6.36-vs2.3.0.36.33/fs/ocfs2/namei.c
6460 --- linux-2.6.36/fs/ocfs2/namei.c       2010-10-21 13:07:50.000000000 +0200
6461 +++ linux-2.6.36-vs2.3.0.36.33/fs/ocfs2/namei.c 2010-10-21 13:09:36.000000000 +0200
6462 @@ -41,6 +41,7 @@
6463  #include <linux/slab.h>
6464  #include <linux/highmem.h>
6465  #include <linux/quotaops.h>
6466 +#include <linux/vs_tag.h>
6467  
6468  #define MLOG_MASK_PREFIX ML_NAMEI
6469  #include <cluster/masklog.h>
6470 @@ -486,6 +487,7 @@ static int __ocfs2_mknod_locked(struct i
6471         struct ocfs2_dinode *fe = NULL;
6472         struct ocfs2_extent_list *fel;
6473         u16 feat;
6474 +       tag_t tag;
6475  
6476         *new_fe_bh = NULL;
6477  
6478 @@ -523,8 +525,11 @@ static int __ocfs2_mknod_locked(struct i
6479         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
6480         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
6481         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
6482 -       fe->i_uid = cpu_to_le32(inode->i_uid);
6483 -       fe->i_gid = cpu_to_le32(inode->i_gid);
6484 +
6485 +       tag = dx_current_fstag(osb->sb);
6486 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
6487 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
6488 +       inode->i_tag = tag;
6489         fe->i_mode = cpu_to_le16(inode->i_mode);
6490         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
6491                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
6492 diff -NurpP --minimal linux-2.6.36/fs/ocfs2/ocfs2_fs.h linux-2.6.36-vs2.3.0.36.33/fs/ocfs2/ocfs2_fs.h
6493 --- linux-2.6.36/fs/ocfs2/ocfs2_fs.h    2010-10-21 13:07:51.000000000 +0200
6494 +++ linux-2.6.36-vs2.3.0.36.33/fs/ocfs2/ocfs2_fs.h      2010-10-21 14:00:41.000000000 +0200
6495 @@ -258,6 +258,11 @@
6496  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
6497  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
6498  
6499 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
6500 +
6501 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
6502 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
6503 +
6504  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
6505  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
6506  
6507 diff -NurpP --minimal linux-2.6.36/fs/ocfs2/ocfs2.h linux-2.6.36-vs2.3.0.36.33/fs/ocfs2/ocfs2.h
6508 --- linux-2.6.36/fs/ocfs2/ocfs2.h       2010-08-02 16:52:51.000000000 +0200
6509 +++ linux-2.6.36-vs2.3.0.36.33/fs/ocfs2/ocfs2.h 2010-10-21 13:09:36.000000000 +0200
6510 @@ -256,6 +256,7 @@ enum ocfs2_mount_options
6511                                                    control lists */
6512         OCFS2_MOUNT_USRQUOTA = 1 << 10, /* We support user quotas */
6513         OCFS2_MOUNT_GRPQUOTA = 1 << 11, /* We support group quotas */
6514 +       OCFS2_MOUNT_TAGGED = 1 << 12, /* use tagging */
6515  };
6516  
6517  #define OCFS2_OSB_SOFT_RO                      0x0001
6518 diff -NurpP --minimal linux-2.6.36/fs/ocfs2/super.c linux-2.6.36-vs2.3.0.36.33/fs/ocfs2/super.c
6519 --- linux-2.6.36/fs/ocfs2/super.c       2010-10-21 13:07:51.000000000 +0200
6520 +++ linux-2.6.36-vs2.3.0.36.33/fs/ocfs2/super.c 2010-10-21 13:09:36.000000000 +0200
6521 @@ -179,6 +179,7 @@ enum {
6522         Opt_grpquota,
6523         Opt_resv_level,
6524         Opt_dir_resv_level,
6525 +       Opt_tag, Opt_notag, Opt_tagid,
6526         Opt_err,
6527  };
6528  
6529 @@ -207,6 +208,9 @@ static const match_table_t tokens = {
6530         {Opt_grpquota, "grpquota"},
6531         {Opt_resv_level, "resv_level=%u"},
6532         {Opt_dir_resv_level, "dir_resv_level=%u"},
6533 +       {Opt_tag, "tag"},
6534 +       {Opt_notag, "notag"},
6535 +       {Opt_tagid, "tagid=%u"},
6536         {Opt_err, NULL}
6537  };
6538  
6539 @@ -617,6 +621,13 @@ static int ocfs2_remount(struct super_bl
6540                 goto out;
6541         }
6542  
6543 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
6544 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
6545 +               ret = -EINVAL;
6546 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
6547 +               goto out;
6548 +       }
6549 +
6550         if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
6551             (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
6552                 ret = -EINVAL;
6553 @@ -1153,6 +1164,9 @@ static int ocfs2_fill_super(struct super
6554  
6555         ocfs2_complete_mount_recovery(osb);
6556  
6557 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
6558 +               sb->s_flags |= MS_TAGGED;
6559 +
6560         if (ocfs2_mount_local(osb))
6561                 snprintf(nodestr, sizeof(nodestr), "local");
6562         else
6563 @@ -1468,6 +1482,20 @@ static int ocfs2_parse_options(struct su
6564                             option < OCFS2_MAX_RESV_LEVEL)
6565                                 mopt->dir_resv_level = option;
6566                         break;
6567 +#ifndef CONFIG_TAGGING_NONE
6568 +               case Opt_tag:
6569 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6570 +                       break;
6571 +               case Opt_notag:
6572 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
6573 +                       break;
6574 +#endif
6575 +#ifdef CONFIG_PROPAGATE
6576 +               case Opt_tagid:
6577 +                       /* use args[0] */
6578 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6579 +                       break;
6580 +#endif
6581                 default:
6582                         mlog(ML_ERROR,
6583                              "Unrecognized mount option \"%s\" "
6584 diff -NurpP --minimal linux-2.6.36/fs/open.c linux-2.6.36-vs2.3.0.36.33/fs/open.c
6585 --- linux-2.6.36/fs/open.c      2010-10-21 13:07:51.000000000 +0200
6586 +++ linux-2.6.36-vs2.3.0.36.33/fs/open.c        2010-10-21 13:55:41.000000000 +0200
6587 @@ -30,6 +30,11 @@
6588  #include <linux/fs_struct.h>
6589  #include <linux/ima.h>
6590  #include <linux/dnotify.h>
6591 +#include <linux/vs_base.h>
6592 +#include <linux/vs_limit.h>
6593 +#include <linux/vs_tag.h>
6594 +#include <linux/vs_cowbl.h>
6595 +#include <linux/vserver/dlimit.h>
6596  
6597  #include "internal.h"
6598  
6599 @@ -481,6 +486,12 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6600         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
6601         if (error)
6602                 goto out;
6603 +
6604 +#ifdef CONFIG_VSERVER_COWBL
6605 +       error = cow_check_and_break(&path);
6606 +       if (error)
6607 +               goto dput_and_out;
6608 +#endif
6609         inode = path.dentry->d_inode;
6610  
6611         error = mnt_want_write(path.mnt);
6612 @@ -518,11 +529,11 @@ static int chown_common(struct path *pat
6613         newattrs.ia_valid =  ATTR_CTIME;
6614         if (user != (uid_t) -1) {
6615                 newattrs.ia_valid |= ATTR_UID;
6616 -               newattrs.ia_uid = user;
6617 +               newattrs.ia_uid = dx_map_uid(user);
6618         }
6619         if (group != (gid_t) -1) {
6620                 newattrs.ia_valid |= ATTR_GID;
6621 -               newattrs.ia_gid = group;
6622 +               newattrs.ia_gid = dx_map_gid(group);
6623         }
6624         if (!S_ISDIR(inode->i_mode))
6625                 newattrs.ia_valid |=
6626 @@ -547,6 +558,10 @@ SYSCALL_DEFINE3(chown, const char __user
6627         error = mnt_want_write(path.mnt);
6628         if (error)
6629                 goto out_release;
6630 +#ifdef CONFIG_VSERVER_COWBL
6631 +       error = cow_check_and_break(&path);
6632 +       if (!error)
6633 +#endif
6634         error = chown_common(&path, user, group);
6635         mnt_drop_write(path.mnt);
6636  out_release:
6637 @@ -572,6 +587,10 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
6638         error = mnt_want_write(path.mnt);
6639         if (error)
6640                 goto out_release;
6641 +#ifdef CONFIG_VSERVER_COWBL
6642 +       error = cow_check_and_break(&path);
6643 +       if (!error)
6644 +#endif
6645         error = chown_common(&path, user, group);
6646         mnt_drop_write(path.mnt);
6647  out_release:
6648 @@ -591,6 +610,10 @@ SYSCALL_DEFINE3(lchown, const char __use
6649         error = mnt_want_write(path.mnt);
6650         if (error)
6651                 goto out_release;
6652 +#ifdef CONFIG_VSERVER_COWBL
6653 +       error = cow_check_and_break(&path);
6654 +       if (!error)
6655 +#endif
6656         error = chown_common(&path, user, group);
6657         mnt_drop_write(path.mnt);
6658  out_release:
6659 @@ -837,6 +860,7 @@ static void __put_unused_fd(struct files
6660         __FD_CLR(fd, fdt->open_fds);
6661         if (fd < files->next_fd)
6662                 files->next_fd = fd;
6663 +       vx_openfd_dec(fd);
6664  }
6665  
6666  void put_unused_fd(unsigned int fd)
6667 diff -NurpP --minimal linux-2.6.36/fs/proc/array.c linux-2.6.36-vs2.3.0.36.33/fs/proc/array.c
6668 --- linux-2.6.36/fs/proc/array.c        2010-08-02 16:52:51.000000000 +0200
6669 +++ linux-2.6.36-vs2.3.0.36.33/fs/proc/array.c  2010-10-21 13:09:36.000000000 +0200
6670 @@ -81,6 +81,8 @@
6671  #include <linux/pid_namespace.h>
6672  #include <linux/ptrace.h>
6673  #include <linux/tracehook.h>
6674 +#include <linux/vs_context.h>
6675 +#include <linux/vs_network.h>
6676  
6677  #include <asm/pgtable.h>
6678  #include <asm/processor.h>
6679 @@ -170,6 +172,9 @@ static inline void task_state(struct seq
6680         rcu_read_lock();
6681         ppid = pid_alive(p) ?
6682                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6683 +       if (unlikely(vx_current_initpid(p->pid)))
6684 +               ppid = 0;
6685 +
6686         tpid = 0;
6687         if (pid_alive(p)) {
6688                 struct task_struct *tracer = tracehook_tracer_task(p);
6689 @@ -287,7 +292,7 @@ static inline void task_sig(struct seq_f
6690  }
6691  
6692  static void render_cap_t(struct seq_file *m, const char *header,
6693 -                       kernel_cap_t *a)
6694 +                       struct vx_info *vxi, kernel_cap_t *a)
6695  {
6696         unsigned __capi;
6697  
6698 @@ -312,10 +317,11 @@ static inline void task_cap(struct seq_f
6699         cap_bset        = cred->cap_bset;
6700         rcu_read_unlock();
6701  
6702 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6703 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6704 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6705 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6706 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6707 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6708 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6709 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6710 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6711  }
6712  
6713  static inline void task_context_switch_counts(struct seq_file *m,
6714 @@ -337,6 +343,42 @@ static void task_cpus_allowed(struct seq
6715         seq_printf(m, "\n");
6716  }
6717  
6718 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6719 +                       struct pid *pid, struct task_struct *task)
6720 +{
6721 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6722 +                       "Count:\t%u\n"
6723 +                       "uts:\t%p(%c)\n"
6724 +                       "ipc:\t%p(%c)\n"
6725 +                       "mnt:\t%p(%c)\n"
6726 +                       "pid:\t%p(%c)\n"
6727 +                       "net:\t%p(%c)\n",
6728 +                       task->nsproxy,
6729 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6730 +                       atomic_read(&task->nsproxy->count),
6731 +                       task->nsproxy->uts_ns,
6732 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6733 +                       task->nsproxy->ipc_ns,
6734 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6735 +                       task->nsproxy->mnt_ns,
6736 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6737 +                       task->nsproxy->pid_ns,
6738 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6739 +                       task->nsproxy->net_ns,
6740 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6741 +       return 0;
6742 +}
6743 +
6744 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6745 +{
6746 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6747 +               return;
6748 +
6749 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6750 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6751 +}
6752 +
6753 +
6754  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6755                         struct pid *pid, struct task_struct *task)
6756  {
6757 @@ -353,6 +395,7 @@ int proc_pid_status(struct seq_file *m, 
6758         task_cap(m, task);
6759         task_cpus_allowed(m, task);
6760         cpuset_task_status_allowed(m, task);
6761 +       task_vs_id(m, task);
6762  #if defined(CONFIG_S390)
6763         task_show_regs(m, task);
6764  #endif
6765 @@ -465,6 +508,17 @@ static int do_task_stat(struct seq_file 
6766         /* convert nsec -> ticks */
6767         start_time = nsec_to_clock_t(start_time);
6768  
6769 +       /* fixup start time for virt uptime */
6770 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6771 +               unsigned long long bias =
6772 +                       current->vx_info->cvirt.bias_clock;
6773 +
6774 +               if (start_time > bias)
6775 +                       start_time -= bias;
6776 +               else
6777 +                       start_time = 0;
6778 +       }
6779 +
6780         seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \
6781  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
6782  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
6783 diff -NurpP --minimal linux-2.6.36/fs/proc/base.c linux-2.6.36-vs2.3.0.36.33/fs/proc/base.c
6784 --- linux-2.6.36/fs/proc/base.c 2010-10-21 13:07:51.000000000 +0200
6785 +++ linux-2.6.36-vs2.3.0.36.33/fs/proc/base.c   2010-10-21 13:58:32.000000000 +0200
6786 @@ -83,6 +83,8 @@
6787  #include <linux/pid_namespace.h>
6788  #include <linux/fs_struct.h>
6789  #include <linux/slab.h>
6790 +#include <linux/vs_context.h>
6791 +#include <linux/vs_network.h>
6792  #include "internal.h"
6793  
6794  /* NOTE:
6795 @@ -1041,12 +1043,17 @@ static ssize_t oom_adjust_write(struct f
6796                 return -ESRCH;
6797         }
6798  
6799 -       if (oom_adjust < task->signal->oom_adj && !capable(CAP_SYS_RESOURCE)) {
6800 +       if (oom_adjust < task->signal->oom_adj &&
6801 +               !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6802                 unlock_task_sighand(task, &flags);
6803                 put_task_struct(task);
6804                 return -EACCES;
6805         }
6806  
6807 +       /* prevent guest processes from circumventing the oom killer */
6808 +       if (vx_current_xid() && (oom_adjust == OOM_DISABLE))
6809 +               oom_adjust = OOM_ADJUST_MIN;
6810 +
6811         /*
6812          * Warn that /proc/pid/oom_adj is deprecated, see
6813          * Documentation/feature-removal-schedule.txt.
6814 @@ -1179,7 +1186,7 @@ static ssize_t proc_loginuid_write(struc
6815         ssize_t length;
6816         uid_t loginuid;
6817  
6818 -       if (!capable(CAP_AUDIT_CONTROL))
6819 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
6820                 return -EPERM;
6821  
6822         rcu_read_lock();
6823 @@ -1617,6 +1624,8 @@ static struct inode *proc_pid_make_inode
6824                 inode->i_gid = cred->egid;
6825                 rcu_read_unlock();
6826         }
6827 +       /* procfs is xid tagged */
6828 +       inode->i_tag = (tag_t)vx_task_xid(task);
6829         security_task_to_inode(task, inode);
6830  
6831  out:
6832 @@ -2167,6 +2176,13 @@ static struct dentry *proc_pident_lookup
6833         if (!task)
6834                 goto out_no_task;
6835  
6836 +       /* TODO: maybe we can come up with a generic approach? */
6837 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6838 +               (dentry->d_name.len == 5) &&
6839 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6840 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6841 +               goto out;
6842 +
6843         /*
6844          * Yes, it does not scale. And it should not. Don't add
6845          * new entries into /proc/<tgid>/ without very good reasons.
6846 @@ -2574,7 +2590,7 @@ out_iput:
6847  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
6848  {
6849         struct dentry *error;
6850 -       struct task_struct *task = get_proc_task(dir);
6851 +       struct task_struct *task = get_proc_task_real(dir);
6852         const struct pid_entry *p, *last;
6853  
6854         error = ERR_PTR(-ENOENT);
6855 @@ -2664,6 +2680,9 @@ static int proc_pid_personality(struct s
6856  static const struct file_operations proc_task_operations;
6857  static const struct inode_operations proc_task_inode_operations;
6858  
6859 +extern int proc_pid_vx_info(struct task_struct *, char *);
6860 +extern int proc_pid_nx_info(struct task_struct *, char *);
6861 +
6862  static const struct pid_entry tgid_base_stuff[] = {
6863         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6864         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6865 @@ -2723,6 +2742,8 @@ static const struct pid_entry tgid_base_
6866  #ifdef CONFIG_CGROUPS
6867         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6868  #endif
6869 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6870 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6871         INF("oom_score",  S_IRUGO, proc_oom_score),
6872         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
6873         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6874 @@ -2739,6 +2760,7 @@ static const struct pid_entry tgid_base_
6875  #ifdef CONFIG_TASK_IO_ACCOUNTING
6876         INF("io",       S_IRUGO, proc_tgid_io_accounting),
6877  #endif
6878 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6879  };
6880  
6881  static int proc_tgid_base_readdir(struct file * filp,
6882 @@ -2930,7 +2952,7 @@ retry:
6883         iter.task = NULL;
6884         pid = find_ge_pid(iter.tgid, ns);
6885         if (pid) {
6886 -               iter.tgid = pid_nr_ns(pid, ns);
6887 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6888                 iter.task = pid_task(pid, PIDTYPE_PID);
6889                 /* What we to know is if the pid we have find is the
6890                  * pid of a thread_group_leader.  Testing for task
6891 @@ -2960,7 +2982,7 @@ static int proc_pid_fill_cache(struct fi
6892         struct tgid_iter iter)
6893  {
6894         char name[PROC_NUMBUF];
6895 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6896 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6897         return proc_fill_cache(filp, dirent, filldir, name, len,
6898                                 proc_pid_instantiate, iter.task, NULL);
6899  }
6900 @@ -2969,7 +2991,7 @@ static int proc_pid_fill_cache(struct fi
6901  int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
6902  {
6903         unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
6904 -       struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode);
6905 +       struct task_struct *reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
6906         struct tgid_iter iter;
6907         struct pid_namespace *ns;
6908  
6909 @@ -2989,6 +3011,8 @@ int proc_pid_readdir(struct file * filp,
6910              iter.task;
6911              iter.tgid += 1, iter = next_tgid(ns, iter)) {
6912                 filp->f_pos = iter.tgid + TGID_OFFSET;
6913 +               if (!vx_proc_task_visible(iter.task))
6914 +                       continue;
6915                 if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
6916                         put_task_struct(iter.task);
6917                         goto out;
6918 @@ -3137,6 +3161,8 @@ static struct dentry *proc_task_lookup(s
6919         tid = name_to_int(dentry);
6920         if (tid == ~0U)
6921                 goto out;
6922 +       if (vx_current_initpid(tid))
6923 +               goto out;
6924  
6925         ns = dentry->d_sb->s_fs_info;
6926         rcu_read_lock();
6927 diff -NurpP --minimal linux-2.6.36/fs/proc/generic.c linux-2.6.36-vs2.3.0.36.33/fs/proc/generic.c
6928 --- linux-2.6.36/fs/proc/generic.c      2010-10-21 13:07:51.000000000 +0200
6929 +++ linux-2.6.36-vs2.3.0.36.33/fs/proc/generic.c        2010-10-21 13:09:36.000000000 +0200
6930 @@ -22,6 +22,7 @@
6931  #include <linux/bitops.h>
6932  #include <linux/spinlock.h>
6933  #include <linux/completion.h>
6934 +#include <linux/vserver/inode.h>
6935  #include <asm/uaccess.h>
6936  
6937  #include "internal.h"
6938 @@ -424,6 +425,8 @@ struct dentry *proc_lookup_de(struct pro
6939         for (de = de->subdir; de ; de = de->next) {
6940                 if (de->namelen != dentry->d_name.len)
6941                         continue;
6942 +                       if (!vx_hide_check(0, de->vx_flags))
6943 +                               continue;
6944                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6945                         unsigned int ino;
6946  
6947 @@ -432,6 +435,8 @@ struct dentry *proc_lookup_de(struct pro
6948                         spin_unlock(&proc_subdir_lock);
6949                         error = -EINVAL;
6950                         inode = proc_get_inode(dir->i_sb, ino, de);
6951 +                               /* generic proc entries belong to the host */
6952 +                               inode->i_tag = 0;
6953                         goto out_unlock;
6954                 }
6955         }
6956 @@ -509,6 +514,8 @@ int proc_readdir_de(struct proc_dir_entr
6957  
6958                                 /* filldir passes info to user space */
6959                                 pde_get(de);
6960 +                               if (!vx_hide_check(0, de->vx_flags))
6961 +                                       goto skip;
6962                                 spin_unlock(&proc_subdir_lock);
6963                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6964                                             de->low_ino, de->mode >> 12) < 0) {
6965 @@ -516,6 +523,7 @@ int proc_readdir_de(struct proc_dir_entr
6966                                         goto out;
6967                                 }
6968                                 spin_lock(&proc_subdir_lock);
6969 +                       skip:
6970                                 filp->f_pos++;
6971                                 next = de->next;
6972                                 pde_put(de);
6973 @@ -630,6 +638,7 @@ static struct proc_dir_entry *__proc_cre
6974         ent->nlink = nlink;
6975         atomic_set(&ent->count, 1);
6976         ent->pde_users = 0;
6977 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6978         spin_lock_init(&ent->pde_unload_lock);
6979         ent->pde_unload_completion = NULL;
6980         INIT_LIST_HEAD(&ent->pde_openers);
6981 @@ -653,7 +662,8 @@ struct proc_dir_entry *proc_symlink(cons
6982                                 kfree(ent->data);
6983                                 kfree(ent);
6984                                 ent = NULL;
6985 -                       }
6986 +                       } else
6987 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6988                 } else {
6989                         kfree(ent);
6990                         ent = NULL;
6991 diff -NurpP --minimal linux-2.6.36/fs/proc/inode.c linux-2.6.36-vs2.3.0.36.33/fs/proc/inode.c
6992 --- linux-2.6.36/fs/proc/inode.c        2010-10-21 13:07:51.000000000 +0200
6993 +++ linux-2.6.36-vs2.3.0.36.33/fs/proc/inode.c  2010-10-21 13:09:36.000000000 +0200
6994 @@ -428,6 +428,8 @@ struct inode *proc_get_inode(struct supe
6995                         inode->i_uid = de->uid;
6996                         inode->i_gid = de->gid;
6997                 }
6998 +               if (de->vx_flags)
6999 +                       PROC_I(inode)->vx_flags = de->vx_flags;
7000                 if (de->size)
7001                         inode->i_size = de->size;
7002                 if (de->nlink)
7003 diff -NurpP --minimal linux-2.6.36/fs/proc/internal.h linux-2.6.36-vs2.3.0.36.33/fs/proc/internal.h
7004 --- linux-2.6.36/fs/proc/internal.h     2010-02-25 11:52:06.000000000 +0100
7005 +++ linux-2.6.36-vs2.3.0.36.33/fs/proc/internal.h       2010-10-21 13:09:36.000000000 +0200
7006 @@ -10,6 +10,7 @@
7007   */
7008  
7009  #include <linux/proc_fs.h>
7010 +#include <linux/vs_pid.h>
7011  
7012  extern struct proc_dir_entry proc_root;
7013  #ifdef CONFIG_PROC_SYSCTL
7014 @@ -51,6 +52,9 @@ extern int proc_pid_status(struct seq_fi
7015                                 struct pid *pid, struct task_struct *task);
7016  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
7017                                 struct pid *pid, struct task_struct *task);
7018 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
7019 +                               struct pid *pid, struct task_struct *task);
7020 +
7021  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
7022  
7023  extern const struct file_operations proc_maps_operations;
7024 @@ -68,11 +72,16 @@ static inline struct pid *proc_pid(struc
7025         return PROC_I(inode)->pid;
7026  }
7027  
7028 -static inline struct task_struct *get_proc_task(struct inode *inode)
7029 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
7030  {
7031         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
7032  }
7033  
7034 +static inline struct task_struct *get_proc_task(struct inode *inode)
7035 +{
7036 +       return vx_get_proc_task(inode, proc_pid(inode));
7037 +}
7038 +
7039  static inline int proc_fd(struct inode *inode)
7040  {
7041         return PROC_I(inode)->fd;
7042 diff -NurpP --minimal linux-2.6.36/fs/proc/loadavg.c linux-2.6.36-vs2.3.0.36.33/fs/proc/loadavg.c
7043 --- linux-2.6.36/fs/proc/loadavg.c      2009-09-10 15:26:23.000000000 +0200
7044 +++ linux-2.6.36-vs2.3.0.36.33/fs/proc/loadavg.c        2010-10-21 13:09:36.000000000 +0200
7045 @@ -12,15 +12,27 @@
7046  
7047  static int loadavg_proc_show(struct seq_file *m, void *v)
7048  {
7049 +       unsigned long running;
7050 +       unsigned int threads;
7051         unsigned long avnrun[3];
7052  
7053         get_avenrun(avnrun, FIXED_1/200, 0);
7054  
7055 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
7056 +               struct vx_info *vxi = current_vx_info();
7057 +
7058 +               running = atomic_read(&vxi->cvirt.nr_running);
7059 +               threads = atomic_read(&vxi->cvirt.nr_threads);
7060 +       } else {
7061 +               running = nr_running();
7062 +               threads = nr_threads;
7063 +       }
7064 +
7065         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
7066                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
7067                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
7068                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
7069 -               nr_running(), nr_threads,
7070 +               running, threads,
7071                 task_active_pid_ns(current)->last_pid);
7072         return 0;
7073  }
7074 diff -NurpP --minimal linux-2.6.36/fs/proc/meminfo.c linux-2.6.36-vs2.3.0.36.33/fs/proc/meminfo.c
7075 --- linux-2.6.36/fs/proc/meminfo.c      2009-12-03 20:02:53.000000000 +0100
7076 +++ linux-2.6.36-vs2.3.0.36.33/fs/proc/meminfo.c        2010-10-21 13:09:36.000000000 +0200
7077 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
7078         allowed = ((totalram_pages - hugetlb_total_pages())
7079                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
7080  
7081 -       cached = global_page_state(NR_FILE_PAGES) -
7082 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
7083 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
7084                         total_swapcache_pages - i.bufferram;
7085         if (cached < 0)
7086                 cached = 0;
7087 diff -NurpP --minimal linux-2.6.36/fs/proc/root.c linux-2.6.36-vs2.3.0.36.33/fs/proc/root.c
7088 --- linux-2.6.36/fs/proc/root.c 2010-08-02 16:52:51.000000000 +0200
7089 +++ linux-2.6.36-vs2.3.0.36.33/fs/proc/root.c   2010-10-21 13:09:36.000000000 +0200
7090 @@ -18,9 +18,14 @@
7091  #include <linux/bitops.h>
7092  #include <linux/mount.h>
7093  #include <linux/pid_namespace.h>
7094 +#include <linux/vserver/inode.h>
7095  
7096  #include "internal.h"
7097  
7098 +struct proc_dir_entry *proc_virtual;
7099 +
7100 +extern void proc_vx_init(void);
7101 +
7102  static int proc_test_super(struct super_block *sb, void *data)
7103  {
7104         return sb->s_fs_info == data;
7105 @@ -135,6 +140,7 @@ void __init proc_root_init(void)
7106  #endif
7107         proc_mkdir("bus", NULL);
7108         proc_sys_init();
7109 +       proc_vx_init();
7110  }
7111  
7112  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
7113 @@ -202,6 +208,7 @@ struct proc_dir_entry proc_root = {
7114         .proc_iops      = &proc_root_inode_operations, 
7115         .proc_fops      = &proc_root_operations,
7116         .parent         = &proc_root,
7117 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
7118  };
7119  
7120  int pid_ns_prepare_proc(struct pid_namespace *ns)
7121 diff -NurpP --minimal linux-2.6.36/fs/proc/uptime.c linux-2.6.36-vs2.3.0.36.33/fs/proc/uptime.c
7122 --- linux-2.6.36/fs/proc/uptime.c       2009-12-03 20:02:53.000000000 +0100
7123 +++ linux-2.6.36-vs2.3.0.36.33/fs/proc/uptime.c 2010-10-21 13:09:36.000000000 +0200
7124 @@ -4,22 +4,22 @@
7125  #include <linux/sched.h>
7126  #include <linux/seq_file.h>
7127  #include <linux/time.h>
7128 -#include <linux/kernel_stat.h>
7129 +#include <linux/vserver/cvirt.h>
7130  #include <asm/cputime.h>
7131  
7132  static int uptime_proc_show(struct seq_file *m, void *v)
7133  {
7134         struct timespec uptime;
7135         struct timespec idle;
7136 -       int i;
7137 -       cputime_t idletime = cputime_zero;
7138 -
7139 -       for_each_possible_cpu(i)
7140 -               idletime = cputime64_add(idletime, kstat_cpu(i).cpustat.idle);
7141 +       cputime_t idletime = cputime_add(init_task.utime, init_task.stime);
7142  
7143         do_posix_clock_monotonic_gettime(&uptime);
7144         monotonic_to_bootbased(&uptime);
7145         cputime_to_timespec(idletime, &idle);
7146 +
7147 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
7148 +               vx_vsi_uptime(&uptime, &idle);
7149 +
7150         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
7151                         (unsigned long) uptime.tv_sec,
7152                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
7153 diff -NurpP --minimal linux-2.6.36/fs/quota/dquot.c linux-2.6.36-vs2.3.0.36.33/fs/quota/dquot.c
7154 --- linux-2.6.36/fs/quota/dquot.c       2010-10-21 13:07:51.000000000 +0200
7155 +++ linux-2.6.36-vs2.3.0.36.33/fs/quota/dquot.c 2010-10-21 13:09:36.000000000 +0200
7156 @@ -1538,6 +1538,9 @@ int __dquot_alloc_space(struct inode *in
7157         int reserve = flags & DQUOT_SPACE_RESERVE;
7158         int nofail = flags & DQUOT_SPACE_NOFAIL;
7159  
7160 +       if ((ret = dl_alloc_space(inode, number)))
7161 +               return ret;
7162 +
7163         /*
7164          * First test before acquiring mutex - solves deadlocks when we
7165          * re-enter the quota code and are already holding the mutex
7166 @@ -1592,6 +1595,9 @@ int dquot_alloc_inode(const struct inode
7167         int cnt, ret = 0;
7168         char warntype[MAXQUOTAS];
7169  
7170 +       if ((ret = dl_alloc_inode(inode)))
7171 +               return ret;
7172 +
7173         /* First test before acquiring mutex - solves deadlocks when we
7174           * re-enter the quota code and are already holding the mutex */
7175         if (!dquot_active(inode))
7176 @@ -1662,6 +1668,8 @@ void __dquot_free_space(struct inode *in
7177         char warntype[MAXQUOTAS];
7178         int reserve = flags & DQUOT_SPACE_RESERVE;
7179  
7180 +       dl_free_space(inode, number);
7181 +
7182         /* First test before acquiring mutex - solves deadlocks when we
7183           * re-enter the quota code and are already holding the mutex */
7184         if (!dquot_active(inode)) {
7185 @@ -1700,6 +1708,8 @@ void dquot_free_inode(const struct inode
7186         unsigned int cnt;
7187         char warntype[MAXQUOTAS];
7188  
7189 +       dl_free_inode(inode);
7190 +
7191         /* First test before acquiring mutex - solves deadlocks when we
7192           * re-enter the quota code and are already holding the mutex */
7193         if (!dquot_active(inode))
7194 diff -NurpP --minimal linux-2.6.36/fs/quota/quota.c linux-2.6.36-vs2.3.0.36.33/fs/quota/quota.c
7195 --- linux-2.6.36/fs/quota/quota.c       2010-08-02 16:52:51.000000000 +0200
7196 +++ linux-2.6.36-vs2.3.0.36.33/fs/quota/quota.c 2010-10-21 13:09:36.000000000 +0200
7197 @@ -8,6 +8,7 @@
7198  #include <linux/fs.h>
7199  #include <linux/namei.h>
7200  #include <linux/slab.h>
7201 +#include <linux/vs_context.h>
7202  #include <asm/current.h>
7203  #include <asm/uaccess.h>
7204  #include <linux/kernel.h>
7205 @@ -38,7 +39,7 @@ static int check_quotactl_permission(str
7206                         break;
7207                 /*FALLTHROUGH*/
7208         default:
7209 -               if (!capable(CAP_SYS_ADMIN))
7210 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7211                         return -EPERM;
7212         }
7213  
7214 @@ -296,6 +297,46 @@ static int do_quotactl(struct super_bloc
7215         }
7216  }
7217  
7218 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7219 +
7220 +#include <linux/vroot.h>
7221 +#include <linux/major.h>
7222 +#include <linux/module.h>
7223 +#include <linux/kallsyms.h>
7224 +#include <linux/vserver/debug.h>
7225 +
7226 +static vroot_grb_func *vroot_get_real_bdev = NULL;
7227 +
7228 +static spinlock_t vroot_grb_lock = SPIN_LOCK_UNLOCKED;
7229 +
7230 +int register_vroot_grb(vroot_grb_func *func) {
7231 +       int ret = -EBUSY;
7232 +
7233 +       spin_lock(&vroot_grb_lock);
7234 +       if (!vroot_get_real_bdev) {
7235 +               vroot_get_real_bdev = func;
7236 +               ret = 0;
7237 +       }
7238 +       spin_unlock(&vroot_grb_lock);
7239 +       return ret;
7240 +}
7241 +EXPORT_SYMBOL(register_vroot_grb);
7242 +
7243 +int unregister_vroot_grb(vroot_grb_func *func) {
7244 +       int ret = -EINVAL;
7245 +
7246 +       spin_lock(&vroot_grb_lock);
7247 +       if (vroot_get_real_bdev) {
7248 +               vroot_get_real_bdev = NULL;
7249 +               ret = 0;
7250 +       }
7251 +       spin_unlock(&vroot_grb_lock);
7252 +       return ret;
7253 +}
7254 +EXPORT_SYMBOL(unregister_vroot_grb);
7255 +
7256 +#endif
7257 +
7258  /*
7259   * look up a superblock on which quota ops will be performed
7260   * - use the name of a block device to find the superblock thereon
7261 @@ -313,6 +354,22 @@ static struct super_block *quotactl_bloc
7262         putname(tmp);
7263         if (IS_ERR(bdev))
7264                 return ERR_CAST(bdev);
7265 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7266 +       if (bdev && bdev->bd_inode &&
7267 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
7268 +               struct block_device *bdnew = (void *)-EINVAL;
7269 +
7270 +               if (vroot_get_real_bdev)
7271 +                       bdnew = vroot_get_real_bdev(bdev);
7272 +               else
7273 +                       vxdprintk(VXD_CBIT(misc, 0),
7274 +                                       "vroot_get_real_bdev not set");
7275 +               bdput(bdev);
7276 +               if (IS_ERR(bdnew))
7277 +                       return ERR_PTR(PTR_ERR(bdnew));
7278 +               bdev = bdnew;
7279 +       }
7280 +#endif
7281         sb = get_super(bdev);
7282         bdput(bdev);
7283         if (!sb)
7284 diff -NurpP --minimal linux-2.6.36/fs/reiserfs/file.c linux-2.6.36-vs2.3.0.36.33/fs/reiserfs/file.c
7285 --- linux-2.6.36/fs/reiserfs/file.c     2010-10-21 13:07:51.000000000 +0200
7286 +++ linux-2.6.36-vs2.3.0.36.33/fs/reiserfs/file.c       2010-10-21 13:09:36.000000000 +0200
7287 @@ -313,4 +313,5 @@ const struct inode_operations reiserfs_f
7288         .listxattr = reiserfs_listxattr,
7289         .removexattr = reiserfs_removexattr,
7290         .permission = reiserfs_permission,
7291 +       .sync_flags = reiserfs_sync_flags,
7292  };
7293 diff -NurpP --minimal linux-2.6.36/fs/reiserfs/inode.c linux-2.6.36-vs2.3.0.36.33/fs/reiserfs/inode.c
7294 --- linux-2.6.36/fs/reiserfs/inode.c    2010-10-21 13:07:51.000000000 +0200
7295 +++ linux-2.6.36-vs2.3.0.36.33/fs/reiserfs/inode.c      2010-10-21 13:59:16.000000000 +0200
7296 @@ -19,6 +19,7 @@
7297  #include <linux/writeback.h>
7298  #include <linux/quotaops.h>
7299  #include <linux/swap.h>
7300 +#include <linux/vs_tag.h>
7301  
7302  int reiserfs_commit_write(struct file *f, struct page *page,
7303                           unsigned from, unsigned to);
7304 @@ -1133,6 +1134,8 @@ static void init_inode(struct inode *ino
7305         struct buffer_head *bh;
7306         struct item_head *ih;
7307         __u32 rdev;
7308 +       uid_t uid;
7309 +       gid_t gid;
7310         //int version = ITEM_VERSION_1;
7311  
7312         bh = PATH_PLAST_BUFFER(path);
7313 @@ -1153,12 +1156,13 @@ static void init_inode(struct inode *ino
7314                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
7315                 unsigned long blocks;
7316  
7317 +               uid = sd_v1_uid(sd);
7318 +               gid = sd_v1_gid(sd);
7319 +
7320                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
7321                 set_inode_sd_version(inode, STAT_DATA_V1);
7322                 inode->i_mode = sd_v1_mode(sd);
7323                 inode->i_nlink = sd_v1_nlink(sd);
7324 -               inode->i_uid = sd_v1_uid(sd);
7325 -               inode->i_gid = sd_v1_gid(sd);
7326                 inode->i_size = sd_v1_size(sd);
7327                 inode->i_atime.tv_sec = sd_v1_atime(sd);
7328                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
7329 @@ -1200,11 +1204,12 @@ static void init_inode(struct inode *ino
7330                 // (directories and symlinks)
7331                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
7332  
7333 +               uid    = sd_v2_uid(sd);
7334 +               gid    = sd_v2_gid(sd);
7335 +
7336                 inode->i_mode = sd_v2_mode(sd);
7337                 inode->i_nlink = sd_v2_nlink(sd);
7338 -               inode->i_uid = sd_v2_uid(sd);
7339                 inode->i_size = sd_v2_size(sd);
7340 -               inode->i_gid = sd_v2_gid(sd);
7341                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
7342                 inode->i_atime.tv_sec = sd_v2_atime(sd);
7343                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
7344 @@ -1234,6 +1239,10 @@ static void init_inode(struct inode *ino
7345                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
7346         }
7347  
7348 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7349 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7350 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
7351 +
7352         pathrelse(path);
7353         if (S_ISREG(inode->i_mode)) {
7354                 inode->i_op = &reiserfs_file_inode_operations;
7355 @@ -1256,13 +1265,15 @@ static void init_inode(struct inode *ino
7356  static void inode2sd(void *sd, struct inode *inode, loff_t size)
7357  {
7358         struct stat_data *sd_v2 = (struct stat_data *)sd;
7359 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
7360 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
7361         __u16 flags;
7362  
7363 +       set_sd_v2_uid(sd_v2, uid);
7364 +       set_sd_v2_gid(sd_v2, gid);
7365         set_sd_v2_mode(sd_v2, inode->i_mode);
7366         set_sd_v2_nlink(sd_v2, inode->i_nlink);
7367 -       set_sd_v2_uid(sd_v2, inode->i_uid);
7368         set_sd_v2_size(sd_v2, size);
7369 -       set_sd_v2_gid(sd_v2, inode->i_gid);
7370         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
7371         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
7372         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
7373 @@ -2861,14 +2872,19 @@ int reiserfs_commit_write(struct file *f
7374  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
7375  {
7376         if (reiserfs_attrs(inode->i_sb)) {
7377 -               if (sd_attrs & REISERFS_SYNC_FL)
7378 -                       inode->i_flags |= S_SYNC;
7379 -               else
7380 -                       inode->i_flags &= ~S_SYNC;
7381                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
7382                         inode->i_flags |= S_IMMUTABLE;
7383                 else
7384                         inode->i_flags &= ~S_IMMUTABLE;
7385 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
7386 +                       inode->i_flags |= S_IXUNLINK;
7387 +               else
7388 +                       inode->i_flags &= ~S_IXUNLINK;
7389 +
7390 +               if (sd_attrs & REISERFS_SYNC_FL)
7391 +                       inode->i_flags |= S_SYNC;
7392 +               else
7393 +                       inode->i_flags &= ~S_SYNC;
7394                 if (sd_attrs & REISERFS_APPEND_FL)
7395                         inode->i_flags |= S_APPEND;
7396                 else
7397 @@ -2881,6 +2897,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
7398                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
7399                 else
7400                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
7401 +
7402 +               if (sd_attrs & REISERFS_BARRIER_FL)
7403 +                       inode->i_vflags |= V_BARRIER;
7404 +               else
7405 +                       inode->i_vflags &= ~V_BARRIER;
7406 +               if (sd_attrs & REISERFS_COW_FL)
7407 +                       inode->i_vflags |= V_COW;
7408 +               else
7409 +                       inode->i_vflags &= ~V_COW;
7410         }
7411  }
7412  
7413 @@ -2891,6 +2916,11 @@ void i_attrs_to_sd_attrs(struct inode *i
7414                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
7415                 else
7416                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
7417 +               if (inode->i_flags & S_IXUNLINK)
7418 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
7419 +               else
7420 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
7421 +
7422                 if (inode->i_flags & S_SYNC)
7423                         *sd_attrs |= REISERFS_SYNC_FL;
7424                 else
7425 @@ -2903,6 +2933,15 @@ void i_attrs_to_sd_attrs(struct inode *i
7426                         *sd_attrs |= REISERFS_NOTAIL_FL;
7427                 else
7428                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
7429 +
7430 +               if (inode->i_vflags & V_BARRIER)
7431 +                       *sd_attrs |= REISERFS_BARRIER_FL;
7432 +               else
7433 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
7434 +               if (inode->i_vflags & V_COW)
7435 +                       *sd_attrs |= REISERFS_COW_FL;
7436 +               else
7437 +                       *sd_attrs &= ~REISERFS_COW_FL;
7438         }
7439  }
7440  
7441 @@ -3146,7 +3185,8 @@ int reiserfs_setattr(struct dentry *dent
7442         }
7443  
7444         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
7445 -           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
7446 +           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
7447 +           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
7448                 struct reiserfs_transaction_handle th;
7449                 int jbegin_count =
7450                     2 *
7451 @@ -3175,6 +3215,9 @@ int reiserfs_setattr(struct dentry *dent
7452                         inode->i_uid = attr->ia_uid;
7453                 if (attr->ia_valid & ATTR_GID)
7454                         inode->i_gid = attr->ia_gid;
7455 +                               if ((attr->ia_valid & ATTR_TAG) &&
7456 +                                       IS_TAGGED(inode))
7457 +                                       inode->i_tag = attr->ia_tag;
7458                 mark_inode_dirty(inode);
7459                 error = journal_end(&th, inode->i_sb, jbegin_count);
7460                 if (error)
7461 diff -NurpP --minimal linux-2.6.36/fs/reiserfs/ioctl.c linux-2.6.36-vs2.3.0.36.33/fs/reiserfs/ioctl.c
7462 --- linux-2.6.36/fs/reiserfs/ioctl.c    2010-10-21 13:07:51.000000000 +0200
7463 +++ linux-2.6.36-vs2.3.0.36.33/fs/reiserfs/ioctl.c      2010-10-21 13:09:36.000000000 +0200
7464 @@ -7,11 +7,27 @@
7465  #include <linux/mount.h>
7466  #include <linux/reiserfs_fs.h>
7467  #include <linux/time.h>
7468 +#include <linux/mount.h>
7469  #include <asm/uaccess.h>
7470  #include <linux/pagemap.h>
7471  #include <linux/smp_lock.h>
7472  #include <linux/compat.h>
7473  
7474 +
7475 +int reiserfs_sync_flags(struct inode *inode, int flags, int vflags)
7476 +{
7477 +       __u16 sd_attrs = 0;
7478 +
7479 +       inode->i_flags = flags;
7480 +       inode->i_vflags = vflags;
7481 +
7482 +       i_attrs_to_sd_attrs(inode, &sd_attrs);
7483 +       REISERFS_I(inode)->i_attrs = sd_attrs;
7484 +       inode->i_ctime = CURRENT_TIME_SEC;
7485 +       mark_inode_dirty(inode);
7486 +       return 0;
7487 +}
7488 +
7489  /*
7490   * reiserfs_ioctl - handler for ioctl for inode
7491   * supported commands:
7492 @@ -23,7 +39,7 @@
7493  long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
7494  {
7495         struct inode *inode = filp->f_path.dentry->d_inode;
7496 -       unsigned int flags;
7497 +       unsigned int flags, oldflags;
7498         int err = 0;
7499  
7500         reiserfs_write_lock(inode->i_sb);
7501 @@ -48,6 +64,7 @@ long reiserfs_ioctl(struct file *filp, u
7502  
7503                 flags = REISERFS_I(inode)->i_attrs;
7504                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
7505 +               flags &= REISERFS_FL_USER_VISIBLE;
7506                 err = put_user(flags, (int __user *)arg);
7507                 break;
7508         case REISERFS_IOC_SETFLAGS:{
7509 @@ -68,6 +85,10 @@ long reiserfs_ioctl(struct file *filp, u
7510                                 err = -EFAULT;
7511                                 goto setflags_out;
7512                         }
7513 +                       if (IS_BARRIER(inode)) {
7514 +                               vxwprintk_task(1, "messing with the barrier.");
7515 +                               return -EACCES;
7516 +                       }
7517                         /*
7518                          * Is it quota file? Do not allow user to mess with it
7519                          */
7520 @@ -92,6 +113,10 @@ long reiserfs_ioctl(struct file *filp, u
7521                                         goto setflags_out;
7522                                 }
7523                         }
7524 +
7525 +                       oldflags = REISERFS_I(inode)->i_attrs;
7526 +                       flags &= REISERFS_FL_USER_MODIFIABLE;
7527 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
7528                         sd_attrs_to_i_attrs(flags, inode);
7529                         REISERFS_I(inode)->i_attrs = flags;
7530                         inode->i_ctime = CURRENT_TIME_SEC;
7531 diff -NurpP --minimal linux-2.6.36/fs/reiserfs/namei.c linux-2.6.36-vs2.3.0.36.33/fs/reiserfs/namei.c
7532 --- linux-2.6.36/fs/reiserfs/namei.c    2010-08-02 16:52:52.000000000 +0200
7533 +++ linux-2.6.36-vs2.3.0.36.33/fs/reiserfs/namei.c      2010-10-21 13:09:36.000000000 +0200
7534 @@ -18,6 +18,7 @@
7535  #include <linux/reiserfs_acl.h>
7536  #include <linux/reiserfs_xattr.h>
7537  #include <linux/quotaops.h>
7538 +#include <linux/vs_tag.h>
7539  
7540  #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; }
7541  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
7542 @@ -362,6 +363,7 @@ static struct dentry *reiserfs_lookup(st
7543         if (retval == IO_ERROR) {
7544                 return ERR_PTR(-EIO);
7545         }
7546 +               dx_propagate_tag(nd, inode);
7547  
7548         return d_splice_alias(inode, dentry);
7549  }
7550 @@ -1532,6 +1534,7 @@ const struct inode_operations reiserfs_d
7551         .listxattr = reiserfs_listxattr,
7552         .removexattr = reiserfs_removexattr,
7553         .permission = reiserfs_permission,
7554 +       .sync_flags = reiserfs_sync_flags,
7555  };
7556  
7557  /*
7558 diff -NurpP --minimal linux-2.6.36/fs/reiserfs/super.c linux-2.6.36-vs2.3.0.36.33/fs/reiserfs/super.c
7559 --- linux-2.6.36/fs/reiserfs/super.c    2010-10-21 13:07:51.000000000 +0200
7560 +++ linux-2.6.36-vs2.3.0.36.33/fs/reiserfs/super.c      2010-10-21 13:09:36.000000000 +0200
7561 @@ -893,6 +893,14 @@ static int reiserfs_parse_options(struct
7562                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
7563                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
7564  #endif
7565 +#ifndef CONFIG_TAGGING_NONE
7566 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
7567 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
7568 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
7569 +#endif
7570 +#ifdef CONFIG_PROPAGATE
7571 +               {"tag",.arg_required = 'T',.values = NULL},
7572 +#endif
7573  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
7574                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
7575                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
7576 @@ -1202,6 +1210,14 @@ static int reiserfs_remount(struct super
7577         handle_quota_files(s, qf_names, &qfmt);
7578  #endif
7579  
7580 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
7581 +               !(s->s_flags & MS_TAGGED)) {
7582 +               reiserfs_warning(s, "super-vs01",
7583 +                       "reiserfs: tagging not permitted on remount.");
7584 +               err = -EINVAL;
7585 +               goto out_err;
7586 +       }
7587 +
7588         handle_attrs(s);
7589  
7590         /* Add options that are safe here */
7591 @@ -1684,6 +1700,10 @@ static int reiserfs_fill_super(struct su
7592                 goto error;
7593         }
7594  
7595 +       /* map mount option tagxid */
7596 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
7597 +               s->s_flags |= MS_TAGGED;
7598 +
7599         rs = SB_DISK_SUPER_BLOCK(s);
7600         /* Let's do basic sanity check to verify that underlying device is not
7601            smaller than the filesystem. If the check fails then abort and scream,
7602 diff -NurpP --minimal linux-2.6.36/fs/reiserfs/xattr.c linux-2.6.36-vs2.3.0.36.33/fs/reiserfs/xattr.c
7603 --- linux-2.6.36/fs/reiserfs/xattr.c    2010-08-02 16:52:52.000000000 +0200
7604 +++ linux-2.6.36-vs2.3.0.36.33/fs/reiserfs/xattr.c      2010-10-21 13:09:36.000000000 +0200
7605 @@ -40,6 +40,7 @@
7606  #include <linux/errno.h>
7607  #include <linux/gfp.h>
7608  #include <linux/fs.h>
7609 +#include <linux/mount.h>
7610  #include <linux/file.h>
7611  #include <linux/pagemap.h>
7612  #include <linux/xattr.h>
7613 diff -NurpP --minimal linux-2.6.36/fs/stat.c linux-2.6.36-vs2.3.0.36.33/fs/stat.c
7614 --- linux-2.6.36/fs/stat.c      2010-10-21 13:07:51.000000000 +0200
7615 +++ linux-2.6.36-vs2.3.0.36.33/fs/stat.c        2010-10-21 13:09:36.000000000 +0200
7616 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
7617         stat->nlink = inode->i_nlink;
7618         stat->uid = inode->i_uid;
7619         stat->gid = inode->i_gid;
7620 +       stat->tag = inode->i_tag;
7621         stat->rdev = inode->i_rdev;
7622         stat->atime = inode->i_atime;
7623         stat->mtime = inode->i_mtime;
7624 diff -NurpP --minimal linux-2.6.36/fs/statfs.c linux-2.6.36-vs2.3.0.36.33/fs/statfs.c
7625 --- linux-2.6.36/fs/statfs.c    2010-10-21 13:07:51.000000000 +0200
7626 +++ linux-2.6.36-vs2.3.0.36.33/fs/statfs.c      2010-10-21 14:07:35.000000000 +0200
7627 @@ -7,6 +7,8 @@
7628  #include <linux/statfs.h>
7629  #include <linux/security.h>
7630  #include <linux/uaccess.h>
7631 +#include <linux/vs_base.h>
7632 +#include <linux/vs_dlimit.h>
7633  
7634  static int flags_by_mnt(int mnt_flags)
7635  {
7636 @@ -59,6 +61,8 @@ int statfs_by_dentry(struct dentry *dent
7637         retval = dentry->d_sb->s_op->statfs(dentry, buf);
7638         if (retval == 0 && buf->f_frsize == 0)
7639                 buf->f_frsize = buf->f_bsize;
7640 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
7641 +               vx_vsi_statfs(dentry->d_sb, buf);
7642         return retval;
7643  }
7644  
7645 diff -NurpP --minimal linux-2.6.36/fs/super.c linux-2.6.36-vs2.3.0.36.33/fs/super.c
7646 --- linux-2.6.36/fs/super.c     2010-10-21 13:07:51.000000000 +0200
7647 +++ linux-2.6.36-vs2.3.0.36.33/fs/super.c       2010-10-21 13:09:36.000000000 +0200
7648 @@ -30,6 +30,9 @@
7649  #include <linux/idr.h>
7650  #include <linux/mutex.h>
7651  #include <linux/backing-dev.h>
7652 +#include <linux/devpts_fs.h>
7653 +#include <linux/proc_fs.h>
7654 +#include <linux/vs_context.h>
7655  #include "internal.h"
7656  
7657  
7658 @@ -918,12 +921,18 @@ struct vfsmount *
7659  vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
7660  {
7661         struct vfsmount *mnt;
7662 +       struct super_block *sb;
7663         char *secdata = NULL;
7664         int error;
7665  
7666         if (!type)
7667                 return ERR_PTR(-ENODEV);
7668  
7669 +       error = -EPERM;
7670 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
7671 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
7672 +               goto out;
7673 +
7674         error = -ENOMEM;
7675         mnt = alloc_vfsmnt(name);
7676         if (!mnt)
7677 @@ -945,11 +954,19 @@ vfs_kern_mount(struct file_system_type *
7678         error = type->get_sb(type, flags, name, data, mnt);
7679         if (error < 0)
7680                 goto out_free_secdata;
7681 -       BUG_ON(!mnt->mnt_sb);
7682 -       WARN_ON(!mnt->mnt_sb->s_bdi);
7683 +
7684 +       sb = mnt->mnt_sb;
7685 +       BUG_ON(!sb);
7686 +       WARN_ON(!sb->s_bdi);
7687         mnt->mnt_sb->s_flags |= MS_BORN;
7688  
7689 -       error = security_sb_kern_mount(mnt->mnt_sb, flags, secdata);
7690 +       error = -EPERM;
7691 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) && !sb->s_bdev &&
7692 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
7693 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
7694 +               goto out_sb;
7695 +
7696 +       error = security_sb_kern_mount(sb, flags, secdata);
7697         if (error)
7698                 goto out_sb;
7699  
7700 diff -NurpP --minimal linux-2.6.36/fs/sysfs/mount.c linux-2.6.36-vs2.3.0.36.33/fs/sysfs/mount.c
7701 --- linux-2.6.36/fs/sysfs/mount.c       2010-10-21 13:07:51.000000000 +0200
7702 +++ linux-2.6.36-vs2.3.0.36.33/fs/sysfs/mount.c 2010-10-21 13:09:36.000000000 +0200
7703 @@ -47,7 +47,7 @@ static int sysfs_fill_super(struct super
7704  
7705         sb->s_blocksize = PAGE_CACHE_SIZE;
7706         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
7707 -       sb->s_magic = SYSFS_MAGIC;
7708 +       sb->s_magic = SYSFS_SUPER_MAGIC;
7709         sb->s_op = &sysfs_ops;
7710         sb->s_time_gran = 1;
7711  
7712 diff -NurpP --minimal linux-2.6.36/fs/utimes.c linux-2.6.36-vs2.3.0.36.33/fs/utimes.c
7713 --- linux-2.6.36/fs/utimes.c    2010-10-21 13:07:51.000000000 +0200
7714 +++ linux-2.6.36-vs2.3.0.36.33/fs/utimes.c      2010-10-21 13:09:36.000000000 +0200
7715 @@ -8,6 +8,8 @@
7716  #include <linux/stat.h>
7717  #include <linux/utime.h>
7718  #include <linux/syscalls.h>
7719 +#include <linux/mount.h>
7720 +#include <linux/vs_cowbl.h>
7721  #include <asm/uaccess.h>
7722  #include <asm/unistd.h>
7723  
7724 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
7725  {
7726         int error;
7727         struct iattr newattrs;
7728 -       struct inode *inode = path->dentry->d_inode;
7729 +       struct inode *inode;
7730  
7731         error = mnt_want_write(path->mnt);
7732         if (error)
7733                 goto out;
7734  
7735 +       error = cow_check_and_break(path);
7736 +       if (error)
7737 +               goto mnt_drop_write_and_out;
7738 +
7739 +       inode = path->dentry->d_inode;
7740 +
7741         if (times && times[0].tv_nsec == UTIME_NOW &&
7742                      times[1].tv_nsec == UTIME_NOW)
7743                 times = NULL;
7744 diff -NurpP --minimal linux-2.6.36/fs/xattr.c linux-2.6.36-vs2.3.0.36.33/fs/xattr.c
7745 --- linux-2.6.36/fs/xattr.c     2010-08-02 16:52:52.000000000 +0200
7746 +++ linux-2.6.36-vs2.3.0.36.33/fs/xattr.c       2010-10-21 13:09:36.000000000 +0200
7747 @@ -18,6 +18,7 @@
7748  #include <linux/module.h>
7749  #include <linux/fsnotify.h>
7750  #include <linux/audit.h>
7751 +#include <linux/mount.h>
7752  #include <asm/uaccess.h>
7753  
7754  
7755 @@ -49,7 +50,7 @@ xattr_permission(struct inode *inode, co
7756          * The trusted.* namespace can only be accessed by a privileged user.
7757          */
7758         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN))
7759 -               return (capable(CAP_SYS_ADMIN) ? 0 : -EPERM);
7760 +               return (vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED) ? 0 : -EPERM);
7761  
7762         /* In user.* namespace, only regular files and directories can have
7763          * extended attributes. For sticky directories, only the owner and
7764 diff -NurpP --minimal linux-2.6.36/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.36-vs2.3.0.36.33/fs/xfs/linux-2.6/xfs_ioctl.c
7765 --- linux-2.6.36/fs/xfs/linux-2.6/xfs_ioctl.c   2010-10-21 13:07:51.000000000 +0200
7766 +++ linux-2.6.36-vs2.3.0.36.33/fs/xfs/linux-2.6/xfs_ioctl.c     2010-10-21 14:02:37.000000000 +0200
7767 @@ -28,7 +28,7 @@
7768  #include "xfs_bmap_btree.h"
7769  #include "xfs_dinode.h"
7770  #include "xfs_inode.h"
7771 -#include "xfs_ioctl.h"
7772 +// #include "xfs_ioctl.h"
7773  #include "xfs_rtalloc.h"
7774  #include "xfs_itable.h"
7775  #include "xfs_error.h"
7776 @@ -738,6 +738,10 @@ xfs_merge_ioc_xflags(
7777                 xflags |= XFS_XFLAG_IMMUTABLE;
7778         else
7779                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7780 +       if (flags & FS_IXUNLINK_FL)
7781 +               xflags |= XFS_XFLAG_IXUNLINK;
7782 +       else
7783 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7784         if (flags & FS_APPEND_FL)
7785                 xflags |= XFS_XFLAG_APPEND;
7786         else
7787 @@ -766,6 +770,8 @@ xfs_di2lxflags(
7788  
7789         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7790                 flags |= FS_IMMUTABLE_FL;
7791 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7792 +               flags |= FS_IXUNLINK_FL;
7793         if (di_flags & XFS_DIFLAG_APPEND)
7794                 flags |= FS_APPEND_FL;
7795         if (di_flags & XFS_DIFLAG_SYNC)
7796 @@ -826,6 +832,8 @@ xfs_set_diflags(
7797         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7798         if (xflags & XFS_XFLAG_IMMUTABLE)
7799                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7800 +       if (xflags & XFS_XFLAG_IXUNLINK)
7801 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7802         if (xflags & XFS_XFLAG_APPEND)
7803                 di_flags |= XFS_DIFLAG_APPEND;
7804         if (xflags & XFS_XFLAG_SYNC)
7805 @@ -868,6 +876,10 @@ xfs_diflags_to_linux(
7806                 inode->i_flags |= S_IMMUTABLE;
7807         else
7808                 inode->i_flags &= ~S_IMMUTABLE;
7809 +       if (xflags & XFS_XFLAG_IXUNLINK)
7810 +               inode->i_flags |= S_IXUNLINK;
7811 +       else
7812 +               inode->i_flags &= ~S_IXUNLINK;
7813         if (xflags & XFS_XFLAG_APPEND)
7814                 inode->i_flags |= S_APPEND;
7815         else
7816 @@ -1341,10 +1353,18 @@ xfs_file_ioctl(
7817         case XFS_IOC_FSGETXATTRA:
7818                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7819         case XFS_IOC_FSSETXATTR:
7820 +               if (IS_BARRIER(inode)) {
7821 +                       vxwprintk_task(1, "messing with the barrier.");
7822 +                       return -XFS_ERROR(EACCES);
7823 +               }
7824                 return xfs_ioc_fssetxattr(ip, filp, arg);
7825         case XFS_IOC_GETXFLAGS:
7826                 return xfs_ioc_getxflags(ip, arg);
7827         case XFS_IOC_SETXFLAGS:
7828 +               if (IS_BARRIER(inode)) {
7829 +                       vxwprintk_task(1, "messing with the barrier.");
7830 +                       return -XFS_ERROR(EACCES);
7831 +               }
7832                 return xfs_ioc_setxflags(ip, filp, arg);
7833  
7834         case XFS_IOC_FSSETDM: {
7835 diff -NurpP --minimal linux-2.6.36/fs/xfs/linux-2.6/xfs_ioctl.h linux-2.6.36-vs2.3.0.36.33/fs/xfs/linux-2.6/xfs_ioctl.h
7836 --- linux-2.6.36/fs/xfs/linux-2.6/xfs_ioctl.h   2010-07-07 18:31:54.000000000 +0200
7837 +++ linux-2.6.36-vs2.3.0.36.33/fs/xfs/linux-2.6/xfs_ioctl.h     2010-10-21 13:09:36.000000000 +0200
7838 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7839         void __user             *uhandle,
7840         u32                     hlen);
7841  
7842 +extern int
7843 +xfs_sync_flags(
7844 +       struct inode            *inode,
7845 +       int                     flags,
7846 +       int                     vflags);
7847 +
7848  extern long
7849  xfs_file_ioctl(
7850         struct file             *filp,
7851 diff -NurpP --minimal linux-2.6.36/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.36-vs2.3.0.36.33/fs/xfs/linux-2.6/xfs_iops.c
7852 --- linux-2.6.36/fs/xfs/linux-2.6/xfs_iops.c    2010-10-21 13:07:51.000000000 +0200
7853 +++ linux-2.6.36-vs2.3.0.36.33/fs/xfs/linux-2.6/xfs_iops.c      2010-10-21 13:09:36.000000000 +0200
7854 @@ -30,6 +30,7 @@
7855  #include "xfs_bmap_btree.h"
7856  #include "xfs_dinode.h"
7857  #include "xfs_inode.h"
7858 +#include "xfs_ioctl.h"
7859  #include "xfs_bmap.h"
7860  #include "xfs_rtalloc.h"
7861  #include "xfs_error.h"
7862 @@ -49,6 +50,7 @@
7863  #include <linux/falloc.h>
7864  #include <linux/fiemap.h>
7865  #include <linux/slab.h>
7866 +#include <linux/vs_tag.h>
7867  
7868  /*
7869   * Bring the timestamps in the XFS inode uptodate.
7870 @@ -499,6 +501,7 @@ xfs_vn_getattr(
7871         stat->nlink = ip->i_d.di_nlink;
7872         stat->uid = ip->i_d.di_uid;
7873         stat->gid = ip->i_d.di_gid;
7874 +       stat->tag = ip->i_d.di_tag;
7875         stat->ino = ip->i_ino;
7876         stat->atime = inode->i_atime;
7877         stat->mtime = inode->i_mtime;
7878 @@ -687,6 +690,7 @@ static const struct inode_operations xfs
7879         .listxattr              = xfs_vn_listxattr,
7880         .fallocate              = xfs_vn_fallocate,
7881         .fiemap                 = xfs_vn_fiemap,
7882 +       .sync_flags             = xfs_sync_flags,
7883  };
7884  
7885  static const struct inode_operations xfs_dir_inode_operations = {
7886 @@ -712,6 +716,7 @@ static const struct inode_operations xfs
7887         .getxattr               = generic_getxattr,
7888         .removexattr            = generic_removexattr,
7889         .listxattr              = xfs_vn_listxattr,
7890 +       .sync_flags             = xfs_sync_flags,
7891  };
7892  
7893  static const struct inode_operations xfs_dir_ci_inode_operations = {
7894 @@ -761,6 +766,10 @@ xfs_diflags_to_iflags(
7895                 inode->i_flags |= S_IMMUTABLE;
7896         else
7897                 inode->i_flags &= ~S_IMMUTABLE;
7898 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7899 +               inode->i_flags |= S_IXUNLINK;
7900 +       else
7901 +               inode->i_flags &= ~S_IXUNLINK;
7902         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7903                 inode->i_flags |= S_APPEND;
7904         else
7905 @@ -773,6 +782,15 @@ xfs_diflags_to_iflags(
7906                 inode->i_flags |= S_NOATIME;
7907         else
7908                 inode->i_flags &= ~S_NOATIME;
7909 +
7910 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7911 +               inode->i_vflags |= V_BARRIER;
7912 +       else
7913 +               inode->i_vflags &= ~V_BARRIER;
7914 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7915 +               inode->i_vflags |= V_COW;
7916 +       else
7917 +               inode->i_vflags &= ~V_COW;
7918  }
7919  
7920  /*
7921 @@ -801,6 +819,7 @@ xfs_setup_inode(
7922         inode->i_nlink  = ip->i_d.di_nlink;
7923         inode->i_uid    = ip->i_d.di_uid;
7924         inode->i_gid    = ip->i_d.di_gid;
7925 +       inode->i_tag    = ip->i_d.di_tag;
7926  
7927         switch (inode->i_mode & S_IFMT) {
7928         case S_IFBLK:
7929 diff -NurpP --minimal linux-2.6.36/fs/xfs/linux-2.6/xfs_linux.h linux-2.6.36-vs2.3.0.36.33/fs/xfs/linux-2.6/xfs_linux.h
7930 --- linux-2.6.36/fs/xfs/linux-2.6/xfs_linux.h   2010-10-21 13:07:51.000000000 +0200
7931 +++ linux-2.6.36-vs2.3.0.36.33/fs/xfs/linux-2.6/xfs_linux.h     2010-10-21 13:09:36.000000000 +0200
7932 @@ -116,6 +116,7 @@
7933  
7934  #define current_cpu()          (raw_smp_processor_id())
7935  #define current_pid()          (current->pid)
7936 +#define current_fstag(cred,vp) (dx_current_fstag((vp)->i_sb))
7937  #define current_test_flags(f)  (current->flags & (f))
7938  #define current_set_flags_nested(sp, f)                \
7939                 (*(sp) = current->flags, current->flags |= (f))
7940 diff -NurpP --minimal linux-2.6.36/fs/xfs/linux-2.6/xfs_super.c linux-2.6.36-vs2.3.0.36.33/fs/xfs/linux-2.6/xfs_super.c
7941 --- linux-2.6.36/fs/xfs/linux-2.6/xfs_super.c   2010-10-21 13:07:51.000000000 +0200
7942 +++ linux-2.6.36-vs2.3.0.36.33/fs/xfs/linux-2.6/xfs_super.c     2010-10-21 13:09:36.000000000 +0200
7943 @@ -113,6 +113,9 @@ mempool_t *xfs_ioend_pool;
7944  #define MNTOPT_QUOTANOENF  "qnoenforce"        /* same as uqnoenforce */
7945  #define MNTOPT_DELAYLOG   "delaylog"   /* Delayed loging enabled */
7946  #define MNTOPT_NODELAYLOG "nodelaylog" /* Delayed loging disabled */
7947 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
7948 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
7949 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
7950  
7951  /*
7952   * Table driven mount option parser.
7953 @@ -121,10 +124,14 @@ mempool_t *xfs_ioend_pool;
7954   * in the future, too.
7955   */
7956  enum {
7957 +       Opt_tag, Opt_notag,
7958         Opt_barrier, Opt_nobarrier, Opt_err
7959  };
7960  
7961  static const match_table_t tokens = {
7962 +       {Opt_tag, "tagxid"},
7963 +       {Opt_tag, "tag"},
7964 +       {Opt_notag, "notag"},
7965         {Opt_barrier, "barrier"},
7966         {Opt_nobarrier, "nobarrier"},
7967         {Opt_err, NULL}
7968 @@ -371,6 +378,19 @@ xfs_parseargs(
7969                 } else if (!strcmp(this_char, "irixsgid")) {
7970                         cmn_err(CE_WARN,
7971         "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
7972 +#ifndef CONFIG_TAGGING_NONE
7973 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7974 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7975 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7976 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
7977 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7978 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7979 +#endif
7980 +#ifdef CONFIG_PROPAGATE
7981 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7982 +                       /* use value */
7983 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7984 +#endif
7985                 } else {
7986                         cmn_err(CE_WARN,
7987                                 "XFS: unknown mount option [%s].", this_char);
7988 @@ -1320,6 +1340,16 @@ xfs_fs_remount(
7989                 case Opt_nobarrier:
7990                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
7991                         break;
7992 +               case Opt_tag:
7993 +                       if (!(sb->s_flags & MS_TAGGED)) {
7994 +                               printk(KERN_INFO
7995 +                                       "XFS: %s: tagging not permitted on remount.\n",
7996 +                                       sb->s_id);
7997 +                               return -EINVAL;
7998 +                       }
7999 +                       break;
8000 +               case Opt_notag:
8001 +                       break;
8002                 default:
8003                         /*
8004                          * Logically we would return an error here to prevent
8005 @@ -1547,6 +1577,9 @@ xfs_fs_fill_super(
8006         if (error)
8007                 goto out_filestream_unmount;
8008  
8009 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
8010 +               sb->s_flags |= MS_TAGGED;
8011 +
8012         sb->s_magic = XFS_SB_MAGIC;
8013         sb->s_blocksize = mp->m_sb.sb_blocksize;
8014         sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
8015 diff -NurpP --minimal linux-2.6.36/fs/xfs/xfs_dinode.h linux-2.6.36-vs2.3.0.36.33/fs/xfs/xfs_dinode.h
8016 --- linux-2.6.36/fs/xfs/xfs_dinode.h    2009-06-11 17:13:09.000000000 +0200
8017 +++ linux-2.6.36-vs2.3.0.36.33/fs/xfs/xfs_dinode.h      2010-10-21 13:09:36.000000000 +0200
8018 @@ -50,7 +50,9 @@ typedef struct xfs_dinode {
8019         __be32          di_gid;         /* owner's group id */
8020         __be32          di_nlink;       /* number of links to file */
8021         __be16          di_projid;      /* owner's project id */
8022 -       __u8            di_pad[8];      /* unused, zeroed space */
8023 +       __be16          di_tag;         /* context tagging */
8024 +       __be16          di_vflags;      /* vserver specific flags */
8025 +       __u8            di_pad[4];      /* unused, zeroed space */
8026         __be16          di_flushiter;   /* incremented on flush */
8027         xfs_timestamp_t di_atime;       /* time last accessed */
8028         xfs_timestamp_t di_mtime;       /* time last modified */
8029 @@ -183,6 +185,8 @@ static inline void xfs_dinode_put_rdev(s
8030  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
8031  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
8032  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
8033 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
8034 +
8035  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
8036  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
8037  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
8038 @@ -198,6 +202,7 @@ static inline void xfs_dinode_put_rdev(s
8039  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
8040  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
8041  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
8042 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
8043  
8044  #ifdef CONFIG_XFS_RT
8045  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
8046 @@ -210,6 +215,10 @@ static inline void xfs_dinode_put_rdev(s
8047          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
8048          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
8049          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
8050 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
8051 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
8052 +        XFS_DIFLAG_IXUNLINK)
8053 +
8054 +#define XFS_DIVFLAG_BARRIER    0x01
8055 +#define XFS_DIVFLAG_COW                0x02
8056  
8057  #endif /* __XFS_DINODE_H__ */
8058 diff -NurpP --minimal linux-2.6.36/fs/xfs/xfs_fs.h linux-2.6.36-vs2.3.0.36.33/fs/xfs/xfs_fs.h
8059 --- linux-2.6.36/fs/xfs/xfs_fs.h        2010-10-21 13:07:52.000000000 +0200
8060 +++ linux-2.6.36-vs2.3.0.36.33/fs/xfs/xfs_fs.h  2010-10-21 13:09:36.000000000 +0200
8061 @@ -67,6 +67,9 @@ struct fsxattr {
8062  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
8063  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
8064  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
8065 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
8066 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
8067 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
8068  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
8069  
8070  /*
8071 @@ -295,7 +298,8 @@ typedef struct xfs_bstat {
8072         __u32           bs_gen;         /* generation count             */
8073         __u16           bs_projid;      /* project id                   */
8074         __u16           bs_forkoff;     /* inode fork offset in bytes   */
8075 -       unsigned char   bs_pad[12];     /* pad space, unused            */
8076 +       __u16           bs_tag;         /* context tagging              */
8077 +       unsigned char   bs_pad[10];     /* pad space, unused            */
8078         __u32           bs_dmevmask;    /* DMIG event mask              */
8079         __u16           bs_dmstate;     /* DMIG state info              */
8080         __u16           bs_aextents;    /* attribute number of extents  */
8081 diff -NurpP --minimal linux-2.6.36/fs/xfs/xfs_ialloc.c linux-2.6.36-vs2.3.0.36.33/fs/xfs/xfs_ialloc.c
8082 --- linux-2.6.36/fs/xfs/xfs_ialloc.c    2010-10-21 13:07:52.000000000 +0200
8083 +++ linux-2.6.36-vs2.3.0.36.33/fs/xfs/xfs_ialloc.c      2010-10-21 13:09:36.000000000 +0200
8084 @@ -37,7 +37,6 @@
8085  #include "xfs_error.h"
8086  #include "xfs_bmap.h"
8087  
8088 -
8089  /*
8090   * Allocation group level functions.
8091   */
8092 diff -NurpP --minimal linux-2.6.36/fs/xfs/xfs_inode.c linux-2.6.36-vs2.3.0.36.33/fs/xfs/xfs_inode.c
8093 --- linux-2.6.36/fs/xfs/xfs_inode.c     2010-10-21 13:07:52.000000000 +0200
8094 +++ linux-2.6.36-vs2.3.0.36.33/fs/xfs/xfs_inode.c       2010-10-21 13:09:36.000000000 +0200
8095 @@ -245,6 +245,7 @@ xfs_inotobp(
8096         return 0;
8097  }
8098  
8099 +#include <linux/vs_tag.h>
8100  
8101  /*
8102   * This routine is called to map an inode to the buffer containing
8103 @@ -650,15 +651,25 @@ xfs_iformat_btree(
8104  STATIC void
8105  xfs_dinode_from_disk(
8106         xfs_icdinode_t          *to,
8107 -       xfs_dinode_t            *from)
8108 +       xfs_dinode_t            *from,
8109 +       int tagged)
8110  {
8111 +       uint32_t uid, gid, tag;
8112 +
8113         to->di_magic = be16_to_cpu(from->di_magic);
8114         to->di_mode = be16_to_cpu(from->di_mode);
8115         to->di_version = from ->di_version;
8116         to->di_format = from->di_format;
8117         to->di_onlink = be16_to_cpu(from->di_onlink);
8118 -       to->di_uid = be32_to_cpu(from->di_uid);
8119 -       to->di_gid = be32_to_cpu(from->di_gid);
8120 +
8121 +       uid = be32_to_cpu(from->di_uid);
8122 +       gid = be32_to_cpu(from->di_gid);
8123 +       tag = be16_to_cpu(from->di_tag);
8124 +
8125 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
8126 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
8127 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
8128 +
8129         to->di_nlink = be32_to_cpu(from->di_nlink);
8130         to->di_projid = be16_to_cpu(from->di_projid);
8131         memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
8132 @@ -679,21 +690,26 @@ xfs_dinode_from_disk(
8133         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
8134         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
8135         to->di_flags    = be16_to_cpu(from->di_flags);
8136 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
8137         to->di_gen      = be32_to_cpu(from->di_gen);
8138  }
8139  
8140  void
8141  xfs_dinode_to_disk(
8142         xfs_dinode_t            *to,
8143 -       xfs_icdinode_t          *from)
8144 +       xfs_icdinode_t          *from,
8145 +       int tagged)
8146  {
8147         to->di_magic = cpu_to_be16(from->di_magic);
8148         to->di_mode = cpu_to_be16(from->di_mode);
8149         to->di_version = from ->di_version;
8150         to->di_format = from->di_format;
8151         to->di_onlink = cpu_to_be16(from->di_onlink);
8152 -       to->di_uid = cpu_to_be32(from->di_uid);
8153 -       to->di_gid = cpu_to_be32(from->di_gid);
8154 +
8155 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
8156 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
8157 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
8158 +
8159         to->di_nlink = cpu_to_be32(from->di_nlink);
8160         to->di_projid = cpu_to_be16(from->di_projid);
8161         memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
8162 @@ -714,12 +730,14 @@ xfs_dinode_to_disk(
8163         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
8164         to->di_dmstate = cpu_to_be16(from->di_dmstate);
8165         to->di_flags = cpu_to_be16(from->di_flags);
8166 +       to->di_vflags = cpu_to_be16(from->di_vflags);
8167         to->di_gen = cpu_to_be32(from->di_gen);
8168  }
8169  
8170  STATIC uint
8171  _xfs_dic2xflags(
8172 -       __uint16_t              di_flags)
8173 +       __uint16_t              di_flags,
8174 +       __uint16_t              di_vflags)
8175  {
8176         uint                    flags = 0;
8177  
8178 @@ -730,6 +748,8 @@ _xfs_dic2xflags(
8179                         flags |= XFS_XFLAG_PREALLOC;
8180                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
8181                         flags |= XFS_XFLAG_IMMUTABLE;
8182 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
8183 +                       flags |= XFS_XFLAG_IXUNLINK;
8184                 if (di_flags & XFS_DIFLAG_APPEND)
8185                         flags |= XFS_XFLAG_APPEND;
8186                 if (di_flags & XFS_DIFLAG_SYNC)
8187 @@ -754,6 +774,10 @@ _xfs_dic2xflags(
8188                         flags |= XFS_XFLAG_FILESTREAM;
8189         }
8190  
8191 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
8192 +               flags |= FS_BARRIER_FL;
8193 +       if (di_vflags & XFS_DIVFLAG_COW)
8194 +               flags |= FS_COW_FL;
8195         return flags;
8196  }
8197  
8198 @@ -763,7 +787,7 @@ xfs_ip2xflags(
8199  {
8200         xfs_icdinode_t          *dic = &ip->i_d;
8201  
8202 -       return _xfs_dic2xflags(dic->di_flags) |
8203 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
8204                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
8205  }
8206  
8207 @@ -771,7 +795,8 @@ uint
8208  xfs_dic2xflags(
8209         xfs_dinode_t            *dip)
8210  {
8211 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
8212 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
8213 +                               be16_to_cpu(dip->di_vflags)) |
8214                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
8215  }
8216  
8217 @@ -804,7 +829,6 @@ xfs_iread(
8218         if (error)
8219                 return error;
8220         dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);
8221 -
8222         /*
8223          * If we got something that isn't an inode it means someone
8224          * (nfs or dmi) has a stale handle.
8225 @@ -829,7 +853,8 @@ xfs_iread(
8226          * Otherwise, just get the truly permanent information.
8227          */
8228         if (dip->di_mode) {
8229 -               xfs_dinode_from_disk(&ip->i_d, dip);
8230 +               xfs_dinode_from_disk(&ip->i_d, dip,
8231 +                       mp->m_flags & XFS_MOUNT_TAGGED);
8232                 error = xfs_iformat(ip, dip);
8233                 if (error)  {
8234  #ifdef DEBUG
8235 @@ -1027,6 +1052,7 @@ xfs_ialloc(
8236         ASSERT(ip->i_d.di_nlink == nlink);
8237         ip->i_d.di_uid = current_fsuid();
8238         ip->i_d.di_gid = current_fsgid();
8239 +       ip->i_d.di_tag = current_fstag(cr, &ip->i_vnode);
8240         ip->i_d.di_projid = prid;
8241         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
8242  
8243 @@ -1087,6 +1113,7 @@ xfs_ialloc(
8244         ip->i_d.di_dmevmask = 0;
8245         ip->i_d.di_dmstate = 0;
8246         ip->i_d.di_flags = 0;
8247 +       ip->i_d.di_vflags = 0;
8248         flags = XFS_ILOG_CORE;
8249         switch (mode & S_IFMT) {
8250         case S_IFIFO:
8251 @@ -2105,6 +2132,7 @@ xfs_ifree(
8252         }
8253         ip->i_d.di_mode = 0;            /* mark incore inode as free */
8254         ip->i_d.di_flags = 0;
8255 +       ip->i_d.di_vflags = 0;
8256         ip->i_d.di_dmevmask = 0;
8257         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
8258         ip->i_df.if_ext_max =
8259 @@ -2975,7 +3003,8 @@ xfs_iflush_int(
8260          * because if the inode is dirty at all the core must
8261          * be.
8262          */
8263 -       xfs_dinode_to_disk(dip, &ip->i_d);
8264 +       xfs_dinode_to_disk(dip, &ip->i_d,
8265 +               mp->m_flags & XFS_MOUNT_TAGGED);
8266  
8267         /* Wrap, we never let the log put out DI_MAX_FLUSH */
8268         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
8269 diff -NurpP --minimal linux-2.6.36/fs/xfs/xfs_inode.h linux-2.6.36-vs2.3.0.36.33/fs/xfs/xfs_inode.h
8270 --- linux-2.6.36/fs/xfs/xfs_inode.h     2010-10-21 13:07:52.000000000 +0200
8271 +++ linux-2.6.36-vs2.3.0.36.33/fs/xfs/xfs_inode.h       2010-10-21 13:09:36.000000000 +0200
8272 @@ -135,7 +135,9 @@ typedef struct xfs_icdinode {
8273         __uint32_t      di_gid;         /* owner's group id */
8274         __uint32_t      di_nlink;       /* number of links to file */
8275         __uint16_t      di_projid;      /* owner's project id */
8276 -       __uint8_t       di_pad[8];      /* unused, zeroed space */
8277 +       __uint16_t      di_tag;         /* context tagging */
8278 +       __uint16_t      di_vflags;      /* vserver specific flags */
8279 +       __uint8_t       di_pad[4];      /* unused, zeroed space */
8280         __uint16_t      di_flushiter;   /* incremented on flush */
8281         xfs_ictimestamp_t di_atime;     /* time last accessed */
8282         xfs_ictimestamp_t di_mtime;     /* time last modified */
8283 @@ -509,7 +511,7 @@ int         xfs_itobp(struct xfs_mount *, struc
8284  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
8285                           struct xfs_inode *, uint);
8286  void           xfs_dinode_to_disk(struct xfs_dinode *,
8287 -                                  struct xfs_icdinode *);
8288 +                                  struct xfs_icdinode *, int);
8289  void           xfs_idestroy_fork(struct xfs_inode *, int);
8290  void           xfs_idata_realloc(struct xfs_inode *, int, int);
8291  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
8292 diff -NurpP --minimal linux-2.6.36/fs/xfs/xfs_itable.c linux-2.6.36-vs2.3.0.36.33/fs/xfs/xfs_itable.c
8293 --- linux-2.6.36/fs/xfs/xfs_itable.c    2010-10-21 13:07:52.000000000 +0200
8294 +++ linux-2.6.36-vs2.3.0.36.33/fs/xfs/xfs_itable.c      2010-10-21 13:09:36.000000000 +0200
8295 @@ -97,6 +97,7 @@ xfs_bulkstat_one_int(
8296         buf->bs_mode = dic->di_mode;
8297         buf->bs_uid = dic->di_uid;
8298         buf->bs_gid = dic->di_gid;
8299 +       buf->bs_tag = dic->di_tag;
8300         buf->bs_size = dic->di_size;
8301  
8302         /*
8303 diff -NurpP --minimal linux-2.6.36/fs/xfs/xfs_log_recover.c linux-2.6.36-vs2.3.0.36.33/fs/xfs/xfs_log_recover.c
8304 --- linux-2.6.36/fs/xfs/xfs_log_recover.c       2010-10-21 13:07:52.000000000 +0200
8305 +++ linux-2.6.36-vs2.3.0.36.33/fs/xfs/xfs_log_recover.c 2010-10-21 14:02:02.000000000 +0200
8306 @@ -2450,7 +2450,8 @@ xlog_recover_do_inode_trans(
8307         }
8308  
8309         /* The core is in in-core format */
8310 -       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr);
8311 +       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr,
8312 +               mp->m_flags & XFS_MOUNT_TAGGED);
8313  
8314         /* the rest is in on-disk format */
8315         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
8316 diff -NurpP --minimal linux-2.6.36/fs/xfs/xfs_mount.h linux-2.6.36-vs2.3.0.36.33/fs/xfs/xfs_mount.h
8317 --- linux-2.6.36/fs/xfs/xfs_mount.h     2010-10-21 13:07:52.000000000 +0200
8318 +++ linux-2.6.36-vs2.3.0.36.33/fs/xfs/xfs_mount.h       2010-10-21 13:09:36.000000000 +0200
8319 @@ -238,6 +238,7 @@ typedef struct xfs_mount {
8320                                                    allocator */
8321  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
8322  
8323 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
8324  
8325  /*
8326   * Default minimum read and write sizes.
8327 diff -NurpP --minimal linux-2.6.36/fs/xfs/xfs_vnodeops.c linux-2.6.36-vs2.3.0.36.33/fs/xfs/xfs_vnodeops.c
8328 --- linux-2.6.36/fs/xfs/xfs_vnodeops.c  2010-10-21 13:07:52.000000000 +0200
8329 +++ linux-2.6.36-vs2.3.0.36.33/fs/xfs/xfs_vnodeops.c    2010-10-21 15:17:26.000000000 +0200
8330 @@ -50,6 +50,78 @@
8331  #include "xfs_vnodeops.h"
8332  #include "xfs_trace.h"
8333  
8334 +
8335 +STATIC void
8336 +xfs_get_inode_flags(
8337 +       xfs_inode_t     *ip)
8338 +{
8339 +       struct inode    *inode = VFS_I(ip);
8340 +       unsigned int    flags = inode->i_flags;
8341 +       unsigned int    vflags = inode->i_vflags;
8342 +
8343 +       if (flags & S_IMMUTABLE)
8344 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
8345 +       else
8346 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
8347 +       if (flags & S_IXUNLINK)
8348 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
8349 +       else
8350 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
8351 +
8352 +       if (vflags & V_BARRIER)
8353 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
8354 +       else
8355 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
8356 +       if (vflags & V_COW)
8357 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
8358 +       else
8359 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
8360 +}
8361 +
8362 +int
8363 +xfs_sync_flags(
8364 +       struct inode            *inode,
8365 +       int                     flags,
8366 +       int                     vflags)
8367 +{
8368 +       struct xfs_inode        *ip = XFS_I(inode);
8369 +       struct xfs_mount        *mp = ip->i_mount;
8370 +       struct xfs_trans        *tp;
8371 +       unsigned int            lock_flags = 0;
8372 +       int                     code;
8373 +
8374 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
8375 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
8376 +       if (code)
8377 +               goto error_out;
8378 +
8379 +       xfs_ilock(ip, XFS_ILOCK_EXCL);
8380 +
8381 +       xfs_trans_ijoin(tp, ip);
8382 +
8383 +       inode->i_flags = flags;
8384 +       inode->i_vflags = vflags;
8385 +       xfs_get_inode_flags(ip);
8386 +
8387 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
8388 +       xfs_ichgtime(ip, XFS_ICHGTIME_CHG);
8389 +
8390 +       XFS_STATS_INC(xs_ig_attrchg);
8391 +
8392 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
8393 +               xfs_trans_set_sync(tp);
8394 +       code = xfs_trans_commit(tp, 0);
8395 +       xfs_iunlock(ip, XFS_ILOCK_EXCL);
8396 +       return code;
8397 +
8398 +error_out:
8399 +       xfs_trans_cancel(tp, 0);
8400 +       if (lock_flags)
8401 +               xfs_iunlock(ip, XFS_ILOCK_EXCL);
8402 +       return code;
8403 +}
8404 +
8405 +
8406  int
8407  xfs_setattr(
8408         struct xfs_inode        *ip,
8409 @@ -65,6 +137,7 @@ xfs_setattr(
8410         uint                    commit_flags=0;
8411         uid_t                   uid=0, iuid=0;
8412         gid_t                   gid=0, igid=0;
8413 +       tag_t                   tag=0, itag=0;
8414         struct xfs_dquot        *udqp, *gdqp, *olddquot1, *olddquot2;
8415         int                     need_iolock = 1;
8416  
8417 @@ -147,7 +220,7 @@ xfs_setattr(
8418         /*
8419          * Change file ownership.  Must be the owner or privileged.
8420          */
8421 -       if (mask & (ATTR_UID|ATTR_GID)) {
8422 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8423                 /*
8424                  * These IDs could have changed since we last looked at them.
8425                  * But, we're assured that if the ownership did change
8426 @@ -156,8 +229,10 @@ xfs_setattr(
8427                  */
8428                 iuid = ip->i_d.di_uid;
8429                 igid = ip->i_d.di_gid;
8430 +               itag = ip->i_d.di_tag;
8431                 gid = (mask & ATTR_GID) ? iattr->ia_gid : igid;
8432                 uid = (mask & ATTR_UID) ? iattr->ia_uid : iuid;
8433 +               tag = (mask & ATTR_TAG) ? iattr->ia_tag : itag;
8434  
8435                 /*
8436                  * Do a quota reservation only if uid/gid is actually
8437 @@ -165,7 +240,8 @@ xfs_setattr(
8438                  */
8439                 if (XFS_IS_QUOTA_RUNNING(mp) &&
8440                     ((XFS_IS_UQUOTA_ON(mp) && iuid != uid) ||
8441 -                    (XFS_IS_GQUOTA_ON(mp) && igid != gid))) {
8442 +                    (XFS_IS_GQUOTA_ON(mp) && igid != gid) ||
8443 +                    (XFS_IS_GQUOTA_ON(mp) && itag != tag))) {
8444                         ASSERT(tp);
8445                         code = xfs_qm_vop_chown_reserve(tp, ip, udqp, gdqp,
8446                                                 capable(CAP_FOWNER) ?
8447 @@ -326,7 +402,7 @@ xfs_setattr(
8448         /*
8449          * Change file ownership.  Must be the owner or privileged.
8450          */
8451 -       if (mask & (ATTR_UID|ATTR_GID)) {
8452 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8453                 /*
8454                  * CAP_FSETID overrides the following restrictions:
8455                  *
8456 @@ -342,6 +418,10 @@ xfs_setattr(
8457                  * Change the ownerships and register quota modifications
8458                  * in the transaction.
8459                  */
8460 +               if (itag != tag) {
8461 +                       ip->i_d.di_tag = tag;
8462 +                       inode->i_tag = tag;
8463 +               }
8464                 if (iuid != uid) {
8465                         if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_UQUOTA_ON(mp)) {
8466                                 ASSERT(mask & ATTR_UID);
8467 diff -NurpP --minimal linux-2.6.36/fs/xfs/xfs_vnodeops.h linux-2.6.36-vs2.3.0.36.33/fs/xfs/xfs_vnodeops.h
8468 --- linux-2.6.36/fs/xfs/xfs_vnodeops.h  2010-07-07 18:31:54.000000000 +0200
8469 +++ linux-2.6.36-vs2.3.0.36.33/fs/xfs/xfs_vnodeops.h    2010-10-21 13:09:36.000000000 +0200
8470 @@ -14,6 +14,7 @@ struct xfs_inode;
8471  struct xfs_iomap;
8472  
8473  
8474 +int xfs_sync_xflags(struct xfs_inode *ip);
8475  int xfs_setattr(struct xfs_inode *ip, struct iattr *vap, int flags);
8476  #define        XFS_ATTR_DMI            0x01    /* invocation from a DMI function */
8477  #define        XFS_ATTR_NONBLOCK       0x02    /* return EAGAIN if operation would block */
8478 diff -NurpP --minimal linux-2.6.36/include/asm-generic/tlb.h linux-2.6.36-vs2.3.0.36.33/include/asm-generic/tlb.h
8479 --- linux-2.6.36/include/asm-generic/tlb.h      2009-09-10 15:26:24.000000000 +0200
8480 +++ linux-2.6.36-vs2.3.0.36.33/include/asm-generic/tlb.h        2010-10-21 13:09:36.000000000 +0200
8481 @@ -14,6 +14,7 @@
8482  #define _ASM_GENERIC__TLB_H
8483  
8484  #include <linux/swap.h>
8485 +#include <linux/vs_memory.h>
8486  #include <asm/pgalloc.h>
8487  #include <asm/tlbflush.h>
8488  
8489 diff -NurpP --minimal linux-2.6.36/include/linux/capability.h linux-2.6.36-vs2.3.0.36.33/include/linux/capability.h
8490 --- linux-2.6.36/include/linux/capability.h     2010-10-21 13:07:52.000000000 +0200
8491 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/capability.h       2010-10-21 13:09:36.000000000 +0200
8492 @@ -280,6 +280,7 @@ struct cpu_vfs_cap_data {
8493     arbitrary SCSI commands */
8494  /* Allow setting encryption key on loopback filesystem */
8495  /* Allow setting zone reclaim policy */
8496 +/* Allow the selection of a security context */
8497  
8498  #define CAP_SYS_ADMIN        21
8499  
8500 @@ -352,7 +353,13 @@ struct cpu_vfs_cap_data {
8501  
8502  #define CAP_MAC_ADMIN        33
8503  
8504 -#define CAP_LAST_CAP         CAP_MAC_ADMIN
8505 +/* Allow context manipulations */
8506 +/* Allow changing context info on files */
8507 +
8508 +#define CAP_CONTEXT         34
8509 +
8510 +
8511 +#define CAP_LAST_CAP         CAP_CONTEXT
8512  
8513  #define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
8514  
8515 diff -NurpP --minimal linux-2.6.36/include/linux/devpts_fs.h linux-2.6.36-vs2.3.0.36.33/include/linux/devpts_fs.h
8516 --- linux-2.6.36/include/linux/devpts_fs.h      2008-12-25 00:26:37.000000000 +0100
8517 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/devpts_fs.h        2010-10-21 13:09:36.000000000 +0200
8518 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
8519  
8520  #endif
8521  
8522 -
8523  #endif /* _LINUX_DEVPTS_FS_H */
8524 diff -NurpP --minimal linux-2.6.36/include/linux/ext2_fs.h linux-2.6.36-vs2.3.0.36.33/include/linux/ext2_fs.h
8525 --- linux-2.6.36/include/linux/ext2_fs.h        2010-02-25 11:52:07.000000000 +0100
8526 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/ext2_fs.h  2010-10-21 13:09:36.000000000 +0200
8527 @@ -189,8 +189,12 @@ struct ext2_group_desc
8528  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
8529  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
8530  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
8531 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
8532  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
8533  
8534 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
8535 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
8536 +
8537  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
8538  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
8539  
8540 @@ -274,7 +278,8 @@ struct ext2_inode {
8541                         __u16   i_pad1;
8542                         __le16  l_i_uid_high;   /* these 2 fields    */
8543                         __le16  l_i_gid_high;   /* were reserved2[0] */
8544 -                       __u32   l_i_reserved2;
8545 +                       __le16  l_i_tag;        /* Context Tag */
8546 +                       __u16   l_i_reserved2;
8547                 } linux2;
8548                 struct {
8549                         __u8    h_i_frag;       /* Fragment number */
8550 @@ -303,6 +308,7 @@ struct ext2_inode {
8551  #define i_gid_low      i_gid
8552  #define i_uid_high     osd2.linux2.l_i_uid_high
8553  #define i_gid_high     osd2.linux2.l_i_gid_high
8554 +#define i_raw_tag      osd2.linux2.l_i_tag
8555  #define i_reserved2    osd2.linux2.l_i_reserved2
8556  #endif
8557  
8558 @@ -347,6 +353,7 @@ struct ext2_inode {
8559  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
8560  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
8561  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
8562 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
8563  
8564  
8565  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
8566 diff -NurpP --minimal linux-2.6.36/include/linux/ext3_fs.h linux-2.6.36-vs2.3.0.36.33/include/linux/ext3_fs.h
8567 --- linux-2.6.36/include/linux/ext3_fs.h        2010-10-21 13:07:53.000000000 +0200
8568 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/ext3_fs.h  2010-10-21 13:09:36.000000000 +0200
8569 @@ -173,10 +173,14 @@ struct ext3_group_desc
8570  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
8571  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
8572  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
8573 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
8574  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
8575  
8576 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
8577 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
8578 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
8579 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
8580 +
8581 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
8582 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
8583  
8584  /* Flags that should be inherited by new inodes from their parent. */
8585  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
8586 @@ -312,7 +316,8 @@ struct ext3_inode {
8587                         __u16   i_pad1;
8588                         __le16  l_i_uid_high;   /* these 2 fields    */
8589                         __le16  l_i_gid_high;   /* were reserved2[0] */
8590 -                       __u32   l_i_reserved2;
8591 +                       __le16  l_i_tag;        /* Context Tag */
8592 +                       __u16   l_i_reserved2;
8593                 } linux2;
8594                 struct {
8595                         __u8    h_i_frag;       /* Fragment number */
8596 @@ -343,6 +348,7 @@ struct ext3_inode {
8597  #define i_gid_low      i_gid
8598  #define i_uid_high     osd2.linux2.l_i_uid_high
8599  #define i_gid_high     osd2.linux2.l_i_gid_high
8600 +#define i_raw_tag      osd2.linux2.l_i_tag
8601  #define i_reserved2    osd2.linux2.l_i_reserved2
8602  
8603  #elif defined(__GNU__)
8604 @@ -405,6 +411,7 @@ struct ext3_inode {
8605  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
8606  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
8607                                                   * error in ordered mode */
8608 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
8609  
8610  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
8611  #ifndef _LINUX_EXT2_FS_H
8612 @@ -908,6 +915,7 @@ extern void ext3_get_inode_flags(struct 
8613  extern void ext3_set_aops(struct inode *inode);
8614  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
8615                        u64 start, u64 len);
8616 +extern int ext3_sync_flags(struct inode *, int, int);
8617  
8618  /* ioctl.c */
8619  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
8620 diff -NurpP --minimal linux-2.6.36/include/linux/fs.h linux-2.6.36-vs2.3.0.36.33/include/linux/fs.h
8621 --- linux-2.6.36/include/linux/fs.h     2010-10-21 13:07:53.000000000 +0200
8622 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/fs.h       2010-10-21 13:09:36.000000000 +0200
8623 @@ -208,6 +208,9 @@ struct inodes_stat_t {
8624  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
8625  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
8626  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
8627 +#define MS_TAGGED      (1<<25) /* use generic inode tagging */
8628 +#define MS_TAGID       (1<<26) /* use specific tag for this mount */
8629 +#define MS_NOTAGCHECK  (1<<27) /* don't check tags */
8630  #define MS_BORN                (1<<29)
8631  #define MS_ACTIVE      (1<<30)
8632  #define MS_NOUSER      (1<<31)
8633 @@ -235,6 +238,14 @@ struct inodes_stat_t {
8634  #define S_NOCMTIME     128     /* Do not update file c/mtime */
8635  #define S_SWAPFILE     256     /* Do not truncate: swapon got its bmaps */
8636  #define S_PRIVATE      512     /* Inode is fs-internal */
8637 +#define S_IXUNLINK     1024    /* Immutable Invert on unlink */
8638 +
8639 +/* Linux-VServer related Inode flags */
8640 +
8641 +#define V_VALID                1
8642 +#define V_XATTR                2
8643 +#define V_BARRIER      4       /* Barrier for chroot() */
8644 +#define V_COW          8       /* Copy on Write */
8645  
8646  /*
8647   * Note that nosuid etc flags are inode-specific: setting some file-system
8648 @@ -257,12 +268,15 @@ struct inodes_stat_t {
8649  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
8650                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
8651  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
8652 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8653 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
8654 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8655 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
8656 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
8657  
8658  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
8659  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
8660  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
8661 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
8662 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
8663  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
8664  
8665  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
8666 @@ -270,6 +284,16 @@ struct inodes_stat_t {
8667  #define IS_SWAPFILE(inode)     ((inode)->i_flags & S_SWAPFILE)
8668  #define IS_PRIVATE(inode)      ((inode)->i_flags & S_PRIVATE)
8669  
8670 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
8671 +
8672 +#ifdef CONFIG_VSERVER_COWBL
8673 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
8674 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
8675 +#else
8676 +#  define IS_COW(inode)                (0)
8677 +#  define IS_COW_LINK(inode)   (0)
8678 +#endif
8679 +
8680  /* the read-only stuff doesn't really belong here, but any other place is
8681     probably as bad and I don't want to create yet another include file. */
8682  
8683 @@ -353,11 +377,14 @@ struct inodes_stat_t {
8684  #define FS_TOPDIR_FL                   0x00020000 /* Top of directory hierarchies*/
8685  #define FS_EXTENT_FL                   0x00080000 /* Extents */
8686  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
8687 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
8688  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
8689  
8690 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
8691 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
8692 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
8693 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
8694  
8695 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
8696 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
8697  
8698  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
8699  #define SYNC_FILE_RANGE_WRITE          2
8700 @@ -437,6 +464,7 @@ typedef void (dio_iodone_t)(struct kiocb
8701  #define ATTR_KILL_PRIV (1 << 14)
8702  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
8703  #define ATTR_TIMES_SET (1 << 16)
8704 +#define ATTR_TAG       (1 << 17)
8705  
8706  /*
8707   * This is the Inode Attributes structure, used for notify_change().  It
8708 @@ -452,6 +480,7 @@ struct iattr {
8709         umode_t         ia_mode;
8710         uid_t           ia_uid;
8711         gid_t           ia_gid;
8712 +       tag_t           ia_tag;
8713         loff_t          ia_size;
8714         struct timespec ia_atime;
8715         struct timespec ia_mtime;
8716 @@ -465,6 +494,9 @@ struct iattr {
8717         struct file     *ia_file;
8718  };
8719  
8720 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
8721 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
8722 +
8723  /*
8724   * Includes for diskquotas.
8725   */
8726 @@ -732,7 +764,9 @@ struct inode {
8727         unsigned int            i_nlink;
8728         uid_t                   i_uid;
8729         gid_t                   i_gid;
8730 +       tag_t                   i_tag;
8731         dev_t                   i_rdev;
8732 +       dev_t                   i_mdev;
8733         unsigned int            i_blkbits;
8734         u64                     i_version;
8735         loff_t                  i_size;
8736 @@ -774,7 +808,8 @@ struct inode {
8737         unsigned long           i_state;
8738         unsigned long           dirtied_when;   /* jiffies of first dirtying */
8739  
8740 -       unsigned int            i_flags;
8741 +       unsigned short          i_flags;
8742 +       unsigned short          i_vflags;
8743  
8744         atomic_t                i_writecount;
8745  #ifdef CONFIG_SECURITY
8746 @@ -862,12 +897,12 @@ static inline void i_size_write(struct i
8747  
8748  static inline unsigned iminor(const struct inode *inode)
8749  {
8750 -       return MINOR(inode->i_rdev);
8751 +       return MINOR(inode->i_mdev);
8752  }
8753  
8754  static inline unsigned imajor(const struct inode *inode)
8755  {
8756 -       return MAJOR(inode->i_rdev);
8757 +       return MAJOR(inode->i_mdev);
8758  }
8759  
8760  extern struct block_device *I_BDEV(struct inode *inode);
8761 @@ -929,6 +964,7 @@ struct file {
8762         loff_t                  f_pos;
8763         struct fown_struct      f_owner;
8764         const struct cred       *f_cred;
8765 +       xid_t                   f_xid;
8766         struct file_ra_state    f_ra;
8767  
8768         u64                     f_version;
8769 @@ -1068,6 +1104,7 @@ struct file_lock {
8770         struct file *fl_file;
8771         loff_t fl_start;
8772         loff_t fl_end;
8773 +       xid_t fl_xid;
8774  
8775         struct fasync_struct *  fl_fasync; /* for lease break notifications */
8776         unsigned long fl_break_time;    /* for nonblocking lease breaks */
8777 @@ -1536,6 +1573,7 @@ struct inode_operations {
8778         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
8779         ssize_t (*listxattr) (struct dentry *, char *, size_t);
8780         int (*removexattr) (struct dentry *, const char *);
8781 +       int (*sync_flags) (struct inode *, int, int);
8782         void (*truncate_range)(struct inode *, loff_t, loff_t);
8783         long (*fallocate)(struct inode *inode, int mode, loff_t offset,
8784                           loff_t len);
8785 @@ -1556,6 +1594,7 @@ extern ssize_t vfs_readv(struct file *, 
8786                 unsigned long, loff_t *);
8787  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
8788                 unsigned long, loff_t *);
8789 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
8790  
8791  struct super_operations {
8792         struct inode *(*alloc_inode)(struct super_block *sb);
8793 @@ -2344,6 +2383,7 @@ extern int dcache_dir_open(struct inode 
8794  extern int dcache_dir_close(struct inode *, struct file *);
8795  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
8796  extern int dcache_readdir(struct file *, void *, filldir_t);
8797 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
8798  extern int simple_setattr(struct dentry *, struct iattr *);
8799  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
8800  extern int simple_statfs(struct dentry *, struct kstatfs *);
8801 diff -NurpP --minimal linux-2.6.36/include/linux/gfs2_ondisk.h linux-2.6.36-vs2.3.0.36.33/include/linux/gfs2_ondisk.h
8802 --- linux-2.6.36/include/linux/gfs2_ondisk.h    2010-07-07 18:31:55.000000000 +0200
8803 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/gfs2_ondisk.h      2010-10-21 13:09:36.000000000 +0200
8804 @@ -211,6 +211,9 @@ enum {
8805         gfs2fl_NoAtime          = 7,
8806         gfs2fl_Sync             = 8,
8807         gfs2fl_System           = 9,
8808 +       gfs2fl_IXUnlink         = 16,
8809 +       gfs2fl_Barrier          = 17,
8810 +       gfs2fl_Cow              = 18,
8811         gfs2fl_TruncInProg      = 29,
8812         gfs2fl_InheritDirectio  = 30,
8813         gfs2fl_InheritJdata     = 31,
8814 @@ -227,6 +230,9 @@ enum {
8815  #define GFS2_DIF_NOATIME               0x00000080
8816  #define GFS2_DIF_SYNC                  0x00000100
8817  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
8818 +#define GFS2_DIF_IXUNLINK              0x00010000
8819 +#define GFS2_DIF_BARRIER               0x00020000
8820 +#define GFS2_DIF_COW                   0x00040000
8821  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
8822  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000
8823  #define GFS2_DIF_INHERIT_JDATA         0x80000000
8824 diff -NurpP --minimal linux-2.6.36/include/linux/if_tun.h linux-2.6.36-vs2.3.0.36.33/include/linux/if_tun.h
8825 --- linux-2.6.36/include/linux/if_tun.h 2010-08-02 16:52:54.000000000 +0200
8826 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/if_tun.h   2010-10-21 13:09:36.000000000 +0200
8827 @@ -53,6 +53,7 @@
8828  #define TUNDETACHFILTER _IOW('T', 214, struct sock_fprog)
8829  #define TUNGETVNETHDRSZ _IOR('T', 215, int)
8830  #define TUNSETVNETHDRSZ _IOW('T', 216, int)
8831 +#define TUNSETNID     _IOW('T', 217, int)
8832  
8833  /* TUNSETIFF ifr flags */
8834  #define IFF_TUN                0x0001
8835 diff -NurpP --minimal linux-2.6.36/include/linux/init_task.h linux-2.6.36-vs2.3.0.36.33/include/linux/init_task.h
8836 --- linux-2.6.36/include/linux/init_task.h      2010-08-02 16:52:54.000000000 +0200
8837 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/init_task.h        2010-10-21 13:09:36.000000000 +0200
8838 @@ -172,6 +172,10 @@ extern struct cred init_cred;
8839         INIT_FTRACE_GRAPH                                               \
8840         INIT_TRACE_RECURSION                                            \
8841         INIT_TASK_RCU_PREEMPT(tsk)                                      \
8842 +       .xid            = 0,                                            \
8843 +       .vx_info        = NULL,                                         \
8844 +       .nid            = 0,                                            \
8845 +       .nx_info        = NULL,                                         \
8846  }
8847  
8848  
8849 diff -NurpP --minimal linux-2.6.36/include/linux/ipc.h linux-2.6.36-vs2.3.0.36.33/include/linux/ipc.h
8850 --- linux-2.6.36/include/linux/ipc.h    2009-12-03 20:02:55.000000000 +0100
8851 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/ipc.h      2010-10-21 13:09:36.000000000 +0200
8852 @@ -91,6 +91,7 @@ struct kern_ipc_perm
8853         key_t           key;
8854         uid_t           uid;
8855         gid_t           gid;
8856 +       xid_t           xid;
8857         uid_t           cuid;
8858         gid_t           cgid;
8859         mode_t          mode; 
8860 diff -NurpP --minimal linux-2.6.36/include/linux/Kbuild linux-2.6.36-vs2.3.0.36.33/include/linux/Kbuild
8861 --- linux-2.6.36/include/linux/Kbuild   2010-10-21 13:07:52.000000000 +0200
8862 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/Kbuild     2010-10-21 14:12:01.000000000 +0200
8863 @@ -15,6 +15,7 @@ header-y += netfilter_bridge/
8864  header-y += netfilter_ipv4/
8865  header-y += netfilter_ipv6/
8866  header-y += usb/
8867 +header-y += vserver/
8868  header-y += wimax/
8869  
8870  objhdr-y += version.h
8871 diff -NurpP --minimal linux-2.6.36/include/linux/loop.h linux-2.6.36-vs2.3.0.36.33/include/linux/loop.h
8872 --- linux-2.6.36/include/linux/loop.h   2009-09-10 15:26:25.000000000 +0200
8873 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/loop.h     2010-10-21 13:09:36.000000000 +0200
8874 @@ -45,6 +45,7 @@ struct loop_device {
8875         struct loop_func_table *lo_encryption;
8876         __u32           lo_init[2];
8877         uid_t           lo_key_owner;   /* Who set the key */
8878 +       xid_t           lo_xid;
8879         int             (*ioctl)(struct loop_device *, int cmd, 
8880                                  unsigned long arg); 
8881  
8882 diff -NurpP --minimal linux-2.6.36/include/linux/magic.h linux-2.6.36-vs2.3.0.36.33/include/linux/magic.h
8883 --- linux-2.6.36/include/linux/magic.h  2010-07-07 18:31:55.000000000 +0200
8884 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/magic.h    2010-10-21 13:09:36.000000000 +0200
8885 @@ -3,7 +3,7 @@
8886  
8887  #define ADFS_SUPER_MAGIC       0xadf5
8888  #define AFFS_SUPER_MAGIC       0xadff
8889 -#define AFS_SUPER_MAGIC                0x5346414F
8890 +#define AFS_SUPER_MAGIC                0x5346414F
8891  #define AUTOFS_SUPER_MAGIC     0x0187
8892  #define CODA_SUPER_MAGIC       0x73757245
8893  #define CRAMFS_MAGIC           0x28cd3d45      /* some random number */
8894 @@ -38,6 +38,7 @@
8895  #define NFS_SUPER_MAGIC                0x6969
8896  #define OPENPROM_SUPER_MAGIC   0x9fa1
8897  #define PROC_SUPER_MAGIC       0x9fa0
8898 +#define DEVPTS_SUPER_MAGIC     0x1cd1
8899  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
8900  
8901  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
8902 diff -NurpP --minimal linux-2.6.36/include/linux/major.h linux-2.6.36-vs2.3.0.36.33/include/linux/major.h
8903 --- linux-2.6.36/include/linux/major.h  2009-09-10 15:26:25.000000000 +0200
8904 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/major.h    2010-10-21 13:09:36.000000000 +0200
8905 @@ -15,6 +15,7 @@
8906  #define HD_MAJOR               IDE0_MAJOR
8907  #define PTY_SLAVE_MAJOR                3
8908  #define TTY_MAJOR              4
8909 +#define VROOT_MAJOR            4
8910  #define TTYAUX_MAJOR           5
8911  #define LP_MAJOR               6
8912  #define VCS_MAJOR              7
8913 diff -NurpP --minimal linux-2.6.36/include/linux/memcontrol.h linux-2.6.36-vs2.3.0.36.33/include/linux/memcontrol.h
8914 --- linux-2.6.36/include/linux/memcontrol.h     2010-10-21 13:07:53.000000000 +0200
8915 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/memcontrol.h       2010-10-21 13:09:36.000000000 +0200
8916 @@ -77,6 +77,13 @@ int task_in_mem_cgroup(struct task_struc
8917  extern struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page);
8918  extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
8919  
8920 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
8921 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
8922 +
8923 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
8924 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
8925 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
8926 +
8927  static inline
8928  int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
8929  {
8930 diff -NurpP --minimal linux-2.6.36/include/linux/mm_types.h linux-2.6.36-vs2.3.0.36.33/include/linux/mm_types.h
8931 --- linux-2.6.36/include/linux/mm_types.h       2010-10-21 13:07:53.000000000 +0200
8932 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/mm_types.h 2010-10-21 13:09:36.000000000 +0200
8933 @@ -269,6 +269,7 @@ struct mm_struct {
8934  
8935         /* Architecture-specific MM context */
8936         mm_context_t context;
8937 +       struct vx_info *mm_vx_info;
8938  
8939         /* Swap token stuff */
8940         /*
8941 diff -NurpP --minimal linux-2.6.36/include/linux/mount.h linux-2.6.36-vs2.3.0.36.33/include/linux/mount.h
8942 --- linux-2.6.36/include/linux/mount.h  2010-10-21 13:07:53.000000000 +0200
8943 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/mount.h    2010-10-21 13:09:36.000000000 +0200
8944 @@ -46,6 +46,9 @@ struct mnt_namespace;
8945  
8946  #define MNT_INTERNAL   0x4000
8947  
8948 +#define MNT_TAGID      0x10000
8949 +#define MNT_NOTAG      0x20000
8950 +
8951  struct vfsmount {
8952         struct list_head mnt_hash;
8953         struct vfsmount *mnt_parent;    /* fs we are mounted on */
8954 @@ -84,6 +87,7 @@ struct vfsmount {
8955  #else
8956         int mnt_writers;
8957  #endif
8958 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
8959  };
8960  
8961  static inline int *get_mnt_writers_ptr(struct vfsmount *mnt)
8962 diff -NurpP --minimal linux-2.6.36/include/linux/net.h linux-2.6.36-vs2.3.0.36.33/include/linux/net.h
8963 --- linux-2.6.36/include/linux/net.h    2010-08-02 16:52:55.000000000 +0200
8964 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/net.h      2010-10-21 13:09:36.000000000 +0200
8965 @@ -71,6 +71,7 @@ struct net;
8966  #define SOCK_NOSPACE           2
8967  #define SOCK_PASSCRED          3
8968  #define SOCK_PASSSEC           4
8969 +#define SOCK_USER_SOCKET       5
8970  
8971  #ifndef ARCH_HAS_SOCKET_TYPES
8972  /**
8973 diff -NurpP --minimal linux-2.6.36/include/linux/nfs_mount.h linux-2.6.36-vs2.3.0.36.33/include/linux/nfs_mount.h
8974 --- linux-2.6.36/include/linux/nfs_mount.h      2010-10-21 13:07:54.000000000 +0200
8975 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/nfs_mount.h        2010-10-21 13:09:36.000000000 +0200
8976 @@ -63,7 +63,8 @@ struct nfs_mount_data {
8977  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
8978  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
8979  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
8980 -#define NFS_MOUNT_FLAGMASK     0xFFFF
8981 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
8982 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
8983  
8984  /* The following are for internal use only */
8985  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
8986 diff -NurpP --minimal linux-2.6.36/include/linux/nsproxy.h linux-2.6.36-vs2.3.0.36.33/include/linux/nsproxy.h
8987 --- linux-2.6.36/include/linux/nsproxy.h        2009-06-11 17:13:17.000000000 +0200
8988 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/nsproxy.h  2010-10-21 13:09:36.000000000 +0200
8989 @@ -3,6 +3,7 @@
8990  
8991  #include <linux/spinlock.h>
8992  #include <linux/sched.h>
8993 +#include <linux/vserver/debug.h>
8994  
8995  struct mnt_namespace;
8996  struct uts_namespace;
8997 @@ -63,22 +64,33 @@ static inline struct nsproxy *task_nspro
8998  }
8999  
9000  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
9001 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
9002  void exit_task_namespaces(struct task_struct *tsk);
9003  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
9004  void free_nsproxy(struct nsproxy *ns);
9005  int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
9006         struct fs_struct *);
9007  
9008 -static inline void put_nsproxy(struct nsproxy *ns)
9009 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
9010 +
9011 +static inline void __get_nsproxy(struct nsproxy *ns,
9012 +       const char *_file, int _line)
9013  {
9014 -       if (atomic_dec_and_test(&ns->count)) {
9015 -               free_nsproxy(ns);
9016 -       }
9017 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
9018 +               ns, atomic_read(&ns->count), _file, _line);
9019 +       atomic_inc(&ns->count);
9020  }
9021  
9022 -static inline void get_nsproxy(struct nsproxy *ns)
9023 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
9024 +
9025 +static inline void __put_nsproxy(struct nsproxy *ns,
9026 +       const char *_file, int _line)
9027  {
9028 -       atomic_inc(&ns->count);
9029 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
9030 +               ns, atomic_read(&ns->count), _file, _line);
9031 +       if (atomic_dec_and_test(&ns->count)) {
9032 +               free_nsproxy(ns);
9033 +       }
9034  }
9035  
9036  #ifdef CONFIG_CGROUP_NS
9037 diff -NurpP --minimal linux-2.6.36/include/linux/pid.h linux-2.6.36-vs2.3.0.36.33/include/linux/pid.h
9038 --- linux-2.6.36/include/linux/pid.h    2009-03-24 14:22:43.000000000 +0100
9039 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/pid.h      2010-10-21 13:09:36.000000000 +0200
9040 @@ -8,7 +8,8 @@ enum pid_type
9041         PIDTYPE_PID,
9042         PIDTYPE_PGID,
9043         PIDTYPE_SID,
9044 -       PIDTYPE_MAX
9045 +       PIDTYPE_MAX,
9046 +       PIDTYPE_REALPID
9047  };
9048  
9049  /*
9050 @@ -160,6 +161,7 @@ static inline pid_t pid_nr(struct pid *p
9051  }
9052  
9053  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
9054 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
9055  pid_t pid_vnr(struct pid *pid);
9056  
9057  #define do_each_pid_task(pid, type, task)                              \
9058 diff -NurpP --minimal linux-2.6.36/include/linux/proc_fs.h linux-2.6.36-vs2.3.0.36.33/include/linux/proc_fs.h
9059 --- linux-2.6.36/include/linux/proc_fs.h        2009-12-03 20:02:56.000000000 +0100
9060 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/proc_fs.h  2010-10-21 13:09:36.000000000 +0200
9061 @@ -56,6 +56,7 @@ struct proc_dir_entry {
9062         nlink_t nlink;
9063         uid_t uid;
9064         gid_t gid;
9065 +       int vx_flags;
9066         loff_t size;
9067         const struct inode_operations *proc_iops;
9068         /*
9069 @@ -250,12 +251,18 @@ kclist_add(struct kcore_list *new, void 
9070  extern void kclist_add(struct kcore_list *, void *, size_t, int type);
9071  #endif
9072  
9073 +struct vx_info;
9074 +struct nx_info;
9075 +
9076  union proc_op {
9077         int (*proc_get_link)(struct inode *, struct path *);
9078         int (*proc_read)(struct task_struct *task, char *page);
9079         int (*proc_show)(struct seq_file *m,
9080                 struct pid_namespace *ns, struct pid *pid,
9081                 struct task_struct *task);
9082 +       int (*proc_vs_read)(char *page);
9083 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
9084 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
9085  };
9086  
9087  struct ctl_table_header;
9088 @@ -263,6 +270,7 @@ struct ctl_table;
9089  
9090  struct proc_inode {
9091         struct pid *pid;
9092 +       int vx_flags;
9093         int fd;
9094         union proc_op op;
9095         struct proc_dir_entry *pde;
9096 diff -NurpP --minimal linux-2.6.36/include/linux/quotaops.h linux-2.6.36-vs2.3.0.36.33/include/linux/quotaops.h
9097 --- linux-2.6.36/include/linux/quotaops.h       2010-10-21 13:07:54.000000000 +0200
9098 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/quotaops.h 2010-10-21 13:09:36.000000000 +0200
9099 @@ -8,6 +8,7 @@
9100  #define _LINUX_QUOTAOPS_
9101  
9102  #include <linux/fs.h>
9103 +#include <linux/vs_dlimit.h>
9104  
9105  #define DQUOT_SPACE_WARN       0x1
9106  #define DQUOT_SPACE_RESERVE    0x2
9107 @@ -205,11 +206,12 @@ static inline void dquot_drop(struct ino
9108  
9109  static inline int dquot_alloc_inode(const struct inode *inode)
9110  {
9111 -       return 0;
9112 +       return dl_alloc_inode(inode);
9113  }
9114  
9115  static inline void dquot_free_inode(const struct inode *inode)
9116  {
9117 +       dl_free_inode(inode);
9118  }
9119  
9120  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
9121 @@ -220,6 +222,10 @@ static inline int dquot_transfer(struct 
9122  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
9123                 int flags)
9124  {
9125 +       int ret = 0;
9126 +
9127 +       if ((ret = dl_alloc_space(inode, number)))
9128 +               return ret;
9129         if (!(flags & DQUOT_SPACE_RESERVE))
9130                 inode_add_bytes(inode, number);
9131         return 0;
9132 @@ -230,6 +236,7 @@ static inline void __dquot_free_space(st
9133  {
9134         if (!(flags & DQUOT_SPACE_RESERVE))
9135                 inode_sub_bytes(inode, number);
9136 +       dl_free_space(inode, number);
9137  }
9138  
9139  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
9140 diff -NurpP --minimal linux-2.6.36/include/linux/reboot.h linux-2.6.36-vs2.3.0.36.33/include/linux/reboot.h
9141 --- linux-2.6.36/include/linux/reboot.h 2010-07-07 18:31:56.000000000 +0200
9142 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/reboot.h   2010-10-21 13:09:36.000000000 +0200
9143 @@ -33,6 +33,7 @@
9144  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
9145  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
9146  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
9147 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
9148  
9149  
9150  #ifdef __KERNEL__
9151 diff -NurpP --minimal linux-2.6.36/include/linux/reiserfs_fs.h linux-2.6.36-vs2.3.0.36.33/include/linux/reiserfs_fs.h
9152 --- linux-2.6.36/include/linux/reiserfs_fs.h    2010-10-21 13:07:54.000000000 +0200
9153 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/reiserfs_fs.h      2010-10-21 13:09:36.000000000 +0200
9154 @@ -977,6 +977,11 @@ struct stat_data_v1 {
9155  #define REISERFS_COMPR_FL     FS_COMPR_FL
9156  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
9157  
9158 +/* unfortunately reiserfs sdattr is only 16 bit */
9159 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
9160 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
9161 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
9162 +
9163  /* persistent flags that file inherits from the parent directory */
9164  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
9165                                 REISERFS_SYNC_FL |      \
9166 @@ -986,6 +991,9 @@ struct stat_data_v1 {
9167                                 REISERFS_COMPR_FL |     \
9168                                 REISERFS_NOTAIL_FL )
9169  
9170 +#define REISERFS_FL_USER_VISIBLE       0x80FF
9171 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
9172 +
9173  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
9174     address blocks) */
9175  struct stat_data {
9176 @@ -2071,6 +2079,7 @@ static inline void reiserfs_update_sd(st
9177  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
9178  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
9179  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
9180 +int reiserfs_sync_flags(struct inode *inode, int, int);
9181  
9182  /* namei.c */
9183  void set_de_name_and_namelen(struct reiserfs_dir_entry *de);
9184 diff -NurpP --minimal linux-2.6.36/include/linux/reiserfs_fs_sb.h linux-2.6.36-vs2.3.0.36.33/include/linux/reiserfs_fs_sb.h
9185 --- linux-2.6.36/include/linux/reiserfs_fs_sb.h 2010-02-25 11:52:07.000000000 +0100
9186 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/reiserfs_fs_sb.h   2010-10-21 13:09:36.000000000 +0200
9187 @@ -476,6 +476,7 @@ enum reiserfs_mount_options {
9188         REISERFS_EXPOSE_PRIVROOT,
9189         REISERFS_BARRIER_NONE,
9190         REISERFS_BARRIER_FLUSH,
9191 +       REISERFS_TAGGED,
9192  
9193         /* Actions on error */
9194         REISERFS_ERROR_PANIC,
9195 diff -NurpP --minimal linux-2.6.36/include/linux/sched.h linux-2.6.36-vs2.3.0.36.33/include/linux/sched.h
9196 --- linux-2.6.36/include/linux/sched.h  2010-10-21 13:07:54.000000000 +0200
9197 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/sched.h    2010-10-21 13:09:36.000000000 +0200
9198 @@ -1339,6 +1339,14 @@ struct task_struct {
9199  #endif
9200         seccomp_t seccomp;
9201  
9202 +/* vserver context data */
9203 +       struct vx_info *vx_info;
9204 +       struct nx_info *nx_info;
9205 +
9206 +       xid_t xid;
9207 +       nid_t nid;
9208 +       tag_t tag;
9209 +
9210  /* Thread group tracking */
9211         u32 parent_exec_id;
9212         u32 self_exec_id;
9213 @@ -1573,6 +1581,11 @@ struct pid_namespace;
9214  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
9215                         struct pid_namespace *ns);
9216  
9217 +#include <linux/vserver/base.h>
9218 +#include <linux/vserver/context.h>
9219 +#include <linux/vserver/debug.h>
9220 +#include <linux/vserver/pid.h>
9221 +
9222  static inline pid_t task_pid_nr(struct task_struct *tsk)
9223  {
9224         return tsk->pid;
9225 @@ -1586,7 +1599,8 @@ static inline pid_t task_pid_nr_ns(struc
9226  
9227  static inline pid_t task_pid_vnr(struct task_struct *tsk)
9228  {
9229 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
9230 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
9231 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
9232  }
9233  
9234  
9235 @@ -1599,7 +1613,7 @@ pid_t task_tgid_nr_ns(struct task_struct
9236  
9237  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
9238  {
9239 -       return pid_vnr(task_tgid(tsk));
9240 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
9241  }
9242  
9243  
9244 diff -NurpP --minimal linux-2.6.36/include/linux/shmem_fs.h linux-2.6.36-vs2.3.0.36.33/include/linux/shmem_fs.h
9245 --- linux-2.6.36/include/linux/shmem_fs.h       2010-10-21 13:07:55.000000000 +0200
9246 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/shmem_fs.h 2010-10-21 13:09:36.000000000 +0200
9247 @@ -9,6 +9,9 @@
9248  
9249  #define SHMEM_NR_DIRECT 16
9250  
9251 +#define TMPFS_SUPER_MAGIC      0x01021994
9252 +
9253 +
9254  struct shmem_inode_info {
9255         spinlock_t              lock;
9256         unsigned long           flags;
9257 diff -NurpP --minimal linux-2.6.36/include/linux/stat.h linux-2.6.36-vs2.3.0.36.33/include/linux/stat.h
9258 --- linux-2.6.36/include/linux/stat.h   2008-12-25 00:26:37.000000000 +0100
9259 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/stat.h     2010-10-21 13:09:36.000000000 +0200
9260 @@ -66,6 +66,7 @@ struct kstat {
9261         unsigned int    nlink;
9262         uid_t           uid;
9263         gid_t           gid;
9264 +       tag_t           tag;
9265         dev_t           rdev;
9266         loff_t          size;
9267         struct timespec  atime;
9268 diff -NurpP --minimal linux-2.6.36/include/linux/sunrpc/auth.h linux-2.6.36-vs2.3.0.36.33/include/linux/sunrpc/auth.h
9269 --- linux-2.6.36/include/linux/sunrpc/auth.h    2010-10-21 13:07:55.000000000 +0200
9270 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/sunrpc/auth.h      2010-10-21 13:09:36.000000000 +0200
9271 @@ -25,6 +25,7 @@
9272  struct auth_cred {
9273         uid_t   uid;
9274         gid_t   gid;
9275 +       tag_t   tag;
9276         struct group_info *group_info;
9277         unsigned char machine_cred : 1;
9278  };
9279 diff -NurpP --minimal linux-2.6.36/include/linux/sunrpc/clnt.h linux-2.6.36-vs2.3.0.36.33/include/linux/sunrpc/clnt.h
9280 --- linux-2.6.36/include/linux/sunrpc/clnt.h    2010-10-21 13:07:55.000000000 +0200
9281 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/sunrpc/clnt.h      2010-10-21 13:09:36.000000000 +0200
9282 @@ -49,7 +49,8 @@ struct rpc_clnt {
9283         unsigned int            cl_softrtry : 1,/* soft timeouts */
9284                                 cl_discrtry : 1,/* disconnect before retry */
9285                                 cl_autobind : 1,/* use getport() */
9286 -                               cl_chatty   : 1;/* be verbose */
9287 +                               cl_chatty   : 1,/* be verbose */
9288 +                               cl_tag      : 1;/* context tagging */
9289  
9290         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
9291         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
9292 diff -NurpP --minimal linux-2.6.36/include/linux/syscalls.h linux-2.6.36-vs2.3.0.36.33/include/linux/syscalls.h
9293 --- linux-2.6.36/include/linux/syscalls.h       2010-10-21 13:07:55.000000000 +0200
9294 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/syscalls.h 2010-10-21 13:09:36.000000000 +0200
9295 @@ -478,6 +478,8 @@ asmlinkage long sys_symlink(const char _
9296  asmlinkage long sys_unlink(const char __user *pathname);
9297  asmlinkage long sys_rename(const char __user *oldname,
9298                                 const char __user *newname);
9299 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
9300 +                               umode_t mode);
9301  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
9302  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
9303  
9304 diff -NurpP --minimal linux-2.6.36/include/linux/sysctl.h linux-2.6.36-vs2.3.0.36.33/include/linux/sysctl.h
9305 --- linux-2.6.36/include/linux/sysctl.h 2010-08-02 16:52:56.000000000 +0200
9306 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/sysctl.h   2010-10-21 13:09:36.000000000 +0200
9307 @@ -60,6 +60,7 @@ enum
9308         CTL_ABI=9,              /* Binary emulation */
9309         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
9310         CTL_ARLAN=254,          /* arlan wireless driver */
9311 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
9312         CTL_S390DBF=5677,       /* s390 debug */
9313         CTL_SUNRPC=7249,        /* sunrpc debug */
9314         CTL_PM=9899,            /* frv power management */
9315 @@ -94,6 +95,7 @@ enum
9316  
9317         KERN_PANIC=15,          /* int: panic timeout */
9318         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
9319 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
9320  
9321         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
9322         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
9323 diff -NurpP --minimal linux-2.6.36/include/linux/sysfs.h linux-2.6.36-vs2.3.0.36.33/include/linux/sysfs.h
9324 --- linux-2.6.36/include/linux/sysfs.h  2010-10-21 13:07:55.000000000 +0200
9325 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/sysfs.h    2010-10-21 13:09:36.000000000 +0200
9326 @@ -19,6 +19,8 @@
9327  #include <linux/kobject_ns.h>
9328  #include <asm/atomic.h>
9329  
9330 +#define SYSFS_SUPER_MAGIC      0x62656572
9331 +
9332  struct kobject;
9333  struct module;
9334  enum kobj_ns_type;
9335 diff -NurpP --minimal linux-2.6.36/include/linux/time.h linux-2.6.36-vs2.3.0.36.33/include/linux/time.h
9336 --- linux-2.6.36/include/linux/time.h   2010-10-21 13:07:55.000000000 +0200
9337 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/time.h     2010-10-21 13:09:36.000000000 +0200
9338 @@ -252,6 +252,9 @@ static __always_inline void timespec_add
9339         a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
9340         a->tv_nsec = ns;
9341  }
9342 +
9343 +#include <linux/vs_time.h>
9344 +
9345  #endif /* __KERNEL__ */
9346  
9347  #define NFDBITS                        __NFDBITS
9348 diff -NurpP --minimal linux-2.6.36/include/linux/types.h linux-2.6.36-vs2.3.0.36.33/include/linux/types.h
9349 --- linux-2.6.36/include/linux/types.h  2010-10-21 13:07:55.000000000 +0200
9350 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/types.h    2010-10-21 13:09:36.000000000 +0200
9351 @@ -40,6 +40,9 @@ typedef __kernel_uid32_t      uid_t;
9352  typedef __kernel_gid32_t       gid_t;
9353  typedef __kernel_uid16_t        uid16_t;
9354  typedef __kernel_gid16_t        gid16_t;
9355 +typedef unsigned int           xid_t;
9356 +typedef unsigned int           nid_t;
9357 +typedef unsigned int           tag_t;
9358  
9359  typedef unsigned long          uintptr_t;
9360  
9361 diff -NurpP --minimal linux-2.6.36/include/linux/vroot.h linux-2.6.36-vs2.3.0.36.33/include/linux/vroot.h
9362 --- linux-2.6.36/include/linux/vroot.h  1970-01-01 01:00:00.000000000 +0100
9363 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vroot.h    2010-10-21 13:09:36.000000000 +0200
9364 @@ -0,0 +1,51 @@
9365 +
9366 +/*
9367 + * include/linux/vroot.h
9368 + *
9369 + * written by Herbert Pötzl, 9/11/2002
9370 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
9371 + *
9372 + * Copyright (C) 2002-2007 by Herbert Pötzl.
9373 + * Redistribution of this file is permitted under the
9374 + * GNU General Public License.
9375 + */
9376 +
9377 +#ifndef _LINUX_VROOT_H
9378 +#define _LINUX_VROOT_H
9379 +
9380 +
9381 +#ifdef __KERNEL__
9382 +
9383 +/* Possible states of device */
9384 +enum {
9385 +       Vr_unbound,
9386 +       Vr_bound,
9387 +};
9388 +
9389 +struct vroot_device {
9390 +       int             vr_number;
9391 +       int             vr_refcnt;
9392 +
9393 +       struct semaphore        vr_ctl_mutex;
9394 +       struct block_device    *vr_device;
9395 +       int                     vr_state;
9396 +};
9397 +
9398 +
9399 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
9400 +
9401 +extern int register_vroot_grb(vroot_grb_func *);
9402 +extern int unregister_vroot_grb(vroot_grb_func *);
9403 +
9404 +#endif /* __KERNEL__ */
9405 +
9406 +#define MAX_VROOT_DEFAULT      8
9407 +
9408 +/*
9409 + * IOCTL commands --- we will commandeer 0x56 ('V')
9410 + */
9411 +
9412 +#define VROOT_SET_DEV          0x5600
9413 +#define VROOT_CLR_DEV          0x5601
9414 +
9415 +#endif /* _LINUX_VROOT_H */
9416 diff -NurpP --minimal linux-2.6.36/include/linux/vs_base.h linux-2.6.36-vs2.3.0.36.33/include/linux/vs_base.h
9417 --- linux-2.6.36/include/linux/vs_base.h        1970-01-01 01:00:00.000000000 +0100
9418 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vs_base.h  2010-10-21 13:09:36.000000000 +0200
9419 @@ -0,0 +1,10 @@
9420 +#ifndef _VS_BASE_H
9421 +#define _VS_BASE_H
9422 +
9423 +#include "vserver/base.h"
9424 +#include "vserver/check.h"
9425 +#include "vserver/debug.h"
9426 +
9427 +#else
9428 +#warning duplicate inclusion
9429 +#endif
9430 diff -NurpP --minimal linux-2.6.36/include/linux/vs_context.h linux-2.6.36-vs2.3.0.36.33/include/linux/vs_context.h
9431 --- linux-2.6.36/include/linux/vs_context.h     1970-01-01 01:00:00.000000000 +0100
9432 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vs_context.h       2010-10-21 13:09:36.000000000 +0200
9433 @@ -0,0 +1,242 @@
9434 +#ifndef _VS_CONTEXT_H
9435 +#define _VS_CONTEXT_H
9436 +
9437 +#include "vserver/base.h"
9438 +#include "vserver/check.h"
9439 +#include "vserver/context.h"
9440 +#include "vserver/history.h"
9441 +#include "vserver/debug.h"
9442 +
9443 +#include <linux/sched.h>
9444 +
9445 +
9446 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
9447 +
9448 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
9449 +       const char *_file, int _line, void *_here)
9450 +{
9451 +       if (!vxi)
9452 +               return NULL;
9453 +
9454 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
9455 +               vxi, vxi ? vxi->vx_id : 0,
9456 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9457 +               _file, _line);
9458 +       __vxh_get_vx_info(vxi, _here);
9459 +
9460 +       atomic_inc(&vxi->vx_usecnt);
9461 +       return vxi;
9462 +}
9463 +
9464 +
9465 +extern void free_vx_info(struct vx_info *);
9466 +
9467 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
9468 +
9469 +static inline void __put_vx_info(struct vx_info *vxi,
9470 +       const char *_file, int _line, void *_here)
9471 +{
9472 +       if (!vxi)
9473 +               return;
9474 +
9475 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
9476 +               vxi, vxi ? vxi->vx_id : 0,
9477 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9478 +               _file, _line);
9479 +       __vxh_put_vx_info(vxi, _here);
9480 +
9481 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
9482 +               free_vx_info(vxi);
9483 +}
9484 +
9485 +
9486 +#define init_vx_info(p, i) \
9487 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9488 +
9489 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9490 +       const char *_file, int _line, void *_here)
9491 +{
9492 +       if (vxi) {
9493 +               vxlprintk(VXD_CBIT(xid, 3),
9494 +                       "init_vx_info(%p[#%d.%d])",
9495 +                       vxi, vxi ? vxi->vx_id : 0,
9496 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9497 +                       _file, _line);
9498 +               __vxh_init_vx_info(vxi, vxp, _here);
9499 +
9500 +               atomic_inc(&vxi->vx_usecnt);
9501 +       }
9502 +       *vxp = vxi;
9503 +}
9504 +
9505 +
9506 +#define set_vx_info(p, i) \
9507 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9508 +
9509 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9510 +       const char *_file, int _line, void *_here)
9511 +{
9512 +       struct vx_info *vxo;
9513 +
9514 +       if (!vxi)
9515 +               return;
9516 +
9517 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
9518 +               vxi, vxi ? vxi->vx_id : 0,
9519 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9520 +               _file, _line);
9521 +       __vxh_set_vx_info(vxi, vxp, _here);
9522 +
9523 +       atomic_inc(&vxi->vx_usecnt);
9524 +       vxo = xchg(vxp, vxi);
9525 +       BUG_ON(vxo);
9526 +}
9527 +
9528 +
9529 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
9530 +
9531 +static inline void __clr_vx_info(struct vx_info **vxp,
9532 +       const char *_file, int _line, void *_here)
9533 +{
9534 +       struct vx_info *vxo;
9535 +
9536 +       vxo = xchg(vxp, NULL);
9537 +       if (!vxo)
9538 +               return;
9539 +
9540 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
9541 +               vxo, vxo ? vxo->vx_id : 0,
9542 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
9543 +               _file, _line);
9544 +       __vxh_clr_vx_info(vxo, vxp, _here);
9545 +
9546 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
9547 +               free_vx_info(vxo);
9548 +}
9549 +
9550 +
9551 +#define claim_vx_info(v, p) \
9552 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9553 +
9554 +static inline void __claim_vx_info(struct vx_info *vxi,
9555 +       struct task_struct *task,
9556 +       const char *_file, int _line, void *_here)
9557 +{
9558 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
9559 +               vxi, vxi ? vxi->vx_id : 0,
9560 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9561 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9562 +               task, _file, _line);
9563 +       __vxh_claim_vx_info(vxi, task, _here);
9564 +
9565 +       atomic_inc(&vxi->vx_tasks);
9566 +}
9567 +
9568 +
9569 +extern void unhash_vx_info(struct vx_info *);
9570 +
9571 +#define release_vx_info(v, p) \
9572 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9573 +
9574 +static inline void __release_vx_info(struct vx_info *vxi,
9575 +       struct task_struct *task,
9576 +       const char *_file, int _line, void *_here)
9577 +{
9578 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
9579 +               vxi, vxi ? vxi->vx_id : 0,
9580 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9581 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9582 +               task, _file, _line);
9583 +       __vxh_release_vx_info(vxi, task, _here);
9584 +
9585 +       might_sleep();
9586 +
9587 +       if (atomic_dec_and_test(&vxi->vx_tasks))
9588 +               unhash_vx_info(vxi);
9589 +}
9590 +
9591 +
9592 +#define task_get_vx_info(p) \
9593 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
9594 +
9595 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
9596 +       const char *_file, int _line, void *_here)
9597 +{
9598 +       struct vx_info *vxi;
9599 +
9600 +       task_lock(p);
9601 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
9602 +               p, _file, _line);
9603 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
9604 +       task_unlock(p);
9605 +       return vxi;
9606 +}
9607 +
9608 +
9609 +static inline void __wakeup_vx_info(struct vx_info *vxi)
9610 +{
9611 +       if (waitqueue_active(&vxi->vx_wait))
9612 +               wake_up_interruptible(&vxi->vx_wait);
9613 +}
9614 +
9615 +
9616 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
9617 +
9618 +static inline void __enter_vx_info(struct vx_info *vxi,
9619 +       struct vx_info_save *vxis, const char *_file, int _line)
9620 +{
9621 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
9622 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
9623 +               current->xid, current->vx_info, _file, _line);
9624 +       vxis->vxi = xchg(&current->vx_info, vxi);
9625 +       vxis->xid = current->xid;
9626 +       current->xid = vxi ? vxi->vx_id : 0;
9627 +}
9628 +
9629 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
9630 +
9631 +static inline void __leave_vx_info(struct vx_info_save *vxis,
9632 +       const char *_file, int _line)
9633 +{
9634 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
9635 +               vxis, vxis->xid, vxis->vxi, current,
9636 +               current->xid, current->vx_info, _file, _line);
9637 +       (void)xchg(&current->vx_info, vxis->vxi);
9638 +       current->xid = vxis->xid;
9639 +}
9640 +
9641 +
9642 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
9643 +{
9644 +       vxis->vxi = xchg(&current->vx_info, NULL);
9645 +       vxis->xid = xchg(&current->xid, (xid_t)0);
9646 +}
9647 +
9648 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
9649 +{
9650 +       (void)xchg(&current->xid, vxis->xid);
9651 +       (void)xchg(&current->vx_info, vxis->vxi);
9652 +}
9653 +
9654 +#define task_is_init(p) \
9655 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
9656 +
9657 +static inline int __task_is_init(struct task_struct *p,
9658 +       const char *_file, int _line, void *_here)
9659 +{
9660 +       int is_init = is_global_init(p);
9661 +
9662 +       task_lock(p);
9663 +       if (p->vx_info)
9664 +               is_init = p->vx_info->vx_initpid == p->pid;
9665 +       task_unlock(p);
9666 +       return is_init;
9667 +}
9668 +
9669 +extern void exit_vx_info(struct task_struct *, int);
9670 +extern void exit_vx_info_early(struct task_struct *, int);
9671 +
9672 +
9673 +#else
9674 +#warning duplicate inclusion
9675 +#endif
9676 diff -NurpP --minimal linux-2.6.36/include/linux/vs_cowbl.h linux-2.6.36-vs2.3.0.36.33/include/linux/vs_cowbl.h
9677 --- linux-2.6.36/include/linux/vs_cowbl.h       1970-01-01 01:00:00.000000000 +0100
9678 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vs_cowbl.h 2010-10-21 13:09:36.000000000 +0200
9679 @@ -0,0 +1,48 @@
9680 +#ifndef _VS_COWBL_H
9681 +#define _VS_COWBL_H
9682 +
9683 +#include <linux/fs.h>
9684 +#include <linux/dcache.h>
9685 +#include <linux/namei.h>
9686 +#include <linux/slab.h>
9687 +
9688 +extern struct dentry *cow_break_link(const char *pathname);
9689 +
9690 +static inline int cow_check_and_break(struct path *path)
9691 +{
9692 +       struct inode *inode = path->dentry->d_inode;
9693 +       int error = 0;
9694 +
9695 +       /* do we need this check? */
9696 +       if (IS_RDONLY(inode))
9697 +               return -EROFS;
9698 +
9699 +       if (IS_COW(inode)) {
9700 +               if (IS_COW_LINK(inode)) {
9701 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
9702 +                       char *pp, *buf;
9703 +
9704 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
9705 +                       if (!buf) {
9706 +                               return -ENOMEM;
9707 +                       }
9708 +                       pp = d_path(path, buf, PATH_MAX);
9709 +                       new_dentry = cow_break_link(pp);
9710 +                       kfree(buf);
9711 +                       if (!IS_ERR(new_dentry)) {
9712 +                               path->dentry = new_dentry;
9713 +                               dput(old_dentry);
9714 +                       } else
9715 +                               error = PTR_ERR(new_dentry);
9716 +               } else {
9717 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
9718 +                       inode->i_ctime = CURRENT_TIME;
9719 +                       mark_inode_dirty(inode);
9720 +               }
9721 +       }
9722 +       return error;
9723 +}
9724 +
9725 +#else
9726 +#warning duplicate inclusion
9727 +#endif
9728 diff -NurpP --minimal linux-2.6.36/include/linux/vs_cvirt.h linux-2.6.36-vs2.3.0.36.33/include/linux/vs_cvirt.h
9729 --- linux-2.6.36/include/linux/vs_cvirt.h       1970-01-01 01:00:00.000000000 +0100
9730 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vs_cvirt.h 2010-10-21 13:09:36.000000000 +0200
9731 @@ -0,0 +1,50 @@
9732 +#ifndef _VS_CVIRT_H
9733 +#define _VS_CVIRT_H
9734 +
9735 +#include "vserver/cvirt.h"
9736 +#include "vserver/context.h"
9737 +#include "vserver/base.h"
9738 +#include "vserver/check.h"
9739 +#include "vserver/debug.h"
9740 +
9741 +
9742 +static inline void vx_activate_task(struct task_struct *p)
9743 +{
9744 +       struct vx_info *vxi;
9745 +
9746 +       if ((vxi = p->vx_info)) {
9747 +               vx_update_load(vxi);
9748 +               atomic_inc(&vxi->cvirt.nr_running);
9749 +       }
9750 +}
9751 +
9752 +static inline void vx_deactivate_task(struct task_struct *p)
9753 +{
9754 +       struct vx_info *vxi;
9755 +
9756 +       if ((vxi = p->vx_info)) {
9757 +               vx_update_load(vxi);
9758 +               atomic_dec(&vxi->cvirt.nr_running);
9759 +       }
9760 +}
9761 +
9762 +static inline void vx_uninterruptible_inc(struct task_struct *p)
9763 +{
9764 +       struct vx_info *vxi;
9765 +
9766 +       if ((vxi = p->vx_info))
9767 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
9768 +}
9769 +
9770 +static inline void vx_uninterruptible_dec(struct task_struct *p)
9771 +{
9772 +       struct vx_info *vxi;
9773 +
9774 +       if ((vxi = p->vx_info))
9775 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
9776 +}
9777 +
9778 +
9779 +#else
9780 +#warning duplicate inclusion
9781 +#endif
9782 diff -NurpP --minimal linux-2.6.36/include/linux/vs_device.h linux-2.6.36-vs2.3.0.36.33/include/linux/vs_device.h
9783 --- linux-2.6.36/include/linux/vs_device.h      1970-01-01 01:00:00.000000000 +0100
9784 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vs_device.h        2010-10-21 13:09:36.000000000 +0200
9785 @@ -0,0 +1,45 @@
9786 +#ifndef _VS_DEVICE_H
9787 +#define _VS_DEVICE_H
9788 +
9789 +#include "vserver/base.h"
9790 +#include "vserver/device.h"
9791 +#include "vserver/debug.h"
9792 +
9793 +
9794 +#ifdef CONFIG_VSERVER_DEVICE
9795 +
9796 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
9797 +
9798 +#define vs_device_perm(v, d, m, p) \
9799 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
9800 +
9801 +#else
9802 +
9803 +static inline
9804 +int vs_map_device(struct vx_info *vxi,
9805 +       dev_t device, dev_t *target, umode_t mode)
9806 +{
9807 +       if (target)
9808 +               *target = device;
9809 +       return ~0;
9810 +}
9811 +
9812 +#define vs_device_perm(v, d, m, p) ((p) == (p))
9813 +
9814 +#endif
9815 +
9816 +
9817 +#define vs_map_chrdev(d, t, p) \
9818 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
9819 +#define vs_map_blkdev(d, t, p) \
9820 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
9821 +
9822 +#define vs_chrdev_perm(d, p) \
9823 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
9824 +#define vs_blkdev_perm(d, p) \
9825 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
9826 +
9827 +
9828 +#else
9829 +#warning duplicate inclusion
9830 +#endif
9831 diff -NurpP --minimal linux-2.6.36/include/linux/vs_dlimit.h linux-2.6.36-vs2.3.0.36.33/include/linux/vs_dlimit.h
9832 --- linux-2.6.36/include/linux/vs_dlimit.h      1970-01-01 01:00:00.000000000 +0100
9833 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vs_dlimit.h        2010-10-21 13:09:36.000000000 +0200
9834 @@ -0,0 +1,215 @@
9835 +#ifndef _VS_DLIMIT_H
9836 +#define _VS_DLIMIT_H
9837 +
9838 +#include <linux/fs.h>
9839 +
9840 +#include "vserver/dlimit.h"
9841 +#include "vserver/base.h"
9842 +#include "vserver/debug.h"
9843 +
9844 +
9845 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
9846 +
9847 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
9848 +       const char *_file, int _line)
9849 +{
9850 +       if (!dli)
9851 +               return NULL;
9852 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
9853 +               dli, dli ? dli->dl_tag : 0,
9854 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9855 +               _file, _line);
9856 +       atomic_inc(&dli->dl_usecnt);
9857 +       return dli;
9858 +}
9859 +
9860 +
9861 +#define free_dl_info(i) \
9862 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
9863 +
9864 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
9865 +
9866 +static inline void __put_dl_info(struct dl_info *dli,
9867 +       const char *_file, int _line)
9868 +{
9869 +       if (!dli)
9870 +               return;
9871 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
9872 +               dli, dli ? dli->dl_tag : 0,
9873 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
9874 +               _file, _line);
9875 +       if (atomic_dec_and_test(&dli->dl_usecnt))
9876 +               free_dl_info(dli);
9877 +}
9878 +
9879 +
9880 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
9881 +
9882 +static inline int __dl_alloc_space(struct super_block *sb,
9883 +       tag_t tag, dlsize_t nr, const char *file, int line)
9884 +{
9885 +       struct dl_info *dli = NULL;
9886 +       int ret = 0;
9887 +
9888 +       if (nr == 0)
9889 +               goto out;
9890 +       dli = locate_dl_info(sb, tag);
9891 +       if (!dli)
9892 +               goto out;
9893 +
9894 +       spin_lock(&dli->dl_lock);
9895 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
9896 +       if (!ret)
9897 +               dli->dl_space_used += nr;
9898 +       spin_unlock(&dli->dl_lock);
9899 +       put_dl_info(dli);
9900 +out:
9901 +       vxlprintk(VXD_CBIT(dlim, 1),
9902 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
9903 +               sb, tag, __dlimit_char(dli), (long long)nr,
9904 +               ret, file, line);
9905 +       return ret ? -ENOSPC : 0;
9906 +}
9907 +
9908 +static inline void __dl_free_space(struct super_block *sb,
9909 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
9910 +{
9911 +       struct dl_info *dli = NULL;
9912 +
9913 +       if (nr == 0)
9914 +               goto out;
9915 +       dli = locate_dl_info(sb, tag);
9916 +       if (!dli)
9917 +               goto out;
9918 +
9919 +       spin_lock(&dli->dl_lock);
9920 +       if (dli->dl_space_used > nr)
9921 +               dli->dl_space_used -= nr;
9922 +       else
9923 +               dli->dl_space_used = 0;
9924 +       spin_unlock(&dli->dl_lock);
9925 +       put_dl_info(dli);
9926 +out:
9927 +       vxlprintk(VXD_CBIT(dlim, 1),
9928 +               "FREE  (%p,#%d)%c %lld bytes",
9929 +               sb, tag, __dlimit_char(dli), (long long)nr,
9930 +               _file, _line);
9931 +}
9932 +
9933 +static inline int __dl_alloc_inode(struct super_block *sb,
9934 +       tag_t tag, const char *_file, int _line)
9935 +{
9936 +       struct dl_info *dli;
9937 +       int ret = 0;
9938 +
9939 +       dli = locate_dl_info(sb, tag);
9940 +       if (!dli)
9941 +               goto out;
9942 +
9943 +       spin_lock(&dli->dl_lock);
9944 +       dli->dl_inodes_used++;
9945 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
9946 +       spin_unlock(&dli->dl_lock);
9947 +       put_dl_info(dli);
9948 +out:
9949 +       vxlprintk(VXD_CBIT(dlim, 0),
9950 +               "ALLOC (%p,#%d)%c inode (%d)",
9951 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
9952 +       return ret ? -ENOSPC : 0;
9953 +}
9954 +
9955 +static inline void __dl_free_inode(struct super_block *sb,
9956 +       tag_t tag, const char *_file, int _line)
9957 +{
9958 +       struct dl_info *dli;
9959 +
9960 +       dli = locate_dl_info(sb, tag);
9961 +       if (!dli)
9962 +               goto out;
9963 +
9964 +       spin_lock(&dli->dl_lock);
9965 +       if (dli->dl_inodes_used > 1)
9966 +               dli->dl_inodes_used--;
9967 +       else
9968 +               dli->dl_inodes_used = 0;
9969 +       spin_unlock(&dli->dl_lock);
9970 +       put_dl_info(dli);
9971 +out:
9972 +       vxlprintk(VXD_CBIT(dlim, 0),
9973 +               "FREE  (%p,#%d)%c inode",
9974 +               sb, tag, __dlimit_char(dli), _file, _line);
9975 +}
9976 +
9977 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
9978 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
9979 +       const char *_file, int _line)
9980 +{
9981 +       struct dl_info *dli;
9982 +       uint64_t broot, bfree;
9983 +
9984 +       dli = locate_dl_info(sb, tag);
9985 +       if (!dli)
9986 +               return;
9987 +
9988 +       spin_lock(&dli->dl_lock);
9989 +       broot = (dli->dl_space_total -
9990 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
9991 +               >> sb->s_blocksize_bits;
9992 +       bfree = (dli->dl_space_total - dli->dl_space_used)
9993 +                       >> sb->s_blocksize_bits;
9994 +       spin_unlock(&dli->dl_lock);
9995 +
9996 +       vxlprintk(VXD_CBIT(dlim, 2),
9997 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
9998 +               (long long)bfree, (long long)broot,
9999 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
10000 +               _file, _line);
10001 +       if (free_blocks) {
10002 +               if (*free_blocks > bfree)
10003 +                       *free_blocks = bfree;
10004 +       }
10005 +       if (root_blocks) {
10006 +               if (*root_blocks > broot)
10007 +                       *root_blocks = broot;
10008 +       }
10009 +       put_dl_info(dli);
10010 +}
10011 +
10012 +#define dl_prealloc_space(in, bytes) \
10013 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10014 +               __FILE__, __LINE__ )
10015 +
10016 +#define dl_alloc_space(in, bytes) \
10017 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10018 +               __FILE__, __LINE__ )
10019 +
10020 +#define dl_reserve_space(in, bytes) \
10021 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10022 +               __FILE__, __LINE__ )
10023 +
10024 +#define dl_claim_space(in, bytes) (0)
10025 +
10026 +#define dl_release_space(in, bytes) \
10027 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10028 +               __FILE__, __LINE__ )
10029 +
10030 +#define dl_free_space(in, bytes) \
10031 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10032 +               __FILE__, __LINE__ )
10033 +
10034 +
10035 +
10036 +#define dl_alloc_inode(in) \
10037 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10038 +
10039 +#define dl_free_inode(in) \
10040 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10041 +
10042 +
10043 +#define dl_adjust_block(sb, tag, fb, rb) \
10044 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
10045 +
10046 +
10047 +#else
10048 +#warning duplicate inclusion
10049 +#endif
10050 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/base.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/base.h
10051 --- linux-2.6.36/include/linux/vserver/base.h   1970-01-01 01:00:00.000000000 +0100
10052 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/base.h     2010-10-21 13:09:36.000000000 +0200
10053 @@ -0,0 +1,170 @@
10054 +#ifndef _VX_BASE_H
10055 +#define _VX_BASE_H
10056 +
10057 +
10058 +/* context state changes */
10059 +
10060 +enum {
10061 +       VSC_STARTUP = 1,
10062 +       VSC_SHUTDOWN,
10063 +
10064 +       VSC_NETUP,
10065 +       VSC_NETDOWN,
10066 +};
10067 +
10068 +
10069 +
10070 +#define vx_task_xid(t) ((t)->xid)
10071 +
10072 +#define vx_current_xid() vx_task_xid(current)
10073 +
10074 +#define current_vx_info() (current->vx_info)
10075 +
10076 +
10077 +#define nx_task_nid(t) ((t)->nid)
10078 +
10079 +#define nx_current_nid() nx_task_nid(current)
10080 +
10081 +#define current_nx_info() (current->nx_info)
10082 +
10083 +
10084 +/* generic flag merging */
10085 +
10086 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10087 +
10088 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10089 +
10090 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10091 +
10092 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10093 +
10094 +
10095 +/* context flags */
10096 +
10097 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10098 +
10099 +#define vx_current_flags()     __vx_flags(current_vx_info())
10100 +
10101 +#define vx_info_flags(v, m, f) \
10102 +       vs_check_flags(__vx_flags(v), m, f)
10103 +
10104 +#define task_vx_flags(t, m, f) \
10105 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10106 +
10107 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10108 +
10109 +
10110 +/* context caps */
10111 +
10112 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10113 +
10114 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
10115 +
10116 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10117 +
10118 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
10119 +
10120 +
10121 +
10122 +/* network flags */
10123 +
10124 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10125 +
10126 +#define nx_current_flags()     __nx_flags(current_nx_info())
10127 +
10128 +#define nx_info_flags(n, m, f) \
10129 +       vs_check_flags(__nx_flags(n), m, f)
10130 +
10131 +#define task_nx_flags(t, m, f) \
10132 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10133 +
10134 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10135 +
10136 +
10137 +/* network caps */
10138 +
10139 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10140 +
10141 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
10142 +
10143 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10144 +
10145 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
10146 +
10147 +
10148 +/* context mask capabilities */
10149 +
10150 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10151 +
10152 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10153 +
10154 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
10155 +
10156 +
10157 +/* context bcap mask */
10158 +
10159 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10160 +
10161 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
10162 +
10163 +
10164 +/* mask given bcaps */
10165 +
10166 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10167 +
10168 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
10169 +
10170 +
10171 +/* masked cap_bset */
10172 +
10173 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10174 +
10175 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
10176 +
10177 +#if 0
10178 +#define vx_info_mbcap(v, b) \
10179 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10180 +       vx_info_bcaps(v, b) : (b))
10181 +
10182 +#define task_vx_mbcap(t, b) \
10183 +       vx_info_mbcap((t)->vx_info, (t)->b)
10184 +
10185 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10186 +#endif
10187 +
10188 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10189 +
10190 +#define vx_capable(b, c) (capable(b) || \
10191 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10192 +
10193 +#define nx_capable(b, c) (capable(b) || \
10194 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10195 +
10196 +#define vx_task_initpid(t, n) \
10197 +       ((t)->vx_info && \
10198 +       ((t)->vx_info->vx_initpid == (n)))
10199 +
10200 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
10201 +
10202 +
10203 +/* context unshare mask */
10204 +
10205 +#define __vx_umask(v)          ((v)->vx_umask)
10206 +
10207 +#define vx_current_umask()     __vx_umask(current_vx_info())
10208 +
10209 +#define vx_can_unshare(b, f) (capable(b) || \
10210 +       (cap_raised(current_cap(), b) && \
10211 +       !((f) & ~vx_current_umask())))
10212 +
10213 +
10214 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10215 +
10216 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10217 +
10218 +
10219 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10220 +
10221 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10222 +
10223 +#endif
10224 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/cacct_cmd.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/cacct_cmd.h
10225 --- linux-2.6.36/include/linux/vserver/cacct_cmd.h      1970-01-01 01:00:00.000000000 +0100
10226 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/cacct_cmd.h        2010-10-21 13:09:36.000000000 +0200
10227 @@ -0,0 +1,23 @@
10228 +#ifndef _VX_CACCT_CMD_H
10229 +#define _VX_CACCT_CMD_H
10230 +
10231 +
10232 +/* virtual host info name commands */
10233 +
10234 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
10235 +
10236 +struct vcmd_sock_stat_v0 {
10237 +       uint32_t field;
10238 +       uint32_t count[3];
10239 +       uint64_t total[3];
10240 +};
10241 +
10242 +
10243 +#ifdef __KERNEL__
10244 +
10245 +#include <linux/compiler.h>
10246 +
10247 +extern int vc_sock_stat(struct vx_info *, void __user *);
10248 +
10249 +#endif /* __KERNEL__ */
10250 +#endif /* _VX_CACCT_CMD_H */
10251 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/cacct_def.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/cacct_def.h
10252 --- linux-2.6.36/include/linux/vserver/cacct_def.h      1970-01-01 01:00:00.000000000 +0100
10253 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/cacct_def.h        2010-10-21 13:09:36.000000000 +0200
10254 @@ -0,0 +1,43 @@
10255 +#ifndef _VX_CACCT_DEF_H
10256 +#define _VX_CACCT_DEF_H
10257 +
10258 +#include <asm/atomic.h>
10259 +#include <linux/vserver/cacct.h>
10260 +
10261 +
10262 +struct _vx_sock_acc {
10263 +       atomic_long_t count;
10264 +       atomic_long_t total;
10265 +};
10266 +
10267 +/* context sub struct */
10268 +
10269 +struct _vx_cacct {
10270 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10271 +       atomic_t slab[8];
10272 +       atomic_t page[6][8];
10273 +};
10274 +
10275 +#ifdef CONFIG_VSERVER_DEBUG
10276 +
10277 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10278 +{
10279 +       int i, j;
10280 +
10281 +       printk("\t_vx_cacct:");
10282 +       for (i = 0; i < 6; i++) {
10283 +               struct _vx_sock_acc *ptr = cacct->sock[i];
10284 +
10285 +               printk("\t [%d] =", i);
10286 +               for (j = 0; j < 3; j++) {
10287 +                       printk(" [%d] = %8lu, %8lu", j,
10288 +                               atomic_long_read(&ptr[j].count),
10289 +                               atomic_long_read(&ptr[j].total));
10290 +               }
10291 +               printk("\n");
10292 +       }
10293 +}
10294 +
10295 +#endif
10296 +
10297 +#endif /* _VX_CACCT_DEF_H */
10298 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/cacct.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/cacct.h
10299 --- linux-2.6.36/include/linux/vserver/cacct.h  1970-01-01 01:00:00.000000000 +0100
10300 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/cacct.h    2010-10-21 13:09:36.000000000 +0200
10301 @@ -0,0 +1,15 @@
10302 +#ifndef _VX_CACCT_H
10303 +#define _VX_CACCT_H
10304 +
10305 +
10306 +enum sock_acc_field {
10307 +       VXA_SOCK_UNSPEC = 0,
10308 +       VXA_SOCK_UNIX,
10309 +       VXA_SOCK_INET,
10310 +       VXA_SOCK_INET6,
10311 +       VXA_SOCK_PACKET,
10312 +       VXA_SOCK_OTHER,
10313 +       VXA_SOCK_SIZE   /* array size */
10314 +};
10315 +
10316 +#endif /* _VX_CACCT_H */
10317 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/cacct_int.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/cacct_int.h
10318 --- linux-2.6.36/include/linux/vserver/cacct_int.h      1970-01-01 01:00:00.000000000 +0100
10319 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/cacct_int.h        2010-10-21 13:09:36.000000000 +0200
10320 @@ -0,0 +1,21 @@
10321 +#ifndef _VX_CACCT_INT_H
10322 +#define _VX_CACCT_INT_H
10323 +
10324 +
10325 +#ifdef __KERNEL__
10326 +
10327 +static inline
10328 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10329 +{
10330 +       return atomic_long_read(&cacct->sock[type][pos].count);
10331 +}
10332 +
10333 +
10334 +static inline
10335 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10336 +{
10337 +       return atomic_long_read(&cacct->sock[type][pos].total);
10338 +}
10339 +
10340 +#endif /* __KERNEL__ */
10341 +#endif /* _VX_CACCT_INT_H */
10342 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/check.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/check.h
10343 --- linux-2.6.36/include/linux/vserver/check.h  1970-01-01 01:00:00.000000000 +0100
10344 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/check.h    2010-10-21 13:09:36.000000000 +0200
10345 @@ -0,0 +1,89 @@
10346 +#ifndef _VS_CHECK_H
10347 +#define _VS_CHECK_H
10348 +
10349 +
10350 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
10351 +
10352 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10353 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
10354 +#else
10355 +#define MIN_D_CONTEXT  65536
10356 +#endif
10357 +
10358 +/* check conditions */
10359 +
10360 +#define VS_ADMIN       0x0001
10361 +#define VS_WATCH       0x0002
10362 +#define VS_HIDE                0x0004
10363 +#define VS_HOSTID      0x0008
10364 +
10365 +#define VS_IDENT       0x0010
10366 +#define VS_EQUIV       0x0020
10367 +#define VS_PARENT      0x0040
10368 +#define VS_CHILD       0x0080
10369 +
10370 +#define VS_ARG_MASK    0x00F0
10371 +
10372 +#define VS_DYNAMIC     0x0100
10373 +#define VS_STATIC      0x0200
10374 +
10375 +#define VS_ATR_MASK    0x0F00
10376 +
10377 +#ifdef CONFIG_VSERVER_PRIVACY
10378 +#define VS_ADMIN_P     (0)
10379 +#define VS_WATCH_P     (0)
10380 +#else
10381 +#define VS_ADMIN_P     VS_ADMIN
10382 +#define VS_WATCH_P     VS_WATCH
10383 +#endif
10384 +
10385 +#define VS_HARDIRQ     0x1000
10386 +#define VS_SOFTIRQ     0x2000
10387 +#define VS_IRQ         0x4000
10388 +
10389 +#define VS_IRQ_MASK    0xF000
10390 +
10391 +#include <linux/hardirq.h>
10392 +
10393 +/*
10394 + * check current context for ADMIN/WATCH and
10395 + * optionally against supplied argument
10396 + */
10397 +static inline int __vs_check(int cid, int id, unsigned int mode)
10398 +{
10399 +       if (mode & VS_ARG_MASK) {
10400 +               if ((mode & VS_IDENT) && (id == cid))
10401 +                       return 1;
10402 +       }
10403 +       if (mode & VS_ATR_MASK) {
10404 +               if ((mode & VS_DYNAMIC) &&
10405 +                       (id >= MIN_D_CONTEXT) &&
10406 +                       (id <= MAX_S_CONTEXT))
10407 +                       return 1;
10408 +               if ((mode & VS_STATIC) &&
10409 +                       (id > 1) && (id < MIN_D_CONTEXT))
10410 +                       return 1;
10411 +       }
10412 +       if (mode & VS_IRQ_MASK) {
10413 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
10414 +                       return 1;
10415 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
10416 +                       return 1;
10417 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
10418 +                       return 1;
10419 +       }
10420 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
10421 +               ((mode & VS_WATCH) && (cid == 1)) ||
10422 +               ((mode & VS_HOSTID) && (id == 0)));
10423 +}
10424 +
10425 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
10426 +
10427 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
10428 +
10429 +
10430 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
10431 +
10432 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
10433 +
10434 +#endif
10435 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/context_cmd.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/context_cmd.h
10436 --- linux-2.6.36/include/linux/vserver/context_cmd.h    1970-01-01 01:00:00.000000000 +0100
10437 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/context_cmd.h      2010-10-21 13:09:36.000000000 +0200
10438 @@ -0,0 +1,145 @@
10439 +#ifndef _VX_CONTEXT_CMD_H
10440 +#define _VX_CONTEXT_CMD_H
10441 +
10442 +
10443 +/* vinfo commands */
10444 +
10445 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
10446 +
10447 +#ifdef __KERNEL__
10448 +extern int vc_task_xid(uint32_t);
10449 +
10450 +#endif /* __KERNEL__ */
10451 +
10452 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
10453 +
10454 +struct vcmd_vx_info_v0 {
10455 +       uint32_t xid;
10456 +       uint32_t initpid;
10457 +       /* more to come */
10458 +};
10459 +
10460 +#ifdef __KERNEL__
10461 +extern int vc_vx_info(struct vx_info *, void __user *);
10462 +
10463 +#endif /* __KERNEL__ */
10464 +
10465 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
10466 +
10467 +struct vcmd_ctx_stat_v0 {
10468 +       uint32_t usecnt;
10469 +       uint32_t tasks;
10470 +       /* more to come */
10471 +};
10472 +
10473 +#ifdef __KERNEL__
10474 +extern int vc_ctx_stat(struct vx_info *, void __user *);
10475 +
10476 +#endif /* __KERNEL__ */
10477 +
10478 +/* context commands */
10479 +
10480 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
10481 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
10482 +
10483 +struct vcmd_ctx_create {
10484 +       uint64_t flagword;
10485 +};
10486 +
10487 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
10488 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
10489 +
10490 +struct vcmd_ctx_migrate {
10491 +       uint64_t flagword;
10492 +};
10493 +
10494 +#ifdef __KERNEL__
10495 +extern int vc_ctx_create(uint32_t, void __user *);
10496 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
10497 +
10498 +#endif /* __KERNEL__ */
10499 +
10500 +
10501 +/* flag commands */
10502 +
10503 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
10504 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
10505 +
10506 +struct vcmd_ctx_flags_v0 {
10507 +       uint64_t flagword;
10508 +       uint64_t mask;
10509 +};
10510 +
10511 +#ifdef __KERNEL__
10512 +extern int vc_get_cflags(struct vx_info *, void __user *);
10513 +extern int vc_set_cflags(struct vx_info *, void __user *);
10514 +
10515 +#endif /* __KERNEL__ */
10516 +
10517 +
10518 +/* context caps commands */
10519 +
10520 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
10521 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
10522 +
10523 +struct vcmd_ctx_caps_v1 {
10524 +       uint64_t ccaps;
10525 +       uint64_t cmask;
10526 +};
10527 +
10528 +#ifdef __KERNEL__
10529 +extern int vc_get_ccaps(struct vx_info *, void __user *);
10530 +extern int vc_set_ccaps(struct vx_info *, void __user *);
10531 +
10532 +#endif /* __KERNEL__ */
10533 +
10534 +
10535 +/* bcaps commands */
10536 +
10537 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
10538 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
10539 +
10540 +struct vcmd_bcaps {
10541 +       uint64_t bcaps;
10542 +       uint64_t bmask;
10543 +};
10544 +
10545 +#ifdef __KERNEL__
10546 +extern int vc_get_bcaps(struct vx_info *, void __user *);
10547 +extern int vc_set_bcaps(struct vx_info *, void __user *);
10548 +
10549 +#endif /* __KERNEL__ */
10550 +
10551 +
10552 +/* umask commands */
10553 +
10554 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
10555 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
10556 +
10557 +struct vcmd_umask {
10558 +       uint64_t umask;
10559 +       uint64_t mask;
10560 +};
10561 +
10562 +#ifdef __KERNEL__
10563 +extern int vc_get_umask(struct vx_info *, void __user *);
10564 +extern int vc_set_umask(struct vx_info *, void __user *);
10565 +
10566 +#endif /* __KERNEL__ */
10567 +
10568 +
10569 +/* OOM badness */
10570 +
10571 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
10572 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
10573 +
10574 +struct vcmd_badness_v0 {
10575 +       int64_t bias;
10576 +};
10577 +
10578 +#ifdef __KERNEL__
10579 +extern int vc_get_badness(struct vx_info *, void __user *);
10580 +extern int vc_set_badness(struct vx_info *, void __user *);
10581 +
10582 +#endif /* __KERNEL__ */
10583 +#endif /* _VX_CONTEXT_CMD_H */
10584 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/context.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/context.h
10585 --- linux-2.6.36/include/linux/vserver/context.h        1970-01-01 01:00:00.000000000 +0100
10586 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/context.h  2010-10-21 13:09:36.000000000 +0200
10587 @@ -0,0 +1,184 @@
10588 +#ifndef _VX_CONTEXT_H
10589 +#define _VX_CONTEXT_H
10590 +
10591 +#include <linux/types.h>
10592 +#include <linux/capability.h>
10593 +
10594 +
10595 +/* context flags */
10596 +
10597 +#define VXF_INFO_SCHED         0x00000002
10598 +#define VXF_INFO_NPROC         0x00000004
10599 +#define VXF_INFO_PRIVATE       0x00000008
10600 +
10601 +#define VXF_INFO_INIT          0x00000010
10602 +#define VXF_INFO_HIDE          0x00000020
10603 +#define VXF_INFO_ULIMIT                0x00000040
10604 +#define VXF_INFO_NSPACE                0x00000080
10605 +
10606 +#define VXF_SCHED_HARD         0x00000100
10607 +#define VXF_SCHED_PRIO         0x00000200
10608 +#define VXF_SCHED_PAUSE                0x00000400
10609 +
10610 +#define VXF_VIRT_MEM           0x00010000
10611 +#define VXF_VIRT_UPTIME                0x00020000
10612 +#define VXF_VIRT_CPU           0x00040000
10613 +#define VXF_VIRT_LOAD          0x00080000
10614 +#define VXF_VIRT_TIME          0x00100000
10615 +
10616 +#define VXF_HIDE_MOUNT         0x01000000
10617 +/* was VXF_HIDE_NETIF          0x02000000 */
10618 +#define VXF_HIDE_VINFO         0x04000000
10619 +
10620 +#define VXF_STATE_SETUP                (1ULL << 32)
10621 +#define VXF_STATE_INIT         (1ULL << 33)
10622 +#define VXF_STATE_ADMIN                (1ULL << 34)
10623 +
10624 +#define VXF_SC_HELPER          (1ULL << 36)
10625 +#define VXF_REBOOT_KILL                (1ULL << 37)
10626 +#define VXF_PERSISTENT         (1ULL << 38)
10627 +
10628 +#define VXF_FORK_RSS           (1ULL << 48)
10629 +#define VXF_PROLIFIC           (1ULL << 49)
10630 +
10631 +#define VXF_IGNEG_NICE         (1ULL << 52)
10632 +
10633 +#define VXF_ONE_TIME           (0x0007ULL << 32)
10634 +
10635 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
10636 +
10637 +
10638 +/* context migration */
10639 +
10640 +#define VXM_SET_INIT           0x00000001
10641 +#define VXM_SET_REAPER         0x00000002
10642 +
10643 +/* context caps */
10644 +
10645 +#define VXC_CAP_MASK           0x00000000
10646 +
10647 +#define VXC_SET_UTSNAME                0x00000001
10648 +#define VXC_SET_RLIMIT         0x00000002
10649 +#define VXC_FS_SECURITY                0x00000004
10650 +#define VXC_FS_TRUSTED         0x00000008
10651 +#define VXC_TIOCSTI            0x00000010
10652 +
10653 +/* was VXC_RAW_ICMP            0x00000100 */
10654 +#define VXC_SYSLOG             0x00001000
10655 +#define VXC_OOM_ADJUST         0x00002000
10656 +#define VXC_AUDIT_CONTROL      0x00004000
10657 +
10658 +#define VXC_SECURE_MOUNT       0x00010000
10659 +#define VXC_SECURE_REMOUNT     0x00020000
10660 +#define VXC_BINARY_MOUNT       0x00040000
10661 +
10662 +#define VXC_QUOTA_CTL          0x00100000
10663 +#define VXC_ADMIN_MAPPER       0x00200000
10664 +#define VXC_ADMIN_CLOOP                0x00400000
10665 +
10666 +#define VXC_KTHREAD            0x01000000
10667 +#define VXC_NAMESPACE          0x02000000
10668 +
10669 +
10670 +#ifdef __KERNEL__
10671 +
10672 +#include <linux/list.h>
10673 +#include <linux/spinlock.h>
10674 +#include <linux/rcupdate.h>
10675 +
10676 +#include "limit_def.h"
10677 +#include "sched_def.h"
10678 +#include "cvirt_def.h"
10679 +#include "cacct_def.h"
10680 +#include "device_def.h"
10681 +
10682 +#define VX_SPACES      2
10683 +
10684 +struct _vx_info_pc {
10685 +       struct _vx_sched_pc sched_pc;
10686 +       struct _vx_cvirt_pc cvirt_pc;
10687 +};
10688 +
10689 +struct vx_info {
10690 +       struct hlist_node vx_hlist;             /* linked list of contexts */
10691 +       xid_t vx_id;                            /* context id */
10692 +       atomic_t vx_usecnt;                     /* usage count */
10693 +       atomic_t vx_tasks;                      /* tasks count */
10694 +       struct vx_info *vx_parent;              /* parent context */
10695 +       int vx_state;                           /* context state */
10696 +
10697 +       unsigned long vx_nsmask[VX_SPACES];     /* assignment mask */
10698 +       struct nsproxy *vx_nsproxy[VX_SPACES];  /* private namespaces */
10699 +       struct fs_struct *vx_fs[VX_SPACES];     /* private namespace fs */
10700 +
10701 +       uint64_t vx_flags;                      /* context flags */
10702 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
10703 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
10704 +       unsigned long vx_umask;                 /* unshare mask (guest) */
10705 +
10706 +       struct task_struct *vx_reaper;          /* guest reaper process */
10707 +       pid_t vx_initpid;                       /* PID of guest init */
10708 +       int64_t vx_badness_bias;                /* OOM points bias */
10709 +
10710 +       struct _vx_limit limit;                 /* vserver limits */
10711 +       struct _vx_sched sched;                 /* vserver scheduler */
10712 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
10713 +       struct _vx_cacct cacct;                 /* context accounting */
10714 +
10715 +       struct _vx_device dmap;                 /* default device map targets */
10716 +
10717 +#ifndef CONFIG_SMP
10718 +       struct _vx_info_pc info_pc;             /* per cpu data */
10719 +#else
10720 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
10721 +#endif
10722 +
10723 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
10724 +       int reboot_cmd;                         /* last sys_reboot() cmd */
10725 +       int exit_code;                          /* last process exit code */
10726 +
10727 +       char vx_name[65];                       /* vserver name */
10728 +};
10729 +
10730 +#ifndef CONFIG_SMP
10731 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
10732 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
10733 +#else
10734 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
10735 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
10736 +#endif
10737 +
10738 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
10739 +
10740 +
10741 +struct vx_info_save {
10742 +       struct vx_info *vxi;
10743 +       xid_t xid;
10744 +};
10745 +
10746 +
10747 +/* status flags */
10748 +
10749 +#define VXS_HASHED     0x0001
10750 +#define VXS_PAUSED     0x0010
10751 +#define VXS_SHUTDOWN   0x0100
10752 +#define VXS_HELPER     0x1000
10753 +#define VXS_RELEASED   0x8000
10754 +
10755 +
10756 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
10757 +extern void release_vx_info(struct vx_info *, struct task_struct *);
10758 +
10759 +extern struct vx_info *lookup_vx_info(int);
10760 +extern struct vx_info *lookup_or_create_vx_info(int);
10761 +
10762 +extern int get_xid_list(int, unsigned int *, int);
10763 +extern int xid_is_hashed(xid_t);
10764 +
10765 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
10766 +
10767 +extern long vs_state_change(struct vx_info *, unsigned int);
10768 +
10769 +
10770 +#endif /* __KERNEL__ */
10771 +#endif /* _VX_CONTEXT_H */
10772 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/cvirt_cmd.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/cvirt_cmd.h
10773 --- linux-2.6.36/include/linux/vserver/cvirt_cmd.h      1970-01-01 01:00:00.000000000 +0100
10774 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/cvirt_cmd.h        2010-10-21 13:09:36.000000000 +0200
10775 @@ -0,0 +1,53 @@
10776 +#ifndef _VX_CVIRT_CMD_H
10777 +#define _VX_CVIRT_CMD_H
10778 +
10779 +
10780 +/* virtual host info name commands */
10781 +
10782 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
10783 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
10784 +
10785 +struct vcmd_vhi_name_v0 {
10786 +       uint32_t field;
10787 +       char name[65];
10788 +};
10789 +
10790 +
10791 +enum vhi_name_field {
10792 +       VHIN_CONTEXT = 0,
10793 +       VHIN_SYSNAME,
10794 +       VHIN_NODENAME,
10795 +       VHIN_RELEASE,
10796 +       VHIN_VERSION,
10797 +       VHIN_MACHINE,
10798 +       VHIN_DOMAINNAME,
10799 +};
10800 +
10801 +
10802 +#ifdef __KERNEL__
10803 +
10804 +#include <linux/compiler.h>
10805 +
10806 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
10807 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
10808 +
10809 +#endif /* __KERNEL__ */
10810 +
10811 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
10812 +
10813 +struct vcmd_virt_stat_v0 {
10814 +       uint64_t offset;
10815 +       uint64_t uptime;
10816 +       uint32_t nr_threads;
10817 +       uint32_t nr_running;
10818 +       uint32_t nr_uninterruptible;
10819 +       uint32_t nr_onhold;
10820 +       uint32_t nr_forks;
10821 +       uint32_t load[3];
10822 +};
10823 +
10824 +#ifdef __KERNEL__
10825 +extern int vc_virt_stat(struct vx_info *, void __user *);
10826 +
10827 +#endif /* __KERNEL__ */
10828 +#endif /* _VX_CVIRT_CMD_H */
10829 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/cvirt_def.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/cvirt_def.h
10830 --- linux-2.6.36/include/linux/vserver/cvirt_def.h      1970-01-01 01:00:00.000000000 +0100
10831 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/cvirt_def.h        2010-10-21 14:26:47.000000000 +0200
10832 @@ -0,0 +1,80 @@
10833 +#ifndef _VX_CVIRT_DEF_H
10834 +#define _VX_CVIRT_DEF_H
10835 +
10836 +#include <linux/jiffies.h>
10837 +#include <linux/spinlock.h>
10838 +#include <linux/wait.h>
10839 +#include <linux/time.h>
10840 +#include <asm/atomic.h>
10841 +
10842 +
10843 +struct _vx_usage_stat {
10844 +       uint64_t user;
10845 +       uint64_t nice;
10846 +       uint64_t system;
10847 +       uint64_t softirq;
10848 +       uint64_t irq;
10849 +       uint64_t idle;
10850 +       uint64_t iowait;
10851 +};
10852 +
10853 +struct _vx_syslog {
10854 +       wait_queue_head_t log_wait;
10855 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
10856 +
10857 +       unsigned long log_start;        /* next char to be read by syslog() */
10858 +       unsigned long con_start;        /* next char to be sent to consoles */
10859 +       unsigned long log_end;  /* most-recently-written-char + 1 */
10860 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
10861 +
10862 +       char log_buf[1024];
10863 +};
10864 +
10865 +
10866 +/* context sub struct */
10867 +
10868 +struct _vx_cvirt {
10869 +       atomic_t nr_threads;            /* number of current threads */
10870 +       atomic_t nr_running;            /* number of running threads */
10871 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
10872 +
10873 +       atomic_t nr_onhold;             /* processes on hold */
10874 +       uint32_t onhold_last;           /* jiffies when put on hold */
10875 +
10876 +       struct timespec bias_ts;        /* time offset to the host */
10877 +       struct timespec bias_idle;
10878 +       struct timespec bias_uptime;    /* context creation point */
10879 +       uint64_t bias_clock;            /* offset in clock_t */
10880 +
10881 +       spinlock_t load_lock;           /* lock for the load averages */
10882 +       atomic_t load_updates;          /* nr of load updates done so far */
10883 +       uint32_t load_last;             /* last time load was calculated */
10884 +       uint32_t load[3];               /* load averages 1,5,15 */
10885 +
10886 +       atomic_t total_forks;           /* number of forks so far */
10887 +
10888 +       struct _vx_syslog syslog;
10889 +};
10890 +
10891 +struct _vx_cvirt_pc {
10892 +       struct _vx_usage_stat cpustat;
10893 +};
10894 +
10895 +
10896 +#ifdef CONFIG_VSERVER_DEBUG
10897 +
10898 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
10899 +{
10900 +       printk("\t_vx_cvirt:\n");
10901 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
10902 +               atomic_read(&cvirt->nr_threads),
10903 +               atomic_read(&cvirt->nr_running),
10904 +               atomic_read(&cvirt->nr_uninterruptible),
10905 +               atomic_read(&cvirt->nr_onhold));
10906 +       /* add rest here */
10907 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
10908 +}
10909 +
10910 +#endif
10911 +
10912 +#endif /* _VX_CVIRT_DEF_H */
10913 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/cvirt.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/cvirt.h
10914 --- linux-2.6.36/include/linux/vserver/cvirt.h  1970-01-01 01:00:00.000000000 +0100
10915 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/cvirt.h    2010-10-21 13:09:36.000000000 +0200
10916 @@ -0,0 +1,20 @@
10917 +#ifndef _VX_CVIRT_H
10918 +#define _VX_CVIRT_H
10919 +
10920 +
10921 +#ifdef __KERNEL__
10922 +
10923 +struct timespec;
10924 +
10925 +void vx_vsi_uptime(struct timespec *, struct timespec *);
10926 +
10927 +
10928 +struct vx_info;
10929 +
10930 +void vx_update_load(struct vx_info *);
10931 +
10932 +
10933 +int vx_do_syslog(int, char __user *, int);
10934 +
10935 +#endif /* __KERNEL__ */
10936 +#endif /* _VX_CVIRT_H */
10937 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/debug_cmd.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/debug_cmd.h
10938 --- linux-2.6.36/include/linux/vserver/debug_cmd.h      1970-01-01 01:00:00.000000000 +0100
10939 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/debug_cmd.h        2010-10-21 13:09:36.000000000 +0200
10940 @@ -0,0 +1,58 @@
10941 +#ifndef _VX_DEBUG_CMD_H
10942 +#define _VX_DEBUG_CMD_H
10943 +
10944 +
10945 +/* debug commands */
10946 +
10947 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
10948 +
10949 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
10950 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
10951 +
10952 +struct  vcmd_read_history_v0 {
10953 +       uint32_t index;
10954 +       uint32_t count;
10955 +       char __user *data;
10956 +};
10957 +
10958 +struct  vcmd_read_monitor_v0 {
10959 +       uint32_t index;
10960 +       uint32_t count;
10961 +       char __user *data;
10962 +};
10963 +
10964 +
10965 +#ifdef __KERNEL__
10966 +
10967 +#ifdef CONFIG_COMPAT
10968 +
10969 +#include <asm/compat.h>
10970 +
10971 +struct vcmd_read_history_v0_x32 {
10972 +       uint32_t index;
10973 +       uint32_t count;
10974 +       compat_uptr_t data_ptr;
10975 +};
10976 +
10977 +struct vcmd_read_monitor_v0_x32 {
10978 +       uint32_t index;
10979 +       uint32_t count;
10980 +       compat_uptr_t data_ptr;
10981 +};
10982 +
10983 +#endif  /* CONFIG_COMPAT */
10984 +
10985 +extern int vc_dump_history(uint32_t);
10986 +
10987 +extern int vc_read_history(uint32_t, void __user *);
10988 +extern int vc_read_monitor(uint32_t, void __user *);
10989 +
10990 +#ifdef CONFIG_COMPAT
10991 +
10992 +extern int vc_read_history_x32(uint32_t, void __user *);
10993 +extern int vc_read_monitor_x32(uint32_t, void __user *);
10994 +
10995 +#endif  /* CONFIG_COMPAT */
10996 +
10997 +#endif /* __KERNEL__ */
10998 +#endif /* _VX_DEBUG_CMD_H */
10999 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/debug.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/debug.h
11000 --- linux-2.6.36/include/linux/vserver/debug.h  1970-01-01 01:00:00.000000000 +0100
11001 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/debug.h    2010-10-21 13:09:36.000000000 +0200
11002 @@ -0,0 +1,127 @@
11003 +#ifndef _VX_DEBUG_H
11004 +#define _VX_DEBUG_H
11005 +
11006 +
11007 +#define VXD_CBIT(n, m) (vx_debug_ ## n & (1 << (m)))
11008 +#define VXD_CMIN(n, m) (vx_debug_ ## n > (m))
11009 +#define VXD_MASK(n, m) (vx_debug_ ## n & (m))
11010 +
11011 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
11012 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
11013 +#define VXF_DEV                "%p[%lu,%d:%d]"
11014 +
11015 +
11016 +#define vxd_path(p)                                            \
11017 +       ({ static char _buffer[PATH_MAX];                       \
11018 +          d_path(p, _buffer, sizeof(_buffer)); })
11019 +
11020 +#define vxd_cond_path(n)                                       \
11021 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
11022 +
11023 +
11024 +#ifdef CONFIG_VSERVER_DEBUG
11025 +
11026 +extern unsigned int vx_debug_switch;
11027 +extern unsigned int vx_debug_xid;
11028 +extern unsigned int vx_debug_nid;
11029 +extern unsigned int vx_debug_tag;
11030 +extern unsigned int vx_debug_net;
11031 +extern unsigned int vx_debug_limit;
11032 +extern unsigned int vx_debug_cres;
11033 +extern unsigned int vx_debug_dlim;
11034 +extern unsigned int vx_debug_quota;
11035 +extern unsigned int vx_debug_cvirt;
11036 +extern unsigned int vx_debug_space;
11037 +extern unsigned int vx_debug_misc;
11038 +
11039 +
11040 +#define VX_LOGLEVEL    "vxD: "
11041 +#define VX_PROC_FMT    "%p: "
11042 +#define VX_PROCESS     current
11043 +
11044 +#define vxdprintk(c, f, x...)                                  \
11045 +       do {                                                    \
11046 +               if (c)                                          \
11047 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
11048 +                               VX_PROCESS , ##x);              \
11049 +       } while (0)
11050 +
11051 +#define vxlprintk(c, f, x...)                                  \
11052 +       do {                                                    \
11053 +               if (c)                                          \
11054 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
11055 +       } while (0)
11056 +
11057 +#define vxfprintk(c, f, x...)                                  \
11058 +       do {                                                    \
11059 +               if (c)                                          \
11060 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
11061 +       } while (0)
11062 +
11063 +
11064 +struct vx_info;
11065 +
11066 +void dump_vx_info(struct vx_info *, int);
11067 +void dump_vx_info_inactive(int);
11068 +
11069 +#else  /* CONFIG_VSERVER_DEBUG */
11070 +
11071 +#define vx_debug_switch 0
11072 +#define vx_debug_xid   0
11073 +#define vx_debug_nid   0
11074 +#define vx_debug_tag   0
11075 +#define vx_debug_net   0
11076 +#define vx_debug_limit 0
11077 +#define vx_debug_cres  0
11078 +#define vx_debug_dlim  0
11079 +#define vx_debug_cvirt 0
11080 +
11081 +#define vxdprintk(x...) do { } while (0)
11082 +#define vxlprintk(x...) do { } while (0)
11083 +#define vxfprintk(x...) do { } while (0)
11084 +
11085 +#endif /* CONFIG_VSERVER_DEBUG */
11086 +
11087 +
11088 +#ifdef CONFIG_VSERVER_WARN
11089 +
11090 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
11091 +#define VX_WARN_TASK   "[»%s«,%u:#%u|%u|%u] "
11092 +#define VX_WARN_XID    "[xid #%u] "
11093 +#define VX_WARN_NID    "[nid #%u] "
11094 +#define VX_WARN_TAG    "[tag #%u] "
11095 +
11096 +#define vxwprintk(c, f, x...)                                  \
11097 +       do {                                                    \
11098 +               if (c)                                          \
11099 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
11100 +       } while (0)
11101 +
11102 +#else  /* CONFIG_VSERVER_WARN */
11103 +
11104 +#define vxwprintk(x...) do { } while (0)
11105 +
11106 +#endif /* CONFIG_VSERVER_WARN */
11107 +
11108 +#define vxwprintk_task(c, f, x...)                             \
11109 +       vxwprintk(c, VX_WARN_TASK f,                            \
11110 +               current->comm, current->pid,                    \
11111 +               current->xid, current->nid, current->tag, ##x)
11112 +#define vxwprintk_xid(c, f, x...)                              \
11113 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
11114 +#define vxwprintk_nid(c, f, x...)                              \
11115 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
11116 +#define vxwprintk_tag(c, f, x...)                              \
11117 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
11118 +
11119 +#ifdef CONFIG_VSERVER_DEBUG
11120 +#define vxd_assert_lock(l)     assert_spin_locked(l)
11121 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
11122 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
11123 +#else
11124 +#define vxd_assert_lock(l)     do { } while (0)
11125 +#define vxd_assert(c, f, x...) do { } while (0)
11126 +#endif
11127 +
11128 +
11129 +#endif /* _VX_DEBUG_H */
11130 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/device_cmd.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/device_cmd.h
11131 --- linux-2.6.36/include/linux/vserver/device_cmd.h     1970-01-01 01:00:00.000000000 +0100
11132 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/device_cmd.h       2010-10-21 13:09:36.000000000 +0200
11133 @@ -0,0 +1,44 @@
11134 +#ifndef _VX_DEVICE_CMD_H
11135 +#define _VX_DEVICE_CMD_H
11136 +
11137 +
11138 +/*  device vserver commands */
11139 +
11140 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
11141 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
11142 +
11143 +struct vcmd_set_mapping_v0 {
11144 +       const char __user *device;
11145 +       const char __user *target;
11146 +       uint32_t flags;
11147 +};
11148 +
11149 +
11150 +#ifdef __KERNEL__
11151 +
11152 +#ifdef CONFIG_COMPAT
11153 +
11154 +#include <asm/compat.h>
11155 +
11156 +struct vcmd_set_mapping_v0_x32 {
11157 +       compat_uptr_t device_ptr;
11158 +       compat_uptr_t target_ptr;
11159 +       uint32_t flags;
11160 +};
11161 +
11162 +#endif /* CONFIG_COMPAT */
11163 +
11164 +#include <linux/compiler.h>
11165 +
11166 +extern int vc_set_mapping(struct vx_info *, void __user *);
11167 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11168 +
11169 +#ifdef CONFIG_COMPAT
11170 +
11171 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11172 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11173 +
11174 +#endif /* CONFIG_COMPAT */
11175 +
11176 +#endif /* __KERNEL__ */
11177 +#endif /* _VX_DEVICE_CMD_H */
11178 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/device_def.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/device_def.h
11179 --- linux-2.6.36/include/linux/vserver/device_def.h     1970-01-01 01:00:00.000000000 +0100
11180 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/device_def.h       2010-10-21 13:09:36.000000000 +0200
11181 @@ -0,0 +1,17 @@
11182 +#ifndef _VX_DEVICE_DEF_H
11183 +#define _VX_DEVICE_DEF_H
11184 +
11185 +#include <linux/types.h>
11186 +
11187 +struct vx_dmap_target {
11188 +       dev_t target;
11189 +       uint32_t flags;
11190 +};
11191 +
11192 +struct _vx_device {
11193 +#ifdef CONFIG_VSERVER_DEVICE
11194 +       struct vx_dmap_target targets[2];
11195 +#endif
11196 +};
11197 +
11198 +#endif /* _VX_DEVICE_DEF_H */
11199 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/device.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/device.h
11200 --- linux-2.6.36/include/linux/vserver/device.h 1970-01-01 01:00:00.000000000 +0100
11201 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/device.h   2010-10-21 13:09:36.000000000 +0200
11202 @@ -0,0 +1,15 @@
11203 +#ifndef _VX_DEVICE_H
11204 +#define _VX_DEVICE_H
11205 +
11206 +
11207 +#define DATTR_CREATE   0x00000001
11208 +#define DATTR_OPEN     0x00000002
11209 +
11210 +#define DATTR_REMAP    0x00000010
11211 +
11212 +#define DATTR_MASK     0x00000013
11213 +
11214 +
11215 +#else  /* _VX_DEVICE_H */
11216 +#warning duplicate inclusion
11217 +#endif /* _VX_DEVICE_H */
11218 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/dlimit_cmd.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/dlimit_cmd.h
11219 --- linux-2.6.36/include/linux/vserver/dlimit_cmd.h     1970-01-01 01:00:00.000000000 +0100
11220 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/dlimit_cmd.h       2010-10-21 13:09:36.000000000 +0200
11221 @@ -0,0 +1,109 @@
11222 +#ifndef _VX_DLIMIT_CMD_H
11223 +#define _VX_DLIMIT_CMD_H
11224 +
11225 +
11226 +/*  dlimit vserver commands */
11227 +
11228 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
11229 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
11230 +
11231 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
11232 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
11233 +
11234 +struct vcmd_ctx_dlimit_base_v0 {
11235 +       const char __user *name;
11236 +       uint32_t flags;
11237 +};
11238 +
11239 +struct vcmd_ctx_dlimit_v0 {
11240 +       const char __user *name;
11241 +       uint32_t space_used;                    /* used space in kbytes */
11242 +       uint32_t space_total;                   /* maximum space in kbytes */
11243 +       uint32_t inodes_used;                   /* used inodes */
11244 +       uint32_t inodes_total;                  /* maximum inodes */
11245 +       uint32_t reserved;                      /* reserved for root in % */
11246 +       uint32_t flags;
11247 +};
11248 +
11249 +#define CDLIM_UNSET            ((uint32_t)0UL)
11250 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
11251 +#define CDLIM_KEEP             ((uint32_t)~1UL)
11252 +
11253 +#define DLIME_UNIT     0
11254 +#define DLIME_KILO     1
11255 +#define DLIME_MEGA     2
11256 +#define DLIME_GIGA     3
11257 +
11258 +#define DLIMF_SHIFT    0x10
11259 +
11260 +#define DLIMS_USED     0
11261 +#define DLIMS_TOTAL    2
11262 +
11263 +static inline
11264 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
11265 +{
11266 +       int exp = (flags & DLIMF_SHIFT) ?
11267 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
11268 +       return ((uint64_t)val) << (10 * exp);
11269 +}
11270 +
11271 +static inline
11272 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
11273 +{
11274 +       int exp = 0;
11275 +
11276 +       if (*flags & DLIMF_SHIFT) {
11277 +               while (val > (1LL << 32) && (exp < 3)) {
11278 +                       val >>= 10;
11279 +                       exp++;
11280 +               }
11281 +               *flags &= ~(DLIME_GIGA << shift);
11282 +               *flags |= exp << shift;
11283 +       } else
11284 +               val >>= 10;
11285 +       return val;
11286 +}
11287 +
11288 +#ifdef __KERNEL__
11289 +
11290 +#ifdef CONFIG_COMPAT
11291 +
11292 +#include <asm/compat.h>
11293 +
11294 +struct vcmd_ctx_dlimit_base_v0_x32 {
11295 +       compat_uptr_t name_ptr;
11296 +       uint32_t flags;
11297 +};
11298 +
11299 +struct vcmd_ctx_dlimit_v0_x32 {
11300 +       compat_uptr_t name_ptr;
11301 +       uint32_t space_used;                    /* used space in kbytes */
11302 +       uint32_t space_total;                   /* maximum space in kbytes */
11303 +       uint32_t inodes_used;                   /* used inodes */
11304 +       uint32_t inodes_total;                  /* maximum inodes */
11305 +       uint32_t reserved;                      /* reserved for root in % */
11306 +       uint32_t flags;
11307 +};
11308 +
11309 +#endif /* CONFIG_COMPAT */
11310 +
11311 +#include <linux/compiler.h>
11312 +
11313 +extern int vc_add_dlimit(uint32_t, void __user *);
11314 +extern int vc_rem_dlimit(uint32_t, void __user *);
11315 +
11316 +extern int vc_set_dlimit(uint32_t, void __user *);
11317 +extern int vc_get_dlimit(uint32_t, void __user *);
11318 +
11319 +#ifdef CONFIG_COMPAT
11320 +
11321 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
11322 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
11323 +
11324 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
11325 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
11326 +
11327 +#endif /* CONFIG_COMPAT */
11328 +
11329 +#endif /* __KERNEL__ */
11330 +#endif /* _VX_DLIMIT_CMD_H */
11331 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/dlimit.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/dlimit.h
11332 --- linux-2.6.36/include/linux/vserver/dlimit.h 1970-01-01 01:00:00.000000000 +0100
11333 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/dlimit.h   2010-10-21 13:09:36.000000000 +0200
11334 @@ -0,0 +1,54 @@
11335 +#ifndef _VX_DLIMIT_H
11336 +#define _VX_DLIMIT_H
11337 +
11338 +#include "switch.h"
11339 +
11340 +
11341 +#ifdef __KERNEL__
11342 +
11343 +/*      keep in sync with CDLIM_INFINITY       */
11344 +
11345 +#define DLIM_INFINITY          (~0ULL)
11346 +
11347 +#include <linux/spinlock.h>
11348 +#include <linux/rcupdate.h>
11349 +
11350 +struct super_block;
11351 +
11352 +struct dl_info {
11353 +       struct hlist_node dl_hlist;             /* linked list of contexts */
11354 +       struct rcu_head dl_rcu;                 /* the rcu head */
11355 +       tag_t dl_tag;                           /* context tag */
11356 +       atomic_t dl_usecnt;                     /* usage count */
11357 +       atomic_t dl_refcnt;                     /* reference count */
11358 +
11359 +       struct super_block *dl_sb;              /* associated superblock */
11360 +
11361 +       spinlock_t dl_lock;                     /* protect the values */
11362 +
11363 +       unsigned long long dl_space_used;       /* used space in bytes */
11364 +       unsigned long long dl_space_total;      /* maximum space in bytes */
11365 +       unsigned long dl_inodes_used;           /* used inodes */
11366 +       unsigned long dl_inodes_total;          /* maximum inodes */
11367 +
11368 +       unsigned int dl_nrlmult;                /* non root limit mult */
11369 +};
11370 +
11371 +struct rcu_head;
11372 +
11373 +extern void rcu_free_dl_info(struct rcu_head *);
11374 +extern void unhash_dl_info(struct dl_info *);
11375 +
11376 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
11377 +
11378 +
11379 +struct kstatfs;
11380 +
11381 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11382 +
11383 +typedef uint64_t dlsize_t;
11384 +
11385 +#endif /* __KERNEL__ */
11386 +#else  /* _VX_DLIMIT_H */
11387 +#warning duplicate inclusion
11388 +#endif /* _VX_DLIMIT_H */
11389 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/global.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/global.h
11390 --- linux-2.6.36/include/linux/vserver/global.h 1970-01-01 01:00:00.000000000 +0100
11391 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/global.h   2010-10-21 13:09:36.000000000 +0200
11392 @@ -0,0 +1,19 @@
11393 +#ifndef _VX_GLOBAL_H
11394 +#define _VX_GLOBAL_H
11395 +
11396 +
11397 +extern atomic_t vx_global_ctotal;
11398 +extern atomic_t vx_global_cactive;
11399 +
11400 +extern atomic_t nx_global_ctotal;
11401 +extern atomic_t nx_global_cactive;
11402 +
11403 +extern atomic_t vs_global_nsproxy;
11404 +extern atomic_t vs_global_fs;
11405 +extern atomic_t vs_global_mnt_ns;
11406 +extern atomic_t vs_global_uts_ns;
11407 +extern atomic_t vs_global_user_ns;
11408 +extern atomic_t vs_global_pid_ns;
11409 +
11410 +
11411 +#endif /* _VX_GLOBAL_H */
11412 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/history.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/history.h
11413 --- linux-2.6.36/include/linux/vserver/history.h        1970-01-01 01:00:00.000000000 +0100
11414 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/history.h  2010-10-21 13:09:36.000000000 +0200
11415 @@ -0,0 +1,197 @@
11416 +#ifndef _VX_HISTORY_H
11417 +#define _VX_HISTORY_H
11418 +
11419 +
11420 +enum {
11421 +       VXH_UNUSED = 0,
11422 +       VXH_THROW_OOPS = 1,
11423 +
11424 +       VXH_GET_VX_INFO,
11425 +       VXH_PUT_VX_INFO,
11426 +       VXH_INIT_VX_INFO,
11427 +       VXH_SET_VX_INFO,
11428 +       VXH_CLR_VX_INFO,
11429 +       VXH_CLAIM_VX_INFO,
11430 +       VXH_RELEASE_VX_INFO,
11431 +       VXH_ALLOC_VX_INFO,
11432 +       VXH_DEALLOC_VX_INFO,
11433 +       VXH_HASH_VX_INFO,
11434 +       VXH_UNHASH_VX_INFO,
11435 +       VXH_LOC_VX_INFO,
11436 +       VXH_LOOKUP_VX_INFO,
11437 +       VXH_CREATE_VX_INFO,
11438 +};
11439 +
11440 +struct _vxhe_vxi {
11441 +       struct vx_info *ptr;
11442 +       unsigned xid;
11443 +       unsigned usecnt;
11444 +       unsigned tasks;
11445 +};
11446 +
11447 +struct _vxhe_set_clr {
11448 +       void *data;
11449 +};
11450 +
11451 +struct _vxhe_loc_lookup {
11452 +       unsigned arg;
11453 +};
11454 +
11455 +struct _vx_hist_entry {
11456 +       void *loc;
11457 +       unsigned short seq;
11458 +       unsigned short type;
11459 +       struct _vxhe_vxi vxi;
11460 +       union {
11461 +               struct _vxhe_set_clr sc;
11462 +               struct _vxhe_loc_lookup ll;
11463 +       };
11464 +};
11465 +
11466 +#ifdef CONFIG_VSERVER_HISTORY
11467 +
11468 +extern unsigned volatile int vxh_active;
11469 +
11470 +struct _vx_hist_entry *vxh_advance(void *loc);
11471 +
11472 +
11473 +static inline
11474 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
11475 +{
11476 +       entry->vxi.ptr = vxi;
11477 +       if (vxi) {
11478 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
11479 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
11480 +               entry->vxi.xid = vxi->vx_id;
11481 +       }
11482 +}
11483 +
11484 +
11485 +#define        __HERE__ current_text_addr()
11486 +
11487 +#define __VXH_BODY(__type, __data, __here)     \
11488 +       struct _vx_hist_entry *entry;           \
11489 +                                               \
11490 +       preempt_disable();                      \
11491 +       entry = vxh_advance(__here);            \
11492 +       __data;                                 \
11493 +       entry->type = __type;                   \
11494 +       preempt_enable();
11495 +
11496 +
11497 +       /* pass vxi only */
11498 +
11499 +#define __VXH_SMPL                             \
11500 +       __vxh_copy_vxi(entry, vxi)
11501 +
11502 +static inline
11503 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
11504 +{
11505 +       __VXH_BODY(__type, __VXH_SMPL, __here)
11506 +}
11507 +
11508 +       /* pass vxi and data (void *) */
11509 +
11510 +#define __VXH_DATA                             \
11511 +       __vxh_copy_vxi(entry, vxi);             \
11512 +       entry->sc.data = data
11513 +
11514 +static inline
11515 +void   __vxh_data(struct vx_info *vxi, void *data,
11516 +                       int __type, void *__here)
11517 +{
11518 +       __VXH_BODY(__type, __VXH_DATA, __here)
11519 +}
11520 +
11521 +       /* pass vxi and arg (long) */
11522 +
11523 +#define __VXH_LONG                             \
11524 +       __vxh_copy_vxi(entry, vxi);             \
11525 +       entry->ll.arg = arg
11526 +
11527 +static inline
11528 +void   __vxh_long(struct vx_info *vxi, long arg,
11529 +                       int __type, void *__here)
11530 +{
11531 +       __VXH_BODY(__type, __VXH_LONG, __here)
11532 +}
11533 +
11534 +
11535 +static inline
11536 +void   __vxh_throw_oops(void *__here)
11537 +{
11538 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
11539 +       /* prevent further acquisition */
11540 +       vxh_active = 0;
11541 +}
11542 +
11543 +
11544 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
11545 +
11546 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
11547 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
11548 +
11549 +#define __vxh_init_vx_info(v, d, h) \
11550 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
11551 +#define __vxh_set_vx_info(v, d, h) \
11552 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
11553 +#define __vxh_clr_vx_info(v, d, h) \
11554 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
11555 +
11556 +#define __vxh_claim_vx_info(v, d, h) \
11557 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
11558 +#define __vxh_release_vx_info(v, d, h) \
11559 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
11560 +
11561 +#define vxh_alloc_vx_info(v) \
11562 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
11563 +#define vxh_dealloc_vx_info(v) \
11564 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
11565 +
11566 +#define vxh_hash_vx_info(v) \
11567 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
11568 +#define vxh_unhash_vx_info(v) \
11569 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
11570 +
11571 +#define vxh_loc_vx_info(v, l) \
11572 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
11573 +#define vxh_lookup_vx_info(v, l) \
11574 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
11575 +#define vxh_create_vx_info(v, l) \
11576 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
11577 +
11578 +extern void vxh_dump_history(void);
11579 +
11580 +
11581 +#else  /* CONFIG_VSERVER_HISTORY */
11582 +
11583 +#define        __HERE__        0
11584 +
11585 +#define vxh_throw_oops()               do { } while (0)
11586 +
11587 +#define __vxh_get_vx_info(v, h)                do { } while (0)
11588 +#define __vxh_put_vx_info(v, h)                do { } while (0)
11589 +
11590 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
11591 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
11592 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
11593 +
11594 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
11595 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
11596 +
11597 +#define vxh_alloc_vx_info(v)           do { } while (0)
11598 +#define vxh_dealloc_vx_info(v)         do { } while (0)
11599 +
11600 +#define vxh_hash_vx_info(v)            do { } while (0)
11601 +#define vxh_unhash_vx_info(v)          do { } while (0)
11602 +
11603 +#define vxh_loc_vx_info(v, l)          do { } while (0)
11604 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
11605 +#define vxh_create_vx_info(v, l)       do { } while (0)
11606 +
11607 +#define vxh_dump_history()             do { } while (0)
11608 +
11609 +
11610 +#endif /* CONFIG_VSERVER_HISTORY */
11611 +
11612 +#endif /* _VX_HISTORY_H */
11613 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/inode_cmd.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/inode_cmd.h
11614 --- linux-2.6.36/include/linux/vserver/inode_cmd.h      1970-01-01 01:00:00.000000000 +0100
11615 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/inode_cmd.h        2010-10-21 13:09:36.000000000 +0200
11616 @@ -0,0 +1,59 @@
11617 +#ifndef _VX_INODE_CMD_H
11618 +#define _VX_INODE_CMD_H
11619 +
11620 +
11621 +/*  inode vserver commands */
11622 +
11623 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
11624 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
11625 +
11626 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
11627 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
11628 +
11629 +struct vcmd_ctx_iattr_v1 {
11630 +       const char __user *name;
11631 +       uint32_t tag;
11632 +       uint32_t flags;
11633 +       uint32_t mask;
11634 +};
11635 +
11636 +struct vcmd_ctx_fiattr_v0 {
11637 +       uint32_t tag;
11638 +       uint32_t flags;
11639 +       uint32_t mask;
11640 +};
11641 +
11642 +
11643 +#ifdef __KERNEL__
11644 +
11645 +
11646 +#ifdef CONFIG_COMPAT
11647 +
11648 +#include <asm/compat.h>
11649 +
11650 +struct vcmd_ctx_iattr_v1_x32 {
11651 +       compat_uptr_t name_ptr;
11652 +       uint32_t tag;
11653 +       uint32_t flags;
11654 +       uint32_t mask;
11655 +};
11656 +
11657 +#endif /* CONFIG_COMPAT */
11658 +
11659 +#include <linux/compiler.h>
11660 +
11661 +extern int vc_get_iattr(void __user *);
11662 +extern int vc_set_iattr(void __user *);
11663 +
11664 +extern int vc_fget_iattr(uint32_t, void __user *);
11665 +extern int vc_fset_iattr(uint32_t, void __user *);
11666 +
11667 +#ifdef CONFIG_COMPAT
11668 +
11669 +extern int vc_get_iattr_x32(void __user *);
11670 +extern int vc_set_iattr_x32(void __user *);
11671 +
11672 +#endif /* CONFIG_COMPAT */
11673 +
11674 +#endif /* __KERNEL__ */
11675 +#endif /* _VX_INODE_CMD_H */
11676 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/inode.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/inode.h
11677 --- linux-2.6.36/include/linux/vserver/inode.h  1970-01-01 01:00:00.000000000 +0100
11678 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/inode.h    2010-10-21 13:09:36.000000000 +0200
11679 @@ -0,0 +1,39 @@
11680 +#ifndef _VX_INODE_H
11681 +#define _VX_INODE_H
11682 +
11683 +
11684 +#define IATTR_TAG      0x01000000
11685 +
11686 +#define IATTR_ADMIN    0x00000001
11687 +#define IATTR_WATCH    0x00000002
11688 +#define IATTR_HIDE     0x00000004
11689 +#define IATTR_FLAGS    0x00000007
11690 +
11691 +#define IATTR_BARRIER  0x00010000
11692 +#define IATTR_IXUNLINK 0x00020000
11693 +#define IATTR_IMMUTABLE 0x00040000
11694 +#define IATTR_COW      0x00080000
11695 +
11696 +#ifdef __KERNEL__
11697 +
11698 +
11699 +#ifdef CONFIG_VSERVER_PROC_SECURE
11700 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
11701 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11702 +#else
11703 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
11704 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11705 +#endif
11706 +
11707 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
11708 +
11709 +#endif /* __KERNEL__ */
11710 +
11711 +/* inode ioctls */
11712 +
11713 +#define FIOC_GETXFLG   _IOR('x', 5, long)
11714 +#define FIOC_SETXFLG   _IOW('x', 6, long)
11715 +
11716 +#else  /* _VX_INODE_H */
11717 +#warning duplicate inclusion
11718 +#endif /* _VX_INODE_H */
11719 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/Kbuild linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/Kbuild
11720 --- linux-2.6.36/include/linux/vserver/Kbuild   1970-01-01 01:00:00.000000000 +0100
11721 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/Kbuild     2010-10-21 13:09:36.000000000 +0200
11722 @@ -0,0 +1,8 @@
11723 +
11724 +unifdef-y += context_cmd.h network_cmd.h space_cmd.h \
11725 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
11726 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
11727 +       debug_cmd.h device_cmd.h
11728 +
11729 +unifdef-y += switch.h network.h monitor.h inode.h device.h
11730 +
11731 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/limit_cmd.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/limit_cmd.h
11732 --- linux-2.6.36/include/linux/vserver/limit_cmd.h      1970-01-01 01:00:00.000000000 +0100
11733 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/limit_cmd.h        2010-10-21 13:09:36.000000000 +0200
11734 @@ -0,0 +1,71 @@
11735 +#ifndef _VX_LIMIT_CMD_H
11736 +#define _VX_LIMIT_CMD_H
11737 +
11738 +
11739 +/*  rlimit vserver commands */
11740 +
11741 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
11742 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
11743 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
11744 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
11745 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
11746 +
11747 +struct vcmd_ctx_rlimit_v0 {
11748 +       uint32_t id;
11749 +       uint64_t minimum;
11750 +       uint64_t softlimit;
11751 +       uint64_t maximum;
11752 +};
11753 +
11754 +struct vcmd_ctx_rlimit_mask_v0 {
11755 +       uint32_t minimum;
11756 +       uint32_t softlimit;
11757 +       uint32_t maximum;
11758 +};
11759 +
11760 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
11761 +
11762 +struct vcmd_rlimit_stat_v0 {
11763 +       uint32_t id;
11764 +       uint32_t hits;
11765 +       uint64_t value;
11766 +       uint64_t minimum;
11767 +       uint64_t maximum;
11768 +};
11769 +
11770 +#define CRLIM_UNSET            (0ULL)
11771 +#define CRLIM_INFINITY         (~0ULL)
11772 +#define CRLIM_KEEP             (~1ULL)
11773 +
11774 +#ifdef __KERNEL__
11775 +
11776 +#ifdef CONFIG_IA32_EMULATION
11777 +
11778 +struct vcmd_ctx_rlimit_v0_x32 {
11779 +       uint32_t id;
11780 +       uint64_t minimum;
11781 +       uint64_t softlimit;
11782 +       uint64_t maximum;
11783 +} __attribute__ ((packed));
11784 +
11785 +#endif /* CONFIG_IA32_EMULATION */
11786 +
11787 +#include <linux/compiler.h>
11788 +
11789 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
11790 +extern int vc_get_rlimit(struct vx_info *, void __user *);
11791 +extern int vc_set_rlimit(struct vx_info *, void __user *);
11792 +extern int vc_reset_hits(struct vx_info *, void __user *);
11793 +extern int vc_reset_minmax(struct vx_info *, void __user *);
11794 +
11795 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
11796 +
11797 +#ifdef CONFIG_IA32_EMULATION
11798 +
11799 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
11800 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
11801 +
11802 +#endif /* CONFIG_IA32_EMULATION */
11803 +
11804 +#endif /* __KERNEL__ */
11805 +#endif /* _VX_LIMIT_CMD_H */
11806 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/limit_def.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/limit_def.h
11807 --- linux-2.6.36/include/linux/vserver/limit_def.h      1970-01-01 01:00:00.000000000 +0100
11808 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/limit_def.h        2010-10-21 13:09:36.000000000 +0200
11809 @@ -0,0 +1,47 @@
11810 +#ifndef _VX_LIMIT_DEF_H
11811 +#define _VX_LIMIT_DEF_H
11812 +
11813 +#include <asm/atomic.h>
11814 +#include <asm/resource.h>
11815 +
11816 +#include "limit.h"
11817 +
11818 +
11819 +struct _vx_res_limit {
11820 +       rlim_t soft;            /* Context soft limit */
11821 +       rlim_t hard;            /* Context hard limit */
11822 +
11823 +       rlim_atomic_t rcur;     /* Current value */
11824 +       rlim_t rmin;            /* Context minimum */
11825 +       rlim_t rmax;            /* Context maximum */
11826 +
11827 +       atomic_t lhit;          /* Limit hits */
11828 +};
11829 +
11830 +/* context sub struct */
11831 +
11832 +struct _vx_limit {
11833 +       struct _vx_res_limit res[NUM_LIMITS];
11834 +};
11835 +
11836 +#ifdef CONFIG_VSERVER_DEBUG
11837 +
11838 +static inline void __dump_vx_limit(struct _vx_limit *limit)
11839 +{
11840 +       int i;
11841 +
11842 +       printk("\t_vx_limit:");
11843 +       for (i = 0; i < NUM_LIMITS; i++) {
11844 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
11845 +                       i, (unsigned long)__rlim_get(limit, i),
11846 +                       (unsigned long)__rlim_rmin(limit, i),
11847 +                       (unsigned long)__rlim_rmax(limit, i),
11848 +                       (long)__rlim_soft(limit, i),
11849 +                       (long)__rlim_hard(limit, i),
11850 +                       atomic_read(&__rlim_lhit(limit, i)));
11851 +       }
11852 +}
11853 +
11854 +#endif
11855 +
11856 +#endif /* _VX_LIMIT_DEF_H */
11857 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/limit.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/limit.h
11858 --- linux-2.6.36/include/linux/vserver/limit.h  1970-01-01 01:00:00.000000000 +0100
11859 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/limit.h    2010-10-21 13:09:36.000000000 +0200
11860 @@ -0,0 +1,71 @@
11861 +#ifndef _VX_LIMIT_H
11862 +#define _VX_LIMIT_H
11863 +
11864 +#define VLIMIT_NSOCK   16
11865 +#define VLIMIT_OPENFD  17
11866 +#define VLIMIT_ANON    18
11867 +#define VLIMIT_SHMEM   19
11868 +#define VLIMIT_SEMARY  20
11869 +#define VLIMIT_NSEMS   21
11870 +#define VLIMIT_DENTRY  22
11871 +#define VLIMIT_MAPPED  23
11872 +
11873 +
11874 +#ifdef __KERNEL__
11875 +
11876 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
11877 +
11878 +/*     keep in sync with CRLIM_INFINITY */
11879 +
11880 +#define        VLIM_INFINITY   (~0ULL)
11881 +
11882 +#include <asm/atomic.h>
11883 +#include <asm/resource.h>
11884 +
11885 +#ifndef RLIM_INFINITY
11886 +#warning RLIM_INFINITY is undefined
11887 +#endif
11888 +
11889 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
11890 +
11891 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
11892 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
11893 +
11894 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
11895 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
11896 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
11897 +
11898 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
11899 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
11900 +
11901 +typedef atomic_long_t rlim_atomic_t;
11902 +typedef unsigned long rlim_t;
11903 +
11904 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
11905 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
11906 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
11907 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
11908 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
11909 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
11910 +
11911 +
11912 +#if    (RLIM_INFINITY == VLIM_INFINITY)
11913 +#define        VX_VLIM(r) ((long long)(long)(r))
11914 +#define        VX_RLIM(v) ((rlim_t)(v))
11915 +#else
11916 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
11917 +               ? VLIM_INFINITY : (long long)(r))
11918 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
11919 +               ? RLIM_INFINITY : (rlim_t)(v))
11920 +#endif
11921 +
11922 +struct sysinfo;
11923 +
11924 +void vx_vsi_meminfo(struct sysinfo *);
11925 +void vx_vsi_swapinfo(struct sysinfo *);
11926 +long vx_vsi_cached(struct sysinfo *);
11927 +
11928 +#define NUM_LIMITS     24
11929 +
11930 +#endif /* __KERNEL__ */
11931 +#endif /* _VX_LIMIT_H */
11932 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/limit_int.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/limit_int.h
11933 --- linux-2.6.36/include/linux/vserver/limit_int.h      1970-01-01 01:00:00.000000000 +0100
11934 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/limit_int.h        2010-10-21 13:09:36.000000000 +0200
11935 @@ -0,0 +1,198 @@
11936 +#ifndef _VX_LIMIT_INT_H
11937 +#define _VX_LIMIT_INT_H
11938 +
11939 +#include "context.h"
11940 +
11941 +#ifdef __KERNEL__
11942 +
11943 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
11944 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
11945 +
11946 +extern const char *vlimit_name[NUM_LIMITS];
11947 +
11948 +static inline void __vx_acc_cres(struct vx_info *vxi,
11949 +       int res, int dir, void *_data, char *_file, int _line)
11950 +{
11951 +       if (VXD_RCRES_COND(res))
11952 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
11953 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11954 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11955 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
11956 +       if (!vxi)
11957 +               return;
11958 +
11959 +       if (dir > 0)
11960 +               __rlim_inc(&vxi->limit, res);
11961 +       else
11962 +               __rlim_dec(&vxi->limit, res);
11963 +}
11964 +
11965 +static inline void __vx_add_cres(struct vx_info *vxi,
11966 +       int res, int amount, void *_data, char *_file, int _line)
11967 +{
11968 +       if (VXD_RCRES_COND(res))
11969 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
11970 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11971 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11972 +                       amount, _data, _file, _line);
11973 +       if (amount == 0)
11974 +               return;
11975 +       if (!vxi)
11976 +               return;
11977 +       __rlim_add(&vxi->limit, res, amount);
11978 +}
11979 +
11980 +static inline
11981 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
11982 +{
11983 +       int cond = (value > __rlim_rmax(limit, res));
11984 +
11985 +       if (cond)
11986 +               __rlim_rmax(limit, res) = value;
11987 +       return cond;
11988 +}
11989 +
11990 +static inline
11991 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
11992 +{
11993 +       int cond = (value < __rlim_rmin(limit, res));
11994 +
11995 +       if (cond)
11996 +               __rlim_rmin(limit, res) = value;
11997 +       return cond;
11998 +}
11999 +
12000 +static inline
12001 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
12002 +{
12003 +       if (!__vx_cres_adjust_max(limit, res, value))
12004 +               __vx_cres_adjust_min(limit, res, value);
12005 +}
12006 +
12007 +
12008 +/*     return values:
12009 +        +1 ... no limit hit
12010 +        -1 ... over soft limit
12011 +         0 ... over hard limit         */
12012 +
12013 +static inline int __vx_cres_avail(struct vx_info *vxi,
12014 +       int res, int num, char *_file, int _line)
12015 +{
12016 +       struct _vx_limit *limit;
12017 +       rlim_t value;
12018 +
12019 +       if (VXD_RLIMIT_COND(res))
12020 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
12021 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12022 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
12023 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
12024 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12025 +                       num, _file, _line);
12026 +       if (!vxi)
12027 +               return 1;
12028 +
12029 +       limit = &vxi->limit;
12030 +       value = __rlim_get(limit, res);
12031 +
12032 +       if (!__vx_cres_adjust_max(limit, res, value))
12033 +               __vx_cres_adjust_min(limit, res, value);
12034 +
12035 +       if (num == 0)
12036 +               return 1;
12037 +
12038 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
12039 +               return -1;
12040 +       if (value + num <= __rlim_soft(limit, res))
12041 +               return -1;
12042 +
12043 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
12044 +               return 1;
12045 +       if (value + num <= __rlim_hard(limit, res))
12046 +               return 1;
12047 +
12048 +       __rlim_hit(limit, res);
12049 +       return 0;
12050 +}
12051 +
12052 +
12053 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
12054 +
12055 +static inline
12056 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
12057 +{
12058 +       rlim_t value, sum = 0;
12059 +       int res;
12060 +
12061 +       while ((res = *array++)) {
12062 +               value = __rlim_get(limit, res);
12063 +               __vx_cres_fixup(limit, res, value);
12064 +               sum += value;
12065 +       }
12066 +       return sum;
12067 +}
12068 +
12069 +static inline
12070 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
12071 +{
12072 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
12073 +       int res = *array;
12074 +
12075 +       if (value == __rlim_get(limit, res))
12076 +               return value;
12077 +
12078 +       __rlim_set(limit, res, value);
12079 +       /* now adjust min/max */
12080 +       if (!__vx_cres_adjust_max(limit, res, value))
12081 +               __vx_cres_adjust_min(limit, res, value);
12082 +
12083 +       return value;
12084 +}
12085 +
12086 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
12087 +       const int *array, int num, char *_file, int _line)
12088 +{
12089 +       struct _vx_limit *limit;
12090 +       rlim_t value = 0;
12091 +       int res;
12092 +
12093 +       if (num == 0)
12094 +               return 1;
12095 +       if (!vxi)
12096 +               return 1;
12097 +
12098 +       limit = &vxi->limit;
12099 +       res = *array;
12100 +       value = __vx_cres_array_sum(limit, array + 1);
12101 +
12102 +       __rlim_set(limit, res, value);
12103 +       __vx_cres_fixup(limit, res, value);
12104 +
12105 +       return __vx_cres_avail(vxi, res, num, _file, _line);
12106 +}
12107 +
12108 +
12109 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
12110 +{
12111 +       rlim_t value;
12112 +       int res;
12113 +
12114 +       /* complex resources first */
12115 +       if ((id < 0) || (id == RLIMIT_RSS))
12116 +               __vx_cres_array_fixup(limit, VLA_RSS);
12117 +
12118 +       for (res = 0; res < NUM_LIMITS; res++) {
12119 +               if ((id > 0) && (res != id))
12120 +                       continue;
12121 +
12122 +               value = __rlim_get(limit, res);
12123 +               __vx_cres_fixup(limit, res, value);
12124 +
12125 +               /* not supposed to happen, maybe warn? */
12126 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
12127 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
12128 +       }
12129 +}
12130 +
12131 +
12132 +#endif /* __KERNEL__ */
12133 +#endif /* _VX_LIMIT_INT_H */
12134 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/monitor.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/monitor.h
12135 --- linux-2.6.36/include/linux/vserver/monitor.h        1970-01-01 01:00:00.000000000 +0100
12136 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/monitor.h  2010-10-21 13:09:36.000000000 +0200
12137 @@ -0,0 +1,96 @@
12138 +#ifndef _VX_MONITOR_H
12139 +#define _VX_MONITOR_H
12140 +
12141 +#include <linux/types.h>
12142 +
12143 +enum {
12144 +       VXM_UNUSED = 0,
12145 +
12146 +       VXM_SYNC = 0x10,
12147 +
12148 +       VXM_UPDATE = 0x20,
12149 +       VXM_UPDATE_1,
12150 +       VXM_UPDATE_2,
12151 +
12152 +       VXM_RQINFO_1 = 0x24,
12153 +       VXM_RQINFO_2,
12154 +
12155 +       VXM_ACTIVATE = 0x40,
12156 +       VXM_DEACTIVATE,
12157 +       VXM_IDLE,
12158 +
12159 +       VXM_HOLD = 0x44,
12160 +       VXM_UNHOLD,
12161 +
12162 +       VXM_MIGRATE = 0x48,
12163 +       VXM_RESCHED,
12164 +
12165 +       /* all other bits are flags */
12166 +       VXM_SCHED = 0x80,
12167 +};
12168 +
12169 +struct _vxm_update_1 {
12170 +       uint32_t tokens_max;
12171 +       uint32_t fill_rate;
12172 +       uint32_t interval;
12173 +};
12174 +
12175 +struct _vxm_update_2 {
12176 +       uint32_t tokens_min;
12177 +       uint32_t fill_rate;
12178 +       uint32_t interval;
12179 +};
12180 +
12181 +struct _vxm_rqinfo_1 {
12182 +       uint16_t running;
12183 +       uint16_t onhold;
12184 +       uint16_t iowait;
12185 +       uint16_t uintr;
12186 +       uint32_t idle_tokens;
12187 +};
12188 +
12189 +struct _vxm_rqinfo_2 {
12190 +       uint32_t norm_time;
12191 +       uint32_t idle_time;
12192 +       uint32_t idle_skip;
12193 +};
12194 +
12195 +struct _vxm_sched {
12196 +       uint32_t tokens;
12197 +       uint32_t norm_time;
12198 +       uint32_t idle_time;
12199 +};
12200 +
12201 +struct _vxm_task {
12202 +       uint16_t pid;
12203 +       uint16_t state;
12204 +};
12205 +
12206 +struct _vxm_event {
12207 +       uint32_t jif;
12208 +       union {
12209 +               uint32_t seq;
12210 +               uint32_t sec;
12211 +       };
12212 +       union {
12213 +               uint32_t tokens;
12214 +               uint32_t nsec;
12215 +               struct _vxm_task tsk;
12216 +       };
12217 +};
12218 +
12219 +struct _vx_mon_entry {
12220 +       uint16_t type;
12221 +       uint16_t xid;
12222 +       union {
12223 +               struct _vxm_event ev;
12224 +               struct _vxm_sched sd;
12225 +               struct _vxm_update_1 u1;
12226 +               struct _vxm_update_2 u2;
12227 +               struct _vxm_rqinfo_1 q1;
12228 +               struct _vxm_rqinfo_2 q2;
12229 +       };
12230 +};
12231 +
12232 +
12233 +#endif /* _VX_MONITOR_H */
12234 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/network_cmd.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/network_cmd.h
12235 --- linux-2.6.36/include/linux/vserver/network_cmd.h    1970-01-01 01:00:00.000000000 +0100
12236 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/network_cmd.h      2010-10-21 13:09:36.000000000 +0200
12237 @@ -0,0 +1,150 @@
12238 +#ifndef _VX_NETWORK_CMD_H
12239 +#define _VX_NETWORK_CMD_H
12240 +
12241 +
12242 +/* vinfo commands */
12243 +
12244 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
12245 +
12246 +#ifdef __KERNEL__
12247 +extern int vc_task_nid(uint32_t);
12248 +
12249 +#endif /* __KERNEL__ */
12250 +
12251 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
12252 +
12253 +struct vcmd_nx_info_v0 {
12254 +       uint32_t nid;
12255 +       /* more to come */
12256 +};
12257 +
12258 +#ifdef __KERNEL__
12259 +extern int vc_nx_info(struct nx_info *, void __user *);
12260 +
12261 +#endif /* __KERNEL__ */
12262 +
12263 +#include <linux/in.h>
12264 +#include <linux/in6.h>
12265 +
12266 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
12267 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
12268 +
12269 +struct  vcmd_net_create {
12270 +       uint64_t flagword;
12271 +};
12272 +
12273 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
12274 +
12275 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
12276 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
12277 +
12278 +struct vcmd_net_addr_v0 {
12279 +       uint16_t type;
12280 +       uint16_t count;
12281 +       struct in_addr ip[4];
12282 +       struct in_addr mask[4];
12283 +};
12284 +
12285 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 1)
12286 +#define VCMD_net_remove_ipv4   VC_CMD(NETALT, 2, 1)
12287 +
12288 +struct vcmd_net_addr_ipv4_v1 {
12289 +       uint16_t type;
12290 +       uint16_t flags;
12291 +       struct in_addr ip;
12292 +       struct in_addr mask;
12293 +};
12294 +
12295 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
12296 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
12297 +
12298 +struct vcmd_net_addr_ipv6_v1 {
12299 +       uint16_t type;
12300 +       uint16_t flags;
12301 +       uint32_t prefix;
12302 +       struct in6_addr ip;
12303 +       struct in6_addr mask;
12304 +};
12305 +
12306 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
12307 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
12308 +
12309 +struct vcmd_match_ipv4_v0 {
12310 +       uint16_t type;
12311 +       uint16_t flags;
12312 +       uint16_t parent;
12313 +       uint16_t prefix;
12314 +       struct in_addr ip;
12315 +       struct in_addr ip2;
12316 +       struct in_addr mask;
12317 +};
12318 +
12319 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
12320 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
12321 +
12322 +struct vcmd_match_ipv6_v0 {
12323 +       uint16_t type;
12324 +       uint16_t flags;
12325 +       uint16_t parent;
12326 +       uint16_t prefix;
12327 +       struct in6_addr ip;
12328 +       struct in6_addr ip2;
12329 +       struct in6_addr mask;
12330 +};
12331 +
12332 +
12333 +#ifdef __KERNEL__
12334 +extern int vc_net_create(uint32_t, void __user *);
12335 +extern int vc_net_migrate(struct nx_info *, void __user *);
12336 +
12337 +extern int vc_net_add(struct nx_info *, void __user *);
12338 +extern int vc_net_remove(struct nx_info *, void __user *);
12339 +
12340 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
12341 +extern int vc_net_remove_ipv4(struct nx_info *, void __user *);
12342 +
12343 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
12344 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
12345 +
12346 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
12347 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
12348 +
12349 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
12350 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
12351 +
12352 +#endif /* __KERNEL__ */
12353 +
12354 +
12355 +/* flag commands */
12356 +
12357 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
12358 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
12359 +
12360 +struct vcmd_net_flags_v0 {
12361 +       uint64_t flagword;
12362 +       uint64_t mask;
12363 +};
12364 +
12365 +#ifdef __KERNEL__
12366 +extern int vc_get_nflags(struct nx_info *, void __user *);
12367 +extern int vc_set_nflags(struct nx_info *, void __user *);
12368 +
12369 +#endif /* __KERNEL__ */
12370 +
12371 +
12372 +/* network caps commands */
12373 +
12374 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
12375 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
12376 +
12377 +struct vcmd_net_caps_v0 {
12378 +       uint64_t ncaps;
12379 +       uint64_t cmask;
12380 +};
12381 +
12382 +#ifdef __KERNEL__
12383 +extern int vc_get_ncaps(struct nx_info *, void __user *);
12384 +extern int vc_set_ncaps(struct nx_info *, void __user *);
12385 +
12386 +#endif /* __KERNEL__ */
12387 +#endif /* _VX_CONTEXT_CMD_H */
12388 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/network.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/network.h
12389 --- linux-2.6.36/include/linux/vserver/network.h        1970-01-01 01:00:00.000000000 +0100
12390 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/network.h  2010-10-21 13:09:36.000000000 +0200
12391 @@ -0,0 +1,146 @@
12392 +#ifndef _VX_NETWORK_H
12393 +#define _VX_NETWORK_H
12394 +
12395 +#include <linux/types.h>
12396 +
12397 +
12398 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
12399 +
12400 +
12401 +/* network flags */
12402 +
12403 +#define NXF_INFO_PRIVATE       0x00000008
12404 +
12405 +#define NXF_SINGLE_IP          0x00000100
12406 +#define NXF_LBACK_REMAP                0x00000200
12407 +#define NXF_LBACK_ALLOW                0x00000400
12408 +
12409 +#define NXF_HIDE_NETIF         0x02000000
12410 +#define NXF_HIDE_LBACK         0x04000000
12411 +
12412 +#define NXF_STATE_SETUP                (1ULL << 32)
12413 +#define NXF_STATE_ADMIN                (1ULL << 34)
12414 +
12415 +#define NXF_SC_HELPER          (1ULL << 36)
12416 +#define NXF_PERSISTENT         (1ULL << 38)
12417 +
12418 +#define NXF_ONE_TIME           (0x0005ULL << 32)
12419 +
12420 +
12421 +#define        NXF_INIT_SET            (__nxf_init_set())
12422 +
12423 +static inline uint64_t __nxf_init_set(void) {
12424 +       return    NXF_STATE_ADMIN
12425 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12426 +               | NXF_LBACK_REMAP
12427 +               | NXF_HIDE_LBACK
12428 +#endif
12429 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12430 +               | NXF_SINGLE_IP
12431 +#endif
12432 +               | NXF_HIDE_NETIF;
12433 +}
12434 +
12435 +
12436 +/* network caps */
12437 +
12438 +#define NXC_TUN_CREATE         0x00000001
12439 +
12440 +#define NXC_RAW_ICMP           0x00000100
12441 +
12442 +
12443 +/* address types */
12444 +
12445 +#define NXA_TYPE_IPV4          0x0001
12446 +#define NXA_TYPE_IPV6          0x0002
12447 +
12448 +#define NXA_TYPE_NONE          0x0000
12449 +#define NXA_TYPE_ANY           0x00FF
12450 +
12451 +#define NXA_TYPE_ADDR          0x0010
12452 +#define NXA_TYPE_MASK          0x0020
12453 +#define NXA_TYPE_RANGE         0x0040
12454 +
12455 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12456 +
12457 +#define NXA_MOD_BCAST          0x0100
12458 +#define NXA_MOD_LBACK          0x0200
12459 +
12460 +#define NXA_LOOPBACK           0x1000
12461 +
12462 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12463 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
12464 +
12465 +#ifdef __KERNEL__
12466 +
12467 +#include <linux/list.h>
12468 +#include <linux/spinlock.h>
12469 +#include <linux/rcupdate.h>
12470 +#include <linux/in.h>
12471 +#include <linux/in6.h>
12472 +#include <asm/atomic.h>
12473 +
12474 +struct nx_addr_v4 {
12475 +       struct nx_addr_v4 *next;
12476 +       struct in_addr ip[2];
12477 +       struct in_addr mask;
12478 +       uint16_t type;
12479 +       uint16_t flags;
12480 +};
12481 +
12482 +struct nx_addr_v6 {
12483 +       struct nx_addr_v6 *next;
12484 +       struct in6_addr ip;
12485 +       struct in6_addr mask;
12486 +       uint32_t prefix;
12487 +       uint16_t type;
12488 +       uint16_t flags;
12489 +};
12490 +
12491 +struct nx_info {
12492 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
12493 +       nid_t nx_id;                    /* vnet id */
12494 +       atomic_t nx_usecnt;             /* usage count */
12495 +       atomic_t nx_tasks;              /* tasks count */
12496 +       int nx_state;                   /* context state */
12497 +
12498 +       uint64_t nx_flags;              /* network flag word */
12499 +       uint64_t nx_ncaps;              /* network capabilities */
12500 +
12501 +       struct in_addr v4_lback;        /* Loopback address */
12502 +       struct in_addr v4_bcast;        /* Broadcast address */
12503 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
12504 +#ifdef CONFIG_IPV6
12505 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
12506 +#endif
12507 +       char nx_name[65];               /* network context name */
12508 +};
12509 +
12510 +
12511 +/* status flags */
12512 +
12513 +#define NXS_HASHED      0x0001
12514 +#define NXS_SHUTDOWN    0x0100
12515 +#define NXS_RELEASED    0x8000
12516 +
12517 +extern struct nx_info *lookup_nx_info(int);
12518 +
12519 +extern int get_nid_list(int, unsigned int *, int);
12520 +extern int nid_is_hashed(nid_t);
12521 +
12522 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
12523 +
12524 +extern long vs_net_change(struct nx_info *, unsigned int);
12525 +
12526 +struct sock;
12527 +
12528 +
12529 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
12530 +#ifdef  CONFIG_IPV6
12531 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
12532 +#else
12533 +#define NX_IPV6(n)     (0)
12534 +#endif
12535 +
12536 +#endif /* __KERNEL__ */
12537 +#endif /* _VX_NETWORK_H */
12538 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/percpu.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/percpu.h
12539 --- linux-2.6.36/include/linux/vserver/percpu.h 1970-01-01 01:00:00.000000000 +0100
12540 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/percpu.h   2010-10-21 13:09:36.000000000 +0200
12541 @@ -0,0 +1,14 @@
12542 +#ifndef _VX_PERCPU_H
12543 +#define _VX_PERCPU_H
12544 +
12545 +#include "cvirt_def.h"
12546 +#include "sched_def.h"
12547 +
12548 +struct _vx_percpu {
12549 +       struct _vx_cvirt_pc cvirt;
12550 +       struct _vx_sched_pc sched;
12551 +};
12552 +
12553 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
12554 +
12555 +#endif /* _VX_PERCPU_H */
12556 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/pid.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/pid.h
12557 --- linux-2.6.36/include/linux/vserver/pid.h    1970-01-01 01:00:00.000000000 +0100
12558 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/pid.h      2010-10-21 13:09:36.000000000 +0200
12559 @@ -0,0 +1,51 @@
12560 +#ifndef _VSERVER_PID_H
12561 +#define _VSERVER_PID_H
12562 +
12563 +/* pid faking stuff */
12564 +
12565 +#define vx_info_map_pid(v, p) \
12566 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
12567 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
12568 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
12569 +#define vx_map_tgid(p) vx_map_pid(p)
12570 +
12571 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
12572 +       const char *func, const char *file, int line)
12573 +{
12574 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12575 +               vxfprintk(VXD_CBIT(cvirt, 2),
12576 +                       "vx_map_tgid: %p/%llx: %d -> %d",
12577 +                       vxi, (long long)vxi->vx_flags, pid,
12578 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
12579 +                       func, file, line);
12580 +               if (pid == 0)
12581 +                       return 0;
12582 +               if (pid == vxi->vx_initpid)
12583 +                       return 1;
12584 +       }
12585 +       return pid;
12586 +}
12587 +
12588 +#define vx_info_rmap_pid(v, p) \
12589 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
12590 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
12591 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
12592 +
12593 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
12594 +       const char *func, const char *file, int line)
12595 +{
12596 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12597 +               vxfprintk(VXD_CBIT(cvirt, 2),
12598 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
12599 +                       vxi, (long long)vxi->vx_flags, pid,
12600 +                       (pid == 1) ? vxi->vx_initpid : pid,
12601 +                       func, file, line);
12602 +               if ((pid == 1) && vxi->vx_initpid)
12603 +                       return vxi->vx_initpid;
12604 +               if (pid == vxi->vx_initpid)
12605 +                       return ~0U;
12606 +       }
12607 +       return pid;
12608 +}
12609 +
12610 +#endif
12611 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/sched_cmd.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/sched_cmd.h
12612 --- linux-2.6.36/include/linux/vserver/sched_cmd.h      1970-01-01 01:00:00.000000000 +0100
12613 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/sched_cmd.h        2010-10-21 13:09:36.000000000 +0200
12614 @@ -0,0 +1,108 @@
12615 +#ifndef _VX_SCHED_CMD_H
12616 +#define _VX_SCHED_CMD_H
12617 +
12618 +
12619 +/*  sched vserver commands */
12620 +
12621 +#define VCMD_set_sched_v2      VC_CMD(SCHED, 1, 2)
12622 +#define VCMD_set_sched_v3      VC_CMD(SCHED, 1, 3)
12623 +#define VCMD_set_sched_v4      VC_CMD(SCHED, 1, 4)
12624 +
12625 +struct vcmd_set_sched_v2 {
12626 +       int32_t fill_rate;
12627 +       int32_t interval;
12628 +       int32_t tokens;
12629 +       int32_t tokens_min;
12630 +       int32_t tokens_max;
12631 +       uint64_t cpu_mask;
12632 +};
12633 +
12634 +struct vcmd_set_sched_v3 {
12635 +       uint32_t set_mask;
12636 +       int32_t fill_rate;
12637 +       int32_t interval;
12638 +       int32_t tokens;
12639 +       int32_t tokens_min;
12640 +       int32_t tokens_max;
12641 +       int32_t priority_bias;
12642 +};
12643 +
12644 +struct vcmd_set_sched_v4 {
12645 +       uint32_t set_mask;
12646 +       int32_t fill_rate;
12647 +       int32_t interval;
12648 +       int32_t tokens;
12649 +       int32_t tokens_min;
12650 +       int32_t tokens_max;
12651 +       int32_t prio_bias;
12652 +       int32_t cpu_id;
12653 +       int32_t bucket_id;
12654 +};
12655 +
12656 +#define VCMD_set_sched         VC_CMD(SCHED, 1, 5)
12657 +#define VCMD_get_sched         VC_CMD(SCHED, 2, 5)
12658 +
12659 +struct vcmd_sched_v5 {
12660 +       uint32_t mask;
12661 +       int32_t cpu_id;
12662 +       int32_t bucket_id;
12663 +       int32_t fill_rate[2];
12664 +       int32_t interval[2];
12665 +       int32_t tokens;
12666 +       int32_t tokens_min;
12667 +       int32_t tokens_max;
12668 +       int32_t prio_bias;
12669 +};
12670 +
12671 +#define VXSM_FILL_RATE         0x0001
12672 +#define VXSM_INTERVAL          0x0002
12673 +#define VXSM_FILL_RATE2                0x0004
12674 +#define VXSM_INTERVAL2         0x0008
12675 +#define VXSM_TOKENS            0x0010
12676 +#define VXSM_TOKENS_MIN                0x0020
12677 +#define VXSM_TOKENS_MAX                0x0040
12678 +#define VXSM_PRIO_BIAS         0x0100
12679 +
12680 +#define VXSM_IDLE_TIME         0x0200
12681 +#define VXSM_FORCE             0x0400
12682 +
12683 +#define        VXSM_V3_MASK            0x0173
12684 +#define        VXSM_SET_MASK           0x01FF
12685 +
12686 +#define VXSM_CPU_ID            0x1000
12687 +#define VXSM_BUCKET_ID         0x2000
12688 +
12689 +#define VXSM_MSEC              0x4000
12690 +
12691 +#define SCHED_KEEP             (-2)    /* only for v2 */
12692 +
12693 +#ifdef __KERNEL__
12694 +
12695 +#include <linux/compiler.h>
12696 +
12697 +extern int vc_set_sched_v2(struct vx_info *, void __user *);
12698 +extern int vc_set_sched_v3(struct vx_info *, void __user *);
12699 +extern int vc_set_sched_v4(struct vx_info *, void __user *);
12700 +extern int vc_set_sched(struct vx_info *, void __user *);
12701 +extern int vc_get_sched(struct vx_info *, void __user *);
12702 +
12703 +#endif /* __KERNEL__ */
12704 +
12705 +#define VCMD_sched_info                VC_CMD(SCHED, 3, 0)
12706 +
12707 +struct vcmd_sched_info {
12708 +       int32_t cpu_id;
12709 +       int32_t bucket_id;
12710 +       uint64_t user_msec;
12711 +       uint64_t sys_msec;
12712 +       uint64_t hold_msec;
12713 +       uint32_t token_usec;
12714 +       int32_t vavavoom;
12715 +};
12716 +
12717 +#ifdef __KERNEL__
12718 +
12719 +extern int vc_sched_info(struct vx_info *, void __user *);
12720 +
12721 +#endif /* __KERNEL__ */
12722 +#endif /* _VX_SCHED_CMD_H */
12723 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/sched_def.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/sched_def.h
12724 --- linux-2.6.36/include/linux/vserver/sched_def.h      1970-01-01 01:00:00.000000000 +0100
12725 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/sched_def.h        2010-10-21 13:09:36.000000000 +0200
12726 @@ -0,0 +1,68 @@
12727 +#ifndef _VX_SCHED_DEF_H
12728 +#define _VX_SCHED_DEF_H
12729 +
12730 +#include <linux/spinlock.h>
12731 +#include <linux/jiffies.h>
12732 +#include <linux/cpumask.h>
12733 +#include <asm/atomic.h>
12734 +#include <asm/param.h>
12735 +
12736 +
12737 +/* context sub struct */
12738 +
12739 +struct _vx_sched {
12740 +       spinlock_t tokens_lock;         /* lock for token bucket */
12741 +
12742 +       int tokens;                     /* number of CPU tokens */
12743 +       int fill_rate[2];               /* Fill rate: add X tokens... */
12744 +       int interval[2];                /* Divisor:   per Y jiffies   */
12745 +       int tokens_min;                 /* Limit:     minimum for unhold */
12746 +       int tokens_max;                 /* Limit:     no more than N tokens */
12747 +
12748 +       int prio_bias;                  /* bias offset for priority */
12749 +
12750 +       unsigned update_mask;           /* which features should be updated */
12751 +       cpumask_t update;               /* CPUs which should update */
12752 +};
12753 +
12754 +struct _vx_sched_pc {
12755 +       int tokens;                     /* number of CPU tokens */
12756 +       int flags;                      /* bucket flags */
12757 +
12758 +       int fill_rate[2];               /* Fill rate: add X tokens... */
12759 +       int interval[2];                /* Divisor:   per Y jiffies   */
12760 +       int tokens_min;                 /* Limit:     minimum for unhold */
12761 +       int tokens_max;                 /* Limit:     no more than N tokens */
12762 +
12763 +       int prio_bias;                  /* bias offset for priority */
12764 +       int vavavoom;                   /* last calculated vavavoom */
12765 +
12766 +       unsigned long norm_time;        /* last time accounted */
12767 +       unsigned long idle_time;        /* non linear time for fair sched */
12768 +       unsigned long token_time;       /* token time for accounting */
12769 +       unsigned long onhold;           /* jiffies when put on hold */
12770 +
12771 +       uint64_t user_ticks;            /* token tick events */
12772 +       uint64_t sys_ticks;             /* token tick events */
12773 +       uint64_t hold_ticks;            /* token ticks paused */
12774 +};
12775 +
12776 +
12777 +#define VXSF_ONHOLD    0x0001
12778 +#define VXSF_IDLE_TIME 0x0100
12779 +
12780 +#ifdef CONFIG_VSERVER_DEBUG
12781 +
12782 +static inline void __dump_vx_sched(struct _vx_sched *sched)
12783 +{
12784 +       printk("\t_vx_sched:\n");
12785 +       printk("\t tokens: %4d/%4d, %4d/%4d, %4d, %4d\n",
12786 +               sched->fill_rate[0], sched->interval[0],
12787 +               sched->fill_rate[1], sched->interval[1],
12788 +               sched->tokens_min, sched->tokens_max);
12789 +       printk("\t priority = %4d\n", sched->prio_bias);
12790 +}
12791 +
12792 +#endif
12793 +
12794 +#endif /* _VX_SCHED_DEF_H */
12795 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/sched.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/sched.h
12796 --- linux-2.6.36/include/linux/vserver/sched.h  1970-01-01 01:00:00.000000000 +0100
12797 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/sched.h    2010-10-21 13:09:36.000000000 +0200
12798 @@ -0,0 +1,26 @@
12799 +#ifndef _VX_SCHED_H
12800 +#define _VX_SCHED_H
12801 +
12802 +
12803 +#ifdef __KERNEL__
12804 +
12805 +struct timespec;
12806 +
12807 +void vx_vsi_uptime(struct timespec *, struct timespec *);
12808 +
12809 +
12810 +struct vx_info;
12811 +
12812 +void vx_update_load(struct vx_info *);
12813 +
12814 +
12815 +int vx_tokens_recalc(struct _vx_sched_pc *,
12816 +       unsigned long *, unsigned long *, int [2]);
12817 +
12818 +void vx_update_sched_param(struct _vx_sched *sched,
12819 +       struct _vx_sched_pc *sched_pc);
12820 +
12821 +#endif /* __KERNEL__ */
12822 +#else  /* _VX_SCHED_H */
12823 +#warning duplicate inclusion
12824 +#endif /* _VX_SCHED_H */
12825 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/signal_cmd.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/signal_cmd.h
12826 --- linux-2.6.36/include/linux/vserver/signal_cmd.h     1970-01-01 01:00:00.000000000 +0100
12827 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/signal_cmd.h       2010-10-21 13:09:36.000000000 +0200
12828 @@ -0,0 +1,43 @@
12829 +#ifndef _VX_SIGNAL_CMD_H
12830 +#define _VX_SIGNAL_CMD_H
12831 +
12832 +
12833 +/*  signalling vserver commands */
12834 +
12835 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
12836 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
12837 +
12838 +struct vcmd_ctx_kill_v0 {
12839 +       int32_t pid;
12840 +       int32_t sig;
12841 +};
12842 +
12843 +struct vcmd_wait_exit_v0 {
12844 +       int32_t reboot_cmd;
12845 +       int32_t exit_code;
12846 +};
12847 +
12848 +#ifdef __KERNEL__
12849 +
12850 +extern int vc_ctx_kill(struct vx_info *, void __user *);
12851 +extern int vc_wait_exit(struct vx_info *, void __user *);
12852 +
12853 +#endif /* __KERNEL__ */
12854 +
12855 +/*  process alteration commands */
12856 +
12857 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
12858 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
12859 +
12860 +struct vcmd_pflags_v0 {
12861 +       uint32_t flagword;
12862 +       uint32_t mask;
12863 +};
12864 +
12865 +#ifdef __KERNEL__
12866 +
12867 +extern int vc_get_pflags(uint32_t pid, void __user *);
12868 +extern int vc_set_pflags(uint32_t pid, void __user *);
12869 +
12870 +#endif /* __KERNEL__ */
12871 +#endif /* _VX_SIGNAL_CMD_H */
12872 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/signal.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/signal.h
12873 --- linux-2.6.36/include/linux/vserver/signal.h 1970-01-01 01:00:00.000000000 +0100
12874 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/signal.h   2010-10-21 13:09:36.000000000 +0200
12875 @@ -0,0 +1,14 @@
12876 +#ifndef _VX_SIGNAL_H
12877 +#define _VX_SIGNAL_H
12878 +
12879 +
12880 +#ifdef __KERNEL__
12881 +
12882 +struct vx_info;
12883 +
12884 +int vx_info_kill(struct vx_info *, int, int);
12885 +
12886 +#endif /* __KERNEL__ */
12887 +#else  /* _VX_SIGNAL_H */
12888 +#warning duplicate inclusion
12889 +#endif /* _VX_SIGNAL_H */
12890 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/space_cmd.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/space_cmd.h
12891 --- linux-2.6.36/include/linux/vserver/space_cmd.h      1970-01-01 01:00:00.000000000 +0100
12892 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/space_cmd.h        2010-10-21 13:09:36.000000000 +0200
12893 @@ -0,0 +1,38 @@
12894 +#ifndef _VX_SPACE_CMD_H
12895 +#define _VX_SPACE_CMD_H
12896 +
12897 +
12898 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
12899 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
12900 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
12901 +
12902 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
12903 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
12904 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
12905 +
12906 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
12907 +
12908 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
12909 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
12910 +
12911 +
12912 +struct vcmd_space_mask_v1 {
12913 +       uint64_t mask;
12914 +};
12915 +
12916 +struct vcmd_space_mask_v2 {
12917 +       uint64_t mask;
12918 +       uint32_t index;
12919 +};
12920 +
12921 +
12922 +#ifdef __KERNEL__
12923 +
12924 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
12925 +extern int vc_set_space_v1(struct vx_info *, void __user *);
12926 +extern int vc_enter_space(struct vx_info *, void __user *);
12927 +extern int vc_set_space(struct vx_info *, void __user *);
12928 +extern int vc_get_space_mask(void __user *, int);
12929 +
12930 +#endif /* __KERNEL__ */
12931 +#endif /* _VX_SPACE_CMD_H */
12932 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/space.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/space.h
12933 --- linux-2.6.36/include/linux/vserver/space.h  1970-01-01 01:00:00.000000000 +0100
12934 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/space.h    2010-10-21 13:09:36.000000000 +0200
12935 @@ -0,0 +1,12 @@
12936 +#ifndef _VX_SPACE_H
12937 +#define _VX_SPACE_H
12938 +
12939 +#include <linux/types.h>
12940 +
12941 +struct vx_info;
12942 +
12943 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
12944 +
12945 +#else  /* _VX_SPACE_H */
12946 +#warning duplicate inclusion
12947 +#endif /* _VX_SPACE_H */
12948 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/switch.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/switch.h
12949 --- linux-2.6.36/include/linux/vserver/switch.h 1970-01-01 01:00:00.000000000 +0100
12950 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/switch.h   2010-10-21 13:09:36.000000000 +0200
12951 @@ -0,0 +1,98 @@
12952 +#ifndef _VX_SWITCH_H
12953 +#define _VX_SWITCH_H
12954 +
12955 +#include <linux/types.h>
12956 +
12957 +
12958 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
12959 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
12960 +#define VC_VERSION(c)          ((c) & 0xFFF)
12961 +
12962 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
12963 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
12964 +
12965 +/*
12966 +
12967 +  Syscall Matrix V2.8
12968 +
12969 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
12970 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
12971 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
12972 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12973 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
12974 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
12975 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12976 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
12977 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
12978 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12979 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
12980 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
12981 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12982 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
12983 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
12984 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12985 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
12986 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
12987 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12988 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
12989 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
12990 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
12991 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
12992 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
12993 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12994 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
12995 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
12996 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12997 +
12998 +*/
12999 +
13000 +#define VC_CAT_VERSION         0
13001 +
13002 +#define VC_CAT_VSETUP          1
13003 +#define VC_CAT_VHOST           2
13004 +
13005 +#define VC_CAT_DEVICE          6
13006 +
13007 +#define VC_CAT_VPROC           9
13008 +#define VC_CAT_PROCALT         10
13009 +#define VC_CAT_PROCMIG         11
13010 +#define VC_CAT_PROCTRL         12
13011 +
13012 +#define VC_CAT_SCHED           14
13013 +#define VC_CAT_MEMCTRL         20
13014 +
13015 +#define VC_CAT_VNET            25
13016 +#define VC_CAT_NETALT          26
13017 +#define VC_CAT_NETMIG          27
13018 +#define VC_CAT_NETCTRL         28
13019 +
13020 +#define VC_CAT_TAGMIG          35
13021 +#define VC_CAT_DLIMIT          36
13022 +#define VC_CAT_INODE           38
13023 +
13024 +#define VC_CAT_VSTAT           40
13025 +#define VC_CAT_VINFO           46
13026 +#define VC_CAT_EVENT           48
13027 +
13028 +#define VC_CAT_FLAGS           52
13029 +#define VC_CAT_VSPACE          54
13030 +#define VC_CAT_DEBUG           56
13031 +#define VC_CAT_RLIMIT          60
13032 +
13033 +#define VC_CAT_SYSTEST         61
13034 +#define VC_CAT_COMPAT          63
13035 +
13036 +/*  query version */
13037 +
13038 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13039 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13040 +
13041 +
13042 +#ifdef __KERNEL__
13043 +
13044 +#include <linux/errno.h>
13045 +
13046 +#endif /* __KERNEL__ */
13047 +
13048 +#endif /* _VX_SWITCH_H */
13049 +
13050 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/tag_cmd.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/tag_cmd.h
13051 --- linux-2.6.36/include/linux/vserver/tag_cmd.h        1970-01-01 01:00:00.000000000 +0100
13052 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/tag_cmd.h  2010-10-21 13:09:36.000000000 +0200
13053 @@ -0,0 +1,22 @@
13054 +#ifndef _VX_TAG_CMD_H
13055 +#define _VX_TAG_CMD_H
13056 +
13057 +
13058 +/* vinfo commands */
13059 +
13060 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13061 +
13062 +#ifdef __KERNEL__
13063 +extern int vc_task_tag(uint32_t);
13064 +
13065 +#endif /* __KERNEL__ */
13066 +
13067 +/* context commands */
13068 +
13069 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13070 +
13071 +#ifdef __KERNEL__
13072 +extern int vc_tag_migrate(uint32_t);
13073 +
13074 +#endif /* __KERNEL__ */
13075 +#endif /* _VX_TAG_CMD_H */
13076 diff -NurpP --minimal linux-2.6.36/include/linux/vserver/tag.h linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/tag.h
13077 --- linux-2.6.36/include/linux/vserver/tag.h    1970-01-01 01:00:00.000000000 +0100
13078 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/tag.h      2010-10-21 13:09:36.000000000 +0200
13079 @@ -0,0 +1,143 @@
13080 +#ifndef _DX_TAG_H
13081 +#define _DX_TAG_H
13082 +
13083 +#include <linux/types.h>
13084 +
13085 +
13086 +#define DX_TAG(in)     (IS_TAGGED(in))
13087 +
13088 +
13089 +#ifdef CONFIG_TAG_NFSD
13090 +#define DX_TAG_NFSD    1
13091 +#else
13092 +#define DX_TAG_NFSD    0
13093 +#endif
13094 +
13095 +
13096 +#ifdef CONFIG_TAGGING_NONE
13097 +
13098 +#define MAX_UID                0xFFFFFFFF
13099 +#define MAX_GID                0xFFFFFFFF
13100 +
13101 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
13102 +
13103 +#define TAGINO_UID(cond, uid, tag)     (uid)
13104 +#define TAGINO_GID(cond, gid, tag)     (gid)
13105 +
13106 +#endif
13107 +
13108 +
13109 +#ifdef CONFIG_TAGGING_GID16
13110 +
13111 +#define MAX_UID                0xFFFFFFFF
13112 +#define MAX_GID                0x0000FFFF
13113 +
13114 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13115 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
13116 +
13117 +#define TAGINO_UID(cond, uid, tag)     (uid)
13118 +#define TAGINO_GID(cond, gid, tag)     \
13119 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
13120 +
13121 +#endif
13122 +
13123 +
13124 +#ifdef CONFIG_TAGGING_ID24
13125 +
13126 +#define MAX_UID                0x00FFFFFF
13127 +#define MAX_GID                0x00FFFFFF
13128 +
13129 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13130 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
13131 +
13132 +#define TAGINO_UID(cond, uid, tag)     \
13133 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
13134 +#define TAGINO_GID(cond, gid, tag)     \
13135 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
13136 +
13137 +#endif
13138 +
13139 +
13140 +#ifdef CONFIG_TAGGING_UID16
13141 +
13142 +#define MAX_UID                0x0000FFFF
13143 +#define MAX_GID                0xFFFFFFFF
13144 +
13145 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13146 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
13147 +
13148 +#define TAGINO_UID(cond, uid, tag)     \
13149 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
13150 +#define TAGINO_GID(cond, gid, tag)     (gid)
13151 +
13152 +#endif
13153 +
13154 +
13155 +#ifdef CONFIG_TAGGING_INTERN
13156 +
13157 +#define MAX_UID                0xFFFFFFFF
13158 +#define MAX_GID                0xFFFFFFFF
13159 +
13160 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13161 +       ((cond) ? (tag) : 0)
13162 +
13163 +#define TAGINO_UID(cond, uid, tag)     (uid)
13164 +#define TAGINO_GID(cond, gid, tag)     (gid)
13165 +
13166 +#endif
13167 +
13168 +
13169 +#ifndef CONFIG_TAGGING_NONE
13170 +#define dx_current_fstag(sb)   \
13171 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
13172 +#else
13173 +#define dx_current_fstag(sb)   (0)
13174 +#endif
13175 +
13176 +#ifndef CONFIG_TAGGING_INTERN
13177 +#define TAGINO_TAG(cond, tag)  (0)
13178 +#else
13179 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
13180 +#endif
13181 +
13182 +#define INOTAG_UID(cond, uid, gid)     \
13183 +       ((cond) ? ((uid) & MAX_UID) : (uid))
13184 +#define INOTAG_GID(cond, uid, gid)     \
13185 +       ((cond) ? ((gid) & MAX_GID) : (gid))
13186 +
13187 +
13188 +static inline uid_t dx_map_uid(uid_t uid)
13189 +{
13190 +       if ((uid > MAX_UID) && (uid != -1))
13191 +               uid = -2;
13192 +       return (uid & MAX_UID);
13193 +}
13194 +
13195 +static inline gid_t dx_map_gid(gid_t gid)
13196 +{
13197 +       if ((gid > MAX_GID) && (gid != -1))
13198 +               gid = -2;
13199 +       return (gid & MAX_GID);
13200 +}
13201 +
13202 +struct peer_tag {
13203 +       int32_t xid;
13204 +       int32_t nid;
13205 +};
13206 +
13207 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
13208 +
13209 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
13210 +                unsigned long *flags);
13211 +
13212 +#ifdef CONFIG_PROPAGATE
13213 +
13214 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
13215 +
13216 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
13217 +
13218 +#else
13219 +#define dx_propagate_tag(n, i) do { } while (0)
13220 +#endif
13221 +
13222 +#endif /* _DX_TAG_H */
13223 diff -NurpP --minimal linux-2.6.36/include/linux/vs_inet6.h linux-2.6.36-vs2.3.0.36.33/include/linux/vs_inet6.h
13224 --- linux-2.6.36/include/linux/vs_inet6.h       1970-01-01 01:00:00.000000000 +0100
13225 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vs_inet6.h 2010-10-21 13:09:36.000000000 +0200
13226 @@ -0,0 +1,246 @@
13227 +#ifndef _VS_INET6_H
13228 +#define _VS_INET6_H
13229 +
13230 +#include "vserver/base.h"
13231 +#include "vserver/network.h"
13232 +#include "vserver/debug.h"
13233 +
13234 +#include <net/ipv6.h>
13235 +
13236 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
13237 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
13238 +
13239 +
13240 +#ifdef CONFIG_IPV6
13241 +
13242 +static inline
13243 +int v6_addr_match(struct nx_addr_v6 *nxa,
13244 +       const struct in6_addr *addr, uint16_t mask)
13245 +{
13246 +       int ret = 0;
13247 +
13248 +       switch (nxa->type & mask) {
13249 +       case NXA_TYPE_MASK:
13250 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
13251 +               break;
13252 +       case NXA_TYPE_ADDR:
13253 +               ret = ipv6_addr_equal(&nxa->ip, addr);
13254 +               break;
13255 +       case NXA_TYPE_ANY:
13256 +               ret = 1;
13257 +               break;
13258 +       }
13259 +       vxdprintk(VXD_CBIT(net, 0),
13260 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
13261 +               nxa, NXAV6(nxa), addr, mask, ret);
13262 +       return ret;
13263 +}
13264 +
13265 +static inline
13266 +int v6_addr_in_nx_info(struct nx_info *nxi,
13267 +       const struct in6_addr *addr, uint16_t mask)
13268 +{
13269 +       struct nx_addr_v6 *nxa;
13270 +       int ret = 1;
13271 +
13272 +       if (!nxi)
13273 +               goto out;
13274 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
13275 +               if (v6_addr_match(nxa, addr, mask))
13276 +                       goto out;
13277 +       ret = 0;
13278 +out:
13279 +       vxdprintk(VXD_CBIT(net, 0),
13280 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
13281 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
13282 +       return ret;
13283 +}
13284 +
13285 +static inline
13286 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
13287 +{
13288 +       /* FIXME: needs full range checks */
13289 +       return v6_addr_match(nxa, &addr->ip, mask);
13290 +}
13291 +
13292 +static inline
13293 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
13294 +{
13295 +       struct nx_addr_v6 *ptr;
13296 +
13297 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
13298 +               if (v6_nx_addr_match(ptr, nxa, mask))
13299 +                       return 1;
13300 +       return 0;
13301 +}
13302 +
13303 +
13304 +/*
13305 + *     Check if a given address matches for a socket
13306 + *
13307 + *     nxi:            the socket's nx_info if any
13308 + *     addr:           to be verified address
13309 + */
13310 +static inline
13311 +int v6_sock_addr_match (
13312 +       struct nx_info *nxi,
13313 +       struct inet_sock *inet,
13314 +       struct in6_addr *addr)
13315 +{
13316 +       struct sock *sk = &inet->sk;
13317 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13318 +
13319 +       if (!ipv6_addr_any(addr) &&
13320 +               ipv6_addr_equal(saddr, addr))
13321 +               return 1;
13322 +       if (ipv6_addr_any(saddr))
13323 +               return v6_addr_in_nx_info(nxi, addr, -1);
13324 +       return 0;
13325 +}
13326 +
13327 +/*
13328 + *     check if address is covered by socket
13329 + *
13330 + *     sk:     the socket to check against
13331 + *     addr:   the address in question (must be != 0)
13332 + */
13333 +
13334 +static inline
13335 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
13336 +{
13337 +       struct nx_info *nxi = sk->sk_nx_info;
13338 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13339 +
13340 +       vxdprintk(VXD_CBIT(net, 5),
13341 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
13342 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
13343 +               (sk->sk_socket?sk->sk_socket->flags:0));
13344 +
13345 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
13346 +               return v6_addr_match(nxa, saddr, -1);
13347 +       } else if (nxi) {               /* match against nx_info */
13348 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
13349 +       } else {                        /* unrestricted any socket */
13350 +               return 1;
13351 +       }
13352 +}
13353 +
13354 +
13355 +/* inet related checks and helpers */
13356 +
13357 +
13358 +struct in_ifaddr;
13359 +struct net_device;
13360 +struct sock;
13361 +
13362 +
13363 +#include <linux/netdevice.h>
13364 +#include <linux/inetdevice.h>
13365 +#include <net/inet_timewait_sock.h>
13366 +
13367 +
13368 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13369 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
13370 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
13371 +
13372 +
13373 +
13374 +static inline
13375 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
13376 +{
13377 +       if (!nxi)
13378 +               return 1;
13379 +       if (!ifa)
13380 +               return 0;
13381 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
13382 +}
13383 +
13384 +static inline
13385 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
13386 +{
13387 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
13388 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13389 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
13390 +
13391 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13392 +               return 1;
13393 +       if (v6_ifa_in_nx_info(ifa, nxi))
13394 +               return 1;
13395 +       return 0;
13396 +}
13397 +
13398 +
13399 +struct nx_v6_sock_addr {
13400 +       struct in6_addr saddr;  /* Address used for validation */
13401 +       struct in6_addr baddr;  /* Address used for socket bind */
13402 +};
13403 +
13404 +static inline
13405 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
13406 +       struct nx_v6_sock_addr *nsa)
13407 +{
13408 +       // struct sock *sk = &inet->sk;
13409 +       // struct nx_info *nxi = sk->sk_nx_info;
13410 +       struct in6_addr saddr = addr->sin6_addr;
13411 +       struct in6_addr baddr = saddr;
13412 +
13413 +       nsa->saddr = saddr;
13414 +       nsa->baddr = baddr;
13415 +       return 0;
13416 +}
13417 +
13418 +static inline
13419 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
13420 +{
13421 +       // struct sock *sk = &inet->sk;
13422 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
13423 +
13424 +       // *saddr = nsa->baddr;
13425 +       // inet->inet_saddr = nsa->baddr;
13426 +}
13427 +
13428 +static inline
13429 +int nx_info_has_v6(struct nx_info *nxi)
13430 +{
13431 +       if (!nxi)
13432 +               return 1;
13433 +       if (NX_IPV6(nxi))
13434 +               return 1;
13435 +       return 0;
13436 +}
13437 +
13438 +#else /* CONFIG_IPV6 */
13439 +
13440 +static inline
13441 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
13442 +{
13443 +       return 1;
13444 +}
13445 +
13446 +
13447 +static inline
13448 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13449 +{
13450 +       return 1;
13451 +}
13452 +
13453 +static inline
13454 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13455 +{
13456 +       return 1;
13457 +}
13458 +
13459 +static inline
13460 +int nx_info_has_v6(struct nx_info *nxi)
13461 +{
13462 +       return 0;
13463 +}
13464 +
13465 +#endif /* CONFIG_IPV6 */
13466 +
13467 +#define current_nx_info_has_v6() \
13468 +       nx_info_has_v6(current_nx_info())
13469 +
13470 +#else
13471 +#warning duplicate inclusion
13472 +#endif
13473 diff -NurpP --minimal linux-2.6.36/include/linux/vs_inet.h linux-2.6.36-vs2.3.0.36.33/include/linux/vs_inet.h
13474 --- linux-2.6.36/include/linux/vs_inet.h        1970-01-01 01:00:00.000000000 +0100
13475 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vs_inet.h  2010-10-21 14:48:51.000000000 +0200
13476 @@ -0,0 +1,350 @@
13477 +#ifndef _VS_INET_H
13478 +#define _VS_INET_H
13479 +
13480 +#include "vserver/base.h"
13481 +#include "vserver/network.h"
13482 +#include "vserver/debug.h"
13483 +
13484 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
13485 +
13486 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
13487 +                       NIPQUAD((a)->mask), (a)->type
13488 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
13489 +
13490 +#define NIPQUAD(addr) \
13491 +       ((unsigned char *)&addr)[0], \
13492 +       ((unsigned char *)&addr)[1], \
13493 +       ((unsigned char *)&addr)[2], \
13494 +       ((unsigned char *)&addr)[3]
13495 +
13496 +#define NIPQUAD_FMT "%u.%u.%u.%u"
13497 +
13498 +
13499 +static inline
13500 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
13501 +{
13502 +       __be32 ip = nxa->ip[0].s_addr;
13503 +       __be32 mask = nxa->mask.s_addr;
13504 +       __be32 bcast = ip | ~mask;
13505 +       int ret = 0;
13506 +
13507 +       switch (nxa->type & tmask) {
13508 +       case NXA_TYPE_MASK:
13509 +               ret = (ip == (addr & mask));
13510 +               break;
13511 +       case NXA_TYPE_ADDR:
13512 +               ret = 3;
13513 +               if (addr == ip)
13514 +                       break;
13515 +               /* fall through to broadcast */
13516 +       case NXA_MOD_BCAST:
13517 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
13518 +               break;
13519 +       case NXA_TYPE_RANGE:
13520 +               ret = ((nxa->ip[0].s_addr <= addr) &&
13521 +                       (nxa->ip[1].s_addr > addr));
13522 +               break;
13523 +       case NXA_TYPE_ANY:
13524 +               ret = 2;
13525 +               break;
13526 +       }
13527 +
13528 +       vxdprintk(VXD_CBIT(net, 0),
13529 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
13530 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
13531 +       return ret;
13532 +}
13533 +
13534 +static inline
13535 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
13536 +{
13537 +       struct nx_addr_v4 *nxa;
13538 +       int ret = 1;
13539 +
13540 +       if (!nxi)
13541 +               goto out;
13542 +
13543 +       ret = 2;
13544 +       /* allow 127.0.0.1 when remapping lback */
13545 +       if ((tmask & NXA_LOOPBACK) &&
13546 +               (addr == IPI_LOOPBACK) &&
13547 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13548 +               goto out;
13549 +       ret = 3;
13550 +       /* check for lback address */
13551 +       if ((tmask & NXA_MOD_LBACK) &&
13552 +               (nxi->v4_lback.s_addr == addr))
13553 +               goto out;
13554 +       ret = 4;
13555 +       /* check for broadcast address */
13556 +       if ((tmask & NXA_MOD_BCAST) &&
13557 +               (nxi->v4_bcast.s_addr == addr))
13558 +               goto out;
13559 +       ret = 5;
13560 +       /* check for v4 addresses */
13561 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
13562 +               if (v4_addr_match(nxa, addr, tmask))
13563 +                       goto out;
13564 +       ret = 0;
13565 +out:
13566 +       vxdprintk(VXD_CBIT(net, 0),
13567 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
13568 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
13569 +       return ret;
13570 +}
13571 +
13572 +static inline
13573 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
13574 +{
13575 +       /* FIXME: needs full range checks */
13576 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
13577 +}
13578 +
13579 +static inline
13580 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
13581 +{
13582 +       struct nx_addr_v4 *ptr;
13583 +
13584 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
13585 +               if (v4_nx_addr_match(ptr, nxa, mask))
13586 +                       return 1;
13587 +       return 0;
13588 +}
13589 +
13590 +#include <net/inet_sock.h>
13591 +
13592 +/*
13593 + *     Check if a given address matches for a socket
13594 + *
13595 + *     nxi:            the socket's nx_info if any
13596 + *     addr:           to be verified address
13597 + */
13598 +static inline
13599 +int v4_sock_addr_match (
13600 +       struct nx_info *nxi,
13601 +       struct inet_sock *inet,
13602 +       __be32 addr)
13603 +{
13604 +       __be32 saddr = inet->inet_rcv_saddr;
13605 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
13606 +
13607 +       if (addr && (saddr == addr || bcast == addr))
13608 +               return 1;
13609 +       if (!saddr)
13610 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
13611 +       return 0;
13612 +}
13613 +
13614 +
13615 +/* inet related checks and helpers */
13616 +
13617 +
13618 +struct in_ifaddr;
13619 +struct net_device;
13620 +struct sock;
13621 +
13622 +#ifdef CONFIG_INET
13623 +
13624 +#include <linux/netdevice.h>
13625 +#include <linux/inetdevice.h>
13626 +#include <net/inet_sock.h>
13627 +#include <net/inet_timewait_sock.h>
13628 +
13629 +
13630 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13631 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
13632 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
13633 +
13634 +
13635 +/*
13636 + *     check if address is covered by socket
13637 + *
13638 + *     sk:     the socket to check against
13639 + *     addr:   the address in question (must be != 0)
13640 + */
13641 +
13642 +static inline
13643 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
13644 +{
13645 +       struct nx_info *nxi = sk->sk_nx_info;
13646 +       __be32 saddr = inet_rcv_saddr(sk);
13647 +
13648 +       vxdprintk(VXD_CBIT(net, 5),
13649 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
13650 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
13651 +               (sk->sk_socket?sk->sk_socket->flags:0));
13652 +
13653 +       if (saddr) {            /* direct address match */
13654 +               return v4_addr_match(nxa, saddr, -1);
13655 +       } else if (nxi) {       /* match against nx_info */
13656 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
13657 +       } else {                /* unrestricted any socket */
13658 +               return 1;
13659 +       }
13660 +}
13661 +
13662 +
13663 +
13664 +static inline
13665 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
13666 +{
13667 +       vxdprintk(VXD_CBIT(net, 1), "nx_dev_visible(%p[#%u],%p »%s«) %d",
13668 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
13669 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
13670 +
13671 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13672 +               return 1;
13673 +       if (dev_in_nx_info(dev, nxi))
13674 +               return 1;
13675 +       return 0;
13676 +}
13677 +
13678 +
13679 +static inline
13680 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
13681 +{
13682 +       if (!nxi)
13683 +               return 1;
13684 +       if (!ifa)
13685 +               return 0;
13686 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
13687 +}
13688 +
13689 +static inline
13690 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
13691 +{
13692 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
13693 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13694 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
13695 +
13696 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13697 +               return 1;
13698 +       if (v4_ifa_in_nx_info(ifa, nxi))
13699 +               return 1;
13700 +       return 0;
13701 +}
13702 +
13703 +
13704 +struct nx_v4_sock_addr {
13705 +       __be32 saddr;   /* Address used for validation */
13706 +       __be32 baddr;   /* Address used for socket bind */
13707 +};
13708 +
13709 +static inline
13710 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
13711 +       struct nx_v4_sock_addr *nsa)
13712 +{
13713 +       struct sock *sk = &inet->sk;
13714 +       struct nx_info *nxi = sk->sk_nx_info;
13715 +       __be32 saddr = addr->sin_addr.s_addr;
13716 +       __be32 baddr = saddr;
13717 +
13718 +       vxdprintk(VXD_CBIT(net, 3),
13719 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
13720 +               sk, sk->sk_nx_info, sk->sk_socket,
13721 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
13722 +               NIPQUAD(saddr));
13723 +
13724 +       if (nxi) {
13725 +               if (saddr == INADDR_ANY) {
13726 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
13727 +                               baddr = nxi->v4.ip[0].s_addr;
13728 +               } else if (saddr == IPI_LOOPBACK) {
13729 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13730 +                               baddr = nxi->v4_lback.s_addr;
13731 +               } else {        /* normal address bind */
13732 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
13733 +                               return -EADDRNOTAVAIL;
13734 +               }
13735 +       }
13736 +
13737 +       vxdprintk(VXD_CBIT(net, 3),
13738 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
13739 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
13740 +
13741 +       nsa->saddr = saddr;
13742 +       nsa->baddr = baddr;
13743 +       return 0;
13744 +}
13745 +
13746 +static inline
13747 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
13748 +{
13749 +       inet->inet_saddr = nsa->baddr;
13750 +       inet->inet_rcv_saddr = nsa->baddr;
13751 +}
13752 +
13753 +
13754 +/*
13755 + *      helper to simplify inet_lookup_listener
13756 + *
13757 + *      nxi:   the socket's nx_info if any
13758 + *      addr:  to be verified address
13759 + *      saddr: socket address
13760 + */
13761 +static inline int v4_inet_addr_match (
13762 +       struct nx_info *nxi,
13763 +       __be32 addr,
13764 +       __be32 saddr)
13765 +{
13766 +       if (addr && (saddr == addr))
13767 +               return 1;
13768 +       if (!saddr)
13769 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
13770 +       return 0;
13771 +}
13772 +
13773 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
13774 +{
13775 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
13776 +               (addr == nxi->v4_lback.s_addr))
13777 +               return IPI_LOOPBACK;
13778 +       return addr;
13779 +}
13780 +
13781 +static inline
13782 +int nx_info_has_v4(struct nx_info *nxi)
13783 +{
13784 +       if (!nxi)
13785 +               return 1;
13786 +       if (NX_IPV4(nxi))
13787 +               return 1;
13788 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13789 +               return 1;
13790 +       return 0;
13791 +}
13792 +
13793 +#else /* CONFIG_INET */
13794 +
13795 +static inline
13796 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
13797 +{
13798 +       return 1;
13799 +}
13800 +
13801 +static inline
13802 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13803 +{
13804 +       return 1;
13805 +}
13806 +
13807 +static inline
13808 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13809 +{
13810 +       return 1;
13811 +}
13812 +
13813 +static inline
13814 +int nx_info_has_v4(struct nx_info *nxi)
13815 +{
13816 +       return 0;
13817 +}
13818 +
13819 +#endif /* CONFIG_INET */
13820 +
13821 +#define current_nx_info_has_v4() \
13822 +       nx_info_has_v4(current_nx_info())
13823 +
13824 +#else
13825 +// #warning duplicate inclusion
13826 +#endif
13827 diff -NurpP --minimal linux-2.6.36/include/linux/vs_limit.h linux-2.6.36-vs2.3.0.36.33/include/linux/vs_limit.h
13828 --- linux-2.6.36/include/linux/vs_limit.h       1970-01-01 01:00:00.000000000 +0100
13829 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vs_limit.h 2010-10-21 13:09:36.000000000 +0200
13830 @@ -0,0 +1,140 @@
13831 +#ifndef _VS_LIMIT_H
13832 +#define _VS_LIMIT_H
13833 +
13834 +#include "vserver/limit.h"
13835 +#include "vserver/base.h"
13836 +#include "vserver/context.h"
13837 +#include "vserver/debug.h"
13838 +#include "vserver/context.h"
13839 +#include "vserver/limit_int.h"
13840 +
13841 +
13842 +#define vx_acc_cres(v, d, p, r) \
13843 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
13844 +
13845 +#define vx_acc_cres_cond(x, d, p, r) \
13846 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
13847 +       r, d, p, __FILE__, __LINE__)
13848 +
13849 +
13850 +#define vx_add_cres(v, a, p, r) \
13851 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
13852 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
13853 +
13854 +#define vx_add_cres_cond(x, a, p, r) \
13855 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
13856 +       r, a, p, __FILE__, __LINE__)
13857 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
13858 +
13859 +
13860 +/* process and file limits */
13861 +
13862 +#define vx_nproc_inc(p) \
13863 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
13864 +
13865 +#define vx_nproc_dec(p) \
13866 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
13867 +
13868 +#define vx_files_inc(f) \
13869 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
13870 +
13871 +#define vx_files_dec(f) \
13872 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
13873 +
13874 +#define vx_locks_inc(l) \
13875 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
13876 +
13877 +#define vx_locks_dec(l) \
13878 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
13879 +
13880 +#define vx_openfd_inc(f) \
13881 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
13882 +
13883 +#define vx_openfd_dec(f) \
13884 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
13885 +
13886 +
13887 +#define vx_cres_avail(v, n, r) \
13888 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
13889 +
13890 +
13891 +#define vx_nproc_avail(n) \
13892 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
13893 +
13894 +#define vx_files_avail(n) \
13895 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
13896 +
13897 +#define vx_locks_avail(n) \
13898 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
13899 +
13900 +#define vx_openfd_avail(n) \
13901 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
13902 +
13903 +
13904 +/* dentry limits */
13905 +
13906 +#define vx_dentry_inc(d) do {                                          \
13907 +       if (atomic_read(&d->d_count) == 1)                              \
13908 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
13909 +       } while (0)
13910 +
13911 +#define vx_dentry_dec(d) do {                                          \
13912 +       if (atomic_read(&d->d_count) == 0)                              \
13913 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
13914 +       } while (0)
13915 +
13916 +#define vx_dentry_avail(n) \
13917 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
13918 +
13919 +
13920 +/* socket limits */
13921 +
13922 +#define vx_sock_inc(s) \
13923 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
13924 +
13925 +#define vx_sock_dec(s) \
13926 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
13927 +
13928 +#define vx_sock_avail(n) \
13929 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
13930 +
13931 +
13932 +/* ipc resource limits */
13933 +
13934 +#define vx_ipcmsg_add(v, u, a) \
13935 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
13936 +
13937 +#define vx_ipcmsg_sub(v, u, a) \
13938 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
13939 +
13940 +#define vx_ipcmsg_avail(v, a) \
13941 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
13942 +
13943 +
13944 +#define vx_ipcshm_add(v, k, a) \
13945 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
13946 +
13947 +#define vx_ipcshm_sub(v, k, a) \
13948 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
13949 +
13950 +#define vx_ipcshm_avail(v, a) \
13951 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
13952 +
13953 +
13954 +#define vx_semary_inc(a) \
13955 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
13956 +
13957 +#define vx_semary_dec(a) \
13958 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
13959 +
13960 +
13961 +#define vx_nsems_add(a,n) \
13962 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
13963 +
13964 +#define vx_nsems_sub(a,n) \
13965 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
13966 +
13967 +
13968 +#else
13969 +#warning duplicate inclusion
13970 +#endif
13971 diff -NurpP --minimal linux-2.6.36/include/linux/vs_memory.h linux-2.6.36-vs2.3.0.36.33/include/linux/vs_memory.h
13972 --- linux-2.6.36/include/linux/vs_memory.h      1970-01-01 01:00:00.000000000 +0100
13973 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vs_memory.h        2010-10-21 13:09:36.000000000 +0200
13974 @@ -0,0 +1,58 @@
13975 +#ifndef _VS_MEMORY_H
13976 +#define _VS_MEMORY_H
13977 +
13978 +#include "vserver/limit.h"
13979 +#include "vserver/base.h"
13980 +#include "vserver/context.h"
13981 +#include "vserver/debug.h"
13982 +#include "vserver/context.h"
13983 +#include "vserver/limit_int.h"
13984 +
13985 +enum {
13986 +       VXPT_UNKNOWN = 0,
13987 +       VXPT_ANON,
13988 +       VXPT_NONE,
13989 +       VXPT_FILE,
13990 +       VXPT_SWAP,
13991 +       VXPT_WRITE
13992 +};
13993 +
13994 +#if 0
13995 +#define        vx_page_fault(mm, vma, type, ret)
13996 +#else
13997 +
13998 +static inline
13999 +void __vx_page_fault(struct mm_struct *mm,
14000 +       struct vm_area_struct *vma, int type, int ret)
14001 +{
14002 +       struct vx_info *vxi = mm->mm_vx_info;
14003 +       int what;
14004 +/*
14005 +       static char *page_type[6] =
14006 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
14007 +       static char *page_what[4] =
14008 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
14009 +*/
14010 +
14011 +       if (!vxi)
14012 +               return;
14013 +
14014 +       what = (ret & 0x3);
14015 +
14016 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
14017 +               type, what, ret, page_type[type], page_what[what]);
14018 +*/
14019 +       if (ret & VM_FAULT_WRITE)
14020 +               what |= 0x4;
14021 +       atomic_inc(&vxi->cacct.page[type][what]);
14022 +}
14023 +
14024 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
14025 +#endif
14026 +
14027 +
14028 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
14029 +
14030 +#else
14031 +#warning duplicate inclusion
14032 +#endif
14033 diff -NurpP --minimal linux-2.6.36/include/linux/vs_network.h linux-2.6.36-vs2.3.0.36.33/include/linux/vs_network.h
14034 --- linux-2.6.36/include/linux/vs_network.h     1970-01-01 01:00:00.000000000 +0100
14035 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vs_network.h       2010-10-21 13:09:36.000000000 +0200
14036 @@ -0,0 +1,169 @@
14037 +#ifndef _NX_VS_NETWORK_H
14038 +#define _NX_VS_NETWORK_H
14039 +
14040 +#include "vserver/context.h"
14041 +#include "vserver/network.h"
14042 +#include "vserver/base.h"
14043 +#include "vserver/check.h"
14044 +#include "vserver/debug.h"
14045 +
14046 +#include <linux/sched.h>
14047 +
14048 +
14049 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
14050 +
14051 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
14052 +       const char *_file, int _line)
14053 +{
14054 +       if (!nxi)
14055 +               return NULL;
14056 +
14057 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
14058 +               nxi, nxi ? nxi->nx_id : 0,
14059 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14060 +               _file, _line);
14061 +
14062 +       atomic_inc(&nxi->nx_usecnt);
14063 +       return nxi;
14064 +}
14065 +
14066 +
14067 +extern void free_nx_info(struct nx_info *);
14068 +
14069 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
14070 +
14071 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
14072 +{
14073 +       if (!nxi)
14074 +               return;
14075 +
14076 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
14077 +               nxi, nxi ? nxi->nx_id : 0,
14078 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14079 +               _file, _line);
14080 +
14081 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
14082 +               free_nx_info(nxi);
14083 +}
14084 +
14085 +
14086 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
14087 +
14088 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14089 +               const char *_file, int _line)
14090 +{
14091 +       if (nxi) {
14092 +               vxlprintk(VXD_CBIT(nid, 3),
14093 +                       "init_nx_info(%p[#%d.%d])",
14094 +                       nxi, nxi ? nxi->nx_id : 0,
14095 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14096 +                       _file, _line);
14097 +
14098 +               atomic_inc(&nxi->nx_usecnt);
14099 +       }
14100 +       *nxp = nxi;
14101 +}
14102 +
14103 +
14104 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
14105 +
14106 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14107 +       const char *_file, int _line)
14108 +{
14109 +       struct nx_info *nxo;
14110 +
14111 +       if (!nxi)
14112 +               return;
14113 +
14114 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
14115 +               nxi, nxi ? nxi->nx_id : 0,
14116 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14117 +               _file, _line);
14118 +
14119 +       atomic_inc(&nxi->nx_usecnt);
14120 +       nxo = xchg(nxp, nxi);
14121 +       BUG_ON(nxo);
14122 +}
14123 +
14124 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
14125 +
14126 +static inline void __clr_nx_info(struct nx_info **nxp,
14127 +       const char *_file, int _line)
14128 +{
14129 +       struct nx_info *nxo;
14130 +
14131 +       nxo = xchg(nxp, NULL);
14132 +       if (!nxo)
14133 +               return;
14134 +
14135 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
14136 +               nxo, nxo ? nxo->nx_id : 0,
14137 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
14138 +               _file, _line);
14139 +
14140 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
14141 +               free_nx_info(nxo);
14142 +}
14143 +
14144 +
14145 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
14146 +
14147 +static inline void __claim_nx_info(struct nx_info *nxi,
14148 +       struct task_struct *task, const char *_file, int _line)
14149 +{
14150 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
14151 +               nxi, nxi ? nxi->nx_id : 0,
14152 +               nxi?atomic_read(&nxi->nx_usecnt):0,
14153 +               nxi?atomic_read(&nxi->nx_tasks):0,
14154 +               task, _file, _line);
14155 +
14156 +       atomic_inc(&nxi->nx_tasks);
14157 +}
14158 +
14159 +
14160 +extern void unhash_nx_info(struct nx_info *);
14161 +
14162 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
14163 +
14164 +static inline void __release_nx_info(struct nx_info *nxi,
14165 +       struct task_struct *task, const char *_file, int _line)
14166 +{
14167 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
14168 +               nxi, nxi ? nxi->nx_id : 0,
14169 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14170 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
14171 +               task, _file, _line);
14172 +
14173 +       might_sleep();
14174 +
14175 +       if (atomic_dec_and_test(&nxi->nx_tasks))
14176 +               unhash_nx_info(nxi);
14177 +}
14178 +
14179 +
14180 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
14181 +
14182 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
14183 +       const char *_file, int _line)
14184 +{
14185 +       struct nx_info *nxi;
14186 +
14187 +       task_lock(p);
14188 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
14189 +               p, _file, _line);
14190 +       nxi = __get_nx_info(p->nx_info, _file, _line);
14191 +       task_unlock(p);
14192 +       return nxi;
14193 +}
14194 +
14195 +
14196 +static inline void exit_nx_info(struct task_struct *p)
14197 +{
14198 +       if (p->nx_info)
14199 +               release_nx_info(p->nx_info, p);
14200 +}
14201 +
14202 +
14203 +#else
14204 +#warning duplicate inclusion
14205 +#endif
14206 diff -NurpP --minimal linux-2.6.36/include/linux/vs_pid.h linux-2.6.36-vs2.3.0.36.33/include/linux/vs_pid.h
14207 --- linux-2.6.36/include/linux/vs_pid.h 1970-01-01 01:00:00.000000000 +0100
14208 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vs_pid.h   2010-10-21 13:09:36.000000000 +0200
14209 @@ -0,0 +1,95 @@
14210 +#ifndef _VS_PID_H
14211 +#define _VS_PID_H
14212 +
14213 +#include "vserver/base.h"
14214 +#include "vserver/check.h"
14215 +#include "vserver/context.h"
14216 +#include "vserver/debug.h"
14217 +#include "vserver/pid.h"
14218 +#include <linux/pid_namespace.h>
14219 +
14220 +
14221 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
14222 +
14223 +static inline
14224 +int vx_proc_task_visible(struct task_struct *task)
14225 +{
14226 +       if ((task->pid == 1) &&
14227 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
14228 +               /* show a blend through init */
14229 +               goto visible;
14230 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
14231 +               goto visible;
14232 +       return 0;
14233 +visible:
14234 +       return 1;
14235 +}
14236 +
14237 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
14238 +
14239 +#if 0
14240 +
14241 +static inline
14242 +struct task_struct *vx_find_proc_task_by_pid(int pid)
14243 +{
14244 +       struct task_struct *task = find_task_by_real_pid(pid);
14245 +
14246 +       if (task && !vx_proc_task_visible(task)) {
14247 +               vxdprintk(VXD_CBIT(misc, 6),
14248 +                       "dropping task (find) %p[#%u,%u] for %p[#%u,%u]",
14249 +                       task, task->xid, task->pid,
14250 +                       current, current->xid, current->pid);
14251 +               task = NULL;
14252 +       }
14253 +       return task;
14254 +}
14255 +
14256 +#endif
14257 +
14258 +static inline
14259 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
14260 +{
14261 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
14262 +
14263 +       if (task && !vx_proc_task_visible(task)) {
14264 +               vxdprintk(VXD_CBIT(misc, 6),
14265 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
14266 +                       task, task->xid, task->pid,
14267 +                       current, current->xid, current->pid);
14268 +               put_task_struct(task);
14269 +               task = NULL;
14270 +       }
14271 +       return task;
14272 +}
14273 +
14274 +#if 0
14275 +
14276 +static inline
14277 +struct task_struct *vx_child_reaper(struct task_struct *p)
14278 +{
14279 +       struct vx_info *vxi = p->vx_info;
14280 +       struct task_struct *reaper = child_reaper(p);
14281 +
14282 +       if (!vxi)
14283 +               goto out;
14284 +
14285 +       BUG_ON(!p->vx_info->vx_reaper);
14286 +
14287 +       /* child reaper for the guest reaper */
14288 +       if (vxi->vx_reaper == p)
14289 +               goto out;
14290 +
14291 +       reaper = vxi->vx_reaper;
14292 +out:
14293 +       vxdprintk(VXD_CBIT(xid, 7),
14294 +               "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]",
14295 +               p, p->xid, p->pid, reaper, reaper->xid, reaper->pid);
14296 +       return reaper;
14297 +}
14298 +
14299 +#endif
14300 +
14301 +
14302 +#else
14303 +#warning duplicate inclusion
14304 +#endif
14305 diff -NurpP --minimal linux-2.6.36/include/linux/vs_sched.h linux-2.6.36-vs2.3.0.36.33/include/linux/vs_sched.h
14306 --- linux-2.6.36/include/linux/vs_sched.h       1970-01-01 01:00:00.000000000 +0100
14307 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vs_sched.h 2010-10-21 13:09:36.000000000 +0200
14308 @@ -0,0 +1,110 @@
14309 +#ifndef _VS_SCHED_H
14310 +#define _VS_SCHED_H
14311 +
14312 +#include "vserver/base.h"
14313 +#include "vserver/context.h"
14314 +#include "vserver/sched.h"
14315 +
14316 +
14317 +#define VAVAVOOM_RATIO          50
14318 +
14319 +#define MAX_PRIO_BIAS           20
14320 +#define MIN_PRIO_BIAS          -20
14321 +
14322 +
14323 +#ifdef CONFIG_VSERVER_HARDCPU
14324 +
14325 +/*
14326 + * effective_prio - return the priority that is based on the static
14327 + * priority but is modified by bonuses/penalties.
14328 + *
14329 + * We scale the actual sleep average [0 .... MAX_SLEEP_AVG]
14330 + * into a -4 ... 0 ... +4 bonus/penalty range.
14331 + *
14332 + * Additionally, we scale another amount based on the number of
14333 + * CPU tokens currently held by the context, if the process is
14334 + * part of a context (and the appropriate SCHED flag is set).
14335 + * This ranges from -5 ... 0 ... +15, quadratically.
14336 + *
14337 + * So, the total bonus is -9 .. 0 .. +19
14338 + * We use ~50% of the full 0...39 priority range so that:
14339 + *
14340 + * 1) nice +19 interactive tasks do not preempt nice 0 CPU hogs.
14341 + * 2) nice -20 CPU hogs do not get preempted by nice 0 tasks.
14342 + *    unless that context is far exceeding its CPU allocation.
14343 + *
14344 + * Both properties are important to certain workloads.
14345 + */
14346 +static inline
14347 +int vx_effective_vavavoom(struct _vx_sched_pc *sched_pc, int max_prio)
14348 +{
14349 +       int vavavoom, max;
14350 +
14351 +       /* lots of tokens = lots of vavavoom
14352 +        *      no tokens = no vavavoom      */
14353 +       if ((vavavoom = sched_pc->tokens) >= 0) {
14354 +               max = sched_pc->tokens_max;
14355 +               vavavoom = max - vavavoom;
14356 +               max = max * max;
14357 +               vavavoom = max_prio * VAVAVOOM_RATIO / 100
14358 +                       * (vavavoom*vavavoom - (max >> 2)) / max;
14359 +               return vavavoom;
14360 +       }
14361 +       return 0;
14362 +}
14363 +
14364 +
14365 +static inline
14366 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14367 +{
14368 +       struct vx_info *vxi = p->vx_info;
14369 +       struct _vx_sched_pc *sched_pc;
14370 +
14371 +       if (!vxi)
14372 +               return prio;
14373 +
14374 +       sched_pc = &vx_cpu(vxi, sched_pc);
14375 +       if (vx_info_flags(vxi, VXF_SCHED_PRIO, 0)) {
14376 +               int vavavoom = vx_effective_vavavoom(sched_pc, max_user);
14377 +
14378 +               sched_pc->vavavoom = vavavoom;
14379 +               prio += vavavoom;
14380 +       }
14381 +       prio += sched_pc->prio_bias;
14382 +       return prio;
14383 +}
14384 +
14385 +#else /* !CONFIG_VSERVER_HARDCPU */
14386 +
14387 +static inline
14388 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14389 +{
14390 +       struct vx_info *vxi = p->vx_info;
14391 +
14392 +       if (vxi)
14393 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
14394 +       return prio;
14395 +}
14396 +
14397 +#endif /* CONFIG_VSERVER_HARDCPU */
14398 +
14399 +
14400 +static inline void vx_account_user(struct vx_info *vxi,
14401 +       cputime_t cputime, int nice)
14402 +{
14403 +       if (!vxi)
14404 +               return;
14405 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
14406 +}
14407 +
14408 +static inline void vx_account_system(struct vx_info *vxi,
14409 +       cputime_t cputime, int idle)
14410 +{
14411 +       if (!vxi)
14412 +               return;
14413 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
14414 +}
14415 +
14416 +#else
14417 +#warning duplicate inclusion
14418 +#endif
14419 diff -NurpP --minimal linux-2.6.36/include/linux/vs_socket.h linux-2.6.36-vs2.3.0.36.33/include/linux/vs_socket.h
14420 --- linux-2.6.36/include/linux/vs_socket.h      1970-01-01 01:00:00.000000000 +0100
14421 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vs_socket.h        2010-10-21 13:09:36.000000000 +0200
14422 @@ -0,0 +1,67 @@
14423 +#ifndef _VS_SOCKET_H
14424 +#define _VS_SOCKET_H
14425 +
14426 +#include "vserver/debug.h"
14427 +#include "vserver/base.h"
14428 +#include "vserver/cacct.h"
14429 +#include "vserver/context.h"
14430 +#include "vserver/tag.h"
14431 +
14432 +
14433 +/* socket accounting */
14434 +
14435 +#include <linux/socket.h>
14436 +
14437 +static inline int vx_sock_type(int family)
14438 +{
14439 +       switch (family) {
14440 +       case PF_UNSPEC:
14441 +               return VXA_SOCK_UNSPEC;
14442 +       case PF_UNIX:
14443 +               return VXA_SOCK_UNIX;
14444 +       case PF_INET:
14445 +               return VXA_SOCK_INET;
14446 +       case PF_INET6:
14447 +               return VXA_SOCK_INET6;
14448 +       case PF_PACKET:
14449 +               return VXA_SOCK_PACKET;
14450 +       default:
14451 +               return VXA_SOCK_OTHER;
14452 +       }
14453 +}
14454 +
14455 +#define vx_acc_sock(v, f, p, s) \
14456 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
14457 +
14458 +static inline void __vx_acc_sock(struct vx_info *vxi,
14459 +       int family, int pos, int size, char *file, int line)
14460 +{
14461 +       if (vxi) {
14462 +               int type = vx_sock_type(family);
14463 +
14464 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
14465 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
14466 +       }
14467 +}
14468 +
14469 +#define vx_sock_recv(sk, s) \
14470 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
14471 +#define vx_sock_send(sk, s) \
14472 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
14473 +#define vx_sock_fail(sk, s) \
14474 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
14475 +
14476 +
14477 +#define sock_vx_init(s) do {           \
14478 +       (s)->sk_xid = 0;                \
14479 +       (s)->sk_vx_info = NULL;         \
14480 +       } while (0)
14481 +
14482 +#define sock_nx_init(s) do {           \
14483 +       (s)->sk_nid = 0;                \
14484 +       (s)->sk_nx_info = NULL;         \
14485 +       } while (0)
14486 +
14487 +#else
14488 +#warning duplicate inclusion
14489 +#endif
14490 diff -NurpP --minimal linux-2.6.36/include/linux/vs_tag.h linux-2.6.36-vs2.3.0.36.33/include/linux/vs_tag.h
14491 --- linux-2.6.36/include/linux/vs_tag.h 1970-01-01 01:00:00.000000000 +0100
14492 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vs_tag.h   2010-10-21 13:09:36.000000000 +0200
14493 @@ -0,0 +1,47 @@
14494 +#ifndef _VS_TAG_H
14495 +#define _VS_TAG_H
14496 +
14497 +#include <linux/vserver/tag.h>
14498 +
14499 +/* check conditions */
14500 +
14501 +#define DX_ADMIN       0x0001
14502 +#define DX_WATCH       0x0002
14503 +#define DX_HOSTID      0x0008
14504 +
14505 +#define DX_IDENT       0x0010
14506 +
14507 +#define DX_ARG_MASK    0x0010
14508 +
14509 +
14510 +#define dx_task_tag(t) ((t)->tag)
14511 +
14512 +#define dx_current_tag() dx_task_tag(current)
14513 +
14514 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
14515 +
14516 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
14517 +
14518 +
14519 +/*
14520 + * check current context for ADMIN/WATCH and
14521 + * optionally against supplied argument
14522 + */
14523 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
14524 +{
14525 +       if (mode & DX_ARG_MASK) {
14526 +               if ((mode & DX_IDENT) && (id == cid))
14527 +                       return 1;
14528 +       }
14529 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
14530 +               ((mode & DX_WATCH) && (cid == 1)) ||
14531 +               ((mode & DX_HOSTID) && (id == 0)));
14532 +}
14533 +
14534 +struct inode;
14535 +int dx_permission(const struct inode *inode, int mask);
14536 +
14537 +
14538 +#else
14539 +#warning duplicate inclusion
14540 +#endif
14541 diff -NurpP --minimal linux-2.6.36/include/linux/vs_time.h linux-2.6.36-vs2.3.0.36.33/include/linux/vs_time.h
14542 --- linux-2.6.36/include/linux/vs_time.h        1970-01-01 01:00:00.000000000 +0100
14543 +++ linux-2.6.36-vs2.3.0.36.33/include/linux/vs_time.h  2010-10-21 14:25:37.000000000 +0200
14544 @@ -0,0 +1,19 @@
14545 +#ifndef _VS_TIME_H
14546 +#define _VS_TIME_H
14547 +
14548 +
14549 +/* time faking stuff */
14550 +
14551 +#ifdef CONFIG_VSERVER_VTIME
14552 +
14553 +extern void vx_adjust_timespec(struct timespec *ts);
14554 +extern int vx_settimeofday(struct timespec *ts);
14555 +
14556 +#else
14557 +#define        vx_adjust_timespec(t)   do { } while (0)
14558 +#define        vx_settimeofday(t)      do_settimeofday(t)
14559 +#endif
14560 +
14561 +#else
14562 +#warning duplicate inclusion
14563 +#endif
14564 diff -NurpP --minimal linux-2.6.36/include/net/addrconf.h linux-2.6.36-vs2.3.0.36.33/include/net/addrconf.h
14565 --- linux-2.6.36/include/net/addrconf.h 2010-10-21 13:07:56.000000000 +0200
14566 +++ linux-2.6.36-vs2.3.0.36.33/include/net/addrconf.h   2010-10-21 13:09:36.000000000 +0200
14567 @@ -84,7 +84,8 @@ extern int                    ipv6_dev_get_saddr(struct n
14568                                                struct net_device *dev,
14569                                                const struct in6_addr *daddr,
14570                                                unsigned int srcprefs,
14571 -                                              struct in6_addr *saddr);
14572 +                                              struct in6_addr *saddr,
14573 +                                              struct nx_info *nxi);
14574  extern int                     ipv6_get_lladdr(struct net_device *dev,
14575                                                 struct in6_addr *addr,
14576                                                 unsigned char banned_flags);
14577 diff -NurpP --minimal linux-2.6.36/include/net/af_unix.h linux-2.6.36-vs2.3.0.36.33/include/net/af_unix.h
14578 --- linux-2.6.36/include/net/af_unix.h  2010-10-21 13:07:56.000000000 +0200
14579 +++ linux-2.6.36-vs2.3.0.36.33/include/net/af_unix.h    2010-10-21 13:09:36.000000000 +0200
14580 @@ -4,6 +4,7 @@
14581  #include <linux/socket.h>
14582  #include <linux/un.h>
14583  #include <linux/mutex.h>
14584 +#include <linux/vs_base.h>
14585  #include <net/sock.h>
14586  
14587  extern void unix_inflight(struct file *fp);
14588 diff -NurpP --minimal linux-2.6.36/include/net/inet_timewait_sock.h linux-2.6.36-vs2.3.0.36.33/include/net/inet_timewait_sock.h
14589 --- linux-2.6.36/include/net/inet_timewait_sock.h       2010-08-02 16:52:56.000000000 +0200
14590 +++ linux-2.6.36-vs2.3.0.36.33/include/net/inet_timewait_sock.h 2010-10-21 13:09:36.000000000 +0200
14591 @@ -117,6 +117,10 @@ struct inet_timewait_sock {
14592  #define tw_hash                        __tw_common.skc_hash
14593  #define tw_prot                        __tw_common.skc_prot
14594  #define tw_net                 __tw_common.skc_net
14595 +#define tw_xid                 __tw_common.skc_xid
14596 +#define tw_vx_info             __tw_common.skc_vx_info
14597 +#define tw_nid                 __tw_common.skc_nid
14598 +#define tw_nx_info             __tw_common.skc_nx_info
14599         int                     tw_timeout;
14600         volatile unsigned char  tw_substate;
14601         /* 3 bits hole, try to pack */
14602 diff -NurpP --minimal linux-2.6.36/include/net/route.h linux-2.6.36-vs2.3.0.36.33/include/net/route.h
14603 --- linux-2.6.36/include/net/route.h    2010-10-21 13:07:56.000000000 +0200
14604 +++ linux-2.6.36-vs2.3.0.36.33/include/net/route.h      2010-10-21 13:09:36.000000000 +0200
14605 @@ -145,6 +145,9 @@ static inline void ip_rt_put(struct rtab
14606                 dst_release(&rt->dst);
14607  }
14608  
14609 +#include <linux/vs_base.h>
14610 +#include <linux/vs_inet.h>
14611 +
14612  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
14613  
14614  extern const __u8 ip_tos2prio[16];
14615 @@ -154,6 +157,9 @@ static inline char rt_tos2priority(u8 to
14616         return ip_tos2prio[IPTOS_TOS(tos)>>1];
14617  }
14618  
14619 +extern int ip_v4_find_src(struct net *net, struct nx_info *,
14620 +       struct rtable **, struct flowi *);
14621 +
14622  static inline int ip_route_connect(struct rtable **rp, __be32 dst,
14623                                    __be32 src, u32 tos, int oif, u8 protocol,
14624                                    __be16 sport, __be16 dport, struct sock *sk,
14625 @@ -171,11 +177,24 @@ static inline int ip_route_connect(struc
14626  
14627         int err;
14628         struct net *net = sock_net(sk);
14629 +       struct nx_info *nx_info = current_nx_info();
14630  
14631         if (inet_sk(sk)->transparent)
14632                 fl.flags |= FLOWI_FLAG_ANYSRC;
14633  
14634 -       if (!dst || !src) {
14635 +       if (sk)
14636 +               nx_info = sk->sk_nx_info;
14637 +
14638 +       vxdprintk(VXD_CBIT(net, 4),
14639 +               "ip_route_connect(%p) %p,%p;%lx",
14640 +               sk, nx_info, sk->sk_socket,
14641 +               (sk->sk_socket?sk->sk_socket->flags:0));
14642 +
14643 +       err = ip_v4_find_src(net, nx_info, rp, &fl);
14644 +       if (err)
14645 +               return err;
14646 +
14647 +       if (!fl.fl4_dst || !fl.fl4_src) {
14648                 err = __ip_route_output_key(net, rp, &fl);
14649                 if (err)
14650                         return err;
14651 diff -NurpP --minimal linux-2.6.36/include/net/sock.h linux-2.6.36-vs2.3.0.36.33/include/net/sock.h
14652 --- linux-2.6.36/include/net/sock.h     2010-10-21 13:07:56.000000000 +0200
14653 +++ linux-2.6.36-vs2.3.0.36.33/include/net/sock.h       2010-10-21 13:09:36.000000000 +0200
14654 @@ -150,6 +150,10 @@ struct sock_common {
14655  #ifdef CONFIG_NET_NS
14656         struct net              *skc_net;
14657  #endif
14658 +       xid_t                   skc_xid;
14659 +       struct vx_info          *skc_vx_info;
14660 +       nid_t                   skc_nid;
14661 +       struct nx_info          *skc_nx_info;
14662  };
14663  
14664  /**
14665 @@ -241,6 +245,10 @@ struct sock {
14666  #define sk_bind_node           __sk_common.skc_bind_node
14667  #define sk_prot                        __sk_common.skc_prot
14668  #define sk_net                 __sk_common.skc_net
14669 +#define sk_xid                 __sk_common.skc_xid
14670 +#define sk_vx_info             __sk_common.skc_vx_info
14671 +#define sk_nid                 __sk_common.skc_nid
14672 +#define sk_nx_info             __sk_common.skc_nx_info
14673         kmemcheck_bitfield_begin(flags);
14674         unsigned int            sk_shutdown  : 2,
14675                                 sk_no_check  : 2,
14676 diff -NurpP --minimal linux-2.6.36/init/Kconfig linux-2.6.36-vs2.3.0.36.33/init/Kconfig
14677 --- linux-2.6.36/init/Kconfig   2010-10-21 13:07:56.000000000 +0200
14678 +++ linux-2.6.36-vs2.3.0.36.33/init/Kconfig     2010-10-21 13:09:36.000000000 +0200
14679 @@ -476,6 +476,7 @@ config HAVE_UNSTABLE_SCHED_CLOCK
14680  menuconfig CGROUPS
14681         boolean "Control Group support"
14682         depends on EVENTFD
14683 +       default y
14684         help
14685           This option adds support for grouping sets of processes together, for
14686           use with process control subsystems such as Cpusets, CFS, memory
14687 @@ -503,6 +504,7 @@ config CGROUP_DEBUG
14688  config CGROUP_NS
14689         bool "Namespace cgroup subsystem"
14690         depends on CGROUPS
14691 +       default n
14692         help
14693           Provides a simple namespace cgroup subsystem to
14694           provide hierarchical naming of sets of namespaces,
14695 diff -NurpP --minimal linux-2.6.36/init/main.c linux-2.6.36-vs2.3.0.36.33/init/main.c
14696 --- linux-2.6.36/init/main.c    2010-10-21 13:07:56.000000000 +0200
14697 +++ linux-2.6.36-vs2.3.0.36.33/init/main.c      2010-10-21 13:10:12.000000000 +0200
14698 @@ -68,6 +68,7 @@
14699  #include <linux/sfi.h>
14700  #include <linux/shmem_fs.h>
14701  #include <linux/slab.h>
14702 +#include <linux/vserver/percpu.h>
14703  
14704  #include <asm/io.h>
14705  #include <asm/bugs.h>
14706 diff -NurpP --minimal linux-2.6.36/ipc/mqueue.c linux-2.6.36-vs2.3.0.36.33/ipc/mqueue.c
14707 --- linux-2.6.36/ipc/mqueue.c   2010-10-21 13:07:56.000000000 +0200
14708 +++ linux-2.6.36-vs2.3.0.36.33/ipc/mqueue.c     2010-10-21 13:28:42.000000000 +0200
14709 @@ -33,6 +33,8 @@
14710  #include <linux/pid.h>
14711  #include <linux/ipc_namespace.h>
14712  #include <linux/slab.h>
14713 +#include <linux/vs_context.h>
14714 +#include <linux/vs_limit.h>
14715  
14716  #include <net/sock.h>
14717  #include "util.h"
14718 @@ -66,6 +68,7 @@ struct mqueue_inode_info {
14719         struct sigevent notify;
14720         struct pid* notify_owner;
14721         struct user_struct *user;       /* user who created, for accounting */
14722 +       struct vx_info *vxi;
14723         struct sock *notify_sock;
14724         struct sk_buff *notify_cookie;
14725  
14726 @@ -125,6 +128,7 @@ static struct inode *mqueue_get_inode(st
14727                 if (S_ISREG(mode)) {
14728                         struct mqueue_inode_info *info;
14729                         struct task_struct *p = current;
14730 +                       struct vx_info *vxi = p->vx_info;
14731                         unsigned long mq_bytes, mq_msg_tblsz;
14732  
14733                         inode->i_fop = &mqueue_file_operations;
14734 @@ -138,6 +142,7 @@ static struct inode *mqueue_get_inode(st
14735                         info->notify_owner = NULL;
14736                         info->qsize = 0;
14737                         info->user = NULL;      /* set when all is ok */
14738 +                       info->vxi = NULL;
14739                         memset(&info->attr, 0, sizeof(info->attr));
14740                         info->attr.mq_maxmsg = ipc_ns->mq_msg_max;
14741                         info->attr.mq_msgsize = ipc_ns->mq_msgsize_max;
14742 @@ -156,16 +161,19 @@ static struct inode *mqueue_get_inode(st
14743                         spin_lock(&mq_lock);
14744                         if (u->mq_bytes + mq_bytes < u->mq_bytes ||
14745                             u->mq_bytes + mq_bytes >
14746 -                           task_rlimit(p, RLIMIT_MSGQUEUE)) {
14747 +                           task_rlimit(p, RLIMIT_MSGQUEUE) ||
14748 +                           !vx_ipcmsg_avail(vxi, mq_bytes)) {
14749                                 spin_unlock(&mq_lock);
14750                                 /* mqueue_evict_inode() releases info->messages */
14751                                 goto out_inode;
14752                         }
14753                         u->mq_bytes += mq_bytes;
14754 +                       vx_ipcmsg_add(vxi, u, mq_bytes);
14755                         spin_unlock(&mq_lock);
14756  
14757                         /* all is ok */
14758                         info->user = get_uid(u);
14759 +                       info->vxi = get_vx_info(vxi);
14760                 } else if (S_ISDIR(mode)) {
14761                         inc_nlink(inode);
14762                         /* Some things misbehave if size == 0 on a directory */
14763 @@ -267,8 +275,11 @@ static void mqueue_evict_inode(struct in
14764             + info->attr.mq_msgsize);
14765         user = info->user;
14766         if (user) {
14767 +               struct vx_info *vxi = info->vxi;
14768 +
14769                 spin_lock(&mq_lock);
14770                 user->mq_bytes -= mq_bytes;
14771 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
14772                 /*
14773                  * get_ns_from_inode() ensures that the
14774                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
14775 @@ -278,6 +289,7 @@ static void mqueue_evict_inode(struct in
14776                 if (ipc_ns)
14777                         ipc_ns->mq_queues_count--;
14778                 spin_unlock(&mq_lock);
14779 +               put_vx_info(vxi);
14780                 free_uid(user);
14781         }
14782         if (ipc_ns)
14783 diff -NurpP --minimal linux-2.6.36/ipc/msg.c linux-2.6.36-vs2.3.0.36.33/ipc/msg.c
14784 --- linux-2.6.36/ipc/msg.c      2010-08-02 16:52:57.000000000 +0200
14785 +++ linux-2.6.36-vs2.3.0.36.33/ipc/msg.c        2010-10-21 13:09:36.000000000 +0200
14786 @@ -37,6 +37,7 @@
14787  #include <linux/rwsem.h>
14788  #include <linux/nsproxy.h>
14789  #include <linux/ipc_namespace.h>
14790 +#include <linux/vs_base.h>
14791  
14792  #include <asm/current.h>
14793  #include <asm/uaccess.h>
14794 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
14795  
14796         msq->q_perm.mode = msgflg & S_IRWXUGO;
14797         msq->q_perm.key = key;
14798 +       msq->q_perm.xid = vx_current_xid();
14799  
14800         msq->q_perm.security = NULL;
14801         retval = security_msg_queue_alloc(msq);
14802 diff -NurpP --minimal linux-2.6.36/ipc/namespace.c linux-2.6.36-vs2.3.0.36.33/ipc/namespace.c
14803 --- linux-2.6.36/ipc/namespace.c        2009-09-10 15:26:27.000000000 +0200
14804 +++ linux-2.6.36-vs2.3.0.36.33/ipc/namespace.c  2010-10-21 13:09:36.000000000 +0200
14805 @@ -11,6 +11,8 @@
14806  #include <linux/slab.h>
14807  #include <linux/fs.h>
14808  #include <linux/mount.h>
14809 +#include <linux/vs_base.h>
14810 +#include <linux/vserver/global.h>
14811  
14812  #include "util.h"
14813  
14814 diff -NurpP --minimal linux-2.6.36/ipc/sem.c linux-2.6.36-vs2.3.0.36.33/ipc/sem.c
14815 --- linux-2.6.36/ipc/sem.c      2010-10-21 13:07:56.000000000 +0200
14816 +++ linux-2.6.36-vs2.3.0.36.33/ipc/sem.c        2010-10-21 13:09:36.000000000 +0200
14817 @@ -86,6 +86,8 @@
14818  #include <linux/rwsem.h>
14819  #include <linux/nsproxy.h>
14820  #include <linux/ipc_namespace.h>
14821 +#include <linux/vs_base.h>
14822 +#include <linux/vs_limit.h>
14823  
14824  #include <asm/uaccess.h>
14825  #include "util.h"
14826 @@ -260,6 +262,7 @@ static int newary(struct ipc_namespace *
14827  
14828         sma->sem_perm.mode = (semflg & S_IRWXUGO);
14829         sma->sem_perm.key = key;
14830 +       sma->sem_perm.xid = vx_current_xid();
14831  
14832         sma->sem_perm.security = NULL;
14833         retval = security_sem_alloc(sma);
14834 @@ -275,6 +278,9 @@ static int newary(struct ipc_namespace *
14835                 return id;
14836         }
14837         ns->used_sems += nsems;
14838 +       /* FIXME: obsoleted? */
14839 +       vx_semary_inc(sma);
14840 +       vx_nsems_add(sma, nsems);
14841  
14842         sma->sem_base = (struct sem *) &sma[1];
14843  
14844 @@ -730,6 +736,9 @@ static void freeary(struct ipc_namespace
14845  
14846         wake_up_sem_queue_do(&tasks);
14847         ns->used_sems -= sma->sem_nsems;
14848 +       /* FIXME: obsoleted? */
14849 +       vx_nsems_sub(sma, sma->sem_nsems);
14850 +       vx_semary_dec(sma);
14851         security_sem_free(sma);
14852         ipc_rcu_putref(sma);
14853  }
14854 diff -NurpP --minimal linux-2.6.36/ipc/shm.c linux-2.6.36-vs2.3.0.36.33/ipc/shm.c
14855 --- linux-2.6.36/ipc/shm.c      2010-08-02 16:52:57.000000000 +0200
14856 +++ linux-2.6.36-vs2.3.0.36.33/ipc/shm.c        2010-10-21 13:09:36.000000000 +0200
14857 @@ -39,6 +39,8 @@
14858  #include <linux/nsproxy.h>
14859  #include <linux/mount.h>
14860  #include <linux/ipc_namespace.h>
14861 +#include <linux/vs_context.h>
14862 +#include <linux/vs_limit.h>
14863  
14864  #include <asm/uaccess.h>
14865  
14866 @@ -169,7 +171,12 @@ static void shm_open(struct vm_area_stru
14867   */
14868  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
14869  {
14870 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14871 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
14872 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
14873 +
14874 +       vx_ipcshm_sub(vxi, shp, numpages);
14875 +       ns->shm_tot -= numpages;
14876 +
14877         shm_rmid(ns, shp);
14878         shm_unlock(shp);
14879         if (!is_file_hugepages(shp->shm_file))
14880 @@ -179,6 +186,7 @@ static void shm_destroy(struct ipc_names
14881                                                 shp->mlock_user);
14882         fput (shp->shm_file);
14883         security_shm_free(shp);
14884 +       put_vx_info(vxi);
14885         ipc_rcu_putref(shp);
14886  }
14887  
14888 @@ -349,11 +357,15 @@ static int newseg(struct ipc_namespace *
14889         if (ns->shm_tot + numpages > ns->shm_ctlall)
14890                 return -ENOSPC;
14891  
14892 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
14893 +               return -ENOSPC;
14894 +
14895         shp = ipc_rcu_alloc(sizeof(*shp));
14896         if (!shp)
14897                 return -ENOMEM;
14898  
14899         shp->shm_perm.key = key;
14900 +       shp->shm_perm.xid = vx_current_xid();
14901         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
14902         shp->mlock_user = NULL;
14903  
14904 @@ -407,6 +419,7 @@ static int newseg(struct ipc_namespace *
14905         ns->shm_tot += numpages;
14906         error = shp->shm_perm.id;
14907         shm_unlock(shp);
14908 +       vx_ipcshm_add(current_vx_info(), key, numpages);
14909         return error;
14910  
14911  no_id:
14912 diff -NurpP --minimal linux-2.6.36/kernel/capability.c linux-2.6.36-vs2.3.0.36.33/kernel/capability.c
14913 --- linux-2.6.36/kernel/capability.c    2010-08-02 16:52:57.000000000 +0200
14914 +++ linux-2.6.36-vs2.3.0.36.33/kernel/capability.c      2010-10-21 13:09:36.000000000 +0200
14915 @@ -14,6 +14,7 @@
14916  #include <linux/security.h>
14917  #include <linux/syscalls.h>
14918  #include <linux/pid_namespace.h>
14919 +#include <linux/vs_context.h>
14920  #include <asm/uaccess.h>
14921  
14922  /*
14923 @@ -119,6 +120,7 @@ static int cap_validate_magic(cap_user_h
14924         return 0;
14925  }
14926  
14927 +
14928  /*
14929   * The only thing that can change the capabilities of the current
14930   * process is the current process. As such, we can't be in this code
14931 @@ -289,6 +291,8 @@ error:
14932         return ret;
14933  }
14934  
14935 +#include <linux/vserver/base.h>
14936 +
14937  /**
14938   * capable - Determine if the current task has a superior capability in effect
14939   * @cap: The capability to be tested for
14940 @@ -301,6 +305,9 @@ error:
14941   */
14942  int capable(int cap)
14943  {
14944 +       /* here for now so we don't require task locking */
14945 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
14946 +               return 0;
14947         if (unlikely(!cap_valid(cap))) {
14948                 printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
14949                 BUG();
14950 diff -NurpP --minimal linux-2.6.36/kernel/compat.c linux-2.6.36-vs2.3.0.36.33/kernel/compat.c
14951 --- linux-2.6.36/kernel/compat.c        2010-10-21 13:07:56.000000000 +0200
14952 +++ linux-2.6.36-vs2.3.0.36.33/kernel/compat.c  2010-10-21 14:22:43.000000000 +0200
14953 @@ -914,7 +914,7 @@ asmlinkage long compat_sys_stime(compat_
14954         if (err)
14955                 return err;
14956  
14957 -       do_settimeofday(&tv);
14958 +       vx_settimeofday(&tv);
14959         return 0;
14960  }
14961  
14962 diff -NurpP --minimal linux-2.6.36/kernel/exit.c linux-2.6.36-vs2.3.0.36.33/kernel/exit.c
14963 --- linux-2.6.36/kernel/exit.c  2010-10-21 13:07:56.000000000 +0200
14964 +++ linux-2.6.36-vs2.3.0.36.33/kernel/exit.c    2010-10-21 13:09:36.000000000 +0200
14965 @@ -48,6 +48,10 @@
14966  #include <linux/fs_struct.h>
14967  #include <linux/init_task.h>
14968  #include <linux/perf_event.h>
14969 +#include <linux/vs_limit.h>
14970 +#include <linux/vs_context.h>
14971 +#include <linux/vs_network.h>
14972 +#include <linux/vs_pid.h>
14973  #include <trace/events/sched.h>
14974  #include <linux/hw_breakpoint.h>
14975  
14976 @@ -487,9 +491,11 @@ static void close_files(struct files_str
14977                                         filp_close(file, files);
14978                                         cond_resched();
14979                                 }
14980 +                               vx_openfd_dec(i);
14981                         }
14982                         i++;
14983                         set >>= 1;
14984 +                       cond_resched();
14985                 }
14986         }
14987  }
14988 @@ -1023,11 +1029,16 @@ NORET_TYPE void do_exit(long code)
14989  
14990         validate_creds_for_do_exit(tsk);
14991  
14992 +       /* needs to stay after exit_notify() */
14993 +       exit_vx_info(tsk, code);
14994 +       exit_nx_info(tsk);
14995 +
14996         preempt_disable();
14997         exit_rcu();
14998         /* causes final put_task_struct in finish_task_switch(). */
14999         tsk->state = TASK_DEAD;
15000         schedule();
15001 +       printk("bad task: %p [%lx]\n", current, current->state);
15002         BUG();
15003         /* Avoid "noreturn function does return".  */
15004         for (;;)
15005 diff -NurpP --minimal linux-2.6.36/kernel/fork.c linux-2.6.36-vs2.3.0.36.33/kernel/fork.c
15006 --- linux-2.6.36/kernel/fork.c  2010-10-21 13:07:56.000000000 +0200
15007 +++ linux-2.6.36-vs2.3.0.36.33/kernel/fork.c    2010-10-21 13:09:36.000000000 +0200
15008 @@ -65,6 +65,10 @@
15009  #include <linux/perf_event.h>
15010  #include <linux/posix-timers.h>
15011  #include <linux/user-return-notifier.h>
15012 +#include <linux/vs_context.h>
15013 +#include <linux/vs_network.h>
15014 +#include <linux/vs_limit.h>
15015 +#include <linux/vs_memory.h>
15016  
15017  #include <asm/pgtable.h>
15018  #include <asm/pgalloc.h>
15019 @@ -160,6 +164,8 @@ void free_task(struct task_struct *tsk)
15020         account_kernel_stack(tsk->stack, -1);
15021         free_thread_info(tsk->stack);
15022         rt_mutex_debug_task_free(tsk);
15023 +       clr_vx_info(&tsk->vx_info);
15024 +       clr_nx_info(&tsk->nx_info);
15025         ftrace_graph_exit_task(tsk);
15026         free_task_struct(tsk);
15027  }
15028 @@ -492,6 +498,7 @@ static struct mm_struct * mm_init(struct
15029         if (likely(!mm_alloc_pgd(mm))) {
15030                 mm->def_flags = 0;
15031                 mmu_notifier_mm_init(mm);
15032 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
15033                 return mm;
15034         }
15035  
15036 @@ -525,6 +532,7 @@ void __mmdrop(struct mm_struct *mm)
15037         mm_free_pgd(mm);
15038         destroy_context(mm);
15039         mmu_notifier_mm_destroy(mm);
15040 +       clr_vx_info(&mm->mm_vx_info);
15041         free_mm(mm);
15042  }
15043  EXPORT_SYMBOL_GPL(__mmdrop);
15044 @@ -660,6 +668,7 @@ struct mm_struct *dup_mm(struct task_str
15045                 goto fail_nomem;
15046  
15047         memcpy(mm, oldmm, sizeof(*mm));
15048 +       mm->mm_vx_info = NULL;
15049  
15050         /* Initializing for Swap token stuff */
15051         mm->token_priority = 0;
15052 @@ -698,6 +707,7 @@ fail_nocontext:
15053          * If init_new_context() failed, we cannot use mmput() to free the mm
15054          * because it calls destroy_context()
15055          */
15056 +       clr_vx_info(&mm->mm_vx_info);
15057         mm_free_pgd(mm);
15058         free_mm(mm);
15059         return NULL;
15060 @@ -973,6 +983,8 @@ static struct task_struct *copy_process(
15061         int retval;
15062         struct task_struct *p;
15063         int cgroup_callbacks_done = 0;
15064 +       struct vx_info *vxi;
15065 +       struct nx_info *nxi;
15066  
15067         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
15068                 return ERR_PTR(-EINVAL);
15069 @@ -1019,7 +1031,12 @@ static struct task_struct *copy_process(
15070         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
15071         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
15072  #endif
15073 +       init_vx_info(&p->vx_info, current_vx_info());
15074 +       init_nx_info(&p->nx_info, current_nx_info());
15075 +
15076         retval = -EAGAIN;
15077 +       if (!vx_nproc_avail(1))
15078 +               goto bad_fork_free;
15079         if (atomic_read(&p->real_cred->user->processes) >=
15080                         task_rlimit(p, RLIMIT_NPROC)) {
15081                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
15082 @@ -1284,6 +1301,18 @@ static struct task_struct *copy_process(
15083  
15084         total_forks++;
15085         spin_unlock(&current->sighand->siglock);
15086 +
15087 +       /* p is copy of current */
15088 +       vxi = p->vx_info;
15089 +       if (vxi) {
15090 +               claim_vx_info(vxi, p);
15091 +               atomic_inc(&vxi->cvirt.nr_threads);
15092 +               atomic_inc(&vxi->cvirt.total_forks);
15093 +               vx_nproc_inc(p);
15094 +       }
15095 +       nxi = p->nx_info;
15096 +       if (nxi)
15097 +               claim_nx_info(nxi, p);
15098         write_unlock_irq(&tasklist_lock);
15099         proc_fork_connector(p);
15100         cgroup_post_fork(p);
15101 diff -NurpP --minimal linux-2.6.36/kernel/kthread.c linux-2.6.36-vs2.3.0.36.33/kernel/kthread.c
15102 --- linux-2.6.36/kernel/kthread.c       2010-10-21 13:07:57.000000000 +0200
15103 +++ linux-2.6.36-vs2.3.0.36.33/kernel/kthread.c 2010-10-21 13:42:40.000000000 +0200
15104 @@ -16,6 +16,7 @@
15105  #include <linux/mutex.h>
15106  #include <linux/slab.h>
15107  #include <linux/freezer.h>
15108 +#include <linux/vs_pid.h>
15109  #include <trace/events/sched.h>
15110  
15111  static DEFINE_SPINLOCK(kthread_create_lock);
15112 diff -NurpP --minimal linux-2.6.36/kernel/Makefile linux-2.6.36-vs2.3.0.36.33/kernel/Makefile
15113 --- linux-2.6.36/kernel/Makefile        2010-10-21 13:07:56.000000000 +0200
15114 +++ linux-2.6.36-vs2.3.0.36.33/kernel/Makefile  2010-10-21 13:09:36.000000000 +0200
15115 @@ -25,6 +25,7 @@ CFLAGS_REMOVE_sched_clock.o = -pg
15116  CFLAGS_REMOVE_perf_event.o = -pg
15117  endif
15118  
15119 +obj-y += vserver/
15120  obj-$(CONFIG_FREEZER) += freezer.o
15121  obj-$(CONFIG_PROFILING) += profile.o
15122  obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
15123 diff -NurpP --minimal linux-2.6.36/kernel/nsproxy.c linux-2.6.36-vs2.3.0.36.33/kernel/nsproxy.c
15124 --- linux-2.6.36/kernel/nsproxy.c       2010-07-07 18:31:57.000000000 +0200
15125 +++ linux-2.6.36-vs2.3.0.36.33/kernel/nsproxy.c 2010-10-21 13:09:36.000000000 +0200
15126 @@ -20,6 +20,8 @@
15127  #include <linux/mnt_namespace.h>
15128  #include <linux/utsname.h>
15129  #include <linux/pid_namespace.h>
15130 +#include <linux/vserver/global.h>
15131 +#include <linux/vserver/debug.h>
15132  #include <net/net_namespace.h>
15133  #include <linux/ipc_namespace.h>
15134  
15135 @@ -43,8 +45,11 @@ static inline struct nsproxy *create_nsp
15136         struct nsproxy *nsproxy;
15137  
15138         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
15139 -       if (nsproxy)
15140 +       if (nsproxy) {
15141                 atomic_set(&nsproxy->count, 1);
15142 +               atomic_inc(&vs_global_nsproxy);
15143 +       }
15144 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
15145         return nsproxy;
15146  }
15147  
15148 @@ -53,41 +58,52 @@ static inline struct nsproxy *create_nsp
15149   * Return the newly created nsproxy.  Do not attach this to the task,
15150   * leave it to the caller to do proper locking and attach it to task.
15151   */
15152 -static struct nsproxy *create_new_namespaces(unsigned long flags,
15153 -                       struct task_struct *tsk, struct fs_struct *new_fs)
15154 +static struct nsproxy *unshare_namespaces(unsigned long flags,
15155 +                       struct nsproxy *orig, struct fs_struct *new_fs)
15156  {
15157         struct nsproxy *new_nsp;
15158         int err;
15159  
15160 +       vxdprintk(VXD_CBIT(space, 4),
15161 +               "unshare_namespaces(0x%08lx,%p,%p)",
15162 +               flags, orig, new_fs);
15163 +
15164         new_nsp = create_nsproxy();
15165         if (!new_nsp)
15166                 return ERR_PTR(-ENOMEM);
15167  
15168 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
15169 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
15170         if (IS_ERR(new_nsp->mnt_ns)) {
15171                 err = PTR_ERR(new_nsp->mnt_ns);
15172                 goto out_ns;
15173         }
15174  
15175 -       new_nsp->uts_ns = copy_utsname(flags, tsk->nsproxy->uts_ns);
15176 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns);
15177         if (IS_ERR(new_nsp->uts_ns)) {
15178                 err = PTR_ERR(new_nsp->uts_ns);
15179                 goto out_uts;
15180         }
15181  
15182 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk->nsproxy->ipc_ns);
15183 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns);
15184         if (IS_ERR(new_nsp->ipc_ns)) {
15185                 err = PTR_ERR(new_nsp->ipc_ns);
15186                 goto out_ipc;
15187         }
15188  
15189 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
15190 +       new_nsp->pid_ns = copy_pid_ns(flags, orig->pid_ns);
15191         if (IS_ERR(new_nsp->pid_ns)) {
15192                 err = PTR_ERR(new_nsp->pid_ns);
15193                 goto out_pid;
15194         }
15195  
15196 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
15197 +       /* disabled now?
15198 +       new_nsp->user_ns = copy_user_ns(flags, orig->user_ns);
15199 +       if (IS_ERR(new_nsp->user_ns)) {
15200 +               err = PTR_ERR(new_nsp->user_ns);
15201 +               goto out_user;
15202 +       } */
15203 +
15204 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
15205         if (IS_ERR(new_nsp->net_ns)) {
15206                 err = PTR_ERR(new_nsp->net_ns);
15207                 goto out_net;
15208 @@ -112,6 +128,38 @@ out_ns:
15209         return ERR_PTR(err);
15210  }
15211  
15212 +static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
15213 +                       struct fs_struct *new_fs)
15214 +{
15215 +       return unshare_namespaces(flags, tsk->nsproxy, new_fs);
15216 +}
15217 +
15218 +/*
15219 + * copies the nsproxy, setting refcount to 1, and grabbing a
15220 + * reference to all contained namespaces.
15221 + */
15222 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
15223 +{
15224 +       struct nsproxy *ns = create_nsproxy();
15225 +
15226 +       if (ns) {
15227 +               memcpy(ns, orig, sizeof(struct nsproxy));
15228 +               atomic_set(&ns->count, 1);
15229 +
15230 +               if (ns->mnt_ns)
15231 +                       get_mnt_ns(ns->mnt_ns);
15232 +               if (ns->uts_ns)
15233 +                       get_uts_ns(ns->uts_ns);
15234 +               if (ns->ipc_ns)
15235 +                       get_ipc_ns(ns->ipc_ns);
15236 +               if (ns->pid_ns)
15237 +                       get_pid_ns(ns->pid_ns);
15238 +               if (ns->net_ns)
15239 +                       get_net(ns->net_ns);
15240 +       }
15241 +       return ns;
15242 +}
15243 +
15244  /*
15245   * called from clone.  This now handles copy for nsproxy and all
15246   * namespaces therein.
15247 @@ -119,9 +167,12 @@ out_ns:
15248  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
15249  {
15250         struct nsproxy *old_ns = tsk->nsproxy;
15251 -       struct nsproxy *new_ns;
15252 +       struct nsproxy *new_ns = NULL;
15253         int err = 0;
15254  
15255 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
15256 +               flags, tsk, old_ns);
15257 +
15258         if (!old_ns)
15259                 return 0;
15260  
15261 @@ -131,7 +182,7 @@ int copy_namespaces(unsigned long flags,
15262                                 CLONE_NEWPID | CLONE_NEWNET)))
15263                 return 0;
15264  
15265 -       if (!capable(CAP_SYS_ADMIN)) {
15266 +       if (!vx_can_unshare(CAP_SYS_ADMIN, flags)) {
15267                 err = -EPERM;
15268                 goto out;
15269         }
15270 @@ -158,6 +209,9 @@ int copy_namespaces(unsigned long flags,
15271  
15272  out:
15273         put_nsproxy(old_ns);
15274 +       vxdprintk(VXD_CBIT(space, 3),
15275 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
15276 +               flags, tsk, old_ns, err, new_ns);
15277         return err;
15278  }
15279  
15280 @@ -171,7 +225,9 @@ void free_nsproxy(struct nsproxy *ns)
15281                 put_ipc_ns(ns->ipc_ns);
15282         if (ns->pid_ns)
15283                 put_pid_ns(ns->pid_ns);
15284 -       put_net(ns->net_ns);
15285 +       if (ns->net_ns)
15286 +               put_net(ns->net_ns);
15287 +       atomic_dec(&vs_global_nsproxy);
15288         kmem_cache_free(nsproxy_cachep, ns);
15289  }
15290  
15291 @@ -184,11 +240,15 @@ int unshare_nsproxy_namespaces(unsigned 
15292  {
15293         int err = 0;
15294  
15295 +       vxdprintk(VXD_CBIT(space, 4),
15296 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
15297 +               unshare_flags, current->nsproxy);
15298 +
15299         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
15300                                CLONE_NEWNET)))
15301                 return 0;
15302  
15303 -       if (!capable(CAP_SYS_ADMIN))
15304 +       if (!vx_can_unshare(CAP_SYS_ADMIN, unshare_flags))
15305                 return -EPERM;
15306  
15307         *new_nsp = create_new_namespaces(unshare_flags, current,
15308 diff -NurpP --minimal linux-2.6.36/kernel/pid.c linux-2.6.36-vs2.3.0.36.33/kernel/pid.c
15309 --- linux-2.6.36/kernel/pid.c   2010-10-21 13:07:57.000000000 +0200
15310 +++ linux-2.6.36-vs2.3.0.36.33/kernel/pid.c     2010-10-21 13:09:36.000000000 +0200
15311 @@ -36,6 +36,7 @@
15312  #include <linux/pid_namespace.h>
15313  #include <linux/init_task.h>
15314  #include <linux/syscalls.h>
15315 +#include <linux/vs_pid.h>
15316  
15317  #define pid_hashfn(nr, ns)     \
15318         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
15319 @@ -339,7 +340,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
15320  
15321  struct pid *find_vpid(int nr)
15322  {
15323 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
15324 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
15325  }
15326  EXPORT_SYMBOL_GPL(find_vpid);
15327  
15328 @@ -399,6 +400,9 @@ void transfer_pid(struct task_struct *ol
15329  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
15330  {
15331         struct task_struct *result = NULL;
15332 +
15333 +       if (type == PIDTYPE_REALPID)
15334 +               type = PIDTYPE_PID;
15335         if (pid) {
15336                 struct hlist_node *first;
15337                 first = rcu_dereference_check(pid->tasks[type].first,
15338 @@ -416,7 +420,7 @@ EXPORT_SYMBOL(pid_task);
15339   */
15340  struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
15341  {
15342 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
15343 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
15344  }
15345  
15346  struct task_struct *find_task_by_vpid(pid_t vnr)
15347 @@ -458,7 +462,7 @@ struct pid *find_get_pid(pid_t nr)
15348  }
15349  EXPORT_SYMBOL_GPL(find_get_pid);
15350  
15351 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15352 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
15353  {
15354         struct upid *upid;
15355         pid_t nr = 0;
15356 @@ -471,6 +475,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
15357         return nr;
15358  }
15359  
15360 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15361 +{
15362 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
15363 +}
15364 +
15365  pid_t pid_vnr(struct pid *pid)
15366  {
15367         return pid_nr_ns(pid, current->nsproxy->pid_ns);
15368 diff -NurpP --minimal linux-2.6.36/kernel/pid_namespace.c linux-2.6.36-vs2.3.0.36.33/kernel/pid_namespace.c
15369 --- linux-2.6.36/kernel/pid_namespace.c 2010-07-07 18:31:57.000000000 +0200
15370 +++ linux-2.6.36-vs2.3.0.36.33/kernel/pid_namespace.c   2010-10-21 13:09:36.000000000 +0200
15371 @@ -14,6 +14,7 @@
15372  #include <linux/err.h>
15373  #include <linux/acct.h>
15374  #include <linux/slab.h>
15375 +#include <linux/vserver/global.h>
15376  
15377  #define BITS_PER_PAGE          (PAGE_SIZE*8)
15378  
15379 @@ -87,6 +88,7 @@ static struct pid_namespace *create_pid_
15380                 goto out_free_map;
15381  
15382         kref_init(&ns->kref);
15383 +       atomic_inc(&vs_global_pid_ns);
15384         ns->level = level;
15385         ns->parent = get_pid_ns(parent_pid_ns);
15386  
15387 @@ -112,6 +114,7 @@ static void destroy_pid_namespace(struct
15388  
15389         for (i = 0; i < PIDMAP_ENTRIES; i++)
15390                 kfree(ns->pidmap[i].page);
15391 +       atomic_dec(&vs_global_pid_ns);
15392         kmem_cache_free(pid_ns_cachep, ns);
15393  }
15394  
15395 diff -NurpP --minimal linux-2.6.36/kernel/posix-timers.c linux-2.6.36-vs2.3.0.36.33/kernel/posix-timers.c
15396 --- linux-2.6.36/kernel/posix-timers.c  2010-10-21 13:07:57.000000000 +0200
15397 +++ linux-2.6.36-vs2.3.0.36.33/kernel/posix-timers.c    2010-10-21 13:09:36.000000000 +0200
15398 @@ -46,6 +46,7 @@
15399  #include <linux/wait.h>
15400  #include <linux/workqueue.h>
15401  #include <linux/module.h>
15402 +#include <linux/vs_context.h>
15403  
15404  /*
15405   * Management arrays for POSIX timers.  Timers are kept in slab memory
15406 @@ -363,6 +364,7 @@ int posix_timer_event(struct k_itimer *t
15407  {
15408         struct task_struct *task;
15409         int shared, ret = -1;
15410 +
15411         /*
15412          * FIXME: if ->sigq is queued we can race with
15413          * dequeue_signal()->do_schedule_next_timer().
15414 @@ -379,10 +381,18 @@ int posix_timer_event(struct k_itimer *t
15415         rcu_read_lock();
15416         task = pid_task(timr->it_pid, PIDTYPE_PID);
15417         if (task) {
15418 +               struct vx_info_save vxis;
15419 +               struct vx_info *vxi;
15420 +
15421 +               vxi = get_vx_info(task->vx_info);
15422 +               enter_vx_info(vxi, &vxis);
15423                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
15424                 ret = send_sigqueue(timr->sigq, task, shared);
15425 +               leave_vx_info(&vxis);
15426 +               put_vx_info(vxi);
15427         }
15428         rcu_read_unlock();
15429 +
15430         /* If we failed to send the signal the timer stops. */
15431         return ret > 0;
15432  }
15433 diff -NurpP --minimal linux-2.6.36/kernel/printk.c linux-2.6.36-vs2.3.0.36.33/kernel/printk.c
15434 --- linux-2.6.36/kernel/printk.c        2010-10-21 13:07:57.000000000 +0200
15435 +++ linux-2.6.36-vs2.3.0.36.33/kernel/printk.c  2010-10-21 13:43:06.000000000 +0200
15436 @@ -39,6 +39,7 @@
15437  #include <linux/syslog.h>
15438  #include <linux/cpu.h>
15439  #include <linux/notifier.h>
15440 +#include <linux/vs_cvirt.h>
15441  
15442  #include <asm/uaccess.h>
15443  
15444 @@ -266,18 +267,15 @@ int do_syslog(int type, char __user *buf
15445         unsigned i, j, limit, count;
15446         int do_clear = 0;
15447         char c;
15448 -       int error = 0;
15449 +       int error;
15450  
15451         error = security_syslog(type, from_file);
15452         if (error)
15453                 return error;
15454  
15455 -       switch (type) {
15456 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
15457 -               break;
15458 -       case SYSLOG_ACTION_OPEN:        /* Open log */
15459 -               break;
15460 -       case SYSLOG_ACTION_READ:        /* Read from log */
15461 +       if ((type == SYSLOG_ACTION_READ) ||
15462 +           (type == SYSLOG_ACTION_READ_ALL) ||
15463 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
15464                 error = -EINVAL;
15465                 if (!buf || len < 0)
15466                         goto out;
15467 @@ -288,6 +286,16 @@ int do_syslog(int type, char __user *buf
15468                         error = -EFAULT;
15469                         goto out;
15470                 }
15471 +       }
15472 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15473 +               return vx_do_syslog(type, buf, len);
15474 +
15475 +       switch (type) {
15476 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
15477 +               break;
15478 +       case SYSLOG_ACTION_OPEN:        /* Open log */
15479 +               break;
15480 +       case SYSLOG_ACTION_READ:        /* Read from log */
15481                 error = wait_event_interruptible(log_wait,
15482                                                         (log_start - log_end));
15483                 if (error)
15484 @@ -314,16 +322,6 @@ int do_syslog(int type, char __user *buf
15485                 /* FALL THRU */
15486         /* Read last kernel messages */
15487         case SYSLOG_ACTION_READ_ALL:
15488 -               error = -EINVAL;
15489 -               if (!buf || len < 0)
15490 -                       goto out;
15491 -               error = 0;
15492 -               if (!len)
15493 -                       goto out;
15494 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
15495 -                       error = -EFAULT;
15496 -                       goto out;
15497 -               }
15498                 count = len;
15499                 if (count > log_buf_len)
15500                         count = log_buf_len;
15501 diff -NurpP --minimal linux-2.6.36/kernel/ptrace.c linux-2.6.36-vs2.3.0.36.33/kernel/ptrace.c
15502 --- linux-2.6.36/kernel/ptrace.c        2010-10-21 13:07:57.000000000 +0200
15503 +++ linux-2.6.36-vs2.3.0.36.33/kernel/ptrace.c  2010-10-21 13:09:36.000000000 +0200
15504 @@ -22,6 +22,7 @@
15505  #include <linux/syscalls.h>
15506  #include <linux/uaccess.h>
15507  #include <linux/regset.h>
15508 +#include <linux/vs_context.h>
15509  
15510  
15511  /*
15512 @@ -150,6 +151,11 @@ int __ptrace_may_access(struct task_stru
15513                 dumpable = get_dumpable(task->mm);
15514         if (!dumpable && !capable(CAP_SYS_PTRACE))
15515                 return -EPERM;
15516 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_IDENT))
15517 +               return -EPERM;
15518 +       if (!vx_check(task->xid, VS_IDENT) &&
15519 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
15520 +               return -EACCES;
15521  
15522         return security_ptrace_access_check(task, mode);
15523  }
15524 @@ -709,6 +715,10 @@ SYSCALL_DEFINE4(ptrace, long, request, l
15525                 goto out;
15526         }
15527  
15528 +       ret = -EPERM;
15529 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
15530 +               goto out_put_task_struct;
15531 +
15532         if (request == PTRACE_ATTACH) {
15533                 ret = ptrace_attach(child);
15534                 /*
15535 diff -NurpP --minimal linux-2.6.36/kernel/sched.c linux-2.6.36-vs2.3.0.36.33/kernel/sched.c
15536 --- linux-2.6.36/kernel/sched.c 2010-10-21 13:07:57.000000000 +0200
15537 +++ linux-2.6.36-vs2.3.0.36.33/kernel/sched.c   2010-10-21 13:09:36.000000000 +0200
15538 @@ -72,6 +72,8 @@
15539  #include <linux/ctype.h>
15540  #include <linux/ftrace.h>
15541  #include <linux/slab.h>
15542 +#include <linux/vs_sched.h>
15543 +#include <linux/vs_cvirt.h>
15544  
15545  #include <asm/tlb.h>
15546  #include <asm/irq_regs.h>
15547 @@ -3024,9 +3026,17 @@ static inline long calc_load_fold_idle(v
15548   */
15549  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
15550  {
15551 -       loads[0] = (avenrun[0] + offset) << shift;
15552 -       loads[1] = (avenrun[1] + offset) << shift;
15553 -       loads[2] = (avenrun[2] + offset) << shift;
15554 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
15555 +               struct vx_info *vxi = current_vx_info();
15556 +
15557 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
15558 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
15559 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
15560 +       } else {
15561 +               loads[0] = (avenrun[0] + offset) << shift;
15562 +               loads[1] = (avenrun[1] + offset) << shift;
15563 +               loads[2] = (avenrun[2] + offset) << shift;
15564 +       }
15565  }
15566  
15567  static unsigned long
15568 @@ -3321,16 +3331,19 @@ void account_user_time(struct task_struc
15569                        cputime_t cputime_scaled)
15570  {
15571         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
15572 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15573         cputime64_t tmp;
15574 +       int nice = (TASK_NICE(p) > 0);
15575  
15576         /* Add user time to process. */
15577         p->utime = cputime_add(p->utime, cputime);
15578         p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
15579 +       vx_account_user(vxi, cputime, nice);
15580         account_group_user_time(p, cputime);
15581  
15582         /* Add user time to cpustat. */
15583         tmp = cputime_to_cputime64(cputime);
15584 -       if (TASK_NICE(p) > 0)
15585 +       if (nice)
15586                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
15587         else
15588                 cpustat->user = cputime64_add(cpustat->user, tmp);
15589 @@ -3381,6 +3394,7 @@ void account_system_time(struct task_str
15590                          cputime_t cputime, cputime_t cputime_scaled)
15591  {
15592         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
15593 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15594         cputime64_t tmp;
15595  
15596         if ((p->flags & PF_VCPU) && (irq_count() - hardirq_offset == 0)) {
15597 @@ -3391,6 +3405,7 @@ void account_system_time(struct task_str
15598         /* Add system time to process. */
15599         p->stime = cputime_add(p->stime, cputime);
15600         p->stimescaled = cputime_add(p->stimescaled, cputime_scaled);
15601 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
15602         account_group_system_time(p, cputime);
15603  
15604         /* Add system time to cpustat. */
15605 @@ -4477,7 +4492,7 @@ SYSCALL_DEFINE1(nice, int, increment)
15606                 nice = 19;
15607  
15608         if (increment < 0 && !can_nice(current, nice))
15609 -               return -EPERM;
15610 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
15611  
15612         retval = security_task_setnice(current, nice);
15613         if (retval)
15614 diff -NurpP --minimal linux-2.6.36/kernel/sched_fair.c linux-2.6.36-vs2.3.0.36.33/kernel/sched_fair.c
15615 --- linux-2.6.36/kernel/sched_fair.c    2010-10-21 13:07:57.000000000 +0200
15616 +++ linux-2.6.36-vs2.3.0.36.33/kernel/sched_fair.c      2010-10-21 13:09:36.000000000 +0200
15617 @@ -782,6 +782,9 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
15618         check_spread(cfs_rq, se);
15619         if (se != cfs_rq->curr)
15620                 __enqueue_entity(cfs_rq, se);
15621 +
15622 +       if (entity_is_task(se))
15623 +               vx_activate_task(task_of(se));
15624  }
15625  
15626  static void __clear_buddies(struct cfs_rq *cfs_rq, struct sched_entity *se)
15627 @@ -825,6 +828,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
15628  
15629         if (se != cfs_rq->curr)
15630                 __dequeue_entity(cfs_rq, se);
15631 +       if (entity_is_task(se))
15632 +               vx_deactivate_task(task_of(se));
15633         account_entity_dequeue(cfs_rq, se);
15634         update_min_vruntime(cfs_rq);
15635  
15636 diff -NurpP --minimal linux-2.6.36/kernel/signal.c linux-2.6.36-vs2.3.0.36.33/kernel/signal.c
15637 --- linux-2.6.36/kernel/signal.c        2010-10-21 13:07:57.000000000 +0200
15638 +++ linux-2.6.36-vs2.3.0.36.33/kernel/signal.c  2010-10-21 13:09:36.000000000 +0200
15639 @@ -28,6 +28,8 @@
15640  #include <linux/freezer.h>
15641  #include <linux/pid_namespace.h>
15642  #include <linux/nsproxy.h>
15643 +#include <linux/vs_context.h>
15644 +#include <linux/vs_pid.h>
15645  #define CREATE_TRACE_POINTS
15646  #include <trace/events/signal.h>
15647  
15648 @@ -646,9 +648,18 @@ static int check_kill_permission(int sig
15649         struct pid *sid;
15650         int error;
15651  
15652 +       vxdprintk(VXD_CBIT(misc, 7),
15653 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
15654 +               sig, info, t, vx_task_xid(t), t->pid);
15655 +
15656         if (!valid_signal(sig))
15657                 return -EINVAL;
15658  
15659 +/*     FIXME: needed? if so, why?
15660 +       if ((info != SEND_SIG_NOINFO) &&
15661 +               (is_si_special(info) || !si_fromuser(info)))
15662 +               goto skip;      */
15663 +
15664         if (!si_fromuser(info))
15665                 return 0;
15666  
15667 @@ -678,6 +689,20 @@ static int check_kill_permission(int sig
15668                 }
15669         }
15670  
15671 +       error = -EPERM;
15672 +       if (t->pid == 1 && current->xid)
15673 +               return error;
15674 +
15675 +       error = -ESRCH;
15676 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
15677 +                 loops, maybe ENOENT or EACCES? */
15678 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
15679 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
15680 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
15681 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
15682 +               return error;
15683 +       }
15684 +/* skip: */
15685         return security_task_kill(t, info, sig, 0);
15686  }
15687  
15688 @@ -1170,7 +1195,7 @@ int kill_pid_info(int sig, struct siginf
15689         rcu_read_lock();
15690  retry:
15691         p = pid_task(pid, PIDTYPE_PID);
15692 -       if (p) {
15693 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
15694                 error = group_send_sig_info(sig, info, p);
15695                 if (unlikely(error == -ESRCH))
15696                         /*
15697 @@ -1210,7 +1235,7 @@ int kill_pid_info_as_uid(int sig, struct
15698  
15699         rcu_read_lock();
15700         p = pid_task(pid, PIDTYPE_PID);
15701 -       if (!p) {
15702 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
15703                 ret = -ESRCH;
15704                 goto out_unlock;
15705         }
15706 @@ -1265,8 +1290,10 @@ static int kill_something_info(int sig, 
15707                 struct task_struct * p;
15708  
15709                 for_each_process(p) {
15710 -                       if (task_pid_vnr(p) > 1 &&
15711 -                                       !same_thread_group(p, current)) {
15712 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
15713 +                               task_pid_vnr(p) > 1 &&
15714 +                               !same_thread_group(p, current) &&
15715 +                               !vx_current_initpid(p->pid)) {
15716                                 int err = group_send_sig_info(sig, info, p);
15717                                 ++count;
15718                                 if (err != -EPERM)
15719 @@ -1933,6 +1960,11 @@ relock:
15720                                 !sig_kernel_only(signr))
15721                         continue;
15722  
15723 +               /* virtual init is protected against user signals */
15724 +               if ((info->si_code == SI_USER) &&
15725 +                       vx_current_initpid(current->pid))
15726 +                       continue;
15727 +
15728                 if (sig_kernel_stop(signr)) {
15729                         /*
15730                          * The default action is to stop all threads in
15731 diff -NurpP --minimal linux-2.6.36/kernel/softirq.c linux-2.6.36-vs2.3.0.36.33/kernel/softirq.c
15732 --- linux-2.6.36/kernel/softirq.c       2010-08-02 16:52:57.000000000 +0200
15733 +++ linux-2.6.36-vs2.3.0.36.33/kernel/softirq.c 2010-10-21 13:09:36.000000000 +0200
15734 @@ -24,6 +24,7 @@
15735  #include <linux/ftrace.h>
15736  #include <linux/smp.h>
15737  #include <linux/tick.h>
15738 +#include <linux/vs_context.h>
15739  
15740  #define CREATE_TRACE_POINTS
15741  #include <trace/events/irq.h>
15742 diff -NurpP --minimal linux-2.6.36/kernel/sys.c linux-2.6.36-vs2.3.0.36.33/kernel/sys.c
15743 --- linux-2.6.36/kernel/sys.c   2010-10-21 13:07:57.000000000 +0200
15744 +++ linux-2.6.36-vs2.3.0.36.33/kernel/sys.c     2010-10-21 13:45:48.000000000 +0200
15745 @@ -42,6 +42,7 @@
15746  #include <linux/syscalls.h>
15747  #include <linux/kprobes.h>
15748  #include <linux/user_namespace.h>
15749 +#include <linux/vs_pid.h>
15750  
15751  #include <asm/uaccess.h>
15752  #include <asm/io.h>
15753 @@ -131,7 +132,10 @@ static int set_one_prio(struct task_stru
15754                 goto out;
15755         }
15756         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
15757 -               error = -EACCES;
15758 +               if (vx_flags(VXF_IGNEG_NICE, 0))
15759 +                       error = 0;
15760 +               else
15761 +                       error = -EACCES;
15762                 goto out;
15763         }
15764         no_nice = security_task_setnice(p, niceval);
15765 @@ -181,6 +185,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
15766                         else
15767                                 pgrp = task_pgrp(current);
15768                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15769 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15770 +                                       continue;
15771                                 error = set_one_prio(p, niceval, error);
15772                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
15773                         break;
15774 @@ -244,6 +250,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
15775                         else
15776                                 pgrp = task_pgrp(current);
15777                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
15778 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
15779 +                                       continue;
15780                                 niceval = 20 - task_nice(p);
15781                                 if (niceval > retval)
15782                                         retval = niceval;
15783 @@ -357,6 +365,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
15784  
15785  static DEFINE_MUTEX(reboot_mutex);
15786  
15787 +long vs_reboot(unsigned int, void __user *);
15788 +
15789  /*
15790   * Reboot system call: for obvious reasons only root may call it,
15791   * and even root needs to set up some magic numbers in the registers
15792 @@ -389,6 +399,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
15793         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
15794                 cmd = LINUX_REBOOT_CMD_HALT;
15795  
15796 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15797 +               return vs_reboot(cmd, arg);
15798 +
15799         mutex_lock(&reboot_mutex);
15800         switch (cmd) {
15801         case LINUX_REBOOT_CMD_RESTART:
15802 @@ -1169,7 +1182,7 @@ SYSCALL_DEFINE2(sethostname, char __user
15803         int errno;
15804         char tmp[__NEW_UTS_LEN];
15805  
15806 -       if (!capable(CAP_SYS_ADMIN))
15807 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15808                 return -EPERM;
15809         if (len < 0 || len > __NEW_UTS_LEN)
15810                 return -EINVAL;
15811 @@ -1218,7 +1231,7 @@ SYSCALL_DEFINE2(setdomainname, char __us
15812         int errno;
15813         char tmp[__NEW_UTS_LEN];
15814  
15815 -       if (!capable(CAP_SYS_ADMIN))
15816 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15817                 return -EPERM;
15818         if (len < 0 || len > __NEW_UTS_LEN)
15819                 return -EINVAL;
15820 @@ -1334,7 +1347,7 @@ int do_prlimit(struct task_struct *tsk, 
15821         task_lock(tsk->group_leader);
15822         if (new_rlim) {
15823                 if (new_rlim->rlim_max > rlim->rlim_max &&
15824 -                               !capable(CAP_SYS_RESOURCE))
15825 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15826                         retval = -EPERM;
15827                 if (!retval)
15828                         retval = security_task_setrlimit(tsk->group_leader,
15829 @@ -1383,7 +1396,7 @@ static int check_prlimit_permission(stru
15830              cred->gid != tcred->egid ||
15831              cred->gid != tcred->sgid ||
15832              cred->gid != tcred->gid) &&
15833 -            !capable(CAP_SYS_RESOURCE)) {
15834 +            !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT)) {
15835                 return -EPERM;
15836         }
15837  
15838 diff -NurpP --minimal linux-2.6.36/kernel/sysctl_binary.c linux-2.6.36-vs2.3.0.36.33/kernel/sysctl_binary.c
15839 --- linux-2.6.36/kernel/sysctl_binary.c 2010-08-02 16:52:57.000000000 +0200
15840 +++ linux-2.6.36-vs2.3.0.36.33/kernel/sysctl_binary.c   2010-10-21 13:09:36.000000000 +0200
15841 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
15842  
15843         { CTL_INT,      KERN_PANIC,                     "panic" },
15844         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
15845 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
15846  
15847         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
15848         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
15849 diff -NurpP --minimal linux-2.6.36/kernel/sysctl.c linux-2.6.36-vs2.3.0.36.33/kernel/sysctl.c
15850 --- linux-2.6.36/kernel/sysctl.c        2010-10-21 13:07:57.000000000 +0200
15851 +++ linux-2.6.36-vs2.3.0.36.33/kernel/sysctl.c  2010-10-21 13:09:36.000000000 +0200
15852 @@ -73,6 +73,7 @@
15853  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
15854  #include <linux/lockdep.h>
15855  #endif
15856 +extern char vshelper_path[];
15857  #ifdef CONFIG_CHR_DEV_SG
15858  #include <scsi/sg.h>
15859  #endif
15860 @@ -573,6 +574,13 @@ static struct ctl_table kern_table[] = {
15861                 .proc_handler   = proc_dostring,
15862         },
15863  #endif
15864 +       {
15865 +               .procname       = "vshelper",
15866 +               .data           = &vshelper_path,
15867 +               .maxlen         = 256,
15868 +               .mode           = 0644,
15869 +               .proc_handler   = &proc_dostring,
15870 +       },
15871  #ifdef CONFIG_CHR_DEV_SG
15872         {
15873                 .procname       = "sg-big-buff",
15874 diff -NurpP --minimal linux-2.6.36/kernel/time/timekeeping.c linux-2.6.36-vs2.3.0.36.33/kernel/time/timekeeping.c
15875 --- linux-2.6.36/kernel/time/timekeeping.c      2010-10-21 13:07:57.000000000 +0200
15876 +++ linux-2.6.36-vs2.3.0.36.33/kernel/time/timekeeping.c        2010-10-21 14:17:59.000000000 +0200
15877 @@ -229,6 +229,7 @@ void getnstimeofday(struct timespec *ts)
15878         } while (read_seqretry(&xtime_lock, seq));
15879  
15880         timespec_add_ns(ts, nsecs);
15881 +       vx_adjust_timespec(ts);
15882  }
15883  
15884  EXPORT_SYMBOL(getnstimeofday);
15885 diff -NurpP --minimal linux-2.6.36/kernel/time.c linux-2.6.36-vs2.3.0.36.33/kernel/time.c
15886 --- linux-2.6.36/kernel/time.c  2010-10-21 13:07:57.000000000 +0200
15887 +++ linux-2.6.36-vs2.3.0.36.33/kernel/time.c    2010-10-21 14:22:43.000000000 +0200
15888 @@ -92,7 +92,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
15889         if (err)
15890                 return err;
15891  
15892 -       do_settimeofday(&tv);
15893 +       vx_settimeofday(&tv);
15894         return 0;
15895  }
15896  
15897 @@ -177,7 +177,7 @@ int do_sys_settimeofday(struct timespec 
15898                 /* SMP safe, again the code in arch/foo/time.c should
15899                  * globally block out interrupts when it runs.
15900                  */
15901 -               return do_settimeofday(tv);
15902 +               return vx_settimeofday(tv);
15903         }
15904         return 0;
15905  }
15906 diff -NurpP --minimal linux-2.6.36/kernel/timer.c linux-2.6.36-vs2.3.0.36.33/kernel/timer.c
15907 --- linux-2.6.36/kernel/timer.c 2010-10-21 13:07:57.000000000 +0200
15908 +++ linux-2.6.36-vs2.3.0.36.33/kernel/timer.c   2010-10-21 13:09:36.000000000 +0200
15909 @@ -40,6 +40,10 @@
15910  #include <linux/perf_event.h>
15911  #include <linux/sched.h>
15912  #include <linux/slab.h>
15913 +#include <linux/vs_base.h>
15914 +#include <linux/vs_cvirt.h>
15915 +#include <linux/vs_pid.h>
15916 +#include <linux/vserver/sched.h>
15917  
15918  #include <asm/uaccess.h>
15919  #include <asm/unistd.h>
15920 @@ -1332,12 +1336,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
15921  
15922  #endif
15923  
15924 -#ifndef __alpha__
15925 -
15926 -/*
15927 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
15928 - * should be moved into arch/i386 instead?
15929 - */
15930  
15931  /**
15932   * sys_getpid - return the thread group id of the current process
15933 @@ -1366,10 +1364,23 @@ SYSCALL_DEFINE0(getppid)
15934         rcu_read_lock();
15935         pid = task_tgid_vnr(current->real_parent);
15936         rcu_read_unlock();
15937 +       return vx_map_pid(pid);
15938 +}
15939  
15940 -       return pid;
15941 +#ifdef __alpha__
15942 +
15943 +/*
15944 + * The Alpha uses getxpid, getxuid, and getxgid instead.
15945 + */
15946 +
15947 +asmlinkage long do_getxpid(long *ppid)
15948 +{
15949 +       *ppid = sys_getppid();
15950 +       return sys_getpid();
15951  }
15952  
15953 +#else /* _alpha_ */
15954 +
15955  SYSCALL_DEFINE0(getuid)
15956  {
15957         /* Only we change this so SMP safe */
15958 diff -NurpP --minimal linux-2.6.36/kernel/user_namespace.c linux-2.6.36-vs2.3.0.36.33/kernel/user_namespace.c
15959 --- linux-2.6.36/kernel/user_namespace.c        2010-10-21 13:07:57.000000000 +0200
15960 +++ linux-2.6.36-vs2.3.0.36.33/kernel/user_namespace.c  2010-10-21 13:09:36.000000000 +0200
15961 @@ -11,6 +11,7 @@
15962  #include <linux/user_namespace.h>
15963  #include <linux/highuid.h>
15964  #include <linux/cred.h>
15965 +#include <linux/vserver/global.h>
15966  
15967  /*
15968   * Create a new user namespace, deriving the creator from the user in the
15969 @@ -31,6 +32,7 @@ int create_user_ns(struct cred *new)
15970                 return -ENOMEM;
15971  
15972         kref_init(&ns->kref);
15973 +       atomic_inc(&vs_global_user_ns);
15974  
15975         for (n = 0; n < UIDHASH_SZ; ++n)
15976                 INIT_HLIST_HEAD(ns->uidhash_table + n);
15977 @@ -79,6 +81,8 @@ void free_user_ns(struct kref *kref)
15978         struct user_namespace *ns =
15979                 container_of(kref, struct user_namespace, kref);
15980  
15981 +       /* FIXME: maybe move into destroyer? */
15982 +       atomic_dec(&vs_global_user_ns);
15983         INIT_WORK(&ns->destroyer, free_user_ns_work);
15984         schedule_work(&ns->destroyer);
15985  }
15986 diff -NurpP --minimal linux-2.6.36/kernel/utsname.c linux-2.6.36-vs2.3.0.36.33/kernel/utsname.c
15987 --- linux-2.6.36/kernel/utsname.c       2009-09-10 15:26:28.000000000 +0200
15988 +++ linux-2.6.36-vs2.3.0.36.33/kernel/utsname.c 2010-10-21 13:09:36.000000000 +0200
15989 @@ -14,14 +14,17 @@
15990  #include <linux/utsname.h>
15991  #include <linux/err.h>
15992  #include <linux/slab.h>
15993 +#include <linux/vserver/global.h>
15994  
15995  static struct uts_namespace *create_uts_ns(void)
15996  {
15997         struct uts_namespace *uts_ns;
15998  
15999         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
16000 -       if (uts_ns)
16001 +       if (uts_ns) {
16002                 kref_init(&uts_ns->kref);
16003 +               atomic_inc(&vs_global_uts_ns);
16004 +       }
16005         return uts_ns;
16006  }
16007  
16008 @@ -71,5 +74,6 @@ void free_uts_ns(struct kref *kref)
16009         struct uts_namespace *ns;
16010  
16011         ns = container_of(kref, struct uts_namespace, kref);
16012 +       atomic_dec(&vs_global_uts_ns);
16013         kfree(ns);
16014  }
16015 diff -NurpP --minimal linux-2.6.36/kernel/vserver/cacct.c linux-2.6.36-vs2.3.0.36.33/kernel/vserver/cacct.c
16016 --- linux-2.6.36/kernel/vserver/cacct.c 1970-01-01 01:00:00.000000000 +0100
16017 +++ linux-2.6.36-vs2.3.0.36.33/kernel/vserver/cacct.c   2010-10-21 13:09:36.000000000 +0200
16018 @@ -0,0 +1,42 @@
16019 +/*
16020 + *  linux/kernel/vserver/cacct.c
16021 + *
16022 + *  Virtual Server: Context Accounting
16023 + *
16024 + *  Copyright (C) 2006-2007 Herbert Pötzl
16025 + *
16026 + *  V0.01  added accounting stats
16027 + *
16028 + */
16029 +
16030 +#include <linux/types.h>
16031 +#include <linux/vs_context.h>
16032 +#include <linux/vserver/cacct_cmd.h>
16033 +#include <linux/vserver/cacct_int.h>
16034 +
16035 +#include <asm/errno.h>
16036 +#include <asm/uaccess.h>
16037 +
16038 +
16039 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
16040 +{
16041 +       struct vcmd_sock_stat_v0 vc_data;
16042 +       int j, field;
16043 +
16044 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16045 +               return -EFAULT;
16046 +
16047 +       field = vc_data.field;
16048 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
16049 +               return -EINVAL;
16050 +
16051 +       for (j = 0; j < 3; j++) {
16052 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
16053 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
16054 +       }
16055 +
16056 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16057 +               return -EFAULT;
16058 +       return 0;
16059 +}
16060 +
16061 diff -NurpP --minimal linux-2.6.36/kernel/vserver/cacct_init.h linux-2.6.36-vs2.3.0.36.33/kernel/vserver/cacct_init.h
16062 --- linux-2.6.36/kernel/vserver/cacct_init.h    1970-01-01 01:00:00.000000000 +0100
16063 +++ linux-2.6.36-vs2.3.0.36.33/kernel/vserver/cacct_init.h      2010-10-21 13:09:36.000000000 +0200
16064 @@ -0,0 +1,25 @@
16065 +
16066 +
16067 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
16068 +{
16069 +       int i, j;
16070 +
16071 +
16072 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
16073 +               for (j = 0; j < 3; j++) {
16074 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
16075 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
16076 +               }
16077 +       }
16078 +       for (i = 0; i < 8; i++)
16079 +               atomic_set(&cacct->slab[i], 0);
16080 +       for (i = 0; i < 5; i++)
16081 +               for (j = 0; j < 4; j++)
16082 +                       atomic_set(&cacct->page[i][j], 0);
16083 +}
16084 +
16085 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
16086 +{
16087 +       return;
16088 +}
16089 +
16090 diff -NurpP --minimal linux-2.6.36/kernel/vserver/cacct_proc.h linux-2.6.36-vs2.3.0.36.33/kernel/vserver/cacct_proc.h
16091 --- linux-2.6.36/kernel/vserver/cacct_proc.h    1970-01-01 01:00:00.000000000 +0100
16092 +++ linux-2.6.36-vs2.3.0.36.33/kernel/vserver/cacct_proc.h      2010-10-21 13:09:36.000000000 +0200
16093 @@ -0,0 +1,53 @@
16094 +#ifndef _VX_CACCT_PROC_H
16095 +#define _VX_CACCT_PROC_H
16096 +
16097 +#include <linux/vserver/cacct_int.h>
16098 +
16099 +
16100 +#define VX_SOCKA_TOP   \
16101 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
16102 +
16103 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
16104 +{
16105 +       int i, j, length = 0;
16106 +       static char *type[VXA_SOCK_SIZE] = {
16107 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
16108 +       };
16109 +
16110 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
16111 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
16112 +               length += sprintf(buffer + length, "%s:", type[i]);
16113 +               for (j = 0; j < 3; j++) {
16114 +                       length += sprintf(buffer + length,
16115 +                               "\t%10lu/%-10lu",
16116 +                               vx_sock_count(cacct, i, j),
16117 +                               vx_sock_total(cacct, i, j));
16118 +               }
16119 +               buffer[length++] = '\n';
16120 +       }
16121 +
16122 +       length += sprintf(buffer + length, "\n");
16123 +       length += sprintf(buffer + length,
16124 +               "slab:\t %8u %8u %8u %8u\n",
16125 +               atomic_read(&cacct->slab[1]),
16126 +               atomic_read(&cacct->slab[4]),
16127 +               atomic_read(&cacct->slab[0]),
16128 +               atomic_read(&cacct->slab[2]));
16129 +
16130 +       length += sprintf(buffer + length, "\n");
16131 +       for (i = 0; i < 5; i++) {
16132 +               length += sprintf(buffer + length,
16133 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
16134 +                       atomic_read(&cacct->page[i][0]),
16135 +                       atomic_read(&cacct->page[i][1]),
16136 +                       atomic_read(&cacct->page[i][2]),
16137 +                       atomic_read(&cacct->page[i][3]),
16138 +                       atomic_read(&cacct->page[i][4]),
16139 +                       atomic_read(&cacct->page[i][5]),
16140 +                       atomic_read(&cacct->page[i][6]),
16141 +                       atomic_read(&cacct->page[i][7]));
16142 +       }
16143 +       return length;
16144 +}
16145 +
16146 +#endif /* _VX_CACCT_PROC_H */
16147 diff -NurpP --minimal linux-2.6.36/kernel/vserver/context.c linux-2.6.36-vs2.3.0.36.33/kernel/vserver/context.c
16148 --- linux-2.6.36/kernel/vserver/context.c       1970-01-01 01:00:00.000000000 +0100
16149 +++ linux-2.6.36-vs2.3.0.36.33/kernel/vserver/context.c 2010-10-21 14:39:59.000000000 +0200
16150 @@ -0,0 +1,1058 @@
16151 +/*
16152 + *  linux/kernel/vserver/context.c
16153 + *
16154 + *  Virtual Server: Context Support
16155 + *
16156 + *  Copyright (C) 2003-2007  Herbert Pötzl
16157 + *
16158 + *  V0.01  context helper
16159 + *  V0.02  vx_ctx_kill syscall command
16160 + *  V0.03  replaced context_info calls
16161 + *  V0.04  redesign of struct (de)alloc
16162 + *  V0.05  rlimit basic implementation
16163 + *  V0.06  task_xid and info commands
16164 + *  V0.07  context flags and caps
16165 + *  V0.08  switch to RCU based hash
16166 + *  V0.09  revert to non RCU for now
16167 + *  V0.10  and back to working RCU hash
16168 + *  V0.11  and back to locking again
16169 + *  V0.12  referenced context store
16170 + *  V0.13  separate per cpu data
16171 + *  V0.14  changed vcmds to vxi arg
16172 + *  V0.15  added context stat
16173 + *  V0.16  have __create claim() the vxi
16174 + *  V0.17  removed older and legacy stuff
16175 + *
16176 + */
16177 +
16178 +#include <linux/slab.h>
16179 +#include <linux/types.h>
16180 +#include <linux/security.h>
16181 +#include <linux/pid_namespace.h>
16182 +
16183 +#include <linux/vserver/context.h>
16184 +#include <linux/vserver/network.h>
16185 +#include <linux/vserver/debug.h>
16186 +#include <linux/vserver/limit.h>
16187 +#include <linux/vserver/limit_int.h>
16188 +#include <linux/vserver/space.h>
16189 +#include <linux/init_task.h>
16190 +#include <linux/fs_struct.h>
16191 +
16192 +#include <linux/vs_context.h>
16193 +#include <linux/vs_limit.h>
16194 +#include <linux/vs_pid.h>
16195 +#include <linux/vserver/context_cmd.h>
16196 +
16197 +#include "cvirt_init.h"
16198 +#include "cacct_init.h"
16199 +#include "limit_init.h"
16200 +#include "sched_init.h"
16201 +
16202 +
16203 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
16204 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
16205 +
16206 +
16207 +/*     now inactive context structures */
16208 +
16209 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
16210 +
16211 +static spinlock_t vx_info_inactive_lock = SPIN_LOCK_UNLOCKED;
16212 +
16213 +
16214 +/*     __alloc_vx_info()
16215 +
16216 +       * allocate an initialized vx_info struct
16217 +       * doesn't make it visible (hash)                        */
16218 +
16219 +static struct vx_info *__alloc_vx_info(xid_t xid)
16220 +{
16221 +       struct vx_info *new = NULL;
16222 +       int cpu, index;
16223 +
16224 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
16225 +
16226 +       /* would this benefit from a slab cache? */
16227 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
16228 +       if (!new)
16229 +               return 0;
16230 +
16231 +       memset(new, 0, sizeof(struct vx_info));
16232 +#ifdef CONFIG_SMP
16233 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
16234 +       if (!new->ptr_pc)
16235 +               goto error;
16236 +#endif
16237 +       new->vx_id = xid;
16238 +       INIT_HLIST_NODE(&new->vx_hlist);
16239 +       atomic_set(&new->vx_usecnt, 0);
16240 +       atomic_set(&new->vx_tasks, 0);
16241 +       new->vx_parent = NULL;
16242 +       new->vx_state = 0;
16243 +       init_waitqueue_head(&new->vx_wait);
16244 +
16245 +       /* prepare reaper */
16246 +       get_task_struct(init_pid_ns.child_reaper);
16247 +       new->vx_reaper = init_pid_ns.child_reaper;
16248 +       new->vx_badness_bias = 0;
16249 +
16250 +       /* rest of init goes here */
16251 +       vx_info_init_limit(&new->limit);
16252 +       vx_info_init_sched(&new->sched);
16253 +       vx_info_init_cvirt(&new->cvirt);
16254 +       vx_info_init_cacct(&new->cacct);
16255 +
16256 +       /* per cpu data structures */
16257 +       for_each_possible_cpu(cpu) {
16258 +               vx_info_init_sched_pc(
16259 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
16260 +               vx_info_init_cvirt_pc(
16261 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
16262 +       }
16263 +
16264 +       new->vx_flags = VXF_INIT_SET;
16265 +       cap_set_init_eff(new->vx_bcaps);
16266 +       new->vx_ccaps = 0;
16267 +       new->vx_umask = 0;
16268 +
16269 +       new->reboot_cmd = 0;
16270 +       new->exit_code = 0;
16271 +
16272 +       // preconfig fs entries
16273 +       for (index = 0; index < VX_SPACES; index++) {
16274 +               spin_lock(&init_fs.lock);
16275 +               init_fs.users++;
16276 +               spin_unlock(&init_fs.lock);
16277 +               new->vx_fs[index] = &init_fs;
16278 +       }
16279 +
16280 +       vxdprintk(VXD_CBIT(xid, 0),
16281 +               "alloc_vx_info(%d) = %p", xid, new);
16282 +       vxh_alloc_vx_info(new);
16283 +       atomic_inc(&vx_global_ctotal);
16284 +       return new;
16285 +#ifdef CONFIG_SMP
16286 +error:
16287 +       kfree(new);
16288 +       return 0;
16289 +#endif
16290 +}
16291 +
16292 +/*     __dealloc_vx_info()
16293 +
16294 +       * final disposal of vx_info                             */
16295 +
16296 +static void __dealloc_vx_info(struct vx_info *vxi)
16297 +{
16298 +#ifdef CONFIG_VSERVER_WARN
16299 +       struct vx_info_save vxis;
16300 +       int cpu;
16301 +#endif
16302 +       vxdprintk(VXD_CBIT(xid, 0),
16303 +               "dealloc_vx_info(%p)", vxi);
16304 +       vxh_dealloc_vx_info(vxi);
16305 +
16306 +#ifdef CONFIG_VSERVER_WARN
16307 +       enter_vx_info(vxi, &vxis);
16308 +       vx_info_exit_limit(&vxi->limit);
16309 +       vx_info_exit_sched(&vxi->sched);
16310 +       vx_info_exit_cvirt(&vxi->cvirt);
16311 +       vx_info_exit_cacct(&vxi->cacct);
16312 +
16313 +       for_each_possible_cpu(cpu) {
16314 +               vx_info_exit_sched_pc(
16315 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
16316 +               vx_info_exit_cvirt_pc(
16317 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
16318 +       }
16319 +       leave_vx_info(&vxis);
16320 +#endif
16321 +
16322 +       vxi->vx_id = -1;
16323 +       vxi->vx_state |= VXS_RELEASED;
16324 +
16325 +#ifdef CONFIG_SMP
16326 +       free_percpu(vxi->ptr_pc);
16327 +#endif
16328 +       kfree(vxi);
16329 +       atomic_dec(&vx_global_ctotal);
16330 +}
16331 +
16332 +static void __shutdown_vx_info(struct vx_info *vxi)
16333 +{
16334 +       struct nsproxy *nsproxy;
16335 +       struct fs_struct *fs;
16336 +       int index, kill;
16337 +
16338 +       might_sleep();
16339 +
16340 +       vxi->vx_state |= VXS_SHUTDOWN;
16341 +       vs_state_change(vxi, VSC_SHUTDOWN);
16342 +
16343 +       for (index = 0; index < VX_SPACES; index++) {
16344 +               nsproxy = xchg(&vxi->vx_nsproxy[index], NULL);
16345 +               if (nsproxy)
16346 +                       put_nsproxy(nsproxy);
16347 +
16348 +               fs = xchg(&vxi->vx_fs[index], NULL);
16349 +               spin_lock(&fs->lock);
16350 +               kill = !--fs->users;
16351 +               spin_unlock(&fs->lock);
16352 +               if (kill)
16353 +                       free_fs_struct(fs);
16354 +       }
16355 +}
16356 +
16357 +/* exported stuff */
16358 +
16359 +void free_vx_info(struct vx_info *vxi)
16360 +{
16361 +       unsigned long flags;
16362 +       unsigned index;
16363 +
16364 +       /* check for reference counts first */
16365 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
16366 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16367 +
16368 +       /* context must not be hashed */
16369 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16370 +
16371 +       /* context shutdown is mandatory */
16372 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
16373 +
16374 +       /* nsproxy and fs check */
16375 +       for (index = 0; index < VX_SPACES; index++) {
16376 +               BUG_ON(vxi->vx_nsproxy[index]);
16377 +               BUG_ON(vxi->vx_fs[index]);
16378 +       }
16379 +
16380 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16381 +       hlist_del(&vxi->vx_hlist);
16382 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16383 +
16384 +       __dealloc_vx_info(vxi);
16385 +}
16386 +
16387 +
16388 +/*     hash table for vx_info hash */
16389 +
16390 +#define VX_HASH_SIZE   13
16391 +
16392 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
16393 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
16394 +
16395 +static spinlock_t vx_info_hash_lock = SPIN_LOCK_UNLOCKED;
16396 +
16397 +
16398 +static inline unsigned int __hashval(xid_t xid)
16399 +{
16400 +       return (xid % VX_HASH_SIZE);
16401 +}
16402 +
16403 +
16404 +
16405 +/*     __hash_vx_info()
16406 +
16407 +       * add the vxi to the global hash table
16408 +       * requires the hash_lock to be held                     */
16409 +
16410 +static inline void __hash_vx_info(struct vx_info *vxi)
16411 +{
16412 +       struct hlist_head *head;
16413 +
16414 +       vxd_assert_lock(&vx_info_hash_lock);
16415 +       vxdprintk(VXD_CBIT(xid, 4),
16416 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
16417 +       vxh_hash_vx_info(vxi);
16418 +
16419 +       /* context must not be hashed */
16420 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
16421 +
16422 +       vxi->vx_state |= VXS_HASHED;
16423 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
16424 +       hlist_add_head(&vxi->vx_hlist, head);
16425 +       atomic_inc(&vx_global_cactive);
16426 +}
16427 +
16428 +/*     __unhash_vx_info()
16429 +
16430 +       * remove the vxi from the global hash table
16431 +       * requires the hash_lock to be held                     */
16432 +
16433 +static inline void __unhash_vx_info(struct vx_info *vxi)
16434 +{
16435 +       unsigned long flags;
16436 +
16437 +       vxd_assert_lock(&vx_info_hash_lock);
16438 +       vxdprintk(VXD_CBIT(xid, 4),
16439 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
16440 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
16441 +       vxh_unhash_vx_info(vxi);
16442 +
16443 +       /* context must be hashed */
16444 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
16445 +       /* but without tasks */
16446 +       BUG_ON(atomic_read(&vxi->vx_tasks));
16447 +
16448 +       vxi->vx_state &= ~VXS_HASHED;
16449 +       hlist_del_init(&vxi->vx_hlist);
16450 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
16451 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
16452 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
16453 +       atomic_dec(&vx_global_cactive);
16454 +}
16455 +
16456 +
16457 +/*     __lookup_vx_info()
16458 +
16459 +       * requires the hash_lock to be held
16460 +       * doesn't increment the vx_refcnt                       */
16461 +
16462 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
16463 +{
16464 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
16465 +       struct hlist_node *pos;
16466 +       struct vx_info *vxi;
16467 +
16468 +       vxd_assert_lock(&vx_info_hash_lock);
16469 +       hlist_for_each(pos, head) {
16470 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16471 +
16472 +               if (vxi->vx_id == xid)
16473 +                       goto found;
16474 +       }
16475 +       vxi = NULL;
16476 +found:
16477 +       vxdprintk(VXD_CBIT(xid, 0),
16478 +               "__lookup_vx_info(#%u): %p[#%u]",
16479 +               xid, vxi, vxi ? vxi->vx_id : 0);
16480 +       vxh_lookup_vx_info(vxi, xid);
16481 +       return vxi;
16482 +}
16483 +
16484 +
16485 +/*     __create_vx_info()
16486 +
16487 +       * create the requested context
16488 +       * get(), claim() and hash it                            */
16489 +
16490 +static struct vx_info *__create_vx_info(int id)
16491 +{
16492 +       struct vx_info *new, *vxi = NULL;
16493 +
16494 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
16495 +
16496 +       if (!(new = __alloc_vx_info(id)))
16497 +               return ERR_PTR(-ENOMEM);
16498 +
16499 +       /* required to make dynamic xids unique */
16500 +       spin_lock(&vx_info_hash_lock);
16501 +
16502 +       /* static context requested */
16503 +       if ((vxi = __lookup_vx_info(id))) {
16504 +               vxdprintk(VXD_CBIT(xid, 0),
16505 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
16506 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16507 +                       vxi = ERR_PTR(-EBUSY);
16508 +               else
16509 +                       vxi = ERR_PTR(-EEXIST);
16510 +               goto out_unlock;
16511 +       }
16512 +       /* new context */
16513 +       vxdprintk(VXD_CBIT(xid, 0),
16514 +               "create_vx_info(%d) = %p (new)", id, new);
16515 +       claim_vx_info(new, NULL);
16516 +       __hash_vx_info(get_vx_info(new));
16517 +       vxi = new, new = NULL;
16518 +
16519 +out_unlock:
16520 +       spin_unlock(&vx_info_hash_lock);
16521 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
16522 +       if (new)
16523 +               __dealloc_vx_info(new);
16524 +       return vxi;
16525 +}
16526 +
16527 +
16528 +/*     exported stuff                                          */
16529 +
16530 +
16531 +void unhash_vx_info(struct vx_info *vxi)
16532 +{
16533 +       __shutdown_vx_info(vxi);
16534 +       spin_lock(&vx_info_hash_lock);
16535 +       __unhash_vx_info(vxi);
16536 +       spin_unlock(&vx_info_hash_lock);
16537 +       __wakeup_vx_info(vxi);
16538 +}
16539 +
16540 +
16541 +/*     lookup_vx_info()
16542 +
16543 +       * search for a vx_info and get() it
16544 +       * negative id means current                             */
16545 +
16546 +struct vx_info *lookup_vx_info(int id)
16547 +{
16548 +       struct vx_info *vxi = NULL;
16549 +
16550 +       if (id < 0) {
16551 +               vxi = get_vx_info(current_vx_info());
16552 +       } else if (id > 1) {
16553 +               spin_lock(&vx_info_hash_lock);
16554 +               vxi = get_vx_info(__lookup_vx_info(id));
16555 +               spin_unlock(&vx_info_hash_lock);
16556 +       }
16557 +       return vxi;
16558 +}
16559 +
16560 +/*     xid_is_hashed()
16561 +
16562 +       * verify that xid is still hashed                       */
16563 +
16564 +int xid_is_hashed(xid_t xid)
16565 +{
16566 +       int hashed;
16567 +
16568 +       spin_lock(&vx_info_hash_lock);
16569 +       hashed = (__lookup_vx_info(xid) != NULL);
16570 +       spin_unlock(&vx_info_hash_lock);
16571 +       return hashed;
16572 +}
16573 +
16574 +#ifdef CONFIG_PROC_FS
16575 +
16576 +/*     get_xid_list()
16577 +
16578 +       * get a subset of hashed xids for proc
16579 +       * assumes size is at least one                          */
16580 +
16581 +int get_xid_list(int index, unsigned int *xids, int size)
16582 +{
16583 +       int hindex, nr_xids = 0;
16584 +
16585 +       /* only show current and children */
16586 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
16587 +               if (index > 0)
16588 +                       return 0;
16589 +               xids[nr_xids] = vx_current_xid();
16590 +               return 1;
16591 +       }
16592 +
16593 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
16594 +               struct hlist_head *head = &vx_info_hash[hindex];
16595 +               struct hlist_node *pos;
16596 +
16597 +               spin_lock(&vx_info_hash_lock);
16598 +               hlist_for_each(pos, head) {
16599 +                       struct vx_info *vxi;
16600 +
16601 +                       if (--index > 0)
16602 +                               continue;
16603 +
16604 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16605 +                       xids[nr_xids] = vxi->vx_id;
16606 +                       if (++nr_xids >= size) {
16607 +                               spin_unlock(&vx_info_hash_lock);
16608 +                               goto out;
16609 +                       }
16610 +               }
16611 +               /* keep the lock time short */
16612 +               spin_unlock(&vx_info_hash_lock);
16613 +       }
16614 +out:
16615 +       return nr_xids;
16616 +}
16617 +#endif
16618 +
16619 +#ifdef CONFIG_VSERVER_DEBUG
16620 +
16621 +void   dump_vx_info_inactive(int level)
16622 +{
16623 +       struct hlist_node *entry, *next;
16624 +
16625 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
16626 +               struct vx_info *vxi =
16627 +                       list_entry(entry, struct vx_info, vx_hlist);
16628 +
16629 +               dump_vx_info(vxi, level);
16630 +       }
16631 +}
16632 +
16633 +#endif
16634 +
16635 +#if 0
16636 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16637 +{
16638 +       struct user_struct *new_user, *old_user;
16639 +
16640 +       if (!p || !vxi)
16641 +               BUG();
16642 +
16643 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16644 +               return -EACCES;
16645 +
16646 +       new_user = alloc_uid(vxi->vx_id, p->uid);
16647 +       if (!new_user)
16648 +               return -ENOMEM;
16649 +
16650 +       old_user = p->user;
16651 +       if (new_user != old_user) {
16652 +               atomic_inc(&new_user->processes);
16653 +               atomic_dec(&old_user->processes);
16654 +               p->user = new_user;
16655 +       }
16656 +       free_uid(old_user);
16657 +       return 0;
16658 +}
16659 +#endif
16660 +
16661 +#if 0
16662 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16663 +{
16664 +       // p->cap_effective &= vxi->vx_cap_bset;
16665 +       p->cap_effective =
16666 +               cap_intersect(p->cap_effective, vxi->cap_bset);
16667 +       // p->cap_inheritable &= vxi->vx_cap_bset;
16668 +       p->cap_inheritable =
16669 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
16670 +       // p->cap_permitted &= vxi->vx_cap_bset;
16671 +       p->cap_permitted =
16672 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
16673 +}
16674 +#endif
16675 +
16676 +
16677 +#include <linux/file.h>
16678 +#include <linux/fdtable.h>
16679 +
16680 +static int vx_openfd_task(struct task_struct *tsk)
16681 +{
16682 +       struct files_struct *files = tsk->files;
16683 +       struct fdtable *fdt;
16684 +       const unsigned long *bptr;
16685 +       int count, total;
16686 +
16687 +       /* no rcu_read_lock() because of spin_lock() */
16688 +       spin_lock(&files->file_lock);
16689 +       fdt = files_fdtable(files);
16690 +       bptr = fdt->open_fds->fds_bits;
16691 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
16692 +       for (total = 0; count > 0; count--) {
16693 +               if (*bptr)
16694 +                       total += hweight_long(*bptr);
16695 +               bptr++;
16696 +       }
16697 +       spin_unlock(&files->file_lock);
16698 +       return total;
16699 +}
16700 +
16701 +
16702 +/*     for *space compatibility */
16703 +
16704 +asmlinkage long sys_unshare(unsigned long);
16705 +
16706 +/*
16707 + *     migrate task to new context
16708 + *     gets vxi, puts old_vxi on change
16709 + *     optionally unshares namespaces (hack)
16710 + */
16711 +
16712 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
16713 +{
16714 +       struct vx_info *old_vxi;
16715 +       int ret = 0;
16716 +
16717 +       if (!p || !vxi)
16718 +               BUG();
16719 +
16720 +       vxdprintk(VXD_CBIT(xid, 5),
16721 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
16722 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
16723 +
16724 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
16725 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16726 +               return -EACCES;
16727 +
16728 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
16729 +               return -EFAULT;
16730 +
16731 +       old_vxi = task_get_vx_info(p);
16732 +       if (old_vxi == vxi)
16733 +               goto out;
16734 +
16735 +//     if (!(ret = vx_migrate_user(p, vxi))) {
16736 +       {
16737 +               int openfd;
16738 +
16739 +               task_lock(p);
16740 +               openfd = vx_openfd_task(p);
16741 +
16742 +               if (old_vxi) {
16743 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
16744 +                       atomic_dec(&old_vxi->cvirt.nr_running);
16745 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
16746 +                       /* FIXME: what about the struct files here? */
16747 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
16748 +                       /* account for the executable */
16749 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
16750 +               }
16751 +               atomic_inc(&vxi->cvirt.nr_threads);
16752 +               atomic_inc(&vxi->cvirt.nr_running);
16753 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
16754 +               /* FIXME: what about the struct files here? */
16755 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
16756 +               /* account for the executable */
16757 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
16758 +
16759 +               if (old_vxi) {
16760 +                       release_vx_info(old_vxi, p);
16761 +                       clr_vx_info(&p->vx_info);
16762 +               }
16763 +               claim_vx_info(vxi, p);
16764 +               set_vx_info(&p->vx_info, vxi);
16765 +               p->xid = vxi->vx_id;
16766 +
16767 +               vxdprintk(VXD_CBIT(xid, 5),
16768 +                       "moved task %p into vxi:%p[#%d]",
16769 +                       p, vxi, vxi->vx_id);
16770 +
16771 +               // vx_mask_cap_bset(vxi, p);
16772 +               task_unlock(p);
16773 +
16774 +               /* hack for *spaces to provide compatibility */
16775 +               if (unshare) {
16776 +                       struct nsproxy *old_nsp, *new_nsp;
16777 +
16778 +                       ret = unshare_nsproxy_namespaces(
16779 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
16780 +                               &new_nsp, NULL);
16781 +                       if (ret)
16782 +                               goto out;
16783 +
16784 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
16785 +                       vx_set_space(vxi,
16786 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
16787 +                       put_nsproxy(old_nsp);
16788 +               }
16789 +       }
16790 +out:
16791 +       put_vx_info(old_vxi);
16792 +       return ret;
16793 +}
16794 +
16795 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
16796 +{
16797 +       struct task_struct *old_reaper;
16798 +
16799 +       if (!vxi)
16800 +               return -EINVAL;
16801 +
16802 +       vxdprintk(VXD_CBIT(xid, 6),
16803 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
16804 +               vxi, vxi->vx_id, p, p->xid, p->pid);
16805 +
16806 +       old_reaper = vxi->vx_reaper;
16807 +       if (old_reaper == p)
16808 +               return 0;
16809 +
16810 +       /* set new child reaper */
16811 +       get_task_struct(p);
16812 +       vxi->vx_reaper = p;
16813 +       put_task_struct(old_reaper);
16814 +       return 0;
16815 +}
16816 +
16817 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
16818 +{
16819 +       if (!vxi)
16820 +               return -EINVAL;
16821 +
16822 +       vxdprintk(VXD_CBIT(xid, 6),
16823 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
16824 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16825 +
16826 +       vxi->vx_flags &= ~VXF_STATE_INIT;
16827 +       // vxi->vx_initpid = p->tgid;
16828 +       vxi->vx_initpid = p->pid;
16829 +       return 0;
16830 +}
16831 +
16832 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
16833 +{
16834 +       vxdprintk(VXD_CBIT(xid, 6),
16835 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
16836 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16837 +
16838 +       vxi->exit_code = code;
16839 +       vxi->vx_initpid = 0;
16840 +}
16841 +
16842 +
16843 +void vx_set_persistent(struct vx_info *vxi)
16844 +{
16845 +       vxdprintk(VXD_CBIT(xid, 6),
16846 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
16847 +
16848 +       get_vx_info(vxi);
16849 +       claim_vx_info(vxi, NULL);
16850 +}
16851 +
16852 +void vx_clear_persistent(struct vx_info *vxi)
16853 +{
16854 +       vxdprintk(VXD_CBIT(xid, 6),
16855 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
16856 +
16857 +       release_vx_info(vxi, NULL);
16858 +       put_vx_info(vxi);
16859 +}
16860 +
16861 +void vx_update_persistent(struct vx_info *vxi)
16862 +{
16863 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
16864 +               vx_set_persistent(vxi);
16865 +       else
16866 +               vx_clear_persistent(vxi);
16867 +}
16868 +
16869 +
16870 +/*     task must be current or locked          */
16871 +
16872 +void   exit_vx_info(struct task_struct *p, int code)
16873 +{
16874 +       struct vx_info *vxi = p->vx_info;
16875 +
16876 +       if (vxi) {
16877 +               atomic_dec(&vxi->cvirt.nr_threads);
16878 +               vx_nproc_dec(p);
16879 +
16880 +               vxi->exit_code = code;
16881 +               release_vx_info(vxi, p);
16882 +       }
16883 +}
16884 +
16885 +void   exit_vx_info_early(struct task_struct *p, int code)
16886 +{
16887 +       struct vx_info *vxi = p->vx_info;
16888 +
16889 +       if (vxi) {
16890 +               if (vxi->vx_initpid == p->pid)
16891 +                       vx_exit_init(vxi, p, code);
16892 +               if (vxi->vx_reaper == p)
16893 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
16894 +       }
16895 +}
16896 +
16897 +
16898 +/* vserver syscall commands below here */
16899 +
16900 +/* taks xid and vx_info functions */
16901 +
16902 +#include <asm/uaccess.h>
16903 +
16904 +
16905 +int vc_task_xid(uint32_t id)
16906 +{
16907 +       xid_t xid;
16908 +
16909 +       if (id) {
16910 +               struct task_struct *tsk;
16911 +
16912 +               read_lock(&tasklist_lock);
16913 +               tsk = find_task_by_real_pid(id);
16914 +               xid = (tsk) ? tsk->xid : -ESRCH;
16915 +               read_unlock(&tasklist_lock);
16916 +       } else
16917 +               xid = vx_current_xid();
16918 +       return xid;
16919 +}
16920 +
16921 +
16922 +int vc_vx_info(struct vx_info *vxi, void __user *data)
16923 +{
16924 +       struct vcmd_vx_info_v0 vc_data;
16925 +
16926 +       vc_data.xid = vxi->vx_id;
16927 +       vc_data.initpid = vxi->vx_initpid;
16928 +
16929 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16930 +               return -EFAULT;
16931 +       return 0;
16932 +}
16933 +
16934 +
16935 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
16936 +{
16937 +       struct vcmd_ctx_stat_v0 vc_data;
16938 +
16939 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
16940 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
16941 +
16942 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16943 +               return -EFAULT;
16944 +       return 0;
16945 +}
16946 +
16947 +
16948 +/* context functions */
16949 +
16950 +int vc_ctx_create(uint32_t xid, void __user *data)
16951 +{
16952 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
16953 +       struct vx_info *new_vxi;
16954 +       int ret;
16955 +
16956 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16957 +               return -EFAULT;
16958 +
16959 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
16960 +               return -EINVAL;
16961 +
16962 +       new_vxi = __create_vx_info(xid);
16963 +       if (IS_ERR(new_vxi))
16964 +               return PTR_ERR(new_vxi);
16965 +
16966 +       /* initial flags */
16967 +       new_vxi->vx_flags = vc_data.flagword;
16968 +
16969 +       ret = -ENOEXEC;
16970 +       if (vs_state_change(new_vxi, VSC_STARTUP))
16971 +               goto out;
16972 +
16973 +       ret = vx_migrate_task(current, new_vxi, (!data));
16974 +       if (ret)
16975 +               goto out;
16976 +
16977 +       /* return context id on success */
16978 +       ret = new_vxi->vx_id;
16979 +
16980 +       /* get a reference for persistent contexts */
16981 +       if ((vc_data.flagword & VXF_PERSISTENT))
16982 +               vx_set_persistent(new_vxi);
16983 +out:
16984 +       release_vx_info(new_vxi, NULL);
16985 +       put_vx_info(new_vxi);
16986 +       return ret;
16987 +}
16988 +
16989 +
16990 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
16991 +{
16992 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
16993 +       int ret;
16994 +
16995 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16996 +               return -EFAULT;
16997 +
16998 +       ret = vx_migrate_task(current, vxi, 0);
16999 +       if (ret)
17000 +               return ret;
17001 +       if (vc_data.flagword & VXM_SET_INIT)
17002 +               ret = vx_set_init(vxi, current);
17003 +       if (ret)
17004 +               return ret;
17005 +       if (vc_data.flagword & VXM_SET_REAPER)
17006 +               ret = vx_set_reaper(vxi, current);
17007 +       return ret;
17008 +}
17009 +
17010 +
17011 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
17012 +{
17013 +       struct vcmd_ctx_flags_v0 vc_data;
17014 +
17015 +       vc_data.flagword = vxi->vx_flags;
17016 +
17017 +       /* special STATE flag handling */
17018 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
17019 +
17020 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17021 +               return -EFAULT;
17022 +       return 0;
17023 +}
17024 +
17025 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
17026 +{
17027 +       struct vcmd_ctx_flags_v0 vc_data;
17028 +       uint64_t mask, trigger;
17029 +
17030 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17031 +               return -EFAULT;
17032 +
17033 +       /* special STATE flag handling */
17034 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
17035 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
17036 +
17037 +       if (vxi == current_vx_info()) {
17038 +               /* if (trigger & VXF_STATE_SETUP)
17039 +                       vx_mask_cap_bset(vxi, current); */
17040 +               if (trigger & VXF_STATE_INIT) {
17041 +                       int ret;
17042 +
17043 +                       ret = vx_set_init(vxi, current);
17044 +                       if (ret)
17045 +                               return ret;
17046 +                       ret = vx_set_reaper(vxi, current);
17047 +                       if (ret)
17048 +                               return ret;
17049 +               }
17050 +       }
17051 +
17052 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
17053 +               vc_data.flagword, mask);
17054 +       if (trigger & VXF_PERSISTENT)
17055 +               vx_update_persistent(vxi);
17056 +
17057 +       return 0;
17058 +}
17059 +
17060 +
17061 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
17062 +{
17063 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
17064 +
17065 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
17066 +       return v;
17067 +}
17068 +
17069 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
17070 +{
17071 +       kernel_cap_t c = __cap_empty_set;
17072 +
17073 +       c.cap[0] = v & 0xFFFFFFFF;
17074 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
17075 +
17076 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
17077 +       return c;
17078 +}
17079 +
17080 +
17081 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
17082 +{
17083 +       if (bcaps)
17084 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
17085 +       if (ccaps)
17086 +               *ccaps = vxi->vx_ccaps;
17087 +
17088 +       return 0;
17089 +}
17090 +
17091 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
17092 +{
17093 +       struct vcmd_ctx_caps_v1 vc_data;
17094 +       int ret;
17095 +
17096 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
17097 +       if (ret)
17098 +               return ret;
17099 +       vc_data.cmask = ~0ULL;
17100 +
17101 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17102 +               return -EFAULT;
17103 +       return 0;
17104 +}
17105 +
17106 +static int do_set_caps(struct vx_info *vxi,
17107 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
17108 +{
17109 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
17110 +
17111 +#if 0
17112 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
17113 +               bcaps, bmask, ccaps, cmask);
17114 +#endif
17115 +       vxi->vx_bcaps = cap_t_from_caps(
17116 +               vs_mask_flags(bcold, bcaps, bmask));
17117 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
17118 +
17119 +       return 0;
17120 +}
17121 +
17122 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
17123 +{
17124 +       struct vcmd_ctx_caps_v1 vc_data;
17125 +
17126 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17127 +               return -EFAULT;
17128 +
17129 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
17130 +}
17131 +
17132 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
17133 +{
17134 +       struct vcmd_bcaps vc_data;
17135 +       int ret;
17136 +
17137 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
17138 +       if (ret)
17139 +               return ret;
17140 +       vc_data.bmask = ~0ULL;
17141 +
17142 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17143 +               return -EFAULT;
17144 +       return 0;
17145 +}
17146 +
17147 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
17148 +{
17149 +       struct vcmd_bcaps vc_data;
17150 +
17151 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17152 +               return -EFAULT;
17153 +
17154 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
17155 +}
17156 +
17157 +
17158 +int vc_get_umask(struct vx_info *vxi, void __user *data)
17159 +{
17160 +       struct vcmd_umask vc_data;
17161 +
17162 +       vc_data.umask = vxi->vx_umask;
17163 +       vc_data.mask = ~0ULL;
17164 +
17165 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17166 +               return -EFAULT;
17167 +       return 0;
17168 +}
17169 +
17170 +int vc_set_umask(struct vx_info *vxi, void __user *data)
17171 +{
17172 +       struct vcmd_umask vc_data;
17173 +
17174 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17175 +               return -EFAULT;
17176 +
17177 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
17178 +               vc_data.umask, vc_data.mask);
17179 +       return 0;
17180 +}
17181 +
17182 +
17183 +int vc_get_badness(struct vx_info *vxi, void __user *data)
17184 +{
17185 +       struct vcmd_badness_v0 vc_data;
17186 +
17187 +       vc_data.bias = vxi->vx_badness_bias;
17188 +
17189 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17190 +               return -EFAULT;
17191 +       return 0;
17192 +}
17193 +
17194 +int vc_set_badness(struct vx_info *vxi, void __user *data)
17195 +{
17196 +       struct vcmd_badness_v0 vc_data;
17197 +
17198 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17199 +               return -EFAULT;
17200 +
17201 +       vxi->vx_badness_bias = vc_data.bias;
17202 +       return 0;
17203 +}
17204 +
17205 +#include <linux/module.h>
17206 +
17207 +EXPORT_SYMBOL_GPL(free_vx_info);
17208 +
17209 diff -NurpP --minimal linux-2.6.36/kernel/vserver/cvirt.c linux-2.6.36-vs2.3.0.36.33/kernel/vserver/cvirt.c
17210 --- linux-2.6.36/kernel/vserver/cvirt.c 1970-01-01 01:00:00.000000000 +0100
17211 +++ linux-2.6.36-vs2.3.0.36.33/kernel/vserver/cvirt.c   2010-10-21 14:47:08.000000000 +0200
17212 @@ -0,0 +1,303 @@
17213 +/*
17214 + *  linux/kernel/vserver/cvirt.c
17215 + *
17216 + *  Virtual Server: Context Virtualization
17217 + *
17218 + *  Copyright (C) 2004-2007  Herbert Pötzl
17219 + *
17220 + *  V0.01  broken out from limit.c
17221 + *  V0.02  added utsname stuff
17222 + *  V0.03  changed vcmds to vxi arg
17223 + *
17224 + */
17225 +
17226 +#include <linux/types.h>
17227 +#include <linux/utsname.h>
17228 +#include <linux/vs_cvirt.h>
17229 +#include <linux/vserver/switch.h>
17230 +#include <linux/vserver/cvirt_cmd.h>
17231 +
17232 +#include <asm/uaccess.h>
17233 +
17234 +
17235 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
17236 +{
17237 +       struct vx_info *vxi = current_vx_info();
17238 +
17239 +       set_normalized_timespec(uptime,
17240 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
17241 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
17242 +       if (!idle)
17243 +               return;
17244 +       set_normalized_timespec(idle,
17245 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
17246 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
17247 +       return;
17248 +}
17249 +
17250 +uint64_t vx_idle_jiffies(void)
17251 +{
17252 +       return init_task.utime + init_task.stime;
17253 +}
17254 +
17255 +
17256 +
17257 +static inline uint32_t __update_loadavg(uint32_t load,
17258 +       int wsize, int delta, int n)
17259 +{
17260 +       unsigned long long calc, prev;
17261 +
17262 +       /* just set it to n */
17263 +       if (unlikely(delta >= wsize))
17264 +               return (n << FSHIFT);
17265 +
17266 +       calc = delta * n;
17267 +       calc <<= FSHIFT;
17268 +       prev = (wsize - delta);
17269 +       prev *= load;
17270 +       calc += prev;
17271 +       do_div(calc, wsize);
17272 +       return calc;
17273 +}
17274 +
17275 +
17276 +void vx_update_load(struct vx_info *vxi)
17277 +{
17278 +       uint32_t now, last, delta;
17279 +       unsigned int nr_running, nr_uninterruptible;
17280 +       unsigned int total;
17281 +       unsigned long flags;
17282 +
17283 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
17284 +
17285 +       now = jiffies;
17286 +       last = vxi->cvirt.load_last;
17287 +       delta = now - last;
17288 +
17289 +       if (delta < 5*HZ)
17290 +               goto out;
17291 +
17292 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
17293 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
17294 +       total = nr_running + nr_uninterruptible;
17295 +
17296 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
17297 +               60*HZ, delta, total);
17298 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
17299 +               5*60*HZ, delta, total);
17300 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
17301 +               15*60*HZ, delta, total);
17302 +
17303 +       vxi->cvirt.load_last = now;
17304 +out:
17305 +       atomic_inc(&vxi->cvirt.load_updates);
17306 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
17307 +}
17308 +
17309 +
17310 +/*
17311 + * Commands to do_syslog:
17312 + *
17313 + *      0 -- Close the log.  Currently a NOP.
17314 + *      1 -- Open the log. Currently a NOP.
17315 + *      2 -- Read from the log.
17316 + *      3 -- Read all messages remaining in the ring buffer.
17317 + *      4 -- Read and clear all messages remaining in the ring buffer
17318 + *      5 -- Clear ring buffer.
17319 + *      6 -- Disable printk's to console
17320 + *      7 -- Enable printk's to console
17321 + *      8 -- Set level of messages printed to console
17322 + *      9 -- Return number of unread characters in the log buffer
17323 + *     10 -- Return size of the log buffer
17324 + */
17325 +int vx_do_syslog(int type, char __user *buf, int len)
17326 +{
17327 +       int error = 0;
17328 +       int do_clear = 0;
17329 +       struct vx_info *vxi = current_vx_info();
17330 +       struct _vx_syslog *log;
17331 +
17332 +       if (!vxi)
17333 +               return -EINVAL;
17334 +       log = &vxi->cvirt.syslog;
17335 +
17336 +       switch (type) {
17337 +       case 0:         /* Close log */
17338 +       case 1:         /* Open log */
17339 +               break;
17340 +       case 2:         /* Read from log */
17341 +               error = wait_event_interruptible(log->log_wait,
17342 +                       (log->log_start - log->log_end));
17343 +               if (error)
17344 +                       break;
17345 +               spin_lock_irq(&log->logbuf_lock);
17346 +               spin_unlock_irq(&log->logbuf_lock);
17347 +               break;
17348 +       case 4:         /* Read/clear last kernel messages */
17349 +               do_clear = 1;
17350 +               /* fall through */
17351 +       case 3:         /* Read last kernel messages */
17352 +               return 0;
17353 +
17354 +       case 5:         /* Clear ring buffer */
17355 +               return 0;
17356 +
17357 +       case 6:         /* Disable logging to console */
17358 +       case 7:         /* Enable logging to console */
17359 +       case 8:         /* Set level of messages printed to console */
17360 +               break;
17361 +
17362 +       case 9:         /* Number of chars in the log buffer */
17363 +               return 0;
17364 +       case 10:        /* Size of the log buffer */
17365 +               return 0;
17366 +       default:
17367 +               error = -EINVAL;
17368 +               break;
17369 +       }
17370 +       return error;
17371 +}
17372 +
17373 +
17374 +/* virtual host info names */
17375 +
17376 +static char *vx_vhi_name(struct vx_info *vxi, int id)
17377 +{
17378 +       struct nsproxy *nsproxy;
17379 +       struct uts_namespace *uts;
17380 +
17381 +       if (id == VHIN_CONTEXT)
17382 +               return vxi->vx_name;
17383 +
17384 +       nsproxy = vxi->vx_nsproxy[0];
17385 +       if (!nsproxy)
17386 +               return NULL;
17387 +
17388 +       uts = nsproxy->uts_ns;
17389 +       if (!uts)
17390 +               return NULL;
17391 +
17392 +       switch (id) {
17393 +       case VHIN_SYSNAME:
17394 +               return uts->name.sysname;
17395 +       case VHIN_NODENAME:
17396 +               return uts->name.nodename;
17397 +       case VHIN_RELEASE:
17398 +               return uts->name.release;
17399 +       case VHIN_VERSION:
17400 +               return uts->name.version;
17401 +       case VHIN_MACHINE:
17402 +               return uts->name.machine;
17403 +       case VHIN_DOMAINNAME:
17404 +               return uts->name.domainname;
17405 +       default:
17406 +               return NULL;
17407 +       }
17408 +       return NULL;
17409 +}
17410 +
17411 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
17412 +{
17413 +       struct vcmd_vhi_name_v0 vc_data;
17414 +       char *name;
17415 +
17416 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17417 +               return -EFAULT;
17418 +
17419 +       name = vx_vhi_name(vxi, vc_data.field);
17420 +       if (!name)
17421 +               return -EINVAL;
17422 +
17423 +       memcpy(name, vc_data.name, 65);
17424 +       return 0;
17425 +}
17426 +
17427 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
17428 +{
17429 +       struct vcmd_vhi_name_v0 vc_data;
17430 +       char *name;
17431 +
17432 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17433 +               return -EFAULT;
17434 +
17435 +       name = vx_vhi_name(vxi, vc_data.field);
17436 +       if (!name)
17437 +               return -EINVAL;
17438 +
17439 +       memcpy(vc_data.name, name, 65);
17440 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17441 +               return -EFAULT;
17442 +       return 0;
17443 +}
17444 +
17445 +
17446 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
17447 +{
17448 +       struct vcmd_virt_stat_v0 vc_data;
17449 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
17450 +       struct timespec uptime;
17451 +
17452 +       do_posix_clock_monotonic_gettime(&uptime);
17453 +       set_normalized_timespec(&uptime,
17454 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
17455 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
17456 +
17457 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
17458 +       vc_data.uptime = timespec_to_ns(&uptime);
17459 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
17460 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
17461 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
17462 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
17463 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
17464 +       vc_data.load[0] = cvirt->load[0];
17465 +       vc_data.load[1] = cvirt->load[1];
17466 +       vc_data.load[2] = cvirt->load[2];
17467 +
17468 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17469 +               return -EFAULT;
17470 +       return 0;
17471 +}
17472 +
17473 +
17474 +#ifdef CONFIG_VSERVER_VTIME
17475 +
17476 +/* virtualized time base */
17477 +
17478 +void vx_adjust_timespec(struct timespec *ts)
17479 +{
17480 +       struct vx_info *vxi;
17481 +
17482 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17483 +               return;
17484 +
17485 +       vxi = current_vx_info();
17486 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
17487 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
17488 +
17489 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
17490 +               ts->tv_sec++;
17491 +               ts->tv_nsec -= NSEC_PER_SEC;
17492 +       } else if (ts->tv_nsec < 0) {
17493 +               ts->tv_sec--;
17494 +               ts->tv_nsec += NSEC_PER_SEC;
17495 +       }
17496 +}
17497 +
17498 +int vx_settimeofday(struct timespec *ts)
17499 +{
17500 +       struct timespec ats, delta;
17501 +       struct vx_info *vxi;
17502 +
17503 +       if (!vx_flags(VXF_VIRT_TIME, 0))
17504 +               return do_settimeofday(ts);
17505 +
17506 +       getnstimeofday(&ats);
17507 +       delta = timespec_sub(ts, &ats);
17508 +
17509 +       vxi = current_vx_info();
17510 +       vxi->cvirt.bias_ts = timespec_add(&vxi->cvirt.bias_ts, &delta);
17511 +       return 0;
17512 +}
17513 +
17514 +#endif
17515 +
17516 diff -NurpP --minimal linux-2.6.36/kernel/vserver/cvirt_init.h linux-2.6.36-vs2.3.0.36.33/kernel/vserver/cvirt_init.h
17517 --- linux-2.6.36/kernel/vserver/cvirt_init.h    1970-01-01 01:00:00.000000000 +0100
17518 +++ linux-2.6.36-vs2.3.0.36.33/kernel/vserver/cvirt_init.h      2010-10-21 14:40:17.000000000 +0200
17519 @@ -0,0 +1,69 @@
17520 +
17521 +
17522 +extern uint64_t vx_idle_jiffies(void);
17523 +
17524 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
17525 +{
17526 +       uint64_t idle_jiffies = vx_idle_jiffies();
17527 +       uint64_t nsuptime;
17528 +
17529 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
17530 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
17531 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
17532 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
17533 +       cvirt->bias_ts.tv_sec = 0;
17534 +       cvirt->bias_ts.tv_nsec = 0;
17535 +
17536 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
17537 +       atomic_set(&cvirt->nr_threads, 0);
17538 +       atomic_set(&cvirt->nr_running, 0);
17539 +       atomic_set(&cvirt->nr_uninterruptible, 0);
17540 +       atomic_set(&cvirt->nr_onhold, 0);
17541 +
17542 +       spin_lock_init(&cvirt->load_lock);
17543 +       cvirt->load_last = jiffies;
17544 +       atomic_set(&cvirt->load_updates, 0);
17545 +       cvirt->load[0] = 0;
17546 +       cvirt->load[1] = 0;
17547 +       cvirt->load[2] = 0;
17548 +       atomic_set(&cvirt->total_forks, 0);
17549 +
17550 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
17551 +       init_waitqueue_head(&cvirt->syslog.log_wait);
17552 +       cvirt->syslog.log_start = 0;
17553 +       cvirt->syslog.log_end = 0;
17554 +       cvirt->syslog.con_start = 0;
17555 +       cvirt->syslog.logged_chars = 0;
17556 +}
17557 +
17558 +static inline
17559 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17560 +{
17561 +       // cvirt_pc->cpustat = { 0 };
17562 +}
17563 +
17564 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
17565 +{
17566 +       int value;
17567 +
17568 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
17569 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
17570 +               cvirt, value);
17571 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
17572 +               "!!! cvirt: %p[nr_running] = %d on exit.",
17573 +               cvirt, value);
17574 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
17575 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
17576 +               cvirt, value);
17577 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
17578 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
17579 +               cvirt, value);
17580 +       return;
17581 +}
17582 +
17583 +static inline
17584 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17585 +{
17586 +       return;
17587 +}
17588 +
17589 diff -NurpP --minimal linux-2.6.36/kernel/vserver/cvirt_proc.h linux-2.6.36-vs2.3.0.36.33/kernel/vserver/cvirt_proc.h
17590 --- linux-2.6.36/kernel/vserver/cvirt_proc.h    1970-01-01 01:00:00.000000000 +0100
17591 +++ linux-2.6.36-vs2.3.0.36.33/kernel/vserver/cvirt_proc.h      2010-10-21 13:09:36.000000000 +0200
17592 @@ -0,0 +1,135 @@
17593 +#ifndef _VX_CVIRT_PROC_H
17594 +#define _VX_CVIRT_PROC_H
17595 +
17596 +#include <linux/nsproxy.h>
17597 +#include <linux/mnt_namespace.h>
17598 +#include <linux/ipc_namespace.h>
17599 +#include <linux/utsname.h>
17600 +#include <linux/ipc.h>
17601 +
17602 +
17603 +static inline
17604 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17605 +{
17606 +       struct mnt_namespace *ns;
17607 +       struct uts_namespace *uts;
17608 +       struct ipc_namespace *ipc;
17609 +       struct path path;
17610 +       char *pstr, *root;
17611 +       int length = 0;
17612 +
17613 +       if (!nsproxy)
17614 +               goto out;
17615 +
17616 +       length += sprintf(buffer + length,
17617 +               "NSProxy:\t%p [%p,%p,%p]\n",
17618 +               nsproxy, nsproxy->mnt_ns,
17619 +               nsproxy->uts_ns, nsproxy->ipc_ns);
17620 +
17621 +       ns = nsproxy->mnt_ns;
17622 +       if (!ns)
17623 +               goto skip_ns;
17624 +
17625 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
17626 +       if (!pstr)
17627 +               goto skip_ns;
17628 +
17629 +       path.mnt = ns->root;
17630 +       path.dentry = ns->root->mnt_root;
17631 +       root = d_path(&path, pstr, PATH_MAX - 2);
17632 +       length += sprintf(buffer + length,
17633 +               "Namespace:\t%p [#%u]\n"
17634 +               "RootPath:\t%s\n",
17635 +               ns, atomic_read(&ns->count),
17636 +               root);
17637 +       kfree(pstr);
17638 +skip_ns:
17639 +
17640 +       uts = nsproxy->uts_ns;
17641 +       if (!uts)
17642 +               goto skip_uts;
17643 +
17644 +       length += sprintf(buffer + length,
17645 +               "SysName:\t%.*s\n"
17646 +               "NodeName:\t%.*s\n"
17647 +               "Release:\t%.*s\n"
17648 +               "Version:\t%.*s\n"
17649 +               "Machine:\t%.*s\n"
17650 +               "DomainName:\t%.*s\n",
17651 +               __NEW_UTS_LEN, uts->name.sysname,
17652 +               __NEW_UTS_LEN, uts->name.nodename,
17653 +               __NEW_UTS_LEN, uts->name.release,
17654 +               __NEW_UTS_LEN, uts->name.version,
17655 +               __NEW_UTS_LEN, uts->name.machine,
17656 +               __NEW_UTS_LEN, uts->name.domainname);
17657 +skip_uts:
17658 +
17659 +       ipc = nsproxy->ipc_ns;
17660 +       if (!ipc)
17661 +               goto skip_ipc;
17662 +
17663 +       length += sprintf(buffer + length,
17664 +               "SEMS:\t\t%d %d %d %d  %d\n"
17665 +               "MSG:\t\t%d %d %d\n"
17666 +               "SHM:\t\t%lu %lu  %d %d\n",
17667 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
17668 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
17669 +               ipc->used_sems,
17670 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17671 +               (unsigned long)ipc->shm_ctlmax,
17672 +               (unsigned long)ipc->shm_ctlall,
17673 +               ipc->shm_ctlmni, ipc->shm_tot);
17674 +skip_ipc:
17675 +out:
17676 +       return length;
17677 +}
17678 +
17679 +
17680 +#include <linux/sched.h>
17681 +
17682 +#define LOAD_INT(x) ((x) >> FSHIFT)
17683 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
17684 +
17685 +static inline
17686 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
17687 +{
17688 +       int length = 0;
17689 +       int a, b, c;
17690 +
17691 +       length += sprintf(buffer + length,
17692 +               "BiasUptime:\t%lu.%02lu\n",
17693 +               (unsigned long)cvirt->bias_uptime.tv_sec,
17694 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
17695 +
17696 +       a = cvirt->load[0] + (FIXED_1 / 200);
17697 +       b = cvirt->load[1] + (FIXED_1 / 200);
17698 +       c = cvirt->load[2] + (FIXED_1 / 200);
17699 +       length += sprintf(buffer + length,
17700 +               "nr_threads:\t%d\n"
17701 +               "nr_running:\t%d\n"
17702 +               "nr_unintr:\t%d\n"
17703 +               "nr_onhold:\t%d\n"
17704 +               "load_updates:\t%d\n"
17705 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
17706 +               "total_forks:\t%d\n",
17707 +               atomic_read(&cvirt->nr_threads),
17708 +               atomic_read(&cvirt->nr_running),
17709 +               atomic_read(&cvirt->nr_uninterruptible),
17710 +               atomic_read(&cvirt->nr_onhold),
17711 +               atomic_read(&cvirt->load_updates),
17712 +               LOAD_INT(a), LOAD_FRAC(a),
17713 +               LOAD_INT(b), LOAD_FRAC(b),
17714 +               LOAD_INT(c), LOAD_FRAC(c),
17715 +               atomic_read(&cvirt->total_forks));
17716 +       return length;
17717 +}
17718 +
17719 +static inline
17720 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
17721 +       char *buffer, int cpu)
17722 +{
17723 +       int length = 0;
17724 +       return length;
17725 +}
17726 +
17727 +#endif /* _VX_CVIRT_PROC_H */
17728 diff -NurpP --minimal linux-2.6.36/kernel/vserver/debug.c linux-2.6.36-vs2.3.0.36.33/kernel/vserver/debug.c
17729 --- linux-2.6.36/kernel/vserver/debug.c 1970-01-01 01:00:00.000000000 +0100
17730 +++ linux-2.6.36-vs2.3.0.36.33/kernel/vserver/debug.c   2010-10-21 13:09:36.000000000 +0200
17731 @@ -0,0 +1,32 @@
17732 +/*
17733 + *  kernel/vserver/debug.c
17734 + *
17735 + *  Copyright (C) 2005-2007 Herbert Pötzl
17736 + *
17737 + *  V0.01  vx_info dump support
17738 + *
17739 + */
17740 +
17741 +#include <linux/module.h>
17742 +
17743 +#include <linux/vserver/context.h>
17744 +
17745 +
17746 +void   dump_vx_info(struct vx_info *vxi, int level)
17747 +{
17748 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
17749 +               atomic_read(&vxi->vx_usecnt),
17750 +               atomic_read(&vxi->vx_tasks),
17751 +               vxi->vx_state);
17752 +       if (level > 0) {
17753 +               __dump_vx_limit(&vxi->limit);
17754 +               __dump_vx_sched(&vxi->sched);
17755 +               __dump_vx_cvirt(&vxi->cvirt);
17756 +               __dump_vx_cacct(&vxi->cacct);
17757 +       }
17758 +       printk("---\n");
17759 +}
17760 +
17761 +
17762 +EXPORT_SYMBOL_GPL(dump_vx_info);
17763 +
17764 diff -NurpP --minimal linux-2.6.36/kernel/vserver/device.c linux-2.6.36-vs2.3.0.36.33/kernel/vserver/device.c
17765 --- linux-2.6.36/kernel/vserver/device.c        1970-01-01 01:00:00.000000000 +0100
17766 +++ linux-2.6.36-vs2.3.0.36.33/kernel/vserver/device.c  2010-10-21 13:09:36.000000000 +0200
17767 @@ -0,0 +1,443 @@
17768 +/*
17769 + *  linux/kernel/vserver/device.c
17770 + *
17771 + *  Linux-VServer: Device Support
17772 + *
17773 + *  Copyright (C) 2006  Herbert Pötzl
17774 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
17775 + *
17776 + *  V0.01  device mapping basics
17777 + *  V0.02  added defaults
17778 + *
17779 + */
17780 +
17781 +#include <linux/slab.h>
17782 +#include <linux/rcupdate.h>
17783 +#include <linux/fs.h>
17784 +#include <linux/namei.h>
17785 +#include <linux/hash.h>
17786 +
17787 +#include <asm/errno.h>
17788 +#include <asm/uaccess.h>
17789 +#include <linux/vserver/base.h>
17790 +#include <linux/vserver/debug.h>
17791 +#include <linux/vserver/context.h>
17792 +#include <linux/vserver/device.h>
17793 +#include <linux/vserver/device_cmd.h>
17794 +
17795 +
17796 +#define DMAP_HASH_BITS 4
17797 +
17798 +
17799 +struct vs_mapping {
17800 +       union {
17801 +               struct hlist_node hlist;
17802 +               struct list_head list;
17803 +       } u;
17804 +#define dm_hlist       u.hlist
17805 +#define dm_list                u.list
17806 +       xid_t xid;
17807 +       dev_t device;
17808 +       struct vx_dmap_target target;
17809 +};
17810 +
17811 +
17812 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
17813 +
17814 +static spinlock_t dmap_main_hash_lock = SPIN_LOCK_UNLOCKED;
17815 +
17816 +static struct vx_dmap_target dmap_defaults[2] = {
17817 +       { .flags = DATTR_OPEN },
17818 +       { .flags = DATTR_OPEN },
17819 +};
17820 +
17821 +
17822 +struct kmem_cache *dmap_cachep __read_mostly;
17823 +
17824 +int __init dmap_cache_init(void)
17825 +{
17826 +       dmap_cachep = kmem_cache_create("dmap_cache",
17827 +               sizeof(struct vs_mapping), 0,
17828 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
17829 +       return 0;
17830 +}
17831 +
17832 +__initcall(dmap_cache_init);
17833 +
17834 +
17835 +static inline unsigned int __hashval(dev_t dev, int bits)
17836 +{
17837 +       return hash_long((unsigned long)dev, bits);
17838 +}
17839 +
17840 +
17841 +/*     __hash_mapping()
17842 + *     add the mapping to the hash table
17843 + */
17844 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
17845 +{
17846 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17847 +       struct hlist_head *head, *hash = dmap_main_hash;
17848 +       int device = vdm->device;
17849 +
17850 +       spin_lock(hash_lock);
17851 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
17852 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
17853 +
17854 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
17855 +       hlist_add_head(&vdm->dm_hlist, head);
17856 +       spin_unlock(hash_lock);
17857 +}
17858 +
17859 +
17860 +static inline int __mode_to_default(umode_t mode)
17861 +{
17862 +       switch (mode) {
17863 +       case S_IFBLK:
17864 +               return 0;
17865 +       case S_IFCHR:
17866 +               return 1;
17867 +       default:
17868 +               BUG();
17869 +       }
17870 +}
17871 +
17872 +
17873 +/*     __set_default()
17874 + *     set a default
17875 + */
17876 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
17877 +       struct vx_dmap_target *vdmt)
17878 +{
17879 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17880 +       spin_lock(hash_lock);
17881 +
17882 +       if (vxi)
17883 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
17884 +       else
17885 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
17886 +
17887 +
17888 +       spin_unlock(hash_lock);
17889 +
17890 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
17891 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
17892 +}
17893 +
17894 +
17895 +/*     __remove_default()
17896 + *     remove a default
17897 + */
17898 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
17899 +{
17900 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17901 +       spin_lock(hash_lock);
17902 +
17903 +       if (vxi)
17904 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
17905 +       else    /* remove == reset */
17906 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
17907 +
17908 +       spin_unlock(hash_lock);
17909 +       return 0;
17910 +}
17911 +
17912 +
17913 +/*     __find_mapping()
17914 + *     find a mapping in the hash table
17915 + *
17916 + *     caller must hold hash_lock
17917 + */
17918 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
17919 +       struct vs_mapping **local, struct vs_mapping **global)
17920 +{
17921 +       struct hlist_head *hash = dmap_main_hash;
17922 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
17923 +       struct hlist_node *pos;
17924 +       struct vs_mapping *vdm;
17925 +
17926 +       *local = NULL;
17927 +       if (global)
17928 +               *global = NULL;
17929 +
17930 +       hlist_for_each(pos, head) {
17931 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
17932 +
17933 +               if ((vdm->device == device) &&
17934 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
17935 +                       if (vdm->xid == xid) {
17936 +                               *local = vdm;
17937 +                               return 1;
17938 +                       } else if (global && vdm->xid == 0)
17939 +                               *global = vdm;
17940 +               }
17941 +       }
17942 +
17943 +       if (global && *global)
17944 +               return 0;
17945 +       else
17946 +               return -ENOENT;
17947 +}
17948 +
17949 +
17950 +/*     __lookup_mapping()
17951 + *     find a mapping and store the result in target and flags
17952 + */
17953 +static inline int __lookup_mapping(struct vx_info *vxi,
17954 +       dev_t device, dev_t *target, int *flags, umode_t mode)
17955 +{
17956 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17957 +       struct vs_mapping *vdm, *global;
17958 +       struct vx_dmap_target *vdmt;
17959 +       int ret = 0;
17960 +       xid_t xid = vxi->vx_id;
17961 +       int index;
17962 +
17963 +       spin_lock(hash_lock);
17964 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
17965 +               ret = 1;
17966 +               vdmt = &vdm->target;
17967 +               goto found;
17968 +       }
17969 +
17970 +       index = __mode_to_default(mode);
17971 +       if (vxi && vxi->dmap.targets[index].flags) {
17972 +               ret = 2;
17973 +               vdmt = &vxi->dmap.targets[index];
17974 +       } else if (global) {
17975 +               ret = 3;
17976 +               vdmt = &global->target;
17977 +               goto found;
17978 +       } else {
17979 +               ret = 4;
17980 +               vdmt = &dmap_defaults[index];
17981 +       }
17982 +
17983 +found:
17984 +       if (target && (vdmt->flags & DATTR_REMAP))
17985 +               *target = vdmt->target;
17986 +       else if (target)
17987 +               *target = device;
17988 +       if (flags)
17989 +               *flags = vdmt->flags;
17990 +
17991 +       spin_unlock(hash_lock);
17992 +
17993 +       return ret;
17994 +}
17995 +
17996 +
17997 +/*     __remove_mapping()
17998 + *     remove a mapping from the hash table
17999 + */
18000 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
18001 +       umode_t mode)
18002 +{
18003 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18004 +       struct vs_mapping *vdm = NULL;
18005 +       int ret = 0;
18006 +
18007 +       spin_lock(hash_lock);
18008 +
18009 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
18010 +               NULL);
18011 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
18012 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
18013 +       if (ret < 0)
18014 +               goto out;
18015 +       hlist_del(&vdm->dm_hlist);
18016 +
18017 +out:
18018 +       spin_unlock(hash_lock);
18019 +       if (vdm)
18020 +               kmem_cache_free(dmap_cachep, vdm);
18021 +       return ret;
18022 +}
18023 +
18024 +
18025 +
18026 +int vs_map_device(struct vx_info *vxi,
18027 +       dev_t device, dev_t *target, umode_t mode)
18028 +{
18029 +       int ret, flags = DATTR_MASK;
18030 +
18031 +       if (!vxi) {
18032 +               if (target)
18033 +                       *target = device;
18034 +               goto out;
18035 +       }
18036 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
18037 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
18038 +               device, target ? *target : 0, flags, mode, ret);
18039 +out:
18040 +       return (flags & DATTR_MASK);
18041 +}
18042 +
18043 +
18044 +
18045 +static int do_set_mapping(struct vx_info *vxi,
18046 +       dev_t device, dev_t target, int flags, umode_t mode)
18047 +{
18048 +       if (device) {
18049 +               struct vs_mapping *new;
18050 +
18051 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
18052 +               if (!new)
18053 +                       return -ENOMEM;
18054 +
18055 +               INIT_HLIST_NODE(&new->dm_hlist);
18056 +               new->device = device;
18057 +               new->target.target = target;
18058 +               new->target.flags = flags | mode;
18059 +               new->xid = (vxi ? vxi->vx_id : 0);
18060 +
18061 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
18062 +               __hash_mapping(vxi, new);
18063 +       } else {
18064 +               struct vx_dmap_target new = {
18065 +                       .target = target,
18066 +                       .flags = flags | mode,
18067 +               };
18068 +               __set_default(vxi, mode, &new);
18069 +       }
18070 +       return 0;
18071 +}
18072 +
18073 +
18074 +static int do_unset_mapping(struct vx_info *vxi,
18075 +       dev_t device, dev_t target, int flags, umode_t mode)
18076 +{
18077 +       int ret = -EINVAL;
18078 +
18079 +       if (device) {
18080 +               ret = __remove_mapping(vxi, device, mode);
18081 +               if (ret < 0)
18082 +                       goto out;
18083 +       } else {
18084 +               ret = __remove_default(vxi, mode);
18085 +               if (ret < 0)
18086 +                       goto out;
18087 +       }
18088 +
18089 +out:
18090 +       return ret;
18091 +}
18092 +
18093 +
18094 +static inline int __user_device(const char __user *name, dev_t *dev,
18095 +       umode_t *mode)
18096 +{
18097 +       struct nameidata nd;
18098 +       int ret;
18099 +
18100 +       if (!name) {
18101 +               *dev = 0;
18102 +               return 0;
18103 +       }
18104 +       ret = user_lpath(name, &nd.path);
18105 +       if (ret)
18106 +               return ret;
18107 +       if (nd.path.dentry->d_inode) {
18108 +               *dev = nd.path.dentry->d_inode->i_rdev;
18109 +               *mode = nd.path.dentry->d_inode->i_mode;
18110 +       }
18111 +       path_put(&nd.path);
18112 +       return 0;
18113 +}
18114 +
18115 +static inline int __mapping_mode(dev_t device, dev_t target,
18116 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
18117 +{
18118 +       if (device)
18119 +               *mode = device_mode & S_IFMT;
18120 +       else if (target)
18121 +               *mode = target_mode & S_IFMT;
18122 +       else
18123 +               return -EINVAL;
18124 +
18125 +       /* if both given, device and target mode have to match */
18126 +       if (device && target &&
18127 +               ((device_mode ^ target_mode) & S_IFMT))
18128 +               return -EINVAL;
18129 +       return 0;
18130 +}
18131 +
18132 +
18133 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
18134 +       const char __user *target_path, int flags, int set)
18135 +{
18136 +       dev_t device = ~0, target = ~0;
18137 +       umode_t device_mode = 0, target_mode = 0, mode;
18138 +       int ret;
18139 +
18140 +       ret = __user_device(device_path, &device, &device_mode);
18141 +       if (ret)
18142 +               return ret;
18143 +       ret = __user_device(target_path, &target, &target_mode);
18144 +       if (ret)
18145 +               return ret;
18146 +
18147 +       ret = __mapping_mode(device, target,
18148 +               device_mode, target_mode, &mode);
18149 +       if (ret)
18150 +               return ret;
18151 +
18152 +       if (set)
18153 +               return do_set_mapping(vxi, device, target,
18154 +                       flags, mode);
18155 +       else
18156 +               return do_unset_mapping(vxi, device, target,
18157 +                       flags, mode);
18158 +}
18159 +
18160 +
18161 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
18162 +{
18163 +       struct vcmd_set_mapping_v0 vc_data;
18164 +
18165 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18166 +               return -EFAULT;
18167 +
18168 +       return do_mapping(vxi, vc_data.device, vc_data.target,
18169 +               vc_data.flags, 1);
18170 +}
18171 +
18172 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
18173 +{
18174 +       struct vcmd_set_mapping_v0 vc_data;
18175 +
18176 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18177 +               return -EFAULT;
18178 +
18179 +       return do_mapping(vxi, vc_data.device, vc_data.target,
18180 +               vc_data.flags, 0);
18181 +}
18182 +
18183 +
18184 +#ifdef CONFIG_COMPAT
18185 +
18186 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
18187 +{
18188 +       struct vcmd_set_mapping_v0_x32 vc_data;
18189 +
18190 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18191 +               return -EFAULT;
18192 +
18193 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
18194 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
18195 +}
18196 +
18197 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
18198 +{
18199 +       struct vcmd_set_mapping_v0_x32 vc_data;
18200 +
18201 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18202 +               return -EFAULT;
18203 +
18204 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
18205 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
18206 +}
18207 +
18208 +#endif /* CONFIG_COMPAT */
18209 +
18210 +
18211 diff -NurpP --minimal linux-2.6.36/kernel/vserver/dlimit.c linux-2.6.36-vs2.3.0.36.33/kernel/vserver/dlimit.c
18212 --- linux-2.6.36/kernel/vserver/dlimit.c        1970-01-01 01:00:00.000000000 +0100
18213 +++ linux-2.6.36-vs2.3.0.36.33/kernel/vserver/dlimit.c  2010-10-21 13:09:36.000000000 +0200
18214 @@ -0,0 +1,531 @@
18215 +/*
18216 + *  linux/kernel/vserver/dlimit.c
18217 + *
18218 + *  Virtual Server: Context Disk Limits
18219 + *
18220 + *  Copyright (C) 2004-2009  Herbert Pötzl
18221 + *
18222 + *  V0.01  initial version
18223 + *  V0.02  compat32 splitup
18224 + *  V0.03  extended interface
18225 + *
18226 + */
18227 +
18228 +#include <linux/statfs.h>
18229 +#include <linux/sched.h>
18230 +#include <linux/namei.h>
18231 +#include <linux/vs_tag.h>
18232 +#include <linux/vs_dlimit.h>
18233 +#include <linux/vserver/dlimit_cmd.h>
18234 +#include <linux/slab.h>
18235 +// #include <linux/gfp.h>
18236 +
18237 +#include <asm/uaccess.h>
18238 +
18239 +/*     __alloc_dl_info()
18240 +
18241 +       * allocate an initialized dl_info struct
18242 +       * doesn't make it visible (hash)                        */
18243 +
18244 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
18245 +{
18246 +       struct dl_info *new = NULL;
18247 +
18248 +       vxdprintk(VXD_CBIT(dlim, 5),
18249 +               "alloc_dl_info(%p,%d)*", sb, tag);
18250 +
18251 +       /* would this benefit from a slab cache? */
18252 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
18253 +       if (!new)
18254 +               return 0;
18255 +
18256 +       memset(new, 0, sizeof(struct dl_info));
18257 +       new->dl_tag = tag;
18258 +       new->dl_sb = sb;
18259 +       INIT_RCU_HEAD(&new->dl_rcu);
18260 +       INIT_HLIST_NODE(&new->dl_hlist);
18261 +       spin_lock_init(&new->dl_lock);
18262 +       atomic_set(&new->dl_refcnt, 0);
18263 +       atomic_set(&new->dl_usecnt, 0);
18264 +
18265 +       /* rest of init goes here */
18266 +
18267 +       vxdprintk(VXD_CBIT(dlim, 4),
18268 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
18269 +       return new;
18270 +}
18271 +
18272 +/*     __dealloc_dl_info()
18273 +
18274 +       * final disposal of dl_info                             */
18275 +
18276 +static void __dealloc_dl_info(struct dl_info *dli)
18277 +{
18278 +       vxdprintk(VXD_CBIT(dlim, 4),
18279 +               "dealloc_dl_info(%p)", dli);
18280 +
18281 +       dli->dl_hlist.next = LIST_POISON1;
18282 +       dli->dl_tag = -1;
18283 +       dli->dl_sb = 0;
18284 +
18285 +       BUG_ON(atomic_read(&dli->dl_usecnt));
18286 +       BUG_ON(atomic_read(&dli->dl_refcnt));
18287 +
18288 +       kfree(dli);
18289 +}
18290 +
18291 +
18292 +/*     hash table for dl_info hash */
18293 +
18294 +#define DL_HASH_SIZE   13
18295 +
18296 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
18297 +
18298 +static spinlock_t dl_info_hash_lock = SPIN_LOCK_UNLOCKED;
18299 +
18300 +
18301 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
18302 +{
18303 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
18304 +}
18305 +
18306 +
18307 +
18308 +/*     __hash_dl_info()
18309 +
18310 +       * add the dli to the global hash table
18311 +       * requires the hash_lock to be held                     */
18312 +
18313 +static inline void __hash_dl_info(struct dl_info *dli)
18314 +{
18315 +       struct hlist_head *head;
18316 +
18317 +       vxdprintk(VXD_CBIT(dlim, 6),
18318 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
18319 +       get_dl_info(dli);
18320 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
18321 +       hlist_add_head_rcu(&dli->dl_hlist, head);
18322 +}
18323 +
18324 +/*     __unhash_dl_info()
18325 +
18326 +       * remove the dli from the global hash table
18327 +       * requires the hash_lock to be held                     */
18328 +
18329 +static inline void __unhash_dl_info(struct dl_info *dli)
18330 +{
18331 +       vxdprintk(VXD_CBIT(dlim, 6),
18332 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
18333 +       hlist_del_rcu(&dli->dl_hlist);
18334 +       put_dl_info(dli);
18335 +}
18336 +
18337 +
18338 +/*     __lookup_dl_info()
18339 +
18340 +       * requires the rcu_read_lock()
18341 +       * doesn't increment the dl_refcnt                       */
18342 +
18343 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
18344 +{
18345 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
18346 +       struct hlist_node *pos;
18347 +       struct dl_info *dli;
18348 +
18349 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
18350 +
18351 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
18352 +                       return dli;
18353 +               }
18354 +       }
18355 +       return NULL;
18356 +}
18357 +
18358 +
18359 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
18360 +{
18361 +       struct dl_info *dli;
18362 +
18363 +       rcu_read_lock();
18364 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
18365 +       vxdprintk(VXD_CBIT(dlim, 7),
18366 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
18367 +       rcu_read_unlock();
18368 +       return dli;
18369 +}
18370 +
18371 +void rcu_free_dl_info(struct rcu_head *head)
18372 +{
18373 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
18374 +       int usecnt, refcnt;
18375 +
18376 +       BUG_ON(!dli || !head);
18377 +
18378 +       usecnt = atomic_read(&dli->dl_usecnt);
18379 +       BUG_ON(usecnt < 0);
18380 +
18381 +       refcnt = atomic_read(&dli->dl_refcnt);
18382 +       BUG_ON(refcnt < 0);
18383 +
18384 +       vxdprintk(VXD_CBIT(dlim, 3),
18385 +               "rcu_free_dl_info(%p)", dli);
18386 +       if (!usecnt)
18387 +               __dealloc_dl_info(dli);
18388 +       else
18389 +               printk("!!! rcu didn't free\n");
18390 +}
18391 +
18392 +
18393 +
18394 +
18395 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
18396 +       uint32_t flags, int add)
18397 +{
18398 +       struct path path;
18399 +       int ret;
18400 +
18401 +       ret = user_lpath(name, &path);
18402 +       if (!ret) {
18403 +               struct super_block *sb;
18404 +               struct dl_info *dli;
18405 +
18406 +               ret = -EINVAL;
18407 +               if (!path.dentry->d_inode)
18408 +                       goto out_release;
18409 +               if (!(sb = path.dentry->d_inode->i_sb))
18410 +                       goto out_release;
18411 +
18412 +               if (add) {
18413 +                       dli = __alloc_dl_info(sb, id);
18414 +                       spin_lock(&dl_info_hash_lock);
18415 +
18416 +                       ret = -EEXIST;
18417 +                       if (__lookup_dl_info(sb, id))
18418 +                               goto out_unlock;
18419 +                       __hash_dl_info(dli);
18420 +                       dli = NULL;
18421 +               } else {
18422 +                       spin_lock(&dl_info_hash_lock);
18423 +                       dli = __lookup_dl_info(sb, id);
18424 +
18425 +                       ret = -ESRCH;
18426 +                       if (!dli)
18427 +                               goto out_unlock;
18428 +                       __unhash_dl_info(dli);
18429 +               }
18430 +               ret = 0;
18431 +       out_unlock:
18432 +               spin_unlock(&dl_info_hash_lock);
18433 +               if (add && dli)
18434 +                       __dealloc_dl_info(dli);
18435 +       out_release:
18436 +               path_put(&path);
18437 +       }
18438 +       return ret;
18439 +}
18440 +
18441 +int vc_add_dlimit(uint32_t id, void __user *data)
18442 +{
18443 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18444 +
18445 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18446 +               return -EFAULT;
18447 +
18448 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
18449 +}
18450 +
18451 +int vc_rem_dlimit(uint32_t id, void __user *data)
18452 +{
18453 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
18454 +
18455 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18456 +               return -EFAULT;
18457 +
18458 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
18459 +}
18460 +
18461 +#ifdef CONFIG_COMPAT
18462 +
18463 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
18464 +{
18465 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18466 +
18467 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18468 +               return -EFAULT;
18469 +
18470 +       return do_addrem_dlimit(id,
18471 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
18472 +}
18473 +
18474 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
18475 +{
18476 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
18477 +
18478 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18479 +               return -EFAULT;
18480 +
18481 +       return do_addrem_dlimit(id,
18482 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
18483 +}
18484 +
18485 +#endif /* CONFIG_COMPAT */
18486 +
18487 +
18488 +static inline
18489 +int do_set_dlimit(uint32_t id, const char __user *name,
18490 +       uint32_t space_used, uint32_t space_total,
18491 +       uint32_t inodes_used, uint32_t inodes_total,
18492 +       uint32_t reserved, uint32_t flags)
18493 +{
18494 +       struct path path;
18495 +       int ret;
18496 +
18497 +       ret = user_lpath(name, &path);
18498 +       if (!ret) {
18499 +               struct super_block *sb;
18500 +               struct dl_info *dli;
18501 +
18502 +               ret = -EINVAL;
18503 +               if (!path.dentry->d_inode)
18504 +                       goto out_release;
18505 +               if (!(sb = path.dentry->d_inode->i_sb))
18506 +                       goto out_release;
18507 +
18508 +               /* sanity checks */
18509 +               if ((reserved != CDLIM_KEEP &&
18510 +                       reserved > 100) ||
18511 +                       (inodes_used != CDLIM_KEEP &&
18512 +                       inodes_used > inodes_total) ||
18513 +                       (space_used != CDLIM_KEEP &&
18514 +                       space_used > space_total))
18515 +                       goto out_release;
18516 +
18517 +               ret = -ESRCH;
18518 +               dli = locate_dl_info(sb, id);
18519 +               if (!dli)
18520 +                       goto out_release;
18521 +
18522 +               spin_lock(&dli->dl_lock);
18523 +
18524 +               if (inodes_used != CDLIM_KEEP)
18525 +                       dli->dl_inodes_used = inodes_used;
18526 +               if (inodes_total != CDLIM_KEEP)
18527 +                       dli->dl_inodes_total = inodes_total;
18528 +               if (space_used != CDLIM_KEEP)
18529 +                       dli->dl_space_used = dlimit_space_32to64(
18530 +                               space_used, flags, DLIMS_USED);
18531 +
18532 +               if (space_total == CDLIM_INFINITY)
18533 +                       dli->dl_space_total = DLIM_INFINITY;
18534 +               else if (space_total != CDLIM_KEEP)
18535 +                       dli->dl_space_total = dlimit_space_32to64(
18536 +                               space_total, flags, DLIMS_TOTAL);
18537 +
18538 +               if (reserved != CDLIM_KEEP)
18539 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
18540 +
18541 +               spin_unlock(&dli->dl_lock);
18542 +
18543 +               put_dl_info(dli);
18544 +               ret = 0;
18545 +
18546 +       out_release:
18547 +               path_put(&path);
18548 +       }
18549 +       return ret;
18550 +}
18551 +
18552 +int vc_set_dlimit(uint32_t id, void __user *data)
18553 +{
18554 +       struct vcmd_ctx_dlimit_v0 vc_data;
18555 +
18556 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18557 +               return -EFAULT;
18558 +
18559 +       return do_set_dlimit(id, vc_data.name,
18560 +               vc_data.space_used, vc_data.space_total,
18561 +               vc_data.inodes_used, vc_data.inodes_total,
18562 +               vc_data.reserved, vc_data.flags);
18563 +}
18564 +
18565 +#ifdef CONFIG_COMPAT
18566 +
18567 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
18568 +{
18569 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18570 +
18571 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18572 +               return -EFAULT;
18573 +
18574 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
18575 +               vc_data.space_used, vc_data.space_total,
18576 +               vc_data.inodes_used, vc_data.inodes_total,
18577 +               vc_data.reserved, vc_data.flags);
18578 +}
18579 +
18580 +#endif /* CONFIG_COMPAT */
18581 +
18582 +
18583 +static inline
18584 +int do_get_dlimit(uint32_t id, const char __user *name,
18585 +       uint32_t *space_used, uint32_t *space_total,
18586 +       uint32_t *inodes_used, uint32_t *inodes_total,
18587 +       uint32_t *reserved, uint32_t *flags)
18588 +{
18589 +       struct path path;
18590 +       int ret;
18591 +
18592 +       ret = user_lpath(name, &path);
18593 +       if (!ret) {
18594 +               struct super_block *sb;
18595 +               struct dl_info *dli;
18596 +
18597 +               ret = -EINVAL;
18598 +               if (!path.dentry->d_inode)
18599 +                       goto out_release;
18600 +               if (!(sb = path.dentry->d_inode->i_sb))
18601 +                       goto out_release;
18602 +
18603 +               ret = -ESRCH;
18604 +               dli = locate_dl_info(sb, id);
18605 +               if (!dli)
18606 +                       goto out_release;
18607 +
18608 +               spin_lock(&dli->dl_lock);
18609 +               *inodes_used = dli->dl_inodes_used;
18610 +               *inodes_total = dli->dl_inodes_total;
18611 +
18612 +               *space_used = dlimit_space_64to32(
18613 +                       dli->dl_space_used, flags, DLIMS_USED);
18614 +
18615 +               if (dli->dl_space_total == DLIM_INFINITY)
18616 +                       *space_total = CDLIM_INFINITY;
18617 +               else
18618 +                       *space_total = dlimit_space_64to32(
18619 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
18620 +
18621 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18622 +               spin_unlock(&dli->dl_lock);
18623 +
18624 +               put_dl_info(dli);
18625 +               ret = -EFAULT;
18626 +
18627 +               ret = 0;
18628 +       out_release:
18629 +               path_put(&path);
18630 +       }
18631 +       return ret;
18632 +}
18633 +
18634 +
18635 +int vc_get_dlimit(uint32_t id, void __user *data)
18636 +{
18637 +       struct vcmd_ctx_dlimit_v0 vc_data;
18638 +       int ret;
18639 +
18640 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18641 +               return -EFAULT;
18642 +
18643 +       ret = do_get_dlimit(id, vc_data.name,
18644 +               &vc_data.space_used, &vc_data.space_total,
18645 +               &vc_data.inodes_used, &vc_data.inodes_total,
18646 +               &vc_data.reserved, &vc_data.flags);
18647 +       if (ret)
18648 +               return ret;
18649 +
18650 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18651 +               return -EFAULT;
18652 +       return 0;
18653 +}
18654 +
18655 +#ifdef CONFIG_COMPAT
18656 +
18657 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18658 +{
18659 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18660 +       int ret;
18661 +
18662 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18663 +               return -EFAULT;
18664 +
18665 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18666 +               &vc_data.space_used, &vc_data.space_total,
18667 +               &vc_data.inodes_used, &vc_data.inodes_total,
18668 +               &vc_data.reserved, &vc_data.flags);
18669 +       if (ret)
18670 +               return ret;
18671 +
18672 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18673 +               return -EFAULT;
18674 +       return 0;
18675 +}
18676 +
18677 +#endif /* CONFIG_COMPAT */
18678 +
18679 +
18680 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
18681 +{
18682 +       struct dl_info *dli;
18683 +       __u64 blimit, bfree, bavail;
18684 +       __u32 ifree;
18685 +
18686 +       dli = locate_dl_info(sb, dx_current_tag());
18687 +       if (!dli)
18688 +               return;
18689 +
18690 +       spin_lock(&dli->dl_lock);
18691 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
18692 +               goto no_ilim;
18693 +
18694 +       /* reduce max inodes available to limit */
18695 +       if (buf->f_files > dli->dl_inodes_total)
18696 +               buf->f_files = dli->dl_inodes_total;
18697 +
18698 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
18699 +       /* reduce free inodes to min */
18700 +       if (ifree < buf->f_ffree)
18701 +               buf->f_ffree = ifree;
18702 +
18703 +no_ilim:
18704 +       if (dli->dl_space_total == DLIM_INFINITY)
18705 +               goto no_blim;
18706 +
18707 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
18708 +
18709 +       if (dli->dl_space_total < dli->dl_space_used)
18710 +               bfree = 0;
18711 +       else
18712 +               bfree = (dli->dl_space_total - dli->dl_space_used)
18713 +                       >> sb->s_blocksize_bits;
18714 +
18715 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
18716 +       if (bavail < dli->dl_space_used)
18717 +               bavail = 0;
18718 +       else
18719 +               bavail = (bavail - dli->dl_space_used)
18720 +                       >> sb->s_blocksize_bits;
18721 +
18722 +       /* reduce max space available to limit */
18723 +       if (buf->f_blocks > blimit)
18724 +               buf->f_blocks = blimit;
18725 +
18726 +       /* reduce free space to min */
18727 +       if (bfree < buf->f_bfree)
18728 +               buf->f_bfree = bfree;
18729 +
18730 +       /* reduce avail space to min */
18731 +       if (bavail < buf->f_bavail)
18732 +               buf->f_bavail = bavail;
18733 +
18734 +no_blim:
18735 +       spin_unlock(&dli->dl_lock);
18736 +       put_dl_info(dli);
18737 +
18738 +       return;
18739 +}
18740 +
18741 +#include <linux/module.h>
18742 +
18743 +EXPORT_SYMBOL_GPL(locate_dl_info);
18744 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
18745 +
18746 diff -NurpP --minimal linux-2.6.36/kernel/vserver/helper.c linux-2.6.36-vs2.3.0.36.33/kernel/vserver/helper.c
18747 --- linux-2.6.36/kernel/vserver/helper.c        1970-01-01 01:00:00.000000000 +0100
18748 +++ linux-2.6.36-vs2.3.0.36.33/kernel/vserver/helper.c  2010-10-21 13:09:36.000000000 +0200
18749 @@ -0,0 +1,223 @@
18750 +/*
18751 + *  linux/kernel/vserver/helper.c
18752 + *
18753 + *  Virtual Context Support
18754 + *
18755 + *  Copyright (C) 2004-2007  Herbert Pötzl
18756 + *
18757 + *  V0.01  basic helper
18758 + *
18759 + */
18760 +
18761 +#include <linux/kmod.h>
18762 +#include <linux/reboot.h>
18763 +#include <linux/vs_context.h>
18764 +#include <linux/vs_network.h>
18765 +#include <linux/vserver/signal.h>
18766 +
18767 +
18768 +char vshelper_path[255] = "/sbin/vshelper";
18769 +
18770 +
18771 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
18772 +{
18773 +       int ret;
18774 +
18775 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
18776 +               printk( KERN_WARNING
18777 +                       "%s: (%s %s) returned %s with %d\n",
18778 +                       name, argv[1], argv[2],
18779 +                       sync ? "sync" : "async", ret);
18780 +       }
18781 +       vxdprintk(VXD_CBIT(switch, 4),
18782 +               "%s: (%s %s) returned %s with %d",
18783 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
18784 +       return ret;
18785 +}
18786 +
18787 +/*
18788 + *      vshelper path is set via /proc/sys
18789 + *      invoked by vserver sys_reboot(), with
18790 + *      the following arguments
18791 + *
18792 + *      argv [0] = vshelper_path;
18793 + *      argv [1] = action: "restart", "halt", "poweroff", ...
18794 + *      argv [2] = context identifier
18795 + *
18796 + *      envp [*] = type-specific parameters
18797 + */
18798 +
18799 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
18800 +{
18801 +       char id_buf[8], cmd_buf[16];
18802 +       char uid_buf[16], pid_buf[16];
18803 +       int ret;
18804 +
18805 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18806 +       char *envp[] = {"HOME=/", "TERM=linux",
18807 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
18808 +                       uid_buf, pid_buf, cmd_buf, 0};
18809 +
18810 +       if (vx_info_state(vxi, VXS_HELPER))
18811 +               return -EAGAIN;
18812 +       vxi->vx_state |= VXS_HELPER;
18813 +
18814 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
18815 +
18816 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
18817 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current_uid());
18818 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
18819 +
18820 +       switch (cmd) {
18821 +       case LINUX_REBOOT_CMD_RESTART:
18822 +               argv[1] = "restart";
18823 +               break;
18824 +
18825 +       case LINUX_REBOOT_CMD_HALT:
18826 +               argv[1] = "halt";
18827 +               break;
18828 +
18829 +       case LINUX_REBOOT_CMD_POWER_OFF:
18830 +               argv[1] = "poweroff";
18831 +               break;
18832 +
18833 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
18834 +               argv[1] = "swsusp";
18835 +               break;
18836 +
18837 +       case LINUX_REBOOT_CMD_OOM:
18838 +               argv[1] = "oom";
18839 +               break;
18840 +
18841 +       default:
18842 +               vxi->vx_state &= ~VXS_HELPER;
18843 +               return 0;
18844 +       }
18845 +
18846 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
18847 +       vxi->vx_state &= ~VXS_HELPER;
18848 +       __wakeup_vx_info(vxi);
18849 +       return (ret) ? -EPERM : 0;
18850 +}
18851 +
18852 +
18853 +long vs_reboot(unsigned int cmd, void __user *arg)
18854 +{
18855 +       struct vx_info *vxi = current_vx_info();
18856 +       long ret = 0;
18857 +
18858 +       vxdprintk(VXD_CBIT(misc, 5),
18859 +               "vs_reboot(%p[#%d],%u)",
18860 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18861 +
18862 +       ret = vs_reboot_helper(vxi, cmd, arg);
18863 +       if (ret)
18864 +               return ret;
18865 +
18866 +       vxi->reboot_cmd = cmd;
18867 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18868 +               switch (cmd) {
18869 +               case LINUX_REBOOT_CMD_RESTART:
18870 +               case LINUX_REBOOT_CMD_HALT:
18871 +               case LINUX_REBOOT_CMD_POWER_OFF:
18872 +                       vx_info_kill(vxi, 0, SIGKILL);
18873 +                       vx_info_kill(vxi, 1, SIGKILL);
18874 +               default:
18875 +                       break;
18876 +               }
18877 +       }
18878 +       return 0;
18879 +}
18880 +
18881 +long vs_oom_action(unsigned int cmd)
18882 +{
18883 +       struct vx_info *vxi = current_vx_info();
18884 +       long ret = 0;
18885 +
18886 +       vxdprintk(VXD_CBIT(misc, 5),
18887 +               "vs_oom_action(%p[#%d],%u)",
18888 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18889 +
18890 +       ret = vs_reboot_helper(vxi, cmd, NULL);
18891 +       if (ret)
18892 +               return ret;
18893 +
18894 +       vxi->reboot_cmd = cmd;
18895 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18896 +               vx_info_kill(vxi, 0, SIGKILL);
18897 +               vx_info_kill(vxi, 1, SIGKILL);
18898 +       }
18899 +       return 0;
18900 +}
18901 +
18902 +/*
18903 + *      argv [0] = vshelper_path;
18904 + *      argv [1] = action: "startup", "shutdown"
18905 + *      argv [2] = context identifier
18906 + *
18907 + *      envp [*] = type-specific parameters
18908 + */
18909 +
18910 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
18911 +{
18912 +       char id_buf[8], cmd_buf[16];
18913 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18914 +       char *envp[] = {"HOME=/", "TERM=linux",
18915 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18916 +
18917 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
18918 +               return 0;
18919 +
18920 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
18921 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
18922 +
18923 +       switch (cmd) {
18924 +       case VSC_STARTUP:
18925 +               argv[1] = "startup";
18926 +               break;
18927 +       case VSC_SHUTDOWN:
18928 +               argv[1] = "shutdown";
18929 +               break;
18930 +       default:
18931 +               return 0;
18932 +       }
18933 +
18934 +       return do_vshelper(vshelper_path, argv, envp, 1);
18935 +}
18936 +
18937 +
18938 +/*
18939 + *      argv [0] = vshelper_path;
18940 + *      argv [1] = action: "netup", "netdown"
18941 + *      argv [2] = context identifier
18942 + *
18943 + *      envp [*] = type-specific parameters
18944 + */
18945 +
18946 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
18947 +{
18948 +       char id_buf[8], cmd_buf[16];
18949 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18950 +       char *envp[] = {"HOME=/", "TERM=linux",
18951 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18952 +
18953 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
18954 +               return 0;
18955 +
18956 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
18957 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
18958 +
18959 +       switch (cmd) {
18960 +       case VSC_NETUP:
18961 +               argv[1] = "netup";
18962 +               break;
18963 +       case VSC_NETDOWN:
18964 +               argv[1] = "netdown";
18965 +               break;
18966 +       default:
18967 +               return 0;
18968 +       }
18969 +
18970 +       return do_vshelper(vshelper_path, argv, envp, 1);
18971 +}
18972 +
18973 diff -NurpP --minimal linux-2.6.36/kernel/vserver/history.c linux-2.6.36-vs2.3.0.36.33/kernel/vserver/history.c
18974 --- linux-2.6.36/kernel/vserver/history.c       1970-01-01 01:00:00.000000000 +0100
18975 +++ linux-2.6.36-vs2.3.0.36.33/kernel/vserver/history.c 2010-10-21 13:09:36.000000000 +0200
18976 @@ -0,0 +1,258 @@
18977 +/*
18978 + *  kernel/vserver/history.c
18979 + *
18980 + *  Virtual Context History Backtrace
18981 + *
18982 + *  Copyright (C) 2004-2007  Herbert Pötzl
18983 + *
18984 + *  V0.01  basic structure
18985 + *  V0.02  hash/unhash and trace
18986 + *  V0.03  preemption fixes
18987 + *
18988 + */
18989 +
18990 +#include <linux/module.h>
18991 +#include <asm/uaccess.h>
18992 +
18993 +#include <linux/vserver/context.h>
18994 +#include <linux/vserver/debug.h>
18995 +#include <linux/vserver/debug_cmd.h>
18996 +#include <linux/vserver/history.h>
18997 +
18998 +
18999 +#ifdef CONFIG_VSERVER_HISTORY
19000 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
19001 +#else
19002 +#define VXH_SIZE       64
19003 +#endif
19004 +
19005 +struct _vx_history {
19006 +       unsigned int counter;
19007 +
19008 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
19009 +};
19010 +
19011 +
19012 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
19013 +
19014 +unsigned volatile int vxh_active = 1;
19015 +
19016 +static atomic_t sequence = ATOMIC_INIT(0);
19017 +
19018 +
19019 +/*     vxh_advance()
19020 +
19021 +       * requires disabled preemption                          */
19022 +
19023 +struct _vx_hist_entry *vxh_advance(void *loc)
19024 +{
19025 +       unsigned int cpu = smp_processor_id();
19026 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
19027 +       struct _vx_hist_entry *entry;
19028 +       unsigned int index;
19029 +
19030 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
19031 +       entry = &hist->entry[index];
19032 +
19033 +       entry->seq = atomic_inc_return(&sequence);
19034 +       entry->loc = loc;
19035 +       return entry;
19036 +}
19037 +
19038 +EXPORT_SYMBOL_GPL(vxh_advance);
19039 +
19040 +
19041 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
19042 +
19043 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
19044 +
19045 +
19046 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
19047 +
19048 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
19049 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
19050 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
19051 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
19052 +
19053 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
19054 +{
19055 +       switch (e->type) {
19056 +       case VXH_THROW_OOPS:
19057 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
19058 +               break;
19059 +
19060 +       case VXH_GET_VX_INFO:
19061 +       case VXH_PUT_VX_INFO:
19062 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
19063 +                       VXH_LOC_ARGS(e),
19064 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
19065 +                       VXH_VXI_ARGS(e));
19066 +               break;
19067 +
19068 +       case VXH_INIT_VX_INFO:
19069 +       case VXH_SET_VX_INFO:
19070 +       case VXH_CLR_VX_INFO:
19071 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
19072 +                       VXH_LOC_ARGS(e),
19073 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
19074 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
19075 +                       VXH_VXI_ARGS(e), e->sc.data);
19076 +               break;
19077 +
19078 +       case VXH_CLAIM_VX_INFO:
19079 +       case VXH_RELEASE_VX_INFO:
19080 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
19081 +                       VXH_LOC_ARGS(e),
19082 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
19083 +                       VXH_VXI_ARGS(e), e->sc.data);
19084 +               break;
19085 +
19086 +       case VXH_ALLOC_VX_INFO:
19087 +       case VXH_DEALLOC_VX_INFO:
19088 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
19089 +                       VXH_LOC_ARGS(e),
19090 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
19091 +                       VXH_VXI_ARGS(e));
19092 +               break;
19093 +
19094 +       case VXH_HASH_VX_INFO:
19095 +       case VXH_UNHASH_VX_INFO:
19096 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
19097 +                       VXH_LOC_ARGS(e),
19098 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
19099 +                       VXH_VXI_ARGS(e));
19100 +               break;
19101 +
19102 +       case VXH_LOC_VX_INFO:
19103 +       case VXH_LOOKUP_VX_INFO:
19104 +       case VXH_CREATE_VX_INFO:
19105 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
19106 +                       VXH_LOC_ARGS(e),
19107 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
19108 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
19109 +                       e->ll.arg, VXH_VXI_ARGS(e));
19110 +               break;
19111 +       }
19112 +}
19113 +
19114 +static void __vxh_dump_history(void)
19115 +{
19116 +       unsigned int i, cpu;
19117 +
19118 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
19119 +               atomic_read(&sequence), NR_CPUS);
19120 +
19121 +       for (i = 0; i < VXH_SIZE; i++) {
19122 +               for_each_online_cpu(cpu) {
19123 +                       struct _vx_history *hist =
19124 +                               &per_cpu(vx_history_buffer, cpu);
19125 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
19126 +                       struct _vx_hist_entry *entry = &hist->entry[index];
19127 +
19128 +                       vxh_dump_entry(entry, cpu);
19129 +               }
19130 +       }
19131 +}
19132 +
19133 +void   vxh_dump_history(void)
19134 +{
19135 +       vxh_active = 0;
19136 +#ifdef CONFIG_SMP
19137 +       local_irq_enable();
19138 +       smp_send_stop();
19139 +       local_irq_disable();
19140 +#endif
19141 +       __vxh_dump_history();
19142 +}
19143 +
19144 +
19145 +/* vserver syscall commands below here */
19146 +
19147 +
19148 +int vc_dump_history(uint32_t id)
19149 +{
19150 +       vxh_active = 0;
19151 +       __vxh_dump_history();
19152 +       vxh_active = 1;
19153 +
19154 +       return 0;
19155 +}
19156 +
19157 +
19158 +int do_read_history(struct __user _vx_hist_entry *data,
19159 +       int cpu, uint32_t *index, uint32_t *count)
19160 +{
19161 +       int pos, ret = 0;
19162 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
19163 +       int end = hist->counter;
19164 +       int start = end - VXH_SIZE + 2;
19165 +       int idx = *index;
19166 +
19167 +       /* special case: get current pos */
19168 +       if (!*count) {
19169 +               *index = end;
19170 +               return 0;
19171 +       }
19172 +
19173 +       /* have we lost some data? */
19174 +       if (idx < start)
19175 +               idx = start;
19176 +
19177 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
19178 +               struct _vx_hist_entry *entry =
19179 +                       &hist->entry[idx % VXH_SIZE];
19180 +
19181 +               /* send entry to userspace */
19182 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
19183 +               if (ret)
19184 +                       break;
19185 +       }
19186 +       /* save new index and count */
19187 +       *index = idx;
19188 +       *count = pos;
19189 +       return ret ? ret : (*index < end);
19190 +}
19191 +
19192 +int vc_read_history(uint32_t id, void __user *data)
19193 +{
19194 +       struct vcmd_read_history_v0 vc_data;
19195 +       int ret;
19196 +
19197 +       if (id >= NR_CPUS)
19198 +               return -EINVAL;
19199 +
19200 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19201 +               return -EFAULT;
19202 +
19203 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
19204 +               id, &vc_data.index, &vc_data.count);
19205 +
19206 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19207 +               return -EFAULT;
19208 +       return ret;
19209 +}
19210 +
19211 +#ifdef CONFIG_COMPAT
19212 +
19213 +int vc_read_history_x32(uint32_t id, void __user *data)
19214 +{
19215 +       struct vcmd_read_history_v0_x32 vc_data;
19216 +       int ret;
19217 +
19218 +       if (id >= NR_CPUS)
19219 +               return -EINVAL;
19220 +
19221 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19222 +               return -EFAULT;
19223 +
19224 +       ret = do_read_history((struct __user _vx_hist_entry *)
19225 +               compat_ptr(vc_data.data_ptr),
19226 +               id, &vc_data.index, &vc_data.count);
19227 +
19228 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19229 +               return -EFAULT;
19230 +       return ret;
19231 +}
19232 +
19233 +#endif /* CONFIG_COMPAT */
19234 +
19235 diff -NurpP --minimal linux-2.6.36/kernel/vserver/inet.c linux-2.6.36-vs2.3.0.36.33/kernel/vserver/inet.c
19236 --- linux-2.6.36/kernel/vserver/inet.c  1970-01-01 01:00:00.000000000 +0100
19237 +++ linux-2.6.36-vs2.3.0.36.33/kernel/vserver/inet.c    2010-10-21 13:09:36.000000000 +0200
19238 @@ -0,0 +1,224 @@
19239 +
19240 +#include <linux/in.h>
19241 +#include <linux/inetdevice.h>
19242 +#include <linux/vs_inet.h>
19243 +#include <linux/vs_inet6.h>
19244 +#include <linux/vserver/debug.h>
19245 +#include <net/route.h>
19246 +#include <net/addrconf.h>
19247 +
19248 +
19249 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19250 +{
19251 +       int ret = 0;
19252 +
19253 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19254 +               ret = 1;
19255 +       else {
19256 +               struct nx_addr_v4 *ptr;
19257 +
19258 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
19259 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19260 +                               ret = 1;
19261 +                               break;
19262 +                       }
19263 +               }
19264 +       }
19265 +
19266 +       vxdprintk(VXD_CBIT(net, 2),
19267 +               "nx_v4_addr_conflict(%p,%p): %d",
19268 +               nxi1, nxi2, ret);
19269 +
19270 +       return ret;
19271 +}
19272 +
19273 +
19274 +#ifdef CONFIG_IPV6
19275 +
19276 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
19277 +{
19278 +       int ret = 0;
19279 +
19280 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
19281 +               ret = 1;
19282 +       else {
19283 +               struct nx_addr_v6 *ptr;
19284 +
19285 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
19286 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
19287 +                               ret = 1;
19288 +                               break;
19289 +                       }
19290 +               }
19291 +       }
19292 +
19293 +       vxdprintk(VXD_CBIT(net, 2),
19294 +               "nx_v6_addr_conflict(%p,%p): %d",
19295 +               nxi1, nxi2, ret);
19296 +
19297 +       return ret;
19298 +}
19299 +
19300 +#endif
19301 +
19302 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19303 +{
19304 +       struct in_device *in_dev;
19305 +       struct in_ifaddr **ifap;
19306 +       struct in_ifaddr *ifa;
19307 +       int ret = 0;
19308 +
19309 +       if (!dev)
19310 +               goto out;
19311 +       in_dev = in_dev_get(dev);
19312 +       if (!in_dev)
19313 +               goto out;
19314 +
19315 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
19316 +               ifap = &ifa->ifa_next) {
19317 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
19318 +                       ret = 1;
19319 +                       break;
19320 +               }
19321 +       }
19322 +       in_dev_put(in_dev);
19323 +out:
19324 +       return ret;
19325 +}
19326 +
19327 +
19328 +#ifdef CONFIG_IPV6
19329 +
19330 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19331 +{
19332 +       struct inet6_dev *in_dev;
19333 +       struct inet6_ifaddr *ifa;
19334 +       int ret = 0;
19335 +
19336 +       if (!dev)
19337 +               goto out;
19338 +       in_dev = in6_dev_get(dev);
19339 +       if (!in_dev)
19340 +               goto out;
19341 +
19342 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
19343 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
19344 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
19345 +                       ret = 1;
19346 +                       break;
19347 +               }
19348 +       }
19349 +       in6_dev_put(in_dev);
19350 +out:
19351 +       return ret;
19352 +}
19353 +
19354 +#endif
19355 +
19356 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
19357 +{
19358 +       int ret = 1;
19359 +
19360 +       if (!nxi)
19361 +               goto out;
19362 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
19363 +               goto out;
19364 +#ifdef CONFIG_IPV6
19365 +       ret = 2;
19366 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
19367 +               goto out;
19368 +#endif
19369 +       ret = 0;
19370 +out:
19371 +       vxdprintk(VXD_CBIT(net, 3),
19372 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
19373 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
19374 +       return ret;
19375 +}
19376 +
19377 +int ip_v4_find_src(struct net *net, struct nx_info *nxi,
19378 +       struct rtable **rp, struct flowi *fl)
19379 +{
19380 +       if (!nxi)
19381 +               return 0;
19382 +
19383 +       /* FIXME: handle lback only case */
19384 +       if (!NX_IPV4(nxi))
19385 +               return -EPERM;
19386 +
19387 +       vxdprintk(VXD_CBIT(net, 4),
19388 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
19389 +               nxi, nxi ? nxi->nx_id : 0,
19390 +               NIPQUAD(fl->fl4_src), NIPQUAD(fl->fl4_dst));
19391 +
19392 +       /* single IP is unconditional */
19393 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
19394 +               (fl->fl4_src == INADDR_ANY))
19395 +               fl->fl4_src = nxi->v4.ip[0].s_addr;
19396 +
19397 +       if (fl->fl4_src == INADDR_ANY) {
19398 +               struct nx_addr_v4 *ptr;
19399 +               __be32 found = 0;
19400 +               int err;
19401 +
19402 +               err = __ip_route_output_key(net, rp, fl);
19403 +               if (!err) {
19404 +                       found = (*rp)->rt_src;
19405 +                       ip_rt_put(*rp);
19406 +                       vxdprintk(VXD_CBIT(net, 4),
19407 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19408 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(found));
19409 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
19410 +                               goto found;
19411 +               }
19412 +
19413 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
19414 +                       __be32 primary = ptr->ip[0].s_addr;
19415 +                       __be32 mask = ptr->mask.s_addr;
19416 +                       __be32 neta = primary & mask;
19417 +
19418 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
19419 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
19420 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
19421 +                               NIPQUAD(mask), NIPQUAD(neta));
19422 +                       if ((found & mask) != neta)
19423 +                               continue;
19424 +
19425 +                       fl->fl4_src = primary;
19426 +                       err = __ip_route_output_key(net, rp, fl);
19427 +                       vxdprintk(VXD_CBIT(net, 4),
19428 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
19429 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(primary));
19430 +                       if (!err) {
19431 +                               found = (*rp)->rt_src;
19432 +                               ip_rt_put(*rp);
19433 +                               if (found == primary)
19434 +                                       goto found;
19435 +                       }
19436 +               }
19437 +               /* still no source ip? */
19438 +               found = ipv4_is_loopback(fl->fl4_dst)
19439 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
19440 +       found:
19441 +               /* assign src ip to flow */
19442 +               fl->fl4_src = found;
19443 +
19444 +       } else {
19445 +               if (!v4_addr_in_nx_info(nxi, fl->fl4_src, NXA_MASK_BIND))
19446 +                       return -EPERM;
19447 +       }
19448 +
19449 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
19450 +               if (ipv4_is_loopback(fl->fl4_dst))
19451 +                       fl->fl4_dst = nxi->v4_lback.s_addr;
19452 +               if (ipv4_is_loopback(fl->fl4_src))
19453 +                       fl->fl4_src = nxi->v4_lback.s_addr;
19454 +       } else if (ipv4_is_loopback(fl->fl4_dst) &&
19455 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
19456 +               return -EPERM;
19457 +
19458 +       return 0;
19459 +}
19460 +
19461 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
19462 +
19463 diff -NurpP --minimal linux-2.6.36/kernel/vserver/init.c linux-2.6.36-vs2.3.0.36.33/kernel/vserver/init.c
19464 --- linux-2.6.36/kernel/vserver/init.c  1970-01-01 01:00:00.000000000 +0100
19465 +++ linux-2.6.36-vs2.3.0.36.33/kernel/vserver/init.c    2010-10-21 13:09:36.000000000 +0200
19466 @@ -0,0 +1,45 @@
19467 +/*
19468 + *  linux/kernel/init.c
19469 + *
19470 + *  Virtual Server Init
19471 + *
19472 + *  Copyright (C) 2004-2007  Herbert Pötzl
19473 + *
19474 + *  V0.01  basic structure
19475 + *
19476 + */
19477 +
19478 +#include <linux/init.h>
19479 +
19480 +int    vserver_register_sysctl(void);
19481 +void   vserver_unregister_sysctl(void);
19482 +
19483 +
19484 +static int __init init_vserver(void)
19485 +{
19486 +       int ret = 0;
19487 +
19488 +#ifdef CONFIG_VSERVER_DEBUG
19489 +       vserver_register_sysctl();
19490 +#endif
19491 +       return ret;
19492 +}
19493 +
19494 +
19495 +static void __exit exit_vserver(void)
19496 +{
19497 +
19498 +#ifdef CONFIG_VSERVER_DEBUG
19499 +       vserver_unregister_sysctl();
19500 +#endif
19501 +       return;
19502 +}
19503 +
19504 +/* FIXME: GFP_ZONETYPES gone
19505 +long vx_slab[GFP_ZONETYPES]; */
19506 +long vx_area;
19507 +
19508 +
19509 +module_init(init_vserver);
19510 +module_exit(exit_vserver);
19511 +
19512 diff -NurpP --minimal linux-2.6.36/kernel/vserver/inode.c linux-2.6.36-vs2.3.0.36.33/kernel/vserver/inode.c
19513 --- linux-2.6.36/kernel/vserver/inode.c 1970-01-01 01:00:00.000000000 +0100
19514 +++ linux-2.6.36-vs2.3.0.36.33/kernel/vserver/inode.c   2010-10-21 14:46:31.000000000 +0200
19515 @@ -0,0 +1,435 @@
19516 +/*
19517 + *  linux/kernel/vserver/inode.c
19518 + *
19519 + *  Virtual Server: File System Support
19520 + *
19521 + *  Copyright (C) 2004-2007  Herbert Pötzl
19522 + *
19523 + *  V0.01  separated from vcontext V0.05
19524 + *  V0.02  moved to tag (instead of xid)
19525 + *
19526 + */
19527 +
19528 +#include <linux/tty.h>
19529 +#include <linux/proc_fs.h>
19530 +#include <linux/devpts_fs.h>
19531 +#include <linux/fs.h>
19532 +#include <linux/file.h>
19533 +#include <linux/mount.h>
19534 +#include <linux/parser.h>
19535 +#include <linux/namei.h>
19536 +#include <linux/vserver/inode.h>
19537 +#include <linux/vserver/inode_cmd.h>
19538 +#include <linux/vs_base.h>
19539 +#include <linux/vs_tag.h>
19540 +
19541 +#include <asm/uaccess.h>
19542 +
19543 +
19544 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19545 +{
19546 +       struct proc_dir_entry *entry;
19547 +
19548 +       if (!in || !in->i_sb)
19549 +               return -ESRCH;
19550 +
19551 +       *flags = IATTR_TAG
19552 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
19553 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
19554 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
19555 +               | (IS_COW(in) ? IATTR_COW : 0);
19556 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
19557 +
19558 +       if (S_ISDIR(in->i_mode))
19559 +               *mask |= IATTR_BARRIER;
19560 +
19561 +       if (IS_TAGGED(in)) {
19562 +               *tag = in->i_tag;
19563 +               *mask |= IATTR_TAG;
19564 +       }
19565 +
19566 +       switch (in->i_sb->s_magic) {
19567 +       case PROC_SUPER_MAGIC:
19568 +               entry = PROC_I(in)->pde;
19569 +
19570 +               /* check for specific inodes? */
19571 +               if (entry)
19572 +                       *mask |= IATTR_FLAGS;
19573 +               if (entry)
19574 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
19575 +               else
19576 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19577 +               break;
19578 +
19579 +       case DEVPTS_SUPER_MAGIC:
19580 +               *tag = in->i_tag;
19581 +               *mask |= IATTR_TAG;
19582 +               break;
19583 +
19584 +       default:
19585 +               break;
19586 +       }
19587 +       return 0;
19588 +}
19589 +
19590 +int vc_get_iattr(void __user *data)
19591 +{
19592 +       struct path path;
19593 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19594 +       int ret;
19595 +
19596 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19597 +               return -EFAULT;
19598 +
19599 +       ret = user_lpath(vc_data.name, &path);
19600 +       if (!ret) {
19601 +               ret = __vc_get_iattr(path.dentry->d_inode,
19602 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19603 +               path_put(&path);
19604 +       }
19605 +       if (ret)
19606 +               return ret;
19607 +
19608 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19609 +               ret = -EFAULT;
19610 +       return ret;
19611 +}
19612 +
19613 +#ifdef CONFIG_COMPAT
19614 +
19615 +int vc_get_iattr_x32(void __user *data)
19616 +{
19617 +       struct path path;
19618 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19619 +       int ret;
19620 +
19621 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19622 +               return -EFAULT;
19623 +
19624 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19625 +       if (!ret) {
19626 +               ret = __vc_get_iattr(path.dentry->d_inode,
19627 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19628 +               path_put(&path);
19629 +       }
19630 +       if (ret)
19631 +               return ret;
19632 +
19633 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19634 +               ret = -EFAULT;
19635 +       return ret;
19636 +}
19637 +
19638 +#endif /* CONFIG_COMPAT */
19639 +
19640 +
19641 +int vc_fget_iattr(uint32_t fd, void __user *data)
19642 +{
19643 +       struct file *filp;
19644 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19645 +       int ret;
19646 +
19647 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19648 +               return -EFAULT;
19649 +
19650 +       filp = fget(fd);
19651 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19652 +               return -EBADF;
19653 +
19654 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
19655 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
19656 +
19657 +       fput(filp);
19658 +
19659 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19660 +               ret = -EFAULT;
19661 +       return ret;
19662 +}
19663 +
19664 +
19665 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19666 +{
19667 +       struct inode *in = de->d_inode;
19668 +       int error = 0, is_proc = 0, has_tag = 0;
19669 +       struct iattr attr = { 0 };
19670 +
19671 +       if (!in || !in->i_sb)
19672 +               return -ESRCH;
19673 +
19674 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19675 +       if ((*mask & IATTR_FLAGS) && !is_proc)
19676 +               return -EINVAL;
19677 +
19678 +       has_tag = IS_TAGGED(in) ||
19679 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
19680 +       if ((*mask & IATTR_TAG) && !has_tag)
19681 +               return -EINVAL;
19682 +
19683 +       mutex_lock(&in->i_mutex);
19684 +       if (*mask & IATTR_TAG) {
19685 +               attr.ia_tag = *tag;
19686 +               attr.ia_valid |= ATTR_TAG;
19687 +       }
19688 +
19689 +       if (*mask & IATTR_FLAGS) {
19690 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
19691 +               unsigned int iflags = PROC_I(in)->vx_flags;
19692 +
19693 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
19694 +                       | (*flags & IATTR_FLAGS);
19695 +               PROC_I(in)->vx_flags = iflags;
19696 +               if (entry)
19697 +                       entry->vx_flags = iflags;
19698 +       }
19699 +
19700 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
19701 +               IATTR_BARRIER | IATTR_COW)) {
19702 +               int iflags = in->i_flags;
19703 +               int vflags = in->i_vflags;
19704 +
19705 +               if (*mask & IATTR_IMMUTABLE) {
19706 +                       if (*flags & IATTR_IMMUTABLE)
19707 +                               iflags |= S_IMMUTABLE;
19708 +                       else
19709 +                               iflags &= ~S_IMMUTABLE;
19710 +               }
19711 +               if (*mask & IATTR_IXUNLINK) {
19712 +                       if (*flags & IATTR_IXUNLINK)
19713 +                               iflags |= S_IXUNLINK;
19714 +                       else
19715 +                               iflags &= ~S_IXUNLINK;
19716 +               }
19717 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
19718 +                       if (*flags & IATTR_BARRIER)
19719 +                               vflags |= V_BARRIER;
19720 +                       else
19721 +                               vflags &= ~V_BARRIER;
19722 +               }
19723 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
19724 +                       if (*flags & IATTR_COW)
19725 +                               vflags |= V_COW;
19726 +                       else
19727 +                               vflags &= ~V_COW;
19728 +               }
19729 +               if (in->i_op && in->i_op->sync_flags) {
19730 +                       error = in->i_op->sync_flags(in, iflags, vflags);
19731 +                       if (error)
19732 +                               goto out;
19733 +               }
19734 +       }
19735 +
19736 +       if (attr.ia_valid) {
19737 +               if (in->i_op && in->i_op->setattr)
19738 +                       error = in->i_op->setattr(de, &attr);
19739 +               else {
19740 +                       error = inode_change_ok(in, &attr);
19741 +                       if (!error) {
19742 +                               setattr_copy(in, &attr);
19743 +                               mark_inode_dirty(in);
19744 +                       }
19745 +               }
19746 +       }
19747 +
19748 +out:
19749 +       mutex_unlock(&in->i_mutex);
19750 +       return error;
19751 +}
19752 +
19753 +int vc_set_iattr(void __user *data)
19754 +{
19755 +       struct path path;
19756 +       struct vcmd_ctx_iattr_v1 vc_data;
19757 +       int ret;
19758 +
19759 +       if (!capable(CAP_LINUX_IMMUTABLE))
19760 +               return -EPERM;
19761 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19762 +               return -EFAULT;
19763 +
19764 +       ret = user_lpath(vc_data.name, &path);
19765 +       if (!ret) {
19766 +               ret = __vc_set_iattr(path.dentry,
19767 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19768 +               path_put(&path);
19769 +       }
19770 +
19771 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19772 +               ret = -EFAULT;
19773 +       return ret;
19774 +}
19775 +
19776 +#ifdef CONFIG_COMPAT
19777 +
19778 +int vc_set_iattr_x32(void __user *data)
19779 +{
19780 +       struct path path;
19781 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
19782 +       int ret;
19783 +
19784 +       if (!capable(CAP_LINUX_IMMUTABLE))
19785 +               return -EPERM;
19786 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19787 +               return -EFAULT;
19788 +
19789 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19790 +       if (!ret) {
19791 +               ret = __vc_set_iattr(path.dentry,
19792 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19793 +               path_put(&path);
19794 +       }
19795 +
19796 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19797 +               ret = -EFAULT;
19798 +       return ret;
19799 +}
19800 +
19801 +#endif /* CONFIG_COMPAT */
19802 +
19803 +int vc_fset_iattr(uint32_t fd, void __user *data)
19804 +{
19805 +       struct file *filp;
19806 +       struct vcmd_ctx_fiattr_v0 vc_data;
19807 +       int ret;
19808 +
19809 +       if (!capable(CAP_LINUX_IMMUTABLE))
19810 +               return -EPERM;
19811 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19812 +               return -EFAULT;
19813 +
19814 +       filp = fget(fd);
19815 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19816 +               return -EBADF;
19817 +
19818 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
19819 +               &vc_data.flags, &vc_data.mask);
19820 +
19821 +       fput(filp);
19822 +
19823 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19824 +               return -EFAULT;
19825 +       return ret;
19826 +}
19827 +
19828 +
19829 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
19830 +
19831 +static match_table_t tokens = {
19832 +       {Opt_notagcheck, "notagcheck"},
19833 +#ifdef CONFIG_PROPAGATE
19834 +       {Opt_notag, "notag"},
19835 +       {Opt_tag, "tag"},
19836 +       {Opt_tagid, "tagid=%u"},
19837 +#endif
19838 +       {Opt_err, NULL}
19839 +};
19840 +
19841 +
19842 +static void __dx_parse_remove(char *string, char *opt)
19843 +{
19844 +       char *p = strstr(string, opt);
19845 +       char *q = p;
19846 +
19847 +       if (p) {
19848 +               while (*q != '\0' && *q != ',')
19849 +                       q++;
19850 +               while (*q)
19851 +                       *p++ = *q++;
19852 +               while (*p)
19853 +                       *p++ = '\0';
19854 +       }
19855 +}
19856 +
19857 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
19858 +                unsigned long *flags)
19859 +{
19860 +       int set = 0;
19861 +       substring_t args[MAX_OPT_ARGS];
19862 +       int token, option = 0;
19863 +       char *s, *p, *opts;
19864 +
19865 +       if (!string)
19866 +               return 0;
19867 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
19868 +       if (!s)
19869 +               return 0;
19870 +
19871 +       opts = s;
19872 +       while ((p = strsep(&opts, ",")) != NULL) {
19873 +               token = match_token(p, tokens, args);
19874 +
19875 +               vxdprintk(VXD_CBIT(tag, 7),
19876 +                       "dx_parse_tag(»%s«): %d:#%d",
19877 +                       p, token, option);
19878 +
19879 +               switch (token) {
19880 +#ifdef CONFIG_PROPAGATE
19881 +               case Opt_tag:
19882 +                       if (tag)
19883 +                               *tag = 0;
19884 +                       if (remove)
19885 +                               __dx_parse_remove(s, "tag");
19886 +                       *mnt_flags |= MNT_TAGID;
19887 +                       set |= MNT_TAGID;
19888 +                       break;
19889 +               case Opt_notag:
19890 +                       if (remove)
19891 +                               __dx_parse_remove(s, "notag");
19892 +                       *mnt_flags |= MNT_NOTAG;
19893 +                       set |= MNT_NOTAG;
19894 +                       break;
19895 +               case Opt_tagid:
19896 +                       if (tag && !match_int(args, &option))
19897 +                               *tag = option;
19898 +                       if (remove)
19899 +                               __dx_parse_remove(s, "tagid");
19900 +                       *mnt_flags |= MNT_TAGID;
19901 +                       set |= MNT_TAGID;
19902 +                       break;
19903 +#endif
19904 +               case Opt_notagcheck:
19905 +                       if (remove)
19906 +                               __dx_parse_remove(s, "notagcheck");
19907 +                       *flags |= MS_NOTAGCHECK;
19908 +                       set |= MS_NOTAGCHECK;
19909 +                       break;
19910 +               }
19911 +       }
19912 +       if (set)
19913 +               strcpy(string, s);
19914 +       kfree(s);
19915 +       return set;
19916 +}
19917 +
19918 +#ifdef CONFIG_PROPAGATE
19919 +
19920 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
19921 +{
19922 +       tag_t new_tag = 0;
19923 +       struct vfsmount *mnt;
19924 +       int propagate;
19925 +
19926 +       if (!nd)
19927 +               return;
19928 +       mnt = nd->path.mnt;
19929 +       if (!mnt)
19930 +               return;
19931 +
19932 +       propagate = (mnt->mnt_flags & MNT_TAGID);
19933 +       if (propagate)
19934 +               new_tag = mnt->mnt_tag;
19935 +
19936 +       vxdprintk(VXD_CBIT(tag, 7),
19937 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
19938 +               inode, inode->i_ino, inode->i_tag,
19939 +               new_tag, (propagate) ? 1 : 0);
19940 +
19941 +       if (propagate)
19942 +               inode->i_tag = new_tag;
19943 +}
19944 +
19945 +#include <linux/module.h>
19946 +
19947 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
19948 +
19949 +#endif /* CONFIG_PROPAGATE */
19950 +
19951 diff -NurpP --minimal linux-2.6.36/kernel/vserver/Kconfig linux-2.6.36-vs2.3.0.36.33/kernel/vserver/Kconfig
19952 --- linux-2.6.36/kernel/vserver/Kconfig 1970-01-01 01:00:00.000000000 +0100
19953 +++ linux-2.6.36-vs2.3.0.36.33/kernel/vserver/Kconfig   2010-10-21 13:09:36.000000000 +0200
19954 @@ -0,0 +1,260 @@
19955 +#
19956 +# Linux VServer configuration
19957 +#
19958 +
19959 +menu "Linux VServer"
19960 +
19961 +config VSERVER_AUTO_LBACK
19962 +       bool    "Automatically Assign Loopback IP"
19963 +       default y
19964 +       help
19965 +         Automatically assign a guest specific loopback
19966 +         IP and add it to the kernel network stack on
19967 +         startup.
19968 +
19969 +config VSERVER_AUTO_SINGLE
19970 +       bool    "Automatic Single IP Special Casing"
19971 +       depends on EXPERIMENTAL
19972 +       default y
19973 +       help
19974 +         This allows network contexts with a single IP to
19975 +         automatically remap 0.0.0.0 bindings to that IP,
19976 +         avoiding further network checks and improving
19977 +         performance.
19978 +
19979 +         (note: such guests do not allow to change the ip
19980 +          on the fly and do not show loopback addresses)
19981 +
19982 +config VSERVER_COWBL
19983 +       bool    "Enable COW Immutable Link Breaking"
19984 +       default y
19985 +       help
19986 +         This enables the COW (Copy-On-Write) link break code.
19987 +         It allows you to treat unified files like normal files
19988 +         when writing to them (which will implicitely break the
19989 +         link and create a copy of the unified file)
19990 +
19991 +config VSERVER_VTIME
19992 +       bool    "Enable Virtualized Guest Time"
19993 +       depends on EXPERIMENTAL
19994 +       default n
19995 +       help
19996 +         This enables per guest time offsets to allow for
19997 +         adjusting the system clock individually per guest.
19998 +         this adds some overhead to the time functions and
19999 +         therefore should not be enabled without good reason.
20000 +
20001 +config VSERVER_DEVICE
20002 +       bool    "Enable Guest Device Mapping"
20003 +       depends on EXPERIMENTAL
20004 +       default n
20005 +       help
20006 +         This enables generic device remapping.
20007 +
20008 +config VSERVER_PROC_SECURE
20009 +       bool    "Enable Proc Security"
20010 +       depends on PROC_FS
20011 +       default y
20012 +       help
20013 +         This configures ProcFS security to initially hide
20014 +         non-process entries for all contexts except the main and
20015 +         spectator context (i.e. for all guests), which is a secure
20016 +         default.
20017 +
20018 +         (note: on 1.2x the entries were visible by default)
20019 +
20020 +config VSERVER_HARDCPU
20021 +       bool    "Enable Hard CPU Limits"
20022 +       default y
20023 +       help
20024 +         Activate the Hard CPU Limits
20025 +
20026 +         This will compile in code that allows the Token Bucket
20027 +         Scheduler to put processes on hold when a context's
20028 +         tokens are depleted (provided that its per-context
20029 +         sched_hard flag is set).
20030 +
20031 +         Processes belonging to that context will not be able
20032 +         to consume CPU resources again until a per-context
20033 +         configured minimum of tokens has been reached.
20034 +
20035 +config VSERVER_IDLETIME
20036 +       bool    "Avoid idle CPUs by skipping Time"
20037 +       depends on VSERVER_HARDCPU
20038 +       default y
20039 +       help
20040 +         This option allows the scheduler to artificially
20041 +         advance time (per cpu) when otherwise the idle
20042 +         task would be scheduled, thus keeping the cpu
20043 +         busy and sharing the available resources among
20044 +         certain contexts.
20045 +
20046 +config VSERVER_IDLELIMIT
20047 +       bool    "Limit the IDLE task"
20048 +       depends on VSERVER_HARDCPU
20049 +       default n
20050 +       help
20051 +         Limit the idle slices, so the the next context
20052 +         will be scheduled as soon as possible.
20053 +
20054 +         This might improve interactivity and latency, but
20055 +         will also marginally increase scheduling overhead.
20056 +
20057 +choice
20058 +       prompt  "Persistent Inode Tagging"
20059 +       default TAGGING_ID24
20060 +       help
20061 +         This adds persistent context information to filesystems
20062 +         mounted with the tagxid option. Tagging is a requirement
20063 +         for per-context disk limits and per-context quota.
20064 +
20065 +
20066 +config TAGGING_NONE
20067 +       bool    "Disabled"
20068 +       help
20069 +         do not store per-context information in inodes.
20070 +
20071 +config TAGGING_UID16
20072 +       bool    "UID16/GID32"
20073 +       help
20074 +         reduces UID to 16 bit, but leaves GID at 32 bit.
20075 +
20076 +config TAGGING_GID16
20077 +       bool    "UID32/GID16"
20078 +       help
20079 +         reduces GID to 16 bit, but leaves UID at 32 bit.
20080 +
20081 +config TAGGING_ID24
20082 +       bool    "UID24/GID24"
20083 +       help
20084 +         uses the upper 8bit from UID and GID for XID tagging
20085 +         which leaves 24bit for UID/GID each, which should be
20086 +         more than sufficient for normal use.
20087 +
20088 +config TAGGING_INTERN
20089 +       bool    "UID32/GID32"
20090 +       help
20091 +         this uses otherwise reserved inode fields in the on
20092 +         disk representation, which limits the use to a few
20093 +         filesystems (currently ext2 and ext3)
20094 +
20095 +endchoice
20096 +
20097 +config TAG_NFSD
20098 +       bool    "Tag NFSD User Auth and Files"
20099 +       default n
20100 +       help
20101 +         Enable this if you do want the in-kernel NFS
20102 +         Server to use the tagging specified above.
20103 +         (will require patched clients too)
20104 +
20105 +config VSERVER_PRIVACY
20106 +       bool    "Honor Privacy Aspects of Guests"
20107 +       default n
20108 +       help
20109 +         When enabled, most context checks will disallow
20110 +         access to structures assigned to a specific context,
20111 +         like ptys or loop devices.
20112 +
20113 +config VSERVER_CONTEXTS
20114 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
20115 +       range 1 65533
20116 +       default "768"   if 64BIT
20117 +       default "256"
20118 +       help
20119 +         This setting will optimize certain data structures
20120 +         and memory allocations according to the expected
20121 +         maximum.
20122 +
20123 +         note: this is not a strict upper limit.
20124 +
20125 +config VSERVER_WARN
20126 +       bool    "VServer Warnings"
20127 +       default y
20128 +       help
20129 +         This enables various runtime warnings, which will
20130 +         notify about potential manipulation attempts or
20131 +         resource shortage. It is generally considered to
20132 +         be a good idea to have that enabled.
20133 +
20134 +config VSERVER_DEBUG
20135 +       bool    "VServer Debugging Code"
20136 +       default n
20137 +       help
20138 +         Set this to yes if you want to be able to activate
20139 +         debugging output at runtime. It adds a very small
20140 +         overhead to all vserver related functions and
20141 +         increases the kernel size by about 20k.
20142 +
20143 +config VSERVER_HISTORY
20144 +       bool    "VServer History Tracing"
20145 +       depends on VSERVER_DEBUG
20146 +       default n
20147 +       help
20148 +         Set this to yes if you want to record the history of
20149 +         linux-vserver activities, so they can be replayed in
20150 +         the event of a kernel panic or oops.
20151 +
20152 +config VSERVER_HISTORY_SIZE
20153 +       int     "Per-CPU History Size (32-65536)"
20154 +       depends on VSERVER_HISTORY
20155 +       range 32 65536
20156 +       default 64
20157 +       help
20158 +         This allows you to specify the number of entries in
20159 +         the per-CPU history buffer.
20160 +
20161 +config VSERVER_MONITOR
20162 +       bool    "VServer Scheduling Monitor"
20163 +       depends on VSERVER_DISABLED
20164 +       default n
20165 +       help
20166 +         Set this to yes if you want to record the scheduling
20167 +         decisions, so that they can be relayed to userspace
20168 +         for detailed analysis.
20169 +
20170 +config VSERVER_MONITOR_SIZE
20171 +       int     "Per-CPU Monitor Queue Size (32-65536)"
20172 +       depends on VSERVER_MONITOR
20173 +       range 32 65536
20174 +       default 1024
20175 +       help
20176 +         This allows you to specify the number of entries in
20177 +         the per-CPU scheduling monitor buffer.
20178 +
20179 +config VSERVER_MONITOR_SYNC
20180 +       int     "Per-CPU Monitor Sync Interval (0-65536)"
20181 +       depends on VSERVER_MONITOR
20182 +       range 0 65536
20183 +       default 256
20184 +       help
20185 +         This allows you to specify the interval in ticks
20186 +         when a time sync entry is inserted.
20187 +
20188 +config VSERVER_LEGACY_MEM
20189 +       bool    "Legacy Memory Limits"
20190 +       default n
20191 +       help
20192 +         This provides fake memory limits to keep
20193 +         older tools happy in the face of memory
20194 +         cgroups
20195 +
20196 +
20197 +endmenu
20198 +
20199 +
20200 +config VSERVER
20201 +       bool
20202 +       default y
20203 +       select NAMESPACES
20204 +       select UTS_NS
20205 +       select IPC_NS
20206 +       select USER_NS
20207 +       select SYSVIPC
20208 +
20209 +config VSERVER_SECURITY
20210 +       bool
20211 +       depends on SECURITY
20212 +       default y
20213 +       select SECURITY_CAPABILITIES
20214 +
20215 diff -NurpP --minimal linux-2.6.36/kernel/vserver/limit.c linux-2.6.36-vs2.3.0.36.33/kernel/vserver/limit.c
20216 --- linux-2.6.36/kernel/vserver/limit.c 1970-01-01 01:00:00.000000000 +0100
20217 +++ linux-2.6.36-vs2.3.0.36.33/kernel/vserver/limit.c   2010-10-21 13:09:36.000000000 +0200
20218 @@ -0,0 +1,354 @@
20219 +/*
20220 + *  linux/kernel/vserver/limit.c
20221 + *
20222 + *  Virtual Server: Context Limits
20223 + *
20224 + *  Copyright (C) 2004-2010  Herbert Pötzl
20225 + *
20226 + *  V0.01  broken out from vcontext V0.05
20227 + *  V0.02  changed vcmds to vxi arg
20228 + *  V0.03  added memory cgroup support
20229 + *
20230 + */
20231 +
20232 +#include <linux/sched.h>
20233 +#include <linux/module.h>
20234 +#include <linux/memcontrol.h>
20235 +#include <linux/res_counter.h>
20236 +#include <linux/vs_limit.h>
20237 +#include <linux/vserver/limit.h>
20238 +#include <linux/vserver/limit_cmd.h>
20239 +
20240 +#include <asm/uaccess.h>
20241 +
20242 +
20243 +const char *vlimit_name[NUM_LIMITS] = {
20244 +#ifdef CONFIG_VSERVER_LEGACY_MEM
20245 +       [RLIMIT_RSS]            = "RSS",
20246 +       [RLIMIT_AS]             = "VM",
20247 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
20248 +       [RLIMIT_CPU]            = "CPU",
20249 +       [RLIMIT_NPROC]          = "NPROC",
20250 +       [RLIMIT_NOFILE]         = "NOFILE",
20251 +       [RLIMIT_LOCKS]          = "LOCKS",
20252 +       [RLIMIT_SIGPENDING]     = "SIGP",
20253 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
20254 +
20255 +       [VLIMIT_NSOCK]          = "NSOCK",
20256 +       [VLIMIT_OPENFD]         = "OPENFD",
20257 +       [VLIMIT_SHMEM]          = "SHMEM",
20258 +       [VLIMIT_DENTRY]         = "DENTRY",
20259 +};
20260 +
20261 +EXPORT_SYMBOL_GPL(vlimit_name);
20262 +
20263 +#define MASK_ENTRY(x)  (1 << (x))
20264 +
20265 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
20266 +               /* minimum */
20267 +       0
20268 +       ,       /* softlimit */
20269 +#ifdef CONFIG_VSERVER_LEGACY_MEM
20270 +       MASK_ENTRY( RLIMIT_RSS          ) |
20271 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
20272 +       0
20273 +       ,       /* maximum */
20274 +#ifdef CONFIG_VSERVER_LEGACY_MEM
20275 +       MASK_ENTRY( RLIMIT_RSS          ) |
20276 +       MASK_ENTRY( RLIMIT_AS           ) |
20277 +#endif /* CONFIG_VSERVER_LEGACY_MEM */
20278 +       MASK_ENTRY( RLIMIT_NPROC        ) |
20279 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
20280 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
20281 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
20282 +
20283 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
20284 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
20285 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
20286 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
20287 +       0
20288 +};
20289 +               /* accounting only */
20290 +uint32_t account_mask =
20291 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
20292 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
20293 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
20294 +       0;
20295 +
20296 +
20297 +static int is_valid_vlimit(int id)
20298 +{
20299 +       uint32_t mask = vlimit_mask.minimum |
20300 +               vlimit_mask.softlimit | vlimit_mask.maximum;
20301 +       return mask & (1 << id);
20302 +}
20303 +
20304 +static int is_accounted_vlimit(int id)
20305 +{
20306 +       if (is_valid_vlimit(id))
20307 +               return 1;
20308 +       return account_mask & (1 << id);
20309 +}
20310 +
20311 +
20312 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
20313 +{
20314 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
20315 +       return VX_VLIM(limit);
20316 +}
20317 +
20318 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
20319 +{
20320 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
20321 +       return VX_VLIM(limit);
20322 +}
20323 +
20324 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
20325 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
20326 +{
20327 +       if (!is_valid_vlimit(id))
20328 +               return -EINVAL;
20329 +
20330 +       if (minimum)
20331 +               *minimum = CRLIM_UNSET;
20332 +       if (softlimit)
20333 +               *softlimit = vc_get_soft(vxi, id);
20334 +       if (maximum)
20335 +               *maximum = vc_get_hard(vxi, id);
20336 +       return 0;
20337 +}
20338 +
20339 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
20340 +{
20341 +       struct vcmd_ctx_rlimit_v0 vc_data;
20342 +       int ret;
20343 +
20344 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20345 +               return -EFAULT;
20346 +
20347 +       ret = do_get_rlimit(vxi, vc_data.id,
20348 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
20349 +       if (ret)
20350 +               return ret;
20351 +
20352 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20353 +               return -EFAULT;
20354 +       return 0;
20355 +}
20356 +
20357 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
20358 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
20359 +{
20360 +       if (!is_valid_vlimit(id))
20361 +               return -EINVAL;
20362 +
20363 +       if (maximum != CRLIM_KEEP)
20364 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
20365 +       if (softlimit != CRLIM_KEEP)
20366 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
20367 +
20368 +       /* clamp soft limit */
20369 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
20370 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
20371 +
20372 +       return 0;
20373 +}
20374 +
20375 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
20376 +{
20377 +       struct vcmd_ctx_rlimit_v0 vc_data;
20378 +
20379 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20380 +               return -EFAULT;
20381 +
20382 +       return do_set_rlimit(vxi, vc_data.id,
20383 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
20384 +}
20385 +
20386 +#ifdef CONFIG_IA32_EMULATION
20387 +
20388 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
20389 +{
20390 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
20391 +
20392 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20393 +               return -EFAULT;
20394 +
20395 +       return do_set_rlimit(vxi, vc_data.id,
20396 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
20397 +}
20398 +
20399 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
20400 +{
20401 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
20402 +       int ret;
20403 +
20404 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20405 +               return -EFAULT;
20406 +
20407 +       ret = do_get_rlimit(vxi, vc_data.id,
20408 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
20409 +       if (ret)
20410 +               return ret;
20411 +
20412 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20413 +               return -EFAULT;
20414 +       return 0;
20415 +}
20416 +
20417 +#endif /* CONFIG_IA32_EMULATION */
20418 +
20419 +
20420 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
20421 +{
20422 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
20423 +               return -EFAULT;
20424 +       return 0;
20425 +}
20426 +
20427 +
20428 +static inline void vx_reset_hits(struct _vx_limit *limit)
20429 +{
20430 +       int lim;
20431 +
20432 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20433 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20434 +       }
20435 +}
20436 +
20437 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
20438 +{
20439 +       vx_reset_hits(&vxi->limit);
20440 +       return 0;
20441 +}
20442 +
20443 +static inline void vx_reset_minmax(struct _vx_limit *limit)
20444 +{
20445 +       rlim_t value;
20446 +       int lim;
20447 +
20448 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20449 +               value = __rlim_get(limit, lim);
20450 +               __rlim_rmax(limit, lim) = value;
20451 +               __rlim_rmin(limit, lim) = value;
20452 +       }
20453 +}
20454 +
20455 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
20456 +{
20457 +       vx_reset_minmax(&vxi->limit);
20458 +       return 0;
20459 +}
20460 +
20461 +
20462 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
20463 +{
20464 +       struct vcmd_rlimit_stat_v0 vc_data;
20465 +       struct _vx_limit *limit = &vxi->limit;
20466 +       int id;
20467 +
20468 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20469 +               return -EFAULT;
20470 +
20471 +       id = vc_data.id;
20472 +       if (!is_accounted_vlimit(id))
20473 +               return -EINVAL;
20474 +
20475 +       vx_limit_fixup(limit, id);
20476 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
20477 +       vc_data.value = __rlim_get(limit, id);
20478 +       vc_data.minimum = __rlim_rmin(limit, id);
20479 +       vc_data.maximum = __rlim_rmax(limit, id);
20480 +
20481 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20482 +               return -EFAULT;
20483 +       return 0;
20484 +}
20485 +
20486 +
20487 +void vx_vsi_meminfo(struct sysinfo *val)
20488 +{
20489 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20490 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20491 +       u64 res_limit, res_usage;
20492 +
20493 +       if (!mcg)
20494 +               return;
20495 +
20496 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
20497 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
20498 +
20499 +       if (res_limit != RESOURCE_MAX)
20500 +               val->totalram = (res_limit >> PAGE_SHIFT);
20501 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
20502 +       val->bufferram = 0;
20503 +       val->totalhigh = 0;
20504 +       val->freehigh = 0;
20505 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
20506 +       return;
20507 +}
20508 +
20509 +void vx_vsi_swapinfo(struct sysinfo *val)
20510 +{
20511 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20512 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
20513 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20514 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
20515 +       s64 swap_limit, swap_usage;
20516 +
20517 +       if (!mcg)
20518 +               return;
20519 +
20520 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
20521 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
20522 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
20523 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
20524 +
20525 +       if (res_limit == RESOURCE_MAX)
20526 +               return;
20527 +
20528 +       swap_limit = memsw_limit - res_limit;
20529 +       if (memsw_limit != RESOURCE_MAX)
20530 +               val->totalswap = swap_limit >> PAGE_SHIFT;
20531 +
20532 +       swap_usage = memsw_usage - res_usage;
20533 +       val->freeswap = (swap_usage < swap_limit) ?
20534 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
20535 +#else  /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20536 +       val->totalswap = 0;
20537 +       val->freeswap = 0;
20538 +#endif /* !CONFIG_CGROUP_MEM_RES_CTLR_SWAP */
20539 +#endif /* CONFIG_CGROUP_MEM_RES_CTLR */
20540 +       return;
20541 +}
20542 +
20543 +long vx_vsi_cached(struct sysinfo *val)
20544 +{
20545 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
20546 +       struct mem_cgroup *mcg = mem_cgroup_from_task(current);
20547 +
20548 +       return mem_cgroup_stat_read_cache(mcg);
20549 +#else
20550 +       return 0;
20551 +#endif
20552 +}
20553 +
20554 +
20555 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
20556 +{
20557 +       struct vx_info *vxi = mm->mm_vx_info;
20558 +       unsigned long points;
20559 +       rlim_t v, w;
20560 +
20561 +       if (!vxi)
20562 +               return 0;
20563 +
20564 +       points = vxi->vx_badness_bias;
20565 +
20566 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
20567 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
20568 +       points += (v > w) ? (v - w) : 0;
20569 +
20570 +       return points;
20571 +}
20572 +
20573 diff -NurpP --minimal linux-2.6.36/kernel/vserver/limit_init.h linux-2.6.36-vs2.3.0.36.33/kernel/vserver/limit_init.h
20574 --- linux-2.6.36/kernel/vserver/limit_init.h    1970-01-01 01:00:00.000000000 +0100
20575 +++ linux-2.6.36-vs2.3.0.36.33/kernel/vserver/limit_init.h      2010-10-21 13:09:36.000000000 +0200
20576 @@ -0,0 +1,31 @@
20577 +
20578 +
20579 +static inline void vx_info_init_limit(struct _vx_limit *limit)
20580 +{
20581 +       int lim;
20582 +
20583 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20584 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
20585 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
20586 +               __rlim_set(limit, lim, 0);
20587 +               atomic_set(&__rlim_lhit(limit, lim), 0);
20588 +               __rlim_rmin(limit, lim) = 0;
20589 +               __rlim_rmax(limit, lim) = 0;
20590 +       }
20591 +}
20592 +
20593 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
20594 +{
20595 +       rlim_t value;
20596 +       int lim;
20597 +
20598 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
20599 +               if ((1 << lim) & VLIM_NOCHECK)
20600 +                       continue;
20601 +               value = __rlim_get(limit, lim);
20602 +               vxwprintk_xid(value,
20603 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
20604 +                       limit, vlimit_name[lim], lim, (long)value);
20605 +       }
20606 +}
20607 +
20608 diff -NurpP --minimal linux-2.6.36/kernel/vserver/limit_proc.h linux-2.6.36-vs2.3.0.36.33/kernel/vserver/limit_proc.h
20609 --- linux-2.6.36/kernel/vserver/limit_proc.h    1970-01-01 01:00:00.000000000 +0100
20610 +++ linux-2.6.36-vs2.3.0.36.33/kernel/vserver/limit_proc.h      2010-10-21 13:09:36.000000000 +0200
20611 @@ -0,0 +1,57 @@
20612 +#ifndef _VX_LIMIT_PROC_H
20613 +#define _VX_LIMIT_PROC_H
20614 +
20615 +#include <linux/vserver/limit_int.h>
20616 +
20617 +
20618 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
20619 +#define VX_LIMIT_TOP   \
20620 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
20621 +
20622 +#define VX_LIMIT_ARG(r)                                \
20623 +       (unsigned long)__rlim_get(limit, r),    \
20624 +       (unsigned long)__rlim_rmin(limit, r),   \
20625 +       (unsigned long)__rlim_rmax(limit, r),   \
20626 +       VX_VLIM(__rlim_soft(limit, r)),         \
20627 +       VX_VLIM(__rlim_hard(limit, r)),         \
20628 +       atomic_read(&__rlim_lhit(limit, r))
20629 +
20630 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
20631 +{
20632 +       vx_limit_fixup(limit, -1);
20633 +       return sprintf(buffer, VX_LIMIT_TOP
20634 +               "PROC"  VX_LIMIT_FMT
20635 +               "VM"    VX_LIMIT_FMT
20636 +               "VML"   VX_LIMIT_FMT
20637 +               "RSS"   VX_LIMIT_FMT
20638 +               "ANON"  VX_LIMIT_FMT
20639 +               "RMAP"  VX_LIMIT_FMT
20640 +               "FILES" VX_LIMIT_FMT
20641 +               "OFD"   VX_LIMIT_FMT
20642 +               "LOCKS" VX_LIMIT_FMT
20643 +               "SOCK"  VX_LIMIT_FMT
20644 +               "MSGQ"  VX_LIMIT_FMT
20645 +               "SHM"   VX_LIMIT_FMT
20646 +               "SEMA"  VX_LIMIT_FMT
20647 +               "SEMS"  VX_LIMIT_FMT
20648 +               "DENT"  VX_LIMIT_FMT,
20649 +               VX_LIMIT_ARG(RLIMIT_NPROC),
20650 +               VX_LIMIT_ARG(RLIMIT_AS),
20651 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
20652 +               VX_LIMIT_ARG(RLIMIT_RSS),
20653 +               VX_LIMIT_ARG(VLIMIT_ANON),
20654 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
20655 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
20656 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
20657 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
20658 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
20659 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
20660 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
20661 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
20662 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
20663 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
20664 +}
20665 +
20666 +#endif /* _VX_LIMIT_PROC_H */
20667 +
20668 +
20669 diff -NurpP --minimal linux-2.6.36/kernel/vserver/Makefile linux-2.6.36-vs2.3.0.36.33/kernel/vserver/Makefile
20670 --- linux-2.6.36/kernel/vserver/Makefile        1970-01-01 01:00:00.000000000 +0100
20671 +++ linux-2.6.36-vs2.3.0.36.33/kernel/vserver/Makefile  2010-10-21 13:09:36.000000000 +0200
20672 @@ -0,0 +1,18 @@
20673 +#
20674 +# Makefile for the Linux vserver routines.
20675 +#
20676 +
20677 +
20678 +obj-y          += vserver.o
20679 +
20680 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
20681 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
20682 +                  dlimit.o tag.o
20683 +
20684 +vserver-$(CONFIG_INET) += inet.o
20685 +vserver-$(CONFIG_PROC_FS) += proc.o
20686 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
20687 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
20688 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
20689 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
20690 +
20691 diff -NurpP --minimal linux-2.6.36/kernel/vserver/monitor.c linux-2.6.36-vs2.3.0.36.33/kernel/vserver/monitor.c
20692 --- linux-2.6.36/kernel/vserver/monitor.c       1970-01-01 01:00:00.000000000 +0100
20693 +++ linux-2.6.36-vs2.3.0.36.33/kernel/vserver/monitor.c 2010-10-21 13:09:36.000000000 +0200
20694 @@ -0,0 +1,138 @@
20695 +/*
20696 + *  kernel/vserver/monitor.c
20697 + *
20698 + *  Virtual Context Scheduler Monitor
20699 + *
20700 + *  Copyright (C) 2006-2007 Herbert Pötzl
20701 + *
20702 + *  V0.01  basic design
20703 + *
20704 + */
20705 +
20706 +#include <linux/module.h>
20707 +#include <linux/jiffies.h>
20708 +#include <asm/uaccess.h>
20709 +#include <asm/atomic.h>
20710 +
20711 +#include <linux/vserver/monitor.h>
20712 +#include <linux/vserver/debug_cmd.h>
20713 +
20714 +
20715 +#ifdef CONFIG_VSERVER_MONITOR
20716 +#define VXM_SIZE       CONFIG_VSERVER_MONITOR_SIZE
20717 +#else
20718 +#define VXM_SIZE       64
20719 +#endif
20720 +
20721 +struct _vx_monitor {
20722 +       unsigned int counter;
20723 +
20724 +       struct _vx_mon_entry entry[VXM_SIZE+1];
20725 +};
20726 +
20727 +
20728 +DEFINE_PER_CPU(struct _vx_monitor, vx_monitor_buffer);
20729 +
20730 +unsigned volatile int vxm_active = 1;
20731 +
20732 +static atomic_t sequence = ATOMIC_INIT(0);
20733 +
20734 +
20735 +/*     vxm_advance()
20736 +
20737 +       * requires disabled preemption                          */
20738 +
20739 +struct _vx_mon_entry *vxm_advance(int cpu)
20740 +{
20741 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
20742 +       struct _vx_mon_entry *entry;
20743 +       unsigned int index;
20744 +
20745 +       index = vxm_active ? (mon->counter++ % VXM_SIZE) : VXM_SIZE;
20746 +       entry = &mon->entry[index];
20747 +
20748 +       entry->ev.seq = atomic_inc_return(&sequence);
20749 +       entry->ev.jif = jiffies;
20750 +       return entry;
20751 +}
20752 +
20753 +EXPORT_SYMBOL_GPL(vxm_advance);
20754 +
20755 +
20756 +int do_read_monitor(struct __user _vx_mon_entry *data,
20757 +       int cpu, uint32_t *index, uint32_t *count)
20758 +{
20759 +       int pos, ret = 0;
20760 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
20761 +       int end = mon->counter;
20762 +       int start = end - VXM_SIZE + 2;
20763 +       int idx = *index;
20764 +
20765 +       /* special case: get current pos */
20766 +       if (!*count) {
20767 +               *index = end;
20768 +               return 0;
20769 +       }
20770 +
20771 +       /* have we lost some data? */
20772 +       if (idx < start)
20773 +               idx = start;
20774 +
20775 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
20776 +               struct _vx_mon_entry *entry =
20777 +                       &mon->entry[idx % VXM_SIZE];
20778 +
20779 +               /* send entry to userspace */
20780 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
20781 +               if (ret)
20782 +                       break;
20783 +       }
20784 +       /* save new index and count */
20785 +       *index = idx;
20786 +       *count = pos;
20787 +       return ret ? ret : (*index < end);
20788 +}
20789 +
20790 +int vc_read_monitor(uint32_t id, void __user *data)
20791 +{
20792 +       struct vcmd_read_monitor_v0 vc_data;
20793 +       int ret;
20794 +
20795 +       if (id >= NR_CPUS)
20796 +               return -EINVAL;
20797 +
20798 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20799 +               return -EFAULT;
20800 +
20801 +       ret = do_read_monitor((struct __user _vx_mon_entry *)vc_data.data,
20802 +               id, &vc_data.index, &vc_data.count);
20803 +
20804 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20805 +               return -EFAULT;
20806 +       return ret;
20807 +}
20808 +
20809 +#ifdef CONFIG_COMPAT
20810 +
20811 +int vc_read_monitor_x32(uint32_t id, void __user *data)
20812 +{
20813 +       struct vcmd_read_monitor_v0_x32 vc_data;
20814 +       int ret;
20815 +
20816 +       if (id >= NR_CPUS)
20817 +               return -EINVAL;
20818 +
20819 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20820 +               return -EFAULT;
20821 +
20822 +       ret = do_read_monitor((struct __user _vx_mon_entry *)
20823 +               compat_ptr(vc_data.data_ptr),
20824 +               id, &vc_data.index, &vc_data.count);
20825 +
20826 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20827 +               return -EFAULT;
20828 +       return ret;
20829 +}
20830 +
20831 +#endif /* CONFIG_COMPAT */
20832 +
20833 diff -NurpP --minimal linux-2.6.36/kernel/vserver/network.c linux-2.6.36-vs2.3.0.36.33/kernel/vserver/network.c
20834 --- linux-2.6.36/kernel/vserver/network.c       1970-01-01 01:00:00.000000000 +0100
20835 +++ linux-2.6.36-vs2.3.0.36.33/kernel/vserver/network.c 2010-10-21 13:09:36.000000000 +0200
20836 @@ -0,0 +1,864 @@
20837 +/*
20838 + *  linux/kernel/vserver/network.c
20839 + *
20840 + *  Virtual Server: Network Support
20841 + *
20842 + *  Copyright (C) 2003-2007  Herbert Pötzl
20843 + *
20844 + *  V0.01  broken out from vcontext V0.05
20845 + *  V0.02  cleaned up implementation
20846 + *  V0.03  added equiv nx commands
20847 + *  V0.04  switch to RCU based hash
20848 + *  V0.05  and back to locking again
20849 + *  V0.06  changed vcmds to nxi arg
20850 + *  V0.07  have __create claim() the nxi
20851 + *
20852 + */
20853 +
20854 +#include <linux/err.h>
20855 +#include <linux/slab.h>
20856 +#include <linux/rcupdate.h>
20857 +
20858 +#include <linux/vs_network.h>
20859 +#include <linux/vs_pid.h>
20860 +#include <linux/vserver/network_cmd.h>
20861 +
20862 +
20863 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
20864 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
20865 +
20866 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
20867 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
20868 +
20869 +
20870 +static int __init init_network(void)
20871 +{
20872 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
20873 +               sizeof(struct nx_addr_v4), 0,
20874 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20875 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
20876 +               sizeof(struct nx_addr_v6), 0,
20877 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
20878 +       return 0;
20879 +}
20880 +
20881 +
20882 +/*     __alloc_nx_addr_v4()                                    */
20883 +
20884 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
20885 +{
20886 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
20887 +               nx_addr_v4_cachep, GFP_KERNEL);
20888 +
20889 +       if (!IS_ERR(nxa))
20890 +               memset(nxa, 0, sizeof(*nxa));
20891 +       return nxa;
20892 +}
20893 +
20894 +/*     __dealloc_nx_addr_v4()                                  */
20895 +
20896 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
20897 +{
20898 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
20899 +}
20900 +
20901 +/*     __dealloc_nx_addr_v4_all()                              */
20902 +
20903 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
20904 +{
20905 +       while (nxa) {
20906 +               struct nx_addr_v4 *next = nxa->next;
20907 +
20908 +               __dealloc_nx_addr_v4(nxa);
20909 +               nxa = next;
20910 +       }
20911 +}
20912 +
20913 +
20914 +#ifdef CONFIG_IPV6
20915 +
20916 +/*     __alloc_nx_addr_v6()                                    */
20917 +
20918 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
20919 +{
20920 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
20921 +               nx_addr_v6_cachep, GFP_KERNEL);
20922 +
20923 +       if (!IS_ERR(nxa))
20924 +               memset(nxa, 0, sizeof(*nxa));
20925 +       return nxa;
20926 +}
20927 +
20928 +/*     __dealloc_nx_addr_v6()                                  */
20929 +
20930 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
20931 +{
20932 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
20933 +}
20934 +
20935 +/*     __dealloc_nx_addr_v6_all()                              */
20936 +
20937 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
20938 +{
20939 +       while (nxa) {
20940 +               struct nx_addr_v6 *next = nxa->next;
20941 +
20942 +               __dealloc_nx_addr_v6(nxa);
20943 +               nxa = next;
20944 +       }
20945 +}
20946 +
20947 +#endif /* CONFIG_IPV6 */
20948 +
20949 +/*     __alloc_nx_info()
20950 +
20951 +       * allocate an initialized nx_info struct
20952 +       * doesn't make it visible (hash)                        */
20953 +
20954 +static struct nx_info *__alloc_nx_info(nid_t nid)
20955 +{
20956 +       struct nx_info *new = NULL;
20957 +
20958 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
20959 +
20960 +       /* would this benefit from a slab cache? */
20961 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
20962 +       if (!new)
20963 +               return 0;
20964 +
20965 +       memset(new, 0, sizeof(struct nx_info));
20966 +       new->nx_id = nid;
20967 +       INIT_HLIST_NODE(&new->nx_hlist);
20968 +       atomic_set(&new->nx_usecnt, 0);
20969 +       atomic_set(&new->nx_tasks, 0);
20970 +       new->nx_state = 0;
20971 +
20972 +       new->nx_flags = NXF_INIT_SET;
20973 +
20974 +       /* rest of init goes here */
20975 +
20976 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
20977 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
20978 +
20979 +       vxdprintk(VXD_CBIT(nid, 0),
20980 +               "alloc_nx_info(%d) = %p", nid, new);
20981 +       atomic_inc(&nx_global_ctotal);
20982 +       return new;
20983 +}
20984 +
20985 +/*     __dealloc_nx_info()
20986 +
20987 +       * final disposal of nx_info                             */
20988 +
20989 +static void __dealloc_nx_info(struct nx_info *nxi)
20990 +{
20991 +       vxdprintk(VXD_CBIT(nid, 0),
20992 +               "dealloc_nx_info(%p)", nxi);
20993 +
20994 +       nxi->nx_hlist.next = LIST_POISON1;
20995 +       nxi->nx_id = -1;
20996 +
20997 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20998 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20999 +
21000 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
21001 +
21002 +       nxi->nx_state |= NXS_RELEASED;
21003 +       kfree(nxi);
21004 +       atomic_dec(&nx_global_ctotal);
21005 +}
21006 +
21007 +static void __shutdown_nx_info(struct nx_info *nxi)
21008 +{
21009 +       nxi->nx_state |= NXS_SHUTDOWN;
21010 +       vs_net_change(nxi, VSC_NETDOWN);
21011 +}
21012 +
21013 +/*     exported stuff                                          */
21014 +
21015 +void free_nx_info(struct nx_info *nxi)
21016 +{
21017 +       /* context shutdown is mandatory */
21018 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
21019 +
21020 +       /* context must not be hashed */
21021 +       BUG_ON(nxi->nx_state & NXS_HASHED);
21022 +
21023 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
21024 +       BUG_ON(atomic_read(&nxi->nx_tasks));
21025 +
21026 +       __dealloc_nx_info(nxi);
21027 +}
21028 +
21029 +
21030 +void __nx_set_lback(struct nx_info *nxi)
21031 +{
21032 +       int nid = nxi->nx_id;
21033 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
21034 +
21035 +       nxi->v4_lback.s_addr = lback;
21036 +}
21037 +
21038 +extern int __nx_inet_add_lback(__be32 addr);
21039 +extern int __nx_inet_del_lback(__be32 addr);
21040 +
21041 +
21042 +/*     hash table for nx_info hash */
21043 +
21044 +#define NX_HASH_SIZE   13
21045 +
21046 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
21047 +
21048 +static spinlock_t nx_info_hash_lock = SPIN_LOCK_UNLOCKED;
21049 +
21050 +
21051 +static inline unsigned int __hashval(nid_t nid)
21052 +{
21053 +       return (nid % NX_HASH_SIZE);
21054 +}
21055 +
21056 +
21057 +
21058 +/*     __hash_nx_info()
21059 +
21060 +       * add the nxi to the global hash table
21061 +       * requires the hash_lock to be held                     */
21062 +
21063 +static inline void __hash_nx_info(struct nx_info *nxi)
21064 +{
21065 +       struct hlist_head *head;
21066 +
21067 +       vxd_assert_lock(&nx_info_hash_lock);
21068 +       vxdprintk(VXD_CBIT(nid, 4),
21069 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
21070 +
21071 +       /* context must not be hashed */
21072 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
21073 +
21074 +       nxi->nx_state |= NXS_HASHED;
21075 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
21076 +       hlist_add_head(&nxi->nx_hlist, head);
21077 +       atomic_inc(&nx_global_cactive);
21078 +}
21079 +
21080 +/*     __unhash_nx_info()
21081 +
21082 +       * remove the nxi from the global hash table
21083 +       * requires the hash_lock to be held                     */
21084 +
21085 +static inline void __unhash_nx_info(struct nx_info *nxi)
21086 +{
21087 +       vxd_assert_lock(&nx_info_hash_lock);
21088 +       vxdprintk(VXD_CBIT(nid, 4),
21089 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
21090 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
21091 +
21092 +       /* context must be hashed */
21093 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
21094 +       /* but without tasks */
21095 +       BUG_ON(atomic_read(&nxi->nx_tasks));
21096 +
21097 +       nxi->nx_state &= ~NXS_HASHED;
21098 +       hlist_del(&nxi->nx_hlist);
21099 +       atomic_dec(&nx_global_cactive);
21100 +}
21101 +
21102 +
21103 +/*     __lookup_nx_info()
21104 +
21105 +       * requires the hash_lock to be held
21106 +       * doesn't increment the nx_refcnt                       */
21107 +
21108 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
21109 +{
21110 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
21111 +       struct hlist_node *pos;
21112 +       struct nx_info *nxi;
21113 +
21114 +       vxd_assert_lock(&nx_info_hash_lock);
21115 +       hlist_for_each(pos, head) {
21116 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
21117 +
21118 +               if (nxi->nx_id == nid)
21119 +                       goto found;
21120 +       }
21121 +       nxi = NULL;
21122 +found:
21123 +       vxdprintk(VXD_CBIT(nid, 0),
21124 +               "__lookup_nx_info(#%u): %p[#%u]",
21125 +               nid, nxi, nxi ? nxi->nx_id : 0);
21126 +       return nxi;
21127 +}
21128 +
21129 +
21130 +/*     __create_nx_info()
21131 +
21132 +       * create the requested context
21133 +       * get(), claim() and hash it                            */
21134 +
21135 +static struct nx_info *__create_nx_info(int id)
21136 +{
21137 +       struct nx_info *new, *nxi = NULL;
21138 +
21139 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
21140 +
21141 +       if (!(new = __alloc_nx_info(id)))
21142 +               return ERR_PTR(-ENOMEM);
21143 +
21144 +       /* required to make dynamic xids unique */
21145 +       spin_lock(&nx_info_hash_lock);
21146 +
21147 +       /* static context requested */
21148 +       if ((nxi = __lookup_nx_info(id))) {
21149 +               vxdprintk(VXD_CBIT(nid, 0),
21150 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
21151 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
21152 +                       nxi = ERR_PTR(-EBUSY);
21153 +               else
21154 +                       nxi = ERR_PTR(-EEXIST);
21155 +               goto out_unlock;
21156 +       }
21157 +       /* new context */
21158 +       vxdprintk(VXD_CBIT(nid, 0),
21159 +               "create_nx_info(%d) = %p (new)", id, new);
21160 +       claim_nx_info(new, NULL);
21161 +       __nx_set_lback(new);
21162 +       __hash_nx_info(get_nx_info(new));
21163 +       nxi = new, new = NULL;
21164 +
21165 +out_unlock:
21166 +       spin_unlock(&nx_info_hash_lock);
21167 +       if (new)
21168 +               __dealloc_nx_info(new);
21169 +       return nxi;
21170 +}
21171 +
21172 +
21173 +
21174 +/*     exported stuff                                          */
21175 +
21176 +
21177 +void unhash_nx_info(struct nx_info *nxi)
21178 +{
21179 +       __shutdown_nx_info(nxi);
21180 +       spin_lock(&nx_info_hash_lock);
21181 +       __unhash_nx_info(nxi);
21182 +       spin_unlock(&nx_info_hash_lock);
21183 +}
21184 +
21185 +/*     lookup_nx_info()
21186 +
21187 +       * search for a nx_info and get() it
21188 +       * negative id means current                             */
21189 +
21190 +struct nx_info *lookup_nx_info(int id)
21191 +{
21192 +       struct nx_info *nxi = NULL;
21193 +
21194 +       if (id < 0) {
21195 +               nxi = get_nx_info(current_nx_info());
21196 +       } else if (id > 1) {
21197 +               spin_lock(&nx_info_hash_lock);
21198 +               nxi = get_nx_info(__lookup_nx_info(id));
21199 +               spin_unlock(&nx_info_hash_lock);
21200 +       }
21201 +       return nxi;
21202 +}
21203 +
21204 +/*     nid_is_hashed()
21205 +
21206 +       * verify that nid is still hashed                       */
21207 +
21208 +int nid_is_hashed(nid_t nid)
21209 +{
21210 +       int hashed;
21211 +
21212 +       spin_lock(&nx_info_hash_lock);
21213 +       hashed = (__lookup_nx_info(nid) != NULL);
21214 +       spin_unlock(&nx_info_hash_lock);
21215 +       return hashed;
21216 +}
21217 +
21218 +
21219 +#ifdef CONFIG_PROC_FS
21220 +
21221 +/*     get_nid_list()
21222 +
21223 +       * get a subset of hashed nids for proc
21224 +       * assumes size is at least one                          */
21225 +
21226 +int get_nid_list(int index, unsigned int *nids, int size)
21227 +{
21228 +       int hindex, nr_nids = 0;
21229 +
21230 +       /* only show current and children */
21231 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
21232 +               if (index > 0)
21233 +                       return 0;
21234 +               nids[nr_nids] = nx_current_nid();
21235 +               return 1;
21236 +       }
21237 +
21238 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
21239 +               struct hlist_head *head = &nx_info_hash[hindex];
21240 +               struct hlist_node *pos;
21241 +
21242 +               spin_lock(&nx_info_hash_lock);
21243 +               hlist_for_each(pos, head) {
21244 +                       struct nx_info *nxi;
21245 +
21246 +                       if (--index > 0)
21247 +                               continue;
21248 +
21249 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
21250 +                       nids[nr_nids] = nxi->nx_id;
21251 +                       if (++nr_nids >= size) {
21252 +                               spin_unlock(&nx_info_hash_lock);
21253 +                               goto out;
21254 +                       }
21255 +               }
21256 +               /* keep the lock time short */
21257 +               spin_unlock(&nx_info_hash_lock);
21258 +       }
21259 +out:
21260 +       return nr_nids;
21261 +}
21262 +#endif
21263 +
21264 +
21265 +/*
21266 + *     migrate task to new network
21267 + *     gets nxi, puts old_nxi on change
21268 + */
21269 +
21270 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
21271 +{
21272 +       struct nx_info *old_nxi;
21273 +       int ret = 0;
21274 +
21275 +       if (!p || !nxi)
21276 +               BUG();
21277 +
21278 +       vxdprintk(VXD_CBIT(nid, 5),
21279 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
21280 +               p, nxi, nxi->nx_id,
21281 +               atomic_read(&nxi->nx_usecnt),
21282 +               atomic_read(&nxi->nx_tasks));
21283 +
21284 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
21285 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
21286 +               return -EACCES;
21287 +
21288 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
21289 +               return -EFAULT;
21290 +
21291 +       /* maybe disallow this completely? */
21292 +       old_nxi = task_get_nx_info(p);
21293 +       if (old_nxi == nxi)
21294 +               goto out;
21295 +
21296 +       task_lock(p);
21297 +       if (old_nxi)
21298 +               clr_nx_info(&p->nx_info);
21299 +       claim_nx_info(nxi, p);
21300 +       set_nx_info(&p->nx_info, nxi);
21301 +       p->nid = nxi->nx_id;
21302 +       task_unlock(p);
21303 +
21304 +       vxdprintk(VXD_CBIT(nid, 5),
21305 +               "moved task %p into nxi:%p[#%d]",
21306 +               p, nxi, nxi->nx_id);
21307 +
21308 +       if (old_nxi)
21309 +               release_nx_info(old_nxi, p);
21310 +       ret = 0;
21311 +out:
21312 +       put_nx_info(old_nxi);
21313 +       return ret;
21314 +}
21315 +
21316 +
21317 +void nx_set_persistent(struct nx_info *nxi)
21318 +{
21319 +       vxdprintk(VXD_CBIT(nid, 6),
21320 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
21321 +
21322 +       get_nx_info(nxi);
21323 +       claim_nx_info(nxi, NULL);
21324 +}
21325 +
21326 +void nx_clear_persistent(struct nx_info *nxi)
21327 +{
21328 +       vxdprintk(VXD_CBIT(nid, 6),
21329 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
21330 +
21331 +       release_nx_info(nxi, NULL);
21332 +       put_nx_info(nxi);
21333 +}
21334 +
21335 +void nx_update_persistent(struct nx_info *nxi)
21336 +{
21337 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
21338 +               nx_set_persistent(nxi);
21339 +       else
21340 +               nx_clear_persistent(nxi);
21341 +}
21342 +
21343 +/* vserver syscall commands below here */
21344 +
21345 +/* taks nid and nx_info functions */
21346 +
21347 +#include <asm/uaccess.h>
21348 +
21349 +
21350 +int vc_task_nid(uint32_t id)
21351 +{
21352 +       nid_t nid;
21353 +
21354 +       if (id) {
21355 +               struct task_struct *tsk;
21356 +
21357 +               read_lock(&tasklist_lock);
21358 +               tsk = find_task_by_real_pid(id);
21359 +               nid = (tsk) ? tsk->nid : -ESRCH;
21360 +               read_unlock(&tasklist_lock);
21361 +       } else
21362 +               nid = nx_current_nid();
21363 +       return nid;
21364 +}
21365 +
21366 +
21367 +int vc_nx_info(struct nx_info *nxi, void __user *data)
21368 +{
21369 +       struct vcmd_nx_info_v0 vc_data;
21370 +
21371 +       vc_data.nid = nxi->nx_id;
21372 +
21373 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21374 +               return -EFAULT;
21375 +       return 0;
21376 +}
21377 +
21378 +
21379 +/* network functions */
21380 +
21381 +int vc_net_create(uint32_t nid, void __user *data)
21382 +{
21383 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
21384 +       struct nx_info *new_nxi;
21385 +       int ret;
21386 +
21387 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21388 +               return -EFAULT;
21389 +
21390 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
21391 +               return -EINVAL;
21392 +
21393 +       new_nxi = __create_nx_info(nid);
21394 +       if (IS_ERR(new_nxi))
21395 +               return PTR_ERR(new_nxi);
21396 +
21397 +       /* initial flags */
21398 +       new_nxi->nx_flags = vc_data.flagword;
21399 +
21400 +       ret = -ENOEXEC;
21401 +       if (vs_net_change(new_nxi, VSC_NETUP))
21402 +               goto out;
21403 +
21404 +       ret = nx_migrate_task(current, new_nxi);
21405 +       if (ret)
21406 +               goto out;
21407 +
21408 +       /* return context id on success */
21409 +       ret = new_nxi->nx_id;
21410 +
21411 +       /* get a reference for persistent contexts */
21412 +       if ((vc_data.flagword & NXF_PERSISTENT))
21413 +               nx_set_persistent(new_nxi);
21414 +out:
21415 +       release_nx_info(new_nxi, NULL);
21416 +       put_nx_info(new_nxi);
21417 +       return ret;
21418 +}
21419 +
21420 +
21421 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
21422 +{
21423 +       return nx_migrate_task(current, nxi);
21424 +}
21425 +
21426 +
21427 +
21428 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
21429 +       uint16_t type, uint16_t flags)
21430 +{
21431 +       struct nx_addr_v4 *nxa = &nxi->v4;
21432 +
21433 +       if (NX_IPV4(nxi)) {
21434 +               /* locate last entry */
21435 +               for (; nxa->next; nxa = nxa->next);
21436 +               nxa->next = __alloc_nx_addr_v4();
21437 +               nxa = nxa->next;
21438 +
21439 +               if (IS_ERR(nxa))
21440 +                       return PTR_ERR(nxa);
21441 +       }
21442 +
21443 +       if (nxi->v4.next)
21444 +               /* remove single ip for ip list */
21445 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
21446 +
21447 +       nxa->ip[0].s_addr = ip;
21448 +       nxa->ip[1].s_addr = ip2;
21449 +       nxa->mask.s_addr = mask;
21450 +       nxa->type = type;
21451 +       nxa->flags = flags;
21452 +       return 0;
21453 +}
21454 +
21455 +
21456 +int vc_net_add(struct nx_info *nxi, void __user *data)
21457 +{
21458 +       struct vcmd_net_addr_v0 vc_data;
21459 +       int index, ret = 0;
21460 +
21461 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21462 +               return -EFAULT;
21463 +
21464 +       switch (vc_data.type) {
21465 +       case NXA_TYPE_IPV4:
21466 +               if ((vc_data.count < 1) || (vc_data.count > 4))
21467 +                       return -EINVAL;
21468 +
21469 +               index = 0;
21470 +               while (index < vc_data.count) {
21471 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
21472 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
21473 +                       if (ret)
21474 +                               return ret;
21475 +                       index++;
21476 +               }
21477 +               ret = index;
21478 +               break;
21479 +
21480 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
21481 +               nxi->v4_bcast = vc_data.ip[0];
21482 +               ret = 1;
21483 +               break;
21484 +
21485 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
21486 +               nxi->v4_lback = vc_data.ip[0];
21487 +               ret = 1;
21488 +               break;
21489 +
21490 +       default:
21491 +               ret = -EINVAL;
21492 +               break;
21493 +       }
21494 +       return ret;
21495 +}
21496 +
21497 +int vc_net_remove(struct nx_info *nxi, void __user *data)
21498 +{
21499 +       struct vcmd_net_addr_v0 vc_data;
21500 +
21501 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21502 +               return -EFAULT;
21503 +
21504 +       switch (vc_data.type) {
21505 +       case NXA_TYPE_ANY:
21506 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
21507 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
21508 +               break;
21509 +
21510 +       default:
21511 +               return -EINVAL;
21512 +       }
21513 +       return 0;
21514 +}
21515 +
21516 +
21517 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
21518 +{
21519 +       struct vcmd_net_addr_ipv4_v1 vc_data;
21520 +
21521 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21522 +               return -EFAULT;
21523 +
21524 +       switch (vc_data.type) {
21525 +       case NXA_TYPE_ADDR:
21526 +       case NXA_TYPE_RANGE:
21527 +       case NXA_TYPE_MASK:
21528 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
21529 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
21530 +
21531 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
21532 +               nxi->v4_bcast = vc_data.ip;
21533 +               break;
21534 +
21535 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
21536 +               nxi->v4_lback = vc_data.ip;
21537 +               break;
21538 +
21539 +       default:
21540 +               return -EINVAL;
21541 +       }
21542 +       return 0;
21543 +}
21544 +
21545 +int vc_net_remove_ipv4(struct nx_info *nxi, void __user *data)
21546 +{
21547 +       struct vcmd_net_addr_ipv4_v1 vc_data;
21548 +
21549 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21550 +               return -EFAULT;
21551 +
21552 +       switch (vc_data.type) {
21553 +/*     case NXA_TYPE_ADDR:
21554 +               break;          */
21555 +
21556 +       case NXA_TYPE_ANY:
21557 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
21558 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
21559 +               break;
21560 +
21561 +       default:
21562 +               return -EINVAL;
21563 +       }
21564 +       return 0;
21565 +}
21566 +
21567 +
21568 +#ifdef CONFIG_IPV6
21569 +
21570 +int do_add_v6_addr(struct nx_info *nxi,
21571 +       struct in6_addr *ip, struct in6_addr *mask,
21572 +       uint32_t prefix, uint16_t type, uint16_t flags)
21573 +{
21574 +       struct nx_addr_v6 *nxa = &nxi->v6;
21575 +
21576 +       if (NX_IPV6(nxi)) {
21577 +               /* locate last entry */
21578 +               for (; nxa->next; nxa = nxa->next);
21579 +               nxa->next = __alloc_nx_addr_v6();
21580 +               nxa = nxa->next;
21581 +
21582 +               if (IS_ERR(nxa))
21583 +                       return PTR_ERR(nxa);
21584 +       }
21585 +
21586 +       nxa->ip = *ip;
21587 +       nxa->mask = *mask;
21588 +       nxa->prefix = prefix;
21589 +       nxa->type = type;
21590 +       nxa->flags = flags;
21591 +       return 0;
21592 +}
21593 +
21594 +
21595 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
21596 +{
21597 +       struct vcmd_net_addr_ipv6_v1 vc_data;
21598 +
21599 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21600 +               return -EFAULT;
21601 +
21602 +       switch (vc_data.type) {
21603 +       case NXA_TYPE_ADDR:
21604 +       case NXA_TYPE_MASK:
21605 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
21606 +                       vc_data.prefix, vc_data.type, vc_data.flags);
21607 +       default:
21608 +               return -EINVAL;
21609 +       }
21610 +       return 0;
21611 +}
21612 +
21613 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
21614 +{
21615 +       struct vcmd_net_addr_ipv6_v1 vc_data;
21616 +
21617 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21618 +               return -EFAULT;
21619 +
21620 +       switch (vc_data.type) {
21621 +       case NXA_TYPE_ANY:
21622 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
21623 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
21624 +               break;
21625 +
21626 +       default:
21627 +               return -EINVAL;
21628 +       }
21629 +       return 0;
21630 +}
21631 +
21632 +#endif /* CONFIG_IPV6 */
21633 +
21634 +
21635 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
21636 +{
21637 +       struct vcmd_net_flags_v0 vc_data;
21638 +
21639 +       vc_data.flagword = nxi->nx_flags;
21640 +
21641 +       /* special STATE flag handling */
21642 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
21643 +
21644 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21645 +               return -EFAULT;
21646 +       return 0;
21647 +}
21648 +
21649 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
21650 +{
21651 +       struct vcmd_net_flags_v0 vc_data;
21652 +       uint64_t mask, trigger;
21653 +
21654 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21655 +               return -EFAULT;
21656 +
21657 +       /* special STATE flag handling */
21658 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
21659 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
21660 +
21661 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
21662 +               vc_data.flagword, mask);
21663 +       if (trigger & NXF_PERSISTENT)
21664 +               nx_update_persistent(nxi);
21665 +
21666 +       return 0;
21667 +}
21668 +
21669 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
21670 +{
21671 +       struct vcmd_net_caps_v0 vc_data;
21672 +
21673 +       vc_data.ncaps = nxi->nx_ncaps;
21674 +       vc_data.cmask = ~0ULL;
21675 +
21676 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21677 +               return -EFAULT;
21678 +       return 0;
21679 +}
21680 +
21681 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
21682 +{
21683 +       struct vcmd_net_caps_v0 vc_data;
21684 +
21685 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21686 +               return -EFAULT;
21687 +
21688 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
21689 +               vc_data.ncaps, vc_data.cmask);
21690 +       return 0;
21691 +}
21692 +
21693 +
21694 +#include <linux/module.h>
21695 +
21696 +module_init(init_network);
21697 +
21698 +EXPORT_SYMBOL_GPL(free_nx_info);
21699 +EXPORT_SYMBOL_GPL(unhash_nx_info);
21700 +
21701 diff -NurpP --minimal linux-2.6.36/kernel/vserver/proc.c linux-2.6.36-vs2.3.0.36.33/kernel/vserver/proc.c
21702 --- linux-2.6.36/kernel/vserver/proc.c  1970-01-01 01:00:00.000000000 +0100
21703 +++ linux-2.6.36-vs2.3.0.36.33/kernel/vserver/proc.c    2010-10-21 13:09:36.000000000 +0200
21704 @@ -0,0 +1,1098 @@
21705 +/*
21706 + *  linux/kernel/vserver/proc.c
21707 + *
21708 + *  Virtual Context Support
21709 + *
21710 + *  Copyright (C) 2003-2007  Herbert Pötzl
21711 + *
21712 + *  V0.01  basic structure
21713 + *  V0.02  adaptation vs1.3.0
21714 + *  V0.03  proc permissions
21715 + *  V0.04  locking/generic
21716 + *  V0.05  next generation procfs
21717 + *  V0.06  inode validation
21718 + *  V0.07  generic rewrite vid
21719 + *  V0.08  remove inode type
21720 + *
21721 + */
21722 +
21723 +#include <linux/proc_fs.h>
21724 +#include <linux/fs_struct.h>
21725 +#include <linux/mount.h>
21726 +#include <asm/unistd.h>
21727 +
21728 +#include <linux/vs_context.h>
21729 +#include <linux/vs_network.h>
21730 +#include <linux/vs_cvirt.h>
21731 +
21732 +#include <linux/in.h>
21733 +#include <linux/inetdevice.h>
21734 +#include <linux/vs_inet.h>
21735 +#include <linux/vs_inet6.h>
21736 +
21737 +#include <linux/vserver/global.h>
21738 +
21739 +#include "cvirt_proc.h"
21740 +#include "cacct_proc.h"
21741 +#include "limit_proc.h"
21742 +#include "sched_proc.h"
21743 +#include "vci_config.h"
21744 +
21745 +
21746 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
21747 +{
21748 +       unsigned __capi;
21749 +
21750 +       CAP_FOR_EACH_U32(__capi) {
21751 +               buffer += sprintf(buffer, "%08x",
21752 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
21753 +       }
21754 +       return buffer;
21755 +}
21756 +
21757 +
21758 +static struct proc_dir_entry *proc_virtual;
21759 +
21760 +static struct proc_dir_entry *proc_virtnet;
21761 +
21762 +
21763 +/* first the actual feeds */
21764 +
21765 +
21766 +static int proc_vci(char *buffer)
21767 +{
21768 +       return sprintf(buffer,
21769 +               "VCIVersion:\t%04x:%04x\n"
21770 +               "VCISyscall:\t%d\n"
21771 +               "VCIKernel:\t%08x\n",
21772 +               VCI_VERSION >> 16,
21773 +               VCI_VERSION & 0xFFFF,
21774 +               __NR_vserver,
21775 +               vci_kernel_config());
21776 +}
21777 +
21778 +static int proc_virtual_info(char *buffer)
21779 +{
21780 +       return proc_vci(buffer);
21781 +}
21782 +
21783 +static int proc_virtual_status(char *buffer)
21784 +{
21785 +       return sprintf(buffer,
21786 +               "#CTotal:\t%d\n"
21787 +               "#CActive:\t%d\n"
21788 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
21789 +               "#InitTask:\t%d\t%d %d\n",
21790 +               atomic_read(&vx_global_ctotal),
21791 +               atomic_read(&vx_global_cactive),
21792 +               atomic_read(&vs_global_nsproxy),
21793 +               atomic_read(&vs_global_fs),
21794 +               atomic_read(&vs_global_mnt_ns),
21795 +               atomic_read(&vs_global_uts_ns),
21796 +               atomic_read(&nr_ipc_ns),
21797 +               atomic_read(&vs_global_user_ns),
21798 +               atomic_read(&vs_global_pid_ns),
21799 +               atomic_read(&init_task.usage),
21800 +               atomic_read(&init_task.nsproxy->count),
21801 +               init_task.fs->users);
21802 +}
21803 +
21804 +
21805 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
21806 +{
21807 +       int length;
21808 +
21809 +       length = sprintf(buffer,
21810 +               "ID:\t%d\n"
21811 +               "Info:\t%p\n"
21812 +               "Init:\t%d\n"
21813 +               "OOM:\t%lld\n",
21814 +               vxi->vx_id,
21815 +               vxi,
21816 +               vxi->vx_initpid,
21817 +               vxi->vx_badness_bias);
21818 +       return length;
21819 +}
21820 +
21821 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
21822 +{
21823 +       char *orig = buffer;
21824 +
21825 +       buffer += sprintf(buffer,
21826 +               "UseCnt:\t%d\n"
21827 +               "Tasks:\t%d\n"
21828 +               "Flags:\t%016llx\n",
21829 +               atomic_read(&vxi->vx_usecnt),
21830 +               atomic_read(&vxi->vx_tasks),
21831 +               (unsigned long long)vxi->vx_flags);
21832 +
21833 +       buffer += sprintf(buffer, "BCaps:\t");
21834 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21835 +       buffer += sprintf(buffer, "\n");
21836 +
21837 +       buffer += sprintf(buffer,
21838 +               "CCaps:\t%016llx\n"
21839 +               "Spaces:\t%08lx %08lx\n",
21840 +               (unsigned long long)vxi->vx_ccaps,
21841 +               vxi->vx_nsmask[0], vxi->vx_nsmask[1]);
21842 +       return buffer - orig;
21843 +}
21844 +
21845 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
21846 +{
21847 +       return vx_info_proc_limit(&vxi->limit, buffer);
21848 +}
21849 +
21850 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
21851 +{
21852 +       int cpu, length;
21853 +
21854 +       length = vx_info_proc_sched(&vxi->sched, buffer);
21855 +       for_each_online_cpu(cpu) {
21856 +               length += vx_info_proc_sched_pc(
21857 +                       &vx_per_cpu(vxi, sched_pc, cpu),
21858 +                       buffer + length, cpu);
21859 +       }
21860 +       return length;
21861 +}
21862 +
21863 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
21864 +{
21865 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[0], buffer);
21866 +}
21867 +
21868 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
21869 +{
21870 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[1], buffer);
21871 +}
21872 +
21873 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
21874 +{
21875 +       int cpu, length;
21876 +
21877 +       vx_update_load(vxi);
21878 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
21879 +       for_each_online_cpu(cpu) {
21880 +               length += vx_info_proc_cvirt_pc(
21881 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
21882 +                       buffer + length, cpu);
21883 +       }
21884 +       return length;
21885 +}
21886 +
21887 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
21888 +{
21889 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
21890 +}
21891 +
21892 +
21893 +static int proc_virtnet_info(char *buffer)
21894 +{
21895 +       return proc_vci(buffer);
21896 +}
21897 +
21898 +static int proc_virtnet_status(char *buffer)
21899 +{
21900 +       return sprintf(buffer,
21901 +               "#CTotal:\t%d\n"
21902 +               "#CActive:\t%d\n",
21903 +               atomic_read(&nx_global_ctotal),
21904 +               atomic_read(&nx_global_cactive));
21905 +}
21906 +
21907 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
21908 +{
21909 +       struct nx_addr_v4 *v4a;
21910 +#ifdef CONFIG_IPV6
21911 +       struct nx_addr_v6 *v6a;
21912 +#endif
21913 +       int length, i;
21914 +
21915 +       length = sprintf(buffer,
21916 +               "ID:\t%d\n"
21917 +               "Info:\t%p\n"
21918 +               "Bcast:\t" NIPQUAD_FMT "\n"
21919 +               "Lback:\t" NIPQUAD_FMT "\n",
21920 +               nxi->nx_id,
21921 +               nxi,
21922 +               NIPQUAD(nxi->v4_bcast.s_addr),
21923 +               NIPQUAD(nxi->v4_lback.s_addr));
21924 +
21925 +       if (!NX_IPV4(nxi))
21926 +               goto skip_v4;
21927 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21928 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
21929 +                       i, NXAV4(v4a));
21930 +skip_v4:
21931 +#ifdef CONFIG_IPV6
21932 +       if (!NX_IPV6(nxi))
21933 +               goto skip_v6;
21934 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21935 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
21936 +                       i, NXAV6(v6a));
21937 +skip_v6:
21938 +#endif
21939 +       return length;
21940 +}
21941 +
21942 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
21943 +{
21944 +       int length;
21945 +
21946 +       length = sprintf(buffer,
21947 +               "UseCnt:\t%d\n"
21948 +               "Tasks:\t%d\n"
21949 +               "Flags:\t%016llx\n"
21950 +               "NCaps:\t%016llx\n",
21951 +               atomic_read(&nxi->nx_usecnt),
21952 +               atomic_read(&nxi->nx_tasks),
21953 +               (unsigned long long)nxi->nx_flags,
21954 +               (unsigned long long)nxi->nx_ncaps);
21955 +       return length;
21956 +}
21957 +
21958 +
21959 +
21960 +/* here the inode helpers */
21961 +
21962 +struct vs_entry {
21963 +       int len;
21964 +       char *name;
21965 +       mode_t mode;
21966 +       struct inode_operations *iop;
21967 +       struct file_operations *fop;
21968 +       union proc_op op;
21969 +};
21970 +
21971 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
21972 +{
21973 +       struct inode *inode = new_inode(sb);
21974 +
21975 +       if (!inode)
21976 +               goto out;
21977 +
21978 +       inode->i_mode = p->mode;
21979 +       if (p->iop)
21980 +               inode->i_op = p->iop;
21981 +       if (p->fop)
21982 +               inode->i_fop = p->fop;
21983 +
21984 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
21985 +       inode->i_flags |= S_IMMUTABLE;
21986 +
21987 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
21988 +
21989 +       inode->i_uid = 0;
21990 +       inode->i_gid = 0;
21991 +       inode->i_tag = 0;
21992 +out:
21993 +       return inode;
21994 +}
21995 +
21996 +static struct dentry *vs_proc_instantiate(struct inode *dir,
21997 +       struct dentry *dentry, int id, void *ptr)
21998 +{
21999 +       struct vs_entry *p = ptr;
22000 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
22001 +       struct dentry *error = ERR_PTR(-EINVAL);
22002 +
22003 +       if (!inode)
22004 +               goto out;
22005 +
22006 +       PROC_I(inode)->op = p->op;
22007 +       PROC_I(inode)->fd = id;
22008 +       d_add(dentry, inode);
22009 +       error = NULL;
22010 +out:
22011 +       return error;
22012 +}
22013 +
22014 +/* Lookups */
22015 +
22016 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
22017 +
22018 +/*
22019 + * Fill a directory entry.
22020 + *
22021 + * If possible create the dcache entry and derive our inode number and
22022 + * file type from dcache entry.
22023 + *
22024 + * Since all of the proc inode numbers are dynamically generated, the inode
22025 + * numbers do not exist until the inode is cache.  This means creating the
22026 + * the dcache entry in readdir is necessary to keep the inode numbers
22027 + * reported by readdir in sync with the inode numbers reported
22028 + * by stat.
22029 + */
22030 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
22031 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
22032 +{
22033 +       struct dentry *child, *dir = filp->f_dentry;
22034 +       struct inode *inode;
22035 +       struct qstr qname;
22036 +       ino_t ino = 0;
22037 +       unsigned type = DT_UNKNOWN;
22038 +
22039 +       qname.name = name;
22040 +       qname.len  = len;
22041 +       qname.hash = full_name_hash(name, len);
22042 +
22043 +       child = d_lookup(dir, &qname);
22044 +       if (!child) {
22045 +               struct dentry *new;
22046 +               new = d_alloc(dir, &qname);
22047 +               if (new) {
22048 +                       child = instantiate(dir->d_inode, new, id, ptr);
22049 +                       if (child)
22050 +                               dput(new);
22051 +                       else
22052 +                               child = new;
22053 +               }
22054 +       }
22055 +       if (!child || IS_ERR(child) || !child->d_inode)
22056 +               goto end_instantiate;
22057 +       inode = child->d_inode;
22058 +       if (inode) {
22059 +               ino = inode->i_ino;
22060 +               type = inode->i_mode >> 12;
22061 +       }
22062 +       dput(child);
22063 +end_instantiate:
22064 +       if (!ino)
22065 +               ino = find_inode_number(dir, &qname);
22066 +       if (!ino)
22067 +               ino = 1;
22068 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
22069 +}
22070 +
22071 +
22072 +
22073 +/* get and revalidate vx_info/xid */
22074 +
22075 +static inline
22076 +struct vx_info *get_proc_vx_info(struct inode *inode)
22077 +{
22078 +       return lookup_vx_info(PROC_I(inode)->fd);
22079 +}
22080 +
22081 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
22082 +{
22083 +       struct inode *inode = dentry->d_inode;
22084 +       xid_t xid = PROC_I(inode)->fd;
22085 +
22086 +       if (!xid || xid_is_hashed(xid))
22087 +               return 1;
22088 +       d_drop(dentry);
22089 +       return 0;
22090 +}
22091 +
22092 +
22093 +/* get and revalidate nx_info/nid */
22094 +
22095 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
22096 +{
22097 +       struct inode *inode = dentry->d_inode;
22098 +       nid_t nid = PROC_I(inode)->fd;
22099 +
22100 +       if (!nid || nid_is_hashed(nid))
22101 +               return 1;
22102 +       d_drop(dentry);
22103 +       return 0;
22104 +}
22105 +
22106 +
22107 +
22108 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
22109 +
22110 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
22111 +                         size_t count, loff_t *ppos)
22112 +{
22113 +       struct inode *inode = file->f_dentry->d_inode;
22114 +       unsigned long page;
22115 +       ssize_t length = 0;
22116 +
22117 +       if (count > PROC_BLOCK_SIZE)
22118 +               count = PROC_BLOCK_SIZE;
22119 +
22120 +       /* fade that out as soon as stable */
22121 +       WARN_ON(PROC_I(inode)->fd);
22122 +
22123 +       if (!(page = __get_free_page(GFP_KERNEL)))
22124 +               return -ENOMEM;
22125 +
22126 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
22127 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
22128 +
22129 +       if (length >= 0)
22130 +               length = simple_read_from_buffer(buf, count, ppos,
22131 +                       (char *)page, length);
22132 +
22133 +       free_page(page);
22134 +       return length;
22135 +}
22136 +
22137 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
22138 +                         size_t count, loff_t *ppos)
22139 +{
22140 +       struct inode *inode = file->f_dentry->d_inode;
22141 +       struct vx_info *vxi = NULL;
22142 +       xid_t xid = PROC_I(inode)->fd;
22143 +       unsigned long page;
22144 +       ssize_t length = 0;
22145 +
22146 +       if (count > PROC_BLOCK_SIZE)
22147 +               count = PROC_BLOCK_SIZE;
22148 +
22149 +       /* fade that out as soon as stable */
22150 +       WARN_ON(!xid);
22151 +       vxi = lookup_vx_info(xid);
22152 +       if (!vxi)
22153 +               goto out;
22154 +
22155 +       length = -ENOMEM;
22156 +       if (!(page = __get_free_page(GFP_KERNEL)))
22157 +               goto out_put;
22158 +
22159 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
22160 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
22161 +
22162 +       if (length >= 0)
22163 +               length = simple_read_from_buffer(buf, count, ppos,
22164 +                       (char *)page, length);
22165 +
22166 +       free_page(page);
22167 +out_put:
22168 +       put_vx_info(vxi);
22169 +out:
22170 +       return length;
22171 +}
22172 +
22173 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
22174 +                         size_t count, loff_t *ppos)
22175 +{
22176 +       struct inode *inode = file->f_dentry->d_inode;
22177 +       struct nx_info *nxi = NULL;
22178 +       nid_t nid = PROC_I(inode)->fd;
22179 +       unsigned long page;
22180 +       ssize_t length = 0;
22181 +
22182 +       if (count > PROC_BLOCK_SIZE)
22183 +               count = PROC_BLOCK_SIZE;
22184 +
22185 +       /* fade that out as soon as stable */
22186 +       WARN_ON(!nid);
22187 +       nxi = lookup_nx_info(nid);
22188 +       if (!nxi)
22189 +               goto out;
22190 +
22191 +       length = -ENOMEM;
22192 +       if (!(page = __get_free_page(GFP_KERNEL)))
22193 +               goto out_put;
22194 +
22195 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
22196 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
22197 +
22198 +       if (length >= 0)
22199 +               length = simple_read_from_buffer(buf, count, ppos,
22200 +                       (char *)page, length);
22201 +
22202 +       free_page(page);
22203 +out_put:
22204 +       put_nx_info(nxi);
22205 +out:
22206 +       return length;
22207 +}
22208 +
22209 +
22210 +
22211 +/* here comes the lower level */
22212 +
22213 +
22214 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
22215 +       .len  = sizeof(NAME) - 1,       \
22216 +       .name = (NAME),                 \
22217 +       .mode = MODE,                   \
22218 +       .iop  = IOP,                    \
22219 +       .fop  = FOP,                    \
22220 +       .op   = OP,                     \
22221 +}
22222 +
22223 +
22224 +#define DIR(NAME, MODE, OTYPE)                         \
22225 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
22226 +               &proc_ ## OTYPE ## _inode_operations,   \
22227 +               &proc_ ## OTYPE ## _file_operations, { } )
22228 +
22229 +#define INF(NAME, MODE, OTYPE)                         \
22230 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
22231 +               &proc_vs_info_file_operations,          \
22232 +               { .proc_vs_read = &proc_##OTYPE } )
22233 +
22234 +#define VINF(NAME, MODE, OTYPE)                                \
22235 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
22236 +               &proc_vx_info_file_operations,          \
22237 +               { .proc_vxi_read = &proc_##OTYPE } )
22238 +
22239 +#define NINF(NAME, MODE, OTYPE)                                \
22240 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
22241 +               &proc_nx_info_file_operations,          \
22242 +               { .proc_nxi_read = &proc_##OTYPE } )
22243 +
22244 +
22245 +static struct file_operations proc_vs_info_file_operations = {
22246 +       .read =         proc_vs_info_read,
22247 +};
22248 +
22249 +static struct file_operations proc_vx_info_file_operations = {
22250 +       .read =         proc_vx_info_read,
22251 +};
22252 +
22253 +static struct dentry_operations proc_xid_dentry_operations = {
22254 +       .d_revalidate = proc_xid_revalidate,
22255 +};
22256 +
22257 +static struct vs_entry vx_base_stuff[] = {
22258 +       VINF("info",    S_IRUGO, vxi_info),
22259 +       VINF("status",  S_IRUGO, vxi_status),
22260 +       VINF("limit",   S_IRUGO, vxi_limit),
22261 +       VINF("sched",   S_IRUGO, vxi_sched),
22262 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
22263 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
22264 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
22265 +       VINF("cacct",   S_IRUGO, vxi_cacct),
22266 +       {}
22267 +};
22268 +
22269 +
22270 +
22271 +
22272 +static struct dentry *proc_xid_instantiate(struct inode *dir,
22273 +       struct dentry *dentry, int id, void *ptr)
22274 +{
22275 +       dentry->d_op = &proc_xid_dentry_operations;
22276 +       return vs_proc_instantiate(dir, dentry, id, ptr);
22277 +}
22278 +
22279 +static struct dentry *proc_xid_lookup(struct inode *dir,
22280 +       struct dentry *dentry, struct nameidata *nd)
22281 +{
22282 +       struct vs_entry *p = vx_base_stuff;
22283 +       struct dentry *error = ERR_PTR(-ENOENT);
22284 +
22285 +       for (; p->name; p++) {
22286 +               if (p->len != dentry->d_name.len)
22287 +                       continue;
22288 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22289 +                       break;
22290 +       }
22291 +       if (!p->name)
22292 +               goto out;
22293 +
22294 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
22295 +out:
22296 +       return error;
22297 +}
22298 +
22299 +static int proc_xid_readdir(struct file *filp,
22300 +       void *dirent, filldir_t filldir)
22301 +{
22302 +       struct dentry *dentry = filp->f_dentry;
22303 +       struct inode *inode = dentry->d_inode;
22304 +       struct vs_entry *p = vx_base_stuff;
22305 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
22306 +       int pos, index;
22307 +       u64 ino;
22308 +
22309 +       pos = filp->f_pos;
22310 +       switch (pos) {
22311 +       case 0:
22312 +               ino = inode->i_ino;
22313 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22314 +                       goto out;
22315 +               pos++;
22316 +               /* fall through */
22317 +       case 1:
22318 +               ino = parent_ino(dentry);
22319 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22320 +                       goto out;
22321 +               pos++;
22322 +               /* fall through */
22323 +       default:
22324 +               index = pos - 2;
22325 +               if (index >= size)
22326 +                       goto out;
22327 +               for (p += index; p->name; p++) {
22328 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22329 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
22330 +                               goto out;
22331 +                       pos++;
22332 +               }
22333 +       }
22334 +out:
22335 +       filp->f_pos = pos;
22336 +       return 1;
22337 +}
22338 +
22339 +
22340 +
22341 +static struct file_operations proc_nx_info_file_operations = {
22342 +       .read =         proc_nx_info_read,
22343 +};
22344 +
22345 +static struct dentry_operations proc_nid_dentry_operations = {
22346 +       .d_revalidate = proc_nid_revalidate,
22347 +};
22348 +
22349 +static struct vs_entry nx_base_stuff[] = {
22350 +       NINF("info",    S_IRUGO, nxi_info),
22351 +       NINF("status",  S_IRUGO, nxi_status),
22352 +       {}
22353 +};
22354 +
22355 +
22356 +static struct dentry *proc_nid_instantiate(struct inode *dir,
22357 +       struct dentry *dentry, int id, void *ptr)
22358 +{
22359 +       dentry->d_op = &proc_nid_dentry_operations;
22360 +       return vs_proc_instantiate(dir, dentry, id, ptr);
22361 +}
22362 +
22363 +static struct dentry *proc_nid_lookup(struct inode *dir,
22364 +       struct dentry *dentry, struct nameidata *nd)
22365 +{
22366 +       struct vs_entry *p = nx_base_stuff;
22367 +       struct dentry *error = ERR_PTR(-ENOENT);
22368 +
22369 +       for (; p->name; p++) {
22370 +               if (p->len != dentry->d_name.len)
22371 +                       continue;
22372 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22373 +                       break;
22374 +       }
22375 +       if (!p->name)
22376 +               goto out;
22377 +
22378 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
22379 +out:
22380 +       return error;
22381 +}
22382 +
22383 +static int proc_nid_readdir(struct file *filp,
22384 +       void *dirent, filldir_t filldir)
22385 +{
22386 +       struct dentry *dentry = filp->f_dentry;
22387 +       struct inode *inode = dentry->d_inode;
22388 +       struct vs_entry *p = nx_base_stuff;
22389 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
22390 +       int pos, index;
22391 +       u64 ino;
22392 +
22393 +       pos = filp->f_pos;
22394 +       switch (pos) {
22395 +       case 0:
22396 +               ino = inode->i_ino;
22397 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22398 +                       goto out;
22399 +               pos++;
22400 +               /* fall through */
22401 +       case 1:
22402 +               ino = parent_ino(dentry);
22403 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22404 +                       goto out;
22405 +               pos++;
22406 +               /* fall through */
22407 +       default:
22408 +               index = pos - 2;
22409 +               if (index >= size)
22410 +                       goto out;
22411 +               for (p += index; p->name; p++) {
22412 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22413 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
22414 +                               goto out;
22415 +                       pos++;
22416 +               }
22417 +       }
22418 +out:
22419 +       filp->f_pos = pos;
22420 +       return 1;
22421 +}
22422 +
22423 +
22424 +#define MAX_MULBY10    ((~0U - 9) / 10)
22425 +
22426 +static inline int atovid(const char *str, int len)
22427 +{
22428 +       int vid, c;
22429 +
22430 +       vid = 0;
22431 +       while (len-- > 0) {
22432 +               c = *str - '0';
22433 +               str++;
22434 +               if (c > 9)
22435 +                       return -1;
22436 +               if (vid >= MAX_MULBY10)
22437 +                       return -1;
22438 +               vid *= 10;
22439 +               vid += c;
22440 +               if (!vid)
22441 +                       return -1;
22442 +       }
22443 +       return vid;
22444 +}
22445 +
22446 +/* now the upper level (virtual) */
22447 +
22448 +
22449 +static struct file_operations proc_xid_file_operations = {
22450 +       .read =         generic_read_dir,
22451 +       .readdir =      proc_xid_readdir,
22452 +};
22453 +
22454 +static struct inode_operations proc_xid_inode_operations = {
22455 +       .lookup =       proc_xid_lookup,
22456 +};
22457 +
22458 +static struct vs_entry vx_virtual_stuff[] = {
22459 +       INF("info",     S_IRUGO, virtual_info),
22460 +       INF("status",   S_IRUGO, virtual_status),
22461 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
22462 +};
22463 +
22464 +
22465 +static struct dentry *proc_virtual_lookup(struct inode *dir,
22466 +       struct dentry *dentry, struct nameidata *nd)
22467 +{
22468 +       struct vs_entry *p = vx_virtual_stuff;
22469 +       struct dentry *error = ERR_PTR(-ENOENT);
22470 +       int id = 0;
22471 +
22472 +       for (; p->name; p++) {
22473 +               if (p->len != dentry->d_name.len)
22474 +                       continue;
22475 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22476 +                       break;
22477 +       }
22478 +       if (p->name)
22479 +               goto instantiate;
22480 +
22481 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
22482 +       if ((id < 0) || !xid_is_hashed(id))
22483 +               goto out;
22484 +
22485 +instantiate:
22486 +       error = proc_xid_instantiate(dir, dentry, id, p);
22487 +out:
22488 +       return error;
22489 +}
22490 +
22491 +static struct file_operations proc_nid_file_operations = {
22492 +       .read =         generic_read_dir,
22493 +       .readdir =      proc_nid_readdir,
22494 +};
22495 +
22496 +static struct inode_operations proc_nid_inode_operations = {
22497 +       .lookup =       proc_nid_lookup,
22498 +};
22499 +
22500 +static struct vs_entry nx_virtnet_stuff[] = {
22501 +       INF("info",     S_IRUGO, virtnet_info),
22502 +       INF("status",   S_IRUGO, virtnet_status),
22503 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
22504 +};
22505 +
22506 +
22507 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
22508 +       struct dentry *dentry, struct nameidata *nd)
22509 +{
22510 +       struct vs_entry *p = nx_virtnet_stuff;
22511 +       struct dentry *error = ERR_PTR(-ENOENT);
22512 +       int id = 0;
22513 +
22514 +       for (; p->name; p++) {
22515 +               if (p->len != dentry->d_name.len)
22516 +                       continue;
22517 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
22518 +                       break;
22519 +       }
22520 +       if (p->name)
22521 +               goto instantiate;
22522 +
22523 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
22524 +       if ((id < 0) || !nid_is_hashed(id))
22525 +               goto out;
22526 +
22527 +instantiate:
22528 +       error = proc_nid_instantiate(dir, dentry, id, p);
22529 +out:
22530 +       return error;
22531 +}
22532 +
22533 +
22534 +#define PROC_MAXVIDS 32
22535 +
22536 +int proc_virtual_readdir(struct file *filp,
22537 +       void *dirent, filldir_t filldir)
22538 +{
22539 +       struct dentry *dentry = filp->f_dentry;
22540 +       struct inode *inode = dentry->d_inode;
22541 +       struct vs_entry *p = vx_virtual_stuff;
22542 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
22543 +       int pos, index;
22544 +       unsigned int xid_array[PROC_MAXVIDS];
22545 +       char buf[PROC_NUMBUF];
22546 +       unsigned int nr_xids, i;
22547 +       u64 ino;
22548 +
22549 +       pos = filp->f_pos;
22550 +       switch (pos) {
22551 +       case 0:
22552 +               ino = inode->i_ino;
22553 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22554 +                       goto out;
22555 +               pos++;
22556 +               /* fall through */
22557 +       case 1:
22558 +               ino = parent_ino(dentry);
22559 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22560 +                       goto out;
22561 +               pos++;
22562 +               /* fall through */
22563 +       default:
22564 +               index = pos - 2;
22565 +               if (index >= size)
22566 +                       goto entries;
22567 +               for (p += index; p->name; p++) {
22568 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22569 +                               vs_proc_instantiate, 0, p))
22570 +                               goto out;
22571 +                       pos++;
22572 +               }
22573 +       entries:
22574 +               index = pos - size;
22575 +               p = &vx_virtual_stuff[size - 1];
22576 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
22577 +               for (i = 0; i < nr_xids; i++) {
22578 +                       int n, xid = xid_array[i];
22579 +                       unsigned int j = PROC_NUMBUF;
22580 +
22581 +                       n = xid;
22582 +                       do
22583 +                               buf[--j] = '0' + (n % 10);
22584 +                       while (n /= 10);
22585 +
22586 +                       if (proc_fill_cache(filp, dirent, filldir,
22587 +                               buf + j, PROC_NUMBUF - j,
22588 +                               vs_proc_instantiate, xid, p))
22589 +                               goto out;
22590 +                       pos++;
22591 +               }
22592 +       }
22593 +out:
22594 +       filp->f_pos = pos;
22595 +       return 0;
22596 +}
22597 +
22598 +static int proc_virtual_getattr(struct vfsmount *mnt,
22599 +       struct dentry *dentry, struct kstat *stat)
22600 +{
22601 +       struct inode *inode = dentry->d_inode;
22602 +
22603 +       generic_fillattr(inode, stat);
22604 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
22605 +       return 0;
22606 +}
22607 +
22608 +static struct file_operations proc_virtual_dir_operations = {
22609 +       .read =         generic_read_dir,
22610 +       .readdir =      proc_virtual_readdir,
22611 +};
22612 +
22613 +static struct inode_operations proc_virtual_dir_inode_operations = {
22614 +       .getattr =      proc_virtual_getattr,
22615 +       .lookup =       proc_virtual_lookup,
22616 +};
22617 +
22618 +
22619 +
22620 +
22621 +
22622 +int proc_virtnet_readdir(struct file *filp,
22623 +       void *dirent, filldir_t filldir)
22624 +{
22625 +       struct dentry *dentry = filp->f_dentry;
22626 +       struct inode *inode = dentry->d_inode;
22627 +       struct vs_entry *p = nx_virtnet_stuff;
22628 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
22629 +       int pos, index;
22630 +       unsigned int nid_array[PROC_MAXVIDS];
22631 +       char buf[PROC_NUMBUF];
22632 +       unsigned int nr_nids, i;
22633 +       u64 ino;
22634 +
22635 +       pos = filp->f_pos;
22636 +       switch (pos) {
22637 +       case 0:
22638 +               ino = inode->i_ino;
22639 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
22640 +                       goto out;
22641 +               pos++;
22642 +               /* fall through */
22643 +       case 1:
22644 +               ino = parent_ino(dentry);
22645 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
22646 +                       goto out;
22647 +               pos++;
22648 +               /* fall through */
22649 +       default:
22650 +               index = pos - 2;
22651 +               if (index >= size)
22652 +                       goto entries;
22653 +               for (p += index; p->name; p++) {
22654 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
22655 +                               vs_proc_instantiate, 0, p))
22656 +                               goto out;
22657 +                       pos++;
22658 +               }
22659 +       entries:
22660 +               index = pos - size;
22661 +               p = &nx_virtnet_stuff[size - 1];
22662 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
22663 +               for (i = 0; i < nr_nids; i++) {
22664 +                       int n, nid = nid_array[i];
22665 +                       unsigned int j = PROC_NUMBUF;
22666 +
22667 +                       n = nid;
22668 +                       do
22669 +                               buf[--j] = '0' + (n % 10);
22670 +                       while (n /= 10);
22671 +
22672 +                       if (proc_fill_cache(filp, dirent, filldir,
22673 +                               buf + j, PROC_NUMBUF - j,
22674 +                               vs_proc_instantiate, nid, p))
22675 +                               goto out;
22676 +                       pos++;
22677 +               }
22678 +       }
22679 +out:
22680 +       filp->f_pos = pos;
22681 +       return 0;
22682 +}
22683 +
22684 +static int proc_virtnet_getattr(struct vfsmount *mnt,
22685 +       struct dentry *dentry, struct kstat *stat)
22686 +{
22687 +       struct inode *inode = dentry->d_inode;
22688 +
22689 +       generic_fillattr(inode, stat);
22690 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
22691 +       return 0;
22692 +}
22693 +
22694 +static struct file_operations proc_virtnet_dir_operations = {
22695 +       .read =         generic_read_dir,
22696 +       .readdir =      proc_virtnet_readdir,
22697 +};
22698 +
22699 +static struct inode_operations proc_virtnet_dir_inode_operations = {
22700 +       .getattr =      proc_virtnet_getattr,
22701 +       .lookup =       proc_virtnet_lookup,
22702 +};
22703 +
22704 +
22705 +
22706 +void proc_vx_init(void)
22707 +{
22708 +       struct proc_dir_entry *ent;
22709 +
22710 +       ent = proc_mkdir("virtual", 0);
22711 +       if (ent) {
22712 +               ent->proc_fops = &proc_virtual_dir_operations;
22713 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
22714 +       }
22715 +       proc_virtual = ent;
22716 +
22717 +       ent = proc_mkdir("virtnet", 0);
22718 +       if (ent) {
22719 +               ent->proc_fops = &proc_virtnet_dir_operations;
22720 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
22721 +       }
22722 +       proc_virtnet = ent;
22723 +}
22724 +
22725 +
22726 +
22727 +
22728 +/* per pid info */
22729 +
22730 +
22731 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
22732 +{
22733 +       struct vx_info *vxi;
22734 +       char *orig = buffer;
22735 +
22736 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
22737 +
22738 +       vxi = task_get_vx_info(p);
22739 +       if (!vxi)
22740 +               goto out;
22741 +
22742 +       buffer += sprintf(buffer, "BCaps:\t");
22743 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
22744 +       buffer += sprintf(buffer, "\n");
22745 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
22746 +               (unsigned long long)vxi->vx_ccaps);
22747 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
22748 +               (unsigned long long)vxi->vx_flags);
22749 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
22750 +
22751 +       put_vx_info(vxi);
22752 +out:
22753 +       return buffer - orig;
22754 +}
22755 +
22756 +
22757 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
22758 +{
22759 +       struct nx_info *nxi;
22760 +       struct nx_addr_v4 *v4a;
22761 +#ifdef CONFIG_IPV6
22762 +       struct nx_addr_v6 *v6a;
22763 +#endif
22764 +       char *orig = buffer;
22765 +       int i;
22766 +
22767 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
22768 +
22769 +       nxi = task_get_nx_info(p);
22770 +       if (!nxi)
22771 +               goto out;
22772 +
22773 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
22774 +               (unsigned long long)nxi->nx_ncaps);
22775 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
22776 +               (unsigned long long)nxi->nx_flags);
22777 +
22778 +       buffer += sprintf(buffer,
22779 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
22780 +               NIPQUAD(nxi->v4_bcast.s_addr));
22781 +       buffer += sprintf (buffer,
22782 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
22783 +               NIPQUAD(nxi->v4_lback.s_addr));
22784 +       if (!NX_IPV4(nxi))
22785 +               goto skip_v4;
22786 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22787 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
22788 +                       i, NXAV4(v4a));
22789 +skip_v4:
22790 +#ifdef CONFIG_IPV6
22791 +       if (!NX_IPV6(nxi))
22792 +               goto skip_v6;
22793 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22794 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
22795 +                       i, NXAV6(v6a));
22796 +skip_v6:
22797 +#endif
22798 +       put_nx_info(nxi);
22799 +out:
22800 +       return buffer - orig;
22801 +}
22802 +
22803 diff -NurpP --minimal linux-2.6.36/kernel/vserver/sched.c linux-2.6.36-vs2.3.0.36.33/kernel/vserver/sched.c
22804 --- linux-2.6.36/kernel/vserver/sched.c 1970-01-01 01:00:00.000000000 +0100
22805 +++ linux-2.6.36-vs2.3.0.36.33/kernel/vserver/sched.c   2010-10-21 13:09:36.000000000 +0200
22806 @@ -0,0 +1,414 @@
22807 +/*
22808 + *  linux/kernel/vserver/sched.c
22809 + *
22810 + *  Virtual Server: Scheduler Support
22811 + *
22812 + *  Copyright (C) 2004-2007  Herbert Pötzl
22813 + *
22814 + *  V0.01  adapted Sam Vilains version to 2.6.3
22815 + *  V0.02  removed legacy interface
22816 + *  V0.03  changed vcmds to vxi arg
22817 + *  V0.04  removed older and legacy interfaces
22818 + *
22819 + */
22820 +
22821 +#include <linux/vs_context.h>
22822 +#include <linux/vs_sched.h>
22823 +#include <linux/vserver/sched_cmd.h>
22824 +
22825 +#include <asm/uaccess.h>
22826 +
22827 +
22828 +#define vxd_check_range(val, min, max) do {            \
22829 +       vxlprintk((val < min) || (val > max),           \
22830 +               "check_range(%ld,%ld,%ld)",             \
22831 +               (long)val, (long)min, (long)max,        \
22832 +               __FILE__, __LINE__);                    \
22833 +       } while (0)
22834 +
22835 +
22836 +void vx_update_sched_param(struct _vx_sched *sched,
22837 +       struct _vx_sched_pc *sched_pc)
22838 +{
22839 +       unsigned int set_mask = sched->update_mask;
22840 +
22841 +       if (set_mask & VXSM_FILL_RATE)
22842 +               sched_pc->fill_rate[0] = sched->fill_rate[0];
22843 +       if (set_mask & VXSM_INTERVAL)
22844 +               sched_pc->interval[0] = sched->interval[0];
22845 +       if (set_mask & VXSM_FILL_RATE2)
22846 +               sched_pc->fill_rate[1] = sched->fill_rate[1];
22847 +       if (set_mask & VXSM_INTERVAL2)
22848 +               sched_pc->interval[1] = sched->interval[1];
22849 +       if (set_mask & VXSM_TOKENS)
22850 +               sched_pc->tokens = sched->tokens;
22851 +       if (set_mask & VXSM_TOKENS_MIN)
22852 +               sched_pc->tokens_min = sched->tokens_min;
22853 +       if (set_mask & VXSM_TOKENS_MAX)
22854 +               sched_pc->tokens_max = sched->tokens_max;
22855 +       if (set_mask & VXSM_PRIO_BIAS)
22856 +               sched_pc->prio_bias = sched->prio_bias;
22857 +
22858 +       if (set_mask & VXSM_IDLE_TIME)
22859 +               sched_pc->flags |= VXSF_IDLE_TIME;
22860 +       else
22861 +               sched_pc->flags &= ~VXSF_IDLE_TIME;
22862 +
22863 +       /* reset time */
22864 +       sched_pc->norm_time = jiffies;
22865 +}
22866 +
22867 +
22868 +/*
22869 + * recalculate the context's scheduling tokens
22870 + *
22871 + * ret > 0 : number of tokens available
22872 + * ret < 0 : on hold, check delta_min[]
22873 + *          -1 only jiffies
22874 + *          -2 also idle time
22875 + *
22876 + */
22877 +int vx_tokens_recalc(struct _vx_sched_pc *sched_pc,
22878 +       unsigned long *norm_time, unsigned long *idle_time, int delta_min[2])
22879 +{
22880 +       long delta;
22881 +       long tokens = 0;
22882 +       int flags = sched_pc->flags;
22883 +
22884 +       /* how much time did pass? */
22885 +       delta = *norm_time - sched_pc->norm_time;
22886 +       // printk("@ %ld, %ld, %ld\n", *norm_time, sched_pc->norm_time, jiffies);
22887 +       vxd_check_range(delta, 0, INT_MAX);
22888 +
22889 +       if (delta >= sched_pc->interval[0]) {
22890 +               long tokens, integral;
22891 +
22892 +               /* calc integral token part */
22893 +               tokens = delta / sched_pc->interval[0];
22894 +               integral = tokens * sched_pc->interval[0];
22895 +               tokens *= sched_pc->fill_rate[0];
22896 +#ifdef CONFIG_VSERVER_HARDCPU
22897 +               delta_min[0] = delta - integral;
22898 +               vxd_check_range(delta_min[0], 0, sched_pc->interval[0]);
22899 +#endif
22900 +               /* advance time */
22901 +               sched_pc->norm_time += delta;
22902 +
22903 +               /* add tokens */
22904 +               sched_pc->tokens += tokens;
22905 +               sched_pc->token_time += tokens;
22906 +       } else
22907 +               delta_min[0] = delta;
22908 +
22909 +#ifdef CONFIG_VSERVER_IDLETIME
22910 +       if (!(flags & VXSF_IDLE_TIME))
22911 +               goto skip_idle;
22912 +
22913 +       /* how much was the idle skip? */
22914 +       delta = *idle_time - sched_pc->idle_time;
22915 +       vxd_check_range(delta, 0, INT_MAX);
22916 +
22917 +       if (delta >= sched_pc->interval[1]) {
22918 +               long tokens, integral;
22919 +
22920 +               /* calc fair share token part */
22921 +               tokens = delta / sched_pc->interval[1];
22922 +               integral = tokens * sched_pc->interval[1];
22923 +               tokens *= sched_pc->fill_rate[1];
22924 +               delta_min[1] = delta - integral;
22925 +               vxd_check_range(delta_min[1], 0, sched_pc->interval[1]);
22926 +
22927 +               /* advance idle time */
22928 +               sched_pc->idle_time += integral;
22929 +
22930 +               /* add tokens */
22931 +               sched_pc->tokens += tokens;
22932 +               sched_pc->token_time += tokens;
22933 +       } else
22934 +               delta_min[1] = delta;
22935 +skip_idle:
22936 +#endif
22937 +
22938 +       /* clip at maximum */
22939 +       if (sched_pc->tokens > sched_pc->tokens_max)
22940 +               sched_pc->tokens = sched_pc->tokens_max;
22941 +       tokens = sched_pc->tokens;
22942 +
22943 +       if ((flags & VXSF_ONHOLD)) {
22944 +               /* can we unhold? */
22945 +               if (tokens >= sched_pc->tokens_min) {
22946 +                       flags &= ~VXSF_ONHOLD;
22947 +                       sched_pc->hold_ticks +=
22948 +                               *norm_time - sched_pc->onhold;
22949 +               } else
22950 +                       goto on_hold;
22951 +       } else {
22952 +               /* put on hold? */
22953 +               if (tokens <= 0) {
22954 +                       flags |= VXSF_ONHOLD;
22955 +                       sched_pc->onhold = *norm_time;
22956 +                       goto on_hold;
22957 +               }
22958 +       }
22959 +       sched_pc->flags = flags;
22960 +       return tokens;
22961 +
22962 +on_hold:
22963 +       tokens = sched_pc->tokens_min - tokens;
22964 +       sched_pc->flags = flags;
22965 +       // BUG_ON(tokens < 0); probably doesn't hold anymore
22966 +
22967 +#ifdef CONFIG_VSERVER_HARDCPU
22968 +       /* next interval? */
22969 +       if (!sched_pc->fill_rate[0])
22970 +               delta_min[0] = HZ;
22971 +       else if (tokens > sched_pc->fill_rate[0])
22972 +               delta_min[0] += sched_pc->interval[0] *
22973 +                       tokens / sched_pc->fill_rate[0];
22974 +       else
22975 +               delta_min[0] = sched_pc->interval[0] - delta_min[0];
22976 +       vxd_check_range(delta_min[0], 0, INT_MAX);
22977 +
22978 +#ifdef CONFIG_VSERVER_IDLETIME
22979 +       if (!(flags & VXSF_IDLE_TIME))
22980 +               return -1;
22981 +
22982 +       /* next interval? */
22983 +       if (!sched_pc->fill_rate[1])
22984 +               delta_min[1] = HZ;
22985 +       else if (tokens > sched_pc->fill_rate[1])
22986 +               delta_min[1] += sched_pc->interval[1] *
22987 +                       tokens / sched_pc->fill_rate[1];
22988 +       else
22989 +               delta_min[1] = sched_pc->interval[1] - delta_min[1];
22990 +       vxd_check_range(delta_min[1], 0, INT_MAX);
22991 +
22992 +       return -2;
22993 +#else
22994 +       return -1;
22995 +#endif /* CONFIG_VSERVER_IDLETIME */
22996 +#else
22997 +       return 0;
22998 +#endif /* CONFIG_VSERVER_HARDCPU */
22999 +}
23000 +
23001 +static inline unsigned long msec_to_ticks(unsigned long msec)
23002 +{
23003 +       return msecs_to_jiffies(msec);
23004 +}
23005 +
23006 +static inline unsigned long ticks_to_msec(unsigned long ticks)
23007 +{
23008 +       return jiffies_to_msecs(ticks);
23009 +}
23010 +
23011 +static inline unsigned long ticks_to_usec(unsigned long ticks)
23012 +{
23013 +       return jiffies_to_usecs(ticks);
23014 +}
23015 +
23016 +
23017 +static int do_set_sched(struct vx_info *vxi, struct vcmd_sched_v5 *data)
23018 +{
23019 +       unsigned int set_mask = data->mask;
23020 +       unsigned int update_mask;
23021 +       int i, cpu;
23022 +
23023 +       /* Sanity check data values */
23024 +       if (data->tokens_max <= 0)
23025 +               data->tokens_max = HZ;
23026 +       if (data->tokens_min < 0)
23027 +               data->tokens_min = HZ / 3;
23028 +       if (data->tokens_min >= data->tokens_max)
23029 +               data->tokens_min = data->tokens_max;
23030 +
23031 +       if (data->prio_bias > MAX_PRIO_BIAS)
23032 +               data->prio_bias = MAX_PRIO_BIAS;
23033 +       if (data->prio_bias < MIN_PRIO_BIAS)
23034 +               data->prio_bias = MIN_PRIO_BIAS;
23035 +
23036 +       spin_lock(&vxi->sched.tokens_lock);
23037 +
23038 +       /* sync up on delayed updates */
23039 +       for_each_cpu_mask(cpu, vxi->sched.update)
23040 +               vx_update_sched_param(&vxi->sched,
23041 +                       &vx_per_cpu(vxi, sched_pc, cpu));
23042 +
23043 +       if (set_mask & VXSM_FILL_RATE)
23044 +               vxi->sched.fill_rate[0] = data->fill_rate[0];
23045 +       if (set_mask & VXSM_FILL_RATE2)
23046 +               vxi->sched.fill_rate[1] = data->fill_rate[1];
23047 +       if (set_mask & VXSM_INTERVAL)
23048 +               vxi->sched.interval[0] = (set_mask & VXSM_MSEC) ?
23049 +                       msec_to_ticks(data->interval[0]) : data->interval[0];
23050 +       if (set_mask & VXSM_INTERVAL2)
23051 +               vxi->sched.interval[1] = (set_mask & VXSM_MSEC) ?
23052 +                       msec_to_ticks(data->interval[1]) : data->interval[1];
23053 +       if (set_mask & VXSM_TOKENS)
23054 +               vxi->sched.tokens = data->tokens;
23055 +       if (set_mask & VXSM_TOKENS_MIN)
23056 +               vxi->sched.tokens_min = data->tokens_min;
23057 +       if (set_mask & VXSM_TOKENS_MAX)
23058 +               vxi->sched.tokens_max = data->tokens_max;
23059 +       if (set_mask & VXSM_PRIO_BIAS)
23060 +               vxi->sched.prio_bias = data->prio_bias;
23061 +
23062 +       /* Sanity check rate/interval */
23063 +       for (i = 0; i < 2; i++) {
23064 +               if (data->fill_rate[i] < 0)
23065 +                       data->fill_rate[i] = 0;
23066 +               if (data->interval[i] <= 0)
23067 +                       data->interval[i] = HZ;
23068 +       }
23069 +
23070 +       update_mask = vxi->sched.update_mask & VXSM_SET_MASK;
23071 +       update_mask |= (set_mask & (VXSM_SET_MASK | VXSM_IDLE_TIME));
23072 +       vxi->sched.update_mask = update_mask;
23073 +
23074 +#ifdef CONFIG_SMP
23075 +       rmb();
23076 +       if (set_mask & VXSM_CPU_ID) {
23077 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
23078 +               cpus_and(vxi->sched.update, cpu_online_map,
23079 +                       vxi->sched.update);
23080 +       } else
23081 +               vxi->sched.update = cpu_online_map;
23082 +
23083 +       /* forced reload? */
23084 +       if (set_mask & VXSM_FORCE) {
23085 +               for_each_cpu_mask(cpu, vxi->sched.update)
23086 +                       vx_update_sched_param(&vxi->sched,
23087 +                               &vx_per_cpu(vxi, sched_pc, cpu));
23088 +               vxi->sched.update = CPU_MASK_NONE;
23089 +       }
23090 +#else
23091 +       /* on UP we update immediately */
23092 +       vx_update_sched_param(&vxi->sched,
23093 +               &vx_per_cpu(vxi, sched_pc, 0));
23094 +#endif
23095 +
23096 +       spin_unlock(&vxi->sched.tokens_lock);
23097 +       return 0;
23098 +}
23099 +
23100 +
23101 +#define COPY_IDS(C) C(cpu_id); C(bucket_id)
23102 +#define COPY_PRI(C) C(prio_bias)
23103 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
23104 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);   \
23105 +                   C(fill_rate[1]); C(interval[1]);
23106 +
23107 +#define COPY_VALUE(name) vc_data.name = data->name
23108 +
23109 +static int do_set_sched_v4(struct vx_info *vxi, struct vcmd_set_sched_v4 *data)
23110 +{
23111 +       struct vcmd_sched_v5 vc_data;
23112 +
23113 +       vc_data.mask = data->set_mask;
23114 +       COPY_IDS(COPY_VALUE);
23115 +       COPY_PRI(COPY_VALUE);
23116 +       COPY_TOK(COPY_VALUE);
23117 +       vc_data.fill_rate[0] = vc_data.fill_rate[1] = data->fill_rate;
23118 +       vc_data.interval[0] = vc_data.interval[1] = data->interval;
23119 +       return do_set_sched(vxi, &vc_data);
23120 +}
23121 +
23122 +int vc_set_sched_v4(struct vx_info *vxi, void __user *data)
23123 +{
23124 +       struct vcmd_set_sched_v4 vc_data;
23125 +
23126 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23127 +               return -EFAULT;
23128 +
23129 +       return do_set_sched_v4(vxi, &vc_data);
23130 +}
23131 +
23132 +       /* latest interface is v5 */
23133 +
23134 +int vc_set_sched(struct vx_info *vxi, void __user *data)
23135 +{
23136 +       struct vcmd_sched_v5 vc_data;
23137 +
23138 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23139 +               return -EFAULT;
23140 +
23141 +       return do_set_sched(vxi, &vc_data);
23142 +}
23143 +
23144 +
23145 +#define COPY_PRI(C) C(prio_bias)
23146 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
23147 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);    \
23148 +                   C(fill_rate[1]); C(interval[1]);
23149 +
23150 +#define COPY_VALUE(name) vc_data.name = data->name
23151 +
23152 +
23153 +int vc_get_sched(struct vx_info *vxi, void __user *data)
23154 +{
23155 +       struct vcmd_sched_v5 vc_data;
23156 +
23157 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23158 +               return -EFAULT;
23159 +
23160 +       if (vc_data.mask & VXSM_CPU_ID) {
23161 +               int cpu = vc_data.cpu_id;
23162 +               struct _vx_sched_pc *data;
23163 +
23164 +               if (!cpu_possible(cpu))
23165 +                       return -EINVAL;
23166 +
23167 +               data = &vx_per_cpu(vxi, sched_pc, cpu);
23168 +               COPY_TOK(COPY_VALUE);
23169 +               COPY_PRI(COPY_VALUE);
23170 +               COPY_FRI(COPY_VALUE);
23171 +
23172 +               if (data->flags & VXSF_IDLE_TIME)
23173 +                       vc_data.mask |= VXSM_IDLE_TIME;
23174 +       } else {
23175 +               struct _vx_sched *data = &vxi->sched;
23176 +
23177 +               COPY_TOK(COPY_VALUE);
23178 +               COPY_PRI(COPY_VALUE);
23179 +               COPY_FRI(COPY_VALUE);
23180 +       }
23181 +
23182 +       if (vc_data.mask & VXSM_MSEC) {
23183 +               vc_data.interval[0] = ticks_to_msec(vc_data.interval[0]);
23184 +               vc_data.interval[1] = ticks_to_msec(vc_data.interval[1]);
23185 +       }
23186 +
23187 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23188 +               return -EFAULT;
23189 +       return 0;
23190 +}
23191 +
23192 +
23193 +int vc_sched_info(struct vx_info *vxi, void __user *data)
23194 +{
23195 +       struct vcmd_sched_info vc_data;
23196 +       int cpu;
23197 +
23198 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23199 +               return -EFAULT;
23200 +
23201 +       cpu = vc_data.cpu_id;
23202 +       if (!cpu_possible(cpu))
23203 +               return -EINVAL;
23204 +
23205 +       if (vxi) {
23206 +               struct _vx_sched_pc *sched_pc =
23207 +                       &vx_per_cpu(vxi, sched_pc, cpu);
23208 +
23209 +               vc_data.user_msec = ticks_to_msec(sched_pc->user_ticks);
23210 +               vc_data.sys_msec = ticks_to_msec(sched_pc->sys_ticks);
23211 +               vc_data.hold_msec = ticks_to_msec(sched_pc->hold_ticks);
23212 +               vc_data.vavavoom = sched_pc->vavavoom;
23213 +       }
23214 +       vc_data.token_usec = ticks_to_usec(1);
23215 +
23216 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23217 +               return -EFAULT;
23218 +       return 0;
23219 +}
23220 +
23221 diff -NurpP --minimal linux-2.6.36/kernel/vserver/sched_init.h linux-2.6.36-vs2.3.0.36.33/kernel/vserver/sched_init.h
23222 --- linux-2.6.36/kernel/vserver/sched_init.h    1970-01-01 01:00:00.000000000 +0100
23223 +++ linux-2.6.36-vs2.3.0.36.33/kernel/vserver/sched_init.h      2010-10-21 13:09:36.000000000 +0200
23224 @@ -0,0 +1,50 @@
23225 +
23226 +static inline void vx_info_init_sched(struct _vx_sched *sched)
23227 +{
23228 +       static struct lock_class_key tokens_lock_key;
23229 +
23230 +       /* scheduling; hard code starting values as constants */
23231 +       sched->fill_rate[0]     = 1;
23232 +       sched->interval[0]      = 4;
23233 +       sched->fill_rate[1]     = 1;
23234 +       sched->interval[1]      = 8;
23235 +       sched->tokens           = HZ >> 2;
23236 +       sched->tokens_min       = HZ >> 4;
23237 +       sched->tokens_max       = HZ >> 1;
23238 +       sched->tokens_lock      = SPIN_LOCK_UNLOCKED;
23239 +       sched->prio_bias        = 0;
23240 +
23241 +       lockdep_set_class(&sched->tokens_lock, &tokens_lock_key);
23242 +}
23243 +
23244 +static inline
23245 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
23246 +{
23247 +       sched_pc->fill_rate[0]  = 1;
23248 +       sched_pc->interval[0]   = 4;
23249 +       sched_pc->fill_rate[1]  = 1;
23250 +       sched_pc->interval[1]   = 8;
23251 +       sched_pc->tokens        = HZ >> 2;
23252 +       sched_pc->tokens_min    = HZ >> 4;
23253 +       sched_pc->tokens_max    = HZ >> 1;
23254 +       sched_pc->prio_bias     = 0;
23255 +       sched_pc->vavavoom      = 0;
23256 +       sched_pc->token_time    = 0;
23257 +       sched_pc->idle_time     = 0;
23258 +       sched_pc->norm_time     = jiffies;
23259 +
23260 +       sched_pc->user_ticks = 0;
23261 +       sched_pc->sys_ticks = 0;
23262 +       sched_pc->hold_ticks = 0;
23263 +}
23264 +
23265 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
23266 +{
23267 +       return;
23268 +}
23269 +
23270 +static inline
23271 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
23272 +{
23273 +       return;
23274 +}
23275 diff -NurpP --minimal linux-2.6.36/kernel/vserver/sched_proc.h linux-2.6.36-vs2.3.0.36.33/kernel/vserver/sched_proc.h
23276 --- linux-2.6.36/kernel/vserver/sched_proc.h    1970-01-01 01:00:00.000000000 +0100
23277 +++ linux-2.6.36-vs2.3.0.36.33/kernel/vserver/sched_proc.h      2010-10-21 13:09:36.000000000 +0200
23278 @@ -0,0 +1,57 @@
23279 +#ifndef _VX_SCHED_PROC_H
23280 +#define _VX_SCHED_PROC_H
23281 +
23282 +
23283 +static inline
23284 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
23285 +{
23286 +       int length = 0;
23287 +
23288 +       length += sprintf(buffer,
23289 +               "FillRate:\t%8d,%d\n"
23290 +               "Interval:\t%8d,%d\n"
23291 +               "TokensMin:\t%8d\n"
23292 +               "TokensMax:\t%8d\n"
23293 +               "PrioBias:\t%8d\n",
23294 +               sched->fill_rate[0],
23295 +               sched->fill_rate[1],
23296 +               sched->interval[0],
23297 +               sched->interval[1],
23298 +               sched->tokens_min,
23299 +               sched->tokens_max,
23300 +               sched->prio_bias);
23301 +       return length;
23302 +}
23303 +
23304 +static inline
23305 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
23306 +       char *buffer, int cpu)
23307 +{
23308 +       int length = 0;
23309 +
23310 +       length += sprintf(buffer + length,
23311 +               "cpu %d: %lld %lld %lld %ld %ld", cpu,
23312 +               (unsigned long long)sched_pc->user_ticks,
23313 +               (unsigned long long)sched_pc->sys_ticks,
23314 +               (unsigned long long)sched_pc->hold_ticks,
23315 +               sched_pc->token_time,
23316 +               sched_pc->idle_time);
23317 +       length += sprintf(buffer + length,
23318 +               " %c%c %d %d %d %d/%d %d/%d",
23319 +               (sched_pc->flags & VXSF_ONHOLD) ? 'H' : 'R',
23320 +               (sched_pc->flags & VXSF_IDLE_TIME) ? 'I' : '-',
23321 +               sched_pc->tokens,
23322 +               sched_pc->tokens_min,
23323 +               sched_pc->tokens_max,
23324 +               sched_pc->fill_rate[0],
23325 +               sched_pc->interval[0],
23326 +               sched_pc->fill_rate[1],
23327 +               sched_pc->interval[1]);
23328 +       length += sprintf(buffer + length,
23329 +               " %d %d\n",
23330 +               sched_pc->prio_bias,
23331 +               sched_pc->vavavoom);
23332 +       return length;
23333 +}
23334 +
23335 +#endif /* _VX_SCHED_PROC_H */
23336 diff -NurpP --minimal linux-2.6.36/kernel/vserver/signal.c linux-2.6.36-vs2.3.0.36.33/kernel/vserver/signal.c
23337 --- linux-2.6.36/kernel/vserver/signal.c        1970-01-01 01:00:00.000000000 +0100
23338 +++ linux-2.6.36-vs2.3.0.36.33/kernel/vserver/signal.c  2010-10-21 13:09:36.000000000 +0200
23339 @@ -0,0 +1,132 @@
23340 +/*
23341 + *  linux/kernel/vserver/signal.c
23342 + *
23343 + *  Virtual Server: Signal Support
23344 + *
23345 + *  Copyright (C) 2003-2007  Herbert Pötzl
23346 + *
23347 + *  V0.01  broken out from vcontext V0.05
23348 + *  V0.02  changed vcmds to vxi arg
23349 + *  V0.03  adjusted siginfo for kill
23350 + *
23351 + */
23352 +
23353 +#include <asm/uaccess.h>
23354 +
23355 +#include <linux/vs_context.h>
23356 +#include <linux/vs_pid.h>
23357 +#include <linux/vserver/signal_cmd.h>
23358 +
23359 +
23360 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
23361 +{
23362 +       int retval, count = 0;
23363 +       struct task_struct *p;
23364 +       struct siginfo *sip = SEND_SIG_PRIV;
23365 +
23366 +       retval = -ESRCH;
23367 +       vxdprintk(VXD_CBIT(misc, 4),
23368 +               "vx_info_kill(%p[#%d],%d,%d)*",
23369 +               vxi, vxi->vx_id, pid, sig);
23370 +       read_lock(&tasklist_lock);
23371 +       switch (pid) {
23372 +       case  0:
23373 +       case -1:
23374 +               for_each_process(p) {
23375 +                       int err = 0;
23376 +
23377 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
23378 +                               (pid && vxi->vx_initpid == p->pid))
23379 +                               continue;
23380 +
23381 +                       err = group_send_sig_info(sig, sip, p);
23382 +                       ++count;
23383 +                       if (err != -EPERM)
23384 +                               retval = err;
23385 +               }
23386 +               break;
23387 +
23388 +       case 1:
23389 +               if (vxi->vx_initpid) {
23390 +                       pid = vxi->vx_initpid;
23391 +                       /* for now, only SIGINT to private init ... */
23392 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
23393 +                               /* ... as long as there are tasks left */
23394 +                               (atomic_read(&vxi->vx_tasks) > 1))
23395 +                               sig = SIGINT;
23396 +               }
23397 +               /* fallthrough */
23398 +       default:
23399 +               p = find_task_by_real_pid(pid);
23400 +               if (p) {
23401 +                       if (vx_task_xid(p) == vxi->vx_id)
23402 +                               retval = group_send_sig_info(sig, sip, p);
23403 +               }
23404 +               break;
23405 +       }
23406 +       read_unlock(&tasklist_lock);
23407 +       vxdprintk(VXD_CBIT(misc, 4),
23408 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
23409 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
23410 +       return retval;
23411 +}
23412 +
23413 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
23414 +{
23415 +       struct vcmd_ctx_kill_v0 vc_data;
23416 +
23417 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
23418 +               return -EFAULT;
23419 +
23420 +       /* special check to allow guest shutdown */
23421 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
23422 +               /* forbid killall pid=0 when init is present */
23423 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
23424 +               (vc_data.pid > 1)))
23425 +               return -EACCES;
23426 +
23427 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
23428 +}
23429 +
23430 +
23431 +static int __wait_exit(struct vx_info *vxi)
23432 +{
23433 +       DECLARE_WAITQUEUE(wait, current);
23434 +       int ret = 0;
23435 +
23436 +       add_wait_queue(&vxi->vx_wait, &wait);
23437 +       set_current_state(TASK_INTERRUPTIBLE);
23438 +
23439 +wait:
23440 +       if (vx_info_state(vxi,
23441 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
23442 +               goto out;
23443 +       if (signal_pending(current)) {
23444 +               ret = -ERESTARTSYS;
23445 +               goto out;
23446 +       }
23447 +       schedule();
23448 +       goto wait;
23449 +
23450 +out:
23451 +       set_current_state(TASK_RUNNING);
23452 +       remove_wait_queue(&vxi->vx_wait, &wait);
23453 +       return ret;
23454 +}
23455 +
23456 +
23457 +
23458 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
23459 +{
23460 +       struct vcmd_wait_exit_v0 vc_data;
23461 +       int ret;
23462 +
23463 +       ret = __wait_exit(vxi);
23464 +       vc_data.reboot_cmd = vxi->reboot_cmd;
23465 +       vc_data.exit_code = vxi->exit_code;
23466 +
23467 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
23468 +               ret = -EFAULT;
23469 +       return ret;
23470 +}
23471 +
23472 diff -NurpP --minimal linux-2.6.36/kernel/vserver/space.c linux-2.6.36-vs2.3.0.36.33/kernel/vserver/space.c
23473 --- linux-2.6.36/kernel/vserver/space.c 1970-01-01 01:00:00.000000000 +0100
23474 +++ linux-2.6.36-vs2.3.0.36.33/kernel/vserver/space.c   2010-10-21 14:41:06.000000000 +0200
23475 @@ -0,0 +1,375 @@
23476 +/*
23477 + *  linux/kernel/vserver/space.c
23478 + *
23479 + *  Virtual Server: Context Space Support
23480 + *
23481 + *  Copyright (C) 2003-2007  Herbert Pötzl
23482 + *
23483 + *  V0.01  broken out from context.c 0.07
23484 + *  V0.02  added task locking for namespace
23485 + *  V0.03  broken out vx_enter_namespace
23486 + *  V0.04  added *space support and commands
23487 + *
23488 + */
23489 +
23490 +#include <linux/utsname.h>
23491 +#include <linux/nsproxy.h>
23492 +#include <linux/err.h>
23493 +#include <linux/fs_struct.h>
23494 +#include <asm/uaccess.h>
23495 +
23496 +#include <linux/vs_context.h>
23497 +#include <linux/vserver/space.h>
23498 +#include <linux/vserver/space_cmd.h>
23499 +
23500 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
23501 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
23502 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
23503 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
23504 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
23505 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
23506 +
23507 +
23508 +/* namespace functions */
23509 +
23510 +#include <linux/mnt_namespace.h>
23511 +#include <linux/user_namespace.h>
23512 +#include <linux/pid_namespace.h>
23513 +#include <linux/ipc_namespace.h>
23514 +#include <net/net_namespace.h>
23515 +
23516 +
23517 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
23518 +       .mask = CLONE_FS |
23519 +               CLONE_NEWNS |
23520 +               CLONE_NEWUTS |
23521 +               CLONE_NEWIPC |
23522 +               CLONE_NEWUSER |
23523 +               0
23524 +};
23525 +
23526 +static const struct vcmd_space_mask_v1 space_mask = {
23527 +       .mask = CLONE_FS |
23528 +               CLONE_NEWNS |
23529 +               CLONE_NEWUTS |
23530 +               CLONE_NEWIPC |
23531 +               CLONE_NEWUSER |
23532 +#ifdef CONFIG_PID_NS
23533 +               CLONE_NEWPID |
23534 +#endif
23535 +#ifdef CONFIG_NET_NS
23536 +               CLONE_NEWNET |
23537 +#endif
23538 +               0
23539 +};
23540 +
23541 +static const struct vcmd_space_mask_v1 default_space_mask = {
23542 +       .mask = CLONE_FS |
23543 +               CLONE_NEWNS |
23544 +               CLONE_NEWUTS |
23545 +               CLONE_NEWIPC |
23546 +               CLONE_NEWUSER |
23547 +#ifdef CONFIG_PID_NS
23548 +//             CLONE_NEWPID |
23549 +#endif
23550 +               0
23551 +};
23552 +
23553 +/*
23554 + *     build a new nsproxy mix
23555 + *      assumes that both proxies are 'const'
23556 + *     does not touch nsproxy refcounts
23557 + *     will hold a reference on the result.
23558 + */
23559 +
23560 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
23561 +       struct nsproxy *new_nsproxy, unsigned long mask)
23562 +{
23563 +       struct mnt_namespace *old_ns;
23564 +       struct uts_namespace *old_uts;
23565 +       struct ipc_namespace *old_ipc;
23566 +#ifdef CONFIG_PID_NS
23567 +       struct pid_namespace *old_pid;
23568 +#endif
23569 +#ifdef CONFIG_NET_NS
23570 +       struct net *old_net;
23571 +#endif
23572 +       struct nsproxy *nsproxy;
23573 +
23574 +       nsproxy = copy_nsproxy(old_nsproxy);
23575 +       if (!nsproxy)
23576 +               goto out;
23577 +
23578 +       if (mask & CLONE_NEWNS) {
23579 +               old_ns = nsproxy->mnt_ns;
23580 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
23581 +               if (nsproxy->mnt_ns)
23582 +                       get_mnt_ns(nsproxy->mnt_ns);
23583 +       } else
23584 +               old_ns = NULL;
23585 +
23586 +       if (mask & CLONE_NEWUTS) {
23587 +               old_uts = nsproxy->uts_ns;
23588 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
23589 +               if (nsproxy->uts_ns)
23590 +                       get_uts_ns(nsproxy->uts_ns);
23591 +       } else
23592 +               old_uts = NULL;
23593 +
23594 +       if (mask & CLONE_NEWIPC) {
23595 +               old_ipc = nsproxy->ipc_ns;
23596 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
23597 +               if (nsproxy->ipc_ns)
23598 +                       get_ipc_ns(nsproxy->ipc_ns);
23599 +       } else
23600 +               old_ipc = NULL;
23601 +
23602 +#ifdef CONFIG_PID_NS
23603 +       if (mask & CLONE_NEWPID) {
23604 +               old_pid = nsproxy->pid_ns;
23605 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
23606 +               if (nsproxy->pid_ns)
23607 +                       get_pid_ns(nsproxy->pid_ns);
23608 +       } else
23609 +               old_pid = NULL;
23610 +#endif
23611 +#ifdef CONFIG_NET_NS
23612 +       if (mask & CLONE_NEWNET) {
23613 +               old_net = nsproxy->net_ns;
23614 +               nsproxy->net_ns = new_nsproxy->net_ns;
23615 +               if (nsproxy->net_ns)
23616 +                       get_net(nsproxy->net_ns);
23617 +       } else
23618 +               old_net = NULL;
23619 +#endif
23620 +       if (old_ns)
23621 +               put_mnt_ns(old_ns);
23622 +       if (old_uts)
23623 +               put_uts_ns(old_uts);
23624 +       if (old_ipc)
23625 +               put_ipc_ns(old_ipc);
23626 +#ifdef CONFIG_PID_NS
23627 +       if (old_pid)
23628 +               put_pid_ns(old_pid);
23629 +#endif
23630 +#ifdef CONFIG_NET_NS
23631 +       if (old_net)
23632 +               put_net(old_net);
23633 +#endif
23634 +out:
23635 +       return nsproxy;
23636 +}
23637 +
23638 +
23639 +/*
23640 + *     merge two nsproxy structs into a new one.
23641 + *     will hold a reference on the result.
23642 + */
23643 +
23644 +static inline
23645 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
23646 +       struct nsproxy *proxy, unsigned long mask)
23647 +{
23648 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
23649 +
23650 +       if (!proxy)
23651 +               return NULL;
23652 +
23653 +       if (mask) {
23654 +               /* vs_mix_nsproxy returns with reference */
23655 +               return vs_mix_nsproxy(old ? old : &null_proxy,
23656 +                       proxy, mask);
23657 +       }
23658 +       get_nsproxy(proxy);
23659 +       return proxy;
23660 +}
23661 +
23662 +
23663 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
23664 +{
23665 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
23666 +       struct fs_struct *fs_cur, *fs = NULL;
23667 +       int ret, kill = 0;
23668 +
23669 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
23670 +               vxi, vxi->vx_id, mask, index);
23671 +
23672 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
23673 +               return -EACCES;
23674 +
23675 +       if (!mask)
23676 +               mask = vxi->vx_nsmask[index];
23677 +
23678 +       if ((mask & vxi->vx_nsmask[index]) != mask)
23679 +               return -EINVAL;
23680 +
23681 +       if (mask & CLONE_FS) {
23682 +               fs = copy_fs_struct(vxi->vx_fs[index]);
23683 +               if (!fs)
23684 +                       return -ENOMEM;
23685 +       }
23686 +       proxy = vxi->vx_nsproxy[index];
23687 +
23688 +       vxdprintk(VXD_CBIT(space, 9),
23689 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
23690 +               vxi, vxi->vx_id, mask, index, proxy, fs);
23691 +
23692 +       task_lock(current);
23693 +       fs_cur = current->fs;
23694 +
23695 +       if (mask & CLONE_FS) {
23696 +               spin_lock(&fs_cur->lock);
23697 +               current->fs = fs;
23698 +               kill = !--fs_cur->users;
23699 +               spin_unlock(&fs_cur->lock);
23700 +       }
23701 +
23702 +       proxy_cur = current->nsproxy;
23703 +       get_nsproxy(proxy_cur);
23704 +       task_unlock(current);
23705 +
23706 +       if (kill)
23707 +               free_fs_struct(fs_cur);
23708 +
23709 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
23710 +       if (IS_ERR(proxy_new)) {
23711 +               ret = PTR_ERR(proxy_new);
23712 +               goto out_put;
23713 +       }
23714 +
23715 +       proxy_new = xchg(&current->nsproxy, proxy_new);
23716 +       ret = 0;
23717 +
23718 +       if (proxy_new)
23719 +               put_nsproxy(proxy_new);
23720 +out_put:
23721 +       if (proxy_cur)
23722 +               put_nsproxy(proxy_cur);
23723 +       return ret;
23724 +}
23725 +
23726 +
23727 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
23728 +{
23729 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
23730 +       struct fs_struct *fs_vxi, *fs;
23731 +       int ret, kill = 0;
23732 +
23733 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
23734 +               vxi, vxi->vx_id, mask, index);
23735 +#if 0
23736 +       if (!mask)
23737 +               mask = default_space_mask.mask;
23738 +#endif
23739 +       if ((mask & space_mask.mask) != mask)
23740 +               return -EINVAL;
23741 +
23742 +       proxy_vxi = vxi->vx_nsproxy[index];
23743 +       fs_vxi = vxi->vx_fs[index];
23744 +
23745 +       if (mask & CLONE_FS) {
23746 +               fs = copy_fs_struct(current->fs);
23747 +               if (!fs)
23748 +                       return -ENOMEM;
23749 +       }
23750 +
23751 +       task_lock(current);
23752 +
23753 +       if (mask & CLONE_FS) {
23754 +               spin_lock(&fs_vxi->lock);
23755 +               vxi->vx_fs[index] = fs;
23756 +               kill = !--fs_vxi->users;
23757 +               spin_unlock(&fs_vxi->lock);
23758 +       }
23759 +
23760 +       proxy_cur = current->nsproxy;
23761 +       get_nsproxy(proxy_cur);
23762 +       task_unlock(current);
23763 +
23764 +       if (kill)
23765 +               free_fs_struct(fs_vxi);
23766 +
23767 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
23768 +       if (IS_ERR(proxy_new)) {
23769 +               ret = PTR_ERR(proxy_new);
23770 +               goto out_put;
23771 +       }
23772 +
23773 +       proxy_new = xchg(&vxi->vx_nsproxy[index], proxy_new);
23774 +       vxi->vx_nsmask[index] |= mask;
23775 +       ret = 0;
23776 +
23777 +       if (proxy_new)
23778 +               put_nsproxy(proxy_new);
23779 +out_put:
23780 +       if (proxy_cur)
23781 +               put_nsproxy(proxy_cur);
23782 +       return ret;
23783 +}
23784 +
23785 +
23786 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
23787 +{
23788 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
23789 +
23790 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23791 +               return -EFAULT;
23792 +
23793 +       return vx_enter_space(vxi, vc_data.mask, 0);
23794 +}
23795 +
23796 +int vc_enter_space(struct vx_info *vxi, void __user *data)
23797 +{
23798 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
23799 +
23800 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23801 +               return -EFAULT;
23802 +
23803 +       if (vc_data.index >= VX_SPACES)
23804 +               return -EINVAL;
23805 +
23806 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
23807 +}
23808 +
23809 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
23810 +{
23811 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
23812 +
23813 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23814 +               return -EFAULT;
23815 +
23816 +       return vx_set_space(vxi, vc_data.mask, 0);
23817 +}
23818 +
23819 +int vc_set_space(struct vx_info *vxi, void __user *data)
23820 +{
23821 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
23822 +
23823 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
23824 +               return -EFAULT;
23825 +
23826 +       if (vc_data.index >= VX_SPACES)
23827 +               return -EINVAL;
23828 +
23829 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
23830 +}
23831 +
23832 +int vc_get_space_mask(void __user *data, int type)
23833 +{
23834 +       const struct vcmd_space_mask_v1 *mask;
23835 +
23836 +       if (type == 0)
23837 +               mask = &space_mask_v0;
23838 +       else if (type == 1)
23839 +               mask = &space_mask;
23840 +       else
23841 +               mask = &default_space_mask;
23842 +
23843 +       vxdprintk(VXD_CBIT(space, 10),
23844 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
23845 +
23846 +       if (copy_to_user(data, mask, sizeof(*mask)))
23847 +               return -EFAULT;
23848 +       return 0;
23849 +}
23850 +
23851 diff -NurpP --minimal linux-2.6.36/kernel/vserver/switch.c linux-2.6.36-vs2.3.0.36.33/kernel/vserver/switch.c
23852 --- linux-2.6.36/kernel/vserver/switch.c        1970-01-01 01:00:00.000000000 +0100
23853 +++ linux-2.6.36-vs2.3.0.36.33/kernel/vserver/switch.c  2010-10-21 13:09:36.000000000 +0200
23854 @@ -0,0 +1,546 @@
23855 +/*
23856 + *  linux/kernel/vserver/switch.c
23857 + *
23858 + *  Virtual Server: Syscall Switch
23859 + *
23860 + *  Copyright (C) 2003-2007  Herbert Pötzl
23861 + *
23862 + *  V0.01  syscall switch
23863 + *  V0.02  added signal to context
23864 + *  V0.03  added rlimit functions
23865 + *  V0.04  added iattr, task/xid functions
23866 + *  V0.05  added debug/history stuff
23867 + *  V0.06  added compat32 layer
23868 + *  V0.07  vcmd args and perms
23869 + *  V0.08  added status commands
23870 + *  V0.09  added tag commands
23871 + *  V0.10  added oom bias
23872 + *  V0.11  added device commands
23873 + *
23874 + */
23875 +
23876 +#include <linux/vs_context.h>
23877 +#include <linux/vs_network.h>
23878 +#include <linux/vserver/switch.h>
23879 +
23880 +#include "vci_config.h"
23881 +
23882 +
23883 +static inline
23884 +int vc_get_version(uint32_t id)
23885 +{
23886 +       return VCI_VERSION;
23887 +}
23888 +
23889 +static inline
23890 +int vc_get_vci(uint32_t id)
23891 +{
23892 +       return vci_kernel_config();
23893 +}
23894 +
23895 +#include <linux/vserver/context_cmd.h>
23896 +#include <linux/vserver/cvirt_cmd.h>
23897 +#include <linux/vserver/cacct_cmd.h>
23898 +#include <linux/vserver/limit_cmd.h>
23899 +#include <linux/vserver/network_cmd.h>
23900 +#include <linux/vserver/sched_cmd.h>
23901 +#include <linux/vserver/debug_cmd.h>
23902 +#include <linux/vserver/inode_cmd.h>
23903 +#include <linux/vserver/dlimit_cmd.h>
23904 +#include <linux/vserver/signal_cmd.h>
23905 +#include <linux/vserver/space_cmd.h>
23906 +#include <linux/vserver/tag_cmd.h>
23907 +#include <linux/vserver/device_cmd.h>
23908 +
23909 +#include <linux/vserver/inode.h>
23910 +#include <linux/vserver/dlimit.h>
23911 +
23912 +
23913 +#ifdef CONFIG_COMPAT
23914 +#define __COMPAT(name, id, data, compat)       \
23915 +       (compat) ? name ## _x32(id, data) : name(id, data)
23916 +#define __COMPAT_NO_ID(name, data, compat)     \
23917 +       (compat) ? name ## _x32(data) : name(data)
23918 +#else
23919 +#define __COMPAT(name, id, data, compat)       \
23920 +       name(id, data)
23921 +#define __COMPAT_NO_ID(name, data, compat)     \
23922 +       name(data)
23923 +#endif
23924 +
23925 +
23926 +static inline
23927 +long do_vcmd(uint32_t cmd, uint32_t id,
23928 +       struct vx_info *vxi, struct nx_info *nxi,
23929 +       void __user *data, int compat)
23930 +{
23931 +       switch (cmd) {
23932 +
23933 +       case VCMD_get_version:
23934 +               return vc_get_version(id);
23935 +       case VCMD_get_vci:
23936 +               return vc_get_vci(id);
23937 +
23938 +       case VCMD_task_xid:
23939 +               return vc_task_xid(id);
23940 +       case VCMD_vx_info:
23941 +               return vc_vx_info(vxi, data);
23942 +
23943 +       case VCMD_task_nid:
23944 +               return vc_task_nid(id);
23945 +       case VCMD_nx_info:
23946 +               return vc_nx_info(nxi, data);
23947 +
23948 +       case VCMD_task_tag:
23949 +               return vc_task_tag(id);
23950 +
23951 +       case VCMD_set_space_v1:
23952 +               return vc_set_space_v1(vxi, data);
23953 +       /* this is version 2 */
23954 +       case VCMD_set_space:
23955 +               return vc_set_space(vxi, data);
23956 +
23957 +       case VCMD_get_space_mask_v0:
23958 +               return vc_get_space_mask(data, 0);
23959 +       /* this is version 1 */
23960 +       case VCMD_get_space_mask:
23961 +               return vc_get_space_mask(data, 1);
23962 +
23963 +       case VCMD_get_space_default:
23964 +               return vc_get_space_mask(data, -1);
23965 +
23966 +#ifdef CONFIG_IA32_EMULATION
23967 +       case VCMD_get_rlimit:
23968 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
23969 +       case VCMD_set_rlimit:
23970 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
23971 +#else
23972 +       case VCMD_get_rlimit:
23973 +               return vc_get_rlimit(vxi, data);
23974 +       case VCMD_set_rlimit:
23975 +               return vc_set_rlimit(vxi, data);
23976 +#endif
23977 +       case VCMD_get_rlimit_mask:
23978 +               return vc_get_rlimit_mask(id, data);
23979 +       case VCMD_reset_hits:
23980 +               return vc_reset_hits(vxi, data);
23981 +       case VCMD_reset_minmax:
23982 +               return vc_reset_minmax(vxi, data);
23983 +
23984 +       case VCMD_get_vhi_name:
23985 +               return vc_get_vhi_name(vxi, data);
23986 +       case VCMD_set_vhi_name:
23987 +               return vc_set_vhi_name(vxi, data);
23988 +
23989 +       case VCMD_ctx_stat:
23990 +               return vc_ctx_stat(vxi, data);
23991 +       case VCMD_virt_stat:
23992 +               return vc_virt_stat(vxi, data);
23993 +       case VCMD_sock_stat:
23994 +               return vc_sock_stat(vxi, data);
23995 +       case VCMD_rlimit_stat:
23996 +               return vc_rlimit_stat(vxi, data);
23997 +
23998 +       case VCMD_set_cflags:
23999 +               return vc_set_cflags(vxi, data);
24000 +       case VCMD_get_cflags:
24001 +               return vc_get_cflags(vxi, data);
24002 +
24003 +       /* this is version 1 */
24004 +       case VCMD_set_ccaps:
24005 +               return vc_set_ccaps(vxi, data);
24006 +       /* this is version 1 */
24007 +       case VCMD_get_ccaps:
24008 +               return vc_get_ccaps(vxi, data);
24009 +       case VCMD_set_bcaps:
24010 +               return vc_set_bcaps(vxi, data);
24011 +       case VCMD_get_bcaps:
24012 +               return vc_get_bcaps(vxi, data);
24013 +
24014 +       case VCMD_set_badness:
24015 +               return vc_set_badness(vxi, data);
24016 +       case VCMD_get_badness:
24017 +               return vc_get_badness(vxi, data);
24018 +
24019 +       case VCMD_set_nflags:
24020 +               return vc_set_nflags(nxi, data);
24021 +       case VCMD_get_nflags:
24022 +               return vc_get_nflags(nxi, data);
24023 +
24024 +       case VCMD_set_ncaps:
24025 +               return vc_set_ncaps(nxi, data);
24026 +       case VCMD_get_ncaps:
24027 +               return vc_get_ncaps(nxi, data);
24028 +
24029 +       case VCMD_set_sched_v4:
24030 +               return vc_set_sched_v4(vxi, data);
24031 +       /* this is version 5 */
24032 +       case VCMD_set_sched:
24033 +               return vc_set_sched(vxi, data);
24034 +       case VCMD_get_sched:
24035 +               return vc_get_sched(vxi, data);
24036 +       case VCMD_sched_info:
24037 +               return vc_sched_info(vxi, data);
24038 +
24039 +       case VCMD_add_dlimit:
24040 +               return __COMPAT(vc_add_dlimit, id, data, compat);
24041 +       case VCMD_rem_dlimit:
24042 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
24043 +       case VCMD_set_dlimit:
24044 +               return __COMPAT(vc_set_dlimit, id, data, compat);
24045 +       case VCMD_get_dlimit:
24046 +               return __COMPAT(vc_get_dlimit, id, data, compat);
24047 +
24048 +       case VCMD_ctx_kill:
24049 +               return vc_ctx_kill(vxi, data);
24050 +
24051 +       case VCMD_wait_exit:
24052 +               return vc_wait_exit(vxi, data);
24053 +
24054 +       case VCMD_get_iattr:
24055 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
24056 +       case VCMD_set_iattr:
24057 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
24058 +
24059 +       case VCMD_fget_iattr:
24060 +               return vc_fget_iattr(id, data);
24061 +       case VCMD_fset_iattr:
24062 +               return vc_fset_iattr(id, data);
24063 +
24064 +       case VCMD_enter_space_v0:
24065 +               return vc_enter_space_v1(vxi, NULL);
24066 +       case VCMD_enter_space_v1:
24067 +               return vc_enter_space_v1(vxi, data);
24068 +       /* this is version 2 */
24069 +       case VCMD_enter_space:
24070 +               return vc_enter_space(vxi, data);
24071 +
24072 +       case VCMD_ctx_create_v0:
24073 +               return vc_ctx_create(id, NULL);
24074 +       case VCMD_ctx_create:
24075 +               return vc_ctx_create(id, data);
24076 +       case VCMD_ctx_migrate_v0:
24077 +               return vc_ctx_migrate(vxi, NULL);
24078 +       case VCMD_ctx_migrate:
24079 +               return vc_ctx_migrate(vxi, data);
24080 +
24081 +       case VCMD_net_create_v0:
24082 +               return vc_net_create(id, NULL);
24083 +       case VCMD_net_create:
24084 +               return vc_net_create(id, data);
24085 +       case VCMD_net_migrate:
24086 +               return vc_net_migrate(nxi, data);
24087 +
24088 +       case VCMD_tag_migrate:
24089 +               return vc_tag_migrate(id);
24090 +
24091 +       case VCMD_net_add:
24092 +               return vc_net_add(nxi, data);
24093 +       case VCMD_net_remove:
24094 +               return vc_net_remove(nxi, data);
24095 +
24096 +       case VCMD_net_add_ipv4:
24097 +               return vc_net_add_ipv4(nxi, data);
24098 +       case VCMD_net_remove_ipv4:
24099 +               return vc_net_remove_ipv4(nxi, data);
24100 +#ifdef CONFIG_IPV6
24101 +       case VCMD_net_add_ipv6:
24102 +               return vc_net_add_ipv6(nxi, data);
24103 +       case VCMD_net_remove_ipv6:
24104 +               return vc_net_remove_ipv6(nxi, data);
24105 +#endif
24106 +/*     case VCMD_add_match_ipv4:
24107 +               return vc_add_match_ipv4(nxi, data);
24108 +       case VCMD_get_match_ipv4:
24109 +               return vc_get_match_ipv4(nxi, data);
24110 +#ifdef CONFIG_IPV6
24111 +       case VCMD_add_match_ipv6:
24112 +               return vc_add_match_ipv6(nxi, data);
24113 +       case VCMD_get_match_ipv6:
24114 +               return vc_get_match_ipv6(nxi, data);
24115 +#endif */
24116 +
24117 +#ifdef CONFIG_VSERVER_DEVICE
24118 +       case VCMD_set_mapping:
24119 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
24120 +       case VCMD_unset_mapping:
24121 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
24122 +#endif
24123 +#ifdef CONFIG_VSERVER_HISTORY
24124 +       case VCMD_dump_history:
24125 +               return vc_dump_history(id);
24126 +       case VCMD_read_history:
24127 +               return __COMPAT(vc_read_history, id, data, compat);
24128 +#endif
24129 +#ifdef CONFIG_VSERVER_MONITOR
24130 +       case VCMD_read_monitor:
24131 +               return __COMPAT(vc_read_monitor, id, data, compat);
24132 +#endif
24133 +       default:
24134 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
24135 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
24136 +       }
24137 +       return -ENOSYS;
24138 +}
24139 +
24140 +
24141 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
24142 +       case VCMD_ ## vcmd: perm = _perm;               \
24143 +               args = _args; flags = _flags; break
24144 +
24145 +
24146 +#define VCA_NONE       0x00
24147 +#define VCA_VXI                0x01
24148 +#define VCA_NXI                0x02
24149 +
24150 +#define VCF_NONE       0x00
24151 +#define VCF_INFO       0x01
24152 +#define VCF_ADMIN      0x02
24153 +#define VCF_ARES       0x06    /* includes admin */
24154 +#define VCF_SETUP      0x08
24155 +
24156 +#define VCF_ZIDOK      0x10    /* zero id okay */
24157 +
24158 +
24159 +static inline
24160 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
24161 +{
24162 +       long ret;
24163 +       int permit = -1, state = 0;
24164 +       int perm = -1, args = 0, flags = 0;
24165 +       struct vx_info *vxi = NULL;
24166 +       struct nx_info *nxi = NULL;
24167 +
24168 +       switch (cmd) {
24169 +       /* unpriviledged commands */
24170 +       __VCMD(get_version,      0, VCA_NONE,   0);
24171 +       __VCMD(get_vci,          0, VCA_NONE,   0);
24172 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
24173 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
24174 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
24175 +       __VCMD(get_space_default,0, VCA_NONE,   0);
24176 +
24177 +       /* info commands */
24178 +       __VCMD(task_xid,         2, VCA_NONE,   0);
24179 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
24180 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
24181 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
24182 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
24183 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
24184 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
24185 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
24186 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
24187 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
24188 +
24189 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
24190 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
24191 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
24192 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
24193 +
24194 +       __VCMD(task_nid,         2, VCA_NONE,   0);
24195 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
24196 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
24197 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
24198 +
24199 +       __VCMD(task_tag,         2, VCA_NONE,   0);
24200 +
24201 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
24202 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
24203 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
24204 +       __VCMD(get_sched,        3, VCA_VXI,    VCF_INFO);
24205 +       __VCMD(sched_info,       3, VCA_VXI,    VCF_INFO | VCF_ZIDOK);
24206 +
24207 +       /* lower admin commands */
24208 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
24209 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
24210 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
24211 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
24212 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
24213 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
24214 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
24215 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
24216 +
24217 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
24218 +       __VCMD(net_create,       5, VCA_NONE,   0);
24219 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
24220 +
24221 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
24222 +
24223 +       /* higher admin commands */
24224 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
24225 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24226 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24227 +
24228 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24229 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24230 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24231 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24232 +
24233 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24234 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24235 +       __VCMD(set_sched,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24236 +       __VCMD(set_sched_v4,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
24237 +
24238 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
24239 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
24240 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
24241 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
24242 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
24243 +       __VCMD(net_remove_ipv4,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
24244 +#ifdef CONFIG_IPV6
24245 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
24246 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
24247 +#endif
24248 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
24249 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
24250 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
24251 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
24252 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
24253 +
24254 +#ifdef CONFIG_VSERVER_DEVICE
24255 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
24256 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
24257 +#endif
24258 +       /* debug level admin commands */
24259 +#ifdef CONFIG_VSERVER_HISTORY
24260 +       __VCMD(dump_history,     9, VCA_NONE,   0);
24261 +       __VCMD(read_history,     9, VCA_NONE,   0);
24262 +#endif
24263 +#ifdef CONFIG_VSERVER_MONITOR
24264 +       __VCMD(read_monitor,     9, VCA_NONE,   0);
24265 +#endif
24266 +
24267 +       default:
24268 +               perm = -1;
24269 +       }
24270 +
24271 +       vxdprintk(VXD_CBIT(switch, 0),
24272 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
24273 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
24274 +               VC_VERSION(cmd), id, data, compat,
24275 +               perm, args, flags);
24276 +
24277 +       ret = -ENOSYS;
24278 +       if (perm < 0)
24279 +               goto out;
24280 +
24281 +       state = 1;
24282 +       if (!capable(CAP_CONTEXT))
24283 +               goto out;
24284 +
24285 +       state = 2;
24286 +       /* moved here from the individual commands */
24287 +       ret = -EPERM;
24288 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
24289 +               goto out;
24290 +
24291 +       state = 3;
24292 +       /* vcmd involves resource management  */
24293 +       ret = -EPERM;
24294 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
24295 +               goto out;
24296 +
24297 +       state = 4;
24298 +       /* various legacy exceptions */
24299 +       switch (cmd) {
24300 +       /* will go away when spectator is a cap */
24301 +       case VCMD_ctx_migrate_v0:
24302 +       case VCMD_ctx_migrate:
24303 +               if (id == 1) {
24304 +                       current->xid = 1;
24305 +                       ret = 1;
24306 +                       goto out;
24307 +               }
24308 +               break;
24309 +
24310 +       /* will go away when spectator is a cap */
24311 +       case VCMD_net_migrate:
24312 +               if (id == 1) {
24313 +                       current->nid = 1;
24314 +                       ret = 1;
24315 +                       goto out;
24316 +               }
24317 +               break;
24318 +       }
24319 +
24320 +       /* vcmds are fine by default */
24321 +       permit = 1;
24322 +
24323 +       /* admin type vcmds require admin ... */
24324 +       if (flags & VCF_ADMIN)
24325 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
24326 +
24327 +       /* ... but setup type vcmds override that */
24328 +       if (!permit && (flags & VCF_SETUP))
24329 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
24330 +
24331 +       state = 5;
24332 +       ret = -EPERM;
24333 +       if (!permit)
24334 +               goto out;
24335 +
24336 +       state = 6;
24337 +       if (!id && (flags & VCF_ZIDOK))
24338 +               goto skip_id;
24339 +
24340 +       ret = -ESRCH;
24341 +       if (args & VCA_VXI) {
24342 +               vxi = lookup_vx_info(id);
24343 +               if (!vxi)
24344 +                       goto out;
24345 +
24346 +               if ((flags & VCF_ADMIN) &&
24347 +                       /* special case kill for shutdown */
24348 +                       (cmd != VCMD_ctx_kill) &&
24349 +                       /* can context be administrated? */
24350 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
24351 +                       ret = -EACCES;
24352 +                       goto out_vxi;
24353 +               }
24354 +       }
24355 +       state = 7;
24356 +       if (args & VCA_NXI) {
24357 +               nxi = lookup_nx_info(id);
24358 +               if (!nxi)
24359 +                       goto out_vxi;
24360 +
24361 +               if ((flags & VCF_ADMIN) &&
24362 +                       /* can context be administrated? */
24363 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
24364 +                       ret = -EACCES;
24365 +                       goto out_nxi;
24366 +               }
24367 +       }
24368 +skip_id:
24369 +       state = 8;
24370 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
24371 +
24372 +out_nxi:
24373 +       if ((args & VCA_NXI) && nxi)
24374 +               put_nx_info(nxi);
24375 +out_vxi:
24376 +       if ((args & VCA_VXI) && vxi)
24377 +               put_vx_info(vxi);
24378 +out:
24379 +       vxdprintk(VXD_CBIT(switch, 1),
24380 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
24381 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
24382 +               VC_VERSION(cmd), ret, ret, state, permit);
24383 +       return ret;
24384 +}
24385 +
24386 +asmlinkage long
24387 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
24388 +{
24389 +       return do_vserver(cmd, id, data, 0);
24390 +}
24391 +
24392 +#ifdef CONFIG_COMPAT
24393 +
24394 +asmlinkage long
24395 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
24396 +{
24397 +       return do_vserver(cmd, id, data, 1);
24398 +}
24399 +
24400 +#endif /* CONFIG_COMPAT */
24401 diff -NurpP --minimal linux-2.6.36/kernel/vserver/sysctl.c linux-2.6.36-vs2.3.0.36.33/kernel/vserver/sysctl.c
24402 --- linux-2.6.36/kernel/vserver/sysctl.c        1970-01-01 01:00:00.000000000 +0100
24403 +++ linux-2.6.36-vs2.3.0.36.33/kernel/vserver/sysctl.c  2010-10-21 13:09:36.000000000 +0200
24404 @@ -0,0 +1,241 @@
24405 +/*
24406 + *  kernel/vserver/sysctl.c
24407 + *
24408 + *  Virtual Context Support
24409 + *
24410 + *  Copyright (C) 2004-2007  Herbert Pötzl
24411 + *
24412 + *  V0.01  basic structure
24413 + *
24414 + */
24415 +
24416 +#include <linux/module.h>
24417 +#include <linux/ctype.h>
24418 +#include <linux/sysctl.h>
24419 +#include <linux/parser.h>
24420 +#include <asm/uaccess.h>
24421 +
24422 +enum {
24423 +       CTL_DEBUG_ERROR         = 0,
24424 +       CTL_DEBUG_SWITCH        = 1,
24425 +       CTL_DEBUG_XID,
24426 +       CTL_DEBUG_NID,
24427 +       CTL_DEBUG_TAG,
24428 +       CTL_DEBUG_NET,
24429 +       CTL_DEBUG_LIMIT,
24430 +       CTL_DEBUG_CRES,
24431 +       CTL_DEBUG_DLIM,
24432 +       CTL_DEBUG_QUOTA,
24433 +       CTL_DEBUG_CVIRT,
24434 +       CTL_DEBUG_SPACE,
24435 +       CTL_DEBUG_MISC,
24436 +};
24437 +
24438 +
24439 +unsigned int vx_debug_switch   = 0;
24440 +unsigned int vx_debug_xid      = 0;
24441 +unsigned int vx_debug_nid      = 0;
24442 +unsigned int vx_debug_tag      = 0;
24443 +unsigned int vx_debug_net      = 0;
24444 +unsigned int vx_debug_limit    = 0;
24445 +unsigned int vx_debug_cres     = 0;
24446 +unsigned int vx_debug_dlim     = 0;
24447 +unsigned int vx_debug_quota    = 0;
24448 +unsigned int vx_debug_cvirt    = 0;
24449 +unsigned int vx_debug_space    = 0;
24450 +unsigned int vx_debug_misc     = 0;
24451 +
24452 +
24453 +static struct ctl_table_header *vserver_table_header;
24454 +static ctl_table vserver_root_table[];
24455 +
24456 +
24457 +void vserver_register_sysctl(void)
24458 +{
24459 +       if (!vserver_table_header) {
24460 +               vserver_table_header = register_sysctl_table(vserver_root_table);
24461 +       }
24462 +
24463 +}
24464 +
24465 +void vserver_unregister_sysctl(void)
24466 +{
24467 +       if (vserver_table_header) {
24468 +               unregister_sysctl_table(vserver_table_header);
24469 +               vserver_table_header = NULL;
24470 +       }
24471 +}
24472 +
24473 +
24474 +static int proc_dodebug(ctl_table *table, int write,
24475 +       void __user *buffer, size_t *lenp, loff_t *ppos)
24476 +{
24477 +       char            tmpbuf[20], *p, c;
24478 +       unsigned int    value;
24479 +       size_t          left, len;
24480 +
24481 +       if ((*ppos && !write) || !*lenp) {
24482 +               *lenp = 0;
24483 +               return 0;
24484 +       }
24485 +
24486 +       left = *lenp;
24487 +
24488 +       if (write) {
24489 +               if (!access_ok(VERIFY_READ, buffer, left))
24490 +                       return -EFAULT;
24491 +               p = (char *)buffer;
24492 +               while (left && __get_user(c, p) >= 0 && isspace(c))
24493 +                       left--, p++;
24494 +               if (!left)
24495 +                       goto done;
24496 +
24497 +               if (left > sizeof(tmpbuf) - 1)
24498 +                       return -EINVAL;
24499 +               if (copy_from_user(tmpbuf, p, left))
24500 +                       return -EFAULT;
24501 +               tmpbuf[left] = '\0';
24502 +
24503 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
24504 +                       value = 10 * value + (*p - '0');
24505 +               if (*p && !isspace(*p))
24506 +                       return -EINVAL;
24507 +               while (left && isspace(*p))
24508 +                       left--, p++;
24509 +               *(unsigned int *)table->data = value;
24510 +       } else {
24511 +               if (!access_ok(VERIFY_WRITE, buffer, left))
24512 +                       return -EFAULT;
24513 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
24514 +               if (len > left)
24515 +                       len = left;
24516 +               if (__copy_to_user(buffer, tmpbuf, len))
24517 +                       return -EFAULT;
24518 +               if ((left -= len) > 0) {
24519 +                       if (put_user('\n', (char *)buffer + len))
24520 +                               return -EFAULT;
24521 +                       left--;
24522 +               }
24523 +       }
24524 +
24525 +done:
24526 +       *lenp -= left;
24527 +       *ppos += *lenp;
24528 +       return 0;
24529 +}
24530 +
24531 +static int zero;
24532 +
24533 +#define        CTL_ENTRY(ctl, name)                            \
24534 +       {                                               \
24535 +               .procname       = #name,                \
24536 +               .data           = &vx_ ## name,         \
24537 +               .maxlen         = sizeof(int),          \
24538 +               .mode           = 0644,                 \
24539 +               .proc_handler   = &proc_dodebug,        \
24540 +               .extra1         = &zero,                \
24541 +               .extra2         = &zero,                \
24542 +       }
24543 +
24544 +static ctl_table vserver_debug_table[] = {
24545 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
24546 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
24547 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
24548 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
24549 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
24550 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
24551 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
24552 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
24553 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
24554 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
24555 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
24556 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
24557 +       { 0 }
24558 +};
24559 +
24560 +static ctl_table vserver_root_table[] = {
24561 +       {
24562 +               .procname       = "vserver",
24563 +               .mode           = 0555,
24564 +               .child          = vserver_debug_table
24565 +       },
24566 +       { 0 }
24567 +};
24568 +
24569 +
24570 +static match_table_t tokens = {
24571 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
24572 +       { CTL_DEBUG_XID,        "xid=%x"        },
24573 +       { CTL_DEBUG_NID,        "nid=%x"        },
24574 +       { CTL_DEBUG_TAG,        "tag=%x"        },
24575 +       { CTL_DEBUG_NET,        "net=%x"        },
24576 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
24577 +       { CTL_DEBUG_CRES,       "cres=%x"       },
24578 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
24579 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
24580 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
24581 +       { CTL_DEBUG_SPACE,      "space=%x"      },
24582 +       { CTL_DEBUG_MISC,       "misc=%x"       },
24583 +       { CTL_DEBUG_ERROR,      NULL            }
24584 +};
24585 +
24586 +#define        HANDLE_CASE(id, name, val)                              \
24587 +       case CTL_DEBUG_ ## id:                                  \
24588 +               vx_debug_ ## name = val;                        \
24589 +               printk("vs_debug_" #name "=0x%x\n", val);       \
24590 +               break
24591 +
24592 +
24593 +static int __init vs_debug_setup(char *str)
24594 +{
24595 +       char *p;
24596 +       int token;
24597 +
24598 +       printk("vs_debug_setup(%s)\n", str);
24599 +       while ((p = strsep(&str, ",")) != NULL) {
24600 +               substring_t args[MAX_OPT_ARGS];
24601 +               unsigned int value;
24602 +
24603 +               if (!*p)
24604 +                       continue;
24605 +
24606 +               token = match_token(p, tokens, args);
24607 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
24608 +
24609 +               switch (token) {
24610 +               HANDLE_CASE(SWITCH, switch, value);
24611 +               HANDLE_CASE(XID,    xid,    value);
24612 +               HANDLE_CASE(NID,    nid,    value);
24613 +               HANDLE_CASE(TAG,    tag,    value);
24614 +               HANDLE_CASE(NET,    net,    value);
24615 +               HANDLE_CASE(LIMIT,  limit,  value);
24616 +               HANDLE_CASE(CRES,   cres,   value);
24617 +               HANDLE_CASE(DLIM,   dlim,   value);
24618 +               HANDLE_CASE(QUOTA,  quota,  value);
24619 +               HANDLE_CASE(CVIRT,  cvirt,  value);
24620 +               HANDLE_CASE(SPACE,  space,  value);
24621 +               HANDLE_CASE(MISC,   misc,   value);
24622 +               default:
24623 +                       return -EINVAL;
24624 +                       break;
24625 +               }
24626 +       }
24627 +       return 1;
24628 +}
24629 +
24630 +__setup("vsdebug=", vs_debug_setup);
24631 +
24632 +
24633 +
24634 +EXPORT_SYMBOL_GPL(vx_debug_switch);
24635 +EXPORT_SYMBOL_GPL(vx_debug_xid);
24636 +EXPORT_SYMBOL_GPL(vx_debug_nid);
24637 +EXPORT_SYMBOL_GPL(vx_debug_net);
24638 +EXPORT_SYMBOL_GPL(vx_debug_limit);
24639 +EXPORT_SYMBOL_GPL(vx_debug_cres);
24640 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
24641 +EXPORT_SYMBOL_GPL(vx_debug_quota);
24642 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
24643 +EXPORT_SYMBOL_GPL(vx_debug_space);
24644 +EXPORT_SYMBOL_GPL(vx_debug_misc);
24645 +
24646 diff -NurpP --minimal linux-2.6.36/kernel/vserver/tag.c linux-2.6.36-vs2.3.0.36.33/kernel/vserver/tag.c
24647 --- linux-2.6.36/kernel/vserver/tag.c   1970-01-01 01:00:00.000000000 +0100
24648 +++ linux-2.6.36-vs2.3.0.36.33/kernel/vserver/tag.c     2010-10-21 13:09:36.000000000 +0200
24649 @@ -0,0 +1,63 @@
24650 +/*
24651 + *  linux/kernel/vserver/tag.c
24652 + *
24653 + *  Virtual Server: Shallow Tag Space
24654 + *
24655 + *  Copyright (C) 2007  Herbert Pötzl
24656 + *
24657 + *  V0.01  basic implementation
24658 + *
24659 + */
24660 +
24661 +#include <linux/sched.h>
24662 +#include <linux/vserver/debug.h>
24663 +#include <linux/vs_pid.h>
24664 +#include <linux/vs_tag.h>
24665 +
24666 +#include <linux/vserver/tag_cmd.h>
24667 +
24668 +
24669 +int dx_migrate_task(struct task_struct *p, tag_t tag)
24670 +{
24671 +       if (!p)
24672 +               BUG();
24673 +
24674 +       vxdprintk(VXD_CBIT(tag, 5),
24675 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
24676 +
24677 +       task_lock(p);
24678 +       p->tag = tag;
24679 +       task_unlock(p);
24680 +
24681 +       vxdprintk(VXD_CBIT(tag, 5),
24682 +               "moved task %p into [#%d]", p, tag);
24683 +       return 0;
24684 +}
24685 +
24686 +/* vserver syscall commands below here */
24687 +
24688 +/* taks xid and vx_info functions */
24689 +
24690 +
24691 +int vc_task_tag(uint32_t id)
24692 +{
24693 +       tag_t tag;
24694 +
24695 +       if (id) {
24696 +               struct task_struct *tsk;
24697 +               read_lock(&tasklist_lock);
24698 +               tsk = find_task_by_real_pid(id);
24699 +               tag = (tsk) ? tsk->tag : -ESRCH;
24700 +               read_unlock(&tasklist_lock);
24701 +       } else
24702 +               tag = dx_current_tag();
24703 +       return tag;
24704 +}
24705 +
24706 +
24707 +int vc_tag_migrate(uint32_t tag)
24708 +{
24709 +       return dx_migrate_task(current, tag & 0xFFFF);
24710 +}
24711 +
24712 +
24713 diff -NurpP --minimal linux-2.6.36/kernel/vserver/vci_config.h linux-2.6.36-vs2.3.0.36.33/kernel/vserver/vci_config.h
24714 --- linux-2.6.36/kernel/vserver/vci_config.h    1970-01-01 01:00:00.000000000 +0100
24715 +++ linux-2.6.36-vs2.3.0.36.33/kernel/vserver/vci_config.h      2010-10-21 13:09:36.000000000 +0200
24716 @@ -0,0 +1,85 @@
24717 +
24718 +/*  interface version */
24719 +
24720 +#define VCI_VERSION            0x00020306
24721 +
24722 +
24723 +enum {
24724 +       VCI_KCBIT_NO_DYNAMIC = 0,
24725 +
24726 +       VCI_KCBIT_PROC_SECURE = 4,
24727 +       VCI_KCBIT_HARDCPU = 5,
24728 +       VCI_KCBIT_IDLELIMIT = 6,
24729 +       VCI_KCBIT_IDLETIME = 7,
24730 +
24731 +       VCI_KCBIT_COWBL = 8,
24732 +       VCI_KCBIT_FULLCOWBL = 9,
24733 +       VCI_KCBIT_SPACES = 10,
24734 +       VCI_KCBIT_NETV2 = 11,
24735 +       VCI_KCBIT_MEMCG = 12,
24736 +
24737 +       VCI_KCBIT_DEBUG = 16,
24738 +       VCI_KCBIT_HISTORY = 20,
24739 +       VCI_KCBIT_TAGGED = 24,
24740 +       VCI_KCBIT_PPTAG = 28,
24741 +
24742 +       VCI_KCBIT_MORE = 31,
24743 +};
24744 +
24745 +
24746 +static inline uint32_t vci_kernel_config(void)
24747 +{
24748 +       return
24749 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
24750 +
24751 +       /* configured features */
24752 +#ifdef CONFIG_VSERVER_PROC_SECURE
24753 +       (1 << VCI_KCBIT_PROC_SECURE) |
24754 +#endif
24755 +#ifdef CONFIG_VSERVER_HARDCPU
24756 +       (1 << VCI_KCBIT_HARDCPU) |
24757 +#endif
24758 +#ifdef CONFIG_VSERVER_IDLELIMIT
24759 +       (1 << VCI_KCBIT_IDLELIMIT) |
24760 +#endif
24761 +#ifdef CONFIG_VSERVER_IDLETIME
24762 +       (1 << VCI_KCBIT_IDLETIME) |
24763 +#endif
24764 +#ifdef CONFIG_VSERVER_COWBL
24765 +       (1 << VCI_KCBIT_COWBL) |
24766 +       (1 << VCI_KCBIT_FULLCOWBL) |
24767 +#endif
24768 +       (1 << VCI_KCBIT_SPACES) |
24769 +       (1 << VCI_KCBIT_NETV2) |
24770 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
24771 +       (1 << VCI_KCBIT_MEMCG) |
24772 +#endif
24773 +
24774 +       /* debug options */
24775 +#ifdef CONFIG_VSERVER_DEBUG
24776 +       (1 << VCI_KCBIT_DEBUG) |
24777 +#endif
24778 +#ifdef CONFIG_VSERVER_HISTORY
24779 +       (1 << VCI_KCBIT_HISTORY) |
24780 +#endif
24781 +
24782 +       /* inode context tagging */
24783 +#if    defined(CONFIG_TAGGING_NONE)
24784 +       (0 << VCI_KCBIT_TAGGED) |
24785 +#elif  defined(CONFIG_TAGGING_UID16)
24786 +       (1 << VCI_KCBIT_TAGGED) |
24787 +#elif  defined(CONFIG_TAGGING_GID16)
24788 +       (2 << VCI_KCBIT_TAGGED) |
24789 +#elif  defined(CONFIG_TAGGING_ID24)
24790 +       (3 << VCI_KCBIT_TAGGED) |
24791 +#elif  defined(CONFIG_TAGGING_INTERN)
24792 +       (4 << VCI_KCBIT_TAGGED) |
24793 +#elif  defined(CONFIG_TAGGING_RUNTIME)
24794 +       (5 << VCI_KCBIT_TAGGED) |
24795 +#else
24796 +       (7 << VCI_KCBIT_TAGGED) |
24797 +#endif
24798 +       (1 << VCI_KCBIT_PPTAG) |
24799 +       0;
24800 +}
24801 +
24802 diff -NurpP --minimal linux-2.6.36/mm/filemap_xip.c linux-2.6.36-vs2.3.0.36.33/mm/filemap_xip.c
24803 --- linux-2.6.36/mm/filemap_xip.c       2010-07-07 18:31:58.000000000 +0200
24804 +++ linux-2.6.36-vs2.3.0.36.33/mm/filemap_xip.c 2010-10-21 13:09:36.000000000 +0200
24805 @@ -18,6 +18,7 @@
24806  #include <linux/seqlock.h>
24807  #include <linux/mutex.h>
24808  #include <linux/gfp.h>
24809 +#include <linux/vs_memory.h>
24810  #include <asm/tlbflush.h>
24811  #include <asm/io.h>
24812  
24813 diff -NurpP --minimal linux-2.6.36/mm/fremap.c linux-2.6.36-vs2.3.0.36.33/mm/fremap.c
24814 --- linux-2.6.36/mm/fremap.c    2010-10-21 13:07:57.000000000 +0200
24815 +++ linux-2.6.36-vs2.3.0.36.33/mm/fremap.c      2010-10-21 13:09:36.000000000 +0200
24816 @@ -16,6 +16,7 @@
24817  #include <linux/module.h>
24818  #include <linux/syscalls.h>
24819  #include <linux/mmu_notifier.h>
24820 +#include <linux/vs_memory.h>
24821  
24822  #include <asm/mmu_context.h>
24823  #include <asm/cacheflush.h>
24824 diff -NurpP --minimal linux-2.6.36/mm/hugetlb.c linux-2.6.36-vs2.3.0.36.33/mm/hugetlb.c
24825 --- linux-2.6.36/mm/hugetlb.c   2010-10-21 13:07:57.000000000 +0200
24826 +++ linux-2.6.36-vs2.3.0.36.33/mm/hugetlb.c     2010-10-21 13:09:36.000000000 +0200
24827 @@ -28,6 +28,7 @@
24828  
24829  #include <linux/hugetlb.h>
24830  #include <linux/node.h>
24831 +#include <linux/vs_memory.h>
24832  #include "internal.h"
24833  
24834  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
24835 diff -NurpP --minimal linux-2.6.36/mm/memcontrol.c linux-2.6.36-vs2.3.0.36.33/mm/memcontrol.c
24836 --- linux-2.6.36/mm/memcontrol.c        2010-10-21 13:07:57.000000000 +0200
24837 +++ linux-2.6.36-vs2.3.0.36.33/mm/memcontrol.c  2010-10-21 13:09:36.000000000 +0200
24838 @@ -638,6 +638,31 @@ struct mem_cgroup *mem_cgroup_from_task(
24839                                 struct mem_cgroup, css);
24840  }
24841  
24842 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
24843 +{
24844 +       return res_counter_read_u64(&mem->res, member);
24845 +}
24846 +
24847 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
24848 +{
24849 +       return res_counter_read_u64(&mem->memsw, member);
24850 +}
24851 +
24852 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
24853 +{
24854 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
24855 +}
24856 +
24857 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
24858 +{
24859 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
24860 +}
24861 +
24862 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
24863 +{
24864 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
24865 +}
24866 +
24867  static struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
24868  {
24869         struct mem_cgroup *mem = NULL;
24870 diff -NurpP --minimal linux-2.6.36/mm/memory.c linux-2.6.36-vs2.3.0.36.33/mm/memory.c
24871 --- linux-2.6.36/mm/memory.c    2010-10-21 13:07:57.000000000 +0200
24872 +++ linux-2.6.36-vs2.3.0.36.33/mm/memory.c      2010-10-21 13:09:36.000000000 +0200
24873 @@ -3145,6 +3145,7 @@ static inline int handle_pte_fault(struc
24874  {
24875         pte_t entry;
24876         spinlock_t *ptl;
24877 +       int ret = 0, type = VXPT_UNKNOWN;
24878  
24879         entry = *pte;
24880         if (!pte_present(entry)) {
24881 @@ -3169,9 +3170,12 @@ static inline int handle_pte_fault(struc
24882         if (unlikely(!pte_same(*pte, entry)))
24883                 goto unlock;
24884         if (flags & FAULT_FLAG_WRITE) {
24885 -               if (!pte_write(entry))
24886 -                       return do_wp_page(mm, vma, address,
24887 +               if (!pte_write(entry)) {
24888 +                       ret = do_wp_page(mm, vma, address,
24889                                         pte, pmd, ptl, entry);
24890 +                       type = VXPT_WRITE;
24891 +                       goto out;
24892 +               }
24893                 entry = pte_mkdirty(entry);
24894         }
24895         entry = pte_mkyoung(entry);
24896 @@ -3189,7 +3193,10 @@ static inline int handle_pte_fault(struc
24897         }
24898  unlock:
24899         pte_unmap_unlock(pte, ptl);
24900 -       return 0;
24901 +       ret = 0;
24902 +out:
24903 +       vx_page_fault(mm, vma, type, ret);
24904 +       return ret;
24905  }
24906  
24907  /*
24908 diff -NurpP --minimal linux-2.6.36/mm/mremap.c linux-2.6.36-vs2.3.0.36.33/mm/mremap.c
24909 --- linux-2.6.36/mm/mremap.c    2010-07-07 18:31:58.000000000 +0200
24910 +++ linux-2.6.36-vs2.3.0.36.33/mm/mremap.c      2010-10-21 13:09:36.000000000 +0200
24911 @@ -19,6 +19,7 @@
24912  #include <linux/security.h>
24913  #include <linux/syscalls.h>
24914  #include <linux/mmu_notifier.h>
24915 +#include <linux/vs_memory.h>
24916  
24917  #include <asm/uaccess.h>
24918  #include <asm/cacheflush.h>
24919 diff -NurpP --minimal linux-2.6.36/mm/oom_kill.c linux-2.6.36-vs2.3.0.36.33/mm/oom_kill.c
24920 --- linux-2.6.36/mm/oom_kill.c  2010-10-21 13:07:57.000000000 +0200
24921 +++ linux-2.6.36-vs2.3.0.36.33/mm/oom_kill.c    2010-10-21 14:57:29.000000000 +0200
24922 @@ -31,6 +31,9 @@
24923  #include <linux/memcontrol.h>
24924  #include <linux/mempolicy.h>
24925  #include <linux/security.h>
24926 +#include <linux/reboot.h>
24927 +#include <linux/vs_memory.h>
24928 +#include <linux/vs_context.h>
24929  
24930  int sysctl_panic_on_oom;
24931  int sysctl_oom_kill_allocating_task;
24932 @@ -124,11 +127,18 @@ struct task_struct *find_lock_task_mm(st
24933  static bool oom_unkillable_task(struct task_struct *p,
24934                 const struct mem_cgroup *mem, const nodemask_t *nodemask)
24935  {
24936 -       if (is_global_init(p))
24937 +       unsigned xid = vx_current_xid();
24938 +
24939 +       /* skip the init task, global and per guest */
24940 +       if (task_is_init(p))
24941                 return true;
24942         if (p->flags & PF_KTHREAD)
24943                 return true;
24944  
24945 +       /* skip other guest and host processes if oom in guest */
24946 +       if (xid && vx_task_xid(p) != xid)
24947 +               return true;
24948 +
24949         /* When mem_cgroup_out_of_memory() and p is not member of the group */
24950         if (mem && !task_in_mem_cgroup(p, mem))
24951                 return true;
24952 @@ -209,6 +219,18 @@ unsigned int oom_badness(struct task_str
24953         points += p->signal->oom_score_adj;
24954  
24955         /*
24956 +        * add points for context badness and
24957 +        * reduce badness for processes belonging to
24958 +        * a different context
24959 +        */
24960 +
24961 +       points += vx_badness(p, p->mm);
24962 +
24963 +       if ((vx_current_xid() > 1) &&
24964 +               vx_current_xid() != vx_task_xid(p))
24965 +               points /= 16;
24966 +
24967 +       /*
24968          * Never return 0 for an eligible task that may be killed since it's
24969          * possible that no single user task uses more than 0.1% of memory and
24970          * no single admin tasks uses more than 3.0%.
24971 @@ -407,8 +429,8 @@ static int oom_kill_task(struct task_str
24972         if (!p)
24973                 return 1;
24974  
24975 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
24976 -               task_pid_nr(p), p->comm, K(p->mm->total_vm),
24977 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
24978 +               task_pid_nr(p), p->xid, p->comm, K(p->mm->total_vm),
24979                 K(get_mm_counter(p->mm, MM_ANONPAGES)),
24980                 K(get_mm_counter(p->mm, MM_FILEPAGES)));
24981         task_unlock(p);
24982 @@ -452,8 +474,8 @@ static int oom_kill_process(struct task_
24983         }
24984  
24985         task_lock(p);
24986 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
24987 -               message, task_pid_nr(p), p->comm, points);
24988 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
24989 +               message, task_pid_nr(p), p->xid, p->comm, points);
24990         task_unlock(p);
24991  
24992         /*
24993 @@ -542,6 +564,8 @@ int unregister_oom_notifier(struct notif
24994  }
24995  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
24996  
24997 +long vs_oom_action(unsigned int);
24998 +
24999  /*
25000   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
25001   * if a parallel OOM killing is already taking place that includes a zone in
25002 @@ -701,7 +725,12 @@ retry:
25003         if (!p) {
25004                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
25005                 read_unlock(&tasklist_lock);
25006 -               panic("Out of memory and no killable processes...\n");
25007 +
25008 +               /* avoid panic for guest OOM */
25009 +               if (current->xid)
25010 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
25011 +               else
25012 +                       panic("Out of memory and no killable processes...\n");
25013         }
25014  
25015         if (oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
25016 diff -NurpP --minimal linux-2.6.36/mm/page_alloc.c linux-2.6.36-vs2.3.0.36.33/mm/page_alloc.c
25017 --- linux-2.6.36/mm/page_alloc.c        2010-10-21 13:07:57.000000000 +0200
25018 +++ linux-2.6.36-vs2.3.0.36.33/mm/page_alloc.c  2010-10-21 13:09:36.000000000 +0200
25019 @@ -52,6 +52,8 @@
25020  #include <linux/compaction.h>
25021  #include <trace/events/kmem.h>
25022  #include <linux/ftrace_event.h>
25023 +#include <linux/vs_base.h>
25024 +#include <linux/vs_limit.h>
25025  
25026  #include <asm/tlbflush.h>
25027  #include <asm/div64.h>
25028 @@ -2329,6 +2331,9 @@ void si_meminfo(struct sysinfo *val)
25029         val->totalhigh = totalhigh_pages;
25030         val->freehigh = nr_free_highpages();
25031         val->mem_unit = PAGE_SIZE;
25032 +
25033 +       if (vx_flags(VXF_VIRT_MEM, 0))
25034 +               vx_vsi_meminfo(val);
25035  }
25036  
25037  EXPORT_SYMBOL(si_meminfo);
25038 @@ -2349,6 +2354,9 @@ void si_meminfo_node(struct sysinfo *val
25039         val->freehigh = 0;
25040  #endif
25041         val->mem_unit = PAGE_SIZE;
25042 +
25043 +       if (vx_flags(VXF_VIRT_MEM, 0))
25044 +               vx_vsi_meminfo(val);
25045  }
25046  #endif
25047  
25048 diff -NurpP --minimal linux-2.6.36/mm/rmap.c linux-2.6.36-vs2.3.0.36.33/mm/rmap.c
25049 --- linux-2.6.36/mm/rmap.c      2010-10-21 13:07:57.000000000 +0200
25050 +++ linux-2.6.36-vs2.3.0.36.33/mm/rmap.c        2010-10-21 13:19:11.000000000 +0200
25051 @@ -57,6 +57,7 @@
25052  #include <linux/mmu_notifier.h>
25053  #include <linux/migrate.h>
25054  #include <linux/hugetlb.h>
25055 +#include <linux/vs_memory.h>
25056  
25057  #include <asm/tlbflush.h>
25058  
25059 diff -NurpP --minimal linux-2.6.36/mm/shmem.c linux-2.6.36-vs2.3.0.36.33/mm/shmem.c
25060 --- linux-2.6.36/mm/shmem.c     2010-10-21 13:07:57.000000000 +0200
25061 +++ linux-2.6.36-vs2.3.0.36.33/mm/shmem.c       2010-10-21 13:09:36.000000000 +0200
25062 @@ -1815,7 +1815,7 @@ static int shmem_statfs(struct dentry *d
25063  {
25064         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
25065  
25066 -       buf->f_type = TMPFS_MAGIC;
25067 +       buf->f_type = TMPFS_SUPER_MAGIC;
25068         buf->f_bsize = PAGE_CACHE_SIZE;
25069         buf->f_namelen = NAME_MAX;
25070         if (sbinfo->max_blocks) {
25071 @@ -2377,7 +2377,7 @@ int shmem_fill_super(struct super_block 
25072         sb->s_maxbytes = SHMEM_MAX_BYTES;
25073         sb->s_blocksize = PAGE_CACHE_SIZE;
25074         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
25075 -       sb->s_magic = TMPFS_MAGIC;
25076 +       sb->s_magic = TMPFS_SUPER_MAGIC;
25077         sb->s_op = &shmem_ops;
25078         sb->s_time_gran = 1;
25079  #ifdef CONFIG_TMPFS_POSIX_ACL
25080 diff -NurpP --minimal linux-2.6.36/mm/slab.c linux-2.6.36-vs2.3.0.36.33/mm/slab.c
25081 --- linux-2.6.36/mm/slab.c      2010-10-21 13:07:57.000000000 +0200
25082 +++ linux-2.6.36-vs2.3.0.36.33/mm/slab.c        2010-10-21 13:09:36.000000000 +0200
25083 @@ -407,6 +407,8 @@ static void kmem_list3_init(struct kmem_
25084  #define STATS_INC_FREEMISS(x)  do { } while (0)
25085  #endif
25086  
25087 +#include "slab_vs.h"
25088 +
25089  #if DEBUG
25090  
25091  /*
25092 @@ -3346,6 +3348,7 @@ retry:
25093  
25094         obj = slab_get_obj(cachep, slabp, nodeid);
25095         check_slabp(cachep, slabp);
25096 +       vx_slab_alloc(cachep, flags);
25097         l3->free_objects--;
25098         /* move slabp to correct slabp list: */
25099         list_del(&slabp->list);
25100 @@ -3423,6 +3426,7 @@ __cache_alloc_node(struct kmem_cache *ca
25101         /* ___cache_alloc_node can fall back to other nodes */
25102         ptr = ____cache_alloc_node(cachep, flags, nodeid);
25103    out:
25104 +       vx_slab_alloc(cachep, flags);
25105         local_irq_restore(save_flags);
25106         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
25107         kmemleak_alloc_recursive(ptr, obj_size(cachep), 1, cachep->flags,
25108 @@ -3609,6 +3613,7 @@ static inline void __cache_free(struct k
25109         check_irq_off();
25110         kmemleak_free_recursive(objp, cachep->flags);
25111         objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
25112 +       vx_slab_free(cachep);
25113  
25114         kmemcheck_slab_free(cachep, objp, obj_size(cachep));
25115  
25116 diff -NurpP --minimal linux-2.6.36/mm/slab_vs.h linux-2.6.36-vs2.3.0.36.33/mm/slab_vs.h
25117 --- linux-2.6.36/mm/slab_vs.h   1970-01-01 01:00:00.000000000 +0100
25118 +++ linux-2.6.36-vs2.3.0.36.33/mm/slab_vs.h     2010-10-21 13:09:36.000000000 +0200
25119 @@ -0,0 +1,29 @@
25120 +
25121 +#include <linux/vserver/context.h>
25122 +
25123 +#include <linux/vs_context.h>
25124 +
25125 +static inline
25126 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
25127 +{
25128 +       int what = gfp_zone(cachep->gfpflags);
25129 +       struct vx_info *vxi = current_vx_info();
25130 +
25131 +       if (!vxi)
25132 +               return;
25133 +
25134 +       atomic_add(cachep->buffer_size, &vxi->cacct.slab[what]);
25135 +}
25136 +
25137 +static inline
25138 +void vx_slab_free(struct kmem_cache *cachep)
25139 +{
25140 +       int what = gfp_zone(cachep->gfpflags);
25141 +       struct vx_info *vxi = current_vx_info();
25142 +
25143 +       if (!vxi)
25144 +               return;
25145 +
25146 +       atomic_sub(cachep->buffer_size, &vxi->cacct.slab[what]);
25147 +}
25148 +
25149 diff -NurpP --minimal linux-2.6.36/mm/swapfile.c linux-2.6.36-vs2.3.0.36.33/mm/swapfile.c
25150 --- linux-2.6.36/mm/swapfile.c  2010-10-21 13:07:57.000000000 +0200
25151 +++ linux-2.6.36-vs2.3.0.36.33/mm/swapfile.c    2010-10-21 13:09:36.000000000 +0200
25152 @@ -35,6 +35,8 @@
25153  #include <asm/tlbflush.h>
25154  #include <linux/swapops.h>
25155  #include <linux/page_cgroup.h>
25156 +#include <linux/vs_base.h>
25157 +#include <linux/vs_memory.h>
25158  
25159  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
25160                                  unsigned char);
25161 @@ -1747,6 +1749,16 @@ static int swap_show(struct seq_file *sw
25162  
25163         if (si == SEQ_START_TOKEN) {
25164                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
25165 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
25166 +                       struct sysinfo si;
25167 +
25168 +                       vx_vsi_swapinfo(&si);
25169 +                       if (si.totalswap < (1 << 10))
25170 +                               return 0;
25171 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
25172 +                               "hdv0", "partition", si.totalswap >> 10,
25173 +                               (si.totalswap - si.freeswap) >> 10, -1);
25174 +               }
25175                 return 0;
25176         }
25177  
25178 @@ -2131,6 +2143,8 @@ void si_swapinfo(struct sysinfo *val)
25179         val->freeswap = nr_swap_pages + nr_to_be_unused;
25180         val->totalswap = total_swap_pages + nr_to_be_unused;
25181         spin_unlock(&swap_lock);
25182 +       if (vx_flags(VXF_VIRT_MEM, 0))
25183 +               vx_vsi_swapinfo(val);
25184  }
25185  
25186  /*
25187 diff -NurpP --minimal linux-2.6.36/net/core/dev.c linux-2.6.36-vs2.3.0.36.33/net/core/dev.c
25188 --- linux-2.6.36/net/core/dev.c 2010-10-21 13:07:58.000000000 +0200
25189 +++ linux-2.6.36-vs2.3.0.36.33/net/core/dev.c   2010-10-21 14:12:56.000000000 +0200
25190 @@ -127,6 +127,7 @@
25191  #include <linux/in.h>
25192  #include <linux/jhash.h>
25193  #include <linux/random.h>
25194 +#include <linux/vs_inet.h>
25195  #include <trace/events/napi.h>
25196  #include <linux/pci.h>
25197  
25198 @@ -607,7 +608,8 @@ struct net_device *__dev_get_by_name(str
25199         struct hlist_head *head = dev_name_hash(net, name);
25200  
25201         hlist_for_each_entry(dev, p, head, name_hlist)
25202 -               if (!strncmp(dev->name, name, IFNAMSIZ))
25203 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
25204 +                   nx_dev_visible(current_nx_info(), dev))
25205                         return dev;
25206  
25207         return NULL;
25208 @@ -633,7 +635,8 @@ struct net_device *dev_get_by_name_rcu(s
25209         struct hlist_head *head = dev_name_hash(net, name);
25210  
25211         hlist_for_each_entry_rcu(dev, p, head, name_hlist)
25212 -               if (!strncmp(dev->name, name, IFNAMSIZ))
25213 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
25214 +                   nx_dev_visible(current_nx_info(), dev))
25215                         return dev;
25216  
25217         return NULL;
25218 @@ -684,7 +687,8 @@ struct net_device *__dev_get_by_index(st
25219         struct hlist_head *head = dev_index_hash(net, ifindex);
25220  
25221         hlist_for_each_entry(dev, p, head, index_hlist)
25222 -               if (dev->ifindex == ifindex)
25223 +               if ((dev->ifindex == ifindex) &&
25224 +                   nx_dev_visible(current_nx_info(), dev))
25225                         return dev;
25226  
25227         return NULL;
25228 @@ -709,7 +713,8 @@ struct net_device *dev_get_by_index_rcu(
25229         struct hlist_head *head = dev_index_hash(net, ifindex);
25230  
25231         hlist_for_each_entry_rcu(dev, p, head, index_hlist)
25232 -               if (dev->ifindex == ifindex)
25233 +               if ((dev->ifindex == ifindex) &&
25234 +                   nx_dev_visible(current_nx_info(), dev))
25235                         return dev;
25236  
25237         return NULL;
25238 @@ -762,10 +767,12 @@ struct net_device *dev_getbyhwaddr(struc
25239  
25240         ASSERT_RTNL();
25241  
25242 -       for_each_netdev(net, dev)
25243 +       for_each_netdev(net, dev) {
25244                 if (dev->type == type &&
25245 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
25246 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
25247 +                   nx_dev_visible(current_nx_info(), dev))
25248                         return dev;
25249 +       }
25250  
25251         return NULL;
25252  }
25253 @@ -776,9 +783,11 @@ struct net_device *__dev_getfirstbyhwtyp
25254         struct net_device *dev;
25255  
25256         ASSERT_RTNL();
25257 -       for_each_netdev(net, dev)
25258 -               if (dev->type == type)
25259 +       for_each_netdev(net, dev) {
25260 +               if ((dev->type == type) &&
25261 +                   nx_dev_visible(current_nx_info(), dev))
25262                         return dev;
25263 +       }
25264  
25265         return NULL;
25266  }
25267 @@ -896,6 +905,8 @@ static int __dev_alloc_name(struct net *
25268                                 continue;
25269                         if (i < 0 || i >= max_netdevices)
25270                                 continue;
25271 +                       if (!nx_dev_visible(current_nx_info(), d))
25272 +                               continue;
25273  
25274                         /*  avoid cases where sscanf is not exact inverse of printf */
25275                         snprintf(buf, IFNAMSIZ, name, i);
25276 @@ -3658,6 +3669,8 @@ static int dev_ifconf(struct net *net, c
25277  
25278         total = 0;
25279         for_each_netdev(net, dev) {
25280 +               if (!nx_dev_visible(current_nx_info(), dev))
25281 +                       continue;
25282                 for (i = 0; i < NPROTO; i++) {
25283                         if (gifconf_list[i]) {
25284                                 int done;
25285 @@ -3729,6 +3742,10 @@ static void dev_seq_printf_stats(struct 
25286         struct rtnl_link_stats64 temp;
25287         const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
25288  
25289 +       /* device visible inside network context? */
25290 +       if (!nx_dev_visible(current_nx_info(), dev))
25291 +               return;
25292 +
25293         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
25294                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
25295                    dev->name, stats->rx_bytes, stats->rx_packets,
25296 diff -NurpP --minimal linux-2.6.36/net/core/rtnetlink.c linux-2.6.36-vs2.3.0.36.33/net/core/rtnetlink.c
25297 --- linux-2.6.36/net/core/rtnetlink.c   2010-10-21 13:07:58.000000000 +0200
25298 +++ linux-2.6.36-vs2.3.0.36.33/net/core/rtnetlink.c     2010-10-21 13:09:36.000000000 +0200
25299 @@ -927,6 +927,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
25300                 hlist_for_each_entry(dev, node, head, index_hlist) {
25301                         if (idx < s_idx)
25302                                 goto cont;
25303 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
25304 +                               continue;
25305                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
25306                                              NETLINK_CB(cb->skb).pid,
25307                                              cb->nlh->nlmsg_seq, 0,
25308 @@ -1643,6 +1645,9 @@ void rtmsg_ifinfo(int type, struct net_d
25309         struct sk_buff *skb;
25310         int err = -ENOBUFS;
25311  
25312 +       if (!nx_dev_visible(current_nx_info(), dev))
25313 +               return;
25314 +
25315         skb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL);
25316         if (skb == NULL)
25317                 goto errout;
25318 diff -NurpP --minimal linux-2.6.36/net/core/sock.c linux-2.6.36-vs2.3.0.36.33/net/core/sock.c
25319 --- linux-2.6.36/net/core/sock.c        2010-10-21 13:07:58.000000000 +0200
25320 +++ linux-2.6.36-vs2.3.0.36.33/net/core/sock.c  2010-10-21 13:09:36.000000000 +0200
25321 @@ -127,6 +127,10 @@
25322  #include <net/cls_cgroup.h>
25323  
25324  #include <linux/filter.h>
25325 +#include <linux/vs_socket.h>
25326 +#include <linux/vs_limit.h>
25327 +#include <linux/vs_context.h>
25328 +#include <linux/vs_network.h>
25329  
25330  #ifdef CONFIG_INET
25331  #include <net/tcp.h>
25332 @@ -1046,6 +1050,8 @@ static struct sock *sk_prot_alloc(struct
25333                         goto out_free_sec;
25334                 sk_tx_queue_clear(sk);
25335         }
25336 +               sock_vx_init(sk);
25337 +               sock_nx_init(sk);
25338  
25339         return sk;
25340  
25341 @@ -1142,6 +1148,11 @@ static void __sk_free(struct sock *sk)
25342                 put_cred(sk->sk_peer_cred);
25343         put_pid(sk->sk_peer_pid);
25344         put_net(sock_net(sk));
25345 +       vx_sock_dec(sk);
25346 +       clr_vx_info(&sk->sk_vx_info);
25347 +       sk->sk_xid = -1;
25348 +       clr_nx_info(&sk->sk_nx_info);
25349 +       sk->sk_nid = -1;
25350         sk_prot_free(sk->sk_prot_creator, sk);
25351  }
25352  
25353 @@ -1189,6 +1200,8 @@ struct sock *sk_clone(const struct sock 
25354  
25355                 /* SANITY */
25356                 get_net(sock_net(newsk));
25357 +               sock_vx_init(newsk);
25358 +               sock_nx_init(newsk);
25359                 sk_node_init(&newsk->sk_node);
25360                 sock_lock_init(newsk);
25361                 bh_lock_sock(newsk);
25362 @@ -1244,6 +1257,12 @@ struct sock *sk_clone(const struct sock 
25363                 smp_wmb();
25364                 atomic_set(&newsk->sk_refcnt, 2);
25365  
25366 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
25367 +               newsk->sk_xid = sk->sk_xid;
25368 +               vx_sock_inc(newsk);
25369 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
25370 +               newsk->sk_nid = sk->sk_nid;
25371 +
25372                 /*
25373                  * Increment the counter in the same struct proto as the master
25374                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
25375 @@ -1986,6 +2005,12 @@ void sock_init_data(struct socket *sock,
25376  
25377         sk->sk_stamp = ktime_set(-1L, 0);
25378  
25379 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
25380 +       sk->sk_xid = vx_current_xid();
25381 +       vx_sock_inc(sk);
25382 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
25383 +       sk->sk_nid = nx_current_nid();
25384 +
25385         /*
25386          * Before updating sk_refcnt, we must commit prior changes to memory
25387          * (Documentation/RCU/rculist_nulls.txt for details)
25388 diff -NurpP --minimal linux-2.6.36/net/ipv4/af_inet.c linux-2.6.36-vs2.3.0.36.33/net/ipv4/af_inet.c
25389 --- linux-2.6.36/net/ipv4/af_inet.c     2010-10-21 13:07:58.000000000 +0200
25390 +++ linux-2.6.36-vs2.3.0.36.33/net/ipv4/af_inet.c       2010-10-21 13:09:36.000000000 +0200
25391 @@ -116,6 +116,7 @@
25392  #ifdef CONFIG_IP_MROUTE
25393  #include <linux/mroute.h>
25394  #endif
25395 +#include <linux/vs_limit.h>
25396  
25397  
25398  /* The inetsw table contains everything that inet_create needs to
25399 @@ -327,9 +328,13 @@ lookup_protocol:
25400         }
25401  
25402         err = -EPERM;
25403 +       if ((protocol == IPPROTO_ICMP) &&
25404 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
25405 +               goto override;
25406 +
25407         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
25408                 goto out_rcu_unlock;
25409 -
25410 +override:
25411         err = -EAFNOSUPPORT;
25412         if (!inet_netns_ok(net, protocol))
25413                 goto out_rcu_unlock;
25414 @@ -453,6 +458,7 @@ int inet_bind(struct socket *sock, struc
25415         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
25416         struct sock *sk = sock->sk;
25417         struct inet_sock *inet = inet_sk(sk);
25418 +       struct nx_v4_sock_addr nsa;
25419         unsigned short snum;
25420         int chk_addr_ret;
25421         int err;
25422 @@ -466,7 +472,11 @@ int inet_bind(struct socket *sock, struc
25423         if (addr_len < sizeof(struct sockaddr_in))
25424                 goto out;
25425  
25426 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
25427 +       err = v4_map_sock_addr(inet, addr, &nsa);
25428 +       if (err)
25429 +               goto out;
25430 +
25431 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
25432  
25433         /* Not specified by any standard per-se, however it breaks too
25434          * many applications when removed.  It is unfortunate since
25435 @@ -478,7 +488,7 @@ int inet_bind(struct socket *sock, struc
25436         err = -EADDRNOTAVAIL;
25437         if (!sysctl_ip_nonlocal_bind &&
25438             !(inet->freebind || inet->transparent) &&
25439 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
25440 +           nsa.saddr != htonl(INADDR_ANY) &&
25441             chk_addr_ret != RTN_LOCAL &&
25442             chk_addr_ret != RTN_MULTICAST &&
25443             chk_addr_ret != RTN_BROADCAST)
25444 @@ -503,7 +513,7 @@ int inet_bind(struct socket *sock, struc
25445         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
25446                 goto out_release_sock;
25447  
25448 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
25449 +       v4_set_sock_addr(inet, &nsa);
25450         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
25451                 inet->inet_saddr = 0;  /* Use device */
25452  
25453 @@ -705,11 +715,13 @@ int inet_getname(struct socket *sock, st
25454                      peer == 1))
25455                         return -ENOTCONN;
25456                 sin->sin_port = inet->inet_dport;
25457 -               sin->sin_addr.s_addr = inet->inet_daddr;
25458 +               sin->sin_addr.s_addr =
25459 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
25460         } else {
25461                 __be32 addr = inet->inet_rcv_saddr;
25462                 if (!addr)
25463                         addr = inet->inet_saddr;
25464 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
25465                 sin->sin_port = inet->inet_sport;
25466                 sin->sin_addr.s_addr = addr;
25467         }
25468 diff -NurpP --minimal linux-2.6.36/net/ipv4/devinet.c linux-2.6.36-vs2.3.0.36.33/net/ipv4/devinet.c
25469 --- linux-2.6.36/net/ipv4/devinet.c     2010-10-21 13:07:58.000000000 +0200
25470 +++ linux-2.6.36-vs2.3.0.36.33/net/ipv4/devinet.c       2010-10-21 13:09:36.000000000 +0200
25471 @@ -417,6 +417,7 @@ struct in_device *inetdev_by_index(struc
25472  }
25473  EXPORT_SYMBOL(inetdev_by_index);
25474  
25475 +
25476  /* Called only from RTNL semaphored context. No locks. */
25477  
25478  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
25479 @@ -659,6 +660,8 @@ int devinet_ioctl(struct net *net, unsig
25480  
25481         in_dev = __in_dev_get_rtnl(dev);
25482         if (in_dev) {
25483 +               struct nx_info *nxi = current_nx_info();
25484 +
25485                 if (tryaddrmatch) {
25486                         /* Matthias Andree */
25487                         /* compare label and address (4.4BSD style) */
25488 @@ -667,6 +670,8 @@ int devinet_ioctl(struct net *net, unsig
25489                            This is checked above. */
25490                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
25491                              ifap = &ifa->ifa_next) {
25492 +                               if (!nx_v4_ifa_visible(nxi, ifa))
25493 +                                       continue;
25494                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
25495                                     sin_orig.sin_addr.s_addr ==
25496                                                         ifa->ifa_address) {
25497 @@ -679,9 +684,12 @@ int devinet_ioctl(struct net *net, unsig
25498                    comparing just the label */
25499                 if (!ifa) {
25500                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
25501 -                            ifap = &ifa->ifa_next)
25502 +                            ifap = &ifa->ifa_next) {
25503 +                               if (!nx_v4_ifa_visible(nxi, ifa))
25504 +                                       continue;
25505                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
25506                                         break;
25507 +                       }
25508                 }
25509         }
25510  
25511 @@ -833,6 +841,8 @@ static int inet_gifconf(struct net_devic
25512                 goto out;
25513  
25514         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
25515 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
25516 +                       continue;
25517                 if (!buf) {
25518                         done += sizeof(ifr);
25519                         continue;
25520 @@ -1182,6 +1192,7 @@ static int inet_dump_ifaddr(struct sk_bu
25521         struct net_device *dev;
25522         struct in_device *in_dev;
25523         struct in_ifaddr *ifa;
25524 +       struct sock *sk = skb->sk;
25525         struct hlist_head *head;
25526         struct hlist_node *node;
25527  
25528 @@ -1204,6 +1215,8 @@ static int inet_dump_ifaddr(struct sk_bu
25529  
25530                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
25531                              ifa = ifa->ifa_next, ip_idx++) {
25532 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
25533 +                               continue;
25534                                 if (ip_idx < s_ip_idx)
25535                                         continue;
25536                                 if (inet_fill_ifaddr(skb, ifa,
25537 diff -NurpP --minimal linux-2.6.36/net/ipv4/fib_hash.c linux-2.6.36-vs2.3.0.36.33/net/ipv4/fib_hash.c
25538 --- linux-2.6.36/net/ipv4/fib_hash.c    2010-07-07 18:31:59.000000000 +0200
25539 +++ linux-2.6.36-vs2.3.0.36.33/net/ipv4/fib_hash.c      2010-10-21 13:09:36.000000000 +0200
25540 @@ -1017,7 +1017,7 @@ static int fib_seq_show(struct seq_file 
25541         prefix  = f->fn_key;
25542         mask    = FZ_MASK(iter->zone);
25543         flags   = fib_flag_trans(fa->fa_type, mask, fi);
25544 -       if (fi)
25545 +       if (fi && nx_dev_visible(current_nx_info(), fi->fib_dev))
25546                 seq_printf(seq,
25547                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u%n",
25548                          fi->fib_dev ? fi->fib_dev->name : "*", prefix,
25549 diff -NurpP --minimal linux-2.6.36/net/ipv4/inet_connection_sock.c linux-2.6.36-vs2.3.0.36.33/net/ipv4/inet_connection_sock.c
25550 --- linux-2.6.36/net/ipv4/inet_connection_sock.c        2010-10-21 13:07:58.000000000 +0200
25551 +++ linux-2.6.36-vs2.3.0.36.33/net/ipv4/inet_connection_sock.c  2010-10-21 13:09:36.000000000 +0200
25552 @@ -52,10 +52,40 @@ void inet_get_local_port_range(int *low,
25553  }
25554  EXPORT_SYMBOL(inet_get_local_port_range);
25555  
25556 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25557 +{
25558 +       __be32  sk1_rcv_saddr = inet_rcv_saddr(sk1),
25559 +               sk2_rcv_saddr = inet_rcv_saddr(sk2);
25560 +
25561 +       if (inet_v6_ipv6only(sk2))
25562 +               return 0;
25563 +
25564 +       if (sk1_rcv_saddr &&
25565 +           sk2_rcv_saddr &&
25566 +           sk1_rcv_saddr == sk2_rcv_saddr)
25567 +               return 1;
25568 +
25569 +       if (sk1_rcv_saddr &&
25570 +           !sk2_rcv_saddr &&
25571 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
25572 +               return 1;
25573 +
25574 +       if (sk2_rcv_saddr &&
25575 +           !sk1_rcv_saddr &&
25576 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
25577 +               return 1;
25578 +
25579 +       if (!sk1_rcv_saddr &&
25580 +           !sk2_rcv_saddr &&
25581 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
25582 +               return 1;
25583 +
25584 +       return 0;
25585 +}
25586 +
25587  int inet_csk_bind_conflict(const struct sock *sk,
25588                            const struct inet_bind_bucket *tb)
25589  {
25590 -       const __be32 sk_rcv_saddr = inet_rcv_saddr(sk);
25591         struct sock *sk2;
25592         struct hlist_node *node;
25593         int reuse = sk->sk_reuse;
25594 @@ -75,9 +105,7 @@ int inet_csk_bind_conflict(const struct 
25595                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
25596                         if (!reuse || !sk2->sk_reuse ||
25597                             sk2->sk_state == TCP_LISTEN) {
25598 -                               const __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
25599 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr ||
25600 -                                   sk2_rcv_saddr == sk_rcv_saddr)
25601 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
25602                                         break;
25603                         }
25604                 }
25605 diff -NurpP --minimal linux-2.6.36/net/ipv4/inet_diag.c linux-2.6.36-vs2.3.0.36.33/net/ipv4/inet_diag.c
25606 --- linux-2.6.36/net/ipv4/inet_diag.c   2010-07-07 18:31:59.000000000 +0200
25607 +++ linux-2.6.36-vs2.3.0.36.33/net/ipv4/inet_diag.c     2010-10-21 13:09:36.000000000 +0200
25608 @@ -33,6 +33,8 @@
25609  #include <linux/stddef.h>
25610  
25611  #include <linux/inet_diag.h>
25612 +#include <linux/vs_network.h>
25613 +#include <linux/vs_inet.h>
25614  
25615  static const struct inet_diag_handler **inet_diag_table;
25616  
25617 @@ -119,8 +121,10 @@ static int inet_csk_diag_fill(struct soc
25618  
25619         r->id.idiag_sport = inet->inet_sport;
25620         r->id.idiag_dport = inet->inet_dport;
25621 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
25622 -       r->id.idiag_dst[0] = inet->inet_daddr;
25623 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
25624 +               inet->inet_rcv_saddr);
25625 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
25626 +               inet->inet_daddr);
25627  
25628  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
25629         if (r->idiag_family == AF_INET6) {
25630 @@ -205,8 +209,8 @@ static int inet_twsk_diag_fill(struct in
25631         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
25632         r->id.idiag_sport     = tw->tw_sport;
25633         r->id.idiag_dport     = tw->tw_dport;
25634 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
25635 -       r->id.idiag_dst[0]    = tw->tw_daddr;
25636 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
25637 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
25638         r->idiag_state        = tw->tw_substate;
25639         r->idiag_timer        = 3;
25640         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
25641 @@ -263,6 +267,7 @@ static int inet_diag_get_exact(struct sk
25642         err = -EINVAL;
25643  
25644         if (req->idiag_family == AF_INET) {
25645 +               /* TODO: lback */
25646                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
25647                                  req->id.idiag_dport, req->id.idiag_src[0],
25648                                  req->id.idiag_sport, req->id.idiag_if);
25649 @@ -505,6 +510,7 @@ static int inet_csk_diag_dump(struct soc
25650                 } else
25651  #endif
25652                 {
25653 +                       /* TODO: lback */
25654                         entry.saddr = &inet->inet_rcv_saddr;
25655                         entry.daddr = &inet->inet_daddr;
25656                 }
25657 @@ -541,6 +547,7 @@ static int inet_twsk_diag_dump(struct in
25658                 } else
25659  #endif
25660                 {
25661 +                       /* TODO: lback */
25662                         entry.saddr = &tw->tw_rcv_saddr;
25663                         entry.daddr = &tw->tw_daddr;
25664                 }
25665 @@ -587,8 +594,8 @@ static int inet_diag_fill_req(struct sk_
25666  
25667         r->id.idiag_sport = inet->inet_sport;
25668         r->id.idiag_dport = ireq->rmt_port;
25669 -       r->id.idiag_src[0] = ireq->loc_addr;
25670 -       r->id.idiag_dst[0] = ireq->rmt_addr;
25671 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
25672 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
25673         r->idiag_expires = jiffies_to_msecs(tmo);
25674         r->idiag_rqueue = 0;
25675         r->idiag_wqueue = 0;
25676 @@ -658,6 +665,7 @@ static int inet_diag_dump_reqs(struct sk
25677                                 continue;
25678  
25679                         if (bc) {
25680 +                               /* TODO: lback */
25681                                 entry.saddr =
25682  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
25683                                         (entry.family == AF_INET6) ?
25684 @@ -728,6 +736,8 @@ static int inet_diag_dump(struct sk_buff
25685                         sk_nulls_for_each(sk, node, &ilb->head) {
25686                                 struct inet_sock *inet = inet_sk(sk);
25687  
25688 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25689 +                                       continue;
25690                                 if (num < s_num) {
25691                                         num++;
25692                                         continue;
25693 @@ -794,6 +804,8 @@ skip_listen_ht:
25694                 sk_nulls_for_each(sk, node, &head->chain) {
25695                         struct inet_sock *inet = inet_sk(sk);
25696  
25697 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25698 +                               continue;
25699                         if (num < s_num)
25700                                 goto next_normal;
25701                         if (!(r->idiag_states & (1 << sk->sk_state)))
25702 @@ -818,6 +830,8 @@ next_normal:
25703                         inet_twsk_for_each(tw, node,
25704                                     &head->twchain) {
25705  
25706 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
25707 +                                       continue;
25708                                 if (num < s_num)
25709                                         goto next_dying;
25710                                 if (r->id.idiag_sport != tw->tw_sport &&
25711 diff -NurpP --minimal linux-2.6.36/net/ipv4/inet_hashtables.c linux-2.6.36-vs2.3.0.36.33/net/ipv4/inet_hashtables.c
25712 --- linux-2.6.36/net/ipv4/inet_hashtables.c     2010-10-21 13:07:58.000000000 +0200
25713 +++ linux-2.6.36-vs2.3.0.36.33/net/ipv4/inet_hashtables.c       2010-10-21 13:09:36.000000000 +0200
25714 @@ -21,6 +21,7 @@
25715  
25716  #include <net/inet_connection_sock.h>
25717  #include <net/inet_hashtables.h>
25718 +#include <net/route.h>
25719  #include <net/ip.h>
25720  
25721  /*
25722 @@ -132,6 +133,11 @@ static inline int compute_score(struct s
25723                         if (rcv_saddr != daddr)
25724                                 return -1;
25725                         score += 2;
25726 +               } else {
25727 +                       /* block non nx_info ips */
25728 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
25729 +                               daddr, NXA_MASK_BIND))
25730 +                               return -1;
25731                 }
25732                 if (sk->sk_bound_dev_if) {
25733                         if (sk->sk_bound_dev_if != dif)
25734 @@ -149,7 +155,6 @@ static inline int compute_score(struct s
25735   * wildcarded during the search since they can never be otherwise.
25736   */
25737  
25738 -
25739  struct sock *__inet_lookup_listener(struct net *net,
25740                                     struct inet_hashinfo *hashinfo,
25741                                     const __be32 daddr, const unsigned short hnum,
25742 @@ -172,6 +177,7 @@ begin:
25743                         hiscore = score;
25744                 }
25745         }
25746 +
25747         /*
25748          * if the nulls value we got at the end of this lookup is
25749          * not the expected one, we must restart lookup.
25750 diff -NurpP --minimal linux-2.6.36/net/ipv4/netfilter/nf_nat_helper.c linux-2.6.36-vs2.3.0.36.33/net/ipv4/netfilter/nf_nat_helper.c
25751 --- linux-2.6.36/net/ipv4/netfilter/nf_nat_helper.c     2010-07-07 18:31:59.000000000 +0200
25752 +++ linux-2.6.36-vs2.3.0.36.33/net/ipv4/netfilter/nf_nat_helper.c       2010-10-21 13:09:36.000000000 +0200
25753 @@ -20,6 +20,7 @@
25754  #include <net/route.h>
25755  
25756  #include <linux/netfilter_ipv4.h>
25757 +#include <net/route.h>
25758  #include <net/netfilter/nf_conntrack.h>
25759  #include <net/netfilter/nf_conntrack_helper.h>
25760  #include <net/netfilter/nf_conntrack_ecache.h>
25761 diff -NurpP --minimal linux-2.6.36/net/ipv4/netfilter.c linux-2.6.36-vs2.3.0.36.33/net/ipv4/netfilter.c
25762 --- linux-2.6.36/net/ipv4/netfilter.c   2010-10-21 13:07:58.000000000 +0200
25763 +++ linux-2.6.36-vs2.3.0.36.33/net/ipv4/netfilter.c     2010-10-21 13:09:36.000000000 +0200
25764 @@ -5,7 +5,7 @@
25765  #include <linux/ip.h>
25766  #include <linux/skbuff.h>
25767  #include <linux/gfp.h>
25768 -#include <net/route.h>
25769 +// #include <net/route.h>
25770  #include <net/xfrm.h>
25771  #include <net/ip.h>
25772  #include <net/netfilter/nf_queue.h>
25773 diff -NurpP --minimal linux-2.6.36/net/ipv4/raw.c linux-2.6.36-vs2.3.0.36.33/net/ipv4/raw.c
25774 --- linux-2.6.36/net/ipv4/raw.c 2010-10-21 13:07:58.000000000 +0200
25775 +++ linux-2.6.36-vs2.3.0.36.33/net/ipv4/raw.c   2010-10-21 13:09:36.000000000 +0200
25776 @@ -116,7 +116,7 @@ static struct sock *__raw_v4_lookup(stru
25777  
25778                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
25779                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
25780 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
25781 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
25782                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
25783                         goto found; /* gotcha */
25784         }
25785 @@ -383,6 +383,12 @@ static int raw_send_hdrinc(struct sock *
25786                 icmp_out_count(net, ((struct icmphdr *)
25787                         skb_transport_header(skb))->type);
25788  
25789 +       err = -EPERM;
25790 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
25791 +               sk->sk_nx_info &&
25792 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
25793 +               goto error_free;
25794 +
25795         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
25796                       rt->dst.dev, dst_output);
25797         if (err > 0)
25798 @@ -563,6 +569,13 @@ static int raw_sendmsg(struct kiocb *ioc
25799                 }
25800  
25801                 security_sk_classify_flow(sk, &fl);
25802 +               if (sk->sk_nx_info) {
25803 +                       err = ip_v4_find_src(sock_net(sk),
25804 +                               sk->sk_nx_info, &rt, &fl);
25805 +
25806 +                       if (err)
25807 +                               goto done;
25808 +               }
25809                 err = ip_route_output_flow(sock_net(sk), &rt, &fl, sk, 1);
25810         }
25811         if (err)
25812 @@ -635,17 +648,19 @@ static int raw_bind(struct sock *sk, str
25813  {
25814         struct inet_sock *inet = inet_sk(sk);
25815         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
25816 +       struct nx_v4_sock_addr nsa = { 0 };
25817         int ret = -EINVAL;
25818         int chk_addr_ret;
25819  
25820         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
25821                 goto out;
25822 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
25823 +       v4_map_sock_addr(inet, addr, &nsa);
25824 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
25825         ret = -EADDRNOTAVAIL;
25826 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
25827 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
25828             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
25829                 goto out;
25830 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
25831 +       v4_set_sock_addr(inet, &nsa);
25832         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
25833                 inet->inet_saddr = 0;  /* Use device */
25834         sk_dst_reset(sk);
25835 @@ -697,7 +712,8 @@ static int raw_recvmsg(struct kiocb *ioc
25836         /* Copy the address. */
25837         if (sin) {
25838                 sin->sin_family = AF_INET;
25839 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25840 +               sin->sin_addr.s_addr =
25841 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
25842                 sin->sin_port = 0;
25843                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
25844         }
25845 @@ -875,7 +891,8 @@ static struct sock *raw_get_first(struct
25846                 struct hlist_node *node;
25847  
25848                 sk_for_each(sk, node, &state->h->ht[state->bucket])
25849 -                       if (sock_net(sk) == seq_file_net(seq))
25850 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
25851 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25852                                 goto found;
25853         }
25854         sk = NULL;
25855 @@ -891,7 +908,8 @@ static struct sock *raw_get_next(struct 
25856                 sk = sk_next(sk);
25857  try_again:
25858                 ;
25859 -       } while (sk && sock_net(sk) != seq_file_net(seq));
25860 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
25861 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25862  
25863         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
25864                 sk = sk_head(&state->h->ht[state->bucket]);
25865 @@ -950,7 +968,10 @@ static void raw_sock_seq_show(struct seq
25866  
25867         seq_printf(seq, "%4d: %08X:%04X %08X:%04X"
25868                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n",
25869 -               i, src, srcp, dest, destp, sp->sk_state,
25870 +               i,
25871 +               nx_map_sock_lback(current_nx_info(), src), srcp,
25872 +               nx_map_sock_lback(current_nx_info(), dest), destp,
25873 +               sp->sk_state,
25874                 sk_wmem_alloc_get(sp),
25875                 sk_rmem_alloc_get(sp),
25876                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
25877 diff -NurpP --minimal linux-2.6.36/net/ipv4/tcp.c linux-2.6.36-vs2.3.0.36.33/net/ipv4/tcp.c
25878 --- linux-2.6.36/net/ipv4/tcp.c 2010-10-21 13:07:58.000000000 +0200
25879 +++ linux-2.6.36-vs2.3.0.36.33/net/ipv4/tcp.c   2010-10-21 13:09:36.000000000 +0200
25880 @@ -266,6 +266,7 @@
25881  #include <linux/crypto.h>
25882  #include <linux/time.h>
25883  #include <linux/slab.h>
25884 +#include <linux/in.h>
25885  
25886  #include <net/icmp.h>
25887  #include <net/tcp.h>
25888 diff -NurpP --minimal linux-2.6.36/net/ipv4/tcp_ipv4.c linux-2.6.36-vs2.3.0.36.33/net/ipv4/tcp_ipv4.c
25889 --- linux-2.6.36/net/ipv4/tcp_ipv4.c    2010-10-21 13:07:58.000000000 +0200
25890 +++ linux-2.6.36-vs2.3.0.36.33/net/ipv4/tcp_ipv4.c      2010-10-21 13:09:36.000000000 +0200
25891 @@ -2016,6 +2016,12 @@ static void *listening_get_next(struct s
25892                 req = req->dl_next;
25893                 while (1) {
25894                         while (req) {
25895 +                               vxdprintk(VXD_CBIT(net, 6),
25896 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
25897 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
25898 +                               if (req->sk &&
25899 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
25900 +                                       continue;
25901                                 if (req->rsk_ops->family == st->family) {
25902                                         cur = req;
25903                                         goto out;
25904 @@ -2041,6 +2047,10 @@ get_req:
25905         }
25906  get_sk:
25907         sk_nulls_for_each_from(sk, node) {
25908 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
25909 +                       sk, sk->sk_nid, nx_current_nid());
25910 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25911 +                       continue;
25912                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net)) {
25913                         cur = sk;
25914                         goto out;
25915 @@ -2115,6 +2125,11 @@ static void *established_get_first(struc
25916  
25917                 spin_lock_bh(lock);
25918                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
25919 +                       vxdprintk(VXD_CBIT(net, 6),
25920 +                               "sk,egf: %p [#%d] (from %d)",
25921 +                               sk, sk->sk_nid, nx_current_nid());
25922 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25923 +                               continue;
25924                         if (sk->sk_family != st->family ||
25925                             !net_eq(sock_net(sk), net)) {
25926                                 continue;
25927 @@ -2125,6 +2140,11 @@ static void *established_get_first(struc
25928                 st->state = TCP_SEQ_STATE_TIME_WAIT;
25929                 inet_twsk_for_each(tw, node,
25930                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
25931 +                       vxdprintk(VXD_CBIT(net, 6),
25932 +                               "tw: %p [#%d] (from %d)",
25933 +                               tw, tw->tw_nid, nx_current_nid());
25934 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
25935 +                               continue;
25936                         if (tw->tw_family != st->family ||
25937                             !net_eq(twsk_net(tw), net)) {
25938                                 continue;
25939 @@ -2154,7 +2174,9 @@ static void *established_get_next(struct
25940                 tw = cur;
25941                 tw = tw_next(tw);
25942  get_tw:
25943 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
25944 +               while (tw && (tw->tw_family != st->family ||
25945 +                       !net_eq(twsk_net(tw), net) ||
25946 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
25947                         tw = tw_next(tw);
25948                 }
25949                 if (tw) {
25950 @@ -2178,6 +2200,11 @@ get_tw:
25951                 sk = sk_nulls_next(sk);
25952  
25953         sk_nulls_for_each_from(sk, node) {
25954 +               vxdprintk(VXD_CBIT(net, 6),
25955 +                       "sk,egn: %p [#%d] (from %d)",
25956 +                       sk, sk->sk_nid, nx_current_nid());
25957 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25958 +                       continue;
25959                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
25960                         goto found;
25961         }
25962 @@ -2387,9 +2414,9 @@ static void get_openreq4(struct sock *sk
25963         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
25964                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p%n",
25965                 i,
25966 -               ireq->loc_addr,
25967 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
25968                 ntohs(inet_sk(sk)->inet_sport),
25969 -               ireq->rmt_addr,
25970 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
25971                 ntohs(ireq->rmt_port),
25972                 TCP_SYN_RECV,
25973                 0, 0, /* could print option size, but that is af dependent. */
25974 @@ -2441,7 +2468,10 @@ static void get_tcp4_sock(struct sock *s
25975  
25976         seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
25977                         "%08X %5d %8d %lu %d %p %lu %lu %u %u %d%n",
25978 -               i, src, srcp, dest, destp, sk->sk_state,
25979 +               i,
25980 +               nx_map_sock_lback(current_nx_info(), src), srcp,
25981 +               nx_map_sock_lback(current_nx_info(), dest), destp,
25982 +               sk->sk_state,
25983                 tp->write_seq - tp->snd_una,
25984                 rx_queue,
25985                 timer_active,
25986 @@ -2476,7 +2506,10 @@ static void get_timewait4_sock(struct in
25987  
25988         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
25989                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
25990 -               i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
25991 +               i,
25992 +               nx_map_sock_lback(current_nx_info(), src), srcp,
25993 +               nx_map_sock_lback(current_nx_info(), dest), destp,
25994 +               tw->tw_substate, 0, 0,
25995                 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
25996                 atomic_read(&tw->tw_refcnt), tw, len);
25997  }
25998 diff -NurpP --minimal linux-2.6.36/net/ipv4/tcp_minisocks.c linux-2.6.36-vs2.3.0.36.33/net/ipv4/tcp_minisocks.c
25999 --- linux-2.6.36/net/ipv4/tcp_minisocks.c       2010-10-21 13:07:58.000000000 +0200
26000 +++ linux-2.6.36-vs2.3.0.36.33/net/ipv4/tcp_minisocks.c 2010-10-21 13:09:36.000000000 +0200
26001 @@ -23,6 +23,9 @@
26002  #include <linux/slab.h>
26003  #include <linux/sysctl.h>
26004  #include <linux/workqueue.h>
26005 +#include <linux/vs_limit.h>
26006 +#include <linux/vs_socket.h>
26007 +#include <linux/vs_context.h>
26008  #include <net/tcp.h>
26009  #include <net/inet_common.h>
26010  #include <net/xfrm.h>
26011 @@ -290,6 +293,11 @@ void tcp_time_wait(struct sock *sk, int 
26012                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
26013                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
26014  
26015 +               tw->tw_xid              = sk->sk_xid;
26016 +               tw->tw_vx_info          = NULL;
26017 +               tw->tw_nid              = sk->sk_nid;
26018 +               tw->tw_nx_info          = NULL;
26019 +
26020  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
26021                 if (tw->tw_family == PF_INET6) {
26022                         struct ipv6_pinfo *np = inet6_sk(sk);
26023 diff -NurpP --minimal linux-2.6.36/net/ipv4/udp.c linux-2.6.36-vs2.3.0.36.33/net/ipv4/udp.c
26024 --- linux-2.6.36/net/ipv4/udp.c 2010-10-21 13:07:59.000000000 +0200
26025 +++ linux-2.6.36-vs2.3.0.36.33/net/ipv4/udp.c   2010-10-21 13:09:36.000000000 +0200
26026 @@ -296,14 +296,7 @@ fail:
26027  }
26028  EXPORT_SYMBOL(udp_lib_get_port);
26029  
26030 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
26031 -{
26032 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
26033 -
26034 -       return  (!ipv6_only_sock(sk2)  &&
26035 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
26036 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
26037 -}
26038 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
26039  
26040  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
26041                                        unsigned int port)
26042 @@ -338,6 +331,11 @@ static inline int compute_score(struct s
26043                         if (inet->inet_rcv_saddr != daddr)
26044                                 return -1;
26045                         score += 2;
26046 +               } else {
26047 +                       /* block non nx_info ips */
26048 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
26049 +                               daddr, NXA_MASK_BIND))
26050 +                               return -1;
26051                 }
26052                 if (inet->inet_daddr) {
26053                         if (inet->inet_daddr != saddr)
26054 @@ -441,6 +439,7 @@ exact_match:
26055         return result;
26056  }
26057  
26058 +
26059  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
26060   * harder than this. -DaveM
26061   */
26062 @@ -486,6 +485,11 @@ begin:
26063         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
26064                 score = compute_score(sk, net, saddr, hnum, sport,
26065                                       daddr, dport, dif);
26066 +               /* FIXME: disabled?
26067 +               if (score == 9) {
26068 +                       result = sk;
26069 +                       break;
26070 +               } else */
26071                 if (score > badness) {
26072                         result = sk;
26073                         badness = score;
26074 @@ -499,6 +503,7 @@ begin:
26075         if (get_nulls_value(node) != slot)
26076                 goto begin;
26077  
26078 +
26079         if (result) {
26080                 if (unlikely(!atomic_inc_not_zero(&result->sk_refcnt)))
26081                         result = NULL;
26082 @@ -508,6 +513,7 @@ begin:
26083                         goto begin;
26084                 }
26085         }
26086 +
26087         rcu_read_unlock();
26088         return result;
26089  }
26090 @@ -550,8 +556,7 @@ static inline struct sock *udp_v4_mcast_
26091                     udp_sk(s)->udp_port_hash != hnum ||
26092                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
26093                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
26094 -                   (inet->inet_rcv_saddr &&
26095 -                    inet->inet_rcv_saddr != loc_addr) ||
26096 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
26097                     ipv6_only_sock(s) ||
26098                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
26099                         continue;
26100 @@ -900,8 +905,13 @@ int udp_sendmsg(struct kiocb *iocb, stru
26101                                                { .sport = inet->inet_sport,
26102                                                  .dport = dport } } };
26103                 struct net *net = sock_net(sk);
26104 +               struct nx_info *nxi = sk->sk_nx_info;
26105  
26106                 security_sk_classify_flow(sk, &fl);
26107 +               err = ip_v4_find_src(net, nxi, &rt, &fl);
26108 +               if (err)
26109 +                       goto out;
26110 +
26111                 err = ip_route_output_flow(net, &rt, &fl, sk, 1);
26112                 if (err) {
26113                         if (err == -ENETUNREACH)
26114 @@ -1183,7 +1193,8 @@ try_again:
26115         if (sin) {
26116                 sin->sin_family = AF_INET;
26117                 sin->sin_port = udp_hdr(skb)->source;
26118 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
26119 +               sin->sin_addr.s_addr = nx_map_sock_lback(
26120 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
26121                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
26122         }
26123         if (inet->cmsg_flags)
26124 @@ -1923,6 +1934,8 @@ static struct sock *udp_get_first(struct
26125                 sk_nulls_for_each(sk, node, &hslot->head) {
26126                         if (!net_eq(sock_net(sk), net))
26127                                 continue;
26128 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26129 +                               continue;
26130                         if (sk->sk_family == state->family)
26131                                 goto found;
26132                 }
26133 @@ -1940,7 +1953,9 @@ static struct sock *udp_get_next(struct 
26134  
26135         do {
26136                 sk = sk_nulls_next(sk);
26137 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
26138 +       } while (sk && (!net_eq(sock_net(sk), net) ||
26139 +               sk->sk_family != state->family ||
26140 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
26141  
26142         if (!sk) {
26143                 if (state->bucket <= state->udp_table->mask)
26144 @@ -2047,7 +2062,10 @@ static void udp4_format_sock(struct sock
26145  
26146         seq_printf(f, "%5d: %08X:%04X %08X:%04X"
26147                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d%n",
26148 -               bucket, src, srcp, dest, destp, sp->sk_state,
26149 +               bucket,
26150 +               nx_map_sock_lback(current_nx_info(), src), srcp,
26151 +               nx_map_sock_lback(current_nx_info(), dest), destp,
26152 +               sp->sk_state,
26153                 sk_wmem_alloc_get(sp),
26154                 sk_rmem_alloc_get(sp),
26155                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
26156 diff -NurpP --minimal linux-2.6.36/net/ipv6/addrconf.c linux-2.6.36-vs2.3.0.36.33/net/ipv6/addrconf.c
26157 --- linux-2.6.36/net/ipv6/addrconf.c    2010-10-21 13:07:59.000000000 +0200
26158 +++ linux-2.6.36-vs2.3.0.36.33/net/ipv6/addrconf.c      2010-10-21 13:09:36.000000000 +0200
26159 @@ -87,6 +87,8 @@
26160  
26161  #include <linux/proc_fs.h>
26162  #include <linux/seq_file.h>
26163 +#include <linux/vs_network.h>
26164 +#include <linux/vs_inet6.h>
26165  
26166  /* Set to 3 to get tracing... */
26167  #define ACONF_DEBUG 2
26168 @@ -1119,7 +1121,7 @@ out:
26169  
26170  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
26171                        const struct in6_addr *daddr, unsigned int prefs,
26172 -                      struct in6_addr *saddr)
26173 +                      struct in6_addr *saddr, struct nx_info *nxi)
26174  {
26175         struct ipv6_saddr_score scores[2],
26176                                 *score = &scores[0], *hiscore = &scores[1];
26177 @@ -1191,6 +1193,8 @@ int ipv6_dev_get_saddr(struct net *net, 
26178                                                dev->name);
26179                                 continue;
26180                         }
26181 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
26182 +                               continue;
26183  
26184                         score->rule = -1;
26185                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
26186 @@ -3077,7 +3081,10 @@ static void if6_seq_stop(struct seq_file
26187  static int if6_seq_show(struct seq_file *seq, void *v)
26188  {
26189         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
26190 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
26191 +
26192 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
26193 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
26194 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
26195                    &ifp->addr,
26196                    ifp->idev->dev->ifindex,
26197                    ifp->prefix_len,
26198 @@ -3585,6 +3592,11 @@ static int in6_dump_addrs(struct inet6_d
26199         struct ifacaddr6 *ifaca;
26200         int err = 1;
26201         int ip_idx = *p_ip_idx;
26202 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
26203 +
26204 +       /* disable ipv6 on non v6 guests */
26205 +       if (nxi && !nx_info_has_v6(nxi))
26206 +               return skb->len;
26207  
26208         read_lock_bh(&idev->lock);
26209         switch (type) {
26210 @@ -3595,6 +3607,8 @@ static int in6_dump_addrs(struct inet6_d
26211                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
26212                         if (++ip_idx < s_ip_idx)
26213                                 continue;
26214 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
26215 +                                       continue;
26216                         err = inet6_fill_ifaddr(skb, ifa,
26217                                                 NETLINK_CB(cb->skb).pid,
26218                                                 cb->nlh->nlmsg_seq,
26219 @@ -3611,6 +3625,8 @@ static int in6_dump_addrs(struct inet6_d
26220                      ifmca = ifmca->next, ip_idx++) {
26221                         if (ip_idx < s_ip_idx)
26222                                 continue;
26223 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
26224 +                                       continue;
26225                         err = inet6_fill_ifmcaddr(skb, ifmca,
26226                                                   NETLINK_CB(cb->skb).pid,
26227                                                   cb->nlh->nlmsg_seq,
26228 @@ -3626,6 +3642,8 @@ static int in6_dump_addrs(struct inet6_d
26229                      ifaca = ifaca->aca_next, ip_idx++) {
26230                         if (ip_idx < s_ip_idx)
26231                                 continue;
26232 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
26233 +                                       continue;
26234                         err = inet6_fill_ifacaddr(skb, ifaca,
26235                                                   NETLINK_CB(cb->skb).pid,
26236                                                   cb->nlh->nlmsg_seq,
26237 @@ -3973,6 +3991,11 @@ static int inet6_dump_ifinfo(struct sk_b
26238         struct inet6_dev *idev;
26239         struct hlist_head *head;
26240         struct hlist_node *node;
26241 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
26242 +
26243 +       /* FIXME: maybe disable ipv6 on non v6 guests?
26244 +       if (skb->sk && skb->sk->sk_vx_info)
26245 +               return skb->len; */
26246  
26247         s_h = cb->args[0];
26248         s_idx = cb->args[1];
26249 @@ -3984,6 +4007,8 @@ static int inet6_dump_ifinfo(struct sk_b
26250                 hlist_for_each_entry_rcu(dev, node, head, index_hlist) {
26251                         if (idx < s_idx)
26252                                 goto cont;
26253 +                       if (!v6_dev_in_nx_info(dev, nxi))
26254 +                               goto cont;
26255                         idev = __in6_dev_get(dev);
26256                         if (!idev)
26257                                 goto cont;
26258 diff -NurpP --minimal linux-2.6.36/net/ipv6/af_inet6.c linux-2.6.36-vs2.3.0.36.33/net/ipv6/af_inet6.c
26259 --- linux-2.6.36/net/ipv6/af_inet6.c    2010-10-21 13:07:59.000000000 +0200
26260 +++ linux-2.6.36-vs2.3.0.36.33/net/ipv6/af_inet6.c      2010-10-21 13:09:36.000000000 +0200
26261 @@ -42,6 +42,8 @@
26262  #include <linux/netdevice.h>
26263  #include <linux/icmpv6.h>
26264  #include <linux/netfilter_ipv6.h>
26265 +#include <linux/vs_inet.h>
26266 +#include <linux/vs_inet6.h>
26267  
26268  #include <net/ip.h>
26269  #include <net/ipv6.h>
26270 @@ -160,9 +162,12 @@ lookup_protocol:
26271         }
26272  
26273         err = -EPERM;
26274 +       if ((protocol == IPPROTO_ICMPV6) &&
26275 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
26276 +               goto override;
26277         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
26278                 goto out_rcu_unlock;
26279 -
26280 +override:
26281         sock->ops = answer->ops;
26282         answer_prot = answer->prot;
26283         answer_no_check = answer->no_check;
26284 @@ -261,6 +266,7 @@ int inet6_bind(struct socket *sock, stru
26285         struct inet_sock *inet = inet_sk(sk);
26286         struct ipv6_pinfo *np = inet6_sk(sk);
26287         struct net *net = sock_net(sk);
26288 +       struct nx_v6_sock_addr nsa;
26289         __be32 v4addr = 0;
26290         unsigned short snum;
26291         int addr_type = 0;
26292 @@ -272,6 +278,11 @@ int inet6_bind(struct socket *sock, stru
26293  
26294         if (addr_len < SIN6_LEN_RFC2133)
26295                 return -EINVAL;
26296 +
26297 +       err = v6_map_sock_addr(inet, addr, &nsa);
26298 +       if (err)
26299 +               return err;
26300 +
26301         addr_type = ipv6_addr_type(&addr->sin6_addr);
26302         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
26303                 return -EINVAL;
26304 @@ -303,6 +314,7 @@ int inet6_bind(struct socket *sock, stru
26305                 /* Reproduce AF_INET checks to make the bindings consitant */
26306                 v4addr = addr->sin6_addr.s6_addr32[3];
26307                 chk_addr_ret = inet_addr_type(net, v4addr);
26308 +
26309                 if (!sysctl_ip_nonlocal_bind &&
26310                     !(inet->freebind || inet->transparent) &&
26311                     v4addr != htonl(INADDR_ANY) &&
26312 @@ -312,6 +324,10 @@ int inet6_bind(struct socket *sock, stru
26313                         err = -EADDRNOTAVAIL;
26314                         goto out;
26315                 }
26316 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
26317 +                       err = -EADDRNOTAVAIL;
26318 +                       goto out;
26319 +               }
26320         } else {
26321                 if (addr_type != IPV6_ADDR_ANY) {
26322                         struct net_device *dev = NULL;
26323 @@ -338,6 +354,11 @@ int inet6_bind(struct socket *sock, stru
26324                                 }
26325                         }
26326  
26327 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
26328 +                               err = -EADDRNOTAVAIL;
26329 +                               goto out;
26330 +                       }
26331 +
26332                         /* ipv4 addr of the socket is invalid.  Only the
26333                          * unspecified and mapped address have a v4 equivalent.
26334                          */
26335 @@ -353,6 +374,9 @@ int inet6_bind(struct socket *sock, stru
26336                 }
26337         }
26338  
26339 +       /* what's that for? */
26340 +       v6_set_sock_addr(inet, &nsa);
26341 +
26342         inet->inet_rcv_saddr = v4addr;
26343         inet->inet_saddr = v4addr;
26344  
26345 @@ -454,9 +478,11 @@ int inet6_getname(struct socket *sock, s
26346                         return -ENOTCONN;
26347                 sin->sin6_port = inet->inet_dport;
26348                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
26349 +               /* FIXME: remap lback? */
26350                 if (np->sndflow)
26351                         sin->sin6_flowinfo = np->flow_label;
26352         } else {
26353 +               /* FIXME: remap lback? */
26354                 if (ipv6_addr_any(&np->rcv_saddr))
26355                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
26356                 else
26357 diff -NurpP --minimal linux-2.6.36/net/ipv6/fib6_rules.c linux-2.6.36-vs2.3.0.36.33/net/ipv6/fib6_rules.c
26358 --- linux-2.6.36/net/ipv6/fib6_rules.c  2010-10-21 13:07:59.000000000 +0200
26359 +++ linux-2.6.36-vs2.3.0.36.33/net/ipv6/fib6_rules.c    2010-10-21 13:09:36.000000000 +0200
26360 @@ -89,7 +89,7 @@ static int fib6_rule_action(struct fib_r
26361                                                ip6_dst_idev(&rt->dst)->dev,
26362                                                &flp->fl6_dst,
26363                                                rt6_flags2srcprefs(flags),
26364 -                                              &saddr))
26365 +                                              &saddr, NULL))
26366                                 goto again;
26367                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
26368                                                r->src.plen))
26369 diff -NurpP --minimal linux-2.6.36/net/ipv6/inet6_hashtables.c linux-2.6.36-vs2.3.0.36.33/net/ipv6/inet6_hashtables.c
26370 --- linux-2.6.36/net/ipv6/inet6_hashtables.c    2010-02-25 11:52:10.000000000 +0100
26371 +++ linux-2.6.36-vs2.3.0.36.33/net/ipv6/inet6_hashtables.c      2010-10-21 13:09:36.000000000 +0200
26372 @@ -16,6 +16,7 @@
26373  
26374  #include <linux/module.h>
26375  #include <linux/random.h>
26376 +#include <linux/vs_inet6.h>
26377  
26378  #include <net/inet_connection_sock.h>
26379  #include <net/inet_hashtables.h>
26380 @@ -82,7 +83,6 @@ struct sock *__inet6_lookup_established(
26381         unsigned int slot = hash & hashinfo->ehash_mask;
26382         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
26383  
26384 -
26385         rcu_read_lock();
26386  begin:
26387         sk_nulls_for_each_rcu(sk, node, &head->chain) {
26388 @@ -94,7 +94,7 @@ begin:
26389                                 sock_put(sk);
26390                                 goto begin;
26391                         }
26392 -               goto out;
26393 +                       goto out;
26394                 }
26395         }
26396         if (get_nulls_value(node) != slot)
26397 @@ -140,6 +140,9 @@ static int inline compute_score(struct s
26398                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
26399                                 return -1;
26400                         score++;
26401 +               } else {
26402 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
26403 +                               return -1;
26404                 }
26405                 if (sk->sk_bound_dev_if) {
26406                         if (sk->sk_bound_dev_if != dif)
26407 diff -NurpP --minimal linux-2.6.36/net/ipv6/ip6_output.c linux-2.6.36-vs2.3.0.36.33/net/ipv6/ip6_output.c
26408 --- linux-2.6.36/net/ipv6/ip6_output.c  2010-10-21 13:07:59.000000000 +0200
26409 +++ linux-2.6.36-vs2.3.0.36.33/net/ipv6/ip6_output.c    2010-10-21 13:09:36.000000000 +0200
26410 @@ -938,7 +938,7 @@ static int ip6_dst_lookup_tail(struct so
26411                 err = ipv6_dev_get_saddr(net, ip6_dst_idev(*dst)->dev,
26412                                          &fl->fl6_dst,
26413                                          sk ? inet6_sk(sk)->srcprefs : 0,
26414 -                                        &fl->fl6_src);
26415 +                                        &fl->fl6_src, sk->sk_nx_info);
26416                 if (err)
26417                         goto out_err_release;
26418         }
26419 diff -NurpP --minimal linux-2.6.36/net/ipv6/Kconfig linux-2.6.36-vs2.3.0.36.33/net/ipv6/Kconfig
26420 --- linux-2.6.36/net/ipv6/Kconfig       2010-08-02 16:52:59.000000000 +0200
26421 +++ linux-2.6.36-vs2.3.0.36.33/net/ipv6/Kconfig 2010-10-21 13:09:36.000000000 +0200
26422 @@ -4,8 +4,8 @@
26423  
26424  #   IPv6 as module will cause a CRASH if you try to unload it
26425  menuconfig IPV6
26426 -       tristate "The IPv6 protocol"
26427 -       default m
26428 +       bool "The IPv6 protocol"
26429 +       default n
26430         ---help---
26431           This is complemental support for the IP version 6.
26432           You will still be able to do traditional IPv4 networking as well.
26433 diff -NurpP --minimal linux-2.6.36/net/ipv6/ndisc.c linux-2.6.36-vs2.3.0.36.33/net/ipv6/ndisc.c
26434 --- linux-2.6.36/net/ipv6/ndisc.c       2010-10-21 13:07:59.000000000 +0200
26435 +++ linux-2.6.36-vs2.3.0.36.33/net/ipv6/ndisc.c 2010-10-21 13:09:36.000000000 +0200
26436 @@ -591,7 +591,7 @@ static void ndisc_send_na(struct net_dev
26437         } else {
26438                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
26439                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
26440 -                                      &tmpaddr))
26441 +                                      &tmpaddr, NULL /* FIXME: ? */ ))
26442                         return;
26443                 src_addr = &tmpaddr;
26444         }
26445 diff -NurpP --minimal linux-2.6.36/net/ipv6/raw.c linux-2.6.36-vs2.3.0.36.33/net/ipv6/raw.c
26446 --- linux-2.6.36/net/ipv6/raw.c 2010-10-21 13:07:59.000000000 +0200
26447 +++ linux-2.6.36-vs2.3.0.36.33/net/ipv6/raw.c   2010-10-21 13:09:36.000000000 +0200
26448 @@ -30,6 +30,7 @@
26449  #include <linux/icmpv6.h>
26450  #include <linux/netfilter.h>
26451  #include <linux/netfilter_ipv6.h>
26452 +#include <linux/vs_inet6.h>
26453  #include <linux/skbuff.h>
26454  #include <asm/uaccess.h>
26455  #include <asm/ioctls.h>
26456 @@ -283,6 +284,13 @@ static int rawv6_bind(struct sock *sk, s
26457                                 goto out_unlock;
26458                 }
26459  
26460 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
26461 +                       err = -EADDRNOTAVAIL;
26462 +                       if (dev)
26463 +                               dev_put(dev);
26464 +                       goto out;
26465 +               }
26466 +
26467                 /* ipv4 addr of the socket is invalid.  Only the
26468                  * unspecified and mapped address have a v4 equivalent.
26469                  */
26470 diff -NurpP --minimal linux-2.6.36/net/ipv6/route.c linux-2.6.36-vs2.3.0.36.33/net/ipv6/route.c
26471 --- linux-2.6.36/net/ipv6/route.c       2010-10-21 13:07:59.000000000 +0200
26472 +++ linux-2.6.36-vs2.3.0.36.33/net/ipv6/route.c 2010-10-21 13:09:36.000000000 +0200
26473 @@ -2272,7 +2272,8 @@ static int rt6_fill_node(struct net *net
26474                 struct inet6_dev *idev = ip6_dst_idev(&rt->dst);
26475                 struct in6_addr saddr_buf;
26476                 if (ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
26477 -                                      dst, 0, &saddr_buf) == 0)
26478 +                       dst, 0, &saddr_buf,
26479 +                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
26480                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
26481         }
26482  
26483 diff -NurpP --minimal linux-2.6.36/net/ipv6/tcp_ipv6.c linux-2.6.36-vs2.3.0.36.33/net/ipv6/tcp_ipv6.c
26484 --- linux-2.6.36/net/ipv6/tcp_ipv6.c    2010-10-21 13:07:59.000000000 +0200
26485 +++ linux-2.6.36-vs2.3.0.36.33/net/ipv6/tcp_ipv6.c      2010-10-21 13:09:36.000000000 +0200
26486 @@ -69,6 +69,7 @@
26487  
26488  #include <linux/crypto.h>
26489  #include <linux/scatterlist.h>
26490 +#include <linux/vs_inet6.h>
26491  
26492  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
26493  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
26494 @@ -160,8 +161,15 @@ static int tcp_v6_connect(struct sock *s
26495          *      connect() to INADDR_ANY means loopback (BSD'ism).
26496          */
26497  
26498 -       if(ipv6_addr_any(&usin->sin6_addr))
26499 -               usin->sin6_addr.s6_addr[15] = 0x1;
26500 +       if(ipv6_addr_any(&usin->sin6_addr)) {
26501 +               struct nx_info *nxi =  sk->sk_nx_info;
26502 +
26503 +               if (nxi && nx_info_has_v6(nxi))
26504 +                       /* FIXME: remap lback? */
26505 +                       usin->sin6_addr = nxi->v6.ip;
26506 +               else
26507 +                       usin->sin6_addr.s6_addr[15] = 0x1;
26508 +       }
26509  
26510         addr_type = ipv6_addr_type(&usin->sin6_addr);
26511  
26512 diff -NurpP --minimal linux-2.6.36/net/ipv6/udp.c linux-2.6.36-vs2.3.0.36.33/net/ipv6/udp.c
26513 --- linux-2.6.36/net/ipv6/udp.c 2010-10-21 13:07:59.000000000 +0200
26514 +++ linux-2.6.36-vs2.3.0.36.33/net/ipv6/udp.c   2010-10-21 13:09:36.000000000 +0200
26515 @@ -48,13 +48,14 @@
26516  
26517  #include <linux/proc_fs.h>
26518  #include <linux/seq_file.h>
26519 +#include <linux/vs_inet6.h>
26520  #include "udp_impl.h"
26521  
26522  int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
26523  {
26524         const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
26525         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
26526 -       __be32 sk1_rcv_saddr = inet_sk(sk)->inet_rcv_saddr;
26527 +       __be32 sk_rcv_saddr = inet_sk(sk)->inet_rcv_saddr;
26528         __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
26529         int sk_ipv6only = ipv6_only_sock(sk);
26530         int sk2_ipv6only = inet_v6_ipv6only(sk2);
26531 @@ -62,24 +63,49 @@ int ipv6_rcv_saddr_equal(const struct so
26532         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
26533  
26534         /* if both are mapped, treat as IPv4 */
26535 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
26536 -               return (!sk2_ipv6only &&
26537 -                       (!sk1_rcv_saddr || !sk2_rcv_saddr ||
26538 -                         sk1_rcv_saddr == sk2_rcv_saddr));
26539 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
26540 +               if (!sk2_ipv6only &&
26541 +                       (!sk_rcv_saddr || !sk2_rcv_saddr ||
26542 +                         sk_rcv_saddr == sk2_rcv_saddr))
26543 +                       goto vs_v4;
26544 +               else
26545 +                       return 0;
26546 +       }
26547  
26548         if (addr_type2 == IPV6_ADDR_ANY &&
26549             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
26550 -               return 1;
26551 +               goto vs;
26552  
26553         if (addr_type == IPV6_ADDR_ANY &&
26554             !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
26555 -               return 1;
26556 +               goto vs;
26557  
26558         if (sk2_rcv_saddr6 &&
26559             ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
26560 -               return 1;
26561 +               goto vs;
26562  
26563         return 0;
26564 +
26565 +vs_v4:
26566 +       if (!sk_rcv_saddr && !sk2_rcv_saddr)
26567 +               return nx_v4_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info);
26568 +       if (!sk2_rcv_saddr)
26569 +               return v4_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr, -1);
26570 +       if (!sk_rcv_saddr)
26571 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr, -1);
26572 +       return 1;
26573 +vs:
26574 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
26575 +               return nx_v6_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info);
26576 +       else if (addr_type2 == IPV6_ADDR_ANY)
26577 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr6, -1);
26578 +       else if (addr_type == IPV6_ADDR_ANY) {
26579 +               if (addr_type2 == IPV6_ADDR_MAPPED)
26580 +                       return nx_v4_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info);
26581 +               else
26582 +                       return v6_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr6, -1);
26583 +       }
26584 +       return 1;
26585  }
26586  
26587  static unsigned int udp6_portaddr_hash(struct net *net,
26588 @@ -143,6 +169,10 @@ static inline int compute_score(struct s
26589                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
26590                                 return -1;
26591                         score++;
26592 +               } else {
26593 +                       /* block non nx_info ips */
26594 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
26595 +                               return -1;
26596                 }
26597                 if (!ipv6_addr_any(&np->daddr)) {
26598                         if (!ipv6_addr_equal(&np->daddr, saddr))
26599 diff -NurpP --minimal linux-2.6.36/net/ipv6/xfrm6_policy.c linux-2.6.36-vs2.3.0.36.33/net/ipv6/xfrm6_policy.c
26600 --- linux-2.6.36/net/ipv6/xfrm6_policy.c        2010-08-02 16:53:00.000000000 +0200
26601 +++ linux-2.6.36-vs2.3.0.36.33/net/ipv6/xfrm6_policy.c  2010-10-21 13:09:36.000000000 +0200
26602 @@ -62,7 +62,7 @@ static int xfrm6_get_saddr(struct net *n
26603         dev = ip6_dst_idev(dst)->dev;
26604         ipv6_dev_get_saddr(dev_net(dev), dev,
26605                            (struct in6_addr *)&daddr->a6, 0,
26606 -                          (struct in6_addr *)&saddr->a6);
26607 +                          (struct in6_addr *)&saddr->a6, NULL);
26608         dst_release(dst);
26609         return 0;
26610  }
26611 diff -NurpP --minimal linux-2.6.36/net/netlink/af_netlink.c linux-2.6.36-vs2.3.0.36.33/net/netlink/af_netlink.c
26612 --- linux-2.6.36/net/netlink/af_netlink.c       2010-10-21 13:08:01.000000000 +0200
26613 +++ linux-2.6.36-vs2.3.0.36.33/net/netlink/af_netlink.c 2010-10-21 13:09:36.000000000 +0200
26614 @@ -55,6 +55,9 @@
26615  #include <linux/types.h>
26616  #include <linux/audit.h>
26617  #include <linux/mutex.h>
26618 +#include <linux/vs_context.h>
26619 +#include <linux/vs_network.h>
26620 +#include <linux/vs_limit.h>
26621  
26622  #include <net/net_namespace.h>
26623  #include <net/sock.h>
26624 @@ -1928,6 +1931,8 @@ static struct sock *netlink_seq_socket_i
26625                         sk_for_each(s, node, &hash->table[j]) {
26626                                 if (sock_net(s) != seq_file_net(seq))
26627                                         continue;
26628 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26629 +                                       continue;
26630                                 if (off == pos) {
26631                                         iter->link = i;
26632                                         iter->hash_idx = j;
26633 @@ -1962,7 +1967,8 @@ static void *netlink_seq_next(struct seq
26634         s = v;
26635         do {
26636                 s = sk_next(s);
26637 -       } while (s && sock_net(s) != seq_file_net(seq));
26638 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
26639 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
26640         if (s)
26641                 return s;
26642  
26643 @@ -1974,7 +1980,8 @@ static void *netlink_seq_next(struct seq
26644  
26645                 for (; j <= hash->mask; j++) {
26646                         s = sk_head(&hash->table[j]);
26647 -                       while (s && sock_net(s) != seq_file_net(seq))
26648 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
26649 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
26650                                 s = sk_next(s);
26651                         if (s) {
26652                                 iter->link = i;
26653 diff -NurpP --minimal linux-2.6.36/net/sctp/ipv6.c linux-2.6.36-vs2.3.0.36.33/net/sctp/ipv6.c
26654 --- linux-2.6.36/net/sctp/ipv6.c        2010-08-02 16:53:01.000000000 +0200
26655 +++ linux-2.6.36-vs2.3.0.36.33/net/sctp/ipv6.c  2010-10-21 13:09:36.000000000 +0200
26656 @@ -304,7 +304,8 @@ static void sctp_v6_get_saddr(struct sct
26657                                    dst ? ip6_dst_idev(dst)->dev : NULL,
26658                                    &daddr->v6.sin6_addr,
26659                                    inet6_sk(&sk->inet.sk)->srcprefs,
26660 -                                  &saddr->v6.sin6_addr);
26661 +                                  &saddr->v6.sin6_addr,
26662 +                                  asoc->base.sk->sk_nx_info);
26663                 SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: %pI6\n",
26664                                   &saddr->v6.sin6_addr);
26665                 return;
26666 diff -NurpP --minimal linux-2.6.36/net/socket.c linux-2.6.36-vs2.3.0.36.33/net/socket.c
26667 --- linux-2.6.36/net/socket.c   2010-10-21 13:08:01.000000000 +0200
26668 +++ linux-2.6.36-vs2.3.0.36.33/net/socket.c     2010-10-21 13:09:36.000000000 +0200
26669 @@ -98,6 +98,10 @@
26670  
26671  #include <net/sock.h>
26672  #include <linux/netfilter.h>
26673 +#include <linux/vs_base.h>
26674 +#include <linux/vs_socket.h>
26675 +#include <linux/vs_inet.h>
26676 +#include <linux/vs_inet6.h>
26677  
26678  #include <linux/if_tun.h>
26679  #include <linux/ipv6_route.h>
26680 @@ -551,7 +555,7 @@ static inline int __sock_sendmsg(struct 
26681                                  struct msghdr *msg, size_t size)
26682  {
26683         struct sock_iocb *si = kiocb_to_siocb(iocb);
26684 -       int err;
26685 +       int err, len;
26686  
26687         sock_update_classid(sock->sk);
26688  
26689 @@ -564,7 +568,22 @@ static inline int __sock_sendmsg(struct 
26690         if (err)
26691                 return err;
26692  
26693 -       return sock->ops->sendmsg(iocb, sock, msg, size);
26694 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
26695 +       if (sock->sk) {
26696 +               if (len == size)
26697 +                       vx_sock_send(sock->sk, size);
26698 +               else
26699 +                       vx_sock_fail(sock->sk, size);
26700 +       }
26701 +       vxdprintk(VXD_CBIT(net, 7),
26702 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
26703 +               sock, sock->sk,
26704 +               (sock->sk)?sock->sk->sk_nx_info:0,
26705 +               (sock->sk)?sock->sk->sk_vx_info:0,
26706 +               (sock->sk)?sock->sk->sk_xid:0,
26707 +               (sock->sk)?sock->sk->sk_nid:0,
26708 +               (unsigned int)size, len);
26709 +       return len;
26710  }
26711  
26712  int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
26713 @@ -681,6 +700,7 @@ static inline int __sock_recvmsg_nosec(s
26714                                        struct msghdr *msg, size_t size, int flags)
26715  {
26716         struct sock_iocb *si = kiocb_to_siocb(iocb);
26717 +       int len;
26718  
26719         sock_update_classid(sock->sk);
26720  
26721 @@ -690,7 +710,18 @@ static inline int __sock_recvmsg_nosec(s
26722         si->size = size;
26723         si->flags = flags;
26724  
26725 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
26726 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
26727 +       if ((len >= 0) && sock->sk)
26728 +               vx_sock_recv(sock->sk, len);
26729 +       vxdprintk(VXD_CBIT(net, 7),
26730 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
26731 +               sock, sock->sk,
26732 +               (sock->sk)?sock->sk->sk_nx_info:0,
26733 +               (sock->sk)?sock->sk->sk_vx_info:0,
26734 +               (sock->sk)?sock->sk->sk_xid:0,
26735 +               (sock->sk)?sock->sk->sk_nid:0,
26736 +               (unsigned int)size, len);
26737 +       return len;
26738  }
26739  
26740  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
26741 @@ -1159,6 +1190,13 @@ static int __sock_create(struct net *net
26742         if (type < 0 || type >= SOCK_MAX)
26743                 return -EINVAL;
26744  
26745 +       if (!nx_check(0, VS_ADMIN)) {
26746 +               if (family == PF_INET && !current_nx_info_has_v4())
26747 +                       return -EAFNOSUPPORT;
26748 +               if (family == PF_INET6 && !current_nx_info_has_v6())
26749 +                       return -EAFNOSUPPORT;
26750 +       }
26751 +
26752         /* Compatibility.
26753  
26754            This uglymoron is moved from INET layer to here to avoid
26755 @@ -1293,6 +1331,7 @@ SYSCALL_DEFINE3(socket, int, family, int
26756         if (retval < 0)
26757                 goto out;
26758  
26759 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
26760         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
26761         if (retval < 0)
26762                 goto out_release;
26763 @@ -1334,10 +1373,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
26764         err = sock_create(family, type, protocol, &sock1);
26765         if (err < 0)
26766                 goto out;
26767 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
26768  
26769         err = sock_create(family, type, protocol, &sock2);
26770         if (err < 0)
26771                 goto out_release_1;
26772 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
26773  
26774         err = sock1->ops->socketpair(sock1, sock2);
26775         if (err < 0)
26776 diff -NurpP --minimal linux-2.6.36/net/sunrpc/auth.c linux-2.6.36-vs2.3.0.36.33/net/sunrpc/auth.c
26777 --- linux-2.6.36/net/sunrpc/auth.c      2010-10-21 13:08:01.000000000 +0200
26778 +++ linux-2.6.36-vs2.3.0.36.33/net/sunrpc/auth.c        2010-10-21 13:09:36.000000000 +0200
26779 @@ -14,6 +14,7 @@
26780  #include <linux/hash.h>
26781  #include <linux/sunrpc/clnt.h>
26782  #include <linux/spinlock.h>
26783 +#include <linux/vs_tag.h>
26784  
26785  #ifdef RPC_DEBUG
26786  # define RPCDBG_FACILITY       RPCDBG_AUTH
26787 @@ -425,6 +426,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
26788         memset(&acred, 0, sizeof(acred));
26789         acred.uid = cred->fsuid;
26790         acred.gid = cred->fsgid;
26791 +       acred.tag = dx_current_tag();
26792         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
26793  
26794         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
26795 @@ -465,6 +467,7 @@ rpcauth_bind_root_cred(struct rpc_task *
26796         struct auth_cred acred = {
26797                 .uid = 0,
26798                 .gid = 0,
26799 +               .tag = dx_current_tag(),
26800         };
26801  
26802         dprintk("RPC: %5u looking up %s cred\n",
26803 diff -NurpP --minimal linux-2.6.36/net/sunrpc/auth_unix.c linux-2.6.36-vs2.3.0.36.33/net/sunrpc/auth_unix.c
26804 --- linux-2.6.36/net/sunrpc/auth_unix.c 2010-10-21 13:08:01.000000000 +0200
26805 +++ linux-2.6.36-vs2.3.0.36.33/net/sunrpc/auth_unix.c   2010-10-21 13:09:36.000000000 +0200
26806 @@ -12,12 +12,14 @@
26807  #include <linux/module.h>
26808  #include <linux/sunrpc/clnt.h>
26809  #include <linux/sunrpc/auth.h>
26810 +#include <linux/vs_tag.h>
26811  
26812  #define NFS_NGROUPS    16
26813  
26814  struct unx_cred {
26815         struct rpc_cred         uc_base;
26816         gid_t                   uc_gid;
26817 +       tag_t                   uc_tag;
26818         gid_t                   uc_gids[NFS_NGROUPS];
26819  };
26820  #define uc_uid                 uc_base.cr_uid
26821 @@ -78,6 +80,7 @@ unx_create_cred(struct rpc_auth *auth, s
26822                 groups = NFS_NGROUPS;
26823  
26824         cred->uc_gid = acred->gid;
26825 +       cred->uc_tag = acred->tag;
26826         for (i = 0; i < groups; i++)
26827                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
26828         if (i < NFS_NGROUPS)
26829 @@ -119,7 +122,9 @@ unx_match(struct auth_cred *acred, struc
26830         unsigned int i;
26831  
26832  
26833 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
26834 +       if (cred->uc_uid != acred->uid ||
26835 +               cred->uc_gid != acred->gid ||
26836 +               cred->uc_tag != acred->tag)
26837                 return 0;
26838  
26839         if (acred->group_info != NULL)
26840 @@ -142,7 +147,7 @@ unx_marshal(struct rpc_task *task, __be3
26841         struct rpc_clnt *clnt = task->tk_client;
26842         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
26843         __be32          *base, *hold;
26844 -       int             i;
26845 +       int             i, tag;
26846  
26847         *p++ = htonl(RPC_AUTH_UNIX);
26848         base = p++;
26849 @@ -152,9 +157,12 @@ unx_marshal(struct rpc_task *task, __be3
26850          * Copy the UTS nodename captured when the client was created.
26851          */
26852         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
26853 +       tag = task->tk_client->cl_tag;
26854  
26855 -       *p++ = htonl((u32) cred->uc_uid);
26856 -       *p++ = htonl((u32) cred->uc_gid);
26857 +       *p++ = htonl((u32) TAGINO_UID(tag,
26858 +               cred->uc_uid, cred->uc_tag));
26859 +       *p++ = htonl((u32) TAGINO_GID(tag,
26860 +               cred->uc_gid, cred->uc_tag));
26861         hold = p++;
26862         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
26863                 *p++ = htonl((u32) cred->uc_gids[i]);
26864 diff -NurpP --minimal linux-2.6.36/net/sunrpc/clnt.c linux-2.6.36-vs2.3.0.36.33/net/sunrpc/clnt.c
26865 --- linux-2.6.36/net/sunrpc/clnt.c      2010-10-21 13:08:01.000000000 +0200
26866 +++ linux-2.6.36-vs2.3.0.36.33/net/sunrpc/clnt.c        2010-10-21 13:09:36.000000000 +0200
26867 @@ -33,6 +33,7 @@
26868  #include <linux/utsname.h>
26869  #include <linux/workqueue.h>
26870  #include <linux/in6.h>
26871 +#include <linux/vs_cvirt.h>
26872  
26873  #include <linux/sunrpc/clnt.h>
26874  #include <linux/sunrpc/rpc_pipe_fs.h>
26875 @@ -358,6 +359,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
26876         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
26877                 clnt->cl_chatty = 1;
26878  
26879 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
26880 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
26881 +               clnt->cl_tag = 1; */
26882         return clnt;
26883  }
26884  EXPORT_SYMBOL_GPL(rpc_create);
26885 diff -NurpP --minimal linux-2.6.36/net/unix/af_unix.c linux-2.6.36-vs2.3.0.36.33/net/unix/af_unix.c
26886 --- linux-2.6.36/net/unix/af_unix.c     2010-10-21 13:08:01.000000000 +0200
26887 +++ linux-2.6.36-vs2.3.0.36.33/net/unix/af_unix.c       2010-10-21 13:09:36.000000000 +0200
26888 @@ -114,6 +114,8 @@
26889  #include <linux/mount.h>
26890  #include <net/checksum.h>
26891  #include <linux/security.h>
26892 +#include <linux/vs_context.h>
26893 +#include <linux/vs_limit.h>
26894  
26895  static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
26896  static DEFINE_SPINLOCK(unix_table_lock);
26897 @@ -258,6 +260,8 @@ static struct sock *__unix_find_socket_b
26898                 if (!net_eq(sock_net(s), net))
26899                         continue;
26900  
26901 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26902 +                       continue;
26903                 if (u->addr->len == len &&
26904                     !memcmp(u->addr->name, sunname, len))
26905                         goto found;
26906 @@ -2148,6 +2152,8 @@ static struct sock *unix_seq_idx(struct 
26907         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
26908                 if (sock_net(s) != seq_file_net(seq))
26909                         continue;
26910 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
26911 +                       continue;
26912                 if (off == pos)
26913                         return s;
26914                 ++off;
26915 @@ -2172,7 +2178,8 @@ static void *unix_seq_next(struct seq_fi
26916                 sk = first_unix_socket(&iter->i);
26917         else
26918                 sk = next_unix_socket(&iter->i, sk);
26919 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
26920 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
26921 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
26922                 sk = next_unix_socket(&iter->i, sk);
26923         return sk;
26924  }
26925 diff -NurpP --minimal linux-2.6.36/scripts/checksyscalls.sh linux-2.6.36-vs2.3.0.36.33/scripts/checksyscalls.sh
26926 --- linux-2.6.36/scripts/checksyscalls.sh       2010-10-21 13:08:01.000000000 +0200
26927 +++ linux-2.6.36-vs2.3.0.36.33/scripts/checksyscalls.sh 2010-10-21 13:09:36.000000000 +0200
26928 @@ -193,7 +193,6 @@ cat << EOF
26929  #define __IGNORE_afs_syscall
26930  #define __IGNORE_getpmsg
26931  #define __IGNORE_putpmsg
26932 -#define __IGNORE_vserver
26933  EOF
26934  }
26935  
26936 diff -NurpP --minimal linux-2.6.36/security/commoncap.c linux-2.6.36-vs2.3.0.36.33/security/commoncap.c
26937 --- linux-2.6.36/security/commoncap.c   2010-10-21 13:08:02.000000000 +0200
26938 +++ linux-2.6.36-vs2.3.0.36.33/security/commoncap.c     2010-10-21 13:09:36.000000000 +0200
26939 @@ -28,6 +28,7 @@
26940  #include <linux/prctl.h>
26941  #include <linux/securebits.h>
26942  #include <linux/syslog.h>
26943 +#include <linux/vs_context.h>
26944  
26945  /*
26946   * If a non-root user executes a setuid-root binary in
26947 @@ -53,7 +54,7 @@ static void warn_setuid_and_fcaps_mixed(
26948  
26949  int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
26950  {
26951 -       NETLINK_CB(skb).eff_cap = current_cap();
26952 +       NETLINK_CB(skb).eff_cap = vx_mbcaps(current_cap());
26953         return 0;
26954  }
26955  
26956 @@ -63,6 +64,7 @@ int cap_netlink_recv(struct sk_buff *skb
26957                 return -EPERM;
26958         return 0;
26959  }
26960 +
26961  EXPORT_SYMBOL(cap_netlink_recv);
26962  
26963  /**
26964 @@ -83,7 +85,22 @@ EXPORT_SYMBOL(cap_netlink_recv);
26965  int cap_capable(struct task_struct *tsk, const struct cred *cred, int cap,
26966                 int audit)
26967  {
26968 -       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
26969 +       struct vx_info *vxi = tsk->vx_info;
26970 +
26971 +#if 0
26972 +       printk("cap_capable() VXF_STATE_SETUP = %llx, raised = %x, eff = %08x:%08x\n",
26973 +               vx_info_flags(vxi, VXF_STATE_SETUP, 0),
26974 +               cap_raised(tsk->cap_effective, cap),
26975 +               tsk->cap_effective.cap[1], tsk->cap_effective.cap[0]);
26976 +#endif
26977 +
26978 +       /* special case SETUP */
26979 +       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
26980 +               /* FIXME: maybe use cred instead? */
26981 +               cap_raised(tsk->cred->cap_effective, cap))
26982 +               return 0;
26983 +
26984 +       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
26985  }
26986  
26987  /**
26988 @@ -571,7 +588,7 @@ int cap_inode_setxattr(struct dentry *de
26989  
26990         if (!strncmp(name, XATTR_SECURITY_PREFIX,
26991                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26992 -           !capable(CAP_SYS_ADMIN))
26993 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26994                 return -EPERM;
26995         return 0;
26996  }
26997 @@ -597,7 +614,7 @@ int cap_inode_removexattr(struct dentry 
26998  
26999         if (!strncmp(name, XATTR_SECURITY_PREFIX,
27000                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
27001 -           !capable(CAP_SYS_ADMIN))
27002 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
27003                 return -EPERM;
27004         return 0;
27005  }
27006 @@ -899,7 +916,8 @@ int cap_syslog(int type, bool from_file)
27007         if (type != SYSLOG_ACTION_OPEN && from_file)
27008                 return 0;
27009         if ((type != SYSLOG_ACTION_READ_ALL &&
27010 -            type != SYSLOG_ACTION_SIZE_BUFFER) && !capable(CAP_SYS_ADMIN))
27011 +            type != SYSLOG_ACTION_SIZE_BUFFER) &&
27012 +               !vx_capable(CAP_SYS_ADMIN, VXC_SYSLOG))
27013                 return -EPERM;
27014         return 0;
27015  }
27016 @@ -951,3 +969,4 @@ int cap_file_mmap(struct file *file, uns
27017         }
27018         return ret;
27019  }
27020 +
27021 diff -NurpP --minimal linux-2.6.36/security/selinux/hooks.c linux-2.6.36-vs2.3.0.36.33/security/selinux/hooks.c
27022 --- linux-2.6.36/security/selinux/hooks.c       2010-10-21 13:08:02.000000000 +0200
27023 +++ linux-2.6.36-vs2.3.0.36.33/security/selinux/hooks.c 2010-10-21 13:09:36.000000000 +0200
27024 @@ -64,7 +64,6 @@
27025  #include <linux/dccp.h>
27026  #include <linux/quota.h>
27027  #include <linux/un.h>          /* for Unix socket types */
27028 -#include <net/af_unix.h>       /* for Unix socket types */
27029  #include <linux/parser.h>
27030  #include <linux/nfs_mount.h>
27031  #include <net/ipv6.h>
27032 diff -NurpP --minimal linux-2.6.36-vs2.3.0.36.33/fs/namei.c linux-2.6.36-vs2.3.0.36.34/fs/namei.c
27033 --- linux-2.6.36-vs2.3.0.36.33/fs/namei.c       2010-10-21 14:45:53.000000000 +0200
27034 +++ linux-2.6.36-vs2.3.0.36.34/fs/namei.c       2010-10-21 17:45:49.000000000 +0200
27035 @@ -848,7 +848,8 @@ done:
27036         return 0;
27037  
27038  hidden:
27039 -       vxwprintk_task(1, "did lookup hidden %s:%p[#%d,%lu] »%s/%.*s«.",
27040 +       vxwprintk_task(1,
27041 +               "did lookup hidden %s:%p[#%d,%lu] " VS_Q("%s/%.*s") ".",
27042                 inode->i_sb->s_id, inode, inode->i_tag, inode->i_ino,
27043                 vxd_path(&nd->path), name->len, name->name);
27044         dput(dentry);
27045 @@ -2968,7 +2969,8 @@ struct dentry *cow_break_link(const char
27046         char *to, *path, pad='\251';
27047         loff_t size;
27048  
27049 -       vxdprintk(VXD_CBIT(misc, 1), "cow_break_link(»%s«)", pathname);
27050 +       vxdprintk(VXD_CBIT(misc, 1),
27051 +               "cow_break_link(" VS_Q("%s") ")", pathname);
27052         path = kmalloc(PATH_MAX, GFP_KERNEL);
27053         ret = -ENOMEM;
27054         if (!path)
27055 @@ -2985,7 +2987,8 @@ struct dentry *cow_break_link(const char
27056  
27057         to = d_path(&old_path, path, PATH_MAX-2);
27058         pathlen = strlen(to);
27059 -       vxdprintk(VXD_CBIT(misc, 2), "old path »%s« [»%.*s«:%d]", to,
27060 +       vxdprintk(VXD_CBIT(misc, 2),
27061 +               "old path " VS_Q("%s") " [" VS_Q("%.*s") ":%d]", to,
27062                 old_path.dentry->d_name.len, old_path.dentry->d_name.name,
27063                 old_path.dentry->d_name.len);
27064  
27065 @@ -2996,7 +2999,7 @@ retry:
27066         if (pad <= '\240')
27067                 goto out_rel_old;
27068  
27069 -       vxdprintk(VXD_CBIT(misc, 1), "temp copy »%s«", to);
27070 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
27071         /* dir_nd will have refs to dentry and mnt */
27072         ret = path_lookup(to,
27073                 LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
27074 @@ -3015,7 +3018,8 @@ retry:
27075                 goto retry;
27076         }
27077         vxdprintk(VXD_CBIT(misc, 2),
27078 -               "lookup_create(new): %p [»%.*s«:%d]", new_path.dentry,
27079 +               "lookup_create(new): %p [" VS_Q("%.*s") ":%d]",
27080 +               new_path.dentry,
27081                 new_path.dentry->d_name.len, new_path.dentry->d_name.name,
27082                 new_path.dentry->d_name.len);
27083         dir = dir_nd.path.dentry;
27084 @@ -3091,7 +3095,7 @@ retry:
27085                 goto out_unlock;
27086  
27087         vxdprintk(VXD_CBIT(misc, 2),
27088 -               "vfs_rename: [»%*s«:%d] -> [»%*s«:%d]",
27089 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
27090                 new_path.dentry->d_name.len, new_path.dentry->d_name.name,
27091                 new_path.dentry->d_name.len,
27092                 old_path.dentry->d_name.len, old_path.dentry->d_name.name,
27093 @@ -3136,7 +3140,8 @@ out_redo:
27094  
27095         new_path.dentry = old_nd.path.dentry;
27096         vxdprintk(VXD_CBIT(misc, 2),
27097 -               "path_lookup(redo): %p [»%.*s«:%d]", new_path.dentry,
27098 +               "path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
27099 +               new_path.dentry,
27100                 new_path.dentry->d_name.len, new_path.dentry->d_name.name,
27101                 new_path.dentry->d_name.len);
27102         dget(new_path.dentry);
27103 diff -NurpP --minimal linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/debug.h linux-2.6.36-vs2.3.0.36.34/include/linux/vserver/debug.h
27104 --- linux-2.6.36-vs2.3.0.36.33/include/linux/vserver/debug.h    2010-10-21 13:09:36.000000000 +0200
27105 +++ linux-2.6.36-vs2.3.0.36.34/include/linux/vserver/debug.h    2010-10-21 18:35:25.000000000 +0200
27106 @@ -10,6 +10,19 @@
27107                         imajor((d)->bd_inode), iminor((d)->bd_inode)
27108  #define VXF_DEV                "%p[%lu,%d:%d]"
27109  
27110 +#if    defined(CONFIG_QUOTES_UTF8)
27111 +#define        VS_Q_LQM        "\xc2\xbb"
27112 +#define        VS_Q_RQM        "\xc2\xab"
27113 +#elif  defined(CONFIG_QUOTES_ASCII)
27114 +#define        VS_Q_LQM        "\x27"
27115 +#define        VS_Q_RQM        "\x27"
27116 +#else
27117 +#define        VS_Q_LQM        "\xbb"
27118 +#define        VS_Q_RQM        "\xab"
27119 +#endif
27120 +
27121 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
27122 +
27123  
27124  #define vxd_path(p)                                            \
27125         ({ static char _buffer[PATH_MAX];                       \
27126 @@ -86,7 +99,7 @@ void dump_vx_info_inactive(int);
27127  #ifdef CONFIG_VSERVER_WARN
27128  
27129  #define VX_WARNLEVEL   KERN_WARNING "vxW: "
27130 -#define VX_WARN_TASK   "[»%s«,%u:#%u|%u|%u] "
27131 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
27132  #define VX_WARN_XID    "[xid #%u] "
27133  #define VX_WARN_NID    "[nid #%u] "
27134  #define VX_WARN_TAG    "[tag #%u] "
27135 diff -NurpP --minimal linux-2.6.36-vs2.3.0.36.33/include/linux/vs_inet.h linux-2.6.36-vs2.3.0.36.34/include/linux/vs_inet.h
27136 --- linux-2.6.36-vs2.3.0.36.33/include/linux/vs_inet.h  2010-10-21 14:48:51.000000000 +0200
27137 +++ linux-2.6.36-vs2.3.0.36.34/include/linux/vs_inet.h  2010-10-21 17:41:35.000000000 +0200
27138 @@ -188,7 +188,8 @@ int __v4_addr_match_socket(const struct 
27139  static inline
27140  int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
27141  {
27142 -       vxdprintk(VXD_CBIT(net, 1), "nx_dev_visible(%p[#%u],%p »%s«) %d",
27143 +       vxdprintk(VXD_CBIT(net, 1),
27144 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
27145                 nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
27146                 nxi ? dev_in_nx_info(dev, nxi) : 0);
27147  
27148 diff -NurpP --minimal linux-2.6.36-vs2.3.0.36.33/kernel/vserver/inode.c linux-2.6.36-vs2.3.0.36.34/kernel/vserver/inode.c
27149 --- linux-2.6.36-vs2.3.0.36.33/kernel/vserver/inode.c   2010-10-21 14:46:31.000000000 +0200
27150 +++ linux-2.6.36-vs2.3.0.36.34/kernel/vserver/inode.c   2010-10-21 17:40:44.000000000 +0200
27151 @@ -358,7 +358,7 @@ int dx_parse_tag(char *string, tag_t *ta
27152                 token = match_token(p, tokens, args);
27153  
27154                 vxdprintk(VXD_CBIT(tag, 7),
27155 -                       "dx_parse_tag(»%s«): %d:#%d",
27156 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
27157                         p, token, option);
27158  
27159                 switch (token) {
27160 diff -NurpP --minimal linux-2.6.36-vs2.3.0.36.33/kernel/vserver/Kconfig linux-2.6.36-vs2.3.0.36.34/kernel/vserver/Kconfig
27161 --- linux-2.6.36-vs2.3.0.36.33/kernel/vserver/Kconfig   2010-10-21 13:09:36.000000000 +0200
27162 +++ linux-2.6.36-vs2.3.0.36.34/kernel/vserver/Kconfig   2010-10-21 18:34:45.000000000 +0200
27163 @@ -239,6 +239,29 @@ config     VSERVER_LEGACY_MEM
27164           older tools happy in the face of memory
27165           cgroups
27166  
27167 +choice
27168 +       prompt  "Quotes used in debug and warn messages"
27169 +       default QUOTES_ISO8859
27170 +
27171 +config QUOTES_ISO8859
27172 +       bool    "Extended ASCII (ISO 8859) angle quotes"
27173 +       help
27174 +         This uses the extended ASCII characters \xbb
27175 +         and \xab for quoting file and process names.
27176 +         
27177 +config QUOTES_UTF8
27178 +       bool    "UTF-8 angle quotes"
27179 +       help
27180 +         This uses the the UTF-8 sequences for angle 
27181 +         quotes to quote file and process names.
27182 +
27183 +config QUOTES_ASCII
27184 +       bool    "ASCII single quotes"
27185 +       help
27186 +         This uses the ASCII single quote character
27187 +         (\x27) to quote file and process names.
27188 +
27189 +endchoice
27190  
27191  endmenu
27192  
27193 diff -NurpP --minimal linux-2.6.36-vs2.3.0.36.34/kernel/vserver/Kconfig linux-2.6.36-vs2.3.0.36.35/kernel/vserver/Kconfig
27194 --- linux-2.6.36-vs2.3.0.36.34/kernel/vserver/Kconfig   2010-10-21 18:34:45.000000000 +0200
27195 +++ linux-2.6.36-vs2.3.0.36.35/kernel/vserver/Kconfig   2010-10-21 19:04:20.000000000 +0200
27196 @@ -204,33 +204,6 @@ config     VSERVER_HISTORY_SIZE
27197           This allows you to specify the number of entries in
27198           the per-CPU history buffer.
27199  
27200 -config VSERVER_MONITOR
27201 -       bool    "VServer Scheduling Monitor"
27202 -       depends on VSERVER_DISABLED
27203 -       default n
27204 -       help
27205 -         Set this to yes if you want to record the scheduling
27206 -         decisions, so that they can be relayed to userspace
27207 -         for detailed analysis.
27208 -
27209 -config VSERVER_MONITOR_SIZE
27210 -       int     "Per-CPU Monitor Queue Size (32-65536)"
27211 -       depends on VSERVER_MONITOR
27212 -       range 32 65536
27213 -       default 1024
27214 -       help
27215 -         This allows you to specify the number of entries in
27216 -         the per-CPU scheduling monitor buffer.
27217 -
27218 -config VSERVER_MONITOR_SYNC
27219 -       int     "Per-CPU Monitor Sync Interval (0-65536)"
27220 -       depends on VSERVER_MONITOR
27221 -       range 0 65536
27222 -       default 256
27223 -       help
27224 -         This allows you to specify the interval in ticks
27225 -         when a time sync entry is inserted.
27226 -
27227  config VSERVER_LEGACY_MEM
27228         bool    "Legacy Memory Limits"
27229         default n
27230 diff -NurpP --minimal linux-2.6.36-vs2.3.0.36.34/kernel/vserver/monitor.c linux-2.6.36-vs2.3.0.36.35/kernel/vserver/monitor.c
27231 --- linux-2.6.36-vs2.3.0.36.34/kernel/vserver/monitor.c 2010-10-21 13:09:36.000000000 +0200
27232 +++ linux-2.6.36-vs2.3.0.36.35/kernel/vserver/monitor.c 1970-01-01 01:00:00.000000000 +0100
27233 @@ -1,138 +0,0 @@
27234 -/*
27235 - *  kernel/vserver/monitor.c
27236 - *
27237 - *  Virtual Context Scheduler Monitor
27238 - *
27239 - *  Copyright (C) 2006-2007 Herbert Pötzl
27240 - *
27241 - *  V0.01  basic design
27242 - *
27243 - */
27244 -
27245 -#include <linux/module.h>
27246 -#include <linux/jiffies.h>
27247 -#include <asm/uaccess.h>
27248 -#include <asm/atomic.h>
27249 -
27250 -#include <linux/vserver/monitor.h>
27251 -#include <linux/vserver/debug_cmd.h>
27252 -
27253 -
27254 -#ifdef CONFIG_VSERVER_MONITOR
27255 -#define VXM_SIZE       CONFIG_VSERVER_MONITOR_SIZE
27256 -#else
27257 -#define VXM_SIZE       64
27258 -#endif
27259 -
27260 -struct _vx_monitor {
27261 -       unsigned int counter;
27262 -
27263 -       struct _vx_mon_entry entry[VXM_SIZE+1];
27264 -};
27265 -
27266 -
27267 -DEFINE_PER_CPU(struct _vx_monitor, vx_monitor_buffer);
27268 -
27269 -unsigned volatile int vxm_active = 1;
27270 -
27271 -static atomic_t sequence = ATOMIC_INIT(0);
27272 -
27273 -
27274 -/*     vxm_advance()
27275 -
27276 -       * requires disabled preemption                          */
27277 -
27278 -struct _vx_mon_entry *vxm_advance(int cpu)
27279 -{
27280 -       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
27281 -       struct _vx_mon_entry *entry;
27282 -       unsigned int index;
27283 -
27284 -       index = vxm_active ? (mon->counter++ % VXM_SIZE) : VXM_SIZE;
27285 -       entry = &mon->entry[index];
27286 -
27287 -       entry->ev.seq = atomic_inc_return(&sequence);
27288 -       entry->ev.jif = jiffies;
27289 -       return entry;
27290 -}
27291 -
27292 -EXPORT_SYMBOL_GPL(vxm_advance);
27293 -
27294 -
27295 -int do_read_monitor(struct __user _vx_mon_entry *data,
27296 -       int cpu, uint32_t *index, uint32_t *count)
27297 -{
27298 -       int pos, ret = 0;
27299 -       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
27300 -       int end = mon->counter;
27301 -       int start = end - VXM_SIZE + 2;
27302 -       int idx = *index;
27303 -
27304 -       /* special case: get current pos */
27305 -       if (!*count) {
27306 -               *index = end;
27307 -               return 0;
27308 -       }
27309 -
27310 -       /* have we lost some data? */
27311 -       if (idx < start)
27312 -               idx = start;
27313 -
27314 -       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
27315 -               struct _vx_mon_entry *entry =
27316 -                       &mon->entry[idx % VXM_SIZE];
27317 -
27318 -               /* send entry to userspace */
27319 -               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
27320 -               if (ret)
27321 -                       break;
27322 -       }
27323 -       /* save new index and count */
27324 -       *index = idx;
27325 -       *count = pos;
27326 -       return ret ? ret : (*index < end);
27327 -}
27328 -
27329 -int vc_read_monitor(uint32_t id, void __user *data)
27330 -{
27331 -       struct vcmd_read_monitor_v0 vc_data;
27332 -       int ret;
27333 -
27334 -       if (id >= NR_CPUS)
27335 -               return -EINVAL;
27336 -
27337 -       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
27338 -               return -EFAULT;
27339 -
27340 -       ret = do_read_monitor((struct __user _vx_mon_entry *)vc_data.data,
27341 -               id, &vc_data.index, &vc_data.count);
27342 -
27343 -       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
27344 -               return -EFAULT;
27345 -       return ret;
27346 -}
27347 -
27348 -#ifdef CONFIG_COMPAT
27349 -
27350 -int vc_read_monitor_x32(uint32_t id, void __user *data)
27351 -{
27352 -       struct vcmd_read_monitor_v0_x32 vc_data;
27353 -       int ret;
27354 -
27355 -       if (id >= NR_CPUS)
27356 -               return -EINVAL;
27357 -
27358 -       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
27359 -               return -EFAULT;
27360 -
27361 -       ret = do_read_monitor((struct __user _vx_mon_entry *)
27362 -               compat_ptr(vc_data.data_ptr),
27363 -               id, &vc_data.index, &vc_data.count);
27364 -
27365 -       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
27366 -               return -EFAULT;
27367 -       return ret;
27368 -}
27369 -
27370 -#endif /* CONFIG_COMPAT */
27371 -
27372 diff -NurpP --minimal linux-2.6.36-vs2.3.0.36.34/kernel/vserver/switch.c linux-2.6.36-vs2.3.0.36.35/kernel/vserver/switch.c
27373 --- linux-2.6.36-vs2.3.0.36.34/kernel/vserver/switch.c  2010-10-21 13:09:36.000000000 +0200
27374 +++ linux-2.6.36-vs2.3.0.36.35/kernel/vserver/switch.c  2010-10-21 19:05:54.000000000 +0200
27375 @@ -272,10 +272,6 @@ long do_vcmd(uint32_t cmd, uint32_t id,
27376         case VCMD_read_history:
27377                 return __COMPAT(vc_read_history, id, data, compat);
27378  #endif
27379 -#ifdef CONFIG_VSERVER_MONITOR
27380 -       case VCMD_read_monitor:
27381 -               return __COMPAT(vc_read_monitor, id, data, compat);
27382 -#endif
27383         default:
27384                 vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
27385                         VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
27386 @@ -406,9 +402,6 @@ long do_vserver(uint32_t cmd, uint32_t i
27387         __VCMD(dump_history,     9, VCA_NONE,   0);
27388         __VCMD(read_history,     9, VCA_NONE,   0);
27389  #endif
27390 -#ifdef CONFIG_VSERVER_MONITOR
27391 -       __VCMD(read_monitor,     9, VCA_NONE,   0);
27392 -#endif
27393  
27394         default:
27395                 perm = -1;
This page took 2.179629 seconds and 4 git commands to generate.