]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
ea3178f3225a0ef81d1464ffeb3c8b1050549015
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-2.6.29.4/arch/alpha/Kconfig linux-2.6.29.4-vs2.3.0.36.14/arch/alpha/Kconfig
2 --- linux-2.6.29.4/arch/alpha/Kconfig   2009-03-24 14:18:07.000000000 +0100
3 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/alpha/Kconfig     2009-03-24 14:48:16.000000000 +0100
4 @@ -666,6 +666,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.29.4/arch/alpha/kernel/entry.S linux-2.6.29.4-vs2.3.0.36.14/arch/alpha/kernel/entry.S
14 --- linux-2.6.29.4/arch/alpha/kernel/entry.S    2009-03-24 14:18:07.000000000 +0100
15 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/alpha/kernel/entry.S      2009-03-24 14:48:16.000000000 +0100
16 @@ -874,24 +874,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.29.4/arch/alpha/kernel/osf_sys.c linux-2.6.29.4-vs2.3.0.36.14/arch/alpha/kernel/osf_sys.c
49 --- linux-2.6.29.4/arch/alpha/kernel/osf_sys.c  2009-03-24 14:18:07.000000000 +0100
50 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/alpha/kernel/osf_sys.c    2009-03-24 14:48:16.000000000 +0100
51 @@ -877,7 +877,7 @@ SYSCALL_DEFINE2(osf_gettimeofday, struct
52  {
53         if (tv) {
54                 struct timeval ktv;
55 -               do_gettimeofday(&ktv);
56 +               vx_gettimeofday(&ktv);
57                 if (put_tv32(tv, &ktv))
58                         return -EFAULT;
59         }
60 diff -NurpP --minimal linux-2.6.29.4/arch/alpha/kernel/ptrace.c linux-2.6.29.4-vs2.3.0.36.14/arch/alpha/kernel/ptrace.c
61 --- linux-2.6.29.4/arch/alpha/kernel/ptrace.c   2008-12-25 00:26:37.000000000 +0100
62 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/alpha/kernel/ptrace.c     2009-02-22 22:54:24.000000000 +0100
63 @@ -15,6 +15,7 @@
64  #include <linux/slab.h>
65  #include <linux/security.h>
66  #include <linux/signal.h>
67 +#include <linux/vs_base.h>
68  
69  #include <asm/uaccess.h>
70  #include <asm/pgtable.h>
71 diff -NurpP --minimal linux-2.6.29.4/arch/alpha/kernel/systbls.S linux-2.6.29.4-vs2.3.0.36.14/arch/alpha/kernel/systbls.S
72 --- linux-2.6.29.4/arch/alpha/kernel/systbls.S  2009-03-24 14:18:08.000000000 +0100
73 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/alpha/kernel/systbls.S    2009-03-24 14:48:16.000000000 +0100
74 @@ -446,7 +446,7 @@ sys_call_table:
75         .quad sys_stat64                        /* 425 */
76         .quad sys_lstat64
77         .quad sys_fstat64
78 -       .quad sys_ni_syscall                    /* sys_vserver */
79 +       .quad sys_vserver                       /* sys_vserver */
80         .quad sys_ni_syscall                    /* sys_mbind */
81         .quad sys_ni_syscall                    /* sys_get_mempolicy */
82         .quad sys_ni_syscall                    /* sys_set_mempolicy */
83 diff -NurpP --minimal linux-2.6.29.4/arch/alpha/kernel/traps.c linux-2.6.29.4-vs2.3.0.36.14/arch/alpha/kernel/traps.c
84 --- linux-2.6.29.4/arch/alpha/kernel/traps.c    2008-12-25 00:26:37.000000000 +0100
85 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/alpha/kernel/traps.c      2009-02-22 22:54:24.000000000 +0100
86 @@ -183,7 +183,8 @@ die_if_kernel(char * str, struct pt_regs
87  #ifdef CONFIG_SMP
88         printk("CPU %d ", hard_smp_processor_id());
89  #endif
90 -       printk("%s(%d): %s %ld\n", current->comm, task_pid_nr(current), str, err);
91 +       printk("%s(%d[#%u]): %s %ld\n", current->comm,
92 +               task_pid_nr(current), current->xid, str, err);
93         dik_show_regs(regs, r9_15);
94         add_taint(TAINT_DIE);
95         dik_show_trace((unsigned long *)(regs+1));
96 diff -NurpP --minimal linux-2.6.29.4/arch/alpha/mm/fault.c linux-2.6.29.4-vs2.3.0.36.14/arch/alpha/mm/fault.c
97 --- linux-2.6.29.4/arch/alpha/mm/fault.c        2008-12-25 00:26:37.000000000 +0100
98 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/alpha/mm/fault.c  2009-02-22 22:54:24.000000000 +0100
99 @@ -193,8 +193,8 @@ do_page_fault(unsigned long address, uns
100                 down_read(&mm->mmap_sem);
101                 goto survive;
102         }
103 -       printk(KERN_ALERT "VM: killing process %s(%d)\n",
104 -              current->comm, task_pid_nr(current));
105 +       printk(KERN_ALERT "VM: killing process %s(%d:#%u)\n",
106 +              current->comm, task_pid_nr(current), current->xid);
107         if (!user_mode(regs))
108                 goto no_context;
109         do_group_exit(SIGKILL);
110 diff -NurpP --minimal linux-2.6.29.4/arch/arm/Kconfig linux-2.6.29.4-vs2.3.0.36.14/arch/arm/Kconfig
111 --- linux-2.6.29.4/arch/arm/Kconfig     2009-03-24 14:18:08.000000000 +0100
112 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/arm/Kconfig       2009-03-24 14:48:16.000000000 +0100
113 @@ -1333,6 +1333,8 @@ source "fs/Kconfig"
114  
115  source "arch/arm/Kconfig.debug"
116  
117 +source "kernel/vserver/Kconfig"
118 +
119  source "security/Kconfig"
120  
121  source "crypto/Kconfig"
122 diff -NurpP --minimal linux-2.6.29.4/arch/arm/kernel/calls.S linux-2.6.29.4-vs2.3.0.36.14/arch/arm/kernel/calls.S
123 --- linux-2.6.29.4/arch/arm/kernel/calls.S      2009-03-24 14:18:09.000000000 +0100
124 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/arm/kernel/calls.S        2009-02-22 22:54:24.000000000 +0100
125 @@ -322,7 +322,7 @@
126  /* 310 */      CALL(sys_request_key)
127                 CALL(sys_keyctl)
128                 CALL(ABI(sys_semtimedop, sys_oabi_semtimedop))
129 -/* vserver */  CALL(sys_ni_syscall)
130 +               CALL(sys_vserver)
131                 CALL(sys_ioprio_set)
132  /* 315 */      CALL(sys_ioprio_get)
133                 CALL(sys_inotify_init)
134 diff -NurpP --minimal linux-2.6.29.4/arch/arm/kernel/process.c linux-2.6.29.4-vs2.3.0.36.14/arch/arm/kernel/process.c
135 --- linux-2.6.29.4/arch/arm/kernel/process.c    2008-12-25 00:26:37.000000000 +0100
136 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/arm/kernel/process.c      2009-02-22 22:54:24.000000000 +0100
137 @@ -262,7 +262,8 @@ void __show_regs(struct pt_regs *regs)
138  void show_regs(struct pt_regs * regs)
139  {
140         printk("\n");
141 -       printk("Pid: %d, comm: %20s\n", task_pid_nr(current), current->comm);
142 +       printk("Pid: %d[#%u], comm: %20s\n",
143 +               task_pid_nr(current), current->xid, current->comm);
144         __show_regs(regs);
145         __backtrace();
146  }
147 diff -NurpP --minimal linux-2.6.29.4/arch/arm/kernel/traps.c linux-2.6.29.4-vs2.3.0.36.14/arch/arm/kernel/traps.c
148 --- linux-2.6.29.4/arch/arm/kernel/traps.c      2008-12-25 00:26:37.000000000 +0100
149 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/arm/kernel/traps.c        2009-02-22 22:54:24.000000000 +0100
150 @@ -214,8 +214,8 @@ static void __die(const char *str, int e
151                str, err, ++die_counter);
152         print_modules();
153         __show_regs(regs);
154 -       printk("Process %s (pid: %d, stack limit = 0x%p)\n",
155 -               tsk->comm, task_pid_nr(tsk), thread + 1);
156 +       printk("Process %s (pid: %d:#%u, stack limit = 0x%p)\n",
157 +               tsk->comm, task_pid_nr(tsk), tsk->xid, thread + 1);
158  
159         if (!user_mode(regs) || in_interrupt()) {
160                 dump_mem("Stack: ", regs->ARM_sp,
161 diff -NurpP --minimal linux-2.6.29.4/arch/arm/mm/fault.c linux-2.6.29.4-vs2.3.0.36.14/arch/arm/mm/fault.c
162 --- linux-2.6.29.4/arch/arm/mm/fault.c  2009-03-24 14:18:17.000000000 +0100
163 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/arm/mm/fault.c    2009-03-24 14:48:17.000000000 +0100
164 @@ -294,7 +294,8 @@ do_page_fault(unsigned long addr, unsign
165                  * happened to us that made us unable to handle
166                  * the page fault gracefully.
167                  */
168 -               printk("VM: killing process %s\n", tsk->comm);
169 +               printk("VM: killing process %s(%d:#%u)\n",
170 +                       tsk->comm, task_pid_nr(tsk), tsk->xid);
171                 do_group_exit(SIGKILL);
172                 return 0;
173         }
174 diff -NurpP --minimal linux-2.6.29.4/arch/cris/Kconfig linux-2.6.29.4-vs2.3.0.36.14/arch/cris/Kconfig
175 --- linux-2.6.29.4/arch/cris/Kconfig    2009-03-24 14:18:23.000000000 +0100
176 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/cris/Kconfig      2009-03-24 14:48:19.000000000 +0100
177 @@ -685,6 +685,8 @@ source "drivers/staging/Kconfig"
178  
179  source "arch/cris/Kconfig.debug"
180  
181 +source "kernel/vserver/Kconfig"
182 +
183  source "security/Kconfig"
184  
185  source "crypto/Kconfig"
186 diff -NurpP --minimal linux-2.6.29.4/arch/frv/kernel/kernel_thread.S linux-2.6.29.4-vs2.3.0.36.14/arch/frv/kernel/kernel_thread.S
187 --- linux-2.6.29.4/arch/frv/kernel/kernel_thread.S      2008-12-25 00:26:37.000000000 +0100
188 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/frv/kernel/kernel_thread.S        2009-02-22 22:54:24.000000000 +0100
189 @@ -37,7 +37,7 @@ kernel_thread:
190  
191         # start by forking the current process, but with shared VM
192         setlos.p        #__NR_clone,gr7         ; syscall number
193 -       ori             gr10,#CLONE_VM,gr8      ; first syscall arg     [clone_flags]
194 +       ori             gr10,#CLONE_KT,gr8      ; first syscall arg     [clone_flags]
195         sethi.p         #0xe4e4,gr9             ; second syscall arg    [newsp]
196         setlo           #0xe4e4,gr9
197         setlos.p        #0,gr10                 ; third syscall arg     [parent_tidptr]
198 diff -NurpP --minimal linux-2.6.29.4/arch/h8300/Kconfig linux-2.6.29.4-vs2.3.0.36.14/arch/h8300/Kconfig
199 --- linux-2.6.29.4/arch/h8300/Kconfig   2009-03-24 14:18:24.000000000 +0100
200 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/h8300/Kconfig     2009-03-24 14:48:19.000000000 +0100
201 @@ -226,6 +226,8 @@ source "fs/Kconfig"
202  
203  source "arch/h8300/Kconfig.debug"
204  
205 +source "kernel/vserver/Kconfig"
206 +
207  source "security/Kconfig"
208  
209  source "crypto/Kconfig"
210 diff -NurpP --minimal linux-2.6.29.4/arch/ia64/ia32/ia32_entry.S linux-2.6.29.4-vs2.3.0.36.14/arch/ia64/ia32/ia32_entry.S
211 --- linux-2.6.29.4/arch/ia64/ia32/ia32_entry.S  2009-03-24 14:18:24.000000000 +0100
212 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/ia64/ia32/ia32_entry.S    2009-02-22 22:54:24.000000000 +0100
213 @@ -451,7 +451,7 @@ ia32_syscall_table:
214         data8 sys_tgkill        /* 270 */
215         data8 compat_sys_utimes
216         data8 sys32_fadvise64_64
217 -       data8 sys_ni_syscall
218 +       data8 sys32_vserver
219         data8 sys_ni_syscall
220         data8 sys_ni_syscall    /* 275 */
221         data8 sys_ni_syscall
222 diff -NurpP --minimal linux-2.6.29.4/arch/ia64/Kconfig linux-2.6.29.4-vs2.3.0.36.14/arch/ia64/Kconfig
223 --- linux-2.6.29.4/arch/ia64/Kconfig    2009-03-24 14:18:24.000000000 +0100
224 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/ia64/Kconfig      2009-03-24 14:48:19.000000000 +0100
225 @@ -672,6 +672,8 @@ source "fs/Kconfig"
226  
227  source "arch/ia64/Kconfig.debug"
228  
229 +source "kernel/vserver/Kconfig"
230 +
231  source "security/Kconfig"
232  
233  source "crypto/Kconfig"
234 diff -NurpP --minimal linux-2.6.29.4/arch/ia64/kernel/entry.S linux-2.6.29.4-vs2.3.0.36.14/arch/ia64/kernel/entry.S
235 --- linux-2.6.29.4/arch/ia64/kernel/entry.S     2009-03-24 14:18:25.000000000 +0100
236 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/ia64/kernel/entry.S       2009-02-22 22:54:24.000000000 +0100
237 @@ -1653,7 +1653,7 @@ sys_call_table:
238         data8 sys_mq_notify
239         data8 sys_mq_getsetattr
240         data8 sys_kexec_load
241 -       data8 sys_ni_syscall                    // reserved for vserver
242 +       data8 sys_vserver
243         data8 sys_waitid                        // 1270
244         data8 sys_add_key
245         data8 sys_request_key
246 diff -NurpP --minimal linux-2.6.29.4/arch/ia64/kernel/perfmon.c linux-2.6.29.4-vs2.3.0.36.14/arch/ia64/kernel/perfmon.c
247 --- linux-2.6.29.4/arch/ia64/kernel/perfmon.c   2009-03-24 14:18:25.000000000 +0100
248 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/ia64/kernel/perfmon.c     2009-03-24 14:48:19.000000000 +0100
249 @@ -41,6 +41,7 @@
250  #include <linux/rcupdate.h>
251  #include <linux/completion.h>
252  #include <linux/tracehook.h>
253 +#include <linux/vs_memory.h>
254  
255  #include <asm/errno.h>
256  #include <asm/intrinsics.h>
257 @@ -2372,7 +2373,7 @@ pfm_smpl_buffer_alloc(struct task_struct
258          */
259         insert_vm_struct(mm, vma);
260  
261 -       mm->total_vm  += size >> PAGE_SHIFT;
262 +       vx_vmpages_add(mm, size >> PAGE_SHIFT);
263         vm_stat_account(vma->vm_mm, vma->vm_flags, vma->vm_file,
264                                                         vma_pages(vma));
265         up_write(&task->mm->mmap_sem);
266 diff -NurpP --minimal linux-2.6.29.4/arch/ia64/kernel/process.c linux-2.6.29.4-vs2.3.0.36.14/arch/ia64/kernel/process.c
267 --- linux-2.6.29.4/arch/ia64/kernel/process.c   2008-12-25 00:26:37.000000000 +0100
268 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/ia64/kernel/process.c     2009-02-22 22:54:24.000000000 +0100
269 @@ -110,8 +110,8 @@ show_regs (struct pt_regs *regs)
270         unsigned long ip = regs->cr_iip + ia64_psr(regs)->ri;
271  
272         print_modules();
273 -       printk("\nPid: %d, CPU %d, comm: %20s\n", task_pid_nr(current),
274 -                       smp_processor_id(), current->comm);
275 +       printk("\nPid: %d[#%u], CPU %d, comm: %20s\n", task_pid_nr(current),
276 +                       current->xid, smp_processor_id(), current->comm);
277         printk("psr : %016lx ifs : %016lx ip  : [<%016lx>]    %s (%s)\n",
278                regs->cr_ipsr, regs->cr_ifs, ip, print_tainted(),
279                init_utsname()->release);
280 diff -NurpP --minimal linux-2.6.29.4/arch/ia64/kernel/ptrace.c linux-2.6.29.4-vs2.3.0.36.14/arch/ia64/kernel/ptrace.c
281 --- linux-2.6.29.4/arch/ia64/kernel/ptrace.c    2008-12-25 00:26:37.000000000 +0100
282 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/ia64/kernel/ptrace.c      2009-02-22 22:54:24.000000000 +0100
283 @@ -23,6 +23,7 @@
284  #include <linux/regset.h>
285  #include <linux/elf.h>
286  #include <linux/tracehook.h>
287 +#include <linux/vs_base.h>
288  
289  #include <asm/pgtable.h>
290  #include <asm/processor.h>
291 diff -NurpP --minimal linux-2.6.29.4/arch/ia64/kernel/traps.c linux-2.6.29.4-vs2.3.0.36.14/arch/ia64/kernel/traps.c
292 --- linux-2.6.29.4/arch/ia64/kernel/traps.c     2008-12-25 00:26:37.000000000 +0100
293 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/ia64/kernel/traps.c       2009-02-22 22:54:24.000000000 +0100
294 @@ -60,8 +60,9 @@ die (const char *str, struct pt_regs *re
295         put_cpu();
296  
297         if (++die.lock_owner_depth < 3) {
298 -               printk("%s[%d]: %s %ld [%d]\n",
299 -               current->comm, task_pid_nr(current), str, err, ++die_counter);
300 +               printk("%s[%d[#%u]]: %s %ld [%d]\n",
301 +                       current->comm, task_pid_nr(current), current->xid,
302 +                       str, err, ++die_counter);
303                 if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV)
304                     != NOTIFY_STOP)
305                         show_regs(regs);
306 @@ -324,8 +325,9 @@ handle_fpu_swa (int fp_fault, struct pt_
307                         if ((last.count & 15) < 5 && (ia64_fetchadd(1, &last.count, acq) & 15) < 5) {
308                                 last.time = current_jiffies + 5 * HZ;
309                                 printk(KERN_WARNING
310 -                                       "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
311 -                                       current->comm, task_pid_nr(current), regs->cr_iip + ia64_psr(regs)->ri, isr);
312 +                                       "%s(%d[#%u]): floating-point assist fault at ip %016lx, isr %016lx\n",
313 +                                       current->comm, task_pid_nr(current), current->xid,
314 +                                       regs->cr_iip + ia64_psr(regs)->ri, isr);
315                         }
316                 }
317         }
318 diff -NurpP --minimal linux-2.6.29.4/arch/ia64/mm/fault.c linux-2.6.29.4-vs2.3.0.36.14/arch/ia64/mm/fault.c
319 --- linux-2.6.29.4/arch/ia64/mm/fault.c 2008-12-25 00:26:37.000000000 +0100
320 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/ia64/mm/fault.c   2009-02-22 22:54:24.000000000 +0100
321 @@ -10,6 +10,7 @@
322  #include <linux/interrupt.h>
323  #include <linux/kprobes.h>
324  #include <linux/kdebug.h>
325 +#include <linux/vs_memory.h>
326  
327  #include <asm/pgtable.h>
328  #include <asm/processor.h>
329 diff -NurpP --minimal linux-2.6.29.4/arch/m32r/kernel/traps.c linux-2.6.29.4-vs2.3.0.36.14/arch/m32r/kernel/traps.c
330 --- linux-2.6.29.4/arch/m32r/kernel/traps.c     2008-12-25 00:26:37.000000000 +0100
331 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/m32r/kernel/traps.c       2009-02-22 22:54:24.000000000 +0100
332 @@ -196,8 +196,9 @@ static void show_registers(struct pt_reg
333         } else {
334                 printk("SPI: %08lx\n", sp);
335         }
336 -       printk("Process %s (pid: %d, process nr: %d, stackpage=%08lx)",
337 -               current->comm, task_pid_nr(current), 0xffff & i, 4096+(unsigned long)current);
338 +       printk("Process %s (pid: %d[#%u], process nr: %d, stackpage=%08lx)",
339 +               current->comm, task_pid_nr(current), current->xid,
340 +               0xffff & i, 4096+(unsigned long)current);
341  
342         /*
343          * When in-kernel, we also print out the stack and code at the
344 diff -NurpP --minimal linux-2.6.29.4/arch/m68k/Kconfig linux-2.6.29.4-vs2.3.0.36.14/arch/m68k/Kconfig
345 --- linux-2.6.29.4/arch/m68k/Kconfig    2009-03-24 14:18:26.000000000 +0100
346 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/m68k/Kconfig      2009-03-24 14:48:20.000000000 +0100
347 @@ -616,6 +616,8 @@ source "fs/Kconfig"
348  
349  source "arch/m68k/Kconfig.debug"
350  
351 +source "kernel/vserver/Kconfig"
352 +
353  source "security/Kconfig"
354  
355  source "crypto/Kconfig"
356 diff -NurpP --minimal linux-2.6.29.4/arch/m68k/kernel/ptrace.c linux-2.6.29.4-vs2.3.0.36.14/arch/m68k/kernel/ptrace.c
357 --- linux-2.6.29.4/arch/m68k/kernel/ptrace.c    2008-12-25 00:26:37.000000000 +0100
358 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/m68k/kernel/ptrace.c      2009-02-22 22:54:24.000000000 +0100
359 @@ -18,6 +18,7 @@
360  #include <linux/ptrace.h>
361  #include <linux/user.h>
362  #include <linux/signal.h>
363 +#include <linux/vs_base.h>
364  
365  #include <asm/uaccess.h>
366  #include <asm/page.h>
367 @@ -269,6 +270,8 @@ long arch_ptrace(struct task_struct *chi
368                 ret = ptrace_request(child, request, addr, data);
369                 break;
370         }
371 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
372 +               goto out_tsk;
373  
374         return ret;
375  out_eio:
376 diff -NurpP --minimal linux-2.6.29.4/arch/m68k/kernel/traps.c linux-2.6.29.4-vs2.3.0.36.14/arch/m68k/kernel/traps.c
377 --- linux-2.6.29.4/arch/m68k/kernel/traps.c     2009-03-24 14:18:26.000000000 +0100
378 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/m68k/kernel/traps.c       2009-03-24 14:48:20.000000000 +0100
379 @@ -906,8 +906,8 @@ void show_registers(struct pt_regs *regs
380         printk("d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
381                regs->d4, regs->d5, regs->a0, regs->a1);
382  
383 -       printk("Process %s (pid: %d, task=%p)\n",
384 -               current->comm, task_pid_nr(current), current);
385 +       printk("Process %s (pid: %d[#%u], task=%p)\n",
386 +               current->comm, task_pid_nr(current), current->xid, current);
387         addr = (unsigned long)&fp->un;
388         printk("Frame format=%X ", regs->format);
389         switch (regs->format) {
390 diff -NurpP --minimal linux-2.6.29.4/arch/m68knommu/Kconfig linux-2.6.29.4-vs2.3.0.36.14/arch/m68knommu/Kconfig
391 --- linux-2.6.29.4/arch/m68knommu/Kconfig       2009-03-24 14:18:27.000000000 +0100
392 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/m68knommu/Kconfig 2009-03-24 14:48:20.000000000 +0100
393 @@ -720,6 +720,8 @@ source "fs/Kconfig"
394  
395  source "arch/m68knommu/Kconfig.debug"
396  
397 +source "kernel/vserver/Kconfig"
398 +
399  source "security/Kconfig"
400  
401  source "crypto/Kconfig"
402 diff -NurpP --minimal linux-2.6.29.4/arch/m68knommu/kernel/traps.c linux-2.6.29.4-vs2.3.0.36.14/arch/m68knommu/kernel/traps.c
403 --- linux-2.6.29.4/arch/m68knommu/kernel/traps.c        2008-12-25 00:26:37.000000000 +0100
404 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/m68knommu/kernel/traps.c  2009-02-22 22:54:24.000000000 +0100
405 @@ -78,8 +78,9 @@ void die_if_kernel(char *str, struct pt_
406         printk(KERN_EMERG "d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
407                fp->d4, fp->d5, fp->a0, fp->a1);
408  
409 -       printk(KERN_EMERG "Process %s (pid: %d, stackpage=%08lx)\n",
410 -               current->comm, current->pid, PAGE_SIZE+(unsigned long)current);
411 +       printk(KERN_EMERG "Process %s (pid: %d[#%u], stackpage=%08lx)\n",
412 +               current->comm, task_pid_nr(current), current->xid,
413 +               PAGE_SIZE+(unsigned long)current);
414         show_stack(NULL, (unsigned long *)(fp + 1));
415         add_taint(TAINT_DIE);
416         do_exit(SIGSEGV);
417 diff -NurpP --minimal linux-2.6.29.4/arch/mips/Kconfig linux-2.6.29.4-vs2.3.0.36.14/arch/mips/Kconfig
418 --- linux-2.6.29.4/arch/mips/Kconfig    2009-03-24 14:18:29.000000000 +0100
419 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/mips/Kconfig      2009-03-24 14:48:21.000000000 +0100
420 @@ -2142,6 +2142,8 @@ source "fs/Kconfig"
421  
422  source "arch/mips/Kconfig.debug"
423  
424 +source "kernel/vserver/Kconfig"
425 +
426  source "security/Kconfig"
427  
428  source "crypto/Kconfig"
429 diff -NurpP --minimal linux-2.6.29.4/arch/mips/kernel/ptrace.c linux-2.6.29.4-vs2.3.0.36.14/arch/mips/kernel/ptrace.c
430 --- linux-2.6.29.4/arch/mips/kernel/ptrace.c    2008-12-25 00:26:37.000000000 +0100
431 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/mips/kernel/ptrace.c      2009-02-22 22:54:24.000000000 +0100
432 @@ -25,6 +25,7 @@
433  #include <linux/security.h>
434  #include <linux/audit.h>
435  #include <linux/seccomp.h>
436 +#include <linux/vs_base.h>
437  
438  #include <asm/byteorder.h>
439  #include <asm/cpu.h>
440 @@ -259,6 +260,9 @@ long arch_ptrace(struct task_struct *chi
441  {
442         int ret;
443  
444 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
445 +               goto out;
446 +
447         switch (request) {
448         /* when I and D space are separate, these will need to be fixed. */
449         case PTRACE_PEEKTEXT: /* read word at location addr. */
450 diff -NurpP --minimal linux-2.6.29.4/arch/mips/kernel/scall32-o32.S linux-2.6.29.4-vs2.3.0.36.14/arch/mips/kernel/scall32-o32.S
451 --- linux-2.6.29.4/arch/mips/kernel/scall32-o32.S       2009-03-24 14:18:31.000000000 +0100
452 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/mips/kernel/scall32-o32.S 2009-03-24 14:48:21.000000000 +0100
453 @@ -597,7 +597,7 @@ einval:     li      v0, -ENOSYS
454         sys     sys_mq_timedreceive     5
455         sys     sys_mq_notify           2       /* 4275 */
456         sys     sys_mq_getsetattr       3
457 -       sys     sys_ni_syscall          0       /* sys_vserver */
458 +       sys     sys_vserver             3
459         sys     sys_waitid              5
460         sys     sys_ni_syscall          0       /* available, was setaltroot */
461         sys     sys_add_key             5       /* 4280 */
462 diff -NurpP --minimal linux-2.6.29.4/arch/mips/kernel/scall64-64.S linux-2.6.29.4-vs2.3.0.36.14/arch/mips/kernel/scall64-64.S
463 --- linux-2.6.29.4/arch/mips/kernel/scall64-64.S        2009-03-24 14:18:31.000000000 +0100
464 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/mips/kernel/scall64-64.S  2009-03-24 14:48:21.000000000 +0100
465 @@ -434,7 +434,7 @@ sys_call_table:
466         PTR     sys_mq_timedreceive
467         PTR     sys_mq_notify
468         PTR     sys_mq_getsetattr               /* 5235 */
469 -       PTR     sys_ni_syscall                  /* sys_vserver */
470 +       PTR     sys_vserver
471         PTR     sys_waitid
472         PTR     sys_ni_syscall                  /* available, was setaltroot */
473         PTR     sys_add_key
474 diff -NurpP --minimal linux-2.6.29.4/arch/mips/kernel/scall64-n32.S linux-2.6.29.4-vs2.3.0.36.14/arch/mips/kernel/scall64-n32.S
475 --- linux-2.6.29.4/arch/mips/kernel/scall64-n32.S       2009-03-24 14:18:31.000000000 +0100
476 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/mips/kernel/scall64-n32.S 2009-03-24 14:48:21.000000000 +0100
477 @@ -360,7 +360,7 @@ EXPORT(sysn32_call_table)
478         PTR     compat_sys_mq_timedreceive
479         PTR     compat_sys_mq_notify
480         PTR     compat_sys_mq_getsetattr
481 -       PTR     sys_ni_syscall                  /* 6240, sys_vserver */
482 +       PTR     sys32_vserver                   /* 6240 */
483         PTR     compat_sys_waitid
484         PTR     sys_ni_syscall                  /* available, was setaltroot */
485         PTR     sys_add_key
486 diff -NurpP --minimal linux-2.6.29.4/arch/mips/kernel/scall64-o32.S linux-2.6.29.4-vs2.3.0.36.14/arch/mips/kernel/scall64-o32.S
487 --- linux-2.6.29.4/arch/mips/kernel/scall64-o32.S       2009-03-24 14:18:31.000000000 +0100
488 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/mips/kernel/scall64-o32.S 2009-03-24 14:59:48.000000000 +0100
489 @@ -480,7 +480,7 @@ sys_call_table:
490         PTR     compat_sys_mq_timedreceive
491         PTR     compat_sys_mq_notify            /* 4275 */
492         PTR     compat_sys_mq_getsetattr
493 -       PTR     sys_ni_syscall                  /* sys_vserver */
494 +       PTR     sys32_vserver
495         PTR     sys_32_waitid
496         PTR     sys_ni_syscall                  /* available, was setaltroot */
497         PTR     sys_add_key                     /* 4280 */
498 diff -NurpP --minimal linux-2.6.29.4/arch/mips/kernel/traps.c linux-2.6.29.4-vs2.3.0.36.14/arch/mips/kernel/traps.c
499 --- linux-2.6.29.4/arch/mips/kernel/traps.c     2009-03-24 14:18:31.000000000 +0100
500 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/mips/kernel/traps.c       2009-03-24 14:48:21.000000000 +0100
501 @@ -335,9 +335,10 @@ void show_registers(const struct pt_regs
502  
503         __show_regs(regs);
504         print_modules();
505 -       printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
506 -              current->comm, current->pid, current_thread_info(), current,
507 -             field, current_thread_info()->tp_value);
508 +       printk("Process %s (pid: %d:#%u, threadinfo=%p, task=%p, tls=%0*lx)\n",
509 +               current->comm, task_pid_nr(current), current->xid,
510 +               current_thread_info(), current,
511 +               field, current_thread_info()->tp_value);
512         if (cpu_has_userlocal) {
513                 unsigned long tls;
514  
515 diff -NurpP --minimal linux-2.6.29.4/arch/parisc/Kconfig linux-2.6.29.4-vs2.3.0.36.14/arch/parisc/Kconfig
516 --- linux-2.6.29.4/arch/parisc/Kconfig  2009-03-24 14:18:32.000000000 +0100
517 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/parisc/Kconfig    2009-03-24 14:48:21.000000000 +0100
518 @@ -281,6 +281,8 @@ source "fs/Kconfig"
519  
520  source "arch/parisc/Kconfig.debug"
521  
522 +source "kernel/vserver/Kconfig"
523 +
524  source "security/Kconfig"
525  
526  source "crypto/Kconfig"
527 diff -NurpP --minimal linux-2.6.29.4/arch/parisc/kernel/syscall_table.S linux-2.6.29.4-vs2.3.0.36.14/arch/parisc/kernel/syscall_table.S
528 --- linux-2.6.29.4/arch/parisc/kernel/syscall_table.S   2008-12-25 00:26:37.000000000 +0100
529 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/parisc/kernel/syscall_table.S     2009-02-22 22:54:24.000000000 +0100
530 @@ -361,7 +361,7 @@
531         ENTRY_COMP(mbind)               /* 260 */
532         ENTRY_COMP(get_mempolicy)
533         ENTRY_COMP(set_mempolicy)
534 -       ENTRY_SAME(ni_syscall)  /* 263: reserved for vserver */
535 +       ENTRY_DIFF(vserver)
536         ENTRY_SAME(add_key)
537         ENTRY_SAME(request_key)         /* 265 */
538         ENTRY_SAME(keyctl)
539 diff -NurpP --minimal linux-2.6.29.4/arch/parisc/kernel/traps.c linux-2.6.29.4-vs2.3.0.36.14/arch/parisc/kernel/traps.c
540 --- linux-2.6.29.4/arch/parisc/kernel/traps.c   2009-03-24 14:18:32.000000000 +0100
541 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/parisc/kernel/traps.c     2009-03-24 14:48:21.000000000 +0100
542 @@ -236,8 +236,9 @@ void die_if_kernel(char *str, struct pt_
543                 if (err == 0)
544                         return; /* STFU */
545  
546 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
547 -                       current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
548 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld) at " RFMT "\n",
549 +                       current->comm, task_pid_nr(current), current->xid,
550 +                       str, err, regs->iaoq[0]);
551  #ifdef PRINT_USER_FAULTS
552                 /* XXX for debugging only */
553                 show_regs(regs);
554 @@ -269,8 +270,8 @@ KERN_CRIT "                     ||     |
555                 pdc_console_restart();
556         
557         if (err)
558 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
559 -                       current->comm, task_pid_nr(current), str, err);
560 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld)\n",
561 +                       current->comm, task_pid_nr(current), current->xid, str, err);
562  
563         /* Wot's wrong wif bein' racy? */
564         if (current->thread.flags & PARISC_KERNEL_DEATH) {
565 diff -NurpP --minimal linux-2.6.29.4/arch/parisc/mm/fault.c linux-2.6.29.4-vs2.3.0.36.14/arch/parisc/mm/fault.c
566 --- linux-2.6.29.4/arch/parisc/mm/fault.c       2009-03-24 14:18:33.000000000 +0100
567 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/parisc/mm/fault.c 2009-03-24 14:48:21.000000000 +0100
568 @@ -238,8 +238,9 @@ bad_area:
569  
570  #ifdef PRINT_USER_FAULTS
571                 printk(KERN_DEBUG "\n");
572 -               printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n",
573 -                   task_pid_nr(tsk), tsk->comm, code, address);
574 +               printk(KERN_DEBUG "do_page_fault() pid=%d:#%u "
575 +                   "command='%s' type=%lu address=0x%08lx\n",
576 +                   task_pid_nr(tsk), tsk->xid, tsk->comm, code, address);
577                 if (vma) {
578                         printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n",
579                                         vma->vm_start, vma->vm_end);
580 @@ -265,7 +266,8 @@ no_context:
581  
582    out_of_memory:
583         up_read(&mm->mmap_sem);
584 -       printk(KERN_CRIT "VM: killing process %s\n", current->comm);
585 +       printk(KERN_CRIT "VM: killing process %s(%d:#%u)\n",
586 +               current->comm, current->pid, current->xid);
587         if (user_mode(regs))
588                 do_group_exit(SIGKILL);
589         goto no_context;
590 diff -NurpP --minimal linux-2.6.29.4/arch/powerpc/Kconfig linux-2.6.29.4-vs2.3.0.36.14/arch/powerpc/Kconfig
591 --- linux-2.6.29.4/arch/powerpc/Kconfig 2009-03-24 14:18:33.000000000 +0100
592 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/powerpc/Kconfig   2009-03-24 14:48:22.000000000 +0100
593 @@ -882,6 +882,8 @@ source "lib/Kconfig"
594  
595  source "arch/powerpc/Kconfig.debug"
596  
597 +source "kernel/vserver/Kconfig"
598 +
599  source "security/Kconfig"
600  
601  config KEYS_COMPAT
602 diff -NurpP --minimal linux-2.6.29.4/arch/powerpc/kernel/irq.c linux-2.6.29.4-vs2.3.0.36.14/arch/powerpc/kernel/irq.c
603 --- linux-2.6.29.4/arch/powerpc/kernel/irq.c    2009-03-24 14:18:35.000000000 +0100
604 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/powerpc/kernel/irq.c      2009-03-24 14:48:22.000000000 +0100
605 @@ -53,6 +53,7 @@
606  #include <linux/bootmem.h>
607  #include <linux/pci.h>
608  #include <linux/debugfs.h>
609 +#include <linux/vs_context.h>
610  
611  #include <asm/uaccess.h>
612  #include <asm/system.h>
613 diff -NurpP --minimal linux-2.6.29.4/arch/powerpc/kernel/process.c linux-2.6.29.4-vs2.3.0.36.14/arch/powerpc/kernel/process.c
614 --- linux-2.6.29.4/arch/powerpc/kernel/process.c        2009-03-24 14:18:35.000000000 +0100
615 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/powerpc/kernel/process.c  2009-03-24 14:48:22.000000000 +0100
616 @@ -516,8 +516,9 @@ void show_regs(struct pt_regs * regs)
617  #else
618                 printk("DAR: "REG", DSISR: "REG"\n", regs->dar, regs->dsisr);
619  #endif
620 -       printk("TASK = %p[%d] '%s' THREAD: %p",
621 -              current, task_pid_nr(current), current->comm, task_thread_info(current));
622 +       printk("TASK = %p[%d,#%u] '%s' THREAD: %p",
623 +              current, task_pid_nr(current), current->xid,
624 +              current->comm, task_thread_info(current));
625  
626  #ifdef CONFIG_SMP
627         printk(" CPU: %d", raw_smp_processor_id());
628 diff -NurpP --minimal linux-2.6.29.4/arch/powerpc/kernel/traps.c linux-2.6.29.4-vs2.3.0.36.14/arch/powerpc/kernel/traps.c
629 --- linux-2.6.29.4/arch/powerpc/kernel/traps.c  2009-03-24 14:18:35.000000000 +0100
630 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/powerpc/kernel/traps.c    2009-03-24 14:48:22.000000000 +0100
631 @@ -940,8 +940,9 @@ void nonrecoverable_exception(struct pt_
632  
633  void trace_syscall(struct pt_regs *regs)
634  {
635 -       printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
636 -              current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
637 +       printk("Task: %p(%d[#%u]), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
638 +              current, task_pid_nr(current), current->xid,
639 +              regs->nip, regs->link, regs->gpr[0],
640                regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
641  }
642  
643 diff -NurpP --minimal linux-2.6.29.4/arch/powerpc/kernel/vdso.c linux-2.6.29.4-vs2.3.0.36.14/arch/powerpc/kernel/vdso.c
644 --- linux-2.6.29.4/arch/powerpc/kernel/vdso.c   2009-03-24 14:18:35.000000000 +0100
645 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/powerpc/kernel/vdso.c     2009-03-24 14:48:22.000000000 +0100
646 @@ -22,6 +22,7 @@
647  #include <linux/security.h>
648  #include <linux/bootmem.h>
649  #include <linux/lmb.h>
650 +#include <linux/vs_memory.h>
651  
652  #include <asm/pgtable.h>
653  #include <asm/system.h>
654 diff -NurpP --minimal linux-2.6.29.4/arch/powerpc/mm/fault.c linux-2.6.29.4-vs2.3.0.36.14/arch/powerpc/mm/fault.c
655 --- linux-2.6.29.4/arch/powerpc/mm/fault.c      2009-03-24 14:18:36.000000000 +0100
656 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/powerpc/mm/fault.c        2009-03-24 14:48:22.000000000 +0100
657 @@ -362,7 +362,8 @@ out_of_memory:
658                 down_read(&mm->mmap_sem);
659                 goto survive;
660         }
661 -       printk("VM: killing process %s\n", current->comm);
662 +       printk("VM: killing process %s(%d:#%u)\n",
663 +               current->comm, current->pid, current->xid);
664         if (user_mode(regs))
665                 do_group_exit(SIGKILL);
666         return SIGKILL;
667 diff -NurpP --minimal linux-2.6.29.4/arch/s390/Kconfig linux-2.6.29.4-vs2.3.0.36.14/arch/s390/Kconfig
668 --- linux-2.6.29.4/arch/s390/Kconfig    2009-03-24 14:18:38.000000000 +0100
669 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/s390/Kconfig      2009-03-24 14:48:22.000000000 +0100
670 @@ -586,6 +586,8 @@ source "fs/Kconfig"
671  
672  source "arch/s390/Kconfig.debug"
673  
674 +source "kernel/vserver/Kconfig"
675 +
676  source "security/Kconfig"
677  
678  source "crypto/Kconfig"
679 diff -NurpP --minimal linux-2.6.29.4/arch/s390/kernel/ptrace.c linux-2.6.29.4-vs2.3.0.36.14/arch/s390/kernel/ptrace.c
680 --- linux-2.6.29.4/arch/s390/kernel/ptrace.c    2009-03-24 14:18:40.000000000 +0100
681 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/s390/kernel/ptrace.c      2009-03-24 14:48:22.000000000 +0100
682 @@ -36,6 +36,7 @@
683  #include <linux/elf.h>
684  #include <linux/regset.h>
685  #include <linux/tracehook.h>
686 +#include <linux/vs_base.h>
687  
688  #include <asm/segment.h>
689  #include <asm/page.h>
690 diff -NurpP --minimal linux-2.6.29.4/arch/s390/kernel/syscalls.S linux-2.6.29.4-vs2.3.0.36.14/arch/s390/kernel/syscalls.S
691 --- linux-2.6.29.4/arch/s390/kernel/syscalls.S  2009-03-24 14:18:40.000000000 +0100
692 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/s390/kernel/syscalls.S    2009-03-24 14:48:22.000000000 +0100
693 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
694  SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper)       /* 260 */
695  SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
696  SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
697 -NI_SYSCALL                                                     /* reserved for vserver */
698 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
699  SYSCALL(sys_s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
700  SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
701  SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
702 diff -NurpP --minimal linux-2.6.29.4/arch/s390/mm/fault.c linux-2.6.29.4-vs2.3.0.36.14/arch/s390/mm/fault.c
703 --- linux-2.6.29.4/arch/s390/mm/fault.c 2008-12-25 00:26:37.000000000 +0100
704 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/s390/mm/fault.c   2009-02-22 22:54:24.000000000 +0100
705 @@ -216,7 +216,8 @@ static int do_out_of_memory(struct pt_re
706                 down_read(&mm->mmap_sem);
707                 return 1;
708         }
709 -       printk("VM: killing process %s\n", tsk->comm);
710 +       printk("VM: killing process %s(%d:#%u)\n",
711 +               tsk->comm, tsk->pid, tsk->xid);
712         if (regs->psw.mask & PSW_MASK_PSTATE)
713                 do_group_exit(SIGKILL);
714         do_no_context(regs, error_code, address);
715 diff -NurpP --minimal linux-2.6.29.4/arch/sh/Kconfig linux-2.6.29.4-vs2.3.0.36.14/arch/sh/Kconfig
716 --- linux-2.6.29.4/arch/sh/Kconfig      2009-03-24 14:18:40.000000000 +0100
717 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/sh/Kconfig        2009-03-24 14:48:22.000000000 +0100
718 @@ -694,6 +694,8 @@ source "fs/Kconfig"
719  
720  source "arch/sh/Kconfig.debug"
721  
722 +source "kernel/vserver/Kconfig"
723 +
724  source "security/Kconfig"
725  
726  source "crypto/Kconfig"
727 diff -NurpP --minimal linux-2.6.29.4/arch/sh/kernel/irq.c linux-2.6.29.4-vs2.3.0.36.14/arch/sh/kernel/irq.c
728 --- linux-2.6.29.4/arch/sh/kernel/irq.c 2008-12-25 00:26:37.000000000 +0100
729 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/sh/kernel/irq.c   2009-02-22 22:54:24.000000000 +0100
730 @@ -11,6 +11,7 @@
731  #include <linux/module.h>
732  #include <linux/kernel_stat.h>
733  #include <linux/seq_file.h>
734 +#include <linux/vs_context.h>
735  #include <asm/processor.h>
736  #include <asm/machvec.h>
737  #include <asm/uaccess.h>
738 diff -NurpP --minimal linux-2.6.29.4/arch/sh/kernel/vsyscall/vsyscall.c linux-2.6.29.4-vs2.3.0.36.14/arch/sh/kernel/vsyscall/vsyscall.c
739 --- linux-2.6.29.4/arch/sh/kernel/vsyscall/vsyscall.c   2009-03-24 14:18:42.000000000 +0100
740 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/sh/kernel/vsyscall/vsyscall.c     2009-03-24 14:48:22.000000000 +0100
741 @@ -19,6 +19,7 @@
742  #include <linux/elf.h>
743  #include <linux/sched.h>
744  #include <linux/err.h>
745 +#include <linux/vs_memory.h>
746  
747  /*
748   * Should the kernel map a VDSO page into processes and pass its
749 diff -NurpP --minimal linux-2.6.29.4/arch/sparc/include/asm/tlb_64.h linux-2.6.29.4-vs2.3.0.36.14/arch/sparc/include/asm/tlb_64.h
750 --- linux-2.6.29.4/arch/sparc/include/asm/tlb_64.h      2009-05-23 23:16:50.000000000 +0200
751 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/sparc/include/asm/tlb_64.h        2009-04-30 12:14:53.000000000 +0200
752 @@ -3,6 +3,7 @@
753  
754  #include <linux/swap.h>
755  #include <linux/pagemap.h>
756 +#include <linux/vs_memory.h>
757  #include <asm/pgalloc.h>
758  #include <asm/tlbflush.h>
759  #include <asm/mmu_context.h>
760 diff -NurpP --minimal linux-2.6.29.4/arch/sparc/include/asm/unistd.h linux-2.6.29.4-vs2.3.0.36.14/arch/sparc/include/asm/unistd.h
761 --- linux-2.6.29.4/arch/sparc/include/asm/unistd.h      2009-03-24 14:18:44.000000000 +0100
762 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/sparc/include/asm/unistd.h        2009-04-08 15:52:53.000000000 +0200
763 @@ -335,7 +335,7 @@
764  #define __NR_timer_getoverrun  264
765  #define __NR_timer_delete      265
766  #define __NR_timer_create      266
767 -/* #define __NR_vserver                267 Reserved for VSERVER */
768 +#define __NR_vserver           267
769  #define __NR_io_setup          268
770  #define __NR_io_destroy                269
771  #define __NR_io_submit         270
772 diff -NurpP --minimal linux-2.6.29.4/arch/sparc/Kconfig linux-2.6.29.4-vs2.3.0.36.14/arch/sparc/Kconfig
773 --- linux-2.6.29.4/arch/sparc/Kconfig   2009-03-24 14:18:43.000000000 +0100
774 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/sparc/Kconfig     2009-03-24 14:48:22.000000000 +0100
775 @@ -522,6 +522,8 @@ source "fs/Kconfig"
776  
777  source "arch/sparc/Kconfig.debug"
778  
779 +source "kernel/vserver/Kconfig"
780 +
781  source "security/Kconfig"
782  
783  source "crypto/Kconfig"
784 diff -NurpP --minimal linux-2.6.29.4/arch/sparc/kernel/systbls_32.S linux-2.6.29.4-vs2.3.0.36.14/arch/sparc/kernel/systbls_32.S
785 --- linux-2.6.29.4/arch/sparc/kernel/systbls_32.S       2009-03-24 14:18:45.000000000 +0100
786 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/sparc/kernel/systbls_32.S 2009-04-08 15:57:59.000000000 +0200
787 @@ -70,7 +70,7 @@ sys_call_table:
788  /*250*/        .long sparc_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
789  /*255*/        .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
790  /*260*/        .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
791 -/*265*/        .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
792 +/*265*/        .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
793  /*270*/        .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
794  /*275*/        .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
795  /*280*/        .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
796 diff -NurpP --minimal linux-2.6.29.4/arch/sparc/kernel/systbls_64.S linux-2.6.29.4-vs2.3.0.36.14/arch/sparc/kernel/systbls_64.S
797 --- linux-2.6.29.4/arch/sparc/kernel/systbls_64.S       2009-03-24 14:18:45.000000000 +0100
798 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/sparc/kernel/systbls_64.S 2009-04-08 15:56:23.000000000 +0200
799 @@ -71,7 +71,7 @@ sys_call_table32:
800  /*250*/        .word sys32_mremap, sys32_sysctl, sys32_getsid, sys_fdatasync, sys32_nfsservctl
801         .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
802  /*260*/        .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
803 -       .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
804 +       .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
805  /*270*/        .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
806         .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
807  /*280*/        .word sys32_tee, sys_add_key, sys_request_key, sys_keyctl, compat_sys_openat
808 @@ -145,7 +145,7 @@ sys_call_table:
809  /*250*/        .word sys_64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nfsservctl
810         .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
811  /*260*/        .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
812 -       .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
813 +       .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
814  /*270*/        .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
815         .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
816  /*280*/        .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
817 diff -NurpP --minimal linux-2.6.29.4/arch/x86/ia32/ia32entry.S linux-2.6.29.4-vs2.3.0.36.14/arch/x86/ia32/ia32entry.S
818 --- linux-2.6.29.4/arch/x86/ia32/ia32entry.S    2009-03-24 14:18:48.000000000 +0100
819 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/x86/ia32/ia32entry.S      2009-03-22 23:29:11.000000000 +0100
820 @@ -768,7 +768,7 @@ ia32_sys_call_table:
821         .quad sys_tgkill                /* 270 */
822         .quad compat_sys_utimes
823         .quad sys32_fadvise64_64
824 -       .quad quiet_ni_syscall  /* sys_vserver */
825 +       .quad sys32_vserver
826         .quad sys_mbind
827         .quad compat_sys_get_mempolicy  /* 275 */
828         .quad sys_set_mempolicy
829 diff -NurpP --minimal linux-2.6.29.4/arch/x86/include/asm/unistd_64.h linux-2.6.29.4-vs2.3.0.36.14/arch/x86/include/asm/unistd_64.h
830 --- linux-2.6.29.4/arch/x86/include/asm/unistd_64.h     2008-12-25 00:26:37.000000000 +0100
831 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/x86/include/asm/unistd_64.h       2009-02-22 22:54:24.000000000 +0100
832 @@ -535,7 +535,7 @@ __SYSCALL(__NR_tgkill, sys_tgkill)
833  #define __NR_utimes                            235
834  __SYSCALL(__NR_utimes, sys_utimes)
835  #define __NR_vserver                           236
836 -__SYSCALL(__NR_vserver, sys_ni_syscall)
837 +__SYSCALL(__NR_vserver, sys_vserver)
838  #define __NR_mbind                             237
839  __SYSCALL(__NR_mbind, sys_mbind)
840  #define __NR_set_mempolicy                     238
841 diff -NurpP --minimal linux-2.6.29.4/arch/x86/Kconfig linux-2.6.29.4-vs2.3.0.36.14/arch/x86/Kconfig
842 --- linux-2.6.29.4/arch/x86/Kconfig     2009-03-24 14:18:47.000000000 +0100
843 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/x86/Kconfig       2009-03-24 14:48:23.000000000 +0100
844 @@ -1990,6 +1990,8 @@ source "fs/Kconfig"
845  
846  source "arch/x86/Kconfig.debug"
847  
848 +source "kernel/vserver/Kconfig"
849 +
850  source "security/Kconfig"
851  
852  source "crypto/Kconfig"
853 diff -NurpP --minimal linux-2.6.29.4/arch/x86/kernel/syscall_table_32.S linux-2.6.29.4-vs2.3.0.36.14/arch/x86/kernel/syscall_table_32.S
854 --- linux-2.6.29.4/arch/x86/kernel/syscall_table_32.S   2009-03-24 14:18:51.000000000 +0100
855 +++ linux-2.6.29.4-vs2.3.0.36.14/arch/x86/kernel/syscall_table_32.S     2009-02-22 22:54:24.000000000 +0100
856 @@ -272,7 +272,7 @@ ENTRY(sys_call_table)
857         .long sys_tgkill        /* 270 */
858         .long sys_utimes
859         .long sys_fadvise64_64
860 -       .long sys_ni_syscall    /* sys_vserver */
861 +       .long sys_vserver
862         .long sys_mbind
863         .long sys_get_mempolicy
864         .long sys_set_mempolicy
865 diff -NurpP --minimal linux-2.6.29.4/Documentation/vserver/debug.txt linux-2.6.29.4-vs2.3.0.36.14/Documentation/vserver/debug.txt
866 --- linux-2.6.29.4/Documentation/vserver/debug.txt      1970-01-01 01:00:00.000000000 +0100
867 +++ linux-2.6.29.4-vs2.3.0.36.14/Documentation/vserver/debug.txt        2009-02-22 22:54:24.000000000 +0100
868 @@ -0,0 +1,154 @@
869 +
870 +debug_cvirt:
871 +
872 + 2   4 "vx_map_tgid: %p/%llx: %d -> %d"
873 +       "vx_rmap_tgid: %p/%llx: %d -> %d"
874 +
875 +debug_dlim:
876 +
877 + 0   1 "ALLOC (%p,#%d)%c inode (%d)"
878 +       "FREE  (%p,#%d)%c inode"
879 + 1   2 "ALLOC (%p,#%d)%c %lld bytes (%d)"
880 +       "FREE  (%p,#%d)%c %lld bytes"
881 + 2   4 "ADJUST: %lld,%lld on %ld,%ld [mult=%d]"
882 + 3   8 "ext3_has_free_blocks(%p): %lu<%lu+1, %c, %u!=%u r=%d"
883 +       "ext3_has_free_blocks(%p): free=%lu, root=%lu"
884 +       "rcu_free_dl_info(%p)"
885 + 4  10 "alloc_dl_info(%p,%d) = %p"
886 +       "dealloc_dl_info(%p)"
887 +       "get_dl_info(%p[#%d.%d])"
888 +       "put_dl_info(%p[#%d.%d])"
889 + 5  20 "alloc_dl_info(%p,%d)*"
890 + 6  40 "__hash_dl_info: %p[#%d]"
891 +       "__unhash_dl_info: %p[#%d]"
892 + 7  80 "locate_dl_info(%p,#%d) = %p"
893 +
894 +debug_misc:
895 +
896 + 0   1 "destroy_dqhash: %p [#0x%08x] c=%d"
897 +       "new_dqhash: %p [#0x%08x]"
898 +       "vroot[%d]_clr_dev: dev=%p[%lu,%d:%d]"
899 +       "vroot[%d]_get_real_bdev: dev=%p[%lu,%d:%d]"
900 +       "vroot[%d]_set_dev: dev=%p[%lu,%d:%d]"
901 +       "vroot_get_real_bdev not set"
902 + 1   2 "cow_break_link(»%s«)"
903 +       "temp copy Â»%s«"
904 + 2   4 "dentry_open(new): %p"
905 +       "dentry_open(old): %p"
906 +       "lookup_create(new): %p"
907 +       "old path Â»%s«"
908 +       "path_lookup(old): %d"
909 +       "vfs_create(new): %d"
910 +       "vfs_rename: %d"
911 +       "vfs_sendfile: %d"
912 + 3   8 "fput(new_file=%p[#%d])"
913 +       "fput(old_file=%p[#%d])"
914 + 4  10 "vx_info_kill(%p[#%d],%d,%d) = %d"
915 +       "vx_info_kill(%p[#%d],%d,%d)*"
916 + 5  20 "vs_reboot(%p[#%d],%d)"
917 + 6  40 "dropping task %p[#%u,%u] for %p[#%u,%u]"
918 +
919 +debug_net:
920 +
921 + 2   4 "nx_addr_conflict(%p,%p) %d.%d,%d.%d"
922 + 3   8 "inet_bind(%p) %d.%d.%d.%d, %d.%d.%d.%d, %d.%d.%d.%d"
923 +       "inet_bind(%p)* %p,%p;%lx %d.%d.%d.%d"
924 + 4  10 "ip_route_connect(%p) %p,%p;%lx"
925 + 5  20 "__addr_in_socket(%p,%d.%d.%d.%d) %p:%d.%d.%d.%d %p;%lx"
926 + 6  40 "sk,egf: %p [#%d] (from %d)"
927 +       "sk,egn: %p [#%d] (from %d)"
928 +       "sk,req: %p [#%d] (from %d)"
929 +       "sk: %p [#%d] (from %d)"
930 +       "tw: %p [#%d] (from %d)"
931 + 7  80 "__sock_recvmsg: %p[%p,%p,%p;%d]:%d/%d"
932 +       "__sock_sendmsg: %p[%p,%p,%p;%d]:%d/%d"
933 +
934 +debug_nid:
935 +
936 + 0   1 "__lookup_nx_info(#%u): %p[#%u]"
937 +       "alloc_nx_info(%d) = %p"
938 +       "create_nx_info(%d) (dynamic rejected)"
939 +       "create_nx_info(%d) = %p (already there)"
940 +       "create_nx_info(%d) = %p (new)"
941 +       "dealloc_nx_info(%p)"
942 + 1   2 "alloc_nx_info(%d)*"
943 +       "create_nx_info(%d)*"
944 + 2   4 "get_nx_info(%p[#%d.%d])"
945 +       "put_nx_info(%p[#%d.%d])"
946 + 3   8 "claim_nx_info(%p[#%d.%d.%d]) %p"
947 +       "clr_nx_info(%p[#%d.%d])"
948 +       "init_nx_info(%p[#%d.%d])"
949 +       "release_nx_info(%p[#%d.%d.%d]) %p"
950 +       "set_nx_info(%p[#%d.%d])"
951 + 4  10 "__hash_nx_info: %p[#%d]"
952 +       "__nx_dynamic_id: [#%d]"
953 +       "__unhash_nx_info: %p[#%d.%d.%d]"
954 + 5  20 "moved task %p into nxi:%p[#%d]"
955 +       "nx_migrate_task(%p,%p[#%d.%d.%d])"
956 +       "task_get_nx_info(%p)"
957 + 6  40 "nx_clear_persistent(%p[#%d])"
958 +
959 +debug_quota:
960 +
961 + 0   1 "quota_sync_dqh(%p,%d) discard inode %p"
962 + 1   2 "quota_sync_dqh(%p,%d)"
963 +       "sync_dquots(%p,%d)"
964 +       "sync_dquots_dqh(%p,%d)"
965 + 3   8 "do_quotactl(%p,%d,cmd=%d,id=%d,%p)"
966 +
967 +debug_switch:
968 +
969 + 0   1 "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]"
970 + 1   2 "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]"
971 + 4  10 "%s: (%s %s) returned %s with %d"
972 +
973 +debug_tag:
974 +
975 + 7  80 "dx_parse_tag(»%s«): %d:#%d"
976 +       "dx_propagate_tag(%p[#%lu.%d]): %d,%d"
977 +
978 +debug_xid:
979 +
980 + 0   1 "__lookup_vx_info(#%u): %p[#%u]"
981 +       "alloc_vx_info(%d) = %p"
982 +       "alloc_vx_info(%d)*"
983 +       "create_vx_info(%d) (dynamic rejected)"
984 +       "create_vx_info(%d) = %p (already there)"
985 +       "create_vx_info(%d) = %p (new)"
986 +       "dealloc_vx_info(%p)"
987 +       "loc_vx_info(%d) = %p (found)"
988 +       "loc_vx_info(%d) = %p (new)"
989 +       "loc_vx_info(%d) = %p (not available)"
990 + 1   2 "create_vx_info(%d)*"
991 +       "loc_vx_info(%d)*"
992 + 2   4 "get_vx_info(%p[#%d.%d])"
993 +       "put_vx_info(%p[#%d.%d])"
994 + 3   8 "claim_vx_info(%p[#%d.%d.%d]) %p"
995 +       "clr_vx_info(%p[#%d.%d])"
996 +       "init_vx_info(%p[#%d.%d])"
997 +       "release_vx_info(%p[#%d.%d.%d]) %p"
998 +       "set_vx_info(%p[#%d.%d])"
999 + 4  10 "__hash_vx_info: %p[#%d]"
1000 +       "__unhash_vx_info: %p[#%d.%d.%d]"
1001 +       "__vx_dynamic_id: [#%d]"
1002 + 5  20 "enter_vx_info(%p[#%d],%p) %p[#%d,%p]"
1003 +       "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]"
1004 +       "moved task %p into vxi:%p[#%d]"
1005 +       "task_get_vx_info(%p)"
1006 +       "vx_migrate_task(%p,%p[#%d.%d])"
1007 + 6  40 "vx_clear_persistent(%p[#%d])"
1008 +       "vx_exit_init(%p[#%d],%p[#%d,%d,%d])"
1009 +       "vx_set_init(%p[#%d],%p[#%d,%d,%d])"
1010 +       "vx_set_persistent(%p[#%d])"
1011 +       "vx_set_reaper(%p[#%d],%p[#%d,%d])"
1012 + 7  80 "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]"
1013 +
1014 +
1015 +debug_limit:
1016 +
1017 + n 2^n "vx_acc_cres[%5d,%s,%2d]: %5d%s"
1018 +       "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
1019 +
1020 + m 2^m "vx_acc_page[%5d,%s,%2d]: %5d%s"
1021 +       "vx_acc_pages[%5d,%s,%2d]: %5d += %5d"
1022 +       "vx_pages_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
1023 diff -NurpP --minimal linux-2.6.29.4/drivers/block/Kconfig linux-2.6.29.4-vs2.3.0.36.14/drivers/block/Kconfig
1024 --- linux-2.6.29.4/drivers/block/Kconfig        2008-12-25 00:26:37.000000000 +0100
1025 +++ linux-2.6.29.4-vs2.3.0.36.14/drivers/block/Kconfig  2009-02-22 22:54:24.000000000 +0100
1026 @@ -264,6 +264,13 @@ config BLK_DEV_CRYPTOLOOP
1027           instead, which can be configured to be on-disk compatible with the
1028           cryptoloop device.
1029  
1030 +config BLK_DEV_VROOT
1031 +       tristate "Virtual Root device support"
1032 +       depends on QUOTACTL
1033 +       ---help---
1034 +         Saying Y here will allow you to use quota/fs ioctls on a shared
1035 +         partition within a virtual server without compromising security.
1036 +
1037  config BLK_DEV_NBD
1038         tristate "Network block device support"
1039         depends on NET
1040 diff -NurpP --minimal linux-2.6.29.4/drivers/block/loop.c linux-2.6.29.4-vs2.3.0.36.14/drivers/block/loop.c
1041 --- linux-2.6.29.4/drivers/block/loop.c 2009-03-24 14:18:56.000000000 +0100
1042 +++ linux-2.6.29.4-vs2.3.0.36.14/drivers/block/loop.c   2009-03-24 15:09:29.000000000 +0100
1043 @@ -75,6 +75,7 @@
1044  #include <linux/gfp.h>
1045  #include <linux/kthread.h>
1046  #include <linux/splice.h>
1047 +#include <linux/vs_context.h>
1048  
1049  #include <asm/uaccess.h>
1050  
1051 @@ -809,6 +810,7 @@ static int loop_set_fd(struct loop_devic
1052         lo->lo_blocksize = lo_blocksize;
1053         lo->lo_device = bdev;
1054         lo->lo_flags = lo_flags;
1055 +       lo->lo_xid = vx_current_xid();
1056         lo->lo_backing_file = file;
1057         lo->transfer = transfer_none;
1058         lo->ioctl = NULL;
1059 @@ -931,6 +933,7 @@ static int loop_clr_fd(struct loop_devic
1060         lo->lo_encrypt_key_size = 0;
1061         lo->lo_flags = 0;
1062         lo->lo_thread = NULL;
1063 +       lo->lo_xid = 0;
1064         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
1065         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
1066         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
1067 @@ -958,7 +961,7 @@ loop_set_status(struct loop_device *lo, 
1068  
1069         if (lo->lo_encrypt_key_size &&
1070             lo->lo_key_owner != uid &&
1071 -           !capable(CAP_SYS_ADMIN))
1072 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
1073                 return -EPERM;
1074         if (lo->lo_state != Lo_bound)
1075                 return -ENXIO;
1076 @@ -1042,7 +1045,8 @@ loop_get_status(struct loop_device *lo, 
1077         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
1078         info->lo_encrypt_type =
1079                 lo->lo_encryption ? lo->lo_encryption->number : 0;
1080 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
1081 +       if (lo->lo_encrypt_key_size &&
1082 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
1083                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
1084                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
1085                        lo->lo_encrypt_key_size);
1086 @@ -1351,6 +1355,9 @@ static int lo_open(struct block_device *
1087  {
1088         struct loop_device *lo = bdev->bd_disk->private_data;
1089  
1090 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P))
1091 +               return -EACCES;
1092 +
1093         mutex_lock(&lo->lo_ctl_mutex);
1094         lo->lo_refcnt++;
1095         mutex_unlock(&lo->lo_ctl_mutex);
1096 diff -NurpP --minimal linux-2.6.29.4/drivers/block/Makefile linux-2.6.29.4-vs2.3.0.36.14/drivers/block/Makefile
1097 --- linux-2.6.29.4/drivers/block/Makefile       2009-03-24 14:18:55.000000000 +0100
1098 +++ linux-2.6.29.4-vs2.3.0.36.14/drivers/block/Makefile 2009-03-24 14:48:25.000000000 +0100
1099 @@ -31,5 +31,6 @@ obj-$(CONFIG_VIODASD)         += viodasd.o
1100  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
1101  obj-$(CONFIG_BLK_DEV_UB)       += ub.o
1102  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
1103 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
1104  
1105  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
1106 diff -NurpP --minimal linux-2.6.29.4/drivers/block/vroot.c linux-2.6.29.4-vs2.3.0.36.14/drivers/block/vroot.c
1107 --- linux-2.6.29.4/drivers/block/vroot.c        1970-01-01 01:00:00.000000000 +0100
1108 +++ linux-2.6.29.4-vs2.3.0.36.14/drivers/block/vroot.c  2009-02-22 22:54:24.000000000 +0100
1109 @@ -0,0 +1,281 @@
1110 +/*
1111 + *  linux/drivers/block/vroot.c
1112 + *
1113 + *  written by Herbert Pötzl, 9/11/2002
1114 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
1115 + *
1116 + *  based on the loop.c code by Theodore Ts'o.
1117 + *
1118 + * Copyright (C) 2002-2007 by Herbert Pötzl.
1119 + * Redistribution of this file is permitted under the
1120 + * GNU General Public License.
1121 + *
1122 + */
1123 +
1124 +#include <linux/module.h>
1125 +#include <linux/moduleparam.h>
1126 +#include <linux/file.h>
1127 +#include <linux/major.h>
1128 +#include <linux/blkdev.h>
1129 +
1130 +#include <linux/vroot.h>
1131 +#include <linux/vs_context.h>
1132 +
1133 +
1134 +static int max_vroot = 8;
1135 +
1136 +static struct vroot_device *vroot_dev;
1137 +static struct gendisk **disks;
1138 +
1139 +
1140 +static int vroot_set_dev(
1141 +       struct vroot_device *vr,
1142 +       struct block_device *bdev,
1143 +       unsigned int arg)
1144 +{
1145 +       struct block_device *real_bdev;
1146 +       struct file *file;
1147 +       struct inode *inode;
1148 +       int error;
1149 +
1150 +       error = -EBUSY;
1151 +       if (vr->vr_state != Vr_unbound)
1152 +               goto out;
1153 +
1154 +       error = -EBADF;
1155 +       file = fget(arg);
1156 +       if (!file)
1157 +               goto out;
1158 +
1159 +       error = -EINVAL;
1160 +       inode = file->f_dentry->d_inode;
1161 +
1162 +
1163 +       if (S_ISBLK(inode->i_mode)) {
1164 +               real_bdev = inode->i_bdev;
1165 +               vr->vr_device = real_bdev;
1166 +               __iget(real_bdev->bd_inode);
1167 +       } else
1168 +               goto out_fput;
1169 +
1170 +       vxdprintk(VXD_CBIT(misc, 0),
1171 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
1172 +               vr->vr_number, VXD_DEV(real_bdev));
1173 +
1174 +       vr->vr_state = Vr_bound;
1175 +       error = 0;
1176 +
1177 + out_fput:
1178 +       fput(file);
1179 + out:
1180 +       return error;
1181 +}
1182 +
1183 +static int vroot_clr_dev(
1184 +       struct vroot_device *vr,
1185 +       struct block_device *bdev)
1186 +{
1187 +       struct block_device *real_bdev;
1188 +
1189 +       if (vr->vr_state != Vr_bound)
1190 +               return -ENXIO;
1191 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
1192 +               return -EBUSY;
1193 +
1194 +       real_bdev = vr->vr_device;
1195 +
1196 +       vxdprintk(VXD_CBIT(misc, 0),
1197 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
1198 +               vr->vr_number, VXD_DEV(real_bdev));
1199 +
1200 +       bdput(real_bdev);
1201 +       vr->vr_state = Vr_unbound;
1202 +       vr->vr_device = NULL;
1203 +       return 0;
1204 +}
1205 +
1206 +
1207 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
1208 +       unsigned int cmd, unsigned long arg)
1209 +{
1210 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1211 +       int err;
1212 +
1213 +       down(&vr->vr_ctl_mutex);
1214 +       switch (cmd) {
1215 +       case VROOT_SET_DEV:
1216 +               err = vroot_set_dev(vr, bdev, arg);
1217 +               break;
1218 +       case VROOT_CLR_DEV:
1219 +               err = vroot_clr_dev(vr, bdev);
1220 +               break;
1221 +       default:
1222 +               err = -EINVAL;
1223 +               break;
1224 +       }
1225 +       up(&vr->vr_ctl_mutex);
1226 +       return err;
1227 +}
1228 +
1229 +static int vr_open(struct block_device *bdev, fmode_t mode)
1230 +{
1231 +       struct vroot_device *vr = bdev->bd_disk->private_data;
1232 +
1233 +       down(&vr->vr_ctl_mutex);
1234 +       vr->vr_refcnt++;
1235 +       up(&vr->vr_ctl_mutex);
1236 +       return 0;
1237 +}
1238 +
1239 +static int vr_release(struct gendisk *disk, fmode_t mode)
1240 +{
1241 +       struct vroot_device *vr = disk->private_data;
1242 +
1243 +       down(&vr->vr_ctl_mutex);
1244 +       --vr->vr_refcnt;
1245 +       up(&vr->vr_ctl_mutex);
1246 +       return 0;
1247 +}
1248 +
1249 +static struct block_device_operations vr_fops = {
1250 +       .owner =        THIS_MODULE,
1251 +       .open =         vr_open,
1252 +       .release =      vr_release,
1253 +       .ioctl =        vr_ioctl,
1254 +};
1255 +
1256 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
1257 +{
1258 +       struct inode *inode = bdev->bd_inode;
1259 +       struct vroot_device *vr;
1260 +       struct block_device *real_bdev;
1261 +       int minor = iminor(inode);
1262 +
1263 +       vr = &vroot_dev[minor];
1264 +       real_bdev = vr->vr_device;
1265 +
1266 +       vxdprintk(VXD_CBIT(misc, 0),
1267 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1268 +               vr->vr_number, VXD_DEV(real_bdev));
1269 +
1270 +       if (vr->vr_state != Vr_bound)
1271 +               return ERR_PTR(-ENXIO);
1272 +
1273 +       __iget(real_bdev->bd_inode);
1274 +       return real_bdev;
1275 +}
1276 +
1277 +/*
1278 + * And now the modules code and kernel interface.
1279 + */
1280 +
1281 +module_param(max_vroot, int, 0);
1282 +
1283 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1284 +MODULE_LICENSE("GPL");
1285 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1286 +
1287 +MODULE_AUTHOR ("Herbert Pötzl");
1288 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1289 +
1290 +
1291 +int __init vroot_init(void)
1292 +{
1293 +       int err, i;
1294 +
1295 +       if (max_vroot < 1 || max_vroot > 256) {
1296 +               max_vroot = MAX_VROOT_DEFAULT;
1297 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1298 +                       "(must be between 1 and 256), "
1299 +                       "using default (%d)\n", max_vroot);
1300 +       }
1301 +
1302 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1303 +               return -EIO;
1304 +
1305 +       err = -ENOMEM;
1306 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1307 +       if (!vroot_dev)
1308 +               goto out_mem1;
1309 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1310 +
1311 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1312 +       if (!disks)
1313 +               goto out_mem2;
1314 +
1315 +       for (i = 0; i < max_vroot; i++) {
1316 +               disks[i] = alloc_disk(1);
1317 +               if (!disks[i])
1318 +                       goto out_mem3;
1319 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1320 +               if (!disks[i]->queue)
1321 +                       goto out_mem3;
1322 +       }
1323 +
1324 +       for (i = 0; i < max_vroot; i++) {
1325 +               struct vroot_device *vr = &vroot_dev[i];
1326 +               struct gendisk *disk = disks[i];
1327 +
1328 +               memset(vr, 0, sizeof(*vr));
1329 +               init_MUTEX(&vr->vr_ctl_mutex);
1330 +               vr->vr_number = i;
1331 +               disk->major = VROOT_MAJOR;
1332 +               disk->first_minor = i;
1333 +               disk->fops = &vr_fops;
1334 +               sprintf(disk->disk_name, "vroot%d", i);
1335 +               disk->private_data = vr;
1336 +       }
1337 +
1338 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1339 +       if (err)
1340 +               goto out_mem3;
1341 +
1342 +       for (i = 0; i < max_vroot; i++)
1343 +               add_disk(disks[i]);
1344 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1345 +       return 0;
1346 +
1347 +out_mem3:
1348 +       while (i--)
1349 +               put_disk(disks[i]);
1350 +       kfree(disks);
1351 +out_mem2:
1352 +       kfree(vroot_dev);
1353 +out_mem1:
1354 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1355 +       printk(KERN_ERR "vroot: ran out of memory\n");
1356 +       return err;
1357 +}
1358 +
1359 +void vroot_exit(void)
1360 +{
1361 +       int i;
1362 +
1363 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1364 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1365 +
1366 +       for (i = 0; i < max_vroot; i++) {
1367 +               del_gendisk(disks[i]);
1368 +               put_disk(disks[i]);
1369 +       }
1370 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1371 +
1372 +       kfree(disks);
1373 +       kfree(vroot_dev);
1374 +}
1375 +
1376 +module_init(vroot_init);
1377 +module_exit(vroot_exit);
1378 +
1379 +#ifndef MODULE
1380 +
1381 +static int __init max_vroot_setup(char *str)
1382 +{
1383 +       max_vroot = simple_strtol(str, NULL, 0);
1384 +       return 1;
1385 +}
1386 +
1387 +__setup("max_vroot=", max_vroot_setup);
1388 +
1389 +#endif
1390 +
1391 diff -NurpP --minimal linux-2.6.29.4/drivers/char/sysrq.c linux-2.6.29.4-vs2.3.0.36.14/drivers/char/sysrq.c
1392 --- linux-2.6.29.4/drivers/char/sysrq.c 2009-03-24 14:18:57.000000000 +0100
1393 +++ linux-2.6.29.4-vs2.3.0.36.14/drivers/char/sysrq.c   2009-03-24 15:15:27.000000000 +0100
1394 @@ -38,6 +38,7 @@
1395  #include <linux/irq.h>
1396  #include <linux/hrtimer.h>
1397  #include <linux/oom.h>
1398 +#include <linux/vserver/debug.h>
1399  
1400  #include <asm/ptrace.h>
1401  #include <asm/irq_regs.h>
1402 @@ -369,6 +370,21 @@ static struct sysrq_key_op sysrq_unrt_op
1403         .enable_mask    = SYSRQ_ENABLE_RTNICE,
1404  };
1405  
1406 +
1407 +#ifdef CONFIG_VSERVER_DEBUG
1408 +static void sysrq_handle_vxinfo(int key, struct tty_struct *tty)
1409 +{
1410 +       dump_vx_info_inactive((key == 'x')?0:1);
1411 +}
1412 +
1413 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1414 +       .handler        = sysrq_handle_vxinfo,
1415 +       .help_msg       = "conteXt",
1416 +       .action_msg     = "Show Context Info",
1417 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
1418 +};
1419 +#endif
1420 +
1421  /* Key Operations table and lock */
1422  static DEFINE_SPINLOCK(sysrq_key_table_lock);
1423  
1424 @@ -419,7 +435,11 @@ static struct sysrq_key_op *sysrq_key_ta
1425         NULL,                           /* v */
1426         &sysrq_showstate_blocked_op,    /* w */
1427         /* x: May be registered on ppc/powerpc for xmon */
1428 +#ifdef CONFIG_VSERVER_DEBUG
1429 +       &sysrq_showvxinfo_op,           /* x */
1430 +#else
1431         NULL,                           /* x */
1432 +#endif
1433         /* y: May be registered on sparc64 for global register dump */
1434         NULL,                           /* y */
1435         &sysrq_ftrace_dump_op,          /* z */
1436 @@ -434,6 +454,8 @@ static int sysrq_key_table_key2index(int
1437                 retval = key - '0';
1438         else if ((key >= 'a') && (key <= 'z'))
1439                 retval = key + 10 - 'a';
1440 +       else if ((key >= 'A') && (key <= 'Z'))
1441 +               retval = key + 10 - 'A';
1442         else
1443                 retval = -1;
1444         return retval;
1445 diff -NurpP --minimal linux-2.6.29.4/drivers/char/tty_io.c linux-2.6.29.4-vs2.3.0.36.14/drivers/char/tty_io.c
1446 --- linux-2.6.29.4/drivers/char/tty_io.c        2009-03-24 14:18:57.000000000 +0100
1447 +++ linux-2.6.29.4-vs2.3.0.36.14/drivers/char/tty_io.c  2009-03-24 14:48:25.000000000 +0100
1448 @@ -106,6 +106,7 @@
1449  
1450  #include <linux/kmod.h>
1451  #include <linux/nsproxy.h>
1452 +#include <linux/vs_pid.h>
1453  
1454  #undef TTY_DEBUG_HANGUP
1455  
1456 @@ -2303,6 +2304,7 @@ static int tiocspgrp(struct tty_struct *
1457                 return -ENOTTY;
1458         if (get_user(pgrp_nr, p))
1459                 return -EFAULT;
1460 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
1461         if (pgrp_nr < 0)
1462                 return -EINVAL;
1463         rcu_read_lock();
1464 diff -NurpP --minimal linux-2.6.29.4/drivers/infiniband/hw/ipath/ipath_user_pages.c linux-2.6.29.4-vs2.3.0.36.14/drivers/infiniband/hw/ipath/ipath_user_pages.c
1465 --- linux-2.6.29.4/drivers/infiniband/hw/ipath/ipath_user_pages.c       2008-12-25 00:26:37.000000000 +0100
1466 +++ linux-2.6.29.4-vs2.3.0.36.14/drivers/infiniband/hw/ipath/ipath_user_pages.c 2009-02-22 22:54:24.000000000 +0100
1467 @@ -33,6 +33,7 @@
1468  
1469  #include <linux/mm.h>
1470  #include <linux/device.h>
1471 +#include <linux/vs_memory.h>
1472  
1473  #include "ipath_kernel.h"
1474  
1475 @@ -61,7 +62,8 @@ static int __get_user_pages(unsigned lon
1476         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur >>
1477                 PAGE_SHIFT;
1478  
1479 -       if (num_pages > lock_limit) {
1480 +       if (num_pages > lock_limit ||
1481 +               !vx_vmlocked_avail(current->mm, num_pages)) {
1482                 ret = -ENOMEM;
1483                 goto bail;
1484         }
1485 @@ -78,7 +80,7 @@ static int __get_user_pages(unsigned lon
1486                         goto bail_release;
1487         }
1488  
1489 -       current->mm->locked_vm += num_pages;
1490 +       vx_vmlocked_add(current->mm, num_pages);
1491  
1492         ret = 0;
1493         goto bail;
1494 @@ -177,7 +179,7 @@ void ipath_release_user_pages(struct pag
1495  
1496         __ipath_release_user_pages(p, num_pages, 1);
1497  
1498 -       current->mm->locked_vm -= num_pages;
1499 +       vx_vmlocked_sub(current->mm, num_pages);
1500  
1501         up_write(&current->mm->mmap_sem);
1502  }
1503 @@ -194,7 +196,7 @@ static void user_pages_account(struct wo
1504                 container_of(_work, struct ipath_user_pages_work, work);
1505  
1506         down_write(&work->mm->mmap_sem);
1507 -       work->mm->locked_vm -= work->num_pages;
1508 +       vx_vmlocked_sub(work->mm, work->num_pages);
1509         up_write(&work->mm->mmap_sem);
1510         mmput(work->mm);
1511         kfree(work);
1512 diff -NurpP --minimal linux-2.6.29.4/drivers/md/dm.c linux-2.6.29.4-vs2.3.0.36.14/drivers/md/dm.c
1513 --- linux-2.6.29.4/drivers/md/dm.c      2009-03-24 14:19:05.000000000 +0100
1514 +++ linux-2.6.29.4-vs2.3.0.36.14/drivers/md/dm.c        2009-03-24 15:15:57.000000000 +0100
1515 @@ -22,6 +22,7 @@
1516  #include <linux/hdreg.h>
1517  #include <linux/blktrace_api.h>
1518  #include <trace/block.h>
1519 +#include <linux/vs_base.h>
1520  
1521  #define DM_MSG_PREFIX "core"
1522  
1523 @@ -115,6 +116,7 @@ struct mapped_device {
1524         rwlock_t map_lock;
1525         atomic_t holders;
1526         atomic_t open_count;
1527 +       xid_t xid;
1528  
1529         unsigned long flags;
1530  
1531 @@ -295,6 +297,7 @@ static void __exit dm_exit(void)
1532  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1533  {
1534         struct mapped_device *md;
1535 +       int ret = -ENXIO;
1536  
1537         spin_lock(&_minor_lock);
1538  
1539 @@ -303,18 +306,19 @@ static int dm_blk_open(struct block_devi
1540                 goto out;
1541  
1542         if (test_bit(DMF_FREEING, &md->flags) ||
1543 -           test_bit(DMF_DELETING, &md->flags)) {
1544 -               md = NULL;
1545 +           test_bit(DMF_DELETING, &md->flags))
1546 +               goto out;
1547 +
1548 +       ret = -EACCES;
1549 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1550                 goto out;
1551 -       }
1552  
1553         dm_get(md);
1554         atomic_inc(&md->open_count);
1555 -
1556 +       ret = 0;
1557  out:
1558         spin_unlock(&_minor_lock);
1559 -
1560 -       return md ? 0 : -ENXIO;
1561 +       return ret;
1562  }
1563  
1564  static int dm_blk_close(struct gendisk *disk, fmode_t mode)
1565 @@ -504,6 +508,14 @@ int dm_set_geometry(struct mapped_device
1566         return 0;
1567  }
1568  
1569 +/*
1570 + * Get the xid associated with a dm device
1571 + */
1572 +xid_t dm_get_xid(struct mapped_device *md)
1573 +{
1574 +       return md->xid;
1575 +}
1576 +
1577  /*-----------------------------------------------------------------
1578   * CRUD START:
1579   *   A more elegant soln is in the works that uses the queue
1580 @@ -1110,6 +1122,7 @@ static struct mapped_device *alloc_dev(i
1581         INIT_LIST_HEAD(&md->uevent_list);
1582         spin_lock_init(&md->uevent_lock);
1583  
1584 +       md->xid = vx_current_xid();
1585         md->queue = blk_alloc_queue(GFP_KERNEL);
1586         if (!md->queue)
1587                 goto bad_queue;
1588 diff -NurpP --minimal linux-2.6.29.4/drivers/md/dm.h linux-2.6.29.4-vs2.3.0.36.14/drivers/md/dm.h
1589 --- linux-2.6.29.4/drivers/md/dm.h      2009-03-24 14:19:05.000000000 +0100
1590 +++ linux-2.6.29.4-vs2.3.0.36.14/drivers/md/dm.h        2009-03-24 14:48:26.000000000 +0100
1591 @@ -54,6 +54,8 @@ int dm_table_any_congested(struct dm_tab
1592  #define dm_target_is_valid(t) ((t)->table)
1593  int dm_table_barrier_ok(struct dm_table *t);
1594  
1595 +xid_t dm_get_xid(struct mapped_device *md);
1596 +
1597  /*-----------------------------------------------------------------
1598   * A registry of target types.
1599   *---------------------------------------------------------------*/
1600 diff -NurpP --minimal linux-2.6.29.4/drivers/md/dm-ioctl.c linux-2.6.29.4-vs2.3.0.36.14/drivers/md/dm-ioctl.c
1601 --- linux-2.6.29.4/drivers/md/dm-ioctl.c        2009-03-24 14:19:05.000000000 +0100
1602 +++ linux-2.6.29.4-vs2.3.0.36.14/drivers/md/dm-ioctl.c  2009-03-24 14:48:26.000000000 +0100
1603 @@ -16,6 +16,7 @@
1604  #include <linux/dm-ioctl.h>
1605  #include <linux/hdreg.h>
1606  #include <linux/compat.h>
1607 +#include <linux/vs_context.h>
1608  
1609  #include <asm/uaccess.h>
1610  
1611 @@ -101,7 +102,8 @@ static struct hash_cell *__get_name_cell
1612         unsigned int h = hash_str(str);
1613  
1614         list_for_each_entry (hc, _name_buckets + h, name_list)
1615 -               if (!strcmp(hc->name, str)) {
1616 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1617 +                       !strcmp(hc->name, str)) {
1618                         dm_get(hc->md);
1619                         return hc;
1620                 }
1621 @@ -115,7 +117,8 @@ static struct hash_cell *__get_uuid_cell
1622         unsigned int h = hash_str(str);
1623  
1624         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1625 -               if (!strcmp(hc->uuid, str)) {
1626 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1627 +                       !strcmp(hc->uuid, str)) {
1628                         dm_get(hc->md);
1629                         return hc;
1630                 }
1631 @@ -352,6 +355,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl 
1632  
1633  static int remove_all(struct dm_ioctl *param, size_t param_size)
1634  {
1635 +       if (!vx_check(0, VS_ADMIN))
1636 +               return -EPERM;
1637 +
1638         dm_hash_remove_all(1);
1639         param->data_size = 0;
1640         return 0;
1641 @@ -399,6 +405,8 @@ static int list_devices(struct dm_ioctl 
1642          */
1643         for (i = 0; i < NUM_BUCKETS; i++) {
1644                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1645 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1646 +                               continue;
1647                         needed += sizeof(struct dm_name_list);
1648                         needed += strlen(hc->name) + 1;
1649                         needed += ALIGN_MASK;
1650 @@ -422,6 +430,8 @@ static int list_devices(struct dm_ioctl 
1651          */
1652         for (i = 0; i < NUM_BUCKETS; i++) {
1653                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1654 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1655 +                               continue;
1656                         if (old_nl)
1657                                 old_nl->next = (uint32_t) ((void *) nl -
1658                                                            (void *) old_nl);
1659 @@ -612,10 +622,11 @@ static struct hash_cell *__find_device_h
1660         if (!md)
1661                 goto out;
1662  
1663 -       mdptr = dm_get_mdptr(md);
1664 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1665 +               mdptr = dm_get_mdptr(md);
1666 +
1667         if (!mdptr)
1668                 dm_put(md);
1669 -
1670  out:
1671         return mdptr;
1672  }
1673 @@ -1405,8 +1416,8 @@ static int ctl_ioctl(uint command, struc
1674         ioctl_fn fn = NULL;
1675         size_t param_size;
1676  
1677 -       /* only root can play with this */
1678 -       if (!capable(CAP_SYS_ADMIN))
1679 +       /* only root and certain contexts can play with this */
1680 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1681                 return -EACCES;
1682  
1683         if (_IOC_TYPE(command) != DM_IOCTL)
1684 diff -NurpP --minimal linux-2.6.29.4/drivers/net/tun.c linux-2.6.29.4-vs2.3.0.36.14/drivers/net/tun.c
1685 --- linux-2.6.29.4/drivers/net/tun.c    2009-03-24 14:19:23.000000000 +0100
1686 +++ linux-2.6.29.4-vs2.3.0.36.14/drivers/net/tun.c      2009-03-25 01:51:59.000000000 +0100
1687 @@ -61,6 +61,7 @@
1688  #include <linux/crc32.h>
1689  #include <linux/nsproxy.h>
1690  #include <linux/virtio_net.h>
1691 +#include <linux/vs_network.h>
1692  #include <net/net_namespace.h>
1693  #include <net/netns/generic.h>
1694  
1695 @@ -93,6 +94,7 @@ struct tun_struct {
1696         int                     attached;
1697         uid_t                   owner;
1698         gid_t                   group;
1699 +       nid_t                   nid;
1700  
1701         wait_queue_head_t       read_wait;
1702         struct sk_buff_head     readq;
1703 @@ -697,6 +699,7 @@ static void tun_setup(struct net_device 
1704  
1705         tun->owner = -1;
1706         tun->group = -1;
1707 +       tun->nid = current->nid;
1708  
1709         dev->ethtool_ops = &tun_ethtool_ops;
1710         dev->destructor = free_netdev;
1711 @@ -727,6 +730,9 @@ static int tun_set_iff(struct net *net, 
1712         tn = net_generic(net, tun_net_id);
1713         tun = tun_get_by_name(tn, ifr->ifr_name);
1714         if (tun) {
1715 +               if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
1716 +                       return -EPERM;
1717 +
1718                 if (tun->attached)
1719                         return -EBUSY;
1720  
1721 @@ -735,7 +741,7 @@ static int tun_set_iff(struct net *net, 
1722                       cred->euid != tun->owner) ||
1723                      (tun->group != -1 &&
1724                       cred->egid != tun->group)) &&
1725 -                   !capable(CAP_NET_ADMIN)) {
1726 +                    !cap_raised(current_cap(), CAP_NET_ADMIN)) {
1727                         return -EPERM;
1728                 }
1729         }
1730 @@ -747,7 +753,7 @@ static int tun_set_iff(struct net *net, 
1731  
1732                 err = -EINVAL;
1733  
1734 -               if (!capable(CAP_NET_ADMIN))
1735 +               if (!nx_capable(CAP_NET_ADMIN, NXC_TUN_CREATE))
1736                         return -EPERM;
1737  
1738                 /* Set dev type */
1739 @@ -987,6 +993,16 @@ static int tun_chr_ioctl(struct inode *i
1740                 DBG(KERN_INFO "%s: group set to %d\n", tun->dev->name, tun->group);
1741                 break;
1742  
1743 +       case TUNSETNID:
1744 +               if (!capable(CAP_CONTEXT))
1745 +                       return -EPERM;
1746 +
1747 +               /* Set nid owner of the device */
1748 +               tun->nid = (nid_t) arg;
1749 +
1750 +               DBG(KERN_INFO "%s: nid owner set to %u\n", tun->dev->name, tun->nid);
1751 +               break;
1752 +
1753         case TUNSETLINK:
1754                 /* Only allow setting the type when the interface is down */
1755                 rtnl_lock();
1756 diff -NurpP --minimal linux-2.6.29.4/fs/attr.c linux-2.6.29.4-vs2.3.0.36.14/fs/attr.c
1757 --- linux-2.6.29.4/fs/attr.c    2009-03-24 14:22:24.000000000 +0100
1758 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/attr.c      2009-03-24 14:48:34.000000000 +0100
1759 @@ -14,6 +14,9 @@
1760  #include <linux/fcntl.h>
1761  #include <linux/quotaops.h>
1762  #include <linux/security.h>
1763 +#include <linux/proc_fs.h>
1764 +#include <linux/devpts_fs.h>
1765 +#include <linux/vs_tag.h>
1766  
1767  /* Taken over from the old code... */
1768  
1769 @@ -55,6 +58,10 @@ int inode_change_ok(struct inode *inode,
1770                 if (!is_owner_or_cap(inode))
1771                         goto error;
1772         }
1773 +
1774 +       if (dx_permission(inode, MAY_WRITE))
1775 +               goto error;
1776 +
1777  fine:
1778         retval = 0;
1779  error:
1780 @@ -78,6 +85,8 @@ int inode_setattr(struct inode * inode, 
1781                 inode->i_uid = attr->ia_uid;
1782         if (ia_valid & ATTR_GID)
1783                 inode->i_gid = attr->ia_gid;
1784 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
1785 +               inode->i_tag = attr->ia_tag;
1786         if (ia_valid & ATTR_ATIME)
1787                 inode->i_atime = timespec_trunc(attr->ia_atime,
1788                                                 inode->i_sb->s_time_gran);
1789 @@ -172,7 +181,8 @@ int notify_change(struct dentry * dentry
1790                 error = inode_change_ok(inode, attr);
1791                 if (!error) {
1792                         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
1793 -                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid))
1794 +                           (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
1795 +                           (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag))
1796                                 error = DQUOT_TRANSFER(inode, attr) ? -EDQUOT : 0;
1797                         if (!error)
1798                                 error = inode_setattr(inode, attr);
1799 diff -NurpP --minimal linux-2.6.29.4/fs/binfmt_aout.c linux-2.6.29.4-vs2.3.0.36.14/fs/binfmt_aout.c
1800 --- linux-2.6.29.4/fs/binfmt_aout.c     2009-03-24 14:22:24.000000000 +0100
1801 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/binfmt_aout.c       2009-03-24 14:48:34.000000000 +0100
1802 @@ -24,6 +24,7 @@
1803  #include <linux/binfmts.h>
1804  #include <linux/personality.h>
1805  #include <linux/init.h>
1806 +#include <linux/vs_memory.h>
1807  
1808  #include <asm/system.h>
1809  #include <asm/uaccess.h>
1810 diff -NurpP --minimal linux-2.6.29.4/fs/binfmt_elf.c linux-2.6.29.4-vs2.3.0.36.14/fs/binfmt_elf.c
1811 --- linux-2.6.29.4/fs/binfmt_elf.c      2009-03-24 14:22:24.000000000 +0100
1812 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/binfmt_elf.c        2009-03-24 14:48:34.000000000 +0100
1813 @@ -38,6 +38,7 @@
1814  #include <linux/random.h>
1815  #include <linux/elf.h>
1816  #include <linux/utsname.h>
1817 +#include <linux/vs_memory.h>
1818  #include <asm/uaccess.h>
1819  #include <asm/param.h>
1820  #include <asm/page.h>
1821 diff -NurpP --minimal linux-2.6.29.4/fs/binfmt_flat.c linux-2.6.29.4-vs2.3.0.36.14/fs/binfmt_flat.c
1822 --- linux-2.6.29.4/fs/binfmt_flat.c     2009-03-24 14:22:24.000000000 +0100
1823 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/binfmt_flat.c       2009-03-24 14:48:34.000000000 +0100
1824 @@ -35,6 +35,7 @@
1825  #include <linux/init.h>
1826  #include <linux/flat.h>
1827  #include <linux/syscalls.h>
1828 +#include <linux/vs_memory.h>
1829  
1830  #include <asm/byteorder.h>
1831  #include <asm/system.h>
1832 diff -NurpP --minimal linux-2.6.29.4/fs/binfmt_som.c linux-2.6.29.4-vs2.3.0.36.14/fs/binfmt_som.c
1833 --- linux-2.6.29.4/fs/binfmt_som.c      2009-03-24 14:22:24.000000000 +0100
1834 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/binfmt_som.c        2009-03-24 14:48:34.000000000 +0100
1835 @@ -28,6 +28,7 @@
1836  #include <linux/shm.h>
1837  #include <linux/personality.h>
1838  #include <linux/init.h>
1839 +#include <linux/vs_memory.h>
1840  
1841  #include <asm/uaccess.h>
1842  #include <asm/pgtable.h>
1843 diff -NurpP --minimal linux-2.6.29.4/fs/block_dev.c linux-2.6.29.4-vs2.3.0.36.14/fs/block_dev.c
1844 --- linux-2.6.29.4/fs/block_dev.c       2009-03-24 14:22:24.000000000 +0100
1845 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/block_dev.c 2009-03-24 14:48:34.000000000 +0100
1846 @@ -24,6 +24,7 @@
1847  #include <linux/uio.h>
1848  #include <linux/namei.h>
1849  #include <linux/log2.h>
1850 +#include <linux/vs_device.h>
1851  #include <asm/uaccess.h>
1852  #include "internal.h"
1853  
1854 @@ -392,6 +393,7 @@ struct block_device *bdget(dev_t dev)
1855                 bdev->bd_invalidated = 0;
1856                 inode->i_mode = S_IFBLK;
1857                 inode->i_rdev = dev;
1858 +               inode->i_mdev = dev;
1859                 inode->i_bdev = bdev;
1860                 inode->i_data.a_ops = &def_blk_aops;
1861                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
1862 @@ -428,6 +430,11 @@ EXPORT_SYMBOL(bdput);
1863  static struct block_device *bd_acquire(struct inode *inode)
1864  {
1865         struct block_device *bdev;
1866 +       dev_t mdev;
1867 +
1868 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
1869 +               return NULL;
1870 +       inode->i_mdev = mdev;
1871  
1872         spin_lock(&bdev_lock);
1873         bdev = inode->i_bdev;
1874 @@ -438,7 +445,7 @@ static struct block_device *bd_acquire(s
1875         }
1876         spin_unlock(&bdev_lock);
1877  
1878 -       bdev = bdget(inode->i_rdev);
1879 +       bdev = bdget(mdev);
1880         if (bdev) {
1881                 spin_lock(&bdev_lock);
1882                 if (!inode->i_bdev) {
1883 diff -NurpP --minimal linux-2.6.29.4/fs/char_dev.c linux-2.6.29.4-vs2.3.0.36.14/fs/char_dev.c
1884 --- linux-2.6.29.4/fs/char_dev.c        2009-03-24 14:22:25.000000000 +0100
1885 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/char_dev.c  2009-03-24 14:48:35.000000000 +0100
1886 @@ -21,6 +21,8 @@
1887  #include <linux/cdev.h>
1888  #include <linux/mutex.h>
1889  #include <linux/backing-dev.h>
1890 +#include <linux/vs_context.h>
1891 +#include <linux/vs_device.h>
1892  
1893  #include "internal.h"
1894  
1895 @@ -358,14 +360,21 @@ static int chrdev_open(struct inode *ino
1896         struct cdev *p;
1897         struct cdev *new = NULL;
1898         int ret = 0;
1899 +       dev_t mdev;
1900 +
1901 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
1902 +               return -EPERM;
1903 +       inode->i_mdev = mdev;
1904  
1905         spin_lock(&cdev_lock);
1906         p = inode->i_cdev;
1907         if (!p) {
1908                 struct kobject *kobj;
1909                 int idx;
1910 +
1911                 spin_unlock(&cdev_lock);
1912 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
1913 +
1914 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
1915                 if (!kobj)
1916                         return -ENXIO;
1917                 new = container_of(kobj, struct cdev, kobj);
1918 diff -NurpP --minimal linux-2.6.29.4/fs/dcache.c linux-2.6.29.4-vs2.3.0.36.14/fs/dcache.c
1919 --- linux-2.6.29.4/fs/dcache.c  2009-03-24 14:22:25.000000000 +0100
1920 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/dcache.c    2009-03-24 14:48:35.000000000 +0100
1921 @@ -32,6 +32,7 @@
1922  #include <linux/seqlock.h>
1923  #include <linux/swap.h>
1924  #include <linux/bootmem.h>
1925 +#include <linux/vs_limit.h>
1926  #include "internal.h"
1927  
1928  int sysctl_vfs_cache_pressure __read_mostly = 100;
1929 @@ -229,6 +230,8 @@ repeat:
1930                 return;
1931         }
1932  
1933 +       vx_dentry_dec(dentry);
1934 +
1935         /*
1936          * AV: ->d_delete() is _NOT_ allowed to block now.
1937          */
1938 @@ -320,6 +323,7 @@ static inline struct dentry * __dget_loc
1939  {
1940         atomic_inc(&dentry->d_count);
1941         dentry_lru_del_init(dentry);
1942 +       vx_dentry_inc(dentry);
1943         return dentry;
1944  }
1945  
1946 @@ -918,6 +922,9 @@ struct dentry *d_alloc(struct dentry * p
1947         struct dentry *dentry;
1948         char *dname;
1949  
1950 +       if (!vx_dentry_avail(1))
1951 +               return NULL;
1952 +
1953         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
1954         if (!dentry)
1955                 return NULL;
1956 @@ -963,6 +970,7 @@ struct dentry *d_alloc(struct dentry * p
1957         if (parent)
1958                 list_add(&dentry->d_u.d_child, &parent->d_subdirs);
1959         dentry_stat.nr_dentry++;
1960 +       vx_dentry_inc(dentry);
1961         spin_unlock(&dcache_lock);
1962  
1963         return dentry;
1964 @@ -1418,6 +1426,7 @@ struct dentry * __d_lookup(struct dentry
1965                 }
1966  
1967                 atomic_inc(&dentry->d_count);
1968 +               vx_dentry_inc(dentry);
1969                 found = dentry;
1970                 spin_unlock(&dentry->d_lock);
1971                 break;
1972 diff -NurpP --minimal linux-2.6.29.4/fs/devpts/inode.c linux-2.6.29.4-vs2.3.0.36.14/fs/devpts/inode.c
1973 --- linux-2.6.29.4/fs/devpts/inode.c    2009-03-24 14:22:25.000000000 +0100
1974 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/devpts/inode.c      2009-03-24 15:32:47.000000000 +0100
1975 @@ -19,12 +19,12 @@
1976  #include <linux/tty.h>
1977  #include <linux/mutex.h>
1978  #include <linux/idr.h>
1979 +#include <linux/magic.h>
1980  #include <linux/devpts_fs.h>
1981  #include <linux/parser.h>
1982  #include <linux/fsnotify.h>
1983  #include <linux/seq_file.h>
1984 -
1985 -#define DEVPTS_SUPER_MAGIC 0x1cd1
1986 +#include <linux/vs_base.h>
1987  
1988  #define DEVPTS_DEFAULT_MODE 0600
1989  /*
1990 @@ -36,6 +36,20 @@
1991  #define DEVPTS_DEFAULT_PTMX_MODE 0000
1992  #define PTMX_MINOR     2
1993  
1994 +static int devpts_permission(struct inode *inode, int mask)
1995 +{
1996 +       int ret = -EACCES;
1997 +
1998 +       /* devpts is xid tagged */
1999 +       if (vx_check((xid_t)inode->i_tag, VS_WATCH_P | VS_IDENT))
2000 +               ret = generic_permission(inode, mask, NULL);
2001 +       return ret;
2002 +}
2003 +
2004 +static struct inode_operations devpts_file_inode_operations = {
2005 +       .permission     = devpts_permission,
2006 +};
2007 +
2008  extern int pty_limit;                  /* Config limit on Unix98 ptys */
2009  static DEFINE_MUTEX(allocated_ptys_lock);
2010  
2011 @@ -254,6 +268,25 @@ static int devpts_show_options(struct se
2012         return 0;
2013  }
2014  
2015 +static int devpts_filter(struct dentry *de)
2016 +{
2017 +       /* devpts is xid tagged */
2018 +       return vx_check((xid_t)de->d_inode->i_tag, VS_WATCH_P | VS_IDENT);
2019 +}
2020 +
2021 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2022 +{
2023 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2024 +}
2025 +
2026 +static struct file_operations devpts_dir_operations = {
2027 +       .open           = dcache_dir_open,
2028 +       .release        = dcache_dir_close,
2029 +       .llseek         = dcache_dir_lseek,
2030 +       .read           = generic_read_dir,
2031 +       .readdir        = devpts_readdir,
2032 +};
2033 +
2034  static const struct super_operations devpts_sops = {
2035         .statfs         = simple_statfs,
2036         .remount_fs     = devpts_remount,
2037 @@ -293,12 +326,15 @@ devpts_fill_super(struct super_block *s,
2038         inode = new_inode(s);
2039         if (!inode)
2040                 goto free_fsi;
2041 +
2042         inode->i_ino = 1;
2043         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2044         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2045         inode->i_op = &simple_dir_inode_operations;
2046 -       inode->i_fop = &simple_dir_operations;
2047 +       inode->i_fop = &devpts_dir_operations;
2048         inode->i_nlink = 2;
2049 +       /* devpts is xid tagged */
2050 +       inode->i_tag = (tag_t)vx_current_xid();
2051  
2052         s->s_root = d_alloc_root(inode);
2053         if (s->s_root)
2054 @@ -479,6 +515,7 @@ static int init_pts_mount(struct file_sy
2055         return err;
2056  }
2057  
2058 +
2059  static int devpts_get_sb(struct file_system_type *fs_type,
2060         int flags, const char *dev_name, void *data, struct vfsmount *mnt)
2061  {
2062 @@ -590,6 +627,9 @@ int devpts_pty_new(struct inode *ptmx_in
2063         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2064         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2065         init_special_inode(inode, S_IFCHR|opts->mode, device);
2066 +       /* devpts is xid tagged */
2067 +       inode->i_tag = (tag_t)vx_current_xid();
2068 +       inode->i_op = &devpts_file_inode_operations;
2069         inode->i_private = tty;
2070         tty->driver_data = inode;
2071  
2072 diff -NurpP --minimal linux-2.6.29.4/fs/exec.c linux-2.6.29.4-vs2.3.0.36.14/fs/exec.c
2073 --- linux-2.6.29.4/fs/exec.c    2009-05-23 23:16:52.000000000 +0200
2074 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/exec.c      2009-05-10 23:42:01.000000000 +0200
2075 @@ -257,7 +257,9 @@ static int __bprm_mm_init(struct linux_b
2076         if (err)
2077                 goto err;
2078  
2079 -       mm->stack_vm = mm->total_vm = 1;
2080 +       mm->total_vm = 0;
2081 +       vx_vmpages_inc(mm);
2082 +       mm->stack_vm = 1;
2083         up_write(&mm->mmap_sem);
2084         bprm->p = vma->vm_end - sizeof(void *);
2085         return 0;
2086 @@ -1463,7 +1465,7 @@ static int format_corename(char *corenam
2087                         /* UNIX time of coredump */
2088                         case 't': {
2089                                 struct timeval tv;
2090 -                               do_gettimeofday(&tv);
2091 +                               vx_gettimeofday(&tv);
2092                                 rc = snprintf(out_ptr, out_end - out_ptr,
2093                                               "%lu", tv.tv_sec);
2094                                 if (rc > out_end - out_ptr)
2095 diff -NurpP --minimal linux-2.6.29.4/fs/ext2/balloc.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/balloc.c
2096 --- linux-2.6.29.4/fs/ext2/balloc.c     2009-03-24 14:22:25.000000000 +0100
2097 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/balloc.c       2009-03-24 14:48:35.000000000 +0100
2098 @@ -16,6 +16,8 @@
2099  #include <linux/sched.h>
2100  #include <linux/buffer_head.h>
2101  #include <linux/capability.h>
2102 +#include <linux/vs_dlimit.h>
2103 +#include <linux/vs_tag.h>
2104  
2105  /*
2106   * balloc.c contains the blocks allocation and deallocation routines
2107 @@ -569,6 +571,7 @@ do_more:
2108         }
2109  error_return:
2110         brelse(bitmap_bh);
2111 +       DLIMIT_FREE_BLOCK(inode, freed);
2112         release_blocks(sb, freed);
2113         DQUOT_FREE_BLOCK(inode, freed);
2114  }
2115 @@ -701,7 +704,6 @@ ext2_try_to_allocate(struct super_block 
2116                         start = 0;
2117                 end = EXT2_BLOCKS_PER_GROUP(sb);
2118         }
2119 -
2120         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2121  
2122  repeat:
2123 @@ -1251,6 +1253,11 @@ ext2_fsblk_t ext2_new_blocks(struct inod
2124                 *errp = -EDQUOT;
2125                 return 0;
2126         }
2127 +       if (DLIMIT_ALLOC_BLOCK(inode, num)) {
2128 +               *errp = -ENOSPC;
2129 +               DQUOT_FREE_BLOCK(inode, num);
2130 +               return 0;
2131 +       }
2132  
2133         sbi = EXT2_SB(sb);
2134         es = EXT2_SB(sb)->s_es;
2135 @@ -1409,6 +1416,7 @@ allocated:
2136  
2137         *errp = 0;
2138         brelse(bitmap_bh);
2139 +       DLIMIT_FREE_BLOCK(inode, *count-num);
2140         DQUOT_FREE_BLOCK(inode, *count-num);
2141         *count = num;
2142         return ret_block;
2143 @@ -1419,8 +1427,10 @@ out:
2144         /*
2145          * Undo the block allocation
2146          */
2147 -       if (!performed_allocation)
2148 +       if (!performed_allocation) {
2149 +               DLIMIT_FREE_BLOCK(inode, *count);
2150                 DQUOT_FREE_BLOCK(inode, *count);
2151 +       }
2152         brelse(bitmap_bh);
2153         return 0;
2154  }
2155 diff -NurpP --minimal linux-2.6.29.4/fs/ext2/ext2.h linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/ext2.h
2156 --- linux-2.6.29.4/fs/ext2/ext2.h       2008-12-25 00:26:37.000000000 +0100
2157 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/ext2.h 2009-02-22 22:54:25.000000000 +0100
2158 @@ -170,6 +170,7 @@ extern const struct file_operations ext2
2159  extern const struct address_space_operations ext2_aops;
2160  extern const struct address_space_operations ext2_aops_xip;
2161  extern const struct address_space_operations ext2_nobh_aops;
2162 +extern int ext2_sync_flags(struct inode *inode);
2163  
2164  /* namei.c */
2165  extern const struct inode_operations ext2_dir_inode_operations;
2166 diff -NurpP --minimal linux-2.6.29.4/fs/ext2/file.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/file.c
2167 --- linux-2.6.29.4/fs/ext2/file.c       2008-12-25 00:26:37.000000000 +0100
2168 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/file.c 2009-02-22 22:54:25.000000000 +0100
2169 @@ -87,4 +87,5 @@ const struct inode_operations ext2_file_
2170         .setattr        = ext2_setattr,
2171         .permission     = ext2_permission,
2172         .fiemap         = ext2_fiemap,
2173 +       .sync_flags     = ext2_sync_flags,
2174  };
2175 diff -NurpP --minimal linux-2.6.29.4/fs/ext2/ialloc.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/ialloc.c
2176 --- linux-2.6.29.4/fs/ext2/ialloc.c     2009-03-24 14:22:25.000000000 +0100
2177 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/ialloc.c       2009-03-24 15:36:12.000000000 +0100
2178 @@ -17,6 +17,8 @@
2179  #include <linux/backing-dev.h>
2180  #include <linux/buffer_head.h>
2181  #include <linux/random.h>
2182 +#include <linux/vs_dlimit.h>
2183 +#include <linux/vs_tag.h>
2184  #include "ext2.h"
2185  #include "xattr.h"
2186  #include "acl.h"
2187 @@ -123,6 +125,7 @@ void ext2_free_inode (struct inode * ino
2188                 ext2_xattr_delete_inode(inode);
2189                 DQUOT_FREE_INODE(inode);
2190                 DQUOT_DROP(inode);
2191 +               DLIMIT_FREE_INODE(inode);
2192         }
2193  
2194         es = EXT2_SB(sb)->s_es;
2195 @@ -454,6 +457,11 @@ struct inode *ext2_new_inode(struct inod
2196         if (!inode)
2197                 return ERR_PTR(-ENOMEM);
2198  
2199 +       inode->i_tag = dx_current_fstag(sb);
2200 +       if (DLIMIT_ALLOC_INODE(inode)) {
2201 +               err = -ENOSPC;
2202 +               goto fail_dlim;
2203 +       }
2204         ei = EXT2_I(inode);
2205         sbi = EXT2_SB(sb);
2206         es = sbi->s_es;
2207 @@ -609,6 +617,7 @@ fail_free_drop:
2208  
2209  fail_drop:
2210         DQUOT_DROP(inode);
2211 +       DLIMIT_FREE_INODE(inode);
2212         inode->i_flags |= S_NOQUOTA;
2213         inode->i_nlink = 0;
2214         unlock_new_inode(inode);
2215 @@ -616,6 +625,8 @@ fail_drop:
2216         return ERR_PTR(err);
2217  
2218  fail:
2219 +       DLIMIT_FREE_INODE(inode);
2220 +fail_dlim:
2221         make_bad_inode(inode);
2222         iput(inode);
2223         return ERR_PTR(err);
2224 diff -NurpP --minimal linux-2.6.29.4/fs/ext2/inode.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/inode.c
2225 --- linux-2.6.29.4/fs/ext2/inode.c      2009-03-24 14:22:25.000000000 +0100
2226 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/inode.c        2009-03-24 15:41:38.000000000 +0100
2227 @@ -33,6 +33,7 @@
2228  #include <linux/mpage.h>
2229  #include <linux/fiemap.h>
2230  #include <linux/namei.h>
2231 +#include <linux/vs_tag.h>
2232  #include "ext2.h"
2233  #include "acl.h"
2234  #include "xip.h"
2235 @@ -1018,7 +1019,7 @@ void ext2_truncate(struct inode *inode)
2236                 return;
2237         if (ext2_inode_is_fast_symlink(inode))
2238                 return;
2239 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2240 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2241                 return;
2242  
2243         blocksize = inode->i_sb->s_blocksize;
2244 @@ -1156,38 +1157,72 @@ void ext2_set_inode_flags(struct inode *
2245  {
2246         unsigned int flags = EXT2_I(inode)->i_flags;
2247  
2248 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2249 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2250 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2251 +
2252 +
2253 +       if (flags & EXT2_IMMUTABLE_FL)
2254 +               inode->i_flags |= S_IMMUTABLE;
2255 +       if (flags & EXT2_IXUNLINK_FL)
2256 +               inode->i_flags |= S_IXUNLINK;
2257 +
2258         if (flags & EXT2_SYNC_FL)
2259                 inode->i_flags |= S_SYNC;
2260         if (flags & EXT2_APPEND_FL)
2261                 inode->i_flags |= S_APPEND;
2262 -       if (flags & EXT2_IMMUTABLE_FL)
2263 -               inode->i_flags |= S_IMMUTABLE;
2264         if (flags & EXT2_NOATIME_FL)
2265                 inode->i_flags |= S_NOATIME;
2266         if (flags & EXT2_DIRSYNC_FL)
2267                 inode->i_flags |= S_DIRSYNC;
2268 +
2269 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2270 +
2271 +       if (flags & EXT2_BARRIER_FL)
2272 +               inode->i_vflags |= V_BARRIER;
2273 +       if (flags & EXT2_COW_FL)
2274 +               inode->i_vflags |= V_COW;
2275  }
2276  
2277  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2278  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2279  {
2280         unsigned int flags = ei->vfs_inode.i_flags;
2281 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2282 +
2283 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2284 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2285 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2286 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2287 +
2288 +       if (flags & S_IMMUTABLE)
2289 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2290 +       if (flags & S_IXUNLINK)
2291 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2292  
2293 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2294 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2295         if (flags & S_SYNC)
2296                 ei->i_flags |= EXT2_SYNC_FL;
2297         if (flags & S_APPEND)
2298                 ei->i_flags |= EXT2_APPEND_FL;
2299 -       if (flags & S_IMMUTABLE)
2300 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2301         if (flags & S_NOATIME)
2302                 ei->i_flags |= EXT2_NOATIME_FL;
2303         if (flags & S_DIRSYNC)
2304                 ei->i_flags |= EXT2_DIRSYNC_FL;
2305 +
2306 +       if (vflags & V_BARRIER)
2307 +               ei->i_flags |= EXT2_BARRIER_FL;
2308 +       if (vflags & V_COW)
2309 +               ei->i_flags |= EXT2_COW_FL;
2310  }
2311  
2312 +int ext2_sync_flags(struct inode *inode)
2313 +{
2314 +       ext2_get_inode_flags(EXT2_I(inode));
2315 +       inode->i_ctime = CURRENT_TIME;
2316 +       mark_inode_dirty(inode);
2317 +       return 0;
2318 +}
2319 +
2320 +
2321  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2322  {
2323         struct ext2_inode_info *ei;
2324 @@ -1195,6 +1230,8 @@ struct inode *ext2_iget (struct super_bl
2325         struct ext2_inode *raw_inode;
2326         struct inode *inode;
2327         long ret = -EIO;
2328 +       uid_t uid;
2329 +       gid_t gid;
2330         int n;
2331  
2332         inode = iget_locked(sb, ino);
2333 @@ -1217,12 +1254,17 @@ struct inode *ext2_iget (struct super_bl
2334         }
2335  
2336         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2337 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2338 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2339 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2340 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2341         if (!(test_opt (inode->i_sb, NO_UID32))) {
2342 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2343 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2344 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2345 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2346         }
2347 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2348 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2349 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2350 +               le16_to_cpu(raw_inode->i_raw_tag));
2351 +
2352         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
2353         inode->i_size = le32_to_cpu(raw_inode->i_size);
2354         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2355 @@ -1320,8 +1362,8 @@ static int ext2_update_inode(struct inod
2356         struct ext2_inode_info *ei = EXT2_I(inode);
2357         struct super_block *sb = inode->i_sb;
2358         ino_t ino = inode->i_ino;
2359 -       uid_t uid = inode->i_uid;
2360 -       gid_t gid = inode->i_gid;
2361 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2362 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2363         struct buffer_head * bh;
2364         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2365         int n;
2366 @@ -1357,6 +1399,9 @@ static int ext2_update_inode(struct inod
2367                 raw_inode->i_uid_high = 0;
2368                 raw_inode->i_gid_high = 0;
2369         }
2370 +#ifdef CONFIG_TAGGING_INTERN
2371 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2372 +#endif
2373         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2374         raw_inode->i_size = cpu_to_le32(inode->i_size);
2375         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2376 @@ -1443,7 +1488,8 @@ int ext2_setattr(struct dentry *dentry, 
2377         if (error)
2378                 return error;
2379         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
2380 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
2381 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
2382 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
2383                 error = DQUOT_TRANSFER(inode, iattr) ? -EDQUOT : 0;
2384                 if (error)
2385                         return error;
2386 diff -NurpP --minimal linux-2.6.29.4/fs/ext2/ioctl.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/ioctl.c
2387 --- linux-2.6.29.4/fs/ext2/ioctl.c      2009-03-24 14:22:25.000000000 +0100
2388 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/ioctl.c        2009-03-24 14:48:35.000000000 +0100
2389 @@ -14,6 +14,7 @@
2390  #include <linux/compat.h>
2391  #include <linux/mount.h>
2392  #include <linux/smp_lock.h>
2393 +#include <linux/mount.h>
2394  #include <asm/current.h>
2395  #include <asm/uaccess.h>
2396  
2397 @@ -52,6 +53,11 @@ long ext2_ioctl(struct file *filp, unsig
2398  
2399                 flags = ext2_mask_flags(inode->i_mode, flags);
2400  
2401 +               if (IS_BARRIER(inode)) {
2402 +                       vxwprintk_task(1, "messing with the barrier.");
2403 +                       return -EACCES;
2404 +               }
2405 +
2406                 mutex_lock(&inode->i_mutex);
2407                 /* Is it quota file? Do not allow user to mess with it */
2408                 if (IS_NOQUOTA(inode)) {
2409 @@ -67,7 +73,9 @@ long ext2_ioctl(struct file *filp, unsig
2410                  *
2411                  * This test looks nicer. Thanks to Pauline Middelink
2412                  */
2413 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2414 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2415 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2416 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2417                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2418                                 mutex_unlock(&inode->i_mutex);
2419                                 ret = -EPERM;
2420 diff -NurpP --minimal linux-2.6.29.4/fs/ext2/namei.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/namei.c
2421 --- linux-2.6.29.4/fs/ext2/namei.c      2009-03-24 14:22:25.000000000 +0100
2422 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/namei.c        2009-03-24 14:48:35.000000000 +0100
2423 @@ -31,6 +31,7 @@
2424   */
2425  
2426  #include <linux/pagemap.h>
2427 +#include <linux/vs_tag.h>
2428  #include "ext2.h"
2429  #include "xattr.h"
2430  #include "acl.h"
2431 @@ -68,6 +69,7 @@ static struct dentry *ext2_lookup(struct
2432                 inode = ext2_iget(dir->i_sb, ino);
2433                 if (IS_ERR(inode))
2434                         return ERR_CAST(inode);
2435 +               dx_propagate_tag(nd, inode);
2436         }
2437         return d_splice_alias(inode, dentry);
2438  }
2439 @@ -388,6 +390,7 @@ const struct inode_operations ext2_dir_i
2440  #endif
2441         .setattr        = ext2_setattr,
2442         .permission     = ext2_permission,
2443 +       .sync_flags     = ext2_sync_flags,
2444  };
2445  
2446  const struct inode_operations ext2_special_inode_operations = {
2447 @@ -399,4 +402,5 @@ const struct inode_operations ext2_speci
2448  #endif
2449         .setattr        = ext2_setattr,
2450         .permission     = ext2_permission,
2451 +       .sync_flags     = ext2_sync_flags,
2452  };
2453 diff -NurpP --minimal linux-2.6.29.4/fs/ext2/super.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/super.c
2454 --- linux-2.6.29.4/fs/ext2/super.c      2009-03-24 14:22:25.000000000 +0100
2455 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/super.c        2009-03-24 14:48:35.000000000 +0100
2456 @@ -391,7 +391,8 @@ enum {
2457         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2458         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2459         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2460 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2461 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2462 +       Opt_tag, Opt_notag, Opt_tagid
2463  };
2464  
2465  static const match_table_t tokens = {
2466 @@ -419,6 +420,9 @@ static const match_table_t tokens = {
2467         {Opt_acl, "acl"},
2468         {Opt_noacl, "noacl"},
2469         {Opt_xip, "xip"},
2470 +       {Opt_tag, "tag"},
2471 +       {Opt_notag, "notag"},
2472 +       {Opt_tagid, "tagid=%u"},
2473         {Opt_grpquota, "grpquota"},
2474         {Opt_ignore, "noquota"},
2475         {Opt_quota, "quota"},
2476 @@ -489,6 +493,20 @@ static int parse_options (char * options
2477                 case Opt_nouid32:
2478                         set_opt (sbi->s_mount_opt, NO_UID32);
2479                         break;
2480 +#ifndef CONFIG_TAGGING_NONE
2481 +               case Opt_tag:
2482 +                       set_opt (sbi->s_mount_opt, TAGGED);
2483 +                       break;
2484 +               case Opt_notag:
2485 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2486 +                       break;
2487 +#endif
2488 +#ifdef CONFIG_PROPAGATE
2489 +               case Opt_tagid:
2490 +                       /* use args[0] */
2491 +                       set_opt (sbi->s_mount_opt, TAGGED);
2492 +                       break;
2493 +#endif
2494                 case Opt_nocheck:
2495                         clear_opt (sbi->s_mount_opt, CHECK);
2496                         break;
2497 @@ -838,6 +856,8 @@ static int ext2_fill_super(struct super_
2498         if (!parse_options ((char *) data, sbi))
2499                 goto failed_mount;
2500  
2501 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2502 +               sb->s_flags |= MS_TAGGED;
2503         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2504                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2505                  MS_POSIXACL : 0);
2506 @@ -1170,6 +1190,13 @@ static int ext2_remount (struct super_bl
2507                 goto restore_opts;
2508         }
2509  
2510 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2511 +               !(sb->s_flags & MS_TAGGED)) {
2512 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2513 +                      sb->s_id);
2514 +               return -EINVAL;
2515 +       }
2516 +
2517         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2518                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2519  
2520 diff -NurpP --minimal linux-2.6.29.4/fs/ext2/symlink.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/symlink.c
2521 --- linux-2.6.29.4/fs/ext2/symlink.c    2008-12-25 00:26:37.000000000 +0100
2522 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/symlink.c      2009-02-22 22:54:25.000000000 +0100
2523 @@ -38,6 +38,7 @@ const struct inode_operations ext2_symli
2524         .listxattr      = ext2_listxattr,
2525         .removexattr    = generic_removexattr,
2526  #endif
2527 +       .sync_flags     = ext2_sync_flags,
2528  };
2529   
2530  const struct inode_operations ext2_fast_symlink_inode_operations = {
2531 @@ -49,4 +50,5 @@ const struct inode_operations ext2_fast_
2532         .listxattr      = ext2_listxattr,
2533         .removexattr    = generic_removexattr,
2534  #endif
2535 +       .sync_flags     = ext2_sync_flags,
2536  };
2537 diff -NurpP --minimal linux-2.6.29.4/fs/ext2/xattr.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/xattr.c
2538 --- linux-2.6.29.4/fs/ext2/xattr.c      2008-12-25 00:26:37.000000000 +0100
2539 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext2/xattr.c        2009-02-22 22:54:25.000000000 +0100
2540 @@ -60,6 +60,7 @@
2541  #include <linux/mbcache.h>
2542  #include <linux/quotaops.h>
2543  #include <linux/rwsem.h>
2544 +#include <linux/vs_dlimit.h>
2545  #include "ext2.h"
2546  #include "xattr.h"
2547  #include "acl.h"
2548 @@ -641,8 +642,12 @@ ext2_xattr_set2(struct inode *inode, str
2549                                    the inode.  */
2550                                 ea_bdebug(new_bh, "reusing block");
2551  
2552 +                               error = -ENOSPC;
2553 +                               if (DLIMIT_ALLOC_BLOCK(inode, 1))
2554 +                                       goto cleanup;
2555                                 error = -EDQUOT;
2556                                 if (DQUOT_ALLOC_BLOCK(inode, 1)) {
2557 +                                       DLIMIT_FREE_BLOCK(inode, 1);
2558                                         unlock_buffer(new_bh);
2559                                         goto cleanup;
2560                                 }
2561 @@ -731,6 +736,7 @@ ext2_xattr_set2(struct inode *inode, str
2562                         le32_add_cpu(&HDR(old_bh)->h_refcount, -1);
2563                         if (ce)
2564                                 mb_cache_entry_release(ce);
2565 +                       DLIMIT_FREE_BLOCK(inode, 1);
2566                         DQUOT_FREE_BLOCK(inode, 1);
2567                         mark_buffer_dirty(old_bh);
2568                         ea_bdebug(old_bh, "refcount now=%d",
2569 @@ -794,6 +800,7 @@ ext2_xattr_delete_inode(struct inode *in
2570                 mark_buffer_dirty(bh);
2571                 if (IS_SYNC(inode))
2572                         sync_dirty_buffer(bh);
2573 +               DLIMIT_FREE_BLOCK(inode, 1);
2574                 DQUOT_FREE_BLOCK(inode, 1);
2575         }
2576         EXT2_I(inode)->i_file_acl = 0;
2577 diff -NurpP --minimal linux-2.6.29.4/fs/ext3/balloc.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext3/balloc.c
2578 --- linux-2.6.29.4/fs/ext3/balloc.c     2009-03-24 14:22:25.000000000 +0100
2579 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext3/balloc.c       2009-03-25 00:53:20.000000000 +0100
2580 @@ -19,6 +19,8 @@
2581  #include <linux/ext3_jbd.h>
2582  #include <linux/quotaops.h>
2583  #include <linux/buffer_head.h>
2584 +#include <linux/vs_dlimit.h>
2585 +#include <linux/vs_tag.h>
2586  
2587  /*
2588   * balloc.c contains the blocks allocation and deallocation routines
2589 @@ -675,8 +677,10 @@ void ext3_free_blocks(handle_t *handle, 
2590                 return;
2591         }
2592         ext3_free_blocks_sb(handle, sb, block, count, &dquot_freed_blocks);
2593 -       if (dquot_freed_blocks)
2594 +       if (dquot_freed_blocks) {
2595 +               DLIMIT_FREE_BLOCK(inode, dquot_freed_blocks);
2596                 DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
2597 +       }
2598         return;
2599  }
2600  
2601 @@ -1415,18 +1419,33 @@ out:
2602   *
2603   * Check if filesystem has at least 1 free block available for allocation.
2604   */
2605 -static int ext3_has_free_blocks(struct ext3_sb_info *sbi)
2606 +static int ext3_has_free_blocks(struct super_block *sb)
2607  {
2608 -       ext3_fsblk_t free_blocks, root_blocks;
2609 +       struct ext3_sb_info *sbi = EXT3_SB(sb);
2610 +       unsigned long long free_blocks, root_blocks;
2611 +       int cond;
2612  
2613         free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
2614         root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
2615 -       if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
2616 +
2617 +       vxdprintk(VXD_CBIT(dlim, 3),
2618 +               "ext3_has_free_blocks(%p): free=%llu, root=%llu",
2619 +               sb, free_blocks, root_blocks);
2620 +
2621 +       DLIMIT_ADJUST_BLOCK(sb, dx_current_tag(), &free_blocks, &root_blocks);
2622 +
2623 +       cond = (free_blocks < root_blocks + 1 &&
2624 +               !capable(CAP_SYS_RESOURCE) &&
2625                 sbi->s_resuid != current_fsuid() &&
2626 -               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
2627 -               return 0;
2628 -       }
2629 -       return 1;
2630 +               (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)));
2631 +
2632 +       vxdprintk(VXD_CBIT(dlim, 3),
2633 +               "ext3_has_free_blocks(%p): %llu<%llu+1, %c, %u!=%u r=%d",
2634 +               sb, free_blocks, root_blocks,
2635 +               !capable(CAP_SYS_RESOURCE)?'1':'0',
2636 +               sbi->s_resuid, current_fsuid(), cond?0:1);
2637 +
2638 +       return (cond ? 0 : 1);
2639  }
2640  
2641  /**
2642 @@ -1443,7 +1462,7 @@ static int ext3_has_free_blocks(struct e
2643   */
2644  int ext3_should_retry_alloc(struct super_block *sb, int *retries)
2645  {
2646 -       if (!ext3_has_free_blocks(EXT3_SB(sb)) || (*retries)++ > 3)
2647 +       if (!ext3_has_free_blocks(sb) || (*retries)++ > 3)
2648                 return 0;
2649  
2650         jbd_debug(1, "%s: retrying operation after ENOSPC\n", sb->s_id);
2651 @@ -1506,6 +1525,8 @@ ext3_fsblk_t ext3_new_blocks(handle_t *h
2652                 *errp = -EDQUOT;
2653                 return 0;
2654         }
2655 +       if (DLIMIT_ALLOC_BLOCK(inode, num))
2656 +           goto out_dlimit;
2657  
2658         sbi = EXT3_SB(sb);
2659         es = EXT3_SB(sb)->s_es;
2660 @@ -1522,7 +1543,7 @@ ext3_fsblk_t ext3_new_blocks(handle_t *h
2661         if (block_i && ((windowsz = block_i->rsv_window_node.rsv_goal_size) > 0))
2662                 my_rsv = &block_i->rsv_window_node;
2663  
2664 -       if (!ext3_has_free_blocks(sbi)) {
2665 +       if (!ext3_has_free_blocks(sb)) {
2666                 *errp = -ENOSPC;
2667                 goto out;
2668         }
2669 @@ -1715,12 +1736,16 @@ allocated:
2670         *errp = 0;
2671         brelse(bitmap_bh);
2672         DQUOT_FREE_BLOCK(inode, *count-num);
2673 +       DLIMIT_FREE_BLOCK(inode, *count-num);
2674         *count = num;
2675         return ret_block;
2676  
2677  io_error:
2678         *errp = -EIO;
2679  out:
2680 +       if (!performed_allocation)
2681 +               DLIMIT_FREE_BLOCK(inode, *count);
2682 +out_dlimit:
2683         if (fatal) {
2684                 *errp = fatal;
2685                 ext3_std_error(sb, fatal);
2686 diff -NurpP --minimal linux-2.6.29.4/fs/ext3/file.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext3/file.c
2687 --- linux-2.6.29.4/fs/ext3/file.c       2008-12-25 00:26:37.000000000 +0100
2688 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext3/file.c 2009-02-22 22:54:25.000000000 +0100
2689 @@ -135,5 +135,6 @@ const struct inode_operations ext3_file_
2690  #endif
2691         .permission     = ext3_permission,
2692         .fiemap         = ext3_fiemap,
2693 +       .sync_flags     = ext3_sync_flags,
2694  };
2695  
2696 diff -NurpP --minimal linux-2.6.29.4/fs/ext3/ialloc.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext3/ialloc.c
2697 --- linux-2.6.29.4/fs/ext3/ialloc.c     2009-03-24 14:22:25.000000000 +0100
2698 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext3/ialloc.c       2009-03-24 15:44:06.000000000 +0100
2699 @@ -23,6 +23,8 @@
2700  #include <linux/buffer_head.h>
2701  #include <linux/random.h>
2702  #include <linux/bitops.h>
2703 +#include <linux/vs_dlimit.h>
2704 +#include <linux/vs_tag.h>
2705  
2706  #include <asm/byteorder.h>
2707  
2708 @@ -127,6 +129,7 @@ void ext3_free_inode (handle_t *handle, 
2709         ext3_xattr_delete_inode(handle, inode);
2710         DQUOT_FREE_INODE(inode);
2711         DQUOT_DROP(inode);
2712 +       DLIMIT_FREE_INODE(inode);
2713  
2714         is_directory = S_ISDIR(inode->i_mode);
2715  
2716 @@ -440,6 +443,12 @@ struct inode *ext3_new_inode(handle_t *h
2717         inode = new_inode(sb);
2718         if (!inode)
2719                 return ERR_PTR(-ENOMEM);
2720 +
2721 +       inode->i_tag = dx_current_fstag(sb);
2722 +       if (DLIMIT_ALLOC_INODE(inode)) {
2723 +               err = -ENOSPC;
2724 +               goto out_dlimit;
2725 +       }
2726         ei = EXT3_I(inode);
2727  
2728         sbi = EXT3_SB(sb);
2729 @@ -613,6 +622,8 @@ got:
2730  fail:
2731         ext3_std_error(sb, err);
2732  out:
2733 +       DLIMIT_FREE_INODE(inode);
2734 +out_dlimit:
2735         iput(inode);
2736         ret = ERR_PTR(err);
2737  really_out:
2738 @@ -624,6 +635,7 @@ fail_free_drop:
2739  
2740  fail_drop:
2741         DQUOT_DROP(inode);
2742 +       DLIMIT_FREE_INODE(inode);
2743         inode->i_flags |= S_NOQUOTA;
2744         inode->i_nlink = 0;
2745         unlock_new_inode(inode);
2746 diff -NurpP --minimal linux-2.6.29.4/fs/ext3/inode.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext3/inode.c
2747 --- linux-2.6.29.4/fs/ext3/inode.c      2009-03-24 14:22:25.000000000 +0100
2748 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext3/inode.c        2009-03-24 15:44:29.000000000 +0100
2749 @@ -38,6 +38,7 @@
2750  #include <linux/bio.h>
2751  #include <linux/fiemap.h>
2752  #include <linux/namei.h>
2753 +#include <linux/vs_tag.h>
2754  #include "xattr.h"
2755  #include "acl.h"
2756  
2757 @@ -2288,7 +2289,7 @@ static void ext3_free_branches(handle_t 
2758  
2759  int ext3_can_truncate(struct inode *inode)
2760  {
2761 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2762 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2763                 return 0;
2764         if (S_ISREG(inode->i_mode))
2765                 return 1;
2766 @@ -2662,36 +2663,84 @@ void ext3_set_inode_flags(struct inode *
2767  {
2768         unsigned int flags = EXT3_I(inode)->i_flags;
2769  
2770 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2771 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2772 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2773 +
2774 +       if (flags & EXT3_IMMUTABLE_FL)
2775 +               inode->i_flags |= S_IMMUTABLE;
2776 +       if (flags & EXT3_IXUNLINK_FL)
2777 +               inode->i_flags |= S_IXUNLINK;
2778 +
2779         if (flags & EXT3_SYNC_FL)
2780                 inode->i_flags |= S_SYNC;
2781         if (flags & EXT3_APPEND_FL)
2782                 inode->i_flags |= S_APPEND;
2783 -       if (flags & EXT3_IMMUTABLE_FL)
2784 -               inode->i_flags |= S_IMMUTABLE;
2785         if (flags & EXT3_NOATIME_FL)
2786                 inode->i_flags |= S_NOATIME;
2787         if (flags & EXT3_DIRSYNC_FL)
2788                 inode->i_flags |= S_DIRSYNC;
2789 +
2790 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2791 +
2792 +       if (flags & EXT3_BARRIER_FL)
2793 +               inode->i_vflags |= V_BARRIER;
2794 +       if (flags & EXT3_COW_FL)
2795 +               inode->i_vflags |= V_COW;
2796  }
2797  
2798  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
2799  void ext3_get_inode_flags(struct ext3_inode_info *ei)
2800  {
2801         unsigned int flags = ei->vfs_inode.i_flags;
2802 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2803 +
2804 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
2805 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
2806 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
2807 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
2808 +
2809 +       if (flags & S_IMMUTABLE)
2810 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
2811 +       if (flags & S_IXUNLINK)
2812 +               ei->i_flags |= EXT3_IXUNLINK_FL;
2813  
2814 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
2815 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
2816         if (flags & S_SYNC)
2817                 ei->i_flags |= EXT3_SYNC_FL;
2818         if (flags & S_APPEND)
2819                 ei->i_flags |= EXT3_APPEND_FL;
2820 -       if (flags & S_IMMUTABLE)
2821 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
2822         if (flags & S_NOATIME)
2823                 ei->i_flags |= EXT3_NOATIME_FL;
2824         if (flags & S_DIRSYNC)
2825                 ei->i_flags |= EXT3_DIRSYNC_FL;
2826 +
2827 +       if (vflags & V_BARRIER)
2828 +               ei->i_flags |= EXT3_BARRIER_FL;
2829 +       if (vflags & V_COW)
2830 +               ei->i_flags |= EXT3_COW_FL;
2831 +}
2832 +
2833 +int ext3_sync_flags(struct inode *inode)
2834 +{
2835 +       struct ext3_iloc iloc;
2836 +       handle_t *handle;
2837 +       int err;
2838 +
2839 +       handle = ext3_journal_start(inode, 1);
2840 +       if (IS_ERR(handle))
2841 +               return PTR_ERR(handle);
2842 +       if (IS_SYNC(inode))
2843 +               handle->h_sync = 1;
2844 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
2845 +       if (err)
2846 +               goto flags_err;
2847 +
2848 +       ext3_get_inode_flags(EXT3_I(inode));
2849 +       inode->i_ctime = CURRENT_TIME;
2850 +
2851 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
2852 +flags_err:
2853 +       ext3_journal_stop(handle);
2854 +       return err;
2855  }
2856  
2857  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
2858 @@ -2703,6 +2752,8 @@ struct inode *ext3_iget(struct super_blo
2859         struct inode *inode;
2860         long ret;
2861         int block;
2862 +       uid_t uid;
2863 +       gid_t gid;
2864  
2865         inode = iget_locked(sb, ino);
2866         if (!inode)
2867 @@ -2723,12 +2774,17 @@ struct inode *ext3_iget(struct super_blo
2868         bh = iloc.bh;
2869         raw_inode = ext3_raw_inode(&iloc);
2870         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
2871 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2872 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2873 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
2874 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
2875         if(!(test_opt (inode->i_sb, NO_UID32))) {
2876 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2877 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2878 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2879 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2880         }
2881 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
2882 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
2883 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
2884 +               le16_to_cpu(raw_inode->i_raw_tag));
2885 +
2886         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
2887         inode->i_size = le32_to_cpu(raw_inode->i_size);
2888         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2889 @@ -2859,6 +2915,8 @@ static int ext3_do_update_inode(handle_t
2890         struct ext3_inode *raw_inode = ext3_raw_inode(iloc);
2891         struct ext3_inode_info *ei = EXT3_I(inode);
2892         struct buffer_head *bh = iloc->bh;
2893 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
2894 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
2895         int err = 0, rc, block;
2896  
2897         /* For fields not not tracking in the in-memory inode,
2898 @@ -2869,29 +2927,32 @@ static int ext3_do_update_inode(handle_t
2899         ext3_get_inode_flags(ei);
2900         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2901         if(!(test_opt(inode->i_sb, NO_UID32))) {
2902 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
2903 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
2904 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
2905 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
2906  /*
2907   * Fix up interoperability with old kernels. Otherwise, old inodes get
2908   * re-used with the upper 16 bits of the uid/gid intact
2909   */
2910                 if(!ei->i_dtime) {
2911                         raw_inode->i_uid_high =
2912 -                               cpu_to_le16(high_16_bits(inode->i_uid));
2913 +                               cpu_to_le16(high_16_bits(uid));
2914                         raw_inode->i_gid_high =
2915 -                               cpu_to_le16(high_16_bits(inode->i_gid));
2916 +                               cpu_to_le16(high_16_bits(gid));
2917                 } else {
2918                         raw_inode->i_uid_high = 0;
2919                         raw_inode->i_gid_high = 0;
2920                 }
2921         } else {
2922                 raw_inode->i_uid_low =
2923 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
2924 +                       cpu_to_le16(fs_high2lowuid(uid));
2925                 raw_inode->i_gid_low =
2926 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
2927 +                       cpu_to_le16(fs_high2lowgid(gid));
2928                 raw_inode->i_uid_high = 0;
2929                 raw_inode->i_gid_high = 0;
2930         }
2931 +#ifdef CONFIG_TAGGING_INTERN
2932 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
2933 +#endif
2934         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2935         raw_inode->i_size = cpu_to_le32(ei->i_disksize);
2936         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2937 @@ -3044,7 +3105,8 @@ int ext3_setattr(struct dentry *dentry, 
2938                 return error;
2939  
2940         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
2941 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
2942 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
2943 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
2944                 handle_t *handle;
2945  
2946                 /* (user+group)*(old+new) structure, inode write (sb,
2947 @@ -3066,6 +3128,8 @@ int ext3_setattr(struct dentry *dentry, 
2948                         inode->i_uid = attr->ia_uid;
2949                 if (attr->ia_valid & ATTR_GID)
2950                         inode->i_gid = attr->ia_gid;
2951 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2952 +                       inode->i_tag = attr->ia_tag;
2953                 error = ext3_mark_inode_dirty(handle, inode);
2954                 ext3_journal_stop(handle);
2955         }
2956 diff -NurpP --minimal linux-2.6.29.4/fs/ext3/ioctl.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext3/ioctl.c
2957 --- linux-2.6.29.4/fs/ext3/ioctl.c      2009-03-24 14:22:25.000000000 +0100
2958 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext3/ioctl.c        2009-03-24 14:48:35.000000000 +0100
2959 @@ -8,6 +8,7 @@
2960   */
2961  
2962  #include <linux/fs.h>
2963 +#include <linux/mount.h>
2964  #include <linux/jbd.h>
2965  #include <linux/capability.h>
2966  #include <linux/ext3_fs.h>
2967 @@ -16,6 +17,7 @@
2968  #include <linux/time.h>
2969  #include <linux/compat.h>
2970  #include <linux/smp_lock.h>
2971 +#include <linux/vs_tag.h>
2972  #include <asm/uaccess.h>
2973  
2974  int ext3_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
2975 @@ -55,6 +57,11 @@ int ext3_ioctl (struct inode * inode, st
2976  
2977                 flags = ext3_mask_flags(inode->i_mode, flags);
2978  
2979 +               if (IS_BARRIER(inode)) {
2980 +                       vxwprintk_task(1, "messing with the barrier.");
2981 +                       return -EACCES;
2982 +               }
2983 +
2984                 mutex_lock(&inode->i_mutex);
2985                 /* Is it quota file? Do not allow user to mess with it */
2986                 if (IS_NOQUOTA(inode)) {
2987 @@ -73,7 +80,9 @@ int ext3_ioctl (struct inode * inode, st
2988                  *
2989                  * This test looks nicer. Thanks to Pauline Middelink
2990                  */
2991 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
2992 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
2993 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
2994 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
2995                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2996                                 mutex_unlock(&inode->i_mutex);
2997                                 err = -EPERM;
2998 diff -NurpP --minimal linux-2.6.29.4/fs/ext3/namei.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext3/namei.c
2999 --- linux-2.6.29.4/fs/ext3/namei.c      2009-03-24 14:22:25.000000000 +0100
3000 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext3/namei.c        2009-03-24 14:48:35.000000000 +0100
3001 @@ -36,6 +36,7 @@
3002  #include <linux/quotaops.h>
3003  #include <linux/buffer_head.h>
3004  #include <linux/bio.h>
3005 +#include <linux/vs_tag.h>
3006  
3007  #include "namei.h"
3008  #include "xattr.h"
3009 @@ -912,6 +913,7 @@ restart:
3010                                 if (bh)
3011                                         ll_rw_block(READ_META, 1, &bh);
3012                         }
3013 +               dx_propagate_tag(nd, inode);
3014                 }
3015                 if ((bh = bh_use[ra_ptr++]) == NULL)
3016                         goto next;
3017 @@ -2433,6 +2435,7 @@ const struct inode_operations ext3_dir_i
3018         .removexattr    = generic_removexattr,
3019  #endif
3020         .permission     = ext3_permission,
3021 +       .sync_flags     = ext3_sync_flags,
3022  };
3023  
3024  const struct inode_operations ext3_special_inode_operations = {
3025 @@ -2444,4 +2447,5 @@ const struct inode_operations ext3_speci
3026         .removexattr    = generic_removexattr,
3027  #endif
3028         .permission     = ext3_permission,
3029 +       .sync_flags     = ext3_sync_flags,
3030  };
3031 diff -NurpP --minimal linux-2.6.29.4/fs/ext3/super.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext3/super.c
3032 --- linux-2.6.29.4/fs/ext3/super.c      2009-03-24 14:22:25.000000000 +0100
3033 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext3/super.c        2009-03-24 14:48:35.000000000 +0100
3034 @@ -790,7 +790,7 @@ enum {
3035         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
3036         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
3037         Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
3038 -       Opt_grpquota
3039 +       Opt_grpquota, Opt_tag, Opt_notag, Opt_tagid
3040  };
3041  
3042  static const match_table_t tokens = {
3043 @@ -843,6 +843,9 @@ static const match_table_t tokens = {
3044         {Opt_usrquota, "usrquota"},
3045         {Opt_barrier, "barrier=%u"},
3046         {Opt_resize, "resize"},
3047 +       {Opt_tag, "tag"},
3048 +       {Opt_notag, "notag"},
3049 +       {Opt_tagid, "tagid=%u"},
3050         {Opt_err, NULL},
3051  };
3052  
3053 @@ -935,6 +938,20 @@ static int parse_options (char *options,
3054                 case Opt_nouid32:
3055                         set_opt (sbi->s_mount_opt, NO_UID32);
3056                         break;
3057 +#ifndef CONFIG_TAGGING_NONE
3058 +               case Opt_tag:
3059 +                       set_opt (sbi->s_mount_opt, TAGGED);
3060 +                       break;
3061 +               case Opt_notag:
3062 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3063 +                       break;
3064 +#endif
3065 +#ifdef CONFIG_PROPAGATE
3066 +               case Opt_tagid:
3067 +                       /* use args[0] */
3068 +                       set_opt (sbi->s_mount_opt, TAGGED);
3069 +                       break;
3070 +#endif
3071                 case Opt_nocheck:
3072                         clear_opt (sbi->s_mount_opt, CHECK);
3073                         break;
3074 @@ -1653,6 +1670,9 @@ static int ext3_fill_super (struct super
3075                             NULL, 0))
3076                 goto failed_mount;
3077  
3078 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
3079 +               sb->s_flags |= MS_TAGGED;
3080 +
3081         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3082                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3083  
3084 @@ -2527,6 +2547,13 @@ static int ext3_remount (struct super_bl
3085         if (sbi->s_mount_opt & EXT3_MOUNT_ABORT)
3086                 ext3_abort(sb, __func__, "Abort forced by user");
3087  
3088 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
3089 +               !(sb->s_flags & MS_TAGGED)) {
3090 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
3091 +                       sb->s_id);
3092 +               return -EINVAL;
3093 +       }
3094 +
3095         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3096                 ((sbi->s_mount_opt & EXT3_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3097  
3098 diff -NurpP --minimal linux-2.6.29.4/fs/ext3/symlink.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext3/symlink.c
3099 --- linux-2.6.29.4/fs/ext3/symlink.c    2008-12-25 00:26:37.000000000 +0100
3100 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext3/symlink.c      2009-02-22 22:54:25.000000000 +0100
3101 @@ -40,6 +40,7 @@ const struct inode_operations ext3_symli
3102         .listxattr      = ext3_listxattr,
3103         .removexattr    = generic_removexattr,
3104  #endif
3105 +       .sync_flags     = ext3_sync_flags,
3106  };
3107  
3108  const struct inode_operations ext3_fast_symlink_inode_operations = {
3109 @@ -51,4 +52,5 @@ const struct inode_operations ext3_fast_
3110         .listxattr      = ext3_listxattr,
3111         .removexattr    = generic_removexattr,
3112  #endif
3113 +       .sync_flags     = ext3_sync_flags,
3114  };
3115 diff -NurpP --minimal linux-2.6.29.4/fs/ext3/xattr.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext3/xattr.c
3116 --- linux-2.6.29.4/fs/ext3/xattr.c      2008-12-25 00:26:37.000000000 +0100
3117 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext3/xattr.c        2009-02-22 22:54:25.000000000 +0100
3118 @@ -58,6 +58,7 @@
3119  #include <linux/mbcache.h>
3120  #include <linux/quotaops.h>
3121  #include <linux/rwsem.h>
3122 +#include <linux/vs_dlimit.h>
3123  #include "xattr.h"
3124  #include "acl.h"
3125  
3126 @@ -498,6 +499,7 @@ ext3_xattr_release_block(handle_t *handl
3127                 error = ext3_journal_dirty_metadata(handle, bh);
3128                 if (IS_SYNC(inode))
3129                         handle->h_sync = 1;
3130 +                       DLIMIT_FREE_BLOCK(inode, 1);
3131                 DQUOT_FREE_BLOCK(inode, 1);
3132                 ea_bdebug(bh, "refcount now=%d; releasing",
3133                           le32_to_cpu(BHDR(bh)->h_refcount));
3134 @@ -771,11 +773,14 @@ inserted:
3135                         if (new_bh == bs->bh)
3136                                 ea_bdebug(new_bh, "keeping");
3137                         else {
3138 +                               error = -ENOSPC;
3139 +                               if (DLIMIT_ALLOC_BLOCK(inode, 1))
3140 +                                       goto cleanup;
3141                                 /* The old block is released after updating
3142                                    the inode. */
3143                                 error = -EDQUOT;
3144                                 if (DQUOT_ALLOC_BLOCK(inode, 1))
3145 -                                       goto cleanup;
3146 +                                       goto cleanup_dlimit;
3147                                 error = ext3_journal_get_write_access(handle,
3148                                                                       new_bh);
3149                                 if (error)
3150 @@ -849,6 +854,8 @@ cleanup:
3151  
3152  cleanup_dquot:
3153         DQUOT_FREE_BLOCK(inode, 1);
3154 +cleanup_dlimit:
3155 +       DLIMIT_FREE_BLOCK(inode, 1);
3156         goto cleanup;
3157  
3158  bad_block:
3159 diff -NurpP --minimal linux-2.6.29.4/fs/ext4/balloc.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/balloc.c
3160 --- linux-2.6.29.4/fs/ext4/balloc.c     2009-03-24 14:22:25.000000000 +0100
3161 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/balloc.c       2009-03-24 14:48:35.000000000 +0100
3162 @@ -17,6 +17,8 @@
3163  #include <linux/jbd2.h>
3164  #include <linux/quotaops.h>
3165  #include <linux/buffer_head.h>
3166 +#include <linux/vs_dlimit.h>
3167 +#include <linux/vs_tag.h>
3168  #include "ext4.h"
3169  #include "ext4_jbd2.h"
3170  #include "group.h"
3171 @@ -535,8 +537,10 @@ void ext4_free_blocks(handle_t *handle, 
3172  
3173         ext4_mb_free_blocks(handle, inode, block, count,
3174                             metadata, &dquot_freed_blocks);
3175 -       if (dquot_freed_blocks)
3176 +       if (dquot_freed_blocks) {
3177 +               DLIMIT_FREE_BLOCK(inode, dquot_freed_blocks);
3178                 DQUOT_FREE_BLOCK(inode, dquot_freed_blocks);
3179 +       }
3180         return;
3181  }
3182  
3183 diff -NurpP --minimal linux-2.6.29.4/fs/ext4/ext4.h linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/ext4.h
3184 --- linux-2.6.29.4/fs/ext4/ext4.h       2009-05-23 23:16:52.000000000 +0200
3185 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/ext4.h 2009-05-23 23:19:11.000000000 +0200
3186 @@ -243,8 +243,12 @@ struct flex_groups {
3187  #define EXT4_HUGE_FILE_FL               0x00040000 /* Set to each huge file */
3188  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
3189  #define EXT4_EXT_MIGRATE               0x00100000 /* Inode is migrating */
3190 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
3191  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
3192  
3193 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
3194 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
3195 +
3196  #define EXT4_FL_USER_VISIBLE           0x000BDFFF /* User visible flags */
3197  #define EXT4_FL_USER_MODIFIABLE                0x000B80FF /* User modifiable flags */
3198  
3199 @@ -541,6 +545,7 @@ do {                                                                               \
3200  #define EXT4_MOUNT_I_VERSION            0x2000000 /* i_version support */
3201  #define EXT4_MOUNT_DELALLOC            0x8000000 /* Delalloc support */
3202  #define EXT4_MOUNT_DATA_ERR_ABORT      0x10000000 /* Abort on file data write */
3203 +#define EXT4_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
3204  
3205  /* Compatibility, for having both ext2_fs.h and ext4_fs.h included at once */
3206  #ifndef _LINUX_EXT2_FS_H
3207 @@ -1076,6 +1081,7 @@ struct buffer_head *ext4_bread(handle_t 
3208                                                 ext4_lblk_t, int, int *);
3209  int ext4_get_block(struct inode *inode, sector_t iblock,
3210                                 struct buffer_head *bh_result, int create);
3211 +extern int ext4_sync_flags(struct inode *inode);
3212  
3213  extern struct inode *ext4_iget(struct super_block *, unsigned long);
3214  extern int  ext4_write_inode(struct inode *, int);
3215 diff -NurpP --minimal linux-2.6.29.4/fs/ext4/file.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/file.c
3216 --- linux-2.6.29.4/fs/ext4/file.c       2009-03-24 14:22:25.000000000 +0100
3217 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/file.c 2009-03-24 14:48:35.000000000 +0100
3218 @@ -171,5 +171,6 @@ const struct inode_operations ext4_file_
3219         .permission     = ext4_permission,
3220         .fallocate      = ext4_fallocate,
3221         .fiemap         = ext4_fiemap,
3222 +       .sync_flags     = ext4_sync_flags,
3223  };
3224  
3225 diff -NurpP --minimal linux-2.6.29.4/fs/ext4/ialloc.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/ialloc.c
3226 --- linux-2.6.29.4/fs/ext4/ialloc.c     2009-03-24 14:22:25.000000000 +0100
3227 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/ialloc.c       2009-03-24 14:48:35.000000000 +0100
3228 @@ -22,6 +22,8 @@
3229  #include <linux/random.h>
3230  #include <linux/bitops.h>
3231  #include <linux/blkdev.h>
3232 +#include <linux/vs_dlimit.h>
3233 +#include <linux/vs_tag.h>
3234  #include <asm/byteorder.h>
3235  #include "ext4.h"
3236  #include "ext4_jbd2.h"
3237 @@ -224,6 +226,7 @@ void ext4_free_inode(handle_t *handle, s
3238         ext4_xattr_delete_inode(handle, inode);
3239         DQUOT_FREE_INODE(inode);
3240         DQUOT_DROP(inode);
3241 +       DLIMIT_FREE_INODE(inode);
3242  
3243         is_directory = S_ISDIR(inode->i_mode);
3244  
3245 @@ -711,6 +714,12 @@ struct inode *ext4_new_inode(handle_t *h
3246         inode = new_inode(sb);
3247         if (!inode)
3248                 return ERR_PTR(-ENOMEM);
3249 +
3250 +       inode->i_tag = dx_current_fstag(sb);
3251 +       if (DLIMIT_ALLOC_INODE(inode)) {
3252 +               err = -ENOSPC;
3253 +               goto out_dlimit;
3254 +       }
3255         ei = EXT4_I(inode);
3256  
3257         sbi = EXT4_SB(sb);
3258 @@ -889,7 +898,8 @@ got:
3259          * newly created directory and file only if -o extent mount option is
3260          * specified
3261          */
3262 -       ei->i_flags = EXT4_I(dir)->i_flags & ~(EXT4_INDEX_FL|EXT4_EXTENTS_FL);
3263 +       ei->i_flags = EXT4_I(dir)->i_flags &
3264 +               ~(EXT4_INDEX_FL|EXT4_EXTENTS_FL|EXT4_IXUNLINK_FL|EXT4_BARRIER_FL);
3265         if (S_ISLNK(mode))
3266                 ei->i_flags &= ~(EXT4_IMMUTABLE_FL|EXT4_APPEND_FL);
3267         /* dirsync only applies to directories */
3268 @@ -949,6 +959,8 @@ got:
3269  fail:
3270         ext4_std_error(sb, err);
3271  out:
3272 +       DLIMIT_FREE_INODE(inode);
3273 +out_dlimit:
3274         iput(inode);
3275         ret = ERR_PTR(err);
3276  really_out:
3277 @@ -960,6 +972,7 @@ fail_free_drop:
3278  
3279  fail_drop:
3280         DQUOT_DROP(inode);
3281 +       DLIMIT_FREE_INODE(inode);
3282         inode->i_flags |= S_NOQUOTA;
3283         inode->i_nlink = 0;
3284         unlock_new_inode(inode);
3285 diff -NurpP --minimal linux-2.6.29.4/fs/ext4/inode.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/inode.c
3286 --- linux-2.6.29.4/fs/ext4/inode.c      2009-05-23 23:16:52.000000000 +0200
3287 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/inode.c        2009-05-23 23:19:11.000000000 +0200
3288 @@ -37,6 +37,7 @@
3289  #include <linux/namei.h>
3290  #include <linux/uio.h>
3291  #include <linux/bio.h>
3292 +#include <linux/vs_tag.h>
3293  #include "ext4_jbd2.h"
3294  #include "xattr.h"
3295  #include "acl.h"
3296 @@ -3781,7 +3782,7 @@ static void ext4_free_branches(handle_t 
3297  
3298  int ext4_can_truncate(struct inode *inode)
3299  {
3300 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
3301 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
3302                 return 0;
3303         if (S_ISREG(inode->i_mode))
3304                 return 1;
3305 @@ -4134,37 +4135,86 @@ void ext4_set_inode_flags(struct inode *
3306  {
3307         unsigned int flags = EXT4_I(inode)->i_flags;
3308  
3309 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3310 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3311 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3312 +
3313 +       if (flags & EXT4_IMMUTABLE_FL)
3314 +               inode->i_flags |= S_IMMUTABLE;
3315 +       if (flags & EXT4_IXUNLINK_FL)
3316 +               inode->i_flags |= S_IXUNLINK;
3317 +
3318         if (flags & EXT4_SYNC_FL)
3319                 inode->i_flags |= S_SYNC;
3320         if (flags & EXT4_APPEND_FL)
3321                 inode->i_flags |= S_APPEND;
3322 -       if (flags & EXT4_IMMUTABLE_FL)
3323 -               inode->i_flags |= S_IMMUTABLE;
3324         if (flags & EXT4_NOATIME_FL)
3325                 inode->i_flags |= S_NOATIME;
3326         if (flags & EXT4_DIRSYNC_FL)
3327                 inode->i_flags |= S_DIRSYNC;
3328 +
3329 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3330 +
3331 +       if (flags & EXT4_BARRIER_FL)
3332 +               inode->i_vflags |= V_BARRIER;
3333 +       if (flags & EXT4_COW_FL)
3334 +               inode->i_vflags |= V_COW;
3335  }
3336  
3337  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3338  void ext4_get_inode_flags(struct ext4_inode_info *ei)
3339  {
3340         unsigned int flags = ei->vfs_inode.i_flags;
3341 +       unsigned int vflags = ei->vfs_inode.i_vflags;
3342 +
3343 +       ei->i_flags &= ~(EXT4_SYNC_FL | EXT4_APPEND_FL |
3344 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL |
3345 +                       EXT4_NOATIME_FL | EXT4_DIRSYNC_FL |
3346 +                       EXT4_BARRIER_FL | EXT4_COW_FL);
3347 +
3348 +       if (flags & S_IMMUTABLE)
3349 +               ei->i_flags |= EXT4_IMMUTABLE_FL;
3350 +       if (flags & S_IXUNLINK)
3351 +               ei->i_flags |= EXT4_IXUNLINK_FL;
3352  
3353 -       ei->i_flags &= ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3354 -                       EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|EXT4_DIRSYNC_FL);
3355         if (flags & S_SYNC)
3356                 ei->i_flags |= EXT4_SYNC_FL;
3357         if (flags & S_APPEND)
3358                 ei->i_flags |= EXT4_APPEND_FL;
3359 -       if (flags & S_IMMUTABLE)
3360 -               ei->i_flags |= EXT4_IMMUTABLE_FL;
3361         if (flags & S_NOATIME)
3362                 ei->i_flags |= EXT4_NOATIME_FL;
3363         if (flags & S_DIRSYNC)
3364                 ei->i_flags |= EXT4_DIRSYNC_FL;
3365 +
3366 +       if (vflags & V_BARRIER)
3367 +               ei->i_flags |= EXT4_BARRIER_FL;
3368 +       if (vflags & V_COW)
3369 +               ei->i_flags |= EXT4_COW_FL;
3370 +}
3371 +
3372 +int ext4_sync_flags(struct inode *inode)
3373 +{
3374 +       struct ext4_iloc iloc;
3375 +       handle_t *handle;
3376 +       int err;
3377 +
3378 +       handle = ext4_journal_start(inode, 1);
3379 +       if (IS_ERR(handle))
3380 +               return PTR_ERR(handle);
3381 +       if (IS_SYNC(inode))
3382 +               handle->h_sync = 1;
3383 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3384 +       if (err)
3385 +               goto flags_err;
3386 +
3387 +       ext4_get_inode_flags(EXT4_I(inode));
3388 +       inode->i_ctime = CURRENT_TIME;
3389 +
3390 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3391 +flags_err:
3392 +       ext4_journal_stop(handle);
3393 +       return err;
3394  }
3395 +
3396  static blkcnt_t ext4_inode_blocks(struct ext4_inode *raw_inode,
3397                                         struct ext4_inode_info *ei)
3398  {
3399 @@ -4197,6 +4247,8 @@ struct inode *ext4_iget(struct super_blo
3400         struct inode *inode;
3401         long ret;
3402         int block;
3403 +       uid_t uid;
3404 +       gid_t gid;
3405  
3406         inode = iget_locked(sb, ino);
3407         if (!inode)
3408 @@ -4216,12 +4268,16 @@ struct inode *ext4_iget(struct super_blo
3409         bh = iloc.bh;
3410         raw_inode = ext4_raw_inode(&iloc);
3411         inode->i_mode = le16_to_cpu(raw_inode->i_mode);
3412 -       inode->i_uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3413 -       inode->i_gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3414 +       uid = (uid_t)le16_to_cpu(raw_inode->i_uid_low);
3415 +       gid = (gid_t)le16_to_cpu(raw_inode->i_gid_low);
3416         if (!(test_opt(inode->i_sb, NO_UID32))) {
3417 -               inode->i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3418 -               inode->i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3419 +               uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3420 +               gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3421         }
3422 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
3423 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
3424 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
3425 +               le16_to_cpu(raw_inode->i_raw_tag));
3426         inode->i_nlink = le16_to_cpu(raw_inode->i_links_count);
3427  
3428         ei->i_state = 0;
3429 @@ -4387,6 +4443,8 @@ static int ext4_do_update_inode(handle_t
3430         struct ext4_inode *raw_inode = ext4_raw_inode(iloc);
3431         struct ext4_inode_info *ei = EXT4_I(inode);
3432         struct buffer_head *bh = iloc->bh;
3433 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
3434 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
3435         int err = 0, rc, block;
3436  
3437         /* For fields not not tracking in the in-memory inode,
3438 @@ -4397,29 +4455,32 @@ static int ext4_do_update_inode(handle_t
3439         ext4_get_inode_flags(ei);
3440         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3441         if (!(test_opt(inode->i_sb, NO_UID32))) {
3442 -               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(inode->i_uid));
3443 -               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(inode->i_gid));
3444 +               raw_inode->i_uid_low = cpu_to_le16(low_16_bits(uid));
3445 +               raw_inode->i_gid_low = cpu_to_le16(low_16_bits(gid));
3446  /*
3447   * Fix up interoperability with old kernels. Otherwise, old inodes get
3448   * re-used with the upper 16 bits of the uid/gid intact
3449   */
3450                 if (!ei->i_dtime) {
3451                         raw_inode->i_uid_high =
3452 -                               cpu_to_le16(high_16_bits(inode->i_uid));
3453 +                               cpu_to_le16(high_16_bits(uid));
3454                         raw_inode->i_gid_high =
3455 -                               cpu_to_le16(high_16_bits(inode->i_gid));
3456 +                               cpu_to_le16(high_16_bits(gid));
3457                 } else {
3458                         raw_inode->i_uid_high = 0;
3459                         raw_inode->i_gid_high = 0;
3460                 }
3461         } else {
3462                 raw_inode->i_uid_low =
3463 -                       cpu_to_le16(fs_high2lowuid(inode->i_uid));
3464 +                       cpu_to_le16(fs_high2lowuid(uid));
3465                 raw_inode->i_gid_low =
3466 -                       cpu_to_le16(fs_high2lowgid(inode->i_gid));
3467 +                       cpu_to_le16(fs_high2lowgid(gid));
3468                 raw_inode->i_uid_high = 0;
3469                 raw_inode->i_gid_high = 0;
3470         }
3471 +#ifdef CONFIG_TAGGING_INTERN
3472 +       raw_inode->i_raw_tag = cpu_to_le16(inode->i_tag);
3473 +#endif
3474         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3475  
3476         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3477 @@ -4601,7 +4662,8 @@ int ext4_setattr(struct dentry *dentry, 
3478                 return error;
3479  
3480         if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
3481 -               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
3482 +               (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
3483 +               (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
3484                 handle_t *handle;
3485  
3486                 /* (user+group)*(old+new) structure, inode write (sb,
3487 @@ -4623,6 +4685,8 @@ int ext4_setattr(struct dentry *dentry, 
3488                         inode->i_uid = attr->ia_uid;
3489                 if (attr->ia_valid & ATTR_GID)
3490                         inode->i_gid = attr->ia_gid;
3491 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3492 +                       inode->i_tag = attr->ia_tag;
3493                 error = ext4_mark_inode_dirty(handle, inode);
3494                 ext4_journal_stop(handle);
3495         }
3496 diff -NurpP --minimal linux-2.6.29.4/fs/ext4/ioctl.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/ioctl.c
3497 --- linux-2.6.29.4/fs/ext4/ioctl.c      2009-03-24 14:22:25.000000000 +0100
3498 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/ioctl.c        2009-03-24 14:48:35.000000000 +0100
3499 @@ -8,12 +8,14 @@
3500   */
3501  
3502  #include <linux/fs.h>
3503 +#include <linux/mount.h>
3504  #include <linux/jbd2.h>
3505  #include <linux/capability.h>
3506  #include <linux/time.h>
3507  #include <linux/compat.h>
3508  #include <linux/smp_lock.h>
3509  #include <linux/mount.h>
3510 +#include <linux/vs_tag.h>
3511  #include <asm/uaccess.h>
3512  #include "ext4_jbd2.h"
3513  #include "ext4.h"
3514 @@ -51,6 +53,11 @@ long ext4_ioctl(struct file *filp, unsig
3515                 if (!S_ISDIR(inode->i_mode))
3516                         flags &= ~EXT4_DIRSYNC_FL;
3517  
3518 +               if (IS_BARRIER(inode)) {
3519 +                       vxwprintk_task(1, "messing with the barrier.");
3520 +                       return -EACCES;
3521 +               }
3522 +
3523                 err = -EPERM;
3524                 mutex_lock(&inode->i_mutex);
3525                 /* Is it quota file? Do not allow user to mess with it */
3526 @@ -68,7 +75,9 @@ long ext4_ioctl(struct file *filp, unsig
3527                  *
3528                  * This test looks nicer. Thanks to Pauline Middelink
3529                  */
3530 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3531 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3532 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3533 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3534                         if (!capable(CAP_LINUX_IMMUTABLE))
3535                                 goto flags_out;
3536                 }
3537 diff -NurpP --minimal linux-2.6.29.4/fs/ext4/namei.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/namei.c
3538 --- linux-2.6.29.4/fs/ext4/namei.c      2009-03-24 14:22:25.000000000 +0100
3539 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/namei.c        2009-03-24 14:48:35.000000000 +0100
3540 @@ -34,6 +34,7 @@
3541  #include <linux/quotaops.h>
3542  #include <linux/buffer_head.h>
3543  #include <linux/bio.h>
3544 +#include <linux/vs_tag.h>
3545  #include "ext4.h"
3546  #include "ext4_jbd2.h"
3547  
3548 @@ -917,6 +918,7 @@ restart:
3549                                 if (bh)
3550                                         ll_rw_block(READ_META, 1, &bh);
3551                         }
3552 +               dx_propagate_tag(nd, inode);
3553                 }
3554                 if ((bh = bh_use[ra_ptr++]) == NULL)
3555                         goto next;
3556 @@ -2481,6 +2483,7 @@ const struct inode_operations ext4_dir_i
3557         .removexattr    = generic_removexattr,
3558  #endif
3559         .permission     = ext4_permission,
3560 +       .sync_flags     = ext4_sync_flags,
3561  };
3562  
3563  const struct inode_operations ext4_special_inode_operations = {
3564 @@ -2492,4 +2495,5 @@ const struct inode_operations ext4_speci
3565         .removexattr    = generic_removexattr,
3566  #endif
3567         .permission     = ext4_permission,
3568 +       .sync_flags     = ext4_sync_flags,
3569  };
3570 diff -NurpP --minimal linux-2.6.29.4/fs/ext4/super.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/super.c
3571 --- linux-2.6.29.4/fs/ext4/super.c      2009-03-24 14:22:25.000000000 +0100
3572 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/super.c        2009-03-24 15:46:48.000000000 +0100
3573 @@ -1013,7 +1013,8 @@ enum {
3574         Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota,
3575         Opt_grpquota, Opt_i_version,
3576         Opt_stripe, Opt_delalloc, Opt_nodelalloc,
3577 -       Opt_inode_readahead_blks, Opt_journal_ioprio
3578 +       Opt_inode_readahead_blks, Opt_journal_ioprio,
3579 +       Opt_tag, Opt_notag, Opt_tagid
3580  };
3581  
3582  static const match_table_t tokens = {
3583 @@ -1073,6 +1074,9 @@ static const match_table_t tokens = {
3584         {Opt_nodelalloc, "nodelalloc"},
3585         {Opt_inode_readahead_blks, "inode_readahead_blks=%u"},
3586         {Opt_journal_ioprio, "journal_ioprio=%u"},
3587 +       {Opt_tag, "tag"},
3588 +       {Opt_notag, "notag"},
3589 +       {Opt_tagid, "tagid=%u"},
3590         {Opt_err, NULL},
3591  };
3592  
3593 @@ -1168,6 +1172,20 @@ static int parse_options(char *options, 
3594                 case Opt_nouid32:
3595                         set_opt(sbi->s_mount_opt, NO_UID32);
3596                         break;
3597 +#ifndef CONFIG_TAGGING_NONE
3598 +               case Opt_tag:
3599 +                       set_opt (sbi->s_mount_opt, TAGGED);
3600 +                       break;
3601 +               case Opt_notag:
3602 +                       clear_opt (sbi->s_mount_opt, TAGGED);
3603 +                       break;
3604 +#endif
3605 +#ifdef CONFIG_PROPAGATE
3606 +               case Opt_tagid:
3607 +                       /* use args[0] */
3608 +                       set_opt (sbi->s_mount_opt, TAGGED);
3609 +                       break;
3610 +#endif
3611                 case Opt_debug:
3612                         set_opt(sbi->s_mount_opt, DEBUG);
3613                         break;
3614 @@ -2113,6 +2131,9 @@ static int ext4_fill_super(struct super_
3615                            &journal_ioprio, NULL, 0))
3616                 goto failed_mount;
3617  
3618 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3619 +               sb->s_flags |= MS_TAGGED;
3620 +
3621         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3622                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3623  
3624 @@ -3160,6 +3181,13 @@ static int ext4_remount(struct super_blo
3625         if (sbi->s_mount_opt & EXT4_MOUNT_ABORT)
3626                 ext4_abort(sb, __func__, "Abort forced by user");
3627  
3628 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3629 +               !(sb->s_flags & MS_TAGGED)) {
3630 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3631 +                       sb->s_id);
3632 +               return -EINVAL;
3633 +       }
3634 +
3635         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3636                 ((sbi->s_mount_opt & EXT4_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
3637  
3638 diff -NurpP --minimal linux-2.6.29.4/fs/ext4/symlink.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/symlink.c
3639 --- linux-2.6.29.4/fs/ext4/symlink.c    2008-12-25 00:26:37.000000000 +0100
3640 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/symlink.c      2009-02-22 22:54:25.000000000 +0100
3641 @@ -40,6 +40,7 @@ const struct inode_operations ext4_symli
3642         .listxattr      = ext4_listxattr,
3643         .removexattr    = generic_removexattr,
3644  #endif
3645 +       .sync_flags     = ext4_sync_flags,
3646  };
3647  
3648  const struct inode_operations ext4_fast_symlink_inode_operations = {
3649 @@ -51,4 +52,5 @@ const struct inode_operations ext4_fast_
3650         .listxattr      = ext4_listxattr,
3651         .removexattr    = generic_removexattr,
3652  #endif
3653 +       .sync_flags     = ext4_sync_flags,
3654  };
3655 diff -NurpP --minimal linux-2.6.29.4/fs/ext4/xattr.c linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/xattr.c
3656 --- linux-2.6.29.4/fs/ext4/xattr.c      2009-03-24 14:22:25.000000000 +0100
3657 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ext4/xattr.c        2009-03-24 15:47:44.000000000 +0100
3658 @@ -56,6 +56,7 @@
3659  #include <linux/mbcache.h>
3660  #include <linux/quotaops.h>
3661  #include <linux/rwsem.h>
3662 +#include <linux/vs_dlimit.h>
3663  #include "ext4_jbd2.h"
3664  #include "ext4.h"
3665  #include "xattr.h"
3666 @@ -490,6 +491,7 @@ ext4_xattr_release_block(handle_t *handl
3667                 error = ext4_handle_dirty_metadata(handle, inode, bh);
3668                 if (IS_SYNC(inode))
3669                         ext4_handle_sync(handle);
3670 +               DLIMIT_FREE_BLOCK(inode, 1);
3671                 DQUOT_FREE_BLOCK(inode, 1);
3672                 ea_bdebug(bh, "refcount now=%d; releasing",
3673                           le32_to_cpu(BHDR(bh)->h_refcount));
3674 @@ -781,11 +783,14 @@ inserted:
3675                         if (new_bh == bs->bh)
3676                                 ea_bdebug(new_bh, "keeping");
3677                         else {
3678 +                               error = -ENOSPC;
3679 +                               if (DLIMIT_ALLOC_BLOCK(inode, 1))
3680 +                                       goto cleanup;
3681                                 /* The old block is released after updating
3682                                    the inode. */
3683                                 error = -EDQUOT;
3684                                 if (DQUOT_ALLOC_BLOCK(inode, 1))
3685 -                                       goto cleanup;
3686 +                                       goto cleanup_dlimit;
3687                                 error = ext4_journal_get_write_access(handle,
3688                                                                       new_bh);
3689                                 if (error)
3690 @@ -861,6 +866,8 @@ cleanup:
3691  
3692  cleanup_dquot:
3693         DQUOT_FREE_BLOCK(inode, 1);
3694 +cleanup_dlimit:
3695 +       DLIMIT_FREE_BLOCK(inode, 1);
3696         goto cleanup;
3697  
3698  bad_block:
3699 diff -NurpP --minimal linux-2.6.29.4/fs/fcntl.c linux-2.6.29.4-vs2.3.0.36.14/fs/fcntl.c
3700 --- linux-2.6.29.4/fs/fcntl.c   2009-05-23 23:16:52.000000000 +0200
3701 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/fcntl.c     2009-05-23 23:19:11.000000000 +0200
3702 @@ -20,6 +20,7 @@
3703  #include <linux/rcupdate.h>
3704  #include <linux/pid_namespace.h>
3705  #include <linux/smp_lock.h>
3706 +#include <linux/vs_limit.h>
3707  
3708  #include <asm/poll.h>
3709  #include <asm/siginfo.h>
3710 @@ -103,6 +104,8 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldf
3711  
3712         if (tofree)
3713                 filp_close(tofree, files);
3714 +       else
3715 +               vx_openfd_inc(newfd);   /* fd was unused */
3716  
3717         return newfd;
3718  
3719 @@ -345,6 +348,8 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd,
3720         filp = fget(fd);
3721         if (!filp)
3722                 goto out;
3723 +       if (!vx_files_avail(1))
3724 +               goto out;
3725  
3726         err = security_file_fcntl(filp, cmd, arg);
3727         if (err) {
3728 diff -NurpP --minimal linux-2.6.29.4/fs/file.c linux-2.6.29.4-vs2.3.0.36.14/fs/file.c
3729 --- linux-2.6.29.4/fs/file.c    2008-12-25 00:26:37.000000000 +0100
3730 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/file.c      2009-02-22 22:54:25.000000000 +0100
3731 @@ -19,6 +19,7 @@
3732  #include <linux/spinlock.h>
3733  #include <linux/rcupdate.h>
3734  #include <linux/workqueue.h>
3735 +#include <linux/vs_limit.h>
3736  
3737  struct fdtable_defer {
3738         spinlock_t lock;
3739 @@ -367,6 +368,8 @@ struct files_struct *dup_fd(struct files
3740                 struct file *f = *old_fds++;
3741                 if (f) {
3742                         get_file(f);
3743 +                       /* TODO: sum it first for check and performance */
3744 +                       vx_openfd_inc(open_files - i);
3745                 } else {
3746                         /*
3747                          * The fd may be claimed in the fd bitmap but not yet
3748 @@ -475,6 +478,7 @@ repeat:
3749         else
3750                 FD_CLR(fd, fdt->close_on_exec);
3751         error = fd;
3752 +       vx_openfd_inc(fd);
3753  #if 1
3754         /* Sanity check */
3755         if (rcu_dereference(fdt->fd[fd]) != NULL) {
3756 diff -NurpP --minimal linux-2.6.29.4/fs/file_table.c linux-2.6.29.4-vs2.3.0.36.14/fs/file_table.c
3757 --- linux-2.6.29.4/fs/file_table.c      2009-03-24 14:22:25.000000000 +0100
3758 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/file_table.c        2009-03-24 14:48:35.000000000 +0100
3759 @@ -21,6 +21,8 @@
3760  #include <linux/fsnotify.h>
3761  #include <linux/sysctl.h>
3762  #include <linux/percpu_counter.h>
3763 +#include <linux/vs_limit.h>
3764 +#include <linux/vs_context.h>
3765  
3766  #include <asm/atomic.h>
3767  
3768 @@ -129,6 +131,8 @@ struct file *get_empty_filp(void)
3769         f->f_cred = get_cred(cred);
3770         eventpoll_init_file(f);
3771         /* f->f_version: 0 */
3772 +       f->f_xid = vx_current_xid();
3773 +       vx_files_inc(f);
3774         return f;
3775  
3776  over:
3777 @@ -283,6 +287,8 @@ void __fput(struct file *file)
3778                 cdev_put(inode->i_cdev);
3779         fops_put(file->f_op);
3780         put_pid(file->f_owner.pid);
3781 +       vx_files_dec(file);
3782 +       file->f_xid = 0;
3783         file_kill(file);
3784         if (file->f_mode & FMODE_WRITE)
3785                 drop_file_write_access(file);
3786 @@ -350,6 +356,8 @@ void put_filp(struct file *file)
3787  {
3788         if (atomic_long_dec_and_test(&file->f_count)) {
3789                 security_file_free(file);
3790 +               vx_files_dec(file);
3791 +               file->f_xid = 0;
3792                 file_kill(file);
3793                 file_free(file);
3794         }
3795 diff -NurpP --minimal linux-2.6.29.4/fs/fs_struct.c linux-2.6.29.4-vs2.3.0.36.14/fs/fs_struct.c
3796 --- linux-2.6.29.4/fs/fs_struct.c       2009-05-23 23:16:52.000000000 +0200
3797 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/fs_struct.c 2009-05-20 01:29:56.000000000 +0200
3798 @@ -3,6 +3,7 @@
3799  #include <linux/fs.h>
3800  #include <linux/path.h>
3801  #include <linux/slab.h>
3802 +#include <linux/vserver/global.h>
3803  
3804  /*
3805   * Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values.
3806 @@ -76,6 +77,7 @@ void free_fs_struct(struct fs_struct *fs
3807  {
3808         path_put(&fs->root);
3809         path_put(&fs->pwd);
3810 +       atomic_dec(&vs_global_fs);
3811         kmem_cache_free(fs_cachep, fs);
3812  }
3813  
3814 @@ -111,6 +113,7 @@ struct fs_struct *copy_fs_struct(struct 
3815                 fs->pwd = old->pwd;
3816                 path_get(&old->pwd);
3817                 read_unlock(&old->lock);
3818 +               atomic_inc(&vs_global_fs);
3819         }
3820         return fs;
3821  }
3822 diff -NurpP --minimal linux-2.6.29.4/fs/hfsplus/ioctl.c linux-2.6.29.4-vs2.3.0.36.14/fs/hfsplus/ioctl.c
3823 --- linux-2.6.29.4/fs/hfsplus/ioctl.c   2008-12-25 00:26:37.000000000 +0100
3824 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/hfsplus/ioctl.c     2009-02-22 22:54:25.000000000 +0100
3825 @@ -17,6 +17,7 @@
3826  #include <linux/mount.h>
3827  #include <linux/sched.h>
3828  #include <linux/xattr.h>
3829 +#include <linux/mount.h>
3830  #include <asm/uaccess.h>
3831  #include "hfsplus_fs.h"
3832  
3833 diff -NurpP --minimal linux-2.6.29.4/fs/inode.c linux-2.6.29.4-vs2.3.0.36.14/fs/inode.c
3834 --- linux-2.6.29.4/fs/inode.c   2009-03-24 14:22:26.000000000 +0100
3835 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/inode.c     2009-03-25 00:51:55.000000000 +0100
3836 @@ -126,6 +126,9 @@ struct inode *inode_init_always(struct s
3837         struct address_space * const mapping = &inode->i_data;
3838  
3839         inode->i_sb = sb;
3840 +
3841 +       /* essential because of inode slab reuse */
3842 +       inode->i_tag = 0;
3843         inode->i_blkbits = sb->s_blocksize_bits;
3844         inode->i_flags = 0;
3845         atomic_set(&inode->i_count, 1);
3846 @@ -146,6 +149,7 @@ struct inode *inode_init_always(struct s
3847         inode->i_bdev = NULL;
3848         inode->i_cdev = NULL;
3849         inode->i_rdev = 0;
3850 +       inode->i_mdev = 0;
3851         inode->dirtied_when = 0;
3852         if (security_inode_alloc(inode)) {
3853                 if (inode->i_sb->s_op->destroy_inode)
3854 @@ -267,6 +271,8 @@ void __iget(struct inode * inode)
3855         inodes_stat.nr_unused--;
3856  }
3857  
3858 +EXPORT_SYMBOL_GPL(__iget);
3859 +
3860  /**
3861   * clear_inode - clear an inode
3862   * @inode: inode to clear
3863 @@ -1539,9 +1545,11 @@ void init_special_inode(struct inode *in
3864         if (S_ISCHR(mode)) {
3865                 inode->i_fop = &def_chr_fops;
3866                 inode->i_rdev = rdev;
3867 +               inode->i_mdev = rdev;
3868         } else if (S_ISBLK(mode)) {
3869                 inode->i_fop = &def_blk_fops;
3870                 inode->i_rdev = rdev;
3871 +               inode->i_mdev = rdev;
3872         } else if (S_ISFIFO(mode))
3873                 inode->i_fop = &def_fifo_fops;
3874         else if (S_ISSOCK(mode))
3875 diff -NurpP --minimal linux-2.6.29.4/fs/ioctl.c linux-2.6.29.4-vs2.3.0.36.14/fs/ioctl.c
3876 --- linux-2.6.29.4/fs/ioctl.c   2009-05-23 23:16:52.000000000 +0200
3877 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ioctl.c     2009-05-23 23:19:11.000000000 +0200
3878 @@ -15,6 +15,9 @@
3879  #include <linux/uaccess.h>
3880  #include <linux/writeback.h>
3881  #include <linux/buffer_head.h>
3882 +#include <linux/proc_fs.h>
3883 +#include <linux/vserver/inode.h>
3884 +#include <linux/vs_tag.h>
3885  
3886  #include <asm/ioctls.h>
3887  
3888 diff -NurpP --minimal linux-2.6.29.4/fs/ioprio.c linux-2.6.29.4-vs2.3.0.36.14/fs/ioprio.c
3889 --- linux-2.6.29.4/fs/ioprio.c  2009-03-24 14:22:26.000000000 +0100
3890 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ioprio.c    2009-03-24 14:48:35.000000000 +0100
3891 @@ -26,6 +26,7 @@
3892  #include <linux/syscalls.h>
3893  #include <linux/security.h>
3894  #include <linux/pid_namespace.h>
3895 +#include <linux/vs_base.h>
3896  
3897  int set_task_ioprio(struct task_struct *task, int ioprio)
3898  {
3899 @@ -123,6 +124,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which, 
3900                         else
3901                                 pgrp = find_vpid(who);
3902                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3903 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3904 +                                       continue;
3905                                 ret = set_task_ioprio(p, ioprio);
3906                                 if (ret)
3907                                         break;
3908 @@ -212,6 +215,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which, 
3909                         else
3910                                 pgrp = find_vpid(who);
3911                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3912 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3913 +                                       continue;
3914                                 tmpio = get_task_ioprio(p);
3915                                 if (tmpio < 0)
3916                                         continue;
3917 diff -NurpP --minimal linux-2.6.29.4/fs/jfs/acl.c linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/acl.c
3918 --- linux-2.6.29.4/fs/jfs/acl.c 2008-12-25 00:26:37.000000000 +0100
3919 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/acl.c   2009-02-22 22:54:25.000000000 +0100
3920 @@ -232,7 +232,8 @@ int jfs_setattr(struct dentry *dentry, s
3921                 return rc;
3922  
3923         if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
3924 -           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
3925 +           (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid) ||
3926 +           (iattr->ia_valid & ATTR_TAG && iattr->ia_tag != inode->i_tag)) {
3927                 if (DQUOT_TRANSFER(inode, iattr))
3928                         return -EDQUOT;
3929         }
3930 diff -NurpP --minimal linux-2.6.29.4/fs/jfs/file.c linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/file.c
3931 --- linux-2.6.29.4/fs/jfs/file.c        2008-12-25 00:26:37.000000000 +0100
3932 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/file.c  2009-02-22 22:54:25.000000000 +0100
3933 @@ -98,6 +98,7 @@ const struct inode_operations jfs_file_i
3934         .setattr        = jfs_setattr,
3935         .permission     = jfs_permission,
3936  #endif
3937 +       .sync_flags     = jfs_sync_flags,
3938  };
3939  
3940  const struct file_operations jfs_file_operations = {
3941 diff -NurpP --minimal linux-2.6.29.4/fs/jfs/inode.c linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/inode.c
3942 --- linux-2.6.29.4/fs/jfs/inode.c       2009-03-24 14:22:26.000000000 +0100
3943 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/inode.c 2009-03-24 14:48:35.000000000 +0100
3944 @@ -22,6 +22,7 @@
3945  #include <linux/buffer_head.h>
3946  #include <linux/pagemap.h>
3947  #include <linux/quotaops.h>
3948 +#include <linux/vs_dlimit.h>
3949  #include "jfs_incore.h"
3950  #include "jfs_inode.h"
3951  #include "jfs_filsys.h"
3952 @@ -161,6 +162,7 @@ void jfs_delete_inode(struct inode *inod
3953                 DQUOT_INIT(inode);
3954                 DQUOT_FREE_INODE(inode);
3955                 DQUOT_DROP(inode);
3956 +               DLIMIT_FREE_INODE(inode);
3957         }
3958  
3959         clear_inode(inode);
3960 diff -NurpP --minimal linux-2.6.29.4/fs/jfs/ioctl.c linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/ioctl.c
3961 --- linux-2.6.29.4/fs/jfs/ioctl.c       2008-12-25 00:26:37.000000000 +0100
3962 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/ioctl.c 2009-02-22 22:54:25.000000000 +0100
3963 @@ -11,6 +11,7 @@
3964  #include <linux/mount.h>
3965  #include <linux/time.h>
3966  #include <linux/sched.h>
3967 +#include <linux/mount.h>
3968  #include <asm/current.h>
3969  #include <asm/uaccess.h>
3970  
3971 @@ -85,6 +86,11 @@ long jfs_ioctl(struct file *filp, unsign
3972                 if (!S_ISDIR(inode->i_mode))
3973                         flags &= ~JFS_DIRSYNC_FL;
3974  
3975 +               if (IS_BARRIER(inode)) {
3976 +                       vxwprintk_task(1, "messing with the barrier.");
3977 +                       return -EACCES;
3978 +               }
3979 +
3980                 /* Is it quota file? Do not allow user to mess with it */
3981                 if (IS_NOQUOTA(inode)) {
3982                         err = -EPERM;
3983 @@ -102,8 +108,8 @@ long jfs_ioctl(struct file *filp, unsign
3984                  * the relevant capability.
3985                  */
3986                 if ((oldflags & JFS_IMMUTABLE_FL) ||
3987 -                       ((flags ^ oldflags) &
3988 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3989 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
3990 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3991                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3992                                 mutex_unlock(&inode->i_mutex);
3993                                 err = -EPERM;
3994 diff -NurpP --minimal linux-2.6.29.4/fs/jfs/jfs_dinode.h linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/jfs_dinode.h
3995 --- linux-2.6.29.4/fs/jfs/jfs_dinode.h  2008-12-25 00:26:37.000000000 +0100
3996 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/jfs_dinode.h    2009-02-22 22:54:25.000000000 +0100
3997 @@ -161,9 +161,13 @@ struct dinode {
3998  
3999  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
4000  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
4001 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
4002  
4003 -#define JFS_FL_USER_VISIBLE    0x03F80000
4004 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
4005 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
4006 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
4007 +
4008 +#define JFS_FL_USER_VISIBLE    0x07F80000
4009 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
4010  #define JFS_FL_INHERIT         0x03C80000
4011  
4012  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
4013 diff -NurpP --minimal linux-2.6.29.4/fs/jfs/jfs_dtree.c linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/jfs_dtree.c
4014 --- linux-2.6.29.4/fs/jfs/jfs_dtree.c   2008-12-25 00:26:37.000000000 +0100
4015 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/jfs_dtree.c     2009-02-22 22:54:25.000000000 +0100
4016 @@ -102,6 +102,7 @@
4017  
4018  #include <linux/fs.h>
4019  #include <linux/quotaops.h>
4020 +#include <linux/vs_dlimit.h>
4021  #include "jfs_incore.h"
4022  #include "jfs_superblock.h"
4023  #include "jfs_filsys.h"
4024 @@ -383,10 +384,10 @@ static u32 add_index(tid_t tid, struct i
4025                  */
4026                 if (DQUOT_ALLOC_BLOCK(ip, sbi->nbperpage))
4027                         goto clean_up;
4028 -               if (dbAlloc(ip, 0, sbi->nbperpage, &xaddr)) {
4029 -                       DQUOT_FREE_BLOCK(ip, sbi->nbperpage);
4030 -                       goto clean_up;
4031 -               }
4032 +               if (DLIMIT_ALLOC_BLOCK(ip, sbi->nbperpage))
4033 +                       goto clean_up_dquot;
4034 +               if (dbAlloc(ip, 0, sbi->nbperpage, &xaddr))
4035 +                       goto clean_up_dlimit;
4036  
4037                 /*
4038                  * Save the table, we're going to overwrite it with the
4039 @@ -480,6 +481,12 @@ static u32 add_index(tid_t tid, struct i
4040  
4041         return index;
4042  
4043 +      clean_up_dlimit:
4044 +       DLIMIT_FREE_BLOCK(ip, sbi->nbperpage);
4045 +
4046 +      clean_up_dquot:
4047 +       DQUOT_FREE_BLOCK(ip, sbi->nbperpage);
4048 +
4049        clean_up:
4050  
4051         jfs_ip->next_index--;
4052 @@ -951,6 +958,7 @@ static int dtSplitUp(tid_t tid,
4053         struct tlock *tlck;
4054         struct lv *lv;
4055         int quota_allocation = 0;
4056 +       int dlimit_allocation = 0;
4057  
4058         /* get split page */
4059         smp = split->mp;
4060 @@ -1033,6 +1041,12 @@ static int dtSplitUp(tid_t tid,
4061                 }
4062                 quota_allocation += n;
4063  
4064 +               if (DLIMIT_ALLOC_BLOCK(ip, n)) {
4065 +                       rc = -ENOSPC;
4066 +                       goto extendOut;
4067 +               }
4068 +               dlimit_allocation += n;
4069 +
4070                 if ((rc = dbReAlloc(sbi->ipbmap, xaddr, (s64) xlen,
4071                                     (s64) n, &nxaddr)))
4072                         goto extendOut;
4073 @@ -1306,6 +1320,9 @@ static int dtSplitUp(tid_t tid,
4074        freeKeyName:
4075         kfree(key.name);
4076  
4077 +       /* Rollback dlimit allocation */
4078 +       if (rc && dlimit_allocation)
4079 +               DLIMIT_FREE_BLOCK(ip, dlimit_allocation);
4080         /* Rollback quota allocation */
4081         if (rc && quota_allocation)
4082                 DQUOT_FREE_BLOCK(ip, quota_allocation);
4083 @@ -1373,6 +1390,12 @@ static int dtSplitPage(tid_t tid, struct
4084                 release_metapage(rmp);
4085                 return -EDQUOT;
4086         }
4087 +       /* Allocate blocks to dlimit. */
4088 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
4089 +               DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
4090 +               release_metapage(rmp);
4091 +               return -ENOSPC;
4092 +       }
4093  
4094         jfs_info("dtSplitPage: ip:0x%p smp:0x%p rmp:0x%p", ip, smp, rmp);
4095  
4096 @@ -1920,6 +1943,12 @@ static int dtSplitRoot(tid_t tid,
4097                 release_metapage(rmp);
4098                 return -EDQUOT;
4099         }
4100 +       /* Allocate blocks to dlimit. */
4101 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
4102 +               DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
4103 +               release_metapage(rmp);
4104 +               return -ENOSPC;
4105 +       }
4106  
4107         BT_MARK_DIRTY(rmp, ip);
4108         /*
4109 @@ -2286,6 +2315,8 @@ static int dtDeleteUp(tid_t tid, struct 
4110  
4111         xlen = lengthPXD(&fp->header.self);
4112  
4113 +       /* Free dlimit allocation. */
4114 +       DLIMIT_FREE_BLOCK(ip, xlen);
4115         /* Free quota allocation. */
4116         DQUOT_FREE_BLOCK(ip, xlen);
4117  
4118 @@ -2362,6 +2393,8 @@ static int dtDeleteUp(tid_t tid, struct 
4119  
4120                                 xlen = lengthPXD(&p->header.self);
4121  
4122 +                               /* Free dlimit allocation */
4123 +                               DLIMIT_FREE_BLOCK(ip, xlen);
4124                                 /* Free quota allocation */
4125                                 DQUOT_FREE_BLOCK(ip, xlen);
4126  
4127 diff -NurpP --minimal linux-2.6.29.4/fs/jfs/jfs_extent.c linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/jfs_extent.c
4128 --- linux-2.6.29.4/fs/jfs/jfs_extent.c  2008-12-25 00:26:37.000000000 +0100
4129 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/jfs_extent.c    2009-02-22 22:54:25.000000000 +0100
4130 @@ -18,6 +18,7 @@
4131  
4132  #include <linux/fs.h>
4133  #include <linux/quotaops.h>
4134 +#include <linux/vs_dlimit.h>
4135  #include "jfs_incore.h"
4136  #include "jfs_inode.h"
4137  #include "jfs_superblock.h"
4138 @@ -147,6 +148,14 @@ extAlloc(struct inode *ip, s64 xlen, s64
4139                 return -EDQUOT;
4140         }
4141  
4142 +       /* Allocate blocks to dlimit. */
4143 +       if (DLIMIT_ALLOC_BLOCK(ip, nxlen)) {
4144 +               DQUOT_FREE_BLOCK(ip, nxlen);
4145 +               dbFree(ip, nxaddr, (s64) nxlen);
4146 +               mutex_unlock(&JFS_IP(ip)->commit_mutex);
4147 +               return -ENOSPC;
4148 +       }
4149 +
4150         /* determine the value of the extent flag */
4151         xflag = abnr ? XAD_NOTRECORDED : 0;
4152  
4153 @@ -164,6 +173,7 @@ extAlloc(struct inode *ip, s64 xlen, s64
4154          */
4155         if (rc) {
4156                 dbFree(ip, nxaddr, nxlen);
4157 +               DLIMIT_FREE_BLOCK(ip, nxlen);
4158                 DQUOT_FREE_BLOCK(ip, nxlen);
4159                 mutex_unlock(&JFS_IP(ip)->commit_mutex);
4160                 return (rc);
4161 @@ -261,6 +271,13 @@ int extRealloc(struct inode *ip, s64 nxl
4162                 mutex_unlock(&JFS_IP(ip)->commit_mutex);
4163                 return -EDQUOT;
4164         }
4165 +       /* Allocate blocks to dlimit. */
4166 +       if (DLIMIT_ALLOC_BLOCK(ip, nxlen)) {
4167 +               DQUOT_FREE_BLOCK(ip, nxlen);
4168 +               dbFree(ip, nxaddr, (s64) nxlen);
4169 +               up(&JFS_IP(ip)->commit_sem);
4170 +               return -ENOSPC;
4171 +       }
4172  
4173         delta = nxlen - xlen;
4174  
4175 @@ -297,6 +314,7 @@ int extRealloc(struct inode *ip, s64 nxl
4176                 /* extend the extent */
4177                 if ((rc = xtExtend(0, ip, xoff + xlen, (int) nextend, 0))) {
4178                         dbFree(ip, xaddr + xlen, delta);
4179 +                       DLIMIT_FREE_BLOCK(ip, nxlen);
4180                         DQUOT_FREE_BLOCK(ip, nxlen);
4181                         goto exit;
4182                 }
4183 @@ -308,6 +326,7 @@ int extRealloc(struct inode *ip, s64 nxl
4184                  */
4185                 if ((rc = xtTailgate(0, ip, xoff, (int) ntail, nxaddr, 0))) {
4186                         dbFree(ip, nxaddr, nxlen);
4187 +                       DLIMIT_FREE_BLOCK(ip, nxlen);
4188                         DQUOT_FREE_BLOCK(ip, nxlen);
4189                         goto exit;
4190                 }
4191 diff -NurpP --minimal linux-2.6.29.4/fs/jfs/jfs_filsys.h linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/jfs_filsys.h
4192 --- linux-2.6.29.4/fs/jfs/jfs_filsys.h  2008-12-25 00:26:37.000000000 +0100
4193 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/jfs_filsys.h    2009-02-22 22:54:25.000000000 +0100
4194 @@ -263,6 +263,7 @@
4195  #define JFS_NAME_MAX   255
4196  #define JFS_PATH_MAX   BPSIZE
4197  
4198 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
4199  
4200  /*
4201   *     file system state (superblock state)
4202 diff -NurpP --minimal linux-2.6.29.4/fs/jfs/jfs_imap.c linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/jfs_imap.c
4203 --- linux-2.6.29.4/fs/jfs/jfs_imap.c    2009-03-24 14:22:26.000000000 +0100
4204 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/jfs_imap.c      2009-03-24 14:48:35.000000000 +0100
4205 @@ -45,6 +45,7 @@
4206  #include <linux/buffer_head.h>
4207  #include <linux/pagemap.h>
4208  #include <linux/quotaops.h>
4209 +#include <linux/vs_tag.h>
4210  
4211  #include "jfs_incore.h"
4212  #include "jfs_inode.h"
4213 @@ -3062,6 +3063,8 @@ static int copy_from_dinode(struct dinod
4214  {
4215         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
4216         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
4217 +       uid_t uid;
4218 +       gid_t gid;
4219  
4220         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
4221         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
4222 @@ -3082,14 +3085,18 @@ static int copy_from_dinode(struct dinod
4223         }
4224         ip->i_nlink = le32_to_cpu(dip->di_nlink);
4225  
4226 -       jfs_ip->saved_uid = le32_to_cpu(dip->di_uid);
4227 +       uid = le32_to_cpu(dip->di_uid);
4228 +       gid = le32_to_cpu(dip->di_gid);
4229 +       ip->i_tag = INOTAG_TAG(DX_TAG(ip), uid, gid, 0);
4230 +
4231 +       jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
4232         if (sbi->uid == -1)
4233                 ip->i_uid = jfs_ip->saved_uid;
4234         else {
4235                 ip->i_uid = sbi->uid;
4236         }
4237  
4238 -       jfs_ip->saved_gid = le32_to_cpu(dip->di_gid);
4239 +       jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
4240         if (sbi->gid == -1)
4241                 ip->i_gid = jfs_ip->saved_gid;
4242         else {
4243 @@ -3154,14 +3161,12 @@ static void copy_to_dinode(struct dinode
4244         dip->di_size = cpu_to_le64(ip->i_size);
4245         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
4246         dip->di_nlink = cpu_to_le32(ip->i_nlink);
4247 -       if (sbi->uid == -1)
4248 -               dip->di_uid = cpu_to_le32(ip->i_uid);
4249 -       else
4250 -               dip->di_uid = cpu_to_le32(jfs_ip->saved_uid);
4251 -       if (sbi->gid == -1)
4252 -               dip->di_gid = cpu_to_le32(ip->i_gid);
4253 -       else
4254 -               dip->di_gid = cpu_to_le32(jfs_ip->saved_gid);
4255 +
4256 +       dip->di_uid = cpu_to_le32(TAGINO_UID(DX_TAG(ip),
4257 +               (sbi->uid == -1) ? ip->i_uid : jfs_ip->saved_uid, ip->i_tag));
4258 +       dip->di_gid = cpu_to_le32(TAGINO_GID(DX_TAG(ip),
4259 +               (sbi->gid == -1) ? ip->i_gid : jfs_ip->saved_gid, ip->i_tag));
4260 +
4261         jfs_get_inode_flags(jfs_ip);
4262         /*
4263          * mode2 is only needed for storing the higher order bits.
4264 diff -NurpP --minimal linux-2.6.29.4/fs/jfs/jfs_inode.c linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/jfs_inode.c
4265 --- linux-2.6.29.4/fs/jfs/jfs_inode.c   2009-03-24 14:22:26.000000000 +0100
4266 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/jfs_inode.c     2009-03-24 15:58:01.000000000 +0100
4267 @@ -18,6 +18,8 @@
4268  
4269  #include <linux/fs.h>
4270  #include <linux/quotaops.h>
4271 +#include <linux/vs_dlimit.h>
4272 +#include <linux/vs_tag.h>
4273  #include "jfs_incore.h"
4274  #include "jfs_inode.h"
4275  #include "jfs_filsys.h"
4276 @@ -30,29 +32,46 @@ void jfs_set_inode_flags(struct inode *i
4277  {
4278         unsigned int flags = JFS_IP(inode)->mode2;
4279  
4280 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
4281 -               S_NOATIME | S_DIRSYNC | S_SYNC);
4282 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
4283 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
4284  
4285         if (flags & JFS_IMMUTABLE_FL)
4286                 inode->i_flags |= S_IMMUTABLE;
4287 +       if (flags & JFS_IXUNLINK_FL)
4288 +               inode->i_flags |= S_IXUNLINK;
4289 +
4290 +       if (flags & JFS_SYNC_FL)
4291 +               inode->i_flags |= S_SYNC;
4292         if (flags & JFS_APPEND_FL)
4293                 inode->i_flags |= S_APPEND;
4294         if (flags & JFS_NOATIME_FL)
4295                 inode->i_flags |= S_NOATIME;
4296         if (flags & JFS_DIRSYNC_FL)
4297                 inode->i_flags |= S_DIRSYNC;
4298 -       if (flags & JFS_SYNC_FL)
4299 -               inode->i_flags |= S_SYNC;
4300 +
4301 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
4302 +
4303 +       if (flags & JFS_BARRIER_FL)
4304 +               inode->i_vflags |= V_BARRIER;
4305 +       if (flags & JFS_COW_FL)
4306 +               inode->i_vflags |= V_COW;
4307  }
4308  
4309  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
4310  {
4311         unsigned int flags = jfs_ip->vfs_inode.i_flags;
4312 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
4313 +
4314 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
4315 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
4316 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
4317 +                          JFS_BARRIER_FL | JFS_COW_FL);
4318  
4319 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
4320 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
4321         if (flags & S_IMMUTABLE)
4322                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
4323 +       if (flags & S_IXUNLINK)
4324 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
4325 +
4326         if (flags & S_APPEND)
4327                 jfs_ip->mode2 |= JFS_APPEND_FL;
4328         if (flags & S_NOATIME)
4329 @@ -61,6 +80,19 @@ void jfs_get_inode_flags(struct jfs_inod
4330                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
4331         if (flags & S_SYNC)
4332                 jfs_ip->mode2 |= JFS_SYNC_FL;
4333 +
4334 +       if (vflags & V_BARRIER)
4335 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
4336 +       if (vflags & V_COW)
4337 +               jfs_ip->mode2 |= JFS_COW_FL;
4338 +}
4339 +
4340 +int jfs_sync_flags(struct inode *inode)
4341 +{
4342 +       jfs_get_inode_flags(JFS_IP(inode));
4343 +       inode->i_ctime = CURRENT_TIME;
4344 +       mark_inode_dirty(inode);
4345 +       return 0;
4346  }
4347  
4348  /*
4349 @@ -113,6 +145,12 @@ struct inode *ialloc(struct inode *paren
4350         jfs_inode->saved_uid = inode->i_uid;
4351         jfs_inode->saved_gid = inode->i_gid;
4352  
4353 +       inode->i_tag = dx_current_fstag(sb);
4354 +       if (DLIMIT_ALLOC_INODE(inode)) {
4355 +               rc = -ENOSPC;
4356 +               goto fail_drop2;
4357 +       }
4358 +
4359         /*
4360          * Allocate inode to quota.
4361          */
4362 @@ -162,6 +200,8 @@ struct inode *ialloc(struct inode *paren
4363         return inode;
4364  
4365  fail_drop:
4366 +       DLIMIT_FREE_INODE(inode);
4367 +fail_drop2:
4368         DQUOT_DROP(inode);
4369         inode->i_flags |= S_NOQUOTA;
4370  fail_unlock:
4371 diff -NurpP --minimal linux-2.6.29.4/fs/jfs/jfs_inode.h linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/jfs_inode.h
4372 --- linux-2.6.29.4/fs/jfs/jfs_inode.h   2008-12-25 00:26:37.000000000 +0100
4373 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/jfs_inode.h     2009-02-22 22:54:25.000000000 +0100
4374 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
4375  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
4376         int fh_len, int fh_type);
4377  extern void jfs_set_inode_flags(struct inode *);
4378 +extern int jfs_sync_flags(struct inode *);
4379  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
4380  
4381  extern const struct address_space_operations jfs_aops;
4382 diff -NurpP --minimal linux-2.6.29.4/fs/jfs/jfs_xtree.c linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/jfs_xtree.c
4383 --- linux-2.6.29.4/fs/jfs/jfs_xtree.c   2008-12-25 00:26:37.000000000 +0100
4384 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/jfs_xtree.c     2009-02-22 22:54:25.000000000 +0100
4385 @@ -23,6 +23,7 @@
4386  #include <linux/module.h>
4387  #include <linux/quotaops.h>
4388  #include <linux/seq_file.h>
4389 +#include <linux/vs_dlimit.h>
4390  #include "jfs_incore.h"
4391  #include "jfs_filsys.h"
4392  #include "jfs_metapage.h"
4393 @@ -848,7 +849,12 @@ int xtInsert(tid_t tid,            /* transaction 
4394                         hint = 0;
4395                 if ((rc = DQUOT_ALLOC_BLOCK(ip, xlen)))
4396                         goto out;
4397 +               if ((rc = DLIMIT_ALLOC_BLOCK(ip, xlen))) {
4398 +                       DQUOT_FREE_BLOCK(ip, xlen);
4399 +                       goto out;
4400 +               }
4401                 if ((rc = dbAlloc(ip, hint, (s64) xlen, &xaddr))) {
4402 +                       DLIMIT_FREE_BLOCK(ip, xlen);
4403                         DQUOT_FREE_BLOCK(ip, xlen);
4404                         goto out;
4405                 }
4406 @@ -878,6 +884,7 @@ int xtInsert(tid_t tid,             /* transaction 
4407                         /* undo data extent allocation */
4408                         if (*xaddrp == 0) {
4409                                 dbFree(ip, xaddr, (s64) xlen);
4410 +                               DLIMIT_FREE_BLOCK(ip, xlen);
4411                                 DQUOT_FREE_BLOCK(ip, xlen);
4412                         }
4413                         return rc;
4414 @@ -1234,6 +1241,7 @@ xtSplitPage(tid_t tid, struct inode *ip,
4415         struct tlock *tlck;
4416         struct xtlock *sxtlck = NULL, *rxtlck = NULL;
4417         int quota_allocation = 0;
4418 +       int dlimit_allocation = 0;
4419  
4420         smp = split->mp;
4421         sp = XT_PAGE(ip, smp);
4422 @@ -1253,6 +1261,13 @@ xtSplitPage(tid_t tid, struct inode *ip,
4423  
4424         quota_allocation += lengthPXD(pxd);
4425  
4426 +       /* Allocate blocks to dlimit. */
4427 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
4428 +              rc = -ENOSPC;
4429 +              goto clean_up;
4430 +       }
4431 +       dlimit_allocation += lengthPXD(pxd);
4432 +
4433         /*
4434          * allocate the new right page for the split
4435          */
4436 @@ -1454,6 +1469,9 @@ xtSplitPage(tid_t tid, struct inode *ip,
4437  
4438        clean_up:
4439  
4440 +       /* Rollback dlimit allocation. */
4441 +       if (dlimit_allocation)
4442 +               DLIMIT_FREE_BLOCK(ip, dlimit_allocation);
4443         /* Rollback quota allocation. */
4444         if (quota_allocation)
4445                 DQUOT_FREE_BLOCK(ip, quota_allocation);
4446 @@ -1517,6 +1535,12 @@ xtSplitRoot(tid_t tid,
4447                 release_metapage(rmp);
4448                 return -EDQUOT;
4449         }
4450 +       /* Allocate blocks to dlimit. */
4451 +       if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
4452 +               DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
4453 +               release_metapage(rmp);
4454 +               return -ENOSPC;
4455 +       }
4456  
4457         jfs_info("xtSplitRoot: ip:0x%p rmp:0x%p", ip, rmp);
4458  
4459 @@ -3940,6 +3964,8 @@ s64 xtTruncate(tid_t tid, struct inode *
4460         else
4461                 ip->i_size = newsize;
4462  
4463 +       /* update dlimit allocation to reflect freed blocks */
4464 +       DLIMIT_FREE_BLOCK(ip, nfreed);
4465         /* update quota allocation to reflect freed blocks */
4466         DQUOT_FREE_BLOCK(ip, nfreed);
4467  
4468 diff -NurpP --minimal linux-2.6.29.4/fs/jfs/namei.c linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/namei.c
4469 --- linux-2.6.29.4/fs/jfs/namei.c       2009-03-24 14:22:26.000000000 +0100
4470 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/namei.c 2009-03-24 14:48:35.000000000 +0100
4471 @@ -21,6 +21,7 @@
4472  #include <linux/ctype.h>
4473  #include <linux/quotaops.h>
4474  #include <linux/exportfs.h>
4475 +#include <linux/vs_tag.h>
4476  #include "jfs_incore.h"
4477  #include "jfs_superblock.h"
4478  #include "jfs_inode.h"
4479 @@ -1476,6 +1477,7 @@ static struct dentry *jfs_lookup(struct 
4480                 return ERR_CAST(ip);
4481         }
4482  
4483 +       dx_propagate_tag(nd, ip);
4484         dentry = d_splice_alias(ip, dentry);
4485  
4486         if (dentry && (JFS_SBI(dip->i_sb)->mntflag & JFS_OS2))
4487 @@ -1545,6 +1547,7 @@ const struct inode_operations jfs_dir_in
4488         .setattr        = jfs_setattr,
4489         .permission     = jfs_permission,
4490  #endif
4491 +       .sync_flags     = jfs_sync_flags,
4492  };
4493  
4494  const struct file_operations jfs_dir_operations = {
4495 diff -NurpP --minimal linux-2.6.29.4/fs/jfs/super.c linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/super.c
4496 --- linux-2.6.29.4/fs/jfs/super.c       2009-03-24 14:22:26.000000000 +0100
4497 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/super.c 2009-03-24 14:48:35.000000000 +0100
4498 @@ -196,7 +196,8 @@ static void jfs_put_super(struct super_b
4499  enum {
4500         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4501         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4502 -       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask
4503 +       Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4504 +       Opt_tag, Opt_notag, Opt_tagid
4505  };
4506  
4507  static const match_table_t tokens = {
4508 @@ -206,6 +207,10 @@ static const match_table_t tokens = {
4509         {Opt_resize, "resize=%u"},
4510         {Opt_resize_nosize, "resize"},
4511         {Opt_errors, "errors=%s"},
4512 +       {Opt_tag, "tag"},
4513 +       {Opt_notag, "notag"},
4514 +       {Opt_tagid, "tagid=%u"},
4515 +       {Opt_tag, "tagxid"},
4516         {Opt_ignore, "noquota"},
4517         {Opt_ignore, "quota"},
4518         {Opt_usrquota, "usrquota"},
4519 @@ -340,6 +345,20 @@ static int parse_options(char *options, 
4520                         }
4521                         break;
4522                 }
4523 +#ifndef CONFIG_TAGGING_NONE
4524 +               case Opt_tag:
4525 +                       *flag |= JFS_TAGGED;
4526 +                       break;
4527 +               case Opt_notag:
4528 +                       *flag &= JFS_TAGGED;
4529 +                       break;
4530 +#endif
4531 +#ifdef CONFIG_PROPAGATE
4532 +               case Opt_tagid:
4533 +                       /* use args[0] */
4534 +                       *flag |= JFS_TAGGED;
4535 +                       break;
4536 +#endif
4537                 default:
4538                         printk("jfs: Unrecognized mount option \"%s\" "
4539                                         " or missing value\n", p);
4540 @@ -370,6 +389,13 @@ static int jfs_remount(struct super_bloc
4541         if (!parse_options(data, sb, &newLVSize, &flag)) {
4542                 return -EINVAL;
4543         }
4544 +
4545 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4546 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4547 +                       sb->s_id);
4548 +               return -EINVAL;
4549 +       }
4550 +
4551         if (newLVSize) {
4552                 if (sb->s_flags & MS_RDONLY) {
4553                         printk(KERN_ERR
4554 @@ -441,6 +467,9 @@ static int jfs_fill_super(struct super_b
4555  #ifdef CONFIG_JFS_POSIX_ACL
4556         sb->s_flags |= MS_POSIXACL;
4557  #endif
4558 +       /* map mount option tagxid */
4559 +       if (sbi->flag & JFS_TAGGED)
4560 +               sb->s_flags |= MS_TAGGED;
4561  
4562         if (newLVSize) {
4563                 printk(KERN_ERR "resize option for remount only\n");
4564 diff -NurpP --minimal linux-2.6.29.4/fs/jfs/xattr.c linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/xattr.c
4565 --- linux-2.6.29.4/fs/jfs/xattr.c       2008-12-25 00:26:37.000000000 +0100
4566 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/jfs/xattr.c 2009-02-22 22:54:25.000000000 +0100
4567 @@ -23,6 +23,7 @@
4568  #include <linux/posix_acl_xattr.h>
4569  #include <linux/quotaops.h>
4570  #include <linux/security.h>
4571 +#include <linux/vs_dlimit.h>
4572  #include "jfs_incore.h"
4573  #include "jfs_superblock.h"
4574  #include "jfs_dmap.h"
4575 @@ -263,9 +264,16 @@ static int ea_write(struct inode *ip, st
4576         if (DQUOT_ALLOC_BLOCK(ip, nblocks)) {
4577                 return -EDQUOT;
4578         }
4579 +       /* Allocate new blocks to dlimit. */
4580 +       if (DLIMIT_ALLOC_BLOCK(ip, nblocks)) {
4581 +               DQUOT_FREE_BLOCK(ip, nblocks);
4582 +               return -ENOSPC;
4583 +       }
4584  
4585         rc = dbAlloc(ip, INOHINT(ip), nblocks, &blkno);
4586         if (rc) {
4587 +               /*Rollback dlimit allocation. */
4588 +               DLIMIT_FREE_BLOCK(ip, nblocks);
4589                 /*Rollback quota allocation. */
4590                 DQUOT_FREE_BLOCK(ip, nblocks);
4591                 return rc;
4592 @@ -332,6 +340,8 @@ static int ea_write(struct inode *ip, st
4593  
4594        failed:
4595         /* Rollback quota allocation. */
4596 +       DLIMIT_FREE_BLOCK(ip, nblocks);
4597 +       /* Rollback quota allocation. */
4598         DQUOT_FREE_BLOCK(ip, nblocks);
4599  
4600         dbFree(ip, blkno, nblocks);
4601 @@ -468,6 +478,7 @@ static int ea_get(struct inode *inode, s
4602         s64 blkno;
4603         int rc;
4604         int quota_allocation = 0;
4605 +       int dlimit_allocation = 0;
4606  
4607         /* When fsck.jfs clears a bad ea, it doesn't clear the size */
4608         if (ji->ea.flag == 0)
4609 @@ -543,6 +554,12 @@ static int ea_get(struct inode *inode, s
4610  
4611                 quota_allocation = blocks_needed;
4612  
4613 +               /* Allocate new blocks to dlimit. */
4614 +               rc = -ENOSPC;
4615 +               if (DLIMIT_ALLOC_BLOCK(inode, blocks_needed))
4616 +                       goto clean_up;
4617 +               dlimit_allocation = blocks_needed;
4618 +
4619                 rc = dbAlloc(inode, INOHINT(inode), (s64) blocks_needed,
4620                              &blkno);
4621                 if (rc)
4622 @@ -600,6 +617,9 @@ static int ea_get(struct inode *inode, s
4623         return ea_size;
4624  
4625        clean_up:
4626 +       /* Rollback dlimit allocation */
4627 +       if (dlimit_allocation)
4628 +               DLIMIT_FREE_BLOCK(inode, dlimit_allocation);
4629         /* Rollback quota allocation */
4630         if (quota_allocation)
4631                 DQUOT_FREE_BLOCK(inode, quota_allocation);
4632 @@ -676,8 +696,10 @@ static int ea_put(tid_t tid, struct inod
4633         }
4634  
4635         /* If old blocks exist, they must be removed from quota allocation. */
4636 -       if (old_blocks)
4637 +       if (old_blocks) {
4638 +               DLIMIT_FREE_BLOCK(inode, old_blocks);
4639                 DQUOT_FREE_BLOCK(inode, old_blocks);
4640 +       }
4641  
4642         inode->i_ctime = CURRENT_TIME;
4643  
4644 diff -NurpP --minimal linux-2.6.29.4/fs/libfs.c linux-2.6.29.4-vs2.3.0.36.14/fs/libfs.c
4645 --- linux-2.6.29.4/fs/libfs.c   2009-03-24 14:22:26.000000000 +0100
4646 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/libfs.c     2009-03-24 14:48:35.000000000 +0100
4647 @@ -125,7 +125,8 @@ static inline unsigned char dt_type(stru
4648   * both impossible due to the lock on directory.
4649   */
4650  
4651 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4652 +static inline int do_dcache_readdir_filter(struct file *filp,
4653 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4654  {
4655         struct dentry *dentry = filp->f_path.dentry;
4656         struct dentry *cursor = filp->private_data;
4657 @@ -158,6 +159,8 @@ int dcache_readdir(struct file * filp, v
4658                                 next = list_entry(p, struct dentry, d_u.d_child);
4659                                 if (d_unhashed(next) || !next->d_inode)
4660                                         continue;
4661 +                               if (filter && !filter(next))
4662 +                                       continue;
4663  
4664                                 spin_unlock(&dcache_lock);
4665                                 if (filldir(dirent, next->d_name.name, 
4666 @@ -176,6 +179,18 @@ int dcache_readdir(struct file * filp, v
4667         return 0;
4668  }
4669  
4670 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4671 +{
4672 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4673 +}
4674 +
4675 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4676 +       int (*filter)(struct dentry *))
4677 +{
4678 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4679 +}
4680 +
4681 +
4682  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4683  {
4684         return -EISDIR;
4685 @@ -796,6 +811,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4686  EXPORT_SYMBOL(dcache_dir_lseek);
4687  EXPORT_SYMBOL(dcache_dir_open);
4688  EXPORT_SYMBOL(dcache_readdir);
4689 +EXPORT_SYMBOL(dcache_readdir_filter);
4690  EXPORT_SYMBOL(generic_read_dir);
4691  EXPORT_SYMBOL(get_sb_pseudo);
4692  EXPORT_SYMBOL(simple_write_begin);
4693 diff -NurpP --minimal linux-2.6.29.4/fs/locks.c linux-2.6.29.4-vs2.3.0.36.14/fs/locks.c
4694 --- linux-2.6.29.4/fs/locks.c   2009-03-24 14:22:26.000000000 +0100
4695 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/locks.c     2009-03-24 14:48:35.000000000 +0100
4696 @@ -127,6 +127,8 @@
4697  #include <linux/time.h>
4698  #include <linux/rcupdate.h>
4699  #include <linux/pid_namespace.h>
4700 +#include <linux/vs_base.h>
4701 +#include <linux/vs_limit.h>
4702  
4703  #include <asm/uaccess.h>
4704  
4705 @@ -148,6 +150,8 @@ static struct kmem_cache *filelock_cache
4706  /* Allocate an empty lock structure. */
4707  static struct file_lock *locks_alloc_lock(void)
4708  {
4709 +       if (!vx_locks_avail(1))
4710 +               return NULL;
4711         return kmem_cache_alloc(filelock_cache, GFP_KERNEL);
4712  }
4713  
4714 @@ -173,6 +177,7 @@ static void locks_free_lock(struct file_
4715         BUG_ON(!list_empty(&fl->fl_block));
4716         BUG_ON(!list_empty(&fl->fl_link));
4717  
4718 +       vx_locks_dec(fl);
4719         locks_release_private(fl);
4720         kmem_cache_free(filelock_cache, fl);
4721  }
4722 @@ -193,6 +198,7 @@ void locks_init_lock(struct file_lock *f
4723         fl->fl_start = fl->fl_end = 0;
4724         fl->fl_ops = NULL;
4725         fl->fl_lmops = NULL;
4726 +       fl->fl_xid = -1;
4727  }
4728  
4729  EXPORT_SYMBOL(locks_init_lock);
4730 @@ -247,6 +253,7 @@ void locks_copy_lock(struct file_lock *n
4731         new->fl_file = fl->fl_file;
4732         new->fl_ops = fl->fl_ops;
4733         new->fl_lmops = fl->fl_lmops;
4734 +       new->fl_xid = fl->fl_xid;
4735  
4736         locks_copy_private(new, fl);
4737  }
4738 @@ -285,6 +292,11 @@ static int flock_make_lock(struct file *
4739         fl->fl_flags = FL_FLOCK;
4740         fl->fl_type = type;
4741         fl->fl_end = OFFSET_MAX;
4742 +
4743 +       vxd_assert(filp->f_xid == vx_current_xid(),
4744 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4745 +       fl->fl_xid = filp->f_xid;
4746 +       vx_locks_inc(fl);
4747         
4748         *lock = fl;
4749         return 0;
4750 @@ -450,6 +462,7 @@ static int lease_init(struct file *filp,
4751  
4752         fl->fl_owner = current->files;
4753         fl->fl_pid = current->tgid;
4754 +       fl->fl_xid = vx_current_xid();
4755  
4756         fl->fl_file = filp;
4757         fl->fl_flags = FL_LEASE;
4758 @@ -469,6 +482,11 @@ static struct file_lock *lease_alloc(str
4759         if (fl == NULL)
4760                 return ERR_PTR(error);
4761  
4762 +       fl->fl_xid = vx_current_xid();
4763 +       if (filp)
4764 +               vxd_assert(filp->f_xid == fl->fl_xid,
4765 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4766 +       vx_locks_inc(fl);
4767         error = lease_init(filp, type, fl);
4768         if (error) {
4769                 locks_free_lock(fl);
4770 @@ -769,6 +787,7 @@ static int flock_lock_file(struct file *
4771         if (found)
4772                 cond_resched_bkl();
4773  
4774 +       new_fl->fl_xid = -1;
4775  find_conflict:
4776         for_each_lock(inode, before) {
4777                 struct file_lock *fl = *before;
4778 @@ -789,6 +808,7 @@ find_conflict:
4779                 goto out;
4780         locks_copy_lock(new_fl, request);
4781         locks_insert_lock(before, new_fl);
4782 +       vx_locks_inc(new_fl);
4783         new_fl = NULL;
4784         error = 0;
4785  
4786 @@ -799,7 +819,8 @@ out:
4787         return error;
4788  }
4789  
4790 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4791 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4792 +       struct file_lock *conflock, xid_t xid)
4793  {
4794         struct file_lock *fl;
4795         struct file_lock *new_fl = NULL;
4796 @@ -809,6 +830,8 @@ static int __posix_lock_file(struct inod
4797         struct file_lock **before;
4798         int error, added = 0;
4799  
4800 +       vxd_assert(xid == vx_current_xid(),
4801 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4802         /*
4803          * We may need two file_lock structures for this operation,
4804          * so we get them in advance to avoid races.
4805 @@ -819,7 +842,11 @@ static int __posix_lock_file(struct inod
4806             (request->fl_type != F_UNLCK ||
4807              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4808                 new_fl = locks_alloc_lock();
4809 +               new_fl->fl_xid = xid;
4810 +               vx_locks_inc(new_fl);
4811                 new_fl2 = locks_alloc_lock();
4812 +               new_fl2->fl_xid = xid;
4813 +               vx_locks_inc(new_fl2);
4814         }
4815  
4816         lock_kernel();
4817 @@ -1018,7 +1045,8 @@ static int __posix_lock_file(struct inod
4818  int posix_lock_file(struct file *filp, struct file_lock *fl,
4819                         struct file_lock *conflock)
4820  {
4821 -       return __posix_lock_file(filp->f_path.dentry->d_inode, fl, conflock);
4822 +       return __posix_lock_file(filp->f_path.dentry->d_inode,
4823 +               fl, conflock, filp->f_xid);
4824  }
4825  EXPORT_SYMBOL(posix_lock_file);
4826  
4827 @@ -1108,7 +1136,7 @@ int locks_mandatory_area(int read_write,
4828         fl.fl_end = offset + count - 1;
4829  
4830         for (;;) {
4831 -               error = __posix_lock_file(inode, &fl, NULL);
4832 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4833                 if (error != FILE_LOCK_DEFERRED)
4834                         break;
4835                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4836 @@ -1423,6 +1451,7 @@ int generic_setlease(struct file *filp, 
4837  
4838         locks_copy_lock(new_fl, lease);
4839         locks_insert_lock(before, new_fl);
4840 +       vx_locks_inc(new_fl);
4841  
4842         *flp = new_fl;
4843         return 0;
4844 @@ -1778,6 +1807,11 @@ int fcntl_setlk(unsigned int fd, struct 
4845         if (file_lock == NULL)
4846                 return -ENOLCK;
4847  
4848 +       vxd_assert(filp->f_xid == vx_current_xid(),
4849 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4850 +       file_lock->fl_xid = filp->f_xid;
4851 +       vx_locks_inc(file_lock);
4852 +
4853         /*
4854          * This might block, so we do it before checking the inode.
4855          */
4856 @@ -1896,6 +1930,11 @@ int fcntl_setlk64(unsigned int fd, struc
4857         if (file_lock == NULL)
4858                 return -ENOLCK;
4859  
4860 +       vxd_assert(filp->f_xid == vx_current_xid(),
4861 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4862 +       file_lock->fl_xid = filp->f_xid;
4863 +       vx_locks_inc(file_lock);
4864 +
4865         /*
4866          * This might block, so we do it before checking the inode.
4867          */
4868 @@ -2161,8 +2200,11 @@ static int locks_show(struct seq_file *f
4869  
4870         lock_get_status(f, fl, (long)f->private, "");
4871  
4872 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4873 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4874 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4875 +                       continue;
4876                 lock_get_status(f, bfl, (long)f->private, " ->");
4877 +       }
4878  
4879         f->private++;
4880         return 0;
4881 diff -NurpP --minimal linux-2.6.29.4/fs/namei.c linux-2.6.29.4-vs2.3.0.36.14/fs/namei.c
4882 --- linux-2.6.29.4/fs/namei.c   2009-05-23 23:16:52.000000000 +0200
4883 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/namei.c     2009-05-23 22:57:27.000000000 +0200
4884 @@ -31,6 +31,14 @@
4885  #include <linux/file.h>
4886  #include <linux/fcntl.h>
4887  #include <linux/device_cgroup.h>
4888 +#include <linux/proc_fs.h>
4889 +#include <linux/vserver/inode.h>
4890 +#include <linux/vs_base.h>
4891 +#include <linux/vs_tag.h>
4892 +#include <linux/vs_cowbl.h>
4893 +#include <linux/vs_device.h>
4894 +#include <linux/vs_context.h>
4895 +#include <linux/pid_namespace.h>
4896  #include <asm/uaccess.h>
4897  
4898  #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
4899 @@ -167,6 +175,77 @@ void putname(const char *name)
4900  EXPORT_SYMBOL(putname);
4901  #endif
4902  
4903 +static inline int dx_barrier(struct inode *inode)
4904 +{
4905 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4906 +               vxwprintk_task(1, "did hit the barrier.");
4907 +               return 1;
4908 +       }
4909 +       return 0;
4910 +}
4911 +
4912 +static int __dx_permission(struct inode *inode, int mask)
4913 +{
4914 +       if (dx_barrier(inode))
4915 +               return -EACCES;
4916 +
4917 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4918 +               /* devpts is xid tagged */
4919 +               if (S_ISDIR(inode->i_mode) ||
4920 +                   vx_check((xid_t)inode->i_tag, VS_IDENT | VS_WATCH_P))
4921 +                       return 0;
4922 +       }
4923 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4924 +               struct proc_dir_entry *de = PDE(inode);
4925 +
4926 +               if (de && !vx_hide_check(0, de->vx_flags))
4927 +                       goto out;
4928 +
4929 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4930 +                       struct pid *pid;
4931 +                       struct task_struct *tsk;
4932 +
4933 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4934 +                           vx_flags(VXF_STATE_SETUP, 0))
4935 +                               return 0;
4936 +
4937 +                       pid = PROC_I(inode)->pid;
4938 +                       if (!pid)
4939 +                               goto out;
4940 +
4941 +                       tsk = pid_task(pid, PIDTYPE_PID);
4942 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4943 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4944 +                       if (tsk && vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P))
4945 +                               return 0;
4946 +               }
4947 +               else {
4948 +                       /* FIXME: Should we block some entries here? */
4949 +                       return 0;
4950 +               }
4951 +       }
4952 +       else {
4953 +               if (dx_notagcheck(inode->i_sb) ||
4954 +                   dx_check(inode->i_tag, DX_HOSTID | DX_ADMIN | DX_WATCH |
4955 +                            DX_IDENT))
4956 +                       return 0;
4957 +       }
4958 +
4959 +out:
4960 +       return -EACCES;
4961 +}
4962 +
4963 +int dx_permission(struct inode *inode, int mask)
4964 +{
4965 +       int ret = __dx_permission(inode, mask);
4966 +       if (unlikely(ret)) {
4967 +               vxwprintk_task(1, "denied %x access to %s:%p[#%d,%lu]",
4968 +                       mask, inode->i_sb->s_id, inode, inode->i_tag,
4969 +                       inode->i_ino);
4970 +       }
4971 +       return ret;
4972 +}
4973 +
4974  
4975  /**
4976   * generic_permission  -  check for access rights on a Posix-like filesystem
4977 @@ -253,10 +332,14 @@ int inode_permission(struct inode *inode
4978                 /*
4979                  * Nobody gets write access to an immutable file.
4980                  */
4981 -               if (IS_IMMUTABLE(inode))
4982 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4983                         return -EACCES;
4984         }
4985  
4986 +       retval = dx_permission(inode, mask);
4987 +       if (retval)
4988 +               return retval;
4989 +
4990         if (inode->i_op->permission)
4991                 retval = inode->i_op->permission(inode, mask);
4992         else
4993 @@ -432,6 +515,8 @@ static int exec_permission_lite(struct i
4994  {
4995         umode_t mode = inode->i_mode;
4996  
4997 +       if (dx_barrier(inode))
4998 +               return -EACCES;
4999         if (inode->i_op->permission)
5000                 return -EAGAIN;
5001  
5002 @@ -749,7 +834,8 @@ static __always_inline void follow_dotdo
5003                 if (nd->path.dentry == fs->root.dentry &&
5004                     nd->path.mnt == fs->root.mnt) {
5005                          read_unlock(&fs->lock);
5006 -                       break;
5007 +                       /* for sane '/' avoid follow_mount() */
5008 +                       return;
5009                 }
5010                  read_unlock(&fs->lock);
5011                 spin_lock(&dcache_lock);
5012 @@ -786,16 +872,30 @@ static int do_lookup(struct nameidata *n
5013  {
5014         struct vfsmount *mnt = nd->path.mnt;
5015         struct dentry *dentry = __d_lookup(nd->path.dentry, name);
5016 +       struct inode *inode;
5017  
5018         if (!dentry)
5019                 goto need_lookup;
5020         if (dentry->d_op && dentry->d_op->d_revalidate)
5021                 goto need_revalidate;
5022 +       inode = dentry->d_inode;
5023 +       if (!inode)
5024 +               goto done;
5025 +
5026 +       if (__dx_permission(inode, MAY_ACCESS))
5027 +               goto hidden;
5028 +
5029  done:
5030         path->mnt = mnt;
5031         path->dentry = dentry;
5032         __follow_mount(path);
5033         return 0;
5034 +hidden:
5035 +       vxwprintk_task(1, "did lookup hidden %s:%p[#%d,%lu] Â»%s/%.*s«.",
5036 +               inode->i_sb->s_id, inode, inode->i_tag, inode->i_ino,
5037 +               vxd_path(&nd->path), name->len, name->name);
5038 +       dput(dentry);
5039 +       return -ENOENT;
5040  
5041  need_lookup:
5042         dentry = real_lookup(nd->path.dentry, name, nd);
5043 @@ -1364,7 +1464,7 @@ static int may_delete(struct inode *dir,
5044         if (IS_APPEND(dir))
5045                 return -EPERM;
5046         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
5047 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
5048 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
5049                 return -EPERM;
5050         if (isdir) {
5051                 if (!S_ISDIR(victim->d_inode->i_mode))
5052 @@ -1506,6 +1606,14 @@ int may_open(struct path *path, int acc_
5053                 flag &= ~O_TRUNC;
5054         }
5055  
5056 +#ifdef CONFIG_VSERVER_COWBL
5057 +       if (IS_COW(inode) && (flag & FMODE_WRITE)) {
5058 +               if (IS_COW_LINK(inode))
5059 +                       return -EMLINK;
5060 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
5061 +               mark_inode_dirty(inode);
5062 +       }
5063 +#endif
5064         error = inode_permission(inode, acc_mode);
5065         if (error)
5066                 return error;
5067 @@ -1639,6 +1747,11 @@ struct file *do_filp_open(int dfd, const
5068         int will_write;
5069         int flag = open_to_namei_flags(open_flag);
5070  
5071 +#ifdef CONFIG_VSERVER_COWBL
5072 +       int rflag = flag;
5073 +       int rmode = mode;
5074 +restart:
5075 +#endif
5076         acc_mode = MAY_OPEN | ACC_MODE(flag);
5077  
5078         /* O_TRUNC implies we need access checks for write permissions */
5079 @@ -1771,6 +1884,25 @@ ok:
5080                         goto exit;
5081         }
5082         error = may_open(&nd.path, acc_mode, flag);
5083 +#ifdef CONFIG_VSERVER_COWBL
5084 +       if (error == -EMLINK) {
5085 +               struct dentry *dentry;
5086 +               dentry = cow_break_link(pathname);
5087 +               if (IS_ERR(dentry)) {
5088 +                       error = PTR_ERR(dentry);
5089 +                       goto exit_cow;
5090 +               }
5091 +               dput(dentry);
5092 +               if (will_write)
5093 +                       mnt_drop_write(nd.path.mnt);
5094 +               release_open_intent(&nd);
5095 +               path_put(&nd.path);
5096 +               flag = rflag;
5097 +               mode = rmode;
5098 +               goto restart;
5099 +       }
5100 +exit_cow:
5101 +#endif
5102         if (error) {
5103                 if (will_write)
5104                         mnt_drop_write(nd.path.mnt);
5105 @@ -1924,9 +2056,17 @@ int vfs_mknod(struct inode *dir, struct 
5106         if (error)
5107                 return error;
5108  
5109 -       if ((S_ISCHR(mode) || S_ISBLK(mode)) && !capable(CAP_MKNOD))
5110 +       if (!(S_ISCHR(mode) || S_ISBLK(mode)))
5111 +               goto okay;
5112 +
5113 +       if (!capable(CAP_MKNOD))
5114                 return -EPERM;
5115  
5116 +       if (S_ISCHR(mode) && !vs_chrdev_perm(dev, DATTR_CREATE))
5117 +               return -EPERM;
5118 +       if (S_ISBLK(mode) && !vs_blkdev_perm(dev, DATTR_CREATE))
5119 +               return -EPERM;
5120 +okay:
5121         if (!dir->i_op->mknod)
5122                 return -EPERM;
5123  
5124 @@ -2393,7 +2533,7 @@ int vfs_link(struct dentry *old_dentry, 
5125         /*
5126          * A link to an append-only or immutable file cannot be created.
5127          */
5128 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
5129 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
5130                 return -EPERM;
5131         if (!dir->i_op->link)
5132                 return -EPERM;
5133 @@ -2766,6 +2906,219 @@ int vfs_follow_link(struct nameidata *nd
5134         return __vfs_follow_link(nd, link);
5135  }
5136  
5137 +
5138 +#ifdef CONFIG_VSERVER_COWBL
5139 +
5140 +#include <linux/file.h>
5141 +
5142 +static inline
5143 +long do_cow_splice(struct file *in, struct file *out, size_t len)
5144 +{
5145 +       loff_t ppos = 0;
5146 +
5147 +       return do_splice_direct(in, &ppos, out, len, 0);
5148 +}
5149 +
5150 +struct dentry *cow_break_link(const char *pathname)
5151 +{
5152 +       int ret, mode, pathlen, redo = 0;
5153 +       struct nameidata old_nd, dir_nd;
5154 +       struct path old_path, new_path;
5155 +       struct dentry *dir, *res = NULL;
5156 +       struct file *old_file;
5157 +       struct file *new_file;
5158 +       char *to, *path, pad='\251';
5159 +       loff_t size;
5160 +
5161 +       vxdprintk(VXD_CBIT(misc, 1), "cow_break_link(»%s«)", pathname);
5162 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
5163 +       ret = -ENOMEM;
5164 +       if (!path)
5165 +               goto out;
5166 +
5167 +       /* old_nd will have refs to dentry and mnt */
5168 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5169 +       vxdprintk(VXD_CBIT(misc, 2), "path_lookup(old): %d", ret);
5170 +       if (ret < 0)
5171 +               goto out_free_path;
5172 +
5173 +       old_path = old_nd.path;
5174 +       mode = old_path.dentry->d_inode->i_mode;
5175 +
5176 +       to = d_path(&old_path, path, PATH_MAX-2);
5177 +       pathlen = strlen(to);
5178 +       vxdprintk(VXD_CBIT(misc, 2), "old path Â»%s« [»%.*s«:%d]", to,
5179 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5180 +               old_path.dentry->d_name.len);
5181 +
5182 +       to[pathlen + 1] = 0;
5183 +retry:
5184 +       to[pathlen] = pad--;
5185 +       ret = -EMLINK;
5186 +       if (pad <= '\240')
5187 +               goto out_rel_old;
5188 +
5189 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy Â»%s«", to);
5190 +       /* dir_nd will have refs to dentry and mnt */
5191 +       ret = path_lookup(to,
5192 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
5193 +       vxdprintk(VXD_CBIT(misc, 2),
5194 +               "path_lookup(new): %d", ret);
5195 +       if (ret < 0)
5196 +               goto retry;
5197 +
5198 +       /* this puppy downs the inode mutex */
5199 +       new_path.dentry = lookup_create(&dir_nd, 0);
5200 +       if (!new_path.dentry || IS_ERR(new_path.dentry)) {
5201 +               vxdprintk(VXD_CBIT(misc, 2),
5202 +                       "lookup_create(new): %p", new_path.dentry);
5203 +               mutex_unlock(&dir_nd.path.dentry->d_inode->i_mutex);
5204 +               path_put(&dir_nd.path);
5205 +               goto retry;
5206 +       }
5207 +       vxdprintk(VXD_CBIT(misc, 2),
5208 +               "lookup_create(new): %p [»%.*s«:%d]", new_path.dentry,
5209 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5210 +               new_path.dentry->d_name.len);
5211 +       dir = dir_nd.path.dentry;
5212 +
5213 +       ret = vfs_create(dir_nd.path.dentry->d_inode, new_path.dentry, mode, &dir_nd);
5214 +       vxdprintk(VXD_CBIT(misc, 2),
5215 +               "vfs_create(new): %d", ret);
5216 +       if (ret == -EEXIST) {
5217 +               mutex_unlock(&dir->d_inode->i_mutex);
5218 +               dput(new_path.dentry);
5219 +               path_put(&dir_nd.path);
5220 +               goto retry;
5221 +       }
5222 +       else if (ret < 0)
5223 +               goto out_unlock_new;
5224 +
5225 +       /* drop out early, ret passes ENOENT */
5226 +       ret = -ENOENT;
5227 +       if ((redo = d_unhashed(old_path.dentry)))
5228 +               goto out_unlock_new;
5229 +
5230 +       new_path.mnt = dir_nd.path.mnt;
5231 +       dget(old_path.dentry);
5232 +       mntget(old_path.mnt);
5233 +       /* this one cleans up the dentry/mnt in case of failure */
5234 +       old_file = dentry_open(old_path.dentry, old_path.mnt,
5235 +               O_RDONLY, current_cred());
5236 +       vxdprintk(VXD_CBIT(misc, 2),
5237 +               "dentry_open(old): %p", old_file);
5238 +       if (!old_file || IS_ERR(old_file)) {
5239 +               res = IS_ERR(old_file) ? (void *) old_file : res;
5240 +               goto out_unlock_new;
5241 +       }
5242 +
5243 +       dget(new_path.dentry);
5244 +       mntget(new_path.mnt);
5245 +       /* this one cleans up the dentry/mnt in case of failure */
5246 +       new_file = dentry_open(new_path.dentry, new_path.mnt,
5247 +               O_WRONLY, current_cred());
5248 +       vxdprintk(VXD_CBIT(misc, 2),
5249 +               "dentry_open(new): %p", new_file);
5250 +
5251 +       ret = IS_ERR(new_file) ? PTR_ERR(new_file) : -ENOENT;
5252 +       if (!new_file || IS_ERR(new_file))
5253 +               goto out_fput_old;
5254 +
5255 +       size = i_size_read(old_file->f_dentry->d_inode);
5256 +       ret = do_cow_splice(old_file, new_file, size);
5257 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
5258 +       if (ret < 0) {
5259 +               goto out_fput_both;
5260 +       } else if (ret < size) {
5261 +               ret = -ENOSPC;
5262 +               goto out_fput_both;
5263 +       } else {
5264 +               struct inode *old_inode = old_path.dentry->d_inode;
5265 +               struct inode *new_inode = new_path.dentry->d_inode;
5266 +               struct iattr attr = {
5267 +                       .ia_uid = old_inode->i_uid,
5268 +                       .ia_gid = old_inode->i_gid,
5269 +                       .ia_valid = ATTR_UID | ATTR_GID
5270 +                       };
5271 +
5272 +               ret = inode_setattr(new_inode, &attr);
5273 +               if (ret)
5274 +                       goto out_fput_both;
5275 +       }
5276 +
5277 +       mutex_lock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5278 +
5279 +       /* drop out late */
5280 +       ret = -ENOENT;
5281 +       if ((redo = d_unhashed(old_path.dentry)))
5282 +               goto out_unlock;
5283 +
5284 +       vxdprintk(VXD_CBIT(misc, 2),
5285 +               "vfs_rename: [»%*s«:%d] -> [»%*s«:%d]",
5286 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5287 +               new_path.dentry->d_name.len,
5288 +               old_path.dentry->d_name.len, old_path.dentry->d_name.name,
5289 +               old_path.dentry->d_name.len);
5290 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_path.dentry,
5291 +               old_nd.path.dentry->d_parent->d_inode, old_path.dentry);
5292 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
5293 +       res = new_path.dentry;
5294 +
5295 +out_unlock:
5296 +       mutex_unlock(&old_path.dentry->d_inode->i_sb->s_vfs_rename_mutex);
5297 +
5298 +out_fput_both:
5299 +       vxdprintk(VXD_CBIT(misc, 3),
5300 +               "fput(new_file=%p[#%ld])", new_file,
5301 +               atomic_read(&new_file->f_count));
5302 +       fput(new_file);
5303 +
5304 +out_fput_old:
5305 +       vxdprintk(VXD_CBIT(misc, 3),
5306 +               "fput(old_file=%p[#%ld])", old_file,
5307 +               atomic_read(&old_file->f_count));
5308 +       fput(old_file);
5309 +
5310 +out_unlock_new:
5311 +       mutex_unlock(&dir->d_inode->i_mutex);
5312 +       if (!ret)
5313 +               goto out_redo;
5314 +
5315 +       /* error path cleanup */
5316 +       vfs_unlink(dir->d_inode, new_path.dentry);
5317 +       dput(new_path.dentry);
5318 +
5319 +out_redo:
5320 +       if (!redo)
5321 +               goto out_rel_both;
5322 +       /* lookup dentry once again */
5323 +       path_put(&old_nd.path);
5324 +       ret = path_lookup(pathname, LOOKUP_FOLLOW, &old_nd);
5325 +       if (ret)
5326 +               goto out_rel_both;
5327 +
5328 +       new_path.dentry = old_nd.path.dentry;
5329 +       vxdprintk(VXD_CBIT(misc, 2),
5330 +               "path_lookup(redo): %p [»%.*s«:%d]", new_path.dentry,
5331 +               new_path.dentry->d_name.len, new_path.dentry->d_name.name,
5332 +               new_path.dentry->d_name.len);
5333 +       dget(new_path.dentry);
5334 +       res = new_path.dentry;
5335 +
5336 +out_rel_both:
5337 +       path_put(&dir_nd.path);
5338 +out_rel_old:
5339 +       path_put(&old_nd.path);
5340 +out_free_path:
5341 +       kfree(path);
5342 +out:
5343 +       if (ret)
5344 +               res = ERR_PTR(ret);
5345 +       return res;
5346 +}
5347 +
5348 +#endif
5349 +
5350  /* get the link contents into pagecache */
5351  static char *page_getlink(struct dentry * dentry, struct page **ppage)
5352  {
5353 diff -NurpP --minimal linux-2.6.29.4/fs/namespace.c linux-2.6.29.4-vs2.3.0.36.14/fs/namespace.c
5354 --- linux-2.6.29.4/fs/namespace.c       2009-05-23 23:16:52.000000000 +0200
5355 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/namespace.c 2009-05-10 23:42:01.000000000 +0200
5356 @@ -27,6 +27,11 @@
5357  #include <linux/ramfs.h>
5358  #include <linux/log2.h>
5359  #include <linux/idr.h>
5360 +#include <linux/vs_base.h>
5361 +#include <linux/vs_context.h>
5362 +#include <linux/vs_tag.h>
5363 +#include <linux/vserver/space.h>
5364 +#include <linux/vserver/global.h>
5365  #include <asm/uaccess.h>
5366  #include <asm/unistd.h>
5367  #include "pnode.h"
5368 @@ -573,6 +578,7 @@ static struct vfsmount *clone_mnt(struct
5369                 mnt->mnt_root = dget(root);
5370                 mnt->mnt_mountpoint = mnt->mnt_root;
5371                 mnt->mnt_parent = mnt;
5372 +               mnt->mnt_tag = old->mnt_tag;
5373  
5374                 if (flag & CL_SLAVE) {
5375                         list_add(&mnt->mnt_slave, &old->mnt_slave_list);
5376 @@ -687,6 +693,31 @@ static inline void mangle(struct seq_fil
5377         seq_escape(m, s, " \t\n\\");
5378  }
5379  
5380 +static int mnt_is_reachable(struct vfsmount *mnt)
5381 +{
5382 +       struct path root;
5383 +       struct dentry *point;
5384 +       int ret;
5385 +
5386 +       if (mnt == mnt->mnt_ns->root)
5387 +               return 1;
5388 +
5389 +       spin_lock(&vfsmount_lock);
5390 +       root = current->fs->root;
5391 +       point = root.dentry;
5392 +
5393 +       while ((mnt != mnt->mnt_parent) && (mnt != root.mnt)) {
5394 +               point = mnt->mnt_mountpoint;
5395 +               mnt = mnt->mnt_parent;
5396 +       }
5397 +
5398 +       ret = (mnt == root.mnt) && is_subdir(point, root.dentry);
5399 +
5400 +       spin_unlock(&vfsmount_lock);
5401 +
5402 +       return ret;
5403 +}
5404 +
5405  /*
5406   * Simple .show_options callback for filesystems which don't want to
5407   * implement more complex mount option showing.
5408 @@ -759,6 +790,8 @@ static int show_sb_opts(struct seq_file 
5409                 { MS_SYNCHRONOUS, ",sync" },
5410                 { MS_DIRSYNC, ",dirsync" },
5411                 { MS_MANDLOCK, ",mand" },
5412 +               { MS_TAGGED, ",tag" },
5413 +               { MS_NOTAGCHECK, ",notagcheck" },
5414                 { 0, NULL }
5415         };
5416         const struct proc_fs_info *fs_infop;
5417 @@ -805,10 +838,20 @@ static int show_vfsmnt(struct seq_file *
5418         int err = 0;
5419         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5420  
5421 -       mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5422 -       seq_putc(m, ' ');
5423 -       seq_path(m, &mnt_path, " \t\n\\");
5424 -       seq_putc(m, ' ');
5425 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5426 +               return SEQ_SKIP;
5427 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5428 +               return SEQ_SKIP;
5429 +
5430 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5431 +               mnt == current->fs->root.mnt) {
5432 +               seq_puts(m, "/dev/root / ");
5433 +       } else {
5434 +               mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
5435 +               seq_putc(m, ' ');
5436 +               seq_path(m, &mnt_path, " \t\n\\");
5437 +               seq_putc(m, ' ');
5438 +       }
5439         show_type(m, mnt->mnt_sb);
5440         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
5441         err = show_sb_opts(m, mnt->mnt_sb);
5442 @@ -838,6 +881,11 @@ static int show_mountinfo(struct seq_fil
5443         struct path root = p->root;
5444         int err = 0;
5445  
5446 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5447 +               return SEQ_SKIP;
5448 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5449 +               return SEQ_SKIP;
5450 +
5451         seq_printf(m, "%i %i %u:%u ", mnt->mnt_id, mnt->mnt_parent->mnt_id,
5452                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
5453         seq_dentry(m, mnt->mnt_root, " \t\n\\");
5454 @@ -896,17 +944,27 @@ static int show_vfsstat(struct seq_file 
5455         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
5456         int err = 0;
5457  
5458 -       /* device */
5459 -       if (mnt->mnt_devname) {
5460 -               seq_puts(m, "device ");
5461 -               mangle(m, mnt->mnt_devname);
5462 -       } else
5463 -               seq_puts(m, "no device");
5464 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
5465 +               return SEQ_SKIP;
5466 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
5467 +               return SEQ_SKIP;
5468  
5469 -       /* mount point */
5470 -       seq_puts(m, " mounted on ");
5471 -       seq_path(m, &mnt_path, " \t\n\\");
5472 -       seq_putc(m, ' ');
5473 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
5474 +               mnt == current->fs->root.mnt) {
5475 +               seq_puts(m, "device /dev/root mounted on / ");
5476 +       } else {
5477 +               /* device */
5478 +               if (mnt->mnt_devname) {
5479 +                       seq_puts(m, "device ");
5480 +                       mangle(m, mnt->mnt_devname);
5481 +               } else
5482 +                       seq_puts(m, "no device");
5483 +
5484 +               /* mount point */
5485 +               seq_puts(m, " mounted on ");
5486 +               seq_path(m, &mnt_path, " \t\n\\");
5487 +               seq_putc(m, ' ');
5488 +       }
5489  
5490         /* file system type */
5491         seq_puts(m, "with fstype ");
5492 @@ -1145,7 +1203,7 @@ SYSCALL_DEFINE2(umount, char __user *, n
5493                 goto dput_and_out;
5494  
5495         retval = -EPERM;
5496 -       if (!capable(CAP_SYS_ADMIN))
5497 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5498                 goto dput_and_out;
5499  
5500         retval = do_umount(path.mnt, flags);
5501 @@ -1171,7 +1229,7 @@ SYSCALL_DEFINE1(oldumount, char __user *
5502  
5503  static int mount_is_safe(struct path *path)
5504  {
5505 -       if (capable(CAP_SYS_ADMIN))
5506 +       if (vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5507                 return 0;
5508         return -EPERM;
5509  #ifdef notyet
5510 @@ -1462,11 +1520,13 @@ static int do_change_type(struct path *p
5511   * do loopback mount.
5512   */
5513  static int do_loopback(struct path *path, char *old_name,
5514 -                               int recurse)
5515 +       tag_t tag, unsigned long flags, int mnt_flags)
5516  {
5517         struct path old_path;
5518         struct vfsmount *mnt = NULL;
5519         int err = mount_is_safe(path);
5520 +       int recurse = flags & MS_REC;
5521 +
5522         if (err)
5523                 return err;
5524         if (!old_name || !*old_name)
5525 @@ -1500,6 +1560,7 @@ static int do_loopback(struct path *path
5526                 spin_unlock(&vfsmount_lock);
5527                 release_mounts(&umount_list);
5528         }
5529 +       mnt->mnt_flags = mnt_flags;
5530  
5531  out:
5532         up_write(&namespace_sem);
5533 @@ -1530,12 +1591,12 @@ static int change_mount_flags(struct vfs
5534   * on it - tough luck.
5535   */
5536  static int do_remount(struct path *path, int flags, int mnt_flags,
5537 -                     void *data)
5538 +       void *data, xid_t xid)
5539  {
5540         int err;
5541         struct super_block *sb = path->mnt->mnt_sb;
5542  
5543 -       if (!capable(CAP_SYS_ADMIN))
5544 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_REMOUNT))
5545                 return -EPERM;
5546  
5547         if (!check_mnt(path->mnt))
5548 @@ -1577,7 +1638,7 @@ static int do_move_mount(struct path *pa
5549         struct path old_path, parent_path;
5550         struct vfsmount *p;
5551         int err = 0;
5552 -       if (!capable(CAP_SYS_ADMIN))
5553 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5554                 return -EPERM;
5555         if (!old_name || !*old_name)
5556                 return -EINVAL;
5557 @@ -1659,7 +1720,7 @@ static int do_new_mount(struct path *pat
5558                 return -EINVAL;
5559  
5560         /* we need capabilities... */
5561 -       if (!capable(CAP_SYS_ADMIN))
5562 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
5563                 return -EPERM;
5564  
5565         mnt = do_kern_mount(type, flags, name, data);
5566 @@ -1904,6 +1965,7 @@ long do_mount(char *dev_name, char *dir_
5567         struct path path;
5568         int retval = 0;
5569         int mnt_flags = 0;
5570 +       tag_t tag = 0;
5571  
5572         /* Discard magic */
5573         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5574 @@ -1919,6 +1981,12 @@ long do_mount(char *dev_name, char *dir_
5575         if (data_page)
5576                 ((char *)data_page)[PAGE_SIZE - 1] = 0;
5577  
5578 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5579 +               /* FIXME: bind and re-mounts get the tag flag? */
5580 +               if (flags & (MS_BIND|MS_REMOUNT))
5581 +                       flags |= MS_TAGID;
5582 +       }
5583 +
5584         /* Separate the per-mountpoint flags */
5585         if (flags & MS_NOSUID)
5586                 mnt_flags |= MNT_NOSUID;
5587 @@ -1935,6 +2003,8 @@ long do_mount(char *dev_name, char *dir_
5588         if (flags & MS_RDONLY)
5589                 mnt_flags |= MNT_READONLY;
5590  
5591 +       if (!capable(CAP_SYS_ADMIN))
5592 +               mnt_flags |= MNT_NODEV;
5593         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE |
5594                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT);
5595  
5596 @@ -1950,9 +2020,9 @@ long do_mount(char *dev_name, char *dir_
5597  
5598         if (flags & MS_REMOUNT)
5599                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5600 -                                   data_page);
5601 +                                   data_page, tag);
5602         else if (flags & MS_BIND)
5603 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
5604 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5605         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5606                 retval = do_change_type(&path, flags);
5607         else if (flags & MS_MOVE)
5608 @@ -2021,6 +2091,7 @@ static struct mnt_namespace *dup_mnt_ns(
5609                 q = next_mnt(q, new_ns->root);
5610         }
5611         up_write(&namespace_sem);
5612 +       atomic_inc(&vs_global_mnt_ns);
5613  
5614         if (rootmnt)
5615                 mntput(rootmnt);
5616 @@ -2147,9 +2218,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5617         down_write(&namespace_sem);
5618         mutex_lock(&old.dentry->d_inode->i_mutex);
5619         error = -EINVAL;
5620 -       if (IS_MNT_SHARED(old.mnt) ||
5621 +       if ((IS_MNT_SHARED(old.mnt) ||
5622                 IS_MNT_SHARED(new.mnt->mnt_parent) ||
5623 -               IS_MNT_SHARED(root.mnt->mnt_parent))
5624 +               IS_MNT_SHARED(root.mnt->mnt_parent)) &&
5625 +               !vx_flags(VXF_STATE_SETUP, 0))
5626                 goto out2;
5627         if (!check_mnt(root.mnt))
5628                 goto out2;
5629 @@ -2288,5 +2360,6 @@ void __put_mnt_ns(struct mnt_namespace *
5630         spin_unlock(&vfsmount_lock);
5631         up_write(&namespace_sem);
5632         release_mounts(&umount_list);
5633 +       atomic_dec(&vs_global_mnt_ns);
5634         kfree(ns);
5635  }
5636 diff -NurpP --minimal linux-2.6.29.4/fs/nfs/client.c linux-2.6.29.4-vs2.3.0.36.14/fs/nfs/client.c
5637 --- linux-2.6.29.4/fs/nfs/client.c      2009-03-24 14:22:26.000000000 +0100
5638 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/nfs/client.c        2009-03-24 14:48:35.000000000 +0100
5639 @@ -696,6 +696,9 @@ static int nfs_init_server_rpcclient(str
5640         if (server->flags & NFS_MOUNT_SOFT)
5641                 server->client->cl_softrtry = 1;
5642  
5643 +       server->client->cl_tag = 0;
5644 +       if (server->flags & NFS_MOUNT_TAGGED)
5645 +               server->client->cl_tag = 1;
5646         return 0;
5647  }
5648  
5649 @@ -862,6 +865,10 @@ static void nfs_server_set_fsinfo(struct
5650                 server->acdirmin = server->acdirmax = 0;
5651         }
5652  
5653 +       /* FIXME: needs fsinfo
5654 +       if (server->flags & NFS_MOUNT_TAGGED)
5655 +               sb->s_flags |= MS_TAGGED;       */
5656 +
5657         server->maxfilesize = fsinfo->maxfilesize;
5658  
5659         /* We're airborne Set socket buffersize */
5660 diff -NurpP --minimal linux-2.6.29.4/fs/nfs/dir.c linux-2.6.29.4-vs2.3.0.36.14/fs/nfs/dir.c
5661 --- linux-2.6.29.4/fs/nfs/dir.c 2009-05-23 23:16:52.000000000 +0200
5662 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/nfs/dir.c   2009-05-23 23:19:11.000000000 +0200
5663 @@ -34,6 +34,7 @@
5664  #include <linux/namei.h>
5665  #include <linux/mount.h>
5666  #include <linux/sched.h>
5667 +#include <linux/vs_tag.h>
5668  
5669  #include "nfs4_fs.h"
5670  #include "delegation.h"
5671 @@ -950,6 +951,7 @@ static struct dentry *nfs_lookup(struct 
5672         if (IS_ERR(res))
5673                 goto out_unblock_sillyrename;
5674  
5675 +       dx_propagate_tag(nd, inode);
5676  no_entry:
5677         res = d_materialise_unique(dentry, inode);
5678         if (res != NULL) {
5679 diff -NurpP --minimal linux-2.6.29.4/fs/nfs/inode.c linux-2.6.29.4-vs2.3.0.36.14/fs/nfs/inode.c
5680 --- linux-2.6.29.4/fs/nfs/inode.c       2009-03-24 14:22:26.000000000 +0100
5681 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/nfs/inode.c 2009-03-24 14:48:35.000000000 +0100
5682 @@ -37,6 +37,7 @@
5683  #include <linux/vfs.h>
5684  #include <linux/inet.h>
5685  #include <linux/nfs_xdr.h>
5686 +#include <linux/vs_tag.h>
5687  
5688  #include <asm/system.h>
5689  #include <asm/uaccess.h>
5690 @@ -313,8 +314,10 @@ nfs_fhget(struct super_block *sb, struct
5691                         nfsi->change_attr = fattr->change_attr;
5692                 inode->i_size = nfs_size_to_loff_t(fattr->size);
5693                 inode->i_nlink = fattr->nlink;
5694 -               inode->i_uid = fattr->uid;
5695 -               inode->i_gid = fattr->gid;
5696 +               inode->i_uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5697 +               inode->i_gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5698 +               inode->i_tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5699 +                                        /* maybe fattr->xid someday */
5700                 if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
5701                         /*
5702                          * report the blocks in 512byte units
5703 @@ -462,6 +465,8 @@ void nfs_setattr_update_inode(struct ino
5704                         inode->i_uid = attr->ia_uid;
5705                 if ((attr->ia_valid & ATTR_GID) != 0)
5706                         inode->i_gid = attr->ia_gid;
5707 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5708 +                       inode->i_tag = attr->ia_tag;
5709                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5710                 spin_unlock(&inode->i_lock);
5711         }
5712 @@ -850,6 +855,9 @@ static int nfs_check_inode_attributes(st
5713         struct nfs_inode *nfsi = NFS_I(inode);
5714         loff_t cur_size, new_isize;
5715         unsigned long invalid = 0;
5716 +       uid_t uid;
5717 +       gid_t gid;
5718 +       tag_t tag;
5719  
5720  
5721         /* Has the inode gone and changed behind our back? */
5722 @@ -871,10 +879,15 @@ static int nfs_check_inode_attributes(st
5723         if (cur_size != new_isize && nfsi->npages == 0)
5724                 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5725  
5726 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5727 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5728 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5729 +
5730         /* Have any file permissions changed? */
5731         if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO)
5732 -                       || inode->i_uid != fattr->uid
5733 -                       || inode->i_gid != fattr->gid)
5734 +                       || inode->i_uid != uid
5735 +                       || inode->i_gid != gid
5736 +                       || inode->i_tag != tag)
5737                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5738  
5739         /* Has the link count changed? */
5740 @@ -1073,6 +1086,9 @@ static int nfs_update_inode(struct inode
5741         loff_t cur_isize, new_isize;
5742         unsigned long invalid = 0;
5743         unsigned long now = jiffies;
5744 +       uid_t uid;
5745 +       gid_t gid;
5746 +       tag_t tag;
5747  
5748         dfprintk(VFS, "NFS: %s(%s/%ld ct=%d info=0x%x)\n",
5749                         __func__, inode->i_sb->s_id, inode->i_ino,
5750 @@ -1146,9 +1162,14 @@ static int nfs_update_inode(struct inode
5751         memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5752         nfsi->change_attr = fattr->change_attr;
5753  
5754 +       uid = INOTAG_UID(DX_TAG(inode), fattr->uid, fattr->gid);
5755 +       gid = INOTAG_GID(DX_TAG(inode), fattr->uid, fattr->gid);
5756 +       tag = INOTAG_TAG(DX_TAG(inode), fattr->uid, fattr->gid, 0);
5757 +
5758         if ((inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO) ||
5759 -           inode->i_uid != fattr->uid ||
5760 -           inode->i_gid != fattr->gid)
5761 +           inode->i_uid != uid ||
5762 +           inode->i_gid != gid ||
5763 +           inode->i_tag != tag)
5764                 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5765  
5766         if (inode->i_nlink != fattr->nlink)
5767 @@ -1156,8 +1177,9 @@ static int nfs_update_inode(struct inode
5768  
5769         inode->i_mode = fattr->mode;
5770         inode->i_nlink = fattr->nlink;
5771 -       inode->i_uid = fattr->uid;
5772 -       inode->i_gid = fattr->gid;
5773 +       inode->i_uid = uid;
5774 +       inode->i_gid = gid;
5775 +       inode->i_tag = tag;
5776  
5777         if (fattr->valid & (NFS_ATTR_FATTR_V3 | NFS_ATTR_FATTR_V4)) {
5778                 /*
5779 diff -NurpP --minimal linux-2.6.29.4/fs/nfs/nfs3xdr.c linux-2.6.29.4-vs2.3.0.36.14/fs/nfs/nfs3xdr.c
5780 --- linux-2.6.29.4/fs/nfs/nfs3xdr.c     2009-05-23 23:16:53.000000000 +0200
5781 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/nfs/nfs3xdr.c       2009-04-30 12:14:53.000000000 +0200
5782 @@ -22,6 +22,7 @@
5783  #include <linux/nfs3.h>
5784  #include <linux/nfs_fs.h>
5785  #include <linux/nfsacl.h>
5786 +#include <linux/vs_tag.h>
5787  #include "internal.h"
5788  
5789  #define NFSDBG_FACILITY                NFSDBG_XDR
5790 @@ -182,7 +183,7 @@ xdr_decode_fattr(__be32 *p, struct nfs_f
5791  }
5792  
5793  static inline __be32 *
5794 -xdr_encode_sattr(__be32 *p, struct iattr *attr)
5795 +xdr_encode_sattr(__be32 *p, struct iattr *attr, int tag)
5796  {
5797         if (attr->ia_valid & ATTR_MODE) {
5798                 *p++ = xdr_one;
5799 @@ -190,15 +191,17 @@ xdr_encode_sattr(__be32 *p, struct iattr
5800         } else {
5801                 *p++ = xdr_zero;
5802         }
5803 -       if (attr->ia_valid & ATTR_UID) {
5804 +       if (attr->ia_valid & ATTR_UID ||
5805 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5806                 *p++ = xdr_one;
5807 -               *p++ = htonl(attr->ia_uid);
5808 +               *p++ = htonl(TAGINO_UID(tag, attr->ia_uid, attr->ia_tag));
5809         } else {
5810                 *p++ = xdr_zero;
5811         }
5812 -       if (attr->ia_valid & ATTR_GID) {
5813 +       if (attr->ia_valid & ATTR_GID ||
5814 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5815                 *p++ = xdr_one;
5816 -               *p++ = htonl(attr->ia_gid);
5817 +               *p++ = htonl(TAGINO_GID(tag, attr->ia_gid, attr->ia_tag));
5818         } else {
5819                 *p++ = xdr_zero;
5820         }
5821 @@ -283,7 +286,8 @@ static int
5822  nfs3_xdr_sattrargs(struct rpc_rqst *req, __be32 *p, struct nfs3_sattrargs *args)
5823  {
5824         p = xdr_encode_fhandle(p, args->fh);
5825 -       p = xdr_encode_sattr(p, args->sattr);
5826 +       p = xdr_encode_sattr(p, args->sattr,
5827 +               req->rq_task->tk_client->cl_tag);
5828         *p++ = htonl(args->guard);
5829         if (args->guard)
5830                 p = xdr_encode_time3(p, &args->guardtime);
5831 @@ -388,7 +392,8 @@ nfs3_xdr_createargs(struct rpc_rqst *req
5832                 *p++ = args->verifier[0];
5833                 *p++ = args->verifier[1];
5834         } else
5835 -               p = xdr_encode_sattr(p, args->sattr);
5836 +               p = xdr_encode_sattr(p, args->sattr,
5837 +                       req->rq_task->tk_client->cl_tag);
5838  
5839         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5840         return 0;
5841 @@ -402,7 +407,8 @@ nfs3_xdr_mkdirargs(struct rpc_rqst *req,
5842  {
5843         p = xdr_encode_fhandle(p, args->fh);
5844         p = xdr_encode_array(p, args->name, args->len);
5845 -       p = xdr_encode_sattr(p, args->sattr);
5846 +       p = xdr_encode_sattr(p, args->sattr,
5847 +               req->rq_task->tk_client->cl_tag);
5848         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5849         return 0;
5850  }
5851 @@ -415,7 +421,8 @@ nfs3_xdr_symlinkargs(struct rpc_rqst *re
5852  {
5853         p = xdr_encode_fhandle(p, args->fromfh);
5854         p = xdr_encode_array(p, args->fromname, args->fromlen);
5855 -       p = xdr_encode_sattr(p, args->sattr);
5856 +       p = xdr_encode_sattr(p, args->sattr,
5857 +               req->rq_task->tk_client->cl_tag);
5858         *p++ = htonl(args->pathlen);
5859         req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
5860  
5861 @@ -433,7 +440,8 @@ nfs3_xdr_mknodargs(struct rpc_rqst *req,
5862         p = xdr_encode_fhandle(p, args->fh);
5863         p = xdr_encode_array(p, args->name, args->len);
5864         *p++ = htonl(args->type);
5865 -       p = xdr_encode_sattr(p, args->sattr);
5866 +       p = xdr_encode_sattr(p, args->sattr,
5867 +               req->rq_task->tk_client->cl_tag);
5868         if (args->type == NF3CHR || args->type == NF3BLK) {
5869                 *p++ = htonl(MAJOR(args->rdev));
5870                 *p++ = htonl(MINOR(args->rdev));
5871 diff -NurpP --minimal linux-2.6.29.4/fs/nfs/nfsroot.c linux-2.6.29.4-vs2.3.0.36.14/fs/nfs/nfsroot.c
5872 --- linux-2.6.29.4/fs/nfs/nfsroot.c     2009-03-24 14:22:26.000000000 +0100
5873 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/nfs/nfsroot.c       2009-03-24 14:48:35.000000000 +0100
5874 @@ -119,12 +119,12 @@ static int mount_port __initdata = 0;             /
5875  enum {
5876         /* Options that take integer arguments */
5877         Opt_port, Opt_rsize, Opt_wsize, Opt_timeo, Opt_retrans, Opt_acregmin,
5878 -       Opt_acregmax, Opt_acdirmin, Opt_acdirmax,
5879 +       Opt_acregmax, Opt_acdirmin, Opt_acdirmax, Opt_tagid,
5880         /* Options that take no arguments */
5881         Opt_soft, Opt_hard, Opt_intr,
5882         Opt_nointr, Opt_posix, Opt_noposix, Opt_cto, Opt_nocto, Opt_ac, 
5883         Opt_noac, Opt_lock, Opt_nolock, Opt_v2, Opt_v3, Opt_udp, Opt_tcp,
5884 -       Opt_acl, Opt_noacl,
5885 +       Opt_acl, Opt_noacl, Opt_tag, Opt_notag,
5886         /* Error token */
5887         Opt_err
5888  };
5889 @@ -161,6 +161,9 @@ static match_table_t __initconst tokens 
5890         {Opt_tcp, "tcp"},
5891         {Opt_acl, "acl"},
5892         {Opt_noacl, "noacl"},
5893 +       {Opt_tag, "tag"},
5894 +       {Opt_notag, "notag"},
5895 +       {Opt_tagid, "tagid=%u"},
5896         {Opt_err, NULL}
5897         
5898  };
5899 @@ -272,6 +275,20 @@ static int __init root_nfs_parse(char *n
5900                         case Opt_noacl:
5901                                 nfs_data.flags |= NFS_MOUNT_NOACL;
5902                                 break;
5903 +#ifndef CONFIG_TAGGING_NONE
5904 +                       case Opt_tag:
5905 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
5906 +                               break;
5907 +                       case Opt_notag:
5908 +                               nfs_data.flags &= ~NFS_MOUNT_TAGGED;
5909 +                               break;
5910 +#endif
5911 +#ifdef CONFIG_PROPAGATE
5912 +                       case Opt_tagid:
5913 +                               /* use args[0] */
5914 +                               nfs_data.flags |= NFS_MOUNT_TAGGED;
5915 +                               break;
5916 +#endif
5917                         default:
5918                                 printk(KERN_WARNING "Root-NFS: unknown "
5919                                         "option: %s\n", p);
5920 diff -NurpP --minimal linux-2.6.29.4/fs/nfs/super.c linux-2.6.29.4-vs2.3.0.36.14/fs/nfs/super.c
5921 --- linux-2.6.29.4/fs/nfs/super.c       2009-03-24 14:22:26.000000000 +0100
5922 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/nfs/super.c 2009-03-24 16:02:06.000000000 +0100
5923 @@ -51,6 +51,7 @@
5924  #include <linux/nfs_xdr.h>
5925  #include <linux/magic.h>
5926  #include <linux/parser.h>
5927 +#include <linux/vs_tag.h>
5928  
5929  #include <asm/system.h>
5930  #include <asm/uaccess.h>
5931 @@ -517,6 +518,7 @@ static void nfs_show_mount_options(struc
5932                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5933                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5934                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5935 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5936                 { 0, NULL, NULL }
5937         };
5938         const struct proc_nfs_info *nfs_infop;
5939 diff -NurpP --minimal linux-2.6.29.4/fs/nfsd/auth.c linux-2.6.29.4-vs2.3.0.36.14/fs/nfsd/auth.c
5940 --- linux-2.6.29.4/fs/nfsd/auth.c       2009-03-24 14:22:26.000000000 +0100
5941 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/nfsd/auth.c 2009-03-24 16:09:39.000000000 +0100
5942 @@ -10,6 +10,7 @@
5943  #include <linux/sunrpc/svcauth.h>
5944  #include <linux/nfsd/nfsd.h>
5945  #include <linux/nfsd/export.h>
5946 +#include <linux/vs_tag.h>
5947  #include "auth.h"
5948  
5949  int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp)
5950 @@ -42,6 +43,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5951  
5952         new->fsuid = rqstp->rq_cred.cr_uid;
5953         new->fsgid = rqstp->rq_cred.cr_gid;
5954 +       /* FIXME: this desperately needs a tag :)
5955 +       new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5956 +                       */
5957  
5958         rqgi = rqstp->rq_cred.cr_group_info;
5959  
5960 @@ -69,7 +73,7 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5961                 }
5962         } else {
5963                 gi = get_group_info(rqgi);
5964 -       }
5965 +       }
5966  
5967         if (new->fsuid == (uid_t) -1)
5968                 new->fsuid = exp->ex_anon_uid;
5969 @@ -94,6 +98,6 @@ oom:
5970         ret = -ENOMEM;
5971  error:
5972         abort_creds(new);
5973 -       return ret;
5974 +       return ret;
5975  }
5976  
5977 diff -NurpP --minimal linux-2.6.29.4/fs/nfsd/nfs3xdr.c linux-2.6.29.4-vs2.3.0.36.14/fs/nfsd/nfs3xdr.c
5978 --- linux-2.6.29.4/fs/nfsd/nfs3xdr.c    2008-12-25 00:26:37.000000000 +0100
5979 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/nfsd/nfs3xdr.c      2009-02-22 22:54:25.000000000 +0100
5980 @@ -21,6 +21,7 @@
5981  #include <linux/sunrpc/svc.h>
5982  #include <linux/nfsd/nfsd.h>
5983  #include <linux/nfsd/xdr3.h>
5984 +#include <linux/vs_tag.h>
5985  #include "auth.h"
5986  
5987  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5988 @@ -108,6 +109,8 @@ static __be32 *
5989  decode_sattr3(__be32 *p, struct iattr *iap)
5990  {
5991         u32     tmp;
5992 +       uid_t   uid = 0;
5993 +       gid_t   gid = 0;
5994  
5995         iap->ia_valid = 0;
5996  
5997 @@ -117,12 +120,15 @@ decode_sattr3(__be32 *p, struct iattr *i
5998         }
5999         if (*p++) {
6000                 iap->ia_valid |= ATTR_UID;
6001 -               iap->ia_uid = ntohl(*p++);
6002 +               uid = ntohl(*p++);
6003         }
6004         if (*p++) {
6005                 iap->ia_valid |= ATTR_GID;
6006 -               iap->ia_gid = ntohl(*p++);
6007 +               gid = ntohl(*p++);
6008         }
6009 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6010 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6011 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6012         if (*p++) {
6013                 u64     newsize;
6014  
6015 @@ -178,8 +184,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
6016         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
6017         *p++ = htonl((u32) stat->mode);
6018         *p++ = htonl((u32) stat->nlink);
6019 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6020 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6021 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6022 +               TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6023 +               stat->uid, stat->tag)));
6024 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6025 +               TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
6026 +               stat->gid, stat->tag)));
6027         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
6028                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
6029         } else {
6030 diff -NurpP --minimal linux-2.6.29.4/fs/nfsd/nfs4xdr.c linux-2.6.29.4-vs2.3.0.36.14/fs/nfsd/nfs4xdr.c
6031 --- linux-2.6.29.4/fs/nfsd/nfs4xdr.c    2009-05-23 23:16:53.000000000 +0200
6032 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/nfsd/nfs4xdr.c      2009-05-23 23:19:11.000000000 +0200
6033 @@ -56,6 +56,7 @@
6034  #include <linux/nfs4_acl.h>
6035  #include <linux/sunrpc/gss_api.h>
6036  #include <linux/sunrpc/svcauth_gss.h>
6037 +#include <linux/vs_tag.h>
6038  
6039  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6040  
6041 @@ -1714,14 +1715,18 @@ out_acl:
6042                 WRITE32(stat.nlink);
6043         }
6044         if (bmval1 & FATTR4_WORD1_OWNER) {
6045 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
6046 +               status = nfsd4_encode_user(rqstp,
6047 +                       TAGINO_UID(DX_TAG(dentry->d_inode),
6048 +                       stat.uid, stat.tag), &p, &buflen);
6049                 if (status == nfserr_resource)
6050                         goto out_resource;
6051                 if (status)
6052                         goto out;
6053         }
6054         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
6055 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
6056 +               status = nfsd4_encode_group(rqstp,
6057 +                       TAGINO_GID(DX_TAG(dentry->d_inode),
6058 +                       stat.gid, stat.tag), &p, &buflen);
6059                 if (status == nfserr_resource)
6060                         goto out_resource;
6061                 if (status)
6062 diff -NurpP --minimal linux-2.6.29.4/fs/nfsd/nfsxdr.c linux-2.6.29.4-vs2.3.0.36.14/fs/nfsd/nfsxdr.c
6063 --- linux-2.6.29.4/fs/nfsd/nfsxdr.c     2008-12-25 00:26:37.000000000 +0100
6064 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/nfsd/nfsxdr.c       2009-02-22 22:54:25.000000000 +0100
6065 @@ -15,6 +15,7 @@
6066  #include <linux/nfsd/nfsd.h>
6067  #include <linux/nfsd/xdr.h>
6068  #include <linux/mm.h>
6069 +#include <linux/vs_tag.h>
6070  #include "auth.h"
6071  
6072  #define NFSDDBG_FACILITY               NFSDDBG_XDR
6073 @@ -98,6 +99,8 @@ static __be32 *
6074  decode_sattr(__be32 *p, struct iattr *iap)
6075  {
6076         u32     tmp, tmp1;
6077 +       uid_t   uid = 0;
6078 +       gid_t   gid = 0;
6079  
6080         iap->ia_valid = 0;
6081  
6082 @@ -111,12 +114,15 @@ decode_sattr(__be32 *p, struct iattr *ia
6083         }
6084         if ((tmp = ntohl(*p++)) != (u32)-1) {
6085                 iap->ia_valid |= ATTR_UID;
6086 -               iap->ia_uid = tmp;
6087 +               uid = tmp;
6088         }
6089         if ((tmp = ntohl(*p++)) != (u32)-1) {
6090                 iap->ia_valid |= ATTR_GID;
6091 -               iap->ia_gid = tmp;
6092 +               gid = tmp;
6093         }
6094 +       iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
6095 +       iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
6096 +       iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
6097         if ((tmp = ntohl(*p++)) != (u32)-1) {
6098                 iap->ia_valid |= ATTR_SIZE;
6099                 iap->ia_size = tmp;
6100 @@ -161,8 +167,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
6101         *p++ = htonl(nfs_ftypes[type >> 12]);
6102         *p++ = htonl((u32) stat->mode);
6103         *p++ = htonl((u32) stat->nlink);
6104 -       *p++ = htonl((u32) nfsd_ruid(rqstp, stat->uid));
6105 -       *p++ = htonl((u32) nfsd_rgid(rqstp, stat->gid));
6106 +       *p++ = htonl((u32) nfsd_ruid(rqstp,
6107 +               TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
6108 +       *p++ = htonl((u32) nfsd_rgid(rqstp,
6109 +               TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
6110  
6111         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
6112                 *p++ = htonl(NFS_MAXPATHLEN);
6113 diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/dlm/dlmfs.c linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/dlm/dlmfs.c
6114 --- linux-2.6.29.4/fs/ocfs2/dlm/dlmfs.c 2009-03-24 14:22:27.000000000 +0100
6115 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/dlm/dlmfs.c   2009-03-24 16:10:48.000000000 +0100
6116 @@ -43,6 +43,7 @@
6117  #include <linux/init.h>
6118  #include <linux/string.h>
6119  #include <linux/backing-dev.h>
6120 +#include <linux/vs_tag.h>
6121  
6122  #include <asm/uaccess.h>
6123  
6124 @@ -341,6 +342,7 @@ static struct inode *dlmfs_get_root_inod
6125                 inode->i_mode = mode;
6126                 inode->i_uid = current_fsuid();
6127                 inode->i_gid = current_fsgid();
6128 +               inode->i_tag = dx_current_fstag(sb);
6129                 inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
6130                 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
6131                 inc_nlink(inode);
6132 @@ -366,6 +368,7 @@ static struct inode *dlmfs_get_inode(str
6133         inode->i_mode = mode;
6134         inode->i_uid = current_fsuid();
6135         inode->i_gid = current_fsgid();
6136 +       inode->i_tag = dx_current_fstag(sb);
6137         inode->i_mapping->backing_dev_info = &dlmfs_backing_dev_info;
6138         inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
6139  
6140 diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/dlmglue.c linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/dlmglue.c
6141 --- linux-2.6.29.4/fs/ocfs2/dlmglue.c   2009-03-24 14:22:27.000000000 +0100
6142 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/dlmglue.c     2009-03-24 14:48:35.000000000 +0100
6143 @@ -1885,6 +1885,7 @@ static void __ocfs2_stuff_meta_lvb(struc
6144         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
6145         lvb->lvb_iuid      = cpu_to_be32(inode->i_uid);
6146         lvb->lvb_igid      = cpu_to_be32(inode->i_gid);
6147 +       lvb->lvb_itag      = cpu_to_be16(inode->i_tag);
6148         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
6149         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
6150         lvb->lvb_iatime_packed  =
6151 @@ -1939,6 +1940,7 @@ static void ocfs2_refresh_inode_from_lvb
6152  
6153         inode->i_uid     = be32_to_cpu(lvb->lvb_iuid);
6154         inode->i_gid     = be32_to_cpu(lvb->lvb_igid);
6155 +       inode->i_tag     = be16_to_cpu(lvb->lvb_itag);
6156         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
6157         inode->i_nlink   = be16_to_cpu(lvb->lvb_inlink);
6158         ocfs2_unpack_timespec(&inode->i_atime,
6159 diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/dlmglue.h linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/dlmglue.h
6160 --- linux-2.6.29.4/fs/ocfs2/dlmglue.h   2009-03-24 14:22:27.000000000 +0100
6161 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/dlmglue.h     2009-03-24 14:48:35.000000000 +0100
6162 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
6163         __be16       lvb_inlink;
6164         __be32       lvb_iattr;
6165         __be32       lvb_igeneration;
6166 -       __be32       lvb_reserved2;
6167 +       __be16       lvb_itag;
6168 +       __be16       lvb_reserved2;
6169  };
6170  
6171  #define OCFS2_QINFO_LVB_VERSION 1
6172 diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/file.c linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/file.c
6173 --- linux-2.6.29.4/fs/ocfs2/file.c      2009-05-23 23:16:53.000000000 +0200
6174 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/file.c        2009-05-23 23:19:11.000000000 +0200
6175 @@ -911,13 +911,15 @@ int ocfs2_setattr(struct dentry *dentry,
6176                 mlog(0, "uid change: %d\n", attr->ia_uid);
6177         if (attr->ia_valid & ATTR_GID)
6178                 mlog(0, "gid change: %d\n", attr->ia_gid);
6179 +       if (attr->ia_valid & ATTR_TAG)
6180 +               mlog(0, "tag change: %d\n", attr->ia_tag);
6181         if (attr->ia_valid & ATTR_SIZE)
6182                 mlog(0, "size change...\n");
6183         if (attr->ia_valid & (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME))
6184                 mlog(0, "time change...\n");
6185  
6186  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
6187 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
6188 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
6189         if (!(attr->ia_valid & OCFS2_VALID_ATTRS)) {
6190                 mlog(0, "can't handle attrs: 0x%x\n", attr->ia_valid);
6191                 return 0;
6192 @@ -2128,6 +2130,7 @@ const struct inode_operations ocfs2_file
6193         .removexattr    = generic_removexattr,
6194         .fallocate      = ocfs2_fallocate,
6195         .fiemap         = ocfs2_fiemap,
6196 +       .sync_flags     = ocfs2_sync_flags,
6197  };
6198  
6199  const struct inode_operations ocfs2_special_file_iops = {
6200 diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/inode.c linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/inode.c
6201 --- linux-2.6.29.4/fs/ocfs2/inode.c     2009-03-24 14:22:27.000000000 +0100
6202 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/inode.c       2009-03-24 16:11:11.000000000 +0100
6203 @@ -29,6 +29,7 @@
6204  #include <linux/highmem.h>
6205  #include <linux/pagemap.h>
6206  #include <linux/quotaops.h>
6207 +#include <linux/vs_tag.h>
6208  
6209  #include <asm/byteorder.h>
6210  
6211 @@ -44,6 +45,7 @@
6212  #include "file.h"
6213  #include "heartbeat.h"
6214  #include "inode.h"
6215 +#include "ioctl.h"
6216  #include "journal.h"
6217  #include "namei.h"
6218  #include "suballoc.h"
6219 @@ -77,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode 
6220  {
6221         unsigned int flags = OCFS2_I(inode)->ip_attr;
6222  
6223 -       inode->i_flags &= ~(S_IMMUTABLE |
6224 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
6225                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
6226  
6227         if (flags & OCFS2_IMMUTABLE_FL)
6228                 inode->i_flags |= S_IMMUTABLE;
6229 +       if (flags & OCFS2_IXUNLINK_FL)
6230 +               inode->i_flags |= S_IXUNLINK;
6231  
6232         if (flags & OCFS2_SYNC_FL)
6233                 inode->i_flags |= S_SYNC;
6234 @@ -91,25 +95,85 @@ void ocfs2_set_inode_flags(struct inode 
6235                 inode->i_flags |= S_NOATIME;
6236         if (flags & OCFS2_DIRSYNC_FL)
6237                 inode->i_flags |= S_DIRSYNC;
6238 +
6239 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
6240 +
6241 +       if (flags & OCFS2_BARRIER_FL)
6242 +               inode->i_vflags |= V_BARRIER;
6243 +       if (flags & OCFS2_COW_FL)
6244 +               inode->i_vflags |= V_COW;
6245  }
6246  
6247  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
6248  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
6249  {
6250         unsigned int flags = oi->vfs_inode.i_flags;
6251 +       unsigned int vflags = oi->vfs_inode.i_vflags;
6252 +
6253 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
6254 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
6255 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
6256 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
6257 +
6258 +       if (flags & S_IMMUTABLE)
6259 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6260 +       if (flags & S_IXUNLINK)
6261 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
6262  
6263 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
6264 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
6265         if (flags & S_SYNC)
6266                 oi->ip_attr |= OCFS2_SYNC_FL;
6267         if (flags & S_APPEND)
6268                 oi->ip_attr |= OCFS2_APPEND_FL;
6269 -       if (flags & S_IMMUTABLE)
6270 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
6271         if (flags & S_NOATIME)
6272                 oi->ip_attr |= OCFS2_NOATIME_FL;
6273         if (flags & S_DIRSYNC)
6274                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
6275 +
6276 +       if (vflags & V_BARRIER)
6277 +               oi->ip_attr |= OCFS2_BARRIER_FL;
6278 +       if (vflags & V_COW)
6279 +               oi->ip_attr |= OCFS2_COW_FL;
6280 +}
6281 +
6282 +int ocfs2_sync_flags(struct inode *inode)
6283 +{
6284 +       struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
6285 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
6286 +       handle_t *handle = NULL;
6287 +       struct buffer_head *bh = NULL;
6288 +       int status;
6289 +
6290 +       status = ocfs2_inode_lock(inode, &bh, 1);
6291 +       if (status < 0) {
6292 +               mlog_errno(status);
6293 +               goto bail;
6294 +       }
6295 +
6296 +       status = -EROFS;
6297 +       if (IS_RDONLY(inode))
6298 +               goto bail_unlock;
6299 +
6300 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6301 +       if (IS_ERR(handle)) {
6302 +               status = PTR_ERR(handle);
6303 +               mlog_errno(status);
6304 +               goto bail_unlock;
6305 +       }
6306 +
6307 +       ocfs2_get_inode_flags(ocfs2_inode);
6308 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
6309 +       if (status < 0)
6310 +               mlog_errno(status);
6311 +
6312 +       ocfs2_commit_trans(osb, handle);
6313 +bail_unlock:
6314 +       ocfs2_inode_unlock(inode, 1);
6315 +bail:
6316 +       if (bh)
6317 +               brelse(bh);
6318 +
6319 +       mlog_exit(status);
6320 +       return status;
6321  }
6322  
6323  struct inode *ocfs2_iget(struct ocfs2_super *osb, u64 blkno, unsigned flags,
6324 @@ -222,6 +286,8 @@ void ocfs2_populate_inode(struct inode *
6325         struct super_block *sb;
6326         struct ocfs2_super *osb;
6327         int use_plocks = 1;
6328 +       uid_t uid;
6329 +       gid_t gid;
6330  
6331         mlog_entry("(0x%p, size:%llu)\n", inode,
6332                    (unsigned long long)le64_to_cpu(fe->i_size));
6333 @@ -253,8 +319,12 @@ void ocfs2_populate_inode(struct inode *
6334         inode->i_generation = le32_to_cpu(fe->i_generation);
6335         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
6336         inode->i_mode = le16_to_cpu(fe->i_mode);
6337 -       inode->i_uid = le32_to_cpu(fe->i_uid);
6338 -       inode->i_gid = le32_to_cpu(fe->i_gid);
6339 +       uid = le32_to_cpu(fe->i_uid);
6340 +       gid = le32_to_cpu(fe->i_gid);
6341 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6342 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6343 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
6344 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
6345  
6346         /* Fast symlinks will have i_size but no allocated clusters. */
6347         if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
6348 @@ -1206,8 +1276,11 @@ int ocfs2_mark_inode_dirty(handle_t *han
6349  
6350         fe->i_size = cpu_to_le64(i_size_read(inode));
6351         fe->i_links_count = cpu_to_le16(inode->i_nlink);
6352 -       fe->i_uid = cpu_to_le32(inode->i_uid);
6353 -       fe->i_gid = cpu_to_le32(inode->i_gid);
6354 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode),
6355 +               inode->i_uid, inode->i_tag));
6356 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode),
6357 +               inode->i_gid, inode->i_tag));
6358 +       /* i_tag = = cpu_to_le16(inode->i_tag); */
6359         fe->i_mode = cpu_to_le16(inode->i_mode);
6360         fe->i_atime = cpu_to_le64(inode->i_atime.tv_sec);
6361         fe->i_atime_nsec = cpu_to_le32(inode->i_atime.tv_nsec);
6362 @@ -1235,16 +1308,25 @@ leave:
6363  void ocfs2_refresh_inode(struct inode *inode,
6364                          struct ocfs2_dinode *fe)
6365  {
6366 +       uid_t uid;
6367 +       gid_t gid;
6368 +
6369         spin_lock(&OCFS2_I(inode)->ip_lock);
6370  
6371         OCFS2_I(inode)->ip_clusters = le32_to_cpu(fe->i_clusters);
6372         OCFS2_I(inode)->ip_attr = le32_to_cpu(fe->i_attr);
6373 +       /* OCFS2_I(inode)->ip_flags &= ~OCFS2_FL_MASK;
6374 +          OCFS2_I(inode)->ip_flags |= le32_to_cpu(fe->i_flags) & OCFS2_FL_MASK; */
6375         OCFS2_I(inode)->ip_dyn_features = le16_to_cpu(fe->i_dyn_features);
6376         ocfs2_set_inode_flags(inode);
6377         i_size_write(inode, le64_to_cpu(fe->i_size));
6378         inode->i_nlink = le16_to_cpu(fe->i_links_count);
6379 -       inode->i_uid = le32_to_cpu(fe->i_uid);
6380 -       inode->i_gid = le32_to_cpu(fe->i_gid);
6381 +       uid = le32_to_cpu(fe->i_uid);
6382 +       gid = le32_to_cpu(fe->i_gid);
6383 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
6384 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
6385 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid,
6386 +               /* le16_to_cpu(raw_inode->i_raw_tag)i */ 0);
6387         inode->i_mode = le16_to_cpu(fe->i_mode);
6388         if (S_ISLNK(inode->i_mode) && le32_to_cpu(fe->i_clusters) == 0)
6389                 inode->i_blocks = 0;
6390 diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/inode.h linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/inode.h
6391 --- linux-2.6.29.4/fs/ocfs2/inode.h     2009-03-24 14:22:27.000000000 +0100
6392 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/inode.h       2009-03-24 14:48:35.000000000 +0100
6393 @@ -147,6 +147,7 @@ struct buffer_head *ocfs2_bread(struct i
6394  
6395  void ocfs2_set_inode_flags(struct inode *inode);
6396  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
6397 +int ocfs2_sync_flags(struct inode *inode);
6398  
6399  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
6400  {
6401 diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/ioctl.c linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/ioctl.c
6402 --- linux-2.6.29.4/fs/ocfs2/ioctl.c     2008-12-25 00:26:37.000000000 +0100
6403 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/ioctl.c       2009-02-22 22:54:25.000000000 +0100
6404 @@ -42,7 +42,7 @@ static int ocfs2_get_inode_attr(struct i
6405         return status;
6406  }
6407  
6408 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6409 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6410                                 unsigned mask)
6411  {
6412         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
6413 @@ -67,6 +67,11 @@ static int ocfs2_set_inode_attr(struct i
6414         if (!S_ISDIR(inode->i_mode))
6415                 flags &= ~OCFS2_DIRSYNC_FL;
6416  
6417 +       if (IS_BARRIER(inode)) {
6418 +               vxwprintk_task(1, "messing with the barrier.");
6419 +               goto bail_unlock;
6420 +       }
6421 +
6422         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
6423         if (IS_ERR(handle)) {
6424                 status = PTR_ERR(handle);
6425 diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/ioctl.h linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/ioctl.h
6426 --- linux-2.6.29.4/fs/ocfs2/ioctl.h     2008-12-25 00:26:37.000000000 +0100
6427 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/ioctl.h       2009-02-22 22:54:25.000000000 +0100
6428 @@ -10,6 +10,9 @@
6429  #ifndef OCFS2_IOCTL_H
6430  #define OCFS2_IOCTL_H
6431  
6432 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
6433 +                               unsigned mask);
6434 +
6435  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
6436  long ocfs2_compat_ioctl(struct file *file, unsigned cmd, unsigned long arg);
6437  
6438 diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/namei.c linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/namei.c
6439 --- linux-2.6.29.4/fs/ocfs2/namei.c     2009-03-24 14:22:27.000000000 +0100
6440 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/namei.c       2009-03-25 01:04:31.000000000 +0100
6441 @@ -41,6 +41,7 @@
6442  #include <linux/slab.h>
6443  #include <linux/highmem.h>
6444  #include <linux/quotaops.h>
6445 +#include <linux/vs_tag.h>
6446  
6447  #define MLOG_MASK_PREFIX ML_NAMEI
6448  #include <cluster/masklog.h>
6449 @@ -462,6 +463,7 @@ static int ocfs2_mknod_locked(struct ocf
6450         struct ocfs2_extent_list *fel;
6451         u64 fe_blkno = 0;
6452         u16 suballoc_bit;
6453 +       tag_t tag;
6454  
6455         mlog_entry("(0x%p, 0x%p, %d, %lu, '%.*s')\n", dir, dentry,
6456                    inode->i_mode, (unsigned long)dev, dentry->d_name.len,
6457 @@ -508,8 +510,11 @@ static int ocfs2_mknod_locked(struct ocf
6458         fe->i_blkno = cpu_to_le64(fe_blkno);
6459         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
6460         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
6461 -       fe->i_uid = cpu_to_le32(inode->i_uid);
6462 -       fe->i_gid = cpu_to_le32(inode->i_gid);
6463 +
6464 +       tag = dx_current_fstag(osb->sb);
6465 +       fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), inode->i_uid, tag));
6466 +       fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), inode->i_gid, tag));
6467 +       inode->i_tag = tag;
6468         fe->i_mode = cpu_to_le16(inode->i_mode);
6469         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
6470                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
6471 @@ -2025,6 +2030,7 @@ const struct inode_operations ocfs2_dir_
6472         .rename         = ocfs2_rename,
6473         .setattr        = ocfs2_setattr,
6474         .getattr        = ocfs2_getattr,
6475 +       .sync_flags     = ocfs2_sync_flags,
6476         .permission     = ocfs2_permission,
6477         .setxattr       = generic_setxattr,
6478         .getxattr       = generic_getxattr,
6479 diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/ocfs2_fs.h linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/ocfs2_fs.h
6480 --- linux-2.6.29.4/fs/ocfs2/ocfs2_fs.h  2009-03-24 14:22:27.000000000 +0100
6481 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/ocfs2_fs.h    2009-03-24 14:48:35.000000000 +0100
6482 @@ -219,18 +219,23 @@
6483  #define OCFS2_INDEXED_DIR_FL   (0x0008)
6484  
6485  /* Inode attributes, keep in sync with EXT2 */
6486 -#define OCFS2_SECRM_FL         (0x00000001)    /* Secure deletion */
6487 -#define OCFS2_UNRM_FL          (0x00000002)    /* Undelete */
6488 -#define OCFS2_COMPR_FL         (0x00000004)    /* Compress file */
6489 -#define OCFS2_SYNC_FL          (0x00000008)    /* Synchronous updates */
6490 -#define OCFS2_IMMUTABLE_FL     (0x00000010)    /* Immutable file */
6491 -#define OCFS2_APPEND_FL                (0x00000020)    /* writes to file may only append */
6492 -#define OCFS2_NODUMP_FL                (0x00000040)    /* do not dump file */
6493 -#define OCFS2_NOATIME_FL       (0x00000080)    /* do not update atime */
6494 -#define OCFS2_DIRSYNC_FL       (0x00010000)    /* dirsync behaviour (directories only) */
6495 +#define OCFS2_SECRM_FL         FS_SECRM_FL     /* Secure deletion */
6496 +#define OCFS2_UNRM_FL          FS_UNRM_FL      /* Undelete */
6497 +#define OCFS2_COMPR_FL         FS_COMPR_FL     /* Compress file */
6498 +#define OCFS2_SYNC_FL          FS_SYNC_FL      /* Synchronous updates */
6499 +#define OCFS2_IMMUTABLE_FL     FS_IMMUTABLE_FL /* Immutable file */
6500 +#define OCFS2_APPEND_FL                FS_APPEND_FL    /* writes to file may only append */
6501 +#define OCFS2_NODUMP_FL                FS_NODUMP_FL    /* do not dump file */
6502 +#define OCFS2_NOATIME_FL       FS_NOATIME_FL   /* do not update atime */
6503  
6504 -#define OCFS2_FL_VISIBLE       (0x000100FF)    /* User visible flags */
6505 -#define OCFS2_FL_MODIFIABLE    (0x000100FF)    /* User modifiable flags */
6506 +#define OCFS2_DIRSYNC_FL       FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
6507 +#define OCFS2_IXUNLINK_FL      FS_IXUNLINK_FL  /* Immutable invert on unlink */
6508 +
6509 +#define OCFS2_BARRIER_FL       FS_BARRIER_FL   /* Barrier for chroot() */
6510 +#define OCFS2_COW_FL           FS_COW_FL       /* Copy on Write marker */
6511 +
6512 +#define OCFS2_FL_VISIBLE       (0x010300FF)    /* User visible flags */
6513 +#define OCFS2_FL_MODIFIABLE    (0x010300FF)    /* User modifiable flags */
6514  
6515  /*
6516   * Extent record flags (e_node.leaf.flags)
6517 diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/ocfs2.h linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/ocfs2.h
6518 --- linux-2.6.29.4/fs/ocfs2/ocfs2.h     2009-03-24 14:22:27.000000000 +0100
6519 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/ocfs2.h       2009-03-24 16:18:22.000000000 +0100
6520 @@ -199,6 +199,7 @@ enum ocfs2_mount_options
6521         OCFS2_MOUNT_POSIX_ACL = 1 << 8, /* POSIX access control lists */
6522         OCFS2_MOUNT_USRQUOTA = 1 << 9, /* We support user quotas */
6523         OCFS2_MOUNT_GRPQUOTA = 1 << 10, /* We support group quotas */
6524 +       OCFS2_MOUNT_TAGGED = 1 << 11, /* use tagging */
6525  };
6526  
6527  #define OCFS2_OSB_SOFT_RO      0x0001
6528 diff -NurpP --minimal linux-2.6.29.4/fs/ocfs2/super.c linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/super.c
6529 --- linux-2.6.29.4/fs/ocfs2/super.c     2009-03-24 14:22:27.000000000 +0100
6530 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/ocfs2/super.c       2009-03-24 16:19:44.000000000 +0100
6531 @@ -172,6 +172,7 @@ enum {
6532         Opt_noacl,
6533         Opt_usrquota,
6534         Opt_grpquota,
6535 +       Opt_tag, Opt_notag, Opt_tagid,
6536         Opt_err,
6537  };
6538  
6539 @@ -198,6 +199,9 @@ static const match_table_t tokens = {
6540         {Opt_noacl, "noacl"},
6541         {Opt_usrquota, "usrquota"},
6542         {Opt_grpquota, "grpquota"},
6543 +       {Opt_tag, "tag"},
6544 +       {Opt_notag, "notag"},
6545 +       {Opt_tagid, "tagid=%u"},
6546         {Opt_err, NULL}
6547  };
6548  
6549 @@ -436,6 +440,13 @@ static int ocfs2_remount(struct super_bl
6550                 goto out;
6551         }
6552  
6553 +       if ((parsed_options.mount_opt & OCFS2_MOUNT_TAGGED) &&
6554 +               !(sb->s_flags & MS_TAGGED)) {
6555 +               ret = -EINVAL;
6556 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
6557 +               goto out;
6558 +       }
6559 +
6560         if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
6561             (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
6562                 ret = -EINVAL;
6563 @@ -950,6 +961,9 @@ static int ocfs2_fill_super(struct super
6564  
6565         ocfs2_complete_mount_recovery(osb);
6566  
6567 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
6568 +               sb->s_flags |= MS_TAGGED;
6569 +
6570         if (ocfs2_mount_local(osb))
6571                 snprintf(nodestr, sizeof(nodestr), "local");
6572         else
6573 @@ -1208,6 +1222,20 @@ static int ocfs2_parse_options(struct su
6574                         printk(KERN_INFO "ocfs2 (no)acl options not supported\n");
6575                         break;
6576  #endif
6577 +#ifndef CONFIG_TAGGING_NONE
6578 +               case Opt_tag:
6579 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6580 +                       break;
6581 +               case Opt_notag:
6582 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
6583 +                       break;
6584 +#endif
6585 +#ifdef CONFIG_PROPAGATE
6586 +               case Opt_tagid:
6587 +                       /* use args[0] */
6588 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
6589 +                       break;
6590 +#endif
6591                 default:
6592                         mlog(ML_ERROR,
6593                              "Unrecognized mount option \"%s\" "
6594 diff -NurpP --minimal linux-2.6.29.4/fs/open.c linux-2.6.29.4-vs2.3.0.36.14/fs/open.c
6595 --- linux-2.6.29.4/fs/open.c    2009-03-24 14:22:27.000000000 +0100
6596 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/open.c      2009-03-24 14:48:35.000000000 +0100
6597 @@ -29,22 +29,31 @@
6598  #include <linux/rcupdate.h>
6599  #include <linux/audit.h>
6600  #include <linux/falloc.h>
6601 +#include <linux/vs_base.h>
6602 +#include <linux/vs_limit.h>
6603 +#include <linux/vs_dlimit.h>
6604 +#include <linux/vs_tag.h>
6605 +#include <linux/vs_cowbl.h>
6606  
6607  int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)
6608  {
6609         int retval = -ENODEV;
6610  
6611         if (dentry) {
6612 +               struct super_block *sb = dentry->d_sb;
6613 +
6614                 retval = -ENOSYS;
6615 -               if (dentry->d_sb->s_op->statfs) {
6616 +               if (sb->s_op->statfs) {
6617                         memset(buf, 0, sizeof(*buf));
6618                         retval = security_sb_statfs(dentry);
6619                         if (retval)
6620                                 return retval;
6621 -                       retval = dentry->d_sb->s_op->statfs(dentry, buf);
6622 +                       retval = sb->s_op->statfs(dentry, buf);
6623                         if (retval == 0 && buf->f_frsize == 0)
6624                                 buf->f_frsize = buf->f_bsize;
6625                 }
6626 +               if (!vx_check(0, VS_ADMIN|VS_WATCH))
6627 +                       vx_vsi_statfs(sb, buf);
6628         }
6629         return retval;
6630  }
6631 @@ -638,6 +647,10 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6632         error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
6633         if (error)
6634                 goto out;
6635 +
6636 +       error = cow_check_and_break(&path);
6637 +       if (error)
6638 +               goto dput_and_out;
6639         inode = path.dentry->d_inode;
6640  
6641         error = mnt_want_write(path.mnt);
6642 @@ -671,11 +684,11 @@ static int chown_common(struct dentry * 
6643         newattrs.ia_valid =  ATTR_CTIME;
6644         if (user != (uid_t) -1) {
6645                 newattrs.ia_valid |= ATTR_UID;
6646 -               newattrs.ia_uid = user;
6647 +               newattrs.ia_uid = dx_map_uid(user);
6648         }
6649         if (group != (gid_t) -1) {
6650                 newattrs.ia_valid |= ATTR_GID;
6651 -               newattrs.ia_gid = group;
6652 +               newattrs.ia_gid = dx_map_gid(group);
6653         }
6654         if (!S_ISDIR(inode->i_mode))
6655                 newattrs.ia_valid |=
6656 @@ -698,7 +711,11 @@ SYSCALL_DEFINE3(chown, const char __user
6657         error = mnt_want_write(path.mnt);
6658         if (error)
6659                 goto out_release;
6660 -       error = chown_common(path.dentry, user, group);
6661 +#ifdef CONFIG_VSERVER_COWBL
6662 +       error = cow_check_and_break(&path);
6663 +       if (!error)
6664 +#endif
6665 +               error = chown_common(path.dentry, user, group);
6666         mnt_drop_write(path.mnt);
6667  out_release:
6668         path_put(&path);
6669 @@ -723,7 +740,11 @@ SYSCALL_DEFINE5(fchownat, int, dfd, cons
6670         error = mnt_want_write(path.mnt);
6671         if (error)
6672                 goto out_release;
6673 -       error = chown_common(path.dentry, user, group);
6674 +#ifdef CONFIG_VSERVER_COWBL
6675 +       error = cow_check_and_break(&path);
6676 +       if (!error)
6677 +#endif
6678 +               error = chown_common(path.dentry, user, group);
6679         mnt_drop_write(path.mnt);
6680  out_release:
6681         path_put(&path);
6682 @@ -742,7 +763,11 @@ SYSCALL_DEFINE3(lchown, const char __use
6683         error = mnt_want_write(path.mnt);
6684         if (error)
6685                 goto out_release;
6686 -       error = chown_common(path.dentry, user, group);
6687 +#ifdef CONFIG_VSERVER_COWBL
6688 +       error = cow_check_and_break(&path);
6689 +       if (!error)
6690 +#endif
6691 +               error = chown_common(path.dentry, user, group);
6692         mnt_drop_write(path.mnt);
6693  out_release:
6694         path_put(&path);
6695 @@ -986,6 +1011,7 @@ static void __put_unused_fd(struct files
6696         __FD_CLR(fd, fdt->open_fds);
6697         if (fd < files->next_fd)
6698                 files->next_fd = fd;
6699 +       vx_openfd_dec(fd);
6700  }
6701  
6702  void put_unused_fd(unsigned int fd)
6703 diff -NurpP --minimal linux-2.6.29.4/fs/proc/array.c linux-2.6.29.4-vs2.3.0.36.14/fs/proc/array.c
6704 --- linux-2.6.29.4/fs/proc/array.c      2009-05-23 23:16:53.000000000 +0200
6705 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/proc/array.c        2009-05-10 23:42:01.000000000 +0200
6706 @@ -82,6 +82,8 @@
6707  #include <linux/pid_namespace.h>
6708  #include <linux/ptrace.h>
6709  #include <linux/tracehook.h>
6710 +#include <linux/vs_context.h>
6711 +#include <linux/vs_network.h>
6712  
6713  #include <asm/pgtable.h>
6714  #include <asm/processor.h>
6715 @@ -138,8 +140,9 @@ static const char *task_state_array[] = 
6716         "D (disk sleep)",       /*  2 */
6717         "T (stopped)",          /*  4 */
6718         "T (tracing stop)",     /*  8 */
6719 -       "Z (zombie)",           /* 16 */
6720 -       "X (dead)"              /* 32 */
6721 +       "H (on hold)",          /* 16 */
6722 +       "Z (zombie)",           /* 32 */
6723 +       "X (dead)",             /* 64 */
6724  };
6725  
6726  static inline const char *get_task_state(struct task_struct *tsk)
6727 @@ -166,6 +169,9 @@ static inline void task_state(struct seq
6728         rcu_read_lock();
6729         ppid = pid_alive(p) ?
6730                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6731 +       if (unlikely(vx_current_initpid(p->pid)))
6732 +               ppid = 0;
6733 +
6734         tpid = 0;
6735         if (pid_alive(p)) {
6736                 struct task_struct *tracer = tracehook_tracer_task(p);
6737 @@ -281,7 +287,7 @@ static inline void task_sig(struct seq_f
6738  }
6739  
6740  static void render_cap_t(struct seq_file *m, const char *header,
6741 -                       kernel_cap_t *a)
6742 +                       struct vx_info *vxi, kernel_cap_t *a)
6743  {
6744         unsigned __capi;
6745  
6746 @@ -306,10 +312,11 @@ static inline void task_cap(struct seq_f
6747         cap_bset        = cred->cap_bset;
6748         rcu_read_unlock();
6749  
6750 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
6751 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
6752 -       render_cap_t(m, "CapEff:\t", &cap_effective);
6753 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
6754 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6755 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6756 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6757 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6758 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6759  }
6760  
6761  static inline void task_context_switch_counts(struct seq_file *m,
6762 @@ -321,6 +328,42 @@ static inline void task_context_switch_c
6763                         p->nivcsw);
6764  }
6765  
6766 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6767 +                       struct pid *pid, struct task_struct *task)
6768 +{
6769 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6770 +                       "Count:\t%u\n"
6771 +                       "uts:\t%p(%c)\n"
6772 +                       "ipc:\t%p(%c)\n"
6773 +                       "mnt:\t%p(%c)\n"
6774 +                       "pid:\t%p(%c)\n"
6775 +                       "net:\t%p(%c)\n",
6776 +                       task->nsproxy,
6777 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6778 +                       atomic_read(&task->nsproxy->count),
6779 +                       task->nsproxy->uts_ns,
6780 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6781 +                       task->nsproxy->ipc_ns,
6782 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6783 +                       task->nsproxy->mnt_ns,
6784 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6785 +                       task->nsproxy->pid_ns,
6786 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6787 +                       task->nsproxy->net_ns,
6788 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6789 +       return 0;
6790 +}
6791 +
6792 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6793 +{
6794 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6795 +               return;
6796 +
6797 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6798 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6799 +}
6800 +
6801 +
6802  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6803                         struct pid *pid, struct task_struct *task)
6804  {
6805 @@ -336,6 +379,7 @@ int proc_pid_status(struct seq_file *m, 
6806         task_sig(m, task);
6807         task_cap(m, task);
6808         cpuset_task_status_allowed(m, task);
6809 +       task_vs_id(m, task);
6810  #if defined(CONFIG_S390)
6811         task_show_regs(m, task);
6812  #endif
6813 @@ -452,6 +496,17 @@ static int do_task_stat(struct seq_file 
6814         /* convert nsec -> ticks */
6815         start_time = nsec_to_clock_t(start_time);
6816  
6817 +       /* fixup start time for virt uptime */
6818 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6819 +               unsigned long long bias =
6820 +                       current->vx_info->cvirt.bias_clock;
6821 +
6822 +               if (start_time > bias)
6823 +                       start_time -= bias;
6824 +               else
6825 +                       start_time = 0;
6826 +       }
6827 +
6828         seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \
6829  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
6830  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
6831 diff -NurpP --minimal linux-2.6.29.4/fs/proc/base.c linux-2.6.29.4-vs2.3.0.36.14/fs/proc/base.c
6832 --- linux-2.6.29.4/fs/proc/base.c       2009-05-23 23:16:53.000000000 +0200
6833 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/proc/base.c 2009-05-10 23:42:01.000000000 +0200
6834 @@ -80,6 +80,8 @@
6835  #include <linux/oom.h>
6836  #include <linux/elf.h>
6837  #include <linux/pid_namespace.h>
6838 +#include <linux/vs_context.h>
6839 +#include <linux/vs_network.h>
6840  #include "internal.h"
6841  
6842  /* NOTE:
6843 @@ -1443,6 +1445,8 @@ static struct inode *proc_pid_make_inode
6844                 inode->i_gid = cred->egid;
6845                 rcu_read_unlock();
6846         }
6847 +       /* procfs is xid tagged */
6848 +       inode->i_tag = (tag_t)vx_task_xid(task);
6849         security_task_to_inode(task, inode);
6850  
6851  out:
6852 @@ -1993,6 +1997,13 @@ static struct dentry *proc_pident_lookup
6853         if (!task)
6854                 goto out_no_task;
6855  
6856 +       /* TODO: maybe we can come up with a generic approach? */
6857 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6858 +               (dentry->d_name.len == 5) &&
6859 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6860 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6861 +               goto out;
6862 +
6863         /*
6864          * Yes, it does not scale. And it should not. Don't add
6865          * new entries into /proc/<tgid>/ without very good reasons.
6866 @@ -2378,7 +2389,7 @@ out_iput:
6867  static struct dentry *proc_base_lookup(struct inode *dir, struct dentry *dentry)
6868  {
6869         struct dentry *error;
6870 -       struct task_struct *task = get_proc_task(dir);
6871 +       struct task_struct *task = get_proc_task_real(dir);
6872         const struct pid_entry *p, *last;
6873  
6874         error = ERR_PTR(-ENOENT);
6875 @@ -2468,6 +2479,9 @@ static int proc_pid_personality(struct s
6876  static const struct file_operations proc_task_operations;
6877  static const struct inode_operations proc_task_inode_operations;
6878  
6879 +extern int proc_pid_vx_info(struct task_struct *, char *);
6880 +extern int proc_pid_nx_info(struct task_struct *, char *);
6881 +
6882  static const struct pid_entry tgid_base_stuff[] = {
6883         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6884         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6885 @@ -2526,6 +2540,8 @@ static const struct pid_entry tgid_base_
6886  #ifdef CONFIG_CGROUPS
6887         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6888  #endif
6889 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6890 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6891         INF("oom_score",  S_IRUGO, proc_oom_score),
6892         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adjust_operations),
6893  #ifdef CONFIG_AUDITSYSCALL
6894 @@ -2541,6 +2557,7 @@ static const struct pid_entry tgid_base_
6895  #ifdef CONFIG_TASK_IO_ACCOUNTING
6896         INF("io",       S_IRUGO, proc_tgid_io_accounting),
6897  #endif
6898 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6899  };
6900  
6901  static int proc_tgid_base_readdir(struct file * filp,
6902 @@ -2737,7 +2754,7 @@ retry:
6903         iter.task = NULL;
6904         pid = find_ge_pid(iter.tgid, ns);
6905         if (pid) {
6906 -               iter.tgid = pid_nr_ns(pid, ns);
6907 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6908                 iter.task = pid_task(pid, PIDTYPE_PID);
6909                 /* What we to know is if the pid we have find is the
6910                  * pid of a thread_group_leader.  Testing for task
6911 @@ -2767,7 +2784,7 @@ static int proc_pid_fill_cache(struct fi
6912         struct tgid_iter iter)
6913  {
6914         char name[PROC_NUMBUF];
6915 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6916 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6917         return proc_fill_cache(filp, dirent, filldir, name, len,
6918                                 proc_pid_instantiate, iter.task, NULL);
6919  }
6920 @@ -2776,7 +2793,7 @@ static int proc_pid_fill_cache(struct fi
6921  int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
6922  {
6923         unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
6924 -       struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode);
6925 +       struct task_struct *reaper = get_proc_task_real(filp->f_path.dentry->d_inode);
6926         struct tgid_iter iter;
6927         struct pid_namespace *ns;
6928  
6929 @@ -2796,6 +2813,8 @@ int proc_pid_readdir(struct file * filp,
6930              iter.task;
6931              iter.tgid += 1, iter = next_tgid(ns, iter)) {
6932                 filp->f_pos = iter.tgid + TGID_OFFSET;
6933 +               if (!vx_proc_task_visible(iter.task))
6934 +                       continue;
6935                 if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
6936                         put_task_struct(iter.task);
6937                         goto out;
6938 @@ -2942,6 +2961,8 @@ static struct dentry *proc_task_lookup(s
6939         tid = name_to_int(dentry);
6940         if (tid == ~0U)
6941                 goto out;
6942 +       if (vx_current_initpid(tid))
6943 +               goto out;
6944  
6945         ns = dentry->d_sb->s_fs_info;
6946         rcu_read_lock();
6947 diff -NurpP --minimal linux-2.6.29.4/fs/proc/generic.c linux-2.6.29.4-vs2.3.0.36.14/fs/proc/generic.c
6948 --- linux-2.6.29.4/fs/proc/generic.c    2009-03-24 14:22:27.000000000 +0100
6949 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/proc/generic.c      2009-03-24 14:48:35.000000000 +0100
6950 @@ -20,6 +20,7 @@
6951  #include <linux/bitops.h>
6952  #include <linux/spinlock.h>
6953  #include <linux/completion.h>
6954 +#include <linux/vserver/inode.h>
6955  #include <asm/uaccess.h>
6956  
6957  #include "internal.h"
6958 @@ -382,6 +383,8 @@ struct dentry *proc_lookup_de(struct pro
6959         for (de = de->subdir; de ; de = de->next) {
6960                 if (de->namelen != dentry->d_name.len)
6961                         continue;
6962 +                       if (!vx_hide_check(0, de->vx_flags))
6963 +                               continue;
6964                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6965                         unsigned int ino;
6966  
6967 @@ -390,6 +393,8 @@ struct dentry *proc_lookup_de(struct pro
6968                         spin_unlock(&proc_subdir_lock);
6969                         error = -EINVAL;
6970                         inode = proc_get_inode(dir->i_sb, ino, de);
6971 +                               /* generic proc entries belong to the host */
6972 +                               inode->i_tag = 0;
6973                         goto out_unlock;
6974                 }
6975         }
6976 @@ -467,6 +472,8 @@ int proc_readdir_de(struct proc_dir_entr
6977  
6978                                 /* filldir passes info to user space */
6979                                 de_get(de);
6980 +                               if (!vx_hide_check(0, de->vx_flags))
6981 +                                       goto skip;
6982                                 spin_unlock(&proc_subdir_lock);
6983                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6984                                             de->low_ino, de->mode >> 12) < 0) {
6985 @@ -474,6 +481,7 @@ int proc_readdir_de(struct proc_dir_entr
6986                                         goto out;
6987                                 }
6988                                 spin_lock(&proc_subdir_lock);
6989 +                       skip:
6990                                 filp->f_pos++;
6991                                 next = de->next;
6992                                 de_put(de);
6993 @@ -588,6 +596,7 @@ static struct proc_dir_entry *__proc_cre
6994         ent->nlink = nlink;
6995         atomic_set(&ent->count, 1);
6996         ent->pde_users = 0;
6997 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6998         spin_lock_init(&ent->pde_unload_lock);
6999         ent->pde_unload_completion = NULL;
7000         INIT_LIST_HEAD(&ent->pde_openers);
7001 @@ -611,7 +620,8 @@ struct proc_dir_entry *proc_symlink(cons
7002                                 kfree(ent->data);
7003                                 kfree(ent);
7004                                 ent = NULL;
7005 -                       }
7006 +                       } else
7007 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
7008                 } else {
7009                         kfree(ent);
7010                         ent = NULL;
7011 diff -NurpP --minimal linux-2.6.29.4/fs/proc/inode.c linux-2.6.29.4-vs2.3.0.36.14/fs/proc/inode.c
7012 --- linux-2.6.29.4/fs/proc/inode.c      2009-03-24 14:22:27.000000000 +0100
7013 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/proc/inode.c        2009-03-24 14:48:35.000000000 +0100
7014 @@ -465,6 +465,8 @@ struct inode *proc_get_inode(struct supe
7015                         inode->i_uid = de->uid;
7016                         inode->i_gid = de->gid;
7017                 }
7018 +               if (de->vx_flags)
7019 +                       PROC_I(inode)->vx_flags = de->vx_flags;
7020                 if (de->size)
7021                         inode->i_size = de->size;
7022                 if (de->nlink)
7023 diff -NurpP --minimal linux-2.6.29.4/fs/proc/internal.h linux-2.6.29.4-vs2.3.0.36.14/fs/proc/internal.h
7024 --- linux-2.6.29.4/fs/proc/internal.h   2009-03-24 14:22:27.000000000 +0100
7025 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/proc/internal.h     2009-03-24 14:48:35.000000000 +0100
7026 @@ -10,6 +10,7 @@
7027   */
7028  
7029  #include <linux/proc_fs.h>
7030 +#include <linux/vs_pid.h>
7031  
7032  extern struct proc_dir_entry proc_root;
7033  #ifdef CONFIG_PROC_SYSCTL
7034 @@ -51,6 +52,9 @@ extern int proc_pid_status(struct seq_fi
7035                                 struct pid *pid, struct task_struct *task);
7036  extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
7037                                 struct pid *pid, struct task_struct *task);
7038 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
7039 +                               struct pid *pid, struct task_struct *task);
7040 +
7041  extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
7042  
7043  extern const struct file_operations proc_maps_operations;
7044 @@ -70,11 +74,16 @@ static inline struct pid *proc_pid(struc
7045         return PROC_I(inode)->pid;
7046  }
7047  
7048 -static inline struct task_struct *get_proc_task(struct inode *inode)
7049 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
7050  {
7051         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
7052  }
7053  
7054 +static inline struct task_struct *get_proc_task(struct inode *inode)
7055 +{
7056 +       return vx_get_proc_task(inode, proc_pid(inode));
7057 +}
7058 +
7059  static inline int proc_fd(struct inode *inode)
7060  {
7061         return PROC_I(inode)->fd;
7062 diff -NurpP --minimal linux-2.6.29.4/fs/proc/loadavg.c linux-2.6.29.4-vs2.3.0.36.14/fs/proc/loadavg.c
7063 --- linux-2.6.29.4/fs/proc/loadavg.c    2008-12-25 00:26:37.000000000 +0100
7064 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/proc/loadavg.c      2009-05-20 00:24:34.000000000 +0200
7065 @@ -12,21 +12,37 @@
7066  
7067  static int loadavg_proc_show(struct seq_file *m, void *v)
7068  {
7069 +       unsigned long running;
7070 +       unsigned int threads;
7071         int a, b, c;
7072         unsigned long seq;
7073  
7074         do {
7075                 seq = read_seqbegin(&xtime_lock);
7076 -               a = avenrun[0] + (FIXED_1/200);
7077 -               b = avenrun[1] + (FIXED_1/200);
7078 -               c = avenrun[2] + (FIXED_1/200);
7079 +               if (vx_flags(VXF_VIRT_LOAD, 0)) {
7080 +                       struct vx_info *vxi = current->vx_info;
7081 +
7082 +                       a = vxi->cvirt.load[0] + (FIXED_1/200);
7083 +                       b = vxi->cvirt.load[1] + (FIXED_1/200);
7084 +                       c = vxi->cvirt.load[2] + (FIXED_1/200);
7085 +
7086 +                       running = atomic_read(&vxi->cvirt.nr_running);
7087 +                       threads = atomic_read(&vxi->cvirt.nr_threads);
7088 +               } else {
7089 +                       a = avenrun[0] + (FIXED_1/200);
7090 +                       b = avenrun[1] + (FIXED_1/200);
7091 +                       c = avenrun[2] + (FIXED_1/200);
7092 +
7093 +                       running = nr_running();
7094 +                       threads = nr_threads;
7095 +               }
7096         } while (read_seqretry(&xtime_lock, seq));
7097  
7098         seq_printf(m, "%d.%02d %d.%02d %d.%02d %ld/%d %d\n",
7099                 LOAD_INT(a), LOAD_FRAC(a),
7100                 LOAD_INT(b), LOAD_FRAC(b),
7101                 LOAD_INT(c), LOAD_FRAC(c),
7102 -               nr_running(), nr_threads,
7103 +               running, threads,
7104                 task_active_pid_ns(current)->last_pid);
7105         return 0;
7106  }
7107 diff -NurpP --minimal linux-2.6.29.4/fs/proc/meminfo.c linux-2.6.29.4-vs2.3.0.36.14/fs/proc/meminfo.c
7108 --- linux-2.6.29.4/fs/proc/meminfo.c    2009-05-23 23:16:53.000000000 +0200
7109 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/proc/meminfo.c      2009-05-10 23:42:01.000000000 +0200
7110 @@ -41,7 +41,7 @@ static int meminfo_proc_show(struct seq_
7111  
7112         cached = global_page_state(NR_FILE_PAGES) -
7113                         total_swapcache_pages - i.bufferram;
7114 -       if (cached < 0)
7115 +       if (cached < 0 || vx_flags(VXF_VIRT_MEM, 0))
7116                 cached = 0;
7117  
7118         get_vmalloc_info(&vmi);
7119 diff -NurpP --minimal linux-2.6.29.4/fs/proc/root.c linux-2.6.29.4-vs2.3.0.36.14/fs/proc/root.c
7120 --- linux-2.6.29.4/fs/proc/root.c       2009-03-24 14:22:27.000000000 +0100
7121 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/proc/root.c 2009-03-24 14:48:35.000000000 +0100
7122 @@ -18,9 +18,14 @@
7123  #include <linux/bitops.h>
7124  #include <linux/mount.h>
7125  #include <linux/pid_namespace.h>
7126 +#include <linux/vserver/inode.h>
7127  
7128  #include "internal.h"
7129  
7130 +struct proc_dir_entry *proc_virtual;
7131 +
7132 +extern void proc_vx_init(void);
7133 +
7134  static int proc_test_super(struct super_block *sb, void *data)
7135  {
7136         return sb->s_fs_info == data;
7137 @@ -136,6 +141,7 @@ void __init proc_root_init(void)
7138  #endif
7139         proc_mkdir("bus", NULL);
7140         proc_sys_init();
7141 +       proc_vx_init();
7142  }
7143  
7144  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
7145 @@ -203,6 +209,7 @@ struct proc_dir_entry proc_root = {
7146         .proc_iops      = &proc_root_inode_operations, 
7147         .proc_fops      = &proc_root_operations,
7148         .parent         = &proc_root,
7149 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
7150  };
7151  
7152  int pid_ns_prepare_proc(struct pid_namespace *ns)
7153 diff -NurpP --minimal linux-2.6.29.4/fs/proc/uptime.c linux-2.6.29.4-vs2.3.0.36.14/fs/proc/uptime.c
7154 --- linux-2.6.29.4/fs/proc/uptime.c     2008-12-25 00:26:37.000000000 +0100
7155 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/proc/uptime.c       2009-02-22 22:54:25.000000000 +0100
7156 @@ -2,6 +2,7 @@
7157  #include <linux/proc_fs.h>
7158  #include <linux/sched.h>
7159  #include <linux/time.h>
7160 +#include <linux/vserver/cvirt.h>
7161  #include <asm/cputime.h>
7162  
7163  static int proc_calc_metrics(char *page, char **start, off_t off,
7164 @@ -29,6 +30,10 @@ static int uptime_read_proc(char *page, 
7165         do_posix_clock_monotonic_gettime(&uptime);
7166         monotonic_to_bootbased(&uptime);
7167         cputime_to_timespec(idletime, &idle);
7168 +
7169 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
7170 +               vx_vsi_uptime(&uptime, &idle);
7171 +
7172         len = sprintf(page, "%lu.%02lu %lu.%02lu\n",
7173                         (unsigned long) uptime.tv_sec,
7174                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
7175 diff -NurpP --minimal linux-2.6.29.4/fs/quota.c linux-2.6.29.4-vs2.3.0.36.14/fs/quota.c
7176 --- linux-2.6.29.4/fs/quota.c   2009-03-24 14:22:27.000000000 +0100
7177 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/quota.c     2009-03-24 14:48:35.000000000 +0100
7178 @@ -18,6 +18,7 @@
7179  #include <linux/capability.h>
7180  #include <linux/quotaops.h>
7181  #include <linux/types.h>
7182 +#include <linux/vs_context.h>
7183  
7184  /* Check validity of generic quotactl commands */
7185  static int generic_quotactl_valid(struct super_block *sb, int type, int cmd, qid_t id)
7186 @@ -81,11 +82,11 @@ static int generic_quotactl_valid(struct
7187         if (cmd == Q_GETQUOTA) {
7188                 if (((type == USRQUOTA && current_euid() != id) ||
7189                      (type == GRPQUOTA && !in_egroup_p(id))) &&
7190 -                   !capable(CAP_SYS_ADMIN))
7191 +                   !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7192                         return -EPERM;
7193         }
7194         else if (cmd != Q_GETFMT && cmd != Q_SYNC && cmd != Q_GETINFO)
7195 -               if (!capable(CAP_SYS_ADMIN))
7196 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7197                         return -EPERM;
7198  
7199         return 0;
7200 @@ -132,10 +133,10 @@ static int xqm_quotactl_valid(struct sup
7201         if (cmd == Q_XGETQUOTA) {
7202                 if (((type == XQM_USRQUOTA && current_euid() != id) ||
7203                      (type == XQM_GRPQUOTA && !in_egroup_p(id))) &&
7204 -                    !capable(CAP_SYS_ADMIN))
7205 +                    !vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7206                         return -EPERM;
7207         } else if (cmd != Q_XGETQSTAT && cmd != Q_XQUOTASYNC) {
7208 -               if (!capable(CAP_SYS_ADMIN))
7209 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
7210                         return -EPERM;
7211         }
7212  
7213 @@ -337,6 +338,46 @@ static int do_quotactl(struct super_bloc
7214         return 0;
7215  }
7216  
7217 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7218 +
7219 +#include <linux/vroot.h>
7220 +#include <linux/major.h>
7221 +#include <linux/module.h>
7222 +#include <linux/kallsyms.h>
7223 +#include <linux/vserver/debug.h>
7224 +
7225 +static vroot_grb_func *vroot_get_real_bdev = NULL;
7226 +
7227 +static spinlock_t vroot_grb_lock = SPIN_LOCK_UNLOCKED;
7228 +
7229 +int register_vroot_grb(vroot_grb_func *func) {
7230 +       int ret = -EBUSY;
7231 +
7232 +       spin_lock(&vroot_grb_lock);
7233 +       if (!vroot_get_real_bdev) {
7234 +               vroot_get_real_bdev = func;
7235 +               ret = 0;
7236 +       }
7237 +       spin_unlock(&vroot_grb_lock);
7238 +       return ret;
7239 +}
7240 +EXPORT_SYMBOL(register_vroot_grb);
7241 +
7242 +int unregister_vroot_grb(vroot_grb_func *func) {
7243 +       int ret = -EINVAL;
7244 +
7245 +       spin_lock(&vroot_grb_lock);
7246 +       if (vroot_get_real_bdev) {
7247 +               vroot_get_real_bdev = NULL;
7248 +               ret = 0;
7249 +       }
7250 +       spin_unlock(&vroot_grb_lock);
7251 +       return ret;
7252 +}
7253 +EXPORT_SYMBOL(unregister_vroot_grb);
7254 +
7255 +#endif
7256 +
7257  /*
7258   * look up a superblock on which quota ops will be performed
7259   * - use the name of a block device to find the superblock thereon
7260 @@ -354,6 +395,22 @@ static inline struct super_block *quotac
7261         putname(tmp);
7262         if (IS_ERR(bdev))
7263                 return ERR_CAST(bdev);
7264 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
7265 +       if (bdev && bdev->bd_inode &&
7266 +                       imajor(bdev->bd_inode) == VROOT_MAJOR) {
7267 +               struct block_device *bdnew = (void *)-EINVAL;
7268 +
7269 +               if (vroot_get_real_bdev)
7270 +                       bdnew = vroot_get_real_bdev(bdev);
7271 +               else
7272 +                       vxdprintk(VXD_CBIT(misc, 0),
7273 +                                       "vroot_get_real_bdev not set");
7274 +               bdput(bdev);
7275 +               if (IS_ERR(bdnew))
7276 +                       return ERR_PTR(PTR_ERR(bdnew));
7277 +               bdev = bdnew;
7278 +       }
7279 +#endif
7280         sb = get_super(bdev);
7281         bdput(bdev);
7282         if (!sb)
7283 diff -NurpP --minimal linux-2.6.29.4/fs/reiserfs/bitmap.c linux-2.6.29.4-vs2.3.0.36.14/fs/reiserfs/bitmap.c
7284 --- linux-2.6.29.4/fs/reiserfs/bitmap.c 2008-12-25 00:26:37.000000000 +0100
7285 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/reiserfs/bitmap.c   2009-02-22 22:54:25.000000000 +0100
7286 @@ -13,6 +13,7 @@
7287  #include <linux/reiserfs_fs_sb.h>
7288  #include <linux/reiserfs_fs_i.h>
7289  #include <linux/quotaops.h>
7290 +#include <linux/vs_dlimit.h>
7291  
7292  #define PREALLOCATION_SIZE 9
7293  
7294 @@ -429,8 +430,10 @@ static void _reiserfs_free_block(struct 
7295         set_sb_free_blocks(rs, sb_free_blocks(rs) + 1);
7296  
7297         journal_mark_dirty(th, s, sbh);
7298 -       if (for_unformatted)
7299 +       if (for_unformatted) {
7300 +               DLIMIT_FREE_BLOCK(inode, 1);
7301                 DQUOT_FREE_BLOCK_NODIRTY(inode, 1);
7302 +       }
7303  }
7304  
7305  void reiserfs_free_block(struct reiserfs_transaction_handle *th,
7306 @@ -1045,6 +1048,7 @@ static inline int blocknrs_and_prealloc_
7307         b_blocknr_t finish = SB_BLOCK_COUNT(s) - 1;
7308         int passno = 0;
7309         int nr_allocated = 0;
7310 +       int blocks;
7311  
7312         determine_prealloc_size(hint);
7313         if (!hint->formatted_node) {
7314 @@ -1054,19 +1058,30 @@ static inline int blocknrs_and_prealloc_
7315                                "reiserquota: allocating %d blocks id=%u",
7316                                amount_needed, hint->inode->i_uid);
7317  #endif
7318 -               quota_ret =
7319 -                   DQUOT_ALLOC_BLOCK_NODIRTY(hint->inode, amount_needed);
7320 -               if (quota_ret)  /* Quota exceeded? */
7321 +               quota_ret = DQUOT_ALLOC_BLOCK_NODIRTY(hint->inode,
7322 +                       amount_needed);
7323 +               if (quota_ret)
7324                         return QUOTA_EXCEEDED;
7325 +               if (DLIMIT_ALLOC_BLOCK(hint->inode, amount_needed)) {
7326 +                       DQUOT_FREE_BLOCK_NODIRTY(hint->inode,
7327 +                               amount_needed);
7328 +                       return NO_DISK_SPACE;
7329 +               }
7330 +
7331                 if (hint->preallocate && hint->prealloc_size) {
7332  #ifdef REISERQUOTA_DEBUG
7333                         reiserfs_debug(s, REISERFS_DEBUG_CODE,
7334                                        "reiserquota: allocating (prealloc) %d blocks id=%u",
7335                                        hint->prealloc_size, hint->inode->i_uid);
7336  #endif
7337 -                       quota_ret =
7338 -                           DQUOT_PREALLOC_BLOCK_NODIRTY(hint->inode,
7339 -                                                        hint->prealloc_size);
7340 +                       quota_ret = DQUOT_PREALLOC_BLOCK_NODIRTY(hint->inode,
7341 +                               hint->prealloc_size);
7342 +                       if (!quota_ret &&
7343 +                               DLIMIT_ALLOC_BLOCK(hint->inode, hint->prealloc_size)) {
7344 +                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode,
7345 +                                       hint->prealloc_size);
7346 +                               quota_ret = 1;
7347 +                       }
7348                         if (quota_ret)
7349                                 hint->preallocate = hint->prealloc_size = 0;
7350                 }
7351 @@ -1098,7 +1113,10 @@ static inline int blocknrs_and_prealloc_
7352                                                nr_allocated,
7353                                                hint->inode->i_uid);
7354  #endif
7355 -                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed + hint->prealloc_size - nr_allocated);      /* Free not allocated blocks */
7356 +                               /* Free not allocated blocks */
7357 +                               blocks = amount_needed + hint->prealloc_size - nr_allocated;
7358 +                               DLIMIT_FREE_BLOCK(hint->inode, blocks);
7359 +                               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, blocks);
7360                         }
7361                         while (nr_allocated--)
7362                                 reiserfs_free_block(hint->th, hint->inode,
7363 @@ -1129,10 +1147,10 @@ static inline int blocknrs_and_prealloc_
7364                                REISERFS_I(hint->inode)->i_prealloc_count,
7365                                hint->inode->i_uid);
7366  #endif
7367 -               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed +
7368 -                                        hint->prealloc_size - nr_allocated -
7369 -                                        REISERFS_I(hint->inode)->
7370 -                                        i_prealloc_count);
7371 +               blocks = amount_needed + hint->prealloc_size - nr_allocated -
7372 +                       REISERFS_I(hint->inode)->i_prealloc_count;
7373 +               DLIMIT_FREE_BLOCK(hint->inode, blocks);
7374 +               DQUOT_FREE_BLOCK_NODIRTY(hint->inode, blocks);
7375         }
7376  
7377         return CARRY_ON;
7378 diff -NurpP --minimal linux-2.6.29.4/fs/reiserfs/file.c linux-2.6.29.4-vs2.3.0.36.14/fs/reiserfs/file.c
7379 --- linux-2.6.29.4/fs/reiserfs/file.c   2008-12-25 00:26:37.000000000 +0100
7380 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/reiserfs/file.c     2009-02-22 22:54:25.000000000 +0100
7381 @@ -307,4 +307,5 @@ const struct inode_operations reiserfs_f
7382         .listxattr = reiserfs_listxattr,
7383         .removexattr = reiserfs_removexattr,
7384         .permission = reiserfs_permission,
7385 +       .sync_flags = reiserfs_sync_flags,
7386  };
7387 diff -NurpP --minimal linux-2.6.29.4/fs/reiserfs/inode.c linux-2.6.29.4-vs2.3.0.36.14/fs/reiserfs/inode.c
7388 --- linux-2.6.29.4/fs/reiserfs/inode.c  2009-03-24 14:22:27.000000000 +0100
7389 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/reiserfs/inode.c    2009-03-24 14:48:35.000000000 +0100
7390 @@ -18,6 +18,8 @@
7391  #include <linux/writeback.h>
7392  #include <linux/quotaops.h>
7393  #include <linux/swap.h>
7394 +#include <linux/vs_dlimit.h>
7395 +#include <linux/vs_tag.h>
7396  
7397  int reiserfs_commit_write(struct file *f, struct page *page,
7398                           unsigned from, unsigned to);
7399 @@ -54,6 +56,7 @@ void reiserfs_delete_inode(struct inode 
7400                  * stat data deletion */
7401                 if (!err) 
7402                         DQUOT_FREE_INODE(inode);
7403 +               DLIMIT_FREE_INODE(inode);
7404  
7405                 if (journal_end(&th, inode->i_sb, jbegin_count))
7406                         goto out;
7407 @@ -1116,6 +1119,8 @@ static void init_inode(struct inode *ino
7408         struct buffer_head *bh;
7409         struct item_head *ih;
7410         __u32 rdev;
7411 +       uid_t uid;
7412 +       gid_t gid;
7413         //int version = ITEM_VERSION_1;
7414  
7415         bh = PATH_PLAST_BUFFER(path);
7416 @@ -1139,12 +1144,13 @@ static void init_inode(struct inode *ino
7417                     (struct stat_data_v1 *)B_I_PITEM(bh, ih);
7418                 unsigned long blocks;
7419  
7420 +               uid = sd_v1_uid(sd);
7421 +               gid = sd_v1_gid(sd);
7422 +
7423                 set_inode_item_key_version(inode, KEY_FORMAT_3_5);
7424                 set_inode_sd_version(inode, STAT_DATA_V1);
7425                 inode->i_mode = sd_v1_mode(sd);
7426                 inode->i_nlink = sd_v1_nlink(sd);
7427 -               inode->i_uid = sd_v1_uid(sd);
7428 -               inode->i_gid = sd_v1_gid(sd);
7429                 inode->i_size = sd_v1_size(sd);
7430                 inode->i_atime.tv_sec = sd_v1_atime(sd);
7431                 inode->i_mtime.tv_sec = sd_v1_mtime(sd);
7432 @@ -1186,11 +1192,12 @@ static void init_inode(struct inode *ino
7433                 // (directories and symlinks)
7434                 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bh, ih);
7435  
7436 +               uid    = sd_v2_uid(sd);
7437 +               gid    = sd_v2_gid(sd);
7438 +
7439                 inode->i_mode = sd_v2_mode(sd);
7440                 inode->i_nlink = sd_v2_nlink(sd);
7441 -               inode->i_uid = sd_v2_uid(sd);
7442                 inode->i_size = sd_v2_size(sd);
7443 -               inode->i_gid = sd_v2_gid(sd);
7444                 inode->i_mtime.tv_sec = sd_v2_mtime(sd);
7445                 inode->i_atime.tv_sec = sd_v2_atime(sd);
7446                 inode->i_ctime.tv_sec = sd_v2_ctime(sd);
7447 @@ -1220,6 +1227,10 @@ static void init_inode(struct inode *ino
7448                 sd_attrs_to_i_attrs(sd_v2_attrs(sd), inode);
7449         }
7450  
7451 +       inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
7452 +       inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
7453 +       inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
7454 +
7455         pathrelse(path);
7456         if (S_ISREG(inode->i_mode)) {
7457                 inode->i_op = &reiserfs_file_inode_operations;
7458 @@ -1242,13 +1253,15 @@ static void init_inode(struct inode *ino
7459  static void inode2sd(void *sd, struct inode *inode, loff_t size)
7460  {
7461         struct stat_data *sd_v2 = (struct stat_data *)sd;
7462 +       uid_t uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
7463 +       gid_t gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
7464         __u16 flags;
7465  
7466 +       set_sd_v2_uid(sd_v2, uid);
7467 +       set_sd_v2_gid(sd_v2, gid);
7468         set_sd_v2_mode(sd_v2, inode->i_mode);
7469         set_sd_v2_nlink(sd_v2, inode->i_nlink);
7470 -       set_sd_v2_uid(sd_v2, inode->i_uid);
7471         set_sd_v2_size(sd_v2, size);
7472 -       set_sd_v2_gid(sd_v2, inode->i_gid);
7473         set_sd_v2_mtime(sd_v2, inode->i_mtime.tv_sec);
7474         set_sd_v2_atime(sd_v2, inode->i_atime.tv_sec);
7475         set_sd_v2_ctime(sd_v2, inode->i_ctime.tv_sec);
7476 @@ -1763,6 +1776,10 @@ int reiserfs_new_inode(struct reiserfs_t
7477  
7478         BUG_ON(!th->t_trans_id);
7479  
7480 +       if (DLIMIT_ALLOC_INODE(inode)) {
7481 +               err = -ENOSPC;
7482 +               goto out_bad_dlimit;
7483 +       }
7484         if (DQUOT_ALLOC_INODE(inode)) {
7485                 err = -EDQUOT;
7486                 goto out_end_trans;
7487 @@ -1950,6 +1967,9 @@ int reiserfs_new_inode(struct reiserfs_t
7488         DQUOT_FREE_INODE(inode);
7489  
7490        out_end_trans:
7491 +       DLIMIT_FREE_INODE(inode);
7492 +
7493 +      out_bad_dlimit:
7494         journal_end(th, th->t_super, th->t_blocks_allocated);
7495         /* Drop can be outside and it needs more credits so it's better to have it outside */
7496         DQUOT_DROP(inode);
7497 @@ -2837,14 +2857,19 @@ int reiserfs_commit_write(struct file *f
7498  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode)
7499  {
7500         if (reiserfs_attrs(inode->i_sb)) {
7501 -               if (sd_attrs & REISERFS_SYNC_FL)
7502 -                       inode->i_flags |= S_SYNC;
7503 -               else
7504 -                       inode->i_flags &= ~S_SYNC;
7505                 if (sd_attrs & REISERFS_IMMUTABLE_FL)
7506                         inode->i_flags |= S_IMMUTABLE;
7507                 else
7508                         inode->i_flags &= ~S_IMMUTABLE;
7509 +               if (sd_attrs & REISERFS_IXUNLINK_FL)
7510 +                       inode->i_flags |= S_IXUNLINK;
7511 +               else
7512 +                       inode->i_flags &= ~S_IXUNLINK;
7513 +
7514 +               if (sd_attrs & REISERFS_SYNC_FL)
7515 +                       inode->i_flags |= S_SYNC;
7516 +               else
7517 +                       inode->i_flags &= ~S_SYNC;
7518                 if (sd_attrs & REISERFS_APPEND_FL)
7519                         inode->i_flags |= S_APPEND;
7520                 else
7521 @@ -2857,6 +2882,15 @@ void sd_attrs_to_i_attrs(__u16 sd_attrs,
7522                         REISERFS_I(inode)->i_flags |= i_nopack_mask;
7523                 else
7524                         REISERFS_I(inode)->i_flags &= ~i_nopack_mask;
7525 +
7526 +               if (sd_attrs & REISERFS_BARRIER_FL)
7527 +                       inode->i_vflags |= V_BARRIER;
7528 +               else
7529 +                       inode->i_vflags &= ~V_BARRIER;
7530 +               if (sd_attrs & REISERFS_COW_FL)
7531 +                       inode->i_vflags |= V_COW;
7532 +               else
7533 +                       inode->i_vflags &= ~V_COW;
7534         }
7535  }
7536  
7537 @@ -2867,6 +2901,11 @@ void i_attrs_to_sd_attrs(struct inode *i
7538                         *sd_attrs |= REISERFS_IMMUTABLE_FL;
7539                 else
7540                         *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
7541 +               if (inode->i_flags & S_IXUNLINK)
7542 +                       *sd_attrs |= REISERFS_IXUNLINK_FL;
7543 +               else
7544 +                       *sd_attrs &= ~REISERFS_IXUNLINK_FL;
7545 +
7546                 if (inode->i_flags & S_SYNC)
7547                         *sd_attrs |= REISERFS_SYNC_FL;
7548                 else
7549 @@ -2879,6 +2918,15 @@ void i_attrs_to_sd_attrs(struct inode *i
7550                         *sd_attrs |= REISERFS_NOTAIL_FL;
7551                 else
7552                         *sd_attrs &= ~REISERFS_NOTAIL_FL;
7553 +
7554 +               if (inode->i_vflags & V_BARRIER)
7555 +                       *sd_attrs |= REISERFS_BARRIER_FL;
7556 +               else
7557 +                       *sd_attrs &= ~REISERFS_BARRIER_FL;
7558 +               if (inode->i_vflags & V_COW)
7559 +                       *sd_attrs |= REISERFS_COW_FL;
7560 +               else
7561 +                       *sd_attrs &= ~REISERFS_COW_FL;
7562         }
7563  }
7564  
7565 @@ -3046,6 +3094,22 @@ static ssize_t reiserfs_direct_IO(int rw
7566                                   reiserfs_get_blocks_direct_io, NULL);
7567  }
7568  
7569 +int reiserfs_sync_flags(struct inode *inode)
7570 +{
7571 +       u16 oldflags, newflags;
7572 +
7573 +       oldflags = REISERFS_I(inode)->i_attrs;
7574 +       newflags = oldflags;
7575 +       i_attrs_to_sd_attrs(inode, &newflags);
7576 +
7577 +       if (oldflags ^ newflags) {
7578 +               REISERFS_I(inode)->i_attrs = newflags;
7579 +               inode->i_ctime = CURRENT_TIME_SEC;
7580 +               mark_inode_dirty(inode);
7581 +       }
7582 +       return 0;
7583 +}
7584 +
7585  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
7586  {
7587         struct inode *inode = dentry->d_inode;
7588 @@ -3099,9 +3163,11 @@ int reiserfs_setattr(struct dentry *dent
7589         }
7590  
7591         error = inode_change_ok(inode, attr);
7592 +
7593         if (!error) {
7594                 if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
7595 -                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) {
7596 +                   (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid) ||
7597 +                   (ia_valid & ATTR_TAG && attr->ia_tag != inode->i_tag)) {
7598                         error = reiserfs_chown_xattrs(inode, attr);
7599  
7600                         if (!error) {
7601 @@ -3131,6 +3197,9 @@ int reiserfs_setattr(struct dentry *dent
7602                                         inode->i_uid = attr->ia_uid;
7603                                 if (attr->ia_valid & ATTR_GID)
7604                                         inode->i_gid = attr->ia_gid;
7605 +                               if ((attr->ia_valid & ATTR_TAG) &&
7606 +                                       IS_TAGGED(inode))
7607 +                                       inode->i_tag = attr->ia_tag;
7608                                 mark_inode_dirty(inode);
7609                                 error =
7610                                     journal_end(&th, inode->i_sb, jbegin_count);
7611 diff -NurpP --minimal linux-2.6.29.4/fs/reiserfs/ioctl.c linux-2.6.29.4-vs2.3.0.36.14/fs/reiserfs/ioctl.c
7612 --- linux-2.6.29.4/fs/reiserfs/ioctl.c  2008-12-25 00:26:37.000000000 +0100
7613 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/reiserfs/ioctl.c    2009-02-22 22:54:25.000000000 +0100
7614 @@ -7,6 +7,7 @@
7615  #include <linux/mount.h>
7616  #include <linux/reiserfs_fs.h>
7617  #include <linux/time.h>
7618 +#include <linux/mount.h>
7619  #include <asm/uaccess.h>
7620  #include <linux/pagemap.h>
7621  #include <linux/smp_lock.h>
7622 @@ -23,7 +24,7 @@
7623  int reiserfs_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
7624                    unsigned long arg)
7625  {
7626 -       unsigned int flags;
7627 +       unsigned int flags, oldflags;
7628         int err = 0;
7629  
7630         switch (cmd) {
7631 @@ -43,6 +44,7 @@ int reiserfs_ioctl(struct inode *inode, 
7632  
7633                 flags = REISERFS_I(inode)->i_attrs;
7634                 i_attrs_to_sd_attrs(inode, (__u16 *) & flags);
7635 +               flags &= REISERFS_FL_USER_VISIBLE;
7636                 return put_user(flags, (int __user *)arg);
7637         case REISERFS_IOC_SETFLAGS:{
7638                         if (!reiserfs_attrs(inode->i_sb))
7639 @@ -60,6 +62,10 @@ int reiserfs_ioctl(struct inode *inode, 
7640                                 err = -EFAULT;
7641                                 goto setflags_out;
7642                         }
7643 +                       if (IS_BARRIER(inode)) {
7644 +                               vxwprintk_task(1, "messing with the barrier.");
7645 +                               return -EACCES;
7646 +                       }
7647                         /*
7648                          * Is it quota file? Do not allow user to mess with it
7649                          */
7650 @@ -84,6 +90,10 @@ int reiserfs_ioctl(struct inode *inode, 
7651                                         goto setflags_out;
7652                                 }
7653                         }
7654 +
7655 +                       oldflags = REISERFS_I(inode)->i_attrs;
7656 +                       flags = flags & REISERFS_FL_USER_MODIFIABLE;
7657 +                       flags |= oldflags & ~REISERFS_FL_USER_MODIFIABLE;
7658                         sd_attrs_to_i_attrs(flags, inode);
7659                         REISERFS_I(inode)->i_attrs = flags;
7660                         inode->i_ctime = CURRENT_TIME_SEC;
7661 diff -NurpP --minimal linux-2.6.29.4/fs/reiserfs/namei.c linux-2.6.29.4-vs2.3.0.36.14/fs/reiserfs/namei.c
7662 --- linux-2.6.29.4/fs/reiserfs/namei.c  2009-03-24 14:22:27.000000000 +0100
7663 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/reiserfs/namei.c    2009-03-24 14:48:35.000000000 +0100
7664 @@ -17,6 +17,7 @@
7665  #include <linux/reiserfs_acl.h>
7666  #include <linux/reiserfs_xattr.h>
7667  #include <linux/quotaops.h>
7668 +#include <linux/vs_tag.h>
7669  
7670  #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; }
7671  #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
7672 @@ -360,6 +361,7 @@ static struct dentry *reiserfs_lookup(st
7673                         reiserfs_write_unlock(dir->i_sb);
7674                         return ERR_PTR(-EACCES);
7675                 }
7676 +               dx_propagate_tag(nd, inode);
7677  
7678                 /* Propogate the priv_object flag so we know we're in the priv tree */
7679                 if (is_reiserfs_priv_object(dir))
7680 @@ -586,6 +588,7 @@ static int new_inode_init(struct inode *
7681         } else {
7682                 inode->i_gid = current_fsgid();
7683         }
7684 +       inode->i_tag = dx_current_fstag(inode->i_sb);
7685         DQUOT_INIT(inode);
7686         return 0;
7687  }
7688 @@ -1540,6 +1543,7 @@ const struct inode_operations reiserfs_d
7689         .listxattr = reiserfs_listxattr,
7690         .removexattr = reiserfs_removexattr,
7691         .permission = reiserfs_permission,
7692 +       .sync_flags = reiserfs_sync_flags,
7693  };
7694  
7695  /*
7696 @@ -1556,6 +1560,7 @@ const struct inode_operations reiserfs_s
7697         .listxattr = reiserfs_listxattr,
7698         .removexattr = reiserfs_removexattr,
7699         .permission = reiserfs_permission,
7700 +       .sync_flags = reiserfs_sync_flags,
7701  
7702  };
7703  
7704 @@ -1569,5 +1574,6 @@ const struct inode_operations reiserfs_s
7705         .listxattr = reiserfs_listxattr,
7706         .removexattr = reiserfs_removexattr,
7707         .permission = reiserfs_permission,
7708 +       .sync_flags = reiserfs_sync_flags,
7709  
7710  };
7711 diff -NurpP --minimal linux-2.6.29.4/fs/reiserfs/stree.c linux-2.6.29.4-vs2.3.0.36.14/fs/reiserfs/stree.c
7712 --- linux-2.6.29.4/fs/reiserfs/stree.c  2008-12-25 00:26:37.000000000 +0100
7713 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/reiserfs/stree.c    2009-02-22 22:54:25.000000000 +0100
7714 @@ -55,6 +55,7 @@
7715  #include <linux/reiserfs_fs.h>
7716  #include <linux/buffer_head.h>
7717  #include <linux/quotaops.h>
7718 +#include <linux/vs_dlimit.h>
7719  
7720  /* Does the buffer contain a disk block which is in the tree. */
7721  inline int B_IS_IN_TREE(const struct buffer_head *p_s_bh)
7722 @@ -1297,6 +1298,7 @@ int reiserfs_delete_item(struct reiserfs
7723                        "reiserquota delete_item(): freeing %u, id=%u type=%c",
7724                        quota_cut_bytes, p_s_inode->i_uid, head2type(&s_ih));
7725  #endif
7726 +       DLIMIT_FREE_SPACE(p_s_inode, quota_cut_bytes);
7727         DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes);
7728  
7729         /* Return deleted body length */
7730 @@ -1385,6 +1387,7 @@ void reiserfs_delete_solid_item(struct r
7731  #endif
7732                                 DQUOT_FREE_SPACE_NODIRTY(inode,
7733                                                          quota_cut_bytes);
7734 +                               DLIMIT_FREE_SPACE(inode, quota_cut_bytes);
7735                         }
7736                         break;
7737                 }
7738 @@ -1734,6 +1737,7 @@ int reiserfs_cut_from_item(struct reiser
7739                        "reiserquota cut_from_item(): freeing %u id=%u type=%c",
7740                        quota_cut_bytes, p_s_inode->i_uid, '?');
7741  #endif
7742 +       DLIMIT_FREE_SPACE(p_s_inode, quota_cut_bytes);
7743         DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes);
7744         return n_ret_value;
7745  }
7746 @@ -1975,6 +1979,11 @@ int reiserfs_paste_into_item(struct reis
7747                 pathrelse(p_s_search_path);
7748                 return -EDQUOT;
7749         }
7750 +       if (DLIMIT_ALLOC_SPACE(inode, n_pasted_size)) {
7751 +               DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size);
7752 +               pathrelse(p_s_search_path);
7753 +               return -ENOSPC;
7754 +       }
7755         init_tb_struct(th, &s_paste_balance, th->t_super, p_s_search_path,
7756                        n_pasted_size);
7757  #ifdef DISPLACE_NEW_PACKING_LOCALITIES
7758 @@ -2027,6 +2036,7 @@ int reiserfs_paste_into_item(struct reis
7759                        n_pasted_size, inode->i_uid,
7760                        key2type(&(p_s_key->on_disk_key)));
7761  #endif
7762 +       DLIMIT_FREE_SPACE(inode, n_pasted_size);
7763         DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size);
7764         return retval;
7765  }
7766 @@ -2064,6 +2074,11 @@ int reiserfs_insert_item(struct reiserfs
7767                         pathrelse(p_s_path);
7768                         return -EDQUOT;
7769                 }
7770 +               if (DLIMIT_ALLOC_SPACE(inode, quota_bytes)) {
7771 +                       DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes);
7772 +                       pathrelse(p_s_path);
7773 +                       return -ENOSPC;
7774 +               }
7775         }
7776         init_tb_struct(th, &s_ins_balance, th->t_super, p_s_path,
7777                        IH_SIZE + ih_item_len(p_s_ih));
7778 @@ -2111,7 +2126,9 @@ int reiserfs_insert_item(struct reiserfs
7779                        "reiserquota insert_item(): freeing %u id=%u type=%c",
7780                        quota_bytes, inode->i_uid, head2type(p_s_ih));
7781  #endif
7782 -       if (inode)
7783 +       if (inode) {
7784 +               DLIMIT_FREE_SPACE(inode, quota_bytes);
7785                 DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes);
7786 +       }
7787         return retval;
7788  }
7789 diff -NurpP --minimal linux-2.6.29.4/fs/reiserfs/super.c linux-2.6.29.4-vs2.3.0.36.14/fs/reiserfs/super.c
7790 --- linux-2.6.29.4/fs/reiserfs/super.c  2009-03-24 14:22:27.000000000 +0100
7791 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/reiserfs/super.c    2009-03-24 14:48:35.000000000 +0100
7792 @@ -902,6 +902,14 @@ static int reiserfs_parse_options(struct
7793                 {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
7794                 {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
7795  #endif
7796 +#ifndef CONFIG_TAGGING_NONE
7797 +               {"tagxid",.setmask = 1 << REISERFS_TAGGED},
7798 +               {"tag",.setmask = 1 << REISERFS_TAGGED},
7799 +               {"notag",.clrmask = 1 << REISERFS_TAGGED},
7800 +#endif
7801 +#ifdef CONFIG_PROPAGATE
7802 +               {"tag",.arg_required = 'T',.values = NULL},
7803 +#endif
7804  #ifdef CONFIG_REISERFS_FS_POSIX_ACL
7805                 {"acl",.setmask = 1 << REISERFS_POSIXACL},
7806                 {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
7807 @@ -1195,6 +1203,12 @@ static int reiserfs_remount(struct super
7808         handle_quota_files(s, qf_names, &qfmt);
7809  #endif
7810  
7811 +       if ((mount_options & (1 << REISERFS_TAGGED)) &&
7812 +               !(s->s_flags & MS_TAGGED)) {
7813 +               reiserfs_warning(s, "reiserfs: tagging not permitted on remount.");
7814 +               return -EINVAL;
7815 +       }
7816 +
7817         handle_attrs(s);
7818  
7819         /* Add options that are safe here */
7820 @@ -1659,6 +1673,10 @@ static int reiserfs_fill_super(struct su
7821                 goto error;
7822         }
7823  
7824 +       /* map mount option tagxid */
7825 +       if (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TAGGED))
7826 +               s->s_flags |= MS_TAGGED;
7827 +
7828         rs = SB_DISK_SUPER_BLOCK(s);
7829         /* Let's do basic sanity check to verify that underlying device is not
7830            smaller than the filesystem. If the check fails then abort and scream,
7831 diff -NurpP --minimal linux-2.6.29.4/fs/reiserfs/xattr.c linux-2.6.29.4-vs2.3.0.36.14/fs/reiserfs/xattr.c
7832 --- linux-2.6.29.4/fs/reiserfs/xattr.c  2008-12-25 00:26:37.000000000 +0100
7833 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/reiserfs/xattr.c    2009-02-22 22:54:25.000000000 +0100
7834 @@ -35,6 +35,7 @@
7835  #include <linux/namei.h>
7836  #include <linux/errno.h>
7837  #include <linux/fs.h>
7838 +#include <linux/mount.h>
7839  #include <linux/file.h>
7840  #include <linux/pagemap.h>
7841  #include <linux/xattr.h>
7842 diff -NurpP --minimal linux-2.6.29.4/fs/stat.c linux-2.6.29.4-vs2.3.0.36.14/fs/stat.c
7843 --- linux-2.6.29.4/fs/stat.c    2009-03-24 14:22:36.000000000 +0100
7844 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/stat.c      2009-03-24 14:48:35.000000000 +0100
7845 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
7846         stat->nlink = inode->i_nlink;
7847         stat->uid = inode->i_uid;
7848         stat->gid = inode->i_gid;
7849 +       stat->tag = inode->i_tag;
7850         stat->rdev = inode->i_rdev;
7851         stat->atime = inode->i_atime;
7852         stat->mtime = inode->i_mtime;
7853 diff -NurpP --minimal linux-2.6.29.4/fs/super.c linux-2.6.29.4-vs2.3.0.36.14/fs/super.c
7854 --- linux-2.6.29.4/fs/super.c   2009-03-24 14:22:36.000000000 +0100
7855 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/super.c     2009-03-24 16:32:06.000000000 +0100
7856 @@ -39,6 +39,9 @@
7857  #include <linux/mutex.h>
7858  #include <linux/file.h>
7859  #include <linux/async.h>
7860 +#include <linux/devpts_fs.h>
7861 +#include <linux/proc_fs.h>
7862 +#include <linux/vs_context.h>
7863  #include <asm/uaccess.h>
7864  #include "internal.h"
7865  
7866 @@ -918,12 +921,18 @@ struct vfsmount *
7867  vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
7868  {
7869         struct vfsmount *mnt;
7870 +       struct super_block *sb;
7871         char *secdata = NULL;
7872         int error;
7873  
7874         if (!type)
7875                 return ERR_PTR(-ENODEV);
7876  
7877 +       error = -EPERM;
7878 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
7879 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
7880 +               goto out;
7881 +
7882         error = -ENOMEM;
7883         mnt = alloc_vfsmnt(name);
7884         if (!mnt)
7885 @@ -942,9 +951,17 @@ vfs_kern_mount(struct file_system_type *
7886         error = type->get_sb(type, flags, name, data, mnt);
7887         if (error < 0)
7888                 goto out_free_secdata;
7889 -       BUG_ON(!mnt->mnt_sb);
7890  
7891 -       error = security_sb_kern_mount(mnt->mnt_sb, flags, secdata);
7892 +       sb = mnt->mnt_sb;
7893 +       BUG_ON(!sb);
7894 +
7895 +       error = -EPERM;
7896 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) && !sb->s_bdev &&
7897 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
7898 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
7899 +               goto out_sb;
7900 +
7901 +       error = security_sb_kern_mount(sb, flags, secdata);
7902         if (error)
7903                 goto out_sb;
7904  
7905 diff -NurpP --minimal linux-2.6.29.4/fs/sysfs/mount.c linux-2.6.29.4-vs2.3.0.36.14/fs/sysfs/mount.c
7906 --- linux-2.6.29.4/fs/sysfs/mount.c     2008-12-25 00:26:37.000000000 +0100
7907 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/sysfs/mount.c       2009-02-22 22:54:25.000000000 +0100
7908 @@ -20,8 +20,6 @@
7909  
7910  #include "sysfs.h"
7911  
7912 -/* Random magic number */
7913 -#define SYSFS_MAGIC 0x62656572
7914  
7915  static struct vfsmount *sysfs_mount;
7916  struct super_block * sysfs_sb = NULL;
7917 @@ -47,7 +45,7 @@ static int sysfs_fill_super(struct super
7918  
7919         sb->s_blocksize = PAGE_CACHE_SIZE;
7920         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
7921 -       sb->s_magic = SYSFS_MAGIC;
7922 +       sb->s_magic = SYSFS_SUPER_MAGIC;
7923         sb->s_op = &sysfs_ops;
7924         sb->s_time_gran = 1;
7925         sysfs_sb = sb;
7926 diff -NurpP --minimal linux-2.6.29.4/fs/utimes.c linux-2.6.29.4-vs2.3.0.36.14/fs/utimes.c
7927 --- linux-2.6.29.4/fs/utimes.c  2009-03-24 14:22:37.000000000 +0100
7928 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/utimes.c    2009-02-22 22:54:25.000000000 +0100
7929 @@ -8,6 +8,8 @@
7930  #include <linux/stat.h>
7931  #include <linux/utime.h>
7932  #include <linux/syscalls.h>
7933 +#include <linux/mount.h>
7934 +#include <linux/vs_cowbl.h>
7935  #include <asm/uaccess.h>
7936  #include <asm/unistd.h>
7937  
7938 diff -NurpP --minimal linux-2.6.29.4/fs/xattr.c linux-2.6.29.4-vs2.3.0.36.14/fs/xattr.c
7939 --- linux-2.6.29.4/fs/xattr.c   2009-03-24 14:22:37.000000000 +0100
7940 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/xattr.c     2009-03-24 14:48:35.000000000 +0100
7941 @@ -18,6 +18,7 @@
7942  #include <linux/module.h>
7943  #include <linux/fsnotify.h>
7944  #include <linux/audit.h>
7945 +#include <linux/mount.h>
7946  #include <asm/uaccess.h>
7947  
7948  
7949 diff -NurpP --minimal linux-2.6.29.4/fs/xfs/linux-2.6/xfs_ioctl.c linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/linux-2.6/xfs_ioctl.c
7950 --- linux-2.6.29.4/fs/xfs/linux-2.6/xfs_ioctl.c 2009-03-24 14:22:37.000000000 +0100
7951 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/linux-2.6/xfs_ioctl.c   2009-03-24 14:48:35.000000000 +0100
7952 @@ -769,6 +769,10 @@ xfs_merge_ioc_xflags(
7953                 xflags |= XFS_XFLAG_IMMUTABLE;
7954         else
7955                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7956 +       if (flags & FS_IXUNLINK_FL)
7957 +               xflags |= XFS_XFLAG_IXUNLINK;
7958 +       else
7959 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7960         if (flags & FS_APPEND_FL)
7961                 xflags |= XFS_XFLAG_APPEND;
7962         else
7963 @@ -797,6 +801,8 @@ xfs_di2lxflags(
7964  
7965         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7966                 flags |= FS_IMMUTABLE_FL;
7967 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7968 +               flags |= FS_IXUNLINK_FL;
7969         if (di_flags & XFS_DIFLAG_APPEND)
7970                 flags |= FS_APPEND_FL;
7971         if (di_flags & XFS_DIFLAG_SYNC)
7972 @@ -855,6 +861,8 @@ xfs_set_diflags(
7973         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7974         if (xflags & XFS_XFLAG_IMMUTABLE)
7975                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7976 +       if (xflags & XFS_XFLAG_IXUNLINK)
7977 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7978         if (xflags & XFS_XFLAG_APPEND)
7979                 di_flags |= XFS_DIFLAG_APPEND;
7980         if (xflags & XFS_XFLAG_SYNC)
7981 @@ -897,6 +905,10 @@ xfs_diflags_to_linux(
7982                 inode->i_flags |= S_IMMUTABLE;
7983         else
7984                 inode->i_flags &= ~S_IMMUTABLE;
7985 +       if (xflags & XFS_XFLAG_IXUNLINK)
7986 +               inode->i_flags |= S_IXUNLINK;
7987 +       else
7988 +               inode->i_flags &= ~S_IXUNLINK;
7989         if (xflags & XFS_XFLAG_APPEND)
7990                 inode->i_flags |= S_APPEND;
7991         else
7992 @@ -1371,10 +1383,18 @@ xfs_file_ioctl(
7993         case XFS_IOC_FSGETXATTRA:
7994                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7995         case XFS_IOC_FSSETXATTR:
7996 +               if (IS_BARRIER(inode)) {
7997 +                       vxwprintk_task(1, "messing with the barrier.");
7998 +                       return -XFS_ERROR(EACCES);
7999 +               }
8000                 return xfs_ioc_fssetxattr(ip, filp, arg);
8001         case XFS_IOC_GETXFLAGS:
8002                 return xfs_ioc_getxflags(ip, arg);
8003         case XFS_IOC_SETXFLAGS:
8004 +               if (IS_BARRIER(inode)) {
8005 +                       vxwprintk_task(1, "messing with the barrier.");
8006 +                       return -XFS_ERROR(EACCES);
8007 +               }
8008                 return xfs_ioc_setxflags(ip, filp, arg);
8009  
8010         case XFS_IOC_FSSETDM: {
8011 diff -NurpP --minimal linux-2.6.29.4/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/linux-2.6/xfs_iops.c
8012 --- linux-2.6.29.4/fs/xfs/linux-2.6/xfs_iops.c  2009-03-24 14:22:37.000000000 +0100
8013 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/linux-2.6/xfs_iops.c    2009-03-24 16:33:10.000000000 +0100
8014 @@ -54,6 +54,7 @@
8015  #include <linux/security.h>
8016  #include <linux/falloc.h>
8017  #include <linux/fiemap.h>
8018 +#include <linux/vs_tag.h>
8019  
8020  /*
8021   * Bring the atime in the XFS inode uptodate.
8022 @@ -552,6 +553,7 @@ xfs_vn_getattr(
8023         stat->nlink = ip->i_d.di_nlink;
8024         stat->uid = ip->i_d.di_uid;
8025         stat->gid = ip->i_d.di_gid;
8026 +       stat->tag = ip->i_d.di_tag;
8027         stat->ino = ip->i_ino;
8028  #if XFS_BIG_INUMS
8029         stat->ino += mp->m_inoadd;
8030 @@ -591,6 +593,12 @@ xfs_vn_getattr(
8031  }
8032  
8033  STATIC int
8034 +xfs_vn_sync_xflags(struct inode *inode)
8035 +{
8036 +       return -xfs_sync_xflags(XFS_I(inode));
8037 +}
8038 +
8039 +STATIC int
8040  xfs_vn_setattr(
8041         struct dentry   *dentry,
8042         struct iattr    *iattr)
8043 @@ -748,6 +756,7 @@ static const struct inode_operations xfs
8044         .listxattr              = xfs_vn_listxattr,
8045         .fallocate              = xfs_vn_fallocate,
8046         .fiemap                 = xfs_vn_fiemap,
8047 +       .sync_flags             = xfs_vn_sync_xflags,
8048  };
8049  
8050  static const struct inode_operations xfs_dir_inode_operations = {
8051 @@ -773,6 +782,7 @@ static const struct inode_operations xfs
8052         .getxattr               = generic_getxattr,
8053         .removexattr            = generic_removexattr,
8054         .listxattr              = xfs_vn_listxattr,
8055 +       .sync_flags             = xfs_vn_sync_xflags,
8056  };
8057  
8058  static const struct inode_operations xfs_dir_ci_inode_operations = {
8059 @@ -822,6 +832,10 @@ xfs_diflags_to_iflags(
8060                 inode->i_flags |= S_IMMUTABLE;
8061         else
8062                 inode->i_flags &= ~S_IMMUTABLE;
8063 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
8064 +               inode->i_flags |= S_IXUNLINK;
8065 +       else
8066 +               inode->i_flags &= ~S_IXUNLINK;
8067         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
8068                 inode->i_flags |= S_APPEND;
8069         else
8070 @@ -834,6 +848,15 @@ xfs_diflags_to_iflags(
8071                 inode->i_flags |= S_NOATIME;
8072         else
8073                 inode->i_flags &= ~S_NOATIME;
8074 +
8075 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
8076 +               inode->i_vflags |= V_BARRIER;
8077 +       else
8078 +               inode->i_vflags &= ~V_BARRIER;
8079 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
8080 +               inode->i_vflags |= V_COW;
8081 +       else
8082 +               inode->i_vflags &= ~V_COW;
8083  }
8084  
8085  /*
8086 @@ -862,6 +885,7 @@ xfs_setup_inode(
8087         inode->i_nlink  = ip->i_d.di_nlink;
8088         inode->i_uid    = ip->i_d.di_uid;
8089         inode->i_gid    = ip->i_d.di_gid;
8090 +       inode->i_tag    = ip->i_d.di_tag;
8091  
8092         switch (inode->i_mode & S_IFMT) {
8093         case S_IFBLK:
8094 diff -NurpP --minimal linux-2.6.29.4/fs/xfs/linux-2.6/xfs_linux.h linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/linux-2.6/xfs_linux.h
8095 --- linux-2.6.29.4/fs/xfs/linux-2.6/xfs_linux.h 2009-03-24 14:22:37.000000000 +0100
8096 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/linux-2.6/xfs_linux.h   2009-03-25 01:26:04.000000000 +0100
8097 @@ -119,6 +119,7 @@
8098  
8099  #define current_cpu()          (raw_smp_processor_id())
8100  #define current_pid()          (current->pid)
8101 +#define current_fstag(cred,vp) (dx_current_fstag((vp)->i_sb))
8102  #define current_test_flags(f)  (current->flags & (f))
8103  #define current_set_flags_nested(sp, f)                \
8104                 (*(sp) = current->flags, current->flags |= (f))
8105 diff -NurpP --minimal linux-2.6.29.4/fs/xfs/linux-2.6/xfs_super.c linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/linux-2.6/xfs_super.c
8106 --- linux-2.6.29.4/fs/xfs/linux-2.6/xfs_super.c 2009-03-24 14:22:37.000000000 +0100
8107 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/linux-2.6/xfs_super.c   2009-03-25 01:48:51.000000000 +0100
8108 @@ -120,6 +120,9 @@ mempool_t *xfs_ioend_pool;
8109  #define MNTOPT_DMAPI   "dmapi"         /* DMI enabled (DMAPI / XDSM) */
8110  #define MNTOPT_XDSM    "xdsm"          /* DMI enabled (DMAPI / XDSM) */
8111  #define MNTOPT_DMI     "dmi"           /* DMI enabled (DMAPI / XDSM) */
8112 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
8113 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
8114 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
8115  
8116  /*
8117   * Table driven mount option parser.
8118 @@ -128,10 +131,14 @@ mempool_t *xfs_ioend_pool;
8119   * in the future, too.
8120   */
8121  enum {
8122 +       Opt_tag, Opt_notag,
8123         Opt_barrier, Opt_nobarrier, Opt_err
8124  };
8125  
8126  static const match_table_t tokens = {
8127 +       {Opt_tag, "tagxid"},
8128 +       {Opt_tag, "tag"},
8129 +       {Opt_notag, "notag"},
8130         {Opt_barrier, "barrier"},
8131         {Opt_nobarrier, "nobarrier"},
8132         {Opt_err, NULL}
8133 @@ -395,6 +402,19 @@ xfs_parseargs(
8134                 } else if (!strcmp(this_char, "irixsgid")) {
8135                         cmn_err(CE_WARN,
8136         "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
8137 +#ifndef CONFIG_TAGGING_NONE
8138 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
8139 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
8140 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
8141 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
8142 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
8143 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
8144 +#endif
8145 +#ifdef CONFIG_PROPAGATE
8146 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
8147 +                       /* use value */
8148 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
8149 +#endif
8150                 } else {
8151                         cmn_err(CE_WARN,
8152                                 "XFS: unknown mount option [%s].", this_char);
8153 @@ -1221,6 +1241,16 @@ xfs_fs_remount(
8154                 case Opt_nobarrier:
8155                         mp->m_flags &= ~XFS_MOUNT_BARRIER;
8156                         break;
8157 +               case Opt_tag:
8158 +                       if (!(sb->s_flags & MS_TAGGED)) {
8159 +                               printk(KERN_INFO
8160 +                                       "XFS: %s: tagging not permitted on remount.\n",
8161 +                                       sb->s_id);
8162 +                               return -EINVAL;
8163 +                       }
8164 +                       break;
8165 +               case Opt_notag:
8166 +                       break;
8167                 default:
8168                         /*
8169                          * Logically we would return an error here to prevent
8170 @@ -1480,6 +1510,9 @@ xfs_fs_fill_super(
8171  
8172         XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, mtpt, mp->m_fsname);
8173  
8174 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
8175 +               sb->s_flags |= MS_TAGGED;
8176 +
8177         sb->s_dirt = 1;
8178         sb->s_magic = XFS_SB_MAGIC;
8179         sb->s_blocksize = mp->m_sb.sb_blocksize;
8180 diff -NurpP --minimal linux-2.6.29.4/fs/xfs/quota/xfs_qm_syscalls.c linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/quota/xfs_qm_syscalls.c
8181 --- linux-2.6.29.4/fs/xfs/quota/xfs_qm_syscalls.c       2009-03-24 14:22:37.000000000 +0100
8182 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/quota/xfs_qm_syscalls.c 2009-03-24 14:48:35.000000000 +0100
8183 @@ -426,7 +426,7 @@ xfs_qm_scall_quotaon(
8184         uint            accflags;
8185         __int64_t       sbflags;
8186  
8187 -       if (!capable(CAP_SYS_ADMIN))
8188 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
8189                 return XFS_ERROR(EPERM);
8190  
8191         flags &= (XFS_ALL_QUOTA_ACCT | XFS_ALL_QUOTA_ENFD);
8192 diff -NurpP --minimal linux-2.6.29.4/fs/xfs/xfs_dinode.h linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_dinode.h
8193 --- linux-2.6.29.4/fs/xfs/xfs_dinode.h  2009-03-24 14:22:37.000000000 +0100
8194 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_dinode.h    2009-03-24 16:38:27.000000000 +0100
8195 @@ -50,7 +50,9 @@ typedef struct xfs_dinode {
8196         __be32          di_gid;         /* owner's group id */
8197         __be32          di_nlink;       /* number of links to file */
8198         __be16          di_projid;      /* owner's project id */
8199 -       __u8            di_pad[8];      /* unused, zeroed space */
8200 +       __be16          di_tag;         /* context tagging */
8201 +       __be16          di_vflags;      /* vserver specific flags */
8202 +       __u8            di_pad[4];      /* unused, zeroed space */
8203         __be16          di_flushiter;   /* incremented on flush */
8204         xfs_timestamp_t di_atime;       /* time last accessed */
8205         xfs_timestamp_t di_mtime;       /* time last modified */
8206 @@ -181,6 +183,8 @@ static inline void xfs_dinode_put_rdev(s
8207  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
8208  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
8209  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
8210 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
8211 +
8212  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
8213  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
8214  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
8215 @@ -196,6 +200,7 @@ static inline void xfs_dinode_put_rdev(s
8216  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
8217  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
8218  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
8219 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
8220  
8221  #ifdef CONFIG_XFS_RT
8222  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
8223 @@ -208,6 +213,10 @@ static inline void xfs_dinode_put_rdev(s
8224          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
8225          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
8226          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
8227 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
8228 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
8229 +        XFS_DIFLAG_IXUNLINK)
8230 +
8231 +#define XFS_DIVFLAG_BARRIER    0x01
8232 +#define XFS_DIVFLAG_COW                0x02
8233  
8234  #endif /* __XFS_DINODE_H__ */
8235 diff -NurpP --minimal linux-2.6.29.4/fs/xfs/xfs_fs.h linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_fs.h
8236 --- linux-2.6.29.4/fs/xfs/xfs_fs.h      2009-03-24 14:22:37.000000000 +0100
8237 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_fs.h        2009-03-24 14:48:35.000000000 +0100
8238 @@ -67,6 +67,9 @@ struct fsxattr {
8239  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
8240  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
8241  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
8242 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
8243 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
8244 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
8245  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
8246  
8247  /*
8248 @@ -289,7 +292,8 @@ typedef struct xfs_bstat {
8249         __s32           bs_extents;     /* number of extents            */
8250         __u32           bs_gen;         /* generation count             */
8251         __u16           bs_projid;      /* project id                   */
8252 -       unsigned char   bs_pad[14];     /* pad space, unused            */
8253 +       __u16           bs_tag;         /* context tagging              */
8254 +       unsigned char   bs_pad[12];     /* pad space, unused            */
8255         __u32           bs_dmevmask;    /* DMIG event mask              */
8256         __u16           bs_dmstate;     /* DMIG state info              */
8257         __u16           bs_aextents;    /* attribute number of extents  */
8258 diff -NurpP --minimal linux-2.6.29.4/fs/xfs/xfs_ialloc.c linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_ialloc.c
8259 --- linux-2.6.29.4/fs/xfs/xfs_ialloc.c  2009-03-24 14:22:37.000000000 +0100
8260 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_ialloc.c    2009-03-24 17:03:17.000000000 +0100
8261 @@ -41,7 +41,6 @@
8262  #include "xfs_error.h"
8263  #include "xfs_bmap.h"
8264  
8265 -
8266  /*
8267   * Allocation group level functions.
8268   */
8269 diff -NurpP --minimal linux-2.6.29.4/fs/xfs/xfs_inode.c linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_inode.c
8270 --- linux-2.6.29.4/fs/xfs/xfs_inode.c   2009-03-24 14:22:37.000000000 +0100
8271 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_inode.c     2009-03-25 01:42:50.000000000 +0100
8272 @@ -250,6 +250,7 @@ xfs_inotobp(
8273         return 0;
8274  }
8275  
8276 +#include <linux/vs_tag.h>
8277  
8278  /*
8279   * This routine is called to map an inode to the buffer containing
8280 @@ -645,15 +646,25 @@ xfs_iformat_btree(
8281  void
8282  xfs_dinode_from_disk(
8283         xfs_icdinode_t          *to,
8284 -       xfs_dinode_t            *from)
8285 +       xfs_dinode_t            *from,
8286 +       int tagged)
8287  {
8288 +       uint32_t uid, gid, tag;
8289 +
8290         to->di_magic = be16_to_cpu(from->di_magic);
8291         to->di_mode = be16_to_cpu(from->di_mode);
8292         to->di_version = from ->di_version;
8293         to->di_format = from->di_format;
8294         to->di_onlink = be16_to_cpu(from->di_onlink);
8295 -       to->di_uid = be32_to_cpu(from->di_uid);
8296 -       to->di_gid = be32_to_cpu(from->di_gid);
8297 +
8298 +       uid = be32_to_cpu(from->di_uid);
8299 +       gid = be32_to_cpu(from->di_gid);
8300 +       tag = be16_to_cpu(from->di_tag);
8301 +
8302 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
8303 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
8304 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
8305 +
8306         to->di_nlink = be32_to_cpu(from->di_nlink);
8307         to->di_projid = be16_to_cpu(from->di_projid);
8308         memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
8309 @@ -674,21 +685,26 @@ xfs_dinode_from_disk(
8310         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
8311         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
8312         to->di_flags    = be16_to_cpu(from->di_flags);
8313 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
8314         to->di_gen      = be32_to_cpu(from->di_gen);
8315  }
8316  
8317  void
8318  xfs_dinode_to_disk(
8319         xfs_dinode_t            *to,
8320 -       xfs_icdinode_t          *from)
8321 +       xfs_icdinode_t          *from,
8322 +       int tagged)
8323  {
8324         to->di_magic = cpu_to_be16(from->di_magic);
8325         to->di_mode = cpu_to_be16(from->di_mode);
8326         to->di_version = from ->di_version;
8327         to->di_format = from->di_format;
8328         to->di_onlink = cpu_to_be16(from->di_onlink);
8329 -       to->di_uid = cpu_to_be32(from->di_uid);
8330 -       to->di_gid = cpu_to_be32(from->di_gid);
8331 +
8332 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
8333 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
8334 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
8335 +
8336         to->di_nlink = cpu_to_be32(from->di_nlink);
8337         to->di_projid = cpu_to_be16(from->di_projid);
8338         memcpy(to->di_pad, from->di_pad, sizeof(to->di_pad));
8339 @@ -709,12 +725,14 @@ xfs_dinode_to_disk(
8340         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
8341         to->di_dmstate = cpu_to_be16(from->di_dmstate);
8342         to->di_flags = cpu_to_be16(from->di_flags);
8343 +       to->di_vflags = cpu_to_be16(from->di_vflags);
8344         to->di_gen = cpu_to_be32(from->di_gen);
8345  }
8346  
8347  STATIC uint
8348  _xfs_dic2xflags(
8349 -       __uint16_t              di_flags)
8350 +       __uint16_t              di_flags,
8351 +       __uint16_t              di_vflags)
8352  {
8353         uint                    flags = 0;
8354  
8355 @@ -725,6 +743,8 @@ _xfs_dic2xflags(
8356                         flags |= XFS_XFLAG_PREALLOC;
8357                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
8358                         flags |= XFS_XFLAG_IMMUTABLE;
8359 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
8360 +                       flags |= XFS_XFLAG_IXUNLINK;
8361                 if (di_flags & XFS_DIFLAG_APPEND)
8362                         flags |= XFS_XFLAG_APPEND;
8363                 if (di_flags & XFS_DIFLAG_SYNC)
8364 @@ -749,6 +769,10 @@ _xfs_dic2xflags(
8365                         flags |= XFS_XFLAG_FILESTREAM;
8366         }
8367  
8368 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
8369 +               flags |= FS_BARRIER_FL;
8370 +       if (di_vflags & XFS_DIVFLAG_COW)
8371 +               flags |= FS_COW_FL;
8372         return flags;
8373  }
8374  
8375 @@ -758,7 +782,7 @@ xfs_ip2xflags(
8376  {
8377         xfs_icdinode_t          *dic = &ip->i_d;
8378  
8379 -       return _xfs_dic2xflags(dic->di_flags) |
8380 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
8381                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
8382  }
8383  
8384 @@ -766,7 +790,8 @@ uint
8385  xfs_dic2xflags(
8386         xfs_dinode_t            *dip)
8387  {
8388 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
8389 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
8390 +                               be16_to_cpu(dip->di_vflags)) |
8391                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
8392  }
8393  
8394 @@ -802,7 +827,6 @@ xfs_iread(
8395         if (error)
8396                 return error;
8397         dip = (xfs_dinode_t *)xfs_buf_offset(bp, ip->i_imap.im_boffset);
8398 -
8399         /*
8400          * If we got something that isn't an inode it means someone
8401          * (nfs or dmi) has a stale handle.
8402 @@ -827,7 +851,8 @@ xfs_iread(
8403          * Otherwise, just get the truly permanent information.
8404          */
8405         if (dip->di_mode) {
8406 -               xfs_dinode_from_disk(&ip->i_d, dip);
8407 +               xfs_dinode_from_disk(&ip->i_d, dip,
8408 +                       mp->m_flags & XFS_MOUNT_TAGGED);
8409                 error = xfs_iformat(ip, dip);
8410                 if (error)  {
8411  #ifdef DEBUG
8412 @@ -1027,6 +1052,7 @@ xfs_ialloc(
8413         ASSERT(ip->i_d.di_nlink == nlink);
8414         ip->i_d.di_uid = current_fsuid();
8415         ip->i_d.di_gid = current_fsgid();
8416 +       ip->i_d.di_tag = current_fstag(cr, &ip->i_vnode);
8417         ip->i_d.di_projid = prid;
8418         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
8419  
8420 @@ -1087,6 +1113,7 @@ xfs_ialloc(
8421         ip->i_d.di_dmevmask = 0;
8422         ip->i_d.di_dmstate = 0;
8423         ip->i_d.di_flags = 0;
8424 +       ip->i_d.di_vflags = 0;
8425         flags = XFS_ILOG_CORE;
8426         switch (mode & S_IFMT) {
8427         case S_IFIFO:
8428 @@ -2161,6 +2188,7 @@ xfs_ifree(
8429         }
8430         ip->i_d.di_mode = 0;            /* mark incore inode as free */
8431         ip->i_d.di_flags = 0;
8432 +       ip->i_d.di_vflags = 0;
8433         ip->i_d.di_dmevmask = 0;
8434         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
8435         ip->i_df.if_ext_max =
8436 @@ -3128,7 +3156,8 @@ xfs_iflush_int(
8437          * because if the inode is dirty at all the core must
8438          * be.
8439          */
8440 -       xfs_dinode_to_disk(dip, &ip->i_d);
8441 +       xfs_dinode_to_disk(dip, &ip->i_d,
8442 +               mp->m_flags & XFS_MOUNT_TAGGED);
8443  
8444         /* Wrap, we never let the log put out DI_MAX_FLUSH */
8445         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
8446 diff -NurpP --minimal linux-2.6.29.4/fs/xfs/xfs_inode.h linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_inode.h
8447 --- linux-2.6.29.4/fs/xfs/xfs_inode.h   2009-03-24 14:22:37.000000000 +0100
8448 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_inode.h     2009-03-25 01:10:35.000000000 +0100
8449 @@ -134,7 +134,9 @@ typedef struct xfs_icdinode {
8450         __uint32_t      di_gid;         /* owner's group id */
8451         __uint32_t      di_nlink;       /* number of links to file */
8452         __uint16_t      di_projid;      /* owner's project id */
8453 -       __uint8_t       di_pad[8];      /* unused, zeroed space */
8454 +       __uint16_t      di_tag;         /* context tagging */
8455 +       __uint16_t      di_vflags;      /* vserver specific flags */
8456 +       __uint8_t       di_pad[4];      /* unused, zeroed space */
8457         __uint16_t      di_flushiter;   /* incremented on flush */
8458         xfs_ictimestamp_t di_atime;     /* time last accessed */
8459         xfs_ictimestamp_t di_mtime;     /* time last modified */
8460 @@ -589,9 +591,9 @@ int         xfs_itobp(struct xfs_mount *, struc
8461  int            xfs_iread(struct xfs_mount *, struct xfs_trans *,
8462                           struct xfs_inode *, xfs_daddr_t, uint);
8463  void           xfs_dinode_from_disk(struct xfs_icdinode *,
8464 -                                    struct xfs_dinode *);
8465 +                                    struct xfs_dinode *, int);
8466  void           xfs_dinode_to_disk(struct xfs_dinode *,
8467 -                                  struct xfs_icdinode *);
8468 +                                  struct xfs_icdinode *, int);
8469  void           xfs_idestroy_fork(struct xfs_inode *, int);
8470  void           xfs_idata_realloc(struct xfs_inode *, int, int);
8471  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
8472 diff -NurpP --minimal linux-2.6.29.4/fs/xfs/xfs_itable.c linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_itable.c
8473 --- linux-2.6.29.4/fs/xfs/xfs_itable.c  2009-03-24 14:22:37.000000000 +0100
8474 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_itable.c    2009-03-24 14:48:35.000000000 +0100
8475 @@ -82,6 +82,7 @@ xfs_bulkstat_one_iget(
8476         buf->bs_mode = dic->di_mode;
8477         buf->bs_uid = dic->di_uid;
8478         buf->bs_gid = dic->di_gid;
8479 +       buf->bs_tag = dic->di_tag;
8480         buf->bs_size = dic->di_size;
8481         vn_atime_to_bstime(VFS_I(ip), &buf->bs_atime);
8482         buf->bs_mtime.tv_sec = dic->di_mtime.t_sec;
8483 diff -NurpP --minimal linux-2.6.29.4/fs/xfs/xfs_log_recover.c linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_log_recover.c
8484 --- linux-2.6.29.4/fs/xfs/xfs_log_recover.c     2009-03-24 14:22:37.000000000 +0100
8485 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_log_recover.c       2009-03-24 17:17:15.000000000 +0100
8486 @@ -2421,7 +2421,8 @@ xlog_recover_do_inode_trans(
8487         }
8488  
8489         /* The core is in in-core format */
8490 -       xfs_dinode_to_disk(dip, (xfs_icdinode_t *)item->ri_buf[1].i_addr);
8491 +       xfs_dinode_to_disk(dip, (xfs_icdinode_t *)item->ri_buf[1].i_addr,
8492 +               mp->m_flags & XFS_MOUNT_TAGGED);
8493  
8494         /* the rest is in on-disk format */
8495         if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
8496 diff -NurpP --minimal linux-2.6.29.4/fs/xfs/xfs_mount.h linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_mount.h
8497 --- linux-2.6.29.4/fs/xfs/xfs_mount.h   2009-03-24 14:22:37.000000000 +0100
8498 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_mount.h     2009-03-24 14:48:35.000000000 +0100
8499 @@ -371,6 +371,7 @@ typedef struct xfs_mount {
8500                                                    allocator */
8501  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
8502  
8503 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
8504  
8505  /*
8506   * Default minimum read and write sizes.
8507 diff -NurpP --minimal linux-2.6.29.4/fs/xfs/xfs_vnodeops.c linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_vnodeops.c
8508 --- linux-2.6.29.4/fs/xfs/xfs_vnodeops.c        2009-03-24 14:22:37.000000000 +0100
8509 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_vnodeops.c  2009-03-24 17:18:40.000000000 +0100
8510 @@ -53,6 +53,90 @@
8511  #include "xfs_filestream.h"
8512  #include "xfs_vnodeops.h"
8513  
8514 +
8515 +STATIC void
8516 +xfs_get_inode_flags(
8517 +       xfs_inode_t     *ip)
8518 +{
8519 +       struct inode    *inode = VFS_I(ip);
8520 +       unsigned int    flags = inode->i_flags;
8521 +       unsigned int    vflags = inode->i_vflags;
8522 +
8523 +       if (flags & S_IMMUTABLE)
8524 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
8525 +       else
8526 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
8527 +       if (flags & S_IXUNLINK)
8528 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
8529 +       else
8530 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
8531 +
8532 +       if (vflags & V_BARRIER)
8533 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
8534 +       else
8535 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
8536 +       if (vflags & V_COW)
8537 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
8538 +       else
8539 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
8540 +}
8541 +
8542 +int
8543 +xfs_sync_xflags(
8544 +       xfs_inode_t             *ip)
8545 +{
8546 +       struct xfs_mount        *mp = ip->i_mount;
8547 +       struct xfs_trans        *tp;
8548 +       unsigned int            lock_flags = 0;
8549 +       int                     code;
8550 +
8551 +       xfs_itrace_entry(ip);
8552 +
8553 +       if (mp->m_flags & XFS_MOUNT_RDONLY)
8554 +               return XFS_ERROR(EROFS);
8555 +
8556 +       /*
8557 +        * we acquire the inode lock and do an error checking pass.
8558 +        */
8559 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
8560 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
8561 +       if (code)
8562 +               goto error_return;
8563 +
8564 +       lock_flags = XFS_ILOCK_EXCL;
8565 +       xfs_ilock(ip, lock_flags);
8566 +
8567 +       xfs_trans_ijoin(tp, ip, lock_flags);
8568 +       xfs_trans_ihold(tp, ip);
8569 +
8570 +       xfs_get_inode_flags(ip);
8571 +       // xfs_diflags_to_linux(ip);
8572 +
8573 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
8574 +       xfs_ichgtime(ip, XFS_ICHGTIME_CHG);
8575 +
8576 +       XFS_STATS_INC(xs_ig_attrchg);
8577 +
8578 +       /*
8579 +        * If this is a synchronous mount, make sure that the
8580 +        * transaction goes to disk before returning to the user.
8581 +        */
8582 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
8583 +               xfs_trans_set_sync(tp);
8584 +       code = xfs_trans_commit(tp, 0);
8585 +       xfs_iunlock(ip, lock_flags);
8586 +
8587 +       if (code)
8588 +               return code;
8589 +       return 0;
8590 +
8591 + error_return:
8592 +       xfs_trans_cancel(tp, 0);
8593 +       if (lock_flags)
8594 +               xfs_iunlock(ip, lock_flags);
8595 +       return code;
8596 +}
8597 +
8598  int
8599  xfs_setattr(
8600         struct xfs_inode        *ip,
8601 @@ -68,6 +152,7 @@ xfs_setattr(
8602         uint                    commit_flags=0;
8603         uid_t                   uid=0, iuid=0;
8604         gid_t                   gid=0, igid=0;
8605 +       tag_t                   tag=0, itag=0;
8606         int                     timeflags = 0;
8607         struct xfs_dquot        *udqp, *gdqp, *olddquot1, *olddquot2;
8608         int                     need_iolock = 1;
8609 @@ -164,7 +249,7 @@ xfs_setattr(
8610         /*
8611          * Change file ownership.  Must be the owner or privileged.
8612          */
8613 -       if (mask & (ATTR_UID|ATTR_GID)) {
8614 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8615                 /*
8616                  * These IDs could have changed since we last looked at them.
8617                  * But, we're assured that if the ownership did change
8618 @@ -173,15 +258,19 @@ xfs_setattr(
8619                  */
8620                 iuid = ip->i_d.di_uid;
8621                 igid = ip->i_d.di_gid;
8622 +               itag = ip->i_d.di_tag;
8623                 gid = (mask & ATTR_GID) ? iattr->ia_gid : igid;
8624                 uid = (mask & ATTR_UID) ? iattr->ia_uid : iuid;
8625 +               tag = (mask & ATTR_TAG) ? iattr->ia_tag : itag;
8626  
8627                 /*
8628                  * Do a quota reservation only if uid/gid is actually
8629                  * going to change.
8630                  */
8631                 if ((XFS_IS_UQUOTA_ON(mp) && iuid != uid) ||
8632 -                   (XFS_IS_GQUOTA_ON(mp) && igid != gid)) {
8633 +                   (XFS_IS_GQUOTA_ON(mp) && igid != gid) ||
8634 +                   (XFS_IS_GQUOTA_ON(mp) && itag != tag)) {
8635 +                       /* TODO: handle tagging? */
8636                         ASSERT(tp);
8637                         code = XFS_QM_DQVOPCHOWNRESV(mp, tp, ip, udqp, gdqp,
8638                                                 capable(CAP_FOWNER) ?
8639 @@ -334,7 +423,7 @@ xfs_setattr(
8640         /*
8641          * Change file ownership.  Must be the owner or privileged.
8642          */
8643 -       if (mask & (ATTR_UID|ATTR_GID)) {
8644 +       if (mask & (ATTR_UID|ATTR_GID|ATTR_TAG)) {
8645                 /*
8646                  * CAP_FSETID overrides the following restrictions:
8647                  *
8648 @@ -350,6 +439,10 @@ xfs_setattr(
8649                  * Change the ownerships and register quota modifications
8650                  * in the transaction.
8651                  */
8652 +               if (itag != tag) {
8653 +                       ip->i_d.di_tag = tag;
8654 +                       inode->i_tag = tag;
8655 +               }
8656                 if (iuid != uid) {
8657                         if (XFS_IS_UQUOTA_ON(mp)) {
8658                                 ASSERT(mask & ATTR_UID);
8659 diff -NurpP --minimal linux-2.6.29.4/fs/xfs/xfs_vnodeops.h linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_vnodeops.h
8660 --- linux-2.6.29.4/fs/xfs/xfs_vnodeops.h        2009-03-24 14:22:37.000000000 +0100
8661 +++ linux-2.6.29.4-vs2.3.0.36.14/fs/xfs/xfs_vnodeops.h  2009-03-24 17:19:30.000000000 +0100
8662 @@ -14,6 +14,7 @@ struct xfs_inode;
8663  struct xfs_iomap;
8664  
8665  
8666 +int xfs_sync_xflags(struct xfs_inode *ip);
8667  int xfs_setattr(struct xfs_inode *ip, struct iattr *vap, int flags);
8668  #define        XFS_ATTR_DMI            0x01    /* invocation from a DMI function */
8669  #define        XFS_ATTR_NONBLOCK       0x02    /* return EAGAIN if operation would block */
8670 diff -NurpP --minimal linux-2.6.29.4/include/asm-generic/tlb.h linux-2.6.29.4-vs2.3.0.36.14/include/asm-generic/tlb.h
8671 --- linux-2.6.29.4/include/asm-generic/tlb.h    2008-12-25 00:26:37.000000000 +0100
8672 +++ linux-2.6.29.4-vs2.3.0.36.14/include/asm-generic/tlb.h      2009-04-08 15:50:06.000000000 +0200
8673 @@ -14,6 +14,7 @@
8674  #define _ASM_GENERIC__TLB_H
8675  
8676  #include <linux/swap.h>
8677 +#include <linux/vs_memory.h>
8678  #include <asm/pgalloc.h>
8679  #include <asm/tlbflush.h>
8680  
8681 diff -NurpP --minimal linux-2.6.29.4/include/linux/capability.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/capability.h
8682 --- linux-2.6.29.4/include/linux/capability.h   2009-05-23 23:16:53.000000000 +0200
8683 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/capability.h     2009-04-30 12:14:53.000000000 +0200
8684 @@ -285,6 +285,7 @@ struct cpu_vfs_cap_data {
8685     arbitrary SCSI commands */
8686  /* Allow setting encryption key on loopback filesystem */
8687  /* Allow setting zone reclaim policy */
8688 +/* Allow the selection of a security context */
8689  
8690  #define CAP_SYS_ADMIN        21
8691  
8692 @@ -357,7 +358,13 @@ struct cpu_vfs_cap_data {
8693  
8694  #define CAP_MAC_ADMIN        33
8695  
8696 -#define CAP_LAST_CAP         CAP_MAC_ADMIN
8697 +/* Allow context manipulations */
8698 +/* Allow changing context info on files */
8699 +
8700 +#define CAP_CONTEXT         34
8701 +
8702 +
8703 +#define CAP_LAST_CAP         CAP_CONTEXT
8704  
8705  #define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
8706  
8707 diff -NurpP --minimal linux-2.6.29.4/include/linux/devpts_fs.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/devpts_fs.h
8708 --- linux-2.6.29.4/include/linux/devpts_fs.h    2008-12-25 00:26:37.000000000 +0100
8709 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/devpts_fs.h      2009-02-22 22:54:26.000000000 +0100
8710 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
8711  
8712  #endif
8713  
8714 -
8715  #endif /* _LINUX_DEVPTS_FS_H */
8716 diff -NurpP --minimal linux-2.6.29.4/include/linux/ext2_fs.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/ext2_fs.h
8717 --- linux-2.6.29.4/include/linux/ext2_fs.h      2009-03-24 14:22:41.000000000 +0100
8718 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/ext2_fs.h        2009-03-24 15:39:54.000000000 +0100
8719 @@ -189,8 +189,12 @@ struct ext2_group_desc
8720  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
8721  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
8722  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
8723 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
8724  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
8725  
8726 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
8727 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
8728 +
8729  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
8730  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
8731  
8732 @@ -271,7 +275,7 @@ struct ext2_inode {
8733                 struct {
8734                         __u8    l_i_frag;       /* Fragment number */
8735                         __u8    l_i_fsize;      /* Fragment size */
8736 -                       __u16   i_pad1;
8737 +                       __u16   l_i_tag;        /* Context Tag */
8738                         __le16  l_i_uid_high;   /* these 2 fields    */
8739                         __le16  l_i_gid_high;   /* were reserved2[0] */
8740                         __u32   l_i_reserved2;
8741 @@ -303,6 +307,7 @@ struct ext2_inode {
8742  #define i_gid_low      i_gid
8743  #define i_uid_high     osd2.linux2.l_i_uid_high
8744  #define i_gid_high     osd2.linux2.l_i_gid_high
8745 +#define i_raw_tag      osd2.linux2.l_i_tag
8746  #define i_reserved2    osd2.linux2.l_i_reserved2
8747  #endif
8748  
8749 @@ -347,6 +352,7 @@ struct ext2_inode {
8750  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
8751  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
8752  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
8753 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
8754  
8755  
8756  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
8757 diff -NurpP --minimal linux-2.6.29.4/include/linux/ext3_fs.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/ext3_fs.h
8758 --- linux-2.6.29.4/include/linux/ext3_fs.h      2009-03-24 14:22:41.000000000 +0100
8759 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/ext3_fs.h        2009-03-24 14:48:36.000000000 +0100
8760 @@ -173,10 +173,14 @@ struct ext3_group_desc
8761  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
8762  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
8763  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
8764 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
8765  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
8766  
8767 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
8768 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
8769 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
8770 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
8771 +
8772 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
8773 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
8774  
8775  /* Flags that should be inherited by new inodes from their parent. */
8776  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
8777 @@ -316,7 +320,7 @@ struct ext3_inode {
8778                 struct {
8779                         __u8    l_i_frag;       /* Fragment number */
8780                         __u8    l_i_fsize;      /* Fragment size */
8781 -                       __u16   i_pad1;
8782 +                       __u16   l_i_tag;        /* Context Tag */
8783                         __le16  l_i_uid_high;   /* these 2 fields    */
8784                         __le16  l_i_gid_high;   /* were reserved2[0] */
8785                         __u32   l_i_reserved2;
8786 @@ -350,6 +354,7 @@ struct ext3_inode {
8787  #define i_gid_low      i_gid
8788  #define i_uid_high     osd2.linux2.l_i_uid_high
8789  #define i_gid_high     osd2.linux2.l_i_gid_high
8790 +#define i_raw_tag      osd2.linux2.l_i_tag
8791  #define i_reserved2    osd2.linux2.l_i_reserved2
8792  
8793  #elif defined(__GNU__)
8794 @@ -413,6 +418,7 @@ struct ext3_inode {
8795  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
8796  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
8797                                                   * error in ordered mode */
8798 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
8799  
8800  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
8801  #ifndef _LINUX_EXT2_FS_H
8802 @@ -874,6 +880,7 @@ struct buffer_head * ext3_bread (handle_
8803  int ext3_get_blocks_handle(handle_t *handle, struct inode *inode,
8804         sector_t iblock, unsigned long maxblocks, struct buffer_head *bh_result,
8805         int create, int extend_disksize);
8806 +extern int ext3_sync_flags(struct inode *inode);
8807  
8808  extern struct inode *ext3_iget(struct super_block *, unsigned long);
8809  extern int  ext3_write_inode (struct inode *, int);
8810 diff -NurpP --minimal linux-2.6.29.4/include/linux/fs.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/fs.h
8811 --- linux-2.6.29.4/include/linux/fs.h   2009-03-24 14:22:41.000000000 +0100
8812 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/fs.h     2009-03-24 17:21:20.000000000 +0100
8813 @@ -141,6 +141,9 @@ struct inodes_stat_t {
8814  #define MS_RELATIME    (1<<21) /* Update atime relative to mtime/ctime. */
8815  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
8816  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
8817 +#define MS_TAGGED      (1<<24) /* use generic inode tagging */
8818 +#define MS_TAGID       (1<<25) /* use specific tag for this mount */
8819 +#define MS_NOTAGCHECK  (1<<26) /* don't check tags */
8820  #define MS_ACTIVE      (1<<30)
8821  #define MS_NOUSER      (1<<31)
8822  
8823 @@ -167,6 +170,14 @@ struct inodes_stat_t {
8824  #define S_PRIVATE      512     /* Inode is fs-internal */
8825  #define S_ATOMIC_COPY  1024    /* Pages mapped with this inode need to be
8826                                    atomically copied (gem) */
8827 +#define S_IXUNLINK     2048    /* Immutable Invert on unlink */
8828 +
8829 +/* Linux-VServer related Inode flags */
8830 +
8831 +#define V_VALID                1
8832 +#define V_XATTR                2
8833 +#define V_BARRIER      4       /* Barrier for chroot() */
8834 +#define V_COW          8       /* Copy on Write */
8835  
8836  /*
8837   * Note that nosuid etc flags are inode-specific: setting some file-system
8838 @@ -189,12 +200,15 @@ struct inodes_stat_t {
8839  #define IS_DIRSYNC(inode)      (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \
8840                                         ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))
8841  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
8842 -#define IS_NOATIME(inode)   __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8843 -#define IS_I_VERSION(inode)   __IS_FLG(inode, MS_I_VERSION)
8844 +#define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
8845 +#define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
8846 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
8847  
8848  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
8849  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
8850  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
8851 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
8852 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
8853  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
8854  
8855  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
8856 @@ -202,6 +216,16 @@ struct inodes_stat_t {
8857  #define IS_SWAPFILE(inode)     ((inode)->i_flags & S_SWAPFILE)
8858  #define IS_PRIVATE(inode)      ((inode)->i_flags & S_PRIVATE)
8859  
8860 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
8861 +
8862 +#ifdef CONFIG_VSERVER_COWBL
8863 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
8864 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
8865 +#else
8866 +#  define IS_COW(inode)                (0)
8867 +#  define IS_COW_LINK(inode)   (0)
8868 +#endif
8869 +
8870  /* the read-only stuff doesn't really belong here, but any other place is
8871     probably as bad and I don't want to create yet another include file. */
8872  
8873 @@ -279,11 +303,14 @@ struct inodes_stat_t {
8874  #define FS_TOPDIR_FL                   0x00020000 /* Top of directory hierarchies*/
8875  #define FS_EXTENT_FL                   0x00080000 /* Extents */
8876  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
8877 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
8878  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
8879  
8880 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
8881 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
8882 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
8883 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
8884  
8885 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
8886 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
8887  
8888  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
8889  #define SYNC_FILE_RANGE_WRITE          2
8890 @@ -365,6 +392,7 @@ typedef void (dio_iodone_t)(struct kiocb
8891  #define ATTR_KILL_PRIV (1 << 14)
8892  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
8893  #define ATTR_TIMES_SET (1 << 16)
8894 +#define ATTR_TAG       (1 << 17)
8895  
8896  /*
8897   * This is the Inode Attributes structure, used for notify_change().  It
8898 @@ -380,6 +408,7 @@ struct iattr {
8899         umode_t         ia_mode;
8900         uid_t           ia_uid;
8901         gid_t           ia_gid;
8902 +       tag_t           ia_tag;
8903         loff_t          ia_size;
8904         struct timespec ia_atime;
8905         struct timespec ia_mtime;
8906 @@ -393,6 +422,9 @@ struct iattr {
8907         struct file     *ia_file;
8908  };
8909  
8910 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
8911 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
8912 +
8913  /*
8914   * Includes for diskquotas.
8915   */
8916 @@ -656,7 +688,9 @@ struct inode {
8917         unsigned int            i_nlink;
8918         uid_t                   i_uid;
8919         gid_t                   i_gid;
8920 +       tag_t                   i_tag;
8921         dev_t                   i_rdev;
8922 +       dev_t                   i_mdev;
8923         u64                     i_version;
8924         loff_t                  i_size;
8925  #ifdef __NEED_I_SIZE_ORDERED
8926 @@ -704,7 +738,8 @@ struct inode {
8927         unsigned long           i_state;
8928         unsigned long           dirtied_when;   /* jiffies of first dirtying */
8929  
8930 -       unsigned int            i_flags;
8931 +       unsigned short          i_flags;
8932 +       unsigned short          i_vflags;
8933  
8934         atomic_t                i_writecount;
8935  #ifdef CONFIG_SECURITY
8936 @@ -791,12 +826,12 @@ static inline void i_size_write(struct i
8937  
8938  static inline unsigned iminor(const struct inode *inode)
8939  {
8940 -       return MINOR(inode->i_rdev);
8941 +       return MINOR(inode->i_mdev);
8942  }
8943  
8944  static inline unsigned imajor(const struct inode *inode)
8945  {
8946 -       return MAJOR(inode->i_rdev);
8947 +       return MAJOR(inode->i_mdev);
8948  }
8949  
8950  extern struct block_device *I_BDEV(struct inode *inode);
8951 @@ -854,6 +889,7 @@ struct file {
8952         loff_t                  f_pos;
8953         struct fown_struct      f_owner;
8954         const struct cred       *f_cred;
8955 +       xid_t                   f_xid;
8956         struct file_ra_state    f_ra;
8957  
8958         u64                     f_version;
8959 @@ -996,6 +1032,7 @@ struct file_lock {
8960         struct file *fl_file;
8961         loff_t fl_start;
8962         loff_t fl_end;
8963 +       xid_t fl_xid;
8964  
8965         struct fasync_struct *  fl_fasync; /* for lease break notifications */
8966         unsigned long fl_break_time;    /* for nonblocking lease breaks */
8967 @@ -1363,6 +1400,7 @@ struct inode_operations {
8968                           loff_t len);
8969         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
8970                       u64 len);
8971 +       int (*sync_flags) (struct inode *);
8972  };
8973  
8974  struct seq_file;
8975 @@ -1378,6 +1416,7 @@ extern ssize_t vfs_readv(struct file *, 
8976                 unsigned long, loff_t *);
8977  extern ssize_t vfs_writev(struct file *, const struct iovec __user *,
8978                 unsigned long, loff_t *);
8979 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
8980  
8981  struct super_operations {
8982         struct inode *(*alloc_inode)(struct super_block *sb);
8983 @@ -2096,6 +2135,7 @@ extern int dcache_dir_open(struct inode 
8984  extern int dcache_dir_close(struct inode *, struct file *);
8985  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
8986  extern int dcache_readdir(struct file *, void *, filldir_t);
8987 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
8988  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
8989  extern int simple_statfs(struct dentry *, struct kstatfs *);
8990  extern int simple_link(struct dentry *, struct inode *, struct dentry *);
8991 diff -NurpP --minimal linux-2.6.29.4/include/linux/if_tun.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/if_tun.h
8992 --- linux-2.6.29.4/include/linux/if_tun.h       2008-12-25 00:26:37.000000000 +0100
8993 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/if_tun.h 2009-02-22 22:54:26.000000000 +0100
8994 @@ -46,6 +46,7 @@
8995  #define TUNSETOFFLOAD  _IOW('T', 208, unsigned int)
8996  #define TUNSETTXFILTER _IOW('T', 209, unsigned int)
8997  #define TUNGETIFF      _IOR('T', 210, unsigned int)
8998 +#define TUNSETNID     _IOW('T', 215, int)
8999  
9000  /* TUNSETIFF ifr flags */
9001  #define IFF_TUN                0x0001
9002 diff -NurpP --minimal linux-2.6.29.4/include/linux/init_task.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/init_task.h
9003 --- linux-2.6.29.4/include/linux/init_task.h    2009-03-24 14:22:41.000000000 +0100
9004 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/init_task.h      2009-03-24 14:48:36.000000000 +0100
9005 @@ -184,6 +184,10 @@ extern struct cred init_cred;
9006         INIT_IDS                                                        \
9007         INIT_TRACE_IRQFLAGS                                             \
9008         INIT_LOCKDEP                                                    \
9009 +       .xid            = 0,                                            \
9010 +       .vx_info        = NULL,                                         \
9011 +       .nid            = 0,                                            \
9012 +       .nx_info        = NULL,                                         \
9013  }
9014  
9015  
9016 diff -NurpP --minimal linux-2.6.29.4/include/linux/interrupt.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/interrupt.h
9017 --- linux-2.6.29.4/include/linux/interrupt.h    2009-05-23 23:16:53.000000000 +0200
9018 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/interrupt.h      2009-04-30 12:14:53.000000000 +0200
9019 @@ -9,8 +9,8 @@
9020  #include <linux/cpumask.h>
9021  #include <linux/irqreturn.h>
9022  #include <linux/irqnr.h>
9023 -#include <linux/hardirq.h>
9024  #include <linux/sched.h>
9025 +#include <linux/hardirq.h>
9026  #include <linux/irqflags.h>
9027  #include <linux/smp.h>
9028  #include <linux/percpu.h>
9029 diff -NurpP --minimal linux-2.6.29.4/include/linux/ipc.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/ipc.h
9030 --- linux-2.6.29.4/include/linux/ipc.h  2008-12-25 00:26:37.000000000 +0100
9031 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/ipc.h    2009-02-22 22:54:26.000000000 +0100
9032 @@ -93,6 +93,7 @@ struct kern_ipc_perm
9033         key_t           key;
9034         uid_t           uid;
9035         gid_t           gid;
9036 +       xid_t           xid;
9037         uid_t           cuid;
9038         gid_t           cgid;
9039         mode_t          mode; 
9040 diff -NurpP --minimal linux-2.6.29.4/include/linux/Kbuild linux-2.6.29.4-vs2.3.0.36.14/include/linux/Kbuild
9041 --- linux-2.6.29.4/include/linux/Kbuild 2009-03-24 14:22:40.000000000 +0100
9042 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/Kbuild   2009-03-24 17:22:07.000000000 +0100
9043 @@ -373,5 +373,8 @@ unifdef-y += xattr.h
9044  unifdef-y += xfrm.h
9045  
9046  objhdr-y += version.h
9047 +
9048 +header-y += vserver/
9049  header-y += wimax.h
9050  header-y += wimax/
9051 +
9052 diff -NurpP --minimal linux-2.6.29.4/include/linux/loop.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/loop.h
9053 --- linux-2.6.29.4/include/linux/loop.h 2009-03-24 14:22:42.000000000 +0100
9054 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/loop.h   2009-03-24 14:48:36.000000000 +0100
9055 @@ -45,6 +45,7 @@ struct loop_device {
9056         struct loop_func_table *lo_encryption;
9057         __u32           lo_init[2];
9058         uid_t           lo_key_owner;   /* Who set the key */
9059 +       xid_t           lo_xid;
9060         int             (*ioctl)(struct loop_device *, int cmd, 
9061                                  unsigned long arg); 
9062  
9063 diff -NurpP --minimal linux-2.6.29.4/include/linux/magic.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/magic.h
9064 --- linux-2.6.29.4/include/linux/magic.h        2009-03-24 14:22:42.000000000 +0100
9065 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/magic.h  2009-03-24 14:48:36.000000000 +0100
9066 @@ -3,7 +3,7 @@
9067  
9068  #define ADFS_SUPER_MAGIC       0xadf5
9069  #define AFFS_SUPER_MAGIC       0xadff
9070 -#define AFS_SUPER_MAGIC                0x5346414F
9071 +#define AFS_SUPER_MAGIC                0x5346414F
9072  #define AUTOFS_SUPER_MAGIC     0x0187
9073  #define CODA_SUPER_MAGIC       0x73757245
9074  #define DEBUGFS_MAGIC          0x64626720
9075 @@ -33,6 +33,7 @@
9076  #define NFS_SUPER_MAGIC                0x6969
9077  #define OPENPROM_SUPER_MAGIC   0x9fa1
9078  #define PROC_SUPER_MAGIC       0x9fa0
9079 +#define DEVPTS_SUPER_MAGIC     0x1cd1
9080  #define QNX4_SUPER_MAGIC       0x002f          /* qnx4 fs detection */
9081  
9082  #define REISERFS_SUPER_MAGIC   0x52654973      /* used by gcc */
9083 diff -NurpP --minimal linux-2.6.29.4/include/linux/major.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/major.h
9084 --- linux-2.6.29.4/include/linux/major.h        2008-12-25 00:26:37.000000000 +0100
9085 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/major.h  2009-02-22 22:54:26.000000000 +0100
9086 @@ -15,6 +15,7 @@
9087  #define HD_MAJOR               IDE0_MAJOR
9088  #define PTY_SLAVE_MAJOR                3
9089  #define TTY_MAJOR              4
9090 +#define VROOT_MAJOR            4
9091  #define TTYAUX_MAJOR           5
9092  #define LP_MAJOR               6
9093  #define VCS_MAJOR              7
9094 diff -NurpP --minimal linux-2.6.29.4/include/linux/mm_types.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/mm_types.h
9095 --- linux-2.6.29.4/include/linux/mm_types.h     2009-03-24 14:22:42.000000000 +0100
9096 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/mm_types.h       2009-03-24 14:48:36.000000000 +0100
9097 @@ -232,6 +232,7 @@ struct mm_struct {
9098  
9099         /* Architecture-specific MM context */
9100         mm_context_t context;
9101 +       struct vx_info *mm_vx_info;
9102  
9103         /* Swap token stuff */
9104         /*
9105 diff -NurpP --minimal linux-2.6.29.4/include/linux/mount.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/mount.h
9106 --- linux-2.6.29.4/include/linux/mount.h        2008-12-25 00:26:37.000000000 +0100
9107 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/mount.h  2009-02-22 22:54:26.000000000 +0100
9108 @@ -35,6 +35,9 @@ struct mnt_namespace;
9109  #define MNT_UNBINDABLE 0x2000  /* if the vfsmount is a unbindable mount */
9110  #define MNT_PNODE_MASK 0x3000  /* propagation flag mask */
9111  
9112 +#define MNT_TAGID      0x10000
9113 +#define MNT_NOTAG      0x20000
9114 +
9115  struct vfsmount {
9116         struct list_head mnt_hash;
9117         struct vfsmount *mnt_parent;    /* fs we are mounted on */
9118 @@ -69,6 +72,7 @@ struct vfsmount {
9119          * are held, and all mnt_writer[]s on this mount have 0 as their ->count
9120          */
9121         atomic_t __mnt_writers;
9122 +       tag_t mnt_tag;                  /* tagging used for vfsmount */
9123  };
9124  
9125  static inline struct vfsmount *mntget(struct vfsmount *mnt)
9126 diff -NurpP --minimal linux-2.6.29.4/include/linux/net.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/net.h
9127 --- linux-2.6.29.4/include/linux/net.h  2008-12-25 00:26:37.000000000 +0100
9128 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/net.h    2009-02-22 22:54:26.000000000 +0100
9129 @@ -68,6 +68,7 @@ struct net;
9130  #define SOCK_NOSPACE           2
9131  #define SOCK_PASSCRED          3
9132  #define SOCK_PASSSEC           4
9133 +#define SOCK_USER_SOCKET       5
9134  
9135  #ifndef ARCH_HAS_SOCKET_TYPES
9136  /**
9137 diff -NurpP --minimal linux-2.6.29.4/include/linux/nfs_mount.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/nfs_mount.h
9138 --- linux-2.6.29.4/include/linux/nfs_mount.h    2009-03-24 14:22:43.000000000 +0100
9139 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/nfs_mount.h      2009-03-24 14:48:36.000000000 +0100
9140 @@ -63,7 +63,8 @@ struct nfs_mount_data {
9141  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
9142  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
9143  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
9144 -#define NFS_MOUNT_FLAGMASK     0xFFFF
9145 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
9146 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
9147  
9148  /* The following are for internal use only */
9149  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
9150 diff -NurpP --minimal linux-2.6.29.4/include/linux/nsproxy.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/nsproxy.h
9151 --- linux-2.6.29.4/include/linux/nsproxy.h      2009-03-24 14:22:43.000000000 +0100
9152 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/nsproxy.h        2009-03-24 14:48:36.000000000 +0100
9153 @@ -3,6 +3,7 @@
9154  
9155  #include <linux/spinlock.h>
9156  #include <linux/sched.h>
9157 +#include <linux/vserver/debug.h>
9158  
9159  struct mnt_namespace;
9160  struct uts_namespace;
9161 @@ -62,22 +63,33 @@ static inline struct nsproxy *task_nspro
9162  }
9163  
9164  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
9165 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
9166  void exit_task_namespaces(struct task_struct *tsk);
9167  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
9168  void free_nsproxy(struct nsproxy *ns);
9169  int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
9170         struct fs_struct *);
9171  
9172 -static inline void put_nsproxy(struct nsproxy *ns)
9173 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
9174 +
9175 +static inline void __get_nsproxy(struct nsproxy *ns,
9176 +       const char *_file, int _line)
9177  {
9178 -       if (atomic_dec_and_test(&ns->count)) {
9179 -               free_nsproxy(ns);
9180 -       }
9181 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
9182 +               ns, atomic_read(&ns->count), _file, _line);
9183 +       atomic_inc(&ns->count);
9184  }
9185  
9186 -static inline void get_nsproxy(struct nsproxy *ns)
9187 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
9188 +
9189 +static inline void __put_nsproxy(struct nsproxy *ns,
9190 +       const char *_file, int _line)
9191  {
9192 -       atomic_inc(&ns->count);
9193 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
9194 +               ns, atomic_read(&ns->count), _file, _line);
9195 +       if (atomic_dec_and_test(&ns->count)) {
9196 +               free_nsproxy(ns);
9197 +       }
9198  }
9199  
9200  #ifdef CONFIG_CGROUP_NS
9201 diff -NurpP --minimal linux-2.6.29.4/include/linux/pid.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/pid.h
9202 --- linux-2.6.29.4/include/linux/pid.h  2009-03-24 14:22:43.000000000 +0100
9203 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/pid.h    2009-03-24 14:48:36.000000000 +0100
9204 @@ -8,7 +8,8 @@ enum pid_type
9205         PIDTYPE_PID,
9206         PIDTYPE_PGID,
9207         PIDTYPE_SID,
9208 -       PIDTYPE_MAX
9209 +       PIDTYPE_MAX,
9210 +       PIDTYPE_REALPID
9211  };
9212  
9213  /*
9214 @@ -160,6 +161,7 @@ static inline pid_t pid_nr(struct pid *p
9215  }
9216  
9217  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
9218 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
9219  pid_t pid_vnr(struct pid *pid);
9220  
9221  #define do_each_pid_task(pid, type, task)                              \
9222 diff -NurpP --minimal linux-2.6.29.4/include/linux/proc_fs.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/proc_fs.h
9223 --- linux-2.6.29.4/include/linux/proc_fs.h      2008-12-25 00:26:37.000000000 +0100
9224 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/proc_fs.h        2009-02-22 22:54:26.000000000 +0100
9225 @@ -59,6 +59,7 @@ struct proc_dir_entry {
9226         nlink_t nlink;
9227         uid_t uid;
9228         gid_t gid;
9229 +       int vx_flags;
9230         loff_t size;
9231         const struct inode_operations *proc_iops;
9232         /*
9233 @@ -268,12 +269,18 @@ static inline void kclist_add(struct kco
9234  extern void kclist_add(struct kcore_list *, void *, size_t);
9235  #endif
9236  
9237 +struct vx_info;
9238 +struct nx_info;
9239 +
9240  union proc_op {
9241         int (*proc_get_link)(struct inode *, struct path *);
9242         int (*proc_read)(struct task_struct *task, char *page);
9243         int (*proc_show)(struct seq_file *m,
9244                 struct pid_namespace *ns, struct pid *pid,
9245                 struct task_struct *task);
9246 +       int (*proc_vs_read)(char *page);
9247 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
9248 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
9249  };
9250  
9251  struct ctl_table_header;
9252 @@ -281,6 +288,7 @@ struct ctl_table;
9253  
9254  struct proc_inode {
9255         struct pid *pid;
9256 +       int vx_flags;
9257         int fd;
9258         union proc_op op;
9259         struct proc_dir_entry *pde;
9260 diff -NurpP --minimal linux-2.6.29.4/include/linux/reiserfs_fs.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/reiserfs_fs.h
9261 --- linux-2.6.29.4/include/linux/reiserfs_fs.h  2008-12-25 00:26:37.000000000 +0100
9262 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/reiserfs_fs.h    2009-02-22 22:54:26.000000000 +0100
9263 @@ -837,6 +837,11 @@ struct stat_data_v1 {
9264  #define REISERFS_COMPR_FL     FS_COMPR_FL
9265  #define REISERFS_NOTAIL_FL    FS_NOTAIL_FL
9266  
9267 +/* unfortunately reiserfs sdattr is only 16 bit */
9268 +#define REISERFS_IXUNLINK_FL  (FS_IXUNLINK_FL >> 16)
9269 +#define REISERFS_BARRIER_FL   (FS_BARRIER_FL >> 16)
9270 +#define REISERFS_COW_FL       (FS_COW_FL >> 16)
9271 +
9272  /* persistent flags that file inherits from the parent directory */
9273  #define REISERFS_INHERIT_MASK ( REISERFS_IMMUTABLE_FL |        \
9274                                 REISERFS_SYNC_FL |      \
9275 @@ -846,6 +851,9 @@ struct stat_data_v1 {
9276                                 REISERFS_COMPR_FL |     \
9277                                 REISERFS_NOTAIL_FL )
9278  
9279 +#define REISERFS_FL_USER_VISIBLE       0x80FF
9280 +#define REISERFS_FL_USER_MODIFIABLE    0x80FF
9281 +
9282  /* Stat Data on disk (reiserfs version of UFS disk inode minus the
9283     address blocks) */
9284  struct stat_data {
9285 @@ -1911,6 +1919,7 @@ static inline void reiserfs_update_sd(st
9286  void sd_attrs_to_i_attrs(__u16 sd_attrs, struct inode *inode);
9287  void i_attrs_to_sd_attrs(struct inode *inode, __u16 * sd_attrs);
9288  int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
9289 +int reiserfs_sync_flags(struct inode *inode);
9290  
9291  /* namei.c */
9292  void set_de_name_and_namelen(struct reiserfs_dir_entry *de);
9293 diff -NurpP --minimal linux-2.6.29.4/include/linux/reiserfs_fs_sb.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/reiserfs_fs_sb.h
9294 --- linux-2.6.29.4/include/linux/reiserfs_fs_sb.h       2008-12-25 00:26:37.000000000 +0100
9295 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/reiserfs_fs_sb.h 2009-02-22 22:54:26.000000000 +0100
9296 @@ -456,6 +456,7 @@ enum reiserfs_mount_options {
9297         REISERFS_POSIXACL,
9298         REISERFS_BARRIER_NONE,
9299         REISERFS_BARRIER_FLUSH,
9300 +       REISERFS_TAGGED,
9301  
9302         /* Actions on error */
9303         REISERFS_ERROR_PANIC,
9304 diff -NurpP --minimal linux-2.6.29.4/include/linux/sched.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/sched.h
9305 --- linux-2.6.29.4/include/linux/sched.h        2009-05-23 23:16:53.000000000 +0200
9306 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/sched.h  2009-04-30 12:14:53.000000000 +0200
9307 @@ -71,7 +71,6 @@ struct sched_param {
9308  #include <linux/fs_struct.h>
9309  #include <linux/compiler.h>
9310  #include <linux/completion.h>
9311 -#include <linux/pid.h>
9312  #include <linux/percpu.h>
9313  #include <linux/topology.h>
9314  #include <linux/proportions.h>
9315 @@ -88,6 +87,7 @@ struct sched_param {
9316  #include <linux/kobject.h>
9317  #include <linux/latencytop.h>
9318  #include <linux/cred.h>
9319 +#include <linux/pid.h>
9320  
9321  #include <asm/processor.h>
9322  
9323 @@ -176,12 +176,13 @@ extern unsigned long long time_sync_thre
9324  #define TASK_UNINTERRUPTIBLE   2
9325  #define __TASK_STOPPED         4
9326  #define __TASK_TRACED          8
9327 +#define TASK_ONHOLD            16
9328  /* in tsk->exit_state */
9329 -#define EXIT_ZOMBIE            16
9330 -#define EXIT_DEAD              32
9331 +#define EXIT_ZOMBIE            32
9332 +#define EXIT_DEAD              64
9333  /* in tsk->state again */
9334 -#define TASK_DEAD              64
9335 -#define TASK_WAKEKILL          128
9336 +#define TASK_DEAD              128
9337 +#define TASK_WAKEKILL          256
9338  
9339  /* Convenience macros for the sake of set_task_state */
9340  #define TASK_KILLABLE          (TASK_WAKEKILL | TASK_UNINTERRUPTIBLE)
9341 @@ -359,25 +360,28 @@ extern void arch_unmap_area_topdown(stru
9342   * The mm counters are not protected by its page_table_lock,
9343   * so must be incremented atomically.
9344   */
9345 -#define set_mm_counter(mm, member, value) atomic_long_set(&(mm)->_##member, value)
9346 -#define get_mm_counter(mm, member) ((unsigned long)atomic_long_read(&(mm)->_##member))
9347 -#define add_mm_counter(mm, member, value) atomic_long_add(value, &(mm)->_##member)
9348 -#define inc_mm_counter(mm, member) atomic_long_inc(&(mm)->_##member)
9349 -#define dec_mm_counter(mm, member) atomic_long_dec(&(mm)->_##member)
9350 +#define __set_mm_counter(mm, member, value) \
9351 +       atomic_long_set(&(mm)->_##member, value)
9352 +#define get_mm_counter(mm, member) \
9353 +       ((unsigned long)atomic_long_read(&(mm)->_##member))
9354  
9355  #else  /* !USE_SPLIT_PTLOCKS */
9356  /*
9357   * The mm counters are protected by its page_table_lock,
9358   * so can be incremented directly.
9359   */
9360 -#define set_mm_counter(mm, member, value) (mm)->_##member = (value)
9361 +#define __set_mm_counter(mm, member, value) (mm)->_##member = (value)
9362  #define get_mm_counter(mm, member) ((mm)->_##member)
9363 -#define add_mm_counter(mm, member, value) (mm)->_##member += (value)
9364 -#define inc_mm_counter(mm, member) (mm)->_##member++
9365 -#define dec_mm_counter(mm, member) (mm)->_##member--
9366  
9367  #endif /* !USE_SPLIT_PTLOCKS */
9368  
9369 +#define set_mm_counter(mm, member, value) \
9370 +       vx_ ## member ## pages_sub((mm), (get_mm_counter(mm, member) - value))
9371 +#define add_mm_counter(mm, member, value) \
9372 +       vx_ ## member ## pages_add((mm), (value))
9373 +#define inc_mm_counter(mm, member) vx_ ## member ## pages_inc((mm))
9374 +#define dec_mm_counter(mm, member) vx_ ## member ## pages_dec((mm))
9375 +
9376  #define get_mm_rss(mm)                                 \
9377         (get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss))
9378  #define update_hiwater_rss(mm) do {                    \
9379 @@ -1132,7 +1136,9 @@ struct task_struct {
9380         const struct sched_class *sched_class;
9381         struct sched_entity se;
9382         struct sched_rt_entity rt;
9383 -
9384 +#ifdef CONFIG_VSERVER_HARDCPU
9385 +       struct list_head hq;
9386 +#endif
9387  #ifdef CONFIG_PREEMPT_NOTIFIERS
9388         /* list of struct preempt_notifier: */
9389         struct hlist_head preempt_notifiers;
9390 @@ -1288,6 +1294,14 @@ struct task_struct {
9391  #endif
9392         seccomp_t seccomp;
9393  
9394 +/* vserver context data */
9395 +       struct vx_info *vx_info;
9396 +       struct nx_info *nx_info;
9397 +
9398 +       xid_t xid;
9399 +       nid_t nid;
9400 +       tag_t tag;
9401 +
9402  /* Thread group tracking */
9403         u32 parent_exec_id;
9404         u32 self_exec_id;
9405 @@ -1500,6 +1514,11 @@ struct pid_namespace;
9406   * see also pid_nr() etc in include/linux/pid.h
9407   */
9408  
9409 +#include <linux/vserver/base.h>
9410 +#include <linux/vserver/context.h>
9411 +#include <linux/vserver/debug.h>
9412 +#include <linux/vserver/pid.h>
9413 +
9414  static inline pid_t task_pid_nr(struct task_struct *tsk)
9415  {
9416         return tsk->pid;
9417 @@ -1509,7 +1528,7 @@ pid_t task_pid_nr_ns(struct task_struct 
9418  
9419  static inline pid_t task_pid_vnr(struct task_struct *tsk)
9420  {
9421 -       return pid_vnr(task_pid(tsk));
9422 +       return vx_map_pid(pid_vnr(task_pid(tsk)));
9423  }
9424  
9425  
9426 @@ -1522,7 +1541,7 @@ pid_t task_tgid_nr_ns(struct task_struct
9427  
9428  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
9429  {
9430 -       return pid_vnr(task_tgid(tsk));
9431 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
9432  }
9433  
9434  
9435 diff -NurpP --minimal linux-2.6.29.4/include/linux/shmem_fs.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/shmem_fs.h
9436 --- linux-2.6.29.4/include/linux/shmem_fs.h     2008-12-25 00:26:37.000000000 +0100
9437 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/shmem_fs.h       2009-02-22 22:54:26.000000000 +0100
9438 @@ -8,6 +8,9 @@
9439  
9440  #define SHMEM_NR_DIRECT 16
9441  
9442 +#define TMPFS_SUPER_MAGIC      0x01021994
9443 +
9444 +
9445  struct shmem_inode_info {
9446         spinlock_t              lock;
9447         unsigned long           flags;
9448 diff -NurpP --minimal linux-2.6.29.4/include/linux/stat.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/stat.h
9449 --- linux-2.6.29.4/include/linux/stat.h 2008-12-25 00:26:37.000000000 +0100
9450 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/stat.h   2009-02-22 22:54:26.000000000 +0100
9451 @@ -66,6 +66,7 @@ struct kstat {
9452         unsigned int    nlink;
9453         uid_t           uid;
9454         gid_t           gid;
9455 +       tag_t           tag;
9456         dev_t           rdev;
9457         loff_t          size;
9458         struct timespec  atime;
9459 diff -NurpP --minimal linux-2.6.29.4/include/linux/sunrpc/auth.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/sunrpc/auth.h
9460 --- linux-2.6.29.4/include/linux/sunrpc/auth.h  2008-12-25 00:26:37.000000000 +0100
9461 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/sunrpc/auth.h    2009-02-22 22:54:26.000000000 +0100
9462 @@ -25,6 +25,7 @@
9463  struct auth_cred {
9464         uid_t   uid;
9465         gid_t   gid;
9466 +       tag_t   tag;
9467         struct group_info *group_info;
9468         unsigned char machine_cred : 1;
9469  };
9470 diff -NurpP --minimal linux-2.6.29.4/include/linux/sunrpc/clnt.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/sunrpc/clnt.h
9471 --- linux-2.6.29.4/include/linux/sunrpc/clnt.h  2009-03-24 14:22:43.000000000 +0100
9472 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/sunrpc/clnt.h    2009-03-24 14:48:36.000000000 +0100
9473 @@ -43,7 +43,8 @@ struct rpc_clnt {
9474         unsigned int            cl_softrtry : 1,/* soft timeouts */
9475                                 cl_discrtry : 1,/* disconnect before retry */
9476                                 cl_autobind : 1,/* use getport() */
9477 -                               cl_chatty   : 1;/* be verbose */
9478 +                               cl_chatty   : 1,/* be verbose */
9479 +                               cl_tag      : 1;/* context tagging */
9480  
9481         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
9482         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
9483 diff -NurpP --minimal linux-2.6.29.4/include/linux/syscalls.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/syscalls.h
9484 --- linux-2.6.29.4/include/linux/syscalls.h     2009-03-24 14:22:43.000000000 +0100
9485 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/syscalls.h       2009-03-24 14:48:36.000000000 +0100
9486 @@ -369,6 +369,8 @@ asmlinkage long sys_symlink(const char _
9487  asmlinkage long sys_unlink(const char __user *pathname);
9488  asmlinkage long sys_rename(const char __user *oldname,
9489                                 const char __user *newname);
9490 +asmlinkage long sys_copyfile(const char __user *from, const char __user *to,
9491 +                               umode_t mode);
9492  asmlinkage long sys_chmod(const char __user *filename, mode_t mode);
9493  asmlinkage long sys_fchmod(unsigned int fd, mode_t mode);
9494  
9495 diff -NurpP --minimal linux-2.6.29.4/include/linux/sysctl.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/sysctl.h
9496 --- linux-2.6.29.4/include/linux/sysctl.h       2008-12-25 00:26:37.000000000 +0100
9497 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/sysctl.h 2009-02-22 22:54:26.000000000 +0100
9498 @@ -70,6 +70,7 @@ enum
9499         CTL_ABI=9,              /* Binary emulation */
9500         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
9501         CTL_ARLAN=254,          /* arlan wireless driver */
9502 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
9503         CTL_S390DBF=5677,       /* s390 debug */
9504         CTL_SUNRPC=7249,        /* sunrpc debug */
9505         CTL_PM=9899,            /* frv power management */
9506 @@ -104,6 +105,7 @@ enum
9507  
9508         KERN_PANIC=15,          /* int: panic timeout */
9509         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
9510 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
9511  
9512         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
9513         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
9514 diff -NurpP --minimal linux-2.6.29.4/include/linux/sysfs.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/sysfs.h
9515 --- linux-2.6.29.4/include/linux/sysfs.h        2008-12-25 00:26:37.000000000 +0100
9516 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/sysfs.h  2009-02-22 22:54:26.000000000 +0100
9517 @@ -17,6 +17,8 @@
9518  #include <linux/list.h>
9519  #include <asm/atomic.h>
9520  
9521 +#define SYSFS_SUPER_MAGIC      0x62656572
9522 +
9523  struct kobject;
9524  struct module;
9525  
9526 diff -NurpP --minimal linux-2.6.29.4/include/linux/time.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/time.h
9527 --- linux-2.6.29.4/include/linux/time.h 2009-03-24 14:22:43.000000000 +0100
9528 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/time.h   2009-02-22 22:54:26.000000000 +0100
9529 @@ -190,6 +190,9 @@ static __always_inline void timespec_add
9530         a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns);
9531         a->tv_nsec = ns;
9532  }
9533 +
9534 +#include <linux/vs_time.h>
9535 +
9536  #endif /* __KERNEL__ */
9537  
9538  #define NFDBITS                        __NFDBITS
9539 diff -NurpP --minimal linux-2.6.29.4/include/linux/types.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/types.h
9540 --- linux-2.6.29.4/include/linux/types.h        2009-03-24 14:22:43.000000000 +0100
9541 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/types.h  2009-03-24 14:48:36.000000000 +0100
9542 @@ -36,6 +36,9 @@ typedef __kernel_uid32_t      uid_t;
9543  typedef __kernel_gid32_t       gid_t;
9544  typedef __kernel_uid16_t        uid16_t;
9545  typedef __kernel_gid16_t        gid16_t;
9546 +typedef unsigned int           xid_t;
9547 +typedef unsigned int           nid_t;
9548 +typedef unsigned int           tag_t;
9549  
9550  typedef unsigned long          uintptr_t;
9551  
9552 diff -NurpP --minimal linux-2.6.29.4/include/linux/vroot.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vroot.h
9553 --- linux-2.6.29.4/include/linux/vroot.h        1970-01-01 01:00:00.000000000 +0100
9554 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vroot.h  2009-02-22 22:54:26.000000000 +0100
9555 @@ -0,0 +1,51 @@
9556 +
9557 +/*
9558 + * include/linux/vroot.h
9559 + *
9560 + * written by Herbert Pötzl, 9/11/2002
9561 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
9562 + *
9563 + * Copyright (C) 2002-2007 by Herbert Pötzl.
9564 + * Redistribution of this file is permitted under the
9565 + * GNU General Public License.
9566 + */
9567 +
9568 +#ifndef _LINUX_VROOT_H
9569 +#define _LINUX_VROOT_H
9570 +
9571 +
9572 +#ifdef __KERNEL__
9573 +
9574 +/* Possible states of device */
9575 +enum {
9576 +       Vr_unbound,
9577 +       Vr_bound,
9578 +};
9579 +
9580 +struct vroot_device {
9581 +       int             vr_number;
9582 +       int             vr_refcnt;
9583 +
9584 +       struct semaphore        vr_ctl_mutex;
9585 +       struct block_device    *vr_device;
9586 +       int                     vr_state;
9587 +};
9588 +
9589 +
9590 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
9591 +
9592 +extern int register_vroot_grb(vroot_grb_func *);
9593 +extern int unregister_vroot_grb(vroot_grb_func *);
9594 +
9595 +#endif /* __KERNEL__ */
9596 +
9597 +#define MAX_VROOT_DEFAULT      8
9598 +
9599 +/*
9600 + * IOCTL commands --- we will commandeer 0x56 ('V')
9601 + */
9602 +
9603 +#define VROOT_SET_DEV          0x5600
9604 +#define VROOT_CLR_DEV          0x5601
9605 +
9606 +#endif /* _LINUX_VROOT_H */
9607 diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_base.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_base.h
9608 --- linux-2.6.29.4/include/linux/vs_base.h      1970-01-01 01:00:00.000000000 +0100
9609 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_base.h        2009-02-22 22:54:26.000000000 +0100
9610 @@ -0,0 +1,10 @@
9611 +#ifndef _VS_BASE_H
9612 +#define _VS_BASE_H
9613 +
9614 +#include "vserver/base.h"
9615 +#include "vserver/check.h"
9616 +#include "vserver/debug.h"
9617 +
9618 +#else
9619 +#warning duplicate inclusion
9620 +#endif
9621 diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_context.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_context.h
9622 --- linux-2.6.29.4/include/linux/vs_context.h   1970-01-01 01:00:00.000000000 +0100
9623 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_context.h     2009-02-22 22:54:26.000000000 +0100
9624 @@ -0,0 +1,227 @@
9625 +#ifndef _VS_CONTEXT_H
9626 +#define _VS_CONTEXT_H
9627 +
9628 +#include "vserver/base.h"
9629 +#include "vserver/check.h"
9630 +#include "vserver/context.h"
9631 +#include "vserver/history.h"
9632 +#include "vserver/debug.h"
9633 +
9634 +#include <linux/sched.h>
9635 +
9636 +
9637 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
9638 +
9639 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
9640 +       const char *_file, int _line, void *_here)
9641 +{
9642 +       if (!vxi)
9643 +               return NULL;
9644 +
9645 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
9646 +               vxi, vxi ? vxi->vx_id : 0,
9647 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9648 +               _file, _line);
9649 +       __vxh_get_vx_info(vxi, _here);
9650 +
9651 +       atomic_inc(&vxi->vx_usecnt);
9652 +       return vxi;
9653 +}
9654 +
9655 +
9656 +extern void free_vx_info(struct vx_info *);
9657 +
9658 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
9659 +
9660 +static inline void __put_vx_info(struct vx_info *vxi,
9661 +       const char *_file, int _line, void *_here)
9662 +{
9663 +       if (!vxi)
9664 +               return;
9665 +
9666 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
9667 +               vxi, vxi ? vxi->vx_id : 0,
9668 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9669 +               _file, _line);
9670 +       __vxh_put_vx_info(vxi, _here);
9671 +
9672 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
9673 +               free_vx_info(vxi);
9674 +}
9675 +
9676 +
9677 +#define init_vx_info(p, i) \
9678 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9679 +
9680 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9681 +       const char *_file, int _line, void *_here)
9682 +{
9683 +       if (vxi) {
9684 +               vxlprintk(VXD_CBIT(xid, 3),
9685 +                       "init_vx_info(%p[#%d.%d])",
9686 +                       vxi, vxi ? vxi->vx_id : 0,
9687 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9688 +                       _file, _line);
9689 +               __vxh_init_vx_info(vxi, vxp, _here);
9690 +
9691 +               atomic_inc(&vxi->vx_usecnt);
9692 +       }
9693 +       *vxp = vxi;
9694 +}
9695 +
9696 +
9697 +#define set_vx_info(p, i) \
9698 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
9699 +
9700 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
9701 +       const char *_file, int _line, void *_here)
9702 +{
9703 +       struct vx_info *vxo;
9704 +
9705 +       if (!vxi)
9706 +               return;
9707 +
9708 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
9709 +               vxi, vxi ? vxi->vx_id : 0,
9710 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9711 +               _file, _line);
9712 +       __vxh_set_vx_info(vxi, vxp, _here);
9713 +
9714 +       atomic_inc(&vxi->vx_usecnt);
9715 +       vxo = xchg(vxp, vxi);
9716 +       BUG_ON(vxo);
9717 +}
9718 +
9719 +
9720 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
9721 +
9722 +static inline void __clr_vx_info(struct vx_info **vxp,
9723 +       const char *_file, int _line, void *_here)
9724 +{
9725 +       struct vx_info *vxo;
9726 +
9727 +       vxo = xchg(vxp, NULL);
9728 +       if (!vxo)
9729 +               return;
9730 +
9731 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
9732 +               vxo, vxo ? vxo->vx_id : 0,
9733 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
9734 +               _file, _line);
9735 +       __vxh_clr_vx_info(vxo, vxp, _here);
9736 +
9737 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
9738 +               free_vx_info(vxo);
9739 +}
9740 +
9741 +
9742 +#define claim_vx_info(v, p) \
9743 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9744 +
9745 +static inline void __claim_vx_info(struct vx_info *vxi,
9746 +       struct task_struct *task,
9747 +       const char *_file, int _line, void *_here)
9748 +{
9749 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
9750 +               vxi, vxi ? vxi->vx_id : 0,
9751 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9752 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9753 +               task, _file, _line);
9754 +       __vxh_claim_vx_info(vxi, task, _here);
9755 +
9756 +       atomic_inc(&vxi->vx_tasks);
9757 +}
9758 +
9759 +
9760 +extern void unhash_vx_info(struct vx_info *);
9761 +
9762 +#define release_vx_info(v, p) \
9763 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
9764 +
9765 +static inline void __release_vx_info(struct vx_info *vxi,
9766 +       struct task_struct *task,
9767 +       const char *_file, int _line, void *_here)
9768 +{
9769 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
9770 +               vxi, vxi ? vxi->vx_id : 0,
9771 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
9772 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
9773 +               task, _file, _line);
9774 +       __vxh_release_vx_info(vxi, task, _here);
9775 +
9776 +       might_sleep();
9777 +
9778 +       if (atomic_dec_and_test(&vxi->vx_tasks))
9779 +               unhash_vx_info(vxi);
9780 +}
9781 +
9782 +
9783 +#define task_get_vx_info(p) \
9784 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
9785 +
9786 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
9787 +       const char *_file, int _line, void *_here)
9788 +{
9789 +       struct vx_info *vxi;
9790 +
9791 +       task_lock(p);
9792 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
9793 +               p, _file, _line);
9794 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
9795 +       task_unlock(p);
9796 +       return vxi;
9797 +}
9798 +
9799 +
9800 +static inline void __wakeup_vx_info(struct vx_info *vxi)
9801 +{
9802 +       if (waitqueue_active(&vxi->vx_wait))
9803 +               wake_up_interruptible(&vxi->vx_wait);
9804 +}
9805 +
9806 +
9807 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
9808 +
9809 +static inline void __enter_vx_info(struct vx_info *vxi,
9810 +       struct vx_info_save *vxis, const char *_file, int _line)
9811 +{
9812 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
9813 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
9814 +               current->xid, current->vx_info, _file, _line);
9815 +       vxis->vxi = xchg(&current->vx_info, vxi);
9816 +       vxis->xid = current->xid;
9817 +       current->xid = vxi ? vxi->vx_id : 0;
9818 +}
9819 +
9820 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
9821 +
9822 +static inline void __leave_vx_info(struct vx_info_save *vxis,
9823 +       const char *_file, int _line)
9824 +{
9825 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
9826 +               vxis, vxis->xid, vxis->vxi, current,
9827 +               current->xid, current->vx_info, _file, _line);
9828 +       (void)xchg(&current->vx_info, vxis->vxi);
9829 +       current->xid = vxis->xid;
9830 +}
9831 +
9832 +
9833 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
9834 +{
9835 +       vxis->vxi = xchg(&current->vx_info, NULL);
9836 +       vxis->xid = xchg(&current->xid, (xid_t)0);
9837 +}
9838 +
9839 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
9840 +{
9841 +       (void)xchg(&current->xid, vxis->xid);
9842 +       (void)xchg(&current->vx_info, vxis->vxi);
9843 +}
9844 +
9845 +extern void exit_vx_info(struct task_struct *, int);
9846 +extern void exit_vx_info_early(struct task_struct *, int);
9847 +
9848 +
9849 +#else
9850 +#warning duplicate inclusion
9851 +#endif
9852 diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_cowbl.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_cowbl.h
9853 --- linux-2.6.29.4/include/linux/vs_cowbl.h     1970-01-01 01:00:00.000000000 +0100
9854 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_cowbl.h       2009-02-22 22:54:26.000000000 +0100
9855 @@ -0,0 +1,47 @@
9856 +#ifndef _VS_COWBL_H
9857 +#define _VS_COWBL_H
9858 +
9859 +#include <linux/fs.h>
9860 +#include <linux/dcache.h>
9861 +#include <linux/namei.h>
9862 +
9863 +extern struct dentry *cow_break_link(const char *pathname);
9864 +
9865 +static inline int cow_check_and_break(struct path *path)
9866 +{
9867 +       struct inode *inode = path->dentry->d_inode;
9868 +       int error = 0;
9869 +
9870 +       /* do we need this check? */
9871 +       if (IS_RDONLY(inode))
9872 +               return -EROFS;
9873 +
9874 +       if (IS_COW(inode)) {
9875 +               if (IS_COW_LINK(inode)) {
9876 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
9877 +                       char *pp, *buf;
9878 +
9879 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
9880 +                       if (!buf) {
9881 +                               return -ENOMEM;
9882 +                       }
9883 +                       pp = d_path(path, buf, PATH_MAX);
9884 +                       new_dentry = cow_break_link(pp);
9885 +                       kfree(buf);
9886 +                       if (!IS_ERR(new_dentry)) {
9887 +                               path->dentry = new_dentry;
9888 +                               dput(old_dentry);
9889 +                       } else
9890 +                               error = PTR_ERR(new_dentry);
9891 +               } else {
9892 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
9893 +                       inode->i_ctime = CURRENT_TIME;
9894 +                       mark_inode_dirty(inode);
9895 +               }
9896 +       }
9897 +       return error;
9898 +}
9899 +
9900 +#else
9901 +#warning duplicate inclusion
9902 +#endif
9903 diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_cvirt.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_cvirt.h
9904 --- linux-2.6.29.4/include/linux/vs_cvirt.h     1970-01-01 01:00:00.000000000 +0100
9905 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_cvirt.h       2009-02-22 22:54:26.000000000 +0100
9906 @@ -0,0 +1,50 @@
9907 +#ifndef _VS_CVIRT_H
9908 +#define _VS_CVIRT_H
9909 +
9910 +#include "vserver/cvirt.h"
9911 +#include "vserver/context.h"
9912 +#include "vserver/base.h"
9913 +#include "vserver/check.h"
9914 +#include "vserver/debug.h"
9915 +
9916 +
9917 +static inline void vx_activate_task(struct task_struct *p)
9918 +{
9919 +       struct vx_info *vxi;
9920 +
9921 +       if ((vxi = p->vx_info)) {
9922 +               vx_update_load(vxi);
9923 +               atomic_inc(&vxi->cvirt.nr_running);
9924 +       }
9925 +}
9926 +
9927 +static inline void vx_deactivate_task(struct task_struct *p)
9928 +{
9929 +       struct vx_info *vxi;
9930 +
9931 +       if ((vxi = p->vx_info)) {
9932 +               vx_update_load(vxi);
9933 +               atomic_dec(&vxi->cvirt.nr_running);
9934 +       }
9935 +}
9936 +
9937 +static inline void vx_uninterruptible_inc(struct task_struct *p)
9938 +{
9939 +       struct vx_info *vxi;
9940 +
9941 +       if ((vxi = p->vx_info))
9942 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
9943 +}
9944 +
9945 +static inline void vx_uninterruptible_dec(struct task_struct *p)
9946 +{
9947 +       struct vx_info *vxi;
9948 +
9949 +       if ((vxi = p->vx_info))
9950 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
9951 +}
9952 +
9953 +
9954 +#else
9955 +#warning duplicate inclusion
9956 +#endif
9957 diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_device.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_device.h
9958 --- linux-2.6.29.4/include/linux/vs_device.h    1970-01-01 01:00:00.000000000 +0100
9959 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_device.h      2009-02-22 22:54:26.000000000 +0100
9960 @@ -0,0 +1,45 @@
9961 +#ifndef _VS_DEVICE_H
9962 +#define _VS_DEVICE_H
9963 +
9964 +#include "vserver/base.h"
9965 +#include "vserver/device.h"
9966 +#include "vserver/debug.h"
9967 +
9968 +
9969 +#ifdef CONFIG_VSERVER_DEVICE
9970 +
9971 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
9972 +
9973 +#define vs_device_perm(v, d, m, p) \
9974 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
9975 +
9976 +#else
9977 +
9978 +static inline
9979 +int vs_map_device(struct vx_info *vxi,
9980 +       dev_t device, dev_t *target, umode_t mode)
9981 +{
9982 +       if (target)
9983 +               *target = device;
9984 +       return ~0;
9985 +}
9986 +
9987 +#define vs_device_perm(v, d, m, p) ((p) == (p))
9988 +
9989 +#endif
9990 +
9991 +
9992 +#define vs_map_chrdev(d, t, p) \
9993 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
9994 +#define vs_map_blkdev(d, t, p) \
9995 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
9996 +
9997 +#define vs_chrdev_perm(d, p) \
9998 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
9999 +#define vs_blkdev_perm(d, p) \
10000 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
10001 +
10002 +
10003 +#else
10004 +#warning duplicate inclusion
10005 +#endif
10006 diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_dlimit.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_dlimit.h
10007 --- linux-2.6.29.4/include/linux/vs_dlimit.h    1970-01-01 01:00:00.000000000 +0100
10008 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_dlimit.h      2009-02-22 22:54:26.000000000 +0100
10009 @@ -0,0 +1,211 @@
10010 +#ifndef _VS_DLIMIT_H
10011 +#define _VS_DLIMIT_H
10012 +
10013 +#include <linux/fs.h>
10014 +
10015 +#include "vserver/dlimit.h"
10016 +#include "vserver/base.h"
10017 +#include "vserver/debug.h"
10018 +
10019 +
10020 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
10021 +
10022 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
10023 +       const char *_file, int _line)
10024 +{
10025 +       if (!dli)
10026 +               return NULL;
10027 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
10028 +               dli, dli ? dli->dl_tag : 0,
10029 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
10030 +               _file, _line);
10031 +       atomic_inc(&dli->dl_usecnt);
10032 +       return dli;
10033 +}
10034 +
10035 +
10036 +#define free_dl_info(i) \
10037 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
10038 +
10039 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
10040 +
10041 +static inline void __put_dl_info(struct dl_info *dli,
10042 +       const char *_file, int _line)
10043 +{
10044 +       if (!dli)
10045 +               return;
10046 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
10047 +               dli, dli ? dli->dl_tag : 0,
10048 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
10049 +               _file, _line);
10050 +       if (atomic_dec_and_test(&dli->dl_usecnt))
10051 +               free_dl_info(dli);
10052 +}
10053 +
10054 +
10055 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
10056 +
10057 +static inline int __dl_alloc_space(struct super_block *sb,
10058 +       tag_t tag, dlsize_t nr, const char *file, int line)
10059 +{
10060 +       struct dl_info *dli = NULL;
10061 +       int ret = 0;
10062 +
10063 +       if (nr == 0)
10064 +               goto out;
10065 +       dli = locate_dl_info(sb, tag);
10066 +       if (!dli)
10067 +               goto out;
10068 +
10069 +       spin_lock(&dli->dl_lock);
10070 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
10071 +       if (!ret)
10072 +               dli->dl_space_used += nr;
10073 +       spin_unlock(&dli->dl_lock);
10074 +       put_dl_info(dli);
10075 +out:
10076 +       vxlprintk(VXD_CBIT(dlim, 1),
10077 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
10078 +               sb, tag, __dlimit_char(dli), (long long)nr,
10079 +               ret, file, line);
10080 +       return ret;
10081 +}
10082 +
10083 +static inline void __dl_free_space(struct super_block *sb,
10084 +       tag_t tag, dlsize_t nr, const char *_file, int _line)
10085 +{
10086 +       struct dl_info *dli = NULL;
10087 +
10088 +       if (nr == 0)
10089 +               goto out;
10090 +       dli = locate_dl_info(sb, tag);
10091 +       if (!dli)
10092 +               goto out;
10093 +
10094 +       spin_lock(&dli->dl_lock);
10095 +       if (dli->dl_space_used > nr)
10096 +               dli->dl_space_used -= nr;
10097 +       else
10098 +               dli->dl_space_used = 0;
10099 +       spin_unlock(&dli->dl_lock);
10100 +       put_dl_info(dli);
10101 +out:
10102 +       vxlprintk(VXD_CBIT(dlim, 1),
10103 +               "FREE  (%p,#%d)%c %lld bytes",
10104 +               sb, tag, __dlimit_char(dli), (long long)nr,
10105 +               _file, _line);
10106 +}
10107 +
10108 +static inline int __dl_alloc_inode(struct super_block *sb,
10109 +       tag_t tag, const char *_file, int _line)
10110 +{
10111 +       struct dl_info *dli;
10112 +       int ret = 0;
10113 +
10114 +       dli = locate_dl_info(sb, tag);
10115 +       if (!dli)
10116 +               goto out;
10117 +
10118 +       spin_lock(&dli->dl_lock);
10119 +       ret = (dli->dl_inodes_used >= dli->dl_inodes_total);
10120 +       if (!ret)
10121 +               dli->dl_inodes_used++;
10122 +       spin_unlock(&dli->dl_lock);
10123 +       put_dl_info(dli);
10124 +out:
10125 +       vxlprintk(VXD_CBIT(dlim, 0),
10126 +               "ALLOC (%p,#%d)%c inode (%d)",
10127 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
10128 +       return ret;
10129 +}
10130 +
10131 +static inline void __dl_free_inode(struct super_block *sb,
10132 +       tag_t tag, const char *_file, int _line)
10133 +{
10134 +       struct dl_info *dli;
10135 +
10136 +       dli = locate_dl_info(sb, tag);
10137 +       if (!dli)
10138 +               goto out;
10139 +
10140 +       spin_lock(&dli->dl_lock);
10141 +       if (dli->dl_inodes_used > 1)
10142 +               dli->dl_inodes_used--;
10143 +       else
10144 +               dli->dl_inodes_used = 0;
10145 +       spin_unlock(&dli->dl_lock);
10146 +       put_dl_info(dli);
10147 +out:
10148 +       vxlprintk(VXD_CBIT(dlim, 0),
10149 +               "FREE  (%p,#%d)%c inode",
10150 +               sb, tag, __dlimit_char(dli), _file, _line);
10151 +}
10152 +
10153 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
10154 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
10155 +       const char *_file, int _line)
10156 +{
10157 +       struct dl_info *dli;
10158 +       uint64_t broot, bfree;
10159 +
10160 +       dli = locate_dl_info(sb, tag);
10161 +       if (!dli)
10162 +               return;
10163 +
10164 +       spin_lock(&dli->dl_lock);
10165 +       broot = (dli->dl_space_total -
10166 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
10167 +               >> sb->s_blocksize_bits;
10168 +       bfree = (dli->dl_space_total - dli->dl_space_used)
10169 +                       >> sb->s_blocksize_bits;
10170 +       spin_unlock(&dli->dl_lock);
10171 +
10172 +       vxlprintk(VXD_CBIT(dlim, 2),
10173 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
10174 +               (long long)bfree, (long long)broot,
10175 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
10176 +               _file, _line);
10177 +       if (free_blocks) {
10178 +               if (*free_blocks > bfree)
10179 +                       *free_blocks = bfree;
10180 +       }
10181 +       if (root_blocks) {
10182 +               if (*root_blocks > broot)
10183 +                       *root_blocks = broot;
10184 +       }
10185 +       put_dl_info(dli);
10186 +}
10187 +
10188 +#define DLIMIT_ALLOC_SPACE(in, bytes) \
10189 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10190 +               __FILE__, __LINE__ )
10191 +
10192 +#define DLIMIT_FREE_SPACE(in, bytes) \
10193 +       __dl_free_space((in)->i_sb, (in)->i_tag, (dlsize_t)(bytes), \
10194 +               __FILE__, __LINE__ )
10195 +
10196 +#define DLIMIT_ALLOC_BLOCK(in, nr) \
10197 +       __dl_alloc_space((in)->i_sb, (in)->i_tag, \
10198 +               ((dlsize_t)(nr)) << (in)->i_sb->s_blocksize_bits, \
10199 +               __FILE__, __LINE__ )
10200 +
10201 +#define DLIMIT_FREE_BLOCK(in, nr) \
10202 +       __dl_free_space((in)->i_sb, (in)->i_tag, \
10203 +               ((dlsize_t)(nr)) << (in)->i_sb->s_blocksize_bits, \
10204 +               __FILE__, __LINE__ )
10205 +
10206 +
10207 +#define DLIMIT_ALLOC_INODE(in) \
10208 +       __dl_alloc_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10209 +
10210 +#define DLIMIT_FREE_INODE(in) \
10211 +       __dl_free_inode((in)->i_sb, (in)->i_tag, __FILE__, __LINE__ )
10212 +
10213 +
10214 +#define DLIMIT_ADJUST_BLOCK(sb, tag, fb, rb) \
10215 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
10216 +
10217 +
10218 +#else
10219 +#warning duplicate inclusion
10220 +#endif
10221 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/base.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/base.h
10222 --- linux-2.6.29.4/include/linux/vserver/base.h 1970-01-01 01:00:00.000000000 +0100
10223 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/base.h   2009-03-25 00:36:15.000000000 +0100
10224 @@ -0,0 +1,157 @@
10225 +#ifndef _VX_BASE_H
10226 +#define _VX_BASE_H
10227 +
10228 +
10229 +/* context state changes */
10230 +
10231 +enum {
10232 +       VSC_STARTUP = 1,
10233 +       VSC_SHUTDOWN,
10234 +
10235 +       VSC_NETUP,
10236 +       VSC_NETDOWN,
10237 +};
10238 +
10239 +
10240 +
10241 +#define vx_task_xid(t) ((t)->xid)
10242 +
10243 +#define vx_current_xid() vx_task_xid(current)
10244 +
10245 +#define current_vx_info() (current->vx_info)
10246 +
10247 +
10248 +#define nx_task_nid(t) ((t)->nid)
10249 +
10250 +#define nx_current_nid() nx_task_nid(current)
10251 +
10252 +#define current_nx_info() (current->nx_info)
10253 +
10254 +
10255 +/* generic flag merging */
10256 +
10257 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10258 +
10259 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10260 +
10261 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10262 +
10263 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10264 +
10265 +
10266 +/* context flags */
10267 +
10268 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10269 +
10270 +#define vx_current_flags()     __vx_flags(current->vx_info)
10271 +
10272 +#define vx_info_flags(v, m, f) \
10273 +       vs_check_flags(__vx_flags(v), m, f)
10274 +
10275 +#define task_vx_flags(t, m, f) \
10276 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10277 +
10278 +#define vx_flags(m, f) vx_info_flags(current->vx_info, m, f)
10279 +
10280 +
10281 +/* context caps */
10282 +
10283 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10284 +
10285 +#define vx_current_ccaps()     __vx_ccaps(current->vx_info)
10286 +
10287 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10288 +
10289 +#define vx_ccaps(c)    vx_info_ccaps(current->vx_info, (c))
10290 +
10291 +
10292 +
10293 +/* network flags */
10294 +
10295 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10296 +
10297 +#define nx_current_flags()     __nx_flags(current->nx_info)
10298 +
10299 +#define nx_info_flags(n, m, f) \
10300 +       vs_check_flags(__nx_flags(n), m, f)
10301 +
10302 +#define task_nx_flags(t, m, f) \
10303 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10304 +
10305 +#define nx_flags(m, f) nx_info_flags(current->nx_info, m, f)
10306 +
10307 +
10308 +/* network caps */
10309 +
10310 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10311 +
10312 +#define nx_current_ncaps()     __nx_ncaps(current->nx_info)
10313 +
10314 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10315 +
10316 +#define nx_ncaps(c)    nx_info_ncaps(current->nx_info, c)
10317 +
10318 +
10319 +/* context mask capabilities */
10320 +
10321 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10322 +
10323 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10324 +
10325 +#define vx_mcaps(c)    vx_info_mcaps(current->vx_info, c)
10326 +
10327 +
10328 +/* context bcap mask */
10329 +
10330 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10331 +
10332 +#define vx_current_bcaps()     __vx_bcaps(current->vx_info)
10333 +
10334 +
10335 +/* mask given bcaps */
10336 +
10337 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10338 +
10339 +#define vx_mbcaps(c)           vx_info_mbcaps(current->vx_info, c)
10340 +
10341 +
10342 +/* masked cap_bset */
10343 +
10344 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10345 +
10346 +#define vx_current_cap_bset()  vx_info_cap_bset(current->vx_info)
10347 +
10348 +#if 0
10349 +#define vx_info_mbcap(v, b) \
10350 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10351 +       vx_info_bcaps(v, b) : (b))
10352 +
10353 +#define task_vx_mbcap(t, b) \
10354 +       vx_info_mbcap((t)->vx_info, (t)->b)
10355 +
10356 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10357 +#endif
10358 +
10359 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10360 +
10361 +#define vx_capable(b, c) (capable(b) || \
10362 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10363 +
10364 +#define nx_capable(b, c) (capable(b) || \
10365 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10366 +
10367 +#define vx_current_initpid(n) \
10368 +       (current->vx_info && \
10369 +       (current->vx_info->vx_initpid == (n)))
10370 +
10371 +
10372 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10373 +
10374 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10375 +
10376 +
10377 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10378 +
10379 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10380 +
10381 +#endif
10382 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/cacct_cmd.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/cacct_cmd.h
10383 --- linux-2.6.29.4/include/linux/vserver/cacct_cmd.h    1970-01-01 01:00:00.000000000 +0100
10384 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/cacct_cmd.h      2009-02-22 22:54:26.000000000 +0100
10385 @@ -0,0 +1,23 @@
10386 +#ifndef _VX_CACCT_CMD_H
10387 +#define _VX_CACCT_CMD_H
10388 +
10389 +
10390 +/* virtual host info name commands */
10391 +
10392 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
10393 +
10394 +struct vcmd_sock_stat_v0 {
10395 +       uint32_t field;
10396 +       uint32_t count[3];
10397 +       uint64_t total[3];
10398 +};
10399 +
10400 +
10401 +#ifdef __KERNEL__
10402 +
10403 +#include <linux/compiler.h>
10404 +
10405 +extern int vc_sock_stat(struct vx_info *, void __user *);
10406 +
10407 +#endif /* __KERNEL__ */
10408 +#endif /* _VX_CACCT_CMD_H */
10409 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/cacct_def.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/cacct_def.h
10410 --- linux-2.6.29.4/include/linux/vserver/cacct_def.h    1970-01-01 01:00:00.000000000 +0100
10411 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/cacct_def.h      2009-02-22 22:54:26.000000000 +0100
10412 @@ -0,0 +1,43 @@
10413 +#ifndef _VX_CACCT_DEF_H
10414 +#define _VX_CACCT_DEF_H
10415 +
10416 +#include <asm/atomic.h>
10417 +#include <linux/vserver/cacct.h>
10418 +
10419 +
10420 +struct _vx_sock_acc {
10421 +       atomic_long_t count;
10422 +       atomic_long_t total;
10423 +};
10424 +
10425 +/* context sub struct */
10426 +
10427 +struct _vx_cacct {
10428 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10429 +       atomic_t slab[8];
10430 +       atomic_t page[6][8];
10431 +};
10432 +
10433 +#ifdef CONFIG_VSERVER_DEBUG
10434 +
10435 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10436 +{
10437 +       int i, j;
10438 +
10439 +       printk("\t_vx_cacct:");
10440 +       for (i = 0; i < 6; i++) {
10441 +               struct _vx_sock_acc *ptr = cacct->sock[i];
10442 +
10443 +               printk("\t [%d] =", i);
10444 +               for (j = 0; j < 3; j++) {
10445 +                       printk(" [%d] = %8lu, %8lu", j,
10446 +                               atomic_long_read(&ptr[j].count),
10447 +                               atomic_long_read(&ptr[j].total));
10448 +               }
10449 +               printk("\n");
10450 +       }
10451 +}
10452 +
10453 +#endif
10454 +
10455 +#endif /* _VX_CACCT_DEF_H */
10456 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/cacct.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/cacct.h
10457 --- linux-2.6.29.4/include/linux/vserver/cacct.h        1970-01-01 01:00:00.000000000 +0100
10458 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/cacct.h  2009-02-22 22:54:26.000000000 +0100
10459 @@ -0,0 +1,15 @@
10460 +#ifndef _VX_CACCT_H
10461 +#define _VX_CACCT_H
10462 +
10463 +
10464 +enum sock_acc_field {
10465 +       VXA_SOCK_UNSPEC = 0,
10466 +       VXA_SOCK_UNIX,
10467 +       VXA_SOCK_INET,
10468 +       VXA_SOCK_INET6,
10469 +       VXA_SOCK_PACKET,
10470 +       VXA_SOCK_OTHER,
10471 +       VXA_SOCK_SIZE   /* array size */
10472 +};
10473 +
10474 +#endif /* _VX_CACCT_H */
10475 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/cacct_int.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/cacct_int.h
10476 --- linux-2.6.29.4/include/linux/vserver/cacct_int.h    1970-01-01 01:00:00.000000000 +0100
10477 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/cacct_int.h      2009-02-22 22:54:26.000000000 +0100
10478 @@ -0,0 +1,21 @@
10479 +#ifndef _VX_CACCT_INT_H
10480 +#define _VX_CACCT_INT_H
10481 +
10482 +
10483 +#ifdef __KERNEL__
10484 +
10485 +static inline
10486 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10487 +{
10488 +       return atomic_long_read(&cacct->sock[type][pos].count);
10489 +}
10490 +
10491 +
10492 +static inline
10493 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10494 +{
10495 +       return atomic_long_read(&cacct->sock[type][pos].total);
10496 +}
10497 +
10498 +#endif /* __KERNEL__ */
10499 +#endif /* _VX_CACCT_INT_H */
10500 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/check.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/check.h
10501 --- linux-2.6.29.4/include/linux/vserver/check.h        1970-01-01 01:00:00.000000000 +0100
10502 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/check.h  2009-02-22 22:54:26.000000000 +0100
10503 @@ -0,0 +1,89 @@
10504 +#ifndef _VS_CHECK_H
10505 +#define _VS_CHECK_H
10506 +
10507 +
10508 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
10509 +
10510 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10511 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
10512 +#else
10513 +#define MIN_D_CONTEXT  65536
10514 +#endif
10515 +
10516 +/* check conditions */
10517 +
10518 +#define VS_ADMIN       0x0001
10519 +#define VS_WATCH       0x0002
10520 +#define VS_HIDE                0x0004
10521 +#define VS_HOSTID      0x0008
10522 +
10523 +#define VS_IDENT       0x0010
10524 +#define VS_EQUIV       0x0020
10525 +#define VS_PARENT      0x0040
10526 +#define VS_CHILD       0x0080
10527 +
10528 +#define VS_ARG_MASK    0x00F0
10529 +
10530 +#define VS_DYNAMIC     0x0100
10531 +#define VS_STATIC      0x0200
10532 +
10533 +#define VS_ATR_MASK    0x0F00
10534 +
10535 +#ifdef CONFIG_VSERVER_PRIVACY
10536 +#define VS_ADMIN_P     (0)
10537 +#define VS_WATCH_P     (0)
10538 +#else
10539 +#define VS_ADMIN_P     VS_ADMIN
10540 +#define VS_WATCH_P     VS_WATCH
10541 +#endif
10542 +
10543 +#define VS_HARDIRQ     0x1000
10544 +#define VS_SOFTIRQ     0x2000
10545 +#define VS_IRQ         0x4000
10546 +
10547 +#define VS_IRQ_MASK    0xF000
10548 +
10549 +#include <linux/hardirq.h>
10550 +
10551 +/*
10552 + * check current context for ADMIN/WATCH and
10553 + * optionally against supplied argument
10554 + */
10555 +static inline int __vs_check(int cid, int id, unsigned int mode)
10556 +{
10557 +       if (mode & VS_ARG_MASK) {
10558 +               if ((mode & VS_IDENT) && (id == cid))
10559 +                       return 1;
10560 +       }
10561 +       if (mode & VS_ATR_MASK) {
10562 +               if ((mode & VS_DYNAMIC) &&
10563 +                       (id >= MIN_D_CONTEXT) &&
10564 +                       (id <= MAX_S_CONTEXT))
10565 +                       return 1;
10566 +               if ((mode & VS_STATIC) &&
10567 +                       (id > 1) && (id < MIN_D_CONTEXT))
10568 +                       return 1;
10569 +       }
10570 +       if (mode & VS_IRQ_MASK) {
10571 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
10572 +                       return 1;
10573 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
10574 +                       return 1;
10575 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
10576 +                       return 1;
10577 +       }
10578 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
10579 +               ((mode & VS_WATCH) && (cid == 1)) ||
10580 +               ((mode & VS_HOSTID) && (id == 0)));
10581 +}
10582 +
10583 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
10584 +
10585 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
10586 +
10587 +
10588 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
10589 +
10590 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
10591 +
10592 +#endif
10593 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/context_cmd.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/context_cmd.h
10594 --- linux-2.6.29.4/include/linux/vserver/context_cmd.h  1970-01-01 01:00:00.000000000 +0100
10595 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/context_cmd.h    2009-02-22 22:54:26.000000000 +0100
10596 @@ -0,0 +1,128 @@
10597 +#ifndef _VX_CONTEXT_CMD_H
10598 +#define _VX_CONTEXT_CMD_H
10599 +
10600 +
10601 +/* vinfo commands */
10602 +
10603 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
10604 +
10605 +#ifdef __KERNEL__
10606 +extern int vc_task_xid(uint32_t);
10607 +
10608 +#endif /* __KERNEL__ */
10609 +
10610 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
10611 +
10612 +struct vcmd_vx_info_v0 {
10613 +       uint32_t xid;
10614 +       uint32_t initpid;
10615 +       /* more to come */
10616 +};
10617 +
10618 +#ifdef __KERNEL__
10619 +extern int vc_vx_info(struct vx_info *, void __user *);
10620 +
10621 +#endif /* __KERNEL__ */
10622 +
10623 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
10624 +
10625 +struct vcmd_ctx_stat_v0 {
10626 +       uint32_t usecnt;
10627 +       uint32_t tasks;
10628 +       /* more to come */
10629 +};
10630 +
10631 +#ifdef __KERNEL__
10632 +extern int vc_ctx_stat(struct vx_info *, void __user *);
10633 +
10634 +#endif /* __KERNEL__ */
10635 +
10636 +/* context commands */
10637 +
10638 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
10639 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
10640 +
10641 +struct vcmd_ctx_create {
10642 +       uint64_t flagword;
10643 +};
10644 +
10645 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
10646 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
10647 +
10648 +struct vcmd_ctx_migrate {
10649 +       uint64_t flagword;
10650 +};
10651 +
10652 +#ifdef __KERNEL__
10653 +extern int vc_ctx_create(uint32_t, void __user *);
10654 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
10655 +
10656 +#endif /* __KERNEL__ */
10657 +
10658 +
10659 +/* flag commands */
10660 +
10661 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
10662 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
10663 +
10664 +struct vcmd_ctx_flags_v0 {
10665 +       uint64_t flagword;
10666 +       uint64_t mask;
10667 +};
10668 +
10669 +#ifdef __KERNEL__
10670 +extern int vc_get_cflags(struct vx_info *, void __user *);
10671 +extern int vc_set_cflags(struct vx_info *, void __user *);
10672 +
10673 +#endif /* __KERNEL__ */
10674 +
10675 +
10676 +/* context caps commands */
10677 +
10678 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
10679 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
10680 +
10681 +struct vcmd_ctx_caps_v1 {
10682 +       uint64_t ccaps;
10683 +       uint64_t cmask;
10684 +};
10685 +
10686 +#ifdef __KERNEL__
10687 +extern int vc_get_ccaps(struct vx_info *, void __user *);
10688 +extern int vc_set_ccaps(struct vx_info *, void __user *);
10689 +
10690 +#endif /* __KERNEL__ */
10691 +
10692 +
10693 +/* bcaps commands */
10694 +
10695 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
10696 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
10697 +
10698 +struct vcmd_bcaps {
10699 +       uint64_t bcaps;
10700 +       uint64_t bmask;
10701 +};
10702 +
10703 +#ifdef __KERNEL__
10704 +extern int vc_get_bcaps(struct vx_info *, void __user *);
10705 +extern int vc_set_bcaps(struct vx_info *, void __user *);
10706 +
10707 +#endif /* __KERNEL__ */
10708 +
10709 +
10710 +/* OOM badness */
10711 +
10712 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
10713 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
10714 +
10715 +struct vcmd_badness_v0 {
10716 +       int64_t bias;
10717 +};
10718 +
10719 +#ifdef __KERNEL__
10720 +extern int vc_get_badness(struct vx_info *, void __user *);
10721 +extern int vc_set_badness(struct vx_info *, void __user *);
10722 +
10723 +#endif /* __KERNEL__ */
10724 +#endif /* _VX_CONTEXT_CMD_H */
10725 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/context.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/context.h
10726 --- linux-2.6.29.4/include/linux/vserver/context.h      1970-01-01 01:00:00.000000000 +0100
10727 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/context.h        2009-02-22 22:54:26.000000000 +0100
10728 @@ -0,0 +1,179 @@
10729 +#ifndef _VX_CONTEXT_H
10730 +#define _VX_CONTEXT_H
10731 +
10732 +#include <linux/types.h>
10733 +#include <linux/capability.h>
10734 +
10735 +
10736 +/* context flags */
10737 +
10738 +#define VXF_INFO_SCHED         0x00000002
10739 +#define VXF_INFO_NPROC         0x00000004
10740 +#define VXF_INFO_PRIVATE       0x00000008
10741 +
10742 +#define VXF_INFO_INIT          0x00000010
10743 +#define VXF_INFO_HIDE          0x00000020
10744 +#define VXF_INFO_ULIMIT                0x00000040
10745 +#define VXF_INFO_NSPACE                0x00000080
10746 +
10747 +#define VXF_SCHED_HARD         0x00000100
10748 +#define VXF_SCHED_PRIO         0x00000200
10749 +#define VXF_SCHED_PAUSE                0x00000400
10750 +
10751 +#define VXF_VIRT_MEM           0x00010000
10752 +#define VXF_VIRT_UPTIME                0x00020000
10753 +#define VXF_VIRT_CPU           0x00040000
10754 +#define VXF_VIRT_LOAD          0x00080000
10755 +#define VXF_VIRT_TIME          0x00100000
10756 +
10757 +#define VXF_HIDE_MOUNT         0x01000000
10758 +/* was VXF_HIDE_NETIF          0x02000000 */
10759 +#define VXF_HIDE_VINFO         0x04000000
10760 +
10761 +#define VXF_STATE_SETUP                (1ULL << 32)
10762 +#define VXF_STATE_INIT         (1ULL << 33)
10763 +#define VXF_STATE_ADMIN                (1ULL << 34)
10764 +
10765 +#define VXF_SC_HELPER          (1ULL << 36)
10766 +#define VXF_REBOOT_KILL                (1ULL << 37)
10767 +#define VXF_PERSISTENT         (1ULL << 38)
10768 +
10769 +#define VXF_FORK_RSS           (1ULL << 48)
10770 +#define VXF_PROLIFIC           (1ULL << 49)
10771 +
10772 +#define VXF_IGNEG_NICE         (1ULL << 52)
10773 +
10774 +#define VXF_ONE_TIME           (0x0007ULL << 32)
10775 +
10776 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
10777 +
10778 +
10779 +/* context migration */
10780 +
10781 +#define VXM_SET_INIT           0x00000001
10782 +#define VXM_SET_REAPER         0x00000002
10783 +
10784 +/* context caps */
10785 +
10786 +#define VXC_CAP_MASK           0x00000000
10787 +
10788 +#define VXC_SET_UTSNAME                0x00000001
10789 +#define VXC_SET_RLIMIT         0x00000002
10790 +#define VXC_FS_SECURITY                0x00000004
10791 +
10792 +/* was VXC_RAW_ICMP            0x00000100 */
10793 +#define VXC_SYSLOG             0x00001000
10794 +
10795 +#define VXC_SECURE_MOUNT       0x00010000
10796 +#define VXC_SECURE_REMOUNT     0x00020000
10797 +#define VXC_BINARY_MOUNT       0x00040000
10798 +
10799 +#define VXC_QUOTA_CTL          0x00100000
10800 +#define VXC_ADMIN_MAPPER       0x00200000
10801 +#define VXC_ADMIN_CLOOP                0x00400000
10802 +
10803 +#define VXC_KTHREAD            0x01000000
10804 +
10805 +
10806 +#ifdef __KERNEL__
10807 +
10808 +#include <linux/list.h>
10809 +#include <linux/spinlock.h>
10810 +#include <linux/rcupdate.h>
10811 +
10812 +#include "limit_def.h"
10813 +#include "sched_def.h"
10814 +#include "cvirt_def.h"
10815 +#include "cacct_def.h"
10816 +#include "device_def.h"
10817 +
10818 +#define VX_SPACES      2
10819 +
10820 +struct _vx_info_pc {
10821 +       struct _vx_sched_pc sched_pc;
10822 +       struct _vx_cvirt_pc cvirt_pc;
10823 +};
10824 +
10825 +struct vx_info {
10826 +       struct hlist_node vx_hlist;             /* linked list of contexts */
10827 +       xid_t vx_id;                            /* context id */
10828 +       atomic_t vx_usecnt;                     /* usage count */
10829 +       atomic_t vx_tasks;                      /* tasks count */
10830 +       struct vx_info *vx_parent;              /* parent context */
10831 +       int vx_state;                           /* context state */
10832 +
10833 +       unsigned long vx_nsmask[VX_SPACES];     /* assignment mask */
10834 +       struct nsproxy *vx_nsproxy[VX_SPACES];  /* private namespaces */
10835 +       struct fs_struct *vx_fs[VX_SPACES];     /* private namespace fs */
10836 +
10837 +       uint64_t vx_flags;                      /* context flags */
10838 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
10839 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
10840 +       // kernel_cap_t vx_cap_bset;            /* the guest's bset */
10841 +
10842 +       struct task_struct *vx_reaper;          /* guest reaper process */
10843 +       pid_t vx_initpid;                       /* PID of guest init */
10844 +       int64_t vx_badness_bias;                /* OOM points bias */
10845 +
10846 +       struct _vx_limit limit;                 /* vserver limits */
10847 +       struct _vx_sched sched;                 /* vserver scheduler */
10848 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
10849 +       struct _vx_cacct cacct;                 /* context accounting */
10850 +
10851 +       struct _vx_device dmap;                 /* default device map targets */
10852 +
10853 +#ifndef CONFIG_SMP
10854 +       struct _vx_info_pc info_pc;             /* per cpu data */
10855 +#else
10856 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
10857 +#endif
10858 +
10859 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
10860 +       int reboot_cmd;                         /* last sys_reboot() cmd */
10861 +       int exit_code;                          /* last process exit code */
10862 +
10863 +       char vx_name[65];                       /* vserver name */
10864 +};
10865 +
10866 +#ifndef CONFIG_SMP
10867 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
10868 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
10869 +#else
10870 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
10871 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
10872 +#endif
10873 +
10874 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
10875 +
10876 +
10877 +struct vx_info_save {
10878 +       struct vx_info *vxi;
10879 +       xid_t xid;
10880 +};
10881 +
10882 +
10883 +/* status flags */
10884 +
10885 +#define VXS_HASHED     0x0001
10886 +#define VXS_PAUSED     0x0010
10887 +#define VXS_SHUTDOWN   0x0100
10888 +#define VXS_HELPER     0x1000
10889 +#define VXS_RELEASED   0x8000
10890 +
10891 +
10892 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
10893 +extern void release_vx_info(struct vx_info *, struct task_struct *);
10894 +
10895 +extern struct vx_info *lookup_vx_info(int);
10896 +extern struct vx_info *lookup_or_create_vx_info(int);
10897 +
10898 +extern int get_xid_list(int, unsigned int *, int);
10899 +extern int xid_is_hashed(xid_t);
10900 +
10901 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
10902 +
10903 +extern long vs_state_change(struct vx_info *, unsigned int);
10904 +
10905 +
10906 +#endif /* __KERNEL__ */
10907 +#endif /* _VX_CONTEXT_H */
10908 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/cvirt_cmd.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/cvirt_cmd.h
10909 --- linux-2.6.29.4/include/linux/vserver/cvirt_cmd.h    1970-01-01 01:00:00.000000000 +0100
10910 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/cvirt_cmd.h      2009-02-22 22:54:26.000000000 +0100
10911 @@ -0,0 +1,53 @@
10912 +#ifndef _VX_CVIRT_CMD_H
10913 +#define _VX_CVIRT_CMD_H
10914 +
10915 +
10916 +/* virtual host info name commands */
10917 +
10918 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
10919 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
10920 +
10921 +struct vcmd_vhi_name_v0 {
10922 +       uint32_t field;
10923 +       char name[65];
10924 +};
10925 +
10926 +
10927 +enum vhi_name_field {
10928 +       VHIN_CONTEXT = 0,
10929 +       VHIN_SYSNAME,
10930 +       VHIN_NODENAME,
10931 +       VHIN_RELEASE,
10932 +       VHIN_VERSION,
10933 +       VHIN_MACHINE,
10934 +       VHIN_DOMAINNAME,
10935 +};
10936 +
10937 +
10938 +#ifdef __KERNEL__
10939 +
10940 +#include <linux/compiler.h>
10941 +
10942 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
10943 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
10944 +
10945 +#endif /* __KERNEL__ */
10946 +
10947 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
10948 +
10949 +struct vcmd_virt_stat_v0 {
10950 +       uint64_t offset;
10951 +       uint64_t uptime;
10952 +       uint32_t nr_threads;
10953 +       uint32_t nr_running;
10954 +       uint32_t nr_uninterruptible;
10955 +       uint32_t nr_onhold;
10956 +       uint32_t nr_forks;
10957 +       uint32_t load[3];
10958 +};
10959 +
10960 +#ifdef __KERNEL__
10961 +extern int vc_virt_stat(struct vx_info *, void __user *);
10962 +
10963 +#endif /* __KERNEL__ */
10964 +#endif /* _VX_CVIRT_CMD_H */
10965 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/cvirt_def.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/cvirt_def.h
10966 --- linux-2.6.29.4/include/linux/vserver/cvirt_def.h    1970-01-01 01:00:00.000000000 +0100
10967 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/cvirt_def.h      2009-02-22 22:54:26.000000000 +0100
10968 @@ -0,0 +1,80 @@
10969 +#ifndef _VX_CVIRT_DEF_H
10970 +#define _VX_CVIRT_DEF_H
10971 +
10972 +#include <linux/jiffies.h>
10973 +#include <linux/spinlock.h>
10974 +#include <linux/wait.h>
10975 +#include <linux/time.h>
10976 +#include <asm/atomic.h>
10977 +
10978 +
10979 +struct _vx_usage_stat {
10980 +       uint64_t user;
10981 +       uint64_t nice;
10982 +       uint64_t system;
10983 +       uint64_t softirq;
10984 +       uint64_t irq;
10985 +       uint64_t idle;
10986 +       uint64_t iowait;
10987 +};
10988 +
10989 +struct _vx_syslog {
10990 +       wait_queue_head_t log_wait;
10991 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
10992 +
10993 +       unsigned long log_start;        /* next char to be read by syslog() */
10994 +       unsigned long con_start;        /* next char to be sent to consoles */
10995 +       unsigned long log_end;  /* most-recently-written-char + 1 */
10996 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
10997 +
10998 +       char log_buf[1024];
10999 +};
11000 +
11001 +
11002 +/* context sub struct */
11003 +
11004 +struct _vx_cvirt {
11005 +       atomic_t nr_threads;            /* number of current threads */
11006 +       atomic_t nr_running;            /* number of running threads */
11007 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
11008 +
11009 +       atomic_t nr_onhold;             /* processes on hold */
11010 +       uint32_t onhold_last;           /* jiffies when put on hold */
11011 +
11012 +       struct timeval bias_tv;         /* time offset to the host */
11013 +       struct timespec bias_idle;
11014 +       struct timespec bias_uptime;    /* context creation point */
11015 +       uint64_t bias_clock;            /* offset in clock_t */
11016 +
11017 +       spinlock_t load_lock;           /* lock for the load averages */
11018 +       atomic_t load_updates;          /* nr of load updates done so far */
11019 +       uint32_t load_last;             /* last time load was calculated */
11020 +       uint32_t load[3];               /* load averages 1,5,15 */
11021 +
11022 +       atomic_t total_forks;           /* number of forks so far */
11023 +
11024 +       struct _vx_syslog syslog;
11025 +};
11026 +
11027 +struct _vx_cvirt_pc {
11028 +       struct _vx_usage_stat cpustat;
11029 +};
11030 +
11031 +
11032 +#ifdef CONFIG_VSERVER_DEBUG
11033 +
11034 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
11035 +{
11036 +       printk("\t_vx_cvirt:\n");
11037 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
11038 +               atomic_read(&cvirt->nr_threads),
11039 +               atomic_read(&cvirt->nr_running),
11040 +               atomic_read(&cvirt->nr_uninterruptible),
11041 +               atomic_read(&cvirt->nr_onhold));
11042 +       /* add rest here */
11043 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
11044 +}
11045 +
11046 +#endif
11047 +
11048 +#endif /* _VX_CVIRT_DEF_H */
11049 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/cvirt.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/cvirt.h
11050 --- linux-2.6.29.4/include/linux/vserver/cvirt.h        1970-01-01 01:00:00.000000000 +0100
11051 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/cvirt.h  2009-02-22 22:54:26.000000000 +0100
11052 @@ -0,0 +1,20 @@
11053 +#ifndef _VX_CVIRT_H
11054 +#define _VX_CVIRT_H
11055 +
11056 +
11057 +#ifdef __KERNEL__
11058 +
11059 +struct timespec;
11060 +
11061 +void vx_vsi_uptime(struct timespec *, struct timespec *);
11062 +
11063 +
11064 +struct vx_info;
11065 +
11066 +void vx_update_load(struct vx_info *);
11067 +
11068 +
11069 +int vx_do_syslog(int, char __user *, int);
11070 +
11071 +#endif /* __KERNEL__ */
11072 +#endif /* _VX_CVIRT_H */
11073 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/debug_cmd.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/debug_cmd.h
11074 --- linux-2.6.29.4/include/linux/vserver/debug_cmd.h    1970-01-01 01:00:00.000000000 +0100
11075 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/debug_cmd.h      2009-02-22 22:54:26.000000000 +0100
11076 @@ -0,0 +1,58 @@
11077 +#ifndef _VX_DEBUG_CMD_H
11078 +#define _VX_DEBUG_CMD_H
11079 +
11080 +
11081 +/* debug commands */
11082 +
11083 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
11084 +
11085 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
11086 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
11087 +
11088 +struct  vcmd_read_history_v0 {
11089 +       uint32_t index;
11090 +       uint32_t count;
11091 +       char __user *data;
11092 +};
11093 +
11094 +struct  vcmd_read_monitor_v0 {
11095 +       uint32_t index;
11096 +       uint32_t count;
11097 +       char __user *data;
11098 +};
11099 +
11100 +
11101 +#ifdef __KERNEL__
11102 +
11103 +#ifdef CONFIG_COMPAT
11104 +
11105 +#include <asm/compat.h>
11106 +
11107 +struct vcmd_read_history_v0_x32 {
11108 +       uint32_t index;
11109 +       uint32_t count;
11110 +       compat_uptr_t data_ptr;
11111 +};
11112 +
11113 +struct vcmd_read_monitor_v0_x32 {
11114 +       uint32_t index;
11115 +       uint32_t count;
11116 +       compat_uptr_t data_ptr;
11117 +};
11118 +
11119 +#endif  /* CONFIG_COMPAT */
11120 +
11121 +extern int vc_dump_history(uint32_t);
11122 +
11123 +extern int vc_read_history(uint32_t, void __user *);
11124 +extern int vc_read_monitor(uint32_t, void __user *);
11125 +
11126 +#ifdef CONFIG_COMPAT
11127 +
11128 +extern int vc_read_history_x32(uint32_t, void __user *);
11129 +extern int vc_read_monitor_x32(uint32_t, void __user *);
11130 +
11131 +#endif  /* CONFIG_COMPAT */
11132 +
11133 +#endif /* __KERNEL__ */
11134 +#endif /* _VX_DEBUG_CMD_H */
11135 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/debug.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/debug.h
11136 --- linux-2.6.29.4/include/linux/vserver/debug.h        1970-01-01 01:00:00.000000000 +0100
11137 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/debug.h  2009-02-22 22:54:26.000000000 +0100
11138 @@ -0,0 +1,127 @@
11139 +#ifndef _VX_DEBUG_H
11140 +#define _VX_DEBUG_H
11141 +
11142 +
11143 +#define VXD_CBIT(n, m) (vx_debug_ ## n & (1 << (m)))
11144 +#define VXD_CMIN(n, m) (vx_debug_ ## n > (m))
11145 +#define VXD_MASK(n, m) (vx_debug_ ## n & (m))
11146 +
11147 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
11148 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
11149 +#define VXF_DEV                "%p[%lu,%d:%d]"
11150 +
11151 +
11152 +#define vxd_path(p)                                            \
11153 +       ({ static char _buffer[PATH_MAX];                       \
11154 +          d_path(p, _buffer, sizeof(_buffer)); })
11155 +
11156 +#define vxd_cond_path(n)                                       \
11157 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
11158 +
11159 +
11160 +#ifdef CONFIG_VSERVER_DEBUG
11161 +
11162 +extern unsigned int vx_debug_switch;
11163 +extern unsigned int vx_debug_xid;
11164 +extern unsigned int vx_debug_nid;
11165 +extern unsigned int vx_debug_tag;
11166 +extern unsigned int vx_debug_net;
11167 +extern unsigned int vx_debug_limit;
11168 +extern unsigned int vx_debug_cres;
11169 +extern unsigned int vx_debug_dlim;
11170 +extern unsigned int vx_debug_quota;
11171 +extern unsigned int vx_debug_cvirt;
11172 +extern unsigned int vx_debug_space;
11173 +extern unsigned int vx_debug_misc;
11174 +
11175 +
11176 +#define VX_LOGLEVEL    "vxD: "
11177 +#define VX_PROC_FMT    "%p: "
11178 +#define VX_PROCESS     current
11179 +
11180 +#define vxdprintk(c, f, x...)                                  \
11181 +       do {                                                    \
11182 +               if (c)                                          \
11183 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
11184 +                               VX_PROCESS , ##x);              \
11185 +       } while (0)
11186 +
11187 +#define vxlprintk(c, f, x...)                                  \
11188 +       do {                                                    \
11189 +               if (c)                                          \
11190 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
11191 +       } while (0)
11192 +
11193 +#define vxfprintk(c, f, x...)                                  \
11194 +       do {                                                    \
11195 +               if (c)                                          \
11196 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
11197 +       } while (0)
11198 +
11199 +
11200 +struct vx_info;
11201 +
11202 +void dump_vx_info(struct vx_info *, int);
11203 +void dump_vx_info_inactive(int);
11204 +
11205 +#else  /* CONFIG_VSERVER_DEBUG */
11206 +
11207 +#define vx_debug_switch 0
11208 +#define vx_debug_xid   0
11209 +#define vx_debug_nid   0
11210 +#define vx_debug_tag   0
11211 +#define vx_debug_net   0
11212 +#define vx_debug_limit 0
11213 +#define vx_debug_cres  0
11214 +#define vx_debug_dlim  0
11215 +#define vx_debug_cvirt 0
11216 +
11217 +#define vxdprintk(x...) do { } while (0)
11218 +#define vxlprintk(x...) do { } while (0)
11219 +#define vxfprintk(x...) do { } while (0)
11220 +
11221 +#endif /* CONFIG_VSERVER_DEBUG */
11222 +
11223 +
11224 +#ifdef CONFIG_VSERVER_WARN
11225 +
11226 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
11227 +#define VX_WARN_TASK   "[»%s«,%u:#%u|%u|%u] "
11228 +#define VX_WARN_XID    "[xid #%u] "
11229 +#define VX_WARN_NID    "[nid #%u] "
11230 +#define VX_WARN_TAG    "[tag #%u] "
11231 +
11232 +#define vxwprintk(c, f, x...)                                  \
11233 +       do {                                                    \
11234 +               if (c)                                          \
11235 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
11236 +       } while (0)
11237 +
11238 +#else  /* CONFIG_VSERVER_WARN */
11239 +
11240 +#define vxwprintk(x...) do { } while (0)
11241 +
11242 +#endif /* CONFIG_VSERVER_WARN */
11243 +
11244 +#define vxwprintk_task(c, f, x...)                             \
11245 +       vxwprintk(c, VX_WARN_TASK f,                            \
11246 +               current->comm, current->pid,                    \
11247 +               current->xid, current->nid, current->tag, ##x)
11248 +#define vxwprintk_xid(c, f, x...)                              \
11249 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
11250 +#define vxwprintk_nid(c, f, x...)                              \
11251 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
11252 +#define vxwprintk_tag(c, f, x...)                              \
11253 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
11254 +
11255 +#ifdef CONFIG_VSERVER_DEBUG
11256 +#define vxd_assert_lock(l)     assert_spin_locked(l)
11257 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
11258 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
11259 +#else
11260 +#define vxd_assert_lock(l)     do { } while (0)
11261 +#define vxd_assert(c, f, x...) do { } while (0)
11262 +#endif
11263 +
11264 +
11265 +#endif /* _VX_DEBUG_H */
11266 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/device_cmd.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/device_cmd.h
11267 --- linux-2.6.29.4/include/linux/vserver/device_cmd.h   1970-01-01 01:00:00.000000000 +0100
11268 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/device_cmd.h     2009-02-22 22:54:26.000000000 +0100
11269 @@ -0,0 +1,44 @@
11270 +#ifndef _VX_DEVICE_CMD_H
11271 +#define _VX_DEVICE_CMD_H
11272 +
11273 +
11274 +/*  device vserver commands */
11275 +
11276 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
11277 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
11278 +
11279 +struct vcmd_set_mapping_v0 {
11280 +       const char __user *device;
11281 +       const char __user *target;
11282 +       uint32_t flags;
11283 +};
11284 +
11285 +
11286 +#ifdef __KERNEL__
11287 +
11288 +#ifdef CONFIG_COMPAT
11289 +
11290 +#include <asm/compat.h>
11291 +
11292 +struct vcmd_set_mapping_v0_x32 {
11293 +       compat_uptr_t device_ptr;
11294 +       compat_uptr_t target_ptr;
11295 +       uint32_t flags;
11296 +};
11297 +
11298 +#endif /* CONFIG_COMPAT */
11299 +
11300 +#include <linux/compiler.h>
11301 +
11302 +extern int vc_set_mapping(struct vx_info *, void __user *);
11303 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11304 +
11305 +#ifdef CONFIG_COMPAT
11306 +
11307 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11308 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11309 +
11310 +#endif /* CONFIG_COMPAT */
11311 +
11312 +#endif /* __KERNEL__ */
11313 +#endif /* _VX_DEVICE_CMD_H */
11314 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/device_def.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/device_def.h
11315 --- linux-2.6.29.4/include/linux/vserver/device_def.h   1970-01-01 01:00:00.000000000 +0100
11316 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/device_def.h     2009-02-22 22:54:26.000000000 +0100
11317 @@ -0,0 +1,17 @@
11318 +#ifndef _VX_DEVICE_DEF_H
11319 +#define _VX_DEVICE_DEF_H
11320 +
11321 +#include <linux/types.h>
11322 +
11323 +struct vx_dmap_target {
11324 +       dev_t target;
11325 +       uint32_t flags;
11326 +};
11327 +
11328 +struct _vx_device {
11329 +#ifdef CONFIG_VSERVER_DEVICE
11330 +       struct vx_dmap_target targets[2];
11331 +#endif
11332 +};
11333 +
11334 +#endif /* _VX_DEVICE_DEF_H */
11335 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/device.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/device.h
11336 --- linux-2.6.29.4/include/linux/vserver/device.h       1970-01-01 01:00:00.000000000 +0100
11337 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/device.h 2009-02-22 22:54:26.000000000 +0100
11338 @@ -0,0 +1,15 @@
11339 +#ifndef _VX_DEVICE_H
11340 +#define _VX_DEVICE_H
11341 +
11342 +
11343 +#define DATTR_CREATE   0x00000001
11344 +#define DATTR_OPEN     0x00000002
11345 +
11346 +#define DATTR_REMAP    0x00000010
11347 +
11348 +#define DATTR_MASK     0x00000013
11349 +
11350 +
11351 +#else  /* _VX_DEVICE_H */
11352 +#warning duplicate inclusion
11353 +#endif /* _VX_DEVICE_H */
11354 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/dlimit_cmd.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/dlimit_cmd.h
11355 --- linux-2.6.29.4/include/linux/vserver/dlimit_cmd.h   1970-01-01 01:00:00.000000000 +0100
11356 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/dlimit_cmd.h     2009-02-22 22:54:26.000000000 +0100
11357 @@ -0,0 +1,74 @@
11358 +#ifndef _VX_DLIMIT_CMD_H
11359 +#define _VX_DLIMIT_CMD_H
11360 +
11361 +
11362 +/*  dlimit vserver commands */
11363 +
11364 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
11365 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
11366 +
11367 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
11368 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
11369 +
11370 +struct vcmd_ctx_dlimit_base_v0 {
11371 +       const char __user *name;
11372 +       uint32_t flags;
11373 +};
11374 +
11375 +struct vcmd_ctx_dlimit_v0 {
11376 +       const char __user *name;
11377 +       uint32_t space_used;                    /* used space in kbytes */
11378 +       uint32_t space_total;                   /* maximum space in kbytes */
11379 +       uint32_t inodes_used;                   /* used inodes */
11380 +       uint32_t inodes_total;                  /* maximum inodes */
11381 +       uint32_t reserved;                      /* reserved for root in % */
11382 +       uint32_t flags;
11383 +};
11384 +
11385 +#define CDLIM_UNSET            ((uint32_t)0UL)
11386 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
11387 +#define CDLIM_KEEP             ((uint32_t)~1UL)
11388 +
11389 +#ifdef __KERNEL__
11390 +
11391 +#ifdef CONFIG_COMPAT
11392 +
11393 +#include <asm/compat.h>
11394 +
11395 +struct vcmd_ctx_dlimit_base_v0_x32 {
11396 +       compat_uptr_t name_ptr;
11397 +       uint32_t flags;
11398 +};
11399 +
11400 +struct vcmd_ctx_dlimit_v0_x32 {
11401 +       compat_uptr_t name_ptr;
11402 +       uint32_t space_used;                    /* used space in kbytes */
11403 +       uint32_t space_total;                   /* maximum space in kbytes */
11404 +       uint32_t inodes_used;                   /* used inodes */
11405 +       uint32_t inodes_total;                  /* maximum inodes */
11406 +       uint32_t reserved;                      /* reserved for root in % */
11407 +       uint32_t flags;
11408 +};
11409 +
11410 +#endif /* CONFIG_COMPAT */
11411 +
11412 +#include <linux/compiler.h>
11413 +
11414 +extern int vc_add_dlimit(uint32_t, void __user *);
11415 +extern int vc_rem_dlimit(uint32_t, void __user *);
11416 +
11417 +extern int vc_set_dlimit(uint32_t, void __user *);
11418 +extern int vc_get_dlimit(uint32_t, void __user *);
11419 +
11420 +#ifdef CONFIG_COMPAT
11421 +
11422 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
11423 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
11424 +
11425 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
11426 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
11427 +
11428 +#endif /* CONFIG_COMPAT */
11429 +
11430 +#endif /* __KERNEL__ */
11431 +#endif /* _VX_DLIMIT_CMD_H */
11432 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/dlimit.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/dlimit.h
11433 --- linux-2.6.29.4/include/linux/vserver/dlimit.h       1970-01-01 01:00:00.000000000 +0100
11434 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/dlimit.h 2009-02-22 22:54:26.000000000 +0100
11435 @@ -0,0 +1,54 @@
11436 +#ifndef _VX_DLIMIT_H
11437 +#define _VX_DLIMIT_H
11438 +
11439 +#include "switch.h"
11440 +
11441 +
11442 +#ifdef __KERNEL__
11443 +
11444 +/*      keep in sync with CDLIM_INFINITY       */
11445 +
11446 +#define DLIM_INFINITY          (~0ULL)
11447 +
11448 +#include <linux/spinlock.h>
11449 +#include <linux/rcupdate.h>
11450 +
11451 +struct super_block;
11452 +
11453 +struct dl_info {
11454 +       struct hlist_node dl_hlist;             /* linked list of contexts */
11455 +       struct rcu_head dl_rcu;                 /* the rcu head */
11456 +       tag_t dl_tag;                           /* context tag */
11457 +       atomic_t dl_usecnt;                     /* usage count */
11458 +       atomic_t dl_refcnt;                     /* reference count */
11459 +
11460 +       struct super_block *dl_sb;              /* associated superblock */
11461 +
11462 +       spinlock_t dl_lock;                     /* protect the values */
11463 +
11464 +       unsigned long long dl_space_used;       /* used space in bytes */
11465 +       unsigned long long dl_space_total;      /* maximum space in bytes */
11466 +       unsigned long dl_inodes_used;           /* used inodes */
11467 +       unsigned long dl_inodes_total;          /* maximum inodes */
11468 +
11469 +       unsigned int dl_nrlmult;                /* non root limit mult */
11470 +};
11471 +
11472 +struct rcu_head;
11473 +
11474 +extern void rcu_free_dl_info(struct rcu_head *);
11475 +extern void unhash_dl_info(struct dl_info *);
11476 +
11477 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
11478 +
11479 +
11480 +struct kstatfs;
11481 +
11482 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11483 +
11484 +typedef uint64_t dlsize_t;
11485 +
11486 +#endif /* __KERNEL__ */
11487 +#else  /* _VX_DLIMIT_H */
11488 +#warning duplicate inclusion
11489 +#endif /* _VX_DLIMIT_H */
11490 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/global.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/global.h
11491 --- linux-2.6.29.4/include/linux/vserver/global.h       1970-01-01 01:00:00.000000000 +0100
11492 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/global.h 2009-02-22 22:54:26.000000000 +0100
11493 @@ -0,0 +1,20 @@
11494 +#ifndef _VX_GLOBAL_H
11495 +#define _VX_GLOBAL_H
11496 +
11497 +
11498 +extern atomic_t vx_global_ctotal;
11499 +extern atomic_t vx_global_cactive;
11500 +
11501 +extern atomic_t nx_global_ctotal;
11502 +extern atomic_t nx_global_cactive;
11503 +
11504 +extern atomic_t vs_global_nsproxy;
11505 +extern atomic_t vs_global_fs;
11506 +extern atomic_t vs_global_mnt_ns;
11507 +extern atomic_t vs_global_uts_ns;
11508 +extern atomic_t vs_global_ipc_ns;
11509 +extern atomic_t vs_global_user_ns;
11510 +extern atomic_t vs_global_pid_ns;
11511 +
11512 +
11513 +#endif /* _VX_GLOBAL_H */
11514 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/history.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/history.h
11515 --- linux-2.6.29.4/include/linux/vserver/history.h      1970-01-01 01:00:00.000000000 +0100
11516 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/history.h        2009-02-22 22:54:26.000000000 +0100
11517 @@ -0,0 +1,197 @@
11518 +#ifndef _VX_HISTORY_H
11519 +#define _VX_HISTORY_H
11520 +
11521 +
11522 +enum {
11523 +       VXH_UNUSED = 0,
11524 +       VXH_THROW_OOPS = 1,
11525 +
11526 +       VXH_GET_VX_INFO,
11527 +       VXH_PUT_VX_INFO,
11528 +       VXH_INIT_VX_INFO,
11529 +       VXH_SET_VX_INFO,
11530 +       VXH_CLR_VX_INFO,
11531 +       VXH_CLAIM_VX_INFO,
11532 +       VXH_RELEASE_VX_INFO,
11533 +       VXH_ALLOC_VX_INFO,
11534 +       VXH_DEALLOC_VX_INFO,
11535 +       VXH_HASH_VX_INFO,
11536 +       VXH_UNHASH_VX_INFO,
11537 +       VXH_LOC_VX_INFO,
11538 +       VXH_LOOKUP_VX_INFO,
11539 +       VXH_CREATE_VX_INFO,
11540 +};
11541 +
11542 +struct _vxhe_vxi {
11543 +       struct vx_info *ptr;
11544 +       unsigned xid;
11545 +       unsigned usecnt;
11546 +       unsigned tasks;
11547 +};
11548 +
11549 +struct _vxhe_set_clr {
11550 +       void *data;
11551 +};
11552 +
11553 +struct _vxhe_loc_lookup {
11554 +       unsigned arg;
11555 +};
11556 +
11557 +struct _vx_hist_entry {
11558 +       void *loc;
11559 +       unsigned short seq;
11560 +       unsigned short type;
11561 +       struct _vxhe_vxi vxi;
11562 +       union {
11563 +               struct _vxhe_set_clr sc;
11564 +               struct _vxhe_loc_lookup ll;
11565 +       };
11566 +};
11567 +
11568 +#ifdef CONFIG_VSERVER_HISTORY
11569 +
11570 +extern unsigned volatile int vxh_active;
11571 +
11572 +struct _vx_hist_entry *vxh_advance(void *loc);
11573 +
11574 +
11575 +static inline
11576 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
11577 +{
11578 +       entry->vxi.ptr = vxi;
11579 +       if (vxi) {
11580 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
11581 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
11582 +               entry->vxi.xid = vxi->vx_id;
11583 +       }
11584 +}
11585 +
11586 +
11587 +#define        __HERE__ current_text_addr()
11588 +
11589 +#define __VXH_BODY(__type, __data, __here)     \
11590 +       struct _vx_hist_entry *entry;           \
11591 +                                               \
11592 +       preempt_disable();                      \
11593 +       entry = vxh_advance(__here);            \
11594 +       __data;                                 \
11595 +       entry->type = __type;                   \
11596 +       preempt_enable();
11597 +
11598 +
11599 +       /* pass vxi only */
11600 +
11601 +#define __VXH_SMPL                             \
11602 +       __vxh_copy_vxi(entry, vxi)
11603 +
11604 +static inline
11605 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
11606 +{
11607 +       __VXH_BODY(__type, __VXH_SMPL, __here)
11608 +}
11609 +
11610 +       /* pass vxi and data (void *) */
11611 +
11612 +#define __VXH_DATA                             \
11613 +       __vxh_copy_vxi(entry, vxi);             \
11614 +       entry->sc.data = data
11615 +
11616 +static inline
11617 +void   __vxh_data(struct vx_info *vxi, void *data,
11618 +                       int __type, void *__here)
11619 +{
11620 +       __VXH_BODY(__type, __VXH_DATA, __here)
11621 +}
11622 +
11623 +       /* pass vxi and arg (long) */
11624 +
11625 +#define __VXH_LONG                             \
11626 +       __vxh_copy_vxi(entry, vxi);             \
11627 +       entry->ll.arg = arg
11628 +
11629 +static inline
11630 +void   __vxh_long(struct vx_info *vxi, long arg,
11631 +                       int __type, void *__here)
11632 +{
11633 +       __VXH_BODY(__type, __VXH_LONG, __here)
11634 +}
11635 +
11636 +
11637 +static inline
11638 +void   __vxh_throw_oops(void *__here)
11639 +{
11640 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
11641 +       /* prevent further acquisition */
11642 +       vxh_active = 0;
11643 +}
11644 +
11645 +
11646 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
11647 +
11648 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
11649 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
11650 +
11651 +#define __vxh_init_vx_info(v, d, h) \
11652 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
11653 +#define __vxh_set_vx_info(v, d, h) \
11654 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
11655 +#define __vxh_clr_vx_info(v, d, h) \
11656 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
11657 +
11658 +#define __vxh_claim_vx_info(v, d, h) \
11659 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
11660 +#define __vxh_release_vx_info(v, d, h) \
11661 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
11662 +
11663 +#define vxh_alloc_vx_info(v) \
11664 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
11665 +#define vxh_dealloc_vx_info(v) \
11666 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
11667 +
11668 +#define vxh_hash_vx_info(v) \
11669 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
11670 +#define vxh_unhash_vx_info(v) \
11671 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
11672 +
11673 +#define vxh_loc_vx_info(v, l) \
11674 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
11675 +#define vxh_lookup_vx_info(v, l) \
11676 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
11677 +#define vxh_create_vx_info(v, l) \
11678 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
11679 +
11680 +extern void vxh_dump_history(void);
11681 +
11682 +
11683 +#else  /* CONFIG_VSERVER_HISTORY */
11684 +
11685 +#define        __HERE__        0
11686 +
11687 +#define vxh_throw_oops()               do { } while (0)
11688 +
11689 +#define __vxh_get_vx_info(v, h)                do { } while (0)
11690 +#define __vxh_put_vx_info(v, h)                do { } while (0)
11691 +
11692 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
11693 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
11694 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
11695 +
11696 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
11697 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
11698 +
11699 +#define vxh_alloc_vx_info(v)           do { } while (0)
11700 +#define vxh_dealloc_vx_info(v)         do { } while (0)
11701 +
11702 +#define vxh_hash_vx_info(v)            do { } while (0)
11703 +#define vxh_unhash_vx_info(v)          do { } while (0)
11704 +
11705 +#define vxh_loc_vx_info(v, l)          do { } while (0)
11706 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
11707 +#define vxh_create_vx_info(v, l)       do { } while (0)
11708 +
11709 +#define vxh_dump_history()             do { } while (0)
11710 +
11711 +
11712 +#endif /* CONFIG_VSERVER_HISTORY */
11713 +
11714 +#endif /* _VX_HISTORY_H */
11715 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/inode_cmd.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/inode_cmd.h
11716 --- linux-2.6.29.4/include/linux/vserver/inode_cmd.h    1970-01-01 01:00:00.000000000 +0100
11717 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/inode_cmd.h      2009-02-22 22:54:26.000000000 +0100
11718 @@ -0,0 +1,59 @@
11719 +#ifndef _VX_INODE_CMD_H
11720 +#define _VX_INODE_CMD_H
11721 +
11722 +
11723 +/*  inode vserver commands */
11724 +
11725 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
11726 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
11727 +
11728 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
11729 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
11730 +
11731 +struct vcmd_ctx_iattr_v1 {
11732 +       const char __user *name;
11733 +       uint32_t tag;
11734 +       uint32_t flags;
11735 +       uint32_t mask;
11736 +};
11737 +
11738 +struct vcmd_ctx_fiattr_v0 {
11739 +       uint32_t tag;
11740 +       uint32_t flags;
11741 +       uint32_t mask;
11742 +};
11743 +
11744 +
11745 +#ifdef __KERNEL__
11746 +
11747 +
11748 +#ifdef CONFIG_COMPAT
11749 +
11750 +#include <asm/compat.h>
11751 +
11752 +struct vcmd_ctx_iattr_v1_x32 {
11753 +       compat_uptr_t name_ptr;
11754 +       uint32_t tag;
11755 +       uint32_t flags;
11756 +       uint32_t mask;
11757 +};
11758 +
11759 +#endif /* CONFIG_COMPAT */
11760 +
11761 +#include <linux/compiler.h>
11762 +
11763 +extern int vc_get_iattr(void __user *);
11764 +extern int vc_set_iattr(void __user *);
11765 +
11766 +extern int vc_fget_iattr(uint32_t, void __user *);
11767 +extern int vc_fset_iattr(uint32_t, void __user *);
11768 +
11769 +#ifdef CONFIG_COMPAT
11770 +
11771 +extern int vc_get_iattr_x32(void __user *);
11772 +extern int vc_set_iattr_x32(void __user *);
11773 +
11774 +#endif /* CONFIG_COMPAT */
11775 +
11776 +#endif /* __KERNEL__ */
11777 +#endif /* _VX_INODE_CMD_H */
11778 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/inode.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/inode.h
11779 --- linux-2.6.29.4/include/linux/vserver/inode.h        1970-01-01 01:00:00.000000000 +0100
11780 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/inode.h  2009-02-22 22:54:26.000000000 +0100
11781 @@ -0,0 +1,38 @@
11782 +#ifndef _VX_INODE_H
11783 +#define _VX_INODE_H
11784 +
11785 +
11786 +#define IATTR_TAG      0x01000000
11787 +
11788 +#define IATTR_ADMIN    0x00000001
11789 +#define IATTR_WATCH    0x00000002
11790 +#define IATTR_HIDE     0x00000004
11791 +#define IATTR_FLAGS    0x00000007
11792 +
11793 +#define IATTR_BARRIER  0x00010000
11794 +#define IATTR_IXUNLINK 0x00020000
11795 +#define IATTR_IMMUTABLE 0x00040000
11796 +
11797 +#ifdef __KERNEL__
11798 +
11799 +
11800 +#ifdef CONFIG_VSERVER_PROC_SECURE
11801 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
11802 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11803 +#else
11804 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
11805 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11806 +#endif
11807 +
11808 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
11809 +
11810 +#endif /* __KERNEL__ */
11811 +
11812 +/* inode ioctls */
11813 +
11814 +#define FIOC_GETXFLG   _IOR('x', 5, long)
11815 +#define FIOC_SETXFLG   _IOW('x', 6, long)
11816 +
11817 +#else  /* _VX_INODE_H */
11818 +#warning duplicate inclusion
11819 +#endif /* _VX_INODE_H */
11820 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/Kbuild linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/Kbuild
11821 --- linux-2.6.29.4/include/linux/vserver/Kbuild 1970-01-01 01:00:00.000000000 +0100
11822 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/Kbuild   2009-02-22 22:54:26.000000000 +0100
11823 @@ -0,0 +1,8 @@
11824 +
11825 +unifdef-y += context_cmd.h network_cmd.h space_cmd.h \
11826 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
11827 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
11828 +       debug_cmd.h device_cmd.h
11829 +
11830 +unifdef-y += switch.h network.h monitor.h inode.h device.h
11831 +
11832 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/limit_cmd.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/limit_cmd.h
11833 --- linux-2.6.29.4/include/linux/vserver/limit_cmd.h    1970-01-01 01:00:00.000000000 +0100
11834 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/limit_cmd.h      2009-02-22 22:54:26.000000000 +0100
11835 @@ -0,0 +1,69 @@
11836 +#ifndef _VX_LIMIT_CMD_H
11837 +#define _VX_LIMIT_CMD_H
11838 +
11839 +
11840 +/*  rlimit vserver commands */
11841 +
11842 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
11843 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
11844 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
11845 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
11846 +
11847 +struct vcmd_ctx_rlimit_v0 {
11848 +       uint32_t id;
11849 +       uint64_t minimum;
11850 +       uint64_t softlimit;
11851 +       uint64_t maximum;
11852 +};
11853 +
11854 +struct vcmd_ctx_rlimit_mask_v0 {
11855 +       uint32_t minimum;
11856 +       uint32_t softlimit;
11857 +       uint32_t maximum;
11858 +};
11859 +
11860 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
11861 +
11862 +struct vcmd_rlimit_stat_v0 {
11863 +       uint32_t id;
11864 +       uint32_t hits;
11865 +       uint64_t value;
11866 +       uint64_t minimum;
11867 +       uint64_t maximum;
11868 +};
11869 +
11870 +#define CRLIM_UNSET            (0ULL)
11871 +#define CRLIM_INFINITY         (~0ULL)
11872 +#define CRLIM_KEEP             (~1ULL)
11873 +
11874 +#ifdef __KERNEL__
11875 +
11876 +#ifdef CONFIG_IA32_EMULATION
11877 +
11878 +struct vcmd_ctx_rlimit_v0_x32 {
11879 +       uint32_t id;
11880 +       uint64_t minimum;
11881 +       uint64_t softlimit;
11882 +       uint64_t maximum;
11883 +} __attribute__ ((packed));
11884 +
11885 +#endif /* CONFIG_IA32_EMULATION */
11886 +
11887 +#include <linux/compiler.h>
11888 +
11889 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
11890 +extern int vc_get_rlimit(struct vx_info *, void __user *);
11891 +extern int vc_set_rlimit(struct vx_info *, void __user *);
11892 +extern int vc_reset_minmax(struct vx_info *, void __user *);
11893 +
11894 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
11895 +
11896 +#ifdef CONFIG_IA32_EMULATION
11897 +
11898 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
11899 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
11900 +
11901 +#endif /* CONFIG_IA32_EMULATION */
11902 +
11903 +#endif /* __KERNEL__ */
11904 +#endif /* _VX_LIMIT_CMD_H */
11905 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/limit_def.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/limit_def.h
11906 --- linux-2.6.29.4/include/linux/vserver/limit_def.h    1970-01-01 01:00:00.000000000 +0100
11907 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/limit_def.h      2009-02-22 22:54:26.000000000 +0100
11908 @@ -0,0 +1,47 @@
11909 +#ifndef _VX_LIMIT_DEF_H
11910 +#define _VX_LIMIT_DEF_H
11911 +
11912 +#include <asm/atomic.h>
11913 +#include <asm/resource.h>
11914 +
11915 +#include "limit.h"
11916 +
11917 +
11918 +struct _vx_res_limit {
11919 +       rlim_t soft;            /* Context soft limit */
11920 +       rlim_t hard;            /* Context hard limit */
11921 +
11922 +       rlim_atomic_t rcur;     /* Current value */
11923 +       rlim_t rmin;            /* Context minimum */
11924 +       rlim_t rmax;            /* Context maximum */
11925 +
11926 +       atomic_t lhit;          /* Limit hits */
11927 +};
11928 +
11929 +/* context sub struct */
11930 +
11931 +struct _vx_limit {
11932 +       struct _vx_res_limit res[NUM_LIMITS];
11933 +};
11934 +
11935 +#ifdef CONFIG_VSERVER_DEBUG
11936 +
11937 +static inline void __dump_vx_limit(struct _vx_limit *limit)
11938 +{
11939 +       int i;
11940 +
11941 +       printk("\t_vx_limit:");
11942 +       for (i = 0; i < NUM_LIMITS; i++) {
11943 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
11944 +                       i, (unsigned long)__rlim_get(limit, i),
11945 +                       (unsigned long)__rlim_rmin(limit, i),
11946 +                       (unsigned long)__rlim_rmax(limit, i),
11947 +                       (long)__rlim_soft(limit, i),
11948 +                       (long)__rlim_hard(limit, i),
11949 +                       atomic_read(&__rlim_lhit(limit, i)));
11950 +       }
11951 +}
11952 +
11953 +#endif
11954 +
11955 +#endif /* _VX_LIMIT_DEF_H */
11956 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/limit.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/limit.h
11957 --- linux-2.6.29.4/include/linux/vserver/limit.h        1970-01-01 01:00:00.000000000 +0100
11958 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/limit.h  2009-02-22 22:54:26.000000000 +0100
11959 @@ -0,0 +1,70 @@
11960 +#ifndef _VX_LIMIT_H
11961 +#define _VX_LIMIT_H
11962 +
11963 +#define VLIMIT_NSOCK   16
11964 +#define VLIMIT_OPENFD  17
11965 +#define VLIMIT_ANON    18
11966 +#define VLIMIT_SHMEM   19
11967 +#define VLIMIT_SEMARY  20
11968 +#define VLIMIT_NSEMS   21
11969 +#define VLIMIT_DENTRY  22
11970 +#define VLIMIT_MAPPED  23
11971 +
11972 +
11973 +#ifdef __KERNEL__
11974 +
11975 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
11976 +
11977 +/*     keep in sync with CRLIM_INFINITY */
11978 +
11979 +#define        VLIM_INFINITY   (~0ULL)
11980 +
11981 +#include <asm/atomic.h>
11982 +#include <asm/resource.h>
11983 +
11984 +#ifndef RLIM_INFINITY
11985 +#warning RLIM_INFINITY is undefined
11986 +#endif
11987 +
11988 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
11989 +
11990 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
11991 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
11992 +
11993 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
11994 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
11995 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
11996 +
11997 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
11998 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
11999 +
12000 +typedef atomic_long_t rlim_atomic_t;
12001 +typedef unsigned long rlim_t;
12002 +
12003 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
12004 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
12005 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
12006 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
12007 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
12008 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
12009 +
12010 +
12011 +#if    (RLIM_INFINITY == VLIM_INFINITY)
12012 +#define        VX_VLIM(r) ((long long)(long)(r))
12013 +#define        VX_RLIM(v) ((rlim_t)(v))
12014 +#else
12015 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
12016 +               ? VLIM_INFINITY : (long long)(r))
12017 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
12018 +               ? RLIM_INFINITY : (rlim_t)(v))
12019 +#endif
12020 +
12021 +struct sysinfo;
12022 +
12023 +void vx_vsi_meminfo(struct sysinfo *);
12024 +void vx_vsi_swapinfo(struct sysinfo *);
12025 +
12026 +#define NUM_LIMITS     24
12027 +
12028 +#endif /* __KERNEL__ */
12029 +#endif /* _VX_LIMIT_H */
12030 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/limit_int.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/limit_int.h
12031 --- linux-2.6.29.4/include/linux/vserver/limit_int.h    1970-01-01 01:00:00.000000000 +0100
12032 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/limit_int.h      2009-02-22 22:54:26.000000000 +0100
12033 @@ -0,0 +1,198 @@
12034 +#ifndef _VX_LIMIT_INT_H
12035 +#define _VX_LIMIT_INT_H
12036 +
12037 +#include "context.h"
12038 +
12039 +#ifdef __KERNEL__
12040 +
12041 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
12042 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
12043 +
12044 +extern const char *vlimit_name[NUM_LIMITS];
12045 +
12046 +static inline void __vx_acc_cres(struct vx_info *vxi,
12047 +       int res, int dir, void *_data, char *_file, int _line)
12048 +{
12049 +       if (VXD_RCRES_COND(res))
12050 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
12051 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12052 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12053 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
12054 +       if (!vxi)
12055 +               return;
12056 +
12057 +       if (dir > 0)
12058 +               __rlim_inc(&vxi->limit, res);
12059 +       else
12060 +               __rlim_dec(&vxi->limit, res);
12061 +}
12062 +
12063 +static inline void __vx_add_cres(struct vx_info *vxi,
12064 +       int res, int amount, void *_data, char *_file, int _line)
12065 +{
12066 +       if (VXD_RCRES_COND(res))
12067 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
12068 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12069 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12070 +                       amount, _data, _file, _line);
12071 +       if (amount == 0)
12072 +               return;
12073 +       if (!vxi)
12074 +               return;
12075 +       __rlim_add(&vxi->limit, res, amount);
12076 +}
12077 +
12078 +static inline
12079 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
12080 +{
12081 +       int cond = (value > __rlim_rmax(limit, res));
12082 +
12083 +       if (cond)
12084 +               __rlim_rmax(limit, res) = value;
12085 +       return cond;
12086 +}
12087 +
12088 +static inline
12089 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
12090 +{
12091 +       int cond = (value < __rlim_rmin(limit, res));
12092 +
12093 +       if (cond)
12094 +               __rlim_rmin(limit, res) = value;
12095 +       return cond;
12096 +}
12097 +
12098 +static inline
12099 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
12100 +{
12101 +       if (!__vx_cres_adjust_max(limit, res, value))
12102 +               __vx_cres_adjust_min(limit, res, value);
12103 +}
12104 +
12105 +
12106 +/*     return values:
12107 +        +1 ... no limit hit
12108 +        -1 ... over soft limit
12109 +         0 ... over hard limit         */
12110 +
12111 +static inline int __vx_cres_avail(struct vx_info *vxi,
12112 +       int res, int num, char *_file, int _line)
12113 +{
12114 +       struct _vx_limit *limit;
12115 +       rlim_t value;
12116 +
12117 +       if (VXD_RLIMIT_COND(res))
12118 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
12119 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
12120 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
12121 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
12122 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
12123 +                       num, _file, _line);
12124 +       if (!vxi)
12125 +               return 1;
12126 +
12127 +       limit = &vxi->limit;
12128 +       value = __rlim_get(limit, res);
12129 +
12130 +       if (!__vx_cres_adjust_max(limit, res, value))
12131 +               __vx_cres_adjust_min(limit, res, value);
12132 +
12133 +       if (num == 0)
12134 +               return 1;
12135 +
12136 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
12137 +               return -1;
12138 +       if (value + num <= __rlim_soft(limit, res))
12139 +               return -1;
12140 +
12141 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
12142 +               return 1;
12143 +       if (value + num <= __rlim_hard(limit, res))
12144 +               return 1;
12145 +
12146 +       __rlim_hit(limit, res);
12147 +       return 0;
12148 +}
12149 +
12150 +
12151 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
12152 +
12153 +static inline
12154 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
12155 +{
12156 +       rlim_t value, sum = 0;
12157 +       int res;
12158 +
12159 +       while ((res = *array++)) {
12160 +               value = __rlim_get(limit, res);
12161 +               __vx_cres_fixup(limit, res, value);
12162 +               sum += value;
12163 +       }
12164 +       return sum;
12165 +}
12166 +
12167 +static inline
12168 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
12169 +{
12170 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
12171 +       int res = *array;
12172 +
12173 +       if (value == __rlim_get(limit, res))
12174 +               return value;
12175 +
12176 +       __rlim_set(limit, res, value);
12177 +       /* now adjust min/max */
12178 +       if (!__vx_cres_adjust_max(limit, res, value))
12179 +               __vx_cres_adjust_min(limit, res, value);
12180 +
12181 +       return value;
12182 +}
12183 +
12184 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
12185 +       const int *array, int num, char *_file, int _line)
12186 +{
12187 +       struct _vx_limit *limit;
12188 +       rlim_t value = 0;
12189 +       int res;
12190 +
12191 +       if (num == 0)
12192 +               return 1;
12193 +       if (!vxi)
12194 +               return 1;
12195 +
12196 +       limit = &vxi->limit;
12197 +       res = *array;
12198 +       value = __vx_cres_array_sum(limit, array + 1);
12199 +
12200 +       __rlim_set(limit, res, value);
12201 +       __vx_cres_fixup(limit, res, value);
12202 +
12203 +       return __vx_cres_avail(vxi, res, num, _file, _line);
12204 +}
12205 +
12206 +
12207 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
12208 +{
12209 +       rlim_t value;
12210 +       int res;
12211 +
12212 +       /* complex resources first */
12213 +       if ((id < 0) || (id == RLIMIT_RSS))
12214 +               __vx_cres_array_fixup(limit, VLA_RSS);
12215 +
12216 +       for (res = 0; res < NUM_LIMITS; res++) {
12217 +               if ((id > 0) && (res != id))
12218 +                       continue;
12219 +
12220 +               value = __rlim_get(limit, res);
12221 +               __vx_cres_fixup(limit, res, value);
12222 +
12223 +               /* not supposed to happen, maybe warn? */
12224 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
12225 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
12226 +       }
12227 +}
12228 +
12229 +
12230 +#endif /* __KERNEL__ */
12231 +#endif /* _VX_LIMIT_INT_H */
12232 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/monitor.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/monitor.h
12233 --- linux-2.6.29.4/include/linux/vserver/monitor.h      1970-01-01 01:00:00.000000000 +0100
12234 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/monitor.h        2009-02-22 22:54:26.000000000 +0100
12235 @@ -0,0 +1,96 @@
12236 +#ifndef _VX_MONITOR_H
12237 +#define _VX_MONITOR_H
12238 +
12239 +#include <linux/types.h>
12240 +
12241 +enum {
12242 +       VXM_UNUSED = 0,
12243 +
12244 +       VXM_SYNC = 0x10,
12245 +
12246 +       VXM_UPDATE = 0x20,
12247 +       VXM_UPDATE_1,
12248 +       VXM_UPDATE_2,
12249 +
12250 +       VXM_RQINFO_1 = 0x24,
12251 +       VXM_RQINFO_2,
12252 +
12253 +       VXM_ACTIVATE = 0x40,
12254 +       VXM_DEACTIVATE,
12255 +       VXM_IDLE,
12256 +
12257 +       VXM_HOLD = 0x44,
12258 +       VXM_UNHOLD,
12259 +
12260 +       VXM_MIGRATE = 0x48,
12261 +       VXM_RESCHED,
12262 +
12263 +       /* all other bits are flags */
12264 +       VXM_SCHED = 0x80,
12265 +};
12266 +
12267 +struct _vxm_update_1 {
12268 +       uint32_t tokens_max;
12269 +       uint32_t fill_rate;
12270 +       uint32_t interval;
12271 +};
12272 +
12273 +struct _vxm_update_2 {
12274 +       uint32_t tokens_min;
12275 +       uint32_t fill_rate;
12276 +       uint32_t interval;
12277 +};
12278 +
12279 +struct _vxm_rqinfo_1 {
12280 +       uint16_t running;
12281 +       uint16_t onhold;
12282 +       uint16_t iowait;
12283 +       uint16_t uintr;
12284 +       uint32_t idle_tokens;
12285 +};
12286 +
12287 +struct _vxm_rqinfo_2 {
12288 +       uint32_t norm_time;
12289 +       uint32_t idle_time;
12290 +       uint32_t idle_skip;
12291 +};
12292 +
12293 +struct _vxm_sched {
12294 +       uint32_t tokens;
12295 +       uint32_t norm_time;
12296 +       uint32_t idle_time;
12297 +};
12298 +
12299 +struct _vxm_task {
12300 +       uint16_t pid;
12301 +       uint16_t state;
12302 +};
12303 +
12304 +struct _vxm_event {
12305 +       uint32_t jif;
12306 +       union {
12307 +               uint32_t seq;
12308 +               uint32_t sec;
12309 +       };
12310 +       union {
12311 +               uint32_t tokens;
12312 +               uint32_t nsec;
12313 +               struct _vxm_task tsk;
12314 +       };
12315 +};
12316 +
12317 +struct _vx_mon_entry {
12318 +       uint16_t type;
12319 +       uint16_t xid;
12320 +       union {
12321 +               struct _vxm_event ev;
12322 +               struct _vxm_sched sd;
12323 +               struct _vxm_update_1 u1;
12324 +               struct _vxm_update_2 u2;
12325 +               struct _vxm_rqinfo_1 q1;
12326 +               struct _vxm_rqinfo_2 q2;
12327 +       };
12328 +};
12329 +
12330 +
12331 +#endif /* _VX_MONITOR_H */
12332 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/network_cmd.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/network_cmd.h
12333 --- linux-2.6.29.4/include/linux/vserver/network_cmd.h  1970-01-01 01:00:00.000000000 +0100
12334 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/network_cmd.h    2009-02-22 22:54:26.000000000 +0100
12335 @@ -0,0 +1,150 @@
12336 +#ifndef _VX_NETWORK_CMD_H
12337 +#define _VX_NETWORK_CMD_H
12338 +
12339 +
12340 +/* vinfo commands */
12341 +
12342 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
12343 +
12344 +#ifdef __KERNEL__
12345 +extern int vc_task_nid(uint32_t);
12346 +
12347 +#endif /* __KERNEL__ */
12348 +
12349 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
12350 +
12351 +struct vcmd_nx_info_v0 {
12352 +       uint32_t nid;
12353 +       /* more to come */
12354 +};
12355 +
12356 +#ifdef __KERNEL__
12357 +extern int vc_nx_info(struct nx_info *, void __user *);
12358 +
12359 +#endif /* __KERNEL__ */
12360 +
12361 +#include <linux/in.h>
12362 +#include <linux/in6.h>
12363 +
12364 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
12365 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
12366 +
12367 +struct  vcmd_net_create {
12368 +       uint64_t flagword;
12369 +};
12370 +
12371 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
12372 +
12373 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
12374 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
12375 +
12376 +struct vcmd_net_addr_v0 {
12377 +       uint16_t type;
12378 +       uint16_t count;
12379 +       struct in_addr ip[4];
12380 +       struct in_addr mask[4];
12381 +};
12382 +
12383 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 1)
12384 +#define VCMD_net_remove_ipv4   VC_CMD(NETALT, 2, 1)
12385 +
12386 +struct vcmd_net_addr_ipv4_v1 {
12387 +       uint16_t type;
12388 +       uint16_t flags;
12389 +       struct in_addr ip;
12390 +       struct in_addr mask;
12391 +};
12392 +
12393 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
12394 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
12395 +
12396 +struct vcmd_net_addr_ipv6_v1 {
12397 +       uint16_t type;
12398 +       uint16_t flags;
12399 +       uint32_t prefix;
12400 +       struct in6_addr ip;
12401 +       struct in6_addr mask;
12402 +};
12403 +
12404 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
12405 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
12406 +
12407 +struct vcmd_match_ipv4_v0 {
12408 +       uint16_t type;
12409 +       uint16_t flags;
12410 +       uint16_t parent;
12411 +       uint16_t prefix;
12412 +       struct in_addr ip;
12413 +       struct in_addr ip2;
12414 +       struct in_addr mask;
12415 +};
12416 +
12417 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
12418 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
12419 +
12420 +struct vcmd_match_ipv6_v0 {
12421 +       uint16_t type;
12422 +       uint16_t flags;
12423 +       uint16_t parent;
12424 +       uint16_t prefix;
12425 +       struct in6_addr ip;
12426 +       struct in6_addr ip2;
12427 +       struct in6_addr mask;
12428 +};
12429 +
12430 +
12431 +#ifdef __KERNEL__
12432 +extern int vc_net_create(uint32_t, void __user *);
12433 +extern int vc_net_migrate(struct nx_info *, void __user *);
12434 +
12435 +extern int vc_net_add(struct nx_info *, void __user *);
12436 +extern int vc_net_remove(struct nx_info *, void __user *);
12437 +
12438 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
12439 +extern int vc_net_remove_ipv4(struct nx_info *, void __user *);
12440 +
12441 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
12442 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
12443 +
12444 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
12445 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
12446 +
12447 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
12448 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
12449 +
12450 +#endif /* __KERNEL__ */
12451 +
12452 +
12453 +/* flag commands */
12454 +
12455 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
12456 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
12457 +
12458 +struct vcmd_net_flags_v0 {
12459 +       uint64_t flagword;
12460 +       uint64_t mask;
12461 +};
12462 +
12463 +#ifdef __KERNEL__
12464 +extern int vc_get_nflags(struct nx_info *, void __user *);
12465 +extern int vc_set_nflags(struct nx_info *, void __user *);
12466 +
12467 +#endif /* __KERNEL__ */
12468 +
12469 +
12470 +/* network caps commands */
12471 +
12472 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
12473 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
12474 +
12475 +struct vcmd_net_caps_v0 {
12476 +       uint64_t ncaps;
12477 +       uint64_t cmask;
12478 +};
12479 +
12480 +#ifdef __KERNEL__
12481 +extern int vc_get_ncaps(struct nx_info *, void __user *);
12482 +extern int vc_set_ncaps(struct nx_info *, void __user *);
12483 +
12484 +#endif /* __KERNEL__ */
12485 +#endif /* _VX_CONTEXT_CMD_H */
12486 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/network.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/network.h
12487 --- linux-2.6.29.4/include/linux/vserver/network.h      1970-01-01 01:00:00.000000000 +0100
12488 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/network.h        2009-02-22 22:54:26.000000000 +0100
12489 @@ -0,0 +1,146 @@
12490 +#ifndef _VX_NETWORK_H
12491 +#define _VX_NETWORK_H
12492 +
12493 +#include <linux/types.h>
12494 +
12495 +
12496 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
12497 +
12498 +
12499 +/* network flags */
12500 +
12501 +#define NXF_INFO_PRIVATE       0x00000008
12502 +
12503 +#define NXF_SINGLE_IP          0x00000100
12504 +#define NXF_LBACK_REMAP                0x00000200
12505 +#define NXF_LBACK_ALLOW                0x00000400
12506 +
12507 +#define NXF_HIDE_NETIF         0x02000000
12508 +#define NXF_HIDE_LBACK         0x04000000
12509 +
12510 +#define NXF_STATE_SETUP                (1ULL << 32)
12511 +#define NXF_STATE_ADMIN                (1ULL << 34)
12512 +
12513 +#define NXF_SC_HELPER          (1ULL << 36)
12514 +#define NXF_PERSISTENT         (1ULL << 38)
12515 +
12516 +#define NXF_ONE_TIME           (0x0005ULL << 32)
12517 +
12518 +
12519 +#define        NXF_INIT_SET            (__nxf_init_set())
12520 +
12521 +static inline uint64_t __nxf_init_set(void) {
12522 +       return    NXF_STATE_ADMIN
12523 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12524 +               | NXF_LBACK_REMAP
12525 +               | NXF_HIDE_LBACK
12526 +#endif
12527 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12528 +               | NXF_SINGLE_IP
12529 +#endif
12530 +               | NXF_HIDE_NETIF;
12531 +}
12532 +
12533 +
12534 +/* network caps */
12535 +
12536 +#define NXC_TUN_CREATE         0x00000001
12537 +
12538 +#define NXC_RAW_ICMP           0x00000100
12539 +
12540 +
12541 +/* address types */
12542 +
12543 +#define NXA_TYPE_IPV4          0x0001
12544 +#define NXA_TYPE_IPV6          0x0002
12545 +
12546 +#define NXA_TYPE_NONE          0x0000
12547 +#define NXA_TYPE_ANY           0x00FF
12548 +
12549 +#define NXA_TYPE_ADDR          0x0010
12550 +#define NXA_TYPE_MASK          0x0020
12551 +#define NXA_TYPE_RANGE         0x0040
12552 +
12553 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12554 +
12555 +#define NXA_MOD_BCAST          0x0100
12556 +#define NXA_MOD_LBACK          0x0200
12557 +
12558 +#define NXA_LOOPBACK           0x1000
12559 +
12560 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12561 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
12562 +
12563 +#ifdef __KERNEL__
12564 +
12565 +#include <linux/list.h>
12566 +#include <linux/spinlock.h>
12567 +#include <linux/rcupdate.h>
12568 +#include <linux/in.h>
12569 +#include <linux/in6.h>
12570 +#include <asm/atomic.h>
12571 +
12572 +struct nx_addr_v4 {
12573 +       struct nx_addr_v4 *next;
12574 +       struct in_addr ip[2];
12575 +       struct in_addr mask;
12576 +       uint16_t type;
12577 +       uint16_t flags;
12578 +};
12579 +
12580 +struct nx_addr_v6 {
12581 +       struct nx_addr_v6 *next;
12582 +       struct in6_addr ip;
12583 +       struct in6_addr mask;
12584 +       uint32_t prefix;
12585 +       uint16_t type;
12586 +       uint16_t flags;
12587 +};
12588 +
12589 +struct nx_info {
12590 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
12591 +       nid_t nx_id;                    /* vnet id */
12592 +       atomic_t nx_usecnt;             /* usage count */
12593 +       atomic_t nx_tasks;              /* tasks count */
12594 +       int nx_state;                   /* context state */
12595 +
12596 +       uint64_t nx_flags;              /* network flag word */
12597 +       uint64_t nx_ncaps;              /* network capabilities */
12598 +
12599 +       struct in_addr v4_lback;        /* Loopback address */
12600 +       struct in_addr v4_bcast;        /* Broadcast address */
12601 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
12602 +#ifdef CONFIG_IPV6
12603 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
12604 +#endif
12605 +       char nx_name[65];               /* network context name */
12606 +};
12607 +
12608 +
12609 +/* status flags */
12610 +
12611 +#define NXS_HASHED      0x0001
12612 +#define NXS_SHUTDOWN    0x0100
12613 +#define NXS_RELEASED    0x8000
12614 +
12615 +extern struct nx_info *lookup_nx_info(int);
12616 +
12617 +extern int get_nid_list(int, unsigned int *, int);
12618 +extern int nid_is_hashed(nid_t);
12619 +
12620 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
12621 +
12622 +extern long vs_net_change(struct nx_info *, unsigned int);
12623 +
12624 +struct sock;
12625 +
12626 +
12627 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
12628 +#ifdef  CONFIG_IPV6
12629 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
12630 +#else
12631 +#define NX_IPV6(n)     (0)
12632 +#endif
12633 +
12634 +#endif /* __KERNEL__ */
12635 +#endif /* _VX_NETWORK_H */
12636 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/percpu.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/percpu.h
12637 --- linux-2.6.29.4/include/linux/vserver/percpu.h       1970-01-01 01:00:00.000000000 +0100
12638 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/percpu.h 2009-02-22 22:54:26.000000000 +0100
12639 @@ -0,0 +1,14 @@
12640 +#ifndef _VX_PERCPU_H
12641 +#define _VX_PERCPU_H
12642 +
12643 +#include "cvirt_def.h"
12644 +#include "sched_def.h"
12645 +
12646 +struct _vx_percpu {
12647 +       struct _vx_cvirt_pc cvirt;
12648 +       struct _vx_sched_pc sched;
12649 +};
12650 +
12651 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
12652 +
12653 +#endif /* _VX_PERCPU_H */
12654 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/pid.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/pid.h
12655 --- linux-2.6.29.4/include/linux/vserver/pid.h  1970-01-01 01:00:00.000000000 +0100
12656 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/pid.h    2009-02-22 22:54:26.000000000 +0100
12657 @@ -0,0 +1,51 @@
12658 +#ifndef _VSERVER_PID_H
12659 +#define _VSERVER_PID_H
12660 +
12661 +/* pid faking stuff */
12662 +
12663 +#define vx_info_map_pid(v, p) \
12664 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
12665 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
12666 +#define vx_map_pid(p) vx_info_map_pid(current->vx_info, p)
12667 +#define vx_map_tgid(p) vx_map_pid(p)
12668 +
12669 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
12670 +       const char *func, const char *file, int line)
12671 +{
12672 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12673 +               vxfprintk(VXD_CBIT(cvirt, 2),
12674 +                       "vx_map_tgid: %p/%llx: %d -> %d",
12675 +                       vxi, (long long)vxi->vx_flags, pid,
12676 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
12677 +                       func, file, line);
12678 +               if (pid == 0)
12679 +                       return 0;
12680 +               if (pid == vxi->vx_initpid)
12681 +                       return 1;
12682 +       }
12683 +       return pid;
12684 +}
12685 +
12686 +#define vx_info_rmap_pid(v, p) \
12687 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
12688 +#define vx_rmap_pid(p) vx_info_rmap_pid(current->vx_info, p)
12689 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
12690 +
12691 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
12692 +       const char *func, const char *file, int line)
12693 +{
12694 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12695 +               vxfprintk(VXD_CBIT(cvirt, 2),
12696 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
12697 +                       vxi, (long long)vxi->vx_flags, pid,
12698 +                       (pid == 1) ? vxi->vx_initpid : pid,
12699 +                       func, file, line);
12700 +               if ((pid == 1) && vxi->vx_initpid)
12701 +                       return vxi->vx_initpid;
12702 +               if (pid == vxi->vx_initpid)
12703 +                       return ~0U;
12704 +       }
12705 +       return pid;
12706 +}
12707 +
12708 +#endif
12709 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/sched_cmd.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/sched_cmd.h
12710 --- linux-2.6.29.4/include/linux/vserver/sched_cmd.h    1970-01-01 01:00:00.000000000 +0100
12711 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/sched_cmd.h      2009-02-22 22:54:26.000000000 +0100
12712 @@ -0,0 +1,108 @@
12713 +#ifndef _VX_SCHED_CMD_H
12714 +#define _VX_SCHED_CMD_H
12715 +
12716 +
12717 +/*  sched vserver commands */
12718 +
12719 +#define VCMD_set_sched_v2      VC_CMD(SCHED, 1, 2)
12720 +#define VCMD_set_sched_v3      VC_CMD(SCHED, 1, 3)
12721 +#define VCMD_set_sched_v4      VC_CMD(SCHED, 1, 4)
12722 +
12723 +struct vcmd_set_sched_v2 {
12724 +       int32_t fill_rate;
12725 +       int32_t interval;
12726 +       int32_t tokens;
12727 +       int32_t tokens_min;
12728 +       int32_t tokens_max;
12729 +       uint64_t cpu_mask;
12730 +};
12731 +
12732 +struct vcmd_set_sched_v3 {
12733 +       uint32_t set_mask;
12734 +       int32_t fill_rate;
12735 +       int32_t interval;
12736 +       int32_t tokens;
12737 +       int32_t tokens_min;
12738 +       int32_t tokens_max;
12739 +       int32_t priority_bias;
12740 +};
12741 +
12742 +struct vcmd_set_sched_v4 {
12743 +       uint32_t set_mask;
12744 +       int32_t fill_rate;
12745 +       int32_t interval;
12746 +       int32_t tokens;
12747 +       int32_t tokens_min;
12748 +       int32_t tokens_max;
12749 +       int32_t prio_bias;
12750 +       int32_t cpu_id;
12751 +       int32_t bucket_id;
12752 +};
12753 +
12754 +#define VCMD_set_sched         VC_CMD(SCHED, 1, 5)
12755 +#define VCMD_get_sched         VC_CMD(SCHED, 2, 5)
12756 +
12757 +struct vcmd_sched_v5 {
12758 +       uint32_t mask;
12759 +       int32_t cpu_id;
12760 +       int32_t bucket_id;
12761 +       int32_t fill_rate[2];
12762 +       int32_t interval[2];
12763 +       int32_t tokens;
12764 +       int32_t tokens_min;
12765 +       int32_t tokens_max;
12766 +       int32_t prio_bias;
12767 +};
12768 +
12769 +#define VXSM_FILL_RATE         0x0001
12770 +#define VXSM_INTERVAL          0x0002
12771 +#define VXSM_FILL_RATE2                0x0004
12772 +#define VXSM_INTERVAL2         0x0008
12773 +#define VXSM_TOKENS            0x0010
12774 +#define VXSM_TOKENS_MIN                0x0020
12775 +#define VXSM_TOKENS_MAX                0x0040
12776 +#define VXSM_PRIO_BIAS         0x0100
12777 +
12778 +#define VXSM_IDLE_TIME         0x0200
12779 +#define VXSM_FORCE             0x0400
12780 +
12781 +#define        VXSM_V3_MASK            0x0173
12782 +#define        VXSM_SET_MASK           0x01FF
12783 +
12784 +#define VXSM_CPU_ID            0x1000
12785 +#define VXSM_BUCKET_ID         0x2000
12786 +
12787 +#define VXSM_MSEC              0x4000
12788 +
12789 +#define SCHED_KEEP             (-2)    /* only for v2 */
12790 +
12791 +#ifdef __KERNEL__
12792 +
12793 +#include <linux/compiler.h>
12794 +
12795 +extern int vc_set_sched_v2(struct vx_info *, void __user *);
12796 +extern int vc_set_sched_v3(struct vx_info *, void __user *);
12797 +extern int vc_set_sched_v4(struct vx_info *, void __user *);
12798 +extern int vc_set_sched(struct vx_info *, void __user *);
12799 +extern int vc_get_sched(struct vx_info *, void __user *);
12800 +
12801 +#endif /* __KERNEL__ */
12802 +
12803 +#define VCMD_sched_info                VC_CMD(SCHED, 3, 0)
12804 +
12805 +struct vcmd_sched_info {
12806 +       int32_t cpu_id;
12807 +       int32_t bucket_id;
12808 +       uint64_t user_msec;
12809 +       uint64_t sys_msec;
12810 +       uint64_t hold_msec;
12811 +       uint32_t token_usec;
12812 +       int32_t vavavoom;
12813 +};
12814 +
12815 +#ifdef __KERNEL__
12816 +
12817 +extern int vc_sched_info(struct vx_info *, void __user *);
12818 +
12819 +#endif /* __KERNEL__ */
12820 +#endif /* _VX_SCHED_CMD_H */
12821 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/sched_def.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/sched_def.h
12822 --- linux-2.6.29.4/include/linux/vserver/sched_def.h    1970-01-01 01:00:00.000000000 +0100
12823 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/sched_def.h      2009-02-22 22:54:26.000000000 +0100
12824 @@ -0,0 +1,68 @@
12825 +#ifndef _VX_SCHED_DEF_H
12826 +#define _VX_SCHED_DEF_H
12827 +
12828 +#include <linux/spinlock.h>
12829 +#include <linux/jiffies.h>
12830 +#include <linux/cpumask.h>
12831 +#include <asm/atomic.h>
12832 +#include <asm/param.h>
12833 +
12834 +
12835 +/* context sub struct */
12836 +
12837 +struct _vx_sched {
12838 +       spinlock_t tokens_lock;         /* lock for token bucket */
12839 +
12840 +       int tokens;                     /* number of CPU tokens */
12841 +       int fill_rate[2];               /* Fill rate: add X tokens... */
12842 +       int interval[2];                /* Divisor:   per Y jiffies   */
12843 +       int tokens_min;                 /* Limit:     minimum for unhold */
12844 +       int tokens_max;                 /* Limit:     no more than N tokens */
12845 +
12846 +       int prio_bias;                  /* bias offset for priority */
12847 +
12848 +       unsigned update_mask;           /* which features should be updated */
12849 +       cpumask_t update;               /* CPUs which should update */
12850 +};
12851 +
12852 +struct _vx_sched_pc {
12853 +       int tokens;                     /* number of CPU tokens */
12854 +       int flags;                      /* bucket flags */
12855 +
12856 +       int fill_rate[2];               /* Fill rate: add X tokens... */
12857 +       int interval[2];                /* Divisor:   per Y jiffies   */
12858 +       int tokens_min;                 /* Limit:     minimum for unhold */
12859 +       int tokens_max;                 /* Limit:     no more than N tokens */
12860 +
12861 +       int prio_bias;                  /* bias offset for priority */
12862 +       int vavavoom;                   /* last calculated vavavoom */
12863 +
12864 +       unsigned long norm_time;        /* last time accounted */
12865 +       unsigned long idle_time;        /* non linear time for fair sched */
12866 +       unsigned long token_time;       /* token time for accounting */
12867 +       unsigned long onhold;           /* jiffies when put on hold */
12868 +
12869 +       uint64_t user_ticks;            /* token tick events */
12870 +       uint64_t sys_ticks;             /* token tick events */
12871 +       uint64_t hold_ticks;            /* token ticks paused */
12872 +};
12873 +
12874 +
12875 +#define VXSF_ONHOLD    0x0001
12876 +#define VXSF_IDLE_TIME 0x0100
12877 +
12878 +#ifdef CONFIG_VSERVER_DEBUG
12879 +
12880 +static inline void __dump_vx_sched(struct _vx_sched *sched)
12881 +{
12882 +       printk("\t_vx_sched:\n");
12883 +       printk("\t tokens: %4d/%4d, %4d/%4d, %4d, %4d\n",
12884 +               sched->fill_rate[0], sched->interval[0],
12885 +               sched->fill_rate[1], sched->interval[1],
12886 +               sched->tokens_min, sched->tokens_max);
12887 +       printk("\t priority = %4d\n", sched->prio_bias);
12888 +}
12889 +
12890 +#endif
12891 +
12892 +#endif /* _VX_SCHED_DEF_H */
12893 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/sched.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/sched.h
12894 --- linux-2.6.29.4/include/linux/vserver/sched.h        1970-01-01 01:00:00.000000000 +0100
12895 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/sched.h  2009-02-22 22:54:26.000000000 +0100
12896 @@ -0,0 +1,26 @@
12897 +#ifndef _VX_SCHED_H
12898 +#define _VX_SCHED_H
12899 +
12900 +
12901 +#ifdef __KERNEL__
12902 +
12903 +struct timespec;
12904 +
12905 +void vx_vsi_uptime(struct timespec *, struct timespec *);
12906 +
12907 +
12908 +struct vx_info;
12909 +
12910 +void vx_update_load(struct vx_info *);
12911 +
12912 +
12913 +int vx_tokens_recalc(struct _vx_sched_pc *,
12914 +       unsigned long *, unsigned long *, int [2]);
12915 +
12916 +void vx_update_sched_param(struct _vx_sched *sched,
12917 +       struct _vx_sched_pc *sched_pc);
12918 +
12919 +#endif /* __KERNEL__ */
12920 +#else  /* _VX_SCHED_H */
12921 +#warning duplicate inclusion
12922 +#endif /* _VX_SCHED_H */
12923 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/signal_cmd.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/signal_cmd.h
12924 --- linux-2.6.29.4/include/linux/vserver/signal_cmd.h   1970-01-01 01:00:00.000000000 +0100
12925 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/signal_cmd.h     2009-02-22 22:54:26.000000000 +0100
12926 @@ -0,0 +1,43 @@
12927 +#ifndef _VX_SIGNAL_CMD_H
12928 +#define _VX_SIGNAL_CMD_H
12929 +
12930 +
12931 +/*  signalling vserver commands */
12932 +
12933 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
12934 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
12935 +
12936 +struct vcmd_ctx_kill_v0 {
12937 +       int32_t pid;
12938 +       int32_t sig;
12939 +};
12940 +
12941 +struct vcmd_wait_exit_v0 {
12942 +       int32_t reboot_cmd;
12943 +       int32_t exit_code;
12944 +};
12945 +
12946 +#ifdef __KERNEL__
12947 +
12948 +extern int vc_ctx_kill(struct vx_info *, void __user *);
12949 +extern int vc_wait_exit(struct vx_info *, void __user *);
12950 +
12951 +#endif /* __KERNEL__ */
12952 +
12953 +/*  process alteration commands */
12954 +
12955 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
12956 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
12957 +
12958 +struct vcmd_pflags_v0 {
12959 +       uint32_t flagword;
12960 +       uint32_t mask;
12961 +};
12962 +
12963 +#ifdef __KERNEL__
12964 +
12965 +extern int vc_get_pflags(uint32_t pid, void __user *);
12966 +extern int vc_set_pflags(uint32_t pid, void __user *);
12967 +
12968 +#endif /* __KERNEL__ */
12969 +#endif /* _VX_SIGNAL_CMD_H */
12970 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/signal.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/signal.h
12971 --- linux-2.6.29.4/include/linux/vserver/signal.h       1970-01-01 01:00:00.000000000 +0100
12972 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/signal.h 2009-02-22 22:54:26.000000000 +0100
12973 @@ -0,0 +1,14 @@
12974 +#ifndef _VX_SIGNAL_H
12975 +#define _VX_SIGNAL_H
12976 +
12977 +
12978 +#ifdef __KERNEL__
12979 +
12980 +struct vx_info;
12981 +
12982 +int vx_info_kill(struct vx_info *, int, int);
12983 +
12984 +#endif /* __KERNEL__ */
12985 +#else  /* _VX_SIGNAL_H */
12986 +#warning duplicate inclusion
12987 +#endif /* _VX_SIGNAL_H */
12988 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/space_cmd.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/space_cmd.h
12989 --- linux-2.6.29.4/include/linux/vserver/space_cmd.h    1970-01-01 01:00:00.000000000 +0100
12990 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/space_cmd.h      2009-02-22 22:54:26.000000000 +0100
12991 @@ -0,0 +1,38 @@
12992 +#ifndef _VX_SPACE_CMD_H
12993 +#define _VX_SPACE_CMD_H
12994 +
12995 +
12996 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
12997 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
12998 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
12999 +
13000 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
13001 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
13002 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
13003 +
13004 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
13005 +
13006 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
13007 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
13008 +
13009 +
13010 +struct vcmd_space_mask_v1 {
13011 +       uint64_t mask;
13012 +};
13013 +
13014 +struct vcmd_space_mask_v2 {
13015 +       uint64_t mask;
13016 +       uint32_t index;
13017 +};
13018 +
13019 +
13020 +#ifdef __KERNEL__
13021 +
13022 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
13023 +extern int vc_set_space_v1(struct vx_info *, void __user *);
13024 +extern int vc_enter_space(struct vx_info *, void __user *);
13025 +extern int vc_set_space(struct vx_info *, void __user *);
13026 +extern int vc_get_space_mask(void __user *, int);
13027 +
13028 +#endif /* __KERNEL__ */
13029 +#endif /* _VX_SPACE_CMD_H */
13030 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/space.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/space.h
13031 --- linux-2.6.29.4/include/linux/vserver/space.h        1970-01-01 01:00:00.000000000 +0100
13032 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/space.h  2009-02-22 22:54:26.000000000 +0100
13033 @@ -0,0 +1,12 @@
13034 +#ifndef _VX_SPACE_H
13035 +#define _VX_SPACE_H
13036 +
13037 +#include <linux/types.h>
13038 +
13039 +struct vx_info;
13040 +
13041 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
13042 +
13043 +#else  /* _VX_SPACE_H */
13044 +#warning duplicate inclusion
13045 +#endif /* _VX_SPACE_H */
13046 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/switch.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/switch.h
13047 --- linux-2.6.29.4/include/linux/vserver/switch.h       1970-01-01 01:00:00.000000000 +0100
13048 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/switch.h 2009-02-22 22:54:26.000000000 +0100
13049 @@ -0,0 +1,98 @@
13050 +#ifndef _VX_SWITCH_H
13051 +#define _VX_SWITCH_H
13052 +
13053 +#include <linux/types.h>
13054 +
13055 +
13056 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
13057 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
13058 +#define VC_VERSION(c)          ((c) & 0xFFF)
13059 +
13060 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
13061 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13062 +
13063 +/*
13064 +
13065 +  Syscall Matrix V2.8
13066 +
13067 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13068 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
13069 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
13070 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13071 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13072 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13073 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13074 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13075 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13076 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13077 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13078 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13079 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13080 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13081 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13082 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13083 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13084 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13085 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13086 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13087 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13088 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13089 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13090 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13091 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13092 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13093 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13094 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13095 +
13096 +*/
13097 +
13098 +#define VC_CAT_VERSION         0
13099 +
13100 +#define VC_CAT_VSETUP          1
13101 +#define VC_CAT_VHOST           2
13102 +
13103 +#define VC_CAT_DEVICE          6
13104 +
13105 +#define VC_CAT_VPROC           9
13106 +#define VC_CAT_PROCALT         10
13107 +#define VC_CAT_PROCMIG         11
13108 +#define VC_CAT_PROCTRL         12
13109 +
13110 +#define VC_CAT_SCHED           14
13111 +#define VC_CAT_MEMCTRL         20
13112 +
13113 +#define VC_CAT_VNET            25
13114 +#define VC_CAT_NETALT          26
13115 +#define VC_CAT_NETMIG          27
13116 +#define VC_CAT_NETCTRL         28
13117 +
13118 +#define VC_CAT_TAGMIG          35
13119 +#define VC_CAT_DLIMIT          36
13120 +#define VC_CAT_INODE           38
13121 +
13122 +#define VC_CAT_VSTAT           40
13123 +#define VC_CAT_VINFO           46
13124 +#define VC_CAT_EVENT           48
13125 +
13126 +#define VC_CAT_FLAGS           52
13127 +#define VC_CAT_VSPACE          54
13128 +#define VC_CAT_DEBUG           56
13129 +#define VC_CAT_RLIMIT          60
13130 +
13131 +#define VC_CAT_SYSTEST         61
13132 +#define VC_CAT_COMPAT          63
13133 +
13134 +/*  query version */
13135 +
13136 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13137 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13138 +
13139 +
13140 +#ifdef __KERNEL__
13141 +
13142 +#include <linux/errno.h>
13143 +
13144 +#endif /* __KERNEL__ */
13145 +
13146 +#endif /* _VX_SWITCH_H */
13147 +
13148 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/tag_cmd.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/tag_cmd.h
13149 --- linux-2.6.29.4/include/linux/vserver/tag_cmd.h      1970-01-01 01:00:00.000000000 +0100
13150 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/tag_cmd.h        2009-02-22 22:54:26.000000000 +0100
13151 @@ -0,0 +1,22 @@
13152 +#ifndef _VX_TAG_CMD_H
13153 +#define _VX_TAG_CMD_H
13154 +
13155 +
13156 +/* vinfo commands */
13157 +
13158 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13159 +
13160 +#ifdef __KERNEL__
13161 +extern int vc_task_tag(uint32_t);
13162 +
13163 +#endif /* __KERNEL__ */
13164 +
13165 +/* context commands */
13166 +
13167 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13168 +
13169 +#ifdef __KERNEL__
13170 +extern int vc_tag_migrate(uint32_t);
13171 +
13172 +#endif /* __KERNEL__ */
13173 +#endif /* _VX_TAG_CMD_H */
13174 diff -NurpP --minimal linux-2.6.29.4/include/linux/vserver/tag.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/tag.h
13175 --- linux-2.6.29.4/include/linux/vserver/tag.h  1970-01-01 01:00:00.000000000 +0100
13176 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vserver/tag.h    2009-02-22 22:54:26.000000000 +0100
13177 @@ -0,0 +1,143 @@
13178 +#ifndef _DX_TAG_H
13179 +#define _DX_TAG_H
13180 +
13181 +#include <linux/types.h>
13182 +
13183 +
13184 +#define DX_TAG(in)     (IS_TAGGED(in))
13185 +
13186 +
13187 +#ifdef CONFIG_TAG_NFSD
13188 +#define DX_TAG_NFSD    1
13189 +#else
13190 +#define DX_TAG_NFSD    0
13191 +#endif
13192 +
13193 +
13194 +#ifdef CONFIG_TAGGING_NONE
13195 +
13196 +#define MAX_UID                0xFFFFFFFF
13197 +#define MAX_GID                0xFFFFFFFF
13198 +
13199 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
13200 +
13201 +#define TAGINO_UID(cond, uid, tag)     (uid)
13202 +#define TAGINO_GID(cond, gid, tag)     (gid)
13203 +
13204 +#endif
13205 +
13206 +
13207 +#ifdef CONFIG_TAGGING_GID16
13208 +
13209 +#define MAX_UID                0xFFFFFFFF
13210 +#define MAX_GID                0x0000FFFF
13211 +
13212 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13213 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
13214 +
13215 +#define TAGINO_UID(cond, uid, tag)     (uid)
13216 +#define TAGINO_GID(cond, gid, tag)     \
13217 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
13218 +
13219 +#endif
13220 +
13221 +
13222 +#ifdef CONFIG_TAGGING_ID24
13223 +
13224 +#define MAX_UID                0x00FFFFFF
13225 +#define MAX_GID                0x00FFFFFF
13226 +
13227 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13228 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
13229 +
13230 +#define TAGINO_UID(cond, uid, tag)     \
13231 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
13232 +#define TAGINO_GID(cond, gid, tag)     \
13233 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
13234 +
13235 +#endif
13236 +
13237 +
13238 +#ifdef CONFIG_TAGGING_UID16
13239 +
13240 +#define MAX_UID                0x0000FFFF
13241 +#define MAX_GID                0xFFFFFFFF
13242 +
13243 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13244 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
13245 +
13246 +#define TAGINO_UID(cond, uid, tag)     \
13247 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
13248 +#define TAGINO_GID(cond, gid, tag)     (gid)
13249 +
13250 +#endif
13251 +
13252 +
13253 +#ifdef CONFIG_TAGGING_INTERN
13254 +
13255 +#define MAX_UID                0xFFFFFFFF
13256 +#define MAX_GID                0xFFFFFFFF
13257 +
13258 +#define INOTAG_TAG(cond, uid, gid, tag)        \
13259 +       ((cond) ? (tag) : 0)
13260 +
13261 +#define TAGINO_UID(cond, uid, tag)     (uid)
13262 +#define TAGINO_GID(cond, gid, tag)     (gid)
13263 +
13264 +#endif
13265 +
13266 +
13267 +#ifndef CONFIG_TAGGING_NONE
13268 +#define dx_current_fstag(sb)   \
13269 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
13270 +#else
13271 +#define dx_current_fstag(sb)   (0)
13272 +#endif
13273 +
13274 +#ifndef CONFIG_TAGGING_INTERN
13275 +#define TAGINO_TAG(cond, tag)  (0)
13276 +#else
13277 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
13278 +#endif
13279 +
13280 +#define INOTAG_UID(cond, uid, gid)     \
13281 +       ((cond) ? ((uid) & MAX_UID) : (uid))
13282 +#define INOTAG_GID(cond, uid, gid)     \
13283 +       ((cond) ? ((gid) & MAX_GID) : (gid))
13284 +
13285 +
13286 +static inline uid_t dx_map_uid(uid_t uid)
13287 +{
13288 +       if ((uid > MAX_UID) && (uid != -1))
13289 +               uid = -2;
13290 +       return (uid & MAX_UID);
13291 +}
13292 +
13293 +static inline gid_t dx_map_gid(gid_t gid)
13294 +{
13295 +       if ((gid > MAX_GID) && (gid != -1))
13296 +               gid = -2;
13297 +       return (gid & MAX_GID);
13298 +}
13299 +
13300 +struct peer_tag {
13301 +       int32_t xid;
13302 +       int32_t nid;
13303 +};
13304 +
13305 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
13306 +
13307 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
13308 +                unsigned long *flags);
13309 +
13310 +#ifdef CONFIG_PROPAGATE
13311 +
13312 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
13313 +
13314 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
13315 +
13316 +#else
13317 +#define dx_propagate_tag(n, i) do { } while (0)
13318 +#endif
13319 +
13320 +#endif /* _DX_TAG_H */
13321 diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_inet6.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_inet6.h
13322 --- linux-2.6.29.4/include/linux/vs_inet6.h     1970-01-01 01:00:00.000000000 +0100
13323 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_inet6.h       2009-03-25 00:46:50.000000000 +0100
13324 @@ -0,0 +1,246 @@
13325 +#ifndef _VS_INET6_H
13326 +#define _VS_INET6_H
13327 +
13328 +#include "vserver/base.h"
13329 +#include "vserver/network.h"
13330 +#include "vserver/debug.h"
13331 +
13332 +#include <net/ipv6.h>
13333 +
13334 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
13335 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
13336 +
13337 +
13338 +#ifdef CONFIG_IPV6
13339 +
13340 +static inline
13341 +int v6_addr_match(struct nx_addr_v6 *nxa,
13342 +       const struct in6_addr *addr, uint16_t mask)
13343 +{
13344 +       int ret = 0;
13345 +
13346 +       switch (nxa->type & mask) {
13347 +       case NXA_TYPE_MASK:
13348 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
13349 +               break;
13350 +       case NXA_TYPE_ADDR:
13351 +               ret = ipv6_addr_equal(&nxa->ip, addr);
13352 +               break;
13353 +       case NXA_TYPE_ANY:
13354 +               ret = 1;
13355 +               break;
13356 +       }
13357 +       vxdprintk(VXD_CBIT(net, 0),
13358 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
13359 +               nxa, NXAV6(nxa), addr, mask, ret);
13360 +       return ret;
13361 +}
13362 +
13363 +static inline
13364 +int v6_addr_in_nx_info(struct nx_info *nxi,
13365 +       const struct in6_addr *addr, uint16_t mask)
13366 +{
13367 +       struct nx_addr_v6 *nxa;
13368 +       int ret = 1;
13369 +
13370 +       if (!nxi)
13371 +               goto out;
13372 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
13373 +               if (v6_addr_match(nxa, addr, mask))
13374 +                       goto out;
13375 +       ret = 0;
13376 +out:
13377 +       vxdprintk(VXD_CBIT(net, 0),
13378 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
13379 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
13380 +       return ret;
13381 +}
13382 +
13383 +static inline
13384 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
13385 +{
13386 +       /* FIXME: needs full range checks */
13387 +       return v6_addr_match(nxa, &addr->ip, mask);
13388 +}
13389 +
13390 +static inline
13391 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
13392 +{
13393 +       struct nx_addr_v6 *ptr;
13394 +
13395 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
13396 +               if (v6_nx_addr_match(ptr, nxa, mask))
13397 +                       return 1;
13398 +       return 0;
13399 +}
13400 +
13401 +
13402 +/*
13403 + *     Check if a given address matches for a socket
13404 + *
13405 + *     nxi:            the socket's nx_info if any
13406 + *     addr:           to be verified address
13407 + */
13408 +static inline
13409 +int v6_sock_addr_match (
13410 +       struct nx_info *nxi,
13411 +       struct inet_sock *inet,
13412 +       struct in6_addr *addr)
13413 +{
13414 +       struct sock *sk = &inet->sk;
13415 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13416 +
13417 +       if (!ipv6_addr_any(addr) &&
13418 +               ipv6_addr_equal(saddr, addr))
13419 +               return 1;
13420 +       if (ipv6_addr_any(saddr))
13421 +               return v6_addr_in_nx_info(nxi, addr, -1);
13422 +       return 0;
13423 +}
13424 +
13425 +/*
13426 + *     check if address is covered by socket
13427 + *
13428 + *     sk:     the socket to check against
13429 + *     addr:   the address in question (must be != 0)
13430 + */
13431 +
13432 +static inline
13433 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
13434 +{
13435 +       struct nx_info *nxi = sk->sk_nx_info;
13436 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
13437 +
13438 +       vxdprintk(VXD_CBIT(net, 5),
13439 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
13440 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
13441 +               (sk->sk_socket?sk->sk_socket->flags:0));
13442 +
13443 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
13444 +               return v6_addr_match(nxa, saddr, -1);
13445 +       } else if (nxi) {               /* match against nx_info */
13446 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
13447 +       } else {                        /* unrestricted any socket */
13448 +               return 1;
13449 +       }
13450 +}
13451 +
13452 +
13453 +/* inet related checks and helpers */
13454 +
13455 +
13456 +struct in_ifaddr;
13457 +struct net_device;
13458 +struct sock;
13459 +
13460 +
13461 +#include <linux/netdevice.h>
13462 +#include <linux/inetdevice.h>
13463 +#include <net/inet_timewait_sock.h>
13464 +
13465 +
13466 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13467 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
13468 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
13469 +
13470 +
13471 +
13472 +static inline
13473 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
13474 +{
13475 +       if (!nxi)
13476 +               return 1;
13477 +       if (!ifa)
13478 +               return 0;
13479 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
13480 +}
13481 +
13482 +static inline
13483 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
13484 +{
13485 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
13486 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13487 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
13488 +
13489 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13490 +               return 1;
13491 +       if (v6_ifa_in_nx_info(ifa, nxi))
13492 +               return 1;
13493 +       return 0;
13494 +}
13495 +
13496 +
13497 +struct nx_v6_sock_addr {
13498 +       struct in6_addr saddr;  /* Address used for validation */
13499 +       struct in6_addr baddr;  /* Address used for socket bind */
13500 +};
13501 +
13502 +static inline
13503 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
13504 +       struct nx_v6_sock_addr *nsa)
13505 +{
13506 +       // struct sock *sk = &inet->sk;
13507 +       // struct nx_info *nxi = sk->sk_nx_info;
13508 +       struct in6_addr saddr = addr->sin6_addr;
13509 +       struct in6_addr baddr = saddr;
13510 +
13511 +       nsa->saddr = saddr;
13512 +       nsa->baddr = baddr;
13513 +       return 0;
13514 +}
13515 +
13516 +static inline
13517 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
13518 +{
13519 +       // struct sock *sk = &inet->sk;
13520 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
13521 +
13522 +       // *saddr = nsa->baddr;
13523 +       // inet->saddr = nsa->baddr;
13524 +}
13525 +
13526 +static inline
13527 +int nx_info_has_v6(struct nx_info *nxi)
13528 +{
13529 +       if (!nxi)
13530 +               return 1;
13531 +       if (NX_IPV6(nxi))
13532 +               return 1;
13533 +       return 0;
13534 +}
13535 +
13536 +#else /* CONFIG_IPV6 */
13537 +
13538 +static inline
13539 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
13540 +{
13541 +       return 1;
13542 +}
13543 +
13544 +
13545 +static inline
13546 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13547 +{
13548 +       return 1;
13549 +}
13550 +
13551 +static inline
13552 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13553 +{
13554 +       return 1;
13555 +}
13556 +
13557 +static inline
13558 +int nx_info_has_v6(struct nx_info *nxi)
13559 +{
13560 +       return 0;
13561 +}
13562 +
13563 +#endif /* CONFIG_IPV6 */
13564 +
13565 +#define current_nx_info_has_v6() \
13566 +       nx_info_has_v6(current_nx_info())
13567 +
13568 +#else
13569 +#warning duplicate inclusion
13570 +#endif
13571 diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_inet.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_inet.h
13572 --- linux-2.6.29.4/include/linux/vs_inet.h      1970-01-01 01:00:00.000000000 +0100
13573 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_inet.h        2009-02-22 22:54:26.000000000 +0100
13574 @@ -0,0 +1,342 @@
13575 +#ifndef _VS_INET_H
13576 +#define _VS_INET_H
13577 +
13578 +#include "vserver/base.h"
13579 +#include "vserver/network.h"
13580 +#include "vserver/debug.h"
13581 +
13582 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
13583 +
13584 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
13585 +                       NIPQUAD((a)->mask), (a)->type
13586 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
13587 +
13588 +
13589 +static inline
13590 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
13591 +{
13592 +       __be32 ip = nxa->ip[0].s_addr;
13593 +       __be32 mask = nxa->mask.s_addr;
13594 +       __be32 bcast = ip | ~mask;
13595 +       int ret = 0;
13596 +
13597 +       switch (nxa->type & tmask) {
13598 +       case NXA_TYPE_MASK:
13599 +               ret = (ip == (addr & mask));
13600 +               break;
13601 +       case NXA_TYPE_ADDR:
13602 +               ret = 3;
13603 +               if (addr == ip)
13604 +                       break;
13605 +               /* fall through to broadcast */
13606 +       case NXA_MOD_BCAST:
13607 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
13608 +               break;
13609 +       case NXA_TYPE_RANGE:
13610 +               ret = ((nxa->ip[0].s_addr <= addr) &&
13611 +                       (nxa->ip[1].s_addr > addr));
13612 +               break;
13613 +       case NXA_TYPE_ANY:
13614 +               ret = 2;
13615 +               break;
13616 +       }
13617 +
13618 +       vxdprintk(VXD_CBIT(net, 0),
13619 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
13620 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
13621 +       return ret;
13622 +}
13623 +
13624 +static inline
13625 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
13626 +{
13627 +       struct nx_addr_v4 *nxa;
13628 +       int ret = 1;
13629 +
13630 +       if (!nxi)
13631 +               goto out;
13632 +
13633 +       ret = 2;
13634 +       /* allow 127.0.0.1 when remapping lback */
13635 +       if ((tmask & NXA_LOOPBACK) &&
13636 +               (addr == IPI_LOOPBACK) &&
13637 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13638 +               goto out;
13639 +       ret = 3;
13640 +       /* check for lback address */
13641 +       if ((tmask & NXA_MOD_LBACK) &&
13642 +               (nxi->v4_lback.s_addr == addr))
13643 +               goto out;
13644 +       ret = 4;
13645 +       /* check for broadcast address */
13646 +       if ((tmask & NXA_MOD_BCAST) &&
13647 +               (nxi->v4_bcast.s_addr == addr))
13648 +               goto out;
13649 +       ret = 5;
13650 +       /* check for v4 addresses */
13651 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
13652 +               if (v4_addr_match(nxa, addr, tmask))
13653 +                       goto out;
13654 +       ret = 0;
13655 +out:
13656 +       vxdprintk(VXD_CBIT(net, 0),
13657 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
13658 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
13659 +       return ret;
13660 +}
13661 +
13662 +static inline
13663 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
13664 +{
13665 +       /* FIXME: needs full range checks */
13666 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
13667 +}
13668 +
13669 +static inline
13670 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
13671 +{
13672 +       struct nx_addr_v4 *ptr;
13673 +
13674 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
13675 +               if (v4_nx_addr_match(ptr, nxa, mask))
13676 +                       return 1;
13677 +       return 0;
13678 +}
13679 +
13680 +#include <net/inet_sock.h>
13681 +
13682 +/*
13683 + *     Check if a given address matches for a socket
13684 + *
13685 + *     nxi:            the socket's nx_info if any
13686 + *     addr:           to be verified address
13687 + */
13688 +static inline
13689 +int v4_sock_addr_match (
13690 +       struct nx_info *nxi,
13691 +       struct inet_sock *inet,
13692 +       __be32 addr)
13693 +{
13694 +       __be32 saddr = inet->rcv_saddr;
13695 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
13696 +
13697 +       if (addr && (saddr == addr || bcast == addr))
13698 +               return 1;
13699 +       if (!saddr)
13700 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
13701 +       return 0;
13702 +}
13703 +
13704 +
13705 +/* inet related checks and helpers */
13706 +
13707 +
13708 +struct in_ifaddr;
13709 +struct net_device;
13710 +struct sock;
13711 +
13712 +#ifdef CONFIG_INET
13713 +
13714 +#include <linux/netdevice.h>
13715 +#include <linux/inetdevice.h>
13716 +#include <net/inet_sock.h>
13717 +#include <net/inet_timewait_sock.h>
13718 +
13719 +
13720 +int dev_in_nx_info(struct net_device *, struct nx_info *);
13721 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
13722 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
13723 +
13724 +
13725 +/*
13726 + *     check if address is covered by socket
13727 + *
13728 + *     sk:     the socket to check against
13729 + *     addr:   the address in question (must be != 0)
13730 + */
13731 +
13732 +static inline
13733 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
13734 +{
13735 +       struct nx_info *nxi = sk->sk_nx_info;
13736 +       __be32 saddr = inet_rcv_saddr(sk);
13737 +
13738 +       vxdprintk(VXD_CBIT(net, 5),
13739 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
13740 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
13741 +               (sk->sk_socket?sk->sk_socket->flags:0));
13742 +
13743 +       if (saddr) {            /* direct address match */
13744 +               return v4_addr_match(nxa, saddr, -1);
13745 +       } else if (nxi) {       /* match against nx_info */
13746 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
13747 +       } else {                /* unrestricted any socket */
13748 +               return 1;
13749 +       }
13750 +}
13751 +
13752 +
13753 +
13754 +static inline
13755 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
13756 +{
13757 +       vxdprintk(VXD_CBIT(net, 1), "nx_dev_visible(%p[#%u],%p Â»%s«) %d",
13758 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
13759 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
13760 +
13761 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13762 +               return 1;
13763 +       if (dev_in_nx_info(dev, nxi))
13764 +               return 1;
13765 +       return 0;
13766 +}
13767 +
13768 +
13769 +static inline
13770 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
13771 +{
13772 +       if (!nxi)
13773 +               return 1;
13774 +       if (!ifa)
13775 +               return 0;
13776 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
13777 +}
13778 +
13779 +static inline
13780 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
13781 +{
13782 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
13783 +               nxi, nxi ? nxi->nx_id : 0, ifa,
13784 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
13785 +
13786 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
13787 +               return 1;
13788 +       if (v4_ifa_in_nx_info(ifa, nxi))
13789 +               return 1;
13790 +       return 0;
13791 +}
13792 +
13793 +
13794 +struct nx_v4_sock_addr {
13795 +       __be32 saddr;   /* Address used for validation */
13796 +       __be32 baddr;   /* Address used for socket bind */
13797 +};
13798 +
13799 +static inline
13800 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
13801 +       struct nx_v4_sock_addr *nsa)
13802 +{
13803 +       struct sock *sk = &inet->sk;
13804 +       struct nx_info *nxi = sk->sk_nx_info;
13805 +       __be32 saddr = addr->sin_addr.s_addr;
13806 +       __be32 baddr = saddr;
13807 +
13808 +       vxdprintk(VXD_CBIT(net, 3),
13809 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
13810 +               sk, sk->sk_nx_info, sk->sk_socket,
13811 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
13812 +               NIPQUAD(saddr));
13813 +
13814 +       if (nxi) {
13815 +               if (saddr == INADDR_ANY) {
13816 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
13817 +                               baddr = nxi->v4.ip[0].s_addr;
13818 +               } else if (saddr == IPI_LOOPBACK) {
13819 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13820 +                               baddr = nxi->v4_lback.s_addr;
13821 +               } else {        /* normal address bind */
13822 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
13823 +                               return -EADDRNOTAVAIL;
13824 +               }
13825 +       }
13826 +
13827 +       vxdprintk(VXD_CBIT(net, 3),
13828 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
13829 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
13830 +
13831 +       nsa->saddr = saddr;
13832 +       nsa->baddr = baddr;
13833 +       return 0;
13834 +}
13835 +
13836 +static inline
13837 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
13838 +{
13839 +       inet->saddr = nsa->baddr;
13840 +       inet->rcv_saddr = nsa->baddr;
13841 +}
13842 +
13843 +
13844 +/*
13845 + *      helper to simplify inet_lookup_listener
13846 + *
13847 + *      nxi:   the socket's nx_info if any
13848 + *      addr:  to be verified address
13849 + *      saddr: socket address
13850 + */
13851 +static inline int v4_inet_addr_match (
13852 +       struct nx_info *nxi,
13853 +       __be32 addr,
13854 +       __be32 saddr)
13855 +{
13856 +       if (addr && (saddr == addr))
13857 +               return 1;
13858 +       if (!saddr)
13859 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
13860 +       return 0;
13861 +}
13862 +
13863 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
13864 +{
13865 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
13866 +               (addr == nxi->v4_lback.s_addr))
13867 +               return IPI_LOOPBACK;
13868 +       return addr;
13869 +}
13870 +
13871 +static inline
13872 +int nx_info_has_v4(struct nx_info *nxi)
13873 +{
13874 +       if (!nxi)
13875 +               return 1;
13876 +       if (NX_IPV4(nxi))
13877 +               return 1;
13878 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
13879 +               return 1;
13880 +       return 0;
13881 +}
13882 +
13883 +#else /* CONFIG_INET */
13884 +
13885 +static inline
13886 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
13887 +{
13888 +       return 1;
13889 +}
13890 +
13891 +static inline
13892 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
13893 +{
13894 +       return 1;
13895 +}
13896 +
13897 +static inline
13898 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
13899 +{
13900 +       return 1;
13901 +}
13902 +
13903 +static inline
13904 +int nx_info_has_v4(struct nx_info *nxi)
13905 +{
13906 +       return 0;
13907 +}
13908 +
13909 +#endif /* CONFIG_INET */
13910 +
13911 +#define current_nx_info_has_v4() \
13912 +       nx_info_has_v4(current_nx_info())
13913 +
13914 +#else
13915 +// #warning duplicate inclusion
13916 +#endif
13917 diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_limit.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_limit.h
13918 --- linux-2.6.29.4/include/linux/vs_limit.h     1970-01-01 01:00:00.000000000 +0100
13919 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_limit.h       2009-02-22 22:54:26.000000000 +0100
13920 @@ -0,0 +1,140 @@
13921 +#ifndef _VS_LIMIT_H
13922 +#define _VS_LIMIT_H
13923 +
13924 +#include "vserver/limit.h"
13925 +#include "vserver/base.h"
13926 +#include "vserver/context.h"
13927 +#include "vserver/debug.h"
13928 +#include "vserver/context.h"
13929 +#include "vserver/limit_int.h"
13930 +
13931 +
13932 +#define vx_acc_cres(v, d, p, r) \
13933 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
13934 +
13935 +#define vx_acc_cres_cond(x, d, p, r) \
13936 +       __vx_acc_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
13937 +       r, d, p, __FILE__, __LINE__)
13938 +
13939 +
13940 +#define vx_add_cres(v, a, p, r) \
13941 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
13942 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
13943 +
13944 +#define vx_add_cres_cond(x, a, p, r) \
13945 +       __vx_add_cres(((x) == vx_current_xid()) ? current->vx_info : 0, \
13946 +       r, a, p, __FILE__, __LINE__)
13947 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
13948 +
13949 +
13950 +/* process and file limits */
13951 +
13952 +#define vx_nproc_inc(p) \
13953 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
13954 +
13955 +#define vx_nproc_dec(p) \
13956 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
13957 +
13958 +#define vx_files_inc(f) \
13959 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
13960 +
13961 +#define vx_files_dec(f) \
13962 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
13963 +
13964 +#define vx_locks_inc(l) \
13965 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
13966 +
13967 +#define vx_locks_dec(l) \
13968 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
13969 +
13970 +#define vx_openfd_inc(f) \
13971 +       vx_acc_cres(current->vx_info, 1, (void *)(long)(f), VLIMIT_OPENFD)
13972 +
13973 +#define vx_openfd_dec(f) \
13974 +       vx_acc_cres(current->vx_info,-1, (void *)(long)(f), VLIMIT_OPENFD)
13975 +
13976 +
13977 +#define vx_cres_avail(v, n, r) \
13978 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
13979 +
13980 +
13981 +#define vx_nproc_avail(n) \
13982 +       vx_cres_avail(current->vx_info, n, RLIMIT_NPROC)
13983 +
13984 +#define vx_files_avail(n) \
13985 +       vx_cres_avail(current->vx_info, n, RLIMIT_NOFILE)
13986 +
13987 +#define vx_locks_avail(n) \
13988 +       vx_cres_avail(current->vx_info, n, RLIMIT_LOCKS)
13989 +
13990 +#define vx_openfd_avail(n) \
13991 +       vx_cres_avail(current->vx_info, n, VLIMIT_OPENFD)
13992 +
13993 +
13994 +/* dentry limits */
13995 +
13996 +#define vx_dentry_inc(d) do {                                          \
13997 +       if (atomic_read(&d->d_count) == 1)                              \
13998 +               vx_acc_cres(current->vx_info, 1, d, VLIMIT_DENTRY);     \
13999 +       } while (0)
14000 +
14001 +#define vx_dentry_dec(d) do {                                          \
14002 +       if (atomic_read(&d->d_count) == 0)                              \
14003 +               vx_acc_cres(current->vx_info,-1, d, VLIMIT_DENTRY);     \
14004 +       } while (0)
14005 +
14006 +#define vx_dentry_avail(n) \
14007 +       vx_cres_avail(current->vx_info, n, VLIMIT_DENTRY)
14008 +
14009 +
14010 +/* socket limits */
14011 +
14012 +#define vx_sock_inc(s) \
14013 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
14014 +
14015 +#define vx_sock_dec(s) \
14016 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
14017 +
14018 +#define vx_sock_avail(n) \
14019 +       vx_cres_avail(current->vx_info, n, VLIMIT_NSOCK)
14020 +
14021 +
14022 +/* ipc resource limits */
14023 +
14024 +#define vx_ipcmsg_add(v, u, a) \
14025 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
14026 +
14027 +#define vx_ipcmsg_sub(v, u, a) \
14028 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
14029 +
14030 +#define vx_ipcmsg_avail(v, a) \
14031 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
14032 +
14033 +
14034 +#define vx_ipcshm_add(v, k, a) \
14035 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
14036 +
14037 +#define vx_ipcshm_sub(v, k, a) \
14038 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
14039 +
14040 +#define vx_ipcshm_avail(v, a) \
14041 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
14042 +
14043 +
14044 +#define vx_semary_inc(a) \
14045 +       vx_acc_cres(current->vx_info, 1, a, VLIMIT_SEMARY)
14046 +
14047 +#define vx_semary_dec(a) \
14048 +       vx_acc_cres(current->vx_info, -1, a, VLIMIT_SEMARY)
14049 +
14050 +
14051 +#define vx_nsems_add(a,n) \
14052 +       vx_add_cres(current->vx_info, n, a, VLIMIT_NSEMS)
14053 +
14054 +#define vx_nsems_sub(a,n) \
14055 +       vx_sub_cres(current->vx_info, n, a, VLIMIT_NSEMS)
14056 +
14057 +
14058 +#else
14059 +#warning duplicate inclusion
14060 +#endif
14061 diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_memory.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_memory.h
14062 --- linux-2.6.29.4/include/linux/vs_memory.h    1970-01-01 01:00:00.000000000 +0100
14063 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_memory.h      2009-02-22 22:54:26.000000000 +0100
14064 @@ -0,0 +1,159 @@
14065 +#ifndef _VS_MEMORY_H
14066 +#define _VS_MEMORY_H
14067 +
14068 +#include "vserver/limit.h"
14069 +#include "vserver/base.h"
14070 +#include "vserver/context.h"
14071 +#include "vserver/debug.h"
14072 +#include "vserver/context.h"
14073 +#include "vserver/limit_int.h"
14074 +
14075 +
14076 +#define __acc_add_long(a, v)   (*(v) += (a))
14077 +#define __acc_inc_long(v)      (++*(v))
14078 +#define __acc_dec_long(v)      (--*(v))
14079 +
14080 +#if    NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS
14081 +#define __acc_add_atomic(a, v) atomic_long_add(a, v)
14082 +#define __acc_inc_atomic(v)    atomic_long_inc(v)
14083 +#define __acc_dec_atomic(v)    atomic_long_dec(v)
14084 +#else  /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
14085 +#define __acc_add_atomic(a, v) __acc_add_long(a, v)
14086 +#define __acc_inc_atomic(v)    __acc_inc_long(v)
14087 +#define __acc_dec_atomic(v)    __acc_dec_long(v)
14088 +#endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
14089 +
14090 +
14091 +#define vx_acc_page(m, d, v, r) do {                                   \
14092 +       if ((d) > 0)                                                    \
14093 +               __acc_inc_long(&(m)->v);                                \
14094 +       else                                                            \
14095 +               __acc_dec_long(&(m)->v);                                \
14096 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
14097 +} while (0)
14098 +
14099 +#define vx_acc_page_atomic(m, d, v, r) do {                            \
14100 +       if ((d) > 0)                                                    \
14101 +               __acc_inc_atomic(&(m)->v);                              \
14102 +       else                                                            \
14103 +               __acc_dec_atomic(&(m)->v);                              \
14104 +       __vx_acc_cres(m->mm_vx_info, r, d, m, __FILE__, __LINE__);      \
14105 +} while (0)
14106 +
14107 +
14108 +#define vx_acc_pages(m, p, v, r) do {                                  \
14109 +       unsigned long __p = (p);                                        \
14110 +       __acc_add_long(__p, &(m)->v);                                   \
14111 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
14112 +} while (0)
14113 +
14114 +#define vx_acc_pages_atomic(m, p, v, r) do {                           \
14115 +       unsigned long __p = (p);                                        \
14116 +       __acc_add_atomic(__p, &(m)->v);                                 \
14117 +       __vx_add_cres(m->mm_vx_info, r, __p, m, __FILE__, __LINE__);    \
14118 +} while (0)
14119 +
14120 +
14121 +
14122 +#define vx_acc_vmpage(m, d) \
14123 +       vx_acc_page(m, d, total_vm,  RLIMIT_AS)
14124 +#define vx_acc_vmlpage(m, d) \
14125 +       vx_acc_page(m, d, locked_vm, RLIMIT_MEMLOCK)
14126 +#define vx_acc_file_rsspage(m, d) \
14127 +       vx_acc_page_atomic(m, d, _file_rss, VLIMIT_MAPPED)
14128 +#define vx_acc_anon_rsspage(m, d) \
14129 +       vx_acc_page_atomic(m, d, _anon_rss, VLIMIT_ANON)
14130 +
14131 +#define vx_acc_vmpages(m, p) \
14132 +       vx_acc_pages(m, p, total_vm,  RLIMIT_AS)
14133 +#define vx_acc_vmlpages(m, p) \
14134 +       vx_acc_pages(m, p, locked_vm, RLIMIT_MEMLOCK)
14135 +#define vx_acc_file_rsspages(m, p) \
14136 +       vx_acc_pages_atomic(m, p, _file_rss, VLIMIT_MAPPED)
14137 +#define vx_acc_anon_rsspages(m, p) \
14138 +       vx_acc_pages_atomic(m, p, _anon_rss, VLIMIT_ANON)
14139 +
14140 +#define vx_pages_add(s, r, p)  __vx_add_cres(s, r, p, 0, __FILE__, __LINE__)
14141 +#define vx_pages_sub(s, r, p)  vx_pages_add(s, r, -(p))
14142 +
14143 +#define vx_vmpages_inc(m)              vx_acc_vmpage(m, 1)
14144 +#define vx_vmpages_dec(m)              vx_acc_vmpage(m, -1)
14145 +#define vx_vmpages_add(m, p)           vx_acc_vmpages(m, p)
14146 +#define vx_vmpages_sub(m, p)           vx_acc_vmpages(m, -(p))
14147 +
14148 +#define vx_vmlocked_inc(m)             vx_acc_vmlpage(m, 1)
14149 +#define vx_vmlocked_dec(m)             vx_acc_vmlpage(m, -1)
14150 +#define vx_vmlocked_add(m, p)          vx_acc_vmlpages(m, p)
14151 +#define vx_vmlocked_sub(m, p)          vx_acc_vmlpages(m, -(p))
14152 +
14153 +#define vx_file_rsspages_inc(m)                vx_acc_file_rsspage(m, 1)
14154 +#define vx_file_rsspages_dec(m)                vx_acc_file_rsspage(m, -1)
14155 +#define vx_file_rsspages_add(m, p)     vx_acc_file_rsspages(m, p)
14156 +#define vx_file_rsspages_sub(m, p)     vx_acc_file_rsspages(m, -(p))
14157 +
14158 +#define vx_anon_rsspages_inc(m)                vx_acc_anon_rsspage(m, 1)
14159 +#define vx_anon_rsspages_dec(m)                vx_acc_anon_rsspage(m, -1)
14160 +#define vx_anon_rsspages_add(m, p)     vx_acc_anon_rsspages(m, p)
14161 +#define vx_anon_rsspages_sub(m, p)     vx_acc_anon_rsspages(m, -(p))
14162 +
14163 +
14164 +#define vx_pages_avail(m, p, r) \
14165 +       __vx_cres_avail((m)->mm_vx_info, r, p, __FILE__, __LINE__)
14166 +
14167 +#define vx_vmpages_avail(m, p) vx_pages_avail(m, p, RLIMIT_AS)
14168 +#define vx_vmlocked_avail(m, p)        vx_pages_avail(m, p, RLIMIT_MEMLOCK)
14169 +#define vx_anon_avail(m, p)    vx_pages_avail(m, p, VLIMIT_ANON)
14170 +#define vx_mapped_avail(m, p)  vx_pages_avail(m, p, VLIMIT_MAPPED)
14171 +
14172 +#define vx_rss_avail(m, p) \
14173 +       __vx_cres_array_avail((m)->mm_vx_info, VLA_RSS, p, __FILE__, __LINE__)
14174 +
14175 +
14176 +enum {
14177 +       VXPT_UNKNOWN = 0,
14178 +       VXPT_ANON,
14179 +       VXPT_NONE,
14180 +       VXPT_FILE,
14181 +       VXPT_SWAP,
14182 +       VXPT_WRITE
14183 +};
14184 +
14185 +#if 0
14186 +#define        vx_page_fault(mm, vma, type, ret)
14187 +#else
14188 +
14189 +static inline
14190 +void __vx_page_fault(struct mm_struct *mm,
14191 +       struct vm_area_struct *vma, int type, int ret)
14192 +{
14193 +       struct vx_info *vxi = mm->mm_vx_info;
14194 +       int what;
14195 +/*
14196 +       static char *page_type[6] =
14197 +               { "UNKNOWN", "ANON", "NONE", "FILE", "SWAP", "WRITE" };
14198 +       static char *page_what[4] =
14199 +               { "FAULT_OOM", "FAULT_SIGBUS", "FAULT_MINOR", "FAULT_MAJOR" };
14200 +*/
14201 +
14202 +       if (!vxi)
14203 +               return;
14204 +
14205 +       what = (ret & 0x3);
14206 +
14207 +/*     printk("[%d] page[%d][%d] %2x %s %s\n", vxi->vx_id,
14208 +               type, what, ret, page_type[type], page_what[what]);
14209 +*/
14210 +       if (ret & VM_FAULT_WRITE)
14211 +               what |= 0x4;
14212 +       atomic_inc(&vxi->cacct.page[type][what]);
14213 +}
14214 +
14215 +#define        vx_page_fault(mm, vma, type, ret)       __vx_page_fault(mm, vma, type, ret)
14216 +#endif
14217 +
14218 +
14219 +extern unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm);
14220 +
14221 +#else
14222 +#warning duplicate inclusion
14223 +#endif
14224 diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_network.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_network.h
14225 --- linux-2.6.29.4/include/linux/vs_network.h   1970-01-01 01:00:00.000000000 +0100
14226 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_network.h     2009-02-22 22:54:26.000000000 +0100
14227 @@ -0,0 +1,169 @@
14228 +#ifndef _NX_VS_NETWORK_H
14229 +#define _NX_VS_NETWORK_H
14230 +
14231 +#include "vserver/context.h"
14232 +#include "vserver/network.h"
14233 +#include "vserver/base.h"
14234 +#include "vserver/check.h"
14235 +#include "vserver/debug.h"
14236 +
14237 +#include <linux/sched.h>
14238 +
14239 +
14240 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
14241 +
14242 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
14243 +       const char *_file, int _line)
14244 +{
14245 +       if (!nxi)
14246 +               return NULL;
14247 +
14248 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
14249 +               nxi, nxi ? nxi->nx_id : 0,
14250 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14251 +               _file, _line);
14252 +
14253 +       atomic_inc(&nxi->nx_usecnt);
14254 +       return nxi;
14255 +}
14256 +
14257 +
14258 +extern void free_nx_info(struct nx_info *);
14259 +
14260 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
14261 +
14262 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
14263 +{
14264 +       if (!nxi)
14265 +               return;
14266 +
14267 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
14268 +               nxi, nxi ? nxi->nx_id : 0,
14269 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14270 +               _file, _line);
14271 +
14272 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
14273 +               free_nx_info(nxi);
14274 +}
14275 +
14276 +
14277 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
14278 +
14279 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14280 +               const char *_file, int _line)
14281 +{
14282 +       if (nxi) {
14283 +               vxlprintk(VXD_CBIT(nid, 3),
14284 +                       "init_nx_info(%p[#%d.%d])",
14285 +                       nxi, nxi ? nxi->nx_id : 0,
14286 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14287 +                       _file, _line);
14288 +
14289 +               atomic_inc(&nxi->nx_usecnt);
14290 +       }
14291 +       *nxp = nxi;
14292 +}
14293 +
14294 +
14295 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
14296 +
14297 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
14298 +       const char *_file, int _line)
14299 +{
14300 +       struct nx_info *nxo;
14301 +
14302 +       if (!nxi)
14303 +               return;
14304 +
14305 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
14306 +               nxi, nxi ? nxi->nx_id : 0,
14307 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14308 +               _file, _line);
14309 +
14310 +       atomic_inc(&nxi->nx_usecnt);
14311 +       nxo = xchg(nxp, nxi);
14312 +       BUG_ON(nxo);
14313 +}
14314 +
14315 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
14316 +
14317 +static inline void __clr_nx_info(struct nx_info **nxp,
14318 +       const char *_file, int _line)
14319 +{
14320 +       struct nx_info *nxo;
14321 +
14322 +       nxo = xchg(nxp, NULL);
14323 +       if (!nxo)
14324 +               return;
14325 +
14326 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
14327 +               nxo, nxo ? nxo->nx_id : 0,
14328 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
14329 +               _file, _line);
14330 +
14331 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
14332 +               free_nx_info(nxo);
14333 +}
14334 +
14335 +
14336 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
14337 +
14338 +static inline void __claim_nx_info(struct nx_info *nxi,
14339 +       struct task_struct *task, const char *_file, int _line)
14340 +{
14341 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
14342 +               nxi, nxi ? nxi->nx_id : 0,
14343 +               nxi?atomic_read(&nxi->nx_usecnt):0,
14344 +               nxi?atomic_read(&nxi->nx_tasks):0,
14345 +               task, _file, _line);
14346 +
14347 +       atomic_inc(&nxi->nx_tasks);
14348 +}
14349 +
14350 +
14351 +extern void unhash_nx_info(struct nx_info *);
14352 +
14353 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
14354 +
14355 +static inline void __release_nx_info(struct nx_info *nxi,
14356 +       struct task_struct *task, const char *_file, int _line)
14357 +{
14358 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
14359 +               nxi, nxi ? nxi->nx_id : 0,
14360 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
14361 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
14362 +               task, _file, _line);
14363 +
14364 +       might_sleep();
14365 +
14366 +       if (atomic_dec_and_test(&nxi->nx_tasks))
14367 +               unhash_nx_info(nxi);
14368 +}
14369 +
14370 +
14371 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
14372 +
14373 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
14374 +       const char *_file, int _line)
14375 +{
14376 +       struct nx_info *nxi;
14377 +
14378 +       task_lock(p);
14379 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
14380 +               p, _file, _line);
14381 +       nxi = __get_nx_info(p->nx_info, _file, _line);
14382 +       task_unlock(p);
14383 +       return nxi;
14384 +}
14385 +
14386 +
14387 +static inline void exit_nx_info(struct task_struct *p)
14388 +{
14389 +       if (p->nx_info)
14390 +               release_nx_info(p->nx_info, p);
14391 +}
14392 +
14393 +
14394 +#else
14395 +#warning duplicate inclusion
14396 +#endif
14397 diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_pid.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_pid.h
14398 --- linux-2.6.29.4/include/linux/vs_pid.h       1970-01-01 01:00:00.000000000 +0100
14399 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_pid.h 2009-02-22 22:54:26.000000000 +0100
14400 @@ -0,0 +1,95 @@
14401 +#ifndef _VS_PID_H
14402 +#define _VS_PID_H
14403 +
14404 +#include "vserver/base.h"
14405 +#include "vserver/check.h"
14406 +#include "vserver/context.h"
14407 +#include "vserver/debug.h"
14408 +#include "vserver/pid.h"
14409 +#include <linux/pid_namespace.h>
14410 +
14411 +
14412 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
14413 +
14414 +static inline
14415 +int vx_proc_task_visible(struct task_struct *task)
14416 +{
14417 +       if ((task->pid == 1) &&
14418 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
14419 +               /* show a blend through init */
14420 +               goto visible;
14421 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
14422 +               goto visible;
14423 +       return 0;
14424 +visible:
14425 +       return 1;
14426 +}
14427 +
14428 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
14429 +
14430 +#if 0
14431 +
14432 +static inline
14433 +struct task_struct *vx_find_proc_task_by_pid(int pid)
14434 +{
14435 +       struct task_struct *task = find_task_by_real_pid(pid);
14436 +
14437 +       if (task && !vx_proc_task_visible(task)) {
14438 +               vxdprintk(VXD_CBIT(misc, 6),
14439 +                       "dropping task (find) %p[#%u,%u] for %p[#%u,%u]",
14440 +                       task, task->xid, task->pid,
14441 +                       current, current->xid, current->pid);
14442 +               task = NULL;
14443 +       }
14444 +       return task;
14445 +}
14446 +
14447 +#endif
14448 +
14449 +static inline
14450 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
14451 +{
14452 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
14453 +
14454 +       if (task && !vx_proc_task_visible(task)) {
14455 +               vxdprintk(VXD_CBIT(misc, 6),
14456 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
14457 +                       task, task->xid, task->pid,
14458 +                       current, current->xid, current->pid);
14459 +               put_task_struct(task);
14460 +               task = NULL;
14461 +       }
14462 +       return task;
14463 +}
14464 +
14465 +#if 0
14466 +
14467 +static inline
14468 +struct task_struct *vx_child_reaper(struct task_struct *p)
14469 +{
14470 +       struct vx_info *vxi = p->vx_info;
14471 +       struct task_struct *reaper = child_reaper(p);
14472 +
14473 +       if (!vxi)
14474 +               goto out;
14475 +
14476 +       BUG_ON(!p->vx_info->vx_reaper);
14477 +
14478 +       /* child reaper for the guest reaper */
14479 +       if (vxi->vx_reaper == p)
14480 +               goto out;
14481 +
14482 +       reaper = vxi->vx_reaper;
14483 +out:
14484 +       vxdprintk(VXD_CBIT(xid, 7),
14485 +               "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]",
14486 +               p, p->xid, p->pid, reaper, reaper->xid, reaper->pid);
14487 +       return reaper;
14488 +}
14489 +
14490 +#endif
14491 +
14492 +
14493 +#else
14494 +#warning duplicate inclusion
14495 +#endif
14496 diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_sched.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_sched.h
14497 --- linux-2.6.29.4/include/linux/vs_sched.h     1970-01-01 01:00:00.000000000 +0100
14498 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_sched.h       2009-02-22 22:54:26.000000000 +0100
14499 @@ -0,0 +1,110 @@
14500 +#ifndef _VS_SCHED_H
14501 +#define _VS_SCHED_H
14502 +
14503 +#include "vserver/base.h"
14504 +#include "vserver/context.h"
14505 +#include "vserver/sched.h"
14506 +
14507 +
14508 +#define VAVAVOOM_RATIO          50
14509 +
14510 +#define MAX_PRIO_BIAS           20
14511 +#define MIN_PRIO_BIAS          -20
14512 +
14513 +
14514 +#ifdef CONFIG_VSERVER_HARDCPU
14515 +
14516 +/*
14517 + * effective_prio - return the priority that is based on the static
14518 + * priority but is modified by bonuses/penalties.
14519 + *
14520 + * We scale the actual sleep average [0 .... MAX_SLEEP_AVG]
14521 + * into a -4 ... 0 ... +4 bonus/penalty range.
14522 + *
14523 + * Additionally, we scale another amount based on the number of
14524 + * CPU tokens currently held by the context, if the process is
14525 + * part of a context (and the appropriate SCHED flag is set).
14526 + * This ranges from -5 ... 0 ... +15, quadratically.
14527 + *
14528 + * So, the total bonus is -9 .. 0 .. +19
14529 + * We use ~50% of the full 0...39 priority range so that:
14530 + *
14531 + * 1) nice +19 interactive tasks do not preempt nice 0 CPU hogs.
14532 + * 2) nice -20 CPU hogs do not get preempted by nice 0 tasks.
14533 + *    unless that context is far exceeding its CPU allocation.
14534 + *
14535 + * Both properties are important to certain workloads.
14536 + */
14537 +static inline
14538 +int vx_effective_vavavoom(struct _vx_sched_pc *sched_pc, int max_prio)
14539 +{
14540 +       int vavavoom, max;
14541 +
14542 +       /* lots of tokens = lots of vavavoom
14543 +        *      no tokens = no vavavoom      */
14544 +       if ((vavavoom = sched_pc->tokens) >= 0) {
14545 +               max = sched_pc->tokens_max;
14546 +               vavavoom = max - vavavoom;
14547 +               max = max * max;
14548 +               vavavoom = max_prio * VAVAVOOM_RATIO / 100
14549 +                       * (vavavoom*vavavoom - (max >> 2)) / max;
14550 +               return vavavoom;
14551 +       }
14552 +       return 0;
14553 +}
14554 +
14555 +
14556 +static inline
14557 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14558 +{
14559 +       struct vx_info *vxi = p->vx_info;
14560 +       struct _vx_sched_pc *sched_pc;
14561 +
14562 +       if (!vxi)
14563 +               return prio;
14564 +
14565 +       sched_pc = &vx_cpu(vxi, sched_pc);
14566 +       if (vx_info_flags(vxi, VXF_SCHED_PRIO, 0)) {
14567 +               int vavavoom = vx_effective_vavavoom(sched_pc, max_user);
14568 +
14569 +               sched_pc->vavavoom = vavavoom;
14570 +               prio += vavavoom;
14571 +       }
14572 +       prio += sched_pc->prio_bias;
14573 +       return prio;
14574 +}
14575 +
14576 +#else /* !CONFIG_VSERVER_HARDCPU */
14577 +
14578 +static inline
14579 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
14580 +{
14581 +       struct vx_info *vxi = p->vx_info;
14582 +
14583 +       if (vxi)
14584 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
14585 +       return prio;
14586 +}
14587 +
14588 +#endif /* CONFIG_VSERVER_HARDCPU */
14589 +
14590 +
14591 +static inline void vx_account_user(struct vx_info *vxi,
14592 +       cputime_t cputime, int nice)
14593 +{
14594 +       if (!vxi)
14595 +               return;
14596 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
14597 +}
14598 +
14599 +static inline void vx_account_system(struct vx_info *vxi,
14600 +       cputime_t cputime, int idle)
14601 +{
14602 +       if (!vxi)
14603 +               return;
14604 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
14605 +}
14606 +
14607 +#else
14608 +#warning duplicate inclusion
14609 +#endif
14610 diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_socket.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_socket.h
14611 --- linux-2.6.29.4/include/linux/vs_socket.h    1970-01-01 01:00:00.000000000 +0100
14612 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_socket.h      2009-02-22 22:54:26.000000000 +0100
14613 @@ -0,0 +1,67 @@
14614 +#ifndef _VS_SOCKET_H
14615 +#define _VS_SOCKET_H
14616 +
14617 +#include "vserver/debug.h"
14618 +#include "vserver/base.h"
14619 +#include "vserver/cacct.h"
14620 +#include "vserver/context.h"
14621 +#include "vserver/tag.h"
14622 +
14623 +
14624 +/* socket accounting */
14625 +
14626 +#include <linux/socket.h>
14627 +
14628 +static inline int vx_sock_type(int family)
14629 +{
14630 +       switch (family) {
14631 +       case PF_UNSPEC:
14632 +               return VXA_SOCK_UNSPEC;
14633 +       case PF_UNIX:
14634 +               return VXA_SOCK_UNIX;
14635 +       case PF_INET:
14636 +               return VXA_SOCK_INET;
14637 +       case PF_INET6:
14638 +               return VXA_SOCK_INET6;
14639 +       case PF_PACKET:
14640 +               return VXA_SOCK_PACKET;
14641 +       default:
14642 +               return VXA_SOCK_OTHER;
14643 +       }
14644 +}
14645 +
14646 +#define vx_acc_sock(v, f, p, s) \
14647 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
14648 +
14649 +static inline void __vx_acc_sock(struct vx_info *vxi,
14650 +       int family, int pos, int size, char *file, int line)
14651 +{
14652 +       if (vxi) {
14653 +               int type = vx_sock_type(family);
14654 +
14655 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
14656 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
14657 +       }
14658 +}
14659 +
14660 +#define vx_sock_recv(sk, s) \
14661 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
14662 +#define vx_sock_send(sk, s) \
14663 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
14664 +#define vx_sock_fail(sk, s) \
14665 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
14666 +
14667 +
14668 +#define sock_vx_init(s) do {           \
14669 +       (s)->sk_xid = 0;                \
14670 +       (s)->sk_vx_info = NULL;         \
14671 +       } while (0)
14672 +
14673 +#define sock_nx_init(s) do {           \
14674 +       (s)->sk_nid = 0;                \
14675 +       (s)->sk_nx_info = NULL;         \
14676 +       } while (0)
14677 +
14678 +#else
14679 +#warning duplicate inclusion
14680 +#endif
14681 diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_tag.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_tag.h
14682 --- linux-2.6.29.4/include/linux/vs_tag.h       1970-01-01 01:00:00.000000000 +0100
14683 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_tag.h 2009-02-22 22:54:26.000000000 +0100
14684 @@ -0,0 +1,47 @@
14685 +#ifndef _VS_TAG_H
14686 +#define _VS_TAG_H
14687 +
14688 +#include <linux/vserver/tag.h>
14689 +
14690 +/* check conditions */
14691 +
14692 +#define DX_ADMIN       0x0001
14693 +#define DX_WATCH       0x0002
14694 +#define DX_HOSTID      0x0008
14695 +
14696 +#define DX_IDENT       0x0010
14697 +
14698 +#define DX_ARG_MASK    0x0010
14699 +
14700 +
14701 +#define dx_task_tag(t) ((t)->tag)
14702 +
14703 +#define dx_current_tag() dx_task_tag(current)
14704 +
14705 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
14706 +
14707 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
14708 +
14709 +
14710 +/*
14711 + * check current context for ADMIN/WATCH and
14712 + * optionally against supplied argument
14713 + */
14714 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
14715 +{
14716 +       if (mode & DX_ARG_MASK) {
14717 +               if ((mode & DX_IDENT) && (id == cid))
14718 +                       return 1;
14719 +       }
14720 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
14721 +               ((mode & DX_WATCH) && (cid == 1)) ||
14722 +               ((mode & DX_HOSTID) && (id == 0)));
14723 +}
14724 +
14725 +struct inode;
14726 +int dx_permission(struct inode *inode, int mask);
14727 +
14728 +
14729 +#else
14730 +#warning duplicate inclusion
14731 +#endif
14732 diff -NurpP --minimal linux-2.6.29.4/include/linux/vs_time.h linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_time.h
14733 --- linux-2.6.29.4/include/linux/vs_time.h      1970-01-01 01:00:00.000000000 +0100
14734 +++ linux-2.6.29.4-vs2.3.0.36.14/include/linux/vs_time.h        2009-02-22 22:54:26.000000000 +0100
14735 @@ -0,0 +1,19 @@
14736 +#ifndef _VS_TIME_H
14737 +#define _VS_TIME_H
14738 +
14739 +
14740 +/* time faking stuff */
14741 +
14742 +#ifdef CONFIG_VSERVER_VTIME
14743 +
14744 +extern void vx_gettimeofday(struct timeval *tv);
14745 +extern int vx_settimeofday(struct timespec *ts);
14746 +
14747 +#else
14748 +#define        vx_gettimeofday(t)      do_gettimeofday(t)
14749 +#define        vx_settimeofday(t)      do_settimeofday(t)
14750 +#endif
14751 +
14752 +#else
14753 +#warning duplicate inclusion
14754 +#endif
14755 diff -NurpP --minimal linux-2.6.29.4/include/net/addrconf.h linux-2.6.29.4-vs2.3.0.36.14/include/net/addrconf.h
14756 --- linux-2.6.29.4/include/net/addrconf.h       2008-12-25 00:26:37.000000000 +0100
14757 +++ linux-2.6.29.4-vs2.3.0.36.14/include/net/addrconf.h 2009-02-22 22:54:26.000000000 +0100
14758 @@ -84,7 +84,8 @@ extern int                    ipv6_dev_get_saddr(struct n
14759                                                struct net_device *dev,
14760                                                const struct in6_addr *daddr,
14761                                                unsigned int srcprefs,
14762 -                                              struct in6_addr *saddr);
14763 +                                              struct in6_addr *saddr,
14764 +                                              struct nx_info *nxi);
14765  extern int                     ipv6_get_lladdr(struct net_device *dev,
14766                                                 struct in6_addr *addr,
14767                                                 unsigned char banned_flags);
14768 diff -NurpP --minimal linux-2.6.29.4/include/net/af_unix.h linux-2.6.29.4-vs2.3.0.36.14/include/net/af_unix.h
14769 --- linux-2.6.29.4/include/net/af_unix.h        2008-12-25 00:26:37.000000000 +0100
14770 +++ linux-2.6.29.4-vs2.3.0.36.14/include/net/af_unix.h  2009-02-22 22:54:26.000000000 +0100
14771 @@ -4,6 +4,7 @@
14772  #include <linux/socket.h>
14773  #include <linux/un.h>
14774  #include <linux/mutex.h>
14775 +#include <linux/vs_base.h>
14776  #include <net/sock.h>
14777  
14778  extern void unix_inflight(struct file *fp);
14779 diff -NurpP --minimal linux-2.6.29.4/include/net/inet_timewait_sock.h linux-2.6.29.4-vs2.3.0.36.14/include/net/inet_timewait_sock.h
14780 --- linux-2.6.29.4/include/net/inet_timewait_sock.h     2009-03-24 14:22:44.000000000 +0100
14781 +++ linux-2.6.29.4-vs2.3.0.36.14/include/net/inet_timewait_sock.h       2009-03-24 14:48:36.000000000 +0100
14782 @@ -15,15 +15,14 @@
14783  #ifndef _INET_TIMEWAIT_SOCK_
14784  #define _INET_TIMEWAIT_SOCK_
14785  
14786 +// #include <net/inet_sock.h>
14787 +#include <net/sock.h>
14788  
14789  #include <linux/list.h>
14790  #include <linux/module.h>
14791  #include <linux/timer.h>
14792  #include <linux/types.h>
14793  #include <linux/workqueue.h>
14794 -
14795 -#include <net/inet_sock.h>
14796 -#include <net/sock.h>
14797  #include <net/tcp_states.h>
14798  #include <net/timewait_sock.h>
14799  
14800 @@ -116,6 +115,10 @@ struct inet_timewait_sock {
14801  #define tw_hash                        __tw_common.skc_hash
14802  #define tw_prot                        __tw_common.skc_prot
14803  #define tw_net                 __tw_common.skc_net
14804 +#define tw_xid                 __tw_common.skc_xid
14805 +#define tw_vx_info             __tw_common.skc_vx_info
14806 +#define tw_nid                 __tw_common.skc_nid
14807 +#define tw_nx_info             __tw_common.skc_nx_info
14808         int                     tw_timeout;
14809         volatile unsigned char  tw_substate;
14810         /* 3 bits hole, try to pack */
14811 diff -NurpP --minimal linux-2.6.29.4/include/net/route.h linux-2.6.29.4-vs2.3.0.36.14/include/net/route.h
14812 --- linux-2.6.29.4/include/net/route.h  2008-12-25 00:26:37.000000000 +0100
14813 +++ linux-2.6.29.4-vs2.3.0.36.14/include/net/route.h    2009-02-22 22:54:26.000000000 +0100
14814 @@ -135,6 +135,9 @@ static inline void ip_rt_put(struct rtab
14815                 dst_release(&rt->u.dst);
14816  }
14817  
14818 +#include <linux/vs_base.h>
14819 +#include <linux/vs_inet.h>
14820 +
14821  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
14822  
14823  extern const __u8 ip_tos2prio[16];
14824 @@ -144,6 +147,9 @@ static inline char rt_tos2priority(u8 to
14825         return ip_tos2prio[IPTOS_TOS(tos)>>1];
14826  }
14827  
14828 +extern int ip_v4_find_src(struct net *net, struct nx_info *,
14829 +       struct rtable **, struct flowi *);
14830 +
14831  static inline int ip_route_connect(struct rtable **rp, __be32 dst,
14832                                    __be32 src, u32 tos, int oif, u8 protocol,
14833                                    __be16 sport, __be16 dport, struct sock *sk,
14834 @@ -161,11 +167,24 @@ static inline int ip_route_connect(struc
14835  
14836         int err;
14837         struct net *net = sock_net(sk);
14838 +       struct nx_info *nx_info = current->nx_info;
14839  
14840         if (inet_sk(sk)->transparent)
14841                 fl.flags |= FLOWI_FLAG_ANYSRC;
14842  
14843 -       if (!dst || !src) {
14844 +       if (sk)
14845 +               nx_info = sk->sk_nx_info;
14846 +
14847 +       vxdprintk(VXD_CBIT(net, 4),
14848 +               "ip_route_connect(%p) %p,%p;%lx",
14849 +               sk, nx_info, sk->sk_socket,
14850 +               (sk->sk_socket?sk->sk_socket->flags:0));
14851 +
14852 +       err = ip_v4_find_src(net, nx_info, rp, &fl);
14853 +       if (err)
14854 +               return err;
14855 +
14856 +       if (!fl.fl4_dst || !fl.fl4_src) {
14857                 err = __ip_route_output_key(net, rp, &fl);
14858                 if (err)
14859                         return err;
14860 diff -NurpP --minimal linux-2.6.29.4/include/net/sock.h linux-2.6.29.4-vs2.3.0.36.14/include/net/sock.h
14861 --- linux-2.6.29.4/include/net/sock.h   2009-03-24 14:22:44.000000000 +0100
14862 +++ linux-2.6.29.4-vs2.3.0.36.14/include/net/sock.h     2009-03-24 14:48:36.000000000 +0100
14863 @@ -134,6 +134,10 @@ struct sock_common {
14864  #ifdef CONFIG_NET_NS
14865         struct net              *skc_net;
14866  #endif
14867 +       xid_t                   skc_xid;
14868 +       struct vx_info          *skc_vx_info;
14869 +       nid_t                   skc_nid;
14870 +       struct nx_info          *skc_nx_info;
14871  };
14872  
14873  /**
14874 @@ -218,6 +222,10 @@ struct sock {
14875  #define sk_hash                        __sk_common.skc_hash
14876  #define sk_prot                        __sk_common.skc_prot
14877  #define sk_net                 __sk_common.skc_net
14878 +#define sk_xid                 __sk_common.skc_xid
14879 +#define sk_vx_info             __sk_common.skc_vx_info
14880 +#define sk_nid                 __sk_common.skc_nid
14881 +#define sk_nx_info             __sk_common.skc_nx_info
14882         unsigned char           sk_shutdown : 2,
14883                                 sk_no_check : 2,
14884                                 sk_userlocks : 4;
14885 diff -NurpP --minimal linux-2.6.29.4/init/main.c linux-2.6.29.4-vs2.3.0.36.14/init/main.c
14886 --- linux-2.6.29.4/init/main.c  2009-03-24 14:22:44.000000000 +0100
14887 +++ linux-2.6.29.4-vs2.3.0.36.14/init/main.c    2009-03-24 17:22:37.000000000 +0100
14888 @@ -64,6 +64,7 @@
14889  #include <linux/ftrace.h>
14890  #include <linux/async.h>
14891  #include <trace/boot.h>
14892 +#include <linux/vserver/percpu.h>
14893  
14894  #include <asm/io.h>
14895  #include <asm/bugs.h>
14896 @@ -381,12 +382,14 @@ EXPORT_SYMBOL(__per_cpu_offset);
14897  
14898  static void __init setup_per_cpu_areas(void)
14899  {
14900 -       unsigned long size, i;
14901 +       unsigned long size, vspc, i;
14902         char *ptr;
14903         unsigned long nr_possible_cpus = num_possible_cpus();
14904  
14905 +       vspc = PERCPU_PERCTX * CONFIG_VSERVER_CONTEXTS;
14906 +
14907         /* Copy section for each CPU (we discard the original) */
14908 -       size = ALIGN(PERCPU_ENOUGH_ROOM, PAGE_SIZE);
14909 +       size = ALIGN(PERCPU_ENOUGH_ROOM + vspc, PAGE_SIZE);
14910         ptr = alloc_bootmem_pages(size * nr_possible_cpus);
14911  
14912         for_each_possible_cpu(i) {
14913 diff -NurpP --minimal linux-2.6.29.4/ipc/mqueue.c linux-2.6.29.4-vs2.3.0.36.14/ipc/mqueue.c
14914 --- linux-2.6.29.4/ipc/mqueue.c 2009-03-24 14:22:44.000000000 +0100
14915 +++ linux-2.6.29.4-vs2.3.0.36.14/ipc/mqueue.c   2009-03-24 17:24:19.000000000 +0100
14916 @@ -31,6 +31,8 @@
14917  #include <linux/mutex.h>
14918  #include <linux/nsproxy.h>
14919  #include <linux/pid.h>
14920 +#include <linux/vs_context.h>
14921 +#include <linux/vs_limit.h>
14922  
14923  #include <net/sock.h>
14924  #include "util.h"
14925 @@ -79,6 +81,7 @@ struct mqueue_inode_info {
14926         struct sigevent notify;
14927         struct pid* notify_owner;
14928         struct user_struct *user;       /* user who created, for accounting */
14929 +       struct vx_info *vxi;
14930         struct sock *notify_sock;
14931         struct sk_buff *notify_cookie;
14932  
14933 @@ -126,6 +129,7 @@ static struct inode *mqueue_get_inode(st
14934                 if (S_ISREG(mode)) {
14935                         struct mqueue_inode_info *info;
14936                         struct task_struct *p = current;
14937 +                       struct vx_info *vxi = p->vx_info;
14938                         unsigned long mq_bytes, mq_msg_tblsz;
14939  
14940                         inode->i_fop = &mqueue_file_operations;
14941 @@ -140,6 +144,7 @@ static struct inode *mqueue_get_inode(st
14942                         info->notify_owner = NULL;
14943                         info->qsize = 0;
14944                         info->user = NULL;      /* set when all is ok */
14945 +                       info->vxi = NULL;
14946                         memset(&info->attr, 0, sizeof(info->attr));
14947                         info->attr.mq_maxmsg = msg_max;
14948                         info->attr.mq_msgsize = msgsize_max;
14949 @@ -154,22 +159,26 @@ static struct inode *mqueue_get_inode(st
14950                         spin_lock(&mq_lock);
14951                         if (u->mq_bytes + mq_bytes < u->mq_bytes ||
14952                             u->mq_bytes + mq_bytes >
14953 -                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur) {
14954 +                           p->signal->rlim[RLIMIT_MSGQUEUE].rlim_cur ||
14955 +                           !vx_ipcmsg_avail(vxi, mq_bytes)) {
14956                                 spin_unlock(&mq_lock);
14957                                 goto out_inode;
14958                         }
14959                         u->mq_bytes += mq_bytes;
14960 +                       vx_ipcmsg_add(vxi, u, mq_bytes);
14961                         spin_unlock(&mq_lock);
14962  
14963                         info->messages = kmalloc(mq_msg_tblsz, GFP_KERNEL);
14964                         if (!info->messages) {
14965                                 spin_lock(&mq_lock);
14966                                 u->mq_bytes -= mq_bytes;
14967 +                               vx_ipcmsg_sub(vxi, u, mq_bytes);
14968                                 spin_unlock(&mq_lock);
14969                                 goto out_inode;
14970                         }
14971                         /* all is ok */
14972                         info->user = get_uid(u);
14973 +                       info->vxi = get_vx_info(vxi);
14974                 } else if (S_ISDIR(mode)) {
14975                         inc_nlink(inode);
14976                         /* Some things misbehave if size == 0 on a directory */
14977 @@ -260,10 +269,14 @@ static void mqueue_delete_inode(struct i
14978                    (info->attr.mq_maxmsg * info->attr.mq_msgsize));
14979         user = info->user;
14980         if (user) {
14981 +               struct vx_info *vxi = info->vxi;
14982 +
14983                 spin_lock(&mq_lock);
14984                 user->mq_bytes -= mq_bytes;
14985 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
14986                 queues_count--;
14987                 spin_unlock(&mq_lock);
14988 +               put_vx_info(vxi);
14989                 free_uid(user);
14990         }
14991  }
14992 diff -NurpP --minimal linux-2.6.29.4/ipc/msg.c linux-2.6.29.4-vs2.3.0.36.14/ipc/msg.c
14993 --- linux-2.6.29.4/ipc/msg.c    2009-03-24 14:22:44.000000000 +0100
14994 +++ linux-2.6.29.4-vs2.3.0.36.14/ipc/msg.c      2009-02-22 22:54:26.000000000 +0100
14995 @@ -38,6 +38,7 @@
14996  #include <linux/rwsem.h>
14997  #include <linux/nsproxy.h>
14998  #include <linux/ipc_namespace.h>
14999 +#include <linux/vs_base.h>
15000  
15001  #include <asm/current.h>
15002  #include <asm/uaccess.h>
15003 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
15004  
15005         msq->q_perm.mode = msgflg & S_IRWXUGO;
15006         msq->q_perm.key = key;
15007 +       msq->q_perm.xid = vx_current_xid();
15008  
15009         msq->q_perm.security = NULL;
15010         retval = security_msg_queue_alloc(msq);
15011 diff -NurpP --minimal linux-2.6.29.4/ipc/namespace.c linux-2.6.29.4-vs2.3.0.36.14/ipc/namespace.c
15012 --- linux-2.6.29.4/ipc/namespace.c      2008-12-25 00:26:37.000000000 +0100
15013 +++ linux-2.6.29.4-vs2.3.0.36.14/ipc/namespace.c        2009-02-22 22:54:26.000000000 +0100
15014 @@ -9,6 +9,8 @@
15015  #include <linux/rcupdate.h>
15016  #include <linux/nsproxy.h>
15017  #include <linux/slab.h>
15018 +#include <linux/vs_base.h>
15019 +#include <linux/vserver/global.h>
15020  
15021  #include "util.h"
15022  
15023 @@ -35,6 +37,7 @@ static struct ipc_namespace *clone_ipc_n
15024         register_ipcns_notifier(ns);
15025  
15026         kref_init(&ns->kref);
15027 +       atomic_inc(&vs_global_ipc_ns);
15028         return ns;
15029  }
15030  
15031 @@ -101,6 +104,7 @@ void free_ipc_ns(struct kref *kref)
15032         sem_exit_ns(ns);
15033         msg_exit_ns(ns);
15034         shm_exit_ns(ns);
15035 +       atomic_dec(&vs_global_ipc_ns);
15036         kfree(ns);
15037         atomic_dec(&nr_ipc_ns);
15038  
15039 diff -NurpP --minimal linux-2.6.29.4/ipc/sem.c linux-2.6.29.4-vs2.3.0.36.14/ipc/sem.c
15040 --- linux-2.6.29.4/ipc/sem.c    2009-03-24 14:22:44.000000000 +0100
15041 +++ linux-2.6.29.4-vs2.3.0.36.14/ipc/sem.c      2009-03-31 23:31:33.000000000 +0200
15042 @@ -83,6 +83,8 @@
15043  #include <linux/rwsem.h>
15044  #include <linux/nsproxy.h>
15045  #include <linux/ipc_namespace.h>
15046 +#include <linux/vs_base.h>
15047 +#include <linux/vs_limit.h>
15048  
15049  #include <asm/uaccess.h>
15050  #include "util.h"
15051 @@ -255,6 +257,7 @@ static int newary(struct ipc_namespace *
15052  
15053         sma->sem_perm.mode = (semflg & S_IRWXUGO);
15054         sma->sem_perm.key = key;
15055 +       sma->sem_perm.xid = vx_current_xid();
15056  
15057         sma->sem_perm.security = NULL;
15058         retval = security_sem_alloc(sma);
15059 @@ -270,6 +273,9 @@ static int newary(struct ipc_namespace *
15060                 return id;
15061         }
15062         ns->used_sems += nsems;
15063 +       /* FIXME: obsoleted? */
15064 +       vx_semary_inc(sma);
15065 +       vx_nsems_add(sma, nsems);
15066  
15067         sma->sem_base = (struct sem *) &sma[1];
15068         INIT_LIST_HEAD(&sma->sem_pending);
15069 @@ -546,6 +552,9 @@ static void freeary(struct ipc_namespace
15070         sem_unlock(sma);
15071  
15072         ns->used_sems -= sma->sem_nsems;
15073 +       /* FIXME: obsoleted? */
15074 +       vx_nsems_sub(sma, sma->sem_nsems);
15075 +       vx_semary_dec(sma);
15076         security_sem_free(sma);
15077         ipc_rcu_putref(sma);
15078  }
15079 diff -NurpP --minimal linux-2.6.29.4/ipc/shm.c linux-2.6.29.4-vs2.3.0.36.14/ipc/shm.c
15080 --- linux-2.6.29.4/ipc/shm.c    2009-03-24 14:22:44.000000000 +0100
15081 +++ linux-2.6.29.4-vs2.3.0.36.14/ipc/shm.c      2009-03-24 14:48:36.000000000 +0100
15082 @@ -39,6 +39,8 @@
15083  #include <linux/nsproxy.h>
15084  #include <linux/mount.h>
15085  #include <linux/ipc_namespace.h>
15086 +#include <linux/vs_context.h>
15087 +#include <linux/vs_limit.h>
15088  
15089  #include <asm/uaccess.h>
15090  
15091 @@ -168,7 +170,12 @@ static void shm_open(struct vm_area_stru
15092   */
15093  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
15094  {
15095 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
15096 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
15097 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
15098 +
15099 +       vx_ipcshm_sub(vxi, shp, numpages);
15100 +       ns->shm_tot -= numpages;
15101 +
15102         shm_rmid(ns, shp);
15103         shm_unlock(shp);
15104         if (!is_file_hugepages(shp->shm_file))
15105 @@ -178,6 +185,7 @@ static void shm_destroy(struct ipc_names
15106                                                 shp->mlock_user);
15107         fput (shp->shm_file);
15108         security_shm_free(shp);
15109 +       put_vx_info(vxi);
15110         ipc_rcu_putref(shp);
15111  }
15112  
15113 @@ -348,11 +356,15 @@ static int newseg(struct ipc_namespace *
15114         if (ns->shm_tot + numpages > ns->shm_ctlall)
15115                 return -ENOSPC;
15116  
15117 +       if (!vx_ipcshm_avail(current->vx_info, numpages))
15118 +               return -ENOSPC;
15119 +
15120         shp = ipc_rcu_alloc(sizeof(*shp));
15121         if (!shp)
15122                 return -ENOMEM;
15123  
15124         shp->shm_perm.key = key;
15125 +       shp->shm_perm.xid = vx_current_xid();
15126         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
15127         shp->mlock_user = NULL;
15128  
15129 @@ -406,6 +418,7 @@ static int newseg(struct ipc_namespace *
15130         ns->shm_tot += numpages;
15131         error = shp->shm_perm.id;
15132         shm_unlock(shp);
15133 +       vx_ipcshm_add(current->vx_info, key, numpages);
15134         return error;
15135  
15136  no_id:
15137 diff -NurpP --minimal linux-2.6.29.4/kernel/capability.c linux-2.6.29.4-vs2.3.0.36.14/kernel/capability.c
15138 --- linux-2.6.29.4/kernel/capability.c  2009-03-24 14:22:44.000000000 +0100
15139 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/capability.c    2009-03-24 17:27:28.000000000 +0100
15140 @@ -14,6 +14,7 @@
15141  #include <linux/security.h>
15142  #include <linux/syscalls.h>
15143  #include <linux/pid_namespace.h>
15144 +#include <linux/vs_context.h>
15145  #include <asm/uaccess.h>
15146  #include "cred-internals.h"
15147  
15148 @@ -122,6 +123,7 @@ static int cap_validate_magic(cap_user_h
15149         return 0;
15150  }
15151  
15152 +
15153  /*
15154   * The only thing that can change the capabilities of the current
15155   * process is the current process. As such, we can't be in this code
15156 @@ -289,6 +291,8 @@ error:
15157         return ret;
15158  }
15159  
15160 +#include <linux/vserver/base.h>
15161 +
15162  /**
15163   * capable - Determine if the current task has a superior capability in effect
15164   * @cap: The capability to be tested for
15165 @@ -301,6 +305,9 @@ error:
15166   */
15167  int capable(int cap)
15168  {
15169 +       /* here for now so we don't require task locking */
15170 +       if (vs_check_bit(VXC_CAP_MASK, cap) && !vx_mcaps(1L << cap))
15171 +               return 0;
15172         if (unlikely(!cap_valid(cap))) {
15173                 printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
15174                 BUG();
15175 diff -NurpP --minimal linux-2.6.29.4/kernel/compat.c linux-2.6.29.4-vs2.3.0.36.14/kernel/compat.c
15176 --- linux-2.6.29.4/kernel/compat.c      2009-03-24 14:22:44.000000000 +0100
15177 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/compat.c        2009-03-24 14:48:36.000000000 +0100
15178 @@ -891,7 +891,7 @@ asmlinkage long compat_sys_time(compat_t
15179         compat_time_t i;
15180         struct timeval tv;
15181  
15182 -       do_gettimeofday(&tv);
15183 +       vx_gettimeofday(&tv);
15184         i = tv.tv_sec;
15185  
15186         if (tloc) {
15187 @@ -916,7 +916,7 @@ asmlinkage long compat_sys_stime(compat_
15188         if (err)
15189                 return err;
15190  
15191 -       do_settimeofday(&tv);
15192 +       vx_settimeofday(&tv);
15193         return 0;
15194  }
15195  
15196 diff -NurpP --minimal linux-2.6.29.4/kernel/exit.c linux-2.6.29.4-vs2.3.0.36.14/kernel/exit.c
15197 --- linux-2.6.29.4/kernel/exit.c        2009-05-23 23:16:53.000000000 +0200
15198 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/exit.c  2009-05-10 23:58:02.000000000 +0200
15199 @@ -47,6 +47,10 @@
15200  #include <linux/task_io_accounting_ops.h>
15201  #include <linux/tracehook.h>
15202  #include <linux/init_task.h>
15203 +#include <linux/vs_limit.h>
15204 +#include <linux/vs_context.h>
15205 +#include <linux/vs_network.h>
15206 +#include <linux/vs_pid.h>
15207  #include <trace/sched.h>
15208  
15209  #include <asm/uaccess.h>
15210 @@ -497,9 +501,11 @@ static void close_files(struct files_str
15211                                         filp_close(file, files);
15212                                         cond_resched();
15213                                 }
15214 +                               vx_openfd_dec(i);
15215                         }
15216                         i++;
15217                         set >>= 1;
15218 +                       cond_resched();
15219                 }
15220         }
15221  }
15222 @@ -1092,10 +1098,15 @@ NORET_TYPE void do_exit(long code)
15223         if (tsk->splice_pipe)
15224                 __free_pipe_info(tsk->splice_pipe);
15225  
15226 +       /* needs to stay after exit_notify() */
15227 +       exit_vx_info(tsk, code);
15228 +       exit_nx_info(tsk);
15229 +
15230         preempt_disable();
15231         /* causes final put_task_struct in finish_task_switch(). */
15232         tsk->state = TASK_DEAD;
15233         schedule();
15234 +       printk("bad task: %p [%lx]\n", current, current->state);
15235         BUG();
15236         /* Avoid "noreturn function does return".  */
15237         for (;;)
15238 diff -NurpP --minimal linux-2.6.29.4/kernel/fork.c linux-2.6.29.4-vs2.3.0.36.14/kernel/fork.c
15239 --- linux-2.6.29.4/kernel/fork.c        2009-05-23 23:16:53.000000000 +0200
15240 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/fork.c  2009-05-10 23:58:22.000000000 +0200
15241 @@ -60,6 +60,10 @@
15242  #include <linux/tty.h>
15243  #include <linux/proc_fs.h>
15244  #include <linux/blkdev.h>
15245 +#include <linux/vs_context.h>
15246 +#include <linux/vs_network.h>
15247 +#include <linux/vs_limit.h>
15248 +#include <linux/vs_memory.h>
15249  #include <trace/sched.h>
15250  
15251  #include <asm/pgtable.h>
15252 @@ -140,6 +144,8 @@ void free_task(struct task_struct *tsk)
15253         prop_local_destroy_single(&tsk->dirties);
15254         free_thread_info(tsk->stack);
15255         rt_mutex_debug_task_free(tsk);
15256 +       clr_vx_info(&tsk->vx_info);
15257 +       clr_nx_info(&tsk->nx_info);
15258         ftrace_graph_exit_task(tsk);
15259         free_task_struct(tsk);
15260  }
15261 @@ -279,6 +285,8 @@ static int dup_mmap(struct mm_struct *mm
15262         mm->free_area_cache = oldmm->mmap_base;
15263         mm->cached_hole_size = ~0UL;
15264         mm->map_count = 0;
15265 +       __set_mm_counter(mm, file_rss, 0);
15266 +       __set_mm_counter(mm, anon_rss, 0);
15267         cpus_clear(mm->cpu_vm_mask);
15268         mm->mm_rb = RB_ROOT;
15269         rb_link = &mm->mm_rb.rb_node;
15270 @@ -290,7 +298,7 @@ static int dup_mmap(struct mm_struct *mm
15271  
15272                 if (mpnt->vm_flags & VM_DONTCOPY) {
15273                         long pages = vma_pages(mpnt);
15274 -                       mm->total_vm -= pages;
15275 +                       vx_vmpages_sub(mm, pages);
15276                         vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
15277                                                                 -pages);
15278                         continue;
15279 @@ -423,8 +431,8 @@ static struct mm_struct * mm_init(struct
15280         mm->flags = (current->mm) ? current->mm->flags : default_dump_filter;
15281         mm->core_state = NULL;
15282         mm->nr_ptes = 0;
15283 -       set_mm_counter(mm, file_rss, 0);
15284 -       set_mm_counter(mm, anon_rss, 0);
15285 +       __set_mm_counter(mm, file_rss, 0);
15286 +       __set_mm_counter(mm, anon_rss, 0);
15287         spin_lock_init(&mm->page_table_lock);
15288         spin_lock_init(&mm->ioctx_lock);
15289         INIT_HLIST_HEAD(&mm->ioctx_list);
15290 @@ -435,6 +443,7 @@ static struct mm_struct * mm_init(struct
15291         if (likely(!mm_alloc_pgd(mm))) {
15292                 mm->def_flags = 0;
15293                 mmu_notifier_mm_init(mm);
15294 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
15295                 return mm;
15296         }
15297  
15298 @@ -468,6 +477,7 @@ void __mmdrop(struct mm_struct *mm)
15299         mm_free_pgd(mm);
15300         destroy_context(mm);
15301         mmu_notifier_mm_destroy(mm);
15302 +       clr_vx_info(&mm->mm_vx_info);
15303         free_mm(mm);
15304  }
15305  EXPORT_SYMBOL_GPL(__mmdrop);
15306 @@ -594,6 +604,7 @@ struct mm_struct *dup_mm(struct task_str
15307                 goto fail_nomem;
15308  
15309         memcpy(mm, oldmm, sizeof(*mm));
15310 +       mm->mm_vx_info = NULL;
15311  
15312         /* Initializing for Swap token stuff */
15313         mm->token_priority = 0;
15314 @@ -627,6 +638,7 @@ fail_nocontext:
15315          * If init_new_context() failed, we cannot use mmput() to free the mm
15316          * because it calls destroy_context()
15317          */
15318 +       clr_vx_info(&mm->mm_vx_info);
15319         mm_free_pgd(mm);
15320         free_mm(mm);
15321         return NULL;
15322 @@ -943,6 +955,8 @@ static struct task_struct *copy_process(
15323         int retval;
15324         struct task_struct *p;
15325         int cgroup_callbacks_done = 0;
15326 +       struct vx_info *vxi;
15327 +       struct nx_info *nxi;
15328  
15329         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
15330                 return ERR_PTR(-EINVAL);
15331 @@ -977,12 +991,28 @@ static struct task_struct *copy_process(
15332         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
15333         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
15334  #endif
15335 +       init_vx_info(&p->vx_info, current->vx_info);
15336 +       init_nx_info(&p->nx_info, current->nx_info);
15337 +
15338 +       /* check vserver memory */
15339 +       if (p->mm && !(clone_flags & CLONE_VM)) {
15340 +               if (vx_vmpages_avail(p->mm, p->mm->total_vm))
15341 +                       vx_pages_add(p->vx_info, RLIMIT_AS, p->mm->total_vm);
15342 +               else
15343 +                       goto bad_fork_free;
15344 +       }
15345 +       if (p->mm && vx_flags(VXF_FORK_RSS, 0)) {
15346 +               if (!vx_rss_avail(p->mm, get_mm_counter(p->mm, file_rss)))
15347 +                       goto bad_fork_cleanup_vm;
15348 +       }
15349         retval = -EAGAIN;
15350 +       if (!vx_nproc_avail(1))
15351 +               goto bad_fork_cleanup_vm;
15352         if (atomic_read(&p->real_cred->user->processes) >=
15353                         p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
15354                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
15355                     p->real_cred->user != INIT_USER)
15356 -                       goto bad_fork_free;
15357 +                       goto bad_fork_cleanup_vm;
15358         }
15359  
15360         retval = copy_creds(p, clone_flags);
15361 @@ -1259,6 +1289,18 @@ static struct task_struct *copy_process(
15362  
15363         total_forks++;
15364         spin_unlock(&current->sighand->siglock);
15365 +
15366 +       /* p is copy of current */
15367 +       vxi = p->vx_info;
15368 +       if (vxi) {
15369 +               claim_vx_info(vxi, p);
15370 +               atomic_inc(&vxi->cvirt.nr_threads);
15371 +               atomic_inc(&vxi->cvirt.total_forks);
15372 +               vx_nproc_inc(p);
15373 +       }
15374 +       nxi = p->nx_info;
15375 +       if (nxi)
15376 +               claim_nx_info(nxi, p);
15377         write_unlock_irq(&tasklist_lock);
15378         proc_fork_connector(p);
15379         cgroup_post_fork(p);
15380 @@ -1303,6 +1345,9 @@ bad_fork_cleanup_count:
15381         atomic_dec(&p->cred->user->processes);
15382         put_cred(p->real_cred);
15383         put_cred(p->cred);
15384 +bad_fork_cleanup_vm:
15385 +       if (p->mm && !(clone_flags & CLONE_VM))
15386 +               vx_pages_sub(p->vx_info, RLIMIT_AS, p->mm->total_vm);
15387  bad_fork_free:
15388         free_task(p);
15389  fork_out:
15390 diff -NurpP --minimal linux-2.6.29.4/kernel/kthread.c linux-2.6.29.4-vs2.3.0.36.14/kernel/kthread.c
15391 --- linux-2.6.29.4/kernel/kthread.c     2009-03-24 14:22:44.000000000 +0100
15392 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/kthread.c       2009-03-24 14:48:36.000000000 +0100
15393 @@ -13,6 +13,7 @@
15394  #include <linux/file.h>
15395  #include <linux/module.h>
15396  #include <linux/mutex.h>
15397 +#include <linux/vs_pid.h>
15398  #include <trace/sched.h>
15399  
15400  #define KTHREAD_NICE_LEVEL (-5)
15401 @@ -102,7 +103,7 @@ static void create_kthread(struct kthrea
15402                 struct sched_param param = { .sched_priority = 0 };
15403                 wait_for_completion(&create->started);
15404                 read_lock(&tasklist_lock);
15405 -               create->result = find_task_by_pid_ns(pid, &init_pid_ns);
15406 +               create->result = find_task_by_real_pid(pid);
15407                 read_unlock(&tasklist_lock);
15408                 /*
15409                  * root may have changed our (kthreadd's) priority or CPU mask.
15410 diff -NurpP --minimal linux-2.6.29.4/kernel/Makefile linux-2.6.29.4-vs2.3.0.36.14/kernel/Makefile
15411 --- linux-2.6.29.4/kernel/Makefile      2009-03-24 14:22:44.000000000 +0100
15412 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/Makefile        2009-03-24 14:48:36.000000000 +0100
15413 @@ -22,6 +22,7 @@ CFLAGS_REMOVE_cgroup-debug.o = -pg
15414  CFLAGS_REMOVE_sched_clock.o = -pg
15415  endif
15416  
15417 +obj-y += vserver/
15418  obj-$(CONFIG_FREEZER) += freezer.o
15419  obj-$(CONFIG_PROFILING) += profile.o
15420  obj-$(CONFIG_SYSCTL_SYSCALL_CHECK) += sysctl_check.o
15421 diff -NurpP --minimal linux-2.6.29.4/kernel/nsproxy.c linux-2.6.29.4-vs2.3.0.36.14/kernel/nsproxy.c
15422 --- linux-2.6.29.4/kernel/nsproxy.c     2009-03-24 14:22:44.000000000 +0100
15423 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/nsproxy.c       2009-03-25 00:39:02.000000000 +0100
15424 @@ -19,6 +19,8 @@
15425  #include <linux/mnt_namespace.h>
15426  #include <linux/utsname.h>
15427  #include <linux/pid_namespace.h>
15428 +#include <linux/vserver/global.h>
15429 +#include <linux/vserver/debug.h>
15430  #include <net/net_namespace.h>
15431  #include <linux/ipc_namespace.h>
15432  
15433 @@ -37,6 +39,9 @@ static inline struct nsproxy *clone_nspr
15434         if (ns) {
15435                 memcpy(ns, orig, sizeof(struct nsproxy));
15436                 atomic_set(&ns->count, 1);
15437 +               vxdprintk(VXD_CBIT(space, 2), "clone_nsproxy(%p[%u] = %p[1]",
15438 +                       orig, atomic_read(&orig->count), ns);
15439 +               atomic_inc(&vs_global_nsproxy);
15440         }
15441         return ns;
15442  }
15443 @@ -46,41 +51,52 @@ static inline struct nsproxy *clone_nspr
15444   * Return the newly created nsproxy.  Do not attach this to the task,
15445   * leave it to the caller to do proper locking and attach it to task.
15446   */
15447 -static struct nsproxy *create_new_namespaces(unsigned long flags,
15448 -                       struct task_struct *tsk, struct fs_struct *new_fs)
15449 +static struct nsproxy *unshare_namespaces(unsigned long flags,
15450 +                       struct nsproxy *orig, struct fs_struct *new_fs)
15451  {
15452         struct nsproxy *new_nsp;
15453         int err;
15454  
15455 -       new_nsp = clone_nsproxy(tsk->nsproxy);
15456 +       vxdprintk(VXD_CBIT(space, 4),
15457 +               "unshare_namespaces(0x%08lx,%p,%p)",
15458 +               flags, orig, new_fs);
15459 +
15460 +       new_nsp = clone_nsproxy(orig);
15461         if (!new_nsp)
15462                 return ERR_PTR(-ENOMEM);
15463  
15464 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, new_fs);
15465 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_fs);
15466         if (IS_ERR(new_nsp->mnt_ns)) {
15467                 err = PTR_ERR(new_nsp->mnt_ns);
15468                 goto out_ns;
15469         }
15470  
15471 -       new_nsp->uts_ns = copy_utsname(flags, tsk->nsproxy->uts_ns);
15472 +       new_nsp->uts_ns = copy_utsname(flags, orig->uts_ns);
15473         if (IS_ERR(new_nsp->uts_ns)) {
15474                 err = PTR_ERR(new_nsp->uts_ns);
15475                 goto out_uts;
15476         }
15477  
15478 -       new_nsp->ipc_ns = copy_ipcs(flags, tsk->nsproxy->ipc_ns);
15479 +       new_nsp->ipc_ns = copy_ipcs(flags, orig->ipc_ns);
15480         if (IS_ERR(new_nsp->ipc_ns)) {
15481                 err = PTR_ERR(new_nsp->ipc_ns);
15482                 goto out_ipc;
15483         }
15484  
15485 -       new_nsp->pid_ns = copy_pid_ns(flags, task_active_pid_ns(tsk));
15486 +       new_nsp->pid_ns = copy_pid_ns(flags, orig->pid_ns);
15487         if (IS_ERR(new_nsp->pid_ns)) {
15488                 err = PTR_ERR(new_nsp->pid_ns);
15489                 goto out_pid;
15490         }
15491  
15492 -       new_nsp->net_ns = copy_net_ns(flags, tsk->nsproxy->net_ns);
15493 +       /* disabled now?
15494 +       new_nsp->user_ns = copy_user_ns(flags, orig->user_ns);
15495 +       if (IS_ERR(new_nsp->user_ns)) {
15496 +               err = PTR_ERR(new_nsp->user_ns);
15497 +               goto out_user;
15498 +       } */
15499 +
15500 +       new_nsp->net_ns = copy_net_ns(flags, orig->net_ns);
15501         if (IS_ERR(new_nsp->net_ns)) {
15502                 err = PTR_ERR(new_nsp->net_ns);
15503                 goto out_net;
15504 @@ -105,6 +121,35 @@ out_ns:
15505         return ERR_PTR(err);
15506  }
15507  
15508 +static struct nsproxy *create_new_namespaces(int flags, struct task_struct *tsk,
15509 +                       struct fs_struct *new_fs)
15510 +{
15511 +       return unshare_namespaces(flags, tsk->nsproxy, new_fs);
15512 +}
15513 +
15514 +/*
15515 + * copies the nsproxy, setting refcount to 1, and grabbing a
15516 + * reference to all contained namespaces.
15517 + */
15518 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
15519 +{
15520 +       struct nsproxy *ns = clone_nsproxy(orig);
15521 +
15522 +       if (ns) {
15523 +               if (ns->mnt_ns)
15524 +                       get_mnt_ns(ns->mnt_ns);
15525 +               if (ns->uts_ns)
15526 +                       get_uts_ns(ns->uts_ns);
15527 +               if (ns->ipc_ns)
15528 +                       get_ipc_ns(ns->ipc_ns);
15529 +               if (ns->pid_ns)
15530 +                       get_pid_ns(ns->pid_ns);
15531 +               if (ns->net_ns)
15532 +                       get_net(ns->net_ns);
15533 +       }
15534 +       return ns;
15535 +}
15536 +
15537  /*
15538   * called from clone.  This now handles copy for nsproxy and all
15539   * namespaces therein.
15540 @@ -112,9 +157,12 @@ out_ns:
15541  int copy_namespaces(unsigned long flags, struct task_struct *tsk)
15542  {
15543         struct nsproxy *old_ns = tsk->nsproxy;
15544 -       struct nsproxy *new_ns;
15545 +       struct nsproxy *new_ns = NULL;
15546         int err = 0;
15547  
15548 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
15549 +               flags, tsk, old_ns);
15550 +
15551         if (!old_ns)
15552                 return 0;
15553  
15554 @@ -151,6 +199,9 @@ int copy_namespaces(unsigned long flags,
15555  
15556  out:
15557         put_nsproxy(old_ns);
15558 +       vxdprintk(VXD_CBIT(space, 3),
15559 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
15560 +               flags, tsk, old_ns, err, new_ns);
15561         return err;
15562  }
15563  
15564 @@ -164,7 +215,9 @@ void free_nsproxy(struct nsproxy *ns)
15565                 put_ipc_ns(ns->ipc_ns);
15566         if (ns->pid_ns)
15567                 put_pid_ns(ns->pid_ns);
15568 -       put_net(ns->net_ns);
15569 +       if (ns->net_ns)
15570 +               put_net(ns->net_ns);
15571 +       atomic_dec(&vs_global_nsproxy);
15572         kmem_cache_free(nsproxy_cachep, ns);
15573  }
15574  
15575 @@ -177,6 +230,10 @@ int unshare_nsproxy_namespaces(unsigned 
15576  {
15577         int err = 0;
15578  
15579 +       vxdprintk(VXD_CBIT(space, 4),
15580 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
15581 +               unshare_flags, current->nsproxy);
15582 +
15583         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
15584                                CLONE_NEWNET)))
15585                 return 0;
15586 diff -NurpP --minimal linux-2.6.29.4/kernel/pid.c linux-2.6.29.4-vs2.3.0.36.14/kernel/pid.c
15587 --- linux-2.6.29.4/kernel/pid.c 2009-03-24 14:22:44.000000000 +0100
15588 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/pid.c   2009-05-10 23:59:04.000000000 +0200
15589 @@ -36,6 +36,7 @@
15590  #include <linux/pid_namespace.h>
15591  #include <linux/init_task.h>
15592  #include <linux/syscalls.h>
15593 +#include <linux/vs_pid.h>
15594  
15595  #define pid_hashfn(nr, ns)     \
15596         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
15597 @@ -305,7 +306,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
15598  
15599  struct pid *find_vpid(int nr)
15600  {
15601 -       return find_pid_ns(nr, current->nsproxy->pid_ns);
15602 +       return find_pid_ns(vx_rmap_pid(nr), current->nsproxy->pid_ns);
15603  }
15604  EXPORT_SYMBOL_GPL(find_vpid);
15605  
15606 @@ -365,6 +366,9 @@ void transfer_pid(struct task_struct *ol
15607  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
15608  {
15609         struct task_struct *result = NULL;
15610 +
15611 +       if (type == PIDTYPE_REALPID)
15612 +               type = PIDTYPE_PID;
15613         if (pid) {
15614                 struct hlist_node *first;
15615                 first = rcu_dereference(pid->tasks[type].first);
15616 @@ -388,14 +392,14 @@ EXPORT_SYMBOL(find_task_by_pid_type_ns);
15617  
15618  struct task_struct *find_task_by_vpid(pid_t vnr)
15619  {
15620 -       return find_task_by_pid_type_ns(PIDTYPE_PID, vnr,
15621 +       return find_task_by_pid_type_ns(PIDTYPE_PID, vx_rmap_pid(vnr),
15622                         current->nsproxy->pid_ns);
15623  }
15624  EXPORT_SYMBOL(find_task_by_vpid);
15625  
15626  struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
15627  {
15628 -       return find_task_by_pid_type_ns(PIDTYPE_PID, nr, ns);
15629 +       return find_task_by_pid_type_ns(PIDTYPE_PID, vx_rmap_pid(nr), ns);
15630  }
15631  EXPORT_SYMBOL(find_task_by_pid_ns);
15632  
15633 @@ -431,7 +435,7 @@ struct pid *find_get_pid(pid_t nr)
15634  }
15635  EXPORT_SYMBOL_GPL(find_get_pid);
15636  
15637 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15638 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
15639  {
15640         struct upid *upid;
15641         pid_t nr = 0;
15642 @@ -444,6 +448,11 @@ pid_t pid_nr_ns(struct pid *pid, struct 
15643         return nr;
15644  }
15645  
15646 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
15647 +{
15648 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
15649 +}
15650 +
15651  pid_t pid_vnr(struct pid *pid)
15652  {
15653         return pid_nr_ns(pid, current->nsproxy->pid_ns);
15654 diff -NurpP --minimal linux-2.6.29.4/kernel/pid_namespace.c linux-2.6.29.4-vs2.3.0.36.14/kernel/pid_namespace.c
15655 --- linux-2.6.29.4/kernel/pid_namespace.c       2008-12-25 00:26:37.000000000 +0100
15656 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/pid_namespace.c 2009-02-22 22:54:26.000000000 +0100
15657 @@ -13,6 +13,7 @@
15658  #include <linux/syscalls.h>
15659  #include <linux/err.h>
15660  #include <linux/acct.h>
15661 +#include <linux/vserver/global.h>
15662  
15663  #define BITS_PER_PAGE          (PAGE_SIZE*8)
15664  
15665 @@ -85,6 +86,7 @@ static struct pid_namespace *create_pid_
15666                 goto out_free_map;
15667  
15668         kref_init(&ns->kref);
15669 +       atomic_inc(&vs_global_pid_ns);
15670         ns->level = level;
15671  
15672         set_bit(0, ns->pidmap[0].page);
15673 @@ -109,6 +111,7 @@ static void destroy_pid_namespace(struct
15674  
15675         for (i = 0; i < PIDMAP_ENTRIES; i++)
15676                 kfree(ns->pidmap[i].page);
15677 +       atomic_dec(&vs_global_pid_ns);
15678         kmem_cache_free(pid_ns_cachep, ns);
15679  }
15680  
15681 diff -NurpP --minimal linux-2.6.29.4/kernel/posix-timers.c linux-2.6.29.4-vs2.3.0.36.14/kernel/posix-timers.c
15682 --- linux-2.6.29.4/kernel/posix-timers.c        2009-03-24 14:22:44.000000000 +0100
15683 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/posix-timers.c  2009-05-06 21:28:16.000000000 +0200
15684 @@ -46,6 +46,7 @@
15685  #include <linux/wait.h>
15686  #include <linux/workqueue.h>
15687  #include <linux/module.h>
15688 +#include <linux/vs_context.h>
15689  
15690  /*
15691   * Management arrays for POSIX timers.  Timers are kept in slab memory
15692 @@ -321,6 +322,7 @@ int posix_timer_event(struct k_itimer *t
15693  {
15694         struct task_struct *task;
15695         int shared, ret = -1;
15696 +
15697         /*
15698          * FIXME: if ->sigq is queued we can race with
15699          * dequeue_signal()->do_schedule_next_timer().
15700 @@ -337,10 +339,18 @@ int posix_timer_event(struct k_itimer *t
15701         rcu_read_lock();
15702         task = pid_task(timr->it_pid, PIDTYPE_PID);
15703         if (task) {
15704 +               struct vx_info_save vxis;
15705 +               struct vx_info *vxi;
15706 +
15707 +               vxi = task_get_vx_info(task);
15708 +               enter_vx_info(vxi, &vxis);
15709                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
15710                 ret = send_sigqueue(timr->sigq, task, shared);
15711 +               leave_vx_info(&vxis);
15712 +               put_vx_info(vxi);
15713         }
15714         rcu_read_unlock();
15715 +
15716         /* If we failed to send the signal the timer stops. */
15717         return ret > 0;
15718  }
15719 diff -NurpP --minimal linux-2.6.29.4/kernel/printk.c linux-2.6.29.4-vs2.3.0.36.14/kernel/printk.c
15720 --- linux-2.6.29.4/kernel/printk.c      2009-03-24 14:22:44.000000000 +0100
15721 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/printk.c        2009-03-24 14:48:36.000000000 +0100
15722 @@ -32,6 +32,7 @@
15723  #include <linux/security.h>
15724  #include <linux/bootmem.h>
15725  #include <linux/syscalls.h>
15726 +#include <linux/vs_cvirt.h>
15727  
15728  #include <asm/uaccess.h>
15729  
15730 @@ -251,18 +252,13 @@ int do_syslog(int type, char __user *buf
15731         unsigned i, j, limit, count;
15732         int do_clear = 0;
15733         char c;
15734 -       int error = 0;
15735 +       int error;
15736  
15737         error = security_syslog(type);
15738         if (error)
15739                 return error;
15740  
15741 -       switch (type) {
15742 -       case 0:         /* Close log */
15743 -               break;
15744 -       case 1:         /* Open log */
15745 -               break;
15746 -       case 2:         /* Read from log */
15747 +       if ((type >= 2) && (type <= 4)) {
15748                 error = -EINVAL;
15749                 if (!buf || len < 0)
15750                         goto out;
15751 @@ -273,6 +269,16 @@ int do_syslog(int type, char __user *buf
15752                         error = -EFAULT;
15753                         goto out;
15754                 }
15755 +       }
15756 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
15757 +               return vx_do_syslog(type, buf, len);
15758 +
15759 +       switch (type) {
15760 +       case 0:         /* Close log */
15761 +               break;
15762 +       case 1:         /* Open log */
15763 +               break;
15764 +       case 2:         /* Read from log */
15765                 error = wait_event_interruptible(log_wait,
15766                                                         (log_start - log_end));
15767                 if (error)
15768 @@ -297,16 +303,6 @@ int do_syslog(int type, char __user *buf
15769                 do_clear = 1;
15770                 /* FALL THRU */
15771         case 3:         /* Read last kernel messages */
15772 -               error = -EINVAL;
15773 -               if (!buf || len < 0)
15774 -                       goto out;
15775 -               error = 0;
15776 -               if (!len)
15777 -                       goto out;
15778 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
15779 -                       error = -EFAULT;
15780 -                       goto out;
15781 -               }
15782                 count = len;
15783                 if (count > log_buf_len)
15784                         count = log_buf_len;
15785 diff -NurpP --minimal linux-2.6.29.4/kernel/ptrace.c linux-2.6.29.4-vs2.3.0.36.14/kernel/ptrace.c
15786 --- linux-2.6.29.4/kernel/ptrace.c      2009-05-23 23:16:53.000000000 +0200
15787 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/ptrace.c        2009-05-10 23:42:01.000000000 +0200
15788 @@ -21,6 +21,7 @@
15789  #include <linux/audit.h>
15790  #include <linux/pid_namespace.h>
15791  #include <linux/syscalls.h>
15792 +#include <linux/vs_context.h>
15793  
15794  #include <asm/pgtable.h>
15795  #include <asm/uaccess.h>
15796 @@ -159,6 +160,11 @@ int __ptrace_may_access(struct task_stru
15797                 dumpable = get_dumpable(task->mm);
15798         if (!dumpable && !capable(CAP_SYS_PTRACE))
15799                 return -EPERM;
15800 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_IDENT))
15801 +               return -EPERM;
15802 +       if (!vx_check(task->xid, VS_IDENT) &&
15803 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
15804 +               return -EACCES;
15805  
15806         return security_ptrace_may_access(task, mode);
15807  }
15808 @@ -596,6 +602,10 @@ SYSCALL_DEFINE4(ptrace, long, request, l
15809                 goto out;
15810         }
15811  
15812 +       ret = -EPERM;
15813 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
15814 +               goto out_put_task_struct;
15815 +
15816         if (request == PTRACE_ATTACH) {
15817                 ret = ptrace_attach(child);
15818                 /*
15819 diff -NurpP --minimal linux-2.6.29.4/kernel/sched.c linux-2.6.29.4-vs2.3.0.36.14/kernel/sched.c
15820 --- linux-2.6.29.4/kernel/sched.c       2009-05-23 23:16:53.000000000 +0200
15821 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/sched.c 2009-05-10 23:42:01.000000000 +0200
15822 @@ -72,6 +72,8 @@
15823  #include <linux/debugfs.h>
15824  #include <linux/ctype.h>
15825  #include <linux/ftrace.h>
15826 +#include <linux/vs_sched.h>
15827 +#include <linux/vs_cvirt.h>
15828  #include <trace/sched.h>
15829  
15830  #include <asm/tlb.h>
15831 @@ -617,6 +619,16 @@ struct rq {
15832  #endif
15833         struct hrtimer hrtick_timer;
15834  #endif
15835 +       unsigned long norm_time;
15836 +       unsigned long idle_time;
15837 +#ifdef CONFIG_VSERVER_IDLETIME
15838 +       int idle_skip;
15839 +#endif
15840 +#ifdef CONFIG_VSERVER_HARDCPU
15841 +       struct list_head hold_queue;
15842 +       unsigned long nr_onhold;
15843 +       int idle_tokens;
15844 +#endif
15845  
15846  #ifdef CONFIG_SCHEDSTATS
15847         /* latency stats */
15848 @@ -1713,6 +1725,7 @@ static void update_avg(u64 *avg, u64 sam
15849  
15850  static void enqueue_task(struct rq *rq, struct task_struct *p, int wakeup)
15851  {
15852 +       // BUG_ON(p->state & TASK_ONHOLD);
15853         sched_info_queued(p);
15854         p->sched_class->enqueue_task(rq, p, wakeup);
15855         p->se.on_rq = 1;
15856 @@ -1836,6 +1849,8 @@ static inline void check_class_changed(s
15857                 p->sched_class->prio_changed(rq, p, oldprio, running);
15858  }
15859  
15860 +#include "sched_mon.h"
15861 +
15862  #ifdef CONFIG_SMP
15863  
15864  /* Used instead of source_load when we know the type == 0 */
15865 @@ -1923,6 +1938,7 @@ migrate_task(struct task_struct *p, int 
15866  {
15867         struct rq *rq = task_rq(p);
15868  
15869 +       vxm_migrate_task(p, rq, dest_cpu);
15870         /*
15871          * If the task is not on a runqueue (and not running), then
15872          * it is sufficient to simply update the task's cpu field.
15873 @@ -2250,6 +2266,8 @@ static int sched_balance_self(int cpu, i
15874  
15875  #endif /* CONFIG_SMP */
15876  
15877 +#include "sched_hard.h"
15878 +
15879  /***
15880   * try_to_wake_up - wake up a thread
15881   * @p: the to-be-woken-up thread
15882 @@ -2294,6 +2312,13 @@ static int try_to_wake_up(struct task_st
15883         rq = task_rq_lock(p, &flags);
15884         update_rq_clock(rq);
15885         old_state = p->state;
15886 +
15887 +       /* we need to unhold suspended tasks */
15888 +       if (old_state & TASK_ONHOLD) {
15889 +               vx_unhold_task(p, rq);
15890 +               old_state = p->state;
15891 +       }
15892 +
15893         if (!(old_state & state))
15894                 goto out;
15895  
15896 @@ -2315,6 +2340,12 @@ static int try_to_wake_up(struct task_st
15897                 /* might preempt at this point */
15898                 rq = task_rq_lock(p, &flags);
15899                 old_state = p->state;
15900 +
15901 +       /* we need to unhold suspended tasks
15902 +       if (old_state & TASK_ONHOLD) {
15903 +               vx_unhold_task(p, rq);
15904 +               old_state = p->state;
15905 +       } */
15906                 if (!(old_state & state))
15907                         goto out;
15908                 if (p->se.on_rq)
15909 @@ -4226,16 +4257,19 @@ void account_user_time(struct task_struc
15910                        cputime_t cputime_scaled)
15911  {
15912         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
15913 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15914         cputime64_t tmp;
15915 +       int nice = (TASK_NICE(p) > 0);
15916  
15917         /* Add user time to process. */
15918         p->utime = cputime_add(p->utime, cputime);
15919         p->utimescaled = cputime_add(p->utimescaled, cputime_scaled);
15920 +       vx_account_user(vxi, cputime, nice);
15921         account_group_user_time(p, cputime);
15922  
15923         /* Add user time to cpustat. */
15924         tmp = cputime_to_cputime64(cputime);
15925 -       if (TASK_NICE(p) > 0)
15926 +       if (nice)
15927                 cpustat->nice = cputime64_add(cpustat->nice, tmp);
15928         else
15929                 cpustat->user = cputime64_add(cpustat->user, tmp);
15930 @@ -4279,6 +4313,7 @@ void account_system_time(struct task_str
15931                          cputime_t cputime, cputime_t cputime_scaled)
15932  {
15933         struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat;
15934 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
15935         cputime64_t tmp;
15936  
15937         if ((p->flags & PF_VCPU) && (irq_count() - hardirq_offset == 0)) {
15938 @@ -4289,6 +4324,7 @@ void account_system_time(struct task_str
15939         /* Add system time to process. */
15940         p->stime = cputime_add(p->stime, cputime);
15941         p->stimescaled = cputime_add(p->stimescaled, cputime_scaled);
15942 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
15943         account_group_system_time(p, cputime);
15944  
15945         /* Add system time to cpustat. */
15946 @@ -4644,6 +4680,11 @@ need_resched_nonpreemptible:
15947                 idle_balance(cpu, rq);
15948  
15949         prev->sched_class->put_prev_task(rq, prev);
15950 +
15951 +       vx_set_rq_time(rq, jiffies);    /* update time */
15952 +       vx_schedule(prev, rq, cpu);     /* hold if over limit */
15953 +       vx_try_unhold(rq, cpu);         /* unhold if refilled */
15954 +
15955         next = pick_next_task(rq, prev);
15956  
15957         if (likely(prev != next)) {
15958 @@ -5209,7 +5250,7 @@ SYSCALL_DEFINE1(nice, int, increment)
15959                 nice = 19;
15960  
15961         if (increment < 0 && !can_nice(current, nice))
15962 -               return -EPERM;
15963 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
15964  
15965         retval = security_task_setnice(current, nice);
15966         if (retval)
15967 @@ -8485,7 +8526,10 @@ void __init sched_init(void)
15968  
15969  #endif
15970  #endif /* CONFIG_FAIR_GROUP_SCHED */
15971 -
15972 +#ifdef CONFIG_VSERVER_HARDCPU
15973 +               INIT_LIST_HEAD(&rq->hold_queue);
15974 +               rq->nr_onhold = 0;
15975 +#endif
15976                 rq->rt.rt_runtime = def_rt_bandwidth.rt_runtime;
15977  #ifdef CONFIG_RT_GROUP_SCHED
15978                 INIT_LIST_HEAD(&rq->leaf_rt_rq_list);
15979 diff -NurpP --minimal linux-2.6.29.4/kernel/sched_fair.c linux-2.6.29.4-vs2.3.0.36.14/kernel/sched_fair.c
15980 --- linux-2.6.29.4/kernel/sched_fair.c  2009-03-24 14:22:45.000000000 +0100
15981 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/sched_fair.c    2009-03-24 14:48:36.000000000 +0100
15982 @@ -717,6 +717,9 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
15983         check_spread(cfs_rq, se);
15984         if (se != cfs_rq->curr)
15985                 __enqueue_entity(cfs_rq, se);
15986 +
15987 +       if (entity_is_task(se))
15988 +               vx_activate_task(task_of(se));
15989  }
15990  
15991  static void __clear_buddies(struct cfs_rq *cfs_rq, struct sched_entity *se)
15992 @@ -760,6 +763,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
15993  
15994         if (se != cfs_rq->curr)
15995                 __dequeue_entity(cfs_rq, se);
15996 +       if (entity_is_task(se))
15997 +               vx_deactivate_task(task_of(se));
15998         account_entity_dequeue(cfs_rq, se);
15999         update_min_vruntime(cfs_rq);
16000  }
16001 diff -NurpP --minimal linux-2.6.29.4/kernel/sched_hard.h linux-2.6.29.4-vs2.3.0.36.14/kernel/sched_hard.h
16002 --- linux-2.6.29.4/kernel/sched_hard.h  1970-01-01 01:00:00.000000000 +0100
16003 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/sched_hard.h    2009-02-22 22:54:26.000000000 +0100
16004 @@ -0,0 +1,353 @@
16005 +
16006 +#ifdef CONFIG_VSERVER_IDLELIMIT
16007 +
16008 +/*
16009 + * vx_idle_resched - reschedule after maxidle
16010 + */
16011 +static inline
16012 +void vx_idle_resched(struct rq *rq)
16013 +{
16014 +       /* maybe have a better criterion for paused */
16015 +       if (!--rq->idle_tokens && !list_empty(&rq->hold_queue))
16016 +               set_need_resched();
16017 +}
16018 +
16019 +#else /* !CONFIG_VSERVER_IDLELIMIT */
16020 +
16021 +#define vx_idle_resched(rq)
16022 +
16023 +#endif /* CONFIG_VSERVER_IDLELIMIT */
16024 +
16025 +
16026 +
16027 +#ifdef CONFIG_VSERVER_IDLETIME
16028 +
16029 +#define vx_set_rq_min_skip(rq, min)            \
16030 +       (rq)->idle_skip = (min)
16031 +
16032 +#define vx_save_min_skip(ret, min, val)                \
16033 +       __vx_save_min_skip(ret, min, val)
16034 +
16035 +static inline
16036 +void __vx_save_min_skip(int ret, int *min, int val)
16037 +{
16038 +       if (ret > -2)
16039 +               return;
16040 +       if ((*min > val) || !*min)
16041 +               *min = val;
16042 +}
16043 +
16044 +static inline
16045 +int vx_try_skip(struct rq *rq, int cpu)
16046 +{
16047 +       /* artificially advance time */
16048 +       if (rq->idle_skip > 0) {
16049 +               vxdprintk(list_empty(&rq->hold_queue),
16050 +                       "hold queue empty on cpu %d", cpu);
16051 +               rq->idle_time += rq->idle_skip;
16052 +               vxm_idle_skip(rq, cpu);
16053 +               return 1;
16054 +       }
16055 +       return 0;
16056 +}
16057 +
16058 +#else /* !CONFIG_VSERVER_IDLETIME */
16059 +
16060 +#define vx_set_rq_min_skip(rq, min)            \
16061 +       ({ int dummy = (min); dummy; })
16062 +
16063 +#define vx_save_min_skip(ret, min, val)
16064 +
16065 +static inline
16066 +int vx_try_skip(struct rq *rq, int cpu)
16067 +{
16068 +       return 0;
16069 +}
16070 +
16071 +#endif /* CONFIG_VSERVER_IDLETIME */
16072 +
16073 +
16074 +
16075 +#ifdef CONFIG_VSERVER_HARDCPU
16076 +
16077 +#define vx_set_rq_max_idle(rq, max)            \
16078 +       (rq)->idle_tokens = (max)
16079 +
16080 +#define vx_save_max_idle(ret, min, val)                \
16081 +       __vx_save_max_idle(ret, min, val)
16082 +
16083 +static inline
16084 +void __vx_save_max_idle(int ret, int *min, int val)
16085 +{
16086 +       if (*min > val)
16087 +               *min = val;
16088 +}
16089 +
16090 +
16091 +/*
16092 + * vx_hold_task - put a task on the hold queue
16093 + */
16094 +static inline
16095 +void vx_hold_task(struct task_struct *p, struct rq *rq)
16096 +{
16097 +       // printk("@ hold_task(%p[%lx])\n", p, p->state);
16098 +
16099 +       /* ignore dead/killed tasks */
16100 +       if (unlikely(p->state & (TASK_DEAD | TASK_WAKEKILL)))
16101 +               return;
16102 +
16103 +       /* ignore sleeping tasks */
16104 +       if (unlikely(p->state & TASK_NORMAL))
16105 +               return;
16106 +
16107 +       /* remove task from runqueue */
16108 +       if (likely(p->se.on_rq))
16109 +               dequeue_task(rq, p, 0);
16110 +       else
16111 +               printk("@ woops, task %p not on runqueue?\n", p);
16112 +
16113 +       p->state |= TASK_ONHOLD;
16114 +       /* a new one on hold */
16115 +       rq->nr_onhold++;
16116 +       vxm_hold_task(p, rq);
16117 +       list_add_tail(&p->hq, &rq->hold_queue);
16118 +       // list_add_tail(&p->run_list, &rq->hold_queue);
16119 +}
16120 +
16121 +/*
16122 + * vx_unhold_task - put a task back to the runqueue
16123 + */
16124 +static inline
16125 +void vx_unhold_task(struct task_struct *p, struct rq *rq)
16126 +{
16127 +       // printk("@ unhold_task(%p[%lx])\n", p, p->state);
16128 +       list_del_init(&p->hq);
16129 +       // list_del(&p->run_list);
16130 +       /* one less waiting */
16131 +       rq->nr_onhold--;
16132 +       p->state &= ~TASK_ONHOLD;
16133 +       enqueue_task(rq, p, 0);
16134 +       // ? inc_nr_running(p, rq);
16135 +       vxm_unhold_task(p, rq);
16136 +}
16137 +
16138 +/*
16139 + * vx_remove_hold - remove a task from the hold queue
16140 + */
16141 +static inline
16142 +void vx_remove_hold(struct task_struct *p, struct rq *rq)
16143 +{
16144 +       printk("@ remove_hold(%p[%lx])\n", p, p->state);
16145 +       list_del_init(&p->hq);
16146 +       // list_del(&p->run_list);
16147 +       /* one less waiting */
16148 +       rq->nr_onhold--;
16149 +       p->state &= ~TASK_ONHOLD;
16150 +}
16151 +
16152 +unsigned long nr_onhold(void)
16153 +{
16154 +       unsigned long i, sum = 0;
16155 +
16156 +       for_each_online_cpu(i)
16157 +               sum += cpu_rq(i)->nr_onhold;
16158 +
16159 +       return sum;
16160 +}
16161 +
16162 +
16163 +
16164 +static inline
16165 +int __vx_tokens_avail(struct _vx_sched_pc *sched_pc)
16166 +{
16167 +       return sched_pc->tokens;
16168 +}
16169 +
16170 +static inline
16171 +void __vx_consume_token(struct _vx_sched_pc *sched_pc)
16172 +{
16173 +       sched_pc->tokens--;
16174 +}
16175 +
16176 +static inline
16177 +int vx_need_resched(struct task_struct *p, int slice, int cpu)
16178 +{
16179 +       struct vx_info *vxi = p->vx_info;
16180 +
16181 +       if (vx_info_flags(vxi, VXF_SCHED_HARD|VXF_SCHED_PRIO, 0)) {
16182 +               struct _vx_sched_pc *sched_pc =
16183 +                       &vx_per_cpu(vxi, sched_pc, cpu);
16184 +               int tokens;
16185 +
16186 +               /* maybe we can simplify that to decrement
16187 +                  the token counter unconditional? */
16188 +
16189 +               if ((tokens = __vx_tokens_avail(sched_pc)) > 0)
16190 +                       __vx_consume_token(sched_pc);
16191 +
16192 +               /* for tokens > 0, one token was consumed */
16193 +               if (tokens < 2)
16194 +                       slice = 0;
16195 +       }
16196 +       vxm_need_resched(p, slice, cpu);
16197 +       return (slice == 0);
16198 +}
16199 +
16200 +
16201 +#define vx_set_rq_time(rq, time) do {  \
16202 +       rq->norm_time = time;           \
16203 +} while (0)
16204 +
16205 +
16206 +static inline
16207 +void vx_try_unhold(struct rq *rq, int cpu)
16208 +{
16209 +       struct vx_info *vxi = NULL;
16210 +       struct list_head *l, *n;
16211 +       int maxidle = HZ;
16212 +       int minskip = 0;
16213 +
16214 +       /* nothing to do? what about pause? */
16215 +       if (list_empty(&rq->hold_queue))
16216 +               return;
16217 +
16218 +       list_for_each_safe(l, n, &rq->hold_queue) {
16219 +               int ret, delta_min[2];
16220 +               struct _vx_sched_pc *sched_pc;
16221 +               struct task_struct *p;
16222 +
16223 +               p = list_entry(l, struct task_struct, hq);
16224 +               /* don't bother with same context */
16225 +               if (vxi == p->vx_info)
16226 +                       continue;
16227 +
16228 +               vxi = p->vx_info;
16229 +               /* ignore paused contexts */
16230 +               if (vx_info_flags(vxi, VXF_SCHED_PAUSE, 0))
16231 +                       continue;
16232 +
16233 +               sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
16234 +
16235 +               /* recalc tokens */
16236 +               vxm_sched_info(sched_pc, vxi, cpu);
16237 +               ret = vx_tokens_recalc(sched_pc,
16238 +                       &rq->norm_time, &rq->idle_time, delta_min);
16239 +               vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
16240 +
16241 +               if (ret > 0) {
16242 +                       /* we found a runable context */
16243 +                       vx_unhold_task(p, rq);
16244 +                       break;
16245 +               }
16246 +               vx_save_max_idle(ret, &maxidle, delta_min[0]);
16247 +               vx_save_min_skip(ret, &minskip, delta_min[1]);
16248 +       }
16249 +       vx_set_rq_max_idle(rq, maxidle);
16250 +       vx_set_rq_min_skip(rq, minskip);
16251 +       vxm_rq_max_min(rq, cpu);
16252 +}
16253 +
16254 +
16255 +static inline
16256 +int vx_schedule(struct task_struct *next, struct rq *rq, int cpu)
16257 +{
16258 +       struct vx_info *vxi = next->vx_info;
16259 +       struct _vx_sched_pc *sched_pc;
16260 +       int delta_min[2];
16261 +       int flags, ret;
16262 +
16263 +       if (!vxi)
16264 +               return 1;
16265 +
16266 +       flags = vxi->vx_flags;
16267 +
16268 +       if (unlikely(vs_check_flags(flags, VXF_SCHED_PAUSE, 0)))
16269 +               goto put_on_hold;
16270 +       if (!vs_check_flags(flags, VXF_SCHED_HARD | VXF_SCHED_PRIO, 0))
16271 +               return 1;
16272 +
16273 +       sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
16274 +#ifdef CONFIG_SMP
16275 +       /* update scheduler params */
16276 +       if (cpu_isset(cpu, vxi->sched.update)) {
16277 +               vx_update_sched_param(&vxi->sched, sched_pc);
16278 +               vxm_update_sched(sched_pc, vxi, cpu);
16279 +               cpu_clear(cpu, vxi->sched.update);
16280 +       }
16281 +#endif
16282 +       vxm_sched_info(sched_pc, vxi, cpu);
16283 +       ret  = vx_tokens_recalc(sched_pc,
16284 +               &rq->norm_time, &rq->idle_time, delta_min);
16285 +       vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
16286 +
16287 +       if (!vs_check_flags(flags, VXF_SCHED_HARD, 0))
16288 +               return 1;
16289 +
16290 +       if (unlikely(ret < 0)) {
16291 +               vx_save_max_idle(ret, &rq->idle_tokens, delta_min[0]);
16292 +               vx_save_min_skip(ret, &rq->idle_skip, delta_min[1]);
16293 +               vxm_rq_max_min(rq, cpu);
16294 +       put_on_hold:
16295 +               vx_hold_task(next, rq);
16296 +               return 0;
16297 +       }
16298 +       return 1;
16299 +}
16300 +
16301 +
16302 +#else /* CONFIG_VSERVER_HARDCPU */
16303 +
16304 +static inline
16305 +void vx_hold_task(struct task_struct *p, struct rq *rq)
16306 +{
16307 +       return;
16308 +}
16309 +
16310 +static inline
16311 +void vx_unhold_task(struct task_struct *p, struct rq *rq)
16312 +{
16313 +       return;
16314 +}
16315 +
16316 +unsigned long nr_onhold(void)
16317 +{
16318 +       return 0;
16319 +}
16320 +
16321 +
16322 +static inline
16323 +int vx_need_resched(struct task_struct *p, int slice, int cpu)
16324 +{
16325 +       return (slice == 0);
16326 +}
16327 +
16328 +
16329 +#define vx_set_rq_time(rq, time)
16330 +
16331 +static inline
16332 +void vx_try_unhold(struct rq *rq, int cpu)
16333 +{
16334 +       return;
16335 +}
16336 +
16337 +static inline
16338 +int vx_schedule(struct task_struct *next, struct rq *rq, int cpu)
16339 +{
16340 +       struct vx_info *vxi = next->vx_info;
16341 +       struct _vx_sched_pc *sched_pc;
16342 +       int delta_min[2];
16343 +       int ret;
16344 +
16345 +       if (!vx_info_flags(vxi, VXF_SCHED_PRIO, 0))
16346 +               return 1;
16347 +
16348 +       sched_pc = &vx_per_cpu(vxi, sched_pc, cpu);
16349 +       vxm_sched_info(sched_pc, vxi, cpu);
16350 +       ret  = vx_tokens_recalc(sched_pc,
16351 +               &rq->norm_time, &rq->idle_time, delta_min);
16352 +       vxm_tokens_recalc(sched_pc, rq, vxi, cpu);
16353 +       return 1;
16354 +}
16355 +
16356 +#endif /* CONFIG_VSERVER_HARDCPU */
16357 +
16358 diff -NurpP --minimal linux-2.6.29.4/kernel/sched_mon.h linux-2.6.29.4-vs2.3.0.36.14/kernel/sched_mon.h
16359 --- linux-2.6.29.4/kernel/sched_mon.h   1970-01-01 01:00:00.000000000 +0100
16360 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/sched_mon.h     2009-02-22 22:54:26.000000000 +0100
16361 @@ -0,0 +1,200 @@
16362 +
16363 +#include <linux/vserver/monitor.h>
16364 +
16365 +#ifdef  CONFIG_VSERVER_MONITOR
16366 +
16367 +#ifdef CONFIG_VSERVER_HARDCPU
16368 +#define HARDCPU(x) (x)
16369 +#else
16370 +#define HARDCPU(x) (0)
16371 +#endif
16372 +
16373 +#ifdef CONFIG_VSERVER_IDLETIME
16374 +#define IDLETIME(x) (x)
16375 +#else
16376 +#define IDLETIME(x) (0)
16377 +#endif
16378 +
16379 +struct _vx_mon_entry *vxm_advance(int cpu);
16380 +
16381 +
16382 +static inline
16383 +void   __vxm_basic(struct _vx_mon_entry *entry, xid_t xid, int type)
16384 +{
16385 +       entry->type = type;
16386 +       entry->xid = xid;
16387 +}
16388 +
16389 +static inline
16390 +void   __vxm_sync(int cpu)
16391 +{
16392 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16393 +
16394 +       __vxm_basic(entry, 0, VXM_SYNC);
16395 +       entry->ev.sec = xtime.tv_sec;
16396 +       entry->ev.nsec = xtime.tv_nsec;
16397 +}
16398 +
16399 +static inline
16400 +void   __vxm_task(struct task_struct *p, int type)
16401 +{
16402 +       struct _vx_mon_entry *entry = vxm_advance(task_cpu(p));
16403 +
16404 +       __vxm_basic(entry, p->xid, type);
16405 +       entry->ev.tsk.pid = p->pid;
16406 +       entry->ev.tsk.state = p->state;
16407 +}
16408 +
16409 +static inline
16410 +void   __vxm_sched(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16411 +{
16412 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16413 +
16414 +       __vxm_basic(entry, vxi->vx_id, (VXM_SCHED | s->flags));
16415 +       entry->sd.tokens = s->tokens;
16416 +       entry->sd.norm_time = s->norm_time;
16417 +       entry->sd.idle_time = s->idle_time;
16418 +}
16419 +
16420 +static inline
16421 +void   __vxm_rqinfo1(struct rq *q, int cpu)
16422 +{
16423 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16424 +
16425 +       entry->type = VXM_RQINFO_1;
16426 +       entry->xid = ((unsigned long)q >> 16) & 0xffff;
16427 +       entry->q1.running = q->nr_running;
16428 +       entry->q1.onhold = HARDCPU(q->nr_onhold);
16429 +       entry->q1.iowait = atomic_read(&q->nr_iowait);
16430 +       entry->q1.uintr = q->nr_uninterruptible;
16431 +       entry->q1.idle_tokens = IDLETIME(q->idle_tokens);
16432 +}
16433 +
16434 +static inline
16435 +void   __vxm_rqinfo2(struct rq *q, int cpu)
16436 +{
16437 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16438 +
16439 +       entry->type = VXM_RQINFO_2;
16440 +       entry->xid = (unsigned long)q & 0xffff;
16441 +       entry->q2.norm_time = q->norm_time;
16442 +       entry->q2.idle_time = q->idle_time;
16443 +       entry->q2.idle_skip = IDLETIME(q->idle_skip);
16444 +}
16445 +
16446 +static inline
16447 +void   __vxm_update(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16448 +{
16449 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16450 +
16451 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE);
16452 +       entry->ev.tokens = s->tokens;
16453 +}
16454 +
16455 +static inline
16456 +void   __vxm_update1(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16457 +{
16458 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16459 +
16460 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE_1);
16461 +       entry->u1.tokens_max = s->tokens_max;
16462 +       entry->u1.fill_rate = s->fill_rate[0];
16463 +       entry->u1.interval = s->interval[0];
16464 +}
16465 +
16466 +static inline
16467 +void   __vxm_update2(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16468 +{
16469 +       struct _vx_mon_entry *entry = vxm_advance(cpu);
16470 +
16471 +       __vxm_basic(entry, vxi->vx_id, VXM_UPDATE_2);
16472 +       entry->u2.tokens_min = s->tokens_min;
16473 +       entry->u2.fill_rate = s->fill_rate[1];
16474 +       entry->u2.interval = s->interval[1];
16475 +}
16476 +
16477 +
16478 +#define        vxm_activate_task(p,q)          __vxm_task(p, VXM_ACTIVATE)
16479 +#define        vxm_activate_idle(p,q)          __vxm_task(p, VXM_IDLE)
16480 +#define        vxm_deactivate_task(p,q)        __vxm_task(p, VXM_DEACTIVATE)
16481 +#define        vxm_hold_task(p,q)              __vxm_task(p, VXM_HOLD)
16482 +#define        vxm_unhold_task(p,q)            __vxm_task(p, VXM_UNHOLD)
16483 +
16484 +static inline
16485 +void   vxm_migrate_task(struct task_struct *p, struct rq *rq, int dest)
16486 +{
16487 +       __vxm_task(p, VXM_MIGRATE);
16488 +       __vxm_rqinfo1(rq, task_cpu(p));
16489 +       __vxm_rqinfo2(rq, task_cpu(p));
16490 +}
16491 +
16492 +static inline
16493 +void   vxm_idle_skip(struct rq *rq, int cpu)
16494 +{
16495 +       __vxm_rqinfo1(rq, cpu);
16496 +       __vxm_rqinfo2(rq, cpu);
16497 +}
16498 +
16499 +static inline
16500 +void   vxm_need_resched(struct task_struct *p, int slice, int cpu)
16501 +{
16502 +       if (slice)
16503 +               return;
16504 +
16505 +       __vxm_task(p, VXM_RESCHED);
16506 +}
16507 +
16508 +static inline
16509 +void   vxm_sync(unsigned long now, int cpu)
16510 +{
16511 +       if (!CONFIG_VSERVER_MONITOR_SYNC ||
16512 +               (now % CONFIG_VSERVER_MONITOR_SYNC))
16513 +               return;
16514 +
16515 +       __vxm_sync(cpu);
16516 +}
16517 +
16518 +#define        vxm_sched_info(s,v,c)           __vxm_sched(s,v,c)
16519 +
16520 +static inline
16521 +void   vxm_tokens_recalc(struct _vx_sched_pc *s, struct rq *rq,
16522 +       struct vx_info *vxi, int cpu)
16523 +{
16524 +       __vxm_sched(s, vxi, cpu);
16525 +       __vxm_rqinfo2(rq, cpu);
16526 +}
16527 +
16528 +static inline
16529 +void   vxm_update_sched(struct _vx_sched_pc *s, struct vx_info *vxi, int cpu)
16530 +{
16531 +       __vxm_sched(s, vxi, cpu);
16532 +       __vxm_update(s, vxi, cpu);
16533 +       __vxm_update1(s, vxi, cpu);
16534 +       __vxm_update2(s, vxi, cpu);
16535 +}
16536 +
16537 +static inline
16538 +void   vxm_rq_max_min(struct rq *rq, int cpu)
16539 +{
16540 +       __vxm_rqinfo1(rq, cpu);
16541 +       __vxm_rqinfo2(rq, cpu);
16542 +}
16543 +
16544 +#else  /* CONFIG_VSERVER_MONITOR */
16545 +
16546 +#define        vxm_activate_task(t,q)          do { } while (0)
16547 +#define        vxm_activate_idle(t,q)          do { } while (0)
16548 +#define        vxm_deactivate_task(t,q)        do { } while (0)
16549 +#define        vxm_hold_task(t,q)              do { } while (0)
16550 +#define        vxm_unhold_task(t,q)            do { } while (0)
16551 +#define        vxm_migrate_task(t,q,d)         do { } while (0)
16552 +#define        vxm_idle_skip(q,c)              do { } while (0)
16553 +#define        vxm_need_resched(t,s,c)         do { } while (0)
16554 +#define        vxm_sync(s,c)                   do { } while (0)
16555 +#define        vxm_sched_info(s,v,c)           do { } while (0)
16556 +#define        vxm_tokens_recalc(s,q,v,c)      do { } while (0)
16557 +#define        vxm_update_sched(s,v,c)         do { } while (0)
16558 +#define        vxm_rq_max_min(q,c)             do { } while (0)
16559 +
16560 +#endif /* CONFIG_VSERVER_MONITOR */
16561 +
16562 diff -NurpP --minimal linux-2.6.29.4/kernel/signal.c linux-2.6.29.4-vs2.3.0.36.14/kernel/signal.c
16563 --- linux-2.6.29.4/kernel/signal.c      2009-03-24 14:22:45.000000000 +0100
16564 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/signal.c        2009-04-20 23:37:12.000000000 +0200
16565 @@ -27,6 +27,8 @@
16566  #include <linux/freezer.h>
16567  #include <linux/pid_namespace.h>
16568  #include <linux/nsproxy.h>
16569 +#include <linux/vs_context.h>
16570 +#include <linux/vs_pid.h>
16571  #include <trace/sched.h>
16572  
16573  #include <asm/param.h>
16574 @@ -584,6 +586,14 @@ static int check_kill_permission(int sig
16575         if (!valid_signal(sig))
16576                 return -EINVAL;
16577  
16578 +       if ((info != SEND_SIG_NOINFO) &&
16579 +               (is_si_special(info) || !SI_FROMUSER(info)))
16580 +               goto skip;
16581 +
16582 +       vxdprintk(VXD_CBIT(misc, 7),
16583 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
16584 +               sig, info, t, vx_task_xid(t), t->pid);
16585 +
16586         if (info != SEND_SIG_NOINFO && (is_si_special(info) || SI_FROMKERNEL(info)))
16587                 return 0;
16588  
16589 @@ -611,6 +621,20 @@ static int check_kill_permission(int sig
16590                 }
16591         }
16592  
16593 +       error = -EPERM;
16594 +       if (t->pid == 1 && current->xid)
16595 +               return error;
16596 +
16597 +       error = -ESRCH;
16598 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
16599 +                 loops, maybe ENOENT or EACCES? */
16600 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
16601 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
16602 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
16603 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
16604 +               return error;
16605 +       }
16606 +skip:
16607         return security_task_kill(t, info, sig, 0);
16608  }
16609  
16610 @@ -1076,7 +1100,7 @@ int kill_pid_info(int sig, struct siginf
16611         rcu_read_lock();
16612  retry:
16613         p = pid_task(pid, PIDTYPE_PID);
16614 -       if (p) {
16615 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
16616                 error = group_send_sig_info(sig, info, p);
16617                 if (unlikely(error == -ESRCH))
16618                         /*
16619 @@ -1115,7 +1139,7 @@ int kill_pid_info_as_uid(int sig, struct
16620  
16621         read_lock(&tasklist_lock);
16622         p = pid_task(pid, PIDTYPE_PID);
16623 -       if (!p) {
16624 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
16625                 ret = -ESRCH;
16626                 goto out_unlock;
16627         }
16628 @@ -1169,8 +1193,10 @@ static int kill_something_info(int sig, 
16629                 struct task_struct * p;
16630  
16631                 for_each_process(p) {
16632 -                       if (task_pid_vnr(p) > 1 &&
16633 -                                       !same_thread_group(p, current)) {
16634 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
16635 +                               task_pid_vnr(p) > 1 &&
16636 +                               !same_thread_group(p, current) &&
16637 +                               !vx_current_initpid(p->pid)) {
16638                                 int err = group_send_sig_info(sig, info, p);
16639                                 ++count;
16640                                 if (err != -EPERM)
16641 @@ -1849,6 +1875,11 @@ relock:
16642                     !signal_group_exit(signal))
16643                         continue;
16644  
16645 +               /* virtual init is protected against user signals */
16646 +               if ((info->si_code == SI_USER) &&
16647 +                       vx_current_initpid(current->pid))
16648 +                       continue;
16649 +
16650                 if (sig_kernel_stop(signr)) {
16651                         /*
16652                          * The default action is to stop all threads in
16653 diff -NurpP --minimal linux-2.6.29.4/kernel/softirq.c linux-2.6.29.4-vs2.3.0.36.14/kernel/softirq.c
16654 --- linux-2.6.29.4/kernel/softirq.c     2009-05-23 23:16:53.000000000 +0200
16655 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/softirq.c       2009-04-30 12:14:53.000000000 +0200
16656 @@ -23,6 +23,7 @@
16657  #include <linux/rcupdate.h>
16658  #include <linux/smp.h>
16659  #include <linux/tick.h>
16660 +#include <linux/vs_context.h>
16661  
16662  #include <asm/irq.h>
16663  /*
16664 diff -NurpP --minimal linux-2.6.29.4/kernel/sys.c linux-2.6.29.4-vs2.3.0.36.14/kernel/sys.c
16665 --- linux-2.6.29.4/kernel/sys.c 2009-03-24 14:22:45.000000000 +0100
16666 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/sys.c   2009-03-24 14:48:36.000000000 +0100
16667 @@ -39,6 +39,7 @@
16668  #include <linux/syscalls.h>
16669  #include <linux/kprobes.h>
16670  #include <linux/user_namespace.h>
16671 +#include <linux/vs_pid.h>
16672  
16673  #include <asm/uaccess.h>
16674  #include <asm/io.h>
16675 @@ -128,7 +129,10 @@ static int set_one_prio(struct task_stru
16676                 goto out;
16677         }
16678         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
16679 -               error = -EACCES;
16680 +               if (vx_flags(VXF_IGNEG_NICE, 0))
16681 +                       error = 0;
16682 +               else
16683 +                       error = -EACCES;
16684                 goto out;
16685         }
16686         no_nice = security_task_setnice(p, niceval);
16687 @@ -177,6 +181,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
16688                         else
16689                                 pgrp = task_pgrp(current);
16690                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
16691 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
16692 +                                       continue;
16693                                 error = set_one_prio(p, niceval, error);
16694                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
16695                         break;
16696 @@ -238,6 +244,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
16697                         else
16698                                 pgrp = task_pgrp(current);
16699                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
16700 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
16701 +                                       continue;
16702                                 niceval = 20 - task_nice(p);
16703                                 if (niceval > retval)
16704                                         retval = niceval;
16705 @@ -347,6 +355,9 @@ void kernel_power_off(void)
16706         machine_power_off();
16707  }
16708  EXPORT_SYMBOL_GPL(kernel_power_off);
16709 +
16710 +long vs_reboot(unsigned int, void __user *);
16711 +
16712  /*
16713   * Reboot system call: for obvious reasons only root may call it,
16714   * and even root needs to set up some magic numbers in the registers
16715 @@ -378,6 +389,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
16716         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
16717                 cmd = LINUX_REBOOT_CMD_HALT;
16718  
16719 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
16720 +               return vs_reboot(cmd, arg);
16721 +
16722         lock_kernel();
16723         switch (cmd) {
16724         case LINUX_REBOOT_CMD_RESTART:
16725 @@ -1420,7 +1434,7 @@ SYSCALL_DEFINE2(sethostname, char __user
16726         int errno;
16727         char tmp[__NEW_UTS_LEN];
16728  
16729 -       if (!capable(CAP_SYS_ADMIN))
16730 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
16731                 return -EPERM;
16732         if (len < 0 || len > __NEW_UTS_LEN)
16733                 return -EINVAL;
16734 @@ -1469,7 +1483,7 @@ SYSCALL_DEFINE2(setdomainname, char __us
16735         int errno;
16736         char tmp[__NEW_UTS_LEN];
16737  
16738 -       if (!capable(CAP_SYS_ADMIN))
16739 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_SET_UTSNAME))
16740                 return -EPERM;
16741         if (len < 0 || len > __NEW_UTS_LEN)
16742                 return -EINVAL;
16743 @@ -1538,7 +1552,7 @@ SYSCALL_DEFINE2(setrlimit, unsigned int,
16744                 return -EINVAL;
16745         old_rlim = current->signal->rlim + resource;
16746         if ((new_rlim.rlim_max > old_rlim->rlim_max) &&
16747 -           !capable(CAP_SYS_RESOURCE))
16748 +           !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
16749                 return -EPERM;
16750         if (resource == RLIMIT_NOFILE && new_rlim.rlim_max > sysctl_nr_open)
16751                 return -EPERM;
16752 diff -NurpP --minimal linux-2.6.29.4/kernel/sysctl.c linux-2.6.29.4-vs2.3.0.36.14/kernel/sysctl.c
16753 --- linux-2.6.29.4/kernel/sysctl.c      2009-05-23 23:16:53.000000000 +0200
16754 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/sysctl.c        2009-04-30 12:14:53.000000000 +0200
16755 @@ -111,6 +111,7 @@ static int ngroups_max = NGROUPS_MAX;
16756  #ifdef CONFIG_MODULES
16757  extern char modprobe_path[];
16758  #endif
16759 +extern char vshelper_path[];
16760  #ifdef CONFIG_CHR_DEV_SG
16761  extern int sg_big_buff;
16762  #endif
16763 @@ -542,6 +543,15 @@ static struct ctl_table kern_table[] = {
16764                 .strategy       = &sysctl_string,
16765         },
16766  #endif
16767 +       {
16768 +               .ctl_name       = KERN_VSHELPER,
16769 +               .procname       = "vshelper",
16770 +               .data           = &vshelper_path,
16771 +               .maxlen         = 256,
16772 +               .mode           = 0644,
16773 +               .proc_handler   = &proc_dostring,
16774 +               .strategy       = &sysctl_string,
16775 +       },
16776  #ifdef CONFIG_CHR_DEV_SG
16777         {
16778                 .ctl_name       = KERN_SG_BIG_BUFF,
16779 diff -NurpP --minimal linux-2.6.29.4/kernel/sysctl_check.c linux-2.6.29.4-vs2.3.0.36.14/kernel/sysctl_check.c
16780 --- linux-2.6.29.4/kernel/sysctl_check.c        2009-03-24 14:22:45.000000000 +0100
16781 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/sysctl_check.c  2009-03-24 14:48:36.000000000 +0100
16782 @@ -39,6 +39,7 @@ static const struct trans_ctl_table tran
16783  
16784         { KERN_PANIC,                   "panic" },
16785         { KERN_REALROOTDEV,             "real-root-dev" },
16786 +       { KERN_VSHELPER,                "vshelper", },
16787  
16788         { KERN_SPARC_REBOOT,            "reboot-cmd" },
16789         { KERN_CTLALTDEL,               "ctrl-alt-del" },
16790 @@ -1216,6 +1217,22 @@ static const struct trans_ctl_table tran
16791         {}
16792  };
16793  
16794 +static struct trans_ctl_table trans_vserver_table[] = {
16795 +       { 1,    "debug_switch" },
16796 +       { 2,    "debug_xid" },
16797 +       { 3,    "debug_nid" },
16798 +       { 4,    "debug_tag" },
16799 +       { 5,    "debug_net" },
16800 +       { 6,    "debug_limit" },
16801 +       { 7,    "debug_cres" },
16802 +       { 8,    "debug_dlim" },
16803 +       { 9,    "debug_quota" },
16804 +       { 10,   "debug_cvirt" },
16805 +       { 11,   "debug_space" },
16806 +       { 12,   "debug_misc" },
16807 +       {}
16808 +};
16809 +
16810  static const struct trans_ctl_table trans_root_table[] = {
16811         { CTL_KERN,     "kernel",       trans_kern_table },
16812         { CTL_VM,       "vm",           trans_vm_table },
16813 @@ -1232,6 +1249,7 @@ static const struct trans_ctl_table tran
16814         { CTL_SUNRPC,   "sunrpc",       trans_sunrpc_table },
16815         { CTL_PM,       "pm",           trans_pm_table },
16816         { CTL_FRV,      "frv",          trans_frv_table },
16817 +       { CTL_VSERVER,  "vserver",      trans_vserver_table },
16818         {}
16819  };
16820  
16821 diff -NurpP --minimal linux-2.6.29.4/kernel/time.c linux-2.6.29.4-vs2.3.0.36.14/kernel/time.c
16822 --- linux-2.6.29.4/kernel/time.c        2009-03-24 14:22:45.000000000 +0100
16823 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/time.c  2009-03-24 14:48:36.000000000 +0100
16824 @@ -63,6 +63,7 @@ EXPORT_SYMBOL(sys_tz);
16825  SYSCALL_DEFINE1(time, time_t __user *, tloc)
16826  {
16827         time_t i = get_seconds();
16828 +/*     FIXME: do_gettimeofday(&tv) -> vx_gettimeofday(&tv) */
16829  
16830         if (tloc) {
16831                 if (put_user(i,tloc))
16832 @@ -93,7 +94,7 @@ SYSCALL_DEFINE1(stime, time_t __user *, 
16833         if (err)
16834                 return err;
16835  
16836 -       do_settimeofday(&tv);
16837 +       vx_settimeofday(&tv);
16838         return 0;
16839  }
16840  
16841 @@ -104,7 +105,7 @@ SYSCALL_DEFINE2(gettimeofday, struct tim
16842  {
16843         if (likely(tv != NULL)) {
16844                 struct timeval ktv;
16845 -               do_gettimeofday(&ktv);
16846 +               vx_gettimeofday(&ktv);
16847                 if (copy_to_user(tv, &ktv, sizeof(ktv)))
16848                         return -EFAULT;
16849         }
16850 @@ -179,7 +180,7 @@ int do_sys_settimeofday(struct timespec 
16851                 /* SMP safe, again the code in arch/foo/time.c should
16852                  * globally block out interrupts when it runs.
16853                  */
16854 -               return do_settimeofday(tv);
16855 +               return vx_settimeofday(tv);
16856         }
16857         return 0;
16858  }
16859 @@ -311,7 +312,7 @@ void getnstimeofday(struct timespec *tv)
16860  {
16861         struct timeval x;
16862  
16863 -       do_gettimeofday(&x);
16864 +       vx_gettimeofday(&x);
16865         tv->tv_sec = x.tv_sec;
16866         tv->tv_nsec = x.tv_usec * NSEC_PER_USEC;
16867  }
16868 diff -NurpP --minimal linux-2.6.29.4/kernel/timer.c linux-2.6.29.4-vs2.3.0.36.14/kernel/timer.c
16869 --- linux-2.6.29.4/kernel/timer.c       2009-03-24 14:22:45.000000000 +0100
16870 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/timer.c 2009-03-24 17:41:02.000000000 +0100
16871 @@ -37,6 +37,10 @@
16872  #include <linux/delay.h>
16873  #include <linux/tick.h>
16874  #include <linux/kallsyms.h>
16875 +#include <linux/vs_base.h>
16876 +#include <linux/vs_cvirt.h>
16877 +#include <linux/vs_pid.h>
16878 +#include <linux/vserver/sched.h>
16879  
16880  #include <asm/uaccess.h>
16881  #include <asm/unistd.h>
16882 @@ -1018,6 +1022,25 @@ unsigned long get_next_timer_interrupt(u
16883  }
16884  #endif
16885  
16886 +static inline
16887 +void __vx_consume_token(struct _vx_sched_pc *sched_pc)
16888 +{
16889 +       sched_pc->tokens--;
16890 +}
16891 +
16892 +static inline
16893 +void vx_hard_tick(struct task_struct *p, int cpu)
16894 +{
16895 +       struct vx_info *vxi = p->vx_info;
16896 +
16897 +       if (vx_info_flags(vxi, VXF_SCHED_HARD|VXF_SCHED_PRIO, 0)) {
16898 +               struct _vx_sched_pc *sched_pc =
16899 +                       &vx_per_cpu(vxi, sched_pc, cpu);
16900 +
16901 +               __vx_consume_token(sched_pc);
16902 +       }
16903 +}
16904 +
16905  /*
16906   * Called from the timer interrupt handler to charge one tick to the current
16907   * process.  user_tick is 1 if the tick is user time, 0 for system.
16908 @@ -1034,6 +1057,7 @@ void update_process_times(int user_tick)
16909                 rcu_check_callbacks(cpu, user_tick);
16910         printk_tick();
16911         scheduler_tick();
16912 +       vx_hard_tick(p, cpu);
16913         run_posix_cpu_timers(p);
16914  }
16915  
16916 @@ -1136,12 +1160,6 @@ SYSCALL_DEFINE1(alarm, unsigned int, sec
16917  
16918  #endif
16919  
16920 -#ifndef __alpha__
16921 -
16922 -/*
16923 - * The Alpha uses getxpid, getxuid, and getxgid instead.  Maybe this
16924 - * should be moved into arch/i386 instead?
16925 - */
16926  
16927  /**
16928   * sys_getpid - return the thread group id of the current process
16929 @@ -1170,10 +1188,23 @@ SYSCALL_DEFINE0(getppid)
16930         rcu_read_lock();
16931         pid = task_tgid_vnr(current->real_parent);
16932         rcu_read_unlock();
16933 +       return vx_map_pid(pid);
16934 +}
16935  
16936 -       return pid;
16937 +#ifdef __alpha__
16938 +
16939 +/*
16940 + * The Alpha uses getxpid, getxuid, and getxgid instead.
16941 + */
16942 +
16943 +asmlinkage long do_getxpid(long *ppid)
16944 +{
16945 +       *ppid = sys_getppid();
16946 +       return sys_getpid();
16947  }
16948  
16949 +#else /* _alpha_ */
16950 +
16951  SYSCALL_DEFINE0(getuid)
16952  {
16953         /* Only we change this so SMP safe */
16954 @@ -1344,6 +1375,8 @@ int do_sysinfo(struct sysinfo *info)
16955                         tp.tv_nsec = tp.tv_nsec - NSEC_PER_SEC;
16956                         tp.tv_sec++;
16957                 }
16958 +               if (vx_flags(VXF_VIRT_UPTIME, 0))
16959 +                       vx_vsi_uptime(&tp, NULL);
16960                 info->uptime = tp.tv_sec + (tp.tv_nsec ? 1 : 0);
16961  
16962                 info->loads[0] = avenrun[0] << (SI_LOAD_SHIFT - FSHIFT);
16963 diff -NurpP --minimal linux-2.6.29.4/kernel/user.c linux-2.6.29.4-vs2.3.0.36.14/kernel/user.c
16964 --- linux-2.6.29.4/kernel/user.c        2009-03-24 14:22:45.000000000 +0100
16965 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/user.c  2009-03-24 17:47:32.000000000 +0100
16966 @@ -249,10 +249,10 @@ static struct kobj_type uids_ktype = {
16967   *
16968   * See Documentation/scheduler/sched-design-CFS.txt for ramifications.
16969   */
16970 -static int uids_user_create(struct user_struct *up)
16971 +static int uids_user_create(struct user_namespace *ns, struct user_struct *up)
16972  {
16973         struct kobject *kobj = &up->kobj;
16974 -       int error;
16975 +       int error = 0;
16976  
16977         memset(kobj, 0, sizeof(struct kobject));
16978         if (up->user_ns != &init_user_ns)
16979 @@ -280,7 +280,7 @@ int __init uids_sysfs_init(void)
16980         if (!uids_kset)
16981                 return -ENOMEM;
16982  
16983 -       return uids_user_create(&root_user);
16984 +       return uids_user_create(NULL, &root_user);
16985  }
16986  
16987  /* work function to remove sysfs directory for a user and free up
16988 @@ -342,7 +342,8 @@ static void free_user(struct user_struct
16989  #else  /* CONFIG_USER_SCHED && CONFIG_SYSFS */
16990  
16991  int uids_sysfs_init(void) { return 0; }
16992 -static inline int uids_user_create(struct user_struct *up) { return 0; }
16993 +static inline int uids_user_create(struct user_namespace *ns,
16994 +       struct user_struct *up) { return 0; }
16995  static inline void uids_mutex_lock(void) { }
16996  static inline void uids_mutex_unlock(void) { }
16997  
16998 @@ -439,7 +440,7 @@ struct user_struct *alloc_uid(struct use
16999  
17000                 new->user_ns = get_user_ns(ns);
17001  
17002 -               if (uids_user_create(new))
17003 +               if (uids_user_create(ns, new))
17004                         goto out_destoy_sched;
17005  
17006                 /*
17007 diff -NurpP --minimal linux-2.6.29.4/kernel/user_namespace.c linux-2.6.29.4-vs2.3.0.36.14/kernel/user_namespace.c
17008 --- linux-2.6.29.4/kernel/user_namespace.c      2009-03-24 14:22:45.000000000 +0100
17009 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/user_namespace.c        2009-03-24 18:05:19.000000000 +0100
17010 @@ -10,6 +10,7 @@
17011  #include <linux/slab.h>
17012  #include <linux/user_namespace.h>
17013  #include <linux/cred.h>
17014 +#include <linux/vserver/global.h>
17015  
17016  /*
17017   * Create a new user namespace, deriving the creator from the user in the
17018 @@ -30,6 +31,7 @@ int create_user_ns(struct cred *new)
17019                 return -ENOMEM;
17020  
17021         kref_init(&ns->kref);
17022 +       atomic_inc(&vs_global_user_ns);
17023  
17024         for (n = 0; n < UIDHASH_SZ; ++n)
17025                 INIT_HLIST_HEAD(ns->uidhash_table + n);
17026 @@ -78,6 +80,8 @@ void free_user_ns(struct kref *kref)
17027         struct user_namespace *ns =
17028                 container_of(kref, struct user_namespace, kref);
17029  
17030 +       /* FIXME: maybe move into destroyer? */
17031 +       atomic_dec(&vs_global_user_ns);
17032         INIT_WORK(&ns->destroyer, free_user_ns_work);
17033         schedule_work(&ns->destroyer);
17034  }
17035 diff -NurpP --minimal linux-2.6.29.4/kernel/utsname.c linux-2.6.29.4-vs2.3.0.36.14/kernel/utsname.c
17036 --- linux-2.6.29.4/kernel/utsname.c     2008-12-25 00:26:37.000000000 +0100
17037 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/utsname.c       2009-02-22 22:54:26.000000000 +0100
17038 @@ -14,6 +14,7 @@
17039  #include <linux/utsname.h>
17040  #include <linux/err.h>
17041  #include <linux/slab.h>
17042 +#include <linux/vserver/global.h>
17043  
17044  /*
17045   * Clone a new ns copying an original utsname, setting refcount to 1
17046 @@ -32,6 +33,7 @@ static struct uts_namespace *clone_uts_n
17047         memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
17048         up_read(&uts_sem);
17049         kref_init(&ns->kref);
17050 +       atomic_inc(&vs_global_uts_ns);
17051         return ns;
17052  }
17053  
17054 @@ -62,5 +64,6 @@ void free_uts_ns(struct kref *kref)
17055         struct uts_namespace *ns;
17056  
17057         ns = container_of(kref, struct uts_namespace, kref);
17058 +       atomic_dec(&vs_global_uts_ns);
17059         kfree(ns);
17060  }
17061 diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/cacct.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/cacct.c
17062 --- linux-2.6.29.4/kernel/vserver/cacct.c       1970-01-01 01:00:00.000000000 +0100
17063 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/cacct.c 2009-02-22 22:54:26.000000000 +0100
17064 @@ -0,0 +1,42 @@
17065 +/*
17066 + *  linux/kernel/vserver/cacct.c
17067 + *
17068 + *  Virtual Server: Context Accounting
17069 + *
17070 + *  Copyright (C) 2006-2007 Herbert Pötzl
17071 + *
17072 + *  V0.01  added accounting stats
17073 + *
17074 + */
17075 +
17076 +#include <linux/types.h>
17077 +#include <linux/vs_context.h>
17078 +#include <linux/vserver/cacct_cmd.h>
17079 +#include <linux/vserver/cacct_int.h>
17080 +
17081 +#include <asm/errno.h>
17082 +#include <asm/uaccess.h>
17083 +
17084 +
17085 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
17086 +{
17087 +       struct vcmd_sock_stat_v0 vc_data;
17088 +       int j, field;
17089 +
17090 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17091 +               return -EFAULT;
17092 +
17093 +       field = vc_data.field;
17094 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
17095 +               return -EINVAL;
17096 +
17097 +       for (j = 0; j < 3; j++) {
17098 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
17099 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
17100 +       }
17101 +
17102 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17103 +               return -EFAULT;
17104 +       return 0;
17105 +}
17106 +
17107 diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/cacct_init.h linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/cacct_init.h
17108 --- linux-2.6.29.4/kernel/vserver/cacct_init.h  1970-01-01 01:00:00.000000000 +0100
17109 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/cacct_init.h    2009-02-22 22:54:26.000000000 +0100
17110 @@ -0,0 +1,25 @@
17111 +
17112 +
17113 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
17114 +{
17115 +       int i, j;
17116 +
17117 +
17118 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
17119 +               for (j = 0; j < 3; j++) {
17120 +                       atomic_set(&cacct->sock[i][j].count, 0);
17121 +                       atomic_set(&cacct->sock[i][j].total, 0);
17122 +               }
17123 +       }
17124 +       for (i = 0; i < 8; i++)
17125 +               atomic_set(&cacct->slab[i], 0);
17126 +       for (i = 0; i < 5; i++)
17127 +               for (j = 0; j < 4; j++)
17128 +                       atomic_set(&cacct->page[i][j], 0);
17129 +}
17130 +
17131 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
17132 +{
17133 +       return;
17134 +}
17135 +
17136 diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/cacct_proc.h linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/cacct_proc.h
17137 --- linux-2.6.29.4/kernel/vserver/cacct_proc.h  1970-01-01 01:00:00.000000000 +0100
17138 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/cacct_proc.h    2009-02-22 22:54:26.000000000 +0100
17139 @@ -0,0 +1,53 @@
17140 +#ifndef _VX_CACCT_PROC_H
17141 +#define _VX_CACCT_PROC_H
17142 +
17143 +#include <linux/vserver/cacct_int.h>
17144 +
17145 +
17146 +#define VX_SOCKA_TOP   \
17147 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
17148 +
17149 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
17150 +{
17151 +       int i, j, length = 0;
17152 +       static char *type[VXA_SOCK_SIZE] = {
17153 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
17154 +       };
17155 +
17156 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
17157 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
17158 +               length += sprintf(buffer + length, "%s:", type[i]);
17159 +               for (j = 0; j < 3; j++) {
17160 +                       length += sprintf(buffer + length,
17161 +                               "\t%10lu/%-10lu",
17162 +                               vx_sock_count(cacct, i, j),
17163 +                               vx_sock_total(cacct, i, j));
17164 +               }
17165 +               buffer[length++] = '\n';
17166 +       }
17167 +
17168 +       length += sprintf(buffer + length, "\n");
17169 +       length += sprintf(buffer + length,
17170 +               "slab:\t %8u %8u %8u %8u\n",
17171 +               atomic_read(&cacct->slab[1]),
17172 +               atomic_read(&cacct->slab[4]),
17173 +               atomic_read(&cacct->slab[0]),
17174 +               atomic_read(&cacct->slab[2]));
17175 +
17176 +       length += sprintf(buffer + length, "\n");
17177 +       for (i = 0; i < 5; i++) {
17178 +               length += sprintf(buffer + length,
17179 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
17180 +                       atomic_read(&cacct->page[i][0]),
17181 +                       atomic_read(&cacct->page[i][1]),
17182 +                       atomic_read(&cacct->page[i][2]),
17183 +                       atomic_read(&cacct->page[i][3]),
17184 +                       atomic_read(&cacct->page[i][4]),
17185 +                       atomic_read(&cacct->page[i][5]),
17186 +                       atomic_read(&cacct->page[i][6]),
17187 +                       atomic_read(&cacct->page[i][7]));
17188 +       }
17189 +       return length;
17190 +}
17191 +
17192 +#endif /* _VX_CACCT_PROC_H */
17193 diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/context.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/context.c
17194 --- linux-2.6.29.4/kernel/vserver/context.c     1970-01-01 01:00:00.000000000 +0100
17195 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/context.c       2009-05-23 22:56:58.000000000 +0200
17196 @@ -0,0 +1,1030 @@
17197 +/*
17198 + *  linux/kernel/vserver/context.c
17199 + *
17200 + *  Virtual Server: Context Support
17201 + *
17202 + *  Copyright (C) 2003-2007  Herbert Pötzl
17203 + *
17204 + *  V0.01  context helper
17205 + *  V0.02  vx_ctx_kill syscall command
17206 + *  V0.03  replaced context_info calls
17207 + *  V0.04  redesign of struct (de)alloc
17208 + *  V0.05  rlimit basic implementation
17209 + *  V0.06  task_xid and info commands
17210 + *  V0.07  context flags and caps
17211 + *  V0.08  switch to RCU based hash
17212 + *  V0.09  revert to non RCU for now
17213 + *  V0.10  and back to working RCU hash
17214 + *  V0.11  and back to locking again
17215 + *  V0.12  referenced context store
17216 + *  V0.13  separate per cpu data
17217 + *  V0.14  changed vcmds to vxi arg
17218 + *  V0.15  added context stat
17219 + *  V0.16  have __create claim() the vxi
17220 + *  V0.17  removed older and legacy stuff
17221 + *
17222 + */
17223 +
17224 +#include <linux/slab.h>
17225 +#include <linux/types.h>
17226 +#include <linux/security.h>
17227 +#include <linux/pid_namespace.h>
17228 +
17229 +#include <linux/vserver/context.h>
17230 +#include <linux/vserver/network.h>
17231 +#include <linux/vserver/debug.h>
17232 +#include <linux/vserver/limit.h>
17233 +#include <linux/vserver/limit_int.h>
17234 +#include <linux/vserver/space.h>
17235 +#include <linux/init_task.h>
17236 +
17237 +#include <linux/vs_context.h>
17238 +#include <linux/vs_limit.h>
17239 +#include <linux/vs_pid.h>
17240 +#include <linux/vserver/context_cmd.h>
17241 +
17242 +#include "cvirt_init.h"
17243 +#include "cacct_init.h"
17244 +#include "limit_init.h"
17245 +#include "sched_init.h"
17246 +
17247 +
17248 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
17249 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
17250 +
17251 +
17252 +/*     now inactive context structures */
17253 +
17254 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
17255 +
17256 +static spinlock_t vx_info_inactive_lock = SPIN_LOCK_UNLOCKED;
17257 +
17258 +
17259 +/*     __alloc_vx_info()
17260 +
17261 +       * allocate an initialized vx_info struct
17262 +       * doesn't make it visible (hash)                        */
17263 +
17264 +static struct vx_info *__alloc_vx_info(xid_t xid)
17265 +{
17266 +       struct vx_info *new = NULL;
17267 +       int cpu, index;
17268 +
17269 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
17270 +
17271 +       /* would this benefit from a slab cache? */
17272 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
17273 +       if (!new)
17274 +               return 0;
17275 +
17276 +       memset(new, 0, sizeof(struct vx_info));
17277 +#ifdef CONFIG_SMP
17278 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
17279 +       if (!new->ptr_pc)
17280 +               goto error;
17281 +#endif
17282 +       new->vx_id = xid;
17283 +       INIT_HLIST_NODE(&new->vx_hlist);
17284 +       atomic_set(&new->vx_usecnt, 0);
17285 +       atomic_set(&new->vx_tasks, 0);
17286 +       new->vx_parent = NULL;
17287 +       new->vx_state = 0;
17288 +       init_waitqueue_head(&new->vx_wait);
17289 +
17290 +       /* prepare reaper */
17291 +       get_task_struct(init_pid_ns.child_reaper);
17292 +       new->vx_reaper = init_pid_ns.child_reaper;
17293 +       new->vx_badness_bias = 0;
17294 +
17295 +       /* rest of init goes here */
17296 +       vx_info_init_limit(&new->limit);
17297 +       vx_info_init_sched(&new->sched);
17298 +       vx_info_init_cvirt(&new->cvirt);
17299 +       vx_info_init_cacct(&new->cacct);
17300 +
17301 +       /* per cpu data structures */
17302 +       for_each_possible_cpu(cpu) {
17303 +               vx_info_init_sched_pc(
17304 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
17305 +               vx_info_init_cvirt_pc(
17306 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
17307 +       }
17308 +
17309 +       new->vx_flags = VXF_INIT_SET;
17310 +       cap_set_init_eff(new->vx_bcaps);
17311 +       new->vx_ccaps = 0;
17312 +       // new->vx_cap_bset = current->cap_bset;
17313 +
17314 +       new->reboot_cmd = 0;
17315 +       new->exit_code = 0;
17316 +
17317 +       // preconfig fs entries
17318 +       for (index = 0; index < VX_SPACES; index++) {
17319 +               write_lock(&init_fs.lock);
17320 +               init_fs.users++;
17321 +               write_unlock(&init_fs.lock);
17322 +               new->vx_fs[index] = &init_fs;
17323 +       }
17324 +
17325 +       vxdprintk(VXD_CBIT(xid, 0),
17326 +               "alloc_vx_info(%d) = %p", xid, new);
17327 +       vxh_alloc_vx_info(new);
17328 +       atomic_inc(&vx_global_ctotal);
17329 +       return new;
17330 +#ifdef CONFIG_SMP
17331 +error:
17332 +       kfree(new);
17333 +       return 0;
17334 +#endif
17335 +}
17336 +
17337 +/*     __dealloc_vx_info()
17338 +
17339 +       * final disposal of vx_info                             */
17340 +
17341 +static void __dealloc_vx_info(struct vx_info *vxi)
17342 +{
17343 +       struct vx_info_save vxis;
17344 +       int cpu;
17345 +
17346 +       vxdprintk(VXD_CBIT(xid, 0),
17347 +               "dealloc_vx_info(%p)", vxi);
17348 +       vxh_dealloc_vx_info(vxi);
17349 +
17350 +#ifdef CONFIG_VSERVER_WARN
17351 +       enter_vx_info(vxi, &vxis);
17352 +       vx_info_exit_limit(&vxi->limit);
17353 +       vx_info_exit_sched(&vxi->sched);
17354 +       vx_info_exit_cvirt(&vxi->cvirt);
17355 +       vx_info_exit_cacct(&vxi->cacct);
17356 +
17357 +       for_each_possible_cpu(cpu) {
17358 +               vx_info_exit_sched_pc(
17359 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
17360 +               vx_info_exit_cvirt_pc(
17361 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
17362 +       }
17363 +       leave_vx_info(&vxis);
17364 +#endif
17365 +
17366 +       vxi->vx_id = -1;
17367 +       vxi->vx_state |= VXS_RELEASED;
17368 +
17369 +#ifdef CONFIG_SMP
17370 +       free_percpu(vxi->ptr_pc);
17371 +#endif
17372 +       kfree(vxi);
17373 +       atomic_dec(&vx_global_ctotal);
17374 +}
17375 +
17376 +static void __shutdown_vx_info(struct vx_info *vxi)
17377 +{
17378 +       struct nsproxy *nsproxy;
17379 +       struct fs_struct *fs;
17380 +       int index, kill;
17381 +
17382 +       might_sleep();
17383 +
17384 +       vxi->vx_state |= VXS_SHUTDOWN;
17385 +       vs_state_change(vxi, VSC_SHUTDOWN);
17386 +
17387 +       for (index = 0; index < VX_SPACES; index++) {
17388 +               nsproxy = xchg(&vxi->vx_nsproxy[index], NULL);
17389 +               if (nsproxy)
17390 +                       put_nsproxy(nsproxy);
17391 +
17392 +               fs = xchg(&vxi->vx_fs[index], NULL);
17393 +               write_lock(&fs->lock);
17394 +               kill = !--fs->users;
17395 +               write_unlock(&fs->lock);
17396 +               if (kill)
17397 +                       free_fs_struct(fs);
17398 +       }
17399 +}
17400 +
17401 +/* exported stuff */
17402 +
17403 +void free_vx_info(struct vx_info *vxi)
17404 +{
17405 +       unsigned long flags;
17406 +       unsigned index;
17407 +
17408 +       /* check for reference counts first */
17409 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
17410 +       BUG_ON(atomic_read(&vxi->vx_tasks));
17411 +
17412 +       /* context must not be hashed */
17413 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
17414 +
17415 +       /* context shutdown is mandatory */
17416 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
17417 +
17418 +       /* nsproxy and fs check */
17419 +       for (index = 0; index < VX_SPACES; index++) {
17420 +               BUG_ON(vxi->vx_nsproxy[index]);
17421 +               BUG_ON(vxi->vx_fs[index]);
17422 +       }
17423 +
17424 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
17425 +       hlist_del(&vxi->vx_hlist);
17426 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
17427 +
17428 +       __dealloc_vx_info(vxi);
17429 +}
17430 +
17431 +
17432 +/*     hash table for vx_info hash */
17433 +
17434 +#define VX_HASH_SIZE   13
17435 +
17436 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
17437 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
17438 +
17439 +static spinlock_t vx_info_hash_lock = SPIN_LOCK_UNLOCKED;
17440 +
17441 +
17442 +static inline unsigned int __hashval(xid_t xid)
17443 +{
17444 +       return (xid % VX_HASH_SIZE);
17445 +}
17446 +
17447 +
17448 +
17449 +/*     __hash_vx_info()
17450 +
17451 +       * add the vxi to the global hash table
17452 +       * requires the hash_lock to be held                     */
17453 +
17454 +static inline void __hash_vx_info(struct vx_info *vxi)
17455 +{
17456 +       struct hlist_head *head;
17457 +
17458 +       vxd_assert_lock(&vx_info_hash_lock);
17459 +       vxdprintk(VXD_CBIT(xid, 4),
17460 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
17461 +       vxh_hash_vx_info(vxi);
17462 +
17463 +       /* context must not be hashed */
17464 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
17465 +
17466 +       vxi->vx_state |= VXS_HASHED;
17467 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
17468 +       hlist_add_head(&vxi->vx_hlist, head);
17469 +       atomic_inc(&vx_global_cactive);
17470 +}
17471 +
17472 +/*     __unhash_vx_info()
17473 +
17474 +       * remove the vxi from the global hash table
17475 +       * requires the hash_lock to be held                     */
17476 +
17477 +static inline void __unhash_vx_info(struct vx_info *vxi)
17478 +{
17479 +       unsigned long flags;
17480 +
17481 +       vxd_assert_lock(&vx_info_hash_lock);
17482 +       vxdprintk(VXD_CBIT(xid, 4),
17483 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
17484 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
17485 +       vxh_unhash_vx_info(vxi);
17486 +
17487 +       /* context must be hashed */
17488 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
17489 +       /* but without tasks */
17490 +       BUG_ON(atomic_read(&vxi->vx_tasks));
17491 +
17492 +       vxi->vx_state &= ~VXS_HASHED;
17493 +       hlist_del_init(&vxi->vx_hlist);
17494 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
17495 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
17496 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
17497 +       atomic_dec(&vx_global_cactive);
17498 +}
17499 +
17500 +
17501 +/*     __lookup_vx_info()
17502 +
17503 +       * requires the hash_lock to be held
17504 +       * doesn't increment the vx_refcnt                       */
17505 +
17506 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
17507 +{
17508 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
17509 +       struct hlist_node *pos;
17510 +       struct vx_info *vxi;
17511 +
17512 +       vxd_assert_lock(&vx_info_hash_lock);
17513 +       hlist_for_each(pos, head) {
17514 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
17515 +
17516 +               if (vxi->vx_id == xid)
17517 +                       goto found;
17518 +       }
17519 +       vxi = NULL;
17520 +found:
17521 +       vxdprintk(VXD_CBIT(xid, 0),
17522 +               "__lookup_vx_info(#%u): %p[#%u]",
17523 +               xid, vxi, vxi ? vxi->vx_id : 0);
17524 +       vxh_lookup_vx_info(vxi, xid);
17525 +       return vxi;
17526 +}
17527 +
17528 +
17529 +/*     __create_vx_info()
17530 +
17531 +       * create the requested context
17532 +       * get(), claim() and hash it                            */
17533 +
17534 +static struct vx_info *__create_vx_info(int id)
17535 +{
17536 +       struct vx_info *new, *vxi = NULL;
17537 +
17538 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
17539 +
17540 +       if (!(new = __alloc_vx_info(id)))
17541 +               return ERR_PTR(-ENOMEM);
17542 +
17543 +       /* required to make dynamic xids unique */
17544 +       spin_lock(&vx_info_hash_lock);
17545 +
17546 +       /* static context requested */
17547 +       if ((vxi = __lookup_vx_info(id))) {
17548 +               vxdprintk(VXD_CBIT(xid, 0),
17549 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
17550 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
17551 +                       vxi = ERR_PTR(-EBUSY);
17552 +               else
17553 +                       vxi = ERR_PTR(-EEXIST);
17554 +               goto out_unlock;
17555 +       }
17556 +       /* new context */
17557 +       vxdprintk(VXD_CBIT(xid, 0),
17558 +               "create_vx_info(%d) = %p (new)", id, new);
17559 +       claim_vx_info(new, NULL);
17560 +       __hash_vx_info(get_vx_info(new));
17561 +       vxi = new, new = NULL;
17562 +
17563 +out_unlock:
17564 +       spin_unlock(&vx_info_hash_lock);
17565 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
17566 +       if (new)
17567 +               __dealloc_vx_info(new);
17568 +       return vxi;
17569 +}
17570 +
17571 +
17572 +/*     exported stuff                                          */
17573 +
17574 +
17575 +void unhash_vx_info(struct vx_info *vxi)
17576 +{
17577 +       __shutdown_vx_info(vxi);
17578 +       spin_lock(&vx_info_hash_lock);
17579 +       __unhash_vx_info(vxi);
17580 +       spin_unlock(&vx_info_hash_lock);
17581 +       __wakeup_vx_info(vxi);
17582 +}
17583 +
17584 +
17585 +/*     lookup_vx_info()
17586 +
17587 +       * search for a vx_info and get() it
17588 +       * negative id means current                             */
17589 +
17590 +struct vx_info *lookup_vx_info(int id)
17591 +{
17592 +       struct vx_info *vxi = NULL;
17593 +
17594 +       if (id < 0) {
17595 +               vxi = get_vx_info(current->vx_info);
17596 +       } else if (id > 1) {
17597 +               spin_lock(&vx_info_hash_lock);
17598 +               vxi = get_vx_info(__lookup_vx_info(id));
17599 +               spin_unlock(&vx_info_hash_lock);
17600 +       }
17601 +       return vxi;
17602 +}
17603 +
17604 +/*     xid_is_hashed()
17605 +
17606 +       * verify that xid is still hashed                       */
17607 +
17608 +int xid_is_hashed(xid_t xid)
17609 +{
17610 +       int hashed;
17611 +
17612 +       spin_lock(&vx_info_hash_lock);
17613 +       hashed = (__lookup_vx_info(xid) != NULL);
17614 +       spin_unlock(&vx_info_hash_lock);
17615 +       return hashed;
17616 +}
17617 +
17618 +#ifdef CONFIG_PROC_FS
17619 +
17620 +/*     get_xid_list()
17621 +
17622 +       * get a subset of hashed xids for proc
17623 +       * assumes size is at least one                          */
17624 +
17625 +int get_xid_list(int index, unsigned int *xids, int size)
17626 +{
17627 +       int hindex, nr_xids = 0;
17628 +
17629 +       /* only show current and children */
17630 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
17631 +               if (index > 0)
17632 +                       return 0;
17633 +               xids[nr_xids] = vx_current_xid();
17634 +               return 1;
17635 +       }
17636 +
17637 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
17638 +               struct hlist_head *head = &vx_info_hash[hindex];
17639 +               struct hlist_node *pos;
17640 +
17641 +               spin_lock(&vx_info_hash_lock);
17642 +               hlist_for_each(pos, head) {
17643 +                       struct vx_info *vxi;
17644 +
17645 +                       if (--index > 0)
17646 +                               continue;
17647 +
17648 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
17649 +                       xids[nr_xids] = vxi->vx_id;
17650 +                       if (++nr_xids >= size) {
17651 +                               spin_unlock(&vx_info_hash_lock);
17652 +                               goto out;
17653 +                       }
17654 +               }
17655 +               /* keep the lock time short */
17656 +               spin_unlock(&vx_info_hash_lock);
17657 +       }
17658 +out:
17659 +       return nr_xids;
17660 +}
17661 +#endif
17662 +
17663 +#ifdef CONFIG_VSERVER_DEBUG
17664 +
17665 +void   dump_vx_info_inactive(int level)
17666 +{
17667 +       struct hlist_node *entry, *next;
17668 +
17669 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
17670 +               struct vx_info *vxi =
17671 +                       list_entry(entry, struct vx_info, vx_hlist);
17672 +
17673 +               dump_vx_info(vxi, level);
17674 +       }
17675 +}
17676 +
17677 +#endif
17678 +
17679 +#if 0
17680 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
17681 +{
17682 +       struct user_struct *new_user, *old_user;
17683 +
17684 +       if (!p || !vxi)
17685 +               BUG();
17686 +
17687 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
17688 +               return -EACCES;
17689 +
17690 +       new_user = alloc_uid(vxi->vx_id, p->uid);
17691 +       if (!new_user)
17692 +               return -ENOMEM;
17693 +
17694 +       old_user = p->user;
17695 +       if (new_user != old_user) {
17696 +               atomic_inc(&new_user->processes);
17697 +               atomic_dec(&old_user->processes);
17698 +               p->user = new_user;
17699 +       }
17700 +       free_uid(old_user);
17701 +       return 0;
17702 +}
17703 +#endif
17704 +
17705 +#if 0
17706 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
17707 +{
17708 +       // p->cap_effective &= vxi->vx_cap_bset;
17709 +       p->cap_effective =
17710 +               cap_intersect(p->cap_effective, vxi->cap_bset);
17711 +       // p->cap_inheritable &= vxi->vx_cap_bset;
17712 +       p->cap_inheritable =
17713 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
17714 +       // p->cap_permitted &= vxi->vx_cap_bset;
17715 +       p->cap_permitted =
17716 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
17717 +}
17718 +#endif
17719 +
17720 +
17721 +#include <linux/file.h>
17722 +#include <linux/fdtable.h>
17723 +
17724 +static int vx_openfd_task(struct task_struct *tsk)
17725 +{
17726 +       struct files_struct *files = tsk->files;
17727 +       struct fdtable *fdt;
17728 +       const unsigned long *bptr;
17729 +       int count, total;
17730 +
17731 +       /* no rcu_read_lock() because of spin_lock() */
17732 +       spin_lock(&files->file_lock);
17733 +       fdt = files_fdtable(files);
17734 +       bptr = fdt->open_fds->fds_bits;
17735 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
17736 +       for (total = 0; count > 0; count--) {
17737 +               if (*bptr)
17738 +                       total += hweight_long(*bptr);
17739 +               bptr++;
17740 +       }
17741 +       spin_unlock(&files->file_lock);
17742 +       return total;
17743 +}
17744 +
17745 +
17746 +/*     for *space compatibility */
17747 +
17748 +asmlinkage long sys_unshare(unsigned long);
17749 +
17750 +/*
17751 + *     migrate task to new context
17752 + *     gets vxi, puts old_vxi on change
17753 + *     optionally unshares namespaces (hack)
17754 + */
17755 +
17756 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
17757 +{
17758 +       struct vx_info *old_vxi;
17759 +       int ret = 0;
17760 +
17761 +       if (!p || !vxi)
17762 +               BUG();
17763 +
17764 +       vxdprintk(VXD_CBIT(xid, 5),
17765 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
17766 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
17767 +
17768 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
17769 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
17770 +               return -EACCES;
17771 +
17772 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
17773 +               return -EFAULT;
17774 +
17775 +       old_vxi = task_get_vx_info(p);
17776 +       if (old_vxi == vxi)
17777 +               goto out;
17778 +
17779 +//     if (!(ret = vx_migrate_user(p, vxi))) {
17780 +       {
17781 +               int openfd;
17782 +
17783 +               task_lock(p);
17784 +               openfd = vx_openfd_task(p);
17785 +
17786 +               if (old_vxi) {
17787 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
17788 +                       atomic_dec(&old_vxi->cvirt.nr_running);
17789 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
17790 +                       /* FIXME: what about the struct files here? */
17791 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
17792 +                       /* account for the executable */
17793 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
17794 +               }
17795 +               atomic_inc(&vxi->cvirt.nr_threads);
17796 +               atomic_inc(&vxi->cvirt.nr_running);
17797 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
17798 +               /* FIXME: what about the struct files here? */
17799 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
17800 +               /* account for the executable */
17801 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
17802 +
17803 +               if (old_vxi) {
17804 +                       release_vx_info(old_vxi, p);
17805 +                       clr_vx_info(&p->vx_info);
17806 +               }
17807 +               claim_vx_info(vxi, p);
17808 +               set_vx_info(&p->vx_info, vxi);
17809 +               p->xid = vxi->vx_id;
17810 +
17811 +               vxdprintk(VXD_CBIT(xid, 5),
17812 +                       "moved task %p into vxi:%p[#%d]",
17813 +                       p, vxi, vxi->vx_id);
17814 +
17815 +               // vx_mask_cap_bset(vxi, p);
17816 +               task_unlock(p);
17817 +
17818 +               /* hack for *spaces to provide compatibility */
17819 +               if (unshare) {
17820 +                       struct nsproxy *old_nsp, *new_nsp;
17821 +
17822 +                       ret = unshare_nsproxy_namespaces(
17823 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
17824 +                               &new_nsp, NULL);
17825 +                       if (ret)
17826 +                               goto out;
17827 +
17828 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
17829 +                       vx_set_space(vxi,
17830 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
17831 +                       put_nsproxy(old_nsp);
17832 +               }
17833 +       }
17834 +out:
17835 +       put_vx_info(old_vxi);
17836 +       return ret;
17837 +}
17838 +
17839 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
17840 +{
17841 +       struct task_struct *old_reaper;
17842 +
17843 +       if (!vxi)
17844 +               return -EINVAL;
17845 +
17846 +       vxdprintk(VXD_CBIT(xid, 6),
17847 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
17848 +               vxi, vxi->vx_id, p, p->xid, p->pid);
17849 +
17850 +       old_reaper = vxi->vx_reaper;
17851 +       if (old_reaper == p)
17852 +               return 0;
17853 +
17854 +       /* set new child reaper */
17855 +       get_task_struct(p);
17856 +       vxi->vx_reaper = p;
17857 +       put_task_struct(old_reaper);
17858 +       return 0;
17859 +}
17860 +
17861 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
17862 +{
17863 +       if (!vxi)
17864 +               return -EINVAL;
17865 +
17866 +       vxdprintk(VXD_CBIT(xid, 6),
17867 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
17868 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
17869 +
17870 +       vxi->vx_flags &= ~VXF_STATE_INIT;
17871 +       vxi->vx_initpid = p->tgid;
17872 +       return 0;
17873 +}
17874 +
17875 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
17876 +{
17877 +       vxdprintk(VXD_CBIT(xid, 6),
17878 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
17879 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
17880 +
17881 +       vxi->exit_code = code;
17882 +       vxi->vx_initpid = 0;
17883 +}
17884 +
17885 +
17886 +void vx_set_persistent(struct vx_info *vxi)
17887 +{
17888 +       vxdprintk(VXD_CBIT(xid, 6),
17889 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
17890 +
17891 +       get_vx_info(vxi);
17892 +       claim_vx_info(vxi, NULL);
17893 +}
17894 +
17895 +void vx_clear_persistent(struct vx_info *vxi)
17896 +{
17897 +       vxdprintk(VXD_CBIT(xid, 6),
17898 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
17899 +
17900 +       release_vx_info(vxi, NULL);
17901 +       put_vx_info(vxi);
17902 +}
17903 +
17904 +void vx_update_persistent(struct vx_info *vxi)
17905 +{
17906 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
17907 +               vx_set_persistent(vxi);
17908 +       else
17909 +               vx_clear_persistent(vxi);
17910 +}
17911 +
17912 +
17913 +/*     task must be current or locked          */
17914 +
17915 +void   exit_vx_info(struct task_struct *p, int code)
17916 +{
17917 +       struct vx_info *vxi = p->vx_info;
17918 +
17919 +       if (vxi) {
17920 +               atomic_dec(&vxi->cvirt.nr_threads);
17921 +               vx_nproc_dec(p);
17922 +
17923 +               vxi->exit_code = code;
17924 +               release_vx_info(vxi, p);
17925 +       }
17926 +}
17927 +
17928 +void   exit_vx_info_early(struct task_struct *p, int code)
17929 +{
17930 +       struct vx_info *vxi = p->vx_info;
17931 +
17932 +       if (vxi) {
17933 +               if (vxi->vx_initpid == p->tgid)
17934 +                       vx_exit_init(vxi, p, code);
17935 +               if (vxi->vx_reaper == p)
17936 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
17937 +       }
17938 +}
17939 +
17940 +
17941 +/* vserver syscall commands below here */
17942 +
17943 +/* taks xid and vx_info functions */
17944 +
17945 +#include <asm/uaccess.h>
17946 +
17947 +
17948 +int vc_task_xid(uint32_t id)
17949 +{
17950 +       xid_t xid;
17951 +
17952 +       if (id) {
17953 +               struct task_struct *tsk;
17954 +
17955 +               read_lock(&tasklist_lock);
17956 +               tsk = find_task_by_real_pid(id);
17957 +               xid = (tsk) ? tsk->xid : -ESRCH;
17958 +               read_unlock(&tasklist_lock);
17959 +       } else
17960 +               xid = vx_current_xid();
17961 +       return xid;
17962 +}
17963 +
17964 +
17965 +int vc_vx_info(struct vx_info *vxi, void __user *data)
17966 +{
17967 +       struct vcmd_vx_info_v0 vc_data;
17968 +
17969 +       vc_data.xid = vxi->vx_id;
17970 +       vc_data.initpid = vxi->vx_initpid;
17971 +
17972 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17973 +               return -EFAULT;
17974 +       return 0;
17975 +}
17976 +
17977 +
17978 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
17979 +{
17980 +       struct vcmd_ctx_stat_v0 vc_data;
17981 +
17982 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
17983 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
17984 +
17985 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17986 +               return -EFAULT;
17987 +       return 0;
17988 +}
17989 +
17990 +
17991 +/* context functions */
17992 +
17993 +int vc_ctx_create(uint32_t xid, void __user *data)
17994 +{
17995 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
17996 +       struct vx_info *new_vxi;
17997 +       int ret;
17998 +
17999 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
18000 +               return -EFAULT;
18001 +
18002 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
18003 +               return -EINVAL;
18004 +
18005 +       new_vxi = __create_vx_info(xid);
18006 +       if (IS_ERR(new_vxi))
18007 +               return PTR_ERR(new_vxi);
18008 +
18009 +       /* initial flags */
18010 +       new_vxi->vx_flags = vc_data.flagword;
18011 +
18012 +       ret = -ENOEXEC;
18013 +       if (vs_state_change(new_vxi, VSC_STARTUP))
18014 +               goto out;
18015 +
18016 +       ret = vx_migrate_task(current, new_vxi, (!data));
18017 +       if (ret)
18018 +               goto out;
18019 +
18020 +       /* return context id on success */
18021 +       ret = new_vxi->vx_id;
18022 +
18023 +       /* get a reference for persistent contexts */
18024 +       if ((vc_data.flagword & VXF_PERSISTENT))
18025 +               vx_set_persistent(new_vxi);
18026 +out:
18027 +       release_vx_info(new_vxi, NULL);
18028 +       put_vx_info(new_vxi);
18029 +       return ret;
18030 +}
18031 +
18032 +
18033 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
18034 +{
18035 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
18036 +       int ret;
18037 +
18038 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
18039 +               return -EFAULT;
18040 +
18041 +       ret = vx_migrate_task(current, vxi, 0);
18042 +       if (ret)
18043 +               return ret;
18044 +       if (vc_data.flagword & VXM_SET_INIT)
18045 +               ret = vx_set_init(vxi, current);
18046 +       if (ret)
18047 +               return ret;
18048 +       if (vc_data.flagword & VXM_SET_REAPER)
18049 +               ret = vx_set_reaper(vxi, current);
18050 +       return ret;
18051 +}
18052 +
18053 +
18054 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
18055 +{
18056 +       struct vcmd_ctx_flags_v0 vc_data;
18057 +
18058 +       vc_data.flagword = vxi->vx_flags;
18059 +
18060 +       /* special STATE flag handling */
18061 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
18062 +
18063 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18064 +               return -EFAULT;
18065 +       return 0;
18066 +}
18067 +
18068 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
18069 +{
18070 +       struct vcmd_ctx_flags_v0 vc_data;
18071 +       uint64_t mask, trigger;
18072 +
18073 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18074 +               return -EFAULT;
18075 +
18076 +       /* special STATE flag handling */
18077 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
18078 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
18079 +
18080 +       if (vxi == current->vx_info) {
18081 +               /* if (trigger & VXF_STATE_SETUP)
18082 +                       vx_mask_cap_bset(vxi, current); */
18083 +               if (trigger & VXF_STATE_INIT) {
18084 +                       int ret;
18085 +
18086 +                       ret = vx_set_init(vxi, current);
18087 +                       if (ret)
18088 +                               return ret;
18089 +                       ret = vx_set_reaper(vxi, current);
18090 +                       if (ret)
18091 +                               return ret;
18092 +               }
18093 +       }
18094 +
18095 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
18096 +               vc_data.flagword, mask);
18097 +       if (trigger & VXF_PERSISTENT)
18098 +               vx_update_persistent(vxi);
18099 +
18100 +       return 0;
18101 +}
18102 +
18103 +
18104 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
18105 +{
18106 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
18107 +
18108 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
18109 +       return v;
18110 +}
18111 +
18112 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
18113 +{
18114 +       kernel_cap_t c = __cap_empty_set;
18115 +
18116 +       c.cap[0] = v & 0xFFFFFFFF;
18117 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
18118 +
18119 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
18120 +       return c;
18121 +}
18122 +
18123 +
18124 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
18125 +{
18126 +       if (bcaps)
18127 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
18128 +       if (ccaps)
18129 +               *ccaps = vxi->vx_ccaps;
18130 +
18131 +       return 0;
18132 +}
18133 +
18134 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
18135 +{
18136 +       struct vcmd_ctx_caps_v1 vc_data;
18137 +       int ret;
18138 +
18139 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
18140 +       if (ret)
18141 +               return ret;
18142 +       vc_data.cmask = ~0ULL;
18143 +
18144 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18145 +               return -EFAULT;
18146 +       return 0;
18147 +}
18148 +
18149 +static int do_set_caps(struct vx_info *vxi,
18150 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
18151 +{
18152 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
18153 +
18154 +#if 0
18155 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
18156 +               bcaps, bmask, ccaps, cmask);
18157 +#endif
18158 +       vxi->vx_bcaps = cap_t_from_caps(
18159 +               vs_mask_flags(bcold, bcaps, bmask));
18160 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
18161 +
18162 +       return 0;
18163 +}
18164 +
18165 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
18166 +{
18167 +       struct vcmd_ctx_caps_v1 vc_data;
18168 +
18169 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18170 +               return -EFAULT;
18171 +
18172 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
18173 +}
18174 +
18175 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
18176 +{
18177 +       struct vcmd_bcaps vc_data;
18178 +       int ret;
18179 +
18180 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
18181 +       if (ret)
18182 +               return ret;
18183 +       vc_data.bmask = ~0ULL;
18184 +
18185 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18186 +               return -EFAULT;
18187 +       return 0;
18188 +}
18189 +
18190 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
18191 +{
18192 +       struct vcmd_bcaps vc_data;
18193 +
18194 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18195 +               return -EFAULT;
18196 +
18197 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
18198 +}
18199 +
18200 +
18201 +int vc_get_badness(struct vx_info *vxi, void __user *data)
18202 +{
18203 +       struct vcmd_badness_v0 vc_data;
18204 +
18205 +       vc_data.bias = vxi->vx_badness_bias;
18206 +
18207 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18208 +               return -EFAULT;
18209 +       return 0;
18210 +}
18211 +
18212 +int vc_set_badness(struct vx_info *vxi, void __user *data)
18213 +{
18214 +       struct vcmd_badness_v0 vc_data;
18215 +
18216 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18217 +               return -EFAULT;
18218 +
18219 +       vxi->vx_badness_bias = vc_data.bias;
18220 +       return 0;
18221 +}
18222 +
18223 +#include <linux/module.h>
18224 +
18225 +EXPORT_SYMBOL_GPL(free_vx_info);
18226 +
18227 diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/cvirt.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/cvirt.c
18228 --- linux-2.6.29.4/kernel/vserver/cvirt.c       1970-01-01 01:00:00.000000000 +0100
18229 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/cvirt.c 2009-02-22 22:54:26.000000000 +0100
18230 @@ -0,0 +1,300 @@
18231 +/*
18232 + *  linux/kernel/vserver/cvirt.c
18233 + *
18234 + *  Virtual Server: Context Virtualization
18235 + *
18236 + *  Copyright (C) 2004-2007  Herbert Pötzl
18237 + *
18238 + *  V0.01  broken out from limit.c
18239 + *  V0.02  added utsname stuff
18240 + *  V0.03  changed vcmds to vxi arg
18241 + *
18242 + */
18243 +
18244 +#include <linux/types.h>
18245 +#include <linux/utsname.h>
18246 +#include <linux/vs_cvirt.h>
18247 +#include <linux/vserver/switch.h>
18248 +#include <linux/vserver/cvirt_cmd.h>
18249 +
18250 +#include <asm/uaccess.h>
18251 +
18252 +
18253 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
18254 +{
18255 +       struct vx_info *vxi = current->vx_info;
18256 +
18257 +       set_normalized_timespec(uptime,
18258 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
18259 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
18260 +       if (!idle)
18261 +               return;
18262 +       set_normalized_timespec(idle,
18263 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
18264 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
18265 +       return;
18266 +}
18267 +
18268 +uint64_t vx_idle_jiffies(void)
18269 +{
18270 +       return init_task.utime + init_task.stime;
18271 +}
18272 +
18273 +
18274 +
18275 +static inline uint32_t __update_loadavg(uint32_t load,
18276 +       int wsize, int delta, int n)
18277 +{
18278 +       unsigned long long calc, prev;
18279 +
18280 +       /* just set it to n */
18281 +       if (unlikely(delta >= wsize))
18282 +               return (n << FSHIFT);
18283 +
18284 +       calc = delta * n;
18285 +       calc <<= FSHIFT;
18286 +       prev = (wsize - delta);
18287 +       prev *= load;
18288 +       calc += prev;
18289 +       do_div(calc, wsize);
18290 +       return calc;
18291 +}
18292 +
18293 +
18294 +void vx_update_load(struct vx_info *vxi)
18295 +{
18296 +       uint32_t now, last, delta;
18297 +       unsigned int nr_running, nr_uninterruptible;
18298 +       unsigned int total;
18299 +       unsigned long flags;
18300 +
18301 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
18302 +
18303 +       now = jiffies;
18304 +       last = vxi->cvirt.load_last;
18305 +       delta = now - last;
18306 +
18307 +       if (delta < 5*HZ)
18308 +               goto out;
18309 +
18310 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
18311 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
18312 +       total = nr_running + nr_uninterruptible;
18313 +
18314 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
18315 +               60*HZ, delta, total);
18316 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
18317 +               5*60*HZ, delta, total);
18318 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
18319 +               15*60*HZ, delta, total);
18320 +
18321 +       vxi->cvirt.load_last = now;
18322 +out:
18323 +       atomic_inc(&vxi->cvirt.load_updates);
18324 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
18325 +}
18326 +
18327 +
18328 +/*
18329 + * Commands to do_syslog:
18330 + *
18331 + *      0 -- Close the log.  Currently a NOP.
18332 + *      1 -- Open the log. Currently a NOP.
18333 + *      2 -- Read from the log.
18334 + *      3 -- Read all messages remaining in the ring buffer.
18335 + *      4 -- Read and clear all messages remaining in the ring buffer
18336 + *      5 -- Clear ring buffer.
18337 + *      6 -- Disable printk's to console
18338 + *      7 -- Enable printk's to console
18339 + *      8 -- Set level of messages printed to console
18340 + *      9 -- Return number of unread characters in the log buffer
18341 + *     10 -- Return size of the log buffer
18342 + */
18343 +int vx_do_syslog(int type, char __user *buf, int len)
18344 +{
18345 +       int error = 0;
18346 +       int do_clear = 0;
18347 +       struct vx_info *vxi = current->vx_info;
18348 +       struct _vx_syslog *log;
18349 +
18350 +       if (!vxi)
18351 +               return -EINVAL;
18352 +       log = &vxi->cvirt.syslog;
18353 +
18354 +       switch (type) {
18355 +       case 0:         /* Close log */
18356 +       case 1:         /* Open log */
18357 +               break;
18358 +       case 2:         /* Read from log */
18359 +               error = wait_event_interruptible(log->log_wait,
18360 +                       (log->log_start - log->log_end));
18361 +               if (error)
18362 +                       break;
18363 +               spin_lock_irq(&log->logbuf_lock);
18364 +               spin_unlock_irq(&log->logbuf_lock);
18365 +               break;
18366 +       case 4:         /* Read/clear last kernel messages */
18367 +               do_clear = 1;
18368 +               /* fall through */
18369 +       case 3:         /* Read last kernel messages */
18370 +               return 0;
18371 +
18372 +       case 5:         /* Clear ring buffer */
18373 +               return 0;
18374 +
18375 +       case 6:         /* Disable logging to console */
18376 +       case 7:         /* Enable logging to console */
18377 +       case 8:         /* Set level of messages printed to console */
18378 +               break;
18379 +
18380 +       case 9:         /* Number of chars in the log buffer */
18381 +               return 0;
18382 +       case 10:        /* Size of the log buffer */
18383 +               return 0;
18384 +       default:
18385 +               error = -EINVAL;
18386 +               break;
18387 +       }
18388 +       return error;
18389 +}
18390 +
18391 +
18392 +/* virtual host info names */
18393 +
18394 +static char *vx_vhi_name(struct vx_info *vxi, int id)
18395 +{
18396 +       struct nsproxy *nsproxy;
18397 +       struct uts_namespace *uts;
18398 +
18399 +       if (id == VHIN_CONTEXT)
18400 +               return vxi->vx_name;
18401 +
18402 +       nsproxy = vxi->vx_nsproxy[0];
18403 +       if (!nsproxy)
18404 +               return NULL;
18405 +
18406 +       uts = nsproxy->uts_ns;
18407 +       if (!uts)
18408 +               return NULL;
18409 +
18410 +       switch (id) {
18411 +       case VHIN_SYSNAME:
18412 +               return uts->name.sysname;
18413 +       case VHIN_NODENAME:
18414 +               return uts->name.nodename;
18415 +       case VHIN_RELEASE:
18416 +               return uts->name.release;
18417 +       case VHIN_VERSION:
18418 +               return uts->name.version;
18419 +       case VHIN_MACHINE:
18420 +               return uts->name.machine;
18421 +       case VHIN_DOMAINNAME:
18422 +               return uts->name.domainname;
18423 +       default:
18424 +               return NULL;
18425 +       }
18426 +       return NULL;
18427 +}
18428 +
18429 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
18430 +{
18431 +       struct vcmd_vhi_name_v0 vc_data;
18432 +       char *name;
18433 +
18434 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18435 +               return -EFAULT;
18436 +
18437 +       name = vx_vhi_name(vxi, vc_data.field);
18438 +       if (!name)
18439 +               return -EINVAL;
18440 +
18441 +       memcpy(name, vc_data.name, 65);
18442 +       return 0;
18443 +}
18444 +
18445 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
18446 +{
18447 +       struct vcmd_vhi_name_v0 vc_data;
18448 +       char *name;
18449 +
18450 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18451 +               return -EFAULT;
18452 +
18453 +       name = vx_vhi_name(vxi, vc_data.field);
18454 +       if (!name)
18455 +               return -EINVAL;
18456 +
18457 +       memcpy(vc_data.name, name, 65);
18458 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18459 +               return -EFAULT;
18460 +       return 0;
18461 +}
18462 +
18463 +
18464 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
18465 +{
18466 +       struct vcmd_virt_stat_v0 vc_data;
18467 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
18468 +       struct timespec uptime;
18469 +
18470 +       do_posix_clock_monotonic_gettime(&uptime);
18471 +       set_normalized_timespec(&uptime,
18472 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
18473 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
18474 +
18475 +       vc_data.offset = timeval_to_ns(&cvirt->bias_tv);
18476 +       vc_data.uptime = timespec_to_ns(&uptime);
18477 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
18478 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
18479 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
18480 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
18481 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
18482 +       vc_data.load[0] = cvirt->load[0];
18483 +       vc_data.load[1] = cvirt->load[1];
18484 +       vc_data.load[2] = cvirt->load[2];
18485 +
18486 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18487 +               return -EFAULT;
18488 +       return 0;
18489 +}
18490 +
18491 +
18492 +#ifdef CONFIG_VSERVER_VTIME
18493 +
18494 +/* virtualized time base */
18495 +
18496 +void vx_gettimeofday(struct timeval *tv)
18497 +{
18498 +       do_gettimeofday(tv);
18499 +       if (!vx_flags(VXF_VIRT_TIME, 0))
18500 +               return;
18501 +
18502 +       tv->tv_sec += current->vx_info->cvirt.bias_tv.tv_sec;
18503 +       tv->tv_usec += current->vx_info->cvirt.bias_tv.tv_usec;
18504 +
18505 +       if (tv->tv_usec >= USEC_PER_SEC) {
18506 +               tv->tv_sec++;
18507 +               tv->tv_usec -= USEC_PER_SEC;
18508 +       } else if (tv->tv_usec < 0) {
18509 +               tv->tv_sec--;
18510 +               tv->tv_usec += USEC_PER_SEC;
18511 +       }
18512 +}
18513 +
18514 +int vx_settimeofday(struct timespec *ts)
18515 +{
18516 +       struct timeval tv;
18517 +
18518 +       if (!vx_flags(VXF_VIRT_TIME, 0))
18519 +               return do_settimeofday(ts);
18520 +
18521 +       do_gettimeofday(&tv);
18522 +       current->vx_info->cvirt.bias_tv.tv_sec =
18523 +               ts->tv_sec - tv.tv_sec;
18524 +       current->vx_info->cvirt.bias_tv.tv_usec =
18525 +               (ts->tv_nsec/NSEC_PER_USEC) - tv.tv_usec;
18526 +       return 0;
18527 +}
18528 +
18529 +#endif
18530 +
18531 diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/cvirt_init.h linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/cvirt_init.h
18532 --- linux-2.6.29.4/kernel/vserver/cvirt_init.h  1970-01-01 01:00:00.000000000 +0100
18533 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/cvirt_init.h    2009-02-22 22:54:26.000000000 +0100
18534 @@ -0,0 +1,69 @@
18535 +
18536 +
18537 +extern uint64_t vx_idle_jiffies(void);
18538 +
18539 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
18540 +{
18541 +       uint64_t idle_jiffies = vx_idle_jiffies();
18542 +       uint64_t nsuptime;
18543 +
18544 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
18545 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
18546 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
18547 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
18548 +       cvirt->bias_tv.tv_sec = 0;
18549 +       cvirt->bias_tv.tv_usec = 0;
18550 +
18551 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
18552 +       atomic_set(&cvirt->nr_threads, 0);
18553 +       atomic_set(&cvirt->nr_running, 0);
18554 +       atomic_set(&cvirt->nr_uninterruptible, 0);
18555 +       atomic_set(&cvirt->nr_onhold, 0);
18556 +
18557 +       spin_lock_init(&cvirt->load_lock);
18558 +       cvirt->load_last = jiffies;
18559 +       atomic_set(&cvirt->load_updates, 0);
18560 +       cvirt->load[0] = 0;
18561 +       cvirt->load[1] = 0;
18562 +       cvirt->load[2] = 0;
18563 +       atomic_set(&cvirt->total_forks, 0);
18564 +
18565 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
18566 +       init_waitqueue_head(&cvirt->syslog.log_wait);
18567 +       cvirt->syslog.log_start = 0;
18568 +       cvirt->syslog.log_end = 0;
18569 +       cvirt->syslog.con_start = 0;
18570 +       cvirt->syslog.logged_chars = 0;
18571 +}
18572 +
18573 +static inline
18574 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
18575 +{
18576 +       // cvirt_pc->cpustat = { 0 };
18577 +}
18578 +
18579 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
18580 +{
18581 +       int value;
18582 +
18583 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
18584 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
18585 +               cvirt, value);
18586 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
18587 +               "!!! cvirt: %p[nr_running] = %d on exit.",
18588 +               cvirt, value);
18589 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
18590 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
18591 +               cvirt, value);
18592 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
18593 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
18594 +               cvirt, value);
18595 +       return;
18596 +}
18597 +
18598 +static inline
18599 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
18600 +{
18601 +       return;
18602 +}
18603 +
18604 diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/cvirt_proc.h linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/cvirt_proc.h
18605 --- linux-2.6.29.4/kernel/vserver/cvirt_proc.h  1970-01-01 01:00:00.000000000 +0100
18606 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/cvirt_proc.h    2009-02-22 22:54:26.000000000 +0100
18607 @@ -0,0 +1,135 @@
18608 +#ifndef _VX_CVIRT_PROC_H
18609 +#define _VX_CVIRT_PROC_H
18610 +
18611 +#include <linux/nsproxy.h>
18612 +#include <linux/mnt_namespace.h>
18613 +#include <linux/ipc_namespace.h>
18614 +#include <linux/utsname.h>
18615 +#include <linux/ipc.h>
18616 +
18617 +
18618 +static inline
18619 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
18620 +{
18621 +       struct mnt_namespace *ns;
18622 +       struct uts_namespace *uts;
18623 +       struct ipc_namespace *ipc;
18624 +       struct path path;
18625 +       char *pstr, *root;
18626 +       int length = 0;
18627 +
18628 +       if (!nsproxy)
18629 +               goto out;
18630 +
18631 +       length += sprintf(buffer + length,
18632 +               "NSProxy:\t%p [%p,%p,%p]\n",
18633 +               nsproxy, nsproxy->mnt_ns,
18634 +               nsproxy->uts_ns, nsproxy->ipc_ns);
18635 +
18636 +       ns = nsproxy->mnt_ns;
18637 +       if (!ns)
18638 +               goto skip_ns;
18639 +
18640 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
18641 +       if (!pstr)
18642 +               goto skip_ns;
18643 +
18644 +       path.mnt = ns->root;
18645 +       path.dentry = ns->root->mnt_root;
18646 +       root = d_path(&path, pstr, PATH_MAX - 2);
18647 +       length += sprintf(buffer + length,
18648 +               "Namespace:\t%p [#%u]\n"
18649 +               "RootPath:\t%s\n",
18650 +               ns, atomic_read(&ns->count),
18651 +               root);
18652 +       kfree(pstr);
18653 +skip_ns:
18654 +
18655 +       uts = nsproxy->uts_ns;
18656 +       if (!uts)
18657 +               goto skip_uts;
18658 +
18659 +       length += sprintf(buffer + length,
18660 +               "SysName:\t%.*s\n"
18661 +               "NodeName:\t%.*s\n"
18662 +               "Release:\t%.*s\n"
18663 +               "Version:\t%.*s\n"
18664 +               "Machine:\t%.*s\n"
18665 +               "DomainName:\t%.*s\n",
18666 +               __NEW_UTS_LEN, uts->name.sysname,
18667 +               __NEW_UTS_LEN, uts->name.nodename,
18668 +               __NEW_UTS_LEN, uts->name.release,
18669 +               __NEW_UTS_LEN, uts->name.version,
18670 +               __NEW_UTS_LEN, uts->name.machine,
18671 +               __NEW_UTS_LEN, uts->name.domainname);
18672 +skip_uts:
18673 +
18674 +       ipc = nsproxy->ipc_ns;
18675 +       if (!ipc)
18676 +               goto skip_ipc;
18677 +
18678 +       length += sprintf(buffer + length,
18679 +               "SEMS:\t\t%d %d %d %d  %d\n"
18680 +               "MSG:\t\t%d %d %d\n"
18681 +               "SHM:\t\t%lu %lu  %d %d\n",
18682 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
18683 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
18684 +               ipc->used_sems,
18685 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
18686 +               (unsigned long)ipc->shm_ctlmax,
18687 +               (unsigned long)ipc->shm_ctlall,
18688 +               ipc->shm_ctlmni, ipc->shm_tot);
18689 +skip_ipc:
18690 +out:
18691 +       return length;
18692 +}
18693 +
18694 +
18695 +#include <linux/sched.h>
18696 +
18697 +#define LOAD_INT(x) ((x) >> FSHIFT)
18698 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
18699 +
18700 +static inline
18701 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
18702 +{
18703 +       int length = 0;
18704 +       int a, b, c;
18705 +
18706 +       length += sprintf(buffer + length,
18707 +               "BiasUptime:\t%lu.%02lu\n",
18708 +               (unsigned long)cvirt->bias_uptime.tv_sec,
18709 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
18710 +
18711 +       a = cvirt->load[0] + (FIXED_1 / 200);
18712 +       b = cvirt->load[1] + (FIXED_1 / 200);
18713 +       c = cvirt->load[2] + (FIXED_1 / 200);
18714 +       length += sprintf(buffer + length,
18715 +               "nr_threads:\t%d\n"
18716 +               "nr_running:\t%d\n"
18717 +               "nr_unintr:\t%d\n"
18718 +               "nr_onhold:\t%d\n"
18719 +               "load_updates:\t%d\n"
18720 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
18721 +               "total_forks:\t%d\n",
18722 +               atomic_read(&cvirt->nr_threads),
18723 +               atomic_read(&cvirt->nr_running),
18724 +               atomic_read(&cvirt->nr_uninterruptible),
18725 +               atomic_read(&cvirt->nr_onhold),
18726 +               atomic_read(&cvirt->load_updates),
18727 +               LOAD_INT(a), LOAD_FRAC(a),
18728 +               LOAD_INT(b), LOAD_FRAC(b),
18729 +               LOAD_INT(c), LOAD_FRAC(c),
18730 +               atomic_read(&cvirt->total_forks));
18731 +       return length;
18732 +}
18733 +
18734 +static inline
18735 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
18736 +       char *buffer, int cpu)
18737 +{
18738 +       int length = 0;
18739 +       return length;
18740 +}
18741 +
18742 +#endif /* _VX_CVIRT_PROC_H */
18743 diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/debug.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/debug.c
18744 --- linux-2.6.29.4/kernel/vserver/debug.c       1970-01-01 01:00:00.000000000 +0100
18745 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/debug.c 2009-02-22 22:54:26.000000000 +0100
18746 @@ -0,0 +1,32 @@
18747 +/*
18748 + *  kernel/vserver/debug.c
18749 + *
18750 + *  Copyright (C) 2005-2007 Herbert Pötzl
18751 + *
18752 + *  V0.01  vx_info dump support
18753 + *
18754 + */
18755 +
18756 +#include <linux/module.h>
18757 +
18758 +#include <linux/vserver/context.h>
18759 +
18760 +
18761 +void   dump_vx_info(struct vx_info *vxi, int level)
18762 +{
18763 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
18764 +               atomic_read(&vxi->vx_usecnt),
18765 +               atomic_read(&vxi->vx_tasks),
18766 +               vxi->vx_state);
18767 +       if (level > 0) {
18768 +               __dump_vx_limit(&vxi->limit);
18769 +               __dump_vx_sched(&vxi->sched);
18770 +               __dump_vx_cvirt(&vxi->cvirt);
18771 +               __dump_vx_cacct(&vxi->cacct);
18772 +       }
18773 +       printk("---\n");
18774 +}
18775 +
18776 +
18777 +EXPORT_SYMBOL_GPL(dump_vx_info);
18778 +
18779 diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/device.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/device.c
18780 --- linux-2.6.29.4/kernel/vserver/device.c      1970-01-01 01:00:00.000000000 +0100
18781 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/device.c        2009-02-22 22:54:26.000000000 +0100
18782 @@ -0,0 +1,443 @@
18783 +/*
18784 + *  linux/kernel/vserver/device.c
18785 + *
18786 + *  Linux-VServer: Device Support
18787 + *
18788 + *  Copyright (C) 2006  Herbert Pötzl
18789 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
18790 + *
18791 + *  V0.01  device mapping basics
18792 + *  V0.02  added defaults
18793 + *
18794 + */
18795 +
18796 +#include <linux/slab.h>
18797 +#include <linux/rcupdate.h>
18798 +#include <linux/fs.h>
18799 +#include <linux/namei.h>
18800 +#include <linux/hash.h>
18801 +
18802 +#include <asm/errno.h>
18803 +#include <asm/uaccess.h>
18804 +#include <linux/vserver/base.h>
18805 +#include <linux/vserver/debug.h>
18806 +#include <linux/vserver/context.h>
18807 +#include <linux/vserver/device.h>
18808 +#include <linux/vserver/device_cmd.h>
18809 +
18810 +
18811 +#define DMAP_HASH_BITS 4
18812 +
18813 +
18814 +struct vs_mapping {
18815 +       union {
18816 +               struct hlist_node hlist;
18817 +               struct list_head list;
18818 +       } u;
18819 +#define dm_hlist       u.hlist
18820 +#define dm_list                u.list
18821 +       xid_t xid;
18822 +       dev_t device;
18823 +       struct vx_dmap_target target;
18824 +};
18825 +
18826 +
18827 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
18828 +
18829 +static spinlock_t dmap_main_hash_lock = SPIN_LOCK_UNLOCKED;
18830 +
18831 +static struct vx_dmap_target dmap_defaults[2] = {
18832 +       { .flags = DATTR_OPEN },
18833 +       { .flags = DATTR_OPEN },
18834 +};
18835 +
18836 +
18837 +struct kmem_cache *dmap_cachep __read_mostly;
18838 +
18839 +int __init dmap_cache_init(void)
18840 +{
18841 +       dmap_cachep = kmem_cache_create("dmap_cache",
18842 +               sizeof(struct vs_mapping), 0,
18843 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
18844 +       return 0;
18845 +}
18846 +
18847 +__initcall(dmap_cache_init);
18848 +
18849 +
18850 +static inline unsigned int __hashval(dev_t dev, int bits)
18851 +{
18852 +       return hash_long((unsigned long)dev, bits);
18853 +}
18854 +
18855 +
18856 +/*     __hash_mapping()
18857 + *     add the mapping to the hash table
18858 + */
18859 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
18860 +{
18861 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18862 +       struct hlist_head *head, *hash = dmap_main_hash;
18863 +       int device = vdm->device;
18864 +
18865 +       spin_lock(hash_lock);
18866 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
18867 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
18868 +
18869 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
18870 +       hlist_add_head(&vdm->dm_hlist, head);
18871 +       spin_unlock(hash_lock);
18872 +}
18873 +
18874 +
18875 +static inline int __mode_to_default(umode_t mode)
18876 +{
18877 +       switch (mode) {
18878 +       case S_IFBLK:
18879 +               return 0;
18880 +       case S_IFCHR:
18881 +               return 1;
18882 +       default:
18883 +               BUG();
18884 +       }
18885 +}
18886 +
18887 +
18888 +/*     __set_default()
18889 + *     set a default
18890 + */
18891 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
18892 +       struct vx_dmap_target *vdmt)
18893 +{
18894 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18895 +       spin_lock(hash_lock);
18896 +
18897 +       if (vxi)
18898 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
18899 +       else
18900 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
18901 +
18902 +
18903 +       spin_unlock(hash_lock);
18904 +
18905 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
18906 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
18907 +}
18908 +
18909 +
18910 +/*     __remove_default()
18911 + *     remove a default
18912 + */
18913 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
18914 +{
18915 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18916 +       spin_lock(hash_lock);
18917 +
18918 +       if (vxi)
18919 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
18920 +       else    /* remove == reset */
18921 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
18922 +
18923 +       spin_unlock(hash_lock);
18924 +       return 0;
18925 +}
18926 +
18927 +
18928 +/*     __find_mapping()
18929 + *     find a mapping in the hash table
18930 + *
18931 + *     caller must hold hash_lock
18932 + */
18933 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
18934 +       struct vs_mapping **local, struct vs_mapping **global)
18935 +{
18936 +       struct hlist_head *hash = dmap_main_hash;
18937 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
18938 +       struct hlist_node *pos;
18939 +       struct vs_mapping *vdm;
18940 +
18941 +       *local = NULL;
18942 +       if (global)
18943 +               *global = NULL;
18944 +
18945 +       hlist_for_each(pos, head) {
18946 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
18947 +
18948 +               if ((vdm->device == device) &&
18949 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
18950 +                       if (vdm->xid == xid) {
18951 +                               *local = vdm;
18952 +                               return 1;
18953 +                       } else if (global && vdm->xid == 0)
18954 +                               *global = vdm;
18955 +               }
18956 +       }
18957 +
18958 +       if (global && *global)
18959 +               return 0;
18960 +       else
18961 +               return -ENOENT;
18962 +}
18963 +
18964 +
18965 +/*     __lookup_mapping()
18966 + *     find a mapping and store the result in target and flags
18967 + */
18968 +static inline int __lookup_mapping(struct vx_info *vxi,
18969 +       dev_t device, dev_t *target, int *flags, umode_t mode)
18970 +{
18971 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
18972 +       struct vs_mapping *vdm, *global;
18973 +       struct vx_dmap_target *vdmt;
18974 +       int ret = 0;
18975 +       xid_t xid = vxi->vx_id;
18976 +       int index;
18977 +
18978 +       spin_lock(hash_lock);
18979 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
18980 +               ret = 1;
18981 +               vdmt = &vdm->target;
18982 +               goto found;
18983 +       }
18984 +
18985 +       index = __mode_to_default(mode);
18986 +       if (vxi && vxi->dmap.targets[index].flags) {
18987 +               ret = 2;
18988 +               vdmt = &vxi->dmap.targets[index];
18989 +       } else if (global) {
18990 +               ret = 3;
18991 +               vdmt = &global->target;
18992 +               goto found;
18993 +       } else {
18994 +               ret = 4;
18995 +               vdmt = &dmap_defaults[index];
18996 +       }
18997 +
18998 +found:
18999 +       if (target && (vdmt->flags & DATTR_REMAP))
19000 +               *target = vdmt->target;
19001 +       else if (target)
19002 +               *target = device;
19003 +       if (flags)
19004 +               *flags = vdmt->flags;
19005 +
19006 +       spin_unlock(hash_lock);
19007 +
19008 +       return ret;
19009 +}
19010 +
19011 +
19012 +/*     __remove_mapping()
19013 + *     remove a mapping from the hash table
19014 + */
19015 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
19016 +       umode_t mode)
19017 +{
19018 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
19019 +       struct vs_mapping *vdm = NULL;
19020 +       int ret = 0;
19021 +
19022 +       spin_lock(hash_lock);
19023 +
19024 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
19025 +               NULL);
19026 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
19027 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
19028 +       if (ret < 0)
19029 +               goto out;
19030 +       hlist_del(&vdm->dm_hlist);
19031 +
19032 +out:
19033 +       spin_unlock(hash_lock);
19034 +       if (vdm)
19035 +               kmem_cache_free(dmap_cachep, vdm);
19036 +       return ret;
19037 +}
19038 +
19039 +
19040 +
19041 +int vs_map_device(struct vx_info *vxi,
19042 +       dev_t device, dev_t *target, umode_t mode)
19043 +{
19044 +       int ret, flags = DATTR_MASK;
19045 +
19046 +       if (!vxi) {
19047 +               if (target)
19048 +                       *target = device;
19049 +               goto out;
19050 +       }
19051 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
19052 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
19053 +               device, target ? *target : 0, flags, mode, ret);
19054 +out:
19055 +       return (flags & DATTR_MASK);
19056 +}
19057 +
19058 +
19059 +
19060 +static int do_set_mapping(struct vx_info *vxi,
19061 +       dev_t device, dev_t target, int flags, umode_t mode)
19062 +{
19063 +       if (device) {
19064 +               struct vs_mapping *new;
19065 +
19066 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
19067 +               if (!new)
19068 +                       return -ENOMEM;
19069 +
19070 +               INIT_HLIST_NODE(&new->dm_hlist);
19071 +               new->device = device;
19072 +               new->target.target = target;
19073 +               new->target.flags = flags | mode;
19074 +               new->xid = (vxi ? vxi->vx_id : 0);
19075 +
19076 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
19077 +               __hash_mapping(vxi, new);
19078 +       } else {
19079 +               struct vx_dmap_target new = {
19080 +                       .target = target,
19081 +                       .flags = flags | mode,
19082 +               };
19083 +               __set_default(vxi, mode, &new);
19084 +       }
19085 +       return 0;
19086 +}
19087 +
19088 +
19089 +static int do_unset_mapping(struct vx_info *vxi,
19090 +       dev_t device, dev_t target, int flags, umode_t mode)
19091 +{
19092 +       int ret = -EINVAL;
19093 +
19094 +       if (device) {
19095 +               ret = __remove_mapping(vxi, device, mode);
19096 +               if (ret < 0)
19097 +                       goto out;
19098 +       } else {
19099 +               ret = __remove_default(vxi, mode);
19100 +               if (ret < 0)
19101 +                       goto out;
19102 +       }
19103 +
19104 +out:
19105 +       return ret;
19106 +}
19107 +
19108 +
19109 +static inline int __user_device(const char __user *name, dev_t *dev,
19110 +       umode_t *mode)
19111 +{
19112 +       struct nameidata nd;
19113 +       int ret;
19114 +
19115 +       if (!name) {
19116 +               *dev = 0;
19117 +               return 0;
19118 +       }
19119 +       ret = user_lpath(name, &nd.path);
19120 +       if (ret)
19121 +               return ret;
19122 +       if (nd.path.dentry->d_inode) {
19123 +               *dev = nd.path.dentry->d_inode->i_rdev;
19124 +               *mode = nd.path.dentry->d_inode->i_mode;
19125 +       }
19126 +       path_put(&nd.path);
19127 +       return 0;
19128 +}
19129 +
19130 +static inline int __mapping_mode(dev_t device, dev_t target,
19131 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
19132 +{
19133 +       if (device)
19134 +               *mode = device_mode & S_IFMT;
19135 +       else if (target)
19136 +               *mode = target_mode & S_IFMT;
19137 +       else
19138 +               return -EINVAL;
19139 +
19140 +       /* if both given, device and target mode have to match */
19141 +       if (device && target &&
19142 +               ((device_mode ^ target_mode) & S_IFMT))
19143 +               return -EINVAL;
19144 +       return 0;
19145 +}
19146 +
19147 +
19148 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
19149 +       const char __user *target_path, int flags, int set)
19150 +{
19151 +       dev_t device = ~0, target = ~0;
19152 +       umode_t device_mode = 0, target_mode = 0, mode;
19153 +       int ret;
19154 +
19155 +       ret = __user_device(device_path, &device, &device_mode);
19156 +       if (ret)
19157 +               return ret;
19158 +       ret = __user_device(target_path, &target, &target_mode);
19159 +       if (ret)
19160 +               return ret;
19161 +
19162 +       ret = __mapping_mode(device, target,
19163 +               device_mode, target_mode, &mode);
19164 +       if (ret)
19165 +               return ret;
19166 +
19167 +       if (set)
19168 +               return do_set_mapping(vxi, device, target,
19169 +                       flags, mode);
19170 +       else
19171 +               return do_unset_mapping(vxi, device, target,
19172 +                       flags, mode);
19173 +}
19174 +
19175 +
19176 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
19177 +{
19178 +       struct vcmd_set_mapping_v0 vc_data;
19179 +
19180 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19181 +               return -EFAULT;
19182 +
19183 +       return do_mapping(vxi, vc_data.device, vc_data.target,
19184 +               vc_data.flags, 1);
19185 +}
19186 +
19187 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
19188 +{
19189 +       struct vcmd_set_mapping_v0 vc_data;
19190 +
19191 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19192 +               return -EFAULT;
19193 +
19194 +       return do_mapping(vxi, vc_data.device, vc_data.target,
19195 +               vc_data.flags, 0);
19196 +}
19197 +
19198 +
19199 +#ifdef CONFIG_COMPAT
19200 +
19201 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
19202 +{
19203 +       struct vcmd_set_mapping_v0_x32 vc_data;
19204 +
19205 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19206 +               return -EFAULT;
19207 +
19208 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
19209 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
19210 +}
19211 +
19212 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
19213 +{
19214 +       struct vcmd_set_mapping_v0_x32 vc_data;
19215 +
19216 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19217 +               return -EFAULT;
19218 +
19219 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
19220 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
19221 +}
19222 +
19223 +#endif /* CONFIG_COMPAT */
19224 +
19225 +
19226 diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/dlimit.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/dlimit.c
19227 --- linux-2.6.29.4/kernel/vserver/dlimit.c      1970-01-01 01:00:00.000000000 +0100
19228 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/dlimit.c        2009-02-22 22:54:26.000000000 +0100
19229 @@ -0,0 +1,522 @@
19230 +/*
19231 + *  linux/kernel/vserver/dlimit.c
19232 + *
19233 + *  Virtual Server: Context Disk Limits
19234 + *
19235 + *  Copyright (C) 2004-2007  Herbert Pötzl
19236 + *
19237 + *  V0.01  initial version
19238 + *  V0.02  compat32 splitup
19239 + *
19240 + */
19241 +
19242 +#include <linux/statfs.h>
19243 +#include <linux/sched.h>
19244 +#include <linux/namei.h>
19245 +#include <linux/vs_tag.h>
19246 +#include <linux/vs_dlimit.h>
19247 +#include <linux/vserver/dlimit_cmd.h>
19248 +
19249 +#include <asm/uaccess.h>
19250 +
19251 +/*     __alloc_dl_info()
19252 +
19253 +       * allocate an initialized dl_info struct
19254 +       * doesn't make it visible (hash)                        */
19255 +
19256 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
19257 +{
19258 +       struct dl_info *new = NULL;
19259 +
19260 +       vxdprintk(VXD_CBIT(dlim, 5),
19261 +               "alloc_dl_info(%p,%d)*", sb, tag);
19262 +
19263 +       /* would this benefit from a slab cache? */
19264 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
19265 +       if (!new)
19266 +               return 0;
19267 +
19268 +       memset(new, 0, sizeof(struct dl_info));
19269 +       new->dl_tag = tag;
19270 +       new->dl_sb = sb;
19271 +       INIT_RCU_HEAD(&new->dl_rcu);
19272 +       INIT_HLIST_NODE(&new->dl_hlist);
19273 +       spin_lock_init(&new->dl_lock);
19274 +       atomic_set(&new->dl_refcnt, 0);
19275 +       atomic_set(&new->dl_usecnt, 0);
19276 +
19277 +       /* rest of init goes here */
19278 +
19279 +       vxdprintk(VXD_CBIT(dlim, 4),
19280 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
19281 +       return new;
19282 +}
19283 +
19284 +/*     __dealloc_dl_info()
19285 +
19286 +       * final disposal of dl_info                             */
19287 +
19288 +static void __dealloc_dl_info(struct dl_info *dli)
19289 +{
19290 +       vxdprintk(VXD_CBIT(dlim, 4),
19291 +               "dealloc_dl_info(%p)", dli);
19292 +
19293 +       dli->dl_hlist.next = LIST_POISON1;
19294 +       dli->dl_tag = -1;
19295 +       dli->dl_sb = 0;
19296 +
19297 +       BUG_ON(atomic_read(&dli->dl_usecnt));
19298 +       BUG_ON(atomic_read(&dli->dl_refcnt));
19299 +
19300 +       kfree(dli);
19301 +}
19302 +
19303 +
19304 +/*     hash table for dl_info hash */
19305 +
19306 +#define DL_HASH_SIZE   13
19307 +
19308 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
19309 +
19310 +static spinlock_t dl_info_hash_lock = SPIN_LOCK_UNLOCKED;
19311 +
19312 +
19313 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
19314 +{
19315 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
19316 +}
19317 +
19318 +
19319 +
19320 +/*     __hash_dl_info()
19321 +
19322 +       * add the dli to the global hash table
19323 +       * requires the hash_lock to be held                     */
19324 +
19325 +static inline void __hash_dl_info(struct dl_info *dli)
19326 +{
19327 +       struct hlist_head *head;
19328 +
19329 +       vxdprintk(VXD_CBIT(dlim, 6),
19330 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
19331 +       get_dl_info(dli);
19332 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
19333 +       hlist_add_head_rcu(&dli->dl_hlist, head);
19334 +}
19335 +
19336 +/*     __unhash_dl_info()
19337 +
19338 +       * remove the dli from the global hash table
19339 +       * requires the hash_lock to be held                     */
19340 +
19341 +static inline void __unhash_dl_info(struct dl_info *dli)
19342 +{
19343 +       vxdprintk(VXD_CBIT(dlim, 6),
19344 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
19345 +       hlist_del_rcu(&dli->dl_hlist);
19346 +       put_dl_info(dli);
19347 +}
19348 +
19349 +
19350 +/*     __lookup_dl_info()
19351 +
19352 +       * requires the rcu_read_lock()
19353 +       * doesn't increment the dl_refcnt                       */
19354 +
19355 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
19356 +{
19357 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
19358 +       struct hlist_node *pos;
19359 +       struct dl_info *dli;
19360 +
19361 +       hlist_for_each_entry_rcu(dli, pos, head, dl_hlist) {
19362 +
19363 +               if (dli->dl_tag == tag && dli->dl_sb == sb) {
19364 +                       return dli;
19365 +               }
19366 +       }
19367 +       return NULL;
19368 +}
19369 +
19370 +
19371 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
19372 +{
19373 +       struct dl_info *dli;
19374 +
19375 +       rcu_read_lock();
19376 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
19377 +       vxdprintk(VXD_CBIT(dlim, 7),
19378 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
19379 +       rcu_read_unlock();
19380 +       return dli;
19381 +}
19382 +
19383 +void rcu_free_dl_info(struct rcu_head *head)
19384 +{
19385 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
19386 +       int usecnt, refcnt;
19387 +
19388 +       BUG_ON(!dli || !head);
19389 +
19390 +       usecnt = atomic_read(&dli->dl_usecnt);
19391 +       BUG_ON(usecnt < 0);
19392 +
19393 +       refcnt = atomic_read(&dli->dl_refcnt);
19394 +       BUG_ON(refcnt < 0);
19395 +
19396 +       vxdprintk(VXD_CBIT(dlim, 3),
19397 +               "rcu_free_dl_info(%p)", dli);
19398 +       if (!usecnt)
19399 +               __dealloc_dl_info(dli);
19400 +       else
19401 +               printk("!!! rcu didn't free\n");
19402 +}
19403 +
19404 +
19405 +
19406 +
19407 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
19408 +       uint32_t flags, int add)
19409 +{
19410 +       struct path path;
19411 +       int ret;
19412 +
19413 +       ret = user_lpath(name, &path);
19414 +       if (!ret) {
19415 +               struct super_block *sb;
19416 +               struct dl_info *dli;
19417 +
19418 +               ret = -EINVAL;
19419 +               if (!path.dentry->d_inode)
19420 +                       goto out_release;
19421 +               if (!(sb = path.dentry->d_inode->i_sb))
19422 +                       goto out_release;
19423 +
19424 +               if (add) {
19425 +                       dli = __alloc_dl_info(sb, id);
19426 +                       spin_lock(&dl_info_hash_lock);
19427 +
19428 +                       ret = -EEXIST;
19429 +                       if (__lookup_dl_info(sb, id))
19430 +                               goto out_unlock;
19431 +                       __hash_dl_info(dli);
19432 +                       dli = NULL;
19433 +               } else {
19434 +                       spin_lock(&dl_info_hash_lock);
19435 +                       dli = __lookup_dl_info(sb, id);
19436 +
19437 +                       ret = -ESRCH;
19438 +                       if (!dli)
19439 +                               goto out_unlock;
19440 +                       __unhash_dl_info(dli);
19441 +               }
19442 +               ret = 0;
19443 +       out_unlock:
19444 +               spin_unlock(&dl_info_hash_lock);
19445 +               if (add && dli)
19446 +                       __dealloc_dl_info(dli);
19447 +       out_release:
19448 +               path_put(&path);
19449 +       }
19450 +       return ret;
19451 +}
19452 +
19453 +int vc_add_dlimit(uint32_t id, void __user *data)
19454 +{
19455 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
19456 +
19457 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19458 +               return -EFAULT;
19459 +
19460 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
19461 +}
19462 +
19463 +int vc_rem_dlimit(uint32_t id, void __user *data)
19464 +{
19465 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
19466 +
19467 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19468 +               return -EFAULT;
19469 +
19470 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
19471 +}
19472 +
19473 +#ifdef CONFIG_COMPAT
19474 +
19475 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
19476 +{
19477 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
19478 +
19479 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19480 +               return -EFAULT;
19481 +
19482 +       return do_addrem_dlimit(id,
19483 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
19484 +}
19485 +
19486 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
19487 +{
19488 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
19489 +
19490 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19491 +               return -EFAULT;
19492 +
19493 +       return do_addrem_dlimit(id,
19494 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
19495 +}
19496 +
19497 +#endif /* CONFIG_COMPAT */
19498 +
19499 +
19500 +static inline
19501 +int do_set_dlimit(uint32_t id, const char __user *name,
19502 +       uint32_t space_used, uint32_t space_total,
19503 +       uint32_t inodes_used, uint32_t inodes_total,
19504 +       uint32_t reserved, uint32_t flags)
19505 +{
19506 +       struct path path;
19507 +       int ret;
19508 +
19509 +       ret = user_lpath(name, &path);
19510 +       if (!ret) {
19511 +               struct super_block *sb;
19512 +               struct dl_info *dli;
19513 +
19514 +               ret = -EINVAL;
19515 +               if (!path.dentry->d_inode)
19516 +                       goto out_release;
19517 +               if (!(sb = path.dentry->d_inode->i_sb))
19518 +                       goto out_release;
19519 +               if ((reserved != CDLIM_KEEP &&
19520 +                       reserved > 100) ||
19521 +                       (inodes_used != CDLIM_KEEP &&
19522 +                       inodes_used > inodes_total) ||
19523 +                       (space_used != CDLIM_KEEP &&
19524 +                       space_used > space_total))
19525 +                       goto out_release;
19526 +
19527 +               ret = -ESRCH;
19528 +               dli = locate_dl_info(sb, id);
19529 +               if (!dli)
19530 +                       goto out_release;
19531 +
19532 +               spin_lock(&dli->dl_lock);
19533 +
19534 +               if (inodes_used != CDLIM_KEEP)
19535 +                       dli->dl_inodes_used = inodes_used;
19536 +               if (inodes_total != CDLIM_KEEP)
19537 +                       dli->dl_inodes_total = inodes_total;
19538 +               if (space_used != CDLIM_KEEP) {
19539 +                       dli->dl_space_used = space_used;
19540 +                       dli->dl_space_used <<= 10;
19541 +               }
19542 +               if (space_total == CDLIM_INFINITY)
19543 +                       dli->dl_space_total = DLIM_INFINITY;
19544 +               else if (space_total != CDLIM_KEEP) {
19545 +                       dli->dl_space_total = space_total;
19546 +                       dli->dl_space_total <<= 10;
19547 +               }
19548 +               if (reserved != CDLIM_KEEP)
19549 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
19550 +
19551 +               spin_unlock(&dli->dl_lock);
19552 +
19553 +               put_dl_info(dli);
19554 +               ret = 0;
19555 +
19556 +       out_release:
19557 +               path_put(&path);
19558 +       }
19559 +       return ret;
19560 +}
19561 +
19562 +int vc_set_dlimit(uint32_t id, void __user *data)
19563 +{
19564 +       struct vcmd_ctx_dlimit_v0 vc_data;
19565 +
19566 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19567 +               return -EFAULT;
19568 +
19569 +       return do_set_dlimit(id, vc_data.name,
19570 +               vc_data.space_used, vc_data.space_total,
19571 +               vc_data.inodes_used, vc_data.inodes_total,
19572 +               vc_data.reserved, vc_data.flags);
19573 +}
19574 +
19575 +#ifdef CONFIG_COMPAT
19576 +
19577 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
19578 +{
19579 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
19580 +
19581 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19582 +               return -EFAULT;
19583 +
19584 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
19585 +               vc_data.space_used, vc_data.space_total,
19586 +               vc_data.inodes_used, vc_data.inodes_total,
19587 +               vc_data.reserved, vc_data.flags);
19588 +}
19589 +
19590 +#endif /* CONFIG_COMPAT */
19591 +
19592 +
19593 +static inline
19594 +int do_get_dlimit(uint32_t id, const char __user *name,
19595 +       uint32_t *space_used, uint32_t *space_total,
19596 +       uint32_t *inodes_used, uint32_t *inodes_total,
19597 +       uint32_t *reserved, uint32_t *flags)
19598 +{
19599 +       struct path path;
19600 +       int ret;
19601 +
19602 +       ret = user_lpath(name, &path);
19603 +       if (!ret) {
19604 +               struct super_block *sb;
19605 +               struct dl_info *dli;
19606 +
19607 +               ret = -EINVAL;
19608 +               if (!path.dentry->d_inode)
19609 +                       goto out_release;
19610 +               if (!(sb = path.dentry->d_inode->i_sb))
19611 +                       goto out_release;
19612 +
19613 +               ret = -ESRCH;
19614 +               dli = locate_dl_info(sb, id);
19615 +               if (!dli)
19616 +                       goto out_release;
19617 +
19618 +               spin_lock(&dli->dl_lock);
19619 +               *inodes_used = dli->dl_inodes_used;
19620 +               *inodes_total = dli->dl_inodes_total;
19621 +               *space_used = dli->dl_space_used >> 10;
19622 +               if (dli->dl_space_total == DLIM_INFINITY)
19623 +                       *space_total = CDLIM_INFINITY;
19624 +               else
19625 +                       *space_total = dli->dl_space_total >> 10;
19626 +
19627 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
19628 +               spin_unlock(&dli->dl_lock);
19629 +
19630 +               put_dl_info(dli);
19631 +               ret = -EFAULT;
19632 +
19633 +               ret = 0;
19634 +       out_release:
19635 +               path_put(&path);
19636 +       }
19637 +       return ret;
19638 +}
19639 +
19640 +
19641 +int vc_get_dlimit(uint32_t id, void __user *data)
19642 +{
19643 +       struct vcmd_ctx_dlimit_v0 vc_data;
19644 +       int ret;
19645 +
19646 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19647 +               return -EFAULT;
19648 +
19649 +       ret = do_get_dlimit(id, vc_data.name,
19650 +               &vc_data.space_used, &vc_data.space_total,
19651 +               &vc_data.inodes_used, &vc_data.inodes_total,
19652 +               &vc_data.reserved, &vc_data.flags);
19653 +       if (ret)
19654 +               return ret;
19655 +
19656 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19657 +               return -EFAULT;
19658 +       return 0;
19659 +}
19660 +
19661 +#ifdef CONFIG_COMPAT
19662 +
19663 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
19664 +{
19665 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
19666 +       int ret;
19667 +
19668 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19669 +               return -EFAULT;
19670 +
19671 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
19672 +               &vc_data.space_used, &vc_data.space_total,
19673 +               &vc_data.inodes_used, &vc_data.inodes_total,
19674 +               &vc_data.reserved, &vc_data.flags);
19675 +       if (ret)
19676 +               return ret;
19677 +
19678 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19679 +               return -EFAULT;
19680 +       return 0;
19681 +}
19682 +
19683 +#endif /* CONFIG_COMPAT */
19684 +
19685 +
19686 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
19687 +{
19688 +       struct dl_info *dli;
19689 +       __u64 blimit, bfree, bavail;
19690 +       __u32 ifree;
19691 +
19692 +       dli = locate_dl_info(sb, dx_current_tag());
19693 +       if (!dli)
19694 +               return;
19695 +
19696 +       spin_lock(&dli->dl_lock);
19697 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
19698 +               goto no_ilim;
19699 +
19700 +       /* reduce max inodes available to limit */
19701 +       if (buf->f_files > dli->dl_inodes_total)
19702 +               buf->f_files = dli->dl_inodes_total;
19703 +
19704 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
19705 +       /* reduce free inodes to min */
19706 +       if (ifree < buf->f_ffree)
19707 +               buf->f_ffree = ifree;
19708 +
19709 +no_ilim:
19710 +       if (dli->dl_space_total == DLIM_INFINITY)
19711 +               goto no_blim;
19712 +
19713 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
19714 +
19715 +       if (dli->dl_space_total < dli->dl_space_used)
19716 +               bfree = 0;
19717 +       else
19718 +               bfree = (dli->dl_space_total - dli->dl_space_used)
19719 +                       >> sb->s_blocksize_bits;
19720 +
19721 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
19722 +       if (bavail < dli->dl_space_used)
19723 +               bavail = 0;
19724 +       else
19725 +               bavail = (bavail - dli->dl_space_used)
19726 +                       >> sb->s_blocksize_bits;
19727 +
19728 +       /* reduce max space available to limit */
19729 +       if (buf->f_blocks > blimit)
19730 +               buf->f_blocks = blimit;
19731 +
19732 +       /* reduce free space to min */
19733 +       if (bfree < buf->f_bfree)
19734 +               buf->f_bfree = bfree;
19735 +
19736 +       /* reduce avail space to min */
19737 +       if (bavail < buf->f_bavail)
19738 +               buf->f_bavail = bavail;
19739 +
19740 +no_blim:
19741 +       spin_unlock(&dli->dl_lock);
19742 +       put_dl_info(dli);
19743 +
19744 +       return;
19745 +}
19746 +
19747 +#include <linux/module.h>
19748 +
19749 +EXPORT_SYMBOL_GPL(locate_dl_info);
19750 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
19751 +
19752 diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/helper.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/helper.c
19753 --- linux-2.6.29.4/kernel/vserver/helper.c      1970-01-01 01:00:00.000000000 +0100
19754 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/helper.c        2009-03-25 00:40:43.000000000 +0100
19755 @@ -0,0 +1,199 @@
19756 +/*
19757 + *  linux/kernel/vserver/helper.c
19758 + *
19759 + *  Virtual Context Support
19760 + *
19761 + *  Copyright (C) 2004-2007  Herbert Pötzl
19762 + *
19763 + *  V0.01  basic helper
19764 + *
19765 + */
19766 +
19767 +#include <linux/kmod.h>
19768 +#include <linux/reboot.h>
19769 +#include <linux/vs_context.h>
19770 +#include <linux/vs_network.h>
19771 +#include <linux/vserver/signal.h>
19772 +
19773 +
19774 +char vshelper_path[255] = "/sbin/vshelper";
19775 +
19776 +
19777 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
19778 +{
19779 +       int ret;
19780 +
19781 +       if ((ret = call_usermodehelper(name, argv, envp, sync))) {
19782 +               printk( KERN_WARNING
19783 +                       "%s: (%s %s) returned %s with %d\n",
19784 +                       name, argv[1], argv[2],
19785 +                       sync ? "sync" : "async", ret);
19786 +       }
19787 +       vxdprintk(VXD_CBIT(switch, 4),
19788 +               "%s: (%s %s) returned %s with %d",
19789 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
19790 +       return ret;
19791 +}
19792 +
19793 +/*
19794 + *      vshelper path is set via /proc/sys
19795 + *      invoked by vserver sys_reboot(), with
19796 + *      the following arguments
19797 + *
19798 + *      argv [0] = vshelper_path;
19799 + *      argv [1] = action: "restart", "halt", "poweroff", ...
19800 + *      argv [2] = context identifier
19801 + *
19802 + *      envp [*] = type-specific parameters
19803 + */
19804 +
19805 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
19806 +{
19807 +       char id_buf[8], cmd_buf[16];
19808 +       char uid_buf[16], pid_buf[16];
19809 +       int ret;
19810 +
19811 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
19812 +       char *envp[] = {"HOME=/", "TERM=linux",
19813 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
19814 +                       uid_buf, pid_buf, cmd_buf, 0};
19815 +
19816 +       if (vx_info_state(vxi, VXS_HELPER))
19817 +               return -EAGAIN;
19818 +       vxi->vx_state |= VXS_HELPER;
19819 +
19820 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
19821 +
19822 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
19823 +       snprintf(uid_buf, sizeof(uid_buf)-1, "VS_UID=%d", current_uid());
19824 +       snprintf(pid_buf, sizeof(pid_buf)-1, "VS_PID=%d", current->pid);
19825 +
19826 +       switch (cmd) {
19827 +       case LINUX_REBOOT_CMD_RESTART:
19828 +               argv[1] = "restart";
19829 +               break;
19830 +
19831 +       case LINUX_REBOOT_CMD_HALT:
19832 +               argv[1] = "halt";
19833 +               break;
19834 +
19835 +       case LINUX_REBOOT_CMD_POWER_OFF:
19836 +               argv[1] = "poweroff";
19837 +               break;
19838 +
19839 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
19840 +               argv[1] = "swsusp";
19841 +               break;
19842 +
19843 +       default:
19844 +               vxi->vx_state &= ~VXS_HELPER;
19845 +               return 0;
19846 +       }
19847 +
19848 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
19849 +       vxi->vx_state &= ~VXS_HELPER;
19850 +       __wakeup_vx_info(vxi);
19851 +       return (ret) ? -EPERM : 0;
19852 +}
19853 +
19854 +
19855 +long vs_reboot(unsigned int cmd, void __user *arg)
19856 +{
19857 +       struct vx_info *vxi = current->vx_info;
19858 +       long ret = 0;
19859 +
19860 +       vxdprintk(VXD_CBIT(misc, 5),
19861 +               "vs_reboot(%p[#%d],%d)",
19862 +               vxi, vxi ? vxi->vx_id : 0, cmd);
19863 +
19864 +       ret = vs_reboot_helper(vxi, cmd, arg);
19865 +       if (ret)
19866 +               return ret;
19867 +
19868 +       vxi->reboot_cmd = cmd;
19869 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
19870 +               switch (cmd) {
19871 +               case LINUX_REBOOT_CMD_RESTART:
19872 +               case LINUX_REBOOT_CMD_HALT:
19873 +               case LINUX_REBOOT_CMD_POWER_OFF:
19874 +                       vx_info_kill(vxi, 0, SIGKILL);
19875 +                       vx_info_kill(vxi, 1, SIGKILL);
19876 +               default:
19877 +                       break;
19878 +               }
19879 +       }
19880 +       return 0;
19881 +}
19882 +
19883 +
19884 +/*
19885 + *      argv [0] = vshelper_path;
19886 + *      argv [1] = action: "startup", "shutdown"
19887 + *      argv [2] = context identifier
19888 + *
19889 + *      envp [*] = type-specific parameters
19890 + */
19891 +
19892 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
19893 +{
19894 +       char id_buf[8], cmd_buf[16];
19895 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
19896 +       char *envp[] = {"HOME=/", "TERM=linux",
19897 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
19898 +
19899 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
19900 +               return 0;
19901 +
19902 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", vxi->vx_id);
19903 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
19904 +
19905 +       switch (cmd) {
19906 +       case VSC_STARTUP:
19907 +               argv[1] = "startup";
19908 +               break;
19909 +       case VSC_SHUTDOWN:
19910 +               argv[1] = "shutdown";
19911 +               break;
19912 +       default:
19913 +               return 0;
19914 +       }
19915 +
19916 +       return do_vshelper(vshelper_path, argv, envp, 1);
19917 +}
19918 +
19919 +
19920 +/*
19921 + *      argv [0] = vshelper_path;
19922 + *      argv [1] = action: "netup", "netdown"
19923 + *      argv [2] = context identifier
19924 + *
19925 + *      envp [*] = type-specific parameters
19926 + */
19927 +
19928 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
19929 +{
19930 +       char id_buf[8], cmd_buf[16];
19931 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
19932 +       char *envp[] = {"HOME=/", "TERM=linux",
19933 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
19934 +
19935 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
19936 +               return 0;
19937 +
19938 +       snprintf(id_buf, sizeof(id_buf)-1, "%d", nxi->nx_id);
19939 +       snprintf(cmd_buf, sizeof(cmd_buf)-1, "VS_CMD=%08x", cmd);
19940 +
19941 +       switch (cmd) {
19942 +       case VSC_NETUP:
19943 +               argv[1] = "netup";
19944 +               break;
19945 +       case VSC_NETDOWN:
19946 +               argv[1] = "netdown";
19947 +               break;
19948 +       default:
19949 +               return 0;
19950 +       }
19951 +
19952 +       return do_vshelper(vshelper_path, argv, envp, 1);
19953 +}
19954 +
19955 diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/history.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/history.c
19956 --- linux-2.6.29.4/kernel/vserver/history.c     1970-01-01 01:00:00.000000000 +0100
19957 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/history.c       2009-02-22 22:54:26.000000000 +0100
19958 @@ -0,0 +1,258 @@
19959 +/*
19960 + *  kernel/vserver/history.c
19961 + *
19962 + *  Virtual Context History Backtrace
19963 + *
19964 + *  Copyright (C) 2004-2007  Herbert Pötzl
19965 + *
19966 + *  V0.01  basic structure
19967 + *  V0.02  hash/unhash and trace
19968 + *  V0.03  preemption fixes
19969 + *
19970 + */
19971 +
19972 +#include <linux/module.h>
19973 +#include <asm/uaccess.h>
19974 +
19975 +#include <linux/vserver/context.h>
19976 +#include <linux/vserver/debug.h>
19977 +#include <linux/vserver/debug_cmd.h>
19978 +#include <linux/vserver/history.h>
19979 +
19980 +
19981 +#ifdef CONFIG_VSERVER_HISTORY
19982 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
19983 +#else
19984 +#define VXH_SIZE       64
19985 +#endif
19986 +
19987 +struct _vx_history {
19988 +       unsigned int counter;
19989 +
19990 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
19991 +};
19992 +
19993 +
19994 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
19995 +
19996 +unsigned volatile int vxh_active = 1;
19997 +
19998 +static atomic_t sequence = ATOMIC_INIT(0);
19999 +
20000 +
20001 +/*     vxh_advance()
20002 +
20003 +       * requires disabled preemption                          */
20004 +
20005 +struct _vx_hist_entry *vxh_advance(void *loc)
20006 +{
20007 +       unsigned int cpu = smp_processor_id();
20008 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
20009 +       struct _vx_hist_entry *entry;
20010 +       unsigned int index;
20011 +
20012 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
20013 +       entry = &hist->entry[index];
20014 +
20015 +       entry->seq = atomic_inc_return(&sequence);
20016 +       entry->loc = loc;
20017 +       return entry;
20018 +}
20019 +
20020 +EXPORT_SYMBOL_GPL(vxh_advance);
20021 +
20022 +
20023 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
20024 +
20025 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
20026 +
20027 +
20028 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
20029 +
20030 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
20031 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
20032 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
20033 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
20034 +
20035 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
20036 +{
20037 +       switch (e->type) {
20038 +       case VXH_THROW_OOPS:
20039 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
20040 +               break;
20041 +
20042 +       case VXH_GET_VX_INFO:
20043 +       case VXH_PUT_VX_INFO:
20044 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
20045 +                       VXH_LOC_ARGS(e),
20046 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
20047 +                       VXH_VXI_ARGS(e));
20048 +               break;
20049 +
20050 +       case VXH_INIT_VX_INFO:
20051 +       case VXH_SET_VX_INFO:
20052 +       case VXH_CLR_VX_INFO:
20053 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
20054 +                       VXH_LOC_ARGS(e),
20055 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
20056 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
20057 +                       VXH_VXI_ARGS(e), e->sc.data);
20058 +               break;
20059 +
20060 +       case VXH_CLAIM_VX_INFO:
20061 +       case VXH_RELEASE_VX_INFO:
20062 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
20063 +                       VXH_LOC_ARGS(e),
20064 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
20065 +                       VXH_VXI_ARGS(e), e->sc.data);
20066 +               break;
20067 +
20068 +       case VXH_ALLOC_VX_INFO:
20069 +       case VXH_DEALLOC_VX_INFO:
20070 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
20071 +                       VXH_LOC_ARGS(e),
20072 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
20073 +                       VXH_VXI_ARGS(e));
20074 +               break;
20075 +
20076 +       case VXH_HASH_VX_INFO:
20077 +       case VXH_UNHASH_VX_INFO:
20078 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
20079 +                       VXH_LOC_ARGS(e),
20080 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
20081 +                       VXH_VXI_ARGS(e));
20082 +               break;
20083 +
20084 +       case VXH_LOC_VX_INFO:
20085 +       case VXH_LOOKUP_VX_INFO:
20086 +       case VXH_CREATE_VX_INFO:
20087 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
20088 +                       VXH_LOC_ARGS(e),
20089 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
20090 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
20091 +                       e->ll.arg, VXH_VXI_ARGS(e));
20092 +               break;
20093 +       }
20094 +}
20095 +
20096 +static void __vxh_dump_history(void)
20097 +{
20098 +       unsigned int i, cpu;
20099 +
20100 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
20101 +               atomic_read(&sequence), NR_CPUS);
20102 +
20103 +       for (i = 0; i < VXH_SIZE; i++) {
20104 +               for_each_online_cpu(cpu) {
20105 +                       struct _vx_history *hist =
20106 +                               &per_cpu(vx_history_buffer, cpu);
20107 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
20108 +                       struct _vx_hist_entry *entry = &hist->entry[index];
20109 +
20110 +                       vxh_dump_entry(entry, cpu);
20111 +               }
20112 +       }
20113 +}
20114 +
20115 +void   vxh_dump_history(void)
20116 +{
20117 +       vxh_active = 0;
20118 +#ifdef CONFIG_SMP
20119 +       local_irq_enable();
20120 +       smp_send_stop();
20121 +       local_irq_disable();
20122 +#endif
20123 +       __vxh_dump_history();
20124 +}
20125 +
20126 +
20127 +/* vserver syscall commands below here */
20128 +
20129 +
20130 +int vc_dump_history(uint32_t id)
20131 +{
20132 +       vxh_active = 0;
20133 +       __vxh_dump_history();
20134 +       vxh_active = 1;
20135 +
20136 +       return 0;
20137 +}
20138 +
20139 +
20140 +int do_read_history(struct __user _vx_hist_entry *data,
20141 +       int cpu, uint32_t *index, uint32_t *count)
20142 +{
20143 +       int pos, ret = 0;
20144 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
20145 +       int end = hist->counter;
20146 +       int start = end - VXH_SIZE + 2;
20147 +       int idx = *index;
20148 +
20149 +       /* special case: get current pos */
20150 +       if (!*count) {
20151 +               *index = end;
20152 +               return 0;
20153 +       }
20154 +
20155 +       /* have we lost some data? */
20156 +       if (idx < start)
20157 +               idx = start;
20158 +
20159 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
20160 +               struct _vx_hist_entry *entry =
20161 +                       &hist->entry[idx % VXH_SIZE];
20162 +
20163 +               /* send entry to userspace */
20164 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
20165 +               if (ret)
20166 +                       break;
20167 +       }
20168 +       /* save new index and count */
20169 +       *index = idx;
20170 +       *count = pos;
20171 +       return ret ? ret : (*index < end);
20172 +}
20173 +
20174 +int vc_read_history(uint32_t id, void __user *data)
20175 +{
20176 +       struct vcmd_read_history_v0 vc_data;
20177 +       int ret;
20178 +
20179 +       if (id >= NR_CPUS)
20180 +               return -EINVAL;
20181 +
20182 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20183 +               return -EFAULT;
20184 +
20185 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
20186 +               id, &vc_data.index, &vc_data.count);
20187 +
20188 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20189 +               return -EFAULT;
20190 +       return ret;
20191 +}
20192 +
20193 +#ifdef CONFIG_COMPAT
20194 +
20195 +int vc_read_history_x32(uint32_t id, void __user *data)
20196 +{
20197 +       struct vcmd_read_history_v0_x32 vc_data;
20198 +       int ret;
20199 +
20200 +       if (id >= NR_CPUS)
20201 +               return -EINVAL;
20202 +
20203 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20204 +               return -EFAULT;
20205 +
20206 +       ret = do_read_history((struct __user _vx_hist_entry *)
20207 +               compat_ptr(vc_data.data_ptr),
20208 +               id, &vc_data.index, &vc_data.count);
20209 +
20210 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20211 +               return -EFAULT;
20212 +       return ret;
20213 +}
20214 +
20215 +#endif /* CONFIG_COMPAT */
20216 +
20217 diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/inet.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/inet.c
20218 --- linux-2.6.29.4/kernel/vserver/inet.c        1970-01-01 01:00:00.000000000 +0100
20219 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/inet.c  2009-02-22 22:54:26.000000000 +0100
20220 @@ -0,0 +1,225 @@
20221 +
20222 +#include <linux/in.h>
20223 +#include <linux/inetdevice.h>
20224 +#include <linux/vs_inet.h>
20225 +#include <linux/vs_inet6.h>
20226 +#include <linux/vserver/debug.h>
20227 +#include <net/route.h>
20228 +#include <net/addrconf.h>
20229 +
20230 +
20231 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
20232 +{
20233 +       int ret = 0;
20234 +
20235 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
20236 +               ret = 1;
20237 +       else {
20238 +               struct nx_addr_v4 *ptr;
20239 +
20240 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
20241 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
20242 +                               ret = 1;
20243 +                               break;
20244 +                       }
20245 +               }
20246 +       }
20247 +
20248 +       vxdprintk(VXD_CBIT(net, 2),
20249 +               "nx_v4_addr_conflict(%p,%p): %d",
20250 +               nxi1, nxi2, ret);
20251 +
20252 +       return ret;
20253 +}
20254 +
20255 +
20256 +#ifdef CONFIG_IPV6
20257 +
20258 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
20259 +{
20260 +       int ret = 0;
20261 +
20262 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
20263 +               ret = 1;
20264 +       else {
20265 +               struct nx_addr_v6 *ptr;
20266 +
20267 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
20268 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
20269 +                               ret = 1;
20270 +                               break;
20271 +                       }
20272 +               }
20273 +       }
20274 +
20275 +       vxdprintk(VXD_CBIT(net, 2),
20276 +               "nx_v6_addr_conflict(%p,%p): %d",
20277 +               nxi1, nxi2, ret);
20278 +
20279 +       return ret;
20280 +}
20281 +
20282 +#endif
20283 +
20284 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20285 +{
20286 +       struct in_device *in_dev;
20287 +       struct in_ifaddr **ifap;
20288 +       struct in_ifaddr *ifa;
20289 +       int ret = 0;
20290 +
20291 +       if (!dev)
20292 +               goto out;
20293 +       in_dev = in_dev_get(dev);
20294 +       if (!in_dev)
20295 +               goto out;
20296 +
20297 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
20298 +               ifap = &ifa->ifa_next) {
20299 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
20300 +                       ret = 1;
20301 +                       break;
20302 +               }
20303 +       }
20304 +       in_dev_put(in_dev);
20305 +out:
20306 +       return ret;
20307 +}
20308 +
20309 +
20310 +#ifdef CONFIG_IPV6
20311 +
20312 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20313 +{
20314 +       struct inet6_dev *in_dev;
20315 +       struct inet6_ifaddr **ifap;
20316 +       struct inet6_ifaddr *ifa;
20317 +       int ret = 0;
20318 +
20319 +       if (!dev)
20320 +               goto out;
20321 +       in_dev = in6_dev_get(dev);
20322 +       if (!in_dev)
20323 +               goto out;
20324 +
20325 +       for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
20326 +               ifap = &ifa->if_next) {
20327 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
20328 +                       ret = 1;
20329 +                       break;
20330 +               }
20331 +       }
20332 +       in6_dev_put(in_dev);
20333 +out:
20334 +       return ret;
20335 +}
20336 +
20337 +#endif
20338 +
20339 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
20340 +{
20341 +       int ret = 1;
20342 +
20343 +       if (!nxi)
20344 +               goto out;
20345 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
20346 +               goto out;
20347 +#ifdef CONFIG_IPV6
20348 +       ret = 2;
20349 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
20350 +               goto out;
20351 +#endif
20352 +       ret = 0;
20353 +out:
20354 +       vxdprintk(VXD_CBIT(net, 3),
20355 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
20356 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
20357 +       return ret;
20358 +}
20359 +
20360 +int ip_v4_find_src(struct net *net, struct nx_info *nxi,
20361 +       struct rtable **rp, struct flowi *fl)
20362 +{
20363 +       if (!nxi)
20364 +               return 0;
20365 +
20366 +       /* FIXME: handle lback only case */
20367 +       if (!NX_IPV4(nxi))
20368 +               return -EPERM;
20369 +
20370 +       vxdprintk(VXD_CBIT(net, 4),
20371 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
20372 +               nxi, nxi ? nxi->nx_id : 0,
20373 +               NIPQUAD(fl->fl4_src), NIPQUAD(fl->fl4_dst));
20374 +
20375 +       /* single IP is unconditional */
20376 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
20377 +               (fl->fl4_src == INADDR_ANY))
20378 +               fl->fl4_src = nxi->v4.ip[0].s_addr;
20379 +
20380 +       if (fl->fl4_src == INADDR_ANY) {
20381 +               struct nx_addr_v4 *ptr;
20382 +               __be32 found = 0;
20383 +               int err;
20384 +
20385 +               err = __ip_route_output_key(net, rp, fl);
20386 +               if (!err) {
20387 +                       found = (*rp)->rt_src;
20388 +                       ip_rt_put(*rp);
20389 +                       vxdprintk(VXD_CBIT(net, 4),
20390 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
20391 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(found));
20392 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
20393 +                               goto found;
20394 +               }
20395 +
20396 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
20397 +                       __be32 primary = ptr->ip[0].s_addr;
20398 +                       __be32 mask = ptr->mask.s_addr;
20399 +                       __be32 neta = primary & mask;
20400 +
20401 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
20402 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
20403 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
20404 +                               NIPQUAD(mask), NIPQUAD(neta));
20405 +                       if ((found & mask) != neta)
20406 +                               continue;
20407 +
20408 +                       fl->fl4_src = primary;
20409 +                       err = __ip_route_output_key(net, rp, fl);
20410 +                       vxdprintk(VXD_CBIT(net, 4),
20411 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
20412 +                               nxi, nxi ? nxi->nx_id : 0, fl->oif, NIPQUAD(primary));
20413 +                       if (!err) {
20414 +                               found = (*rp)->rt_src;
20415 +                               ip_rt_put(*rp);
20416 +                               if (found == primary)
20417 +                                       goto found;
20418 +                       }
20419 +               }
20420 +               /* still no source ip? */
20421 +               found = ipv4_is_loopback(fl->fl4_dst)
20422 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
20423 +       found:
20424 +               /* assign src ip to flow */
20425 +               fl->fl4_src = found;
20426 +
20427 +       } else {
20428 +               if (!v4_addr_in_nx_info(nxi, fl->fl4_src, NXA_MASK_BIND))
20429 +                       return -EPERM;
20430 +       }
20431 +
20432 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
20433 +               if (ipv4_is_loopback(fl->fl4_dst))
20434 +                       fl->fl4_dst = nxi->v4_lback.s_addr;
20435 +               if (ipv4_is_loopback(fl->fl4_src))
20436 +                       fl->fl4_src = nxi->v4_lback.s_addr;
20437 +       } else if (ipv4_is_loopback(fl->fl4_dst) &&
20438 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
20439 +               return -EPERM;
20440 +
20441 +       return 0;
20442 +}
20443 +
20444 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
20445 +
20446 diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/init.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/init.c
20447 --- linux-2.6.29.4/kernel/vserver/init.c        1970-01-01 01:00:00.000000000 +0100
20448 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/init.c  2009-02-22 22:54:26.000000000 +0100
20449 @@ -0,0 +1,45 @@
20450 +/*
20451 + *  linux/kernel/init.c
20452 + *
20453 + *  Virtual Server Init
20454 + *
20455 + *  Copyright (C) 2004-2007  Herbert Pötzl
20456 + *
20457 + *  V0.01  basic structure
20458 + *
20459 + */
20460 +
20461 +#include <linux/init.h>
20462 +
20463 +int    vserver_register_sysctl(void);
20464 +void   vserver_unregister_sysctl(void);
20465 +
20466 +
20467 +static int __init init_vserver(void)
20468 +{
20469 +       int ret = 0;
20470 +
20471 +#ifdef CONFIG_VSERVER_DEBUG
20472 +       vserver_register_sysctl();
20473 +#endif
20474 +       return ret;
20475 +}
20476 +
20477 +
20478 +static void __exit exit_vserver(void)
20479 +{
20480 +
20481 +#ifdef CONFIG_VSERVER_DEBUG
20482 +       vserver_unregister_sysctl();
20483 +#endif
20484 +       return;
20485 +}
20486 +
20487 +/* FIXME: GFP_ZONETYPES gone
20488 +long vx_slab[GFP_ZONETYPES]; */
20489 +long vx_area;
20490 +
20491 +
20492 +module_init(init_vserver);
20493 +module_exit(exit_vserver);
20494 +
20495 diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/inode.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/inode.c
20496 --- linux-2.6.29.4/kernel/vserver/inode.c       1970-01-01 01:00:00.000000000 +0100
20497 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/inode.c 2009-02-22 22:54:26.000000000 +0100
20498 @@ -0,0 +1,422 @@
20499 +/*
20500 + *  linux/kernel/vserver/inode.c
20501 + *
20502 + *  Virtual Server: File System Support
20503 + *
20504 + *  Copyright (C) 2004-2007  Herbert Pötzl
20505 + *
20506 + *  V0.01  separated from vcontext V0.05
20507 + *  V0.02  moved to tag (instead of xid)
20508 + *
20509 + */
20510 +
20511 +#include <linux/tty.h>
20512 +#include <linux/proc_fs.h>
20513 +#include <linux/devpts_fs.h>
20514 +#include <linux/fs.h>
20515 +#include <linux/file.h>
20516 +#include <linux/mount.h>
20517 +#include <linux/parser.h>
20518 +#include <linux/namei.h>
20519 +#include <linux/vserver/inode.h>
20520 +#include <linux/vserver/inode_cmd.h>
20521 +#include <linux/vs_base.h>
20522 +#include <linux/vs_tag.h>
20523 +
20524 +#include <asm/uaccess.h>
20525 +
20526 +
20527 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
20528 +{
20529 +       struct proc_dir_entry *entry;
20530 +
20531 +       if (!in || !in->i_sb)
20532 +               return -ESRCH;
20533 +
20534 +       *flags = IATTR_TAG
20535 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
20536 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
20537 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0);
20538 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE;
20539 +
20540 +       if (S_ISDIR(in->i_mode))
20541 +               *mask |= IATTR_BARRIER;
20542 +
20543 +       if (IS_TAGGED(in)) {
20544 +               *tag = in->i_tag;
20545 +               *mask |= IATTR_TAG;
20546 +       }
20547 +
20548 +       switch (in->i_sb->s_magic) {
20549 +       case PROC_SUPER_MAGIC:
20550 +               entry = PROC_I(in)->pde;
20551 +
20552 +               /* check for specific inodes? */
20553 +               if (entry)
20554 +                       *mask |= IATTR_FLAGS;
20555 +               if (entry)
20556 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
20557 +               else
20558 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
20559 +               break;
20560 +
20561 +       case DEVPTS_SUPER_MAGIC:
20562 +               *tag = in->i_tag;
20563 +               *mask |= IATTR_TAG;
20564 +               break;
20565 +
20566 +       default:
20567 +               break;
20568 +       }
20569 +       return 0;
20570 +}
20571 +
20572 +int vc_get_iattr(void __user *data)
20573 +{
20574 +       struct path path;
20575 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
20576 +       int ret;
20577 +
20578 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20579 +               return -EFAULT;
20580 +
20581 +       ret = user_lpath(vc_data.name, &path);
20582 +       if (!ret) {
20583 +               ret = __vc_get_iattr(path.dentry->d_inode,
20584 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20585 +               path_put(&path);
20586 +       }
20587 +       if (ret)
20588 +               return ret;
20589 +
20590 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20591 +               ret = -EFAULT;
20592 +       return ret;
20593 +}
20594 +
20595 +#ifdef CONFIG_COMPAT
20596 +
20597 +int vc_get_iattr_x32(void __user *data)
20598 +{
20599 +       struct path path;
20600 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
20601 +       int ret;
20602 +
20603 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20604 +               return -EFAULT;
20605 +
20606 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
20607 +       if (!ret) {
20608 +               ret = __vc_get_iattr(path.dentry->d_inode,
20609 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20610 +               path_put(&path);
20611 +       }
20612 +       if (ret)
20613 +               return ret;
20614 +
20615 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20616 +               ret = -EFAULT;
20617 +       return ret;
20618 +}
20619 +
20620 +#endif /* CONFIG_COMPAT */
20621 +
20622 +
20623 +int vc_fget_iattr(uint32_t fd, void __user *data)
20624 +{
20625 +       struct file *filp;
20626 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
20627 +       int ret;
20628 +
20629 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20630 +               return -EFAULT;
20631 +
20632 +       filp = fget(fd);
20633 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
20634 +               return -EBADF;
20635 +
20636 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
20637 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
20638 +
20639 +       fput(filp);
20640 +
20641 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20642 +               ret = -EFAULT;
20643 +       return ret;
20644 +}
20645 +
20646 +
20647 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
20648 +{
20649 +       struct inode *in = de->d_inode;
20650 +       int error = 0, is_proc = 0, has_tag = 0;
20651 +       struct iattr attr = { 0 };
20652 +
20653 +       if (!in || !in->i_sb)
20654 +               return -ESRCH;
20655 +
20656 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
20657 +       if ((*mask & IATTR_FLAGS) && !is_proc)
20658 +               return -EINVAL;
20659 +
20660 +       has_tag = IS_TAGGED(in) ||
20661 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
20662 +       if ((*mask & IATTR_TAG) && !has_tag)
20663 +               return -EINVAL;
20664 +
20665 +       mutex_lock(&in->i_mutex);
20666 +       if (*mask & IATTR_TAG) {
20667 +               attr.ia_tag = *tag;
20668 +               attr.ia_valid |= ATTR_TAG;
20669 +       }
20670 +
20671 +       if (*mask & IATTR_FLAGS) {
20672 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
20673 +               unsigned int iflags = PROC_I(in)->vx_flags;
20674 +
20675 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
20676 +                       | (*flags & IATTR_FLAGS);
20677 +               PROC_I(in)->vx_flags = iflags;
20678 +               if (entry)
20679 +                       entry->vx_flags = iflags;
20680 +       }
20681 +
20682 +       if (*mask & (IATTR_BARRIER | IATTR_IXUNLINK | IATTR_IMMUTABLE)) {
20683 +               if (*mask & IATTR_IMMUTABLE) {
20684 +                       if (*flags & IATTR_IMMUTABLE)
20685 +                               in->i_flags |= S_IMMUTABLE;
20686 +                       else
20687 +                               in->i_flags &= ~S_IMMUTABLE;
20688 +               }
20689 +               if (*mask & IATTR_IXUNLINK) {
20690 +                       if (*flags & IATTR_IXUNLINK)
20691 +                               in->i_flags |= S_IXUNLINK;
20692 +                       else
20693 +                               in->i_flags &= ~S_IXUNLINK;
20694 +               }
20695 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
20696 +                       if (*flags & IATTR_BARRIER)
20697 +                               in->i_vflags |= V_BARRIER;
20698 +                       else
20699 +                               in->i_vflags &= ~V_BARRIER;
20700 +               }
20701 +               if (in->i_op && in->i_op->sync_flags) {
20702 +                       error = in->i_op->sync_flags(in);
20703 +                       if (error)
20704 +                               goto out;
20705 +               }
20706 +       }
20707 +
20708 +       if (attr.ia_valid) {
20709 +               if (in->i_op && in->i_op->setattr)
20710 +                       error = in->i_op->setattr(de, &attr);
20711 +               else {
20712 +                       error = inode_change_ok(in, &attr);
20713 +                       if (!error)
20714 +                               error = inode_setattr(in, &attr);
20715 +               }
20716 +       }
20717 +
20718 +out:
20719 +       mutex_unlock(&in->i_mutex);
20720 +       return error;
20721 +}
20722 +
20723 +int vc_set_iattr(void __user *data)
20724 +{
20725 +       struct path path;
20726 +       struct vcmd_ctx_iattr_v1 vc_data;
20727 +       int ret;
20728 +
20729 +       if (!capable(CAP_LINUX_IMMUTABLE))
20730 +               return -EPERM;
20731 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20732 +               return -EFAULT;
20733 +
20734 +       ret = user_lpath(vc_data.name, &path);
20735 +       if (!ret) {
20736 +               ret = __vc_set_iattr(path.dentry,
20737 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20738 +               path_put(&path);
20739 +       }
20740 +
20741 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20742 +               ret = -EFAULT;
20743 +       return ret;
20744 +}
20745 +
20746 +#ifdef CONFIG_COMPAT
20747 +
20748 +int vc_set_iattr_x32(void __user *data)
20749 +{
20750 +       struct path path;
20751 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
20752 +       int ret;
20753 +
20754 +       if (!capable(CAP_LINUX_IMMUTABLE))
20755 +               return -EPERM;
20756 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20757 +               return -EFAULT;
20758 +
20759 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
20760 +       if (!ret) {
20761 +               ret = __vc_set_iattr(path.dentry,
20762 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
20763 +               path_put(&path);
20764 +       }
20765 +
20766 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20767 +               ret = -EFAULT;
20768 +       return ret;
20769 +}
20770 +
20771 +#endif /* CONFIG_COMPAT */
20772 +
20773 +int vc_fset_iattr(uint32_t fd, void __user *data)
20774 +{
20775 +       struct file *filp;
20776 +       struct vcmd_ctx_fiattr_v0 vc_data;
20777 +       int ret;
20778 +
20779 +       if (!capable(CAP_LINUX_IMMUTABLE))
20780 +               return -EPERM;
20781 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20782 +               return -EFAULT;
20783 +
20784 +       filp = fget(fd);
20785 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
20786 +               return -EBADF;
20787 +
20788 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
20789 +               &vc_data.flags, &vc_data.mask);
20790 +
20791 +       fput(filp);
20792 +
20793 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20794 +               return -EFAULT;
20795 +       return ret;
20796 +}
20797 +
20798 +
20799 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
20800 +
20801 +static match_table_t tokens = {
20802 +       {Opt_notagcheck, "notagcheck"},
20803 +#ifdef CONFIG_PROPAGATE
20804 +       {Opt_notag, "notag"},
20805 +       {Opt_tag, "tag"},
20806 +       {Opt_tagid, "tagid=%u"},
20807 +#endif
20808 +       {Opt_err, NULL}
20809 +};
20810 +
20811 +
20812 +static void __dx_parse_remove(char *string, char *opt)
20813 +{
20814 +       char *p = strstr(string, opt);
20815 +       char *q = p;
20816 +
20817 +       if (p) {
20818 +               while (*q != '\0' && *q != ',')
20819 +                       q++;
20820 +               while (*q)
20821 +                       *p++ = *q++;
20822 +               while (*p)
20823 +                       *p++ = '\0';
20824 +       }
20825 +}
20826 +
20827 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
20828 +                unsigned long *flags)
20829 +{
20830 +       int set = 0;
20831 +       substring_t args[MAX_OPT_ARGS];
20832 +       int token, option = 0;
20833 +       char *s, *p, *opts;
20834 +
20835 +       if (!string)
20836 +               return 0;
20837 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
20838 +       if (!s)
20839 +               return 0;
20840 +
20841 +       opts = s;
20842 +       while ((p = strsep(&opts, ",")) != NULL) {
20843 +               token = match_token(p, tokens, args);
20844 +
20845 +               vxdprintk(VXD_CBIT(tag, 7),
20846 +                       "dx_parse_tag(»%s«): %d:#%d",
20847 +                       p, token, option);
20848 +
20849 +               switch (token) {
20850 +#ifdef CONFIG_PROPAGATE
20851 +               case Opt_tag:
20852 +                       if (tag)
20853 +                               *tag = 0;
20854 +                       if (remove)
20855 +                               __dx_parse_remove(s, "tag");
20856 +                       *mnt_flags |= MNT_TAGID;
20857 +                       set |= MNT_TAGID;
20858 +                       break;
20859 +               case Opt_notag:
20860 +                       if (remove)
20861 +                               __dx_parse_remove(s, "notag");
20862 +                       *mnt_flags |= MNT_NOTAG;
20863 +                       set |= MNT_NOTAG;
20864 +                       break;
20865 +               case Opt_tagid:
20866 +                       if (tag && !match_int(args, &option))
20867 +                               *tag = option;
20868 +                       if (remove)
20869 +                               __dx_parse_remove(s, "tagid");
20870 +                       *mnt_flags |= MNT_TAGID;
20871 +                       set |= MNT_TAGID;
20872 +                       break;
20873 +#endif
20874 +               case Opt_notagcheck:
20875 +                       if (remove)
20876 +                               __dx_parse_remove(s, "notagcheck");
20877 +                       *flags |= MS_NOTAGCHECK;
20878 +                       set |= MS_NOTAGCHECK;
20879 +                       break;
20880 +               }
20881 +       }
20882 +       if (set)
20883 +               strcpy(string, s);
20884 +       kfree(s);
20885 +       return set;
20886 +}
20887 +
20888 +#ifdef CONFIG_PROPAGATE
20889 +
20890 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
20891 +{
20892 +       tag_t new_tag = 0;
20893 +       struct vfsmount *mnt;
20894 +       int propagate;
20895 +
20896 +       if (!nd)
20897 +               return;
20898 +       mnt = nd->path.mnt;
20899 +       if (!mnt)
20900 +               return;
20901 +
20902 +       propagate = (mnt->mnt_flags & MNT_TAGID);
20903 +       if (propagate)
20904 +               new_tag = mnt->mnt_tag;
20905 +
20906 +       vxdprintk(VXD_CBIT(tag, 7),
20907 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
20908 +               inode, inode->i_ino, inode->i_tag,
20909 +               new_tag, (propagate) ? 1 : 0);
20910 +
20911 +       if (propagate)
20912 +               inode->i_tag = new_tag;
20913 +}
20914 +
20915 +#include <linux/module.h>
20916 +
20917 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
20918 +
20919 +#endif /* CONFIG_PROPAGATE */
20920 +
20921 diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/Kconfig linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/Kconfig
20922 --- linux-2.6.29.4/kernel/vserver/Kconfig       1970-01-01 01:00:00.000000000 +0100
20923 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/Kconfig 2009-02-22 22:54:26.000000000 +0100
20924 @@ -0,0 +1,251 @@
20925 +#
20926 +# Linux VServer configuration
20927 +#
20928 +
20929 +menu "Linux VServer"
20930 +
20931 +config VSERVER_AUTO_LBACK
20932 +       bool    "Automatically Assign Loopback IP"
20933 +       default y
20934 +       help
20935 +         Automatically assign a guest specific loopback
20936 +         IP and add it to the kernel network stack on
20937 +         startup.
20938 +
20939 +config VSERVER_AUTO_SINGLE
20940 +       bool    "Automatic Single IP Special Casing"
20941 +       depends on EXPERIMENTAL
20942 +       default y
20943 +       help
20944 +         This allows network contexts with a single IP to
20945 +         automatically remap 0.0.0.0 bindings to that IP,
20946 +         avoiding further network checks and improving
20947 +         performance.
20948 +
20949 +         (note: such guests do not allow to change the ip
20950 +          on the fly and do not show loopback addresses)
20951 +
20952 +config VSERVER_COWBL
20953 +       bool    "Enable COW Immutable Link Breaking"
20954 +       default y
20955 +       help
20956 +         This enables the COW (Copy-On-Write) link break code.
20957 +         It allows you to treat unified files like normal files
20958 +         when writing to them (which will implicitely break the
20959 +         link and create a copy of the unified file)
20960 +
20961 +config VSERVER_VTIME
20962 +       bool    "Enable Virtualized Guest Time"
20963 +       depends on EXPERIMENTAL
20964 +       default n
20965 +       help
20966 +         This enables per guest time offsets to allow for
20967 +         adjusting the system clock individually per guest.
20968 +         this adds some overhead to the time functions and
20969 +         therefore should not be enabled without good reason.
20970 +
20971 +config VSERVER_DEVICE
20972 +       bool    "Enable Guest Device Mapping"
20973 +       depends on EXPERIMENTAL
20974 +       default n
20975 +       help
20976 +         This enables generic device remapping.
20977 +
20978 +config VSERVER_PROC_SECURE
20979 +       bool    "Enable Proc Security"
20980 +       depends on PROC_FS
20981 +       default y
20982 +       help
20983 +         This configures ProcFS security to initially hide
20984 +         non-process entries for all contexts except the main and
20985 +         spectator context (i.e. for all guests), which is a secure
20986 +         default.
20987 +
20988 +         (note: on 1.2x the entries were visible by default)
20989 +
20990 +config VSERVER_HARDCPU
20991 +       bool    "Enable Hard CPU Limits"
20992 +       default y
20993 +       help
20994 +         Activate the Hard CPU Limits
20995 +
20996 +         This will compile in code that allows the Token Bucket
20997 +         Scheduler to put processes on hold when a context's
20998 +         tokens are depleted (provided that its per-context
20999 +         sched_hard flag is set).
21000 +
21001 +         Processes belonging to that context will not be able
21002 +         to consume CPU resources again until a per-context
21003 +         configured minimum of tokens has been reached.
21004 +
21005 +config VSERVER_IDLETIME
21006 +       bool    "Avoid idle CPUs by skipping Time"
21007 +       depends on VSERVER_HARDCPU
21008 +       default y
21009 +       help
21010 +         This option allows the scheduler to artificially
21011 +         advance time (per cpu) when otherwise the idle
21012 +         task would be scheduled, thus keeping the cpu
21013 +         busy and sharing the available resources among
21014 +         certain contexts.
21015 +
21016 +config VSERVER_IDLELIMIT
21017 +       bool    "Limit the IDLE task"
21018 +       depends on VSERVER_HARDCPU
21019 +       default n
21020 +       help
21021 +         Limit the idle slices, so the the next context
21022 +         will be scheduled as soon as possible.
21023 +
21024 +         This might improve interactivity and latency, but
21025 +         will also marginally increase scheduling overhead.
21026 +
21027 +choice
21028 +       prompt  "Persistent Inode Tagging"
21029 +       default TAGGING_ID24
21030 +       help
21031 +         This adds persistent context information to filesystems
21032 +         mounted with the tagxid option. Tagging is a requirement
21033 +         for per-context disk limits and per-context quota.
21034 +
21035 +
21036 +config TAGGING_NONE
21037 +       bool    "Disabled"
21038 +       help
21039 +         do not store per-context information in inodes.
21040 +
21041 +config TAGGING_UID16
21042 +       bool    "UID16/GID32"
21043 +       help
21044 +         reduces UID to 16 bit, but leaves GID at 32 bit.
21045 +
21046 +config TAGGING_GID16
21047 +       bool    "UID32/GID16"
21048 +       help
21049 +         reduces GID to 16 bit, but leaves UID at 32 bit.
21050 +
21051 +config TAGGING_ID24
21052 +       bool    "UID24/GID24"
21053 +       help
21054 +         uses the upper 8bit from UID and GID for XID tagging
21055 +         which leaves 24bit for UID/GID each, which should be
21056 +         more than sufficient for normal use.
21057 +
21058 +config TAGGING_INTERN
21059 +       bool    "UID32/GID32"
21060 +       help
21061 +         this uses otherwise reserved inode fields in the on
21062 +         disk representation, which limits the use to a few
21063 +         filesystems (currently ext2 and ext3)
21064 +
21065 +endchoice
21066 +
21067 +config TAG_NFSD
21068 +       bool    "Tag NFSD User Auth and Files"
21069 +       default n
21070 +       help
21071 +         Enable this if you do want the in-kernel NFS
21072 +         Server to use the tagging specified above.
21073 +         (will require patched clients too)
21074 +
21075 +config VSERVER_PRIVACY
21076 +       bool    "Honor Privacy Aspects of Guests"
21077 +       default n
21078 +       help
21079 +         When enabled, most context checks will disallow
21080 +         access to structures assigned to a specific context,
21081 +         like ptys or loop devices.
21082 +
21083 +config VSERVER_CONTEXTS
21084 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
21085 +       range 1 65533
21086 +       default "768"   if 64BIT
21087 +       default "256"
21088 +       help
21089 +         This setting will optimize certain data structures
21090 +         and memory allocations according to the expected
21091 +         maximum.
21092 +
21093 +         note: this is not a strict upper limit.
21094 +
21095 +config VSERVER_WARN
21096 +       bool    "VServer Warnings"
21097 +       default y
21098 +       help
21099 +         This enables various runtime warnings, which will
21100 +         notify about potential manipulation attempts or
21101 +         resource shortage. It is generally considered to
21102 +         be a good idea to have that enabled.
21103 +
21104 +config VSERVER_DEBUG
21105 +       bool    "VServer Debugging Code"
21106 +       default n
21107 +       help
21108 +         Set this to yes if you want to be able to activate
21109 +         debugging output at runtime. It adds a very small
21110 +         overhead to all vserver related functions and
21111 +         increases the kernel size by about 20k.
21112 +
21113 +config VSERVER_HISTORY
21114 +       bool    "VServer History Tracing"
21115 +       depends on VSERVER_DEBUG
21116 +       default n
21117 +       help
21118 +         Set this to yes if you want to record the history of
21119 +         linux-vserver activities, so they can be replayed in
21120 +         the event of a kernel panic or oops.
21121 +
21122 +config VSERVER_HISTORY_SIZE
21123 +       int     "Per-CPU History Size (32-65536)"
21124 +       depends on VSERVER_HISTORY
21125 +       range 32 65536
21126 +       default 64
21127 +       help
21128 +         This allows you to specify the number of entries in
21129 +         the per-CPU history buffer.
21130 +
21131 +config VSERVER_MONITOR
21132 +       bool    "VServer Scheduling Monitor"
21133 +       depends on VSERVER_DISABLED
21134 +       default n
21135 +       help
21136 +         Set this to yes if you want to record the scheduling
21137 +         decisions, so that they can be relayed to userspace
21138 +         for detailed analysis.
21139 +
21140 +config VSERVER_MONITOR_SIZE
21141 +       int     "Per-CPU Monitor Queue Size (32-65536)"
21142 +       depends on VSERVER_MONITOR
21143 +       range 32 65536
21144 +       default 1024
21145 +       help
21146 +         This allows you to specify the number of entries in
21147 +         the per-CPU scheduling monitor buffer.
21148 +
21149 +config VSERVER_MONITOR_SYNC
21150 +       int     "Per-CPU Monitor Sync Interval (0-65536)"
21151 +       depends on VSERVER_MONITOR
21152 +       range 0 65536
21153 +       default 256
21154 +       help
21155 +         This allows you to specify the interval in ticks
21156 +         when a time sync entry is inserted.
21157 +
21158 +endmenu
21159 +
21160 +
21161 +config VSERVER
21162 +       bool
21163 +       default y
21164 +       select NAMESPACES
21165 +       select UTS_NS
21166 +       select IPC_NS
21167 +       select USER_NS
21168 +       select SYSVIPC
21169 +
21170 +config VSERVER_SECURITY
21171 +       bool
21172 +       depends on SECURITY
21173 +       default y
21174 +       select SECURITY_CAPABILITIES
21175 +
21176 diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/limit.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/limit.c
21177 --- linux-2.6.29.4/kernel/vserver/limit.c       1970-01-01 01:00:00.000000000 +0100
21178 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/limit.c 2009-02-22 22:54:26.000000000 +0100
21179 @@ -0,0 +1,319 @@
21180 +/*
21181 + *  linux/kernel/vserver/limit.c
21182 + *
21183 + *  Virtual Server: Context Limits
21184 + *
21185 + *  Copyright (C) 2004-2007  Herbert Pötzl
21186 + *
21187 + *  V0.01  broken out from vcontext V0.05
21188 + *  V0.02  changed vcmds to vxi arg
21189 + *
21190 + */
21191 +
21192 +#include <linux/sched.h>
21193 +#include <linux/module.h>
21194 +#include <linux/vs_limit.h>
21195 +#include <linux/vserver/limit.h>
21196 +#include <linux/vserver/limit_cmd.h>
21197 +
21198 +#include <asm/uaccess.h>
21199 +
21200 +
21201 +const char *vlimit_name[NUM_LIMITS] = {
21202 +       [RLIMIT_CPU]            = "CPU",
21203 +       [RLIMIT_RSS]            = "RSS",
21204 +       [RLIMIT_NPROC]          = "NPROC",
21205 +       [RLIMIT_NOFILE]         = "NOFILE",
21206 +       [RLIMIT_MEMLOCK]        = "VML",
21207 +       [RLIMIT_AS]             = "VM",
21208 +       [RLIMIT_LOCKS]          = "LOCKS",
21209 +       [RLIMIT_SIGPENDING]     = "SIGP",
21210 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
21211 +
21212 +       [VLIMIT_NSOCK]          = "NSOCK",
21213 +       [VLIMIT_OPENFD]         = "OPENFD",
21214 +       [VLIMIT_ANON]           = "ANON",
21215 +       [VLIMIT_SHMEM]          = "SHMEM",
21216 +       [VLIMIT_DENTRY]         = "DENTRY",
21217 +};
21218 +
21219 +EXPORT_SYMBOL_GPL(vlimit_name);
21220 +
21221 +#define MASK_ENTRY(x)  (1 << (x))
21222 +
21223 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
21224 +               /* minimum */
21225 +       0
21226 +       ,       /* softlimit */
21227 +       MASK_ENTRY( RLIMIT_RSS          ) |
21228 +       MASK_ENTRY( VLIMIT_ANON         ) |
21229 +       0
21230 +       ,       /* maximum */
21231 +       MASK_ENTRY( RLIMIT_RSS          ) |
21232 +       MASK_ENTRY( RLIMIT_NPROC        ) |
21233 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
21234 +       MASK_ENTRY( RLIMIT_MEMLOCK      ) |
21235 +       MASK_ENTRY( RLIMIT_AS           ) |
21236 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
21237 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
21238 +
21239 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
21240 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
21241 +       MASK_ENTRY( VLIMIT_ANON         ) |
21242 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
21243 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
21244 +       0
21245 +};
21246 +               /* accounting only */
21247 +uint32_t account_mask =
21248 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
21249 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
21250 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
21251 +       0;
21252 +
21253 +
21254 +static int is_valid_vlimit(int id)
21255 +{
21256 +       uint32_t mask = vlimit_mask.minimum |
21257 +               vlimit_mask.softlimit | vlimit_mask.maximum;
21258 +       return mask & (1 << id);
21259 +}
21260 +
21261 +static int is_accounted_vlimit(int id)
21262 +{
21263 +       if (is_valid_vlimit(id))
21264 +               return 1;
21265 +       return account_mask & (1 << id);
21266 +}
21267 +
21268 +
21269 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
21270 +{
21271 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
21272 +       return VX_VLIM(limit);
21273 +}
21274 +
21275 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
21276 +{
21277 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
21278 +       return VX_VLIM(limit);
21279 +}
21280 +
21281 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
21282 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
21283 +{
21284 +       if (!is_valid_vlimit(id))
21285 +               return -EINVAL;
21286 +
21287 +       if (minimum)
21288 +               *minimum = CRLIM_UNSET;
21289 +       if (softlimit)
21290 +               *softlimit = vc_get_soft(vxi, id);
21291 +       if (maximum)
21292 +               *maximum = vc_get_hard(vxi, id);
21293 +       return 0;
21294 +}
21295 +
21296 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
21297 +{
21298 +       struct vcmd_ctx_rlimit_v0 vc_data;
21299 +       int ret;
21300 +
21301 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21302 +               return -EFAULT;
21303 +
21304 +       ret = do_get_rlimit(vxi, vc_data.id,
21305 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
21306 +       if (ret)
21307 +               return ret;
21308 +
21309 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21310 +               return -EFAULT;
21311 +       return 0;
21312 +}
21313 +
21314 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
21315 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
21316 +{
21317 +       if (!is_valid_vlimit(id))
21318 +               return -EINVAL;
21319 +
21320 +       if (maximum != CRLIM_KEEP)
21321 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
21322 +       if (softlimit != CRLIM_KEEP)
21323 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
21324 +
21325 +       /* clamp soft limit */
21326 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
21327 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
21328 +
21329 +       return 0;
21330 +}
21331 +
21332 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
21333 +{
21334 +       struct vcmd_ctx_rlimit_v0 vc_data;
21335 +
21336 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21337 +               return -EFAULT;
21338 +
21339 +       return do_set_rlimit(vxi, vc_data.id,
21340 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
21341 +}
21342 +
21343 +#ifdef CONFIG_IA32_EMULATION
21344 +
21345 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
21346 +{
21347 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
21348 +
21349 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21350 +               return -EFAULT;
21351 +
21352 +       return do_set_rlimit(vxi, vc_data.id,
21353 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
21354 +}
21355 +
21356 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
21357 +{
21358 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
21359 +       int ret;
21360 +
21361 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21362 +               return -EFAULT;
21363 +
21364 +       ret = do_get_rlimit(vxi, vc_data.id,
21365 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
21366 +       if (ret)
21367 +               return ret;
21368 +
21369 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21370 +               return -EFAULT;
21371 +       return 0;
21372 +}
21373 +
21374 +#endif /* CONFIG_IA32_EMULATION */
21375 +
21376 +
21377 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
21378 +{
21379 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
21380 +               return -EFAULT;
21381 +       return 0;
21382 +}
21383 +
21384 +
21385 +static inline void vx_reset_minmax(struct _vx_limit *limit)
21386 +{
21387 +       rlim_t value;
21388 +       int lim;
21389 +
21390 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21391 +               value = __rlim_get(limit, lim);
21392 +               __rlim_rmax(limit, lim) = value;
21393 +               __rlim_rmin(limit, lim) = value;
21394 +       }
21395 +}
21396 +
21397 +
21398 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
21399 +{
21400 +       vx_reset_minmax(&vxi->limit);
21401 +       return 0;
21402 +}
21403 +
21404 +
21405 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
21406 +{
21407 +       struct vcmd_rlimit_stat_v0 vc_data;
21408 +       struct _vx_limit *limit = &vxi->limit;
21409 +       int id;
21410 +
21411 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21412 +               return -EFAULT;
21413 +
21414 +       id = vc_data.id;
21415 +       if (!is_accounted_vlimit(id))
21416 +               return -EINVAL;
21417 +
21418 +       vx_limit_fixup(limit, id);
21419 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
21420 +       vc_data.value = __rlim_get(limit, id);
21421 +       vc_data.minimum = __rlim_rmin(limit, id);
21422 +       vc_data.maximum = __rlim_rmax(limit, id);
21423 +
21424 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21425 +               return -EFAULT;
21426 +       return 0;
21427 +}
21428 +
21429 +
21430 +void vx_vsi_meminfo(struct sysinfo *val)
21431 +{
21432 +       struct vx_info *vxi = current->vx_info;
21433 +       unsigned long totalram, freeram;
21434 +       rlim_t v;
21435 +
21436 +       /* we blindly accept the max */
21437 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21438 +       totalram = (v != RLIM_INFINITY) ? v : val->totalram;
21439 +
21440 +       /* total minus used equals free */
21441 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21442 +       freeram = (v < totalram) ? totalram - v : 0;
21443 +
21444 +       val->totalram = totalram;
21445 +       val->freeram = freeram;
21446 +       val->bufferram = 0;
21447 +       val->totalhigh = 0;
21448 +       val->freehigh = 0;
21449 +       return;
21450 +}
21451 +
21452 +void vx_vsi_swapinfo(struct sysinfo *val)
21453 +{
21454 +       struct vx_info *vxi = current->vx_info;
21455 +       unsigned long totalswap, freeswap;
21456 +       rlim_t v, w;
21457 +
21458 +       v = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21459 +       if (v == RLIM_INFINITY) {
21460 +               val->freeswap = val->totalswap;
21461 +               return;
21462 +       }
21463 +
21464 +       /* we blindly accept the max */
21465 +       w = __rlim_hard(&vxi->limit, RLIMIT_RSS);
21466 +       totalswap = (w != RLIM_INFINITY) ? (w - v) : val->totalswap;
21467 +
21468 +       /* currently 'used' swap */
21469 +       w = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21470 +       w -= (w > v) ? v : w;
21471 +
21472 +       /* total minus used equals free */
21473 +       freeswap = (w < totalswap) ? totalswap - w : 0;
21474 +
21475 +       val->totalswap = totalswap;
21476 +       val->freeswap = freeswap;
21477 +       return;
21478 +}
21479 +
21480 +
21481 +unsigned long vx_badness(struct task_struct *task, struct mm_struct *mm)
21482 +{
21483 +       struct vx_info *vxi = mm->mm_vx_info;
21484 +       unsigned long points;
21485 +       rlim_t v, w;
21486 +
21487 +       if (!vxi)
21488 +               return 0;
21489 +
21490 +       points = vxi->vx_badness_bias;
21491 +
21492 +       v = __vx_cres_array_fixup(&vxi->limit, VLA_RSS);
21493 +       w = __rlim_soft(&vxi->limit, RLIMIT_RSS);
21494 +       points += (v > w) ? (v - w) : 0;
21495 +
21496 +       return points;
21497 +}
21498 +
21499 diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/limit_init.h linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/limit_init.h
21500 --- linux-2.6.29.4/kernel/vserver/limit_init.h  1970-01-01 01:00:00.000000000 +0100
21501 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/limit_init.h    2009-02-22 22:54:26.000000000 +0100
21502 @@ -0,0 +1,31 @@
21503 +
21504 +
21505 +static inline void vx_info_init_limit(struct _vx_limit *limit)
21506 +{
21507 +       int lim;
21508 +
21509 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21510 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
21511 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
21512 +               __rlim_set(limit, lim, 0);
21513 +               atomic_set(&__rlim_lhit(limit, lim), 0);
21514 +               __rlim_rmin(limit, lim) = 0;
21515 +               __rlim_rmax(limit, lim) = 0;
21516 +       }
21517 +}
21518 +
21519 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
21520 +{
21521 +       rlim_t value;
21522 +       int lim;
21523 +
21524 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
21525 +               if ((1 << lim) & VLIM_NOCHECK)
21526 +                       continue;
21527 +               value = __rlim_get(limit, lim);
21528 +               vxwprintk_xid(value,
21529 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
21530 +                       limit, vlimit_name[lim], lim, (long)value);
21531 +       }
21532 +}
21533 +
21534 diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/limit_proc.h linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/limit_proc.h
21535 --- linux-2.6.29.4/kernel/vserver/limit_proc.h  1970-01-01 01:00:00.000000000 +0100
21536 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/limit_proc.h    2009-02-22 22:54:26.000000000 +0100
21537 @@ -0,0 +1,57 @@
21538 +#ifndef _VX_LIMIT_PROC_H
21539 +#define _VX_LIMIT_PROC_H
21540 +
21541 +#include <linux/vserver/limit_int.h>
21542 +
21543 +
21544 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
21545 +#define VX_LIMIT_TOP   \
21546 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
21547 +
21548 +#define VX_LIMIT_ARG(r)                                \
21549 +       (unsigned long)__rlim_get(limit, r),    \
21550 +       (unsigned long)__rlim_rmin(limit, r),   \
21551 +       (unsigned long)__rlim_rmax(limit, r),   \
21552 +       VX_VLIM(__rlim_soft(limit, r)),         \
21553 +       VX_VLIM(__rlim_hard(limit, r)),         \
21554 +       atomic_read(&__rlim_lhit(limit, r))
21555 +
21556 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
21557 +{
21558 +       vx_limit_fixup(limit, -1);
21559 +       return sprintf(buffer, VX_LIMIT_TOP
21560 +               "PROC"  VX_LIMIT_FMT
21561 +               "VM"    VX_LIMIT_FMT
21562 +               "VML"   VX_LIMIT_FMT
21563 +               "RSS"   VX_LIMIT_FMT
21564 +               "ANON"  VX_LIMIT_FMT
21565 +               "RMAP"  VX_LIMIT_FMT
21566 +               "FILES" VX_LIMIT_FMT
21567 +               "OFD"   VX_LIMIT_FMT
21568 +               "LOCKS" VX_LIMIT_FMT
21569 +               "SOCK"  VX_LIMIT_FMT
21570 +               "MSGQ"  VX_LIMIT_FMT
21571 +               "SHM"   VX_LIMIT_FMT
21572 +               "SEMA"  VX_LIMIT_FMT
21573 +               "SEMS"  VX_LIMIT_FMT
21574 +               "DENT"  VX_LIMIT_FMT,
21575 +               VX_LIMIT_ARG(RLIMIT_NPROC),
21576 +               VX_LIMIT_ARG(RLIMIT_AS),
21577 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
21578 +               VX_LIMIT_ARG(RLIMIT_RSS),
21579 +               VX_LIMIT_ARG(VLIMIT_ANON),
21580 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
21581 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
21582 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
21583 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
21584 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
21585 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
21586 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
21587 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
21588 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
21589 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
21590 +}
21591 +
21592 +#endif /* _VX_LIMIT_PROC_H */
21593 +
21594 +
21595 diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/Makefile linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/Makefile
21596 --- linux-2.6.29.4/kernel/vserver/Makefile      1970-01-01 01:00:00.000000000 +0100
21597 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/Makefile        2009-02-22 22:54:26.000000000 +0100
21598 @@ -0,0 +1,18 @@
21599 +#
21600 +# Makefile for the Linux vserver routines.
21601 +#
21602 +
21603 +
21604 +obj-y          += vserver.o
21605 +
21606 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
21607 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
21608 +                  dlimit.o tag.o
21609 +
21610 +vserver-$(CONFIG_INET) += inet.o
21611 +vserver-$(CONFIG_PROC_FS) += proc.o
21612 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
21613 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
21614 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
21615 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
21616 +
21617 diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/monitor.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/monitor.c
21618 --- linux-2.6.29.4/kernel/vserver/monitor.c     1970-01-01 01:00:00.000000000 +0100
21619 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/monitor.c       2009-02-22 22:54:26.000000000 +0100
21620 @@ -0,0 +1,138 @@
21621 +/*
21622 + *  kernel/vserver/monitor.c
21623 + *
21624 + *  Virtual Context Scheduler Monitor
21625 + *
21626 + *  Copyright (C) 2006-2007 Herbert Pötzl
21627 + *
21628 + *  V0.01  basic design
21629 + *
21630 + */
21631 +
21632 +#include <linux/module.h>
21633 +#include <linux/jiffies.h>
21634 +#include <asm/uaccess.h>
21635 +#include <asm/atomic.h>
21636 +
21637 +#include <linux/vserver/monitor.h>
21638 +#include <linux/vserver/debug_cmd.h>
21639 +
21640 +
21641 +#ifdef CONFIG_VSERVER_MONITOR
21642 +#define VXM_SIZE       CONFIG_VSERVER_MONITOR_SIZE
21643 +#else
21644 +#define VXM_SIZE       64
21645 +#endif
21646 +
21647 +struct _vx_monitor {
21648 +       unsigned int counter;
21649 +
21650 +       struct _vx_mon_entry entry[VXM_SIZE+1];
21651 +};
21652 +
21653 +
21654 +DEFINE_PER_CPU(struct _vx_monitor, vx_monitor_buffer);
21655 +
21656 +unsigned volatile int vxm_active = 1;
21657 +
21658 +static atomic_t sequence = ATOMIC_INIT(0);
21659 +
21660 +
21661 +/*     vxm_advance()
21662 +
21663 +       * requires disabled preemption                          */
21664 +
21665 +struct _vx_mon_entry *vxm_advance(int cpu)
21666 +{
21667 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
21668 +       struct _vx_mon_entry *entry;
21669 +       unsigned int index;
21670 +
21671 +       index = vxm_active ? (mon->counter++ % VXM_SIZE) : VXM_SIZE;
21672 +       entry = &mon->entry[index];
21673 +
21674 +       entry->ev.seq = atomic_inc_return(&sequence);
21675 +       entry->ev.jif = jiffies;
21676 +       return entry;
21677 +}
21678 +
21679 +EXPORT_SYMBOL_GPL(vxm_advance);
21680 +
21681 +
21682 +int do_read_monitor(struct __user _vx_mon_entry *data,
21683 +       int cpu, uint32_t *index, uint32_t *count)
21684 +{
21685 +       int pos, ret = 0;
21686 +       struct _vx_monitor *mon = &per_cpu(vx_monitor_buffer, cpu);
21687 +       int end = mon->counter;
21688 +       int start = end - VXM_SIZE + 2;
21689 +       int idx = *index;
21690 +
21691 +       /* special case: get current pos */
21692 +       if (!*count) {
21693 +               *index = end;
21694 +               return 0;
21695 +       }
21696 +
21697 +       /* have we lost some data? */
21698 +       if (idx < start)
21699 +               idx = start;
21700 +
21701 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
21702 +               struct _vx_mon_entry *entry =
21703 +                       &mon->entry[idx % VXM_SIZE];
21704 +
21705 +               /* send entry to userspace */
21706 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
21707 +               if (ret)
21708 +                       break;
21709 +       }
21710 +       /* save new index and count */
21711 +       *index = idx;
21712 +       *count = pos;
21713 +       return ret ? ret : (*index < end);
21714 +}
21715 +
21716 +int vc_read_monitor(uint32_t id, void __user *data)
21717 +{
21718 +       struct vcmd_read_monitor_v0 vc_data;
21719 +       int ret;
21720 +
21721 +       if (id >= NR_CPUS)
21722 +               return -EINVAL;
21723 +
21724 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21725 +               return -EFAULT;
21726 +
21727 +       ret = do_read_monitor((struct __user _vx_mon_entry *)vc_data.data,
21728 +               id, &vc_data.index, &vc_data.count);
21729 +
21730 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21731 +               return -EFAULT;
21732 +       return ret;
21733 +}
21734 +
21735 +#ifdef CONFIG_COMPAT
21736 +
21737 +int vc_read_monitor_x32(uint32_t id, void __user *data)
21738 +{
21739 +       struct vcmd_read_monitor_v0_x32 vc_data;
21740 +       int ret;
21741 +
21742 +       if (id >= NR_CPUS)
21743 +               return -EINVAL;
21744 +
21745 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21746 +               return -EFAULT;
21747 +
21748 +       ret = do_read_monitor((struct __user _vx_mon_entry *)
21749 +               compat_ptr(vc_data.data_ptr),
21750 +               id, &vc_data.index, &vc_data.count);
21751 +
21752 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21753 +               return -EFAULT;
21754 +       return ret;
21755 +}
21756 +
21757 +#endif /* CONFIG_COMPAT */
21758 +
21759 diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/network.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/network.c
21760 --- linux-2.6.29.4/kernel/vserver/network.c     1970-01-01 01:00:00.000000000 +0100
21761 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/network.c       2009-02-22 22:54:26.000000000 +0100
21762 @@ -0,0 +1,864 @@
21763 +/*
21764 + *  linux/kernel/vserver/network.c
21765 + *
21766 + *  Virtual Server: Network Support
21767 + *
21768 + *  Copyright (C) 2003-2007  Herbert Pötzl
21769 + *
21770 + *  V0.01  broken out from vcontext V0.05
21771 + *  V0.02  cleaned up implementation
21772 + *  V0.03  added equiv nx commands
21773 + *  V0.04  switch to RCU based hash
21774 + *  V0.05  and back to locking again
21775 + *  V0.06  changed vcmds to nxi arg
21776 + *  V0.07  have __create claim() the nxi
21777 + *
21778 + */
21779 +
21780 +#include <linux/err.h>
21781 +#include <linux/slab.h>
21782 +#include <linux/rcupdate.h>
21783 +
21784 +#include <linux/vs_network.h>
21785 +#include <linux/vs_pid.h>
21786 +#include <linux/vserver/network_cmd.h>
21787 +
21788 +
21789 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
21790 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
21791 +
21792 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
21793 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
21794 +
21795 +
21796 +static int __init init_network(void)
21797 +{
21798 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
21799 +               sizeof(struct nx_addr_v4), 0,
21800 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
21801 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
21802 +               sizeof(struct nx_addr_v6), 0,
21803 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
21804 +       return 0;
21805 +}
21806 +
21807 +
21808 +/*     __alloc_nx_addr_v4()                                    */
21809 +
21810 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
21811 +{
21812 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
21813 +               nx_addr_v4_cachep, GFP_KERNEL);
21814 +
21815 +       if (!IS_ERR(nxa))
21816 +               memset(nxa, 0, sizeof(*nxa));
21817 +       return nxa;
21818 +}
21819 +
21820 +/*     __dealloc_nx_addr_v4()                                  */
21821 +
21822 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
21823 +{
21824 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
21825 +}
21826 +
21827 +/*     __dealloc_nx_addr_v4_all()                              */
21828 +
21829 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
21830 +{
21831 +       while (nxa) {
21832 +               struct nx_addr_v4 *next = nxa->next;
21833 +
21834 +               __dealloc_nx_addr_v4(nxa);
21835 +               nxa = next;
21836 +       }
21837 +}
21838 +
21839 +
21840 +#ifdef CONFIG_IPV6
21841 +
21842 +/*     __alloc_nx_addr_v6()                                    */
21843 +
21844 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
21845 +{
21846 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
21847 +               nx_addr_v6_cachep, GFP_KERNEL);
21848 +
21849 +       if (!IS_ERR(nxa))
21850 +               memset(nxa, 0, sizeof(*nxa));
21851 +       return nxa;
21852 +}
21853 +
21854 +/*     __dealloc_nx_addr_v6()                                  */
21855 +
21856 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
21857 +{
21858 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
21859 +}
21860 +
21861 +/*     __dealloc_nx_addr_v6_all()                              */
21862 +
21863 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
21864 +{
21865 +       while (nxa) {
21866 +               struct nx_addr_v6 *next = nxa->next;
21867 +
21868 +               __dealloc_nx_addr_v6(nxa);
21869 +               nxa = next;
21870 +       }
21871 +}
21872 +
21873 +#endif /* CONFIG_IPV6 */
21874 +
21875 +/*     __alloc_nx_info()
21876 +
21877 +       * allocate an initialized nx_info struct
21878 +       * doesn't make it visible (hash)                        */
21879 +
21880 +static struct nx_info *__alloc_nx_info(nid_t nid)
21881 +{
21882 +       struct nx_info *new = NULL;
21883 +
21884 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
21885 +
21886 +       /* would this benefit from a slab cache? */
21887 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
21888 +       if (!new)
21889 +               return 0;
21890 +
21891 +       memset(new, 0, sizeof(struct nx_info));
21892 +       new->nx_id = nid;
21893 +       INIT_HLIST_NODE(&new->nx_hlist);
21894 +       atomic_set(&new->nx_usecnt, 0);
21895 +       atomic_set(&new->nx_tasks, 0);
21896 +       new->nx_state = 0;
21897 +
21898 +       new->nx_flags = NXF_INIT_SET;
21899 +
21900 +       /* rest of init goes here */
21901 +
21902 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
21903 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
21904 +
21905 +       vxdprintk(VXD_CBIT(nid, 0),
21906 +               "alloc_nx_info(%d) = %p", nid, new);
21907 +       atomic_inc(&nx_global_ctotal);
21908 +       return new;
21909 +}
21910 +
21911 +/*     __dealloc_nx_info()
21912 +
21913 +       * final disposal of nx_info                             */
21914 +
21915 +static void __dealloc_nx_info(struct nx_info *nxi)
21916 +{
21917 +       vxdprintk(VXD_CBIT(nid, 0),
21918 +               "dealloc_nx_info(%p)", nxi);
21919 +
21920 +       nxi->nx_hlist.next = LIST_POISON1;
21921 +       nxi->nx_id = -1;
21922 +
21923 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
21924 +       BUG_ON(atomic_read(&nxi->nx_tasks));
21925 +
21926 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
21927 +
21928 +       nxi->nx_state |= NXS_RELEASED;
21929 +       kfree(nxi);
21930 +       atomic_dec(&nx_global_ctotal);
21931 +}
21932 +
21933 +static void __shutdown_nx_info(struct nx_info *nxi)
21934 +{
21935 +       nxi->nx_state |= NXS_SHUTDOWN;
21936 +       vs_net_change(nxi, VSC_NETDOWN);
21937 +}
21938 +
21939 +/*     exported stuff                                          */
21940 +
21941 +void free_nx_info(struct nx_info *nxi)
21942 +{
21943 +       /* context shutdown is mandatory */
21944 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
21945 +
21946 +       /* context must not be hashed */
21947 +       BUG_ON(nxi->nx_state & NXS_HASHED);
21948 +
21949 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
21950 +       BUG_ON(atomic_read(&nxi->nx_tasks));
21951 +
21952 +       __dealloc_nx_info(nxi);
21953 +}
21954 +
21955 +
21956 +void __nx_set_lback(struct nx_info *nxi)
21957 +{
21958 +       int nid = nxi->nx_id;
21959 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
21960 +
21961 +       nxi->v4_lback.s_addr = lback;
21962 +}
21963 +
21964 +extern int __nx_inet_add_lback(__be32 addr);
21965 +extern int __nx_inet_del_lback(__be32 addr);
21966 +
21967 +
21968 +/*     hash table for nx_info hash */
21969 +
21970 +#define NX_HASH_SIZE   13
21971 +
21972 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
21973 +
21974 +static spinlock_t nx_info_hash_lock = SPIN_LOCK_UNLOCKED;
21975 +
21976 +
21977 +static inline unsigned int __hashval(nid_t nid)
21978 +{
21979 +       return (nid % NX_HASH_SIZE);
21980 +}
21981 +
21982 +
21983 +
21984 +/*     __hash_nx_info()
21985 +
21986 +       * add the nxi to the global hash table
21987 +       * requires the hash_lock to be held                     */
21988 +
21989 +static inline void __hash_nx_info(struct nx_info *nxi)
21990 +{
21991 +       struct hlist_head *head;
21992 +
21993 +       vxd_assert_lock(&nx_info_hash_lock);
21994 +       vxdprintk(VXD_CBIT(nid, 4),
21995 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
21996 +
21997 +       /* context must not be hashed */
21998 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
21999 +
22000 +       nxi->nx_state |= NXS_HASHED;
22001 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
22002 +       hlist_add_head(&nxi->nx_hlist, head);
22003 +       atomic_inc(&nx_global_cactive);
22004 +}
22005 +
22006 +/*     __unhash_nx_info()
22007 +
22008 +       * remove the nxi from the global hash table
22009 +       * requires the hash_lock to be held                     */
22010 +
22011 +static inline void __unhash_nx_info(struct nx_info *nxi)
22012 +{
22013 +       vxd_assert_lock(&nx_info_hash_lock);
22014 +       vxdprintk(VXD_CBIT(nid, 4),
22015 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
22016 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
22017 +
22018 +       /* context must be hashed */
22019 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
22020 +       /* but without tasks */
22021 +       BUG_ON(atomic_read(&nxi->nx_tasks));
22022 +
22023 +       nxi->nx_state &= ~NXS_HASHED;
22024 +       hlist_del(&nxi->nx_hlist);
22025 +       atomic_dec(&nx_global_cactive);
22026 +}
22027 +
22028 +
22029 +/*     __lookup_nx_info()
22030 +
22031 +       * requires the hash_lock to be held
22032 +       * doesn't increment the nx_refcnt                       */
22033 +
22034 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
22035 +{
22036 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
22037 +       struct hlist_node *pos;
22038 +       struct nx_info *nxi;
22039 +
22040 +       vxd_assert_lock(&nx_info_hash_lock);
22041 +       hlist_for_each(pos, head) {
22042 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
22043 +
22044 +               if (nxi->nx_id == nid)
22045 +                       goto found;
22046 +       }
22047 +       nxi = NULL;
22048 +found:
22049 +       vxdprintk(VXD_CBIT(nid, 0),
22050 +               "__lookup_nx_info(#%u): %p[#%u]",
22051 +               nid, nxi, nxi ? nxi->nx_id : 0);
22052 +       return nxi;
22053 +}
22054 +
22055 +
22056 +/*     __create_nx_info()
22057 +
22058 +       * create the requested context
22059 +       * get(), claim() and hash it                            */
22060 +
22061 +static struct nx_info *__create_nx_info(int id)
22062 +{
22063 +       struct nx_info *new, *nxi = NULL;
22064 +
22065 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
22066 +
22067 +       if (!(new = __alloc_nx_info(id)))
22068 +               return ERR_PTR(-ENOMEM);
22069 +
22070 +       /* required to make dynamic xids unique */
22071 +       spin_lock(&nx_info_hash_lock);
22072 +
22073 +       /* static context requested */
22074 +       if ((nxi = __lookup_nx_info(id))) {
22075 +               vxdprintk(VXD_CBIT(nid, 0),
22076 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
22077 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22078 +                       nxi = ERR_PTR(-EBUSY);
22079 +               else
22080 +                       nxi = ERR_PTR(-EEXIST);
22081 +               goto out_unlock;
22082 +       }
22083 +       /* new context */
22084 +       vxdprintk(VXD_CBIT(nid, 0),
22085 +               "create_nx_info(%d) = %p (new)", id, new);
22086 +       claim_nx_info(new, NULL);
22087 +       __nx_set_lback(new);
22088 +       __hash_nx_info(get_nx_info(new));
22089 +       nxi = new, new = NULL;
22090 +
22091 +out_unlock:
22092 +       spin_unlock(&nx_info_hash_lock);
22093 +       if (new)
22094 +               __dealloc_nx_info(new);
22095 +       return nxi;
22096 +}
22097 +
22098 +
22099 +
22100 +/*     exported stuff                                          */
22101 +
22102 +
22103 +void unhash_nx_info(struct nx_info *nxi)
22104 +{
22105 +       __shutdown_nx_info(nxi);
22106 +       spin_lock(&nx_info_hash_lock);
22107 +       __unhash_nx_info(nxi);
22108 +       spin_unlock(&nx_info_hash_lock);
22109 +}
22110 +
22111 +/*     lookup_nx_info()
22112 +
22113 +       * search for a nx_info and get() it
22114 +       * negative id means current                             */
22115 +
22116 +struct nx_info *lookup_nx_info(int id)
22117 +{
22118 +       struct nx_info *nxi = NULL;
22119 +
22120 +       if (id < 0) {
22121 +               nxi = get_nx_info(current->nx_info);
22122 +       } else if (id > 1) {
22123 +               spin_lock(&nx_info_hash_lock);
22124 +               nxi = get_nx_info(__lookup_nx_info(id));
22125 +               spin_unlock(&nx_info_hash_lock);
22126 +       }
22127 +       return nxi;
22128 +}
22129 +
22130 +/*     nid_is_hashed()
22131 +
22132 +       * verify that nid is still hashed                       */
22133 +
22134 +int nid_is_hashed(nid_t nid)
22135 +{
22136 +       int hashed;
22137 +
22138 +       spin_lock(&nx_info_hash_lock);
22139 +       hashed = (__lookup_nx_info(nid) != NULL);
22140 +       spin_unlock(&nx_info_hash_lock);
22141 +       return hashed;
22142 +}
22143 +
22144 +
22145 +#ifdef CONFIG_PROC_FS
22146 +
22147 +/*     get_nid_list()
22148 +
22149 +       * get a subset of hashed nids for proc
22150 +       * assumes size is at least one                          */
22151 +
22152 +int get_nid_list(int index, unsigned int *nids, int size)
22153 +{
22154 +       int hindex, nr_nids = 0;
22155 +
22156 +       /* only show current and children */
22157 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
22158 +               if (index > 0)
22159 +                       return 0;
22160 +               nids[nr_nids] = nx_current_nid();
22161 +               return 1;
22162 +       }
22163 +
22164 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
22165 +               struct hlist_head *head = &nx_info_hash[hindex];
22166 +               struct hlist_node *pos;
22167 +
22168 +               spin_lock(&nx_info_hash_lock);
22169 +               hlist_for_each(pos, head) {
22170 +                       struct nx_info *nxi;
22171 +
22172 +                       if (--index > 0)
22173 +                               continue;
22174 +
22175 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
22176 +                       nids[nr_nids] = nxi->nx_id;
22177 +                       if (++nr_nids >= size) {
22178 +                               spin_unlock(&nx_info_hash_lock);
22179 +                               goto out;
22180 +                       }
22181 +               }
22182 +               /* keep the lock time short */
22183 +               spin_unlock(&nx_info_hash_lock);
22184 +       }
22185 +out:
22186 +       return nr_nids;
22187 +}
22188 +#endif
22189 +
22190 +
22191 +/*
22192 + *     migrate task to new network
22193 + *     gets nxi, puts old_nxi on change
22194 + */
22195 +
22196 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
22197 +{
22198 +       struct nx_info *old_nxi;
22199 +       int ret = 0;
22200 +
22201 +       if (!p || !nxi)
22202 +               BUG();
22203 +
22204 +       vxdprintk(VXD_CBIT(nid, 5),
22205 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
22206 +               p, nxi, nxi->nx_id,
22207 +               atomic_read(&nxi->nx_usecnt),
22208 +               atomic_read(&nxi->nx_tasks));
22209 +
22210 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
22211 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
22212 +               return -EACCES;
22213 +
22214 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
22215 +               return -EFAULT;
22216 +
22217 +       /* maybe disallow this completely? */
22218 +       old_nxi = task_get_nx_info(p);
22219 +       if (old_nxi == nxi)
22220 +               goto out;
22221 +
22222 +       task_lock(p);
22223 +       if (old_nxi)
22224 +               clr_nx_info(&p->nx_info);
22225 +       claim_nx_info(nxi, p);
22226 +       set_nx_info(&p->nx_info, nxi);
22227 +       p->nid = nxi->nx_id;
22228 +       task_unlock(p);
22229 +
22230 +       vxdprintk(VXD_CBIT(nid, 5),
22231 +               "moved task %p into nxi:%p[#%d]",
22232 +               p, nxi, nxi->nx_id);
22233 +
22234 +       if (old_nxi)
22235 +               release_nx_info(old_nxi, p);
22236 +       ret = 0;
22237 +out:
22238 +       put_nx_info(old_nxi);
22239 +       return ret;
22240 +}
22241 +
22242 +
22243 +void nx_set_persistent(struct nx_info *nxi)
22244 +{
22245 +       vxdprintk(VXD_CBIT(nid, 6),
22246 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
22247 +
22248 +       get_nx_info(nxi);
22249 +       claim_nx_info(nxi, NULL);
22250 +}
22251 +
22252 +void nx_clear_persistent(struct nx_info *nxi)
22253 +{
22254 +       vxdprintk(VXD_CBIT(nid, 6),
22255 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
22256 +
22257 +       release_nx_info(nxi, NULL);
22258 +       put_nx_info(nxi);
22259 +}
22260 +
22261 +void nx_update_persistent(struct nx_info *nxi)
22262 +{
22263 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
22264 +               nx_set_persistent(nxi);
22265 +       else
22266 +               nx_clear_persistent(nxi);
22267 +}
22268 +
22269 +/* vserver syscall commands below here */
22270 +
22271 +/* taks nid and nx_info functions */
22272 +
22273 +#include <asm/uaccess.h>
22274 +
22275 +
22276 +int vc_task_nid(uint32_t id)
22277 +{
22278 +       nid_t nid;
22279 +
22280 +       if (id) {
22281 +               struct task_struct *tsk;
22282 +
22283 +               read_lock(&tasklist_lock);
22284 +               tsk = find_task_by_real_pid(id);
22285 +               nid = (tsk) ? tsk->nid : -ESRCH;
22286 +               read_unlock(&tasklist_lock);
22287 +       } else
22288 +               nid = nx_current_nid();
22289 +       return nid;
22290 +}
22291 +
22292 +
22293 +int vc_nx_info(struct nx_info *nxi, void __user *data)
22294 +{
22295 +       struct vcmd_nx_info_v0 vc_data;
22296 +
22297 +       vc_data.nid = nxi->nx_id;
22298 +
22299 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22300 +               return -EFAULT;
22301 +       return 0;
22302 +}
22303 +
22304 +
22305 +/* network functions */
22306 +
22307 +int vc_net_create(uint32_t nid, void __user *data)
22308 +{
22309 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
22310 +       struct nx_info *new_nxi;
22311 +       int ret;
22312 +
22313 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22314 +               return -EFAULT;
22315 +
22316 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
22317 +               return -EINVAL;
22318 +
22319 +       new_nxi = __create_nx_info(nid);
22320 +       if (IS_ERR(new_nxi))
22321 +               return PTR_ERR(new_nxi);
22322 +
22323 +       /* initial flags */
22324 +       new_nxi->nx_flags = vc_data.flagword;
22325 +
22326 +       ret = -ENOEXEC;
22327 +       if (vs_net_change(new_nxi, VSC_NETUP))
22328 +               goto out;
22329 +
22330 +       ret = nx_migrate_task(current, new_nxi);
22331 +       if (ret)
22332 +               goto out;
22333 +
22334 +       /* return context id on success */
22335 +       ret = new_nxi->nx_id;
22336 +
22337 +       /* get a reference for persistent contexts */
22338 +       if ((vc_data.flagword & NXF_PERSISTENT))
22339 +               nx_set_persistent(new_nxi);
22340 +out:
22341 +       release_nx_info(new_nxi, NULL);
22342 +       put_nx_info(new_nxi);
22343 +       return ret;
22344 +}
22345 +
22346 +
22347 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
22348 +{
22349 +       return nx_migrate_task(current, nxi);
22350 +}
22351 +
22352 +
22353 +
22354 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
22355 +       uint16_t type, uint16_t flags)
22356 +{
22357 +       struct nx_addr_v4 *nxa = &nxi->v4;
22358 +
22359 +       if (NX_IPV4(nxi)) {
22360 +               /* locate last entry */
22361 +               for (; nxa->next; nxa = nxa->next);
22362 +               nxa->next = __alloc_nx_addr_v4();
22363 +               nxa = nxa->next;
22364 +
22365 +               if (IS_ERR(nxa))
22366 +                       return PTR_ERR(nxa);
22367 +       }
22368 +
22369 +       if (nxi->v4.next)
22370 +               /* remove single ip for ip list */
22371 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
22372 +
22373 +       nxa->ip[0].s_addr = ip;
22374 +       nxa->ip[1].s_addr = ip2;
22375 +       nxa->mask.s_addr = mask;
22376 +       nxa->type = type;
22377 +       nxa->flags = flags;
22378 +       return 0;
22379 +}
22380 +
22381 +
22382 +int vc_net_add(struct nx_info *nxi, void __user *data)
22383 +{
22384 +       struct vcmd_net_addr_v0 vc_data;
22385 +       int index, ret = 0;
22386 +
22387 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22388 +               return -EFAULT;
22389 +
22390 +       switch (vc_data.type) {
22391 +       case NXA_TYPE_IPV4:
22392 +               if ((vc_data.count < 1) || (vc_data.count > 4))
22393 +                       return -EINVAL;
22394 +
22395 +               index = 0;
22396 +               while (index < vc_data.count) {
22397 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
22398 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
22399 +                       if (ret)
22400 +                               return ret;
22401 +                       index++;
22402 +               }
22403 +               ret = index;
22404 +               break;
22405 +
22406 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
22407 +               nxi->v4_bcast = vc_data.ip[0];
22408 +               ret = 1;
22409 +               break;
22410 +
22411 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
22412 +               nxi->v4_lback = vc_data.ip[0];
22413 +               ret = 1;
22414 +               break;
22415 +
22416 +       default:
22417 +               ret = -EINVAL;
22418 +               break;
22419 +       }
22420 +       return ret;
22421 +}
22422 +
22423 +int vc_net_remove(struct nx_info *nxi, void __user *data)
22424 +{
22425 +       struct vcmd_net_addr_v0 vc_data;
22426 +
22427 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22428 +               return -EFAULT;
22429 +
22430 +       switch (vc_data.type) {
22431 +       case NXA_TYPE_ANY:
22432 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
22433 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
22434 +               break;
22435 +
22436 +       default:
22437 +               return -EINVAL;
22438 +       }
22439 +       return 0;
22440 +}
22441 +
22442 +
22443 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
22444 +{
22445 +       struct vcmd_net_addr_ipv4_v1 vc_data;
22446 +
22447 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22448 +               return -EFAULT;
22449 +
22450 +       switch (vc_data.type) {
22451 +       case NXA_TYPE_ADDR:
22452 +       case NXA_TYPE_RANGE:
22453 +       case NXA_TYPE_MASK:
22454 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
22455 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
22456 +
22457 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
22458 +               nxi->v4_bcast = vc_data.ip;
22459 +               break;
22460 +
22461 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
22462 +               nxi->v4_lback = vc_data.ip;
22463 +               break;
22464 +
22465 +       default:
22466 +               return -EINVAL;
22467 +       }
22468 +       return 0;
22469 +}
22470 +
22471 +int vc_net_remove_ipv4(struct nx_info *nxi, void __user *data)
22472 +{
22473 +       struct vcmd_net_addr_ipv4_v1 vc_data;
22474 +
22475 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22476 +               return -EFAULT;
22477 +
22478 +       switch (vc_data.type) {
22479 +/*     case NXA_TYPE_ADDR:
22480 +               break;          */
22481 +
22482 +       case NXA_TYPE_ANY:
22483 +               __dealloc_nx_addr_v4_all(xchg(&nxi->v4.next, NULL));
22484 +               memset(&nxi->v4, 0, sizeof(nxi->v4));
22485 +               break;
22486 +
22487 +       default:
22488 +               return -EINVAL;
22489 +       }
22490 +       return 0;
22491 +}
22492 +
22493 +
22494 +#ifdef CONFIG_IPV6
22495 +
22496 +int do_add_v6_addr(struct nx_info *nxi,
22497 +       struct in6_addr *ip, struct in6_addr *mask,
22498 +       uint32_t prefix, uint16_t type, uint16_t flags)
22499 +{
22500 +       struct nx_addr_v6 *nxa = &nxi->v6;
22501 +
22502 +       if (NX_IPV6(nxi)) {
22503 +               /* locate last entry */
22504 +               for (; nxa->next; nxa = nxa->next);
22505 +               nxa->next = __alloc_nx_addr_v6();
22506 +               nxa = nxa->next;
22507 +
22508 +               if (IS_ERR(nxa))
22509 +                       return PTR_ERR(nxa);
22510 +       }
22511 +
22512 +       nxa->ip = *ip;
22513 +       nxa->mask = *mask;
22514 +       nxa->prefix = prefix;
22515 +       nxa->type = type;
22516 +       nxa->flags = flags;
22517 +       return 0;
22518 +}
22519 +
22520 +
22521 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
22522 +{
22523 +       struct vcmd_net_addr_ipv6_v1 vc_data;
22524 +
22525 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22526 +               return -EFAULT;
22527 +
22528 +       switch (vc_data.type) {
22529 +       case NXA_TYPE_ADDR:
22530 +       case NXA_TYPE_MASK:
22531 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
22532 +                       vc_data.prefix, vc_data.type, vc_data.flags);
22533 +       default:
22534 +               return -EINVAL;
22535 +       }
22536 +       return 0;
22537 +}
22538 +
22539 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
22540 +{
22541 +       struct vcmd_net_addr_ipv6_v1 vc_data;
22542 +
22543 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22544 +               return -EFAULT;
22545 +
22546 +       switch (vc_data.type) {
22547 +       case NXA_TYPE_ANY:
22548 +               __dealloc_nx_addr_v6_all(xchg(&nxi->v6.next, NULL));
22549 +               memset(&nxi->v6, 0, sizeof(nxi->v6));
22550 +               break;
22551 +
22552 +       default:
22553 +               return -EINVAL;
22554 +       }
22555 +       return 0;
22556 +}
22557 +
22558 +#endif /* CONFIG_IPV6 */
22559 +
22560 +
22561 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
22562 +{
22563 +       struct vcmd_net_flags_v0 vc_data;
22564 +
22565 +       vc_data.flagword = nxi->nx_flags;
22566 +
22567 +       /* special STATE flag handling */
22568 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
22569 +
22570 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22571 +               return -EFAULT;
22572 +       return 0;
22573 +}
22574 +
22575 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
22576 +{
22577 +       struct vcmd_net_flags_v0 vc_data;
22578 +       uint64_t mask, trigger;
22579 +
22580 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22581 +               return -EFAULT;
22582 +
22583 +       /* special STATE flag handling */
22584 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
22585 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
22586 +
22587 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
22588 +               vc_data.flagword, mask);
22589 +       if (trigger & NXF_PERSISTENT)
22590 +               nx_update_persistent(nxi);
22591 +
22592 +       return 0;
22593 +}
22594 +
22595 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
22596 +{
22597 +       struct vcmd_net_caps_v0 vc_data;
22598 +
22599 +       vc_data.ncaps = nxi->nx_ncaps;
22600 +       vc_data.cmask = ~0ULL;
22601 +
22602 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22603 +               return -EFAULT;
22604 +       return 0;
22605 +}
22606 +
22607 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
22608 +{
22609 +       struct vcmd_net_caps_v0 vc_data;
22610 +
22611 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22612 +               return -EFAULT;
22613 +
22614 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
22615 +               vc_data.ncaps, vc_data.cmask);
22616 +       return 0;
22617 +}
22618 +
22619 +
22620 +#include <linux/module.h>
22621 +
22622 +module_init(init_network);
22623 +
22624 +EXPORT_SYMBOL_GPL(free_nx_info);
22625 +EXPORT_SYMBOL_GPL(unhash_nx_info);
22626 +
22627 diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/proc.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/proc.c
22628 --- linux-2.6.29.4/kernel/vserver/proc.c        1970-01-01 01:00:00.000000000 +0100
22629 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/proc.c  2009-05-23 22:57:16.000000000 +0200
22630 @@ -0,0 +1,1096 @@
22631 +/*
22632 + *  linux/kernel/vserver/proc.c
22633 + *
22634 + *  Virtual Context Support
22635 + *
22636 + *  Copyright (C) 2003-2007  Herbert Pötzl
22637 + *
22638 + *  V0.01  basic structure
22639 + *  V0.02  adaptation vs1.3.0
22640 + *  V0.03  proc permissions
22641 + *  V0.04  locking/generic
22642 + *  V0.05  next generation procfs
22643 + *  V0.06  inode validation
22644 + *  V0.07  generic rewrite vid
22645 + *  V0.08  remove inode type
22646 + *
22647 + */
22648 +
22649 +#include <linux/proc_fs.h>
22650 +#include <asm/unistd.h>
22651 +
22652 +#include <linux/vs_context.h>
22653 +#include <linux/vs_network.h>
22654 +#include <linux/vs_cvirt.h>
22655 +
22656 +#include <linux/in.h>
22657 +#include <linux/inetdevice.h>
22658 +#include <linux/vs_inet.h>
22659 +#include <linux/vs_inet6.h>
22660 +
22661 +#include <linux/vserver/global.h>
22662 +
22663 +#include "cvirt_proc.h"
22664 +#include "cacct_proc.h"
22665 +#include "limit_proc.h"
22666 +#include "sched_proc.h"
22667 +#include "vci_config.h"
22668 +
22669 +
22670 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
22671 +{
22672 +       unsigned __capi;
22673 +
22674 +       CAP_FOR_EACH_U32(__capi) {
22675 +               buffer += sprintf(buffer, "%08x",
22676 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
22677 +       }
22678 +       return buffer;
22679 +}
22680 +
22681 +
22682 +static struct proc_dir_entry *proc_virtual;
22683 +
22684 +static struct proc_dir_entry *proc_virtnet;
22685 +
22686 +
22687 +/* first the actual feeds */
22688 +
22689 +
22690 +static int proc_vci(char *buffer)
22691 +{
22692 +       return sprintf(buffer,
22693 +               "VCIVersion:\t%04x:%04x\n"
22694 +               "VCISyscall:\t%d\n"
22695 +               "VCIKernel:\t%08x\n",
22696 +               VCI_VERSION >> 16,
22697 +               VCI_VERSION & 0xFFFF,
22698 +               __NR_vserver,
22699 +               vci_kernel_config());
22700 +}
22701 +
22702 +static int proc_virtual_info(char *buffer)
22703 +{
22704 +       return proc_vci(buffer);
22705 +}
22706 +
22707 +static int proc_virtual_status(char *buffer)
22708 +{
22709 +       return sprintf(buffer,
22710 +               "#CTotal:\t%d\n"
22711 +               "#CActive:\t%d\n"
22712 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
22713 +               "#InitTask:\t%d\t%d %d\n",
22714 +               atomic_read(&vx_global_ctotal),
22715 +               atomic_read(&vx_global_cactive),
22716 +               atomic_read(&vs_global_nsproxy),
22717 +               atomic_read(&vs_global_fs),
22718 +               atomic_read(&vs_global_mnt_ns),
22719 +               atomic_read(&vs_global_uts_ns),
22720 +               atomic_read(&vs_global_ipc_ns),
22721 +               atomic_read(&vs_global_user_ns),
22722 +               atomic_read(&vs_global_pid_ns),
22723 +               atomic_read(&init_task.usage),
22724 +               atomic_read(&init_task.nsproxy->count),
22725 +               init_task.fs->users);
22726 +}
22727 +
22728 +
22729 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
22730 +{
22731 +       int length;
22732 +
22733 +       length = sprintf(buffer,
22734 +               "ID:\t%d\n"
22735 +               "Info:\t%p\n"
22736 +               "Init:\t%d\n"
22737 +               "OOM:\t%lld\n",
22738 +               vxi->vx_id,
22739 +               vxi,
22740 +               vxi->vx_initpid,
22741 +               vxi->vx_badness_bias);
22742 +       return length;
22743 +}
22744 +
22745 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
22746 +{
22747 +       char *orig = buffer;
22748 +
22749 +       buffer += sprintf(buffer,
22750 +               "UseCnt:\t%d\n"
22751 +               "Tasks:\t%d\n"
22752 +               "Flags:\t%016llx\n",
22753 +               atomic_read(&vxi->vx_usecnt),
22754 +               atomic_read(&vxi->vx_tasks),
22755 +               (unsigned long long)vxi->vx_flags);
22756 +
22757 +       buffer += sprintf(buffer, "BCaps:\t");
22758 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
22759 +       buffer += sprintf(buffer, "\n");
22760 +
22761 +       buffer += sprintf(buffer,
22762 +               "CCaps:\t%016llx\n"
22763 +               "Spaces:\t%08lx %08lx\n",
22764 +               (unsigned long long)vxi->vx_ccaps,
22765 +               vxi->vx_nsmask[0], vxi->vx_nsmask[1]);
22766 +       return buffer - orig;
22767 +}
22768 +
22769 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
22770 +{
22771 +       return vx_info_proc_limit(&vxi->limit, buffer);
22772 +}
22773 +
22774 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
22775 +{
22776 +       int cpu, length;
22777 +
22778 +       length = vx_info_proc_sched(&vxi->sched, buffer);
22779 +       for_each_online_cpu(cpu) {
22780 +               length += vx_info_proc_sched_pc(
22781 +                       &vx_per_cpu(vxi, sched_pc, cpu),
22782 +                       buffer + length, cpu);
22783 +       }
22784 +       return length;
22785 +}
22786 +
22787 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
22788 +{
22789 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[0], buffer);
22790 +}
22791 +
22792 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
22793 +{
22794 +       return vx_info_proc_nsproxy(vxi->vx_nsproxy[1], buffer);
22795 +}
22796 +
22797 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
22798 +{
22799 +       int cpu, length;
22800 +
22801 +       vx_update_load(vxi);
22802 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
22803 +       for_each_online_cpu(cpu) {
22804 +               length += vx_info_proc_cvirt_pc(
22805 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
22806 +                       buffer + length, cpu);
22807 +       }
22808 +       return length;
22809 +}
22810 +
22811 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
22812 +{
22813 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
22814 +}
22815 +
22816 +
22817 +static int proc_virtnet_info(char *buffer)
22818 +{
22819 +       return proc_vci(buffer);
22820 +}
22821 +
22822 +static int proc_virtnet_status(char *buffer)
22823 +{
22824 +       return sprintf(buffer,
22825 +               "#CTotal:\t%d\n"
22826 +               "#CActive:\t%d\n",
22827 +               atomic_read(&nx_global_ctotal),
22828 +               atomic_read(&nx_global_cactive));
22829 +}
22830 +
22831 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
22832 +{
22833 +       struct nx_addr_v4 *v4a;
22834 +#ifdef CONFIG_IPV6
22835 +       struct nx_addr_v6 *v6a;
22836 +#endif
22837 +       int length, i;
22838 +
22839 +       length = sprintf(buffer,
22840 +               "ID:\t%d\n"
22841 +               "Info:\t%p\n"
22842 +               "Bcast:\t" NIPQUAD_FMT "\n"
22843 +               "Lback:\t" NIPQUAD_FMT "\n",
22844 +               nxi->nx_id,
22845 +               nxi,
22846 +               NIPQUAD(nxi->v4_bcast.s_addr),
22847 +               NIPQUAD(nxi->v4_lback.s_addr));
22848 +
22849 +       if (!NX_IPV4(nxi))
22850 +               goto skip_v4;
22851 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22852 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
22853 +                       i, NXAV4(v4a));
22854 +skip_v4:
22855 +#ifdef CONFIG_IPV6
22856 +       if (!NX_IPV6(nxi))
22857 +               goto skip_v6;
22858 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22859 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
22860 +                       i, NXAV6(v6a));
22861 +skip_v6:
22862 +#endif
22863 +       return length;
22864 +}
22865 +
22866 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
22867 +{
22868 +       int length;
22869 +
22870 +       length = sprintf(buffer,
22871 +               "UseCnt:\t%d\n"
22872 +               "Tasks:\t%d\n"
22873 +               "Flags:\t%016llx\n"
22874 +               "NCaps:\t%016llx\n",
22875 +               atomic_read(&nxi->nx_usecnt),
22876 +               atomic_read(&nxi->nx_tasks),
22877 +               (unsigned long long)nxi->nx_flags,
22878 +               (unsigned long long)nxi->nx_ncaps);
22879 +       return length;
22880 +}
22881 +
22882 +
22883 +
22884 +/* here the inode helpers */
22885 +
22886 +struct vs_entry {
22887 +       int len;
22888 +       char *name;
22889 +       mode_t mode;
22890 +       struct inode_operations *iop;
22891 +       struct file_operations *fop;
22892 +       union proc_op op;
22893 +};
22894 +
22895 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
22896 +{
22897 +       struct inode *inode = new_inode(sb);
22898 +
22899 +       if (!inode)
22900 +               goto out;
22901 +
22902 +       inode->i_mode = p->mode;
22903 +       if (p->iop)
22904 +               inode->i_op = p->iop;
22905 +       if (p->fop)
22906 +               inode->i_fop = p->fop;
22907 +
22908 +       inode->i_nlink = (p->mode & S_IFDIR) ? 2 : 1;
22909 +       inode->i_flags |= S_IMMUTABLE;
22910 +
22911 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
22912 +
22913 +       inode->i_uid = 0;
22914 +       inode->i_gid = 0;
22915 +       inode->i_tag = 0;
22916 +out:
22917 +       return inode;
22918 +}
22919 +
22920 +static struct dentry *vs_proc_instantiate(struct inode *dir,
22921 +       struct dentry *dentry, int id, void *ptr)
22922 +{
22923 +       struct vs_entry *p = ptr;
22924 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
22925 +       struct dentry *error = ERR_PTR(-EINVAL);
22926 +
22927 +       if (!inode)
22928 +               goto out;
22929 +
22930 +       PROC_I(inode)->op = p->op;
22931 +       PROC_I(inode)->fd = id;
22932 +       d_add(dentry, inode);
22933 +       error = NULL;
22934 +out:
22935 +       return error;
22936 +}
22937 +
22938 +/* Lookups */
22939 +
22940 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
22941 +
22942 +/*
22943 + * Fill a directory entry.
22944 + *
22945 + * If possible create the dcache entry and derive our inode number and
22946 + * file type from dcache entry.
22947 + *
22948 + * Since all of the proc inode numbers are dynamically generated, the inode
22949 + * numbers do not exist until the inode is cache.  This means creating the
22950 + * the dcache entry in readdir is necessary to keep the inode numbers
22951 + * reported by readdir in sync with the inode numbers reported
22952 + * by stat.
22953 + */
22954 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
22955 +       char *name, int len, instantiate_t instantiate, int id, void *ptr)
22956 +{
22957 +       struct dentry *child, *dir = filp->f_dentry;
22958 +       struct inode *inode;
22959 +       struct qstr qname;
22960 +       ino_t ino = 0;
22961 +       unsigned type = DT_UNKNOWN;
22962 +
22963 +       qname.name = name;
22964 +       qname.len  = len;
22965 +       qname.hash = full_name_hash(name, len);
22966 +
22967 +       child = d_lookup(dir, &qname);
22968 +       if (!child) {
22969 +               struct dentry *new;
22970 +               new = d_alloc(dir, &qname);
22971 +               if (new) {
22972 +                       child = instantiate(dir->d_inode, new, id, ptr);
22973 +                       if (child)
22974 +                               dput(new);
22975 +                       else
22976 +                               child = new;
22977 +               }
22978 +       }
22979 +       if (!child || IS_ERR(child) || !child->d_inode)
22980 +               goto end_instantiate;
22981 +       inode = child->d_inode;
22982 +       if (inode) {
22983 +               ino = inode->i_ino;
22984 +               type = inode->i_mode >> 12;
22985 +       }
22986 +       dput(child);
22987 +end_instantiate:
22988 +       if (!ino)
22989 +               ino = find_inode_number(dir, &qname);
22990 +       if (!ino)
22991 +               ino = 1;
22992 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
22993 +}
22994 +
22995 +
22996 +
22997 +/* get and revalidate vx_info/xid */
22998 +
22999 +static inline
23000 +struct vx_info *get_proc_vx_info(struct inode *inode)
23001 +{
23002 +       return lookup_vx_info(PROC_I(inode)->fd);
23003 +}
23004 +
23005 +static int proc_xid_revalidate(struct dentry *dentry, struct nameidata *nd)
23006 +{
23007 +       struct inode *inode = dentry->d_inode;
23008 +       xid_t xid = PROC_I(inode)->fd;
23009 +
23010 +       if (!xid || xid_is_hashed(xid))
23011 +               return 1;
23012 +       d_drop(dentry);
23013 +       return 0;
23014 +}
23015 +
23016 +
23017 +/* get and revalidate nx_info/nid */
23018 +
23019 +static int proc_nid_revalidate(struct dentry *dentry, struct nameidata *nd)
23020 +{
23021 +       struct inode *inode = dentry->d_inode;
23022 +       nid_t nid = PROC_I(inode)->fd;
23023 +
23024 +       if (!nid || nid_is_hashed(nid))
23025 +               return 1;
23026 +       d_drop(dentry);
23027 +       return 0;
23028 +}
23029 +
23030 +
23031 +
23032 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
23033 +
23034 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
23035 +                         size_t count, loff_t *ppos)
23036 +{
23037 +       struct inode *inode = file->f_dentry->d_inode;
23038 +       unsigned long page;
23039 +       ssize_t length = 0;
23040 +
23041 +       if (count > PROC_BLOCK_SIZE)
23042 +               count = PROC_BLOCK_SIZE;
23043 +
23044 +       /* fade that out as soon as stable */
23045 +       WARN_ON(PROC_I(inode)->fd);
23046 +
23047 +       if (!(page = __get_free_page(GFP_KERNEL)))
23048 +               return -ENOMEM;
23049 +
23050 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
23051 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
23052 +
23053 +       if (length >= 0)
23054 +               length = simple_read_from_buffer(buf, count, ppos,
23055 +                       (char *)page, length);
23056 +
23057 +       free_page(page);
23058 +       return length;
23059 +}
23060 +
23061 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
23062 +                         size_t count, loff_t *ppos)
23063 +{
23064 +       struct inode *inode = file->f_dentry->d_inode;
23065 +       struct vx_info *vxi = NULL;
23066 +       xid_t xid = PROC_I(inode)->fd;
23067 +       unsigned long page;
23068 +       ssize_t length = 0;
23069 +
23070 +       if (count > PROC_BLOCK_SIZE)
23071 +               count = PROC_BLOCK_SIZE;
23072 +
23073 +       /* fade that out as soon as stable */
23074 +       WARN_ON(!xid);
23075 +       vxi = lookup_vx_info(xid);
23076 +       if (!vxi)
23077 +               goto out;
23078 +
23079 +       length = -ENOMEM;
23080 +       if (!(page = __get_free_page(GFP_KERNEL)))
23081 +               goto out_put;
23082 +
23083 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
23084 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
23085 +
23086 +       if (length >= 0)
23087 +               length = simple_read_from_buffer(buf, count, ppos,
23088 +                       (char *)page, length);
23089 +
23090 +       free_page(page);
23091 +out_put:
23092 +       put_vx_info(vxi);
23093 +out:
23094 +       return length;
23095 +}
23096 +
23097 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
23098 +                         size_t count, loff_t *ppos)
23099 +{
23100 +       struct inode *inode = file->f_dentry->d_inode;
23101 +       struct nx_info *nxi = NULL;
23102 +       nid_t nid = PROC_I(inode)->fd;
23103 +       unsigned long page;
23104 +       ssize_t length = 0;
23105 +
23106 +       if (count > PROC_BLOCK_SIZE)
23107 +               count = PROC_BLOCK_SIZE;
23108 +
23109 +       /* fade that out as soon as stable */
23110 +       WARN_ON(!nid);
23111 +       nxi = lookup_nx_info(nid);
23112 +       if (!nxi)
23113 +               goto out;
23114 +
23115 +       length = -ENOMEM;
23116 +       if (!(page = __get_free_page(GFP_KERNEL)))
23117 +               goto out_put;
23118 +
23119 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
23120 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
23121 +
23122 +       if (length >= 0)
23123 +               length = simple_read_from_buffer(buf, count, ppos,
23124 +                       (char *)page, length);
23125 +
23126 +       free_page(page);
23127 +out_put:
23128 +       put_nx_info(nxi);
23129 +out:
23130 +       return length;
23131 +}
23132 +
23133 +
23134 +
23135 +/* here comes the lower level */
23136 +
23137 +
23138 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
23139 +       .len  = sizeof(NAME) - 1,       \
23140 +       .name = (NAME),                 \
23141 +       .mode = MODE,                   \
23142 +       .iop  = IOP,                    \
23143 +       .fop  = FOP,                    \
23144 +       .op   = OP,                     \
23145 +}
23146 +
23147 +
23148 +#define DIR(NAME, MODE, OTYPE)                         \
23149 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
23150 +               &proc_ ## OTYPE ## _inode_operations,   \
23151 +               &proc_ ## OTYPE ## _file_operations, { } )
23152 +
23153 +#define INF(NAME, MODE, OTYPE)                         \
23154 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23155 +               &proc_vs_info_file_operations,          \
23156 +               { .proc_vs_read = &proc_##OTYPE } )
23157 +
23158 +#define VINF(NAME, MODE, OTYPE)                                \
23159 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23160 +               &proc_vx_info_file_operations,          \
23161 +               { .proc_vxi_read = &proc_##OTYPE } )
23162 +
23163 +#define NINF(NAME, MODE, OTYPE)                                \
23164 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
23165 +               &proc_nx_info_file_operations,          \
23166 +               { .proc_nxi_read = &proc_##OTYPE } )
23167 +
23168 +
23169 +static struct file_operations proc_vs_info_file_operations = {
23170 +       .read =         proc_vs_info_read,
23171 +};
23172 +
23173 +static struct file_operations proc_vx_info_file_operations = {
23174 +       .read =         proc_vx_info_read,
23175 +};
23176 +
23177 +static struct dentry_operations proc_xid_dentry_operations = {
23178 +       .d_revalidate = proc_xid_revalidate,
23179 +};
23180 +
23181 +static struct vs_entry vx_base_stuff[] = {
23182 +       VINF("info",    S_IRUGO, vxi_info),
23183 +       VINF("status",  S_IRUGO, vxi_status),
23184 +       VINF("limit",   S_IRUGO, vxi_limit),
23185 +       VINF("sched",   S_IRUGO, vxi_sched),
23186 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
23187 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
23188 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
23189 +       VINF("cacct",   S_IRUGO, vxi_cacct),
23190 +       {}
23191 +};
23192 +
23193 +
23194 +
23195 +
23196 +static struct dentry *proc_xid_instantiate(struct inode *dir,
23197 +       struct dentry *dentry, int id, void *ptr)
23198 +{
23199 +       dentry->d_op = &proc_xid_dentry_operations;
23200 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23201 +}
23202 +
23203 +static struct dentry *proc_xid_lookup(struct inode *dir,
23204 +       struct dentry *dentry, struct nameidata *nd)
23205 +{
23206 +       struct vs_entry *p = vx_base_stuff;
23207 +       struct dentry *error = ERR_PTR(-ENOENT);
23208 +
23209 +       for (; p->name; p++) {
23210 +               if (p->len != dentry->d_name.len)
23211 +                       continue;
23212 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23213 +                       break;
23214 +       }
23215 +       if (!p->name)
23216 +               goto out;
23217 +
23218 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23219 +out:
23220 +       return error;
23221 +}
23222 +
23223 +static int proc_xid_readdir(struct file *filp,
23224 +       void *dirent, filldir_t filldir)
23225 +{
23226 +       struct dentry *dentry = filp->f_dentry;
23227 +       struct inode *inode = dentry->d_inode;
23228 +       struct vs_entry *p = vx_base_stuff;
23229 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
23230 +       int pos, index;
23231 +       u64 ino;
23232 +
23233 +       pos = filp->f_pos;
23234 +       switch (pos) {
23235 +       case 0:
23236 +               ino = inode->i_ino;
23237 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23238 +                       goto out;
23239 +               pos++;
23240 +               /* fall through */
23241 +       case 1:
23242 +               ino = parent_ino(dentry);
23243 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23244 +                       goto out;
23245 +               pos++;
23246 +               /* fall through */
23247 +       default:
23248 +               index = pos - 2;
23249 +               if (index >= size)
23250 +                       goto out;
23251 +               for (p += index; p->name; p++) {
23252 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23253 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23254 +                               goto out;
23255 +                       pos++;
23256 +               }
23257 +       }
23258 +out:
23259 +       filp->f_pos = pos;
23260 +       return 1;
23261 +}
23262 +
23263 +
23264 +
23265 +static struct file_operations proc_nx_info_file_operations = {
23266 +       .read =         proc_nx_info_read,
23267 +};
23268 +
23269 +static struct dentry_operations proc_nid_dentry_operations = {
23270 +       .d_revalidate = proc_nid_revalidate,
23271 +};
23272 +
23273 +static struct vs_entry nx_base_stuff[] = {
23274 +       NINF("info",    S_IRUGO, nxi_info),
23275 +       NINF("status",  S_IRUGO, nxi_status),
23276 +       {}
23277 +};
23278 +
23279 +
23280 +static struct dentry *proc_nid_instantiate(struct inode *dir,
23281 +       struct dentry *dentry, int id, void *ptr)
23282 +{
23283 +       dentry->d_op = &proc_nid_dentry_operations;
23284 +       return vs_proc_instantiate(dir, dentry, id, ptr);
23285 +}
23286 +
23287 +static struct dentry *proc_nid_lookup(struct inode *dir,
23288 +       struct dentry *dentry, struct nameidata *nd)
23289 +{
23290 +       struct vs_entry *p = nx_base_stuff;
23291 +       struct dentry *error = ERR_PTR(-ENOENT);
23292 +
23293 +       for (; p->name; p++) {
23294 +               if (p->len != dentry->d_name.len)
23295 +                       continue;
23296 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23297 +                       break;
23298 +       }
23299 +       if (!p->name)
23300 +               goto out;
23301 +
23302 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
23303 +out:
23304 +       return error;
23305 +}
23306 +
23307 +static int proc_nid_readdir(struct file *filp,
23308 +       void *dirent, filldir_t filldir)
23309 +{
23310 +       struct dentry *dentry = filp->f_dentry;
23311 +       struct inode *inode = dentry->d_inode;
23312 +       struct vs_entry *p = nx_base_stuff;
23313 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
23314 +       int pos, index;
23315 +       u64 ino;
23316 +
23317 +       pos = filp->f_pos;
23318 +       switch (pos) {
23319 +       case 0:
23320 +               ino = inode->i_ino;
23321 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23322 +                       goto out;
23323 +               pos++;
23324 +               /* fall through */
23325 +       case 1:
23326 +               ino = parent_ino(dentry);
23327 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23328 +                       goto out;
23329 +               pos++;
23330 +               /* fall through */
23331 +       default:
23332 +               index = pos - 2;
23333 +               if (index >= size)
23334 +                       goto out;
23335 +               for (p += index; p->name; p++) {
23336 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23337 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
23338 +                               goto out;
23339 +                       pos++;
23340 +               }
23341 +       }
23342 +out:
23343 +       filp->f_pos = pos;
23344 +       return 1;
23345 +}
23346 +
23347 +
23348 +#define MAX_MULBY10    ((~0U - 9) / 10)
23349 +
23350 +static inline int atovid(const char *str, int len)
23351 +{
23352 +       int vid, c;
23353 +
23354 +       vid = 0;
23355 +       while (len-- > 0) {
23356 +               c = *str - '0';
23357 +               str++;
23358 +               if (c > 9)
23359 +                       return -1;
23360 +               if (vid >= MAX_MULBY10)
23361 +                       return -1;
23362 +               vid *= 10;
23363 +               vid += c;
23364 +               if (!vid)
23365 +                       return -1;
23366 +       }
23367 +       return vid;
23368 +}
23369 +
23370 +/* now the upper level (virtual) */
23371 +
23372 +
23373 +static struct file_operations proc_xid_file_operations = {
23374 +       .read =         generic_read_dir,
23375 +       .readdir =      proc_xid_readdir,
23376 +};
23377 +
23378 +static struct inode_operations proc_xid_inode_operations = {
23379 +       .lookup =       proc_xid_lookup,
23380 +};
23381 +
23382 +static struct vs_entry vx_virtual_stuff[] = {
23383 +       INF("info",     S_IRUGO, virtual_info),
23384 +       INF("status",   S_IRUGO, virtual_status),
23385 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
23386 +};
23387 +
23388 +
23389 +static struct dentry *proc_virtual_lookup(struct inode *dir,
23390 +       struct dentry *dentry, struct nameidata *nd)
23391 +{
23392 +       struct vs_entry *p = vx_virtual_stuff;
23393 +       struct dentry *error = ERR_PTR(-ENOENT);
23394 +       int id = 0;
23395 +
23396 +       for (; p->name; p++) {
23397 +               if (p->len != dentry->d_name.len)
23398 +                       continue;
23399 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23400 +                       break;
23401 +       }
23402 +       if (p->name)
23403 +               goto instantiate;
23404 +
23405 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
23406 +       if ((id < 0) || !xid_is_hashed(id))
23407 +               goto out;
23408 +
23409 +instantiate:
23410 +       error = proc_xid_instantiate(dir, dentry, id, p);
23411 +out:
23412 +       return error;
23413 +}
23414 +
23415 +static struct file_operations proc_nid_file_operations = {
23416 +       .read =         generic_read_dir,
23417 +       .readdir =      proc_nid_readdir,
23418 +};
23419 +
23420 +static struct inode_operations proc_nid_inode_operations = {
23421 +       .lookup =       proc_nid_lookup,
23422 +};
23423 +
23424 +static struct vs_entry nx_virtnet_stuff[] = {
23425 +       INF("info",     S_IRUGO, virtnet_info),
23426 +       INF("status",   S_IRUGO, virtnet_status),
23427 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
23428 +};
23429 +
23430 +
23431 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
23432 +       struct dentry *dentry, struct nameidata *nd)
23433 +{
23434 +       struct vs_entry *p = nx_virtnet_stuff;
23435 +       struct dentry *error = ERR_PTR(-ENOENT);
23436 +       int id = 0;
23437 +
23438 +       for (; p->name; p++) {
23439 +               if (p->len != dentry->d_name.len)
23440 +                       continue;
23441 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
23442 +                       break;
23443 +       }
23444 +       if (p->name)
23445 +               goto instantiate;
23446 +
23447 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
23448 +       if ((id < 0) || !nid_is_hashed(id))
23449 +               goto out;
23450 +
23451 +instantiate:
23452 +       error = proc_nid_instantiate(dir, dentry, id, p);
23453 +out:
23454 +       return error;
23455 +}
23456 +
23457 +
23458 +#define PROC_MAXVIDS 32
23459 +
23460 +int proc_virtual_readdir(struct file *filp,
23461 +       void *dirent, filldir_t filldir)
23462 +{
23463 +       struct dentry *dentry = filp->f_dentry;
23464 +       struct inode *inode = dentry->d_inode;
23465 +       struct vs_entry *p = vx_virtual_stuff;
23466 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
23467 +       int pos, index;
23468 +       unsigned int xid_array[PROC_MAXVIDS];
23469 +       char buf[PROC_NUMBUF];
23470 +       unsigned int nr_xids, i;
23471 +       u64 ino;
23472 +
23473 +       pos = filp->f_pos;
23474 +       switch (pos) {
23475 +       case 0:
23476 +               ino = inode->i_ino;
23477 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23478 +                       goto out;
23479 +               pos++;
23480 +               /* fall through */
23481 +       case 1:
23482 +               ino = parent_ino(dentry);
23483 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23484 +                       goto out;
23485 +               pos++;
23486 +               /* fall through */
23487 +       default:
23488 +               index = pos - 2;
23489 +               if (index >= size)
23490 +                       goto entries;
23491 +               for (p += index; p->name; p++) {
23492 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23493 +                               vs_proc_instantiate, 0, p))
23494 +                               goto out;
23495 +                       pos++;
23496 +               }
23497 +       entries:
23498 +               index = pos - size;
23499 +               p = &vx_virtual_stuff[size - 1];
23500 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
23501 +               for (i = 0; i < nr_xids; i++) {
23502 +                       int n, xid = xid_array[i];
23503 +                       unsigned int j = PROC_NUMBUF;
23504 +
23505 +                       n = xid;
23506 +                       do
23507 +                               buf[--j] = '0' + (n % 10);
23508 +                       while (n /= 10);
23509 +
23510 +                       if (proc_fill_cache(filp, dirent, filldir,
23511 +                               buf + j, PROC_NUMBUF - j,
23512 +                               vs_proc_instantiate, xid, p))
23513 +                               goto out;
23514 +                       pos++;
23515 +               }
23516 +       }
23517 +out:
23518 +       filp->f_pos = pos;
23519 +       return 0;
23520 +}
23521 +
23522 +static int proc_virtual_getattr(struct vfsmount *mnt,
23523 +       struct dentry *dentry, struct kstat *stat)
23524 +{
23525 +       struct inode *inode = dentry->d_inode;
23526 +
23527 +       generic_fillattr(inode, stat);
23528 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
23529 +       return 0;
23530 +}
23531 +
23532 +static struct file_operations proc_virtual_dir_operations = {
23533 +       .read =         generic_read_dir,
23534 +       .readdir =      proc_virtual_readdir,
23535 +};
23536 +
23537 +static struct inode_operations proc_virtual_dir_inode_operations = {
23538 +       .getattr =      proc_virtual_getattr,
23539 +       .lookup =       proc_virtual_lookup,
23540 +};
23541 +
23542 +
23543 +
23544 +
23545 +
23546 +int proc_virtnet_readdir(struct file *filp,
23547 +       void *dirent, filldir_t filldir)
23548 +{
23549 +       struct dentry *dentry = filp->f_dentry;
23550 +       struct inode *inode = dentry->d_inode;
23551 +       struct vs_entry *p = nx_virtnet_stuff;
23552 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
23553 +       int pos, index;
23554 +       unsigned int nid_array[PROC_MAXVIDS];
23555 +       char buf[PROC_NUMBUF];
23556 +       unsigned int nr_nids, i;
23557 +       u64 ino;
23558 +
23559 +       pos = filp->f_pos;
23560 +       switch (pos) {
23561 +       case 0:
23562 +               ino = inode->i_ino;
23563 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
23564 +                       goto out;
23565 +               pos++;
23566 +               /* fall through */
23567 +       case 1:
23568 +               ino = parent_ino(dentry);
23569 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
23570 +                       goto out;
23571 +               pos++;
23572 +               /* fall through */
23573 +       default:
23574 +               index = pos - 2;
23575 +               if (index >= size)
23576 +                       goto entries;
23577 +               for (p += index; p->name; p++) {
23578 +                       if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
23579 +                               vs_proc_instantiate, 0, p))
23580 +                               goto out;
23581 +                       pos++;
23582 +               }
23583 +       entries:
23584 +               index = pos - size;
23585 +               p = &nx_virtnet_stuff[size - 1];
23586 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
23587 +               for (i = 0; i < nr_nids; i++) {
23588 +                       int n, nid = nid_array[i];
23589 +                       unsigned int j = PROC_NUMBUF;
23590 +
23591 +                       n = nid;
23592 +                       do
23593 +                               buf[--j] = '0' + (n % 10);
23594 +                       while (n /= 10);
23595 +
23596 +                       if (proc_fill_cache(filp, dirent, filldir,
23597 +                               buf + j, PROC_NUMBUF - j,
23598 +                               vs_proc_instantiate, nid, p))
23599 +                               goto out;
23600 +                       pos++;
23601 +               }
23602 +       }
23603 +out:
23604 +       filp->f_pos = pos;
23605 +       return 0;
23606 +}
23607 +
23608 +static int proc_virtnet_getattr(struct vfsmount *mnt,
23609 +       struct dentry *dentry, struct kstat *stat)
23610 +{
23611 +       struct inode *inode = dentry->d_inode;
23612 +
23613 +       generic_fillattr(inode, stat);
23614 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
23615 +       return 0;
23616 +}
23617 +
23618 +static struct file_operations proc_virtnet_dir_operations = {
23619 +       .read =         generic_read_dir,
23620 +       .readdir =      proc_virtnet_readdir,
23621 +};
23622 +
23623 +static struct inode_operations proc_virtnet_dir_inode_operations = {
23624 +       .getattr =      proc_virtnet_getattr,
23625 +       .lookup =       proc_virtnet_lookup,
23626 +};
23627 +
23628 +
23629 +
23630 +void proc_vx_init(void)
23631 +{
23632 +       struct proc_dir_entry *ent;
23633 +
23634 +       ent = proc_mkdir("virtual", 0);
23635 +       if (ent) {
23636 +               ent->proc_fops = &proc_virtual_dir_operations;
23637 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
23638 +       }
23639 +       proc_virtual = ent;
23640 +
23641 +       ent = proc_mkdir("virtnet", 0);
23642 +       if (ent) {
23643 +               ent->proc_fops = &proc_virtnet_dir_operations;
23644 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
23645 +       }
23646 +       proc_virtnet = ent;
23647 +}
23648 +
23649 +
23650 +
23651 +
23652 +/* per pid info */
23653 +
23654 +
23655 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
23656 +{
23657 +       struct vx_info *vxi;
23658 +       char *orig = buffer;
23659 +
23660 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
23661 +
23662 +       vxi = task_get_vx_info(p);
23663 +       if (!vxi)
23664 +               goto out;
23665 +
23666 +       buffer += sprintf(buffer, "BCaps:\t");
23667 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
23668 +       buffer += sprintf(buffer, "\n");
23669 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
23670 +               (unsigned long long)vxi->vx_ccaps);
23671 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
23672 +               (unsigned long long)vxi->vx_flags);
23673 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
23674 +
23675 +       put_vx_info(vxi);
23676 +out:
23677 +       return buffer - orig;
23678 +}
23679 +
23680 +
23681 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
23682 +{
23683 +       struct nx_info *nxi;
23684 +       struct nx_addr_v4 *v4a;
23685 +#ifdef CONFIG_IPV6
23686 +       struct nx_addr_v6 *v6a;
23687 +#endif
23688 +       char *orig = buffer;
23689 +       int i;
23690 +
23691 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
23692 +
23693 +       nxi = task_get_nx_info(p);
23694 +       if (!nxi)
23695 +               goto out;
23696 +
23697 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
23698 +               (unsigned long long)nxi->nx_ncaps);
23699 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
23700 +               (unsigned long long)nxi->nx_flags);
23701 +
23702 +       buffer += sprintf(buffer,
23703 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
23704 +               NIPQUAD(nxi->v4_bcast.s_addr));
23705 +       buffer += sprintf (buffer,
23706 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
23707 +               NIPQUAD(nxi->v4_lback.s_addr));
23708 +       if (!NX_IPV4(nxi))
23709 +               goto skip_v4;
23710 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
23711 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
23712 +                       i, NXAV4(v4a));
23713 +skip_v4:
23714 +#ifdef CONFIG_IPV6
23715 +       if (!NX_IPV6(nxi))
23716 +               goto skip_v6;
23717 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
23718 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
23719 +                       i, NXAV6(v6a));
23720 +skip_v6:
23721 +#endif
23722 +       put_nx_info(nxi);
23723 +out:
23724 +       return buffer - orig;
23725 +}
23726 +
23727 diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/sched.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/sched.c
23728 --- linux-2.6.29.4/kernel/vserver/sched.c       1970-01-01 01:00:00.000000000 +0100
23729 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/sched.c 2009-02-22 22:54:26.000000000 +0100
23730 @@ -0,0 +1,414 @@
23731 +/*
23732 + *  linux/kernel/vserver/sched.c
23733 + *
23734 + *  Virtual Server: Scheduler Support
23735 + *
23736 + *  Copyright (C) 2004-2007  Herbert Pötzl
23737 + *
23738 + *  V0.01  adapted Sam Vilains version to 2.6.3
23739 + *  V0.02  removed legacy interface
23740 + *  V0.03  changed vcmds to vxi arg
23741 + *  V0.04  removed older and legacy interfaces
23742 + *
23743 + */
23744 +
23745 +#include <linux/vs_context.h>
23746 +#include <linux/vs_sched.h>
23747 +#include <linux/vserver/sched_cmd.h>
23748 +
23749 +#include <asm/uaccess.h>
23750 +
23751 +
23752 +#define vxd_check_range(val, min, max) do {            \
23753 +       vxlprintk((val < min) || (val > max),           \
23754 +               "check_range(%ld,%ld,%ld)",             \
23755 +               (long)val, (long)min, (long)max,        \
23756 +               __FILE__, __LINE__);                    \
23757 +       } while (0)
23758 +
23759 +
23760 +void vx_update_sched_param(struct _vx_sched *sched,
23761 +       struct _vx_sched_pc *sched_pc)
23762 +{
23763 +       unsigned int set_mask = sched->update_mask;
23764 +
23765 +       if (set_mask & VXSM_FILL_RATE)
23766 +               sched_pc->fill_rate[0] = sched->fill_rate[0];
23767 +       if (set_mask & VXSM_INTERVAL)
23768 +               sched_pc->interval[0] = sched->interval[0];
23769 +       if (set_mask & VXSM_FILL_RATE2)
23770 +               sched_pc->fill_rate[1] = sched->fill_rate[1];
23771 +       if (set_mask & VXSM_INTERVAL2)
23772 +               sched_pc->interval[1] = sched->interval[1];
23773 +       if (set_mask & VXSM_TOKENS)
23774 +               sched_pc->tokens = sched->tokens;
23775 +       if (set_mask & VXSM_TOKENS_MIN)
23776 +               sched_pc->tokens_min = sched->tokens_min;
23777 +       if (set_mask & VXSM_TOKENS_MAX)
23778 +               sched_pc->tokens_max = sched->tokens_max;
23779 +       if (set_mask & VXSM_PRIO_BIAS)
23780 +               sched_pc->prio_bias = sched->prio_bias;
23781 +
23782 +       if (set_mask & VXSM_IDLE_TIME)
23783 +               sched_pc->flags |= VXSF_IDLE_TIME;
23784 +       else
23785 +               sched_pc->flags &= ~VXSF_IDLE_TIME;
23786 +
23787 +       /* reset time */
23788 +       sched_pc->norm_time = jiffies;
23789 +}
23790 +
23791 +
23792 +/*
23793 + * recalculate the context's scheduling tokens
23794 + *
23795 + * ret > 0 : number of tokens available
23796 + * ret < 0 : on hold, check delta_min[]
23797 + *          -1 only jiffies
23798 + *          -2 also idle time
23799 + *
23800 + */
23801 +int vx_tokens_recalc(struct _vx_sched_pc *sched_pc,
23802 +       unsigned long *norm_time, unsigned long *idle_time, int delta_min[2])
23803 +{
23804 +       long delta;
23805 +       long tokens = 0;
23806 +       int flags = sched_pc->flags;
23807 +
23808 +       /* how much time did pass? */
23809 +       delta = *norm_time - sched_pc->norm_time;
23810 +       // printk("@ %ld, %ld, %ld\n", *norm_time, sched_pc->norm_time, jiffies);
23811 +       vxd_check_range(delta, 0, INT_MAX);
23812 +
23813 +       if (delta >= sched_pc->interval[0]) {
23814 +               long tokens, integral;
23815 +
23816 +               /* calc integral token part */
23817 +               tokens = delta / sched_pc->interval[0];
23818 +               integral = tokens * sched_pc->interval[0];
23819 +               tokens *= sched_pc->fill_rate[0];
23820 +#ifdef CONFIG_VSERVER_HARDCPU
23821 +               delta_min[0] = delta - integral;
23822 +               vxd_check_range(delta_min[0], 0, sched_pc->interval[0]);
23823 +#endif
23824 +               /* advance time */
23825 +               sched_pc->norm_time += delta;
23826 +
23827 +               /* add tokens */
23828 +               sched_pc->tokens += tokens;
23829 +               sched_pc->token_time += tokens;
23830 +       } else
23831 +               delta_min[0] = delta;
23832 +
23833 +#ifdef CONFIG_VSERVER_IDLETIME
23834 +       if (!(flags & VXSF_IDLE_TIME))
23835 +               goto skip_idle;
23836 +
23837 +       /* how much was the idle skip? */
23838 +       delta = *idle_time - sched_pc->idle_time;
23839 +       vxd_check_range(delta, 0, INT_MAX);
23840 +
23841 +       if (delta >= sched_pc->interval[1]) {
23842 +               long tokens, integral;
23843 +
23844 +               /* calc fair share token part */
23845 +               tokens = delta / sched_pc->interval[1];
23846 +               integral = tokens * sched_pc->interval[1];
23847 +               tokens *= sched_pc->fill_rate[1];
23848 +               delta_min[1] = delta - integral;
23849 +               vxd_check_range(delta_min[1], 0, sched_pc->interval[1]);
23850 +
23851 +               /* advance idle time */
23852 +               sched_pc->idle_time += integral;
23853 +
23854 +               /* add tokens */
23855 +               sched_pc->tokens += tokens;
23856 +               sched_pc->token_time += tokens;
23857 +       } else
23858 +               delta_min[1] = delta;
23859 +skip_idle:
23860 +#endif
23861 +
23862 +       /* clip at maximum */
23863 +       if (sched_pc->tokens > sched_pc->tokens_max)
23864 +               sched_pc->tokens = sched_pc->tokens_max;
23865 +       tokens = sched_pc->tokens;
23866 +
23867 +       if ((flags & VXSF_ONHOLD)) {
23868 +               /* can we unhold? */
23869 +               if (tokens >= sched_pc->tokens_min) {
23870 +                       flags &= ~VXSF_ONHOLD;
23871 +                       sched_pc->hold_ticks +=
23872 +                               *norm_time - sched_pc->onhold;
23873 +               } else
23874 +                       goto on_hold;
23875 +       } else {
23876 +               /* put on hold? */
23877 +               if (tokens <= 0) {
23878 +                       flags |= VXSF_ONHOLD;
23879 +                       sched_pc->onhold = *norm_time;
23880 +                       goto on_hold;
23881 +               }
23882 +       }
23883 +       sched_pc->flags = flags;
23884 +       return tokens;
23885 +
23886 +on_hold:
23887 +       tokens = sched_pc->tokens_min - tokens;
23888 +       sched_pc->flags = flags;
23889 +       // BUG_ON(tokens < 0); probably doesn't hold anymore
23890 +
23891 +#ifdef CONFIG_VSERVER_HARDCPU
23892 +       /* next interval? */
23893 +       if (!sched_pc->fill_rate[0])
23894 +               delta_min[0] = HZ;
23895 +       else if (tokens > sched_pc->fill_rate[0])
23896 +               delta_min[0] += sched_pc->interval[0] *
23897 +                       tokens / sched_pc->fill_rate[0];
23898 +       else
23899 +               delta_min[0] = sched_pc->interval[0] - delta_min[0];
23900 +       vxd_check_range(delta_min[0], 0, INT_MAX);
23901 +
23902 +#ifdef CONFIG_VSERVER_IDLETIME
23903 +       if (!(flags & VXSF_IDLE_TIME))
23904 +               return -1;
23905 +
23906 +       /* next interval? */
23907 +       if (!sched_pc->fill_rate[1])
23908 +               delta_min[1] = HZ;
23909 +       else if (tokens > sched_pc->fill_rate[1])
23910 +               delta_min[1] += sched_pc->interval[1] *
23911 +                       tokens / sched_pc->fill_rate[1];
23912 +       else
23913 +               delta_min[1] = sched_pc->interval[1] - delta_min[1];
23914 +       vxd_check_range(delta_min[1], 0, INT_MAX);
23915 +
23916 +       return -2;
23917 +#else
23918 +       return -1;
23919 +#endif /* CONFIG_VSERVER_IDLETIME */
23920 +#else
23921 +       return 0;
23922 +#endif /* CONFIG_VSERVER_HARDCPU */
23923 +}
23924 +
23925 +static inline unsigned long msec_to_ticks(unsigned long msec)
23926 +{
23927 +       return msecs_to_jiffies(msec);
23928 +}
23929 +
23930 +static inline unsigned long ticks_to_msec(unsigned long ticks)
23931 +{
23932 +       return jiffies_to_msecs(ticks);
23933 +}
23934 +
23935 +static inline unsigned long ticks_to_usec(unsigned long ticks)
23936 +{
23937 +       return jiffies_to_usecs(ticks);
23938 +}
23939 +
23940 +
23941 +static int do_set_sched(struct vx_info *vxi, struct vcmd_sched_v5 *data)
23942 +{
23943 +       unsigned int set_mask = data->mask;
23944 +       unsigned int update_mask;
23945 +       int i, cpu;
23946 +
23947 +       /* Sanity check data values */
23948 +       if (data->tokens_max <= 0)
23949 +               data->tokens_max = HZ;
23950 +       if (data->tokens_min < 0)
23951 +               data->tokens_min = HZ / 3;
23952 +       if (data->tokens_min >= data->tokens_max)
23953 +               data->tokens_min = data->tokens_max;
23954 +
23955 +       if (data->prio_bias > MAX_PRIO_BIAS)
23956 +               data->prio_bias = MAX_PRIO_BIAS;
23957 +       if (data->prio_bias < MIN_PRIO_BIAS)
23958 +               data->prio_bias = MIN_PRIO_BIAS;
23959 +
23960 +       spin_lock(&vxi->sched.tokens_lock);
23961 +
23962 +       /* sync up on delayed updates */
23963 +       for_each_cpu_mask(cpu, vxi->sched.update)
23964 +               vx_update_sched_param(&vxi->sched,
23965 +                       &vx_per_cpu(vxi, sched_pc, cpu));
23966 +
23967 +       if (set_mask & VXSM_FILL_RATE)
23968 +               vxi->sched.fill_rate[0] = data->fill_rate[0];
23969 +       if (set_mask & VXSM_FILL_RATE2)
23970 +               vxi->sched.fill_rate[1] = data->fill_rate[1];
23971 +       if (set_mask & VXSM_INTERVAL)
23972 +               vxi->sched.interval[0] = (set_mask & VXSM_MSEC) ?
23973 +                       msec_to_ticks(data->interval[0]) : data->interval[0];
23974 +       if (set_mask & VXSM_INTERVAL2)
23975 +               vxi->sched.interval[1] = (set_mask & VXSM_MSEC) ?
23976 +                       msec_to_ticks(data->interval[1]) : data->interval[1];
23977 +       if (set_mask & VXSM_TOKENS)
23978 +               vxi->sched.tokens = data->tokens;
23979 +       if (set_mask & VXSM_TOKENS_MIN)
23980 +               vxi->sched.tokens_min = data->tokens_min;
23981 +       if (set_mask & VXSM_TOKENS_MAX)
23982 +               vxi->sched.tokens_max = data->tokens_max;
23983 +       if (set_mask & VXSM_PRIO_BIAS)
23984 +               vxi->sched.prio_bias = data->prio_bias;
23985 +
23986 +       /* Sanity check rate/interval */
23987 +       for (i = 0; i < 2; i++) {
23988 +               if (data->fill_rate[i] < 0)
23989 +                       data->fill_rate[i] = 0;
23990 +               if (data->interval[i] <= 0)
23991 +                       data->interval[i] = HZ;
23992 +       }
23993 +
23994 +       update_mask = vxi->sched.update_mask & VXSM_SET_MASK;
23995 +       update_mask |= (set_mask & (VXSM_SET_MASK | VXSM_IDLE_TIME));
23996 +       vxi->sched.update_mask = update_mask;
23997 +
23998 +#ifdef CONFIG_SMP
23999 +       rmb();
24000 +       if (set_mask & VXSM_CPU_ID) {
24001 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
24002 +               cpus_and(vxi->sched.update, cpu_online_map,
24003 +                       vxi->sched.update);
24004 +       } else
24005 +               vxi->sched.update = cpu_online_map;
24006 +
24007 +       /* forced reload? */
24008 +       if (set_mask & VXSM_FORCE) {
24009 +               for_each_cpu_mask(cpu, vxi->sched.update)
24010 +                       vx_update_sched_param(&vxi->sched,
24011 +                               &vx_per_cpu(vxi, sched_pc, cpu));
24012 +               vxi->sched.update = CPU_MASK_NONE;
24013 +       }
24014 +#else
24015 +       /* on UP we update immediately */
24016 +       vx_update_sched_param(&vxi->sched,
24017 +               &vx_per_cpu(vxi, sched_pc, 0));
24018 +#endif
24019 +
24020 +       spin_unlock(&vxi->sched.tokens_lock);
24021 +       return 0;
24022 +}
24023 +
24024 +
24025 +#define COPY_IDS(C) C(cpu_id); C(bucket_id)
24026 +#define COPY_PRI(C) C(prio_bias)
24027 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
24028 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);   \
24029 +                   C(fill_rate[1]); C(interval[1]);
24030 +
24031 +#define COPY_VALUE(name) vc_data.name = data->name
24032 +
24033 +static int do_set_sched_v4(struct vx_info *vxi, struct vcmd_set_sched_v4 *data)
24034 +{
24035 +       struct vcmd_sched_v5 vc_data;
24036 +
24037 +       vc_data.mask = data->set_mask;
24038 +       COPY_IDS(COPY_VALUE);
24039 +       COPY_PRI(COPY_VALUE);
24040 +       COPY_TOK(COPY_VALUE);
24041 +       vc_data.fill_rate[0] = vc_data.fill_rate[1] = data->fill_rate;
24042 +       vc_data.interval[0] = vc_data.interval[1] = data->interval;
24043 +       return do_set_sched(vxi, &vc_data);
24044 +}
24045 +
24046 +int vc_set_sched_v4(struct vx_info *vxi, void __user *data)
24047 +{
24048 +       struct vcmd_set_sched_v4 vc_data;
24049 +
24050 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24051 +               return -EFAULT;
24052 +
24053 +       return do_set_sched_v4(vxi, &vc_data);
24054 +}
24055 +
24056 +       /* latest interface is v5 */
24057 +
24058 +int vc_set_sched(struct vx_info *vxi, void __user *data)
24059 +{
24060 +       struct vcmd_sched_v5 vc_data;
24061 +
24062 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24063 +               return -EFAULT;
24064 +
24065 +       return do_set_sched(vxi, &vc_data);
24066 +}
24067 +
24068 +
24069 +#define COPY_PRI(C) C(prio_bias)
24070 +#define COPY_TOK(C) C(tokens); C(tokens_min); C(tokens_max)
24071 +#define COPY_FRI(C) C(fill_rate[0]); C(interval[0]);    \
24072 +                   C(fill_rate[1]); C(interval[1]);
24073 +
24074 +#define COPY_VALUE(name) vc_data.name = data->name
24075 +
24076 +
24077 +int vc_get_sched(struct vx_info *vxi, void __user *data)
24078 +{
24079 +       struct vcmd_sched_v5 vc_data;
24080 +
24081 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24082 +               return -EFAULT;
24083 +
24084 +       if (vc_data.mask & VXSM_CPU_ID) {
24085 +               int cpu = vc_data.cpu_id;
24086 +               struct _vx_sched_pc *data;
24087 +
24088 +               if (!cpu_possible(cpu))
24089 +                       return -EINVAL;
24090 +
24091 +               data = &vx_per_cpu(vxi, sched_pc, cpu);
24092 +               COPY_TOK(COPY_VALUE);
24093 +               COPY_PRI(COPY_VALUE);
24094 +               COPY_FRI(COPY_VALUE);
24095 +
24096 +               if (data->flags & VXSF_IDLE_TIME)
24097 +                       vc_data.mask |= VXSM_IDLE_TIME;
24098 +       } else {
24099 +               struct _vx_sched *data = &vxi->sched;
24100 +
24101 +               COPY_TOK(COPY_VALUE);
24102 +               COPY_PRI(COPY_VALUE);
24103 +               COPY_FRI(COPY_VALUE);
24104 +       }
24105 +
24106 +       if (vc_data.mask & VXSM_MSEC) {
24107 +               vc_data.interval[0] = ticks_to_msec(vc_data.interval[0]);
24108 +               vc_data.interval[1] = ticks_to_msec(vc_data.interval[1]);
24109 +       }
24110 +
24111 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24112 +               return -EFAULT;
24113 +       return 0;
24114 +}
24115 +
24116 +
24117 +int vc_sched_info(struct vx_info *vxi, void __user *data)
24118 +{
24119 +       struct vcmd_sched_info vc_data;
24120 +       int cpu;
24121 +
24122 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24123 +               return -EFAULT;
24124 +
24125 +       cpu = vc_data.cpu_id;
24126 +       if (!cpu_possible(cpu))
24127 +               return -EINVAL;
24128 +
24129 +       if (vxi) {
24130 +               struct _vx_sched_pc *sched_pc =
24131 +                       &vx_per_cpu(vxi, sched_pc, cpu);
24132 +
24133 +               vc_data.user_msec = ticks_to_msec(sched_pc->user_ticks);
24134 +               vc_data.sys_msec = ticks_to_msec(sched_pc->sys_ticks);
24135 +               vc_data.hold_msec = ticks_to_msec(sched_pc->hold_ticks);
24136 +               vc_data.vavavoom = sched_pc->vavavoom;
24137 +       }
24138 +       vc_data.token_usec = ticks_to_usec(1);
24139 +
24140 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24141 +               return -EFAULT;
24142 +       return 0;
24143 +}
24144 +
24145 diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/sched_init.h linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/sched_init.h
24146 --- linux-2.6.29.4/kernel/vserver/sched_init.h  1970-01-01 01:00:00.000000000 +0100
24147 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/sched_init.h    2009-02-22 22:54:26.000000000 +0100
24148 @@ -0,0 +1,50 @@
24149 +
24150 +static inline void vx_info_init_sched(struct _vx_sched *sched)
24151 +{
24152 +       static struct lock_class_key tokens_lock_key;
24153 +
24154 +       /* scheduling; hard code starting values as constants */
24155 +       sched->fill_rate[0]     = 1;
24156 +       sched->interval[0]      = 4;
24157 +       sched->fill_rate[1]     = 1;
24158 +       sched->interval[1]      = 8;
24159 +       sched->tokens           = HZ >> 2;
24160 +       sched->tokens_min       = HZ >> 4;
24161 +       sched->tokens_max       = HZ >> 1;
24162 +       sched->tokens_lock      = SPIN_LOCK_UNLOCKED;
24163 +       sched->prio_bias        = 0;
24164 +
24165 +       lockdep_set_class(&sched->tokens_lock, &tokens_lock_key);
24166 +}
24167 +
24168 +static inline
24169 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24170 +{
24171 +       sched_pc->fill_rate[0]  = 1;
24172 +       sched_pc->interval[0]   = 4;
24173 +       sched_pc->fill_rate[1]  = 1;
24174 +       sched_pc->interval[1]   = 8;
24175 +       sched_pc->tokens        = HZ >> 2;
24176 +       sched_pc->tokens_min    = HZ >> 4;
24177 +       sched_pc->tokens_max    = HZ >> 1;
24178 +       sched_pc->prio_bias     = 0;
24179 +       sched_pc->vavavoom      = 0;
24180 +       sched_pc->token_time    = 0;
24181 +       sched_pc->idle_time     = 0;
24182 +       sched_pc->norm_time     = jiffies;
24183 +
24184 +       sched_pc->user_ticks = 0;
24185 +       sched_pc->sys_ticks = 0;
24186 +       sched_pc->hold_ticks = 0;
24187 +}
24188 +
24189 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
24190 +{
24191 +       return;
24192 +}
24193 +
24194 +static inline
24195 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
24196 +{
24197 +       return;
24198 +}
24199 diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/sched_proc.h linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/sched_proc.h
24200 --- linux-2.6.29.4/kernel/vserver/sched_proc.h  1970-01-01 01:00:00.000000000 +0100
24201 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/sched_proc.h    2009-02-22 22:54:26.000000000 +0100
24202 @@ -0,0 +1,57 @@
24203 +#ifndef _VX_SCHED_PROC_H
24204 +#define _VX_SCHED_PROC_H
24205 +
24206 +
24207 +static inline
24208 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
24209 +{
24210 +       int length = 0;
24211 +
24212 +       length += sprintf(buffer,
24213 +               "FillRate:\t%8d,%d\n"
24214 +               "Interval:\t%8d,%d\n"
24215 +               "TokensMin:\t%8d\n"
24216 +               "TokensMax:\t%8d\n"
24217 +               "PrioBias:\t%8d\n",
24218 +               sched->fill_rate[0],
24219 +               sched->fill_rate[1],
24220 +               sched->interval[0],
24221 +               sched->interval[1],
24222 +               sched->tokens_min,
24223 +               sched->tokens_max,
24224 +               sched->prio_bias);
24225 +       return length;
24226 +}
24227 +
24228 +static inline
24229 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
24230 +       char *buffer, int cpu)
24231 +{
24232 +       int length = 0;
24233 +
24234 +       length += sprintf(buffer + length,
24235 +               "cpu %d: %lld %lld %lld %ld %ld", cpu,
24236 +               (unsigned long long)sched_pc->user_ticks,
24237 +               (unsigned long long)sched_pc->sys_ticks,
24238 +               (unsigned long long)sched_pc->hold_ticks,
24239 +               sched_pc->token_time,
24240 +               sched_pc->idle_time);
24241 +       length += sprintf(buffer + length,
24242 +               " %c%c %d %d %d %d/%d %d/%d",
24243 +               (sched_pc->flags & VXSF_ONHOLD) ? 'H' : 'R',
24244 +               (sched_pc->flags & VXSF_IDLE_TIME) ? 'I' : '-',
24245 +               sched_pc->tokens,
24246 +               sched_pc->tokens_min,
24247 +               sched_pc->tokens_max,
24248 +               sched_pc->fill_rate[0],
24249 +               sched_pc->interval[0],
24250 +               sched_pc->fill_rate[1],
24251 +               sched_pc->interval[1]);
24252 +       length += sprintf(buffer + length,
24253 +               " %d %d\n",
24254 +               sched_pc->prio_bias,
24255 +               sched_pc->vavavoom);
24256 +       return length;
24257 +}
24258 +
24259 +#endif /* _VX_SCHED_PROC_H */
24260 diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/signal.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/signal.c
24261 --- linux-2.6.29.4/kernel/vserver/signal.c      1970-01-01 01:00:00.000000000 +0100
24262 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/signal.c        2009-02-22 22:54:26.000000000 +0100
24263 @@ -0,0 +1,132 @@
24264 +/*
24265 + *  linux/kernel/vserver/signal.c
24266 + *
24267 + *  Virtual Server: Signal Support
24268 + *
24269 + *  Copyright (C) 2003-2007  Herbert Pötzl
24270 + *
24271 + *  V0.01  broken out from vcontext V0.05
24272 + *  V0.02  changed vcmds to vxi arg
24273 + *  V0.03  adjusted siginfo for kill
24274 + *
24275 + */
24276 +
24277 +#include <asm/uaccess.h>
24278 +
24279 +#include <linux/vs_context.h>
24280 +#include <linux/vs_pid.h>
24281 +#include <linux/vserver/signal_cmd.h>
24282 +
24283 +
24284 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
24285 +{
24286 +       int retval, count = 0;
24287 +       struct task_struct *p;
24288 +       struct siginfo *sip = SEND_SIG_PRIV;
24289 +
24290 +       retval = -ESRCH;
24291 +       vxdprintk(VXD_CBIT(misc, 4),
24292 +               "vx_info_kill(%p[#%d],%d,%d)*",
24293 +               vxi, vxi->vx_id, pid, sig);
24294 +       read_lock(&tasklist_lock);
24295 +       switch (pid) {
24296 +       case  0:
24297 +       case -1:
24298 +               for_each_process(p) {
24299 +                       int err = 0;
24300 +
24301 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
24302 +                               (pid && vxi->vx_initpid == p->pid))
24303 +                               continue;
24304 +
24305 +                       err = group_send_sig_info(sig, sip, p);
24306 +                       ++count;
24307 +                       if (err != -EPERM)
24308 +                               retval = err;
24309 +               }
24310 +               break;
24311 +
24312 +       case 1:
24313 +               if (vxi->vx_initpid) {
24314 +                       pid = vxi->vx_initpid;
24315 +                       /* for now, only SIGINT to private init ... */
24316 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24317 +                               /* ... as long as there are tasks left */
24318 +                               (atomic_read(&vxi->vx_tasks) > 1))
24319 +                               sig = SIGINT;
24320 +               }
24321 +               /* fallthrough */
24322 +       default:
24323 +               p = find_task_by_real_pid(pid);
24324 +               if (p) {
24325 +                       if (vx_task_xid(p) == vxi->vx_id)
24326 +                               retval = group_send_sig_info(sig, sip, p);
24327 +               }
24328 +               break;
24329 +       }
24330 +       read_unlock(&tasklist_lock);
24331 +       vxdprintk(VXD_CBIT(misc, 4),
24332 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
24333 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
24334 +       return retval;
24335 +}
24336 +
24337 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
24338 +{
24339 +       struct vcmd_ctx_kill_v0 vc_data;
24340 +
24341 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
24342 +               return -EFAULT;
24343 +
24344 +       /* special check to allow guest shutdown */
24345 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
24346 +               /* forbid killall pid=0 when init is present */
24347 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
24348 +               (vc_data.pid > 1)))
24349 +               return -EACCES;
24350 +
24351 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
24352 +}
24353 +
24354 +
24355 +static int __wait_exit(struct vx_info *vxi)
24356 +{
24357 +       DECLARE_WAITQUEUE(wait, current);
24358 +       int ret = 0;
24359 +
24360 +       add_wait_queue(&vxi->vx_wait, &wait);
24361 +       set_current_state(TASK_INTERRUPTIBLE);
24362 +
24363 +wait:
24364 +       if (vx_info_state(vxi,
24365 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
24366 +               goto out;
24367 +       if (signal_pending(current)) {
24368 +               ret = -ERESTARTSYS;
24369 +               goto out;
24370 +       }
24371 +       schedule();
24372 +       goto wait;
24373 +
24374 +out:
24375 +       set_current_state(TASK_RUNNING);
24376 +       remove_wait_queue(&vxi->vx_wait, &wait);
24377 +       return ret;
24378 +}
24379 +
24380 +
24381 +
24382 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
24383 +{
24384 +       struct vcmd_wait_exit_v0 vc_data;
24385 +       int ret;
24386 +
24387 +       ret = __wait_exit(vxi);
24388 +       vc_data.reboot_cmd = vxi->reboot_cmd;
24389 +       vc_data.exit_code = vxi->exit_code;
24390 +
24391 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
24392 +               ret = -EFAULT;
24393 +       return ret;
24394 +}
24395 +
24396 diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/space.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/space.c
24397 --- linux-2.6.29.4/kernel/vserver/space.c       1970-01-01 01:00:00.000000000 +0100
24398 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/space.c 2009-05-29 18:59:49.000000000 +0200
24399 @@ -0,0 +1,375 @@
24400 +/*
24401 + *  linux/kernel/vserver/space.c
24402 + *
24403 + *  Virtual Server: Context Space Support
24404 + *
24405 + *  Copyright (C) 2003-2007  Herbert Pötzl
24406 + *
24407 + *  V0.01  broken out from context.c 0.07
24408 + *  V0.02  added task locking for namespace
24409 + *  V0.03  broken out vx_enter_namespace
24410 + *  V0.04  added *space support and commands
24411 + *
24412 + */
24413 +
24414 +#include <linux/utsname.h>
24415 +#include <linux/nsproxy.h>
24416 +#include <linux/err.h>
24417 +#include <asm/uaccess.h>
24418 +
24419 +#include <linux/vs_context.h>
24420 +#include <linux/vserver/space.h>
24421 +#include <linux/vserver/space_cmd.h>
24422 +
24423 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
24424 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
24425 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
24426 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
24427 +atomic_t vs_global_ipc_ns      = ATOMIC_INIT(0);
24428 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
24429 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
24430 +
24431 +
24432 +/* namespace functions */
24433 +
24434 +#include <linux/mnt_namespace.h>
24435 +#include <linux/user_namespace.h>
24436 +#include <linux/pid_namespace.h>
24437 +#include <linux/ipc_namespace.h>
24438 +#include <net/net_namespace.h>
24439 +
24440 +
24441 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
24442 +       .mask = CLONE_FS |
24443 +               CLONE_NEWNS |
24444 +               CLONE_NEWUTS |
24445 +               CLONE_NEWIPC |
24446 +               CLONE_NEWUSER |
24447 +               0
24448 +};
24449 +
24450 +static const struct vcmd_space_mask_v1 space_mask = {
24451 +       .mask = CLONE_FS |
24452 +               CLONE_NEWNS |
24453 +               CLONE_NEWUTS |
24454 +               CLONE_NEWIPC |
24455 +               CLONE_NEWUSER |
24456 +#ifdef CONFIG_PID_NS
24457 +               CLONE_NEWPID |
24458 +#endif
24459 +#ifdef CONFIG_NET_NS
24460 +               CLONE_NEWNET |
24461 +#endif
24462 +               0
24463 +};
24464 +
24465 +static const struct vcmd_space_mask_v1 default_space_mask = {
24466 +       .mask = CLONE_FS |
24467 +               CLONE_NEWNS |
24468 +               CLONE_NEWUTS |
24469 +               CLONE_NEWIPC |
24470 +               CLONE_NEWUSER |
24471 +#ifdef CONFIG_PID_NS
24472 +//             CLONE_NEWPID |
24473 +#endif
24474 +               0
24475 +};
24476 +
24477 +/*
24478 + *     build a new nsproxy mix
24479 + *      assumes that both proxies are 'const'
24480 + *     does not touch nsproxy refcounts
24481 + *     will hold a reference on the result.
24482 + */
24483 +
24484 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
24485 +       struct nsproxy *new_nsproxy, unsigned long mask)
24486 +{
24487 +       struct mnt_namespace *old_ns;
24488 +       struct uts_namespace *old_uts;
24489 +       struct ipc_namespace *old_ipc;
24490 +#ifdef CONFIG_PID_NS
24491 +       struct pid_namespace *old_pid;
24492 +#endif
24493 +#ifdef CONFIG_NET_NS
24494 +       struct net *old_net;
24495 +#endif
24496 +       struct nsproxy *nsproxy;
24497 +
24498 +       nsproxy = copy_nsproxy(old_nsproxy);
24499 +       if (!nsproxy)
24500 +               goto out;
24501 +
24502 +       if (mask & CLONE_NEWNS) {
24503 +               old_ns = nsproxy->mnt_ns;
24504 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
24505 +               if (nsproxy->mnt_ns)
24506 +                       get_mnt_ns(nsproxy->mnt_ns);
24507 +       } else
24508 +               old_ns = NULL;
24509 +
24510 +       if (mask & CLONE_NEWUTS) {
24511 +               old_uts = nsproxy->uts_ns;
24512 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
24513 +               if (nsproxy->uts_ns)
24514 +                       get_uts_ns(nsproxy->uts_ns);
24515 +       } else
24516 +               old_uts = NULL;
24517 +
24518 +       if (mask & CLONE_NEWIPC) {
24519 +               old_ipc = nsproxy->ipc_ns;
24520 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
24521 +               if (nsproxy->ipc_ns)
24522 +                       get_ipc_ns(nsproxy->ipc_ns);
24523 +       } else
24524 +               old_ipc = NULL;
24525 +
24526 +#ifdef CONFIG_PID_NS
24527 +       if (mask & CLONE_NEWPID) {
24528 +               old_pid = nsproxy->pid_ns;
24529 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
24530 +               if (nsproxy->pid_ns)
24531 +                       get_pid_ns(nsproxy->pid_ns);
24532 +       } else
24533 +               old_pid = NULL;
24534 +#endif
24535 +#ifdef CONFIG_NET_NS
24536 +       if (mask & CLONE_NEWNET) {
24537 +               old_net = nsproxy->net_ns;
24538 +               nsproxy->net_ns = new_nsproxy->net_ns;
24539 +               if (nsproxy->net_ns)
24540 +                       get_net(nsproxy->net_ns);
24541 +       } else
24542 +               old_net = NULL;
24543 +#endif
24544 +       if (old_ns)
24545 +               put_mnt_ns(old_ns);
24546 +       if (old_uts)
24547 +               put_uts_ns(old_uts);
24548 +       if (old_ipc)
24549 +               put_ipc_ns(old_ipc);
24550 +#ifdef CONFIG_PID_NS
24551 +       if (old_pid)
24552 +               put_pid_ns(old_pid);
24553 +#endif
24554 +#ifdef CONFIG_NET_NS
24555 +       if (old_net)
24556 +               put_net(old_net);
24557 +#endif
24558 +out:
24559 +       return nsproxy;
24560 +}
24561 +
24562 +
24563 +/*
24564 + *     merge two nsproxy structs into a new one.
24565 + *     will hold a reference on the result.
24566 + */
24567 +
24568 +static inline
24569 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
24570 +       struct nsproxy *proxy, unsigned long mask)
24571 +{
24572 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
24573 +
24574 +       if (!proxy)
24575 +               return NULL;
24576 +
24577 +       if (mask) {
24578 +               /* vs_mix_nsproxy returns with reference */
24579 +               return vs_mix_nsproxy(old ? old : &null_proxy,
24580 +                       proxy, mask);
24581 +       }
24582 +       get_nsproxy(proxy);
24583 +       return proxy;
24584 +}
24585 +
24586 +
24587 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
24588 +{
24589 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
24590 +       struct fs_struct *fs_cur, *fs = NULL;
24591 +       int ret, kill = 0;
24592 +
24593 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
24594 +               vxi, vxi->vx_id, mask, index);
24595 +
24596 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
24597 +               return -EACCES;
24598 +
24599 +       if (!mask)
24600 +               mask = vxi->vx_nsmask[index];
24601 +
24602 +       if ((mask & vxi->vx_nsmask[index]) != mask)
24603 +               return -EINVAL;
24604 +
24605 +       if (mask & CLONE_FS) {
24606 +               fs = copy_fs_struct(vxi->vx_fs[index]);
24607 +               if (!fs)
24608 +                       return -ENOMEM;
24609 +       }
24610 +       proxy = vxi->vx_nsproxy[index];
24611 +
24612 +       vxdprintk(VXD_CBIT(space, 9),
24613 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
24614 +               vxi, vxi->vx_id, mask, index, proxy, fs);
24615 +
24616 +       task_lock(current);
24617 +       fs_cur = current->fs;
24618 +
24619 +       if (mask & CLONE_FS) {
24620 +               write_lock(&fs_cur->lock);
24621 +               current->fs = fs;
24622 +               kill = !--fs_cur->users;
24623 +               write_unlock(&fs_cur->lock);
24624 +       }
24625 +
24626 +       proxy_cur = current->nsproxy;
24627 +       get_nsproxy(proxy_cur);
24628 +       task_unlock(current);
24629 +
24630 +       if (kill)
24631 +               free_fs_struct(fs_cur);
24632 +
24633 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
24634 +       if (IS_ERR(proxy_new)) {
24635 +               ret = PTR_ERR(proxy_new);
24636 +               goto out_put;
24637 +       }
24638 +
24639 +       proxy_new = xchg(&current->nsproxy, proxy_new);
24640 +       ret = 0;
24641 +
24642 +       if (proxy_new)
24643 +               put_nsproxy(proxy_new);
24644 +out_put:
24645 +       if (proxy_cur)
24646 +               put_nsproxy(proxy_cur);
24647 +       return ret;
24648 +}
24649 +
24650 +
24651 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
24652 +{
24653 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
24654 +       struct fs_struct *fs_vxi, *fs;
24655 +       int ret, kill = 0;
24656 +
24657 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
24658 +               vxi, vxi->vx_id, mask, index);
24659 +#if 0
24660 +       if (!mask)
24661 +               mask = default_space_mask.mask;
24662 +#endif
24663 +       if ((mask & space_mask.mask) != mask)
24664 +               return -EINVAL;
24665 +
24666 +       proxy_vxi = vxi->vx_nsproxy[index];
24667 +       fs_vxi = vxi->vx_fs[index];
24668 +
24669 +       if (mask & CLONE_FS) {
24670 +               fs = copy_fs_struct(current->fs);
24671 +               if (!fs)
24672 +                       return -ENOMEM;
24673 +       }
24674 +
24675 +       task_lock(current);
24676 +
24677 +       if (mask & CLONE_FS) {
24678 +               write_lock(&fs_vxi->lock);
24679 +               vxi->vx_fs[index] = fs;
24680 +               kill = !--fs_vxi->users;
24681 +               write_unlock(&fs_vxi->lock);
24682 +       }
24683 +
24684 +       proxy_cur = current->nsproxy;
24685 +       get_nsproxy(proxy_cur);
24686 +       task_unlock(current);
24687 +
24688 +       if (kill)
24689 +               free_fs_struct(fs_vxi);
24690 +
24691 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
24692 +       if (IS_ERR(proxy_new)) {
24693 +               ret = PTR_ERR(proxy_new);
24694 +               goto out_put;
24695 +       }
24696 +
24697 +       proxy_new = xchg(&vxi->vx_nsproxy[index], proxy_new);
24698 +       vxi->vx_nsmask[index] |= mask;
24699 +       ret = 0;
24700 +
24701 +       if (proxy_new)
24702 +               put_nsproxy(proxy_new);
24703 +out_put:
24704 +       if (proxy_cur)
24705 +               put_nsproxy(proxy_cur);
24706 +       return ret;
24707 +}
24708 +
24709 +
24710 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
24711 +{
24712 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
24713 +
24714 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24715 +               return -EFAULT;
24716 +
24717 +       return vx_enter_space(vxi, vc_data.mask, 0);
24718 +}
24719 +
24720 +int vc_enter_space(struct vx_info *vxi, void __user *data)
24721 +{
24722 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
24723 +
24724 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24725 +               return -EFAULT;
24726 +
24727 +       if (vc_data.index >= VX_SPACES)
24728 +               return -EINVAL;
24729 +
24730 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
24731 +}
24732 +
24733 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
24734 +{
24735 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
24736 +
24737 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24738 +               return -EFAULT;
24739 +
24740 +       return vx_set_space(vxi, vc_data.mask, 0);
24741 +}
24742 +
24743 +int vc_set_space(struct vx_info *vxi, void __user *data)
24744 +{
24745 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
24746 +
24747 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
24748 +               return -EFAULT;
24749 +
24750 +       if (vc_data.index >= VX_SPACES)
24751 +               return -EINVAL;
24752 +
24753 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
24754 +}
24755 +
24756 +int vc_get_space_mask(void __user *data, int type)
24757 +{
24758 +       const struct vcmd_space_mask_v1 *mask;
24759 +
24760 +       if (type == 0)
24761 +               mask = &space_mask_v0;
24762 +       else if (type == 1)
24763 +               mask = &space_mask;
24764 +       else
24765 +               mask = &default_space_mask;
24766 +
24767 +       vxdprintk(VXD_CBIT(space, 10),
24768 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
24769 +
24770 +       if (copy_to_user(data, mask, sizeof(*mask)))
24771 +               return -EFAULT;
24772 +       return 0;
24773 +}
24774 +
24775 diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/switch.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/switch.c
24776 --- linux-2.6.29.4/kernel/vserver/switch.c      1970-01-01 01:00:00.000000000 +0100
24777 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/switch.c        2009-03-24 14:59:18.000000000 +0100
24778 @@ -0,0 +1,543 @@
24779 +/*
24780 + *  linux/kernel/vserver/switch.c
24781 + *
24782 + *  Virtual Server: Syscall Switch
24783 + *
24784 + *  Copyright (C) 2003-2007  Herbert Pötzl
24785 + *
24786 + *  V0.01  syscall switch
24787 + *  V0.02  added signal to context
24788 + *  V0.03  added rlimit functions
24789 + *  V0.04  added iattr, task/xid functions
24790 + *  V0.05  added debug/history stuff
24791 + *  V0.06  added compat32 layer
24792 + *  V0.07  vcmd args and perms
24793 + *  V0.08  added status commands
24794 + *  V0.09  added tag commands
24795 + *  V0.10  added oom bias
24796 + *  V0.11  added device commands
24797 + *
24798 + */
24799 +
24800 +#include <linux/vs_context.h>
24801 +#include <linux/vs_network.h>
24802 +#include <linux/vserver/switch.h>
24803 +
24804 +#include "vci_config.h"
24805 +
24806 +
24807 +static inline
24808 +int vc_get_version(uint32_t id)
24809 +{
24810 +       return VCI_VERSION;
24811 +}
24812 +
24813 +static inline
24814 +int vc_get_vci(uint32_t id)
24815 +{
24816 +       return vci_kernel_config();
24817 +}
24818 +
24819 +#include <linux/vserver/context_cmd.h>
24820 +#include <linux/vserver/cvirt_cmd.h>
24821 +#include <linux/vserver/cacct_cmd.h>
24822 +#include <linux/vserver/limit_cmd.h>
24823 +#include <linux/vserver/network_cmd.h>
24824 +#include <linux/vserver/sched_cmd.h>
24825 +#include <linux/vserver/debug_cmd.h>
24826 +#include <linux/vserver/inode_cmd.h>
24827 +#include <linux/vserver/dlimit_cmd.h>
24828 +#include <linux/vserver/signal_cmd.h>
24829 +#include <linux/vserver/space_cmd.h>
24830 +#include <linux/vserver/tag_cmd.h>
24831 +#include <linux/vserver/device_cmd.h>
24832 +
24833 +#include <linux/vserver/inode.h>
24834 +#include <linux/vserver/dlimit.h>
24835 +
24836 +
24837 +#ifdef CONFIG_COMPAT
24838 +#define __COMPAT(name, id, data, compat)       \
24839 +       (compat) ? name ## _x32(id, data) : name(id, data)
24840 +#define __COMPAT_NO_ID(name, data, compat)     \
24841 +       (compat) ? name ## _x32(data) : name(data)
24842 +#else
24843 +#define __COMPAT(name, id, data, compat)       \
24844 +       name(id, data)
24845 +#define __COMPAT_NO_ID(name, data, compat)     \
24846 +       name(data)
24847 +#endif
24848 +
24849 +
24850 +static inline
24851 +long do_vcmd(uint32_t cmd, uint32_t id,
24852 +       struct vx_info *vxi, struct nx_info *nxi,
24853 +       void __user *data, int compat)
24854 +{
24855 +       switch (cmd) {
24856 +
24857 +       case VCMD_get_version:
24858 +               return vc_get_version(id);
24859 +       case VCMD_get_vci:
24860 +               return vc_get_vci(id);
24861 +
24862 +       case VCMD_task_xid:
24863 +               return vc_task_xid(id);
24864 +       case VCMD_vx_info:
24865 +               return vc_vx_info(vxi, data);
24866 +
24867 +       case VCMD_task_nid:
24868 +               return vc_task_nid(id);
24869 +       case VCMD_nx_info:
24870 +               return vc_nx_info(nxi, data);
24871 +
24872 +       case VCMD_task_tag:
24873 +               return vc_task_tag(id);
24874 +
24875 +       case VCMD_set_space_v1:
24876 +               return vc_set_space_v1(vxi, data);
24877 +       /* this is version 2 */
24878 +       case VCMD_set_space:
24879 +               return vc_set_space(vxi, data);
24880 +
24881 +       case VCMD_get_space_mask_v0:
24882 +               return vc_get_space_mask(data, 0);
24883 +       /* this is version 1 */
24884 +       case VCMD_get_space_mask:
24885 +               return vc_get_space_mask(data, 1);
24886 +
24887 +       case VCMD_get_space_default:
24888 +               return vc_get_space_mask(data, -1);
24889 +
24890 +#ifdef CONFIG_IA32_EMULATION
24891 +       case VCMD_get_rlimit:
24892 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
24893 +       case VCMD_set_rlimit:
24894 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
24895 +#else
24896 +       case VCMD_get_rlimit:
24897 +               return vc_get_rlimit(vxi, data);
24898 +       case VCMD_set_rlimit:
24899 +               return vc_set_rlimit(vxi, data);
24900 +#endif
24901 +       case VCMD_get_rlimit_mask:
24902 +               return vc_get_rlimit_mask(id, data);
24903 +       case VCMD_reset_minmax:
24904 +               return vc_reset_minmax(vxi, data);
24905 +
24906 +       case VCMD_get_vhi_name:
24907 +               return vc_get_vhi_name(vxi, data);
24908 +       case VCMD_set_vhi_name:
24909 +               return vc_set_vhi_name(vxi, data);
24910 +
24911 +       case VCMD_ctx_stat:
24912 +               return vc_ctx_stat(vxi, data);
24913 +       case VCMD_virt_stat:
24914 +               return vc_virt_stat(vxi, data);
24915 +       case VCMD_sock_stat:
24916 +               return vc_sock_stat(vxi, data);
24917 +       case VCMD_rlimit_stat:
24918 +               return vc_rlimit_stat(vxi, data);
24919 +
24920 +       case VCMD_set_cflags:
24921 +               return vc_set_cflags(vxi, data);
24922 +       case VCMD_get_cflags:
24923 +               return vc_get_cflags(vxi, data);
24924 +
24925 +       /* this is version 1 */
24926 +       case VCMD_set_ccaps:
24927 +               return vc_set_ccaps(vxi, data);
24928 +       /* this is version 1 */
24929 +       case VCMD_get_ccaps:
24930 +               return vc_get_ccaps(vxi, data);
24931 +       case VCMD_set_bcaps:
24932 +               return vc_set_bcaps(vxi, data);
24933 +       case VCMD_get_bcaps:
24934 +               return vc_get_bcaps(vxi, data);
24935 +
24936 +       case VCMD_set_badness:
24937 +               return vc_set_badness(vxi, data);
24938 +       case VCMD_get_badness:
24939 +               return vc_get_badness(vxi, data);
24940 +
24941 +       case VCMD_set_nflags:
24942 +               return vc_set_nflags(nxi, data);
24943 +       case VCMD_get_nflags:
24944 +               return vc_get_nflags(nxi, data);
24945 +
24946 +       case VCMD_set_ncaps:
24947 +               return vc_set_ncaps(nxi, data);
24948 +       case VCMD_get_ncaps:
24949 +               return vc_get_ncaps(nxi, data);
24950 +
24951 +       case VCMD_set_sched_v4:
24952 +               return vc_set_sched_v4(vxi, data);
24953 +       /* this is version 5 */
24954 +       case VCMD_set_sched:
24955 +               return vc_set_sched(vxi, data);
24956 +       case VCMD_get_sched:
24957 +               return vc_get_sched(vxi, data);
24958 +       case VCMD_sched_info:
24959 +               return vc_sched_info(vxi, data);
24960 +
24961 +       case VCMD_add_dlimit:
24962 +               return __COMPAT(vc_add_dlimit, id, data, compat);
24963 +       case VCMD_rem_dlimit:
24964 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
24965 +       case VCMD_set_dlimit:
24966 +               return __COMPAT(vc_set_dlimit, id, data, compat);
24967 +       case VCMD_get_dlimit:
24968 +               return __COMPAT(vc_get_dlimit, id, data, compat);
24969 +
24970 +       case VCMD_ctx_kill:
24971 +               return vc_ctx_kill(vxi, data);
24972 +
24973 +       case VCMD_wait_exit:
24974 +               return vc_wait_exit(vxi, data);
24975 +
24976 +       case VCMD_get_iattr:
24977 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
24978 +       case VCMD_set_iattr:
24979 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
24980 +
24981 +       case VCMD_fget_iattr:
24982 +               return vc_fget_iattr(id, data);
24983 +       case VCMD_fset_iattr:
24984 +               return vc_fset_iattr(id, data);
24985 +
24986 +       case VCMD_enter_space_v0:
24987 +               return vc_enter_space_v1(vxi, NULL);
24988 +       case VCMD_enter_space_v1:
24989 +               return vc_enter_space_v1(vxi, data);
24990 +       /* this is version 2 */
24991 +       case VCMD_enter_space:
24992 +               return vc_enter_space(vxi, data);
24993 +
24994 +       case VCMD_ctx_create_v0:
24995 +               return vc_ctx_create(id, NULL);
24996 +       case VCMD_ctx_create:
24997 +               return vc_ctx_create(id, data);
24998 +       case VCMD_ctx_migrate_v0:
24999 +               return vc_ctx_migrate(vxi, NULL);
25000 +       case VCMD_ctx_migrate:
25001 +               return vc_ctx_migrate(vxi, data);
25002 +
25003 +       case VCMD_net_create_v0:
25004 +               return vc_net_create(id, NULL);
25005 +       case VCMD_net_create:
25006 +               return vc_net_create(id, data);
25007 +       case VCMD_net_migrate:
25008 +               return vc_net_migrate(nxi, data);
25009 +
25010 +       case VCMD_tag_migrate:
25011 +               return vc_tag_migrate(id);
25012 +
25013 +       case VCMD_net_add:
25014 +               return vc_net_add(nxi, data);
25015 +       case VCMD_net_remove:
25016 +               return vc_net_remove(nxi, data);
25017 +
25018 +       case VCMD_net_add_ipv4:
25019 +               return vc_net_add_ipv4(nxi, data);
25020 +       case VCMD_net_remove_ipv4:
25021 +               return vc_net_remove_ipv4(nxi, data);
25022 +#ifdef CONFIG_IPV6
25023 +       case VCMD_net_add_ipv6:
25024 +               return vc_net_add_ipv6(nxi, data);
25025 +       case VCMD_net_remove_ipv6:
25026 +               return vc_net_remove_ipv6(nxi, data);
25027 +#endif
25028 +/*     case VCMD_add_match_ipv4:
25029 +               return vc_add_match_ipv4(nxi, data);
25030 +       case VCMD_get_match_ipv4:
25031 +               return vc_get_match_ipv4(nxi, data);
25032 +#ifdef CONFIG_IPV6
25033 +       case VCMD_add_match_ipv6:
25034 +               return vc_add_match_ipv6(nxi, data);
25035 +       case VCMD_get_match_ipv6:
25036 +               return vc_get_match_ipv6(nxi, data);
25037 +#endif */
25038 +
25039 +#ifdef CONFIG_VSERVER_DEVICE
25040 +       case VCMD_set_mapping:
25041 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
25042 +       case VCMD_unset_mapping:
25043 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
25044 +#endif
25045 +#ifdef CONFIG_VSERVER_HISTORY
25046 +       case VCMD_dump_history:
25047 +               return vc_dump_history(id);
25048 +       case VCMD_read_history:
25049 +               return __COMPAT(vc_read_history, id, data, compat);
25050 +#endif
25051 +#ifdef CONFIG_VSERVER_MONITOR
25052 +       case VCMD_read_monitor:
25053 +               return __COMPAT(vc_read_monitor, id, data, compat);
25054 +#endif
25055 +       default:
25056 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
25057 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
25058 +       }
25059 +       return -ENOSYS;
25060 +}
25061 +
25062 +
25063 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
25064 +       case VCMD_ ## vcmd: perm = _perm;               \
25065 +               args = _args; flags = _flags; break
25066 +
25067 +
25068 +#define VCA_NONE       0x00
25069 +#define VCA_VXI                0x01
25070 +#define VCA_NXI                0x02
25071 +
25072 +#define VCF_NONE       0x00
25073 +#define VCF_INFO       0x01
25074 +#define VCF_ADMIN      0x02
25075 +#define VCF_ARES       0x06    /* includes admin */
25076 +#define VCF_SETUP      0x08
25077 +
25078 +#define VCF_ZIDOK      0x10    /* zero id okay */
25079 +
25080 +
25081 +static inline
25082 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
25083 +{
25084 +       long ret;
25085 +       int permit = -1, state = 0;
25086 +       int perm = -1, args = 0, flags = 0;
25087 +       struct vx_info *vxi = NULL;
25088 +       struct nx_info *nxi = NULL;
25089 +
25090 +       switch (cmd) {
25091 +       /* unpriviledged commands */
25092 +       __VCMD(get_version,      0, VCA_NONE,   0);
25093 +       __VCMD(get_vci,          0, VCA_NONE,   0);
25094 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
25095 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
25096 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
25097 +       __VCMD(get_space_default,0, VCA_NONE,   0);
25098 +
25099 +       /* info commands */
25100 +       __VCMD(task_xid,         2, VCA_NONE,   0);
25101 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
25102 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
25103 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
25104 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
25105 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
25106 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
25107 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
25108 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
25109 +
25110 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
25111 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
25112 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
25113 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
25114 +
25115 +       __VCMD(task_nid,         2, VCA_NONE,   0);
25116 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
25117 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
25118 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
25119 +
25120 +       __VCMD(task_tag,         2, VCA_NONE,   0);
25121 +
25122 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
25123 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
25124 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
25125 +       __VCMD(get_sched,        3, VCA_VXI,    VCF_INFO);
25126 +       __VCMD(sched_info,       3, VCA_VXI,    VCF_INFO | VCF_ZIDOK);
25127 +
25128 +       /* lower admin commands */
25129 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
25130 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
25131 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
25132 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
25133 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
25134 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
25135 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
25136 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
25137 +
25138 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
25139 +       __VCMD(net_create,       5, VCA_NONE,   0);
25140 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
25141 +
25142 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
25143 +
25144 +       /* higher admin commands */
25145 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
25146 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25147 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25148 +
25149 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25150 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25151 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25152 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25153 +
25154 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25155 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25156 +       __VCMD(set_sched,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25157 +       __VCMD(set_sched_v4,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
25158 +
25159 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25160 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
25161 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25162 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25163 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25164 +       __VCMD(net_remove_ipv4,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25165 +#ifdef CONFIG_IPV6
25166 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25167 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
25168 +#endif
25169 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
25170 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
25171 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
25172 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
25173 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
25174 +
25175 +#ifdef CONFIG_VSERVER_DEVICE
25176 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
25177 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
25178 +#endif
25179 +       /* debug level admin commands */
25180 +#ifdef CONFIG_VSERVER_HISTORY
25181 +       __VCMD(dump_history,     9, VCA_NONE,   0);
25182 +       __VCMD(read_history,     9, VCA_NONE,   0);
25183 +#endif
25184 +#ifdef CONFIG_VSERVER_MONITOR
25185 +       __VCMD(read_monitor,     9, VCA_NONE,   0);
25186 +#endif
25187 +
25188 +       default:
25189 +               perm = -1;
25190 +       }
25191 +
25192 +       vxdprintk(VXD_CBIT(switch, 0),
25193 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
25194 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25195 +               VC_VERSION(cmd), id, data, compat,
25196 +               perm, args, flags);
25197 +
25198 +       ret = -ENOSYS;
25199 +       if (perm < 0)
25200 +               goto out;
25201 +
25202 +       state = 1;
25203 +       if (!capable(CAP_CONTEXT))
25204 +               goto out;
25205 +
25206 +       state = 2;
25207 +       /* moved here from the individual commands */
25208 +       ret = -EPERM;
25209 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
25210 +               goto out;
25211 +
25212 +       state = 3;
25213 +       /* vcmd involves resource management  */
25214 +       ret = -EPERM;
25215 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
25216 +               goto out;
25217 +
25218 +       state = 4;
25219 +       /* various legacy exceptions */
25220 +       switch (cmd) {
25221 +       /* will go away when spectator is a cap */
25222 +       case VCMD_ctx_migrate_v0:
25223 +       case VCMD_ctx_migrate:
25224 +               if (id == 1) {
25225 +                       current->xid = 1;
25226 +                       ret = 1;
25227 +                       goto out;
25228 +               }
25229 +               break;
25230 +
25231 +       /* will go away when spectator is a cap */
25232 +       case VCMD_net_migrate:
25233 +               if (id == 1) {
25234 +                       current->nid = 1;
25235 +                       ret = 1;
25236 +                       goto out;
25237 +               }
25238 +               break;
25239 +       }
25240 +
25241 +       /* vcmds are fine by default */
25242 +       permit = 1;
25243 +
25244 +       /* admin type vcmds require admin ... */
25245 +       if (flags & VCF_ADMIN)
25246 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
25247 +
25248 +       /* ... but setup type vcmds override that */
25249 +       if (!permit && (flags & VCF_SETUP))
25250 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
25251 +
25252 +       state = 5;
25253 +       ret = -EPERM;
25254 +       if (!permit)
25255 +               goto out;
25256 +
25257 +       state = 6;
25258 +       if (!id && (flags & VCF_ZIDOK))
25259 +               goto skip_id;
25260 +
25261 +       ret = -ESRCH;
25262 +       if (args & VCA_VXI) {
25263 +               vxi = lookup_vx_info(id);
25264 +               if (!vxi)
25265 +                       goto out;
25266 +
25267 +               if ((flags & VCF_ADMIN) &&
25268 +                       /* special case kill for shutdown */
25269 +                       (cmd != VCMD_ctx_kill) &&
25270 +                       /* can context be administrated? */
25271 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
25272 +                       ret = -EACCES;
25273 +                       goto out_vxi;
25274 +               }
25275 +       }
25276 +       state = 7;
25277 +       if (args & VCA_NXI) {
25278 +               nxi = lookup_nx_info(id);
25279 +               if (!nxi)
25280 +                       goto out_vxi;
25281 +
25282 +               if ((flags & VCF_ADMIN) &&
25283 +                       /* can context be administrated? */
25284 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
25285 +                       ret = -EACCES;
25286 +                       goto out_nxi;
25287 +               }
25288 +       }
25289 +skip_id:
25290 +       state = 8;
25291 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
25292 +
25293 +out_nxi:
25294 +       if ((args & VCA_NXI) && nxi)
25295 +               put_nx_info(nxi);
25296 +out_vxi:
25297 +       if ((args & VCA_VXI) && vxi)
25298 +               put_vx_info(vxi);
25299 +out:
25300 +       vxdprintk(VXD_CBIT(switch, 1),
25301 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
25302 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
25303 +               VC_VERSION(cmd), ret, ret, state, permit);
25304 +       return ret;
25305 +}
25306 +
25307 +asmlinkage long
25308 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
25309 +{
25310 +       return do_vserver(cmd, id, data, 0);
25311 +}
25312 +
25313 +#ifdef CONFIG_COMPAT
25314 +
25315 +asmlinkage long
25316 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
25317 +{
25318 +       return do_vserver(cmd, id, data, 1);
25319 +}
25320 +
25321 +#endif /* CONFIG_COMPAT */
25322 diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/sysctl.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/sysctl.c
25323 --- linux-2.6.29.4/kernel/vserver/sysctl.c      1970-01-01 01:00:00.000000000 +0100
25324 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/sysctl.c        2009-02-22 22:54:26.000000000 +0100
25325 @@ -0,0 +1,244 @@
25326 +/*
25327 + *  kernel/vserver/sysctl.c
25328 + *
25329 + *  Virtual Context Support
25330 + *
25331 + *  Copyright (C) 2004-2007  Herbert Pötzl
25332 + *
25333 + *  V0.01  basic structure
25334 + *
25335 + */
25336 +
25337 +#include <linux/module.h>
25338 +#include <linux/ctype.h>
25339 +#include <linux/sysctl.h>
25340 +#include <linux/parser.h>
25341 +#include <asm/uaccess.h>
25342 +
25343 +
25344 +enum {
25345 +       CTL_DEBUG_ERROR         = 0,
25346 +       CTL_DEBUG_SWITCH        = 1,
25347 +       CTL_DEBUG_XID,
25348 +       CTL_DEBUG_NID,
25349 +       CTL_DEBUG_TAG,
25350 +       CTL_DEBUG_NET,
25351 +       CTL_DEBUG_LIMIT,
25352 +       CTL_DEBUG_CRES,
25353 +       CTL_DEBUG_DLIM,
25354 +       CTL_DEBUG_QUOTA,
25355 +       CTL_DEBUG_CVIRT,
25356 +       CTL_DEBUG_SPACE,
25357 +       CTL_DEBUG_MISC,
25358 +};
25359 +
25360 +
25361 +unsigned int vx_debug_switch   = 0;
25362 +unsigned int vx_debug_xid      = 0;
25363 +unsigned int vx_debug_nid      = 0;
25364 +unsigned int vx_debug_tag      = 0;
25365 +unsigned int vx_debug_net      = 0;
25366 +unsigned int vx_debug_limit    = 0;
25367 +unsigned int vx_debug_cres     = 0;
25368 +unsigned int vx_debug_dlim     = 0;
25369 +unsigned int vx_debug_quota    = 0;
25370 +unsigned int vx_debug_cvirt    = 0;
25371 +unsigned int vx_debug_space    = 0;
25372 +unsigned int vx_debug_misc     = 0;
25373 +
25374 +
25375 +static struct ctl_table_header *vserver_table_header;
25376 +static ctl_table vserver_root_table[];
25377 +
25378 +
25379 +void vserver_register_sysctl(void)
25380 +{
25381 +       if (!vserver_table_header) {
25382 +               vserver_table_header = register_sysctl_table(vserver_root_table);
25383 +       }
25384 +
25385 +}
25386 +
25387 +void vserver_unregister_sysctl(void)
25388 +{
25389 +       if (vserver_table_header) {
25390 +               unregister_sysctl_table(vserver_table_header);
25391 +               vserver_table_header = NULL;
25392 +       }
25393 +}
25394 +
25395 +
25396 +static int proc_dodebug(ctl_table *table, int write,
25397 +       struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
25398 +{
25399 +       char            tmpbuf[20], *p, c;
25400 +       unsigned int    value;
25401 +       size_t          left, len;
25402 +
25403 +       if ((*ppos && !write) || !*lenp) {
25404 +               *lenp = 0;
25405 +               return 0;
25406 +       }
25407 +
25408 +       left = *lenp;
25409 +
25410 +       if (write) {
25411 +               if (!access_ok(VERIFY_READ, buffer, left))
25412 +                       return -EFAULT;
25413 +               p = (char *)buffer;
25414 +               while (left && __get_user(c, p) >= 0 && isspace(c))
25415 +                       left--, p++;
25416 +               if (!left)
25417 +                       goto done;
25418 +
25419 +               if (left > sizeof(tmpbuf) - 1)
25420 +                       return -EINVAL;
25421 +               if (copy_from_user(tmpbuf, p, left))
25422 +                       return -EFAULT;
25423 +               tmpbuf[left] = '\0';
25424 +
25425 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
25426 +                       value = 10 * value + (*p - '0');
25427 +               if (*p && !isspace(*p))
25428 +                       return -EINVAL;
25429 +               while (left && isspace(*p))
25430 +                       left--, p++;
25431 +               *(unsigned int *)table->data = value;
25432 +       } else {
25433 +               if (!access_ok(VERIFY_WRITE, buffer, left))
25434 +                       return -EFAULT;
25435 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
25436 +               if (len > left)
25437 +                       len = left;
25438 +               if (__copy_to_user(buffer, tmpbuf, len))
25439 +                       return -EFAULT;
25440 +               if ((left -= len) > 0) {
25441 +                       if (put_user('\n', (char *)buffer + len))
25442 +                               return -EFAULT;
25443 +                       left--;
25444 +               }
25445 +       }
25446 +
25447 +done:
25448 +       *lenp -= left;
25449 +       *ppos += *lenp;
25450 +       return 0;
25451 +}
25452 +
25453 +static int zero;
25454 +
25455 +#define        CTL_ENTRY(ctl, name)                            \
25456 +       {                                               \
25457 +               .ctl_name       = ctl,                  \
25458 +               .procname       = #name,                \
25459 +               .data           = &vx_ ## name,         \
25460 +               .maxlen         = sizeof(int),          \
25461 +               .mode           = 0644,                 \
25462 +               .proc_handler   = &proc_dodebug,        \
25463 +               .strategy       = &sysctl_intvec,       \
25464 +               .extra1         = &zero,                \
25465 +       }
25466 +
25467 +static ctl_table vserver_debug_table[] = {
25468 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
25469 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
25470 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
25471 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
25472 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
25473 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
25474 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
25475 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
25476 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
25477 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
25478 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
25479 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
25480 +       { .ctl_name = 0 }
25481 +};
25482 +
25483 +static ctl_table vserver_root_table[] = {
25484 +       {
25485 +               .ctl_name       = CTL_VSERVER,
25486 +               .procname       = "vserver",
25487 +               .mode           = 0555,
25488 +               .child          = vserver_debug_table
25489 +       },
25490 +       { .ctl_name = 0 }
25491 +};
25492 +
25493 +
25494 +static match_table_t tokens = {
25495 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
25496 +       { CTL_DEBUG_XID,        "xid=%x"        },
25497 +       { CTL_DEBUG_NID,        "nid=%x"        },
25498 +       { CTL_DEBUG_TAG,        "tag=%x"        },
25499 +       { CTL_DEBUG_NET,        "net=%x"        },
25500 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
25501 +       { CTL_DEBUG_CRES,       "cres=%x"       },
25502 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
25503 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
25504 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
25505 +       { CTL_DEBUG_SPACE,      "space=%x"      },
25506 +       { CTL_DEBUG_MISC,       "misc=%x"       },
25507 +       { CTL_DEBUG_ERROR,      NULL            }
25508 +};
25509 +
25510 +#define        HANDLE_CASE(id, name, val)                              \
25511 +       case CTL_DEBUG_ ## id:                                  \
25512 +               vx_debug_ ## name = val;                        \
25513 +               printk("vs_debug_" #name "=0x%x\n", val);       \
25514 +               break
25515 +
25516 +
25517 +static int __init vs_debug_setup(char *str)
25518 +{
25519 +       char *p;
25520 +       int token;
25521 +
25522 +       printk("vs_debug_setup(%s)\n", str);
25523 +       while ((p = strsep(&str, ",")) != NULL) {
25524 +               substring_t args[MAX_OPT_ARGS];
25525 +               unsigned int value;
25526 +
25527 +               if (!*p)
25528 +                       continue;
25529 +
25530 +               token = match_token(p, tokens, args);
25531 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
25532 +
25533 +               switch (token) {
25534 +               HANDLE_CASE(SWITCH, switch, value);
25535 +               HANDLE_CASE(XID,    xid,    value);
25536 +               HANDLE_CASE(NID,    nid,    value);
25537 +               HANDLE_CASE(TAG,    tag,    value);
25538 +               HANDLE_CASE(NET,    net,    value);
25539 +               HANDLE_CASE(LIMIT,  limit,  value);
25540 +               HANDLE_CASE(CRES,   cres,   value);
25541 +               HANDLE_CASE(DLIM,   dlim,   value);
25542 +               HANDLE_CASE(QUOTA,  quota,  value);
25543 +               HANDLE_CASE(CVIRT,  cvirt,  value);
25544 +               HANDLE_CASE(SPACE,  space,  value);
25545 +               HANDLE_CASE(MISC,   misc,   value);
25546 +               default:
25547 +                       return -EINVAL;
25548 +                       break;
25549 +               }
25550 +       }
25551 +       return 1;
25552 +}
25553 +
25554 +__setup("vsdebug=", vs_debug_setup);
25555 +
25556 +
25557 +
25558 +EXPORT_SYMBOL_GPL(vx_debug_switch);
25559 +EXPORT_SYMBOL_GPL(vx_debug_xid);
25560 +EXPORT_SYMBOL_GPL(vx_debug_nid);
25561 +EXPORT_SYMBOL_GPL(vx_debug_net);
25562 +EXPORT_SYMBOL_GPL(vx_debug_limit);
25563 +EXPORT_SYMBOL_GPL(vx_debug_cres);
25564 +EXPORT_SYMBOL_GPL(vx_debug_dlim);
25565 +EXPORT_SYMBOL_GPL(vx_debug_quota);
25566 +EXPORT_SYMBOL_GPL(vx_debug_cvirt);
25567 +EXPORT_SYMBOL_GPL(vx_debug_space);
25568 +EXPORT_SYMBOL_GPL(vx_debug_misc);
25569 +
25570 diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/tag.c linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/tag.c
25571 --- linux-2.6.29.4/kernel/vserver/tag.c 1970-01-01 01:00:00.000000000 +0100
25572 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/tag.c   2009-02-22 22:54:26.000000000 +0100
25573 @@ -0,0 +1,63 @@
25574 +/*
25575 + *  linux/kernel/vserver/tag.c
25576 + *
25577 + *  Virtual Server: Shallow Tag Space
25578 + *
25579 + *  Copyright (C) 2007  Herbert Pötzl
25580 + *
25581 + *  V0.01  basic implementation
25582 + *
25583 + */
25584 +
25585 +#include <linux/sched.h>
25586 +#include <linux/vserver/debug.h>
25587 +#include <linux/vs_pid.h>
25588 +#include <linux/vs_tag.h>
25589 +
25590 +#include <linux/vserver/tag_cmd.h>
25591 +
25592 +
25593 +int dx_migrate_task(struct task_struct *p, tag_t tag)
25594 +{
25595 +       if (!p)
25596 +               BUG();
25597 +
25598 +       vxdprintk(VXD_CBIT(tag, 5),
25599 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
25600 +
25601 +       task_lock(p);
25602 +       p->tag = tag;
25603 +       task_unlock(p);
25604 +
25605 +       vxdprintk(VXD_CBIT(tag, 5),
25606 +               "moved task %p into [#%d]", p, tag);
25607 +       return 0;
25608 +}
25609 +
25610 +/* vserver syscall commands below here */
25611 +
25612 +/* taks xid and vx_info functions */
25613 +
25614 +
25615 +int vc_task_tag(uint32_t id)
25616 +{
25617 +       tag_t tag;
25618 +
25619 +       if (id) {
25620 +               struct task_struct *tsk;
25621 +               read_lock(&tasklist_lock);
25622 +               tsk = find_task_by_real_pid(id);
25623 +               tag = (tsk) ? tsk->tag : -ESRCH;
25624 +               read_unlock(&tasklist_lock);
25625 +       } else
25626 +               tag = dx_current_tag();
25627 +       return tag;
25628 +}
25629 +
25630 +
25631 +int vc_tag_migrate(uint32_t tag)
25632 +{
25633 +       return dx_migrate_task(current, tag & 0xFFFF);
25634 +}
25635 +
25636 +
25637 diff -NurpP --minimal linux-2.6.29.4/kernel/vserver/vci_config.h linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/vci_config.h
25638 --- linux-2.6.29.4/kernel/vserver/vci_config.h  1970-01-01 01:00:00.000000000 +0100
25639 +++ linux-2.6.29.4-vs2.3.0.36.14/kernel/vserver/vci_config.h    2009-02-22 22:54:26.000000000 +0100
25640 @@ -0,0 +1,81 @@
25641 +
25642 +/*  interface version */
25643 +
25644 +#define VCI_VERSION            0x00020304
25645 +
25646 +
25647 +enum {
25648 +       VCI_KCBIT_NO_DYNAMIC = 0,
25649 +
25650 +       VCI_KCBIT_PROC_SECURE = 4,
25651 +       VCI_KCBIT_HARDCPU = 5,
25652 +       VCI_KCBIT_IDLELIMIT = 6,
25653 +       VCI_KCBIT_IDLETIME = 7,
25654 +
25655 +       VCI_KCBIT_COWBL = 8,
25656 +       VCI_KCBIT_FULLCOWBL = 9,
25657 +       VCI_KCBIT_SPACES = 10,
25658 +       VCI_KCBIT_NETV2 = 11,
25659 +
25660 +       VCI_KCBIT_DEBUG = 16,
25661 +       VCI_KCBIT_HISTORY = 20,
25662 +       VCI_KCBIT_TAGGED = 24,
25663 +       VCI_KCBIT_PPTAG = 28,
25664 +
25665 +       VCI_KCBIT_MORE = 31,
25666 +};
25667 +
25668 +
25669 +static inline uint32_t vci_kernel_config(void)
25670 +{
25671 +       return
25672 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
25673 +
25674 +       /* configured features */
25675 +#ifdef CONFIG_VSERVER_PROC_SECURE
25676 +       (1 << VCI_KCBIT_PROC_SECURE) |
25677 +#endif
25678 +#ifdef CONFIG_VSERVER_HARDCPU
25679 +       (1 << VCI_KCBIT_HARDCPU) |
25680 +#endif
25681 +#ifdef CONFIG_VSERVER_IDLELIMIT
25682 +       (1 << VCI_KCBIT_IDLELIMIT) |
25683 +#endif
25684 +#ifdef CONFIG_VSERVER_IDLETIME
25685 +       (1 << VCI_KCBIT_IDLETIME) |
25686 +#endif
25687 +#ifdef CONFIG_VSERVER_COWBL
25688 +       (1 << VCI_KCBIT_COWBL) |
25689 +       (1 << VCI_KCBIT_FULLCOWBL) |
25690 +#endif
25691 +       (1 << VCI_KCBIT_SPACES) |
25692 +       (1 << VCI_KCBIT_NETV2) |
25693 +
25694 +       /* debug options */
25695 +#ifdef CONFIG_VSERVER_DEBUG
25696 +       (1 << VCI_KCBIT_DEBUG) |
25697 +#endif
25698 +#ifdef CONFIG_VSERVER_HISTORY
25699 +       (1 << VCI_KCBIT_HISTORY) |
25700 +#endif
25701 +
25702 +       /* inode context tagging */
25703 +#if    defined(CONFIG_TAGGING_NONE)
25704 +       (0 << VCI_KCBIT_TAGGED) |
25705 +#elif  defined(CONFIG_TAGGING_UID16)
25706 +       (1 << VCI_KCBIT_TAGGED) |
25707 +#elif  defined(CONFIG_TAGGING_GID16)
25708 +       (2 << VCI_KCBIT_TAGGED) |
25709 +#elif  defined(CONFIG_TAGGING_ID24)
25710 +       (3 << VCI_KCBIT_TAGGED) |
25711 +#elif  defined(CONFIG_TAGGING_INTERN)
25712 +       (4 << VCI_KCBIT_TAGGED) |
25713 +#elif  defined(CONFIG_TAGGING_RUNTIME)
25714 +       (5 << VCI_KCBIT_TAGGED) |
25715 +#else
25716 +       (7 << VCI_KCBIT_TAGGED) |
25717 +#endif
25718 +       (1 << VCI_KCBIT_PPTAG) |
25719 +       0;
25720 +}
25721 +
25722 diff -NurpP --minimal linux-2.6.29.4/mm/filemap_xip.c linux-2.6.29.4-vs2.3.0.36.14/mm/filemap_xip.c
25723 --- linux-2.6.29.4/mm/filemap_xip.c     2009-05-23 23:16:53.000000000 +0200
25724 +++ linux-2.6.29.4-vs2.3.0.36.14/mm/filemap_xip.c       2009-04-30 12:14:53.000000000 +0200
25725 @@ -17,6 +17,7 @@
25726  #include <linux/sched.h>
25727  #include <linux/seqlock.h>
25728  #include <linux/mutex.h>
25729 +#include <linux/vs_memory.h>
25730  #include <asm/tlbflush.h>
25731  #include <asm/io.h>
25732  
25733 diff -NurpP --minimal linux-2.6.29.4/mm/fremap.c linux-2.6.29.4-vs2.3.0.36.14/mm/fremap.c
25734 --- linux-2.6.29.4/mm/fremap.c  2009-03-24 14:22:45.000000000 +0100
25735 +++ linux-2.6.29.4-vs2.3.0.36.14/mm/fremap.c    2009-03-24 14:48:36.000000000 +0100
25736 @@ -16,6 +16,7 @@
25737  #include <linux/module.h>
25738  #include <linux/syscalls.h>
25739  #include <linux/mmu_notifier.h>
25740 +#include <linux/vs_memory.h>
25741  
25742  #include <asm/mmu_context.h>
25743  #include <asm/cacheflush.h>
25744 diff -NurpP --minimal linux-2.6.29.4/mm/hugetlb.c linux-2.6.29.4-vs2.3.0.36.14/mm/hugetlb.c
25745 --- linux-2.6.29.4/mm/hugetlb.c 2009-03-24 14:22:45.000000000 +0100
25746 +++ linux-2.6.29.4-vs2.3.0.36.14/mm/hugetlb.c   2009-03-24 14:48:36.000000000 +0100
25747 @@ -24,6 +24,7 @@
25748  #include <asm/io.h>
25749  
25750  #include <linux/hugetlb.h>
25751 +#include <linux/vs_memory.h>
25752  #include "internal.h"
25753  
25754  const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
25755 diff -NurpP --minimal linux-2.6.29.4/mm/memory.c linux-2.6.29.4-vs2.3.0.36.14/mm/memory.c
25756 --- linux-2.6.29.4/mm/memory.c  2009-05-23 23:16:53.000000000 +0200
25757 +++ linux-2.6.29.4-vs2.3.0.36.14/mm/memory.c    2009-05-23 23:19:11.000000000 +0200
25758 @@ -55,6 +55,7 @@
25759  #include <linux/kallsyms.h>
25760  #include <linux/swapops.h>
25761  #include <linux/elf.h>
25762 +// #include <linux/vs_memory.h>
25763  
25764  #include <asm/pgalloc.h>
25765  #include <asm/uaccess.h>
25766 @@ -612,6 +613,9 @@ static int copy_pte_range(struct mm_stru
25767         int progress = 0;
25768         int rss[2];
25769  
25770 +       if (!vx_rss_avail(dst_mm, ((end - addr)/PAGE_SIZE + 1)))
25771 +               return -ENOMEM;
25772 +
25773  again:
25774         rss[1] = rss[0] = 0;
25775         dst_pte = pte_alloc_map_lock(dst_mm, dst_pmd, addr, &dst_ptl);
25776 @@ -2481,6 +2485,11 @@ static int do_swap_page(struct mm_struct
25777                 count_vm_event(PGMAJFAULT);
25778         }
25779  
25780 +       if (!vx_rss_avail(mm, 1)) {
25781 +               ret = VM_FAULT_OOM;
25782 +               goto out;
25783 +       }
25784 +
25785         mark_page_accessed(page);
25786  
25787         lock_page(page);
25788 @@ -2572,6 +2581,8 @@ static int do_anonymous_page(struct mm_s
25789         /* Allocate our own private page. */
25790         pte_unmap(page_table);
25791  
25792 +       if (!vx_rss_avail(mm, 1))
25793 +               goto oom;
25794         if (unlikely(anon_vma_prepare(vma)))
25795                 goto oom;
25796         page = alloc_zeroed_user_highpage_movable(vma, address);
25797 @@ -2855,6 +2866,7 @@ static inline int handle_pte_fault(struc
25798  {
25799         pte_t entry;
25800         spinlock_t *ptl;
25801 +       int ret = 0, type = VXPT_UNKNOWN;
25802  
25803         entry = *pte;
25804         if (!pte_present(entry)) {
25805 @@ -2879,9 +2891,12 @@ static inline int handle_pte_fault(struc
25806         if (unlikely(!pte_same(*pte, entry)))
25807                 goto unlock;
25808         if (write_access) {
25809 -               if (!pte_write(entry))
25810 -                       return do_wp_page(mm, vma, address,
25811 +               if (!pte_write(entry)) {
25812 +                       ret = do_wp_page(mm, vma, address,
25813                                         pte, pmd, ptl, entry);
25814 +                       type = VXPT_WRITE;
25815 +                       goto out;
25816 +               }
25817                 entry = pte_mkdirty(entry);
25818         }
25819         entry = pte_mkyoung(entry);
25820 @@ -2899,7 +2914,10 @@ static inline int handle_pte_fault(struc
25821         }
25822  unlock:
25823         pte_unmap_unlock(pte, ptl);
25824 -       return 0;
25825 +       ret = 0;
25826 +out:
25827 +       vx_page_fault(mm, vma, type, ret);
25828 +       return ret;
25829  }
25830  
25831  /*
25832 diff -NurpP --minimal linux-2.6.29.4/mm/mlock.c linux-2.6.29.4-vs2.3.0.36.14/mm/mlock.c
25833 --- linux-2.6.29.4/mm/mlock.c   2009-03-24 14:22:45.000000000 +0100
25834 +++ linux-2.6.29.4-vs2.3.0.36.14/mm/mlock.c     2009-03-28 05:08:26.000000000 +0100
25835 @@ -18,6 +18,7 @@
25836  #include <linux/rmap.h>
25837  #include <linux/mmzone.h>
25838  #include <linux/hugetlb.h>
25839 +#include <linux/vs_memory.h>
25840  
25841  #include "internal.h"
25842  
25843 @@ -415,7 +416,7 @@ success:
25844         nr_pages = (end - start) >> PAGE_SHIFT;
25845         if (!lock)
25846                 nr_pages = -nr_pages;
25847 -       mm->locked_vm += nr_pages;
25848 +       vx_vmlocked_add(mm, nr_pages);
25849  
25850         /*
25851          * vm_flags is protected by the mmap_sem held in write mode.
25852 @@ -492,7 +493,7 @@ static int do_mlock(unsigned long start,
25853  
25854  SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
25855  {
25856 -       unsigned long locked;
25857 +       unsigned long locked, grow;
25858         unsigned long lock_limit;
25859         int error = -ENOMEM;
25860  
25861 @@ -505,8 +506,10 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
25862         len = PAGE_ALIGN(len + (start & ~PAGE_MASK));
25863         start &= PAGE_MASK;
25864  
25865 -       locked = len >> PAGE_SHIFT;
25866 -       locked += current->mm->locked_vm;
25867 +       grow = len >> PAGE_SHIFT;
25868 +       if (!vx_vmlocked_avail(current->mm, grow))
25869 +               goto out;
25870 +       locked = current->mm->locked_vm + grow;
25871  
25872         lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
25873         lock_limit >>= PAGE_SHIFT;
25874 @@ -514,6 +517,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, st
25875         /* check against resource limits */
25876         if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
25877                 error = do_mlock(start, len, 1);
25878 +out:
25879         up_write(&current->mm->mmap_sem);
25880         return error;
25881  }
25882 @@ -575,6 +579,8 @@ SYSCALL_DEFINE1(mlockall, int, flags)
25883         lock_limit >>= PAGE_SHIFT;
25884  
25885         ret = -ENOMEM;
25886 +       if (!vx_vmlocked_avail(current->mm, current->mm->total_vm))
25887 +               goto out;
25888         if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
25889             capable(CAP_IPC_LOCK))
25890                 ret = do_mlockall(flags);
25891 @@ -652,8 +658,10 @@ void *alloc_locked_buffer(size_t size)
25892         if (!buffer)
25893                 goto out;
25894  
25895 -       current->mm->total_vm  += pgsz;
25896 -       current->mm->locked_vm += pgsz;
25897 +       // current->mm->total_vm  += pgsz;
25898 +       vx_vmpages_add(current->mm, pgsz);
25899 +       // current->mm->locked_vm += pgsz;
25900 +       vx_vmlocked_add(current->mm, pgsz);
25901  
25902   out:
25903         up_write(&current->mm->mmap_sem);
25904 @@ -666,8 +674,10 @@ void release_locked_buffer(void *buffer,
25905  
25906         down_write(&current->mm->mmap_sem);
25907  
25908 -       current->mm->total_vm  -= pgsz;
25909 -       current->mm->locked_vm -= pgsz;
25910 +       // current->mm->total_vm  -= pgsz;
25911 +       vx_vmpages_sub(current->mm, pgsz);
25912 +       // current->mm->locked_vm -= pgsz;
25913 +       vx_vmlocked_sub(current->mm, pgsz);
25914  
25915         up_write(&current->mm->mmap_sem);
25916  }
25917 diff -NurpP --minimal linux-2.6.29.4/mm/mmap.c linux-2.6.29.4-vs2.3.0.36.14/mm/mmap.c
25918 --- linux-2.6.29.4/mm/mmap.c    2009-05-23 23:16:53.000000000 +0200
25919 +++ linux-2.6.29.4-vs2.3.0.36.14/mm/mmap.c      2009-05-10 23:42:01.000000000 +0200
25920 @@ -1215,7 +1215,8 @@ munmap_back:
25921         if (correct_wcount)
25922                 atomic_inc(&inode->i_writecount);
25923  out:
25924 -       mm->total_vm += len >> PAGE_SHIFT;
25925 +       // mm->total_vm += len >> PAGE_SHIFT;
25926 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
25927         vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
25928         if (vm_flags & VM_LOCKED) {
25929                 /*
25930 @@ -1224,7 +1225,8 @@ out:
25931                 long nr_pages = mlock_vma_pages_range(vma, addr, addr + len);
25932                 if (nr_pages < 0)
25933                         return nr_pages;        /* vma gone! */
25934 -               mm->locked_vm += (len >> PAGE_SHIFT) - nr_pages;
25935 +               // mm->locked_vm += (len >> PAGE_SHIFT) - nr_pages;
25936 +               vx_vmlocked_add(mm, (len >> PAGE_SHIFT) - nr_pages);
25937         } else if ((flags & MAP_POPULATE) && !(flags & MAP_NONBLOCK))
25938                 make_pages_present(addr, addr + len);
25939         return addr;
25940 @@ -1571,9 +1573,9 @@ static int acct_stack_growth(struct vm_a
25941                 return -ENOMEM;
25942  
25943         /* Ok, everything looks good - let it rip */
25944 -       mm->total_vm += grow;
25945 +       vx_vmpages_add(mm, grow);
25946         if (vma->vm_flags & VM_LOCKED)
25947 -               mm->locked_vm += grow;
25948 +               vx_vmlocked_add(mm, grow);
25949         vm_stat_account(mm, vma->vm_flags, vma->vm_file, grow);
25950         return 0;
25951  }
25952 @@ -1748,7 +1750,8 @@ static void remove_vma_list(struct mm_st
25953         do {
25954                 long nrpages = vma_pages(vma);
25955  
25956 -               mm->total_vm -= nrpages;
25957 +               // mm->total_vm -= nrpages;
25958 +               vx_vmpages_sub(mm, nrpages);
25959                 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
25960                 vma = remove_vma(vma);
25961         } while (vma);
25962 @@ -1920,7 +1923,8 @@ int do_munmap(struct mm_struct *mm, unsi
25963                 struct vm_area_struct *tmp = vma;
25964                 while (tmp && tmp->vm_start < end) {
25965                         if (tmp->vm_flags & VM_LOCKED) {
25966 -                               mm->locked_vm -= vma_pages(tmp);
25967 +                               // mm->locked_vm -= vma_pages(tmp);
25968 +                               vx_vmlocked_sub(mm, vma_pages(tmp));
25969                                 munlock_vma_pages_all(tmp);
25970                         }
25971                         tmp = tmp->vm_next;
25972 @@ -2009,6 +2013,8 @@ unsigned long do_brk(unsigned long addr,
25973                 lock_limit >>= PAGE_SHIFT;
25974                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
25975                         return -EAGAIN;
25976 +               if (!vx_vmlocked_avail(mm, len >> PAGE_SHIFT))
25977 +                       return -ENOMEM;
25978         }
25979  
25980         /*
25981 @@ -2035,7 +2041,8 @@ unsigned long do_brk(unsigned long addr,
25982         if (mm->map_count > sysctl_max_map_count)
25983                 return -ENOMEM;
25984  
25985 -       if (security_vm_enough_memory(len >> PAGE_SHIFT))
25986 +       if (security_vm_enough_memory(len >> PAGE_SHIFT) ||
25987 +               !vx_vmpages_avail(mm, len >> PAGE_SHIFT))
25988                 return -ENOMEM;
25989  
25990         /* Can we just expand an old private anonymous mapping? */
25991 @@ -2061,10 +2068,13 @@ unsigned long do_brk(unsigned long addr,
25992         vma->vm_page_prot = vm_get_page_prot(flags);
25993         vma_link(mm, vma, prev, rb_link, rb_parent);
25994  out:
25995 -       mm->total_vm += len >> PAGE_SHIFT;
25996 +       // mm->total_vm += len >> PAGE_SHIFT;
25997 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
25998 +
25999         if (flags & VM_LOCKED) {
26000                 if (!mlock_vma_pages_range(vma, addr, addr + len))
26001 -                       mm->locked_vm += (len >> PAGE_SHIFT);
26002 +                       // mm->locked_vm += (len >> PAGE_SHIFT);
26003 +                       vx_vmlocked_add(mm, len >> PAGE_SHIFT);
26004         }
26005         return addr;
26006  }
26007 @@ -2107,6 +2117,11 @@ void exit_mmap(struct mm_struct *mm)
26008         free_pgtables(tlb, vma, FIRST_USER_ADDRESS, 0);
26009         tlb_finish_mmu(tlb, 0, end);
26010  
26011 +       set_mm_counter(mm, file_rss, 0);
26012 +       set_mm_counter(mm, anon_rss, 0);
26013 +       vx_vmpages_sub(mm, mm->total_vm);
26014 +       vx_vmlocked_sub(mm, mm->locked_vm);
26015 +
26016         /*
26017          * Walk the list again, actually closing and freeing it,
26018          * with preemption enabled, without holding any MM locks.
26019 @@ -2146,7 +2161,8 @@ int insert_vm_struct(struct mm_struct * 
26020         if (__vma && __vma->vm_start < vma->vm_end)
26021                 return -ENOMEM;
26022         if ((vma->vm_flags & VM_ACCOUNT) &&
26023 -            security_vm_enough_memory_mm(mm, vma_pages(vma)))
26024 +               (security_vm_enough_memory_mm(mm, vma_pages(vma)) ||
26025 +               !vx_vmpages_avail(mm, vma_pages(vma))))
26026                 return -ENOMEM;
26027         vma_link(mm, vma, prev, rb_link, rb_parent);
26028         return 0;
26029 @@ -2222,6 +2238,8 @@ int may_expand_vm(struct mm_struct *mm, 
26030  
26031         if (cur + npages > lim)
26032                 return 0;
26033 +       if (!vx_vmpages_avail(mm, npages))
26034 +               return 0;
26035         return 1;
26036  }
26037  
26038 @@ -2299,8 +2317,7 @@ int install_special_mapping(struct mm_st
26039                 return -ENOMEM;
26040         }
26041  
26042 -       mm->total_vm += len >> PAGE_SHIFT;
26043 -
26044 +       vx_vmpages_add(mm, len >> PAGE_SHIFT);
26045         return 0;
26046  }
26047  
26048 diff -NurpP --minimal linux-2.6.29.4/mm/mremap.c linux-2.6.29.4-vs2.3.0.36.14/mm/mremap.c
26049 --- linux-2.6.29.4/mm/mremap.c  2009-03-24 14:22:45.000000000 +0100
26050 +++ linux-2.6.29.4-vs2.3.0.36.14/mm/mremap.c    2009-03-24 14:48:36.000000000 +0100
26051 @@ -19,6 +19,7 @@
26052  #include <linux/security.h>
26053  #include <linux/syscalls.h>
26054  #include <linux/mmu_notifier.h>
26055 +#include <linux/vs_memory.h>
26056  
26057  #include <asm/uaccess.h>
26058  #include <asm/cacheflush.h>
26059 @@ -220,7 +221,7 @@ static unsigned long move_vma(struct vm_
26060          * If this were a serious issue, we'd add a flag to do_munmap().
26061          */
26062         hiwater_vm = mm->hiwater_vm;
26063 -       mm->total_vm += new_len >> PAGE_SHIFT;
26064 +       vx_vmpages_add(mm, new_len >> PAGE_SHIFT);
26065         vm_stat_account(mm, vma->vm_flags, vma->vm_file, new_len>>PAGE_SHIFT);
26066  
26067         if (do_munmap(mm, old_addr, old_len) < 0) {
26068 @@ -238,7 +239,7 @@ static unsigned long move_vma(struct vm_
26069         }
26070  
26071         if (vm_flags & VM_LOCKED) {
26072 -               mm->locked_vm += new_len >> PAGE_SHIFT;
26073 +               vx_vmlocked_add(mm, new_len >> PAGE_SHIFT);
26074                 if (new_len > old_len)
26075                         mlock_vma_pages_range(new_vma, new_addr + old_len,
26076                                                        new_addr + new_len);
26077 @@ -349,6 +350,9 @@ unsigned long do_mremap(unsigned long ad
26078                 ret = -EAGAIN;
26079                 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
26080                         goto out;
26081 +               if (!vx_vmlocked_avail(current->mm,
26082 +                       (new_len - old_len) >> PAGE_SHIFT))
26083 +                       goto out;
26084         }
26085         if (!may_expand_vm(mm, (new_len - old_len) >> PAGE_SHIFT)) {
26086                 ret = -ENOMEM;
26087 @@ -377,10 +381,12 @@ unsigned long do_mremap(unsigned long ad
26088                         vma_adjust(vma, vma->vm_start,
26089                                 addr + new_len, vma->vm_pgoff, NULL);
26090  
26091 -                       mm->total_vm += pages;
26092 +                       // mm->total_vm += pages;
26093 +                       vx_vmpages_add(mm, pages);
26094                         vm_stat_account(mm, vma->vm_flags, vma->vm_file, pages);
26095                         if (vma->vm_flags & VM_LOCKED) {
26096 -                               mm->locked_vm += pages;
26097 +                               // mm->locked_vm += pages;
26098 +                               vx_vmlocked_add(mm, pages);
26099                                 mlock_vma_pages_range(vma, addr + old_len,
26100                                                    addr + new_len);
26101                         }
26102 diff -NurpP --minimal linux-2.6.29.4/mm/nommu.c linux-2.6.29.4-vs2.3.0.36.14/mm/nommu.c
26103 --- linux-2.6.29.4/mm/nommu.c   2009-05-23 23:16:53.000000000 +0200
26104 +++ linux-2.6.29.4-vs2.3.0.36.14/mm/nommu.c     2009-05-10 23:42:01.000000000 +0200
26105 @@ -1352,7 +1352,7 @@ unsigned long do_mmap_pgoff(struct file 
26106         /* okay... we have a mapping; now we have to register it */
26107         result = vma->vm_start;
26108  
26109 -       current->mm->total_vm += len >> PAGE_SHIFT;
26110 +       vx_vmpages_add(current->mm, len >> PAGE_SHIFT);
26111  
26112  share:
26113         add_vma_to_mm(current->mm, vma);
26114 @@ -1618,7 +1618,7 @@ void exit_mmap(struct mm_struct *mm)
26115  
26116         kenter("");
26117  
26118 -       mm->total_vm = 0;
26119 +       vx_vmpages_sub(mm, mm->total_vm);
26120  
26121         while ((vma = mm->mmap)) {
26122                 mm->mmap = vma->vm_next;
26123 diff -NurpP --minimal linux-2.6.29.4/mm/oom_kill.c linux-2.6.29.4-vs2.3.0.36.14/mm/oom_kill.c
26124 --- linux-2.6.29.4/mm/oom_kill.c        2009-03-24 14:22:45.000000000 +0100
26125 +++ linux-2.6.29.4-vs2.3.0.36.14/mm/oom_kill.c  2009-03-24 14:48:36.000000000 +0100
26126 @@ -27,6 +27,7 @@
26127  #include <linux/notifier.h>
26128  #include <linux/memcontrol.h>
26129  #include <linux/security.h>
26130 +#include <linux/vs_memory.h>
26131  
26132  int sysctl_panic_on_oom;
26133  int sysctl_oom_kill_allocating_task;
26134 @@ -72,6 +73,12 @@ unsigned long badness(struct task_struct
26135         points = mm->total_vm;
26136  
26137         /*
26138 +        * add points for context badness
26139 +        */
26140 +
26141 +       points += vx_badness(p, mm);
26142 +
26143 +       /*
26144          * After this unlock we can no longer dereference local variable `mm'
26145          */
26146         task_unlock(p);
26147 @@ -162,8 +169,8 @@ unsigned long badness(struct task_struct
26148         }
26149  
26150  #ifdef DEBUG
26151 -       printk(KERN_DEBUG "OOMkill: task %d (%s) got %lu points\n",
26152 -       p->pid, p->comm, points);
26153 +       printk(KERN_DEBUG "OOMkill: task %d:#%u (%s) got %d points\n",
26154 +               task_pid_nr(p), p->xid, p->comm, points);
26155  #endif
26156         return points;
26157  }
26158 @@ -326,8 +333,8 @@ static void __oom_kill_task(struct task_
26159         }
26160  
26161         if (verbose)
26162 -               printk(KERN_ERR "Killed process %d (%s)\n",
26163 -                               task_pid_nr(p), p->comm);
26164 +               printk(KERN_ERR "Killed process %d:#%u (%s)\n",
26165 +                               task_pid_nr(p), p->xid, p->comm);
26166  
26167         /*
26168          * We give our sacrificial lamb high priority and access to
26169 @@ -410,8 +417,8 @@ static int oom_kill_process(struct task_
26170                 return 0;
26171         }
26172  
26173 -       printk(KERN_ERR "%s: kill process %d (%s) score %li or a child\n",
26174 -                                       message, task_pid_nr(p), p->comm, points);
26175 +       printk(KERN_ERR "%s: kill process %d:#%u (%s) score %li or a child\n",
26176 +                               message, task_pid_nr(p), p->xid, p->comm, points);
26177  
26178         /* Try to kill a child first */
26179         list_for_each_entry(c, &p->children, sibling) {
26180 diff -NurpP --minimal linux-2.6.29.4/mm/page_alloc.c linux-2.6.29.4-vs2.3.0.36.14/mm/page_alloc.c
26181 --- linux-2.6.29.4/mm/page_alloc.c      2009-03-24 14:22:45.000000000 +0100
26182 +++ linux-2.6.29.4-vs2.3.0.36.14/mm/page_alloc.c        2009-03-24 14:48:36.000000000 +0100
26183 @@ -46,6 +46,8 @@
26184  #include <linux/page-isolation.h>
26185  #include <linux/page_cgroup.h>
26186  #include <linux/debugobjects.h>
26187 +#include <linux/vs_base.h>
26188 +#include <linux/vs_limit.h>
26189  
26190  #include <asm/tlbflush.h>
26191  #include <asm/div64.h>
26192 @@ -1839,6 +1841,9 @@ void si_meminfo(struct sysinfo *val)
26193         val->totalhigh = totalhigh_pages;
26194         val->freehigh = nr_free_highpages();
26195         val->mem_unit = PAGE_SIZE;
26196 +
26197 +       if (vx_flags(VXF_VIRT_MEM, 0))
26198 +               vx_vsi_meminfo(val);
26199  }
26200  
26201  EXPORT_SYMBOL(si_meminfo);
26202 @@ -1859,6 +1864,9 @@ void si_meminfo_node(struct sysinfo *val
26203         val->freehigh = 0;
26204  #endif
26205         val->mem_unit = PAGE_SIZE;
26206 +
26207 +       if (vx_flags(VXF_VIRT_MEM, 0))
26208 +               vx_vsi_meminfo(val);
26209  }
26210  #endif
26211  
26212 diff -NurpP --minimal linux-2.6.29.4/mm/rmap.c linux-2.6.29.4-vs2.3.0.36.14/mm/rmap.c
26213 --- linux-2.6.29.4/mm/rmap.c    2009-03-24 14:22:45.000000000 +0100
26214 +++ linux-2.6.29.4-vs2.3.0.36.14/mm/rmap.c      2009-03-24 18:26:27.000000000 +0100
26215 @@ -50,6 +50,7 @@
26216  #include <linux/memcontrol.h>
26217  #include <linux/mmu_notifier.h>
26218  #include <linux/migrate.h>
26219 +#include <linux/vs_memory.h>
26220  
26221  #include <asm/tlbflush.h>
26222  
26223 diff -NurpP --minimal linux-2.6.29.4/mm/shmem.c linux-2.6.29.4-vs2.3.0.36.14/mm/shmem.c
26224 --- linux-2.6.29.4/mm/shmem.c   2009-03-24 14:22:45.000000000 +0100
26225 +++ linux-2.6.29.4-vs2.3.0.36.14/mm/shmem.c     2009-03-24 14:48:36.000000000 +0100
26226 @@ -1757,7 +1757,7 @@ static int shmem_statfs(struct dentry *d
26227  {
26228         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
26229  
26230 -       buf->f_type = TMPFS_MAGIC;
26231 +       buf->f_type = TMPFS_SUPER_MAGIC;
26232         buf->f_bsize = PAGE_CACHE_SIZE;
26233         buf->f_namelen = NAME_MAX;
26234         spin_lock(&sbinfo->stat_lock);
26235 @@ -2326,7 +2326,7 @@ static int shmem_fill_super(struct super
26236         sb->s_maxbytes = SHMEM_MAX_BYTES;
26237         sb->s_blocksize = PAGE_CACHE_SIZE;
26238         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
26239 -       sb->s_magic = TMPFS_MAGIC;
26240 +       sb->s_magic = TMPFS_SUPER_MAGIC;
26241         sb->s_op = &shmem_ops;
26242         sb->s_time_gran = 1;
26243  #ifdef CONFIG_TMPFS_POSIX_ACL
26244 diff -NurpP --minimal linux-2.6.29.4/mm/slab.c linux-2.6.29.4-vs2.3.0.36.14/mm/slab.c
26245 --- linux-2.6.29.4/mm/slab.c    2009-03-24 14:22:45.000000000 +0100
26246 +++ linux-2.6.29.4-vs2.3.0.36.14/mm/slab.c      2009-03-24 14:48:36.000000000 +0100
26247 @@ -509,6 +509,8 @@ struct kmem_cache {
26248  #define STATS_INC_FREEMISS(x)  do { } while (0)
26249  #endif
26250  
26251 +#include "slab_vs.h"
26252 +
26253  #if DEBUG
26254  
26255  /*
26256 @@ -3275,6 +3277,7 @@ retry:
26257  
26258         obj = slab_get_obj(cachep, slabp, nodeid);
26259         check_slabp(cachep, slabp);
26260 +       vx_slab_alloc(cachep, flags);
26261         l3->free_objects--;
26262         /* move slabp to correct slabp list: */
26263         list_del(&slabp->list);
26264 @@ -3347,6 +3350,7 @@ __cache_alloc_node(struct kmem_cache *ca
26265         /* ___cache_alloc_node can fall back to other nodes */
26266         ptr = ____cache_alloc_node(cachep, flags, nodeid);
26267    out:
26268 +       vx_slab_alloc(cachep, flags);
26269         local_irq_restore(save_flags);
26270         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
26271  
26272 @@ -3518,6 +3522,7 @@ static inline void __cache_free(struct k
26273  
26274         check_irq_off();
26275         objp = cache_free_debugcheck(cachep, objp, __builtin_return_address(0));
26276 +       vx_slab_free(cachep);
26277  
26278         /*
26279          * Skip calling cache_free_alien() when the platform is not numa.
26280 diff -NurpP --minimal linux-2.6.29.4/mm/slab_vs.h linux-2.6.29.4-vs2.3.0.36.14/mm/slab_vs.h
26281 --- linux-2.6.29.4/mm/slab_vs.h 1970-01-01 01:00:00.000000000 +0100
26282 +++ linux-2.6.29.4-vs2.3.0.36.14/mm/slab_vs.h   2009-02-22 22:54:26.000000000 +0100
26283 @@ -0,0 +1,27 @@
26284 +
26285 +#include <linux/vserver/context.h>
26286 +
26287 +#include <linux/vs_context.h>
26288 +
26289 +static inline
26290 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
26291 +{
26292 +       int what = gfp_zone(cachep->gfpflags);
26293 +
26294 +       if (!current->vx_info)
26295 +               return;
26296 +
26297 +       atomic_add(cachep->buffer_size, &current->vx_info->cacct.slab[what]);
26298 +}
26299 +
26300 +static inline
26301 +void vx_slab_free(struct kmem_cache *cachep)
26302 +{
26303 +       int what = gfp_zone(cachep->gfpflags);
26304 +
26305 +       if (!current->vx_info)
26306 +               return;
26307 +
26308 +       atomic_sub(cachep->buffer_size, &current->vx_info->cacct.slab[what]);
26309 +}
26310 +
26311 diff -NurpP --minimal linux-2.6.29.4/mm/swapfile.c linux-2.6.29.4-vs2.3.0.36.14/mm/swapfile.c
26312 --- linux-2.6.29.4/mm/swapfile.c        2009-03-24 14:22:45.000000000 +0100
26313 +++ linux-2.6.29.4-vs2.3.0.36.14/mm/swapfile.c  2009-03-24 18:27:15.000000000 +0100
26314 @@ -34,6 +34,8 @@
26315  #include <asm/tlbflush.h>
26316  #include <linux/swapops.h>
26317  #include <linux/page_cgroup.h>
26318 +#include <linux/vs_base.h>
26319 +#include <linux/vs_memory.h>
26320  
26321  static DEFINE_SPINLOCK(swap_lock);
26322  static unsigned int nr_swapfiles;
26323 @@ -1935,6 +1937,8 @@ void si_swapinfo(struct sysinfo *val)
26324         val->freeswap = nr_swap_pages + nr_to_be_unused;
26325         val->totalswap = total_swap_pages + nr_to_be_unused;
26326         spin_unlock(&swap_lock);
26327 +       if (vx_flags(VXF_VIRT_MEM, 0))
26328 +               vx_vsi_swapinfo(val);
26329  }
26330  
26331  /*
26332 diff -NurpP --minimal linux-2.6.29.4/net/core/dev.c linux-2.6.29.4-vs2.3.0.36.14/net/core/dev.c
26333 --- linux-2.6.29.4/net/core/dev.c       2009-05-23 23:16:53.000000000 +0200
26334 +++ linux-2.6.29.4-vs2.3.0.36.14/net/core/dev.c 2009-04-15 22:58:30.000000000 +0200
26335 @@ -126,6 +126,7 @@
26336  #include <linux/in.h>
26337  #include <linux/jhash.h>
26338  #include <linux/random.h>
26339 +#include <linux/vs_inet.h>
26340  
26341  #include "net-sysfs.h"
26342  
26343 @@ -2853,6 +2854,8 @@ static int dev_ifconf(struct net *net, c
26344  
26345         total = 0;
26346         for_each_netdev(net, dev) {
26347 +               if (!nx_dev_visible(current->nx_info, dev))
26348 +                       continue;
26349                 for (i = 0; i < NPROTO; i++) {
26350                         if (gifconf_list[i]) {
26351                                 int done;
26352 @@ -2921,6 +2924,9 @@ static void dev_seq_printf_stats(struct 
26353  {
26354         const struct net_device_stats *stats = dev_get_stats(dev);
26355  
26356 +       if (!nx_dev_visible(current->nx_info, dev))
26357 +               return;
26358 +
26359         seq_printf(seq, "%6s:%8lu %7lu %4lu %4lu %4lu %5lu %10lu %9lu "
26360                    "%8lu %7lu %4lu %4lu %4lu %5lu %7lu %10lu\n",
26361                    dev->name, stats->rx_bytes, stats->rx_packets,
26362 @@ -4862,6 +4868,15 @@ int dev_change_net_namespace(struct net_
26363                 goto out;
26364  #endif
26365  
26366 +#ifdef CONFIG_SYSFS
26367 +       /* Don't allow real devices to be moved when sysfs
26368 +        * is enabled.
26369 +        */
26370 +       err = -EINVAL;
26371 +       if (dev->dev.parent)
26372 +               goto out;
26373 +#endif
26374 +
26375         /* Ensure the device has been registrered */
26376         err = -EINVAL;
26377         if (dev->reg_state != NETREG_REGISTERED)
26378 @@ -4921,6 +4936,8 @@ int dev_change_net_namespace(struct net_
26379  
26380         netdev_unregister_kobject(dev);
26381  
26382 +       netdev_unregister_kobject(dev);
26383 +
26384         /* Actually switch the network namespace */
26385         dev_net_set(dev, net);
26386  
26387 diff -NurpP --minimal linux-2.6.29.4/net/core/net-sysfs.c linux-2.6.29.4-vs2.3.0.36.14/net/core/net-sysfs.c
26388 --- linux-2.6.29.4/net/core/net-sysfs.c 2009-03-24 14:22:46.000000000 +0100
26389 +++ linux-2.6.29.4-vs2.3.0.36.14/net/core/net-sysfs.c   2009-03-24 18:30:01.000000000 +0100
26390 @@ -512,6 +512,9 @@ int netdev_register_kobject(struct net_d
26391         if (dev_net(net) != &init_net)
26392                 return 0;
26393  
26394 +       if (dev_net(net) != &init_net)
26395 +               return 0;
26396 +
26397         return device_add(dev);
26398  }
26399  
26400 diff -NurpP --minimal linux-2.6.29.4/net/core/rtnetlink.c linux-2.6.29.4-vs2.3.0.36.14/net/core/rtnetlink.c
26401 --- linux-2.6.29.4/net/core/rtnetlink.c 2009-03-24 14:22:46.000000000 +0100
26402 +++ linux-2.6.29.4-vs2.3.0.36.14/net/core/rtnetlink.c   2009-03-24 14:48:36.000000000 +0100
26403 @@ -690,6 +690,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
26404  
26405         idx = 0;
26406         for_each_netdev(net, dev) {
26407 +               if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
26408 +                       continue;
26409                 if (idx < s_idx)
26410                         goto cont;
26411                 if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
26412 @@ -1235,6 +1237,9 @@ void rtmsg_ifinfo(int type, struct net_d
26413         struct sk_buff *skb;
26414         int err = -ENOBUFS;
26415  
26416 +       if (!nx_dev_visible(current->nx_info, dev))
26417 +               return;
26418 +
26419         skb = nlmsg_new(if_nlmsg_size(dev), GFP_KERNEL);
26420         if (skb == NULL)
26421                 goto errout;
26422 diff -NurpP --minimal linux-2.6.29.4/net/core/sock.c linux-2.6.29.4-vs2.3.0.36.14/net/core/sock.c
26423 --- linux-2.6.29.4/net/core/sock.c      2009-03-24 14:22:46.000000000 +0100
26424 +++ linux-2.6.29.4-vs2.3.0.36.14/net/core/sock.c        2009-03-24 14:48:36.000000000 +0100
26425 @@ -124,6 +124,10 @@
26426  #include <linux/ipsec.h>
26427  
26428  #include <linux/filter.h>
26429 +#include <linux/vs_socket.h>
26430 +#include <linux/vs_limit.h>
26431 +#include <linux/vs_context.h>
26432 +#include <linux/vs_network.h>
26433  
26434  #ifdef CONFIG_INET
26435  #include <net/tcp.h>
26436 @@ -900,6 +904,8 @@ static struct sock *sk_prot_alloc(struct
26437                 if (!try_module_get(prot->owner))
26438                         goto out_free_sec;
26439         }
26440 +               sock_vx_init(sk);
26441 +               sock_nx_init(sk);
26442  
26443         return sk;
26444  
26445 @@ -976,6 +982,11 @@ void sk_free(struct sock *sk)
26446                        __func__, atomic_read(&sk->sk_omem_alloc));
26447  
26448         put_net(sock_net(sk));
26449 +       vx_sock_dec(sk);
26450 +       clr_vx_info(&sk->sk_vx_info);
26451 +       sk->sk_xid = -1;
26452 +       clr_nx_info(&sk->sk_nx_info);
26453 +       sk->sk_nid = -1;
26454         sk_prot_free(sk->sk_prot_creator, sk);
26455  }
26456  
26457 @@ -1011,6 +1022,8 @@ struct sock *sk_clone(const struct sock 
26458  
26459                 /* SANITY */
26460                 get_net(sock_net(newsk));
26461 +               sock_vx_init(newsk);
26462 +               sock_nx_init(newsk);
26463                 sk_node_init(&newsk->sk_node);
26464                 sock_lock_init(newsk);
26465                 bh_lock_sock(newsk);
26466 @@ -1057,6 +1070,12 @@ struct sock *sk_clone(const struct sock 
26467                 newsk->sk_priority = 0;
26468                 atomic_set(&newsk->sk_refcnt, 2);
26469  
26470 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
26471 +               newsk->sk_xid = sk->sk_xid;
26472 +               vx_sock_inc(newsk);
26473 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
26474 +               newsk->sk_nid = sk->sk_nid;
26475 +
26476                 /*
26477                  * Increment the counter in the same struct proto as the master
26478                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
26479 @@ -1744,6 +1763,11 @@ void sock_init_data(struct socket *sock,
26480  
26481         sk->sk_stamp = ktime_set(-1L, 0);
26482  
26483 +       set_vx_info(&sk->sk_vx_info, current->vx_info);
26484 +       sk->sk_xid = vx_current_xid();
26485 +       vx_sock_inc(sk);
26486 +       set_nx_info(&sk->sk_nx_info, current->nx_info);
26487 +       sk->sk_nid = nx_current_nid();
26488         atomic_set(&sk->sk_refcnt, 1);
26489         atomic_set(&sk->sk_drops, 0);
26490  }
26491 diff -NurpP --minimal linux-2.6.29.4/net/ipv4/af_inet.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/af_inet.c
26492 --- linux-2.6.29.4/net/ipv4/af_inet.c   2009-03-24 14:22:46.000000000 +0100
26493 +++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/af_inet.c     2009-03-24 14:48:37.000000000 +0100
26494 @@ -115,6 +115,7 @@
26495  #ifdef CONFIG_IP_MROUTE
26496  #include <linux/mroute.h>
26497  #endif
26498 +#include <linux/vs_limit.h>
26499  
26500  extern void ip_mc_drop_socket(struct sock *sk);
26501  
26502 @@ -325,9 +326,12 @@ lookup_protocol:
26503         }
26504  
26505         err = -EPERM;
26506 +       if ((protocol == IPPROTO_ICMP) &&
26507 +               nx_capable(answer->capability, NXC_RAW_ICMP))
26508 +               goto override;
26509         if (answer->capability > 0 && !capable(answer->capability))
26510                 goto out_rcu_unlock;
26511 -
26512 +override:
26513         err = -EAFNOSUPPORT;
26514         if (!inet_netns_ok(net, protocol))
26515                 goto out_rcu_unlock;
26516 @@ -445,6 +449,7 @@ int inet_bind(struct socket *sock, struc
26517         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
26518         struct sock *sk = sock->sk;
26519         struct inet_sock *inet = inet_sk(sk);
26520 +       struct nx_v4_sock_addr nsa;
26521         unsigned short snum;
26522         int chk_addr_ret;
26523         int err;
26524 @@ -458,7 +463,11 @@ int inet_bind(struct socket *sock, struc
26525         if (addr_len < sizeof(struct sockaddr_in))
26526                 goto out;
26527  
26528 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
26529 +       err = v4_map_sock_addr(inet, addr, &nsa);
26530 +       if (err)
26531 +               goto out;
26532 +
26533 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
26534  
26535         /* Not specified by any standard per-se, however it breaks too
26536          * many applications when removed.  It is unfortunate since
26537 @@ -470,7 +479,7 @@ int inet_bind(struct socket *sock, struc
26538         err = -EADDRNOTAVAIL;
26539         if (!sysctl_ip_nonlocal_bind &&
26540             !(inet->freebind || inet->transparent) &&
26541 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
26542 +           nsa.saddr != htonl(INADDR_ANY) &&
26543             chk_addr_ret != RTN_LOCAL &&
26544             chk_addr_ret != RTN_MULTICAST &&
26545             chk_addr_ret != RTN_BROADCAST)
26546 @@ -495,7 +504,7 @@ int inet_bind(struct socket *sock, struc
26547         if (sk->sk_state != TCP_CLOSE || inet->num)
26548                 goto out_release_sock;
26549  
26550 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
26551 +       v4_set_sock_addr(inet, &nsa);
26552         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
26553                 inet->saddr = 0;  /* Use device */
26554  
26555 @@ -688,11 +697,13 @@ int inet_getname(struct socket *sock, st
26556                      peer == 1))
26557                         return -ENOTCONN;
26558                 sin->sin_port = inet->dport;
26559 -               sin->sin_addr.s_addr = inet->daddr;
26560 +               sin->sin_addr.s_addr =
26561 +                       nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
26562         } else {
26563                 __be32 addr = inet->rcv_saddr;
26564                 if (!addr)
26565                         addr = inet->saddr;
26566 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
26567                 sin->sin_port = inet->sport;
26568                 sin->sin_addr.s_addr = addr;
26569         }
26570 diff -NurpP --minimal linux-2.6.29.4/net/ipv4/devinet.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/devinet.c
26571 --- linux-2.6.29.4/net/ipv4/devinet.c   2009-03-24 14:22:46.000000000 +0100
26572 +++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/devinet.c     2009-03-24 14:48:37.000000000 +0100
26573 @@ -413,6 +413,7 @@ struct in_device *inetdev_by_index(struc
26574         return in_dev;
26575  }
26576  
26577 +
26578  /* Called only from RTNL semaphored context. No locks. */
26579  
26580  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
26581 @@ -653,6 +654,8 @@ int devinet_ioctl(struct net *net, unsig
26582                 *colon = ':';
26583  
26584         if ((in_dev = __in_dev_get_rtnl(dev)) != NULL) {
26585 +               struct nx_info *nxi = current->nx_info;
26586 +
26587                 if (tryaddrmatch) {
26588                         /* Matthias Andree */
26589                         /* compare label and address (4.4BSD style) */
26590 @@ -661,6 +664,8 @@ int devinet_ioctl(struct net *net, unsig
26591                            This is checked above. */
26592                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
26593                              ifap = &ifa->ifa_next) {
26594 +                               if (!nx_v4_ifa_visible(nxi, ifa))
26595 +                                       continue;
26596                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
26597                                     sin_orig.sin_addr.s_addr ==
26598                                                         ifa->ifa_address) {
26599 @@ -673,9 +678,12 @@ int devinet_ioctl(struct net *net, unsig
26600                    comparing just the label */
26601                 if (!ifa) {
26602                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
26603 -                            ifap = &ifa->ifa_next)
26604 +                            ifap = &ifa->ifa_next) {
26605 +                               if (!nx_v4_ifa_visible(nxi, ifa))
26606 +                                       continue;
26607                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
26608                                         break;
26609 +                       }
26610                 }
26611         }
26612  
26613 @@ -826,6 +834,8 @@ static int inet_gifconf(struct net_devic
26614                 goto out;
26615  
26616         for (; ifa; ifa = ifa->ifa_next) {
26617 +               if (!nx_v4_ifa_visible(current->nx_info, ifa))
26618 +                       continue;
26619                 if (!buf) {
26620                         done += sizeof(ifr);
26621                         continue;
26622 @@ -1156,6 +1166,7 @@ static int inet_dump_ifaddr(struct sk_bu
26623         struct net_device *dev;
26624         struct in_device *in_dev;
26625         struct in_ifaddr *ifa;
26626 +       struct sock *sk = skb->sk;
26627         int s_ip_idx, s_idx = cb->args[0];
26628  
26629         s_ip_idx = ip_idx = cb->args[1];
26630 @@ -1170,6 +1181,8 @@ static int inet_dump_ifaddr(struct sk_bu
26631  
26632                 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
26633                      ifa = ifa->ifa_next, ip_idx++) {
26634 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
26635 +                               continue;
26636                         if (ip_idx < s_ip_idx)
26637                                 continue;
26638                         if (inet_fill_ifaddr(skb, ifa, NETLINK_CB(cb->skb).pid,
26639 diff -NurpP --minimal linux-2.6.29.4/net/ipv4/fib_hash.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/fib_hash.c
26640 --- linux-2.6.29.4/net/ipv4/fib_hash.c  2009-03-24 14:22:46.000000000 +0100
26641 +++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/fib_hash.c    2009-03-24 14:48:37.000000000 +0100
26642 @@ -1022,7 +1022,7 @@ static int fib_seq_show(struct seq_file 
26643         prefix  = f->fn_key;
26644         mask    = FZ_MASK(iter->zone);
26645         flags   = fib_flag_trans(fa->fa_type, mask, fi);
26646 -       if (fi)
26647 +       if (fi && nx_dev_visible(current->nx_info, fi->fib_dev))
26648                 seq_printf(seq,
26649                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u%n",
26650                          fi->fib_dev ? fi->fib_dev->name : "*", prefix,
26651 diff -NurpP --minimal linux-2.6.29.4/net/ipv4/inet_connection_sock.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/inet_connection_sock.c
26652 --- linux-2.6.29.4/net/ipv4/inet_connection_sock.c      2009-03-24 14:22:46.000000000 +0100
26653 +++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/inet_connection_sock.c        2009-03-24 14:48:37.000000000 +0100
26654 @@ -49,10 +49,40 @@ void inet_get_local_port_range(int *low,
26655  }
26656  EXPORT_SYMBOL(inet_get_local_port_range);
26657  
26658 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
26659 +{
26660 +       __be32  sk1_rcv_saddr = inet_rcv_saddr(sk1),
26661 +               sk2_rcv_saddr = inet_rcv_saddr(sk2);
26662 +
26663 +       if (inet_v6_ipv6only(sk2))
26664 +               return 0;
26665 +
26666 +       if (sk1_rcv_saddr &&
26667 +           sk2_rcv_saddr &&
26668 +           sk1_rcv_saddr == sk2_rcv_saddr)
26669 +               return 1;
26670 +
26671 +       if (sk1_rcv_saddr &&
26672 +           !sk2_rcv_saddr &&
26673 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
26674 +               return 1;
26675 +
26676 +       if (sk2_rcv_saddr &&
26677 +           !sk1_rcv_saddr &&
26678 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
26679 +               return 1;
26680 +
26681 +       if (!sk1_rcv_saddr &&
26682 +           !sk2_rcv_saddr &&
26683 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
26684 +               return 1;
26685 +
26686 +       return 0;
26687 +}
26688 +
26689  int inet_csk_bind_conflict(const struct sock *sk,
26690                            const struct inet_bind_bucket *tb)
26691  {
26692 -       const __be32 sk_rcv_saddr = inet_rcv_saddr(sk);
26693         struct sock *sk2;
26694         struct hlist_node *node;
26695         int reuse = sk->sk_reuse;
26696 @@ -72,9 +102,7 @@ int inet_csk_bind_conflict(const struct 
26697                      sk->sk_bound_dev_if == sk2->sk_bound_dev_if)) {
26698                         if (!reuse || !sk2->sk_reuse ||
26699                             sk2->sk_state == TCP_LISTEN) {
26700 -                               const __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
26701 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr ||
26702 -                                   sk2_rcv_saddr == sk_rcv_saddr)
26703 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
26704                                         break;
26705                         }
26706                 }
26707 diff -NurpP --minimal linux-2.6.29.4/net/ipv4/inet_diag.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/inet_diag.c
26708 --- linux-2.6.29.4/net/ipv4/inet_diag.c 2009-03-24 14:22:46.000000000 +0100
26709 +++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/inet_diag.c   2009-03-24 14:48:37.000000000 +0100
26710 @@ -32,6 +32,8 @@
26711  #include <linux/stddef.h>
26712  
26713  #include <linux/inet_diag.h>
26714 +#include <linux/vs_network.h>
26715 +#include <linux/vs_inet.h>
26716  
26717  static const struct inet_diag_handler **inet_diag_table;
26718  
26719 @@ -118,8 +120,8 @@ static int inet_csk_diag_fill(struct soc
26720  
26721         r->id.idiag_sport = inet->sport;
26722         r->id.idiag_dport = inet->dport;
26723 -       r->id.idiag_src[0] = inet->rcv_saddr;
26724 -       r->id.idiag_dst[0] = inet->daddr;
26725 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, inet->rcv_saddr);
26726 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, inet->daddr);
26727  
26728  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
26729         if (r->idiag_family == AF_INET6) {
26730 @@ -206,8 +208,8 @@ static int inet_twsk_diag_fill(struct in
26731         r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
26732         r->id.idiag_sport     = tw->tw_sport;
26733         r->id.idiag_dport     = tw->tw_dport;
26734 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
26735 -       r->id.idiag_dst[0]    = tw->tw_daddr;
26736 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
26737 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
26738         r->idiag_state        = tw->tw_substate;
26739         r->idiag_timer        = 3;
26740         r->idiag_expires      = DIV_ROUND_UP(tmo * 1000, HZ);
26741 @@ -264,6 +266,7 @@ static int inet_diag_get_exact(struct sk
26742         err = -EINVAL;
26743  
26744         if (req->idiag_family == AF_INET) {
26745 +               /* TODO: lback */
26746                 sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
26747                                  req->id.idiag_dport, req->id.idiag_src[0],
26748                                  req->id.idiag_sport, req->id.idiag_if);
26749 @@ -506,6 +509,7 @@ static int inet_csk_diag_dump(struct soc
26750                 } else
26751  #endif
26752                 {
26753 +                       /* TODO: lback */
26754                         entry.saddr = &inet->rcv_saddr;
26755                         entry.daddr = &inet->daddr;
26756                 }
26757 @@ -542,6 +546,7 @@ static int inet_twsk_diag_dump(struct in
26758                 } else
26759  #endif
26760                 {
26761 +                       /* TODO: lback */
26762                         entry.saddr = &tw->tw_rcv_saddr;
26763                         entry.daddr = &tw->tw_daddr;
26764                 }
26765 @@ -588,8 +593,8 @@ static int inet_diag_fill_req(struct sk_
26766  
26767         r->id.idiag_sport = inet->sport;
26768         r->id.idiag_dport = ireq->rmt_port;
26769 -       r->id.idiag_src[0] = ireq->loc_addr;
26770 -       r->id.idiag_dst[0] = ireq->rmt_addr;
26771 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
26772 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
26773         r->idiag_expires = jiffies_to_msecs(tmo);
26774         r->idiag_rqueue = 0;
26775         r->idiag_wqueue = 0;
26776 @@ -659,6 +664,7 @@ static int inet_diag_dump_reqs(struct sk
26777                                 continue;
26778  
26779                         if (bc) {
26780 +                               /* TODO: lback */
26781                                 entry.saddr =
26782  #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
26783                                         (entry.family == AF_INET6) ?
26784 @@ -729,6 +735,8 @@ static int inet_diag_dump(struct sk_buff
26785                         sk_nulls_for_each(sk, node, &ilb->head) {
26786                                 struct inet_sock *inet = inet_sk(sk);
26787  
26788 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26789 +                                       continue;
26790                                 if (num < s_num) {
26791                                         num++;
26792                                         continue;
26793 @@ -795,6 +803,8 @@ skip_listen_ht:
26794                 sk_nulls_for_each(sk, node, &head->chain) {
26795                         struct inet_sock *inet = inet_sk(sk);
26796  
26797 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26798 +                               continue;
26799                         if (num < s_num)
26800                                 goto next_normal;
26801                         if (!(r->idiag_states & (1 << sk->sk_state)))
26802 @@ -819,6 +829,8 @@ next_normal:
26803                         inet_twsk_for_each(tw, node,
26804                                     &head->twchain) {
26805  
26806 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
26807 +                                       continue;
26808                                 if (num < s_num)
26809                                         goto next_dying;
26810                                 if (r->id.idiag_sport != tw->tw_sport &&
26811 diff -NurpP --minimal linux-2.6.29.4/net/ipv4/inet_hashtables.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/inet_hashtables.c
26812 --- linux-2.6.29.4/net/ipv4/inet_hashtables.c   2009-03-24 14:22:46.000000000 +0100
26813 +++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/inet_hashtables.c     2009-04-17 15:35:48.000000000 +0200
26814 @@ -21,6 +21,7 @@
26815  
26816  #include <net/inet_connection_sock.h>
26817  #include <net/inet_hashtables.h>
26818 +#include <net/route.h>
26819  #include <net/ip.h>
26820  
26821  /*
26822 @@ -125,6 +126,11 @@ static inline int compute_score(struct s
26823                         if (rcv_saddr != daddr)
26824                                 return -1;
26825                         score += 2;
26826 +               } else {
26827 +                       /* block non nx_info ips */
26828 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
26829 +                               daddr, NXA_MASK_BIND))
26830 +                               return -1;
26831                 }
26832                 if (sk->sk_bound_dev_if) {
26833                         if (sk->sk_bound_dev_if != dif)
26834 @@ -142,7 +148,6 @@ static inline int compute_score(struct s
26835   * wildcarded during the search since they can never be otherwise.
26836   */
26837  
26838 -
26839  struct sock *__inet_lookup_listener(struct net *net,
26840                                     struct inet_hashinfo *hashinfo,
26841                                     const __be32 daddr, const unsigned short hnum,
26842 @@ -165,6 +170,7 @@ begin:
26843                         hiscore = score;
26844                 }
26845         }
26846 +
26847         /*
26848          * if the nulls value we got at the end of this lookup is
26849          * not the expected one, we must restart lookup.
26850 diff -NurpP --minimal linux-2.6.29.4/net/ipv4/netfilter/nf_nat_helper.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/netfilter/nf_nat_helper.c
26851 --- linux-2.6.29.4/net/ipv4/netfilter/nf_nat_helper.c   2008-12-25 00:26:37.000000000 +0100
26852 +++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/netfilter/nf_nat_helper.c     2009-02-22 22:54:26.000000000 +0100
26853 @@ -19,6 +19,7 @@
26854  #include <net/route.h>
26855  
26856  #include <linux/netfilter_ipv4.h>
26857 +#include <net/route.h>
26858  #include <net/netfilter/nf_conntrack.h>
26859  #include <net/netfilter/nf_conntrack_helper.h>
26860  #include <net/netfilter/nf_conntrack_ecache.h>
26861 diff -NurpP --minimal linux-2.6.29.4/net/ipv4/netfilter.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/netfilter.c
26862 --- linux-2.6.29.4/net/ipv4/netfilter.c 2009-03-24 14:22:46.000000000 +0100
26863 +++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/netfilter.c   2009-03-24 14:48:37.000000000 +0100
26864 @@ -4,7 +4,7 @@
26865  #include <linux/netfilter_ipv4.h>
26866  #include <linux/ip.h>
26867  #include <linux/skbuff.h>
26868 -#include <net/route.h>
26869 +// #include <net/route.h>
26870  #include <net/xfrm.h>
26871  #include <net/ip.h>
26872  #include <net/netfilter/nf_queue.h>
26873 diff -NurpP --minimal linux-2.6.29.4/net/ipv4/raw.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/raw.c
26874 --- linux-2.6.29.4/net/ipv4/raw.c       2009-03-24 14:22:46.000000000 +0100
26875 +++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/raw.c 2009-03-24 14:48:37.000000000 +0100
26876 @@ -117,7 +117,7 @@ static struct sock *__raw_v4_lookup(stru
26877  
26878                 if (net_eq(sock_net(sk), net) && inet->num == num       &&
26879                     !(inet->daddr && inet->daddr != raddr)              &&
26880 -                   !(inet->rcv_saddr && inet->rcv_saddr != laddr)      &&
26881 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
26882                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
26883                         goto found; /* gotcha */
26884         }
26885 @@ -372,6 +372,12 @@ static int raw_send_hdrinc(struct sock *
26886                 icmp_out_count(net, ((struct icmphdr *)
26887                         skb_transport_header(skb))->type);
26888  
26889 +       err = -EPERM;
26890 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
26891 +               sk->sk_nx_info &&
26892 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
26893 +               goto error_free;
26894 +
26895         err = NF_HOOK(PF_INET, NF_INET_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
26896                       dst_output);
26897         if (err > 0)
26898 @@ -383,6 +389,7 @@ out:
26899  
26900  error_fault:
26901         err = -EFAULT;
26902 +error_free:
26903         kfree_skb(skb);
26904  error:
26905         IP_INC_STATS(net, IPSTATS_MIB_OUTDISCARDS);
26906 @@ -550,6 +557,13 @@ static int raw_sendmsg(struct kiocb *ioc
26907                 }
26908  
26909                 security_sk_classify_flow(sk, &fl);
26910 +               if (sk->sk_nx_info) {
26911 +                       err = ip_v4_find_src(sock_net(sk),
26912 +                               sk->sk_nx_info, &rt, &fl);
26913 +
26914 +                       if (err)
26915 +                               goto done;
26916 +               }
26917                 err = ip_route_output_flow(sock_net(sk), &rt, &fl, sk, 1);
26918         }
26919         if (err)
26920 @@ -619,17 +633,19 @@ static int raw_bind(struct sock *sk, str
26921  {
26922         struct inet_sock *inet = inet_sk(sk);
26923         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
26924 +       struct nx_v4_sock_addr nsa = { 0 };
26925         int ret = -EINVAL;
26926         int chk_addr_ret;
26927  
26928         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
26929                 goto out;
26930 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
26931 +       v4_map_sock_addr(inet, addr, &nsa);
26932 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
26933         ret = -EADDRNOTAVAIL;
26934 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
26935 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
26936             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
26937                 goto out;
26938 -       inet->rcv_saddr = inet->saddr = addr->sin_addr.s_addr;
26939 +       v4_set_sock_addr(inet, &nsa);
26940         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
26941                 inet->saddr = 0;  /* Use device */
26942         sk_dst_reset(sk);
26943 @@ -681,7 +697,8 @@ static int raw_recvmsg(struct kiocb *ioc
26944         /* Copy the address. */
26945         if (sin) {
26946                 sin->sin_family = AF_INET;
26947 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
26948 +               sin->sin_addr.s_addr =
26949 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
26950                 sin->sin_port = 0;
26951                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
26952         }
26953 @@ -858,7 +875,8 @@ static struct sock *raw_get_first(struct
26954                 struct hlist_node *node;
26955  
26956                 sk_for_each(sk, node, &state->h->ht[state->bucket])
26957 -                       if (sock_net(sk) == seq_file_net(seq))
26958 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
26959 +                               nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
26960                                 goto found;
26961         }
26962         sk = NULL;
26963 @@ -874,7 +892,8 @@ static struct sock *raw_get_next(struct 
26964                 sk = sk_next(sk);
26965  try_again:
26966                 ;
26967 -       } while (sk && sock_net(sk) != seq_file_net(seq));
26968 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
26969 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
26970  
26971         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
26972                 sk = sk_head(&state->h->ht[state->bucket]);
26973 @@ -933,7 +952,10 @@ static void raw_sock_seq_show(struct seq
26974  
26975         seq_printf(seq, "%4d: %08X:%04X %08X:%04X"
26976                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d\n",
26977 -               i, src, srcp, dest, destp, sp->sk_state,
26978 +               i,
26979 +               nx_map_sock_lback(current_nx_info(), src), srcp,
26980 +               nx_map_sock_lback(current_nx_info(), dest), destp,
26981 +               sp->sk_state,
26982                 atomic_read(&sp->sk_wmem_alloc),
26983                 atomic_read(&sp->sk_rmem_alloc),
26984                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
26985 diff -NurpP --minimal linux-2.6.29.4/net/ipv4/tcp.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/tcp.c
26986 --- linux-2.6.29.4/net/ipv4/tcp.c       2009-03-24 14:22:46.000000000 +0100
26987 +++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/tcp.c 2009-03-24 14:48:37.000000000 +0100
26988 @@ -264,6 +264,7 @@
26989  #include <linux/cache.h>
26990  #include <linux/err.h>
26991  #include <linux/crypto.h>
26992 +#include <linux/in.h>
26993  
26994  #include <net/icmp.h>
26995  #include <net/tcp.h>
26996 diff -NurpP --minimal linux-2.6.29.4/net/ipv4/tcp_ipv4.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/tcp_ipv4.c
26997 --- linux-2.6.29.4/net/ipv4/tcp_ipv4.c  2009-05-23 23:16:53.000000000 +0200
26998 +++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/tcp_ipv4.c    2009-05-23 23:19:11.000000000 +0200
26999 @@ -1895,6 +1895,12 @@ static void *listening_get_next(struct s
27000                 req = req->dl_next;
27001                 while (1) {
27002                         while (req) {
27003 +                               vxdprintk(VXD_CBIT(net, 6),
27004 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
27005 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
27006 +                               if (req->sk &&
27007 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
27008 +                                       continue;
27009                                 if (req->rsk_ops->family == st->family) {
27010                                         cur = req;
27011                                         goto out;
27012 @@ -1919,6 +1925,10 @@ get_req:
27013         }
27014  get_sk:
27015         sk_nulls_for_each_from(sk, node) {
27016 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
27017 +                       sk, sk->sk_nid, nx_current_nid());
27018 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27019 +                       continue;
27020                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net)) {
27021                         cur = sk;
27022                         goto out;
27023 @@ -1982,6 +1992,11 @@ static void *established_get_first(struc
27024  
27025                 spin_lock_bh(lock);
27026                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
27027 +                       vxdprintk(VXD_CBIT(net, 6),
27028 +                               "sk,egf: %p [#%d] (from %d)",
27029 +                               sk, sk->sk_nid, nx_current_nid());
27030 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27031 +                               continue;
27032                         if (sk->sk_family != st->family ||
27033                             !net_eq(sock_net(sk), net)) {
27034                                 continue;
27035 @@ -1992,6 +2007,11 @@ static void *established_get_first(struc
27036                 st->state = TCP_SEQ_STATE_TIME_WAIT;
27037                 inet_twsk_for_each(tw, node,
27038                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
27039 +                       vxdprintk(VXD_CBIT(net, 6),
27040 +                               "tw: %p [#%d] (from %d)",
27041 +                               tw, tw->tw_nid, nx_current_nid());
27042 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
27043 +                               continue;
27044                         if (tw->tw_family != st->family ||
27045                             !net_eq(twsk_net(tw), net)) {
27046                                 continue;
27047 @@ -2020,7 +2040,9 @@ static void *established_get_next(struct
27048                 tw = cur;
27049                 tw = tw_next(tw);
27050  get_tw:
27051 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
27052 +               while (tw && (tw->tw_family != st->family ||
27053 +                       !net_eq(twsk_net(tw), net) ||
27054 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
27055                         tw = tw_next(tw);
27056                 }
27057                 if (tw) {
27058 @@ -2043,6 +2065,11 @@ get_tw:
27059                 sk = sk_nulls_next(sk);
27060  
27061         sk_nulls_for_each_from(sk, node) {
27062 +               vxdprintk(VXD_CBIT(net, 6),
27063 +                       "sk,egn: %p [#%d] (from %d)",
27064 +                       sk, sk->sk_nid, nx_current_nid());
27065 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27066 +                       continue;
27067                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
27068                         goto found;
27069         }
27070 @@ -2194,9 +2221,9 @@ static void get_openreq4(struct sock *sk
27071         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
27072                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p%n",
27073                 i,
27074 -               ireq->loc_addr,
27075 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
27076                 ntohs(inet_sk(sk)->sport),
27077 -               ireq->rmt_addr,
27078 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
27079                 ntohs(ireq->rmt_port),
27080                 TCP_SYN_RECV,
27081                 0, 0, /* could print option size, but that is af dependent. */
27082 @@ -2239,7 +2266,10 @@ static void get_tcp4_sock(struct sock *s
27083  
27084         seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
27085                         "%08X %5d %8d %lu %d %p %lu %lu %u %u %d%n",
27086 -               i, src, srcp, dest, destp, sk->sk_state,
27087 +               i,
27088 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27089 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27090 +               sk->sk_state,
27091                 tp->write_seq - tp->snd_una,
27092                 sk->sk_state == TCP_LISTEN ? sk->sk_ack_backlog :
27093                                              (tp->rcv_nxt - tp->copied_seq),
27094 @@ -2275,7 +2305,10 @@ static void get_timewait4_sock(struct in
27095  
27096         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
27097                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
27098 -               i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
27099 +               i,
27100 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27101 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27102 +               tw->tw_substate, 0, 0,
27103                 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
27104                 atomic_read(&tw->tw_refcnt), tw, len);
27105  }
27106 diff -NurpP --minimal linux-2.6.29.4/net/ipv4/tcp_minisocks.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/tcp_minisocks.c
27107 --- linux-2.6.29.4/net/ipv4/tcp_minisocks.c     2009-03-24 14:22:46.000000000 +0100
27108 +++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/tcp_minisocks.c       2009-03-24 14:48:37.000000000 +0100
27109 @@ -26,6 +26,10 @@
27110  #include <net/inet_common.h>
27111  #include <net/xfrm.h>
27112  
27113 +#include <linux/vs_limit.h>
27114 +#include <linux/vs_socket.h>
27115 +#include <linux/vs_context.h>
27116 +
27117  #ifdef CONFIG_SYSCTL
27118  #define SYNC_INIT 0 /* let the user enable it */
27119  #else
27120 @@ -293,6 +297,11 @@ void tcp_time_wait(struct sock *sk, int 
27121                 tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
27122                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
27123  
27124 +               tw->tw_xid              = sk->sk_xid;
27125 +               tw->tw_vx_info          = NULL;
27126 +               tw->tw_nid              = sk->sk_nid;
27127 +               tw->tw_nx_info          = NULL;
27128 +
27129  #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
27130                 if (tw->tw_family == PF_INET6) {
27131                         struct ipv6_pinfo *np = inet6_sk(sk);
27132 diff -NurpP --minimal linux-2.6.29.4/net/ipv4/udp.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/udp.c
27133 --- linux-2.6.29.4/net/ipv4/udp.c       2009-05-23 23:16:53.000000000 +0200
27134 +++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv4/udp.c 2009-04-15 22:58:30.000000000 +0200
27135 @@ -222,14 +222,7 @@ fail:
27136         return error;
27137  }
27138  
27139 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
27140 -{
27141 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
27142 -
27143 -       return  ( !ipv6_only_sock(sk2)  &&
27144 -                 (!inet1->rcv_saddr || !inet2->rcv_saddr ||
27145 -                  inet1->rcv_saddr == inet2->rcv_saddr      ));
27146 -}
27147 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
27148  
27149  int udp_v4_get_port(struct sock *sk, unsigned short snum)
27150  {
27151 @@ -251,6 +244,11 @@ static inline int compute_score(struct s
27152                         if (inet->rcv_saddr != daddr)
27153                                 return -1;
27154                         score += 2;
27155 +               } else {
27156 +                       /* block non nx_info ips */
27157 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
27158 +                               daddr, NXA_MASK_BIND))
27159 +                               return -1;
27160                 }
27161                 if (inet->daddr) {
27162                         if (inet->daddr != saddr)
27163 @@ -271,6 +269,7 @@ static inline int compute_score(struct s
27164         return score;
27165  }
27166  
27167 +
27168  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
27169   * harder than this. -DaveM
27170   */
27171 @@ -292,6 +291,11 @@ begin:
27172         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
27173                 score = compute_score(sk, net, saddr, hnum, sport,
27174                                       daddr, dport, dif);
27175 +               /* FIXME: disabled?
27176 +               if (score == 9) {
27177 +                       result = sk;
27178 +                       break;
27179 +               } else */
27180                 if (score > badness) {
27181                         result = sk;
27182                         badness = score;
27183 @@ -305,6 +309,7 @@ begin:
27184         if (get_nulls_value(node) != hash)
27185                 goto begin;
27186  
27187 +
27188         if (result) {
27189                 if (unlikely(!atomic_inc_not_zero(&result->sk_refcnt)))
27190                         result = NULL;
27191 @@ -314,6 +319,7 @@ begin:
27192                         goto begin;
27193                 }
27194         }
27195 +
27196         rcu_read_unlock();
27197         return result;
27198  }
27199 @@ -356,7 +362,7 @@ static inline struct sock *udp_v4_mcast_
27200                     s->sk_hash != hnum                                  ||
27201                     (inet->daddr && inet->daddr != rmt_addr)            ||
27202                     (inet->dport != rmt_port && inet->dport)            ||
27203 -                   (inet->rcv_saddr && inet->rcv_saddr != loc_addr)    ||
27204 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
27205                     ipv6_only_sock(s)                                   ||
27206                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
27207                         continue;
27208 @@ -694,8 +700,13 @@ int udp_sendmsg(struct kiocb *iocb, stru
27209                                                { .sport = inet->sport,
27210                                                  .dport = dport } } };
27211                 struct net *net = sock_net(sk);
27212 +               struct nx_info *nxi = sk->sk_nx_info;
27213  
27214                 security_sk_classify_flow(sk, &fl);
27215 +               err = ip_v4_find_src(net, nxi, &rt, &fl);
27216 +               if (err)
27217 +                       goto out;
27218 +
27219                 err = ip_route_output_flow(net, &rt, &fl, sk, 1);
27220                 if (err) {
27221                         if (err == -ENETUNREACH)
27222 @@ -940,7 +951,8 @@ try_again:
27223         {
27224                 sin->sin_family = AF_INET;
27225                 sin->sin_port = udp_hdr(skb)->source;
27226 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
27227 +               sin->sin_addr.s_addr = nx_map_sock_lback(
27228 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
27229                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
27230         }
27231         if (inet->cmsg_flags)
27232 @@ -1594,6 +1606,8 @@ static struct sock *udp_get_first(struct
27233                 sk_nulls_for_each(sk, node, &hslot->head) {
27234                         if (!net_eq(sock_net(sk), net))
27235                                 continue;
27236 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
27237 +                               continue;
27238                         if (sk->sk_family == state->family)
27239                                 goto found;
27240                 }
27241 @@ -1611,7 +1625,9 @@ static struct sock *udp_get_next(struct 
27242  
27243         do {
27244                 sk = sk_nulls_next(sk);
27245 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
27246 +       } while (sk && (!net_eq(sock_net(sk), net) ||
27247 +               sk->sk_family != state->family ||
27248 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
27249  
27250         if (!sk) {
27251                 if (state->bucket < UDP_HTABLE_SIZE)
27252 @@ -1716,7 +1732,10 @@ static void udp4_format_sock(struct sock
27253  
27254         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
27255                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p %d%n",
27256 -               bucket, src, srcp, dest, destp, sp->sk_state,
27257 +               bucket,
27258 +               nx_map_sock_lback(current_nx_info(), src), srcp,
27259 +               nx_map_sock_lback(current_nx_info(), dest), destp,
27260 +               sp->sk_state,
27261                 atomic_read(&sp->sk_wmem_alloc),
27262                 atomic_read(&sp->sk_rmem_alloc),
27263                 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
27264 diff -NurpP --minimal linux-2.6.29.4/net/ipv6/addrconf.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/addrconf.c
27265 --- linux-2.6.29.4/net/ipv6/addrconf.c  2009-03-24 14:22:46.000000000 +0100
27266 +++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/addrconf.c    2009-03-24 20:39:23.000000000 +0100
27267 @@ -85,6 +85,8 @@
27268  
27269  #include <linux/proc_fs.h>
27270  #include <linux/seq_file.h>
27271 +#include <linux/vs_network.h>
27272 +#include <linux/vs_inet6.h>
27273  
27274  /* Set to 3 to get tracing... */
27275  #define ACONF_DEBUG 2
27276 @@ -1111,7 +1113,7 @@ out:
27277  
27278  int ipv6_dev_get_saddr(struct net *net, struct net_device *dst_dev,
27279                        const struct in6_addr *daddr, unsigned int prefs,
27280 -                      struct in6_addr *saddr)
27281 +                      struct in6_addr *saddr, struct nx_info *nxi)
27282  {
27283         struct ipv6_saddr_score scores[2],
27284                                 *score = &scores[0], *hiscore = &scores[1];
27285 @@ -1184,6 +1186,8 @@ int ipv6_dev_get_saddr(struct net *net, 
27286                                                dev->name);
27287                                 continue;
27288                         }
27289 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
27290 +                               continue;
27291  
27292                         score->rule = -1;
27293                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
27294 @@ -1367,35 +1371,46 @@ struct inet6_ifaddr *ipv6_get_ifaddr(str
27295         return ifp;
27296  }
27297  
27298 +extern int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2);
27299 +
27300  int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
27301  {
27302         const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
27303         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
27304 -       __be32 sk_rcv_saddr = inet_sk(sk)->rcv_saddr;
27305         __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
27306         int sk_ipv6only = ipv6_only_sock(sk);
27307         int sk2_ipv6only = inet_v6_ipv6only(sk2);
27308         int addr_type = ipv6_addr_type(sk_rcv_saddr6);
27309         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
27310  
27311 -       if (!sk2_rcv_saddr && !sk_ipv6only)
27312 +       /* FIXME: needs handling for v4 ANY */
27313 +       if (!sk2_rcv_saddr && !sk_ipv6only && !sk2->sk_nx_info)
27314                 return 1;
27315  
27316         if (addr_type2 == IPV6_ADDR_ANY &&
27317 -           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
27318 +           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED) &&
27319 +           v6_addr_in_nx_info(sk2->sk_nx_info, sk_rcv_saddr6, -1))
27320                 return 1;
27321  
27322         if (addr_type == IPV6_ADDR_ANY &&
27323 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
27324 +           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED) &&
27325 +           (sk2_rcv_saddr6 && v6_addr_in_nx_info(sk->sk_nx_info, sk2_rcv_saddr6, -1)))
27326 +               return 1;
27327 +
27328 +       if (addr_type == IPV6_ADDR_ANY &&
27329 +           addr_type2 == IPV6_ADDR_ANY &&
27330 +           nx_v6_addr_conflict(sk->sk_nx_info, sk2->sk_nx_info))
27331                 return 1;
27332  
27333         if (sk2_rcv_saddr6 &&
27334 +           addr_type != IPV6_ADDR_ANY &&
27335 +           addr_type != IPV6_ADDR_ANY &&
27336             ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
27337                 return 1;
27338  
27339         if (addr_type == IPV6_ADDR_MAPPED &&
27340             !sk2_ipv6only &&
27341 -           (!sk2_rcv_saddr || !sk_rcv_saddr || sk_rcv_saddr == sk2_rcv_saddr))
27342 +           ipv4_rcv_saddr_equal(sk, sk2))
27343                 return 1;
27344  
27345         return 0;
27346 @@ -2993,7 +3008,10 @@ static void if6_seq_stop(struct seq_file
27347  static int if6_seq_show(struct seq_file *seq, void *v)
27348  {
27349         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
27350 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
27351 +
27352 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
27353 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
27354 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
27355                    &ifp->addr,
27356                    ifp->idev->dev->ifindex,
27357                    ifp->prefix_len,
27358 @@ -3487,6 +3505,12 @@ static int inet6_dump_addr(struct sk_buf
27359         struct ifmcaddr6 *ifmca;
27360         struct ifacaddr6 *ifaca;
27361         struct net *net = sock_net(skb->sk);
27362 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
27363 +
27364 +       /* disable ipv6 on non v6 guests */
27365 +       if (nxi && !nx_info_has_v6(nxi))
27366 +               return skb->len;
27367 +
27368  
27369         s_idx = cb->args[0];
27370         s_ip_idx = ip_idx = cb->args[1];
27371 @@ -3508,6 +3532,8 @@ static int inet6_dump_addr(struct sk_buf
27372                              ifa = ifa->if_next, ip_idx++) {
27373                                 if (ip_idx < s_ip_idx)
27374                                         continue;
27375 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
27376 +                                       continue;
27377                                 err = inet6_fill_ifaddr(skb, ifa,
27378                                                         NETLINK_CB(cb->skb).pid,
27379                                                         cb->nlh->nlmsg_seq,
27380 @@ -3521,6 +3547,8 @@ static int inet6_dump_addr(struct sk_buf
27381                              ifmca = ifmca->next, ip_idx++) {
27382                                 if (ip_idx < s_ip_idx)
27383                                         continue;
27384 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
27385 +                                       continue;
27386                                 err = inet6_fill_ifmcaddr(skb, ifmca,
27387                                                           NETLINK_CB(cb->skb).pid,
27388                                                           cb->nlh->nlmsg_seq,
27389 @@ -3534,6 +3562,8 @@ static int inet6_dump_addr(struct sk_buf
27390                              ifaca = ifaca->aca_next, ip_idx++) {
27391                                 if (ip_idx < s_ip_idx)
27392                                         continue;
27393 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
27394 +                                       continue;
27395                                 err = inet6_fill_ifacaddr(skb, ifaca,
27396                                                           NETLINK_CB(cb->skb).pid,
27397                                                           cb->nlh->nlmsg_seq,
27398 @@ -3819,12 +3849,19 @@ static int inet6_dump_ifinfo(struct sk_b
27399         int s_idx = cb->args[0];
27400         struct net_device *dev;
27401         struct inet6_dev *idev;
27402 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
27403 +
27404 +       /* FIXME: maybe disable ipv6 on non v6 guests?
27405 +       if (skb->sk && skb->sk->sk_vx_info)
27406 +               return skb->len; */
27407  
27408         read_lock(&dev_base_lock);
27409         idx = 0;
27410         for_each_netdev(net, dev) {
27411                 if (idx < s_idx)
27412                         goto cont;
27413 +               if (!v6_dev_in_nx_info(dev, nxi))
27414 +                       goto cont;
27415                 if ((idev = in6_dev_get(dev)) == NULL)
27416                         goto cont;
27417                 err = inet6_fill_ifinfo(skb, idev, NETLINK_CB(cb->skb).pid,
27418 diff -NurpP --minimal linux-2.6.29.4/net/ipv6/af_inet6.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/af_inet6.c
27419 --- linux-2.6.29.4/net/ipv6/af_inet6.c  2009-03-24 14:22:46.000000000 +0100
27420 +++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/af_inet6.c    2009-03-24 14:48:37.000000000 +0100
27421 @@ -41,6 +41,8 @@
27422  #include <linux/netdevice.h>
27423  #include <linux/icmpv6.h>
27424  #include <linux/netfilter_ipv6.h>
27425 +#include <linux/vs_inet.h>
27426 +#include <linux/vs_inet6.h>
27427  
27428  #include <net/ip.h>
27429  #include <net/ipv6.h>
27430 @@ -49,6 +51,7 @@
27431  #include <net/tcp.h>
27432  #include <net/ipip.h>
27433  #include <net/protocol.h>
27434 +#include <net/route.h>
27435  #include <net/inet_common.h>
27436  #include <net/route.h>
27437  #include <net/transp_v6.h>
27438 @@ -146,9 +149,12 @@ lookup_protocol:
27439         }
27440  
27441         err = -EPERM;
27442 +       if ((protocol == IPPROTO_ICMPV6) &&
27443 +               nx_capable(answer->capability, NXC_RAW_ICMP))
27444 +               goto override;
27445         if (answer->capability > 0 && !capable(answer->capability))
27446                 goto out_rcu_unlock;
27447 -
27448 +override:
27449         sock->ops = answer->ops;
27450         answer_prot = answer->prot;
27451         answer_no_check = answer->no_check;
27452 @@ -247,6 +253,7 @@ int inet6_bind(struct socket *sock, stru
27453         struct inet_sock *inet = inet_sk(sk);
27454         struct ipv6_pinfo *np = inet6_sk(sk);
27455         struct net *net = sock_net(sk);
27456 +       struct nx_v6_sock_addr nsa;
27457         __be32 v4addr = 0;
27458         unsigned short snum;
27459         int addr_type = 0;
27460 @@ -258,6 +265,11 @@ int inet6_bind(struct socket *sock, stru
27461  
27462         if (addr_len < SIN6_LEN_RFC2133)
27463                 return -EINVAL;
27464 +
27465 +       err = v6_map_sock_addr(inet, addr, &nsa);
27466 +       if (err)
27467 +               return err;
27468 +
27469         addr_type = ipv6_addr_type(&addr->sin6_addr);
27470         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
27471                 return -EINVAL;
27472 @@ -281,6 +293,10 @@ int inet6_bind(struct socket *sock, stru
27473                         err = -EADDRNOTAVAIL;
27474                         goto out;
27475                 }
27476 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
27477 +                       err = -EADDRNOTAVAIL;
27478 +                       goto out;
27479 +               }
27480         } else {
27481                 if (addr_type != IPV6_ADDR_ANY) {
27482                         struct net_device *dev = NULL;
27483 @@ -306,6 +322,11 @@ int inet6_bind(struct socket *sock, stru
27484                                 }
27485                         }
27486  
27487 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
27488 +                               err = -EADDRNOTAVAIL;
27489 +                               goto out;
27490 +                       }
27491 +
27492                         /* ipv4 addr of the socket is invalid.  Only the
27493                          * unspecified and mapped address have a v4 equivalent.
27494                          */
27495 @@ -324,6 +345,8 @@ int inet6_bind(struct socket *sock, stru
27496                 }
27497         }
27498  
27499 +       v6_set_sock_addr(inet, &nsa);
27500 +
27501         inet->rcv_saddr = v4addr;
27502         inet->saddr = v4addr;
27503  
27504 @@ -416,9 +439,11 @@ int inet6_getname(struct socket *sock, s
27505                         return -ENOTCONN;
27506                 sin->sin6_port = inet->dport;
27507                 ipv6_addr_copy(&sin->sin6_addr, &np->daddr);
27508 +               /* FIXME: remap lback? */
27509                 if (np->sndflow)
27510                         sin->sin6_flowinfo = np->flow_label;
27511         } else {
27512 +               /* FIXME: remap lback? */
27513                 if (ipv6_addr_any(&np->rcv_saddr))
27514                         ipv6_addr_copy(&sin->sin6_addr, &np->saddr);
27515                 else
27516 diff -NurpP --minimal linux-2.6.29.4/net/ipv6/fib6_rules.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/fib6_rules.c
27517 --- linux-2.6.29.4/net/ipv6/fib6_rules.c        2008-12-25 00:26:37.000000000 +0100
27518 +++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/fib6_rules.c  2009-02-22 22:54:26.000000000 +0100
27519 @@ -96,7 +96,7 @@ static int fib6_rule_action(struct fib_r
27520                         if (ipv6_dev_get_saddr(net,
27521                                                ip6_dst_idev(&rt->u.dst)->dev,
27522                                                &flp->fl6_dst, srcprefs,
27523 -                                              &saddr))
27524 +                                              &saddr, NULL))
27525                                 goto again;
27526                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
27527                                                r->src.plen))
27528 diff -NurpP --minimal linux-2.6.29.4/net/ipv6/inet6_hashtables.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/inet6_hashtables.c
27529 --- linux-2.6.29.4/net/ipv6/inet6_hashtables.c  2009-03-24 14:22:46.000000000 +0100
27530 +++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/inet6_hashtables.c    2009-03-24 20:50:24.000000000 +0100
27531 @@ -16,6 +16,7 @@
27532  
27533  #include <linux/module.h>
27534  #include <linux/random.h>
27535 +#include <linux/vs_inet6.h>
27536  
27537  #include <net/inet_connection_sock.h>
27538  #include <net/inet_hashtables.h>
27539 @@ -76,7 +77,6 @@ struct sock *__inet6_lookup_established(
27540         unsigned int slot = hash & (hashinfo->ehash_size - 1);
27541         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
27542  
27543 -
27544         rcu_read_lock();
27545  begin:
27546         sk_nulls_for_each_rcu(sk, node, &head->chain) {
27547 @@ -88,7 +88,7 @@ begin:
27548                                 sock_put(sk);
27549                                 goto begin;
27550                         }
27551 -               goto out;
27552 +                       goto out;
27553                 }
27554         }
27555         if (get_nulls_value(node) != slot)
27556 @@ -134,6 +134,9 @@ static int inline compute_score(struct s
27557                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
27558                                 return -1;
27559                         score++;
27560 +               } else {
27561 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
27562 +                               return -1;
27563                 }
27564                 if (sk->sk_bound_dev_if) {
27565                         if (sk->sk_bound_dev_if != dif)
27566 diff -NurpP --minimal linux-2.6.29.4/net/ipv6/ip6_output.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/ip6_output.c
27567 --- linux-2.6.29.4/net/ipv6/ip6_output.c        2009-03-24 14:22:47.000000000 +0100
27568 +++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/ip6_output.c  2009-03-24 14:48:37.000000000 +0100
27569 @@ -951,7 +951,7 @@ static int ip6_dst_lookup_tail(struct so
27570                 err = ipv6_dev_get_saddr(net, ip6_dst_idev(*dst)->dev,
27571                                          &fl->fl6_dst,
27572                                          sk ? inet6_sk(sk)->srcprefs : 0,
27573 -                                        &fl->fl6_src);
27574 +                                        &fl->fl6_src, sk->sk_nx_info);
27575                 if (err)
27576                         goto out_err_release;
27577         }
27578 diff -NurpP --minimal linux-2.6.29.4/net/ipv6/Kconfig linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/Kconfig
27579 --- linux-2.6.29.4/net/ipv6/Kconfig     2008-12-25 00:26:37.000000000 +0100
27580 +++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/Kconfig       2009-02-22 22:54:26.000000000 +0100
27581 @@ -4,8 +4,8 @@
27582  
27583  #   IPv6 as module will cause a CRASH if you try to unload it
27584  menuconfig IPV6
27585 -       tristate "The IPv6 protocol"
27586 -       default m
27587 +       bool "The IPv6 protocol"
27588 +       default n
27589         ---help---
27590           This is complemental support for the IP version 6.
27591           You will still be able to do traditional IPv4 networking as well.
27592 diff -NurpP --minimal linux-2.6.29.4/net/ipv6/ndisc.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/ndisc.c
27593 --- linux-2.6.29.4/net/ipv6/ndisc.c     2009-03-24 14:22:47.000000000 +0100
27594 +++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/ndisc.c       2009-03-24 14:48:37.000000000 +0100
27595 @@ -589,7 +589,7 @@ static void ndisc_send_na(struct net_dev
27596         } else {
27597                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
27598                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
27599 -                                      &tmpaddr))
27600 +                                      &tmpaddr, NULL /* FIXME: ? */ ))
27601                         return;
27602                 src_addr = &tmpaddr;
27603         }
27604 diff -NurpP --minimal linux-2.6.29.4/net/ipv6/raw.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/raw.c
27605 --- linux-2.6.29.4/net/ipv6/raw.c       2009-03-24 14:22:47.000000000 +0100
27606 +++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/raw.c 2009-03-24 14:48:37.000000000 +0100
27607 @@ -29,6 +29,7 @@
27608  #include <linux/icmpv6.h>
27609  #include <linux/netfilter.h>
27610  #include <linux/netfilter_ipv6.h>
27611 +#include <linux/vs_inet6.h>
27612  #include <linux/skbuff.h>
27613  #include <asm/uaccess.h>
27614  #include <asm/ioctls.h>
27615 @@ -281,6 +282,13 @@ static int rawv6_bind(struct sock *sk, s
27616                         }
27617                 }
27618  
27619 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
27620 +                       err = -EADDRNOTAVAIL;
27621 +                       if (dev)
27622 +                               dev_put(dev);
27623 +                       goto out;
27624 +               }
27625 +
27626                 /* ipv4 addr of the socket is invalid.  Only the
27627                  * unspecified and mapped address have a v4 equivalent.
27628                  */
27629 diff -NurpP --minimal linux-2.6.29.4/net/ipv6/route.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/route.c
27630 --- linux-2.6.29.4/net/ipv6/route.c     2009-03-24 14:22:47.000000000 +0100
27631 +++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/route.c       2009-03-24 14:48:37.000000000 +0100
27632 @@ -2254,7 +2254,8 @@ static int rt6_fill_node(struct net *net
27633                 struct inet6_dev *idev = ip6_dst_idev(&rt->u.dst);
27634                 struct in6_addr saddr_buf;
27635                 if (ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
27636 -                                      dst, 0, &saddr_buf) == 0)
27637 +                       dst, 0, &saddr_buf,
27638 +                       (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0)
27639                         NLA_PUT(skb, RTA_PREFSRC, 16, &saddr_buf);
27640         }
27641  
27642 diff -NurpP --minimal linux-2.6.29.4/net/ipv6/tcp_ipv6.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/tcp_ipv6.c
27643 --- linux-2.6.29.4/net/ipv6/tcp_ipv6.c  2009-03-24 14:22:47.000000000 +0100
27644 +++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/tcp_ipv6.c    2009-03-24 14:48:37.000000000 +0100
27645 @@ -68,6 +68,7 @@
27646  
27647  #include <linux/crypto.h>
27648  #include <linux/scatterlist.h>
27649 +#include <linux/vs_inet6.h>
27650  
27651  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
27652  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
27653 @@ -156,8 +157,15 @@ static int tcp_v6_connect(struct sock *s
27654          *      connect() to INADDR_ANY means loopback (BSD'ism).
27655          */
27656  
27657 -       if(ipv6_addr_any(&usin->sin6_addr))
27658 -               usin->sin6_addr.s6_addr[15] = 0x1;
27659 +       if(ipv6_addr_any(&usin->sin6_addr)) {
27660 +               struct nx_info *nxi =  sk->sk_nx_info;
27661 +
27662 +               if (nxi && nx_info_has_v6(nxi))
27663 +                       /* FIXME: remap lback? */
27664 +                       usin->sin6_addr = nxi->v6.ip;
27665 +               else
27666 +                       usin->sin6_addr.s6_addr[15] = 0x1;
27667 +       }
27668  
27669         addr_type = ipv6_addr_type(&usin->sin6_addr);
27670  
27671 diff -NurpP --minimal linux-2.6.29.4/net/ipv6/udp.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/udp.c
27672 --- linux-2.6.29.4/net/ipv6/udp.c       2009-03-24 14:22:47.000000000 +0100
27673 +++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/udp.c 2009-03-24 20:56:49.000000000 +0100
27674 @@ -47,6 +47,7 @@
27675  
27676  #include <linux/proc_fs.h>
27677  #include <linux/seq_file.h>
27678 +#include <linux/vs_inet6.h>
27679  #include "udp_impl.h"
27680  
27681  int udp_v6_get_port(struct sock *sk, unsigned short snum)
27682 @@ -77,6 +78,10 @@ static inline int compute_score(struct s
27683                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
27684                                 return -1;
27685                         score++;
27686 +               } else {
27687 +                       /* block non nx_info ips */
27688 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
27689 +                               return -1;
27690                 }
27691                 if (!ipv6_addr_any(&np->daddr)) {
27692                         if (!ipv6_addr_equal(&np->daddr, saddr))
27693 diff -NurpP --minimal linux-2.6.29.4/net/ipv6/xfrm6_policy.c linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/xfrm6_policy.c
27694 --- linux-2.6.29.4/net/ipv6/xfrm6_policy.c      2009-03-24 14:22:47.000000000 +0100
27695 +++ linux-2.6.29.4-vs2.3.0.36.14/net/ipv6/xfrm6_policy.c        2009-03-24 14:48:37.000000000 +0100
27696 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
27697         dev = ip6_dst_idev(dst)->dev;
27698         ipv6_dev_get_saddr(dev_net(dev), dev,
27699                            (struct in6_addr *)&daddr->a6, 0,
27700 -                          (struct in6_addr *)&saddr->a6);
27701 +                          (struct in6_addr *)&saddr->a6, NULL);
27702         dst_release(dst);
27703         return 0;
27704  }
27705 diff -NurpP --minimal linux-2.6.29.4/net/netlink/af_netlink.c linux-2.6.29.4-vs2.3.0.36.14/net/netlink/af_netlink.c
27706 --- linux-2.6.29.4/net/netlink/af_netlink.c     2009-03-24 14:22:47.000000000 +0100
27707 +++ linux-2.6.29.4-vs2.3.0.36.14/net/netlink/af_netlink.c       2009-03-24 14:48:37.000000000 +0100
27708 @@ -55,6 +55,9 @@
27709  #include <linux/types.h>
27710  #include <linux/audit.h>
27711  #include <linux/mutex.h>
27712 +#include <linux/vs_context.h>
27713 +#include <linux/vs_network.h>
27714 +#include <linux/vs_limit.h>
27715  
27716  #include <net/net_namespace.h>
27717  #include <net/sock.h>
27718 @@ -1776,6 +1779,8 @@ static struct sock *netlink_seq_socket_i
27719                         sk_for_each(s, node, &hash->table[j]) {
27720                                 if (sock_net(s) != seq_file_net(seq))
27721                                         continue;
27722 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
27723 +                                       continue;
27724                                 if (off == pos) {
27725                                         iter->link = i;
27726                                         iter->hash_idx = j;
27727 @@ -1810,7 +1815,8 @@ static void *netlink_seq_next(struct seq
27728         s = v;
27729         do {
27730                 s = sk_next(s);
27731 -       } while (s && sock_net(s) != seq_file_net(seq));
27732 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
27733 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
27734         if (s)
27735                 return s;
27736  
27737 @@ -1822,7 +1828,8 @@ static void *netlink_seq_next(struct seq
27738  
27739                 for (; j <= hash->mask; j++) {
27740                         s = sk_head(&hash->table[j]);
27741 -                       while (s && sock_net(s) != seq_file_net(seq))
27742 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
27743 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
27744                                 s = sk_next(s);
27745                         if (s) {
27746                                 iter->link = i;
27747 diff -NurpP --minimal linux-2.6.29.4/net/sctp/ipv6.c linux-2.6.29.4-vs2.3.0.36.14/net/sctp/ipv6.c
27748 --- linux-2.6.29.4/net/sctp/ipv6.c      2009-03-24 14:22:48.000000000 +0100
27749 +++ linux-2.6.29.4-vs2.3.0.36.14/net/sctp/ipv6.c        2009-03-24 20:58:14.000000000 +0100
27750 @@ -317,7 +317,8 @@ static void sctp_v6_get_saddr(struct sct
27751                                    dst ? ip6_dst_idev(dst)->dev : NULL,
27752                                    &daddr->v6.sin6_addr,
27753                                    inet6_sk(&sk->inet.sk)->srcprefs,
27754 -                                  &saddr->v6.sin6_addr);
27755 +                                  &saddr->v6.sin6_addr,
27756 +                                  asoc->base.sk->sk_nx_info);
27757                 SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: %pI6\n",
27758                                   &saddr->v6.sin6_addr);
27759                 return;
27760 diff -NurpP --minimal linux-2.6.29.4/net/socket.c linux-2.6.29.4-vs2.3.0.36.14/net/socket.c
27761 --- linux-2.6.29.4/net/socket.c 2009-03-24 14:22:48.000000000 +0100
27762 +++ linux-2.6.29.4-vs2.3.0.36.14/net/socket.c   2009-03-24 14:48:37.000000000 +0100
27763 @@ -95,6 +95,10 @@
27764  
27765  #include <net/sock.h>
27766  #include <linux/netfilter.h>
27767 +#include <linux/vs_base.h>
27768 +#include <linux/vs_socket.h>
27769 +#include <linux/vs_inet.h>
27770 +#include <linux/vs_inet6.h>
27771  
27772  static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
27773  static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
27774 @@ -549,7 +553,7 @@ static inline int __sock_sendmsg(struct 
27775                                  struct msghdr *msg, size_t size)
27776  {
27777         struct sock_iocb *si = kiocb_to_siocb(iocb);
27778 -       int err;
27779 +       int err, len;
27780  
27781         si->sock = sock;
27782         si->scm = NULL;
27783 @@ -560,7 +564,22 @@ static inline int __sock_sendmsg(struct 
27784         if (err)
27785                 return err;
27786  
27787 -       return sock->ops->sendmsg(iocb, sock, msg, size);
27788 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
27789 +       if (sock->sk) {
27790 +               if (len == size)
27791 +                       vx_sock_send(sock->sk, size);
27792 +               else
27793 +                       vx_sock_fail(sock->sk, size);
27794 +       }
27795 +       vxdprintk(VXD_CBIT(net, 7),
27796 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
27797 +               sock, sock->sk,
27798 +               (sock->sk)?sock->sk->sk_nx_info:0,
27799 +               (sock->sk)?sock->sk->sk_vx_info:0,
27800 +               (sock->sk)?sock->sk->sk_xid:0,
27801 +               (sock->sk)?sock->sk->sk_nid:0,
27802 +               (unsigned int)size, len);
27803 +       return len;
27804  }
27805  
27806  int sock_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
27807 @@ -629,7 +648,7 @@ EXPORT_SYMBOL_GPL(__sock_recv_timestamp)
27808  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
27809                                  struct msghdr *msg, size_t size, int flags)
27810  {
27811 -       int err;
27812 +       int err, len;
27813         struct sock_iocb *si = kiocb_to_siocb(iocb);
27814  
27815         si->sock = sock;
27816 @@ -642,7 +661,18 @@ static inline int __sock_recvmsg(struct 
27817         if (err)
27818                 return err;
27819  
27820 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
27821 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
27822 +       if ((len >= 0) && sock->sk)
27823 +               vx_sock_recv(sock->sk, len);
27824 +       vxdprintk(VXD_CBIT(net, 7),
27825 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
27826 +               sock, sock->sk,
27827 +               (sock->sk)?sock->sk->sk_nx_info:0,
27828 +               (sock->sk)?sock->sk->sk_vx_info:0,
27829 +               (sock->sk)?sock->sk->sk_xid:0,
27830 +               (sock->sk)?sock->sk->sk_nid:0,
27831 +               (unsigned int)size, len);
27832 +       return len;
27833  }
27834  
27835  int sock_recvmsg(struct socket *sock, struct msghdr *msg,
27836 @@ -1106,6 +1136,13 @@ static int __sock_create(struct net *net
27837         if (type < 0 || type >= SOCK_MAX)
27838                 return -EINVAL;
27839  
27840 +       if (!nx_check(0, VS_ADMIN)) {
27841 +               if (family == PF_INET && !current_nx_info_has_v4())
27842 +                       return -EAFNOSUPPORT;
27843 +               if (family == PF_INET6 && !current_nx_info_has_v6())
27844 +                       return -EAFNOSUPPORT;
27845 +       }
27846 +
27847         /* Compatibility.
27848  
27849            This uglymoron is moved from INET layer to here to avoid
27850 @@ -1238,6 +1275,7 @@ SYSCALL_DEFINE3(socket, int, family, int
27851         if (retval < 0)
27852                 goto out;
27853  
27854 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
27855         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
27856         if (retval < 0)
27857                 goto out_release;
27858 @@ -1279,10 +1317,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
27859         err = sock_create(family, type, protocol, &sock1);
27860         if (err < 0)
27861                 goto out;
27862 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
27863  
27864         err = sock_create(family, type, protocol, &sock2);
27865         if (err < 0)
27866                 goto out_release_1;
27867 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
27868  
27869         err = sock1->ops->socketpair(sock1, sock2);
27870         if (err < 0)
27871 diff -NurpP --minimal linux-2.6.29.4/net/sunrpc/auth.c linux-2.6.29.4-vs2.3.0.36.14/net/sunrpc/auth.c
27872 --- linux-2.6.29.4/net/sunrpc/auth.c    2009-03-24 14:22:48.000000000 +0100
27873 +++ linux-2.6.29.4-vs2.3.0.36.14/net/sunrpc/auth.c      2009-03-24 21:00:49.000000000 +0100
27874 @@ -14,6 +14,7 @@
27875  #include <linux/hash.h>
27876  #include <linux/sunrpc/clnt.h>
27877  #include <linux/spinlock.h>
27878 +#include <linux/vs_tag.h>
27879  
27880  #ifdef RPC_DEBUG
27881  # define RPCDBG_FACILITY       RPCDBG_AUTH
27882 @@ -360,6 +361,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
27883         memset(&acred, 0, sizeof(acred));
27884         acred.uid = cred->fsuid;
27885         acred.gid = cred->fsgid;
27886 +       acred.tag = dx_current_tag();
27887         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
27888  
27889         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
27890 @@ -400,6 +402,7 @@ rpcauth_bind_root_cred(struct rpc_task *
27891         struct auth_cred acred = {
27892                 .uid = 0,
27893                 .gid = 0,
27894 +               .tag = dx_current_tag(),
27895         };
27896         struct rpc_cred *ret;
27897  
27898 diff -NurpP --minimal linux-2.6.29.4/net/sunrpc/auth_unix.c linux-2.6.29.4-vs2.3.0.36.14/net/sunrpc/auth_unix.c
27899 --- linux-2.6.29.4/net/sunrpc/auth_unix.c       2008-12-25 00:26:37.000000000 +0100
27900 +++ linux-2.6.29.4-vs2.3.0.36.14/net/sunrpc/auth_unix.c 2009-02-22 22:54:26.000000000 +0100
27901 @@ -11,12 +11,14 @@
27902  #include <linux/module.h>
27903  #include <linux/sunrpc/clnt.h>
27904  #include <linux/sunrpc/auth.h>
27905 +#include <linux/vs_tag.h>
27906  
27907  #define NFS_NGROUPS    16
27908  
27909  struct unx_cred {
27910         struct rpc_cred         uc_base;
27911         gid_t                   uc_gid;
27912 +       tag_t                   uc_tag;
27913         gid_t                   uc_gids[NFS_NGROUPS];
27914  };
27915  #define uc_uid                 uc_base.cr_uid
27916 @@ -78,6 +80,7 @@ unx_create_cred(struct rpc_auth *auth, s
27917                 groups = NFS_NGROUPS;
27918  
27919         cred->uc_gid = acred->gid;
27920 +       cred->uc_tag = acred->tag;
27921         for (i = 0; i < groups; i++)
27922                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
27923         if (i < NFS_NGROUPS)
27924 @@ -119,7 +122,9 @@ unx_match(struct auth_cred *acred, struc
27925         unsigned int i;
27926  
27927  
27928 -       if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
27929 +       if (cred->uc_uid != acred->uid ||
27930 +               cred->uc_gid != acred->gid ||
27931 +               cred->uc_tag != acred->tag)
27932                 return 0;
27933  
27934         if (acred->group_info != NULL)
27935 @@ -142,7 +147,7 @@ unx_marshal(struct rpc_task *task, __be3
27936         struct rpc_clnt *clnt = task->tk_client;
27937         struct unx_cred *cred = container_of(task->tk_msg.rpc_cred, struct unx_cred, uc_base);
27938         __be32          *base, *hold;
27939 -       int             i;
27940 +       int             i, tag;
27941  
27942         *p++ = htonl(RPC_AUTH_UNIX);
27943         base = p++;
27944 @@ -152,9 +157,12 @@ unx_marshal(struct rpc_task *task, __be3
27945          * Copy the UTS nodename captured when the client was created.
27946          */
27947         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
27948 +       tag = task->tk_client->cl_tag;
27949  
27950 -       *p++ = htonl((u32) cred->uc_uid);
27951 -       *p++ = htonl((u32) cred->uc_gid);
27952 +       *p++ = htonl((u32) TAGINO_UID(tag,
27953 +               cred->uc_uid, cred->uc_tag));
27954 +       *p++ = htonl((u32) TAGINO_GID(tag,
27955 +               cred->uc_gid, cred->uc_tag));
27956         hold = p++;
27957         for (i = 0; i < 16 && cred->uc_gids[i] != (gid_t) NOGROUP; i++)
27958                 *p++ = htonl((u32) cred->uc_gids[i]);
27959 diff -NurpP --minimal linux-2.6.29.4/net/sunrpc/clnt.c linux-2.6.29.4-vs2.3.0.36.14/net/sunrpc/clnt.c
27960 --- linux-2.6.29.4/net/sunrpc/clnt.c    2009-03-24 14:22:48.000000000 +0100
27961 +++ linux-2.6.29.4-vs2.3.0.36.14/net/sunrpc/clnt.c      2009-03-24 14:48:37.000000000 +0100
27962 @@ -32,6 +32,7 @@
27963  #include <linux/utsname.h>
27964  #include <linux/workqueue.h>
27965  #include <linux/in6.h>
27966 +#include <linux/vs_cvirt.h>
27967  
27968  #include <linux/sunrpc/clnt.h>
27969  #include <linux/sunrpc/rpc_pipe_fs.h>
27970 @@ -335,6 +336,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
27971         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
27972                 clnt->cl_chatty = 1;
27973  
27974 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
27975 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
27976 +               clnt->cl_tag = 1; */
27977         return clnt;
27978  }
27979  EXPORT_SYMBOL_GPL(rpc_create);
27980 diff -NurpP --minimal linux-2.6.29.4/net/unix/af_unix.c linux-2.6.29.4-vs2.3.0.36.14/net/unix/af_unix.c
27981 --- linux-2.6.29.4/net/unix/af_unix.c   2009-03-24 14:22:48.000000000 +0100
27982 +++ linux-2.6.29.4-vs2.3.0.36.14/net/unix/af_unix.c     2009-03-24 14:48:37.000000000 +0100
27983 @@ -114,6 +114,8 @@
27984  #include <linux/mount.h>
27985  #include <net/checksum.h>
27986  #include <linux/security.h>
27987 +#include <linux/vs_context.h>
27988 +#include <linux/vs_limit.h>
27989  
27990  static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
27991  static DEFINE_SPINLOCK(unix_table_lock);
27992 @@ -258,6 +260,8 @@ static struct sock *__unix_find_socket_b
27993                 if (!net_eq(sock_net(s), net))
27994                         continue;
27995  
27996 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
27997 +                       continue;
27998                 if (u->addr->len == len &&
27999                     !memcmp(u->addr->name, sunname, len))
28000                         goto found;
28001 @@ -2110,6 +2114,8 @@ static struct sock *unix_seq_idx(struct 
28002         for (s = first_unix_socket(&iter->i); s; s = next_unix_socket(&iter->i, s)) {
28003                 if (sock_net(s) != seq_file_net(seq))
28004                         continue;
28005 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
28006 +                       continue;
28007                 if (off == pos)
28008                         return s;
28009                 ++off;
28010 @@ -2134,7 +2140,8 @@ static void *unix_seq_next(struct seq_fi
28011                 sk = first_unix_socket(&iter->i);
28012         else
28013                 sk = next_unix_socket(&iter->i, sk);
28014 -       while (sk && (sock_net(sk) != seq_file_net(seq)))
28015 +       while (sk && (sock_net(sk) != seq_file_net(seq) ||
28016 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)))
28017                 sk = next_unix_socket(&iter->i, sk);
28018         return sk;
28019  }
28020 diff -NurpP --minimal linux-2.6.29.4/net/x25/af_x25.c linux-2.6.29.4-vs2.3.0.36.14/net/x25/af_x25.c
28021 --- linux-2.6.29.4/net/x25/af_x25.c     2009-05-23 23:16:53.000000000 +0200
28022 +++ linux-2.6.29.4-vs2.3.0.36.14/net/x25/af_x25.c       2009-04-30 12:14:53.000000000 +0200
28023 @@ -506,7 +506,10 @@ static int x25_create(struct net *net, s
28024  
28025         x25 = x25_sk(sk);
28026  
28027 -       sock_init_data(sock, sk);
28028 +       sk->sk_socket = sock;
28029 +       sk->sk_type = sock->type;
28030 +       sk->sk_sleep = &sock->wait;
28031 +       sock->sk = sk;
28032  
28033         x25_init_timers(sk);
28034  
28035 diff -NurpP --minimal linux-2.6.29.4/scripts/checksyscalls.sh linux-2.6.29.4-vs2.3.0.36.14/scripts/checksyscalls.sh
28036 --- linux-2.6.29.4/scripts/checksyscalls.sh     2008-12-25 00:26:37.000000000 +0100
28037 +++ linux-2.6.29.4-vs2.3.0.36.14/scripts/checksyscalls.sh       2009-02-22 22:54:26.000000000 +0100
28038 @@ -108,7 +108,6 @@ cat << EOF
28039  #define __IGNORE_afs_syscall
28040  #define __IGNORE_getpmsg
28041  #define __IGNORE_putpmsg
28042 -#define __IGNORE_vserver
28043  EOF
28044  }
28045  
28046 diff -NurpP --minimal linux-2.6.29.4/security/commoncap.c linux-2.6.29.4-vs2.3.0.36.14/security/commoncap.c
28047 --- linux-2.6.29.4/security/commoncap.c 2009-05-23 23:16:53.000000000 +0200
28048 +++ linux-2.6.29.4-vs2.3.0.36.14/security/commoncap.c   2009-04-30 12:14:53.000000000 +0200
28049 @@ -27,10 +27,11 @@
28050  #include <linux/sched.h>
28051  #include <linux/prctl.h>
28052  #include <linux/securebits.h>
28053 +#include <linux/vs_context.h>
28054  
28055  int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
28056  {
28057 -       NETLINK_CB(skb).eff_cap = current_cap();
28058 +       NETLINK_CB(skb).eff_cap = vx_mbcaps(current_cap());
28059         return 0;
28060  }
28061  
28062 @@ -40,6 +41,7 @@ int cap_netlink_recv(struct sk_buff *skb
28063                 return -EPERM;
28064         return 0;
28065  }
28066 +
28067  EXPORT_SYMBOL(cap_netlink_recv);
28068  
28069  /**
28070 @@ -60,7 +62,22 @@ EXPORT_SYMBOL(cap_netlink_recv);
28071  int cap_capable(struct task_struct *tsk, const struct cred *cred, int cap,
28072                 int audit)
28073  {
28074 -       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
28075 +       struct vx_info *vxi = tsk->vx_info;
28076 +
28077 +#if 0
28078 +       printk("cap_capable() VXF_STATE_SETUP = %llx, raised = %x, eff = %08x:%08x\n",
28079 +               vx_info_flags(vxi, VXF_STATE_SETUP, 0),
28080 +               cap_raised(tsk->cap_effective, cap),
28081 +               tsk->cap_effective.cap[1], tsk->cap_effective.cap[0]);
28082 +#endif
28083 +
28084 +       /* special case SETUP */
28085 +       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
28086 +               /* FIXME: maybe use cred instead? */
28087 +               cap_raised(tsk->cred->cap_effective, cap))
28088 +               return 0;
28089 +
28090 +       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
28091  }
28092  
28093  /**
28094 @@ -586,7 +603,7 @@ int cap_inode_setxattr(struct dentry *de
28095  
28096         if (!strncmp(name, XATTR_SECURITY_PREFIX,
28097                      sizeof(XATTR_SECURITY_PREFIX) - 1)  &&
28098 -           !capable(CAP_SYS_ADMIN))
28099 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
28100                 return -EPERM;
28101         return 0;
28102  }
28103 @@ -930,7 +947,8 @@ error:
28104   */
28105  int cap_syslog(int type)
28106  {
28107 -       if ((type != 3 && type != 10) && !capable(CAP_SYS_ADMIN))
28108 +       if ((type != 3 && type != 10) &&
28109 +               !vx_capable(CAP_SYS_ADMIN, VXC_SYSLOG))
28110                 return -EPERM;
28111         return 0;
28112  }
28113 @@ -952,3 +970,4 @@ int cap_vm_enough_memory(struct mm_struc
28114                 cap_sys_admin = 1;
28115         return __vm_enough_memory(mm, pages, cap_sys_admin);
28116  }
28117 +
28118 diff -NurpP --minimal linux-2.6.29.4/security/selinux/hooks.c linux-2.6.29.4-vs2.3.0.36.14/security/selinux/hooks.c
28119 --- linux-2.6.29.4/security/selinux/hooks.c     2009-05-23 23:16:53.000000000 +0200
28120 +++ linux-2.6.29.4-vs2.3.0.36.14/security/selinux/hooks.c       2009-05-23 23:19:11.000000000 +0200
28121 @@ -64,7 +64,6 @@
28122  #include <linux/dccp.h>
28123  #include <linux/quota.h>
28124  #include <linux/un.h>          /* for Unix socket types */
28125 -#include <net/af_unix.h>       /* for Unix socket types */
28126  #include <linux/parser.h>
28127  #include <linux/nfs_mount.h>
28128  #include <net/ipv6.h>
This page took 2.207629 seconds and 2 git commands to generate.